@player-ui/react 0.15.3 → 0.15.4--canary.881.37421
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 +110 -22
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +111 -17
- package/dist/index.mjs +111 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/player.test.tsx +263 -2
- package/src/asset/AssetRenderError.ts +20 -2
- package/src/asset/__tests__/index.test.tsx +3 -3
- package/src/asset/index.tsx +2 -0
- package/src/manager/__tests__/__snapshots__/managed-player.test.tsx.snap +249 -0
- package/src/manager/__tests__/managed-player.test.tsx +20 -3
- package/src/manager/managed-player.tsx +3 -5
- package/src/manager/types.ts +10 -10
- package/src/player.tsx +152 -19
- package/types/asset/AssetRenderError.d.ts +8 -2
- package/types/manager/types.d.ts +10 -8
- package/types/player.d.ts +13 -7
package/types/manager/types.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
|
-
import type { CompletedState, Flow,
|
|
2
|
+
import type { CompletedState, Flow, InProgressState } from "@player-ui/player";
|
|
3
3
|
import type { ReactPlayer, ReactPlayerOptions } from "../player";
|
|
4
4
|
export interface FinalState {
|
|
5
5
|
/** Mark the iteration as complete */
|
|
6
6
|
done: true;
|
|
7
7
|
}
|
|
8
|
-
export interface NextState
|
|
8
|
+
export interface NextState {
|
|
9
9
|
/** Optional mark the iteration as _not_ completed */
|
|
10
|
-
done
|
|
10
|
+
done: false;
|
|
11
11
|
/** The next value in the iteration */
|
|
12
|
-
value:
|
|
12
|
+
value: Flow;
|
|
13
13
|
}
|
|
14
|
+
/** A JS Iterator that returns a new flow or completion marker
|
|
15
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator */
|
|
14
16
|
export interface FlowManager {
|
|
15
17
|
/**
|
|
16
18
|
* An iterator implementation that takes the result of the previous flow and returns a new one or completion marker.
|
|
@@ -19,12 +21,12 @@ export interface FlowManager {
|
|
|
19
21
|
*
|
|
20
22
|
* @param previousValue - The result of the previous flow.
|
|
21
23
|
*/
|
|
22
|
-
next: (
|
|
24
|
+
next: (result?: CompletedState) => Promise<FinalState | NextState>;
|
|
23
25
|
/**
|
|
24
26
|
* Called when the flow is ended early (the react tree is torn down)
|
|
25
27
|
* Allows clients the opportunity to save-data before destroying the tree
|
|
26
28
|
*/
|
|
27
|
-
terminate?: (
|
|
29
|
+
terminate?: (state?: InProgressState) => void;
|
|
28
30
|
}
|
|
29
31
|
export interface FallbackProps {
|
|
30
32
|
/** A callback to reset the flow iteration from the start */
|
|
@@ -38,7 +40,7 @@ export interface ManagedPlayerProps extends ReactPlayerOptions {
|
|
|
38
40
|
/** The manager for populating the next flows */
|
|
39
41
|
manager: FlowManager;
|
|
40
42
|
/** A callback when a flow is started */
|
|
41
|
-
onStartedFlow?: () => void;
|
|
43
|
+
onStartedFlow?: (flow: Flow) => void;
|
|
42
44
|
/** A callback when the entire async iteration is completed */
|
|
43
45
|
onComplete?: (finalState?: CompletedState) => void;
|
|
44
46
|
/** A callback for any errors */
|
|
@@ -67,7 +69,7 @@ export type ManagedPlayerState = {
|
|
|
67
69
|
/** The previous completed state */
|
|
68
70
|
prevResult?: CompletedState;
|
|
69
71
|
/** A promise from the flow manager for the next state */
|
|
70
|
-
next: Promise<FinalState | NextState
|
|
72
|
+
next: Promise<FinalState | NextState>;
|
|
71
73
|
};
|
|
72
74
|
} | {
|
|
73
75
|
/** A flow was retrieved from the flow manager, but hasn't been processed yet */
|
package/types/player.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { SyncWaterfallHook, AsyncParallelHook } from "tapable-ts";
|
|
3
3
|
import { Subscribe } from "@player-ui/react-subscribe";
|
|
4
|
-
import type { CompletedState, PlayerPlugin, Flow, PlayerInfo } from "@player-ui/player";
|
|
4
|
+
import type { CompletedState, PlayerPlugin, Flow, View, PlayerInfo } from "@player-ui/player";
|
|
5
5
|
import { Player } from "@player-ui/player";
|
|
6
6
|
import type { AssetRegistryType } from "./asset";
|
|
7
7
|
import type { ReactPlayerProps } from "./app";
|
|
8
|
+
/** Backup context for receiving ReactPlayerComponentProps when components setup in the webComponent call don't pass the props down to their inner components. */
|
|
9
|
+
export declare const ReactPlayerPropsContext: React.Context<ReactPlayerComponentProps>;
|
|
8
10
|
export interface DevtoolsGlobals {
|
|
9
11
|
/** A global for a plugin to load to Player for devtools */
|
|
10
12
|
__PLAYER_DEVTOOLS_PLUGIN?: {
|
|
@@ -27,7 +29,11 @@ export interface ReactPlayerOptions {
|
|
|
27
29
|
/** A set of plugins to apply to this player */
|
|
28
30
|
plugins?: Array<ReactPlayerPlugin>;
|
|
29
31
|
}
|
|
30
|
-
export type ReactPlayerComponentProps =
|
|
32
|
+
export type ReactPlayerComponentProps = {
|
|
33
|
+
/** Whether or not player is currently recovering from an error. */
|
|
34
|
+
isInErrorState?: boolean;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
};
|
|
31
37
|
/** A Player that renders UI through React */
|
|
32
38
|
export declare class ReactPlayer {
|
|
33
39
|
readonly options: ReactPlayerOptions;
|
|
@@ -38,7 +44,9 @@ export declare class ReactPlayer {
|
|
|
38
44
|
/**
|
|
39
45
|
* A hook to create a React Component to be used for Player, regardless of the current flow state
|
|
40
46
|
*/
|
|
41
|
-
webComponent: SyncWaterfallHook<[
|
|
47
|
+
webComponent: SyncWaterfallHook<[
|
|
48
|
+
React.ComponentType<any>
|
|
49
|
+
], Record<string, any>>;
|
|
42
50
|
/**
|
|
43
51
|
* A hook to create a React Component that's used to render a specific view.
|
|
44
52
|
* It will be called for each view update from the core player.
|
|
@@ -52,9 +60,7 @@ export declare class ReactPlayer {
|
|
|
52
60
|
*/
|
|
53
61
|
onBeforeViewReset: AsyncParallelHook<[], Record<string, any>>;
|
|
54
62
|
};
|
|
55
|
-
readonly viewUpdateSubscription: Subscribe<
|
|
56
|
-
validation?: Array<import("@player-ui/player").Validation.CrossfieldReference>;
|
|
57
|
-
}>;
|
|
63
|
+
readonly viewUpdateSubscription: Subscribe<View>;
|
|
58
64
|
private reactPlayerInfo;
|
|
59
65
|
constructor(options?: ReactPlayerOptions);
|
|
60
66
|
/** Returns the current version Player */
|
|
@@ -64,7 +70,7 @@ export declare class ReactPlayer {
|
|
|
64
70
|
/** Find instance of [Plugin] that has been registered to the web player */
|
|
65
71
|
findPlugin<Plugin extends ReactPlayerPlugin>(symbol: symbol): Plugin | undefined;
|
|
66
72
|
/** Register and apply [Plugin] if one with the same symbol is not already registered. */
|
|
67
|
-
registerPlugin(plugin: ReactPlayerPlugin): void;
|
|
73
|
+
registerPlugin(plugin: ReactPlayerPlugin | PlayerPlugin): void;
|
|
68
74
|
/**
|
|
69
75
|
* Returns the current version of the running React Player
|
|
70
76
|
* @deprecated use `getPlayerVersion()` instead. Will be removed next major
|