@applicaster/zapp-react-native-utils 16.0.0-alpha.1052711356 → 16.0.0-alpha.1054344748

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 (120) hide show
  1. package/actionsExecutor/ActionExecutor.ts +50 -3
  2. package/actionsExecutor/ActionExecutorContext.tsx +97 -19
  3. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  4. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  5. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +3 -0
  6. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  7. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  8. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
  9. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +300 -0
  10. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  11. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  12. package/actionsExecutor/actions/__tests__/showToast.test.ts +29 -4
  13. package/actionsExecutor/actions/dismissBottomSheet.ts +2 -1
  14. package/actionsExecutor/actions/goBack.ts +60 -0
  15. package/actionsExecutor/actions/goHome.ts +31 -0
  16. package/actionsExecutor/actions/index.ts +8 -0
  17. package/actionsExecutor/actions/navigateToScreen.ts +18 -4
  18. package/actionsExecutor/actions/openBottomSheet.ts +51 -31
  19. package/actionsExecutor/actions/presentScreen.ts +78 -0
  20. package/actionsExecutor/actions/sendCloudEvent.ts +5 -8
  21. package/actionsExecutor/actions/showAlert.ts +51 -0
  22. package/actionsExecutor/actions/showToast.ts +62 -6
  23. package/actionsExecutor/consts.ts +27 -0
  24. package/actionsExecutor/feedDecorator.ts +6 -6
  25. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  26. package/appUtils/HooksManager/index.ts +9 -0
  27. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
  28. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  29. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  30. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  31. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  32. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  33. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  34. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  35. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  36. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  37. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  38. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  39. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  40. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -0
  41. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  42. package/appUtils/playerManager/{conts.ts → const.ts} +33 -0
  43. package/appUtils/playerManager/index.ts +3 -1
  44. package/appUtils/playerManager/player.ts +125 -3
  45. package/appUtils/playerManager/playerFactory.ts +1 -1
  46. package/appUtils/playerManager/playerNative.ts +28 -4
  47. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  48. package/appUtils/playerManager/playerToolbox.ts +192 -0
  49. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  50. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  51. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  52. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  53. package/arrayUtils/index.ts +62 -0
  54. package/cellUtils/index.ts +30 -3
  55. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  56. package/configurationUtils/__tests__/modalBlocksParser.test.ts +269 -0
  57. package/configurationUtils/manifestKeyParser.ts +50 -10
  58. package/configurationUtils/modalBlocksParser.ts +214 -0
  59. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  60. package/entryActions/aliasPresentation.ts +108 -0
  61. package/entryActions/buildEntryActions.ts +167 -0
  62. package/entryActions/index.ts +15 -0
  63. package/entryActions/types.ts +39 -0
  64. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  65. package/manifestUtils/_internals/index.js +8 -3
  66. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  67. package/manifestUtils/defaultManifestConfigurations/player.js +330 -1
  68. package/manifestUtils/index.js +3 -0
  69. package/manifestUtils/modalBlocks.js +304 -0
  70. package/modalState/ContentViewModel.ts +2 -0
  71. package/modalState/ModalOrchestrator.ts +23 -9
  72. package/modalState/RemoteEditableCollection.ts +77 -31
  73. package/modalState/__tests__/ContentViewModel.test.ts +3 -3
  74. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +35 -0
  75. package/modalState/__tests__/RemoteEditableCollection.test.ts +157 -1
  76. package/modalState/__tests__/index.test.ts +30 -1
  77. package/modalState/__tests__/useBottomSheetContent.test.ts +0 -23
  78. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  79. package/modalState/index.ts +6 -1
  80. package/modalState/store.ts +9 -2
  81. package/modalState/types.ts +56 -4
  82. package/modalState/useBottomSheetContent.ts +37 -26
  83. package/package.json +2 -2
  84. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  85. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  86. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  87. package/playerUtils/contentDataKeys.ts +134 -0
  88. package/playerUtils/index.ts +37 -16
  89. package/playerUtils/isAudioItem.ts +26 -0
  90. package/playerUtils/resolvePlayerActions.ts +71 -0
  91. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  92. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  93. package/pluginUtils/index.ts +29 -0
  94. package/reactHooks/actions/index.ts +67 -2
  95. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  96. package/reactHooks/cell-click/index.ts +21 -14
  97. package/reactHooks/connection/index.tsx +8 -5
  98. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  99. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  100. package/reactHooks/index.ts +2 -0
  101. package/reactHooks/layout/index.ts +1 -1
  102. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  103. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  104. package/reactHooks/navigation/index.ts +2 -0
  105. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  106. package/reactHooks/navigation/useRoute.ts +22 -5
  107. package/reactHooks/usePluginConfiguration.ts +4 -1
  108. package/reactHooks/utils/__tests__/index.test.js +22 -2
  109. package/reactHooks/utils/index.ts +11 -1
  110. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  111. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  112. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  113. package/uiActionsRegistrator/index.ts +25 -203
  114. package/uiActionsRegistrator/registry.ts +351 -0
  115. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  116. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  117. package/zappFrameworkUtils/localStorageHelper.ts +10 -2
  118. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  119. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  120. package/playerUtils/getPlayerActionButtons.ts +0 -17
