@storybook/react-native 6.0.1-beta.7 → 6.0.1-canary.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 (66) 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 +13 -12
  20. package/dist/index.js +13 -17
  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 +26 -37
  25. package/dist/preview/components/OnDeviceUI/Panel.js +1 -0
  26. package/dist/preview/components/OnDeviceUI/animation.d.ts +5 -5
  27. package/dist/preview/components/OnDeviceUI/navigation/Bar.d.ts +3 -1
  28. package/dist/preview/components/OnDeviceUI/navigation/Bar.js +1 -1
  29. package/dist/preview/components/OnDeviceUI/navigation/Navigation.d.ts +4 -3
  30. package/dist/preview/components/OnDeviceUI/navigation/Navigation.js +15 -10
  31. package/dist/preview/components/OnDeviceUI/navigation/VisibilityButton.d.ts +3 -1
  32. package/dist/preview/components/OnDeviceUI/navigation/VisibilityButton.js +34 -5
  33. package/dist/preview/components/Shared/icons.d.ts +1 -0
  34. package/dist/preview/components/Shared/text.d.ts +3 -44
  35. package/dist/preview/components/StoryListView/StoryListView.d.ts +7 -4
  36. package/dist/preview/components/StoryListView/StoryListView.js +24 -15
  37. package/dist/preview/components/StoryView/StoryView.d.ts +5 -3
  38. package/dist/preview/components/StoryView/StoryView.js +6 -24
  39. package/dist/preview/executeLoadable.d.ts +24 -0
  40. package/dist/preview/executeLoadable.js +82 -0
  41. package/dist/preview/rn-host-detect.d.ts +1 -0
  42. package/dist/preview/rn-host-detect.js +62 -0
  43. package/dist/preview/start.d.ts +13 -0
  44. package/dist/preview/start.js +75 -0
  45. package/dist/{types-6.0.d.ts → types/types-6.0.d.ts} +4 -0
  46. package/dist/types/types-6.0.js +1 -0
  47. package/dist/types/types.d.ts +14 -0
  48. package/dist/types/types.js +1 -0
  49. package/package.json +16 -13
  50. package/scripts/loader.js +11 -2
  51. package/scripts/loader.test.js +23 -5
  52. package/scripts/mocks/preview-files/js/preview.js +24 -0
  53. package/scripts/mocks/preview-files/jsx/preview.jsx +24 -0
  54. package/scripts/mocks/preview-files/ts/preview.ts +9 -0
  55. package/scripts/mocks/preview-files/tsx/preview.tsx +9 -0
  56. package/scripts/mocks/wrong-extension-preview/FakeComponent.tsx +1 -0
  57. package/scripts/mocks/wrong-extension-preview/FakeStory.stories.tsx +10 -0
  58. package/scripts/mocks/wrong-extension-preview/main.js +9 -0
  59. package/scripts/mocks/wrong-extension-preview/preview.txt +24 -0
  60. package/dist/preview/Preview.d.ts +0 -57
  61. package/dist/preview/Preview.js +0 -119
  62. package/dist/preview/global.d.ts +0 -8
  63. package/dist/preview/index.d.ts +0 -1
  64. package/dist/preview/index.js +0 -1
  65. package/dist/preview/loadCsf.d.ts +0 -16
  66. package/dist/preview/loadCsf.js +0 -180
@@ -10,7 +10,7 @@ const Container = styled.View(({ theme }) => ({
10
10
  borderBottomWidth: 1,
11
11
  borderColor: theme.borderColor || '#e6e6e6',
12
12
  }));
