@applicaster/zapp-react-native-utils 16.0.0-alpha.3683430391 → 16.0.0-alpha.4004661200

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 (102) hide show
  1. package/actionsExecutor/ActionExecutor.ts +40 -2
  2. package/actionsExecutor/ActionExecutorContext.tsx +86 -16
  3. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  4. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +22 -0
  5. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  6. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  7. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  8. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
  9. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  10. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +100 -0
  11. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  12. package/actionsExecutor/actions/dismissBottomSheet.ts +22 -0
  13. package/actionsExecutor/actions/goBack.ts +60 -0
  14. package/actionsExecutor/actions/goHome.ts +31 -0
  15. package/actionsExecutor/actions/index.ts +8 -0
  16. package/actionsExecutor/actions/navigateToScreen.ts +18 -4
  17. package/actionsExecutor/actions/openBottomSheet.ts +320 -0
  18. package/actionsExecutor/actions/refreshComponent.ts +6 -0
  19. package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
  20. package/actionsExecutor/actions/showToast.ts +64 -8
  21. package/actionsExecutor/consts.ts +25 -0
  22. package/actionsExecutor/feedDecorator.ts +6 -6
  23. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  24. package/appUtils/HooksManager/index.ts +9 -0
  25. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
  26. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  27. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -0
  28. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  29. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  30. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
  31. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  32. package/appUtils/playerManager/OverlayObserver/utils.ts +54 -20
  33. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  34. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  35. package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
  36. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  37. package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
  38. package/appUtils/playerManager/index.ts +1 -1
  39. package/appUtils/playerManager/player.ts +115 -3
  40. package/appUtils/playerManager/playerFactory.ts +1 -1
  41. package/appUtils/playerManager/playerNative.ts +6 -4
  42. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  43. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  44. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  45. package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
  46. package/arrayUtils/index.ts +79 -0
  47. package/cellUtils/index.ts +30 -3
  48. package/configurationUtils/__tests__/modalBlocksParser.test.ts +107 -0
  49. package/configurationUtils/manifestKeyParser.ts +38 -9
  50. package/configurationUtils/modalBlocksParser.ts +178 -0
  51. package/entryActions/__tests__/buildEntryActions.test.ts +156 -0
  52. package/entryActions/aliasPresentation.ts +124 -0
  53. package/entryActions/buildEntryActions.ts +166 -0
  54. package/entryActions/index.ts +17 -0
  55. package/entryActions/types.ts +39 -0
  56. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  57. package/manifestUtils/_internals/index.js +8 -3
  58. package/manifestUtils/defaultManifestConfigurations/player.js +330 -1
  59. package/manifestUtils/index.js +3 -0
  60. package/manifestUtils/modalBlocks.js +304 -0
  61. package/modalState/ContentViewModel.ts +113 -0
  62. package/modalState/EditableCollection.ts +17 -0
  63. package/modalState/EditableCollectionRegistry.ts +51 -0
  64. package/modalState/ModalOrchestrator.ts +199 -0
  65. package/modalState/RemoteEditableCollection.ts +227 -0
  66. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  67. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  68. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  69. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
  70. package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
  71. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  72. package/modalState/index.ts +30 -83
  73. package/modalState/store.ts +102 -0
  74. package/modalState/types.ts +133 -0
  75. package/modalState/useBottomSheetContent.ts +102 -0
  76. package/package.json +2 -2
  77. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  78. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  79. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  80. package/playerUtils/contentDataKeys.ts +134 -0
  81. package/playerUtils/index.ts +37 -16
  82. package/playerUtils/isAudioItem.ts +26 -0
  83. package/playerUtils/resolvePlayerActions.ts +71 -0
  84. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  85. package/reactHooks/actions/index.ts +67 -2
  86. package/reactHooks/index.ts +2 -0
  87. package/reactHooks/layout/index.ts +1 -1
  88. package/reactHooks/usePluginConfiguration.ts +4 -1
  89. package/reactHooks/utils/__tests__/index.test.js +22 -2
  90. package/reactHooks/utils/index.ts +11 -1
  91. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  92. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  93. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  94. package/uiActionsRegistrator/index.ts +25 -203
  95. package/uiActionsRegistrator/registry.ts +335 -0
  96. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  97. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  98. package/zappFrameworkUtils/localStorageHelper.ts +10 -2
  99. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  100. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  101. package/playerUtils/getPlayerActionButtons.ts +0 -17
  102. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -0,0 +1,100 @@