@@ -34,16 +34,26 @@ const itemPlain: MenuItem = { id: "2", title: "B" };
34
34
  function makeCollection(
35
35
  items: MenuItem[],
36
36
  refetch = jest.fn().mockResolvedValue(undefined),
37
- operations = ["remove", "reorder"]
37
+ operations = ["remove", "reorder"],
38
+ context?: Record<string, unknown>
38
39
  ) {
39
40
  const content = {
40
41
  items,
42
+ context,
41
43
  dynamicCollection: { operations, postUrl: "https://x/cloud-events" },
42
44
  } as unknown as Content;
43
45
 
44
46
  return { col: new RemoteEditableCollection(content, refetch), refetch };
45
47
  }
46
48
 
49
+ const openingContext = {
50
+ component: {
51
+ id: "list-1",
52
+ data: { source: "https://example.com/user/collections/abc" },
53
+ },
54
+ screenData: { id: "playlist-screen" },
55
+ };
56
+
47
57
  describe("RemoteEditableCollection", () => {
48
58
  beforeEach(() => jest.clearAllMocks());
49
59
 
@@ -118,6 +128,24 @@ describe("RemoteEditableCollection", () => {
118
128
  expect(refetch).toHaveBeenCalledTimes(1);
119
129
  expect(currentItems(col)).toEqual([itemWithRemove]);
120
130
  });
131
+
132
+ it("forwards stored sheet context plus the removed item as entry", async () => {
133
+ handleAction.mockResolvedValue("success");
134
+
135
+ const { col } = makeCollection(
136
+ [itemWithRemove, itemPlain],
137
+ jest.fn().mockResolvedValue(undefined),
138
+ ["remove", "reorder"],
139
+ openingContext
140
+ );
141
+
142
+ await col.remove(0);
143
+
144
+ expect(handleAction).toHaveBeenCalledWith(removeAction, {
145
+ ...openingContext,
146
+ entry: itemWithRemove,
147
+ });
148
+ });
121
149
  });
122
150
 
