@storybook/react 9.2.0-alpha.2 → 10.0.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.
- package/README.md +2 -0
- package/dist/_browser-chunks/chunk-BUAOEMNB.js +14 -0
- package/dist/_browser-chunks/chunk-HBQ5Y6GW.js +209 -0
- package/dist/_browser-chunks/chunk-I3XJ5JHI.js +43 -0
- package/dist/_browser-chunks/chunk-L5NVL7MD.js +37 -0
- package/dist/_browser-chunks/chunk-V6XFC4HM.js +18819 -0
- package/dist/_browser-chunks/chunk-VVH2AMAL.js +1075 -0
- package/dist/_browser-chunks/chunk-XNNKYNNU.js +2187 -0
- package/dist/entry-preview-argtypes.js +10 -45
- package/dist/entry-preview-docs.js +13 -17
- package/dist/entry-preview-rsc.js +11 -1
- package/dist/entry-preview.js +21 -1
- package/dist/index.d.ts +447 -10
- package/dist/index.js +79 -46
- package/dist/playwright.js +7 -1
- package/dist/preset.js +203 -1
- package/dist/preview.d.ts +3 -202
- package/dist/preview.d.tsx +420 -0
- package/dist/preview.js +12 -46
- package/package.json +20 -54
- package/preset.js +1 -1
- package/preview.js +1 -0
- package/dist/chunk-6BNVLEVL.mjs +0 -22
- package/dist/chunk-6PSAWJ36.mjs +0 -12
- package/dist/chunk-JQQVJC7C.mjs +0 -36
- package/dist/chunk-MNKU3DTE.mjs +0 -9
- package/dist/chunk-OZUYIFQK.mjs +0 -8
- package/dist/chunk-XLZBPYSH.mjs +0 -6
- package/dist/chunk-XP5HYGXS.mjs +0 -3
- package/dist/entry-preview-argtypes.d.ts +0 -16
- package/dist/entry-preview-argtypes.mjs +0 -3
- package/dist/entry-preview-docs.d.ts +0 -18
- package/dist/entry-preview-docs.mjs +0 -4
- package/dist/entry-preview-rsc.d.ts +0 -7
- package/dist/entry-preview-rsc.mjs +0 -5
- package/dist/entry-preview.d.ts +0 -21
- package/dist/entry-preview.mjs +0 -3
- package/dist/index.mjs +0 -14
- package/dist/playwright.mjs +0 -2
- package/dist/preset.d.ts +0 -19
- package/dist/preview.mjs +0 -7
- package/dist/public-types-d899d203.d.ts +0 -230
- package/dist/types-7abe74eb.d.ts +0 -28
package/README.md
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-L5NVL7MD.js";
|
|
4
|
+
|
|
5
|
+
// src/applyDecorators.ts
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { defaultDecorateStory } from "storybook/preview-api";
|
|
8
|
+
var applyDecorators = /* @__PURE__ */ __name((storyFn, decorators) => {
|
|
9
|
+
return defaultDecorateStory((context) => React.createElement(storyFn, context), decorators);
|
|
10
|
+
}, "applyDecorators");
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
applyDecorators
|
|
14
|
+
};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyDecorators
|
|
3
|
+
} from "./chunk-BUAOEMNB.js";
|
|
4
|
+
import {
|
|
5
|
+
isForwardRef,
|
|
6
|
+
isMemo,
|
|
7
|
+
reactElementToJsxString
|
|
8
|
+
} from "./chunk-VVH2AMAL.js";
|
|
9
|
+
import {
|
|
10
|
+
__export,
|
|
11
|
+
__name
|
|
12
|
+
} from "./chunk-L5NVL7MD.js";
|
|
13
|
+
|
|
14
|
+
// src/entry-preview-docs.ts
|
|
15
|
+
var entry_preview_docs_exports = {};
|
|
16
|
+
__export(entry_preview_docs_exports, {
|
|
17
|
+
applyDecorators: () => applyDecorators2,
|
|
18
|
+
decorators: () => decorators,
|
|
19
|
+
parameters: () => parameters
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// src/docs/jsxDecorator.tsx
|
|
23
|
+
import React, { createElement, isValidElement } from "react";
|
|
24
|
+
import { logger } from "storybook/internal/client-logger";
|
|
25
|
+
import { SourceType, getDocgenSection } from "storybook/internal/docs-tools";
|
|
26
|
+
import { emitTransformCode, useEffect, useRef } from "storybook/preview-api";
|
|
27
|
+
var reactElementToJSXString = reactElementToJsxString;
|
|
28
|
+
var toPascalCase = /* @__PURE__ */ __name((str) => str.charAt(0).toUpperCase() + str.slice(1), "toPascalCase");
|
|
29
|
+
var getReactSymbolName = /* @__PURE__ */ __name((elementType) => {
|
|
30
|
+
const elementName = elementType.$$typeof || elementType;
|
|
31
|
+
const symbolDescription = elementName.toString().replace(/^Symbol\((.*)\)$/, "$1");
|
|
32
|
+
const reactComponentName = symbolDescription.split(".").map((segment) => {
|
|
33
|
+
return segment.split("_").map(toPascalCase).join("");
|
|
34
|
+
}).join(".");
|
|
35
|
+
return reactComponentName;
|
|
36
|
+
}, "getReactSymbolName");
|
|
37
|
+
function simplifyNodeForStringify(node) {
|
|
38
|
+
if (isValidElement(node)) {
|
|
39
|
+
const props = Object.keys(node.props).reduce((acc, cur) => {
|
|
40
|
+
acc[cur] = simplifyNodeForStringify(node.props[cur]);
|
|
41
|
+
return acc;
|
|
42
|
+
}, {});
|
|
43
|
+
return {
|
|
44
|
+
...node,
|
|
45
|
+
props,
|
|
46
|
+
// @ts-expect-error (this is an internal or removed api)
|
|
47
|
+
_owner: null
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(node)) {
|
|
51
|
+
return node.map(simplifyNodeForStringify);
|
|
52
|
+
}
|
|
53
|
+
return node;
|
|
54
|
+
}
|
|
55
|
+
__name(simplifyNodeForStringify, "simplifyNodeForStringify");
|
|
56
|
+
var renderJsx = /* @__PURE__ */ __name((code, options) => {
|
|
57
|
+
if (typeof code === "undefined") {
|
|
58
|
+
logger.warn("Too many skip or undefined component");
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
let renderedJSX = code;
|
|
62
|
+
const Type = renderedJSX.type;
|
|
63
|
+
for (let i = 0; i < options?.skip; i += 1) {
|
|
64
|
+
if (typeof renderedJSX === "undefined") {
|
|
65
|
+
logger.warn("Cannot skip undefined element");
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (React.Children.count(renderedJSX) > 1) {
|
|
69
|
+
logger.warn("Trying to skip an array of elements");
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
if (typeof renderedJSX.props.children === "undefined") {
|
|
73
|
+
logger.warn("Not enough children to skip elements.");
|
|
74
|
+
if (typeof renderedJSX.type === "function" && renderedJSX.type.name === "") {
|
|
75
|
+
renderedJSX = React.createElement(Type, { ...renderedJSX.props });
|
|
76
|
+
}
|
|
77
|
+
} else if (typeof renderedJSX.props.children === "function") {
|
|
78
|
+
renderedJSX = renderedJSX.props.children();
|
|
79
|
+
} else {
|
|
80
|
+
renderedJSX = renderedJSX.props.children;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
let displayNameDefaults;
|
|
84
|
+
if (typeof options?.displayName === "string") {
|
|
85
|
+
displayNameDefaults = { showFunctions: true, displayName: /* @__PURE__ */ __name(() => options.displayName, "displayName") };
|
|
86
|
+
} else {
|
|
87
|
+
displayNameDefaults = {
|
|
88
|
+
// To get exotic component names resolving properly
|
|
89
|
+
displayName: /* @__PURE__ */ __name((el) => {
|
|
90
|
+
if (el.type.displayName) {
|
|
91
|
+
return el.type.displayName;
|
|
92
|
+
} else if (getDocgenSection(el.type, "displayName")) {
|
|
93
|
+
return getDocgenSection(el.type, "displayName");
|
|
94
|
+
} else if (el.type.render?.displayName) {
|
|
95
|
+
return el.type.render.displayName;
|
|
96
|
+
} else if (typeof el.type === "symbol" || el.type.$$typeof && typeof el.type.$$typeof === "symbol") {
|
|
97
|
+
return getReactSymbolName(el.type);
|
|
98
|
+
} else if (el.type.name && el.type.name !== "_default") {
|
|
99
|
+
return el.type.name;
|
|
100
|
+
} else if (typeof el.type === "function") {
|
|
101
|
+
return "No Display Name";
|
|
102
|
+
} else if (isForwardRef(el.type)) {
|
|
103
|
+
return el.type.render.name;
|
|
104
|
+
} else if (isMemo(el.type)) {
|
|
105
|
+
return el.type.type.name;
|
|
106
|
+
} else {
|
|
107
|
+
return el.type;
|
|
108
|
+
}
|
|
109
|
+
}, "displayName")
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const filterDefaults = {
|
|
113
|
+
filterProps: /* @__PURE__ */ __name((value, key) => value !== void 0, "filterProps")
|
|
114
|
+
};
|
|
115
|
+
const opts = {
|
|
116
|
+
...displayNameDefaults,
|
|
117
|
+
...filterDefaults,
|
|
118
|
+
...options
|
|
119
|
+
};
|
|
120
|
+
const result = React.Children.map(code, (c) => {
|
|
121
|
+
const child = typeof c === "number" ? c.toString() : c;
|
|
122
|
+
const toJSXString = typeof reactElementToJSXString === "function" ? reactElementToJSXString : (
|
|
123
|
+
// @ts-expect-error (Converted from ts-ignore)
|
|
124
|
+
reactElementToJSXString.default
|
|
125
|
+
);
|
|
126
|
+
let string = toJSXString(simplifyNodeForStringify(child), opts);
|
|
127
|
+
if (string.indexOf(""") > -1) {
|
|
128
|
+
const matches = string.match(/\S+=\\"([^"]*)\\"/g);
|
|
129
|
+
if (matches) {
|
|
130
|
+
matches.forEach((match) => {
|
|
131
|
+
string = string.replace(match, match.replace(/"/g, "'"));
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return string;
|
|
136
|
+
}).join("\n");
|
|
137
|
+
return result.replace(/function\s+noRefCheck\(\)\s*\{\}/g, "() => {}");
|
|
138
|
+
}, "renderJsx");
|
|
139
|
+
var defaultOpts = {
|
|
140
|
+
skip: 0,
|
|
141
|
+
showFunctions: false,
|
|
142
|
+
enableBeautify: true,
|
|
143
|
+
showDefaultProps: false
|
|
144
|
+
};
|
|
145
|
+
var skipJsxRender = /* @__PURE__ */ __name((context) => {
|
|
146
|
+
const sourceParams = context?.parameters.docs?.source;
|
|
147
|
+
const isArgsStory = context?.parameters.__isArgsStory;
|
|
148
|
+
if (sourceParams?.type === SourceType.DYNAMIC) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
return !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;
|
|
152
|
+
}, "skipJsxRender");
|
|
153
|
+
var isMdx = /* @__PURE__ */ __name((node) => node.type?.displayName === "MDXCreateElement" && !!node.props?.mdxType, "isMdx");
|
|
154
|
+
var mdxToJsx = /* @__PURE__ */ __name((node) => {
|
|
155
|
+
if (!isMdx(node)) {
|
|
156
|
+
return node;
|
|
157
|
+
}
|
|
158
|
+
const { mdxType, originalType, children, ...rest } = node.props;
|
|
159
|
+
let jsxChildren = [];
|
|
160
|
+
if (children) {
|
|
161
|
+
const array = Array.isArray(children) ? children : [children];
|
|
162
|
+
jsxChildren = array.map(mdxToJsx);
|
|
163
|
+
}
|
|
164
|
+
return createElement(originalType, rest, ...jsxChildren);
|
|
165
|
+
}, "mdxToJsx");
|
|
166
|
+
var jsxDecorator = /* @__PURE__ */ __name((storyFn, context) => {
|
|
167
|
+
const jsx = useRef(void 0);
|
|
168
|
+
const story = storyFn();
|
|
169
|
+
const skip = skipJsxRender(context);
|
|
170
|
+
const options = {
|
|
171
|
+
...defaultOpts,
|
|
172
|
+
...context?.parameters.jsx || {}
|
|
173
|
+
};
|
|
174
|
+
const storyJsx = context.originalStoryFn(context.args, context);
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
if (skip) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const sourceJsx = mdxToJsx(storyJsx);
|
|
180
|
+
const rendered = renderJsx(sourceJsx, options);
|
|
181
|
+
if (rendered && jsx.current !== rendered) {
|
|
182
|
+
emitTransformCode(rendered, context);
|
|
183
|
+
jsx.current = rendered;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return story;
|
|
187
|
+
}, "jsxDecorator");
|
|
188
|
+
|
|
189
|
+
// src/docs/applyDecorators.ts
|
|
190
|
+
var applyDecorators2 = /* @__PURE__ */ __name((storyFn, decorators2) => {
|
|
191
|
+
const jsxIndex = decorators2.findIndex((d) => d.originalFn === jsxDecorator);
|
|
192
|
+
const reorderedDecorators = jsxIndex === -1 ? decorators2 : [...decorators2.splice(jsxIndex, 1), ...decorators2];
|
|
193
|
+
return applyDecorators(storyFn, reorderedDecorators);
|
|
194
|
+
}, "applyDecorators");
|
|
195
|
+
|
|
196
|
+
// src/entry-preview-docs.ts
|
|
197
|
+
var decorators = [jsxDecorator];
|
|
198
|
+
var parameters = {
|
|
199
|
+
docs: {
|
|
200
|
+
story: { inline: true }
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export {
|
|
205
|
+
applyDecorators2 as applyDecorators,
|
|
206
|
+
decorators,
|
|
207
|
+
parameters,
|
|
208
|
+
entry_preview_docs_exports
|
|
209
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
entry_preview_exports
|
|
3
|
+
} from "./chunk-XNNKYNNU.js";
|
|
4
|
+
import {
|
|
5
|
+
entry_preview_argtypes_exports
|
|
6
|
+
} from "./chunk-V6XFC4HM.js";
|
|
7
|
+
import {
|
|
8
|
+
entry_preview_docs_exports
|
|
9
|
+
} from "./chunk-HBQ5Y6GW.js";
|
|
10
|
+
import {
|
|
11
|
+
__name
|
|
12
|
+
} from "./chunk-L5NVL7MD.js";
|
|
13
|
+
|
|
14
|
+
// src/preview.tsx
|
|
15
|
+
import { definePreview as definePreviewBase } from "storybook/internal/csf";
|
|
16
|
+
function __definePreview(input) {
|
|
17
|
+
const preview = definePreviewBase({
|
|
18
|
+
...input,
|
|
19
|
+
addons: [
|
|
20
|
+
entry_preview_exports,
|
|
21
|
+
entry_preview_argtypes_exports,
|
|
22
|
+
entry_preview_docs_exports,
|
|
23
|
+
...input.addons ?? []
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
const defineMeta = preview.meta.bind(preview);
|
|
27
|
+
preview.meta = (_input) => {
|
|
28
|
+
const meta = defineMeta(_input);
|
|
29
|
+
const defineStory = meta.story.bind(meta);
|
|
30
|
+
meta.story = (__input) => {
|
|
31
|
+
const story = defineStory(__input);
|
|
32
|
+
story.Component = story.__compose();
|
|
33
|
+
return story;
|
|
34
|
+
};
|
|
35
|
+
return meta;
|
|
36
|
+
};
|
|
37
|
+
return preview;
|
|
38
|
+
}
|
|
39
|
+
__name(__definePreview, "__definePreview");
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
__definePreview
|
|
43
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
__name,
|
|
34
|
+
__commonJS,
|
|
35
|
+
__export,
|
|
36
|
+
__toESM
|
|
37
|
+
};
|