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

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 (146) 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 +88 -0
  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 +64 -8
  27. package/actionsExecutor/consts.ts +27 -0
  28. package/actionsExecutor/feedDecorator.ts +6 -6
  29. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  30. package/appUtils/HooksManager/index.ts +9 -0
  31. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
  32. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  33. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  34. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  35. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  36. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  37. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  38. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  39. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  40. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  41. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  42. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  43. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  44. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -0
  45. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  46. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  47. package/appUtils/playerManager/{conts.ts → const.ts} +33 -0
  48. package/appUtils/playerManager/index.ts +8 -1
  49. package/appUtils/playerManager/player.ts +125 -3
  50. package/appUtils/playerManager/playerFactory.ts +1 -1
  51. package/appUtils/playerManager/playerNative.ts +28 -4
  52. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  53. package/appUtils/playerManager/playerToolbox.ts +157 -0
  54. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  55. package/appUtils/playerManager/usePlayerControllerSetup.tsx +7 -1
  56. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  57. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  58. package/arrayUtils/index.ts +62 -0
  59. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  60. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  61. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  62. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  63. package/cellUtils/index.ts +70 -3
  64. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  65. package/configurationUtils/__tests__/modalBlocksParser.test.ts +392 -0
  66. package/configurationUtils/manifestKeyParser.ts +50 -10
  67. package/configurationUtils/modalBlocksParser.ts +252 -0
  68. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  69. package/entryActions/aliasPresentation.ts +108 -0
  70. package/entryActions/buildEntryActions.ts +167 -0
  71. package/entryActions/index.ts +15 -0
  72. package/entryActions/types.ts +39 -0
  73. package/focusManager/FocusManager.ts +26 -0
  74. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  75. package/localizationUtils/index.ts +12 -6
  76. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  77. package/logger/xrayToolbox.ts +67 -0
  78. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  79. package/manifestUtils/_internals/index.js +8 -3
  80. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  81. package/manifestUtils/defaultManifestConfigurations/player.js +338 -1
  82. package/manifestUtils/index.js +3 -0
  83. package/manifestUtils/keys.js +6 -1
  84. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  85. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  86. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  87. package/manifestUtils/modalBlocks.js +304 -0
  88. package/modalState/ContentViewModel.ts +113 -0
  89. package/modalState/EditableCollection.ts +17 -0
  90. package/modalState/EditableCollectionRegistry.ts +51 -0
  91. package/modalState/ModalOrchestrator.ts +212 -0
  92. package/modalState/RemoteEditableCollection.ts +235 -0
  93. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  94. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  95. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  96. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +63 -0
  97. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  98. package/modalState/__tests__/index.test.ts +30 -1
  99. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  100. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  101. package/modalState/index.ts +35 -83
  102. package/modalState/store.ts +109 -0
  103. package/modalState/types.ts +162 -0
  104. package/modalState/useBottomSheetContent.ts +109 -0
  105. package/navigationUtils/xrayNavigator.ts +12 -0
  106. package/package.json +2 -2
  107. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  108. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  109. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  110. package/playerUtils/contentDataKeys.ts +134 -0
  111. package/playerUtils/index.ts +37 -16
  112. package/playerUtils/isAudioItem.ts +26 -0
  113. package/playerUtils/resolvePlayerActions.ts +71 -0
  114. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  115. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  116. package/pluginUtils/index.ts +29 -0
  117. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  118. package/reactHooks/actions/index.ts +67 -2
  119. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  120. package/reactHooks/cell-click/index.ts +21 -14
  121. package/reactHooks/connection/index.tsx +8 -5
  122. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  123. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  124. package/reactHooks/index.ts +2 -0
  125. package/reactHooks/layout/index.ts +1 -1
  126. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  127. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  128. package/reactHooks/navigation/index.ts +2 -0
  129. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  130. package/reactHooks/navigation/useRoute.ts +22 -5
  131. package/reactHooks/usePluginConfiguration.ts +88 -47
  132. package/reactHooks/utils/__tests__/index.test.js +22 -2
  133. package/reactHooks/utils/index.ts +11 -1
  134. package/riverComponetsMeasurementProvider/index.tsx +3 -1
  135. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  136. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  137. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  138. package/uiActionsRegistrator/index.ts +25 -203
  139. package/uiActionsRegistrator/registry.ts +351 -0
  140. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  141. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  142. package/zappFrameworkUtils/localStorageHelper.ts +10 -2
  143. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  144. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  145. package/playerUtils/getPlayerActionButtons.ts +0 -17
  146. /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
