histoire 0.6.1 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundled/SandboxVue3.js +17 -0
- package/dist/client/app/components/sandbox/SandboxVue3.vue +19 -0
- package/dist/client/app/style/main.pcss +1 -1
- package/dist/client/app/style/sandbox.css +2 -4
- package/dist/client/bundle-sandbox.js +0 -1
- package/dist/client/server/vue3/run.js +5 -0
- package/dist/node/config.d.ts +4 -0
- package/dist/node/config.js +4 -0
- package/dist/node/search.js +1 -1
- package/dist/node/vite.d.ts +4 -0
- package/dist/node/vite.js +38 -2
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/src/client/app/components/sandbox/SandboxVue3.vue +19 -0
- package/src/client/app/style/main.pcss +1 -1
- package/src/client/app/style/sandbox.css +2 -4
- package/src/client/app/types.ts +0 -1
- package/src/client/bundle-sandbox.js +0 -1
- package/src/client/server/vue3/run.ts +6 -0
- package/src/node/config.ts +9 -0
- package/src/node/search.ts +1 -1
- package/src/node/vite.ts +37 -2
|
@@ -18,6 +18,7 @@ import { Text, vModelText, vModelSelect, vModelRadio, vModelCheckbox, vModelDyna
|
|
|
18
18
|
import { pascal } from "case";
|
|
19
19
|
import { a as applyStateToVariant } from "./state.js";
|
|
20
20
|
import * as setup from "$histoire-setup";
|
|
21
|
+
import * as generatedSetup from "$histoire-generated-global-setup";
|
|
21
22
|
function indent(lines, count = 1) {
|
|
22
23
|
return lines.map((line) => `${" ".repeat(count)}${line}`);
|
|
23
24
|
}
|
|
@@ -580,7 +581,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
580
581
|
default: defaultValue
|
|
581
582
|
});
|
|
582
583
|
if ((_c2 = (_b2 = (_a2 = props.variant.state) == null ? void 0 : _a2._hPropState) == null ? void 0 : _b2[index]) == null ? void 0 : _c2[key]) {
|
|
584
|
+
if (!vnode.props) {
|
|
585
|
+
vnode.props = {};
|
|
586
|
+
}
|
|
583
587
|
vnode.props[key] = props.variant.state._hPropState[index][key];
|
|
588
|
+
if (!vnode.dynamicProps) {
|
|
589
|
+
vnode.dynamicProps = [];
|
|
590
|
+
}
|
|
591
|
+
if (!vnode.dynamicProps.includes(key)) {
|
|
592
|
+
vnode.dynamicProps.push(key);
|
|
593
|
+
}
|
|
584
594
|
}
|
|
585
595
|
}
|
|
586
596
|
return {
|
|
@@ -605,6 +615,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
605
615
|
return vnodes;
|
|
606
616
|
}
|
|
607
617
|
});
|
|
618
|
+
if (typeof (generatedSetup == null ? void 0 : generatedSetup.setupVue3) === "function") {
|
|
619
|
+
await generatedSetup.setupVue3({
|
|
620
|
+
app,
|
|
621
|
+
story: props.story,
|
|
622
|
+
variant: props.variant
|
|
623
|
+
});
|
|
624
|
+
}
|
|
608
625
|
if (typeof (setup == null ? void 0 : setup.setupVue3) === "function") {
|
|
609
626
|
await setup.setupVue3({
|
|
610
627
|
app,
|
|
@@ -5,6 +5,8 @@ import { getTagName } from '../../codegen/vue3'
|
|
|
5
5
|
import { applyStateToVariant } from '../../util/state'
|
|
6
6
|
// @ts-expect-error virtual module id
|
|
7
7
|
import * as setup from '$histoire-setup'
|
|
8
|
+
// @ts-expect-error virtual module id
|
|
9
|
+
import * as generatedSetup from '$histoire-generated-global-setup'
|
|
8
10
|
|
|
9
11
|
const props = defineProps({
|
|
10
12
|
variant: {
|
|
@@ -85,7 +87,16 @@ async function mountVariant () {
|
|
|
85
87
|
|
|
86
88
|
// Props overrides
|
|
87
89
|
if (props.variant.state?._hPropState?.[index]?.[key]) {
|
|
90
|
+
if (!vnode.props) {
|
|
91
|
+
vnode.props = {}
|
|
92
|
+
}
|
|
88
93
|
vnode.props[key] = props.variant.state._hPropState[index][key]
|
|
94
|
+
if (!vnode.dynamicProps) {
|
|
95
|
+
vnode.dynamicProps = []
|
|
96
|
+
}
|
|
97
|
+
if (!vnode.dynamicProps.includes(key)) {
|
|
98
|
+
vnode.dynamicProps.push(key)
|
|
99
|
+
}
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
102
|
|
|
@@ -114,6 +125,14 @@ async function mountVariant () {
|
|
|
114
125
|
},
|
|
115
126
|
})
|
|
116
127
|
|
|
128
|
+
if (typeof generatedSetup?.setupVue3 === 'function') {
|
|
129
|
+
await generatedSetup.setupVue3({
|
|
130
|
+
app,
|
|
131
|
+
story: props.story,
|
|
132
|
+
variant: props.variant,
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
117
136
|
if (typeof setup?.setupVue3 === 'function') {
|
|
118
137
|
await setup.setupVue3({
|
|
119
138
|
app,
|
|
@@ -4,6 +4,8 @@ import Story from './Story.vue';
|
|
|
4
4
|
import Variant from './Variant.vue';
|
|
5
5
|
// @ts-expect-error virtual module id
|
|
6
6
|
import * as setup from '$histoire-setup';
|
|
7
|
+
// @ts-expect-error virtual module id
|
|
8
|
+
import * as generatedSetup from '$histoire-generated-global-setup';
|
|
7
9
|
export async function run({ file, storyData, el }) {
|
|
8
10
|
const { default: Comp } = await import(file.moduleId);
|
|
9
11
|
const app = createApp({
|
|
@@ -19,6 +21,9 @@ export async function run({ file, storyData, el }) {
|
|
|
19
21
|
});
|
|
20
22
|
},
|
|
21
23
|
});
|
|
24
|
+
if (typeof generatedSetup?.setupVue3 === 'function') {
|
|
25
|
+
await generatedSetup.setupVue3({ app });
|
|
26
|
+
}
|
|
22
27
|
if (typeof setup?.setupVue3 === 'function') {
|
|
23
28
|
await setup.setupVue3({ app });
|
|
24
29
|
}
|
package/dist/node/config.d.ts
CHANGED
|
@@ -106,6 +106,10 @@ export interface HistoireConfig {
|
|
|
106
106
|
* Example: `'/src/histoire-setup.ts'`
|
|
107
107
|
*/
|
|
108
108
|
setupFile?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Setup code created by plugins
|
|
111
|
+
*/
|
|
112
|
+
setupCode?: string[];
|
|
109
113
|
/**
|
|
110
114
|
* Predefined responsive sizes for story playgrounds.
|
|
111
115
|
*/
|
package/dist/node/config.js
CHANGED
|
@@ -156,6 +156,10 @@ export const mergeConfig = createDefu((obj, key, value) => {
|
|
|
156
156
|
}
|
|
157
157
|
return true;
|
|
158
158
|
}
|
|
159
|
+
if (obj[key] && key === 'setupCode') {
|
|
160
|
+
obj[key] = [...obj[key], ...value];
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
159
163
|
// By default, arrays should be replaced
|
|
160
164
|
if (obj[key] && Array.isArray(obj[key])) {
|
|
161
165
|
obj[key] = value;
|
package/dist/node/search.js
CHANGED
|
@@ -80,7 +80,7 @@ const exportKeys = new Set([
|
|
|
80
80
|
]);
|
|
81
81
|
async function exportSearchIndex(index) {
|
|
82
82
|
// eslint-disable-next-line no-async-promise-executor
|
|
83
|
-
return new Promise(async (resolve
|
|
83
|
+
return new Promise(async (resolve) => {
|
|
84
84
|
const exportedData = {};
|
|
85
85
|
const exportedKeys = new Set();
|
|
86
86
|
await index.export((key, data) => {
|
package/dist/node/vite.d.ts
CHANGED
|
@@ -12,5 +12,9 @@ export declare const SEARCH_TITLE_DATA_ID = "$histoire-search-title-data";
|
|
|
12
12
|
export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
|
|
13
13
|
export declare const SEARCH_DOCS_DATA_ID = "$histoire-search-docs-data";
|
|
14
14
|
export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
|
|
15
|
+
export declare const GENERATED_GLOBAL_SETUP = "$histoire-generated-global-setup";
|
|
16
|
+
export declare const RESOLVED_GENERATED_GLOBAL_SETUP: string;
|
|
17
|
+
export declare const GENERATED_SETUP_CODE = "$histoire-generated-setup-code";
|
|
18
|
+
export declare const RESOLVED_GENERATED_SETUP_CODE: string;
|
|
15
19
|
export declare function resolveViteConfig(ctx: Context): Promise<ResolvedConfig>;
|
|
16
20
|
export declare function getViteConfigWithPlugins(server: boolean, ctx: Context): Promise<InlineConfig>;
|
package/dist/node/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
|
-
import { relative, dirname } from 'pathe';
|
|
2
|
+
import { relative, dirname, resolve } from 'pathe';
|
|
3
3
|
import { resolveConfig as resolveViteConfigInternal, mergeConfig as mergeViteConfig, } from 'vite';
|
|
4
4
|
import { lookup as lookupMime } from 'mrmime';
|
|
5
5
|
import { APP_PATH, DIST_PATH, TEMP_PATH } from './alias.js';
|
|
@@ -21,6 +21,10 @@ export const SEARCH_TITLE_DATA_ID = '$histoire-search-title-data';
|
|
|
21
21
|
export const RESOLVED_SEARCH_TITLE_DATA_ID = `/${SEARCH_TITLE_DATA_ID}-resolved`;
|
|
22
22
|
export const SEARCH_DOCS_DATA_ID = '$histoire-search-docs-data';
|
|
23
23
|
export const RESOLVED_SEARCH_DOCS_DATA_ID = `/${SEARCH_DOCS_DATA_ID}-resolved`;
|
|
24
|
+
export const GENERATED_GLOBAL_SETUP = '$histoire-generated-global-setup';
|
|
25
|
+
export const RESOLVED_GENERATED_GLOBAL_SETUP = `/${GENERATED_GLOBAL_SETUP}-resolved`;
|
|
26
|
+
export const GENERATED_SETUP_CODE = '$histoire-generated-setup-code';
|
|
27
|
+
export const RESOLVED_GENERATED_SETUP_CODE = `/${GENERATED_SETUP_CODE}-resolved`;
|
|
24
28
|
export async function resolveViteConfig(ctx) {
|
|
25
29
|
const command = ctx.mode === 'dev' ? 'serve' : 'build';
|
|
26
30
|
let viteConfig = (await resolveViteConfigInternal({}, command));
|
|
@@ -86,7 +90,7 @@ export async function getViteConfigWithPlugins(server, ctx) {
|
|
|
86
90
|
}
|
|
87
91
|
if (id.startsWith(SETUP_ID)) {
|
|
88
92
|
if (ctx.config.setupFile) {
|
|
89
|
-
return this.resolve(ctx.config.setupFile, importer, {
|
|
93
|
+
return this.resolve(resolve(ctx.root, ctx.config.setupFile), importer, {
|
|
90
94
|
skipSelf: true,
|
|
91
95
|
});
|
|
92
96
|
}
|
|
@@ -106,6 +110,13 @@ export async function getViteConfigWithPlugins(server, ctx) {
|
|
|
106
110
|
if (id.startsWith(SEARCH_DOCS_DATA_ID)) {
|
|
107
111
|
return RESOLVED_SEARCH_DOCS_DATA_ID;
|
|
108
112
|
}
|
|
113
|
+
if (id.startsWith(GENERATED_GLOBAL_SETUP)) {
|
|
114
|
+
return RESOLVED_GENERATED_GLOBAL_SETUP;
|
|
115
|
+
}
|
|
116
|
+
if (id.startsWith(GENERATED_SETUP_CODE)) {
|
|
117
|
+
const [, index] = id.split('__');
|
|
118
|
+
return `${RESOLVED_GENERATED_SETUP_CODE}__${index}`;
|
|
119
|
+
}
|
|
109
120
|
},
|
|
110
121
|
async load(id) {
|
|
111
122
|
if (id === RESOLVED_STORIES_ID) {
|
|
@@ -171,6 +182,31 @@ if (import.meta.hot) {
|
|
|
171
182
|
if (id === RESOLVED_SEARCH_DOCS_DATA_ID) {
|
|
172
183
|
return getSearchDataJS(await generateDocSearchData(ctx));
|
|
173
184
|
}
|
|
185
|
+
if (id === RESOLVED_GENERATED_GLOBAL_SETUP) {
|
|
186
|
+
if (ctx.config.setupCode) {
|
|
187
|
+
return [
|
|
188
|
+
// Import
|
|
189
|
+
`${ctx.config.setupCode.map((c, index) => `import * as setup_${index} from '${GENERATED_SETUP_CODE}__${index}'`).join('\n')}`,
|
|
190
|
+
// List
|
|
191
|
+
`const setupList = [${ctx.config.setupCode.map((c, index) => `setup_${index}`).join(', ')}]`,
|
|
192
|
+
// Setups
|
|
193
|
+
['setupVue3'].map(fnName => `export async function ${fnName} (payload) {
|
|
194
|
+
for (const setup of setupList) {
|
|
195
|
+
if (setup?.${fnName}) {
|
|
196
|
+
await setup.${fnName}(payload)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}`),
|
|
200
|
+
].join('\n');
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
return '';
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (id.startsWith(RESOLVED_GENERATED_SETUP_CODE)) {
|
|
207
|
+
const [, index] = id.split('__');
|
|
208
|
+
return ctx.config.setupCode?.[index] ?? '';
|
|
209
|
+
}
|
|
174
210
|
},
|
|
175
211
|
handleHotUpdate(updateContext) {
|
|
176
212
|
const story = ctx.storyFiles.find(file => file.path === updateContext.file);
|
package/dist/style.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"histoire": "./bin.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@histoire/controls": "^0.6.
|
|
36
|
+
"@histoire/controls": "^0.6.4",
|
|
37
37
|
"@iconify/vue": "^3.2.1",
|
|
38
38
|
"@types/markdown-it": "^12.2.3",
|
|
39
39
|
"@vueuse/core": "^8.2.5",
|
|
@@ -5,6 +5,8 @@ import { getTagName } from '../../codegen/vue3'
|
|
|
5
5
|
import { applyStateToVariant } from '../../util/state'
|
|
6
6
|
// @ts-expect-error virtual module id
|
|
7
7
|
import * as setup from '$histoire-setup'
|
|
8
|
+
// @ts-expect-error virtual module id
|
|
9
|
+
import * as generatedSetup from '$histoire-generated-global-setup'
|
|
8
10
|
|
|
9
11
|
const props = defineProps({
|
|
10
12
|
variant: {
|
|
@@ -85,7 +87,16 @@ async function mountVariant () {
|
|
|
85
87
|
|
|
86
88
|
// Props overrides
|
|
87
89
|
if (props.variant.state?._hPropState?.[index]?.[key]) {
|
|
90
|
+
if (!vnode.props) {
|
|
91
|
+
vnode.props = {}
|
|
92
|
+
}
|
|
88
93
|
vnode.props[key] = props.variant.state._hPropState[index][key]
|
|
94
|
+
if (!vnode.dynamicProps) {
|
|
95
|
+
vnode.dynamicProps = []
|
|
96
|
+
}
|
|
97
|
+
if (!vnode.dynamicProps.includes(key)) {
|
|
98
|
+
vnode.dynamicProps.push(key)
|
|
99
|
+
}
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
102
|
|
|
@@ -114,6 +125,14 @@ async function mountVariant () {
|
|
|
114
125
|
},
|
|
115
126
|
})
|
|
116
127
|
|
|
128
|
+
if (typeof generatedSetup?.setupVue3 === 'function') {
|
|
129
|
+
await generatedSetup.setupVue3({
|
|
130
|
+
app,
|
|
131
|
+
story: props.story,
|
|
132
|
+
variant: props.variant,
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
117
136
|
if (typeof setup?.setupVue3 === 'function') {
|
|
118
137
|
await setup.setupVue3({
|
|
119
138
|
app,
|
package/src/client/app/types.ts
CHANGED
|
@@ -5,6 +5,8 @@ import Story from './Story.vue'
|
|
|
5
5
|
import Variant from './Variant.vue'
|
|
6
6
|
// @ts-expect-error virtual module id
|
|
7
7
|
import * as setup from '$histoire-setup'
|
|
8
|
+
// @ts-expect-error virtual module id
|
|
9
|
+
import * as generatedSetup from '$histoire-generated-global-setup'
|
|
8
10
|
|
|
9
11
|
export async function run ({ file, storyData, el }: ServerRunPayload) {
|
|
10
12
|
const { default: Comp } = await import(file.moduleId)
|
|
@@ -23,6 +25,10 @@ export async function run ({ file, storyData, el }: ServerRunPayload) {
|
|
|
23
25
|
},
|
|
24
26
|
})
|
|
25
27
|
|
|
28
|
+
if (typeof generatedSetup?.setupVue3 === 'function') {
|
|
29
|
+
await generatedSetup.setupVue3({ app })
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
if (typeof setup?.setupVue3 === 'function') {
|
|
27
33
|
await setup.setupVue3({ app })
|
|
28
34
|
}
|
package/src/node/config.ts
CHANGED
|
@@ -125,6 +125,10 @@ export interface HistoireConfig {
|
|
|
125
125
|
* Example: `'/src/histoire-setup.ts'`
|
|
126
126
|
*/
|
|
127
127
|
setupFile?: string
|
|
128
|
+
/**
|
|
129
|
+
* Setup code created by plugins
|
|
130
|
+
*/
|
|
131
|
+
setupCode?: string[]
|
|
128
132
|
/**
|
|
129
133
|
* Predefined responsive sizes for story playgrounds.
|
|
130
134
|
*/
|
|
@@ -303,6 +307,11 @@ export const mergeConfig = createDefu((obj: any, key, value) => {
|
|
|
303
307
|
return true
|
|
304
308
|
}
|
|
305
309
|
|
|
310
|
+
if (obj[key] && key === 'setupCode') {
|
|
311
|
+
obj[key] = [...obj[key], ...value]
|
|
312
|
+
return true
|
|
313
|
+
}
|
|
314
|
+
|
|
306
315
|
// By default, arrays should be replaced
|
|
307
316
|
if (obj[key] && Array.isArray(obj[key])) {
|
|
308
317
|
obj[key] = value
|
package/src/node/search.ts
CHANGED
|
@@ -94,7 +94,7 @@ const exportKeys = new Set([
|
|
|
94
94
|
|
|
95
95
|
async function exportSearchIndex (index) {
|
|
96
96
|
// eslint-disable-next-line no-async-promise-executor
|
|
97
|
-
return new Promise(async (resolve
|
|
97
|
+
return new Promise(async (resolve) => {
|
|
98
98
|
const exportedData: Record<string, any> = {}
|
|
99
99
|
const exportedKeys = new Set<string>()
|
|
100
100
|
await index.export((key, data) => {
|
package/src/node/vite.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'module'
|
|
2
|
-
import { relative, dirname } from 'pathe'
|
|
2
|
+
import { relative, dirname, resolve } from 'pathe'
|
|
3
3
|
import {
|
|
4
4
|
resolveConfig as resolveViteConfigInternal,
|
|
5
5
|
Plugin as VitePlugin,
|
|
@@ -31,6 +31,10 @@ export const SEARCH_TITLE_DATA_ID = '$histoire-search-title-data'
|
|
|
31
31
|
export const RESOLVED_SEARCH_TITLE_DATA_ID = `/${SEARCH_TITLE_DATA_ID}-resolved`
|
|
32
32
|
export const SEARCH_DOCS_DATA_ID = '$histoire-search-docs-data'
|
|
33
33
|
export const RESOLVED_SEARCH_DOCS_DATA_ID = `/${SEARCH_DOCS_DATA_ID}-resolved`
|
|
34
|
+
export const GENERATED_GLOBAL_SETUP = '$histoire-generated-global-setup'
|
|
35
|
+
export const RESOLVED_GENERATED_GLOBAL_SETUP = `/${GENERATED_GLOBAL_SETUP}-resolved`
|
|
36
|
+
export const GENERATED_SETUP_CODE = '$histoire-generated-setup-code'
|
|
37
|
+
export const RESOLVED_GENERATED_SETUP_CODE = `/${GENERATED_SETUP_CODE}-resolved`
|
|
34
38
|
|
|
35
39
|
export async function resolveViteConfig (ctx: Context): Promise<ResolvedConfig> {
|
|
36
40
|
const command = ctx.mode === 'dev' ? 'serve' : 'build'
|
|
@@ -103,7 +107,7 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
|
|
|
103
107
|
}
|
|
104
108
|
if (id.startsWith(SETUP_ID)) {
|
|
105
109
|
if (ctx.config.setupFile) {
|
|
106
|
-
return this.resolve(ctx.config.setupFile, importer, {
|
|
110
|
+
return this.resolve(resolve(ctx.root, ctx.config.setupFile), importer, {
|
|
107
111
|
skipSelf: true,
|
|
108
112
|
})
|
|
109
113
|
} else {
|
|
@@ -122,6 +126,13 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
|
|
|
122
126
|
if (id.startsWith(SEARCH_DOCS_DATA_ID)) {
|
|
123
127
|
return RESOLVED_SEARCH_DOCS_DATA_ID
|
|
124
128
|
}
|
|
129
|
+
if (id.startsWith(GENERATED_GLOBAL_SETUP)) {
|
|
130
|
+
return RESOLVED_GENERATED_GLOBAL_SETUP
|
|
131
|
+
}
|
|
132
|
+
if (id.startsWith(GENERATED_SETUP_CODE)) {
|
|
133
|
+
const [, index] = id.split('__')
|
|
134
|
+
return `${RESOLVED_GENERATED_SETUP_CODE}__${index}`
|
|
135
|
+
}
|
|
125
136
|
},
|
|
126
137
|
|
|
127
138
|
async load (id) {
|
|
@@ -188,6 +199,30 @@ if (import.meta.hot) {
|
|
|
188
199
|
if (id === RESOLVED_SEARCH_DOCS_DATA_ID) {
|
|
189
200
|
return getSearchDataJS(await generateDocSearchData(ctx))
|
|
190
201
|
}
|
|
202
|
+
if (id === RESOLVED_GENERATED_GLOBAL_SETUP) {
|
|
203
|
+
if (ctx.config.setupCode) {
|
|
204
|
+
return [
|
|
205
|
+
// Import
|
|
206
|
+
`${ctx.config.setupCode.map((c, index) => `import * as setup_${index} from '${GENERATED_SETUP_CODE}__${index}'`).join('\n')}`,
|
|
207
|
+
// List
|
|
208
|
+
`const setupList = [${ctx.config.setupCode.map((c, index) => `setup_${index}`).join(', ')}]`,
|
|
209
|
+
// Setups
|
|
210
|
+
['setupVue3'].map(fnName => `export async function ${fnName} (payload) {
|
|
211
|
+
for (const setup of setupList) {
|
|
212
|
+
if (setup?.${fnName}) {
|
|
213
|
+
await setup.${fnName}(payload)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}`),
|
|
217
|
+
].join('\n')
|
|
218
|
+
} else {
|
|
219
|
+
return ''
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (id.startsWith(RESOLVED_GENERATED_SETUP_CODE)) {
|
|
223
|
+
const [, index] = id.split('__')
|
|
224
|
+
return ctx.config.setupCode?.[index] ?? ''
|
|
225
|
+
}
|
|
191
226
|
},
|
|
192
227
|
|
|
193
228
|
handleHotUpdate (updateContext) {
|