react-arborist 3.0.2 → 3.2.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/README.md +1 -0
- package/dist/index.js +52 -23
- package/dist/index.js.map +1 -1
- package/dist/interfaces/tree-api.d.ts +6 -0
- package/dist/module.js +52 -23
- package/dist/module.js.map +1 -1
- package/dist/state/selection-slice.d.ts +8 -2
- package/dist/types/tree-props.d.ts +2 -0
- package/package.json +3 -2
- package/src/components/provider.tsx +2 -2
- package/src/data/create-list.ts +23 -12
- package/src/interfaces/tree-api.ts +24 -9
- package/src/state/selection-slice.ts +12 -3
- package/src/types/tree-props.ts +2 -0
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -663,9 +663,9 @@ const $58f9381615aa3d17$export$e324594224ef24da = {
|
|
|
663
663
|
id
|
|
664
664
|
]).map((0, $eb5355379510ac9b$export$65e5b62a4c490288))
|
|
665
665
|
}),
|
|
666
|
-
set: (
|
|
666
|
+
set: (args)=>({
|
|
667
667
|
type: "SELECTION_SET",
|
|
668
|
-
|
|
668
|
+
...args
|
|
669
669
|
}),
|
|
670
670
|
mostRecent: (id)=>({
|
|
671
671
|
type: "SELECTION_MOST_RECENT",
|
|
@@ -708,7 +708,9 @@ function $58f9381615aa3d17$export$1650419e431d3ba3(state = (0, $9d556ecd8e421ffe
|
|
|
708
708
|
case "SELECTION_SET":
|
|
709
709
|
return {
|
|
710
710
|
...state,
|
|
711
|
-
ids:
|
|
711
|
+
ids: action.ids,
|
|
712
|
+
mostRecent: action.mostRecent,
|
|
713
|
+
anchor: action.anchor
|
|
712
714
|
};
|
|
713
715
|
case "SELECTION_MOST_RECENT":
|
|
714
716
|
return {
|
|
@@ -1474,20 +1476,26 @@ function $07d1cda4da20dc54$var$flattenTree(root) {
|
|
|
1474
1476
|
return list;
|
|
1475
1477
|
}
|
|
1476
1478
|
function $07d1cda4da20dc54$var$flattenAndFilterTree(root, isMatch) {
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
+
const matches = {};
|
|
1480
|
+
const list = [];
|
|
1481
|
+
function markMatch(node) {
|
|
1479
1482
|
const yes = !node.isRoot && isMatch(node);
|
|
1480
|
-
if (
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1483
|
+
if (yes) {
|
|
1484
|
+
matches[node.id] = true;
|
|
1485
|
+
let parent = node.parent;
|
|
1486
|
+
while(parent){
|
|
1487
|
+
matches[parent.id] = true;
|
|
1488
|
+
parent = parent.parent;
|
|
1489
|
+
}
|
|
1484
1490
|
}
|
|
1485
|
-
if (
|
|
1486
|
-
node
|
|
1487
|
-
];
|
|
1488
|
-
else return [];
|
|
1491
|
+
if (node.children) for (let child of node.children)markMatch(child);
|
|
1489
1492
|
}
|
|
1490
|
-
|
|
1493
|
+
function collect(node) {
|
|
1494
|
+
if (node.level >= 0 && matches[node.id]) list.push(node);
|
|
1495
|
+
if (node.isOpen) node.children?.forEach(collect);
|
|
1496
|
+
}
|
|
1497
|
+
markMatch(root);
|
|
1498
|
+
collect(root);
|
|
1491
1499
|
list.forEach($07d1cda4da20dc54$var$assignRowIndex);
|
|
1492
1500
|
return list;
|
|
1493
1501
|
}
|
|
@@ -1741,13 +1749,14 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
|
|
|
1741
1749
|
}
|
|
1742
1750
|
select(node, opts = {}) {
|
|
1743
1751
|
if (!node) return;
|
|
1752
|
+
const changeFocus = opts.focus !== false;
|
|
1744
1753
|
const id = $5c74fef433be2b0a$var$identify(node);
|
|
1745
|
-
this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(id));
|
|
1754
|
+
if (changeFocus) this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(id));
|
|
1746
1755
|
this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).only(id));
|
|
1747
1756
|
this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(id));
|
|
1748
1757
|
this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(id));
|
|
1749
1758
|
this.scrollTo(id, opts.align);
|
|
1750
|
-
if (this.focusedNode) $5c74fef433be2b0a$var$safeRun(this.props.onFocus, this.focusedNode);
|
|
1759
|
+
if (this.focusedNode && changeFocus) $5c74fef433be2b0a$var$safeRun(this.props.onFocus, this.focusedNode);
|
|
1751
1760
|
$5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
|
|
1752
1761
|
}
|
|
1753
1762
|
deselect(node) {
|
|
@@ -1779,19 +1788,34 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
|
|
|
1779
1788
|
$5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
|
|
1780
1789
|
}
|
|
1781
1790
|
deselectAll() {
|
|
1782
|
-
this.
|
|
1783
|
-
|
|
1784
|
-
|
|
1791
|
+
this.setSelection({
|
|
1792
|
+
ids: [],
|
|
1793
|
+
anchor: null,
|
|
1794
|
+
mostRecent: null
|
|
1795
|
+
});
|
|
1785
1796
|
$5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
|
|
1786
1797
|
}
|
|
1787
1798
|
selectAll() {
|
|
1788
|
-
this.
|
|
1799
|
+
this.setSelection({
|
|
1800
|
+
ids: Object.keys(this.idToIndex),
|
|
1801
|
+
anchor: this.firstNode,
|
|
1802
|
+
mostRecent: this.lastNode
|
|
1803
|
+
});
|
|
1789
1804
|
this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(this.lastNode?.id));
|
|
1790
|
-
this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(this.firstNode));
|
|
1791
|
-
this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(this.lastNode));
|
|
1792
1805
|
if (this.focusedNode) $5c74fef433be2b0a$var$safeRun(this.props.onFocus, this.focusedNode);
|
|
1793
1806
|
$5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
|
|
1794
1807
|
}
|
|
1808
|
+
setSelection(args) {
|
|
1809
|
+
const ids = new Set(args.ids?.map($5c74fef433be2b0a$var$identify));
|
|
1810
|
+
const anchor = $5c74fef433be2b0a$var$identifyNull(args.anchor);
|
|
1811
|
+
const mostRecent = $5c74fef433be2b0a$var$identifyNull(args.mostRecent);
|
|
1812
|
+
this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).set({
|
|
1813
|
+
ids: ids,
|
|
1814
|
+
anchor: anchor,
|
|
1815
|
+
mostRecent: mostRecent
|
|
1816
|
+
}));
|
|
1817
|
+
$5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
|
|
1818
|
+
}
|
|
1795
1819
|
/* Drag and Drop */ get cursorParentId() {
|
|
1796
1820
|
const { cursor: cursor } = this.state.dnd;
|
|
1797
1821
|
switch(cursor.type){
|
|
@@ -2052,7 +2076,9 @@ function $9511ad6af37da13b$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
|
|
|
2052
2076
|
]);
|
|
2053
2077
|
/* Expose the tree api */ (0, $foSVk$react.useImperativeHandle)(imperativeHandle, ()=>api);
|
|
2054
2078
|
/* Change selection based on props */ (0, $foSVk$react.useEffect)(()=>{
|
|
2055
|
-
if (api.props.selection) api.select(api.props.selection
|
|
2079
|
+
if (api.props.selection) api.select(api.props.selection, {
|
|
2080
|
+
focus: false
|
|
2081
|
+
});
|
|
2056
2082
|
else api.deselectAll();
|
|
2057
2083
|
}, [
|
|
2058
2084
|
api.props.selection
|
|
@@ -2075,6 +2101,9 @@ function $9511ad6af37da13b$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
|
|
|
2075
2101
|
options: {
|
|
2076
2102
|
rootElement: api.props.dndRootElement || undefined
|
|
2077
2103
|
},
|
|
2104
|
+
...treeProps.dndManager && {
|
|
2105
|
+
manager: treeProps.dndManager
|
|
2106
|
+
},
|
|
2078
2107
|
children: children
|
|
2079
2108
|
})
|
|
2080
2109
|
})
|