@headless-tree/core 1.6.1 → 1.6.3
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/CHANGELOG.md +15 -0
- package/dist/index.d.mts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +93 -66
- package/dist/index.mjs +93 -66
- package/package.json +1 -1
- package/src/features/async-data-loader/feature.ts +14 -8
- package/src/features/async-data-loader/types.ts +11 -3
- package/src/features/drag-and-drop/drag-and-drop.spec.ts +175 -2
- package/src/features/drag-and-drop/feature.ts +76 -62
- package/src/features/drag-and-drop/types.ts +11 -0
- package/src/features/drag-and-drop/utils.ts +10 -4
- package/src/features/hotkeys-core/feature.ts +11 -4
- package/src/features/keyboard-drag-and-drop/feature.ts +1 -0
- package/src/features/prop-memoization/feature.ts +8 -0
- package/src/features/prop-memoization/types.ts +1 -0
- package/src/features/tree/feature.ts +6 -2
- package/src/utils.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @headless-tree/core
|
|
2
2
|
|
|
3
|
+
## 1.6.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4397d8c: Added `draggedItemOverwritesSelection` as config option to the Drag Feature. Setting it to false will disable the current default behavior, where dragging an unselected item will overwrite the selection to just the dragged item.
|
|
8
|
+
|
|
9
|
+
## 1.6.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 39a8b44: Add skipUpdateTree parameter to `updateCachedChildrenIds` and `updateCachedData` in async tree loader
|
|
14
|
+
- 26ecc1b: Fixed an issue where dropping items inside a collapsed folder will make the tree become un-focusable until a new item is clicked with mouse again. This could break usage with keyboard-only drag operations.
|
|
15
|
+
- 0108b7a: Fixed a bug where some hotkeys (like up/down navigation, search and renaming) doesn't work after items are dragged within the tree (#179)
|
|
16
|
+
- ffd2619: Fixed an issue where `canDropForeignDragObject` was being called in `onDragOver` events without payload. `canDropForeignDragObject` should never be called in `onDragOver` events since there, browsers do not allow access to the data transfer payload. Now, `canDropForeignDragObject` is only called in onDrop events, and `canDragForeignDragObjectOver` is always called in `onDragOver` events.
|
|
17
|
+
|
|
3
18
|
## 1.6.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -68,6 +68,11 @@ type DragAndDropFeatureDef<T> = {
|
|
|
68
68
|
onCompleteForeignDrop?: (items: ItemInstance<T>[]) => void;
|
|
69
69
|
/** When dragging for this many ms on a closed folder, the folder will automatically open. Set to zero to disable. */
|
|
70
70
|
openOnDropDelay?: number;
|
|
71
|
+
/** If true, `item.getProps()` will not include drag event handlers. Use `item.getDragHandleProps()` on the handler element. */
|
|
72
|
+
seperateDragHandle?: boolean;
|
|
73
|
+
/** If true, the item that is dragged is not selected, the selected items will be overwritten to just the dragged item.
|
|
74
|
+
* Defaults to true */
|
|
75
|
+
draggedItemOverwritesSelection?: boolean;
|
|
71
76
|
};
|
|
72
77
|
treeInstance: {
|
|
73
78
|
getDragTarget: () => DragTarget<T> | null;
|
|
@@ -84,6 +89,9 @@ type DragAndDropFeatureDef<T> = {
|
|
|
84
89
|
isDragTargetAbove: () => boolean;
|
|
85
90
|
isDragTargetBelow: () => boolean;
|
|
86
91
|
isDraggingOver: () => boolean;
|
|
92
|
+
/** Note that `item.getProps()` already passes in all drag event handlers by default. Set `seperateDragHandle` to true to
|
|
93
|
+
* disable the default behavior and use this on the handler element instead. */
|
|
94
|
+
getDragHandleProps: () => Record<string, any>;
|
|
87
95
|
};
|
|
88
96
|
hotkeys: never;
|
|
89
97
|
};
|
|
@@ -329,9 +337,11 @@ type AsyncDataLoaderFeatureDef<T> = {
|
|
|
329
337
|
* @param optimistic If true, the item will not trigger a state update on `loadingItemChildrens`, and
|
|
330
338
|
* the tree will continue to display the old data until the new data has loaded. */
|
|
331
339
|
invalidateChildrenIds: (optimistic?: boolean) => Promise<void>;
|
|
332
|
-
/** Set to undefined to clear cache without triggering automatic refetch. Use @invalidateItemData to clear and triggering refetch.
|
|
333
|
-
|
|
334
|
-
|
|
340
|
+
/** Set to undefined to clear cache without triggering automatic refetch. Use @invalidateItemData to clear and triggering refetch.
|
|
341
|
+
* @param skipUpdateTree If true, the tree will not rebuild the tree structure cache afterwards by calling `tree.rebuildTree()`. */
|
|
342
|
+
updateCachedData: (data: T | undefined, skipUpdateTree?: boolean) => void;
|
|
343
|
+
/** @param skipUpdateTree If true, the tree will not rebuild the tree structure cache afterwards by calling `tree.rebuildTree()`. */
|
|
344
|
+
updateCachedChildrenIds: (childrenIds: string[], skipUpdateTree?: boolean) => void;
|
|
335
345
|
hasLoadedData: () => boolean;
|
|
336
346
|
isLoading: () => boolean;
|
|
337
347
|
};
|
|
@@ -420,6 +430,7 @@ interface PropMemoizationDataRef {
|
|
|
420
430
|
memo?: {
|
|
421
431
|
tree?: Record<string, any>;
|
|
422
432
|
item?: Record<string, any>;
|
|
433
|
+
drag?: Record<string, any>;
|
|
423
434
|
search?: Record<string, any>;
|
|
424
435
|
rename?: Record<string, any>;
|
|
425
436
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -68,6 +68,11 @@ type DragAndDropFeatureDef<T> = {
|
|
|
68
68
|
onCompleteForeignDrop?: (items: ItemInstance<T>[]) => void;
|
|
69
69
|
/** When dragging for this many ms on a closed folder, the folder will automatically open. Set to zero to disable. */
|
|
70
70
|
openOnDropDelay?: number;
|
|
71
|
+
/** If true, `item.getProps()` will not include drag event handlers. Use `item.getDragHandleProps()` on the handler element. */
|
|
72
|
+
seperateDragHandle?: boolean;
|
|
73
|
+
/** If true, the item that is dragged is not selected, the selected items will be overwritten to just the dragged item.
|
|
74
|
+
* Defaults to true */
|
|
75
|
+
draggedItemOverwritesSelection?: boolean;
|
|
71
76
|
};
|
|
72
77
|
treeInstance: {
|
|
73
78
|
getDragTarget: () => DragTarget<T> | null;
|
|
@@ -84,6 +89,9 @@ type DragAndDropFeatureDef<T> = {
|
|
|
84
89
|
isDragTargetAbove: () => boolean;
|
|
85
90
|
isDragTargetBelow: () => boolean;
|
|
86
91
|
isDraggingOver: () => boolean;
|
|
92
|
+
/** Note that `item.getProps()` already passes in all drag event handlers by default. Set `seperateDragHandle` to true to
|
|
93
|
+
* disable the default behavior and use this on the handler element instead. */
|
|
94
|
+
getDragHandleProps: () => Record<string, any>;
|
|
87
95
|
};
|
|
88
96
|
hotkeys: never;
|
|
89
97
|
};
|
|
@@ -329,9 +337,11 @@ type AsyncDataLoaderFeatureDef<T> = {
|
|
|
329
337
|
* @param optimistic If true, the item will not trigger a state update on `loadingItemChildrens`, and
|
|
330
338
|
* the tree will continue to display the old data until the new data has loaded. */
|
|
331
339
|
invalidateChildrenIds: (optimistic?: boolean) => Promise<void>;
|
|
332
|
-
/** Set to undefined to clear cache without triggering automatic refetch. Use @invalidateItemData to clear and triggering refetch.
|
|
333
|
-
|
|
334
|
-
|
|
340
|
+
/** Set to undefined to clear cache without triggering automatic refetch. Use @invalidateItemData to clear and triggering refetch.
|
|
341
|
+
* @param skipUpdateTree If true, the tree will not rebuild the tree structure cache afterwards by calling `tree.rebuildTree()`. */
|
|
342
|
+
updateCachedData: (data: T | undefined, skipUpdateTree?: boolean) => void;
|
|
343
|
+
/** @param skipUpdateTree If true, the tree will not rebuild the tree structure cache afterwards by calling `tree.rebuildTree()`. */
|
|
344
|
+
updateCachedChildrenIds: (childrenIds: string[], skipUpdateTree?: boolean) => void;
|
|
335
345
|
hasLoadedData: () => boolean;
|
|
336
346
|
isLoading: () => boolean;
|
|
337
347
|
};
|
|
@@ -420,6 +430,7 @@ interface PropMemoizationDataRef {
|
|
|
420
430
|
memo?: {
|
|
421
431
|
tree?: Record<string, any>;
|
|
422
432
|
item?: Record<string, any>;
|
|
433
|
+
drag?: Record<string, any>;
|
|
423
434
|
search?: Record<string, any>;
|
|
424
435
|
rename?: Record<string, any>;
|
|
425
436
|
};
|
package/dist/index.js
CHANGED
|
@@ -125,6 +125,7 @@ var poll = (fn, interval = 100, timeout = 1e3) => new Promise((resolve) => {
|
|
|
125
125
|
}, interval);
|
|
126
126
|
clear = setTimeout(() => {
|
|
127
127
|
clearInterval(i);
|
|
128
|
+
resolve();
|
|
128
129
|
}, timeout);
|
|
129
130
|
});
|
|
130
131
|
|
|
@@ -214,12 +215,16 @@ var treeFeature = {
|
|
|
214
215
|
},
|
|
215
216
|
updateDomFocus: ({ tree }) => {
|
|
216
217
|
setTimeout(() => __async(null, null, function* () {
|
|
217
|
-
var _a, _b;
|
|
218
|
+
var _a, _b, _c, _d, _e;
|
|
218
219
|
const focusedItem = tree.getFocusedItem();
|
|
219
220
|
(_b = (_a = tree.getConfig()).scrollToItem) == null ? void 0 : _b.call(_a, focusedItem);
|
|
220
|
-
yield poll(() => focusedItem.getElement() !== null, 20);
|
|
221
|
+
yield poll(() => focusedItem.getElement() !== null, 20, 500);
|
|
221
222
|
const focusedElement = focusedItem.getElement();
|
|
222
|
-
if (!focusedElement)
|
|
223
|
+
if (!focusedElement) {
|
|
224
|
+
(_c = tree.getItems()[0]) == null ? void 0 : _c.setFocused();
|
|
225
|
+
(_e = (_d = tree.getItems()[0]) == null ? void 0 : _d.getElement()) == null ? void 0 : _e.focus();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
223
228
|
focusedElement.focus();
|
|
224
229
|
}));
|
|
225
230
|
},
|
|
@@ -1020,6 +1025,7 @@ var checkboxesFeature = {
|
|
|
1020
1025
|
};
|
|
1021
1026
|
|
|
1022
1027
|
// src/features/hotkeys-core/feature.ts
|
|
1028
|
+
var resolveKeyCode = (e) => e.code !== "" && e.code !== "Unidentified" ? e.code : e.key;
|
|
1023
1029
|
var specialKeys = {
|
|
1024
1030
|
// TODO:breaking deprecate auto-lowercase
|
|
1025
1031
|
letter: /^Key[A-Z]$/,
|
|
@@ -1068,9 +1074,10 @@ var hotkeysCoreFeature = {
|
|
|
1068
1074
|
if (e.target instanceof HTMLInputElement && ignoreHotkeysOnInputs) {
|
|
1069
1075
|
return;
|
|
1070
1076
|
}
|
|
1077
|
+
const resolvedCode = resolveKeyCode(e);
|
|
1071
1078
|
(_b = (_a = data.current).pressedKeys) != null ? _b : _a.pressedKeys = /* @__PURE__ */ new Set();
|
|
1072
|
-
const newMatch = !data.current.pressedKeys.has(
|
|
1073
|
-
data.current.pressedKeys.add(
|
|
1079
|
+
const newMatch = !data.current.pressedKeys.has(resolvedCode);
|
|
1080
|
+
data.current.pressedKeys.add(resolvedCode);
|
|
1074
1081
|
const hotkeyName = findHotkeyMatch(
|
|
1075
1082
|
data.current.pressedKeys,
|
|
1076
1083
|
tree,
|
|
@@ -1078,7 +1085,7 @@ var hotkeysCoreFeature = {
|
|
|
1078
1085
|
hotkeys
|
|
1079
1086
|
);
|
|
1080
1087
|
if (e.target instanceof HTMLInputElement) {
|
|
1081
|
-
data.current.pressedKeys.delete(
|
|
1088
|
+
data.current.pressedKeys.delete(resolvedCode);
|
|
1082
1089
|
}
|
|
1083
1090
|
if (!hotkeyName) return;
|
|
1084
1091
|
const hotkeyConfig = __spreadValues(__spreadValues({}, tree.getHotkeyPresets()[hotkeyName]), hotkeys == null ? void 0 : hotkeys[hotkeyName]);
|
|
@@ -1093,7 +1100,7 @@ var hotkeysCoreFeature = {
|
|
|
1093
1100
|
const keyup = (e) => {
|
|
1094
1101
|
var _a, _b;
|
|
1095
1102
|
(_b = (_a = data.current).pressedKeys) != null ? _b : _a.pressedKeys = /* @__PURE__ */ new Set();
|
|
1096
|
-
data.current.pressedKeys.delete(e
|
|
1103
|
+
data.current.pressedKeys.delete(resolveKeyCode(e));
|
|
1097
1104
|
};
|
|
1098
1105
|
const reset = () => {
|
|
1099
1106
|
data.current.pressedKeys = /* @__PURE__ */ new Set();
|
|
@@ -1274,15 +1281,17 @@ var asyncDataLoaderFeature = {
|
|
|
1274
1281
|
}
|
|
1275
1282
|
yield loadChildrenIds(tree, itemId);
|
|
1276
1283
|
}),
|
|
1277
|
-
updateCachedChildrenIds: ({ tree, itemId }, childrenIds) => {
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1284
|
+
updateCachedChildrenIds: ({ tree, itemId }, childrenIds, skipUpdateTree) => {
|
|
1285
|
+
getDataRef(tree).current.childrenIds[itemId] = childrenIds;
|
|
1286
|
+
if (!skipUpdateTree) {
|
|
1287
|
+
tree.rebuildTree();
|
|
1288
|
+
}
|
|
1281
1289
|
},
|
|
1282
|
-
updateCachedData: ({ tree, itemId }, data) => {
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1290
|
+
updateCachedData: ({ tree, itemId }, data, skipUpdateTree) => {
|
|
1291
|
+
getDataRef(tree).current.itemData[itemId] = data;
|
|
1292
|
+
if (!skipUpdateTree) {
|
|
1293
|
+
tree.rebuildTree();
|
|
1294
|
+
}
|
|
1286
1295
|
},
|
|
1287
1296
|
hasLoadedData: ({ tree, itemId }) => {
|
|
1288
1297
|
const dataRef = tree.getDataRef();
|
|
@@ -1449,15 +1458,16 @@ var getReparentTarget = (item, reparentLevel, draggedItems) => {
|
|
|
1449
1458
|
dragLineLevel: reparentLevel
|
|
1450
1459
|
};
|
|
1451
1460
|
};
|
|
1452
|
-
var getDragTarget = (e, item, tree, canReorder = tree.getConfig().canReorder) => {
|
|
1461
|
+
var getDragTarget = (e, item, tree, hasDataTransferPayload, canReorder = tree.getConfig().canReorder) => {
|
|
1453
1462
|
var _a;
|
|
1463
|
+
const dataTransfer = hasDataTransferPayload ? e.dataTransfer : null;
|
|
1454
1464
|
const draggedItems = (_a = tree.getState().dnd) == null ? void 0 : _a.draggedItems;
|
|
1455
1465
|
const itemMeta = item.getItemMeta();
|
|
1456
1466
|
const parent = item.getParent();
|
|
1457
1467
|
const itemTarget = { item };
|
|
1458
1468
|
const parentTarget = parent ? { item: parent } : null;
|
|
1459
|
-
const canBecomeSibling = parentTarget && canDrop(
|
|
1460
|
-
const canMakeChild = canDrop(
|
|
1469
|
+
const canBecomeSibling = parentTarget && canDrop(dataTransfer, parentTarget, tree);
|
|
1470
|
+
const canMakeChild = canDrop(dataTransfer, itemTarget, tree);
|
|
1461
1471
|
const placement = getTargetPlacement(e, item, tree, canMakeChild);
|
|
1462
1472
|
if (!canReorder && parent && canBecomeSibling && placement.type !== 2 /* MakeChild */) {
|
|
1463
1473
|
if (draggedItems == null ? void 0 : draggedItems.some((item2) => item2.isDescendentOf(parent.getId()))) {
|
|
@@ -1466,7 +1476,7 @@ var getDragTarget = (e, item, tree, canReorder = tree.getConfig().canReorder) =>
|
|
|
1466
1476
|
return parentTarget;
|
|
1467
1477
|
}
|
|
1468
1478
|
if (!canReorder && parent && !canBecomeSibling) {
|
|
1469
|
-
return getDragTarget(e, parent, tree, false);
|
|
1479
|
+
return getDragTarget(e, parent, tree, hasDataTransferPayload, false);
|
|
1470
1480
|
}
|
|
1471
1481
|
if (!parent) {
|
|
1472
1482
|
return itemTarget;
|
|
@@ -1475,7 +1485,7 @@ var getDragTarget = (e, item, tree, canReorder = tree.getConfig().canReorder) =>
|
|
|
1475
1485
|
return itemTarget;
|
|
1476
1486
|
}
|
|
1477
1487
|
if (!canBecomeSibling) {
|
|
1478
|
-
return getDragTarget(e, parent, tree, false);
|
|
1488
|
+
return getDragTarget(e, parent, tree, hasDataTransferPayload, false);
|
|
1479
1489
|
}
|
|
1480
1490
|
if (placement.type === 3 /* Reparent */) {
|
|
1481
1491
|
return getReparentTarget(item, placement.reparentLevel, draggedItems);
|
|
@@ -1519,7 +1529,8 @@ var dragAndDropFeature = {
|
|
|
1519
1529
|
canDragForeignDragObjectOver: defaultConfig.canDropForeignDragObject !== defaultCanDropForeignDragObject ? (dataTransfer) => dataTransfer.effectAllowed !== "none" : () => false,
|
|
1520
1530
|
setDndState: makeStateUpdater("dnd", tree),
|
|
1521
1531
|
canReorder: true,
|
|
1522
|
-
openOnDropDelay: 800
|
|
1532
|
+
openOnDropDelay: 800,
|
|
1533
|
+
draggedItemOverwritesSelection: true
|
|
1523
1534
|
}, defaultConfig),
|
|
1524
1535
|
stateHandlerNames: {
|
|
1525
1536
|
dnd: "setDndState"
|
|
@@ -1612,36 +1623,8 @@ var dragAndDropFeature = {
|
|
|
1612
1623
|
}
|
|
1613
1624
|
},
|
|
1614
1625
|
itemInstance: {
|
|
1615
|
-
getProps: ({ tree, item, prev }) => __spreadProps(__spreadValues({}, prev == null ? void 0 : prev()), {
|
|
1616
|
-
draggable: true,
|
|
1626
|
+
getProps: ({ tree, item, prev }) => __spreadProps(__spreadValues(__spreadValues({}, prev == null ? void 0 : prev()), tree.getConfig().seperateDragHandle ? {} : item.getDragHandleProps()), {
|
|
1617
1627
|
onDragEnter: (e) => e.preventDefault(),
|
|
1618
|
-
onDragStart: (e) => {
|
|
1619
|
-
var _a, _b, _c, _d;
|
|
1620
|
-
const selectedItems = tree.getSelectedItems ? tree.getSelectedItems() : [tree.getFocusedItem()];
|
|
1621
|
-
const items = selectedItems.includes(item) ? selectedItems : [item];
|
|
1622
|
-
const config = tree.getConfig();
|
|
1623
|
-
if (!selectedItems.includes(item)) {
|
|
1624
|
-
(_a = tree.setSelectedItems) == null ? void 0 : _a.call(tree, [item.getItemMeta().itemId]);
|
|
1625
|
-
}
|
|
1626
|
-
if (!((_c = (_b = config.canDrag) == null ? void 0 : _b.call(config, items)) != null ? _c : true)) {
|
|
1627
|
-
e.preventDefault();
|
|
1628
|
-
return;
|
|
1629
|
-
}
|
|
1630
|
-
if (config.setDragImage) {
|
|
1631
|
-
const { imgElement, xOffset, yOffset } = config.setDragImage(items);
|
|
1632
|
-
(_d = e.dataTransfer) == null ? void 0 : _d.setDragImage(imgElement, xOffset != null ? xOffset : 0, yOffset != null ? yOffset : 0);
|
|
1633
|
-
}
|
|
1634
|
-
if (config.createForeignDragObject && e.dataTransfer) {
|
|
1635
|
-
const { format, data, dropEffect, effectAllowed } = config.createForeignDragObject(items);
|
|
1636
|
-
e.dataTransfer.setData(format, data);
|
|
1637
|
-
if (dropEffect) e.dataTransfer.dropEffect = dropEffect;
|
|
1638
|
-
if (effectAllowed) e.dataTransfer.effectAllowed = effectAllowed;
|
|
1639
|
-
}
|
|
1640
|
-
tree.applySubStateUpdate("dnd", {
|
|
1641
|
-
draggedItems: items,
|
|
1642
|
-
draggingOverItem: tree.getFocusedItem()
|
|
1643
|
-
});
|
|
1644
|
-
},
|
|
1645
1628
|
onDragOver: (e) => {
|
|
1646
1629
|
var _a, _b, _c;
|
|
1647
1630
|
e.stopPropagation();
|
|
@@ -1657,12 +1640,12 @@ var dragAndDropFeature = {
|
|
|
1657
1640
|
dataRef.current.lastDragCode = nextDragCode;
|
|
1658
1641
|
dataRef.current.lastDragEnter = Date.now();
|
|
1659
1642
|
handleAutoOpenFolder(dataRef, tree, item, placement);
|
|
1660
|
-
const target = getDragTarget(e, item, tree);
|
|
1643
|
+
const target = getDragTarget(e, item, tree, false);
|
|
1661
1644
|
if (!((_a = tree.getState().dnd) == null ? void 0 : _a.draggedItems) && (!e.dataTransfer || !((_c = (_b = tree.getConfig()).canDragForeignDragObjectOver) == null ? void 0 : _c.call(_b, e.dataTransfer, target)))) {
|
|
1662
1645
|
dataRef.current.lastAllowDrop = false;
|
|
1663
1646
|
return;
|
|
1664
1647
|
}
|
|
1665
|
-
if (!canDrop(
|
|
1648
|
+
if (!canDrop(null, target, tree)) {
|
|
1666
1649
|
dataRef.current.lastAllowDrop = false;
|
|
1667
1650
|
return;
|
|
1668
1651
|
}
|
|
@@ -1685,24 +1668,11 @@ var dragAndDropFeature = {
|
|
|
1685
1668
|
}));
|
|
1686
1669
|
}, 100);
|
|
1687
1670
|
},
|
|
1688
|
-
onDragEnd: (e) => {
|
|
1689
|
-
var _a, _b;
|
|
1690
|
-
const { onCompleteForeignDrop, canDragForeignDragObjectOver } = tree.getConfig();
|
|
1691
|
-
const draggedItems = (_a = tree.getState().dnd) == null ? void 0 : _a.draggedItems;
|
|
1692
|
-
if (((_b = e.dataTransfer) == null ? void 0 : _b.dropEffect) === "none" || !draggedItems) {
|
|
1693
|
-
return;
|
|
1694
|
-
}
|
|
1695
|
-
const target = getDragTarget(e, item, tree);
|
|
1696
|
-
if (canDragForeignDragObjectOver && e.dataTransfer && !canDragForeignDragObjectOver(e.dataTransfer, target)) {
|
|
1697
|
-
return;
|
|
1698
|
-
}
|
|
1699
|
-
onCompleteForeignDrop == null ? void 0 : onCompleteForeignDrop(draggedItems);
|
|
1700
|
-
},
|
|
1701
1671
|
onDrop: (e) => __async(null, null, function* () {
|
|
1702
1672
|
var _a, _b, _c;
|
|
1703
1673
|
e.stopPropagation();
|
|
1704
1674
|
const dataRef = tree.getDataRef();
|
|
1705
|
-
const target = getDragTarget(e, item, tree);
|
|
1675
|
+
const target = getDragTarget(e, item, tree, true);
|
|
1706
1676
|
const draggedItems = (_a = tree.getState().dnd) == null ? void 0 : _a.draggedItems;
|
|
1707
1677
|
const isValidDrop = canDrop(e.dataTransfer, target, tree);
|
|
1708
1678
|
tree.applySubStateUpdate("dnd", {
|
|
@@ -1718,11 +1688,59 @@ var dragAndDropFeature = {
|
|
|
1718
1688
|
dataRef.current.lastDragCode = void 0;
|
|
1719
1689
|
if (draggedItems) {
|
|
1720
1690
|
yield (_b = config.onDrop) == null ? void 0 : _b.call(config, draggedItems, target);
|
|
1691
|
+
draggedItems[0].setFocused();
|
|
1721
1692
|
} else if (e.dataTransfer) {
|
|
1722
1693
|
yield (_c = config.onDropForeignDragObject) == null ? void 0 : _c.call(config, e.dataTransfer, target);
|
|
1723
1694
|
}
|
|
1695
|
+
tree.applySubStateUpdate("dnd", null);
|
|
1696
|
+
tree.updateDomFocus();
|
|
1724
1697
|
})
|
|
1725
1698
|
}),
|
|
1699
|
+
getDragHandleProps: ({ tree, item, prev }) => __spreadProps(__spreadValues({}, prev == null ? void 0 : prev()), {
|
|
1700
|
+
draggable: true,
|
|
1701
|
+
onDragStart: (e) => {
|
|
1702
|
+
var _a, _b, _c, _d;
|
|
1703
|
+
const { draggedItemOverwritesSelection } = tree.getConfig();
|
|
1704
|
+
const selectedItems = tree.getSelectedItems ? tree.getSelectedItems() : [tree.getFocusedItem()];
|
|
1705
|
+
const overwriteSelection = !selectedItems.includes(item) && draggedItemOverwritesSelection;
|
|
1706
|
+
const items = overwriteSelection ? [item] : selectedItems;
|
|
1707
|
+
const config = tree.getConfig();
|
|
1708
|
+
if (overwriteSelection) {
|
|
1709
|
+
(_a = tree.setSelectedItems) == null ? void 0 : _a.call(tree, [item.getItemMeta().itemId]);
|
|
1710
|
+
}
|
|
1711
|
+
if (!((_c = (_b = config.canDrag) == null ? void 0 : _b.call(config, items)) != null ? _c : true)) {
|
|
1712
|
+
e.preventDefault();
|
|
1713
|
+
return;
|
|
1714
|
+
}
|
|
1715
|
+
if (config.setDragImage) {
|
|
1716
|
+
const { imgElement, xOffset, yOffset } = config.setDragImage(items);
|
|
1717
|
+
(_d = e.dataTransfer) == null ? void 0 : _d.setDragImage(imgElement, xOffset != null ? xOffset : 0, yOffset != null ? yOffset : 0);
|
|
1718
|
+
}
|
|
1719
|
+
if (config.createForeignDragObject && e.dataTransfer) {
|
|
1720
|
+
const { format, data, dropEffect, effectAllowed } = config.createForeignDragObject(items);
|
|
1721
|
+
e.dataTransfer.setData(format, data);
|
|
1722
|
+
if (dropEffect) e.dataTransfer.dropEffect = dropEffect;
|
|
1723
|
+
if (effectAllowed) e.dataTransfer.effectAllowed = effectAllowed;
|
|
1724
|
+
}
|
|
1725
|
+
tree.applySubStateUpdate("dnd", {
|
|
1726
|
+
draggedItems: items,
|
|
1727
|
+
draggingOverItem: tree.getFocusedItem()
|
|
1728
|
+
});
|
|
1729
|
+
},
|
|
1730
|
+
onDragEnd: (e) => {
|
|
1731
|
+
var _a, _b;
|
|
1732
|
+
const { onCompleteForeignDrop, canDragForeignDragObjectOver } = tree.getConfig();
|
|
1733
|
+
const draggedItems = (_a = tree.getState().dnd) == null ? void 0 : _a.draggedItems;
|
|
1734
|
+
if (((_b = e.dataTransfer) == null ? void 0 : _b.dropEffect) === "none" || !draggedItems) {
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1737
|
+
const target = getDragTarget(e, item, tree, false);
|
|
1738
|
+
if (canDragForeignDragObjectOver && e.dataTransfer && !canDragForeignDragObjectOver(e.dataTransfer, target)) {
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1741
|
+
onCompleteForeignDrop == null ? void 0 : onCompleteForeignDrop(draggedItems);
|
|
1742
|
+
}
|
|
1743
|
+
}),
|
|
1726
1744
|
isDragTarget: ({ tree, item }) => {
|
|
1727
1745
|
const target = tree.getDragTarget();
|
|
1728
1746
|
return target ? target.item.getId() === item.getId() : false;
|
|
@@ -1946,6 +1964,7 @@ var keyboardDragAndDropFeature = {
|
|
|
1946
1964
|
} else if (dataTransfer) {
|
|
1947
1965
|
yield (_d = config.onDropForeignDragObject) == null ? void 0 : _d.call(config, dataTransfer, target);
|
|
1948
1966
|
}
|
|
1967
|
+
tree.updateDomFocus();
|
|
1949
1968
|
tree.applySubStateUpdate(
|
|
1950
1969
|
"assistiveDndState",
|
|
1951
1970
|
3 /* Completed */
|
|
@@ -2296,6 +2315,14 @@ var propMemoizationFeature = {
|
|
|
2296
2315
|
(_e = (_d = dataRef.current.memo).item) != null ? _e : _d.item = {};
|
|
2297
2316
|
return memoize(props, dataRef.current.memo.item);
|
|
2298
2317
|
},
|
|
2318
|
+
getDragHandleProps: ({ item, prev }) => {
|
|
2319
|
+
var _a, _b, _c, _d, _e;
|
|
2320
|
+
const dataRef = item.getDataRef();
|
|
2321
|
+
const props = (_a = prev == null ? void 0 : prev()) != null ? _a : {};
|
|
2322
|
+
(_c = (_b = dataRef.current).memo) != null ? _c : _b.memo = {};
|
|
2323
|
+
(_e = (_d = dataRef.current.memo).drag) != null ? _e : _d.drag = {};
|
|
2324
|
+
return memoize(props, dataRef.current.memo.drag);
|
|
2325
|
+
},
|
|
2299
2326
|
getRenameInputProps: ({ item, prev }) => {
|
|
2300
2327
|
var _a, _b, _c, _d, _e;
|
|
2301
2328
|
const dataRef = item.getDataRef();
|