@storybook/react-native 7.6.10-alpha.0 → 7.6.10-alpha.3

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/V6.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { P as Params } from './View-0aedc31a.js';
2
+ import { P as Params } from './View-090d9c8b.js';
3
3
  import { ClientApi } from '@storybook/preview-api';
4
- import { L as LoaderFunction, A as Addon_StoryApi } from './index.d-cff8c6fa.js';
4
+ import { L as LoaderFunction, A as Addon_StoryApi } from './index.d-48fbc63a.js';
5
5
  import { ReactNode } from 'react';
6
6
  import { ReactRenderer } from '@storybook/react';
7
7
  export { Theme, darkTheme, theme } from '@storybook/react-native-theming';
package/dist/V6.js CHANGED
@@ -80,14 +80,21 @@ var import_preview_api3 = require("@storybook/preview-api");
80
80
  var import_preview_web = require("@storybook/preview-web");
81
81
 
82
82
  // src/View.tsx
83
- var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"));
84
83
  var import_csf = require("@storybook/csf");
85
- var import_preview_api2 = require("@storybook/preview-api");
86
84
  var import_manager_api2 = require("@storybook/manager-api");
85
+ var import_preview_api2 = require("@storybook/preview-api");
87
86
  var import_react_native_theming12 = require("@storybook/react-native-theming");
88
87
  var import_react16 = require("react");
89
88
  var import_react_native_safe_area_context3 = require("react-native-safe-area-context");
90
89
 
90
+ // src/components/OnDeviceUI/OnDeviceUI.tsx
91
+ var import_react_native_theming10 = require("@storybook/react-native-theming");
92
+ var import_react15 = __toESM(require("react"));
93
+ var import_react_native14 = require("react-native");
94
+
95
+ // src/constants.ts
96
+ var ANIMATION_DURATION_TRANSITION = 400;
97
+
91
98
  // src/hooks.tsx
92
99
  var import_react2 = __toESM(require("react"));
93
100
 
@@ -841,14 +848,6 @@ function useSelectedAddon(initialValue) {
841
848
  return result;
842
849
  }
843
850
 
844
- // src/components/OnDeviceUI/OnDeviceUI.tsx
845
- var import_react_native_theming10 = require("@storybook/react-native-theming");
846
- var import_react15 = __toESM(require("react"));
847
- var import_react_native14 = require("react-native");
848
-
849
- // src/constants.ts
850
- var ANIMATION_DURATION_TRANSITION = 400;
851
-
852
851
  // src/components/StoryListView/StoryListView.tsx
853
852
  var import_core_events = __toESM(require("@storybook/core-events"));
854
853
  var import_react_native_theming = require("@storybook/react-native-theming");
@@ -1952,6 +1951,7 @@ var OnDeviceUI_default = import_react15.default.memo(OnDeviceUI);
1952
1951
  // src/View.tsx
1953
1952
  var import_channels = require("@storybook/channels");
1954
1953
  var import_core_events2 = __toESM(require("@storybook/core-events"));
1954
+ var import_dedent = __toESM(require("dedent"));
1955
1955
  var import_deepmerge = __toESM(require("deepmerge"));
1956
1956
  var import_react_native16 = require("react-native");
1957
1957
 
