@applicaster/zapp-react-native-utils 16.0.0-alpha.1701179921 → 16.0.0-alpha.1733304298

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 (74) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
  3. package/actionsExecutor/__tests__/feedDecorator.test.ts +30 -0
  4. package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
  5. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +139 -5
  6. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
  7. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +72 -0
  8. package/actionsExecutor/actions/navigateToScreen.ts +29 -45
  9. package/actionsExecutor/actions/openBottomSheet.ts +2 -0
  10. package/actionsExecutor/actions/screenToggleFlag.ts +1 -3
  11. package/actionsExecutor/feedDecorator.ts +6 -0
  12. package/analyticsUtils/__tests__/playerAnalyticsSafeguard.test.ts +62 -0
  13. package/analyticsUtils/playerAnalyticsTracker.ts +1 -0
  14. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -22
  15. package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
  16. package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
  17. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +0 -25
  18. package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
  19. package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
  20. package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
  21. package/appUtils/contextKeysManager/index.ts +28 -129
  22. package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
  23. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
  24. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  25. package/appUtils/playerManager/index.ts +7 -0
  26. package/appUtils/playerManager/player.ts +15 -0
  27. package/appUtils/playerManager/playerToolbox.ts +196 -0
  28. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
  29. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  30. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  31. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  32. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  33. package/cellUtils/index.ts +40 -0
  34. package/configurationUtils/__tests__/modalBlocksParser.test.ts +134 -0
  35. package/configurationUtils/modalBlocksParser.ts +38 -0
  36. package/focusManager/FocusManager.ts +26 -0
  37. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  38. package/localizationUtils/index.ts +12 -6
  39. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  40. package/logger/xrayToolbox.ts +67 -0
  41. package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
  42. package/manifestUtils/keys.js +7 -2
  43. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  44. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  45. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  46. package/modalState/ModalOrchestrator.ts +1 -0
  47. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +23 -0
  48. package/modalState/index.ts +2 -0
  49. package/modalState/types.ts +11 -0
  50. package/navigationUtils/xrayNavigator.ts +12 -0
  51. package/package.json +3 -2
  52. package/quickBrickAssets/__tests__/index.test.ts +18 -0
  53. package/quickBrickAssets/index.ts +35 -0
  54. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  55. package/reactHooks/actions/index.ts +29 -23
  56. package/reactHooks/connection/index.tsx +8 -5
  57. package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
  58. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
  59. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  60. package/reactHooks/feed/useFeedLoader.tsx +28 -1
  61. package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
  62. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  63. package/reactHooks/usePluginConfiguration.ts +84 -46
  64. package/riverComponetsMeasurementProvider/index.tsx +3 -1
  65. package/uiActionsRegistrator/__tests__/subscribe.test.ts +26 -0
  66. package/uiActionsRegistrator/registry.ts +16 -0
  67. package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
  68. package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
  69. package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
  70. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
  71. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
  72. package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
  73. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
  74. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
