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