@storybook/react 10.0.0-rc.1 → 10.0.0-rc.2
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/_browser-chunks/chunk-7HDTOAND.js +279 -0
- package/dist/_browser-chunks/{chunk-352EX3YB.js → chunk-O24TFCLO.js} +2 -2
- package/dist/_browser-chunks/{chunk-2SCDRHCG.js → chunk-SKEPQA2F.js} +744 -7833
- package/dist/entry-preview-argtypes.js +1 -1
- package/dist/entry-preview.js +1 -1
- package/dist/index.js +3 -3
- package/dist/preset.js +6 -6
- package/dist/preview.js +3 -3
- package/package.json +3 -5
- package/dist/_browser-chunks/chunk-4WKCOEYI.js +0 -2196
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyDecorators
|
|
3
|
+
} from "./chunk-BUAOEMNB.js";
|
|
4
|
+
import {
|
|
5
|
+
__export,
|
|
6
|
+
__name
|
|
7
|
+
} from "./chunk-L5NVL7MD.js";
|
|
8
|
+
|
|
9
|
+
// src/entry-preview.tsx
|
|
10
|
+
var entry_preview_exports = {};
|
|
11
|
+
__export(entry_preview_exports, {
|
|
12
|
+
applyDecorators: () => applyDecorators,
|
|
13
|
+
beforeAll: () => beforeAll,
|
|
14
|
+
decorators: () => decorators,
|
|
15
|
+
mount: () => mount,
|
|
16
|
+
parameters: () => parameters,
|
|
17
|
+
render: () => render,
|
|
18
|
+
renderToCanvas: () => renderToCanvas
|
|
19
|
+
});
|
|
20
|
+
import * as React4 from "react";
|
|
21
|
+
import { global as global2 } from "@storybook/global";
|
|
22
|
+
import { configure } from "storybook/test";
|
|
23
|
+
|
|
24
|
+
// src/act-compat.ts
|
|
25
|
+
import * as React from "react";
|
|
26
|
+
var clonedReact = { ...React };
|
|
27
|
+
function setReactActEnvironment(isReactActEnvironment) {
|
|
28
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;
|
|
29
|
+
}
|
|
30
|
+
__name(setReactActEnvironment, "setReactActEnvironment");
|
|
31
|
+
function getReactActEnvironment() {
|
|
32
|
+
return globalThis.IS_REACT_ACT_ENVIRONMENT;
|
|
33
|
+
}
|
|
34
|
+
__name(getReactActEnvironment, "getReactActEnvironment");
|
|
35
|
+
function withGlobalActEnvironment(actImplementation) {
|
|
36
|
+
return (callback) => {
|
|
37
|
+
const previousActEnvironment = getReactActEnvironment();
|
|
38
|
+
setReactActEnvironment(true);
|
|
39
|
+
try {
|
|
40
|
+
let callbackNeedsToBeAwaited = false;
|
|
41
|
+
const actResult = actImplementation(() => {
|
|
42
|
+
const result = callback();
|
|
43
|
+
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
44
|
+
callbackNeedsToBeAwaited = true;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
});
|
|
48
|
+
if (callbackNeedsToBeAwaited) {
|
|
49
|
+
const thenable = actResult;
|
|
50
|
+
return {
|
|
51
|
+
then: /* @__PURE__ */ __name((resolve, reject) => {
|
|
52
|
+
thenable.then(
|
|
53
|
+
(returnValue) => {
|
|
54
|
+
setReactActEnvironment(previousActEnvironment);
|
|
55
|
+
resolve(returnValue);
|
|
56
|
+
},
|
|
57
|
+
(error) => {
|
|
58
|
+
setReactActEnvironment(previousActEnvironment);
|
|
59
|
+
reject(error);
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}, "then")
|
|
63
|
+
};
|
|
64
|
+
} else {
|
|
65
|
+
setReactActEnvironment(previousActEnvironment);
|
|
66
|
+
return actResult;
|
|
67
|
+
}
|
|
68
|
+
} catch (error) {
|
|
69
|
+
setReactActEnvironment(previousActEnvironment);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
__name(withGlobalActEnvironment, "withGlobalActEnvironment");
|
|
75
|
+
var getAct = /* @__PURE__ */ __name(async ({ disableAct = false } = {}) => {
|
|
76
|
+
if (process.env.NODE_ENV === "production" || disableAct) {
|
|
77
|
+
return (cb) => cb();
|
|
78
|
+
}
|
|
79
|
+
let reactAct;
|
|
80
|
+
if (typeof clonedReact.act === "function") {
|
|
81
|
+
reactAct = clonedReact.act;
|
|
82
|
+
} else {
|
|
83
|
+
const deprecatedTestUtils = await import("react-dom/test-utils");
|
|
84
|
+
reactAct = deprecatedTestUtils?.default?.act ?? deprecatedTestUtils.act;
|
|
85
|
+
}
|
|
86
|
+
return withGlobalActEnvironment(reactAct);
|
|
87
|
+
}, "getAct");
|
|
88
|
+
|
|
89
|
+
// src/render.tsx
|
|
90
|
+
import React2 from "react";
|
|
91
|
+
var render = /* @__PURE__ */ __name((args, context) => {
|
|
92
|
+
const { id, component: Component } = context;
|
|
93
|
+
if (!Component) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Unable to render story ${id} as the component annotation is missing from the default export`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return React2.createElement(Component, { ...args });
|
|
99
|
+
}, "render");
|
|
100
|
+
|
|
101
|
+
// src/renderToCanvas.tsx
|
|
102
|
+
import React3, { Fragment, Component as ReactComponent, StrictMode } from "react";
|
|
103
|
+
import { global } from "@storybook/global";
|
|
104
|
+
var { FRAMEWORK_OPTIONS } = global;
|
|
105
|
+
var _ErrorBoundary = class _ErrorBoundary extends ReactComponent {
|
|
106
|
+
constructor() {
|
|
107
|
+
super(...arguments);
|
|
108
|
+
this.state = { hasError: false };
|
|
109
|
+
}
|
|
110
|
+
static getDerivedStateFromError() {
|
|
111
|
+
return { hasError: true };
|
|
112
|
+
}
|
|
113
|
+
componentDidMount() {
|
|
114
|
+
const { hasError } = this.state;
|
|
115
|
+
const { showMain } = this.props;
|
|
116
|
+
if (!hasError) {
|
|
117
|
+
showMain();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
componentDidCatch(err) {
|
|
121
|
+
const { showException } = this.props;
|
|
122
|
+
showException(err);
|
|
123
|
+
}
|
|
124
|
+
render() {
|
|
125
|
+
const { hasError } = this.state;
|
|
126
|
+
const { children } = this.props;
|
|
127
|
+
return hasError ? null : children;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
__name(_ErrorBoundary, "ErrorBoundary");
|
|
131
|
+
var ErrorBoundary = _ErrorBoundary;
|
|
132
|
+
var Wrapper = FRAMEWORK_OPTIONS?.strictMode ? StrictMode : Fragment;
|
|
133
|
+
var actQueue = [];
|
|
134
|
+
var isActing = false;
|
|
135
|
+
var processActQueue = /* @__PURE__ */ __name(async () => {
|
|
136
|
+
if (isActing || actQueue.length === 0) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
isActing = true;
|
|
140
|
+
const actTask = actQueue.shift();
|
|
141
|
+
if (actTask) {
|
|
142
|
+
await actTask();
|
|
143
|
+
}
|
|
144
|
+
isActing = false;
|
|
145
|
+
processActQueue();
|
|
146
|
+
}, "processActQueue");
|
|
147
|
+
async function renderToCanvas({
|
|
148
|
+
storyContext,
|
|
149
|
+
unboundStoryFn,
|
|
150
|
+
showMain,
|
|
151
|
+
showException,
|
|
152
|
+
forceRemount
|
|
153
|
+
}, canvasElement) {
|
|
154
|
+
const { renderElement, unmountElement } = await import("@storybook/react-dom-shim");
|
|
155
|
+
const Story = unboundStoryFn;
|
|
156
|
+
const isPortableStory = storyContext.parameters.__isPortableStory;
|
|
157
|
+
const content = isPortableStory ? React3.createElement(Story, { ...storyContext }) : React3.createElement(ErrorBoundary, { key: storyContext.id, showMain, showException }, React3.createElement(Story, { ...storyContext }));
|
|
158
|
+
const element = Wrapper ? React3.createElement(Wrapper, null, content) : content;
|
|
159
|
+
if (forceRemount) {
|
|
160
|
+
unmountElement(canvasElement);
|
|
161
|
+
}
|
|
162
|
+
const act = await getAct({ disableAct: storyContext.viewMode === "docs" });
|
|
163
|
+
await new Promise(async (resolve, reject) => {
|
|
164
|
+
actQueue.push(async () => {
|
|
165
|
+
try {
|
|
166
|
+
await act(async () => {
|
|
167
|
+
await renderElement(element, canvasElement, storyContext?.parameters?.react?.rootOptions);
|
|
168
|
+
});
|
|
169
|
+
resolve();
|
|
170
|
+
} catch (e) {
|
|
171
|
+
reject(e);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
processActQueue();
|
|
175
|
+
});
|
|
176
|
+
return async () => {
|
|
177
|
+
await act(() => {
|
|
178
|
+
unmountElement(canvasElement);
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
__name(renderToCanvas, "renderToCanvas");
|
|
183
|
+
|
|
184
|
+
// src/mount.ts
|
|
185
|
+
var mount = /* @__PURE__ */ __name((context) => async (ui) => {
|
|
186
|
+
if (ui != null) {
|
|
187
|
+
context.originalStoryFn = () => ui;
|
|
188
|
+
}
|
|
189
|
+
await context.renderToCanvas();
|
|
190
|
+
return context.canvas;
|
|
191
|
+
}, "mount");
|
|
192
|
+
|
|
193
|
+
// src/entry-preview.tsx
|
|
194
|
+
var decorators = [
|
|
195
|
+
(story, context) => {
|
|
196
|
+
if (!context.parameters?.react?.rsc) {
|
|
197
|
+
return story();
|
|
198
|
+
}
|
|
199
|
+
const [major, minor] = React4.version.split(".").map((part) => parseInt(part, 10));
|
|
200
|
+
if (!Number.isInteger(major) || !Number.isInteger(minor)) {
|
|
201
|
+
throw new Error("Unable to parse React version");
|
|
202
|
+
}
|
|
203
|
+
if (major < 18 || major === 18 && minor < 3) {
|
|
204
|
+
throw new Error("React Server Components require React >= 18.3");
|
|
205
|
+
}
|
|
206
|
+
return React4.createElement(React4.Suspense, null, story());
|
|
207
|
+
},
|
|
208
|
+
(story, context) => {
|
|
209
|
+
if (context.tags?.includes("test-fn") && !global2.FEATURES?.experimentalTestSyntax) {
|
|
210
|
+
throw new Error(
|
|
211
|
+
"To use the experimental test function, you must enable the experimentalTestSyntax feature flag. See https://storybook.js.org/docs/10/api/main-config/main-config-features#experimentalTestSyntax"
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
return story();
|
|
215
|
+
}
|
|
216
|
+
];
|
|
217
|
+
var parameters = {
|
|
218
|
+
renderer: "react"
|
|
219
|
+
};
|
|
220
|
+
var beforeAll = /* @__PURE__ */ __name(async () => {
|
|
221
|
+
try {
|
|
222
|
+
const act = await getAct();
|
|
223
|
+
configure({
|
|
224
|
+
unstable_advanceTimersWrapper: /* @__PURE__ */ __name((cb) => {
|
|
225
|
+
return act(cb);
|
|
226
|
+
}, "unstable_advanceTimersWrapper"),
|
|
227
|
+
// For more context about why we need disable act warnings in waitFor:
|
|
228
|
+
// https://github.com/reactwg/react-18/discussions/102
|
|
229
|
+
asyncWrapper: /* @__PURE__ */ __name(async (cb) => {
|
|
230
|
+
const previousActEnvironment = getReactActEnvironment();
|
|
231
|
+
setReactActEnvironment(false);
|
|
232
|
+
try {
|
|
233
|
+
const result = await cb();
|
|
234
|
+
await new Promise((resolve) => {
|
|
235
|
+
setTimeout(() => {
|
|
236
|
+
resolve();
|
|
237
|
+
}, 0);
|
|
238
|
+
if (jestFakeTimersAreEnabled()) {
|
|
239
|
+
jest.advanceTimersByTime(0);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return result;
|
|
243
|
+
} finally {
|
|
244
|
+
setReactActEnvironment(previousActEnvironment);
|
|
245
|
+
}
|
|
246
|
+
}, "asyncWrapper"),
|
|
247
|
+
eventWrapper: /* @__PURE__ */ __name((cb) => {
|
|
248
|
+
let result;
|
|
249
|
+
act(() => {
|
|
250
|
+
result = cb();
|
|
251
|
+
return result;
|
|
252
|
+
});
|
|
253
|
+
return result;
|
|
254
|
+
}, "eventWrapper")
|
|
255
|
+
});
|
|
256
|
+
} catch (e) {
|
|
257
|
+
}
|
|
258
|
+
}, "beforeAll");
|
|
259
|
+
function jestFakeTimersAreEnabled() {
|
|
260
|
+
if (typeof jest !== "undefined" && jest !== null) {
|
|
261
|
+
return (
|
|
262
|
+
// legacy timers
|
|
263
|
+
setTimeout._isMockFunction === true || // modern timers
|
|
264
|
+
Object.prototype.hasOwnProperty.call(setTimeout, "clock")
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
__name(jestFakeTimersAreEnabled, "jestFakeTimersAreEnabled");
|
|
270
|
+
|
|
271
|
+
export {
|
|
272
|
+
render,
|
|
273
|
+
renderToCanvas,
|
|
274
|
+
mount,
|
|
275
|
+
decorators,
|
|
276
|
+
parameters,
|
|
277
|
+
beforeAll,
|
|
278
|
+
entry_preview_exports
|
|
279
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
entry_preview_exports
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7HDTOAND.js";
|
|
4
4
|
import {
|
|
5
5
|
entry_preview_argtypes_exports
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SKEPQA2F.js";
|
|
7
7
|
import {
|
|
8
8
|
entry_preview_docs_exports
|
|
9
9
|
} from "./chunk-HBQ5Y6GW.js";
|