@storybook/svelte 11.0.0-alpha.7 → 11.0.0-alpha.8
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/_browser-chunks/chunk-JERPECF7.js +68 -0
- package/dist/_node-chunks/{chunk-IUSLW4WK.js → chunk-5AP4EINI.js} +6 -6
- package/dist/_node-chunks/{chunk-MYOHBO2T.js → chunk-H7NN6AMU.js} +204 -84
- package/dist/_node-chunks/{parsers-MYBB7UC2.js → parsers-B3TUDVKM.js} +6 -6
- package/dist/_node-chunks/{walk-DL4OJGQB.js → walk-UNPFNDYR.js} +6 -6
- package/dist/chunk-C7Fmzjt_.d.ts +248 -0
- package/dist/docgen/docgen-worker.js +7 -7
- package/dist/entry-preview-docs.js +3 -55
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -2
- package/dist/preset.js +8 -8
- package/dist/svelte-csf/addon-check.js +6 -6
- package/dist/svelte-csf/compiler/transform.d.ts +9 -9
- package/dist/svelte-csf/compiler/transform.js +90 -86
- package/dist/svelte-csf/indexer/index.js +39 -43
- package/dist/svelte-csf/runtime/component-helpers.d.ts +1 -1
- package/dist/svelte-csf/runtime/create-runtime-stories.d.ts +1 -1
- package/package.json +2 -2
- package/dist/chunk-C5ZpXlin.d.ts +0 -138
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-4BE7D4DS.js";
|
|
4
|
+
|
|
5
|
+
// src/entry-preview-docs.ts
|
|
6
|
+
var entry_preview_docs_exports = {};
|
|
7
|
+
__export(entry_preview_docs_exports, {
|
|
8
|
+
decorators: () => decorators
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// src/docs/sourceDecorator.ts
|
|
12
|
+
import { SourceType } from "storybook/internal/docs-tools";
|
|
13
|
+
import { emitTransformCode, useEffect, useRef } from "storybook/preview-api";
|
|
14
|
+
var skipSourceRender = (context) => {
|
|
15
|
+
let sourceParams = context?.parameters.docs?.source, isArgsStory = context?.parameters.__isArgsStory;
|
|
16
|
+
return (context?.tags ?? []).some((tag) => tag.startsWith("svelte-csf")) ? !0 : sourceParams?.type === SourceType.DYNAMIC ? !1 : !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;
|
|
17
|
+
};
|
|
18
|
+
function toSvelteProperty(key, value, argTypes) {
|
|
19
|
+
if (value == null)
|
|
20
|
+
return null;
|
|
21
|
+
let argType = argTypes[key];
|
|
22
|
+
return argType && argType.action ? null : value === !0 ? key : typeof value == "string" ? `${key}=${JSON.stringify(value)}` : typeof value == "function" ? `${key}={<handler>}` : `${key}={${JSON.stringify(value)}}`;
|
|
23
|
+
}
|
|
24
|
+
function getComponentName(component) {
|
|
25
|
+
if (component == null)
|
|
26
|
+
return null;
|
|
27
|
+
let { __docgen = {} } = component, { name } = __docgen;
|
|
28
|
+
return name ? (name.endsWith(".svelte") && (name = name.substring(0, name.length - 7)), name) : component.name;
|
|
29
|
+
}
|
|
30
|
+
function generateSvelteSource(component, args, argTypes, slotProperty) {
|
|
31
|
+
let name = getComponentName(component);
|
|
32
|
+
if (!name)
|
|
33
|
+
return null;
|
|
34
|
+
let propsArray = Object.entries(args).filter(([k]) => k !== slotProperty).map(([k, v]) => toSvelteProperty(k, v, argTypes)).filter((p) => p), props = propsArray.join(" "), multiline = props.length > 50, slotValue = slotProperty ? args[slotProperty] : null, srcStart = multiline ? `<${name}
|
|
35
|
+
${propsArray.join(`
|
|
36
|
+
`)}` : `<${name} ${props}`;
|
|
37
|
+
return slotValue ? `${srcStart}>
|
|
38
|
+
${slotValue}
|
|
39
|
+
</${name}>` : `${srcStart}/>`;
|
|
40
|
+
}
|
|
41
|
+
function getWrapperProperties(component) {
|
|
42
|
+
let { __docgen } = component || {};
|
|
43
|
+
return __docgen ? __docgen.keywords?.find((kw) => kw.name === "wrapper") ? { wrapper: !0, slotProperty: __docgen.data?.find(
|
|
44
|
+
(prop) => prop.keywords.find((kw) => kw.name === "slot")
|
|
45
|
+
)?.name } : { wrapper: !1 } : { wrapper: !1 };
|
|
46
|
+
}
|
|
47
|
+
var sourceDecorator = (storyFn, context) => {
|
|
48
|
+
let skip = skipSourceRender(context), story = storyFn(), source = useRef(void 0);
|
|
49
|
+
return useEffect(() => {
|
|
50
|
+
if (skip)
|
|
51
|
+
return;
|
|
52
|
+
let { args = {}, component: ctxComponent } = context || {}, { Component: component } = context.originalStoryFn(
|
|
53
|
+
args,
|
|
54
|
+
context
|
|
55
|
+
), { wrapper, slotProperty } = getWrapperProperties(component);
|
|
56
|
+
wrapper && (component = ctxComponent);
|
|
57
|
+
let generated = generateSvelteSource(component, args, context?.argTypes, slotProperty);
|
|
58
|
+
generated && source.current !== generated && (emitTransformCode(generated, context), source.current = generated);
|
|
59
|
+
}), story;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/entry-preview-docs.ts
|
|
63
|
+
var decorators = [sourceDecorator];
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
decorators,
|
|
67
|
+
entry_preview_docs_exports
|
|
68
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_qyfvae71z7 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_qyfvae71z7 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_qyfvae71z7 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_qyfvae71z7.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_qyfvae71z7.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_qyfvae71z7.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_qyfvae71z7 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_qyfvae71z7 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_qyfvae71z7 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_qyfvae71z7.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_qyfvae71z7.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_qyfvae71z7.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -19,61 +19,6 @@ var SVELTE_CSF_TAG_PREFIX = "svelte-csf", SVELTE_CSF_V5_TAG = `${SVELTE_CSF_TAG_
|
|
|
19
19
|
SVELTE_CSF_RENDERER_IMPORT_SOURCE
|
|
20
20
|
], SVELTE_CSF_RUNTIME_STORIES_IMPORT_SOURCE = "@storybook/svelte/internal/svelte-csf/create-runtime-stories";
|
|
21
21
|
|
|
22
|
-
// src/svelte-csf/parser/ast.ts
|
|
23
|
-
import { compile } from "svelte/compiler";
|
|
24
|
-
function getSvelteAST(options) {
|
|
25
|
-
let { filename, code } = options, { ast } = compile(code, {
|
|
26
|
-
filename,
|
|
27
|
-
modernAst: !0
|
|
28
|
-
});
|
|
29
|
-
return ast;
|
|
30
|
-
}
|
|
31
|
-
function createASTProperty(name, value) {
|
|
32
|
-
return {
|
|
33
|
-
type: "Property",
|
|
34
|
-
kind: "init",
|
|
35
|
-
computed: !1,
|
|
36
|
-
method: !1,
|
|
37
|
-
shorthand: !1,
|
|
38
|
-
key: {
|
|
39
|
-
type: "Identifier",
|
|
40
|
-
name
|
|
41
|
-
},
|
|
42
|
-
value
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function createASTArrayExpression(elements = []) {
|
|
46
|
-
return {
|
|
47
|
-
type: "ArrayExpression",
|
|
48
|
-
elements
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function createASTObjectExpression(properties = []) {
|
|
52
|
-
return {
|
|
53
|
-
type: "ObjectExpression",
|
|
54
|
-
properties
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function appendASTProperty(node, property) {
|
|
58
|
-
node.properties = [...node.properties, property];
|
|
59
|
-
}
|
|
60
|
-
function createASTIdentifier(name) {
|
|
61
|
-
return {
|
|
62
|
-
type: "Identifier",
|
|
63
|
-
name
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function createASTExportSpecifier({
|
|
67
|
-
local,
|
|
68
|
-
exported
|
|
69
|
-
}) {
|
|
70
|
-
return {
|
|
71
|
-
type: "ExportSpecifier",
|
|
72
|
-
local: createASTIdentifier(local),
|
|
73
|
-
exported: createASTIdentifier(exported ?? local)
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
22
|
// src/svelte-csf/utils/error.ts
|
|
78
23
|
import url from "node:url";
|
|
79
24
|
import rendererPkg from "@storybook/svelte/package.json" with { type: "json" };
|
|
@@ -198,6 +143,7 @@ var BASE_INITIAL_SNIPPET = dedent`
|
|
|
198
143
|
</script>
|
|
199
144
|
|
|
200
145
|
In a SvelteKit project, import defineMeta from "${StorybookSvelteCSFError.sveltekitImportSource}".
|
|
146
|
+
With CSF factories, call preview.meta() in place of defineMeta(), with preview imported from '#.storybook/preview'.
|
|
201
147
|
`, MissingModuleTagError = class extends StorybookSvelteCSFError {
|
|
202
148
|
constructor(filename) {
|
|
203
149
|
super({ filename });
|
|
@@ -210,7 +156,7 @@ In a SvelteKit project, import defineMeta from "${StorybookSvelteCSFError.svelte
|
|
|
210
156
|
The file '${this.filepathURL}'
|
|
211
157
|
does not have a module context (<script module> ... </script>).
|
|
212
158
|
|
|
213
|
-
defineMeta(...) should be called inside a module script tag, like so:
|
|
159
|
+
defineMeta(...) or preview.meta(...) should be called inside a module script tag, like so:
|
|
214
160
|
|
|
215
161
|
${BASE_INITIAL_SNIPPET}
|
|
216
162
|
`;
|
|
@@ -243,7 +189,7 @@ In a SvelteKit project, import defineMeta from "${StorybookSvelteCSFError.svelte
|
|
|
243
189
|
template() {
|
|
244
190
|
return dedent`
|
|
245
191
|
The file '${this.filepathURL}'
|
|
246
|
-
does not import defineMeta from ${StorybookSvelteCSFError.importSourcesText} inside the module context.
|
|
192
|
+
does not import defineMeta from ${StorybookSvelteCSFError.importSourcesText}, or the preview from .storybook/preview, inside the module context.
|
|
247
193
|
|
|
248
194
|
Make sure to import defineMeta from the package and use it inside the module context like so:
|
|
249
195
|
|
|
@@ -260,7 +206,7 @@ In a SvelteKit project, import defineMeta from "${StorybookSvelteCSFError.svelte
|
|
|
260
206
|
template() {
|
|
261
207
|
return dedent`
|
|
262
208
|
The file '${this.filepathURL}'
|
|
263
|
-
does not store the result of calling defineMeta()
|
|
209
|
+
does not store the result of calling defineMeta() or preview.meta(). While it might have been called,
|
|
264
210
|
it's return value needs to be stored and destructured for the parsing to succeed, eg.:
|
|
265
211
|
|
|
266
212
|
${BASE_INITIAL_SNIPPET}
|
|
@@ -269,18 +215,18 @@ In a SvelteKit project, import defineMeta from "${StorybookSvelteCSFError.svelte
|
|
|
269
215
|
}, NoStoryComponentDestructuredError = class extends StorybookSvelteCSFError {
|
|
270
216
|
constructor({
|
|
271
217
|
filename,
|
|
272
|
-
|
|
218
|
+
metaFunctionName
|
|
273
219
|
}) {
|
|
274
220
|
super({ filename });
|
|
275
221
|
this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
|
|
276
222
|
this.code = 5;
|
|
277
223
|
this.documentation = !0;
|
|
278
|
-
this.
|
|
224
|
+
this.metaFunctionName = metaFunctionName;
|
|
279
225
|
}
|
|
280
226
|
template() {
|
|
281
227
|
return dedent`
|
|
282
228
|
The file '${this.filepathURL}'
|
|
283
|
-
does not destructure the Story component from the '${this.
|
|
229
|
+
does not destructure the Story component from the '${this.metaFunctionName}({ ... })' function call.
|
|
284
230
|
eg.:
|
|
285
231
|
|
|
286
232
|
${BASE_INITIAL_SNIPPET}
|
|
@@ -300,7 +246,7 @@ In a SvelteKit project, import defineMeta from "${StorybookSvelteCSFError.svelte
|
|
|
300
246
|
template() {
|
|
301
247
|
return dedent`
|
|
302
248
|
The file '${this.filepathURL}'
|
|
303
|
-
passes an invalid first argument to the 'defineMeta' call.
|
|
249
|
+
passes an invalid first argument to the 'defineMeta' or 'preview.meta' call.
|
|
304
250
|
|
|
305
251
|
The first argument must be an object expression with the meta properties set.
|
|
306
252
|
`;
|
|
@@ -361,8 +307,115 @@ In a SvelteKit project, import defineMeta from "${StorybookSvelteCSFError.svelte
|
|
|
361
307
|
If the original error doesn't point to a problem in the stories file, please report it on the issue tracker on GitHub at https://github.com/storybookjs/storybook/issues/new?template=bug_report.yml.
|
|
362
308
|
`;
|
|
363
309
|
}
|
|
310
|
+
}, MixedMetaError = class extends StorybookSvelteCSFError {
|
|
311
|
+
constructor(filename) {
|
|
312
|
+
super({ filename });
|
|
313
|
+
this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
|
|
314
|
+
this.code = 10;
|
|
315
|
+
this.documentation = !0;
|
|
316
|
+
}
|
|
317
|
+
template() {
|
|
318
|
+
return dedent`
|
|
319
|
+
The file '${this.filepathURL}'
|
|
320
|
+
calls both defineMeta() and preview.meta(). A stories file can only have one meta.
|
|
321
|
+
Use preview.meta() for CSF factories, or defineMeta() otherwise.
|
|
322
|
+
`;
|
|
323
|
+
}
|
|
324
|
+
}, MultipleMetaError = class extends StorybookSvelteCSFError {
|
|
325
|
+
constructor(filename) {
|
|
326
|
+
super({ filename });
|
|
327
|
+
this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
|
|
328
|
+
this.code = 12;
|
|
329
|
+
this.documentation = !0;
|
|
330
|
+
}
|
|
331
|
+
template() {
|
|
332
|
+
return dedent`
|
|
333
|
+
The file '${this.filepathURL}'
|
|
334
|
+
calls preview.meta() more than once. A stories file can only have one meta.
|
|
335
|
+
Move the stories of each meta to their own stories file.
|
|
336
|
+
`;
|
|
337
|
+
}
|
|
338
|
+
}, PreviewNotImportedError = class extends StorybookSvelteCSFError {
|
|
339
|
+
constructor(filename) {
|
|
340
|
+
super({ filename });
|
|
341
|
+
this.category = StorybookSvelteCSFError.CATEGORY.parserExtractSvelte;
|
|
342
|
+
this.code = 11;
|
|
343
|
+
this.documentation = !0;
|
|
344
|
+
}
|
|
345
|
+
template() {
|
|
346
|
+
return dedent`
|
|
347
|
+
The file '${this.filepathURL}'
|
|
348
|
+
calls preview.meta(), but it doesn't import preview from the preview file of Storybook. Import it like so:
|
|
349
|
+
|
|
350
|
+
<script module>
|
|
351
|
+
import preview from '#.storybook/preview';
|
|
352
|
+
|
|
353
|
+
const { Story } = preview.meta({});
|
|
354
|
+
</script>
|
|
355
|
+
|
|
356
|
+
The import path must end with '/preview', with or without a file extension.
|
|
357
|
+
`;
|
|
358
|
+
}
|
|
364
359
|
};
|
|
365
360
|
|
|
361
|
+
// src/svelte-csf/parser/ast.ts
|
|
362
|
+
import { compile } from "svelte/compiler";
|
|
363
|
+
function getSvelteAST(options) {
|
|
364
|
+
let { filename, code } = options, { ast } = compile(code, {
|
|
365
|
+
filename,
|
|
366
|
+
modernAst: !0
|
|
367
|
+
});
|
|
368
|
+
return ast;
|
|
369
|
+
}
|
|
370
|
+
function createASTProperty(name, value) {
|
|
371
|
+
return {
|
|
372
|
+
type: "Property",
|
|
373
|
+
kind: "init",
|
|
374
|
+
computed: !1,
|
|
375
|
+
method: !1,
|
|
376
|
+
shorthand: !1,
|
|
377
|
+
key: {
|
|
378
|
+
type: "Identifier",
|
|
379
|
+
name
|
|
380
|
+
},
|
|
381
|
+
value
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
function createASTArrayExpression(elements = []) {
|
|
385
|
+
return {
|
|
386
|
+
type: "ArrayExpression",
|
|
387
|
+
elements
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function createASTObjectExpression(properties = []) {
|
|
391
|
+
return {
|
|
392
|
+
type: "ObjectExpression",
|
|
393
|
+
properties
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function appendASTProperty(node, property) {
|
|
397
|
+
node.properties = [...node.properties, property];
|
|
398
|
+
}
|
|
399
|
+
function createASTIdentifier(name) {
|
|
400
|
+
return {
|
|
401
|
+
type: "Identifier",
|
|
402
|
+
name
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function createASTExportSpecifier({
|
|
406
|
+
local,
|
|
407
|
+
exported
|
|
408
|
+
}) {
|
|
409
|
+
return {
|
|
410
|
+
type: "ExportSpecifier",
|
|
411
|
+
local: createASTIdentifier(local),
|
|
412
|
+
exported: createASTIdentifier(exported ?? local)
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// src/svelte-csf/utils/import-source.ts
|
|
417
|
+
import { isValidPreviewPath } from "storybook/internal/csf-tools";
|
|
418
|
+
|
|
366
419
|
// src/svelte-csf/utils/is-one-of.ts
|
|
367
420
|
function isOneOf(values, value) {
|
|
368
421
|
return values.some((candidate) => candidate === value);
|
|
@@ -372,14 +425,78 @@ function isOneOf(values, value) {
|
|
|
372
425
|
function isSvelteCsfImportSource(source) {
|
|
373
426
|
return typeof source == "string" && isOneOf(SVELTE_CSF_IMPORT_SOURCES, source);
|
|
374
427
|
}
|
|
375
|
-
function
|
|
376
|
-
let result = { hasDefaultOrNamespaceImport: !1 };
|
|
377
|
-
for (let statement of body)
|
|
378
|
-
if (
|
|
379
|
-
|
|
428
|
+
function findMetaImports(body) {
|
|
429
|
+
let result = { hasDefaultOrNamespaceImport: !1, previewNames: [] };
|
|
430
|
+
for (let statement of body) {
|
|
431
|
+
if (statement.type !== "ImportDeclaration")
|
|
432
|
+
continue;
|
|
433
|
+
let { source, specifiers } = statement;
|
|
434
|
+
if (typeof source.value == "string" && isValidPreviewPath(source.value)) {
|
|
435
|
+
result.previewNames.push(...specifiers.map((specifier) => specifier.local.name));
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
if (isSvelteCsfImportSource(source.value))
|
|
439
|
+
for (let specifier of specifiers)
|
|
380
440
|
specifier.type !== "ImportSpecifier" ? result.hasDefaultOrNamespaceImport = !0 : "name" in specifier.imported && specifier.imported.name === "defineMeta" && (result.defineMetaImport = specifier);
|
|
441
|
+
}
|
|
381
442
|
return result;
|
|
382
443
|
}
|
|
444
|
+
function hasMetaImport(imports) {
|
|
445
|
+
return !!imports.defineMetaImport || imports.previewNames.length > 0;
|
|
446
|
+
}
|
|
447
|
+
function findMeta(body, imports, filename) {
|
|
448
|
+
let meta;
|
|
449
|
+
for (let statement of body) {
|
|
450
|
+
if (statement.type !== "VariableDeclaration")
|
|
451
|
+
continue;
|
|
452
|
+
let { id, init: initWithTypeCalls } = statement.declarations[0], init = initWithTypeCalls && skipTypeCalls(initWithTypeCalls), functionName = init?.type === "CallExpression" ? getMetaFunctionName(init, imports, filename) : void 0;
|
|
453
|
+
if (init?.type === "CallExpression" && functionName) {
|
|
454
|
+
let isFactory = init.callee.type === "MemberExpression";
|
|
455
|
+
if (meta && meta.isFactory !== isFactory)
|
|
456
|
+
throw new MixedMetaError(filename);
|
|
457
|
+
if (meta?.isFactory)
|
|
458
|
+
throw new MultipleMetaError(filename);
|
|
459
|
+
meta = {
|
|
460
|
+
isFactory,
|
|
461
|
+
declaration: statement,
|
|
462
|
+
call: init,
|
|
463
|
+
functionName,
|
|
464
|
+
metaIdentifier: isFactory && id.type === "Identifier" ? id : void 0,
|
|
465
|
+
storyNames: findStoryNames(id)
|
|
466
|
+
};
|
|
467
|
+
} else if (meta?.metaIdentifier)
|
|
468
|
+
for (let declarator of statement.declarations) {
|
|
469
|
+
let metaReference = declarator.init && skipTypeCalls(declarator.init);
|
|
470
|
+
metaReference?.type === "Identifier" && metaReference.name === meta.metaIdentifier.name && meta.storyNames.push(...findStoryNames(declarator.id));
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return meta;
|
|
474
|
+
}
|
|
475
|
+
function getMetaFunctionName(call, imports, filename) {
|
|
476
|
+
let { callee } = call;
|
|
477
|
+
if (callee.type === "Identifier")
|
|
478
|
+
return callee.name === imports.defineMetaImport?.local.name ? callee.name : void 0;
|
|
479
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || callee.property.name !== "meta")
|
|
480
|
+
return;
|
|
481
|
+
let object = skipTypeCalls(callee.object);
|
|
482
|
+
if (object.type === "Identifier") {
|
|
483
|
+
if (imports.previewNames.includes(object.name))
|
|
484
|
+
return `${object.name}.meta`;
|
|
485
|
+
if (object.name === "preview")
|
|
486
|
+
throw new PreviewNotImportedError(filename);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function skipTypeCalls(expression) {
|
|
490
|
+
let current = expression;
|
|
491
|
+
for (; current.type === "CallExpression" && current.arguments.length === 0 && current.callee.type === "MemberExpression" && !current.callee.computed && current.callee.property.type === "Identifier" && current.callee.property.name === "type"; )
|
|
492
|
+
current = current.callee.object;
|
|
493
|
+
return current;
|
|
494
|
+
}
|
|
495
|
+
function findStoryNames(id) {
|
|
496
|
+
return id.type !== "ObjectPattern" ? [] : id.properties.flatMap(
|
|
497
|
+
(property) => property.type === "Property" && property.key.type === "Identifier" && property.key.name === "Story" && property.value.type === "Identifier" ? [property.value.name] : []
|
|
498
|
+
);
|
|
499
|
+
}
|
|
383
500
|
|
|
384
501
|
// src/svelte-csf/parser/extract/svelte/story/attributes.ts
|
|
385
502
|
function extractStoryAttributesNodes(options) {
|
|
@@ -869,7 +986,20 @@ export {
|
|
|
869
986
|
RUNTIME_STORIES_IDENTIFIER,
|
|
870
987
|
SVELTE_CSF_RUNTIME_STORIES_IMPORT_SOURCE,
|
|
871
988
|
isOneOf,
|
|
872
|
-
|
|
989
|
+
StorybookSvelteCSFError,
|
|
990
|
+
isStorybookSvelteCSFError,
|
|
991
|
+
MissingModuleTagError,
|
|
992
|
+
DefaultOrNamespaceImportUsedError,
|
|
993
|
+
MissingDefineMetaImportError,
|
|
994
|
+
MissingDefineMetaVariableDeclarationError,
|
|
995
|
+
NoStoryComponentDestructuredError,
|
|
996
|
+
GetDefineMetaFirstArgumentError,
|
|
997
|
+
InvalidStoryTemplateAttributeError,
|
|
998
|
+
IndexerParseError,
|
|
999
|
+
findMetaImports,
|
|
1000
|
+
hasMetaImport,
|
|
1001
|
+
findMeta,
|
|
1002
|
+
skipTypeCalls,
|
|
873
1003
|
getSvelteAST,
|
|
874
1004
|
createASTProperty,
|
|
875
1005
|
createASTArrayExpression,
|
|
@@ -878,8 +1008,6 @@ export {
|
|
|
878
1008
|
createASTIdentifier,
|
|
879
1009
|
createASTExportSpecifier,
|
|
880
1010
|
extractStoryAttributesNodes,
|
|
881
|
-
StorybookSvelteCSFError,
|
|
882
|
-
isStorybookSvelteCSFError,
|
|
883
1011
|
StoryTemplateAndChildrenError,
|
|
884
1012
|
StoryTemplateAndAsChildError,
|
|
885
1013
|
StoryAsChildWithoutChildrenError,
|
|
@@ -892,13 +1020,5 @@ export {
|
|
|
892
1020
|
NoArrayExpressionError,
|
|
893
1021
|
ArrayElementNotStringError,
|
|
894
1022
|
InvalidRenderValueError,
|
|
895
|
-
MissingModuleTagError,
|
|
896
|
-
DefaultOrNamespaceImportUsedError,
|
|
897
|
-
MissingDefineMetaImportError,
|
|
898
|
-
MissingDefineMetaVariableDeclarationError,
|
|
899
|
-
NoStoryComponentDestructuredError,
|
|
900
|
-
GetDefineMetaFirstArgumentError,
|
|
901
|
-
InvalidStoryTemplateAttributeError,
|
|
902
|
-
IndexerParseError,
|
|
903
1023
|
extractStoryTemplateSnippetBlock
|
|
904
1024
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_qyfvae71z7 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_qyfvae71z7 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_qyfvae71z7 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_qyfvae71z7.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_qyfvae71z7.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_qyfvae71z7.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_qyfvae71z7 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_qyfvae71z7 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_qyfvae71z7 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_qyfvae71z7.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_qyfvae71z7.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_qyfvae71z7.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|