@storybook/react-native 6.0.1-beta.0 → 6.0.1-beta.10

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 (78) hide show
  1. package/dist/document-polyfill/DOM/Document.d.ts +14 -0
  2. package/dist/document-polyfill/DOM/Document.js +37 -0
  3. package/dist/document-polyfill/DOM/Element.d.ts +37 -0
  4. package/dist/document-polyfill/DOM/Element.js +58 -0
  5. package/dist/document-polyfill/DOM/HTMLCanvasElement.d.ts +4 -0
  6. package/dist/document-polyfill/DOM/HTMLCanvasElement.js +4 -0
  7. package/dist/document-polyfill/DOM/HTMLImageElement.d.ts +4 -0
  8. package/dist/document-polyfill/DOM/HTMLImageElement.js +4 -0
  9. package/dist/document-polyfill/DOM/HTMLVideoElement.d.ts +4 -0
  10. package/dist/document-polyfill/DOM/HTMLVideoElement.js +4 -0
  11. package/dist/document-polyfill/DOM/Node.d.ts +26 -0
  12. package/dist/document-polyfill/DOM/Node.js +33 -0
  13. package/dist/{preview/global.js → document-polyfill/index.d.ts} +0 -0
  14. package/dist/document-polyfill/index.js +3 -0
  15. package/dist/document-polyfill/module.d.ts +0 -0
  16. package/dist/document-polyfill/module.js +1 -0
  17. package/dist/{types-6.0.js → document-polyfill/module.native.d.ts} +0 -0
  18. package/dist/document-polyfill/module.native.js +2 -0
  19. package/dist/index.d.ts +16 -13
  20. package/dist/index.js +18 -18
  21. package/dist/preview/View.d.ts +40 -0
  22. package/dist/preview/View.js +90 -0
  23. package/dist/preview/components/OnDeviceUI/OnDeviceUI.d.ts +6 -3
  24. package/dist/preview/components/OnDeviceUI/OnDeviceUI.js +33 -38
  25. package/dist/preview/components/OnDeviceUI/Panel.js +1 -0
  26. package/dist/preview/components/OnDeviceUI/animation.d.ts +16 -6
  27. package/dist/preview/components/OnDeviceUI/animation.js +4 -3
  28. package/dist/preview/components/OnDeviceUI/navigation/Bar.d.ts +3 -1
  29. package/dist/preview/components/OnDeviceUI/navigation/Bar.js +1 -1
  30. package/dist/preview/components/OnDeviceUI/navigation/Navigation.d.ts +4 -3
  31. package/dist/preview/components/OnDeviceUI/navigation/Navigation.js +15 -10
  32. package/dist/preview/components/OnDeviceUI/navigation/VisibilityButton.d.ts +3 -1
  33. package/dist/preview/components/OnDeviceUI/navigation/VisibilityButton.js +34 -5
  34. package/dist/preview/components/Shared/icons.d.ts +5 -0
  35. package/dist/preview/components/Shared/icons.js +21 -0
  36. package/dist/preview/components/Shared/text.d.ts +3 -32
  37. package/dist/preview/components/Shared/text.js +3 -4
  38. package/dist/preview/components/Shared/theme.d.ts +4 -0
  39. package/dist/preview/components/Shared/theme.js +4 -0
  40. package/dist/preview/components/StoryListView/StoryListView.d.ts +7 -4
  41. package/dist/preview/components/StoryListView/StoryListView.js +46 -27
  42. package/dist/preview/components/StoryView/StoryView.d.ts +5 -3
  43. package/dist/preview/components/StoryView/StoryView.js +6 -24
  44. package/dist/preview/executeLoadable.d.ts +24 -0
  45. package/dist/preview/executeLoadable.js +79 -0
  46. package/dist/preview/rn-host-detect.d.ts +1 -0
  47. package/dist/preview/rn-host-detect.js +62 -0
  48. package/dist/preview/start.d.ts +16 -0
  49. package/dist/preview/start.js +83 -0
  50. package/dist/types/types-6.0.d.ts +72 -0
  51. package/dist/types/types-6.0.js +1 -0
  52. package/dist/types/types.d.ts +14 -0
  53. package/dist/types/types.js +1 -0
  54. package/package.json +16 -13
  55. package/scripts/__snapshots__/loader.test.js.snap +82 -7
  56. package/scripts/loader.js +40 -10
  57. package/scripts/loader.test.js +47 -5
  58. package/scripts/mocks/file-extensions/FakeComponent.tsx +1 -0
  59. package/scripts/mocks/file-extensions/FakeStory.stories.tsx +10 -0
  60. package/scripts/mocks/file-extensions/main.ts +13 -0
  61. package/scripts/mocks/file-extensions/preview.tsx +23 -0
  62. package/scripts/mocks/preview-files/js/preview.js +24 -0
  63. package/scripts/mocks/preview-files/jsx/preview.jsx +24 -0
  64. package/scripts/mocks/preview-files/ts/preview.ts +9 -0
  65. package/scripts/mocks/preview-files/tsx/preview.tsx +9 -0
  66. package/scripts/mocks/wrong-extension-preview/FakeComponent.tsx +1 -0
  67. package/scripts/mocks/wrong-extension-preview/FakeStory.stories.tsx +10 -0
  68. package/scripts/mocks/wrong-extension-preview/main.js +9 -0
  69. package/scripts/mocks/wrong-extension-preview/preview.txt +24 -0
  70. package/scripts/watcher.js +7 -4
  71. package/dist/preview/Preview.d.ts +0 -55
  72. package/dist/preview/Preview.js +0 -117
  73. package/dist/preview/global.d.ts +0 -8
  74. package/dist/preview/index.d.ts +0 -1
  75. package/dist/preview/index.js +0 -1
  76. package/dist/preview/loadCsf.d.ts +0 -16
  77. package/dist/preview/loadCsf.js +0 -175
  78. package/dist/types-6.0.d.ts +0 -34