123
151
  describe("move", () => {
@@ -164,6 +192,35 @@ describe("RemoteEditableCollection", () => {
164
192
  expect(refetch).toHaveBeenCalledTimes(1);
165
193
  });
166
194
 
195
+ it("forwards stored sheet context plus the moved item as entry", async () => {
196
+ handleAction.mockResolvedValue("success");
197
+
198
+ const itemA: MenuItem = {
199
+ id: "2",
200
+ title: "B",
201
+ entryActions: [
202
+ { button: { alias: "reorder_item" }, actions: [removeAction] },
203
+ ],
204
+ };
205
+
206
+ const { col } = makeCollection(
207
+ [itemA],
208
+ jest.fn().mockResolvedValue(undefined),
209
+ ["remove", "reorder"],
210
+ openingContext
211
+ );
212
+
213
+ await col.move(["2"]);
214
+
215
+ expect(handleAction).toHaveBeenCalledWith(
216
+ expect.objectContaining({ type: "sendCloudEvent" }),
217
+ {
218
+ ...openingContext,
219
+ entry: itemA,
220
+ }
221
+ );
222
+ });
223
+
167
224
  it("rolls back on failure", async () => {
168
225
  handleAction.mockRejectedValue(new Error("nope"));
169
226
 
@@ -209,6 +266,42 @@ describe("RemoteEditableCollection", () => {
209
266
 
210
267
  expect(currentItems(col)).toEqual(next);
211
268
  });
269
+
270
+ it("suppresses sync updates while a local mutation is in-flight", async () => {
271
+ let resolveAction: () => void = () => {};
272
+
273
+ handleAction.mockImplementation(
274
+ () =>
275
+ new Promise<void>((resolve) => {
276
+ resolveAction = resolve;
277
+ })
278
+ );
279
+
280
+ const { col } = makeCollection([itemWithRemove, itemPlain]);
281
+ const staleServerItems: MenuItem[] = [{ id: "stale", title: "Stale" }];
282
+
283
+ // Initiate optimistic removal (mutation in-flight)
284
+ const removePromise = col.remove(0);
285
+
286
+ // Verify optimistic state applied locally
287
+ expect(currentItems(col)).toEqual([itemPlain]);
288
+
289
+ // Attempt sync while mutation is in-flight
290
+ col.sync(staleServerItems);
291
+
292
+ // Verify sync was suppressed and optimistic state remained
293
+ expect(currentItems(col)).toEqual([itemPlain]);
294
+
295
+ // Resolve the in-flight mutation
296
+ resolveAction();
297
+ await removePromise;
298
+
299
+ // After mutation completes, sync applies normally
300
+ const freshServerItems: MenuItem[] = [{ id: "fresh", title: "Fresh" }];
301
+ col.sync(freshServerItems);
302
+
303
+ expect(currentItems(col)).toEqual(freshServerItems);
304
+ });
212
305
  });
213
306
 
214
307
  describe("deleteCollection", () => {
@@ -221,6 +314,37 @@ describe("RemoteEditableCollection", () => {
221
314
  expect(currentItems(col)).toEqual([]);
222
315
  expect(refetch).toHaveBeenCalledTimes(1);
223
316
  });
317
+
318
+ it("dispatches aliased action when first item contains delete_collection alias", async () => {
319
+ handleAction.mockResolvedValue("success");
320
+
321
+ const deleteAction = {
322
+ type: "sendCloudEvent",
323
+ options: { subject: "delete_collection" },
324
+ };
325
+
326
+ const itemWithDelete: MenuItem = {
327
+ id: "100",
328
+ title: "Collection Item",
329
+ entryActions: [
330
+ {
331
+ button: { alias: "delete_collection" },
332
+ actions: [deleteAction],
333
+ },
334
+ ],
335
+ };
336
+
337
+ const { col, refetch } = makeCollection([itemWithDelete]);
338
+
339
+ await col.deleteCollection();
340
+
341
+ expect(handleAction).toHaveBeenCalledWith(deleteAction, {
342
+ entry: itemWithDelete,
343
+ });
344
+
345
+ expect(refetch).toHaveBeenCalledTimes(1);
346
+ expect(currentItems(col)).toEqual([]);
347
+ });
224
348
  });
225
349
 
226
350
  describe("add", () => {
@@ -255,5 +379,37 @@ describe("RemoteEditableCollection", () => {
255
379
  expect(handleAction).toHaveBeenCalledWith(addAction);
256
380
  expect(refetch).toHaveBeenCalledTimes(1);
257
381
  });
382
+
383
+ it("forwards stored sheet context into events.add actions", async () => {
384
+ handleAction.mockResolvedValue("success");
385
+
386
+ const addAction = {
387
+ type: "showTextInput",
388
+ options: {
389
+ headerTitle: "Create Playlist",
390
+ buttonLabel: "Create",
391
+ actions: [{ type: "sendCloudEvent" }],
392
+ },
393
+ };
394
+
395
+ const content = {
396
+ items: [],
397
+ context: openingContext,
398
+ dynamicCollection: {
399
+ operations: ["add"],
400
+ postUrl: "https://x/cloud-events",
401
+ events: {
402
+ add: [addAction],
403
+ },
404
+ },
405
+ } as any;
406
+
407
+ const refetch = jest.fn().mockResolvedValue(undefined);
408
+ const col = new RemoteEditableCollection(content, refetch);
409
+
410
+ await col.add();
411
+
412
+ expect(handleAction).toHaveBeenCalledWith(addAction, openingContext);
413
+ });
258
414
  });
259
415
  });
