@player-ui/react 0.10.4 → 0.10.5--canary.606.20908

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.
@@ -39,6 +39,7 @@ __export(src_exports, {
39
39
  WebPlayer: () => WebPlayer,
40
40
  buildUrl: () => buildUrl,
41
41
  callOrReturn: () => callOrReturn,
42
+ createPersistentStateMachine: () => createPersistentStateMachine,
42
43
  isEmptyObject: () => isEmptyObject,
43
44
  isFunction: () => isFunction,
44
45
  removeEmptyValuesFromObject: () => removeEmptyValuesFromObject,
@@ -47,7 +48,6 @@ __export(src_exports, {
47
48
  useGetConstant: () => useGetConstant,
48
49
  useGetConstantByType: () => useGetConstantByType,
49
50
  useLogger: () => useLogger,
50
- usePersistentStateMachine: () => usePersistentStateMachine,
51
51
  usePlayer: () => usePlayer,
52
52
  useReactPlayer: () => useReactPlayer,
53
53
  useRequestTime: () => useRequestTime
@@ -412,6 +412,7 @@ var useReactPlayer = (options) => {
412
412
 
413
413
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/managed-player.tsx
414
414
  var import_react7 = __toESM(require("react"));
415
+ var import_shim = require("use-sync-external-store/shim/index.js");
415
416
 
416
417
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/request-time.tsx
417
418
  var import_react6 = require("react");
@@ -463,16 +464,19 @@ var ManagedState = class {
463
464
  constructor({
464
465
  middleware
465
466
  }) {
467
+ /** Add a listener to state changes */
468
+ this.addListener = (callback) => {
469
+ this.callbacks.push(callback);
470
+ return () => {
471
+ this.callbacks = this.callbacks.filter((s) => s !== callback);
472
+ };
473
+ };
474
+ this.getSnapshot = () => {
475
+ return this.state;
476
+ };
466
477
  this.middleware = middleware;
467
478
  this.callbacks = [];
468
479
  }
469
- /** Add a listener to state changes */
470
- addListener(callback) {
471
- this.callbacks.push(callback);
472
- return () => {
473
- this.callbacks = this.callbacks.filter((s) => s !== callback);
474
- };
475
- }
476
480
  /** start the managed flow */
477
481
  start(options) {
478
482
  const initialState = {
@@ -596,53 +600,67 @@ var ManagedState = class {
596
600
  }
597
601
  };
598
602
  var managedPlayerStateMachines = /* @__PURE__ */ new WeakMap();
599
- var usePersistentStateMachine = (options) => {
600
- const keyRef = import_react7.default.useRef({
603
+ function createKey() {
604
+ return {
601
605
  _key: Symbol("managed-player")
602
- });
603
- const managedState = managedPlayerStateMachines.get(keyRef.current) ?? new ManagedState({ middleware: options.middleware });
606
+ };
607
+ }
608
+ var createPersistentStateMachine = (keyRef, middleware) => {
609
+ const managedState = managedPlayerStateMachines.get(keyRef.current) ?? new ManagedState({ middleware });
604
610
  managedPlayerStateMachines.set(keyRef.current, managedState);
605
- const [state, setState] = import_react7.default.useState(managedState.state);
606
- import_react7.default.useEffect(() => {
607
- const unsub = managedState.addListener({
608
- onState: (s) => {
609
- setState(s);
610
- }
611
- });
612
- if (managedState.state === void 0) {
613
- managedState.start(options);
614
- }
615
- return unsub;
616
- }, []);
617
- return { managedState, state };
611
+ return managedState;
618
612
  };
619
613
  var ManagedPlayer = (props) => {
614
+ const keyRef = import_react7.default.useRef(createKey());
620
615
  const { withRequestTime, RequestTimeMetricsPlugin } = useRequestTime();
621
- const { state, managedState } = usePersistentStateMachine({
622
- manager: props.manager,
623
- middleware: { next: withRequestTime },
624
- playerConfig: {
625
- plugins: [...props?.plugins ?? [], RequestTimeMetricsPlugin],
626
- player: props.player
627
- }
616
+ const initialState = createPersistentStateMachine(keyRef, {
617
+ next: withRequestTime
628
618
  });
619
+ const [managedState, setManagedState] = import_react7.default.useState(initialState);
620
+ const wrappedListener = import_react7.default.useCallback(
621
+ (cb) => {
622
+ return managedState.addListener({
623
+ onState(s) {
624
+ cb(s);
625
+ }
626
+ });
627
+ },
628
+ [managedState]
629
+ );
630
+ const state = (0, import_shim.useSyncExternalStore)(wrappedListener, managedState.getSnapshot);
629
631
  import_react7.default.useEffect(() => {
630
632
  if (state?.value === "ended") {
631
- props.onComplete?.(state?.context.result);
633
+ if (props.manager !== state.context.manager) {
634
+ keyRef.current = createKey();
635
+ const newManagedState = createPersistentStateMachine(keyRef, {
636
+ next: withRequestTime
637
+ });
638
+ setManagedState(newManagedState);
639
+ } else {
640
+ props.onComplete?.(state?.context.result);
641
+ }
632
642
  } else if (state?.value === "error") {
633
643
  props.onError?.(state?.context.error);
634
644
  } else if (state?.value === "running") {
635
645
  props.onStartedFlow?.();
646
+ } else if (state === void 0) {
647
+ managedState.start({
648
+ manager: props.manager,
649
+ playerConfig: {
650
+ plugins: [...props?.plugins ?? [], RequestTimeMetricsPlugin],
651
+ player: props.player
652
+ }
653
+ });
636
654
  }
637
655
  }, [state]);
638
656
  import_react7.default.useEffect(() => {
639
657
  return () => {
640
- const playerState = state?.context.reactPlayer.player.getState();
658
+ const playerState = state?.context?.reactPlayer?.player?.getState();
641
659
  if (state?.value === "running" && playerState?.status === "in-progress") {
642
660
  props.manager.terminate?.(playerState.controllers.data.serialize());
643
661
  }
644
662
  };
645
- }, [props.manager, state?.context.reactPlayer.player, state?.value]);
663
+ }, [props.manager, state?.context?.reactPlayer?.player, state?.value]);
646
664
  if (state?.value === "error") {
647
665
  if (props.fallbackComponent) {
648
666
  return /* @__PURE__ */ import_react7.default.createElement(
@@ -678,6 +696,7 @@ var ManagedPlayer = (props) => {
678
696
  WebPlayer,
679
697
  buildUrl,
680
698
  callOrReturn,
699
+ createPersistentStateMachine,
681
700
  isEmptyObject,
682
701
  isFunction,
683
702
  removeEmptyValuesFromObject,
@@ -686,7 +705,6 @@ var ManagedPlayer = (props) => {
686
705
  useGetConstant,
687
706
  useGetConstantByType,
688
707
  useLogger,
689
- usePersistentStateMachine,
690
708
  usePlayer,
691
709
  useReactPlayer,
692
710
  useRequestTime,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/player-context.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-logger.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-asset-props.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/helpers.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/url.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/shared-constants.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/app.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/onupdate-plugin.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/hooks.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/tapstate-plugin.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/managed-player.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/request-time.tsx"],"sourcesContent":["export * from \"@player-ui/player\";\nexport * from \"./player\";\nexport * from \"./hooks\";\nexport * from \"./manager/managed-player\";\nexport * from \"./manager/request-time\";\nexport * from \"./manager/types\";\nexport * from \"./asset\";\nexport * from \"./utils\";\n","/* eslint-disable react/no-this-in-sfc */\nimport React from \"react\";\nimport { SyncWaterfallHook, AsyncParallelHook } from \"tapable-ts\";\nimport { Subscribe, useSubscribedState } from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n Flow,\n View,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport PlayerComp from \"./app\";\nimport OnUpdatePlugin from \"./plugins/onupdate-plugin\";\n\nconst WEB_PLAYER_VERSION = \"__VERSION__\";\nconst COMMIT = \"__GIT_COMMIT__\";\n\nexport interface DevtoolsGlobals {\n /** A global for a plugin to load to Player for devtools */\n __PLAYER_DEVTOOLS_PLUGIN?: {\n new (): ReactPlayerPlugin;\n };\n}\n\nexport type DevtoolsWindow = typeof window & DevtoolsGlobals;\n\nconst _window: DevtoolsWindow | undefined =\n typeof window === \"undefined\" ? undefined : window;\n\nexport interface ReactPlayerInfo {\n /** Version of the running player */\n playerVersion: string;\n\n /** Version of the running reactPlayer */\n reactPlayerVersion: string;\n\n /** Hash of the HEAD commit used to build the current player version */\n playerCommit: string;\n\n /** Hash of the HEAD commit used to build the current reactPlayer version */\n reactPlayerCommit: string;\n}\n\nexport interface ReactPlayerPlugin extends Partial<PlayerPlugin> {\n /** The name of this plugin */\n name: string;\n\n /**\n * Attach listeners to the web-player instance\n */\n applyReact?: (reactPlayer: ReactPlayer) => void;\n}\n\nexport interface ReactPlayerOptions {\n /** A headless player instance to use */\n player?: Player;\n\n /** A set of plugins to apply to this player */\n plugins?: Array<ReactPlayerPlugin>;\n}\n\nexport type ReactPlayerComponentProps = Record<string, unknown>;\n\n/** A Player that renders UI through React */\nexport class ReactPlayer {\n public readonly options: ReactPlayerOptions;\n public readonly player: Player;\n public readonly assetRegistry: AssetRegistryType = new Registry();\n public readonly Component: React.ComponentType<ReactPlayerComponentProps>;\n public readonly hooks = {\n /**\n * A hook to create a React Component to be used for Player, regardless of the current flow state\n */\n webComponent: new SyncWaterfallHook<[React.ComponentType]>(),\n\n /**\n * A hook to create a React Component that's used to render a specific view.\n * It will be called for each view update from the core player.\n * Typically this will just be `Asset`\n */\n playerComponent: new SyncWaterfallHook<\n [React.ComponentType<ReactPlayerProps>]\n >(),\n\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: new AsyncParallelHook<[]>(),\n };\n\n private viewUpdateSubscription = new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n this.options = options ?? {};\n\n const Devtools = _window?.__PLAYER_DEVTOOLS_PLUGIN;\n const onUpdatePlugin = new OnUpdatePlugin(\n this.viewUpdateSubscription.publish,\n );\n\n const plugins = options?.plugins ?? [];\n\n if (Devtools) {\n plugins.push(new Devtools());\n }\n\n const playerPlugins = plugins.filter((p) =>\n Boolean(p.apply),\n ) as PlayerPlugin[];\n\n this.player = options?.player ?? new Player({ plugins: playerPlugins });\n\n plugins.forEach((plugin) => {\n if (plugin.applyReact) {\n plugin.applyReact(this);\n }\n });\n\n onUpdatePlugin.apply(this.player);\n\n this.Component = this.createReactPlayerComponent();\n this.reactPlayerInfo = {\n playerVersion: this.player.getVersion(),\n playerCommit: this.player.getCommit(),\n reactPlayerVersion: WEB_PLAYER_VERSION,\n reactPlayerCommit: COMMIT,\n };\n }\n\n /** Returns the current version of the underlying core Player */\n public getPlayerVersion(): string {\n return this.reactPlayerInfo.playerVersion;\n }\n\n /** Returns the git commit used to build this core Player version */\n public getPlayerCommit(): string {\n return this.reactPlayerInfo.playerCommit;\n }\n\n /** Find instance of [Plugin] that has been registered to the web player */\n public findPlugin<Plugin extends ReactPlayerPlugin>(\n symbol: symbol,\n ): Plugin | undefined {\n return this.options.plugins?.find((el) => el.symbol === symbol) as Plugin;\n }\n\n /** Register and apply [Plugin] if one with the same symbol is not already registered. */\n public registerPlugin(plugin: ReactPlayerPlugin): void {\n if (!plugin.applyReact) return;\n\n plugin.applyReact(this);\n this.options.plugins?.push(plugin);\n }\n\n /** Returns the current version of the running React Player */\n public getReactPlayerVersion(): string {\n return this.reactPlayerInfo.reactPlayerVersion;\n }\n\n /** Returns the git commit used to build the React Player version */\n public getReactPlayerCommit(): string {\n return this.reactPlayerInfo.reactPlayerCommit;\n }\n\n private createReactPlayerComponent(): React.ComponentType<ReactPlayerComponentProps> {\n const BaseComp = this.hooks.webComponent.call(this.createReactComp());\n\n /** Wrap the Error boundary and context provider after the hook call to catch anything wrapped by the hook */\n const ReactPlayerComponent = (props: ReactPlayerComponentProps) => {\n return (\n <ErrorBoundary\n fallbackRender={() => null}\n onError={(err) => {\n const playerState = this.player.getState();\n\n if (playerState.status === \"in-progress\") {\n playerState.fail(err);\n }\n }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...props} />\n </PlayerContext.Provider>\n </ErrorBoundary>\n );\n };\n\n return ReactPlayerComponent;\n }\n\n private createReactComp(): React.ComponentType<ReactPlayerComponentProps> {\n const ActualPlayerComp = this.hooks.playerComponent.call(PlayerComp);\n\n /** the component to use to render the player */\n const WebPlayerComponent = () => {\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n this.viewUpdateSubscription.suspend();\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {view && <ActualPlayerComp view={view} />}\n </AssetContext.Provider>\n );\n };\n\n return WebPlayerComponent;\n }\n\n /**\n * Call this method to force the ReactPlayer to wait for the next view-update before performing the next render.\n * If the `suspense` option is set, this will suspend while an update is pending, otherwise nothing will be rendered.\n */\n public setWaitForNextViewUpdate() {\n const shouldCallResetHook = this.hooks.onBeforeViewReset.isUsed();\n\n return this.viewUpdateSubscription.reset(\n shouldCallResetHook ? this.hooks.onBeforeViewReset.call() : undefined,\n );\n }\n\n public start(flow: Flow): Promise<CompletedState> {\n this.setWaitForNextViewUpdate();\n\n return this.player.start(flow).finally(async () => {\n await this.setWaitForNextViewUpdate();\n });\n }\n}\n\n// For compatibility\nexport const WebPlayer = ReactPlayer;\n","import React from \"react\";\nimport leven from \"leven\";\nimport type { Asset as AssetType, AssetWrapper } from \"@player-ui/player\";\nimport type { Registry } from \"@player-ui/partial-match-registry\";\n\nexport type AssetRegistryType = Registry<React.ComponentType<any>>;\n\nexport interface ContextType {\n /**\n * A registry of Asset -> React Components\n */\n registry?: AssetRegistryType;\n}\n\nexport const AssetContext = React.createContext<ContextType>({});\n\n/**\n * A React Component that looks up an implementation from a registry\n */\nexport const ReactAsset = (\n props: AssetType<string> | AssetWrapper<AssetType<string>>,\n) => {\n const { registry } = React.useContext(AssetContext);\n\n let unwrapped;\n\n if (\"type\" in props && \"id\" in props) {\n unwrapped = props;\n } else if (\"asset\" in props) {\n unwrapped = (props as unknown as AssetWrapper).asset;\n }\n\n if (!unwrapped) {\n throw Error(\n `Cannot determine asset type for props: ${JSON.stringify(props)}`,\n );\n }\n\n if (typeof unwrapped !== \"object\") {\n throw Error(\n `Asset was not an object got (${typeof unwrapped}) instead: ${unwrapped}`,\n );\n }\n\n if (unwrapped.type === undefined) {\n const info =\n unwrapped.id === undefined\n ? JSON.stringify(props)\n : `id: ${unwrapped.id}`;\n throw Error(`Asset is missing type for ${info}`);\n }\n\n if (!registry || registry.isRegistryEmpty()) {\n throw Error(`No asset found in registry. This could happen for one of the following reasons: \\n\n 1. You might have no assets registered or no plugins added to the Player instance. \\n\n 2. You might have mismatching versions of React Asset Registry Context. \\n\n See https://player-ui.github.io/latest/tools/cli#player-dependency-versions-check for tips about how to debug and fix this problem`);\n }\n\n const Impl = registry?.get(unwrapped);\n\n if (!Impl) {\n const matchList: object[] = [];\n\n registry.forEach((asset) => {\n matchList.push(asset.key);\n });\n\n const typeList = matchList.map(\n (match) => JSON.parse(JSON.stringify(match)).type,\n );\n\n const similarType = typeList.reduce((prev, curr) => {\n const next = {\n value: leven(unwrapped.type, curr),\n type: curr,\n };\n\n if (prev !== undefined && prev.value < next.value) {\n return prev;\n }\n\n return next;\n }, undefined);\n\n throw Error(\n `No implementation found for id: ${unwrapped.id} type: ${unwrapped.type}. Did you mean ${similarType.type}? \\n \n Registered Asset matching functions are listed below: \\n\n ${JSON.stringify(matchList)}`,\n );\n }\n\n return <Impl key={unwrapped.id} {...unwrapped} />;\n};\n","import React from \"react\";\nimport type { Player, NavigationFlowViewState } from \"@player-ui/player\";\n\nexport interface PlayerContextType {\n /**\n * An instance of a headless player\n */\n player?: Player;\n\n /** The currently rendered view state */\n viewState?: NavigationFlowViewState;\n}\n\nexport const PlayerContext = React.createContext<PlayerContextType>({});\n\n/**\n * A hook to get the current player\n */\nexport const usePlayer = () => {\n const { player } = React.useContext(PlayerContext);\n\n return player;\n};\n","import type { Logger } from \"@player-ui/player\";\nimport { NoopLogger } from \"@player-ui/player\";\nimport { usePlayer } from \"./player-context\";\n\nconst noopLogger = new NoopLogger();\n\n/**\n * A hook to get the logger instance from the current player\n */\nexport function useLogger(): Logger {\n const player = usePlayer();\n\n return player?.logger ?? noopLogger;\n}\n","import type { Asset } from \"@player-ui/player\";\n\n/** Common props for any dom node */\nexport function useAssetProps(asset: Asset) {\n return {\n id: asset.id,\n \"data-asset-type\": asset.type,\n };\n}\n","/**\n * Trim leading and trailing slashes from string\n */\nexport function trimSlashes(str: string) {\n return str.replace(/^\\/+|\\/+$/g, \"\");\n}\n\n/**\n * Removes any key: value pairs from an object when the value is null or undefined\n */\nexport function removeEmptyValuesFromObject(\n obj: Record<string, any>,\n): Record<string, NonNullable<any>> {\n return Object.keys(obj).reduce(\n (acc, key) => {\n const value = obj[key];\n\n if (value !== null && value !== undefined) {\n acc[key] = value;\n }\n\n return acc;\n },\n {} as Record<string, any>,\n );\n}\n\n/** Check if the object has no keys */\nexport function isEmptyObject(obj: Record<string, unknown>) {\n return Object.keys(obj).length === 0 && obj.constructor === Object;\n}\n\n/** Check if the argument is a function */\nexport function isFunction<ReturnType>(\n maybeFn: ReturnType | ((...args: unknown[]) => ReturnType),\n): maybeFn is (...args: unknown[]) => ReturnType {\n return Boolean(maybeFn instanceof Function || typeof maybeFn === \"function\");\n}\n\n/**\n * Calls function with provided data or returns original value\n */\nexport function callOrReturn<\n ReturnType,\n FnArgs extends Array<unknown> = unknown[],\n FnType = (...args: FnArgs) => ReturnType,\n>(maybeFn: FnType | ReturnType, fnArgs: FnArgs): ReturnType {\n if (isFunction(maybeFn)) {\n return maybeFn(fnArgs) as ReturnType;\n }\n\n return maybeFn as ReturnType;\n}\n","import { isEmptyObject } from \"./helpers\";\n\n/**\n * Combines a URL with any additional parameters\n */\nexport function buildUrl(\n url: string,\n params: Record<string, unknown> = {},\n): string {\n const baseUrl = new URL(url);\n\n if (params && isEmptyObject(params)) {\n return baseUrl.toString();\n }\n\n Object.keys(params).forEach((key) => {\n const value = params[key];\n baseUrl.searchParams.append(key, String(value));\n });\n\n return baseUrl.toString();\n}\n","import { usePlayer } from \"./player-context\";\n\n/** Hook to get a constant under a specific namespace */\nexport function useGetConstantByType(type: string, key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, type);\n}\n\n/** Get a constant under the default namespace */\nexport function useGetConstant(key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, \"constants\");\n}\n","import React from \"react\";\nimport type { View } from \"@player-ui/player\";\nimport { ReactAsset } from \"./asset\";\n\nexport interface ReactPlayerProps {\n /**\n * The Content view object to render\n */\n view: View;\n}\n\n/**\n * The entry for the ReactPlayer's React tree\n */\nconst ReactPlayer = ({ view }: ReactPlayerProps) => {\n return <ReactAsset {...view} />;\n};\n\nexport default ReactPlayer;\n","import type { Player, PlayerPlugin, ViewInstance } from \"@player-ui/player\";\n\nexport type OnUpdateCallback = (update: any) => void;\n\n/**\n * A plugin that listens for view updates and publishes an event for when a view is updated\n */\nexport default class OnUpdatePlugin implements PlayerPlugin {\n name = \"view-update\";\n\n private readonly onUpdateCallback: OnUpdateCallback;\n\n constructor(onUpdate: OnUpdateCallback) {\n this.onUpdateCallback = onUpdate;\n }\n\n apply(player: Player) {\n /** Trigger the callback for the view update */\n const updateTap = (updatedView: any) => {\n this.onUpdateCallback(updatedView);\n };\n\n /** Trigger the callback for the view creation */\n const viewTap = (view: ViewInstance) => {\n view.hooks.onUpdate.tap(this.name, updateTap);\n };\n\n // Attach hooks for any new vc that gets created\n player.hooks.view.tap(this.name, viewTap);\n\n // Attach listeners and publish an update event for a view already in progress\n const currentPlayerState = player.getState();\n\n if (currentPlayerState.status === \"in-progress\") {\n const { currentView } = currentPlayerState.controllers.view;\n\n if (currentView) {\n viewTap(currentView);\n const { lastUpdate } = currentView;\n\n if (lastUpdate) {\n this.onUpdateCallback(lastUpdate);\n }\n }\n }\n }\n}\n","import type { Player, PlayerFlowState } from \"@player-ui/player\";\nimport { NOT_STARTED_STATE } from \"@player-ui/player\";\nimport React from \"react\";\nimport type { ReactPlayerOptions } from \"./player\";\nimport { ReactPlayer } from \"./player\";\nimport { StateTapPlugin } from \"./plugins/tapstate-plugin\";\n\nexport interface UseReactPlayerReturn {\n /** The web-player instance */\n reactPlayer: ReactPlayer;\n /** Player instance */\n player: Player;\n /** The state of Player */\n playerState: PlayerFlowState;\n}\n\n/**\n * The `useReactPlayer` hook is an easy way to integrate the web-player into your React app.\n * Simply supply your config, plugins, and an optional flow, which will be automatically started for you when changed.\n */\nexport const useReactPlayer = (\n options?: ReactPlayerOptions,\n): UseReactPlayerReturn => {\n const [playerState, setPlayerState] =\n React.useState<PlayerFlowState>(NOT_STARTED_STATE);\n\n const reactPlayer = React.useMemo(() => {\n const rp = new ReactPlayer({\n player: options?.player,\n plugins: [\n ...(options?.plugins ?? []),\n new StateTapPlugin(setPlayerState),\n ],\n });\n\n return rp;\n }, []);\n\n const { player } = reactPlayer;\n\n return {\n reactPlayer,\n player,\n playerState,\n };\n};\n","import type { PlayerFlowState, Player } from \"@player-ui/player\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\n/**\n * A plugin to tap into state transition changes and call an arbitrary update function\n */\nexport class StateTapPlugin implements ReactPlayerPlugin {\n name = \"statetap\";\n private callbackFunction: (state: PlayerFlowState) => void;\n\n constructor(callback: (state: PlayerFlowState) => void) {\n this.callbackFunction = callback;\n }\n\n apply(player: Player) {\n player.hooks.state.tap(\"usePlayer\", (newPlayerState: PlayerFlowState) => {\n this.callbackFunction(newPlayerState);\n });\n }\n}\n","import React from \"react\";\nimport type {\n FlowManager,\n ManagedPlayerProps,\n ManagedPlayerState,\n ManagerMiddleware,\n ManagedPlayerContext,\n} from \"./types\";\nimport { useRequestTime } from \"./request-time\";\nimport type { ReactPlayerOptions } from \"../player\";\nimport { ReactPlayer } from \"../player\";\n\n/** noop middleware */\nfunction identityMiddleware<T>(next: Promise<T>) {\n return next;\n}\n\ninterface ManagedPlayerStateKey {\n /** the storage key for the state (outside of the react tree) */\n _key: symbol;\n}\n\nexport interface StateChangeCallback {\n /** Trigger for state changes */\n onState: (s: ManagedPlayerState) => void;\n}\n\n/**\n * An object to store the state of the managed player\n */\nclass ManagedState {\n public state?: ManagedPlayerState;\n private callbacks: Array<StateChangeCallback>;\n private middleware?: ManagerMiddleware;\n\n constructor({\n middleware,\n }: {\n /** middleware to use in the managed player */\n middleware?: ManagerMiddleware;\n }) {\n this.middleware = middleware;\n this.callbacks = [];\n }\n\n /** Add a listener to state changes */\n public addListener(callback: StateChangeCallback): () => void {\n this.callbacks.push(callback);\n\n return () => {\n this.callbacks = this.callbacks.filter((s) => s !== callback);\n };\n }\n\n /** start the managed flow */\n public start(options: {\n /** the flow manager to use */\n manager: FlowManager;\n\n /** the config to use when creating a player */\n playerConfig: ReactPlayerOptions;\n }) {\n const initialState: ManagedPlayerState = {\n value: \"not_started\",\n context: {\n playerConfig: options.playerConfig,\n reactPlayer: new ReactPlayer(options.playerConfig),\n manager: options.manager,\n },\n };\n\n this.setState(initialState);\n\n return this;\n }\n\n /** reset starts from nothing */\n public reset() {\n if (this.state?.value === \"error\") {\n const { playerConfig, manager } = this.state.context;\n this.start({ playerConfig, manager });\n } else {\n throw new Error(\"Flow must be in error state to reset\");\n }\n }\n\n /** restart starts from the last result */\n public restart() {\n if (this.state?.value === \"error\") {\n const { playerConfig, manager, prevResult, reactPlayer } =\n this.state.context;\n this.setState({\n value: \"completed\",\n context: {\n playerConfig,\n manager,\n result: prevResult,\n reactPlayer,\n },\n });\n } else {\n throw new Error(\"Flow must be in error state to restart\");\n }\n }\n\n private async setState(state: ManagedPlayerState) {\n this.state = state;\n this.callbacks.forEach((c) => {\n c.onState(state);\n });\n\n const { manager, reactPlayer, playerConfig } = state.context;\n\n try {\n const nextState = await this.processState(state, {\n manager,\n reactPlayer,\n playerConfig,\n });\n\n if (nextState) {\n this.setState(nextState);\n }\n } catch (e) {\n this.setState({\n value: \"error\",\n context: {\n manager,\n reactPlayer,\n playerConfig,\n error: e as Error,\n },\n });\n }\n }\n\n private async processState(\n state: ManagedPlayerState,\n context: ManagedPlayerContext,\n ): Promise<ManagedPlayerState | undefined> {\n if (state.value === \"not_started\" || state.value === \"completed\") {\n const prevResult =\n state.value === \"completed\" ? state.context.result : undefined;\n\n const middleware = this.middleware?.next ?? identityMiddleware;\n\n return {\n value: \"pending\",\n context: {\n ...context,\n prevResult,\n next: middleware(state.context.manager.next(prevResult)),\n },\n };\n }\n\n if (state.value === \"pending\") {\n const nextResult = await state.context.next;\n\n if (nextResult.done) {\n return {\n value: \"ended\",\n context: {\n ...context,\n result: state.context.prevResult,\n },\n };\n }\n\n return {\n value: \"loaded\",\n context: {\n ...context,\n prevResult: state.context.prevResult,\n flow: nextResult.value,\n },\n };\n }\n\n if (state.value === \"loaded\") {\n return {\n value: \"running\",\n context: {\n ...context,\n flow: state.context.flow,\n prevResult: state.context.prevResult,\n result: state.context.reactPlayer.start(state.context.flow),\n },\n };\n }\n\n if (state.value === \"running\") {\n const result = await state.context.result;\n\n return {\n value: \"completed\",\n context: {\n ...context,\n result,\n },\n };\n }\n }\n}\n\nconst managedPlayerStateMachines = new WeakMap<\n ManagedPlayerStateKey,\n ManagedState\n>();\n\n/** Creates an x-state state machine that persists when this component is no longer renders (due to Suspense) */\nexport const usePersistentStateMachine = (options: {\n /** the flow manager to use */\n manager: FlowManager;\n\n /** Player config */\n playerConfig: ReactPlayerOptions;\n\n /** Any middleware for the manager */\n middleware?: ManagerMiddleware;\n}) => {\n const keyRef = React.useRef<ManagedPlayerStateKey>({\n _key: Symbol(\"managed-player\"),\n });\n\n const managedState =\n managedPlayerStateMachines.get(keyRef.current) ??\n new ManagedState({ middleware: options.middleware });\n managedPlayerStateMachines.set(keyRef.current, managedState);\n const [state, setState] = React.useState(managedState.state);\n\n React.useEffect(() => {\n const unsub = managedState.addListener({\n onState: (s) => {\n setState(s);\n },\n });\n\n if (managedState.state === undefined) {\n managedState.start(options);\n }\n\n return unsub;\n }, []);\n\n return { managedState, state };\n};\n\n/**\n * A ManagedPlayer is a component responsible for orchestrating multi-flow experiences using Player.\n * Provide a valid `FlowManager` to handle fetching the next flow.\n *\n * `suspense` must be enabled to wait for results in flight.\n */\nexport const ManagedPlayer = (props: ManagedPlayerProps) => {\n const { withRequestTime, RequestTimeMetricsPlugin } = useRequestTime();\n\n const { state, managedState } = usePersistentStateMachine({\n manager: props.manager,\n middleware: { next: withRequestTime },\n playerConfig: {\n plugins: [...(props?.plugins ?? []), RequestTimeMetricsPlugin],\n player: props.player,\n },\n });\n\n React.useEffect(() => {\n if (state?.value === \"ended\") {\n props.onComplete?.(state?.context.result);\n } else if (state?.value === \"error\") {\n props.onError?.(state?.context.error);\n } else if (state?.value === \"running\") {\n props.onStartedFlow?.();\n }\n }, [state]);\n\n React.useEffect(() => {\n return () => {\n const playerState = state?.context.reactPlayer.player.getState();\n\n if (state?.value === \"running\" && playerState?.status === \"in-progress\") {\n props.manager.terminate?.(playerState.controllers.data.serialize());\n }\n };\n }, [props.manager, state?.context.reactPlayer.player, state?.value]);\n\n if (state?.value === \"error\") {\n if (props.fallbackComponent) {\n return (\n <props.fallbackComponent\n reset={() => {\n managedState.reset();\n }}\n retry={() => {\n managedState.restart();\n }}\n error={state.context.error}\n />\n );\n }\n\n if (!props.onError) {\n throw state.context.error;\n }\n }\n\n if (state?.context.reactPlayer) {\n const { Component } = state.context.reactPlayer;\n\n return <Component />;\n }\n\n return null;\n};\n","import { useCallback, useEffect, useRef, useMemo } from \"react\";\nimport type { Player } from \"@player-ui/player\";\nimport type { MetricsCorePlugin } from \"@player-ui/metrics-plugin\";\nimport {\n MetricsCorePluginSymbol,\n RequestTimeWebPlugin,\n} from \"@player-ui/metrics-plugin\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\ntype RequestTime = {\n /** request start time */\n start?: number;\n /** request end time */\n end?: number;\n};\n\n/** hook to time a promise and add it to the metrics plugin */\nexport const useRequestTime = () => {\n const requestTimeRef = useRef<RequestTime>({});\n\n useEffect(() => {\n return () => {\n requestTimeRef.current = {};\n };\n }, [requestTimeRef]);\n\n const getRequestTime = useCallback(() => {\n const { end, start } = requestTimeRef.current;\n\n if (end && start) {\n return end - start;\n }\n }, [requestTimeRef]);\n\n /** wrap a promise with tracking it's time in flight */\n function withRequestTime<Type>(nextPromise: Promise<Type>): Promise<Type> {\n const getTime = typeof performance === \"undefined\" ? Date : performance;\n requestTimeRef.current = { start: getTime.now() };\n\n return nextPromise.finally(() => {\n requestTimeRef.current = {\n ...requestTimeRef.current,\n end: getTime.now(),\n };\n });\n }\n\n const RequestTimeMetricsPlugin: ReactPlayerPlugin = useMemo(() => {\n return {\n name: \"RequestTimeMetricsPlugin\",\n apply(player: Player): void {\n player.applyTo<MetricsCorePlugin>(\n MetricsCorePluginSymbol,\n (metricsCorePlugin) => {\n new RequestTimeWebPlugin(getRequestTime).apply(metricsCorePlugin);\n },\n );\n },\n };\n }, [getRequestTime]);\n\n return { withRequestTime, RequestTimeMetricsPlugin };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,8BAAd;;;ACCA,IAAAC,gBAAkB;AAClB,wB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W,CAAC,GAAI,wBAAwB;AAAA,MAC7D,QAAQ,MAAM;AAAA,IAChB;AAAA,EACF,CAAC;AAED,gBAAAA,QAAM,UAAU,MAAM;AACpB,QAAI,OAAO,UAAU,SAAS;AAC5B,YAAM,aAAa,OAAO,QAAQ,MAAM;AAAA,IAC1C,WAAW,OAAO,UAAU,SAAS;AACnC,YAAM,UAAU,OAAO,QAAQ,KAAK;AAAA,IACtC,WAAW,OAAO,UAAU,WAAW;AACrC,YAAM,gBAAgB;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,KAAK,CAAC;AAEV,gBAAAA,QAAM,UAAU,MAAM;AACpB,WAAO,MAAM;AACX,YAAM,cAAc,OAAO,QAAQ,YAAY,OAAO,SAAS;AAE/D,UAAI,OAAO,UAAU,aAAa,aAAa,WAAW,eAAe;AACvE,cAAM,QAAQ,YAAY,YAAY,YAAY,KAAK,UAAU,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,SAAS,OAAO,QAAQ,YAAY,QAAQ,OAAO,KAAK,CAAC;AAEnE,MAAI,OAAO,UAAU,SAAS;AAC5B,QAAI,MAAM,mBAAmB;AAC3B,aACE,8BAAAA,QAAA;AAAA,QAAC,MAAM;AAAA,QAAN;AAAA,UACC,OAAO,MAAM;AACX,yBAAa,MAAM;AAAA,UACrB;AAAA,UACA,OAAO,MAAM;AACX,yBAAa,QAAQ;AAAA,UACvB;AAAA,UACA,OAAO,MAAM,QAAQ;AAAA;AAAA,MACvB;AAAA,IAEJ;AAEA,QAAI,CAAC,MAAM,SAAS;AAClB,YAAM,MAAM,QAAQ;AAAA,IACtB;AAAA,EACF;AAEA,MAAI,OAAO,QAAQ,aAAa;AAC9B,UAAM,EAAE,UAAU,IAAI,MAAM,QAAQ;AAEpC,WAAO,8BAAAA,QAAA,cAAC,eAAU;AAAA,EACpB;AAEA,SAAO;AACT;","names":["ReactPlayer","import_react","import_player","React","leven","import_react","React","import_react","React","ReactPlayer","React","import_player","import_react","React","ReactPlayer","import_react","import_react","ReactPlayer","React"]}
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/player-context.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-logger.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-asset-props.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/helpers.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/url.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/shared-constants.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/app.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/onupdate-plugin.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/hooks.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/tapstate-plugin.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/managed-player.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/request-time.tsx"],"sourcesContent":["export * from \"@player-ui/player\";\nexport * from \"./player\";\nexport * from \"./hooks\";\nexport * from \"./manager/managed-player\";\nexport * from \"./manager/request-time\";\nexport * from \"./manager/types\";\nexport * from \"./asset\";\nexport * from \"./utils\";\n","/* eslint-disable react/no-this-in-sfc */\nimport React from \"react\";\nimport { SyncWaterfallHook, AsyncParallelHook } from \"tapable-ts\";\nimport { Subscribe, useSubscribedState } from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n Flow,\n View,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport PlayerComp from \"./app\";\nimport OnUpdatePlugin from \"./plugins/onupdate-plugin\";\n\nconst WEB_PLAYER_VERSION = \"__VERSION__\";\nconst COMMIT = \"__GIT_COMMIT__\";\n\nexport interface DevtoolsGlobals {\n /** A global for a plugin to load to Player for devtools */\n __PLAYER_DEVTOOLS_PLUGIN?: {\n new (): ReactPlayerPlugin;\n };\n}\n\nexport type DevtoolsWindow = typeof window & DevtoolsGlobals;\n\nconst _window: DevtoolsWindow | undefined =\n typeof window === \"undefined\" ? undefined : window;\n\nexport interface ReactPlayerInfo {\n /** Version of the running player */\n playerVersion: string;\n\n /** Version of the running reactPlayer */\n reactPlayerVersion: string;\n\n /** Hash of the HEAD commit used to build the current player version */\n playerCommit: string;\n\n /** Hash of the HEAD commit used to build the current reactPlayer version */\n reactPlayerCommit: string;\n}\n\nexport interface ReactPlayerPlugin extends Partial<PlayerPlugin> {\n /** The name of this plugin */\n name: string;\n\n /**\n * Attach listeners to the web-player instance\n */\n applyReact?: (reactPlayer: ReactPlayer) => void;\n}\n\nexport interface ReactPlayerOptions {\n /** A headless player instance to use */\n player?: Player;\n\n /** A set of plugins to apply to this player */\n plugins?: Array<ReactPlayerPlugin>;\n}\n\nexport type ReactPlayerComponentProps = Record<string, unknown>;\n\n/** A Player that renders UI through React */\nexport class ReactPlayer {\n public readonly options: ReactPlayerOptions;\n public readonly player: Player;\n public readonly assetRegistry: AssetRegistryType = new Registry();\n public readonly Component: React.ComponentType<ReactPlayerComponentProps>;\n public readonly hooks = {\n /**\n * A hook to create a React Component to be used for Player, regardless of the current flow state\n */\n webComponent: new SyncWaterfallHook<[React.ComponentType]>(),\n\n /**\n * A hook to create a React Component that's used to render a specific view.\n * It will be called for each view update from the core player.\n * Typically this will just be `Asset`\n */\n playerComponent: new SyncWaterfallHook<\n [React.ComponentType<ReactPlayerProps>]\n >(),\n\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: new AsyncParallelHook<[]>(),\n };\n\n private viewUpdateSubscription = new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n this.options = options ?? {};\n\n const Devtools = _window?.__PLAYER_DEVTOOLS_PLUGIN;\n const onUpdatePlugin = new OnUpdatePlugin(\n this.viewUpdateSubscription.publish,\n );\n\n const plugins = options?.plugins ?? [];\n\n if (Devtools) {\n plugins.push(new Devtools());\n }\n\n const playerPlugins = plugins.filter((p) =>\n Boolean(p.apply),\n ) as PlayerPlugin[];\n\n this.player = options?.player ?? new Player({ plugins: playerPlugins });\n\n plugins.forEach((plugin) => {\n if (plugin.applyReact) {\n plugin.applyReact(this);\n }\n });\n\n onUpdatePlugin.apply(this.player);\n\n this.Component = this.createReactPlayerComponent();\n this.reactPlayerInfo = {\n playerVersion: this.player.getVersion(),\n playerCommit: this.player.getCommit(),\n reactPlayerVersion: WEB_PLAYER_VERSION,\n reactPlayerCommit: COMMIT,\n };\n }\n\n /** Returns the current version of the underlying core Player */\n public getPlayerVersion(): string {\n return this.reactPlayerInfo.playerVersion;\n }\n\n /** Returns the git commit used to build this core Player version */\n public getPlayerCommit(): string {\n return this.reactPlayerInfo.playerCommit;\n }\n\n /** Find instance of [Plugin] that has been registered to the web player */\n public findPlugin<Plugin extends ReactPlayerPlugin>(\n symbol: symbol,\n ): Plugin | undefined {\n return this.options.plugins?.find((el) => el.symbol === symbol) as Plugin;\n }\n\n /** Register and apply [Plugin] if one with the same symbol is not already registered. */\n public registerPlugin(plugin: ReactPlayerPlugin): void {\n if (!plugin.applyReact) return;\n\n plugin.applyReact(this);\n this.options.plugins?.push(plugin);\n }\n\n /** Returns the current version of the running React Player */\n public getReactPlayerVersion(): string {\n return this.reactPlayerInfo.reactPlayerVersion;\n }\n\n /** Returns the git commit used to build the React Player version */\n public getReactPlayerCommit(): string {\n return this.reactPlayerInfo.reactPlayerCommit;\n }\n\n private createReactPlayerComponent(): React.ComponentType<ReactPlayerComponentProps> {\n const BaseComp = this.hooks.webComponent.call(this.createReactComp());\n\n /** Wrap the Error boundary and context provider after the hook call to catch anything wrapped by the hook */\n const ReactPlayerComponent = (props: ReactPlayerComponentProps) => {\n return (\n <ErrorBoundary\n fallbackRender={() => null}\n onError={(err) => {\n const playerState = this.player.getState();\n\n if (playerState.status === \"in-progress\") {\n playerState.fail(err);\n }\n }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...props} />\n </PlayerContext.Provider>\n </ErrorBoundary>\n );\n };\n\n return ReactPlayerComponent;\n }\n\n private createReactComp(): React.ComponentType<ReactPlayerComponentProps> {\n const ActualPlayerComp = this.hooks.playerComponent.call(PlayerComp);\n\n /** the component to use to render the player */\n const WebPlayerComponent = () => {\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n this.viewUpdateSubscription.suspend();\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {view && <ActualPlayerComp view={view} />}\n </AssetContext.Provider>\n );\n };\n\n return WebPlayerComponent;\n }\n\n /**\n * Call this method to force the ReactPlayer to wait for the next view-update before performing the next render.\n * If the `suspense` option is set, this will suspend while an update is pending, otherwise nothing will be rendered.\n */\n public setWaitForNextViewUpdate() {\n const shouldCallResetHook = this.hooks.onBeforeViewReset.isUsed();\n\n return this.viewUpdateSubscription.reset(\n shouldCallResetHook ? this.hooks.onBeforeViewReset.call() : undefined,\n );\n }\n\n public start(flow: Flow): Promise<CompletedState> {\n this.setWaitForNextViewUpdate();\n\n return this.player.start(flow).finally(async () => {\n await this.setWaitForNextViewUpdate();\n });\n }\n}\n\n// For compatibility\nexport const WebPlayer = ReactPlayer;\n","import React from \"react\";\nimport leven from \"leven\";\nimport type { Asset as AssetType, AssetWrapper } from \"@player-ui/player\";\nimport type { Registry } from \"@player-ui/partial-match-registry\";\n\nexport type AssetRegistryType = Registry<React.ComponentType<any>>;\n\nexport interface ContextType {\n /**\n * A registry of Asset -> React Components\n */\n registry?: AssetRegistryType;\n}\n\nexport const AssetContext = React.createContext<ContextType>({});\n\n/**\n * A React Component that looks up an implementation from a registry\n */\nexport const ReactAsset = (\n props: AssetType<string> | AssetWrapper<AssetType<string>>,\n) => {\n const { registry } = React.useContext(AssetContext);\n\n let unwrapped;\n\n if (\"type\" in props && \"id\" in props) {\n unwrapped = props;\n } else if (\"asset\" in props) {\n unwrapped = (props as unknown as AssetWrapper).asset;\n }\n\n if (!unwrapped) {\n throw Error(\n `Cannot determine asset type for props: ${JSON.stringify(props)}`,\n );\n }\n\n if (typeof unwrapped !== \"object\") {\n throw Error(\n `Asset was not an object got (${typeof unwrapped}) instead: ${unwrapped}`,\n );\n }\n\n if (unwrapped.type === undefined) {\n const info =\n unwrapped.id === undefined\n ? JSON.stringify(props)\n : `id: ${unwrapped.id}`;\n throw Error(`Asset is missing type for ${info}`);\n }\n\n if (!registry || registry.isRegistryEmpty()) {\n throw Error(`No asset found in registry. This could happen for one of the following reasons: \\n\n 1. You might have no assets registered or no plugins added to the Player instance. \\n\n 2. You might have mismatching versions of React Asset Registry Context. \\n\n See https://player-ui.github.io/latest/tools/cli#player-dependency-versions-check for tips about how to debug and fix this problem`);\n }\n\n const Impl = registry?.get(unwrapped);\n\n if (!Impl) {\n const matchList: object[] = [];\n\n registry.forEach((asset) => {\n matchList.push(asset.key);\n });\n\n const typeList = matchList.map(\n (match) => JSON.parse(JSON.stringify(match)).type,\n );\n\n const similarType = typeList.reduce((prev, curr) => {\n const next = {\n value: leven(unwrapped.type, curr),\n type: curr,\n };\n\n if (prev !== undefined && prev.value < next.value) {\n return prev;\n }\n\n return next;\n }, undefined);\n\n throw Error(\n `No implementation found for id: ${unwrapped.id} type: ${unwrapped.type}. Did you mean ${similarType.type}? \\n \n Registered Asset matching functions are listed below: \\n\n ${JSON.stringify(matchList)}`,\n );\n }\n\n return <Impl key={unwrapped.id} {...unwrapped} />;\n};\n","import React from \"react\";\nimport type { Player, NavigationFlowViewState } from \"@player-ui/player\";\n\nexport interface PlayerContextType {\n /**\n * An instance of a headless player\n */\n player?: Player;\n\n /** The currently rendered view state */\n viewState?: NavigationFlowViewState;\n}\n\nexport const PlayerContext = React.createContext<PlayerContextType>({});\n\n/**\n * A hook to get the current player\n */\nexport const usePlayer = () => {\n const { player } = React.useContext(PlayerContext);\n\n return player;\n};\n","import type { Logger } from \"@player-ui/player\";\nimport { NoopLogger } from \"@player-ui/player\";\nimport { usePlayer } from \"./player-context\";\n\nconst noopLogger = new NoopLogger();\n\n/**\n * A hook to get the logger instance from the current player\n */\nexport function useLogger(): Logger {\n const player = usePlayer();\n\n return player?.logger ?? noopLogger;\n}\n","import type { Asset } from \"@player-ui/player\";\n\n/** Common props for any dom node */\nexport function useAssetProps(asset: Asset) {\n return {\n id: asset.id,\n \"data-asset-type\": asset.type,\n };\n}\n","/**\n * Trim leading and trailing slashes from string\n */\nexport function trimSlashes(str: string) {\n return str.replace(/^\\/+|\\/+$/g, \"\");\n}\n\n/**\n * Removes any key: value pairs from an object when the value is null or undefined\n */\nexport function removeEmptyValuesFromObject(\n obj: Record<string, any>,\n): Record<string, NonNullable<any>> {\n return Object.keys(obj).reduce(\n (acc, key) => {\n const value = obj[key];\n\n if (value !== null && value !== undefined) {\n acc[key] = value;\n }\n\n return acc;\n },\n {} as Record<string, any>,\n );\n}\n\n/** Check if the object has no keys */\nexport function isEmptyObject(obj: Record<string, unknown>) {\n return Object.keys(obj).length === 0 && obj.constructor === Object;\n}\n\n/** Check if the argument is a function */\nexport function isFunction<ReturnType>(\n maybeFn: ReturnType | ((...args: unknown[]) => ReturnType),\n): maybeFn is (...args: unknown[]) => ReturnType {\n return Boolean(maybeFn instanceof Function || typeof maybeFn === \"function\");\n}\n\n/**\n * Calls function with provided data or returns original value\n */\nexport function callOrReturn<\n ReturnType,\n FnArgs extends Array<unknown> = unknown[],\n FnType = (...args: FnArgs) => ReturnType,\n>(maybeFn: FnType | ReturnType, fnArgs: FnArgs): ReturnType {\n if (isFunction(maybeFn)) {\n return maybeFn(fnArgs) as ReturnType;\n }\n\n return maybeFn as ReturnType;\n}\n","import { isEmptyObject } from \"./helpers\";\n\n/**\n * Combines a URL with any additional parameters\n */\nexport function buildUrl(\n url: string,\n params: Record<string, unknown> = {},\n): string {\n const baseUrl = new URL(url);\n\n if (params && isEmptyObject(params)) {\n return baseUrl.toString();\n }\n\n Object.keys(params).forEach((key) => {\n const value = params[key];\n baseUrl.searchParams.append(key, String(value));\n });\n\n return baseUrl.toString();\n}\n","import { usePlayer } from \"./player-context\";\n\n/** Hook to get a constant under a specific namespace */\nexport function useGetConstantByType(type: string, key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, type);\n}\n\n/** Get a constant under the default namespace */\nexport function useGetConstant(key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, \"constants\");\n}\n","import React from \"react\";\nimport type { View } from \"@player-ui/player\";\nimport { ReactAsset } from \"./asset\";\n\nexport interface ReactPlayerProps {\n /**\n * The Content view object to render\n */\n view: View;\n}\n\n/**\n * The entry for the ReactPlayer's React tree\n */\nconst ReactPlayer = ({ view }: ReactPlayerProps) => {\n return <ReactAsset {...view} />;\n};\n\nexport default ReactPlayer;\n","import type { Player, PlayerPlugin, ViewInstance } from \"@player-ui/player\";\n\nexport type OnUpdateCallback = (update: any) => void;\n\n/**\n * A plugin that listens for view updates and publishes an event for when a view is updated\n */\nexport default class OnUpdatePlugin implements PlayerPlugin {\n name = \"view-update\";\n\n private readonly onUpdateCallback: OnUpdateCallback;\n\n constructor(onUpdate: OnUpdateCallback) {\n this.onUpdateCallback = onUpdate;\n }\n\n apply(player: Player) {\n /** Trigger the callback for the view update */\n const updateTap = (updatedView: any) => {\n this.onUpdateCallback(updatedView);\n };\n\n /** Trigger the callback for the view creation */\n const viewTap = (view: ViewInstance) => {\n view.hooks.onUpdate.tap(this.name, updateTap);\n };\n\n // Attach hooks for any new vc that gets created\n player.hooks.view.tap(this.name, viewTap);\n\n // Attach listeners and publish an update event for a view already in progress\n const currentPlayerState = player.getState();\n\n if (currentPlayerState.status === \"in-progress\") {\n const { currentView } = currentPlayerState.controllers.view;\n\n if (currentView) {\n viewTap(currentView);\n const { lastUpdate } = currentView;\n\n if (lastUpdate) {\n this.onUpdateCallback(lastUpdate);\n }\n }\n }\n }\n}\n","import type { Player, PlayerFlowState } from \"@player-ui/player\";\nimport { NOT_STARTED_STATE } from \"@player-ui/player\";\nimport React from \"react\";\nimport type { ReactPlayerOptions } from \"./player\";\nimport { ReactPlayer } from \"./player\";\nimport { StateTapPlugin } from \"./plugins/tapstate-plugin\";\n\nexport interface UseReactPlayerReturn {\n /** The web-player instance */\n reactPlayer: ReactPlayer;\n /** Player instance */\n player: Player;\n /** The state of Player */\n playerState: PlayerFlowState;\n}\n\n/**\n * The `useReactPlayer` hook is an easy way to integrate the web-player into your React app.\n * Simply supply your config, plugins, and an optional flow, which will be automatically started for you when changed.\n */\nexport const useReactPlayer = (\n options?: ReactPlayerOptions,\n): UseReactPlayerReturn => {\n const [playerState, setPlayerState] =\n React.useState<PlayerFlowState>(NOT_STARTED_STATE);\n\n const reactPlayer = React.useMemo(() => {\n const rp = new ReactPlayer({\n player: options?.player,\n plugins: [\n ...(options?.plugins ?? []),\n new StateTapPlugin(setPlayerState),\n ],\n });\n\n return rp;\n }, []);\n\n const { player } = reactPlayer;\n\n return {\n reactPlayer,\n player,\n playerState,\n };\n};\n","import type { PlayerFlowState, Player } from \"@player-ui/player\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\n/**\n * A plugin to tap into state transition changes and call an arbitrary update function\n */\nexport class StateTapPlugin implements ReactPlayerPlugin {\n name = \"statetap\";\n private callbackFunction: (state: PlayerFlowState) => void;\n\n constructor(callback: (state: PlayerFlowState) => void) {\n this.callbackFunction = callback;\n }\n\n apply(player: Player) {\n player.hooks.state.tap(\"usePlayer\", (newPlayerState: PlayerFlowState) => {\n this.callbackFunction(newPlayerState);\n });\n }\n}\n","import React from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport type {\n FlowManager,\n ManagedPlayerProps,\n ManagedPlayerState,\n ManagerMiddleware,\n ManagedPlayerContext,\n} from \"./types\";\nimport { useRequestTime } from \"./request-time\";\nimport type { ReactPlayerOptions } from \"../player\";\nimport { ReactPlayer } from \"../player\";\n\n/** noop middleware */\nfunction identityMiddleware<T>(next: Promise<T>) {\n return next;\n}\n\ninterface ManagedPlayerStateKey {\n /** the storage key for the state (outside of the react tree) */\n _key: symbol;\n}\n\nexport interface StateChangeCallback {\n /** Trigger for state changes */\n onState: (s: ManagedPlayerState) => void;\n}\n\n/**\n * An object to store the state of the managed player\n */\nclass ManagedState {\n public state?: ManagedPlayerState;\n private callbacks: Array<StateChangeCallback>;\n private middleware?: ManagerMiddleware;\n\n constructor({\n middleware,\n }: {\n /** middleware to use in the managed player */\n middleware?: ManagerMiddleware;\n }) {\n this.middleware = middleware;\n this.callbacks = [];\n // this.state = {\n // value: \"uninitialized\",\n // context: {},\n // };\n }\n\n /** Add a listener to state changes */\n public addListener = (callback: StateChangeCallback): (() => void) => {\n this.callbacks.push(callback);\n\n return () => {\n this.callbacks = this.callbacks.filter((s) => s !== callback);\n };\n };\n\n public getSnapshot = (): ManagedPlayerState | undefined => {\n return this.state;\n };\n\n /** start the managed flow */\n public start(options: {\n /** the flow manager to use */\n manager: FlowManager;\n\n /** the config to use when creating a player */\n playerConfig: ReactPlayerOptions;\n }): this {\n const initialState: ManagedPlayerState = {\n value: \"not_started\",\n context: {\n playerConfig: options.playerConfig,\n reactPlayer: new ReactPlayer(options.playerConfig),\n manager: options.manager,\n },\n };\n\n this.setState(initialState);\n\n return this;\n }\n\n /** reset starts from nothing */\n public reset(): void {\n if (this.state?.value === \"error\") {\n const { playerConfig, manager } = this.state.context;\n this.start({ playerConfig, manager });\n } else {\n throw new Error(\"Flow must be in error state to reset\");\n }\n }\n\n /** restart starts from the last result */\n public restart(): void {\n if (this.state?.value === \"error\") {\n const { playerConfig, manager, prevResult, reactPlayer } =\n this.state.context;\n this.setState({\n value: \"completed\",\n context: {\n playerConfig,\n manager,\n result: prevResult,\n reactPlayer,\n },\n });\n } else {\n throw new Error(\"Flow must be in error state to restart\");\n }\n }\n\n private async setState(state: ManagedPlayerState) {\n this.state = state;\n this.callbacks.forEach((c) => {\n c.onState(state);\n });\n\n const { manager, reactPlayer, playerConfig } = state.context;\n\n try {\n const nextState = await this.processState(state, {\n manager,\n reactPlayer,\n playerConfig,\n });\n\n if (nextState) {\n this.setState(nextState);\n }\n } catch (e) {\n this.setState({\n value: \"error\",\n context: {\n manager,\n reactPlayer,\n playerConfig,\n error: e as Error,\n },\n });\n }\n }\n\n private async processState(\n state: ManagedPlayerState,\n context: ManagedPlayerContext,\n ): Promise<ManagedPlayerState | undefined> {\n if (state.value === \"not_started\" || state.value === \"completed\") {\n const prevResult =\n state.value === \"completed\" ? state.context.result : undefined;\n\n const middleware = this.middleware?.next ?? identityMiddleware;\n\n return {\n value: \"pending\",\n context: {\n ...context,\n prevResult,\n next: middleware(state.context.manager.next(prevResult)),\n },\n };\n }\n\n if (state.value === \"pending\") {\n const nextResult = await state.context.next;\n\n if (nextResult.done) {\n return {\n value: \"ended\",\n context: {\n ...context,\n result: state.context.prevResult,\n },\n };\n }\n\n return {\n value: \"loaded\",\n context: {\n ...context,\n prevResult: state.context.prevResult,\n flow: nextResult.value,\n },\n };\n }\n\n if (state.value === \"loaded\") {\n return {\n value: \"running\",\n context: {\n ...context,\n flow: state.context.flow,\n prevResult: state.context.prevResult,\n result: state.context.reactPlayer.start(state.context.flow),\n },\n };\n }\n\n if (state.value === \"running\") {\n const result = await state.context.result;\n\n return {\n value: \"completed\",\n context: {\n ...context,\n result,\n },\n };\n }\n }\n}\n\nconst managedPlayerStateMachines = new WeakMap<\n ManagedPlayerStateKey,\n ManagedState\n>();\n\n/**\n * Helper to make a unique symbol\n */\nfunction createKey() {\n return {\n _key: Symbol(\"managed-player\"),\n };\n}\n\n/** Creates an x-state state machine that persists when this component is no longer rendered (due to Suspense) */\nexport const createPersistentStateMachine = (\n keyRef: React.MutableRefObject<ManagedPlayerStateKey>,\n middleware?: ManagerMiddleware,\n): ManagedState => {\n const managedState =\n managedPlayerStateMachines.get(keyRef.current) ??\n new ManagedState({ middleware: middleware });\n managedPlayerStateMachines.set(keyRef.current, managedState);\n\n return managedState;\n};\n\n/**\n * A ManagedPlayer is a component responsible for orchestrating multi-flow experiences using Player.\n * Provide a valid `FlowManager` to handle fetching the next flow.\n *\n * `suspense` must be enabled to wait for results in flight.\n */\nexport const ManagedPlayer = (\n props: ManagedPlayerProps,\n): React.JSX.Element | null => {\n const keyRef = React.useRef<ManagedPlayerStateKey>(createKey());\n const { withRequestTime, RequestTimeMetricsPlugin } = useRequestTime();\n\n const initialState = createPersistentStateMachine(keyRef, {\n next: withRequestTime,\n });\n\n const [managedState, setManagedState] = React.useState(initialState);\n const wrappedListener = React.useCallback(\n (cb: (s: ManagedPlayerState) => void) => {\n return managedState.addListener({\n onState(s) {\n cb(s);\n },\n });\n },\n [managedState],\n );\n\n // const [state, setState] = React.useState(managedState.state);\n const state = useSyncExternalStore(wrappedListener, managedState.getSnapshot);\n\n React.useEffect(() => {\n if (state?.value === \"ended\") {\n if (props.manager !== state.context.manager) {\n keyRef.current = createKey();\n const newManagedState = createPersistentStateMachine(keyRef, {\n next: withRequestTime,\n });\n setManagedState(newManagedState);\n // setState(newManagedState.state);\n } else {\n props.onComplete?.(state?.context.result);\n }\n } else if (state?.value === \"error\") {\n props.onError?.(state?.context.error);\n } else if (state?.value === \"running\") {\n props.onStartedFlow?.();\n } else if (state === undefined) {\n managedState.start({\n manager: props.manager,\n playerConfig: {\n plugins: [...(props?.plugins ?? []), RequestTimeMetricsPlugin],\n player: props.player,\n },\n });\n }\n }, [state]);\n\n React.useEffect(() => {\n return () => {\n const playerState = state?.context?.reactPlayer?.player?.getState();\n\n if (state?.value === \"running\" && playerState?.status === \"in-progress\") {\n props.manager.terminate?.(playerState.controllers.data.serialize());\n }\n };\n }, [props.manager, state?.context?.reactPlayer?.player, state?.value]);\n\n if (state?.value === \"error\") {\n if (props.fallbackComponent) {\n return (\n <props.fallbackComponent\n reset={() => {\n managedState.reset();\n }}\n retry={() => {\n managedState.restart();\n }}\n error={state.context.error}\n />\n );\n }\n\n if (!props.onError) {\n throw state.context.error;\n }\n }\n\n if (state?.context.reactPlayer) {\n const { Component } = state.context.reactPlayer;\n\n return <Component />;\n }\n\n return null;\n};\n","import { useCallback, useEffect, useRef, useMemo } from \"react\";\nimport type { Player } from \"@player-ui/player\";\nimport type { MetricsCorePlugin } from \"@player-ui/metrics-plugin\";\nimport {\n MetricsCorePluginSymbol,\n RequestTimeWebPlugin,\n} from \"@player-ui/metrics-plugin\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\ntype RequestTime = {\n /** request start time */\n start?: number;\n /** request end time */\n end?: number;\n};\n\n/** hook to time a promise and add it to the metrics plugin */\nexport const useRequestTime = () => {\n const requestTimeRef = useRef<RequestTime>({});\n\n useEffect(() => {\n return () => {\n requestTimeRef.current = {};\n };\n }, [requestTimeRef]);\n\n const getRequestTime = useCallback(() => {\n const { end, start } = requestTimeRef.current;\n\n if (end && start) {\n return end - start;\n }\n }, [requestTimeRef]);\n\n /** wrap a promise with tracking it's time in flight */\n function withRequestTime<Type>(nextPromise: Promise<Type>): Promise<Type> {\n const getTime = typeof performance === \"undefined\" ? Date : performance;\n requestTimeRef.current = { start: getTime.now() };\n\n return nextPromise.finally(() => {\n requestTimeRef.current = {\n ...requestTimeRef.current,\n end: getTime.now(),\n };\n });\n }\n\n const RequestTimeMetricsPlugin: ReactPlayerPlugin = useMemo(() => {\n return {\n name: \"RequestTimeMetricsPlugin\",\n apply(player: Player): void {\n player.applyTo<MetricsCorePlugin>(\n MetricsCorePluginSymbol,\n (metricsCorePlugin) => {\n new RequestTimeWebPlugin(getRequestTime).apply(metricsCorePlugin);\n },\n );\n },\n };\n }, [getRequestTime]);\n\n return { withRequestTime, RequestTimeMetricsPlugin };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,8BAAd;;;ACCA,IAAAC,gBAAkB;AAClB,wBAAqD;AACrD,6BAA8C;AAC9C,oCAAyB;AAOzB,IAAAC,iBAAuB;AACvB,kCAA8B;;;ACZ9B,mBAAkB;AAClB,mBAAkB;AAaX,IAAM,eAAe,aAAAC,QAAM,cAA2B,CAAC,CAAC;AAKxD,IAAM,aAAa,CACxB,UACG;AACH,QAAM,EAAE,SAAS,IAAI,aAAAA,QAAM,WAAW,YAAY;AAElD,MAAI;AAEJ,MAAI,UAAU,SAAS,QAAQ,OAAO;AACpC,gBAAY;AAAA,EACd,WAAW,WAAW,OAAO;AAC3B,gBAAa,MAAkC;AAAA,EACjD;AAEA,MAAI,CAAC,WAAW;AACd,UAAM;AAAA,MACJ,0CAA0C,KAAK,UAAU,KAAK,CAAC;AAAA,IACjE;AAAA,EACF;AAEA,MAAI,OAAO,cAAc,UAAU;AACjC,UAAM;AAAA,MACJ,gCAAgC,OAAO,SAAS,cAAc,SAAS;AAAA,IACzE;AAAA,EACF;AAEA,MAAI,UAAU,SAAS,QAAW;AAChC,UAAM,OACJ,UAAU,OAAO,SACb,KAAK,UAAU,KAAK,IACpB,OAAO,UAAU,EAAE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,QAAM,UAAU,MAAM;AACpB,WAAO,MAAM;AACX,YAAM,cAAc,OAAO,SAAS,aAAa,QAAQ,SAAS;AAElE,UAAI,OAAO,UAAU,aAAa,aAAa,WAAW,eAAe;AACvE,cAAM,QAAQ,YAAY,YAAY,YAAY,KAAK,UAAU,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,SAAS,OAAO,SAAS,aAAa,QAAQ,OAAO,KAAK,CAAC;AAErE,MAAI,OAAO,UAAU,SAAS;AAC5B,QAAI,MAAM,mBAAmB;AAC3B,aACE,8BAAAA,QAAA;AAAA,QAAC,MAAM;AAAA,QAAN;AAAA,UACC,OAAO,MAAM;AACX,yBAAa,MAAM;AAAA,UACrB;AAAA,UACA,OAAO,MAAM;AACX,yBAAa,QAAQ;AAAA,UACvB;AAAA,UACA,OAAO,MAAM,QAAQ;AAAA;AAAA,MACvB;AAAA,IAEJ;AAEA,QAAI,CAAC,MAAM,SAAS;AAClB,YAAM,MAAM,QAAQ;AAAA,IACtB;AAAA,EACF;AAEA,MAAI,OAAO,QAAQ,aAAa;AAC9B,UAAM,EAAE,UAAU,IAAI,MAAM,QAAQ;AAEpC,WAAO,8BAAAA,QAAA,cAAC,eAAU;AAAA,EACpB;AAEA,SAAO;AACT;","names":["ReactPlayer","import_react","import_player","React","leven","import_react","React","import_react","React","ReactPlayer","React","import_player","import_react","React","ReactPlayer","import_react","import_react","ReactPlayer","React"]}
@@ -358,6 +358,7 @@ var useReactPlayer = (options) => {
358
358
 
359
359
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/managed-player.tsx
360
360
  import React6 from "react";
361
+ import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
361
362
 
362
363
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/request-time.tsx
363
364
  import { useCallback, useEffect, useRef, useMemo } from "react";
@@ -412,16 +413,19 @@ var ManagedState = class {
412
413
  constructor({
413
414
  middleware
414
415
  }) {
416
+ /** Add a listener to state changes */
417
+ this.addListener = (callback) => {
418
+ this.callbacks.push(callback);
419
+ return () => {
420
+ this.callbacks = this.callbacks.filter((s) => s !== callback);
421
+ };
422
+ };
423
+ this.getSnapshot = () => {
424
+ return this.state;
425
+ };
415
426
  this.middleware = middleware;
416
427
  this.callbacks = [];
417
428
  }
418
- /** Add a listener to state changes */
419
- addListener(callback) {
420
- this.callbacks.push(callback);
421
- return () => {
422
- this.callbacks = this.callbacks.filter((s) => s !== callback);
423
- };
424
- }
425
429
  /** start the managed flow */
426
430
  start(options) {
427
431
  const initialState = {
@@ -545,53 +549,67 @@ var ManagedState = class {
545
549
  }
546
550
  };
547
551
  var managedPlayerStateMachines = /* @__PURE__ */ new WeakMap();
548
- var usePersistentStateMachine = (options) => {
549
- const keyRef = React6.useRef({
552
+ function createKey() {
553
+ return {
550
554
  _key: Symbol("managed-player")
551
- });
552
- const managedState = managedPlayerStateMachines.get(keyRef.current) ?? new ManagedState({ middleware: options.middleware });
555
+ };
556
+ }
557
+ var createPersistentStateMachine = (keyRef, middleware) => {
558
+ const managedState = managedPlayerStateMachines.get(keyRef.current) ?? new ManagedState({ middleware });
553
559
  managedPlayerStateMachines.set(keyRef.current, managedState);
554
- const [state, setState] = React6.useState(managedState.state);
555
- React6.useEffect(() => {
556
- const unsub = managedState.addListener({
557
- onState: (s) => {
558
- setState(s);
559
- }
560
- });
561
- if (managedState.state === void 0) {
562
- managedState.start(options);
563
- }
564
- return unsub;
565
- }, []);
566
- return { managedState, state };
560
+ return managedState;
567
561
  };
568
562
  var ManagedPlayer = (props) => {
563
+ const keyRef = React6.useRef(createKey());
569
564
  const { withRequestTime, RequestTimeMetricsPlugin } = useRequestTime();
570
- const { state, managedState } = usePersistentStateMachine({
571
- manager: props.manager,
572
- middleware: { next: withRequestTime },
573
- playerConfig: {
574
- plugins: [...props?.plugins ?? [], RequestTimeMetricsPlugin],
575
- player: props.player
576
- }
565
+ const initialState = createPersistentStateMachine(keyRef, {
566
+ next: withRequestTime
577
567
  });
568
+ const [managedState, setManagedState] = React6.useState(initialState);
569
+ const wrappedListener = React6.useCallback(
570
+ (cb) => {
571
+ return managedState.addListener({
572
+ onState(s) {
573
+ cb(s);
574
+ }
575
+ });
576
+ },
577
+ [managedState]
578
+ );
579
+ const state = useSyncExternalStore(wrappedListener, managedState.getSnapshot);
578
580
  React6.useEffect(() => {
579
581
  if (state?.value === "ended") {
580
- props.onComplete?.(state?.context.result);
582
+ if (props.manager !== state.context.manager) {
583
+ keyRef.current = createKey();
584
+ const newManagedState = createPersistentStateMachine(keyRef, {
585
+ next: withRequestTime
586
+ });
587
+ setManagedState(newManagedState);
588
+ } else {
589
+ props.onComplete?.(state?.context.result);
590
+ }
581
591
  } else if (state?.value === "error") {
582
592
  props.onError?.(state?.context.error);
583
593
  } else if (state?.value === "running") {
584
594
  props.onStartedFlow?.();
595
+ } else if (state === void 0) {
596
+ managedState.start({
597
+ manager: props.manager,
598
+ playerConfig: {
599
+ plugins: [...props?.plugins ?? [], RequestTimeMetricsPlugin],
600
+ player: props.player
601
+ }
602
+ });
585
603
  }
586
604
  }, [state]);
587
605
  React6.useEffect(() => {
588
606
  return () => {
589
- const playerState = state?.context.reactPlayer.player.getState();
607
+ const playerState = state?.context?.reactPlayer?.player?.getState();
590
608
  if (state?.value === "running" && playerState?.status === "in-progress") {
591
609
  props.manager.terminate?.(playerState.controllers.data.serialize());
592
610
  }
593
611
  };
594
- }, [props.manager, state?.context.reactPlayer.player, state?.value]);
612
+ }, [props.manager, state?.context?.reactPlayer?.player, state?.value]);
595
613
  if (state?.value === "error") {
596
614
  if (props.fallbackComponent) {
597
615
  return /* @__PURE__ */ React6.createElement(
@@ -626,6 +644,7 @@ export {
626
644
  WebPlayer,
627
645
  buildUrl,
628
646
  callOrReturn,
647
+ createPersistentStateMachine,
629
648
  isEmptyObject,
630
649
  isFunction,
631
650
  removeEmptyValuesFromObject,
@@ -634,7 +653,6 @@ export {
634
653
  useGetConstant,
635
654
  useGetConstantByType,
636
655
  useLogger,
637
- usePersistentStateMachine,
638
656
  usePlayer,
639
657
  useReactPlayer,
640
658
  useRequestTime
package/dist/index.mjs CHANGED
@@ -358,6 +358,7 @@ var useReactPlayer = (options) => {
358
358
 
359
359
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/managed-player.tsx
360
360
  import React6 from "react";
361
+ import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
361
362
 
362
363
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/request-time.tsx
363
364
  import { useCallback, useEffect, useRef, useMemo } from "react";
@@ -412,16 +413,19 @@ var ManagedState = class {
412
413
  constructor({
413
414
  middleware
414
415
  }) {
416
+ /** Add a listener to state changes */
417
+ this.addListener = (callback) => {
418
+ this.callbacks.push(callback);
419
+ return () => {
420
+ this.callbacks = this.callbacks.filter((s) => s !== callback);
421
+ };
422
+ };
423
+ this.getSnapshot = () => {
424
+ return this.state;
425
+ };
415
426
  this.middleware = middleware;
416
427
  this.callbacks = [];
417
428
  }
418
- /** Add a listener to state changes */
419
- addListener(callback) {
420
- this.callbacks.push(callback);
421
- return () => {
422
- this.callbacks = this.callbacks.filter((s) => s !== callback);
423
- };
424
- }
425
429
  /** start the managed flow */
426
430
  start(options) {
427
431
  const initialState = {
@@ -545,53 +549,67 @@ var ManagedState = class {
545
549
  }
546
550
  };
547
551
  var managedPlayerStateMachines = /* @__PURE__ */ new WeakMap();
548
- var usePersistentStateMachine = (options) => {
549
- const keyRef = React6.useRef({
552
+ function createKey() {
553
+ return {
550
554
  _key: Symbol("managed-player")
551
- });
552
- const managedState = managedPlayerStateMachines.get(keyRef.current) ?? new ManagedState({ middleware: options.middleware });
555
+ };
556
+ }
557
+ var createPersistentStateMachine = (keyRef, middleware) => {
558
+ const managedState = managedPlayerStateMachines.get(keyRef.current) ?? new ManagedState({ middleware });
553
559
  managedPlayerStateMachines.set(keyRef.current, managedState);
554
- const [state, setState] = React6.useState(managedState.state);
555
- React6.useEffect(() => {
556
- const unsub = managedState.addListener({
557
- onState: (s) => {
558
- setState(s);
559
- }
560
- });
561
- if (managedState.state === void 0) {
562
- managedState.start(options);
563
- }
564
- return unsub;
565
- }, []);
566
- return { managedState, state };
560
+ return managedState;
567
561
  };
568
562
  var ManagedPlayer = (props) => {
563
+ const keyRef = React6.useRef(createKey());
569
564
  const { withRequestTime, RequestTimeMetricsPlugin } = useRequestTime();
570
- const { state, managedState } = usePersistentStateMachine({
571
- manager: props.manager,
572
- middleware: { next: withRequestTime },
573
- playerConfig: {
574
- plugins: [...props?.plugins ?? [], RequestTimeMetricsPlugin],
575
- player: props.player
576
- }
565
+ const initialState = createPersistentStateMachine(keyRef, {
566
+ next: withRequestTime
577
567
  });
568
+ const [managedState, setManagedState] = React6.useState(initialState);
569
+ const wrappedListener = React6.useCallback(
570
+ (cb) => {
571
+ return managedState.addListener({
572
+ onState(s) {
573
+ cb(s);
574
+ }
575
+ });
576
+ },
577
+ [managedState]
578
+ );
579
+ const state = useSyncExternalStore(wrappedListener, managedState.getSnapshot);
578
580
  React6.useEffect(() => {
579
581
  if (state?.value === "ended") {
580
- props.onComplete?.(state?.context.result);
582
+ if (props.manager !== state.context.manager) {
583
+ keyRef.current = createKey();
584
+ const newManagedState = createPersistentStateMachine(keyRef, {
585
+ next: withRequestTime
586
+ });
587
+ setManagedState(newManagedState);
588
+ } else {
589
+ props.onComplete?.(state?.context.result);
590
+ }
581
591
  } else if (state?.value === "error") {
582
592
  props.onError?.(state?.context.error);
583
593
  } else if (state?.value === "running") {
584
594
  props.onStartedFlow?.();
595
+ } else if (state === void 0) {
596
+ managedState.start({
597
+ manager: props.manager,
598
+ playerConfig: {
599
+ plugins: [...props?.plugins ?? [], RequestTimeMetricsPlugin],
600
+ player: props.player
601
+ }
602
+ });
585
603
  }
586
604
  }, [state]);
587
605
  React6.useEffect(() => {
588
606
  return () => {
589
- const playerState = state?.context.reactPlayer.player.getState();
607
+ const playerState = state?.context?.reactPlayer?.player?.getState();
590
608
  if (state?.value === "running" && playerState?.status === "in-progress") {
591
609
  props.manager.terminate?.(playerState.controllers.data.serialize());
592
610
  }
593
611
  };
594
- }, [props.manager, state?.context.reactPlayer.player, state?.value]);
612
+ }, [props.manager, state?.context?.reactPlayer?.player, state?.value]);
595
613
  if (state?.value === "error") {
596
614
  if (props.fallbackComponent) {
597
615
  return /* @__PURE__ */ React6.createElement(
@@ -626,6 +644,7 @@ export {
626
644
  WebPlayer,
627
645
  buildUrl,
628
646
  callOrReturn,
647
+ createPersistentStateMachine,
629
648
  isEmptyObject,
630
649
  isFunction,
631
650
  removeEmptyValuesFromObject,
@@ -634,7 +653,6 @@ export {
634
653
  useGetConstant,
635
654
  useGetConstantByType,
636
655
  useLogger,
637
- usePersistentStateMachine,
638
656
  usePlayer,
639
657
  useReactPlayer,
640
658
  useRequestTime
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/player-context.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-logger.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-asset-props.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/helpers.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/url.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/shared-constants.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/app.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/onupdate-plugin.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/hooks.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/tapstate-plugin.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/managed-player.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/request-time.tsx"],"sourcesContent":["export * from \"@player-ui/player\";\nexport * from \"./player\";\nexport * from \"./hooks\";\nexport * from \"./manager/managed-player\";\nexport * from \"./manager/request-time\";\nexport * from \"./manager/types\";\nexport * from \"./asset\";\nexport * from \"./utils\";\n","/* eslint-disable react/no-this-in-sfc */\nimport React from \"react\";\nimport { SyncWaterfallHook, AsyncParallelHook } from \"tapable-ts\";\nimport { Subscribe, useSubscribedState } from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n Flow,\n View,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport PlayerComp from \"./app\";\nimport OnUpdatePlugin from \"./plugins/onupdate-plugin\";\n\nconst WEB_PLAYER_VERSION = \"__VERSION__\";\nconst COMMIT = \"__GIT_COMMIT__\";\n\nexport interface DevtoolsGlobals {\n /** A global for a plugin to load to Player for devtools */\n __PLAYER_DEVTOOLS_PLUGIN?: {\n new (): ReactPlayerPlugin;\n };\n}\n\nexport type DevtoolsWindow = typeof window & DevtoolsGlobals;\n\nconst _window: DevtoolsWindow | undefined =\n typeof window === \"undefined\" ? undefined : window;\n\nexport interface ReactPlayerInfo {\n /** Version of the running player */\n playerVersion: string;\n\n /** Version of the running reactPlayer */\n reactPlayerVersion: string;\n\n /** Hash of the HEAD commit used to build the current player version */\n playerCommit: string;\n\n /** Hash of the HEAD commit used to build the current reactPlayer version */\n reactPlayerCommit: string;\n}\n\nexport interface ReactPlayerPlugin extends Partial<PlayerPlugin> {\n /** The name of this plugin */\n name: string;\n\n /**\n * Attach listeners to the web-player instance\n */\n applyReact?: (reactPlayer: ReactPlayer) => void;\n}\n\nexport interface ReactPlayerOptions {\n /** A headless player instance to use */\n player?: Player;\n\n /** A set of plugins to apply to this player */\n plugins?: Array<ReactPlayerPlugin>;\n}\n\nexport type ReactPlayerComponentProps = Record<string, unknown>;\n\n/** A Player that renders UI through React */\nexport class ReactPlayer {\n public readonly options: ReactPlayerOptions;\n public readonly player: Player;\n public readonly assetRegistry: AssetRegistryType = new Registry();\n public readonly Component: React.ComponentType<ReactPlayerComponentProps>;\n public readonly hooks = {\n /**\n * A hook to create a React Component to be used for Player, regardless of the current flow state\n */\n webComponent: new SyncWaterfallHook<[React.ComponentType]>(),\n\n /**\n * A hook to create a React Component that's used to render a specific view.\n * It will be called for each view update from the core player.\n * Typically this will just be `Asset`\n */\n playerComponent: new SyncWaterfallHook<\n [React.ComponentType<ReactPlayerProps>]\n >(),\n\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: new AsyncParallelHook<[]>(),\n };\n\n private viewUpdateSubscription = new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n this.options = options ?? {};\n\n const Devtools = _window?.__PLAYER_DEVTOOLS_PLUGIN;\n const onUpdatePlugin = new OnUpdatePlugin(\n this.viewUpdateSubscription.publish,\n );\n\n const plugins = options?.plugins ?? [];\n\n if (Devtools) {\n plugins.push(new Devtools());\n }\n\n const playerPlugins = plugins.filter((p) =>\n Boolean(p.apply),\n ) as PlayerPlugin[];\n\n this.player = options?.player ?? new Player({ plugins: playerPlugins });\n\n plugins.forEach((plugin) => {\n if (plugin.applyReact) {\n plugin.applyReact(this);\n }\n });\n\n onUpdatePlugin.apply(this.player);\n\n this.Component = this.createReactPlayerComponent();\n this.reactPlayerInfo = {\n playerVersion: this.player.getVersion(),\n playerCommit: this.player.getCommit(),\n reactPlayerVersion: WEB_PLAYER_VERSION,\n reactPlayerCommit: COMMIT,\n };\n }\n\n /** Returns the current version of the underlying core Player */\n public getPlayerVersion(): string {\n return this.reactPlayerInfo.playerVersion;\n }\n\n /** Returns the git commit used to build this core Player version */\n public getPlayerCommit(): string {\n return this.reactPlayerInfo.playerCommit;\n }\n\n /** Find instance of [Plugin] that has been registered to the web player */\n public findPlugin<Plugin extends ReactPlayerPlugin>(\n symbol: symbol,\n ): Plugin | undefined {\n return this.options.plugins?.find((el) => el.symbol === symbol) as Plugin;\n }\n\n /** Register and apply [Plugin] if one with the same symbol is not already registered. */\n public registerPlugin(plugin: ReactPlayerPlugin): void {\n if (!plugin.applyReact) return;\n\n plugin.applyReact(this);\n this.options.plugins?.push(plugin);\n }\n\n /** Returns the current version of the running React Player */\n public getReactPlayerVersion(): string {\n return this.reactPlayerInfo.reactPlayerVersion;\n }\n\n /** Returns the git commit used to build the React Player version */\n public getReactPlayerCommit(): string {\n return this.reactPlayerInfo.reactPlayerCommit;\n }\n\n private createReactPlayerComponent(): React.ComponentType<ReactPlayerComponentProps> {\n const BaseComp = this.hooks.webComponent.call(this.createReactComp());\n\n /** Wrap the Error boundary and context provider after the hook call to catch anything wrapped by the hook */\n const ReactPlayerComponent = (props: ReactPlayerComponentProps) => {\n return (\n <ErrorBoundary\n fallbackRender={() => null}\n onError={(err) => {\n const playerState = this.player.getState();\n\n if (playerState.status === \"in-progress\") {\n playerState.fail(err);\n }\n }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...props} />\n </PlayerContext.Provider>\n </ErrorBoundary>\n );\n };\n\n return ReactPlayerComponent;\n }\n\n private createReactComp(): React.ComponentType<ReactPlayerComponentProps> {\n const ActualPlayerComp = this.hooks.playerComponent.call(PlayerComp);\n\n /** the component to use to render the player */\n const WebPlayerComponent = () => {\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n this.viewUpdateSubscription.suspend();\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {view && <ActualPlayerComp view={view} />}\n </AssetContext.Provider>\n );\n };\n\n return WebPlayerComponent;\n }\n\n /**\n * Call this method to force the ReactPlayer to wait for the next view-update before performing the next render.\n * If the `suspense` option is set, this will suspend while an update is pending, otherwise nothing will be rendered.\n */\n public setWaitForNextViewUpdate() {\n const shouldCallResetHook = this.hooks.onBeforeViewReset.isUsed();\n\n return this.viewUpdateSubscription.reset(\n shouldCallResetHook ? this.hooks.onBeforeViewReset.call() : undefined,\n );\n }\n\n public start(flow: Flow): Promise<CompletedState> {\n this.setWaitForNextViewUpdate();\n\n return this.player.start(flow).finally(async () => {\n await this.setWaitForNextViewUpdate();\n });\n }\n}\n\n// For compatibility\nexport const WebPlayer = ReactPlayer;\n","import React from \"react\";\nimport leven from \"leven\";\nimport type { Asset as AssetType, AssetWrapper } from \"@player-ui/player\";\nimport type { Registry } from \"@player-ui/partial-match-registry\";\n\nexport type AssetRegistryType = Registry<React.ComponentType<any>>;\n\nexport interface ContextType {\n /**\n * A registry of Asset -> React Components\n */\n registry?: AssetRegistryType;\n}\n\nexport const AssetContext = React.createContext<ContextType>({});\n\n/**\n * A React Component that looks up an implementation from a registry\n */\nexport const ReactAsset = (\n props: AssetType<string> | AssetWrapper<AssetType<string>>,\n) => {\n const { registry } = React.useContext(AssetContext);\n\n let unwrapped;\n\n if (\"type\" in props && \"id\" in props) {\n unwrapped = props;\n } else if (\"asset\" in props) {\n unwrapped = (props as unknown as AssetWrapper).asset;\n }\n\n if (!unwrapped) {\n throw Error(\n `Cannot determine asset type for props: ${JSON.stringify(props)}`,\n );\n }\n\n if (typeof unwrapped !== \"object\") {\n throw Error(\n `Asset was not an object got (${typeof unwrapped}) instead: ${unwrapped}`,\n );\n }\n\n if (unwrapped.type === undefined) {\n const info =\n unwrapped.id === undefined\n ? JSON.stringify(props)\n : `id: ${unwrapped.id}`;\n throw Error(`Asset is missing type for ${info}`);\n }\n\n if (!registry || registry.isRegistryEmpty()) {\n throw Error(`No asset found in registry. This could happen for one of the following reasons: \\n\n 1. You might have no assets registered or no plugins added to the Player instance. \\n\n 2. You might have mismatching versions of React Asset Registry Context. \\n\n See https://player-ui.github.io/latest/tools/cli#player-dependency-versions-check for tips about how to debug and fix this problem`);\n }\n\n const Impl = registry?.get(unwrapped);\n\n if (!Impl) {\n const matchList: object[] = [];\n\n registry.forEach((asset) => {\n matchList.push(asset.key);\n });\n\n const typeList = matchList.map(\n (match) => JSON.parse(JSON.stringify(match)).type,\n );\n\n const similarType = typeList.reduce((prev, curr) => {\n const next = {\n value: leven(unwrapped.type, curr),\n type: curr,\n };\n\n if (prev !== undefined && prev.value < next.value) {\n return prev;\n }\n\n return next;\n }, undefined);\n\n throw Error(\n `No implementation found for id: ${unwrapped.id} type: ${unwrapped.type}. Did you mean ${similarType.type}? \\n \n Registered Asset matching functions are listed below: \\n\n ${JSON.stringify(matchList)}`,\n );\n }\n\n return <Impl key={unwrapped.id} {...unwrapped} />;\n};\n","import React from \"react\";\nimport type { Player, NavigationFlowViewState } from \"@player-ui/player\";\n\nexport interface PlayerContextType {\n /**\n * An instance of a headless player\n */\n player?: Player;\n\n /** The currently rendered view state */\n viewState?: NavigationFlowViewState;\n}\n\nexport const PlayerContext = React.createContext<PlayerContextType>({});\n\n/**\n * A hook to get the current player\n */\nexport const usePlayer = () => {\n const { player } = React.useContext(PlayerContext);\n\n return player;\n};\n","import type { Logger } from \"@player-ui/player\";\nimport { NoopLogger } from \"@player-ui/player\";\nimport { usePlayer } from \"./player-context\";\n\nconst noopLogger = new NoopLogger();\n\n/**\n * A hook to get the logger instance from the current player\n */\nexport function useLogger(): Logger {\n const player = usePlayer();\n\n return player?.logger ?? noopLogger;\n}\n","import type { Asset } from \"@player-ui/player\";\n\n/** Common props for any dom node */\nexport function useAssetProps(asset: Asset) {\n return {\n id: asset.id,\n \"data-asset-type\": asset.type,\n };\n}\n","/**\n * Trim leading and trailing slashes from string\n */\nexport function trimSlashes(str: string) {\n return str.replace(/^\\/+|\\/+$/g, \"\");\n}\n\n/**\n * Removes any key: value pairs from an object when the value is null or undefined\n */\nexport function removeEmptyValuesFromObject(\n obj: Record<string, any>,\n): Record<string, NonNullable<any>> {\n return Object.keys(obj).reduce(\n (acc, key) => {\n const value = obj[key];\n\n if (value !== null && value !== undefined) {\n acc[key] = value;\n }\n\n return acc;\n },\n {} as Record<string, any>,\n );\n}\n\n/** Check if the object has no keys */\nexport function isEmptyObject(obj: Record<string, unknown>) {\n return Object.keys(obj).length === 0 && obj.constructor === Object;\n}\n\n/** Check if the argument is a function */\nexport function isFunction<ReturnType>(\n maybeFn: ReturnType | ((...args: unknown[]) => ReturnType),\n): maybeFn is (...args: unknown[]) => ReturnType {\n return Boolean(maybeFn instanceof Function || typeof maybeFn === \"function\");\n}\n\n/**\n * Calls function with provided data or returns original value\n */\nexport function callOrReturn<\n ReturnType,\n FnArgs extends Array<unknown> = unknown[],\n FnType = (...args: FnArgs) => ReturnType,\n>(maybeFn: FnType | ReturnType, fnArgs: FnArgs): ReturnType {\n if (isFunction(maybeFn)) {\n return maybeFn(fnArgs) as ReturnType;\n }\n\n return maybeFn as ReturnType;\n}\n","import { isEmptyObject } from \"./helpers\";\n\n/**\n * Combines a URL with any additional parameters\n */\nexport function buildUrl(\n url: string,\n params: Record<string, unknown> = {},\n): string {\n const baseUrl = new URL(url);\n\n if (params && isEmptyObject(params)) {\n return baseUrl.toString();\n }\n\n Object.keys(params).forEach((key) => {\n const value = params[key];\n baseUrl.searchParams.append(key, String(value));\n });\n\n return baseUrl.toString();\n}\n","import { usePlayer } from \"./player-context\";\n\n/** Hook to get a constant under a specific namespace */\nexport function useGetConstantByType(type: string, key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, type);\n}\n\n/** Get a constant under the default namespace */\nexport function useGetConstant(key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, \"constants\");\n}\n","import React from \"react\";\nimport type { View } from \"@player-ui/player\";\nimport { ReactAsset } from \"./asset\";\n\nexport interface ReactPlayerProps {\n /**\n * The Content view object to render\n */\n view: View;\n}\n\n/**\n * The entry for the ReactPlayer's React tree\n */\nconst ReactPlayer = ({ view }: ReactPlayerProps) => {\n return <ReactAsset {...view} />;\n};\n\nexport default ReactPlayer;\n","import type { Player, PlayerPlugin, ViewInstance } from \"@player-ui/player\";\n\nexport type OnUpdateCallback = (update: any) => void;\n\n/**\n * A plugin that listens for view updates and publishes an event for when a view is updated\n */\nexport default class OnUpdatePlugin implements PlayerPlugin {\n name = \"view-update\";\n\n private readonly onUpdateCallback: OnUpdateCallback;\n\n constructor(onUpdate: OnUpdateCallback) {\n this.onUpdateCallback = onUpdate;\n }\n\n apply(player: Player) {\n /** Trigger the callback for the view update */\n const updateTap = (updatedView: any) => {\n this.onUpdateCallback(updatedView);\n };\n\n /** Trigger the callback for the view creation */\n const viewTap = (view: ViewInstance) => {\n view.hooks.onUpdate.tap(this.name, updateTap);\n };\n\n // Attach hooks for any new vc that gets created\n player.hooks.view.tap(this.name, viewTap);\n\n // Attach listeners and publish an update event for a view already in progress\n const currentPlayerState = player.getState();\n\n if (currentPlayerState.status === \"in-progress\") {\n const { currentView } = currentPlayerState.controllers.view;\n\n if (currentView) {\n viewTap(currentView);\n const { lastUpdate } = currentView;\n\n if (lastUpdate) {\n this.onUpdateCallback(lastUpdate);\n }\n }\n }\n }\n}\n","import type { Player, PlayerFlowState } from \"@player-ui/player\";\nimport { NOT_STARTED_STATE } from \"@player-ui/player\";\nimport React from \"react\";\nimport type { ReactPlayerOptions } from \"./player\";\nimport { ReactPlayer } from \"./player\";\nimport { StateTapPlugin } from \"./plugins/tapstate-plugin\";\n\nexport interface UseReactPlayerReturn {\n /** The web-player instance */\n reactPlayer: ReactPlayer;\n /** Player instance */\n player: Player;\n /** The state of Player */\n playerState: PlayerFlowState;\n}\n\n/**\n * The `useReactPlayer` hook is an easy way to integrate the web-player into your React app.\n * Simply supply your config, plugins, and an optional flow, which will be automatically started for you when changed.\n */\nexport const useReactPlayer = (\n options?: ReactPlayerOptions,\n): UseReactPlayerReturn => {\n const [playerState, setPlayerState] =\n React.useState<PlayerFlowState>(NOT_STARTED_STATE);\n\n const reactPlayer = React.useMemo(() => {\n const rp = new ReactPlayer({\n player: options?.player,\n plugins: [\n ...(options?.plugins ?? []),\n new StateTapPlugin(setPlayerState),\n ],\n });\n\n return rp;\n }, []);\n\n const { player } = reactPlayer;\n\n return {\n reactPlayer,\n player,\n playerState,\n };\n};\n","import type { PlayerFlowState, Player } from \"@player-ui/player\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\n/**\n * A plugin to tap into state transition changes and call an arbitrary update function\n */\nexport class StateTapPlugin implements ReactPlayerPlugin {\n name = \"statetap\";\n private callbackFunction: (state: PlayerFlowState) => void;\n\n constructor(callback: (state: PlayerFlowState) => void) {\n this.callbackFunction = callback;\n }\n\n apply(player: Player) {\n player.hooks.state.tap(\"usePlayer\", (newPlayerState: PlayerFlowState) => {\n this.callbackFunction(newPlayerState);\n });\n }\n}\n","import React from \"react\";\nimport type {\n FlowManager,\n ManagedPlayerProps,\n ManagedPlayerState,\n ManagerMiddleware,\n ManagedPlayerContext,\n} from \"./types\";\nimport { useRequestTime } from \"./request-time\";\nimport type { ReactPlayerOptions } from \"../player\";\nimport { ReactPlayer } from \"../player\";\n\n/** noop middleware */\nfunction identityMiddleware<T>(next: Promise<T>) {\n return next;\n}\n\ninterface ManagedPlayerStateKey {\n /** the storage key for the state (outside of the react tree) */\n _key: symbol;\n}\n\nexport interface StateChangeCallback {\n /** Trigger for state changes */\n onState: (s: ManagedPlayerState) => void;\n}\n\n/**\n * An object to store the state of the managed player\n */\nclass ManagedState {\n public state?: ManagedPlayerState;\n private callbacks: Array<StateChangeCallback>;\n private middleware?: ManagerMiddleware;\n\n constructor({\n middleware,\n }: {\n /** middleware to use in the managed player */\n middleware?: ManagerMiddleware;\n }) {\n this.middleware = middleware;\n this.callbacks = [];\n }\n\n /** Add a listener to state changes */\n public addListener(callback: StateChangeCallback): () => void {\n this.callbacks.push(callback);\n\n return () => {\n this.callbacks = this.callbacks.filter((s) => s !== callback);\n };\n }\n\n /** start the managed flow */\n public start(options: {\n /** the flow manager to use */\n manager: FlowManager;\n\n /** the config to use when creating a player */\n playerConfig: ReactPlayerOptions;\n }) {\n const initialState: ManagedPlayerState = {\n value: \"not_started\",\n context: {\n playerConfig: options.playerConfig,\n reactPlayer: new ReactPlayer(options.playerConfig),\n manager: options.manager,\n },\n };\n\n this.setState(initialState);\n\n return this;\n }\n\n /** reset starts from nothing */\n public reset() {\n if (this.state?.value === \"error\") {\n const { playerConfig, manager } = this.state.context;\n this.start({ playerConfig, manager });\n } else {\n throw new Error(\"Flow must be in error state to reset\");\n }\n }\n\n /** restart starts from the last result */\n public restart() {\n if (this.state?.value === \"error\") {\n const { playerConfig, manager, prevResult, reactPlayer } =\n this.state.context;\n this.setState({\n value: \"completed\",\n context: {\n playerConfig,\n manager,\n result: prevResult,\n reactPlayer,\n },\n });\n } else {\n throw new Error(\"Flow must be in error state to restart\");\n }\n }\n\n private async setState(state: ManagedPlayerState) {\n this.state = state;\n this.callbacks.forEach((c) => {\n c.onState(state);\n });\n\n const { manager, reactPlayer, playerConfig } = state.context;\n\n try {\n const nextState = await this.processState(state, {\n manager,\n reactPlayer,\n playerConfig,\n });\n\n if (nextState) {\n this.setState(nextState);\n }\n } catch (e) {\n this.setState({\n value: \"error\",\n context: {\n manager,\n reactPlayer,\n playerConfig,\n error: e as Error,\n },\n });\n }\n }\n\n private async processState(\n state: ManagedPlayerState,\n context: ManagedPlayerContext,\n ): Promise<ManagedPlayerState | undefined> {\n if (state.value === \"not_started\" || state.value === \"completed\") {\n const prevResult =\n state.value === \"completed\" ? state.context.result : undefined;\n\n const middleware = this.middleware?.next ?? identityMiddleware;\n\n return {\n value: \"pending\",\n context: {\n ...context,\n prevResult,\n next: middleware(state.context.manager.next(prevResult)),\n },\n };\n }\n\n if (state.value === \"pending\") {\n const nextResult = await state.context.next;\n\n if (nextResult.done) {\n return {\n value: \"ended\",\n context: {\n ...context,\n result: state.context.prevResult,\n },\n };\n }\n\n return {\n value: \"loaded\",\n context: {\n ...context,\n prevResult: state.context.prevResult,\n flow: nextResult.value,\n },\n };\n }\n\n if (state.value === \"loaded\") {\n return {\n value: \"running\",\n context: {\n ...context,\n flow: state.context.flow,\n prevResult: state.context.prevResult,\n result: state.context.reactPlayer.start(state.context.flow),\n },\n };\n }\n\n if (state.value === \"running\") {\n const result = await state.context.result;\n\n return {\n value: \"completed\",\n context: {\n ...context,\n result,\n },\n };\n }\n }\n}\n\nconst managedPlayerStateMachines = new WeakMap<\n ManagedPlayerStateKey,\n ManagedState\n>();\n\n/** Creates an x-state state machine that persists when this component is no longer renders (due to Suspense) */\nexport const usePersistentStateMachine = (options: {\n /** the flow manager to use */\n manager: FlowManager;\n\n /** Player config */\n playerConfig: ReactPlayerOptions;\n\n /** Any middleware for the manager */\n middleware?: ManagerMiddleware;\n}) => {\n const keyRef = React.useRef<ManagedPlayerStateKey>({\n _key: Symbol(\"managed-player\"),\n });\n\n const managedState =\n managedPlayerStateMachines.get(keyRef.current) ??\n new ManagedState({ middleware: options.middleware });\n managedPlayerStateMachines.set(keyRef.current, managedState);\n const [state, setState] = React.useState(managedState.state);\n\n React.useEffect(() => {\n const unsub = managedState.addListener({\n onState: (s) => {\n setState(s);\n },\n });\n\n if (managedState.state === undefined) {\n managedState.start(options);\n }\n\n return unsub;\n }, []);\n\n return { managedState, state };\n};\n\n/**\n * A ManagedPlayer is a component responsible for orchestrating multi-flow experiences using Player.\n * Provide a valid `FlowManager` to handle fetching the next flow.\n *\n * `suspense` must be enabled to wait for results in flight.\n */\nexport const ManagedPlayer = (props: ManagedPlayerProps) => {\n const { withRequestTime, RequestTimeMetricsPlugin } = useRequestTime();\n\n const { state, managedState } = usePersistentStateMachine({\n manager: props.manager,\n middleware: { next: withRequestTime },\n playerConfig: {\n plugins: [...(props?.plugins ?? []), RequestTimeMetricsPlugin],\n player: props.player,\n },\n });\n\n React.useEffect(() => {\n if (state?.value === \"ended\") {\n props.onComplete?.(state?.context.result);\n } else if (state?.value === \"error\") {\n props.onError?.(state?.context.error);\n } else if (state?.value === \"running\") {\n props.onStartedFlow?.();\n }\n }, [state]);\n\n React.useEffect(() => {\n return () => {\n const playerState = state?.context.reactPlayer.player.getState();\n\n if (state?.value === \"running\" && playerState?.status === \"in-progress\") {\n props.manager.terminate?.(playerState.controllers.data.serialize());\n }\n };\n }, [props.manager, state?.context.reactPlayer.player, state?.value]);\n\n if (state?.value === \"error\") {\n if (props.fallbackComponent) {\n return (\n <props.fallbackComponent\n reset={() => {\n managedState.reset();\n }}\n retry={() => {\n managedState.restart();\n }}\n error={state.context.error}\n />\n );\n }\n\n if (!props.onError) {\n throw state.context.error;\n }\n }\n\n if (state?.context.reactPlayer) {\n const { Component } = state.context.reactPlayer;\n\n return <Component />;\n }\n\n return null;\n};\n","import { useCallback, useEffect, useRef, useMemo } from \"react\";\nimport type { Player } from \"@player-ui/player\";\nimport type { MetricsCorePlugin } from \"@player-ui/metrics-plugin\";\nimport {\n MetricsCorePluginSymbol,\n RequestTimeWebPlugin,\n} from \"@player-ui/metrics-plugin\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\ntype RequestTime = {\n /** request start time */\n start?: number;\n /** request end time */\n end?: number;\n};\n\n/** hook to time a promise and add it to the metrics plugin */\nexport const useRequestTime = () => {\n const requestTimeRef = useRef<RequestTime>({});\n\n useEffect(() => {\n return () => {\n requestTimeRef.current = {};\n };\n }, [requestTimeRef]);\n\n const getRequestTime = useCallback(() => {\n const { end, start } = requestTimeRef.current;\n\n if (end && start) {\n return end - start;\n }\n }, [requestTimeRef]);\n\n /** wrap a promise with tracking it's time in flight */\n function withRequestTime<Type>(nextPromise: Promise<Type>): Promise<Type> {\n const getTime = typeof performance === \"undefined\" ? Date : performance;\n requestTimeRef.current = { start: getTime.now() };\n\n return nextPromise.finally(() => {\n requestTimeRef.current = {\n ...requestTimeRef.current,\n end: getTime.now(),\n };\n });\n }\n\n const RequestTimeMetricsPlugin: ReactPlayerPlugin = useMemo(() => {\n return {\n name: \"RequestTimeMetricsPlugin\",\n apply(player: Player): void {\n player.applyTo<MetricsCorePlugin>(\n MetricsCorePluginSymbol,\n (metricsCorePlugin) => {\n new RequestTimeWebPlugin(getRequestTime).apply(metricsCorePlugin);\n },\n );\n },\n };\n }, [getRequestTime]);\n\n return { withRequestTime, RequestTimeMetricsPlugin };\n};\n"],"mappings":";AAAA,cAAc;;;ACCd,OAAOA,YAAW;AAClB,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,WAAW,0BAA0B;AAC9C,SAAS,gBAAgB;AAOzB,SAAS,cAAc;AACvB,SAAS,qBAAqB;;;ACZ9B,OAAO,WAAW;AAClB,OAAO,WAAW;AAaX,IAAM,eAAe,MAAM,cAA2B,CAAC,CAAC;AAKxD,IAAM,aAAa,CACxB,UACG;AACH,QAAM,EAAE,SAAS,IAAI,MAAM,WAAW,YAAY;AAElD,MAAI;AAEJ,MAAI,UAAU,SAAS,QAAQ,OAAO;AACpC,gBAAY;AAAA,EACd,WAAW,WAAW,OAAO;AAC3B,gBAAa,MAAkC;AAAA,EACjD;AAEA,MAAI,CAAC,WAAW;AACd,UAAM;AAAA,MACJ,0CAA0C,KAAK,UAAU,KAAK,CAAC;AAAA,IACjE;AAAA,EACF;AAEA,MAAI,OAAO,cAAc,UAAU;AACjC,UAAM;AAAA,MACJ,gCAAgC,OAAO,SAAS,cAAc,SAAS;AAAA,IACzE;AAAA,EACF;AAEA,MAAI,UAAU,SAAS,QAAW;AAChC,UAAM,OACJ,UAAU,OAAO,SACb,KAAK,UAAU,KAAK,IACpB,OAAO,UAAU,EAAE;AACzB,UAAM,MAAM,6BAA6B,IAAI,E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AC,MAAM;AAAA,QAAN;AAAA,UACC,OAAO,MAAM;AACX,yBAAa,MAAM;AAAA,UACrB;AAAA,UACA,OAAO,MAAM;AACX,yBAAa,QAAQ;AAAA,UACvB;AAAA,UACA,OAAO,MAAM,QAAQ;AAAA;AAAA,MACvB;AAAA,IAEJ;AAEA,QAAI,CAAC,MAAM,SAAS;AAClB,YAAM,MAAM,QAAQ;AAAA,IACtB;AAAA,EACF;AAEA,MAAI,OAAO,QAAQ,aAAa;AAC9B,UAAM,EAAE,UAAU,IAAI,MAAM,QAAQ;AAEpC,WAAO,gBAAAA,OAAA,cAAC,eAAU;AAAA,EACpB;AAEA,SAAO;AACT;","names":["React","React","React","React","ReactPlayer","React","React","React","ReactPlayer","React","ReactPlayer","React"]}
1
+ {"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/player-context.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-logger.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-asset-props.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/helpers.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/url.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/shared-constants.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/app.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/onupdate-plugin.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/hooks.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/tapstate-plugin.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/managed-player.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/request-time.tsx"],"sourcesContent":["export * from \"@player-ui/player\";\nexport * from \"./player\";\nexport * from \"./hooks\";\nexport * from \"./manager/managed-player\";\nexport * from \"./manager/request-time\";\nexport * from \"./manager/types\";\nexport * from \"./asset\";\nexport * from \"./utils\";\n","/* eslint-disable react/no-this-in-sfc */\nimport React from \"react\";\nimport { SyncWaterfallHook, AsyncParallelHook } from \"tapable-ts\";\nimport { Subscribe, useSubscribedState } from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n Flow,\n View,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport PlayerComp from \"./app\";\nimport OnUpdatePlugin from \"./plugins/onupdate-plugin\";\n\nconst WEB_PLAYER_VERSION = \"__VERSION__\";\nconst COMMIT = \"__GIT_COMMIT__\";\n\nexport interface DevtoolsGlobals {\n /** A global for a plugin to load to Player for devtools */\n __PLAYER_DEVTOOLS_PLUGIN?: {\n new (): ReactPlayerPlugin;\n };\n}\n\nexport type DevtoolsWindow = typeof window & DevtoolsGlobals;\n\nconst _window: DevtoolsWindow | undefined =\n typeof window === \"undefined\" ? undefined : window;\n\nexport interface ReactPlayerInfo {\n /** Version of the running player */\n playerVersion: string;\n\n /** Version of the running reactPlayer */\n reactPlayerVersion: string;\n\n /** Hash of the HEAD commit used to build the current player version */\n playerCommit: string;\n\n /** Hash of the HEAD commit used to build the current reactPlayer version */\n reactPlayerCommit: string;\n}\n\nexport interface ReactPlayerPlugin extends Partial<PlayerPlugin> {\n /** The name of this plugin */\n name: string;\n\n /**\n * Attach listeners to the web-player instance\n */\n applyReact?: (reactPlayer: ReactPlayer) => void;\n}\n\nexport interface ReactPlayerOptions {\n /** A headless player instance to use */\n player?: Player;\n\n /** A set of plugins to apply to this player */\n plugins?: Array<ReactPlayerPlugin>;\n}\n\nexport type ReactPlayerComponentProps = Record<string, unknown>;\n\n/** A Player that renders UI through React */\nexport class ReactPlayer {\n public readonly options: ReactPlayerOptions;\n public readonly player: Player;\n public readonly assetRegistry: AssetRegistryType = new Registry();\n public readonly Component: React.ComponentType<ReactPlayerComponentProps>;\n public readonly hooks = {\n /**\n * A hook to create a React Component to be used for Player, regardless of the current flow state\n */\n webComponent: new SyncWaterfallHook<[React.ComponentType]>(),\n\n /**\n * A hook to create a React Component that's used to render a specific view.\n * It will be called for each view update from the core player.\n * Typically this will just be `Asset`\n */\n playerComponent: new SyncWaterfallHook<\n [React.ComponentType<ReactPlayerProps>]\n >(),\n\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: new AsyncParallelHook<[]>(),\n };\n\n private viewUpdateSubscription = new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n this.options = options ?? {};\n\n const Devtools = _window?.__PLAYER_DEVTOOLS_PLUGIN;\n const onUpdatePlugin = new OnUpdatePlugin(\n this.viewUpdateSubscription.publish,\n );\n\n const plugins = options?.plugins ?? [];\n\n if (Devtools) {\n plugins.push(new Devtools());\n }\n\n const playerPlugins = plugins.filter((p) =>\n Boolean(p.apply),\n ) as PlayerPlugin[];\n\n this.player = options?.player ?? new Player({ plugins: playerPlugins });\n\n plugins.forEach((plugin) => {\n if (plugin.applyReact) {\n plugin.applyReact(this);\n }\n });\n\n onUpdatePlugin.apply(this.player);\n\n this.Component = this.createReactPlayerComponent();\n this.reactPlayerInfo = {\n playerVersion: this.player.getVersion(),\n playerCommit: this.player.getCommit(),\n reactPlayerVersion: WEB_PLAYER_VERSION,\n reactPlayerCommit: COMMIT,\n };\n }\n\n /** Returns the current version of the underlying core Player */\n public getPlayerVersion(): string {\n return this.reactPlayerInfo.playerVersion;\n }\n\n /** Returns the git commit used to build this core Player version */\n public getPlayerCommit(): string {\n return this.reactPlayerInfo.playerCommit;\n }\n\n /** Find instance of [Plugin] that has been registered to the web player */\n public findPlugin<Plugin extends ReactPlayerPlugin>(\n symbol: symbol,\n ): Plugin | undefined {\n return this.options.plugins?.find((el) => el.symbol === symbol) as Plugin;\n }\n\n /** Register and apply [Plugin] if one with the same symbol is not already registered. */\n public registerPlugin(plugin: ReactPlayerPlugin): void {\n if (!plugin.applyReact) return;\n\n plugin.applyReact(this);\n this.options.plugins?.push(plugin);\n }\n\n /** Returns the current version of the running React Player */\n public getReactPlayerVersion(): string {\n return this.reactPlayerInfo.reactPlayerVersion;\n }\n\n /** Returns the git commit used to build the React Player version */\n public getReactPlayerCommit(): string {\n return this.reactPlayerInfo.reactPlayerCommit;\n }\n\n private createReactPlayerComponent(): React.ComponentType<ReactPlayerComponentProps> {\n const BaseComp = this.hooks.webComponent.call(this.createReactComp());\n\n /** Wrap the Error boundary and context provider after the hook call to catch anything wrapped by the hook */\n const ReactPlayerComponent = (props: ReactPlayerComponentProps) => {\n return (\n <ErrorBoundary\n fallbackRender={() => null}\n onError={(err) => {\n const playerState = this.player.getState();\n\n if (playerState.status === \"in-progress\") {\n playerState.fail(err);\n }\n }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...props} />\n </PlayerContext.Provider>\n </ErrorBoundary>\n );\n };\n\n return ReactPlayerComponent;\n }\n\n private createReactComp(): React.ComponentType<ReactPlayerComponentProps> {\n const ActualPlayerComp = this.hooks.playerComponent.call(PlayerComp);\n\n /** the component to use to render the player */\n const WebPlayerComponent = () => {\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n this.viewUpdateSubscription.suspend();\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {view && <ActualPlayerComp view={view} />}\n </AssetContext.Provider>\n );\n };\n\n return WebPlayerComponent;\n }\n\n /**\n * Call this method to force the ReactPlayer to wait for the next view-update before performing the next render.\n * If the `suspense` option is set, this will suspend while an update is pending, otherwise nothing will be rendered.\n */\n public setWaitForNextViewUpdate() {\n const shouldCallResetHook = this.hooks.onBeforeViewReset.isUsed();\n\n return this.viewUpdateSubscription.reset(\n shouldCallResetHook ? this.hooks.onBeforeViewReset.call() : undefined,\n );\n }\n\n public start(flow: Flow): Promise<CompletedState> {\n this.setWaitForNextViewUpdate();\n\n return this.player.start(flow).finally(async () => {\n await this.setWaitForNextViewUpdate();\n });\n }\n}\n\n// For compatibility\nexport const WebPlayer = ReactPlayer;\n","import React from \"react\";\nimport leven from \"leven\";\nimport type { Asset as AssetType, AssetWrapper } from \"@player-ui/player\";\nimport type { Registry } from \"@player-ui/partial-match-registry\";\n\nexport type AssetRegistryType = Registry<React.ComponentType<any>>;\n\nexport interface ContextType {\n /**\n * A registry of Asset -> React Components\n */\n registry?: AssetRegistryType;\n}\n\nexport const AssetContext = React.createContext<ContextType>({});\n\n/**\n * A React Component that looks up an implementation from a registry\n */\nexport const ReactAsset = (\n props: AssetType<string> | AssetWrapper<AssetType<string>>,\n) => {\n const { registry } = React.useContext(AssetContext);\n\n let unwrapped;\n\n if (\"type\" in props && \"id\" in props) {\n unwrapped = props;\n } else if (\"asset\" in props) {\n unwrapped = (props as unknown as AssetWrapper).asset;\n }\n\n if (!unwrapped) {\n throw Error(\n `Cannot determine asset type for props: ${JSON.stringify(props)}`,\n );\n }\n\n if (typeof unwrapped !== \"object\") {\n throw Error(\n `Asset was not an object got (${typeof unwrapped}) instead: ${unwrapped}`,\n );\n }\n\n if (unwrapped.type === undefined) {\n const info =\n unwrapped.id === undefined\n ? JSON.stringify(props)\n : `id: ${unwrapped.id}`;\n throw Error(`Asset is missing type for ${info}`);\n }\n\n if (!registry || registry.isRegistryEmpty()) {\n throw Error(`No asset found in registry. This could happen for one of the following reasons: \\n\n 1. You might have no assets registered or no plugins added to the Player instance. \\n\n 2. You might have mismatching versions of React Asset Registry Context. \\n\n See https://player-ui.github.io/latest/tools/cli#player-dependency-versions-check for tips about how to debug and fix this problem`);\n }\n\n const Impl = registry?.get(unwrapped);\n\n if (!Impl) {\n const matchList: object[] = [];\n\n registry.forEach((asset) => {\n matchList.push(asset.key);\n });\n\n const typeList = matchList.map(\n (match) => JSON.parse(JSON.stringify(match)).type,\n );\n\n const similarType = typeList.reduce((prev, curr) => {\n const next = {\n value: leven(unwrapped.type, curr),\n type: curr,\n };\n\n if (prev !== undefined && prev.value < next.value) {\n return prev;\n }\n\n return next;\n }, undefined);\n\n throw Error(\n `No implementation found for id: ${unwrapped.id} type: ${unwrapped.type}. Did you mean ${similarType.type}? \\n \n Registered Asset matching functions are listed below: \\n\n ${JSON.stringify(matchList)}`,\n );\n }\n\n return <Impl key={unwrapped.id} {...unwrapped} />;\n};\n","import React from \"react\";\nimport type { Player, NavigationFlowViewState } from \"@player-ui/player\";\n\nexport interface PlayerContextType {\n /**\n * An instance of a headless player\n */\n player?: Player;\n\n /** The currently rendered view state */\n viewState?: NavigationFlowViewState;\n}\n\nexport const PlayerContext = React.createContext<PlayerContextType>({});\n\n/**\n * A hook to get the current player\n */\nexport const usePlayer = () => {\n const { player } = React.useContext(PlayerContext);\n\n return player;\n};\n","import type { Logger } from \"@player-ui/player\";\nimport { NoopLogger } from \"@player-ui/player\";\nimport { usePlayer } from \"./player-context\";\n\nconst noopLogger = new NoopLogger();\n\n/**\n * A hook to get the logger instance from the current player\n */\nexport function useLogger(): Logger {\n const player = usePlayer();\n\n return player?.logger ?? noopLogger;\n}\n","import type { Asset } from \"@player-ui/player\";\n\n/** Common props for any dom node */\nexport function useAssetProps(asset: Asset) {\n return {\n id: asset.id,\n \"data-asset-type\": asset.type,\n };\n}\n","/**\n * Trim leading and trailing slashes from string\n */\nexport function trimSlashes(str: string) {\n return str.replace(/^\\/+|\\/+$/g, \"\");\n}\n\n/**\n * Removes any key: value pairs from an object when the value is null or undefined\n */\nexport function removeEmptyValuesFromObject(\n obj: Record<string, any>,\n): Record<string, NonNullable<any>> {\n return Object.keys(obj).reduce(\n (acc, key) => {\n const value = obj[key];\n\n if (value !== null && value !== undefined) {\n acc[key] = value;\n }\n\n return acc;\n },\n {} as Record<string, any>,\n );\n}\n\n/** Check if the object has no keys */\nexport function isEmptyObject(obj: Record<string, unknown>) {\n return Object.keys(obj).length === 0 && obj.constructor === Object;\n}\n\n/** Check if the argument is a function */\nexport function isFunction<ReturnType>(\n maybeFn: ReturnType | ((...args: unknown[]) => ReturnType),\n): maybeFn is (...args: unknown[]) => ReturnType {\n return Boolean(maybeFn instanceof Function || typeof maybeFn === \"function\");\n}\n\n/**\n * Calls function with provided data or returns original value\n */\nexport function callOrReturn<\n ReturnType,\n FnArgs extends Array<unknown> = unknown[],\n FnType = (...args: FnArgs) => ReturnType,\n>(maybeFn: FnType | ReturnType, fnArgs: FnArgs): ReturnType {\n if (isFunction(maybeFn)) {\n return maybeFn(fnArgs) as ReturnType;\n }\n\n return maybeFn as ReturnType;\n}\n","import { isEmptyObject } from \"./helpers\";\n\n/**\n * Combines a URL with any additional parameters\n */\nexport function buildUrl(\n url: string,\n params: Record<string, unknown> = {},\n): string {\n const baseUrl = new URL(url);\n\n if (params && isEmptyObject(params)) {\n return baseUrl.toString();\n }\n\n Object.keys(params).forEach((key) => {\n const value = params[key];\n baseUrl.searchParams.append(key, String(value));\n });\n\n return baseUrl.toString();\n}\n","import { usePlayer } from \"./player-context\";\n\n/** Hook to get a constant under a specific namespace */\nexport function useGetConstantByType(type: string, key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, type);\n}\n\n/** Get a constant under the default namespace */\nexport function useGetConstant(key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, \"constants\");\n}\n","import React from \"react\";\nimport type { View } from \"@player-ui/player\";\nimport { ReactAsset } from \"./asset\";\n\nexport interface ReactPlayerProps {\n /**\n * The Content view object to render\n */\n view: View;\n}\n\n/**\n * The entry for the ReactPlayer's React tree\n */\nconst ReactPlayer = ({ view }: ReactPlayerProps) => {\n return <ReactAsset {...view} />;\n};\n\nexport default ReactPlayer;\n","import type { Player, PlayerPlugin, ViewInstance } from \"@player-ui/player\";\n\nexport type OnUpdateCallback = (update: any) => void;\n\n/**\n * A plugin that listens for view updates and publishes an event for when a view is updated\n */\nexport default class OnUpdatePlugin implements PlayerPlugin {\n name = \"view-update\";\n\n private readonly onUpdateCallback: OnUpdateCallback;\n\n constructor(onUpdate: OnUpdateCallback) {\n this.onUpdateCallback = onUpdate;\n }\n\n apply(player: Player) {\n /** Trigger the callback for the view update */\n const updateTap = (updatedView: any) => {\n this.onUpdateCallback(updatedView);\n };\n\n /** Trigger the callback for the view creation */\n const viewTap = (view: ViewInstance) => {\n view.hooks.onUpdate.tap(this.name, updateTap);\n };\n\n // Attach hooks for any new vc that gets created\n player.hooks.view.tap(this.name, viewTap);\n\n // Attach listeners and publish an update event for a view already in progress\n const currentPlayerState = player.getState();\n\n if (currentPlayerState.status === \"in-progress\") {\n const { currentView } = currentPlayerState.controllers.view;\n\n if (currentView) {\n viewTap(currentView);\n const { lastUpdate } = currentView;\n\n if (lastUpdate) {\n this.onUpdateCallback(lastUpdate);\n }\n }\n }\n }\n}\n","import type { Player, PlayerFlowState } from \"@player-ui/player\";\nimport { NOT_STARTED_STATE } from \"@player-ui/player\";\nimport React from \"react\";\nimport type { ReactPlayerOptions } from \"./player\";\nimport { ReactPlayer } from \"./player\";\nimport { StateTapPlugin } from \"./plugins/tapstate-plugin\";\n\nexport interface UseReactPlayerReturn {\n /** The web-player instance */\n reactPlayer: ReactPlayer;\n /** Player instance */\n player: Player;\n /** The state of Player */\n playerState: PlayerFlowState;\n}\n\n/**\n * The `useReactPlayer` hook is an easy way to integrate the web-player into your React app.\n * Simply supply your config, plugins, and an optional flow, which will be automatically started for you when changed.\n */\nexport const useReactPlayer = (\n options?: ReactPlayerOptions,\n): UseReactPlayerReturn => {\n const [playerState, setPlayerState] =\n React.useState<PlayerFlowState>(NOT_STARTED_STATE);\n\n const reactPlayer = React.useMemo(() => {\n const rp = new ReactPlayer({\n player: options?.player,\n plugins: [\n ...(options?.plugins ?? []),\n new StateTapPlugin(setPlayerState),\n ],\n });\n\n return rp;\n }, []);\n\n const { player } = reactPlayer;\n\n return {\n reactPlayer,\n player,\n playerState,\n };\n};\n","import type { PlayerFlowState, Player } from \"@player-ui/player\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\n/**\n * A plugin to tap into state transition changes and call an arbitrary update function\n */\nexport class StateTapPlugin implements ReactPlayerPlugin {\n name = \"statetap\";\n private callbackFunction: (state: PlayerFlowState) => void;\n\n constructor(callback: (state: PlayerFlowState) => void) {\n this.callbackFunction = callback;\n }\n\n apply(player: Player) {\n player.hooks.state.tap(\"usePlayer\", (newPlayerState: PlayerFlowState) => {\n this.callbackFunction(newPlayerState);\n });\n }\n}\n","import React from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport type {\n FlowManager,\n ManagedPlayerProps,\n ManagedPlayerState,\n ManagerMiddleware,\n ManagedPlayerContext,\n} from \"./types\";\nimport { useRequestTime } from \"./request-time\";\nimport type { ReactPlayerOptions } from \"../player\";\nimport { ReactPlayer } from \"../player\";\n\n/** noop middleware */\nfunction identityMiddleware<T>(next: Promise<T>) {\n return next;\n}\n\ninterface ManagedPlayerStateKey {\n /** the storage key for the state (outside of the react tree) */\n _key: symbol;\n}\n\nexport interface StateChangeCallback {\n /** Trigger for state changes */\n onState: (s: ManagedPlayerState) => void;\n}\n\n/**\n * An object to store the state of the managed player\n */\nclass ManagedState {\n public state?: ManagedPlayerState;\n private callbacks: Array<StateChangeCallback>;\n private middleware?: ManagerMiddleware;\n\n constructor({\n middleware,\n }: {\n /** middleware to use in the managed player */\n middleware?: ManagerMiddleware;\n }) {\n this.middleware = middleware;\n this.callbacks = [];\n // this.state = {\n // value: \"uninitialized\",\n // context: {},\n // };\n }\n\n /** Add a listener to state changes */\n public addListener = (callback: StateChangeCallback): (() => void) => {\n this.callbacks.push(callback);\n\n return () => {\n this.callbacks = this.callbacks.filter((s) => s !== callback);\n };\n };\n\n public getSnapshot = (): ManagedPlayerState | undefined => {\n return this.state;\n };\n\n /** start the managed flow */\n public start(options: {\n /** the flow manager to use */\n manager: FlowManager;\n\n /** the config to use when creating a player */\n playerConfig: ReactPlayerOptions;\n }): this {\n const initialState: ManagedPlayerState = {\n value: \"not_started\",\n context: {\n playerConfig: options.playerConfig,\n reactPlayer: new ReactPlayer(options.playerConfig),\n manager: options.manager,\n },\n };\n\n this.setState(initialState);\n\n return this;\n }\n\n /** reset starts from nothing */\n public reset(): void {\n if (this.state?.value === \"error\") {\n const { playerConfig, manager } = this.state.context;\n this.start({ playerConfig, manager });\n } else {\n throw new Error(\"Flow must be in error state to reset\");\n }\n }\n\n /** restart starts from the last result */\n public restart(): void {\n if (this.state?.value === \"error\") {\n const { playerConfig, manager, prevResult, reactPlayer } =\n this.state.context;\n this.setState({\n value: \"completed\",\n context: {\n playerConfig,\n manager,\n result: prevResult,\n reactPlayer,\n },\n });\n } else {\n throw new Error(\"Flow must be in error state to restart\");\n }\n }\n\n private async setState(state: ManagedPlayerState) {\n this.state = state;\n this.callbacks.forEach((c) => {\n c.onState(state);\n });\n\n const { manager, reactPlayer, playerConfig } = state.context;\n\n try {\n const nextState = await this.processState(state, {\n manager,\n reactPlayer,\n playerConfig,\n });\n\n if (nextState) {\n this.setState(nextState);\n }\n } catch (e) {\n this.setState({\n value: \"error\",\n context: {\n manager,\n reactPlayer,\n playerConfig,\n error: e as Error,\n },\n });\n }\n }\n\n private async processState(\n state: ManagedPlayerState,\n context: ManagedPlayerContext,\n ): Promise<ManagedPlayerState | undefined> {\n if (state.value === \"not_started\" || state.value === \"completed\") {\n const prevResult =\n state.value === \"completed\" ? state.context.result : undefined;\n\n const middleware = this.middleware?.next ?? identityMiddleware;\n\n return {\n value: \"pending\",\n context: {\n ...context,\n prevResult,\n next: middleware(state.context.manager.next(prevResult)),\n },\n };\n }\n\n if (state.value === \"pending\") {\n const nextResult = await state.context.next;\n\n if (nextResult.done) {\n return {\n value: \"ended\",\n context: {\n ...context,\n result: state.context.prevResult,\n },\n };\n }\n\n return {\n value: \"loaded\",\n context: {\n ...context,\n prevResult: state.context.prevResult,\n flow: nextResult.value,\n },\n };\n }\n\n if (state.value === \"loaded\") {\n return {\n value: \"running\",\n context: {\n ...context,\n flow: state.context.flow,\n prevResult: state.context.prevResult,\n result: state.context.reactPlayer.start(state.context.flow),\n },\n };\n }\n\n if (state.value === \"running\") {\n const result = await state.context.result;\n\n return {\n value: \"completed\",\n context: {\n ...context,\n result,\n },\n };\n }\n }\n}\n\nconst managedPlayerStateMachines = new WeakMap<\n ManagedPlayerStateKey,\n ManagedState\n>();\n\n/**\n * Helper to make a unique symbol\n */\nfunction createKey() {\n return {\n _key: Symbol(\"managed-player\"),\n };\n}\n\n/** Creates an x-state state machine that persists when this component is no longer rendered (due to Suspense) */\nexport const createPersistentStateMachine = (\n keyRef: React.MutableRefObject<ManagedPlayerStateKey>,\n middleware?: ManagerMiddleware,\n): ManagedState => {\n const managedState =\n managedPlayerStateMachines.get(keyRef.current) ??\n new ManagedState({ middleware: middleware });\n managedPlayerStateMachines.set(keyRef.current, managedState);\n\n return managedState;\n};\n\n/**\n * A ManagedPlayer is a component responsible for orchestrating multi-flow experiences using Player.\n * Provide a valid `FlowManager` to handle fetching the next flow.\n *\n * `suspense` must be enabled to wait for results in flight.\n */\nexport const ManagedPlayer = (\n props: ManagedPlayerProps,\n): React.JSX.Element | null => {\n const keyRef = React.useRef<ManagedPlayerStateKey>(createKey());\n const { withRequestTime, RequestTimeMetricsPlugin } = useRequestTime();\n\n const initialState = createPersistentStateMachine(keyRef, {\n next: withRequestTime,\n });\n\n const [managedState, setManagedState] = React.useState(initialState);\n const wrappedListener = React.useCallback(\n (cb: (s: ManagedPlayerState) => void) => {\n return managedState.addListener({\n onState(s) {\n cb(s);\n },\n });\n },\n [managedState],\n );\n\n // const [state, setState] = React.useState(managedState.state);\n const state = useSyncExternalStore(wrappedListener, managedState.getSnapshot);\n\n React.useEffect(() => {\n if (state?.value === \"ended\") {\n if (props.manager !== state.context.manager) {\n keyRef.current = createKey();\n const newManagedState = createPersistentStateMachine(keyRef, {\n next: withRequestTime,\n });\n setManagedState(newManagedState);\n // setState(newManagedState.state);\n } else {\n props.onComplete?.(state?.context.result);\n }\n } else if (state?.value === \"error\") {\n props.onError?.(state?.context.error);\n } else if (state?.value === \"running\") {\n props.onStartedFlow?.();\n } else if (state === undefined) {\n managedState.start({\n manager: props.manager,\n playerConfig: {\n plugins: [...(props?.plugins ?? []), RequestTimeMetricsPlugin],\n player: props.player,\n },\n });\n }\n }, [state]);\n\n React.useEffect(() => {\n return () => {\n const playerState = state?.context?.reactPlayer?.player?.getState();\n\n if (state?.value === \"running\" && playerState?.status === \"in-progress\") {\n props.manager.terminate?.(playerState.controllers.data.serialize());\n }\n };\n }, [props.manager, state?.context?.reactPlayer?.player, state?.value]);\n\n if (state?.value === \"error\") {\n if (props.fallbackComponent) {\n return (\n <props.fallbackComponent\n reset={() => {\n managedState.reset();\n }}\n retry={() => {\n managedState.restart();\n }}\n error={state.context.error}\n />\n );\n }\n\n if (!props.onError) {\n throw state.context.error;\n }\n }\n\n if (state?.context.reactPlayer) {\n const { Component } = state.context.reactPlayer;\n\n return <Component />;\n }\n\n return null;\n};\n","import { useCallback, useEffect, useRef, useMemo } from \"react\";\nimport type { Player } from \"@player-ui/player\";\nimport type { MetricsCorePlugin } from \"@player-ui/metrics-plugin\";\nimport {\n MetricsCorePluginSymbol,\n RequestTimeWebPlugin,\n} from \"@player-ui/metrics-plugin\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\ntype RequestTime = {\n /** request start time */\n start?: number;\n /** request end time */\n end?: number;\n};\n\n/** hook to time a promise and add it to the metrics plugin */\nexport const useRequestTime = () => {\n const requestTimeRef = useRef<RequestTime>({});\n\n useEffect(() => {\n return () => {\n requestTimeRef.current = {};\n };\n }, [requestTimeRef]);\n\n const getRequestTime = useCallback(() => {\n const { end, start } = requestTimeRef.current;\n\n if (end && start) {\n return end - start;\n }\n }, [requestTimeRef]);\n\n /** wrap a promise with tracking it's time in flight */\n function withRequestTime<Type>(nextPromise: Promise<Type>): Promise<Type> {\n const getTime = typeof performance === \"undefined\" ? Date : performance;\n requestTimeRef.current = { start: getTime.now() };\n\n return nextPromise.finally(() => {\n requestTimeRef.current = {\n ...requestTimeRef.current,\n end: getTime.now(),\n };\n });\n }\n\n const RequestTimeMetricsPlugin: ReactPlayerPlugin = useMemo(() => {\n return {\n name: \"RequestTimeMetricsPlugin\",\n apply(player: Player): void {\n player.applyTo<MetricsCorePlugin>(\n MetricsCorePluginSymbol,\n (metricsCorePlugin) => {\n new RequestTimeWebPlugin(getRequestTime).apply(metricsCorePlugin);\n },\n );\n },\n };\n }, [getRequestTime]);\n\n return { withRequestTime, RequestTimeMetricsPlugin };\n};\n"],"mappings":";AAAA,cAAc;;;ACCd,OAAOA,YAAW;AAClB,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,WAAW,0BAA0B;AAC9C,SAAS,gBAAgB;AAOzB,SAAS,cAAc;AACvB,SAAS,qBAAqB;;;ACZ9B,OAAO,WAAW;AAClB,OAAO,WAAW;AAaX,IAAM,eAAe,MAAM,cAA2B,CAAC,CAAC;AAKxD,IAAM,aAAa,CACxB,UACG;AACH,QAAM,EAAE,SAAS,IAAI,MAAM,WAAW,YAAY;AAElD,MAAI;AAEJ,MAAI,UAAU,SAAS,QAAQ,OAAO;AACpC,gBAAY;AAAA,EACd,WAAW,WAAW,OAAO;AAC3B,gBAAa,MAAkC;AAAA,EACjD;AAEA,MAAI,CAAC,WAAW;AACd,UAAM;AAAA,MACJ,0CAA0C,KAAK,UAAU,KAAK,CAAC;AA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AS,MAAM;AAAA,QACf,cAAc;AAAA,UACZ,SAAS,CAAC,GAAI,OAAO,WAAW,CAAC,GAAI,wBAAwB;AAAA,UAC7D,QAAQ,MAAM;AAAA,QAChB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,KAAK,CAAC;AAEV,EAAAA,OAAM,UAAU,MAAM;AACpB,WAAO,MAAM;AACX,YAAM,cAAc,OAAO,SAAS,aAAa,QAAQ,SAAS;AAElE,UAAI,OAAO,UAAU,aAAa,aAAa,WAAW,eAAe;AACvE,cAAM,QAAQ,YAAY,YAAY,YAAY,KAAK,UAAU,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,SAAS,OAAO,SAAS,aAAa,QAAQ,OAAO,KAAK,CAAC;AAErE,MAAI,OAAO,UAAU,SAAS;AAC5B,QAAI,MAAM,mBAAmB;AAC3B,aACE,gBAAAA,OAAA;AAAA,QAAC,MAAM;AAAA,QAAN;AAAA,UACC,OAAO,MAAM;AACX,yBAAa,MAAM;AAAA,UACrB;AAAA,UACA,OAAO,MAAM;AACX,yBAAa,QAAQ;AAAA,UACvB;AAAA,UACA,OAAO,MAAM,QAAQ;AAAA;AAAA,MACvB;AAAA,IAEJ;AAEA,QAAI,CAAC,MAAM,SAAS;AAClB,YAAM,MAAM,QAAQ;AAAA,IACtB;AAAA,EACF;AAEA,MAAI,OAAO,QAAQ,aAAa;AAC9B,UAAM,EAAE,UAAU,IAAI,MAAM,QAAQ;AAEpC,WAAO,gBAAAA,OAAA,cAAC,eAAU;AAAA,EACpB;AAEA,SAAO;AACT;","names":["React","React","React","React","ReactPlayer","React","React","React","ReactPlayer","React","ReactPlayer","React"]}
package/package.json CHANGED
@@ -6,16 +6,18 @@
6
6
  "types"
7
7
  ],
8
8
  "name": "@player-ui/react",
9
- "version": "0.10.4",
9
+ "version": "0.10.5--canary.606.20908",
10
10
  "main": "dist/cjs/index.cjs",
11
11
  "dependencies": {
12
- "@player-ui/metrics-plugin": "0.10.4",
13
- "@player-ui/partial-match-registry": "0.10.4",
14
- "@player-ui/player": "0.10.4",
15
- "@player-ui/react-subscribe": "0.10.4",
12
+ "@player-ui/metrics-plugin": "0.10.5--canary.606.20908",
13
+ "@player-ui/partial-match-registry": "0.10.5--canary.606.20908",
14
+ "@player-ui/player": "0.10.5--canary.606.20908",
15
+ "@player-ui/react-subscribe": "0.10.5--canary.606.20908",
16
+ "@types/use-sync-external-store": "^0.0.6",
16
17
  "react-error-boundary": "^3.1.3",
17
18
  "tapable-ts": "^0.2.3",
18
19
  "leven": "3.1.0",
20
+ "use-sync-external-store": "^1.4.0",
19
21
  "tslib": "^2.6.2"
20
22
  },
21
23
  "devDependencies": {
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
2
3
  import type {
3
4
  FlowManager,
4
5
  ManagedPlayerProps,
@@ -41,16 +42,24 @@ class ManagedState {
41
42
  }) {
42
43
  this.middleware = middleware;
43
44
  this.callbacks = [];
45
+ // this.state = {
46
+ // value: "uninitialized",
47
+ // context: {},
48
+ // };
44
49
  }
45
50
 
46
51
  /** Add a listener to state changes */
47
- public addListener(callback: StateChangeCallback): () => void {
52
+ public addListener = (callback: StateChangeCallback): (() => void) => {
48
53
  this.callbacks.push(callback);
49
54
 
50
55
  return () => {
51
56
  this.callbacks = this.callbacks.filter((s) => s !== callback);
52
57
  };
53
- }
58
+ };
59
+
60
+ public getSnapshot = (): ManagedPlayerState | undefined => {
61
+ return this.state;
62
+ };
54
63
 
55
64
  /** start the managed flow */
56
65
  public start(options: {
@@ -59,7 +68,7 @@ class ManagedState {
59
68
 
60
69
  /** the config to use when creating a player */
61
70
  playerConfig: ReactPlayerOptions;
62
- }) {
71
+ }): this {
63
72
  const initialState: ManagedPlayerState = {
64
73
  value: "not_started",
65
74
  context: {
@@ -75,7 +84,7 @@ class ManagedState {
75
84
  }
76
85
 
77
86
  /** reset starts from nothing */
78
- public reset() {
87
+ public reset(): void {
79
88
  if (this.state?.value === "error") {
80
89
  const { playerConfig, manager } = this.state.context;
81
90
  this.start({ playerConfig, manager });
@@ -85,7 +94,7 @@ class ManagedState {
85
94
  }
86
95
 
87
96
  /** restart starts from the last result */
88
- public restart() {
97
+ public restart(): void {
89
98
  if (this.state?.value === "error") {
90
99
  const { playerConfig, manager, prevResult, reactPlayer } =
91
100
  this.state.context;
@@ -208,42 +217,26 @@ const managedPlayerStateMachines = new WeakMap<
208
217
  ManagedState
209
218
  >();
210
219
 
211
- /** Creates an x-state state machine that persists when this component is no longer renders (due to Suspense) */
212
- export const usePersistentStateMachine = (options: {
213
- /** the flow manager to use */
214
- manager: FlowManager;
215
-
216
- /** Player config */
217
- playerConfig: ReactPlayerOptions;
218
-
219
- /** Any middleware for the manager */
220
- middleware?: ManagerMiddleware;
221
- }) => {
222
- const keyRef = React.useRef<ManagedPlayerStateKey>({
220
+ /**
221
+ * Helper to make a unique symbol
222
+ */
223
+ function createKey() {
224
+ return {
223
225
  _key: Symbol("managed-player"),
224
- });
226
+ };
227
+ }
225
228
 
229
+ /** Creates an x-state state machine that persists when this component is no longer rendered (due to Suspense) */
230
+ export const createPersistentStateMachine = (
231
+ keyRef: React.MutableRefObject<ManagedPlayerStateKey>,
232
+ middleware?: ManagerMiddleware,
233
+ ): ManagedState => {
226
234
  const managedState =
227
235
  managedPlayerStateMachines.get(keyRef.current) ??
228
- new ManagedState({ middleware: options.middleware });
236
+ new ManagedState({ middleware: middleware });
229
237
  managedPlayerStateMachines.set(keyRef.current, managedState);
230
- const [state, setState] = React.useState(managedState.state);
231
-
232
- React.useEffect(() => {
233
- const unsub = managedState.addListener({
234
- onState: (s) => {
235
- setState(s);
236
- },
237
- });
238
238
 
239
- if (managedState.state === undefined) {
240
- managedState.start(options);
241
- }
242
-
243
- return unsub;
244
- }, []);
245
-
246
- return { managedState, state };
239
+ return managedState;
247
240
  };
248
241
 
249
242
  /**
@@ -252,37 +245,67 @@ export const usePersistentStateMachine = (options: {
252
245
  *
253
246
  * `suspense` must be enabled to wait for results in flight.
254
247
  */
255
- export const ManagedPlayer = (props: ManagedPlayerProps) => {
248
+ export const ManagedPlayer = (
249
+ props: ManagedPlayerProps,
250
+ ): React.JSX.Element | null => {
251
+ const keyRef = React.useRef<ManagedPlayerStateKey>(createKey());
256
252
  const { withRequestTime, RequestTimeMetricsPlugin } = useRequestTime();
257
253
 
258
- const { state, managedState } = usePersistentStateMachine({
259
- manager: props.manager,
260
- middleware: { next: withRequestTime },
261
- playerConfig: {
262
- plugins: [...(props?.plugins ?? []), RequestTimeMetricsPlugin],
263
- player: props.player,
264
- },
254
+ const initialState = createPersistentStateMachine(keyRef, {
255
+ next: withRequestTime,
265
256
  });
266
257
 
258
+ const [managedState, setManagedState] = React.useState(initialState);
259
+ const wrappedListener = React.useCallback(
260
+ (cb: (s: ManagedPlayerState) => void) => {
261
+ return managedState.addListener({
262
+ onState(s) {
263
+ cb(s);
264
+ },
265
+ });
266
+ },
267
+ [managedState],
268
+ );
269
+
270
+ // const [state, setState] = React.useState(managedState.state);
271
+ const state = useSyncExternalStore(wrappedListener, managedState.getSnapshot);
272
+
267
273
  React.useEffect(() => {
268
274
  if (state?.value === "ended") {
269
- props.onComplete?.(state?.context.result);
275
+ if (props.manager !== state.context.manager) {
276
+ keyRef.current = createKey();
277
+ const newManagedState = createPersistentStateMachine(keyRef, {
278
+ next: withRequestTime,
279
+ });
280
+ setManagedState(newManagedState);
281
+ // setState(newManagedState.state);
282
+ } else {
283
+ props.onComplete?.(state?.context.result);
284
+ }
270
285
  } else if (state?.value === "error") {
271
286
  props.onError?.(state?.context.error);
272
287
  } else if (state?.value === "running") {
273
288
  props.onStartedFlow?.();
289
+ } else if (state === undefined) {
290
+ managedState.start({
291
+ manager: props.manager,
292
+ playerConfig: {
293
+ plugins: [...(props?.plugins ?? []), RequestTimeMetricsPlugin],
294
+ player: props.player,
295
+ },
296
+ });
274
297
  }
275
298
  }, [state]);
276
299
 
277
300
  React.useEffect(() => {
278
301
  return () => {
279
- const playerState = state?.context.reactPlayer.player.getState();
302
+ const playerState = state?.context?.reactPlayer?.player?.getState();
280
303
 
281
304
  if (state?.value === "running" && playerState?.status === "in-progress") {
282
305
  props.manager.terminate?.(playerState.controllers.data.serialize());
283
306
  }
284
307
  };
285
- }, [props.manager, state?.context.reactPlayer.player, state?.value]);
308
+ }, [props.manager, state?.context?.reactPlayer?.player, state?.value]);
286
309
 
287
310
  if (state?.value === "error") {
288
311
  if (props.fallbackComponent) {
@@ -1,6 +1,10 @@
1
1
  import React from "react";
2
- import type { FlowManager, ManagedPlayerProps, ManagedPlayerState, ManagerMiddleware, ManagedPlayerContext } from "./types";
2
+ import type { FlowManager, ManagedPlayerProps, ManagedPlayerState, ManagerMiddleware } from "./types";
3
3
  import type { ReactPlayerOptions } from "../player";
4
+ interface ManagedPlayerStateKey {
5
+ /** the storage key for the state (outside of the react tree) */
6
+ _key: symbol;
7
+ }
4
8
  export interface StateChangeCallback {
5
9
  /** Trigger for state changes */
6
10
  onState: (s: ManagedPlayerState) => void;
@@ -17,7 +21,8 @@ declare class ManagedState {
17
21
  middleware?: ManagerMiddleware;
18
22
  });
19
23
  /** Add a listener to state changes */
20
- addListener(callback: StateChangeCallback): () => void;
24
+ addListener: (callback: StateChangeCallback) => (() => void);
25
+ getSnapshot: () => ManagedPlayerState | undefined;
21
26
  /** start the managed flow */
22
27
  start(options: {
23
28
  /** the flow manager to use */
@@ -32,56 +37,8 @@ declare class ManagedState {
32
37
  private setState;
33
38
  private processState;
34
39
  }
35
- /** Creates an x-state state machine that persists when this component is no longer renders (due to Suspense) */
36
- export declare const usePersistentStateMachine: (options: {
37
- /** the flow manager to use */
38
- manager: FlowManager;
39
- /** Player config */
40
- playerConfig: ReactPlayerOptions;
41
- /** Any middleware for the manager */
42
- middleware?: ManagerMiddleware;
43
- }) => {
44
- managedState: ManagedState;
45
- state: {
46
- value: "not_started";
47
- context: ManagedPlayerContext;
48
- } | {
49
- value: "pending";
50
- context: ManagedPlayerContext & {
51
- prevResult?: import("@player-ui/player").CompletedState;
52
- next: Promise<import("./types").FinalState | import("./types").NextState<import("@player-ui/player").Flow>>;
53
- };
54
- } | {
55
- value: "loaded";
56
- context: ManagedPlayerContext & {
57
- flow: import("@player-ui/player").Flow;
58
- prevResult?: import("@player-ui/player").CompletedState;
59
- };
60
- } | {
61
- value: "running";
62
- context: ManagedPlayerContext & {
63
- flow: import("@player-ui/player").Flow;
64
- result: Promise<import("@player-ui/player").CompletedState>;
65
- prevResult?: import("@player-ui/player").CompletedState;
66
- };
67
- } | {
68
- value: "completed";
69
- context: ManagedPlayerContext & {
70
- result?: import("@player-ui/player").CompletedState;
71
- };
72
- } | {
73
- value: "ended";
74
- context: ManagedPlayerContext & {
75
- result?: import("@player-ui/player").CompletedState;
76
- };
77
- } | {
78
- value: "error";
79
- context: ManagedPlayerContext & {
80
- error: Error;
81
- prevResult?: import("@player-ui/player").CompletedState;
82
- };
83
- } | undefined;
84
- };
40
+ /** Creates an x-state state machine that persists when this component is no longer rendered (due to Suspense) */
41
+ export declare const createPersistentStateMachine: (keyRef: React.MutableRefObject<ManagedPlayerStateKey>, middleware?: ManagerMiddleware) => ManagedState;
85
42
  /**
86
43
  * A ManagedPlayer is a component responsible for orchestrating multi-flow experiences using Player.
87
44
  * Provide a valid `FlowManager` to handle fetching the next flow.