storybook 9.0.0-beta.9 → 9.0.0-rc.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.
Files changed (72) hide show
  1. package/assets/server/base-preview-head.html +21 -0
  2. package/assets/server/template.ejs +4 -4
  3. package/dist/actions/preview.cjs +1 -1
  4. package/dist/actions/preview.d.ts +501 -0
  5. package/dist/actions/preview.js +1 -1
  6. package/dist/backgrounds/index.d.ts +501 -0
  7. package/dist/backgrounds/preview.d.ts +501 -0
  8. package/dist/bin/index.cjs +61 -62
  9. package/dist/bin/index.js +61 -62
  10. package/dist/builder-manager/index.cjs +27 -27
  11. package/dist/builder-manager/index.js +46 -46
  12. package/dist/cli/bin/index.cjs +1032 -1032
  13. package/dist/cli/bin/index.js +1032 -1032
  14. package/dist/cli/index.cjs +33709 -28783
  15. package/dist/cli/index.js +33641 -28711
  16. package/dist/common/index.cjs +3060 -3048
  17. package/dist/common/index.d.ts +2 -2
  18. package/dist/common/index.js +3247 -3235
  19. package/dist/components/index.cjs +711 -711
  20. package/dist/components/index.d.ts +2 -1
  21. package/dist/components/index.js +15 -15
  22. package/dist/controls/preview.d.ts +501 -0
  23. package/dist/core-events/index.cjs +55 -52
  24. package/dist/core-events/index.d.ts +3 -1
  25. package/dist/core-events/index.js +52 -49
  26. package/dist/core-server/index.cjs +12 -12
  27. package/dist/core-server/index.d.ts +512 -11
  28. package/dist/core-server/index.js +12 -12
  29. package/dist/core-server/presets/common-manager.js +4563 -5786
  30. package/dist/core-server/presets/common-override-preset.cjs +10 -12
  31. package/dist/core-server/presets/common-override-preset.js +3 -5
  32. package/dist/core-server/presets/common-preset.cjs +112 -116
  33. package/dist/core-server/presets/common-preset.js +10 -14
  34. package/dist/csf/index.d.ts +1 -1
  35. package/dist/csf-tools/index.cjs +116 -111
  36. package/dist/csf-tools/index.js +33 -28
  37. package/dist/docs-tools/index.d.ts +1 -1
  38. package/dist/highlight/preview.d.ts +501 -0
  39. package/dist/instrumenter/index.js +1849 -3547
  40. package/dist/manager/globals-module-info.cjs +3 -0
  41. package/dist/manager/globals-module-info.js +3 -0
  42. package/dist/manager/globals-runtime.js +21082 -22647
  43. package/dist/manager/runtime.js +2468 -2449
  44. package/dist/manager-api/index.cjs +2302 -8594
  45. package/dist/manager-api/index.d.ts +501 -0
  46. package/dist/manager-api/index.js +2602 -2631
  47. package/dist/measure/index.d.ts +501 -0
  48. package/dist/measure/preview.d.ts +501 -0
  49. package/dist/outline/index.d.ts +501 -0
  50. package/dist/outline/preview.d.ts +501 -0
  51. package/dist/preview/runtime.js +38420 -40024
  52. package/dist/preview-api/index.cjs +1546 -1459
  53. package/dist/preview-api/index.d.ts +8 -5
  54. package/dist/preview-api/index.js +1267 -1181
  55. package/dist/router/index.cjs +5700 -2327
  56. package/dist/router/index.d.ts +622 -243
  57. package/dist/router/index.js +1297 -870
  58. package/dist/test/index.cjs +1810 -1811
  59. package/dist/test/index.d.ts +53 -5
  60. package/dist/test/index.js +1907 -1908
  61. package/dist/test/preview.cjs +51 -15860
  62. package/dist/test/preview.d.ts +520 -13
  63. package/dist/test/preview.js +44 -14431
  64. package/dist/theming/index.cjs +17 -0
  65. package/dist/theming/index.js +17 -0
  66. package/dist/types/index.d.ts +516 -82
  67. package/dist/viewport/index.d.ts +502 -3
  68. package/dist/viewport/preview.d.ts +501 -0
  69. package/package.json +2 -18
  70. package/dist/test/spy.cjs +0 -258
  71. package/dist/test/spy.d.ts +0 -62
  72. package/dist/test/spy.js +0 -240
