@storybook/react 10.5.0-alpha.5 → 10.5.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/preset.js +111 -118
- package/package.json +4 -3
package/dist/preset.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_swx3ow7zp9i from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_swx3ow7zp9i from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_swx3ow7zp9i from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_swx3ow7zp9i.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_swx3ow7zp9i.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_swx3ow7zp9i.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -16280,9 +16280,9 @@ function buildReactComponentDocgenFromResolved({
|
|
|
16280
16280
|
docgenEngine,
|
|
16281
16281
|
filterStoryIds
|
|
16282
16282
|
}) {
|
|
16283
|
-
let
|
|
16283
|
+
let id = getComponentIdFromEntry(entry), title = entry.title.split("/").at(-1).replace(/\s+/g, ""), packageName = getPackageInfo(component?.path, storyPath), fallbackImport = getFallbackImport(packageName, componentName), imports = getImports({ components: allComponents, packageName }).join(`
|
|
16284
16284
|
`).trim() || fallbackImport, stories = extractStorySnippets(csf, component?.componentName, filterStoryIds), base2 = {
|
|
16285
|
-
|
|
16285
|
+
id,
|
|
16286
16286
|
name: componentName ?? title,
|
|
16287
16287
|
path: storyFilePath,
|
|
16288
16288
|
stories,
|
|
@@ -16345,32 +16345,6 @@ ${storyFile}`
|
|
|
16345
16345
|
error: docgenError
|
|
16346
16346
|
};
|
|
16347
16347
|
}
|
|
16348
|
-
function toReactComponentManifest(resolved) {
|
|
16349
|
-
let { componentId, subcomponents, ...rest } = resolved;
|
|
16350
|
-
return {
|
|
16351
|
-
...rest,
|
|
16352
|
-
id: componentId,
|
|
16353
|
-
...subcomponents ? {
|
|
16354
|
-
subcomponents: Object.fromEntries(
|
|
16355
|
-
Object.entries(subcomponents).map(([key, sub]) => [
|
|
16356
|
-
key,
|
|
16357
|
-
{
|
|
16358
|
-
name: sub.name,
|
|
16359
|
-
path: sub.path,
|
|
16360
|
-
description: sub.description,
|
|
16361
|
-
summary: sub.summary,
|
|
16362
|
-
import: sub.import,
|
|
16363
|
-
jsDocTags: sub.jsDocTags,
|
|
16364
|
-
error: sub.error,
|
|
16365
|
-
reactDocgen: sub.reactDocgen,
|
|
16366
|
-
reactDocgenTypescript: sub.reactDocgenTypescript,
|
|
16367
|
-
reactComponentMeta: sub.reactComponentMeta
|
|
16368
|
-
}
|
|
16369
|
-
])
|
|
16370
|
-
)
|
|
16371
|
-
} : {}
|
|
16372
|
-
};
|
|
16373
|
-
}
|
|
16374
16348
|
|
|
16375
16349
|
// src/componentManifest/componentMetaManagerSingleton.ts
|
|
16376
16350
|
import { logger as logger8 } from "storybook/internal/node-logger";
|
|
@@ -16454,19 +16428,19 @@ function resolveComponentSymbol(typescript, checker, symbol, contextNode, depth
|
|
|
16454
16428
|
}
|
|
16455
16429
|
return resolved;
|
|
16456
16430
|
}
|
|
16457
|
-
function
|
|
16431
|
+
function findImportSymbolInStoryFile(typescript, checker, storySourceFile, componentRef) {
|
|
16458
16432
|
let importSpecifier = componentRef.importId, importName = componentRef.importName, memberAccess = componentRef.member;
|
|
16459
|
-
if (
|
|
16460
|
-
|
|
16461
|
-
|
|
16462
|
-
|
|
16463
|
-
|
|
16464
|
-
|
|
16465
|
-
|
|
16466
|
-
|
|
16467
|
-
|
|
16468
|
-
|
|
16469
|
-
|
|
16433
|
+
if (importSpecifier)
|
|
16434
|
+
for (let stmt of storySourceFile.statements) {
|
|
16435
|
+
if (!typescript.isImportDeclaration(stmt))
|
|
16436
|
+
continue;
|
|
16437
|
+
let moduleSpec = stmt.moduleSpecifier;
|
|
16438
|
+
if (!typescript.isStringLiteral(moduleSpec) || moduleSpec.text !== importSpecifier)
|
|
16439
|
+
continue;
|
|
16440
|
+
let clause = stmt.importClause;
|
|
16441
|
+
if (!clause)
|
|
16442
|
+
continue;
|
|
16443
|
+
let importSymbol;
|
|
16470
16444
|
if (importName === "default") {
|
|
16471
16445
|
if (clause.name && (importSymbol = checker.getSymbolAtLocation(clause.name)), !importSymbol && clause.namedBindings && typescript.isNamedImports(clause.namedBindings)) {
|
|
16472
16446
|
for (let spec of clause.namedBindings.elements)
|
|
@@ -16483,9 +16457,28 @@ function resolvePropsFromStoryFile(typescript, checker, storySourceFile, compone
|
|
|
16483
16457
|
}
|
|
16484
16458
|
}
|
|
16485
16459
|
if (!importSymbol && memberAccess && clause.namedBindings && typescript.isNamespaceImport(clause.namedBindings) && (importSymbol = checker.getSymbolAtLocation(clause.namedBindings.name)), importSymbol)
|
|
16486
|
-
|
|
16460
|
+
return importSymbol;
|
|
16487
16461
|
}
|
|
16462
|
+
}
|
|
16463
|
+
function metaComponentMatchesRef(typescript, checker, storySourceFile, componentRef, metaComponentInitializer) {
|
|
16464
|
+
let refSymbol = findImportSymbolInStoryFile(typescript, checker, storySourceFile, componentRef), metaSymbol = resolveComponentSymbolFromNode(typescript, checker, metaComponentInitializer);
|
|
16465
|
+
if (refSymbol && metaSymbol && !componentRef.member)
|
|
16466
|
+
return resolveAliasedSymbol(typescript, checker, refSymbol) === resolveAliasedSymbol(typescript, checker, metaSymbol);
|
|
16467
|
+
if (typescript.isIdentifier(metaComponentInitializer))
|
|
16468
|
+
return componentRef.componentName === metaComponentInitializer.text;
|
|
16469
|
+
if (typescript.isPropertyAccessExpression(metaComponentInitializer) && typescript.isIdentifier(metaComponentInitializer.expression)) {
|
|
16470
|
+
let metaName = `${metaComponentInitializer.expression.text}.${metaComponentInitializer.name.text}`;
|
|
16471
|
+
return componentRef.componentName === metaName;
|
|
16488
16472
|
}
|
|
16473
|
+
return !1;
|
|
16474
|
+
}
|
|
16475
|
+
function resolvePropsFromStoryFile(typescript, checker, storySourceFile, componentRef) {
|
|
16476
|
+
let memberAccess = componentRef.member, importSymbol = findImportSymbolInStoryFile(
|
|
16477
|
+
typescript,
|
|
16478
|
+
checker,
|
|
16479
|
+
storySourceFile,
|
|
16480
|
+
componentRef
|
|
16481
|
+
);
|
|
16489
16482
|
if (!importSymbol)
|
|
16490
16483
|
return;
|
|
16491
16484
|
let result;
|
|
@@ -16556,6 +16549,37 @@ function resolvePropsFromComponentType(typescript, checker, componentType) {
|
|
|
16556
16549
|
}
|
|
16557
16550
|
}
|
|
16558
16551
|
}
|
|
16552
|
+
function resolvePropsFromComponentExport(typescript, checker, componentSourceFile, componentRef) {
|
|
16553
|
+
let moduleSymbol = checker.getSymbolAtLocation(componentSourceFile);
|
|
16554
|
+
if (!moduleSymbol)
|
|
16555
|
+
return;
|
|
16556
|
+
let exports = checker.getExportsOfModule(checker.getMergedSymbol(moduleSymbol)), exportName = componentRef.importName ?? componentRef.componentName.split(".").at(-1);
|
|
16557
|
+
if (!exportName)
|
|
16558
|
+
return;
|
|
16559
|
+
let exportSymbol, componentType;
|
|
16560
|
+
if (componentRef.namespace && componentRef.member) {
|
|
16561
|
+
let namespaceExportName = componentRef.importName ?? componentRef.member;
|
|
16562
|
+
if (exportSymbol = namespaceExportName === "default" ? exports.find((symbol) => symbol.getName() === "default") : exports.find((symbol) => symbol.getName() === namespaceExportName), !exportSymbol)
|
|
16563
|
+
return;
|
|
16564
|
+
componentType = checker.getTypeOfSymbol(exportSymbol);
|
|
16565
|
+
} else {
|
|
16566
|
+
if (exportSymbol = exportName === "default" ? exports.find((symbol) => symbol.getName() === "default") : exports.find((symbol) => symbol.getName() === exportName), !exportSymbol)
|
|
16567
|
+
return;
|
|
16568
|
+
if (componentType = checker.getTypeOfSymbol(exportSymbol), componentRef.member) {
|
|
16569
|
+
let memberSymbol = componentType.getProperty(componentRef.member);
|
|
16570
|
+
if (!memberSymbol)
|
|
16571
|
+
return;
|
|
16572
|
+
exportSymbol = memberSymbol, componentType = checker.getTypeOfSymbol(memberSymbol);
|
|
16573
|
+
}
|
|
16574
|
+
}
|
|
16575
|
+
let propsType = resolvePropsFromComponentType(typescript, checker, componentType), contextNode = exportSymbol ? getSymbolContextNode(exportSymbol) : void 0;
|
|
16576
|
+
if (!(!propsType || !exportSymbol || !contextNode))
|
|
16577
|
+
return {
|
|
16578
|
+
componentRef,
|
|
16579
|
+
propsType,
|
|
16580
|
+
symbol: resolveComponentSymbol(typescript, checker, exportSymbol, contextNode)
|
|
16581
|
+
};
|
|
16582
|
+
}
|
|
16559
16583
|
function getPropSourceFile(prop) {
|
|
16560
16584
|
let declarations = prop.getDeclarations();
|
|
16561
16585
|
if (declarations?.length) {
|
|
@@ -17175,6 +17199,11 @@ var ComponentMetaProject = class {
|
|
|
17175
17199
|
checker,
|
|
17176
17200
|
storySourceFile,
|
|
17177
17201
|
entryComponent
|
|
17202
|
+
)), resolvedComponent || (resolvedComponent = resolvePropsFromComponentExport(
|
|
17203
|
+
this.typescript,
|
|
17204
|
+
checker,
|
|
17205
|
+
componentSourceFile,
|
|
17206
|
+
entryComponent
|
|
17178
17207
|
)), !resolvedComponent)
|
|
17179
17208
|
continue;
|
|
17180
17209
|
let serializationContext = serializationContextByComponentPath.get(componentPath);
|
|
@@ -17230,7 +17259,16 @@ var ComponentMetaProject = class {
|
|
|
17230
17259
|
if (!defaultExport)
|
|
17231
17260
|
return;
|
|
17232
17261
|
let componentProp = checker.getTypeOfSymbol(defaultExport).getProperty("component");
|
|
17233
|
-
if (!componentProp)
|
|
17262
|
+
if (!componentProp?.valueDeclaration || !this.typescript.isPropertyAssignment(componentProp.valueDeclaration))
|
|
17263
|
+
return;
|
|
17264
|
+
let metaComponentInitializer = componentProp.valueDeclaration.initializer;
|
|
17265
|
+
if (!metaComponentInitializer || !metaComponentMatchesRef(
|
|
17266
|
+
this.typescript,
|
|
17267
|
+
checker,
|
|
17268
|
+
storySourceFile,
|
|
17269
|
+
componentRef,
|
|
17270
|
+
metaComponentInitializer
|
|
17271
|
+
))
|
|
17234
17272
|
return;
|
|
17235
17273
|
let componentType = checker.getTypeOfSymbol(componentProp), selectedSymbol = componentProp.valueDeclaration && this.typescript.isPropertyAssignment(componentProp.valueDeclaration) ? checker.getSymbolAtLocation(componentProp.valueDeclaration.initializer) : componentType.getSymbol?.();
|
|
17236
17274
|
if (memberAccess) {
|
|
@@ -17620,7 +17658,17 @@ function getSharedComponentMetaManager() {
|
|
|
17620
17658
|
|
|
17621
17659
|
// src/componentManifest/generator.ts
|
|
17622
17660
|
var manifests = async (existingManifests = {}, options) => {
|
|
17623
|
-
let { manifestEntries, presets, watch: watch2 } = options, typescriptOptions = await presets?.apply("typescript", {}) ?? {},
|
|
17661
|
+
let { manifestEntries, presets, watch: watch2 } = options, typescriptOptions = await presets?.apply("typescript", {}) ?? {}, features = await presets?.apply("features", {});
|
|
17662
|
+
if (features?.experimentalDocgenServer)
|
|
17663
|
+
return {
|
|
17664
|
+
...existingManifests,
|
|
17665
|
+
components: {
|
|
17666
|
+
v: 0,
|
|
17667
|
+
components: {},
|
|
17668
|
+
meta: { docgen: "react-component-meta", durationMs: 0 }
|
|
17669
|
+
}
|
|
17670
|
+
};
|
|
17671
|
+
let docgenEngine = features?.experimentalReactComponentMeta ? "react-component-meta" : typescriptOptions.reactDocgen || "react-docgen";
|
|
17624
17672
|
invalidateCache(), invalidateParser();
|
|
17625
17673
|
let startTime = performance.now(), manager = docgenEngine === "react-component-meta" ? await getSharedComponentMetaManager() : void 0, entriesByUniqueComponent = [
|
|
17626
17674
|
...selectComponentEntriesByComponentId(manifestEntries).values()
|
|
@@ -17660,21 +17708,19 @@ var manifests = async (existingManifests = {}, options) => {
|
|
|
17660
17708
|
componentName,
|
|
17661
17709
|
allComponents,
|
|
17662
17710
|
subcomponents
|
|
17663
|
-
}) =>
|
|
17664
|
-
|
|
17665
|
-
|
|
17666
|
-
|
|
17667
|
-
|
|
17668
|
-
|
|
17669
|
-
|
|
17670
|
-
|
|
17671
|
-
|
|
17672
|
-
|
|
17673
|
-
|
|
17674
|
-
|
|
17675
|
-
|
|
17676
|
-
})
|
|
17677
|
-
)
|
|
17711
|
+
}) => buildReactComponentDocgenFromResolved({
|
|
17712
|
+
entry,
|
|
17713
|
+
storyPath,
|
|
17714
|
+
storyFilePath,
|
|
17715
|
+
storyFile,
|
|
17716
|
+
csf,
|
|
17717
|
+
componentName,
|
|
17718
|
+
component,
|
|
17719
|
+
allComponents,
|
|
17720
|
+
subcomponents,
|
|
17721
|
+
docgenEngine,
|
|
17722
|
+
filterStoryIds: manifestEntryIds
|
|
17723
|
+
})
|
|
17678
17724
|
).filter((component) => component !== void 0);
|
|
17679
17725
|
manager && watch2 && manager.startWatching();
|
|
17680
17726
|
let durationMs = Math.round(performance.now() - startTime);
|
|
@@ -17769,57 +17815,6 @@ import { STORY_FILE_TEST_REGEXP, getStoryImportPathFromEntry as getStoryImportPa
|
|
|
17769
17815
|
|
|
17770
17816
|
// src/docgen/buildDocgen.ts
|
|
17771
17817
|
import { getStoryImportPathFromEntry as getStoryImportPathFromEntry2 } from "storybook/internal/common";
|
|
17772
|
-
function mapProps(doc) {
|
|
17773
|
-
return doc ? Object.values(doc.props).map((prop) => ({
|
|
17774
|
-
name: prop.name,
|
|
17775
|
-
required: prop.required,
|
|
17776
|
-
type: prop.type,
|
|
17777
|
-
description: prop.description,
|
|
17778
|
-
defaultValue: prop.defaultValue,
|
|
17779
|
-
parent: prop.parent,
|
|
17780
|
-
declarations: prop.declarations
|
|
17781
|
-
})) : [];
|
|
17782
|
-
}
|
|
17783
|
-
function mapSubcomponentToDocgen(sub) {
|
|
17784
|
-
return {
|
|
17785
|
-
name: sub.name,
|
|
17786
|
-
path: sub.path,
|
|
17787
|
-
description: sub.description,
|
|
17788
|
-
summary: sub.summary,
|
|
17789
|
-
import: sub.import,
|
|
17790
|
-
jsDocTags: sub.jsDocTags,
|
|
17791
|
-
props: mapProps(sub.reactComponentMeta),
|
|
17792
|
-
error: sub.error
|
|
17793
|
-
};
|
|
17794
|
-
}
|
|
17795
|
-
function toDocgenPayload(resolved) {
|
|
17796
|
-
let stories = resolved.stories.length > 0 ? resolved.stories.map((story) => ({
|
|
17797
|
-
id: story.id,
|
|
17798
|
-
name: story.name,
|
|
17799
|
-
snippet: story.snippet,
|
|
17800
|
-
description: story.description,
|
|
17801
|
-
summary: story.summary,
|
|
17802
|
-
error: story.error
|
|
17803
|
-
})) : void 0, subcomponents = resolved.subcomponents && Object.keys(resolved.subcomponents).length > 0 ? Object.fromEntries(
|
|
17804
|
-
Object.entries(resolved.subcomponents).map(([key, sub]) => [
|
|
17805
|
-
key,
|
|
17806
|
-
mapSubcomponentToDocgen(sub)
|
|
17807
|
-
])
|
|
17808
|
-
) : void 0;
|
|
17809
|
-
return {
|
|
17810
|
-
componentId: resolved.componentId,
|
|
17811
|
-
name: resolved.name,
|
|
17812
|
-
path: resolved.path,
|
|
17813
|
-
import: resolved.import,
|
|
17814
|
-
description: resolved.description ?? "",
|
|
17815
|
-
summary: resolved.summary,
|
|
17816
|
-
jsDocTags: resolved.jsDocTags,
|
|
17817
|
-
props: mapProps(resolved.reactComponentMeta),
|
|
17818
|
-
error: resolved.error,
|
|
17819
|
-
...subcomponents ? { subcomponents } : {},
|
|
17820
|
-
...stories ? { stories } : {}
|
|
17821
|
-
};
|
|
17822
|
-
}
|
|
17823
17818
|
async function buildDocgenPayload(input, context) {
|
|
17824
17819
|
let storyFilePath = getStoryImportPathFromEntry2(input.entry);
|
|
17825
17820
|
if (!storyFilePath)
|
|
@@ -17841,8 +17836,7 @@ async function buildDocgenPayload(input, context) {
|
|
|
17841
17836
|
...component ? [{ storyPath, component }] : [],
|
|
17842
17837
|
...usableSubcomponents.map((sub) => ({ storyPath, component: sub.component }))
|
|
17843
17838
|
];
|
|
17844
|
-
storyRefs.length > 0 && context.componentMetaManager.batchExtract(storyRefs)
|
|
17845
|
-
let componentDocgen = buildReactComponentDocgenFromResolved({
|
|
17839
|
+
return storyRefs.length > 0 && context.componentMetaManager.batchExtract(storyRefs), buildReactComponentDocgenFromResolved({
|
|
17846
17840
|
entry: input.entry,
|
|
17847
17841
|
storyPath,
|
|
17848
17842
|
storyFilePath,
|
|
@@ -17854,7 +17848,6 @@ async function buildDocgenPayload(input, context) {
|
|
|
17854
17848
|
subcomponents,
|
|
17855
17849
|
docgenEngine: "react-component-meta"
|
|
17856
17850
|
});
|
|
17857
|
-
return toDocgenPayload(componentDocgen);
|
|
17858
17851
|
}
|
|
17859
17852
|
|
|
17860
17853
|
// src/docgen/preset.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react",
|
|
3
|
-
"version": "10.5.0-alpha.
|
|
3
|
+
"version": "10.5.0-alpha.6",
|
|
4
4
|
"description": "Storybook React renderer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@storybook/global": "^5.0.0",
|
|
56
|
-
"@storybook/react-dom-shim": "10.5.0-alpha.
|
|
56
|
+
"@storybook/react-dom-shim": "10.5.0-alpha.6",
|
|
57
57
|
"react-docgen": "^8.0.2",
|
|
58
58
|
"react-docgen-typescript": "^2.2.2"
|
|
59
59
|
},
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"escodegen": "^2.1.0",
|
|
75
75
|
"expect-type": "^0.15.0",
|
|
76
76
|
"html-tags": "^3.1.0",
|
|
77
|
+
"memfs": "^4.11.1",
|
|
77
78
|
"prop-types": "^15.7.2",
|
|
78
79
|
"react-element-to-jsx-string": "patch:react-element-to-jsx-string@npm%3A@7rulnik/react-element-to-jsx-string@15.0.1#~/.yarn/patches/@7rulnik-react-element-to-jsx-string-npm-15.0.1-e53b67c4b3.patch",
|
|
79
80
|
"require-from-string": "^2.0.2",
|
|
@@ -85,7 +86,7 @@
|
|
|
85
86
|
"@types/react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
86
87
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
87
88
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
88
|
-
"storybook": "^10.5.0-alpha.
|
|
89
|
+
"storybook": "^10.5.0-alpha.6",
|
|
89
90
|
"typescript": ">= 4.9.x"
|
|
90
91
|
},
|
|
91
92
|
"peerDependenciesMeta": {
|