@@ -76,6 +76,12 @@ export class Player {
76
76
  private overlaysObserver?: OverlaysObserver | null;
77
77
  private entryObservable?: BehaviorSubject<ZappEntry> | null;
78
78
  private contentSubject?: BehaviorSubject<PlayerContent> | null;
79
+ // Read by the X-Ray `player` toolbox: the last onError/onVideoError of the current entry,
80
+ // and the Play Next action of the PlayerContainer showing this player.
81
+ public lastError: unknown = null;
82
+ public playNextHandler: (() => void) | null = null;
83
+ // The web engine the default player picked (hls.js, dash.js, shaka, video.js); null elsewhere.
84
+ public engine: string | null = null;
79
85
 
80
86
  protected listeners: {
81
87
  [key: string]: QuickBrickPlayer.SharedPlayerCallBacks;
@@ -89,6 +95,7 @@ export class Player {
89
95
 
90
96
  set entry(newEntry: ZappEntry | null) {
91
97
  this._entry = newEntry;
98
+ this.lastError = null;
92
99
  // The live entry is scoped to the entry it overlays - see
93
100
  // `OverlaysObserver.clearLiveEntry`. No-op when there is no observer,
94
101
  // which is every non-live player.
@@ -271,6 +278,10 @@ export class Player {
271
278
 
272
279
  getEntry = (): ZappEntry | null => this.entry;
273
280
 
281
+ /** The entry Play Next would play now; null without one. Never creates the overlay observer. */
282
+ getPlayNextEntry = (): ZappEntry | null =>
283
+ this.overlaysObserver?.getPlayNextEntry() ?? null;
284
+
274
285
  logState = (text, additionalParams = {}) => {
275
286
  const isSeeking = this.playerState.seekPosition !== null;
276
287
 
@@ -492,6 +503,8 @@ export class Player {
492
503
  };
493
504
 
494
505
  onVideoError = (error: Error) => {
506
+ this.lastError = error;
507
+
495
508
  this.invokeListenersUpdate({
496
509
  callbackName: SharedPlayerCallBacksKeys.OnVideoError,
497
510
  event: error,
@@ -499,6 +512,8 @@ export class Player {
499
512
  };
500
513
 
501
514
  onError = (error: Error) => {
515
+ this.lastError = error;
516
+
502
517
  this.invokeListenersUpdate({
503
518
  callbackName: SharedPlayerCallBacksKeys.OnError,
504
519
  event: error,
@@ -0,0 +1,196 @@
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
+ /** Key systems the entry declares (widevine, playready, fairplay...). */
18
+ const drmKeySystems = (drm: unknown) =>
19
+ drm && typeof drm === "object" && Object.keys(drm).length
20
+ ? Object.keys(drm)
21
+ : null;
22
+
23
+ /** The range a seek can reach: the DVR window on live, the content on VOD. */
24
+ const requireSeekable = (player: {
25
+ getSeekableDuration: () => number | undefined;
26
+ }) => {
27
+ const seekable = toNumber(player.getSeekableDuration());
28
+
29
+ if (!seekable) throw new Error("Seek is not supported");
30
+
31
+ return seekable;
32
+ };
33
+
34
+ const tools = (manager: PlayerManager): XrayToolSpec[] => {
35
+ const requirePlayer = () => {
36
+ const player = manager.getActivePlayer();
37
+
38
+ if (!player) throw new Error("No active player");
39
+
40
+ return player;
41
+ };
42
+
43
+ return [
44
+ {
45
+ name: "state",
46
+ description:
47
+ "The active player: entry, position and duration in seconds (the ad's while an ad plays), " +
48
+ "playing/buffering/ad/live/muted, role (Primary, Cell, Chromecast) and casting; in seconds, " +
49
+ "seekableDuration and contentPosition/contentDuration (the content's, even during ads); " +
50
+ "drm key systems, lastError {message} and next {id, title}, each null when absent; " +
51
+ "plugin (player plugin id) and engine (the default player's web engine, else null). " +
52
+ "active: false when nothing plays.",
53
+ handler: () => {
54
+ const player = manager.getActivePlayer();
55
+
56
+ if (!player) return { active: false, casting: manager.isCasting() };
57
+
58
+ const entry = player.getEntry();
59
+ const seekableDuration = toNumber(player.getSeekableDuration());
60
+ const next = player.getPlayNextEntry();
61
+ const error: any = player.lastError;
62
+
63
+ return {
64
+ active: true,
65
+ playerId: player.playerId,
66
+ entry: entry ? { id: entry.id, title: entry.title } : null,
67
+ position: toNumber(player.getPosition()),
68
+ duration: toNumber(player.getDuration()),
69
+ // isPlaying() only means "not paused", which is also true before the stream starts.
70
+ playing: !!player.isReadyToPlay() && player.isPlaying(),
71
+ buffering: !!player.isBuffering(),
72
+ readyToPlay: !!player.isReadyToPlay(),
73
+ ad: player.isAd(),
74
+ live: !!player.isLive(),
75
+ muted: !!player.getIsMuted(),
76
+ role: player.playerRole,
77
+ plugin: player.playerPluginId ?? null,
78
+ engine: player.engine ?? null,
79
+ casting: manager.isCasting(),
80
+ seekableDuration,
81
+ contentPosition: toNumber(player.getContentPosition()),
82
+ contentDuration: toNumber(player.getContentDuration()),
83
+ drm: drmKeySystems(entry?.extensions?.drm),
84
+ lastError:
85
+ error == null
86
+ ? null
87
+ : { message: String(error?.message ?? error?.error ?? error) },
88
+ next: next ? { id: next.id, title: next.title } : null,
89
+ };
90
+ },
91
+ },
92
+ {
93
+ name: "play",
94
+ description: "Resume the active player.",
95
+ handler: () => {
96
+ requirePlayer().play();
97
+
98
+ return "OK";
99
+ },
100
+ },
101
+ {
102
+ name: "pause",
103
+ description: "Pause the active player.",
104
+ handler: () => {
105
+ requirePlayer().pause();
106
+
107
+ return "OK";
108
+ },
109
+ },
110
+ {
111
+ name: "next",
112
+ description:
113
+ "Play the next item, as the Play Next overlay does. Fails when there is none.",
114
+ handler: () => {
115
+ const player = requirePlayer();
116
+ const next = player.getPlayNextEntry();
117
+
118
+ if (!next || !player.playNextHandler) throw new Error("No next item");
119
+
120
+ player.playNextHandler();
121
+
122
+ return { id: next.id, title: next.title };
123
+ },
124
+ },
125
+ {
126
+ name: "seek",
127
+ description:
128
+ "Seek to an absolute position, as the player's console command does: seconds from the start, " +
129
+ "or from the end when negative. Clamped to the seekable range. Where it lands can differ: " +
130
+ "server-side ads snap back to the break before the target; read player.state afterwards.",
131
+ parameters: [
132
+ {
133
+ name: "position",
134
+ type: "number",
135
+ description:
136
+ "Seconds from the start; negative values count back from the end.",
137
+ },
138
+ ],
139
+ handler: ({ position }) => {
140
+ const player = requirePlayer();
141
+ const seconds = toNumber(position);
142
+
143
+ if (seconds === null) {
144
+ throw new Error("'position' must be a number of seconds");
145
+ }
146
+
147
+ const seekable = requireSeekable(player);
148
+
149
+ const target =
150
+ seconds >= 0
151
+ ? Math.min(seconds, seekable)
152
+ : clamp(seekable + seconds, seekable);
153
+
154
+ player.seekTo(target);
155
+
156
+ return { position: target };
157
+ },
158
+ },
159
+ {
160
+ name: "offset",
161
+ description:
162
+ "Seek relative to the current position, as the player's console command does: positive " +
163
+ "forward, negative back. Clamped to the seekable range.",
164
+ parameters: [
165
+ {
166
+ name: "seconds",
167
+ type: "number",
168
+ description: "Seconds to move: positive forward, negative back.",
169
+ },
170
+ ],
171
+ handler: ({ seconds }) => {
172
+ const player = requirePlayer();
173
+ const delta = toNumber(seconds);
174
+
175
+ if (delta === null) throw new Error("'seconds' must be a number");
176
+
177
+ if (delta === 0) throw new Error("Ignored zero relative seek");
178
+
179
+ const seekable = requireSeekable(player);
180
+ const from = toNumber(player.getContentPosition()) ?? 0;
181
+ const target = clamp(from + delta, seekable);
182
+
183
+ player.seekTo(target);
184
+
185
+ return { from, position: target };
186
+ },
187
+ },
188
+ ];
189
+ };
190
+
191
+ export const registerPlayerToolbox = (manager: PlayerManager) =>
192
+ registerXrayToolbox({
193
+ name: "player",
194
+ description: "Inspect and control the active player.",
195
+ tools: tools(manager),
196
+ });
@@ -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,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
 
@@ -572,3 +573,42 @@ export const hasTextLabelsEnabled = (
572
573
  return Boolean(value);
573
574
  });
574
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
+ );
@@ -171,6 +171,17 @@ describe("parseModalBlocksConfiguration", () => {
171
171
  expect(result.item.checkbox.default).toBeUndefined();
172
172
  expect(result.item.actionButtons.default).toBeUndefined();
173
173
  });
174
+
175
+ it("parses the generic button leading icon asset", () => {
176
+ const result = parseModalBlocksConfiguration(
177
+ { "button.leading_icon.asset": "https://example.com/add.png" },
178
+ "playlist-experience"
179
+ );
180
+
181
+ expect(result.button.leadingIcon.default?.asset).toBe(
182
+ "https://example.com/add.png"
183
+ );
184
+ });
174
185
  });
175
186
 
176
187
  describe("getEmptyModalBlocksStructure", () => {
@@ -257,6 +268,69 @@ describe("getEmptyModalBlocksStructure", () => {
257
268
  );
258
269
  });
259
270
 
271
+ it("maps text label and now playing font keys onto the label style", () => {
272
+ const result = parseModalBlocksConfiguration(
273
+ {
274
+ "item.text_label1.ios.font_family": "SFProText-Bold",
275
+ "item.text_label1.letter_spacing": -0.4,
276
+ "item.text_label1.text_transform": "uppercase",
277
+ "now_playing_item.now_playing_label.ios.font_family":
278
+ "SFProText-Semibold",
279
+ "now_playing_item.now_playing_label.font_size": 18,
280
+ },
281
+ "queue-action"
282
+ );
283
+
284
+ expect(result.item.textLabel1.default).toEqual(
285
+ expect.objectContaining({
286
+ fontFamily: "SFProText-Bold",
287
+ letterSpacing: -0.4,
288
+ textTransform: "uppercase",
289
+ })
290
+ );
291
+
292
+ expect(result.nowPlayingItem?.nowPlayingLabel.default).toEqual(
293
+ expect.objectContaining({
294
+ fontFamily: "SFProText-Semibold",
295
+ fontSize: 18,
296
+ })
297
+ );
298
+ });
299
+
300
+ it("maps queue remove and reorder assets onto item action buttons", () => {
301
+ const result = parseModalBlocksConfiguration(
302
+ {
303
+ "item.remove_asset": "https://example.com/remove.png",
304
+ "item.reorder_handle_asset": "https://example.com/reorder.png",
305
+ },
306
+ "queue-action"
307
+ );
308
+
309
+ expect(result.item.actionButtons.default).toEqual(
310
+ expect.objectContaining({
311
+ removeAsset: "https://example.com/remove.png",
312
+ dragAsset: "https://example.com/reorder.png",
313
+ })
314
+ );
315
+ });
316
+
317
+ it("maps now playing play and pause assets onto action buttons", () => {
318
+ const result = parseModalBlocksConfiguration(
319
+ {
320
+ "now_playing_item.play_asset": "https://example.com/play.png",
321
+ "now_playing_item.pause_asset": "https://example.com/pause.png",
322
+ },
323
+ "queue-action"
324
+ );
325
+
326
+ expect(result.nowPlayingItem?.actionButtons.default).toEqual(
327
+ expect.objectContaining({
328
+ playAsset: "https://example.com/play.png",
329
+ pauseAsset: "https://example.com/pause.png",
330
+ })
331
+ );
332
+ });
333
+
260
334
  it("should leave sectionHeader empty when keys are absent", () => {
261
335
  const result = parseModalBlocksConfiguration(
262
336
  { "item.text_label1.font_color": "#FFFFFF" },
@@ -266,4 +340,64 @@ describe("getEmptyModalBlocksStructure", () => {
266
340
  expect(result.sectionHeader.title).toEqual({ default: {} });
267
341
  expect(result.sectionHeader.actionButtons).toEqual({ default: {} });
268
342
  });
343
+
344
+ it("maps playlist button font family and the new green style keys", () => {
345
+ const result = parseModalBlocksConfiguration(
346
+ {
347
+ "button.title.ios.font_family": "GreycliffCF-Bold",
348
+ "button.title.inactive_font_color": "#111111",
349
+ "button.title.focused_font_color": "#222222",
350
+ "button.title.text_transform": "uppercase",
351
+ "button.background.inactive_color": "#999999",
352
+ "button.background.horizontal_gutter": 6,
353
+ "button.icons.width": 24,
354
+ "button.icons.height": 24,
355
+ },
356
+ "playlist-experience"
357
+ );
358
+
359
+ expect(result.button.title.default).toEqual(
360
+ expect.objectContaining({
361
+ fontFamily: "GreycliffCF-Bold",
362
+ inactiveFontColor: "#111111",
363
+ textTransform: "uppercase",
364
+ })
365
+ );
366
+
367
+ // "focused_" is a state prefix, so this key lands on the focused bucket.
368
+ expect(result.button.title.focused).toEqual(
369
+ expect.objectContaining({
370
+ fontColor: "#222222",
371
+ })
372
+ );
373
+
374
+ expect(result.button.background.default).toEqual(
375
+ expect.objectContaining({
376
+ inactiveColor: "#999999",
377
+ horizontalGutter: 6,
378
+ })
379
+ );
380
+
381
+ expect(result.button.icons.default).toEqual(
382
+ expect.objectContaining({
383
+ width: 24,
384
+ height: 24,
385
+ })
386
+ );
387
+ });
388
+
389
+ it("keeps a font-selector object on the button title", () => {
390
+ const result = parseModalBlocksConfiguration(
391
+ {
392
+ "button.title.ios.font_family": { fontFamily: "GreycliffCF-Bold" },
393
+ },
394
+ "playlist-experience"
395
+ );
396
+
397
+ expect(result.button.title.default).toEqual(
398
+ expect.objectContaining({
399
+ fontFamily: { fontFamily: "GreycliffCF-Bold" },
400
+ })
401
+ );
402
+ });
269
403
  });
@@ -210,5 +210,43 @@ export const parseModalBlocksConfiguration = (
210
210
 
211
211
  parseBlock("button", ["background", "title", "icons", "leading_icon"]);
212
212
 
213
+ // Leaf uploader keys. They are not `<block>_<sub>_<prop>` styles, so
214
+ // getAllSpecificStyles never sees them.
215
+ const assignLeafAsset = (
216
+ block: ModalBlocksConfig["item"] | undefined,
217
+ key: string,
218
+ prop: "playAsset" | "pauseAsset" | "removeAsset" | "dragAsset"
219
+ ) => {
220
+ if (!block) return;
221
+
222
+ const value = configuration[key];
223
+
224
+ if (typeof value !== "string" || !value.trim()) return;
225
+
226
+ block.actionButtons = {
227
+ ...block.actionButtons,
228
+ default: {
229
+ ...(block.actionButtons?.default || {}),
230
+ [prop]: value,
231
+ },
232
+ };
233
+ };
234
+
235
+ assignLeafAsset(
236
+ result.nowPlayingItem,
237
+ "now_playing_item.play_asset",
238
+ "playAsset"
239
+ );
240
+
241
+ assignLeafAsset(
242
+ result.nowPlayingItem,
243
+ "now_playing_item.pause_asset",
244
+ "pauseAsset"
245
+ );
246
+
247
+ assignLeafAsset(result.item, "item.remove_asset", "removeAsset");
248
+
249
+ assignLeafAsset(result.item, "item.reorder_handle_asset", "dragAsset");
250
+
213
251
  return result;
214
252
  };
@@ -224,12 +224,38 @@ class FocusManager {
224
224
 
225
225
  unregisterFocusable(focusableId: string) {
226
226
  const node = this.tree.find(focusableId);
227
+ const parentNode = this.tree.findParent(focusableId);
227
228
 
228
229
  this.focusableComponents = this.focusableComponents.filter(
229
230
  (c) => c !== node?.component
230
231
  );
231
232
 
232
233
  this.tree.remove(focusableId);
234
+
235
+ if (this._focusedId === focusableId) {
236
+ this._focusedId = null;
237
+ this.retainFocus(parentNode);
238
+ }
239
+ }
240
+
241
+ // Empty groups drop their focusable list after the feed fails, which is
242
+ // after Layout's one-shot focus pass. Land on the nearest ancestor that is
243
+ // still mounted so key handlers keep a target.
244
+ private retainFocus(node: TreeNode | null) {
245
+ let current = node;
246
+
247
+ while (current) {
248
+ const ref = current.component;
249
+
250
+ if (ref?.current?.props?.id) {
251
+ this.setFocusLocal(ref);
252
+ ref.current.onFocus?.(ref.current, {}, undefined);
253
+
254
+ return;
255
+ }
256
+
257
+ current = current.parentId ? this.tree.find(current.parentId) : null;
258
+ }
233
259
  }
234
260
 
235
261
  private setNextFocus(
@@ -231,6 +231,15 @@ describe("FocusManager", () => {
231
231
  ).toBeFalsy();
232
232
  });
233
233
 
234
+ it("moves focus to the mounted parent when the focused element unregisters", () => {
235
+ focusManager.setFocus("child1");
236
+
237
+ focusManager.unregisterFocusable("child1");
238
+
239
+ expect(focusManager.focusedId).toBe("group");
240
+ expect(focusManager.focused).toBe(group.current);
241
+ });
242
+
234
243
  it("focusManager registerFocusable should be defined", () => {
235
244
  expect(focusManager.registerFocusable).toBeDefined();
236
245
  });