1
1
import { openHtmlElementMap } from "src/store/state/htmlElementMap" ;
2
- import path from "path " ;
2
+ import { useStore } from "src/store/main " ;
3
3
export function useExportComponent ( ) {
4
4
// OVERVUE 8.0: export active component
5
5
/**
@@ -9,6 +9,8 @@ export function useExportComponent() {
9
9
* @return : none -- outputs file to fs
10
10
*
11
11
*/
12
+ const { ipcRenderer, fs, path } = window ;
13
+ const store = useStore ( ) ;
12
14
13
15
const exportComponent = ( ) => {
14
16
ipcRenderer
@@ -17,7 +19,10 @@ export function useExportComponent() {
17
19
message : "Choose location to save folder in" ,
18
20
nameFieldLabel : "Component Name" ,
19
21
} )
20
- . then ( ( result ) => exportComponentFile ( result . filePath ) )
22
+ . then ( ( result ) => {
23
+ exportComponentFile ( result . filePath ) ;
24
+ alert ( "Successfully Exported" ) ;
25
+ } )
21
26
. catch ( ( err ) => console . log ( err ) ) ;
22
27
} ;
23
28
@@ -167,7 +172,7 @@ export function useExportComponent() {
167
172
return nestedString ;
168
173
} ;
169
174
// iterate through component's htmllist
170
- let htmlArr = this . componentMap [ componentName ] . htmlList ;
175
+ let htmlArr = store . componentMap [ componentName ] . htmlList ;
171
176
let outputStr = `` ;
172
177
// eslint-disable-next-line no-unused-vars
173
178
for ( let el of htmlArr ) {
@@ -199,9 +204,9 @@ export function useExportComponent() {
199
204
} ;
200
205
201
206
const writeComments = ( componentName ) => {
202
- if ( this . componentMap [ componentName ] ?. noteList ?. length > 0 ) {
207
+ if ( store . componentMap [ componentName ] ?. noteList ?. length > 0 ) {
203
208
let commentStr = "<!--" ;
204
- this . componentMap [ componentName ] . noteList . forEach ( ( el ) => {
209
+ store . componentMap [ componentName ] . noteList . forEach ( ( el ) => {
205
210
commentStr += "\n" ;
206
211
commentStr += el ;
207
212
} ) ;
@@ -222,29 +227,29 @@ export function useExportComponent() {
222
227
223
228
//used to loop through - and apply class/id in code snippet
224
229
if (
225
- this . componentMap [ componentName ] . htmlAttributes . class !== "" &&
226
- this . componentMap [ componentName ] . htmlAttributes . id !== ""
230
+ store . componentMap [ componentName ] . htmlAttributes . class !== "" &&
231
+ store . componentMap [ componentName ] . htmlAttributes . id !== ""
227
232
) {
228
- return `<template>\n <div id = "${ this . componentMap [ componentName ] . htmlAttributes . id } " class = "${ this . componentMap [ componentName ] . htmlAttributes . class } ">\n${ templateTagStr } </div>\n</template>` ;
233
+ return `<template>\n <div id = "${ store . componentMap [ componentName ] . htmlAttributes . id } " class = "${ store . componentMap [ componentName ] . htmlAttributes . class } ">\n${ templateTagStr } </div>\n</template>` ;
229
234
} else if (
230
- this . componentMap [ componentName ] . htmlAttributes . class !== "" &&
231
- this . componentMap [ componentName ] . htmlAttributes . id === ""
235
+ store . componentMap [ componentName ] . htmlAttributes . class !== "" &&
236
+ store . componentMap [ componentName ] . htmlAttributes . id === ""
232
237
) {
233
- return `<template>\n <div class = "${ this . componentMap [ componentName ] . htmlAttributes . class } ">\n${ templateTagStr } </div>\n</template>` ;
238
+ return `<template>\n <div class = "${ store . componentMap [ componentName ] . htmlAttributes . class } ">\n${ templateTagStr } </div>\n</template>` ;
234
239
} else if (
235
- this . componentMap [ componentName ] . htmlAttributes . class === "" &&
236
- this . componentMap [ componentName ] . htmlAttributes . id !== ""
240
+ store . componentMap [ componentName ] . htmlAttributes . class === "" &&
241
+ store . componentMap [ componentName ] . htmlAttributes . id !== ""
237
242
)
238
- return `<template>\n <div id = "${ this . componentMap [ componentName ] . htmlAttributes . id } ">\n${ templateTagStr } </div>\n</template>` ;
239
- else return `<template>\n <div>\n${ templateTagStr } </div>\n</template>` ;
243
+ return `<template>\n <div id = "${ store . componentMap [ componentName ] . htmlAttributes . id } ">\n${ templateTagStr } </div>\n</template>` ;
244
+ else return `<template>\n <div>\n${ templateTagStr } </div>\n</template>` ;
240
245
} ;
241
246
242
247
/**
243
248
* @description imports child components into <script>
244
249
*/
245
250
const writeScript = ( componentName , children ) => {
246
251
// add import mapstate and mapactions if they exist
247
- const currentComponent = this . componentMap [ componentName ] ;
252
+ const currentComponent = store . componentMap [ componentName ] ;
248
253
let imports = "" ;
249
254
if ( currentComponent . actions . length || currentComponent . state . length ) {
250
255
imports += "import { " ;
@@ -255,7 +260,7 @@ export function useExportComponent() {
255
260
imports += ' } from "vuex"\n' ;
256
261
}
257
262
// if Typescript toggle is on, import defineComponent
258
- if ( this . exportAsTypescript === "on" ) {
263
+ if ( store . exportAsTypescript === "on" ) {
259
264
imports += 'import { defineComponent } from "vue";\n' ;
260
265
}
261
266
// add imports for children
@@ -277,7 +282,7 @@ export function useExportComponent() {
277
282
data += `\n ${ prop } : "PLACEHOLDER FOR VALUE",` ;
278
283
} ) ;
279
284
}
280
- this . routes . HomeView . forEach ( ( element ) => {
285
+ store . routes . HomeView . forEach ( ( element ) => {
281
286
element . htmlList . forEach ( ( html ) => {
282
287
if ( html . binding !== "" ) {
283
288
data += `\n ${ html . binding } : "PLACEHOLDER FOR VALUE",` ;
@@ -313,7 +318,7 @@ export function useExportComponent() {
313
318
// concat all code within script tags
314
319
// if exportAsTypescript is on, out should be <script lang="ts">
315
320
let output ;
316
- if ( this . exportAsTypescript === "on" ) {
321
+ if ( store . exportAsTypescript === "on" ) {
317
322
output = "\n\n<script lang='ts'>\n" ;
318
323
output +=
319
324
imports +
@@ -330,7 +335,7 @@ export function useExportComponent() {
330
335
output += computed ;
331
336
output += methods ;
332
337
// eslint-disable-next-line no-useless-escape
333
- if ( this . exportAsTypescript === "on" ) {
338
+ if ( store . exportAsTypescript === "on" ) {
334
339
output += "});\n</script>" ;
335
340
} else {
336
341
output += "};\n</script>" ;
@@ -343,10 +348,10 @@ export function useExportComponent() {
343
348
* if component is 'App', writes css, else returns <style scoped>
344
349
*/
345
350
const writeStyle = ( componentName ) => {
346
- let htmlArray = this . componentMap [ componentName ] . htmlList ;
351
+ let htmlArray = store . componentMap [ componentName ] . htmlList ;
347
352
let styleString = "" ;
348
353
349
- this . routes . HomeView . forEach ( ( element ) => {
354
+ store . routes . HomeView . forEach ( ( element ) => {
350
355
if ( element . htmlAttributes . class !== "" ) {
351
356
styleString += `.${ element . htmlAttributes . class } {\nbackground-color: ${ element . color } ;
352
357
width: ${ element . w } px;
@@ -378,10 +383,11 @@ z-index: ${html.z};
378
383
// main logic below for creating single component
379
384
// eslint-disable-next-line no-unused-vars
380
385
createComponentCode (
381
- path . join ( data , this . activeComponent ) ,
382
- this . activeComponent ,
383
- this . componentMap [ this . activeComponent ] . children
386
+ path . join ( data , store . activeComponent ) ,
387
+ store . activeComponent ,
388
+ store . componentMap [ store . activeComponent ] . children
384
389
) ;
385
390
} ;
391
+
386
392
exportComponent ( ) ;
387
393
}
0 commit comments