@applicaster/zapp-react-native-utils 16.0.0-alpha.2480030155 → 16.0.0-alpha.2500443242

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 (142) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +50 -3
  3. package/actionsExecutor/ActionExecutorContext.tsx +99 -17
  4. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  5. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  6. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  7. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  8. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  9. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  10. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +267 -0
  11. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +100 -0
  12. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +300 -0
  13. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  14. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  15. package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
  16. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  17. package/actionsExecutor/actions/goBack.ts +60 -0
  18. package/actionsExecutor/actions/goHome.ts +31 -0
  19. package/actionsExecutor/actions/index.ts +12 -0
  20. package/actionsExecutor/actions/navigateToScreen.ts +43 -45
  21. package/actionsExecutor/actions/openBottomSheet.ts +339 -0
  22. package/actionsExecutor/actions/presentScreen.ts +78 -0
  23. package/actionsExecutor/actions/refreshComponent.ts +6 -0
  24. package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
  25. package/actionsExecutor/actions/showAlert.ts +51 -0
  26. package/actionsExecutor/actions/showToast.ts +2 -2
  27. package/actionsExecutor/consts.ts +27 -0
  28. package/actionsExecutor/feedDecorator.ts +6 -6
  29. package/appUtils/HooksManager/index.ts +9 -0
  30. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +131 -54
  31. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  32. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  33. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  34. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  35. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  36. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  37. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  38. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  39. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  40. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  41. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  42. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -0
  43. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  44. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  45. package/appUtils/playerManager/const.ts +13 -0
  46. package/appUtils/playerManager/index.ts +7 -0
  47. package/appUtils/playerManager/player.ts +124 -2
  48. package/appUtils/playerManager/playerNative.ts +27 -3
  49. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  50. package/appUtils/playerManager/playerToolbox.ts +157 -0
  51. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  52. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
  53. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  54. package/arrayUtils/index.ts +62 -0
  55. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  56. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  57. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  58. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  59. package/cellUtils/index.ts +104 -22
  60. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  61. package/configurationUtils/__tests__/modalBlocksParser.test.ts +392 -0
  62. package/configurationUtils/index.ts +77 -73
  63. package/configurationUtils/manifestKeyParser.ts +50 -10
  64. package/configurationUtils/modalBlocksParser.ts +252 -0
  65. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  66. package/entryActions/aliasPresentation.ts +108 -0
  67. package/entryActions/buildEntryActions.ts +167 -0
  68. package/entryActions/index.ts +15 -0
  69. package/entryActions/types.ts +39 -0
  70. package/focusManager/FocusManager.ts +26 -0
  71. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  72. package/localizationUtils/index.ts +12 -6
  73. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  74. package/logger/xrayToolbox.ts +67 -0
  75. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  76. package/manifestUtils/_internals/index.js +8 -3
  77. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  78. package/manifestUtils/defaultManifestConfigurations/player.js +338 -1
  79. package/manifestUtils/index.js +3 -0
  80. package/manifestUtils/keys.js +6 -1
  81. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  82. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  83. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  84. package/manifestUtils/modalBlocks.js +304 -0
  85. package/modalState/ContentViewModel.ts +113 -0
  86. package/modalState/EditableCollection.ts +17 -0
  87. package/modalState/EditableCollectionRegistry.ts +51 -0
  88. package/modalState/ModalOrchestrator.ts +212 -0
  89. package/modalState/RemoteEditableCollection.ts +235 -0
  90. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  91. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  92. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  93. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +63 -0
  94. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  95. package/modalState/__tests__/index.test.ts +30 -1
  96. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  97. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  98. package/modalState/index.ts +35 -83
  99. package/modalState/store.ts +109 -0
  100. package/modalState/types.ts +162 -0
  101. package/modalState/useBottomSheetContent.ts +109 -0
  102. package/navigationUtils/xrayNavigator.ts +12 -0
  103. package/package.json +2 -2
  104. package/perfTracker.ts +206 -0
  105. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  106. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  107. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  108. package/playerUtils/contentDataKeys.ts +134 -0
  109. package/playerUtils/index.ts +37 -16
  110. package/playerUtils/isAudioItem.ts +26 -0
  111. package/playerUtils/resolvePlayerActions.ts +71 -0
  112. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  113. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  114. package/pluginUtils/index.ts +29 -0
  115. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  116. package/reactHooks/actions/index.ts +67 -2
  117. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  118. package/reactHooks/cell-click/index.ts +21 -14
  119. package/reactHooks/connection/index.tsx +8 -5
  120. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  121. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  122. package/reactHooks/index.ts +2 -0
  123. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  124. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  125. package/reactHooks/navigation/index.ts +2 -0
  126. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  127. package/reactHooks/navigation/useRoute.ts +22 -5
  128. package/reactHooks/usePluginConfiguration.ts +88 -47
  129. package/reactHooks/utils/__tests__/index.test.js +22 -2
  130. package/reactHooks/utils/index.ts +11 -1
  131. package/riverComponetsMeasurementProvider/index.tsx +8 -1
  132. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  133. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  134. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  135. package/uiActionsRegistrator/index.ts +25 -203
  136. package/uiActionsRegistrator/registry.ts +351 -0
  137. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  138. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  139. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  140. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  141. package/playerUtils/getPlayerActionButtons.ts +0 -17
  142. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -0,0 +1,157 @@
