@storybook/react-native 8.3.10-alpha.2 → 8.4.0-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.
package/dist/index.js CHANGED
@@ -795,7 +795,7 @@ var StoryView = () => {
795
795
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
796
796
  import_react_native2.View,
797
797
  {
798
- style: { flex: 1, backgroundColor: theme3.background?.content },
798
+ style: { flex: 1, backgroundColor: theme3.background?.content, overflow: "hidden" },
799
799
  testID: id,
800
800
  onStartShouldSetResponder: dismissOnStartResponder,
801
801
  children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -1,50 +1,43 @@
1
- import type { InputConfigT } from 'metro-config';
1
+ import { MetroConfig } from 'metro-config';
2
2
 
3
3
  /**
4
4
  * Options for configuring WebSockets used for syncing storybook instances or sending events to storybook.
5
5
  */
6
6
  interface WebsocketsOptions {
7
- /**
8
- * The port WebSocket server will listen on. Defaults to 7007.
9
- */
10
- port?: number;
11
-
12
- /**
13
- * The host WebSocket server will bind to. Defaults to 'localhost'.
14
- */
15
- host?: string;
7
+ /**
8
+ * The port WebSocket server will listen on. Defaults to 7007.
9
+ */
10
+ port?: number;
11
+ /**
12
+ * The host WebSocket server will bind to. Defaults to 'localhost'.
13
+ */
14
+ host?: string;
16
15
  }
17
-
18
16
  /**
19
17
  * Options for configuring Storybook with React Native.
20
18
  */
21
19
  interface WithStorybookOptions {
22
- /**
23
- * The path to the Storybook config folder. Defaults to './.storybook'.
24
- */
25
- configPath?: string;
26
-
27
- /**
28
- * Whether Storybook is enabled. Defaults to true.
29
- */
30
- enabled?: boolean;
31
-
32
- /**
33
- * WebSocket configuration for syncing storybook instances or sending events to storybook.
34
- */
35
- websockets?: WebsocketsOptions;
36
-
37
- /**
38
- * Whether to use JavaScript files for Storybook configuration instead of TypeScript. Defaults to false.
39
- */
40
- useJs?: boolean;
41
-
42
- /**
43
- * If enabled is false and onDisabledRemoveStorybook is true, we will attempt to remove storybook from the js bundle.
44
- */
45
- onDisabledRemoveStorybook?: boolean;
20
+ /**
21
+ * The path to the Storybook config folder. Defaults to './.storybook'.
22
+ */
23
+ configPath?: string;
24
+ /**
25
+ * Whether Storybook is enabled. Defaults to true.
26
+ */
27
+ enabled?: boolean;
28
+ /**
29
+ * WebSocket configuration for syncing storybook instances or sending events to storybook.
30
+ */
31
+ websockets?: WebsocketsOptions;
32
+ /**
33
+ * Whether to use JavaScript files for Storybook configuration instead of TypeScript. Defaults to false.
34
+ */
35
+ useJs?: boolean;
36
+ /**
37
+ * If enabled is false and onDisabledRemoveStorybook is true, we will attempt to remove storybook from the js bundle.
38
+ */
39
+ onDisabledRemoveStorybook?: boolean;
46
40
  }
47
-
48
41
  /**
49
42
  * Configures Metro bundler to work with Storybook in React Native.
50
43
  * This function wraps a Metro configuration to enable Storybook usage.
@@ -69,4 +62,6 @@ interface WithStorybookOptions {
69
62
  * onDisabledRemoveStorybook: true,
70
63
  * });
71
64
  */
72
- export function withStorybook(config: InputConfigT, options?: WithStorybookOptions): InputConfigT;
65
+ declare function withStorybook(config: MetroConfig, options?: WithStorybookOptions): MetroConfig;
66
+
67
+ export { withStorybook as default };
@@ -0,0 +1,267 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // scripts/common.js
28
+ var require_common = __commonJS({
29
+ "scripts/common.js"(exports2, module2) {
30
+ var { globToRegexp, serverRequire } = require("@storybook/core/common");
31
+ var path2 = require("path");
32
+ var fs = require("fs");
33
+ var cwd = process.cwd();
34
+ var toRequireContext = (specifier) => {
35
+ const { directory, files } = specifier;
36
+ const match = globToRegexp(`./${files}`);
37
+ return {
38
+ path: directory,
39
+ recursive: files.includes("**") || files.split("/").length > 1,
40
+ match
41
+ };
42
+ };
43
+ function requireUncached(module3) {
44
+ delete require.cache[require.resolve(module3)];
45
+ return serverRequire(module3);
46
+ }
47
+ var supportedExtensions = ["js", "jsx", "ts", "tsx", "cjs", "mjs"];
48
+ function getFilePathExtension({ configPath }, fileName) {
49
+ for (const ext of supportedExtensions) {
50
+ const filePath = path2.resolve(cwd, configPath, `${fileName}.${ext}`);
51
+ if (fs.existsSync(filePath)) {
52
+ return ext;
53
+ }
54
+ }
55
+ return null;
56
+ }
57
+ function getMain({ configPath }) {
58
+ const fileExtension = getFilePathExtension({ configPath }, "main");
59
+ if (fileExtension === null) {
60
+ throw new Error("main config file not found");
61
+ }
62
+ const mainPath = path2.resolve(cwd, configPath, `main.${fileExtension}`);
63
+ return requireUncached(mainPath);
64
+ }
65
+ function ensureRelativePathHasDot(relativePath) {
66
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
67
+ }
68
+ function getPreviewExists({ configPath }) {
69
+ return !!getFilePathExtension({ configPath }, "preview");
70
+ }
71
+ module2.exports = {
72
+ toRequireContext,
73
+ requireUncached,
74
+ getFilePathExtension,
75
+ getMain,
76
+ ensureRelativePathHasDot,
77
+ getPreviewExists
78
+ };
79
+ }
80
+ });
81
+
82
+ // scripts/generate.js
83
+ var require_generate = __commonJS({
84
+ "scripts/generate.js"(exports2, module2) {
85
+ var {
86
+ toRequireContext,
87
+ ensureRelativePathHasDot,
88
+ getMain,
89
+ getPreviewExists
90
+ } = require_common();
91
+ var { normalizeStories, globToRegexp } = require("@storybook/core/common");
92
+ var fs = require("fs");
93
+ var prettier = require("prettier");
94
+ var path2 = require("path");
95
+ var cwd = process.cwd();
96
+ function generate2({ configPath, absolute = false, useJs = false }) {
97
+ const storybookRequiresLocation = path2.resolve(
98
+ cwd,
99
+ configPath,
100
+ `storybook.requires.${useJs ? "js" : "ts"}`
101
+ );
102
+ const mainImport = getMain({ configPath });
103
+ const main = mainImport.default ?? mainImport;
104
+ const storiesSpecifiers = normalizeStories(main.stories, {
105
+ configDir: configPath,
106
+ workingDir: cwd
107
+ });
108
+ const normalizedStories = storiesSpecifiers.map((specifier) => {
109
+ const reg = globToRegexp(`./${specifier.files}`);
110
+ const { path: p, recursive: r, match: m } = toRequireContext(specifier);
111
+ const pathToStory = ensureRelativePathHasDot(path2.posix.relative(configPath, p));
112
+ return `{
113
+ titlePrefix: "${specifier.titlePrefix}",
114
+ directory: "${specifier.directory}",
115
+ files: "${specifier.files}",
116
+ importPathMatcher: /${reg.source}/,
117
+ ${useJs ? "" : "// @ts-ignore"}
118
+ req: require.context('${pathToStory}', ${r}, ${m})
119
+ }`;
120
+ });
121
+ const registerAddons = main.addons?.map((addon) => `import "${addon}/register";`).join("\n");
122
+ const doctools = 'require("@storybook/react-native/preview")';
123
+ const enhancer = main.addons?.includes("@storybook/addon-ondevice-actions") ? "require('@storybook/addon-actions/preview')" : "";
124
+ let options = "";
125
+ let optionsVar = "";
126
+ const reactNativeOptions = main.reactNative;
127
+ if (reactNativeOptions && typeof reactNativeOptions === "object") {
128
+ optionsVar = `const options = ${JSON.stringify(reactNativeOptions)}`;
129
+ options = "options";
130
+ }
131
+ const previewExists = getPreviewExists({ configPath });
132
+ const annotations = `[${previewExists ? "require('./preview')," : ""}${doctools}, ${enhancer}]`;
133
+ const globalTypes = `
134
+ declare global {
135
+ var view: ReturnType<typeof start>;
136
+ var STORIES: typeof normalizedStories;
137
+ }
138
+ `;
139
+ const fileContent = `
140
+ /* do not change this file, it is auto generated by storybook. */
141
+
142
+ import { start, updateView } from '@storybook/react-native';
143
+
144
+ ${registerAddons}
145
+
146
+ const normalizedStories = [${normalizedStories.join(",")}];
147
+
148
+ ${useJs ? "" : globalTypes}
149
+
150
+ const annotations = ${annotations};
151
+
152
+ global.STORIES = normalizedStories;
153
+
154
+ ${useJs ? "" : "// @ts-ignore"}
155
+ module?.hot?.accept?.();
156
+
157
+ ${optionsVar}
158
+
159
+ if (!global.view) {
160
+ global.view = start({
161
+ annotations,
162
+ storyEntries: normalizedStories,
163
+ ${options}
164
+ });
165
+ } else {
166
+ updateView(global.view, annotations, normalizedStories, ${options});
167
+ }
168
+
169
+ export const view = global.view;
170
+ `;
171
+ const formattedFileContent = prettier.format(fileContent, { parser: "babel-ts" });
172
+ fs.writeFileSync(storybookRequiresLocation, formattedFileContent, {
173
+ encoding: "utf8",
174
+ flag: "w"
175
+ });
176
+ }
177
+ module2.exports = {
178
+ generate: generate2
179
+ };
180
+ }
181
+ });
182
+
183
+ // src/metro/withStorybook.ts
184
+ var path = __toESM(require("path"));
185
+ var import_generate = __toESM(require_generate());
186
+ var import_ws = require("ws");
187
+ function withStorybook(config, options = {
188
+ enabled: true,
189
+ useJs: false,
190
+ onDisabledRemoveStorybook: false
191
+ }) {
192
+ const {
193
+ configPath,
194
+ enabled = true,
195
+ websockets,
196
+ useJs = false,
197
+ onDisabledRemoveStorybook = false
198
+ } = options;
199
+ if (!enabled) {
200
+ if (onDisabledRemoveStorybook) {
201
+ return {
202
+ ...config,
203
+ resolver: {
204
+ ...config.resolver,
205
+ resolveRequest: (context, moduleName, platform) => {
206
+ const resolveFunction = config?.resolver?.resolveRequest ? config.resolver.resolveRequest : context.resolveRequest;
207
+ if (moduleName.startsWith("storybook") || moduleName.startsWith("@storybook")) {
208
+ return {
209
+ type: "empty"
210
+ };
211
+ }
212
+ return resolveFunction(context, moduleName, platform);
213
+ }
214
+ }
215
+ };
216
+ }
217
+ return config;
218
+ }
219
+ if (websockets) {
220
+ const port = websockets.port ?? 7007;
221
+ const host = websockets.host ?? "localhost";
222
+ const wss = new import_ws.WebSocketServer({ port, host });
223
+ wss.on("connection", function connection(ws) {
224
+ console.log("WebSocket connection established");
225
+ ws.on("error", console.error);
226
+ ws.on("message", function message(data) {
227
+ try {
228
+ const json = JSON.parse(data.toString());
229
+ wss.clients.forEach((wsClient) => wsClient.send(JSON.stringify(json)));
230
+ } catch (error) {
231
+ console.error(error);
232
+ }
233
+ });
234
+ });
235
+ }
236
+ (0, import_generate.generate)({
237
+ configPath: configPath ?? path.resolve(process.cwd(), "./.storybook"),
238
+ useJs
239
+ });
240
+ return {
241
+ ...config,
242
+ transformer: {
243
+ ...config.transformer,
244
+ unstable_allowRequireContext: true
245
+ },
246
+ resolver: {
247
+ ...config.resolver,
248
+ resolveRequest: (context, moduleName, platform) => {
249
+ const resolveFunction = config?.resolver?.resolveRequest ? config.resolver.resolveRequest : context.resolveRequest;
250
+ const isStorybookModule = moduleName.startsWith("storybook") || moduleName.startsWith("@storybook");
251
+ const theContext = isStorybookModule ? {
252
+ ...context,
253
+ unstable_enablePackageExports: true,
254
+ unstable_conditionNames: ["import"]
255
+ } : context;
256
+ const resolveResult = resolveFunction(theContext, moduleName, platform);
257
+ if (resolveResult?.filePath?.includes?.("@storybook/react/template/cli")) {
258
+ return {
259
+ type: "empty"
260
+ };
261
+ }
262
+ return resolveResult;
263
+ }
264
+ }
265
+ };
266
+ }
267
+ module.exports = withStorybook;
@@ -1,106 +1 @@
1
- const path = require('path');
2
-
3
- const { generate } = require('../scripts/generate');
4
- const { WebSocketServer } = require('ws');
5
-
6
- module.exports = (
7
- config,
8
- { configPath, enabled = true, websockets, useJs = false, onDisabledRemoveStorybook = false } = {
9
- enabled: true,
10
- useJs: false,
11
- onDisabledRemoveStorybook: false,
12
- }
13
- ) => {
14
- if (!enabled) {
15
- if (onDisabledRemoveStorybook) {
16
- return {
17
- ...config,
18
- resolver: {
19
- ...config.resolver,
20
- resolveRequest: (context, moduleName, platform) => {
21
- const resolveFunction = config?.resolver?.resolveRequest
22
- ? config?.resolver?.resolveRequest
23
- : context.resolveRequest;
24
-
25
- if (moduleName.startsWith('storybook') || moduleName.startsWith('@storybook')) {
26
- return {
27
- type: 'empty',
28
- };
29
- }
30
-
31
- return resolveFunction(context, moduleName, platform);
32
- },
33
- },
34
- };
35
- }
36
-
37
- return config;
38
- }
39
-
40
- if (websockets) {
41
- const port = websockets.port ?? 7007;
42
-
43
- const host = websockets.host ?? 'localhost';
44
-
45
- const wss = new WebSocketServer({ port, host });
46
-
47
- wss.on('connection', function connection(ws) {
48
- console.log('websocket connection established');
49
-
50
- ws.on('error', console.error);
51
-
52
- ws.on('message', function message(data) {
53
- try {
54
- const json = JSON.parse(data.toString());
55
-
56
- wss.clients.forEach((wsClient) => wsClient.send(JSON.stringify(json)));
57
- } catch (error) {
58
- console.error(error);
59
- }
60
- });
61
- });
62
- }
63
-
64
- generate({
65
- configPath: configPath ?? path.resolve(process.cwd(), './.storybook'),
66
- useJs,
67
- });
68
-
69
- return {
70
- ...config,
71
- transformer: {
72
- ...config.transformer,
73
- unstable_allowRequireContext: true,
74
- },
75
- resolver: {
76
- ...config.resolver,
77
- resolveRequest: (context, moduleName, platform) => {
78
- const resolveFunction = config?.resolver?.resolveRequest
79
- ? config?.resolver?.resolveRequest
80
- : context.resolveRequest;
81
-
82
- const isStorybookModule =
83
- moduleName.startsWith('storybook') || moduleName.startsWith('@storybook');
84
-
85
- const theContext = isStorybookModule
86
- ? {
87
- ...context,
88
- unstable_enablePackageExports: true,
89
- unstable_conditionNames: ['import'],
90
- }
91
- : context;
92
-
93
- const resolveResult = resolveFunction(theContext, moduleName, platform);
94
-
95
- // workaround for template files with invalid imports
96
- if (resolveResult?.filePath?.includes?.('@storybook/react/template/cli')) {
97
- return {
98
- type: 'empty',
99
- };
100
- }
101
-
102
- return resolveResult;
103
- },
104
- },
105
- };
106
- };
1
+ module.exports = require('../dist/metro/withStorybook.js');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react-native",
3
- "version": "8.3.10-alpha.2",
3
+ "version": "8.4.0-alpha.0",
4
4
  "description": "A better way to develop React Native Components for your app",
5
5
  "keywords": [
6
6
  "react",
@@ -22,6 +22,11 @@
22
22
  "sb-rn-get-stories": "./bin/get-stories.js",
23
23
  "sb-rn-watcher": "./bin/watcher.js"
24
24
  },
25
+ "exports": {
26
+ ".": "./dist/index.js",
27
+ "./metro/withStorybook": "./dist/metro/withStorybook.js",
28
+ "./preview": "./dist/preview.js"
29
+ },
25
30
  "files": [
26
31
  "bin/**/*",
27
32
  "dist/**/*",
@@ -29,22 +34,22 @@
29
34
  "*.js",
30
35
  "*.d.ts",
31
36
  "scripts/*",
32
- "metro/*",
33
- "template/**/*"
37
+ "template/**/*",
38
+ "metro/**/*"
34
39
  ],
35
40
  "scripts": {
36
- "dev": "npx tsx buildscripts/gendtsdev.ts && tsup --watch",
41
+ "dev": "npx --yes tsx buildscripts/gendtsdev.ts && tsup --watch",
37
42
  "prepare": "rm -rf dist/ && tsup",
38
43
  "test": "jest",
39
44
  "test:ci": "jest"
40
45
  },
41
46
  "dependencies": {
42
- "@storybook/core": "^8.3.5",
47
+ "@storybook/core": "^8.4.0-beta.0",
43
48
  "@storybook/csf": "^0.1.1",
44
49
  "@storybook/global": "^5.0.0",
45
- "@storybook/react": "^8.3.5",
46
- "@storybook/react-native-theming": "^8.3.10-alpha.2",
47
- "@storybook/react-native-ui": "^8.3.10-alpha.2",
50
+ "@storybook/react": "^8.4.0-beta.0",
51
+ "@storybook/react-native-theming": "^8.4.0-alpha.0",
52
+ "@storybook/react-native-ui": "^8.4.0-alpha.0",
48
53
  "chokidar": "^3.5.1",
49
54
  "commander": "^8.2.0",
50
55
  "dedent": "^1.5.1",
@@ -54,14 +59,14 @@
54
59
  "react-native-swipe-gestures": "^1.0.5",
55
60
  "react-native-url-polyfill": "^2.0.0",
56
61
  "setimmediate": "^1.0.5",
57
- "storybook": "^8.3.5",
62
+ "storybook": "^8.4.0-beta.0",
58
63
  "type-fest": "~2.19",
59
64
  "util": "^0.12.4",
60
65
  "ws": "^8.18.0"
61
66
  },
62
67
  "devDependencies": {
63
68
  "@types/jest": "^29.4.3",
64
- "@types/react": "~18.2.79",
69
+ "@types/react": "~18.3.12",
65
70
  "babel-jest": "^29.4.3",
66
71
  "jest": "29.7.0",
67
72
  "jotai": "^2.6.2",
@@ -82,5 +87,5 @@
82
87
  "publishConfig": {
83
88
  "access": "public"
84
89
  },
85
- "gitHead": "2567b9a4d11a77d9b5bf74dd699ad49fb47afa5b"
90
+ "gitHead": "11531d9d55c0c933feb61d507595da80becb0b4a"
86
91
  }
package/preview.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/preview.js');
@@ -27,7 +27,7 @@ import "@storybook/addon-ondevice-actions/register";
27
27
  }
28
28
 
29
29
 
30
- const annotations = [require('./preview'),require("@storybook/react-native/dist/preview"), require('@storybook/addon-actions/preview')];
30
+ const annotations = [require('./preview'),require("@storybook/react-native/preview"), require('@storybook/addon-actions/preview')];
31
31
 
32
32
  global.STORIES = normalizedStories;
33
33
 
@@ -77,7 +77,7 @@ import "@storybook/addon-ondevice-actions/register";
77
77
  }
