@storybook/react-native 6.0.1-canary.2 → 6.5.0-rc.0

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 (46) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/preview/View.d.ts +8 -0
  4. package/dist/preview/View.js +34 -4
  5. package/dist/preview/components/OnDeviceUI/OnDeviceUI.js +13 -3
  6. package/dist/preview/components/OnDeviceUI/animation.d.ts +11 -1
  7. package/dist/preview/components/OnDeviceUI/animation.js +9 -6
  8. package/dist/preview/components/StoryListView/StoryListView.js +1 -1
  9. package/dist/preview/executeLoadable.js +8 -12
  10. package/dist/preview/rn-host-detect.js +2 -3
  11. package/dist/preview/start.d.ts +0 -1
  12. package/dist/preview/start.js +27 -12
  13. package/dist/types/types-6.0.d.ts +47 -13
  14. package/package.json +13 -12
  15. package/scripts/__snapshots__/loader.test.js.snap +84 -11
  16. package/scripts/loader.js +55 -16
  17. package/scripts/loader.test.js +24 -0
  18. package/scripts/mocks/file-extensions/FakeComponent.tsx +1 -0
  19. package/scripts/mocks/file-extensions/FakeStory.stories.tsx +10 -0
  20. package/scripts/mocks/file-extensions/main.ts +13 -0
  21. package/scripts/mocks/file-extensions/preview.tsx +23 -0
  22. package/scripts/watcher.js +7 -4
  23. package/template/cli/index.js +7 -0
  24. package/template/cli/main.js +4 -0
  25. package/template/cli/preview.js +8 -0
  26. package/template/cli/stories/Button/Button.js +20 -0
  27. package/template/cli/stories/Button/Button.stories.js +31 -0
  28. package/template/cli/storybook.requires.js +58 -0
  29. package/dist/document-polyfill/DOM/Document.d.ts +0 -14
  30. package/dist/document-polyfill/DOM/Document.js +0 -37
  31. package/dist/document-polyfill/DOM/Element.d.ts +0 -37
  32. package/dist/document-polyfill/DOM/Element.js +0 -58
  33. package/dist/document-polyfill/DOM/HTMLCanvasElement.d.ts +0 -4
  34. package/dist/document-polyfill/DOM/HTMLCanvasElement.js +0 -4
  35. package/dist/document-polyfill/DOM/HTMLImageElement.d.ts +0 -4
  36. package/dist/document-polyfill/DOM/HTMLImageElement.js +0 -4
  37. package/dist/document-polyfill/DOM/HTMLVideoElement.d.ts +0 -4
  38. package/dist/document-polyfill/DOM/HTMLVideoElement.js +0 -4
  39. package/dist/document-polyfill/DOM/Node.d.ts +0 -26
  40. package/dist/document-polyfill/DOM/Node.js +0 -33
  41. package/dist/document-polyfill/index.d.ts +0 -1
  42. package/dist/document-polyfill/index.js +0 -3
  43. package/dist/document-polyfill/module.d.ts +0 -0
  44. package/dist/document-polyfill/module.js +0 -1
  45. package/dist/document-polyfill/module.native.d.ts +0 -1
  46. package/dist/document-polyfill/module.native.js +0 -2
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare const setAddon: C['setAddon'];
11
11
  export declare const addDecorator: C['addDecorator'];
12
12
  export declare const addParameters: C['addParameters'];
13
13
  export declare const addArgsEnhancer: C['addArgsEnhancer'];
14
+ export declare const addArgTypesEnhancer: C['addArgTypesEnhancer'];
14
15
  export declare const clearDecorators: C['clearDecorators'];
15
16
  export declare const getStorybook: C['getStorybook'];
16
17
  export declare const raw: C['raw'];
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export const setAddon = clientApi.setAddon.bind(clientApi);
6
6
  export const addDecorator = clientApi.addDecorator.bind(clientApi);
7
7
  export const addParameters = clientApi.addParameters.bind(clientApi);
8
8
  export const addArgsEnhancer = clientApi.addArgsEnhancer.bind(clientApi);
