@storybook/react 10.5.0-alpha.9 → 10.5.0-beta.0

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.
@@ -0,0 +1,103 @@
1
+ import CJS_COMPAT_NODE_URL_q9tm0u3vmz from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_q9tm0u3vmz from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_q9tm0u3vmz from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_q9tm0u3vmz.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_q9tm0u3vmz.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_q9tm0u3vmz.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ ComponentMetaManager,
14
+ buildComponentDocgenFromResolved,
15
+ extractArgTypes,
16
+ path,
17
+ resolveStoryFileComponents
18
+ } from "../_node-chunks/chunk-DQJ6C235.js";
19
+
20
+ // src/docgen/docgen-worker.ts
21
+ import { STORY_FILE_TEST_REGEXP, getStoryImportPathFromEntry as getStoryImportPathFromEntry2 } from "storybook/internal/common";
22
+
23
+ // src/docgen/buildDocgen.ts
24
+ import { getStoryImportPathFromEntry } from "storybook/internal/common";
25
+ function extractArgTypesFromComponentMeta(componentMeta) {
26
+ return componentMeta ? extractArgTypes({ __docgenInfo: componentMeta }) ?? void 0 : void 0;
27
+ }
28
+ function addArgTypesFromComponentMeta(payload) {
29
+ let argTypes = extractArgTypesFromComponentMeta(payload.reactComponentMeta), subcomponents = payload.subcomponents ? Object.fromEntries(
30
+ Object.entries(payload.subcomponents).map(([name, subcomponent]) => [
31
+ name,
32
+ {
33
+ ...subcomponent,
34
+ argTypes: extractArgTypesFromComponentMeta(subcomponent.reactComponentMeta)
35
+ }
36
+ ])
37
+ ) : void 0;
38
+ return {
39
+ ...payload,
40
+ ...argTypes ? { argTypes } : {},
41
+ ...subcomponents ? { subcomponents } : {}
42
+ };
43
+ }
44
+ async function buildDocgenPayload(input, context) {
45
+ let storyFilePath = getStoryImportPathFromEntry(input.entry);
46
+ if (!storyFilePath)
47
+ return;
48
+ let storyPath = (context.resolvePath ?? ((importPath) => path.join(process.cwd(), importPath)))(storyFilePath), resolved;
49
+ try {
50
+ resolved = await resolveStoryFileComponents({
51
+ storyPath,
52
+ title: input.entry.title,
53
+ typescriptOptions: context.typescriptOptions,
54
+ docgenEngine: "react-component-meta"
55
+ });
56
+ } catch {
57
+ return;
58
+ }
59
+ let { csf, componentName, component, subcomponents, storyFile } = resolved, usableSubcomponents = subcomponents.filter(
60
+ (sub) => sub.component !== void 0
61
+ ), storyRefs = [
62
+ ...component ? [{ storyPath, component }] : [],
63
+ ...usableSubcomponents.map((sub) => ({ storyPath, component: sub.component }))
64
+ ];
65
+ storyRefs.length > 0 && context.componentMetaManager.batchExtract(storyRefs);
66
+ let componentDocgen = buildComponentDocgenFromResolved({
67
+ entry: input.entry,
68
+ storyPath,
69
+ storyFilePath,
70
+ storyFile,
71
+ csf,
72
+ componentName,
73
+ component,
74
+ subcomponents,
75
+ docgenEngine: "react-component-meta"
76
+ });
77
+ return addArgTypesFromComponentMeta(componentDocgen);
78
+ }
79
+
80
+ // src/docgen/docgen-worker.ts
81
+ var createDocgenProvider = () => {
82
+ let managerPromise, getManager = () => (managerPromise || (managerPromise = (async () => {
83
+ try {
84
+ let ts = await import("typescript");
85
+ return new ComponentMetaManager(ts);
86
+ } catch {
87
+ return;
88
+ }
89
+ })()), managerPromise);
90
+ return (nextDocgen) => async (input) => {
91
+ let storyImportPath = getStoryImportPathFromEntry2(input.entry);
92
+ if (!storyImportPath || !STORY_FILE_TEST_REGEXP.test(storyImportPath))
93
+ return nextDocgen(input);
94
+ let componentMetaManager = await getManager();
95
+ if (!componentMetaManager)
96
+ return nextDocgen(input);
97
+ let ours = await buildDocgenPayload(input, { componentMetaManager });
98
+ return ours ? { ...await nextDocgen(input), ...ours } : nextDocgen(input);
99
+ };
100
+ };
101
+ export {
102
+ createDocgenProvider
103
+ };