@storybook/react-native 6.5.3 → 6.5.4-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 (34) hide show
  1. package/dist/constants.js +4 -1
  2. package/dist/hooks.js +75 -36
  3. package/dist/index.js +40 -18
  4. package/dist/preview/View.js +165 -88
  5. package/dist/preview/components/OnDeviceUI/OnDeviceUI.js +127 -81
  6. package/dist/preview/components/OnDeviceUI/Panel.js +24 -15
  7. package/dist/preview/components/OnDeviceUI/absolute-positioned-keyboard-aware-view.js +17 -10
  8. package/dist/preview/components/OnDeviceUI/addons/Addons.js +32 -23
  9. package/dist/preview/components/OnDeviceUI/addons/AddonsSkeleton.js +69 -41
  10. package/dist/preview/components/OnDeviceUI/addons/List.js +15 -9
  11. package/dist/preview/components/OnDeviceUI/addons/Wrapper.js +27 -18
  12. package/dist/preview/components/OnDeviceUI/addons/index.js +8 -1
  13. package/dist/preview/components/OnDeviceUI/animation.js +37 -29
  14. package/dist/preview/components/OnDeviceUI/index.js +8 -1
  15. package/dist/preview/components/OnDeviceUI/navigation/Navigation.js +31 -24
  16. package/dist/preview/components/OnDeviceUI/navigation/NavigationBar.js +26 -14
  17. package/dist/preview/components/OnDeviceUI/navigation/NavigationButton.js +26 -17
  18. package/dist/preview/components/OnDeviceUI/navigation/constants.js +6 -3
  19. package/dist/preview/components/OnDeviceUI/navigation/index.js +8 -1
  20. package/dist/preview/components/Shared/icons.js +28 -10
  21. package/dist/preview/components/Shared/layout.js +21 -4
  22. package/dist/preview/components/Shared/tabs.js +41 -27
  23. package/dist/preview/components/Shared/theme.js +11 -8
  24. package/dist/preview/components/StoryListView/StoryListView.js +161 -97
  25. package/dist/preview/components/StoryListView/index.js +8 -1
  26. package/dist/preview/components/StoryView/StoryView.js +30 -14
  27. package/dist/preview/components/StoryView/index.js +8 -1
  28. package/dist/preview/executeLoadable.d.ts +4 -1
  29. package/dist/preview/executeLoadable.js +43 -23
  30. package/dist/preview/rn-host-detect.js +3 -1
  31. package/dist/preview/start.js +80 -55
  32. package/dist/types/types-6.0.js +2 -1
  33. package/dist/types/types.js +2 -1
  34. package/package.json +3 -3
package/dist/constants.js CHANGED
@@ -1,5 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ANIMATION_DURATION_TRANSITION = void 0;
1
4
  /**
2
5
  * Duration for a typical transition animation, such as rescaling the canvas
3
6
  * UI.
4
7
  */
5
- export const ANIMATION_DURATION_TRANSITION = 400;
8
+ exports.ANIMATION_DURATION_TRANSITION = 400;
package/dist/hooks.js CHANGED
@@ -1,85 +1,122 @@
1
- import React, { useMemo } from 'react';
2
- import { atom, useAtom, useAtomValue, useSetAtom, getDefaultStore } from 'jotai';
3
- import { useTheme as useEmotionTheme } from 'emotion-theming';
4
- const storyContextAtom = atom(null);
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.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 emotion_theming_1 = require("emotion-theming");
30
+ var storyContextAtom = (0, jotai_1.atom)(null);
5
31
  /**
6
32
  * Hook that returns a function to set the current story context.
7
33
  */