1
+ import { openBottomSheetAction } from "../openBottomSheet";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+ import { modalOrchestrator } from "../../../modalState/ModalOrchestrator";
4
+
5
+ jest.mock("../../../modalState/store", () => ({
6
+ openBottomSheetModal: jest.fn(),
7
+ }));
8
+
9
+ jest.mock("../../../modalState/ModalOrchestrator", () => ({
10
+ modalOrchestrator: {
11
+ open: jest.fn(),
12
+ replace: jest.fn(),
13
+ stackSize: 0,
14
+ },
15
+ isPresentSubMenuAction: jest.requireActual("../../../modalState/types")
16
+ .isPresentSubMenuAction,
17
+ }));
18
+
19
+ describe("openBottomSheetAction inline items", () => {
20
+ beforeEach(() => {
21
+ jest.clearAllMocks();
22
+ (modalOrchestrator as any).stackSize = 0;
23
+ });
24
+
25
+ const speedSheetAction = {
26
+ type: "openBottomSheet",
27
+ options: {
28
+ header: { title: "Playback Speed" },
29
+ content: {
30
+ role: "collection_selector",
31
+ behavior: {
32
+ selectMode: "single",
33
+ currentSelection: ["1"],
34
+ },
35
+ items: [
36
+ {
37
+ id: "0.8",
38
+ title: "0.8x",
39
+ extensions: {
40
+ tap_actions: {
41
+ actions: [
42
+ { type: "setPlaybackSpeed", options: { value: 0.8 } },
43
+ ],
44
+ },
45
+ },
46
+ },
47
+ {
48
+ id: "1",
49
+ title: "1x",
50
+ extensions: {
51
+ tap_actions: {
52
+ actions: [{ type: "setPlaybackSpeed", options: { value: 1 } }],
53
+ },
54
+ },
55
+ },
56
+ ],
57
+ },
58
+ },
59
+ } as any;
60
+
61
+ it("opens orchestrator with inline items and marks current selection", async () => {
62
+ const result = await openBottomSheetAction(speedSheetAction);
63
+
64
+ expect(result).toBe(ActionResult.Success);
65
+ expect(modalOrchestrator.open).toHaveBeenCalledTimes(1);
66
+ expect(modalOrchestrator.replace).not.toHaveBeenCalled();
67
+
68
+ const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
69
+
70
+ expect(menu.content.items[0].isSelected).toBe(false);
71
+
72
+ expect(menu.content.items[1]).toMatchObject({
73
+ id: "1",
74
+ title: "1x",
75
+ isSelected: true,
76
+ action: { type: "setPlaybackSpeed", options: { value: 1 } },
77
+ });
78
+ });
79
+
80
+ it("pushes a new sheet by default even when another sheet is already open", async () => {
81
+ (modalOrchestrator as any).stackSize = 1;
82
+
83
+ await openBottomSheetAction(speedSheetAction);
84
+
85
+ expect(modalOrchestrator.open).toHaveBeenCalledTimes(1);
86
+ expect(modalOrchestrator.replace).not.toHaveBeenCalled();
87
+ });
88
+
89
+ it("replaces the current sheet when options.replace is true", async () => {
90
+ (modalOrchestrator as any).stackSize = 1;
91
+
92
+ await openBottomSheetAction({
93
+ ...speedSheetAction,
94
+ options: { ...speedSheetAction.options, replace: true },
95
+ });
96
+
97
+ expect(modalOrchestrator.replace).toHaveBeenCalledTimes(1);
98
+ expect(modalOrchestrator.open).not.toHaveBeenCalled();
99
+ });
100
+ });
@@ -0,0 +1,88 @@
1
+ import { showToastAction } from "../showToast";
2
+ import { postEvent } from "../../../reactHooks/useSubscriberFor";
3
+ import { ActionResult } from "../../ActionExecutor";
4
+
5
+ jest.mock("../../../reactHooks/useSubscriberFor", () => ({
6
+ postEvent: jest.fn(),
7
+ }));
8
+
9
+ describe("showToastAction", () => {
10
+ beforeEach(() => {
11
+ jest.clearAllMocks();
12
+ });
13
+
14
+ it("calls postEvent with confirmation source, default timeout, and returns Success", async () => {
15
+ const action = {
16
+ type: "showToast",
17
+ options: {
18
+ id: "toast-1",
19
+ message: "Added to queue",
20
+ extraMessage: "Extra info",
21
+ },
22
+ };
23
+
24
+ const result = await showToastAction(action);
25
+
26
+ expect(postEvent).toHaveBeenCalledTimes(1);
27
+
28
+ expect(postEvent).toHaveBeenCalledWith("showToast", [
29
+ {
30
+ id: "toast-1",
31
+ message: "Added to queue",
32
+ extraMessage: "Extra info",
33
+ style: undefined,
34
+ timeout: 1000,
35
+ source: "confirmation",
36
+ },
37
+ ]);
38
+
39
+ expect(result).toBe(ActionResult.Success);
40
+ });
41
+
42
+ it("preserves an explicit timeout and style override", async () => {
43
+ const action = {
44
+ type: "showToast",
45
+ options: {
46
+ message: "Playlist created",
47
+ timeout: 3000,
48
+ style: { backgroundColor: "#00FF00" },
49
+ },
50
+ };
51
+
52
+ await showToastAction(action);
53
+
54
+ expect(postEvent).toHaveBeenCalledWith("showToast", [
55
+ {
56
+ id: undefined,
57
+ message: "Playlist created",
58
+ extraMessage: undefined,
59
+ style: { backgroundColor: "#00FF00" },
60
+ timeout: 3000,
61
+ source: "confirmation",
62
+ },
63
+ ]);
64
+ });
65
+
66
+ it("handles missing or empty options without throwing", async () => {
67
+ const action = {
68
+ type: "showToast",
69
+ };
70
+
71
+ const result = await showToastAction(action);
72
+
73
+ expect(postEvent).toHaveBeenCalledTimes(1);
74
+
75
+ expect(postEvent).toHaveBeenCalledWith("showToast", [
76
+ {
77
+ id: undefined,
78
+ message: undefined,
79
+ extraMessage: undefined,
80
+ style: undefined,
81
+ timeout: 1000,
82
+ source: "confirmation",
83
+ },
84
+ ]);
85
+
86
+ expect(result).toBe(ActionResult.Success);
87
+ });
88
+ });
@@ -0,0 +1,22 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { dismissModal } from "../../modalState";
3
+ import { ActionResult } from "../ActionExecutor";
4
+ import { ActionHandler } from "../types";
5
+ import { createLogger } from "../../logger";
6
+
7
+ const { log_info } = createLogger({
8
+ subsystem: "ActionExecutorContext",
9
+ category: "General",
10
+ });
11
+
12
+ /**
13
+ * Dismisses the active bottom sheet / modal.
14
+ */
15
+ export const dismissBottomSheetAction: ActionHandler<
16
+ any
17
+ > = async (): Promise<ActionResult> => {
18
+ log_info("handleAction: dismissBottomSheet");
19
+ dismissModal();
20
+
21
+ return ActionResult.Success;
22
+ };
@@ -0,0 +1,60 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler } from "../types";
4
+ import { createLogger } from "../../logger";
5
+
6
+ const { log_info } = createLogger({
7
+ subsystem: "ActionExecutorContext",
8
+ category: "General",
9
+ });
10
+
11
+ /**
12
+ * Options for the goBack action.
13
+ */
14
+ export interface GoBackOptions {
15
+ /**
16
+ * Navigate to the home screen when there is no screen to go back to.
17
+ * Defaults to true.
18
+ */
19
+ fallbackToHome?: boolean;
20
+
21
+ /**
22
+ * Go back to the first screen of the stack instead of the previous one.
23
+ * Defaults to false.
24
+ */
25
+ backToTop?: boolean;
26
+ }
27
+
28
+ /**
29
+ * Creates a go back action handler with the provided dependencies.
30
+ * This factory pattern allows the action to access navigation state at runtime.
31
+ *
32
+ * @param navigator - The app navigator performing the back navigation
33
+ * @returns An action handler that navigates back
34
+ */
35
+ export function createGoBackAction(
36
+ navigator: QuickBrickAppNavigator
37
+ ): ActionHandler<GoBackOptions> {
38
+ return async function goBackAction(action): Promise<ActionResult> {
39
+ const fallbackToHome = action.options?.fallbackToHome ?? true;
40
+ const backToTop = action.options?.backToTop ?? false;
41
+
42
+ // With fallbackToHome on, the navigator goes home on an empty stack by
43
+ // itself. The guard only matters when the caller opted out of that.
44
+ if (!fallbackToHome && !navigator.canGoBack()) {
45
+ log_info(
46
+ "goBack: no screen to go back to and fallbackToHome is disabled, ignoring"
47
+ );
48
+
49
+ return ActionResult.Error;
50
+ }
51
+
52
+ log_info(
53
+ `goBack: navigating back, fallbackToHome: ${fallbackToHome}, backToTop: ${backToTop}`
54
+ );
55
+
56
+ navigator.goBack(fallbackToHome, false, backToTop);
57
+
58
+ return ActionResult.Success;
59
+ };
60
+ }
@@ -0,0 +1,31 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler } from "../types";
4
+ import { createLogger } from "../../logger";
5
+
6
+ const { log_info } = createLogger({
7
+ subsystem: "ActionExecutorContext",
8
+ category: "General",
9
+ });
10
+
11
+ /**
12
+ * Creates a go home action handler with the provided dependencies.
13
+ * This factory pattern allows the action to access navigation state at runtime.
14
+ *
15
+ * The navigator's `initialLaunch` flag is intentionally not exposed: it selects
16
+ * the offline home river during app bootstrap and is not a per-action choice.
17
+ *
18
+ * @param navigator - The app navigator performing the navigation
19
+ * @returns An action handler that navigates to the home screen
20
+ */
21
+ export function createGoHomeAction(
22
+ navigator: QuickBrickAppNavigator
23
+ ): ActionHandler {
24
+ return async function goHomeAction(): Promise<ActionResult> {
25
+ log_info("goHome: navigating to the home screen");
26
+
27
+ navigator.goHome();
28
+
29
+ return ActionResult.Success;
30
+ };
31
+ }
@@ -27,4 +27,12 @@ export { screenToggleFlagAction } from "./screenToggleFlag";
27
27
 
