react-arborist 3.2.0 → 3.3.0-rc.1

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.
@@ -51,6 +51,7 @@ export declare class NodeApi<T = any> {
51
51
  get next(): NodeApi<T> | null;
52
52
  get prev(): NodeApi<T> | null;
53
53
  get nextSibling(): NodeApi<T> | null;
54
+ isAncestorOf(node: NodeApi<T> | null): boolean;
54
55
  select(): void;
55
56
  deselect(): void;
56
57
  selectMulti(): void;
@@ -95,6 +95,9 @@ export declare class TreeApi<T> {
95
95
  get cursorParentId(): string | null;
96
96
  get cursorOverFolder(): boolean;
97
97
  get dragNodes(): NodeApi<T>[];
98
+ get dragNode(): NodeApi<T> | null;
99
+ get dragDestinationParent(): NodeApi<T> | null;
100
+ get dragDestinationIndex(): number | null;
98
101
  canDrop(): boolean;
99
102
  hideCursor(): void;
100
103
  showCursor(cursor: Cursor): void;
package/dist/module.js CHANGED
@@ -47,7 +47,7 @@ var $0e6083160f4b36ed$exports = {};
47
47
  $parcel$export($0e6083160f4b36ed$exports, "bound", () => $0e6083160f4b36ed$export$adf7c0fe6059d774);
48
48
  $parcel$export($0e6083160f4b36ed$exports, "isItem", () => $0e6083160f4b36ed$export$5318634f2ee07019);
49
49
  $parcel$export($0e6083160f4b36ed$exports, "isClosed", () => $0e6083160f4b36ed$export$4210f5ea57fbae57);
50
- $parcel$export($0e6083160f4b36ed$exports, "isDecendent", () => $0e6083160f4b36ed$export$1e38f72c6c546f70);
50
+ $parcel$export($0e6083160f4b36ed$exports, "isDescendant", () => $0e6083160f4b36ed$export$8503f9d2928f9a64);
51
51
  $parcel$export($0e6083160f4b36ed$exports, "indexOf", () => $0e6083160f4b36ed$export$305f7d4e9d4624f2);
52
52
  $parcel$export($0e6083160f4b36ed$exports, "noop", () => $0e6083160f4b36ed$export$8793edee2d425525);
53
53
  $parcel$export($0e6083160f4b36ed$exports, "dfs", () => $0e6083160f4b36ed$export$51b654aff22fc5a6);
@@ -71,7 +71,7 @@ function $0e6083160f4b36ed$export$5318634f2ee07019(node) {
71
71
  function $0e6083160f4b36ed$export$4210f5ea57fbae57(node) {
72
72
  return node && node.isInternal && !node.isOpen;
73
73
  }
74
- const $0e6083160f4b36ed$export$1e38f72c6c546f70 = (a, b)=>{
74
+ const $0e6083160f4b36ed$export$8503f9d2928f9a64 = (a, b)=>{
75
75
  let n = a;
76
76
  while(n){
77
77
  if (n.id === b.id) return true;
@@ -428,6 +428,15 @@ class $096e74084443e9a3$export$d4b903da0f522dc8 {
428
428
  const i = this.childIndex;
429
429
  return this.parent?.children[i + 1] ?? null;
430
430
  }
431
+ isAncestorOf(node) {
432
+ if (!node) return false;
433
+ let ancestor = node;
434
+ while(ancestor){
435
+ if (ancestor.id === this.id) return true;
436
+ ancestor = ancestor.parent;
437
+ }
438
+ return false;
439
+ }
431
440
  select() {
432
441
  this.tree.select(this);
433
442
  }
@@ -602,7 +611,9 @@ const $6ad32e02250c922e$export$d4c72bab9d6cc13a = (props)=>({
602
611
  },
603
612
  drag: {
604
613
  id: null,
605
- idWillReceiveDrop: null
614
+ selectedIds: [],
615
+ destinationParentId: null,
616
+ destinationIndex: null
606
617
  },
607
618
  selection: {
608
619
  ids: new Set(),
@@ -961,7 +972,7 @@ function $907e707a330ef23a$export$715c0d031ede7907(node) {
961
972
  (0, $0e6083160f4b36ed$export$c6d63370cef03886)(tree.props.onMove, {
962
973
  dragIds: dragIds,
963
974
  parentId: parentId === (0, $81080a351c006222$export$ec71a3379b43ae5c) ? null : parentId,
964
- index: index,
975
+ index: index === null ? 0 : index,
965
976
  dragNodes: tree.dragNodes,
966
977
  parentNode: tree.get(parentId)
967
978
  });
@@ -1006,7 +1017,7 @@ function $2db980bfed6822da$var$measureHover(el, offset) {
1006
1017
  };
1007
1018
  }
1008
1019
  function $2db980bfed6822da$var$getNodesAroundCursor(node, prev, next, hover) {
1009
- if (!node) // We're hoving over the empty part of the list, not over an item,
1020
+ if (!node) // We're hovering over the empty part of the list, not over an item,
1010
1021
  // Put the cursor below the last item which is "prev"
1011
1022
  return [
1012
1023
  prev,
@@ -1090,7 +1101,7 @@ function $2db980bfed6822da$export$f502ca02ebb85a1c(args) {
1090
1101
  const { node: node , nextNode: nextNode , prevNode: prevNode } = args;
1091
1102
  const [above, below] = $2db980bfed6822da$var$getNodesAroundCursor(node, prevNode, nextNode, hover);
1092
1103
  /* Hovering over the middle of a folder */ if (node && node.isInternal && hover.inMiddle) return {
1093
- drop: $2db980bfed6822da$var$dropAt(node.id, 0),
1104
+ drop: $2db980bfed6822da$var$dropAt(node.id, null),
1094
1105
  cursor: $2db980bfed6822da$var$highlightCursor(node.id)
1095
1106
  };
1096
1107
  /* At the top of the list */ if (!above) return {
@@ -1810,6 +1821,15 @@ class $bfece7c4aed4e9c4$export$e2da3477247342d1 {
1810
1821
  get dragNodes() {
1811
1822
  return this.state.dnd.dragIds.map((id)=>this.get(id)).filter((n)=>!!n);
1812
1823
  }
1824
+ get dragNode() {
1825
+ return this.get(this.state.nodes.drag.id);
1826
+ }
1827
+ get dragDestinationParent() {
1828
+ return this.get(this.state.nodes.drag.destinationParentId);
1829
+ }
1830
+ get dragDestinationIndex() {
1831
+ return this.state.nodes.drag.destinationIndex;
1832
+ }
1813
1833
  canDrop() {
1814
1834
  if (this.isFiltered) return false;
1815
1835
  const parentNode = this.get(this.state.dnd.parentId) ?? this.root;
@@ -1818,13 +1838,13 @@ class $bfece7c4aed4e9c4$export$e2da3477247342d1 {
1818
1838
  for (const drag of dragNodes){
1819
1839
  if (!drag) return false;
1820
1840
  if (!parentNode) return false;
1821
- if (drag.isInternal && $0e6083160f4b36ed$exports.isDecendent(parentNode, drag)) return false;
1841
+ if (drag.isInternal && $0e6083160f4b36ed$exports.isDescendant(parentNode, drag)) return false;
1822
1842
  }
1823
1843
  // Allow the user to insert their own logic
1824
1844
  if (typeof isDisabled == "function") return !isDisabled({
1825
1845
  parentNode: parentNode,
1826
1846
  dragNodes: this.dragNodes,
1827
- index: this.state.dnd.index
1847
+ index: this.state.dnd.index || 0
1828
1848
  });
1829
1849
  else if (typeof isDisabled == "string") // @ts-ignore
1830
1850
  return !parentNode.data[isDisabled];
@@ -1950,7 +1970,8 @@ class $bfece7c4aed4e9c4$export$e2da3477247342d1 {
1950
1970
  willReceiveDrop(node) {
1951
1971
  const id = $bfece7c4aed4e9c4$var$identifyNull(node);
1952
1972
  if (!id) return false;
1953
- return id === this.state.nodes.drag.idWillReceiveDrop;
1973
+ const { destinationParentId: destinationParentId , destinationIndex: destinationIndex } = this.state.nodes.drag;
1974
+ return id === destinationParentId && destinationIndex === null;
1954
1975
  }
1955
1976
  /* Tree Event Handlers */ onFocus() {
1956
1977
  const node = this.focusedNode || this.firstNode;
@@ -1988,30 +2009,28 @@ class $bfece7c4aed4e9c4$export$e2da3477247342d1 {
1988
2009
 
1989
2010
 
1990
2011
 
1991
- function $5c35ee13c124a8cc$export$1650419e431d3ba3(state = {
1992
- id: null,
1993
- idWillReceiveDrop: null
1994
- }, action) {
2012
+
2013
+ function $5c35ee13c124a8cc$export$1650419e431d3ba3(state = (0, $6ad32e02250c922e$export$d4c72bab9d6cc13a)().nodes.drag, action) {
1995
2014
  switch(action.type){
1996
2015
  case "DND_DRAG_START":
1997
2016
  return {
1998
2017
  ...state,
1999
- id: action.id
2018
+ id: action.id,
2019
+ selectedIds: action.dragIds
2000
2020
  };
2001
2021
  case "DND_DRAG_END":
2002
2022
  return {
2003
2023
  ...state,
2004
- id: null
2005
- };
2006
- case "DND_CURSOR":
2007
- const c = action.cursor;
2008
- if (c.type === "highlight" && c.id !== state.idWillReceiveDrop) return {
2009
- ...state,
2010
- idWillReceiveDrop: c.id
2024
+ id: null,
2025
+ destinationParentId: null,
2026
+ destinationIndex: null,
2027
+ selectedIds: []
2011
2028
  };
2012
- else if (c.type !== "highlight" && state.idWillReceiveDrop !== null) return {
2029
+ case "DND_HOVERING":
2030
+ if (action.parentId !== state.destinationParentId || action.index != state.destinationIndex) return {
2013
2031
  ...state,
2014
- idWillReceiveDrop: null
2032
+ destinationParentId: action.parentId,
2033
+ destinationIndex: action.index
2015
2034
  };
2016
2035
  else return state;
2017
2036
  default: