react-arborist 2.3.0 → 3.0.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.
package/README.md CHANGED
@@ -17,18 +17,13 @@ Here is a Gmail sidebar clone built with react-arborist.
17
17
  - Inline renaming
18
18
  - Virtualized rendering
19
19
  - Custom styling
20
-
21
- **New Features in Version 2**
22
-
23
20
  - Keyboard navigation
24
21
  - Aria attributes
25
22
  - Tree filtering
26
23
  - Selection synchronization
27
- - More callbacks (onScroll, onActivate, onSelect)
24
+ - Callbacks (onScroll, onActivate, onSelect)
28
25
  - Controlled or uncontrolled trees
29
26
 
30
- > These docs are for version 2. It contains breaking changes. Here is the [v1.2.0 README](https://github.com/brimdata/react-arborist/tree/4fe9659d2c4cbd57582294330863d4fd7e7af74b).
31
-
32
27
  ## Installation
33
28
 
34
29
  ```
@@ -265,25 +260,26 @@ These are all the props you can pass to the Tree component.
265
260
  ```ts
266
261
  interface TreeProps<T> {
267
262
  /* Data Options */
268
- data?: T[];
269
- initialData?: T[];
263
+ data?: readonly T[];
264
+ initialData?: readonly T[];
270
265
 
271
266
  /* Data Handlers */
272
- onCreate?: handlers.CreateHandler;
273
- onMove?: handlers.MoveHandler;
274
- onRename?: handlers.RenameHandler;
275
- onDelete?: handlers.DeleteHandler;
267
+ onCreate?: handlers.CreateHandler<T>;
268
+ onMove?: handlers.MoveHandler<T>;
269
+ onRename?: handlers.RenameHandler<T>;
270
+ onDelete?: handlers.DeleteHandler<T>;
276
271
 
277
272
  /* Renderers*/
278
273
  children?: ElementType<renderers.NodeRendererProps<T>>;
279
274
  renderRow?: ElementType<renderers.RowRendererProps<T>>;
280
275
  renderDragPreview?: ElementType<renderers.DragPreviewProps>;
281
276
  renderCursor?: ElementType<renderers.CursorProps>;
277
+ renderContainer?: ElementType<{}>;
282
278
 
283
279
  /* Sizes */
284
280
  rowHeight?: number;
285
281
  overscanCount?: number;
286
- width?: number;
282
+ width?: number | string;
287
283
  height?: number;
288
284
  indent?: number;
289
285
  paddingTop?: number;
@@ -291,13 +287,21 @@ interface TreeProps<T> {
291
287
  padding?: number;
292
288
 
293
289
  /* Config */
290
+ childrenAccessor?: string | ((d: T) => T[] | null);
291
+ idAccessor?: string | ((d: T) => string);
294
292
  openByDefault?: boolean;
295
293
  selectionFollowsFocus?: boolean;
296
294
  disableMultiSelection?: boolean;
295
+ disableEdit?: string | boolean | BoolFunc<T>;
297
296
  disableDrag?: string | boolean | BoolFunc<T>;
298
- disableDrop?: string | boolean | BoolFunc<T>;
299
- childrenAccessor?: string | ((d: T) => T[]);
300
- idAccessor?: string | ((d: T) => string);
297
+ disableDrop?:
298
+ | string
299
+ | boolean
300
+ | ((args: {
301
+ parentNode: NodeApi<T>;
302
+ dragNodes: NodeApi<T>[];
303
+ index: number;
304
+ }) => boolean);
301
305
 
302
306
  /* Event Handlers */
303
307
  onActivate?: (node: NodeApi<T>) => void;
@@ -319,6 +323,7 @@ interface TreeProps<T> {
319
323
  /* Extra */
320
324
  className?: string | undefined;
321
325
  rowClassName?: string | undefined;
326
+
322
327
  dndRootElement?: globalThis.Node | null;
323
328
  onClick?: MouseEventHandler;
324
329
  onContextMenu?: MouseEventHandler;
@@ -1,2 +1,2 @@
1
1
  import React from "react";
2
- export declare const ListInnerElement: (props: any) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
2
+ export declare const ListInnerElement: React.ForwardRefExoticComponent<Pick<any, string | number | symbol> & React.RefAttributes<any>>;
@@ -1,2 +1,2 @@
1
1
  /// <reference types="react" />
2
- export declare const ListOuterElement: (props: import("react").HTMLProps<HTMLDivElement> & import("react").RefAttributes<unknown>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
2
+ export declare const ListOuterElement: import("react").ForwardRefExoticComponent<Pick<import("react").HTMLProps<HTMLDivElement>, "id" | "children" | "data" | "open" | "cite" | "form" | "label" | "slot" | "span" | "style" | "summary" | "title" | "pattern" | "start" | "hidden" | "color" | "content" | "size" | "default" | "wrap" | "multiple" | "disabled" | "onFocus" | "onClick" | "list" | "name" | "defaultValue" | "onBlur" | "onKeyDown" | "accessKey" | "dir" | "draggable" | "lang" | "translate" | "className" | "classID" | "value" | "defaultChecked" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "download" | "alt" | "coords" | "autoPlay" | "controls" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "dateTime" | "acceptCharset" | "action" | "autoComplete" | "encType" | "manifest" | "allowFullScreen" | "allowTransparency" | "frameBorder" | "accept" | "capture" | "checked" | "challenge" | "keyType" | "keyParams" | "htmlFor" | "as" | "charSet" | "httpEquiv" | "high" | "low" | "reversed" | "selected" | "async" | "cellPadding" | "cellSpacing" | "colSpan" | "headers" | "rowSpan" | "scope" | "cols" | "maxLength" | "minLength" | "kind" | "src" | "srcLang" | "preload" | "crossOrigin" | "defer" | "height" | "href" | "hrefLang" | "integrity" | "loop" | "marginHeight" | "marginWidth" | "max" | "media" | "mediaGroup" | "method" | "min" | "muted" | "nonce" | "noValidate" | "optimum" | "placeholder" | "playsInline" | "poster" | "readOnly" | "rel" | "required" | "rows" | "sandbox" | "scoped" | "scrolling" | "seamless" | "shape" | "sizes" | "srcDoc" | "srcSet" | "step" | "target" | "type" | "useMap" | "width" | "wmode" | "contentEditable" | "contextMenu" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key"> & import("react").RefAttributes<unknown>>;
@@ -1,4 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { TreeApi } from "../interfaces/tree-api";
3
3
  import { TreeProps } from "../types/tree-props";
4
- export declare const Tree: <T>(props: TreeProps<T> & import("react").RefAttributes<TreeApi<T> | undefined>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
4
+ declare function TreeComponent<T>(props: TreeProps<T>, ref: React.Ref<TreeApi<T> | undefined>): JSX.Element;
5
+ export declare const Tree: <T>(props: TreeProps<T> & {
6
+ ref?: import("react").ForwardedRef<TreeApi<T> | undefined> | undefined;
7
+ }) => ReturnType<typeof TreeComponent>;
8
+ export {};
package/dist/index.js CHANGED
@@ -201,7 +201,7 @@ function $eb5355379510ac9b$export$58fe32731f07ed56(tree) {
201
201
  const focus = tree.focusedNode;
202
202
  if (!focus) return null;
203
203
  if (focus.isOpen) return focus.id;
204
- if (focus.parent) return focus.parent.id;
204
+ if (focus.parent && !focus.parent.isRoot) return focus.parent.id;
205
205
  return null;
206
206
  }
207
207
 
@@ -374,7 +374,6 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
374
374
  this.children = params.children;
375
375
  this.parent = params.parent;
376
376
  this.isDraggable = params.isDraggable;
377
- this.isDroppable = params.isDroppable;
378
377
  this.rowIndex = params.rowIndex;
379
378
  }
380
379
  get isRoot() {
@@ -392,6 +391,9 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
392
391
  get isClosed() {
393
392
  return this.isLeaf ? false : !this.tree.isOpen(this.id);
394
393
  }
394
+ get isEditable() {
395
+ return this.tree.isEditable(this.data);
396
+ }
395
397
  get isEditing() {
396
398
  return this.tree.editingId === this.id;
397
399
  }
@@ -514,7 +516,6 @@ function $0d7f39915c1a8ae9$export$882461b6382ed46c(tree) {
514
516
  id: id,
515
517
  children: null,
516
518
  isDraggable: tree.isDraggable(data),
517
- isDroppable: tree.isDroppable(data),
518
519
  rowIndex: null
519
520
  });
520
521
  const children = tree.accessChildren(data);
@@ -532,7 +533,6 @@ function $0d7f39915c1a8ae9$export$882461b6382ed46c(tree) {
532
533
  parent: null,
533
534
  children: null,
534
535
  isDraggable: true,
535
- isDroppable: true,
536
536
  rowIndex: null
537
537
  });
538
538
  const data = tree.props.data ?? [];
@@ -635,7 +635,10 @@ const $9d556ecd8e421ffe$export$d4c72bab9d6cc13a = (props)=>({
635
635
  cursor: {
636
636
  type: "none"
637
637
  },
638
- dragId: null
638
+ dragId: null,
639
+ dragIds: [],
640
+ parentId: null,
641
+ index: -1
639
642
  }
640
643
  });
641
644
 
@@ -731,16 +734,24 @@ const $7d98f5b84ecaa66b$export$e324594224ef24da = {
731
734
  cursor: cursor
732
735
  };
733
736
  },
734
- dragStart (id) {
737
+ dragStart (id, dragIds) {
735
738
  return {
736
739
  type: "DND_DRAG_START",
737
- id: id
740
+ id: id,
741
+ dragIds: dragIds
738
742
  };
739
743
  },
740
744
  dragEnd () {
741
745
  return {
742
746
  type: "DND_DRAG_END"
743
747
  };
748
+ },
749
+ hovering (parentId, index) {
750
+ return {
751
+ type: "DND_HOVERING",
752
+ parentId: parentId,
753
+ index: index
754
+ };
744
755
  }
745
756
  };
746
757
  function $7d98f5b84ecaa66b$export$1650419e431d3ba3(state = (0, $9d556ecd8e421ffe$export$d4c72bab9d6cc13a)()["dnd"], action) {
@@ -753,12 +764,16 @@ function $7d98f5b84ecaa66b$export$1650419e431d3ba3(state = (0, $9d556ecd8e421ffe
753
764
  case "DND_DRAG_START":
754
765
  return {
755
766
  ...state,
756
- dragId: action.id
767
+ dragId: action.id,
768
+ dragIds: action.dragIds
757
769
  };
758
770
  case "DND_DRAG_END":
771
+ return (0, $9d556ecd8e421ffe$export$d4c72bab9d6cc13a)()["dnd"];
772
+ case "DND_HOVERING":
759
773
  return {
760
774
  ...state,
761
- dragId: null
775
+ parentId: action.parentId,
776
+ index: action.index
762
777
  };
763
778
  default:
764
779
  return state;
@@ -946,32 +961,32 @@ function $74bee24dbb0f3e2b$export$715c0d031ede7907(node) {
946
961
  const [_, ref, preview] = (0, $foSVk$reactdnd.useDrag)(()=>({
947
962
  canDrag: ()=>node.isDraggable,
948
963
  type: "NODE",
949
- item: ()=>({
950
- id: node.id,
951
- dragIds: tree.isSelected(node.id) ? Array.from(ids) : [
952
- node.id
953
- ]
954
- }),
955
- start: ()=>{
956
- tree.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).dragStart(node.id));
964
+ item: ()=>{
965
+ // This is fired once at the begging of a drag operation
966
+ const dragIds = tree.isSelected(node.id) ? Array.from(ids) : [
967
+ node.id
968
+ ];
969
+ tree.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).dragStart(node.id, dragIds));
970
+ return {
971
+ id: node.id
972
+ };
957
973
  },
958
- end: (item, monitor)=>{
959
- tree.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).dragEnd());
974
+ end: ()=>{
960
975
  tree.hideCursor();
961
- const drop = monitor.getDropResult();
976
+ let { parentId: parentId , index: index , dragIds: dragIds } = tree.state.dnd;
962
977
  // If they held down meta, we need to create a copy
963
978
  // if (drop.dropEffect === "copy")
964
- if (drop && drop.parentId) {
965
- const parentId = drop.parentId === (0, $0d7f39915c1a8ae9$export$ec71a3379b43ae5c) ? null : drop.parentId;
979
+ if (tree.canDrop()) {
966
980
  (0, $eb5355379510ac9b$export$c6d63370cef03886)(tree.props.onMove, {
967
- dragIds: item.dragIds,
968
- parentId: parentId,
969
- index: drop.index,
970
- dragNodes: item.dragIds.map((id)=>tree.get(id)),
971
- parentNode: tree.get(drop.parentId)
981
+ dragIds: dragIds,
982
+ parentId: parentId === (0, $0d7f39915c1a8ae9$export$ec71a3379b43ae5c) ? null : parentId,
983
+ index: index,
984
+ dragNodes: tree.dragNodes,
985
+ parentNode: tree.get(parentId)
972
986
  });
973
- tree.open(drop.parentId);
987
+ tree.open(parentId);
974
988
  }
989
+ tree.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).dragEnd());
975
990
  }
976
991
  }), [
977
992
  ids,
@@ -989,7 +1004,6 @@ function $74bee24dbb0f3e2b$export$715c0d031ede7907(node) {
989
1004
 
990
1005
 
991
1006
 
992
-
993
1007
  function $462841de7cc5b715$var$measureHover(el, offset) {
994
1008
  const rect = el.getBoundingClientRect();
995
1009
  const x = offset.x - Math.round(rect.x);
@@ -1056,16 +1070,6 @@ function $462841de7cc5b715$var$getDropLevel(hovering, aboveCursor, belowCursor,
1056
1070
  }
1057
1071
  return (0, $eb5355379510ac9b$export$adf7c0fe6059d774)(hoverLevel, min, max);
1058
1072
  }
1059
- function $462841de7cc5b715$var$canDrop(above, below) {
1060
- if (!above) return true;
1061
- let n = above;
1062
- if ((0, $eb5355379510ac9b$export$4210f5ea57fbae57)(above) && above !== below) n = above.parent;
1063
- while(n){
1064
- if (!n.isDroppable) return false;
1065
- n = n.parent;
1066
- }
1067
- return true;
1068
- }
1069
1073
  function $462841de7cc5b715$var$dropAt(parentId, index) {
1070
1074
  return {
1071
1075
  parentId: parentId || null,
@@ -1104,10 +1108,6 @@ function $462841de7cc5b715$export$f502ca02ebb85a1c(args) {
1104
1108
  const hover = $462841de7cc5b715$var$measureHover(args.element, args.offset);
1105
1109
  const { node: node , nextNode: nextNode , prevNode: prevNode } = args;
1106
1110
  const [above, below] = $462841de7cc5b715$var$getNodesAroundCursor(node, prevNode, nextNode, hover);
1107
- if (!$462841de7cc5b715$var$canDrop(above, below)) return {
1108
- drop: null,
1109
- cursor: $462841de7cc5b715$var$noCursor()
1110
- };
1111
1111
  /* Hovering over the middle of a folder */ if (node && node.isInternal && hover.inMiddle) return {
1112
1112
  drop: $462841de7cc5b715$var$dropAt(node.id, 0),
1113
1113
  cursor: $462841de7cc5b715$var$highlightCursor(node.id)
@@ -1130,15 +1130,16 @@ function $462841de7cc5b715$export$f502ca02ebb85a1c(args) {
1130
1130
  }
1131
1131
 
1132
1132
 
1133
+
1133
1134
  function $cf8ebdb33758b119$export$57afafec4637d997(el, node) {
1134
1135
  const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
1135
1136
  const [_, dropRef] = (0, $foSVk$reactdnd.useDrop)(()=>({
1136
1137
  accept: "NODE",
1137
- canDrop: (item, m)=>{
1138
- if (node.tree.isFiltered) return false;
1138
+ canDrop: ()=>tree.canDrop(),
1139
+ hover: (_item, m)=>{
1139
1140
  const offset = m.getClientOffset();
1140
- if (!el.current || !offset) return false;
1141
- const { drop: drop } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
1141
+ if (!el.current || !offset) return;
1142
+ const { cursor: cursor , drop: drop } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
1142
1143
  element: el.current,
1143
1144
  offset: offset,
1144
1145
  indent: tree.indent,
@@ -1146,43 +1147,13 @@ function $cf8ebdb33758b119$export$57afafec4637d997(el, node) {
1146
1147
  prevNode: node.prev,
1147
1148
  nextNode: node.next
1148
1149
  });
1149
- if (!drop) return false;
1150
- const dropParent = tree.get(drop.parentId) ?? tree.root;
1151
- for (let id of item.dragIds){
1152
- const drag = tree.get(id);
1153
- if (!drag) return false;
1154
- if (!dropParent) return false;
1155
- if (drag.isInternal && (0, $eb5355379510ac9b$export$1e38f72c6c546f70)(dropParent, drag)) return false;
1156
- }
1157
- return true;
1158
- },
1159
- hover: (item, m)=>{
1150
+ if (drop) tree.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).hovering(drop.parentId, drop.index));
1160
1151
  if (m.canDrop()) {
1161
- const offset = m.getClientOffset();
1162
- if (!el.current || !offset) return;
1163
- const { cursor: cursor } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
1164
- element: el.current,
1165
- offset: offset,
1166
- indent: tree.indent,
1167
- node: node,
1168
- prevNode: node.prev,
1169
- nextNode: node.next
1170
- });
1171
1152
  if (cursor) tree.showCursor(cursor);
1172
1153
  } else tree.hideCursor();
1173
1154
  },
1174
- drop: (item, m)=>{
1175
- const offset = m.getClientOffset();
1176
- if (!el.current || !offset) return;
1177
- const { drop: drop } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
1178
- element: el.current,
1179
- offset: offset,
1180
- indent: tree.indent,
1181
- node: node,
1182
- prevNode: node.prev,
1183
- nextNode: node.next
1184
- });
1185
- return drop;
1155
+ drop: (_, m)=>{
1156
+ if (!m.canDrop()) return null;
1186
1157
  }
1187
1158
  }), [
1188
1159
  node,
@@ -1418,26 +1389,28 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
1418
1389
  return;
1419
1390
  }
1420
1391
  if (e.key === "Enter") {
1421
- if (!tree.props.onRename) return;
1392
+ const node3 = tree.focusedNode;
1393
+ if (!node3) return;
1394
+ if (!node3.isEditable || !tree.props.onRename) return;
1422
1395
  setTimeout(()=>{
1423
- if (tree.focusedNode) tree.edit(tree.focusedNode);
1396
+ if (node3) tree.edit(node3);
1424
1397
  });
1425
1398
  return;
1426
1399
  }
1427
1400
  if (e.key === " ") {
1428
1401
  e.preventDefault();
1429
- const node3 = tree.focusedNode;
1430
- if (!node3) return;
1431
- if (node3.isLeaf) {
1432
- node3.select();
1433
- node3.activate();
1434
- } else node3.toggle();
1402
+ const node4 = tree.focusedNode;
1403
+ if (!node4) return;
1404
+ if (node4.isLeaf) {
1405
+ node4.select();
1406
+ node4.activate();
1407
+ } else node4.toggle();
1435
1408
  return;
1436
1409
  }
1437
1410
  if (e.key === "*") {
1438
- const node4 = tree.focusedNode;
1439
- if (!node4) return;
1440
- tree.openSiblings(node4);
1411
+ const node5 = tree.focusedNode;
1412
+ if (!node5) return;
1413
+ tree.openSiblings(node5);
1441
1414
  return;
1442
1415
  }
1443
1416
  if (e.key === "PageUp") {
@@ -1458,13 +1431,13 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
1458
1431
  $bb9a1e34249689ac$var$timeoutId = setTimeout(()=>{
1459
1432
  $bb9a1e34249689ac$var$focusSearchTerm = "";
1460
1433
  }, 600);
1461
- const node5 = tree.visibleNodes.find((n)=>{
1434
+ const node6 = tree.visibleNodes.find((n)=>{
1462
1435
  // @ts-ignore
1463
1436
  const name = n.data.name;
1464
1437
  if (typeof name === "string") return name.toLowerCase().startsWith($bb9a1e34249689ac$var$focusSearchTerm);
1465
1438
  else return false;
1466
1439
  });
1467
- if (node5) tree.focus(node5.id);
1440
+ if (node6) tree.focus(node6.id);
1468
1441
  },
1469
1442
  children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $foSVk$reactwindow.FixedSizeList), {
1470
1443
  className: tree.props.className,
@@ -1831,6 +1804,30 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1831
1804
  get cursorOverFolder() {
1832
1805
  return this.state.dnd.cursor.type === "highlight";
1833
1806
  }
1807
+ get dragNodes() {
1808
+ return this.state.dnd.dragIds.map((id)=>this.get(id)).filter((n)=>!!n);
1809
+ }
1810
+ canDrop() {
1811
+ if (this.isFiltered) return false;
1812
+ const parentNode = this.get(this.state.dnd.parentId) ?? this.root;
1813
+ const dragNodes = this.dragNodes;
1814
+ const check = this.props.disableDrop;
1815
+ for (const drag of dragNodes){
1816
+ if (!drag) return false;
1817
+ if (!parentNode) return false;
1818
+ if (drag.isInternal && $eb5355379510ac9b$exports.isDecendent(parentNode, drag)) return false;
1819
+ }
1820
+ // Allow the user to insert their own logic
1821
+ if (typeof check == "function") return check({
1822
+ parentNode: parentNode,
1823
+ dragNodes: this.dragNodes,
1824
+ index: this.state.dnd.index
1825
+ });
1826
+ else if (typeof check == "string") // @ts-ignore
1827
+ return !!parentNode.data[check];
1828
+ else if (typeof check === "boolean") return check;
1829
+ else return true;
1830
+ }
1834
1831
  hideCursor() {
1835
1832
  this.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).cursor({
1836
1833
  type: "none"
@@ -1928,12 +1925,12 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1928
1925
  if (this.isFiltered) return this.state.nodes.open.filtered[id] ?? true; // Filtered folders are always opened by default
1929
1926
  else return this.state.nodes.open.unfiltered[id] ?? def;
1930
1927
  }
1931
- isDraggable(data) {
1932
- const check = this.props.disableDrag || (()=>false);
1928
+ isEditable(data) {
1929
+ const check = this.props.disableEdit || (()=>false);
1933
1930
  return !$eb5355379510ac9b$exports.access(data, check) ?? true;
1934
1931
  }
1935
- isDroppable(data) {
1936
- const check = this.props.disableDrop || (()=>false);
1932
+ isDraggable(data) {
1933
+ const check = this.props.disableDrag || (()=>false);
1937
1934
  return !$eb5355379510ac9b$exports.access(data, check) ?? true;
1938
1935
  }
1939
1936
  isDragging(node) {
@@ -2096,54 +2093,19 @@ function $6c0a9a91d5e7ff45$export$5a6c424b1725f44f() {
2096
2093
  // In case we drop an item at the bottom of the list
2097
2094
  const [, drop] = (0, $foSVk$reactdnd.useDrop)(()=>({
2098
2095
  accept: "NODE",
2099
- hover: (item, m)=>{
2096
+ canDrop: (_item, m)=>{
2100
2097
  if (!m.isOver({
2101
2098
  shallow: true
2102
- })) return;
2103
- if (m.canDrop()) {
2104
- const offset = m.getClientOffset();
2105
- if (!tree.listEl.current || !offset) return;
2106
- const { cursor: cursor } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
2107
- element: tree.listEl.current,
2108
- offset: offset,
2109
- indent: tree.indent,
2110
- node: null,
2111
- prevNode: tree.visibleNodes[tree.visibleNodes.length - 1],
2112
- nextNode: null
2113
- });
2114
- if (cursor) tree.showCursor(cursor);
2115
- } else tree.hideCursor();
2099
+ })) return false;
2100
+ return tree.canDrop();
2116
2101
  },
2117
- canDrop: (item, m)=>{
2102
+ hover: (_item, m)=>{
2118
2103
  if (!m.isOver({
2119
2104
  shallow: true
2120
- })) return false;
2121
- if (tree.isFiltered) return false;
2122
- const offset = m.getClientOffset();
2123
- if (!tree.listEl.current || !offset) return false;
2124
- const { drop: drop } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
2125
- element: tree.listEl.current,
2126
- offset: offset,
2127
- indent: tree.indent,
2128
- node: null,
2129
- prevNode: tree.visibleNodes[tree.visibleNodes.length - 1],
2130
- nextNode: null
2131
- });
2132
- if (!drop) return false;
2133
- const dropParent = tree.get(drop.parentId) ?? tree.root;
2134
- for (let id of item.dragIds){
2135
- const drag = tree.get(id);
2136
- if (!drag) return false;
2137
- if (!dropParent) return false;
2138
- if (drag.isInternal && (0, $eb5355379510ac9b$export$1e38f72c6c546f70)(dropParent, drag)) return false;
2139
- }
2140
- return true;
2141
- },
2142
- drop: (item, m)=>{
2143
- if (m.didDrop()) return;
2105
+ })) return;
2144
2106
  const offset = m.getClientOffset();
2145
2107
  if (!tree.listEl.current || !offset) return;
2146
- const { drop: drop } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
2108
+ const { cursor: cursor , drop: drop } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
2147
2109
  element: tree.listEl.current,
2148
2110
  offset: offset,
2149
2111
  indent: tree.indent,
@@ -2151,7 +2113,10 @@ function $6c0a9a91d5e7ff45$export$5a6c424b1725f44f() {
2151
2113
  prevNode: tree.visibleNodes[tree.visibleNodes.length - 1],
2152
2114
  nextNode: null
2153
2115
  });
2154
- return drop;
2116
+ if (drop) tree.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).hovering(drop.parentId, drop.index));
2117
+ if (m.canDrop()) {
2118
+ if (cursor) tree.showCursor(cursor);
2119
+ } else tree.hideCursor();
2155
2120
  }
2156
2121
  }), [
2157
2122
  tree
@@ -2379,7 +2344,7 @@ Use the data prop if you want to provide your own handlers.`);
2379
2344
  }
2380
2345
 
2381
2346
 
2382
- const $641461e16d1a2941$export$7fbedc92909ed28e = /*#__PURE__*/ (0, $foSVk$react.forwardRef)(function Tree(props, ref) {
2347
+ function $641461e16d1a2941$var$TreeComponent(props, ref) {
2383
2348
  const treeProps = (0, $8e1ae4dab2259e77$export$d227906824a13416)(props);
2384
2349
  return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsxs)((0, $9511ad6af37da13b$export$c49dab5eb1b4ce0c), {
2385
2350
  treeProps: treeProps,
@@ -2391,7 +2356,8 @@ const $641461e16d1a2941$export$7fbedc92909ed28e = /*#__PURE__*/ (0, $foSVk$react
2391
2356
  /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $ed13b1d404b3872b$export$3e21b60650ec7e55), {})
2392
2357
  ]
2393
2358
  });
2394
- });
2359
+ }
2360
+ const $641461e16d1a2941$export$7fbedc92909ed28e = /*#__PURE__*/ (0, $foSVk$react.forwardRef)($641461e16d1a2941$var$TreeComponent);
2395
2361
 
2396
2362
 
2397
2363
  var $73c61fb8fd3b5237$exports = {};