28
28
  export { createNavigateToScreenAction } from "./navigateToScreen";
29
29
 
30
+ export { createGoBackAction } from "./goBack";
31
+
32
+ export { createGoHomeAction } from "./goHome";
33
+
30
34
  export { showToastAction } from "./showToast";
35
+
36
+ export { openBottomSheetAction } from "./openBottomSheet";
37
+
38
+ export { dismissBottomSheetAction } from "./dismissBottomSheet";
@@ -25,6 +25,19 @@ export interface NavigateToScreenOptions {
25
25
  * - undefined to navigate to screen without entry
26
26
  */
27
27
  entry?: "@{entry/}" | ZappEntry;
28
+
29
+ /**
30
+ * Arbitrary values passed through to the destination screen.
31
+ *
32
+ * They are stored on the navigation route as `NavigationScreenData.options`
33
+ * and read on the target screen via `useNavigation().data?.options`. Use this
34
+ * to hand per-navigation parameters to a screen instead of routing them
35
+ * through module-level state.
36
+ *
37
+ * Note: `legacyScreenData()` does not carry these values, so they are not
38
+ * visible through `useCurrentScreenData()` / `useRoute()`.
39
+ */
40
+ navigationOptions?: Record<string, unknown>;
28
41
  }
29
42
 
30
43
  /**
@@ -55,6 +68,7 @@ export function createNavigateToScreenAction(
55
68
 
56
69
  const navigationAction = action.options?.navigationAction;
57
70
  const entrySource = action.options?.entry;
71
+ const navigationOptions = action.options?.navigationOptions;
58
72
 
59
73
  const entry = entrySource
60
74
  ? entrySource === "@{entry/}"
@@ -83,10 +97,10 @@ export function createNavigateToScreenAction(
83
97
  };
84
98
 
85
99
  if (navigationAction === "push") {
86
- navigator.push(overriddenEntry);
100
+ navigator.push(overriddenEntry, navigationOptions);
87
101
  } else {
88
102
  // Use replaceTop for entries since replace() only accepts ZappRiver
89
- navigator.replaceTop(overriddenEntry);
103
+ navigator.replaceTop(overriddenEntry, navigationOptions);
90
104
  }
91
105
 
92
106
  return ActionResult.Success;
@@ -113,9 +127,9 @@ export function createNavigateToScreenAction(
113
127
  context?.callback?.({ success: false, error: null, abort: true });
114
128
 
115
129
  if (navigationAction === "push") {
116
- navigator.push(river);
130
+ navigator.push(river, navigationOptions);
117
131
  } else {
118
- navigator.replace(river);
132
+ navigator.replace(river, navigationOptions);
119
133
  }
120
134
 
121
135
  return ActionResult.Success;
@@ -0,0 +1,320 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import {
3
+ PipesClientResponseHelper,
4
+ RequestBuilder,
5
+ } from "@applicaster/zapp-pipes-v2-client";
6
+ import uuidv4 from "uuid/v4";
7
+ import { modalOrchestrator } from "../../modalState/ModalOrchestrator";
8
+ import { openBottomSheetModal } from "../../modalState/store";
9
+ import {
10
+ DynamicCollectionOptions,
11
+ isPresentSubMenuAction,
12
+ Menu,
13
+ MenuItem,
14
+ Operation,
15
+ SelectionBehavior,
16
+ } from "../../modalState/types";
17
+ import { actionExecutor, ActionResult } from "../ActionExecutor";
18
+ import { createLogger } from "../../logger";
19
+
20
+ const { log_info, log_error } = createLogger({
21
+ subsystem: "ActionExecutorContext",
22
+ category: "General",
23
+ });
24
+
25
+ export type LoadedSheetContent = {
26
+ items: MenuItem[];
27
+ role?: string;
28
+ behavior?: SelectionBehavior;
29
+ dynamicCollection?: DynamicCollectionOptions;
30
+ };
31
+
32
+ /**
33
+ * Parse a raw `dynamic_collection_options` block (feed or inline content) into
34
+ * the typed `DynamicCollectionOptions`. `operations` accepts either a CSV
35
+ * string (feed) or an array (already parsed).
36
+ */
37
+ export function parseDynamicCollectionOptions(
38
+ raw:
39
+ | {
40
+ operations?: string | string[];
41
+ postUrl?: string;
42
+ provider?: string;
43
+ events?: Record<string, any[]>;
44
+ }
45
+ | undefined
46
+ ): DynamicCollectionOptions | undefined {
47
+ if (!raw) {
48
+ return undefined;
49
+ }
50
+
51
+ const operations = Array.isArray(raw.operations)
52
+ ? (raw.operations as Operation[])
53
+ : ((raw.operations || "").split(",").filter(Boolean) as Operation[]);
54
+
55
+ return {
56
+ operations,
57
+ postUrl: raw.postUrl,
58
+ provider: raw.provider,
59
+ events: raw.events,
60
+ };
61
+ }
62
+
63
+ /**
64
+ * Converts a ZappEntry from a pipes feed into a MenuItem.
65
+ * - Icon: first src found in the image media_group.
66
+ * - Primary action: taken from tap_actions.actions[0].
67
+ * - isSelected: true when entry.id is in currentSelection.
68
+ */
69
+ export function entryToMenuItem(
70
+ entry: ZappEntry,
71
+ currentSelection: string[] = []
72
+ ): MenuItem {
73
+ const imageGroup = entry.media_group?.find((g) => g.type === "image");
74
+
75
+ const firstImage = Array.isArray(imageGroup?.media_item)
76
+ ? imageGroup.media_item[0]
77
+ : imageGroup?.media_item;
78
+
79
+ // Primary action — first tap_action on the entry
80
+ const tapActions = entry.extensions?.tap_actions?.actions || [];
81
+ const primaryAction = tapActions.length > 0 ? tapActions[0] : undefined;
82
+
83
+ const summary = entry.summary as string;
84
+
85
+ const itemId = String(entry.id ?? entry.title ?? uuidv4());
86
+
87
+ return {
88
+ id: itemId,
89
+ title: entry.title as string,
90
+ summary,
91
+ icon: firstImage?.src,
92
+ isSelected: currentSelection.includes(itemId),
93
+ action: primaryAction,
94
+ entryActions: entry.extensions?.entry_action || [],
95
+ };
96
+ }
97
+
98
+ function parseCurrentSelection(rawSelection: unknown): string[] {
99
+ if (Array.isArray(rawSelection)) {
100
+ return (rawSelection as any[]).map(String);
101
+ }
102
+
103
+ if (rawSelection !== undefined && rawSelection !== null) {
104
+ return [String(rawSelection)];
105
+ }
106
+
107
+ return [];
108
+ }
109
+
110
+ function parseBehaviorFromFeed(
111
+ feed: ZappFeed | undefined,
112
+ currentSelection: string[]
113
+ ): SelectionBehavior | undefined {
114
+ const raw = feed?.extensions?.behavior;
115
+
116
+ if (!raw && currentSelection.length === 0) {
117
+ return undefined;
118
+ }
119
+
120
+ return {
121
+ selectMode: raw?.select_mode,
122
+ currentSelection,
123
+ selector: raw?.selector,
124
+ };
125
+ }
126
+
127
+ function parseBehaviorFromContentOptions(
128
+ content: Record<string, any> | undefined
129
+ ): SelectionBehavior | undefined {
130
+ const raw = content?.behavior ?? content?.extensions?.behavior;
131
+
132
+ if (!raw) {
133
+ return undefined;
134
+ }
135
+
136
+ return {
137
+ selectMode: raw.selectMode ?? raw.select_mode,
138
+ currentSelection: parseCurrentSelection(
139
+ raw.currentSelection ?? raw.current_selection
140
+ ),
141
+ selector: raw.selector,
142
+ };
143
+ }
144
+
145
+ // Exported so MultiLevelBottomSheetContent can lazy-load sub-levels
146
+ export async function loadItemsFromSource(
147
+ source: string,
148
+ context?: Record<string, any>
149
+ ): Promise<LoadedSheetContent> {
150
+ const requestBuilder = new RequestBuilder()
151
+ .setEntryContext(context?.entry || {})
152
+ .setScreenContext(context?.screenData || {})
153
+ .setUrl(source);
154
+
155
+ await requestBuilder.buildAxiosRequest();
156
+
157
+ const responseData = await requestBuilder.call<ZappFeed>();
158
+
159
+ const responseHelper = new PipesClientResponseHelper(responseData);
160
+
161
+ if (responseHelper.error) {
162
+ throw responseHelper.error;
163
+ }
164
+
165
+ const feed = responseData?.response as ZappFeed;
166
+
167
+ const currentSelection = parseCurrentSelection(
168
+ feed?.extensions?.behavior?.current_selection
169
+ );
170
+
171
+ const items = (feed?.entry || []).map((entry) =>
172
+ entryToMenuItem(entry, currentSelection)
173
+ );
174
+
175
+ const dynamicCollectionOptions = feed?.extensions?.dynamic_collection_options;
176
+
177
+ const dynamicCollection = parseDynamicCollectionOptions(
178
+ dynamicCollectionOptions
179
+ );
180
+
181
+ return {
182
+ items,
183
+ role: feed?.extensions?.role,
184
+ behavior: parseBehaviorFromFeed(feed, currentSelection),
185
+ dynamicCollection,
186
+ };
187
+ }
188
+
189
+ export async function openBottomSheetAction(
190
+ action: ActionType,
191
+ context?: Record<string, any>
192
+ ): Promise<ActionResult> {
193
+ try {
194
+ const { content, header, themePluginId, styleOverrides } =
195
+ action.options || {};
196
+
197
+ // Custom body component — keep default ModalComponent so standard header
198
+ // (dismiss x) is used; content.component is body-only (e.g. TextInputContent).
199
+ if (content?.component) {
200
+ log_info("openBottomSheet: using custom content component");
201
+
202
+ openBottomSheetModal({
203
+ modalBottomSheetContentProps: {
204
+ title: header?.title,
205
+ summary: header?.subtitle,
206
+ items: [],
207
+ onPress: () => {},
208
+ contentComponent: content.component,
209
+ contentComponentProps: content.props || {},
210
+ },
211
+ });
212
+
213
+ return ActionResult.Success;
214
+ }
215
+
216
+ const inlineItems: ZappEntry[] = content?.items;
217
+ const itemsUrl: string = content?.itemsUrl;
218
+
219
+ let items: MenuItem[];
220
+ let role: string | undefined;
221
+ let behavior: SelectionBehavior | undefined;
222
+
223
+ let dynamicCollection: DynamicCollectionOptions | undefined;
224
+
225
+ if (Array.isArray(inlineItems) && inlineItems.length > 0) {
226
+ log_info("openBottomSheet: using inline items from action options", {
227
+ count: inlineItems.length,
228
+ });
229
+
230
+ role = content?.role ?? content?.extensions?.role;
231
+ behavior = parseBehaviorFromContentOptions(content);
232
+
233
+ items = inlineItems.map((entry) =>
234
+ entryToMenuItem(entry, behavior?.currentSelection ?? [])
235
+ );
236
+
237
+ dynamicCollection = parseDynamicCollectionOptions(
238
+ content?.dynamicCollection ??
239
+ content?.extensions?.dynamic_collection_options
240
+ );
241
+ } else if (itemsUrl) {
242
+ log_info(`openBottomSheet: loading items from source: ${itemsUrl}`);
243
+
244
+ const loaded = await loadItemsFromSource(itemsUrl, context);
245
+ items = loaded.items;
246
+ role = loaded.role ?? content?.role ?? content?.extensions?.role;
247
+ behavior = loaded.behavior ?? parseBehaviorFromContentOptions(content);
248
+ dynamicCollection = loaded.dynamicCollection;
249
+
250
+ log_info(
251
+ `openBottomSheet: loaded ${items.length} items from source: ${itemsUrl}`
252
+ );
253
+ } else {
254
+ log_error(
255
+ "openBottomSheet: no itemsUrl, items, or content.component provided in action options"
256
+ );
257
+
258
+ return ActionResult.Error;
259
+ }
260
+
261
+ const menu: Menu = {
262
+ header: header
263
+ ? {
264
+ title: header.title,
265
+ subtitle: header.subtitle,
266
+ icon: header.icon,
267
+ }
268
+ : undefined,
269
+ content: {
270
+ title: content?.title ?? "",
271
+ items,
272
+ itemsUrl, // stored so the component can reload after an action
273
+ role,
274
+ behavior,
275
+ dynamicCollection,
276
+ themePluginId,
277
+ styleOverrides: styleOverrides ?? content?.styleOverrides,
278
+ },
279
+ };
280
+
281
+ /**
282
+ * Called when the user taps a menu item.
283
+ *
284
+ * - PresentSubMenuAction → handled by the orchestrator (pushes sub-menu)
285
+ * - Any other Action type → forwarded to the action executor, keeping the
286
+ * original execution context so screen/entry data is available to handlers.
287
+ * The pressed item is also added as `entry` so downstream actions can
288
+ * reference it.
289
+ */
290
+ const onItemPress = async (item: MenuItem): Promise<void> => {
291
+ if (!item.action || isPresentSubMenuAction(item.action)) {
292
+ // Submenu navigation is handled internally by the orchestrator
293
+ return;
294
+ }
295
+
296
+ await actionExecutor.handleAction(
297
+ item.action as ActionType,
298
+ {
299
+ ...context,
300
+ entry: item as any,
301
+ } as any
302
+ );
303
+ };
304
+
305
+ if (action.options?.replace) {
306
+ modalOrchestrator.replace(menu, onItemPress);
307
+ } else {
308
+ modalOrchestrator.open(menu, onItemPress);
309
+ }
310
+
311
+ return ActionResult.Success;
312
+ } catch (error) {
313
+ log_error("openBottomSheet: failed to open bottom sheet", {
314
+ error,
315
+ action,
316
+ });
317
+
318
+ return ActionResult.Error;
319
+ }
320
+ }
@@ -57,6 +57,12 @@ export const refreshComponentAction: ActionHandler = async (
57
57
  }) || source;
58
58
  }
59
59
 
60
+ if (!dataSource) {
61
+ log_info("handleAction: refreshComponent skipped: no dataSource found");
62
+
63
+ return ActionResult.Success;
64
+ }
65
+
60
66
  log_info(`handleAction: refreshComponent for dataSource:${dataSource}`, {
61
67
  source,
62
68
  inflatedUrl: dataSource,