8
- export function useSetStoryContext() {
9
- return useSetAtom(storyContextAtom);
34
+ function useSetStoryContext() {
35
+ return (0, jotai_1.useSetAtom)(storyContextAtom);
10
36
  }
37
+ exports.useSetStoryContext = useSetStoryContext;
11
38
  /**
12
39
  * Hook to read the current story context.
13
40
  */
14
- export function useStoryContext() {
15
- return useAtomValue(storyContextAtom);
41
+ function useStoryContext() {
42
+ return (0, jotai_1.useAtomValue)(storyContextAtom);
16
43
  }
44
+ exports.useStoryContext = useStoryContext;
17
45
  /**
18
46
  * Hook that reads the value of a specific story context parameter.
19
47
  */
20
- export function useStoryContextParam(name, defaultValue) {
48
+ function useStoryContextParam(name, defaultValue) {
21
49
  var _a;
22
- const paramAtom = useMemo(() => atom((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]);
23
- return (_a = useAtomValue(paramAtom)) !== null && _a !== void 0 ? _a : defaultValue;
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;
24
52
  }
53
+ exports.useStoryContextParam = useStoryContextParam;
25
54
  /**
26
55
  * Hook that indicates if `storyId` is the currently selected story.
27
56
  */
28
- export function useIsStorySelected(storyId) {
29
- return useAtomValue(useMemo(() => atom((get) => { var _a; return ((_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.id) === storyId; }), [storyId]));
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]));
30
59
  }
60
+ exports.useIsStorySelected = useIsStorySelected;
31
61
  /**
32
62
  * Hook that indicates if `title` is the currently selected story section.
33
63
  */
34
- export function useIsStorySectionSelected(title) {
35
- return useAtomValue(useMemo(() => atom((get) => { var _a; return ((_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.title) === title; }), [title]));
64
+ function useIsStorySectionSelected(title) {
65
+ 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.title) === title; }); }, [title]));
36
66
  }
67
+ exports.useIsStorySectionSelected = useIsStorySectionSelected;
37
68
  /**
38
69
  * Hook that causes a re-render when the currently selected story is changed.
39
70
  */
40
- export function useUpdateOnStoryChanged() {
41
- useAtomValue(useMemo(() => atom((get) => { var _a; return (_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.id; }), []));
71
+ function useUpdateOnStoryChanged() {
72
+ (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; }); }, []));
42
73
  }
74
+ exports.useUpdateOnStoryChanged = useUpdateOnStoryChanged;
43
75
  /**
44
76
  * Hook that gets the current theme values.
45
77
  */
