Skip to content

Commit 1c78c38

Browse files
committed
fixed parent/child relationship in exportmenu
> > Co-authored-by: Chris Davis <[email protected]> Co-authored-by: Ji Kim <[email protected]> Co-authored-by: Jigar Patel <[email protected]> Co-authored-by: Linden Young <[email protected]>
1 parent 1fa9c79 commit 1c78c38

File tree

2 files changed

+100
-8
lines changed

2 files changed

+100
-8
lines changed

src/components/nav-buttons/ExportMenu.vue

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ import { useExportComponent } from "../composables/useExportComponent.js";
2222
import { mapState } from "vuex";
2323
const { fs, ipcRenderer } = window;
2424
25-
import writeNested from "../../mixins/writeNested";
26-
import { result } from "lodash";
25+
// import writeNested from "../../mixins/writeNested";
2726
2827
2928
export default {
3029
name: "ExportProjectComponent",
31-
mixins: [writeNested],
3230
methods: {
3331
useExportComponentBound() {
3432
useExportComponent.bind(this)();
@@ -227,7 +225,42 @@ test('renders ${componentName}', () => {
227225
`
228226
</el-badge>`],
229227
};
230-
228+
// function to loop through nested elements
229+
function writeNested(childrenArray, indent) {
230+
if (!childrenArray.length) {
231+
return "";
232+
}
233+
let indented = indent + " ";
234+
let nestedString = "";
235+
236+
childrenArray.forEach((child) => {
237+
nestedString += indented;
238+
if (!child.text) {
239+
nestedString += `<${child}/>\n`;
240+
} else {
241+
nestedString += htmlElementMap[child.text][0];
242+
if (child.class !== "") {
243+
nestedString += " " + "class = " + `"${child.class}"`;
244+
}
245+
if(child.binding !== "") {
246+
nestedString += " " + "v-model = " + `"${child.binding}"`;
247+
}
248+
if (child.text === "img" || child.text === "input" || child.text === "link") {
249+
nestedString += "/>";
250+
} else { nestedString += ">"; }
251+
252+
if (child.children.length) {
253+
nestedString += "\n";
254+
nestedString += writeNested(child.children, indented);
255+
nestedString += indented + htmlElementMap[child.text][1];
256+
nestedString += "\n";
257+
} else {
258+
nestedString += htmlElementMap[child.text][1] + "\n";
259+
}
260+
}
261+
});
262+
return nestedString;
263+
}
231264
// iterate through component's htmllist
232265
let htmlArr = this.componentMap[componentName].htmlList;
233266
let outputStr = ``;
@@ -328,12 +361,18 @@ test('renders ${componentName}', () => {
328361
return `<template>\n <div id = "${compID}">\n${templateTagStr}${routeStr} </div>\n</template>`;
329362
}
330363
else {
331-
364+
const arrOfChildComp = this.componentMap[componentName].children;
365+
arrOfChildComp.forEach(childName => {
366+
let childNameClass = this.componentMap[childName].htmlAttributes.class;
367+
let childNameClassFullStr = (childNameClass === "") ? "" : ` class = '${childNameClass}'`;
368+
routeStr += `<${childName}${childNameClassFullStr}></${childName}>\n`
369+
});
370+
332371
return `<template>\n <div>\n\t${str}${templateTagStr}${routeStr} </div>\n</template>`;
333372
}
334373
}
335374
else {
336-
return `<template>\n\t${str}${templateTagStr}${routeStr}\t</div>\n</template>`
375+
return `<template>\n<div>\n\t${str}${templateTagStr}${routeStr}\t</div>\n</template>`
337376
}
338377
},
339378
/**
@@ -366,6 +405,20 @@ test('renders ${componentName}', () => {
366405
}
367406
368407
let childrenComponentNames = "";
408+
let childComponentImportNames = "";
409+
410+
const arrOfChildComp = this.componentMap[componentName].children;
411+
412+
arrOfChildComp.forEach(childName => {
413+
// Build child component text string
414+
if (childName !== arrOfChildComp[arrOfChildComp.length - 1]){
415+
childrenComponentNames += " " + childName + ",\n";
416+
}
417+
else {
418+
childrenComponentNames += " " + childName + "\n";
419+
}
420+
childComponentImportNames += `import ${childName} from '../components/${childName}.vue';\n`
421+
})
369422
370423
let data = "";
371424
data += " data () {\n return {";
@@ -416,6 +469,8 @@ test('renders ${componentName}', () => {
416469
} else {
417470
output = "\n\n<script>\n";
418471
472+
output+= `\n${childComponentImportNames}`;
473+
419474
output += imports + "\nexport default {\n name: '" + componentName + "'";
420475
421476
}

src/components/right-sidebar/CodeSnippet.vue

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import "prismjs/components/prism-clike";
2727
import "prismjs/components/prism-javascript";
2828
import "prismjs/themes/prism-tomorrow.css"; // import syntax highlighting styles
2929
30-
import writeNested from "../../mixins/writeNested";
30+
// import writeNested from "../../mixins/writeNested";
3131
3232
export default {
3333
data() {
@@ -45,7 +45,6 @@ export default {
4545
// needs access to current component aka activeComponent
4646
...mapState(["componentMap", "activeComponent", "activeComponentObj", "exportAsTypescript"]),
4747
},
48-
mixins: [writeNested],
4948
methods: {
5049
snippetInvoke() {
5150
if (this.activeComponent !== '') {
@@ -172,6 +171,44 @@ export default {
172171
htmlElementMap[child]=[`<${child}`, ""] //single
173172
})
174173
174+
function writeNested(childrenArray, indent) {
175+
if (!childrenArray.length) {
176+
return "";
177+
}
178+
let indented = indent + " ";
179+
let nestedString = "";
180+
181+
childrenArray.forEach((child) => {
182+
nestedString += indented;
183+
if (!child.text) {
184+
nestedString += `<${child}/>\n`;
185+
} else {
186+
nestedString += htmlElementMap[child.text][0];
187+
if (child.class !== "") {
188+
nestedString += " " + "class=" + `"${child.class}"`;
189+
}
190+
if (child.binding !== "") {
191+
if (child.text !== 'img' || child.text !== 'link') {
192+
nestedString += ` v-model="${child.binding}"`
193+
194+
}
195+
}
196+
if (child.text === "img" || child.text === "input" || child.text === "link" || childComponents.includes(child.text)) {
197+
nestedString += "/>";
198+
} else { nestedString += ">"; }
199+
200+
if (child.children.length) {
201+
nestedString += "\n";
202+
nestedString += writeNested(child.children, indented);
203+
nestedString += indented + htmlElementMap[child.text][1];
204+
nestedString += "\n"
205+
} else {
206+
nestedString += htmlElementMap[child.text][1] + "\n";
207+
}
208+
}
209+
});
210+
return nestedString;
211+
}
175212
// Iterates through active component's HTML elements list and adds to code snippet
176213
let htmlArr = this.componentMap[componentName].htmlList;
177214
let outputStr = ``;

0 commit comments

Comments
 (0)