react-arborist 3.0.2 → 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.
@@ -80,6 +80,7 @@ export declare class TreeApi<T> {
80
80
  pageDown(): void;
81
81
  select(node: Identity, opts?: {
82
82
  align?: Align;
83
+ focus?: boolean;
83
84
  }): void;
84
85
  deselect(node: Identity): void;
85
86
  selectMulti(identity: Identity): void;
package/dist/module.js CHANGED
@@ -1453,20 +1453,26 @@ function $749bc746798c29ad$var$flattenTree(root) {
1453
1453
  return list;
1454
1454
  }
1455
1455
  function $749bc746798c29ad$var$flattenAndFilterTree(root, isMatch) {
1456
- function collect(node) {
1457
- let result = [];
1456
+ const matches = {};
1457
+ const list = [];
1458
+ function markMatch(node) {
1458
1459
  const yes = !node.isRoot && isMatch(node);
1459
- if (node.children) for (let child of node.children)result = result.concat(collect(child));
1460
- if (result.length) {
1461
- if (!node.isRoot) result.unshift(node);
1462
- return result;
1460
+ if (yes) {
1461
+ matches[node.id] = true;
1462
+ let parent = node.parent;
1463
+ while(parent){
1464
+ matches[parent.id] = true;
1465
+ parent = parent.parent;
1466
+ }
1463
1467
  }
1464
- if (yes) return [
1465
- node
1466
- ];
1467
- else return [];
1468
+ if (node.children) for (let child of node.children)markMatch(child);
1468
1469
  }
1469
- const list = collect(root).filter((n)=>n.parent?.isOpen);
1470
+ function collect(node) {
1471
+ if (node.level >= 0 && matches[node.id]) list.push(node);
1472
+ if (node.isOpen) node.children?.forEach(collect);
1473
+ }
1474
+ markMatch(root);
1475
+ collect(root);
1470
1476
  list.forEach($749bc746798c29ad$var$assignRowIndex);
1471
1477
  return list;
1472
1478
  }
@@ -1720,13 +1726,14 @@ class $bfece7c4aed4e9c4$export$e2da3477247342d1 {
1720
1726
  }
1721
1727
  select(node, opts = {}) {
1722
1728
  if (!node) return;
1729
+ const changeFocus = opts.focus !== false;
1723
1730
  const id = $bfece7c4aed4e9c4$var$identify(node);
1724
- this.dispatch((0, $c27b8e9863235052$export$d7ddd398f22d79ef)(id));
1731
+ if (changeFocus) this.dispatch((0, $c27b8e9863235052$export$d7ddd398f22d79ef)(id));
1725
1732
  this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).only(id));
1726
1733
  this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).anchor(id));
1727
1734
  this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).mostRecent(id));
1728
1735
  this.scrollTo(id, opts.align);
1729
- if (this.focusedNode) $bfece7c4aed4e9c4$var$safeRun(this.props.onFocus, this.focusedNode);
1736
+ if (this.focusedNode && changeFocus) $bfece7c4aed4e9c4$var$safeRun(this.props.onFocus, this.focusedNode);
1730
1737
  $bfece7c4aed4e9c4$var$safeRun(this.props.onSelect, this.selectedNodes);
1731
1738
  }
1732
1739
  deselect(node) {
@@ -2031,7 +2038,9 @@ function $dac24389e46ba09d$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
2031
2038
  ]);
2032
2039
  /* Expose the tree api */ (0, $g00cZ$useImperativeHandle)(imperativeHandle, ()=>api);
2033
2040
  /* Change selection based on props */ (0, $g00cZ$useEffect)(()=>{
2034
- if (api.props.selection) api.select(api.props.selection);
2041
+ if (api.props.selection) api.select(api.props.selection, {
2042
+ focus: false
2043
+ });
2035
2044
  else api.deselectAll();
2036
2045
  }, [
2037
2046
  api.props.selection
@@ -2054,6 +2063,9 @@ function $dac24389e46ba09d$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
2054
2063
  options: {
2055
2064
  rootElement: api.props.dndRootElement || undefined
2056
2065
  },
2066
+ ...treeProps.dndManager && {
2067
+ manager: treeProps.dndManager
2068
+ },
2057
2069
  children: children
2058
2070
  })
2059
2071
  })