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.
@@ -3,6 +3,6 @@ import { ConnectDropTarget } from "react-dnd";
3
3
  import { NodeApi } from "../interfaces/node-api";
4
4
  export declare type DropResult = {
5
5
  parentId: string | null;
6
- index: number;
6
+ index: number | null;
7
7
  };
8
8
  export declare function useDropHook(el: RefObject<HTMLElement | null>, node: NodeApi<any>): ConnectDropTarget;
package/dist/index.js CHANGED
@@ -68,7 +68,7 @@ var $eb5355379510ac9b$exports = {};
68
68
  $parcel$export($eb5355379510ac9b$exports, "bound", () => $eb5355379510ac9b$export$adf7c0fe6059d774);
69
69
  $parcel$export($eb5355379510ac9b$exports, "isItem", () => $eb5355379510ac9b$export$5318634f2ee07019);
70
70
  $parcel$export($eb5355379510ac9b$exports, "isClosed", () => $eb5355379510ac9b$export$4210f5ea57fbae57);
71
- $parcel$export($eb5355379510ac9b$exports, "isDecendent", () => $eb5355379510ac9b$export$1e38f72c6c546f70);
71
+ $parcel$export($eb5355379510ac9b$exports, "isDescendant", () => $eb5355379510ac9b$export$8503f9d2928f9a64);
72
72
  $parcel$export($eb5355379510ac9b$exports, "indexOf", () => $eb5355379510ac9b$export$305f7d4e9d4624f2);
73
73
  $parcel$export($eb5355379510ac9b$exports, "noop", () => $eb5355379510ac9b$export$8793edee2d425525);
74
74
  $parcel$export($eb5355379510ac9b$exports, "dfs", () => $eb5355379510ac9b$export$51b654aff22fc5a6);
