@storybook/react-native 6.5.5 → 6.5.6-alpha.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 (67) hide show
  1. package/dist/index.d.ts +125 -18
  2. package/dist/index.js +1591 -41
  3. package/package.json +7 -8
  4. package/dist/constants.d.ts +0 -5
  5. package/dist/constants.js +0 -8
  6. package/dist/hooks.d.ts +0 -67
  7. package/dist/hooks.js +0 -168
  8. package/dist/preview/View.d.ts +0 -50
  9. package/dist/preview/View.js +0 -183
  10. package/dist/preview/components/OnDeviceUI/OnDeviceUI.d.ts +0 -12
  11. package/dist/preview/components/OnDeviceUI/OnDeviceUI.js +0 -163
  12. package/dist/preview/components/OnDeviceUI/Panel.d.ts +0 -9
  13. package/dist/preview/components/OnDeviceUI/Panel.js +0 -28
  14. package/dist/preview/components/OnDeviceUI/absolute-positioned-keyboard-aware-view.d.ts +0 -12
  15. package/dist/preview/components/OnDeviceUI/absolute-positioned-keyboard-aware-view.js +0 -31
  16. package/dist/preview/components/OnDeviceUI/addons/Addons.d.ts +0 -6
  17. package/dist/preview/components/OnDeviceUI/addons/Addons.js +0 -34
  18. package/dist/preview/components/OnDeviceUI/addons/AddonsSkeleton.d.ts +0 -14
  19. package/dist/preview/components/OnDeviceUI/addons/AddonsSkeleton.js +0 -78
  20. package/dist/preview/components/OnDeviceUI/addons/List.d.ts +0 -9
  21. package/dist/preview/components/OnDeviceUI/addons/List.js +0 -18
  22. package/dist/preview/components/OnDeviceUI/addons/Wrapper.d.ts +0 -8
  23. package/dist/preview/components/OnDeviceUI/addons/Wrapper.js +0 -31
  24. package/dist/preview/components/OnDeviceUI/addons/index.d.ts +0 -1
  25. package/dist/preview/components/OnDeviceUI/addons/index.js +0 -8
  26. package/dist/preview/components/OnDeviceUI/animation.d.ts +0 -61
  27. package/dist/preview/components/OnDeviceUI/animation.js +0 -116
  28. package/dist/preview/components/OnDeviceUI/index.d.ts +0 -1
  29. package/dist/preview/components/OnDeviceUI/index.js +0 -8
  30. package/dist/preview/components/OnDeviceUI/navigation/Navigation.d.ts +0 -9
  31. package/dist/preview/components/OnDeviceUI/navigation/Navigation.js +0 -54
  32. package/dist/preview/components/OnDeviceUI/navigation/NavigationBar.d.ts +0 -8
  33. package/dist/preview/components/OnDeviceUI/navigation/NavigationBar.js +0 -24
  34. package/dist/preview/components/OnDeviceUI/navigation/NavigationButton.d.ts +0 -2
  35. package/dist/preview/components/OnDeviceUI/navigation/NavigationButton.js +0 -23
  36. package/dist/preview/components/OnDeviceUI/navigation/constants.d.ts +0 -3
  37. package/dist/preview/components/OnDeviceUI/navigation/constants.js +0 -6
  38. package/dist/preview/components/OnDeviceUI/navigation/index.d.ts +0 -1
  39. package/dist/preview/components/OnDeviceUI/navigation/index.js +0 -8
  40. package/dist/preview/components/Shared/icons.d.ts +0 -53
  41. package/dist/preview/components/Shared/icons.js +0 -72
  42. package/dist/preview/components/Shared/layout.d.ts +0 -26
  43. package/dist/preview/components/Shared/layout.js +0 -24
  44. package/dist/preview/components/Shared/tabs.d.ts +0 -20
  45. package/dist/preview/components/Shared/tabs.js +0 -48
  46. package/dist/preview/components/StoryListView/StoryListView.d.ts +0 -7
  47. package/dist/preview/components/StoryListView/StoryListView.js +0 -201
  48. package/dist/preview/components/StoryListView/getNestedStories.d.ts +0 -10
  49. package/dist/preview/components/StoryListView/getNestedStories.js +0 -95
  50. package/dist/preview/components/StoryListView/getNestedStories.test.d.ts +0 -1
  51. package/dist/preview/components/StoryListView/getNestedStories.test.js +0 -237
  52. package/dist/preview/components/StoryListView/index.d.ts +0 -1
  53. package/dist/preview/components/StoryListView/index.js +0 -8
  54. package/dist/preview/components/StoryView/StoryView.d.ts +0 -3
  55. package/dist/preview/components/StoryView/StoryView.js +0 -47
  56. package/dist/preview/components/StoryView/index.d.ts +0 -1
  57. package/dist/preview/components/StoryView/index.js +0 -8
  58. package/dist/preview/executeLoadable.d.ts +0 -27
  59. package/dist/preview/executeLoadable.js +0 -95
  60. package/dist/preview/rn-host-detect.d.ts +0 -1
  61. package/dist/preview/rn-host-detect.js +0 -63
  62. package/dist/preview/start.d.ts +0 -16
  63. package/dist/preview/start.js +0 -124
  64. package/dist/types/types-6.0.d.ts +0 -72
  65. package/dist/types/types-6.0.js +0 -2
  66. package/dist/types/types.d.ts +0 -14
  67. package/dist/types/types.js +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react-native",