46
- export function useTheme() {
47
- return useEmotionTheme();
78
+ function useTheme() {
79
+ return (0, emotion_theming_1.useTheme)();
48
80
  }
81
+ exports.useTheme = useTheme;
49
82
  /**
50
83
  * A boolean atom creator for an atom that can only be toggled between
51
84
  * true/false.
52
85
  *
53
86
  * @see {@link https://jotai.org/docs/recipes/atom-creators#atomwithtoggle}
54
87
  */
55
- export function atomWithToggle(initialValue) {
56
- const anAtom = atom(initialValue, (get, set, nextValue) => {
57
- const update = nextValue !== null && nextValue !== void 0 ? nextValue : !get(anAtom);
88
+ function atomWithToggle(initialValue) {
89
+ var anAtom = (0, jotai_1.atom)(initialValue, function (get, set, nextValue) {
90
+ var update = nextValue !== null && nextValue !== void 0 ? nextValue : !get(anAtom);
58
91
  set(anAtom, update);
59
92
  });
60
93
  return anAtom;
61
94
  }
62
- const isUIVisibleAtom = atomWithToggle(true);
95
+ exports.atomWithToggle = atomWithToggle;
96
+ var isUIVisibleAtom = atomWithToggle(true);
63
97
  /**
64
98
  * Hook that retrieves the current state, and a setter, for the `isUIVisible`
65
99
  * atom.
66
100
  */
67
- export function useIsUIVisible() {
68
- return useAtom(isUIVisibleAtom);
101
+ function useIsUIVisible() {
102
+ return (0, jotai_1.useAtom)(isUIVisibleAtom);
69
103
  }
70
- const isSplitPanelVisibleAtom = atomWithToggle(false);
104
+ exports.useIsUIVisible = useIsUIVisible;
105
+ var isSplitPanelVisibleAtom = atomWithToggle(false);
71
106
  /**
72
107
  * Hook that retrieves the current state, and a setter, for the
73
108
  * `isSplitPanelVisibleAtom` atom.
74
109
  */
75
- export function useIsSplitPanelVisible() {
76
- return useAtom(isSplitPanelVisibleAtom);
110
+ function useIsSplitPanelVisible() {
111
+ return (0, jotai_1.useAtom)(isSplitPanelVisibleAtom);
77
112
  }
113
+ exports.useIsSplitPanelVisible = useIsSplitPanelVisible;
78
114
  /**
79
115
  * Sync the UI atom states with external values, such as from Story parameters.
80
116
  */
81
- export function syncExternalUI({ isUIVisible, isSplitPanelVisible }) {
82
- const jotaiStore = getDefaultStore();
117
+ function syncExternalUI(_a) {
118
+ var isUIVisible = _a.isUIVisible, isSplitPanelVisible = _a.isSplitPanelVisible;
119
+ var jotaiStore = (0, jotai_1.getDefaultStore)();
83
120
  if (isUIVisible !== undefined) {
84
121
  jotaiStore.set(isUIVisibleAtom, isUIVisible);
85
122
  }
@@ -87,18 +124,19 @@ export function syncExternalUI({ isUIVisible, isSplitPanelVisible }) {
87
124
  jotaiStore.set(isSplitPanelVisibleAtom, isSplitPanelVisible);
88
125
  }
89
126
  }
90
- const selectedAddonAtom = atom(undefined);
127
+ exports.syncExternalUI = syncExternalUI;
128
+ var selectedAddonAtom = (0, jotai_1.atom)(undefined);
91
129
  /**
92
130
  * Hook that manages the state for the currently selected addon.
93
131
  *
94
132
  * This value persists across stories, so that the same addon will be selected
95
133
  * when switching stories.
96
134
  */
97
- export function useSelectedAddon(initialValue) {
98
- const result = useAtom(selectedAddonAtom);
99
- const set = result[1];
100
- React.useEffect(() => {
101
- const jotaiStore = getDefaultStore();
135
+ function useSelectedAddon(initialValue) {
136
+ var result = (0, jotai_1.useAtom)(selectedAddonAtom);
137
+ var set = result[1];
138
+ react_1.default.useEffect(function () {
139
+ var jotaiStore = (0, jotai_1.getDefaultStore)();
102
140
  // Only apply the initial value once, and only if the atom doesn't have a
103
141
  // value yet.
104
142
  if (jotaiStore.get(selectedAddonAtom) === undefined) {
@@ -108,3 +146,4 @@ export function useSelectedAddon(initialValue) {
108
146
  }, []);
109
147
  return result;
110
148
  }
149
+ exports.useSelectedAddon = useSelectedAddon;
package/dist/index.js CHANGED
@@ -1,23 +1,45 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
1
16
  var _a;
2
- import { start } from './preview/start';
3
- const { clientApi, configure, view } = start();
4
- export { configure };
5
- const rawStoriesOf = clientApi.storiesOf.bind(clientApi);
6
- export const setAddon = clientApi.setAddon.bind(clientApi);
7
- export const addDecorator = clientApi.addDecorator.bind(clientApi);
8
- export const addParameters = clientApi.addParameters.bind(clientApi);
9
- export const addArgsEnhancer = clientApi.addArgsEnhancer.bind(clientApi);
10
- export const addArgTypesEnhancer = clientApi.addArgTypesEnhancer.bind(clientApi);
11
- export const clearDecorators = clientApi.clearDecorators.bind(clientApi);
12
- export const getStorybook = clientApi.getStorybook.bind(clientApi);
13
- export const raw = clientApi.raw.bind(clientApi);
14
- export const storiesOf = (kind, _module) => rawStoriesOf(kind, { hot: () => { } }).addParameters({
15
- framework: 'react-native',
16
- });
17
- export const getStorybookUI = view.getStorybookUI;
18
- export * from './types/types-6.0';
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.darkTheme = exports.theme = exports.getStorybookUI = exports.storiesOf = exports.raw = exports.getStorybook = exports.clearDecorators = exports.addArgTypesEnhancer = exports.addArgsEnhancer = exports.addParameters = exports.addDecorator = exports.setAddon = exports.configure = void 0;
19
+ var start_1 = require("./preview/start");
20
+ var _b = (0, start_1.start)(), clientApi = _b.clientApi, configure = _b.configure, view = _b.view;
21
+ exports.configure = configure;
22
+ var rawStoriesOf = clientApi.storiesOf.bind(clientApi);
23
+ exports.setAddon = clientApi.setAddon.bind(clientApi);
24
+ exports.addDecorator = clientApi.addDecorator.bind(clientApi);
25
+ exports.addParameters = clientApi.addParameters.bind(clientApi);
26
+ exports.addArgsEnhancer = clientApi.addArgsEnhancer.bind(clientApi);
27
+ exports.addArgTypesEnhancer = clientApi.addArgTypesEnhancer.bind(clientApi);
28
+ exports.clearDecorators = clientApi.clearDecorators.bind(clientApi);
29
+ exports.getStorybook = clientApi.getStorybook.bind(clientApi);
30
+ exports.raw = clientApi.raw.bind(clientApi);
31
+ var storiesOf = function (kind, _module) {
32
+ return rawStoriesOf(kind, { hot: function () { } }).addParameters({
33
+ framework: 'react-native',
34
+ });
35
+ };
36
+ exports.storiesOf = storiesOf;
37
+ exports.getStorybookUI = view.getStorybookUI;
38
+ __exportStar(require("./types/types-6.0"), exports);
19
39
  // @storybook/addon-storyshots v6 needs global.__STORYBOOK_STORY_STORE__.initializationPromise
20
40
  global.__STORYBOOK_STORY_STORE__ = {
21
41
  initializationPromise: (_a = clientApi.storyStore) === null || _a === void 0 ? void 0 : _a.initializationPromise,
22
42
  };
23
- export { theme, darkTheme } from './preview/components/Shared/theme';
43
+ var theme_1 = require("./preview/components/Shared/theme");
44
+ Object.defineProperty(exports, "theme", { enumerable: true, get: function () { return theme_1.theme; } });
45
+ Object.defineProperty(exports, "darkTheme", { enumerable: true, get: function () { return theme_1.darkTheme; } });
@@ -1,3 +1,27 @@
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
+ };
1
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,127 +31,180 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
32
  });
9
33
  };
10
- import React, { useEffect, useMemo, useReducer } from 'react';
11
- import AsyncStorage from '@react-native-async-storage/async-storage';
12
- import { toId } from '@storybook/csf';
13
- import { addons } from '@storybook/addons';
14
- import { ThemeProvider } from 'emotion-theming';
15
- import { SafeAreaProvider } from 'react-native-safe-area-context';
16
- import { useSetStoryContext, syncExternalUI } from '../hooks';
17
- import OnDeviceUI from './components/OnDeviceUI';
18
- import { darkTheme, theme } from './components/Shared/theme';
19
- import StoryView from './components/StoryView';
20
- import createChannel from '@storybook/channel-websocket';
21
- import getHost from './rn-host-detect';
22
- import events from '@storybook/core-events';
23
- import { useColorScheme } from 'react-native';
24
- import deepmerge from 'deepmerge';
25
- const STORAGE_KEY = 'lastOpenedStory';
26
- export class View {
27
- constructor(preview) {
28
- this._setStory = () => { };
29
- this._ready = false;
30
- this._getInitialStory = ({ initialSelection, shouldPersistSelection = true, } = {}) => __awaiter(this, void 0, void 0, function* () {
31
- if (initialSelection) {
32
- if (typeof initialSelection === 'string') {
33
- return { storySpecifier: initialSelection, viewMode: 'story' };
34
- }
35
- else {
36
- return {
37
- storySpecifier: toId(initialSelection.kind, initialSelection.name),
38
- viewMode: 'story',
39
- };
40
- }
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
41
55
  }
42
- if (shouldPersistSelection) {
43
- try {
44
- let value = this._asyncStorageStoryId;
45
- if (!value) {
46
- value = yield AsyncStorage.getItem(STORAGE_KEY);
47
- this._asyncStorageStoryId = value;
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.View = void 0;
66
+ var react_1 = __importStar(require("react"));
67
+ var async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
68
+ var csf_1 = require("@storybook/csf");
69
+ var addons_1 = require("@storybook/addons");
70
+ var emotion_theming_1 = require("emotion-theming");
71
+ var react_native_safe_area_context_1 = require("react-native-safe-area-context");
72
+ var hooks_1 = require("../hooks");
73
+ var OnDeviceUI_1 = __importDefault(require("./components/OnDeviceUI"));
74
+ var theme_1 = require("./components/Shared/theme");
75
+ var StoryView_1 = __importDefault(require("./components/StoryView"));
76
+ var channel_websocket_1 = __importDefault(require("@storybook/channel-websocket"));
77
+ var rn_host_detect_1 = __importDefault(require("./rn-host-detect"));
78
+ var core_events_1 = __importDefault(require("@storybook/core-events"));
79
+ var react_native_1 = require("react-native");
80
+ var deepmerge_1 = __importDefault(require("deepmerge"));
81
+ var STORAGE_KEY = 'lastOpenedStory';
82
+ var View = /** @class */ (function () {
83
+ function View(preview) {
84
+ var _this = this;
85
+ this._setStory = function () { };
86
+ this._ready = false;
87
+ this._getInitialStory = function (_a) {
88
+ var _b = _a === void 0 ? {} : _a, initialSelection = _b.initialSelection, _c = _b.shouldPersistSelection, shouldPersistSelection = _c === void 0 ? true : _c;
89
+ return __awaiter(_this, void 0, void 0, function () {
90
+ var value, e_1;
91
+ return __generator(this, function (_d) {
92
+ switch (_d.label) {
93
+ case 0:
94
+ if (initialSelection) {
95
+ if (typeof initialSelection === 'string') {
96
+ return [2 /*return*/, { storySpecifier: initialSelection, viewMode: 'story' }];
97
+ }
98
+ else {
99
+ return [2 /*return*/, {
100
+ storySpecifier: (0, csf_1.toId)(initialSelection.kind, initialSelection.name),
101
+ viewMode: 'story',
102
+ }];
103
+ }
104
+ }
105
+ if (!shouldPersistSelection) return [3 /*break*/, 5];
106
+ _d.label = 1;
107
+ case 1:
108
+ _d.trys.push([1, 4, , 5]);
109
+ value = this._asyncStorageStoryId;
110
+ if (!!value) return [3 /*break*/, 3];
111
+ return [4 /*yield*/, async_storage_1.default.getItem(STORAGE_KEY)];
112
+ case 2:
113
+ value = _d.sent();
114
+ this._asyncStorageStoryId = value;
115
+ _d.label = 3;
116
+ case 3: return [2 /*return*/, { storySpecifier: value !== null && value !== void 0 ? value : '*', viewMode: 'story' }];
117
+ case 4:
118
+ e_1 = _d.sent();
119
+ console.warn('storybook-log: error reading from async storage', e_1);
120
+ return [3 /*break*/, 5];
121
+ case 5: return [2 /*return*/, { storySpecifier: '*', viewMode: 'story' }];
48
122
  }
49
- return { storySpecifier: value !== null && value !== void 0 ? value : '*', viewMode: 'story' };
50
- }
51
- catch (e) {
52
- console.warn('storybook-log: error reading from async storage', e);
53
- }
54
- }
55
- return { storySpecifier: '*', viewMode: 'story' };
56
- });
57
- this._getServerChannel = (params = {}) => {
58
- const host = getHost(params.host || 'localhost');
59
- const port = `:${params.port || 7007}`;
60
- const query = params.query || '';
61
- const websocketType = params.secured ? 'wss' : 'ws';
62
- const url = `${websocketType}://${host}${port}/${query}`;
63
- return createChannel({
64
- url,
123
+ });
124
+ });
125
+ };
126
+ this._getServerChannel = function (params) {
127
+ if (params === void 0) { params = {}; }
128
+ var host = (0, rn_host_detect_1.default)(params.host || 'localhost');
129
+ var port = ":".concat(params.port || 7007);
130
+ var query = params.query || '';
131
+ var websocketType = params.secured ? 'wss' : 'ws';
132
+ var url = "".concat(websocketType, "://").concat(host).concat(port, "/").concat(query);
133
+ return (0, channel_websocket_1.default)({
134
+ url: url,
65
135
  async: true,
66
- onError: () => __awaiter(this, void 0, void 0, function* () { }),
136
+ onError: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
137
+ return [2 /*return*/];
138
+ }); }); },
67
139
  });
68
140
  };
69
- this.getStorybookUI = (params = {}) => {
70
- const { shouldPersistSelection = true, onDeviceUI = true, enableWebsockets = false } = params;
71
- const initialStory = this._getInitialStory(params);
141
+ this.getStorybookUI = function (params) {
142
+ if (params === void 0) { params = {}; }
143
+ 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;
144
+ var initialStory = _this._getInitialStory(params);
72
145
  if (enableWebsockets) {
73
- const channel = this._getServerChannel(params);
74
- addons.setChannel(channel);
146
+ var channel = _this._getServerChannel(params);
147
+ addons_1.addons.setChannel(channel);
75
148
  // TODO: check this with someone who knows what they're doing
76
- this._preview.channel = channel;
77
- this._preview.setupListeners();
78
- channel.emit(events.CHANNEL_CREATED);
79
- this._preview.initializeWithStoryIndex(this._storyIndex);
149
+ _this._preview.channel = channel;
150
+ _this._preview.setupListeners();
151
+ channel.emit(core_events_1.default.CHANNEL_CREATED);
152
+ _this._preview.initializeWithStoryIndex(_this._storyIndex);
80
153
  }
81
- addons.loadAddons({
82
- store: () => ({
83
- fromId: (id) => this._preview.storyStore.getStoryContext(this._preview.storyStore.fromId(id)),
84
- getSelection: () => {
85
- return this._preview.currentSelection;
154
+ addons_1.addons.loadAddons({
155
+ store: function () { return ({
156
+ fromId: function (id) {
157
+ return _this._preview.storyStore.getStoryContext(_this._preview.storyStore.fromId(id));
158
+ },
159
+ getSelection: function () {
160
+ return _this._preview.currentSelection;
86
161
  },
87
- _channel: this._preview.channel,
88
- }),
162
+ _channel: _this._preview.channel,
163
+ }); },
89
164
  });
90
165
  // eslint-disable-next-line consistent-this
91
- const self = this;
166
+ var self = _this;
92
167
  // Sync the Storybook parameters (external) with app UI state (internal), to initialise them.
93
- syncExternalUI({
168
+ (0, hooks_1.syncExternalUI)({
94
169
  isUIVisible: params.isUIHidden !== undefined ? !params.isUIHidden : undefined,
95
170
  isSplitPanelVisible: params.isSplitPanelVisible,
96
171
  });
97
- return () => {
98
- const setContext = useSetStoryContext();
99
- const colorScheme = useColorScheme();
100
- const [, forceUpdate] = useReducer((x) => x + 1, 0);
101
- const appliedTheme = useMemo(() => {
172
+ return function () {
173
+ var setContext = (0, hooks_1.useSetStoryContext)();
174
+ var colorScheme = (0, react_native_1.useColorScheme)();
175
+ var _a = (0, react_1.useReducer)(function (x) { return x + 1; }, 0), forceUpdate = _a[1];
176
+ var appliedTheme = (0, react_1.useMemo)(function () {
102
177
  var _a;
103
- return deepmerge(colorScheme === 'dark' ? darkTheme : theme, (_a = params.theme) !== null && _a !== void 0 ? _a : {});
178
+ return (0, deepmerge_1.default)(colorScheme === 'dark' ? theme_1.darkTheme : theme_1.theme, (_a = params.theme) !== null && _a !== void 0 ? _a : {});
104
179
  }, [colorScheme]);
105
- useEffect(() => {
106
- self._setStory = (newStory) => {
180
+ (0, react_1.useEffect)(function () {
181
+ self._setStory = function (newStory) {
107
182
  setContext(newStory);
108
183
  if (shouldPersistSelection) {
109
- AsyncStorage.setItem(STORAGE_KEY, newStory.id).catch((e) => {
184
+ async_storage_1.default.setItem(STORAGE_KEY, newStory.id).catch(function (e) {
110
185
  console.warn('storybook-log: error writing to async storage', e);
111
186
  });
112
187
  }
113
188
  };
114
- self._forceRerender = () => forceUpdate();
115
- initialStory.then((story) => {
189
+ self._forceRerender = function () { return forceUpdate(); };
190
+ initialStory.then(function (story) {
116
191
  self._preview.urlStore.selectionSpecifier = story;
117
192
  self._preview.selectSpecifiedStory();
118
193
  });
119
194
  // eslint-disable-next-line react-hooks/exhaustive-deps
120
195
  }, []);
121
196
  if (onDeviceUI) {
122
- return (React.createElement(SafeAreaProvider, null,
123
- React.createElement(ThemeProvider, { theme: appliedTheme },
124
- React.createElement(OnDeviceUI, { storyIndex: self._storyIndex, tabOpen: params.tabOpen, shouldDisableKeyboardAvoidingView: params.shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset: params.keyboardAvoidingViewVerticalOffset }))));
197
+ return (react_1.default.createElement(react_native_safe_area_context_1.SafeAreaProvider, null,
198
+ react_1.default.createElement(emotion_theming_1.ThemeProvider, { theme: appliedTheme },
199
+ react_1.default.createElement(OnDeviceUI_1.default, { storyIndex: self._storyIndex, tabOpen: params.tabOpen, shouldDisableKeyboardAvoidingView: params.shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset: params.keyboardAvoidingViewVerticalOffset }))));
125
200
  }
126
201
  else {
127
- return React.createElement(StoryView, null);
202
+ return react_1.default.createElement(StoryView_1.default, null);
128
203
  }
129
204
  };
130
205
  };
131
206
  this._preview = preview;
132
207
  }
133
- }
208
+ return View;
209
+ }());
210
+ exports.View = View;