@storybook/svelte 11.0.0-beta.5 → 11.0.0-rc.1
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/_node-chunks/{build-docgen-4CLD5RKH.js → build-docgen-IN2KQQ7N.js} +14 -129
- package/dist/_node-chunks/chunk-5PSMHZ5O.js +131 -0
- package/dist/_node-chunks/{chunk-EZI5LVNW.js → chunk-DHQULEOF.js} +1 -1
- package/dist/_node-chunks/{chunk-3JLJMGBT.js → chunk-OAEBQIZS.js} +5 -7
- package/dist/_node-chunks/chunk-RLLUKTHS.js +15 -0
- package/dist/_node-chunks/{chunk-XLMS4YUB.js → chunk-XXIY25TZ.js} +12 -8
- package/dist/_node-chunks/{svelte-project-manager-Q35NEAHT.js → svelte-project-manager-UM2UGPYV.js} +2 -1
- package/dist/docgen/component-docgen/svelte2tsx/generate-docgen.js +2 -1
- package/dist/docgen/docgen-worker.js +2 -2
- package/dist/preset.js +58 -15
- package/dist/svelte-csf/compiler/transform.js +6 -3
- package/package.json +2 -2
- package/template/components/index.js +0 -2
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
parseSvelteSource
|
|
6
|
-
} from "./chunk-2Z47YIHP.js";
|
|
2
|
+
resolveStoryComponent,
|
|
3
|
+
resolveStorySubcomponents
|
|
4
|
+
} from "./chunk-5PSMHZ5O.js";
|
|
7
5
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
UNPRINTABLE_DEFAULT
|
|
7
|
+
} from "./chunk-OAEBQIZS.js";
|
|
8
|
+
import "./chunk-RLLUKTHS.js";
|
|
9
|
+
import "./chunk-2Z47YIHP.js";
|
|
10
|
+
import "./chunk-XXIY25TZ.js";
|
|
11
11
|
import "./chunk-FZFWZSUN.js";
|
|
12
12
|
|
|
13
13
|
// src/docgen/component-docgen/build-docgen.ts
|
|
14
|
-
import { readFile
|
|
15
|
-
import { resolve
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
15
|
+
import { resolve } from "node:path";
|
|
16
16
|
import { preprocess } from "svelte/compiler";
|
|
17
17
|
import {
|
|
18
18
|
componentPathFromStory,
|
|
19
19
|
getComponentIdFromEntry,
|
|
20
|
-
getStoryImportPathFromEntry
|
|
20
|
+
getStoryImportPathFromEntry
|
|
21
21
|
} from "storybook/internal/common";
|
|
22
22
|
import { extractComponentDescription } from "storybook/internal/csf-tools";
|
|
23
23
|
|
|
@@ -209,124 +209,9 @@ function createServerArgTypes(docgen) {
|
|
|
209
209
|
return argTypes;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
// src/docgen/component-docgen/resolve-component/resolve-component.ts
|
|
213
|
-
import { readFileSync } from "node:fs";
|
|
214
|
-
import { readFile } from "node:fs/promises";
|
|
215
|
-
import { resolve } from "node:path";
|
|
216
|
-
import {
|
|
217
|
-
createComponentNodeResolver,
|
|
218
|
-
createModuleResolver,
|
|
219
|
-
defaultResolveConditionNames,
|
|
220
|
-
extractDeclaredSubcomponents,
|
|
221
|
-
extractSubcomponents,
|
|
222
|
-
getStoryImportPathFromEntry,
|
|
223
|
-
jsTsSourceExtensions,
|
|
224
|
-
typescriptExtensionAlias
|
|
225
|
-
} from "storybook/internal/common";
|
|
226
|
-
import {
|
|
227
|
-
SourceEditor,
|
|
228
|
-
loadCsf,
|
|
229
|
-
parseExpression,
|
|
230
|
-
propertyValue
|
|
231
|
-
} from "storybook/internal/csf-tools";
|
|
232
|
-
var moduleResolver = createModuleResolver({
|
|
233
|
-
extensions: [".svelte", ...jsTsSourceExtensions],
|
|
234
|
-
// TypeScript projects import `./index.ts` as `./index.js`, as SvelteKit's packaging requires.
|
|
235
|
-
extensionAlias: typescriptExtensionAlias,
|
|
236
|
-
mainFields: ["svelte", "module", "main"],
|
|
237
|
-
// Core's conditions plus `svelte`, so a `storybook` entry resolves as it does in the preview.
|
|
238
|
-
conditionNames: ["svelte", ...defaultResolveConditionNames],
|
|
239
|
-
tsconfig: "auto"
|
|
240
|
-
});
|
|
241
|
-
function moduleEditor(filePath) {
|
|
242
|
-
try {
|
|
243
|
-
let file = readFileSync(filePath, "utf8");
|
|
244
|
-
if (!filePath.endsWith(".svelte")) return new SourceEditor(file, filePath);
|
|
245
|
-
let { source, ast } = parseSvelteSource(file), module = ast.module?.content;
|
|
246
|
-
return module && new SourceEditor(source.slice(module.start, module.end), `${filePath}.ts`);
|
|
247
|
-
} catch {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
function readModule(filePath) {
|
|
252
|
-
let editor = moduleEditor(filePath);
|
|
253
|
-
return editor && { editor, filePath };
|
|
254
|
-
}
|
|
255
|
-
var isComponent = (filePath, exportName) => filePath.endsWith(".svelte") && exportName === "default", exportReader = {
|
|
256
|
-
resolver: moduleResolver,
|
|
257
|
-
readModule,
|
|
258
|
-
ownsExport: isComponent
|
|
259
|
-
}, resolveComponentExpression = createComponentNodeResolver({ reader: exportReader }), unresolved = (specifier, exportName) => new Error(`Could not resolve \`${specifier}\` export \`${exportName}\``);
|
|
260
|
-
async function readStoryFile(entry) {
|
|
261
|
-
let importPath = getStoryImportPathFromEntry(entry);
|
|
262
|
-
if (!importPath) return;
|
|
263
|
-
let storyPath = resolve(importPath), file = await readFile(storyPath, "utf8");
|
|
264
|
-
return storyPath.endsWith(".svelte") ? { storyPath, ...await readSvelteMeta(file, storyPath) } : { storyPath, csf: loadCsf(file, { makeTitle: () => entry.title }).parse() };
|
|
265
|
-
}
|
|
266
|
-
function resolveComponentNode(story, node) {
|
|
267
|
-
let { module, meta } = "csf" in story ? {
|
|
268
|
-
module: { editor: story.csf.editor, filePath: story.storyPath },
|
|
269
|
-
meta: story.csf._metaAnnotations.component
|
|
270
|
-
} : { module: story.module, meta: propertyValue(story.meta, "component") }, expression = node ?? meta;
|
|
271
|
-
if (!expression) return;
|
|
272
|
-
let resolved = resolveComponentExpression(module, expression);
|
|
273
|
-
if ("reason" in resolved)
|
|
274
|
-
switch (resolved.reason) {
|
|
275
|
-
case "unreadable-component-expression":
|
|
276
|
-
throw new Error(`Cannot resolve the component \`${resolved.expression}\``);
|
|
277
|
-
case "missing-export":
|
|
278
|
-
throw unresolved(resolved.importId, resolved.exportName);
|
|
279
|
-
case "no-meta-component":
|
|
280
|
-
case "no-component-import":
|
|
281
|
-
return;
|
|
282
|
-
default: {
|
|
283
|
-
let unhandled = resolved;
|
|
284
|
-
throw new Error(`Unhandled resolution ${JSON.stringify(unhandled)}`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
let { importId, path, exportName, localName } = resolved.component;
|
|
288
|
-
if (importId) {
|
|
289
|
-
if (!path || !isComponent(path, exportName)) throw unresolved(importId, exportName);
|
|
290
|
-
return { componentPath: path, exportName, name: localName };
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
async function resolveStoryComponent(entry) {
|
|
294
|
-
let story = await readStoryFile(entry);
|
|
295
|
-
return story && resolveComponentNode(story);
|
|
296
|
-
}
|
|
297
|
-
async function resolveStorySubcomponents(entry) {
|
|
298
|
-
let story = await readStoryFile(entry);
|
|
299
|
-
if (!story) return {};
|
|
300
|
-
let declared = "csf" in story ? extractDeclaredSubcomponents(story.csf) : extractSubcomponents(
|
|
301
|
-
propertyValue(story.meta, "subcomponents"),
|
|
302
|
-
story.module.editor.program
|
|
303
|
-
), resolved = {};
|
|
304
|
-
for (let { name, node } of declared)
|
|
305
|
-
try {
|
|
306
|
-
let component = resolveComponentNode(story, node);
|
|
307
|
-
component && (resolved[name] = { ...component, name });
|
|
308
|
-
} catch {
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
return resolved;
|
|
312
|
-
}
|
|
313
|
-
async function readSvelteMeta(file, storyPath) {
|
|
314
|
-
let { source, ast } = parseSvelteSource(file), nodes = await extractSvelteASTNodes({ ast, filename: storyPath }), { start, end } = getDefineMetaFirstArgumentObjectExpression({
|
|
315
|
-
nodes,
|
|
316
|
-
filename: storyPath
|
|
317
|
-
}), script = ast.module.content, meta = parseExpression(source.slice(start, end));
|
|
318
|
-
return {
|
|
319
|
-
meta: meta.type === "ObjectExpression" ? meta : void 0,
|
|
320
|
-
module: {
|
|
321
|
-
editor: new SourceEditor(source.slice(script.start, script.end), `${storyPath}.ts`),
|
|
322
|
-
filePath: storyPath
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
|
|
327
212
|
// src/docgen/component-docgen/build-docgen.ts
|
|
328
213
|
async function buildDocgenPayload(input, context) {
|
|
329
|
-
let path =
|
|
214
|
+
let path = getStoryImportPathFromEntry(input.entry);
|
|
330
215
|
if (!path) return;
|
|
331
216
|
let base = {
|
|
332
217
|
id: getComponentIdFromEntry(input.entry),
|
|
@@ -345,7 +230,7 @@ async function buildDocgenPayload(input, context) {
|
|
|
345
230
|
try {
|
|
346
231
|
subcomponents[name] = {
|
|
347
232
|
name,
|
|
348
|
-
path: componentPathFromStory(path,
|
|
233
|
+
path: componentPathFromStory(path, resolve(path), subcomponent.componentPath),
|
|
349
234
|
...await componentDocs(subcomponent.componentPath, name, context)
|
|
350
235
|
};
|
|
351
236
|
} catch {
|
|
@@ -368,7 +253,7 @@ async function buildDocgenPayload(input, context) {
|
|
|
368
253
|
}
|
|
369
254
|
}
|
|
370
255
|
async function componentDocs(componentPath, name, context) {
|
|
371
|
-
let source = await
|
|
256
|
+
let source = await readFile(componentPath, "utf8"), documentationSource = await preprocess(source, { style: () => ({ code: "" }) }), docgen = context.componentMetaManager.generateDocgen(componentPath, {
|
|
372
257
|
server: !0,
|
|
373
258
|
documentationSource: documentationSource.code
|
|
374
259
|
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseSvelteSource
|
|
3
|
+
} from "./chunk-2Z47YIHP.js";
|
|
4
|
+
import {
|
|
5
|
+
extractSvelteASTNodes,
|
|
6
|
+
getDefineMetaFirstArgumentObjectExpression
|
|
7
|
+
} from "./chunk-XXIY25TZ.js";
|
|
8
|
+
|
|
9
|
+
// src/docgen/component-docgen/resolve-component/resolve-component.ts
|
|
10
|
+
import { readFileSync } from "node:fs";
|
|
11
|
+
import { readFile } from "node:fs/promises";
|
|
12
|
+
import { resolve } from "node:path";
|
|
13
|
+
import {
|
|
14
|
+
createComponentNodeResolver,
|
|
15
|
+
createModuleResolver,
|
|
16
|
+
defaultResolveConditionNames,
|
|
17
|
+
extractDeclaredSubcomponents,
|
|
18
|
+
extractSubcomponents,
|
|
19
|
+
getStoryImportPathFromEntry,
|
|
20
|
+
jsTsSourceExtensions,
|
|
21
|
+
typescriptExtensionAlias
|
|
22
|
+
} from "storybook/internal/common";
|
|
23
|
+
import {
|
|
24
|
+
SourceEditor,
|
|
25
|
+
loadCsf,
|
|
26
|
+
parseExpression,
|
|
27
|
+
propertyValue
|
|
28
|
+
} from "storybook/internal/csf-tools";
|
|
29
|
+
var moduleResolver = createModuleResolver({
|
|
30
|
+
extensions: [".svelte", ...jsTsSourceExtensions],
|
|
31
|
+
// TypeScript projects import `./index.ts` as `./index.js`, as SvelteKit's packaging requires.
|
|
32
|
+
extensionAlias: typescriptExtensionAlias,
|
|
33
|
+
mainFields: ["svelte", "module", "main"],
|
|
34
|
+
// Core's conditions plus `svelte`, so a `storybook` entry resolves as it does in the preview.
|
|
35
|
+
conditionNames: ["svelte", ...defaultResolveConditionNames],
|
|
36
|
+
tsconfig: "auto"
|
|
37
|
+
});
|
|
38
|
+
function moduleEditor(filePath) {
|
|
39
|
+
try {
|
|
40
|
+
let file = readFileSync(filePath, "utf8");
|
|
41
|
+
if (!filePath.endsWith(".svelte")) return new SourceEditor(file, filePath);
|
|
42
|
+
let { source, ast } = parseSvelteSource(file), module = ast.module?.content;
|
|
43
|
+
return module && new SourceEditor(source.slice(module.start, module.end), `${filePath}.ts`);
|
|
44
|
+
} catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function readModule(filePath) {
|
|
49
|
+
let editor = moduleEditor(filePath);
|
|
50
|
+
return editor && { editor, filePath };
|
|
51
|
+
}
|
|
52
|
+
var isComponent = (filePath, exportName) => filePath.endsWith(".svelte") && exportName === "default", exportReader = {
|
|
53
|
+
resolver: moduleResolver,
|
|
54
|
+
readModule,
|
|
55
|
+
ownsExport: isComponent
|
|
56
|
+
}, resolveComponentExpression = createComponentNodeResolver({ reader: exportReader }), unresolved = (specifier, exportName) => new Error(`Could not resolve \`${specifier}\` export \`${exportName}\``);
|
|
57
|
+
async function readStoryFile(entry) {
|
|
58
|
+
let importPath = getStoryImportPathFromEntry(entry);
|
|
59
|
+
if (!importPath) return;
|
|
60
|
+
let storyPath = resolve(importPath), file = await readFile(storyPath, "utf8");
|
|
61
|
+
return storyPath.endsWith(".svelte") ? { storyPath, ...await readSvelteMeta(file, storyPath) } : { storyPath, csf: loadCsf(file, { makeTitle: () => entry.title }).parse() };
|
|
62
|
+
}
|
|
63
|
+
function resolveComponentNode(story, node) {
|
|
64
|
+
let { module, meta } = "csf" in story ? {
|
|
65
|
+
module: { editor: story.csf.editor, filePath: story.storyPath },
|
|
66
|
+
meta: story.csf._metaAnnotations.component
|
|
67
|
+
} : { module: story.module, meta: propertyValue(story.meta, "component") }, expression = node ?? meta;
|
|
68
|
+
if (!expression) return;
|
|
69
|
+
let resolved = resolveComponentExpression(module, expression);
|
|
70
|
+
if ("reason" in resolved)
|
|
71
|
+
switch (resolved.reason) {
|
|
72
|
+
case "unreadable-component-expression":
|
|
73
|
+
throw new Error(`Cannot resolve the component \`${resolved.expression}\``);
|
|
74
|
+
case "missing-export":
|
|
75
|
+
throw unresolved(resolved.importId, resolved.exportName);
|
|
76
|
+
case "no-meta-component":
|
|
77
|
+
case "no-component-import":
|
|
78
|
+
return;
|
|
79
|
+
default: {
|
|
80
|
+
let unhandled = resolved;
|
|
81
|
+
throw new Error(`Unhandled resolution ${JSON.stringify(unhandled)}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
let { importId, path, exportName, localName } = resolved.component;
|
|
85
|
+
if (importId) {
|
|
86
|
+
if (!path || !isComponent(path, exportName)) throw unresolved(importId, exportName);
|
|
87
|
+
return { componentPath: path, exportName, name: localName };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function resolveStoryComponent(entry) {
|
|
91
|
+
let story = await readStoryFile(entry);
|
|
92
|
+
return story && resolveComponentNode(story);
|
|
93
|
+
}
|
|
94
|
+
function resolveCsfComponent(storyPath, csf) {
|
|
95
|
+
return resolveComponentNode({ storyPath, csf });
|
|
96
|
+
}
|
|
97
|
+
async function resolveStorySubcomponents(entry) {
|
|
98
|
+
let story = await readStoryFile(entry);
|
|
99
|
+
if (!story) return {};
|
|
100
|
+
let declared = "csf" in story ? extractDeclaredSubcomponents(story.csf) : extractSubcomponents(
|
|
101
|
+
propertyValue(story.meta, "subcomponents"),
|
|
102
|
+
story.module.editor.program
|
|
103
|
+
), resolved = {};
|
|
104
|
+
for (let { name, node } of declared)
|
|
105
|
+
try {
|
|
106
|
+
let component = resolveComponentNode(story, node);
|
|
107
|
+
component && (resolved[name] = { ...component, name });
|
|
108
|
+
} catch {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
return resolved;
|
|
112
|
+
}
|
|
113
|
+
async function readSvelteMeta(file, storyPath) {
|
|
114
|
+
let { source, ast } = parseSvelteSource(file), nodes = await extractSvelteASTNodes({ ast, filename: storyPath }), { start, end } = getDefineMetaFirstArgumentObjectExpression({
|
|
115
|
+
nodes,
|
|
116
|
+
filename: storyPath
|
|
117
|
+
}), script = ast.module.content, meta = parseExpression(source.slice(start, end));
|
|
118
|
+
return {
|
|
119
|
+
meta: meta.type === "ObjectExpression" ? meta : void 0,
|
|
120
|
+
module: {
|
|
121
|
+
editor: new SourceEditor(source.slice(script.start, script.end), `${storyPath}.ts`),
|
|
122
|
+
filePath: storyPath
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export {
|
|
128
|
+
resolveStoryComponent,
|
|
129
|
+
resolveCsfComponent,
|
|
130
|
+
resolveStorySubcomponents
|
|
131
|
+
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractComponentComment
|
|
3
|
+
} from "./chunk-RLLUKTHS.js";
|
|
4
|
+
|
|
1
5
|
// src/docgen/component-docgen/svelte2tsx/generate-docgen.ts
|
|
2
6
|
import path from "node:path";
|
|
3
7
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { extractJSDocInfo } from "storybook/internal/csf-tools";
|
|
5
8
|
import svelte2tsx, { internalHelpers } from "svelte2tsx";
|
|
6
9
|
import { VERSION, parse } from "svelte/compiler";
|
|
7
10
|
import ts from "typescript";
|
|
@@ -360,12 +363,7 @@ function extractDocgen(program, checker, targetFileName, options) {
|
|
|
360
363
|
}
|
|
361
364
|
});
|
|
362
365
|
});
|
|
363
|
-
let source = options.documentationSource,
|
|
364
|
-
(node) => node.type === "Comment" && /@component\b/.test(node.data)
|
|
365
|
-
), typeParams = renderFunction.typeParameters?.map((param) => param.getText()).join(", "), docs = comment && comment.type === "Comment" ? extractJSDocInfo(
|
|
366
|
-
comment.data.replace(/@component\b/, "").replace(/\s+(@[a-zA-Z]+\b)/g, `
|
|
367
|
-
$1`).trim()
|
|
368
|
-
) : void 0, omittedTypes = propsType && omitted.size ? [...new Set(libraryTypesWithOmittedProps(propsType, omitted, checker))] : [];
|
|
366
|
+
let source = options.documentationSource, docs = source ? extractComponentComment(parse(source, { modern: !0 })) : void 0, typeParams = renderFunction.typeParameters?.map((param) => param.getText()).join(", "), omittedTypes = propsType && omitted.size ? [...new Set(libraryTypesWithOmittedProps(propsType, omitted, checker))] : [];
|
|
369
367
|
return {
|
|
370
368
|
props: Array.from(propMap.values()),
|
|
371
369
|
events,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/docgen/component-docgen/component-comment.ts
|
|
2
|
+
import { extractJSDocInfo } from "storybook/internal/csf-tools";
|
|
3
|
+
function extractComponentComment(root) {
|
|
4
|
+
let comments = root.fragment.nodes.filter(
|
|
5
|
+
(node) => node.type === "Comment" && /@component\b/.test(node.data)
|
|
6
|
+
), comment = comments.find((node) => /^\s*@component\b/.test(node.data)) ?? comments[0];
|
|
7
|
+
return comment ? extractJSDocInfo(
|
|
8
|
+
comment.data.replace(/@component\b/, "").replace(/\s+(@[a-zA-Z]+\b)/g, `
|
|
9
|
+
$1`).trim()
|
|
10
|
+
) : void 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
extractComponentComment
|
|
15
|
+
};
|
|
@@ -37,25 +37,29 @@ async function extractModuleNodes(options) {
|
|
|
37
37
|
|
|
38
38
|
// src/svelte-csf/parser/extract/svelte/fragment-nodes.ts
|
|
39
39
|
async function extractFragmentNodes(params) {
|
|
40
|
-
let { walk } = await import("./walk-TKX2QFK2.js"), { fragment, moduleNodes } = params, { storyNames } = moduleNodes,
|
|
40
|
+
let { walk } = await import("./walk-TKX2QFK2.js"), { fragment, moduleNodes } = params, { storyNames } = moduleNodes, state = {
|
|
41
41
|
storyComponents: [],
|
|
42
42
|
snippetBlocks: []
|
|
43
43
|
};
|
|
44
44
|
return walk(fragment, state, {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
Component(node, { state: state2 }) {
|
|
49
|
-
storyNames.includes(node.name) && (state2.storyComponents.push({
|
|
50
|
-
comment: latestComment,
|
|
45
|
+
Component(node, { state: state2, path }) {
|
|
46
|
+
storyNames.includes(node.name) && state2.storyComponents.push({
|
|
47
|
+
comment: commentBefore(node, path.at(-1)),
|
|
51
48
|
component: node
|
|
52
|
-
})
|
|
49
|
+
});
|
|
53
50
|
},
|
|
54
51
|
SnippetBlock(node, { state: state2 }) {
|
|
55
52
|
state2.snippetBlocks.push(node);
|
|
56
53
|
}
|
|
57
54
|
}), state;
|
|
58
55
|
}
|
|
56
|
+
function commentBefore(node, parent) {
|
|
57
|
+
if (parent?.type !== "Fragment") return;
|
|
58
|
+
let index = parent.nodes.indexOf(node), previous = parent.nodes[index - 1], whitespace = previous?.type === "Text" && !previous.data.trim() ? previous : void 0, comment = whitespace ? parent.nodes[index - 2] : previous;
|
|
59
|
+
if (comment?.type !== "Comment") return;
|
|
60
|
+
let whitespaceLength = whitespace ? whitespace.end - whitespace.start : 0;
|
|
61
|
+
return node.start - comment.end === whitespaceLength ? comment : void 0;
|
|
62
|
+
}
|
|
59
63
|
|
|
60
64
|
// src/svelte-csf/parser/extract/svelte/nodes.ts
|
|
61
65
|
async function extractSvelteASTNodes(params) {
|
package/dist/_node-chunks/{svelte-project-manager-Q35NEAHT.js → svelte-project-manager-UM2UGPYV.js}
RENAMED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
inferredCommandLine,
|
|
7
7
|
parseSvelteConfig,
|
|
8
8
|
virtualFileName
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-OAEBQIZS.js";
|
|
10
|
+
import "./chunk-RLLUKTHS.js";
|
|
10
11
|
|
|
11
12
|
// src/docgen/component-docgen/component-meta/svelte-project-manager.ts
|
|
12
13
|
import { statSync } from "node:fs";
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
inferredCommandLine,
|
|
9
9
|
parseSvelteConfig,
|
|
10
10
|
virtualFileName
|
|
11
|
-
} from "../../../_node-chunks/chunk-
|
|
11
|
+
} from "../../../_node-chunks/chunk-OAEBQIZS.js";
|
|
12
|
+
import "../../../_node-chunks/chunk-RLLUKTHS.js";
|
|
12
13
|
export {
|
|
13
14
|
UNPRINTABLE_DEFAULT,
|
|
14
15
|
assertCompilerApi,
|
|
@@ -11,8 +11,8 @@ var createDocgenProvider = () => createLazyDocgenMiddleware({
|
|
|
11
11
|
try {
|
|
12
12
|
await loadTypeScriptCompilerApi(() => import("typescript"));
|
|
13
13
|
let [{ SvelteComponentMetaManager }, { buildDocgenPayload }] = await Promise.all([
|
|
14
|
-
import("../_node-chunks/svelte-project-manager-
|
|
15
|
-
import("../_node-chunks/build-docgen-
|
|
14
|
+
import("../_node-chunks/svelte-project-manager-UM2UGPYV.js"),
|
|
15
|
+
import("../_node-chunks/build-docgen-IN2KQQ7N.js")
|
|
16
16
|
]), componentMetaManager = new SvelteComponentMetaManager();
|
|
17
17
|
return componentMetaManager.startWatching(), { componentMetaManager, buildDocgenPayload };
|
|
18
18
|
} catch (error) {
|
package/dist/preset.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveCsfComponent
|
|
3
|
+
} from "./_node-chunks/chunk-5PSMHZ5O.js";
|
|
4
|
+
import {
|
|
5
|
+
extractComponentComment
|
|
6
|
+
} from "./_node-chunks/chunk-RLLUKTHS.js";
|
|
1
7
|
import {
|
|
2
8
|
SVELTE_DOCGEN_STORY_FILE_TEST_REGEXP
|
|
3
9
|
} from "./_node-chunks/chunk-4AFBO5RP.js";
|
|
@@ -9,11 +15,11 @@ import {
|
|
|
9
15
|
findStoryAttributeTemplateSnippetBlock,
|
|
10
16
|
getStoryContentRawCode,
|
|
11
17
|
span
|
|
12
|
-
} from "./_node-chunks/chunk-
|
|
18
|
+
} from "./_node-chunks/chunk-DHQULEOF.js";
|
|
13
19
|
import {
|
|
14
20
|
extractSvelteASTNodes,
|
|
15
21
|
getDefineMetaFirstArgumentObjectExpression
|
|
16
|
-
} from "./_node-chunks/chunk-
|
|
22
|
+
} from "./_node-chunks/chunk-XXIY25TZ.js";
|
|
17
23
|
import {
|
|
18
24
|
extractStoryAttributesNodes,
|
|
19
25
|
extractStoryTemplateSnippetBlock,
|
|
@@ -59,7 +65,7 @@ import { resolve } from "node:path";
|
|
|
59
65
|
import { getComponentIdFromEntry, getStoryImportPathFromEntry } from "storybook/internal/common";
|
|
60
66
|
import { storyNameFromExport, toId } from "storybook/internal/csf";
|
|
61
67
|
import {
|
|
62
|
-
collectImportBindings,
|
|
68
|
+
collectImportBindings as collectImportBindings2,
|
|
63
69
|
createStoryArgsResolver,
|
|
64
70
|
createStoryReferenceResolver,
|
|
65
71
|
extractStoryJSDocInfo,
|
|
@@ -444,7 +450,9 @@ function isPrimary(node) {
|
|
|
444
450
|
import {
|
|
445
451
|
SourceEditor as SourceEditor2,
|
|
446
452
|
buildImportStatements,
|
|
453
|
+
collectImportBindings,
|
|
447
454
|
detachedTextOf,
|
|
455
|
+
parseModule,
|
|
448
456
|
resolveComponentImport,
|
|
449
457
|
textOf as textOf2,
|
|
450
458
|
walk as walkEstree2
|
|
@@ -502,12 +510,19 @@ function buildSnippetImportBlock(markup, {
|
|
|
502
510
|
visit(base.startsWith("$") && !GLOBALS.has(base) ? base.slice(1) : base);
|
|
503
511
|
}
|
|
504
512
|
for (let name of names.types) visit(name, 0, !0);
|
|
505
|
-
let
|
|
513
|
+
let readElsewhere = (namespace) => [...components].some(
|
|
514
|
+
(name) => name !== importOverride?.name && name.split(".")[0] === namespace
|
|
515
|
+
) || [namespace, `$${namespace}`].some((name) => names.values.has(name)) || scripts.some(
|
|
516
|
+
(script) => [...script?.selected ?? []].some(
|
|
517
|
+
({ dependencies }) => [...dependencies.values, ...dependencies.types].some(
|
|
518
|
+
(name) => name.split(".")[0] === namespace
|
|
519
|
+
)
|
|
520
|
+
)
|
|
521
|
+
), importLines = buildImportStatements({
|
|
506
522
|
refs: [
|
|
507
|
-
...[...storyImports].map(
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
})),
|
|
523
|
+
...[...storyImports].map(
|
|
524
|
+
(name) => storyImport(name, bindings, importOverride, readElsewhere)
|
|
525
|
+
),
|
|
511
526
|
...imports
|
|
512
527
|
]
|
|
513
528
|
}), [instance, module] = scripts.map((script) => script ? printSelected(script) : []), copies = scripts.some(
|
|
@@ -524,6 +539,20 @@ function buildSnippetImportBlock(markup, {
|
|
|
524
539
|
...unresolved.size ? { unresolvedIdentifiers: [...unresolved] } : {}
|
|
525
540
|
};
|
|
526
541
|
}
|
|
542
|
+
function storyImport(name, bindings, importOverride, readElsewhere) {
|
|
543
|
+
let ref = resolveComponentImport(name, bindings);
|
|
544
|
+
if (name === importOverride?.name) return { ...ref, importOverride: importOverride.statement };
|
|
545
|
+
if (!importOverride?.name.startsWith(`${name}.`) || readElsewhere(name)) return ref;
|
|
546
|
+
let member = importOverride.name.slice(name.length + 1), source = importedBinding(importOverride.statement);
|
|
547
|
+
return source?.importName === "*" || source?.importName === member ? { importId: source.importId, importName: "*", localImportName: name, namespace: name } : ref;
|
|
548
|
+
}
|
|
549
|
+
function importedBinding(statement) {
|
|
550
|
+
try {
|
|
551
|
+
return [...collectImportBindings(parseModule(statement).program).values()].at(0);
|
|
552
|
+
} catch {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
527
556
|
function needsTypeScript(markup) {
|
|
528
557
|
try {
|
|
529
558
|
return parseMarkup(markup, !1), !1;
|
|
@@ -684,6 +713,7 @@ function printSelected(script) {
|
|
|
684
713
|
// src/docgen/story-docs/svelte-csf-file.ts
|
|
685
714
|
import {
|
|
686
715
|
SourceEditor as SourceEditor3,
|
|
716
|
+
extractComponentDescription,
|
|
687
717
|
generateUid,
|
|
688
718
|
unwrapExpression as unwrapExpression2
|
|
689
719
|
} from "storybook/internal/csf-tools";
|
|
@@ -716,12 +746,16 @@ export const ${exportName} = ${storyObject};`;
|
|
|
716
746
|
asChild: content.asChild,
|
|
717
747
|
originalCode: source,
|
|
718
748
|
filename
|
|
719
|
-
}), parameter = templateParameter(content.component, nodes, filename)
|
|
749
|
+
}), parameter = templateParameter(content.component, nodes, filename), { description, summary } = extractComponentDescription(
|
|
750
|
+
story.comment?.data.trim() || void 0,
|
|
751
|
+
void 0
|
|
752
|
+
);
|
|
720
753
|
stories.set(exportName, {
|
|
721
754
|
// Without a meta component, a story with no markup of its own renders nothing static.
|
|
722
755
|
template: template.startsWith("<undefined ") ? void 0 : template,
|
|
723
756
|
...parameter ? { parameter } : {},
|
|
724
|
-
description
|
|
757
|
+
description,
|
|
758
|
+
summary
|
|
725
759
|
});
|
|
726
760
|
}
|
|
727
761
|
let snippets = /* @__PURE__ */ new Map();
|
|
@@ -781,18 +815,17 @@ async function buildStoryDocsPayload(input) {
|
|
|
781
815
|
}, csf = loadCsf(file.csfSource, {
|
|
782
816
|
makeTitle: () => input.entry.title,
|
|
783
817
|
fileName: svelte ? `${filename}.${file.typescript ? "ts" : "js"}` : filename
|
|
784
|
-
}).parse(), meta = metaObject(csf), component = propertyValue(meta, "component"), componentName = component && /^[A-Z][\w$]*(?:\.[\w$]+)*$/.test(textOf3(component)) ? textOf3(component) : void 0, importStatement = meta
|
|
818
|
+
}).parse(), meta = metaObject(csf), component = propertyValue(meta, "component"), componentName = component && /^[A-Z][\w$]*(?:\.[\w$]+)*$/.test(textOf3(component)) ? textOf3(component) : void 0, importStatement = componentName && ((meta && jsDocTagsForNode(meta, csf.editor).import?.[0]) ?? await componentImportTag(filename, csf)), context = {
|
|
785
819
|
file,
|
|
786
|
-
bindings:
|
|
820
|
+
bindings: collectImportBindings2(csf.program),
|
|
787
821
|
importOverride: componentName && importStatement ? { name: componentName, statement: importStatement } : void 0,
|
|
788
822
|
componentName: svelte ? void 0 : componentName
|
|
789
823
|
}, resolver = createStoryArgsResolver(csf, { filePath: filename, ...openStoryReferences() }), stories = {};
|
|
790
824
|
for (let [exportName, story] of Object.entries(csf._stories)) {
|
|
791
|
-
let id = svelte ? toId(csf.meta.id ?? csf.meta.title ?? input.entry.title, storyNameFromExport(exportName)) : story.id, doc = {
|
|
825
|
+
let id = svelte ? toId(csf.meta.id ?? csf.meta.title ?? input.entry.title, storyNameFromExport(exportName)) : story.id, markup = file.stories.get(exportName), doc = {
|
|
792
826
|
id,
|
|
793
827
|
name: story.name ?? storyNameFromExport(exportName),
|
|
794
|
-
...extractStoryJSDocInfo(csf._storyStatements[exportName], csf.editor)
|
|
795
|
-
...file.stories.get(exportName)?.description ? { description: file.stories.get(exportName).description } : {}
|
|
828
|
+
...markup ? { description: markup.description, summary: markup.summary } : extractStoryJSDocInfo(csf._storyStatements[exportName], csf.editor)
|
|
796
829
|
};
|
|
797
830
|
try {
|
|
798
831
|
stories[id] = { ...doc, ...storySnippet(exportName, resolver.resolve(exportName), context) };
|
|
@@ -808,6 +841,16 @@ async function buildStoryDocsPayload(input) {
|
|
|
808
841
|
stories
|
|
809
842
|
};
|
|
810
843
|
}
|
|
844
|
+
async function componentImportTag(storyPath, csf) {
|
|
845
|
+
try {
|
|
846
|
+
let component = resolveCsfComponent(storyPath, csf);
|
|
847
|
+
if (!component) return;
|
|
848
|
+
let { ast } = parseSvelteSource(await readFile(component.componentPath, "utf8"));
|
|
849
|
+
return extractComponentComment(ast)?.tags.import?.[0];
|
|
850
|
+
} catch {
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
811
854
|
function storySnippet(exportName, resolved, { file, bindings, importOverride, componentName }) {
|
|
812
855
|
let story = file.stories.get(exportName), template = story?.template ?? (componentName ? `<${componentName} {...args} />` : void 0), renders = !story?.template && (resolved.storyMembers.properties.render || resolved.metaMembers.properties.render);
|
|
813
856
|
if (!template) return renders ? { warning: RENDER_WARNING } : {};
|
|
@@ -8,11 +8,11 @@ import {
|
|
|
8
8
|
getStoryContentRawCode,
|
|
9
9
|
getSvelteAST,
|
|
10
10
|
span
|
|
11
|
-
} from "../../_node-chunks/chunk-
|
|
11
|
+
} from "../../_node-chunks/chunk-DHQULEOF.js";
|
|
12
12
|
import {
|
|
13
13
|
extractSvelteASTNodes,
|
|
14
14
|
getDefineMetaFirstArgumentObjectExpression
|
|
15
|
-
} from "../../_node-chunks/chunk-
|
|
15
|
+
} from "../../_node-chunks/chunk-XXIY25TZ.js";
|
|
16
16
|
import {
|
|
17
17
|
DefaultOrNamespaceImportUsedError,
|
|
18
18
|
NoDestructuredDefineMetaCallError,
|
|
@@ -3150,6 +3150,8 @@ function createRuntimeStoryVariableDeclaration(params) {
|
|
|
3150
3150
|
...params.nodes.tags?.elements ?? [],
|
|
3151
3151
|
{ type: "Literal", value: SVELTE_CSF_V5_TAG }
|
|
3152
3152
|
]), annotations = createASTObjectExpression([
|
|
3153
|
+
// Core reads a story's name from the source. At runtime the spread below carries it.
|
|
3154
|
+
...params.name === void 0 ? [] : [createASTProperty("name", { type: "Literal", value: params.name })],
|
|
3153
3155
|
{
|
|
3154
3156
|
type: "SpreadElement",
|
|
3155
3157
|
argument: {
|
|
@@ -3195,9 +3197,10 @@ async function createAppendix(params) {
|
|
|
3195
3197
|
storiesFunctionDeclaration,
|
|
3196
3198
|
factoryMeta,
|
|
3197
3199
|
filename
|
|
3198
|
-
}), exportNames = stories.map(({ exportName }) => exportName), storiesVariableDeclarations = orderByParents(exportNames, parents).map(
|
|
3200
|
+
}), exportNames = stories.map(({ exportName }) => exportName), names = new Map(stories.map(({ exportName, name }) => [exportName, name])), storiesVariableDeclarations = orderByParents(exportNames, parents).map(
|
|
3199
3201
|
(exportName) => createRuntimeStoryVariableDeclaration({
|
|
3200
3202
|
exportName,
|
|
3203
|
+
name: names.get(exportName),
|
|
3201
3204
|
parentExportName: parents.get(exportName),
|
|
3202
3205
|
filename,
|
|
3203
3206
|
nodes: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/svelte",
|
|
3
|
-
"version": "11.0.0-
|
|
3
|
+
"version": "11.0.0-rc.1",
|
|
4
4
|
"description": "Storybook Svelte renderer: Develop, document, and test UI components in isolation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"zimmerframe": "^1.1.2"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
|
-
"storybook": "^11.0.0-
|
|
108
|
+
"storybook": "^11.0.0-rc.1",
|
|
109
109
|
"svelte": "^5.0.0",
|
|
110
110
|
"typescript": "^5.9.0 || ^6.0.0 || ^7.0.0"
|
|
111
111
|
},
|