1
+ import { registerXrayToolbox, XrayToolSpec } from "../../logger/xrayToolbox";
2
+ import type { PlayerManager } from "./index";
3
+
4
+ /**
5
+ * X-Ray `player.*` toolbox: lets an agent read and drive the active player without screenshots.
6
+ * Registered by the PlayerManager singleton itself, so it exists wherever players do. Skipped
7
+ * when the installed X-Ray plugin has no React toolbox API.
8
+ *
9
+ * How the player is shown (video modal mode, mini player) is navigation state: see `nav.*`.
10
+ */
11
+
12
+ const toNumber = (value: unknown) =>
13
+ typeof value === "number" && Number.isFinite(value) ? value : null;
14
+
15
+ const clamp = (value: number, max: number) => Math.min(Math.max(value, 0), max);
16
+
17
+ /** The range a seek can reach: the DVR window on live, the content on VOD. */
18
+ const requireSeekable = (player: {
19
+ getSeekableDuration: () => number | undefined;
20
+ }) => {
21
+ const seekable = toNumber(player.getSeekableDuration());
22
+
23
+ if (!seekable) throw new Error("Seek is not supported");
24
+
25
+ return seekable;
26
+ };
27
+
28
+ const tools = (manager: PlayerManager): XrayToolSpec[] => {
29
+ const requirePlayer = () => {
30
+ const player = manager.getActivePlayer();
31
+
32
+ if (!player) throw new Error("No active player");
33
+
34
+ return player;
35
+ };
36
+
37
+ return [
38
+ {
39
+ name: "state",
40
+ description:
41
+ "The active player: entry, position and duration in seconds, playing/buffering/ad/live/muted, " +
42
+ "role (Primary, Cell, Chromecast) and casting. active: false when nothing plays.",
43
+ handler: () => {
44
+ const player = manager.getActivePlayer();
45
+
46
+ if (!player) return { active: false, casting: manager.isCasting() };
47
+
48
+ const entry = player.getEntry();
49
+
50
+ return {
51
+ active: true,
52
+ playerId: player.playerId,
53
+ entry: entry ? { id: entry.id, title: entry.title } : null,
54
+ position: toNumber(player.getPosition()),
55
+ duration: toNumber(player.getDuration()),
56
+ // isPlaying() only means "not paused", which is also true before the stream starts.
57
+ playing: !!player.isReadyToPlay() && player.isPlaying(),
58
+ buffering: !!player.isBuffering(),
59
+ readyToPlay: !!player.isReadyToPlay(),
60
+ ad: player.isAd(),
61
+ live: !!player.isLive(),
62
+ muted: !!player.getIsMuted(),
63
+ role: player.playerRole,
64
+ casting: manager.isCasting(),
65
+ };
66
+ },
67
+ },
68
+ {
69
+ name: "play",
70
+ description: "Resume the active player.",
71
+ handler: () => {
72
+ requirePlayer().play();
73
+
74
+ return "OK";
75
+ },
76
+ },
77
+ {
78
+ name: "pause",
79
+ description: "Pause the active player.",
80
+ handler: () => {
81
+ requirePlayer().pause();
82
+
83
+ return "OK";
84
+ },
85
+ },
86
+ {
87
+ name: "seek",
88
+ description:
89
+ "Seek to an absolute position, as the player's console command does: seconds from the start, " +
90
+ "or from the end when negative. Clamped to the seekable range. Where it lands can differ: " +
91
+ "server-side ads snap back to the break before the target; read player.state afterwards.",
92
+ parameters: [
93
+ {
94
+ name: "position",
95
+ type: "number",
96
+ description:
97
+ "Seconds from the start; negative values count back from the end.",
98
+ },
99
+ ],
100
+ handler: ({ position }) => {
101
+ const player = requirePlayer();
102
+ const seconds = toNumber(position);
103
+
104
+ if (seconds === null) {
105
+ throw new Error("'position' must be a number of seconds");
106
+ }
107
+
108
+ const seekable = requireSeekable(player);
109
+
110
+ const target =
111
+ seconds >= 0
112
+ ? Math.min(seconds, seekable)
113
+ : clamp(seekable + seconds, seekable);
114
+
115
+ player.seekTo(target);
116
+
117
+ return { position: target };
118
+ },
119
+ },
120
+ {
121
+ name: "offset",
122
+ description:
123
+ "Seek relative to the current position, as the player's console command does: positive " +
124
+ "forward, negative back. Clamped to the seekable range.",
125
+ parameters: [
126
+ {
127
+ name: "seconds",
128
+ type: "number",
129
+ description: "Seconds to move: positive forward, negative back.",
130
+ },
131
+ ],
132
+ handler: ({ seconds }) => {
133
+ const player = requirePlayer();
134
+ const delta = toNumber(seconds);
135
+
136
+ if (delta === null) throw new Error("'seconds' must be a number");
137
+
138
+ if (delta === 0) throw new Error("Ignored zero relative seek");
139
+
140
+ const seekable = requireSeekable(player);
141
+ const from = toNumber(player.getContentPosition()) ?? 0;
142
+ const target = clamp(from + delta, seekable);
143
+
144
+ player.seekTo(target);
145
+
146
+ return { from, position: target };
147
+ },
148
+ },
149
+ ];
150
+ };
151
+
152
+ export const registerPlayerToolbox = (manager: PlayerManager) =>
153
+ registerXrayToolbox({
154
+ name: "player",
155
+ description: "Inspect and control the active player.",
156
+ tools: tools(manager),
157
+ });
@@ -0,0 +1,43 @@
1
+ import * as React from "react";
2
+ import { Player, PlayerContent } from "./player";
3
+ import { usePlayer } from "./usePlayer";
4
+
5
+ const EMPTY_CONTENT: PlayerContent = {
6
+ title: null,
7
+ summary: null,
8
+ imageUrl: null,
9
+ };
10
+
11
+ /**
12
+ * Subscribes to the player's resolved Title/Subtitle, the same way
13
+ * `usePlayerState` subscribes to playback state. Modeled on that hook
14
+ * deliberately: one React bridge pattern for everything the manager publishes.
15
+ *
16
+ * Passing no `playerId` uses the active player, which is the right default -
17
+ * only one player instance is live at a time. `usePlayer` additionally swaps
18
+ * to the casting receiver while casting, so this follows cast handover
19
+ * automatically.
20
+ */
21
+ export const usePlayerContent = (playerId?: string): PlayerContent => {
22
+ const player: Player = usePlayer(playerId);
23
+
24
+ const [content, setContent] = React.useState<PlayerContent>(
25
+ () => player?.getContent() ?? EMPTY_CONTENT
26
+ );
27
+
28
+ React.useEffect(() => {
29
+ if (!player) {
30
+ setContent(EMPTY_CONTENT);
31
+
32
+ return;
33
+ }
34
+
35
+ const subscription = player
36
+ .getContentObservable()
37
+ .subscribe((next) => setContent(next));
38
+
39
+ return () => subscription.unsubscribe();
40
+ }, [player]);
41
+
42
+ return content;
43
+ };
@@ -8,6 +8,7 @@ import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/
8
8
  import { TVSeekController } from "../../reactHooks/player/TVSeekControlller/TVSeekController";