@@ -0,0 +1 @@
1
+ export const FakeComponent = () => null;
@@ -0,0 +1,10 @@
1
+ import { FakeComponent } from './FakeComponent';
2
+
3
+ export default {
4
+ title: 'components/FakeComponent',
5
+ component: FakeComponent,
6
+ };
7
+
8
+ export const Basic = {
9
+ args: {},
10
+ };
@@ -0,0 +1,13 @@
1
+ import type { StorybookConfig } from '@storybook/core-common';
2
+
3
+ const config: StorybookConfig = {
4
+ stories: ['./FakeStory.stories.tsx'],
5
+ addons: [
6
+ '@storybook/addon-ondevice-notes',
7
+ '@storybook/addon-ondevice-controls',
8
+ '@storybook/addon-ondevice-backgrounds',
9
+ '@storybook/addon-ondevice-actions',
10
+ ],
11
+ };
12
+
13
+ export default config;
@@ -0,0 +1,23 @@
1
+ import { View, StyleSheet } from 'react-native';
2
+ import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds';
3
+
4
+ export const decorators = [
5
+ (StoryFn) => (
6
+ <View style={styles.container}>
7
+ <StoryFn />
8
+ </View>
9
+ ),
10
+ withBackgrounds,
11
+ ];
12
+ export const parameters = {
13
+ my_param: 'anything',
14
+ backgrounds: [
15
+ { name: 'plain', value: 'white', default: true },
16
+ { name: 'warm', value: 'hotpink' },
17
+ { name: 'cool', value: 'deepskyblue' },
18
+ ],
19
+ };
20
+
21
+ const styles = StyleSheet.create({
22
+ container: { padding: 8, flex: 1 },
23
+ });
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+ import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds';
4
+
5
+ export const decorators = [
6
+ (StoryFn) => (
7
+ <View style={styles.container}>
8
+ <StoryFn />
9
+ </View>
10
+ ),
11
+ withBackgrounds,
12
+ ];
13
+ export const parameters = {
14
+ my_param: 'anything',
15
+ backgrounds: [
16
+ { name: 'plain', value: 'white', default: true },
17
+ { name: 'warm', value: 'hotpink' },
18
+ { name: 'cool', value: 'deepskyblue' },
19
+ ],
20
+ };
21
+
22
+ const styles = StyleSheet.create({
23
+ container: { padding: 8, flex: 1 },
24
+ });
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+ import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds';
4
+
5
+ export const decorators = [
6
+ (StoryFn) => (
7
+ <View style={styles.container}>
8
+ <StoryFn />
9
+ </View>
10
+ ),
11
+ withBackgrounds,
12
+ ];
13
+ export const parameters = {
14
+ my_param: 'anything',
15
+ backgrounds: [
16
+ { name: 'plain', value: 'white', default: true },
17
+ { name: 'warm', value: 'hotpink' },
18
+ { name: 'cool', value: 'deepskyblue' },
19
+ ],
20
+ };
21
+
22
+ const styles = StyleSheet.create({
23
+ container: { padding: 8, flex: 1 },
24
+ });
@@ -0,0 +1,9 @@
1
+ export const decorators: any = [];
2
+ export const parameters = {
3
+ my_param: 'anything',
4
+ backgrounds: [
5
+ { name: 'plain', value: 'white', default: true },
6
+ { name: 'warm', value: 'hotpink' },
7
+ { name: 'cool', value: 'deepskyblue' },
8
+ ],
9
+ };
@@ -0,0 +1,9 @@
1
+ export const decorators: any = [];
2
+ export const parameters = {
3
+ my_param: 'anything',
4
+ backgrounds: [
5
+ { name: 'plain', value: 'white', default: true },
6
+ { name: 'warm', value: 'hotpink' },
7
+ { name: 'cool', value: 'deepskyblue' },
8
+ ],
9
+ };
@@ -0,0 +1 @@
1
+ export const FakeComponent = () => null;
@@ -0,0 +1,10 @@
1
+ import { FakeComponent } from './FakeComponent';
2
+
3
+ export default {
4
+ title: 'components/FakeComponent',
5
+ component: FakeComponent,
6
+ };
7
+
8
+ export const Basic = {
9
+ args: {},
10
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ stories: ['./FakeStory.stories.tsx'],
3
+ addons: [
4
+ '@storybook/addon-ondevice-notes',
5
+ '@storybook/addon-ondevice-controls',
6
+ '@storybook/addon-ondevice-backgrounds',
7
+ '@storybook/addon-ondevice-actions',
8
+ ],
9
+ };
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+ import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds';
4
+
5
+ export const decorators = [
6
+ (StoryFn) => (
7
+ <View style={styles.container}>
8
+ <StoryFn />
9
+ </View>
10
+ ),
11
+ withBackgrounds,
12
+ ];
13
+ export const parameters = {
14
+ my_param: 'anything',
15
+ backgrounds: [
16
+ { name: 'plain', value: 'white', default: true },
17
+ { name: 'warm', value: 'hotpink' },
18
+ { name: 'cool', value: 'deepskyblue' },
19
+ ],
20
+ };
21
+
22
+ const styles = StyleSheet.create({
23
+ container: { padding: 8, flex: 1 },
24
+ });
@@ -1,17 +1,20 @@
1
1
  const chokidar = require('chokidar');
