@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,75 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var useTreeActionHandlers_exports = {};
|
|
29
|
+
__export(useTreeActionHandlers_exports, {
|
|
30
|
+
useTreeActionHandlers: () => useTreeActionHandlers
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_sortable = require("@dnd-kit/sortable");
|
|
34
|
+
var import_lodash = require("lodash");
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var import_constants = require("./constants");
|
|
37
|
+
const useTreeActionHandlers = ({
|
|
38
|
+
handlePreviewDragStart,
|
|
39
|
+
handlePreviewDragMove,
|
|
40
|
+
handlePreviewDragOver,
|
|
41
|
+
handlePreviewDragEnd,
|
|
42
|
+
handlePreviewDragCancel,
|
|
43
|
+
onReorder,
|
|
44
|
+
flattenedItems,
|
|
45
|
+
projected,
|
|
46
|
+
dropIndicatorPosition,
|
|
47
|
+
isDropValid
|
|
48
|
+
}) => {
|
|
49
|
+
const onDragStart = (0, import_react.useCallback)((e) => {
|
|
23
50
|
handlePreviewDragStart(e);
|
|
24
51
|
}, [handlePreviewDragStart]);
|
|
25
|
-
const onDragMove =
|
|
52
|
+
const onDragMove = (0, import_react.useCallback)((e) => {
|
|
26
53
|
handlePreviewDragMove(e);
|
|
27
54
|
}, [handlePreviewDragMove]);
|
|
28
|
-
const onDragOver =
|
|
55
|
+
const onDragOver = (0, import_react.useCallback)((e) => {
|
|
29
56
|
handlePreviewDragOver(e);
|
|
30
57
|
}, [handlePreviewDragOver]);
|
|
31
|
-
const onDragEnd =
|
|
58
|
+
const onDragEnd = (0, import_react.useCallback)((e) => {
|
|
32
59
|
handlePreviewDragEnd(e);
|
|
33
|
-
const {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (over === null) return;
|
|
38
|
-
const activeIndex = flattenedItems.findIndex(item => item.uid === active.id);
|
|
60
|
+
const { active, over } = e;
|
|
61
|
+
if (over === null || !isDropValid)
|
|
62
|
+
return;
|
|
63
|
+
const activeIndex = flattenedItems.findIndex((item) => item.uid === active.id);
|
|
39
64
|
let considerExpanding = null;
|
|
40
|
-
let overIndex = flattenedItems.findIndex(item => item.uid === over.id);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside) {
|
|
44
|
-
var _flattenedItems$overI, _flattenedItems$overI2;
|
|
45
|
-
|
|
65
|
+
let overIndex = flattenedItems.findIndex((item) => item.uid === over.id);
|
|
66
|
+
if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside) {
|
|
46
67
|
considerExpanding = over.id;
|
|
47
|
-
overIndex = flattenedItems[overIndex].realIndex +
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
overIndex = flattenedItems[overIndex].realIndex + flattenedItems[overIndex].childrenCount + 1;
|
|
69
|
+
}
|
|
51
70
|
if (projected && (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth)) {
|
|
52
|
-
// Change parent and depth from projected data
|
|
53
71
|
flattenedItems[activeIndex].parentId = projected.parentId;
|
|
54
|
-
flattenedItems[activeIndex].depth = projected.depth;
|
|
55
|
-
|
|
56
|
-
const newFlattenedData = activeIndex !== overIndex ? sortable.arrayMove(flattenedItems, activeIndex, overIndex) : lodash.cloneDeep(flattenedItems);
|
|
72
|
+
flattenedItems[activeIndex].depth = projected.depth;
|
|
73
|
+
const newFlattenedData = activeIndex !== overIndex ? (0, import_sortable.arrayMove)(flattenedItems, activeIndex, overIndex) : (0, import_lodash.cloneDeep)(flattenedItems);
|
|
57
74
|
onReorder(newFlattenedData, {
|
|
58
75
|
targetIndex: overIndex,
|
|
59
76
|
fromIndex: activeIndex
|
|
60
|
-
}, considerExpanding ||
|
|
77
|
+
}, considerExpanding || "");
|
|
61
78
|
}
|
|
62
|
-
}, [handlePreviewDragEnd, flattenedItems, projected, onReorder
|
|
63
|
-
const onDragCancel =
|
|
79
|
+
}, [handlePreviewDragEnd, isDropValid, flattenedItems, dropIndicatorPosition, projected, onReorder]);
|
|
80
|
+
const onDragCancel = (0, import_react.useCallback)((e) => {
|
|
64
81
|
handlePreviewDragCancel(e);
|
|
65
82
|
}, [handlePreviewDragCancel]);
|
|
66
|
-
return {
|
|
67
|
-
onDragStart,
|
|
68
|
-
onDragMove,
|
|
69
|
-
onDragOver,
|
|
70
|
-
onDragEnd,
|
|
71
|
-
onDragCancel
|
|
72
|
-
};
|
|
83
|
+
return { onDragStart, onDragMove, onDragOver, onDragEnd, onDragCancel };
|
|
73
84
|
};
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
module.exports = __toCommonJS(useTreeActionHandlers_exports);
|
|
86
|
+
//# sourceMappingURL=useTreeActionHandlers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tree/useTreeActionHandlers.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["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", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,sBAA0B;AAC1B,oBAA0B;AAC1B,mBAA4B;AAE5B,uBAAsC;AAG/B,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,8BAClB,CAAC,MAAsB;AACrB,2BAAuB;AAAA,KAEzB,CAAC;AAGH,QAAM,aAAa,8BACjB,CAAC,MAAqB;AACpB,0BAAsB;AAAA,KAExB,CAAC;AAGH,QAAM,aAAa,8BACjB,CAAC,MAAqB;AACpB,0BAAsB;AAAA,KAExB,CAAC;AAGH,QAAM,YAAY,8BAChB,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,uCAAsB,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,+BAAU,gBAAgB,aAAa,aAAa,6BAAU;AAE5F,gBACE,kBACA;AAAA,QACE,aAAa;AAAA,QACb,WAAW;AAAA,SAEb,qBAAqB;AAAA;AAAA,KAI3B,CAAC,sBAAsB,aAAa,gBAAgB,uBAAuB,WAAW;AAGxF,QAAM,eAAe,8BACnB,CAAC,MAAuB;AACtB,4BAAwB;AAAA,KAE1B,CAAC;AAGH,SAAO,EAAE,aAAa,YAAY,YAAY,WAAW;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,55 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var useTreeAnnouncements_exports = {};
|
|
29
|
+
__export(useTreeAnnouncements_exports, {
|
|
30
|
+
useTreeAnnouncements: () => useTreeAnnouncements
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_react = require("react");
|
|
34
|
+
var import_constants = require("./constants");
|
|
8
35
|
const useTreeAnnouncements = (visibleItemsDictionary, dropIndicatorPosition) => {
|
|
9
|
-
const onDragStart =
|
|
10
|
-
const onDragMove =
|
|
36
|
+
const onDragStart = (0, import_react.useCallback)((id) => `Picked up draggable item from position ${visibleItemsDictionary[id].realIndex + 1}.`, [visibleItemsDictionary]);
|
|
37
|
+
const onDragMove = (0, import_react.useCallback)((id, overId) => {
|
|
11
38
|
if (overId) {
|
|
12
39
|
const overIndex = visibleItemsDictionary[overId].realIndex + 1;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return "Draggable item was moved inside the item at position ".concat(overIndex, ".");
|
|
40
|
+
if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside) {
|
|
41
|
+
return `Draggable item was moved inside the item at position ${overIndex}.`;
|
|
16
42
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return "Draggable item was moved to position ".concat(overIndex - 1, ".");
|
|
43
|
+
if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Before) {
|
|
44
|
+
return `Draggable item was moved to position ${overIndex - 1}.`;
|
|
20
45
|
}
|
|
21
|
-
|
|
22
|
-
return "Draggable item was moved to position ".concat(overIndex, ".");
|
|
46
|
+
return `Draggable item was moved to position ${overIndex}.`;
|
|
23
47
|
}
|
|
24
|
-
|
|
25
|
-
return "Draggable item is no longer over a droppable area.";
|
|
48
|
+
return `Draggable item is no longer over a droppable area.`;
|
|
26
49
|
}, [visibleItemsDictionary, dropIndicatorPosition]);
|
|
27
50
|
const onDragOver = onDragMove;
|
|
28
|
-
const onDragEnd =
|
|
51
|
+
const onDragEnd = (0, import_react.useCallback)((id, overId) => {
|
|
29
52
|
if (overId) {
|
|
30
53
|
const overIndex = visibleItemsDictionary[overId].realIndex + 1;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return "Draggable item was dropped inside the item at position ".concat(overIndex, ".");
|
|
54
|
+
if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside) {
|
|
55
|
+
return `Draggable item was dropped inside the item at position ${overIndex}.`;
|
|
34
56
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return "Draggable item was dropped over position ".concat(overIndex - 1, ".");
|
|
57
|
+
if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Before) {
|
|
58
|
+
return `Draggable item was dropped over position ${overIndex - 1}.`;
|
|
38
59
|
}
|
|
39
|
-
|
|
40
|
-
return "Draggable item was dropped over position ".concat(overIndex, ".");
|
|
60
|
+
return `Draggable item was dropped over position ${overIndex}.`;
|
|
41
61
|
}
|
|
42
|
-
|
|
43
|
-
return "Draggable item was dropped at it's original position.";
|
|
62
|
+
return `Draggable item was dropped at it's original position.`;
|
|
44
63
|
}, [dropIndicatorPosition, visibleItemsDictionary]);
|
|
45
|
-
const onDragCancel =
|
|
46
|
-
return {
|
|
47
|
-
onDragStart,
|
|
48
|
-
onDragOver,
|
|
49
|
-
onDragMove,
|
|
50
|
-
onDragEnd,
|
|
51
|
-
onDragCancel
|
|
52
|
-
};
|
|
64
|
+
const onDragCancel = (0, import_react.useCallback)((id) => `Dragging was cancelled. Draggable item from position ${visibleItemsDictionary[id].realIndex + 1} was dropped at it's initial position.`, [visibleItemsDictionary]);
|
|
65
|
+
return { onDragStart, onDragOver, onDragMove, onDragEnd, onDragCancel };
|
|
53
66
|
};
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
module.exports = __toCommonJS(useTreeAnnouncements_exports);
|
|
68
|
+
//# sourceMappingURL=useTreeAnnouncements.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tree/useTreeAnnouncements.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["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", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAA4B;AAC5B,uBAAsC;AAG/B,MAAM,uBAAuB,CAClC,wBACA,0BACkB;AAClB,QAAM,cAAc,8BAClB,CAAC,OAAe,0CAA0C,uBAAuB,IAAI,YAAY,MACjG,CAAC;AAGH,QAAM,aAAa,8BACjB,CAAC,IAAY,WAAmB;AAC9B,QAAI,QAAQ;AACV,YAAM,YAAY,uBAAuB,QAAQ,YAAY;AAC7D,UAAI,0BAA0B,uCAAsB,QAAQ;AAC1D,eAAO,wDAAwD;AAAA;AAEjE,UAAI,0BAA0B,uCAAsB,QAAQ;AAC1D,eAAO,wCAAwC,YAAY;AAAA;AAE7D,aAAO,wCAAwC;AAAA;AAGjD,WAAO;AAAA,KAET,CAAC,wBAAwB;AAG3B,QAAM,aAAa;AAEnB,QAAM,YAAY,8BAChB,CAAC,IAAY,WAAmB;AAC9B,QAAI,QAAQ;AACV,YAAM,YAAY,uBAAuB,QAAQ,YAAY;AAC7D,UAAI,0BAA0B,uCAAsB,QAAQ;AAC1D,eAAO,0DAA0D;AAAA;AAEnE,UAAI,0BAA0B,uCAAsB,QAAQ;AAC1D,eAAO,4CAA4C,YAAY;AAAA;AAEjE,aAAO,4CAA4C;AAAA;AAGrD,WAAO;AAAA,KAET,CAAC,uBAAuB;AAG1B,QAAM,eAAe,8BACnB,CAAC,OACC,wDACE,uBAAuB,IAAI,YAAY,2CAE3C,CAAC;AAGH,SAAO,EAAE,aAAa,YAAY,YAAY,WAAW;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,142 +1,156 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var useTreePreviewHandlers = require('./useTreePreviewHandlers.js');
|
|
18
|
-
var getTreeKeyboardCoordinates = require('./getTreeKeyboardCoordinates.js');
|
|
19
|
-
var utilities = require('./utilities.js');
|
|
20
|
-
var useTreeActionHandlers = require('./useTreeActionHandlers.js');
|
|
21
|
-
var constants = require('./constants.js');
|
|
22
|
-
var customCollisionDetection = require('./customCollisionDetection.js');
|
|
23
|
-
var useTreeAnnouncements = require('./useTreeAnnouncements.js');
|
|
24
|
-
|
|
25
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
26
|
-
|
|
27
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
28
|
-
|
|
29
|
-
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; }
|
|
30
|
-
|
|
31
|
-
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__default["default"](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; }
|
|
32
|
-
// if second parameter is true, the space will be done on the horizontal axis
|
|
33
|
-
|
|
34
|
-
const adjustTranslate = isHorizontalDnD => _ref => {
|
|
35
|
-
let {
|
|
36
|
-
transform
|
|
37
|
-
} = _ref;
|
|
38
|
-
|
|
39
|
-
const newTransform = _objectSpread({}, transform);
|
|
40
|
-
|
|
41
|
-
if (isHorizontalDnD) {
|
|
42
|
-
newTransform.x = transform.x + 25;
|
|
43
|
-
} else {
|
|
44
|
-
newTransform.x = transform.x + 15;
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
45
17
|
}
|
|
46
|
-
|
|
47
|
-
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var useTreeDndkitConfig_exports = {};
|
|
29
|
+
__export(useTreeDndkitConfig_exports, {
|
|
30
|
+
useTreeDndkitConfig: () => useTreeDndkitConfig
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_react = require("react");
|
|
34
|
+
var import_core = require("@dnd-kit/core");
|
|
35
|
+
var import_useTreePreviewHandlers = require("./useTreePreviewHandlers");
|
|
36
|
+
var import_getTreeKeyboardCoordinates = require("./getTreeKeyboardCoordinates");
|
|
37
|
+
var import_utilities = require("./utilities");
|
|
38
|
+
var import_useTreeActionHandlers = require("./useTreeActionHandlers");
|
|
39
|
+
var import_constants = require("./constants");
|
|
40
|
+
var import_customCollisionDetection = require("./customCollisionDetection");
|
|
41
|
+
var import_useTreeAnnouncements = require("./useTreeAnnouncements");
|
|
42
|
+
const adjustTranslate = (isHorizontalDnD) => {
|
|
43
|
+
const func = ({ transform }) => {
|
|
44
|
+
const newTransform = {
|
|
45
|
+
...transform
|
|
46
|
+
};
|
|
47
|
+
if (isHorizontalDnD) {
|
|
48
|
+
newTransform.x = transform.x + 25;
|
|
49
|
+
} else {
|
|
50
|
+
newTransform.x = transform.x + 15;
|
|
51
|
+
}
|
|
52
|
+
return newTransform;
|
|
53
|
+
};
|
|
54
|
+
return func;
|
|
48
55
|
};
|
|
49
|
-
|
|
50
56
|
const measuring = {
|
|
51
57
|
droppable: {
|
|
52
|
-
strategy:
|
|
58
|
+
strategy: import_core.MeasuringStrategy.Always
|
|
53
59
|
}
|
|
54
60
|
};
|
|
55
|
-
const useTreeDndkitConfig =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const [
|
|
67
|
-
const [
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const visibleItems = react.useMemo(() => utilities.removeChildrenOf(preVisibleItems, activeId), [preVisibleItems, activeId]); // Sorted ids for the library
|
|
72
|
-
|
|
73
|
-
const sortedIds = react.useMemo(() => visibleItems.map(item => item.uid), [visibleItems]);
|
|
74
|
-
/**
|
|
75
|
-
* Dictionary from UID to ITEM
|
|
76
|
-
* This dictionary is computed since on every DnD move, I need to know the
|
|
77
|
-
* depth of a particular row, so O(1) per DnD move instead of O(#ITEMS)
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
const visibleItemsDictionary = react.useMemo(() => {
|
|
81
|
-
// Using plain for to achieve O(#ITEMS) performance
|
|
61
|
+
const useTreeDndkitConfig = ({
|
|
62
|
+
flattenedItems,
|
|
63
|
+
visibleItems: preVisibleItems,
|
|
64
|
+
isHorizontalDnD = false,
|
|
65
|
+
isExpandable = false,
|
|
66
|
+
onReorder,
|
|
67
|
+
getIsDropValid = () => true,
|
|
68
|
+
maxDragAndDropLevel
|
|
69
|
+
}) => {
|
|
70
|
+
const [activeId, setActiveId] = (0, import_react.useState)("");
|
|
71
|
+
const [overId, setOverId] = (0, import_react.useState)("");
|
|
72
|
+
const [dropIndicatorPosition, setDropIndicatorPosition] = (0, import_react.useState)(import_constants.DropIndicatorPosition.None);
|
|
73
|
+
const [lastPosition, setLastPosition] = (0, import_react.useState)("");
|
|
74
|
+
const visibleItems = (0, import_react.useMemo)(() => (0, import_utilities.removeChildrenOf)(preVisibleItems, activeId), [preVisibleItems, activeId]);
|
|
75
|
+
const sortedIds = (0, import_react.useMemo)(() => visibleItems.map((item) => item.uid), [visibleItems]);
|
|
76
|
+
const visibleItemsDictionary = (0, import_react.useMemo)(() => {
|
|
82
77
|
const dictionary = {};
|
|
83
|
-
visibleItems.forEach(item => {
|
|
78
|
+
visibleItems.forEach((item) => {
|
|
84
79
|
dictionary[item.uid] = item;
|
|
85
80
|
});
|
|
86
81
|
return dictionary;
|
|
87
82
|
}, [visibleItems]);
|
|
88
|
-
const
|
|
89
|
-
|
|
83
|
+
const isDropValid = (0, import_react.useMemo)(() => {
|
|
84
|
+
if (!activeId || !overId)
|
|
85
|
+
return true;
|
|
86
|
+
return getIsDropValid(visibleItemsDictionary[activeId], visibleItemsDictionary[overId], ["none", "before", "after", "inside"][dropIndicatorPosition]);
|
|
87
|
+
}, [getIsDropValid, visibleItemsDictionary, activeId, overId, dropIndicatorPosition]);
|
|
88
|
+
const modifiers = (0, import_react.useMemo)(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
|
|
89
|
+
const sensorContext = (0, import_react.useRef)({
|
|
90
90
|
items: visibleItems,
|
|
91
91
|
dropIndicatorPosition,
|
|
92
92
|
setDropIndicatorPosition
|
|
93
93
|
});
|
|
94
|
-
|
|
94
|
+
(0, import_react.useEffect)(() => {
|
|
95
95
|
sensorContext.current = {
|
|
96
96
|
items: visibleItems,
|
|
97
97
|
dropIndicatorPosition,
|
|
98
98
|
setDropIndicatorPosition
|
|
99
99
|
};
|
|
100
100
|
}, [visibleItems, dropIndicatorPosition, setDropIndicatorPosition]);
|
|
101
|
-
const coordinateGetter =
|
|
102
|
-
const sensors =
|
|
101
|
+
const coordinateGetter = (0, import_react.useMemo)(() => (0, import_getTreeKeyboardCoordinates.getTreeKeyboardCoordinates)(sensorContext, isHorizontalDnD, maxDragAndDropLevel), [sensorContext, isHorizontalDnD, maxDragAndDropLevel]);
|
|
102
|
+
const sensors = (0, import_core.useSensors)((0, import_core.useSensor)(import_core.PointerSensor), (0, import_core.useSensor)(import_core.KeyboardSensor, {
|
|
103
103
|
coordinateGetter
|
|
104
|
-
}));
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
const dragPreviewHandlers = useTreePreviewHandlers.useTreePreviewHandlers({
|
|
104
|
+
}));
|
|
105
|
+
const projected = (0, import_react.useMemo)(() => overId ? (0, import_utilities.getProjection)(visibleItems, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) : null, [overId, visibleItems, visibleItemsDictionary, dropIndicatorPosition, isExpandable]);
|
|
106
|
+
const dragPreviewHandlers = (0, import_useTreePreviewHandlers.useTreePreviewHandlers)({
|
|
108
107
|
setActiveId,
|
|
109
108
|
setOverId,
|
|
110
109
|
setDropIndicatorPosition
|
|
111
110
|
});
|
|
112
|
-
const dragActionHandlers =
|
|
111
|
+
const dragActionHandlers = (0, import_useTreeActionHandlers.useTreeActionHandlers)({
|
|
112
|
+
...dragPreviewHandlers,
|
|
113
113
|
onReorder,
|
|
114
114
|
projected,
|
|
115
115
|
flattenedItems,
|
|
116
|
-
dropIndicatorPosition
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
116
|
+
dropIndicatorPosition,
|
|
117
|
+
isDropValid
|
|
118
|
+
});
|
|
119
|
+
const announcements = (0, import_useTreeAnnouncements.useTreeAnnouncements)(visibleItemsDictionary, dropIndicatorPosition);
|
|
120
|
+
const dndContextProps = (0, import_react.useMemo)(() => ({
|
|
120
121
|
announcements,
|
|
121
122
|
modifiers,
|
|
122
123
|
sensors,
|
|
123
124
|
measuring,
|
|
124
|
-
collisionDetection:
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
collisionDetection: (0, import_customCollisionDetection.customCollisionDetection)(activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition),
|
|
126
|
+
...dragActionHandlers
|
|
127
|
+
}), [
|
|
128
|
+
announcements,
|
|
129
|
+
modifiers,
|
|
130
|
+
sensors,
|
|
131
|
+
dragActionHandlers,
|
|
132
|
+
visibleItemsDictionary,
|
|
133
|
+
setDropIndicatorPosition,
|
|
134
|
+
activeId,
|
|
135
|
+
maxDragAndDropLevel,
|
|
136
|
+
lastPosition,
|
|
137
|
+
setLastPosition
|
|
138
|
+
]);
|
|
139
|
+
const sortableContextProps = (0, import_react.useMemo)(() => ({
|
|
127
140
|
items: sortedIds,
|
|
128
|
-
strategy:
|
|
129
|
-
}), [sortedIds
|
|
141
|
+
strategy: () => null
|
|
142
|
+
}), [sortedIds]);
|
|
130
143
|
return {
|
|
131
144
|
dndContextProps,
|
|
132
145
|
sortableContextProps,
|
|
146
|
+
isDropValid,
|
|
133
147
|
activeId,
|
|
134
|
-
activeIndex:
|
|
148
|
+
activeIndex: visibleItemsDictionary[activeId]?.realIndex ?? -1,
|
|
135
149
|
overId,
|
|
136
150
|
depth: projected ? projected.depth : 0,
|
|
137
151
|
dropIndicatorPosition,
|
|
138
152
|
visibleItems
|
|
139
153
|
};
|
|
140
154
|
};
|
|
141
|
-
|
|
142
|
-
|
|
155
|
+
module.exports = __toCommonJS(useTreeDndkitConfig_exports);
|
|
156
|
+
//# sourceMappingURL=useTreeDndkitConfig.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tree/useTreeDndkitConfig.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-lines */\nimport { useState, useEffect, useMemo, useRef } from 'react';\nimport {\n useSensor,\n useSensors,\n KeyboardSensor,\n PointerSensor,\n MeasuringConfiguration,\n MeasuringStrategy,\n Modifier,\n} from '@dnd-kit/core';\nimport { useTreePreviewHandlers } from './useTreePreviewHandlers';\nimport { getTreeKeyboardCoordinates } from './getTreeKeyboardCoordinates';\nimport { getProjection, removeChildrenOf } from './utilities';\nimport { useTreeActionHandlers } from './useTreeActionHandlers';\nimport type { UseTreeDndkitConfigType, SensorContext } from './types';\nimport { DropIndicatorPosition } from './constants';\nimport { customCollisionDetection } from './customCollisionDetection';\nimport { useTreeAnnouncements } from './useTreeAnnouncements';\n\n// we make space for the drop indicator\n// if second parameter is true, the space will be done on the horizontal axis\nconst adjustTranslate = (isHorizontalDnD: boolean): Modifier => {\n const func: Modifier = ({ transform }) => {\n const newTransform = {\n ...transform,\n };\n if (isHorizontalDnD) {\n newTransform.x = transform.x + 25;\n } else {\n newTransform.x = transform.x + 15;\n }\n return newTransform;\n };\n return func;\n};\n\nconst measuring: Partial<MeasuringConfiguration> = {\n droppable: {\n strategy: MeasuringStrategy.Always,\n },\n};\n\nexport const useTreeDndkitConfig: UseTreeDndkitConfigType = ({\n flattenedItems,\n visibleItems: preVisibleItems,\n isHorizontalDnD = false,\n isExpandable = false,\n onReorder,\n getIsDropValid = () => true,\n maxDragAndDropLevel,\n}) => {\n const [activeId, setActiveId] = useState<string>('');\n const [overId, setOverId] = useState<string>('');\n const [dropIndicatorPosition, setDropIndicatorPosition] = useState<DropIndicatorPosition>(DropIndicatorPosition.None);\n const [lastPosition, setLastPosition] = useState<string>('');\n\n // Remove activeId's children\n const visibleItems = useMemo(() => removeChildrenOf(preVisibleItems, activeId), [preVisibleItems, activeId]);\n\n // Sorted ids for the library\n const sortedIds = useMemo(() => visibleItems.map((item) => item.uid), [visibleItems]);\n\n /**\n * Dictionary from UID to ITEM\n * This dictionary is computed since on every DnD move, I need to know the\n * depth of a particular row, so O(1) per DnD move instead of O(#ITEMS)\n */\n const visibleItemsDictionary = useMemo(() => {\n // Using plain for to achieve O(#ITEMS) performance\n const dictionary: Record<string, typeof visibleItems[0]> = {};\n visibleItems.forEach((item) => {\n dictionary[item.uid] = item;\n });\n return dictionary;\n }, [visibleItems]);\n\n const isDropValid = useMemo(() => {\n if (!activeId || !overId) return true;\n return getIsDropValid(\n visibleItemsDictionary[activeId],\n visibleItemsDictionary[overId],\n ['none', 'before', 'after', 'inside'][dropIndicatorPosition] as Parameters<typeof getIsDropValid>[2],\n );\n }, [getIsDropValid, visibleItemsDictionary, activeId, overId, dropIndicatorPosition]);\n\n const modifiers: Modifier[] = useMemo(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);\n\n const sensorContext: SensorContext = useRef({\n items: visibleItems,\n dropIndicatorPosition,\n setDropIndicatorPosition,\n });\n\n useEffect(() => {\n sensorContext.current = {\n items: visibleItems,\n dropIndicatorPosition,\n setDropIndicatorPosition,\n };\n }, [visibleItems, dropIndicatorPosition, setDropIndicatorPosition]);\n\n const coordinateGetter = useMemo(\n () => getTreeKeyboardCoordinates(sensorContext, isHorizontalDnD, maxDragAndDropLevel),\n [sensorContext, isHorizontalDnD, maxDragAndDropLevel],\n );\n\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor, {\n coordinateGetter,\n }),\n );\n\n // where is the activeItem being positioned (depth and parent)\n const projected = useMemo(\n () =>\n overId ? getProjection(visibleItems, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) : null,\n [overId, visibleItems, visibleItemsDictionary, dropIndicatorPosition, isExpandable],\n );\n\n const dragPreviewHandlers = useTreePreviewHandlers({\n setActiveId,\n setOverId,\n setDropIndicatorPosition,\n });\n\n const dragActionHandlers = useTreeActionHandlers({\n ...dragPreviewHandlers,\n onReorder,\n projected,\n flattenedItems,\n dropIndicatorPosition,\n isDropValid,\n });\n\n const announcements = useTreeAnnouncements(visibleItemsDictionary, dropIndicatorPosition);\n\n const dndContextProps = useMemo(\n () => ({\n announcements,\n modifiers,\n sensors,\n measuring,\n collisionDetection: customCollisionDetection(\n activeId,\n visibleItemsDictionary,\n setDropIndicatorPosition,\n maxDragAndDropLevel,\n lastPosition,\n setLastPosition,\n ),\n ...dragActionHandlers,\n }),\n [\n announcements,\n modifiers,\n sensors,\n dragActionHandlers,\n visibleItemsDictionary,\n setDropIndicatorPosition,\n activeId,\n maxDragAndDropLevel,\n lastPosition,\n setLastPosition,\n ],\n );\n\n const sortableContextProps = useMemo(\n () => ({\n items: sortedIds,\n strategy: () => null,\n }),\n [sortedIds],\n );\n\n return {\n dndContextProps,\n sortableContextProps,\n isDropValid,\n activeId,\n activeIndex: visibleItemsDictionary[activeId]?.realIndex ?? -1,\n overId,\n depth: projected ? projected.depth : 0,\n dropIndicatorPosition,\n visibleItems,\n };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|