@storybook/react-native 7.6.10-alpha.1 → 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-3a0f8584.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
@@ -2014,6 +2014,7 @@ var View10 = class {
2014
2014
  _webUrl;
2015
2015
  _storage;
2016
2016
  _channel;
2017
+ _idToPrepared = {};
2017
2018
  constructor(preview, channel) {
2018
2019
  this._preview = preview;
2019
2020
  this._channel = channel;
@@ -2062,6 +2063,14 @@ var View10 = class {
2062
2063
  }
2063
2064
  });
2064
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
+ };
2065
2074
  getStorybookUI = (params = {}) => {
2066
2075
  const {
2067
2076
  shouldPersistSelection = true,
@@ -2072,7 +2081,6 @@ var View10 = class {
2072
2081
  this._storage = storage;
2073
2082
  const initialStory = this._getInitialStory(params);
2074
2083
  if (enableWebsockets) {
2075
- console.log("websockets enabled");
2076
2084
  const channel = this._getServerChannel(params);
2077
2085
  import_manager_api2.addons.setChannel(channel);
2078
2086
  import_preview_api2.addons.setChannel(channel);
@@ -2084,13 +2092,15 @@ var View10 = class {
2084
2092
  }
2085
2093
  import_manager_api2.addons.loadAddons({
2086
2094
  store: () => ({
2087
- 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
+ },
2088
2101
  getSelection: () => {
2089
2102
  return this._preview.currentSelection;
2090
2103
  },
2091
- // @ts-ignore :) FIXME
2092
- // _channel: this._preview.channel,
2093
- // global.__STORYBOOK_ADDONS_CHANNEL__,
2094
2104
  _channel: this._channel
2095
2105
  })
2096
2106
  });
@@ -2103,11 +2113,16 @@ var View10 = class {
2103
2113
  const setContext = useSetStoryContext();
2104
2114
  const colorScheme = (0, import_react_native16.useColorScheme)();
2105
2115
  const [, forceUpdate] = (0, import_react16.useReducer)((x) => x + 1, 0);
2116
+ const [ready, setReady] = (0, import_react16.useState)(false);
2106
2117
  const appliedTheme = (0, import_react16.useMemo)(
2107
2118
  () => (0, import_deepmerge.default)(colorScheme === "dark" ? import_react_native_theming12.darkTheme : import_react_native_theming12.theme, params.theme ?? {}),
2108
2119
  [colorScheme]
2109
2120
  );
2110
2121
  (0, import_react16.useEffect)(() => {
2122
+ this.createPreparedStoryMapping().then(() => {
2123
+ this._ready = true;
2124
+ setReady(true);
2125
+ }).catch((e) => console.error(e));
2111
2126
  self._setStory = (newStory) => {
2112
2127
  setContext(newStory);
2113
2128
  if (shouldPersistSelection && !storage) {
@@ -2132,6 +2147,19 @@ var View10 = class {
2132
2147
  self._preview.selectSpecifiedStory();
2133
2148
  });
2134
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
+ }
2135
2163
  if (onDeviceUI) {
2136
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)(
2137
2165
  OnDeviceUI_default,
@@ -3,7 +3,7 @@ import { StoryContext } from '@storybook/csf';
3
3
  import { PreviewWithSelection } from '@storybook/preview-web';
4
4
  import { ReactRenderer } from '@storybook/react';
5
5
  import { Theme } from '@storybook/react-native-theming';
6
- import { S as StoryIndex } from './index.d-cff8c6fa.js';
6
+ import { S as StoryIndex, P as PreparedStory } from './index.d-48fbc63a.js';
7
7
  import { Channel } from '@storybook/channels';
8
8
 
9
9
  interface Storage {
@@ -52,12 +52,14 @@ declare class View {
52
52
  _webUrl: string;
53
53
  _storage: Storage;
54
54
  _channel: Channel;
55
+ _idToPrepared: Record<string, PreparedStory<ReactRenderer>>;
55
56
  constructor(preview: PreviewWithSelection<ReactRenderer>, channel: Channel);
56
57
  _getInitialStory: ({ initialSelection, shouldPersistSelection, }?: Partial<Params>) => Promise<{
57
58
  storySpecifier: string;
58
59
  viewMode: string;
59
60
  }>;
60
61
  _getServerChannel: (params?: Partial<Params>) => Channel;
62
+ createPreparedStoryMapping: () => Promise<void>;
61
63
  getStorybookUI: (params?: Partial<Params>) => () => react_jsx_runtime.JSX.Element;
62
64
  }
63
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-3a0f8584.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
@@ -2007,6 +2007,7 @@ var View10 = class {
2007
2007
  _webUrl;
2008
2008
  _storage;
2009
2009
  _channel;
2010
+ _idToPrepared = {};
2010
2011
  constructor(preview, channel) {
2011
2012
  this._preview = preview;
2012
2013
  this._channel = channel;
@@ -2055,6 +2056,14 @@ var View10 = class {
2055
2056
  }
2056
2057
  });
2057
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
+ };
2058
2067
  getStorybookUI = (params = {}) => {
2059
2068
  const {
2060
2069
  shouldPersistSelection = true,
@@ -2065,7 +2074,6 @@ var View10 = class {
2065
2074
  this._storage = storage;
2066
2075
  const initialStory = this._getInitialStory(params);
2067
2076
  if (enableWebsockets) {
2068
- console.log("websockets enabled");
2069
2077
  const channel = this._getServerChannel(params);
2070
2078
  import_manager_api2.addons.setChannel(channel);
2071
2079
  import_preview_api2.addons.setChannel(channel);
@@ -2077,13 +2085,15 @@ var View10 = class {
2077
2085
  }
2078
2086
  import_manager_api2.addons.loadAddons({
2079
2087
  store: () => ({
2080
- 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
+ },
2081
2094
  getSelection: () => {
2082
2095
  return this._preview.currentSelection;
2083
2096
  },
2084
- // @ts-ignore :) FIXME
2085
- // _channel: this._preview.channel,
2086
- // global.__STORYBOOK_ADDONS_CHANNEL__,
2087
2097
  _channel: this._channel
2088
2098
  })
2089
2099
  });
@@ -2096,11 +2106,16 @@ var View10 = class {
2096
2106
  const setContext = useSetStoryContext();
2097
2107
  const colorScheme = (0, import_react_native16.useColorScheme)();
2098
2108
  const [, forceUpdate] = (0, import_react16.useReducer)((x) => x + 1, 0);
2109
+ const [ready, setReady] = (0, import_react16.useState)(false);
2099
2110
  const appliedTheme = (0, import_react16.useMemo)(
2100
2111
  () => (0, import_deepmerge.default)(colorScheme === "dark" ? import_react_native_theming12.darkTheme : import_react_native_theming12.theme, params.theme ?? {}),
2101
2112
  [colorScheme]
2102
2113
  );
2103
2114
  (0, import_react16.useEffect)(() => {
2115
+ this.createPreparedStoryMapping().then(() => {
2116
+ this._ready = true;
2117
+ setReady(true);
2118
+ }).catch((e) => console.error(e));
2104
2119
  self._setStory = (newStory) => {
2105
2120
  setContext(newStory);
2106
2121
  if (shouldPersistSelection && !storage) {
@@ -2125,6 +2140,19 @@ var View10 = class {
2125
2140
  self._preview.selectSpecifiedStory();
2126
2141
  });
2127
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
+ }
2128
2156
  if (onDeviceUI) {
2129
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)(
2130
2158
  OnDeviceUI_default,
@@ -2152,8 +2180,8 @@ function prepareStories({
2152
2180
  entries: {}
2153
2181
  };
2154
2182
  let importMap = {};
2155
- const makeTitle = (fileName, userTitle) => {
2156
- 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);
2157
2185
  if (title) {
2158
2186
  return title.replace("./", "");
2159
2187
  } else {
@@ -2168,7 +2196,8 @@ function prepareStories({
2168
2196
  throw new Error("Could not generate title");
2169
2197
  }
2170
2198
  };
2171
- storyEntries.forEach(({ req, directory: root }) => {
2199
+ storyEntries.forEach((specifier) => {
2200
+ const { req, directory: root } = specifier;
2172
2201
  req.keys().forEach((filename) => {
2173
2202
  try {
2174
2203
  const fileExports = req(filename);
@@ -2182,7 +2211,7 @@ function prepareStories({
2182
2211
  if (!exportValue)
2183
2212
  return;
2184
2213
  const name = (0, import_csf2.storyNameFromExport)(key);
2185
- const title = makeTitle(filename, meta.title);
2214
+ const title = makeTitle(filename, specifier, meta.title);
2186
2215
  if (title) {
2187
2216
  const id = (0, import_csf2.toId)(title, name);
2188
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.1",
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,7 +63,7 @@
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.1",
66
+ "@storybook/react-native-theming": "^7.6.10-alpha.3",
68
67
  "chokidar": "^3.5.1",
69
68
  "commander": "^8.2.0",
70
69
  "dedent": "^1.5.1",
@@ -98,5 +97,5 @@
98
97
  "publishConfig": {
99
98
  "access": "public"
100
99
  },
101
- "gitHead": "8b2e96767cc361ae5382c5ba0ba9d6ea6112634f"
100
+ "gitHead": "d0c275a9a09187b5f04e60c4d9170d7eae3a5437"
102
101
  }
@@ -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