@storybook/angular-vite 10.6.0-alpha.6 → 10.6.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/build-schema.json +33 -5
- package/dist/_browser-chunks/{chunk-CHMLOECK.js → chunk-AL7GEPYM.js} +15 -26
- package/dist/_browser-chunks/{chunk-HBLYOJ22.js → chunk-THQDNKQS.js} +3 -3
- package/dist/_browser-chunks/{chunk-ECGMCGUZ.js → chunk-UJ3I56EP.js} +6 -6
- package/dist/_browser-chunks/{chunk-BUNW7ROM.js → chunk-VP3W5GY3.js} +4 -4
- package/dist/_node-chunks/{chunk-ORVVXDOZ.js → chunk-5GTDRCMW.js} +18 -8
- package/dist/_node-chunks/{chunk-6P3TQP4W.js → chunk-DQYSVBAE.js} +7 -7
- package/dist/_node-chunks/chunk-FLU3HTGB.js +42 -0
- package/dist/_node-chunks/story-docs-template-analysis-LGFOFAHO.js +163 -0
- package/dist/builders/build-storybook/index.js +15 -10
- package/dist/builders/start-storybook/index.js +15 -10
- package/dist/chunk-Bv2XDHY-.d.ts +64 -0
- package/dist/client/config.js +2 -2
- package/dist/client/docs/config.js +2 -2
- package/dist/client/index.js +4 -4
- package/dist/docgen/docgen-worker.js +784 -286
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +6 -6
- package/dist/node/vitest.js +6 -6
- package/dist/preset.js +770 -197
- package/package.json +6 -6
- package/start-schema.json +33 -5
- package/dist/_node-chunks/chunk-5LXEVSHB.js +0 -35
- package/dist/chunk-D8_SR6hI.d.ts +0 -31
package/dist/preset.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_z1ub7mlv0j from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_z1ub7mlv0j from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_z1ub7mlv0j from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_z1ub7mlv0j.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_z1ub7mlv0j.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_z1ub7mlv0j.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
import {
|
|
13
13
|
findTsconfigUp
|
|
14
|
-
} from "./_node-chunks/chunk-
|
|
14
|
+
} from "./_node-chunks/chunk-5GTDRCMW.js";
|
|
15
15
|
import {
|
|
16
16
|
parseStoryFile
|
|
17
|
-
} from "./_node-chunks/chunk-
|
|
17
|
+
} from "./_node-chunks/chunk-FLU3HTGB.js";
|
|
18
18
|
|
|
19
19
|
// src/preset.ts
|
|
20
20
|
import { findConfigFile } from "storybook/internal/common";
|
|
@@ -25,8 +25,10 @@ import {
|
|
|
25
25
|
getAutomockCode,
|
|
26
26
|
getRealPath
|
|
27
27
|
} from "storybook/internal/mocking-utils";
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
28
|
+
import { logger as logger5 } from "storybook/internal/node-logger";
|
|
29
|
+
import { AngularUnresolvedStyleError } from "storybook/internal/server-errors";
|
|
30
|
+
import { readFileSync as readFileSync3, statSync as statSync2 } from "node:fs";
|
|
31
|
+
import { basename, isAbsolute as isAbsolute2, relative as relative2, resolve as resolve4 } from "node:path";
|
|
30
32
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
31
33
|
|
|
32
34
|
// src/compodoc-config.ts
|
|
@@ -60,16 +62,39 @@ var DEFAULT_COMPODOC_ARGS = ["-e", "json", "-d", "."], DOCUMENTATION_JSON = "doc
|
|
|
60
62
|
};
|
|
61
63
|
};
|
|
62
64
|
|
|
65
|
+
// src/props-table.ts
|
|
66
|
+
import { deprecate, logger } from "storybook/internal/node-logger";
|
|
67
|
+
var MODES = ["all", "api", "inputs"], configuredMode = (frameworkOptions) => {
|
|
68
|
+
let configured = frameworkOptions?.propsTable;
|
|
69
|
+
return MODES.includes(configured) ? configured : void 0;
|
|
70
|
+
}, resolvePropsTable = (frameworkOptions, features2) => {
|
|
71
|
+
let deprecatedFlag = features2?.angularFilterNonInputControls, inherited = deprecatedFlag === void 0 ? void 0 : deprecatedFlag ? "inputs" : "all";
|
|
72
|
+
return configuredMode(frameworkOptions) ?? inherited ?? "api";
|
|
73
|
+
}, warnAboutPropsTable = (frameworkOptions, features2) => {
|
|
74
|
+
let raw = frameworkOptions?.propsTable, configured = configuredMode(frameworkOptions);
|
|
75
|
+
if (raw !== void 0 && configured === void 0 && logger.warn(
|
|
76
|
+
`Ignoring the unknown \`propsTable\` value ${JSON.stringify(raw)}; expected 'all', 'api' or 'inputs'.`
|
|
77
|
+
), features2?.angularFilterNonInputControls !== void 0) {
|
|
78
|
+
let mode = resolvePropsTable(frameworkOptions, features2);
|
|
79
|
+
deprecate(
|
|
80
|
+
"The `angularFilterNonInputControls` feature is deprecated and will be removed in Storybook 11. " + (configured !== void 0 ? `The \`propsTable: '${mode}'\` framework option takes precedence over it, so the feature has no effect and can be removed.` : `Replace it with the \`propsTable: '${mode}'\` option on your \`@storybook/angular-vite\` framework.`)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
configured === "api" && features2?.experimentalDocgenServer !== !0 && logger.warn(
|
|
84
|
+
"`propsTable: 'api'` needs the `experimentalDocgenServer` feature, which is off, so the props table keeps showing every member. Enable it with `features: { experimentalDocgenServer: true }`, or set `propsTable: 'all'` to say you want every member."
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
63
88
|
// src/compodoc/ensure-documentation.ts
|
|
64
89
|
import { withFileLock } from "storybook/internal/common";
|
|
65
|
-
import { logger as
|
|
90
|
+
import { logger as logger3 } from "storybook/internal/node-logger";
|
|
66
91
|
import { randomUUID } from "node:crypto";
|
|
67
92
|
import { readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
68
93
|
import { join as join2 } from "node:path";
|
|
69
94
|
|
|
70
95
|
// src/compodoc/generate-documentation.ts
|
|
71
96
|
import { executeNodeCommand } from "storybook/internal/common";
|
|
72
|
-
import { logger } from "storybook/internal/node-logger";
|
|
97
|
+
import { logger as logger2 } from "storybook/internal/node-logger";
|
|
73
98
|
import {
|
|
74
99
|
existsSync,
|
|
75
100
|
mkdirSync,
|
|
@@ -143,7 +168,7 @@ ${output}`
|
|
|
143
168
|
);
|
|
144
169
|
mkdirSync(outputDir, { recursive: !0 }), removeAbandonedScratchDirs(outputDir, timeoutMs);
|
|
145
170
|
let scratchDir = mkdtempSync(join(outputDir, SCRATCH_PREFIX)), startedAt = Date.now();
|
|
146
|
-
|
|
171
|
+
logger2.info("[storybook-angular-vite] Generating Angular documentation with Compodoc...");
|
|
147
172
|
try {
|
|
148
173
|
await runCli(
|
|
149
174
|
cli,
|
|
@@ -163,7 +188,7 @@ ${output}`
|
|
|
163
188
|
throw new Error(
|
|
164
189
|
`Compodoc finished without writing ${DOCUMENTATION_JSON}. Check that its arguments still export JSON: ${compodocArgs.join(" ")}`
|
|
165
190
|
);
|
|
166
|
-
renameSync(produced, join(outputDir, DOCUMENTATION_JSON)),
|
|
191
|
+
renameSync(produced, join(outputDir, DOCUMENTATION_JSON)), logger2.debug(
|
|
167
192
|
`[storybook-angular-vite] generated ${DOCUMENTATION_JSON} in ${Date.now() - startedAt}ms`
|
|
168
193
|
);
|
|
169
194
|
} finally {
|
|
@@ -194,11 +219,11 @@ var COMPODOC_LOCK = ".compodoc.lock", COMPODOC_RUN_MARKER = ".compodoc.run", RUN
|
|
|
194
219
|
markerRunId(markerPath) !== runId && (await generateDocumentation({ compodocArgs, tsconfig, workspaceRoot, outputDir }), writeFileSync(markerPath, runId));
|
|
195
220
|
},
|
|
196
221
|
{ waitBudgetMs }
|
|
197
|
-
) === "busy" &&
|
|
222
|
+
) === "busy" && logger3.debug(
|
|
198
223
|
`[storybook-angular-vite] another process is still generating ${DOCUMENTATION_JSON}; continuing with what is on disk`
|
|
199
224
|
);
|
|
200
225
|
} catch (error) {
|
|
201
|
-
|
|
226
|
+
logger3.warn(
|
|
202
227
|
`[storybook-angular-vite] Compodoc generation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
203
228
|
);
|
|
204
229
|
}
|
|
@@ -207,21 +232,21 @@ var COMPODOC_LOCK = ".compodoc.lock", COMPODOC_RUN_MARKER = ".compodoc.run", RUN
|
|
|
207
232
|
// src/docgen/preset.ts
|
|
208
233
|
import { fileURLToPath } from "node:url";
|
|
209
234
|
var experimental_docgenProvider = async (existing = [], options) => {
|
|
210
|
-
let
|
|
211
|
-
if (!
|
|
235
|
+
let features2 = await options?.presets?.apply("features", {});
|
|
236
|
+
if (!features2?.experimentalDocgenServer)
|
|
212
237
|
return existing;
|
|
213
238
|
let descriptor = {
|
|
214
239
|
moduleSpecifier: fileURLToPath(
|
|
215
240
|
import.meta.resolve("@storybook/angular-vite/internal/docgen-worker")
|
|
216
241
|
),
|
|
217
242
|
options: {
|
|
218
|
-
|
|
243
|
+
propsTable: resolvePropsTable(await options?.presets?.apply("frameworkOptions"), features2)
|
|
219
244
|
}
|
|
220
245
|
};
|
|
221
246
|
return [...existing, descriptor];
|
|
222
247
|
}, experimental_manifests = async (existingManifests = {}, options) => {
|
|
223
|
-
let
|
|
224
|
-
if (!
|
|
248
|
+
let features2 = await options?.presets?.apply("features", {});
|
|
249
|
+
if (!features2?.experimentalDocgenServer || !features2?.componentsManifest)
|
|
225
250
|
return existingManifests;
|
|
226
251
|
let existingComponents = existingManifests.components;
|
|
227
252
|
return {
|
|
@@ -237,47 +262,33 @@ var experimental_docgenProvider = async (existing = [], options) => {
|
|
|
237
262
|
// src/docgen/story-docs-preset.ts
|
|
238
263
|
import { STORY_FILE_TEST_REGEXP, getStoryImportPathFromEntry as getStoryImportPathFromEntry2 } from "storybook/internal/common";
|
|
239
264
|
import { getService } from "storybook/internal/core-server";
|
|
240
|
-
import { logger as
|
|
265
|
+
import { logger as logger4 } from "storybook/internal/node-logger";
|
|
241
266
|
|
|
242
267
|
// src/docgen/story-docs-build.ts
|
|
243
|
-
import { types as
|
|
268
|
+
import { types as t5 } from "storybook/internal/babel";
|
|
244
269
|
import { getComponentIdFromEntry, getStoryImportPathFromEntry } from "storybook/internal/common";
|
|
245
270
|
import { storyNameFromExport } from "storybook/internal/csf";
|
|
246
271
|
import {
|
|
247
|
-
|
|
248
|
-
buildImportStatements,
|
|
272
|
+
buildImportStatements as buildImportStatements2,
|
|
249
273
|
collectImportBindings,
|
|
274
|
+
createStoryArgsResolver,
|
|
275
|
+
createStoryReferenceResolver,
|
|
250
276
|
extractStoryJSDocInfo,
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
resolveComponentImport,
|
|
254
|
-
|
|
277
|
+
isSelfContained,
|
|
278
|
+
parseReferenceModule,
|
|
279
|
+
resolveComponentImport as resolveComponentImport2,
|
|
280
|
+
unresolvedWarning,
|
|
281
|
+
unwrapExpression as unwrapExpression5
|
|
255
282
|
} from "storybook/internal/csf-tools";
|
|
256
283
|
import { resolve as resolve3 } from "node:path";
|
|
257
284
|
|
|
285
|
+
// src/docgen/story-docs-args.ts
|
|
286
|
+
import { babelPrint, types as t } from "storybook/internal/babel";
|
|
287
|
+
import { keyOf, unwrapExpression } from "storybook/internal/csf-tools";
|
|
288
|
+
|
|
258
289
|
// src/template-grammar.ts
|
|
259
|
-
var isValidIdentifier = (name) => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name), formatPropInTemplate = (propertyName) => isValidIdentifier(propertyName) ? propertyName : `this['${propertyName}']
|
|
260
|
-
|
|
261
|
-
return JSON.stringify(obj, (key, value) => {
|
|
262
|
-
if (typeof value == "object" && value !== null) {
|
|
263
|
-
if (seen.has(value))
|
|
264
|
-
return "[Circular]";
|
|
265
|
-
seen.add(value);
|
|
266
|
-
}
|
|
267
|
-
return value;
|
|
268
|
-
});
|
|
269
|
-
}, singleQuoted = (text) => `'${JSON.stringify(text).slice(1, -1).replace(/\\"/g, '"').replace(/'/g, "\\'").replace(/"/g, """)}'`, formatJsonValue = (value) => typeof value == "string" ? singleQuoted(value) : Array.isArray(value) ? `[${value.map(formatJsonValue).join(", ")}]` : value !== null && typeof value == "object" ? `{${Object.entries(value).map(
|
|
270
|
-
([key, item]) => `${isValidIdentifier(key) ? key : singleQuoted(key)}: ${formatJsonValue(item)}`
|
|
271
|
-
).join(", ")}}` : String(value), formatInputValue = (value) => {
|
|
272
|
-
switch (typeof value) {
|
|
273
|
-
case "string":
|
|
274
|
-
return singleQuoted(value);
|
|
275
|
-
case "object":
|
|
276
|
-
return formatJsonValue(JSON.parse(stringifyCircular(value)));
|
|
277
|
-
default:
|
|
278
|
-
return `${value}`;
|
|
279
|
-
}
|
|
280
|
-
}, VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
290
|
+
var isValidIdentifier = (name) => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name), formatPropInTemplate = (propertyName) => isValidIdentifier(propertyName) ? propertyName : `this['${propertyName}']`;
|
|
291
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
281
292
|
"area",
|
|
282
293
|
"base",
|
|
283
294
|
"br",
|
|
@@ -294,31 +305,455 @@ var isValidIdentifier = (name) => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name), forma
|
|
|
294
305
|
"source",
|
|
295
306
|
"track",
|
|
296
307
|
"wbr"
|
|
297
|
-
]), LEADING_CLASS = /^\..+/, LEADING_ATTRIBUTE = /^\[.+?]/, ID = /#([\w-]+)/, CLASS_RUN = /(\.[\w-]+)+/, ATTRIBUTE = /\[(.+?)]/g, ELEMENT_AND_ATTRIBUTES = /(\S+)(.*)/, MAX_SINGLE_LINE = 80, buildTemplate = (selector, { inputs, outputs, innerTemplate = "" }) => {
|
|
308
|
+
]), LEADING_CLASS = /^\..+/, LEADING_ATTRIBUTE = /^\[.+?]/, ID = /#([\w-]+)/, CLASS_RUN = /(\.[\w-]+)+/, ATTRIBUTE = /\[(.+?)]/g, ELEMENT_AND_ATTRIBUTES = /(\S+)(.*)/, MAX_SINGLE_LINE = 80, buildTemplate = (selector, { inputs, outputs, innerTemplate = "", selfClosing = !1 }) => {
|
|
298
309
|
let bindings = [
|
|
299
310
|
...inputs.map(({ name, expression }) => `[${name}]="${expression}"`),
|
|
300
311
|
...outputs.map((name) => `(${name})="${formatPropInTemplate(name)}($event)"`)
|
|
301
312
|
], firstSelector = selector.split(",")[0];
|
|
302
313
|
return (LEADING_CLASS.test(firstSelector) || LEADING_ATTRIBUTE.test(firstSelector) ? `div${firstSelector}` : firstSelector).replace(ID, ' id="$1"').replace(CLASS_RUN, (classes) => ` class="${classes.split(".").join(" ").trim()}"`).replace(ATTRIBUTE, " $1").replace(ELEMENT_AND_ATTRIBUTES, (_, element, attributes) => {
|
|
303
|
-
let inlineTag = `<${element}${attributes}${bindings.map((binding) => ` ${binding}`).join("")}`, inline =
|
|
314
|
+
let closesItself = VOID_ELEMENTS.has(element) || selfClosing && element.includes("-") && innerTemplate === "", inlineTag = `<${element}${attributes}${bindings.map((binding) => ` ${binding}`).join("")}`, inline = closesItself ? `${inlineTag} />` : `${inlineTag}>${innerTemplate}</${element}>`;
|
|
304
315
|
if (inline.length <= MAX_SINGLE_LINE || bindings.length === 0)
|
|
305
316
|
return inline;
|
|
306
317
|
let brokenTag = `<${element}${attributes}
|
|
307
318
|
${bindings.map((binding) => ` ${binding}`).join(`
|
|
308
319
|
`)}`;
|
|
309
|
-
if (
|
|
310
|
-
return `${brokenTag}
|
|
320
|
+
if (closesItself)
|
|
321
|
+
return selfClosing ? `${brokenTag}
|
|
322
|
+
/>` : `${brokenTag} />`;
|
|
311
323
|
let content = innerTemplate === "" ? `
|
|
312
324
|
` : `
|
|
313
325
|
${innerTemplate}
|
|
314
326
|
`;
|
|
315
327
|
return `${brokenTag}>${content}</${element}>`;
|
|
316
328
|
});
|
|
317
|
-
}, buildComponentOutletTemplate = (componentName) => `<ng-container *ngComponentOutlet="${componentName}"></ng-container
|
|
329
|
+
}, buildComponentOutletTemplate = (componentName, { selfClosing = !1 } = {}) => selfClosing ? `<ng-container *ngComponentOutlet="${componentName}" />` : `<ng-container *ngComponentOutlet="${componentName}"></ng-container>`, INDENT = " ", MARKUP_TAG = /<(\/?)([A-Za-z][\w-]*)((?:"[^"]*"|'[^']*'|[^>"'])*)>/g, parseMarkup = (markup) => {
|
|
330
|
+
let root = {
|
|
331
|
+
tag: "",
|
|
332
|
+
rawOpen: "",
|
|
333
|
+
attrText: "",
|
|
334
|
+
closed: !1,
|
|
335
|
+
start: 0,
|
|
336
|
+
end: 0,
|
|
337
|
+
children: []
|
|
338
|
+
}, stack = [root], lastIndex = 0;
|
|
339
|
+
for (let match of markup.matchAll(MARKUP_TAG)) {
|
|
340
|
+
let text = markup.slice(lastIndex, match.index).trim();
|
|
341
|
+
text && stack.at(-1).children.push(text), lastIndex = match.index + match[0].length;
|
|
342
|
+
let [rawOpen, closing, tag, rawAttrText] = match;
|
|
343
|
+
if (closing) {
|
|
344
|
+
let open = stack.pop();
|
|
345
|
+
if (!open || open.tag !== tag || stack.length === 0)
|
|
346
|
+
return;
|
|
347
|
+
open.end = lastIndex;
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
let selfClosing = rawAttrText.trimEnd().endsWith("/"), attrText = selfClosing ? rawAttrText.trimEnd().slice(0, -1) : rawAttrText, element = {
|
|
351
|
+
tag,
|
|
352
|
+
rawOpen,
|
|
353
|
+
attrText: attrText.trimEnd(),
|
|
354
|
+
closed: selfClosing || VOID_ELEMENTS.has(tag),
|
|
355
|
+
start: match.index,
|
|
356
|
+
end: lastIndex,
|
|
357
|
+
children: []
|
|
358
|
+
};
|
|
359
|
+
stack.at(-1).children.push(element), element.closed || stack.push(element);
|
|
360
|
+
}
|
|
361
|
+
let trailing = markup.slice(lastIndex).trim();
|
|
362
|
+
return trailing && stack.at(-1).children.push(trailing), stack.length === 1 ? root.children : void 0;
|
|
363
|
+
}, MARKUP_ATTRIBUTE = /[^\s=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|\S+))?/g, openTagLines = (node, pad, forceAttrBreak) => {
|
|
364
|
+
let inlineOpen = `${pad}${node.rawOpen}`, attrs = node.attrText.match(MARKUP_ATTRIBUTE) ?? [];
|
|
365
|
+
if (inlineOpen.length <= MAX_SINGLE_LINE && !forceAttrBreak || attrs.length === 0)
|
|
366
|
+
return [inlineOpen];
|
|
367
|
+
let bracket = node.closed ? " />" : ">";
|
|
368
|
+
return [
|
|
369
|
+
`${pad}<${node.tag}`,
|
|
370
|
+
...attrs.map(
|
|
371
|
+
(attr, index) => `${pad}${INDENT}${attr}${index === attrs.length - 1 ? bracket : ""}`
|
|
372
|
+
)
|
|
373
|
+
];
|
|
374
|
+
}, printMarkup = (markup, node, depth) => {
|
|
375
|
+
let pad = INDENT.repeat(depth);
|
|
376
|
+
if (typeof node == "string")
|
|
377
|
+
return [`${pad}${node}`];
|
|
378
|
+
let hasElementChild = node.children.some((child) => typeof child != "string"), verbatim = markup.slice(node.start, node.end);
|
|
379
|
+
if (!hasElementChild && pad.length + verbatim.length <= MAX_SINGLE_LINE)
|
|
380
|
+
return [`${pad}${verbatim}`];
|
|
381
|
+
let openLines = openTagLines(node, pad, !hasElementChild);
|
|
382
|
+
return node.closed ? openLines : [
|
|
383
|
+
...openLines,
|
|
384
|
+
...node.children.flatMap((child) => printMarkup(markup, child, depth + 1)),
|
|
385
|
+
`${pad}</${node.tag}>`
|
|
386
|
+
];
|
|
387
|
+
}, formatTemplateMarkup = (markup) => {
|
|
388
|
+
let children = parseMarkup(markup);
|
|
389
|
+
return !children || children.length === 0 ? markup : children.flatMap((child) => printMarkup(markup, child, 0)).join(`
|
|
390
|
+
`);
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// src/docgen/story-docs-args.ts
|
|
394
|
+
var EVAL_FAILED = /* @__PURE__ */ Symbol("story-docs-eval-failed"), createArgExternalizer = (enums) => (node) => {
|
|
395
|
+
let value = evaluateNode(node, enums);
|
|
396
|
+
return value === EVAL_FAILED ? void 0 : t.valueToNode(value);
|
|
397
|
+
}, evaluateArgExpression = (node, enums) => {
|
|
398
|
+
let literal = evaluateArgLiteral(node, enums);
|
|
399
|
+
return escapeAttributeExpression(literal ?? printArgSource(unwrapExpression(node)));
|
|
400
|
+
}, evaluateArgLiteral = (node, enums) => {
|
|
401
|
+
let value = evaluateNode(unwrapExpression(node), enums);
|
|
402
|
+
return value === EVAL_FAILED ? void 0 : printExpressionValue(value, /* @__PURE__ */ new Set());
|
|
403
|
+
}, argFieldValue = (node) => printArgSource(unwrapExpression(node)), printArgSource = (node) => babelPrint(t.cloneNode(node, !0)), quoteExpressionString = (value) => `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r")}'`, printExpressionValue = (value, seen) => typeof value == "string" ? quoteExpressionString(value) : typeof value != "object" || value === null ? `${value}` : seen.has(value) ? quoteExpressionString("[Circular]") : (seen.add(value), Array.isArray(value) ? `[${value.map((element) => printExpressionValue(element ?? null, seen)).join(", ")}]` : `{${Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).map(
|
|
404
|
+
([key, entryValue]) => `${isValidIdentifier(key) ? key : quoteExpressionString(key)}: ${printExpressionValue(entryValue, seen)}`
|
|
405
|
+
).join(", ")}}`), escapeAttributeExpression = (expression) => expression.replace(/&(?=#|\w+;)/g, "&").replace(/"/g, """), evaluateNode = (node, enums) => {
|
|
406
|
+
let unwrapped = unwrapExpression(node);
|
|
407
|
+
if (t.isStringLiteral(unwrapped) || t.isNumericLiteral(unwrapped) || t.isBooleanLiteral(unwrapped))
|
|
408
|
+
return unwrapped.value;
|
|
409
|
+
if (t.isNullLiteral(unwrapped))
|
|
410
|
+
return null;
|
|
411
|
+
if (!(t.isIdentifier(unwrapped) && unwrapped.name === "undefined") && !(t.isUnaryExpression(unwrapped) && unwrapped.operator === "void")) {
|
|
412
|
+
if (t.isUnaryExpression(unwrapped) && unwrapped.operator === "-" && t.isNumericLiteral(unwrapped.argument))
|
|
413
|
+
return -unwrapped.argument.value;
|
|
414
|
+
if (t.isTemplateLiteral(unwrapped) && unwrapped.expressions.length === 0)
|
|
415
|
+
return unwrapped.quasis[0]?.value.cooked ?? EVAL_FAILED;
|
|
416
|
+
if (t.isArrayExpression(unwrapped)) {
|
|
417
|
+
let values = [];
|
|
418
|
+
for (let element of unwrapped.elements) {
|
|
419
|
+
if (element === null || t.isSpreadElement(element))
|
|
420
|
+
return EVAL_FAILED;
|
|
421
|
+
let value = evaluateNode(element, enums);
|
|
422
|
+
if (value === EVAL_FAILED)
|
|
423
|
+
return EVAL_FAILED;
|
|
424
|
+
values.push(value);
|
|
425
|
+
}
|
|
426
|
+
return values;
|
|
427
|
+
}
|
|
428
|
+
if (t.isObjectExpression(unwrapped)) {
|
|
429
|
+
let value = {};
|
|
430
|
+
for (let property of unwrapped.properties) {
|
|
431
|
+
if (!t.isObjectProperty(property))
|
|
432
|
+
return EVAL_FAILED;
|
|
433
|
+
let key = keyOf(property);
|
|
434
|
+
if (key === null)
|
|
435
|
+
return EVAL_FAILED;
|
|
436
|
+
let propertyValue = evaluateNode(property.value, enums);
|
|
437
|
+
if (propertyValue === EVAL_FAILED)
|
|
438
|
+
return EVAL_FAILED;
|
|
439
|
+
value[key] = propertyValue;
|
|
440
|
+
}
|
|
441
|
+
return value;
|
|
442
|
+
}
|
|
443
|
+
if (t.isMemberExpression(unwrapped) && !unwrapped.computed && t.isIdentifier(unwrapped.object) && t.isIdentifier(unwrapped.property)) {
|
|
444
|
+
let objectName = unwrapped.object.name, propertyName = unwrapped.property.name;
|
|
445
|
+
return enums.find((enumeration) => enumeration.name === objectName)?.members.find((candidate) => candidate.name === propertyName)?.value ?? EVAL_FAILED;
|
|
446
|
+
}
|
|
447
|
+
return EVAL_FAILED;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// src/docgen/story-docs-markup.ts
|
|
452
|
+
import { types as t2 } from "storybook/internal/babel";
|
|
453
|
+
import {
|
|
454
|
+
isCanonicalCsf2BindCall,
|
|
455
|
+
isCsfFactoryCall,
|
|
456
|
+
sourceOf,
|
|
457
|
+
unwrapExpression as unwrapExpression2
|
|
458
|
+
} from "storybook/internal/csf-tools";
|
|
459
|
+
var bindingAttributes = ({ inputs, outputs }, filter, representedArgs) => {
|
|
460
|
+
let allowed = (name) => filter.include ? filter.include.includes(name) : !filter.exclude?.includes(name), representedInputs = inputs.filter(({ name }) => allowed(name)), representedOutputs = outputs.filter(allowed);
|
|
461
|
+
return representedInputs.forEach(({ name }) => representedArgs.add(name)), representedOutputs.forEach((name) => representedArgs.add(name)), {
|
|
462
|
+
inputAttributes: representedInputs.map(({ name, expression }) => `[${name}]="${expression}"`),
|
|
463
|
+
outputAttributes: representedOutputs.map((name) => ({
|
|
464
|
+
name,
|
|
465
|
+
markup: `(${name})="${formatPropInTemplate(name)}($event)"`
|
|
466
|
+
}))
|
|
467
|
+
};
|
|
468
|
+
}, NO_SCOPE = {
|
|
469
|
+
argBindings: /* @__PURE__ */ new Map(),
|
|
470
|
+
parameterNames: /* @__PURE__ */ new Set(),
|
|
471
|
+
bodyDeclared: /* @__PURE__ */ new Set(),
|
|
472
|
+
argsExpansions: /* @__PURE__ */ new Map()
|
|
473
|
+
}, userTemplate = (shape, bindings) => {
|
|
474
|
+
let own = shapeTemplate(shape.members, shape, bindings);
|
|
475
|
+
if (own)
|
|
476
|
+
return own;
|
|
477
|
+
let csf2 = csf2Shape(shape);
|
|
478
|
+
if (csf2) {
|
|
479
|
+
let templateProperty = resolvedProperty(csf2.returned, "template");
|
|
480
|
+
if (templateProperty.kind === "unresolvable")
|
|
481
|
+
return { kind: "unresolvable", source: sourceOf(csf2.returned) };
|
|
482
|
+
let fromCsf2 = templateFrom(
|
|
483
|
+
templateProperty.kind === "value" ? templateProperty.node : void 0,
|
|
484
|
+
shape,
|
|
485
|
+
bindings,
|
|
486
|
+
functionScope(csf2.fn)
|
|
487
|
+
);
|
|
488
|
+
if (fromCsf2)
|
|
489
|
+
return fromCsf2;
|
|
490
|
+
}
|
|
491
|
+
return shapeTemplate(shape.metaMembers, shape, bindings);
|
|
492
|
+
}, shapeTemplate = (members, shape, bindings) => {
|
|
493
|
+
let template = resolvedMember(members, "template");
|
|
494
|
+
if (template.kind === "unresolvable")
|
|
495
|
+
return { kind: "unresolvable", ...template.node ? { source: sourceOf(template.node) } : {} };
|
|
496
|
+
if (template.kind === "value") {
|
|
497
|
+
let own = templateFrom(declaredValue(shape, template.node), shape, bindings, NO_SCOPE);
|
|
498
|
+
if (own)
|
|
499
|
+
return own;
|
|
500
|
+
}
|
|
501
|
+
let render = resolvedMember(members, "render");
|
|
502
|
+
if (render.kind === "missing")
|
|
503
|
+
return;
|
|
504
|
+
if (render.kind === "unresolvable")
|
|
505
|
+
return { kind: "unresolvable", ...render.node ? { source: sourceOf(render.node) } : {} };
|
|
506
|
+
let fn = declaredValue(shape, render.node), returned = returnedObject(fn);
|
|
507
|
+
if (!returned)
|
|
508
|
+
return { kind: "unresolvable", source: `render: ${sourceOf(render.node)}` };
|
|
509
|
+
let templateProperty = resolvedProperty(returned, "template");
|
|
510
|
+
return templateProperty.kind === "unresolvable" ? { kind: "unresolvable", source: `render: ${sourceOf(render.node)}` } : templateFrom(
|
|
511
|
+
templateProperty.kind === "value" ? templateProperty.node : void 0,
|
|
512
|
+
shape,
|
|
513
|
+
bindings,
|
|
514
|
+
functionScope(fn)
|
|
515
|
+
);
|
|
516
|
+
}, templateFrom = (node, shape, bindings, scope) => {
|
|
517
|
+
if (node === void 0 || t2.isNullLiteral(node) || t2.isIdentifier(node) && node.name === "undefined")
|
|
518
|
+
return;
|
|
519
|
+
if (t2.isStringLiteral(node))
|
|
520
|
+
return literalTemplate(node.value, /* @__PURE__ */ new Set(), []);
|
|
521
|
+
let parts = templateParts(node);
|
|
522
|
+
if (parts) {
|
|
523
|
+
let representedArgs = /* @__PURE__ */ new Set(), expansions = [], markup = interpolate(parts, shape, bindings, scope, representedArgs, expansions);
|
|
524
|
+
return markup === void 0 ? { kind: "unresolvable", source: sourceOf(node) } : literalTemplate(markup, representedArgs, expansions);
|
|
525
|
+
}
|
|
526
|
+
return { kind: "unresolvable", source: sourceOf(node) };
|
|
527
|
+
}, literalTemplate = (markup, representedArgs, expansions) => ({
|
|
528
|
+
kind: "literal",
|
|
529
|
+
markup,
|
|
530
|
+
representedArgs: [...representedArgs],
|
|
531
|
+
expansions
|
|
532
|
+
}), templateParts = (node) => {
|
|
533
|
+
if (t2.isTemplateLiteral(node))
|
|
534
|
+
return {
|
|
535
|
+
quasis: node.quasis.map((quasi) => quasi.value.cooked ?? ""),
|
|
536
|
+
expressions: node.expressions
|
|
537
|
+
};
|
|
538
|
+
if (!(!t2.isTaggedTemplateExpression(node) || !isStringRawTag(node.tag)))
|
|
539
|
+
return {
|
|
540
|
+
quasis: node.quasi.quasis.map((quasi) => quasi.value.raw),
|
|
541
|
+
expressions: node.quasi.expressions
|
|
542
|
+
};
|
|
543
|
+
}, isStringRawTag = (tag) => t2.isMemberExpression(tag) && !tag.computed && t2.isIdentifier(tag.object, { name: "String" }) && t2.isIdentifier(tag.property, { name: "raw" }), interpolate = ({ quasis, expressions }, shape, bindings, scope, representedArgs, expansions) => {
|
|
544
|
+
let markup = quasis[0] ?? "";
|
|
545
|
+
for (let [index, expression] of expressions.entries()) {
|
|
546
|
+
let marker = `data-storybook-args-to-template-${index}`;
|
|
547
|
+
for (; markup.includes(marker) || quasis.some((quasi) => quasi.includes(marker)); )
|
|
548
|
+
marker += "-x";
|
|
549
|
+
let substituted = substituteExpression(
|
|
550
|
+
expression,
|
|
551
|
+
shape,
|
|
552
|
+
bindings,
|
|
553
|
+
scope,
|
|
554
|
+
representedArgs,
|
|
555
|
+
marker,
|
|
556
|
+
expansions
|
|
557
|
+
);
|
|
558
|
+
if (substituted === void 0)
|
|
559
|
+
return;
|
|
560
|
+
markup += substituted + (quasis[index + 1] ?? "");
|
|
561
|
+
}
|
|
562
|
+
return markup;
|
|
563
|
+
}, substituteExpression = (expression, shape, bindings, scope, representedArgs, marker, expansions) => {
|
|
564
|
+
if (t2.isCallExpression(expression) && isImportedArgsToTemplate(expression, shape)) {
|
|
565
|
+
let argument = expression.arguments[0], excluded = t2.isIdentifier(argument) ? scope.argsExpansions.get(argument.name) : void 0;
|
|
566
|
+
if (!bindings || excluded === void 0)
|
|
567
|
+
return;
|
|
568
|
+
let filter = bindingFilterOf(expression.arguments[1]);
|
|
569
|
+
if (filter === void 0)
|
|
570
|
+
return;
|
|
571
|
+
let withRest = { ...filter, exclude: [...filter.exclude ?? [], ...excluded] }, allowed = filter.include ? { ...withRest, include: filter.include.filter((name) => !excluded.includes(name)) } : withRest;
|
|
572
|
+
return expansions.push({ marker, ...bindingAttributes(bindings, allowed, representedArgs) }), marker;
|
|
573
|
+
}
|
|
574
|
+
if (!t2.isIdentifier(expression))
|
|
575
|
+
return;
|
|
576
|
+
let argName = scope.argBindings.get(expression.name);
|
|
577
|
+
if (argName !== void 0) {
|
|
578
|
+
let text = shape.unresolvedArgs.length === 0 ? literalText(shape.args[argName]) : void 0;
|
|
579
|
+
return text !== void 0 && representedArgs.add(argName), text;
|
|
580
|
+
}
|
|
581
|
+
if (scope.parameterNames.has(expression.name) || scope.bodyDeclared.has(expression.name))
|
|
582
|
+
return;
|
|
583
|
+
let declared = declaredValue(shape, expression);
|
|
584
|
+
return declared === expression ? void 0 : literalText(declared);
|
|
585
|
+
}, ARGS_TO_TEMPLATE_MODULES = /* @__PURE__ */ new Set(["@storybook/angular", "@storybook/angular-vite"]), isImportedArgsToTemplate = (call, shape) => {
|
|
586
|
+
if (!t2.isIdentifier(call.callee))
|
|
587
|
+
return !1;
|
|
588
|
+
let binding = shape.csf._file.path.scope.getBinding(call.callee.name);
|
|
589
|
+
if (!binding?.referencePaths.some((path) => path.node === call.callee))
|
|
590
|
+
return !1;
|
|
591
|
+
let specifier = binding?.path.node, declaration = binding?.path.findParent((path) => t2.isImportDeclaration(path.node))?.node;
|
|
592
|
+
return !t2.isImportSpecifier(specifier) || !t2.isImportDeclaration(declaration) ? !1 : (t2.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) === "argsToTemplate" && ARGS_TO_TEMPLATE_MODULES.has(declaration.source.value);
|
|
593
|
+
}, bindingFilterOf = (options) => {
|
|
594
|
+
if (options === void 0)
|
|
595
|
+
return {};
|
|
596
|
+
let unwrapped = unwrapExpression2(options);
|
|
597
|
+
if (!t2.isObjectExpression(unwrapped) || unwrapped.properties.some(t2.isSpreadElement))
|
|
598
|
+
return;
|
|
599
|
+
let filter = {};
|
|
600
|
+
for (let key of ["include", "exclude"]) {
|
|
601
|
+
let node = resolvedProperty(unwrapped, key);
|
|
602
|
+
if (node.kind === "unresolvable")
|
|
603
|
+
return;
|
|
604
|
+
if (node.kind === "value") {
|
|
605
|
+
let names = stringArray(node.node);
|
|
606
|
+
if (names === void 0)
|
|
607
|
+
return;
|
|
608
|
+
filter[key] = names;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return filter;
|
|
612
|
+
}, stringArray = (node) => t2.isArrayExpression(node) && node.elements.every((element) => t2.isStringLiteral(element)) ? node.elements.map((element) => element.value) : void 0, literalText = (node) => {
|
|
613
|
+
let unwrapped = node && unwrapExpression2(node);
|
|
614
|
+
return t2.isStringLiteral(unwrapped) ? unwrapped.value : t2.isNumericLiteral(unwrapped) || t2.isBooleanLiteral(unwrapped) ? String(unwrapped.value) : void 0;
|
|
615
|
+
}, resolvedMember = (members, key) => {
|
|
616
|
+
let node = members.properties[key];
|
|
617
|
+
return node !== void 0 ? members.shadowed.includes(key) ? { kind: "unresolvable", node } : { kind: "value", node } : members.unresolved.length > 0 ? { kind: "unresolvable" } : { kind: "missing" };
|
|
618
|
+
}, resolvedProperty = (object, key) => {
|
|
619
|
+
let found, opaqueAfter;
|
|
620
|
+
return object.properties.forEach((property) => {
|
|
621
|
+
let isMember = t2.isObjectProperty(property) || t2.isObjectMethod(property);
|
|
622
|
+
if (isMember && keyNameOf(property) === key) {
|
|
623
|
+
found = property, opaqueAfter = void 0;
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
(t2.isSpreadElement(property) || isMember && keyNameOf(property) === void 0) && (opaqueAfter = property);
|
|
627
|
+
}), found ? opaqueAfter ? { kind: "unresolvable", node: opaqueAfter } : t2.isObjectMethod(found) ? found.kind === "method" && !found.generator ? { kind: "value", node: found } : { kind: "unresolvable", node: found } : { kind: "value", node: found.value } : opaqueAfter ? { kind: "unresolvable", node: opaqueAfter } : { kind: "missing" };
|
|
628
|
+
}, keyNameOf = (property) => t2.isIdentifier(property.key) && !property.computed ? property.key.name : t2.isStringLiteral(property.key) ? property.key.value : void 0;
|
|
629
|
+
var returnedObject = (fn) => {
|
|
630
|
+
let isPlainMethod = t2.isObjectMethod(fn) && fn.kind === "method" && !fn.generator;
|
|
631
|
+
if (!t2.isArrowFunctionExpression(fn) && !t2.isFunctionExpression(fn) && !t2.isFunctionDeclaration(fn) && !isPlainMethod)
|
|
632
|
+
return;
|
|
633
|
+
if (!t2.isBlockStatement(fn.body)) {
|
|
634
|
+
let unwrapped2 = unwrapExpression2(fn.body);
|
|
635
|
+
return t2.isObjectExpression(unwrapped2) ? unwrapped2 : void 0;
|
|
636
|
+
}
|
|
637
|
+
let statements = fn.body.body, last = statements.at(-1);
|
|
638
|
+
if (!t2.isReturnStatement(last) || !last.argument || !statements.slice(0, -1).every((statement) => t2.isVariableDeclaration(statement) || t2.isExpressionStatement(statement)))
|
|
639
|
+
return;
|
|
640
|
+
let unwrapped = unwrapExpression2(last.argument);
|
|
641
|
+
return t2.isObjectExpression(unwrapped) ? unwrapped : void 0;
|
|
642
|
+
}, csf2Shape = (shape) => {
|
|
643
|
+
let declared = shape.csf._storyExports[shape.exportName], candidates = t2.isVariableDeclarator(declared) ? [declared.init] : (
|
|
644
|
+
// `export { S }` records no declarator; the statement is the initializer it resolved to.
|
|
645
|
+
[declared, shape.csf._storyStatements[shape.exportName]]
|
|
646
|
+
);
|
|
647
|
+
for (let candidate of candidates) {
|
|
648
|
+
let fn = candidate ? unwrapExpression2(candidate) : void 0;
|
|
649
|
+
fn && isCanonicalCsf2BindCall(fn) && (fn = declaredValue(shape, fn.callee.object));
|
|
650
|
+
let returned = returnedObject(fn);
|
|
651
|
+
if (fn && returned)
|
|
652
|
+
return { fn, returned };
|
|
653
|
+
}
|
|
654
|
+
}, functionScope = (fn) => {
|
|
655
|
+
if (!t2.isArrowFunctionExpression(fn) && !t2.isFunctionExpression(fn) && !t2.isFunctionDeclaration(fn) && !t2.isObjectMethod(fn))
|
|
656
|
+
return NO_SCOPE;
|
|
657
|
+
let [firstParam] = fn.params, argsPattern = t2.isAssignmentPattern(firstParam) ? firstParam.left : firstParam, parameterNames = /* @__PURE__ */ new Set();
|
|
658
|
+
fn.params.forEach((param) => collectPatternNames(param, parameterNames));
|
|
659
|
+
let argBindings = /* @__PURE__ */ new Map();
|
|
660
|
+
if (t2.isObjectPattern(argsPattern))
|
|
661
|
+
for (let property of argsPattern.properties) {
|
|
662
|
+
if (!t2.isObjectProperty(property) || property.computed)
|
|
663
|
+
continue;
|
|
664
|
+
let argName = keyNameOf(property), local = t2.isAssignmentPattern(property.value) ? property.value.left : property.value;
|
|
665
|
+
argName !== void 0 && t2.isIdentifier(local) && argBindings.set(local.name, argName);
|
|
666
|
+
}
|
|
667
|
+
let bodyDeclared = /* @__PURE__ */ new Set();
|
|
668
|
+
if (t2.isBlockStatement(fn.body)) {
|
|
669
|
+
for (let statement of fn.body.body)
|
|
670
|
+
if (t2.isVariableDeclaration(statement))
|
|
671
|
+
for (let declarator of statement.declarations)
|
|
672
|
+
collectPatternNames(declarator.id, bodyDeclared);
|
|
673
|
+
}
|
|
674
|
+
let argsExpansions = /* @__PURE__ */ new Map();
|
|
675
|
+
if (t2.isIdentifier(argsPattern))
|
|
676
|
+
argsExpansions.set(argsPattern.name, []);
|
|
677
|
+
else if (t2.isObjectPattern(argsPattern)) {
|
|
678
|
+
let destructured = [], rest, knownKeys = !0;
|
|
679
|
+
for (let property of argsPattern.properties)
|
|
680
|
+
if (t2.isRestElement(property) && t2.isIdentifier(property.argument))
|
|
681
|
+
rest = property.argument.name;
|
|
682
|
+
else if (t2.isObjectProperty(property)) {
|
|
683
|
+
let key = property.computed ? void 0 : keyNameOf(property);
|
|
684
|
+
key !== void 0 ? destructured.push(key) : knownKeys = !1;
|
|
685
|
+
}
|
|
686
|
+
rest !== void 0 && knownKeys && argsExpansions.set(rest, destructured);
|
|
687
|
+
}
|
|
688
|
+
return { argBindings, parameterNames, bodyDeclared, argsExpansions };
|
|
689
|
+
}, collectPatternNames = (pattern, into) => {
|
|
690
|
+
if (t2.isIdentifier(pattern))
|
|
691
|
+
into.add(pattern.name);
|
|
692
|
+
else if (t2.isObjectPattern(pattern))
|
|
693
|
+
for (let property of pattern.properties)
|
|
694
|
+
collectPatternNames(t2.isRestElement(property) ? property.argument : property.value, into);
|
|
695
|
+
else t2.isArrayPattern(pattern) ? pattern.elements.forEach((element) => element && collectPatternNames(element, into)) : t2.isAssignmentPattern(pattern) ? collectPatternNames(pattern.left, into) : t2.isRestElement(pattern) && collectPatternNames(pattern.argument, into);
|
|
696
|
+
}, declaredValue = (shape, node) => {
|
|
697
|
+
if (!t2.isIdentifier(node))
|
|
698
|
+
return node;
|
|
699
|
+
let binding = shape.csf._file.path.scope.getBinding(node.name);
|
|
700
|
+
if (!binding?.constant)
|
|
701
|
+
return node;
|
|
702
|
+
let declaration = binding.path.node;
|
|
703
|
+
return t2.isVariableDeclarator(declaration) ? declaration.init ?? node : t2.isFunctionDeclaration(declaration) ? declaration : node;
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
// src/docgen/story-docs-ng-modules.ts
|
|
707
|
+
import { types as t3 } from "storybook/internal/babel";
|
|
708
|
+
import {
|
|
709
|
+
buildImportStatements,
|
|
710
|
+
keyOf as keyOf2,
|
|
711
|
+
resolveComponentImport,
|
|
712
|
+
unwrapExpression as unwrapExpression3
|
|
713
|
+
} from "storybook/internal/csf-tools";
|
|
714
|
+
var ngModulesFromDecorators = (decorators, componentName) => {
|
|
715
|
+
let result = { names: [], declaresComponent: !1 }, list = decorators === void 0 ? void 0 : unwrapExpression3(decorators);
|
|
716
|
+
if (!list || !t3.isArrayExpression(list))
|
|
717
|
+
return result;
|
|
718
|
+
for (let element of list.elements) {
|
|
719
|
+
if (!element || t3.isSpreadElement(element))
|
|
720
|
+
continue;
|
|
721
|
+
let call = unwrapExpression3(element);
|
|
722
|
+
if (!t3.isCallExpression(call) || !t3.isIdentifier(call.callee, { name: "moduleMetadata" }))
|
|
723
|
+
continue;
|
|
724
|
+
let [metadataArg] = call.arguments, metadata = metadataArg && t3.isExpression(metadataArg) ? unwrapExpression3(metadataArg) : void 0;
|
|
725
|
+
if (!(!metadata || !t3.isObjectExpression(metadata)))
|
|
726
|
+
for (let property of metadata.properties) {
|
|
727
|
+
if (!t3.isObjectProperty(property) || !t3.isExpression(property.value))
|
|
728
|
+
continue;
|
|
729
|
+
let key = keyOf2(property), value = unwrapExpression3(property.value);
|
|
730
|
+
if (!(key !== "imports" && key !== "declarations" || !t3.isArrayExpression(value)))
|
|
731
|
+
for (let item of value.elements) {
|
|
732
|
+
if (!item || t3.isSpreadElement(item))
|
|
733
|
+
continue;
|
|
734
|
+
let entry = unwrapExpression3(item);
|
|
735
|
+
t3.isIdentifier(entry) && (key === "imports" ? entry.name !== componentName && !result.names.includes(entry.name) && result.names.push(entry.name) : entry.name === componentName && (result.declaresComponent = !0));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return result;
|
|
740
|
+
}, storyNgModules = (storyDecorators, { metaNgModules, componentName, importBindings }) => {
|
|
741
|
+
let story = ngModulesFromDecorators(storyDecorators, componentName);
|
|
742
|
+
if (metaNgModules.declaresComponent || story.declaresComponent)
|
|
743
|
+
return;
|
|
744
|
+
let refs = [.../* @__PURE__ */ new Set([...metaNgModules.names, ...story.names])].map((name) => resolveComponentImport(name, importBindings)).filter((ref) => ref.importId);
|
|
745
|
+
if (refs.length !== 0)
|
|
746
|
+
return {
|
|
747
|
+
names: refs.map((ref) => ref.componentName),
|
|
748
|
+
importStatements: buildImportStatements({ refs })
|
|
749
|
+
};
|
|
750
|
+
};
|
|
318
751
|
|
|
319
752
|
// src/docgen/story-docs-snippet.ts
|
|
320
753
|
var HOST_SELECTOR = "app-demo", HOST_CLASS = "DemoComponent", escapeTemplateLiteral = (template) => template.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
321
|
-
var memberName = (name) => isValidIdentifier(name) ? name : `['${name}']`,
|
|
754
|
+
var memberName = (name) => isValidIdentifier(name) ? name : `['${name}']`, memberValue = (value) => value.split(`
|
|
755
|
+
`).join(`
|
|
756
|
+
`), embedTemplate = (template) => template.includes(`
|
|
322
757
|
`) ? `
|
|
323
758
|
${template.split(`
|
|
324
759
|
`).map((line) => line === "" ? line : ` ${line}`).join(`
|
|
@@ -329,15 +764,17 @@ ${template.split(`
|
|
|
329
764
|
viaComponentOutlet,
|
|
330
765
|
standalone,
|
|
331
766
|
ngModules,
|
|
332
|
-
outputs
|
|
767
|
+
outputs,
|
|
768
|
+
fields = []
|
|
333
769
|
}) => {
|
|
334
|
-
let importable = viaComponentOutlet || standalone, moduleNames =
|
|
770
|
+
let importable = viaComponentOutlet || standalone, moduleNames = viaComponentOutlet ? [] : ngModules?.names ?? [], imports = [
|
|
335
771
|
...viaComponentOutlet ? ["import { NgComponentOutlet } from '@angular/common';"] : [],
|
|
336
772
|
"import { Component } from '@angular/core';",
|
|
337
773
|
...componentImport && importable ? [componentImport] : [],
|
|
338
774
|
...moduleNames.length > 0 ? ngModules?.importStatements ?? [] : []
|
|
339
|
-
], declared = viaComponentOutlet ? "NgComponentOutlet" : standalone ? componentName : moduleNames.join(", "), members = [
|
|
775
|
+
], declared = viaComponentOutlet ? "NgComponentOutlet" : [...standalone ? [componentName] : [], ...moduleNames].join(", "), members = [
|
|
340
776
|
...viaComponentOutlet ? [` protected readonly ${componentName} = ${componentName};`] : [],
|
|
777
|
+
...fields.map(({ name, value }) => ` ${memberName(name)} = ${memberValue(value)};`),
|
|
341
778
|
...outputs.map((name) => ` ${memberName(name)}(event: unknown) {}`)
|
|
342
779
|
], body = members.length > 0 ? `{
|
|
343
780
|
${members.join(`
|
|
@@ -357,28 +794,80 @@ ${members.join(`
|
|
|
357
794
|
return warning === void 0 ? { snippet } : { snippet, warning };
|
|
358
795
|
};
|
|
359
796
|
|
|
797
|
+
// src/docgen/story-docs-source.ts
|
|
798
|
+
import { types as t4 } from "storybook/internal/babel";
|
|
799
|
+
import {
|
|
800
|
+
resolveArgValue,
|
|
801
|
+
resolveObjectMembers,
|
|
802
|
+
sourceOf as sourceOf2,
|
|
803
|
+
unwrapExpression as unwrapExpression4
|
|
804
|
+
} from "storybook/internal/csf-tools";
|
|
805
|
+
var authoredSource = (shape, ctx) => {
|
|
806
|
+
for (let members of [shape.members, shape.metaMembers]) {
|
|
807
|
+
let code = memberAt(members, ["parameters", "docs", "source", "code"], ctx);
|
|
808
|
+
if (code.kind === "missing")
|
|
809
|
+
continue;
|
|
810
|
+
if (code.kind === "masked")
|
|
811
|
+
return { kind: "missing" };
|
|
812
|
+
if (code.kind === "unresolvable")
|
|
813
|
+
return code;
|
|
814
|
+
let resolved = resolveArgValue(code.node, ctx), value = unwrapExpression4(resolved.node);
|
|
815
|
+
if (t4.isIdentifier(value, { name: "undefined" }) || t4.isUnaryExpression(value, { operator: "void" }))
|
|
816
|
+
continue;
|
|
817
|
+
if (t4.isNullLiteral(value))
|
|
818
|
+
return { kind: "disabled" };
|
|
819
|
+
if (t4.isStringLiteral(value))
|
|
820
|
+
return { kind: "code", code: value.value };
|
|
821
|
+
let parts = templateParts(value);
|
|
822
|
+
return parts && parts.expressions.length === 0 ? { kind: "code", code: parts.quasis[0] ?? "" } : { kind: "unresolvable", source: sourceOf2(code.node) };
|
|
823
|
+
}
|
|
824
|
+
return { kind: "missing" };
|
|
825
|
+
}, memberAt = (members, path, ctx) => {
|
|
826
|
+
let result = memberOf(members, path[0]);
|
|
827
|
+
for (let [depth, key] of path.slice(1).entries()) {
|
|
828
|
+
if (result.kind !== "value")
|
|
829
|
+
return result;
|
|
830
|
+
let original = result.node, object = unwrapExpression4(resolveArgValue(original, ctx).node);
|
|
831
|
+
if (!t4.isObjectExpression(object))
|
|
832
|
+
return t4.isIdentifier(object, { name: "undefined" }) || t4.isUnaryExpression(object, { operator: "void" }) ? { kind: "missing" } : isOpaqueValue(object) ? { kind: "unresolvable", source: sourceOf2(original) } : depth === 0 ? { kind: "missing" } : { kind: "masked" };
|
|
833
|
+
result = memberOf(resolveObjectMembers(object, ctx), key);
|
|
834
|
+
}
|
|
835
|
+
return result;
|
|
836
|
+
}, memberOf = (members, key) => {
|
|
837
|
+
let node = members.properties[key];
|
|
838
|
+
return node !== void 0 && !members.shadowed.includes(key) ? { kind: "value", node } : members.unresolved.length > 0 ? { kind: "unresolvable", source: members.unresolved.at(-1) } : { kind: "missing" };
|
|
839
|
+
}, isOpaqueValue = (node) => !t4.isLiteral(node) && !t4.isArrayExpression(node) && !t4.isFunction(node);
|
|
840
|
+
|
|
360
841
|
// src/docgen/story-docs-build.ts
|
|
361
842
|
var buildStoryDocsPayload = async (input, context) => {
|
|
362
843
|
let storyImportPath = getStoryImportPathFromEntry(input.entry);
|
|
363
844
|
if (!storyImportPath)
|
|
364
845
|
return;
|
|
365
|
-
let
|
|
366
|
-
if (!
|
|
846
|
+
let storyFilePath = (context.resolvePath ?? ((importPath) => resolve3(process.cwd(), importPath)))(storyImportPath), csf = parseStoryFile(storyFilePath, input.entry.title);
|
|
847
|
+
if (!csf)
|
|
367
848
|
return;
|
|
368
|
-
let
|
|
849
|
+
let componentNode = csf._metaAnnotations.component, docgenPayload = componentNode ? await context.getDocgenPayload(getComponentIdFromEntry(input.entry)) : void 0, enums = docgenPayload?.angularComponentMeta?.enums ?? [], { resolveImport } = context, references = {
|
|
850
|
+
filePath: storyFilePath,
|
|
851
|
+
externalize: createArgExternalizer(enums),
|
|
852
|
+
resolveModule: resolveImport ? (fromFile, specifier) => {
|
|
853
|
+
let target = resolveImport(fromFile, specifier);
|
|
854
|
+
return target === void 0 ? void 0 : parseReferenceModule(target);
|
|
855
|
+
} : openStoryReferences().resolveModule
|
|
856
|
+
}, componentName = componentNameOf(componentNode), importBindings = collectImportBindings(csf._file.path), deps = {
|
|
369
857
|
csf,
|
|
370
|
-
|
|
371
|
-
metaArgs: argsRecordFromNode(csf._metaAnnotations.args),
|
|
372
|
-
metaHasRender: csf._metaAnnotations.render !== void 0,
|
|
858
|
+
resolveStoryArgs: createStoryArgsResolver(csf, references),
|
|
373
859
|
snippetMeta: docgenPayload?.angularComponentMeta,
|
|
374
860
|
componentName,
|
|
375
861
|
componentImport: componentName === void 0 ? void 0 : createImportStatement(componentName, importBindings, docgenPayload),
|
|
376
862
|
metaNgModules: ngModulesFromDecorators(csf._metaAnnotations.decorators, componentName),
|
|
377
863
|
importBindings
|
|
378
|
-
}, stories =
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
864
|
+
}, stories = Object.fromEntries(
|
|
865
|
+
await Promise.all(
|
|
866
|
+
Object.entries(csf._stories).map(
|
|
867
|
+
async ([exportName, story]) => [story.id, await buildStoryDoc(exportName, story, deps)]
|
|
868
|
+
)
|
|
869
|
+
)
|
|
870
|
+
), titleName = input.entry.title.split("/").at(-1).replace(/\s+/g, "");
|
|
382
871
|
return {
|
|
383
872
|
id: getComponentIdFromEntry(input.entry),
|
|
384
873
|
// The docgen payload knows the class name even when the story file imported it under an alias.
|
|
@@ -387,52 +876,16 @@ var buildStoryDocsPayload = async (input, context) => {
|
|
|
387
876
|
stories
|
|
388
877
|
};
|
|
389
878
|
}, createImportStatement = (componentName, importBindings, docgenPayload) => {
|
|
390
|
-
let ref =
|
|
391
|
-
return
|
|
879
|
+
let ref = resolveComponentImport2(componentName, importBindings), importOverride = docgenPayload?.jsDocTags?.import?.[0]?.trim();
|
|
880
|
+
return buildImportStatements2({ refs: [{ ...ref, importOverride }] }).join(`
|
|
392
881
|
`) || void 0;
|
|
393
882
|
}, componentNameOf = (node) => {
|
|
394
|
-
let identifier = node &&
|
|
395
|
-
return identifier &&
|
|
396
|
-
},
|
|
397
|
-
let
|
|
398
|
-
if (!list || !t.isArrayExpression(list))
|
|
399
|
-
return result;
|
|
400
|
-
for (let element of list.elements) {
|
|
401
|
-
if (!element || t.isSpreadElement(element))
|
|
402
|
-
continue;
|
|
403
|
-
let call = unwrapExpression(element);
|
|
404
|
-
if (!t.isCallExpression(call) || !t.isIdentifier(call.callee, { name: "moduleMetadata" }))
|
|
405
|
-
continue;
|
|
406
|
-
let [metadataArg] = call.arguments, metadata = metadataArg && t.isExpression(metadataArg) ? unwrapExpression(metadataArg) : void 0;
|
|
407
|
-
if (!(!metadata || !t.isObjectExpression(metadata)))
|
|
408
|
-
for (let property of metadata.properties) {
|
|
409
|
-
if (!t.isObjectProperty(property) || !t.isExpression(property.value))
|
|
410
|
-
continue;
|
|
411
|
-
let key = keyOf(property), value = unwrapExpression(property.value);
|
|
412
|
-
if (!(key !== "imports" && key !== "declarations" || !t.isArrayExpression(value)))
|
|
413
|
-
for (let item of value.elements) {
|
|
414
|
-
if (!item || t.isSpreadElement(item))
|
|
415
|
-
continue;
|
|
416
|
-
let entry = unwrapExpression(item);
|
|
417
|
-
t.isIdentifier(entry) && (key === "imports" ? entry.name !== componentName && !result.names.includes(entry.name) && result.names.push(entry.name) : entry.name === componentName && (result.declaresComponent = !0));
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
return result;
|
|
422
|
-
}, storyNgModules = (storyDecorators, { metaNgModules, componentName, importBindings }) => {
|
|
423
|
-
let story = ngModulesFromDecorators(storyDecorators, componentName);
|
|
424
|
-
if (metaNgModules.declaresComponent || story.declaresComponent)
|
|
425
|
-
return;
|
|
426
|
-
let refs = [.../* @__PURE__ */ new Set([...metaNgModules.names, ...story.names])].map((name) => resolveComponentImport(name, importBindings)).filter((ref) => ref.importId);
|
|
427
|
-
if (refs.length !== 0)
|
|
428
|
-
return {
|
|
429
|
-
names: refs.map((ref) => ref.componentName),
|
|
430
|
-
importStatements: buildImportStatements({ refs })
|
|
431
|
-
};
|
|
432
|
-
}, buildStoryDoc = (exportName, story, deps) => {
|
|
433
|
-
let { csf, metaArgs, metaHasRender, snippetMeta } = deps, name = story.name ?? storyNameFromExport(exportName);
|
|
883
|
+
let identifier = node && t5.isTSInstantiationExpression(node) ? node.expression : node;
|
|
884
|
+
return identifier && t5.isIdentifier(identifier) ? identifier.name : void 0;
|
|
885
|
+
}, openStoryReferences = createStoryReferenceResolver(), buildStoryDoc = async (exportName, story, deps) => {
|
|
886
|
+
let { csf } = deps, name = story.name ?? storyNameFromExport(exportName);
|
|
434
887
|
try {
|
|
435
|
-
let { description, summary } = extractStoryJSDocInfo(csf._storyStatements[exportName]),
|
|
888
|
+
let { description, summary } = extractStoryJSDocInfo(csf._storyStatements[exportName]), rendered = await renderedSnippet(storyShape(exportName, deps), deps);
|
|
436
889
|
return {
|
|
437
890
|
id: story.id,
|
|
438
891
|
name,
|
|
@@ -449,81 +902,126 @@ var buildStoryDocsPayload = async (input, context) => {
|
|
|
449
902
|
error: { name: err?.name ?? "Error", message: err?.message ?? String(e) }
|
|
450
903
|
};
|
|
451
904
|
}
|
|
452
|
-
},
|
|
453
|
-
let
|
|
454
|
-
|
|
905
|
+
}, renderedSnippet = async (shape, deps) => {
|
|
906
|
+
let authored = authoredSource(shape, deps.resolveStoryArgs.ctx);
|
|
907
|
+
if (authored.kind === "code")
|
|
908
|
+
return { snippet: authored.code };
|
|
909
|
+
if (authored.kind === "disabled")
|
|
910
|
+
return;
|
|
911
|
+
let derived = deps.snippetMeta ? await renderStorySnippet(deps.snippetMeta, shape, shape.members.properties.decorators, deps) : void 0;
|
|
912
|
+
return derived && authored.kind === "unresolvable" ? withWarnings(derived, unresolvedWarning([authored.source])) : derived;
|
|
913
|
+
}, storyShape = (exportName, deps) => {
|
|
914
|
+
let resolved = deps.resolveStoryArgs.resolve(exportName), enums = deps.snippetMeta?.enums ?? [], unresolved = [...resolved.unresolved];
|
|
915
|
+
for (let value of Object.values(resolved.args))
|
|
916
|
+
evaluateArgLiteral(value, enums) === void 0 && !isSelfContained(value) && unresolved.push(sourceOf(value));
|
|
917
|
+
return {
|
|
918
|
+
csf: deps.csf,
|
|
919
|
+
exportName,
|
|
920
|
+
members: resolved.storyMembers,
|
|
921
|
+
metaMembers: resolved.metaMembers,
|
|
922
|
+
args: resolved.args,
|
|
923
|
+
unresolvedArgs: unresolved
|
|
924
|
+
};
|
|
925
|
+
}, renderStorySnippet = async (snippetMeta, shape, storyDecorators, deps) => {
|
|
926
|
+
let { componentImport } = deps, localName = componentNameOf(shape.csf._metaAnnotations.component) ?? snippetMeta.name, ngModules = storyNgModules(storyDecorators, deps), expansion = argsExpansion(snippetMeta, shape), userMarkup = userTemplate(shape, shape.unresolvedArgs.length === 0 ? expansion : void 0), host = (template, viaComponentOutlet, outputs, fields2) => buildHostComponentSnippet({
|
|
455
927
|
template,
|
|
456
928
|
componentName: localName,
|
|
457
929
|
componentImport,
|
|
458
930
|
viaComponentOutlet,
|
|
459
931
|
standalone: snippetMeta.standalone,
|
|
460
|
-
ngModules
|
|
461
|
-
outputs
|
|
932
|
+
ngModules,
|
|
933
|
+
outputs,
|
|
934
|
+
fields: fields2
|
|
462
935
|
});
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
if (
|
|
488
|
-
return
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
936
|
+
if (userMarkup?.kind === "literal") {
|
|
937
|
+
let { analyzeStoryTemplate } = await import("./_node-chunks/story-docs-template-analysis-LGFOFAHO.js"), analysis = analyzeStoryTemplate(userMarkup.markup, userMarkup.expansions), referencedNames = new Set(analysis.kind === "resolved" ? analysis.referencedNames : []), boundOutputs = analysis.kind === "resolved" ? snippetMeta.outputs.filter((name) => analysis.boundOutputs.includes(name)) : [], hostArgs = referencedArgFields(
|
|
938
|
+
referencedNames,
|
|
939
|
+
userMarkup.representedArgs,
|
|
940
|
+
shape,
|
|
941
|
+
boundOutputs,
|
|
942
|
+
snippetMeta.enums
|
|
943
|
+
);
|
|
944
|
+
return withWarnings(
|
|
945
|
+
host(formatTemplateMarkup(analysis.markup), !1, boundOutputs, hostArgs.fields),
|
|
946
|
+
unresolvedWarning([
|
|
947
|
+
...shape.metaMembers.unresolved,
|
|
948
|
+
...shape.members.unresolved,
|
|
949
|
+
...hostArgs.unresolved
|
|
950
|
+
]),
|
|
951
|
+
templateAnalysisWarning(analysis),
|
|
952
|
+
unknownTemplateReferencesWarning(referencedNames, shape, boundOutputs),
|
|
953
|
+
unboundArgsWarning(localName, snippetMeta, shape, [
|
|
954
|
+
...userMarkup.representedArgs,
|
|
955
|
+
...referencedNames
|
|
956
|
+
])
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
let markupSources = userMarkup?.source === void 0 ? [] : [userMarkup.source];
|
|
960
|
+
if (!snippetMeta.selector)
|
|
961
|
+
return withWarnings(
|
|
962
|
+
host(buildComponentOutletTemplate(localName, { selfClosing: !0 }), !0, []),
|
|
963
|
+
unresolvedWarning(markupSources)
|
|
964
|
+
);
|
|
965
|
+
let { bindings, fields } = componentBindings(snippetMeta, shape);
|
|
966
|
+
return withWarnings(
|
|
967
|
+
host(
|
|
968
|
+
buildTemplate(snippetMeta.selector, { ...bindings, selfClosing: !0 }),
|
|
969
|
+
!1,
|
|
970
|
+
snippetMeta.outputs,
|
|
971
|
+
fields
|
|
972
|
+
),
|
|
973
|
+
unresolvedWarning([...markupSources, ...shape.unresolvedArgs]),
|
|
974
|
+
unboundArgsWarning(localName, snippetMeta, shape)
|
|
975
|
+
);
|
|
976
|
+
}, referencedArgFields = (referencedNames, representedArgs, shape, boundOutputs, enums) => {
|
|
977
|
+
let taken = /* @__PURE__ */ new Set([...representedArgs, ...boundOutputs]), fields = [], unresolved = [];
|
|
978
|
+
for (let [name, node] of Object.entries(shape.args)) {
|
|
979
|
+
if (taken.has(name) || !referencedNames.has(name))
|
|
980
|
+
continue;
|
|
981
|
+
let value = evaluateArgLiteral(node, enums);
|
|
982
|
+
if (value === void 0) {
|
|
983
|
+
unresolved.push(sourceOf(node));
|
|
984
|
+
continue;
|
|
505
985
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
986
|
+
fields.push({ name, value });
|
|
987
|
+
}
|
|
988
|
+
return { fields, unresolved };
|
|
989
|
+
}, withWarnings = (rendered, ...parts) => {
|
|
990
|
+
let warning = [.../* @__PURE__ */ new Set([rendered.warning, ...parts])].filter((part) => part !== void 0).join(`
|
|
991
|
+
`);
|
|
992
|
+
return warning === "" ? rendered : { snippet: rendered.snippet, warning };
|
|
993
|
+
}, templateAnalysisWarning = (analysis) => analysis.kind === "resolved" ? void 0 : `Incomplete snippet: the story template could not be analyzed statically. ${analysis.errors.join(`
|
|
994
|
+
`)}`, unknownTemplateReferencesWarning = (referencedNames, shape, outputHandlers) => {
|
|
995
|
+
let provided = /* @__PURE__ */ new Set([...Object.keys(shape.args), ...outputHandlers]), names = [...referencedNames].filter((name) => !provided.has(name));
|
|
996
|
+
return names.length === 0 ? void 0 : `Incomplete snippet: ${names.map((name) => `\`${name}\``).join(", ")} could not be provided, since the story declares no such arg.`;
|
|
997
|
+
}, unboundArgsWarning = (componentName, snippetMeta, shape, representedArgs) => {
|
|
998
|
+
let represented = new Set(representedArgs), inputNames = new Set(snippetMeta.inputs), outputNames = new Set(snippetMeta.outputs), unbound = Object.entries(shape.args).filter(([name, node]) => represented.has(name) || isUndefinedValue(node) ? !1 : representedArgs === void 0 ? !inputNames.has(name) && !outputNames.has(name) : isFunctionValue(node) ? !outputNames.has(name) : !inputNames.has(name)).map(([name, node]) => ({ name, kind: isFunctionValue(node) ? "output" : "input" }));
|
|
999
|
+
if (unbound.length === 0)
|
|
1000
|
+
return;
|
|
1001
|
+
let reason = new Set(unbound.map(({ kind }) => kind)).size === 1 ? `declares no such ${unbound[0].kind}` : "declares no compatible input or output";
|
|
1002
|
+
return `Incomplete snippet: ${unbound.map(({ name }) => `\`${name}\``).join(", ")} could not be bound, since ${componentName} ${reason}.`;
|
|
1003
|
+
}, componentBindings = (snippetMeta, shape) => {
|
|
1004
|
+
let inputNames = new Set(snippetMeta.inputs), inputs = [], fields = [];
|
|
1005
|
+
for (let [name, node] of Object.entries(shape.args))
|
|
1006
|
+
if (inputNames.has(name)) {
|
|
1007
|
+
if (evaluateArgLiteral(node, snippetMeta.enums) === void 0 && isSelfContained(node)) {
|
|
1008
|
+
fields.push({ name, value: argFieldValue(node) }), inputs.push({ name, expression: formatPropInTemplate(name) });
|
|
1009
|
+
continue;
|
|
518
1010
|
}
|
|
519
|
-
|
|
1011
|
+
inputs.push({ name, expression: evaluateArgExpression(node, snippetMeta.enums) });
|
|
520
1012
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
1013
|
+
return { bindings: { inputs, outputs: snippetMeta.outputs }, fields };
|
|
1014
|
+
}, argsExpansion = (snippetMeta, shape) => {
|
|
1015
|
+
let inputNames = new Set(snippetMeta.inputs), outputNames = new Set(snippetMeta.outputs), inputs = [], outputs = [];
|
|
1016
|
+
for (let [name, node] of Object.entries(shape.args))
|
|
1017
|
+
isUndefinedValue(node) || (isFunctionValue(node) ? outputNames.has(name) && outputs.push(name) : inputNames.has(name) && inputs.push({ name, expression: evaluateArgExpression(node, snippetMeta.enums) }));
|
|
1018
|
+
return { inputs, outputs };
|
|
1019
|
+
}, isFunctionValue = (node) => {
|
|
1020
|
+
let unwrapped = unwrapExpression5(node);
|
|
1021
|
+
return t5.isFunction(unwrapped);
|
|
1022
|
+
}, isUndefinedValue = (node) => {
|
|
1023
|
+
let unwrapped = unwrapExpression5(node);
|
|
1024
|
+
return t5.isIdentifier(unwrapped) && unwrapped.name === "undefined" || t5.isUnaryExpression(unwrapped, { operator: "void" });
|
|
527
1025
|
};
|
|
528
1026
|
|
|
529
1027
|
// src/docgen/story-docs-preset.ts
|
|
@@ -531,7 +1029,7 @@ var warnedMissingDocgenService = !1, getDocgenPayload = async (componentId) => {
|
|
|
531
1029
|
try {
|
|
532
1030
|
return await getService("core/docgen", { internal: !0 }).queries.docgen.loaded({ id: componentId });
|
|
533
1031
|
} catch (error) {
|
|
534
|
-
warnedMissingDocgenService || (warnedMissingDocgenService = !0,
|
|
1032
|
+
warnedMissingDocgenService || (warnedMissingDocgenService = !0, logger4.warn(
|
|
535
1033
|
`Angular story snippets are unavailable: querying core/docgen failed. ${error instanceof Error ? error.message : String(error)}`
|
|
536
1034
|
));
|
|
537
1035
|
return;
|
|
@@ -545,7 +1043,10 @@ var warnedMissingDocgenService = !1, getDocgenPayload = async (componentId) => {
|
|
|
545
1043
|
};
|
|
546
1044
|
|
|
547
1045
|
// src/preset.ts
|
|
548
|
-
var addons = [],
|
|
1046
|
+
var addons = [], features = async (existing) => ({
|
|
1047
|
+
...existing,
|
|
1048
|
+
experimentalDocgenServer: !0
|
|
1049
|
+
}), previewAnnotations = async (entries = [], options) => {
|
|
549
1050
|
let config = fileURLToPath2(import.meta.resolve("@storybook/angular-vite/client/config")), annotations = [...entries, config];
|
|
550
1051
|
if (options.enableProdMode) {
|
|
551
1052
|
let previewProdPath = fileURLToPath2(
|
|
@@ -583,13 +1084,20 @@ var viteFinal = async (config, options) => {
|
|
|
583
1084
|
} catch {
|
|
584
1085
|
}
|
|
585
1086
|
config.plugins = (config.plugins ?? []).flat().filter((plugin) => !plugin?.name?.includes("analogjs"));
|
|
586
|
-
let { mergeConfig, normalizePath } = await import("vite"), { default: angular } = await import("@analogjs/vite-plugin-angular"), framework = await options.presets.apply("framework"),
|
|
587
|
-
|
|
1087
|
+
let { mergeConfig, normalizePath } = await import("vite"), { default: angular } = await import("@analogjs/vite-plugin-angular"), framework = await options.presets.apply("framework"), resolvedFeatures = await options.presets.apply(
|
|
1088
|
+
"features",
|
|
1089
|
+
{}
|
|
1090
|
+
), docgenServer = !!resolvedFeatures?.experimentalDocgenServer, compodocConfig = await resolveCompodocConfig(options, { viteRoot: config?.root });
|
|
1091
|
+
compodocConfig.enabled && !docgenServer && await ensureCompodocDocumentation({
|
|
588
1092
|
compodocArgs: compodocConfig.compodocArgs,
|
|
589
1093
|
tsconfig: compodocConfig.tsconfig,
|
|
590
1094
|
workspaceRoot: compodocConfig.workspaceRoot,
|
|
591
1095
|
outputDir: compodocConfig.outputDir
|
|
592
1096
|
});
|
|
1097
|
+
let propsTable = resolvePropsTable(framework.options, resolvedFeatures);
|
|
1098
|
+
warnAboutPropsTable(framework.options, resolvedFeatures), resolvedFeatures?.componentsManifest && !docgenServer && logger5.warn(
|
|
1099
|
+
"The `componentsManifest` feature needs the `experimentalDocgenServer` feature, which is off, so this Storybook publishes no components manifest and MCP clients get no component API from it. Turn the docgen server on with `features: { experimentalDocgenServer: true }` in your `main.ts`."
|
|
1100
|
+
);
|
|
593
1101
|
let zoneless = resolveZoneless(options?.angularBuilderOptions), angularPlugins = angular({
|
|
594
1102
|
jit: typeof framework.options?.jit < "u" ? framework.options?.jit : !0,
|
|
595
1103
|
liveReload: typeof framework.options?.liveReload < "u" ? framework.options?.liveReload : !1,
|
|
@@ -597,6 +1105,15 @@ var viteFinal = async (config, options) => {
|
|
|
597
1105
|
inlineStylesExtension: typeof framework.options?.inlineStylesExtension < "u" ? framework.options?.inlineStylesExtension : "css"
|
|
598
1106
|
}), pluginsToInject = (Array.isArray(angularPlugins) ? angularPlugins : [angularPlugins]).filter(Boolean).map((plugin) => plugin?.name === "@analogjs/vite-plugin-angular" && !plugin.enforce ? { ...plugin, enforce: "pre" } : plugin);
|
|
599
1107
|
return mergeConfig(config, {
|
|
1108
|
+
// `build` already falls back to `compilerOptions.paths` once normal resolution fails, so an
|
|
1109
|
+
// Angular workspace alias with no `node_modules` counterpart already resolves in `build`
|
|
1110
|
+
// today; `dev` only consults `paths` when this is on, so the same alias fails to serve.
|
|
1111
|
+
// Turning it on closes that gap, but for a specifier that resolves both ways - a tsconfig
|
|
1112
|
+
// path alongside a `node_modules` copy of the same package - it also flips precedence to the
|
|
1113
|
+
// tsconfig target in `build`, not just `dev`. See MIGRATION.md.
|
|
1114
|
+
resolve: {
|
|
1115
|
+
tsconfigPaths: config.resolve?.tsconfigPaths ?? !0
|
|
1116
|
+
},
|
|
600
1117
|
// Add dependencies to pre-optimization
|
|
601
1118
|
optimizeDeps: {
|
|
602
1119
|
include: [
|
|
@@ -642,46 +1159,100 @@ var viteFinal = async (config, options) => {
|
|
|
642
1159
|
...pluginsToInject,
|
|
643
1160
|
angularViteRedirectReapplyPlugin(options),
|
|
644
1161
|
angularOptionsPlugin(options, { normalizePath, zoneless }),
|
|
645
|
-
storybookOxcPlugin()
|
|
1162
|
+
storybookOxcPlugin(),
|
|
1163
|
+
...docgenServer && options?.configDir ? [compodocJsonStubPlugin(options.configDir)] : []
|
|
646
1164
|
],
|
|
647
1165
|
define: {
|
|
648
1166
|
STORYBOOK_ANGULAR_OPTIONS: JSON.stringify({
|
|
649
|
-
zoneless: !!zoneless
|
|
1167
|
+
zoneless: !!zoneless,
|
|
1168
|
+
propsTable
|
|
650
1169
|
})
|
|
651
1170
|
}
|
|
652
1171
|
});
|
|
1172
|
+
}, COMPODOC_JSON_STUB_ID = "\0storybook-angular-vite/empty-compodoc-json", EMPTY_COMPODOC_JSON = {
|
|
1173
|
+
classes: [],
|
|
1174
|
+
components: [],
|
|
1175
|
+
coverage: { count: 0, status: "low", files: [] },
|
|
1176
|
+
directives: [],
|
|
1177
|
+
guards: [],
|
|
1178
|
+
injectables: [],
|
|
1179
|
+
interceptors: [],
|
|
1180
|
+
interfaces: [],
|
|
1181
|
+
miscellaneous: {
|
|
1182
|
+
enumerations: [],
|
|
1183
|
+
functions: [],
|
|
1184
|
+
groupedEnumerations: {},
|
|
1185
|
+
groupedFunctions: {},
|
|
1186
|
+
groupedTypeAliases: {},
|
|
1187
|
+
groupedVariables: {},
|
|
1188
|
+
typealiases: [],
|
|
1189
|
+
variables: []
|
|
1190
|
+
},
|
|
1191
|
+
modules: [],
|
|
1192
|
+
pipes: [],
|
|
1193
|
+
routes: { name: "<root>", kind: "module", children: [] }
|
|
653
1194
|
};
|
|
1195
|
+
function compodocJsonStubPlugin(configDir) {
|
|
1196
|
+
let importedFromStorybookConfig = (importer) => {
|
|
1197
|
+
if (!importer)
|
|
1198
|
+
return !1;
|
|
1199
|
+
let fromConfigDir = relative2(configDir, importer);
|
|
1200
|
+
return fromConfigDir !== "" && !fromConfigDir.startsWith("..") && !isAbsolute2(fromConfigDir);
|
|
1201
|
+
};
|
|
1202
|
+
return {
|
|
1203
|
+
name: "storybook-angular-vite-compodoc-json-stub",
|
|
1204
|
+
enforce: "pre",
|
|
1205
|
+
async resolveId(source, importer, resolveOptions) {
|
|
1206
|
+
return basename(source) !== DOCUMENTATION_JSON || !importedFromStorybookConfig(importer) || await this.resolve(source, importer, { ...resolveOptions, skipSelf: !0 }) ? null : COMPODOC_JSON_STUB_ID;
|
|
1207
|
+
},
|
|
1208
|
+
load(id) {
|
|
1209
|
+
return id === COMPODOC_JSON_STUB_ID ? `export default ${JSON.stringify(EMPTY_COMPODOC_JSON)};` : null;
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
var STYLE_EXTENSIONS = [".css", ".scss", ".sass", ".less"], isFile = (path) => statSync2(path, { throwIfNoEntry: !1 })?.isFile() === !0;
|
|
1214
|
+
function resolveBuilderStyle(stylePath, workspaceRoot) {
|
|
1215
|
+
let workspacePath = resolve4(workspaceRoot, stylePath), onDisk = [workspacePath, ...STYLE_EXTENSIONS.map((ext) => workspacePath + ext)].find(
|
|
1216
|
+
isFile
|
|
1217
|
+
);
|
|
1218
|
+
if (onDisk)
|
|
1219
|
+
return onDisk;
|
|
1220
|
+
if (isAbsolute2(stylePath) || /^\.\.?[/\\]/.test(stylePath))
|
|
1221
|
+
throw new AngularUnresolvedStyleError({
|
|
1222
|
+
stylePath,
|
|
1223
|
+
workspaceRoot,
|
|
1224
|
+
extensions: STYLE_EXTENSIONS
|
|
1225
|
+
});
|
|
1226
|
+
return stylePath;
|
|
1227
|
+
}
|
|
654
1228
|
function angularOptionsPlugin(options, { normalizePath, zoneless }) {
|
|
655
|
-
let
|
|
1229
|
+
let resolvedPreviewPath, workspaceRoot = process.cwd();
|
|
656
1230
|
return {
|
|
657
1231
|
name: "storybook-angular-vite-options-plugin",
|
|
658
1232
|
config(userConfig) {
|
|
659
|
-
|
|
1233
|
+
resolvedPreviewPath = findConfigFile("preview", options.configDir) ?? void 0, workspaceRoot = options.angularBuilderContext?.workspaceRoot ?? userConfig?.root ?? process.cwd();
|
|
660
1234
|
let stylePreprocessorOptions = options?.angularBuilderOptions?.stylePreprocessorOptions ?? {}, loadPaths = stylePreprocessorOptions.includePaths ?? stylePreprocessorOptions.loadPaths, sassOptions = stylePreprocessorOptions.sass;
|
|
661
|
-
if (Array.isArray(loadPaths))
|
|
662
|
-
let workspaceRoot = options.angularBuilderContext?.workspaceRoot ?? userConfig?.root ?? process.cwd();
|
|
1235
|
+
if (!(!Array.isArray(loadPaths) && !sassOptions))
|
|
663
1236
|
return {
|
|
664
1237
|
css: {
|
|
665
1238
|
preprocessorOptions: {
|
|
666
1239
|
scss: {
|
|
667
1240
|
...sassOptions,
|
|
668
|
-
loadPaths: loadPaths.map((loadPath) => `${resolve4(workspaceRoot, loadPath)}`)
|
|
1241
|
+
...Array.isArray(loadPaths) ? { loadPaths: loadPaths.map((loadPath) => `${resolve4(workspaceRoot, loadPath)}`) } : {}
|
|
669
1242
|
}
|
|
670
1243
|
}
|
|
671
1244
|
}
|
|
672
1245
|
};
|
|
673
|
-
}
|
|
674
1246
|
},
|
|
675
1247
|
async transform(code, id) {
|
|
676
1248
|
if (resolvedPreviewPath && normalizePath(id).endsWith(normalizePath(resolvedPreviewPath))) {
|
|
677
1249
|
let imports = [], styles = options?.angularBuilderOptions?.styles;
|
|
678
|
-
Array.isArray(styles) && styles.forEach((style) => {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
return {
|
|
1250
|
+
return Array.isArray(styles) && styles.forEach((style) => {
|
|
1251
|
+
let stylePath = typeof style == "string" ? style : style !== null && typeof style == "object" && "input" in style && typeof style.input == "string" ? style.input : void 0;
|
|
1252
|
+
stylePath !== void 0 && imports.push(normalizePath(resolveBuilderStyle(stylePath, workspaceRoot)));
|
|
1253
|
+
}), zoneless || imports.push("zone.js"), {
|
|
683
1254
|
code: `
|
|
684
|
-
${imports.map((extraImport) =>
|
|
1255
|
+
${imports.map((extraImport) => `import '${extraImport}';`).join(`
|
|
685
1256
|
`)}
|
|
686
1257
|
${code}
|
|
687
1258
|
`
|
|
@@ -766,10 +1337,12 @@ var typescript = async (config) => ({
|
|
|
766
1337
|
export {
|
|
767
1338
|
addons,
|
|
768
1339
|
angularOptionsPlugin,
|
|
1340
|
+
compodocJsonStubPlugin,
|
|
769
1341
|
core,
|
|
770
1342
|
experimental_docgenProvider,
|
|
771
1343
|
experimental_manifests,
|
|
772
1344
|
experimental_storyDocsProvider,
|
|
1345
|
+
features,
|
|
773
1346
|
previewAnnotations,
|
|
774
1347
|
typescript,
|
|
775
1348
|
viteFinal
|