@player-ui/react 1.0.2--canary.900.39222 → 1.0.2--canary.900.39588

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.
@@ -513,9 +513,9 @@ var ReactPlayer2 = class {
513
513
  shouldCallResetHook ? this.hooks.onBeforeViewReset.call() : void 0
514
514
  );
515
515
  }
516
- start(flow) {
516
+ start(payload, options) {
517
517
  this.setWaitForNextViewUpdate();
518
- return this.player.start(flow).finally(async () => {
518
+ return this.player.start(payload, options).finally(async () => {
519
519
  await this.setWaitForNextViewUpdate();
520
520
  });
521
521
  }
@@ -631,7 +631,8 @@ var ManagedState = class {
631
631
  context: {
632
632
  playerConfig: options.playerConfig,
633
633
  reactPlayer: new ReactPlayer2(options.playerConfig),
634
- manager: options.manager
634
+ manager: options.manager,
635
+ startOptions: options.startOptions
635
636
  }
636
637
  };
637
638
  this.setState(initialState);
@@ -640,8 +641,8 @@ var ManagedState = class {
640
641
  /** reset starts from nothing */
641
642
  reset() {
642
643
  if (this.state?.value === "error") {
643
- const { playerConfig, manager } = this.state.context;
644
- this.start({ playerConfig, manager });
644
+ const { playerConfig, manager, startOptions } = this.state.context;
645
+ this.start({ playerConfig, manager, startOptions });
645
646
  } else {
646
647
  throw new Error("Flow must be in error state to reset");
647
648
  }
@@ -649,14 +650,15 @@ var ManagedState = class {
649
650
  /** restart starts from the last result */
650
651
  restart() {
651
652
  if (this.state?.value === "error") {
652
- const { playerConfig, manager, prevResult, reactPlayer } = this.state.context;
653
+ const { playerConfig, manager, prevResult, reactPlayer, startOptions } = this.state.context;
653
654
  this.setState({
654
655
  value: "completed",
655
656
  context: {
656
657
  playerConfig,
657
658
  manager,
658
659
  result: prevResult,
659
- reactPlayer
660
+ reactPlayer,
661
+ startOptions
660
662
  }
661
663
  });
662
664
  } else {
@@ -670,12 +672,13 @@ var ManagedState = class {
670
672
  c(this.state);
671
673
  }
672
674
  });
673
- const { manager, reactPlayer, playerConfig } = state.context;
675
+ const { manager, reactPlayer, playerConfig, startOptions } = state.context;
674
676
  try {
675
677
  const nextState = await this.processState(state, {
676
678
  manager,
677
679
  reactPlayer,
678
- playerConfig
680
+ playerConfig,
681
+ startOptions
679
682
  });
680
683
  if (nextState) {
681
684
  this.setState(nextState);
@@ -687,6 +690,7 @@ var ManagedState = class {
687
690
  manager,
688
691
  reactPlayer,
689
692
  playerConfig,
693
+ startOptions,
690
694
  error: e
691
695
  }
692
696
  });
@@ -732,7 +736,10 @@ var ManagedState = class {
732
736
  ...context,
733
737
  flow: state.context.flow,
734
738
  prevResult: state.context.prevResult,
735
- result: state.context.reactPlayer.start(state.context.flow)
739
+ result: state.context.reactPlayer.start(
740
+ state.context.flow,
741
+ state.context.startOptions
742
+ )
736
743
  }
737
744
  };
738
745
  }
@@ -818,7 +825,8 @@ var ManagedPlayer = (props) => {
818
825
  playerConfig: {
819
826
  plugins: [...props?.plugins ?? [], RequestTimeMetricsPlugin],
820
827
  player: props.player
821
- }
828
+ },
829
+ startOptions: props.startOptions
822
830
  });
823
831
  const previousState = import_react7.default.useRef();
824
832
  if (state?.value !== previousState.current?.value) {
@@ -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/asset/AssetRenderError.ts","../../../../../../../../../../../../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","import React from \"react\";\nimport { SyncWaterfallHook, AsyncParallelHook } from \"tapable-ts\";\nimport {\n Subscribe,\n useSubscribedState,\n useSubscriber,\n} from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n Flow,\n View,\n PlayerInfo,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary, FallbackProps } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport { ReactPlayer as PlayerComp } from \"./app\";\nimport { OnUpdatePlugin } from \"./plugins/onupdate-plugin\";\n\n/** Backup context for receiving ReactPlayerComponentProps when components setup in the webComponent call don't pass the props down to their inner components. */\nexport const ReactPlayerPropsContext: React.Context<ReactPlayerComponentProps> =\n React.createContext<ReactPlayerComponentProps>({ isInErrorState: false });\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\n// Alias until more properties are added\nexport type ReactPlayerInfo = PlayerInfo;\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 = {\n /** Whether or not player is currently recovering from an error. */\n isInErrorState?: boolean;\n [key: string]: unknown;\n};\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: SyncWaterfallHook<\n [React.ComponentType<any>],\n Record<string, any>\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: SyncWaterfallHook<\n [React.ComponentType<ReactPlayerProps>],\n Record<string, any>\n >;\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: AsyncParallelHook<[], Record<string, any>>;\n } = {\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(),\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\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: new AsyncParallelHook(),\n };\n\n public readonly viewUpdateSubscription: Subscribe<View> =\n new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n const startTime = performance.now();\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 version: this.player.getVersion(),\n commit: this.player.getCommit(),\n };\n\n // Log the time it took to initialize Player\n const coldStartTime = Math.round(performance.now() - startTime);\n this.player.logger.info(`ReactPlayer initialized in ${coldStartTime} ms.`);\n }\n\n /** Returns the current version Player */\n public getPlayerVersion(): string {\n return this.reactPlayerInfo.version;\n }\n\n /** Returns the git commit used to build this Player version */\n public getPlayerCommit(): string {\n return this.reactPlayerInfo.commit;\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 | PlayerPlugin): void {\n if (plugin.apply) {\n this.player.registerPlugin(plugin as PlayerPlugin);\n }\n\n if ((plugin as ReactPlayerPlugin).applyReact) {\n (plugin as ReactPlayerPlugin).applyReact?.(this);\n }\n\n if (!this.options.plugins) {\n this.options.plugins = [];\n }\n\n this.options.plugins.push(plugin);\n }\n\n /**\n * Returns the current version of the running React Player\n * @deprecated use `getPlayerVersion()` instead. Will be removed next major\n */\n public getReactPlayerVersion(): string {\n return this.reactPlayerInfo.version;\n }\n\n /**\n * Returns the git commit used to build the React Player version\n * @deprecated use `getPlayerCommit()` instead. Will be removed next major\n */\n public getReactPlayerCommit(): string {\n return this.reactPlayerInfo.commit;\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 const trackedErrors = React.useRef(new Map<Error, boolean>());\n const [errorSubId, setErrorSubId] = React.useState<number | undefined>(\n undefined,\n );\n const { subscribe, unsubscribe } = useSubscriber(\n this.viewUpdateSubscription,\n );\n\n const componentProps: ReactPlayerComponentProps = React.useMemo(\n () => ({\n ...props,\n isInErrorState: errorSubId !== undefined,\n }),\n [props, errorSubId],\n );\n\n /** Callback to remove all tracked errors and unsub from */\n const clearErrorTracking = React.useCallback(() => {\n trackedErrors.current.clear();\n setErrorSubId((prev) => {\n if (prev !== undefined) {\n unsubscribe(prev);\n }\n\n return undefined;\n });\n }, []);\n\n React.useEffect(() => {\n // Clear errors and error subscription on unmount\n return clearErrorTracking;\n }, [clearErrorTracking]);\n\n /** capture error and return true or false to represent if we are recovering from the error or not. */\n const captureError = React.useCallback(\n (err: Error) => {\n // If player isn't in progress we can't actually render anything so render errors are irrelevant.\n const playerState = this.player.getState();\n if (playerState.status !== \"in-progress\") {\n this.player.logger.warn(\n `[ReactPlayer]: An error occurred during rendering but was ignored due to a change in the player state (current state: '${playerState.status}'). Error Details:`,\n err,\n );\n return false;\n }\n\n // Only capture each error once.\n const currentError = trackedErrors.current.get(err);\n if (currentError !== undefined) {\n return currentError;\n }\n\n let isRecovering = false;\n setErrorSubId((prev) => {\n // subscribe only if no subscription available.\n // Needs to happen before capture error to ensure error recovery isn't missed\n const subId =\n prev === undefined\n ? subscribe(clearErrorTracking, {\n initializeWithPreviousValue: false,\n })\n : prev;\n\n // Get skipped state after trying to capture.\n isRecovering = playerState.controllers.error.captureError(err);\n trackedErrors.current.set(err, isRecovering);\n\n // If we can't recover from the error, avoid updating state to stay in error boundary\n if (!isRecovering) {\n // Unsub if not previously subbed since we don't need to reset the view\n if (subId !== prev) {\n unsubscribe(subId);\n }\n return prev;\n }\n\n return subId;\n });\n\n return isRecovering;\n },\n [errorSubId],\n );\n\n return (\n <ErrorBoundary\n fallbackRender={(fallbackProps: FallbackProps) => {\n const isRecovering = captureError(fallbackProps.error);\n\n if (!isRecovering) {\n // Display nothing if not recovering. Let the player state fail and handle what the view will be.\n return null;\n }\n fallbackProps.resetErrorBoundary();\n\n // Render the same as on success when recovering to preserve the react tree.\n return (\n <ReactPlayerPropsContext.Provider\n value={{ ...componentProps, isInErrorState: true }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...componentProps} isInErrorState />\n </PlayerContext.Provider>\n </ReactPlayerPropsContext.Provider>\n );\n }}\n >\n <ReactPlayerPropsContext.Provider value={{ ...componentProps }}>\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...componentProps} />\n </PlayerContext.Provider>\n </ReactPlayerPropsContext.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: React.ComponentType = (): React.ReactElement => {\n const { isInErrorState } = React.useContext(ReactPlayerPropsContext);\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n const lastSuccessfulView = React.useRef<View | undefined>(undefined);\n this.viewUpdateSubscription.suspend();\n\n React.useEffect(() => {\n if (!isInErrorState) {\n lastSuccessfulView.current = view;\n }\n }, [isInErrorState, view]);\n\n const displayedView = isInErrorState ? lastSuccessfulView.current : view;\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {displayedView && <ActualPlayerComp view={displayedView} />}\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(): Promise<void> {\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: typeof ReactPlayer = 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\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport { AssetRenderError } from \"./AssetRenderError\";\n\nexport * from \"./AssetRenderError\";\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.Context<ContextType> =\n React.createContext<ContextType>({});\n\nconst isAssetUnwrapped = (\n props: AssetType<string> | AssetWrapper<AssetType<string>>,\n): props is AssetType<string> => {\n return \"type\" in props && \"id\" in props;\n};\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): React.ReactElement => {\n const { registry } = React.useContext(AssetContext);\n\n let unwrapped: AssetType<string> | undefined;\n\n if (isAssetUnwrapped(props)) {\n unwrapped = props;\n } else if (\"asset\" in props) {\n unwrapped = props.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 (\n <ErrorBoundary\n fallbackRender={(props) => {\n const { error } = props;\n\n if (error instanceof AssetRenderError) {\n error.addAssetParent(unwrapped);\n throw error;\n } else {\n throw new AssetRenderError(\n unwrapped,\n \"Failed to render asset\",\n error,\n );\n }\n return null;\n }}\n >\n <Impl key={unwrapped.id} {...unwrapped} />\n </ErrorBoundary>\n );\n};\n","import {\n ErrorSeverity,\n ErrorTypes,\n type Asset,\n type PlayerErrorMetadata,\n} from \"@player-ui/player\";\n\nexport type AssetRenderErrorMetadata = {\n assetId: string;\n};\nexport class AssetRenderError\n extends Error\n implements PlayerErrorMetadata<AssetRenderErrorMetadata>\n{\n private assetParentPath: Array<Asset> = [];\n initialMessage: string;\n innerExceptionMessage: string;\n\n readonly type: string = ErrorTypes.RENDER;\n readonly severity: ErrorSeverity = ErrorSeverity.ERROR;\n readonly metadata: AssetRenderErrorMetadata;\n\n constructor(\n readonly rootAsset: Asset,\n message?: string,\n readonly innerException?: unknown,\n ) {\n super(message);\n this.metadata = {\n assetId: rootAsset.id,\n };\n this.initialMessage = message ?? \"\";\n this.innerExceptionMessage =\n innerException instanceof Error\n ? innerException.message\n : String(innerException);\n\n if (this.innerExceptionMessage) {\n this.initialMessage = this.initialMessage.concat(\n \"\\nCaused by: \",\n this.innerExceptionMessage,\n );\n }\n\n this.message = this.initialMessage;\n }\n\n private updateMessage() {\n this.message = `${this.initialMessage}\n${this.getAssetPathMessage()}\n`;\n }\n\n getAssetPathMessage() {\n return `Exception occurred in asset with id '${this.rootAsset.id}' of type '${this.rootAsset.type}'${this.assetParentPath.map((c) => `\\n\\tFound in (id: '${c.id}', type: '${c.type}')`)}`;\n }\n\n addAssetParent(asset: Asset): void {\n this.assetParentPath.push(asset);\n this.updateMessage();\n }\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 */\nexport const ReactPlayer = ({ view }: ReactPlayerProps) => {\n return <ReactAsset {...view} />;\n};\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 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\";\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 type StateChangeCallback = (state?: ManagedPlayerState) => void;\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 }): 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 if (c && typeof c === \"function\") {\n c(this.state);\n }\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\nfunction createKey(): ManagedPlayerStateKey {\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 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}): { managedState: ManagedState; state?: ManagedPlayerState } => {\n const mounted = React.useRef(false);\n const previousManager = React.useRef(options.manager);\n const keyRef = React.useRef<ManagedPlayerStateKey>(createKey());\n const managedStateRef = React.useRef(\n new ManagedState({ middleware: options.middleware }),\n );\n\n if (!mounted.current) {\n managedPlayerStateMachines.set(keyRef.current, managedStateRef.current);\n mounted.current = true;\n }\n\n if (previousManager.current !== options.manager) {\n const oldManagedState = managedPlayerStateMachines.get(keyRef.current);\n\n /**\n * We have to handle terminate here as well as the useEffect in the\n * ManagedPlayer since it won't have the instance of the previous manager\n */\n if (oldManagedState) {\n const playerState =\n oldManagedState.state?.context.reactPlayer.player.getState();\n\n if (\n oldManagedState.state?.value === \"running\" &&\n playerState?.status === \"in-progress\"\n ) {\n previousManager.current.terminate?.(playerState);\n }\n }\n\n const newKey = createKey();\n const newManagedState = new ManagedState({\n middleware: options.middleware,\n });\n\n managedPlayerStateMachines.set(newKey, newManagedState);\n keyRef.current = newKey;\n managedStateRef.current = newManagedState;\n previousManager.current = options.manager;\n }\n\n const managedState =\n managedPlayerStateMachines.get(keyRef.current) ?? managedStateRef.current;\n\n /**\n * There are times where the managedState the external store references no\n * longer exists, so we have to wrap instead of calling addListener directly.\n */\n function subscription(callback: (val?: ManagedPlayerState) => void) {\n if (managedState) {\n const unsub = managedState.addListener((s) => {\n callback(s);\n });\n\n return () => {\n if (managedState) {\n unsub();\n }\n };\n }\n\n return () => {};\n }\n\n function getSnapshot() {\n return managedState.state;\n }\n\n const state = useSyncExternalStore(\n subscription,\n getSnapshot,\n () => undefined,\n );\n\n /**\n * This needs to come after useSyncExternalStore, otherwise it causes\n * a weird state update and none of the refs in this hook persist\n */\n if (managedState.state === undefined) {\n managedState.start(options);\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 = (\n props: ManagedPlayerProps,\n): React.JSX.Element | null => {\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 const previousState = React.useRef<ManagedPlayerState | undefined>();\n\n if (state?.value !== previousState.current?.value) {\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?.(state.context.flow);\n }\n }\n\n previousState.current = 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);\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;AAAA,qBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,8BAAd;;;ACAA,IAAAC,gBAAkB;AAClB,wBAAqD;AACrD,6BAIO;AACP,oCAAyB;AAQzB,IAAAC,iBAAuB;AACvB,IAAAC,+BAA6C;;;AChB7C,mBAAkB;AAClB,mBAAkB;AAGlB,kCAA8B;;;ACJ9B,oBAKO;AAKA,IAAM,mBAAN,cACG,MAEV;AAAA,EASE,YACW,WACT,SACS,gBACT;AACA,UAAM,OAAO;AAJJ;AAEA;AAXX,SAAQ,kBAAgC,CAAC;AAIzC,SAAS,OAAe,yBAAW;AACnC,SAAS,WAA0B,4BAAc;AAS/C,SAAK,WAAW;AAAA,MACd,SAAS,UAAU;AAAA,IACrB;AACA,SAAK,iBAAiB,WAAW;AACjC,SAAK,wBACH,0BAA0B,QACtB,eAAe,UACf,OAAO,cAAc;AAE3B,QAAI,KAAK,uBAAuB;AAC9B,WAAK,iBAAiB,KAAK,eAAe;AAAA,QACxC;AAAA,QACA,KAAK;AAAA,MACP;AAAA,IACF;AAEA,SAAK,UAAU,KAAK;AAAA,EACtB;AAAA,EAEQ,gBAAgB;AACtB,SAAK,UAAU,GAAG,KAAK,cAAc;AAAA,EACvC,KAAK,oBAAoB,CAAC;AAAA;AAAA,EAE1B;AAAA,EAEA,sBAAsB;AACpB,WAAO,wCAAwC,KAAK,UAAU,EAAE,cAAc,KAAK,UAAU,IAAI,IAAI,KAAK,gBAAgB,IAAI,CAAC,MAAM;AAAA,k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Player","import_react","import_player","import_react_error_boundary","React","leven","props","import_react","React","import_player","import_react","React","React","ReactPlayer","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/asset/AssetRenderError.ts","../../../../../../../../../../../../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","import React from \"react\";\nimport { SyncWaterfallHook, AsyncParallelHook } from \"tapable-ts\";\nimport {\n Subscribe,\n useSubscribedState,\n useSubscriber,\n} from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n View,\n PlayerInfo,\n StartOptions,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary, FallbackProps } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport { ReactPlayer as PlayerComp } from \"./app\";\nimport { OnUpdatePlugin } from \"./plugins/onupdate-plugin\";\n\n/** Backup context for receiving ReactPlayerComponentProps when components setup in the webComponent call don't pass the props down to their inner components. */\nexport const ReactPlayerPropsContext: React.Context<ReactPlayerComponentProps> =\n React.createContext<ReactPlayerComponentProps>({ isInErrorState: false });\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\n// Alias until more properties are added\nexport type ReactPlayerInfo = PlayerInfo;\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 = {\n /** Whether or not player is currently recovering from an error. */\n isInErrorState?: boolean;\n [key: string]: unknown;\n};\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: SyncWaterfallHook<\n [React.ComponentType<any>],\n Record<string, any>\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: SyncWaterfallHook<\n [React.ComponentType<ReactPlayerProps>],\n Record<string, any>\n >;\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: AsyncParallelHook<[], Record<string, any>>;\n } = {\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(),\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\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: new AsyncParallelHook(),\n };\n\n public readonly viewUpdateSubscription: Subscribe<View> =\n new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n const startTime = performance.now();\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 version: this.player.getVersion(),\n commit: this.player.getCommit(),\n };\n\n // Log the time it took to initialize Player\n const coldStartTime = Math.round(performance.now() - startTime);\n this.player.logger.info(`ReactPlayer initialized in ${coldStartTime} ms.`);\n }\n\n /** Returns the current version Player */\n public getPlayerVersion(): string {\n return this.reactPlayerInfo.version;\n }\n\n /** Returns the git commit used to build this Player version */\n public getPlayerCommit(): string {\n return this.reactPlayerInfo.commit;\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 | PlayerPlugin): void {\n if (plugin.apply) {\n this.player.registerPlugin(plugin as PlayerPlugin);\n }\n\n if ((plugin as ReactPlayerPlugin).applyReact) {\n (plugin as ReactPlayerPlugin).applyReact?.(this);\n }\n\n if (!this.options.plugins) {\n this.options.plugins = [];\n }\n\n this.options.plugins.push(plugin);\n }\n\n /**\n * Returns the current version of the running React Player\n * @deprecated use `getPlayerVersion()` instead. Will be removed next major\n */\n public getReactPlayerVersion(): string {\n return this.reactPlayerInfo.version;\n }\n\n /**\n * Returns the git commit used to build the React Player version\n * @deprecated use `getPlayerCommit()` instead. Will be removed next major\n */\n public getReactPlayerCommit(): string {\n return this.reactPlayerInfo.commit;\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 const trackedErrors = React.useRef(new Map<Error, boolean>());\n const [errorSubId, setErrorSubId] = React.useState<number | undefined>(\n undefined,\n );\n const { subscribe, unsubscribe } = useSubscriber(\n this.viewUpdateSubscription,\n );\n\n const componentProps: ReactPlayerComponentProps = React.useMemo(\n () => ({\n ...props,\n isInErrorState: errorSubId !== undefined,\n }),\n [props, errorSubId],\n );\n\n /** Callback to remove all tracked errors and unsub from */\n const clearErrorTracking = React.useCallback(() => {\n trackedErrors.current.clear();\n setErrorSubId((prev) => {\n if (prev !== undefined) {\n unsubscribe(prev);\n }\n\n return undefined;\n });\n }, []);\n\n React.useEffect(() => {\n // Clear errors and error subscription on unmount\n return clearErrorTracking;\n }, [clearErrorTracking]);\n\n /** capture error and return true or false to represent if we are recovering from the error or not. */\n const captureError = React.useCallback(\n (err: Error) => {\n // If player isn't in progress we can't actually render anything so render errors are irrelevant.\n const playerState = this.player.getState();\n if (playerState.status !== \"in-progress\") {\n this.player.logger.warn(\n `[ReactPlayer]: An error occurred during rendering but was ignored due to a change in the player state (current state: '${playerState.status}'). Error Details:`,\n err,\n );\n return false;\n }\n\n // Only capture each error once.\n const currentError = trackedErrors.current.get(err);\n if (currentError !== undefined) {\n return currentError;\n }\n\n let isRecovering = false;\n setErrorSubId((prev) => {\n // subscribe only if no subscription available.\n // Needs to happen before capture error to ensure error recovery isn't missed\n const subId =\n prev === undefined\n ? subscribe(clearErrorTracking, {\n initializeWithPreviousValue: false,\n })\n : prev;\n\n // Get skipped state after trying to capture.\n isRecovering = playerState.controllers.error.captureError(err);\n trackedErrors.current.set(err, isRecovering);\n\n // If we can't recover from the error, avoid updating state to stay in error boundary\n if (!isRecovering) {\n // Unsub if not previously subbed since we don't need to reset the view\n if (subId !== prev) {\n unsubscribe(subId);\n }\n return prev;\n }\n\n return subId;\n });\n\n return isRecovering;\n },\n [errorSubId],\n );\n\n return (\n <ErrorBoundary\n fallbackRender={(fallbackProps: FallbackProps) => {\n const isRecovering = captureError(fallbackProps.error);\n\n if (!isRecovering) {\n // Display nothing if not recovering. Let the player state fail and handle what the view will be.\n return null;\n }\n fallbackProps.resetErrorBoundary();\n\n // Render the same as on success when recovering to preserve the react tree.\n return (\n <ReactPlayerPropsContext.Provider\n value={{ ...componentProps, isInErrorState: true }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...componentProps} isInErrorState />\n </PlayerContext.Provider>\n </ReactPlayerPropsContext.Provider>\n );\n }}\n >\n <ReactPlayerPropsContext.Provider value={{ ...componentProps }}>\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...componentProps} />\n </PlayerContext.Provider>\n </ReactPlayerPropsContext.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: React.ComponentType = (): React.ReactElement => {\n const { isInErrorState } = React.useContext(ReactPlayerPropsContext);\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n const lastSuccessfulView = React.useRef<View | undefined>(undefined);\n this.viewUpdateSubscription.suspend();\n\n React.useEffect(() => {\n if (!isInErrorState) {\n lastSuccessfulView.current = view;\n }\n }, [isInErrorState, view]);\n\n const displayedView = isInErrorState ? lastSuccessfulView.current : view;\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {displayedView && <ActualPlayerComp view={displayedView} />}\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(): Promise<void> {\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(\n payload: unknown,\n options?: StartOptions,\n ): Promise<CompletedState> {\n this.setWaitForNextViewUpdate();\n\n return this.player.start(payload, options).finally(async () => {\n await this.setWaitForNextViewUpdate();\n });\n }\n}\n\n// For compatibility\nexport const WebPlayer: typeof ReactPlayer = 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\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport { AssetRenderError } from \"./AssetRenderError\";\n\nexport * from \"./AssetRenderError\";\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.Context<ContextType> =\n React.createContext<ContextType>({});\n\nconst isAssetUnwrapped = (\n props: AssetType<string> | AssetWrapper<AssetType<string>>,\n): props is AssetType<string> => {\n return \"type\" in props && \"id\" in props;\n};\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): React.ReactElement => {\n const { registry } = React.useContext(AssetContext);\n\n let unwrapped: AssetType<string> | undefined;\n\n if (isAssetUnwrapped(props)) {\n unwrapped = props;\n } else if (\"asset\" in props) {\n unwrapped = props.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 (\n <ErrorBoundary\n fallbackRender={(props) => {\n const { error } = props;\n\n if (error instanceof AssetRenderError) {\n error.addAssetParent(unwrapped);\n throw error;\n } else {\n throw new AssetRenderError(\n unwrapped,\n \"Failed to render asset\",\n error,\n );\n }\n return null;\n }}\n >\n <Impl key={unwrapped.id} {...unwrapped} />\n </ErrorBoundary>\n );\n};\n","import {\n ErrorSeverity,\n ErrorTypes,\n type Asset,\n type PlayerErrorMetadata,\n} from \"@player-ui/player\";\n\nexport type AssetRenderErrorMetadata = {\n assetId: string;\n};\nexport class AssetRenderError\n extends Error\n implements PlayerErrorMetadata<AssetRenderErrorMetadata>\n{\n private assetParentPath: Array<Asset> = [];\n initialMessage: string;\n innerExceptionMessage: string;\n\n readonly type: string = ErrorTypes.RENDER;\n readonly severity: ErrorSeverity = ErrorSeverity.ERROR;\n readonly metadata: AssetRenderErrorMetadata;\n\n constructor(\n readonly rootAsset: Asset,\n message?: string,\n readonly innerException?: unknown,\n ) {\n super(message);\n this.metadata = {\n assetId: rootAsset.id,\n };\n this.initialMessage = message ?? \"\";\n this.innerExceptionMessage =\n innerException instanceof Error\n ? innerException.message\n : String(innerException);\n\n if (this.innerExceptionMessage) {\n this.initialMessage = this.initialMessage.concat(\n \"\\nCaused by: \",\n this.innerExceptionMessage,\n );\n }\n\n this.message = this.initialMessage;\n }\n\n private updateMessage() {\n this.message = `${this.initialMessage}\n${this.getAssetPathMessage()}\n`;\n }\n\n getAssetPathMessage() {\n return `Exception occurred in asset with id '${this.rootAsset.id}' of type '${this.rootAsset.type}'${this.assetParentPath.map((c) => `\\n\\tFound in (id: '${c.id}', type: '${c.type}')`)}`;\n }\n\n addAssetParent(asset: Asset): void {\n this.assetParentPath.push(asset);\n this.updateMessage();\n }\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 */\nexport const ReactPlayer = ({ view }: ReactPlayerProps) => {\n return <ReactAsset {...view} />;\n};\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 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\";\nimport type {\n FlowManager,\n ManagedPlayerProps,\n ManagedPlayerState,\n ManagerMiddleware,\n ManagedPlayerContext,\n} from \"./types\";\nimport type { StartOptions } from \"@player-ui/player\";\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 type StateChangeCallback = (state?: ManagedPlayerState) => void;\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 /** options forwarded to `player.start()` for each flow */\n startOptions?: StartOptions;\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 startOptions: options.startOptions,\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, startOptions } = this.state.context;\n this.start({ playerConfig, manager, startOptions });\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, startOptions } =\n this.state.context;\n this.setState({\n value: \"completed\",\n context: {\n playerConfig,\n manager,\n result: prevResult,\n reactPlayer,\n startOptions,\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 if (c && typeof c === \"function\") {\n c(this.state);\n }\n });\n\n const { manager, reactPlayer, playerConfig, startOptions } = state.context;\n\n try {\n const nextState = await this.processState(state, {\n manager,\n reactPlayer,\n playerConfig,\n startOptions,\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 startOptions,\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(\n state.context.flow,\n state.context.startOptions,\n ),\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\nfunction createKey(): ManagedPlayerStateKey {\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 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 /** Options forwarded to `player.start()` for each flow */\n startOptions?: StartOptions;\n}): { managedState: ManagedState; state?: ManagedPlayerState } => {\n const mounted = React.useRef(false);\n const previousManager = React.useRef(options.manager);\n const keyRef = React.useRef<ManagedPlayerStateKey>(createKey());\n const managedStateRef = React.useRef(\n new ManagedState({ middleware: options.middleware }),\n );\n\n if (!mounted.current) {\n managedPlayerStateMachines.set(keyRef.current, managedStateRef.current);\n mounted.current = true;\n }\n\n if (previousManager.current !== options.manager) {\n const oldManagedState = managedPlayerStateMachines.get(keyRef.current);\n\n /**\n * We have to handle terminate here as well as the useEffect in the\n * ManagedPlayer since it won't have the instance of the previous manager\n */\n if (oldManagedState) {\n const playerState =\n oldManagedState.state?.context.reactPlayer.player.getState();\n\n if (\n oldManagedState.state?.value === \"running\" &&\n playerState?.status === \"in-progress\"\n ) {\n previousManager.current.terminate?.(playerState);\n }\n }\n\n const newKey = createKey();\n const newManagedState = new ManagedState({\n middleware: options.middleware,\n });\n\n managedPlayerStateMachines.set(newKey, newManagedState);\n keyRef.current = newKey;\n managedStateRef.current = newManagedState;\n previousManager.current = options.manager;\n }\n\n const managedState =\n managedPlayerStateMachines.get(keyRef.current) ?? managedStateRef.current;\n\n /**\n * There are times where the managedState the external store references no\n * longer exists, so we have to wrap instead of calling addListener directly.\n */\n function subscription(callback: (val?: ManagedPlayerState) => void) {\n if (managedState) {\n const unsub = managedState.addListener((s) => {\n callback(s);\n });\n\n return () => {\n if (managedState) {\n unsub();\n }\n };\n }\n\n return () => {};\n }\n\n function getSnapshot() {\n return managedState.state;\n }\n\n const state = useSyncExternalStore(\n subscription,\n getSnapshot,\n () => undefined,\n );\n\n /**\n * This needs to come after useSyncExternalStore, otherwise it causes\n * a weird state update and none of the refs in this hook persist\n */\n if (managedState.state === undefined) {\n managedState.start(options);\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 = (\n props: ManagedPlayerProps,\n): React.JSX.Element | null => {\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 startOptions: props.startOptions,\n });\n\n const previousState = React.useRef<ManagedPlayerState | undefined>();\n\n if (state?.value !== previousState.current?.value) {\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?.(state.context.flow);\n }\n }\n\n previousState.current = 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);\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;AAAA,qBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,w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;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,MAAM,QAAQ,IAAI;AAAA,IAC1C;AAAA,EACF;AAEA,gBAAc,UAAU;AAExB,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,WAAW;AAAA,MACvC;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","import_react_error_boundary","React","leven","props","import_react","React","import_player","import_react","React","React","ReactPlayer","import_player","import_react","React","ReactPlayer","import_react","import_react","ReactPlayer","React"]}
@@ -464,9 +464,9 @@ var ReactPlayer2 = class {
464
464
  shouldCallResetHook ? this.hooks.onBeforeViewReset.call() : void 0
465
465
  );
466
466
  }
