@player-ui/react 0.15.0-next.3 → 0.15.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +62 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +61 -4
- package/dist/index.mjs +61 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/asset/AssetRenderError.ts +44 -0
- package/src/asset/__tests__/index.bench.tsx +102 -0
- package/src/asset/__tests__/index.test.tsx +35 -0
- package/src/asset/index.tsx +35 -6
- package/types/asset/AssetRenderError.d.ts +13 -0
- package/types/asset/index.d.ts +2 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
var src_exports = {};
|
|
33
33
|
__export(src_exports, {
|
|
34
34
|
AssetContext: () => AssetContext,
|
|
35
|
+
AssetRenderError: () => AssetRenderError,
|
|
35
36
|
ManagedPlayer: () => ManagedPlayer,
|
|
36
37
|
PlayerContext: () => PlayerContext,
|
|
37
38
|
ReactAsset: () => ReactAsset,
|
|
@@ -61,16 +62,54 @@ var import_tapable_ts = require("tapable-ts");
|
|
|
61
62
|
var import_react_subscribe = require("@player-ui/react-subscribe");
|
|
62
63
|
var import_partial_match_registry = require("@player-ui/partial-match-registry");
|
|
63
64
|
var import_player2 = require("@player-ui/player");
|
|
64
|
-
var
|
|
65
|
+
var import_react_error_boundary2 = require("react-error-boundary");
|
|
65
66
|
|
|
66
67
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx
|
|
67
68
|
var import_react = __toESM(require("react"));
|
|
68
69
|
var import_leven = __toESM(require("leven"));
|
|
70
|
+
var import_react_error_boundary = require("react-error-boundary");
|
|
71
|
+
|
|
72
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/AssetRenderError.ts
|
|
73
|
+
var AssetRenderError = class extends Error {
|
|
74
|
+
constructor(rootAsset, message, innerException) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.rootAsset = rootAsset;
|
|
77
|
+
this.innerException = innerException;
|
|
78
|
+
this.assetParentPath = [];
|
|
79
|
+
this.initialMessage = message ?? "";
|
|
80
|
+
this.innerExceptionMessage = innerException instanceof Error ? innerException.message : String(innerException);
|
|
81
|
+
if (this.innerExceptionMessage) {
|
|
82
|
+
this.initialMessage = this.initialMessage.concat(
|
|
83
|
+
"\nCaused by: ",
|
|
84
|
+
this.innerExceptionMessage
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
this.message = this.initialMessage;
|
|
88
|
+
}
|
|
89
|
+
updateMessage() {
|
|
90
|
+
this.message = `${this.initialMessage}
|
|
91
|
+
${this.getAssetPathMessage()}
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
getAssetPathMessage() {
|
|
95
|
+
return `Exception occurred in asset with id '${this.rootAsset.id}' of type '${this.rootAsset.type}'${this.assetParentPath.map((c) => `
|
|
96
|
+
Found in (id: '${c.id}', type: '${c.type}')`)}`;
|
|
97
|
+
}
|
|
98
|
+
addAssetParent(asset) {
|
|
99
|
+
this.assetParentPath.push(asset);
|
|
100
|
+
this.updateMessage();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx
|
|
69
105
|
var AssetContext = import_react.default.createContext({});
|
|
106
|
+
var isAssetUnwrapped = (props) => {
|
|
107
|
+
return "type" in props && "id" in props;
|
|
108
|
+
};
|
|
70
109
|
var ReactAsset = (props) => {
|
|
71
110
|
const { registry } = import_react.default.useContext(AssetContext);
|
|
72
111
|
let unwrapped;
|
|
73
|
-
if (
|
|
112
|
+
if (isAssetUnwrapped(props)) {
|
|
74
113
|
unwrapped = props;
|
|
75
114
|
} else if ("asset" in props) {
|
|
76
115
|
unwrapped = props.asset;
|
|
@@ -125,7 +164,25 @@ var ReactAsset = (props) => {
|
|
|
125
164
|
${JSON.stringify(matchList)}`
|
|
126
165
|
);
|
|
127
166
|
}
|
|
128
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
167
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
168
|
+
import_react_error_boundary.ErrorBoundary,
|
|
169
|
+
{
|
|
170
|
+
fallbackRender: (props2) => {
|
|
171
|
+
const { error } = props2;
|
|
172
|
+
if (error instanceof AssetRenderError) {
|
|
173
|
+
error.addAssetParent(unwrapped);
|
|
174
|
+
throw error;
|
|
175
|
+
} else {
|
|
176
|
+
throw new AssetRenderError(
|
|
177
|
+
unwrapped,
|
|
178
|
+
"Failed to render asset",
|
|
179
|
+
error
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
/* @__PURE__ */ import_react.default.createElement(Impl, { key: unwrapped.id, ...unwrapped })
|
|
185
|
+
);
|
|
129
186
|
};
|
|
130
187
|
|
|
131
188
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/player-context.ts
|
|
@@ -322,7 +379,7 @@ var ReactPlayer2 = class {
|
|
|
322
379
|
const BaseComp = this.hooks.webComponent.call(this.createReactComp());
|
|
323
380
|
const ReactPlayerComponent = (props) => {
|
|
324
381
|
return /* @__PURE__ */ import_react4.default.createElement(
|
|
325
|
-
|
|
382
|
+
import_react_error_boundary2.ErrorBoundary,
|
|
326
383
|
{
|
|
327
384
|
fallbackRender: () => null,
|
|
328
385
|
onError: (err) => {
|
|
@@ -720,6 +777,7 @@ var ManagedPlayer = (props) => {
|
|
|
720
777
|
// Annotate the CommonJS export names for ESM import in node:
|
|
721
778
|
0 && (module.exports = {
|
|
722
779
|
AssetContext,
|
|
780
|
+
AssetRenderError,
|
|
723
781
|
ManagedPlayer,
|
|
724
782
|
PlayerContext,
|
|
725
783
|
ReactAsset,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/player-context.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-logger.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-asset-props.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/helpers.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/url.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/shared-constants.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/app.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/onupdate-plugin.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/hooks.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/tapstate-plugin.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/managed-player.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/request-time.tsx"],"sourcesContent":["export * from \"@player-ui/player\";\nexport * from \"./player\";\nexport * from \"./hooks\";\nexport * from \"./manager/managed-player\";\nexport * from \"./manager/request-time\";\nexport * from \"./manager/types\";\nexport * from \"./asset\";\nexport * from \"./utils\";\n","import React from \"react\";\nimport { SyncWaterfallHook, AsyncParallelHook } from \"tapable-ts\";\nimport { Subscribe, useSubscribedState } from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n Flow,\n View,\n PlayerInfo,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport { ReactPlayer as PlayerComp } from \"./app\";\nimport { OnUpdatePlugin } from \"./plugins/onupdate-plugin\";\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 = Record<string, unknown>;\n\n/** A Player that renders UI through React */\nexport class ReactPlayer {\n public readonly options: ReactPlayerOptions;\n public readonly player: Player;\n public readonly assetRegistry: AssetRegistryType = new Registry();\n public readonly Component: React.ComponentType<ReactPlayerComponentProps>;\n public readonly hooks: {\n /**\n * A hook to create a React Component to be used for Player, regardless of the current flow state\n */\n webComponent: SyncWaterfallHook<[React.ComponentType], Record<string, any>>;\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 = new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n this.options = options ?? {};\n\n const Devtools = _window?.__PLAYER_DEVTOOLS_PLUGIN;\n const onUpdatePlugin = new OnUpdatePlugin(\n this.viewUpdateSubscription.publish,\n );\n\n const plugins = options?.plugins ?? [];\n\n if (Devtools) {\n plugins.push(new Devtools());\n }\n\n const playerPlugins = plugins.filter((p) =>\n Boolean(p.apply),\n ) as PlayerPlugin[];\n\n this.player = options?.player ?? new Player({ plugins: playerPlugins });\n\n plugins.forEach((plugin) => {\n if (plugin.applyReact) {\n plugin.applyReact(this);\n }\n });\n\n onUpdatePlugin.apply(this.player);\n\n this.Component = this.createReactPlayerComponent();\n this.reactPlayerInfo = {\n version: this.player.getVersion(),\n commit: this.player.getCommit(),\n };\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): void {\n if (!plugin.applyReact) return;\n\n plugin.applyReact(this);\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 return (\n <ErrorBoundary\n fallbackRender={() => null}\n onError={(err) => {\n const playerState = this.player.getState();\n\n if (playerState.status === \"in-progress\") {\n playerState.fail(err);\n }\n }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...props} />\n </PlayerContext.Provider>\n </ErrorBoundary>\n );\n };\n\n return ReactPlayerComponent;\n }\n\n private createReactComp(): React.ComponentType<ReactPlayerComponentProps> {\n const ActualPlayerComp = this.hooks.playerComponent.call(PlayerComp);\n\n /** the component to use to render the player */\n const WebPlayerComponent = () => {\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n this.viewUpdateSubscription.suspend();\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {view && <ActualPlayerComp view={view} />}\n </AssetContext.Provider>\n );\n };\n\n return WebPlayerComponent;\n }\n\n /**\n * Call this method to force the ReactPlayer to wait for the next view-update before performing the next render.\n * If the `suspense` option is set, this will suspend while an update is pending, otherwise nothing will be rendered.\n */\n public setWaitForNextViewUpdate(): 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\";\n\nexport type AssetRegistryType = Registry<React.ComponentType<any>>;\n\nexport interface ContextType {\n /**\n * A registry of Asset -> React Components\n */\n registry?: AssetRegistryType;\n}\n\nexport const AssetContext = React.createContext<ContextType>({});\n\n/**\n * A React Component that looks up an implementation from a registry\n */\nexport const ReactAsset = (\n props: AssetType<string> | AssetWrapper<AssetType<string>>,\n) => {\n const { registry } = React.useContext(AssetContext);\n\n let unwrapped;\n\n if (\"type\" in props && \"id\" in props) {\n unwrapped = props;\n } else if (\"asset\" in props) {\n unwrapped = (props as unknown as AssetWrapper).asset;\n }\n\n if (!unwrapped) {\n throw Error(\n `Cannot determine asset type for props: ${JSON.stringify(props)}`,\n );\n }\n\n if (typeof unwrapped !== \"object\") {\n throw Error(\n `Asset was not an object got (${typeof unwrapped}) instead: ${unwrapped}`,\n );\n }\n\n if (unwrapped.type === undefined) {\n const info =\n unwrapped.id === undefined\n ? JSON.stringify(props)\n : `id: ${unwrapped.id}`;\n throw Error(`Asset is missing type for ${info}`);\n }\n\n if (!registry || registry.isRegistryEmpty()) {\n throw Error(`No asset found in registry. This could happen for one of the following reasons: \\n\n 1. You might have no assets registered or no plugins added to the Player instance. \\n\n 2. You might have mismatching versions of React Asset Registry Context. \\n\n See https://player-ui.github.io/latest/tools/cli#player-dependency-versions-check for tips about how to debug and fix this problem`);\n }\n\n const Impl = registry?.get(unwrapped);\n\n if (!Impl) {\n const matchList: object[] = [];\n\n registry.forEach((asset) => {\n matchList.push(asset.key);\n });\n\n const typeList = matchList.map(\n (match) => JSON.parse(JSON.stringify(match)).type,\n );\n\n const similarType = typeList.reduce((prev, curr) => {\n const next = {\n value: leven(unwrapped.type, curr),\n type: curr,\n };\n\n if (prev !== undefined && prev.value < next.value) {\n return prev;\n }\n\n return next;\n }, undefined);\n\n throw Error(\n `No implementation found for id: ${unwrapped.id} type: ${unwrapped.type}. Did you mean ${similarType.type}? \\n \n Registered Asset matching functions are listed below: \\n\n ${JSON.stringify(matchList)}`,\n );\n }\n\n return <Impl key={unwrapped.id} {...unwrapped} />;\n};\n","import React from \"react\";\nimport type { Player, NavigationFlowViewState } from \"@player-ui/player\";\n\nexport interface PlayerContextType {\n /**\n * An instance of a headless player\n */\n player?: Player;\n\n /** The currently rendered view state */\n viewState?: NavigationFlowViewState;\n}\n\nexport const PlayerContext = React.createContext<PlayerContextType>({});\n\n/**\n * A hook to get the current player\n */\nexport const usePlayer = () => {\n const { player } = React.useContext(PlayerContext);\n\n return player;\n};\n","import type { Logger } from \"@player-ui/player\";\nimport { NoopLogger } from \"@player-ui/player\";\nimport { usePlayer } from \"./player-context\";\n\nconst noopLogger = new NoopLogger();\n\n/**\n * A hook to get the logger instance from the current player\n */\nexport function useLogger(): Logger {\n const player = usePlayer();\n\n return player?.logger ?? noopLogger;\n}\n","import type { Asset } from \"@player-ui/player\";\n\n/** Common props for any dom node */\nexport function useAssetProps(asset: Asset) {\n return {\n id: asset.id,\n \"data-asset-type\": asset.type,\n };\n}\n","/**\n * Trim leading and trailing slashes from string\n */\nexport function trimSlashes(str: string) {\n return str.replace(/^\\/+|\\/+$/g, \"\");\n}\n\n/**\n * Removes any key: value pairs from an object when the value is null or undefined\n */\nexport function removeEmptyValuesFromObject(\n obj: Record<string, any>,\n): Record<string, NonNullable<any>> {\n return Object.keys(obj).reduce(\n (acc, key) => {\n const value = obj[key];\n\n if (value !== null && value !== undefined) {\n acc[key] = value;\n }\n\n return acc;\n },\n {} as Record<string, any>,\n );\n}\n\n/** Check if the object has no keys */\nexport function isEmptyObject(obj: Record<string, unknown>) {\n return Object.keys(obj).length === 0 && obj.constructor === Object;\n}\n\n/** Check if the argument is a function */\nexport function isFunction<ReturnType>(\n maybeFn: ReturnType | ((...args: unknown[]) => ReturnType),\n): maybeFn is (...args: unknown[]) => ReturnType {\n return Boolean(maybeFn instanceof Function || typeof maybeFn === \"function\");\n}\n\n/**\n * Calls function with provided data or returns original value\n */\nexport function callOrReturn<\n ReturnType,\n FnArgs extends Array<unknown> = unknown[],\n FnType = (...args: FnArgs) => ReturnType,\n>(maybeFn: FnType | ReturnType, fnArgs: FnArgs): ReturnType {\n if (isFunction(maybeFn)) {\n return maybeFn(fnArgs) as ReturnType;\n }\n\n return maybeFn as ReturnType;\n}\n","import { isEmptyObject } from \"./helpers\";\n\n/**\n * Combines a URL with any additional parameters\n */\nexport function buildUrl(\n url: string,\n params: Record<string, unknown> = {},\n): string {\n const baseUrl = new URL(url);\n\n if (params && isEmptyObject(params)) {\n return baseUrl.toString();\n }\n\n Object.keys(params).forEach((key) => {\n const value = params[key];\n baseUrl.searchParams.append(key, String(value));\n });\n\n return baseUrl.toString();\n}\n","import { usePlayer } from \"./player-context\";\n\n/** Hook to get a constant under a specific namespace */\nexport function useGetConstantByType(type: string, key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, type);\n}\n\n/** Get a constant under the default namespace */\nexport function useGetConstant(key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, \"constants\");\n}\n","import React from \"react\";\nimport type { View } from \"@player-ui/player\";\nimport { ReactAsset } from \"./asset\";\n\nexport interface ReactPlayerProps {\n /**\n * The Content view object to render\n */\n view: View;\n}\n\n/**\n * The entry for the ReactPlayer's React tree\n */\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?.(\n playerState.controllers.data.serialize(),\n );\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?.();\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.controllers.data.serialize());\n }\n };\n }, [props.manager, state?.context.reactPlayer.player, state?.value]);\n\n if (state?.value === \"error\") {\n if (props.fallbackComponent) {\n return (\n <props.fallbackComponent\n reset={() => {\n managedState.reset();\n }}\n retry={() => {\n managedState.restart();\n }}\n error={state.context.error}\n />\n );\n }\n\n if (!props.onError) {\n throw state.context.error;\n }\n }\n\n if (state?.context.reactPlayer) {\n const { Component } = state.context.reactPlayer;\n\n return <Component />;\n }\n\n return null;\n};\n","import { useCallback, useEffect, useRef, useMemo } from \"react\";\nimport type { Player } from \"@player-ui/player\";\nimport type { MetricsCorePlugin } from \"@player-ui/metrics-plugin\";\nimport {\n MetricsCorePluginSymbol,\n RequestTimeWebPlugin,\n} from \"@player-ui/metrics-plugin\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\ntype RequestTime = {\n /** request start time */\n start?: number;\n /** request end time */\n end?: number;\n};\n\n/** hook to time a promise and add it to the metrics plugin */\nexport const useRequestTime = () => {\n const requestTimeRef = useRef<RequestTime>({});\n\n useEffect(() => {\n return () => {\n requestTimeRef.current = {};\n };\n }, [requestTimeRef]);\n\n const getRequestTime = useCallback(() => {\n const { end, start } = requestTimeRef.current;\n\n if (end && start) {\n return end - start;\n }\n }, [requestTimeRef]);\n\n /** wrap a promise with tracking it's time in flight */\n function withRequestTime<Type>(nextPromise: Promise<Type>): Promise<Type> {\n const getTime = typeof performance === \"undefined\" ? Date : performance;\n requestTimeRef.current = { start: getTime.now() };\n\n return nextPromise.finally(() => {\n requestTimeRef.current = {\n ...requestTimeRef.current,\n end: getTime.now(),\n };\n });\n }\n\n const RequestTimeMetricsPlugin: ReactPlayerPlugin = useMemo(() => {\n return {\n name: \"RequestTimeMetricsPlugin\",\n apply(player: Player): void {\n player.applyTo<MetricsCorePlugin>(\n MetricsCorePluginSymbol,\n (metricsCorePlugin) => {\n new RequestTimeWebPlugin(getRequestTime).apply(metricsCorePlugin);\n },\n );\n },\n };\n }, [getRequestTime]);\n\n return { withRequestTime, RequestTimeMetricsPlugin };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,8BAAd;;;ACAA,IAAAC,gBAAkB;AAClB,wBAAqD;AACrD,6BAA8C;AAC9C,oCAAyB;A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YAAM,gBAAgB;AAAA,IACxB;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,YAAY,YAAY,KAAK,UAAU,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,SAAS,OAAO,QAAQ,YAAY,QAAQ,OAAO,KAAK,CAAC;AAEnE,MAAI,OAAO,UAAU,SAAS;AAC5B,QAAI,MAAM,mBAAmB;AAC3B,aACE,8BAAAA,QAAA;AAAA,QAAC,MAAM;AAAA,QAAN;AAAA,UACC,OAAO,MAAM;AACX,yBAAa,MAAM;AAAA,UACrB;AAAA,UACA,OAAO,MAAM;AACX,yBAAa,QAAQ;AAAA,UACvB;AAAA,UACA,OAAO,MAAM,QAAQ;AAAA;AAAA,MACvB;AAAA,IAEJ;AAEA,QAAI,CAAC,MAAM,SAAS;AAClB,YAAM,MAAM,QAAQ;AAAA,IACtB;AAAA,EACF;AAEA,MAAI,OAAO,QAAQ,aAAa;AAC9B,UAAM,EAAE,UAAU,IAAI,MAAM,QAAQ;AAEpC,WAAO,8BAAAA,QAAA,cAAC,eAAU;AAAA,EACpB;AAEA,SAAO;AACT;","names":["ReactPlayer","import_react","import_player","React","leven","import_react","React","import_react","React","ReactPlayer","React","import_player","import_react","React","ReactPlayer","import_react","import_react","ReactPlayer","React"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/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 { Subscribe, useSubscribedState } from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n Flow,\n View,\n PlayerInfo,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport { ReactPlayer as PlayerComp } from \"./app\";\nimport { OnUpdatePlugin } from \"./plugins/onupdate-plugin\";\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 = Record<string, unknown>;\n\n/** A Player that renders UI through React */\nexport class ReactPlayer {\n public readonly options: ReactPlayerOptions;\n public readonly player: Player;\n public readonly assetRegistry: AssetRegistryType = new Registry();\n public readonly Component: React.ComponentType<ReactPlayerComponentProps>;\n public readonly hooks: {\n /**\n * A hook to create a React Component to be used for Player, regardless of the current flow state\n */\n webComponent: SyncWaterfallHook<[React.ComponentType], Record<string, any>>;\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 = new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n this.options = options ?? {};\n\n const Devtools = _window?.__PLAYER_DEVTOOLS_PLUGIN;\n const onUpdatePlugin = new OnUpdatePlugin(\n this.viewUpdateSubscription.publish,\n );\n\n const plugins = options?.plugins ?? [];\n\n if (Devtools) {\n plugins.push(new Devtools());\n }\n\n const playerPlugins = plugins.filter((p) =>\n Boolean(p.apply),\n ) as PlayerPlugin[];\n\n this.player = options?.player ?? new Player({ plugins: playerPlugins });\n\n plugins.forEach((plugin) => {\n if (plugin.applyReact) {\n plugin.applyReact(this);\n }\n });\n\n onUpdatePlugin.apply(this.player);\n\n this.Component = this.createReactPlayerComponent();\n this.reactPlayerInfo = {\n version: this.player.getVersion(),\n commit: this.player.getCommit(),\n };\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): void {\n if (!plugin.applyReact) return;\n\n plugin.applyReact(this);\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 return (\n <ErrorBoundary\n fallbackRender={() => null}\n onError={(err) => {\n const playerState = this.player.getState();\n\n if (playerState.status === \"in-progress\") {\n playerState.fail(err);\n }\n }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...props} />\n </PlayerContext.Provider>\n </ErrorBoundary>\n );\n };\n\n return ReactPlayerComponent;\n }\n\n private createReactComp(): React.ComponentType<ReactPlayerComponentProps> {\n const ActualPlayerComp = this.hooks.playerComponent.call(PlayerComp);\n\n /** the component to use to render the player */\n const WebPlayerComponent = () => {\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n this.viewUpdateSubscription.suspend();\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {view && <ActualPlayerComp view={view} />}\n </AssetContext.Provider>\n );\n };\n\n return WebPlayerComponent;\n }\n\n /**\n * Call this method to force the ReactPlayer to wait for the next view-update before performing the next render.\n * If the `suspense` option is set, this will suspend while an update is pending, otherwise nothing will be rendered.\n */\n public setWaitForNextViewUpdate(): 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 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 }}\n >\n <Impl key={unwrapped.id} {...unwrapped} />\n </ErrorBoundary>\n );\n};\n","import type { Asset } from \"@player-ui/player\";\n\nexport class AssetRenderError extends Error {\n private assetParentPath: Array<Asset> = [];\n initialMessage: string;\n innerExceptionMessage: string;\n\n constructor(\n readonly rootAsset: Asset,\n message?: string,\n readonly innerException?: unknown,\n ) {\n super(message);\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?.(\n playerState.controllers.data.serialize(),\n );\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?.();\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.controllers.data.serialize());\n }\n };\n }, [props.manager, state?.context.reactPlayer.player, state?.value]);\n\n if (state?.value === \"error\") {\n if (props.fallbackComponent) {\n return (\n <props.fallbackComponent\n reset={() => {\n managedState.reset();\n }}\n retry={() => {\n managedState.restart();\n }}\n error={state.context.error}\n />\n );\n }\n\n if (!props.onError) {\n throw state.context.error;\n }\n }\n\n if (state?.context.reactPlayer) {\n const { Component } = state.context.reactPlayer;\n\n return <Component />;\n }\n\n return null;\n};\n","import { useCallback, useEffect, useRef, useMemo } from \"react\";\nimport type { Player } from \"@player-ui/player\";\nimport type { MetricsCorePlugin } from \"@player-ui/metrics-plugin\";\nimport {\n MetricsCorePluginSymbol,\n RequestTimeWebPlugin,\n} from \"@player-ui/metrics-plugin\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\ntype RequestTime = {\n /** request start time */\n start?: number;\n /** request end time */\n end?: number;\n};\n\n/** hook to time a promise and add it to the metrics plugin */\nexport const useRequestTime = () => {\n const requestTimeRef = useRef<RequestTime>({});\n\n useEffect(() => {\n return () => {\n requestTimeRef.current = {};\n };\n }, [requestTimeRef]);\n\n const getRequestTime = useCallback(() => {\n const { end, start } = requestTimeRef.current;\n\n if (end && start) {\n return end - start;\n }\n }, [requestTimeRef]);\n\n /** wrap a promise with tracking it's time in flight */\n function withRequestTime<Type>(nextPromise: Promise<Type>): Promise<Type> {\n const getTime = typeof performance === \"undefined\" ? Date : performance;\n requestTimeRef.current = { start: getTime.now() };\n\n return nextPromise.finally(() => {\n requestTimeRef.current = {\n ...requestTimeRef.current,\n end: getTime.now(),\n };\n });\n }\n\n const RequestTimeMetricsPlugin: ReactPlayerPlugin = useMemo(() => {\n return {\n name: \"RequestTimeMetricsPlugin\",\n apply(player: Player): void {\n player.applyTo<MetricsCorePlugin>(\n MetricsCorePluginSymbol,\n (metricsCorePlugin) => {\n new RequestTimeWebPlugin(getRequestTime).apply(metricsCorePlugin);\n },\n );\n },\n };\n }, [getRequestTime]);\n\n return { withRequestTime, RequestTimeMetricsPlugin };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAAA;AAAA,EAAA;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,6BAA8C;AAC9C,oCAAyB;AAQzB,IAAAC,iBAAuB;AACvB,IAAAC,+BAA8B;;;ACZ9B,mBAAkB;AAClB,mBAAkB;AAGlB,kCAA8B;;;ACFvB,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAK1C,YACW,WACT,SACS,gBACT;AACA,UAAM,OAAO;AAJJ;AAEA;AAPX,SAAQ,kBAAgC,CAAC;AAUvC,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;AACt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AAQ;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_react","React","ReactPlayer","React","import_player","import_react","React","ReactPlayer","import_react","import_react","ReactPlayer","React"]}
|
package/dist/index.legacy-esm.js
CHANGED
|
@@ -7,16 +7,54 @@ import { SyncWaterfallHook, AsyncParallelHook } from "tapable-ts";
|
|
|
7
7
|
import { Subscribe, useSubscribedState } from "@player-ui/react-subscribe";
|
|
8
8
|
import { Registry } from "@player-ui/partial-match-registry";
|
|
9
9
|
import { Player } from "@player-ui/player";
|
|
10
|
-
import { ErrorBoundary } from "react-error-boundary";
|
|
10
|
+
import { ErrorBoundary as ErrorBoundary2 } from "react-error-boundary";
|
|
11
11
|
|
|
12
12
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx
|
|
13
13
|
import React from "react";
|
|
14
14
|
import leven from "leven";
|
|
15
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
16
|
+
|
|
17
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/AssetRenderError.ts
|
|
18
|
+
var AssetRenderError = class extends Error {
|
|
19
|
+
constructor(rootAsset, message, innerException) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.rootAsset = rootAsset;
|
|
22
|
+
this.innerException = innerException;
|
|
23
|
+
this.assetParentPath = [];
|
|
24
|
+
this.initialMessage = message ?? "";
|
|
25
|
+
this.innerExceptionMessage = innerException instanceof Error ? innerException.message : String(innerException);
|
|
26
|
+
if (this.innerExceptionMessage) {
|
|
27
|
+
this.initialMessage = this.initialMessage.concat(
|
|
28
|
+
"\nCaused by: ",
|
|
29
|
+
this.innerExceptionMessage
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
this.message = this.initialMessage;
|
|
33
|
+
}
|
|
34
|
+
updateMessage() {
|
|
35
|
+
this.message = `${this.initialMessage}
|
|
36
|
+
${this.getAssetPathMessage()}
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
getAssetPathMessage() {
|
|
40
|
+
return `Exception occurred in asset with id '${this.rootAsset.id}' of type '${this.rootAsset.type}'${this.assetParentPath.map((c) => `
|
|
41
|
+
Found in (id: '${c.id}', type: '${c.type}')`)}`;
|
|
42
|
+
}
|
|
43
|
+
addAssetParent(asset) {
|
|
44
|
+
this.assetParentPath.push(asset);
|
|
45
|
+
this.updateMessage();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx
|
|
15
50
|
var AssetContext = React.createContext({});
|
|
51
|
+
var isAssetUnwrapped = (props) => {
|
|
52
|
+
return "type" in props && "id" in props;
|
|
53
|
+
};
|
|
16
54
|
var ReactAsset = (props) => {
|
|
17
55
|
const { registry } = React.useContext(AssetContext);
|
|
18
56
|
let unwrapped;
|
|
19
|
-
if (
|
|
57
|
+
if (isAssetUnwrapped(props)) {
|
|
20
58
|
unwrapped = props;
|
|
21
59
|
} else if ("asset" in props) {
|
|
22
60
|
unwrapped = props.asset;
|
|
@@ -71,7 +109,25 @@ var ReactAsset = (props) => {
|
|
|
71
109
|
${JSON.stringify(matchList)}`
|
|
72
110
|
);
|
|
73
111
|
}
|
|
74
|
-
return /* @__PURE__ */ React.createElement(
|
|
112
|
+
return /* @__PURE__ */ React.createElement(
|
|
113
|
+
ErrorBoundary,
|
|
114
|
+
{
|
|
115
|
+
fallbackRender: (props2) => {
|
|
116
|
+
const { error } = props2;
|
|
117
|
+
if (error instanceof AssetRenderError) {
|
|
118
|
+
error.addAssetParent(unwrapped);
|
|
119
|
+
throw error;
|
|
120
|
+
} else {
|
|
121
|
+
throw new AssetRenderError(
|
|
122
|
+
unwrapped,
|
|
123
|
+
"Failed to render asset",
|
|
124
|
+
error
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
/* @__PURE__ */ React.createElement(Impl, { key: unwrapped.id, ...unwrapped })
|
|
130
|
+
);
|
|
75
131
|
};
|
|
76
132
|
|
|
77
133
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/player-context.ts
|
|
@@ -268,7 +324,7 @@ var ReactPlayer2 = class {
|
|
|
268
324
|
const BaseComp = this.hooks.webComponent.call(this.createReactComp());
|
|
269
325
|
const ReactPlayerComponent = (props) => {
|
|
270
326
|
return /* @__PURE__ */ React4.createElement(
|
|
271
|
-
|
|
327
|
+
ErrorBoundary2,
|
|
272
328
|
{
|
|
273
329
|
fallbackRender: () => null,
|
|
274
330
|
onError: (err) => {
|
|
@@ -668,6 +724,7 @@ var ManagedPlayer = (props) => {
|
|
|
668
724
|
};
|
|
669
725
|
export {
|
|
670
726
|
AssetContext,
|
|
727
|
+
AssetRenderError,
|
|
671
728
|
ManagedPlayer,
|
|
672
729
|
PlayerContext,
|
|
673
730
|
ReactAsset,
|
package/dist/index.mjs
CHANGED
|
@@ -7,16 +7,54 @@ import { SyncWaterfallHook, AsyncParallelHook } from "tapable-ts";
|
|
|
7
7
|
import { Subscribe, useSubscribedState } from "@player-ui/react-subscribe";
|
|
8
8
|
import { Registry } from "@player-ui/partial-match-registry";
|
|
9
9
|
import { Player } from "@player-ui/player";
|
|
10
|
-
import { ErrorBoundary } from "react-error-boundary";
|
|
10
|
+
import { ErrorBoundary as ErrorBoundary2 } from "react-error-boundary";
|
|
11
11
|
|
|
12
12
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx
|
|
13
13
|
import React from "react";
|
|
14
14
|
import leven from "leven";
|
|
15
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
16
|
+
|
|
17
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/AssetRenderError.ts
|
|
18
|
+
var AssetRenderError = class extends Error {
|
|
19
|
+
constructor(rootAsset, message, innerException) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.rootAsset = rootAsset;
|
|
22
|
+
this.innerException = innerException;
|
|
23
|
+
this.assetParentPath = [];
|
|
24
|
+
this.initialMessage = message ?? "";
|
|
25
|
+
this.innerExceptionMessage = innerException instanceof Error ? innerException.message : String(innerException);
|
|
26
|
+
if (this.innerExceptionMessage) {
|
|
27
|
+
this.initialMessage = this.initialMessage.concat(
|
|
28
|
+
"\nCaused by: ",
|
|
29
|
+
this.innerExceptionMessage
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
this.message = this.initialMessage;
|
|
33
|
+
}
|
|
34
|
+
updateMessage() {
|
|
35
|
+
this.message = `${this.initialMessage}
|
|
36
|
+
${this.getAssetPathMessage()}
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
getAssetPathMessage() {
|
|
40
|
+
return `Exception occurred in asset with id '${this.rootAsset.id}' of type '${this.rootAsset.type}'${this.assetParentPath.map((c) => `
|
|
41
|
+
Found in (id: '${c.id}', type: '${c.type}')`)}`;
|
|
42
|
+
}
|
|
43
|
+
addAssetParent(asset) {
|
|
44
|
+
this.assetParentPath.push(asset);
|
|
45
|
+
this.updateMessage();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx
|
|
15
50
|
var AssetContext = React.createContext({});
|
|
51
|
+
var isAssetUnwrapped = (props) => {
|
|
52
|
+
return "type" in props && "id" in props;
|
|
53
|
+
};
|
|
16
54
|
var ReactAsset = (props) => {
|
|
17
55
|
const { registry } = React.useContext(AssetContext);
|
|
18
56
|
let unwrapped;
|
|
19
|
-
if (
|
|
57
|
+
if (isAssetUnwrapped(props)) {
|
|
20
58
|
unwrapped = props;
|
|
21
59
|
} else if ("asset" in props) {
|
|
22
60
|
unwrapped = props.asset;
|
|
@@ -71,7 +109,25 @@ var ReactAsset = (props) => {
|
|
|
71
109
|
${JSON.stringify(matchList)}`
|
|
72
110
|
);
|
|
73
111
|
}
|
|
74
|
-
return /* @__PURE__ */ React.createElement(
|
|
112
|
+
return /* @__PURE__ */ React.createElement(
|
|
113
|
+
ErrorBoundary,
|
|
114
|
+
{
|
|
115
|
+
fallbackRender: (props2) => {
|
|
116
|
+
const { error } = props2;
|
|
117
|
+
if (error instanceof AssetRenderError) {
|
|
118
|
+
error.addAssetParent(unwrapped);
|
|
119
|
+
throw error;
|
|
120
|
+
} else {
|
|
121
|
+
throw new AssetRenderError(
|
|
122
|
+
unwrapped,
|
|
123
|
+
"Failed to render asset",
|
|
124
|
+
error
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
/* @__PURE__ */ React.createElement(Impl, { key: unwrapped.id, ...unwrapped })
|
|
130
|
+
);
|
|
75
131
|
};
|
|
76
132
|
|
|
77
133
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/player-context.ts
|
|
@@ -268,7 +324,7 @@ var ReactPlayer2 = class {
|
|
|
268
324
|
const BaseComp = this.hooks.webComponent.call(this.createReactComp());
|
|
269
325
|
const ReactPlayerComponent = (props) => {
|
|
270
326
|
return /* @__PURE__ */ React4.createElement(
|
|
271
|
-
|
|
327
|
+
ErrorBoundary2,
|
|
272
328
|
{
|
|
273
329
|
fallbackRender: () => null,
|
|
274
330
|
onError: (err) => {
|
|
@@ -668,6 +724,7 @@ var ManagedPlayer = (props) => {
|
|
|
668
724
|
};
|
|
669
725
|
export {
|
|
670
726
|
AssetContext,
|
|
727
|
+
AssetRenderError,
|
|
671
728
|
ManagedPlayer,
|
|
672
729
|
PlayerContext,
|
|
673
730
|
ReactAsset,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/player-context.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-logger.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/use-asset-props.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/helpers.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/url.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/utils/shared-constants.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/app.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/onupdate-plugin.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/hooks.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/plugins/tapstate-plugin.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/managed-player.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/manager/request-time.tsx"],"sourcesContent":["export * from \"@player-ui/player\";\nexport * from \"./player\";\nexport * from \"./hooks\";\nexport * from \"./manager/managed-player\";\nexport * from \"./manager/request-time\";\nexport * from \"./manager/types\";\nexport * from \"./asset\";\nexport * from \"./utils\";\n","import React from \"react\";\nimport { SyncWaterfallHook, AsyncParallelHook } from \"tapable-ts\";\nimport { Subscribe, useSubscribedState } from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n Flow,\n View,\n PlayerInfo,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport { ReactPlayer as PlayerComp } from \"./app\";\nimport { OnUpdatePlugin } from \"./plugins/onupdate-plugin\";\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 = Record<string, unknown>;\n\n/** A Player that renders UI through React */\nexport class ReactPlayer {\n public readonly options: ReactPlayerOptions;\n public readonly player: Player;\n public readonly assetRegistry: AssetRegistryType = new Registry();\n public readonly Component: React.ComponentType<ReactPlayerComponentProps>;\n public readonly hooks: {\n /**\n * A hook to create a React Component to be used for Player, regardless of the current flow state\n */\n webComponent: SyncWaterfallHook<[React.ComponentType], Record<string, any>>;\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 = new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n this.options = options ?? {};\n\n const Devtools = _window?.__PLAYER_DEVTOOLS_PLUGIN;\n const onUpdatePlugin = new OnUpdatePlugin(\n this.viewUpdateSubscription.publish,\n );\n\n const plugins = options?.plugins ?? [];\n\n if (Devtools) {\n plugins.push(new Devtools());\n }\n\n const playerPlugins = plugins.filter((p) =>\n Boolean(p.apply),\n ) as PlayerPlugin[];\n\n this.player = options?.player ?? new Player({ plugins: playerPlugins });\n\n plugins.forEach((plugin) => {\n if (plugin.applyReact) {\n plugin.applyReact(this);\n }\n });\n\n onUpdatePlugin.apply(this.player);\n\n this.Component = this.createReactPlayerComponent();\n this.reactPlayerInfo = {\n version: this.player.getVersion(),\n commit: this.player.getCommit(),\n };\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): void {\n if (!plugin.applyReact) return;\n\n plugin.applyReact(this);\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 return (\n <ErrorBoundary\n fallbackRender={() => null}\n onError={(err) => {\n const playerState = this.player.getState();\n\n if (playerState.status === \"in-progress\") {\n playerState.fail(err);\n }\n }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...props} />\n </PlayerContext.Provider>\n </ErrorBoundary>\n );\n };\n\n return ReactPlayerComponent;\n }\n\n private createReactComp(): React.ComponentType<ReactPlayerComponentProps> {\n const ActualPlayerComp = this.hooks.playerComponent.call(PlayerComp);\n\n /** the component to use to render the player */\n const WebPlayerComponent = () => {\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n this.viewUpdateSubscription.suspend();\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {view && <ActualPlayerComp view={view} />}\n </AssetContext.Provider>\n );\n };\n\n return WebPlayerComponent;\n }\n\n /**\n * Call this method to force the ReactPlayer to wait for the next view-update before performing the next render.\n * If the `suspense` option is set, this will suspend while an update is pending, otherwise nothing will be rendered.\n */\n public setWaitForNextViewUpdate(): 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\";\n\nexport type AssetRegistryType = Registry<React.ComponentType<any>>;\n\nexport interface ContextType {\n /**\n * A registry of Asset -> React Components\n */\n registry?: AssetRegistryType;\n}\n\nexport const AssetContext = React.createContext<ContextType>({});\n\n/**\n * A React Component that looks up an implementation from a registry\n */\nexport const ReactAsset = (\n props: AssetType<string> | AssetWrapper<AssetType<string>>,\n) => {\n const { registry } = React.useContext(AssetContext);\n\n let unwrapped;\n\n if (\"type\" in props && \"id\" in props) {\n unwrapped = props;\n } else if (\"asset\" in props) {\n unwrapped = (props as unknown as AssetWrapper).asset;\n }\n\n if (!unwrapped) {\n throw Error(\n `Cannot determine asset type for props: ${JSON.stringify(props)}`,\n );\n }\n\n if (typeof unwrapped !== \"object\") {\n throw Error(\n `Asset was not an object got (${typeof unwrapped}) instead: ${unwrapped}`,\n );\n }\n\n if (unwrapped.type === undefined) {\n const info =\n unwrapped.id === undefined\n ? JSON.stringify(props)\n : `id: ${unwrapped.id}`;\n throw Error(`Asset is missing type for ${info}`);\n }\n\n if (!registry || registry.isRegistryEmpty()) {\n throw Error(`No asset found in registry. This could happen for one of the following reasons: \\n\n 1. You might have no assets registered or no plugins added to the Player instance. \\n\n 2. You might have mismatching versions of React Asset Registry Context. \\n\n See https://player-ui.github.io/latest/tools/cli#player-dependency-versions-check for tips about how to debug and fix this problem`);\n }\n\n const Impl = registry?.get(unwrapped);\n\n if (!Impl) {\n const matchList: object[] = [];\n\n registry.forEach((asset) => {\n matchList.push(asset.key);\n });\n\n const typeList = matchList.map(\n (match) => JSON.parse(JSON.stringify(match)).type,\n );\n\n const similarType = typeList.reduce((prev, curr) => {\n const next = {\n value: leven(unwrapped.type, curr),\n type: curr,\n };\n\n if (prev !== undefined && prev.value < next.value) {\n return prev;\n }\n\n return next;\n }, undefined);\n\n throw Error(\n `No implementation found for id: ${unwrapped.id} type: ${unwrapped.type}. Did you mean ${similarType.type}? \\n \n Registered Asset matching functions are listed below: \\n\n ${JSON.stringify(matchList)}`,\n );\n }\n\n return <Impl key={unwrapped.id} {...unwrapped} />;\n};\n","import React from \"react\";\nimport type { Player, NavigationFlowViewState } from \"@player-ui/player\";\n\nexport interface PlayerContextType {\n /**\n * An instance of a headless player\n */\n player?: Player;\n\n /** The currently rendered view state */\n viewState?: NavigationFlowViewState;\n}\n\nexport const PlayerContext = React.createContext<PlayerContextType>({});\n\n/**\n * A hook to get the current player\n */\nexport const usePlayer = () => {\n const { player } = React.useContext(PlayerContext);\n\n return player;\n};\n","import type { Logger } from \"@player-ui/player\";\nimport { NoopLogger } from \"@player-ui/player\";\nimport { usePlayer } from \"./player-context\";\n\nconst noopLogger = new NoopLogger();\n\n/**\n * A hook to get the logger instance from the current player\n */\nexport function useLogger(): Logger {\n const player = usePlayer();\n\n return player?.logger ?? noopLogger;\n}\n","import type { Asset } from \"@player-ui/player\";\n\n/** Common props for any dom node */\nexport function useAssetProps(asset: Asset) {\n return {\n id: asset.id,\n \"data-asset-type\": asset.type,\n };\n}\n","/**\n * Trim leading and trailing slashes from string\n */\nexport function trimSlashes(str: string) {\n return str.replace(/^\\/+|\\/+$/g, \"\");\n}\n\n/**\n * Removes any key: value pairs from an object when the value is null or undefined\n */\nexport function removeEmptyValuesFromObject(\n obj: Record<string, any>,\n): Record<string, NonNullable<any>> {\n return Object.keys(obj).reduce(\n (acc, key) => {\n const value = obj[key];\n\n if (value !== null && value !== undefined) {\n acc[key] = value;\n }\n\n return acc;\n },\n {} as Record<string, any>,\n );\n}\n\n/** Check if the object has no keys */\nexport function isEmptyObject(obj: Record<string, unknown>) {\n return Object.keys(obj).length === 0 && obj.constructor === Object;\n}\n\n/** Check if the argument is a function */\nexport function isFunction<ReturnType>(\n maybeFn: ReturnType | ((...args: unknown[]) => ReturnType),\n): maybeFn is (...args: unknown[]) => ReturnType {\n return Boolean(maybeFn instanceof Function || typeof maybeFn === \"function\");\n}\n\n/**\n * Calls function with provided data or returns original value\n */\nexport function callOrReturn<\n ReturnType,\n FnArgs extends Array<unknown> = unknown[],\n FnType = (...args: FnArgs) => ReturnType,\n>(maybeFn: FnType | ReturnType, fnArgs: FnArgs): ReturnType {\n if (isFunction(maybeFn)) {\n return maybeFn(fnArgs) as ReturnType;\n }\n\n return maybeFn as ReturnType;\n}\n","import { isEmptyObject } from \"./helpers\";\n\n/**\n * Combines a URL with any additional parameters\n */\nexport function buildUrl(\n url: string,\n params: Record<string, unknown> = {},\n): string {\n const baseUrl = new URL(url);\n\n if (params && isEmptyObject(params)) {\n return baseUrl.toString();\n }\n\n Object.keys(params).forEach((key) => {\n const value = params[key];\n baseUrl.searchParams.append(key, String(value));\n });\n\n return baseUrl.toString();\n}\n","import { usePlayer } from \"./player-context\";\n\n/** Hook to get a constant under a specific namespace */\nexport function useGetConstantByType(type: string, key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, type);\n}\n\n/** Get a constant under the default namespace */\nexport function useGetConstant(key: string): unknown {\n const player = usePlayer();\n\n return player?.constantsController.getConstants(key, \"constants\");\n}\n","import React from \"react\";\nimport type { View } from \"@player-ui/player\";\nimport { ReactAsset } from \"./asset\";\n\nexport interface ReactPlayerProps {\n /**\n * The Content view object to render\n */\n view: View;\n}\n\n/**\n * The entry for the ReactPlayer's React tree\n */\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?.(\n playerState.controllers.data.serialize(),\n );\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?.();\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.controllers.data.serialize());\n }\n };\n }, [props.manager, state?.context.reactPlayer.player, state?.value]);\n\n if (state?.value === \"error\") {\n if (props.fallbackComponent) {\n return (\n <props.fallbackComponent\n reset={() => {\n managedState.reset();\n }}\n retry={() => {\n managedState.restart();\n }}\n error={state.context.error}\n />\n );\n }\n\n if (!props.onError) {\n throw state.context.error;\n }\n }\n\n if (state?.context.reactPlayer) {\n const { Component } = state.context.reactPlayer;\n\n return <Component />;\n }\n\n return null;\n};\n","import { useCallback, useEffect, useRef, useMemo } from \"react\";\nimport type { Player } from \"@player-ui/player\";\nimport type { MetricsCorePlugin } from \"@player-ui/metrics-plugin\";\nimport {\n MetricsCorePluginSymbol,\n RequestTimeWebPlugin,\n} from \"@player-ui/metrics-plugin\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\ntype RequestTime = {\n /** request start time */\n start?: number;\n /** request end time */\n end?: number;\n};\n\n/** hook to time a promise and add it to the metrics plugin */\nexport const useRequestTime = () => {\n const requestTimeRef = useRef<RequestTime>({});\n\n useEffect(() => {\n return () => {\n requestTimeRef.current = {};\n };\n }, [requestTimeRef]);\n\n const getRequestTime = useCallback(() => {\n const { end, start } = requestTimeRef.current;\n\n if (end && start) {\n return end - start;\n }\n }, [requestTimeRef]);\n\n /** wrap a promise with tracking it's time in flight */\n function withRequestTime<Type>(nextPromise: Promise<Type>): Promise<Type> {\n const getTime = typeof performance === \"undefined\" ? Date : performance;\n requestTimeRef.current = { start: getTime.now() };\n\n return nextPromise.finally(() => {\n requestTimeRef.current = {\n ...requestTimeRef.current,\n end: getTime.now(),\n };\n });\n }\n\n const RequestTimeMetricsPlugin: ReactPlayerPlugin = useMemo(() => {\n return {\n name: \"RequestTimeMetricsPlugin\",\n apply(player: Player): void {\n player.applyTo<MetricsCorePlugin>(\n MetricsCorePluginSymbol,\n (metricsCorePlugin) => {\n new RequestTimeWebPlugin(getRequestTime).apply(metricsCorePlugin);\n },\n );\n },\n };\n }, [getRequestTime]);\n\n return { withRequestTime, RequestTimeMetricsPlugin };\n};\n"],"mappings":";AAAA,cAAc;;;ACAd,OAAOA,YAAW;AAClB,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,WAAW,0BAA0B;AAC9C,SAAS,gBAAgB;AAQzB,SAAS,cAAc;AACvB,SAAS,qBAAqB;;;ACZ9B,OAAO,WAAW;AAClB,OAAO,WAAW;AAaX,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,YAAY,OAAO,SAAS;AAE/D,UAAI,OAAO,UAAU,aAAa,aAAa,WAAW,eAAe;AACvE,cAAM,QAAQ,YAAY,YAAY,YAAY,KAAK,UAAU,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,SAAS,OAAO,QAAQ,YAAY,QAAQ,OAAO,KAAK,CAAC;AAEnE,MAAI,OAAO,UAAU,SAAS;AAC5B,QAAI,MAAM,mBAAmB;AAC3B,aACE,gBAAAA,OAAA;AAAA,QAAC,MAAM;AAAA,QAAN;AAAA,UACC,OAAO,MAAM;AACX,yBAAa,MAAM;AAAA,UACrB;AAAA,UACA,OAAO,MAAM;AACX,yBAAa,QAAQ;AAAA,UACvB;AAAA,UACA,OAAO,MAAM,QAAQ;AAAA;AAAA,MACvB;AAAA,IAEJ;AAEA,QAAI,CAAC,MAAM,SAAS;AAClB,YAAM,MAAM,QAAQ;AAAA,IACtB;AAAA,EACF;AAEA,MAAI,OAAO,QAAQ,aAAa;AAC9B,UAAM,EAAE,UAAU,IAAI,MAAM,QAAQ;AAEpC,WAAO,gBAAAA,OAAA,cAAC,eAAU;AAAA,EACpB;AAEA,SAAO;AACT;","names":["React","React","React","React","ReactPlayer","React","React","React","ReactPlayer","React","ReactPlayer","React"]}
|
|
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 { Subscribe, useSubscribedState } from \"@player-ui/react-subscribe\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport type {\n CompletedState,\n PlayerPlugin,\n Flow,\n View,\n PlayerInfo,\n} from \"@player-ui/player\";\nimport { Player } from \"@player-ui/player\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport type { AssetRegistryType } from \"./asset\";\nimport { AssetContext } from \"./asset\";\nimport { PlayerContext } from \"./utils\";\n\nimport type { ReactPlayerProps } from \"./app\";\nimport { ReactPlayer as PlayerComp } from \"./app\";\nimport { OnUpdatePlugin } from \"./plugins/onupdate-plugin\";\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 = Record<string, unknown>;\n\n/** A Player that renders UI through React */\nexport class ReactPlayer {\n public readonly options: ReactPlayerOptions;\n public readonly player: Player;\n public readonly assetRegistry: AssetRegistryType = new Registry();\n public readonly Component: React.ComponentType<ReactPlayerComponentProps>;\n public readonly hooks: {\n /**\n * A hook to create a React Component to be used for Player, regardless of the current flow state\n */\n webComponent: SyncWaterfallHook<[React.ComponentType], Record<string, any>>;\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 = new Subscribe<View>();\n private reactPlayerInfo: ReactPlayerInfo;\n\n constructor(options?: ReactPlayerOptions) {\n this.options = options ?? {};\n\n const Devtools = _window?.__PLAYER_DEVTOOLS_PLUGIN;\n const onUpdatePlugin = new OnUpdatePlugin(\n this.viewUpdateSubscription.publish,\n );\n\n const plugins = options?.plugins ?? [];\n\n if (Devtools) {\n plugins.push(new Devtools());\n }\n\n const playerPlugins = plugins.filter((p) =>\n Boolean(p.apply),\n ) as PlayerPlugin[];\n\n this.player = options?.player ?? new Player({ plugins: playerPlugins });\n\n plugins.forEach((plugin) => {\n if (plugin.applyReact) {\n plugin.applyReact(this);\n }\n });\n\n onUpdatePlugin.apply(this.player);\n\n this.Component = this.createReactPlayerComponent();\n this.reactPlayerInfo = {\n version: this.player.getVersion(),\n commit: this.player.getCommit(),\n };\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): void {\n if (!plugin.applyReact) return;\n\n plugin.applyReact(this);\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 return (\n <ErrorBoundary\n fallbackRender={() => null}\n onError={(err) => {\n const playerState = this.player.getState();\n\n if (playerState.status === \"in-progress\") {\n playerState.fail(err);\n }\n }}\n >\n <PlayerContext.Provider value={{ player: this.player }}>\n <BaseComp {...props} />\n </PlayerContext.Provider>\n </ErrorBoundary>\n );\n };\n\n return ReactPlayerComponent;\n }\n\n private createReactComp(): React.ComponentType<ReactPlayerComponentProps> {\n const ActualPlayerComp = this.hooks.playerComponent.call(PlayerComp);\n\n /** the component to use to render the player */\n const WebPlayerComponent = () => {\n const view = useSubscribedState<View>(this.viewUpdateSubscription);\n this.viewUpdateSubscription.suspend();\n\n return (\n <AssetContext.Provider\n value={{\n registry: this.assetRegistry,\n }}\n >\n {view && <ActualPlayerComp view={view} />}\n </AssetContext.Provider>\n );\n };\n\n return WebPlayerComponent;\n }\n\n /**\n * Call this method to force the ReactPlayer to wait for the next view-update before performing the next render.\n * If the `suspense` option is set, this will suspend while an update is pending, otherwise nothing will be rendered.\n */\n public setWaitForNextViewUpdate(): 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 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 }}\n >\n <Impl key={unwrapped.id} {...unwrapped} />\n </ErrorBoundary>\n );\n};\n","import type { Asset } from \"@player-ui/player\";\n\nexport class AssetRenderError extends Error {\n private assetParentPath: Array<Asset> = [];\n initialMessage: string;\n innerExceptionMessage: string;\n\n constructor(\n readonly rootAsset: Asset,\n message?: string,\n readonly innerException?: unknown,\n ) {\n super(message);\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?.(\n playerState.controllers.data.serialize(),\n );\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?.();\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.controllers.data.serialize());\n }\n };\n }, [props.manager, state?.context.reactPlayer.player, state?.value]);\n\n if (state?.value === \"error\") {\n if (props.fallbackComponent) {\n return (\n <props.fallbackComponent\n reset={() => {\n managedState.reset();\n }}\n retry={() => {\n managedState.restart();\n }}\n error={state.context.error}\n />\n );\n }\n\n if (!props.onError) {\n throw state.context.error;\n }\n }\n\n if (state?.context.reactPlayer) {\n const { Component } = state.context.reactPlayer;\n\n return <Component />;\n }\n\n return null;\n};\n","import { useCallback, useEffect, useRef, useMemo } from \"react\";\nimport type { Player } from \"@player-ui/player\";\nimport type { MetricsCorePlugin } from \"@player-ui/metrics-plugin\";\nimport {\n MetricsCorePluginSymbol,\n RequestTimeWebPlugin,\n} from \"@player-ui/metrics-plugin\";\nimport type { ReactPlayerPlugin } from \"../player\";\n\ntype RequestTime = {\n /** request start time */\n start?: number;\n /** request end time */\n end?: number;\n};\n\n/** hook to time a promise and add it to the metrics plugin */\nexport const useRequestTime = () => {\n const requestTimeRef = useRef<RequestTime>({});\n\n useEffect(() => {\n return () => {\n requestTimeRef.current = {};\n };\n }, [requestTimeRef]);\n\n const getRequestTime = useCallback(() => {\n const { end, start } = requestTimeRef.current;\n\n if (end && start) {\n return end - start;\n }\n }, [requestTimeRef]);\n\n /** wrap a promise with tracking it's time in flight */\n function withRequestTime<Type>(nextPromise: Promise<Type>): Promise<Type> {\n const getTime = typeof performance === \"undefined\" ? Date : performance;\n requestTimeRef.current = { start: getTime.now() };\n\n return nextPromise.finally(() => {\n requestTimeRef.current = {\n ...requestTimeRef.current,\n end: getTime.now(),\n };\n });\n }\n\n const RequestTimeMetricsPlugin: ReactPlayerPlugin = useMemo(() => {\n return {\n name: \"RequestTimeMetricsPlugin\",\n apply(player: Player): void {\n player.applyTo<MetricsCorePlugin>(\n MetricsCorePluginSymbol,\n (metricsCorePlugin) => {\n new RequestTimeWebPlugin(getRequestTime).apply(metricsCorePlugin);\n },\n );\n },\n };\n }, [getRequestTime]);\n\n return { withRequestTime, RequestTimeMetricsPlugin };\n};\n"],"mappings":";AAAA,cAAc;;;ACAd,OAAOA,YAAW;AAClB,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,WAAW,0BAA0B;AAC9C,SAAS,gBAAgB;AAQzB,SAAS,cAAc;AACvB,SAAS,iBAAAC,sBAAqB;;;ACZ9B,OAAO,WAAW;AAClB,OAAO,WAAW;AAGlB,SAAS,qBAAqB;;;ACFvB,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAK1C,YACW,WACT,SACS,gBACT;AACA,UAAM,OAAO;AAJJ;AAEA;AAPX,SAAQ,kBAAgC,CAAC;AAUvC,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,kBAAsB,EAAE,EAAE,aAAa,EAAE,IAAI,IAAI,CAAC;AAAA,EACzL;AAAA,EAEA,eAAe,OAAoB;AACjC,SAAK,gBAAgB,KAAK,KAAK;AAC/B,SAAK,cAAc;AAAA,EACr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M,OAAuC;AAEnE,MAAI,OAAO,UAAU,cAAc,SAAS,OAAO;AACjD,QAAI,OAAO,UAAU,SAAS;AAC5B,YAAM,aAAa,OAAO,QAAQ,MAAM;AAAA,IAC1C,WAAW,OAAO,UAAU,SAAS;AACnC,YAAM,UAAU,OAAO,QAAQ,KAAK;AAAA,IACtC,WAAW,OAAO,UAAU,WAAW;AACrC,YAAM,gBAAgB;AAAA,IACxB;AAAA,EACF;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,YAAY,YAAY,KAAK,UAAU,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,SAAS,OAAO,QAAQ,YAAY,QAAQ,OAAO,KAAK,CAAC;AAEnE,MAAI,OAAO,UAAU,SAAS;AAC5B,QAAI,MAAM,mBAAmB;AAC3B,aACE,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","ReactPlayer","React","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": "0.15.0-next.
|
|
9
|
+
"version": "0.15.0-next.4",
|
|
10
10
|
"main": "dist/cjs/index.cjs",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@player-ui/metrics-plugin": "0.15.0-next.
|
|
13
|
-
"@player-ui/partial-match-registry": "0.15.0-next.
|
|
14
|
-
"@player-ui/player": "0.15.0-next.
|
|
15
|
-
"@player-ui/react-subscribe": "0.15.0-next.
|
|
12
|
+
"@player-ui/metrics-plugin": "0.15.0-next.4",
|
|
13
|
+
"@player-ui/partial-match-registry": "0.15.0-next.4",
|
|
14
|
+
"@player-ui/player": "0.15.0-next.4",
|
|
15
|
+
"@player-ui/react-subscribe": "0.15.0-next.4",
|
|
16
16
|
"react-error-boundary": "^3.1.3",
|
|
17
17
|
"tapable-ts": "^0.2.3",
|
|
18
18
|
"leven": "3.1.0",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Asset } from "@player-ui/player";
|
|
2
|
+
|
|
3
|
+
export class AssetRenderError extends Error {
|
|
4
|
+
private assetParentPath: Array<Asset> = [];
|
|
5
|
+
initialMessage: string;
|
|
6
|
+
innerExceptionMessage: string;
|
|
7
|
+
|
|
8
|
+
constructor(
|
|
9
|
+
readonly rootAsset: Asset,
|
|
10
|
+
message?: string,
|
|
11
|
+
readonly innerException?: unknown,
|
|
12
|
+
) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.initialMessage = message ?? "";
|
|
15
|
+
this.innerExceptionMessage =
|
|
16
|
+
innerException instanceof Error
|
|
17
|
+
? innerException.message
|
|
18
|
+
: String(innerException);
|
|
19
|
+
|
|
20
|
+
if (this.innerExceptionMessage) {
|
|
21
|
+
this.initialMessage = this.initialMessage.concat(
|
|
22
|
+
"\nCaused by: ",
|
|
23
|
+
this.innerExceptionMessage,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this.message = this.initialMessage;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private updateMessage() {
|
|
31
|
+
this.message = `${this.initialMessage}
|
|
32
|
+
${this.getAssetPathMessage()}
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getAssetPathMessage() {
|
|
37
|
+
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}')`)}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
addAssetParent(asset: Asset): void {
|
|
41
|
+
this.assetParentPath.push(asset);
|
|
42
|
+
this.updateMessage();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { vi, bench, describe, expect } from "vitest";
|
|
3
|
+
import { AssetContext, AssetRegistryType, ReactAsset } from "..";
|
|
4
|
+
import type { Asset, AssetWrapper } from "@player-ui/player";
|
|
5
|
+
import { Registry } from "@player-ui/partial-match-registry";
|
|
6
|
+
import { render, cleanup } from "@testing-library/react";
|
|
7
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
8
|
+
|
|
9
|
+
type FooProps = Asset<"foo"> & {
|
|
10
|
+
nested: AssetWrapper;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type BarProps = Asset<"bar">;
|
|
14
|
+
|
|
15
|
+
type BrokeProps = Asset<"broke">;
|
|
16
|
+
|
|
17
|
+
const registry: AssetRegistryType = new Registry<React.ComponentType<any>>([
|
|
18
|
+
[
|
|
19
|
+
{ type: "foo" },
|
|
20
|
+
({ nested }: FooProps) => <ReactAsset asset={nested.asset} />,
|
|
21
|
+
],
|
|
22
|
+
[{ type: "bar" }, ({ id }: BarProps) => <div data-testid={id} />],
|
|
23
|
+
[
|
|
24
|
+
{ type: "broke" },
|
|
25
|
+
({ id }: BrokeProps) => {
|
|
26
|
+
throw new Error(`Thrown by ${id}`);
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const createWithDepth = (depth: number, finalAssetType = "bar"): Asset => {
|
|
32
|
+
const root: Asset = {
|
|
33
|
+
type: finalAssetType,
|
|
34
|
+
id: "1",
|
|
35
|
+
};
|
|
36
|
+
let current: Asset = root;
|
|
37
|
+
|
|
38
|
+
for (let i = depth; i > 1; i--) {
|
|
39
|
+
current.type = "foo";
|
|
40
|
+
current.id = String(i);
|
|
41
|
+
const next: Asset = {
|
|
42
|
+
type: finalAssetType,
|
|
43
|
+
id: "1",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
current.nested = { asset: next };
|
|
47
|
+
current = next;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return root;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Bench tests for rendering ReactAssets. Used to measure overhead this component is adding to the underlying assets that need to render.
|
|
54
|
+
describe("ReactAsset benchmarks", () => {
|
|
55
|
+
const depths = [1, 5, 10, 50, 100];
|
|
56
|
+
|
|
57
|
+
depths.forEach((depth) => {
|
|
58
|
+
const asset = createWithDepth(depth);
|
|
59
|
+
|
|
60
|
+
bench(
|
|
61
|
+
`Render asset nested in ${depth} ReactAssets`,
|
|
62
|
+
async () => {
|
|
63
|
+
const { findByTestId } = render(
|
|
64
|
+
<AssetContext.Provider value={{ registry }}>
|
|
65
|
+
<ReactAsset asset={asset} />
|
|
66
|
+
</AssetContext.Provider>,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
await findByTestId("1"); // Wait for render to complete and find the "bar" asset
|
|
70
|
+
cleanup(); // Bench tests do not automatically cleanup after each iteration
|
|
71
|
+
},
|
|
72
|
+
{ iterations: 100, throws: true },
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const brokenAsset = createWithDepth(depth, "broke");
|
|
76
|
+
|
|
77
|
+
bench(
|
|
78
|
+
`Bubble errors nested in ${depth} ReactAssets`,
|
|
79
|
+
async () => {
|
|
80
|
+
let err: Error | undefined;
|
|
81
|
+
render(
|
|
82
|
+
<ErrorBoundary
|
|
83
|
+
onError={(e) => {
|
|
84
|
+
err = e;
|
|
85
|
+
}}
|
|
86
|
+
fallbackRender={() => null}
|
|
87
|
+
>
|
|
88
|
+
<AssetContext.Provider value={{ registry }}>
|
|
89
|
+
<ReactAsset asset={brokenAsset} />
|
|
90
|
+
</AssetContext.Provider>
|
|
91
|
+
</ErrorBoundary>,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
await vi.waitFor(() => {
|
|
95
|
+
expect(err).toBeDefined();
|
|
96
|
+
}); // Wait for error to be thrown
|
|
97
|
+
cleanup(); // Bench tests do not automatically cleanup after each iteration
|
|
98
|
+
},
|
|
99
|
+
{ iterations: 100, throws: true },
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -181,3 +181,38 @@ test("throw an error for no assets in registry", () => {
|
|
|
181
181
|
2. You might have mismatching versions of React Asset Registry Context. \n
|
|
182
182
|
See https://player-ui.github.io/latest/tools/cli#player-dependency-versions-check for tips about how to debug and fix this problem`);
|
|
183
183
|
});
|
|
184
|
+
|
|
185
|
+
test("throws an AssetRenderError if the asset implementation throws an error", () => {
|
|
186
|
+
const assetDef = {
|
|
187
|
+
id: "foo",
|
|
188
|
+
type: "foo",
|
|
189
|
+
asset: {
|
|
190
|
+
id: "bar",
|
|
191
|
+
type: "bar",
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const registry: AssetRegistryType = new Registry([
|
|
196
|
+
[
|
|
197
|
+
{ type: "foo" },
|
|
198
|
+
(props: { asset: AssetType }) => <ReactAsset {...props.asset} />,
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
{ type: "bar" },
|
|
202
|
+
() => {
|
|
203
|
+
throw new Error("a problem");
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
]);
|
|
207
|
+
|
|
208
|
+
expect(() =>
|
|
209
|
+
render(
|
|
210
|
+
<AssetContext.Provider value={{ registry }}>
|
|
211
|
+
<ReactAsset {...assetDef} />
|
|
212
|
+
</AssetContext.Provider>,
|
|
213
|
+
),
|
|
214
|
+
).toThrowError(`Failed to render asset
|
|
215
|
+
Caused by: a problem
|
|
216
|
+
Exception occurred in asset with id 'bar' of type 'bar'
|
|
217
|
+
\tFound in (id: 'foo', type: 'foo')`);
|
|
218
|
+
});
|
package/src/asset/index.tsx
CHANGED
|
@@ -2,6 +2,10 @@ import React from "react";
|
|
|
2
2
|
import leven from "leven";
|
|
3
3
|
import type { Asset as AssetType, AssetWrapper } from "@player-ui/player";
|
|
4
4
|
import type { Registry } from "@player-ui/partial-match-registry";
|
|
5
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
6
|
+
import { AssetRenderError } from "./AssetRenderError";
|
|
7
|
+
|
|
8
|
+
export * from "./AssetRenderError";
|
|
5
9
|
|
|
6
10
|
export type AssetRegistryType = Registry<React.ComponentType<any>>;
|
|
7
11
|
|
|
@@ -12,22 +16,29 @@ export interface ContextType {
|
|
|
12
16
|
registry?: AssetRegistryType;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
export const AssetContext
|
|
19
|
+
export const AssetContext: React.Context<ContextType> =
|
|
20
|
+
React.createContext<ContextType>({});
|
|
21
|
+
|
|
22
|
+
const isAssetUnwrapped = (
|
|
23
|
+
props: AssetType<string> | AssetWrapper<AssetType<string>>,
|
|
24
|
+
): props is AssetType<string> => {
|
|
25
|
+
return "type" in props && "id" in props;
|
|
26
|
+
};
|
|
16
27
|
|
|
17
28
|
/**
|
|
18
29
|
* A React Component that looks up an implementation from a registry
|
|
19
30
|
*/
|
|
20
31
|
export const ReactAsset = (
|
|
21
32
|
props: AssetType<string> | AssetWrapper<AssetType<string>>,
|
|
22
|
-
) => {
|
|
33
|
+
): React.ReactElement => {
|
|
23
34
|
const { registry } = React.useContext(AssetContext);
|
|
24
35
|
|
|
25
|
-
let unwrapped;
|
|
36
|
+
let unwrapped: AssetType<string> | undefined;
|
|
26
37
|
|
|
27
|
-
if (
|
|
38
|
+
if (isAssetUnwrapped(props)) {
|
|
28
39
|
unwrapped = props;
|
|
29
40
|
} else if ("asset" in props) {
|
|
30
|
-
unwrapped =
|
|
41
|
+
unwrapped = props.asset;
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
if (!unwrapped) {
|
|
@@ -90,5 +101,23 @@ export const ReactAsset = (
|
|
|
90
101
|
);
|
|
91
102
|
}
|
|
92
103
|
|
|
93
|
-
return
|
|
104
|
+
return (
|
|
105
|
+
<ErrorBoundary
|
|
106
|
+
fallbackRender={(props) => {
|
|
107
|
+
const { error } = props;
|
|
108
|
+
if (error instanceof AssetRenderError) {
|
|
109
|
+
error.addAssetParent(unwrapped);
|
|
110
|
+
throw error;
|
|
111
|
+
} else {
|
|
112
|
+
throw new AssetRenderError(
|
|
113
|
+
unwrapped,
|
|
114
|
+
"Failed to render asset",
|
|
115
|
+
error,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
<Impl key={unwrapped.id} {...unwrapped} />
|
|
121
|
+
</ErrorBoundary>
|
|
122
|
+
);
|
|
94
123
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Asset } from "@player-ui/player";
|
|
2
|
+
export declare class AssetRenderError extends Error {
|
|
3
|
+
readonly rootAsset: Asset;
|
|
4
|
+
readonly innerException?: unknown | undefined;
|
|
5
|
+
private assetParentPath;
|
|
6
|
+
initialMessage: string;
|
|
7
|
+
innerExceptionMessage: string;
|
|
8
|
+
constructor(rootAsset: Asset, message?: string, innerException?: unknown | undefined);
|
|
9
|
+
private updateMessage;
|
|
10
|
+
getAssetPathMessage(): string;
|
|
11
|
+
addAssetParent(asset: Asset): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=AssetRenderError.d.ts.map
|
package/types/asset/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { Asset as AssetType, AssetWrapper } from "@player-ui/player";
|
|
3
3
|
import type { Registry } from "@player-ui/partial-match-registry";
|
|
4
|
+
export * from "./AssetRenderError";
|
|
4
5
|
export type AssetRegistryType = Registry<React.ComponentType<any>>;
|
|
5
6
|
export interface ContextType {
|
|
6
7
|
/**
|
|
@@ -12,5 +13,5 @@ export declare const AssetContext: React.Context<ContextType>;
|
|
|
12
13
|
/**
|
|
13
14
|
* A React Component that looks up an implementation from a registry
|
|
14
15
|
*/
|
|
15
|
-
export declare const ReactAsset: (props: AssetType<string> | AssetWrapper<AssetType<string>>) => React.
|
|
16
|
+
export declare const ReactAsset: (props: AssetType<string> | AssetWrapper<AssetType<string>>) => React.ReactElement;
|
|
16
17
|
//# sourceMappingURL=index.d.ts.map
|