react-arborist 3.0.1 → 3.1.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
@@ -1474,20 +1474,26 @@ function $07d1cda4da20dc54$var$flattenTree(root) {
1474
1474
  return list;
1475
1475
  }
1476
1476
  function $07d1cda4da20dc54$var$flattenAndFilterTree(root, isMatch) {
1477
- function collect(node) {
1478
- let result = [];
1477
+ const matches = {};
1478
+ const list = [];
1479
+ function markMatch(node) {
1479
1480
  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;
1481
+ if (yes) {
1482
+ matches[node.id] = true;
1483
+ let parent = node.parent;
1484
+ while(parent){
1485
+ matches[parent.id] = true;
1486
+ parent = parent.parent;
1487
+ }
1484
1488
  }
1485
- if (yes) return [
1486
- node
1487
- ];
1488
- else return [];
1489
+ if (node.children) for (let child of node.children)markMatch(child);
1489
1490
  }
1490
- const list = collect(root).filter((n)=>n.parent?.isOpen);
1491
+ function collect(node) {
1492
+ if (node.level >= 0 && matches[node.id]) list.push(node);
1493
+ if (node.isOpen) node.children?.forEach(collect);
1494
+ }
1495
+ markMatch(root);
1496
+ collect(root);
1491
1497
  list.forEach($07d1cda4da20dc54$var$assignRowIndex);
1492
1498
  return list;
1493
1499
  }
@@ -1741,13 +1747,14 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1741
1747
  }
1742
1748
  select(node, opts = {}) {
1743
1749
  if (!node) return;
1750
+ const changeFocus = opts.focus !== false;
1744
1751
  const id = $5c74fef433be2b0a$var$identify(node);
1745
- this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(id));
1752
+ if (changeFocus) this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(id));
1746
1753
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).only(id));
1747
1754
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(id));
1748
1755
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(id));
1749
1756
  this.scrollTo(id, opts.align);
1750
- if (this.focusedNode) $5c74fef433be2b0a$var$safeRun(this.props.onFocus, this.focusedNode);
1757
+ if (this.focusedNode && changeFocus) $5c74fef433be2b0a$var$safeRun(this.props.onFocus, this.focusedNode);
1751
1758
  $5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
1752
1759
  }
1753
1760
  deselect(node) {
@@ -1811,21 +1818,21 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1811
1818
  if (this.isFiltered) return false;
1812
1819
  const parentNode = this.get(this.state.dnd.parentId) ?? this.root;
1813
1820
  const dragNodes = this.dragNodes;
1814
- const check = this.props.disableDrop;
1821
+ const isDisabled = this.props.disableDrop;
1815
1822
  for (const drag of dragNodes){
1816
1823
  if (!drag) return false;
1817
1824
  if (!parentNode) return false;
1818
1825
  if (drag.isInternal && $eb5355379510ac9b$exports.isDecendent(parentNode, drag)) return false;
1819
1826
  }
1820
1827
  // Allow the user to insert their own logic
1821
- if (typeof check == "function") return check({
1828
+ if (typeof isDisabled == "function") return !isDisabled({
1822
1829
  parentNode: parentNode,
1823
1830
  dragNodes: this.dragNodes,
1824
1831
  index: this.state.dnd.index
1825
1832
  });
1826
- else if (typeof check == "string") // @ts-ignore
1827
- return !!parentNode.data[check];
1828
- else if (typeof check === "boolean") return check;
1833
+ else if (typeof isDisabled == "string") // @ts-ignore
1834
+ return !parentNode.data[isDisabled];
1835
+ else if (typeof isDisabled === "boolean") return !isDisabled;
1829
1836
  else return true;
1830
1837
  }
1831
1838
  hideCursor() {
@@ -2052,7 +2059,9 @@ function $9511ad6af37da13b$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
2052
2059
  ]);
2053
2060
  /* Expose the tree api */ (0, $foSVk$react.useImperativeHandle)(imperativeHandle, ()=>api);
2054
2061
  /* Change selection based on props */ (0, $foSVk$react.useEffect)(()=>{
2055
- if (api.props.selection) api.select(api.props.selection);
2062
+ if (api.props.selection) api.select(api.props.selection, {
2063
+ focus: false
2064
+ });
2056
2065
  else api.deselectAll();
2057
2066
  }, [
2058
2067
  api.props.selection
@@ -2075,6 +2084,9 @@ function $9511ad6af37da13b$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
2075
2084
  options: {
2076
2085
  rootElement: api.props.dndRootElement || undefined
2077
2086
  },
2087
+ ...treeProps.dndManager && {
2088
+ manager: treeProps.dndManager
2089
+ },
2078
2090
  children: children
2079
2091
  })
2080
2092
  })