@player-ui/storybook 0.0.1-next.11 → 0.0.1-next.14

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.cjs.js CHANGED
@@ -540,19 +540,27 @@ const PlayerRenderContext = React__default["default"].createContext({
540
540
  const StorybookControlsContext = React__default["default"].createContext({
541
541
  controls: {}
542
542
  });
543
+ const PlayerOptionsContext = React__default["default"].createContext({ options: {} });
543
544
  const LocalPlayerStory = (props) => {
544
545
  var _a, _b;
545
546
  let flow = useEditorFlow(props.flow);
546
547
  const renderContext = React__default["default"].useContext(PlayerRenderContext);
547
548
  const pluginContext = React__default["default"].useContext(WebPlayerPluginContext);
548
549
  const controlsContext = React__default["default"].useContext(StorybookControlsContext);
550
+ const optionsContext = React__default["default"].useContext(PlayerOptionsContext);
551
+ const options = __spreadValues({}, optionsContext == null ? void 0 : optionsContext.options);
549
552
  const stateActions = useStateActions(addons__default["default"].getChannel());
550
553
  const plugins = (_b = (_a = props.webPlugins) != null ? _a : pluginContext == null ? void 0 : pluginContext.plugins) != null ? _b : [];
551
554
  const [playerState, setPlayerState] = React__default["default"].useState("not-started");
552
555
  const wp = React__default["default"].useMemo(() => {
553
- return new react$1.WebPlayer({
554
- plugins: [new StorybookPlayerPlugin(stateActions), ...plugins]
555
- });
556
+ var _a2;
557
+ return new react$1.WebPlayer(__spreadProps(__spreadValues({}, options), {
558
+ plugins: [
559
+ new StorybookPlayerPlugin(stateActions),
560
+ ...plugins,
561
+ ...(_a2 = options == null ? void 0 : options.plugins) != null ? _a2 : []
562
+ ]
563
+ }));
556
564
  }, [plugins]);
557
565
  const startFlow = () => {
558
566
  setPlayerState("in-progress");
@@ -620,13 +628,17 @@ function wrapInLazy(Component, flowFactory, other) {
620
628
  return React__default["default"].lazy(asPlayer);
621
629
  }
622
630
  const PlayerStory = (props) => {
623
- const _a = props, { flow, storybookControls } = _a, other = __objRest(_a, ["flow", "storybookControls"]);
631
+ const _a = props, { flow, storybookControls, options } = _a, other = __objRest(_a, ["flow", "storybookControls", "options"]);
624
632
  const MockComp = React__default["default"].useMemo(() => wrapInLazy(LocalPlayerStory, flow, other), []);
625
633
  return /* @__PURE__ */ React__default["default"].createElement("div", null, /* @__PURE__ */ React__default["default"].createElement(react.ChakraProvider, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Suspense, {
626
634
  fallback: /* @__PURE__ */ React__default["default"].createElement(react.Spinner, null)
627
635
  }, /* @__PURE__ */ React__default["default"].createElement(StorybookControlsContext.Provider, {
628
636
  value: __spreadValues({}, storybookControls)
629
- }, /* @__PURE__ */ React__default["default"].createElement(MockComp, null)))));
637
+ }, /* @__PURE__ */ React__default["default"].createElement(PlayerOptionsContext.Provider, {
638
+ value: {
639
+ options
640
+ }
641
+ }, /* @__PURE__ */ React__default["default"].createElement(MockComp, null)), " "))));
630
642
  };
631
643
 
632
644
  const PlayerDecorator = (story, ctx) => {
@@ -651,6 +663,7 @@ const PlayerDecorator = (story, ctx) => {
651
663
  };
652
664
 
653
665
  exports.PlayerDecorator = PlayerDecorator;
666
+ exports.PlayerOptionsContext = PlayerOptionsContext;
654
667
  exports.PlayerRenderContext = PlayerRenderContext;
655
668
  exports.PlayerStory = PlayerStory;
656
669
  exports.StorybookControlsContext = StorybookControlsContext;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DecoratorFn } from '@storybook/react';
