@applicaster/zapp-react-native-utils 16.0.0-rc.90 → 16.0.0-rc.91

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.
@@ -1,4 +1,7 @@
1
- import { parseModalBlocksConfiguration } from "../modalBlocksParser";
1
+ import {
2
+ getEmptyModalBlocksStructure,
3
+ parseModalBlocksConfiguration,
4
+ } from "../modalBlocksParser";
2
5
 
3
6
  // Mock the platform selection logic so it's consistent
4
7
  jest.mock("../../reactUtils", () => ({
@@ -151,110 +154,55 @@ describe("parseModalBlocksConfiguration", () => {
151
154
  );
152
155
  });
153
156
 
154
- it("should map button.create_new_playlist_asset onto leadingIcon.asset", () => {
157
+ it("should ignore keys that do not map to a known block sub-component", () => {
155
158
  const result = parseModalBlocksConfiguration(
156
159
  {
157
160
  "button.create_new_playlist_asset":
158
161
  "https://placehold.co/24x24/FF00FF/FFFFFF/png?text=CN",
159
- },
160
- "playlist-experience"
161
- );
162
-
163
- expect(result.button.leadingIcon.default).toEqual(
164
- expect.objectContaining({
165
- asset: "https://placehold.co/24x24/FF00FF/FFFFFF/png?text=CN",
166
- })
167
- );
168
- });
169
-
170
- it("should map item.checkbox_asset and checked_checkbox_asset onto item.checkbox", () => {
171
- const result = parseModalBlocksConfiguration(
172
- {
173
162
  "item.checkbox_asset":
174
163
  "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=CB",
175
- "item.checked_checkbox_asset":
176
- "https://placehold.co/24x24/FFD60A/000000/png?text=CK",
177
- },
178
- "playlist-experience"
179
- );
180
-
181
- expect(result.item.checkbox.default).toEqual(
182
- expect.objectContaining({
183
- asset: "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=CB",
184
- checkedAsset: "https://placehold.co/24x24/FFD60A/000000/png?text=CK",
185
- })
186
- );
187
- });
188
-
189
- it("should map reorder/remove Studio assets onto item.actionButtons", () => {
190
- const result = parseModalBlocksConfiguration(
191
- {
192
- "reorder_playlist_item.remove_from_playlist_asset":
193
- "https://placehold.co/24x24/00FF00/000000/png?text=RM",
194
164
  "reorder_playlist_item.reorder_handle_asset":
195
165
  "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
196
166
  },
197
167
  "playlist-experience"
198
168
  );
199
169
 
200
- expect(result.item.actionButtons.default).toEqual(
201
- expect.objectContaining({
202
- removeAsset: "https://placehold.co/24x24/00FF00/000000/png?text=RM",
203
- dragAsset: "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
204
- })
205
- );
170
+ expect(result.button.leadingIcon.default?.asset).toBeUndefined();
171
+ expect(result.item.checkbox.default).toBeUndefined();
172
+ expect(result.item.actionButtons.default).toBeUndefined();
206
173
  });
174
+ });
207
175
 
208
- it("should fall back to flavor1 reorder/remove assets", () => {
209
- const result = parseModalBlocksConfiguration(
210
- {
211
- "playlist_experience_assets_flavor1.remove_from_playlist_asset":
212
- "https://placehold.co/24x24/00FF00/000000/png?text=RM",
213
- "playlist_experience_assets_flavor1.reorder_handle_asset":
214
- "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
215
- },
216
- "playlist-experience"
217
- );
176
+ describe("getEmptyModalBlocksStructure", () => {
177
+ it("should return every block with empty containers and no state entries", () => {
178
+ const result = getEmptyModalBlocksStructure();
218
179
 
219
- expect(result.item.actionButtons.default).toEqual(
220
- expect.objectContaining({
221
- removeAsset: "https://placehold.co/24x24/00FF00/000000/png?text=RM",
222
- dragAsset: "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
223
- })
224
- );
180
+ expect(result.header.container).toEqual({});
181
+ expect(result.item.background).toEqual({});
182
+ expect(result.button.background).toEqual({});
183
+ expect(result.action.background).toEqual({});
184
+
185
+ expect(result.button.leadingIcon.default).toBeUndefined();
186
+ expect(result.item.checkbox.default).toBeUndefined();
187
+ expect(result.item.actionButtons.default).toBeUndefined();
225
188
  });
226
189
 
227
- it("should fall back to flavor2 reorder/remove assets", () => {
228
- const result = parseModalBlocksConfiguration(
229
- {
230
- "playlist_experience_assets_flavor2.remove_from_playlist_asset":
231
- "https://placehold.co/24x24/00FF00/000000/png?text=RM",
232
- "playlist_experience_assets_flavor2.reorder_handle_asset":
233
- "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
234
- },
235
- "playlist-experience"
236
- );
190
+ it("should return a fresh object on every call", () => {
191
+ const first = getEmptyModalBlocksStructure();
192
+ const second = getEmptyModalBlocksStructure();
237
193
 
238
- expect(result.item.actionButtons.default).toEqual(
239
- expect.objectContaining({
240
- removeAsset: "https://placehold.co/24x24/00FF00/000000/png?text=RM",
241
- dragAsset: "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
242
- })
243
- );
194
+ expect(first).not.toBe(second);
195
+ expect(first.header).not.toBe(second.header);
196
+ expect(first).toEqual(second);
244
197
  });
245
198
 
246
- it("should ignore playlist-only asset keys for other theme plugins", () => {
247
- const result = parseModalBlocksConfiguration(
248
- {
249
- "button.create_new_playlist_asset":
250
- "https://placehold.co/24x24/FF00FF/FFFFFF/png?text=CN",
251
- "playlist_experience_assets_flavor1.reorder_handle_asset":
252
- "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
253
- },
254
- "queue-action"
255
- );
199
+ it("should be what the parser returns when config or componentName is missing", () => {
200
+ expect(
201
+ parseModalBlocksConfiguration(undefined as any, "queue_action")
202
+ ).toEqual(getEmptyModalBlocksStructure());
256
203
 
257
- expect(result.button.leadingIcon.default?.asset).toBeUndefined();
258
- expect(result.item.actionButtons.default?.dragAsset).toBeUndefined();
204
+ expect(parseModalBlocksConfiguration({ foo: "bar" }, "")).toEqual(
205
+ getEmptyModalBlocksStructure()
206
+ );
259
207
  });
260
208
  });
@@ -52,10 +52,7 @@ export type ModalBlocksConfig = {
52
52
  };
53
53
  };
54
54
 
55
- export const parseModalBlocksConfiguration = (
56
- configuration: Record<string, any>,
57
- componentName: string
58
- ): ModalBlocksConfig => {
55
+ export const getEmptyModalBlocksStructure = (): ModalBlocksConfig => {
59
56
  const result: ModalBlocksConfig = {
60
57
  header: {
61
58
  container: {},
@@ -106,6 +103,15 @@ export const parseModalBlocksConfiguration = (
106
103
  },
107
104
  };
108
105
 
106
+ return result;
107
+ };
108
+
109
+ export const parseModalBlocksConfiguration = (
110
+ configuration: Record<string, any>,
111
+ componentName: string
112
+ ): ModalBlocksConfig => {
113
+ const result = getEmptyModalBlocksStructure();
114
+
109
115
  if (!configuration || !componentName) {
110
116
  return result;
111
117
  }
@@ -190,107 +196,5 @@ export const parseModalBlocksConfiguration = (
190
196
 
191
197
  parseBlock("button", ["background", "title", "icons", "leading_icon"]);
192
198
 
193
- // Playlist-experience Studio keys live in this shared parser because modal
194
- // blocks are themed by themePluginId. Gate them so other plugins are not
195
- // affected by playlist-only asset names.
196
- const isPlaylistExperience =
197
- normalizedComponentName === "playlist_experience";
198
-
199
- // Studio uploads Create New icon as button.create_new_playlist_asset (not
200
- // button.leading_icon.asset). Map it onto leadingIcon so AudioPlayerButton
201
- // can override the hardcoded action-type asset.
202
- const createNewPlaylistAsset = isPlaylistExperience
203
- ? configuration["button.create_new_playlist_asset"] ||
204
- configuration[
205
- `${normalizedComponentName}_button_create_new_playlist_asset`
206
- ]
207
- : undefined;
208
-
209
- if (createNewPlaylistAsset) {
210
- if (!result.button.leadingIcon.default) {
211
- result.button.leadingIcon.default = {};
212
- }
213
-
214
- result.button.leadingIcon.default.asset = createNewPlaylistAsset;
215
- }
216
-
217
- // Studio checkbox assets are top-level item.* keys (not a parseBlock
218
- // sub-component). Map onto item.checkbox so multiSelect can render them.
219
- const checkboxAsset =
220
- configuration["item.checkbox_asset"] ||
221
- configuration[`${normalizedComponentName}_item_checkbox_asset`];
222
-
223
- const checkedCheckboxAsset =
224
- configuration["item.checked_checkbox_asset"] ||
225
- configuration[`${normalizedComponentName}_item_checked_checkbox_asset`];
226
-
227
- if (checkboxAsset || checkedCheckboxAsset) {
228
- if (!result.item.checkbox.default) {
229
- result.item.checkbox.default = {};
230
- }
231
-
232
- if (checkboxAsset) {
233
- result.item.checkbox.default.asset = checkboxAsset;
234
- }
235
-
236
- if (checkedCheckboxAsset) {
237
- result.item.checkbox.default.checkedAsset = checkedCheckboxAsset;
238
- }
239
- }
240
-
241
- // Edit Order row icons: prefer reorder_playlist_item.*, then flavor1, then
242
- // flavor2 playlist_experience_assets_* (playlist-experience theme only).
243
- const removeAsset = isPlaylistExperience
244
- ? configuration["reorder_playlist_item.remove_from_playlist_asset"] ||
245
- configuration[
246
- `${normalizedComponentName}_reorder_playlist_item_remove_from_playlist_asset`
247
- ] ||
248
- configuration[
249
- "playlist_experience_assets_flavor1.remove_from_playlist_asset"
250
- ] ||
251
- configuration[
252
- `${normalizedComponentName}_assets_flavor1_remove_from_playlist_asset`
253
- ] ||
254
- configuration[
255
- "playlist_experience_assets_flavor2.remove_from_playlist_asset"
256
- ] ||
257
- configuration[
258
- `${normalizedComponentName}_assets_flavor2_remove_from_playlist_asset`
259
- ]
260
- : undefined;
261
-
262
- const dragAsset = isPlaylistExperience
263
- ? configuration["reorder_playlist_item.reorder_handle_asset"] ||
264
- configuration[
265
- `${normalizedComponentName}_reorder_playlist_item_reorder_handle_asset`
266
- ] ||
267
- configuration[
268
- "playlist_experience_assets_flavor1.reorder_handle_asset"
269
- ] ||
270
- configuration[
271
- `${normalizedComponentName}_assets_flavor1_reorder_handle_asset`
272
- ] ||
273
- configuration[
274
- "playlist_experience_assets_flavor2.reorder_handle_asset"
275
- ] ||
276
- configuration[
277
- `${normalizedComponentName}_assets_flavor2_reorder_handle_asset`
278
- ]
279
- : undefined;
280
-
281
- if (removeAsset || dragAsset) {
282
- if (!result.item.actionButtons.default) {
283
- result.item.actionButtons.default = {};
284
- }
285
-
286
- if (removeAsset) {
287
- result.item.actionButtons.default.removeAsset = removeAsset;
288
- }
289
-
290
- if (dragAsset) {
291
- result.item.actionButtons.default.dragAsset = dragAsset;
292
- }
293
- }
294
-
295
199
  return result;
296
200
  };
@@ -60,7 +60,7 @@ describe("buildEntryActions - alias & label resolution", () => {
60
60
  expect(state.label).toBe("Label Property Action");
61
61
  });
62
62
 
63
- it("resolves entry action with known backend button alias (e.g. add_all_to_queue)", () => {
63
+ it("humanizes an un-overridden alias and falls back to the placeholder asset", () => {
64
64
  const entry = {
65
65
  id: "entry-3",
66
66
  extensions: {
@@ -71,11 +71,7 @@ describe("buildEntryActions - alias & label resolution", () => {
71
71
  dismiss_on_action: true,
72
72
  },
73
73
  {
74
- button: { alias: "add_to_playlist" },
75
- actions: [{ type: "test" }],
76
- },
77
- {
78
- button: { alias: "delete_collection" },
74
+ button: { alias: "custom_unknown_action" },
79
75
  actions: [{ type: "test" }],
80
76
  },
81
77
  ],
@@ -84,42 +80,86 @@ describe("buildEntryActions - alias & label resolution", () => {
84
80
 
85
81
  const actions = resolveEntryActions(entry as any);
86
82
 
87
- expect(actions).toHaveLength(3);
83
+ expect(actions).toHaveLength(2);
88
84
 
85
+ // No built-in alias vocabulary any more: underscores become spaces and
86
+ // only the first letter is capitalized, so "queue" stays lowercase.
89
87
  expect(actions[0].action.initialEntryState(entry as any)).toMatchObject({
90
88
  state: 0,
91
- label: "Add all to Queue",
89
+ label: "Add all to queue",
92
90
  });
93
91
 
94
92
  expect(actions[1].action.initialEntryState(entry as any)).toMatchObject({
95
93
  state: 0,
96
- label: "Add to Playlist",
94
+ label: "Custom unknown action",
97
95
  });
98
96
 
99
- expect(actions[2].action.initialEntryState(entry as any)).toMatchObject({
100
- state: 0,
101
- label: "Delete collection",
102
- });
97
+ // The asset has no such fallback: without an override it is the red-box
98
+ // placeholder, so a missing Studio icon is visible rather than absent.
99
+ for (const action of actions) {
100
+ expect(action.action.initialEntryState(entry as any)).toMatchObject({
101
+ asset: expect.stringMatching(/^data:image\/png;base64,/),
102
+ });
103
+ }
103
104
  });
104
105
 
105
- it("formats unknown alias nicely as fallback", () => {
106
+ it("prefers aliasPresentation overrides over the humanized fallbacks", () => {
107
+ const deps = {
108
+ actionExecutor: { handleActions: jest.fn() } as any,
109
+ actionContext: {},
110
+ aliasPresentation: {
111
+ labels: { add_all_to_queue: "Add all to Queue" },
112
+ assets: { add_all_to_queue: "http://example.com/queue.png" },
113
+ },
114
+ };
115
+
106
116
  const entry = {
107
117
  id: "entry-4",
108
118
  extensions: {
109
119
  entry_action: [
110
120
  {
111
- button: { alias: "custom_unknown_action" },
121
+ button: { alias: "add_all_to_queue" },
122
+ actions: [{ type: "test" }],
123
+ },
124
+ {
125
+ button: { alias: "not_overridden" },
112
126
  actions: [{ type: "test" }],
113
127
  },
114
128
  ],
115
129
  },
116
130
  };
117
131
 
118
- const actions = resolveEntryActions(entry as any);
132
+ const actions = buildEntryActions(entry as any, deps);
119
133
 
120
- expect(actions).toHaveLength(1);
134
+ expect(actions[0].action.initialEntryState(entry as any)).toMatchObject({
135
+ label: "Add all to Queue",
136
+ asset: "http://example.com/queue.png",
137
+ });
138
+
139
+ // Overrides are per-alias, so an alias absent from the map still humanizes.
140
+ expect(actions[1].action.initialEntryState(entry as any)).toMatchObject({
141
+ label: "Not overridden",
142
+ });
143
+ });
144
+
145
+ it("returns no asset when the button has neither iconURL nor alias", () => {
146
+ const entry = {
147
+ id: "entry-5",
148
+ extensions: {
149
+ entry_action: [
150
+ {
151
+ button: { label: "Plain Label" },
152
+ actions: [{ type: "test" }],
153
+ },
154
+ ],
155
+ },
156
+ };
157
+
158
+ const actions = resolveEntryActions(entry as any);
121
159
  const state = actions[0].action.initialEntryState(entry as any);
122
- expect(state.label).toBe("Custom unknown action");
160
+
161
+ expect(state.label).toBe("Plain Label");
162
+ expect(state.asset).toBeUndefined();
123
163
  });
124
164
 
125
165
  it("uses actionExecutor.getActionState for plugin-provided label and asset", () => {
@@ -1,52 +1,29 @@
1
1
  /**
2
- * Presentation defaults for backend action aliases.
2
+ * Presentation fallbacks for backend action aliases.
3
3
  *
4
4
  * Entries may declare an action by `alias` alone, without a label or an icon.
5
- * These maps are the last-resort labels/icons for the aliases we know about; an
6
- * unknown alias falls back to a humanized version of the alias itself.
5
+ * There is no built-in alias vocabulary: a label falls back to a humanized
6
+ * version of the alias itself, and an icon falls back to an inline placeholder
7
+ * that is deliberately conspicuous, so a missing asset reads as unconfigured
8
+ * rather than as a deliberate blank.
7
9
  *
8
- * They are defaults, not a framework guarantee: an app that speaks a different
9
- * alias vocabulary, needs other languages, or does not want to depend on these
10
- * icon hosts passes its own through `EntryActionDeps.aliasPresentation`.
10
+ * Both are last resorts, not a framework guarantee: an app that speaks its own
11
+ * alias vocabulary or needs other languages passes labels and assets through
12
+ * `EntryActionDeps.aliasPresentation`, which is consulted per alias.
11
13
  */
12
14
 
13
15
  import { EntryAction } from "./types";
14
16
 
15
- const ADD_TO_PLAYLIST_ICON =
16
- "https://assets-secure.applicaster.com/zapp/assets/app_family/1710/906728572617/playlist_add_24dp_FFFFFF_FILL0_wght400_GRAD0_opsz24.png";
17
-
18
- const REMOVE_ICON =
19
- "https://assets-secure.applicaster.com/zapp/assets/app_family/1710/372097240191/remove_24dp_EA3323_FILL0_wght400_GRAD0_opsz24.png";
20
-
21
- const EDIT_ICON =
22
- "https://upload.wikimedia.org/wikipedia/commons/b/b6/Edit-icon.png";
23
-
24
- /** Known backend action alias labels. */
25
- export const ALIAS_LABELS: Record<string, string> = {
26
- add_to_playlist: "Add to Playlist",
27
- add_to_queue: "Add to Queue",
28
- add_all_to_queue: "Add all to Queue",
29
- play_all: "Play All",
30
- remove_item: "Remove item",
31
- delete_collection: "Delete collection",
32
- create_collection: "Create collection",
33
- edit: "Edit",
34
- edit_name: "Edit Name & Details",
35
- };
17
+ import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
36
18
 
37
- /** Known backend action alias image assets. */
38
- export const ALIAS_ASSETS: Record<string, string> = {
39
- add_to_playlist: ADD_TO_PLAYLIST_ICON,
40
- add_to_queue: ADD_TO_PLAYLIST_ICON,
41
- add_all_to_queue: ADD_TO_PLAYLIST_ICON,
42
- play_all: ADD_TO_PLAYLIST_ICON,
43
- remove_item: REMOVE_ICON,
44
- delete_collection: REMOVE_ICON,
45
- edit: EDIT_ICON,
46
- edit_name: EDIT_ICON,
47
- };
19
+ const logger = createLogger({
20
+ category: "zapp-react-native-utils:aliasPresentation",
21
+ });
22
+
23
+ const PLACEHOLDER_RED_BOX =
24
+ "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAJ0lEQVR4nO3NMQEAAAjDsIF/z2ACvlRAU5NMHuvPOQAAAAAAAMBdC/07Ai5sNw+CAAAAAElFTkSuQmCC";
48
25
 
49
- /** Per-app overrides for the maps above. */
26
+ /** Per-app labels and icons, keyed by alias, that outrank the fallbacks. */
50
27
  export type AliasPresentation = {
51
28
  labels?: Record<string, string>;
52
29
  assets?: Record<string, string>;
@@ -56,7 +33,7 @@ function formatAliasLabel(
56
33
  alias: string,
57
34
  overrides?: AliasPresentation
58
35
  ): string {
59
- const label = overrides?.labels?.[alias] ?? ALIAS_LABELS[alias];
36
+ const label = overrides?.labels?.[alias];
60
37
 
61
38
  if (label) {
62
39
  return label;
@@ -107,7 +84,7 @@ export function resolveButtonLabel(
107
84
  return "";
108
85
  }
109
86
 
110
- /** Icon to show for an entry action: explicit iconURL, else the alias default. */
87
+ /** Icon to show for an entry action: explicit iconURL, matching alias asset or fallback to red box. */
111
88
  export function resolveButtonAsset(
112
89
  button: EntryAction["button"],
113
90
  overrides?: AliasPresentation
@@ -120,5 +97,12 @@ export function resolveButtonAsset(
120
97
  return undefined;
121
98
  }
122
99
 
123
- return overrides?.assets?.[button.alias] ?? ALIAS_ASSETS[button.alias];
100
+ if (!overrides?.assets?.[button.alias]) {
101
+ logger.log_warning(
102
+ `Entry action alias '${button.alias}' was not resolved by any plugin feedDecorator or app override. Falling back to placeholder red box.`,
103
+ { data: { button } }
104
+ );
105
+ }
106
+
107
+ return overrides?.assets?.[button.alias] ?? PLACEHOLDER_RED_BOX;
124
108
  }
@@ -1,8 +1,6 @@
1
1
  export { buildEntryActions, isEntryAction } from "./buildEntryActions";
2
2
 
3
3
  export {
4
- ALIAS_ASSETS,
5
- ALIAS_LABELS,
6
4
  resolveButtonAsset,
7
5
  resolveButtonLabel,
8
6
  resolveExplicitLabel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-rc.90",
3
+ "version": "16.0.0-rc.91",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "16.0.0-rc.90",
30
+ "@applicaster/applicaster-types": "16.0.0-rc.91",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",