@player-ui/react 0.15.4--canary.881.37421 → 0.15.4--canary.884.37483

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.
@@ -4,11 +4,7 @@ export * from "@player-ui/player";
4
4
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx
5
5
  import React4 from "react";
6
6
  import { SyncWaterfallHook, AsyncParallelHook } from "tapable-ts";
7
- import {
8
- Subscribe,
9
- useSubscribedState,
10
- useSubscriber
11
- } from "@player-ui/react-subscribe";
7
+ import { Subscribe, useSubscribedState } from "@player-ui/react-subscribe";
12
8
  import { Registry } from "@player-ui/partial-match-registry";
13
9
  import { Player } from "@player-ui/player";
14
10
  import { ErrorBoundary as ErrorBoundary2 } from "react-error-boundary";
@@ -19,21 +15,12 @@ import leven from "leven";
19
15
  import { ErrorBoundary } from "react-error-boundary";
20
16
 
21
17
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/AssetRenderError.ts
22
- import {
23
- ErrorSeverity,
24
- ErrorTypes
25
- } from "@player-ui/player";
26
18
  var AssetRenderError = class extends Error {
27
19
  constructor(rootAsset, message, innerException) {
28
20
  super(message);
29
21
  this.rootAsset = rootAsset;
30
22
  this.innerException = innerException;
31
23
  this.assetParentPath = [];
32
- this.type = ErrorTypes.RENDER;
33
- this.severity = ErrorSeverity.ERROR;
34
- this.metadata = {
35
- assetId: rootAsset.id
36
- };
37
24
  this.initialMessage = message ?? "";
38
25
  this.innerExceptionMessage = innerException instanceof Error ? innerException.message : String(innerException);
39
26
  if (this.innerExceptionMessage) {
@@ -137,7 +124,6 @@ var ReactAsset = (props) => {
137
124
  error
138
125
  );
139
126
  }
140
- return null;
141
127
  }
142
128
  },
143
129
  /* @__PURE__ */ React.createElement(Impl, { key: unwrapped.id, ...unwrapped })
@@ -255,7 +241,6 @@ var OnUpdatePlugin = class {
255
241
  };
256
242
 
257
243
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx
258
- var ReactPlayerPropsContext = React4.createContext({ isInErrorState: false });
259
244
  var _window = typeof window === "undefined" ? void 0 : window;
