@elliemae/ds-drag-and-drop 2.2.0 → 2.3.0-alpha.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/cjs/hierarchy/customCollisionDetection.js +44 -50
- package/cjs/hierarchy/customCollisionDetection.js.map +7 -0
- package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js +78 -91
- package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js.map +7 -0
- package/cjs/hierarchy/index.js +28 -9
- package/cjs/hierarchy/index.js.map +7 -0
- package/cjs/hierarchy/types.js +27 -2
- package/cjs/hierarchy/types.js.map +7 -0
- package/cjs/hierarchy/useHierarchyActionHandlers.js +53 -35
- package/cjs/hierarchy/useHierarchyActionHandlers.js.map +7 -0
- package/cjs/hierarchy/useHierarchyAnnouncements.js +45 -26
- package/cjs/hierarchy/useHierarchyAnnouncements.js.map +7 -0
- package/cjs/hierarchy/useHierarchyDndkitConfig.js +77 -83
- package/cjs/hierarchy/useHierarchyDndkitConfig.js.map +7 -0
- package/cjs/hierarchy/useHierarchyPreviewHandlers.js +48 -27
- package/cjs/hierarchy/useHierarchyPreviewHandlers.js.map +7 -0
- package/cjs/index.js +29 -11
- package/cjs/index.js.map +7 -0
- package/cjs/tree/constants.js +41 -12
- package/cjs/tree/constants.js.map +7 -0
- package/cjs/tree/customCollisionDetection.js +96 -124
- package/cjs/tree/customCollisionDetection.js.map +7 -0
- package/cjs/tree/getTreeKeyboardCoordinates.js +86 -101
- package/cjs/tree/getTreeKeyboardCoordinates.js.map +7 -0
- package/cjs/tree/index.js +28 -9
- package/cjs/tree/index.js.map +7 -0
- package/cjs/tree/types.js +27 -2
- package/cjs/tree/types.js.map +7 -0
- package/cjs/tree/useTreeActionHandlers.js +68 -57
- package/cjs/tree/useTreeActionHandlers.js.map +7 -0
- package/cjs/tree/useTreeAnnouncements.js +53 -40
- package/cjs/tree/useTreeAnnouncements.js.map +7 -0
- package/cjs/tree/useTreeDndkitConfig.js +112 -98
- package/cjs/tree/useTreeDndkitConfig.js.map +7 -0
- package/cjs/tree/useTreePreviewHandlers.js +53 -37
- package/cjs/tree/useTreePreviewHandlers.js.map +7 -0
- package/cjs/tree/utilities.js +44 -30
- package/cjs/tree/utilities.js.map +7 -0
- package/esm/hierarchy/customCollisionDetection.js +15 -46
- package/esm/hierarchy/customCollisionDetection.js.map +7 -0
- package/esm/hierarchy/getHierarchyKeyboardCoordinates.js +42 -76
- package/esm/hierarchy/getHierarchyKeyboardCoordinates.js.map +7 -0
- package/esm/hierarchy/index.js +3 -1
- package/esm/hierarchy/index.js.map +7 -0
- package/esm/hierarchy/types.js +2 -1
- package/esm/hierarchy/types.js.map +7 -0
- package/esm/hierarchy/useHierarchyActionHandlers.js +24 -31
- package/esm/hierarchy/useHierarchyActionHandlers.js.map +7 -0
- package/esm/hierarchy/useHierarchyAnnouncements.js +14 -20
- package/esm/hierarchy/useHierarchyAnnouncements.js.map +7 -0
- package/esm/hierarchy/useHierarchyDndkitConfig.js +45 -66
- package/esm/hierarchy/useHierarchyDndkitConfig.js.map +7 -0
- package/esm/hierarchy/useHierarchyPreviewHandlers.js +15 -19
- package/esm/hierarchy/useHierarchyPreviewHandlers.js.map +7 -0
- package/esm/index.js +4 -2
- package/esm/index.js.map +7 -0
- package/esm/tree/constants.js +12 -10
- package/esm/tree/constants.js.map +7 -0
- package/esm/tree/customCollisionDetection.js +67 -120
- package/esm/tree/customCollisionDetection.js.map +7 -0
- package/esm/tree/getTreeKeyboardCoordinates.js +48 -84
- package/esm/tree/getTreeKeyboardCoordinates.js.map +7 -0
- package/esm/tree/index.js +3 -1
- package/esm/tree/index.js.map +7 -0
- package/esm/tree/types.js +2 -1
- package/esm/tree/types.js.map +7 -0
- package/esm/tree/useTreeActionHandlers.js +37 -51
- package/esm/tree/useTreeActionHandlers.js.map +7 -0
- package/esm/tree/useTreeAnnouncements.js +18 -30
- package/esm/tree/useTreeAnnouncements.js.map +7 -0
- package/esm/tree/useTreeDndkitConfig.js +79 -80
- package/esm/tree/useTreeDndkitConfig.js.map +7 -0
- package/esm/tree/useTreePreviewHandlers.js +19 -28
- package/esm/tree/useTreePreviewHandlers.js.map +7 -0
- package/esm/tree/utilities.js +13 -23
- package/esm/tree/utilities.js.map +7 -0
- package/package.json +1 -1
- package/types/hierarchy/types.d.ts +1 -1
- package/types/tree/types.d.ts +17 -13
- package/types/tree/useTreeActionHandlers.d.ts +2 -2
- package/types/tree/useTreeDndkitConfig.d.ts +2 -2
- package/types/tree/useTreePreviewHandlers.d.ts +2 -2
|
@@ -1,46 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
5
|
-
import 'core-js/modules/esnext.async-iterator.find.js';
|
|
6
|
-
import 'core-js/modules/esnext.iterator.find.js';
|
|
7
|
-
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
8
|
-
import 'core-js/modules/esnext.iterator.filter.js';
|
|
9
|
-
import { KeyboardCode, closestCorners, getViewRect } from '@dnd-kit/core';
|
|
10
|
-
import { DropIndicatorPosition } from './constants.js';
|
|
11
|
-
|
|
12
|
-
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; }
|
|
13
|
-
|
|
14
|
-
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; }
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { closestCorners, getViewRect, KeyboardCode } from "@dnd-kit/core";
|
|
3
|
+
import { DropIndicatorPosition } from "./constants";
|
|
15
4
|
const directions = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];
|
|
16
5
|
const horizontal = [KeyboardCode.Left, KeyboardCode.Right];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
dropIndicatorPosition,
|
|
31
|
-
maxDragAndDropLevel
|
|
32
|
-
} = _ref;
|
|
33
|
-
if (horizontal.includes(event.code)) return undefined;
|
|
6
|
+
const getVerticalKeyboardCoordinates = ({
|
|
7
|
+
items,
|
|
8
|
+
active,
|
|
9
|
+
over,
|
|
10
|
+
event,
|
|
11
|
+
currentCoordinates,
|
|
12
|
+
droppableContainers,
|
|
13
|
+
collisionRect,
|
|
14
|
+
dropIndicatorPosition,
|
|
15
|
+
maxDragAndDropLevel
|
|
16
|
+
}) => {
|
|
17
|
+
if (horizontal.includes(event.code))
|
|
18
|
+
return void 0;
|
|
34
19
|
const overRect = over.rect;
|
|
35
|
-
const layoutRects = [];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (container !== null && container !== void 0 && container.disabled || !overRect) {
|
|
20
|
+
const layoutRects = [];
|
|
21
|
+
droppableContainers.forEach((container) => {
|
|
22
|
+
if (container?.disabled || !overRect) {
|
|
39
23
|
return;
|
|
40
24
|
}
|
|
41
|
-
|
|
42
25
|
const rect = container.rect.current;
|
|
43
|
-
|
|
44
26
|
if (rect && event.code === KeyboardCode.Down && collisionRect.top - 2 <= rect.offsetTop) {
|
|
45
27
|
layoutRects.push(container);
|
|
46
28
|
} else if (rect && event.code === KeyboardCode.Up && collisionRect.top >= rect.offsetTop) {
|
|
@@ -52,64 +34,44 @@ const getVerticalKeyboardCoordinates = _ref => {
|
|
|
52
34
|
droppableContainers: layoutRects,
|
|
53
35
|
active
|
|
54
36
|
});
|
|
55
|
-
const closestItem = items.find(item => item.uid === closestId);
|
|
56
|
-
const closestElement =
|
|
57
|
-
if (!closestId || !closestItem || !closestElement)
|
|
37
|
+
const closestItem = items.find((item) => item.uid === closestId);
|
|
38
|
+
const closestElement = droppableContainers.get(closestId)?.node?.current;
|
|
39
|
+
if (!closestId || !closestItem || !closestElement)
|
|
40
|
+
return void 0;
|
|
58
41
|
const closestRect = getViewRect(closestElement);
|
|
59
|
-
|
|
60
42
|
if (event.code === KeyboardCode.Up) {
|
|
61
|
-
// If the drop indicator is inside (or over ourselves)
|
|
62
|
-
// We are gonna go to the before position
|
|
63
|
-
// Else we are gonna go inside the over rect
|
|
64
43
|
if (dropIndicatorPosition === DropIndicatorPosition.Inside || closestId === active.id || closestItem.depth + 1 > maxDragAndDropLevel) {
|
|
65
|
-
return
|
|
44
|
+
return {
|
|
45
|
+
...currentCoordinates,
|
|
66
46
|
y: closestRect.top - collisionRect.height / 2
|
|
67
|
-
}
|
|
47
|
+
};
|
|
68
48
|
}
|
|
69
|
-
|
|
70
|
-
|
|
49
|
+
return {
|
|
50
|
+
...currentCoordinates,
|
|
71
51
|
y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// We are gonna go to the after position
|
|
75
|
-
// Else we are gonna go inside the over rect
|
|
76
|
-
|
|
77
|
-
|
|
52
|
+
};
|
|
53
|
+
}
|
|
78
54
|
if (dropIndicatorPosition === DropIndicatorPosition.Inside || closestId === active.id || closestItem.depth + 1 > maxDragAndDropLevel) {
|
|
79
|
-
return
|
|
55
|
+
return {
|
|
56
|
+
...currentCoordinates,
|
|
80
57
|
y: closestRect.top + collisionRect.height / 2
|
|
81
|
-
}
|
|
58
|
+
};
|
|
82
59
|
}
|
|
83
|
-
|
|
84
|
-
|
|
60
|
+
return {
|
|
61
|
+
...currentCoordinates,
|
|
85
62
|
y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2
|
|
86
|
-
}
|
|
63
|
+
};
|
|
87
64
|
};
|
|
88
|
-
|
|
89
|
-
const getTreeKeyboardCoordinates = (context, isHorizontalDnD, maxDragAndDropLevel) => (event, _ref2) => {
|
|
90
|
-
let {
|
|
91
|
-
currentCoordinates,
|
|
92
|
-
context: {
|
|
93
|
-
over,
|
|
94
|
-
translatedRect,
|
|
95
|
-
droppableContainers,
|
|
96
|
-
active,
|
|
97
|
-
collisionRect
|
|
98
|
-
}
|
|
99
|
-
} = _ref2;
|
|
100
|
-
|
|
65
|
+
const getTreeKeyboardCoordinates = (context, isHorizontalDnD, maxDragAndDropLevel) => (event, { currentCoordinates, context: { over, translatedRect, droppableContainers, active, collisionRect } }) => {
|
|
101
66
|
if (directions.includes(event.code)) {
|
|
102
67
|
if (!translatedRect) {
|
|
103
|
-
return
|
|
68
|
+
return void 0;
|
|
104
69
|
}
|
|
105
|
-
|
|
106
70
|
const {
|
|
107
|
-
current: {
|
|
108
|
-
items,
|
|
109
|
-
dropIndicatorPosition
|
|
110
|
-
}
|
|
71
|
+
current: { items, dropIndicatorPosition }
|
|
111
72
|
} = context;
|
|
112
|
-
if (!over || !active || !collisionRect)
|
|
73
|
+
if (!over || !active || !collisionRect)
|
|
74
|
+
return void 0;
|
|
113
75
|
const args = {
|
|
114
76
|
items,
|
|
115
77
|
active,
|
|
@@ -121,11 +83,13 @@ const getTreeKeyboardCoordinates = (context, isHorizontalDnD, maxDragAndDropLeve
|
|
|
121
83
|
dropIndicatorPosition,
|
|
122
84
|
maxDragAndDropLevel
|
|
123
85
|
};
|
|
124
|
-
if (isHorizontalDnD)
|
|
86
|
+
if (isHorizontalDnD)
|
|
87
|
+
return void 0;
|
|
125
88
|
return getVerticalKeyboardCoordinates(args);
|
|
126
89
|
}
|
|
127
|
-
|
|
128
|
-
|
|
90
|
+
return void 0;
|
|
91
|
+
};
|
|
92
|
+
export {
|
|
93
|
+
getTreeKeyboardCoordinates
|
|
129
94
|
};
|
|
130
|
-
|
|
131
|
-
export { getTreeKeyboardCoordinates };
|
|
95
|
+
//# sourceMappingURL=getTreeKeyboardCoordinates.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tree/getTreeKeyboardCoordinates.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nimport { closestCorners, getViewRect, KeyboardCode, KeyboardCoordinateGetter, DroppableContainer } from '@dnd-kit/core';\nimport { Coordinates } from '@dnd-kit/core/dist/types';\nimport type { GetKeyboardCoordinatesArgs, SensorContext } from './types';\nimport { DropIndicatorPosition } from './constants';\n\nconst directions: string[] = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];\n\nconst horizontal: string[] = [KeyboardCode.Left, KeyboardCode.Right];\n\nconst getVerticalKeyboardCoordinates = ({\n items,\n active,\n over,\n event,\n currentCoordinates,\n droppableContainers,\n collisionRect,\n dropIndicatorPosition,\n maxDragAndDropLevel,\n}: GetKeyboardCoordinatesArgs): Coordinates | undefined => {\n if (horizontal.includes(event.code)) return undefined;\n\n const overRect = over.rect;\n\n const layoutRects: DroppableContainer[] = [];\n\n // Get the reacheable rects depending on the arrow key pressed\n droppableContainers.forEach((container) => {\n if (container?.disabled || !overRect) {\n return;\n }\n const rect = container.rect.current;\n if (rect && event.code === KeyboardCode.Down && collisionRect.top - 2 <= rect.offsetTop) {\n layoutRects.push(container);\n } else if (rect && event.code === KeyboardCode.Up && collisionRect.top >= rect.offsetTop) {\n layoutRects.push(container);\n }\n });\n\n const closestId = closestCorners({\n collisionRect,\n droppableContainers: layoutRects,\n active,\n });\n\n const closestItem = items.find((item) => item.uid === closestId);\n\n const closestElement = droppableContainers.get(closestId)?.node?.current;\n\n if (!closestId || !closestItem || !closestElement) return undefined;\n\n const closestRect = getViewRect(closestElement);\n\n if (event.code === KeyboardCode.Up) {\n // If the drop indicator is inside (or over ourselves)\n // We are gonna go to the before position\n // Else we are gonna go inside the over rect\n if (\n dropIndicatorPosition === DropIndicatorPosition.Inside ||\n closestId === active.id ||\n closestItem.depth + 1 > maxDragAndDropLevel\n ) {\n return {\n ...currentCoordinates,\n y: closestRect.top - collisionRect.height / 2,\n };\n }\n return {\n ...currentCoordinates,\n y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2,\n };\n }\n // If the drop indicator is inside (or over ourselves)\n // We are gonna go to the after position\n // Else we are gonna go inside the over rect\n if (\n dropIndicatorPosition === DropIndicatorPosition.Inside ||\n closestId === active.id ||\n closestItem.depth + 1 > maxDragAndDropLevel\n ) {\n return {\n ...currentCoordinates,\n y: closestRect.top + collisionRect.height / 2,\n };\n }\n return {\n ...currentCoordinates,\n y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2,\n };\n};\n\nexport const getTreeKeyboardCoordinates: (\n context: SensorContext,\n isHorizontalDnD: boolean,\n maxDragAndDropLevel: number,\n) => KeyboardCoordinateGetter =\n (context, isHorizontalDnD, maxDragAndDropLevel) =>\n (event, { currentCoordinates, context: { over, translatedRect, droppableContainers, active, collisionRect } }) => {\n if (directions.includes(event.code)) {\n if (!translatedRect) {\n return undefined;\n }\n\n const {\n current: { items, dropIndicatorPosition },\n } = context;\n\n if (!over || !active || !collisionRect) return undefined;\n\n const args = {\n items,\n active,\n over,\n event,\n currentCoordinates,\n droppableContainers,\n collisionRect,\n dropIndicatorPosition,\n maxDragAndDropLevel,\n };\n\n if (isHorizontalDnD) return undefined;\n return getVerticalKeyboardCoordinates(args);\n }\n return undefined;\n };\n"],
|
|
5
|
+
"mappings": "AAAA;ACCA;AAGA;AAEA,MAAM,aAAuB,CAAC,aAAa,MAAM,aAAa,OAAO,aAAa,IAAI,aAAa;AAEnG,MAAM,aAAuB,CAAC,aAAa,MAAM,aAAa;AAE9D,MAAM,iCAAiC,CAAC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACyD;AACzD,MAAI,WAAW,SAAS,MAAM;AAAO,WAAO;AAE5C,QAAM,WAAW,KAAK;AAEtB,QAAM,cAAoC;AAG1C,sBAAoB,QAAQ,CAAC,cAAc;AACzC,QAAI,WAAW,YAAY,CAAC,UAAU;AACpC;AAAA;AAEF,UAAM,OAAO,UAAU,KAAK;AAC5B,QAAI,QAAQ,MAAM,SAAS,aAAa,QAAQ,cAAc,MAAM,KAAK,KAAK,WAAW;AACvF,kBAAY,KAAK;AAAA,eACR,QAAQ,MAAM,SAAS,aAAa,MAAM,cAAc,OAAO,KAAK,WAAW;AACxF,kBAAY,KAAK;AAAA;AAAA;AAIrB,QAAM,YAAY,eAAe;AAAA,IAC/B;AAAA,IACA,qBAAqB;AAAA,IACrB;AAAA;AAGF,QAAM,cAAc,MAAM,KAAK,CAAC,SAAS,KAAK,QAAQ;AAEtD,QAAM,iBAAiB,oBAAoB,IAAI,YAAY,MAAM;AAEjE,MAAI,CAAC,aAAa,CAAC,eAAe,CAAC;AAAgB,WAAO;AAE1D,QAAM,cAAc,YAAY;AAEhC,MAAI,MAAM,SAAS,aAAa,IAAI;AAIlC,QACE,0BAA0B,sBAAsB,UAChD,cAAc,OAAO,MACrB,YAAY,QAAQ,IAAI,qBACxB;AACA,aAAO;AAAA,WACF;AAAA,QACH,GAAG,YAAY,MAAM,cAAc,SAAS;AAAA;AAAA;AAGhD,WAAO;AAAA,SACF;AAAA,MACH,GAAG,YAAY,MAAM,KAAK,IAAI,YAAY,SAAS,cAAc,UAAU;AAAA;AAAA;AAM/E,MACE,0BAA0B,sBAAsB,UAChD,cAAc,OAAO,MACrB,YAAY,QAAQ,IAAI,qBACxB;AACA,WAAO;AAAA,SACF;AAAA,MACH,GAAG,YAAY,MAAM,cAAc,SAAS;AAAA;AAAA;AAGhD,SAAO;AAAA,OACF;AAAA,IACH,GAAG,YAAY,MAAM,KAAK,IAAI,YAAY,SAAS,cAAc,UAAU;AAAA;AAAA;AAIxE,MAAM,6BAKX,CAAC,SAAS,iBAAiB,wBAC3B,CAAC,OAAO,EAAE,oBAAoB,SAAS,EAAE,MAAM,gBAAgB,qBAAqB,QAAQ,sBAAsB;AAChH,MAAI,WAAW,SAAS,MAAM,OAAO;AACnC,QAAI,CAAC,gBAAgB;AACnB,aAAO;AAAA;AAGT,UAAM;AAAA,MACJ,SAAS,EAAE,OAAO;AAAA,QAChB;AAEJ,QAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;AAAe,aAAO;AAE/C,UAAM,OAAO;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAGF,QAAI;AAAiB,aAAO;AAC5B,WAAO,+BAA+B;AAAA;AAExC,SAAO;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esm/tree/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tree/index.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './useTreeDndkitConfig';\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esm/tree/types.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -1,71 +1,57 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const useTreeActionHandlers =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const onDragStart = useCallback(e => {
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { arrayMove } from "@dnd-kit/sortable";
|
|
3
|
+
import { cloneDeep } from "lodash";
|
|
4
|
+
import { useCallback } from "react";
|
|
5
|
+
import { DropIndicatorPosition } from "./constants";
|
|
6
|
+
const useTreeActionHandlers = ({
|
|
7
|
+
handlePreviewDragStart,
|
|
8
|
+
handlePreviewDragMove,
|
|
9
|
+
handlePreviewDragOver,
|
|
10
|
+
handlePreviewDragEnd,
|
|
11
|
+
handlePreviewDragCancel,
|
|
12
|
+
onReorder,
|
|
13
|
+
flattenedItems,
|
|
14
|
+
projected,
|
|
15
|
+
dropIndicatorPosition,
|
|
16
|
+
isDropValid
|
|
17
|
+
}) => {
|
|
18
|
+
const onDragStart = useCallback((e) => {
|
|
19
19
|
handlePreviewDragStart(e);
|
|
20
20
|
}, [handlePreviewDragStart]);
|
|
21
|
-
const onDragMove = useCallback(e => {
|
|
21
|
+
const onDragMove = useCallback((e) => {
|
|
22
22
|
handlePreviewDragMove(e);
|
|
23
23
|
}, [handlePreviewDragMove]);
|
|
24
|
-
const onDragOver = useCallback(e => {
|
|
24
|
+
const onDragOver = useCallback((e) => {
|
|
25
25
|
handlePreviewDragOver(e);
|
|
26
26
|
}, [handlePreviewDragOver]);
|
|
27
|
-
const onDragEnd = useCallback(e => {
|
|
27
|
+
const onDragEnd = useCallback((e) => {
|
|
28
28
|
handlePreviewDragEnd(e);
|
|
29
|
-
const {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (over === null) return;
|
|
34
|
-
const activeIndex = flattenedItems.findIndex(item => item.uid === active.id);
|
|
29
|
+
const { active, over } = e;
|
|
30
|
+
if (over === null || !isDropValid)
|
|
31
|
+
return;
|
|
32
|
+
const activeIndex = flattenedItems.findIndex((item) => item.uid === active.id);
|
|
35
33
|
let considerExpanding = null;
|
|
36
|
-
let overIndex = flattenedItems.findIndex(item => item.uid === over.id);
|
|
37
|
-
// It will be reconstructed well later
|
|
38
|
-
|
|
34
|
+
let overIndex = flattenedItems.findIndex((item) => item.uid === over.id);
|
|
39
35
|
if (dropIndicatorPosition === DropIndicatorPosition.Inside) {
|
|
40
|
-
var _flattenedItems$overI, _flattenedItems$overI2;
|
|
41
|
-
|
|
42
36
|
considerExpanding = over.id;
|
|
43
|
-
overIndex = flattenedItems[overIndex].realIndex +
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
overIndex = flattenedItems[overIndex].realIndex + flattenedItems[overIndex].childrenCount + 1;
|
|
38
|
+
}
|
|
47
39
|
if (projected && (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth)) {
|
|
48
|
-
// Change parent and depth from projected data
|
|
49
40
|
flattenedItems[activeIndex].parentId = projected.parentId;
|
|
50
|
-
flattenedItems[activeIndex].depth = projected.depth;
|
|
51
|
-
|
|
41
|
+
flattenedItems[activeIndex].depth = projected.depth;
|
|
52
42
|
const newFlattenedData = activeIndex !== overIndex ? arrayMove(flattenedItems, activeIndex, overIndex) : cloneDeep(flattenedItems);
|
|
53
43
|
onReorder(newFlattenedData, {
|
|
54
44
|
targetIndex: overIndex,
|
|
55
45
|
fromIndex: activeIndex
|
|
56
|
-
}, considerExpanding ||
|
|
46
|
+
}, considerExpanding || "");
|
|
57
47
|
}
|
|
58
|
-
}, [handlePreviewDragEnd, flattenedItems, projected, onReorder
|
|
59
|
-
const onDragCancel = useCallback(e => {
|
|
48
|
+
}, [handlePreviewDragEnd, isDropValid, flattenedItems, dropIndicatorPosition, projected, onReorder]);
|
|
49
|
+
const onDragCancel = useCallback((e) => {
|
|
60
50
|
handlePreviewDragCancel(e);
|
|
61
51
|
}, [handlePreviewDragCancel]);
|
|
62
|
-
return {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
onDragEnd,
|
|
67
|
-
onDragCancel
|
|
68
|
-
};
|
|
52
|
+
return { onDragStart, onDragMove, onDragOver, onDragEnd, onDragCancel };
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
useTreeActionHandlers
|
|
69
56
|
};
|
|
70
|
-
|
|
71
|
-
export { useTreeActionHandlers };
|
|
57
|
+
//# sourceMappingURL=useTreeActionHandlers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tree/useTreeActionHandlers.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { arrayMove } from '@dnd-kit/sortable';\nimport { cloneDeep } from 'lodash';\nimport { useCallback } from 'react';\nimport type { DragStartEvent, DragMoveEvent, DragEndEvent, DragOverEvent, DragCancelEvent } from '@dnd-kit/core';\nimport { DropIndicatorPosition } from './constants';\nimport type { UseTreeActionHandlersReturn, UseTreeActionHandlersArgs } from './types';\n\nexport const useTreeActionHandlers = ({\n handlePreviewDragStart,\n handlePreviewDragMove,\n handlePreviewDragOver,\n handlePreviewDragEnd,\n handlePreviewDragCancel,\n onReorder,\n flattenedItems,\n projected,\n dropIndicatorPosition,\n isDropValid,\n}: UseTreeActionHandlersArgs): UseTreeActionHandlersReturn => {\n const onDragStart = useCallback(\n (e: DragStartEvent) => {\n handlePreviewDragStart(e);\n },\n [handlePreviewDragStart],\n );\n\n const onDragMove = useCallback(\n (e: DragMoveEvent) => {\n handlePreviewDragMove(e);\n },\n [handlePreviewDragMove],\n );\n\n const onDragOver = useCallback(\n (e: DragOverEvent) => {\n handlePreviewDragOver(e);\n },\n [handlePreviewDragOver],\n );\n\n const onDragEnd = useCallback(\n (e: DragEndEvent) => {\n handlePreviewDragEnd(e);\n const { active, over } = e;\n\n if (over === null || !isDropValid) return;\n\n const activeIndex = flattenedItems.findIndex((item) => item.uid === active.id);\n\n let considerExpanding = null;\n\n let overIndex = flattenedItems.findIndex((item) => item.uid === over.id);\n // If drop indicator is inside, then put it last,\n // It will be reconstructed well later\n if (dropIndicatorPosition === DropIndicatorPosition.Inside) {\n considerExpanding = over.id;\n overIndex = flattenedItems[overIndex].realIndex + flattenedItems[overIndex].childrenCount + 1;\n }\n\n // If we are dropping the item in a new position, or new depth\n if (projected && (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth)) {\n // Change parent and depth from projected data\n flattenedItems[activeIndex].parentId = projected.parentId;\n flattenedItems[activeIndex].depth = projected.depth;\n\n // If same index, don't move the array, just copy it\n const newFlattenedData =\n activeIndex !== overIndex ? arrayMove(flattenedItems, activeIndex, overIndex) : cloneDeep(flattenedItems);\n\n onReorder(\n newFlattenedData,\n {\n targetIndex: overIndex,\n fromIndex: activeIndex,\n },\n considerExpanding || '',\n );\n }\n },\n [handlePreviewDragEnd, isDropValid, flattenedItems, dropIndicatorPosition, projected, onReorder],\n );\n\n const onDragCancel = useCallback(\n (e: DragCancelEvent) => {\n handlePreviewDragCancel(e);\n },\n [handlePreviewDragCancel],\n );\n\n return { onDragStart, onDragMove, onDragOver, onDragEnd, onDragCancel };\n};\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;AACA;AAEA;AAGO,MAAM,wBAAwB,CAAC;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MAC4D;AAC5D,QAAM,cAAc,YAClB,CAAC,MAAsB;AACrB,2BAAuB;AAAA,KAEzB,CAAC;AAGH,QAAM,aAAa,YACjB,CAAC,MAAqB;AACpB,0BAAsB;AAAA,KAExB,CAAC;AAGH,QAAM,aAAa,YACjB,CAAC,MAAqB;AACpB,0BAAsB;AAAA,KAExB,CAAC;AAGH,QAAM,YAAY,YAChB,CAAC,MAAoB;AACnB,yBAAqB;AACrB,UAAM,EAAE,QAAQ,SAAS;AAEzB,QAAI,SAAS,QAAQ,CAAC;AAAa;AAEnC,UAAM,cAAc,eAAe,UAAU,CAAC,SAAS,KAAK,QAAQ,OAAO;AAE3E,QAAI,oBAAoB;AAExB,QAAI,YAAY,eAAe,UAAU,CAAC,SAAS,KAAK,QAAQ,KAAK;AAGrE,QAAI,0BAA0B,sBAAsB,QAAQ;AAC1D,0BAAoB,KAAK;AACzB,kBAAY,eAAe,WAAW,YAAY,eAAe,WAAW,gBAAgB;AAAA;AAI9F,QAAI,aAAc,iBAAgB,aAAa,eAAe,aAAa,UAAU,UAAU,QAAQ;AAErG,qBAAe,aAAa,WAAW,UAAU;AACjD,qBAAe,aAAa,QAAQ,UAAU;AAG9C,YAAM,mBACJ,gBAAgB,YAAY,UAAU,gBAAgB,aAAa,aAAa,UAAU;AAE5F,gBACE,kBACA;AAAA,QACE,aAAa;AAAA,QACb,WAAW;AAAA,SAEb,qBAAqB;AAAA;AAAA,KAI3B,CAAC,sBAAsB,aAAa,gBAAgB,uBAAuB,WAAW;AAGxF,QAAM,eAAe,YACnB,CAAC,MAAuB;AACtB,4BAAwB;AAAA,KAE1B,CAAC;AAGH,SAAO,EAAE,aAAa,YAAY,YAAY,WAAW;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,51 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { DropIndicatorPosition } from "./constants";
|
|
4
4
|
const useTreeAnnouncements = (visibleItemsDictionary, dropIndicatorPosition) => {
|
|
5
|
-
const onDragStart = useCallback(id =>
|
|
5
|
+
const onDragStart = useCallback((id) => `Picked up draggable item from position ${visibleItemsDictionary[id].realIndex + 1}.`, [visibleItemsDictionary]);
|
|
6
6
|
const onDragMove = useCallback((id, overId) => {
|
|
7
7
|
if (overId) {
|
|
8
8
|
const overIndex = visibleItemsDictionary[overId].realIndex + 1;
|
|
9
|
-
|
|
10
9
|
if (dropIndicatorPosition === DropIndicatorPosition.Inside) {
|
|
11
|
-
return
|
|
10
|
+
return `Draggable item was moved inside the item at position ${overIndex}.`;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
if (dropIndicatorPosition === DropIndicatorPosition.Before) {
|
|
15
|
-
return
|
|
13
|
+
return `Draggable item was moved to position ${overIndex - 1}.`;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
return "Draggable item was moved to position ".concat(overIndex, ".");
|
|
15
|
+
return `Draggable item was moved to position ${overIndex}.`;
|
|
19
16
|
}
|
|
20
|
-
|
|
21
|
-
return "Draggable item is no longer over a droppable area.";
|
|
17
|
+
return `Draggable item is no longer over a droppable area.`;
|
|
22
18
|
}, [visibleItemsDictionary, dropIndicatorPosition]);
|
|
23
19
|
const onDragOver = onDragMove;
|
|
24
20
|
const onDragEnd = useCallback((id, overId) => {
|
|
25
21
|
if (overId) {
|
|
26
22
|
const overIndex = visibleItemsDictionary[overId].realIndex + 1;
|
|
27
|
-
|
|
28
23
|
if (dropIndicatorPosition === DropIndicatorPosition.Inside) {
|
|
29
|
-
return
|
|
24
|
+
return `Draggable item was dropped inside the item at position ${overIndex}.`;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
if (dropIndicatorPosition === DropIndicatorPosition.Before) {
|
|
33
|
-
return
|
|
27
|
+
return `Draggable item was dropped over position ${overIndex - 1}.`;
|
|
34
28
|
}
|
|
35
|
-
|
|
36
|
-
return "Draggable item was dropped over position ".concat(overIndex, ".");
|
|
29
|
+
return `Draggable item was dropped over position ${overIndex}.`;
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
return "Draggable item was dropped at it's original position.";
|
|
31
|
+
return `Draggable item was dropped at it's original position.`;
|
|
40
32
|
}, [dropIndicatorPosition, visibleItemsDictionary]);
|
|
41
|
-
const onDragCancel = useCallback(id =>
|
|
42
|
-
return {
|
|
43
|
-
onDragStart,
|
|
44
|
-
onDragOver,
|
|
45
|
-
onDragMove,
|
|
46
|
-
onDragEnd,
|
|
47
|
-
onDragCancel
|
|
48
|
-
};
|
|
33
|
+
const onDragCancel = useCallback((id) => `Dragging was cancelled. Draggable item from position ${visibleItemsDictionary[id].realIndex + 1} was dropped at it's initial position.`, [visibleItemsDictionary]);
|
|
34
|
+
return { onDragStart, onDragOver, onDragMove, onDragEnd, onDragCancel };
|
|
49
35
|
};
|
|
50
|
-
|
|
51
|
-
|
|
36
|
+
export {
|
|
37
|
+
useTreeAnnouncements
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=useTreeAnnouncements.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tree/useTreeAnnouncements.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { Announcements } from '@dnd-kit/core';\nimport { useCallback } from 'react';\nimport { DropIndicatorPosition } from './constants';\nimport { Item } from './types';\n\nexport const useTreeAnnouncements = (\n visibleItemsDictionary: Record<string, Item>,\n dropIndicatorPosition: DropIndicatorPosition,\n): Announcements => {\n const onDragStart = useCallback(\n (id: string) => `Picked up draggable item from position ${visibleItemsDictionary[id].realIndex + 1}.`,\n [visibleItemsDictionary],\n );\n\n const onDragMove = useCallback(\n (id: string, overId: string) => {\n if (overId) {\n const overIndex = visibleItemsDictionary[overId].realIndex + 1;\n if (dropIndicatorPosition === DropIndicatorPosition.Inside) {\n return `Draggable item was moved inside the item at position ${overIndex}.`;\n }\n if (dropIndicatorPosition === DropIndicatorPosition.Before) {\n return `Draggable item was moved to position ${overIndex - 1}.`;\n }\n return `Draggable item was moved to position ${overIndex}.`;\n }\n\n return `Draggable item is no longer over a droppable area.`;\n },\n [visibleItemsDictionary, dropIndicatorPosition],\n );\n\n const onDragOver = onDragMove;\n\n const onDragEnd = useCallback(\n (id: string, overId: string) => {\n if (overId) {\n const overIndex = visibleItemsDictionary[overId].realIndex + 1;\n if (dropIndicatorPosition === DropIndicatorPosition.Inside) {\n return `Draggable item was dropped inside the item at position ${overIndex}.`;\n }\n if (dropIndicatorPosition === DropIndicatorPosition.Before) {\n return `Draggable item was dropped over position ${overIndex - 1}.`;\n }\n return `Draggable item was dropped over position ${overIndex}.`;\n }\n\n return `Draggable item was dropped at it's original position.`;\n },\n [dropIndicatorPosition, visibleItemsDictionary],\n );\n\n const onDragCancel = useCallback(\n (id: string) =>\n `Dragging was cancelled. Draggable item from position ${\n visibleItemsDictionary[id].realIndex + 1\n } was dropped at it's initial position.`,\n [visibleItemsDictionary],\n );\n\n return { onDragStart, onDragOver, onDragMove, onDragEnd, onDragCancel };\n};\n"],
|
|
5
|
+
"mappings": "AAAA;ACCA;AACA;AAGO,MAAM,uBAAuB,CAClC,wBACA,0BACkB;AAClB,QAAM,cAAc,YAClB,CAAC,OAAe,0CAA0C,uBAAuB,IAAI,YAAY,MACjG,CAAC;AAGH,QAAM,aAAa,YACjB,CAAC,IAAY,WAAmB;AAC9B,QAAI,QAAQ;AACV,YAAM,YAAY,uBAAuB,QAAQ,YAAY;AAC7D,UAAI,0BAA0B,sBAAsB,QAAQ;AAC1D,eAAO,wDAAwD;AAAA;AAEjE,UAAI,0BAA0B,sBAAsB,QAAQ;AAC1D,eAAO,wCAAwC,YAAY;AAAA;AAE7D,aAAO,wCAAwC;AAAA;AAGjD,WAAO;AAAA,KAET,CAAC,wBAAwB;AAG3B,QAAM,aAAa;AAEnB,QAAM,YAAY,YAChB,CAAC,IAAY,WAAmB;AAC9B,QAAI,QAAQ;AACV,YAAM,YAAY,uBAAuB,QAAQ,YAAY;AAC7D,UAAI,0BAA0B,sBAAsB,QAAQ;AAC1D,eAAO,0DAA0D;AAAA;AAEnE,UAAI,0BAA0B,sBAAsB,QAAQ;AAC1D,eAAO,4CAA4C,YAAY;AAAA;AAEjE,aAAO,4CAA4C;AAAA;AAGrD,WAAO;AAAA,KAET,CAAC,uBAAuB;AAG1B,QAAM,eAAe,YACnB,CAAC,OACC,wDACE,uBAAuB,IAAI,YAAY,2CAE3C,CAAC;AAGH,SAAO,EAAE,aAAa,YAAY,YAAY,WAAW;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,82 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const newTransform = _objectSpread({}, transform);
|
|
32
|
-
|
|
33
|
-
if (isHorizontalDnD) {
|
|
34
|
-
newTransform.x = transform.x + 25;
|
|
35
|
-
} else {
|
|
36
|
-
newTransform.x = transform.x + 15;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return newTransform;
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useState, useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import {
|
|
4
|
+
useSensor,
|
|
5
|
+
useSensors,
|
|
6
|
+
KeyboardSensor,
|
|
7
|
+
PointerSensor,
|
|
8
|
+
MeasuringStrategy
|
|
9
|
+
} from "@dnd-kit/core";
|
|
10
|
+
import { useTreePreviewHandlers } from "./useTreePreviewHandlers";
|
|
11
|
+
import { getTreeKeyboardCoordinates } from "./getTreeKeyboardCoordinates";
|
|
12
|
+
import { getProjection, removeChildrenOf } from "./utilities";
|
|
13
|
+
import { useTreeActionHandlers } from "./useTreeActionHandlers";
|
|
14
|
+
import { DropIndicatorPosition } from "./constants";
|
|
15
|
+
import { customCollisionDetection } from "./customCollisionDetection";
|
|
16
|
+
import { useTreeAnnouncements } from "./useTreeAnnouncements";
|
|
17
|
+
const adjustTranslate = (isHorizontalDnD) => {
|
|
18
|
+
const func = ({ transform }) => {
|
|
19
|
+
const newTransform = {
|
|
20
|
+
...transform
|
|
21
|
+
};
|
|
22
|
+
if (isHorizontalDnD) {
|
|
23
|
+
newTransform.x = transform.x + 25;
|
|
24
|
+
} else {
|
|
25
|
+
newTransform.x = transform.x + 15;
|
|
26
|
+
}
|
|
27
|
+
return newTransform;
|
|
28
|
+
};
|
|
29
|
+
return func;
|
|
40
30
|
};
|
|
41
|
-
|
|
42
31
|
const measuring = {
|
|
43
32
|
droppable: {
|
|
44
|
-
strategy: MeasuringStrategy.
|
|
33
|
+
strategy: MeasuringStrategy.Always
|
|
45
34
|
}
|
|
46
35
|
};
|
|
47
|
-
const useTreeDndkitConfig =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const [activeId, setActiveId] = useState('');
|
|
59
|
-
const [overId, setOverId] = useState('');
|
|
36
|
+
const useTreeDndkitConfig = ({
|
|
37
|
+
flattenedItems,
|
|
38
|
+
visibleItems: preVisibleItems,
|
|
39
|
+
isHorizontalDnD = false,
|
|
40
|
+
isExpandable = false,
|
|
41
|
+
onReorder,
|
|
42
|
+
getIsDropValid = () => true,
|
|
43
|
+
maxDragAndDropLevel
|
|
44
|
+
}) => {
|
|
45
|
+
const [activeId, setActiveId] = useState("");
|
|
46
|
+
const [overId, setOverId] = useState("");
|
|
60
47
|
const [dropIndicatorPosition, setDropIndicatorPosition] = useState(DropIndicatorPosition.None);
|
|
61
|
-
const [lastPosition, setLastPosition] = useState(
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const sortedIds = useMemo(() => visibleItems.map(item => item.uid), [visibleItems]);
|
|
66
|
-
/**
|
|
67
|
-
* Dictionary from UID to ITEM
|
|
68
|
-
* This dictionary is computed since on every DnD move, I need to know the
|
|
69
|
-
* depth of a particular row, so O(1) per DnD move instead of O(#ITEMS)
|
|
70
|
-
*/
|
|
71
|
-
|
|
48
|
+
const [lastPosition, setLastPosition] = useState("");
|
|
49
|
+
const visibleItems = useMemo(() => removeChildrenOf(preVisibleItems, activeId), [preVisibleItems, activeId]);
|
|
50
|
+
const sortedIds = useMemo(() => visibleItems.map((item) => item.uid), [visibleItems]);
|
|
72
51
|
const visibleItemsDictionary = useMemo(() => {
|
|
73
|
-
// Using plain for to achieve O(#ITEMS) performance
|
|
74
52
|
const dictionary = {};
|
|
75
|
-
visibleItems.forEach(item => {
|
|
53
|
+
visibleItems.forEach((item) => {
|
|
76
54
|
dictionary[item.uid] = item;
|
|
77
55
|
});
|
|
78
56
|
return dictionary;
|
|
79
57
|
}, [visibleItems]);
|
|
58
|
+
const isDropValid = useMemo(() => {
|
|
59
|
+
if (!activeId || !overId)
|
|
60
|
+
return true;
|
|
61
|
+
return getIsDropValid(visibleItemsDictionary[activeId], visibleItemsDictionary[overId], ["none", "before", "after", "inside"][dropIndicatorPosition]);
|
|
62
|
+
}, [getIsDropValid, visibleItemsDictionary, activeId, overId, dropIndicatorPosition]);
|
|
80
63
|
const modifiers = useMemo(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
|
|
81
64
|
const sensorContext = useRef({
|
|
82
65
|
items: visibleItems,
|
|
@@ -93,42 +76,58 @@ const useTreeDndkitConfig = _ref2 => {
|
|
|
93
76
|
const coordinateGetter = useMemo(() => getTreeKeyboardCoordinates(sensorContext, isHorizontalDnD, maxDragAndDropLevel), [sensorContext, isHorizontalDnD, maxDragAndDropLevel]);
|
|
94
77
|
const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, {
|
|
95
78
|
coordinateGetter
|
|
96
|
-
}));
|
|
97
|
-
|
|
79
|
+
}));
|
|
98
80
|
const projected = useMemo(() => overId ? getProjection(visibleItems, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) : null, [overId, visibleItems, visibleItemsDictionary, dropIndicatorPosition, isExpandable]);
|
|
99
81
|
const dragPreviewHandlers = useTreePreviewHandlers({
|
|
100
82
|
setActiveId,
|
|
101
83
|
setOverId,
|
|
102
84
|
setDropIndicatorPosition
|
|
103
85
|
});
|
|
104
|
-
const dragActionHandlers = useTreeActionHandlers(
|
|
86
|
+
const dragActionHandlers = useTreeActionHandlers({
|
|
87
|
+
...dragPreviewHandlers,
|
|
105
88
|
onReorder,
|
|
106
89
|
projected,
|
|
107
90
|
flattenedItems,
|
|
108
|
-
dropIndicatorPosition
|
|
109
|
-
|
|
91
|
+
dropIndicatorPosition,
|
|
92
|
+
isDropValid
|
|
93
|
+
});
|
|
110
94
|
const announcements = useTreeAnnouncements(visibleItemsDictionary, dropIndicatorPosition);
|
|
111
|
-
const dndContextProps = useMemo(() =>
|
|
95
|
+
const dndContextProps = useMemo(() => ({
|
|
112
96
|
announcements,
|
|
113
97
|
modifiers,
|
|
114
98
|
sensors,
|
|
115
99
|
measuring,
|
|
116
|
-
collisionDetection: customCollisionDetection(activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition)
|
|
117
|
-
|
|
100
|
+
collisionDetection: customCollisionDetection(activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition),
|
|
101
|
+
...dragActionHandlers
|
|
102
|
+
}), [
|
|
103
|
+
announcements,
|
|
104
|
+
modifiers,
|
|
105
|
+
sensors,
|
|
106
|
+
dragActionHandlers,
|
|
107
|
+
visibleItemsDictionary,
|
|
108
|
+
setDropIndicatorPosition,
|
|
109
|
+
activeId,
|
|
110
|
+
maxDragAndDropLevel,
|
|
111
|
+
lastPosition,
|
|
112
|
+
setLastPosition
|
|
113
|
+
]);
|
|
118
114
|
const sortableContextProps = useMemo(() => ({
|
|
119
115
|
items: sortedIds,
|
|
120
|
-
strategy:
|
|
121
|
-
}), [sortedIds
|
|
116
|
+
strategy: () => null
|
|
117
|
+
}), [sortedIds]);
|
|
122
118
|
return {
|
|
123
119
|
dndContextProps,
|
|
124
120
|
sortableContextProps,
|
|
121
|
+
isDropValid,
|
|
125
122
|
activeId,
|
|
126
|
-
activeIndex:
|
|
123
|
+
activeIndex: visibleItemsDictionary[activeId]?.realIndex ?? -1,
|
|
127
124
|
overId,
|
|
128
125
|
depth: projected ? projected.depth : 0,
|
|
129
126
|
dropIndicatorPosition,
|
|
130
127
|
visibleItems
|
|
131
128
|
};
|
|
132
129
|
};
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
export {
|
|
131
|
+
useTreeDndkitConfig
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=useTreeDndkitConfig.js.map
|