@applicaster/zapp-react-native-utils 15.0.0-rc.100 → 15.0.0-rc.102

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.
@@ -373,3 +373,49 @@ describe("addNode", () => {
373
373
  checkParents(tree.root);
374
374
  });
375
375
  });
376
+
377
+ describe("findInTree", () => {
378
+ function createNode(id, children) {
379
+ return {
380
+ id,
381
+ children,
382
+ };
383
+ }
384
+
385
+ it("returns a direct child match from root children", () => {
386
+ const tree = new Tree(treeLoaded);
387
+ const direct = createNode("direct-node");
388
+
389
+ tree.root.children = [direct];
390
+
391
+ expect(tree.findInTree("direct-node")).toEqual(direct);
392
+ });
393
+
394
+ it("returns a nested descendant match", () => {
395
+ const tree = new Tree(treeLoaded);
396
+ const nested = createNode("nested-node");
397
+ const intermediate = createNode("intermediate-node", [nested]);
398
+ const rootNode = createNode("root-node", [intermediate]);
399
+
400
+ tree.root.children = [rootNode];
401
+
402
+ expect(tree.findInTree("nested-node")).toEqual(nested);
403
+ });
404
+
405
+ it("returns null when node id does not exist", () => {
406
+ const tree = new Tree(treeLoaded);
407
+ const leaf = createNode("leaf-node");
408
+ const rootNode = createNode("root-node", [leaf]);
409
+
410
+ tree.root.children = [rootNode];
411
+
412
+ expect(tree.findInTree("missing-node")).toEqual(null);
413
+ });
414
+
415
+ it("returns null when tree has no children", () => {
416
+ const tree = new Tree(treeLoaded);
417
+ tree.root.children = null;
418
+
419
+ expect(tree.findInTree("any-node")).toEqual(null);
420
+ });
421
+ });
@@ -205,31 +205,31 @@ export class Tree {
205
205
  * @returns founded node or null
206
206
  */
207
207
  findInTree(id) {
208
- const retVal = null;
209
-
210
- return this.findInArray(id, this.root.children, retVal);
208
+ return this.findInArray(id, this.root.children);
211
209
  }
212
210
 
213
- findInArray(id, children, retVal) {
214
- if (!retVal && children) {
215
- retVal = children.find((obj) => obj.id === id);
211
+ findInArray(id, children) {
212
+ if (!children) {
213
+ return null;
214
+ }
216
215
 
217
- if (!retVal) {
218
- children.forEach((child) => {
219
- if (child.children) {
220
- retVal = this.findInArray(id, child.children, retVal);
216
+ const directMatch = children.find((obj) => obj.id === id);
221
217
 
222
- if (retVal) {
223
- return retVal;
224
- }
225
- }
226
- });
227
- } else {
228
- return retVal;
218
+ if (directMatch) {
219
+ return directMatch;
220
+ }
221
+
222
+ for (const child of children) {
223
+ if (child.children) {
224
+ const nestedMatch = this.findInArray(id, child.children);
225
+
226
+ if (nestedMatch) {
227
+ return nestedMatch;
228
+ }
229
229
  }
230
230
  }
231
231
 
232
- return retVal;
232
+ return null;
233
233
  }
234
234
 
235
235
  /**
@@ -229,8 +229,9 @@ export class PlayerNative extends Player {
229
229
  };
230
230
 
231
231
  closeNativePlayer = () => {
232
- // TODO: Delete does not work
232
+ // TODO: Delete, does not work (component is null)
233
233
  this.currentPlayerComponent()?.closeNativePlayer?.();
234
+ this.getPlayerModule()?.stopBackgroundPlayback?.();
234
235
  };
235
236
 
236
237
  togglePlayPause = () => {
@@ -707,22 +707,6 @@ function getPlayerConfiguration({ platform, version }) {
707
707
  }
708
708
 
709
709
  if (isMobile(platform)) {
710
- localizations.fields.push(
711
- {
712
- type: "text_input",
713
- label: "Restrict playback on mobile networks alert title",
714
- key: "mobile_connection_restricted_alert_title",
715
- initial_value: "Restricted Connection Type",
716
- },
717
- {
718
- type: "text_input",
719
- label: "Restrict playback on mobile networks alert message",
720
- key: "mobile_connection_restricted_alert_message",
721
- initial_value:
722
- "This content can only be viewed over a Wi-Fi or LAN network.",
723
- }
724
- );
725
-
726
710
  general.fields.push(
727
711
  {
728
712
  section: "Default Timestamp Type",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "15.0.0-rc.100",
3
+ "version": "15.0.0-rc.102",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "15.0.0-rc.100",
30
+ "@applicaster/applicaster-types": "15.0.0-rc.102",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -0,0 +1,158 @@
1
+ import { clone } from "../clone";
2
+
3
+ describe("clone", () => {
4
+ const originalStructuredClone = global.structuredClone;
5
+
6
+ afterEach(() => {
7
+ // Restore the original structuredClone after each test
8
+ global.structuredClone = originalStructuredClone;
9
+ });
10
+
11
+ describe("when structuredClone is available", () => {
12
+ beforeEach(() => {
13
+ // Mock structuredClone if it's not available
14
+ if (typeof global.structuredClone === "undefined") {
15
+ global.structuredClone = jest.fn((value) =>
16
+ JSON.parse(JSON.stringify(value))
17
+ );
18
+ }
19
+ });
20
+
21
+ test("clones primitive values", () => {
22
+ expect(clone(42)).toBe(42);
23
+ expect(clone("test")).toBe("test");
24
+ expect(clone(true)).toBe(true);
25
+ expect(clone(null)).toBe(null);
26
+ });
27
+
28
+ test("clones simple objects", () => {
29
+ const original = { a: 1, b: 2 };
30
+ const cloned = clone(original);
31
+
32
+ expect(cloned).toEqual(original);
33
+ expect(cloned).not.toBe(original);
34
+ });
35
+
36
+ test("clones nested objects", () => {
37
+ const original = { a: { b: { c: 1 } } };
38
+ const cloned = clone(original);
39
+
40
+ expect(cloned).toEqual(original);
41
+ expect(cloned).not.toBe(original);
42
+ expect(cloned.a).not.toBe(original.a);
43
+ expect(cloned.a.b).not.toBe(original.a.b);
44
+ });
45
+
46
+ test("clones arrays", () => {
47
+ const original = [1, 2, 3];
48
+ const cloned = clone(original);
49
+
50
+ expect(cloned).toEqual(original);
51
+ expect(cloned).not.toBe(original);
52
+ });
53
+
54
+ test("clones arrays with nested objects", () => {
55
+ const original = [{ a: 1 }, { b: 2 }];
56
+ const cloned = clone(original);
57
+
58
+ expect(cloned).toEqual(original);
59
+ expect(cloned).not.toBe(original);
60
+ expect(cloned[0]).not.toBe(original[0]);
61
+ expect(cloned[1]).not.toBe(original[1]);
62
+ });
63
+
64
+ test("does not mutate the original value", () => {
65
+ const original = { a: 1, b: { c: 2 } };
66
+ const cloned = clone(original);
67
+
68
+ cloned.a = 99;
69
+ cloned.b.c = 99;
70
+
71
+ expect(original.a).toBe(1);
72
+ expect(original.b.c).toBe(2);
73
+ });
74
+ });
75
+
76
+ describe("when structuredClone is not available (fallback to cloneDeep)", () => {
77
+ beforeEach(() => {
78
+ // Delete structuredClone to force fallback to cloneDeep
79
+ delete (global as any).structuredClone;
80
+ });
81
+
82
+ test("clones primitive values using cloneDeep", () => {
83
+ expect(clone(42)).toBe(42);
84
+ expect(clone("test")).toBe("test");
85
+ expect(clone(true)).toBe(true);
86
+ expect(clone(null)).toBe(null);
87
+ });
88
+
89
+ test("clones simple objects using cloneDeep", () => {
90
+ const original = { a: 1, b: 2 };
91
+ const cloned = clone(original);
92
+
93
+ expect(cloned).toEqual(original);
94
+ expect(cloned).not.toBe(original);
95
+ });
96
+
97
+ test("clones nested objects using cloneDeep", () => {
98
+ const original = { a: { b: { c: 1 } } };
99
+ const cloned = clone(original);
100
+
101
+ expect(cloned).toEqual(original);
102
+ expect(cloned).not.toBe(original);
103
+ expect(cloned.a).not.toBe(original.a);
104
+ expect(cloned.a.b).not.toBe(original.a.b);
105
+ });
106
+
107
+ test("clones arrays using cloneDeep", () => {
108
+ const original = [1, 2, 3];
109
+ const cloned = clone(original);
110
+
111
+ expect(cloned).toEqual(original);
112
+ expect(cloned).not.toBe(original);
113
+ });
114
+
115
+ test("clones arrays with nested objects using cloneDeep", () => {
116
+ const original = [{ a: 1 }, { b: 2 }];
117
+ const cloned = clone(original);
118
+
119
+ expect(cloned).toEqual(original);
120
+ expect(cloned).not.toBe(original);
121
+ expect(cloned[0]).not.toBe(original[0]);
122
+ expect(cloned[1]).not.toBe(original[1]);
123
+ });
124
+
125
+ test("does not mutate the original value when using cloneDeep", () => {
126
+ const original = { a: 1, b: { c: 2 } };
127
+ const cloned = clone(original);
128
+
129
+ cloned.a = 99;
130
+ cloned.b.c = 99;
131
+
132
+ expect(original.a).toBe(1);
133
+ expect(original.b.c).toBe(2);
134
+ });
135
+
136
+ test("handles complex objects with multiple levels", () => {
137
+ const original = {
138
+ name: "test",
139
+ data: {
140
+ items: [
141
+ { id: 1, value: "a" },
142
+ { id: 2, value: "b" },
143
+ ],
144
+ meta: { count: 2 },
145
+ },
146
+ };
147
+
148
+ const cloned = clone(original);
149
+
150
+ expect(cloned).toEqual(original);
151
+ expect(cloned).not.toBe(original);
152
+ expect(cloned.data).not.toBe(original.data);
153
+ expect(cloned.data.items).not.toBe(original.data.items);
154
+ expect(cloned.data.items[0]).not.toBe(original.data.items[0]);
155
+ expect(cloned.data.meta).not.toBe(original.data.meta);
156
+ });
157
+ });
158
+ });
package/utils/clone.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { cloneDeep } from "lodash";
2
+
3
+ export const clone = (value) => {
4
+ return typeof structuredClone !== "undefined"
5
+ ? structuredClone(value) // no support for hermes, fallback to cloneDeep
6
+ : cloneDeep(value);
7
+ };
package/utils/index.ts CHANGED
@@ -20,8 +20,9 @@ export { mapAccum } from "./mapAccum";
20
20
 
21
21
  export { mergeRight } from "./mergeRight";
22
22
 
23
+ export { clone } from "./clone";
24
+
23
25
  export {
24
- cloneDeep as clone,
25
26
  flatten,
26
27
  drop,
27
28
  size,