78
78
 
79
79
 
80
- const annotations = [require('./preview'),require("@storybook/react-native/dist/preview"), require('@storybook/addon-actions/preview')];
80
+ const annotations = [require('./preview'),require("@storybook/react-native/preview"), require('@storybook/addon-actions/preview')];
81
81
 
82
82
  global.STORIES = normalizedStories;
83
83
 
@@ -127,7 +127,7 @@ import "@storybook/addon-ondevice-actions/register";
127
127
  }
128
128
 
129
129
 
130
- const annotations = [require('./preview'),require("@storybook/react-native/dist/preview"), require('@storybook/addon-actions/preview')];
130
+ const annotations = [require('./preview'),require("@storybook/react-native/preview"), require('@storybook/addon-actions/preview')];
131
131
 
132
132
  global.STORIES = normalizedStories;
133
133
 
@@ -177,7 +177,7 @@ import "@storybook/addon-ondevice-actions/register";
177
177
  }
178
178
 
179
179
 
180
- const annotations = [require("@storybook/react-native/dist/preview"), require('@storybook/addon-actions/preview')];
180
+ const annotations = [require("@storybook/react-native/preview"), require('@storybook/addon-actions/preview')];
181
181
 
182
182
  global.STORIES = normalizedStories;
183
183
 
@@ -222,7 +222,7 @@ import "@storybook/addon-ondevice-actions/register";
222
222
 
223
223
 
224
224
 
225
- const annotations = [require('./preview'),require("@storybook/react-native/dist/preview"), require('@storybook/addon-actions/preview')];
225
+ const annotations = [require('./preview'),require("@storybook/react-native/preview"), require('@storybook/addon-actions/preview')];
226
226
 
227
227
  global.STORIES = normalizedStories;
228
228
 
@@ -48,7 +48,7 @@ function generate({ configPath, absolute = false, useJs = false }) {
48
48
 
49
49
  const registerAddons = main.addons?.map((addon) => `import "${addon}/register";`).join('\n');
50
50
 
51
- const doctools = 'require("@storybook/react-native/dist/preview")';
51
+ const doctools = 'require("@storybook/react-native/preview")';
52
52
 
53
53
  // TODO: implement presets or something similar
54
54
  const enhancer = main.addons?.includes('@storybook/addon-ondevice-actions')