2
2
  import React from 'react';
3
- import { WebPlayerPlugin, Flow } from '@player-ui/react';
3
+ import { WebPlayerPlugin, Flow, WebPlayerOptions } from '@player-ui/react';
4
4
 
5
5
  /** register all the storybook addons */
6
6
  declare function register(): void;
@@ -33,7 +33,7 @@ declare type RenderTarget = {
33
33
  };
34
34
 
35
35
  declare const WebPlayerPluginContext: React.Context<{
36
- /** Plugins to use for the player */
36
+ /** Web plugins to load into Player */
37
37
  plugins?: WebPlayerPlugin[] | undefined;
38
38
  }>;
39
39
  declare const PlayerRenderContext: React.Context<RenderTarget>;
@@ -41,6 +41,10 @@ declare const StorybookControlsContext: React.Context<{
41
41
  /** any storybook controls to include */
42
42
  controls?: Flow['data'];
43
43
  }>;
44
+ declare const PlayerOptionsContext: React.Context<{
45
+ /** these are options such as suspend, or plugins */
46
+ options?: WebPlayerOptions | undefined;
47
+ }>;
44
48
  declare type Mock = Record<string, unknown>;
45
49
  declare type MockFactory = () => Mock;
46
50
  declare type MockFactoryOrPromise = MockFactory | Mock;
@@ -51,6 +55,8 @@ interface PlayerStoryProps {
51
55
  data?: Flow['data'];
52
56
  /** props from storybook controls */
53
57
  storybookControls?: Flow['data'];
58
+ /** options, like suspend and plugins */
59
+ options?: WebPlayerOptions;
54
60
  }
55
61
  /**
56
62
  * Takes an initial flow and renders it as a story in storybook.
@@ -58,4 +64,4 @@ interface PlayerStoryProps {
58
64
  */
59
65
  declare const PlayerStory: (props: PlayerStoryProps) => JSX.Element;
60
66
 
61
- export { PlayerDecorator, PlayerRenderContext, PlayerStory, PlayerStoryProps, StorybookControlsContext, WebPlayerPluginContext, register };
67
+ export { PlayerDecorator, PlayerOptionsContext, PlayerRenderContext, PlayerStory, PlayerStoryProps, StorybookControlsContext, WebPlayerPluginContext, register };
package/dist/index.esm.js CHANGED
@@ -529,19 +529,27 @@ const PlayerRenderContext = React.createContext({
529
529
  const StorybookControlsContext = React.createContext({
530
530
  controls: {}
531
531
  });
532
+ const PlayerOptionsContext = React.createContext({ options: {} });
532
533
  const LocalPlayerStory = (props) => {
533
534
  var _a, _b;
534
535
  let flow = useEditorFlow(props.flow);
535
536
  const renderContext = React.useContext(PlayerRenderContext);
536
537
  const pluginContext = React.useContext(WebPlayerPluginContext);
537
538
  const controlsContext = React.useContext(StorybookControlsContext);
539
+ const optionsContext = React.useContext(PlayerOptionsContext);
540
+ const options = __spreadValues({}, optionsContext == null ? void 0 : optionsContext.options);
538
541
  const stateActions = useStateActions(addons.getChannel());
539
542
  const plugins = (_b = (_a = props.webPlugins) != null ? _a : pluginContext == null ? void 0 : pluginContext.plugins) != null ? _b : [];
540
543
  const [playerState, setPlayerState] = React.useState("not-started");
541
544
  const wp = React.useMemo(() => {
542
- return new WebPlayer({
543
- plugins: [new StorybookPlayerPlugin(stateActions), ...plugins]
544
- });
545
+ var _a2;
546
+ return new WebPlayer(__spreadProps(__spreadValues({}, options), {
547
+ plugins: [
548
+ new StorybookPlayerPlugin(stateActions),
549
+ ...plugins,
550
+ ...(_a2 = options == null ? void 0 : options.plugins) != null ? _a2 : []
551
+ ]
552
+ }));
545
553
  }, [plugins]);
546
554
  const startFlow = () => {
547
555
  setPlayerState("in-progress");
@@ -609,13 +617,17 @@ function wrapInLazy(Component, flowFactory, other) {
609
617
  return React.lazy(asPlayer);
610
618
  }
611
619
  const PlayerStory = (props) => {
612
- const _a = props, { flow, storybookControls } = _a, other = __objRest(_a, ["flow", "storybookControls"]);
620
+ const _a = props, { flow, storybookControls, options } = _a, other = __objRest(_a, ["flow", "storybookControls", "options"]);
613
621
  const MockComp = React.useMemo(() => wrapInLazy(LocalPlayerStory, flow, other), []);
614
622
  return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(ChakraProvider, null, /* @__PURE__ */ React.createElement(React.Suspense, {
615
623
  fallback: /* @__PURE__ */ React.createElement(Spinner, null)
616
624
  }, /* @__PURE__ */ React.createElement(StorybookControlsContext.Provider, {
617
625
  value: __spreadValues({}, storybookControls)
618
- }, /* @__PURE__ */ React.createElement(MockComp, null)))));
626
+ }, /* @__PURE__ */ React.createElement(PlayerOptionsContext.Provider, {
627
+ value: {
628
+ options
629
+ }
630
+ }, /* @__PURE__ */ React.createElement(MockComp, null)), " "))));
619
631
  };
620
632
 
621
633
  const PlayerDecorator = (story, ctx) => {
@@ -639,5 +651,5 @@ const PlayerDecorator = (story, ctx) => {
639
651
  }, story()));
640
652
  };
641
653
 
642
- export { PlayerDecorator, PlayerRenderContext, PlayerStory, StorybookControlsContext, WebPlayerPluginContext, register };
654
+ export { PlayerDecorator, PlayerOptionsContext, PlayerRenderContext, PlayerStory, StorybookControlsContext, WebPlayerPluginContext, register };
643
655
  //# sourceMappingURL=index.esm.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@player-ui/storybook",
3
- "version": "0.0.1-next.11",
3
+ "version": "0.0.1-next.14",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"
@@ -11,8 +11,8 @@
11
11
  "@storybook/addon-docs": "^6.4.15",
12
12
  "react": "^17.0.2",
13
13
  "@types/react": "^17.0.25",
14
- "@player-ui/react": "0.0.1-next.11",
15
- "@player-ui/make-flow": "0.0.1-next.11"
14
+ "@player-ui/react": "0.0.1-next.14",
15
+ "@player-ui/make-flow": "0.0.1-next.14"
16
16
  },
17
17
  "dependencies": {
18
18
  "@monaco-editor/react": "^4.3.1",
@@ -28,7 +28,7 @@
28
28
  "dequal": "^2.0.2",
29
29
  "ts-debounce": "^4.0.0",
30
30
  "uuid": "^8.3.2",
31
- "@player-ui/metrics-plugin-react": "0.0.1-next.11",
31
+ "@player-ui/metrics-plugin-react": "0.0.1-next.14",
32
32
  "@babel/runtime": "7.15.4"
33
33
  },
34
34
  "main": "dist/index.cjs.js",
@@ -1,5 +1,10 @@
1
1
  import React from 'react';
2
- import type { WebPlayerPlugin, PlayerFlowStatus, Flow } from '@player-ui/react';
2
+ import type {
3
+ WebPlayerPlugin,
4
+ PlayerFlowStatus,
5
+ Flow,
6
+ WebPlayerOptions,
7
+ } from '@player-ui/react';
3
8
  import { WebPlayer } from '@player-ui/react';
4
9
  import { ChakraProvider, Spinner } from '@chakra-ui/react';
5
10
  import { makeFlow } from '@player-ui/make-flow';
@@ -15,12 +20,12 @@ interface LocalPlayerStory {
15
20
  /** the mock to load */
16
21
  flow: Flow;
17
22
 
18
- /** plugins to the player */
23
+ /** Web plugins to load into Player */
19
24
  webPlugins?: Array<WebPlayerPlugin>;
20
25
  }
21
26
 
22
27
  export const WebPlayerPluginContext = React.createContext<{
23
- /** Plugins to use for the player */
28
+ /** Web plugins to load into Player */
24
29
  plugins?: Array<WebPlayerPlugin>;
25
30
  }>({ plugins: [] });
26
31
 
@@ -35,6 +40,11 @@ export const StorybookControlsContext = React.createContext<{
35
40
  controls: {},
36
41
  });
37
42
 
43
+ export const PlayerOptionsContext = React.createContext<{
44
+ /** these are options such as suspend, or plugins */
45
+ options?: WebPlayerOptions;
46
+ }>({ options: {} });
47
+
38
48
  /** A component to render a player + flow */
39
49
  const LocalPlayerStory = (props: LocalPlayerStory) => {
40
50
  let flow = useEditorFlow(props.flow);
@@ -42,6 +52,8 @@ const LocalPlayerStory = (props: LocalPlayerStory) => {
42
52
  const renderContext = React.useContext(PlayerRenderContext);
43
53
  const pluginContext = React.useContext(WebPlayerPluginContext);
44
54
  const controlsContext = React.useContext(StorybookControlsContext);
55
+ const optionsContext = React.useContext(PlayerOptionsContext);
56
+ const options = { ...optionsContext?.options };
45
57
  const stateActions = useStateActions(addons.getChannel());
46
58
  const plugins = props.webPlugins ?? pluginContext?.plugins ?? [];
47
59
  const [playerState, setPlayerState] =
@@ -49,7 +61,12 @@ const LocalPlayerStory = (props: LocalPlayerStory) => {
49
61
 
50
62
  const wp = React.useMemo(() => {
51
63
  return new WebPlayer({
52
- plugins: [new StorybookPlayerPlugin(stateActions), ...plugins],
64
+ ...options,
65
+ plugins: [
66
+ new StorybookPlayerPlugin(stateActions),
67
+ ...plugins,
68
+ ...(options?.plugins ?? []),
69
+ ],
53
70
  });
54
71
  }, [plugins]);
55
72
 
@@ -167,6 +184,8 @@ export interface PlayerStoryProps {
167
184
  data?: Flow['data'];
168
185
  /** props from storybook controls */
169
186
  storybookControls?: Flow['data'];
187
+ /** options, like suspend and plugins */
188
+ options?: WebPlayerOptions;
170
189
  }
171
190
 
172
191
  /**
@@ -174,7 +193,8 @@ export interface PlayerStoryProps {
174
193
  * This handles all of the wiring of the mock into the flow editor, events, etc
175
194
  */
176
195
  export const PlayerStory = (props: PlayerStoryProps) => {
177
- const { flow, storybookControls, ...other } = props;
196
+ const { flow, storybookControls, options, ...other } = props;
197
+
178
198
  const MockComp = React.useMemo(
179
199
  () => wrapInLazy(LocalPlayerStory, flow, other),
180
200
  []
@@ -189,7 +209,13 @@ export const PlayerStory = (props: PlayerStoryProps) => {
189
209
  ...storybookControls,
190
210
  }}
191
211
  >
192
- <MockComp />
212
+ <PlayerOptionsContext.Provider
213
+ value={{
214
+ options,
215
+ }}
216
+ >
217
+ <MockComp />
218
+ </PlayerOptionsContext.Provider>{' '}
193
219
  </StorybookControlsContext.Provider>
194
220
  </React.Suspense>
195
221
  </ChakraProvider>