@@ -2,6 +2,507 @@ import * as storybook_internal_csf from 'storybook/internal/csf';
2
2
  import { Renderer as Renderer$1, ProjectAnnotations as ProjectAnnotations$1, StoryIdentifier, StoryContext, PartialStoryFn, LegacyStoryFn } from 'storybook/internal/csf';
3
3
  import { NormalizedProjectAnnotations, ProjectAnnotations as ProjectAnnotations$2, ComposedStoryFn } from 'storybook/internal/types';
4
4
 
5
+ /**
6
+ * Actions represent the type of change to a location value.
7
+ */
8
+ declare enum Action {
9
+ /**
10
+ * A POP indicates a change to an arbitrary index in the history stack, such
11
+ * as a back or forward navigation. It does not describe the direction of the
12
+ * navigation, only that the current index changed.
13
+ *
14
+ * Note: This is the default action for newly created history objects.
15
+ */
16
+ Pop = "POP",
17
+ /**
18
+ * A PUSH indicates a new entry being added to the history stack, such as when
19
+ * a link is clicked and a new page loads. When this happens, all subsequent
20
+ * entries in the stack are lost.
21
+ */
22
+ Push = "PUSH",
23
+ /**
24
+ * A REPLACE indicates the entry at the current index in the history stack
25
+ * being replaced by a new one.
26
+ */
27
+ Replace = "REPLACE"
28
+ }
29
+ /**
30
+ * The pathname, search, and hash values of a URL.
31
+ */
32
+ interface Path {
33
+ /**
34
+ * A URL pathname, beginning with a /.
35
+ */
36
+ pathname: string;
37
+ /**
38
+ * A URL search string, beginning with a ?.
39
+ */
40
+ search: string;
41
+ /**
42
+ * A URL fragment identifier, beginning with a #.
43
+ */
44
+ hash: string;
45
+ }
46
+ /**
47
+ * An entry in a history stack. A location contains information about the
48
+ * URL path, as well as possibly some arbitrary state and a key.
49
+ */
50
+ interface Location extends Path {
51
+ /**
52
+ * A value of arbitrary data associated with this location.
53
+ */
54
+ state: any;
55
+ /**
56
+ * A unique string associated with this location. May be used to safely store
57
+ * and retrieve data in some other storage API, like `localStorage`.
58
+ *
59
+ * Note: This value is always "default" on the initial location.
60
+ */
61
+ key: string;
62
+ }
63
+
64
+ /**
65
+ * Map of routeId -> data returned from a loader/action/error
66
+ */
67
+ interface RouteData {
68
+ [routeId: string]: any;
69
+ }
70
+ declare enum ResultType {
71
+ data = "data",
72
+ deferred = "deferred",
73
+ redirect = "redirect",
74
+ error = "error"
75
+ }
76
+ /**
77
+ * Successful result from a loader or action
78
+ */
79
+ interface SuccessResult {
80
+ type: ResultType.data;
81
+ data: any;
82
+ statusCode?: number;
83
+ headers?: Headers;
84
+ }
85
+ /**
86
+ * Successful defer() result from a loader or action
87
+ */
88
+ interface DeferredResult {
89
+ type: ResultType.deferred;
90
+ deferredData: DeferredData;
91
+ statusCode?: number;
92
+ headers?: Headers;
93
+ }
94
+ /**
95
+ * Redirect result from a loader or action
96
+ */
97
+ interface RedirectResult {
98
+ type: ResultType.redirect;
99
+ status: number;
100
+ location: string;
101
+ revalidate: boolean;
102
+ reloadDocument?: boolean;
103
+ }
104
+ /**
105
+ * Unsuccessful result from a loader or action
106
+ */
107
+ interface ErrorResult {
108
+ type: ResultType.error;
109
+ error: any;
110
+ headers?: Headers;
111
+ }
112
+ /**
113
+ * Result from a loader or action - potentially successful or unsuccessful
114
+ */
115
+ type DataResult = SuccessResult | DeferredResult | RedirectResult | ErrorResult;
116
+ type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
117
+ type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
118
+ /**
119
+ * Active navigation/fetcher form methods are exposed in lowercase on the
120
+ * RouterState
121
+ */
122
+ type FormMethod = LowerCaseFormMethod;
123
+ /**
124
+ * In v7, active navigation/fetcher form methods are exposed in uppercase on the
125
+ * RouterState. This is to align with the normalization done via fetch().
126
+ */
127
+ type V7_FormMethod = UpperCaseFormMethod;
128
+ type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
129
+ type JsonObject = {
130
+ [Key in string]: JsonValue;
131
+ } & {
132
+ [Key in string]?: JsonValue | undefined;
133
+ };
134
+ type JsonArray = JsonValue[] | readonly JsonValue[];
135
+ type JsonPrimitive = string | number | boolean | null;
136
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
137
+ /**
138
+ * @private
139
+ * Internal interface to pass around for action submissions, not intended for
140
+ * external consumption
141
+ */
142
+ type Submission = {
143
+ formMethod: FormMethod | V7_FormMethod;
144
+ formAction: string;
145
+ formEncType: FormEncType;
146
+ formData: FormData;
147
+ json: undefined;
148
+ text: undefined;
149
+ } | {
150
+ formMethod: FormMethod | V7_FormMethod;
151
+ formAction: string;
152
+ formEncType: FormEncType;
153
+ formData: undefined;
154
+ json: JsonValue;
155
+ text: undefined;
156
+ } | {
157
+ formMethod: FormMethod | V7_FormMethod;
158
+ formAction: string;
159
+ formEncType: FormEncType;
160
+ formData: undefined;
161
+ json: undefined;
162
+ text: string;
163
+ };
164
+ /**
165
+ * @private
166
+ * Arguments passed to route loader/action functions. Same for now but we keep
167
+ * this as a private implementation detail in case they diverge in the future.
168
+ */
169
+ interface DataFunctionArgs {
170
+ request: Request;
171
+ params: Params;
172
+ context?: any;
173
+ }
174
+ /**
175
+ * Arguments passed to loader functions
176
+ */
177
+ interface LoaderFunctionArgs extends DataFunctionArgs {
178
+ }
179
+ /**
180
+ * Arguments passed to action functions
181
+ */
182
+ interface ActionFunctionArgs extends DataFunctionArgs {
183
+ }
184
+ /**
185
+ * Loaders and actions can return anything except `undefined` (`null` is a
186
+ * valid return value if there is no data to return). Responses are preferred
187
+ * and will ease any future migration to Remix
188
+ */
189
+ type DataFunctionValue = Response | NonNullable<unknown> | null;
190
+ /**
191
+ * Route loader function signature
192
+ */
193
+ interface LoaderFunction {
194
+ (args: LoaderFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
195
+ }
196
+ /**
197
+ * Route action function signature
198
+ */
199
+ interface ActionFunction {
200
+ (args: ActionFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
201
+ }
202
+ /**
203
+ * Route shouldRevalidate function signature. This runs after any submission
204
+ * (navigation or fetcher), so we flatten the navigation/fetcher submission
205
+ * onto the arguments. It shouldn't matter whether it came from a navigation
206
+ * or a fetcher, what really matters is the URLs and the formData since loaders
207
+ * have to re-run based on the data models that were potentially mutated.
208
+ */
209
+ interface ShouldRevalidateFunction {
210
+ (args: {
211
+ currentUrl: URL;
212
+ currentParams: AgnosticDataRouteMatch["params"];
213
+ nextUrl: URL;
214
+ nextParams: AgnosticDataRouteMatch["params"];
215
+ formMethod?: Submission["formMethod"];
216
+ formAction?: Submission["formAction"];
217
+ formEncType?: Submission["formEncType"];
218
+ text?: Submission["text"];
219
+ formData?: Submission["formData"];
220
+ json?: Submission["json"];
221
+ actionResult?: DataResult;
222
+ defaultShouldRevalidate: boolean;
223
+ }): boolean;
224
+ }
225
+ /**
226
+ * Keys we cannot change from within a lazy() function. We spread all other keys
227
+ * onto the route. Either they're meaningful to the router, or they'll get
228
+ * ignored.
229
+ */
230
+ type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
231
+ type RequireOne<T, Key = keyof T> = Exclude<{
232
+ [K in keyof T]: K extends Key ? Omit<T, K> & Required<Pick<T, K>> : never;
233
+ }[keyof T], undefined>;
234
+ /**
235
+ * lazy() function to load a route definition, which can add non-matching
236
+ * related properties to a route
237
+ */
238
+ interface LazyRouteFunction<R extends AgnosticRouteObject> {
239
+ (): Promise<RequireOne<Omit<R, ImmutableRouteKey>>>;
240
+ }
241
+ /**
242
+ * Base RouteObject with common props shared by all types of routes
243
+ */
244
+ type AgnosticBaseRouteObject = {
245
+ caseSensitive?: boolean;
246
+ path?: string;
247
+ id?: string;
248
+ loader?: LoaderFunction;
249
+ action?: ActionFunction;
250
+ hasErrorBoundary?: boolean;
251
+ shouldRevalidate?: ShouldRevalidateFunction;
252
+ handle?: any;
253
+ lazy?: LazyRouteFunction<AgnosticBaseRouteObject>;
254
+ };
255
+ /**
256
+ * Index routes must not have children
257
+ */
258
+ type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
259
+ children?: undefined;
260
+ index: true;
261
+ };
262
+ /**
263
+ * Non-index routes may have children, but cannot have index
264
+ */
265
+ type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
266
+ children?: AgnosticRouteObject[];
267
+ index?: false;
268
+ };
269
+ /**
270
+ * A route object represents a logical route, with (optionally) its child
271
+ * routes organized in a tree-like structure.
272
+ */
273
+ type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
274
+ type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
275
+ id: string;
276
+ };
277
+ type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
278
+ children?: AgnosticDataRouteObject[];
279
+ id: string;
280
+ };
281
+ /**
282
+ * A data route object, which is just a RouteObject with a required unique ID
283
+ */
284
+ type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
285
+ /**
286
+ * The parameters that were parsed from the URL path.
287
+ */
288
+ type Params<Key extends string = string> = {
289
+ readonly [key in Key]: string | undefined;
290
+ };
291
+ /**
292
+ * A RouteMatch contains info about how a route matched a URL.
293
+ */
294
+ interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
295
+ /**
296
+ * The names and values of dynamic parameters in the URL.
297
+ */
298
+ params: Params<ParamKey>;
299
+ /**
300
+ * The portion of the URL pathname that was matched.
301
+ */
302
+ pathname: string;
303
+ /**
304
+ * The portion of the URL pathname that was matched before child routes.
305
+ */
306
+ pathnameBase: string;
307
+ /**
308
+ * The route object that was used to match.
309
+ */
310
+ route: RouteObjectType;
311
+ }
312
+ interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
313
+ }
314
+ declare class DeferredData {
315
+ private pendingKeysSet;
316
+ private controller;
317
+ private abortPromise;
318
+ private unlistenAbortSignal;
319
+ private subscribers;
320
+ data: Record<string, unknown>;
321
+ init?: ResponseInit;
322
+ deferredKeys: string[];
323
+ constructor(data: Record<string, unknown>, responseInit?: ResponseInit);
324
+ private trackPromise;
325
+ private onSettle;
326
+ private emit;
327
+ subscribe(fn: (aborted: boolean, settledKey?: string) => void): () => boolean;
328
+ cancel(): void;
329
+ resolveData(signal: AbortSignal): Promise<boolean>;
330
+ get done(): boolean;
331
+ get unwrappedData(): {};
332
+ get pendingKeys(): string[];
333
+ }
334
+
335
+ /**
336
+ * State maintained internally by the router. During a navigation, all states
337
+ * reflect the the "old" location unless otherwise noted.
338
+ */
339
+ interface RouterState {
340
+ /**
341
+ * The action of the most recent navigation
342
+ */
343
+ historyAction: Action;
344
+ /**
345
+ * The current location reflected by the router
346
+ */
347
+ location: Location;
348
+ /**
349
+ * The current set of route matches
350
+ */
351
+ matches: AgnosticDataRouteMatch[];
352
+ /**
353
+ * Tracks whether we've completed our initial data load
354
+ */
355
+ initialized: boolean;
356
+ /**
357
+ * Current scroll position we should start at for a new view
358
+ * - number -> scroll position to restore to
359
+ * - false -> do not restore scroll at all (used during submissions)
360
+ * - null -> don't have a saved position, scroll to hash or top of page
361
+ */
362
+ restoreScrollPosition: number | false | null;
363
+ /**
364
+ * Indicate whether this navigation should skip resetting the scroll position
365
+ * if we are unable to restore the scroll position
366
+ */
367
+ preventScrollReset: boolean;
368
+ /**
369
+ * Tracks the state of the current navigation
370
+ */
371
+ navigation: Navigation;
372
+ /**
373
+ * Tracks any in-progress revalidations
374
+ */
375
+ revalidation: RevalidationState;
376
+ /**
377
+ * Data from the loaders for the current matches
378
+ */
379
+ loaderData: RouteData;
380
+ /**
381
+ * Data from the action for the current matches
382
+ */
383
+ actionData: RouteData | null;
384
+ /**
385
+ * Errors caught from loaders for the current matches
386
+ */
387
+ errors: RouteData | null;
388
+ /**
389
+ * Map of current fetchers
390
+ */
391
+ fetchers: Map<string, Fetcher>;
392
+ /**
393
+ * Map of current blockers
394
+ */
395
+ blockers: Map<string, Blocker>;
396
+ }
397
+ /**
398
+ * Data that can be passed into hydrate a Router from SSR
399
+ */
400
+ type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
401
+ /**
402
+ * Potential states for state.navigation
403
+ */
404
+ type NavigationStates = {
405
+ Idle: {
406
+ state: "idle";
407
+ location: undefined;
408
+ formMethod: undefined;
409
+ formAction: undefined;
410
+ formEncType: undefined;
411
+ formData: undefined;
412
+ json: undefined;
413
+ text: undefined;
414
+ };
415
+ Loading: {
416
+ state: "loading";
417
+ location: Location;
418
+ formMethod: Submission["formMethod"] | undefined;
419
+ formAction: Submission["formAction"] | undefined;
420
+ formEncType: Submission["formEncType"] | undefined;
421
+ formData: Submission["formData"] | undefined;
422
+ json: Submission["json"] | undefined;
423
+ text: Submission["text"] | undefined;
424
+ };
425
+ Submitting: {
426
+ state: "submitting";
427
+ location: Location;
428
+ formMethod: Submission["formMethod"];
429
+ formAction: Submission["formAction"];
430
+ formEncType: Submission["formEncType"];
431
+ formData: Submission["formData"];
432
+ json: Submission["json"];
433
+ text: Submission["text"];
434
+ };
435
+ };
436
+ type Navigation = NavigationStates[keyof NavigationStates];
437
+ type RevalidationState = "idle" | "loading";
438
+ /**
439
+ * Potential states for fetchers
440
+ */
441
+ type FetcherStates<TData = any> = {
442
+ Idle: {
443
+ state: "idle";
444
+ formMethod: undefined;
445
+ formAction: undefined;
446
+ formEncType: undefined;
447
+ text: undefined;
448
+ formData: undefined;
449
+ json: undefined;
450
+ data: TData | undefined;
451
+ " _hasFetcherDoneAnything "?: boolean;
452
+ };
453
+ Loading: {
454
+ state: "loading";
455
+ formMethod: Submission["formMethod"] | undefined;
456
+ formAction: Submission["formAction"] | undefined;
457
+ formEncType: Submission["formEncType"] | undefined;
458
+ text: Submission["text"] | undefined;
459
+ formData: Submission["formData"] | undefined;
460
+ json: Submission["json"] | undefined;
461
+ data: TData | undefined;
462
+ " _hasFetcherDoneAnything "?: boolean;
463
+ };
464
+ Submitting: {
465
+ state: "submitting";
466
+ formMethod: Submission["formMethod"];
467
+ formAction: Submission["formAction"];
468
+ formEncType: Submission["formEncType"];
469
+ text: Submission["text"];
470
+ formData: Submission["formData"];
471
+ json: Submission["json"];
472
+ data: TData | undefined;
473
+ " _hasFetcherDoneAnything "?: boolean;
474
+ };
475
+ };
476
+ type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
477
+ interface BlockerBlocked {
478
+ state: "blocked";
479
+ reset(): void;
480
+ proceed(): void;
481
+ location: Location;
482
+ }
483
+ interface BlockerUnblocked {
484
+ state: "unblocked";
485
+ reset: undefined;
486
+ proceed: undefined;
487
+ location: undefined;
488
+ }
489
+ interface BlockerProceeding {
490
+ state: "proceeding";
491
+ reset: undefined;
492
+ proceed: undefined;
493
+ location: Location;
494
+ }
495
+ type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
496
+
497
+ /**
498
+ * NOTE: If you refactor this to split up the modules into separate files,
499
+ * you'll need to update the rollup config for react-router-dom-v5-compat.
500
+ */
501
+
502
+ declare global {
503
+ var __staticRouterHydrationData: HydrationState | undefined;
504
+ }
505
+
5
506
  declare global {
6
507
  interface SymbolConstructor {
7
508
  readonly observable: symbol;