@storybook/react-native 6.0.1-beta.8 → 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.
- package/dist/document-polyfill/DOM/Document.d.ts +14 -0
- package/dist/document-polyfill/DOM/Document.js +37 -0
- package/dist/document-polyfill/DOM/Element.d.ts +37 -0
- package/dist/document-polyfill/DOM/Element.js +58 -0
- package/dist/document-polyfill/DOM/HTMLCanvasElement.d.ts +4 -0
- package/dist/document-polyfill/DOM/HTMLCanvasElement.js +4 -0
- package/dist/document-polyfill/DOM/HTMLImageElement.d.ts +4 -0
- package/dist/document-polyfill/DOM/HTMLImageElement.js +4 -0
- package/dist/document-polyfill/DOM/HTMLVideoElement.d.ts +4 -0
- package/dist/document-polyfill/DOM/HTMLVideoElement.js +4 -0
- package/dist/document-polyfill/DOM/Node.d.ts +26 -0
- package/dist/document-polyfill/DOM/Node.js +33 -0
- package/dist/{preview/global.js → document-polyfill/index.d.ts} +0 -0
- package/dist/document-polyfill/index.js +3 -0
- package/dist/document-polyfill/module.d.ts +0 -0
- package/dist/document-polyfill/module.js +1 -0
- package/dist/{types-6.0.js → document-polyfill/module.native.d.ts} +0 -0
- package/dist/document-polyfill/module.native.js +2 -0
- package/dist/index.d.ts +13 -12
- package/dist/index.js +13 -17
- package/dist/preview/View.d.ts +40 -0
- package/dist/preview/View.js +90 -0
- package/dist/preview/components/OnDeviceUI/OnDeviceUI.d.ts +6 -3
- package/dist/preview/components/OnDeviceUI/OnDeviceUI.js +6 -26
- package/dist/preview/components/OnDeviceUI/Panel.js +1 -0
- package/dist/preview/components/OnDeviceUI/animation.d.ts +5 -5
- package/dist/preview/components/Shared/icons.d.ts +1 -0
- package/dist/preview/components/Shared/text.d.ts +3 -44
- package/dist/preview/components/StoryListView/StoryListView.d.ts +7 -4
- package/dist/preview/components/StoryListView/StoryListView.js +12 -12
- package/dist/preview/components/StoryView/StoryView.d.ts +5 -3
- package/dist/preview/components/StoryView/StoryView.js +5 -24
- package/dist/preview/executeLoadable.d.ts +24 -0
- package/dist/preview/executeLoadable.js +82 -0
- package/dist/preview/rn-host-detect.d.ts +1 -0
- package/dist/preview/rn-host-detect.js +62 -0
- package/dist/preview/start.d.ts +13 -0
- package/dist/preview/start.js +75 -0
- package/dist/{types-6.0.d.ts → types/types-6.0.d.ts} +4 -0
- package/dist/types/types-6.0.js +1 -0
- package/dist/types/types.d.ts +14 -0
- package/dist/types/types.js +1 -0
- package/package.json +14 -12
- package/dist/preview/Preview.d.ts +0 -57
- package/dist/preview/Preview.js +0 -121
- package/dist/preview/global.d.ts +0 -8
- package/dist/preview/index.d.ts +0 -1
- package/dist/preview/index.js +0 -1
- package/dist/preview/loadCsf.d.ts +0 -16
- package/dist/preview/loadCsf.js +0 -180
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
4
|
-
|
|
6
|
+
storyIndex: StoryIndex;
|
|
7
|
+
selectedStoryContext: StoryContext<ReactNativeFramework>;
|
|
5
8
|
}
|
|
6
|
-
declare const StoryListView: ({
|
|
9
|
+
declare const StoryListView: ({ selectedStoryContext, storyIndex }: Props) => JSX.Element;
|
|
7
10
|
export default StoryListView;
|
|
@@ -47,27 +47,27 @@ const ItemTouchable = styled.TouchableOpacity({
|
|
|
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);
|
|
50
|
-
const getStories = (
|
|
51
|
-
if (!
|
|
50
|
+
const getStories = (storyIndex) => {
|
|
51
|
+
if (!storyIndex) {
|
|
52
52
|
return [];
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
title: story
|
|
59
|
-
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),
|
|
60
59
|
};
|
|
61
60
|
return acc;
|
|
62
|
-
}, {})
|
|
61
|
+
}, {});
|
|
62
|
+
return Object.values(groupedStories);
|
|
63
63
|
};
|
|
64
64
|
const styles = StyleSheet.create({
|
|
65
65
|
sectionList: { flex: 1 },
|
|
66
66
|
});
|
|
67
67
|
const tabBarHeight = 40;
|
|
68
|
-
const StoryListView = ({
|
|
68
|
+
const StoryListView = ({ selectedStoryContext, storyIndex }) => {
|
|
69
69
|
const insets = useSafeAreaInsets();
|
|
70
|
-
const originalData = useMemo(() => getStories(
|
|
70
|
+
const originalData = useMemo(() => getStories(storyIndex), [storyIndex]);
|
|
71
71
|
const [data, setData] = useState(originalData);
|
|
72
72
|
const handleChangeSearchText = (text) => {
|
|
73
73
|
const query = text.trim();
|
|
@@ -100,6 +100,6 @@ const StoryListView = ({ selectedStory, storyStore }) => {
|
|
|
100
100
|
// contentInset={{ bottom: insets.bottom, top: 0 }}
|
|
101
101
|
, {
|
|
102
102
|
// contentInset={{ bottom: insets.bottom, top: 0 }}
|
|
103
|
-
style: styles.sectionList, testID: "Storybook.ListView", renderItem: ({ item }) => (React.createElement(ListItem, { title: item.name, kind: item.
|
|
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 }))));
|
|
104
104
|
};
|
|
105
105
|
export default StoryListView;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
5
|
+
context?: StoryContext<ReactNativeFramework>;
|
|
4
6
|
}
|
|
5
|
-
declare const StoryView: ({
|
|
7
|
+
declare const StoryView: ({ context }: Props) => JSX.Element;
|
|
6
8
|
export default StoryView;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
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,10 @@ const styles = StyleSheet.create({
|
|
|
19
10
|
justifyContent: 'center',
|
|
20
11
|
},
|
|
21
12
|
});
|
|
22
|
-
const StoryView = ({
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
const StoryComponent = (context && context.id === story.id) ? unboundStoryFn : 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;
|
|
36
17
|
return (React.createElement(View, { key: id, testID: id, style: styles.container }, StoryComponent && React.createElement(StoryComponent, Object.assign({}, context))));
|
|
37
18
|
}
|
|
38
19
|
return (React.createElement(View, { style: styles.helpContainer },
|
|
@@ -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 {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react-native",
|
|
3
|
-
"version": "6.0.1-
|
|
3
|
+
"version": "6.0.1-canary.0",
|
|
4
4
|
"description": "A better way to develop React Native Components for your app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -49,14 +49,15 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@emotion/core": "^10.0.20",
|
|
51
51
|
"@emotion/native": "^10.0.14",
|
|
52
|
-
"@storybook/addons": "
|
|
53
|
-
"@storybook/channel-websocket": "
|
|
54
|
-
"@storybook/channels": "
|
|
55
|
-
"@storybook/client-api": "
|
|
56
|
-
"@storybook/client-logger": "
|
|
57
|
-
"@storybook/core-client": "
|
|
58
|
-
"@storybook/core-events": "
|
|
59
|
-
"@storybook/csf": "0.0.
|
|
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",
|
|
60
61
|
"chokidar": "^3.5.1",
|
|
61
62
|
"commander": "^8.2.0",
|
|
62
63
|
"emotion-theming": "^10.0.19",
|
|
@@ -66,10 +67,11 @@
|
|
|
66
67
|
"util": "^0.12.4"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@types/react
|
|
70
|
+
"@types/react": "^18.0.21",
|
|
71
|
+
"@types/react-native": "^0.70.4",
|
|
70
72
|
"babel-jest": "^26.6.3",
|
|
71
73
|
"jest": "^26.6.3",
|
|
72
|
-
"react-test-renderer": "
|
|
74
|
+
"react-test-renderer": "18.2.0"
|
|
73
75
|
},
|
|
74
76
|
"peerDependencies": {
|
|
75
77
|
"@react-native-async-storage/async-storage": ">=1",
|
|
@@ -83,5 +85,5 @@
|
|
|
83
85
|
"publishConfig": {
|
|
84
86
|
"access": "public"
|
|
85
87
|
},
|
|
86
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "2aa26caa5afbee685a7a9eb673ef0afd9b3ad857"
|
|
87
89
|
}
|
|
@@ -1,57 +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
|
-
declare type StoryKind = string;
|
|
8
|
-
declare type StoryName = string;
|
|
9
|
-
declare type InitialSelection = `${StoryKind}--${StoryName}` | {
|
|
10
|
-
/**
|
|
11
|
-
* Kind is the default export name or the storiesOf("name") name
|
|
12
|
-
*/
|
|
13
|
-
kind: StoryKind;
|
|
14
|
-
/**
|
|
15
|
-
* Name is the named export or the .add("name") name
|
|
16
|
-
*/
|
|
17
|
-
name: StoryName;
|
|
18
|
-
};
|
|
19
|
-
export declare type Params = {
|
|
20
|
-
onDeviceUI?: boolean;
|
|
21
|
-
resetStorybook?: boolean;
|
|
22
|
-
disableWebsockets?: boolean;
|
|
23
|
-
query?: string;
|
|
24
|
-
host?: string;
|
|
25
|
-
port?: number;
|
|
26
|
-
secured?: boolean;
|
|
27
|
-
initialSelection?: InitialSelection;
|
|
28
|
-
shouldPersistSelection?: boolean;
|
|
29
|
-
tabOpen?: number;
|
|
30
|
-
isUIHidden?: boolean;
|
|
31
|
-
shouldDisableKeyboardAvoidingView?: boolean;
|
|
32
|
-
keyboardAvoidingViewVerticalOffset?: number;
|
|
33
|
-
} & {
|
|
34
|
-
theme?: typeof theme;
|
|
35
|
-
};
|
|
36
|
-
export default class Preview {
|
|
37
|
-
_clientApi: ClientApi;
|
|
38
|
-
_storyStore: StoryStore;
|
|
39
|
-
_addons: any;
|
|
40
|
-
_channel: Channel;
|
|
41
|
-
_decorators: any[];
|
|
42
|
-
_asyncStorageStoryId: string;
|
|
43
|
-
_configApi: ConfigApi;
|
|
44
|
-
configure: (loadable: Loadable, m: NodeModule, showDeprecationWarning: boolean) => void;
|
|
45
|
-
constructor();
|
|
46
|
-
api: () => ClientApi;
|
|
47
|
-
getStorybookUI: (params?: Partial<Params>) => () => JSX.Element;
|
|
48
|
-
_setInitialStory: (initialSelection?: InitialSelection, shouldPersistSelection?: boolean) => Promise<void>;
|
|
49
|
-
_getInitialStory: (initialSelection?: InitialSelection, shouldPersistSelection?: boolean) => Promise<import("@storybook/client-api").PublishedStoreItem>;
|
|
50
|
-
_getStory(storyId: string): import("@storybook/client-api").PublishedStoreItem;
|
|
51
|
-
_selectStoryEvent({ storyId }: {
|
|
52
|
-
storyId: string;
|
|
53
|
-
}, shouldPersistSelection: any): void;
|
|
54
|
-
_selectStory(story: any): void;
|
|
55
|
-
_checkStory(storyId: string): import("@storybook/client-api").PublishedStoreItem;
|
|
56
|
-
}
|
|
57
|
-
export {};
|
package/dist/preview/Preview.js
DELETED
|
@@ -1,121 +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 { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
19
|
-
import OnDeviceUI from './components/OnDeviceUI';
|
|
20
|
-
import { theme } from './components/Shared/theme';
|
|
21
|
-
import { loadCsf } from './loadCsf';
|
|
22
|
-
const STORAGE_KEY = 'lastOpenedStory';
|
|
23
|
-
export default class Preview {
|
|
24
|
-
constructor() {
|
|
25
|
-
this.api = () => {
|
|
26
|
-
return this._clientApi;
|
|
27
|
-
};
|
|
28
|
-
this.getStorybookUI = (params = {}) => {
|
|
29
|
-
const { initialSelection, shouldPersistSelection = true } = params;
|
|
30
|
-
this._setInitialStory(initialSelection, shouldPersistSelection);
|
|
31
|
-
this._channel.on(Events.SET_CURRENT_STORY, (d) => {
|
|
32
|
-
this._selectStoryEvent(d, shouldPersistSelection);
|
|
33
|
-
});
|
|
34
|
-
const { _storyStore } = this;
|
|
35
|
-
addons.loadAddons(this._clientApi);
|
|
36
|
-
const appliedTheme = Object.assign(Object.assign({}, theme), params.theme);
|
|
37
|
-
return () => (React.createElement(SafeAreaProvider, null,
|
|
38
|
-
React.createElement(ThemeProvider, { theme: appliedTheme },
|
|
39
|
-
React.createElement(OnDeviceUI, { storyStore: _storyStore, isUIHidden: params.isUIHidden, tabOpen: params.tabOpen, shouldDisableKeyboardAvoidingView: params.shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset: params.keyboardAvoidingViewVerticalOffset }))));
|
|
40
|
-
};
|
|
41
|
-
this._setInitialStory = (initialSelection, shouldPersistSelection = true) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const story = yield this._getInitialStory(initialSelection, shouldPersistSelection);
|
|
43
|
-
if (story) {
|
|
44
|
-
this._selectStory(story);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
this._getInitialStory = (initialSelection, shouldPersistSelection = true) => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
let story = null;
|
|
49
|
-
const initialSelectionId = initialSelection === undefined
|
|
50
|
-
? undefined
|
|
51
|
-
: typeof initialSelection === 'string'
|
|
52
|
-
? initialSelection
|
|
53
|
-
: toId(initialSelection.kind, initialSelection.name);
|
|
54
|
-
if (initialSelectionId !== undefined && this._checkStory(initialSelectionId)) {
|
|
55
|
-
story = initialSelectionId;
|
|
56
|
-
}
|
|
57
|
-
else if (shouldPersistSelection) {
|
|
58
|
-
try {
|
|
59
|
-
let value = this._asyncStorageStoryId;
|
|
60
|
-
if (!value) {
|
|
61
|
-
value = JSON.parse(yield AsyncStorage.getItem(STORAGE_KEY));
|
|
62
|
-
this._asyncStorageStoryId = value;
|
|
63
|
-
}
|
|
64
|
-
if (this._checkStory(value)) {
|
|
65
|
-
story = value;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
//
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (story) {
|
|
73
|
-
return this._getStory(story);
|
|
74
|
-
}
|
|
75
|
-
const stories = this._storyStore.raw();
|
|
76
|
-
if (stories && stories.length) {
|
|
77
|
-
return this._getStory(stories[0].id);
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
80
|
-
});
|
|
81
|
-
const channel = new Channel({ async: true });
|
|
82
|
-
this._decorators = [];
|
|
83
|
-
this._storyStore = new StoryStore({ channel });
|
|
84
|
-
this._clientApi = new ClientApi({ storyStore: this._storyStore });
|
|
85
|
-
this._configApi = new ConfigApi({ storyStore: this._storyStore });
|
|
86
|
-
this._channel = channel;
|
|
87
|
-
const configure = loadCsf({
|
|
88
|
-
clientApi: this._clientApi,
|
|
89
|
-
storyStore: this._storyStore,
|
|
90
|
-
configApi: this._configApi,
|
|
91
|
-
});
|
|
92
|
-
this.configure = (...args) => configure('react-native', ...args);
|
|
93
|
-
addons.setChannel(channel);
|
|
94
|
-
}
|
|
95
|
-
_getStory(storyId) {
|
|
96
|
-
return this._storyStore.fromId(storyId);
|
|
97
|
-
}
|
|
98
|
-
_selectStoryEvent({ storyId }, shouldPersistSelection) {
|
|
99
|
-
if (storyId) {
|
|
100
|
-
if (shouldPersistSelection) {
|
|
101
|
-
AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(storyId)).catch(() => { });
|
|
102
|
-
}
|
|
103
|
-
const story = this._getStory(storyId);
|
|
104
|
-
this._selectStory(story);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
_selectStory(story) {
|
|
108
|
-
this._storyStore.setSelection({ storyId: story.id, viewMode: 'story' });
|
|
109
|
-
this._channel.emit(Events.SELECT_STORY, story);
|
|
110
|
-
}
|
|
111
|
-
_checkStory(storyId) {
|
|
112
|
-
if (!storyId) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
const story = this._getStory(storyId);
|
|
116
|
-
if (story === null || story.storyFn === null) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
return story;
|
|
120
|
-
}
|
|
121
|
-
}
|