@elliemae/ds-drag-and-drop 2.1.0 → 2.2.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 +64 -95
- package/cjs/tree/customCollisionDetection.js.map +7 -0
- package/cjs/tree/getTreeKeyboardCoordinates.js +87 -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 +66 -56
- 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 +95 -91
- 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 +33 -89
- package/esm/tree/customCollisionDetection.js.map +7 -0
- package/esm/tree/getTreeKeyboardCoordinates.js +49 -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 +35 -50
- 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 +59 -70
- 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
|
@@ -1,45 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 useTreePreviewHandlers_exports = {};
|
|
29
|
+
__export(useTreePreviewHandlers_exports, {
|
|
30
|
+
useTreePreviewHandlers: () => useTreePreviewHandlers
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_react = __toESM(require("react"));
|
|
34
|
+
var import_constants = __toESM(require("./constants"));
|
|
35
|
+
const useTreePreviewHandlers = ({
|
|
36
|
+
setOverId,
|
|
37
|
+
setActiveId,
|
|
38
|
+
setDropIndicatorPosition
|
|
39
|
+
}) => {
|
|
40
|
+
const resetState = (0, import_react.useCallback)(() => {
|
|
41
|
+
setOverId("");
|
|
42
|
+
setActiveId("");
|
|
43
|
+
document.body.style.setProperty("cursor", "");
|
|
18
44
|
}, [setOverId, setActiveId]);
|
|
19
|
-
const handlePreviewDragStart =
|
|
20
|
-
let {
|
|
21
|
-
active: {
|
|
22
|
-
id
|
|
23
|
-
}
|
|
24
|
-
} = _ref2;
|
|
45
|
+
const handlePreviewDragStart = (0, import_react.useCallback)(({ active: { id } }) => {
|
|
25
46
|
setActiveId(id);
|
|
26
47
|
setOverId(id);
|
|
27
|
-
setDropIndicatorPosition(
|
|
28
|
-
document.body.style.setProperty(
|
|
48
|
+
setDropIndicatorPosition(import_constants.DropIndicatorPosition.Inside);
|
|
49
|
+
document.body.style.setProperty("cursor", "grabbing");
|
|
29
50
|
}, [setActiveId, setDropIndicatorPosition, setOverId]);
|
|
30
|
-
const handlePreviewDragMove =
|
|
31
|
-
const handlePreviewDragOver =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let {
|
|
35
|
-
over
|
|
36
|
-
} = _ref3;
|
|
37
|
-
setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : '');
|
|
51
|
+
const handlePreviewDragMove = (0, import_react.useCallback)(() => null, []);
|
|
52
|
+
const handlePreviewDragOver = (0, import_react.useCallback)(({ over }) => {
|
|
53
|
+
setOverId(over?.id ?? "");
|
|
38
54
|
}, [setOverId]);
|
|
39
|
-
const handlePreviewDragEnd =
|
|
55
|
+
const handlePreviewDragEnd = (0, import_react.useCallback)(() => {
|
|
40
56
|
resetState();
|
|
41
57
|
}, [resetState]);
|
|
42
|
-
const handlePreviewDragCancel =
|
|
58
|
+
const handlePreviewDragCancel = (0, import_react.useCallback)(() => {
|
|
43
59
|
resetState();
|
|
44
60
|
}, [resetState]);
|
|
45
61
|
return {
|
|
@@ -50,5 +66,5 @@ const useTreePreviewHandlers = _ref => {
|
|
|
50
66
|
handlePreviewDragCancel
|
|
51
67
|
};
|
|
52
68
|
};
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
module.exports = __toCommonJS(useTreePreviewHandlers_exports);
|
|
70
|
+
//# sourceMappingURL=useTreePreviewHandlers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tree/useTreePreviewHandlers.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["import { useCallback } from 'react';\nimport { DragStartEvent, DragOverEvent } from '@dnd-kit/core';\nimport type { useTreePreviewHandlersReturn, useTreePreviewHandlersArgs } from './types';\nimport { DropIndicatorPosition } from './constants';\n\nexport const useTreePreviewHandlers = ({\n setOverId,\n setActiveId,\n setDropIndicatorPosition,\n}: useTreePreviewHandlersArgs): useTreePreviewHandlersReturn => {\n const resetState = useCallback(() => {\n setOverId('');\n setActiveId('');\n\n document.body.style.setProperty('cursor', '');\n }, [setOverId, setActiveId]);\n\n const handlePreviewDragStart = useCallback(\n ({ active: { id } }: DragStartEvent) => {\n setActiveId(id);\n setOverId(id);\n setDropIndicatorPosition(DropIndicatorPosition.Inside);\n\n document.body.style.setProperty('cursor', 'grabbing');\n },\n [setActiveId, setDropIndicatorPosition, setOverId],\n );\n\n const handlePreviewDragMove = useCallback(() => null, []);\n\n const handlePreviewDragOver = useCallback(\n ({ over }: DragOverEvent) => {\n setOverId(over?.id ?? '');\n },\n [setOverId],\n );\n\n const handlePreviewDragEnd = useCallback(() => {\n resetState();\n }, [resetState]);\n\n const handlePreviewDragCancel = useCallback(() => {\n resetState();\n }, [resetState]);\n\n return {\n handlePreviewDragStart,\n handlePreviewDragMove,\n handlePreviewDragOver,\n handlePreviewDragEnd,\n handlePreviewDragCancel,\n };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAA4B;AAG5B,uBAAsC;AAE/B,MAAM,yBAAyB,CAAC;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,MAC8D;AAC9D,QAAM,aAAa,8BAAY,MAAM;AACnC,cAAU;AACV,gBAAY;AAEZ,aAAS,KAAK,MAAM,YAAY,UAAU;AAAA,KACzC,CAAC,WAAW;AAEf,QAAM,yBAAyB,8BAC7B,CAAC,EAAE,QAAQ,EAAE,WAA2B;AACtC,gBAAY;AACZ,cAAU;AACV,6BAAyB,uCAAsB;AAE/C,aAAS,KAAK,MAAM,YAAY,UAAU;AAAA,KAE5C,CAAC,aAAa,0BAA0B;AAG1C,QAAM,wBAAwB,8BAAY,MAAM,MAAM;AAEtD,QAAM,wBAAwB,8BAC5B,CAAC,EAAE,WAA0B;AAC3B,cAAU,MAAM,MAAM;AAAA,KAExB,CAAC;AAGH,QAAM,uBAAuB,8BAAY,MAAM;AAC7C;AAAA,KACC,CAAC;AAEJ,QAAM,0BAA0B,8BAAY,MAAM;AAChD;AAAA,KACC,CAAC;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/cjs/tree/utilities.js
CHANGED
|
@@ -1,52 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 utilities_exports = {};
|
|
29
|
+
__export(utilities_exports, {
|
|
30
|
+
getProjection: () => getProjection,
|
|
31
|
+
removeChildrenOf: () => removeChildrenOf
|
|
32
|
+
});
|
|
33
|
+
var React = __toESM(require("react"));
|
|
34
|
+
var import_constants = __toESM(require("./constants"));
|
|
35
|
+
const getMinDepth = (item) => {
|
|
36
|
+
if (item)
|
|
37
|
+
return item.depth;
|
|
12
38
|
return 0;
|
|
13
39
|
};
|
|
14
|
-
|
|
15
40
|
const getProjection = (items, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) => {
|
|
16
41
|
const overItemIndex = visibleItemsDictionary[overId].realIndex;
|
|
17
42
|
const previousItem = items[overItemIndex];
|
|
18
43
|
const nextItem = items[overItemIndex + 1];
|
|
19
|
-
|
|
20
|
-
if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside && isExpandable) {
|
|
44
|
+
if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside && isExpandable) {
|
|
21
45
|
return {
|
|
22
46
|
depth: visibleItemsDictionary[overId].depth + 1,
|
|
23
47
|
parentId: overId
|
|
24
48
|
};
|
|
25
49
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
depth: getMinDepth(previousItem),
|
|
30
|
-
parentId: previousItem.parentId
|
|
31
|
-
};
|
|
50
|
+
if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Before) {
|
|
51
|
+
return { depth: getMinDepth(previousItem), parentId: previousItem.parentId };
|
|
32
52
|
}
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
depth: getMinDepth(nextItem),
|
|
36
|
-
parentId: nextItem === null || nextItem === void 0 ? void 0 : nextItem.parentId
|
|
37
|
-
};
|
|
53
|
+
return { depth: getMinDepth(nextItem), parentId: nextItem?.parentId };
|
|
38
54
|
};
|
|
39
55
|
const removeChildrenOf = (items, id) => {
|
|
40
56
|
const excludeParentIds = [id];
|
|
41
|
-
return items.filter(item => {
|
|
57
|
+
return items.filter((item) => {
|
|
42
58
|
if (item.parentId !== null && excludeParentIds.includes(item.parentId)) {
|
|
43
59
|
excludeParentIds.push(item.uid);
|
|
44
60
|
return false;
|
|
45
61
|
}
|
|
46
|
-
|
|
47
62
|
return true;
|
|
48
63
|
});
|
|
49
64
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
exports.removeChildrenOf = removeChildrenOf;
|
|
65
|
+
module.exports = __toCommonJS(utilities_exports);
|
|
66
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tree/utilities.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-params */\nimport { DropIndicatorPosition } from './constants';\n\nimport { Item } from './types';\n\nconst getMinDepth = (item: Item) => {\n if (item) return item.depth;\n return 0;\n};\n\nexport const getProjection = (\n items: Item[],\n visibleItemsDictionary: Record<string, Item>,\n overId: string,\n dropIndicatorPosition: DropIndicatorPosition,\n isExpandable: boolean,\n): { depth: number; parentId: string } => {\n const overItemIndex = visibleItemsDictionary[overId].realIndex;\n\n const previousItem = items[overItemIndex];\n const nextItem = items[overItemIndex + 1];\n\n if (dropIndicatorPosition === DropIndicatorPosition.Inside && isExpandable) {\n return {\n depth: visibleItemsDictionary[overId].depth + 1,\n parentId: overId,\n };\n }\n if (dropIndicatorPosition === DropIndicatorPosition.Before) {\n return { depth: getMinDepth(previousItem), parentId: previousItem.parentId };\n }\n return { depth: getMinDepth(nextItem), parentId: nextItem?.parentId };\n};\n\nexport const removeChildrenOf = (items: Item[], id: string): Item[] => {\n const excludeParentIds = [id];\n\n return items.filter((item) => {\n if (item.parentId !== null && excludeParentIds.includes(item.parentId)) {\n excludeParentIds.push(item.uid);\n return false;\n }\n return true;\n });\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,uBAAsC;AAItC,MAAM,cAAc,CAAC,SAAe;AAClC,MAAI;AAAM,WAAO,KAAK;AACtB,SAAO;AAAA;AAGF,MAAM,gBAAgB,CAC3B,OACA,wBACA,QACA,uBACA,iBACwC;AACxC,QAAM,gBAAgB,uBAAuB,QAAQ;AAErD,QAAM,eAAe,MAAM;AAC3B,QAAM,WAAW,MAAM,gBAAgB;AAEvC,MAAI,0BAA0B,uCAAsB,UAAU,cAAc;AAC1E,WAAO;AAAA,MACL,OAAO,uBAAuB,QAAQ,QAAQ;AAAA,MAC9C,UAAU;AAAA;AAAA;AAGd,MAAI,0BAA0B,uCAAsB,QAAQ;AAC1D,WAAO,EAAE,OAAO,YAAY,eAAe,UAAU,aAAa;AAAA;AAEpE,SAAO,EAAE,OAAO,YAAY,WAAW,UAAU,UAAU;AAAA;AAGtD,MAAM,mBAAmB,CAAC,OAAe,OAAuB;AACrE,QAAM,mBAAmB,CAAC;AAE1B,SAAO,MAAM,OAAO,CAAC,SAAS;AAC5B,QAAI,KAAK,aAAa,QAAQ,iBAAiB,SAAS,KAAK,WAAW;AACtE,uBAAiB,KAAK,KAAK;AAC3B,aAAO;AAAA;AAET,WAAO;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,54 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const customCollisionDetection = (activeId, activeParent, dndItems) => _ref => {
|
|
10
|
-
var _originalContainer$re;
|
|
11
|
-
|
|
12
|
-
let {
|
|
13
|
-
droppableContainers,
|
|
14
|
-
collisionRect
|
|
15
|
-
} = _ref;
|
|
16
|
-
const entriesWithSameParent = droppableContainers.filter(_ref2 => {
|
|
17
|
-
var _dndItems$find;
|
|
18
|
-
|
|
19
|
-
let {
|
|
20
|
-
id
|
|
21
|
-
} = _ref2;
|
|
22
|
-
return ((_dndItems$find = dndItems.find(item => item.id === id)) === null || _dndItems$find === void 0 ? void 0 : _dndItems$find.parentId) === activeParent;
|
|
23
|
-
});
|
|
24
|
-
const originalContainer = entriesWithSameParent.find(_ref3 => {
|
|
25
|
-
let {
|
|
26
|
-
id
|
|
27
|
-
} = _ref3;
|
|
28
|
-
return id === activeId;
|
|
29
|
-
});
|
|
30
|
-
const originalRect = originalContainer === null || originalContainer === void 0 ? void 0 : (_originalContainer$re = originalContainer.rect) === null || _originalContainer$re === void 0 ? void 0 : _originalContainer$re.current;
|
|
31
|
-
if (!originalRect) return null;
|
|
32
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const customCollisionDetection = (activeId, activeParent, dndItems) => ({ droppableContainers, collisionRect }) => {
|
|
3
|
+
const entriesWithSameParent = droppableContainers.filter(({ id }) => dndItems.find((item) => item.id === id)?.parentId === activeParent);
|
|
4
|
+
const originalContainer = entriesWithSameParent.find(({ id }) => id === activeId);
|
|
5
|
+
const originalRect = originalContainer?.rect?.current;
|
|
6
|
+
if (!originalRect)
|
|
7
|
+
return null;
|
|
33
8
|
if (originalRect.offsetLeft <= collisionRect.offsetLeft && collisionRect.offsetLeft <= originalRect.offsetLeft + originalRect.width) {
|
|
34
9
|
return originalContainer.id;
|
|
35
10
|
}
|
|
36
|
-
|
|
37
11
|
const isLeft = collisionRect.offsetLeft <= originalRect.offsetLeft + collisionRect.width / 2 + 5;
|
|
38
|
-
let match = null;
|
|
39
|
-
// Otherwise, get the closest offset right
|
|
40
|
-
|
|
12
|
+
let match = null;
|
|
41
13
|
const collisionPoint = collisionRect.offsetLeft + collisionRect.width / 2;
|
|
42
|
-
entriesWithSameParent.forEach(entry => {
|
|
14
|
+
entriesWithSameParent.forEach((entry) => {
|
|
43
15
|
const {
|
|
44
|
-
rect: {
|
|
45
|
-
current: rect
|
|
46
|
-
}
|
|
16
|
+
rect: { current: rect }
|
|
47
17
|
} = entry;
|
|
48
|
-
|
|
49
18
|
if (rect !== null) {
|
|
50
19
|
const offsetRight = rect.offsetLeft + rect.width;
|
|
51
|
-
|
|
52
20
|
if (!match) {
|
|
53
21
|
match = entry;
|
|
54
22
|
} else if (match && match.rect.current && isLeft && Math.abs(collisionPoint - rect.offsetLeft) <= Math.abs(collisionPoint - match.rect.current.offsetLeft)) {
|
|
@@ -57,10 +25,11 @@ const customCollisionDetection = (activeId, activeParent, dndItems) => _ref => {
|
|
|
57
25
|
match = entry;
|
|
58
26
|
}
|
|
59
27
|
}
|
|
60
|
-
});
|
|
61
|
-
|
|
28
|
+
});
|
|
62
29
|
const matchCastedForSomeReason = match;
|
|
63
30
|
return matchCastedForSomeReason === null ? null : matchCastedForSomeReason.id;
|
|
64
31
|
};
|
|
65
|
-
|
|
66
|
-
|
|
32
|
+
export {
|
|
33
|
+
customCollisionDetection
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=customCollisionDetection.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hierarchy/customCollisionDetection.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { CollisionDetection, DroppableContainer } from '@dnd-kit/core';\nimport { Item } from './types';\n\nexport const customCollisionDetection =\n (activeId: string | null, activeParent: string | undefined, dndItems: Item[]): CollisionDetection =>\n ({ droppableContainers, collisionRect }) => {\n const entriesWithSameParent = droppableContainers.filter(\n ({ id }) => dndItems.find((item) => item.id === id)?.parentId === activeParent,\n );\n\n const originalContainer = entriesWithSameParent.find(({ id }) => id === activeId);\n const originalRect = originalContainer?.rect?.current;\n\n if (!originalRect) return null;\n\n if (\n originalRect.offsetLeft <= collisionRect.offsetLeft &&\n collisionRect.offsetLeft <= originalRect.offsetLeft + originalRect.width\n ) {\n return originalContainer.id;\n }\n\n const isLeft = collisionRect.offsetLeft <= originalRect.offsetLeft + collisionRect.width / 2 + 5;\n\n let match: DroppableContainer | null = null;\n // If going to the left, search the closest offset left\n // Otherwise, get the closest offset right\n const collisionPoint = collisionRect.offsetLeft + collisionRect.width / 2;\n entriesWithSameParent.forEach((entry) => {\n const {\n rect: { current: rect },\n } = entry;\n\n if (rect !== null) {\n const offsetRight = rect.offsetLeft + rect.width;\n\n if (!match) {\n match = entry;\n } else if (\n match &&\n match.rect.current &&\n isLeft &&\n Math.abs(collisionPoint - rect.offsetLeft) <= Math.abs(collisionPoint - match.rect.current.offsetLeft)\n ) {\n match = entry;\n } else if (\n match &&\n match.rect.current &&\n !isLeft &&\n Math.abs(collisionPoint - offsetRight) <=\n Math.abs(collisionPoint - match.rect.current.offsetLeft - match.rect.current.width)\n ) {\n match = entry;\n }\n }\n });\n // Typescript believes match is always null for some reason\n const matchCastedForSomeReason = match as DroppableContainer | null;\n return matchCastedForSomeReason === null ? null : matchCastedForSomeReason.id;\n };\n"],
|
|
5
|
+
"mappings": "AAAA;ACGO,MAAM,2BACX,CAAC,UAAyB,cAAkC,aAC5D,CAAC,EAAE,qBAAqB,oBAAoB;AAC1C,QAAM,wBAAwB,oBAAoB,OAChD,CAAC,EAAE,SAAS,SAAS,KAAK,CAAC,SAAS,KAAK,OAAO,KAAK,aAAa;AAGpE,QAAM,oBAAoB,sBAAsB,KAAK,CAAC,EAAE,SAAS,OAAO;AACxE,QAAM,eAAe,mBAAmB,MAAM;AAE9C,MAAI,CAAC;AAAc,WAAO;AAE1B,MACE,aAAa,cAAc,cAAc,cACzC,cAAc,cAAc,aAAa,aAAa,aAAa,OACnE;AACA,WAAO,kBAAkB;AAAA;AAG3B,QAAM,SAAS,cAAc,cAAc,aAAa,aAAa,cAAc,QAAQ,IAAI;AAE/F,MAAI,QAAmC;AAGvC,QAAM,iBAAiB,cAAc,aAAa,cAAc,QAAQ;AACxE,wBAAsB,QAAQ,CAAC,UAAU;AACvC,UAAM;AAAA,MACJ,MAAM,EAAE,SAAS;AAAA,QACf;AAEJ,QAAI,SAAS,MAAM;AACjB,YAAM,cAAc,KAAK,aAAa,KAAK;AAE3C,UAAI,CAAC,OAAO;AACV,gBAAQ;AAAA,iBAER,SACA,MAAM,KAAK,WACX,UACA,KAAK,IAAI,iBAAiB,KAAK,eAAe,KAAK,IAAI,iBAAiB,MAAM,KAAK,QAAQ,aAC3F;AACA,gBAAQ;AAAA,iBAER,SACA,MAAM,KAAK,WACX,CAAC,UACD,KAAK,IAAI,iBAAiB,gBACxB,KAAK,IAAI,iBAAiB,MAAM,KAAK,QAAQ,aAAa,MAAM,KAAK,QAAQ,QAC/E;AACA,gBAAQ;AAAA;AAAA;AAAA;AAKd,QAAM,2BAA2B;AACjC,SAAO,6BAA6B,OAAO,OAAO,yBAAyB;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,97 +1,61 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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; }
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { closestCorners, getViewRect, KeyboardCode } from "@dnd-kit/core";
|
|
14
3
|
const directions = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];
|
|
15
4
|
const vertical = [KeyboardCode.Up, KeyboardCode.Down];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} = _ref;
|
|
29
|
-
if (vertical.includes(event.code) || !active || !over) return undefined;
|
|
30
|
-
const activeItem = items.find(item => item.id === active.id);
|
|
5
|
+
const getHorizontalKeyboardCoordinates = ({
|
|
6
|
+
items,
|
|
7
|
+
active,
|
|
8
|
+
over,
|
|
9
|
+
event,
|
|
10
|
+
currentCoordinates,
|
|
11
|
+
droppableContainers,
|
|
12
|
+
collisionRect
|
|
13
|
+
}) => {
|
|
14
|
+
if (vertical.includes(event.code) || !active || !over)
|
|
15
|
+
return void 0;
|
|
16
|
+
const activeItem = items.find((item) => item.id === active.id);
|
|
31
17
|
const overRect = over.rect;
|
|
32
|
-
const layoutRects = [];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var _items$find;
|
|
36
|
-
|
|
37
|
-
if (container !== null && container !== void 0 && container.disabled || !overRect) {
|
|
18
|
+
const layoutRects = [];
|
|
19
|
+
droppableContainers.forEach((container) => {
|
|
20
|
+
if (container?.disabled || !overRect) {
|
|
38
21
|
return;
|
|
39
22
|
}
|
|
40
|
-
|
|
41
|
-
const node = container === null || container === void 0 ? void 0 : container.node.current;
|
|
42
|
-
|
|
23
|
+
const node = container?.node.current;
|
|
43
24
|
if (!node) {
|
|
44
25
|
return;
|
|
45
26
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
27
|
+
const itemParent = items.find((item) => item.id === container.id)?.parentId;
|
|
28
|
+
if (itemParent !== activeItem?.parentId)
|
|
29
|
+
return;
|
|
49
30
|
const rect = getViewRect(node);
|
|
50
|
-
|
|
51
31
|
if (event.code === KeyboardCode.Left && collisionRect.left > rect.right - 10) {
|
|
52
32
|
layoutRects.push(container);
|
|
53
33
|
} else if (event.code === KeyboardCode.Right && collisionRect.left < rect.left) {
|
|
54
34
|
layoutRects.push(container);
|
|
55
35
|
}
|
|
56
36
|
});
|
|
57
|
-
const closestId = closestCorners({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!
|
|
63
|
-
|
|
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;
|
|
37
|
+
const closestId = closestCorners({ droppableContainers: layoutRects, collisionRect, active });
|
|
38
|
+
if (!closestId)
|
|
39
|
+
return void 0;
|
|
40
|
+
const closestDroppableContainer = droppableContainers.get(closestId)?.node?.current;
|
|
41
|
+
const activeDroppableContainer = droppableContainers.get(active?.id)?.node?.current;
|
|
42
|
+
if (!closestDroppableContainer || !activeDroppableContainer)
|
|
43
|
+
return void 0;
|
|
66
44
|
const closestRect = getViewRect(closestDroppableContainer);
|
|
67
45
|
const activeRect = getViewRect(activeDroppableContainer);
|
|
68
|
-
return
|
|
46
|
+
return {
|
|
47
|
+
...currentCoordinates,
|
|
69
48
|
x: closestRect.left + (closestRect.width - collisionRect.width) / 2 + (closestRect.offsetLeft < activeRect.left ? -1 : 1)
|
|
70
|
-
}
|
|
49
|
+
};
|
|
71
50
|
};
|
|
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
|
-
|
|
51
|
+
const getHierarchyKeyboardCoordinates = (context, dragOverlayDataTestid, isHorizontalDnD) => (event, { currentCoordinates, context: { active, over, collisionRect, droppableContainers } }) => {
|
|
84
52
|
if (directions.includes(event.code)) {
|
|
85
53
|
event.preventDefault();
|
|
86
|
-
|
|
87
54
|
if (!collisionRect) {
|
|
88
|
-
return
|
|
55
|
+
return void 0;
|
|
89
56
|
}
|
|
90
|
-
|
|
91
57
|
const {
|
|
92
|
-
current: {
|
|
93
|
-
items
|
|
94
|
-
}
|
|
58
|
+
current: { items }
|
|
95
59
|
} = context;
|
|
96
60
|
const args = {
|
|
97
61
|
dragOverlayDataTestid,
|
|
@@ -103,11 +67,13 @@ const getHierarchyKeyboardCoordinates = (context, dragOverlayDataTestid, isHoriz
|
|
|
103
67
|
droppableContainers,
|
|
104
68
|
collisionRect
|
|
105
69
|
};
|
|
106
|
-
if (isHorizontalDnD)
|
|
107
|
-
|
|
70
|
+
if (isHorizontalDnD)
|
|
71
|
+
return getHorizontalKeyboardCoordinates(args);
|
|
72
|
+
return void 0;
|
|
108
73
|
}
|
|
109
|
-
|
|
110
|
-
|
|
74
|
+
return void 0;
|
|
75
|
+
};
|
|
76
|
+
export {
|
|
77
|
+
getHierarchyKeyboardCoordinates
|
|
111
78
|
};
|
|
112
|
-
|
|
113
|
-
export { getHierarchyKeyboardCoordinates };
|
|
79
|
+
//# sourceMappingURL=getHierarchyKeyboardCoordinates.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hierarchy/getHierarchyKeyboardCoordinates.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { closestCorners, getViewRect, KeyboardCode, KeyboardCoordinateGetter, DroppableContainer } from '@dnd-kit/core';\nimport { Coordinates } from '@dnd-kit/core/dist/types';\n\nimport { GetKeyboardCoordinatesArgs, SensorContext } from './types';\n\nconst directions: string[] = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];\n\nconst vertical: string[] = [KeyboardCode.Up, KeyboardCode.Down];\n\nconst getHorizontalKeyboardCoordinates = ({\n items,\n active,\n over,\n event,\n currentCoordinates,\n droppableContainers,\n collisionRect,\n}: GetKeyboardCoordinatesArgs): Coordinates | undefined => {\n if (vertical.includes(event.code) || !active || !over) return undefined;\n\n const activeItem = items.find((item) => item.id === active.id);\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 node = container?.node.current;\n if (!node) {\n return;\n }\n const itemParent = items.find((item) => item.id === container.id)?.parentId;\n if (itemParent !== activeItem?.parentId) return;\n const rect = getViewRect(node);\n if (event.code === KeyboardCode.Left && collisionRect.left > rect.right - 10) {\n layoutRects.push(container);\n } else if (event.code === KeyboardCode.Right && collisionRect.left < rect.left) {\n layoutRects.push(container);\n }\n });\n\n const closestId = closestCorners({ droppableContainers: layoutRects, collisionRect, active });\n\n if (!closestId) return undefined;\n\n const closestDroppableContainer = droppableContainers.get(closestId)?.node?.current;\n const activeDroppableContainer = droppableContainers.get(active?.id)?.node?.current;\n\n if (!closestDroppableContainer || !activeDroppableContainer) return undefined;\n\n const closestRect = getViewRect(closestDroppableContainer);\n const activeRect = getViewRect(activeDroppableContainer);\n return {\n ...currentCoordinates,\n x:\n closestRect.left +\n (closestRect.width - collisionRect.width) / 2 +\n (closestRect.offsetLeft < activeRect.left ? -1 : 1),\n };\n};\n\nexport const getHierarchyKeyboardCoordinates: (\n context: SensorContext,\n dragOverlayDataTestid: string,\n isHorizontalDnD: boolean,\n) => KeyboardCoordinateGetter =\n (context, dragOverlayDataTestid, isHorizontalDnD) =>\n (event, { currentCoordinates, context: { active, over, collisionRect, droppableContainers } }) => {\n if (directions.includes(event.code)) {\n event.preventDefault();\n if (!collisionRect) {\n return undefined;\n }\n\n const {\n current: { items },\n } = context;\n\n const args = {\n dragOverlayDataTestid,\n items,\n active,\n over,\n event,\n currentCoordinates,\n droppableContainers,\n collisionRect,\n };\n\n if (isHorizontalDnD) return getHorizontalKeyboardCoordinates(args);\n return undefined;\n }\n return undefined;\n };\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AAKA,MAAM,aAAuB,CAAC,aAAa,MAAM,aAAa,OAAO,aAAa,IAAI,aAAa;AAEnG,MAAM,WAAqB,CAAC,aAAa,IAAI,aAAa;AAE1D,MAAM,mCAAmC,CAAC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACyD;AACzD,MAAI,SAAS,SAAS,MAAM,SAAS,CAAC,UAAU,CAAC;AAAM,WAAO;AAE9D,QAAM,aAAa,MAAM,KAAK,CAAC,SAAS,KAAK,OAAO,OAAO;AAE3D,QAAM,WAAW,KAAK;AAEtB,QAAM,cAAoC;AAG1C,sBAAoB,QAAQ,CAAC,cAAc;AACzC,QAAI,WAAW,YAAY,CAAC,UAAU;AACpC;AAAA;AAEF,UAAM,OAAO,WAAW,KAAK;AAC7B,QAAI,CAAC,MAAM;AACT;AAAA;AAEF,UAAM,aAAa,MAAM,KAAK,CAAC,SAAS,KAAK,OAAO,UAAU,KAAK;AACnE,QAAI,eAAe,YAAY;AAAU;AACzC,UAAM,OAAO,YAAY;AACzB,QAAI,MAAM,SAAS,aAAa,QAAQ,cAAc,OAAO,KAAK,QAAQ,IAAI;AAC5E,kBAAY,KAAK;AAAA,eACR,MAAM,SAAS,aAAa,SAAS,cAAc,OAAO,KAAK,MAAM;AAC9E,kBAAY,KAAK;AAAA;AAAA;AAIrB,QAAM,YAAY,eAAe,EAAE,qBAAqB,aAAa,eAAe;AAEpF,MAAI,CAAC;AAAW,WAAO;AAEvB,QAAM,4BAA4B,oBAAoB,IAAI,YAAY,MAAM;AAC5E,QAAM,2BAA2B,oBAAoB,IAAI,QAAQ,KAAK,MAAM;AAE5E,MAAI,CAAC,6BAA6B,CAAC;AAA0B,WAAO;AAEpE,QAAM,cAAc,YAAY;AAChC,QAAM,aAAa,YAAY;AAC/B,SAAO;AAAA,OACF;AAAA,IACH,GACE,YAAY,OACX,aAAY,QAAQ,cAAc,SAAS,IAC3C,aAAY,aAAa,WAAW,OAAO,KAAK;AAAA;AAAA;AAIhD,MAAM,kCAKX,CAAC,SAAS,uBAAuB,oBACjC,CAAC,OAAO,EAAE,oBAAoB,SAAS,EAAE,QAAQ,MAAM,eAAe,4BAA4B;AAChG,MAAI,WAAW,SAAS,MAAM,OAAO;AACnC,UAAM;AACN,QAAI,CAAC,eAAe;AAClB,aAAO;AAAA;AAGT,UAAM;AAAA,MACJ,SAAS,EAAE;AAAA,QACT;AAEJ,UAAM,OAAO;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAGF,QAAI;AAAiB,aAAO,iCAAiC;AAC7D,WAAO;AAAA;AAET,SAAO;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esm/hierarchy/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hierarchy/index.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './useHierarchyDndkitConfig';\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esm/hierarchy/types.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -1,46 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const useHierarchyActionHandlers =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const onDragStart = useCallback(e => {
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
const useHierarchyActionHandlers = ({
|
|
4
|
+
handlePreviewDragStart,
|
|
5
|
+
handlePreviewDragMove,
|
|
6
|
+
handlePreviewDragEnd,
|
|
7
|
+
handlePreviewDragCancel,
|
|
8
|
+
onReorder,
|
|
9
|
+
dndItems
|
|
10
|
+
}) => {
|
|
11
|
+
const onDragStart = useCallback((e) => {
|
|
13
12
|
handlePreviewDragStart(e);
|
|
14
13
|
}, [handlePreviewDragStart]);
|
|
15
|
-
const onDragMove = useCallback(e => {
|
|
14
|
+
const onDragMove = useCallback((e) => {
|
|
16
15
|
handlePreviewDragMove(e);
|
|
17
16
|
}, [handlePreviewDragMove]);
|
|
18
|
-
const onDragEnd = useCallback(e => {
|
|
17
|
+
const onDragEnd = useCallback((e) => {
|
|
19
18
|
handlePreviewDragEnd(e);
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} = e;
|
|
24
|
-
if (!over) return;
|
|
25
|
-
|
|
19
|
+
const { active, over } = e;
|
|
20
|
+
if (!over)
|
|
21
|
+
return;
|
|
26
22
|
if (active.id !== over.id) {
|
|
27
|
-
const activeIndex = dndItems.findIndex(item => item.id === active.id);
|
|
28
|
-
const overIndex = dndItems.findIndex(item => item.id === over.id);
|
|
23
|
+
const activeIndex = dndItems.findIndex((item) => item.id === active.id);
|
|
24
|
+
const overIndex = dndItems.findIndex((item) => item.id === over.id);
|
|
29
25
|
onReorder(dndItems[activeIndex], {
|
|
30
26
|
targetIndex: overIndex,
|
|
31
27
|
fromIndex: activeIndex
|
|
32
28
|
});
|
|
33
29
|
}
|
|
34
30
|
}, [handlePreviewDragEnd, dndItems, onReorder]);
|
|
35
|
-
const onDragCancel = useCallback(e => {
|
|
31
|
+
const onDragCancel = useCallback((e) => {
|
|
36
32
|
handlePreviewDragCancel(e);
|
|
37
33
|
}, [handlePreviewDragCancel]);
|
|
38
|
-
return {
|
|
39
|
-
onDragStart,
|
|
40
|
-
onDragMove,
|
|
41
|
-
onDragEnd,
|
|
42
|
-
onDragCancel
|
|
43
|
-
};
|
|
34
|
+
return { onDragStart, onDragMove, onDragEnd, onDragCancel };
|
|
44
35
|
};
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
export {
|
|
37
|
+
useHierarchyActionHandlers
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=useHierarchyActionHandlers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hierarchy/useHierarchyActionHandlers.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback } from 'react';\nimport { DragStartEvent, DragMoveEvent, DragEndEvent, DragCancelEvent } from '@dnd-kit/core';\nimport { UseHierarchyActionHandlersReturn, UseHierarchyActionHandlersArgs } from './types';\n\nexport const useHierarchyActionHandlers = ({\n handlePreviewDragStart,\n handlePreviewDragMove,\n handlePreviewDragEnd,\n handlePreviewDragCancel,\n onReorder,\n dndItems,\n}: UseHierarchyActionHandlersArgs): UseHierarchyActionHandlersReturn => {\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 onDragEnd = useCallback(\n (e: DragEndEvent) => {\n handlePreviewDragEnd(e);\n const { active, over } = e;\n\n if (!over) return;\n\n if (active.id !== over.id) {\n const activeIndex = dndItems.findIndex((item) => item.id === active.id);\n const overIndex = dndItems.findIndex((item) => item.id === over.id);\n\n onReorder(dndItems[activeIndex], {\n targetIndex: overIndex,\n fromIndex: activeIndex,\n });\n }\n },\n [handlePreviewDragEnd, dndItems, onReorder],\n );\n\n const onDragCancel = useCallback(\n (e: DragCancelEvent) => {\n handlePreviewDragCancel(e);\n },\n [handlePreviewDragCancel],\n );\n\n return { onDragStart, onDragMove, onDragEnd, onDragCancel };\n};\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AAIO,MAAM,6BAA6B,CAAC;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACsE;AACtE,QAAM,cAAc,YAClB,CAAC,MAAsB;AACrB,2BAAuB;AAAA,KAEzB,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,CAAC;AAAM;AAEX,QAAI,OAAO,OAAO,KAAK,IAAI;AACzB,YAAM,cAAc,SAAS,UAAU,CAAC,SAAS,KAAK,OAAO,OAAO;AACpE,YAAM,YAAY,SAAS,UAAU,CAAC,SAAS,KAAK,OAAO,KAAK;AAEhE,gBAAU,SAAS,cAAc;AAAA,QAC/B,aAAa;AAAA,QACb,WAAW;AAAA;AAAA;AAAA,KAIjB,CAAC,sBAAsB,UAAU;AAGnC,QAAM,eAAe,YACnB,CAAC,MAAuB;AACtB,4BAAwB;AAAA,KAE1B,CAAC;AAGH,SAAO,EAAE,aAAa,YAAY,WAAW;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|