9
9
  import { KeyInputHandler } from "../keyInputHandler/KeyInputHandler";
10
10
  import { isTV } from "../../reactUtils";
11
+ import { PlayerAnalyticsManager } from "../../analyticsUtils/PlayerAnalyticsManager";
11
12
 
12
13
  // TODO: Rename to ControllerType
13
14
  export const usePlayerControllerSetup = ({
@@ -68,6 +69,11 @@ export const usePlayerControllerSetup = ({
68
69
  return;
69
70
  }
70
71
 
72
+ // The analytics manager attaches its listener when a player registers, so it
73
+ // must exist first; on web the Player wrapper that also creates it renders
74
+ // only after the lazily loaded engine chunk, i.e. after registration.
75
+ PlayerAnalyticsManager.getInstance();
76
+
71
77
  playerManager.registerPlayer({
72
78
  id: playerId,
73
79
  playerController,
@@ -0,0 +1,63 @@
1
+ import { reorderByIds } from "../index";
2
+
3
+ describe("reorderByIds", () => {
4
+ const items = [
5
+ { id: "1", title: "Track 1" },
6
+ { id: "2", title: "Track 2" },
7
+ { id: "3", title: "Track 3" },
8
+ { id: "4", title: "Track 4" },
9
+ ];
10
+
11
+ it("returns an empty array if items is empty or nullish", () => {
12
+ expect(reorderByIds([], ["1"])).toEqual([]);
13
+ expect(reorderByIds(null as any, ["1"])).toEqual([]);
14
+ });
15
+
16
+ it("returns a copy of items if orderedIds is empty or nullish", () => {
17
+ expect(reorderByIds(items, [])).toEqual(items);
18
+ expect(reorderByIds(items, null as any)).toEqual(items);
19
+ });
20
+
21
+ it("reorders items based on the provided orderedIds sequence", () => {
22
+ const result = reorderByIds(items, ["3", "1", "4", "2"]);
23
+
24
+ expect(result.map((i) => i.id)).toEqual(["3", "1", "4", "2"]);
25
+ });
26
+
27
+ it("replaces items in their original slots when reordering a subset", () => {
28
+ const result = reorderByIds(items, ["4", "2"]);
29
+
30
+ expect(result.map((i) => i.id)).toEqual(["1", "4", "3", "2"]);
31
+ });
32
+
33
+ it("ignores IDs in orderedIds that do not exist in items", () => {
34
+ const result = reorderByIds(items, ["unknown", "3", "99", "1"]);
35
+
36
+ expect(result.map((i) => i.id)).toEqual(["3", "2", "1", "4"]);
37
+ });
38
+
39
+ it("supports custom getId selector function", () => {
40
+ const customItems = [
41
+ { key: "a", name: "Alpha" },
42
+ { key: "b", name: "Beta" },
43
+ { key: "c", name: "Gamma" },
44
+ ];
45
+
46
+ const result = reorderByIds(customItems, ["c", "a"], (item) => item.key);
47
+
48
+ expect(result.map((i) => i.key)).toEqual(["c", "b", "a"]);
49
+ });
50
+
51
+ it("reorders duplicate items when using unique slot identifiers via getId", () => {
52
+ const duplicateItems = [
53
+ { id: "x", slot: "s1", name: "First X" },
54
+ { id: "y", slot: "s2", name: "Y" },
55
+ { id: "x", slot: "s3", name: "Second X" },
56
+ ];
57
+
58
+ const result = reorderByIds(duplicateItems, ["s3", "s1"], (i) => i.slot);
59
+
60
+ expect(result).toHaveLength(3);
61
+ expect(result.map((i) => i.name)).toEqual(["Second X", "Y", "First X"]);
62
+ });
63
+ });
@@ -158,3 +158,65 @@ export const allTruthy = (xs: boolean[]) =>
158
158
 
159
159
  /** Returns `true` when at least one value in `xs` is truthy. */
160
160
  export const anyTruthy = (xs: boolean[]) => xs.some(Boolean);
161
+
162
+ /**
163
+ * Reorders `items` based on an ordered array of IDs (`orderedIds`).
164
+ * Items whose IDs are in `orderedIds` appear first in that exact sequence.
165
+ * Any remaining items not present in `orderedIds` are appended at the end preserving their relative order.
166
+ */
167
+ export function reorderByIds<T>(
168
+ items: T[],
169
+ orderedIds: string[],
170
+ getId: (item: T) => string = (item: any) => item?.id
171
+ ): T[] {
172
+ if (!items || items.length === 0) return [];
173
+ if (!orderedIds || orderedIds.length === 0) return [...items];
174
+
175
+ const itemMap = new Map<string, T>();
176
+
177
+ items.forEach((item) => {
178
+ const id = getId(item);
179
+
180
+ if (
181
+ id !== undefined &&
182
+ id !== null &&
183
+ id !== "" &&
184
+ !itemMap.has(String(id))
185
+ ) {
186
+ itemMap.set(String(id), item);
187
+ }
188
+ });
189
+
190
+ const reorderedSubset: T[] = [];
191
+ const orderedIdsSet = new Set<string>();
192
+
193
+ orderedIds.forEach((id) => {
194
+ const strId = String(id);
195
+ const item = itemMap.get(strId);
196
+
197
+ if (item && !orderedIdsSet.has(strId)) {
198
+ reorderedSubset.push(item);
199
+ orderedIdsSet.add(strId);
200
+ }
201
+ });
202
+
203
+ if (reorderedSubset.length === 0) return [...items];
204
+
205
+ let subsetIdx = 0;
206
+
207
+ return items.map((item) => {
208
+ const id = getId(item);
209
+
210
+ if (
211
+ id !== undefined &&
212
+ id !== null &&
213
+ id !== "" &&
214
+ orderedIdsSet.has(String(id)) &&
215
+ subsetIdx < reorderedSubset.length
216
+ ) {
217
+ return reorderedSubset[subsetIdx++];
218
+ }
219
+
220
+ return item;
221
+ });
222
+ }
@@ -0,0 +1,28 @@
1
+ import { getButtonsEnabled } from "..";
2
+
3
+ describe("getButtonsEnabled", () => {
4
+ it("returns true when the buttons container is enabled", () => {
5
+ expect(
6
+ getButtonsEnabled({ mobile_buttons_container_buttons_enabled: true })
7
+ ).toBe(true);
8
+
9
+ expect(
10
+ getButtonsEnabled({ mobile_buttons_container_buttons_enabled: "true" })
11
+ ).toBe(true);
12
+ });
13
+
14
+ it("returns false when the buttons container is disabled", () => {
15
+ expect(
16
+ getButtonsEnabled({ mobile_buttons_container_buttons_enabled: false })
17
+ ).toBe(false);
18
+
19
+ expect(
20
+ getButtonsEnabled({ mobile_buttons_container_buttons_enabled: "false" })
21
+ ).toBe(false);
22
+ });
23
+
24
+ it("returns false when the key or styles are missing", () => {
25
+ expect(getButtonsEnabled({})).toBe(false);
26
+ expect(getButtonsEnabled(undefined)).toBe(false);
27
+ });
28
+ });
@@ -0,0 +1,36 @@
1
+ import { getCellNavigationEnabled } from "..";
2
+
3
+ describe("getCellNavigationEnabled", () => {
4
+ it("returns true when cell navigation is enabled", () => {
5
+ expect(
6
+ getCellNavigationEnabled({
7
+ mobile_buttons_container_cell_navigation_enabled: true,
8
+ })
9
+ ).toBe(true);
10
+
11
+ expect(
12
+ getCellNavigationEnabled({
13
+ mobile_buttons_container_cell_navigation_enabled: "true",
14
+ })
15
+ ).toBe(true);
16
+ });
17
+
18
+ it("returns false when cell navigation is disabled", () => {
19
+ expect(
20
+ getCellNavigationEnabled({
21
+ mobile_buttons_container_cell_navigation_enabled: false,
22
+ })
23
+ ).toBe(false);
24
+
25
+ expect(
26
+ getCellNavigationEnabled({
27
+ mobile_buttons_container_cell_navigation_enabled: "false",
28
+ })
29
+ ).toBe(false);
30
+ });
31
+
32
+ it("returns false when the key or styles are missing", () => {
33
+ expect(getCellNavigationEnabled({})).toBe(false);
34
+ expect(getCellNavigationEnabled(undefined)).toBe(false);
35
+ });
36
+ });
@@ -0,0 +1,35 @@
1
+ import { getIsCellNavigationEnabled } from "..";
2
+
3
+ describe("getIsCellNavigationEnabled", () => {
4
+ it("is disabled when buttons are enabled and cell navigation is off", () => {
5
+ expect(
6
+ getIsCellNavigationEnabled({
7
+ mobile_buttons_container_buttons_enabled: true,
8
+ mobile_buttons_container_cell_navigation_enabled: false,
9
+ })
10
+ ).toBe(false);
11
+ });
12
+
13
+ it("is enabled when buttons and cell navigation are both on", () => {
14
+ expect(
15
+ getIsCellNavigationEnabled({
16
+ mobile_buttons_container_buttons_enabled: true,
17
+ mobile_buttons_container_cell_navigation_enabled: true,
18
+ })
19
+ ).toBe(true);
20
+ });
21
+
22
+ it("is enabled when buttons are disabled", () => {
23
+ expect(
24
+ getIsCellNavigationEnabled({
25
+ mobile_buttons_container_buttons_enabled: false,
26
+ mobile_buttons_container_cell_navigation_enabled: false,
27
+ })
28
+ ).toBe(true);
29
+ });
30
+
31
+ it("is enabled when the keys or styles are missing", () => {
32
+ expect(getIsCellNavigationEnabled({})).toBe(true);
33
+ expect(getIsCellNavigationEnabled(undefined)).toBe(true);
34
+ });
35
+ });
@@ -0,0 +1,21 @@
1
+ import { isCellNavigationEnabled } from "..";
2
+
3
+ describe("isCellNavigationEnabled", () => {
4
+ it("is enabled when buttons are disabled, regardless of the toggle", () => {
5
+ expect(isCellNavigationEnabled(false, false)).toBe(true);
6
+ expect(isCellNavigationEnabled(false, true)).toBe(true);
7
+ expect(isCellNavigationEnabled(undefined, undefined)).toBe(true);
8
+ expect(isCellNavigationEnabled("false", false)).toBe(true);
9
+ });
10
+
11
+ it("is disabled when buttons are enabled and the toggle is off or missing", () => {
12
+ expect(isCellNavigationEnabled(true, false)).toBe(false);
13
+ expect(isCellNavigationEnabled(true, undefined)).toBe(false);
14
+ expect(isCellNavigationEnabled("true", "false")).toBe(false);
15
+ });
16
+
17
+ it("is enabled when buttons and the toggle are both enabled", () => {
18
+ expect(isCellNavigationEnabled(true, true)).toBe(true);
19
+ expect(isCellNavigationEnabled("true", "true")).toBe(true);
20
+ });
21
+ });
@@ -12,6 +12,7 @@ import { isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
12
12
  import { isNotNil } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
13
13
 
14
14
  import { toNumberWithDefault, toNumberWithDefaultZero } from "../numberUtils";
15
+ import { isTrue } from "../booleanUtils";
15
16
 
16
17
  const CUSTOM_KEY = "other";
17
18
 
@@ -65,11 +66,38 @@ export const isEmptyOrNil = (value: any): boolean =>
65
66
  */
66
67
  export const getLabel = (dataKeyValue, customDataKeyValue) => (entry) => {
67
68
  const label = getKeyForLabel(dataKeyValue, customDataKeyValue);
68
- const isPath = label && R.length(label) > 0;
69
- const fallback = isEmptyOrNil(label) ? "" : R.head(label);
69
+ const isPath = label && label.length > 0;
70
+
71
+ // An unresolved key is rendered as-is, because a data key is allowed to be a
72
+ // literal label ("More") rather than a path. Fall back to the whole key
73
+ // instead of its first segment: "extensions.section" reads as an unresolved
74
+ // path, while "extensions" reads as a legitimate label and hides the problem.
75
+ const fallback = isEmptyOrNil(label) ? "" : label.join(".");
70
76
 
71
77
  try {
72
- return isPath ? R.pathOr(fallback, label, entry) : fallback;
78
+ if (!isPath) {
79
+ return fallback;
80
+ }
81
+
82
+ const resolved = label.reduce(
83
+ (value, key) => (value == null ? undefined : value[key]),
84
+ entry
85
+ );
86
+
87
+ if (isNotNil(resolved)) {
88
+ return resolved;
89
+ }
90
+
91
+ // A multi-segment key is unambiguously a path, so failing to resolve it is
92
+ // a misconfiguration rather than someone typing a literal label.
93
+ if (label.length > 1) {
94
+ cellUtilsLogger.warning({
95
+ message: `getLabel: data key "${fallback}" was not found on the entry, rendering the key itself`,
96
+ data: { dataKeyValue, customDataKeyValue, entryId: entry?.id },
97
+ });
98
+ }
99
+
100
+ return fallback;
73
101
  } catch (error) {
74
102
  cellUtilsLogger.warning({
75
103
  data: { error, dataKeyValue, customDataKeyValue },
@@ -165,14 +193,19 @@ export const textTransform = (transformType, value) => {
165
193
  */
166
194
  export const getCellWidth = (componentStyles) => {
167
195
  const DEFAULT_CELL_WIDTH = 1920;
196
+ if (!componentStyles) return DEFAULT_CELL_WIDTH;
168
197
 
169
- const cellWidth = R.compose(
170
- R.prop(R.__, componentStyles),
171
- R.find(R.includes("cell_width")),
172
- R.keys
173
- )(componentStyles);
198
+ for (const key in componentStyles) {
199
+ if (key.includes("cell_width")) {
200
+ const val = Number(componentStyles[key]);
174
201
 
175
- return Number(cellWidth) || DEFAULT_CELL_WIDTH;
202
+ if (!isNaN(val) && val > 0) {
203
+ return val;
204
+ }
205
+ }
206
+ }
207
+
208
+ return DEFAULT_CELL_WIDTH;
176
209
  };
177
210
 
178
211
  /**
@@ -183,7 +216,7 @@ export const getCellWidth = (componentStyles) => {
183
216
  */
184
217
  export const getHeight = (width, aspectRatio) => {
185
218
  const DEFAULT_CELL_HEIGHT = 216;
186
- const height = R.divide(width, aspectRatio);
219
+ const height = width / aspectRatio;
187
220
 
188
221
  return toNumberWithDefault(DEFAULT_CELL_HEIGHT, height);
189
222
  };
@@ -335,14 +368,18 @@ export const ifElseFocusedSelected = (
335
368
  */
336
369
 
337
370
  export const getValue = (stylesObj) => (key) => {
338
- return R.propOr(null, key, stylesObj);
371
+ if (!stylesObj) return null;
372
+ const val = stylesObj[key];
373
+
374
+ return val === undefined ? null : val;
339
375
  };
340
376
 
341
377
  export const CELL_CONFIG_ID_PATH = ["styles", "cell_plugin_configuration_id"];
342
378
 
343
- export const getCellConfigPath = R.path(CELL_CONFIG_ID_PATH);
379
+ export const getCellConfigPath = (component) =>
380
+ component?.styles?.cell_plugin_configuration_id;
344
381
 
345
- export const getPropComponentType = R.prop("component_type");
382
+ export const getPropComponentType = (component) => component?.component_type;
346
383
 
347
384
  /**
348
385
  *
@@ -396,14 +433,11 @@ export const castAndFallbackNumber = toNumberWithDefaultZero;
396
433
 
397
434
  const DEFAULT_COLOR = "#FFFFFF";
398
435
 
399
- export const castAndFallbackColor = R.ifElse(
400
- R.isNil,
401
- R.always(DEFAULT_COLOR),
402
- fixColorHexCode
403
- );
436
+ export const castAndFallbackColor = (value) =>
437
+ value == null ? DEFAULT_COLOR : fixColorHexCode(value);
404
438
 
405
439
  export const getTextTransform = (textTransform: string) => {
406
- if (R.isNil(textTransform) || R.isEmpty(textTransform)) {
440
+ if (!textTransform) {
407
441
  return "none";
408
442
  }
409
443
 
@@ -427,15 +461,24 @@ export const withAntialising = () => {
427
461
 
428
462
  export const compact = (xs) => xs.filter(isNotNil);
429
463
 
430
- export const mergeConfiguration = (configuration, config) =>
431
- R.evolve({ configuration }, config);
464
+ export const mergeConfiguration = (configuration, config) => {
465
+ if (!config) return config;
466
+
467
+ return {
468
+ ...config,
469
+ configuration:
470
+ typeof configuration === "function"
471
+ ? configuration(config.configuration)
472
+ : configuration,
473
+ };
474
+ };
432
475
 
433
476
  export const extractCellConfiguration =
434
477
  (manifestConfiguration) => (component, cellStyles) => {
435
478
  const cellConfigId = getCellConfigPath(component);
436
479
  const componentType = getPropComponentType(component);
437
480
 
438
- const cellStylesConfig = Object.assign(cellStyles[cellConfigId], {
481
+ const cellStylesConfig = Object.assign({}, cellStyles?.[cellConfigId], {
439
482
  componentType,
440
483
  });
441
484
 
@@ -545,3 +588,42 @@ export const hasTextLabelsEnabled = (
545
588
  return Boolean(value);
546
589
  });
547
590
  };
591
+
592
+ /**
593
+ * Reads the mobile buttons container "buttons enabled" switch from cell styles.
594
+ */
595
+ export const getButtonsEnabled = (styles?: Record<string, any>): boolean => {
596
+ return isTrue(styles?.mobile_buttons_container_buttons_enabled);
597
+ };
598
+
599
+ /**
600
+ * Reads the mobile buttons container "cell navigation enabled" switch from cell styles.
601
+ */
602
+ export const getCellNavigationEnabled = (
603
+ styles?: Record<string, any>
604
+ ): boolean => {
605
+ return isTrue(styles?.mobile_buttons_container_cell_navigation_enabled);
606
+ };
607
+
608
+ /**
609
+ * Whether tapping a cell outside its action buttons triggers the cell's navigation.
610
+ * Always true when the buttons are disabled.
611
+ * @param buttonsEnabled the cell's "buttons enabled" switch value
612
+ * @param cellNavigationEnabled the cell's "cell navigation enabled" switch value
613
+ */
614
+ export const isCellNavigationEnabled = (
615
+ buttonsEnabled: unknown,
616
+ cellNavigationEnabled: unknown
617
+ ): boolean => !isTrue(buttonsEnabled) || isTrue(cellNavigationEnabled);
618
+
619
+ /**
620
+ * Whether tapping a mobile cell outside its action buttons triggers the cell's navigation,
621
+ * read from the cell styles.
622
+ */
623
+ export const getIsCellNavigationEnabled = (
624
+ styles?: Record<string, any>
625
+ ): boolean =>
626
+ isCellNavigationEnabled(
627
+ getButtonsEnabled(styles),
628
+ getCellNavigationEnabled(styles)
629
+ );