+ };
@@ -3,11 +3,12 @@ import { useConfiguration } from "../../reactHooks/useConfiguration";
3
3
  import { useEffect } from "react";
4
4
  import { playerManager } from "./index";
5
5
  import { useValidatePlayerConfig } from "../../playerUtils/useValidatePlayerConfig";
6
- import { PlayerRole } from "./conts";
6
+ import { PlayerRole } from "./const";
7
7
  import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
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,
@@ -1,7 +1,7 @@
1
1
  import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
2
2
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
3
3
  import { createLogger, utilsLogger } from "../../logger";
4
- import { userPreferencesNamespace } from "./conts";
4
+ import { userPreferencesNamespace } from "./const";
5
5
 
6
6
  export const preferredAudioLanguageStorageKey = "preferred_audio_language";
7
7
 
@@ -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 },
@@ -545,3 +573,42 @@ export const hasTextLabelsEnabled = (
545
573
  return Boolean(value);
546
574
  });
547
575
  };
576
+
577
+ /**
578
+ * Reads the mobile buttons container "buttons enabled" switch from cell styles.
579
+ */
580
+ export const getButtonsEnabled = (styles?: Record<string, any>): boolean => {
581
+ return isTrue(styles?.mobile_buttons_container_buttons_enabled);
582
+ };
583
+
584
+ /**
585
+ * Reads the mobile buttons container "cell navigation enabled" switch from cell styles.
586
+ */
587
+ export const getCellNavigationEnabled = (
588
+ styles?: Record<string, any>
589
+ ): boolean => {
590
+ return isTrue(styles?.mobile_buttons_container_cell_navigation_enabled);
591
+ };
592
+
593
+ /**
594
+ * Whether tapping a cell outside its action buttons triggers the cell's navigation.
595
+ * Always true when the buttons are disabled.
596
+ * @param buttonsEnabled the cell's "buttons enabled" switch value
597
+ * @param cellNavigationEnabled the cell's "cell navigation enabled" switch value
598
+ */
599
+ export const isCellNavigationEnabled = (
600
+ buttonsEnabled: unknown,
601
+ cellNavigationEnabled: unknown
602
+ ): boolean => !isTrue(buttonsEnabled) || isTrue(cellNavigationEnabled);
603
+
604
+ /**
605
+ * Whether tapping a mobile cell outside its action buttons triggers the cell's navigation,
606
+ * read from the cell styles.
607
+ */
608
+ export const getIsCellNavigationEnabled = (
609
+ styles?: Record<string, any>
610
+ ): boolean =>
611
+ isCellNavigationEnabled(
612
+ getButtonsEnabled(styles),
613
+ getCellNavigationEnabled(styles)
614
+ );
@@ -176,6 +176,27 @@ describe("getAllSpecificStyles", () => {
176
176
  });
177
177
  });
178
178
 
179
+ it("should normalize Studio focus alias onto focused state", () => {
180
+ const outStyles = {};
181
+
182
+ const configuration = {
183
+ button_style_focus_background_color: "#FF3B30",
184
+ };
185
+
186
+ getAllSpecificStyles({
187
+ componentName: "button",
188
+ subComponentName: "",
189
+ configuration,
190
+ outStyles,
191
+ });
192
+
193
+ expect(outStyles.focused).toEqual({
194
+ backgroundColor: "#FF3B30",
195
+ });
196
+
197
+ expect(outStyles.focus).toBeUndefined();
198
+ });
199
+
179
200
  it("should handle selected state", () => {
180
201
  const outStyles = {};
181
202