@elliemae/ds-drag-and-drop 2.2.0-alpha.2 → 2.2.0-beta.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.
- package/cjs/hierarchy/customCollisionDetection.js +50 -44
- package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js +91 -78
- package/cjs/hierarchy/index.js +9 -28
- package/cjs/hierarchy/types.js +2 -27
- package/cjs/hierarchy/useHierarchyActionHandlers.js +35 -53
- package/cjs/hierarchy/useHierarchyAnnouncements.js +26 -45
- package/cjs/hierarchy/useHierarchyDndkitConfig.js +83 -77
- package/cjs/hierarchy/useHierarchyPreviewHandlers.js +27 -48
- package/cjs/index.js +11 -29
- package/cjs/tree/constants.js +12 -41
- package/cjs/tree/customCollisionDetection.js +95 -64
- package/cjs/tree/getTreeKeyboardCoordinates.js +101 -87
- package/cjs/tree/index.js +9 -28
- package/cjs/tree/types.js +2 -27
- package/cjs/tree/useTreeActionHandlers.js +56 -66
- package/cjs/tree/useTreeAnnouncements.js +40 -53
- package/cjs/tree/useTreeDndkitConfig.js +91 -95
- package/cjs/tree/useTreePreviewHandlers.js +37 -53
- package/cjs/tree/utilities.js +30 -44
- package/esm/hierarchy/customCollisionDetection.js +46 -15
- package/esm/hierarchy/getHierarchyKeyboardCoordinates.js +76 -42
- package/esm/hierarchy/index.js +1 -3
- package/esm/hierarchy/types.js +1 -2
- package/esm/hierarchy/useHierarchyActionHandlers.js +31 -24
- package/esm/hierarchy/useHierarchyAnnouncements.js +20 -14
- package/esm/hierarchy/useHierarchyDndkitConfig.js +66 -45
- package/esm/hierarchy/useHierarchyPreviewHandlers.js +19 -15
- package/esm/index.js +2 -4
- package/esm/tree/constants.js +10 -12
- package/esm/tree/customCollisionDetection.js +89 -33
- package/esm/tree/getTreeKeyboardCoordinates.js +84 -49
- package/esm/tree/index.js +1 -3
- package/esm/tree/types.js +1 -2
- package/esm/tree/useTreeActionHandlers.js +50 -35
- package/esm/tree/useTreeAnnouncements.js +30 -18
- package/esm/tree/useTreeDndkitConfig.js +70 -59
- package/esm/tree/useTreePreviewHandlers.js +28 -19
- package/esm/tree/utilities.js +23 -13
- package/package.json +1 -1
- package/cjs/hierarchy/customCollisionDetection.js.map +0 -7
- package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js.map +0 -7
- package/cjs/hierarchy/index.js.map +0 -7
- package/cjs/hierarchy/types.js.map +0 -7
- package/cjs/hierarchy/useHierarchyActionHandlers.js.map +0 -7
- package/cjs/hierarchy/useHierarchyAnnouncements.js.map +0 -7
- package/cjs/hierarchy/useHierarchyDndkitConfig.js.map +0 -7
- package/cjs/hierarchy/useHierarchyPreviewHandlers.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/cjs/tree/constants.js.map +0 -7
- package/cjs/tree/customCollisionDetection.js.map +0 -7
- package/cjs/tree/getTreeKeyboardCoordinates.js.map +0 -7
- package/cjs/tree/index.js.map +0 -7
- package/cjs/tree/types.js.map +0 -7
- package/cjs/tree/useTreeActionHandlers.js.map +0 -7
- package/cjs/tree/useTreeAnnouncements.js.map +0 -7
- package/cjs/tree/useTreeDndkitConfig.js.map +0 -7
- package/cjs/tree/useTreePreviewHandlers.js.map +0 -7
- package/cjs/tree/utilities.js.map +0 -7
- package/esm/hierarchy/customCollisionDetection.js.map +0 -7
- package/esm/hierarchy/getHierarchyKeyboardCoordinates.js.map +0 -7
- package/esm/hierarchy/index.js.map +0 -7
- package/esm/hierarchy/types.js.map +0 -7
- package/esm/hierarchy/useHierarchyActionHandlers.js.map +0 -7
- package/esm/hierarchy/useHierarchyAnnouncements.js.map +0 -7
- package/esm/hierarchy/useHierarchyDndkitConfig.js.map +0 -7
- package/esm/hierarchy/useHierarchyPreviewHandlers.js.map +0 -7
- package/esm/index.js.map +0 -7
- package/esm/tree/constants.js.map +0 -7
- package/esm/tree/customCollisionDetection.js.map +0 -7
- package/esm/tree/getTreeKeyboardCoordinates.js.map +0 -7
- package/esm/tree/index.js.map +0 -7
- package/esm/tree/types.js.map +0 -7
- package/esm/tree/useTreeActionHandlers.js.map +0 -7
- package/esm/tree/useTreeAnnouncements.js.map +0 -7
- package/esm/tree/useTreeDndkitConfig.js.map +0 -7
- package/esm/tree/useTreePreviewHandlers.js.map +0 -7
- package/esm/tree/utilities.js.map +0 -7
|
@@ -1,61 +1,97 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
|
+
import 'core-js/modules/esnext.async-iterator.find.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
4
|
+
import 'core-js/modules/esnext.iterator.find.js';
|
|
5
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
6
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
7
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
8
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
9
|
+
import { KeyboardCode, getViewRect, closestCorners } from '@dnd-kit/core';
|
|
10
|
+
|
|
11
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
+
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
14
|
const directions = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];
|
|
4
15
|
const vertical = [KeyboardCode.Up, KeyboardCode.Down];
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
const getHorizontalKeyboardCoordinates = _ref => {
|
|
18
|
+
var _droppableContainers$, _droppableContainers$2, _droppableContainers$3, _droppableContainers$4;
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
items,
|
|
22
|
+
active,
|
|
23
|
+
over,
|
|
24
|
+
event,
|
|
25
|
+
currentCoordinates,
|
|
26
|
+
droppableContainers,
|
|
27
|
+
collisionRect
|
|
28
|
+
} = _ref;
|
|
29
|
+
if (vertical.includes(event.code) || !active || !over) return undefined;
|
|
30
|
+
const activeItem = items.find(item => item.id === active.id);
|
|
17
31
|
const overRect = over.rect;
|
|
18
|
-
const layoutRects = [];
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
const layoutRects = []; // Get the reacheable rects depending on the arrow key pressed
|
|
33
|
+
|
|
34
|
+
droppableContainers.forEach(container => {
|
|
35
|
+
var _items$find;
|
|
36
|
+
|
|
37
|
+
if (container !== null && container !== void 0 && container.disabled || !overRect) {
|
|
21
38
|
return;
|
|
22
39
|
}
|
|
23
|
-
|
|
40
|
+
|
|
41
|
+
const node = container === null || container === void 0 ? void 0 : container.node.current;
|
|
42
|
+
|
|
24
43
|
if (!node) {
|
|
25
44
|
return;
|
|
26
45
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
46
|
+
|
|
47
|
+
const itemParent = (_items$find = items.find(item => item.id === container.id)) === null || _items$find === void 0 ? void 0 : _items$find.parentId;
|
|
48
|
+
if (itemParent !== (activeItem === null || activeItem === void 0 ? void 0 : activeItem.parentId)) return;
|
|
30
49
|
const rect = getViewRect(node);
|
|
50
|
+
|
|
31
51
|
if (event.code === KeyboardCode.Left && collisionRect.left > rect.right - 10) {
|
|
32
52
|
layoutRects.push(container);
|
|
33
53
|
} else if (event.code === KeyboardCode.Right && collisionRect.left < rect.left) {
|
|
34
54
|
layoutRects.push(container);
|
|
35
55
|
}
|
|
36
56
|
});
|
|
37
|
-
const closestId = closestCorners({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!
|
|
43
|
-
|
|
57
|
+
const closestId = closestCorners({
|
|
58
|
+
droppableContainers: layoutRects,
|
|
59
|
+
collisionRect,
|
|
60
|
+
active
|
|
61
|
+
});
|
|
62
|
+
if (!closestId) return undefined;
|
|
63
|
+
const closestDroppableContainer = (_droppableContainers$ = droppableContainers.get(closestId)) === null || _droppableContainers$ === void 0 ? void 0 : (_droppableContainers$2 = _droppableContainers$.node) === null || _droppableContainers$2 === void 0 ? void 0 : _droppableContainers$2.current;
|
|
64
|
+
const activeDroppableContainer = (_droppableContainers$3 = droppableContainers.get(active === null || active === void 0 ? void 0 : active.id)) === null || _droppableContainers$3 === void 0 ? void 0 : (_droppableContainers$4 = _droppableContainers$3.node) === null || _droppableContainers$4 === void 0 ? void 0 : _droppableContainers$4.current;
|
|
65
|
+
if (!closestDroppableContainer || !activeDroppableContainer) return undefined;
|
|
44
66
|
const closestRect = getViewRect(closestDroppableContainer);
|
|
45
67
|
const activeRect = getViewRect(activeDroppableContainer);
|
|
46
|
-
return {
|
|
47
|
-
...currentCoordinates,
|
|
68
|
+
return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
|
|
48
69
|
x: closestRect.left + (closestRect.width - collisionRect.width) / 2 + (closestRect.offsetLeft < activeRect.left ? -1 : 1)
|
|
49
|
-
};
|
|
70
|
+
});
|
|
50
71
|
};
|
|
51
|
-
|
|
72
|
+
|
|
73
|
+
const getHierarchyKeyboardCoordinates = (context, dragOverlayDataTestid, isHorizontalDnD) => (event, _ref2) => {
|
|
74
|
+
let {
|
|
75
|
+
currentCoordinates,
|
|
76
|
+
context: {
|
|
77
|
+
active,
|
|
78
|
+
over,
|
|
79
|
+
collisionRect,
|
|
80
|
+
droppableContainers
|
|
81
|
+
}
|
|
82
|
+
} = _ref2;
|
|
83
|
+
|
|
52
84
|
if (directions.includes(event.code)) {
|
|
53
85
|
event.preventDefault();
|
|
86
|
+
|
|
54
87
|
if (!collisionRect) {
|
|
55
|
-
return
|
|
88
|
+
return undefined;
|
|
56
89
|
}
|
|
90
|
+
|
|
57
91
|
const {
|
|
58
|
-
current: {
|
|
92
|
+
current: {
|
|
93
|
+
items
|
|
94
|
+
}
|
|
59
95
|
} = context;
|
|
60
96
|
const args = {
|
|
61
97
|
dragOverlayDataTestid,
|
|
@@ -67,13 +103,11 @@ const getHierarchyKeyboardCoordinates = (context, dragOverlayDataTestid, isHoriz
|
|
|
67
103
|
droppableContainers,
|
|
68
104
|
collisionRect
|
|
69
105
|
};
|
|
70
|
-
if (isHorizontalDnD)
|
|
71
|
-
|
|
72
|
-
return void 0;
|
|
106
|
+
if (isHorizontalDnD) return getHorizontalKeyboardCoordinates(args);
|
|
107
|
+
return undefined;
|
|
73
108
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
export {
|
|
77
|
-
getHierarchyKeyboardCoordinates
|
|
109
|
+
|
|
110
|
+
return undefined;
|
|
78
111
|
};
|
|
79
|
-
|
|
112
|
+
|
|
113
|
+
export { getHierarchyKeyboardCoordinates };
|
package/esm/hierarchy/index.js
CHANGED
package/esm/hierarchy/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
|
|
@@ -1,39 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const useHierarchyActionHandlers =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
const useHierarchyActionHandlers = _ref => {
|
|
4
|
+
let {
|
|
5
|
+
handlePreviewDragStart,
|
|
6
|
+
handlePreviewDragMove,
|
|
7
|
+
handlePreviewDragEnd,
|
|
8
|
+
handlePreviewDragCancel,
|
|
9
|
+
onReorder,
|
|
10
|
+
dndItems
|
|
11
|
+
} = _ref;
|
|
12
|
+
const onDragStart = useCallback(e => {
|
|
12
13
|
handlePreviewDragStart(e);
|
|
13
14
|
}, [handlePreviewDragStart]);
|
|
14
|
-
const onDragMove = useCallback(
|
|
15
|
+
const onDragMove = useCallback(e => {
|
|
15
16
|
handlePreviewDragMove(e);
|
|
16
17
|
}, [handlePreviewDragMove]);
|
|
17
|
-
const onDragEnd = useCallback(
|
|
18
|
+
const onDragEnd = useCallback(e => {
|
|
18
19
|
handlePreviewDragEnd(e);
|
|
19
|
-
const {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const {
|
|
21
|
+
active,
|
|
22
|
+
over
|
|
23
|
+
} = e;
|
|
24
|
+
if (!over) return;
|
|
25
|
+
|
|
22
26
|
if (active.id !== over.id) {
|
|
23
|
-
const activeIndex = dndItems.findIndex(
|
|
24
|
-
const overIndex = dndItems.findIndex(
|
|
27
|
+
const activeIndex = dndItems.findIndex(item => item.id === active.id);
|
|
28
|
+
const overIndex = dndItems.findIndex(item => item.id === over.id);
|
|
25
29
|
onReorder(dndItems[activeIndex], {
|
|
26
30
|
targetIndex: overIndex,
|
|
27
31
|
fromIndex: activeIndex
|
|
28
32
|
});
|
|
29
33
|
}
|
|
30
34
|
}, [handlePreviewDragEnd, dndItems, onReorder]);
|
|
31
|
-
const onDragCancel = useCallback(
|
|
35
|
+
const onDragCancel = useCallback(e => {
|
|
32
36
|
handlePreviewDragCancel(e);
|
|
33
37
|
}, [handlePreviewDragCancel]);
|
|
34
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
onDragStart,
|
|
40
|
+
onDragMove,
|
|
41
|
+
onDragEnd,
|
|
42
|
+
onDragCancel
|
|
43
|
+
};
|
|
35
44
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=useHierarchyActionHandlers.js.map
|
|
45
|
+
|
|
46
|
+
export { useHierarchyActionHandlers };
|
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const useHierarchyAnnouncements =
|
|
4
|
-
const onDragStart = useCallback(
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
const useHierarchyAnnouncements = visibleItemsDictionary => {
|
|
4
|
+
const onDragStart = useCallback(id => "Picked up draggable item from position ".concat(visibleItemsDictionary[id].index + 1, "."), [visibleItemsDictionary]);
|
|
5
5
|
const onDragMove = useCallback((id, overId) => {
|
|
6
6
|
if (overId) {
|
|
7
7
|
const overIndex = visibleItemsDictionary[overId].index + 1;
|
|
8
|
-
return
|
|
8
|
+
return "Draggable item was moved to position ".concat(overIndex, ".");
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
return "Draggable item is no longer over a droppable area.";
|
|
11
12
|
}, [visibleItemsDictionary]);
|
|
12
13
|
const onDragOver = onDragMove;
|
|
13
14
|
const onDragEnd = useCallback((id, overId) => {
|
|
14
15
|
if (overId) {
|
|
15
16
|
const overIndex = visibleItemsDictionary[overId].index + 1;
|
|
16
|
-
return
|
|
17
|
+
return "Draggable item was dropped over position ".concat(overIndex, ".");
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
|
|
20
|
+
return "Draggable item was dropped at it's original position.";
|
|
19
21
|
}, [visibleItemsDictionary]);
|
|
20
|
-
const onDragCancel = useCallback(
|
|
21
|
-
return {
|
|
22
|
+
const onDragCancel = useCallback(id => "Dragging was cancelled. Draggable item from position ".concat(visibleItemsDictionary[id].index + 1, " was dropped at it's initial position."), [visibleItemsDictionary]);
|
|
23
|
+
return {
|
|
24
|
+
onDragStart,
|
|
25
|
+
onDragOver,
|
|
26
|
+
onDragMove,
|
|
27
|
+
onDragEnd,
|
|
28
|
+
onDragCancel
|
|
29
|
+
};
|
|
22
30
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=useHierarchyAnnouncements.js.map
|
|
31
|
+
|
|
32
|
+
export { useHierarchyAnnouncements };
|
|
@@ -1,47 +1,68 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
4
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
6
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
7
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
8
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
9
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
10
|
+
import { useState, useMemo, useRef, useEffect } from 'react';
|
|
11
|
+
import { MeasuringStrategy, useSensors, useSensor, PointerSensor, KeyboardSensor } from '@dnd-kit/core';
|
|
12
|
+
import { useHierarchyActionHandlers } from './useHierarchyActionHandlers.js';
|
|
13
|
+
import { useHierarchyPreviewHandlers } from './useHierarchyPreviewHandlers.js';
|
|
14
|
+
import { getHierarchyKeyboardCoordinates } from './getHierarchyKeyboardCoordinates.js';
|
|
15
|
+
import { customCollisionDetection } from './customCollisionDetection.js';
|
|
16
|
+
import { useHierarchyAnnouncements } from './useHierarchyAnnouncements.js';
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
// if second parameter is true, the space will be done on the horizontal axis
|
|
22
|
+
|
|
23
|
+
const adjustTranslate = isHorizontalDnD => _ref => {
|
|
24
|
+
let {
|
|
25
|
+
transform
|
|
26
|
+
} = _ref;
|
|
27
|
+
|
|
28
|
+
const newTransform = _objectSpread({}, transform);
|
|
29
|
+
|
|
19
30
|
if (isHorizontalDnD) {
|
|
20
31
|
newTransform.y = transform.y + 15;
|
|
21
32
|
} else {
|
|
22
33
|
newTransform.y = transform.y - 35;
|
|
23
34
|
}
|
|
35
|
+
|
|
24
36
|
return newTransform;
|
|
25
37
|
};
|
|
38
|
+
|
|
26
39
|
const measuring = {
|
|
27
40
|
droppable: {
|
|
28
41
|
strategy: MeasuringStrategy.Always
|
|
29
42
|
}
|
|
30
43
|
};
|
|
44
|
+
|
|
31
45
|
const noop = () => null;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
|
|
47
|
+
const useHierarchyDndkitConfig = _ref2 => {
|
|
48
|
+
var _itemsDictionary$acti;
|
|
49
|
+
|
|
50
|
+
let {
|
|
51
|
+
flattenedItems,
|
|
52
|
+
dragOverlayDataTestid,
|
|
53
|
+
isHorizontalDnD = false,
|
|
54
|
+
onReorder,
|
|
55
|
+
onPreviewResetState = noop,
|
|
56
|
+
onPreviewDragStart = noop
|
|
57
|
+
} = _ref2;
|
|
58
|
+
const [activeId, setActiveId] = useState('');
|
|
59
|
+
const dndItems = useMemo(() => flattenedItems.map(_ref3 => {
|
|
60
|
+
let [item] = _ref3;
|
|
61
|
+
return item;
|
|
62
|
+
}), [flattenedItems]);
|
|
42
63
|
const itemsDictionary = useMemo(() => {
|
|
43
64
|
const dictionary = {};
|
|
44
|
-
dndItems.forEach(
|
|
65
|
+
dndItems.forEach(item => {
|
|
45
66
|
dictionary[item.id] = item;
|
|
46
67
|
});
|
|
47
68
|
return dictionary;
|
|
@@ -64,27 +85,27 @@ const useHierarchyDndkitConfig = ({
|
|
|
64
85
|
onPreviewResetState,
|
|
65
86
|
onPreviewDragStart
|
|
66
87
|
});
|
|
67
|
-
const dragActionHandlers = useHierarchyActionHandlers({
|
|
68
|
-
...dragPreviewHandlers,
|
|
88
|
+
const dragActionHandlers = useHierarchyActionHandlers(_objectSpread(_objectSpread({}, dragPreviewHandlers), {}, {
|
|
69
89
|
dndItems,
|
|
70
90
|
onReorder
|
|
71
|
-
});
|
|
91
|
+
}));
|
|
72
92
|
const announcements = useHierarchyAnnouncements(itemsDictionary);
|
|
73
|
-
const dndContextProps = useMemo(() =>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
93
|
+
const dndContextProps = useMemo(() => {
|
|
94
|
+
var _itemsDictionary;
|
|
95
|
+
|
|
96
|
+
return _objectSpread({
|
|
97
|
+
announcements,
|
|
98
|
+
modifiers,
|
|
99
|
+
sensors,
|
|
100
|
+
measuring,
|
|
101
|
+
collisionDetection: customCollisionDetection(activeId, (_itemsDictionary = itemsDictionary[activeId !== null && activeId !== void 0 ? activeId : '']) === null || _itemsDictionary === void 0 ? void 0 : _itemsDictionary.parentId, dndItems)
|
|
102
|
+
}, dragActionHandlers);
|
|
103
|
+
}, [announcements, modifiers, sensors, activeId, itemsDictionary, dndItems, dragActionHandlers]);
|
|
81
104
|
return {
|
|
82
105
|
dndContextProps,
|
|
83
106
|
activeId,
|
|
84
|
-
activeIndex: activeId ? itemsDictionary[activeId]
|
|
107
|
+
activeIndex: activeId ? (_itemsDictionary$acti = itemsDictionary[activeId]) === null || _itemsDictionary$acti === void 0 ? void 0 : _itemsDictionary$acti.index : -1
|
|
85
108
|
};
|
|
86
109
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
//# sourceMappingURL=useHierarchyDndkitConfig.js.map
|
|
110
|
+
|
|
111
|
+
export { useHierarchyDndkitConfig };
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const useHierarchyPreviewHandlers =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
const useHierarchyPreviewHandlers = _ref => {
|
|
4
|
+
let {
|
|
5
|
+
setActiveId,
|
|
6
|
+
onPreviewResetState,
|
|
7
|
+
onPreviewDragStart
|
|
8
|
+
} = _ref;
|
|
8
9
|
const resetState = useCallback(() => {
|
|
9
|
-
setActiveId(
|
|
10
|
+
setActiveId('');
|
|
10
11
|
onPreviewResetState();
|
|
11
|
-
document.body.style.setProperty(
|
|
12
|
+
document.body.style.setProperty('cursor', '');
|
|
12
13
|
}, [setActiveId, onPreviewResetState]);
|
|
13
|
-
const handlePreviewDragStart = useCallback(
|
|
14
|
+
const handlePreviewDragStart = useCallback(_ref2 => {
|
|
15
|
+
let {
|
|
16
|
+
active: {
|
|
17
|
+
id
|
|
18
|
+
}
|
|
19
|
+
} = _ref2;
|
|
14
20
|
setActiveId(id);
|
|
15
|
-
document.body.style.setProperty(
|
|
21
|
+
document.body.style.setProperty('cursor', 'grabbing');
|
|
16
22
|
onPreviewDragStart();
|
|
17
23
|
}, [setActiveId, onPreviewDragStart]);
|
|
18
24
|
const handlePreviewDragMove = useCallback(() => null, []);
|
|
@@ -29,7 +35,5 @@ const useHierarchyPreviewHandlers = ({
|
|
|
29
35
|
handlePreviewDragCancel
|
|
30
36
|
};
|
|
31
37
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=useHierarchyPreviewHandlers.js.map
|
|
38
|
+
|
|
39
|
+
export { useHierarchyPreviewHandlers };
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export * from "./tree";
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { useHierarchyDndkitConfig } from './hierarchy/useHierarchyDndkitConfig.js';
|
|
2
|
+
export { useTreeDndkitConfig } from './tree/useTreeDndkitConfig.js';
|
package/esm/tree/constants.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})(DropIndicatorPosition || {});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=constants.js.map
|
|
1
|
+
let DropIndicatorPosition;
|
|
2
|
+
|
|
3
|
+
(function (DropIndicatorPosition) {
|
|
4
|
+
DropIndicatorPosition[DropIndicatorPosition["None"] = 0] = "None";
|
|
5
|
+
DropIndicatorPosition[DropIndicatorPosition["Before"] = 1] = "Before";
|
|
6
|
+
DropIndicatorPosition[DropIndicatorPosition["After"] = 2] = "After";
|
|
7
|
+
DropIndicatorPosition[DropIndicatorPosition["Inside"] = 3] = "Inside";
|
|
8
|
+
})(DropIndicatorPosition || (DropIndicatorPosition = {}));
|
|
9
|
+
|
|
10
|
+
export { DropIndicatorPosition };
|