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
@@ -55,9 +55,7 @@ interface ViewportGlobals {
55
55
  *
56
56
  * @see https://storybook.js.org/docs/essentials/viewport#globals
57
57
  */
58
- viewport: {
59
- [key: string]: GlobalState | GlobalState['value'];
60
- };
58
+ viewport: GlobalState | GlobalState['value'];
61
59
  }
62
60
 
63
61
  declare const INITIAL_VIEWPORTS_DATA: {
@@ -291,6 +289,507 @@ declare const INITIAL_VIEWPORTS: ViewportMap;
291
289
  declare const DEFAULT_VIEWPORT = "responsive";
292
290
  declare const MINIMAL_VIEWPORTS: ViewportMap;
293
291
 
292
+ /**
293
+ * Actions represent the type of change to a location value.
294
+ */
295
+ declare enum Action {
296
+ /**
297
+ * A POP indicates a change to an arbitrary index in the history stack, such
298
+ * as a back or forward navigation. It does not describe the direction of the
299
+ * navigation, only that the current index changed.
300
+ *
301
+ * Note: This is the default action for newly created history objects.
302
+ */
303
+ Pop = "POP",
304
+ /**
305
+ * A PUSH indicates a new entry being added to the history stack, such as when
306
+ * a link is clicked and a new page loads. When this happens, all subsequent
307
+ * entries in the stack are lost.
308
+ */
309
+ Push = "PUSH",
310
+ /**
311
+ * A REPLACE indicates the entry at the current index in the history stack
312
+ * being replaced by a new one.
313
+ */
314
+ Replace = "REPLACE"
315
+ }
316
+ /**
317
+ * The pathname, search, and hash values of a URL.
318
+ */
319
+ interface Path {
320
+ /**
321
+ * A URL pathname, beginning with a /.
322
+ */
323
+ pathname: string;
324
+ /**
325
+ * A URL search string, beginning with a ?.
326
+ */
327
+ search: string;
328
+ /**
329
+ * A URL fragment identifier, beginning with a #.
330
+ */
331
+ hash: string;
332
+ }
333
+ /**
334
+ * An entry in a history stack. A location contains information about the
335
+ * URL path, as well as possibly some arbitrary state and a key.
336
+ */
337
+ interface Location extends Path {
338
+ /**
339
+ * A value of arbitrary data associated with this location.
340
+ */
341
+ state: any;
342
+ /**
343
+ * A unique string associated with this location. May be used to safely store
344
+ * and retrieve data in some other storage API, like `localStorage`.
345
+ *
346
+ * Note: This value is always "default" on the initial location.
347
+ */
348
+ key: string;
349
+ }
350
+
351
+ /**
352
+ * Map of routeId -> data returned from a loader/action/error
353
+ */
354
+ interface RouteData {
355
+ [routeId: string]: any;
356
+ }
357
+ declare enum ResultType {
358
+ data = "data",
359
+ deferred = "deferred",
360
+ redirect = "redirect",
361
+ error = "error"
362
+ }
363
+ /**
364
+ * Successful result from a loader or action
365
+ */
366
+ interface SuccessResult {
367
+ type: ResultType.data;
368
+ data: any;
369
+ statusCode?: number;
370
+ headers?: Headers;
371
+ }
372
+ /**
373
+ * Successful defer() result from a loader or action
374
+ */
375
+ interface DeferredResult {
376
+ type: ResultType.deferred;
377
+ deferredData: DeferredData;
378
+ statusCode?: number;
379
+ headers?: Headers;
380
+ }
381
+ /**
382
+ * Redirect result from a loader or action
383
+ */
384
+ interface RedirectResult {
385
+ type: ResultType.redirect;
386
+ status: number;
387
+ location: string;
388
+ revalidate: boolean;
389
+ reloadDocument?: boolean;
390
+ }
391
+ /**
392
+ * Unsuccessful result from a loader or action
393
+ */
394
+ interface ErrorResult {
395
+ type: ResultType.error;
396
+ error: any;
397
+ headers?: Headers;
398
+ }
399
+ /**
400
+ * Result from a loader or action - potentially successful or unsuccessful
401
+ */
402
+ type DataResult = SuccessResult | DeferredResult | RedirectResult | ErrorResult;
403
+ type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
404
+ type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
405
+ /**
406
+ * Active navigation/fetcher form methods are exposed in lowercase on the
407
+ * RouterState
408
+ */
409
+ type FormMethod = LowerCaseFormMethod;
410
+ /**
411
+ * In v7, active navigation/fetcher form methods are exposed in uppercase on the
412
+ * RouterState. This is to align with the normalization done via fetch().
413
+ */
414
+ type V7_FormMethod = UpperCaseFormMethod;
415
+ type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
416
+ type JsonObject = {
417
+ [Key in string]: JsonValue;
418
+ } & {
419
+ [Key in string]?: JsonValue | undefined;
420
+ };
421
+ type JsonArray = JsonValue[] | readonly JsonValue[];
422
+ type JsonPrimitive = string | number | boolean | null;
423
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
424
+ /**
425
+ * @private
426
+ * Internal interface to pass around for action submissions, not intended for
427
+ * external consumption
428
+ */
429
+ type Submission = {
430
+ formMethod: FormMethod | V7_FormMethod;
431
+ formAction: string;
432
+ formEncType: FormEncType;
433
+ formData: FormData;
434
+ json: undefined;
435
+ text: undefined;
436
+ } | {
437
+ formMethod: FormMethod | V7_FormMethod;
438
+ formAction: string;
439
+ formEncType: FormEncType;
440
+ formData: undefined;
441
+ json: JsonValue;
442
+ text: undefined;
443
+ } | {
444
+ formMethod: FormMethod | V7_FormMethod;
445
+ formAction: string;
446
+ formEncType: FormEncType;
447
+ formData: undefined;
448
+ json: undefined;
449
+ text: string;
450
+ };
451
+ /**
452
+ * @private
453
+ * Arguments passed to route loader/action functions. Same for now but we keep
454
+ * this as a private implementation detail in case they diverge in the future.
455
+ */
456
+ interface DataFunctionArgs {
457
+ request: Request;
458
+ params: Params;
459
+ context?: any;
460
+ }
461
+ /**
462
+ * Arguments passed to loader functions
463
+ */
464
+ interface LoaderFunctionArgs extends DataFunctionArgs {
465
+ }
466
+ /**
467
+ * Arguments passed to action functions
468
+ */
469
+ interface ActionFunctionArgs extends DataFunctionArgs {
470
+ }
471
+ /**
472
+ * Loaders and actions can return anything except `undefined` (`null` is a
473
+ * valid return value if there is no data to return). Responses are preferred
474
+ * and will ease any future migration to Remix
475
+ */
476
+ type DataFunctionValue = Response | NonNullable<unknown> | null;
477
+ /**
478
+ * Route loader function signature
479
+ */
480
+ interface LoaderFunction {
481
+ (args: LoaderFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
482
+ }
483
+ /**
484
+ * Route action function signature
485
+ */
486
+ interface ActionFunction {
487
+ (args: ActionFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
488
+ }
489
+ /**
490
+ * Route shouldRevalidate function signature. This runs after any submission
491
+ * (navigation or fetcher), so we flatten the navigation/fetcher submission
492
+ * onto the arguments. It shouldn't matter whether it came from a navigation
493
+ * or a fetcher, what really matters is the URLs and the formData since loaders
494
+ * have to re-run based on the data models that were potentially mutated.
495
+ */
496
+ interface ShouldRevalidateFunction {
497
+ (args: {
498
+ currentUrl: URL;
499
+ currentParams: AgnosticDataRouteMatch["params"];
500
+ nextUrl: URL;
501
+ nextParams: AgnosticDataRouteMatch["params"];
502
+ formMethod?: Submission["formMethod"];
503
+ formAction?: Submission["formAction"];
504
+ formEncType?: Submission["formEncType"];
505
+ text?: Submission["text"];
506
+ formData?: Submission["formData"];
507
+ json?: Submission["json"];
508
+ actionResult?: DataResult;
509
+ defaultShouldRevalidate: boolean;
510
+ }): boolean;
511
+ }
512
+ /**
513
+ * Keys we cannot change from within a lazy() function. We spread all other keys
514
+ * onto the route. Either they're meaningful to the router, or they'll get
515
+ * ignored.
516
+ */
517
+ type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
518
+ type RequireOne<T, Key = keyof T> = Exclude<{
519
+ [K in keyof T]: K extends Key ? Omit<T, K> & Required<Pick<T, K>> : never;
520
+ }[keyof T], undefined>;
521
+ /**
522
+ * lazy() function to load a route definition, which can add non-matching
523
+ * related properties to a route
524
+ */
525
+ interface LazyRouteFunction<R extends AgnosticRouteObject> {
526
+ (): Promise<RequireOne<Omit<R, ImmutableRouteKey>>>;
527
+ }
528
+ /**
529
+ * Base RouteObject with common props shared by all types of routes
530
+ */
531
+ type AgnosticBaseRouteObject = {
532
+ caseSensitive?: boolean;
533
+ path?: string;
534
+ id?: string;
535
+ loader?: LoaderFunction;
536
+ action?: ActionFunction;
537
+ hasErrorBoundary?: boolean;
538
+ shouldRevalidate?: ShouldRevalidateFunction;
539
+ handle?: any;
540
+ lazy?: LazyRouteFunction<AgnosticBaseRouteObject>;
541
+ };
542
+ /**
543
+ * Index routes must not have children
544
+ */
545
+ type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
546
+ children?: undefined;
547
+ index: true;
548
+ };
549
+ /**
550
+ * Non-index routes may have children, but cannot have index
551
+ */
552
+ type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
553
+ children?: AgnosticRouteObject[];
554
+ index?: false;
555
+ };
556
+ /**
557
+ * A route object represents a logical route, with (optionally) its child
558
+ * routes organized in a tree-like structure.
559
+ */
560
+ type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
561
+ type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
562
+ id: string;
563
+ };
564
+ type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
565
+ children?: AgnosticDataRouteObject[];
566
+ id: string;
567
+ };
568
+ /**
569
+ * A data route object, which is just a RouteObject with a required unique ID
570
+ */
571
+ type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
572
+ /**
573
+ * The parameters that were parsed from the URL path.
574
+ */
575
+ type Params<Key extends string = string> = {
576
+ readonly [key in Key]: string | undefined;
577
+ };
578
+ /**
579
+ * A RouteMatch contains info about how a route matched a URL.
580
+ */
581
+ interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
582
+ /**
583
+ * The names and values of dynamic parameters in the URL.
584
+ */
585
+ params: Params<ParamKey>;
586
+ /**
587
+ * The portion of the URL pathname that was matched.
588
+ */
589
+ pathname: string;
590
+ /**
591
+ * The portion of the URL pathname that was matched before child routes.
592
+ */
593
+ pathnameBase: string;
594
+ /**
595
+ * The route object that was used to match.
596
+ */
597
+ route: RouteObjectType;
598
+ }
599
+ interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
600
+ }
601
+ declare class DeferredData {
602
+ private pendingKeysSet;
603
+ private controller;
604
+ private abortPromise;
605
+ private unlistenAbortSignal;
606
+ private subscribers;
607
+ data: Record<string, unknown>;
608
+ init?: ResponseInit;
609
+ deferredKeys: string[];
610
+ constructor(data: Record<string, unknown>, responseInit?: ResponseInit);
611
+ private trackPromise;
612
+ private onSettle;
613
+ private emit;
614
+ subscribe(fn: (aborted: boolean, settledKey?: string) => void): () => boolean;
615
+ cancel(): void;
616
+ resolveData(signal: AbortSignal): Promise<boolean>;
617
+ get done(): boolean;
618
+ get unwrappedData(): {};
619
+ get pendingKeys(): string[];
620
+ }
621
+
622
+ /**
623
+ * State maintained internally by the router. During a navigation, all states
624
+ * reflect the the "old" location unless otherwise noted.
625
+ */
626
+ interface RouterState {
627
+ /**
628
+ * The action of the most recent navigation
629
+ */
630
+ historyAction: Action;
631
+ /**
632
+ * The current location reflected by the router
633
+ */
634
+ location: Location;
635
+ /**
636
+ * The current set of route matches
637
+ */
638
+ matches: AgnosticDataRouteMatch[];
639
+ /**
640
+ * Tracks whether we've completed our initial data load
641
+ */
642
+ initialized: boolean;
643
+ /**
644
+ * Current scroll position we should start at for a new view
645
+ * - number -> scroll position to restore to
646
+ * - false -> do not restore scroll at all (used during submissions)
647
+ * - null -> don't have a saved position, scroll to hash or top of page
648
+ */
649
+ restoreScrollPosition: number | false | null;
650
+ /**
651
+ * Indicate whether this navigation should skip resetting the scroll position
652
+ * if we are unable to restore the scroll position
653
+ */
654
+ preventScrollReset: boolean;
655
+ /**
656
+ * Tracks the state of the current navigation
657
+ */
658
+ navigation: Navigation;
659
+ /**
660
+ * Tracks any in-progress revalidations
661
+ */
662
+ revalidation: RevalidationState;
663
+ /**
664
+ * Data from the loaders for the current matches
665
+ */
666
+ loaderData: RouteData;
667
+ /**
668
+ * Data from the action for the current matches
669
+ */
670
+ actionData: RouteData | null;
671
+ /**
672
+ * Errors caught from loaders for the current matches
673
+ */
674
+ errors: RouteData | null;
675
+ /**
676
+ * Map of current fetchers
677
+ */
678
+ fetchers: Map<string, Fetcher>;
679
+ /**
680
+ * Map of current blockers
681
+ */
682
+ blockers: Map<string, Blocker>;
683
+ }
684
+ /**
685
+ * Data that can be passed into hydrate a Router from SSR
686
+ */
687
+ type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
688
+ /**
689
+ * Potential states for state.navigation
690
+ */
691
+ type NavigationStates = {
692
+ Idle: {
693
+ state: "idle";
694
+ location: undefined;
695
+ formMethod: undefined;
696
+ formAction: undefined;
697
+ formEncType: undefined;
698
+ formData: undefined;
699
+ json: undefined;
700
+ text: undefined;
701
+ };
702
+ Loading: {
703
+ state: "loading";
704
+ location: Location;
705
+ formMethod: Submission["formMethod"] | undefined;
706
+ formAction: Submission["formAction"] | undefined;
707
+ formEncType: Submission["formEncType"] | undefined;
708
+ formData: Submission["formData"] | undefined;
709
+ json: Submission["json"] | undefined;
710
+ text: Submission["text"] | undefined;
711
+ };
712
+ Submitting: {
713
+ state: "submitting";
714
+ location: Location;
715
+ formMethod: Submission["formMethod"];
716
+ formAction: Submission["formAction"];
717
+ formEncType: Submission["formEncType"];
718
+ formData: Submission["formData"];
719
+ json: Submission["json"];
720
+ text: Submission["text"];
721
+ };
722
+ };
723
+ type Navigation = NavigationStates[keyof NavigationStates];
724
+ type RevalidationState = "idle" | "loading";
725
+ /**
726
+ * Potential states for fetchers
727
+ */
728
+ type FetcherStates<TData = any> = {
729
+ Idle: {
730
+ state: "idle";
731
+ formMethod: undefined;
732
+ formAction: undefined;
733
+ formEncType: undefined;
734
+ text: undefined;
735
+ formData: undefined;
736
+ json: undefined;
737
+ data: TData | undefined;
738
+ " _hasFetcherDoneAnything "?: boolean;
739
+ };
740
+ Loading: {
741
+ state: "loading";
742
+ formMethod: Submission["formMethod"] | undefined;
743
+ formAction: Submission["formAction"] | undefined;
744
+ formEncType: Submission["formEncType"] | undefined;
745
+ text: Submission["text"] | undefined;
746
+ formData: Submission["formData"] | undefined;
747
+ json: Submission["json"] | undefined;
748
+ data: TData | undefined;
749
+ " _hasFetcherDoneAnything "?: boolean;
750
+ };
751
+ Submitting: {
752
+ state: "submitting";
753
+ formMethod: Submission["formMethod"];
754
+ formAction: Submission["formAction"];
755
+ formEncType: Submission["formEncType"];
756
+ text: Submission["text"];
757
+ formData: Submission["formData"];
758
+ json: Submission["json"];
759
+ data: TData | undefined;
760
+ " _hasFetcherDoneAnything "?: boolean;
761
+ };
762
+ };
763
+ type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
764
+ interface BlockerBlocked {
765
+ state: "blocked";
766
+ reset(): void;
767
+ proceed(): void;
768
+ location: Location;
769
+ }
770
+ interface BlockerUnblocked {
771
+ state: "unblocked";
772
+ reset: undefined;
773
+ proceed: undefined;
774
+ location: undefined;
775
+ }
776
+ interface BlockerProceeding {
777
+ state: "proceeding";
778
+ reset: undefined;
779
+ proceed: undefined;
780
+ location: Location;
781
+ }
782
+ type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
783
+
784
+ /**
785
+ * NOTE: If you refactor this to split up the modules into separate files,
786
+ * you'll need to update the rollup config for react-router-dom-v5-compat.
787
+ */
788
+
789
+ declare global {
790
+ var __staticRouterHydrationData: HydrationState | undefined;
791
+ }
792
+
294
793
  declare global {
295
794
  interface SymbolConstructor {
296
795
  readonly observable: symbol;