13
- const Bar = ({ index, onPress }) => (React.createElement(Container, null,
13
+ const Bar = ({ index, onPress, style }) => (React.createElement(Container, { style: style },
14
14
  React.createElement(Button, { onPress: onPress, testID: "BottomMenu.Navigator", id: NAVIGATOR, active: index === NAVIGATOR }, "NAVIGATOR"),
15
15
  React.createElement(Button, { onPress: onPress, testID: "BottomMenu.Preview", id: PREVIEW, active: index === PREVIEW }, "PREVIEW"),
16
16
  React.createElement(Button, { onPress: onPress, testID: "BottomMenu.Addons", id: ADDONS, active: index === ADDONS }, "ADDONS")));
@@ -1,8 +1,9 @@
1
- import React from 'react';
1
+ import React, { Dispatch, SetStateAction } from 'react';
2
2
  interface Props {
3
- initialUiVisible?: boolean;
4
3
  tabOpen: number;
5
4
  onChangeTab: (index: number) => void;
5
+ isUIVisible: boolean;
6
+ setIsUIVisible: Dispatch<SetStateAction<boolean>>;
6
7
  }
7
- declare const _default: React.MemoExoticComponent<({ tabOpen, onChangeTab, initialUiVisible }: Props) => JSX.Element>;
8
+ declare const _default: React.MemoExoticComponent<({ tabOpen, onChangeTab, isUIVisible, setIsUIVisible }: Props) => JSX.Element>;
8
9
  export default _default;
@@ -1,5 +1,6 @@
1
- import React, { useState } from 'react';
2
- import { View, SafeAreaView } from 'react-native';
1
+ import React from 'react';
2
+ import { View } from 'react-native';
3
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
3
4
  import GestureRecognizer from 'react-native-swipe-gestures';
4
5
  import Bar from './Bar';
5
6
  import VisibilityButton from './VisibilityButton';
@@ -7,8 +8,14 @@ const SWIPE_CONFIG = {
7
8
  velocityThreshold: 0.2,
8
9
  directionalOffsetThreshold: 80,
9
10
  };
10
- const Navigation = ({ tabOpen, onChangeTab, initialUiVisible }) => {
11
- const [isUIVisible, setIsUIVisible] = useState(initialUiVisible !== undefined ? initialUiVisible : true);
11
+ const navStyle = {
12
+ position: 'absolute',
13
+ left: 0,
14
+ right: 0,
15
+ bottom: 0,
16
+ };
17
+ const Navigation = ({ tabOpen, onChangeTab, isUIVisible, setIsUIVisible }) => {
18
+ const insets = useSafeAreaInsets();
12
19
  const handleToggleUI = () => {
13
20
  setIsUIVisible((oldIsUIVisible) => !oldIsUIVisible);
14
21
  };
@@ -22,11 +29,9 @@ const Navigation = ({ tabOpen, onChangeTab, initialUiVisible }) => {
22
29
  onChangeTab(tabOpen - 1);
23
30
  }
24
31
  };
25
- return (React.createElement(View, null,
26
- React.createElement(SafeAreaView, null,
27
- isUIVisible && (React.createElement(GestureRecognizer, { onSwipeLeft: handleSwipeLeft, onSwipeRight: handleSwipeRight, config: SWIPE_CONFIG },
28
- React.createElement(Bar, { index: tabOpen, onPress: onChangeTab }))),
29
- React.createElement(View, null,
30
- React.createElement(VisibilityButton, { onPress: handleToggleUI })))));
32
+ return (React.createElement(View, { style: navStyle },
33
+ isUIVisible && (React.createElement(GestureRecognizer, { onSwipeLeft: handleSwipeLeft, onSwipeRight: handleSwipeRight, config: SWIPE_CONFIG },
34
+ React.createElement(Bar, { index: tabOpen, onPress: onChangeTab, style: { paddingBottom: insets.bottom } }))),
35
+ React.createElement(VisibilityButton, { onPress: handleToggleUI, style: { marginBottom: insets.bottom } })));
31
36
  };
32
37
  export default React.memo(Navigation);
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
+ import { StyleProp, ViewStyle } from 'react-native';
2
3
  interface Props {
3
4
  onPress: () => void;
5
+ style?: StyleProp<ViewStyle>;
4
6
  }
5
- declare const _default: React.MemoExoticComponent<({ onPress }: Props) => JSX.Element>;
7
+ declare const _default: React.MemoExoticComponent<({ onPress, style }: Props) => JSX.Element>;
6
8
  export default _default;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import styled from '@emotion/native';
3
+ import { View } from 'react-native';
3
4
  const Touchable = styled.TouchableOpacity({
4
5
  backgroundColor: 'transparent',
5
6
  position: 'absolute',
@@ -7,10 +8,38 @@ const Touchable = styled.TouchableOpacity({
7
8
  bottom: 12,
8
9
  zIndex: 100,
9
10
  });
10
- const HideIcon = styled.Text(({ theme }) => ({
11
- fontSize: 14,
12
- color: theme.buttonTextColor || '#999999',
11
+ const HIDE_ICON_SIZE = 14;
12
+ const HIDE_ICON_BORDER_WIDTH = 1;
13
+ const Inner = styled.View(({ theme }) => ({
14
+ position: 'absolute',
15
+ top: 0,
16
+ left: 0,
17
+ width: HIDE_ICON_SIZE,
18
+ height: HIDE_ICON_SIZE,
19
+ borderRadius: HIDE_ICON_BORDER_WIDTH,
20
+ overflow: 'hidden',
21
+ borderColor: theme.buttonTextColor || '#999999',
22
+ borderWidth: HIDE_ICON_BORDER_WIDTH * 2,
13
23
  }));
14
- const VisibilityButton = ({ onPress }) => (React.createElement(Touchable, { onPress: onPress, testID: "Storybook.OnDeviceUI.toggleUI", accessibilityLabel: "Storybook.OnDeviceUI.toggleUI", hitSlop: { top: 5, left: 5, bottom: 5, right: 5 } },
15
- React.createElement(HideIcon, null, "\u25A1")));
24
+ const Outer = styled.View({
25
+ position: 'absolute',
26
+ top: 0,
27
+ left: 0,
28
+ width: HIDE_ICON_SIZE,
29
+ height: HIDE_ICON_SIZE,
30
+ borderRadius: HIDE_ICON_BORDER_WIDTH,
31
+ overflow: 'hidden',
32
+ borderColor: 'white',
33
+ borderWidth: HIDE_ICON_BORDER_WIDTH,
34
+ });
35
+ const hideIconStyles = {
36
+ width: HIDE_ICON_SIZE,
37
+ height: HIDE_ICON_SIZE,
38
+ marginRight: 4,
39
+ };
40
+ const HideIcon = () => (React.createElement(View, { style: hideIconStyles },
41
+ React.createElement(Inner, null),
42
+ React.createElement(Outer, null)));
43
+ const VisibilityButton = ({ onPress, style }) => (React.createElement(Touchable, { onPress: onPress, style: style, testID: "Storybook.OnDeviceUI.toggleUI", accessibilityLabel: "Storybook.OnDeviceUI.toggleUI", hitSlop: { top: 5, left: 5, bottom: 5, right: 5 } },
44
+ React.createElement(HideIcon, null)));
16
45
  export default React.memo(VisibilityButton);
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const GridIcon: () => JSX.Element;
2
3
  export declare const StoryIcon: ({ selected }: {
3
4
  selected: boolean;
@@ -1,44 +1,3 @@
1
- /// <reference types="react" />
2
- export declare const Header: import("@emotion/styled-base").StyledComponent<import("react-native").TextProps & import("react").RefAttributes<import("react-native").Text>, {
3
- selected: boolean;
4
- }, {
5
- backgroundColor: string;
6
- storyListBackgroundColor: string;
7
- listItemActiveColor: string;
8
- listItemActiveTextColor: string;
9
- headerTextColor: string;
10
- labelColor: string;
11
- borderColor: string;
12
- previewBorderColor: string;
13
- buttonTextColor: string;
14
- buttonActiveTextColor: string;
15
- secondaryLabelColor: string;
16
- }>;
17
- export declare const Name: import("@emotion/styled-base").StyledComponent<import("react-native").TextProps & import("react").RefAttributes<import("react-native").Text>, {
18
- selected: boolean;
19
- }, {
20
- backgroundColor: string;
21
- storyListBackgroundColor: string;
22
- listItemActiveColor: string;
23
- listItemActiveTextColor: string;
24
- headerTextColor: string;
25
- labelColor: string;
26
- borderColor: string;
27
- previewBorderColor: string;
28
- buttonTextColor: string;
29
- buttonActiveTextColor: string;
30
- secondaryLabelColor: string;
31
- }>;
32
- export declare const Label: import("@emotion/styled-base").StyledComponent<import("react-native").TextProps & import("react").RefAttributes<import("react-native").Text>, Pick<import("react-native").TextProps & import("react").RefAttributes<import("react-native").Text>, keyof import("react-native").TextProps>, {
33
- backgroundColor: string;
34
- storyListBackgroundColor: string;
35
- listItemActiveColor: string;
36
- listItemActiveTextColor: string;
37
- headerTextColor: string;
38
- labelColor: string;
39
- borderColor: string;
40
- previewBorderColor: string;
41
- buttonTextColor: string;
42
- buttonActiveTextColor: string;
43
- secondaryLabelColor: string;
44
- }>;
1
+ export declare const Header: any;
2
+ export declare const Name: any;
3
+ export declare const Label: any;
@@ -1,7 +1,10 @@
1
- import { StoreItem, StoryStore } from '@storybook/client-api';
1
+ /// <reference types="react" />
2
+ import { /* StoreItem, */ StoryIndex } from '@storybook/client-api';
3
+ import { StoryContext } from '@storybook/csf';
4
+ import { ReactNativeFramework } from 'src/types/types-6.0';
2
5
  interface Props {
3
- storyStore: StoryStore;
4
- selectedStory: StoreItem;
6
+ storyIndex: StoryIndex;
7
+ selectedStoryContext: StoryContext<ReactNativeFramework>;
5
8
  }
6
- declare const StoryListView: ({ selectedStory, storyStore }: Props) => JSX.Element;
9
+ declare const StoryListView: ({ selectedStoryContext, storyIndex }: Props) => JSX.Element;
7
10
  export default StoryListView;
@@ -2,7 +2,8 @@ import styled from '@emotion/native';
2
2
  import { addons } from '@storybook/addons';
3
3
  import Events from '@storybook/core-events';
4
4
  import React, { useMemo, useState } from 'react';
5
- import { SectionList, StyleSheet } from 'react-native';
5
+ import { SectionList, StyleSheet, View } from 'react-native';
6
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
6
7
  import { GridIcon, StoryIcon } from '../Shared/icons';
7
8
  import { Header, Name } from '../Shared/text';
8
9
  const SearchBar = styled.TextInput({
@@ -36,7 +37,7 @@ const StoryListContainer = styled.View(({ theme }) => (Object.assign(Object.assi
36
37
  borderRightWidth: StyleSheet.hairlineWidth, borderRightColor: theme.borderColor, backgroundColor: theme.storyListBackgroundColor })));
37
38
  const SectionHeader = React.memo(({ title, selected }) => (React.createElement(HeaderContainer, { key: title },
38
39
  React.createElement(GridIcon, null),
39
- React.createElement(Header, { selected: selected }, title))), (prevProps, nextProps) => prevProps.selected === nextProps.selected);
40
+ React.createElement(Header, { selected: selected }, title))));
40
41
  const ItemTouchable = styled.TouchableOpacity({
41
42
  padding: 5,
42
43
  paddingLeft: 40,
@@ -46,25 +47,27 @@ const ItemTouchable = styled.TouchableOpacity({
46
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 },
47
48
  React.createElement(StoryIcon, { selected: selected }),
48
49
  React.createElement(Name, { selected: selected }, title))), (prevProps, nextProps) => prevProps.selected === nextProps.selected);
49
- const getStories = (storyStore) => {
50
- if (!storyStore) {
50
+ const getStories = (storyIndex) => {
51
+ if (!storyIndex) {
51
52
  return [];
52
53
  }
53
- return Object.values(storyStore
54
- .raw()
55
- .reduce((acc, story) => {
56
- acc[story.kind] = {
57
- title: story.kind,
58
- data: (acc[story.kind] ? acc[story.kind].data : []).concat(story),
54
+ const groupedStories = Object.values(storyIndex.stories).reduce((acc, story) => {
55
+ var _a, _b;
56
+ acc[story.title] = {
57
+ title: story.title,
58
+ data: ((_b = (_a = acc[story.title]) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : []).concat(story),
59
59
  };
60
60
  return acc;
61
- }, {}));
61
+ }, {});
62
+ return Object.values(groupedStories);
62
63
  };
63
64
  const styles = StyleSheet.create({
64
65
  sectionList: { flex: 1 },
65
66
  });
66
- const StoryListView = ({ selectedStory, storyStore }) => {
67
- const originalData = useMemo(() => getStories(storyStore), [storyStore]);
67
+ const tabBarHeight = 40;
68
+ const StoryListView = ({ selectedStoryContext, storyIndex }) => {
69
+ const insets = useSafeAreaInsets();
70
+ const originalData = useMemo(() => getStories(storyIndex), [storyIndex]);
68
71
  const [data, setData] = useState(originalData);
69
72
  const handleChangeSearchText = (text) => {
70
73
  const query = text.trim();
@@ -89,8 +92,14 @@ const StoryListView = ({ selectedStory, storyStore }) => {
89
92
  const channel = addons.getChannel();
90
93
  channel.emit(Events.SET_CURRENT_STORY, { storyId });
91
94
  };
95
+ const safeStyle = { flex: 1, marginTop: insets.top, paddingBottom: insets.bottom + tabBarHeight };
92
96
  return (React.createElement(StoryListContainer, null,
93
- React.createElement(SearchBar, { testID: "Storybook.ListView.SearchBar", clearButtonMode: "while-editing", disableFullscreenUI: true, onChangeText: handleChangeSearchText, placeholder: "Filter", returnKeyType: "search" }),
94
- React.createElement(SectionList, { style: styles.sectionList, testID: "Storybook.ListView", renderItem: ({ item }) => (React.createElement(ListItem, { title: item.name, kind: item.kind, selected: selectedStory && item.id === selectedStory.id, onPress: () => changeStory(item.id) })), renderSectionHeader: ({ section: { title } }) => (React.createElement(SectionHeader, { title: title, selected: selectedStory && title === selectedStory.kind })), keyExtractor: (item, index) => item.id + index, sections: data, stickySectionHeadersEnabled: false })));
97
+ React.createElement(View, { style: safeStyle },
98
+ React.createElement(SearchBar, { testID: "Storybook.ListView.SearchBar", clearButtonMode: "while-editing", disableFullscreenUI: true, onChangeText: handleChangeSearchText, placeholder: "Filter", returnKeyType: "search" }),
99
+ React.createElement(SectionList
100
+ // contentInset={{ bottom: insets.bottom, top: 0 }}
101
+ , {
102
+ // contentInset={{ bottom: insets.bottom, top: 0 }}
103
+ style: styles.sectionList, testID: "Storybook.ListView", renderItem: ({ item }) => (React.createElement(ListItem, { title: item.name, kind: item.title, selected: selectedStoryContext && item.id === selectedStoryContext.id, onPress: () => changeStory(item.id) })), renderSectionHeader: ({ section: { title } }) => (React.createElement(SectionHeader, { title: title, selected: selectedStoryContext && title === selectedStoryContext.title })), keyExtractor: (item, index) => item.id + index, sections: data, stickySectionHeadersEnabled: false }))));
95
104
  };
96
105
  export default StoryListView;
@@ -1,6 +1,8 @@
1
- import { StoreItem } from '@storybook/client-api';
1
+ /// <reference types="react" />
2
+ import type { StoryContext } from '@storybook/csf';
3
+ import { ReactNativeFramework } from 'src/types/types-6.0';
2
4
  interface Props {
3
- story?: StoreItem;
5
+ context?: StoryContext<ReactNativeFramework>;
4
6
  }
5
- declare const StoryView: ({ story }: Props) => JSX.Element;
7
+ declare const StoryView: ({ context }: Props) => JSX.Element;
6
8
  export default StoryView;
@@ -1,13 +1,4 @@
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 React, { useState, useEffect } from 'react';
1
+ import React from 'react';
11
2
  import { Text, View, StyleSheet } from 'react-native';
12
3
  const styles = StyleSheet.create({
13
4
  container: { flex: 1 },
@@ -19,20 +10,11 @@ const styles = StyleSheet.create({
19
10
  justifyContent: 'center',
20
11
  },
21
12
  });
22
- const StoryView = ({ story }) => {
23
- const [context, setContext] = useState(undefined);
24
- const id = story === null || story === void 0 ? void 0 : story.id;
25
- useEffect(() => {
26
- const loadContext = () => __awaiter(void 0, void 0, void 0, function* () {
27
- if (story && story.unboundStoryFn && story.applyLoaders) {
28
- setContext(yield story.applyLoaders());
29
- }
30
- });
31
- loadContext();
32
- }, [story, id]);
33
- if (story && story.unboundStoryFn) {
34
- const { unboundStoryFn } = story;
35
- return (React.createElement(View, { key: id, testID: id, style: styles.container }, context && context.id === story.id ? unboundStoryFn(context) : null));
13
+ const StoryView = ({ context }) => {
14
+ const id = context === null || context === void 0 ? void 0 : context.id;
15
+ if (context && context.unboundStoryFn) {
16
+ const { unboundStoryFn: StoryComponent } = context;
17
+ return (React.createElement(View, { key: id, testID: id, style: styles.container }, StoryComponent && React.createElement(StoryComponent, Object.assign({}, context))));
36
18
  }
37
19
  return (React.createElement(View, { style: styles.helpContainer },
38
20
  React.createElement(Text, null, "Please open navigator and select a story to preview.")));
@@ -0,0 +1,24 @@
1
+ /// <reference types="webpack-env" />
2
+ /// <reference types="node" />
3
+ import { ModuleExports } from '@storybook/store';
4
+ import { Loadable } from '../types/types';
5
+ /**
6
+ * Executes a Loadable (function that returns exports or require context(s))
7
+ * and returns a map of filename => module exports
8
+ *
9
+ * @param loadable Loadable
10
+ * @returns Map<Path, ModuleExports>
11
+ */
12
+ export declare function executeLoadable(loadable: Loadable): Map<string, ModuleExports>;
13
+ /**
14
+ * Executes a Loadable (function that returns exports or require context(s))
15
+ * and compares it's output to the last time it was run (as stored on a node module)
16
+ *
17
+ * @param loadable Loadable
18
+ * @param m NodeModule
19
+ * @returns { added: Map<Path, ModuleExports>, removed: Map<Path, ModuleExports> }
20
+ */
21
+ export declare function executeLoadableForChanges(loadable: Loadable, _m?: NodeModule): {
22
+ added: Map<string, ModuleExports>;
23
+ removed: Map<string, ModuleExports>;
24
+ };
@@ -0,0 +1,82 @@
1
+ import { logger } from '@storybook/client-logger';
2
+ /**
3
+ * Executes a Loadable (function that returns exports or require context(s))
4
+ * and returns a map of filename => module exports
5
+ *
6
+ * @param loadable Loadable
7
+ * @returns Map<Path, ModuleExports>
8
+ */
9
+ export function executeLoadable(loadable) {
10
+ let reqs = null;
11
+ // todo discuss / improve type check
12
+ if (Array.isArray(loadable)) {
13
+ reqs = loadable;
14
+ }
15
+ else if (loadable.keys) {
16
+ reqs = [loadable];
17
+ }
18
+ let exportsMap = new Map();
19
+ if (reqs) {
20
+ reqs.forEach((req) => {
21
+ req.keys().forEach((filename) => {
22
+ try {
23
+ const fileExports = req(filename);
24
+ exportsMap.set(typeof req.resolve === 'function' ? req.resolve(filename) : filename, fileExports);
25
+ }
26
+ catch (error) {
27
+ const errorString = error.message && error.stack ? `${error.message}\n ${error.stack}` : error.toString();
28
+ logger.error(`Unexpected error while loading ${filename}: ${errorString}`);
29
+ }
30
+ });
31
+ });
32
+ }
33
+ else {
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]));
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
+ }
47
+ return exportsMap;
48
+ }
49
+ global.lastExportsMap = new Map();
50
+ /**
51
+ * Executes a Loadable (function that returns exports or require context(s))
52
+ * and compares it's output to the last time it was run (as stored on a node module)
53
+ *
54
+ * @param loadable Loadable
55
+ * @param m NodeModule
56
+ * @returns { added: Map<Path, ModuleExports>, removed: Map<Path, ModuleExports> }
57
+ */
58
+ export function executeLoadableForChanges(loadable, _m) {
59
+ // if (m?.hot?.dispose) {
60
+ // m.hot.accept();
61
+ // m.hot.dispose((data) => {
62
+ // // eslint-disable-next-line no-param-reassign
63
+ // data.lastExportsMap = lastExportsMap;
64
+ // });
65
+ // }
66
+ const lastExportsMap = global.lastExportsMap;
67
+ const exportsMap = executeLoadable(loadable);
68
+ const added = new Map();
69
+ Array.from(exportsMap.entries())
70
+ // Ignore files that do not have a default export
71
+ .filter(([, fileExports]) => !!fileExports.default)
72
+ // Ignore exports that are equal (by reference) to last time, this means the file hasn't changed
73
+ .filter(([fileName, fileExports]) => lastExportsMap.get(fileName) !== fileExports)
74
+ .forEach(([fileName, fileExports]) => added.set(fileName, fileExports));
75
+ const removed = new Map();
76
+ Array.from(lastExportsMap.keys())
77
+ .filter((fileName) => !exportsMap.has(fileName))
78
+ .forEach((fileName) => removed.set(fileName, lastExportsMap.get(fileName)));
79
+ // Save the value for the dispose() call above
80
+ global.lastExportsMap = exportsMap;
81
+ return { added, removed };
82
+ }
@@ -0,0 +1 @@
1
+ export default function getHost(hostname: any): any;
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+ /*
3
+ * It only for Debug Remotely mode for Android
4
+ * When __DEV__ === false, we can't use window.require('NativeModules')
5
+ */
6
+ function getByRemoteConfig(hostname) {
7
+ var remoteModuleConfig = typeof window !== 'undefined' &&
8
+ window.__fbBatchedBridgeConfig &&
9
+ window.__fbBatchedBridgeConfig.remoteModuleConfig;
10
+ if (!Array.isArray(remoteModuleConfig) ||
11
+ (hostname !== 'localhost' && hostname !== '127.0.0.1')) {
12
+ return { hostname: hostname, passed: false };
13
+ }
14
+ var constants = (remoteModuleConfig.find(getConstants) || [])[1];
15
+ if (constants) {
16
+ var serverHost = constants.ServerHost || hostname;
17
+ return { hostname: serverHost.split(':')[0], passed: true };
18
+ }
19
+ return { hostname: hostname, passed: false };
20
+ }
21
+ function getConstants(config) {
22
+ return config && (config[0] === 'AndroidConstants' || config[0] === 'PlatformConstants');
23
+ }
24
+ function getByRNRequirePolyfill(hostname) {
25
+ var NativeModules;
26
+ var PlatformConstants;
27
+ var AndroidConstants;
28
+ if (typeof window === 'undefined' ||
29
+ !window.__DEV__ ||
30
+ typeof window.require !== 'function' ||
31
+ // RN >= 0.56
32
+ // TODO: Get NativeModules for RN >= 0.56
33
+ window.require.name === 'metroRequire') {
34
+ return hostname;
35
+ }
36
+ NativeModules = window.require('NativeModules');
37
+ if (!NativeModules || (!NativeModules.PlatformConstants && !NativeModules.AndroidConstants)) {
38
+ return hostname;
39
+ }
40
+ PlatformConstants = NativeModules.PlatformConstants;
41
+ AndroidConstants = NativeModules.AndroidConstants;
42
+ var serverHost = (PlatformConstants ? PlatformConstants.ServerHost : AndroidConstants.ServerHost) || hostname;
43
+ return serverHost.split(':')[0];
44
+ }
45
+ /*
46
+ * Get React Native server IP if hostname is `localhost`
47
+ * On Android emulator, the IP of host is `10.0.2.2` (Genymotion: 10.0.3.2)
48
+ */
49
+ export default function getHost(hostname) {
50
+ // Check if it in React Native environment
51
+ if (typeof __fbBatchedBridge !== 'object' ||
52
+ (hostname !== 'localhost' && hostname !== '127.0.0.1')) {
53
+ return hostname;
54
+ }
55
+ var result = getByRemoteConfig(hostname);
56
+ // Leave if get hostname by remote config successful
57
+ if (result.passed) {
58
+ return result.hostname;
59
+ }
60
+ // Otherwise, use RN's require polyfill
61
+ return getByRNRequirePolyfill(hostname);
62
+ }
@@ -0,0 +1,13 @@
1
+ import { Loadable } from '@storybook/core-client';
2
+ import { PreviewWeb } from '@storybook/preview-web';
3
+ import { ClientApi } from '@storybook/client-api';
4
+ import type { ReactNativeFramework } from '../types/types-6.0';
5
+ import { View } from './View';
6
+ import '../document-polyfill';
7
+ export declare function start(): {
8
+ view: View;
9
+ forceReRender: () => void;
10
+ clientApi: ClientApi<ReactNativeFramework>;
11
+ preview: PreviewWeb<ReactNativeFramework>;
12
+ configure(loadable: Loadable): void;
13
+ };
@@ -0,0 +1,75 @@
1
+ import Channel from '@storybook/channels';
2
+ import { addons } from '@storybook/addons';
3
+ import Events from '@storybook/core-events';
4
+ import { PreviewWeb } from '@storybook/preview-web';
5
+ import { ClientApi } from '@storybook/client-api';
6
+ import { View } from './View';
7
+ import { executeLoadableForChanges } from './executeLoadable';
8
+ import '../document-polyfill';
9
+ export function start() {
10
+ var _a, _b, _c, _d, _e, _f, _g, _h;
11
+ const channel = new Channel({ async: true });
12
+ addons.setChannel(channel);
13
+ const clientApi = new ClientApi();
14
+ const preview = new PreviewWeb();
15
+ clientApi.storyStore = preview.storyStore;
16
+ preview.urlStore = {
17
+ selection: { storyId: '', viewMode: 'story' },
18
+ selectionSpecifier: null,
19
+ setQueryParams: () => { },
20
+ setSelection: (selection) => {
21
+ preview.urlStore.selection = selection;
22
+ },
23
+ };
24
+ preview.view = Object.assign(Object.assign({}, preview.view), { prepareForStory: () => null, showNoPreview: () => { }, showPreparingStory: () => { }, applyLayout: () => { }, showErrorDisplay: (e) => {
25
+ console.log(e);
26
+ }, showStoryDuringRender: () => { }, showMain: () => { },
27
+ // these are just to make typescript happy
28
+ 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 });
29
+ let initialized = false;
30
+ function onStoriesChanged() {
31
+ const storyIndex = clientApi.getStoryIndex();
32
+ preview.onStoriesChanged({ storyIndex });
33
+ view._storyIndex = storyIndex;
34
+ }
35
+ const view = new View(preview);
36
+ return {
37
+ view,
38
+ forceReRender: () => channel.emit(Events.FORCE_RE_RENDER),
39
+ clientApi,
40
+ preview,
41
+ // This gets called each time the user calls configure (i.e. once per HMR)
42
+ // The first time, it constructs the preview, subsequently it updates it
43
+ configure(loadable) {
44
+ clientApi.addParameters({ framework: 'react-native' });
45
+ // We need to run the `executeLoadableForChanges` function *inside* the `getProjectAnnotations
46
+ // function in case it throws. So we also need to process its output there also
47
+ const getProjectAnnotations = () => {
48
+ const { added, removed } = executeLoadableForChanges(loadable /*,m*/);
49
+ Array.from(added.entries()).forEach(([fileName, fileExports]) => clientApi.facade.addStoriesFromExports(fileName, fileExports));
50
+ Array.from(removed.entries()).forEach(([fileName]) => clientApi.facade.clearFilenameExports(fileName));
51
+ return Object.assign(Object.assign({}, clientApi.facade.projectAnnotations), { renderToDOM: (context) => {
52
+ view._setStory(context.storyContext);
53
+ } });
54
+ };
55
+ const importFn = (path) => clientApi.importFn(path);
56
+ if (!initialized) {
57
+ preview.initialize({
58
+ getStoryIndex: () => {
59
+ const index = clientApi.getStoryIndex();
60
+ view._storyIndex = index;
61
+ return index;
62
+ },
63
+ importFn,
64
+ getProjectAnnotations,
65
+ });
66
+ initialized = true;
67
+ }
68
+ else {
69
+ // TODO -- why don't we care about the new annotations?
70
+ getProjectAnnotations();
71
+ onStoriesChanged();
72
+ }
73
+ },
74
+ };
75
+ }
@@ -4,6 +4,10 @@ export declare type StoryFnReactReturnType = ReactElement<unknown>;
4
4
  export type { Args, ArgTypes, Parameters, StoryContext } from '@storybook/addons';
5
5
  declare type ReactComponent = ComponentType<any>;
6
6
  declare type ReactReturnType = StoryFnReactReturnType;
7
+ export declare type ReactNativeFramework = {
8
+ component: ComponentType<any>;
9
+ storyResult: StoryFnReactReturnType;
10
+ };
7
11
  /**
8
12
  * Metadata to configure the stories for a component.
9
13
  *
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { RenderContext, RenderContextWithoutStoryContext } from '@storybook/client-api';
2
+ export interface PreviewError {
3
+ message?: string;
4
+ stack?: string;
5
+ }
6
+ export interface RequireContext {
7
+ keys: () => string[];
8
+ (id: string): any;
9
+ resolve(id: string): string;
10
+ }
11
+ export declare type LoaderFunction = () => void | any[];
12
+ export declare type Loadable = RequireContext | RequireContext[] | LoaderFunction;
13
+ export type { RenderContext, RenderContextWithoutStoryContext };
14
+ export declare type RenderStoryFunction = (context: RenderContext) => void;
@@ -0,0 +1 @@
1
+ export {};