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 CHANGED
@@ -327,6 +327,7 @@ interface TreeProps<T> {
327
327
  dndRootElement?: globalThis.Node | null;
328
328
  onClick?: MouseEventHandler;
329
329
  onContextMenu?: MouseEventHandler;
330
+ dndManager?: DragDropManager;
330
331
  }
331
332
  ```
332
333
 
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: (ids)=>({
666
+ set: (args)=>({
667
667
  type: "SELECTION_SET",
668
- ids: ids
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: new Set(action.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
- function collect(node) {
1478
- let result = [];
1479
+ const matches = {};
1480
+ const list = [];
1481
+ function markMatch(node) {
1479
1482
  const yes = !node.isRoot && isMatch(node);
1480
- if (node.children) for (let child of node.children)result = result.concat(collect(child));
1481
- if (result.length) {
1482
- if (!node.isRoot) result.unshift(node);
1483
- return result;
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 (yes) return [
1486
- node
1487
- ];
1488
- else return [];
1491
+ if (node.children) for (let child of node.children)markMatch(child);
1489
1492
  }
1490
- const list = collect(root).filter((n)=>n.parent?.isOpen);
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.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).clear());
1783
- this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(null));
1784
- this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(null));
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.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).set(new Set(Object.keys(this.idToIndex))));
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
  })