@storybook/react-native 7.6.10-alpha.1 → 7.6.10-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
+ import { N as NormalizedStoriesSpecifier, S as StorybookConfig$1 } from './index.d-da6c1de4.js';
1
2
  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';
3
+ import { V as View } from './View-bd441663.js';
4
+ import 'file-system-cache';
5
+ import '@babel/core';
6
+ import 'http';
4
7
  import 'react/jsx-runtime';
5
8
  import '@storybook/csf';
6
9
  import '@storybook/preview-web';
@@ -14,4 +17,9 @@ declare function start({ annotations, storyEntries, }: {
14
17
  annotations: any[];
15
18
  }): View;
16
19
 
17
- export { start };
20
+ interface StorybookConfig {
21
+ stories: StorybookConfig$1['stories'];
22
+ addons: string[];
23
+ }
24
+
25
+ export { StorybookConfig, start };
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,8 @@
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, b as StoryContextForEnhancers, c as Args, d as StrictArgTypes } from './index.d-da6c1de4.js';
3
+ import 'file-system-cache';
4
+ import '@babel/core';
5
+ import 'http';
3
6
 
4
7
  declare const _default: {
5
8
  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.4",
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.4",
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": "43c2b5b932a0361178b010f90533069f14007677"
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/common.js CHANGED
@@ -1,4 +1,4 @@
1
- const { globToRegexp } = require('@storybook/core-common');
1
+ const { globToRegexp, serverRequire } = require('@storybook/core-common');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
 
@@ -21,7 +21,7 @@ const toRequireContext = (specifier) => {
21
21
  function requireUncached(module) {
22
22
  delete require.cache[require.resolve(module)];
23
23
 
24
- return require(module);
24
+ return serverRequire(module);
25
25
  }
26
26
 
27
27
  const supportedExtensions = ['js', 'jsx', 'ts', 'tsx', 'cjs', 'mjs'];
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,8 +1,6 @@
1
1
  import AsyncStorage from '@react-native-async-storage/async-storage';
2
2
  import { view } from './storybook.requires';
3
3
 
4
- import './storybook.requires';
5
-
6
4
  const StorybookUIRoot = view.getStorybookUI({
7
5
  storage: {
8
6
  getItem: AsyncStorage.getItem,
@@ -1,4 +1,8 @@
1
- module.exports = {
1
+ import { StorybookConfig } from '@storybook/react-native';
2
+
3
+ const main: StorybookConfig = {
2
4
  stories: ['./stories/**/*.stories.?(ts|tsx|js|jsx)'],
3
5
  addons: ['@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-actions'],
4
6
  };
7
+
8
+ export default main;
@@ -1,198 +0,0 @@
1
- declare global {
2
- interface SymbolConstructor {
3
- readonly observable: symbol;
4
- }
5
- }
6
-
7
- interface SBBaseType {
8
- required?: boolean;
9
- raw?: string;
10
- }
11
- type SBScalarType = SBBaseType & {
12
- name: 'boolean' | 'string' | 'number' | 'function' | 'symbol';
13
- };
14
- type SBArrayType = SBBaseType & {
15
- name: 'array';
16
- value: SBType;
17
- };
18
- type SBObjectType = SBBaseType & {
19
- name: 'object';
20
- value: Record<string, SBType>;
21
- };
22
- type SBEnumType = SBBaseType & {
23
- name: 'enum';
24
- value: (string | number)[];
25
- };
26
- type SBIntersectionType = SBBaseType & {
27
- name: 'intersection';
28
- value: SBType[];
29
- };
30
- type SBUnionType = SBBaseType & {
31
- name: 'union';
32
- value: SBType[];
33
- };
34
- type SBOtherType = SBBaseType & {
35
- name: 'other';
36
- value: string;
37
- };
38
- type SBType = SBScalarType | SBEnumType | SBArrayType | SBObjectType | SBIntersectionType | SBUnionType | SBOtherType;
39
-
40
- type StoryId = string;
41
- type ComponentId = string;
42
- type ComponentTitle = string;
43
- type StoryName = string;
44
- /** @deprecated */
45
- type StoryKind = ComponentTitle;
46
- type Tag = string;
47
- interface StoryIdentifier {
48
- componentId: ComponentId;
49
- title: ComponentTitle;
50
- /** @deprecated */
51
- kind: ComponentTitle;
52
- id: StoryId;
53
- name: StoryName;
54
- /** @deprecated */
55
- story: StoryName;
56
- tags: Tag[];
57
- }
58
- interface Parameters {
59
- [name: string]: any;
60
- }
61
- type ConditionalTest = {
62
- truthy?: boolean;
63
- } | {
64
- exists: boolean;
65
- } | {
66
- eq: any;
67
- } | {
68
- neq: any;
69
- };
70
- type ConditionalValue = {
71
- arg: string;
72
- } | {
73
- global: string;
74
- };
75
- type Conditional = ConditionalValue & ConditionalTest;
76
- interface InputType {
77
- name?: string;
78
- description?: string;
79
- defaultValue?: any;
80
- type?: SBType | SBScalarType['name'];
81
- if?: Conditional;
82
- [key: string]: any;
83
- }
84
- interface StrictInputType extends InputType {
85
- name: string;
86
- type?: SBType;
87
- }
88
- interface Args {
89
- [name: string]: any;
90
- }
91
- type StrictArgTypes<TArgs = Args> = {
92
- [name in keyof TArgs]: StrictInputType;
93
- };
94
- interface Globals {
95
- [name: string]: any;
96
- }
97
- type Renderer = {
98
- /** What is the type of the `component` annotation in this renderer? */
99
- component: unknown;
100
- /** What does the story function return in this renderer? */
101
- storyResult: unknown;
102
- /** What type of element does this renderer render to? */
103
- canvasElement: unknown;
104
- T?: unknown;
105
- };
106
- interface StoryContextForEnhancers<TRenderer extends Renderer = Renderer, TArgs = Args> extends StoryIdentifier {
107
- component?: (TRenderer & {
108
- T: any;
109
- })['component'];
110
- subcomponents?: Record<string, (TRenderer & {
111
- T: any;
112
- })['component']>;
113
- parameters: Parameters;
114
- initialArgs: TArgs;
115
- argTypes: StrictArgTypes<TArgs>;
116
- }
117
- interface StoryContextUpdate<TArgs = Args> {
118
- args?: TArgs;
119
- globals?: Globals;
120
- [key: string]: any;
121
- }
122
- type ViewMode$1 = 'story' | 'docs';
123
- interface StoryContextForLoaders<TRenderer extends Renderer = Renderer, TArgs = Args> extends StoryContextForEnhancers<TRenderer, TArgs>, Required<StoryContextUpdate<TArgs>> {
124
- hooks: unknown;
125
- viewMode: ViewMode$1;
126
- originalStoryFn: StoryFn<TRenderer>;
127
- }
128
- type LoaderFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContextForLoaders<TRenderer, TArgs>) => Promise<Record<string, any> | void> | Record<string, any> | void;
129
- interface StoryContext<TRenderer extends Renderer = Renderer, TArgs = Args> extends StoryContextForLoaders<TRenderer, TArgs> {
130
- loaded: Record<string, any>;
131
- abortSignal: AbortSignal;
132
- canvasElement: TRenderer['canvasElement'];
133
- }
134
- type PartialStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (update?: StoryContextUpdate<Partial<TArgs>>) => TRenderer['storyResult'];
135
- type LegacyStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContext<TRenderer, TArgs>) => TRenderer['storyResult'];
136
- type ArgsStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (args: TArgs, context: StoryContext<TRenderer, TArgs>) => (TRenderer & {
137
- T: TArgs;
138
- })['storyResult'];
139
- type StoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = LegacyStoryFn<TRenderer, TArgs> | ArgsStoryFn<TRenderer, TArgs>;
140
- type DecoratorFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (fn: PartialStoryFn<TRenderer, TArgs>, c: StoryContext<TRenderer, TArgs>) => TRenderer['storyResult'];
141
- interface StoriesSpecifier {
142
- /**
143
- * When auto-titling, what to prefix all generated titles with (default: '')
144
- */
145
- titlePrefix?: string;
146
- /**
147
- * Where to start looking for story files
148
- */
149
- directory: string;
150
- /**
151
- * What does the filename of a story file look like?
152
- * (a glob, relative to directory, no leading `./`)
153
- * If unset, we use `** / *.@(mdx|stories.@(mdx|js|jsx|mjs|ts|tsx))` (no spaces)
154
- */
155
- files?: string;
156
- }
157
- type NormalizedStoriesSpecifier = Required<StoriesSpecifier> & {
158
- importPathMatcher: RegExp;
159
- };
160
- interface BaseIndexEntry {
161
- id: StoryId;
162
- name: StoryName;
163
- title: ComponentTitle;
164
- tags?: Tag[];
165
- importPath: Path;
166
- }
167
- type StoryIndexEntry = BaseIndexEntry & {
168
- type: 'story';
169
- };
170
- type DocsIndexEntry = BaseIndexEntry & {
171
- storiesImports: Path[];
172
- type: 'docs';
173
- };
174
- type IndexEntry = StoryIndexEntry | DocsIndexEntry;
175
- interface StoryIndex {
176
- v: number;
177
- entries: Record<StoryId, IndexEntry>;
178
- }
179
- type Addon_ReturnTypeFramework<ReturnType> = {
180
- component: any;
181
- storyResult: ReturnType;
182
- canvasElement: any;
183
- };
184
- type Addon_StoryFn<ReturnType = unknown> = StoryFn<Addon_ReturnTypeFramework<ReturnType>>;
185
- type Addon_DecoratorFunction<StoryFnReturnType = unknown> = DecoratorFunction<Addon_ReturnTypeFramework<StoryFnReturnType>>;
186
- type Addon_LoaderFunction = LoaderFunction<Addon_ReturnTypeFramework<unknown>>;
187
- type Addon_ClientApiReturnFn<StoryFnReturnType = unknown> = (...args: any[]) => Addon_StoryApi<StoryFnReturnType>;
188
- interface Addon_StoryApi<StoryFnReturnType = unknown> {
189
- kind: StoryKind;
190
- add: (storyName: StoryName, storyFn: Addon_StoryFn<StoryFnReturnType>, parameters?: Parameters) => Addon_StoryApi<StoryFnReturnType>;
191
- addDecorator: (decorator: Addon_DecoratorFunction<StoryFnReturnType>) => Addon_StoryApi<StoryFnReturnType>;
192
- addLoader: (decorator: Addon_LoaderFunction) => Addon_StoryApi<StoryFnReturnType>;
193
- addParameters: (parameters: Parameters) => Addon_StoryApi<StoryFnReturnType>;
194
- [k: string]: string | Addon_ClientApiReturnFn<StoryFnReturnType>;
195
- }
196
- type Path = string;
197
-
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 };