3
- "version": "6.5.5",
3
+ "version": "6.5.6-alpha.0",
4
4
  "description": "A better way to develop React Native Components for your app",
5
5
  "keywords": [
6
6
  "react",
@@ -32,9 +32,8 @@
32
32
  "template/**/*"
33
33
  ],
34
34
  "scripts": {
35
- "dev": "yarn tsc --watch",
36
- "preprepare": "rm -rf dist/",
37
- "prepare": "tsc",
35
+ "dev": "ts-node ./buildscripts/gentsdev.ts && tsup --watch",
36
+ "prepare": "tsup",
38
37
  "test": "jest"
39
38
  },
40
39
  "jest": {
@@ -52,8 +51,6 @@
52
51
  "preset": "react-native"
53
52
  },
54
53
  "dependencies": {
55
- "@emotion/native": "^11.11.0",
56
- "@emotion/react": "^11.11.1",
57
54
  "@storybook/addons": "^6.5.14",
58
55
  "@storybook/channel-websocket": "^6.5.14",
59
56
  "@storybook/channels": "^6.5.14",
@@ -63,7 +60,7 @@
63
60
  "@storybook/core-events": "^6.5.14",
64
61
  "@storybook/csf": "0.0.2--canary.4566f4d.1",
65
62
  "@storybook/preview-web": "^6.5.14",
66
- "@storybook/react-native-theming": "^6.5.5",
63
+ "@storybook/react-native-theming": "^6.5.6-alpha.0",
67
64
  "chokidar": "^3.5.1",
68
65
  "commander": "^8.2.0",
69
66
  "deepmerge": "^4.3.0",
@@ -79,6 +76,8 @@
79
76
  "babel-jest": "^29.4.3",
80
77
  "jest": "^29.4.3",
81
78
  "react-test-renderer": "18.2.0",
79
+ "ts-node": "^10.9.1",
80
+ "tsup": "^7.2.0",
82
81
  "typescript": "^5.1.3"
83
82
  },
84
83
  "peerDependencies": {
@@ -93,5 +92,5 @@
93
92
  "publishConfig": {
94
93
  "access": "public"
95
94
  },
96
- "gitHead": "ad15a9640397fbaf3536c1b8469c7b13b70676d8"
95
+ "gitHead": "f2ff9ddebf4e2a8a008cc484bf054c4a5cd641c5"
97
96
  }
