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

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/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /// <reference types="webpack-env" />
2
2
  /// <reference types="node" />
3
- import './document-polyfill';
4
3
  import { StoryApi } from '@storybook/addons';
5
4
  import { ClientApi } from '@storybook/client-api';
6
5
  import { ReactNode } from 'react';
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import './document-polyfill';
2
1
  import { start } from './preview/start';
3
2
  const { clientApi, configure, view } = start();
4
3
  export { configure };
@@ -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;
@@ -92,7 +92,10 @@ const OnDeviceUI = ({ context, storyIndex, isUIHidden, shouldDisableKeyboardAvoi
92
92
  tabOpen !== PREVIEW ? (React.createElement(TouchableOpacity, { style: absolutePosition, onPress: () => handleToggleTab(PREVIEW) })) : null)),
93
93
  React.createElement(Panel, { style: getNavigatorPanelPosition(animatedValue.current, previewDimensions.width, wide) },
94
94
  React.createElement(StoryListView, { storyIndex: storyIndex, selectedStoryContext: context })),
95
- 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
+ ] },
96
99
  React.createElement(Addons, { active: tabOpen === ADDONS })))),
97
100
  React.createElement(Navigation, { tabOpen: tabOpen, onChangeTab: handleToggleTab, isUIVisible: isUIVisible, setIsUIVisible: setIsUIVisible }))));
98
101
  };
@@ -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);
@@ -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 };
@@ -14,14 +14,32 @@ export const render = (args, context) => {
14
14
  return React.createElement(Component, Object.assign({}, args));
15
15
  };
16
16
  export function start() {
17
- var _a, _b, _c, _d, _e, _f, _g, _h;
17
+ // TODO: can we get settings from main.js and set the channel here?
18
18
  const channel = new Channel({ async: true });
19
19
  addons.setChannel(channel);
20
20
  const clientApi = new ClientApi();
21
- const preview = new PreviewWeb();
22
- clientApi.storyStore = preview.storyStore;
23
- setGlobalRender(render);
24
- 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 = {
25
43
  selection: { storyId: '', viewMode: 'story' },
26
44
  selectionSpecifier: null,
27
45
  setQueryParams: () => { },
@@ -29,11 +47,9 @@ export function start() {
29
47
  preview.urlStore.selection = selection;
30
48
  },
31
49
  };
32
- preview.view = Object.assign(Object.assign({}, preview.view), { prepareForStory: () => null, showNoPreview: () => { }, showPreparingStory: () => { }, applyLayout: () => { }, showErrorDisplay: (e) => {
33
- console.log(e);
34
- }, showStoryDuringRender: () => { }, showMain: () => { },
35
- // these are just to make typescript happy
36
- 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);
37
53
  let initialized = false;
38
54
  function onStoriesChanged() {
39
55
  const storyIndex = clientApi.getStoryIndex();
@@ -47,7 +63,7 @@ export function start() {
47
63
  clientApi,
48
64
  preview,
49
65
  // This gets called each time the user calls configure (i.e. once per HMR)
50
- // The first time, it constructs the preview, subsequently it updates it
66
+ // The first time, it constructs thecurrentSelection preview, subsequently it updates it
51
67
  configure(loadable, m) {
52
68
  clientApi.addParameters({ framework: 'react-native' });
53
69
  // We need to run the `executeLoadableForChanges` function *inside* the `getProjectAnnotations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react-native",
3
- "version": "6.0.1-beta.10",
3
+ "version": "6.0.1-beta.11",
4
4
  "description": "A better way to develop React Native Components for your app",
5
5
  "keywords": [
6
6
  "react",
@@ -49,15 +49,15 @@
49
49
  "dependencies": {
50
50
  "@emotion/core": "^10.0.20",
51
51
  "@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",
52
+ "@storybook/addons": "^6.5.14",
53
+ "@storybook/channel-websocket": "^6.5.14",
54
+ "@storybook/channels": "^6.5.14",
55
+ "@storybook/client-api": "^6.5.14",
56
+ "@storybook/client-logger": "^6.5.14",
57
+ "@storybook/core-client": "^6.5.14",
58
+ "@storybook/core-events": "^6.5.14",
59
59
  "@storybook/csf": "0.0.2--canary.7c6c115.0",
60
- "@storybook/preview-web": "^6.5",
60
+ "@storybook/preview-web": "^6.5.14",
61
61
  "chokidar": "^3.5.1",
62
62
  "commander": "^8.2.0",
63
63
  "emotion-theming": "^10.0.19",
@@ -85,5 +85,5 @@
85
85
  "publishConfig": {
86
86
  "access": "public"
87
87
  },
88
- "gitHead": "0288f6d0728b0f29698435b5cd2d46dc7dde57fc"
88
+ "gitHead": "622dfc390b5bb31681c5f17c4c8815ca27c1ef84"
89
89
  }
@@ -1,14 +0,0 @@
1
- export default Document;
2
- declare class Document extends Element {
3
- constructor();
4
- body: Element;
5
- documentElement: Element;
6
- readyState: string;
7
- createElement(tagName: any): Element;
8
- createElementNS(tagName: any): Element;
9
- getElementById(id: any): Element;
10
- location: {
11
- search: string;
12
- };
13
- }
14
- import Element from "./Element";
@@ -1,37 +0,0 @@
1
- import Element from './Element';
2
- import HTMLVideoElement from './HTMLVideoElement';
3
- import HTMLImageElement from './HTMLImageElement';
4
- import HTMLCanvasElement from './HTMLCanvasElement';
5
- class Document extends Element {
6
- constructor() {
7
- super('#document');
8
- this.location = { search: '' };
9
- this.body = new Element('BODY');
10
- this.documentElement = new Element('HTML');
11
- this.readyState = 'complete';
12
- }
13
- createElement(tagName) {
14
- switch ((tagName || '').toLowerCase()) {
15
- case 'video':
16
- return new HTMLVideoElement(tagName);
17
- case 'img':
18
- return new HTMLImageElement(tagName);
19
- case 'canvas':
20
- return new HTMLCanvasElement(tagName);
21
- case 'iframe':
22
- // Return nothing to keep firebase working.
23
- return null;
24
- default:
25
- return new Element(tagName);
26
- }
27
- }
28
- createElementNS(tagName) {
29
- const element = this.createElement(tagName);
30
- element.toDataURL = () => ({});
31
- return element;
32
- }
33
- getElementById(id) {
34
- return new Element('div');
35
- }
36
- }
37
- export default Document;
@@ -1,37 +0,0 @@
1
- export default Element;
2
- declare class Element extends Node {
3
- doc: {
4
- body: {
5
- innerHTML: string;
6
- };
7
- };
8
- get tagName(): any;
9
- get clientWidth(): number;
10
- get clientHeight(): number;
11
- get offsetWidth(): number;
12
- get offsetHeight(): number;
13
- get innerWidth(): number;
14
- get innerHeight(): number;
15
- getContext(contextType: any, contextOptions: any, context: any): {
16
- fillText: (text: any, x: any, y: any, maxWidth: any) => {};
17
- measureText: (text: any) => {
18
- width: number;
19
- height: number;
20
- };
21
- fillRect: () => {};
22
- drawImage: () => {};
23
- getImageData: () => {
24
- data: Uint8ClampedArray;
25
- };
26
- getContextAttributes: () => {
27
- stencil: boolean;
28
- };
29
- getExtension: () => {
30
- loseContext: () => void;
31
- };
32
- putImageData: () => {};
33
- createImageData: () => {};
34
- };
35
- get ontouchstart(): {};
36
- }
37
- import Node from "./Node";
@@ -1,58 +0,0 @@
1
- import Node from './Node';
2
- class Element extends Node {
3
- constructor(tagName) {
4
- return super(tagName.toUpperCase());
5
- // eslint-disable-next-line no-unreachable
6
- this.doc = {
7
- body: {
8
- innerHTML: '',
9
- },
10
- };
11
- }
12
- get tagName() {
13
- return this.nodeName;
14
- }
15
- setAttributeNS() { }
16
- get clientWidth() {
17
- return this.innerWidth;
18
- }
19
- get clientHeight() {
20
- return this.innerHeight;
21
- }
22
- get offsetWidth() {
23
- return this.innerWidth;
24
- }
25
- get offsetHeight() {
26
- return this.innerHeight;
27
- }
28
- get innerWidth() {
29
- return window.innerWidth;
30
- }
31
- get innerHeight() {
32
- return window.innerHeight;
33
- }
34
- getContext(contextType, contextOptions, context) {
35
- return {
36
- fillText: (text, x, y, maxWidth) => ({}),
37
- measureText: (text) => ({
38
- width: (text || '').split('').length * 6,
39
- height: 24,
40
- }),
41
- fillRect: () => ({}),
42
- drawImage: () => ({}),
43
- getImageData: () => ({ data: new Uint8ClampedArray([255, 0, 0, 0]) }),
44
- getContextAttributes: () => ({
45
- stencil: true,
46
- }),
47
- getExtension: () => ({
48
- loseContext: () => { },
49
- }),
50
- putImageData: () => ({}),
51
- createImageData: () => ({}),
52
- };
53
- }
54
- get ontouchstart() {
55
- return {};
56
- }
57
- }
58
- export default Element;
@@ -1,4 +0,0 @@
1
- export default HTMLCanvasElement;
2
- declare class HTMLCanvasElement extends Element {
3
- }
4
- import Element from "./Element";
@@ -1,4 +0,0 @@
1
- import Element from './Element';
2
- class HTMLCanvasElement extends Element {
3
- }
4
- export default HTMLCanvasElement;
@@ -1,4 +0,0 @@
1
- export default HTMLImageElement;
2
- declare class HTMLImageElement extends Element {
3
- }
4
- import Element from "./Element";
@@ -1,4 +0,0 @@
1
- import Element from './Element';
2
- class HTMLImageElement extends Element {
3
- }
4
- export default HTMLImageElement;
@@ -1,4 +0,0 @@
1
- export default HTMLVideoElement;
2
- declare class HTMLVideoElement extends Element {
3
- }
4
- import Element from "./Element";
@@ -1,4 +0,0 @@
1
- import Element from './Element';
2
- class HTMLVideoElement extends Element {
3
- }
4
- export default HTMLVideoElement;
@@ -1,26 +0,0 @@
1
- export default Node;
2
- declare class Node {
3
- constructor(nodeName: any);
4
- addEventListener(_eventName: any, _listener: any): void;
5
- removeEventListener(_eventName: any, _listener: any): void;
6
- style: {};
7
- className: {
8
- baseVal: string;
9
- };
10
- nodeName: any;
11
- get ownerDocument(): Document;
12
- appendChild(): void;
13
- insertBefore(): void;
14
- removeChild(): void;
15
- setAttributeNS(): void;
16
- getBoundingClientRect(): {
17
- left: number;
18
- top: number;
19
- right: number;
20
- bottom: number;
21
- x: number;
22
- y: number;
23
- width: number;
24
- height: number;
25
- };
26
- }
@@ -1,33 +0,0 @@
1
- class Node {
2
- constructor(nodeName) {
3
- this.addEventListener = this.addEventListener.bind(this);
4
- this.removeEventListener = this.removeEventListener.bind(this);
5
- this.style = {};
6
- this.className = {
7
- baseVal: '',
8
- };
9
- this.nodeName = nodeName;
10
- }
11
- get ownerDocument() {
12
- return window.document;
13
- }
14
- addEventListener(_eventName, _listener) { }
15
- removeEventListener(_eventName, _listener) { }
16
- appendChild() { }
17
- insertBefore() { }
18
- removeChild() { }
19
- setAttributeNS() { }
20
- getBoundingClientRect() {
21
- return {
22
- left: 0,
23
- top: 0,
24
- right: window.innerWidth,
25
- bottom: window.innerHeight,
26
- x: 0,
27
- y: 0,
28
- width: window.innerWidth,
29
- height: window.innerHeight,
30
- };
31
- }
32
- }
33
- export default Node;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- // this is temporary until we can solve the preview web crashing the app by accessing document
2
- // adjusted from expo/browser-polyfill to not require external dependencies https://github.com/expo/browser-polyfill
3
- import './module';
File without changes
@@ -1 +0,0 @@
1
- // do nothing
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import Document from './DOM/Document';
2
- window.document = window.document || new Document();