Skip to content

Commit 6450e0d

Browse files
committed
Merge branch 'dev' into Johnny
2 parents a9ef94f + 561ef7d commit 6450e0d

File tree

7 files changed

+148
-173
lines changed

7 files changed

+148
-173
lines changed

src/components/right-sidebar/CodeSnippet.vue

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@ Description:
1212
Select a component
1313
</div>
1414
<div v-else>{{ `${this.activeComponent}.vue` }}</div>
15-
<prism-editor
16-
v-model="code"
17-
:highlight="highlighter"
18-
line-numbers
19-
class="my-editor"
20-
readonly
21-
/>
22-
</div>
15+
<prism-editor v-model="code" :highlight="highlighter" line-numbers class="my-editor" readonly />
16+
</div>
2317
</template>
2418

2519
<script>
@@ -28,6 +22,7 @@ import { mapState } from "vuex";
2822
import { PrismEditor } from "vue-prism-editor";
2923
import "vue-prism-editor/dist/prismeditor.min.css";
3024
import { highlight, languages } from "prismjs/components/prism-core";
25+
import styleClassMap from '../../store/state/styleClassMap'
3126
import "prismjs/components/prism-clike";
3227
import "prismjs/components/prism-javascript";
3328
import "prismjs/themes/prism-tomorrow.css"; // import syntax highlighting styles
@@ -44,18 +39,19 @@ export default {
4439
PrismEditor,
4540
},
4641
computed: {
42+
//add
4743
// needs access to current component aka activeComponent
4844
...mapState(["componentMap", "activeComponent", "activeComponentObj", "exportAsTypescript"]),
4945
},
5046
methods: {
51-
snippetInvoke(){
52-
if (this.activeComponent !== ''){
47+
snippetInvoke() {
48+
if (this.activeComponent !== '') {
5349
this.code = this.createCodeSnippet(
5450
this.componentMap[this.activeComponent].componentName,
5551
this.componentMap[this.activeComponent].children
5652
)
57-
} else {
58-
this.code = 'Your component boilerplate will be displayed here.'
53+
} else {
54+
this.code = 'Your component boilerplate will be displayed here.'
5955
}
6056
},
6157
//highlighter does not work: OverVue 6.0;
@@ -95,32 +91,16 @@ export default {
9591
"list-ul": ["<ul", "</ul>"],
9692
input: ["<input", ""], //single
9793
navbar: ["<nav", "</nav>"],
98-
header:["<header","</header>"],
99-
footer:["<footer", "</footer>"],
94+
header: ["<header", "</header>"],
95+
footer: ["<footer", "</footer>"],
10096
meta: ["<meta", "</meta>"],
101-
h1:["<h1", "</h1>"],
102-
h2:["<h2", "</h2>"],
103-
h3:["<h3", "</h3>"],
104-
h4:["<h4", "</h4>"],
105-
h5:["<h5", "</h5>"],
106-
h6:["<h6", "</h6>"],
97+
h1: ["<h1", "</h1>"],
98+
h2: ["<h2", "</h2>"],
99+
h3: ["<h3", "</h3>"],
100+
h4: ["<h4", "</h4>"],
101+
h5: ["<h5", "</h5>"],
102+
h6: ["<h6", "</h6>"],
107103
};
108-
//test//
109-
// function writeClass(componentName) {
110-
// if (this.componentMap[componentName]?.classList?.length > 0) {
111-
// let commentStr = '<!--'
112-
// this.componentMap[componentName].classList.forEach((el) => {
113-
// commentStr += "\n"
114-
// commentStr += el;
115-
// })
116-
// commentStr += '\n-->\n\n'
117-
// return commentStr;
118-
// } else {
119-
// return ''
120-
// }
121-
// };
122-
// Helper function that recursively iterates through the given html element's children and their children's children.
123-
// also adds proper indentation to code snippet
124104
function writeNested(childrenArray, indent) {
125105
if (!childrenArray.length) {
126106
return "";
@@ -134,13 +114,13 @@ export default {
134114
nestedString += `<${child}/>\n`;
135115
} else {
136116
nestedString += htmlElementMap[child.text][0];
137-
if(child.class !== "") {
138-
nestedString += " " + "class = " + `"${el.class}"`;
139-
}
140-
if(child.text === "img" || child.text === "input" || child.text === "link") {
141-
nestedString += "/>";
142-
} else {nestedString += ">";}
143-
117+
if (child.class !== "") {
118+
nestedString += " " + "class = " + `"${el.class}"`;
119+
}
120+
if (child.text === "img" || child.text === "input" || child.text === "link") {
121+
nestedString += "/>";
122+
} else { nestedString += ">"; }
123+
144124
if (child.children.length) {
145125
nestedString += "\n";
146126
nestedString += writeNested(child.children, indented);
@@ -158,17 +138,17 @@ export default {
158138
let htmlArr = this.componentMap[componentName].htmlList;
159139
let outputStr = ``;
160140
// eslint-disable-next-line no-unused-vars
161-
for (let el of htmlArr) {
141+
for (const el of htmlArr) {
162142
if (!el.text) {
163143
outputStr += ` <${el}/>\n`;
164144
} else {
165145
outputStr += ` `;
166-
outputStr += htmlElementMap[el.text][0]
167-
//if conditional to check class
168-
if(el.class !== "") {
169-
outputStr += " " + "class = " + `"${el.class}"`;
170-
}
171-
outputStr += ">";
146+
outputStr += htmlElementMap[el.text][0]
147+
//if conditional to check class
148+
if (el.class !== "") {
149+
outputStr += " " + "class = " + `"${el.class}"`;
150+
}
151+
outputStr += ">";
172152
if (el.children.length) {
173153
outputStr += "\n";
174154
outputStr += writeNested(el.children, ` `);
@@ -201,7 +181,7 @@ export default {
201181
imports += ' } from "vuex";\n';
202182
}
203183
204-
// if Typescript toggle is on, import defineComponent
184+
// if Typescript toggle is on, import defineComponent
205185
if (this.exportAsTypescript === "on") {
206186
imports += 'import { defineComponent } from "vue";\n';
207187
}
@@ -253,6 +233,15 @@ export default {
253233
methods += " },\n";
254234
}
255235
236+
let htmlArray = this.componentMap[componentName].htmlList;
237+
let styleString = "";
238+
for (const html of htmlArray) {
239+
if (html.class === ' ') styleString = "";
240+
if (html.class) {
241+
styleString += `.${html.class} {\n}\n`
242+
}
243+
}
244+
256245
// concat all code within script tags
257246
// if exportAsTypescript is on, out should be <script lang="ts">
258247
let output;
@@ -273,28 +262,28 @@ export default {
273262
output += "});\n<\/script>\n\n<style scoped>\n</style>"
274263
275264
} else {
276-
output += "};\n<\/script>\n\n<style scoped>\n</style>"
265+
output += `}; \n <\/script>\n\n<style scoped>\n${styleString}</style > `
277266
}
278-
return output;
267+
return output
279268
},
280269
},
281270
watch: {
282271
// watches activeComponentObj for changes to make it reactive upon mutation
283272
// // // watches componentMap for changes to make it reactive upon mutation
284273
activeComponent: {
285-
handler () {
274+
handler() {
286275
this.snippetInvoke();
287276
},
288277
deep: true
289278
},
290279
componentMap: {
291-
handler () {
280+
handler() {
292281
this.snippetInvoke();
293282
},
294283
deep: true
295284
},
296285
exportAsTypescript: {
297-
handler () {
286+
handler() {
298287
this.snippetInvoke();
299288
},
300289
}

0 commit comments

Comments
 (0)