@applicaster/zapp-react-native-utils 15.0.0-alpha.4153840309 → 15.0.0-alpha.4200413542
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/ActionExecutorContext.tsx +3 -6
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/adsUtils/__tests__/createVMAP.test.ts +419 -0
- package/adsUtils/index.ts +2 -2
- package/analyticsUtils/README.md +1 -1
- package/analyticsUtils/analyticsMapper.ts +10 -2
- package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
- package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
- package/appUtils/HooksManager/index.ts +10 -10
- package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
- package/appUtils/accessibilityManager/__tests__/utils.test.ts +360 -0
- package/appUtils/accessibilityManager/const.ts +4 -0
- package/appUtils/accessibilityManager/utils.ts +25 -5
- package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
- package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
- package/appUtils/contextKeysManager/contextResolver.ts +51 -22
- package/appUtils/contextKeysManager/index.ts +65 -10
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -0
- package/appUtils/focusManager/index.ios.ts +43 -4
- package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
- package/appUtils/focusManagerAux/utils/index.ts +1 -1
- package/appUtils/focusManagerAux/utils/utils.ios.ts +199 -3
- package/appUtils/keyCodes/keys/keys.web.ts +1 -4
- package/appUtils/orientationHelper.ts +2 -4
- package/appUtils/platform/platformUtils.ts +1 -1
- package/appUtils/playerManager/player.ts +4 -0
- package/appUtils/playerManager/playerNative.ts +29 -16
- package/appUtils/playerManager/usePlayerState.tsx +14 -2
- package/cloudEventsUtils/__tests__/index.test.ts +529 -0
- package/cloudEventsUtils/index.ts +65 -1
- package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
- package/configurationUtils/index.ts +17 -11
- package/dateUtils/__tests__/dayjs.test.ts +330 -0
- package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
- package/errorUtils/__tests__/GeneralError.test.ts +97 -0
- package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
- package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
- package/errorUtils/__tests__/NetworkError.test.ts +202 -0
- package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
- package/errorUtils/__tests__/invariant.test.ts +112 -0
- package/focusManager/aux/index.ts +1 -1
- package/headersUtils/__tests__/headersUtils.test.js +11 -1
- package/headersUtils/index.ts +2 -1
- package/manifestUtils/defaultManifestConfigurations/player.js +125 -11
- package/manifestUtils/platformIsTV.js +13 -0
- package/manifestUtils/tvAction/container/index.js +1 -1
- package/navigationUtils/index.ts +15 -5
- package/numberUtils/__tests__/toNumber.test.ts +12 -0
- package/numberUtils/__tests__/toPositiveNumber.test.ts +165 -0
- package/numberUtils/index.ts +19 -1
- package/package.json +4 -4
- package/pluginUtils/index.ts +4 -0
- package/reactHooks/advertising/index.ts +2 -2
- package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
- package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
- package/reactHooks/cell-click/__tests__/index.test.js +1 -3
- package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
- package/reactHooks/connection/__tests__/index.test.js +1 -1
- package/reactHooks/debugging/__tests__/index.test.js +4 -4
- package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
- package/reactHooks/device/useIsTablet.tsx +14 -19
- package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
- package/reactHooks/events/index.ts +20 -0
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
- package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +4 -1
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
- package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +1 -1
- package/reactHooks/feed/__tests__/{useInflatedUrl.test.ts → useInflatedUrl.test.tsx} +62 -7
- package/reactHooks/feed/useEntryScreenId.ts +2 -2
- package/reactHooks/feed/useInflatedUrl.ts +43 -17
- package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
- package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/__tests__/index.test.tsx +1 -1
- package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
- package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
- package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
- package/reactHooks/navigation/index.ts +27 -11
- package/reactHooks/navigation/useRoute.ts +11 -7
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
- package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
- package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
- package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
- package/reactHooks/resolvers/useCellResolver.ts +6 -2
- package/reactHooks/resolvers/useComponentResolver.ts +8 -2
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
- package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
- package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
- package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +12 -4
- package/reactHooks/screen/useTargetScreenData.ts +4 -2
- package/reactHooks/state/useRefWithInitialValue.ts +10 -0
- package/reactHooks/state/useRivers.ts +1 -1
- package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
- package/reactHooks/usePluginConfiguration.ts +2 -2
- package/reactHooks/utils/__tests__/index.test.js +1 -1
- package/rectUtils/__tests__/index.test.ts +549 -0
- package/rectUtils/index.ts +2 -2
- package/screenPickerUtils/__tests__/index.test.ts +333 -0
- package/screenState/__tests__/index.test.ts +1 -1
- package/searchUtils/const.ts +7 -0
- package/searchUtils/index.ts +3 -0
- package/services/storageServiceSync.web.ts +1 -1
- package/stringUtils/index.ts +1 -1
- package/testUtils/index.tsx +30 -21
- package/time/__tests__/BackgroundTimer.test.ts +156 -0
- package/time/__tests__/Timer.test.ts +236 -0
- package/typeGuards/__tests__/isString.test.ts +21 -0
- package/typeGuards/index.ts +4 -0
- package/utils/__tests__/mergeRight.test.ts +48 -0
- package/utils/__tests__/selectors.test.ts +124 -0
- package/utils/index.ts +13 -0
- package/utils/mergeRight.ts +5 -0
- package/utils/path.ts +6 -3
- package/utils/pathOr.ts +5 -1
- package/utils/selectors.ts +46 -0
- package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +34 -11
- package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
- package/reactHooks/componentsMap/index.ts +0 -55
|
@@ -3,6 +3,41 @@ import { RequestBuilder } from "@applicaster/zapp-pipes-v2-client";
|
|
|
3
3
|
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
4
4
|
import { getAppUrlScheme } from "@applicaster/zapp-react-native-utils/appDataUtils";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* CloudEvents v1.0 compliant event object
|
|
8
|
+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
|
|
9
|
+
*/
|
|
10
|
+
export interface CloudEvent<T = any> {
|
|
11
|
+
/** CloudEvents specification version (always "1.0") */
|
|
12
|
+
specversion: "1.0";
|
|
13
|
+
/** Type of event (e.g., "user.action", "commerce.purchase") */
|
|
14
|
+
type: string;
|
|
15
|
+
/** Identifier for the entity that produced the event */
|
|
16
|
+
source: string;
|
|
17
|
+
/** Unique identifier for the event */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Subject of the event in the context of the event producer */
|
|
20
|
+
subject: string;
|
|
21
|
+
/** Timestamp of when the event occurred (ISO 8601 format) */
|
|
22
|
+
time: string;
|
|
23
|
+
/** Content type of the data attribute (always "application/json") */
|
|
24
|
+
datacontenttype: "application/json";
|
|
25
|
+
/** Event payload */
|
|
26
|
+
data: T;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Parameters required to create a cloud event
|
|
31
|
+
*/
|
|
32
|
+
export interface CreateCloudEventParams<T = any> {
|
|
33
|
+
/** Type of event (e.g., "user.action", "commerce.purchase") */
|
|
34
|
+
type: string;
|
|
35
|
+
/** Subject of the event in the context of the event producer */
|
|
36
|
+
subject: string;
|
|
37
|
+
/** Event payload */
|
|
38
|
+
data: T;
|
|
39
|
+
}
|
|
40
|
+
|
|
6
41
|
let source: string | null = null;
|
|
7
42
|
|
|
8
43
|
const addSource = async () => {
|
|
@@ -26,7 +61,36 @@ const addSource = async () => {
|
|
|
26
61
|
return source;
|
|
27
62
|
};
|
|
28
63
|
|
|
29
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Resets the cached CloudEvents source.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
* @testonly This function is intended for test use only and will only work in test environments.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* This function clears the cached source value, forcing the next call to `createCloudEvent`
|
|
72
|
+
* to regenerate the source from app metadata. It only operates when NODE_ENV is set to "test"
|
|
73
|
+
* to prevent accidental misuse in production code.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // In Jest tests
|
|
78
|
+
* beforeEach(() => {
|
|
79
|
+
* resetCloudEventsSource();
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export const resetCloudEventsSource = (): void => {
|
|
84
|
+
if (process.env.NODE_ENV === "test") {
|
|
85
|
+
source = null;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const createCloudEvent = async <T = any>({
|
|
90
|
+
type,
|
|
91
|
+
subject,
|
|
92
|
+
data,
|
|
93
|
+
}: CreateCloudEventParams<T>): Promise<CloudEvent<T>> => {
|
|
30
94
|
return {
|
|
31
95
|
specversion: "1.0",
|
|
32
96
|
type,
|
|
@@ -31,4 +31,42 @@ describe("imageSrcFromMediaItem", () => {
|
|
|
31
31
|
|
|
32
32
|
expect(imageSrcFromMediaItem(badEntry, ["image_base"])).toBeUndefined();
|
|
33
33
|
});
|
|
34
|
+
|
|
35
|
+
it("returns undefined when fallback is false and key is not found", () => {
|
|
36
|
+
const result = imageSrcFromMediaItem(entry as ZappEntry, [
|
|
37
|
+
"does_not_exist",
|
|
38
|
+
false,
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
expect(result).toBeUndefined();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("returns src when fallback is false and key is found", () => {
|
|
45
|
+
const result = imageSrcFromMediaItem(entry as ZappEntry, [
|
|
46
|
+
"logo_thumbnail",
|
|
47
|
+
false,
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
expect(result).toEqual(entry.media_group[1].media_item[0].src);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("returns image_base as fallback when fallback is explicitly true and key is not found", () => {
|
|
54
|
+
const result = imageSrcFromMediaItem(entry as ZappEntry, [
|
|
55
|
+
"does_not_exist",
|
|
56
|
+
true,
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
const fallback = entry.media_group[0].media_item[0];
|
|
60
|
+
expect(result).toEqual(fallback.src);
|
|
61
|
+
expect(fallback.key).toBe("image_base");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("returns src when fallback is explicitly true and key is found", () => {
|
|
65
|
+
const result = imageSrcFromMediaItem(entry as ZappEntry, [
|
|
66
|
+
"logo_thumbnail",
|
|
67
|
+
true,
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
expect(result).toEqual(entry.media_group[1].media_item[0].src);
|
|
71
|
+
});
|
|
34
72
|
});
|
|
@@ -50,7 +50,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
expect(outStyles).toHaveProperty("default");
|
|
53
|
-
expect(outStyles
|
|
53
|
+
expect(outStyles.default).toEqual({});
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
it("should handle empty configuration", () => {
|
|
@@ -83,7 +83,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
83
83
|
outStyles,
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
expect(outStyles
|
|
86
|
+
expect(outStyles.default).toEqual({
|
|
87
87
|
backgroundColor: "#FF0000",
|
|
88
88
|
borderWidth: 2,
|
|
89
89
|
});
|
|
@@ -104,7 +104,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
104
104
|
outStyles,
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
expect(outStyles
|
|
107
|
+
expect(outStyles.default).toEqual({
|
|
108
108
|
backgroundColor: "#FF0000",
|
|
109
109
|
textSize: 16,
|
|
110
110
|
});
|
|
@@ -126,7 +126,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
126
126
|
outStyles,
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
expect(outStyles
|
|
129
|
+
expect(outStyles.default).toEqual({
|
|
130
130
|
backgroundColor: "#FF0000",
|
|
131
131
|
});
|
|
132
132
|
});
|
|
@@ -148,11 +148,11 @@ describe("getAllSpecificStyles", () => {
|
|
|
148
148
|
outStyles,
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
-
expect(outStyles
|
|
151
|
+
expect(outStyles.default).toEqual({
|
|
152
152
|
backgroundColor: "#FF0000",
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
-
expect(outStyles
|
|
155
|
+
expect(outStyles.pressed).toEqual({
|
|
156
156
|
backgroundColor: "#00FF00",
|
|
157
157
|
});
|
|
158
158
|
});
|
|
@@ -171,7 +171,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
171
171
|
outStyles,
|
|
172
172
|
});
|
|
173
173
|
|
|
174
|
-
expect(outStyles
|
|
174
|
+
expect(outStyles.focused).toEqual({
|
|
175
175
|
borderWidth: 3,
|
|
176
176
|
});
|
|
177
177
|
});
|
|
@@ -190,7 +190,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
190
190
|
outStyles,
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
-
expect(outStyles
|
|
193
|
+
expect(outStyles.selected).toEqual({
|
|
194
194
|
opacity: 0.5,
|
|
195
195
|
});
|
|
196
196
|
});
|
|
@@ -209,7 +209,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
209
209
|
outStyles,
|
|
210
210
|
});
|
|
211
211
|
|
|
212
|
-
expect(outStyles
|
|
212
|
+
expect(outStyles.focused_selected).toEqual({
|
|
213
213
|
scale: 1.2,
|
|
214
214
|
});
|
|
215
215
|
});
|
|
@@ -232,21 +232,21 @@ describe("getAllSpecificStyles", () => {
|
|
|
232
232
|
outStyles,
|
|
233
233
|
});
|
|
234
234
|
|
|
235
|
-
expect(outStyles
|
|
235
|
+
expect(outStyles.default).toEqual({
|
|
236
236
|
backgroundColor: "#FF0000",
|
|
237
237
|
borderWidth: 1,
|
|
238
238
|
opacity: 1,
|
|
239
239
|
});
|
|
240
240
|
|
|
241
241
|
// Pressed should have default styles merged with its specific override
|
|
242
|
-
expect(outStyles
|
|
242
|
+
expect(outStyles.pressed).toEqual({
|
|
243
243
|
backgroundColor: "#00FF00", // Override
|
|
244
244
|
borderWidth: 1, // From default
|
|
245
245
|
opacity: 1, // From default
|
|
246
246
|
});
|
|
247
247
|
|
|
248
248
|
// Focused should have default styles merged with its specific override
|
|
249
|
-
expect(outStyles
|
|
249
|
+
expect(outStyles.focused).toEqual({
|
|
250
250
|
backgroundColor: "#FF0000", // From default
|
|
251
251
|
borderWidth: 1, // From default
|
|
252
252
|
opacity: 0.8, // Override
|
|
@@ -270,7 +270,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
270
270
|
outStyles,
|
|
271
271
|
});
|
|
272
272
|
|
|
273
|
-
expect(outStyles
|
|
273
|
+
expect(outStyles.pressed).toEqual({
|
|
274
274
|
existingKey: "existingValue", // Should be preserved
|
|
275
275
|
backgroundColor: "#FF0000", // From default
|
|
276
276
|
textColor: "#FFFFFF", // New pressed style
|
|
@@ -294,7 +294,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
294
294
|
outStyles,
|
|
295
295
|
});
|
|
296
296
|
|
|
297
|
-
expect(outStyles
|
|
297
|
+
expect(outStyles.default).toEqual({
|
|
298
298
|
backgroundColor: "#FF0000", // Samsung-specific should be included
|
|
299
299
|
});
|
|
300
300
|
});
|
|
@@ -317,7 +317,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
317
317
|
outStyles,
|
|
318
318
|
});
|
|
319
319
|
|
|
320
|
-
expect(outStyles
|
|
320
|
+
expect(outStyles.default).toEqual({
|
|
321
321
|
backgroundColor: "#FFFFFF", // Only non-platform specific
|
|
322
322
|
});
|
|
323
323
|
});
|
|
@@ -336,7 +336,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
336
336
|
outStyles,
|
|
337
337
|
});
|
|
338
338
|
|
|
339
|
-
expect(outStyles
|
|
339
|
+
expect(outStyles.default).toEqual({
|
|
340
340
|
color: "#FF0000",
|
|
341
341
|
});
|
|
342
342
|
});
|
|
@@ -356,7 +356,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
356
356
|
outStyles,
|
|
357
357
|
});
|
|
358
358
|
|
|
359
|
-
expect(outStyles
|
|
359
|
+
expect(outStyles.pressed).toEqual({
|
|
360
360
|
backgroundColor: "#FF0000", // Only samsung style
|
|
361
361
|
});
|
|
362
362
|
});
|
|
@@ -377,7 +377,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
377
377
|
outStyles,
|
|
378
378
|
});
|
|
379
379
|
|
|
380
|
-
expect(outStyles
|
|
380
|
+
expect(outStyles.default).toEqual({
|
|
381
381
|
backgroundColor: "#00FF00", // Samsung-specific should win
|
|
382
382
|
});
|
|
383
383
|
});
|
|
@@ -412,14 +412,14 @@ describe("getAllSpecificStyles", () => {
|
|
|
412
412
|
outStyles,
|
|
413
413
|
});
|
|
414
414
|
|
|
415
|
-
expect(outStyles
|
|
415
|
+
expect(outStyles.default).toEqual({
|
|
416
416
|
backgroundColor: "#FFFFFF",
|
|
417
417
|
textColor: "#000000",
|
|
418
418
|
borderWidth: 1,
|
|
419
419
|
padding: 10,
|
|
420
420
|
});
|
|
421
421
|
|
|
422
|
-
expect(outStyles
|
|
422
|
+
expect(outStyles.pressed).toEqual({
|
|
423
423
|
backgroundColor: "#EEEEEE",
|
|
424
424
|
textColor: "#000000",
|
|
425
425
|
borderWidth: 1,
|
|
@@ -427,7 +427,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
427
427
|
opacity: 0.8,
|
|
428
428
|
});
|
|
429
429
|
|
|
430
|
-
expect(outStyles
|
|
430
|
+
expect(outStyles.focused).toEqual({
|
|
431
431
|
backgroundColor: "#FFFFFF",
|
|
432
432
|
textColor: "#000000",
|
|
433
433
|
borderWidth: 1,
|
|
@@ -453,7 +453,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
453
453
|
outStyles,
|
|
454
454
|
});
|
|
455
455
|
|
|
456
|
-
expect(outStyles
|
|
456
|
+
expect(outStyles.default).toEqual({
|
|
457
457
|
validKey: "included",
|
|
458
458
|
});
|
|
459
459
|
});
|
|
@@ -474,11 +474,11 @@ describe("getAllSpecificStyles", () => {
|
|
|
474
474
|
outStyles,
|
|
475
475
|
});
|
|
476
476
|
|
|
477
|
-
expect(outStyles
|
|
477
|
+
expect(outStyles.focused_selected).toEqual({
|
|
478
478
|
test: "focused_selected_value",
|
|
479
479
|
});
|
|
480
480
|
|
|
481
|
-
expect(outStyles
|
|
481
|
+
expect(outStyles.focused).toEqual({
|
|
482
482
|
another: "focused_value",
|
|
483
483
|
});
|
|
484
484
|
});
|
|
@@ -517,7 +517,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
517
517
|
outStyles,
|
|
518
518
|
});
|
|
519
519
|
|
|
520
|
-
expect(outStyles
|
|
520
|
+
expect(outStyles.pressed.backgroundColor).toBe("#222222");
|
|
521
521
|
});
|
|
522
522
|
|
|
523
523
|
it("should handle frozen outStyles properties", () => {
|
|
@@ -537,7 +537,7 @@ describe("getAllSpecificStyles", () => {
|
|
|
537
537
|
});
|
|
538
538
|
|
|
539
539
|
// Should create new object instead of mutating frozen one
|
|
540
|
-
expect(outStyles
|
|
540
|
+
expect(outStyles.default).toEqual({
|
|
541
541
|
existingProp: "value",
|
|
542
542
|
backgroundColor: "#FF0000",
|
|
543
543
|
});
|
|
@@ -155,9 +155,9 @@ export function getMediaItems(entry: ZappEntry): Option<ZappMediaItem[]> {
|
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
157
|
* Retrieves the "src" value from a media item in the entry's media group,
|
|
158
|
-
* based on a provided key, with fallback logic.
|
|
158
|
+
* based on a provided key, with optional fallback logic.
|
|
159
159
|
*
|
|
160
|
-
* Fallback order:
|
|
160
|
+
* Fallback order (when enabled):
|
|
161
161
|
* 1. Attempts to find a media item with the specified key (or "image_base" if none provided).
|
|
162
162
|
* 2. If not found, attempts to find a media item with the key "image_base".
|
|
163
163
|
* 3. If still not found, falls back to the first available media item.
|
|
@@ -166,15 +166,19 @@ export function getMediaItems(entry: ZappEntry): Option<ZappMediaItem[]> {
|
|
|
166
166
|
* since empty URIs are invalid in some platforms (e.g., React Native).
|
|
167
167
|
*
|
|
168
168
|
* @param {ZappEntry} entry - The entry object containing a media group.
|
|
169
|
-
* @param {string[] | unknown} arg -
|
|
169
|
+
* @param {string[] | unknown} arg - Can be an array or any other value (treated as empty array).
|
|
170
|
+
* When an array:
|
|
171
|
+
* - First element: The key to look up. If omitted or undefined, defaults to "image_base".
|
|
172
|
+
* - Second element: Boolean to enable/disable fallback logic. If omitted or undefined, defaults to true.
|
|
170
173
|
* @returns {?string} The "src" URI from the matched media item, or undefined if not found or empty.
|
|
171
174
|
*/
|
|
172
175
|
export function imageSrcFromMediaItem(
|
|
173
176
|
entry: ZappEntry,
|
|
174
177
|
arg: string[] | unknown
|
|
175
178
|
): Option<string> {
|
|
176
|
-
const args:
|
|
179
|
+
const args: any = R.unless(Array.isArray, Array)(arg || []);
|
|
177
180
|
const imageKey: string = args?.[0] || "image_base"; // always a single key in this function
|
|
181
|
+
const fallback: boolean = args?.[1] !== false;
|
|
178
182
|
|
|
179
183
|
const mediaItems = getMediaItems(entry);
|
|
180
184
|
|
|
@@ -185,14 +189,16 @@ export function imageSrcFromMediaItem(
|
|
|
185
189
|
// Try to find the item with the given key
|
|
186
190
|
let foundItem = mediaItems.find((item) => item.key === imageKey);
|
|
187
191
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
+
if (fallback) {
|
|
193
|
+
// If not found and key was not "image_base", try to find "image_base"
|
|
194
|
+
if (!foundItem && imageKey !== "image_base") {
|
|
195
|
+
foundItem = mediaItems.find((item) => item.key === "image_base");
|
|
196
|
+
}
|
|
192
197
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
// If still not found, default to first item
|
|
199
|
+
if (!foundItem) {
|
|
200
|
+
foundItem = mediaItems[0];
|
|
201
|
+
}
|
|
196
202
|
}
|
|
197
203
|
|
|
198
204
|
const src = foundItem?.src;
|