9
+ export const addArgTypesEnhancer = clientApi.addArgTypesEnhancer.bind(clientApi);
9
10
  export const clearDecorators = clientApi.clearDecorators.bind(clientApi);
10
11
  export const getStorybook = clientApi.getStorybook.bind(clientApi);
11
12
  export const raw = clientApi.raw.bind(clientApi);
@@ -17,6 +17,12 @@ declare type InitialSelection = `${StoryKind}--${StoryName}` | {
17
17
  name: StoryName;
18
18
  };
19
19
  export declare type Params = {
20
+ onDeviceUI?: boolean;
21
+ enableWebsockets?: boolean;
22
+ query?: string;
23
+ host?: string;
24
+ port?: number;
25
+ secured?: boolean;
20
26
  initialSelection?: InitialSelection;
21
27
  shouldPersistSelection?: boolean;
22
28
  tabOpen?: number;
@@ -33,8 +39,10 @@ export declare class View {
33
39
  _ready: boolean;
34
40
  _preview: PreviewWeb<ReactNativeFramework>;
35
41
  _asyncStorageStoryId: string;
42
+ _webUrl: string;
36
43
  constructor(preview: PreviewWeb<ReactNativeFramework>);
37
44
  _getInitialStory: ({ initialSelection, shouldPersistSelection, }?: Partial<Params>) => Promise<SelectionSpecifier>;
45
+ _getServerChannel: (params?: Partial<Params>) => import("@storybook/channels").Channel;
38
46
  getStorybookUI: (params?: Partial<Params>) => () => JSX.Element;
39
47
  }
40
48
  export {};
@@ -15,6 +15,10 @@ import { ThemeProvider } from 'emotion-theming';
15
15
  import { SafeAreaProvider } from 'react-native-safe-area-context';
16
16
  import OnDeviceUI from './components/OnDeviceUI';
17
17
  import { theme } from './components/Shared/theme';
18
+ import StoryView from './components/StoryView';
19
+ import createChannel from '@storybook/channel-websocket';
20
+ import getHost from './rn-host-detect';
21
+ import events from '@storybook/core-events';
18
22
  const STORAGE_KEY = 'lastOpenedStory';
19
23
  export class View {
20
24
  constructor(preview) {
@@ -47,9 +51,30 @@ export class View {
47
51
  }
48
52
  return { storySpecifier: '*', viewMode: 'story' };
49
53
  });
54
+ this._getServerChannel = (params = {}) => {
55
+ const host = getHost(params.host || 'localhost');
56
+ const port = `:${params.port || 7007}`;
57
+ const query = params.query || '';
58
+ const websocketType = params.secured ? 'wss' : 'ws';
59
+ const url = `${websocketType}://${host}${port}/${query}`;
60
+ return createChannel({
61
+ url,
62
+ async: true,
63
+ onError: () => __awaiter(this, void 0, void 0, function* () { }),
64
+ });
65
+ };
50
66
  this.getStorybookUI = (params = {}) => {
51
- const { shouldPersistSelection = true } = params;
67
+ const { shouldPersistSelection = true, onDeviceUI = true, enableWebsockets = false } = params;
52
68
  const initialStory = this._getInitialStory(params);
69
+ if (enableWebsockets) {
70
+ const channel = this._getServerChannel(params);
71
+ addons.setChannel(channel);
72
+ // TODO: check this with someone who knows what they're doing
73
+ this._preview.channel = channel;
74
+ this._preview.setupListeners();
75
+ channel.emit(events.CHANNEL_CREATED);
76
+ this._preview.initializeWithStoryIndex(this._storyIndex);
77
+ }
53
78
  addons.loadAddons({
54
79
  store: () => ({
55
80
  fromId: (id) => this._preview.storyStore.getStoryContext(this._preview.storyStore.fromId(id)),
@@ -80,9 +105,14 @@ export class View {
80
105
  self._preview.selectSpecifiedStory();
81
106
  });
82
107
  }, []);
83
- return (React.createElement(SafeAreaProvider, null,
84
- React.createElement(ThemeProvider, { theme: appliedTheme },
85
- React.createElement(OnDeviceUI, { context: context, storyIndex: self._storyIndex, isUIHidden: params.isUIHidden, tabOpen: params.tabOpen, shouldDisableKeyboardAvoidingView: params.shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset: params.keyboardAvoidingViewVerticalOffset }))));
108
+ if (onDeviceUI) {
109
+ return (React.createElement(SafeAreaProvider, null,
110
+ React.createElement(ThemeProvider, { theme: appliedTheme },
111
+ React.createElement(OnDeviceUI, { context: context, storyIndex: self._storyIndex, isUIHidden: params.isUIHidden, tabOpen: params.tabOpen, shouldDisableKeyboardAvoidingView: params.shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset: params.keyboardAvoidingViewVerticalOffset }))));
112
+ }
113
+ else {
114
+ return React.createElement(StoryView, { context: context });
115
+ }
86
116
  };
87
117
  };
88
118
  this._preview = preview;
@@ -65,12 +65,19 @@ const OnDeviceUI = ({ context, storyIndex, isUIHidden, shouldDisableKeyboardAvoi
65
65
  Keyboard.dismiss();
66
66
  }
67
67
  };
68
+ const noSafeArea = (_b = (_a = context === null || context === void 0 ? void 0 : context.parameters) === null || _a === void 0 ? void 0 : _a.noSafeArea) !== null && _b !== void 0 ? _b : false;
68
69
  const previewWrapperStyles = [
69
70
  flex,
70
- getPreviewPosition(animatedValue.current, previewDimensions, slideBetweenAnimation, wide),
71
+ getPreviewPosition({
72
+ animatedValue: animatedValue.current,
73
+ previewDimensions,
74
+ slideBetweenAnimation,
75
+ wide,
76
+ noSafeArea,
77
+ insets,
78
+ }),
71
79
  ];
72
80
  const previewStyles = [flex, getPreviewScale(animatedValue.current, slideBetweenAnimation, wide)];
73
- const noSafeArea = (_b = (_a = context === null || context === void 0 ? void 0 : context.parameters) === null || _a === void 0 ? void 0 : _a.noSafeArea) !== null && _b !== void 0 ? _b : false;
74
81
  const WrapperView = noSafeArea ? View : SafeAreaView;
75
82
  const wrapperMargin = { marginBottom: isUIVisible ? insets.bottom + 40 : 0 };
76
83
  return (React.createElement(React.Fragment, null,
@@ -85,7 +92,10 @@ const OnDeviceUI = ({ context, storyIndex, isUIHidden, shouldDisableKeyboardAvoi
85
92
  tabOpen !== PREVIEW ? (React.createElement(TouchableOpacity, { style: absolutePosition, onPress: () => handleToggleTab(PREVIEW) })) : null)),
86
93
  React.createElement(Panel, { style: getNavigatorPanelPosition(animatedValue.current, previewDimensions.width, wide) },
87
94
  React.createElement(StoryListView, { storyIndex: storyIndex, selectedStoryContext: context })),
88
- React.createElement(Panel, { style: getAddonPanelPosition(animatedValue.current, previewDimensions.width, wide) },
95
+ React.createElement(Panel, { style: [
96
+ getAddonPanelPosition(animatedValue.current, previewDimensions.width, wide),
97
+ wrapperMargin,
98
+ ] },
89
99
  React.createElement(Addons, { active: tabOpen === ADDONS })))),
90
100
  React.createElement(Navigation, { tabOpen: tabOpen, onChangeTab: handleToggleTab, isUIVisible: isUIVisible, setIsUIVisible: setIsUIVisible }))));