2
2
  const path = require('path');
3
3
 
4
- const { writeRequires, getMain, getPreviewExists } = require('./loader');
4
+ const { writeRequires, getMain, getFilePathExtension } = require('./loader');
5
5
 
6
6
  const { getArguments } = require('./handle-args');
7
7
 
8
8
  const args = getArguments();
9
9
  const log = console.log.bind(console);
10
10
 
11
- const watchPaths = ['./main.js'];
11
+ const mainExt = getFilePathExtension(args, 'main');
12
+ const previewExt = getFilePathExtension(args, 'preview');
12
13
 
13
- if (getPreviewExists(args)) {
14
- watchPaths.push('./preview.js');
14
+ const watchPaths = [`./main.${mainExt}`];
15
+
16
+ if (previewExt) {
17
+ watchPaths.push(`./preview.${previewExt}`);
15
18
  }
16
19
 
17
20
  const updateRequires = (event, watchPath) => {
@@ -1,55 +0,0 @@
1
- /// <reference types="webpack-env" />
2
- /// <reference types="node" />
3
- import Channel from '@storybook/channels';
4
- import { ClientApi, ConfigApi, StoryStore } from '@storybook/client-api';
5
- import { Loadable } from '@storybook/core-client';
6
- import { theme } from './components/Shared/theme';
7
- interface InitialSelection {
8
- /**
9
- * Kind is the default export name or the storiesOf("name") name
10
- */
11
- kind: string;
12
- /**
13
- * Name is the named export or the .add("name") name
14
- */
15
- name: string;
16
- }
17
- export declare type Params = {
18
- onDeviceUI?: boolean;
19
- resetStorybook?: boolean;
20
- disableWebsockets?: boolean;
21
- query?: string;
22
- host?: string;
23
- port?: number;
24
- secured?: boolean;
25
- initialSelection?: InitialSelection;
26
- shouldPersistSelection?: boolean;
27
- tabOpen?: number;
28
- isUIHidden?: boolean;
29
- shouldDisableKeyboardAvoidingView?: boolean;
30
- keyboardAvoidingViewVerticalOffset?: number;
31
- } & {
32
- theme?: typeof theme;
33
- };
34
- export default class Preview {
35
- _clientApi: ClientApi;
36
- _storyStore: StoryStore;
37
- _addons: any;
38
- _channel: Channel;
39
- _decorators: any[];
40
- _asyncStorageStoryId: string;
41
- _configApi: ConfigApi;
42
- configure: (loadable: Loadable, m: NodeModule, showDeprecationWarning: boolean) => void;
43
- constructor();
44
- api: () => ClientApi;
45
- getStorybookUI: (params?: Partial<Params>) => () => JSX.Element;
46
- _setInitialStory: (initialSelection?: InitialSelection, shouldPersistSelection?: boolean) => Promise<void>;
47
- _getInitialStory: (initialSelection?: InitialSelection, shouldPersistSelection?: boolean) => Promise<import("@storybook/client-api").PublishedStoreItem>;
48
- _getStory(storyId: string): import("@storybook/client-api").PublishedStoreItem;
49
- _selectStoryEvent({ storyId }: {
50
- storyId: string;
51
- }, shouldPersistSelection: any): void;
52
- _selectStory(story: any): void;
53
- _checkStory(storyId: string): import("@storybook/client-api").PublishedStoreItem;
54
- }
55
- export {};
@@ -1,117 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import AsyncStorage from '@react-native-async-storage/async-storage';
11
- import { addons } from '@storybook/addons';
12
- import Channel from '@storybook/channels';
13
- import { ClientApi, ConfigApi, StoryStore } from '@storybook/client-api';
14
- import Events from '@storybook/core-events';
15
- import { toId } from '@storybook/csf';
16
- import { ThemeProvider } from 'emotion-theming';
17
- import React from 'react';
18
- import OnDeviceUI from './components/OnDeviceUI';
19
- import { theme } from './components/Shared/theme';
20
- import { loadCsf } from './loadCsf';
21
- const STORAGE_KEY = 'lastOpenedStory';
22
- export default class Preview {
23
- constructor() {
24
- this.api = () => {
25
- return this._clientApi;
26
- };
27
- this.getStorybookUI = (params = {}) => {
28
- const { initialSelection, shouldPersistSelection = true } = params;
29
- this._setInitialStory(initialSelection, shouldPersistSelection);
30
- this._channel.on(Events.SET_CURRENT_STORY, (d) => {
31
- this._selectStoryEvent(d, shouldPersistSelection);
32
- });
33
- const { _storyStore } = this;
34
- addons.loadAddons(this._clientApi);
35
- const appliedTheme = Object.assign(Object.assign({}, theme), params.theme);
36
- return () => (React.createElement(ThemeProvider, { theme: appliedTheme },
37
- React.createElement(OnDeviceUI, { storyStore: _storyStore, isUIHidden: params.isUIHidden, tabOpen: params.tabOpen, shouldDisableKeyboardAvoidingView: params.shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset: params.keyboardAvoidingViewVerticalOffset })));
38
- };
39
- this._setInitialStory = (initialSelection, shouldPersistSelection = true) => __awaiter(this, void 0, void 0, function* () {
40
- const story = yield this._getInitialStory(initialSelection, shouldPersistSelection);
41
- if (story) {
42
- this._selectStory(story);
43
- }
44
- });
45
- this._getInitialStory = (initialSelection, shouldPersistSelection = true) => __awaiter(this, void 0, void 0, function* () {
46
- let story = null;
47
- const initialSelectionId = initialSelection
48
- ? toId(initialSelection.kind, initialSelection.name)
49
- : undefined;
50
- if (initialSelection && initialSelectionId && this._checkStory(initialSelectionId)) {
51
- story = initialSelectionId;
52
- }
53
- else if (shouldPersistSelection) {
54
- try {
55
- let value = this._asyncStorageStoryId;
56
- if (!value) {
57
- value = JSON.parse(yield AsyncStorage.getItem(STORAGE_KEY));
58
- this._asyncStorageStoryId = value;
59
- }
60
- if (this._checkStory(value)) {
61
- story = value;
62
- }
63
- }
64
- catch (e) {
65
- //
66
- }
67
- }
68
- if (story) {
69
- return this._getStory(story);
70
- }
71
- const stories = this._storyStore.raw();
72
- if (stories && stories.length) {
73
- return this._getStory(stories[0].id);
74
- }
75
- return null;
76
- });
77
- const channel = new Channel({ async: true });
78
- this._decorators = [];
79
- this._storyStore = new StoryStore({ channel });
80
- this._clientApi = new ClientApi({ storyStore: this._storyStore });
81
- this._configApi = new ConfigApi({ storyStore: this._storyStore });
82
- this._channel = channel;
83
- const configure = loadCsf({
84
- clientApi: this._clientApi,
85
- storyStore: this._storyStore,
86
- configApi: this._configApi,
87
- });
88
- this.configure = (...args) => configure('react-native', ...args);
89
- addons.setChannel(channel);
90
- }
91
- _getStory(storyId) {
92
- return this._storyStore.fromId(storyId);
93
- }
94
- _selectStoryEvent({ storyId }, shouldPersistSelection) {
95
- if (storyId) {
96
- if (shouldPersistSelection) {
97
- AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(storyId)).catch(() => { });
98
- }
99
- const story = this._getStory(storyId);
100
- this._selectStory(story);
101
- }
102
- }
103
- _selectStory(story) {
104
- this._storyStore.setSelection({ storyId: story.id, viewMode: 'story' });
105
- this._channel.emit(Events.SELECT_STORY, story);
106
- }
107
- _checkStory(storyId) {
108
- if (!storyId) {
109
- return null;
110
- }
111
- const story = this._getStory(storyId);
112
- if (story === null || story.storyFn === null) {
113
- return null;
114
- }
115
- return story;
116
- }
117
- }
@@ -1,8 +0,0 @@
1
- export {};
2
- declare global {
3
- namespace NodeJS {
4
- interface Global {
5
- previousExports: Map<any, string>;
6
- }
7
- }
8
- }
@@ -1 +0,0 @@
1
- export { default } from './Preview';
@@ -1 +0,0 @@
1
- export { default } from './Preview';
@@ -1,16 +0,0 @@
1
- /// <reference types="webpack-env" />
2
- /// <reference types="node" />
3
- import { ClientApi, ConfigApi, StoryStore } from '@storybook/client-api';
4
- import './global';
5
- export interface RequireContext {
6
- keys: () => string[];
7
- (id: string): any;
8
- resolve(id: string): string;
9
- }
10
- export declare type LoadableFunction = () => void | any[];
11
- export declare type Loadable = RequireContext | RequireContext[] | LoadableFunction;
12
- export declare const loadCsf: ({ clientApi, storyStore, configApi, }: {
13
- clientApi: ClientApi;
14
- storyStore: StoryStore;
15
- configApi: ConfigApi;
16
- }) => (framework: string, loadable: Loadable, m: NodeModule, showDeprecationWarning?: boolean) => void;
@@ -1,175 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { logger } from '@storybook/client-logger';
13
- import { isExportStory, storyNameFromExport, toId } from '@storybook/csf';
14
- import './global';
15
- const deprecatedStoryAnnotationWarning = () => logger.log(`
16
- CSF .story annotations deprecated; annotate story functions directly:
17
- - StoryFn.story.name => StoryFn.storyName
18
- - StoryFn.story.(parameters|decorators) => StoryFn.(parameters|decorators)
19
- See https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#hoisted-csf-annotations for details and codemod.
20
- `);
21
- const duplicateKindWarning = (kindName) => {
22
- logger.warn(`Duplicate title: '${kindName}'
23
- Duplicate title used in multiple files; use unique titles or a primary file for a component with re-exported stories.
24
-
25
- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-support-for-duplicate-kinds
26
- `);
27
- };
28
- global.previousExports = new Map();
29
- const loadStories = (loadable, framework, { clientApi, storyStore }) => () => {
30
- // Make sure we don't try to define a kind more than once within the same load
31
- const loadedKinds = new Set();
32
- let reqs = null;
33
- // todo discuss / improve type check
34
- if (Array.isArray(loadable)) {
35
- reqs = loadable;
36
- }
37
- else if (loadable.keys) {
38
- reqs = [loadable];
39
- }
40
- let currentExports = new Map();
41
- // reqs is not null when require context is used,
42
- // this comes from storybook core client and will never be true in RN
43
- // keeping this here only to get an idea how the core version could be re-used
44
- if (reqs) {
45
- reqs.forEach((req) => {
46
- req.keys().forEach((filename) => {
47
- try {
48
- const fileExports = req(filename);
49
- currentExports.set(fileExports,
50
- // todo discuss: types infer that this is RequireContext; no checks needed?
51
- // NOTE: turns out `babel-plugin-require-context-hook` doesn't implement this (yet)
52
- typeof req.resolve === 'function' ? req.resolve(filename) : filename);
53
- }
54
- catch (error) {
55
- logger.warn(`Unexpected error while loading ${filename}: ${error}`);
56
- }
57
- });
58
- });
59
- }
60
- else {
61
- const exported = loadable();
62
- if (Array.isArray(exported)) {
63
- const csfExports = exported.filter((obj) => obj.default != null);
64
- currentExports = new Map(csfExports.map((fileExports) => [fileExports, null]));
65
- }
66
- else {
67
- logger.warn(`Loader function passed to 'configure' should return void or an array of module exports that all contain a 'default' export. Received: ${JSON.stringify(exported)}`);
68
- }
69
- }
70
- const removed = Array.from(global.previousExports.keys()).filter((exp) => !currentExports.has(exp));
71
- removed.forEach((exp) => {
72
- if (exp.default) {
73
- storyStore.removeStoryKind(exp.default.title);
74
- }
75
- });
76
- const added = Array.from(currentExports.keys()).filter((exp) => !global.previousExports.has(exp));
77
- added.forEach((fileExports) => {
78
- // An old-style story file
79
- if (!fileExports.default) {
80
- return;
81
- }
82
- if (!fileExports.default.title) {
83
- throw new Error(`Unexpected default export without title: ${JSON.stringify(fileExports.default)}`);
84
- }
85
- const { default: meta, __namedExportsOrder } = fileExports, namedExports = __rest(fileExports, ["default", "__namedExportsOrder"]);
86
- let exports = namedExports;
87
- // prefer a user/loader provided `__namedExportsOrder` array if supplied
88
- // we do this as es module exports are always ordered alphabetically
89
- // see https://github.com/storybookjs/storybook/issues/9136
90
- if (Array.isArray(__namedExportsOrder)) {
91
- exports = {};
92
- __namedExportsOrder.forEach((name) => {
93
- if (namedExports[name]) {
94
- exports[name] = namedExports[name];
95
- }
96
- });
97
- }
98
- const { title: kindName, id: componentId, parameters: kindParameters, decorators: kindDecorators, loaders: kindLoaders = [], component, subcomponents, args: kindArgs, argTypes: kindArgTypes, } = meta;
99
- if (loadedKinds.has(kindName)) {
100
- duplicateKindWarning(kindName);
101
- }
102
- loadedKinds.add(kindName);
103
- // We pass true here to avoid the warning about HMR. It's cool clientApi, we got this
104
- // todo discuss: TS now wants a NodeModule; should we fix this differently?
105
- const kind = clientApi.storiesOf(kindName, true);
106
- // we should always have a framework, rest optional
107
- kind.addParameters(Object.assign(Object.assign({ framework,
108
- component,
109
- subcomponents, fileName: currentExports.get(fileExports) }, kindParameters), { args: kindArgs, argTypes: kindArgTypes }));
110
- // todo add type
111
- (kindDecorators || []).forEach((decorator) => {
112
- kind.addDecorator(decorator);
113
- });
114
- kindLoaders.forEach((loader) => {
115
- kind.addLoader(loader);
116
- });
117
- const storyExports = Object.keys(exports);
118
- if (storyExports.length === 0) {
119
- logger.warn(`
120
- Found a story file for "${kindName}" but no exported stories.
121
- Check the docs for reference: https://storybook.js.org/docs/formats/component-story-format/
122
- `);
123
- return;
124
- }
125
- storyExports.forEach((key) => {
126
- if (isExportStory(key, meta)) {
127
- const storyFn = exports[key];
128
- const { story } = storyFn;
129
- const name = story === null || story === void 0 ? void 0 : story.name;
130
- const { storyName = name } = storyFn;
131
- // storyFn.x and storyFn.story.x get merged with
132
- // storyFn.x taking precedence in the merge
133
- const parameters = Object.assign(Object.assign({}, story === null || story === void 0 ? void 0 : story.parameters), storyFn.parameters);
134
- const decorators = [...(storyFn.decorators || []), ...((story === null || story === void 0 ? void 0 : story.decorators) || [])];
135
- const loaders = [...(storyFn.loaders || []), ...((story === null || story === void 0 ? void 0 : story.loaders) || [])];
136
- const args = Object.assign(Object.assign({}, story === null || story === void 0 ? void 0 : story.args), storyFn.args);
137
- const argTypes = Object.assign(Object.assign({}, story === null || story === void 0 ? void 0 : story.argTypes), storyFn.argTypes);
138
- if (story) {
139
- logger.debug('deprecated story', story);
140
- deprecatedStoryAnnotationWarning();
141
- }
142
- const exportName = storyNameFromExport(key);
143
- const storyParams = Object.assign(Object.assign({}, parameters), { __id: toId(componentId || kindName, exportName), decorators,
144
- loaders,
145
- args,
146
- argTypes });
147
- kind.add(storyName || exportName, storyFn, storyParams);
148
- }
149
- });
150
- });
151
- global.previousExports = currentExports;
152
- };
153
- const configureDeprecationWarning = () => logger.log(`\`configure()\` is deprecated and will be removed in Storybook 7.0.
154
- Please use the \`stories\` field of \`main.js\` to load stories.
155
- Read more at https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-configure`);
156
- export const loadCsf = ({ clientApi, storyStore, configApi, }) =>
157
- /**
158
- * Load a collection of stories. If it has a default export, assume that it is a module-style
159
- * file and process its named exports as stories. If not, assume it's an old-style
160
- * storiesof file and require it.
161
- *
162
- * @param {*} framework - name of framework in use, e.g. "react"
163
- * @param {*} loadable a require.context `req`, an array of `req`s, or a loader function that returns void or an array of exports
164
- * @param {*} m - ES module object for hot-module-reloading (HMR)
165
- * @param {boolean} showDeprecationWarning - show the deprecation warning (default true)
166
- */
167
- (framework, loadable, m, showDeprecationWarning = true) => {
168
- if (showDeprecationWarning) {
169
- configureDeprecationWarning();
170
- }
171
- if (typeof m === 'string') {
172
- throw new Error(`Invalid module '${m}'. Did you forget to pass \`module\` as the second argument to \`configure\`"?`);
173
- }
174
- configApi.configure(loadStories(loadable, framework, { clientApi, storyStore }), m);
175
- };
@@ -1,34 +0,0 @@
1
- import { Annotations, Args as DefaultArgs, BaseMeta, BaseStory } from '@storybook/addons';
2
- import { ComponentProps, ComponentType, JSXElementConstructor, ReactElement } from 'react';
3
- export declare type StoryFnReactReturnType = ReactElement<unknown>;
4
- export type { Args, ArgTypes, Parameters, StoryContext } from '@storybook/addons';
5
- declare type ReactComponent = ComponentType<any>;
6
- declare type ReactReturnType = StoryFnReactReturnType;
7
- /**
8
- * Metadata to configure the stories for a component.
9
- *
10
- * @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
11
- */
12
- export declare type Meta<Args = DefaultArgs> = BaseMeta<ReactComponent> & Annotations<Args, ReactReturnType>;
13
- /**
14
- * Story function that represents a component example.
15
- *
16
- * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
17
- */
18
- export declare type Story<Args = DefaultArgs> = BaseStory<Args, ReactReturnType> & Annotations<Args, ReactReturnType>;
19
- /**
20
- * For the common case where a component's stories are simple components that receives args as props:
21
- *
22
- * ```tsx
23
- * export default { ... } as ComponentMeta<typeof Button>;
24
- * ```
25
- */
26
- export declare type ComponentMeta<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> = Meta<ComponentProps<T>>;
27
- /**
28
- * For the common case where a story is a simple component that receives args as props:
29
- *
30
- * ```tsx
31
- * const Template: ComponentStory<typeof Button> = (args) => <Button {...args} />
32
- * ```
33
- */
34
- export declare type ComponentStory<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> = Story<ComponentProps<T>>;