storybook-builder-rsbuild 2.1.6 → 3.0.0-beta.1

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.
@@ -1,3067 +1,5 @@
1
- import { FileSystemCache } from 'storybook/internal/common';
2
- import { Server } from 'http';
3
-
4
- declare global {
5
- interface SymbolConstructor {
6
- readonly observable: symbol;
7
- }
8
- }
9
-
10
- /**
11
- @see Simplify
12
- */
13
- interface SimplifyOptions {
14
- /**
15
- Do the simplification recursively.
16
-
17
- @default false
18
- */
19
- deep?: boolean;
20
- }
21
-
22
- // Flatten a type without worrying about the result.
23
- type Flatten<
24
- AnyType,
25
- Options extends SimplifyOptions = {},
26
- > = Options['deep'] extends true
27
- ? {[KeyType in keyof AnyType]: Simplify<AnyType[KeyType], Options>}
28
- : {[KeyType in keyof AnyType]: AnyType[KeyType]};
29
-
30
- /**
31
- 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.
32
-
33
- @example
34
- ```
35
- import type {Simplify} from 'type-fest';
36
-
37
- type PositionProps = {
38
- top: number;
39
- left: number;
40
- };
41
-
42
- type SizeProps = {
43
- width: number;
44
- height: number;
45
- };
46
-
47
- // In your editor, hovering over `Props` will show a flattened object with all the properties.
48
- type Props = Simplify<PositionProps & SizeProps>;
49
- ```
50
-
51
- 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.
52
-
53
- 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`.
54
-
55
- @example
56
- ```
57
- import type {Simplify} from 'type-fest';
58
-
59
- interface SomeInterface {
60
- foo: number;
61
- bar?: string;
62
- baz: number | undefined;
63
- }
64
-
65
- type SomeType = {
66
- foo: number;
67
- bar?: string;
68
- baz: number | undefined;
69
- };
70
-
71
- const literal = {foo: 123, bar: 'hello', baz: 456};
72
- const someType: SomeType = literal;
73
- const someInterface: SomeInterface = literal;
74
-
75
- function fn(object: Record<string, unknown>): void {}
76
-
77
- fn(literal); // Good: literal object type is sealed
78
- fn(someType); // Good: type is sealed
79
- fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
80
- fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
81
- ```
82
-
83
- @link https://github.com/microsoft/TypeScript/issues/15300
84
-
85
- @category Object
86
- */
87
- type Simplify<
88
- AnyType,
89
- Options extends SimplifyOptions = {},
90
- > = Flatten<AnyType> extends AnyType
91
- ? Flatten<AnyType, Options>
92
- : AnyType;
93
-
94
- interface SBBaseType {
95
- required?: boolean;
96
- raw?: string;
97
- }
98
- type SBScalarType = SBBaseType & {
99
- name: 'boolean' | 'string' | 'number' | 'function' | 'symbol';
100
- };
101
- type SBArrayType = SBBaseType & {
102
- name: 'array';
103
- value: SBType;
104
- };
105
- type SBObjectType = SBBaseType & {
106
- name: 'object';
107
- value: Record<string, SBType>;
108
- };
109
- type SBEnumType = SBBaseType & {
110
- name: 'enum';
111
- value: (string | number)[];
112
- };
113
- type SBIntersectionType = SBBaseType & {
114
- name: 'intersection';
115
- value: SBType[];
116
- };
117
- type SBUnionType = SBBaseType & {
118
- name: 'union';
119
- value: SBType[];
120
- };
121
- type SBOtherType = SBBaseType & {
122
- name: 'other';
123
- value: string;
124
- };
125
- type SBType = SBScalarType | SBEnumType | SBArrayType | SBObjectType | SBIntersectionType | SBUnionType | SBOtherType;
126
-
127
- interface ActionsParameters {
128
- /**
129
- * Actions configuration
130
- *
131
- * @see https://storybook.js.org/docs/essentials/actions#parameters
132
- */
133
- actions?: {
134
- /**
135
- * Create actions for each arg that matches the regex. (**NOT recommended, see below**)
136
- *
137
- * This is quite useful when your component has dozens (or hundreds) of methods and you do not
138
- * want to manually apply the fn utility for each of those methods. However, this is not the
139
- * recommended way of writing actions. That's because automatically inferred args are not
140
- * available as spies in your play function. If you use argTypesRegex and your stories have play
141
- * functions, you will need to also define args with the fn utility to test them in your play
142
- * function.
143
- *
144
- * @example `argTypesRegex: '^on.*'`
145
- */
146
- argTypesRegex?: string;
147
- /** Remove the addon panel and disable the addon's behavior */
148
- disable?: boolean;
149
- /**
150
- * Binds a standard HTML event handler to the outermost HTML element rendered by your component
151
- * and triggers an action when the event is called for a given selector. The format is
152
- * `<eventname> <selector>`. The selector is optional; it defaults to all elements.
153
- *
154
- * **To enable this feature, you must use the `withActions` decorator.**
155
- *
156
- * @example `handles: ['mouseover', 'click .btn']`
157
- *
158
- * @see https://storybook.js.org/docs/essentials/actions#action-event-handlers
159
- */
160
- handles?: string[];
161
- };
162
- }
163
- interface ActionsTypes {
164
- parameters: ActionsParameters;
165
- }
166
-
167
- declare const PARAM_KEY = "backgrounds";
168
-
169
- interface Background {
170
- name: string;
171
- value: string;
172
- }
173
- type BackgroundMap = Record<string, Background>;
174
- interface GridConfig {
175
- cellAmount: number;
176
- cellSize: number;
177
- opacity: number;
178
- offsetX?: number;
179
- offsetY?: number;
180
- }
181
- type GlobalState$1 = {
182
- value: string | undefined;
183
- grid?: boolean;
184
- };
185
- interface BackgroundsParameters {
186
- /**
187
- * Backgrounds configuration
188
- *
189
- * @see https://storybook.js.org/docs/essentials/backgrounds#parameters
190
- */
191
- backgrounds?: {
192
- /** Default background color */
193
- default?: string;
194
- /** Remove the addon panel and disable the addon's behavior */
195
- disable?: boolean;
196
- /** Configuration for the background grid */
197
- grid?: GridConfig;
198
- /** Available background colors */
199
- options?: BackgroundMap;
200
- };
201
- }
202
- interface BackgroundsGlobals {
203
- /**
204
- * Backgrounds configuration
205
- *
206
- * @see https://storybook.js.org/docs/essentials/backgrounds#globals
207
- */
208
- [PARAM_KEY]?: GlobalState$1 | GlobalState$1['value'];
209
- }
210
- interface BackgroundTypes {
211
- parameters: BackgroundsParameters;
212
- globals: BackgroundsGlobals;
213
- }
214
-
215
- interface ControlsParameters {
216
- /**
217
- * Controls configuration
218
- *
219
- * @see https://storybook.js.org/docs/essentials/controls#parameters-1
220
- */
221
- controls?: {
222
- /** Remove the addon panel and disable the addon's behavior */
223
- disable?: boolean;
224
- /** Disable the ability to create or edit stories from the Controls panel */
225
- disableSaveFromUI?: boolean;
226
- /** Exclude specific properties from the Controls panel */
227
- exclude?: string[] | RegExp;
228
- /**
229
- * Show the full documentation for each property in the Controls addon panel, including the
230
- * description and default value.
231
- */
232
- expanded?: boolean;
233
- /** Exclude only specific properties in the Controls panel */
234
- include?: string[] | RegExp;
235
- /**
236
- * Custom control type matchers
237
- *
238
- * @see https://storybook.js.org/docs/essentials/controls#custom-control-type-matchers
239
- */
240
- matchers?: {
241
- date?: RegExp;
242
- color?: RegExp;
243
- };
244
- /**
245
- * Preset color swatches for the color picker control
246
- *
247
- * @example PresetColors: [{ color: '#ff4785', title: 'Coral' }, 'rgba(0, 159, 183, 1)',
248
- * '#fe4a49']
249
- */
250
- presetColors?: Array<string | {
251
- color: string;
252
- title?: string;
253
- }>;
254
- /** Controls sorting order */
255
- sort?: 'none' | 'alpha' | 'requiredFirst';
256
- };
257
- }
258
- interface ControlsTypes {
259
- parameters: ControlsParameters;
260
- }
261
-
262
- interface HighlightTypes {
263
- parameters: HighlightParameters;
264
- }
265
- interface HighlightParameters {
266
- /**
267
- * Highlight configuration
268
- *
269
- * @see https://storybook.js.org/docs/essentials/highlight#parameters
270
- */
271
- highlight?: {
272
- /** Remove the addon panel and disable the addon's behavior */
273
- disable?: boolean;
274
- };
275
- }
276
-
277
- interface MeasureParameters {
278
- /**
279
- * Measure configuration
280
- *
281
- * @see https://storybook.js.org/docs/essentials/measure-and-outline#parameters
282
- */
283
- measure?: {
284
- /** Remove the addon panel and disable the addon's behavior */
285
- disable?: boolean;
286
- };
287
- }
288
- interface MeasureTypes {
289
- parameters: MeasureParameters;
290
- }
291
-
292
- interface OutlineParameters {
293
- /**
294
- * Outline configuration
295
- *
296
- * @see https://storybook.js.org/docs/essentials/measure-and-outline#parameters
297
- */
298
- outline?: {
299
- /** Remove the addon panel and disable the addon's behavior */
300
- disable?: boolean;
301
- };
302
- }
303
- interface OutlineTypes {
304
- parameters: OutlineParameters;
305
- }
306
-
307
- interface TestParameters {
308
- test?: {
309
- /** Ignore unhandled errors during test execution */
310
- dangerouslyIgnoreUnhandledErrors?: boolean;
311
- /** Whether to throw exceptions coming from the play function */
312
- throwPlayFunctionExceptions?: boolean;
313
- };
314
- }
315
- interface TestTypes {
316
- parameters: TestParameters;
317
- }
318
-
319
- interface Viewport {
320
- name: string;
321
- styles: ViewportStyles;
322
- type?: 'desktop' | 'mobile' | 'tablet' | 'other';
323
- }
324
- interface ViewportStyles {
325
- height: string;
326
- width: string;
327
- }
328
- type GlobalState = {
329
- /**
330
- * When set, the viewport is applied and cannot be changed using the toolbar. Must match the key
331
- * of one of the available viewports.
332
- */
333
- value: string | undefined;
334
- /**
335
- * When true the viewport applied will be rotated 90°, e.g. it will rotate from portrait to
336
- * landscape orientation.
337
- */
338
- isRotated?: boolean;
339
- };
340
- interface ViewportParameters {
341
- /**
342
- * Viewport configuration
343
- *
344
- * @see https://storybook.js.org/docs/essentials/viewport#parameters
345
- */
346
- viewport?: {
347
- /**
348
- * Remove the addon panel and disable the addon's behavior . If you wish to turn off this addon
349
- * for the entire Storybook, you should do so when registering addon-essentials
350
- *
351
- * @see https://storybook.js.org/docs/essentials/index#disabling-addons
352
- */
353
- disable?: boolean;
354
- /**
355
- * Specify the available viewports. The width and height values must include the unit, e.g.
356
- * '320px'.
357
- */
358
- options: Record<string, Viewport>;
359
- };
360
- }
361
- interface ViewportGlobals {
362
- /**
363
- * Viewport configuration
364
- *
365
- * @see https://storybook.js.org/docs/essentials/viewport#globals
366
- */
367
- viewport?: GlobalState | GlobalState['value'];
368
- }
369
- interface ViewportTypes {
370
- parameters: ViewportParameters;
371
- globals: ViewportGlobals;
372
- }
373
-
374
- type CoreTypes = StorybookTypes & ActionsTypes & BackgroundTypes & ControlsTypes & HighlightTypes & MeasureTypes & OutlineTypes & TestTypes & ViewportTypes;
375
-
376
- type StoryId = string;
377
- type ComponentId = string;
378
- type ComponentTitle = string;
379
- type StoryName = string;
380
- type Tag$1 = string;
381
- interface StoryIdentifier {
382
- componentId: ComponentId;
383
- title: ComponentTitle;
384
- /** @deprecated */
385
- kind: ComponentTitle;
386
- id: StoryId;
387
- name: StoryName;
388
- /** @deprecated */
389
- story: StoryName;
390
- tags: Tag$1[];
391
- }
392
- interface Parameters {
393
- [name: string]: any;
394
- }
395
- type ControlType = 'object' | 'boolean' | 'check' | 'inline-check' | 'radio' | 'inline-radio' | 'select' | 'multi-select' | 'number' | 'range' | 'file' | 'color' | 'date' | 'text';
396
- type ConditionalTest = {
397
- truthy?: boolean;
398
- } | {
399
- exists: boolean;
400
- } | {
401
- eq: any;
402
- } | {
403
- neq: any;
404
- };
405
- type ConditionalValue = {
406
- arg: string;
407
- } | {
408
- global: string;
409
- };
410
- type Conditional = ConditionalValue & ConditionalTest;
411
- interface ControlBase {
412
- [key: string]: any;
413
- /** @see https://storybook.js.org/docs/api/arg-types#controltype */
414
- type?: ControlType;
415
- disable?: boolean;
416
- }
417
- interface Report$1 {
418
- type: string;
419
- version?: number;
420
- result: unknown;
421
- status: 'failed' | 'passed' | 'warning';
422
- }
423
- interface ReportingAPI {
424
- reports: Report$1[];
425
- addReport: (report: Report$1) => void;
426
- }
427
- type Control = ControlType | false | (ControlBase & (ControlBase | {
428
- type: 'color';
429
- /** @see https://storybook.js.org/docs/api/arg-types#controlpresetcolors */
430
- presetColors?: string[];
431
- } | {
432
- type: 'file';
433
- /** @see https://storybook.js.org/docs/api/arg-types#controlaccept */
434
- accept?: string;
435
- } | {
436
- type: 'inline-check' | 'radio' | 'inline-radio' | 'select' | 'multi-select';
437
- /** @see https://storybook.js.org/docs/api/arg-types#controllabels */
438
- labels?: {
439
- [options: string]: string;
440
- };
441
- } | {
442
- type: 'number' | 'range';
443
- /** @see https://storybook.js.org/docs/api/arg-types#controlmax */
444
- max?: number;
445
- /** @see https://storybook.js.org/docs/api/arg-types#controlmin */
446
- min?: number;
447
- /** @see https://storybook.js.org/docs/api/arg-types#controlstep */
448
- step?: number;
449
- }));
450
- interface InputType {
451
- /** @see https://storybook.js.org/docs/api/arg-types#control */
452
- control?: Control;
453
- /** @see https://storybook.js.org/docs/api/arg-types#description */
454
- description?: string;
455
- /** @see https://storybook.js.org/docs/api/arg-types#if */
456
- if?: Conditional;
457
- /** @see https://storybook.js.org/docs/api/arg-types#mapping */
458
- mapping?: {
459
- [key: string]: any;
460
- };
461
- /** @see https://storybook.js.org/docs/api/arg-types#name */
462
- name?: string;
463
- /** @see https://storybook.js.org/docs/api/arg-types#options */
464
- options?: readonly any[];
465
- /** @see https://storybook.js.org/docs/api/arg-types#table */
466
- table?: {
467
- [key: string]: unknown;
468
- /** @see https://storybook.js.org/docs/api/arg-types#tablecategory */
469
- category?: string;
470
- /** @see https://storybook.js.org/docs/api/arg-types#tabledefaultvalue */
471
- defaultValue?: {
472
- summary?: string;
473
- detail?: string;
474
- };
475
- /** @see https://storybook.js.org/docs/api/arg-types#tabledisable */
476
- disable?: boolean;
477
- /** @see https://storybook.js.org/docs/api/arg-types#tablesubcategory */
478
- subcategory?: string;
479
- /** @see https://storybook.js.org/docs/api/arg-types#tabletype */
480
- type?: {
481
- summary?: string;
482
- detail?: string;
483
- };
484
- };
485
- /** @see https://storybook.js.org/docs/api/arg-types#type */
486
- type?: SBType | SBScalarType['name'];
487
- /**
488
- * @deprecated Use `table.defaultValue.summary` instead.
489
- * @see https://storybook.js.org/docs/api/arg-types#defaultvalue
490
- */
491
- defaultValue?: any;
492
- [key: string]: any;
493
- }
494
- interface StrictInputType extends InputType {
495
- name: string;
496
- type?: SBType;
497
- }
498
- interface Args {
499
- [name: string]: any;
500
- }
501
- /** @see https://storybook.js.org/docs/api/arg-types#argtypes */
502
- type ArgTypes<TArgs = Args> = {
503
- [name in keyof TArgs]: InputType;
504
- };
505
- type StrictArgTypes<TArgs = Args> = {
506
- [name in keyof TArgs]: StrictInputType;
507
- };
508
- interface Globals {
509
- [name: string]: any;
510
- }
511
- interface GlobalTypes {
512
- [name: string]: InputType;
513
- }
514
- interface StrictGlobalTypes {
515
- [name: string]: StrictInputType;
516
- }
517
- interface AddonTypes {
518
- parameters?: Record<string, any>;
519
- globals?: Record<string, any>;
520
- }
521
- interface Renderer extends AddonTypes {
522
- /** What is the type of the `component` annotation in this renderer? */
523
- component: any;
524
- /** What does the story function return in this renderer? */
525
- storyResult: any;
526
- /** What type of element does this renderer render to? */
527
- canvasElement: any;
528
- mount(): Promise<Canvas>;
529
- T?: unknown;
530
- args: unknown;
531
- csf4: boolean;
532
- }
533
- interface StoryContextForEnhancers<TRenderer extends Renderer = Renderer, TArgs = Args> extends StoryIdentifier {
534
- component?: (TRenderer & {
535
- T: any;
536
- })['component'];
537
- subcomponents?: Record<string, (TRenderer & {
538
- T: any;
539
- })['component']>;
540
- parameters: Parameters;
541
- initialArgs: TArgs;
542
- argTypes: StrictArgTypes<TArgs>;
543
- }
544
- type ArgsEnhancer<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContextForEnhancers<TRenderer, TArgs>) => TArgs;
545
- type ArgTypesEnhancer<TRenderer extends Renderer = Renderer, TArgs = Args> = ((context: StoryContextForEnhancers<TRenderer, TArgs>) => StrictArgTypes<TArgs>) & {
546
- secondPass?: boolean;
547
- };
548
- interface StoryContextUpdate<TArgs = Args> {
549
- args?: TArgs;
550
- globals?: Globals;
551
- [key: string]: any;
552
- }
553
- type ViewMode = 'story' | 'docs';
554
- type LoaderFunction$2<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContextForLoaders<TRenderer, TArgs>) => Promise<Record<string, any> | void> | Record<string, any> | void;
555
- type Awaitable<T> = T | PromiseLike<T>;
556
- type CleanupCallback = () => Awaitable<unknown>;
557
- type BeforeAll = () => Awaitable<CleanupCallback | void>;
558
- type BeforeEach<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContext<TRenderer, TArgs>) => Awaitable<CleanupCallback | void>;
559
- type AfterEach<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContext<TRenderer, TArgs>) => Awaitable<void>;
560
- interface Canvas {
561
- }
562
- interface StoryContext<TRenderer extends Renderer = Renderer, TArgs = Args> extends StoryContextForEnhancers<TRenderer, TArgs>, Required<StoryContextUpdate<TArgs>> {
563
- loaded: Record<string, any>;
564
- abortSignal: AbortSignal;
565
- canvasElement: TRenderer['canvasElement'];
566
- hooks: unknown;
567
- originalStoryFn: ArgsStoryFn<TRenderer>;
568
- viewMode: ViewMode;
569
- step: StepFunction<TRenderer, TArgs>;
570
- context: this;
571
- canvas: Canvas;
572
- mount: TRenderer['mount'];
573
- reporting: ReportingAPI;
574
- }
575
- /** @deprecated Use {@link StoryContext} instead. */
576
- interface StoryContextForLoaders<TRenderer extends Renderer = Renderer, TArgs = Args> extends StoryContext<TRenderer, TArgs> {
577
- }
578
- /** @deprecated Use {@link StoryContext} instead. */
579
- interface PlayFunctionContext<TRenderer extends Renderer = Renderer, TArgs = Args> extends StoryContext<TRenderer, TArgs> {
580
- }
581
- type StepLabel = string;
582
- type StepFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (label: StepLabel, play: PlayFunction<TRenderer, TArgs>) => Promise<void> | void;
583
- type PlayFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: PlayFunctionContext<TRenderer, TArgs>) => Promise<void> | void;
584
- type PartialStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (update?: StoryContextUpdate<Partial<TArgs>>) => TRenderer['storyResult'];
585
- type LegacyStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContext<TRenderer, TArgs>) => TRenderer['storyResult'];
586
- type ArgsStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (args: TArgs, context: StoryContext<TRenderer, TArgs>) => (TRenderer & {
587
- T: TArgs;
588
- })['storyResult'];
589
- type DecoratorFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (fn: PartialStoryFn<TRenderer, TArgs>, c: StoryContext<TRenderer, TArgs>) => TRenderer['storyResult'];
590
- type DecoratorApplicator<TRenderer extends Renderer = Renderer, TArgs = Args> = (storyFn: LegacyStoryFn<TRenderer, TArgs>, decorators: DecoratorFunction<TRenderer, TArgs>[]) => LegacyStoryFn<TRenderer, TArgs>;
591
- type StepRunner<TRenderer extends Renderer = Renderer, TArgs = Args> = (label: StepLabel, play: PlayFunction<TRenderer, TArgs>, context: StoryContext<TRenderer, TArgs>) => Promise<void>;
592
- interface BaseAnnotations<TRenderer extends Renderer = Renderer, TArgs = Args> {
593
- /**
594
- * Wrapper components or Storybook decorators that wrap a story.
595
- *
596
- * Decorators defined in Meta will be applied to every story variation.
597
- *
598
- * @see [Decorators](https://storybook.js.org/docs/writing-stories/decorators)
599
- */
600
- decorators?: DecoratorFunction<TRenderer, Simplify<TArgs>>[] | DecoratorFunction<TRenderer, Simplify<TArgs>>;
601
- /**
602
- * Custom metadata for a story.
603
- *
604
- * @see [Parameters](https://storybook.js.org/docs/writing-stories/parameters)
605
- */
606
- parameters?: Parameters & (TRenderer['csf4'] extends true ? CoreTypes['parameters'] & TRenderer['parameters'] : unknown);
607
- /**
608
- * Dynamic data that are provided (and possibly updated by) Storybook and its addons.
609
- *
610
- * @see [Args](https://storybook.js.org/docs/writing-stories/args)
611
- */
612
- args?: Partial<TArgs>;
613
- /**
614
- * ArgTypes encode basic metadata for args, such as `name`, `description`, `defaultValue` for an
615
- * arg. These get automatically filled in by Storybook Docs.
616
- *
617
- * @see [ArgTypes](https://storybook.js.org/docs/api/arg-types)
618
- */
619
- argTypes?: Partial<ArgTypes<TArgs>>;
620
- /**
621
- * Asynchronous functions which provide data for a story.
622
- *
623
- * @see [Loaders](https://storybook.js.org/docs/writing-stories/loaders)
624
- */
625
- loaders?: LoaderFunction$2<TRenderer, TArgs>[] | LoaderFunction$2<TRenderer, TArgs>;
626
- /**
627
- * Function to be called before each story. When the function is async, it will be awaited.
628
- *
629
- * `beforeEach` can be added to preview, the default export and to a specific story. They are run
630
- * (and awaited) in the order: preview, default export, story
631
- *
632
- * A cleanup function can be returned.
633
- */
634
- beforeEach?: BeforeEach<TRenderer, TArgs>[] | BeforeEach<TRenderer, TArgs>;
635
- /**
636
- * Function to be called after each play function for post-test assertions. Don't use this
637
- * function for cleaning up state. You can use the return callback of `beforeEach` for that, which
638
- * is run when switching stories. When the function is async, it will be awaited.
639
- *
640
- * `afterEach` can be added to preview, the default export and to a specific story. They are run
641
- * (and awaited) reverse order: preview, default export, story
642
- */
643
- afterEach?: AfterEach<TRenderer, TArgs>[] | AfterEach<TRenderer, TArgs>;
644
- /**
645
- * Define a custom render function for the story(ies). If not passed, a default render function by
646
- * the renderer will be used.
647
- */
648
- render?: ArgsStoryFn<TRenderer, TArgs>;
649
- /** Named tags for a story, used to filter stories in different contexts. */
650
- tags?: Tag$1[];
651
- mount?: (context: StoryContext<TRenderer, TArgs>) => TRenderer['mount'];
652
- }
653
- interface ProjectAnnotations$1<TRenderer extends Renderer = Renderer, TArgs = Args> extends BaseAnnotations<TRenderer, TArgs> {
654
- argsEnhancers?: ArgsEnhancer<TRenderer, Args>[];
655
- argTypesEnhancers?: ArgTypesEnhancer<TRenderer, Args>[];
656
- /**
657
- * Lifecycle hook which runs once, before any loaders, decorators or stories, and may rerun when
658
- * configuration changes or when reinitializing (e.g. between test runs). The function may be
659
- * synchronous or asynchronous, and may return a cleanup function which may also be synchronous or
660
- * asynchronous. The cleanup function is not guaranteed to run (e.g. when the browser closes), but
661
- * runs when configuration changes or when reinitializing. This hook may only be defined globally
662
- * (i.e. not on component or story level). When multiple hooks are specified, they are to be
663
- * executed sequentially (and awaited) in the following order:
664
- *
665
- * - Addon hooks (in order of addons array in e.g. .storybook/main.js)
666
- * - Annotation hooks (in order of previewAnnotations array in e.g. .storybook/main.js)
667
- * - Preview hook (via e.g. .storybook/preview.js) Cleanup functions are executed sequentially in
668
- * reverse order of initialization.
669
- */
670
- beforeAll?: BeforeAll;
671
- initialGlobals?: Globals & (TRenderer['csf4'] extends true ? CoreTypes['globals'] & TRenderer['globals'] : unknown);
672
- globalTypes?: GlobalTypes;
673
- applyDecorators?: DecoratorApplicator<TRenderer, Args>;
674
- runStep?: StepRunner<TRenderer, TArgs>;
675
- }
676
-
677
- /**
678
- * Actions represent the type of change to a location value.
679
- */
680
- declare enum Action$1 {
681
- /**
682
- * A POP indicates a change to an arbitrary index in the history stack, such
683
- * as a back or forward navigation. It does not describe the direction of the
684
- * navigation, only that the current index changed.
685
- *
686
- * Note: This is the default action for newly created history objects.
687
- */
688
- Pop = "POP",
689
- /**
690
- * A PUSH indicates a new entry being added to the history stack, such as when
691
- * a link is clicked and a new page loads. When this happens, all subsequent
692
- * entries in the stack are lost.
693
- */
694
- Push = "PUSH",
695
- /**
696
- * A REPLACE indicates the entry at the current index in the history stack
697
- * being replaced by a new one.
698
- */
699
- Replace = "REPLACE"
700
- }
701
- /**
702
- * The pathname, search, and hash values of a URL.
703
- */
704
- interface Path$2 {
705
- /**
706
- * A URL pathname, beginning with a /.
707
- */
708
- pathname: string;
709
- /**
710
- * A URL search string, beginning with a ?.
711
- */
712
- search: string;
713
- /**
714
- * A URL fragment identifier, beginning with a #.
715
- */
716
- hash: string;
717
- }
718
- /**
719
- * An entry in a history stack. A location contains information about the
720
- * URL path, as well as possibly some arbitrary state and a key.
721
- */
722
- interface Location$2 extends Path$2 {
723
- /**
724
- * A value of arbitrary data associated with this location.
725
- */
726
- state: any;
727
- /**
728
- * A unique string associated with this location. May be used to safely store
729
- * and retrieve data in some other storage API, like `localStorage`.
730
- *
731
- * Note: This value is always "default" on the initial location.
732
- */
733
- key: string;
734
- }
735
-
736
- /**
737
- * Map of routeId -> data returned from a loader/action/error
738
- */
739
- interface RouteData$1 {
740
- [routeId: string]: any;
741
- }
742
- declare enum ResultType$1 {
743
- data = "data",
744
- deferred = "deferred",
745
- redirect = "redirect",
746
- error = "error"
747
- }
748
- /**
749
- * Successful result from a loader or action
750
- */
751
- interface SuccessResult$1 {
752
- type: ResultType$1.data;
753
- data: any;
754
- statusCode?: number;
755
- headers?: Headers;
756
- }
757
- /**
758
- * Successful defer() result from a loader or action
759
- */
760
- interface DeferredResult$1 {
761
- type: ResultType$1.deferred;
762
- deferredData: DeferredData$1;
763
- statusCode?: number;
764
- headers?: Headers;
765
- }
766
- /**
767
- * Redirect result from a loader or action
768
- */
769
- interface RedirectResult$1 {
770
- type: ResultType$1.redirect;
771
- status: number;
772
- location: string;
773
- revalidate: boolean;
774
- reloadDocument?: boolean;
775
- }
776
- /**
777
- * Unsuccessful result from a loader or action
778
- */
779
- interface ErrorResult$1 {
780
- type: ResultType$1.error;
781
- error: any;
782
- headers?: Headers;
783
- }
784
- /**
785
- * Result from a loader or action - potentially successful or unsuccessful
786
- */
787
- type DataResult$1 = SuccessResult$1 | DeferredResult$1 | RedirectResult$1 | ErrorResult$1;
788
- type LowerCaseFormMethod$1 = "get" | "post" | "put" | "patch" | "delete";
789
- type UpperCaseFormMethod$1 = Uppercase<LowerCaseFormMethod$1>;
790
- /**
791
- * Active navigation/fetcher form methods are exposed in lowercase on the
792
- * RouterState
793
- */
794
- type FormMethod$1 = LowerCaseFormMethod$1;
795
- /**
796
- * In v7, active navigation/fetcher form methods are exposed in uppercase on the
797
- * RouterState. This is to align with the normalization done via fetch().
798
- */
799
- type V7_FormMethod$1 = UpperCaseFormMethod$1;
800
- type FormEncType$1 = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
801
- type JsonObject$1 = {
802
- [Key in string]: JsonValue$1;
803
- } & {
804
- [Key in string]?: JsonValue$1 | undefined;
805
- };
806
- type JsonArray$1 = JsonValue$1[] | readonly JsonValue$1[];
807
- type JsonPrimitive$1 = string | number | boolean | null;
808
- type JsonValue$1 = JsonPrimitive$1 | JsonObject$1 | JsonArray$1;
809
- /**
810
- * @private
811
- * Internal interface to pass around for action submissions, not intended for
812
- * external consumption
813
- */
814
- type Submission$1 = {
815
- formMethod: FormMethod$1 | V7_FormMethod$1;
816
- formAction: string;
817
- formEncType: FormEncType$1;
818
- formData: FormData;
819
- json: undefined;
820
- text: undefined;
821
- } | {
822
- formMethod: FormMethod$1 | V7_FormMethod$1;
823
- formAction: string;
824
- formEncType: FormEncType$1;
825
- formData: undefined;
826
- json: JsonValue$1;
827
- text: undefined;
828
- } | {
829
- formMethod: FormMethod$1 | V7_FormMethod$1;
830
- formAction: string;
831
- formEncType: FormEncType$1;
832
- formData: undefined;
833
- json: undefined;
834
- text: string;
835
- };
836
- /**
837
- * @private
838
- * Arguments passed to route loader/action functions. Same for now but we keep
839
- * this as a private implementation detail in case they diverge in the future.
840
- */
841
- interface DataFunctionArgs$1 {
842
- request: Request;
843
- params: Params$1;
844
- context?: any;
845
- }
846
- /**
847
- * Arguments passed to loader functions
848
- */
849
- interface LoaderFunctionArgs$1 extends DataFunctionArgs$1 {
850
- }
851
- /**
852
- * Arguments passed to action functions
853
- */
854
- interface ActionFunctionArgs$1 extends DataFunctionArgs$1 {
855
- }
856
- /**
857
- * Loaders and actions can return anything except `undefined` (`null` is a
858
- * valid return value if there is no data to return). Responses are preferred
859
- * and will ease any future migration to Remix
860
- */
861
- type DataFunctionValue$1 = Response | NonNullable<unknown> | null;
862
- /**
863
- * Route loader function signature
864
- */
865
- interface LoaderFunction$1 {
866
- (args: LoaderFunctionArgs$1): Promise<DataFunctionValue$1> | DataFunctionValue$1;
867
- }
868
- /**
869
- * Route action function signature
870
- */
871
- interface ActionFunction$1 {
872
- (args: ActionFunctionArgs$1): Promise<DataFunctionValue$1> | DataFunctionValue$1;
873
- }
874
- /**
875
- * Route shouldRevalidate function signature. This runs after any submission
876
- * (navigation or fetcher), so we flatten the navigation/fetcher submission
877
- * onto the arguments. It shouldn't matter whether it came from a navigation
878
- * or a fetcher, what really matters is the URLs and the formData since loaders
879
- * have to re-run based on the data models that were potentially mutated.
880
- */
881
- interface ShouldRevalidateFunction$1 {
882
- (args: {
883
- currentUrl: URL;
884
- currentParams: AgnosticDataRouteMatch$1["params"];
885
- nextUrl: URL;
886
- nextParams: AgnosticDataRouteMatch$1["params"];
887
- formMethod?: Submission$1["formMethod"];
888
- formAction?: Submission$1["formAction"];
889
- formEncType?: Submission$1["formEncType"];
890
- text?: Submission$1["text"];
891
- formData?: Submission$1["formData"];
892
- json?: Submission$1["json"];
893
- actionResult?: DataResult$1;
894
- defaultShouldRevalidate: boolean;
895
- }): boolean;
896
- }
897
- /**
898
- * Keys we cannot change from within a lazy() function. We spread all other keys
899
- * onto the route. Either they're meaningful to the router, or they'll get
900
- * ignored.
901
- */
902
- type ImmutableRouteKey$1 = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
903
- type RequireOne$1<T, Key = keyof T> = Exclude<{
904
- [K in keyof T]: K extends Key ? Omit<T, K> & Required<Pick<T, K>> : never;
905
- }[keyof T], undefined>;
906
- /**
907
- * lazy() function to load a route definition, which can add non-matching
908
- * related properties to a route
909
- */
910
- interface LazyRouteFunction$1<R extends AgnosticRouteObject$1> {
911
- (): Promise<RequireOne$1<Omit<R, ImmutableRouteKey$1>>>;
912
- }
913
- /**
914
- * Base RouteObject with common props shared by all types of routes
915
- */
916
- type AgnosticBaseRouteObject$1 = {
917
- caseSensitive?: boolean;
918
- path?: string;
919
- id?: string;
920
- loader?: LoaderFunction$1;
921
- action?: ActionFunction$1;
922
- hasErrorBoundary?: boolean;
923
- shouldRevalidate?: ShouldRevalidateFunction$1;
924
- handle?: any;
925
- lazy?: LazyRouteFunction$1<AgnosticBaseRouteObject$1>;
926
- };
927
- /**
928
- * Index routes must not have children
929
- */
930
- type AgnosticIndexRouteObject$1 = AgnosticBaseRouteObject$1 & {
931
- children?: undefined;
932
- index: true;
933
- };
934
- /**
935
- * Non-index routes may have children, but cannot have index
936
- */
937
- type AgnosticNonIndexRouteObject$1 = AgnosticBaseRouteObject$1 & {
938
- children?: AgnosticRouteObject$1[];
939
- index?: false;
940
- };
941
- /**
942
- * A route object represents a logical route, with (optionally) its child
943
- * routes organized in a tree-like structure.
944
- */
945
- type AgnosticRouteObject$1 = AgnosticIndexRouteObject$1 | AgnosticNonIndexRouteObject$1;
946
- type AgnosticDataIndexRouteObject$1 = AgnosticIndexRouteObject$1 & {
947
- id: string;
948
- };
949
- type AgnosticDataNonIndexRouteObject$1 = AgnosticNonIndexRouteObject$1 & {
950
- children?: AgnosticDataRouteObject$1[];
951
- id: string;
952
- };
953
- /**
954
- * A data route object, which is just a RouteObject with a required unique ID
955
- */
956
- type AgnosticDataRouteObject$1 = AgnosticDataIndexRouteObject$1 | AgnosticDataNonIndexRouteObject$1;
957
- /**
958
- * The parameters that were parsed from the URL path.
959
- */
960
- type Params$1<Key extends string = string> = {
961
- readonly [key in Key]: string | undefined;
962
- };
963
- /**
964
- * A RouteMatch contains info about how a route matched a URL.
965
- */
966
- interface AgnosticRouteMatch$1<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject$1 = AgnosticRouteObject$1> {
967
- /**
968
- * The names and values of dynamic parameters in the URL.
969
- */
970
- params: Params$1<ParamKey>;
971
- /**
972
- * The portion of the URL pathname that was matched.
973
- */
974
- pathname: string;
975
- /**
976
- * The portion of the URL pathname that was matched before child routes.
977
- */
978
- pathnameBase: string;
979
- /**
980
- * The route object that was used to match.
981
- */
982
- route: RouteObjectType;
983
- }
984
- interface AgnosticDataRouteMatch$1 extends AgnosticRouteMatch$1<string, AgnosticDataRouteObject$1> {
985
- }
986
- declare class DeferredData$1 {
987
- private pendingKeysSet;
988
- private controller;
989
- private abortPromise;
990
- private unlistenAbortSignal;
991
- private subscribers;
992
- data: Record<string, unknown>;
993
- init?: ResponseInit;
994
- deferredKeys: string[];
995
- constructor(data: Record<string, unknown>, responseInit?: ResponseInit);
996
- private trackPromise;
997
- private onSettle;
998
- private emit;
999
- subscribe(fn: (aborted: boolean, settledKey?: string) => void): () => boolean;
1000
- cancel(): void;
1001
- resolveData(signal: AbortSignal): Promise<boolean>;
1002
- get done(): boolean;
1003
- get unwrappedData(): {};
1004
- get pendingKeys(): string[];
1005
- }
1006
-
1007
- /**
1008
- * State maintained internally by the router. During a navigation, all states
1009
- * reflect the the "old" location unless otherwise noted.
1010
- */
1011
- interface RouterState$1 {
1012
- /**
1013
- * The action of the most recent navigation
1014
- */
1015
- historyAction: Action$1;
1016
- /**
1017
- * The current location reflected by the router
1018
- */
1019
- location: Location$2;
1020
- /**
1021
- * The current set of route matches
1022
- */
1023
- matches: AgnosticDataRouteMatch$1[];
1024
- /**
1025
- * Tracks whether we've completed our initial data load
1026
- */
1027
- initialized: boolean;
1028
- /**
1029
- * Current scroll position we should start at for a new view
1030
- * - number -> scroll position to restore to
1031
- * - false -> do not restore scroll at all (used during submissions)
1032
- * - null -> don't have a saved position, scroll to hash or top of page
1033
- */
1034
- restoreScrollPosition: number | false | null;
1035
- /**
1036
- * Indicate whether this navigation should skip resetting the scroll position
1037
- * if we are unable to restore the scroll position
1038
- */
1039
- preventScrollReset: boolean;
1040
- /**
1041
- * Tracks the state of the current navigation
1042
- */
1043
- navigation: Navigation$1;
1044
- /**
1045
- * Tracks any in-progress revalidations
1046
- */
1047
- revalidation: RevalidationState$1;
1048
- /**
1049
- * Data from the loaders for the current matches
1050
- */
1051
- loaderData: RouteData$1;
1052
- /**
1053
- * Data from the action for the current matches
1054
- */
1055
- actionData: RouteData$1 | null;
1056
- /**
1057
- * Errors caught from loaders for the current matches
1058
- */
1059
- errors: RouteData$1 | null;
1060
- /**
1061
- * Map of current fetchers
1062
- */
1063
- fetchers: Map<string, Fetcher$1>;
1064
- /**
1065
- * Map of current blockers
1066
- */
1067
- blockers: Map<string, Blocker$1>;
1068
- }
1069
- /**
1070
- * Data that can be passed into hydrate a Router from SSR
1071
- */
1072
- type HydrationState$1 = Partial<Pick<RouterState$1, "loaderData" | "actionData" | "errors">>;
1073
- /**
1074
- * Potential states for state.navigation
1075
- */
1076
- type NavigationStates$1 = {
1077
- Idle: {
1078
- state: "idle";
1079
- location: undefined;
1080
- formMethod: undefined;
1081
- formAction: undefined;
1082
- formEncType: undefined;
1083
- formData: undefined;
1084
- json: undefined;
1085
- text: undefined;
1086
- };
1087
- Loading: {
1088
- state: "loading";
1089
- location: Location$2;
1090
- formMethod: Submission$1["formMethod"] | undefined;
1091
- formAction: Submission$1["formAction"] | undefined;
1092
- formEncType: Submission$1["formEncType"] | undefined;
1093
- formData: Submission$1["formData"] | undefined;
1094
- json: Submission$1["json"] | undefined;
1095
- text: Submission$1["text"] | undefined;
1096
- };
1097
- Submitting: {
1098
- state: "submitting";
1099
- location: Location$2;
1100
- formMethod: Submission$1["formMethod"];
1101
- formAction: Submission$1["formAction"];
1102
- formEncType: Submission$1["formEncType"];
1103
- formData: Submission$1["formData"];
1104
- json: Submission$1["json"];
1105
- text: Submission$1["text"];
1106
- };
1107
- };
1108
- type Navigation$1 = NavigationStates$1[keyof NavigationStates$1];
1109
- type RevalidationState$1 = "idle" | "loading";
1110
- /**
1111
- * Potential states for fetchers
1112
- */
1113
- type FetcherStates$1<TData = any> = {
1114
- Idle: {
1115
- state: "idle";
1116
- formMethod: undefined;
1117
- formAction: undefined;
1118
- formEncType: undefined;
1119
- text: undefined;
1120
- formData: undefined;
1121
- json: undefined;
1122
- data: TData | undefined;
1123
- " _hasFetcherDoneAnything "?: boolean;
1124
- };
1125
- Loading: {
1126
- state: "loading";
1127
- formMethod: Submission$1["formMethod"] | undefined;
1128
- formAction: Submission$1["formAction"] | undefined;
1129
- formEncType: Submission$1["formEncType"] | undefined;
1130
- text: Submission$1["text"] | undefined;
1131
- formData: Submission$1["formData"] | undefined;
1132
- json: Submission$1["json"] | undefined;
1133
- data: TData | undefined;
1134
- " _hasFetcherDoneAnything "?: boolean;
1135
- };
1136
- Submitting: {
1137
- state: "submitting";
1138
- formMethod: Submission$1["formMethod"];
1139
- formAction: Submission$1["formAction"];
1140
- formEncType: Submission$1["formEncType"];
1141
- text: Submission$1["text"];
1142
- formData: Submission$1["formData"];
1143
- json: Submission$1["json"];
1144
- data: TData | undefined;
1145
- " _hasFetcherDoneAnything "?: boolean;
1146
- };
1147
- };
1148
- type Fetcher$1<TData = any> = FetcherStates$1<TData>[keyof FetcherStates$1<TData>];
1149
- interface BlockerBlocked$1 {
1150
- state: "blocked";
1151
- reset(): void;
1152
- proceed(): void;
1153
- location: Location$2;
1154
- }
1155
- interface BlockerUnblocked$1 {
1156
- state: "unblocked";
1157
- reset: undefined;
1158
- proceed: undefined;
1159
- location: undefined;
1160
- }
1161
- interface BlockerProceeding$1 {
1162
- state: "proceeding";
1163
- reset: undefined;
1164
- proceed: undefined;
1165
- location: Location$2;
1166
- }
1167
- type Blocker$1 = BlockerUnblocked$1 | BlockerBlocked$1 | BlockerProceeding$1;
1168
-
1169
- /**
1170
- * NOTE: If you refactor this to split up the modules into separate files,
1171
- * you'll need to update the rollup config for react-router-dom-v5-compat.
1172
- */
1173
-
1174
- declare global {
1175
- var __staticRouterHydrationData: HydrationState$1 | undefined;
1176
- }
1177
-
1178
- declare global {
1179
- var globalProjectAnnotations: NormalizedProjectAnnotations<any>;
1180
- var defaultProjectAnnotations: ProjectAnnotations<any>;
1181
- }
1182
- type WrappedStoryRef$1 = {
1183
- __pw_type: 'jsx';
1184
- props: Record<string, any>;
1185
- } | {
1186
- __pw_type: 'importRef';
1187
- };
1188
- type UnwrappedJSXStoryRef$1 = {
1189
- __pw_type: 'jsx';
1190
- type: UnwrappedImportStoryRef$1;
1191
- };
1192
- type UnwrappedImportStoryRef$1 = ComposedStoryFn;
1193
- declare global {
1194
- function __pwUnwrapObject(storyRef: WrappedStoryRef$1): Promise<UnwrappedJSXStoryRef$1 | UnwrappedImportStoryRef$1>;
1195
- }
1196
-
1197
- declare global {
1198
- interface SymbolConstructor {
1199
- readonly observable: symbol;
1200
- }
1201
- }
1202
-
1203
- /**
1204
- * Actions represent the type of change to a location value.
1205
- */
1206
- declare enum Action {
1207
- /**
1208
- * A POP indicates a change to an arbitrary index in the history stack, such
1209
- * as a back or forward navigation. It does not describe the direction of the
1210
- * navigation, only that the current index changed.
1211
- *
1212
- * Note: This is the default action for newly created history objects.
1213
- */
1214
- Pop = "POP",
1215
- /**
1216
- * A PUSH indicates a new entry being added to the history stack, such as when
1217
- * a link is clicked and a new page loads. When this happens, all subsequent
1218
- * entries in the stack are lost.
1219
- */
1220
- Push = "PUSH",
1221
- /**
1222
- * A REPLACE indicates the entry at the current index in the history stack
1223
- * being replaced by a new one.
1224
- */
1225
- Replace = "REPLACE"
1226
- }
1227
- /**
1228
- * The pathname, search, and hash values of a URL.
1229
- */
1230
- interface Path$1 {
1231
- /**
1232
- * A URL pathname, beginning with a /.
1233
- */
1234
- pathname: string;
1235
- /**
1236
- * A URL search string, beginning with a ?.
1237
- */
1238
- search: string;
1239
- /**
1240
- * A URL fragment identifier, beginning with a #.
1241
- */
1242
- hash: string;
1243
- }
1244
- /**
1245
- * An entry in a history stack. A location contains information about the
1246
- * URL path, as well as possibly some arbitrary state and a key.
1247
- */
1248
- interface Location extends Path$1 {
1249
- /**
1250
- * A value of arbitrary data associated with this location.
1251
- */
1252
- state: any;
1253
- /**
1254
- * A unique string associated with this location. May be used to safely store
1255
- * and retrieve data in some other storage API, like `localStorage`.
1256
- *
1257
- * Note: This value is always "default" on the initial location.
1258
- */
1259
- key: string;
1260
- }
1261
-
1262
- /**
1263
- * Map of routeId -> data returned from a loader/action/error
1264
- */
1265
- interface RouteData {
1266
- [routeId: string]: any;
1267
- }
1268
- declare enum ResultType {
1269
- data = "data",
1270
- deferred = "deferred",
1271
- redirect = "redirect",
1272
- error = "error"
1273
- }
1274
- /**
1275
- * Successful result from a loader or action
1276
- */
1277
- interface SuccessResult {
1278
- type: ResultType.data;
1279
- data: any;
1280
- statusCode?: number;
1281
- headers?: Headers;
1282
- }
1283
- /**
1284
- * Successful defer() result from a loader or action
1285
- */
1286
- interface DeferredResult {
1287
- type: ResultType.deferred;
1288
- deferredData: DeferredData;
1289
- statusCode?: number;
1290
- headers?: Headers;
1291
- }
1292
- /**
1293
- * Redirect result from a loader or action
1294
- */
1295
- interface RedirectResult {
1296
- type: ResultType.redirect;
1297
- status: number;
1298
- location: string;
1299
- revalidate: boolean;
1300
- reloadDocument?: boolean;
1301
- }
1302
- /**
1303
- * Unsuccessful result from a loader or action
1304
- */
1305
- interface ErrorResult {
1306
- type: ResultType.error;
1307
- error: any;
1308
- headers?: Headers;
1309
- }
1310
- /**
1311
- * Result from a loader or action - potentially successful or unsuccessful
1312
- */
1313
- type DataResult = SuccessResult | DeferredResult | RedirectResult | ErrorResult;
1314
- type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
1315
- type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
1316
- /**
1317
- * Active navigation/fetcher form methods are exposed in lowercase on the
1318
- * RouterState
1319
- */
1320
- type FormMethod = LowerCaseFormMethod;
1321
- /**
1322
- * In v7, active navigation/fetcher form methods are exposed in uppercase on the
1323
- * RouterState. This is to align with the normalization done via fetch().
1324
- */
1325
- type V7_FormMethod = UpperCaseFormMethod;
1326
- type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
1327
- type JsonObject = {
1328
- [Key in string]: JsonValue;
1329
- } & {
1330
- [Key in string]?: JsonValue | undefined;
1331
- };
1332
- type JsonArray = JsonValue[] | readonly JsonValue[];
1333
- type JsonPrimitive = string | number | boolean | null;
1334
- type JsonValue = JsonPrimitive | JsonObject | JsonArray;
1335
- /**
1336
- * @private
1337
- * Internal interface to pass around for action submissions, not intended for
1338
- * external consumption
1339
- */
1340
- type Submission = {
1341
- formMethod: FormMethod | V7_FormMethod;
1342
- formAction: string;
1343
- formEncType: FormEncType;
1344
- formData: FormData;
1345
- json: undefined;
1346
- text: undefined;
1347
- } | {
1348
- formMethod: FormMethod | V7_FormMethod;
1349
- formAction: string;
1350
- formEncType: FormEncType;
1351
- formData: undefined;
1352
- json: JsonValue;
1353
- text: undefined;
1354
- } | {
1355
- formMethod: FormMethod | V7_FormMethod;
1356
- formAction: string;
1357
- formEncType: FormEncType;
1358
- formData: undefined;
1359
- json: undefined;
1360
- text: string;
1361
- };
1362
- /**
1363
- * @private
1364
- * Arguments passed to route loader/action functions. Same for now but we keep
1365
- * this as a private implementation detail in case they diverge in the future.
1366
- */
1367
- interface DataFunctionArgs {
1368
- request: Request;
1369
- params: Params;
1370
- context?: any;
1371
- }
1372
- /**
1373
- * Arguments passed to loader functions
1374
- */
1375
- interface LoaderFunctionArgs extends DataFunctionArgs {
1376
- }
1377
- /**
1378
- * Arguments passed to action functions
1379
- */
1380
- interface ActionFunctionArgs extends DataFunctionArgs {
1381
- }
1382
- /**
1383
- * Loaders and actions can return anything except `undefined` (`null` is a
1384
- * valid return value if there is no data to return). Responses are preferred
1385
- * and will ease any future migration to Remix
1386
- */
1387
- type DataFunctionValue = Response | NonNullable<unknown> | null;
1388
- /**
1389
- * Route loader function signature
1390
- */
1391
- interface LoaderFunction {
1392
- (args: LoaderFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
1393
- }
1394
- /**
1395
- * Route action function signature
1396
- */
1397
- interface ActionFunction {
1398
- (args: ActionFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
1399
- }
1400
- /**
1401
- * Route shouldRevalidate function signature. This runs after any submission
1402
- * (navigation or fetcher), so we flatten the navigation/fetcher submission
1403
- * onto the arguments. It shouldn't matter whether it came from a navigation
1404
- * or a fetcher, what really matters is the URLs and the formData since loaders
1405
- * have to re-run based on the data models that were potentially mutated.
1406
- */
1407
- interface ShouldRevalidateFunction {
1408
- (args: {
1409
- currentUrl: URL;
1410
- currentParams: AgnosticDataRouteMatch["params"];
1411
- nextUrl: URL;
1412
- nextParams: AgnosticDataRouteMatch["params"];
1413
- formMethod?: Submission["formMethod"];
1414
- formAction?: Submission["formAction"];
1415
- formEncType?: Submission["formEncType"];
1416
- text?: Submission["text"];
1417
- formData?: Submission["formData"];
1418
- json?: Submission["json"];
1419
- actionResult?: DataResult;
1420
- defaultShouldRevalidate: boolean;
1421
- }): boolean;
1422
- }
1423
- /**
1424
- * Keys we cannot change from within a lazy() function. We spread all other keys
1425
- * onto the route. Either they're meaningful to the router, or they'll get
1426
- * ignored.
1427
- */
1428
- type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
1429
- type RequireOne<T, Key = keyof T> = Exclude<{
1430
- [K in keyof T]: K extends Key ? Omit<T, K> & Required<Pick<T, K>> : never;
1431
- }[keyof T], undefined>;
1432
- /**
1433
- * lazy() function to load a route definition, which can add non-matching
1434
- * related properties to a route
1435
- */
1436
- interface LazyRouteFunction<R extends AgnosticRouteObject> {
1437
- (): Promise<RequireOne<Omit<R, ImmutableRouteKey>>>;
1438
- }
1439
- /**
1440
- * Base RouteObject with common props shared by all types of routes
1441
- */
1442
- type AgnosticBaseRouteObject = {
1443
- caseSensitive?: boolean;
1444
- path?: string;
1445
- id?: string;
1446
- loader?: LoaderFunction;
1447
- action?: ActionFunction;
1448
- hasErrorBoundary?: boolean;
1449
- shouldRevalidate?: ShouldRevalidateFunction;
1450
- handle?: any;
1451
- lazy?: LazyRouteFunction<AgnosticBaseRouteObject>;
1452
- };
1453
- /**
1454
- * Index routes must not have children
1455
- */
1456
- type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
1457
- children?: undefined;
1458
- index: true;
1459
- };
1460
- /**
1461
- * Non-index routes may have children, but cannot have index
1462
- */
1463
- type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
1464
- children?: AgnosticRouteObject[];
1465
- index?: false;
1466
- };
1467
- /**
1468
- * A route object represents a logical route, with (optionally) its child
1469
- * routes organized in a tree-like structure.
1470
- */
1471
- type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
1472
- type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
1473
- id: string;
1474
- };
1475
- type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
1476
- children?: AgnosticDataRouteObject[];
1477
- id: string;
1478
- };
1479
- /**
1480
- * A data route object, which is just a RouteObject with a required unique ID
1481
- */
1482
- type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
1483
- /**
1484
- * The parameters that were parsed from the URL path.
1485
- */
1486
- type Params<Key extends string = string> = {
1487
- readonly [key in Key]: string | undefined;
1488
- };
1489
- /**
1490
- * A RouteMatch contains info about how a route matched a URL.
1491
- */
1492
- interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
1493
- /**
1494
- * The names and values of dynamic parameters in the URL.
1495
- */
1496
- params: Params<ParamKey>;
1497
- /**
1498
- * The portion of the URL pathname that was matched.
1499
- */
1500
- pathname: string;
1501
- /**
1502
- * The portion of the URL pathname that was matched before child routes.
1503
- */
1504
- pathnameBase: string;
1505
- /**
1506
- * The route object that was used to match.
1507
- */
1508
- route: RouteObjectType;
1509
- }
1510
- interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
1511
- }
1512
- declare class DeferredData {
1513
- private pendingKeysSet;
1514
- private controller;
1515
- private abortPromise;
1516
- private unlistenAbortSignal;
1517
- private subscribers;
1518
- data: Record<string, unknown>;
1519
- init?: ResponseInit;
1520
- deferredKeys: string[];
1521
- constructor(data: Record<string, unknown>, responseInit?: ResponseInit);
1522
- private trackPromise;
1523
- private onSettle;
1524
- private emit;
1525
- subscribe(fn: (aborted: boolean, settledKey?: string) => void): () => boolean;
1526
- cancel(): void;
1527
- resolveData(signal: AbortSignal): Promise<boolean>;
1528
- get done(): boolean;
1529
- get unwrappedData(): {};
1530
- get pendingKeys(): string[];
1531
- }
1532
-
1533
- /**
1534
- * State maintained internally by the router. During a navigation, all states
1535
- * reflect the the "old" location unless otherwise noted.
1536
- */
1537
- interface RouterState {
1538
- /**
1539
- * The action of the most recent navigation
1540
- */
1541
- historyAction: Action;
1542
- /**
1543
- * The current location reflected by the router
1544
- */
1545
- location: Location;
1546
- /**
1547
- * The current set of route matches
1548
- */
1549
- matches: AgnosticDataRouteMatch[];
1550
- /**
1551
- * Tracks whether we've completed our initial data load
1552
- */
1553
- initialized: boolean;
1554
- /**
1555
- * Current scroll position we should start at for a new view
1556
- * - number -> scroll position to restore to
1557
- * - false -> do not restore scroll at all (used during submissions)
1558
- * - null -> don't have a saved position, scroll to hash or top of page
1559
- */
1560
- restoreScrollPosition: number | false | null;
1561
- /**
1562
- * Indicate whether this navigation should skip resetting the scroll position
1563
- * if we are unable to restore the scroll position
1564
- */
1565
- preventScrollReset: boolean;
1566
- /**
1567
- * Tracks the state of the current navigation
1568
- */
1569
- navigation: Navigation;
1570
- /**
1571
- * Tracks any in-progress revalidations
1572
- */
1573
- revalidation: RevalidationState;
1574
- /**
1575
- * Data from the loaders for the current matches
1576
- */
1577
- loaderData: RouteData;
1578
- /**
1579
- * Data from the action for the current matches
1580
- */
1581
- actionData: RouteData | null;
1582
- /**
1583
- * Errors caught from loaders for the current matches
1584
- */
1585
- errors: RouteData | null;
1586
- /**
1587
- * Map of current fetchers
1588
- */
1589
- fetchers: Map<string, Fetcher>;
1590
- /**
1591
- * Map of current blockers
1592
- */
1593
- blockers: Map<string, Blocker>;
1594
- }
1595
- /**
1596
- * Data that can be passed into hydrate a Router from SSR
1597
- */
1598
- type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
1599
- /**
1600
- * Potential states for state.navigation
1601
- */
1602
- type NavigationStates = {
1603
- Idle: {
1604
- state: "idle";
1605
- location: undefined;
1606
- formMethod: undefined;
1607
- formAction: undefined;
1608
- formEncType: undefined;
1609
- formData: undefined;
1610
- json: undefined;
1611
- text: undefined;
1612
- };
1613
- Loading: {
1614
- state: "loading";
1615
- location: Location;
1616
- formMethod: Submission["formMethod"] | undefined;
1617
- formAction: Submission["formAction"] | undefined;
1618
- formEncType: Submission["formEncType"] | undefined;
1619
- formData: Submission["formData"] | undefined;
1620
- json: Submission["json"] | undefined;
1621
- text: Submission["text"] | undefined;
1622
- };
1623
- Submitting: {
1624
- state: "submitting";
1625
- location: Location;
1626
- formMethod: Submission["formMethod"];
1627
- formAction: Submission["formAction"];
1628
- formEncType: Submission["formEncType"];
1629
- formData: Submission["formData"];
1630
- json: Submission["json"];
1631
- text: Submission["text"];
1632
- };
1633
- };
1634
- type Navigation = NavigationStates[keyof NavigationStates];
1635
- type RevalidationState = "idle" | "loading";
1636
- /**
1637
- * Potential states for fetchers
1638
- */
1639
- type FetcherStates<TData = any> = {
1640
- Idle: {
1641
- state: "idle";
1642
- formMethod: undefined;
1643
- formAction: undefined;
1644
- formEncType: undefined;
1645
- text: undefined;
1646
- formData: undefined;
1647
- json: undefined;
1648
- data: TData | undefined;
1649
- " _hasFetcherDoneAnything "?: boolean;
1650
- };
1651
- Loading: {
1652
- state: "loading";
1653
- formMethod: Submission["formMethod"] | undefined;
1654
- formAction: Submission["formAction"] | undefined;
1655
- formEncType: Submission["formEncType"] | undefined;
1656
- text: Submission["text"] | undefined;
1657
- formData: Submission["formData"] | undefined;
1658
- json: Submission["json"] | undefined;
1659
- data: TData | undefined;
1660
- " _hasFetcherDoneAnything "?: boolean;
1661
- };
1662
- Submitting: {
1663
- state: "submitting";
1664
- formMethod: Submission["formMethod"];
1665
- formAction: Submission["formAction"];
1666
- formEncType: Submission["formEncType"];
1667
- text: Submission["text"];
1668
- formData: Submission["formData"];
1669
- json: Submission["json"];
1670
- data: TData | undefined;
1671
- " _hasFetcherDoneAnything "?: boolean;
1672
- };
1673
- };
1674
- type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
1675
- interface BlockerBlocked {
1676
- state: "blocked";
1677
- reset(): void;
1678
- proceed(): void;
1679
- location: Location;
1680
- }
1681
- interface BlockerUnblocked {
1682
- state: "unblocked";
1683
- reset: undefined;
1684
- proceed: undefined;
1685
- location: undefined;
1686
- }
1687
- interface BlockerProceeding {
1688
- state: "proceeding";
1689
- reset: undefined;
1690
- proceed: undefined;
1691
- location: Location;
1692
- }
1693
- type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
1694
-
1695
- /**
1696
- * NOTE: If you refactor this to split up the modules into separate files,
1697
- * you'll need to update the rollup config for react-router-dom-v5-compat.
1698
- */
1699
-
1700
- declare global {
1701
- var __staticRouterHydrationData: HydrationState | undefined;
1702
- }
1703
-
1704
- interface Options$1 {
1705
- allowRegExp: boolean;
1706
- allowSymbol: boolean;
1707
- allowDate: boolean;
1708
- allowUndefined: boolean;
1709
- allowError: boolean;
1710
- maxDepth: number;
1711
- space: number | undefined;
1712
- }
1713
-
1714
- /**
1715
- Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
1716
-
1717
- @category Type
1718
- */
1719
- type Primitive =
1720
- | null
1721
- | undefined
1722
- | string
1723
- | number
1724
- | boolean
1725
- | symbol
1726
- | bigint;
1727
-
1728
- declare global {
1729
- interface SymbolConstructor {
1730
- readonly observable: symbol;
1731
- }
1732
- }
1733
-
1734
- /**
1735
- Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
1736
-
1737
- Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
1738
-
1739
- This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
1740
-
1741
- @example
1742
- ```
1743
- import type {LiteralUnion} from 'type-fest';
1744
-
1745
- // Before
1746
-
1747
- type Pet = 'dog' | 'cat' | string;
1748
-
1749
- const pet: Pet = '';
1750
- // Start typing in your TypeScript-enabled IDE.
1751
- // You **will not** get auto-completion for `dog` and `cat` literals.
1752
-
1753
- // After
1754
-
1755
- type Pet2 = LiteralUnion<'dog' | 'cat', string>;
1756
-
1757
- const pet: Pet2 = '';
1758
- // You **will** get auto-completion for `dog` and `cat` literals.
1759
- ```
1760
-
1761
- @category Type
1762
- */
1763
- type LiteralUnion<
1764
- LiteralType,
1765
- BaseType extends Primitive,
1766
- > = LiteralType | (BaseType & Record<never, never>);
1767
-
1768
- declare namespace PackageJson$1 {
1769
- /**
1770
- A person who has been involved in creating or maintaining the package.
1771
- */
1772
- export type Person =
1773
- | string
1774
- | {
1775
- name: string;
1776
- url?: string;
1777
- email?: string;
1778
- };
1779
-
1780
- export type BugsLocation =
1781
- | string
1782
- | {
1783
- /**
1784
- The URL to the package's issue tracker.
1785
- */
1786
- url?: string;
1787
-
1788
- /**
1789
- The email address to which issues should be reported.
1790
- */
1791
- email?: string;
1792
- };
1793
-
1794
- export interface DirectoryLocations {
1795
- [directoryType: string]: unknown;
1796
-
1797
- /**
1798
- Location for executable scripts. Sugar to generate entries in the `bin` property by walking the folder.
1799
- */
1800
- bin?: string;
1801
-
1802
- /**
1803
- Location for Markdown files.
1804
- */
1805
- doc?: string;
1806
-
1807
- /**
1808
- Location for example scripts.
1809
- */
1810
- example?: string;
1811
-
1812
- /**
1813
- Location for the bulk of the library.
1814
- */
1815
- lib?: string;
1816
-
1817
- /**
1818
- Location for man pages. Sugar to generate a `man` array by walking the folder.
1819
- */
1820
- man?: string;
1821
-
1822
- /**
1823
- Location for test files.
1824
- */
1825
- test?: string;
1826
- }
1827
-
1828
- export type Scripts = {
1829
- /**
1830
- Run **before** the package is published (Also run on local `npm install` without any arguments).
1831
- */
1832
- prepublish?: string;
1833
-
1834
- /**
1835
- Run both **before** the package is packed and published, and on local `npm install` without any arguments. This is run **after** `prepublish`, but **before** `prepublishOnly`.
1836
- */
1837
- prepare?: string;
1838
-
1839
- /**
1840
- Run **before** the package is prepared and packed, **only** on `npm publish`.
1841
- */
1842
- prepublishOnly?: string;
1843
-
1844
- /**
1845
- Run **before** a tarball is packed (on `npm pack`, `npm publish`, and when installing git dependencies).
1846
- */
1847
- prepack?: string;
1848
-
1849
- /**
1850
- Run **after** the tarball has been generated and moved to its final destination.
1851
- */
1852
- postpack?: string;
1853
-
1854
- /**
1855
- Run **after** the package is published.
1856
- */
1857
- publish?: string;
1858
-
1859
- /**
1860
- Run **after** the package is published.
1861
- */
1862
- postpublish?: string;
1863
-
1864
- /**
1865
- Run **before** the package is installed.
1866
- */
1867
- preinstall?: string;
1868
-
1869
- /**
1870
- Run **after** the package is installed.
1871
- */
1872
- install?: string;
1873
-
1874
- /**
1875
- Run **after** the package is installed and after `install`.
1876
- */
1877
- postinstall?: string;
1878
-
1879
- /**
1880
- Run **before** the package is uninstalled and before `uninstall`.
1881
- */
1882
- preuninstall?: string;
1883
-
1884
- /**
1885
- Run **before** the package is uninstalled.
1886
- */
1887
- uninstall?: string;
1888
-
1889
- /**
1890
- Run **after** the package is uninstalled.
1891
- */
1892
- postuninstall?: string;
1893
-
1894
- /**
1895
- Run **before** bump the package version and before `version`.
1896
- */
1897
- preversion?: string;
1898
-
1899
- /**
1900
- Run **before** bump the package version.
1901
- */
1902
- version?: string;
1903
-
1904
- /**
1905
- Run **after** bump the package version.
1906
- */
1907
- postversion?: string;
1908
-
1909
- /**
1910
- Run with the `npm test` command, before `test`.
1911
- */
1912
- pretest?: string;
1913
-
1914
- /**
1915
- Run with the `npm test` command.
1916
- */
1917
- test?: string;
1918
-
1919
- /**
1920
- Run with the `npm test` command, after `test`.
1921
- */
1922
- posttest?: string;
1923
-
1924
- /**
1925
- Run with the `npm stop` command, before `stop`.
1926
- */
1927
- prestop?: string;
1928
-
1929
- /**
1930
- Run with the `npm stop` command.
1931
- */
1932
- stop?: string;
1933
-
1934
- /**
1935
- Run with the `npm stop` command, after `stop`.
1936
- */
1937
- poststop?: string;
1938
-
1939
- /**
1940
- Run with the `npm start` command, before `start`.
1941
- */
1942
- prestart?: string;
1943
-
1944
- /**
1945
- Run with the `npm start` command.
1946
- */
1947
- start?: string;
1948
-
1949
- /**
1950
- Run with the `npm start` command, after `start`.
1951
- */
1952
- poststart?: string;
1953
-
1954
- /**
1955
- Run with the `npm restart` command, before `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
1956
- */
1957
- prerestart?: string;
1958
-
1959
- /**
1960
- Run with the `npm restart` command. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
1961
- */
1962
- restart?: string;
1963
-
1964
- /**
1965
- Run with the `npm restart` command, after `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
1966
- */
1967
- postrestart?: string;
1968
- } & Partial<Record<string, string>>;
1969
-
1970
- /**
1971
- Dependencies of the package. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or Git URL.
1972
- */
1973
- export type Dependency = Partial<Record<string, string>>;
1974
-
1975
- /**
1976
- Conditions which provide a way to resolve a package entry point based on the environment.
1977
- */
1978
- export type ExportCondition = LiteralUnion<
1979
- | 'import'
1980
- | 'require'
1981
- | 'node'
1982
- | 'node-addons'
1983
- | 'deno'
1984
- | 'browser'
1985
- | 'electron'
1986
- | 'react-native'
1987
- | 'default',
1988
- string
1989
- >;
1990
-
1991
- type ExportConditions = {[condition in ExportCondition]: Exports};
1992
-
1993
- /**
1994
- Entry points of a module, optionally with conditions and subpath exports.
1995
- */
1996
- export type Exports =
1997
- | null
1998
- | string
1999
- | Array<string | ExportConditions>
2000
- | ExportConditions
2001
- | {[path: string]: Exports}; // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
2002
-
2003
- /**
2004
- Import map entries of a module, optionally with conditions.
2005
- */
2006
- export type Imports = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
2007
- [key: string]: string | {[key in ExportCondition]: Exports};
2008
- };
2009
-
2010
- export interface NonStandardEntryPoints {
2011
- /**
2012
- An ECMAScript module ID that is the primary entry point to the program.
2013
- */
2014
- module?: string;
2015
-
2016
- /**
2017
- A module ID with untranspiled code that is the primary entry point to the program.
2018
- */
2019
- esnext?:
2020
- | string
2021
- | {
2022
- [moduleName: string]: string | undefined;
2023
- main?: string;
2024
- browser?: string;
2025
- };
2026
-
2027
- /**
2028
- A hint to JavaScript bundlers or component tools when packaging modules for client side use.
2029
- */
2030
- browser?:
2031
- | string
2032
- | Partial<Record<string, string | false>>;
2033
-
2034
- /**
2035
- Denote which files in your project are "pure" and therefore safe for Webpack to prune if unused.
2036
-
2037
- [Read more.](https://webpack.js.org/guides/tree-shaking/)
2038
- */
2039
- sideEffects?: boolean | string[];
2040
- }
2041
-
2042
- export interface TypeScriptConfiguration {
2043
- /**
2044
- Location of the bundled TypeScript declaration file.
2045
- */
2046
- types?: string;
2047
-
2048
- /**
2049
- Version selection map of TypeScript.
2050
- */
2051
- typesVersions?: Partial<Record<string, Partial<Record<string, string[]>>>>;
2052
-
2053
- /**
2054
- Location of the bundled TypeScript declaration file. Alias of `types`.
2055
- */
2056
- typings?: string;
2057
- }
2058
-
2059
- /**
2060
- An alternative configuration for Yarn workspaces.
2061
- */
2062
- export interface WorkspaceConfig {
2063
- /**
2064
- An array of workspace pattern strings which contain the workspace packages.
2065
- */
2066
- packages?: WorkspacePattern[];
2067
-
2068
- /**
2069
- Designed to solve the problem of packages which break when their `node_modules` are moved to the root workspace directory - a process known as hoisting. For these packages, both within your workspace, and also some that have been installed via `node_modules`, it is important to have a mechanism for preventing the default Yarn workspace behavior. By adding workspace pattern strings here, Yarn will resume non-workspace behavior for any package which matches the defined patterns.
2070
-
2071
- [Read more](https://classic.yarnpkg.com/blog/2018/02/15/nohoist/)
2072
- */
2073
- nohoist?: WorkspacePattern[];
2074
- }
2075
-
2076
- /**
2077
- A workspace pattern points to a directory or group of directories which contain packages that should be included in the workspace installation process.
2078
-
2079
- The patterns are handled with [minimatch](https://github.com/isaacs/minimatch).
2080
-
2081
- @example
2082
- `docs` → Include the docs directory and install its dependencies.
2083
- `packages/*` → Include all nested directories within the packages directory, like `packages/cli` and `packages/core`.
2084
- */
2085
- type WorkspacePattern = string;
2086
-
2087
- export interface YarnConfiguration {
2088
- /**
2089
- Used to configure [Yarn workspaces](https://classic.yarnpkg.com/docs/workspaces/).
2090
-
2091
- Workspaces allow you to manage multiple packages within the same repository in such a way that you only need to run `yarn install` once to install all of them in a single pass.
2092
-
2093
- Please note that the top-level `private` property of `package.json` **must** be set to `true` in order to use workspaces.
2094
- */
2095
- workspaces?: WorkspacePattern[] | WorkspaceConfig;
2096
-
2097
- /**
2098
- If your package only allows one version of a given dependency, and you’d like to enforce the same behavior as `yarn install --flat` on the command-line, set this to `true`.
2099
-
2100
- Note that if your `package.json` contains `"flat": true` and other packages depend on yours (e.g. you are building a library rather than an app), those other packages will also need `"flat": true` in their `package.json` or be installed with `yarn install --flat` on the command-line.
2101
- */
2102
- flat?: boolean;
2103
-
2104
- /**
2105
- Selective version resolutions. Allows the definition of custom package versions inside dependencies without manual edits in the `yarn.lock` file.
2106
- */
2107
- resolutions?: Dependency;
2108
- }
2109
-
2110
- export interface JSPMConfiguration {
2111
- /**
2112
- JSPM configuration.
2113
- */
2114
- jspm?: PackageJson$1;
2115
- }
2116
-
2117
- /**
2118
- Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Containing standard npm properties.
2119
- */
2120
- export interface PackageJsonStandard {
2121
- /**
2122
- The name of the package.
2123
- */
2124
- name?: string;
2125
-
2126
- /**
2127
- Package version, parseable by [`node-semver`](https://github.com/npm/node-semver).
2128
- */
2129
- version?: string;
2130
-
2131
- /**
2132
- Package description, listed in `npm search`.
2133
- */
2134
- description?: string;
2135
-
2136
- /**
2137
- Keywords associated with package, listed in `npm search`.
2138
- */
2139
- keywords?: string[];
2140
-
2141
- /**
2142
- The URL to the package's homepage.
2143
- */
2144
- homepage?: LiteralUnion<'.', string>;
2145
-
2146
- /**
2147
- The URL to the package's issue tracker and/or the email address to which issues should be reported.
2148
- */
2149
- bugs?: BugsLocation;
2150
-
2151
- /**
2152
- The license for the package.
2153
- */
2154
- license?: string;
2155
-
2156
- /**
2157
- The licenses for the package.
2158
- */
2159
- licenses?: Array<{
2160
- type?: string;
2161
- url?: string;
2162
- }>;
2163
-
2164
- author?: Person;
2165
-
2166
- /**
2167
- A list of people who contributed to the package.
2168
- */
2169
- contributors?: Person[];
2170
-
2171
- /**
2172
- A list of people who maintain the package.
2173
- */
2174
- maintainers?: Person[];
2175
-
2176
- /**
2177
- The files included in the package.
2178
- */
2179
- files?: string[];
2180
-
2181
- /**
2182
- Resolution algorithm for importing ".js" files from the package's scope.
2183
-
2184
- [Read more.](https://nodejs.org/api/esm.html#esm_package_json_type_field)
2185
- */
2186
- type?: 'module' | 'commonjs';
2187
-
2188
- /**
2189
- The module ID that is the primary entry point to the program.
2190
- */
2191
- main?: string;
2192
-
2193
- /**
2194
- Subpath exports to define entry points of the package.
2195
-
2196
- [Read more.](https://nodejs.org/api/packages.html#subpath-exports)
2197
- */
2198
- exports?: Exports;
2199
-
2200
- /**
2201
- Subpath imports to define internal package import maps that only apply to import specifiers from within the package itself.
2202
-
2203
- [Read more.](https://nodejs.org/api/packages.html#subpath-imports)
2204
- */
2205
- imports?: Imports;
2206
-
2207
- /**
2208
- The executable files that should be installed into the `PATH`.
2209
- */
2210
- bin?:
2211
- | string
2212
- | Partial<Record<string, string>>;
2213
-
2214
- /**
2215
- Filenames to put in place for the `man` program to find.
2216
- */
2217
- man?: string | string[];
2218
-
2219
- /**
2220
- Indicates the structure of the package.
2221
- */
2222
- directories?: DirectoryLocations;
2223
-
2224
- /**
2225
- Location for the code repository.
2226
- */
2227
- repository?:
2228
- | string
2229
- | {
2230
- type: string;
2231
- url: string;
2232
-
2233
- /**
2234
- Relative path to package.json if it is placed in non-root directory (for example if it is part of a monorepo).
2235
-
2236
- [Read more.](https://github.com/npm/rfcs/blob/latest/implemented/0010-monorepo-subdirectory-declaration.md)
2237
- */
2238
- directory?: string;
2239
- };
2240
-
2241
- /**
2242
- Script commands that are run at various times in the lifecycle of the package. The key is the lifecycle event, and the value is the command to run at that point.
2243
- */
2244
- scripts?: Scripts;
2245
-
2246
- /**
2247
- Is used to set configuration parameters used in package scripts that persist across upgrades.
2248
- */
2249
- config?: Record<string, unknown>;
2250
-
2251
- /**
2252
- The dependencies of the package.
2253
- */
2254
- dependencies?: Dependency;
2255
-
2256
- /**
2257
- Additional tooling dependencies that are not required for the package to work. Usually test, build, or documentation tooling.
2258
- */
2259
- devDependencies?: Dependency;
2260
-
2261
- /**
2262
- Dependencies that are skipped if they fail to install.
2263
- */
2264
- optionalDependencies?: Dependency;
2265
-
2266
- /**
2267
- Dependencies that will usually be required by the package user directly or via another dependency.
2268
- */
2269
- peerDependencies?: Dependency;
2270
-
2271
- /**
2272
- Indicate peer dependencies that are optional.
2273
- */
2274
- peerDependenciesMeta?: Partial<Record<string, {optional: true}>>;
2275
-
2276
- /**
2277
- Package names that are bundled when the package is published.
2278
- */
2279
- bundledDependencies?: string[];
2280
-
2281
- /**
2282
- Alias of `bundledDependencies`.
2283
- */
2284
- bundleDependencies?: string[];
2285
-
2286
- /**
2287
- Engines that this package runs on.
2288
- */
2289
- engines?: {
2290
- [EngineName in 'npm' | 'node' | string]?: string;
2291
- };
2292
-
2293
- /**
2294
- @deprecated
2295
- */
2296
- engineStrict?: boolean;
2297
-
2298
- /**
2299
- Operating systems the module runs on.
2300
- */
2301
- os?: Array<LiteralUnion<
2302
- | 'aix'
2303
- | 'darwin'
2304
- | 'freebsd'
2305
- | 'linux'
2306
- | 'openbsd'
2307
- | 'sunos'
2308
- | 'win32'
2309
- | '!aix'
2310
- | '!darwin'
2311
- | '!freebsd'
2312
- | '!linux'
2313
- | '!openbsd'
2314
- | '!sunos'
2315
- | '!win32',
2316
- string
2317
- >>;
2318
-
2319
- /**
2320
- CPU architectures the module runs on.
2321
- */
2322
- cpu?: Array<LiteralUnion<
2323
- | 'arm'
2324
- | 'arm64'
2325
- | 'ia32'
2326
- | 'mips'
2327
- | 'mipsel'
2328
- | 'ppc'
2329
- | 'ppc64'
2330
- | 's390'
2331
- | 's390x'
2332
- | 'x32'
2333
- | 'x64'
2334
- | '!arm'
2335
- | '!arm64'
2336
- | '!ia32'
2337
- | '!mips'
2338
- | '!mipsel'
2339
- | '!ppc'
2340
- | '!ppc64'
2341
- | '!s390'
2342
- | '!s390x'
2343
- | '!x32'
2344
- | '!x64',
2345
- string
2346
- >>;
2347
-
2348
- /**
2349
- If set to `true`, a warning will be shown if package is installed locally. Useful if the package is primarily a command-line application that should be installed globally.
2350
-
2351
- @deprecated
2352
- */
2353
- preferGlobal?: boolean;
2354
-
2355
- /**
2356
- If set to `true`, then npm will refuse to publish it.
2357
- */
2358
- private?: boolean;
2359
-
2360
- /**
2361
- A set of config values that will be used at publish-time. It's especially handy to set the tag, registry or access, to ensure that a given package is not tagged with 'latest', published to the global public registry or that a scoped module is private by default.
2362
- */
2363
- publishConfig?: PublishConfig;
2364
-
2365
- /**
2366
- Describes and notifies consumers of a package's monetary support information.
2367
-
2368
- [Read more.](https://github.com/npm/rfcs/blob/latest/accepted/0017-add-funding-support.md)
2369
- */
2370
- funding?: string | {
2371
- /**
2372
- The type of funding.
2373
- */
2374
- type?: LiteralUnion<
2375
- | 'github'
2376
- | 'opencollective'
2377
- | 'patreon'
2378
- | 'individual'
2379
- | 'foundation'
2380
- | 'corporation',
2381
- string
2382
- >;
2383
-
2384
- /**
2385
- The URL to the funding page.
2386
- */
2387
- url: string;
2388
- };
2389
- }
2390
-
2391
- export interface PublishConfig {
2392
- /**
2393
- Additional, less common properties from the [npm docs on `publishConfig`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#publishconfig).
2394
- */
2395
- [additionalProperties: string]: unknown;
2396
-
2397
- /**
2398
- When publishing scoped packages, the access level defaults to restricted. If you want your scoped package to be publicly viewable (and installable) set `--access=public`. The only valid values for access are public and restricted. Unscoped packages always have an access level of public.
2399
- */
2400
- access?: 'public' | 'restricted';
2401
-
2402
- /**
2403
- The base URL of the npm registry.
2404
-
2405
- Default: `'https://registry.npmjs.org/'`
2406
- */
2407
- registry?: string;
2408
-
2409
- /**
2410
- The tag to publish the package under.
2411
-
2412
- Default: `'latest'`
2413
- */
2414
- tag?: string;
2415
- }
2416
- }
2417
-
2418
- /**
2419
- Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Also includes types for fields used by other popular projects, like TypeScript and Yarn.
2420
-
2421
- @category File
2422
- */
2423
- type PackageJson$1 =
2424
- PackageJson$1.PackageJsonStandard &
2425
- PackageJson$1.NonStandardEntryPoints &
2426
- PackageJson$1.TypeScriptConfiguration &
2427
- PackageJson$1.YarnConfiguration &
2428
- PackageJson$1.JSPMConfiguration;
2429
-
2430
- type ExportName = string;
2431
- type MetaId = string;
2432
- interface StoriesSpecifier {
2433
- /** When auto-titling, what to prefix all generated titles with (default: '') */
2434
- titlePrefix?: string;
2435
- /** Where to start looking for story files */
2436
- directory: string;
2437
- /**
2438
- * What does the filename of a story file look like? (a glob, relative to directory, no leading
2439
- * `./`) If unset, we use `** / *.@(mdx|stories.@(mdx|js|jsx|mjs|ts|tsx))` (no spaces)
2440
- */
2441
- files?: string;
2442
- }
2443
- type StoriesEntry = string | StoriesSpecifier;
2444
- type NormalizedStoriesSpecifier = Required<StoriesSpecifier> & {
2445
- importPathMatcher: RegExp;
2446
- };
2447
- interface IndexerOptions {
2448
- makeTitle: (userTitle?: string) => string;
2449
- }
2450
- /**
2451
- * FIXME: This is a temporary type to allow us to deprecate the old indexer API. We should remove
2452
- * this type and the deprecated indexer API in 8.0.
2453
- */
2454
- type BaseIndexer = {
2455
- /** A regular expression that should match all files to be handled by this indexer */
2456
- test: RegExp;
2457
- };
2458
- /**
2459
- * An indexer describes which filenames it handles, and how to index each individual file - turning
2460
- * it into an entry in the index.
2461
- */
2462
- type Indexer = BaseIndexer & {
2463
- /**
2464
- * Indexes a file containing stories or docs.
2465
- *
2466
- * @param fileName The name of the file to index.
2467
- * @param options {@link IndexerOptions} for indexing the file.
2468
- * @returns A promise that resolves to an array of {@link IndexInput} objects.
2469
- */
2470
- createIndex: (fileName: string, options: IndexerOptions) => Promise<IndexInput[]>;
2471
- };
2472
- interface BaseIndexEntry {
2473
- id: StoryId;
2474
- name: StoryName;
2475
- title: ComponentTitle;
2476
- tags?: Tag$1[];
2477
- importPath: Path;
2478
- }
2479
- type StoryIndexEntry = BaseIndexEntry & {
2480
- type: 'story';
2481
- };
2482
- type DocsIndexEntry = BaseIndexEntry & {
2483
- storiesImports: Path[];
2484
- type: 'docs';
2485
- };
2486
- type IndexEntry = StoryIndexEntry | DocsIndexEntry;
2487
- interface IndexInputStats {
2488
- loaders?: boolean;
2489
- play?: boolean;
2490
- render?: boolean;
2491
- storyFn?: boolean;
2492
- mount?: boolean;
2493
- beforeEach?: boolean;
2494
- moduleMock?: boolean;
2495
- globals?: boolean;
2496
- factory?: boolean;
2497
- tags?: boolean;
2498
- }
2499
- /** The base input for indexing a story or docs entry. */
2500
- type BaseIndexInput = {
2501
- /** The file to import from e.g. the story file. */
2502
- importPath: Path;
2503
- /** The raw path/package of the file that provides meta.component, if one exists */
2504
- rawComponentPath?: Path;
2505
- /** The name of the export to import. */
2506
- exportName: ExportName;
2507
- /** The name of the entry, auto-generated from {@link exportName} if unspecified. */
2508
- name?: StoryName;
2509
- /** The location in the sidebar, auto-generated from {@link importPath} if unspecified. */
2510
- title?: ComponentTitle;
2511
- /**
2512
- * The custom id optionally set at `meta.id` if it needs to differ from the id generated via
2513
- * {@link title}. If unspecified, the meta id will be auto-generated from {@link title}. If
2514
- * specified, the meta in the CSF file _must_ have a matching id set at `meta.id`, to be correctly
2515
- * matched.
2516
- */
2517
- metaId?: MetaId;
2518
- /** Tags for filtering entries in Storybook and its tools. */
2519
- tags?: Tag$1[];
2520
- /**
2521
- * The id of the entry, auto-generated from {@link title}/{@link metaId} and {@link exportName} if
2522
- * unspecified. If specified, the story in the CSF file _must_ have a matching id set at
2523
- * `parameters.__id`, to be correctly matched. Only use this if you need to override the
2524
- * auto-generated id.
2525
- */
2526
- __id?: StoryId;
2527
- /** Stats about language feature usage that the indexer can optionally report */
2528
- __stats?: IndexInputStats;
2529
- };
2530
- /** The input for indexing a story entry. */
2531
- type StoryIndexInput = BaseIndexInput & {
2532
- type: 'story';
2533
- };
2534
- /** The input for indexing a docs entry. */
2535
- type DocsIndexInput = BaseIndexInput & {
2536
- type: 'docs';
2537
- /** Paths to story files that must be pre-loaded for this docs entry. */
2538
- storiesImports?: Path[];
2539
- };
2540
- type IndexInput = StoryIndexInput | DocsIndexInput;
2541
-
2542
- /** ⚠️ This file contains internal WIP types they MUST NOT be exported outside this package for now! */
2543
- type BuilderName = 'webpack5' | '@storybook/builder-webpack5' | string;
2544
- type RendererName = string;
2545
- interface CoreConfig {
2546
- builder?: BuilderName | {
2547
- name: BuilderName;
2548
- options?: Record<string, any>;
2549
- };
2550
- renderer?: RendererName;
2551
- disableWebpackDefaults?: boolean;
2552
- channelOptions?: Partial<Options$1>;
2553
- /** Disables the generation of project.json, a file containing Storybook metadata */
2554
- disableProjectJson?: boolean;
2555
- /**
2556
- * Disables Storybook telemetry
2557
- *
2558
- * @see https://storybook.js.org/telemetry
2559
- */
2560
- disableTelemetry?: boolean;
2561
- /** Disables notifications for Storybook updates. */
2562
- disableWhatsNewNotifications?: boolean;
2563
- /**
2564
- * Enable crash reports to be sent to Storybook telemetry
2565
- *
2566
- * @see https://storybook.js.org/telemetry
2567
- */
2568
- enableCrashReports?: boolean;
2569
- /**
2570
- * Enable CORS headings to run document in a "secure context" see:
2571
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements
2572
- * This enables these headers in development-mode: Cross-Origin-Opener-Policy: same-origin
2573
- *
2574
- * ```text
2575
- * Cross-Origin-Embedder-Policy: require-corp
2576
- * ```
2577
- */
2578
- crossOriginIsolated?: boolean;
2579
- }
2580
- interface DirectoryMapping {
2581
- from: string;
2582
- to: string;
2583
- }
2584
- interface Presets {
2585
- apply(extension: 'typescript', config: TypescriptOptions, args?: Options): Promise<TypescriptOptions>;
2586
- apply(extension: 'framework', config?: {}, args?: any): Promise<Preset>;
2587
- apply(extension: 'babel', config?: {}, args?: any): Promise<any>;
2588
- apply(extension: 'swc', config?: {}, args?: any): Promise<any>;
2589
- apply(extension: 'entries', config?: [], args?: any): Promise<unknown>;
2590
- apply(extension: 'env', config?: {}, args?: any): Promise<any>;
2591
- apply(extension: 'stories', config?: [], args?: any): Promise<StoriesEntry[]>;
2592
- apply(extension: 'managerEntries', config: [], args?: any): Promise<string[]>;
2593
- apply(extension: 'refs', config?: [], args?: any): Promise<StorybookConfigRaw['refs']>;
2594
- apply(extension: 'core', config?: StorybookConfigRaw['core'], args?: any): Promise<NonNullable<StorybookConfigRaw['core']>>;
2595
- apply(extension: 'docs', config?: StorybookConfigRaw['docs'], args?: any): Promise<NonNullable<StorybookConfigRaw['docs']>>;
2596
- apply(extension: 'features', config?: StorybookConfigRaw['features'], args?: any): Promise<NonNullable<StorybookConfigRaw['features']>>;
2597
- apply(extension: 'typescript', config?: StorybookConfigRaw['typescript'], args?: any): Promise<NonNullable<StorybookConfigRaw['typescript']>>;
2598
- apply(extension: 'build', config?: StorybookConfigRaw['build'], args?: any): Promise<NonNullable<StorybookConfigRaw['build']>>;
2599
- apply(extension: 'staticDirs', config?: StorybookConfigRaw['staticDirs'], args?: any): Promise<StorybookConfigRaw['staticDirs']>;
2600
- apply<T>(extension: string, config?: T, args?: unknown): Promise<T>;
2601
- }
2602
- interface LoadedPreset {
2603
- name: string;
2604
- preset: any;
2605
- options: any;
2606
- }
2607
- interface VersionCheck {
2608
- success: boolean;
2609
- cached: boolean;
2610
- data?: any;
2611
- error?: any;
2612
- time: number;
2613
- }
2614
- interface Stats {
2615
- toJson: () => any;
2616
- }
2617
- interface BuilderResult {
2618
- totalTime?: ReturnType<typeof process.hrtime>;
2619
- stats?: Stats;
2620
- }
2621
- type PackageJson = PackageJson$1 & Record<string, any>;
2622
- interface LoadOptions {
2623
- packageJson?: PackageJson;
2624
- outputDir?: string;
2625
- configDir?: string;
2626
- cacheKey?: string;
2627
- ignorePreview?: boolean;
2628
- extendServer?: (server: Server) => void;
2629
- }
2630
- interface CLIBaseOptions {
2631
- disableTelemetry?: boolean;
2632
- enableCrashReports?: boolean;
2633
- configDir?: string;
2634
- loglevel?: string;
2635
- quiet?: boolean;
2636
- }
2637
- interface CLIOptions extends CLIBaseOptions {
2638
- port?: number;
2639
- ignorePreview?: boolean;
2640
- previewUrl?: string;
2641
- forceBuildPreview?: boolean;
2642
- host?: string;
2643
- initialPath?: string;
2644
- exactPort?: boolean;
2645
- https?: boolean;
2646
- sslCa?: string[];
2647
- sslCert?: string;
2648
- sslKey?: string;
2649
- smokeTest?: boolean;
2650
- managerCache?: boolean;
2651
- open?: boolean;
2652
- ci?: boolean;
2653
- versionUpdates?: boolean;
2654
- docs?: boolean;
2655
- test?: boolean;
2656
- debugWebpack?: boolean;
2657
- webpackStatsJson?: string | boolean;
2658
- statsJson?: string | boolean;
2659
- outputDir?: string;
2660
- previewOnly?: boolean;
2661
- }
2662
- interface BuilderOptions$1 {
2663
- configType?: 'DEVELOPMENT' | 'PRODUCTION';
2664
- ignorePreview?: boolean;
2665
- cache?: FileSystemCache;
2666
- configDir: string;
2667
- docsMode?: boolean;
2668
- features?: StorybookConfigRaw['features'];
2669
- versionCheck?: VersionCheck;
2670
- disableWebpackDefaults?: boolean;
2671
- serverChannelUrl?: string;
2672
- }
2673
- interface StorybookConfigOptions {
2674
- presets: Presets;
2675
- presetsList?: LoadedPreset[];
2676
- }
2677
- type Options = LoadOptions & StorybookConfigOptions & CLIOptions & BuilderOptions$1 & {
2678
- build?: TestBuildConfig;
2679
- };
2680
- /** Options for TypeScript usage within Storybook. */
2681
- interface TypescriptOptions {
2682
- /**
2683
- * Enables type checking within Storybook.
2684
- *
2685
- * @default false
2686
- */
2687
- check: boolean;
2688
- /**
2689
- * Disable parsing TypeScript files through compiler.
2690
- *
2691
- * @default false
2692
- */
2693
- skipCompiler: boolean;
2694
- }
2695
- type Preset = string | {
2696
- name: string;
2697
- options?: any;
2698
- };
2699
- /** An additional script that gets injected into the preview or the manager, */
2700
- type Entry = string;
2701
- type CoreCommon_StorybookRefs = Record<string, {
2702
- title: string;
2703
- url: string;
2704
- } | {
2705
- disable: boolean;
2706
- expanded?: boolean;
2707
- }>;
2708
- type DocsOptions = {
2709
- /** What should we call the generated docs entries? */
2710
- defaultName?: string;
2711
- /** Only show doc entries in the side bar (usually set with the `--docs` CLI flag) */
2712
- docsMode?: boolean;
2713
- };
2714
- interface TestBuildFlags {
2715
- /**
2716
- * The package @storybook/blocks will be excluded from the bundle, even when imported in e.g. the
2717
- * preview.
2718
- */
2719
- disableBlocks?: boolean;
2720
- /** Disable specific addons */
2721
- disabledAddons?: string[];
2722
- /** Filter out .mdx stories entries */
2723
- disableMDXEntries?: boolean;
2724
- /** Override autodocs to be disabled */
2725
- disableAutoDocs?: boolean;
2726
- /** Override docgen to be disabled. */
2727
- disableDocgen?: boolean;
2728
- /** Override sourcemaps generation to be disabled. */
2729
- disableSourcemaps?: boolean;
2730
- /** Override tree-shaking (dead code elimination) to be disabled. */
2731
- disableTreeShaking?: boolean;
2732
- /** Minify with ESBuild when using webpack. */
2733
- esbuildMinify?: boolean;
2734
- }
2735
- interface TestBuildConfig {
2736
- test?: TestBuildFlags;
2737
- }
2738
- type Tag = string;
2739
- interface TagOptions {
2740
- excludeFromSidebar: boolean;
2741
- excludeFromDocsStories: boolean;
2742
- }
2743
- type TagsOptions = Record<Tag, Partial<TagOptions>>;
2744
- /**
2745
- * The interface for Storybook configuration used internally in presets The difference is that these
2746
- * values are the raw values, AKA, not wrapped with `PresetValue<>`
2747
- */
2748
- interface StorybookConfigRaw {
2749
- /**
2750
- * Sets the addons you want to use with Storybook.
2751
- *
2752
- * @example
2753
- *
2754
- * ```ts
2755
- * addons = ['@storybook/addon-essentials'];
2756
- * addons = [{ name: '@storybook/addon-essentials', options: { backgrounds: false } }];
2757
- * ```
2758
- */
2759
- addons?: Preset[];
2760
- core?: CoreConfig;
2761
- staticDirs?: (DirectoryMapping | string)[];
2762
- logLevel?: string;
2763
- features?: {
2764
- /**
2765
- * Enable the integrated viewport addon
2766
- *
2767
- * @default true
2768
- */
2769
- viewport?: boolean;
2770
- /**
2771
- * Enable the integrated highlight addon
2772
- *
2773
- * @default true
2774
- */
2775
- highlight?: boolean;
2776
- /**
2777
- * Enable the integrated backgrounds addon
2778
- *
2779
- * @default true
2780
- */
2781
- backgrounds?: boolean;
2782
- /**
2783
- * Enable the integrated measure addon
2784
- *
2785
- * @default true
2786
- */
2787
- measure?: boolean;
2788
- /**
2789
- * Enable the integrated outline addon
2790
- *
2791
- * @default true
2792
- */
2793
- outline?: boolean;
2794
- /**
2795
- * Enable the integrated controls addon
2796
- *
2797
- * @default true
2798
- */
2799
- controls?: boolean;
2800
- /**
2801
- * Enable the integrated interactions addon
2802
- *
2803
- * @default true
2804
- */
2805
- interactions?: boolean;
2806
- /**
2807
- * Enable the integrated actions addon
2808
- *
2809
- * @default true
2810
- */
2811
- actions?: boolean;
2812
- /**
2813
- * @temporary This feature flag is a migration assistant, and is scheduled to be removed.
2814
- *
2815
- * Filter args with a "target" on the type from the render function (EXPERIMENTAL)
2816
- */
2817
- argTypeTargetsV7?: boolean;
2818
- /**
2819
- * @temporary This feature flag is a migration assistant, and is scheduled to be removed.
2820
- *
2821
- * Apply decorators from preview.js before decorators from addons or frameworks
2822
- */
2823
- legacyDecoratorFileOrder?: boolean;
2824
- /**
2825
- * @temporary This feature flag is a migration assistant, and is scheduled to be removed.
2826
- *
2827
- * Disallow implicit actions during rendering. This will be the default in Storybook 8.
2828
- *
2829
- * This will make sure that your story renders the same no matter if docgen is enabled or not.
2830
- */
2831
- disallowImplicitActionsInRenderV8?: boolean;
2832
- /**
2833
- * @temporary This feature flag is a migration assistant, and is scheduled to be removed.
2834
- *
2835
- * Enable asynchronous component rendering in React renderer
2836
- */
2837
- experimentalRSC?: boolean;
2838
- /**
2839
- * @temporary This feature flag is a migration assistant, and is scheduled to be removed.
2840
- *
2841
- * Set NODE_ENV to development in built Storybooks for better testability and debuggability
2842
- */
2843
- developmentModeForBuild?: boolean;
2844
- /** Only show input controls in Angular */
2845
- angularFilterNonInputControls?: boolean;
2846
- };
2847
- build?: TestBuildConfig;
2848
- stories: StoriesEntry[];
2849
- framework?: Preset;
2850
- typescript?: Partial<TypescriptOptions>;
2851
- refs?: CoreCommon_StorybookRefs;
2852
- babel?: any;
2853
- swc?: any;
2854
- env?: Record<string, string>;
2855
- babelDefault?: any;
2856
- previewAnnotations?: Entry[];
2857
- experimental_indexers?: Indexer[];
2858
- docs?: DocsOptions;
2859
- previewHead?: string;
2860
- previewBody?: string;
2861
- previewMainTemplate?: string;
2862
- managerHead?: string;
2863
- tags?: TagsOptions;
2864
- }
2865
- /**
2866
- * The interface for Storybook configuration in `main.ts` files. This interface is public All values
2867
- * should be wrapped with `PresetValue<>`, though there are a few exceptions: `addons`, `framework`
2868
- */
2869
- interface StorybookConfig$1 {
2870
- /**
2871
- * Sets the addons you want to use with Storybook.
2872
- *
2873
- * @example
2874
- *
2875
- * ```
2876
- * addons = ['@storybook/addon-essentials'];
2877
- * addons = [{ name: '@storybook/addon-essentials', options: { backgrounds: false } }];
2878
- * ```
2879
- */
2880
- addons?: StorybookConfigRaw['addons'];
2881
- core?: PresetValue<StorybookConfigRaw['core']>;
2882
- /**
2883
- * Sets a list of directories of static files to be loaded by Storybook server
2884
- *
2885
- * @example
2886
- *
2887
- * ```ts
2888
- * staticDirs = ['./public'];
2889
- * staticDirs = [{ from: './public', to: '/assets' }];
2890
- * ```
2891
- */
2892
- staticDirs?: PresetValue<StorybookConfigRaw['staticDirs']>;
2893
- logLevel?: PresetValue<StorybookConfigRaw['logLevel']>;
2894
- features?: PresetValue<StorybookConfigRaw['features']>;
2895
- build?: PresetValue<StorybookConfigRaw['build']>;
2896
- /**
2897
- * Tells Storybook where to find stories.
2898
- *
2899
- * @example
2900
- *
2901
- * ```ts
2902
- * stories = ['./src/*.stories.@(j|t)sx?'];
2903
- * stories = async () => [...(await myCustomStoriesEntryBuilderFunc())];
2904
- * ```
2905
- */
2906
- stories: PresetValue<StorybookConfigRaw['stories']>;
2907
- /** Framework, e.g. '@storybook/react-vite', required in v7 */
2908
- framework?: StorybookConfigRaw['framework'];
2909
- /** Controls how Storybook handles TypeScript files. */
2910
- typescript?: PresetValue<StorybookConfigRaw['typescript']>;
2911
- /** References external Storybooks */
2912
- refs?: PresetValue<StorybookConfigRaw['refs']>;
2913
- /** Modify or return babel config. */
2914
- babel?: PresetValue<StorybookConfigRaw['babel']>;
2915
- /** Modify or return swc config. */
2916
- swc?: PresetValue<StorybookConfigRaw['swc']>;
2917
- /** Modify or return env config. */
2918
- env?: PresetValue<StorybookConfigRaw['env']>;
2919
- /** Modify or return babel config. */
2920
- babelDefault?: PresetValue<StorybookConfigRaw['babelDefault']>;
2921
- /** Add additional scripts to run in the preview a la `.storybook/preview.js` */
2922
- previewAnnotations?: PresetValue<StorybookConfigRaw['previewAnnotations']>;
2923
- /** Process CSF files for the story index. */
2924
- experimental_indexers?: PresetValue<StorybookConfigRaw['experimental_indexers']>;
2925
- /** Docs related features in index generation */
2926
- docs?: PresetValue<StorybookConfigRaw['docs']>;
2927
- /**
2928
- * Programmatically modify the preview head/body HTML. The previewHead and previewBody functions
2929
- * accept a string, which is the existing head/body, and return a modified string.
2930
- */
2931
- previewHead?: PresetValue<StorybookConfigRaw['previewHead']>;
2932
- previewBody?: PresetValue<StorybookConfigRaw['previewBody']>;
2933
- /**
2934
- * Programmatically override the preview's main page template. This should return a reference to a
2935
- * file containing an `.ejs` template that will be interpolated with environment variables.
2936
- *
2937
- * @example
2938
- *
2939
- * ```ts
2940
- * previewMainTemplate = '.storybook/index.ejs';
2941
- * ```
2942
- */
2943
- previewMainTemplate?: PresetValue<StorybookConfigRaw['previewMainTemplate']>;
2944
- /**
2945
- * Programmatically modify the preview head/body HTML. The managerHead function accept a string,
2946
- * which is the existing head content, and return a modified string.
2947
- */
2948
- managerHead?: PresetValue<StorybookConfigRaw['managerHead']>;
2949
- /** Configure non-standard tag behaviors */
2950
- tags?: PresetValue<StorybookConfigRaw['tags']>;
2951
- }
2952
- type PresetValue<T> = T | ((config: T, options: Options) => T | Promise<T>);
2953
- type Addon_Comparator<T> = ((a: T, b: T) => boolean) | ((a: T, b: T) => number);
2954
- type Addon_StorySortMethod = 'configure' | 'alphabetical';
2955
- interface Addon_StorySortObjectParameter {
2956
- method?: Addon_StorySortMethod;
2957
- order?: any[];
2958
- locales?: string;
2959
- includeNames?: boolean;
2960
- }
2961
- type Addon_StorySortComparatorV7 = Addon_Comparator<IndexEntry>;
2962
- type Addon_StorySortParameterV7 = Addon_StorySortComparatorV7 | Addon_StorySortObjectParameter;
2963
- interface Addon_OptionsParameterV7 extends Object {
2964
- storySort?: Addon_StorySortParameterV7;
2965
- theme?: {
2966
- base: string;
2967
- brandTitle?: string;
2968
- };
2969
- [key: string]: any;
2970
- }
2971
- type Layout = 'centered' | 'fullscreen' | 'padded' | 'none';
2972
- interface StorybookParameters {
2973
- options?: Addon_OptionsParameterV7;
2974
- /**
2975
- * The layout property defines basic styles added to the preview body where the story is rendered.
2976
- *
2977
- * If you pass `none`, no styles are applied.
2978
- */
2979
- layout?: Layout;
2980
- }
2981
- interface StorybookTypes {
2982
- parameters: StorybookParameters;
2983
- }
2984
- type Path = string;
2985
- type MaybePromise<T> = Promise<T> | T;
2986
- type TeardownRenderToCanvas = () => MaybePromise<void>;
2987
- type RenderToCanvas<TRenderer extends Renderer> = (context: RenderContext<TRenderer>, element: TRenderer['canvasElement']) => MaybePromise<void | TeardownRenderToCanvas>;
2988
- interface ProjectAnnotations<TRenderer extends Renderer> extends ProjectAnnotations$1<TRenderer> {
2989
- testingLibraryRender?: (...args: never[]) => {
2990
- unmount: () => void;
2991
- };
2992
- renderToCanvas?: RenderToCanvas<TRenderer>;
2993
- }
2994
- type NormalizedProjectAnnotations<TRenderer extends Renderer = Renderer> = Omit<ProjectAnnotations<TRenderer>, 'decorators' | 'loaders' | 'runStep' | 'beforeAll'> & {
2995
- argTypes?: StrictArgTypes;
2996
- globalTypes?: StrictGlobalTypes;
2997
- decorators?: DecoratorFunction<TRenderer>[];
2998
- loaders?: LoaderFunction$2<TRenderer>[];
2999
- runStep: StepRunner<TRenderer>;
3000
- beforeAll: BeforeAll;
3001
- };
3002
- declare type RenderContext<TRenderer extends Renderer = Renderer> = StoryIdentifier & {
3003
- showMain: () => void;
3004
- showError: (error: {
3005
- title: string;
3006
- description: string;
3007
- }) => void;
3008
- showException: (err: Error) => void;
3009
- forceRemount: boolean;
3010
- storyContext: StoryContext<TRenderer>;
3011
- storyFn: PartialStoryFn<TRenderer>;
3012
- unboundStoryFn: LegacyStoryFn<TRenderer>;
3013
- };
3014
-
3015
- declare global {
3016
- var globalProjectAnnotations: NormalizedProjectAnnotations<any>;
3017
- var defaultProjectAnnotations: ProjectAnnotations<any>;
3018
- }
3019
- type WrappedStoryRef = {
3020
- __pw_type: 'jsx';
3021
- props: Record<string, any>;
3022
- } | {
3023
- __pw_type: 'importRef';
3024
- };
3025
- type UnwrappedJSXStoryRef = {
3026
- __pw_type: 'jsx';
3027
- type: UnwrappedImportStoryRef;
3028
- };
3029
- type UnwrappedImportStoryRef = ComposedStoryFn;
3030
- declare global {
3031
- function __pwUnwrapObject(storyRef: WrappedStoryRef): Promise<UnwrappedJSXStoryRef | UnwrappedImportStoryRef>;
3032
- }
3033
-
3034
- interface Report<T = unknown> {
3035
- type: string;
3036
- version?: number;
3037
- result: T;
3038
- status: 'failed' | 'passed' | 'warning';
3039
- }
3040
- declare class ReporterAPI {
3041
- reports: Report[];
3042
- addReport(report: Report): Promise<void>;
3043
- }
3044
- /** A story function with partial args, used internally by composeStory */
3045
- type PartialArgsStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (args?: TArgs) => (TRenderer & {
3046
- T: TArgs;
3047
- })['storyResult'];
3048
- /**
3049
- * A story that got recomposed for portable stories, containing all the necessary data to be
3050
- * rendered in external environments
3051
- */
3052
- type ComposedStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = PartialArgsStoryFn<TRenderer, TArgs> & {
3053
- args: TArgs;
3054
- id: StoryId;
3055
- play?: (context?: Partial<StoryContext<TRenderer, Partial<TArgs>>>) => Promise<void>;
3056
- run: (context?: Partial<StoryContext<TRenderer, Partial<TArgs>>>) => Promise<void>;
3057
- load: () => Promise<void>;
3058
- storyName: string;
3059
- parameters: Parameters;
3060
- argTypes: StrictArgTypes<TArgs>;
3061
- reporting: ReporterAPI;
3062
- tags: Tag$1[];
3063
- globals: Globals;
3064
- };
1
+ import { StorybookConfig as StorybookConfig$1, Options, NormalizedStoriesSpecifier } from 'storybook/internal/types';
2
+ export { BuilderResult, Options, Preset, TypescriptOptions } from 'storybook/internal/types';
3065
3
 