91
101
  };
@@ -1,4 +1,5 @@
1
1
  import { Animated } from 'react-native';
2
+ import { EdgeInsets } from 'react-native-safe-area-context';
2
3
  import { PreviewDimens } from './absolute-positioned-keyboard-aware-view';
3
4
  export declare const getNavigatorPanelPosition: (animatedValue: Animated.Value, previewWidth: number, wide: boolean) => {
4
5
  transform: {
@@ -12,7 +13,15 @@ export declare const getAddonPanelPosition: (animatedValue: Animated.Value, prev
12
13
  }[];
13
14
  width: number;
14
15
  }[];
15
- export declare const getPreviewPosition: (animatedValue: Animated.Value, { width: previewWidth, height: previewHeight }: PreviewDimens, slideBetweenAnimation: boolean, wide: boolean) => {
16
+ declare type PreviewPositionArgs = {
17
+ animatedValue: Animated.Value;
18
+ previewDimensions: PreviewDimens;
19
+ slideBetweenAnimation: boolean;
20
+ wide: boolean;
21
+ noSafeArea: boolean;
22
+ insets: EdgeInsets;
23
+ };
24
+ export declare const getPreviewPosition: ({ animatedValue, previewDimensions: { width: previewWidth, height: previewHeight }, slideBetweenAnimation, wide, noSafeArea, insets, }: PreviewPositionArgs) => {
16
25
  transform: ({
17
26
  translateX: Animated.AnimatedInterpolation<string | number>;
18
27
  translateY?: undefined;
@@ -26,3 +35,4 @@ export declare const getPreviewScale: (animatedValue: Animated.Value, slideBetwe
26
35
  scale: Animated.AnimatedInterpolation<string | number>;
27
36
  }[];
28
37
  };
38
+ export {};
@@ -1,4 +1,6 @@
1
+ import { I18nManager } from 'react-native';
1
2
  import { NAVIGATOR, PREVIEW, ADDONS } from './navigation/constants';
3
+ const RTL_SCALE = I18nManager.isRTL ? -1 : 1;
2
4
  const PREVIEW_SCALE = 0.3;
3
5
  const PREVIEW_WIDE_SCREEN = 0.7;
4
6
  const SCALE_OFFSET = 0.025;
@@ -15,7 +17,7 @@ export const getNavigatorPanelPosition = (animatedValue, previewWidth, wide) =>
15
17
  {
16
18
  translateX: animatedValue.interpolate({
17
19
  inputRange: [NAVIGATOR, PREVIEW],
18
- outputRange: [0, -panelWidth(previewWidth, wide) - 1],
20
+ outputRange: [0, (-panelWidth(previewWidth, wide) - 1) * RTL_SCALE],
19
21
  }),
20
22
  },
21
23
  ],
@@ -30,7 +32,7 @@ export const getAddonPanelPosition = (animatedValue, previewWidth, wide) => {
30
32
  {
31
33
  translateX: animatedValue.interpolate({
32
34
  inputRange: [PREVIEW, ADDONS],
33
- outputRange: [previewWidth, previewWidth - panelWidth(previewWidth, wide)],
35
+ outputRange: [previewWidth * RTL_SCALE, (previewWidth - panelWidth(previewWidth, wide)) * RTL_SCALE],
34
36
  }),
35
37
  },
36
38
  ],
@@ -38,10 +40,11 @@ export const getAddonPanelPosition = (animatedValue, previewWidth, wide) => {
38
40
  },
39
41
  ];
40
42
  };
41
- export const getPreviewPosition = (animatedValue, { width: previewWidth, height: previewHeight }, slideBetweenAnimation, wide) => {
43
+ export const getPreviewPosition = ({ animatedValue, previewDimensions: { width: previewWidth, height: previewHeight }, slideBetweenAnimation, wide, noSafeArea, insets, }) => {
42
44
  const scale = wide ? PREVIEW_WIDE_SCREEN : PREVIEW_SCALE;
43
- const translateX = previewWidth / 2 - (previewWidth * scale) / 2 - TRANSLATE_X_OFFSET;
44
- const translateY = -(previewHeight / 2 - (previewHeight * scale) / 2 - TRANSLATE_Y_OFFSET);
45
+ const translateX = (previewWidth / 2 - (previewWidth * scale) / 2 - TRANSLATE_X_OFFSET) * RTL_SCALE;
46
+ const marginTop = noSafeArea ? 0 : insets.top;
47
+ const translateY = -(previewHeight / 2 - (previewHeight * scale) / 2 - TRANSLATE_Y_OFFSET) + marginTop;
45
48
  return {
46
49
  transform: [
47
50
  {
@@ -53,7 +56,7 @@ export const getPreviewPosition = (animatedValue, { width: previewWidth, height:
53
56
  {
54
57
  translateY: animatedValue.interpolate({
55
58
  inputRange: [NAVIGATOR, PREVIEW, ADDONS],
56
- outputRange: [translateY, slideBetweenAnimation ? translateY : 0, translateY],
59
+ outputRange: [translateY, slideBetweenAnimation ? translateY : marginTop, translateY],
57
60
  }),
58
61
  },
59
62
  ],
@@ -43,7 +43,7 @@ const ItemTouchable = styled.TouchableOpacity({
43
43
  paddingLeft: 40,
44
44
  flexDirection: 'row',
45
45
  alignItems: 'center',
46
- }, ({ selected, theme }) => (selected ? { backgroundColor: theme.listItemActiveColor } : {}));
46
+ }, ({ selected, theme }) => { var _a; return (selected ? { backgroundColor: (_a = theme === null || theme === void 0 ? void 0 : theme.listItemActiveColor) !== null && _a !== void 0 ? _a : '#1ea7fd' } : {}); });
47
47
  const ListItem = React.memo(({ kind, title, selected, onPress }) => (React.createElement(ItemTouchable, { key: title, onPress: onPress, activeOpacity: 0.8, testID: `Storybook.ListItem.${kind}.${title}`, accessibilityLabel: `Storybook.ListItem.${title}`, selected: selected },
48
48
  React.createElement(StoryIcon, { selected: selected }),
49
49
  React.createElement(Name, { selected: selected }, title))), (prevProps, nextProps) => prevProps.selected === nextProps.selected);
@@ -13,7 +13,7 @@ export function executeLoadable(loadable) {
13
13
  reqs = loadable;
14
14
  }
15
15
  else if (loadable.keys) {
16
- reqs = [loadable];
16
+ reqs = [loadable]; // todo: test with metro require context
17
17
  }
18
18
  let exportsMap = new Map();
19
19
  if (reqs) {
@@ -32,17 +32,10 @@ export function executeLoadable(loadable) {
32
32
  }
33
33
  else {
34
34
  const exported = loadable();
35
- if (Array.isArray(exported) /*FIXME && exported.every((obj) => obj.default != null)*/) {
36
- const csfExports = exported.filter((obj) => obj.default != null);
37
- exportsMap = new Map(csfExports.map((fileExports, index) => [`exports-map-${index}`, fileExports]));
35
+ if (typeof exported === 'object') {
36
+ const csfExports = Object.entries(exported).filter(([_key, value]) => value.default != null);
37
+ exportsMap = new Map(csfExports.map(([filePath, fileExports]) => [filePath, fileExports]));
38
38
  }
39
- // else if (exported) {
40
- // logger.warn(
41
- // `Loader function passed to 'configure' should return void or an array of module exports that all contain a 'default' export. Received: ${JSON.stringify(
42
- // exported
43
- // )}`
44
- // );
45
- // }
46
39
  }
47
40
  return exportsMap;
48
41
  }
@@ -56,7 +49,10 @@ global.lastExportsMap = new Map();
56
49
  * @returns { added: Map<Path, ModuleExports>, removed: Map<Path, ModuleExports> }
57
50
  */
58
51
  export function executeLoadableForChanges(loadable, m) {
59
- m.hot.accept();
52
+ var _a;
53
+ if ((_a = m === null || m === void 0 ? void 0 : m.hot) === null || _a === void 0 ? void 0 : _a.accept) {
54
+ m.hot.accept();
55
+ }
60
56
  const lastExportsMap = global.lastExportsMap;
61
57
  const exportsMap = executeLoadable(loadable);
62
58
  const added = new Map();
@@ -4,9 +4,8 @@
4
4
  * When __DEV__ === false, we can't use window.require('NativeModules')
5
5
  */
6
6
  function getByRemoteConfig(hostname) {
7
- var remoteModuleConfig = typeof window !== 'undefined' &&
8
- window.__fbBatchedBridgeConfig &&
9
- window.__fbBatchedBridgeConfig.remoteModuleConfig;
7
+ var _a;
8
+ var remoteModuleConfig = (_a = window === null || window === void 0 ? void 0 : window.__fbBatchedBridgeConfig) === null || _a === void 0 ? void 0 : _a.remoteModuleConfig;
10
9
  if (!Array.isArray(remoteModuleConfig) ||
11
10
  (hostname !== 'localhost' && hostname !== '127.0.0.1')) {
12
11
  return { hostname: hostname, passed: false };
@@ -5,7 +5,6 @@ import { PreviewWeb } from '@storybook/preview-web';
5
5
  import { ClientApi } from '@storybook/client-api';
6
6
  import type { ReactNativeFramework } from '../types/types-6.0';
7
7
  import { View } from './View';
8
- import '../document-polyfill';
9
8
  import type { ArgsStoryFn } from '@storybook/csf';
10
9
  export declare const render: ArgsStoryFn<ReactNativeFramework>;
11
10
  export declare function start(): {
@@ -6,7 +6,6 @@ import { PreviewWeb } from '@storybook/preview-web';
6
6
  import { ClientApi, setGlobalRender } from '@storybook/client-api';
7
7
  import { View } from './View';
8
8
  import { executeLoadableForChanges } from './executeLoadable';
9
- import '../document-polyfill';
10
9
  export const render = (args, context) => {
11
10
  const { id, component: Component } = context;
12
11
  if (!Component) {
@@ -15,14 +14,32 @@ export const render = (args, context) => {
15
14
  return React.createElement(Component, Object.assign({}, args));
16
15
  };
17
16
  export function start() {
18
- var _a, _b, _c, _d, _e, _f, _g, _h;
17
+ // TODO: can we get settings from main.js and set the channel here?
19
18
  const channel = new Channel({ async: true });
20
19
  addons.setChannel(channel);
21
20
  const clientApi = new ClientApi();
22
- const preview = new PreviewWeb();
23
- clientApi.storyStore = preview.storyStore;
24
- setGlobalRender(render);
25
- preview.urlStore = {
21
+ const previewView = {
22
+ prepareForStory: () => null,
23
+ showNoPreview: () => { },
24
+ showPreparingStory: () => { },
25
+ applyLayout: () => { },
26
+ showErrorDisplay: (e) => {
27
+ console.log(e);
28
+ },
29
+ showStoryDuringRender: () => { },
30
+ showMain: () => { },
31
+ checkIfLayoutExists: () => { },
32
+ showStory: () => { },
33
+ docsRoot: null,
34
+ prepareForDocs: () => null,
35
+ showDocs: () => { },
36
+ preparingTimeout: setTimeout(() => { }, 0),
37
+ showMode: () => { },
38
+ showPreparingDocs: () => { },
39
+ storyRoot: null,
40
+ testing: false,
41
+ };
42
+ const urlStore = {
26
43
  selection: { storyId: '', viewMode: 'story' },
27
44
  selectionSpecifier: null,
28
45
  setQueryParams: () => { },
@@ -30,11 +47,9 @@ export function start() {
30
47
  preview.urlStore.selection = selection;
31
48
  },
32
49
  };
33
- preview.view = Object.assign(Object.assign({}, preview.view), { prepareForStory: () => null, showNoPreview: () => { }, showPreparingStory: () => { }, applyLayout: () => { }, showErrorDisplay: (e) => {
34
- console.log(e);
35
- }, showStoryDuringRender: () => { }, showMain: () => { },
36
- // these are just to make typescript happy
37
- showDocs: (_a = preview.view) === null || _a === void 0 ? void 0 : _a.showDocs, storyRoot: (_b = preview.view) === null || _b === void 0 ? void 0 : _b.storyRoot, prepareForDocs: (_c = preview.view) === null || _c === void 0 ? void 0 : _c.prepareForDocs, docsRoot: (_d = preview.view) === null || _d === void 0 ? void 0 : _d.docsRoot, checkIfLayoutExists: (_e = preview.view) === null || _e === void 0 ? void 0 : _e.checkIfLayoutExists, showMode: (_f = preview.view) === null || _f === void 0 ? void 0 : _f.showMode, showPreparingDocs: (_g = preview.view) === null || _g === void 0 ? void 0 : _g.showPreparingDocs, showStory: (_h = preview.view) === null || _h === void 0 ? void 0 : _h.showStory });
50
+ const preview = new PreviewWeb(urlStore, previewView);
51
+ clientApi.storyStore = preview.storyStore;
52
+ setGlobalRender(render);
38
53
  let initialized = false;
39
54
  function onStoriesChanged() {
40
55
  const storyIndex = clientApi.getStoryIndex();
@@ -48,7 +63,7 @@ export function start() {
48
63
  clientApi,
49
64
  preview,
50
65
  // This gets called each time the user calls configure (i.e. once per HMR)
51
- // The first time, it constructs the preview, subsequently it updates it
66
+ // The first time, it constructs thecurrentSelection preview, subsequently it updates it
52
67
  configure(loadable, m) {
53
68
  clientApi.addParameters({ framework: 'react-native' });
54
69
  // We need to run the `executeLoadableForChanges` function *inside* the `getProjectAnnotations
@@ -1,38 +1,72 @@
1
- import { Annotations, Args as DefaultArgs, BaseMeta, BaseStory } from '@storybook/addons';
2
1
  import { ComponentProps, ComponentType, JSXElementConstructor, ReactElement } from 'react';
2
+ import type { Args, ComponentAnnotations, StoryAnnotations, AnnotatedStoryFn } from '@storybook/csf';
3
3
  export declare type StoryFnReactReturnType = ReactElement<unknown>;
4
4
  export type { Args, ArgTypes, Parameters, StoryContext } from '@storybook/addons';
5
- declare type ReactComponent = ComponentType<any>;
6
- declare type ReactReturnType = StoryFnReactReturnType;
7
5
  export declare type ReactNativeFramework = {
8
6
  component: ComponentType<any>;
9
7
  storyResult: StoryFnReactReturnType;
10
8
  };
11
9
  /**
12
- * Metadata to configure the stories for a component.
10
+ * For the common case where a component's stories are simple components that receives args as props:
13
11
  *
14
- * @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
12
+ * ```tsx
13
+ * export default { ... } as ComponentMeta<typeof Button>;
14
+ * ```
15
15
  */
16
- export declare type Meta<Args = DefaultArgs> = BaseMeta<ReactComponent> & Annotations<Args, ReactReturnType>;
16
+ export declare type ComponentMeta<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> = Meta<ComponentProps<T>>;
17
17
  /**
18
- * Story function that represents a component example.
18
+ * For the common case where a (CSFv2) story is a simple component that receives args as props:
19
19
  *
20
- * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
20
+ * ```tsx
21
+ * const Template: ComponentStory<typeof Button> = (args) => <Button {...args} />
22
+ * ```
21
23
  */
22
- export declare type Story<Args = DefaultArgs> = BaseStory<Args, ReactReturnType> & Annotations<Args, ReactReturnType>;
24
+ export declare type ComponentStoryFn<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> = StoryFn<ComponentProps<T>>;
23
25
  /**
24
- * For the common case where a component's stories are simple components that receives args as props:
26
+ * For the common case where a (CSFv3) story is a simple component that receives args as props:
25
27
  *
26
28
  * ```tsx
27
- * export default { ... } as ComponentMeta<typeof Button>;
29
+ * const MyStory: ComponentStory<typeof Button> = {
30
+ * args: { buttonArg1: 'val' },
31
+ * }
28
32
  * ```
29
33
  */
30
- export declare type ComponentMeta<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> = Meta<ComponentProps<T>>;
34
+ export declare type ComponentStoryObj<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> = StoryObj<ComponentProps<T>>;
31
35
  /**
32
- * For the common case where a story is a simple component that receives args as props:
36
+ * For the common case where a (CSFv2) story is a simple component that receives args as props:
33
37
  *
34
38
  * ```tsx
35
39
  * const Template: ComponentStory<typeof Button> = (args) => <Button {...args} />
36
40
  * ```
41
+ *
42
+ * NOTE: this is an alias for `ComponentStoryFn`.
43
+ * In Storybook v7, `ComponentStory` will alias `ComponentStoryObj`
37
44
  */
38
45
  export declare type ComponentStory<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> = Story<ComponentProps<T>>;
46
+ /**
47
+ * Metadata to configure the stories for a component.
48
+ *
49
+ * @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
50
+ */
51
+ export declare type Meta<TArgs = Args> = ComponentAnnotations<ReactNativeFramework, TArgs>;
52
+ /**
53
+ * Story function that represents a CSFv2 component example.
54
+ *
55
+ * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
56
+ */
57
+ export declare type StoryFn<TArgs = Args> = AnnotatedStoryFn<ReactNativeFramework, TArgs>;
58
+ /**
59
+ * Story function that represents a CSFv3 component example.
60
+ *
61
+ * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
62
+ */
63
+ export declare type StoryObj<TArgs = Args> = StoryAnnotations<ReactNativeFramework, TArgs>;
64
+ /**
65
+ * Story function that represents a CSFv2 component example.
66
+ *
67
+ * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
68
+ *
69
+ * NOTE that in Storybook 7.0, this type will be renamed to `StoryFn` and replaced by the current `StoryObj` type.
70
+ *
71
+ */
72
+ export declare type Story<TArgs = Args> = StoryFn<TArgs>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react-native",
3
- "version": "6.0.1-canary.2",
3
+ "version": "6.5.0-rc.0",
4
4
  "description": "A better way to develop React Native Components for your app",
5
5
  "keywords": [
6
6
  "react",
@@ -28,7 +28,8 @@
28
28
  "README.md",
29
29
  "*.js",
30
30
  "*.d.ts",
31
- "scripts/*"
31
+ "scripts/*",
32
+ "template/**/*"
32
33
  ],
33
34
  "scripts": {
34
35
  "preprepare": "rm -rf dist/",
@@ -49,15 +50,15 @@
49
50
  "dependencies": {
50
51
  "@emotion/core": "^10.0.20",
51
52
  "@emotion/native": "^10.0.14",
52
- "@storybook/addons": "^6.5",
53
- "@storybook/channel-websocket": "^6.5",
54
- "@storybook/channels": "^6.5",
55
- "@storybook/client-api": "^6.5",
56
- "@storybook/client-logger": "^6.5",
57
- "@storybook/core-client": "^6.5",
58
- "@storybook/core-events": "^6.5",
59
- "@storybook/csf": "0.0.2--canary.7c6c115.0",
60
- "@storybook/preview-web": "^6.5",
53
+ "@storybook/addons": "^6.5.14",
54
+ "@storybook/channel-websocket": "^6.5.14",
55
+ "@storybook/channels": "^6.5.14",
56
+ "@storybook/client-api": "^6.5.14",
57
+ "@storybook/client-logger": "^6.5.14",
58
+ "@storybook/core-client": "^6.5.14",
59
+ "@storybook/core-events": "^6.5.14",
60
+ "@storybook/csf": "0.0.2--canary.4566f4d.1",
61
+ "@storybook/preview-web": "^6.5.14",
61
62
  "chokidar": "^3.5.1",
62
63
  "commander": "^8.2.0",
63
64
  "emotion-theming": "^10.0.19",
@@ -85,5 +86,5 @@
85
86
  "publishConfig": {
86
87
  "access": "public"
87
88
  },
88
- "gitHead": "52a7417c1da6d6056924a03882eb82f592d88678"
89
+ "gitHead": "9ce9d2794c2b7f1f3c177efb8563862255389f07"
89
90
  }