@storybook/react-native 7.6.7-alpha.1 → 7.6.9-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/V6.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { P as Params, R as ReactNativeFramework } from './View-acca1d49.js';
3
- export { C as ComponentMeta, c as ComponentStory, a as ComponentStoryFn, b as ComponentStoryObj, M as Meta, f as Story, d as StoryFn, S as StoryFnReactReturnType, e as StoryObj } from './View-acca1d49.js';
2
+ import { h as Params, b as ReactNativeRenderer } from './View-63944515.js';
3
+ export { D as Decorator, L as Loadable, e as Loader, M as Meta, g as Preview, P as PreviewError, a as RenderStoryFunction, R as RequireContext, f as StoryContext, c as StoryFn, S as StoryFnReactReturnType, d as StoryObj } from './View-63944515.js';
4
4
  import { ClientApi } from '@storybook/preview-api';
5
- import { b as Addon_StoryApi } from './index.d-82fc9196.js';
6
- export { a as ArgTypes, A as Args, P as Parameters, S as StoryContext } from './index.d-82fc9196.js';
5
+ import { b as Addon_StoryApi } from './index.d-c716d0d7.js';
6
+ export { a as ArgTypes, A as Args, P as Parameters, R as RenderContext, S as StrictArgs } from './index.d-c716d0d7.js';
7
7
  import { ReactNode } from 'react';
8
8
  export { Theme, darkTheme, theme } from '@storybook/react-native-theming';
9
9
  import '@storybook/csf';
10
10
  import '@storybook/preview-web';
11
+ import 'type-fest';
11
12
  import '@storybook/channels';
12
13
 
