-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboilerplate.js
80 lines (68 loc) · 2.6 KB
/
boilerplate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
export default ({
component,
config,
dataset,
useTypescript,
useComputedDataset,
useComputedConfig,
configType,
datasetType,
isDatasetArray,
componentSlots,
componentLink,
emits
}) => {
const dsType = useTypescript ? `<${`${datasetType}${isDatasetArray ? '[]' : ''}`}>` : '';
const confType = useTypescript ? `<${configType}>` : '';
const ds = JSON.stringify(dataset);
const conf = JSON.stringify(config);
const sourceSlot = `
<!-- #source slot: display the source for your data -->
<!--<template #source>
<small>Source: <cite>My source</cite></small>
</template>-->
`;
let emitFuncs = '';
let emitDefs = '';
if (emits && emits.length) {
emitFuncs = emits.map(emit => {
return `${useTypescript ? emit.funcTs : emit.func}`
}).toString().replaceAll(',', '\n\n');
emitDefs = emits.map(emit => {
return `@${emit.name}="${emit.name}"`;
}).toString().replaceAll(',', '');
}
return `
<script setup${useTypescript ? ' lang="ts"' : ''}>
import { ${[useComputedConfig, useComputedDataset].includes(false) ? 'ref, ' : ''}${useComputedConfig || useComputedDataset ? 'computed ' : ''}} from "vue";
import { VueDataUi${useTypescript ? `,${['number', 'Array<Array<string | number>>', ''].includes(datasetType) ? '' : `type ${datasetType},`} type ${configType} }` : '}'} from "vue-data-ui";
import "vue-data-ui/style.css"; // Consider importing the css in your main file
${!datasetType ? '' : `const dataset = ${useComputedDataset ? `computed${dsType}(() => {
return ${ds};
})` : `ref${dsType}(${ds})`};`}
/**
* This is the default config.
* It is not required to send it all to the component.
* You can keep only the modified attributes you need.
*/
const config = ${useComputedConfig ? `computed${confType}(() => {
return ${conf};
})` : `ref${confType}(${conf})`};
${emitFuncs}
</script>
<template>
<div :style="{ width: '600px' /** Set your styles for the chart wrapper. This wrapper is not necessary. */ }">
<VueDataUi
component="${component}"
${!datasetType ? '' : `:dataset="dataset"`}
:config="config"
${emitDefs}
${componentSlots.length ? '>' : '/>'}
${ componentSlots.length ? '<!-- Use slots here in template tags. Official Vue slots documentation https://vuejs.org/guide/components/slots -->' : '' }
${ componentSlots.length ? `<!-- Documentation on Vue Data UI slots, check the slots tab at https://vue-data-ui.graphieros.com/docs#${componentLink} -->` : '' }
${ componentSlots.includes('source') ? sourceSlot : ''}
${componentSlots.length ? '</VueDataUi>' : ''}
</div>
</template>
`;
};