@storybook/react 10.1.0-alpha.10 → 10.1.0-alpha.11
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-34HS64JJ.js +212 -0
- package/dist/_browser-chunks/chunk-7SRU6CYS.js +681 -0
- package/dist/_browser-chunks/chunk-DDIRQRCA.js +8 -0
- package/dist/_browser-chunks/chunk-FMVW4CIJ.js +6962 -0
- package/dist/_browser-chunks/chunk-M77NQZM3.js +34 -0
- package/dist/_browser-chunks/chunk-OCTWNRZO.js +120 -0
- package/dist/_browser-chunks/{chunk-L5NVL7MD.js → chunk-SL3VIQZ3.js} +7 -13
- package/dist/entry-preview-argtypes.js +3 -3
- package/dist/entry-preview-docs.js +4 -4
- package/dist/entry-preview-rsc.js +2 -2
- package/dist/entry-preview.js +3 -3
- package/dist/index.js +15 -26
- package/dist/playwright.js +1 -1
- package/dist/preset.js +1400 -3101
- package/dist/preview.js +7 -7
- package/package.json +4 -4
- package/dist/_browser-chunks/chunk-7HDTOAND.js +0 -279
- package/dist/_browser-chunks/chunk-APL3BLM6.js +0 -209
- package/dist/_browser-chunks/chunk-BUAOEMNB.js +0 -14
- package/dist/_browser-chunks/chunk-LBDZ5UD7.js +0 -43
- package/dist/_browser-chunks/chunk-SKEPQA2F.js +0 -12031
- package/dist/_browser-chunks/chunk-VVH2AMAL.js +0 -1075
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyDecorators
|
|
3
|
+
} from "./chunk-DDIRQRCA.js";
|
|
4
|
+
import {
|
|
5
|
+
__export
|
|
6
|
+
} from "./chunk-SL3VIQZ3.js";
|
|
7
|
+
|
|
8
|
+
// src/entry-preview.tsx
|
|
9
|
+
var entry_preview_exports = {};
|
|
10
|
+
__export(entry_preview_exports, {
|
|
11
|
+
applyDecorators: () => applyDecorators,
|
|
12
|
+
beforeAll: () => beforeAll,
|
|
13
|
+
decorators: () => decorators,
|
|
14
|
+
mount: () => mount,
|
|
15
|
+
parameters: () => parameters,
|
|
16
|
+
render: () => render,
|
|
17
|
+
renderToCanvas: () => renderToCanvas
|
|
18
|
+
});
|
|
19
|
+
import * as React4 from "react";
|
|
20
|
+
import { global as global2 } from "@storybook/global";
|
|
21
|
+
import { configure } from "storybook/test";
|
|
22
|
+
|
|
23
|
+
// src/act-compat.ts
|
|
24
|
+
import * as React from "react";
|
|
25
|
+
var clonedReact = { ...React };
|
|
26
|
+
function setReactActEnvironment(isReactActEnvironment) {
|
|
27
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;
|
|
28
|
+
}
|
|
29
|
+
function getReactActEnvironment() {
|
|
30
|
+
return globalThis.IS_REACT_ACT_ENVIRONMENT;
|
|
31
|
+
}
|
|
32
|
+
function withGlobalActEnvironment(actImplementation) {
|
|
33
|
+
return (callback) => {
|
|
34
|
+
let previousActEnvironment = getReactActEnvironment();
|
|
35
|
+
setReactActEnvironment(!0);
|
|
36
|
+
try {
|
|
37
|
+
let callbackNeedsToBeAwaited = !1, actResult = actImplementation(() => {
|
|
38
|
+
let result = callback();
|
|
39
|
+
return result !== null && typeof result == "object" && typeof result.then == "function" && (callbackNeedsToBeAwaited = !0), result;
|
|
40
|
+
});
|
|
41
|
+
if (callbackNeedsToBeAwaited) {
|
|
42
|
+
let thenable = actResult;
|
|
43
|
+
return {
|
|
44
|
+
then: (resolve, reject) => {
|
|
45
|
+
thenable.then(
|
|
46
|
+
(returnValue) => {
|
|
47
|
+
setReactActEnvironment(previousActEnvironment), resolve(returnValue);
|
|
48
|
+
},
|
|
49
|
+
(error) => {
|
|
50
|
+
setReactActEnvironment(previousActEnvironment), reject(error);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
} else
|
|
56
|
+
return setReactActEnvironment(previousActEnvironment), actResult;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
throw setReactActEnvironment(previousActEnvironment), error;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var getAct = async ({ disableAct = !1 } = {}) => {
|
|
63
|
+
if (process.env.NODE_ENV === "production" || disableAct)
|
|
64
|
+
return (cb) => cb();
|
|
65
|
+
let reactAct;
|
|
66
|
+
if (typeof clonedReact.act == "function")
|
|
67
|
+
reactAct = clonedReact.act;
|
|
68
|
+
else {
|
|
69
|
+
let deprecatedTestUtils = await import("react-dom/test-utils");
|
|
70
|
+
reactAct = deprecatedTestUtils?.default?.act ?? deprecatedTestUtils.act;
|
|
71
|
+
}
|
|
72
|
+
return withGlobalActEnvironment(reactAct);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/render.tsx
|
|
76
|
+
import React2 from "react";
|
|
77
|
+
var render = (args, context) => {
|
|
78
|
+
let { id, component: Component } = context;
|
|
79
|
+
if (!Component)
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Unable to render story ${id} as the component annotation is missing from the default export`
|
|
82
|
+
);
|
|
83
|
+
return React2.createElement(Component, { ...args });
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/renderToCanvas.tsx
|
|
87
|
+
import React3, { Fragment, Component as ReactComponent, StrictMode } from "react";
|
|
88
|
+
import { global } from "@storybook/global";
|
|
89
|
+
var { FRAMEWORK_OPTIONS } = global, ErrorBoundary = class extends ReactComponent {
|
|
90
|
+
constructor() {
|
|
91
|
+
super(...arguments);
|
|
92
|
+
this.state = { hasError: !1 };
|
|
93
|
+
}
|
|
94
|
+
static getDerivedStateFromError() {
|
|
95
|
+
return { hasError: !0 };
|
|
96
|
+
}
|
|
97
|
+
componentDidMount() {
|
|
98
|
+
let { hasError } = this.state, { showMain } = this.props;
|
|
99
|
+
hasError || showMain();
|
|
100
|
+
}
|
|
101
|
+
componentDidCatch(err) {
|
|
102
|
+
let { showException } = this.props;
|
|
103
|
+
showException(err);
|
|
104
|
+
}
|
|
105
|
+
render() {
|
|
106
|
+
let { hasError } = this.state, { children } = this.props;
|
|
107
|
+
return hasError ? null : children;
|
|
108
|
+
}
|
|
109
|
+
}, Wrapper = FRAMEWORK_OPTIONS?.strictMode ? StrictMode : Fragment, actQueue = [], isActing = !1, processActQueue = async () => {
|
|
110
|
+
if (isActing || actQueue.length === 0)
|
|
111
|
+
return;
|
|
112
|
+
isActing = !0;
|
|
113
|
+
let actTask = actQueue.shift();
|
|
114
|
+
actTask && await actTask(), isActing = !1, processActQueue();
|
|
115
|
+
};
|
|
116
|
+
async function renderToCanvas({
|
|
117
|
+
storyContext,
|
|
118
|
+
unboundStoryFn,
|
|
119
|
+
showMain,
|
|
120
|
+
showException,
|
|
121
|
+
forceRemount
|
|
122
|
+
}, canvasElement) {
|
|
123
|
+
let { renderElement, unmountElement } = await import("@storybook/react-dom-shim"), Story = unboundStoryFn, content = storyContext.parameters.__isPortableStory ? React3.createElement(Story, { ...storyContext }) : React3.createElement(ErrorBoundary, { key: storyContext.id, showMain, showException }, React3.createElement(Story, { ...storyContext })), element = Wrapper ? React3.createElement(Wrapper, null, content) : content;
|
|
124
|
+
forceRemount && unmountElement(canvasElement);
|
|
125
|
+
let act = await getAct({ disableAct: storyContext.viewMode === "docs" });
|
|
126
|
+
return await new Promise(async (resolve, reject) => {
|
|
127
|
+
actQueue.push(async () => {
|
|
128
|
+
try {
|
|
129
|
+
await act(async () => {
|
|
130
|
+
await renderElement(element, canvasElement, storyContext?.parameters?.react?.rootOptions);
|
|
131
|
+
}), resolve();
|
|
132
|
+
} catch (e) {
|
|
133
|
+
reject(e);
|
|
134
|
+
}
|
|
135
|
+
}), processActQueue();
|
|
136
|
+
}), async () => {
|
|
137
|
+
await act(() => {
|
|
138
|
+
unmountElement(canvasElement);
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/mount.ts
|
|
144
|
+
var mount = (context) => async (ui) => (ui != null && (context.originalStoryFn = () => ui), await context.renderToCanvas(), context.canvas);
|
|
145
|
+
|
|
146
|
+
// src/entry-preview.tsx
|
|
147
|
+
var decorators = [
|
|
148
|
+
(story, context) => {
|
|
149
|
+
if (!context.parameters?.react?.rsc)
|
|
150
|
+
return story();
|
|
151
|
+
let [major, minor] = React4.version.split(".").map((part) => parseInt(part, 10));
|
|
152
|
+
if (!Number.isInteger(major) || !Number.isInteger(minor))
|
|
153
|
+
throw new Error("Unable to parse React version");
|
|
154
|
+
if (major < 18 || major === 18 && minor < 3)
|
|
155
|
+
throw new Error("React Server Components require React >= 18.3");
|
|
156
|
+
return React4.createElement(React4.Suspense, null, story());
|
|
157
|
+
},
|
|
158
|
+
(story, context) => {
|
|
159
|
+
if (context.tags?.includes("test-fn") && !global2.FEATURES?.experimentalTestSyntax)
|
|
160
|
+
throw new Error(
|
|
161
|
+
"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"
|
|
162
|
+
);
|
|
163
|
+
return story();
|
|
164
|
+
}
|
|
165
|
+
], parameters = {
|
|
166
|
+
renderer: "react"
|
|
167
|
+
}, beforeAll = async () => {
|
|
168
|
+
try {
|
|
169
|
+
let act = await getAct();
|
|
170
|
+
configure({
|
|
171
|
+
unstable_advanceTimersWrapper: (cb) => act(cb),
|
|
172
|
+
// For more context about why we need disable act warnings in waitFor:
|
|
173
|
+
// https://github.com/reactwg/react-18/discussions/102
|
|
174
|
+
asyncWrapper: async (cb) => {
|
|
175
|
+
let previousActEnvironment = getReactActEnvironment();
|
|
176
|
+
setReactActEnvironment(!1);
|
|
177
|
+
try {
|
|
178
|
+
let result = await cb();
|
|
179
|
+
return await new Promise((resolve) => {
|
|
180
|
+
setTimeout(() => {
|
|
181
|
+
resolve();
|
|
182
|
+
}, 0), jestFakeTimersAreEnabled() && jest.advanceTimersByTime(0);
|
|
183
|
+
}), result;
|
|
184
|
+
} finally {
|
|
185
|
+
setReactActEnvironment(previousActEnvironment);
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
eventWrapper: (cb) => {
|
|
189
|
+
let result;
|
|
190
|
+
return act(() => (result = cb(), result)), result;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
} catch {
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
function jestFakeTimersAreEnabled() {
|
|
197
|
+
return typeof jest < "u" && jest !== null ? (
|
|
198
|
+
// legacy timers
|
|
199
|
+
setTimeout._isMockFunction === !0 || // modern timers
|
|
200
|
+
Object.prototype.hasOwnProperty.call(setTimeout, "clock")
|
|
201
|
+
) : !1;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export {
|
|
205
|
+
render,
|
|
206
|
+
renderToCanvas,
|
|
207
|
+
mount,
|
|
208
|
+
decorators,
|
|
209
|
+
parameters,
|
|
210
|
+
beforeAll,
|
|
211
|
+
entry_preview_exports
|
|
212
|
+
};
|