@storybook/react-native 7.6.17 → 7.6.19
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 +13 -3
- package/dist/index.js +22 -4
- package/package.json +7 -4
- package/scripts/__snapshots__/generate.test.js.snap +73 -8
- package/scripts/generate.js +17 -5
- package/scripts/generate.test.js +10 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { N as NormalizedStoriesSpecifier, S as StoryIndex, P as ProjectAnnotations, a as StorybookConfig$1 } from './index.d-e107ed3d.js';
|
|
2
|
-
export { Theme, darkTheme, theme } from '@storybook/react-native-theming';
|
|
3
2
|
import { V as View } from './View-9ba91d66.js';
|
|
4
3
|
import { ReactRenderer } from '@storybook/react';
|
|
4
|
+
export { Theme, darkTheme, theme } from '@storybook/react-native-theming';
|
|
5
5
|
import 'file-system-cache';
|
|
6
6
|
import '@babel/core';
|
|
7
7
|
import 'http';
|
|
@@ -10,25 +10,35 @@ import '@storybook/csf';
|
|
|
10
10
|
import '@storybook/preview-web';
|
|
11
11
|
import '@storybook/channels';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/** Configuration options that are needed at startup, only serialisable values are possible */
|
|
14
|
+
interface ReactNativeOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Note that this is for future and play functions are not yet fully supported on native.
|
|
17
|
+
*/
|
|
18
|
+
playFn?: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare function prepareStories({ storyEntries, options, }: {
|
|
14
21
|
storyEntries: Array<NormalizedStoriesSpecifier & {
|
|
15
22
|
req: any;
|
|
16
23
|
}>;
|
|
24
|
+
options?: ReactNativeOptions;
|
|
17
25
|
}): {
|
|
18
26
|
index: StoryIndex;
|
|
19
27
|
importMap: Record<string, any>;
|
|
20
28
|
};
|
|
21
29
|
declare const getProjectAnnotations: (view: View, annotations: any[]) => () => Promise<ProjectAnnotations<ReactRenderer>>;
|
|
22
|
-
declare function start({ annotations, storyEntries, }: {
|
|
30
|
+
declare function start({ annotations, storyEntries, options, }: {
|
|
23
31
|
storyEntries: Array<NormalizedStoriesSpecifier & {
|
|
24
32
|
req: any;
|
|
25
33
|
}>;
|
|
26
34
|
annotations: any[];
|
|
35
|
+
options?: ReactNativeOptions;
|
|
27
36
|
}): View;
|
|
28
37
|
|
|
29
38
|
interface StorybookConfig {
|
|
30
39
|
stories: StorybookConfig$1['stories'];
|
|
31
40
|
addons: string[];
|
|
41
|
+
reactNative?: ReactNativeOptions;
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
export { StorybookConfig, getProjectAnnotations, prepareStories, start };
|
package/dist/index.js
CHANGED
|
@@ -2196,7 +2196,8 @@ var View11 = class {
|
|
|
2196
2196
|
// src/Start.tsx
|
|
2197
2197
|
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2198
2198
|
function prepareStories({
|
|
2199
|
-
storyEntries
|
|
2199
|
+
storyEntries,
|
|
2200
|
+
options
|
|
2200
2201
|
}) {
|
|
2201
2202
|
let index = {
|
|
2202
2203
|
v: 4,
|
|
@@ -2230,6 +2231,8 @@ function prepareStories({
|
|
|
2230
2231
|
Object.keys(fileExports).forEach((key) => {
|
|
2231
2232
|
if (key === "default")
|
|
2232
2233
|
return;
|
|
2234
|
+
if (!(0, import_csf2.isExportStory)(key, fileExports.default))
|
|
2235
|
+
return;
|
|
2233
2236
|
const exportValue = fileExports[key];
|
|
2234
2237
|
if (!exportValue)
|
|
2235
2238
|
return;
|
|
@@ -2246,7 +2249,21 @@ function prepareStories({
|
|
|
2246
2249
|
// FIXME: use normalize function here
|
|
2247
2250
|
tags: ["story"]
|
|
2248
2251
|
};
|
|
2249
|
-
|
|
2252
|
+
const importedStories = req(filename);
|
|
2253
|
+
const stories = Object.entries(importedStories).reduce(
|
|
2254
|
+
(carry, [storyKey, story]) => {
|
|
2255
|
+
if (!(0, import_csf2.isExportStory)(storyKey, fileExports.default))
|
|
2256
|
+
return carry;
|
|
2257
|
+
if (story.play && !options?.playFn) {
|
|
2258
|
+
carry[storyKey] = { ...story, play: void 0 };
|
|
2259
|
+
} else {
|
|
2260
|
+
carry[storyKey] = story;
|
|
2261
|
+
}
|
|
2262
|
+
return carry;
|
|
2263
|
+
},
|
|
2264
|
+
{}
|
|
2265
|
+
);
|
|
2266
|
+
importMap[`${root}/${filename.substring(2)}`] = stories;
|
|
2250
2267
|
} else {
|
|
2251
2268
|
console.log(`Unexpected error while loading ${filename}: could not find title`);
|
|
2252
2269
|
}
|
|
@@ -2279,9 +2296,10 @@ var getProjectAnnotations = (view, annotations) => async () => (0, import_previe
|
|
|
2279
2296
|
]);
|
|
2280
2297
|
function start({
|
|
2281
2298
|
annotations,
|
|
2282
|
-
storyEntries
|
|
2299
|
+
storyEntries,
|
|
2300
|
+
options
|
|
2283
2301
|
}) {
|
|
2284
|
-
const { index, importMap } = prepareStories({ storyEntries });
|
|
2302
|
+
const { index, importMap } = prepareStories({ storyEntries, options });
|
|
2285
2303
|
const channel = (0, import_channels2.createBrowserChannel)({ page: "preview" });
|
|
2286
2304
|
import_manager_api3.addons.setChannel(channel);
|
|
2287
2305
|
import_preview_api3.addons.setChannel(channel);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react-native",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.19",
|
|
4
4
|
"description": "A better way to develop React Native Components for your app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -32,12 +32,15 @@
|
|
|
32
32
|
"template/**/*"
|
|
33
33
|
],
|
|
34
34
|
"scripts": {
|
|
35
|
-
"dev": "ts-node ./buildscripts/
|
|
35
|
+
"dev": "ts-node ./buildscripts/gendtsdev.ts && tsup --watch",
|
|
36
36
|
"prepare": "rm -rf dist/ && tsup",
|
|
37
37
|
"test": "jest",
|
|
38
38
|
"test:ci": "jest"
|
|
39
39
|
},
|
|
40
40
|
"jest": {
|
|
41
|
+
"transformIgnorePatterns": [
|
|
42
|
+
"node_modules/(?!react-native|@react-native)"
|
|
43
|
+
],
|
|
41
44
|
"modulePathIgnorePatterns": [
|
|
42
45
|
"dist/"
|
|
43
46
|
],
|
|
@@ -64,7 +67,7 @@
|
|
|
64
67
|
"@storybook/preview-api": "^7.6.13",
|
|
65
68
|
"@storybook/preview-web": "^7.6.13",
|
|
66
69
|
"@storybook/react": "^7.6.13",
|
|
67
|
-
"@storybook/react-native-theming": "^7.6.
|
|
70
|
+
"@storybook/react-native-theming": "^7.6.19",
|
|
68
71
|
"chokidar": "^3.5.1",
|
|
69
72
|
"commander": "^8.2.0",
|
|
70
73
|
"dedent": "^1.5.1",
|
|
@@ -98,5 +101,5 @@
|
|
|
98
101
|
"publishConfig": {
|
|
99
102
|
"access": "public"
|
|
100
103
|
},
|
|
101
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "d47f71df982288c4be83de044f97b942e132328a"
|
|
102
105
|
}
|
|
@@ -34,13 +34,16 @@ import "@storybook/addon-ondevice-actions/register";
|
|
|
34
34
|
// @ts-ignore
|
|
35
35
|
module?.hot?.accept?.();
|
|
36
36
|
|
|
37
|
+
|
|
38
|
+
|
|
37
39
|
if (!global.view) {
|
|
38
40
|
global.view = start({
|
|
39
41
|
annotations,
|
|
40
|
-
storyEntries: normalizedStories
|
|
42
|
+
storyEntries: normalizedStories,
|
|
43
|
+
|
|
41
44
|
});
|
|
42
45
|
} else {
|
|
43
|
-
const { importMap } = prepareStories({ storyEntries: normalizedStories
|
|
46
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories, });
|
|
44
47
|
|
|
45
48
|
global.view._preview.onStoriesChanged({
|
|
46
49
|
importFn: async (importPath: string) => importMap[importPath],
|
|
@@ -89,13 +92,16 @@ import "@storybook/addon-ondevice-actions/register";
|
|
|
89
92
|
// @ts-ignore
|
|
90
93
|
module?.hot?.accept?.();
|
|
91
94
|
|
|
95
|
+
|
|
96
|
+
|
|
92
97
|
if (!global.view) {
|
|
93
98
|
global.view = start({
|
|
94
99
|
annotations,
|
|
95
|
-
storyEntries: normalizedStories
|
|
100
|
+
storyEntries: normalizedStories,
|
|
101
|
+
|
|
96
102
|
});
|
|
97
103
|
} else {
|
|
98
|
-
const { importMap } = prepareStories({ storyEntries: normalizedStories
|
|
104
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories, });
|
|
99
105
|
|
|
100
106
|
global.view._preview.onStoriesChanged({
|
|
101
107
|
importFn: async (importPath: string) => importMap[importPath],
|
|
@@ -144,13 +150,16 @@ import "@storybook/addon-ondevice-actions/register";
|
|
|
144
150
|
// @ts-ignore
|
|
145
151
|
module?.hot?.accept?.();
|
|
146
152
|
|
|
153
|
+
|
|
154
|
+
|
|
147
155
|
if (!global.view) {
|
|
148
156
|
global.view = start({
|
|
149
157
|
annotations,
|
|
150
|
-
storyEntries: normalizedStories
|
|
158
|
+
storyEntries: normalizedStories,
|
|
159
|
+
|
|
151
160
|
});
|
|
152
161
|
} else {
|
|
153
|
-
const { importMap } = prepareStories({ storyEntries: normalizedStories
|
|
162
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories, });
|
|
154
163
|
|
|
155
164
|
global.view._preview.onStoriesChanged({
|
|
156
165
|
importFn: async (importPath: string) => importMap[importPath],
|
|
@@ -199,13 +208,16 @@ import "@storybook/addon-ondevice-actions/register";
|
|
|
199
208
|
// @ts-ignore
|
|
200
209
|
module?.hot?.accept?.();
|
|
201
210
|
|
|
211
|
+
|
|
212
|
+
|
|
202
213
|
if (!global.view) {
|
|
203
214
|
global.view = start({
|
|
204
215
|
annotations,
|
|
205
|
-
storyEntries: normalizedStories
|
|
216
|
+
storyEntries: normalizedStories,
|
|
217
|
+
|
|
206
218
|
});
|
|
207
219
|
} else {
|
|
208
|
-
const { importMap } = prepareStories({ storyEntries: normalizedStories
|
|
220
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories, });
|
|
209
221
|
|
|
210
222
|
global.view._preview.onStoriesChanged({
|
|
211
223
|
importFn: async (importPath: string) => importMap[importPath],
|
|
@@ -219,3 +231,56 @@ import "@storybook/addon-ondevice-actions/register";
|
|
|
219
231
|
export const view = global.view;
|
|
220
232
|
"
|
|
221
233
|
`;
|
|
234
|
+
|
|
235
|
+
exports[`loader writeRequires when using js writes the story imports without types 1`] = `
|
|
236
|
+
"
|
|
237
|
+
/* do not change this file, it is auto generated by storybook. */
|
|
238
|
+
|
|
239
|
+
import { start, prepareStories, getProjectAnnotations } from '@storybook/react-native';
|
|
240
|
+
|
|
241
|
+
import "@storybook/addon-ondevice-notes/register";
|
|
242
|
+
import "@storybook/addon-ondevice-controls/register";
|
|
243
|
+
import "@storybook/addon-ondevice-backgrounds/register";
|
|
244
|
+
import "@storybook/addon-ondevice-actions/register";
|
|
245
|
+
|
|
246
|
+
const normalizedStories = [{
|
|
247
|
+
titlePrefix: "",
|
|
248
|
+
directory: "./scripts/mocks/all-config-files",
|
|
249
|
+
files: "FakeStory.stories.tsx",
|
|
250
|
+
importPathMatcher: /^\\.[\\\\/](?:FakeStory\\.stories\\.tsx)$/,
|
|
251
|
+
|
|
252
|
+
req: require.context('./', false, /^\\.[\\\\/](?:FakeStory\\.stories\\.tsx)$/)
|
|
253
|
+
}];
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
const annotations = [require('./preview'),require("@storybook/react-native/dist/preview"), require('@storybook/addon-actions/preview')];
|
|
258
|
+
|
|
259
|
+
global.STORIES = normalizedStories;
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
module?.hot?.accept?.();
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
if (!global.view) {
|
|
267
|
+
global.view = start({
|
|
268
|
+
annotations,
|
|
269
|
+
storyEntries: normalizedStories,
|
|
270
|
+
|
|
271
|
+
});
|
|
272
|
+
} else {
|
|
273
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories, });
|
|
274
|
+
|
|
275
|
+
global.view._preview.onStoriesChanged({
|
|
276
|
+
importFn: async (importPath) => importMap[importPath],
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
global.view._preview.onGetProjectAnnotationsChanged({
|
|
280
|
+
getProjectAnnotations: getProjectAnnotations(global.view, annotations),
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export const view = global.view;
|
|
285
|
+
"
|
|
286
|
+
`;
|
package/scripts/generate.js
CHANGED
|
@@ -41,7 +41,7 @@ function generate({ configPath, absolute = false, useJs = false }) {
|
|
|
41
41
|
directory: "${specifier.directory}",
|
|
42
42
|
files: "${specifier.files}",
|
|
43
43
|
importPathMatcher: /${reg.source}/,
|
|
44
|
-
// @ts-ignore
|
|
44
|
+
${useJs ? '' : '// @ts-ignore'}
|
|
45
45
|
req: require.context('${pathToStory}', ${r}, ${m})
|
|
46
46
|
}`;
|
|
47
47
|
});
|
|
@@ -55,6 +55,15 @@ function generate({ configPath, absolute = false, useJs = false }) {
|
|
|
55
55
|
? "require('@storybook/addon-actions/preview')"
|
|
56
56
|
: '';
|
|
57
57
|
|
|
58
|
+
let options = '';
|
|
59
|
+
let optionsVar = '';
|
|
60
|
+
const reactNativeOptions = main.reactNative;
|
|
61
|
+
|
|
62
|
+
if (reactNativeOptions && typeof reactNativeOptions === 'object') {
|
|
63
|
+
optionsVar = `const options = ${JSON.stringify(reactNativeOptions)}`;
|
|
64
|
+
options = 'options';
|
|
65
|
+
}
|
|
66
|
+
|
|
58
67
|
const previewExists = getPreviewExists({ configPath });
|
|
59
68
|
|
|
60
69
|
const annotations = `[${previewExists ? "require('./preview')," : ''}${doctools}, ${enhancer}]`;
|
|
@@ -81,19 +90,22 @@ function generate({ configPath, absolute = false, useJs = false }) {
|
|
|
81
90
|
|
|
82
91
|
global.STORIES = normalizedStories;
|
|
83
92
|
|
|
84
|
-
// @ts-ignore
|
|
93
|
+
${useJs ? '' : '// @ts-ignore'}
|
|
85
94
|
module?.hot?.accept?.();
|
|
86
95
|
|
|
96
|
+
${optionsVar}
|
|
97
|
+
|
|
87
98
|
if (!global.view) {
|
|
88
99
|
global.view = start({
|
|
89
100
|
annotations,
|
|
90
|
-
storyEntries: normalizedStories
|
|
101
|
+
storyEntries: normalizedStories,
|
|
102
|
+
${options}
|
|
91
103
|
});
|
|
92
104
|
} else {
|
|
93
|
-
const { importMap } = prepareStories({ storyEntries: normalizedStories });
|
|
105
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories, ${options} });
|
|
94
106
|
|
|
95
107
|
global.view._preview.onStoriesChanged({
|
|
96
|
-
importFn: async (importPath: string) => importMap[importPath],
|
|
108
|
+
importFn: async (importPath${useJs ? '' : ': string'}) => importMap[importPath],
|
|
97
109
|
});
|
|
98
110
|
|
|
99
111
|
global.view._preview.onGetProjectAnnotationsChanged({
|
package/scripts/generate.test.js
CHANGED
|
@@ -30,6 +30,16 @@ describe('loader', () => {
|
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
+
describe('when using js', () => {
|
|
34
|
+
it('writes the story imports without types', () => {
|
|
35
|
+
generate({ configPath: 'scripts/mocks/all-config-files', useJs: true });
|
|
36
|
+
expect(pathMock).toEqual(
|
|
37
|
+
path.resolve(__dirname, 'mocks/all-config-files/storybook.requires.js')
|
|
38
|
+
);
|
|
39
|
+
expect(fileContentMock).toMatchSnapshot();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
33
43
|
describe('when there are different file extensions', () => {
|
|
34
44
|
it('writes the story imports', () => {
|
|
35
45
|
generate({ configPath: 'scripts/mocks/file-extensions' });
|