@applicaster/zapp-react-native-utils 15.1.13 → 15.1.15-alpha.4236143002
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.
- package/actionsExecutor/ActionExecutor.ts +40 -2
- package/actionsExecutor/ActionExecutorContext.tsx +70 -16
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
- package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +212 -0
- package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
- package/actionsExecutor/actions/index.ts +4 -0
- package/actionsExecutor/actions/openBottomSheet.ts +329 -0
- package/actionsExecutor/actions/refreshComponent.ts +6 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
- package/actionsExecutor/consts.ts +23 -0
- package/actionsExecutor/types.ts +1 -1
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +5 -2
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +55 -2
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
- package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
- package/arrayUtils/index.ts +79 -0
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +260 -0
- package/configurationUtils/manifestKeyParser.ts +50 -10
- package/configurationUtils/modalBlocksParser.ts +296 -0
- package/entryActions/__tests__/buildEntryActions.test.ts +195 -0
- package/entryActions/aliasPresentation.ts +124 -0
- package/entryActions/buildEntryActions.ts +167 -0
- package/entryActions/index.ts +17 -0
- package/entryActions/types.ts +39 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +22 -1
- package/manifestUtils/index.js +3 -0
- package/manifestUtils/modalBlocks.js +304 -0
- package/modalState/ContentViewModel.ts +113 -0
- package/modalState/EditableCollection.ts +17 -0
- package/modalState/EditableCollectionRegistry.ts +51 -0
- package/modalState/ModalOrchestrator.ts +211 -0
- package/modalState/RemoteEditableCollection.ts +235 -0
- package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
- package/modalState/__tests__/ContentViewModel.test.ts +165 -0
- package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
- package/modalState/__tests__/index.test.ts +30 -1
- package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
- package/modalState/index.ts +35 -83
- package/modalState/store.ts +102 -0
- package/modalState/types.ts +160 -0
- package/modalState/useBottomSheetContent.ts +104 -0
- package/package.json +2 -2
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/index.ts +17 -1
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/reactHooks/actions/index.ts +67 -2
- package/reactHooks/usePluginConfiguration.ts +6 -3
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
- package/uiActionsRegistrator/index.ts +25 -203
- package/uiActionsRegistrator/registry.ts +335 -0
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
- package/uiActionsRegistrator/usableActionItems.ts +66 -0
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
- /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
package/arrayUtils/index.ts
CHANGED
|
@@ -121,3 +121,82 @@ export const allTruthy = (xs: boolean[]) =>
|
|
|
121
121
|
isFilledArray(xs) && xs.every(Boolean);
|
|
122
122
|
|
|
123
123
|
export const anyTruthy = (xs: boolean[]) => xs.some(Boolean);
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Reorders `items` based on an ordered array of IDs (`orderedIds`).
|
|
127
|
+
* Items whose IDs are in `orderedIds` appear first in that exact sequence.
|
|
128
|
+
* Any remaining items not present in `orderedIds` are appended at the end preserving their relative order.
|
|
129
|
+
*/
|
|
130
|
+
export function reorderByIds<T>(
|
|
131
|
+
items: T[],
|
|
132
|
+
orderedIds: string[],
|
|
133
|
+
getId: (item: T) => string | string[] = (item: any) => item?.id
|
|
134
|
+
): T[] {
|
|
135
|
+
if (!items || items.length === 0) return [];
|
|
136
|
+
if (!orderedIds || orderedIds.length === 0) return [...items];
|
|
137
|
+
|
|
138
|
+
const itemMap = new Map<string, T>();
|
|
139
|
+
|
|
140
|
+
items.forEach((item) => {
|
|
141
|
+
const rawId = getId(item);
|
|
142
|
+
const keys = Array.isArray(rawId) ? rawId : [rawId];
|
|
143
|
+
|
|
144
|
+
keys.forEach((key) => {
|
|
145
|
+
if (key !== undefined && key !== null && key !== "") {
|
|
146
|
+
itemMap.set(String(key), item);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const reorderedSubset: T[] = [];
|
|
152
|
+
const orderedIdsSet = new Set<string>();
|
|
153
|
+
|
|
154
|
+
orderedIds.forEach((id) => {
|
|
155
|
+
const strId = String(id);
|
|
156
|
+
const item = itemMap.get(strId);
|
|
157
|
+
|
|
158
|
+
if (item && !reorderedSubset.includes(item)) {
|
|
159
|
+
reorderedSubset.push(item);
|
|
160
|
+
const rawId = getId(item);
|
|
161
|
+
const keys = Array.isArray(rawId) ? rawId : [rawId];
|
|
162
|
+
|
|
163
|
+
keys.forEach((k) => {
|
|
164
|
+
if (k !== undefined && k !== null && k !== "") {
|
|
165
|
+
orderedIdsSet.add(String(k));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
if (reorderedSubset.length === 0) return [...items];
|
|
172
|
+
|
|
173
|
+
let subsetIdx = 0;
|
|
174
|
+
const result: T[] = [];
|
|
175
|
+
|
|
176
|
+
items.forEach((item) => {
|
|
177
|
+
const rawId = getId(item);
|
|
178
|
+
const keys = Array.isArray(rawId) ? rawId : [rawId];
|
|
179
|
+
|
|
180
|
+
const isMatched = keys.some(
|
|
181
|
+
(k) =>
|
|
182
|
+
k !== undefined &&
|
|
183
|
+
k !== null &&
|
|
184
|
+
k !== "" &&
|
|
185
|
+
orderedIdsSet.has(String(k))
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
if (isMatched) {
|
|
189
|
+
if (subsetIdx < reorderedSubset.length) {
|
|
190
|
+
result.push(reorderedSubset[subsetIdx++]);
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
result.push(item);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
while (subsetIdx < reorderedSubset.length) {
|
|
198
|
+
result.push(reorderedSubset[subsetIdx++]);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
@@ -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
|
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { parseModalBlocksConfiguration } from "../modalBlocksParser";
|
|
2
|
+
|
|
3
|
+
// Mock the platform selection logic so it's consistent
|
|
4
|
+
jest.mock("../../reactUtils", () => ({
|
|
5
|
+
platformSelect: jest.fn().mockReturnValue("ios"),
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
describe("parseModalBlocksConfiguration", () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
jest.clearAllMocks();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should return empty structures for missing config or componentName", () => {
|
|
14
|
+
const result1 = parseModalBlocksConfiguration(
|
|
15
|
+
undefined as any,
|
|
16
|
+
"queue_action"
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
expect(result1.header.container).toEqual({});
|
|
20
|
+
|
|
21
|
+
const result2 = parseModalBlocksConfiguration({ foo: "bar" }, "");
|
|
22
|
+
expect(result2.item.background).toEqual({});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should correctly parse the specified flat keys into nested objects", () => {
|
|
26
|
+
// The keys follow: <component_name>_style_<blockName>_<subComponent>_[platform_][state_]<styleName>
|
|
27
|
+
const config = {
|
|
28
|
+
// Header container - default platform, default state
|
|
29
|
+
queue_action_style_header_container_backgroundColor: "#000000",
|
|
30
|
+
|
|
31
|
+
// Header title - default platform, pressed state
|
|
32
|
+
queue_action_style_header_title_pressed_fontColor: "#ffffff",
|
|
33
|
+
|
|
34
|
+
// Item background - ios platform, default state
|
|
35
|
+
queue_action_style_item_background_ios_backgroundColor: "blue",
|
|
36
|
+
|
|
37
|
+
// Item textLabel1 - default platform, focused state
|
|
38
|
+
queue_action_style_item_text_label_1_focused_fontSize: 16,
|
|
39
|
+
|
|
40
|
+
// Ignored key (unrelated to building blocks or queue_action)
|
|
41
|
+
other_action_style_header_title_fontColor: "red",
|
|
42
|
+
some_random_key: "value",
|
|
43
|
+
|
|
44
|
+
// Ignored non-style data keys (should NEVER be parsed as styles)
|
|
45
|
+
item_data_source: "http://pipes.example.com",
|
|
46
|
+
item_url: "http://example.com",
|
|
47
|
+
|
|
48
|
+
// New dot notation from manifest-generator (without plugin prefix)
|
|
49
|
+
"item.text_label_2.fontColor": "green",
|
|
50
|
+
"action.background.pressed_backgroundColor": "black",
|
|
51
|
+
|
|
52
|
+
// New now_playing_item block
|
|
53
|
+
"now_playing_item.text_label_1.fontColor": "yellow",
|
|
54
|
+
"now_playing_item.now_playing_asset.asset": "equalizer.png",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const componentName = "queue_action";
|
|
58
|
+
|
|
59
|
+
const result = parseModalBlocksConfiguration(config, componentName);
|
|
60
|
+
|
|
61
|
+
// Assert header container default state
|
|
62
|
+
expect(result.header.container.default).toEqual({
|
|
63
|
+
backgroundColor: "#000000",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Assert header title pressed state
|
|
67
|
+
// (pressed state will inherit default styles in getAllSpecificStyles if any,
|
|
68
|
+
// but here we just have pressed, so it has default empty from the parser)
|
|
69
|
+
expect(result.header.title.pressed).toEqual({
|
|
70
|
+
fontColor: "#ffffff",
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Assert item background ios default state
|
|
74
|
+
// (mocked platform is ios, so it should be accepted and assigned to default)
|
|
75
|
+
expect(result.item.background.default).toEqual({
|
|
76
|
+
backgroundColor: "blue",
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Assert item textLabel1 focused state
|
|
80
|
+
expect(result.item.textLabel1.focused).toEqual({
|
|
81
|
+
fontSize: 16,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Assert dot notation textLabel2 default state
|
|
85
|
+
expect(result.item.textLabel2.default).toEqual({
|
|
86
|
+
fontColor: "green",
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Assert dot notation action background pressed state
|
|
90
|
+
expect(result.action.background.pressed).toEqual({
|
|
91
|
+
backgroundColor: "black",
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Assert nowPlayingItem states
|
|
95
|
+
expect(result.nowPlayingItem?.textLabel1.default).toEqual({
|
|
96
|
+
fontColor: "yellow",
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect(result.nowPlayingItem?.nowPlayingAsset.default).toEqual({
|
|
100
|
+
asset: "equalizer.png",
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Assert untouched properties remain empty default style objects
|
|
104
|
+
expect(result.button.title).toEqual({ default: {} });
|
|
105
|
+
expect(result.action.leadingIcon).toEqual({ default: {} });
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should map Studio item.background.focus.* onto focused state", () => {
|
|
109
|
+
const result = parseModalBlocksConfiguration(
|
|
110
|
+
{
|
|
111
|
+
"item.background.default.background_color": "transparent",
|
|
112
|
+
"item.background.focus.background_color": "#FF3B30",
|
|
113
|
+
},
|
|
114
|
+
"playlist-experience"
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(result.item.background.default).toEqual(
|
|
118
|
+
expect.objectContaining({
|
|
119
|
+
backgroundColor: "transparent",
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(result.item.background.focused).toEqual(
|
|
124
|
+
expect.objectContaining({
|
|
125
|
+
backgroundColor: "#FF3B30",
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("should accept Studio text_label1 keys without underscore before digit", () => {
|
|
131
|
+
const result = parseModalBlocksConfiguration(
|
|
132
|
+
{
|
|
133
|
+
"item.text_label1.font_color": "#00FF00",
|
|
134
|
+
"item.text_label1.font_size": 28,
|
|
135
|
+
"item.text_label2.font_color": "#00FFFF",
|
|
136
|
+
},
|
|
137
|
+
"playlist-experience"
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
expect(result.item.textLabel1.default).toEqual(
|
|
141
|
+
expect.objectContaining({
|
|
142
|
+
fontColor: "#00FF00",
|
|
143
|
+
fontSize: 28,
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
expect(result.item.textLabel2.default).toEqual(
|
|
148
|
+
expect.objectContaining({
|
|
149
|
+
fontColor: "#00FFFF",
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("should map button.create_new_playlist_asset onto leadingIcon.asset", () => {
|
|
155
|
+
const result = parseModalBlocksConfiguration(
|
|
156
|
+
{
|
|
157
|
+
"button.create_new_playlist_asset":
|
|
158
|
+
"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
|
+
"item.checkbox_asset":
|
|
174
|
+
"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
|
+
"reorder_playlist_item.reorder_handle_asset":
|
|
195
|
+
"https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
|
|
196
|
+
},
|
|
197
|
+
"playlist-experience"
|
|
198
|
+
);
|
|
199
|
+
|
|
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
|
+
);
|
|
206
|
+
});
|
|
207
|
+
|
|
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
|
+
);
|
|
218
|
+
|
|
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
|
+
);
|
|
225
|
+
});
|
|
226
|
+
|
|
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
|
+
);
|
|
237
|
+
|
|
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
|
+
);
|
|
244
|
+
});
|
|
245
|
+
|
|
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
|
+
);
|
|
256
|
+
|
|
257
|
+
expect(result.button.leadingIcon.default?.asset).toBeUndefined();
|
|
258
|
+
expect(result.item.actionButtons.default?.dragAsset).toBeUndefined();
|
|
259
|
+
});
|
|
260
|
+
});
|
|
@@ -11,17 +11,30 @@ const currentPlatform = platformSelect({
|
|
|
11
11
|
android_tv: "android",
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
// Do not change the order
|
|
15
|
-
|
|
14
|
+
// Do not change the order: focused_selected must be first, and "focus" must
|
|
15
|
+
// come *after* "focused". Matching uses startsWith(state + "_"), so putting
|
|
16
|
+
// "focus" first would steal focused_* / focused_selected_* keys. Adding
|
|
17
|
+
// "focus" here affects every getAllSpecificStyles consumer (not only modals);
|
|
18
|
+
// property names that themselves start with focus_ (e.g. focus_font_color as
|
|
19
|
+
// a non-state style) would also be classified as the focus state.
|
|
20
|
+
const states = [
|
|
21
|
+
"focused_selected",
|
|
22
|
+
"pressed",
|
|
23
|
+
"focused",
|
|
24
|
+
"focus",
|
|
25
|
+
"selected",
|
|
26
|
+
"default",
|
|
27
|
+
];
|
|
16
28
|
|
|
17
29
|
const platformSuffixes = ["ios", "tvos", "samsung", "lg", "android"];
|
|
18
|
-
type StateKey = (typeof states)[number]
|
|
30
|
+
type StateKey = (typeof states)[number];
|
|
19
31
|
|
|
20
32
|
export type GetAllSpecificStylesProps = {
|
|
21
33
|
componentName: string;
|
|
22
34
|
subComponentName: string;
|
|
23
35
|
configuration: Record<string, any>;
|
|
24
36
|
outStyles: Record<string, any>;
|
|
37
|
+
styleSeparator?: string;
|
|
25
38
|
};
|
|
26
39
|
|
|
27
40
|
/*
|
|
@@ -35,14 +48,23 @@ export const getAllSpecificStyles = ({
|
|
|
35
48
|
componentName,
|
|
36
49
|
subComponentName,
|
|
37
50
|
outStyles,
|
|
51
|
+
styleSeparator = "_style_",
|
|
38
52
|
}: GetAllSpecificStylesProps) => {
|
|
39
53
|
if (!outStyles) throw new Error("outStyles is required");
|
|
40
54
|
if (!componentName) throw new Error("componentName is required");
|
|
41
55
|
|
|
42
|
-
const
|
|
56
|
+
const prefixes =
|
|
43
57
|
subComponentName?.length > 0
|
|
44
|
-
?
|
|
45
|
-
|
|
58
|
+
? [
|
|
59
|
+
styleSeparator
|
|
60
|
+
? `${componentName}${styleSeparator}${subComponentName}_`
|
|
61
|
+
: `${subComponentName}_`,
|
|
62
|
+
`${componentName}_style_${subComponentName}_`,
|
|
63
|
+
]
|
|
64
|
+
: [
|
|
65
|
+
styleSeparator ? `${componentName}${styleSeparator}` : "",
|
|
66
|
+
`${componentName}_style_`,
|
|
67
|
+
];
|
|
46
68
|
|
|
47
69
|
const defaultKey = "default";
|
|
48
70
|
|
|
@@ -51,12 +73,24 @@ export const getAllSpecificStyles = ({
|
|
|
51
73
|
const tmpGenericDict: Record<StateKey, Record<string, any>> = {};
|
|
52
74
|
const tmpPlatformDict: Record<StateKey, Record<string, any>> = {};
|
|
53
75
|
|
|
54
|
-
const parseKey = (key: string, value: any) => {
|
|
55
|
-
|
|
76
|
+
const parseKey = (key: string, originalKey: string, value: any) => {
|
|
77
|
+
const matchedPrefix = prefixes.find((p) => p && key.startsWith(p));
|
|
78
|
+
|
|
79
|
+
if (!matchedPrefix) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Guard: for empty styleSeparator, if matching modern prefix, require dot in originalKey
|
|
84
|
+
if (
|
|
85
|
+
styleSeparator === "" &&
|
|
86
|
+
matchedPrefix === `${subComponentName}_` &&
|
|
87
|
+
!originalKey.includes(".")
|
|
88
|
+
) {
|
|
56
89
|
return;
|
|
57
90
|
}
|
|
58
91
|
|
|
59
|
-
let styleName = key.slice(
|
|
92
|
+
let styleName = key.slice(matchedPrefix.length);
|
|
93
|
+
|
|
60
94
|
if (!styleName || styleName.startsWith("_")) return;
|
|
61
95
|
|
|
62
96
|
const platform = platformSuffixes.find((prefix) =>
|
|
@@ -84,6 +118,11 @@ export const getAllSpecificStyles = ({
|
|
|
84
118
|
state = defaultKey;
|
|
85
119
|
}
|
|
86
120
|
|
|
121
|
+
// Normalize Studio "focus" keys onto the runtime "focused" state bucket.
|
|
122
|
+
if (state === "focus") {
|
|
123
|
+
state = "focused";
|
|
124
|
+
}
|
|
125
|
+
|
|
87
126
|
if (!styleName) return;
|
|
88
127
|
|
|
89
128
|
const camelCaseKey = toCamelCase(styleName);
|
|
@@ -93,7 +132,8 @@ export const getAllSpecificStyles = ({
|
|
|
93
132
|
};
|
|
94
133
|
|
|
95
134
|
for (const [key, value] of Object.entries(configuration)) {
|
|
96
|
-
|
|
135
|
+
const formattedKey = key.replace(/\./g, "_");
|
|
136
|
+
parseKey(formattedKey, key, value);
|
|
97
137
|
}
|
|
98
138
|
|
|
99
139
|
const allStates = Array.from(
|