467
- start(flow) {
467
+ start(payload, options) {
468
468
  this.setWaitForNextViewUpdate();
469
- return this.player.start(flow).finally(async () => {
469
+ return this.player.start(payload, options).finally(async () => {
470
470
  await this.setWaitForNextViewUpdate();
471
471
  });
472
472
  }
@@ -585,7 +585,8 @@ var ManagedState = class {
585
585
  context: {
586
586
  playerConfig: options.playerConfig,
587
587
  reactPlayer: new ReactPlayer2(options.playerConfig),
588
- manager: options.manager
588
+ manager: options.manager,
589
+ startOptions: options.startOptions
589
590
  }
590
591
  };
591
592
  this.setState(initialState);
@@ -594,8 +595,8 @@ var ManagedState = class {
594
595
  /** reset starts from nothing */
595
596
  reset() {
596
597
  if (this.state?.value === "error") {
597
- const { playerConfig, manager } = this.state.context;
598
- this.start({ playerConfig, manager });
598
+ const { playerConfig, manager, startOptions } = this.state.context;
599
+ this.start({ playerConfig, manager, startOptions });
599
600
  } else {
600
601
  throw new Error("Flow must be in error state to reset");
601
602
  }
@@ -603,14 +604,15 @@ var ManagedState = class {
603
604
  /** restart starts from the last result */
604
605
  restart() {
605
606
  if (this.state?.value === "error") {
606
- const { playerConfig, manager, prevResult, reactPlayer } = this.state.context;
607
+ const { playerConfig, manager, prevResult, reactPlayer, startOptions } = this.state.context;
607
608
  this.setState({
608
609
  value: "completed",
609
610
  context: {
610
611
  playerConfig,
611
612
  manager,
612
613
  result: prevResult,
613
- reactPlayer
614
+ reactPlayer,
615
+ startOptions
614
616
  }
615
617
  });
616
618
  } else {
@@ -624,12 +626,13 @@ var ManagedState = class {
624
626
  c(this.state);
625
627
  }
626
628
  });
627
- const { manager, reactPlayer, playerConfig } = state.context;
629
+ const { manager, reactPlayer, playerConfig, startOptions } = state.context;
628
630
  try {
629
631
  const nextState = await this.processState(state, {
630
632
  manager,
631
633
  reactPlayer,
632
- playerConfig
634
+ playerConfig,
635
+ startOptions
633
636
  });
634
637
  if (nextState) {
635
638
  this.setState(nextState);
@@ -641,6 +644,7 @@ var ManagedState = class {
641
644
  manager,
642
645
  reactPlayer,
643
646
  playerConfig,
647
+ startOptions,
644
648
  error: e
645
649
  }
646
650
  });
@@ -686,7 +690,10 @@ var ManagedState = class {
686
690
  ...context,
687
691
  flow: state.context.flow,
688
692
  prevResult: state.context.prevResult,
689
- result: state.context.reactPlayer.start(state.context.flow)
693
+ result: state.context.reactPlayer.start(
694
+ state.context.flow,
695
+ state.context.startOptions
696
+ )
690
697
  }
691
698
  };
692
699
  }
@@ -772,7 +779,8 @@ var ManagedPlayer = (props) => {
772
779
  playerConfig: {
773
780
  plugins: [...props?.plugins ?? [], RequestTimeMetricsPlugin],
774
781
  player: props.player
775
- }
782
+ },
783
+ startOptions: props.startOptions
776
784
  });
777
785
  const previousState = React6.useRef();
778
786
  if (state?.value !== previousState.current?.value) {
package/dist/index.mjs CHANGED
@@ -464,9 +464,9 @@ var ReactPlayer2 = class {
464
464
  shouldCallResetHook ? this.hooks.onBeforeViewReset.call() : void 0
465
465
  );
466
466
  }
467
- start(flow) {
467
+ start(payload, options) {
468
468
  this.setWaitForNextViewUpdate();
469
- return this.player.start(flow).finally(async () => {
469
+ return this.player.start(payload, options).finally(async () => {
470
470
  await this.setWaitForNextViewUpdate();
471
471
  });
472
472
  }
@@ -585,7 +585,8 @@ var ManagedState = class {
585
585
  context: {
586
586
  playerConfig: options.playerConfig,
587
587
  reactPlayer: new ReactPlayer2(options.playerConfig),
588
- manager: options.manager
588
+ manager: options.manager,
589
+ startOptions: options.startOptions
589
590
  }
590
591
  };
591
592
  this.setState(initialState);
@@ -594,8 +595,8 @@ var ManagedState = class {
594
595
  /** reset starts from nothing */
595
596
  reset() {
596
597
  if (this.state?.value === "error") {
597
- const { playerConfig, manager } = this.state.context;
598
- this.start({ playerConfig, manager });
598
+ const { playerConfig, manager, startOptions } = this.state.context;
599
+ this.start({ playerConfig, manager, startOptions });
599
600
  } else {
600
601
  throw new Error("Flow must be in error state to reset");
601
602
  }
@@ -603,14 +604,15 @@ var ManagedState = class {
603
604
  /** restart starts from the last result */
604
605
  restart() {
605
606
  if (this.state?.value === "error") {
606
- const { playerConfig, manager, prevResult, reactPlayer } = this.state.context;
607
+ const { playerConfig, manager, prevResult, reactPlayer, startOptions } = this.state.context;
607
608
  this.setState({
608
609
  value: "completed",
609
610
  context: {
610
611
  playerConfig,
611
612
  manager,
612
613
  result: prevResult,
613
- reactPlayer
614
+ reactPlayer,
615
+ startOptions
614
616
  }
615
617
  });
616
618
  } else {
@@ -624,12 +626,13 @@ var ManagedState = class {
624
626
  c(this.state);
625
627
  }
626
628
  });
627
- const { manager, reactPlayer, playerConfig } = state.context;
629
+ const { manager, reactPlayer, playerConfig, startOptions } = state.context;
628
630
  try {
629
631
  const nextState = await this.processState(state, {
630
632
  manager,
631
633
  reactPlayer,
632
- playerConfig
634
+ playerConfig,
635
+ startOptions
633
636
  });
634
637
  if (nextState) {
635
638
  this.setState(nextState);
@@ -641,6 +644,7 @@ var ManagedState = class {
641
644
  manager,
642
645
  reactPlayer,
643
646
  playerConfig,
647
+ startOptions,
644
648
  error: e
645
649
  }
646
650
  });
@@ -686,7 +690,10 @@ var ManagedState = class {
686
690
  ...context,
687
691
  flow: state.context.flow,
688
692
  prevResult: state.context.prevResult,
689
- result: state.context.reactPlayer.start(state.context.flow)
693
+ result: state.context.reactPlayer.start(
694
+ state.context.flow,
695
+ state.context.startOptions
696
+ )
690
697
  }
691
698
  };
692
699
  }
@@ -772,7 +779,8 @@ var ManagedPlayer = (props) => {
772
779
  playerConfig: {
773
780
  plugins: [...props?.plugins ?? [], RequestTimeMetricsPlugin],
774
781
  player: props.player
775
- }
782
+ },
783
+ startOptions: props.startOptions
776
784
  });
777
785
  const previousState = React6.useRef();
778
786
  if (state?.value !== previousState.current?.value) {
@@ -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/asset/AssetRenderError.ts","../../../../../../../../../../../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","import React from \"react\";\nimport { SyncWaterfallHook, AsyncParallelHook } from \"tapable-ts\";\nimport {\n Subscribe,\n useSubscribedState,\n useSubscriber,\n} from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n Flow,\n View,\n PlayerInfo,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary, FallbackProps } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport { ReactPlayer as PlayerComp } from \"./app\";\nimport { OnUpdatePlugin } from \"./plugins/onupdate-plugin\";\n\n/** Backup context for receiving ReactPlayerComponentProps when components setup in the webComponent call don't pass the props down to their inner components. */\nexport const ReactPlayerPropsContext: React.Context<ReactPlayerComponentProps> =\n React.createContext<ReactPlayerComponentProps>({ isInErrorState: false });\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\n// Alias until more properties are added\nexport type ReactPlayerInfo = PlayerInfo;\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 = {\n /** Whether or not player is currently recovering from an error. */\n isInErrorState?: boolean;\n [key: string]: unknown;\n};\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: SyncWaterfallHook<\n [React.ComponentType<any>],\n Record<string, any>\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: SyncWaterfallHook<\n [React.ComponentType<ReactPlayerProps>],\n Record<string, any>\n >;\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: AsyncParallelHook<[], Record<string, any>>;\n } = {\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(),\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\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: new AsyncParallelHook(),\n };\n\n public readonly viewUpdateSubscription: Subscribe<View> =\n new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n const startTime = performance.now();\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 version: this.player.getVersion(),\n commit: this.player.getCommit(),\n };\n\n // Log the time it took to initialize Player\n const coldStartTime = Math.round(performance.now() - startTime);\n this.player.logger.info(`ReactPlayer initialized in ${coldStartTime} ms.`);\n }\n\n /** Returns the current version Player */\n public getPlayerVersion(): string {\n return this.reactPlayerInfo.version;\n }\n\n /** Returns the git commit used to build this Player version */\n public getPlayerCommit(): string {\n return this.reactPlayerInfo.commit;\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 | PlayerPlugin): void {\n if (plugin.apply) {\n this.player.registerPlugin(plugin as PlayerPlugin);\n }\n\n if ((plugin as ReactPlayerPlugin).applyReact) {\n (plugin as ReactPlayerPlugin).applyReact?.(this);\n }\n\n if (!this.options.plugins) {\n this.options.plugins = [];\n }\n\n this.options.plugins.push(plugin);\n }\n\n /**\n * Returns the current version of the running React Player\n * @deprecated use `getPlayerVersion()` instead. Will be removed next major\n */\n public getReactPlayerVersion(): string {\n return this.reactPlayerInfo.version;\n }\n\n /**\n * Returns the git commit used to build the React Player version\n * @deprecated use `getPlayerCommit()` instead. Will be removed next major\n */\n public getReactPlayerCommit(): string {\n return this.reactPlayerInfo.commit;\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 const trackedErrors = React.useRef(new Map<Error, boolean>());\n const [errorSubId, setErrorSubId] = React.useState<number | undefined>(\n undefined,\n );\n const { subscribe, unsubscribe } = useSubscriber(\n this.viewUpdateSubscription,\n );\n\n const componentProps: ReactPlayerComponentProps = React.useMemo(\n () => ({\n ...props,\n isInErrorState: errorSubId !== undefined,\n }),\n [props, errorSubId],\n );\n\n /** Callback to remove all tracked errors and unsub from */\n const clearErrorTracking = React.useCallback(() => {\n trackedErrors.current.clear();\n setErrorSubId((prev) => {\n if (prev !== undefined) {\n unsubscribe(prev);\n }\n\n return undefined;\n });\n }, []);\n\n React.useEffect(() => {\n // Clear errors and error subscription on unmount\n return clearErrorTracking;\n }, [clearErrorTracking]);\n\n /** capture error and return true or false to represent if we are recovering from the error or not. */\n const captureError = React.useCallback(\n (err: Error) => {\n // If player isn't in progress we can't actually render anything so render errors are irrelevant.\n const playerState = this.player.getState();\n if (playerState.status !== \"in-progress\") {\n this.player.logger.warn(\n `[ReactPlayer]: An error occurred during rendering but was ignored due to a change in the player state (current state: '${playerState.status}'). Error Details:`,\n err,\n );\n return false;\n }\n\n // Only capture each error once.\n const currentError = trackedErrors.current.get(err);\n if (currentError !== undefined) {\n return currentError;\n }\n\n let isRecovering = false;\n setErrorSubId((prev) => {\n // subscribe only if no subscription available.\n // Needs to happen before capture error to ensure error recovery isn't missed\n const subId =\n prev === undefined\n ? subscribe(clearErrorTracking, {\n initializeWithPreviousValue: false,\n })\n : prev;\n\n // Get skipped state after trying to capture.\n isRecovering = playerState.controllers.error.captureError(err);\n trackedErrors.current.set(err, isRecovering);\n\n // If we can't recover from the error, avoid updating state to stay in error boundary\n if (!isRecovering) {\n // Unsub if not previously subbed since we don't need to reset the view\n if (subId !== prev) {\n unsubscribe(subId);\n }\n return prev;\n }\n\n return subId;\n });\n\n return isRecovering;\n },\n [errorSubId],\n );\n\n return (\n <ErrorBoundary\n fallbackRender={(fallbackProps: FallbackProps) => {\n const isRecovering = captureError(fallbackProps.error);\n\n if (!isRecovering) {\n // Display nothing if not recovering. Let the player state fail and handle what the view will be.\n return null;\n }\n fallbackProps.resetErrorBoundary();\n\n // Render the same as on success when recovering to preserve the react tree.\n return (\n <ReactPlayerPropsContext.Provider\n value={{ ...componentProps, isInErrorState: true }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...componentProps} isInErrorState />\n </PlayerContext.Provider>\n </ReactPlayerPropsContext.Provider>\n );\n }}\n >\n <ReactPlayerPropsContext.Provider value={{ ...componentProps }}>\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...componentProps} />\n </PlayerContext.Provider>\n </ReactPlayerPropsContext.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: React.ComponentType = (): React.ReactElement => {\n const { isInErrorState } = React.useContext(ReactPlayerPropsContext);\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n const lastSuccessfulView = React.useRef<View | undefined>(undefined);\n this.viewUpdateSubscription.suspend();\n\n React.useEffect(() => {\n if (!isInErrorState) {\n lastSuccessfulView.current = view;\n }\n }, [isInErrorState, view]);\n\n const displayedView = isInErrorState ? lastSuccessfulView.current : view;\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {displayedView && <ActualPlayerComp view={displayedView} />}\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(): Promise<void> {\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: typeof ReactPlayer = 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\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport { AssetRenderError } from \"./AssetRenderError\";\n\nexport * from \"./AssetRenderError\";\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.Context<ContextType> =\n React.createContext<ContextType>({});\n\nconst isAssetUnwrapped = (\n props: AssetType<string> | AssetWrapper<AssetType<string>>,\n): props is AssetType<string> => {\n return \"type\" in props && \"id\" in props;\n};\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): React.ReactElement => {\n const { registry } = React.useContext(AssetContext);\n\n let unwrapped: AssetType<string> | undefined;\n\n if (isAssetUnwrapped(props)) {\n unwrapped = props;\n } else if (\"asset\" in props) {\n unwrapped = props.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 (\n <ErrorBoundary\n fallbackRender={(props) => {\n const { error } = props;\n\n if (error instanceof AssetRenderError) {\n error.addAssetParent(unwrapped);\n throw error;\n } else {\n throw new AssetRenderError(\n unwrapped,\n \"Failed to render asset\",\n error,\n );\n }\n return null;\n }}\n >\n <Impl key={unwrapped.id} {...unwrapped} />\n </ErrorBoundary>\n );\n};\n","import {\n ErrorSeverity,\n ErrorTypes,\n type Asset,\n type PlayerErrorMetadata,\n} from \"@player-ui/player\";\n\nexport type AssetRenderErrorMetadata = {\n assetId: string;\n};\nexport class AssetRenderError\n extends Error\n implements PlayerErrorMetadata<AssetRenderErrorMetadata>\n{\n private assetParentPath: Array<Asset> = [];\n initialMessage: string;\n innerExceptionMessage: string;\n\n readonly type: string = ErrorTypes.RENDER;\n readonly severity: ErrorSeverity = ErrorSeverity.ERROR;\n readonly metadata: AssetRenderErrorMetadata;\n\n constructor(\n readonly rootAsset: Asset,\n message?: string,\n readonly innerException?: unknown,\n ) {\n super(message);\n this.metadata = {\n assetId: rootAsset.id,\n };\n this.initialMessage = message ?? \"\";\n this.innerExceptionMessage =\n innerException instanceof Error\n ? innerException.message\n : String(innerException);\n\n if (this.innerExceptionMessage) {\n this.initialMessage = this.initialMessage.concat(\n \"\\nCaused by: \",\n this.innerExceptionMessage,\n );\n }\n\n this.message = this.initialMessage;\n }\n\n private updateMessage() {\n this.message = `${this.initialMessage}\n${this.getAssetPathMessage()}\n`;\n }\n\n getAssetPathMessage() {\n return `Exception occurred in asset with id '${this.rootAsset.id}' of type '${this.rootAsset.type}'${this.assetParentPath.map((c) => `\\n\\tFound in (id: '${c.id}', type: '${c.type}')`)}`;\n }\n\n addAssetParent(asset: Asset): void {\n this.assetParentPath.push(asset);\n this.updateMessage();\n }\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 */\nexport const ReactPlayer = ({ view }: ReactPlayerProps) => {\n return <ReactAsset {...view} />;\n};\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 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\";\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 type StateChangeCallback = (state?: ManagedPlayerState) => void;\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 }): 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 if (c && typeof c === \"function\") {\n c(this.state);\n }\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\nfunction createKey(): ManagedPlayerStateKey {\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 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}): { managedState: ManagedState; state?: ManagedPlayerState } => {\n const mounted = React.useRef(false);\n const previousManager = React.useRef(options.manager);\n const keyRef = React.useRef<ManagedPlayerStateKey>(createKey());\n const managedStateRef = React.useRef(\n new ManagedState({ middleware: options.middleware }),\n );\n\n if (!mounted.current) {\n managedPlayerStateMachines.set(keyRef.current, managedStateRef.current);\n mounted.current = true;\n }\n\n if (previousManager.current !== options.manager) {\n const oldManagedState = managedPlayerStateMachines.get(keyRef.current);\n\n /**\n * We have to handle terminate here as well as the useEffect in the\n * ManagedPlayer since it won't have the instance of the previous manager\n */\n if (oldManagedState) {\n const playerState =\n oldManagedState.state?.context.reactPlayer.player.getState();\n\n if (\n oldManagedState.state?.value === \"running\" &&\n playerState?.status === \"in-progress\"\n ) {\n previousManager.current.terminate?.(playerState);\n }\n }\n\n const newKey = createKey();\n const newManagedState = new ManagedState({\n middleware: options.middleware,\n });\n\n managedPlayerStateMachines.set(newKey, newManagedState);\n keyRef.current = newKey;\n managedStateRef.current = newManagedState;\n previousManager.current = options.manager;\n }\n\n const managedState =\n managedPlayerStateMachines.get(keyRef.current) ?? managedStateRef.current;\n\n /**\n * There are times where the managedState the external store references no\n * longer exists, so we have to wrap instead of calling addListener directly.\n */\n function subscription(callback: (val?: ManagedPlayerState) => void) {\n if (managedState) {\n const unsub = managedState.addListener((s) => {\n callback(s);\n });\n\n return () => {\n if (managedState) {\n unsub();\n }\n };\n }\n\n return () => {};\n }\n\n function getSnapshot() {\n return managedState.state;\n }\n\n const state = useSyncExternalStore(\n subscription,\n getSnapshot,\n () => undefined,\n );\n\n /**\n * This needs to come after useSyncExternalStore, otherwise it causes\n * a weird state update and none of the refs in this hook persist\n */\n if (managedState.state === undefined) {\n managedState.start(options);\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 = (\n props: ManagedPlayerProps,\n): React.JSX.Element | null => {\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 const previousState = React.useRef<ManagedPlayerState | undefined>();\n\n if (state?.value !== previousState.current?.value) {\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?.(state.context.flow);\n }\n }\n\n previousState.current = 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);\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;;;ACAd,OAAOA,YAAW;AAClB,SAAS,mBAAmB,yBAAyB;AACrD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AAQzB,SAAS,cAAc;AACvB,SAAS,iBAAAC,sBAAoC;;;AChB7C,OAAO,WAAW;AAClB,OAAO,WAAW;AAGlB,SAAS,qBAAqB;;;ACJ9B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAKA,IAAM,mBAAN,cACG,MAEV;AAAA,EASE,YACW,WACT,SACS,gBACT;AACA,UAAM,OAAO;AAJJ;AAEA;AAXX,SAAQ,kBAAgC,CAAC;AAIzC,SAAS,OAAe,WAAW;AACnC,SAAS,WAA0B,cAAc;AAS/C,SAAK,WAAW;AAAA,MACd,SAAS,UAAU;AAAA,IACrB;AACA,SAAK,iBAAiB,WAAW;AACjC,SAAK,wBACH,0BAA0B,QACtB,eAAe,UACf,OAAO,cAAc;AAE3B,QAAI,KAAK,uBAAuB;AAC9B,WAAK,iBAAiB,KAAK,eAAe;AAAA,QACxC;AAAA,QACA,KAAK;AAAA,MACP;AAAA,IACF;AAEA,SAAK,UAAU,KAAK;AAAA,EACtB;AAAA,EAEQ,g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U,IAAI,MAAM,QAAQ;AAEpC,WAAO,gBAAAA,OAAA,cAAC,eAAU;AAAA,EACpB;AAEA,SAAO;AACT;","names":["React","ErrorBoundary","props","React","React","React","React","ReactPlayer","ErrorBoundary","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/asset/AssetRenderError.ts","../../../../../../../../../../../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","import React from \"react\";\nimport { SyncWaterfallHook, AsyncParallelHook } from \"tapable-ts\";\nimport {\n Subscribe,\n useSubscribedState,\n useSubscriber,\n} from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n View,\n PlayerInfo,\n StartOptions,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary, FallbackProps } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport { ReactPlayer as PlayerComp } from \"./app\";\nimport { OnUpdatePlugin } from \"./plugins/onupdate-plugin\";\n\n/** Backup context for receiving ReactPlayerComponentProps when components setup in the webComponent call don't pass the props down to their inner components. */\nexport const ReactPlayerPropsContext: React.Context<ReactPlayerComponentProps> =\n React.createContext<ReactPlayerComponentProps>({ isInErrorState: false });\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\n// Alias until more properties are added\nexport type ReactPlayerInfo = PlayerInfo;\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 = {\n /** Whether or not player is currently recovering from an error. */\n isInErrorState?: boolean;\n [key: string]: unknown;\n};\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: SyncWaterfallHook<\n [React.ComponentType<any>],\n Record<string, any>\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: SyncWaterfallHook<\n [React.ComponentType<ReactPlayerProps>],\n Record<string, any>\n >;\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: AsyncParallelHook<[], Record<string, any>>;\n } = {\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(),\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\n /**\n * A hook to execute async tasks before the view resets to undefined\n */\n onBeforeViewReset: new AsyncParallelHook(),\n };\n\n public readonly viewUpdateSubscription: Subscribe<View> =\n new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n const startTime = performance.now();\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 version: this.player.getVersion(),\n commit: this.player.getCommit(),\n };\n\n // Log the time it took to initialize Player\n const coldStartTime = Math.round(performance.now() - startTime);\n this.player.logger.info(`ReactPlayer initialized in ${coldStartTime} ms.`);\n }\n\n /** Returns the current version Player */\n public getPlayerVersion(): string {\n return this.reactPlayerInfo.version;\n }\n\n /** Returns the git commit used to build this Player version */\n public getPlayerCommit(): string {\n return this.reactPlayerInfo.commit;\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 | PlayerPlugin): void {\n if (plugin.apply) {\n this.player.registerPlugin(plugin as PlayerPlugin);\n }\n\n if ((plugin as ReactPlayerPlugin).applyReact) {\n (plugin as ReactPlayerPlugin).applyReact?.(this);\n }\n\n if (!this.options.plugins) {\n this.options.plugins = [];\n }\n\n this.options.plugins.push(plugin);\n }\n\n /**\n * Returns the current version of the running React Player\n * @deprecated use `getPlayerVersion()` instead. Will be removed next major\n */\n public getReactPlayerVersion(): string {\n return this.reactPlayerInfo.version;\n }\n\n /**\n * Returns the git commit used to build the React Player version\n * @deprecated use `getPlayerCommit()` instead. Will be removed next major\n */\n public getReactPlayerCommit(): string {\n return this.reactPlayerInfo.commit;\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 const trackedErrors = React.useRef(new Map<Error, boolean>());\n const [errorSubId, setErrorSubId] = React.useState<number | undefined>(\n undefined,\n );\n const { subscribe, unsubscribe } = useSubscriber(\n this.viewUpdateSubscription,\n );\n\n const componentProps: ReactPlayerComponentProps = React.useMemo(\n () => ({\n ...props,\n isInErrorState: errorSubId !== undefined,\n }),\n [props, errorSubId],\n );\n\n /** Callback to remove all tracked errors and unsub from */\n const clearErrorTracking = React.useCallback(() => {\n trackedErrors.current.clear();\n setErrorSubId((prev) => {\n if (prev !== undefined) {\n unsubscribe(prev);\n }\n\n return undefined;\n });\n }, []);\n\n React.useEffect(() => {\n // Clear errors and error subscription on unmount\n return clearErrorTracking;\n }, [clearErrorTracking]);\n\n /** capture error and return true or false to represent if we are recovering from the error or not. */\n const captureError = React.useCallback(\n (err: Error) => {\n // If player isn't in progress we can't actually render anything so render errors are irrelevant.\n const playerState = this.player.getState();\n if (playerState.status !== \"in-progress\") {\n this.player.logger.warn(\n `[ReactPlayer]: An error occurred during rendering but was ignored due to a change in the player state (current state: '${playerState.status}'). Error Details:`,\n err,\n );\n return false;\n }\n\n // Only capture each error once.\n const currentError = trackedErrors.current.get(err);\n if (currentError !== undefined) {\n return currentError;\n }\n\n let isRecovering = false;\n setErrorSubId((prev) => {\n // subscribe only if no subscription available.\n // Needs to happen before capture error to ensure error recovery isn't missed\n const subId =\n prev === undefined\n ? subscribe(clearErrorTracking, {\n initializeWithPreviousValue: false,\n })\n : prev;\n\n // Get skipped state after trying to capture.\n isRecovering = playerState.controllers.error.captureError(err);\n trackedErrors.current.set(err, isRecovering);\n\n // If we can't recover from the error, avoid updating state to stay in error boundary\n if (!isRecovering) {\n // Unsub if not previously subbed since we don't need to reset the view\n if (subId !== prev) {\n unsubscribe(subId);\n }\n return prev;\n }\n\n return subId;\n });\n\n return isRecovering;\n },\n [errorSubId],\n );\n\n return (\n <ErrorBoundary\n fallbackRender={(fallbackProps: FallbackProps) => {\n const isRecovering = captureError(fallbackProps.error);\n\n if (!isRecovering) {\n // Display nothing if not recovering. Let the player state fail and handle what the view will be.\n return null;\n }\n fallbackProps.resetErrorBoundary();\n\n // Render the same as on success when recovering to preserve the react tree.\n return (\n <ReactPlayerPropsContext.Provider\n value={{ ...componentProps, isInErrorState: true }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...componentProps} isInErrorState />\n </PlayerContext.Provider>\n </ReactPlayerPropsContext.Provider>\n );\n }}\n >\n <ReactPlayerPropsContext.Provider value={{ ...componentProps }}>\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...componentProps} />\n </PlayerContext.Provider>\n </ReactPlayerPropsContext.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: React.ComponentType = (): React.ReactElement => {\n const { isInErrorState } = React.useContext(ReactPlayerPropsContext);\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n const lastSuccessfulView = React.useRef<View | undefined>(undefined);\n this.viewUpdateSubscription.suspend();\n\n React.useEffect(() => {\n if (!isInErrorState) {\n lastSuccessfulView.current = view;\n }\n }, [isInErrorState, view]);\n\n const displayedView = isInErrorState ? lastSuccessfulView.current : view;\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {displayedView && <ActualPlayerComp view={displayedView} />}\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(): Promise<void> {\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(\n payload: unknown,\n options?: StartOptions,\n ): Promise<CompletedState> {\n this.setWaitForNextViewUpdate();\n\n return this.player.start(payload, options).finally(async () => {\n await this.setWaitForNextViewUpdate();\n });\n }\n}\n\n// For compatibility\nexport const WebPlayer: typeof ReactPlayer = 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\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport { AssetRenderError } from \"./AssetRenderError\";\n\nexport * from \"./AssetRenderError\";\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.Context<ContextType> =\n React.createContext<ContextType>({});\n\nconst isAssetUnwrapped = (\n props: AssetType<string> | AssetWrapper<AssetType<string>>,\n): props is AssetType<string> => {\n return \"type\" in props && \"id\" in props;\n};\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): React.ReactElement => {\n const { registry } = React.useContext(AssetContext);\n\n let unwrapped: AssetType<string> | undefined;\n\n if (isAssetUnwrapped(props)) {\n unwrapped = props;\n } else if (\"asset\" in props) {\n unwrapped = props.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 (\n <ErrorBoundary\n fallbackRender={(props) => {\n const { error } = props;\n\n if (error instanceof AssetRenderError) {\n error.addAssetParent(unwrapped);\n throw error;\n } else {\n throw new AssetRenderError(\n unwrapped,\n \"Failed to render asset\",\n error,\n );\n }\n return null;\n }}\n >\n <Impl key={unwrapped.id} {...unwrapped} />\n </ErrorBoundary>\n );\n};\n","import {\n ErrorSeverity,\n ErrorTypes,\n type Asset,\n type PlayerErrorMetadata,\n} from \"@player-ui/player\";\n\nexport type AssetRenderErrorMetadata = {\n assetId: string;\n};\nexport class AssetRenderError\n extends Error\n implements PlayerErrorMetadata<AssetRenderErrorMetadata>\n{\n private assetParentPath: Array<Asset> = [];\n initialMessage: string;\n innerExceptionMessage: string;\n\n readonly type: string = ErrorTypes.RENDER;\n readonly severity: ErrorSeverity = ErrorSeverity.ERROR;\n readonly metadata: AssetRenderErrorMetadata;\n\n constructor(\n readonly rootAsset: Asset,\n message?: string,\n readonly innerException?: unknown,\n ) {\n super(message);\n this.metadata = {\n assetId: rootAsset.id,\n };\n this.initialMessage = message ?? \"\";\n this.innerExceptionMessage =\n innerException instanceof Error\n ? innerException.message\n : String(innerException);\n\n if (this.innerExceptionMessage) {\n this.initialMessage = this.initialMessage.concat(\n \"\\nCaused by: \",\n this.innerExceptionMessage,\n );\n }\n\n this.message = this.initialMessage;\n }\n\n private updateMessage() {\n this.message = `${this.initialMessage}\n${this.getAssetPathMessage()}\n`;\n }\n\n getAssetPathMessage() {\n return `Exception occurred in asset with id '${this.rootAsset.id}' of type '${this.rootAsset.type}'${this.assetParentPath.map((c) => `\\n\\tFound in (id: '${c.id}', type: '${c.type}')`)}`;\n }\n\n addAssetParent(asset: Asset): void {\n this.assetParentPath.push(asset);\n this.updateMessage();\n }\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 */\nexport const ReactPlayer = ({ view }: ReactPlayerProps) => {\n return <ReactAsset {...view} />;\n};\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 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\";\nimport type {\n FlowManager,\n ManagedPlayerProps,\n ManagedPlayerState,\n ManagerMiddleware,\n ManagedPlayerContext,\n} from \"./types\";\nimport type { StartOptions } from \"@player-ui/player\";\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 type StateChangeCallback = (state?: ManagedPlayerState) => void;\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 /** options forwarded to `player.start()` for each flow */\n startOptions?: StartOptions;\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 startOptions: options.startOptions,\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, startOptions } = this.state.context;\n this.start({ playerConfig, manager, startOptions });\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, startOptions } =\n this.state.context;\n this.setState({\n value: \"completed\",\n context: {\n playerConfig,\n manager,\n result: prevResult,\n reactPlayer,\n startOptions,\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 if (c && typeof c === \"function\") {\n c(this.state);\n }\n });\n\n const { manager, reactPlayer, playerConfig, startOptions } = state.context;\n\n try {\n const nextState = await this.processState(state, {\n manager,\n reactPlayer,\n playerConfig,\n startOptions,\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 startOptions,\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(\n state.context.flow,\n state.context.startOptions,\n ),\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\nfunction createKey(): ManagedPlayerStateKey {\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 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 /** Options forwarded to `player.start()` for each flow */\n startOptions?: StartOptions;\n}): { managedState: ManagedState; state?: ManagedPlayerState } => {\n const mounted = React.useRef(false);\n const previousManager = React.useRef(options.manager);\n const keyRef = React.useRef<ManagedPlayerStateKey>(createKey());\n const managedStateRef = React.useRef(\n new ManagedState({ middleware: options.middleware }),\n );\n\n if (!mounted.current) {\n managedPlayerStateMachines.set(keyRef.current, managedStateRef.current);\n mounted.current = true;\n }\n\n if (previousManager.current !== options.manager) {\n const oldManagedState = managedPlayerStateMachines.get(keyRef.current);\n\n /**\n * We have to handle terminate here as well as the useEffect in the\n * ManagedPlayer since it won't have the instance of the previous manager\n */\n if (oldManagedState) {\n const playerState =\n oldManagedState.state?.context.reactPlayer.player.getState();\n\n if (\n oldManagedState.state?.value === \"running\" &&\n playerState?.status === \"in-progress\"\n ) {\n previousManager.current.terminate?.(playerState);\n }\n }\n\n const newKey = createKey();\n const newManagedState = new ManagedState({\n middleware: options.middleware,\n });\n\n managedPlayerStateMachines.set(newKey, newManagedState);\n keyRef.current = newKey;\n managedStateRef.current = newManagedState;\n previousManager.current = options.manager;\n }\n\n const managedState =\n managedPlayerStateMachines.get(keyRef.current) ?? managedStateRef.current;\n\n /**\n * There are times where the managedState the external store references no\n * longer exists, so we have to wrap instead of calling addListener directly.\n */\n function subscription(callback: (val?: ManagedPlayerState) => void) {\n if (managedState) {\n const unsub = managedState.addListener((s) => {\n callback(s);\n });\n\n return () => {\n if (managedState) {\n unsub();\n }\n };\n }\n\n return () => {};\n }\n\n function getSnapshot() {\n return managedState.state;\n }\n\n const state = useSyncExternalStore(\n subscription,\n getSnapshot,\n () => undefined,\n );\n\n /**\n * This needs to come after useSyncExternalStore, otherwise it causes\n * a weird state update and none of the refs in this hook persist\n */\n if (managedState.state === undefined) {\n managedState.start(options);\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 = (\n props: ManagedPlayerProps,\n): React.JSX.Element | null => {\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 startOptions: props.startOptions,\n });\n\n const previousState = React.useRef<ManagedPlayerState | undefined>();\n\n if (state?.value !== previousState.current?.value) {\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?.(state.context.flow);\n }\n }\n\n previousState.current = 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);\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;;;ACAd,OAAOA,YAAW;AAClB,SAAS,mBAAmB,yBAAyB;AACrD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AAQzB,SAAS,cAAc;AACvB,SAAS,iBAAAC,sBA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AAA,EACF;AAEA,gBAAc,UAAU;AAExB,EAAAA,OAAM,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,WAAW;AAAA,MACvC;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,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","ErrorBoundary","props","React","React","React","React","ReactPlayer","ErrorBoundary","React","React","ReactPlayer","React","ReactPlayer","React"]}
package/package.json CHANGED
@@ -6,13 +6,13 @@
6
6
  "types"
7
7
  ],
8
8
  "name": "@player-ui/react",
9
- "version": "1.0.2--canary.900.39222",
9
+ "version": "1.0.2--canary.900.39588",
10
10
  "main": "dist/cjs/index.cjs",
11
11
  "dependencies": {
12
- "@player-ui/metrics-plugin": "1.0.2--canary.900.39222",
13
- "@player-ui/partial-match-registry": "1.0.2--canary.900.39222",
14
- "@player-ui/player": "1.0.2--canary.900.39222",
15
- "@player-ui/react-subscribe": "1.0.2--canary.900.39222",
12
+ "@player-ui/metrics-plugin": "1.0.2--canary.900.39588",
13
+ "@player-ui/partial-match-registry": "1.0.2--canary.900.39588",
14
+ "@player-ui/player": "1.0.2--canary.900.39588",
15
+ "@player-ui/react-subscribe": "1.0.2--canary.900.39588",
16
16
  "react-error-boundary": "^3.1.3",
17
17
  "tapable-ts": "^0.2.3",
18
18
  "leven": "3.1.0",
@@ -8,6 +8,7 @@ import {
8
8
  RequestTimeWebPlugin,
9
9
  } from "@player-ui/metrics-plugin";
10
10
  import { ManagedPlayer } from "../managed-player";
11
+ import { ReactPlayer } from "../../player";
11
12
  import type { FlowManager, FallbackProps } from "../types";
12
13
  import { SimpleAssetPlugin } from "../../__tests__/helpers/simple-asset-plugin";
13
14
  import { InProgressState } from "@player-ui/player";
@@ -120,6 +121,58 @@ describe.each([
120
121
  expect(onComplete).toBeCalled();
121
122
  });
122
123
 
124
+ test("forwards startOptions to player.start for each flow", async () => {
125
+ const startSpy = vitest.spyOn(ReactPlayer.prototype, "start");
126
+
127
+ const manager: FlowManager = {
128
+ next: vitest
129
+ .fn()
130
+ .mockReturnValueOnce(
131
+ Promise.resolve({
132
+ value: makeFlow({
133
+ id: "flow-1",
134
+ type: "collection",
135
+ values: [
136
+ {
137
+ asset: {
138
+ id: "action",
139
+ type: "action",
140
+ value: "Next",
141
+ label: "Continue",
142
+ },
143
+ },
144
+ ],
145
+ }),
146
+ }),
147
+ )
148
+ .mockReturnValue(Promise.resolve({ done: true })),
149
+ };
150
+
151
+ render(
152
+ <Suspense fallback="loading">
153
+ <ManagedPlayer
154
+ manager={manager}
155
+ plugins={[new SimpleAssetPlugin()]}
156
+ startOptions={{ format: "a2ui", version: "0.9" }}
157
+ onComplete={vitest.fn()}
158
+ onError={vitest.fn()}
159
+ />
160
+ </Suspense>,
161
+ { legacyRoot },
162
+ );
163
+
164
+ // The managed player forwards startOptions verbatim to player.start at the
165
+ // loaded -> running transition, independent of what the flow renders.
166
+ await vitest.waitFor(() =>
167
+ expect(startSpy).toHaveBeenCalledWith(expect.anything(), {
168
+ format: "a2ui",
169
+ version: "0.9",
170
+ }),
171
+ );
172
+
173
+ startSpy.mockRestore();
174
+ });
175
+
123
176
  test("handles dummy flows", async () => {
124
177
  const manager: FlowManager = {
125
178
  next: vitest
@@ -7,6 +7,7 @@ import type {
7
7
  ManagerMiddleware,
8
8
  ManagedPlayerContext,
9
9
  } from "./types";
10
+ import type { StartOptions } from "@player-ui/player";
10
11
  import { useRequestTime } from "./request-time";
11
12
  import type { ReactPlayerOptions } from "../player";
12
13
  import { ReactPlayer } from "../player";
@@ -57,6 +58,9 @@ class ManagedState {
57
58
 
58
59
  /** the config to use when creating a player */
59
60
  playerConfig: ReactPlayerOptions;
61
+
62
+ /** options forwarded to `player.start()` for each flow */
63
+ startOptions?: StartOptions;
60
64
  }): this {
61
65
  const initialState: ManagedPlayerState = {
62
66
  value: "not_started",
@@ -64,6 +68,7 @@ class ManagedState {
64
68
  playerConfig: options.playerConfig,
65
69
  reactPlayer: new ReactPlayer(options.playerConfig),
66
70
  manager: options.manager,
71
+ startOptions: options.startOptions,
67
72
  },
68
73
  };
69
74
 
@@ -75,8 +80,8 @@ class ManagedState {
75
80
  /** reset starts from nothing */
76
81
  public reset(): void {
77
82
  if (this.state?.value === "error") {
78
- const { playerConfig, manager } = this.state.context;
79
- this.start({ playerConfig, manager });
83
+ const { playerConfig, manager, startOptions } = this.state.context;
84
+ this.start({ playerConfig, manager, startOptions });
80
85
  } else {
81
86
  throw new Error("Flow must be in error state to reset");
82
87
  }
@@ -85,7 +90,7 @@ class ManagedState {
85
90
  /** restart starts from the last result */
86
91
  public restart(): void {
87
92
  if (this.state?.value === "error") {
88
- const { playerConfig, manager, prevResult, reactPlayer } =
93
+ const { playerConfig, manager, prevResult, reactPlayer, startOptions } =
89
94
  this.state.context;
90
95
  this.setState({
91
96
  value: "completed",
@@ -94,6 +99,7 @@ class ManagedState {
94
99
  manager,
95
100
  result: prevResult,
96
101
  reactPlayer,
102
+ startOptions,
97
103
  },
98
104
  });
99
105
  } else {
@@ -109,13 +115,14 @@ class ManagedState {
109
115
  }
110
116
  });
111
117
 
112
- const { manager, reactPlayer, playerConfig } = state.context;
118
+ const { manager, reactPlayer, playerConfig, startOptions } = state.context;
113
119
 
114
120
  try {
115
121
  const nextState = await this.processState(state, {
116
122
  manager,
117
123
  reactPlayer,
118
124
  playerConfig,
125
+ startOptions,
119
126
  });
120
127
 
121
128
  if (nextState) {
@@ -128,6 +135,7 @@ class ManagedState {
128
135
  manager,
129
136
  reactPlayer,
130
137
  playerConfig,
138
+ startOptions,
131
139
  error: e as Error,
132
140
  },
133
141
  });
@@ -184,7 +192,10 @@ class ManagedState {
184
192
  ...context,
185
193
  flow: state.context.flow,
186
194
  prevResult: state.context.prevResult,
187
- result: state.context.reactPlayer.start(state.context.flow),
195
+ result: state.context.reactPlayer.start(
196
+ state.context.flow,
197
+ state.context.startOptions,
198
+ ),
188
199
  },
189
200
  };
190
201
  }
@@ -224,6 +235,9 @@ export const usePersistentStateMachine = (options: {
224
235
 
225
236
  /** Any middleware for the manager */
226
237
  middleware?: ManagerMiddleware;
238
+
239
+ /** Options forwarded to `player.start()` for each flow */
240
+ startOptions?: StartOptions;
227
241
  }): { managedState: ManagedState; state?: ManagedPlayerState } => {
228
242
  const mounted = React.useRef(false);
229
243
  const previousManager = React.useRef(options.manager);
@@ -329,6 +343,7 @@ export const ManagedPlayer = (
329
343
  plugins: [...(props?.plugins ?? []), RequestTimeMetricsPlugin],
330
344
  player: props.player,
331
345
  },
346
+ startOptions: props.startOptions,
332
347
  });
333
348
 
334
349
  const previousState = React.useRef<ManagedPlayerState | undefined>();
@@ -1,5 +1,10 @@
1
1
  import type React from "react";
2
- import type { CompletedState, Flow, InProgressState } from "@player-ui/player";
2
+ import type {
3
+ CompletedState,
4
+ Flow,
5
+ InProgressState,
6
+ StartOptions,
7
+ } from "@player-ui/player";
3
8
  import type { ReactPlayer, ReactPlayerOptions } from "../player";
4
9
 
5
10
  export interface FinalState {
@@ -52,6 +57,12 @@ export interface ManagedPlayerProps extends ReactPlayerOptions {
52
57
  /** A callback when a flow is started */
53
58
  onStartedFlow?: (flow: Flow) => void;
54
59
 
60
+ /**
61
+ * Options forwarded to `player.start()` for every flow in the managed session,
62
+ * e.g. `{ format: "a2ui" }`. Defaults to the `"player"` format.
63
+ */
64
+ startOptions?: StartOptions;
65
+
55
66
  /** A callback when the entire async iteration is completed */
56
67
  onComplete?: (finalState?: CompletedState) => void;
57
68
 
@@ -71,6 +82,9 @@ export type ManagedPlayerContext = {
71
82
 
72
83
  /** The config for Player */
73
84
  playerConfig: ReactPlayerOptions;
85
+
86
+ /** Options forwarded to `player.start()` for each flow (e.g. `{ format: "a2ui" }`) */
87
+ startOptions?: StartOptions;
74
88
  };
75
89
 
76
90
  export type ManagedPlayerState =
package/src/player.tsx CHANGED
@@ -9,9 +9,9 @@ import { Registry } from "@player-ui/partial-match-registry";
9
9
  import type {
10
10
  CompletedState,
11
11
  PlayerPlugin,
12
- Flow,
13
12
  View,
14
13
  PlayerInfo,
14
+ StartOptions,
15
15
  } from "@player-ui/player";
16
16
  import { Player } from "@player-ui/player";
17
17
  import { ErrorBoundary, FallbackProps } from "react-error-boundary";
@@ -374,10 +374,13 @@ export class ReactPlayer {
374
374
  );
375
375
  }
376
376
 
377
- public start(flow: Flow): Promise<CompletedState> {
377
+ public start(
378
+ payload: unknown,
379
+ options?: StartOptions,
380
+ ): Promise<CompletedState> {
378
381
  this.setWaitForNextViewUpdate();
379
382
 
380
- return this.player.start(flow).finally(async () => {
383
+ return this.player.start(payload, options).finally(async () => {
381
384
  await this.setWaitForNextViewUpdate();
382
385
  });
383
386
  }
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import type { FlowManager, ManagedPlayerProps, ManagedPlayerState, ManagerMiddleware } from "./types";
3
+ import type { StartOptions } from "@player-ui/player";
3
4
  import type { ReactPlayerOptions } from "../player";
4
5
  export type StateChangeCallback = (state?: ManagedPlayerState) => void;
5
6
  /**
@@ -21,6 +22,8 @@ declare class ManagedState {
21
22
  manager: FlowManager;
22
23
  /** the config to use when creating a player */
23
24
  playerConfig: ReactPlayerOptions;
25
+ /** options forwarded to `player.start()` for each flow */
26
+ startOptions?: StartOptions;
24
27
  }): this;
25
28
  /** reset starts from nothing */
26
29
  reset(): void;
@@ -37,6 +40,8 @@ export declare const usePersistentStateMachine: (options: {
37
40
  playerConfig: ReactPlayerOptions;
38
41
  /** Any middleware for the manager */
39
42
  middleware?: ManagerMiddleware;
43
+ /** Options forwarded to `player.start()` for each flow */
44
+ startOptions?: StartOptions;
40
45
  }) => {
41
46
  managedState: ManagedState;
42
47
  state?: ManagedPlayerState;
@@ -1,5 +1,5 @@
1
1
  import type React from "react";
2
- import type { CompletedState, Flow, InProgressState } from "@player-ui/player";
2
+ import type { CompletedState, Flow, InProgressState, StartOptions } from "@player-ui/player";
3
3
  import type { ReactPlayer, ReactPlayerOptions } from "../player";
4
4
  export interface FinalState {
5
5
  /** Mark the iteration as complete */
@@ -41,6 +41,11 @@ export interface ManagedPlayerProps extends ReactPlayerOptions {
41
41
  manager: FlowManager;
42
42
  /** A callback when a flow is started */
43
43
  onStartedFlow?: (flow: Flow) => void;
44
+ /**
45
+ * Options forwarded to `player.start()` for every flow in the managed session,
46
+ * e.g. `{ format: "a2ui" }`. Defaults to the `"player"` format.
47
+ */
48
+ startOptions?: StartOptions;
44
49
  /** A callback when the entire async iteration is completed */
45
50
  onComplete?: (finalState?: CompletedState) => void;
46
51
  /** A callback for any errors */
@@ -55,6 +60,8 @@ export type ManagedPlayerContext = {
55
60
  reactPlayer: ReactPlayer;
56
61
  /** The config for Player */
57
62
  playerConfig: ReactPlayerOptions;
63
+ /** Options forwarded to `player.start()` for each flow (e.g. `{ format: "a2ui" }`) */
64
+ startOptions?: StartOptions;
58
65
  };
59
66
  export type ManagedPlayerState = {
60
67
  /** The managed player hasn't started yet */
package/types/player.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { SyncWaterfallHook, AsyncParallelHook } from "tapable-ts";
3
3
  import { Subscribe } from "@player-ui/react-subscribe";
4
- import type { CompletedState, PlayerPlugin, Flow, View, PlayerInfo } from "@player-ui/player";
4
+ import type { CompletedState, PlayerPlugin, View, PlayerInfo, StartOptions } from "@player-ui/player";
5
5
  import { Player } from "@player-ui/player";
6
6
  import type { AssetRegistryType } from "./asset";
7
7
  import type { ReactPlayerProps } from "./app";
@@ -88,7 +88,7 @@ export declare class ReactPlayer {
88
88
  * If the `suspense` option is set, this will suspend while an update is pending, otherwise nothing will be rendered.
89
89
  */
90
90
  setWaitForNextViewUpdate(): Promise<void>;
91
- start(flow: Flow): Promise<CompletedState>;
91
+ start(payload: unknown, options?: StartOptions): Promise<CompletedState>;
92
92
  }
93
93
  export declare const WebPlayer: typeof ReactPlayer;
94
94
  //# sourceMappingURL=player.d.ts.map