260
245
  var ReactPlayer2 = class {
261
246
  constructor(options) {
@@ -316,16 +301,10 @@ var ReactPlayer2 = class {
316
301
  }
317
302
  /** Register and apply [Plugin] if one with the same symbol is not already registered. */
318
303
  registerPlugin(plugin) {
319
- if (plugin.apply) {
320
- this.player.registerPlugin(plugin);
321
- }
322
- if (plugin.applyReact) {
323
- plugin.applyReact?.(this);
324
- }
325
- if (!this.options.plugins) {
326
- this.options.plugins = [];
327
- }
328
- this.options.plugins.push(plugin);
304
+ if (!plugin.applyReact)
305
+ return;
306
+ plugin.applyReact(this);
307
+ this.options.plugins?.push(plugin);
329
308
  }
330
309
  /**
331
310
  * Returns the current version of the running React Player
@@ -344,84 +323,18 @@ var ReactPlayer2 = class {
344
323
  createReactPlayerComponent() {
345
324
  const BaseComp = this.hooks.webComponent.call(this.createReactComp());
346
325
  const ReactPlayerComponent = (props) => {
347
- const trackedErrors = React4.useRef(/* @__PURE__ */ new Map());
348
- const [errorSubId, setErrorSubId] = React4.useState(
349
- void 0
350
- );
351
- const { subscribe, unsubscribe } = useSubscriber(
352
- this.viewUpdateSubscription
353
- );
354
- const componentProps = React4.useMemo(
355
- () => ({
356
- ...props,
357
- isInErrorState: errorSubId !== void 0
358
- }),
359
- [props, errorSubId]
360
- );
361
- const clearErrorTracking = React4.useCallback(() => {
362
- trackedErrors.current.clear();
363
- setErrorSubId((prev) => {
364
- if (prev !== void 0) {
365
- unsubscribe(prev);
366
- }
367
- return void 0;
368
- });
369
- }, []);
370
- React4.useEffect(() => {
371
- return clearErrorTracking;
372
- }, [clearErrorTracking]);
373
- const captureError = React4.useCallback(
374
- (err) => {
375
- const playerState = this.player.getState();
376
- if (playerState.status !== "in-progress") {
377
- this.player.logger.warn(
378
- `[ReactPlayer]: An error occurred during rendering but was ignored due to a change in the player state (current state: '${playerState.status}'). Error Details:`,
379
- err
380
- );
381
- return false;
382
- }
383
- const currentError = trackedErrors.current.get(err);
384
- if (currentError !== void 0) {
385
- return currentError;
386
- }
387
- let isRecovering = false;
388
- setErrorSubId((prev) => {
389
- const subId = prev === void 0 ? subscribe(clearErrorTracking, {
390
- initializeWithPreviousValue: false
391
- }) : prev;
392
- isRecovering = playerState.controllers.error.captureError(err);
393
- trackedErrors.current.set(err, isRecovering);
394
- if (!isRecovering) {
395
- if (subId !== prev) {
396
- unsubscribe(subId);
397
- }
398
- return prev;
399
- }
400
- return subId;
401
- });
402
- return isRecovering;
403
- },
404
- [errorSubId]
405
- );
406
326
  return /* @__PURE__ */ React4.createElement(
407
327
  ErrorBoundary2,
408
328
  {
409
- fallbackRender: (fallbackProps) => {
410
- const isRecovering = captureError(fallbackProps.error);
411
- if (!isRecovering) {
412
- return null;
329
+ fallbackRender: () => null,
330
+ onError: (err) => {
331
+ const playerState = this.player.getState();
332
+ if (playerState.status === "in-progress") {
333
+ playerState.fail(err);
413
334
  }
414
- fallbackProps.resetErrorBoundary();
415
- return /* @__PURE__ */ React4.createElement(
416
- ReactPlayerPropsContext.Provider,
417
- {
418
- value: { ...componentProps, isInErrorState: true }
419
- },
420
- /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...componentProps, isInErrorState: true }))
421
- );
422
335
  }
423
336
  },
424
- /* @__PURE__ */ React4.createElement(ReactPlayerPropsContext.Provider, { value: { ...componentProps } }, /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...componentProps })))
337
+ /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...props }))
425
338
  );
426
339
  };
427
340
  return ReactPlayerComponent;