@@ -1,5 +0,0 @@
1
- /**
2
- * Duration for a typical transition animation, such as rescaling the canvas
3
- * UI.
4
- */
5
- export declare const ANIMATION_DURATION_TRANSITION = 400;
package/dist/constants.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ANIMATION_DURATION_TRANSITION = void 0;
4
- /**
5
- * Duration for a typical transition animation, such as rescaling the canvas
6
- * UI.
7
- */
8
- exports.ANIMATION_DURATION_TRANSITION = 400;
package/dist/hooks.d.ts DELETED
@@ -1,67 +0,0 @@
1
- import type { StoryContext } from '@storybook/csf';
2
- import type { ReactNativeFramework } from './types/types-6.0';
3
- import { StoryIndexEntry } from '@storybook/client-api';
4
- /**
5
- * Hook that returns a function to set the current story context.
6
- */
7
- export declare function useSetStoryContext(): (args_0: StoryContext<ReactNativeFramework> | ((prev: StoryContext<ReactNativeFramework>) => StoryContext<ReactNativeFramework>)) => void;
8
- /**
9
- * Hook to read the current story context.
10
- */
11
- export declare function useStoryContext(): StoryContext<ReactNativeFramework>;
12
- /**
13
- * Hook that reads the value of a specific story context parameter.
14
- */
15
- export declare function useStoryContextParam<T = any>(name: string, defaultValue?: T): T;
16
- /**
17
- * Hook that indicates if `storyId` is the currently selected story.
18
- */
19
- export declare function useIsStorySelected(storyId: string): boolean;
20
- /**
21
- * Hook that indicates if story kind (title) is the currently selected story section.
22
- */
23
- export declare function useIsStorySectionSelected(title: string): boolean;
24
- export declare function useIsChildSelected(entries: StoryIndexEntry[]): boolean;
25
- /**
26
- * Hook that causes a re-render when the currently selected story is changed.
27
- */
28
- export declare function useUpdateOnStoryChanged(): void;
29
- /**
30
- * Hook that gets the current theme values.
31
- */
32
- export declare function useTheme(): import("@emotion/react").Theme;
33
- /**
34
- * A boolean atom creator for an atom that can only be toggled between
35
- * true/false.
36
- *
37
- * @see {@link https://jotai.org/docs/recipes/atom-creators#atomwithtoggle}
38
- */
39
- export declare function atomWithToggle(initialValue?: boolean): import("jotai").WritableAtom<boolean, [nextValue?: boolean], void> & {
40
- init: boolean;
41
- };
42
- /**
43
- * Hook that retrieves the current state, and a setter, for the `isUIVisible`
44
- * atom.
45
- */
46
- export declare function useIsUIVisible(): [boolean, (nextValue?: boolean) => void];
47
- /**
48
- * Hook that retrieves the current state, and a setter, for the
49
- * `isSplitPanelVisibleAtom` atom.
50
- */
51
- export declare function useIsSplitPanelVisible(): [boolean, (nextValue?: boolean) => void];
52
- interface SyncExternalUIParams {
53
- isUIVisible?: boolean;
54
- isSplitPanelVisible?: boolean;
55
- }
56
- /**
57
- * Sync the UI atom states with external values, such as from Story parameters.
58
- */
59
- export declare function syncExternalUI({ isUIVisible, isSplitPanelVisible }: SyncExternalUIParams): void;
60
- /**
61
- * Hook that manages the state for the currently selected addon.
62
- *
63
- * This value persists across stories, so that the same addon will be selected
64
- * when switching stories.
65
- */
66
- export declare function useSelectedAddon(initialValue?: string): [string, (args_0: string | ((prev: string) => string)) => void];
67
- export {};
package/dist/hooks.js DELETED
@@ -1,168 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.useSelectedAddon = exports.syncExternalUI = exports.useIsSplitPanelVisible = exports.useIsUIVisible = exports.atomWithToggle = exports.useTheme = exports.useUpdateOnStoryChanged = exports.useIsChildSelected = exports.useIsStorySectionSelected = exports.useIsStorySelected = exports.useStoryContextParam = exports.useStoryContext = exports.useSetStoryContext = void 0;
27
- var react_1 = __importStar(require("react"));
28
- var jotai_1 = require("jotai");
29
- var react_2 = require("@emotion/react");
30
- var storyContextAtom = (0, jotai_1.atom)(null);
31
- /**
32
- * Hook that returns a function to set the current story context.
33
- */
34
- function useSetStoryContext() {
35
- return (0, jotai_1.useSetAtom)(storyContextAtom);
36
- }
37
- exports.useSetStoryContext = useSetStoryContext;
38
- /**
39
- * Hook to read the current story context.
40
- */
41
- function useStoryContext() {
42
- return (0, jotai_1.useAtomValue)(storyContextAtom);
43
- }
44
- exports.useStoryContext = useStoryContext;
45
- /**
46
- * Hook that reads the value of a specific story context parameter.
47
- */
48
- function useStoryContextParam(name, defaultValue) {
49
- var _a;
50
- var paramAtom = (0, react_1.useMemo)(function () { return (0, jotai_1.atom)(function (get) { var _a, _b; return (_b = (_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.parameters) === null || _b === void 0 ? void 0 : _b[name]; }); }, [name]);
51
- return (_a = (0, jotai_1.useAtomValue)(paramAtom)) !== null && _a !== void 0 ? _a : defaultValue;
52
- }
53
- exports.useStoryContextParam = useStoryContextParam;
54
- /**
55
- * Hook that indicates if `storyId` is the currently selected story.
56
- */
57
- function useIsStorySelected(storyId) {
58
- return (0, jotai_1.useAtomValue)((0, react_1.useMemo)(function () { return (0, jotai_1.atom)(function (get) { var _a; return ((_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.id) === storyId; }); }, [storyId]));
59
- }
60
- exports.useIsStorySelected = useIsStorySelected;
61
- /**
62
- * Hook that indicates if story kind (title) is the currently selected story section.
63
- */
64
- function useIsStorySectionSelected(title) {
65
- return (0, jotai_1.useAtomValue)((0, react_1.useMemo)(function () {
66
- return (0, jotai_1.atom)(function (get) {
67
- var _a;
68
- var contextTitle = (_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.title;
69
- return contextTitle === title || (contextTitle === null || contextTitle === void 0 ? void 0 : contextTitle.startsWith("".concat(title, "/")));
70
- });
71
- }, [title]));
72
- }
73
- exports.useIsStorySectionSelected = useIsStorySectionSelected;
74
- function useIsChildSelected(entries) {
75
- return (0, jotai_1.useAtomValue)((0, react_1.useMemo)(function () {
76
- return (0, jotai_1.atom)(function (get) {
77
- var _a;
78
- var contextId = (_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.id;
79
- return !!entries.find(function (_a) {
80
- var id = _a.id;
81
- return id === contextId;
82
- });
83
- });
84
- }, [entries]));
85
- }
86
- exports.useIsChildSelected = useIsChildSelected;
87
- /**
88
- * Hook that causes a re-render when the currently selected story is changed.
89
- */
90
- function useUpdateOnStoryChanged() {
91
- (0, jotai_1.useAtomValue)((0, react_1.useMemo)(function () { return (0, jotai_1.atom)(function (get) { var _a; return (_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.id; }); }, []));
92
- }
93
- exports.useUpdateOnStoryChanged = useUpdateOnStoryChanged;
94
- /**
95
- * Hook that gets the current theme values.
96
- */
97
- function useTheme() {
98
- return (0, react_2.useTheme)();
99
- }
100
- exports.useTheme = useTheme;
101
- /**
102
- * A boolean atom creator for an atom that can only be toggled between
103
- * true/false.
104
- *
105
- * @see {@link https://jotai.org/docs/recipes/atom-creators#atomwithtoggle}
106
- */
107
- function atomWithToggle(initialValue) {
108
- var anAtom = (0, jotai_1.atom)(initialValue, function (get, set, nextValue) {
109
- var update = nextValue !== null && nextValue !== void 0 ? nextValue : !get(anAtom);
110
- set(anAtom, update);
111
- });
112
- return anAtom;
113
- }
114
- exports.atomWithToggle = atomWithToggle;
115
- var isUIVisibleAtom = atomWithToggle(true);
116
- /**
117
- * Hook that retrieves the current state, and a setter, for the `isUIVisible`
118
- * atom.
119
- */
120
- function useIsUIVisible() {
121
- return (0, jotai_1.useAtom)(isUIVisibleAtom);
122
- }
123
- exports.useIsUIVisible = useIsUIVisible;
124
- var isSplitPanelVisibleAtom = atomWithToggle(false);
125
- /**
126
- * Hook that retrieves the current state, and a setter, for the
127
- * `isSplitPanelVisibleAtom` atom.
128
- */
129
- function useIsSplitPanelVisible() {
130
- return (0, jotai_1.useAtom)(isSplitPanelVisibleAtom);
131
- }
132
- exports.useIsSplitPanelVisible = useIsSplitPanelVisible;
133
- /**
134
- * Sync the UI atom states with external values, such as from Story parameters.
135
- */
136
- function syncExternalUI(_a) {
137
- var isUIVisible = _a.isUIVisible, isSplitPanelVisible = _a.isSplitPanelVisible;
138
- var jotaiStore = (0, jotai_1.getDefaultStore)();
139
- if (isUIVisible !== undefined) {
140
- jotaiStore.set(isUIVisibleAtom, isUIVisible);
141
- }
142
- if (isSplitPanelVisible !== undefined) {
143
- jotaiStore.set(isSplitPanelVisibleAtom, isSplitPanelVisible);
144
- }
145
- }
146
- exports.syncExternalUI = syncExternalUI;
147
- var selectedAddonAtom = (0, jotai_1.atom)(undefined);
148
- /**
149
- * Hook that manages the state for the currently selected addon.
150
- *
151
- * This value persists across stories, so that the same addon will be selected
152
- * when switching stories.
153
- */
154
- function useSelectedAddon(initialValue) {
155
- var result = (0, jotai_1.useAtom)(selectedAddonAtom);
156
- var set = result[1];
157
- react_1.default.useEffect(function () {
158
- var jotaiStore = (0, jotai_1.getDefaultStore)();
159
- // Only apply the initial value once, and only if the atom doesn't have a
160
- // value yet.
161
- if (jotaiStore.get(selectedAddonAtom) === undefined) {
162
- set(initialValue);
163
- }
164
- // eslint-disable-next-line react-hooks/exhaustive-deps
165
- }, []);
166
- return result;
167
- }
168
- exports.useSelectedAddon = useSelectedAddon;
@@ -1,50 +0,0 @@
1
- import { StoryIndex, SelectionSpecifier } from '@storybook/store';
2
- import { StoryContext } from '@storybook/csf';
3
- import { Theme } from '@storybook/react-native-theming';
4
- import type { ReactNativeFramework } from '../types/types-6.0';
5
- import { PreviewWeb } from '@storybook/preview-web';
6
- type StoryKind = string;
7
- type StoryName = string;
8
- type InitialSelection = `${StoryKind}--${StoryName}` | {
9
- /**
10
- * Kind is the default export name or the storiesOf("name") name
11
- */
12
- kind: StoryKind;
13
- /**
14
- * Name is the named export or the .add("name") name
15
- */
16
- name: StoryName;
17
- };
18
- type DeepPartial<T> = T extends object ? {
19
- [P in keyof T]?: DeepPartial<T[P]>;
20
- } : T;
21
- export type Params = {
22
- onDeviceUI?: boolean;
23
- enableWebsockets?: boolean;
24
- query?: string;
25
- host?: string;
26
- port?: number;
27
- secured?: boolean;
28
- initialSelection?: InitialSelection;
29
- shouldPersistSelection?: boolean;
30
- tabOpen?: number;
31
- isUIHidden?: boolean;
32
- isSplitPanelVisible?: boolean;
33
- shouldDisableKeyboardAvoidingView?: boolean;
34
- keyboardAvoidingViewVerticalOffset?: number;
35
- theme: DeepPartial<Theme>;
36
- };
37
- export declare class View {
38
- _storyIndex: StoryIndex;
39
- _setStory: (story: StoryContext<ReactNativeFramework>) => void;
40
- _forceRerender: () => void;
41
- _ready: boolean;
42
- _preview: PreviewWeb<ReactNativeFramework>;
43
- _asyncStorageStoryId: string;
44
- _webUrl: string;
45
- constructor(preview: PreviewWeb<ReactNativeFramework>);
46
- _getInitialStory: ({ initialSelection, shouldPersistSelection, }?: Partial<Params>) => Promise<SelectionSpecifier>;
47
- _getServerChannel: (params?: Partial<Params>) => import("@storybook/channels").Channel;
48
- getStorybookUI: (params?: Partial<Params>) => () => import("react/jsx-runtime").JSX.Element;
49
- }
50
- export {};
@@ -1,183 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.View = void 0;
43
- var jsx_runtime_1 = require("react/jsx-runtime");
44
- var react_1 = require("react");
45
- var async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
46
- var csf_1 = require("@storybook/csf");
47
- var addons_1 = require("@storybook/addons");
48
- var react_2 = require("@emotion/react");
49
- var react_native_safe_area_context_1 = require("react-native-safe-area-context");
50
- var hooks_1 = require("../hooks");
51
- var OnDeviceUI_1 = __importDefault(require("./components/OnDeviceUI"));
52
- var react_native_theming_1 = require("@storybook/react-native-theming");
53
- var StoryView_1 = __importDefault(require("./components/StoryView"));
54
- var channel_websocket_1 = __importDefault(require("@storybook/channel-websocket"));
55
- var rn_host_detect_1 = __importDefault(require("./rn-host-detect"));
56
- var core_events_1 = __importDefault(require("@storybook/core-events"));
57
- var react_native_1 = require("react-native");
58
- var deepmerge_1 = __importDefault(require("deepmerge"));
59
- var STORAGE_KEY = 'lastOpenedStory';
60
- var View = /** @class */ (function () {
61
- function View(preview) {
62
- var _this = this;
63
- this._setStory = function () { };
64
- this._ready = false;
65
- this._getInitialStory = function (_a) {
66
- var _b = _a === void 0 ? {} : _a, initialSelection = _b.initialSelection, _c = _b.shouldPersistSelection, shouldPersistSelection = _c === void 0 ? true : _c;
67
- return __awaiter(_this, void 0, void 0, function () {
68
- var value, e_1;
69
- return __generator(this, function (_d) {
70
- switch (_d.label) {
71
- case 0:
72
- if (initialSelection) {
73
- if (typeof initialSelection === 'string') {
74
- return [2 /*return*/, { storySpecifier: initialSelection, viewMode: 'story' }];
75
- }
76
- else {
77
- return [2 /*return*/, {
78
- storySpecifier: (0, csf_1.toId)(initialSelection.kind, initialSelection.name),
79
- viewMode: 'story',
80
- }];
81
- }
82
- }
83
- if (!shouldPersistSelection) return [3 /*break*/, 5];
84
- _d.label = 1;
85
- case 1:
86
- _d.trys.push([1, 4, , 5]);
87
- value = this._asyncStorageStoryId;
88
- if (!!value) return [3 /*break*/, 3];
89
- return [4 /*yield*/, async_storage_1.default.getItem(STORAGE_KEY)];
90
- case 2:
91
- value = _d.sent();
92
- this._asyncStorageStoryId = value;
93
- _d.label = 3;
94
- case 3: return [2 /*return*/, { storySpecifier: value !== null && value !== void 0 ? value : '*', viewMode: 'story' }];
95
- case 4:
96
- e_1 = _d.sent();
97
- console.warn('storybook-log: error reading from async storage', e_1);
98
- return [3 /*break*/, 5];
99
- case 5: return [2 /*return*/, { storySpecifier: '*', viewMode: 'story' }];
100
- }
101
- });
102
- });
103
- };
104
- this._getServerChannel = function (params) {
105
- if (params === void 0) { params = {}; }
106
- var host = (0, rn_host_detect_1.default)(params.host || 'localhost');
107
- var port = ":".concat(params.port || 7007);
108
- var query = params.query || '';
109
- var websocketType = params.secured ? 'wss' : 'ws';
110
- var url = "".concat(websocketType, "://").concat(host).concat(port, "/").concat(query);
111
- return (0, channel_websocket_1.default)({
112
- url: url,
113
- async: true,
114
- onError: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
115
- return [2 /*return*/];
116
- }); }); },
117
- });
118
- };
119
- this.getStorybookUI = function (params) {
120
- if (params === void 0) { params = {}; }
121
- var _a = params.shouldPersistSelection, shouldPersistSelection = _a === void 0 ? true : _a, _b = params.onDeviceUI, onDeviceUI = _b === void 0 ? true : _b, _c = params.enableWebsockets, enableWebsockets = _c === void 0 ? false : _c;
122
- var initialStory = _this._getInitialStory(params);
123
- if (enableWebsockets) {
124
- var channel = _this._getServerChannel(params);
125
- addons_1.addons.setChannel(channel);
126
- // TODO: check this with someone who knows what they're doing
127
- _this._preview.channel = channel;
128
- _this._preview.setupListeners();
129
- channel.emit(core_events_1.default.CHANNEL_CREATED);
130
- _this._preview.initializeWithStoryIndex(_this._storyIndex);
131
- }
132
- addons_1.addons.loadAddons({
133
- store: function () { return ({
134
- fromId: function (id) {
135
- return _this._preview.storyStore.getStoryContext(_this._preview.storyStore.fromId(id));
136
- },
137
- getSelection: function () {
138
- return _this._preview.currentSelection;
139
- },
140
- _channel: _this._preview.channel,
141
- }); },
142
- });
143
- // eslint-disable-next-line consistent-this
144
- var self = _this;
145
- // Sync the Storybook parameters (external) with app UI state (internal), to initialise them.
146
- (0, hooks_1.syncExternalUI)({
147
- isUIVisible: params.isUIHidden !== undefined ? !params.isUIHidden : undefined,
148
- isSplitPanelVisible: params.isSplitPanelVisible,
149
- });
150
- return function () {
151
- var setContext = (0, hooks_1.useSetStoryContext)();
152
- var colorScheme = (0, react_native_1.useColorScheme)();
153
- var _a = (0, react_1.useReducer)(function (x) { return x + 1; }, 0), forceUpdate = _a[1];
154
- var appliedTheme = (0, react_1.useMemo)(function () { var _a; return (0, deepmerge_1.default)(colorScheme === 'dark' ? react_native_theming_1.darkTheme : react_native_theming_1.theme, (_a = params.theme) !== null && _a !== void 0 ? _a : {}); }, [colorScheme]);
155
- (0, react_1.useEffect)(function () {
156
- self._setStory = function (newStory) {
157
- setContext(newStory);
158
- if (shouldPersistSelection) {
159
- async_storage_1.default.setItem(STORAGE_KEY, newStory.id).catch(function (e) {
160
- console.warn('storybook-log: error writing to async storage', e);
161
- });
162
- }
163
- };
164
- self._forceRerender = function () { return forceUpdate(); };
165
- initialStory.then(function (story) {
166
- self._preview.urlStore.selectionSpecifier = story;
167
- self._preview.selectSpecifiedStory();
168
- });
169
- // eslint-disable-next-line react-hooks/exhaustive-deps
170
- }, []);
171
- if (onDeviceUI) {
172
- return ((0, jsx_runtime_1.jsx)(react_native_safe_area_context_1.SafeAreaProvider, { children: (0, jsx_runtime_1.jsx)(react_2.ThemeProvider, { theme: appliedTheme, children: (0, jsx_runtime_1.jsx)(OnDeviceUI_1.default, { storyIndex: self._storyIndex, tabOpen: params.tabOpen, shouldDisableKeyboardAvoidingView: params.shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset: params.keyboardAvoidingViewVerticalOffset }) }) }));
173
- }
174
- else {
175
- return (0, jsx_runtime_1.jsx)(StoryView_1.default, {});
176
- }
177
- };
178
- };
179
- this._preview = preview;
180
- }
181
- return View;
182
- }());
183
- exports.View = View;
@@ -1,12 +0,0 @@
1
- import { StoryIndex } from '@storybook/client-api';
2
- import React from 'react';
3
- export declare const IS_EXPO: boolean;
4
- interface OnDeviceUIProps {
5
- storyIndex: StoryIndex;
6
- url?: string;
7
- tabOpen?: number;
8
- shouldDisableKeyboardAvoidingView?: boolean;
9
- keyboardAvoidingViewVerticalOffset?: number;
10
- }
11
- declare const _default: React.MemoExoticComponent<({ storyIndex, shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset, tabOpen: initialTabOpen, }: OnDeviceUIProps) => import("react/jsx-runtime").JSX.Element>;
12
- export default _default;