@@ -1,4 +1,4 @@
1
- import { modalStore } from "../";
1
+ import { modalStore, getMenuItemActions } from "../";
2
2
 
3
3
  describe("Modal State", () => {
4
4
  it("should have initial state", () => {
@@ -48,4 +48,33 @@ describe("Modal State", () => {
48
48
  });
49
49
  });
50
50
  });
51
+
52
+ describe("getMenuItemActions", () => {
53
+ it("returns actions array when actions is provided", () => {
54
+ const actions = [{ type: "action1" }, { type: "action2" }];
55
+ const item = { id: "1", title: "Item", actions };
56
+
57
+ expect(getMenuItemActions(item)).toEqual(actions);
58
+ });
59
+
60
+ it("returns [action] when single action is provided", () => {
61
+ const action = { type: "action1" };
62
+ const item = { id: "1", title: "Item", action };
63
+
64
+ expect(getMenuItemActions(item)).toEqual([action]);
65
+ });
66
+
67
+ it("returns action when action is passed as an array", () => {
68
+ const actions = [{ type: "action1" }];
69
+ const item = { id: "1", title: "Item", action: actions as any };
70
+
71
+ expect(getMenuItemActions(item)).toEqual(actions);
72
+ });
73
+
74
+ it("returns empty array when no action or actions are provided", () => {
75
+ expect(getMenuItemActions({ id: "1", title: "Item" })).toEqual([]);
76
+ expect(getMenuItemActions(null)).toEqual([]);
77
+ expect(getMenuItemActions(undefined)).toEqual([]);
78
+ });
79
+ });
51
80
  });
@@ -172,29 +172,6 @@ describe("useBottomSheetContent", () => {
172
172
  expect(viewModel.refetch).toHaveBeenCalledTimes(1);
173
173
  });
174
174
 
