storybook 9.0.0-alpha.2 → 9.0.0-alpha.21

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 (162) hide show
  1. package/README.md +1 -1
  2. package/assets/docs/addon-backgrounds.gif +0 -0
  3. package/assets/docs/addon-controls-args-annotated.png +0 -0
  4. package/assets/docs/addon-controls-args-background-color.png +0 -0
  5. package/assets/docs/addon-controls-args-background-string.png +0 -0
  6. package/assets/docs/addon-controls-args-docs.png +0 -0
  7. package/assets/docs/addon-controls-args-logging.png +0 -0
  8. package/assets/docs/addon-controls-args-no-annotation.png +0 -0
  9. package/assets/docs/addon-controls-args-reflow-slider.png +0 -0
  10. package/assets/docs/addon-controls-args-reflow.png +0 -0
  11. package/assets/docs/addon-controls-args-template.png +0 -0
  12. package/assets/docs/addon-controls-expanded.png +0 -0
  13. package/assets/docs/addon-controls-hero.gif +0 -0
  14. package/assets/docs/addon-controls-install.png +0 -0
  15. package/assets/docs/hero.gif +0 -0
  16. package/assets/docs/highlight.png +0 -0
  17. package/assets/docs/viewport.png +0 -0
  18. package/assets/server/base-preview-head.html +1 -3
  19. package/bin/index.cjs +2 -2
  20. package/dist/actions/decorator.d.ts +6 -0
  21. package/dist/actions/decorator.js +134 -0
  22. package/dist/actions/index.cjs +123 -0
  23. package/dist/actions/index.d.ts +102 -0
  24. package/dist/actions/index.js +108 -0
  25. package/dist/actions/preview.cjs +161 -0
  26. package/dist/actions/preview.d.ts +54 -0
  27. package/dist/actions/preview.js +152 -0
  28. package/dist/babel/index.cjs +822 -816
  29. package/dist/babel/index.js +822 -816
  30. package/dist/backgrounds/index.cjs +148 -0
  31. package/dist/backgrounds/index.d.ts +91 -0
  32. package/dist/backgrounds/index.js +130 -0
  33. package/dist/backgrounds/preview.cjs +143 -0
  34. package/dist/backgrounds/preview.d.ts +54 -0
  35. package/dist/backgrounds/preview.js +127 -0
  36. package/dist/bin/index.cjs +49 -70
  37. package/dist/bin/index.js +49 -70
  38. package/dist/builder-manager/index.cjs +319 -326
  39. package/dist/builder-manager/index.js +576 -583
  40. package/dist/channels/index.cjs +1026 -981
  41. package/dist/channels/index.js +1258 -1207
  42. package/dist/cli/bin/index.cjs +483 -483
  43. package/dist/cli/bin/index.js +495 -495
  44. package/dist/cli/index.cjs +61735 -7590
  45. package/dist/cli/index.d.ts +25 -21
  46. package/dist/cli/index.js +61776 -7631
  47. package/dist/client-logger/index.cjs +56 -88
  48. package/dist/client-logger/index.js +41 -47
  49. package/dist/common/index.cjs +16137 -9085
  50. package/dist/common/index.d.ts +35 -30
  51. package/dist/common/index.js +16230 -9172
  52. package/dist/component-testing/index.cjs +23 -0
  53. package/dist/component-testing/index.d.ts +3 -0
  54. package/dist/component-testing/index.js +5 -0
  55. package/dist/component-testing/preview.cjs +40 -0
  56. package/dist/component-testing/preview.d.ts +5 -0
  57. package/dist/component-testing/preview.js +25 -0
  58. package/dist/components/index.cjs +16268 -24926
  59. package/dist/components/index.d.ts +98 -347
  60. package/dist/components/index.js +5905 -19177
  61. package/dist/controls/decorator.d.ts +5 -0
  62. package/dist/controls/decorator.js +8 -0
  63. package/dist/controls/index.cjs +26 -0
  64. package/dist/controls/index.d.ts +39 -0
  65. package/dist/controls/index.js +6 -0
  66. package/dist/controls/preview.cjs +26 -0
  67. package/dist/controls/preview.d.ts +54 -0
  68. package/dist/controls/preview.js +9 -0
  69. package/dist/core-events/index.cjs +91 -106
  70. package/dist/core-events/index.d.ts +139 -104
  71. package/dist/core-events/index.js +79 -94
  72. package/dist/core-server/index.cjs +13898 -13409
  73. package/dist/core-server/index.d.ts +270 -3
  74. package/dist/core-server/index.js +13981 -13497
  75. package/dist/core-server/presets/common-manager.css +170 -0
  76. package/dist/core-server/presets/common-manager.js +12149 -17
  77. package/dist/core-server/presets/common-preset.cjs +3009 -3155
  78. package/dist/core-server/presets/common-preset.js +2862 -3009
  79. package/dist/csf/index.cjs +76 -120
  80. package/dist/csf/index.d.ts +2 -6
  81. package/dist/csf/index.js +69 -113
  82. package/dist/csf-tools/index.cjs +412 -403
  83. package/dist/csf-tools/index.d.ts +0 -4
  84. package/dist/csf-tools/index.js +410 -401
  85. package/dist/docs-tools/index.cjs +2569 -575
  86. package/dist/docs-tools/index.d.ts +2 -2
  87. package/dist/docs-tools/index.js +2565 -564
  88. package/dist/highlight/index.cjs +27 -0
  89. package/dist/highlight/index.d.ts +61 -0
  90. package/dist/highlight/index.js +7 -0
  91. package/dist/highlight/preview.cjs +535 -0
  92. package/dist/highlight/preview.d.ts +54 -0
  93. package/dist/highlight/preview.js +519 -0
  94. package/dist/instrumenter/index.cjs +2207 -2342
  95. package/dist/instrumenter/index.d.ts +8 -7
  96. package/dist/instrumenter/index.js +2430 -2603
  97. package/dist/manager/globals-module-info.cjs +291 -151
  98. package/dist/manager/globals-module-info.d.ts +1 -1
  99. package/dist/manager/globals-module-info.js +275 -135
  100. package/dist/manager/globals-runtime.js +60263 -28383
  101. package/dist/manager/globals.cjs +23 -19
  102. package/dist/manager/globals.d.ts +8 -5
  103. package/dist/manager/globals.js +10 -6
  104. package/dist/manager/runtime.js +4625 -3921
  105. package/dist/manager-api/index.cjs +4228 -3833
  106. package/dist/manager-api/index.d.ts +398 -102
  107. package/dist/manager-api/index.js +3500 -3084
  108. package/dist/manager-errors.d.ts +25 -1
  109. package/dist/manager-errors.js +50 -30
  110. package/dist/measure/index.cjs +476 -0
  111. package/dist/measure/index.d.ts +66 -0
  112. package/dist/measure/index.js +464 -0
  113. package/dist/measure/preview.cjs +466 -0
  114. package/dist/measure/preview.d.ts +59 -0
  115. package/dist/measure/preview.js +450 -0
  116. package/dist/outline/index.cjs +528 -0
  117. package/dist/outline/index.d.ts +66 -0
  118. package/dist/outline/index.js +500 -0
  119. package/dist/outline/preview.cjs +518 -0
  120. package/dist/outline/preview.d.ts +59 -0
  121. package/dist/outline/preview.js +486 -0
  122. package/dist/preview/globals.cjs +21 -17
  123. package/dist/preview/globals.d.ts +4 -1
  124. package/dist/preview/globals.js +6 -2
  125. package/dist/preview/runtime.js +46311 -6614
  126. package/dist/preview-api/index.cjs +1363 -1899
  127. package/dist/preview-api/index.d.ts +81 -395
  128. package/dist/preview-api/index.js +1711 -2169
  129. package/dist/preview-errors.cjs +119 -88
  130. package/dist/preview-errors.d.ts +30 -2
  131. package/dist/preview-errors.js +192 -142
  132. package/dist/router/index.cjs +847 -871
  133. package/dist/router/index.js +193 -199
  134. package/dist/server-errors.cjs +188 -124
  135. package/dist/server-errors.d.ts +36 -2
  136. package/dist/server-errors.js +188 -124
  137. package/dist/telemetry/index.cjs +1056 -1979
  138. package/dist/telemetry/index.d.ts +26 -5
  139. package/dist/telemetry/index.js +1091 -2010
  140. package/dist/test/index.cjs +35686 -0
  141. package/dist/test/index.d.ts +186 -0
  142. package/dist/test/index.js +33840 -0
  143. package/dist/test/preview.cjs +15870 -0
  144. package/dist/test/preview.d.ts +48 -0
  145. package/dist/test/preview.js +14501 -0
  146. package/dist/test/spy.cjs +258 -0
  147. package/dist/test/spy.d.ts +66 -0
  148. package/dist/test/spy.js +240 -0
  149. package/dist/theming/create.cjs +79 -2269
  150. package/dist/theming/create.js +67 -841
  151. package/dist/theming/index.cjs +1065 -3232
  152. package/dist/theming/index.js +951 -1719
  153. package/dist/types/index.cjs +11 -12
  154. package/dist/types/index.d.ts +684 -163
  155. package/dist/types/index.js +1 -2
  156. package/dist/viewport/index.cjs +310 -0
  157. package/dist/viewport/index.d.ts +320 -0
  158. package/dist/viewport/index.js +290 -0
  159. package/dist/viewport/preview.cjs +35 -0
  160. package/dist/viewport/preview.d.ts +68 -0
  161. package/dist/viewport/preview.js +19 -0
  162. package/package.json +359 -12
