@applicaster/zapp-react-native-utils 15.1.12 → 15.1.13-alpha.1034774223

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.
Files changed (66) hide show
  1. package/actionsExecutor/ActionExecutor.ts +40 -2
  2. package/actionsExecutor/ActionExecutorContext.tsx +70 -16
  3. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  4. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  5. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  6. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +212 -0
  7. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  8. package/actionsExecutor/actions/index.ts +4 -0
  9. package/actionsExecutor/actions/openBottomSheet.ts +325 -0
  10. package/actionsExecutor/actions/refreshComponent.ts +6 -0
  11. package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
  12. package/actionsExecutor/consts.ts +23 -0
  13. package/actionsExecutor/types.ts +1 -1
  14. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +5 -2
  15. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +55 -2
  16. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  17. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  18. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
  19. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  20. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  21. package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
  22. package/arrayUtils/index.ts +79 -0
  23. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  24. package/configurationUtils/__tests__/modalBlocksParser.test.ts +260 -0
  25. package/configurationUtils/manifestKeyParser.ts +50 -10
  26. package/configurationUtils/modalBlocksParser.ts +296 -0
  27. package/entryActions/__tests__/buildEntryActions.test.ts +156 -0
  28. package/entryActions/aliasPresentation.ts +124 -0
  29. package/entryActions/buildEntryActions.ts +166 -0
  30. package/entryActions/index.ts +17 -0
  31. package/entryActions/types.ts +39 -0
  32. package/manifestUtils/defaultManifestConfigurations/player.js +22 -1
  33. package/manifestUtils/index.js +3 -0
  34. package/manifestUtils/modalBlocks.js +304 -0
  35. package/modalState/ContentViewModel.ts +113 -0
  36. package/modalState/EditableCollection.ts +17 -0
  37. package/modalState/EditableCollectionRegistry.ts +51 -0
  38. package/modalState/ModalOrchestrator.ts +211 -0
  39. package/modalState/RemoteEditableCollection.ts +227 -0
  40. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  41. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  42. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  43. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
  44. package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
  45. package/modalState/__tests__/index.test.ts +30 -1
  46. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  47. package/modalState/index.ts +35 -83
  48. package/modalState/store.ts +102 -0
  49. package/modalState/types.ts +159 -0
  50. package/modalState/useBottomSheetContent.ts +104 -0
  51. package/package.json +2 -2
  52. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  53. package/playerUtils/index.ts +17 -1
  54. package/playerUtils/resolvePlayerActions.ts +71 -0
  55. package/reactHooks/actions/index.ts +67 -2
  56. package/reactHooks/usePluginConfiguration.ts +6 -3
  57. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  58. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  59. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  60. package/uiActionsRegistrator/index.ts +25 -203
  61. package/uiActionsRegistrator/registry.ts +335 -0
  62. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  63. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  64. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  65. package/playerUtils/getPlayerActionButtons.ts +0 -17
  66. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -0,0 +1,159 @@
