@storybook/react-native 7.6.15 → 7.6.17
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 +2 -2
- package/dist/{View-425d6066.d.ts → View-9ba91d66.d.ts} +1 -1
- package/dist/{index.d-5b1baa07.d.ts → index.d-e107ed3d.d.ts} +163 -1
- package/dist/index.d.ts +13 -4
- package/dist/index.js +22 -18
- package/dist/preview.d.ts +1 -1
- package/package.json +3 -3
- package/scripts/__snapshots__/generate.test.js.snap +136 -36
- package/scripts/generate.js +37 -23
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-
|
|
2
|
+
import { P as Params } from './View-9ba91d66.js';
|
|
3
3
|
import { ClientApi } from '@storybook/preview-api';
|
|
4
|
-
import { L as LoaderFunction, A as Addon_StoryApi } from './index.d-
|
|
4
|
+
import { L as LoaderFunction, A as Addon_StoryApi } from './index.d-e107ed3d.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';
|
|
@@ -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 {
|
|
6
|
+
import { S as StoryIndex, b as PreparedStory } from './index.d-e107ed3d.js';
|
|
7
7
|
import { Channel } from '@storybook/channels';
|
|
8
8
|
|
|
9
9
|
interface Storage {
|
|
@@ -22,6 +22,90 @@ declare global {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
@see Simplify
|
|
27
|
+
*/
|
|
28
|
+
interface SimplifyOptions {
|
|
29
|
+
/**
|
|
30
|
+
Do the simplification recursively.
|
|
31
|
+
|
|
32
|
+
@default false
|
|
33
|
+
*/
|
|
34
|
+
deep?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Flatten a type without worrying about the result.
|
|
38
|
+
type Flatten<
|
|
39
|
+
AnyType,
|
|
40
|
+
Options extends SimplifyOptions = {},
|
|
41
|
+
> = Options['deep'] extends true
|
|
42
|
+
? {[KeyType in keyof AnyType]: Simplify<AnyType[KeyType], Options>}
|
|
43
|
+
: {[KeyType in keyof AnyType]: AnyType[KeyType]};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
47
|
+
|
|
48
|
+
@example
|
|
49
|
+
```
|
|
50
|
+
import type {Simplify} from 'type-fest';
|
|
51
|
+
|
|
52
|
+
type PositionProps = {
|
|
53
|
+
top: number;
|
|
54
|
+
left: number;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type SizeProps = {
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
63
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
67
|
+
|
|
68
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
69
|
+
|
|
70
|
+
@example
|
|
71
|
+
```
|
|
72
|
+
import type {Simplify} from 'type-fest';
|
|
73
|
+
|
|
74
|
+
interface SomeInterface {
|
|
75
|
+
foo: number;
|
|
76
|
+
bar?: string;
|
|
77
|
+
baz: number | undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type SomeType = {
|
|
81
|
+
foo: number;
|
|
82
|
+
bar?: string;
|
|
83
|
+
baz: number | undefined;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
87
|
+
const someType: SomeType = literal;
|
|
88
|
+
const someInterface: SomeInterface = literal;
|
|
89
|
+
|
|
90
|
+
function fn(object: Record<string, unknown>): void {}
|
|
91
|
+
|
|
92
|
+
fn(literal); // Good: literal object type is sealed
|
|
93
|
+
fn(someType); // Good: type is sealed
|
|
94
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
95
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
99
|
+
|
|
100
|
+
@category Object
|
|
101
|
+
*/
|
|
102
|
+
type Simplify<
|
|
103
|
+
AnyType,
|
|
104
|
+
Options extends SimplifyOptions = {},
|
|
105
|
+
> = Flatten<AnyType> extends AnyType
|
|
106
|
+
? Flatten<AnyType, Options>
|
|
107
|
+
: AnyType;
|
|
108
|
+
|
|
25
109
|
/**
|
|
26
110
|
Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
27
111
|
|
|
@@ -802,12 +886,18 @@ interface StrictInputType extends InputType {
|
|
|
802
886
|
interface Args {
|
|
803
887
|
[name: string]: any;
|
|
804
888
|
}
|
|
889
|
+
type ArgTypes<TArgs = Args> = {
|
|
890
|
+
[name in keyof TArgs]: InputType;
|
|
891
|
+
};
|
|
805
892
|
type StrictArgTypes<TArgs = Args> = {
|
|
806
893
|
[name in keyof TArgs]: StrictInputType;
|
|
807
894
|
};
|
|
808
895
|
interface Globals {
|
|
809
896
|
[name: string]: any;
|
|
810
897
|
}
|
|
898
|
+
interface GlobalTypes {
|
|
899
|
+
[name: string]: InputType;
|
|
900
|
+
}
|
|
811
901
|
type Renderer = {
|
|
812
902
|
/** What is the type of the `component` annotation in this renderer? */
|
|
813
903
|
component: unknown;
|
|
@@ -828,6 +918,10 @@ interface StoryContextForEnhancers<TRenderer extends Renderer = Renderer, TArgs
|
|
|
828
918
|
initialArgs: TArgs;
|
|
829
919
|
argTypes: StrictArgTypes<TArgs>;
|
|
830
920
|
}
|
|
921
|
+
type ArgsEnhancer<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContextForEnhancers<TRenderer, TArgs>) => TArgs;
|
|
922
|
+
type ArgTypesEnhancer<TRenderer extends Renderer = Renderer, TArgs = Args> = ((context: StoryContextForEnhancers<TRenderer, TArgs>) => StrictArgTypes<TArgs>) & {
|
|
923
|
+
secondPass?: boolean;
|
|
924
|
+
};
|
|
831
925
|
interface StoryContextUpdate<TArgs = Args> {
|
|
832
926
|
args?: TArgs;
|
|
833
927
|
globals?: Globals;
|
|
@@ -845,6 +939,12 @@ interface StoryContext<TRenderer extends Renderer = Renderer, TArgs = Args> exte
|
|
|
845
939
|
abortSignal: AbortSignal;
|
|
846
940
|
canvasElement: TRenderer['canvasElement'];
|
|
847
941
|
}
|
|
942
|
+
type StepLabel = string;
|
|
943
|
+
type StepFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (label: StepLabel, play: PlayFunction<TRenderer, TArgs>) => Promise<void> | void;
|
|
944
|
+
type PlayFunctionContext<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryContext<TRenderer, TArgs> & {
|
|
945
|
+
step: StepFunction<TRenderer, TArgs>;
|
|
946
|
+
};
|
|
947
|
+
type PlayFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: PlayFunctionContext<TRenderer, TArgs>) => Promise<void> | void;
|
|
848
948
|
type PartialStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (update?: StoryContextUpdate<Partial<TArgs>>) => TRenderer['storyResult'];
|
|
849
949
|
type LegacyStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContext<TRenderer, TArgs>) => TRenderer['storyResult'];
|
|
850
950
|
type ArgsStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (args: TArgs, context: StoryContext<TRenderer, TArgs>) => (TRenderer & {
|
|
@@ -852,6 +952,49 @@ type ArgsStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (args: T
|
|
|
852
952
|
})['storyResult'];
|
|
853
953
|
type StoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = LegacyStoryFn<TRenderer, TArgs> | ArgsStoryFn<TRenderer, TArgs>;
|
|
854
954
|
type DecoratorFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (fn: PartialStoryFn<TRenderer, TArgs>, c: StoryContext<TRenderer, TArgs>) => TRenderer['storyResult'];
|
|
955
|
+
type DecoratorApplicator<TRenderer extends Renderer = Renderer, TArgs = Args> = (storyFn: LegacyStoryFn<TRenderer, TArgs>, decorators: DecoratorFunction<TRenderer, TArgs>[]) => LegacyStoryFn<TRenderer, TArgs>;
|
|
956
|
+
type StepRunner<TRenderer extends Renderer = Renderer, TArgs = Args> = (label: StepLabel, play: PlayFunction<TRenderer, TArgs>, context: PlayFunctionContext<TRenderer, TArgs>) => Promise<void>;
|
|
957
|
+
type BaseAnnotations<TRenderer extends Renderer = Renderer, TArgs = Args> = {
|
|
958
|
+
/**
|
|
959
|
+
* Wrapper components or Storybook decorators that wrap a story.
|
|
960
|
+
*
|
|
961
|
+
* Decorators defined in Meta will be applied to every story variation.
|
|
962
|
+
* @see [Decorators](https://storybook.js.org/docs/addons/introduction/#1-decorators)
|
|
963
|
+
*/
|
|
964
|
+
decorators?: DecoratorFunction<TRenderer, Simplify<TArgs>>[] | DecoratorFunction<TRenderer, Simplify<TArgs>>;
|
|
965
|
+
/**
|
|
966
|
+
* Custom metadata for a story.
|
|
967
|
+
* @see [Parameters](https://storybook.js.org/docs/basics/writing-stories/#parameters)
|
|
968
|
+
*/
|
|
969
|
+
parameters?: Parameters;
|
|
970
|
+
/**
|
|
971
|
+
* Dynamic data that are provided (and possibly updated by) Storybook and its addons.
|
|
972
|
+
* @see [Arg story inputs](https://storybook.js.org/docs/react/api/csf#args-story-inputs)
|
|
973
|
+
*/
|
|
974
|
+
args?: Partial<TArgs>;
|
|
975
|
+
/**
|
|
976
|
+
* ArgTypes encode basic metadata for args, such as `name`, `description`, `defaultValue` for an arg. These get automatically filled in by Storybook Docs.
|
|
977
|
+
* @see [Control annotations](https://github.com/storybookjs/storybook/blob/91e9dee33faa8eff0b342a366845de7100415367/addons/controls/README.md#control-annotations)
|
|
978
|
+
*/
|
|
979
|
+
argTypes?: Partial<ArgTypes<TArgs>>;
|
|
980
|
+
/**
|
|
981
|
+
* Asynchronous functions which provide data for a story.
|
|
982
|
+
* @see [Loaders](https://storybook.js.org/docs/react/writing-stories/loaders)
|
|
983
|
+
*/
|
|
984
|
+
loaders?: LoaderFunction<TRenderer, TArgs>[] | LoaderFunction<TRenderer, TArgs>;
|
|
985
|
+
/**
|
|
986
|
+
* Define a custom render function for the story(ies). If not passed, a default render function by the renderer will be used.
|
|
987
|
+
*/
|
|
988
|
+
render?: ArgsStoryFn<TRenderer, TArgs>;
|
|
989
|
+
};
|
|
990
|
+
type ProjectAnnotations$1<TRenderer extends Renderer = Renderer, TArgs = Args> = BaseAnnotations<TRenderer, TArgs> & {
|
|
991
|
+
argsEnhancers?: ArgsEnhancer<TRenderer, Args>[];
|
|
992
|
+
argTypesEnhancers?: ArgTypesEnhancer<TRenderer, Args>[];
|
|
993
|
+
globals?: Globals;
|
|
994
|
+
globalTypes?: GlobalTypes;
|
|
995
|
+
applyDecorators?: DecoratorApplicator<TRenderer, Args>;
|
|
996
|
+
runStep?: StepRunner<TRenderer, TArgs>;
|
|
997
|
+
};
|
|
855
998
|
|
|
856
999
|
interface Plugin {
|
|
857
1000
|
(module: Program): Program;
|
|
@@ -3256,6 +3399,13 @@ interface Addon_StoryApi<StoryFnReturnType = unknown> {
|
|
|
3256
3399
|
}
|
|
3257
3400
|
type Path = string;
|
|
3258
3401
|
type ModuleExport = any;
|
|
3402
|
+
type MaybePromise<T> = Promise<T> | T;
|
|
3403
|
+
type TeardownRenderToCanvas = () => MaybePromise<void>;
|
|
3404
|
+
type RenderToCanvas<TRenderer extends Renderer> = (context: RenderContext<TRenderer>, element: TRenderer['canvasElement']) => MaybePromise<void | TeardownRenderToCanvas>;
|
|
3405
|
+
type ProjectAnnotations<TRenderer extends Renderer> = ProjectAnnotations$1<TRenderer> & {
|
|
3406
|
+
renderToCanvas?: RenderToCanvas<TRenderer>;
|
|
3407
|
+
renderToDOM?: RenderToCanvas<TRenderer>;
|
|
3408
|
+
};
|
|
3259
3409
|
type PreparedStory<TRenderer extends Renderer = Renderer> = StoryContextForEnhancers<TRenderer> & {
|
|
3260
3410
|
moduleExport: ModuleExport;
|
|
3261
3411
|
originalStoryFn: StoryFn<TRenderer>;
|
|
@@ -3266,5 +3416,17 @@ type PreparedStory<TRenderer extends Renderer = Renderer> = StoryContextForEnhan
|
|
|
3266
3416
|
}>;
|
|
3267
3417
|
playFunction?: (context: StoryContext<TRenderer>) => Promise<void> | void;
|
|
3268
3418
|
};
|
|
3419
|
+
declare type RenderContext<TRenderer extends Renderer = Renderer> = StoryIdentifier & {
|
|
3420
|
+
showMain: () => void;
|
|
3421
|
+
showError: (error: {
|
|
3422
|
+
title: string;
|
|
3423
|
+
description: string;
|
|
3424
|
+
}) => void;
|
|
3425
|
+
showException: (err: Error) => void;
|
|
3426
|
+
forceRemount: boolean;
|
|
3427
|
+
storyContext: StoryContext<TRenderer>;
|
|
3428
|
+
storyFn: PartialStoryFn<TRenderer>;
|
|
3429
|
+
unboundStoryFn: LegacyStoryFn<TRenderer>;
|
|
3430
|
+
};
|
|
3269
3431
|
|
|
3270
|
-
export { Addon_StoryApi as A, LoaderFunction as L, NormalizedStoriesSpecifier as N,
|
|
3432
|
+
export { Addon_StoryApi as A, LoaderFunction as L, NormalizedStoriesSpecifier as N, ProjectAnnotations as P, Renderer as R, StoryIndex as S, StorybookConfig as a, PreparedStory as b, StoryContextForEnhancers as c, Args as d, StrictArgTypes as e };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import { N as NormalizedStoriesSpecifier, S as StorybookConfig$1 } from './index.d-
|
|
1
|
+
import { N as NormalizedStoriesSpecifier, S as StoryIndex, P as ProjectAnnotations, a as StorybookConfig$1 } from './index.d-e107ed3d.js';
|
|
2
2
|
export { Theme, darkTheme, theme } from '@storybook/react-native-theming';
|
|
3
|
-
import { V as View } from './View-
|
|
3
|
+
import { V as View } from './View-9ba91d66.js';
|
|
4
|
+
import { ReactRenderer } from '@storybook/react';
|
|
4
5
|
import 'file-system-cache';
|
|
5
6
|
import '@babel/core';
|
|
6
7
|
import 'http';
|
|
7
8
|
import 'react/jsx-runtime';
|
|
8
9
|
import '@storybook/csf';
|
|
9
10
|
import '@storybook/preview-web';
|
|
10
|
-
import '@storybook/react';
|
|
11
11
|
import '@storybook/channels';
|
|
12
12
|
|
|
13
|
+
declare function prepareStories({ storyEntries, }: {
|
|
14
|
+
storyEntries: Array<NormalizedStoriesSpecifier & {
|
|
15
|
+
req: any;
|
|
16
|
+
}>;
|
|
17
|
+
}): {
|
|
18
|
+
index: StoryIndex;
|
|
19
|
+
importMap: Record<string, any>;
|
|
20
|
+
};
|
|
21
|
+
declare const getProjectAnnotations: (view: View, annotations: any[]) => () => Promise<ProjectAnnotations<ReactRenderer>>;
|
|
13
22
|
declare function start({ annotations, storyEntries, }: {
|
|
14
23
|
storyEntries: Array<NormalizedStoriesSpecifier & {
|
|
15
24
|
req: any;
|
|
@@ -22,4 +31,4 @@ interface StorybookConfig {
|
|
|
22
31
|
addons: string[];
|
|
23
32
|
}
|
|
24
33
|
|
|
25
|
-
export { StorybookConfig, start };
|
|
34
|
+
export { StorybookConfig, getProjectAnnotations, prepareStories, start };
|
package/dist/index.js
CHANGED
|
@@ -59,6 +59,8 @@ var require_dist = __commonJS({
|
|
|
59
59
|
var src_exports = {};
|
|
60
60
|
__export(src_exports, {
|
|
61
61
|
darkTheme: () => import_react_native_theming13.darkTheme,
|
|
62
|
+
getProjectAnnotations: () => getProjectAnnotations,
|
|
63
|
+
prepareStories: () => prepareStories,
|
|
62
64
|
start: () => start,
|
|
63
65
|
theme: () => import_react_native_theming13.theme
|
|
64
66
|
});
|
|
@@ -2258,6 +2260,23 @@ function prepareStories({
|
|
|
2258
2260
|
});
|
|
2259
2261
|
return { index, importMap };
|
|
2260
2262
|
}
|
|
2263
|
+
var getProjectAnnotations = (view, annotations) => async () => (0, import_preview_api3.composeConfigs)([
|
|
2264
|
+
{
|
|
2265
|
+
renderToCanvas: (context) => {
|
|
2266
|
+
view._setStory(context.storyContext);
|
|
2267
|
+
},
|
|
2268
|
+
render: (args, context) => {
|
|
2269
|
+
const { id, component: Component } = context;
|
|
2270
|
+
if (!Component) {
|
|
2271
|
+
throw new Error(
|
|
2272
|
+
`Unable to render story ${id} as the component annotation is missing from the default export`
|
|
2273
|
+
);
|
|
2274
|
+
}
|
|
2275
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Component, { ...args });
|
|
2276
|
+
}
|
|
2277
|
+
},
|
|
2278
|
+
...annotations
|
|
2279
|
+
]);
|
|
2261
2280
|
function start({
|
|
2262
2281
|
annotations,
|
|
2263
2282
|
storyEntries
|
|
@@ -2307,26 +2326,9 @@ function start({
|
|
|
2307
2326
|
global.__STORYBOOK_PREVIEW__ = preview;
|
|
2308
2327
|
global.__STORYBOOK_STORY_STORE__ = preview.storyStore;
|
|
2309
2328
|
}
|
|
2310
|
-
const getProjectAnnotations = async () => (0, import_preview_api3.composeConfigs)([
|
|
2311
|
-
{
|
|
2312
|
-
renderToCanvas: (context) => {
|
|
2313
|
-
view._setStory(context.storyContext);
|
|
2314
|
-
},
|
|
2315
|
-
render: (args, context) => {
|
|
2316
|
-
const { id, component: Component } = context;
|
|
2317
|
-
if (!Component) {
|
|
2318
|
-
throw new Error(
|
|
2319
|
-
`Unable to render story ${id} as the component annotation is missing from the default export`
|
|
2320
|
-
);
|
|
2321
|
-
}
|
|
2322
|
-
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Component, { ...args });
|
|
2323
|
-
}
|
|
2324
|
-
},
|
|
2325
|
-
...annotations
|
|
2326
|
-
]);
|
|
2327
2329
|
preview.initialize({
|
|
2328
2330
|
importFn: async (importPath) => importMap[importPath],
|
|
2329
|
-
getProjectAnnotations,
|
|
2331
|
+
getProjectAnnotations: getProjectAnnotations(view, annotations),
|
|
2330
2332
|
getStoryIndex: () => index
|
|
2331
2333
|
});
|
|
2332
2334
|
view._storyIndex = index;
|
|
@@ -2335,6 +2337,8 @@ function start({
|
|
|
2335
2337
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2336
2338
|
0 && (module.exports = {
|
|
2337
2339
|
darkTheme,
|
|
2340
|
+
getProjectAnnotations,
|
|
2341
|
+
prepareStories,
|
|
2338
2342
|
start,
|
|
2339
2343
|
theme
|
|
2340
2344
|
});
|
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,
|
|
2
|
+
import { R as Renderer, c as StoryContextForEnhancers, d as Args, e as StrictArgTypes } from './index.d-e107ed3d.js';
|
|
3
3
|
import 'file-system-cache';
|
|
4
4
|
import '@babel/core';
|
|
5
5
|
import 'http';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react-native",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.17",
|
|
4
4
|
"description": "A better way to develop React Native Components for your app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@storybook/preview-api": "^7.6.13",
|
|
65
65
|
"@storybook/preview-web": "^7.6.13",
|
|
66
66
|
"@storybook/react": "^7.6.13",
|
|
67
|
-
"@storybook/react-native-theming": "^7.6.
|
|
67
|
+
"@storybook/react-native-theming": "^7.6.17",
|
|
68
68
|
"chokidar": "^3.5.1",
|
|
69
69
|
"commander": "^8.2.0",
|
|
70
70
|
"dedent": "^1.5.1",
|
|
@@ -98,5 +98,5 @@
|
|
|
98
98
|
"publishConfig": {
|
|
99
99
|
"access": "public"
|
|
100
100
|
},
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "eabc8e9dfc361faa0a7b1c7f08fe85b8cf37725b"
|
|
102
102
|
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
exports[`loader writeRequires when there are different file extensions writes the story imports 1`] = `
|
|
4
4
|
"
|
|
5
5
|
/* do not change this file, it is auto generated by storybook. */
|
|
6
|
-
|
|
7
|
-
import { start } from '@storybook/react-native';
|
|
6
|
+
|
|
7
|
+
import { start, prepareStories, getProjectAnnotations } from '@storybook/react-native';
|
|
8
8
|
|
|
9
9
|
import "@storybook/addon-ondevice-notes/register";
|
|
10
10
|
import "@storybook/addon-ondevice-controls/register";
|
|
@@ -18,23 +18,48 @@ import "@storybook/addon-ondevice-actions/register";
|
|
|
18
18
|
importPathMatcher: /^\\.[\\\\/](?:FakeStory\\.stories\\.tsx)$/,
|
|
19
19
|
// @ts-ignore
|
|
20
20
|
req: require.context('./', false, /^\\.[\\\\/](?:FakeStory\\.stories\\.tsx)$/)
|
|
21
|
-
}]
|
|
21
|
+
}];
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
|
|
24
|
+
declare global {
|
|
25
|
+
var view: ReturnType<typeof start>;
|
|
26
|
+
var STORIES: typeof normalizedStories;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const annotations = [require('./preview'),require("@storybook/react-native/dist/preview"), require('@storybook/addon-actions/preview')];
|
|
25
31
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
global.STORIES = normalizedStories;
|
|
33
|
+
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
module?.hot?.accept?.();
|
|
36
|
+
|
|
37
|
+
if (!global.view) {
|
|
38
|
+
global.view = start({
|
|
39
|
+
annotations,
|
|
40
|
+
storyEntries: normalizedStories
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories });
|
|
44
|
+
|
|
45
|
+
global.view._preview.onStoriesChanged({
|
|
46
|
+
importFn: async (importPath: string) => importMap[importPath],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
global.view._preview.onGetProjectAnnotationsChanged({
|
|
50
|
+
getProjectAnnotations: getProjectAnnotations(global.view, annotations),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const view = global.view;
|
|
30
55
|
"
|
|
31
56
|
`;
|
|
32
57
|
|
|
33
58
|
exports[`loader writeRequires when there is a configuration object writes the story imports 1`] = `
|
|
34
59
|
"
|
|
35
60
|
/* do not change this file, it is auto generated by storybook. */
|
|
36
|
-
|
|
37
|
-
import { start } from '@storybook/react-native';
|
|
61
|
+
|
|
62
|
+
import { start, prepareStories, getProjectAnnotations } from '@storybook/react-native';
|
|
38
63
|
|
|
39
64
|
import "@storybook/addon-ondevice-notes/register";
|
|
40
65
|
import "@storybook/addon-ondevice-controls/register";
|
|
@@ -48,23 +73,48 @@ import "@storybook/addon-ondevice-actions/register";
|
|
|
48
73
|
importPathMatcher: /^\\.(?:(?:^|\\/|(?:(?:(?!(?:^|\\/)\\.).)*?)\\/)(?!\\.)(?=.)[^/]*?\\.stories\\.tsx)$/,
|
|
49
74
|
// @ts-ignore
|
|
50
75
|
req: require.context('./components', true, /^\\.(?:(?:^|\\/|(?:(?:(?!(?:^|\\/)\\.).)*?)\\/)(?!\\.)(?=.)[^/]*?\\.stories\\.tsx)$/)
|
|
51
|
-
}]
|
|
76
|
+
}];
|
|
52
77
|
|
|
53
|
-
|
|
54
|
-
|
|
78
|
+
|
|
79
|
+
declare global {
|
|
80
|
+
var view: ReturnType<typeof start>;
|
|
81
|
+
var STORIES: typeof normalizedStories;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
const annotations = [require('./preview'),require("@storybook/react-native/dist/preview"), require('@storybook/addon-actions/preview')];
|
|
55
86
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
87
|
+
global.STORIES = normalizedStories;
|
|
88
|
+
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
module?.hot?.accept?.();
|
|
91
|
+
|
|
92
|
+
if (!global.view) {
|
|
93
|
+
global.view = start({
|
|
94
|
+
annotations,
|
|
95
|
+
storyEntries: normalizedStories
|
|
96
|
+
});
|
|
97
|
+
} else {
|
|
98
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories });
|
|
99
|
+
|
|
100
|
+
global.view._preview.onStoriesChanged({
|
|
101
|
+
importFn: async (importPath: string) => importMap[importPath],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
global.view._preview.onGetProjectAnnotationsChanged({
|
|
105
|
+
getProjectAnnotations: getProjectAnnotations(global.view, annotations),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const view = global.view;
|
|
60
110
|
"
|
|
61
111
|
`;
|
|
62
112
|
|
|
63
113
|
exports[`loader writeRequires when there is a story glob writes the story imports 1`] = `
|
|
64
114
|
"
|
|
65
115
|
/* do not change this file, it is auto generated by storybook. */
|
|
66
|
-
|
|
67
|
-
import { start } from '@storybook/react-native';
|
|
116
|
+
|
|
117
|
+
import { start, prepareStories, getProjectAnnotations } from '@storybook/react-native';
|
|
68
118
|
|
|
69
119
|
import "@storybook/addon-ondevice-notes/register";
|
|
70
120
|
import "@storybook/addon-ondevice-controls/register";
|
|
@@ -78,23 +128,48 @@ import "@storybook/addon-ondevice-actions/register";
|
|
|
78
128
|
importPathMatcher: /^\\.[\\\\/](?:FakeStory\\.stories\\.tsx)$/,
|
|
79
129
|
// @ts-ignore
|
|
80
130
|
req: require.context('./', false, /^\\.[\\\\/](?:FakeStory\\.stories\\.tsx)$/)
|
|
81
|
-
}]
|
|
131
|
+
}];
|
|
82
132
|
|
|
83
|
-
|
|
84
|
-
|
|
133
|
+
|
|
134
|
+
declare global {
|
|
135
|
+
var view: ReturnType<typeof start>;
|
|
136
|
+
var STORIES: typeof normalizedStories;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
const annotations = [require('./preview'),require("@storybook/react-native/dist/preview"), require('@storybook/addon-actions/preview')];
|
|
85
141
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
142
|
+
global.STORIES = normalizedStories;
|
|
143
|
+
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
module?.hot?.accept?.();
|
|
146
|
+
|
|
147
|
+
if (!global.view) {
|
|
148
|
+
global.view = start({
|
|
149
|
+
annotations,
|
|
150
|
+
storyEntries: normalizedStories
|
|
151
|
+
});
|
|
152
|
+
} else {
|
|
153
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories });
|
|
154
|
+
|
|
155
|
+
global.view._preview.onStoriesChanged({
|
|
156
|
+
importFn: async (importPath: string) => importMap[importPath],
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
global.view._preview.onGetProjectAnnotationsChanged({
|
|
160
|
+
getProjectAnnotations: getProjectAnnotations(global.view, annotations),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export const view = global.view;
|
|
90
165
|
"
|
|
91
166
|
`;
|
|
92
167
|
|
|
93
168
|
exports[`loader writeRequires when there is no preview does not add preview related stuff 1`] = `
|
|
94
169
|
"
|
|
95
170
|
/* do not change this file, it is auto generated by storybook. */
|
|
96
|
-
|
|
97
|
-
import { start } from '@storybook/react-native';
|
|
171
|
+
|
|
172
|
+
import { start, prepareStories, getProjectAnnotations } from '@storybook/react-native';
|
|
98
173
|
|
|
99
174
|
import "@storybook/addon-ondevice-notes/register";
|
|
100
175
|
import "@storybook/addon-ondevice-controls/register";
|
|
@@ -108,14 +183,39 @@ import "@storybook/addon-ondevice-actions/register";
|
|
|
108
183
|
importPathMatcher: /^\\.[\\\\/](?:FakeStory\\.stories\\.tsx)$/,
|
|
109
184
|
// @ts-ignore
|
|
110
185
|
req: require.context('./', false, /^\\.[\\\\/](?:FakeStory\\.stories\\.tsx)$/)
|
|
111
|
-
}]
|
|
186
|
+
}];
|
|
112
187
|
|
|
113
|
-
|
|
114
|
-
|
|
188
|
+
|
|
189
|
+
declare global {
|
|
190
|
+
var view: ReturnType<typeof start>;
|
|
191
|
+
var STORIES: typeof normalizedStories;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
const annotations = [require("@storybook/react-native/dist/preview"), require('@storybook/addon-actions/preview')];
|
|
115
196
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
197
|
+
global.STORIES = normalizedStories;
|
|
198
|
+
|
|
199
|
+
// @ts-ignore
|
|
200
|
+
module?.hot?.accept?.();
|
|
201
|
+
|
|
202
|
+
if (!global.view) {
|
|
203
|
+
global.view = start({
|
|
204
|
+
annotations,
|
|
205
|
+
storyEntries: normalizedStories
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories });
|
|
209
|
+
|
|
210
|
+
global.view._preview.onStoriesChanged({
|
|
211
|
+
importFn: async (importPath: string) => importMap[importPath],
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
global.view._preview.onGetProjectAnnotationsChanged({
|
|
215
|
+
getProjectAnnotations: getProjectAnnotations(global.view, annotations),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export const view = global.view;
|
|
120
220
|
"
|
|
121
221
|
`;
|
package/scripts/generate.js
CHANGED
|
@@ -59,25 +59,52 @@ function generate({ configPath, absolute = false, useJs = false }) {
|
|
|
59
59
|
|
|
60
60
|
const annotations = `[${previewExists ? "require('./preview')," : ''}${doctools}, ${enhancer}]`;
|
|
61
61
|
|
|
62
|
+
const globalTypes = `
|
|
63
|
+
declare global {
|
|
64
|
+
var view: ReturnType<typeof start>;
|
|
65
|
+
var STORIES: typeof normalizedStories;
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
|
|
62
69
|
const fileContent = `
|
|
63
70
|
/* do not change this file, it is auto generated by storybook. */
|
|
64
|
-
|
|
65
|
-
import { start } from '@storybook/react-native';
|
|
71
|
+
|
|
72
|
+
import { start, prepareStories, getProjectAnnotations } from '@storybook/react-native';
|
|
66
73
|
|
|
67
74
|
${registerAddons}
|
|
68
75
|
|
|
69
|
-
const normalizedStories = [${normalizedStories.join(',')}]
|
|
76
|
+
const normalizedStories = [${normalizedStories.join(',')}];
|
|
70
77
|
|
|
71
|
-
|
|
72
|
-
global.STORIES = normalizedStories;
|
|
78
|
+
${useJs ? '' : globalTypes}
|
|
73
79
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
const annotations = ${annotations};
|
|
81
|
+
|
|
82
|
+
global.STORIES = normalizedStories;
|
|
83
|
+
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
module?.hot?.accept?.();
|
|
86
|
+
|
|
87
|
+
if (!global.view) {
|
|
88
|
+
global.view = start({
|
|
89
|
+
annotations,
|
|
90
|
+
storyEntries: normalizedStories
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
const { importMap } = prepareStories({ storyEntries: normalizedStories });
|
|
94
|
+
|
|
95
|
+
global.view._preview.onStoriesChanged({
|
|
96
|
+
importFn: async (importPath: string) => importMap[importPath],
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
global.view._preview.onGetProjectAnnotationsChanged({
|
|
100
|
+
getProjectAnnotations: getProjectAnnotations(global.view, annotations),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const view = global.view;
|
|
78
105
|
`;
|
|
79
106
|
|
|
80
|
-
const formattedFileContent = prettier.format(fileContent, { parser: 'babel' });
|
|
107
|
+
const formattedFileContent = prettier.format(fileContent, { parser: 'babel-ts' });
|
|
81
108
|
|
|
82
109
|
fs.writeFileSync(storybookRequiresLocation, formattedFileContent, {
|
|
83
110
|
encoding: 'utf8',
|
|
@@ -88,16 +115,3 @@ function generate({ configPath, absolute = false, useJs = false }) {
|
|
|
88
115
|
module.exports = {
|
|
89
116
|
generate,
|
|
90
117
|
};
|
|
91
|
-
|
|
92
|
-
// TODO evaluate if this is needed
|
|
93
|
-
// if (import.meta.webpackHot) {
|
|
94
|
-
// import.meta.webpackHot.accept('./{{storiesFilename}}', () => {
|
|
95
|
-
// // importFn has changed so we need to patch the new one in
|
|
96
|
-
// preview.onStoriesChanged({ importFn });
|
|
97
|
-
// });
|
|
98
|
-
|
|
99
|
-
// import.meta.webpackHot.accept([{{#each previewAnnotations}}'{{this}}',{{/each}}], () => {
|
|
100
|
-
// // getProjectAnnotations has changed so we need to patch the new one in
|
|
101
|
-
// preview.onGetProjectAnnotationsChanged({ getProjectAnnotations });
|
|
102
|
-
// });
|
|
103
|
-
// }
|