@@ -2012,7 +2012,9 @@ var View10 = class {
2012
2012
  _preview;
2013
2013
  _asyncStorageStoryId;
2014
2014
  _webUrl;
2015
+ _storage;
2015
2016
  _channel;
2017
+ _idToPrepared = {};
2016
2018
  constructor(preview, channel) {
2017
2019
  this._preview = preview;
2018
2020
  this._channel = channel;
@@ -2034,8 +2036,8 @@ var View10 = class {
2034
2036
  if (shouldPersistSelection) {
2035
2037
  try {
2036
2038
  let value = this._asyncStorageStoryId;
2037
- if (!value) {
2038
- value = await import_async_storage.default.getItem(STORAGE_KEY);
2039
+ if (!value && this._storage != null) {
2040
+ value = await this._storage.getItem(STORAGE_KEY);
2039
2041
  this._asyncStorageStoryId = value;
2040
2042
  }
2041
2043
  const exists = value && Object.keys(this._storyIndex.entries).includes(value);
@@ -2061,11 +2063,24 @@ var View10 = class {
2061
2063
  }
2062
2064
  });
2063
2065
  };
2066
+ createPreparedStoryMapping = async () => {
2067
+ await Promise.all(
2068
+ Object.keys(this._storyIndex.entries).map(async (storyId) => {
2069
+ this._idToPrepared[storyId] = await this._preview.storyStore.loadStory({ storyId });
2070
+ })
2071
+ );
2072
+ console.log("Storybook: Finished building story index");
2073
+ };
2064
2074
  getStorybookUI = (params = {}) => {
2065
- const { shouldPersistSelection = true, onDeviceUI = true, enableWebsockets = false } = params;
2075
+ const {
2076
+ shouldPersistSelection = true,
2077
+ onDeviceUI = true,
2078
+ enableWebsockets = false,
2079
+ storage
2080
+ } = params;
2081
+ this._storage = storage;
2066
2082
  const initialStory = this._getInitialStory(params);
2067
2083
  if (enableWebsockets) {
2068
- console.log("websockets enabled");
2069
2084
  const channel = this._getServerChannel(params);
2070
2085
  import_manager_api2.addons.setChannel(channel);
2071
2086
  import_preview_api2.addons.setChannel(channel);
@@ -2077,13 +2092,15 @@ var View10 = class {
2077
2092
  }
2078
2093
  import_manager_api2.addons.loadAddons({
2079
2094
  store: () => ({
2080
- fromId: (id) => this._preview.storyStore.getStoryContext(this._preview.storyStore.fromId(id)),
2095
+ fromId: (id) => {
2096
+ if (!this._ready) {
2097
+ throw new Error("Storybook is not ready yet");
2098
+ }
2099
+ return this._preview.storyStore.getStoryContext(this._idToPrepared[id]);
2100
+ },
2081
2101
  getSelection: () => {
2082
2102
  return this._preview.currentSelection;
2083
2103
  },
2084
- // @ts-ignore :) FIXME
2085
- // _channel: this._preview.channel,
2086
- // global.__STORYBOOK_ADDONS_CHANNEL__,
2087
2104
  _channel: this._channel
2088
2105
  })
2089
2106
  });
@@ -2096,15 +2113,30 @@ var View10 = class {
2096
2113
  const setContext = useSetStoryContext();
2097
2114
  const colorScheme = (0, import_react_native16.useColorScheme)();
2098
2115
  const [, forceUpdate] = (0, import_react16.useReducer)((x) => x + 1, 0);
2116
+ const [ready, setReady] = (0, import_react16.useState)(false);
2099
2117
  const appliedTheme = (0, import_react16.useMemo)(
2100
2118
  () => (0, import_deepmerge.default)(colorScheme === "dark" ? import_react_native_theming12.darkTheme : import_react_native_theming12.theme, params.theme ?? {}),
2101
2119
  [colorScheme]
2102
2120
  );
2103
2121
  (0, import_react16.useEffect)(() => {
2122
+ this.createPreparedStoryMapping().then(() => {
2123
+ this._ready = true;
2124
+ setReady(true);
2125
+ }).catch((e) => console.error(e));
2104
2126
  self._setStory = (newStory) => {
2105
2127
  setContext(newStory);
2106
- if (shouldPersistSelection) {
2107
- import_async_storage.default.setItem(STORAGE_KEY, newStory.id).catch((e) => {
2128
+ if (shouldPersistSelection && !storage) {
2129
+ console.warn(import_dedent.default`Please set storage in getStorybookUI like this:
2130
+ const StorybookUIRoot = view.getStorybookUI({
2131
+ storage: {
2132
+ getItem: AsyncStorage.getItem,
2133
+ setItem: AsyncStorage.setItem,
2134
+ },
2135
+ });
2136
+ `);
2137
+ }
2138
+ if (shouldPersistSelection && !!this._storage) {
2139
+ this._storage.setItem(STORAGE_KEY, newStory.id).catch((e) => {
2108
2140
  console.warn("storybook-log: error writing to async storage", e);
2109
2141
  });
2110
2142
  }
@@ -2115,6 +2147,19 @@ var View10 = class {
2115
2147
  self._preview.selectSpecifiedStory();
2116
2148
  });
2117
2149
  }, []);
2150
+ if (!ready) {
2151
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2152
+ import_react_native16.View,
2153
+ {
2154
+ style: {
2155
+ ...import_react_native16.StyleSheet.absoluteFillObject,
2156
+ alignItems: "center",
2157
+ justifyContent: "center"
2158
+ },
2159
+ children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_native16.ActivityIndicator, { animating: true, size: "large" })
2160
+ }
2161
+ );
2162
+ }
2118
2163
  if (onDeviceUI) {
2119
2164
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_native_safe_area_context3.SafeAreaProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_native_theming12.ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2120
2165
  OnDeviceUI_default,
@@ -1,11 +1,15 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { StoryContext } from '@storybook/csf';
3
3
  import { PreviewWithSelection } from '@storybook/preview-web';
4
- import { Theme } from '@storybook/react-native-theming';
5
- import { S as StoryIndex } from './index.d-cff8c6fa.js';
6
4
  import { ReactRenderer } from '@storybook/react';
5
+ import { Theme } from '@storybook/react-native-theming';
6
+ import { S as StoryIndex, P as PreparedStory } from './index.d-48fbc63a.js';
7
7
  import { Channel } from '@storybook/channels';
8
8
 
9
+ interface Storage {
10
+ getItem: (key: string) => Promise<string | null>;
11
+ setItem: (key: string, value: string) => Promise<void>;
12
+ }
9
13
  type StoryKind = string;
10
14
  type StoryName = string;
11
15
  type InitialSelection = `${StoryKind}--${StoryName}` | {
@@ -36,6 +40,7 @@ type Params = {
36
40
  shouldDisableKeyboardAvoidingView?: boolean;
37
41
  keyboardAvoidingViewVerticalOffset?: number;
38
42
  theme: DeepPartial<Theme>;
43
+ storage?: Storage;
39
44
  };
40
45
  declare class View {
41
46
  _storyIndex: StoryIndex;
@@ -45,13 +50,16 @@ declare class View {
45
50
  _preview: PreviewWithSelection<ReactRenderer>;
46
51
  _asyncStorageStoryId: string;
47
52
  _webUrl: string;
53
+ _storage: Storage;
48
54
  _channel: Channel;
55
+ _idToPrepared: Record<string, PreparedStory<ReactRenderer>>;
49
56
  constructor(preview: PreviewWithSelection<ReactRenderer>, channel: Channel);
50
57
  _getInitialStory: ({ initialSelection, shouldPersistSelection, }?: Partial<Params>) => Promise<{
51
58
  storySpecifier: string;
52
59
  viewMode: string;
53
60
  }>;
54
61
  _getServerChannel: (params?: Partial<Params>) => Channel;
62
+ createPreparedStoryMapping: () => Promise<void>;
55
63
  getStorybookUI: (params?: Partial<Params>) => () => react_jsx_runtime.JSX.Element;
56
64
  }
57
65
 
@@ -194,5 +194,16 @@ interface Addon_StoryApi<StoryFnReturnType = unknown> {
194
194
  [k: string]: string | Addon_ClientApiReturnFn<StoryFnReturnType>;
195
195
  }
196
196
  type Path = string;
197
+ type ModuleExport = any;
198
+ type PreparedStory<TRenderer extends Renderer = Renderer> = StoryContextForEnhancers<TRenderer> & {
199
+ moduleExport: ModuleExport;
200
+ originalStoryFn: StoryFn<TRenderer>;
201
+ undecoratedStoryFn: LegacyStoryFn<TRenderer>;
202
+ unboundStoryFn: LegacyStoryFn<TRenderer>;
203
+ applyLoaders: (context: StoryContextForLoaders<TRenderer>) => Promise<StoryContextForLoaders<TRenderer> & {
204
+ loaded: StoryContext<TRenderer>['loaded'];
205
+ }>;
206
+ playFunction?: (context: StoryContext<TRenderer>) => Promise<void> | void;
207
+ };
197
208
 
198
- export { Addon_StoryApi as A, LoaderFunction as L, NormalizedStoriesSpecifier as N, Renderer as R, StoryIndex as S, StoryContextForEnhancers as a, Args as b, StrictArgTypes as c };
209
+ export { Addon_StoryApi as A, LoaderFunction as L, NormalizedStoriesSpecifier as N, PreparedStory as P, Renderer as R, StoryIndex as S, StoryContextForEnhancers as a, Args as b, StrictArgTypes as c };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Theme, darkTheme, theme } from '@storybook/react-native-theming';
2
- import { V as View } from './View-0aedc31a.js';
3
- import { N as NormalizedStoriesSpecifier } from './index.d-cff8c6fa.js';
2
+ import { V as View } from './View-090d9c8b.js';
3
+ import { N as NormalizedStoriesSpecifier } from './index.d-48fbc63a.js';
4
4
  import 'react/jsx-runtime';
5
5
  import '@storybook/csf';
6
6
  import '@storybook/preview-web';
package/dist/index.js CHANGED
@@ -73,14 +73,21 @@ var import_preview_web = require("@storybook/preview-api/dist/preview-web");
73
73
  var import_channels2 = require("@storybook/channels");
74
74
 
75
75
  // src/View.tsx
76
- var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"));
77
76
  var import_csf = require("@storybook/csf");
78
- var import_preview_api2 = require("@storybook/preview-api");
79
77
  var import_manager_api2 = require("@storybook/manager-api");
78
+ var import_preview_api2 = require("@storybook/preview-api");
80
79
  var import_react_native_theming12 = require("@storybook/react-native-theming");
81
80
  var import_react16 = require("react");
82
81
  var import_react_native_safe_area_context3 = require("react-native-safe-area-context");
83
82
 
83
+ // src/components/OnDeviceUI/OnDeviceUI.tsx
84
+ var import_react_native_theming10 = require("@storybook/react-native-theming");
85
+ var import_react15 = __toESM(require("react"));
86
+ var import_react_native14 = require("react-native");
87
+
88
+ // src/constants.ts
89
+ var ANIMATION_DURATION_TRANSITION = 400;
90
+
84
91
  // src/hooks.tsx
85
92
  var import_react2 = __toESM(require("react"));
86
93
 
@@ -834,14 +841,6 @@ function useSelectedAddon(initialValue) {
834
841
  return result;
835
842
  }
836
843
 
837
- // src/components/OnDeviceUI/OnDeviceUI.tsx
838
- var import_react_native_theming10 = require("@storybook/react-native-theming");
839
- var import_react15 = __toESM(require("react"));
840
- var import_react_native14 = require("react-native");
841
-
842
- // src/constants.ts
843
- var ANIMATION_DURATION_TRANSITION = 400;
844
-
845
844
  // src/components/StoryListView/StoryListView.tsx
846
845
  var import_core_events = __toESM(require("@storybook/core-events"));
847
846
  var import_react_native_theming = require("@storybook/react-native-theming");
@@ -1945,6 +1944,7 @@ var OnDeviceUI_default = import_react15.default.memo(OnDeviceUI);
1945
1944
  // src/View.tsx
1946
1945
  var import_channels = require("@storybook/channels");
1947
1946
  var import_core_events2 = __toESM(require("@storybook/core-events"));
1947
+ var import_dedent = __toESM(require("dedent"));
1948
1948
  var import_deepmerge = __toESM(require("deepmerge"));
1949
1949
  var import_react_native16 = require("react-native");
1950
1950
 
@@ -2005,7 +2005,9 @@ var View10 = class {
2005
2005
  _preview;
2006
2006
  _asyncStorageStoryId;
2007
2007
  _webUrl;
2008
+ _storage;
2008
2009
  _channel;
2010
+ _idToPrepared = {};
2009
2011
  constructor(preview, channel) {
2010
2012
  this._preview = preview;
2011
2013
  this._channel = channel;
@@ -2027,8 +2029,8 @@ var View10 = class {
2027
2029
  if (shouldPersistSelection) {
2028
2030
  try {
2029
2031
  let value = this._asyncStorageStoryId;
2030
- if (!value) {
2031
- value = await import_async_storage.default.getItem(STORAGE_KEY);
2032
+ if (!value && this._storage != null) {
2033
+ value = await this._storage.getItem(STORAGE_KEY);
2032
2034
  this._asyncStorageStoryId = value;
2033
2035
  }
2034
2036
  const exists = value && Object.keys(this._storyIndex.entries).includes(value);
@@ -2054,11 +2056,24 @@ var View10 = class {
2054
2056
  }
2055
2057
  });
2056
2058
  };
2059
+ createPreparedStoryMapping = async () => {
2060
+ await Promise.all(
2061
+ Object.keys(this._storyIndex.entries).map(async (storyId) => {
2062
+ this._idToPrepared[storyId] = await this._preview.storyStore.loadStory({ storyId });
2063
+ })
2064
+ );
2065
+ console.log("Storybook: Finished building story index");
2066
+ };
2057
2067
  getStorybookUI = (params = {}) => {
2058
- const { shouldPersistSelection = true, onDeviceUI = true, enableWebsockets = false } = params;
2068
+ const {
2069
+ shouldPersistSelection = true,
2070
+ onDeviceUI = true,
2071
+ enableWebsockets = false,
2072
+ storage
2073
+ } = params;
2074
+ this._storage = storage;
2059
2075
  const initialStory = this._getInitialStory(params);
2060
2076
  if (enableWebsockets) {
2061
- console.log("websockets enabled");
2062
2077
  const channel = this._getServerChannel(params);
2063
2078
  import_manager_api2.addons.setChannel(channel);
2064
2079
  import_preview_api2.addons.setChannel(channel);
@@ -2070,13 +2085,15 @@ var View10 = class {
2070
2085
  }
2071
2086
  import_manager_api2.addons.loadAddons({
2072
2087
  store: () => ({
2073
- fromId: (id) => this._preview.storyStore.getStoryContext(this._preview.storyStore.fromId(id)),
2088
+ fromId: (id) => {
2089
+ if (!this._ready) {
2090
+ throw new Error("Storybook is not ready yet");
2091
+ }
2092
+ return this._preview.storyStore.getStoryContext(this._idToPrepared[id]);
2093
+ },
2074
2094
  getSelection: () => {
2075
2095
  return this._preview.currentSelection;
2076
2096
  },
2077
- // @ts-ignore :) FIXME
2078
- // _channel: this._preview.channel,
2079
- // global.__STORYBOOK_ADDONS_CHANNEL__,
2080
2097
  _channel: this._channel
2081
2098
  })
2082
2099
  });
@@ -2089,15 +2106,30 @@ var View10 = class {
2089
2106
  const setContext = useSetStoryContext();
2090
2107
  const colorScheme = (0, import_react_native16.useColorScheme)();
2091
2108
  const [, forceUpdate] = (0, import_react16.useReducer)((x) => x + 1, 0);
2109
+ const [ready, setReady] = (0, import_react16.useState)(false);
2092
2110
  const appliedTheme = (0, import_react16.useMemo)(
2093
2111
  () => (0, import_deepmerge.default)(colorScheme === "dark" ? import_react_native_theming12.darkTheme : import_react_native_theming12.theme, params.theme ?? {}),
2094
2112
  [colorScheme]
2095
2113
  );
2096
2114
  (0, import_react16.useEffect)(() => {
2115
+ this.createPreparedStoryMapping().then(() => {
2116
+ this._ready = true;
2117
+ setReady(true);
2118
+ }).catch((e) => console.error(e));
2097
2119
  self._setStory = (newStory) => {
2098
2120
  setContext(newStory);
2099
- if (shouldPersistSelection) {
2100
- import_async_storage.default.setItem(STORAGE_KEY, newStory.id).catch((e) => {
2121
+ if (shouldPersistSelection && !storage) {
2122
+ console.warn(import_dedent.default`Please set storage in getStorybookUI like this:
2123
+ const StorybookUIRoot = view.getStorybookUI({
2124
+ storage: {
2125
+ getItem: AsyncStorage.getItem,
2126
+ setItem: AsyncStorage.setItem,
2127
+ },
2128
+ });
2129
+ `);
2130
+ }
2131
+ if (shouldPersistSelection && !!this._storage) {
2132
+ this._storage.setItem(STORAGE_KEY, newStory.id).catch((e) => {
2101
2133
  console.warn("storybook-log: error writing to async storage", e);
2102
2134
  });
2103
2135
  }
@@ -2108,6 +2140,19 @@ var View10 = class {
2108
2140
  self._preview.selectSpecifiedStory();
2109
2141
  });
2110
2142
  }, []);
2143
+ if (!ready) {
2144
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2145
+ import_react_native16.View,
2146
+ {
2147
+ style: {
2148
+ ...import_react_native16.StyleSheet.absoluteFillObject,
2149
+ alignItems: "center",
2150
+ justifyContent: "center"
2151
+ },
2152
+ children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_native16.ActivityIndicator, { animating: true, size: "large" })
2153
+ }
2154
+ );
2155
+ }
2111
2156
  if (onDeviceUI) {
2112
2157
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_native_safe_area_context3.SafeAreaProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_native_theming12.ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2113
2158
  OnDeviceUI_default,
@@ -2135,8 +2180,8 @@ function prepareStories({
2135
2180
  entries: {}
2136
2181
  };
2137
2182
  let importMap = {};
2138
- const makeTitle = (fileName, userTitle) => {
2139
- const title = (0, import_preview_api3.userOrAutoTitle)(fileName, storyEntries, userTitle);
2183
+ const makeTitle = (fileName, specifier, userTitle) => {
2184
+ const title = (0, import_preview_api3.userOrAutoTitleFromSpecifier)(fileName, specifier, userTitle);
2140
2185
  if (title) {
2141
2186
  return title.replace("./", "");
2142
2187
  } else {
@@ -2151,7 +2196,8 @@ function prepareStories({
2151
2196
  throw new Error("Could not generate title");
2152
2197
  }
2153
2198
  };
2154
- storyEntries.forEach(({ req, directory: root }) => {
2199
+ storyEntries.forEach((specifier) => {
2200
+ const { req, directory: root } = specifier;
2155
2201
  req.keys().forEach((filename) => {
2156
2202
  try {
2157
2203
  const fileExports = req(filename);
@@ -2165,7 +2211,7 @@ function prepareStories({
2165
2211
  if (!exportValue)
2166
2212
  return;
2167
2213
  const name = (0, import_csf2.storyNameFromExport)(key);
2168
- const title = makeTitle(filename, meta.title);
2214
+ const title = makeTitle(filename, specifier, meta.title);
2169
2215
  if (title) {
2170
2216
  const id = (0, import_csf2.toId)(title, name);
2171
2217
  index.entries[id] = {
package/dist/preview.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _storybook_docs_tools from '@storybook/docs-tools';
2
- import { R as Renderer, a as StoryContextForEnhancers, b as Args, c as StrictArgTypes } from './index.d-cff8c6fa.js';
2
+ import { R as Renderer, a as StoryContextForEnhancers, b as Args, c as StrictArgTypes } from './index.d-48fbc63a.js';
3
3
 
4
4
  declare const _default: {
5
5
  argTypesEnhancers: (<TRenderer extends Renderer>(context: StoryContextForEnhancers<TRenderer, Args>) => StrictArgTypes<Args>)[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react-native",
3
- "version": "7.6.10-alpha.0",
3
+ "version": "7.6.10-alpha.3",
4
4
  "description": "A better way to develop React Native Components for your app",
5
5
  "keywords": [
6
6
  "react",
@@ -51,7 +51,6 @@
51
51
  "preset": "react-native"
52
52
  },
53
53
  "dependencies": {
54
- "@storybook/channel-websocket": "^7.6.10",
55
54
  "@storybook/channels": "^7.6.10",
56
55
  "@storybook/client-logger": "^7.6.10",
57
56
  "@storybook/core-client": "^7.6.10",
@@ -64,9 +63,10 @@
64
63
  "@storybook/preview-api": "^7.6.10",
65
64
  "@storybook/preview-web": "^7.6.10",
66
65
  "@storybook/react": "^7.6.10",
67
- "@storybook/react-native-theming": "^7.6.10-alpha.0",
66
+ "@storybook/react-native-theming": "^7.6.10-alpha.3",
68
67
  "chokidar": "^3.5.1",
69
68
  "commander": "^8.2.0",
69
+ "dedent": "^1.5.1",
70
70
  "deepmerge": "^4.3.0",
71
71
  "glob": "^7.1.7",
72
72
  "prettier": "^2.4.1",
@@ -87,7 +87,6 @@
87
87
  "typescript": "^5.3.3"
88
88
  },
89
89
  "peerDependencies": {
90
- "@react-native-async-storage/async-storage": ">=1",
91
90
  "react": "*",
92
91
  "react-native": ">=0.57.0",
93
92
  "react-native-safe-area-context": "*"
@@ -98,5 +97,5 @@
98
97
  "publishConfig": {
99
98
  "access": "public"
100
99
  },
101
- "gitHead": "d48243ffb345570962154e0bdf610e3699202bed"
100
+ "gitHead": "d0c275a9a09187b5f04e60c4d9170d7eae3a5437"
102
101
  }
package/readme.md CHANGED
@@ -256,6 +256,11 @@ You can pass these parameters to getStorybookUI call in your storybook entry poi
256
256
  -- Disable KeyboardAvoidingView wrapping Storybook's view
257
257
  keyboardAvoidingViewVerticalOffset: Number (0)
258
258
  -- With shouldDisableKeyboardAvoidingView=true, this will set the keyboardverticaloffset (https://facebook.github.io/react-native/docs/keyboardavoidingview#keyboardverticaloffset) value for KeyboardAvoidingView wrapping Storybook's view
259
+ storage: Object (undefined)
260
+ -- {getItem: (key: string) => Promise<string | null>;setItem: (key: string, value: string) => Promise<void>;}
261
+ -- Custom storage to be used instead of AsyncStorage
262
+ shouldPersistSelection: Boolean (true)
263
+ -- Stores last selected story in your devices storage.
259
264
  }
260
265
  ```
261
266
 
@@ -4,7 +4,7 @@ exports[`loader writeRequires when there are different file extensions writes th
4
4
  "
5
5
  /* do not change this file, it is auto generated by storybook. */
6
6
 
7
- import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native';
7
+ import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native/V6';
8
8
 
9
9
  global.STORIES = [{"titlePrefix":"","directory":"./scripts/mocks/file-extensions","files":"FakeStory.stories.tsx","importPathMatcher":"^\\\\.[\\\\\\\\/](?:scripts\\\\/mocks\\\\/file-extensions\\\\/FakeStory\\\\.stories\\\\.tsx)$"}]
10
10
 
@@ -48,7 +48,7 @@ exports[`loader writeRequires when there is a configuration object writes the st
48
48
  "
49
49
  /* do not change this file, it is auto generated by storybook. */
50
50
 
51
- import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native';
51
+ import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native/V6';
52
52
 
53
53
  global.STORIES = [{"titlePrefix":"ComponentsPrefix","files":"**/*.stories.tsx","directory":"./scripts/mocks/configuration-objects/components","importPathMatcher":"^\\\\.[\\\\\\\\/](?:scripts\\\\/mocks\\\\/configuration-objects\\\\/components(?:\\\\/(?!\\\\.)(?:(?:(?!(?:^|\\\\/)\\\\.).)*?)\\\\/|\\\\/|$)(?!\\\\.)(?=.)[^/]*?\\\\.stories\\\\.tsx)$"}]
54
54
 
@@ -92,7 +92,7 @@ exports[`loader writeRequires when there is a story glob and exclude paths globs
92
92
  "
93
93
  /* do not change this file, it is auto generated by storybook. */
94
94
 
95
- import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native';
95
+ import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native/V6';
96
96
 
97
97
  global.STORIES = [{"titlePrefix":"","directory":"./scripts/mocks/exclude-config-files","files":"**/*.stories.tsx","importPathMatcher":"^\\\\.[\\\\\\\\/](?:scripts\\\\/mocks\\\\/exclude-config-files(?:\\\\/(?!\\\\.)(?:(?:(?!(?:^|\\\\/)\\\\.).)*?)\\\\/|\\\\/|$)(?!\\\\.)(?=.)[^/]*?\\\\.stories\\\\.tsx)$"}]
98
98
 
@@ -136,7 +136,7 @@ exports[`loader writeRequires when there is a story glob writes the story import
136
136
  "
137
137
  /* do not change this file, it is auto generated by storybook. */
138
138
 
139
- import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native';
139
+ import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native/V6';
140
140
 
141
141
  global.STORIES = [{"titlePrefix":"","directory":"./scripts/mocks/all-config-files","files":"FakeStory.stories.tsx","importPathMatcher":"^\\\\.[\\\\\\\\/](?:scripts\\\\/mocks\\\\/all-config-files\\\\/FakeStory\\\\.stories\\\\.tsx)$"}]
142
142
 
@@ -180,7 +180,7 @@ exports[`loader writeRequires when there is no preview does not add preview rela
180
180
  "
181
181
  /* do not change this file, it is auto generated by storybook. */
182
182
 
183
- import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native';
183
+ import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native/V6';
184
184
 
185
185
  global.STORIES = [{"titlePrefix":"","directory":"./scripts/mocks/no-preview","files":"FakeStory.stories.tsx","importPathMatcher":"^\\\\.[\\\\\\\\/](?:scripts\\\\/mocks\\\\/no-preview\\\\/FakeStory\\\\.stories\\\\.tsx)$"}]
186
186
 
package/scripts/loader.js CHANGED
@@ -153,7 +153,7 @@ function writeRequires({ configPath, absolute = false, v6RequireContext = false
153
153
  const fileContent = `
154
154
  /* do not change this file, it is auto generated by storybook. */
155
155
 
156
- import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native';
156
+ import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native/V6';
157
157
 
158
158
  ${globalStories}
159
159
 
@@ -1 +1 @@
1
- export const FakeComponent = () => null;
1
+ export const FakeComponentExcluded = () => null;
@@ -1,6 +1,4 @@
1
- import type { StorybookConfig } from '@storybook/core-common';
2
-
3
- const config: StorybookConfig = {
1
+ const config = {
4
2
  stories: ['./FakeStory.stories.tsx'],
5
3
  addons: [
6
4
  '@storybook/addon-ondevice-notes',
@@ -0,0 +1,13 @@
1
+ import AsyncStorage from '@react-native-async-storage/async-storage';
2
+ import { view } from './storybook.requires';
3
+
4
+ import './storybook.requires';
5
+
6
+ const StorybookUIRoot = view.getStorybookUI({
7
+ storage: {
8
+ getItem: AsyncStorage.getItem,
9
+ setItem: AsyncStorage.setItem,
10
+ },
11
+ });
12
+
13
+ export default StorybookUIRoot;
@@ -0,0 +1,14 @@
1
+ import type { Preview } from '@storybook/react';
2
+
3
+ const preview: Preview = {
4
+ parameters: {
5
+ controls: {
6
+ matchers: {
7
+ color: /(background|color)$/i,
8
+ date: /Date$/,
9
+ },
10
+ },
11
+ },
12
+ };
13
+
14
+ export default preview;
@@ -1,8 +1,8 @@
1
- import React from 'react';
2
1
  import { View } from 'react-native';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
3
  import { MyButton } from './Button';
4
4
 
5
- const MyButtonMeta = {
5
+ const MyButtonMeta: Meta<typeof MyButton> = {
6
6
  title: 'MyButton',
7
7
  component: MyButton,
8
8
  argTypes: {
@@ -22,9 +22,9 @@ const MyButtonMeta = {
22
22
 
23
23
  export default MyButtonMeta;
24
24
 
25
- export const Basic = {};
25
+ export const Basic: StoryObj<typeof MyButton> = {};
26
26
 
27
- export const AnotherExample = {
27
+ export const AnotherExample: StoryObj<typeof MyButton> = {
28
28
  args: {
29
29
  text: 'Another example',
30
30
  },
@@ -1,7 +1,11 @@
1
- import React from 'react';
2
1
  import { TouchableOpacity, Text, StyleSheet } from 'react-native';
3
2
 
4
- export const MyButton = ({ onPress, text }) => {
3
+ export type MyButtonProps = {
4
+ onPress: () => void;
5
+ text: string;
6
+ };
7
+
8
+ export const MyButton = ({ onPress, text }: MyButtonProps) => {
5
9
  return (
6
10
  <TouchableOpacity style={styles.container} onPress={onPress} activeOpacity={0.8}>
7
11
  <Text style={styles.text}>{text}</Text>
@@ -0,0 +1,34 @@
1
+ /* do not change this file, it is auto generated by storybook. */
2
+
3
+ import { start } from '@storybook/react-native';
4
+
5
+ import '@storybook/addon-ondevice-controls/register';
6
+ import '@storybook/addon-ondevice-actions/register';
7
+
8
+ const normalizedStories = [
9
+ {
10
+ titlePrefix: '',
11
+ directory: './stories',
12
+ files: '**/*.stories.?(ts|tsx|js|jsx)',
13
+ importPathMatcher:
14
+ /^\.(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)(?!\.)(?=.)[^/]*?\.stories\.(?:ts|tsx|js|jsx)?)$/,
15
+ // @ts-ignore
16
+ req: require.context(
17
+ './stories',
18
+ true,
19
+ /^\.(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)(?!\.)(?=.)[^/]*?\.stories\.(?:ts|tsx|js|jsx)?)$/
20
+ ),
21
+ },
22
+ ];
23
+
24
+ // @ts-ignore
25
+ global.STORIES = normalizedStories;
26
+
27
+ export const view = start({
28
+ annotations: [
29
+ require('./preview'),
30
+ require('@storybook/react-native/dist/preview'),
31
+ require('@storybook/addon-actions/preview'),
32
+ ],
33
+ storyEntries: normalizedStories,
34
+ });
@@ -1,7 +0,0 @@
1
- import { getStorybookUI } from '@storybook/react-native';
2
-
3
- import './storybook.requires';
4
-
5
- const StorybookUIRoot = getStorybookUI({});
6
-
7
- export default StorybookUIRoot;
@@ -1,8 +0,0 @@
1
- export const parameters = {
2
- controls: {
3
- matchers: {
4
- color: /(background|color)$/i,
5
- date: /Date$/,
6
- },
7
- },
8
- };
@@ -1,54 +0,0 @@
1
- /* do not change this file, it is auto generated by storybook. */
2
-
3
- import {
4
- configure,
5
- addDecorator,
6
- addParameters,
7
- addArgsEnhancer,
8
- clearDecorators,
9
- } from '@storybook/react-native';
10
-
11
- global.STORIES = [
12
- {
13
- titlePrefix: '',
14
- directory: './.storybook/stories',
15
- files: '**/*.stories.?(ts|tsx|js|jsx)',
16
- importPathMatcher:
17
- '^\\.[\\\\/](?:\\.storybook\\/stories(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx|js|jsx)?)$',
18
- },
19
- ];
20
-
21
- import '@storybook/addon-ondevice-controls/register';
22
- import '@storybook/addon-ondevice-actions/register';
23
-
24
- import { argsEnhancers } from '@storybook/addon-actions/dist/modern/preset/addArgs';
25
-
26
- import { decorators, parameters } from './preview';
27
-
28
- if (decorators) {
29
- if (__DEV__) {
30
- // stops the warning from showing on every HMR
31
- require('react-native').LogBox.ignoreLogs([
32
- '`clearDecorators` is deprecated and will be removed in Storybook 7.0',
33
- ]);
34
- }
35
- // workaround for global decorators getting infinitely applied on HMR, see https://github.com/storybookjs/react-native/issues/185
36
- clearDecorators();
37
- decorators.forEach((decorator) => addDecorator(decorator));
38
- }
39
-
40
- if (parameters) {
41
- addParameters(parameters);
42
- }
43
-
44
- try {
45
- argsEnhancers.forEach((enhancer) => addArgsEnhancer(enhancer));
46
- } catch {}
47
-
48
- const getStories = () => {
49
- return {
50
- './.storybook/stories/Button/Button.stories.js': require('./stories/Button/Button.stories.js'),
51
- };
52
- };
53
-
54
- configure(getStories, module, false);