@@ -12,14 +12,8 @@ Description:
12
12
Select a component
13
13
</div >
14
14
<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 >
23
17
</template >
24
18
25
19
<script >
@@ -28,6 +22,7 @@ import { mapState } from "vuex";
28
22
import { PrismEditor } from " vue-prism-editor" ;
29
23
import " vue-prism-editor/dist/prismeditor.min.css" ;
30
24
import { highlight , languages } from " prismjs/components/prism-core" ;
25
+ import styleClassMap from ' ../../store/state/styleClassMap'
31
26
import " prismjs/components/prism-clike" ;
32
27
import " prismjs/components/prism-javascript" ;
33
28
import " prismjs/themes/prism-tomorrow.css" ; // import syntax highlighting styles
@@ -44,18 +39,19 @@ export default {
44
39
PrismEditor,
45
40
},
46
41
computed: {
42
+ // add
47
43
// needs access to current component aka activeComponent
48
44
... mapState ([" componentMap" , " activeComponent" , " activeComponentObj" , " exportAsTypescript" ]),
49
45
},
50
46
methods: {
51
- snippetInvoke (){
52
- if (this .activeComponent !== ' ' ){
47
+ snippetInvoke () {
48
+ if (this .activeComponent !== ' ' ) {
53
49
this .code = this .createCodeSnippet (
54
50
this .componentMap [this .activeComponent ].componentName ,
55
51
this .componentMap [this .activeComponent ].children
56
52
)
57
- } else {
58
- this .code = ' Your component boilerplate will be displayed here.'
53
+ } else {
54
+ this .code = ' Your component boilerplate will be displayed here.'
59
55
}
60
56
},
61
57
// highlighter does not work: OverVue 6.0;
@@ -95,32 +91,16 @@ export default {
95
91
" list-ul" : [" <ul" , " </ul>" ],
96
92
input: [" <input" , " " ], // single
97
93
navbar: [" <nav" , " </nav>" ],
98
- header: [" <header" ," </header>" ],
99
- footer: [" <footer" , " </footer>" ],
94
+ header: [" <header" , " </header>" ],
95
+ footer: [" <footer" , " </footer>" ],
100
96
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>" ],
107
103
};
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
124
104
function writeNested (childrenArray , indent ) {
125
105
if (! childrenArray .length ) {
126
106
return " " ;
@@ -134,13 +114,13 @@ export default {
134
114
nestedString += ` <${ child} />\n ` ;
135
115
} else {
136
116
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
+
144
124
if (child .children .length ) {
145
125
nestedString += " \n " ;
146
126
nestedString += writeNested (child .children , indented);
@@ -157,21 +137,22 @@ export default {
157
137
// Iterates through active component's HTML elements list and adds to code snippet
158
138
let htmlArr = this .componentMap [componentName].htmlList ;
159
139
console .log (" ALERT" )
160
- console .log (htmlArr[0 ].class )
161
- console .log (htmlArr[0 ].children )
140
+ console .log (' hellloo' )
141
+ console .log (" here" , htmlArr[0 ].class )
142
+ console .log (htmlArr[0 ].children );
162
143
let outputStr = ` ` ;
163
144
// eslint-disable-next-line no-unused-vars
164
- for (let el of htmlArr) {
145
+ for (const el of htmlArr) {
165
146
if (! el .text ) {
166
147
outputStr += ` <${ el} />\n ` ;
167
148
} else {
168
149
outputStr += ` ` ;
169
- outputStr += htmlElementMap[el .text ][0 ]
170
- // if conditional to check class
171
- if (el .class !== " " ) {
172
- outputStr += " " + " class = " + ` "${ el .class } "` ;
173
- }
174
- outputStr += " >" ;
150
+ outputStr += htmlElementMap[el .text ][0 ]
151
+ // if conditional to check class
152
+ if (el .class !== " " ) {
153
+ outputStr += " " + " class = " + ` "${ el .class } "` ;
154
+ }
155
+ outputStr += " >" ;
175
156
if (el .children .length ) {
176
157
outputStr += " \n " ;
177
158
outputStr += writeNested (el .children , ` ` );
@@ -204,7 +185,7 @@ export default {
204
185
imports += ' } from "vuex";\n ' ;
205
186
}
206
187
207
- // if Typescript toggle is on, import defineComponent
188
+ // if Typescript toggle is on, import defineComponent
208
189
if (this .exportAsTypescript === " on" ) {
209
190
imports += ' import { defineComponent } from "vue";\n ' ;
210
191
}
@@ -256,6 +237,16 @@ export default {
256
237
methods += " },\n " ;
257
238
}
258
239
240
+ let htmlArray = this .componentMap [componentName].htmlList ;
241
+ console .log (" down here" , htmlArray);
242
+ let styleString = " " ;
243
+ for (const html of htmlArray) {
244
+ if (! html .class ) styleString = " " ;
245
+ if (html .class ) {
246
+ styleString += ` .${ html .class } {\n }\n `
247
+ }
248
+ }
249
+
259
250
// concat all code within script tags
260
251
// if exportAsTypescript is on, out should be <script lang="ts">
261
252
let output;
@@ -276,28 +267,28 @@ export default {
276
267
output += " });\n <\/ script>\n\n <style scoped>\n </style>"
277
268
278
269
} else {
279
- output += " }; \n <\/ script>\n\n <style scoped>\n </style> "
270
+ output += ` }; \n <\/ script>\n\n <style scoped>\n ${ styleString } </style > `
280
271
}
281
- return output;
272
+ return output
282
273
},
283
274
},
284
275
watch: {
285
276
// watches activeComponentObj for changes to make it reactive upon mutation
286
277
// // // watches componentMap for changes to make it reactive upon mutation
287
278
activeComponent: {
288
- handler () {
279
+ handler () {
289
280
this .snippetInvoke ();
290
281
},
291
282
deep: true
292
283
},
293
284
componentMap: {
294
- handler () {
285
+ handler () {
295
286
this .snippetInvoke ();
296
287
},
297
288
deep: true
298
289
},
299
290
exportAsTypescript: {
300
- handler () {
291
+ handler () {
301
292
this .snippetInvoke ();
302
293
},
303
294
}
0 commit comments