@@ -429,16 +342,8 @@ var ReactPlayer2 = class {
429
342
  createReactComp() {
430
343
  const ActualPlayerComp = this.hooks.playerComponent.call(ReactPlayer);
431
344
  const WebPlayerComponent = () => {
432
- const { isInErrorState } = React4.useContext(ReactPlayerPropsContext);
433
345
  const view = useSubscribedState(this.viewUpdateSubscription);
434
- const lastSuccessfulView = React4.useRef(void 0);
435
346
  this.viewUpdateSubscription.suspend();
436
- React4.useEffect(() => {
437
- if (!isInErrorState) {
438
- lastSuccessfulView.current = view;
439
- }
440
- }, [isInErrorState, view]);
441
- const displayedView = isInErrorState ? lastSuccessfulView.current : view;
442
347
  return /* @__PURE__ */ React4.createElement(
443
348
  AssetContext.Provider,
444
349
  {
@@ -446,7 +351,7 @@ var ReactPlayer2 = class {
446
351
  registry: this.assetRegistry
447
352
  }
448
353
  },
449
- displayedView && /* @__PURE__ */ React4.createElement(ActualPlayerComp, { view: displayedView })
354
+ view && /* @__PURE__ */ React4.createElement(ActualPlayerComp, { view })
450
355
  );
451
356
  };
452
357
  return WebPlayerComponent;
@@ -721,7 +626,9 @@ var usePersistentStateMachine = (options) => {
721
626
  if (oldManagedState) {
722
627
  const playerState = oldManagedState.state?.context.reactPlayer.player.getState();
723
628
  if (oldManagedState.state?.value === "running" && playerState?.status === "in-progress") {
724
- previousManager.current.terminate?.(playerState);
629
+ previousManager.current.terminate?.(
630
+ playerState.controllers.data.serialize()
631
+ );
725
632
  }
726
633
  }
727
634
  const newKey = createKey();
@@ -778,7 +685,7 @@ var ManagedPlayer = (props) => {
778
685
  } else if (state?.value === "error") {
779
686
  props.onError?.(state?.context.error);
780
687
  } else if (state?.value === "running") {
781
- props.onStartedFlow?.(state.context.flow);
688
+ props.onStartedFlow?.();
782
689
  }
783
690
  }
784
691
  previousState.current = state;
@@ -786,7 +693,7 @@ var ManagedPlayer = (props) => {
786
693
  return () => {
787
694
  const playerState = state?.context.reactPlayer.player.getState();
788
695
  if (state?.value === "running" && playerState?.status === "in-progress") {
789
- props.manager.terminate?.(playerState);
696
+ props.manager.terminate?.(playerState.controllers.data.serialize());
790
697
  }
791
698
  };
792
699
  }, [props.manager, state?.context.reactPlayer.player, state?.value]);
@@ -822,7 +729,6 @@ export {
822
729
  PlayerContext,
823
730
  ReactAsset,
824
731
  ReactPlayer2 as ReactPlayer,
825
- ReactPlayerPropsContext,
826
732
  WebPlayer,
827
733
  buildUrl,
828
734
  callOrReturn,
package/dist/index.mjs CHANGED
@@ -4,11 +4,7 @@ export * from "@player-ui/player";
4
4
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx
5
5
  import React4 from "react";
6
6
  import { SyncWaterfallHook, AsyncParallelHook } from "tapable-ts";
7
- import {
8
- Subscribe,
9
- useSubscribedState,
10
- useSubscriber
11
- } from "@player-ui/react-subscribe";
7
+ import { Subscribe, useSubscribedState } from "@player-ui/react-subscribe";
12
8
  import { Registry } from "@player-ui/partial-match-registry";
13
9
  import { Player } from "@player-ui/player";
14
10
  import { ErrorBoundary as ErrorBoundary2 } from "react-error-boundary";
@@ -19,21 +15,12 @@ import leven from "leven";
19
15
  import { ErrorBoundary } from "react-error-boundary";
20
16
 
21
17
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/AssetRenderError.ts
22
- import {
23
- ErrorSeverity,
24
- ErrorTypes
25
- } from "@player-ui/player";
26
18
  var AssetRenderError = class extends Error {
27
19
  constructor(rootAsset, message, innerException) {
28
20
  super(message);
29
21
  this.rootAsset = rootAsset;
30
22
  this.innerException = innerException;
31
23
  this.assetParentPath = [];
32
- this.type = ErrorTypes.RENDER;
33
- this.severity = ErrorSeverity.ERROR;
34
- this.metadata = {
35
- assetId: rootAsset.id
36
- };
37
24
  this.initialMessage = message ?? "";
38
25
  this.innerExceptionMessage = innerException instanceof Error ? innerException.message : String(innerException);
39
26
  if (this.innerExceptionMessage) {
@@ -137,7 +124,6 @@ var ReactAsset = (props) => {
137
124
  error
138
125
  );
139
126
  }
140
- return null;
141
127
  }
142
128
  },
143
129
  /* @__PURE__ */ React.createElement(Impl, { key: unwrapped.id, ...unwrapped })
@@ -255,7 +241,6 @@ var OnUpdatePlugin = class {
255
241
  };
256
242
 
257
243
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx
258
- var ReactPlayerPropsContext = React4.createContext({ isInErrorState: false });
259
244
  var _window = typeof window === "undefined" ? void 0 : window;
260
245
  var ReactPlayer2 = class {
261
246
  constructor(options) {
@@ -316,16 +301,10 @@ var ReactPlayer2 = class {
316
301
  }
317
302
  /** Register and apply [Plugin] if one with the same symbol is not already registered. */
318
303
  registerPlugin(plugin) {
319
- if (plugin.apply) {
320
- this.player.registerPlugin(plugin);
321
- }
322
- if (plugin.applyReact) {
323
- plugin.applyReact?.(this);
324
- }
325
- if (!this.options.plugins) {
326
- this.options.plugins = [];
327
- }
328
- this.options.plugins.push(plugin);
304
+ if (!plugin.applyReact)
305
+ return;
306
+ plugin.applyReact(this);
307
+ this.options.plugins?.push(plugin);
329
308
  }
330
309
  /**
331
310
  * Returns the current version of the running React Player
@@ -344,84 +323,18 @@ var ReactPlayer2 = class {
344
323
  createReactPlayerComponent() {
345
324
  const BaseComp = this.hooks.webComponent.call(this.createReactComp());
346
325
  const ReactPlayerComponent = (props) => {
347
- const trackedErrors = React4.useRef(/* @__PURE__ */ new Map());
348
- const [errorSubId, setErrorSubId] = React4.useState(
349
- void 0
350
- );
351
- const { subscribe, unsubscribe } = useSubscriber(
352
- this.viewUpdateSubscription
353
- );
354
- const componentProps = React4.useMemo(
355
- () => ({
356
- ...props,
357
- isInErrorState: errorSubId !== void 0
358
- }),
359
- [props, errorSubId]
360
- );
361
- const clearErrorTracking = React4.useCallback(() => {
362
- trackedErrors.current.clear();
363
- setErrorSubId((prev) => {
364
- if (prev !== void 0) {
365
- unsubscribe(prev);
366
- }
367
- return void 0;
368
- });
369
- }, []);
370
- React4.useEffect(() => {
371
- return clearErrorTracking;
372
- }, [clearErrorTracking]);
373
- const captureError = React4.useCallback(
374
- (err) => {
375
- const playerState = this.player.getState();
376
- if (playerState.status !== "in-progress") {
377
- this.player.logger.warn(
378
- `[ReactPlayer]: An error occurred during rendering but was ignored due to a change in the player state (current state: '${playerState.status}'). Error Details:`,
379
- err
380
- );
381
- return false;
382
- }
383
- const currentError = trackedErrors.current.get(err);
384
- if (currentError !== void 0) {
385
- return currentError;
386
- }
387
- let isRecovering = false;
388
- setErrorSubId((prev) => {
389
- const subId = prev === void 0 ? subscribe(clearErrorTracking, {
390
- initializeWithPreviousValue: false
391
- }) : prev;
392
- isRecovering = playerState.controllers.error.captureError(err);
393
- trackedErrors.current.set(err, isRecovering);
394
- if (!isRecovering) {
395
- if (subId !== prev) {
396
- unsubscribe(subId);
397
- }
398
- return prev;
399
- }
400
- return subId;
401
- });
402
- return isRecovering;
403
- },
404
- [errorSubId]
405
- );
406
326
  return /* @__PURE__ */ React4.createElement(
407
327
  ErrorBoundary2,
408
328
  {
409
- fallbackRender: (fallbackProps) => {
410
- const isRecovering = captureError(fallbackProps.error);
411
- if (!isRecovering) {
412
- return null;
329
+ fallbackRender: () => null,
330
+ onError: (err) => {
331
+ const playerState = this.player.getState();
332
+ if (playerState.status === "in-progress") {
333
+ playerState.fail(err);
413
334
  }
414
- fallbackProps.resetErrorBoundary();
415
- return /* @__PURE__ */ React4.createElement(
416
- ReactPlayerPropsContext.Provider,
417
- {
418
- value: { ...componentProps, isInErrorState: true }
419
- },
420
- /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...componentProps, isInErrorState: true }))
421
- );
422
335
  }
423
336
  },
424
- /* @__PURE__ */ React4.createElement(ReactPlayerPropsContext.Provider, { value: { ...componentProps } }, /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...componentProps })))
337
+ /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...props }))
425
338
  );