1
+ export interface Header {
2
+ title: string;
3
+ subtitle?: string;
4
+ icon?: string;
5
+ }
6
+
7
+ export interface Action {
8
+ type: string;
9
+ payload?: any;
10
+ options?: any;
11
+ }
12
+
13
+ // Represented as 3 dots icon on top menu (opens new second level menu on desktop
14
+ // or a new bottom sheet on mobile)
15
+ export interface PresentSubMenuAction extends Action {
16
+ menu: Menu;
17
+ }
18
+
19
+ export interface SecondaryAction {
20
+ action: Action | PresentSubMenuAction;
21
+ icon?: string;
22
+ }
23
+
24
+ /**
25
+ * A group of actions attached to an entry, keyed by a button alias
26
+ * (e.g. "remove_item", "reorder_item"). Injected by the feed decorator and
27
+ * dispatched by the remote EditableCollection when an operation runs.
28
+ */
29
+ export interface EntryActionGroup {
30
+ button?: { alias?: string };
31
+ actions?: Action[];
32
+ }
33
+
34
+ export interface MenuItem {
35
+ id: string;
36
+ title: string;
37
+ summary?: string;
38
+ icon?: string;
39
+ isSelected?: boolean;
40
+ actions?: (Action | PresentSubMenuAction)[];
41
+ /** @deprecated Use `actions` array instead. Maintained for backwards compatibility. */
42
+ action?: Action | PresentSubMenuAction;
43
+ secondaryAction?: SecondaryAction;
44
+ trailingButton?: any;
45
+ entryActions?: EntryActionGroup[];
46
+ }
47
+
48
+ export type SelectMode = "single" | "multi" | "none";
49
+
50
+ export interface SelectionBehavior {
51
+ selectMode?: SelectMode;
52
+ currentSelection?: string[];
53
+ selector?: string;
54
+ }
55
+
56
+ /**
57
+ * Operations that act on a specific item in the collection.
58
+ * Their action payloads are looked up on the item's entryActions (e.g. "remove_item", "reorder_item").
59
+ */
60
+ export type ItemScopedOperation = "remove" | "reorder";
61
+
62
+ /**
63
+ * Operations that act on the collection as a whole.
64
+ * Their action payloads are looked up on dynamicCollection.events (e.g. events.add, events.clearAll, events.delete).
65
+ */
66
+ export type CollectionScopedOperation = "add" | "clearAll" | "delete";
67
+
68
+ /**
69
+ * UI display or behavior flags that do not require action payloads.
70
+ */
71
+ export type UIOperation = "nowPlaying";
72
+
73
+ export const OPERATIONS = {
74
+ REMOVE: "remove",
75
+ REORDER: "reorder",
76
+ ADD: "add",
77
+ CLEAR_ALL: "clearAll",
78
+ DELETE: "delete",
79
+ NOW_PLAYING: "nowPlaying",
80
+ } as const;
81
+
82
+ export function hasOperation(
83
+ operations: string[] | undefined,
84
+ target: string
85
+ ): boolean {
86
+ if (!Array.isArray(operations)) return false;
87
+
88
+ const targetLower = target.toLowerCase();
89
+
90
+ return operations.some(
91
+ (op) => typeof op === "string" && op.toLowerCase() === targetLower
92
+ );
93
+ }
94
+
95
+ export type Operation =
96
+ | ItemScopedOperation
97
+ | CollectionScopedOperation
98
+ | UIOperation;
99
+
100
+ export interface DynamicCollectionOptions {
101
+ operations: Operation[];
102
+ postUrl?: string;
103
+ provider?: string;
104
+ /**
105
+ * Action handlers for CollectionScopedOperations (e.g. "add", "clearAll", "delete").
106
+ */
107
+ events?: Record<CollectionScopedOperation | string, Action[]>;
108
+ }
109
+
110
+ export interface Content {
111
+ title: string;
112
+ stickyTitle?: boolean;
113
+ items: MenuItem[];
114
+ itemsUrl?: string;
115
+ action?: Action;
116
+ role?: string;
117
+ behavior?: SelectionBehavior;
118
+ dynamicCollection?: DynamicCollectionOptions;
119
+ themePluginId?: string;
120
+ styleOverrides?: Record<string, any>;
121
+ }
122
+
123
+ export interface Menu {
124
+ header?: Header;
125
+ content: Content;
126
+ closeButton?: boolean;
127
+ }
128
+
129
+ export function isPresentSubMenuAction(
130
+ action: any
131
+ ): action is PresentSubMenuAction {
132
+ return !!action && typeof action === "object" && "menu" in action;
133
+ }
134
+
135
+ /**
136
+ * Normalizes an item's action/actions into an array of Action items.
137
+ * Supports canonical `actions: Action[]` and backwards-compatible `action: Action | Action[]`.
138
+ */
139
+ export function getMenuItemActions(
140
+ item?: Partial<MenuItem> | null
141
+ ): (Action | PresentSubMenuAction)[] {
142
+ if (!item) {
143
+ return [];
144
+ }
145
+
146
+ if (Array.isArray(item.actions) && item.actions.length > 0) {
147
+ return item.actions;
148
+ }
149
+
150
+ if (Array.isArray((item as any).action)) {
151
+ return (item as any).action;
152
+ }
153
+
154
+ if (item.action) {
155
+ return [item.action];
156
+ }
157
+
158
+ return [];
159
+ }
@@ -0,0 +1,104 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
3
+
4
+ import { MenuItem, modalOrchestrator } from "./ModalOrchestrator";
5
+
6
+ import { ContentViewModel } from "./ContentViewModel";
7
+ import {
8
+ DynamicCollectionOptions,
9
+ getMenuItemActions,
10
+ isPresentSubMenuAction,
11
+ SelectionBehavior,
12
+ } from "./types";
13
+ import type { EditableCollection } from "./EditableCollection";
14
+
15
+ type Props = {
16
+ viewModel?: ContentViewModel | null;
17
+ onPress: (item: MenuItem) => void | Promise<void>;
18
+ };
19
+
20
+ type Return = {
21
+ items: MenuItem[];
22
+ isLoading: boolean;
23
+ error?: Error | string;
24
+ showCentralLoading: boolean;
25
+ canGoBack: boolean;
26
+ handleItemPress: (item: MenuItem) => Promise<void>;
27
+ goBackOrClose: () => void;
28
+ close: () => void;
29
+ role?: string;
30
+ behavior?: SelectionBehavior;
31
+ dynamicCollection?: DynamicCollectionOptions;
32
+ editableCollection: EditableCollection | null;
33
+ themePluginId?: string;
34
+ };
35
+
36
+ export const useBottomSheetContent = (props: Props): Return => {
37
+ const { onPress, viewModel } = props;
38
+
39
+ const [state, setState] = useState(viewModel?.getState());
40
+
41
+ const [editableItems, setEditableItems] = useState<MenuItem[]>(
42
+ () => viewModel?.getState().items || []
43
+ );
44
+
45
+ // Subscribe to the viewModel state changes
46
+ useEffect(() => {
47
+ return viewModel?.subscribe((nextState) => {
48
+ setState(nextState);
49
+ });
50
+ }, [viewModel]);
51
+
52
+ // Subscribe to editable collection items
53
+ useEffect(() => {
54
+ if (viewModel?.editableCollection) {
55
+ const subscription =
56
+ viewModel.editableCollection.items$.subscribe(setEditableItems);
57
+
58
+ return () => subscription.unsubscribe();
59
+ }
60
+ }, [viewModel?.editableCollection]);
61
+
62
+ /**
63
+ * Handles an item press:
64
+ * - Delegates to the parent onPress (which runs the action and awaits it).
65
+ * - If the item was a leaf action (not a submenu), triggers viewModel.refetch()
66
+ * so that checkmarks (isSelected) reflect the updated server state.
67
+ */
68
+ const handleItemPress = async (item: MenuItem) => {
69
+ const actions = getMenuItemActions(item);
70
+ const isSubMenu = actions.some(isPresentSubMenuAction);
71
+
72
+ await onPress(item);
73
+
74
+ if (!isSubMenu) {
75
+ await viewModel?.refetch();
76
+ }
77
+ };
78
+
79
+ const goBackOrClose = React.useCallback(() => {
80
+ if (modalOrchestrator.canGoBack) {
81
+ modalOrchestrator.back();
82
+ } else {
83
+ modalOrchestrator.close();
84
+ }
85
+ }, [modalOrchestrator.canGoBack]);
86
+
87
+ return {
88
+ items: viewModel?.editableCollection ? editableItems : state?.items,
89
+ isLoading: toBooleanWithDefaultFalse(state?.isLoading),
90
+ error: state?.error,
91
+ showCentralLoading: toBooleanWithDefaultFalse(
92
+ state?.isLoading && state?.items.length === 0
93
+ ),
94
+ canGoBack: modalOrchestrator.canGoBack,
95
+ handleItemPress,
96
+ goBackOrClose,
97
+ close: () => modalOrchestrator.close(),
98
+ role: state?.role,
99
+ behavior: state?.behavior,
100
+ dynamicCollection: state?.dynamicCollection,
101
+ editableCollection: viewModel?.editableCollection || null,
102
+ themePluginId: state?.themePluginId,
103
+ };
104
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "15.1.12",
3
+ "version": "15.1.13-alpha.1034774223",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "15.1.12",
30
+ "@applicaster/applicaster-types": "15.1.13-alpha.1034774223",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -0,0 +1,138 @@
1
+ import { resolvePlayerActions } from "../resolvePlayerActions";
2
+ import { selectActionButtons } from "../../conf/player/selectors";
3
+ import { uiActionsRegistry } from "../../uiActionsRegistrator";
4
+
5
+ jest.mock("../../conf/player/selectors", () => ({
6
+ selectActionButtons: jest.fn(),
7
+ }));
8
+
9
+ const action = (identifier: string) =>
10
+ ({ identifier, action: { invokeAction: jest.fn() } }) as any;
11
+
12
+ describe("resolvePlayerActions", () => {
13
+ const entry = {
14
+ id: "e1",
15
+ extensions: {
16
+ entry_action: [
17
+ { button: { alias: "add_to_playlist" }, actions: [{ type: "test" }] },
18
+ { button: { alias: "add_to_queue" }, actions: [{ type: "test" }] },
19
+ ],
20
+ },
21
+ };
22
+
23
+ // The entry's own actions never reach the registry; the caller expands them.
24
+ const expandEntryActions = jest.fn(() => [
25
+ action("entry_action_0"),
26
+ action("entry_action_1"),
27
+ ]);
28
+
29
+ beforeEach(() => {
30
+ expandEntryActions.mockClear();
31
+
32
+ jest
33
+ .spyOn(uiActionsRegistry, "getActions")
34
+ .mockImplementation((name) => [action(name)]);
35
+ });
36
+
37
+ afterEach(() => {
38
+ jest.restoreAllMocks();
39
+ });
40
+
41
+ it("expands entry_actions through the caller and keeps config order", () => {
42
+ (selectActionButtons as jest.Mock).mockReturnValue(
43
+ "entry_actions,local_storage_favourites_action,offline-content-button"
44
+ );
45
+
46
+ const result = resolvePlayerActions({
47
+ configuration: {},
48
+ entry,
49
+ expandEntryActions,
50
+ });
51
+
52
+ expect(expandEntryActions).toHaveBeenCalledWith(entry);
53
+
54
+ expect(uiActionsRegistry.getActions).not.toHaveBeenCalledWith(
55
+ "entry_actions",
56
+ entry
57
+ );
58
+
59
+ expect(result.map((item) => item.identifier)).toEqual([
60
+ "entry_action_0",
61
+ "entry_action_1",
62
+ "local_storage_favourites_action",
63
+ "offline-content-button",
64
+ ]);
65
+ });
66
+
67
+ it.each([undefined, null, ""])(
68
+ "resolves nothing when the config is %p",
69
+ (configured) => {
70
+ (selectActionButtons as jest.Mock).mockReturnValue(configured);
71
+
72
+ expect(
73
+ resolvePlayerActions({ configuration: {}, entry, expandEntryActions })
74
+ ).toEqual([]);
75
+ }
76
+ );
77
+
78
+ it("does not cap the resolved list at two items", () => {
79
+ (selectActionButtons as jest.Mock).mockReturnValue("a,b,c");
80
+
81
+ expect(
82
+ resolvePlayerActions({
83
+ configuration: {},
84
+ entry,
85
+ expandEntryActions,
86
+ }).map((item) => item.identifier)
87
+ ).toEqual(["a", "b", "c"]);
88
+ });
89
+
90
+ it("has no special case for any plugin identifier", () => {
91
+ (selectActionButtons as jest.Mock).mockReturnValue(
92
+ "open-modal-bottom-sheet-cell-action,local_storage_favourites_action"
93
+ );
94
+
95
+ expect(
96
+ resolvePlayerActions({
97
+ configuration: {},
98
+ entry,
99
+ expandEntryActions,
100
+ }).map((item) => item.identifier)
101
+ ).toEqual([
102
+ "open-modal-bottom-sheet-cell-action",
103
+ "local_storage_favourites_action",
104
+ ]);
105
+ });
106
+
107
+ it("collapses a repeated identifier in the config string", () => {
108
+ (selectActionButtons as jest.Mock).mockReturnValue(
109
+ "favorites,favorites,share"
110
+ );
111
+
112
+ expect(
113
+ resolvePlayerActions({
114
+ configuration: {},
115
+ entry,
116
+ expandEntryActions,
117
+ }).map((item) => item.identifier)
118
+ ).toEqual(["favorites", "share"]);
119
+ });
120
+
121
+ it("drops resolved items that cannot be invoked", () => {
122
+ (selectActionButtons as jest.Mock).mockReturnValue("broken,share");
123
+
124
+ (uiActionsRegistry.getActions as jest.Mock).mockImplementation((name) =>
125
+ name === "broken"
126
+ ? [{ identifier: "broken" } as any]
127
+ : [action(name as string)]
128
+ );
129
+
130
+ expect(
131
+ resolvePlayerActions({
132
+ configuration: {},
133
+ entry,
134
+ expandEntryActions,
135
+ }).map((item) => item.identifier)
136
+ ).toEqual(["share"]);
137
+ });
138
+ });
@@ -7,7 +7,23 @@ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
7
7
  import { getBoolFromConfigValue } from "../configurationUtils";
8
8
  import { Dimensions } from "react-native";
9
9
 
10
- export { getPlayerActionButtons } from "./getPlayerActionButtons";
10
+ export { resolvePlayerActions } from "./resolvePlayerActions";
11
+
12
+ export { isEntryAction } from "../entryActions";
13
+
14
+ export {
15
+ parseActionIdentifiers,
16
+ resolveActionIdentifiers,
17
+ } from "../uiActionsRegistrator";
18
+
19
+ export type { ResolveActionIdentifiersParams } from "../uiActionsRegistrator";
20
+
21
+ export type {
22
+ ActionButtonDescriptor,
23
+ OverflowDescriptor,
24
+ PlayerControlDescriptor,
25
+ ResolvePlayerActionsParams,
26
+ } from "./resolvePlayerActions";
11
27
 
12
28
  export {
13
29
  resolvePlayerContentText,
@@ -0,0 +1,71 @@
1
+ import { selectActionButtons } from "../conf/player/selectors";
2
+ import {
3
+ usableActionItems,
4
+ RegisteredAction,
5
+ resolveActionIdentifiers,
6
+ } from "../uiActionsRegistrator";
7
+
8
+ export type ResolvePlayerActionsParams = {
9
+ configuration: any;
10
+ entry: ZappEntry | ZappFeed;
11
+ /** Expands the `entry_actions` token; see `resolveActionIdentifiers`. */
12
+ expandEntryActions?: (entry: ZappEntry | ZappFeed) => RegisteredAction[];
13
+ };
14
+
15
+ /**
16
+ * The player's action buttons, resolved against the entry.
17
+ *
18
+ * Every `player_action_buttons` token goes through `uiActionsRegistry`, except
19
+ * `entry_actions`, which the caller expands from the entry itself. The list is
20
+ * not capped; the overlay decides how many fit and sends the rest to the sheet.
21
+ */
22
+ export function resolvePlayerActions({
23
+ configuration,
24
+ entry,
25
+ expandEntryActions,
26
+ }: ResolvePlayerActionsParams): RegisteredAction[] {
27
+ const buttonsString = selectActionButtons(configuration);
28
+
29
+ if (!buttonsString) {
30
+ return [];
31
+ }
32
+
33
+ // Deduped at the source: `player_action_buttons` is a hand-typed string, so
34
+ // the same identifier can legitimately appear twice. Left alone, a repeat
35
+ // would be counted twice against the inline limit, rendered twice on the
36
+ // overlay, and collide as a React key. Items with no `invokeAction` are
37
+ // dropped here too - they can never do anything.
38
+ return usableActionItems(
39
+ resolveActionIdentifiers({
40
+ identifiers: buttonsString,
41
+ entry,
42
+ expandEntryActions,
43
+ })
44
+ );
45
+ }
46
+
47
+ /** One control on the player overlay, before overflow is applied. */
48
+ export type ActionButtonDescriptor =
49
+ | { kind: "subtitle" }
50
+ | { kind: "close" }
51
+ | { kind: "airplay" }
52
+ | { kind: "action"; action: RegisteredAction };
53
+
54
+ /**
55
+ * The Overflow control, produced by `splitOverflow` when more content actions
56
+ * resolve than fit on the overlay.
57
+ */
58
+ export type OverflowDescriptor = {
59
+ kind: "overflow";
60
+ /**
61
+ * Every content action, the overlay companion included. An overlay button
62
+ * renders nothing when its action has no icon, so the companion needs the
63
+ * sheet as a second home or it could be reachable from nowhere.
64
+ */
65
+ additionalActions: RegisteredAction[];
66
+ };
67
+
68
+ /** What the overlay actually renders, once overflow has been applied. */
69
+ export type PlayerControlDescriptor =
70
+ | ActionButtonDescriptor
71
+ | OverflowDescriptor;
@@ -6,6 +6,7 @@ import { ActionsContext } from "@applicaster/zapp-react-native-ui-components/Con
6
6
  import {
7
7
  observeEntryState,
8
8
  RegisteredActionValue,
9
+ uiActionsRegistry,
9
10
  } from "../../uiActionsRegistrator";
10
11
  import { reactHooksLogger } from "../logger";
11
12
 
@@ -34,7 +35,13 @@ export function useActions<T = unknown>(plugId: string): any {
34
35
  if (!logged) {
35
36
  logger.warning({
36
37
  message: `useActions: Couldn't find an action for ${plugId} plugin`,
37
- data: { actions: context?.actions },
38
+ // Identifiers only. The action map holds every plugin's module and
39
+ // live React context, which is far too large for a log line and can
40
+ // carry whatever state those plugins hold.
41
+ data: {
42
+ plugId,
43
+ availableActions: Object.keys(context?.actions ?? {}),
44
+ },
38
45
  });
39
46
 
40
47
  setLogged(true);
@@ -80,7 +87,31 @@ export function useEntryActionState(
80
87
  useEffect(() => {
81
88
  if (!action) return undefined;
82
89
 
83
- const subscription = observeEntryState(action, entry).subscribe(setState);
90
+ // An action's stream is third-party code. Subscribing with only a `next`
91
+ // handler lets RxJS rethrow an error notification asynchronously, where no
92
+ // error boundary catches it - one plugin faulting would take the app down
93
+ // rather than this one button. The button keeps its last known state.
94
+ let subscription;
95
+
96
+ try {
97
+ subscription = observeEntryState(action, entry).subscribe({
98
+ next: setState,
99
+ error: (error) =>
100
+ logger.warning({
101
+ message:
102
+ "useEntryActionState: the action's state stream failed - the button keeps its last state",
103
+ data: { entryId, error },
104
+ }),
105
+ });
106
+ } catch (error) {
107
+ logger.warning({
108
+ message:
109
+ "useEntryActionState: could not observe the action - the button keeps its initial state",
110
+ data: { entryId, error },
111
+ });
112
+
113
+ return undefined;
114
+ }
84
115
 
85
116
  return () => subscription.unsubscribe();
86
117
  // eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
@@ -88,6 +119,18 @@ export function useEntryActionState(
88
119
 
89
120
  const invokeAction = useCallback(
90
121
  (options: InvokeArgsOptions = {}) => {
122
+ if (typeof action?.invokeAction !== "function") {
123
+ // A button was rendered and pressed, and the press goes nowhere. Only
124
+ // reachable on a user interaction, so it costs nothing on render. The
125
+ // action value carries no identifier, so the label is what locates the
126
+ // button that misbehaved.
127
+ logger.warning({
128
+ message:
129
+ "useEntryActionState: the pressed action has no invokeAction - the press did nothing",
130
+ data: { entryId, label: state?.label },
131
+ });
132
+ }
133
+
91
134
  action?.invokeAction?.(entry, { updateState: setState, ...options });
92
135
  },
93
136
  // eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
@@ -96,3 +139,25 @@ export function useEntryActionState(
96
139
 
97
140
  return { state, invokeAction };
98
141
  }
142
+
143
+ /**
144
+ * A value that changes whenever a provider is added to or removed from
145
+ * `uiActionsRegistry`.
146
+ *
147
+ * Providers can register after the UI that wants them has rendered - the audio
148
+ * player registers playback speed only once its controller has state, and
149
+ * plugin-backed actions are bridged in from an effect. Put this in the
150
+ * dependency list of anything that resolves actions, so the list is re-read
151
+ * instead of being frozen at first paint.
152
+ */
153
+ export function useRegistryRevision(): number {
154
+ const [revision, setRevision] = useState(0);
155
+
156
+ useEffect(
157
+ () =>
158
+ uiActionsRegistry.subscribe(() => setRevision((current) => current + 1)),
159
+ []
160
+ );
161
+
162
+ return revision;
163
+ }
@@ -1,7 +1,7 @@
1
1
  import * as R from "ramda";
2
2
  import { useMemo } from "react";
3
3
 
4
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
4
+ import { usePlugins } from "@applicaster/zapp-react-native-redux/hooks";
5
5
 
6
6
  // importing this way prevents typescript packages importing from this
7
7
  // file to go crazy reporting errors on JS
@@ -24,8 +24,11 @@ export function parsePluginConfiguration(plugin, manifest) {
24
24
  return populateFields(plugin, manifest.custom_configuration_fields);
25
25
  }
26
26
 
27
- export function usePluginConfiguration<T, S>(identifier, manifest) {
28
- const { plugins } = usePickFromState(["plugins"]);
27
+ export function usePluginConfiguration<T = any, S = Record<string, any>>(
28
+ identifier: string,
29
+ manifest?: any
30
+ ) {
31
+ const plugins = usePlugins();
29
32
 
30
33
  const plugin = useMemo(
31
34
  () => R.find(R.propEq("identifier", identifier), plugins),