175
- it("does not refetch when the item has a submenu", async () => {
176
- const viewModel = createViewModel({
177
- items: [{ title: "Parent" }],
178
- isLoading: false,
179
- });
180
-
181
- const item: MenuItem = {
182
- title: "Parent",
183
- submenu: [{ title: "Child" }],
184
- };
185
-
186
- const { result } = renderHook(() =>
187
- useBottomSheetContent({ viewModel: viewModel as any, onPress })
188
- );
189
-
190
- await act(async () => {
191
- await result.current.handleItemPress(item);
192
- });
193
-
194
- expect(onPress).toHaveBeenCalledWith(item);
195
- expect(viewModel.refetch).not.toHaveBeenCalled();
196
- });
197
-
198
175
  it("does not refetch when the item opens a present submenu action", async () => {
199
176
  const viewModel = createViewModel({
200
177
  items: [{ title: "Parent" }],
@@ -0,0 +1,142 @@
1
+ import { act, renderHook } from "@testing-library/react-native";
2
+
3
+ import { modalStore, useModalStoreState } from "../";
4
+
5
+ const item = { id: "river-general", name: "Test Modal" };
6
+ const props = { entry: { id: "modal-entry-1" } };
7
+
8
+ const openModal = () =>
9
+ act(() => {
10
+ modalStore.getState().openModal({ item, props } as any);
11
+ });
12
+
13
+ // Counts every render of the hook so the tests can assert on subscription
14
+ // behaviour, not just on the returned value.
15
+ const renderModalStoreState = (skipSubscription?: boolean) => {
16
+ const renders = { count: 0 };
17
+
18
+ const view = renderHook(() => {
19
+ renders.count += 1;
20
+
21
+ return skipSubscription === undefined
22
+ ? useModalStoreState()
23
+ : useModalStoreState(skipSubscription);
24
+ });
25
+
26
+ return { ...view, renders };
27
+ };
28
+
29
+ describe("useModalStoreState", () => {
30
+ afterEach(() => {
31
+ act(() => {
32
+ modalStore.getState().dismissModal();
33
+ });
34
+ });
35
+
36
+ describe("when subscribed (default)", () => {
37
+ it("returns the live modal state when called without arguments", () => {
38
+ const { result } = renderModalStoreState();
39
+
40
+ expect(result.current.visible).toBe(false);
41
+
42
+ openModal();
43
+
44
+ expect(result.current.visible).toBe(true);
45
+ expect(result.current.screen).toBe(item);
46
+ expect(result.current.props).toBe(props);
47
+ });
48
+
49
+ it("re-renders the consumer when the modal state changes", () => {
50
+ const { renders } = renderModalStoreState(false);
51
+
52
+ const rendersBeforeOpen = renders.count;
53
+
54
+ openModal();
55
+
56
+ expect(renders.count).toBeGreaterThan(rendersBeforeOpen);
57
+ });
58
+
59
+ // Counterpart to "returns a stable reference across store updates": an open
60
+ // modal is the one point where a live subscription and a skipped one hold
61
+ // different references, which is what makes that assertion meaningful.
62
+ it("returns a new reference while the modal is open", () => {
63
+ const { result } = renderModalStoreState(false);
64
+
65
+ const firstValue = result.current;
66
+
67
+ openModal();
68
+
69
+ expect(result.current).not.toBe(firstValue);
70
+ });
71
+ });
72
+
73
+ describe("when subscription is skipped", () => {
74
+ it("reports an empty modal state even while a modal is open", () => {
75
+ openModal();
76
+
77
+ expect(modalStore.getState().modalState.visible).toBe(true);
78
+
79
+ const { result } = renderModalStoreState(true);
80
+
81
+ expect(result.current).toMatchObject({
82
+ visible: false,
83
+ screen: null,
84
+ options: {},
85
+ props: {},
86
+ });
87
+ });
88
+
89
+ it("does not re-render the consumer when the modal state changes", () => {
90
+ const { renders } = renderModalStoreState(true);
91
+
92
+ const rendersBeforeOpen = renders.count;
93
+
94
+ openModal();
95
+
96
+ expect(renders.count).toBe(rendersBeforeOpen);
97
+ });
98
+
99
+ // The skipped branch has to hand back a module-level constant. Returning a
100
+ // fresh object would fail zustand's Object.is check and re-render on every
101
+ // store notification - the opposite of what skipping is for.
102
+ it("returns a stable reference across store updates", () => {
103
+ const { result } = renderModalStoreState(true);
104
+
105
+ const firstValue = result.current;
106
+
107
+ openModal();
108
+
109
+ // Asserted while the modal is open: dismissing resets the store to the
110
+ // very same initialModalState object, so an end-to-end round trip would
111
+ // hold this identity even for a live subscription.
112
+ expect(result.current).toBe(firstValue);
113
+
114
+ act(() => {
115
+ modalStore.getState().dismissModal();
116
+ });
117
+
118
+ expect(result.current).toBe(firstValue);
119
+ });
120
+ });
121
+
122
+ it("picks up the current modal state when it starts subscribing", () => {
123
+ let skipSubscription = true;
124
+
125
+ const { result, rerender } = renderHook(() =>
126
+ useModalStoreState(skipSubscription)
127
+ );
128
+
129
+ openModal();
130
+
131
+ expect(result.current.visible).toBe(false);
132
+
133
+ skipSubscription = false;
134
+
135
+ act(() => {
136
+ rerender(undefined);
137
+ });
138
+
139
+ expect(result.current.visible).toBe(true);
140
+ expect(result.current.screen).toBe(item);
141
+ });
142
+ });
@@ -25,6 +25,11 @@ export type {
25
25
  SelectionBehavior,
26
26
  } from "./types";
27
27
 
28
- export { isPresentSubMenuAction } from "./types";
28
+ export {
29
+ isPresentSubMenuAction,
30
+ getMenuItemActions,
31
+ OPERATIONS,
32
+ hasOperation,
33
+ } from "./types";
29
34
 
30
35
  export { useBottomSheetContent } from "./useBottomSheetContent";
@@ -98,5 +98,12 @@ export const openBottomSheetModal = ({
98
98
  });
99
99
  };
100
100
 
101
- export const useModalStoreState = (): ModalState =>
102
- useModalStore<ModalState>((state) => state.modalState);
101
+ /**
102
+ * Pass `skipSubscription` from callers that render outside of a modal: the
103
+ * selector then returns the stable `initialModalState` reference, so the
104
+ * component is never re-rendered by modal state it does not read.
105
+ */
106
+ export const useModalStoreState = (skipSubscription = false): ModalState =>
107
+ useModalStore<ModalState>((state) =>
108
+ skipSubscription ? initialModalState : state.modalState
109
+ );
@@ -32,16 +32,15 @@ export interface EntryActionGroup {
32
32
  }
33
33
 
34
34
  export interface MenuItem {
35
- id?: string;
35
+ id: string;
36
36
  title: string;
37
37
  summary?: string;
38
38
  icon?: string;
39
39
  isSelected?: boolean;
40
- // When item represents an audio item, clicking on it will start playback
41
- // and secondary action will allow to add it to queue or playlist
40
+ actions?: (Action | PresentSubMenuAction)[];
41
+ /** @deprecated Use `actions` array instead. Maintained for backwards compatibility. */
42
42
  action?: Action | PresentSubMenuAction;
43
43
  secondaryAction?: SecondaryAction;
44
- submenu?: MenuItem[]; // todo: not needed. Must be replaced with PresentSubMenuAction
45
44
  trailingButton?: any;
46
45
  entryActions?: EntryActionGroup[];
47
46
  }
@@ -71,6 +70,28 @@ export type CollectionScopedOperation = "add" | "clearAll" | "delete";
71
70
  */
72
71
  export type UIOperation = "nowPlaying";
73
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
+
74
95
  export type Operation =
75
96
  | ItemScopedOperation
76
97
  | CollectionScopedOperation
@@ -95,6 +116,11 @@ export interface Content {
95
116
  role?: string;
96
117
  behavior?: SelectionBehavior;
97
118
  dynamicCollection?: DynamicCollectionOptions;
119
+ themePluginId?: string;
120
+ styleOverrides?: Record<string, any>;
121
+ /** Shown under Next Up when the queue sheet has no upcoming items. */
122
+ emptyMessage?: string;
123
+ context?: Record<string, any>;
98
124
  }
99
125
 
100
126
  export interface Menu {
@@ -108,3 +134,29 @@ export function isPresentSubMenuAction(
108
134
  ): action is PresentSubMenuAction {
109
135
  return !!action && typeof action === "object" && "menu" in action;
110
136
  }
137
+
138
+ /**
139
+ * Normalizes an item's action/actions into an array of Action items.
140
+ * Supports canonical `actions: Action[]` and backwards-compatible `action: Action | Action[]`.
141
+ */
142
+ export function getMenuItemActions(
143
+ item?: Partial<MenuItem> | null
144
+ ): (Action | PresentSubMenuAction)[] {
145
+ if (!item) {
146
+ return [];
147
+ }
148
+
149
+ if (Array.isArray(item.actions) && item.actions.length > 0) {
150
+ return item.actions;
151
+ }
152
+
153
+ if (Array.isArray((item as any).action)) {
154
+ return (item as any).action;
155
+ }
156
+
157
+ if (item.action) {
158
+ return [item.action];
159
+ }
160
+
161
+ return [];
162
+ }
@@ -1,14 +1,15 @@
1
- import React, { useState, useEffect } from "react";
1
+ import React, { useCallback, useEffect, useState } from "react";
2
2
  import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
3
3
 
4
- import {
5
- isPresentSubMenuAction,
6
- MenuItem,
7
- modalOrchestrator,
8
- } from "./ModalOrchestrator";
4
+ import { MenuItem, modalOrchestrator } from "./ModalOrchestrator";
9
5
 
10
6
  import { ContentViewModel } from "./ContentViewModel";
11
- import type { SelectionBehavior } from "./types";
7
+ import {
8
+ DynamicCollectionOptions,
9
+ getMenuItemActions,
10
+ isPresentSubMenuAction,
11
+ SelectionBehavior,
12
+ } from "./types";
12
13
  import type { EditableCollection } from "./EditableCollection";
13
14
 
14
15
  type Props = {
@@ -20,14 +21,16 @@ type Return = {
20
21
  items: MenuItem[];
21
22
  isLoading: boolean;
22
23
  error?: Error | string;
23
- showCentralLoading: boolean; // isLoading && items.length === 0
24
- canGoBack: boolean; // modalOrchestrator.canGoBack
24
+ showCentralLoading: boolean;
25
+ canGoBack: boolean;
25
26
  handleItemPress: (item: MenuItem) => Promise<void>;
26
- goBackOrClose: () => void; // canGoBack ? back() : close()
27
- close: () => void; // modalOrchestrator.close()
27
+ goBackOrClose: () => void;
28
+ close: () => void;
28
29
  role?: string;
29
30
  behavior?: SelectionBehavior;
30
- editableCollection?: EditableCollection | null;
31
+ dynamicCollection?: DynamicCollectionOptions;
32
+ editableCollection: EditableCollection | null;
33
+ themePluginId?: string;
31
34
  };
32
35
 
33
36
  export const useBottomSheetContent = (props: Props): Return => {
@@ -35,12 +38,16 @@ export const useBottomSheetContent = (props: Props): Return => {
35
38
 
36
39
  const [state, setState] = useState(viewModel?.getState());
37
40
 
38
- const [editableItems, setEditableItems] = useState<MenuItem[]>([]);
41
+ const [editableItems, setEditableItems] = useState<MenuItem[]>(
42
+ () => viewModel?.getState().items || []
43
+ );
39
44
 
40
45
  // Subscribe to the viewModel state changes
41
46
  useEffect(() => {
42
47
  return viewModel?.subscribe((nextState) => {
43
- setState(nextState);
48
+ setState((state) => {
49
+ return state === nextState ? state : nextState;
50
+ });
44
51
  });
45
52
  }, [viewModel]);
46
53
 
@@ -60,17 +67,19 @@ export const useBottomSheetContent = (props: Props): Return => {
60
67
  * - If the item was a leaf action (not a submenu), triggers viewModel.refetch()
61
68
  * so that checkmarks (isSelected) reflect the updated server state.
62
69
  */
63
- const handleItemPress = async (item: MenuItem) => {
64
- const isSubMenu =
65
- (item.submenu && item.submenu.length > 0) ||
66
- (item.action && isPresentSubMenuAction(item.action));
70
+ const handleItemPress = useCallback(
71
+ async (item: MenuItem) => {
72
+ const actions = getMenuItemActions(item);
73
+ const isSubMenu = actions.some(isPresentSubMenuAction);
67
74
 
68
- await onPress(item);
75
+ await onPress(item);
69
76
 
70
- if (!isSubMenu) {
71
- await viewModel?.refetch();
72
- }
73
- };
77
+ if (!isSubMenu) {
78
+ await viewModel?.refetch();
79
+ }
80
+ },
81
+ [onPress, viewModel]
82
+ );
74
83
 
75
84
  const goBackOrClose = React.useCallback(() => {
76
85
  if (modalOrchestrator.canGoBack) {
@@ -78,7 +87,7 @@ export const useBottomSheetContent = (props: Props): Return => {
78
87
  } else {
79
88
  modalOrchestrator.close();
80
89
  }
81
- }, [modalOrchestrator.canGoBack]);
90
+ }, []);
82
91
 
83
92
  return {
84
93
  items: viewModel?.editableCollection ? editableItems : state?.items,
@@ -90,9 +99,11 @@ export const useBottomSheetContent = (props: Props): Return => {
90
99
  canGoBack: modalOrchestrator.canGoBack,
91
100
  handleItemPress,
92
101
  goBackOrClose,
93
- close: () => modalOrchestrator.close(),
102
+ close: useCallback(() => modalOrchestrator.close(), []),
94
103
  role: state?.role,
95
104
  behavior: state?.behavior,
96
- editableCollection: viewModel?.editableCollection,
105
+ dynamicCollection: state?.dynamicCollection,
106
+ editableCollection: viewModel?.editableCollection || null,
107
+ themePluginId: state?.themePluginId,
97
108
  };
98
109
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-alpha.1052711356",
3
+ "version": "16.0.0-alpha.1054344748",
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": "16.0.0-alpha.1052711356",
30
+ "@applicaster/applicaster-types": "16.0.0-alpha.1054344748",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",