426
339
  };
427
340
  return ReactPlayerComponent;
@@ -429,16 +342,8 @@ var ReactPlayer2 = class {
429
342
  createReactComp() {
430
343
  const ActualPlayerComp = this.hooks.playerComponent.call(ReactPlayer);
431
344
  const WebPlayerComponent = () => {
432
- const { isInErrorState } = React4.useContext(ReactPlayerPropsContext);
433
345
  const view = useSubscribedState(this.viewUpdateSubscription);
434
- const lastSuccessfulView = React4.useRef(void 0);
435
346
  this.viewUpdateSubscription.suspend();
436
- React4.useEffect(() => {
437
- if (!isInErrorState) {
438
- lastSuccessfulView.current = view;
439
- }
440
- }, [isInErrorState, view]);
441
- const displayedView = isInErrorState ? lastSuccessfulView.current : view;
442
347
  return /* @__PURE__ */ React4.createElement(
443
348
  AssetContext.Provider,
444
349
  {
@@ -446,7 +351,7 @@ var ReactPlayer2 = class {
446
351
  registry: this.assetRegistry
447
352
  }
448
353
  },
449
- displayedView && /* @__PURE__ */ React4.createElement(ActualPlayerComp, { view: displayedView })
354
+ view && /* @__PURE__ */ React4.createElement(ActualPlayerComp, { view })
450
355
  );
451
356
  };
452
357
  return WebPlayerComponent;
@@ -721,7 +626,9 @@ var usePersistentStateMachine = (options) => {
721
626
  if (oldManagedState) {
722
627
  const playerState = oldManagedState.state?.context.reactPlayer.player.getState();
723
628
  if (oldManagedState.state?.value === "running" && playerState?.status === "in-progress") {
724
- previousManager.current.terminate?.(playerState);
629
+ previousManager.current.terminate?.(
630
+ playerState.controllers.data.serialize()
631
+ );
725
632
  }
726
633
  }
727
634
  const newKey = createKey();
@@ -778,7 +685,7 @@ var ManagedPlayer = (props) => {
778
685
  } else if (state?.value === "error") {
779
686
  props.onError?.(state?.context.error);
780
687
  } else if (state?.value === "running") {
781
- props.onStartedFlow?.(state.context.flow);
688
+ props.onStartedFlow?.();
782
689
  }
783
690
  }
784
691
  previousState.current = state;
@@ -786,7 +693,7 @@ var ManagedPlayer = (props) => {
786
693
  return () => {
787
694
  const playerState = state?.context.reactPlayer.player.getState();
788
695
  if (state?.value === "running" && playerState?.status === "in-progress") {
789
- props.manager.terminate?.(playerState);
696
+ props.manager.terminate?.(playerState.controllers.data.serialize());
790
697
  }
791
698
  };
792
699
  }, [props.manager, state?.context.reactPlayer.player, state?.value]);
@@ -822,7 +729,6 @@ export {
822
729
  PlayerContext,
823
730
  ReactAsset,
824
731
  ReactPlayer2 as ReactPlayer,
825
- ReactPlayerPropsContext,
826
732
  WebPlayer,
827
733
  buildUrl,
828
734
  callOrReturn,