@storybook/react 8.6.14 → 10.0.4
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-7HDTOAND.js +279 -0
- package/dist/_browser-chunks/chunk-BUAOEMNB.js +14 -0
- package/dist/_browser-chunks/chunk-HBQ5Y6GW.js +209 -0
- package/dist/_browser-chunks/chunk-L5NVL7MD.js +37 -0
- package/dist/_browser-chunks/chunk-O24TFCLO.js +43 -0
- package/dist/_browser-chunks/chunk-SKEPQA2F.js +12031 -0
- package/dist/_browser-chunks/chunk-VVH2AMAL.js +1075 -0
- package/dist/entry-preview-argtypes.js +10 -0
- package/dist/entry-preview-docs.js +13 -47
- package/dist/entry-preview-rsc.js +11 -1
- package/dist/entry-preview.js +21 -1
- package/dist/index.d.ts +452 -9
- package/dist/index.js +79 -47
- package/dist/playwright.d.ts +1 -1
- package/dist/playwright.js +7 -1
- package/dist/preset.js +511 -1
- package/dist/preview.d.ts +247 -21
- package/dist/preview.js +12 -47
- package/package.json +25 -68
- package/preset.js +1 -1
- package/preview.js +1 -0
- package/template/cli/js/Button.stories.js +2 -2
- package/template/cli/js/Header.stories.js +1 -1
- package/template/cli/js/Page.stories.js +2 -2
- package/template/cli/{ts-4-9 → ts}/Button.stories.ts +3 -2
- package/template/cli/{ts-4-9 → ts}/Header.stories.ts +2 -1
- package/template/cli/{ts-4-9 → ts}/Page.stories.ts +3 -2
- package/template/components/index.js +1 -1
- package/dist/chunk-EWIU6LHT.mjs +0 -56
- package/dist/chunk-TENYCC3B.mjs +0 -8
- package/dist/chunk-XP5HYGXS.mjs +0 -3
- package/dist/chunk-ZGTCCPPZ.mjs +0 -7
- package/dist/entry-preview-docs.d.ts +0 -20
- package/dist/entry-preview-docs.mjs +0 -2
- package/dist/entry-preview-rsc.d.ts +0 -7
- package/dist/entry-preview-rsc.mjs +0 -5
- package/dist/entry-preview.d.ts +0 -19
- package/dist/entry-preview.mjs +0 -2
- package/dist/index.mjs +0 -11
- package/dist/playwright.mjs +0 -2
- package/dist/preset.d.ts +0 -18
- package/dist/preview.mjs +0 -4
- package/dist/public-types-f2c70f25.d.ts +0 -230
- package/dist/types-5617c98e.d.ts +0 -27
- package/template/cli/ts-3-8/Button.stories.ts +0 -53
- package/template/cli/ts-3-8/Header.stories.ts +0 -33
- package/template/cli/ts-3-8/Page.stories.ts +0 -32
- package/template/cli/ts-3-8/Page.tsx +0 -73
- package/template/cli/ts-4-9/Button.tsx +0 -37
- package/template/cli/ts-4-9/Header.tsx +0 -56
- /package/template/cli/{ts-3-8 → ts}/Button.tsx +0 -0
- /package/template/cli/{ts-3-8 → ts}/Header.tsx +0 -0
- /package/template/cli/{ts-4-9 → ts}/Page.tsx +0 -0
package/dist/preview.d.ts
CHANGED
|
@@ -1,8 +1,165 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
|
-
import { Preview, Meta, Story } from 'storybook/internal/csf';
|
|
3
|
-
import { Args, DecoratorFunction, ArgsStoryFn, ComponentAnnotations,
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { ComponentType, JSX } from 'react';
|
|
2
|
+
import { PreviewAddon, InferTypes, AddonTypes, Preview, Meta, Story } from 'storybook/internal/csf';
|
|
3
|
+
import { WebRenderer, Canvas, ProjectAnnotations, Args, DecoratorFunction, ArgsStoryFn, ComponentAnnotations, StoryAnnotations, Renderer } from 'storybook/internal/types';
|
|
4
|
+
import { RootOptions } from 'react-dom/client';
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface SymbolConstructor {
|
|
8
|
+
readonly observable: symbol;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
Returns a boolean for whether the two given types are equal.
|
|
14
|
+
|
|
15
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
16
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
17
|
+
*/
|
|
18
|
+
type IsEqual<T, U> =
|
|
19
|
+
(<G>() => G extends T ? 1 : 2) extends
|
|
20
|
+
(<G>() => G extends U ? 1 : 2)
|
|
21
|
+
? true
|
|
22
|
+
: false;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
Filter out keys from an object.
|
|
26
|
+
|
|
27
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
28
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
29
|
+
Returns `Key` otherwise.
|
|
30
|
+
|
|
31
|
+
@example
|
|
32
|
+
```
|
|
33
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
34
|
+
//=> never
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
@example
|
|
38
|
+
```
|
|
39
|
+
type Filtered = Filter<'bar', string>;
|
|
40
|
+
//=> never
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
@example
|
|
44
|
+
```
|
|
45
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
46
|
+
//=> 'bar'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
@see {Except}
|
|
50
|
+
*/
|
|
51
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
Create a type from an object type without certain keys.
|
|
55
|
+
|
|
56
|
+
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
57
|
+
|
|
58
|
+
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
59
|
+
|
|
60
|
+
@example
|
|
61
|
+
```
|
|
62
|
+
import type {Except} from 'type-fest';
|
|
63
|
+
|
|
64
|
+
type Foo = {
|
|
65
|
+
a: number;
|
|
66
|
+
b: string;
|
|
67
|
+
c: boolean;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type FooWithoutA = Except<Foo, 'a' | 'c'>;
|
|
71
|
+
//=> {b: string};
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
@category Object
|
|
75
|
+
*/
|
|
76
|
+
type Except<ObjectType, KeysType extends keyof ObjectType> = {
|
|
77
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
@see Simplify
|
|
82
|
+
*/
|
|
83
|
+
interface SimplifyOptions {
|
|
84
|
+
/**
|
|
85
|
+
Do the simplification recursively.
|
|
86
|
+
|
|
87
|
+
@default false
|
|
88
|
+
*/
|
|
89
|
+
deep?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Flatten a type without worrying about the result.
|
|
93
|
+
type Flatten<
|
|
94
|
+
AnyType,
|
|
95
|
+
Options extends SimplifyOptions = {},
|
|
96
|
+
> = Options['deep'] extends true
|
|
97
|
+
? {[KeyType in keyof AnyType]: Simplify<AnyType[KeyType], Options>}
|
|
98
|
+
: {[KeyType in keyof AnyType]: AnyType[KeyType]};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
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.
|
|
102
|
+
|
|
103
|
+
@example
|
|
104
|
+
```
|
|
105
|
+
import type {Simplify} from 'type-fest';
|
|
106
|
+
|
|
107
|
+
type PositionProps = {
|
|
108
|
+
top: number;
|
|
109
|
+
left: number;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
type SizeProps = {
|
|
113
|
+
width: number;
|
|
114
|
+
height: number;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
118
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
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.
|
|
122
|
+
|
|
123
|
+
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`.
|
|
124
|
+
|
|
125
|
+
@example
|
|
126
|
+
```
|
|
127
|
+
import type {Simplify} from 'type-fest';
|
|
128
|
+
|
|
129
|
+
interface SomeInterface {
|
|
130
|
+
foo: number;
|
|
131
|
+
bar?: string;
|
|
132
|
+
baz: number | undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
type SomeType = {
|
|
136
|
+
foo: number;
|
|
137
|
+
bar?: string;
|
|
138
|
+
baz: number | undefined;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
142
|
+
const someType: SomeType = literal;
|
|
143
|
+
const someInterface: SomeInterface = literal;
|
|
144
|
+
|
|
145
|
+
function fn(object: Record<string, unknown>): void {}
|
|
146
|
+
|
|
147
|
+
fn(literal); // Good: literal object type is sealed
|
|
148
|
+
fn(someType); // Good: type is sealed
|
|
149
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
150
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
154
|
+
|
|
155
|
+
@category Object
|
|
156
|
+
*/
|
|
157
|
+
type Simplify<
|
|
158
|
+
AnyType,
|
|
159
|
+
Options extends SimplifyOptions = {},
|
|
160
|
+
> = Flatten<AnyType> extends AnyType
|
|
161
|
+
? Flatten<AnyType, Options>
|
|
162
|
+
: AnyType;
|
|
6
163
|
|
|
7
164
|
/**
|
|
8
165
|
Remove any index signatures from the given object type, so that only explicitly defined properties remain.
|
|
@@ -109,6 +266,39 @@ type RemoveIndexSignature<ObjectType> = {
|
|
|
109
266
|
: KeyType]: ObjectType[KeyType];
|
|
110
267
|
};
|
|
111
268
|
|
|
269
|
+
/**
|
|
270
|
+
Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
|
|
271
|
+
|
|
272
|
+
Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
|
|
273
|
+
|
|
274
|
+
@example
|
|
275
|
+
```
|
|
276
|
+
import type {SetOptional} from 'type-fest';
|
|
277
|
+
|
|
278
|
+
type Foo = {
|
|
279
|
+
a: number;
|
|
280
|
+
b?: string;
|
|
281
|
+
c: boolean;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
|
|
285
|
+
// type SomeOptional = {
|
|
286
|
+
// a: number;
|
|
287
|
+
// b?: string; // Was already optional and still is.
|
|
288
|
+
// c?: boolean; // Is now optional.
|
|
289
|
+
// }
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
@category Object
|
|
293
|
+
*/
|
|
294
|
+
type SetOptional<BaseType, Keys extends keyof BaseType> =
|
|
295
|
+
Simplify<
|
|
296
|
+
// Pick just the keys that are readonly from the base type.
|
|
297
|
+
Except<BaseType, Keys> &
|
|
298
|
+
// Pick the keys that should be mutable from the base type and make them mutable.
|
|
299
|
+
Partial<Pick<BaseType, Keys>>
|
|
300
|
+
>;
|
|
301
|
+
|
|
112
302
|
/**
|
|
113
303
|
Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
114
304
|
|
|
@@ -170,30 +360,66 @@ type UnionToIntersection<Union> = (
|
|
|
170
360
|
? Intersection
|
|
171
361
|
: never;
|
|
172
362
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
363
|
+
interface ReactRenderer extends WebRenderer {
|
|
364
|
+
component: ComponentType<this['T']>;
|
|
365
|
+
storyResult: StoryFnReactReturnType;
|
|
366
|
+
mount: (ui?: JSX.Element) => Promise<Canvas>;
|
|
367
|
+
}
|
|
368
|
+
interface ReactParameters {
|
|
369
|
+
/** React renderer configuration */
|
|
370
|
+
react?: {
|
|
371
|
+
/**
|
|
372
|
+
* Whether to enable React Server Components
|
|
373
|
+
*
|
|
374
|
+
* @see https://storybook.js.org/docs/get-started/frameworks/nextjs#react-server-components-rsc
|
|
375
|
+
*/
|
|
376
|
+
rsc?: boolean;
|
|
377
|
+
/** Options passed to React root creation */
|
|
378
|
+
rootOptions?: RootOptions;
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
interface ReactTypes extends ReactRenderer {
|
|
382
|
+
parameters: ReactParameters;
|
|
383
|
+
}
|
|
384
|
+
type StoryFnReactReturnType = JSX.Element;
|
|
385
|
+
|
|
386
|
+
type AddMocks<TArgs, DefaultArgs> = Simplify<{
|
|
387
|
+
[T in keyof TArgs]: T extends keyof DefaultArgs ? DefaultArgs[T] extends (...args: any) => any & {
|
|
388
|
+
mock: {};
|
|
389
|
+
} ? DefaultArgs[T] : TArgs[T] : TArgs[T];
|
|
390
|
+
}>;
|
|
391
|
+
|
|
392
|
+
declare function __definePreview<Addons extends PreviewAddon<never>[]>(input: {
|
|
393
|
+
addons: Addons;
|
|
394
|
+
} & ProjectAnnotations<ReactTypes & InferTypes<Addons>>): ReactPreview<ReactTypes & InferTypes<Addons>>;
|
|
395
|
+
/** @ts-expect-error We cannot implement the meta faithfully here, but that is okay. */
|
|
396
|
+
interface ReactPreview<T extends AddonTypes> extends Preview<ReactTypes & T> {
|
|
397
|
+
meta<TArgs extends Args, Decorators extends DecoratorFunction<ReactTypes & T, any>, TMetaArgs extends Partial<TArgs>>(meta: {
|
|
398
|
+
render?: ArgsStoryFn<ReactTypes & T, TArgs>;
|
|
178
399
|
component?: ComponentType<TArgs>;
|
|
179
400
|
decorators?: Decorators | Decorators[];
|
|
180
401
|
args?: TMetaArgs;
|
|
181
|
-
} & Omit<ComponentAnnotations<
|
|
182
|
-
args: Simplify<TArgs & Simplify<RemoveIndexSignature<DecoratorsArgs<
|
|
402
|
+
} & Omit<ComponentAnnotations<ReactTypes & T, TArgs>, 'decorators' | 'component' | 'args' | 'render'>): ReactMeta<ReactTypes & T & {
|
|
403
|
+
args: Simplify<TArgs & Simplify<RemoveIndexSignature<DecoratorsArgs<ReactTypes & T, Decorators>>>>;
|
|
183
404
|
}, {
|
|
184
405
|
args: Partial<TArgs> extends TMetaArgs ? {} : TMetaArgs;
|
|
185
406
|
}>;
|
|
186
407
|
}
|
|
187
408
|
type DecoratorsArgs<TRenderer extends Renderer, Decorators> = UnionToIntersection<Decorators extends DecoratorFunction<TRenderer, infer TArgs> ? TArgs : unknown>;
|
|
188
|
-
interface ReactMeta<
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
story<TInput extends StoryAnnotations<
|
|
192
|
-
render: () =>
|
|
193
|
-
}>(story
|
|
194
|
-
|
|
409
|
+
interface ReactMeta<T extends ReactTypes, MetaInput extends ComponentAnnotations<T>>
|
|
410
|
+
/** @ts-expect-error hard */
|
|
411
|
+
extends Meta<T, MetaInput> {
|
|
412
|
+
story<TInput extends (() => ReactTypes['storyResult']) | (StoryAnnotations<T, T['args']> & {
|
|
413
|
+
render: () => ReactTypes['storyResult'];
|
|
414
|
+
})>(story?: TInput): ReactStory<T, TInput extends () => ReactTypes['storyResult'] ? {
|
|
415
|
+
render: TInput;
|
|
416
|
+
} : TInput>;
|
|
417
|
+
story<TInput extends Simplify<StoryAnnotations<T, AddMocks<T['args'], MetaInput['args']>, SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']>>>>(story?: TInput
|
|
418
|
+
/** @ts-expect-error hard */
|
|
419
|
+
): ReactStory<T, TInput>;
|
|
195
420
|
}
|
|
196
|
-
interface ReactStory extends Story<
|
|
421
|
+
interface ReactStory<T extends ReactTypes, TInput extends StoryAnnotations<T, T['args']>> extends Story<T, TInput> {
|
|
422
|
+
Component: ComponentType<Partial<T['args']>>;
|
|
197
423
|
}
|
|
198
424
|
|
|
199
|
-
export { ReactPreview, __definePreview };
|
|
425
|
+
export { type ReactPreview, type ReactStory, __definePreview };
|