@storybook/react 11.0.0-alpha.1 → 11.0.0-alpha.3

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.
@@ -0,0 +1,239 @@
1
+ import { ComponentType, JSX } from "react";
2
+ import { Args, ArgsStoryFn, Canvas, DecoratorFunction, ProjectAnnotations, StoryAnnotations, WebRenderer } from "storybook/internal/types";
3
+ import { RootOptions } from "react-dom/client";
4
+ import { AddonTypes, InferTypes, Meta, MetaInput, MetaTypes, Preview, PreviewAddon, Story, StoryArgs, TypedMetaArgKeys } from "storybook/internal/csf";
5
+
6
+ //#region node_modules/type-fest/source/simplify.d.ts
7
+ /**
8
+ Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
9
+
10
+ @example
11
+ ```
12
+ import type {Simplify} from 'type-fest';
13
+
14
+ type PositionProps = {
15
+ top: number;
16
+ left: number;
17
+ };
18
+
19
+ type SizeProps = {
20
+ width: number;
21
+ height: number;
22
+ };
23
+
24
+ // In your editor, hovering over `Props` will show a flattened object with all the properties.
25
+ type Props = Simplify<PositionProps & SizeProps>;
26
+ ```
27
+
28
+ Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
29
+
30
+ If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
31
+
32
+ @example
33
+ ```
34
+ import type {Simplify} from 'type-fest';
35
+
36
+ interface SomeInterface {
37
+ foo: number;
38
+ bar?: string;
39
+ baz: number | undefined;
40
+ }
41
+
42
+ type SomeType = {
43
+ foo: number;
44
+ bar?: string;
45
+ baz: number | undefined;
46
+ };
47
+
48
+ const literal = {foo: 123, bar: 'hello', baz: 456};
49
+ const someType: SomeType = literal;
50
+ const someInterface: SomeInterface = literal;
51
+
52
+ declare function fn(object: Record<string, unknown>): void;
53
+
54
+ fn(literal); // Good: literal object type is sealed
55
+ fn(someType); // Good: type is sealed
56
+ // @ts-expect-error
57
+ fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
58
+ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
59
+ ```
60
+
61
+ @link https://github.com/microsoft/TypeScript/issues/15300
62
+ @see {@link SimplifyDeep}
63
+ @category Object
64
+ */
65
+ type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
66
+ //#endregion
67
+ //#region code/renderers/react/.dts-emit/code/renderers/react/src/types.d.ts
68
+ interface ReactRenderer extends WebRenderer {
69
+ component: ComponentType<this['T']>;
70
+ storyResult: StoryFnReactReturnType;
71
+ mount: (ui?: JSX.Element) => Promise<Canvas>;
72
+ }
73
+ interface ReactParameters {
74
+ /** React renderer configuration */
75
+ react?: {
76
+ /**
77
+ * Whether to enable React Server Components
78
+ *
79
+ * @see https://storybook.js.org/docs/get-started/frameworks/nextjs#react-server-components-rsc
80
+ */
81
+ rsc?: boolean; /** Options passed to React root creation */
82
+ rootOptions?: RootOptions;
83
+ };
84
+ }
85
+ interface ReactTypes extends ReactRenderer {
86
+ parameters: ReactParameters;
87
+ }
88
+ type StoryFnReactReturnType = JSX.Element;
89
+ //#endregion
90
+ //#region code/renderers/react/.dts-emit/code/renderers/react/src/preview.d.ts
91
+ /**
92
+ * Creates a React-specific preview configuration with CSF factories support.
93
+ *
94
+ * This function wraps the base `definePreview` and adds React-specific annotations for rendering
95
+ * and documentation. It returns a `ReactPreview` that provides type-safe `meta()` and `story()`
96
+ * factory methods.
97
+ *
98
+ * @example
99
+ *
100
+ * ```ts
101
+ * // .storybook/preview.ts
102
+ * import { definePreview } from '@storybook/react';
103
+ *
104
+ * export const preview = definePreview({
105
+ * addons: [],
106
+ * parameters: { layout: 'centered' },
107
+ * });
108
+ * ```
109
+ */
110
+ declare function __definePreview<Addons extends PreviewAddon<never>[]>(input: {
111
+ addons: Addons;
112
+ } & ProjectAnnotations<ReactTypes & InferTypes<Addons>>): ReactPreview<ReactTypes & InferTypes<Addons>>;
113
+ /**
114
+ * React-specific Preview interface that provides type-safe CSF factory methods.
115
+ *
116
+ * Use `preview.meta()` to create a meta configuration for a component, and then `meta.story()` to
117
+ * create individual stories. The type system will infer args from the component props, decorators,
118
+ * and any addon types.
119
+ *
120
+ * @example
121
+ *
122
+ * ```ts
123
+ * const meta = preview.meta({ component: Button });
124
+ * export const Primary = meta.story({ args: { label: 'Click me' } });
125
+ * ```
126
+ */
127
+ interface ReactPreview<T extends AddonTypes> extends Omit<Preview<ReactTypes & T>, 'meta' | 'type'> {
128
+ /**
129
+ * Narrows the type of the preview to include additional type information. This is useful when you
130
+ * need to add args that aren't inferred from the component.
131
+ *
132
+ * @example
133
+ *
134
+ * ```ts
135
+ * const meta = preview.type<{ args: { theme: 'light' | 'dark' } }>().meta({
136
+ * component: Button,
137
+ * });
138
+ * ```
139
+ */
140
+ type<R>(): ReactPreview<T & R>;
141
+ meta<TArgs extends Args, Decorators extends DecoratorFunction<ReactTypes & T, any>, TMetaArgKeys extends PropertyKey = never>(meta: {
142
+ render?: ArgsStoryFn<ReactTypes & T, TArgs & T['args']>;
143
+ component?: ComponentType<TArgs>;
144
+ } & MetaInput<ReactTypes & T, TArgs, Decorators, TMetaArgKeys>): ReactMeta<MetaTypes<ReactTypes & T, TArgs, Decorators, TMetaArgKeys>, TMetaArgKeys>;
145
+ }
146
+ /**
147
+ * React-specific Meta interface returned by `preview.meta()`.
148
+ *
149
+ * Provides the `story()` method to create individual stories with proper type inference. Args
150
+ * provided in meta become optional in stories, while missing required args must be provided at the
151
+ * story level.
152
+ */
153
+ interface ReactMeta<T extends ReactTypes, TMetaArgKeys extends PropertyKey = never> extends Meta<T, TMetaArgKeys> {
154
+ /**
155
+ * Creates a story with a custom render function that takes no args.
156
+ *
157
+ * This overload allows you to define a story using just a render function or an object with a
158
+ * render function that doesn't depend on args. Since the render function doesn't use args, no
159
+ * args need to be provided regardless of what's required by the component.
160
+ *
161
+ * @example
162
+ *
163
+ * ```ts
164
+ * // Using just a render function
165
+ * export const CustomRender = meta.story(() => <div>Custom content</div>);
166
+ *
167
+ * // Using an object with render
168
+ * export const WithRender = meta.story({
169
+ * render: () => <MyComponent prop="static" />,
170
+ * });
171
+ * ```
172
+ */
173
+ story<TInput extends (() => ReactTypes['storyResult']) | (StoryAnnotations<T, T['args']> & {
174
+ render: () => ReactTypes['storyResult'];
175
+ })>(story: TInput): ReactStory<T, TInput extends (() => ReactTypes['storyResult']) ? {
176
+ render: TInput;
177
+ } : TInput>;
178
+ /**
179
+ * Creates a story with custom configuration including args, decorators, or other annotations.
180
+ *
181
+ * This is the primary overload for defining stories. Args that were already provided in meta
182
+ * become optional, while any remaining required args must be specified here.
183
+ *
184
+ * @example
185
+ *
186
+ * ```ts
187
+ * // Provide required args not in meta
188
+ * export const Primary = meta.story({
189
+ * args: { label: 'Click me', disabled: false },
190
+ * });
191
+ *
192
+ * // Override meta args and add story-specific configuration
193
+ * export const Disabled = meta.story({
194
+ * args: { disabled: true },
195
+ * decorators: [withCustomWrapper],
196
+ * });
197
+ * ```
198
+ */
199
+ story<TInput extends Simplify<StoryAnnotations<T, T['args'], StoryArgs<T['args'], TMetaArgKeys>>>>(story: TInput): ReactStory<T, TInput>;
200
+ /**
201
+ * Creates a story with no additional configuration.
202
+ *
203
+ * This overload is only available when all required args have been provided in meta. The
204
+ * conditional type `Partial<T['args']> extends StoryArgs<...>` checks if the remaining required
205
+ * args (after accounting for args provided in meta) are all optional. If so, the function accepts
206
+ * zero arguments `[]`. Otherwise, it requires `[never]` which makes this overload unmatchable,
207
+ * forcing the user to provide args.
208
+ *
209
+ * @example
210
+ *
211
+ * ```ts
212
+ * // When meta provides all required args, story() can be called with no arguments
213
+ * const meta = preview.meta({ component: Button, args: { label: 'Hi', disabled: false } });
214
+ * export const Default = meta.story(); // Valid - all args provided in meta
215
+ * ```
216
+ */
217
+ story(..._args: Partial<T['args']> extends StoryArgs<T['args'], TMetaArgKeys> ? [] : [never]): ReactStory<T, {}>;
218
+ /**
219
+ * Add types to the stories created from the returned meta, such as an arg that only one story
220
+ * has: `meta.type<{ args: { icon: string } }>().story({ args: { icon: 'star' } })`.
221
+ */
222
+ type<S>(): ReactMeta<T & S, TypedMetaArgKeys<TMetaArgKeys, S>>;
223
+ }
224
+ /**
225
+ * React-specific Story interface returned by `meta.story()`.
226
+ *
227
+ * Represents a single story with its configuration and provides access to the composed story for
228
+ * testing via `story.run()`.
229
+ *
230
+ * Also includes a `Component` property for portable story compatibility.
231
+ */
232
+ interface ReactStory<T extends ReactTypes, TInput extends {
233
+ play?: (...args: never[]) => void;
234
+ render?: (...args: never[]) => T['storyResult'];
235
+ }> extends Story<T, TInput> {
236
+ Component: ComponentType<Partial<T['args']>>;
237
+ }
238
+ //#endregion
239
+ export { ReactRenderer as a, __definePreview as i, ReactPreview as n, ReactTypes as o, ReactStory as r, Simplify as s, ReactMeta as t };
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_moh6ij0aoc from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_moh6ij0aoc from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_moh6ij0aoc from "node:module";
1
+ import CJS_COMPAT_NODE_URL_zh4h2xjvlz from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_zh4h2xjvlz from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_zh4h2xjvlz from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_moh6ij0aoc.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_moh6ij0aoc.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_moh6ij0aoc.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_zh4h2xjvlz.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_zh4h2xjvlz.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_zh4h2xjvlz.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -15,7 +15,7 @@ import {
15
15
  extractArgTypes,
16
16
  posix,
17
17
  resolveStoryFileComponents
18
- } from "../_node-chunks/chunk-GFBGFJ4J.js";
18
+ } from "../_node-chunks/chunk-ZB4I7IE4.js";
19
19
 
20
20
  // src/docgen/docgen-worker.ts
21
21
  import { createLazyDocgenMiddleware } from "storybook/internal/common";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  argTypesEnhancers,
3
3
  parameters
4
- } from "./_browser-chunks/chunk-5GZAZJC7.js";
4
+ } from "./_browser-chunks/chunk-LGSTPTL6.js";
5
5
  import "./_browser-chunks/chunk-B3FR4PBN.js";
6
6
  import "./_browser-chunks/chunk-UAWMPV5J.js";
7
7
  export {
@@ -5,7 +5,7 @@ import {
5
5
  parameters,
6
6
  render,
7
7
  renderToCanvas
8
- } from "./_browser-chunks/chunk-XACQAYAZ.js";
8
+ } from "./_browser-chunks/chunk-XD4PMI7Q.js";
9
9
  import {
10
10
  applyDecorators
11
11
  } from "./_browser-chunks/chunk-DDIRQRCA.js";