react-native-tree-multi-select 1.7.0-beta.1 → 1.7.0
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/lib/commonjs/helpers/flattenTree.helper.js +41 -6
- package/lib/commonjs/helpers/flattenTree.helper.js.map +1 -1
- package/lib/commonjs/helpers/treeNode.helper.js +0 -2
- package/lib/commonjs/helpers/treeNode.helper.js.map +1 -1
- package/lib/commonjs/utils/useDeepCompareEffect.js +21 -14
- package/lib/commonjs/utils/useDeepCompareEffect.js.map +1 -1
- package/lib/module/helpers/flattenTree.helper.js +41 -6
- package/lib/module/helpers/flattenTree.helper.js.map +1 -1
- package/lib/module/helpers/treeNode.helper.js +0 -2
- package/lib/module/helpers/treeNode.helper.js.map +1 -1
- package/lib/module/utils/useDeepCompareEffect.js +21 -12
- package/lib/module/utils/useDeepCompareEffect.js.map +1 -1
- package/lib/typescript/helpers/flattenTree.helper.d.ts +1 -1
- package/lib/typescript/helpers/flattenTree.helper.d.ts.map +1 -1
- package/lib/typescript/utils/useDeepCompareEffect.d.ts +2 -2
- package/lib/typescript/utils/useDeepCompareEffect.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/helpers/flattenTree.helper.ts +32 -9
- package/src/helpers/treeNode.helper.ts +2 -2
- package/src/utils/useDeepCompareEffect.ts +22 -13
|
@@ -14,18 +14,53 @@ 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
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
/* istanbul ignore next */
|
|
25
|
+
if (node) {
|
|
26
|
+
// Ensure node is not undefined - redundant safety
|
|
27
|
+
stack.push({
|
|
28
|
+
node,
|
|
29
|
+
level: 0
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
while (stack.length > 0) {
|
|
34
|
+
const item = stack.pop();
|
|
35
|
+
/* istanbul ignore next */
|
|
36
|
+
if (!item) continue; // Redundant safety check
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
node,
|
|
40
|
+
level
|
|
41
|
+
} = item;
|
|
42
|
+
|
|
43
|
+
// Push current node into the flattened array
|
|
20
44
|
flattened.push({
|
|
21
45
|
...node,
|
|
22
|
-
level
|
|
46
|
+
level
|
|
23
47
|
});
|
|
48
|
+
|
|
49
|
+
// Add children nodes to the stack if the node is expanded
|
|
24
50
|
if (node.children && expandedIds.has(node.id)) {
|
|
25
|
-
|
|
51
|
+
for (let i = node.children.length - 1; i >= 0; i--) {
|
|
52
|
+
const childNode = node.children[i];
|
|
53
|
+
/* istanbul ignore next */
|
|
54
|
+
if (childNode) {
|
|
55
|
+
// Ensure childNode is not undefined - redundant safety
|
|
56
|
+
stack.push({
|
|
57
|
+
node: childNode,
|
|
58
|
+
level: level + 1
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
26
62
|
}
|
|
27
63
|
}
|
|
28
64
|
return flattened;
|
|
29
65
|
}
|
|
30
|
-
;
|
|
31
66
|
//# sourceMappingURL=flattenTree.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getFlattenedTreeData","nodes","expandedIds","
|
|
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;IACA,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;IACA,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;QACA,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":[]}
|
|
@@ -21,9 +21,7 @@ function initializeNodeMaps(storeId, initialData) {
|
|
|
21
21
|
updateChildToParentMap
|
|
22
22
|
} = treeViewStore.getState();
|
|
23
23
|
const tempNodeMap = new Map();
|
|
24
|
-
;
|
|
25
24
|
const tempChildToParentMap = new Map();
|
|
26
|
-
;
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
27
|
* Recursively processes nodes, adding them to the nodeMap and childToParentMap.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_treeView","require","initializeNodeMaps","storeId","initialData","treeViewStore","getTreeViewStore","updateNodeMap","updateChildToParentMap","getState","tempNodeMap","Map","tempChildToParentMap","processNodes","nodes","parentId","forEach","node","set","id","children"],"sourceRoot":"../../../src","sources":["helpers/treeNode.helper.ts"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAACC,OAAe,EAAEC,WAAuB,EAAE;EACzE,MAAMC,aAAa,GAAG,IAAAC,0BAAgB,EAACH,OAAO,CAAC;EAC/C,MAAM;IACFI,aAAa;IACbC;EACJ,CAAC,GAAGH,aAAa,CAACI,QAAQ,CAAC,CAAC;EAE5B,MAAMC,WAAkC,GAAG,IAAIC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"names":["_treeView","require","initializeNodeMaps","storeId","initialData","treeViewStore","getTreeViewStore","updateNodeMap","updateChildToParentMap","getState","tempNodeMap","Map","tempChildToParentMap","processNodes","nodes","parentId","forEach","node","set","id","children"],"sourceRoot":"../../../src","sources":["helpers/treeNode.helper.ts"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAACC,OAAe,EAAEC,WAAuB,EAAE;EACzE,MAAMC,aAAa,GAAG,IAAAC,0BAAgB,EAACH,OAAO,CAAC;EAC/C,MAAM;IACFI,aAAa;IACbC;EACJ,CAAC,GAAGH,aAAa,CAACI,QAAQ,CAAC,CAAC;EAE5B,MAAMC,WAAkC,GAAG,IAAIC,GAAG,CAAC,CAAC;EACpD,MAAMC,oBAAyC,GAAG,IAAID,GAAG,CAAC,CAAC;;EAE3D;AACJ;AACA;AACA;AACA;AACA;EACI,MAAME,YAAY,GAAGA,CACjBC,KAAiB,EACjBC,QAAuB,GAAG,IAAI,KAC7B;IACDD,KAAK,CAACE,OAAO,CAAEC,IAAI,IAAK;MACpB;MACAP,WAAW,CAACQ,GAAG,CAACD,IAAI,CAACE,EAAE,EAAEF,IAAI,CAAC;MAC9B;MACA,IAAIF,QAAQ,EAAEH,oBAAoB,CAACM,GAAG,CAACD,IAAI,CAACE,EAAE,EAAEJ,QAAQ,CAAC;MACzD;MACA,IAAIE,IAAI,CAACG,QAAQ,EAAEP,YAAY,CAACI,IAAI,CAACG,QAAQ,EAAEH,IAAI,CAACE,EAAE,CAAC;IAC3D,CAAC,CAAC;EACN,CAAC;;EAED;EACAN,YAAY,CAACT,WAAW,CAAC;EAEzBG,aAAa,CAACG,WAAW,CAAC;EAC1BF,sBAAsB,CAACI,oBAAoB,CAAC;AAChD","ignoreList":[]}
|
|
@@ -4,30 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = useDeepCompareEffect;
|
|
7
|
-
var _react =
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
10
|
/**
|
|
13
11
|
* Deep compare effect hook.
|
|
14
12
|
* Ensures the effect runs on the first render and whenever dependencies deeply change.
|
|
15
13
|
*
|
|
16
14
|
* @param effect The effect callback function.
|
|
17
|
-
* @param
|
|
15
|
+
* @param deps The dependencies array to compare deeply.
|
|
18
16
|
*/
|
|
19
|
-
function useDeepCompareEffect(effect,
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
17
|
+
function useDeepCompareEffect(effect, deps) {
|
|
18
|
+
// Ref to track if it's the first render
|
|
19
|
+
const firstRenderRef = _react.default.useRef(true);
|
|
20
|
+
|
|
21
|
+
// Memoized dependencies to avoid redundant `isEqual` checks
|
|
22
|
+
const memoizedDependencies = _react.default.useMemo(() => deps, [deps]);
|
|
23
|
+
|
|
24
|
+
// Ref to store the previous dependencies
|
|
25
|
+
const dependenciesRef = _react.default.useRef(memoizedDependencies);
|
|
26
|
+
|
|
27
|
+
// Check for dependency changes
|
|
28
|
+
const dependenciesChanged = !(0, _isEqual.default)(dependenciesRef.current, memoizedDependencies);
|
|
29
|
+
if (dependenciesChanged) {
|
|
30
|
+
dependenciesRef.current = memoizedDependencies;
|
|
31
|
+
}
|
|
23
32
|
_react.default.useEffect(() => {
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
previousDependenciesRef.current = dependencies; // Update dependencies reference
|
|
27
|
-
return effect();
|
|
33
|
+
if (firstRenderRef.current) {
|
|
34
|
+
firstRenderRef.current = false;
|
|
28
35
|
}
|
|
36
|
+
return effect();
|
|
29
37
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
-
}, [
|
|
38
|
+
}, [dependenciesChanged]); // exclude the effect function from the dependencies
|
|
31
39
|
}
|
|
32
|
-
;
|
|
33
40
|
//# sourceMappingURL=useDeepCompareEffect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_isEqual","e","__esModule","default","useDeepCompareEffect","effect","deps","firstRenderRef","React","useRef","memoizedDependencies","useMemo","dependenciesRef","dependenciesChanged","isEqual","current","useEffect"],"sourceRoot":"../../../src","sources":["utils/useDeepCompareEffect.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAqC,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,oBAAoBA,CAC1CC,MAA4B,EAC5BC,IAA0B,EAC1B;EACA;EACA,MAAMC,cAAc,GAAGC,cAAK,CAACC,MAAM,CAAU,IAAI,CAAC;;EAElD;EACA,MAAMC,oBAAoB,GAAGF,cAAK,CAACG,OAAO,CAAC,MAAML,IAAI,EAAE,CAACA,IAAI,CAAC,CAAC;;EAE9D;EACA,MAAMM,eAAe,GAAGJ,cAAK,CAACC,MAAM,CAAuBC,oBAAoB,CAAC;;EAEhF;EACA,MAAMG,mBAAmB,GAAG,CAAC,IAAAC,gBAAO,EAACF,eAAe,CAACG,OAAO,EAAEL,oBAAoB,CAAC;EACnF,IAAIG,mBAAmB,EAAE;IACvBD,eAAe,CAACG,OAAO,GAAGL,oBAAoB;EAChD;EAEAF,cAAK,CAACQ,SAAS,CAAC,MAAM;IACpB,IAAIT,cAAc,CAACQ,OAAO,EAAE;MAC1BR,cAAc,CAACQ,OAAO,GAAG,KAAK;IAChC;IAEA,OAAOV,MAAM,CAAC,CAAC;IACf;EACF,CAAC,EAAE,CAACQ,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAC7B","ignoreList":[]}
|
|
@@ -10,18 +10,53 @@
|
|
|
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
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
/* istanbul ignore next */
|
|
21
|
+
if (node) {
|
|
22
|
+
// Ensure node is not undefined - redundant safety
|
|
23
|
+
stack.push({
|
|
24
|
+
node,
|
|
25
|
+
level: 0
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
while (stack.length > 0) {
|
|
30
|
+
const item = stack.pop();
|
|
31
|
+
/* istanbul ignore next */
|
|
32
|
+
if (!item) continue; // Redundant safety check
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
node,
|
|
36
|
+
level
|
|
37
|
+
} = item;
|
|
38
|
+
|
|
39
|
+
// Push current node into the flattened array
|
|
16
40
|
flattened.push({
|
|
17
41
|
...node,
|
|
18
|
-
level
|
|
42
|
+
level
|
|
19
43
|
});
|
|
44
|
+
|
|
45
|
+
// Add children nodes to the stack if the node is expanded
|
|
20
46
|
if (node.children && expandedIds.has(node.id)) {
|
|
21
|
-
|
|
47
|
+
for (let i = node.children.length - 1; i >= 0; i--) {
|
|
48
|
+
const childNode = node.children[i];
|
|
49
|
+
/* istanbul ignore next */
|
|
50
|
+
if (childNode) {
|
|
51
|
+
// Ensure childNode is not undefined - redundant safety
|
|
52
|
+
stack.push({
|
|
53
|
+
node: childNode,
|
|
54
|
+
level: level + 1
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
22
58
|
}
|
|
23
59
|
}
|
|
24
60
|
return flattened;
|
|
25
61
|
}
|
|
26
|
-
;
|
|
27
62
|
//# sourceMappingURL=flattenTree.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getFlattenedTreeData","nodes","expandedIds","
|
|
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;AACA,OAAO,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;IACA,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;IACA,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;QACA,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":[]}
|
|
@@ -18,9 +18,7 @@ export function initializeNodeMaps(storeId, initialData) {
|
|
|
18
18
|
updateChildToParentMap
|
|
19
19
|
} = treeViewStore.getState();
|
|
20
20
|
const tempNodeMap = new Map();
|
|
21
|
-
;
|
|
22
21
|
const tempChildToParentMap = new Map();
|
|
23
|
-
;
|
|
24
22
|
|
|
25
23
|
/**
|
|
26
24
|
* Recursively processes nodes, adding them to the nodeMap and childToParentMap.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getTreeViewStore","initializeNodeMaps","storeId","initialData","treeViewStore","updateNodeMap","updateChildToParentMap","getState","tempNodeMap","Map","tempChildToParentMap","processNodes","nodes","parentId","forEach","node","set","id","children"],"sourceRoot":"../../../src","sources":["helpers/treeNode.helper.ts"],"mappings":";;AACA,SACIA,gBAAgB,QACb,yBAAyB;;AAEhC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAACC,OAAe,EAAEC,WAAuB,EAAE;EACzE,MAAMC,aAAa,GAAGJ,gBAAgB,CAACE,OAAO,CAAC;EAC/C,MAAM;IACFG,aAAa;IACbC;EACJ,CAAC,GAAGF,aAAa,CAACG,QAAQ,CAAC,CAAC;EAE5B,MAAMC,WAAkC,GAAG,IAAIC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"names":["getTreeViewStore","initializeNodeMaps","storeId","initialData","treeViewStore","updateNodeMap","updateChildToParentMap","getState","tempNodeMap","Map","tempChildToParentMap","processNodes","nodes","parentId","forEach","node","set","id","children"],"sourceRoot":"../../../src","sources":["helpers/treeNode.helper.ts"],"mappings":";;AACA,SACIA,gBAAgB,QACb,yBAAyB;;AAEhC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAACC,OAAe,EAAEC,WAAuB,EAAE;EACzE,MAAMC,aAAa,GAAGJ,gBAAgB,CAACE,OAAO,CAAC;EAC/C,MAAM;IACFG,aAAa;IACbC;EACJ,CAAC,GAAGF,aAAa,CAACG,QAAQ,CAAC,CAAC;EAE5B,MAAMC,WAAkC,GAAG,IAAIC,GAAG,CAAC,CAAC;EACpD,MAAMC,oBAAyC,GAAG,IAAID,GAAG,CAAC,CAAC;;EAE3D;AACJ;AACA;AACA;AACA;AACA;EACI,MAAME,YAAY,GAAGA,CACjBC,KAAiB,EACjBC,QAAuB,GAAG,IAAI,KAC7B;IACDD,KAAK,CAACE,OAAO,CAAEC,IAAI,IAAK;MACpB;MACAP,WAAW,CAACQ,GAAG,CAACD,IAAI,CAACE,EAAE,EAAEF,IAAI,CAAC;MAC9B;MACA,IAAIF,QAAQ,EAAEH,oBAAoB,CAACM,GAAG,CAACD,IAAI,CAACE,EAAE,EAAEJ,QAAQ,CAAC;MACzD;MACA,IAAIE,IAAI,CAACG,QAAQ,EAAEP,YAAY,CAACI,IAAI,CAACG,QAAQ,EAAEH,IAAI,CAACE,EAAE,CAAC;IAC3D,CAAC,CAAC;EACN,CAAC;;EAED;EACAN,YAAY,CAACR,WAAW,CAAC;EAEzBE,aAAa,CAACG,WAAW,CAAC;EAC1BF,sBAAsB,CAACI,oBAAoB,CAAC;AAChD","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import React
|
|
3
|
+
import React from "react";
|
|
4
4
|
import isEqual from "lodash/isEqual";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -8,20 +8,29 @@ import isEqual from "lodash/isEqual";
|
|
|
8
8
|
* Ensures the effect runs on the first render and whenever dependencies deeply change.
|
|
9
9
|
*
|
|
10
10
|
* @param effect The effect callback function.
|
|
11
|
-
* @param
|
|
11
|
+
* @param deps The dependencies array to compare deeply.
|
|
12
12
|
*/
|
|
13
|
-
export default function useDeepCompareEffect(effect,
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
13
|
+
export default function useDeepCompareEffect(effect, deps) {
|
|
14
|
+
// Ref to track if it's the first render
|
|
15
|
+
const firstRenderRef = React.useRef(true);
|
|
16
|
+
|
|
17
|
+
// Memoized dependencies to avoid redundant `isEqual` checks
|
|
18
|
+
const memoizedDependencies = React.useMemo(() => deps, [deps]);
|
|
19
|
+
|
|
20
|
+
// Ref to store the previous dependencies
|
|
21
|
+
const dependenciesRef = React.useRef(memoizedDependencies);
|
|
22
|
+
|
|
23
|
+
// Check for dependency changes
|
|
24
|
+
const dependenciesChanged = !isEqual(dependenciesRef.current, memoizedDependencies);
|
|
25
|
+
if (dependenciesChanged) {
|
|
26
|
+
dependenciesRef.current = memoizedDependencies;
|
|
27
|
+
}
|
|
17
28
|
React.useEffect(() => {
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
previousDependenciesRef.current = dependencies; // Update dependencies reference
|
|
21
|
-
return effect();
|
|
29
|
+
if (firstRenderRef.current) {
|
|
30
|
+
firstRenderRef.current = false;
|
|
22
31
|
}
|
|
32
|
+
return effect();
|
|
23
33
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
|
-
}, [
|
|
34
|
+
}, [dependenciesChanged]); // exclude the effect function from the dependencies
|
|
25
35
|
}
|
|
26
|
-
;
|
|
27
36
|
//# sourceMappingURL=useDeepCompareEffect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","
|
|
1
|
+
{"version":3,"names":["React","isEqual","useDeepCompareEffect","effect","deps","firstRenderRef","useRef","memoizedDependencies","useMemo","dependenciesRef","dependenciesChanged","current","useEffect"],"sourceRoot":"../../../src","sources":["utils/useDeepCompareEffect.ts"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,OAAO,MAAM,gBAAgB;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,oBAAoBA,CAC1CC,MAA4B,EAC5BC,IAA0B,EAC1B;EACA;EACA,MAAMC,cAAc,GAAGL,KAAK,CAACM,MAAM,CAAU,IAAI,CAAC;;EAElD;EACA,MAAMC,oBAAoB,GAAGP,KAAK,CAACQ,OAAO,CAAC,MAAMJ,IAAI,EAAE,CAACA,IAAI,CAAC,CAAC;;EAE9D;EACA,MAAMK,eAAe,GAAGT,KAAK,CAACM,MAAM,CAAuBC,oBAAoB,CAAC;;EAEhF;EACA,MAAMG,mBAAmB,GAAG,CAACT,OAAO,CAACQ,eAAe,CAACE,OAAO,EAAEJ,oBAAoB,CAAC;EACnF,IAAIG,mBAAmB,EAAE;IACvBD,eAAe,CAACE,OAAO,GAAGJ,oBAAoB;EAChD;EAEAP,KAAK,CAACY,SAAS,CAAC,MAAM;IACpB,IAAIP,cAAc,CAACM,OAAO,EAAE;MAC1BN,cAAc,CAACM,OAAO,GAAG,KAAK;IAChC;IAEA,OAAOR,MAAM,CAAC,CAAC;IACf;EACF,CAAC,EAAE,CAACO,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAC7B","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
|
|
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,
|
|
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,CAoCzB"}
|
|
@@ -4,7 +4,7 @@ import React from "react";
|
|
|
4
4
|
* Ensures the effect runs on the first render and whenever dependencies deeply change.
|
|
5
5
|
*
|
|
6
6
|
* @param effect The effect callback function.
|
|
7
|
-
* @param
|
|
7
|
+
* @param deps The dependencies array to compare deeply.
|
|
8
8
|
*/
|
|
9
|
-
export default function useDeepCompareEffect(effect: React.EffectCallback,
|
|
9
|
+
export default function useDeepCompareEffect(effect: React.EffectCallback, deps: React.DependencyList): void;
|
|
10
10
|
//# sourceMappingURL=useDeepCompareEffect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeepCompareEffect.d.ts","sourceRoot":"","sources":["../../../src/utils/useDeepCompareEffect.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"useDeepCompareEffect.d.ts","sourceRoot":"","sources":["../../../src/utils/useDeepCompareEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,MAAM,EAAE,KAAK,CAAC,cAAc,EAC5B,IAAI,EAAE,KAAK,CAAC,cAAc,QAyB3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-tree-multi-select",
|
|
3
|
-
"version": "1.7.0
|
|
3
|
+
"version": "1.7.0",
|
|
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",
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
"react-native-vector-icons": "*"
|
|
130
130
|
},
|
|
131
131
|
"engines": {
|
|
132
|
-
"node": ">=
|
|
132
|
+
"node": ">= 18.0.0"
|
|
133
133
|
},
|
|
134
134
|
"packageManager": "yarn@1.22.22",
|
|
135
135
|
"jest": {
|
|
@@ -13,17 +13,40 @@ 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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
/* istanbul ignore next */
|
|
24
|
+
if (node) { // Ensure node is not undefined - redundant safety
|
|
25
|
+
stack.push({ node, level: 0 });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
while (stack.length > 0) {
|
|
30
|
+
const item = stack.pop();
|
|
31
|
+
/* istanbul ignore next */
|
|
32
|
+
if (!item) continue; // Redundant safety check
|
|
33
|
+
|
|
34
|
+
const { node, level } = item;
|
|
35
|
+
|
|
36
|
+
// Push current node into the flattened array
|
|
37
|
+
flattened.push({ ...node, level });
|
|
38
|
+
|
|
39
|
+
// Add children nodes to the stack if the node is expanded
|
|
21
40
|
if (node.children && expandedIds.has(node.id)) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
41
|
+
for (let i = node.children.length - 1; i >= 0; i--) {
|
|
42
|
+
const childNode = node.children[i];
|
|
43
|
+
/* istanbul ignore next */
|
|
44
|
+
if (childNode) { // Ensure childNode is not undefined - redundant safety
|
|
45
|
+
stack.push({ node: childNode, level: level + 1 });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
26
48
|
}
|
|
27
49
|
}
|
|
50
|
+
|
|
28
51
|
return flattened;
|
|
29
|
-
}
|
|
52
|
+
}
|
|
@@ -19,8 +19,8 @@ export function initializeNodeMaps(storeId: string, initialData: TreeNode[]) {
|
|
|
19
19
|
updateChildToParentMap
|
|
20
20
|
} = treeViewStore.getState();
|
|
21
21
|
|
|
22
|
-
const tempNodeMap: Map<string, TreeNode> = new Map()
|
|
23
|
-
const tempChildToParentMap: Map<string, string> = new Map()
|
|
22
|
+
const tempNodeMap: Map<string, TreeNode> = new Map();
|
|
23
|
+
const tempChildToParentMap: Map<string, string> = new Map();
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Recursively processes nodes, adding them to the nodeMap and childToParentMap.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import isEqual from "lodash/isEqual";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -6,24 +6,33 @@ import isEqual from "lodash/isEqual";
|
|
|
6
6
|
* Ensures the effect runs on the first render and whenever dependencies deeply change.
|
|
7
7
|
*
|
|
8
8
|
* @param effect The effect callback function.
|
|
9
|
-
* @param
|
|
9
|
+
* @param deps The dependencies array to compare deeply.
|
|
10
10
|
*/
|
|
11
11
|
export default function useDeepCompareEffect(
|
|
12
12
|
effect: React.EffectCallback,
|
|
13
|
-
|
|
13
|
+
deps: React.DependencyList
|
|
14
14
|
) {
|
|
15
|
-
|
|
16
|
-
const
|
|
15
|
+
// Ref to track if it's the first render
|
|
16
|
+
const firstRenderRef = React.useRef<boolean>(true);
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// Memoized dependencies to avoid redundant `isEqual` checks
|
|
19
|
+
const memoizedDependencies = React.useMemo(() => deps, [deps]);
|
|
20
|
+
|
|
21
|
+
// Ref to store the previous dependencies
|
|
22
|
+
const dependenciesRef = React.useRef<React.DependencyList>(memoizedDependencies);
|
|
23
|
+
|
|
24
|
+
// Check for dependency changes
|
|
25
|
+
const dependenciesChanged = !isEqual(dependenciesRef.current, memoizedDependencies);
|
|
26
|
+
if (dependenciesChanged) {
|
|
27
|
+
dependenciesRef.current = memoizedDependencies;
|
|
28
|
+
}
|
|
20
29
|
|
|
21
30
|
React.useEffect(() => {
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
previousDependenciesRef.current = dependencies; // Update dependencies reference
|
|
25
|
-
return effect();
|
|
31
|
+
if (firstRenderRef.current) {
|
|
32
|
+
firstRenderRef.current = false;
|
|
26
33
|
}
|
|
34
|
+
|
|
35
|
+
return effect();
|
|
27
36
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
|
-
}, [
|
|
29
|
-
}
|
|
37
|
+
}, [dependenciesChanged]); // exclude the effect function from the dependencies
|
|
38
|
+
}
|