@applicaster/zapp-react-native-utils 16.0.0-rc.98 → 17.0.0-alpha.1037440043
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/actionUtils/index.ts +3 -1
- package/actionsExecutor/ActionExecutor.ts +2 -2
- package/actionsExecutor/ActionExecutorContext.tsx +2 -2
- package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
- package/actionsExecutor/__tests__/feedDecorator.test.ts +30 -0
- package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +186 -5
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +72 -0
- package/actionsExecutor/actions/appRestart.ts +2 -2
- package/actionsExecutor/actions/confirmDialog.ts +2 -2
- package/actionsExecutor/actions/dismissBottomSheet.ts +2 -2
- package/actionsExecutor/actions/goBack.ts +2 -2
- package/actionsExecutor/actions/goHome.ts +2 -2
- package/actionsExecutor/actions/navigateToScreen.ts +35 -45
- package/actionsExecutor/actions/openBottomSheet.ts +4 -2
- package/actionsExecutor/actions/presentScreen.ts +2 -2
- package/actionsExecutor/actions/refreshComponent.ts +2 -2
- package/actionsExecutor/actions/screenToggleFlag.ts +1 -3
- package/actionsExecutor/actions/sendCloudEvent.ts +2 -2
- package/actionsExecutor/actions/showAlert.ts +2 -2
- package/actionsExecutor/actions/switchLayout.ts +2 -2
- package/actionsExecutor/feedDecorator.ts +8 -2
- package/actionsExecutor/types.ts +7 -0
- package/analyticsUtils/__tests__/playerAnalyticsSafeguard.test.ts +62 -0
- package/analyticsUtils/logger.ts +9 -4
- package/analyticsUtils/playerAnalyticsTracker.ts +1 -0
- package/appUtils/HooksManager/logger.ts +5 -2
- package/appUtils/accessibilityManager/logger.ts +2 -4
- package/appUtils/accessibilityManager/utils.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -22
- package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
- package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
- package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +0 -25
- package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
- package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
- package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
- package/appUtils/contextKeysManager/index.ts +30 -131
- package/appUtils/focusManager/__tests__/focusManager.test.js +33 -0
- package/appUtils/focusManager/__tests__/focusToolbox.test.ts +357 -0
- package/appUtils/focusManager/focusToolbox.ts +223 -0
- package/appUtils/focusManager/index.ios.ts +7 -1
- package/appUtils/focusManager/index.ts +3 -3
- package/appUtils/focusManager/logger.ts +2 -2
- package/appUtils/focusManagerAux/index.ts +2 -2
- package/appUtils/orientationHelper.ts +2 -2
- package/appUtils/platform/platformUtils.ts +2 -2
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +1 -1
- package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerNative.test.ts +76 -0
- package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
- package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
- package/appUtils/playerManager/const.ts +13 -0
- package/appUtils/playerManager/index.ts +9 -2
- package/appUtils/playerManager/player.ts +26 -1
- package/appUtils/playerManager/playerNative.ts +23 -1
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/appUtils/playerManager/playerToolbox.ts +196 -0
- package/appUtils/playerManager/usePlayNextOverlay.tsx +2 -2
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
- package/appUtils/playerManager/userCellPlayerMutedPreference.ts +1 -1
- package/appUtils/playerManager/userLanguagePreference.ts +1 -1
- package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
- package/arrayUtils/index.ts +26 -43
- package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
- package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
- package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
- package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
- package/cellUtils/index.ts +40 -0
- package/cellUtils/logger.ts +2 -2
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +134 -0
- package/configurationUtils/modalBlocksParser.ts +38 -0
- package/domUtils/logger.ts +2 -2
- package/entryActions/aliasPresentation.ts +1 -0
- package/entryActions/buildEntryActions.ts +1 -1
- package/focusManager/FocusManager.ts +26 -0
- package/focusManager/__tests__/FocusManager.test.ts +9 -0
- package/focusManager/logger.ts +2 -6
- package/headersUtils/index.ts +2 -2
- package/localizationUtils/index.ts +12 -6
- package/logger/__tests__/subsystems.test.ts +148 -0
- package/logger/__tests__/xrayToolbox.test.ts +69 -0
- package/logger/index.ts +48 -9
- package/logger/subsystems.ts +112 -0
- package/logger/xrayToolbox.ts +69 -0
- package/manifestUtils/__tests__/createConfig.test.js +17 -7
- package/manifestUtils/_internals/getDefaultConfiguration.js +9 -11
- package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
- package/manifestUtils/keys.js +7 -2
- package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
- package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
- package/manifestUtils/mobileAction/groups/defaults.js +2 -1
- package/modalState/EditableCollectionRegistry.ts +1 -1
- package/modalState/ModalOrchestrator.ts +1 -0
- package/modalState/RemoteEditableCollection.ts +1 -1
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +23 -0
- package/modalState/index.ts +2 -0
- package/modalState/types.ts +11 -0
- package/navigationUtils/index.ts +5 -2
- package/navigationUtils/xrayNavigator.ts +12 -0
- package/numberUtils/index.ts +2 -2
- package/package.json +3 -2
- package/playerUtils/PlayerTTS/PlayerTTS.ts +1 -1
- package/playerUtils/imaScriptDom.ts +1 -1
- package/playerUtils/useValidatePlayerConfig.tsx +1 -1
- package/pluginUtils/logger.ts +2 -2
- package/quickBrickAssets/__tests__/index.test.ts +18 -0
- package/quickBrickAssets/index.ts +35 -0
- package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
- package/reactHooks/actions/index.ts +29 -23
- package/reactHooks/cell-click/__tests__/index.test.js +67 -1
- package/reactHooks/cell-click/index.ts +10 -2
- package/reactHooks/connection/index.tsx +8 -5
- package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
- package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
- package/reactHooks/feed/useBuildPipesUrl.ts +5 -2
- package/reactHooks/feed/useFeedLoader.tsx +30 -3
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
- package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
- package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +5 -2
- package/reactHooks/logger.ts +5 -2
- package/reactHooks/navigation/usePresentScreen.ts +2 -2
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +2 -2
- package/reactHooks/screen/useScreenData.ts +2 -2
- package/reactHooks/usePluginConfiguration.ts +84 -46
- package/reactHooks/videoModal/hooks/useChangeOrientation.ts +2 -7
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +1 -1
- package/reactUtils/createContext/helpers.ts +2 -2
- package/reactUtils/logger.ts +2 -2
- package/riverComponetsMeasurementProvider/index.tsx +5 -5
- package/storage/ScreenSingleValueProvider.ts +1 -1
- package/storage/ScreenStateMultiSelectProvider.ts +1 -1
- package/storage/StorageMultiSelectProvider.ts +1 -1
- package/storage/StorageSingleSelectProvider.ts +1 -1
- package/stylesUtils/logger.ts +2 -2
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +26 -0
- package/uiActionsRegistrator/registry.ts +17 -1
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +1 -1
- package/uiActionsRegistrator/usableActionItems.ts +1 -1
- package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +2 -1
- package/zappFrameworkUtils/loginPluginUtils.ts +2 -1
- package/zappFrameworkUtils/presentPluginOneTime.ts +2 -1
- package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
- package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
- package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
- package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
- package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
- package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
- package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
- package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
|
@@ -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
|
};
|
package/domUtils/logger.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { subsystemLogger } from "../logger";
|
|
2
2
|
|
|
3
|
-
export const domUtilsLogger =
|
|
3
|
+
export const domUtilsLogger = subsystemLogger("core/dom", "DomUtils");
|
|
@@ -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
|
});
|
package/focusManager/logger.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const { Logger } = getXray();
|
|
1
|
+
import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
3
2
|
|
|
4
|
-
export const logger =
|
|
5
|
-
"QuickBrick",
|
|
6
|
-
"packages/zapp-react-native-utils/focusManager/FocusManager"
|
|
7
|
-
);
|
|
3
|
+
export const logger = subsystemLogger("ui/focus", "FocusManager");
|
package/headersUtils/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
2
2
|
import { getPlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
3
|
-
import {
|
|
3
|
+
import { subsystemLogger } from "../logger";
|
|
4
4
|
import { getUILanguage } from "../localizationUtils";
|
|
5
5
|
|
|
6
|
-
const logger =
|
|
6
|
+
const logger = subsystemLogger("network/headers", "HeadersUtils");
|
|
7
7
|
|
|
8
8
|
export const getAppDataHeaders = (screenId: string) => {
|
|
9
9
|
const appData = appStore.get("appData");
|
|
@@ -28,17 +28,23 @@ const RTL_LOCALES = [
|
|
|
28
28
|
"yi", // Yiddish
|
|
29
29
|
];
|
|
30
30
|
|
|
31
|
+
// The strings for the UI language, else the first language present
|
|
32
|
+
export const getLocalizedStrings = (
|
|
33
|
+
localizations = {},
|
|
34
|
+
languageCode = getUILanguage()
|
|
35
|
+
) =>
|
|
36
|
+
localizations?.[languageCode] ||
|
|
37
|
+
Object.values(localizations).find(
|
|
38
|
+
(value) => typeof value === "object" && value !== null
|
|
39
|
+
) ||
|
|
40
|
+
{};
|
|
41
|
+
|
|
31
42
|
export function useLocalizedStrings({ localizations = {} }) {
|
|
32
43
|
const languageCode = getUILanguage();
|
|
33
44
|
|
|
34
45
|
// TODO: probably we can call getLocalizations here from localizationsHelper.js
|
|
35
46
|
const result = useMemo(
|
|
36
|
-
() =>
|
|
37
|
-
localizations?.[languageCode] ||
|
|
38
|
-
Object.values(localizations).find(
|
|
39
|
-
(value) => typeof value === "object" && value !== null
|
|
40
|
-
) ||
|
|
41
|
-
{},
|
|
47
|
+
() => getLocalizedStrings(localizations, languageCode),
|
|
42
48
|
[languageCode, localizations]
|
|
43
49
|
);
|
|
44
50
|
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import { PLUGIN_KINDS, XRAY_SUBSYSTEMS } from "../subsystems";
|
|
5
|
+
|
|
6
|
+
const REPO_ROOT = path.resolve(__dirname, "../../../..");
|
|
7
|
+
const SOURCE_DIRS = ["packages", "plugins"];
|
|
8
|
+
|
|
9
|
+
const SKIP_DIRS = new Set([
|
|
10
|
+
"node_modules",
|
|
11
|
+
"__tests__",
|
|
12
|
+
"__mocks__",
|
|
13
|
+
"dist",
|
|
14
|
+
"lib",
|
|
15
|
+
"android",
|
|
16
|
+
"ios",
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
const SHARED_LOGGER_DIR = "packages/zapp-react-native-utils/logger/";
|
|
20
|
+
|
|
21
|
+
// `subsystem: "x"`, `anySubsystem = "x"`, `subsystemLogger("x"` and `new Logger("Category", "x"`
|
|
22
|
+
const SUBSYSTEM_LITERALS = [
|
|
23
|
+
/\bsubsystem:\s*"([^"]+)"/g,
|
|
24
|
+
/\b\w*(?:Subsystem|SUBSYSTEM)\s*=\s*"([^"]+)"/g,
|
|
25
|
+
/\bsubsystemLogger\(\s*"([^"]+)"/g,
|
|
26
|
+
/\bnew Logger\(\s*"[^"]*"\s*,\s*"([^"]+)"/g,
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const PLUGIN_NODE = new RegExp(
|
|
30
|
+
`^plugins/(?:${PLUGIN_KINDS.join("|")})/[a-z0-9_]+(/[a-z0-9_]+)?$`
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// A template string is built at runtime, so it cannot be checked against the tree.
|
|
34
|
+
const TEMPLATE_SUBSYSTEMS = [
|
|
35
|
+
/\bsubsystem:\s*`/,
|
|
36
|
+
/\b\w*(?:Subsystem|SUBSYSTEM)\s*=\s*`/,
|
|
37
|
+
/\bsubsystemLogger\(\s*`/,
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const SHARED_CREATE_LOGGER_IMPORT =
|
|
41
|
+
/import\s*\{[^}]*\bcreateLogger\b[^}]*\}\s*from\s*"@applicaster\/zapp-react-native-utils\/logger"/;
|
|
42
|
+
|
|
43
|
+
// Inside zapp-react-native-utils the shared logger is imported by a relative path.
|
|
44
|
+
const RELATIVE_CREATE_LOGGER_IMPORT =
|
|
45
|
+
/import\s*\{[^}]*\bcreateLogger\b[^}]*\}\s*from\s*"(?:\.\.\/)+logger"/;
|
|
46
|
+
|
|
47
|
+
const CREATE_LOGGER_CALLS = /\bcreateLogger\(\s*(\{[^}]*\})?\s*\)/g;
|
|
48
|
+
|
|
49
|
+
// Native-side keys read by the X-Ray sinks, not nodes of the tree.
|
|
50
|
+
const NOT_TREE_NODES = new Set(["xray", "xray/logger"]);
|
|
51
|
+
|
|
52
|
+
// The default player moves onto the tree in its own change; its old names are not checked until then.
|
|
53
|
+
const LEFT_OUT = ["plugins/zapp-react-native-default-player/"];
|
|
54
|
+
|
|
55
|
+
const sourceFiles = (dir: string): string[] =>
|
|
56
|
+
fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
57
|
+
if (entry.isDirectory()) {
|
|
58
|
+
return SKIP_DIRS.has(entry.name)
|
|
59
|
+
? []
|
|
60
|
+
: sourceFiles(path.join(dir, entry.name));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return /\.(ts|tsx|js|jsx)$/.test(entry.name) &&
|
|
64
|
+
!entry.name.endsWith(".d.ts")
|
|
65
|
+
? [path.join(dir, entry.name)]
|
|
66
|
+
: [];
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Commented-out code does not log.
|
|
70
|
+
const loggingSources = () =>
|
|
71
|
+
SOURCE_DIRS.flatMap((dir) => sourceFiles(path.join(REPO_ROOT, dir)))
|
|
72
|
+
.map((file) => path.relative(REPO_ROOT, file))
|
|
73
|
+
.filter((file) => !LEFT_OUT.some((dir) => file.startsWith(dir)))
|
|
74
|
+
.map((file) => ({
|
|
75
|
+
file,
|
|
76
|
+
text: fs
|
|
77
|
+
.readFileSync(path.join(REPO_ROOT, file), "utf8")
|
|
78
|
+
.replace(/^\s*\/\/.*$/gm, ""),
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
const usesSharedCreateLogger = (file: string, text: string) =>
|
|
82
|
+
SHARED_CREATE_LOGGER_IMPORT.test(text) ||
|
|
83
|
+
(file.startsWith("packages/zapp-react-native-utils/") &&
|
|
84
|
+
RELATIVE_CREATE_LOGGER_IMPORT.test(text));
|
|
85
|
+
|
|
86
|
+
describe("X-Ray subsystems", () => {
|
|
87
|
+
const sources = loggingSources();
|
|
88
|
+
|
|
89
|
+
it("only uses nodes of the subsystem tree", () => {
|
|
90
|
+
const known = new Set<string>(XRAY_SUBSYSTEMS);
|
|
91
|
+
const unknown: string[] = [];
|
|
92
|
+
|
|
93
|
+
sources.forEach(({ file, text }) => {
|
|
94
|
+
SUBSYSTEM_LITERALS.forEach((pattern) => {
|
|
95
|
+
Array.from(text.matchAll(pattern)).forEach((match) => {
|
|
96
|
+
const node = match[1];
|
|
97
|
+
|
|
98
|
+
if (
|
|
99
|
+
!known.has(node) &&
|
|
100
|
+
!PLUGIN_NODE.test(node) &&
|
|
101
|
+
!NOT_TREE_NODES.has(node)
|
|
102
|
+
) {
|
|
103
|
+
unknown.push(`${file}: "${node}"`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Add the node to the tree (xray-subsystems skill in Zapp-Frameworks) and to XRAY_SUBSYSTEMS first.
|
|
110
|
+
expect(unknown).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("does not build a subsystem from a template string", () => {
|
|
114
|
+
const templates = sources
|
|
115
|
+
.filter(
|
|
116
|
+
({ file, text }) =>
|
|
117
|
+
!file.startsWith(SHARED_LOGGER_DIR) &&
|
|
118
|
+
TEMPLATE_SUBSYSTEMS.some((pattern) => pattern.test(text))
|
|
119
|
+
)
|
|
120
|
+
.map(({ file }) => file);
|
|
121
|
+
|
|
122
|
+
expect(templates).toEqual([]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("does not call the shared createLogger without a subsystem", () => {
|
|
126
|
+
const missing = sources
|
|
127
|
+
.filter(({ file, text }) => usesSharedCreateLogger(file, text))
|
|
128
|
+
.flatMap(({ file, text }) =>
|
|
129
|
+
Array.from(text.matchAll(CREATE_LOGGER_CALLS))
|
|
130
|
+
.filter(([, args]) => !/\bsubsystem\b/.test(args ?? ""))
|
|
131
|
+
.map(([call]) => `${file}: ${call}`)
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect(missing).toEqual([]);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("creates loggers through the shared logger module, not new Logger", () => {
|
|
138
|
+
const direct = sources
|
|
139
|
+
.filter(
|
|
140
|
+
({ file, text }) =>
|
|
141
|
+
!file.startsWith(SHARED_LOGGER_DIR) && /\bnew Logger\(/.test(text)
|
|
142
|
+
)
|
|
143
|
+
.map(({ file }) => file);
|
|
144
|
+
|
|
145
|
+
// Use subsystemLogger(subsystem, category).
|
|
146
|
+
expect(direct).toEqual([]);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const xray = require("@applicaster/quick-brick-xray");
|
|
2
|
+
|
|
3
|
+
const toolbox = { name: "test", description: "", tools: [] };
|
|
4
|
+
|
|
5
|
+
const load = (): typeof import("../xrayToolbox") => {
|
|
6
|
+
let module;
|
|
7
|
+
|
|
8
|
+
jest.isolateModules(() => {
|
|
9
|
+
module = require("../xrayToolbox");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
return module;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe("registerXrayToolbox", () => {
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
delete xray.registerReactToolbox;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("registers once per name", async () => {
|
|
21
|
+
xray.registerReactToolbox = jest.fn().mockResolvedValue(undefined);
|
|
22
|
+
const { registerXrayToolbox } = load();
|
|
23
|
+
|
|
24
|
+
await expect(registerXrayToolbox(toolbox)).resolves.toBe(true);
|
|
25
|
+
await expect(registerXrayToolbox(toolbox)).resolves.toBe(true);
|
|
26
|
+
|
|
27
|
+
expect(xray.registerReactToolbox).toHaveBeenCalledTimes(1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("resolves false without a toolbox API", async () => {
|
|
31
|
+
await expect(load().registerXrayToolbox(toolbox)).resolves.toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("keeps a failed registration instead of retrying it", async () => {
|
|
35
|
+
xray.registerReactToolbox = jest
|
|
36
|
+
.fn()
|
|
37
|
+
.mockRejectedValue(new Error("XRayToolboxBridge is not available"));
|
|
38
|
+
|
|
39
|
+
const { registerXrayToolbox } = load();
|
|
40
|
+
|
|
41
|
+
await expect(registerXrayToolbox(toolbox)).resolves.toBe(false);
|
|
42
|
+
await expect(registerXrayToolbox(toolbox)).resolves.toBe(false);
|
|
43
|
+
|
|
44
|
+
expect(xray.registerReactToolbox).toHaveBeenCalledTimes(1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("registers new tools under the same name again (Fast Refresh)", async () => {
|
|
48
|
+
xray.registerReactToolbox = jest.fn().mockResolvedValue(undefined);
|
|
49
|
+
const { registerXrayToolbox } = load();
|
|
50
|
+
|
|
51
|
+
await registerXrayToolbox(toolbox);
|
|
52
|
+
await registerXrayToolbox({ ...toolbox, tools: [] });
|
|
53
|
+
|
|
54
|
+
expect(xray.registerReactToolbox).toHaveBeenCalledTimes(2);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("stops trying every toolbox once the bridge is missing", async () => {
|
|
58
|
+
xray.registerReactToolbox = jest.fn().mockRejectedValue(new Error("no"));
|
|
59
|
+
const { registerXrayToolbox } = load();
|
|
60
|
+
|
|
61
|
+
await registerXrayToolbox(toolbox);
|
|
62
|
+
|
|
63
|
+
await expect(
|
|
64
|
+
registerXrayToolbox({ ...toolbox, name: "other" })
|
|
65
|
+
).resolves.toBe(false);
|
|
66
|
+
|
|
67
|
+
expect(xray.registerReactToolbox).toHaveBeenCalledTimes(1);
|
|
68
|
+
});
|
|
69
|
+
});
|
package/logger/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { useEffect } from "react";
|
|
|
2
2
|
import { identity } from "ramda";
|
|
3
3
|
|
|
4
4
|
import MockLogger from "./const";
|
|
5
|
+
import type { XraySubsystem } from "./subsystems";
|
|
5
6
|
|
|
6
7
|
const mockObj = new MockLogger("mock", "native-utils");
|
|
7
8
|
|
|
@@ -43,13 +44,27 @@ export const getUtilsLogger = (): XrayUtils => {
|
|
|
43
44
|
const { Logger } = xray || {};
|
|
44
45
|
|
|
45
46
|
if (xray && !Logger.mock) {
|
|
47
|
+
// A subsystem starts with its domain (xray-subsystems skill), so core and plugins are not under `app/`.
|
|
48
|
+
// The parent is only there to share the context.
|
|
46
49
|
const quickBrickLogger = new Logger("QuickBrick", "app");
|
|
47
|
-
const coreLogger =
|
|
48
|
-
const logger =
|
|
50
|
+
const coreLogger = new Logger("QuickBrick", "core", quickBrickLogger);
|
|
51
|
+
const logger = new Logger("QuickBrick", "plugins", quickBrickLogger);
|
|
49
52
|
const logLevels = Logger.logLevels;
|
|
50
|
-
const utilsLogger = coreLogger
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
const utilsLogger = coreLogger;
|
|
54
|
+
|
|
55
|
+
// A logger on a node of the tree, e.g. subsystemLogger("ui/navigation", "Navigator").
|
|
56
|
+
// The subsystem says where in the product, the category names the component or feature.
|
|
57
|
+
const subsystemLogger = (subsystem: string, category = "QuickBrick") =>
|
|
58
|
+
new Logger(category, subsystem, quickBrickLogger);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
quickBrickLogger,
|
|
62
|
+
coreLogger,
|
|
63
|
+
logger,
|
|
64
|
+
logLevels,
|
|
65
|
+
utilsLogger,
|
|
66
|
+
subsystemLogger,
|
|
67
|
+
};
|
|
53
68
|
}
|
|
54
69
|
|
|
55
70
|
return {
|
|
@@ -58,11 +73,27 @@ export const getUtilsLogger = (): XrayUtils => {
|
|
|
58
73
|
logger: mockObj,
|
|
59
74
|
logLevels: MockLogger.logLevels,
|
|
60
75
|
utilsLogger: mockObj,
|
|
76
|
+
subsystemLogger: () => mockObj,
|
|
61
77
|
}; // TODO: check if this is the best approach
|
|
62
78
|
};
|
|
63
79
|
|
|
64
|
-
const {
|
|
65
|
-
|
|
80
|
+
const {
|
|
81
|
+
quickBrickLogger,
|
|
82
|
+
coreLogger,
|
|
83
|
+
logger,
|
|
84
|
+
logLevels,
|
|
85
|
+
utilsLogger,
|
|
86
|
+
subsystemLogger: anySubsystemLogger,
|
|
87
|
+
} = getUtilsLogger();
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A logger on a node of the X-Ray subsystem tree (see ./subsystems), named after the component by `category`.
|
|
91
|
+
* Only nodes of the tree compile, so a new path has to be added to the list first.
|
|
92
|
+
*/
|
|
93
|
+
const subsystemLogger = anySubsystemLogger as (
|
|
94
|
+
subsystem: XraySubsystem,
|
|
95
|
+
category?: string
|
|
96
|
+
) => ReturnType<XrayUtils["subsystemLogger"]>;
|
|
66
97
|
|
|
67
98
|
/**
|
|
68
99
|
* useLogger is a React hook that can be used within the React lifecycle
|
|
@@ -89,11 +120,16 @@ function useLogger(
|
|
|
89
120
|
|
|
90
121
|
const createLogger = ({
|
|
91
122
|
category = "General",
|
|
92
|
-
subsystem
|
|
123
|
+
subsystem,
|
|
93
124
|
parent = null,
|
|
125
|
+
}: {
|
|
126
|
+
category?: string;
|
|
127
|
+
subsystem: XraySubsystem;
|
|
128
|
+
parent?: XRayLoggerI | null;
|
|
94
129
|
}) => {
|
|
95
130
|
const XRayLogger = getXray().Logger as any;
|
|
96
|
-
|
|
131
|
+
// The type requires a subsystem; the fallback only keeps already built plugins working.
|
|
132
|
+
const logger = new XRayLogger(category, subsystem ?? "MyPlugin", parent);
|
|
97
133
|
|
|
98
134
|
const log_verbose = (message: string, data: any = null) => {
|
|
99
135
|
logger.log({
|
|
@@ -133,6 +169,8 @@ const createLogger = ({
|
|
|
133
169
|
return { log_verbose, log_debug, log_info, log_error, log_warning };
|
|
134
170
|
};
|
|
135
171
|
|
|
172
|
+
export type { XraySubsystem } from "./subsystems";
|
|
173
|
+
|
|
136
174
|
export {
|
|
137
175
|
createLogger,
|
|
138
176
|
useLogger,
|
|
@@ -141,4 +179,5 @@ export {
|
|
|
141
179
|
logger,
|
|
142
180
|
logLevels,
|
|
143
181
|
utilsLogger,
|
|
182
|
+
subsystemLogger,
|
|
144
183
|
};
|