@applicaster/zapp-react-native-utils 15.0.0-alpha.8680244503 → 15.0.0-alpha.9300744523

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,11 +1,31 @@
1
- import * as R from "ramda";
2
-
3
- import { focusManager } from "../focusManager";
1
+ import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager/index.ios";
2
+ import { QUICK_BRICK_CONTENT } from "@applicaster/quick-brick-core/const";
3
+ import { isNil, isEmpty } from "@applicaster/zapp-react-native-utils/utils";
4
+ import { isNotNil } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
4
5
 
5
6
  let riverFocusData = {};
6
7
  let initialyPresentedScreenFocused = false;
7
8
 
8
9
  export const riverFocusManager = (function () {
10
+ /**
11
+ * Create unique key that will be used for save focused group data inside specific screen
12
+ * @param {{ screenId: string, isInsideContainer: boolean }}
13
+ * screenId Unique Id of the screen from layout.json
14
+ * isInsideContainer If this screen a screen picker child
15
+ *
16
+ */
17
+ function screenFocusableGroupId({
18
+ screenId,
19
+ isInsideContainer,
20
+ }: {
21
+ screenId: string;
22
+ isInsideContainer: Option<boolean>;
23
+ }) {
24
+ return `${QUICK_BRICK_CONTENT}-${screenId}${
25
+ isNil(isInsideContainer) ? "" : "-isInsideContainer"
26
+ }`;
27
+ }
28
+
9
29
  function setScreenFocusableData({
10
30
  screenFocusableGroupId,
11
31
  groupId,
@@ -78,8 +98,8 @@ export const riverFocusManager = (function () {
78
98
  }) {
79
99
  // Check if screen should be focused
80
100
  const shouldFocus =
81
- (initialyPresentedScreenFocused === false && R.isEmpty(riverFocusData)) ||
82
- R.compose(R.not, R.isNil)(riverFocusData[screenFocusableGroupId]) ||
101
+ (initialyPresentedScreenFocused === false && isEmpty(riverFocusData)) ||
102
+ isNotNil(riverFocusData[screenFocusableGroupId]) ||
83
103
  isDeepLink;
84
104
 
85
105
  // TODO: Uncommit it to start fixing bug where selection wrong item
@@ -118,19 +138,6 @@ export const riverFocusManager = (function () {
118
138
  }
119
139
  }
120
140
 
121
- /**
122
- * Create unique key that will be used for save focused group data inside specific screen
123
- * @param {{ screenId: string, isInsideContainer: boolean }}
124
- * screenId Unique Id of the screen from layout.json
125
- * isInsideContainer If this screen a screen picker child
126
- *
127
- */
128
- function screenFocusableGroupId({ screenId, isInsideContainer }) {
129
- return `RiverFocusableGroup-${screenId}${
130
- R.isNil(isInsideContainer) ? "" : "-isInsideContainer"
131
- }`;
132
- }
133
-
134
141
  return {
135
142
  setScreenFocusableData,
136
143
  clearAllScreensData,
@@ -0,0 +1,360 @@
1
+ jest.mock("../../../logger", () => {
2
+ const mockLogError = jest.fn();
3
+
4
+ return {
5
+ createLogger: jest.fn(() => ({
6
+ log_error: mockLogError,
7
+ })),
8
+ __mockLogError: mockLogError, // Export for test access
9
+ };
10
+ });
11
+
12
+ import { calculateReadingTime } from "../utils";
13
+ // @ts-ignore - Access the mock
14
+ import { __mockLogError } from "../../../logger";
15
+
16
+ describe("calculateReadingTime", () => {
17
+ // Default parameters for reference
18
+ const DEFAULT_WPM = 140;
19
+ const DEFAULT_MIN_PAUSE = 500;
20
+ const DEFAULT_DELAY = 700;
21
+
22
+ beforeEach(() => {
23
+ (__mockLogError as jest.Mock).mockClear();
24
+ });
25
+
26
+ describe("Type Safety", () => {
27
+ it("should accept and process string input", () => {
28
+ const result = calculateReadingTime("Hello world");
29
+ expect(result).toBeGreaterThan(0);
30
+ expect(__mockLogError).not.toHaveBeenCalled();
31
+ });
32
+
33
+ it("should accept and process number input", () => {
34
+ const result = calculateReadingTime(12345);
35
+ expect(result).toBeGreaterThan(0);
36
+ expect(__mockLogError).not.toHaveBeenCalled();
37
+ });
38
+
39
+ it("should return 0 and log error for null", () => {
40
+ expect(calculateReadingTime(null as any)).toBe(0);
41
+
42
+ expect(__mockLogError).toHaveBeenCalledWith(
43
+ "Invalid text input for reading time calculation got: null"
44
+ );
45
+ });
46
+
47
+ it("should return 0 and log error for undefined", () => {
48
+ expect(calculateReadingTime(undefined as any)).toBe(0);
49
+
50
+ expect(__mockLogError).toHaveBeenCalledWith(
51
+ "Invalid text input for reading time calculation got: undefined"
52
+ );
53
+ });
54
+
55
+ it("should return 0 and log error for boolean", () => {
56
+ calculateReadingTime(true as any);
57
+
58
+ expect(__mockLogError).toHaveBeenCalledWith(
59
+ "Invalid text input for reading time calculation got: true"
60
+ );
61
+
62
+ (__mockLogError as jest.Mock).mockClear();
63
+
64
+ calculateReadingTime(false as any);
65
+
66
+ expect(__mockLogError).toHaveBeenCalledWith(
67
+ "Invalid text input for reading time calculation got: false"
68
+ );
69
+ });
70
+
71
+ it("should return 0 and log error for object", () => {
72
+ const obj = { text: "hello" };
73
+ calculateReadingTime(obj as any);
74
+
75
+ expect(__mockLogError).toHaveBeenCalledWith(
76
+ `Invalid text input for reading time calculation got: ${obj}`
77
+ );
78
+ });
79
+
80
+ it("should return 0 and log error for array", () => {
81
+ const arr = [1, 2, 3];
82
+ calculateReadingTime(arr as any);
83
+
84
+ expect(__mockLogError).toHaveBeenCalledWith(
85
+ `Invalid text input for reading time calculation got: ${arr}`
86
+ );
87
+ });
88
+
89
+ it("should return 0 and log error for function", () => {
90
+ const fn = () => "text";
91
+ calculateReadingTime(fn as any);
92
+ expect(__mockLogError).toHaveBeenCalled();
93
+
94
+ expect((__mockLogError as jest.Mock).mock.calls[0][0]).toContain(
95
+ "Invalid text input for reading time calculation got:"
96
+ );
97
+ });
98
+
99
+ it("should return 0 and log error for symbol", () => {
100
+ const sym = Symbol("test");
101
+ calculateReadingTime(sym as any);
102
+ expect(__mockLogError).toHaveBeenCalled();
103
+
104
+ expect((__mockLogError as jest.Mock).mock.calls[0][0]).toBe(
105
+ `Invalid text input for reading time calculation got: ${String(sym)}`
106
+ );
107
+ });
108
+ });
109
+
110
+ describe("Empty and Whitespace Handling", () => {
111
+ it("should return 0 for empty string", () => {
112
+ expect(calculateReadingTime("")).toBe(0);
113
+ });
114
+
115
+ it("should return 0 for whitespace-only string", () => {
116
+ expect(calculateReadingTime(" ")).toBe(0);
117
+ expect(calculateReadingTime("\n")).toBe(0);
118
+ expect(calculateReadingTime("\t")).toBe(0);
119
+ expect(calculateReadingTime(" \n\t ")).toBe(0);
120
+ });
121
+
122
+ it("should handle leading and trailing whitespace", () => {
123
+ const withWhitespace = calculateReadingTime(" hello ");
124
+ const withoutWhitespace = calculateReadingTime("hello");
125
+ expect(withWhitespace).toBe(withoutWhitespace);
126
+ });
127
+ });
128
+
129
+ describe("Number Input Handling", () => {
130
+ it("should convert number 0 to string and process", () => {
131
+ const result = calculateReadingTime(0);
132
+ // "0" is one word
133
+ expect(result).toBeGreaterThan(0);
134
+ });
135
+
136
+ it("should convert positive numbers to string", () => {
137
+ const result = calculateReadingTime(123);
138
+ // "123" is one word
139
+ expect(result).toBeGreaterThan(0);
140
+ });
141
+
142
+ it("should convert negative numbers to string", () => {
143
+ const result = calculateReadingTime(-456);
144
+ // "-456" is processed as words
145
+ expect(result).toBeGreaterThan(0);
146
+ });
147
+
148
+ it("should convert decimal numbers to string", () => {
149
+ const result = calculateReadingTime(3.14);
150
+ // "3.14" is processed as words
151
+ expect(result).toBeGreaterThan(0);
152
+ });
153
+
154
+ it("should handle NaN", () => {
155
+ const result = calculateReadingTime(NaN);
156
+ // NaN is typeof "number", so it converts to "NaN" string
157
+ expect(result).toBeGreaterThan(0);
158
+ });
159
+
160
+ it("should handle Infinity", () => {
161
+ const result = calculateReadingTime(Infinity);
162
+ // Infinity is typeof "number", converts to "Infinity" string
163
+ expect(result).toBeGreaterThan(0);
164
+ });
165
+ });
166
+
167
+ describe("Word Counting", () => {
168
+ it("should count single word", () => {
169
+ const result = calculateReadingTime("Hello");
170
+
171
+ const expectedTime = Math.max(
172
+ DEFAULT_MIN_PAUSE,
173
+ (1 / DEFAULT_WPM) * 60 * 1000
174
+ );
175
+
176
+ expect(result).toBe(expectedTime + DEFAULT_DELAY);
177
+ });
178
+
179
+ it("should count multiple words separated by spaces", () => {
180
+ const result = calculateReadingTime("Hello world test");
181
+
182
+ // 3 words
183
+ const expectedTime = Math.max(
184
+ DEFAULT_MIN_PAUSE,
185
+ (3 / DEFAULT_WPM) * 60 * 1000
186
+ );
187
+
188
+ expect(result).toBe(expectedTime + DEFAULT_DELAY);
189
+ });
190
+
191
+ it("should handle words with punctuation", () => {
192
+ const result = calculateReadingTime("Hello, world! How are you?");
193
+ // Should split on punctuation and count words
194
+ expect(result).toBeGreaterThan(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
195
+ });
196
+
197
+ it("should handle alphanumeric boundaries", () => {
198
+ const result = calculateReadingTime("test123abc");
199
+ // Should split on alphanumeric boundaries
200
+ expect(result).toBeGreaterThan(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
201
+ });
202
+
203
+ it("should handle long text", () => {
204
+ const longText = "word ".repeat(200); // 200 words
205
+ const result = calculateReadingTime(longText);
206
+ const expectedTime = (200 / DEFAULT_WPM) * 60 * 1000 + DEFAULT_DELAY;
207
+ expect(result).toBeCloseTo(expectedTime, -1); // Within 10ms
208
+ });
209
+ });
210
+
211
+ describe("Minimum Pause", () => {
212
+ it("should return minimum pause + delay for very short text", () => {
213
+ const result = calculateReadingTime("Hi");
214
+ // 1 word, calculation would be less than minimum pause
215
+ expect(result).toBe(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
216
+ });
217
+
218
+ it("should respect custom minimum pause", () => {
219
+ const customMinPause = 1000;
220
+ const result = calculateReadingTime("Hi", DEFAULT_WPM, customMinPause);
221
+ expect(result).toBeGreaterThanOrEqual(customMinPause);
222
+ });
223
+
224
+ it("should exceed minimum pause for longer text", () => {
225
+ const longText = "word ".repeat(50); // 50 words
226
+ const result = calculateReadingTime(longText);
227
+ const calculatedTime = (50 / DEFAULT_WPM) * 60 * 1000;
228
+ expect(result).toBe(calculatedTime + DEFAULT_DELAY);
229
+ expect(result).toBeGreaterThan(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
230
+ });
231
+ });
232
+
233
+ describe("Custom Parameters", () => {
234
+ it("should respect custom words per minute", () => {
235
+ const text = "word ".repeat(140); // 140 words
236
+ const fastReading = calculateReadingTime(text, 280); // 2x speed
237
+ const normalReading = calculateReadingTime(text, 140); // normal speed
238
+
239
+ // Faster reading should take less time
240
+ expect(fastReading).toBeLessThan(normalReading);
241
+ });
242
+
243
+ it("should respect custom announcement delay", () => {
244
+ const text = "Hello world";
245
+
246
+ const shortDelay = calculateReadingTime(
247
+ text,
248
+ DEFAULT_WPM,
249
+ DEFAULT_MIN_PAUSE,
250
+ 100
251
+ );
252
+
253
+ const longDelay = calculateReadingTime(
254
+ text,
255
+ DEFAULT_WPM,
256
+ DEFAULT_MIN_PAUSE,
257
+ 1000
258
+ );
259
+
260
+ expect(longDelay - shortDelay).toBe(900);
261
+ });
262
+
263
+ it("should work with all custom parameters", () => {
264
+ const result = calculateReadingTime("test", 200, 1000, 500);
265
+ expect(result).toBeGreaterThanOrEqual(1500); // minimum pause + delay
266
+ });
267
+ });
268
+
269
+ describe("Real-world Use Cases", () => {
270
+ it("should handle accessibility announcement text", () => {
271
+ const announcement = "New message from John Doe";
272
+ const result = calculateReadingTime(announcement);
273
+ expect(result).toBeGreaterThan(0);
274
+ expect(result).toBeLessThan(10000); // Less than 10 seconds
275
+ });
276
+
277
+ it("should handle button labels", () => {
278
+ const label = "Submit";
279
+ const result = calculateReadingTime(label);
280
+ expect(result).toBe(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
281
+ });
282
+
283
+ it("should handle form error messages", () => {
284
+ const error = "Please enter a valid email address";
285
+ const result = calculateReadingTime(error);
286
+ expect(result).toBeGreaterThan(DEFAULT_MIN_PAUSE);
287
+ });
288
+
289
+ it("should handle article titles", () => {
290
+ const title = "Breaking News: Major Update Released";
291
+ const result = calculateReadingTime(title);
292
+ expect(result).toBeGreaterThan(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
293
+ });
294
+
295
+ it("should handle notification text", () => {
296
+ const notification = "You have 3 new messages";
297
+ const result = calculateReadingTime(notification);
298
+ expect(result).toBeGreaterThan(0);
299
+ });
300
+ });
301
+
302
+ describe("Edge Cases", () => {
303
+ it("should handle text with special characters", () => {
304
+ const result = calculateReadingTime("@#$%^&*()");
305
+ expect(result).toBeGreaterThanOrEqual(0);
306
+ });
307
+
308
+ it("should handle text with emojis", () => {
309
+ const result = calculateReadingTime("Hello 👋 World 🌍");
310
+ expect(result).toBeGreaterThan(0);
311
+ });
312
+
313
+ it("should handle text with newlines", () => {
314
+ const result = calculateReadingTime("Line 1\nLine 2\nLine 3");
315
+ expect(result).toBeGreaterThan(0);
316
+ });
317
+
318
+ it("should handle mixed alphanumeric text", () => {
319
+ const result = calculateReadingTime(
320
+ "Version 1.2.3 released on 2024-01-01"
321
+ );
322
+
323
+ expect(result).toBeGreaterThan(0);
324
+ });
325
+
326
+ it("should handle very large numbers", () => {
327
+ const result = calculateReadingTime(Number.MAX_SAFE_INTEGER);
328
+ expect(result).toBeGreaterThan(0);
329
+ });
330
+
331
+ it("should return consistent results for same input", () => {
332
+ const text = "Consistent test";
333
+ const result1 = calculateReadingTime(text);
334
+ const result2 = calculateReadingTime(text);
335
+ const result3 = calculateReadingTime(text);
336
+
337
+ expect(result1).toBe(result2);
338
+ expect(result2).toBe(result3);
339
+ });
340
+ });
341
+
342
+ describe("Performance Characteristics", () => {
343
+ it("should handle empty input efficiently", () => {
344
+ const start = Date.now();
345
+ calculateReadingTime("");
346
+ const duration = Date.now() - start;
347
+
348
+ expect(duration).toBeLessThan(10); // Should be nearly instant
349
+ });
350
+
351
+ it("should handle large text efficiently", () => {
352
+ const largeText = "word ".repeat(10000);
353
+ const start = Date.now();
354
+ calculateReadingTime(largeText);
355
+ const duration = Date.now() - start;
356
+
357
+ expect(duration).toBeLessThan(100); // Should complete in less than 100ms
358
+ });
359
+ });
360
+ });
@@ -1,20 +1,40 @@
1
+ import { createLogger } from "../../logger";
2
+
3
+ const { log_error } = createLogger({
4
+ category: "AccessibilityManager",
5
+ subsystem: "AppUtils",
6
+ });
7
+
1
8
  /**
2
9
  * Calculates the reading time for a given text based on word count
3
- * @param text - The text to calculate the reading time for
4
- * @param wordsPerMinute - Words per minute reading speed (default: 160)
10
+ * @param text - The text to calculate the reading time for (string or number)
11
+ * @param wordsPerMinute - Words per minute reading speed (default: 140)
5
12
  * @param minimumPause - Minimum pause time in milliseconds (default: 500)
6
13
  * @param announcementDelay - Additional delay for announcement in milliseconds (default: 700)
7
14
  * @returns The reading time in milliseconds
8
15
  */
9
16
  export function calculateReadingTime(
10
- text: string,
17
+ text: string | number,
11
18
  wordsPerMinute: number = 140,
12
19
  minimumPause: number = 500,
13
20
  announcementDelay: number = 700
14
21
  ): number {
15
- const trimmed = text.trim();
22
+ if (typeof text !== "string" && typeof text !== "number") {
23
+ log_error(
24
+ `Invalid text input for reading time calculation got: ${
25
+ typeof text === "symbol" ? String(text) : text
26
+ }`
27
+ );
28
+
29
+ return 0;
30
+ }
31
+
32
+ const trimmed = typeof text === "number" ? String(text) : text.trim();
33
+
34
+ if (!trimmed) {
35
+ return 0;
36
+ }
16
37
 
17
- // Count words (split on whitespace and punctuation, keep alnum boundaries)
18
38
  const words = trimmed
19
39
  .split(/(?<=\d)(?=[a-zA-Z])|(?<=[a-zA-Z])(?=\d)|[^\w\s]+|\s+/)
20
40
  .filter(Boolean).length;
@@ -71,6 +71,9 @@ exports[`focusManagerIOS should be defined 1`] = `
71
71
  "invokeHandler": [Function],
72
72
  "isChildOf": [Function],
73
73
  "isFocusOn": [Function],
74
+ "isFocusOnContent": [Function],
75
+ "isFocusOnMenu": [Function],
76
+ "isFocusOnTabsScreenContent": [Function],
74
77
  "isGroupItemFocused": [Function],
75
78
  "moveFocus": [Function],
76
79
  "on": [Function],
@@ -4,7 +4,11 @@ import * as R from "ramda";
4
4
  import {
5
5
  isCurrentFocusOn,
6
6
  isChildOf as isChildOfUtils,
7
- } from "../focusManagerAux/utils";
7
+ isPartOfMenu,
8
+ isPartOfContent,
9
+ isPartOfTabsScreenContent,
10
+ } from "../focusManagerAux/utils/index.ios";
11
+
8
12
  import { Tree } from "./treeDataStructure/Tree";
9
13
  import { findFocusableNode } from "./treeDataStructure/Utils";
10
14
  import { subscriber } from "../../functionUtils";
@@ -188,9 +192,15 @@ export const focusManager = (function () {
188
192
  function register({ id, component }) {
189
193
  const { isGroup = false } = component;
190
194
 
191
- emitRegistered(id);
195
+ if (isGroup) {
196
+ registerGroup(id, component);
197
+ } else {
198
+ registerItem(id, component);
199
+ }
192
200
 
193
- return isGroup ? registerGroup(id, component) : registerItem(id, component);
201
+ const groupId = component?.props?.groupId;
202
+
203
+ emitRegistered({ id, groupId, isGroup });
194
204
  }
195
205
 
196
206
  function unregister(id, { group = false } = {}) {
@@ -273,7 +283,9 @@ export const focusManager = (function () {
273
283
  function setFocus(
274
284
  id: string,
275
285
  direction?: FocusManager.IOS.Direction,
276
- options?: Partial<{ groupFocusedChanged: boolean }>,
286
+ options?: Partial<{
287
+ groupFocusedChanged: boolean;
288
+ }>,
277
289
  callback?: any
278
290
  ) {
279
291
  blur(direction);
@@ -412,6 +424,30 @@ export const focusManager = (function () {
412
424
  return id && isCurrentFocusOn(id, currentFocusNode);
413
425
  }
414
426
 
427
+ function isFocusOnMenu(): boolean {
428
+ const currentFocusable = getCurrentFocus();
429
+
430
+ return isPartOfMenu(focusableTree, currentFocusable?.props?.id);
431
+ }
432
+
433
+ function isFocusOnContent(): boolean {
434
+ const currentFocusable = getCurrentFocus();
435
+
436
+ return isPartOfContent(focusableTree, currentFocusable?.props?.id);
437
+ }
438
+
439
+ function isFocusOnTabsScreenContent(
440
+ screenPickerContentContainerId: string
441
+ ): boolean {
442
+ const currentFocusable = getCurrentFocus();
443
+
444
+ return isPartOfTabsScreenContent(
445
+ focusableTree,
446
+ screenPickerContentContainerId,
447
+ currentFocusable?.props?.id
448
+ );
449
+ }
450
+
415
451
  function isChildOf(childId, parentId): boolean {
416
452
  return isChildOfUtils(focusableTree, childId, parentId);
417
453
  }
@@ -438,6 +474,9 @@ export const focusManager = (function () {
438
474
  isGroupItemFocused,
439
475
  getPreferredFocusChild,
440
476
  isFocusOn,
477
+ isFocusOnMenu,
478
+ isFocusOnContent,
479
+ isFocusOnTabsScreenContent,
441
480
  isChildOf,
442
481
  };
443
482
  })();
@@ -0,0 +1,122 @@
1
+ import { isNil, startsWith } from "@applicaster/zapp-react-native-utils/utils";
2
+
3
+ import {
4
+ QUICK_BRICK_CONTENT,
5
+ QUICK_BRICK_NAVBAR,
6
+ } from "@applicaster/quick-brick-core/const";
7
+
8
+ const isNavBar = (node) => startsWith(QUICK_BRICK_NAVBAR, node?.id);
9
+ const isContent = (node) => startsWith(QUICK_BRICK_CONTENT, node?.id);
10
+ const isRoot = (node) => node?.id === "root";
11
+
12
+ export const isPartOfTabsScreenContent = (
13
+ focusableTree,
14
+ screenPickerContentContainerId,
15
+ id
16
+ ) => {
17
+ const node = focusableTree.findInTree(id);
18
+
19
+ if (isNil(node)) {
20
+ return false;
21
+ }
22
+
23
+ if (isRoot(node)) {
24
+ return false;
25
+ }
26
+
27
+ if (isNavBar(node)) {
28
+ return false;
29
+ }
30
+
31
+ if (isContent(node)) {
32
+ return false;
33
+ }
34
+
35
+ if (node?.id === screenPickerContentContainerId) {
36
+ return true;
37
+ }
38
+
39
+ return isPartOfTabsScreenContent(
40
+ focusableTree,
41
+ screenPickerContentContainerId,
42
+ node.parent?.id
43
+ );
44
+ };
45
+
46
+ export const isPartOfMenu = (focusableTree, id): boolean => {
47
+ const node = focusableTree.findInTree(id);
48
+
49
+ if (isNil(node)) {
50
+ return false;
51
+ }
52
+
53
+ if (isRoot(node)) {
54
+ return false;
55
+ }
56
+
57
+ if (isNavBar(node)) {
58
+ return true;
59
+ }
60
+
61
+ if (isContent(node)) {
62
+ return false;
63
+ }
64
+
65
+ return isPartOfMenu(focusableTree, node.parent?.id);
66
+ };
67
+
68
+ export const isPartOfContent = (focusableTree, id) => {
69
+ const node = focusableTree.findInTree(id);
70
+
71
+ if (isNil(node)) {
72
+ return false;
73
+ }
74
+
75
+ if (isRoot(node)) {
76
+ return false;
77
+ }
78
+
79
+ if (isNavBar(node)) {
80
+ return false;
81
+ }
82
+
83
+ if (isContent(node)) {
84
+ return true;
85
+ }
86
+
87
+ return isPartOfContent(focusableTree, node.parent?.id);
88
+ };
89
+
90
+ export const isCurrentFocusOn = (id, node) => {
91
+ if (!node) {
92
+ return false;
93
+ }
94
+
95
+ if (isRoot(node)) {
96
+ return false;
97
+ }
98
+
99
+ if (node?.id === id) {
100
+ return true;
101
+ }
102
+
103
+ return isCurrentFocusOn(id, node.parent);
104
+ };
105
+
106
+ export const isChildOf = (focusableTree, childId, parentId) => {
107
+ if (isNil(childId) || isNil(parentId)) {
108
+ return false;
109
+ }
110
+
111
+ const childNode = focusableTree.findInTree(childId);
112
+
113
+ if (isNil(childNode)) {
114
+ return false;
115
+ }
116
+
117
+ if (childNode.parent?.id === parentId) {
118
+ return true;
119
+ }
120
+
121
+ return isChildOf(focusableTree, childNode.parent?.id, parentId);
122
+ };
@@ -102,7 +102,7 @@ export const getNavbarNode = (focusableTree) => {
102
102
 
103
103
  export const waitForContent = (focusableTree) => {
104
104
  const contentHasAnyChildren = (): boolean => {
105
- const countOfChildren = pathOr(
105
+ const countOfChildren = pathOr<number>(
106
106
  0,
107
107
  ["children", "length"],
108
108
  getContentNode(focusableTree)