3066
4
  type RulesConfig = any;
3067
5
  type ModuleConfig = {
@@ -3093,7 +31,7 @@ type StorybookConfig<TWebpackConfiguration = WebpackConfiguration> = StorybookCo
3093
31
  webpackFinal?: (config: TWebpackConfiguration, options: Options) => TWebpackConfiguration | Promise<TWebpackConfiguration>;
3094
32
  };
3095
33
 
3096
- declare const loadCustomWebpackConfig: (configDir: string) => any;
34
+ declare const loadCustomWebpackConfig: (configDir: string) => Promise<any>;
3097
35
 
3098
36
  declare const checkWebpackVersion: (webpack: {
3099
37
  version?: string;
@@ -3115,4 +53,4 @@ declare const toRequireContext: (specifier: NormalizedStoriesSpecifier) => {
3115
53
  declare const toRequireContextString: (specifier: NormalizedStoriesSpecifier) => string;
3116
54
 
3117
55
  export { checkWebpackVersion, loadCustomWebpackConfig, mergeConfigs, toImportFn, toImportFnPart, toRequireContext, toRequireContextString, webpackIncludeRegexp };
3118
- export type { BuilderOptions, BuilderResult, ModuleConfig, Options, Preset, ResolveConfig, RulesConfig, StorybookConfig, TypescriptOptions, WebpackConfiguration };
56
+ export type { BuilderOptions, ModuleConfig, ResolveConfig, RulesConfig, StorybookConfig, WebpackConfiguration };