13
14
  declare const configure: (loadable: any, m: {
@@ -16,7 +17,7 @@ declare const configure: (loadable: any, m: {
16
17
  };
17
18
  }) => void;
18
19
 
19
- type C = ClientApi<ReactNativeFramework>;
20
+ type C = ClientApi<ReactNativeRenderer>;
20
21
  declare const addDecorator: C['addDecorator'];
21
22
  declare const addParameters: C['addParameters'];
22
23
  declare const addArgsEnhancer: C['addArgsEnhancer'];
@@ -25,4 +26,4 @@ declare const raw: C['raw'];
25
26
  declare const storiesOf: (kind: string, m: any) => Addon_StoryApi<ReactNode>;
26
27
  declare const getStorybookUI: (params?: Partial<Params>) => () => react_jsx_runtime.JSX.Element;
27
28
 
28
- export { ReactNativeFramework, addArgTypesEnhancer, addArgsEnhancer, addDecorator, addParameters, configure, getStorybookUI, raw, storiesOf };
29
+ export { ReactNativeRenderer, addArgTypesEnhancer, addArgsEnhancer, addDecorator, addParameters, configure, getStorybookUI, raw, storiesOf };
package/dist/V6.js CHANGED
@@ -72,16 +72,17 @@ __export(V6_exports, {
72
72
  module.exports = __toCommonJS(V6_exports);
73
73
 
74
74
  // src/StartV6.tsx
75
- var import_channels = require("@storybook/channels");
76
- var import_core_events2 = __toESM(require("@storybook/core-events"));
75
+ var import_channels2 = require("@storybook/channels");
76
+ var import_core_events3 = __toESM(require("@storybook/core-events"));
77
77
  var import_global = require("@storybook/global");
78
78
  var import_manager_api3 = require("@storybook/manager-api");
79
- var import_preview_api = require("@storybook/preview-api");
79
+ var import_preview_api3 = require("@storybook/preview-api");
80
80
  var import_preview_web = require("@storybook/preview-web");
81
81
 
82
82
  // src/View.tsx
83
83
  var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"));
84
84
  var import_csf = require("@storybook/csf");
85
+ var import_preview_api2 = require("@storybook/preview-api");
85
86
  var import_manager_api2 = require("@storybook/manager-api");
86
87
  var import_react_native_theming12 = require("@storybook/react-native-theming");
87
88
  var import_react16 = require("react");
@@ -546,17 +547,16 @@ var createStore = () => {
546
547
  };
547
548
  const mountDependencies = (atom2, atomState, prevDependencies) => {
548
549
  const depSet = new Set(atomState.d.keys());
550
+ const maybeUnmountAtomSet = /* @__PURE__ */ new Set();
549
551
  prevDependencies == null ? void 0 : prevDependencies.forEach((_, a) => {
550
552
  if (depSet.has(a)) {
551
553
  depSet.delete(a);
552
554
  return;
553
555
  }
556
+ maybeUnmountAtomSet.add(a);
554
557
  const mounted = mountedMap.get(a);
555
558
  if (mounted) {
556
559
  mounted.t.delete(atom2);
557
- if (canUnmountAtom(a, mounted)) {
558
- unmountAtom(a);
559
- }
560
560
  }
561
561
  });
562
562
  depSet.forEach((a) => {
@@ -567,6 +567,12 @@ var createStore = () => {
567
567
  mountAtom(a, atom2);
568
568
  }
569
569
  });
570
+ maybeUnmountAtomSet.forEach((a) => {
571
+ const mounted = mountedMap.get(a);
572
+ if (mounted && canUnmountAtom(a, mounted)) {
573
+ unmountAtom(a);
574
+ }
575
+ });
570
576
  };
571
577
  const flushPending = () => {
572
578
  let flushed;
@@ -666,11 +672,6 @@ if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
666
672
  }
667
673
  var getDefaultStore = () => {
668
674
  if (!defaultStore) {
669
- if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production" && globalThis.__NUMBER_OF_JOTAI_INSTANCES__ !== 1) {
670
- console.warn(
671
- "Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044"
672
- );
673
- }
674
675
  defaultStore = createStore();
675
676
  }
676
677
  return defaultStore;
@@ -988,6 +989,7 @@ var findFirstChildStory = (story) => {
988
989
  };
989
990
 
990
991
  // src/components/StoryListView/StoryListView.tsx
992
+ var import_preview_api = require("@storybook/preview-api");
991
993
  var import_jsx_runtime2 = require("react/jsx-runtime");
992
994
  var SectionHeaderText = import_react_native_theming.styled.Text(({ theme: theme3 }) => ({
993
995
  fontSize: theme3.storyList.fontSize,
@@ -1202,7 +1204,8 @@ var StoryListView = ({ storyIndex }) => {
1202
1204
  setData(filterNestedStories(originalData, query));
1203
1205
  };
1204
1206
  const changeStory = (storyId) => {
1205
- global.__STORYBOOK_ADDONS_CHANNEL__.emit(import_core_events.default.SET_CURRENT_STORY, { storyId });
1207
+ const channel = import_preview_api.addons.getChannel();
1208
+ channel.emit(import_core_events.default.SET_CURRENT_STORY, { storyId });
1206
1209
  };
1207
1210
  const renderItem = import_react3.default.useCallback(({ item }) => {
1208
1211
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RenderItem, { item, changeStory });
@@ -1947,8 +1950,57 @@ var OnDeviceUI = ({
1947
1950
  var OnDeviceUI_default = import_react15.default.memo(OnDeviceUI);
1948
1951
 
1949
1952
  // src/View.tsx
1953
+ var import_channels = require("@storybook/channels");
1954
+ var import_core_events2 = __toESM(require("@storybook/core-events"));
1950
1955
  var import_deepmerge = __toESM(require("deepmerge"));
1951
1956
  var import_react_native16 = require("react-native");
1957
+
1958
+ // src/rn-host-detect.js
1959
+ function getByRemoteConfig(hostname) {
1960
+ var remoteModuleConfig = window?.__fbBatchedBridgeConfig?.remoteModuleConfig;
1961
+ if (!Array.isArray(remoteModuleConfig) || hostname !== "localhost" && hostname !== "127.0.0.1") {
1962
+ return { hostname, passed: false };
1963
+ }
1964
+ var constants = (remoteModuleConfig.find(getConstants) || [])[1];
1965
+ if (constants) {
1966
+ var serverHost = constants.ServerHost || hostname;
1967
+ return { hostname: serverHost.split(":")[0], passed: true };
1968
+ }
1969
+ return { hostname, passed: false };
1970
+ }
1971
+ function getConstants(config) {
1972
+ return config && (config[0] === "AndroidConstants" || config[0] === "PlatformConstants");
1973
+ }
1974
+ function getByRNRequirePolyfill(hostname) {
1975
+ var NativeModules;
1976
+ var PlatformConstants;
1977
+ var AndroidConstants;
1978
+ if (typeof window === "undefined" || !window.__DEV__ || typeof window.require !== "function" || // RN >= 0.56
1979
+ // TODO: Get NativeModules for RN >= 0.56
1980
+ window.require.name === "metroRequire") {
1981
+ return hostname;
1982
+ }
1983
+ NativeModules = window.require("NativeModules");
1984
+ if (!NativeModules || !NativeModules.PlatformConstants && !NativeModules.AndroidConstants) {
1985
+ return hostname;
1986
+ }
1987
+ PlatformConstants = NativeModules.PlatformConstants;
1988
+ AndroidConstants = NativeModules.AndroidConstants;
1989
+ var serverHost = (PlatformConstants ? PlatformConstants.ServerHost : AndroidConstants.ServerHost) || hostname;
1990
+ return serverHost.split(":")[0];
1991
+ }
1992
+ function getHost(hostname) {
1993
+ if (typeof __fbBatchedBridge !== "object" || hostname !== "localhost" && hostname !== "127.0.0.1") {
1994
+ return hostname;
1995
+ }
1996
+ var result = getByRemoteConfig(hostname);
1997
+ if (result.passed) {
1998
+ return result.hostname;
1999
+ }
2000
+ return getByRNRequirePolyfill(hostname);
2001
+ }
2002
+
2003
+ // src/View.tsx
1952
2004
  var import_jsx_runtime16 = require("react/jsx-runtime");
1953
2005
  var STORAGE_KEY = "lastOpenedStory";
1954
2006
  var View10 = class {
@@ -1996,25 +2048,33 @@ var View10 = class {
1996
2048
  }
1997
2049
  return { storySpecifier: "*", viewMode: "story" };
1998
2050
  };
1999
- // _getServerChannel = (params: Partial<Params> = {}) => {
2000
- // const host = getHost(params.host || 'localhost');
2001
- // const port = `:${params.port || 7007}`;
2002
- // const query = params.query || '';
2003
- // const websocketType = params.secured ? 'wss' : 'ws';
2004
- // const url = `${websocketType}://${host}${port}/${query}`;
2005
- // return createWebSocketChannel({
2006
- // url,
2007
- // async: true,
2008
- // onError: async () => {},
2009
- // });
2010
- // };
2051
+ _getServerChannel = (params = {}) => {
2052
+ const host = getHost(params.host || "localhost");
2053
+ const port = `:${params.port || 7007}`;
2054
+ const query = params.query || "";
2055
+ const websocketType = params.secured ? "wss" : "ws";
2056
+ const url = `${websocketType}://${host}${port}/${query}`;
2057
+ return (0, import_channels.createWebSocketChannel)({
2058
+ url,
2059
+ async: true,
2060
+ onError: async () => {
2061
+ }
2062
+ });
2063
+ };
2011
2064
  getStorybookUI = (params = {}) => {
2012
- const {
2013
- shouldPersistSelection = true,
2014
- onDeviceUI = true
2015
- /* enableWebsockets = false */
2016
- } = params;
2065
+ const { shouldPersistSelection = true, onDeviceUI = true, enableWebsockets = false } = params;
2017
2066
  const initialStory = this._getInitialStory(params);
2067
+ if (enableWebsockets) {
2068
+ console.log("websockets enabled");
2069
+ const channel = this._getServerChannel(params);
2070
+ import_manager_api2.addons.setChannel(channel);
2071
+ import_preview_api2.addons.setChannel(channel);
2072
+ this._channel = channel;
2073
+ this._preview.channel = channel;
2074
+ this._preview.setupListeners();
2075
+ channel.emit(import_core_events2.default.CHANNEL_CREATED);
2076
+ this._preview.initializeWithStoryIndex(this._storyIndex);
2077
+ }
2018
2078
  import_manager_api2.addons.loadAddons({
2019
2079
  store: () => ({
2020
2080
  fromId: (id) => this._preview.storyStore.getStoryContext(this._preview.storyStore.fromId(id)),
@@ -2143,10 +2203,10 @@ var render = (args, context) => {
2143
2203
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Component, { ...args });
2144
2204
  };
2145
2205
  function start() {
2146
- const channel = new import_channels.Channel({ async: true });
2206
+ const channel = new import_channels2.Channel({ async: true });
2147
2207
  import_manager_api3.addons.setChannel(channel);
2148
- channel.emit(import_core_events2.default.CHANNEL_CREATED);
2149
- const clientApi2 = import_global.global?.__STORYBOOK_CLIENT_API__ || new import_preview_api.ClientApi();
2208
+ channel.emit(import_core_events3.default.CHANNEL_CREATED);
2209
+ const clientApi2 = import_global.global?.__STORYBOOK_CLIENT_API__ || new import_preview_api3.ClientApi();
2150
2210
  const previewView = {
2151
2211
  prepareForStory: () => {
2152
2212
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_jsx_runtime17.Fragment, {});
@@ -2188,7 +2248,7 @@ function start() {
2188
2248
  import_global.global.__STORYBOOK_PREVIEW__ = preview;
2189
2249
  import_global.global.__STORYBOOK_STORY_STORE__ = preview.storyStore;
2190
2250
  }
2191
- (0, import_preview_api.setGlobalRender)(render);
2251
+ (0, import_preview_api3.setGlobalRender)(render);
2192
2252
  let initialized = false;
2193
2253
  function onStoriesChanged() {
2194
2254
  const storyIndex = clientApi2.getStoryIndex();
@@ -2198,7 +2258,7 @@ function start() {
2198
2258
  const view2 = new View10(preview, channel);
2199
2259
  return {
2200
2260
  view: view2,
2201
- forceReRender: () => channel.emit(import_core_events2.default.FORCE_RE_RENDER),
2261
+ forceReRender: () => channel.emit(import_core_events3.default.FORCE_RE_RENDER),
2202
2262
  clientApi: clientApi2,
2203
2263
  preview,
2204
2264
  // This gets called each time the user calls configure (i.e. once per HMR)
@@ -0,0 +1,111 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Renderer, StoryContext as StoryContext$2 } from '@storybook/csf';
3
+ import { PreviewWithSelection } from '@storybook/preview-web';
4
+ import { Theme } from '@storybook/react-native-theming';
5
+ import { L as LoaderFunction, R as RenderContext, A as Args, C as ComponentAnnotations, c as AnnotatedStoryFn, d as ArgsStoryFn, e as ArgsFromMeta, f as StoryAnnotations, S as StrictArgs, D as DecoratorFunction, g as StoryContext$1, h as ProjectAnnotations, i as StoryIndex } from './index.d-c716d0d7.js';
6
+ import { ComponentType, ComponentProps } from 'react';
7
+ import { Simplify, SetOptional } from 'type-fest';
8
+ import { Channel } from '@storybook/channels';
9
+
10
+ interface PreviewError {
11
+ message?: string;
12
+ stack?: string;
13
+ }
14
+ interface RequireContext {
15
+ keys: () => string[];
16
+ (id: string): any;
17
+ resolve(id: string): string;
18
+ }
19
+ type Loadable = RequireContext | RequireContext[] | LoaderFunction;
20
+
21
+ type RenderStoryFunction = (context: RenderContext) => void;
22
+ type StoryFnReactReturnType = JSX.Element;
23
+ interface ReactNativeRenderer extends Renderer {
24
+ component: ComponentType<any>;
25
+ storyResult: StoryFnReactReturnType;
26
+ }
27
+
28
+ /**
29
+ * Metadata to configure the stories for a component.
30
+ *
31
+ * @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
32
+ */
33
+ type Meta<TCmpOrArgs = Args> = [TCmpOrArgs] extends [ComponentType<any>] ? ComponentAnnotations<ReactNativeRenderer, ComponentProps<TCmpOrArgs>> : ComponentAnnotations<ReactNativeRenderer, TCmpOrArgs>;
34
+ /**
35
+ * Story function that represents a CSFv2 component example.
36
+ *
37
+ * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
38
+ */
39
+ type StoryFn<TCmpOrArgs = Args> = [TCmpOrArgs] extends [ComponentType<any>] ? AnnotatedStoryFn<ReactNativeRenderer, ComponentProps<TCmpOrArgs>> : AnnotatedStoryFn<ReactNativeRenderer, TCmpOrArgs>;
40
+ /**
41
+ * Story object that represents a CSFv3 component example.
42
+ *
43
+ * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
44
+ */
45
+ type StoryObj<TMetaOrCmpOrArgs = Args> = [TMetaOrCmpOrArgs] extends [
46
+ {
47
+ render?: ArgsStoryFn<ReactNativeRenderer, any>;
48
+ component?: infer Component;
49
+ args?: infer DefaultArgs;
50
+ }
51
+ ] ? Simplify<(Component extends ComponentType<any> ? ComponentProps<Component> : unknown) & ArgsFromMeta<ReactNativeRenderer, TMetaOrCmpOrArgs>> extends infer TArgs ? StoryAnnotations<ReactNativeRenderer, AddMocks<TArgs, DefaultArgs>, SetOptional<TArgs, keyof TArgs & keyof DefaultArgs>> : never : TMetaOrCmpOrArgs extends ComponentType<any> ? StoryAnnotations<ReactNativeRenderer, ComponentProps<TMetaOrCmpOrArgs>> : StoryAnnotations<ReactNativeRenderer, TMetaOrCmpOrArgs>;
52
+ type AddMocks<TArgs, DefaultArgs> = Simplify<{
53
+ [T in keyof TArgs]: T extends keyof DefaultArgs ? DefaultArgs[T] extends (...args: any) => any & {
54
+ mock: {};
55
+ } ? DefaultArgs[T] : TArgs[T] : TArgs[T];
56
+ }>;
57
+ type Decorator<TArgs = StrictArgs> = DecoratorFunction<ReactNativeRenderer, TArgs>;
58
+ type Loader<TArgs = StrictArgs> = LoaderFunction<ReactNativeRenderer, TArgs>;
59
+ type StoryContext<TArgs = StrictArgs> = StoryContext$1<ReactNativeRenderer, TArgs>;
60
+ type Preview = ProjectAnnotations<ReactNativeRenderer>;
61
+
62
+ type StoryKind = string;
63
+ type StoryName = string;
64
+ type InitialSelection = `${StoryKind}--${StoryName}` | {
65
+ /**
66
+ * Kind is the default export name or the storiesOf("name") name
67
+ */
68
+ kind: StoryKind;
69
+ /**
70
+ * Name is the named export or the .add("name") name
71
+ */
72
+ name: StoryName;
73
+ };
74
+ type DeepPartial<T> = T extends object ? {
75
+ [P in keyof T]?: DeepPartial<T[P]>;
76
+ } : T;
77
+ type Params = {
78
+ onDeviceUI?: boolean;
79
+ enableWebsockets?: boolean;
80
+ query?: string;
81
+ host?: string;
82
+ port?: number;
83
+ secured?: boolean;
84
+ initialSelection?: InitialSelection;
85
+ shouldPersistSelection?: boolean;
86
+ tabOpen?: number;
87
+ isUIHidden?: boolean;
88
+ isSplitPanelVisible?: boolean;
89
+ shouldDisableKeyboardAvoidingView?: boolean;
90
+ keyboardAvoidingViewVerticalOffset?: number;
91
+ theme: DeepPartial<Theme>;
92
+ };
93
+ declare class View {
94
+ _storyIndex: StoryIndex;
95
+ _setStory: (story: StoryContext$2<ReactNativeRenderer>) => void;
96
+ _forceRerender: () => void;
97
+ _ready: boolean;
98
+ _preview: PreviewWithSelection<ReactNativeRenderer>;
99
+ _asyncStorageStoryId: string;
100
+ _webUrl: string;
101
+ _channel: Channel;
102
+ constructor(preview: PreviewWithSelection<ReactNativeRenderer>, channel: Channel);
103
+ _getInitialStory: ({ initialSelection, shouldPersistSelection, }?: Partial<Params>) => Promise<{
104
+ storySpecifier: string;
105
+ viewMode: string;
106
+ }>;
107
+ _getServerChannel: (params?: Partial<Params>) => Channel;
108
+ getStorybookUI: (params?: Partial<Params>) => () => react_jsx_runtime.JSX.Element;
109
+ }
110
+
111
+ export { Decorator as D, Loadable as L, Meta as M, PreviewError as P, RequireContext as R, StoryFnReactReturnType as S, View as V, RenderStoryFunction as a, ReactNativeRenderer as b, StoryFn as c, StoryObj as d, Loader as e, StoryContext as f, Preview as g, Params as h };