@storybook/react 10.3.0-alpha.11 → 10.3.0-alpha.13
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 +37 -16
- package/package.json +3 -3
package/dist/preset.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_y9v79lwxbk from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_y9v79lwxbk from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_y9v79lwxbk from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_y9v79lwxbk.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_y9v79lwxbk.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_y9v79lwxbk.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -11297,7 +11297,7 @@ function getCodeSnippet(csf, storyName, componentName) {
|
|
|
11297
11297
|
if (callee.isMemberExpression()) {
|
|
11298
11298
|
let obj = callee.get("object"), prop = callee.get("property"), isBind = prop.isIdentifier() && prop.node.name === "bind" || t2.isStringLiteral(prop.node) && prop.node.value === "bind";
|
|
11299
11299
|
if (obj.isIdentifier() && isBind) {
|
|
11300
|
-
let resolved =
|
|
11300
|
+
let resolved = resolveIdentifierInit(storyDeclaration, obj);
|
|
11301
11301
|
resolved && (normalizedPath = resolved);
|
|
11302
11302
|
}
|
|
11303
11303
|
}
|
|
@@ -11325,14 +11325,20 @@ function getCodeSnippet(csf, storyName, componentName) {
|
|
|
11325
11325
|
"Expected story to be csf factory, function or an object expression"
|
|
11326
11326
|
);
|
|
11327
11327
|
let storyProps = normalizedPath.isObjectExpression() ? normalizedPath.get("properties").filter((p) => p.isObjectProperty()) : [], metaPath = pathForNode(csf._file.path, metaObj), metaProps = metaPath?.isObjectExpression() ? metaPath.get("properties").filter((p) => p.isObjectProperty()) : [], getRenderPath = (object) => {
|
|
11328
|
-
let
|
|
11329
|
-
if (
|
|
11330
|
-
|
|
11328
|
+
let renderPath = object.find((p) => keyOf(p.node) === "render")?.get("value");
|
|
11329
|
+
if (!renderPath)
|
|
11330
|
+
return { kind: "missing" };
|
|
11331
|
+
if (renderPath.isIdentifier()) {
|
|
11332
|
+
let resolved = resolveIdentifierInit(storyDeclaration, renderPath);
|
|
11333
|
+
return resolved && (resolved.isArrowFunctionExpression() || resolved.isFunctionExpression() || resolved.isFunctionDeclaration()) ? { kind: "resolved", path: resolved } : { kind: "unresolved" };
|
|
11334
|
+
}
|
|
11335
|
+
if (!(renderPath.isArrowFunctionExpression() || renderPath.isFunctionExpression()))
|
|
11336
|
+
throw renderPath.buildCodeFrameError(
|
|
11331
11337
|
"Expected render to be an arrow function or function expression"
|
|
11332
11338
|
);
|
|
11333
|
-
return
|
|
11334
|
-
},
|
|
11335
|
-
storyFn
|
|
11339
|
+
return { kind: "resolved", path: renderPath };
|
|
11340
|
+
}, metaRender = getRenderPath(metaProps), storyRender = getRenderPath(storyProps);
|
|
11341
|
+
storyFn || (storyFn = storyRender.kind === "resolved" ? storyRender.path : storyRender.kind === "missing" && metaRender.kind === "resolved" ? metaRender.path : void 0);
|
|
11336
11342
|
let metaArgs = metaArgsRecord(metaObj ?? null), storyArgsPath = storyProps.filter((p) => keyOf(p.node) === "args").map((p) => p.get("value")).find((v) => v.isObjectExpression()), storyArgs = argsRecordFromObjectPath(storyArgsPath), storyAssignedArgsPath = storyArgsAssignmentPath(csf._file.path, storyName), storyAssignedArgs = argsRecordFromObjectPath(storyAssignedArgsPath), merged = { ...metaArgs, ...storyArgs, ...storyAssignedArgs }, entries = Object.entries(merged).filter(([k]) => k !== "children"), validEntries = entries.filter(([k, v]) => isValidJsxAttrName(k) && v != null), invalidEntries = entries.filter(([k, v]) => !isValidJsxAttrName(k) && v != null), injectedAttrs = validEntries.map(([k, v]) => toAttr(k, v)).filter((a) => a != null);
|
|
11337
11343
|
if (storyFn) {
|
|
11338
11344
|
let fn = storyFn.node;
|
|
@@ -11356,14 +11362,20 @@ function getCodeSnippet(csf, storyName, componentName) {
|
|
|
11356
11362
|
return stmt;
|
|
11357
11363
|
});
|
|
11358
11364
|
if (changed)
|
|
11359
|
-
return t2.isFunctionDeclaration(fn) ? t2.functionDeclaration(
|
|
11365
|
+
return t2.isFunctionDeclaration(fn) ? t2.functionDeclaration(
|
|
11366
|
+
t2.identifier(storyName),
|
|
11367
|
+
[],
|
|
11368
|
+
t2.blockStatement(newBody),
|
|
11369
|
+
fn.generator,
|
|
11370
|
+
fn.async
|
|
11371
|
+
) : t2.variableDeclaration("const", [
|
|
11360
11372
|
t2.variableDeclarator(
|
|
11361
11373
|
t2.identifier(storyName),
|
|
11362
11374
|
t2.arrowFunctionExpression([], t2.blockStatement(newBody), fn.async)
|
|
11363
11375
|
)
|
|
11364
11376
|
]);
|
|
11365
11377
|
}
|
|
11366
|
-
return t2.isFunctionDeclaration(fn) ? fn : t2.variableDeclaration("const", [t2.variableDeclarator(t2.identifier(storyName), fn)]);
|
|
11378
|
+
return t2.isFunctionDeclaration(fn) ? t2.functionDeclaration(t2.identifier(storyName), fn.params, fn.body, fn.generator, fn.async) : t2.variableDeclaration("const", [t2.variableDeclarator(t2.identifier(storyName), fn)]);
|
|
11367
11379
|
}
|
|
11368
11380
|
invariant(componentName, "Could not generate snippet without component name.");
|
|
11369
11381
|
let invalidSpread = buildInvalidSpread(invalidEntries), name = t2.jsxIdentifier(componentName), openingElAttrs = invalidSpread ? [...injectedAttrs, invalidSpread] : injectedAttrs, children = toJsxChildren(merged.children), selfClosing = children.length === 0, arrow = t2.arrowFunctionExpression(
|
|
@@ -11507,10 +11519,19 @@ function transformArgsSpreadsInJsx(node, merged) {
|
|
|
11507
11519
|
});
|
|
11508
11520
|
return { node: t2.jsxFragment(node.openingFragment, node.closingFragment, fragChildren), changed };
|
|
11509
11521
|
}
|
|
11510
|
-
function
|
|
11522
|
+
function resolveIdentifierInit(storyPath, identifier) {
|
|
11511
11523
|
let programPath = storyPath.findParent((p) => p.isProgram());
|
|
11512
11524
|
if (!programPath)
|
|
11513
11525
|
return null;
|
|
11526
|
+
for (let stmt of programPath.get("body")) {
|
|
11527
|
+
if (stmt.isFunctionDeclaration() && stmt.node.id?.name === identifier.node.name)
|
|
11528
|
+
return stmt;
|
|
11529
|
+
if (stmt.isExportNamedDeclaration()) {
|
|
11530
|
+
let decl = stmt.get("declaration");
|
|
11531
|
+
if (decl.isFunctionDeclaration() && decl.node.id?.name === identifier.node.name)
|
|
11532
|
+
return decl;
|
|
11533
|
+
}
|
|
11534
|
+
}
|
|
11514
11535
|
let match = programPath.get("body").flatMap((stmt) => {
|
|
11515
11536
|
if (stmt.isVariableDeclaration())
|
|
11516
11537
|
return stmt.get("declarations");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react",
|
|
3
|
-
"version": "10.3.0-alpha.
|
|
3
|
+
"version": "10.3.0-alpha.13",
|
|
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.3.0-alpha.
|
|
56
|
+
"@storybook/react-dom-shim": "10.3.0-alpha.13",
|
|
57
57
|
"react-docgen": "^8.0.2",
|
|
58
58
|
"react-docgen-typescript": "^2.2.2"
|
|
59
59
|
},
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
83
83
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
84
|
-
"storybook": "^10.3.0-alpha.
|
|
84
|
+
"storybook": "^10.3.0-alpha.13",
|
|
85
85
|
"typescript": ">= 4.9.x"
|
|
86
86
|
},
|
|
87
87
|
"peerDependenciesMeta": {
|