@@ -1,9 +1,10 @@
1
1
  import { loadAllPresets } from 'storybook/internal/common';
2
2
  export { getPreviewBodyTemplate, getPreviewHeadTemplate } from 'storybook/internal/common';
3
3
  import * as storybook_internal_types from 'storybook/internal/types';
4
- import { CLIOptions, LoadOptions, BuilderOptions, StorybookConfigRaw, IndexInputStats, NormalizedStoriesSpecifier, Path, Indexer, DocsOptions, StoryIndexEntry, DocsIndexEntry, Tag, IndexEntry, StoryIndex, Options } from 'storybook/internal/types';
4
+ import { CLIOptions, LoadOptions, BuilderOptions, StorybookConfigRaw, IndexInputStats, NormalizedStoriesSpecifier, Path, Indexer, DocsOptions, StoryIndexEntry, DocsIndexEntry, Tag, IndexEntry, StoryIndex, Options, NormalizedProjectAnnotations, ProjectAnnotations, ComposedStoryFn } from 'storybook/internal/types';
5
5
  import { EventType } from 'storybook/internal/telemetry';
6
6
  import { Channel } from 'storybook/internal/channels';
7
+ import { StoryId } from 'storybook/internal/csf';
7
8
 
8
9
  type BuildStaticStandaloneOptions = CLIOptions & LoadOptions & BuilderOptions & {
9
10
  outputDir: string;
@@ -423,7 +424,7 @@ declare class UniversalStore<State, CustomEvent extends {
423
424
  * @example
424
425
  *
425
426
  * ```ts
426
- * import * as testUtils from '@storybook/test'; // in stories
427
+ * import * as testUtils from 'storybook/test'; // in stories
427
428
  * import { vi as testUtils } from 'vitest'; // ... or in Vitest tests
428
429
  *
429
430
  * const initialState = { ... };
@@ -459,4 +460,270 @@ declare class MockUniversalStore<State, CustomEvent extends {
459
460
  unsubscribeAll(): void;
460
461
  }
461
462
 
462
- export { type BuildIndexOptions, type BuildStaticStandaloneOptions, StoryIndexGenerator, build, buildDevStandalone, buildIndex, buildIndexStandalone, buildStaticStandalone, MockUniversalStore as experimental_MockUniversalStore, UniversalStore as experimental_UniversalStore, loadStorybook as experimental_loadStorybook, getErrorLevel, mapStaticDir, sendTelemetryError, withTelemetry };
463
+ type StatusValue = 'status-value:pending' | 'status-value:success' | 'status-value:error' | 'status-value:warning' | 'status-value:unknown';
464
+ type StatusTypeId = string;
465
+ type StatusByTypeId = Record<StatusTypeId, Status>;
466
+ type StatusesByStoryIdAndTypeId = Record<StoryId, StatusByTypeId>;
467
+ interface Status {
468
+ value: StatusValue;
469
+ typeId: StatusTypeId;
470
+ storyId: StoryId;
471
+ title: string;
472
+ description: string;
473
+ data?: any;
474
+ sidebarContextMenu?: boolean;
475
+ }
476
+ declare const StatusStoreEventType: {
477
+ readonly SELECT: "select";
478
+ };
479
+ type StatusStoreEvent = {
480
+ type: typeof StatusStoreEventType.SELECT;
481
+ payload: Status[];
482
+ };
483
+ type StatusStore = {
484
+ getAll: () => StatusesByStoryIdAndTypeId;
485
+ set: (statuses: Status[]) => void;
486
+ onAllStatusChange: (listener: (statuses: StatusesByStoryIdAndTypeId, previousStatuses: StatusesByStoryIdAndTypeId) => void) => () => void;
487
+ onSelect: (listener: (selectedStatuses: Status[]) => void) => () => void;
488
+ unset: (storyIds?: StoryId[]) => void;
489
+ };
490
+ type StatusStoreByTypeId = StatusStore & {
491
+ typeId: StatusTypeId;
492
+ };
493
+
494
+ declare global {
495
+ interface SymbolConstructor {
496
+ readonly observable: symbol;
497
+ }
498
+ }
499
+
500
+ declare global {
501
+ var globalProjectAnnotations: NormalizedProjectAnnotations<any>;
502
+ var defaultProjectAnnotations: ProjectAnnotations<any>;
503
+ }
504
+ type WrappedStoryRef = {
505
+ __pw_type: 'jsx' | 'importRef';
506
+ };
507
+ type UnwrappedJSXStoryRef = {
508
+ __pw_type: 'jsx';
509
+ type: UnwrappedImportStoryRef;
510
+ };
511
+ type UnwrappedImportStoryRef = ComposedStoryFn;
512
+ declare global {
513
+ function __pwUnwrapObject(storyRef: WrappedStoryRef): Promise<UnwrappedJSXStoryRef | UnwrappedImportStoryRef>;
514
+ }
515
+
516
+ type TestProviderState = 'test-provider-state:pending' | 'test-provider-state:running' | 'test-provider-state:succeeded' | 'test-provider-state:crashed';
517
+ type TestProviderId = string;
518
+ type TestProviderStateByProviderId = Record<TestProviderId, TestProviderState>;
519
+ type TestProviderStoreEventType = 'run-all' | 'clear-all' | 'settings-changed';
520
+ type TestProviderStoreEvent = BaseEvent & {
521
+ type: TestProviderStoreEventType;
522
+ };
523
+ type BaseTestProviderStore = {
524
+ /**
525
+ * Notifies all listeners that settings have changed for test providers. The Storybook UI will
526
+ * highlight the test providers to tell the user that settings has changed.
527
+ */
528
+ settingsChanged: () => void;
529
+ /**
530
+ * Subscribe to clicks on the "Run All" button, that is supposed to trigger all test providers to
531
+ * run. Your test provider should do the "main thing" when this happens, similar to when the user
532
+ * triggers your test provider specifically.
533
+ *
534
+ * @example
535
+ *
536
+ * ```typescript
537
+ * // Subscribe to run-all events
538
+ * const unsubscribe = myTestProviderStore.onRunAll(() => {
539
+ * await runAllMyTests();
540
+ * });
541
+ * ```
542
+ */
543
+ onRunAll: (listener: () => void) => () => void;
544
+ /**
545
+ * Subscribe to clicks on the "Clear All" button, that is supposed to clear all state from test
546
+ * providers. Storybook already clears all statuses, but if your test provider has more
547
+ * non-status-based state, you can use this to clear that here.
548
+ *
549
+ * @remarks
550
+ * The purpose of this is _not_ to clear your test provider's settings, only the test results.
551
+ * @example
552
+ *
553
+ * ```typescript
554
+ * // Subscribe to clear-all events
555
+ * const unsubscribe = myTestProviderStore.onClearAll(() => {
556
+ * clearMyTestResults();
557
+ * });
558
+ *
559
+ * // Later, when no longer needed
560
+ * unsubscribe();
561
+ * ```
562
+ */
563
+ onClearAll: (listener: () => void) => () => void;
564
+ };
565
+ /**
566
+ * Represents a store for a specific test provider, identified by its unique ID. This store provides
567
+ * methods to manage the state of an individual test provider, including getting and setting its
568
+ * state, running operations with automatic state management, and accessing its unique identifier.
569
+ *
570
+ * Each test provider has its own instance of this store, allowing for independent state management
571
+ * across different test providers in the application.
572
+ *
573
+ * @example
574
+ *
575
+ * ```typescript
576
+ * // Get a store for a specific test provider
577
+ * const grammarStore = getTestProviderStoreById('addon-grammar');
578
+ *
579
+ * // Check the current state
580
+ * if (grammarStore.getState() === 'test-provider-state:pending') {
581
+ * console.log('Grammar tests are ready to run');
582
+ * }
583
+ *
584
+ * // Run tests with automatic state management
585
+ * grammarStore.runWithState(async () => {
586
+ * await runGrammarTests();
587
+ * });
588
+ * ```
589
+ *
590
+ * @see {@link TestProviderState} for possible state values
591
+ * @see {@link BaseTestProviderStore} for methods inherited from the base store
592
+ */
593
+ type TestProviderStoreById = BaseTestProviderStore & {
594
+ /**
595
+ * Gets the current state of this specific test provider
596
+ *
597
+ * The state represents the current execution status of the test provider, which can be one of the
598
+ * following:
599
+ *
600
+ * - 'test-provider-state:pending': Tests have not been run yet
601
+ * - 'test-provider-state:running': Tests are currently running
602
+ * - 'test-provider-state:succeeded': Tests completed successfully
603
+ * - 'test-provider-state:crashed': Running tests failed or encountered an error
604
+ *
605
+ * Storybook UI will use this state to determine what to show in the UI.
606
+ *
607
+ * @remarks
608
+ * The 'test-provider-state:crashed' is meant to signify that the test run as a whole failed to
609
+ * execute for some reason. It should _not_ be set just because a number of tests failed, use
610
+ * statuses and the status store for that. See {@link TestStatusStore} for managing individual test
611
+ * statuses.
612
+ * @example
613
+ *
614
+ * ```typescript
615
+ * // Get the current state of a specific test provider
616
+ * const state = testProviderStore.getState();
617
+ *
618
+ * // Conditionally render UI based on the state
619
+ * const TestStatus = () => {
620
+ * const state = testProviderStore.getState();
621
+ *
622
+ * if (state === 'test-provider-state:running') {
623
+ * return <Spinner />;
624
+ * } else if (state === 'test-provider-state:succeeded') {
625
+ * return <SuccessIcon />;
626
+ * } else if (state === 'test-provider-state:crashed') {
627
+ * return <ErrorIcon />;
628
+ * }
629
+ *
630
+ * return <PendingIcon />;
631
+ * };
632
+ * ```
633
+ */
634
+ getState: () => TestProviderState;
635
+ /**
636
+ * Sets the state of this specific test provider
637
+ *
638
+ * This method allows you to manually update the execution state of the test provider. It's
639
+ * typically used when you need to reflect the current status of test execution in the UI or when
640
+ * you want to programmatically control the test provider's state.
641
+ *
642
+ * Common use cases include:
643
+ *
644
+ * - Setting to 'running' when tests start
645
+ * - Setting to 'succeeded' when tests complete successfully
646
+ * - Setting to 'crashed' when tests fail or encounter errors
647
+ * - Setting to 'pending' to reset the state
648
+ *
649
+ * The state represents the current execution status of the test provider, which can be one of the
650
+ * following:
651
+ *
652
+ * - 'test-provider-state:pending': Tests have not been run yet
653
+ * - 'test-provider-state:running': Tests are currently running
654
+ * - 'test-provider-state:succeeded': Tests completed successfully
655
+ * - 'test-provider-state:crashed': Running tests failed or encountered an error
656
+ *
657
+ * Storybook UI will use this state to determine what to show in the UI.
658
+ *
659
+ * @remarks
660
+ * The 'test-provider-state:crashed' is meant to signify that the test run as a whole failed to
661
+ * execute for some reason. It should _not_ be set just because a number of tests failed, use
662
+ * statuses and the status store for that. See {@link TestStatusStore} for managing individual test
663
+ * statuses.
664
+ *
665
+ * For most use cases, consider using {@link runWithState} instead, which provides automatic state
666
+ * management and error handling during test execution.
667
+ * @example
668
+ *
669
+ * ```typescript
670
+ * // Update the state when tests start running
671
+ * const startTests = async () => {
672
+ * testProviderStore.setState('test-provider-state:running');
673
+ * ... run tests ...
674
+ * };
675
+ * ```
676
+ */
677
+ setState: (state: TestProviderState) => void;
678
+ /**
679
+ * Runs a callback and automatically updates the test provider's state with running, succeeded or
680
+ * crashed, depending on the end result.
681
+ *
682
+ * - Immediately changes the state to 'running'
683
+ * - If the callback returns/resolves, change the state to 'succeeded'.
684
+ * - If the callback throws an error/rejects, change the state to 'crashed'.
685
+ *
686
+ * This approach helps prevent state inconsistencies that might occur if exceptions are thrown
687
+ * during test execution.
688
+ *
689
+ * @example
690
+ *
691
+ * ```typescript
692
+ * // Run tests with automatic state management
693
+ * const runTests = () => {
694
+ * testProviderStore.runWithState(async () => {
695
+ * // The state is automatically set to 'running' before this callback
696
+ *
697
+ * // Run tests here...
698
+ * const results = await executeTests();
699
+ * });
700
+ * };
701
+ * ```
702
+ */
703
+ runWithState: (callback: () => void | Promise<void>) => Promise<void>;
704
+ /** The unique identifier for this test provider */
705
+ testProviderId: TestProviderId;
706
+ };
707
+
708
+ declare const fullStatusStore: StatusStore & {
709
+ selectStatuses: (statuses: Status[]) => void;
710
+ typeId: undefined;
711
+ };
712
+ declare const getStatusStoreByTypeId: (typeId: StatusTypeId) => StatusStoreByTypeId;
713
+ declare const universalStatusStore: UniversalStore<StatusesByStoryIdAndTypeId, StatusStoreEvent>;
714
+
715
+ declare const fullTestProviderStore: {
716
+ settingsChanged: () => void;
717
+ onRunAll: (listener: () => void) => () => void;
718
+ onClearAll: (listener: () => void) => () => void;
719
+ } & {
720
+ getFullState: UniversalStore<TestProviderStateByProviderId, TestProviderStoreEvent>["getState"];
721
+ setFullState: UniversalStore<TestProviderStateByProviderId, TestProviderStoreEvent>["setState"];
722
+ onSettingsChanged: (listener: (testProviderId: TestProviderId) => void) => () => void;
723
+ runAll: () => void;
724
+ clearAll: () => void;
725
+ };
726
+ declare const getTestProviderStoreById: (testProviderId: TestProviderId) => TestProviderStoreById;
727
+ declare const universalTestProviderStore: UniversalStore<TestProviderStateByProviderId, TestProviderStoreEvent>;
728
+
729
+ export { type BuildIndexOptions, type BuildStaticStandaloneOptions, StoryIndexGenerator, build, buildDevStandalone, buildIndex, buildIndexStandalone, buildStaticStandalone, MockUniversalStore as experimental_MockUniversalStore, UniversalStore as experimental_UniversalStore, getStatusStoreByTypeId as experimental_getStatusStore, getTestProviderStoreById as experimental_getTestProviderStore, loadStorybook as experimental_loadStorybook, getErrorLevel, fullStatusStore as internal_fullStatusStore, fullTestProviderStore as internal_fullTestProviderStore, universalStatusStore as internal_universalStatusStore, universalTestProviderStore as internal_universalTestProviderStore, mapStaticDir, sendTelemetryError, withTelemetry };