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.
@@ -80,12 +80,18 @@ 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;
86
87
  selectContiguous(identity: Identity): void;
87
88
  deselectAll(): void;
88
89
  selectAll(): void;
90
+ setSelection(args: {
91
+ ids: (IdObj | string)[] | null;
92
+ anchor: IdObj | string | null;
93
+ mostRecent: IdObj | string | null;
94
+ }): void;
89
95
  get cursorParentId(): string | null;
90
96
  get cursorOverFolder(): boolean;
91
97
  get dragNodes(): NodeApi<T>[];
package/dist/module.js CHANGED
@@ -642,9 +642,9 @@ const $37bc167debff36d2$export$e324594224ef24da = {
642
642
  id
643
643
  ]).map((0, $0e6083160f4b36ed$export$65e5b62a4c490288))
644
644
  }),
645
- set: (ids)=>({
645
+ set: (args)=>({
646
646
  type: "SELECTION_SET",
647
- ids: ids
647
+ ...args
648
648
  }),
649
649
  mostRecent: (id)=>({
650
650
  type: "SELECTION_MOST_RECENT",
@@ -687,7 +687,9 @@ function $37bc167debff36d2$export$1650419e431d3ba3(state = (0, $6ad32e02250c922e
687
687
  case "SELECTION_SET":
688
688
  return {
689
689
  ...state,
690
- ids: new Set(action.ids)
690
+ ids: action.ids,
691
+ mostRecent: action.mostRecent,
692
+ anchor: action.anchor
691
693
  };
692
694
  case "SELECTION_MOST_RECENT":
693
695
  return {
@@ -1453,20 +1455,26 @@ function $749bc746798c29ad$var$flattenTree(root) {
1453
1455
  return list;
1454
1456
  }
1455
1457
  function $749bc746798c29ad$var$flattenAndFilterTree(root, isMatch) {
1456
- function collect(node) {
1457
- let result = [];
1458
+ const matches = {};
1459
+ const list = [];
1460
+ function markMatch(node) {
1458
1461
  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;
1462
+ if (yes) {
1463
+ matches[node.id] = true;
1464
+ let parent = node.parent;
1465
+ while(parent){
1466
+ matches[parent.id] = true;
1467
+ parent = parent.parent;
1468
+ }
1463
1469
  }
1464
- if (yes) return [
1465
- node
1466
- ];
1467
- else return [];
1470
+ if (node.children) for (let child of node.children)markMatch(child);
1468
1471
  }
1469
- const list = collect(root).filter((n)=>n.parent?.isOpen);
1472
+ function collect(node) {
1473
+ if (node.level >= 0 && matches[node.id]) list.push(node);
1474
+ if (node.isOpen) node.children?.forEach(collect);
1475
+ }
1476
+ markMatch(root);
1477
+ collect(root);
1470
1478
  list.forEach($749bc746798c29ad$var$assignRowIndex);
1471
1479
  return list;
1472
1480
  }
@@ -1720,13 +1728,14 @@ class $bfece7c4aed4e9c4$export$e2da3477247342d1 {
1720
1728
  }
1721
1729
  select(node, opts = {}) {
1722
1730
  if (!node) return;
1731
+ const changeFocus = opts.focus !== false;
1723
1732
  const id = $bfece7c4aed4e9c4$var$identify(node);
1724
- this.dispatch((0, $c27b8e9863235052$export$d7ddd398f22d79ef)(id));
1733
+ if (changeFocus) this.dispatch((0, $c27b8e9863235052$export$d7ddd398f22d79ef)(id));
1725
1734
  this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).only(id));
1726
1735
  this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).anchor(id));
1727
1736
  this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).mostRecent(id));
1728
1737
  this.scrollTo(id, opts.align);
1729
- if (this.focusedNode) $bfece7c4aed4e9c4$var$safeRun(this.props.onFocus, this.focusedNode);
1738
+ if (this.focusedNode && changeFocus) $bfece7c4aed4e9c4$var$safeRun(this.props.onFocus, this.focusedNode);
1730
1739
  $bfece7c4aed4e9c4$var$safeRun(this.props.onSelect, this.selectedNodes);
1731
1740
  }
1732
1741
  deselect(node) {
@@ -1758,19 +1767,34 @@ class $bfece7c4aed4e9c4$export$e2da3477247342d1 {
1758
1767
  $bfece7c4aed4e9c4$var$safeRun(this.props.onSelect, this.selectedNodes);
1759
1768
  }
1760
1769
  deselectAll() {
1761
- this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).clear());
1762
- this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).anchor(null));
1763
- this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).mostRecent(null));
1770
+ this.setSelection({
1771
+ ids: [],
1772
+ anchor: null,
1773
+ mostRecent: null
1774
+ });
1764
1775
  $bfece7c4aed4e9c4$var$safeRun(this.props.onSelect, this.selectedNodes);
1765
1776
  }
1766
1777
  selectAll() {
1767
- this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).set(new Set(Object.keys(this.idToIndex))));
1778
+ this.setSelection({
1779
+ ids: Object.keys(this.idToIndex),
1780
+ anchor: this.firstNode,
1781
+ mostRecent: this.lastNode
1782
+ });
1768
1783
  this.dispatch((0, $c27b8e9863235052$export$d7ddd398f22d79ef)(this.lastNode?.id));
1769
- this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).anchor(this.firstNode));
1770
- this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).mostRecent(this.lastNode));
1771
1784
  if (this.focusedNode) $bfece7c4aed4e9c4$var$safeRun(this.props.onFocus, this.focusedNode);
1772
1785
  $bfece7c4aed4e9c4$var$safeRun(this.props.onSelect, this.selectedNodes);
1773
1786
  }
1787
+ setSelection(args) {
1788
+ const ids = new Set(args.ids?.map($bfece7c4aed4e9c4$var$identify));
1789
+ const anchor = $bfece7c4aed4e9c4$var$identifyNull(args.anchor);
1790
+ const mostRecent = $bfece7c4aed4e9c4$var$identifyNull(args.mostRecent);
1791
+ this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).set({
1792
+ ids: ids,
1793
+ anchor: anchor,
1794
+ mostRecent: mostRecent
1795
+ }));
1796
+ $bfece7c4aed4e9c4$var$safeRun(this.props.onSelect, this.selectedNodes);
1797
+ }
1774
1798
  /* Drag and Drop */ get cursorParentId() {
1775
1799
  const { cursor: cursor } = this.state.dnd;
1776
1800
  switch(cursor.type){
@@ -2031,7 +2055,9 @@ function $dac24389e46ba09d$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
2031
2055
  ]);
2032
2056
  /* Expose the tree api */ (0, $g00cZ$useImperativeHandle)(imperativeHandle, ()=>api);
2033
2057
  /* Change selection based on props */ (0, $g00cZ$useEffect)(()=>{
2034
- if (api.props.selection) api.select(api.props.selection);
2058
+ if (api.props.selection) api.select(api.props.selection, {
2059
+ focus: false
2060
+ });
2035
2061
  else api.deselectAll();
2036
2062
  }, [
2037
2063
  api.props.selection
@@ -2054,6 +2080,9 @@ function $dac24389e46ba09d$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
2054
2080
  options: {
2055
2081
  rootElement: api.props.dndRootElement || undefined
2056
2082
  },
2083
+ ...treeProps.dndManager && {
2084
+ manager: treeProps.dndManager
2085
+ },
2057
2086
  children: children
2058
2087
  })
2059
2088
  })