@@ -92,7 +92,7 @@ function $eb5355379510ac9b$export$5318634f2ee07019(node) {
92
92
  function $eb5355379510ac9b$export$4210f5ea57fbae57(node) {
93
93
  return node && node.isInternal && !node.isOpen;
94
94
  }
95
- const $eb5355379510ac9b$export$1e38f72c6c546f70 = (a, b)=>{
95
+ const $eb5355379510ac9b$export$8503f9d2928f9a64 = (a, b)=>{
96
96
  let n = a;
97
97
  while(n){
98
98
  if (n.id === b.id) return true;
@@ -449,6 +449,15 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
449
449
  const i = this.childIndex;
450
450
  return this.parent?.children[i + 1] ?? null;
451
451
  }
452
+ isAncestorOf(node) {
453
+ if (!node) return false;
454
+ let ancestor = node;
455
+ while(ancestor){
456
+ if (ancestor.id === this.id) return true;
457
+ ancestor = ancestor.parent;
458
+ }
459
+ return false;
460
+ }
452
461
  select() {
453
462
  this.tree.select(this);
454
463
  }
@@ -623,7 +632,9 @@ const $9d556ecd8e421ffe$export$d4c72bab9d6cc13a = (props)=>({
623
632
  },
624
633
  drag: {
625
634
  id: null,
626
- idWillReceiveDrop: null
635
+ selectedIds: [],
636
+ destinationParentId: null,
637
+ destinationIndex: null
627
638
  },
628
639
  selection: {
629
640
  ids: new Set(),
@@ -982,7 +993,7 @@ function $74bee24dbb0f3e2b$export$715c0d031ede7907(node) {
982
993
  (0, $eb5355379510ac9b$export$c6d63370cef03886)(tree.props.onMove, {
983
994
  dragIds: dragIds,
984
995
  parentId: parentId === (0, $0d7f39915c1a8ae9$export$ec71a3379b43ae5c) ? null : parentId,
985
- index: index,
996
+ index: index === null ? 0 : index,
986
997
  dragNodes: tree.dragNodes,
987
998
  parentNode: tree.get(parentId)
988
999
  });
@@ -1027,7 +1038,7 @@ function $462841de7cc5b715$var$measureHover(el, offset) {
1027
1038
  };
1028
1039
  }
1029
1040
  function $462841de7cc5b715$var$getNodesAroundCursor(node, prev, next, hover) {
1030
- if (!node) // We're hoving over the empty part of the list, not over an item,
1041
+ if (!node) // We're hovering over the empty part of the list, not over an item,
1031
1042
  // Put the cursor below the last item which is "prev"
1032
1043
  return [
1033
1044
  prev,
@@ -1111,7 +1122,7 @@ function $462841de7cc5b715$export$f502ca02ebb85a1c(args) {
1111
1122
  const { node: node , nextNode: nextNode , prevNode: prevNode } = args;
1112
1123
  const [above, below] = $462841de7cc5b715$var$getNodesAroundCursor(node, prevNode, nextNode, hover);
1113
1124
  /* Hovering over the middle of a folder */ if (node && node.isInternal && hover.inMiddle) return {
1114
- drop: $462841de7cc5b715$var$dropAt(node.id, 0),
1125
+ drop: $462841de7cc5b715$var$dropAt(node.id, null),
1115
1126
  cursor: $462841de7cc5b715$var$highlightCursor(node.id)
1116
1127
  };
1117
1128
  /* At the top of the list */ if (!above) return {
@@ -1831,6 +1842,15 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1831
1842
  get dragNodes() {
1832
1843
  return this.state.dnd.dragIds.map((id)=>this.get(id)).filter((n)=>!!n);
1833
1844
  }
1845
+ get dragNode() {
1846
+ return this.get(this.state.nodes.drag.id);
1847
+ }
1848
+ get dragDestinationParent() {
1849
+ return this.get(this.state.nodes.drag.destinationParentId);
1850
+ }
1851
+ get dragDestinationIndex() {
1852
+ return this.state.nodes.drag.destinationIndex;
1853
+ }
1834
1854
  canDrop() {
1835
1855
  if (this.isFiltered) return false;
1836
1856
  const parentNode = this.get(this.state.dnd.parentId) ?? this.root;
@@ -1839,13 +1859,13 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1839
1859
  for (const drag of dragNodes){
1840
1860
  if (!drag) return false;
1841
1861
  if (!parentNode) return false;
1842
- if (drag.isInternal && $eb5355379510ac9b$exports.isDecendent(parentNode, drag)) return false;
1862
+ if (drag.isInternal && $eb5355379510ac9b$exports.isDescendant(parentNode, drag)) return false;
1843
1863
  }
1844
1864
  // Allow the user to insert their own logic
1845
1865
  if (typeof isDisabled == "function") return !isDisabled({
1846
1866
  parentNode: parentNode,
1847
1867
  dragNodes: this.dragNodes,
1848
- index: this.state.dnd.index
1868
+ index: this.state.dnd.index || 0
1849
1869
  });
1850
1870
  else if (typeof isDisabled == "string") // @ts-ignore
1851
1871
  return !parentNode.data[isDisabled];
@@ -1971,7 +1991,8 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1971
1991
  willReceiveDrop(node) {
1972
1992
  const id = $5c74fef433be2b0a$var$identifyNull(node);
1973
1993
  if (!id) return false;
1974
- return id === this.state.nodes.drag.idWillReceiveDrop;
1994
+ const { destinationParentId: destinationParentId , destinationIndex: destinationIndex } = this.state.nodes.drag;
1995
+ return id === destinationParentId && destinationIndex === null;
1975
1996
  }
1976
1997
  /* Tree Event Handlers */ onFocus() {
1977
1998
  const node = this.focusedNode || this.firstNode;
@@ -2009,30 +2030,28 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
2009
2030
 
2010
2031
 
2011
2032
 
2012
- function $2f73c1963cd9aa06$export$1650419e431d3ba3(state = {
2013
- id: null,
2014
- idWillReceiveDrop: null
2015
- }, action) {
2033
+
2034
+ function $2f73c1963cd9aa06$export$1650419e431d3ba3(state = (0, $9d556ecd8e421ffe$export$d4c72bab9d6cc13a)().nodes.drag, action) {
2016
2035
  switch(action.type){
2017
2036
  case "DND_DRAG_START":
2018
2037
  return {
2019
2038
  ...state,
2020
- id: action.id
2039
+ id: action.id,
2040
+ selectedIds: action.dragIds
2021
2041
  };
2022
2042
  case "DND_DRAG_END":
2023
2043
  return {
2024
2044
  ...state,
2025
- id: null
2026
- };
2027
- case "DND_CURSOR":
2028
- const c = action.cursor;
2029
- if (c.type === "highlight" && c.id !== state.idWillReceiveDrop) return {
2030
- ...state,
2031
- idWillReceiveDrop: c.id
2045
+ id: null,
2046
+ destinationParentId: null,
2047
+ destinationIndex: null,
2048
+ selectedIds: []
2032
2049
  };
2033
- else if (c.type !== "highlight" && state.idWillReceiveDrop !== null) return {
2050
+ case "DND_HOVERING":
2051
+ if (action.parentId !== state.destinationParentId || action.index != state.destinationIndex) return {
2034
2052
  ...state,
2035
- idWillReceiveDrop: null
2053
+ destinationParentId: action.parentId,
2054
+ destinationIndex: action.index
2036
2055
  };
2037
2056
  else return state;
2038
2057
  default: