react-native-tree-multi-select 1.6.0 → 1.6.1

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.
@@ -14,18 +14,50 @@ exports.getFlattenedTreeData = getFlattenedTreeData;
14
14
  * @param __level__ - (optional) for internal recursive use only
15
15
  * @returns Flattened tree data with expanded ids only
16
16
  */
17
- function getFlattenedTreeData(nodes, expandedIds, __level__ = 0) {
18
- let flattened = [];
19
- for (let node of nodes) {
17
+ function getFlattenedTreeData(nodes, expandedIds) {
18
+ const flattened = [];
19
+ const stack = [];
20
+
21
+ // Initialize stack with the root nodes and level 0
22
+ for (let i = nodes.length - 1; i >= 0; i--) {
23
+ const node = nodes[i];
24
+ if (node) {
25
+ // Ensure node is not undefined
26
+ stack.push({
27
+ node,
28
+ level: 0
29
+ });
30
+ }
31
+ }
32
+ while (stack.length > 0) {
33
+ const item = stack.pop();
34
+ if (!item) continue; // Safety check
35
+
36
+ const {
37
+ node,
38
+ level
39
+ } = item;
40
+
41
+ // Push current node into the flattened array
20
42
  flattened.push({
21
43
  ...node,
22
- level: __level__
44
+ level
23
45
  });
46
+
47
+ // Add children nodes to the stack if the node is expanded
24
48
  if (node.children && expandedIds.has(node.id)) {
25
- flattened = [...flattened, ...getFlattenedTreeData(node.children, expandedIds, __level__ + 1)];
49
+ for (let i = node.children.length - 1; i >= 0; i--) {
50
+ const childNode = node.children[i];
51
+ if (childNode) {
52
+ // Ensure childNode is not undefined
53
+ stack.push({
54
+ node: childNode,
55
+ level: level + 1
56
+ });
57
+ }
58
+ }
26
59
  }
27
60
  }
28
61
  return flattened;
29
62
  }
30
- ;
31
63
  //# sourceMappingURL=flattenTree.helper.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getFlattenedTreeData","nodes","expandedIds","__level__","flattened","node","push","level","children","has","id"],"sourceRoot":"../../../src","sources":["helpers/flattenTree.helper.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAoBA,CAChCC,KAAiB,EACjBC,WAAwB,EACxBC,SAAiB,GAAG,CAAC,EACE;EACvB,IAAIC,SAAkC,GAAG,EAAE;EAC3C,KAAK,IAAIC,IAAI,IAAIJ,KAAK,EAAE;IACpBG,SAAS,CAACE,IAAI,CAAC;MAAE,GAAGD,IAAI;MAAEE,KAAK,EAAEJ;IAAU,CAAC,CAAC;IAC7C,IAAIE,IAAI,CAACG,QAAQ,IAAIN,WAAW,CAACO,GAAG,CAACJ,IAAI,CAACK,EAAE,CAAC,EAAE;MAC3CN,SAAS,GAAG,CACR,GAAGA,SAAS,EACZ,GAAGJ,oBAAoB,CAACK,IAAI,CAACG,QAAQ,EAAEN,WAAW,EAAEC,SAAS,GAAG,CAAC,CAAC,CACrE;IACL;EACJ;EACA,OAAOC,SAAS;AACpB;AAAC","ignoreList":[]}
1
+ {"version":3,"names":["getFlattenedTreeData","nodes","expandedIds","flattened","stack","i","length","node","push","level","item","pop","children","has","id","childNode"],"sourceRoot":"../../../src","sources":["helpers/flattenTree.helper.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAoBA,CAChCC,KAAiB,EACjBC,WAAwB,EACD;EACvB,MAAMC,SAAkC,GAAG,EAAE;EAC7C,MAAMC,KAA2C,GAAG,EAAE;;EAEtD;EACA,KAAK,IAAIC,CAAC,GAAGJ,KAAK,CAACK,MAAM,GAAG,CAAC,EAAED,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;IACxC,MAAME,IAAI,GAAGN,KAAK,CAACI,CAAC,CAAC;IACrB,IAAIE,IAAI,EAAE;MAAE;MACRH,KAAK,CAACI,IAAI,CAAC;QAAED,IAAI;QAAEE,KAAK,EAAE;MAAE,CAAC,CAAC;IAClC;EACJ;EAEA,OAAOL,KAAK,CAACE,MAAM,GAAG,CAAC,EAAE;IACrB,MAAMI,IAAI,GAAGN,KAAK,CAACO,GAAG,CAAC,CAAC;IACxB,IAAI,CAACD,IAAI,EAAE,SAAS,CAAC;;IAErB,MAAM;MAAEH,IAAI;MAAEE;IAAM,CAAC,GAAGC,IAAI;;IAE5B;IACAP,SAAS,CAACK,IAAI,CAAC;MAAE,GAAGD,IAAI;MAAEE;IAAM,CAAC,CAAC;;IAElC;IACA,IAAIF,IAAI,CAACK,QAAQ,IAAIV,WAAW,CAACW,GAAG,CAACN,IAAI,CAACO,EAAE,CAAC,EAAE;MAC3C,KAAK,IAAIT,CAAC,GAAGE,IAAI,CAACK,QAAQ,CAACN,MAAM,GAAG,CAAC,EAAED,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;QAChD,MAAMU,SAAS,GAAGR,IAAI,CAACK,QAAQ,CAACP,CAAC,CAAC;QAClC,IAAIU,SAAS,EAAE;UAAE;UACbX,KAAK,CAACI,IAAI,CAAC;YAAED,IAAI,EAAEQ,SAAS;YAAEN,KAAK,EAAEA,KAAK,GAAG;UAAE,CAAC,CAAC;QACrD;MACJ;IACJ;EACJ;EAEA,OAAON,SAAS;AACpB","ignoreList":[]}
@@ -10,18 +10,50 @@
10
10
  * @param __level__ - (optional) for internal recursive use only
11
11
  * @returns Flattened tree data with expanded ids only
12
12
  */
13
- export function getFlattenedTreeData(nodes, expandedIds, __level__ = 0) {
14
- let flattened = [];
15
- for (let node of nodes) {
13
+ export function getFlattenedTreeData(nodes, expandedIds) {
14
+ const flattened = [];
15
+ const stack = [];
16
+
17
+ // Initialize stack with the root nodes and level 0
18
+ for (let i = nodes.length - 1; i >= 0; i--) {
19
+ const node = nodes[i];
20
+ if (node) {
21
+ // Ensure node is not undefined
22
+ stack.push({
23
+ node,
24
+ level: 0
25
+ });
26
+ }
27
+ }
28
+ while (stack.length > 0) {
29
+ const item = stack.pop();
30
+ if (!item) continue; // Safety check
31
+
32
+ const {
33
+ node,
34
+ level
35
+ } = item;
36
+
37
+ // Push current node into the flattened array
16
38
  flattened.push({
17
39
  ...node,
18
- level: __level__
40
+ level
19
41
  });
42
+
43
+ // Add children nodes to the stack if the node is expanded
20
44
  if (node.children && expandedIds.has(node.id)) {
21
- flattened = [...flattened, ...getFlattenedTreeData(node.children, expandedIds, __level__ + 1)];
45
+ for (let i = node.children.length - 1; i >= 0; i--) {
46
+ const childNode = node.children[i];
47
+ if (childNode) {
48
+ // Ensure childNode is not undefined
49
+ stack.push({
50
+ node: childNode,
51
+ level: level + 1
52
+ });
53
+ }
54
+ }
22
55
  }
23
56
  }
24
57
  return flattened;
25
58
  }
26
- ;
27
59
  //# sourceMappingURL=flattenTree.helper.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getFlattenedTreeData","nodes","expandedIds","__level__","flattened","node","push","level","children","has","id"],"sourceRoot":"../../../src","sources":["helpers/flattenTree.helper.ts"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,oBAAoBA,CAChCC,KAAiB,EACjBC,WAAwB,EACxBC,SAAiB,GAAG,CAAC,EACE;EACvB,IAAIC,SAAkC,GAAG,EAAE;EAC3C,KAAK,IAAIC,IAAI,IAAIJ,KAAK,EAAE;IACpBG,SAAS,CAACE,IAAI,CAAC;MAAE,GAAGD,IAAI;MAAEE,KAAK,EAAEJ;IAAU,CAAC,CAAC;IAC7C,IAAIE,IAAI,CAACG,QAAQ,IAAIN,WAAW,CAACO,GAAG,CAACJ,IAAI,CAACK,EAAE,CAAC,EAAE;MAC3CN,SAAS,GAAG,CACR,GAAGA,SAAS,EACZ,GAAGJ,oBAAoB,CAACK,IAAI,CAACG,QAAQ,EAAEN,WAAW,EAAEC,SAAS,GAAG,CAAC,CAAC,CACrE;IACL;EACJ;EACA,OAAOC,SAAS;AACpB;AAAC","ignoreList":[]}
1
+ {"version":3,"names":["getFlattenedTreeData","nodes","expandedIds","flattened","stack","i","length","node","push","level","item","pop","children","has","id","childNode"],"sourceRoot":"../../../src","sources":["helpers/flattenTree.helper.ts"],"mappings":";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pB","ignoreList":[]}
@@ -9,5 +9,5 @@ import { TreeNode, __FlattenedTreeNode__ } from "../types/treeView.types";
9
9
  * @param __level__ - (optional) for internal recursive use only
10
10
  * @returns Flattened tree data with expanded ids only
11
11
  */
12
- export declare function getFlattenedTreeData(nodes: TreeNode[], expandedIds: Set<string>, __level__?: number): __FlattenedTreeNode__[];
12
+ export declare function getFlattenedTreeData(nodes: TreeNode[], expandedIds: Set<string>): __FlattenedTreeNode__[];
13
13
  //# sourceMappingURL=flattenTree.helper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flattenTree.helper.d.ts","sourceRoot":"","sources":["../../../src/helpers/flattenTree.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAE1E;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,QAAQ,EAAE,EACjB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,EACxB,SAAS,GAAE,MAAU,GACtB,qBAAqB,EAAE,CAYzB"}
1
+ {"version":3,"file":"flattenTree.helper.d.ts","sourceRoot":"","sources":["../../../src/helpers/flattenTree.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAE1E;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,QAAQ,EAAE,EACjB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,GACzB,qBAAqB,EAAE,CAiCzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-tree-multi-select",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "A super-fast, customizable tree view component for React Native with multi-selection, checkboxes, and search filtering capabilities.",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -13,17 +13,37 @@ import { TreeNode, __FlattenedTreeNode__ } from "../types/treeView.types";
13
13
  export function getFlattenedTreeData(
14
14
  nodes: TreeNode[],
15
15
  expandedIds: Set<string>,
16
- __level__: number = 0,
17
16
  ): __FlattenedTreeNode__[] {
18
- let flattened: __FlattenedTreeNode__[] = [];
19
- for (let node of nodes) {
20
- flattened.push({ ...node, level: __level__ });
17
+ const flattened: __FlattenedTreeNode__[] = [];
18
+ const stack: { node: TreeNode; level: number; }[] = [];
19
+
20
+ // Initialize stack with the root nodes and level 0
21
+ for (let i = nodes.length - 1; i >= 0; i--) {
22
+ const node = nodes[i];
23
+ if (node) { // Ensure node is not undefined
24
+ stack.push({ node, level: 0 });
25
+ }
26
+ }
27
+
28
+ while (stack.length > 0) {
29
+ const item = stack.pop();
30
+ if (!item) continue; // Safety check
31
+
32
+ const { node, level } = item;
33
+
34
+ // Push current node into the flattened array
35
+ flattened.push({ ...node, level });
36
+
37
+ // Add children nodes to the stack if the node is expanded
21
38
  if (node.children && expandedIds.has(node.id)) {
22
- flattened = [
23
- ...flattened,
24
- ...getFlattenedTreeData(node.children, expandedIds, __level__ + 1)
25
- ];
39
+ for (let i = node.children.length - 1; i >= 0; i--) {
40
+ const childNode = node.children[i];
41
+ if (childNode) { // Ensure childNode is not undefined
42
+ stack.push({ node: childNode, level: level + 1 });
43
+ }
44
+ }
26
45
  }
27
46
  }
47
+
28
48
  return flattened;
29
- };
49
+ }