@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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tree/useTreeDndkitConfig.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* 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"],
|
|
5
|
+
"mappings": "AAAA;ACCA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AACA;AACA;AAEA;AACA;AACA;AAIA,MAAM,kBAAkB,CAAC,oBAAuC;AAC9D,QAAM,OAAiB,CAAC,E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4
|
-
const useTreePreviewHandlers =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} = _ref;
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { DropIndicatorPosition } from "./constants";
|
|
4
|
+
const useTreePreviewHandlers = ({
|
|
5
|
+
setOverId,
|
|
6
|
+
setActiveId,
|
|
7
|
+
setDropIndicatorPosition
|
|
8
|
+
}) => {
|
|
10
9
|
const resetState = useCallback(() => {
|
|
11
|
-
setOverId(
|
|
12
|
-
setActiveId(
|
|
13
|
-
document.body.style.setProperty(
|
|
10
|
+
setOverId("");
|
|
11
|
+
setActiveId("");
|
|
12
|
+
document.body.style.setProperty("cursor", "");
|
|
14
13
|
}, [setOverId, setActiveId]);
|
|
15
|
-
const handlePreviewDragStart = useCallback(
|
|
16
|
-
let {
|
|
17
|
-
active: {
|
|
18
|
-
id
|
|
19
|
-
}
|
|
20
|
-
} = _ref2;
|
|
14
|
+
const handlePreviewDragStart = useCallback(({ active: { id } }) => {
|
|
21
15
|
setActiveId(id);
|
|
22
16
|
setOverId(id);
|
|
23
17
|
setDropIndicatorPosition(DropIndicatorPosition.Inside);
|
|
24
|
-
document.body.style.setProperty(
|
|
18
|
+
document.body.style.setProperty("cursor", "grabbing");
|
|
25
19
|
}, [setActiveId, setDropIndicatorPosition, setOverId]);
|
|
26
20
|
const handlePreviewDragMove = useCallback(() => null, []);
|
|
27
|
-
const handlePreviewDragOver = useCallback(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let {
|
|
31
|
-
over
|
|
32
|
-
} = _ref3;
|
|
33
|
-
setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : '');
|
|
21
|
+
const handlePreviewDragOver = useCallback(({ over }) => {
|
|
22
|
+
setOverId(over?.id ?? "");
|
|
34
23
|
}, [setOverId]);
|
|
35
24
|
const handlePreviewDragEnd = useCallback(() => {
|
|
36
25
|
resetState();
|
|
@@ -46,5 +35,7 @@ const useTreePreviewHandlers = _ref => {
|
|
|
46
35
|
handlePreviewDragCancel
|
|
47
36
|
};
|
|
48
37
|
};
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
export {
|
|
39
|
+
useTreePreviewHandlers
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=useTreePreviewHandlers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tree/useTreePreviewHandlers.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "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"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AAGA;AAEO,MAAM,yBAAyB,CAAC;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,MAC8D;AAC9D,QAAM,aAAa,YAAY,MAAM;AACnC,cAAU;AACV,gBAAY;AAEZ,aAAS,KAAK,MAAM,YAAY,UAAU;AAAA,KACzC,CAAC,WAAW;AAEf,QAAM,yBAAyB,YAC7B,CAAC,EAAE,QAAQ,EAAE,WAA2B;AACtC,gBAAY;AACZ,cAAU;AACV,6BAAyB,sBAAsB;AAE/C,aAAS,KAAK,MAAM,YAAY,UAAU;AAAA,KAE5C,CAAC,aAAa,0BAA0B;AAG1C,QAAM,wBAAwB,YAAY,MAAM,MAAM;AAEtD,QAAM,wBAAwB,YAC5B,CAAC,EAAE,WAA0B;AAC3B,cAAU,MAAM,MAAM;AAAA,KAExB,CAAC;AAGH,QAAM,uBAAuB,YAAY,MAAM;AAC7C;AAAA,KACC,CAAC;AAEJ,QAAM,0BAA0B,YAAY,MAAM;AAChD;AAAA,KACC,CAAC;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esm/tree/utilities.js
CHANGED
|
@@ -1,47 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const getMinDepth = item => {
|
|
7
|
-
if (item) return item.depth;
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { DropIndicatorPosition } from "./constants";
|
|
3
|
+
const getMinDepth = (item) => {
|
|
4
|
+
if (item)
|
|
5
|
+
return item.depth;
|
|
8
6
|
return 0;
|
|
9
7
|
};
|
|
10
|
-
|
|
11
8
|
const getProjection = (items, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) => {
|
|
12
9
|
const overItemIndex = visibleItemsDictionary[overId].realIndex;
|
|
13
10
|
const previousItem = items[overItemIndex];
|
|
14
11
|
const nextItem = items[overItemIndex + 1];
|
|
15
|
-
|
|
16
12
|
if (dropIndicatorPosition === DropIndicatorPosition.Inside && isExpandable) {
|
|
17
13
|
return {
|
|
18
14
|
depth: visibleItemsDictionary[overId].depth + 1,
|
|
19
15
|
parentId: overId
|
|
20
16
|
};
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
if (dropIndicatorPosition === DropIndicatorPosition.Before) {
|
|
24
|
-
return {
|
|
25
|
-
depth: getMinDepth(previousItem),
|
|
26
|
-
parentId: previousItem.parentId
|
|
27
|
-
};
|
|
19
|
+
return { depth: getMinDepth(previousItem), parentId: previousItem.parentId };
|
|
28
20
|
}
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
depth: getMinDepth(nextItem),
|
|
32
|
-
parentId: nextItem === null || nextItem === void 0 ? void 0 : nextItem.parentId
|
|
33
|
-
};
|
|
21
|
+
return { depth: getMinDepth(nextItem), parentId: nextItem?.parentId };
|
|
34
22
|
};
|
|
35
23
|
const removeChildrenOf = (items, id) => {
|
|
36
24
|
const excludeParentIds = [id];
|
|
37
|
-
return items.filter(item => {
|
|
25
|
+
return items.filter((item) => {
|
|
38
26
|
if (item.parentId !== null && excludeParentIds.includes(item.parentId)) {
|
|
39
27
|
excludeParentIds.push(item.uid);
|
|
40
28
|
return false;
|
|
41
29
|
}
|
|
42
|
-
|
|
43
30
|
return true;
|
|
44
31
|
});
|
|
45
32
|
};
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
export {
|
|
34
|
+
getProjection,
|
|
35
|
+
removeChildrenOf
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tree/utilities.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* 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"],
|
|
5
|
+
"mappings": "AAAA;ACCA;AAIA,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,sBAAsB,UAAU,cAAc;AAC1E,WAAO;AAAA,MACL,OAAO,uBAAuB,QAAQ,QAAQ;AAAA,MAC9C,UAAU;AAAA;AAAA;AAGd,MAAI,0BAA0B,sBAAsB,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
|
+
}
|
package/package.json
CHANGED
|
@@ -64,7 +64,7 @@ export declare type useHierarchyDndkitConfigReturn = {
|
|
|
64
64
|
overId: string | null;
|
|
65
65
|
activeIndex: number | undefined;
|
|
66
66
|
};
|
|
67
|
-
export declare type
|
|
67
|
+
export declare type GetKeyboardCoordinatesArgs = {
|
|
68
68
|
items: Item[];
|
|
69
69
|
active: Active | null;
|
|
70
70
|
over: Over | null;
|
package/types/tree/types.d.ts
CHANGED
|
@@ -4,12 +4,13 @@ import type { SortingStrategy } from '@dnd-kit/sortable';
|
|
|
4
4
|
import { Coordinates } from '@dnd-kit/core/dist/types';
|
|
5
5
|
import React, { MutableRefObject } from 'react';
|
|
6
6
|
import { DropIndicatorPosition } from './constants';
|
|
7
|
-
export declare type Item = {
|
|
7
|
+
export declare type Item<T = unknown> = {
|
|
8
8
|
uid: string;
|
|
9
9
|
depth: number;
|
|
10
|
-
parentId: string;
|
|
10
|
+
parentId: string | null;
|
|
11
11
|
realIndex: number;
|
|
12
|
-
|
|
12
|
+
childrenCount: number;
|
|
13
|
+
original: T;
|
|
13
14
|
};
|
|
14
15
|
export declare type DndContextPropsType = {
|
|
15
16
|
announcements: Announcements;
|
|
@@ -27,49 +28,51 @@ export declare type SortableContextPropsType = {
|
|
|
27
28
|
items: string[];
|
|
28
29
|
strategy: SortingStrategy;
|
|
29
30
|
};
|
|
30
|
-
export declare type
|
|
31
|
+
export declare type UseTreePreviewHandlersReturn = {
|
|
31
32
|
handlePreviewDragStart: (e: DragStartEvent) => void;
|
|
32
33
|
handlePreviewDragMove: (e: DragMoveEvent) => void;
|
|
33
34
|
handlePreviewDragOver: (e: DragOverEvent) => void;
|
|
34
35
|
handlePreviewDragEnd: (e: DragEndEvent) => void;
|
|
35
36
|
handlePreviewDragCancel: (e: DragCancelEvent) => void;
|
|
36
37
|
};
|
|
37
|
-
export declare type
|
|
38
|
+
export declare type UseTreePreviewHandlersArgs = {
|
|
38
39
|
setOverId: React.Dispatch<React.SetStateAction<string>>;
|
|
39
40
|
setActiveId: React.Dispatch<React.SetStateAction<string>>;
|
|
40
41
|
setDropIndicatorPosition: React.Dispatch<React.SetStateAction<DropIndicatorPosition>>;
|
|
41
42
|
};
|
|
42
|
-
export declare type
|
|
43
|
+
export declare type UseTreeActionHandlersArgs<T = unknown> = UseTreePreviewHandlersReturn & {
|
|
43
44
|
dropIndicatorPosition: DropIndicatorPosition;
|
|
44
45
|
flattenedItems: Item[];
|
|
45
46
|
projected: {
|
|
46
47
|
depth: number;
|
|
47
48
|
parentId: string;
|
|
48
49
|
} | null;
|
|
49
|
-
onReorder: (newData: Item[], indexes: {
|
|
50
|
+
onReorder: <S = T>(newData: Item<S>[], indexes: {
|
|
50
51
|
targetIndex: number;
|
|
51
52
|
fromIndex: number;
|
|
52
53
|
}, considerExpanding: string) => void;
|
|
54
|
+
isDropValid: boolean;
|
|
53
55
|
};
|
|
54
|
-
export declare type
|
|
56
|
+
export declare type UseTreeActionHandlersReturn = {
|
|
55
57
|
onDragStart: (e: DragStartEvent) => void;
|
|
56
58
|
onDragMove: (e: DragMoveEvent) => void;
|
|
57
59
|
onDragOver: (e: DragOverEvent) => void;
|
|
58
60
|
onDragEnd: (e: DragEndEvent) => void;
|
|
59
61
|
onDragCancel: (e: DragCancelEvent) => void;
|
|
60
62
|
};
|
|
61
|
-
export declare type
|
|
63
|
+
export declare type UseTreeDndkitConfigArgs<T> = {
|
|
62
64
|
flattenedItems: Item[];
|
|
63
65
|
visibleItems: Item[];
|
|
64
66
|
isHorizontalDnD?: boolean;
|
|
65
67
|
isExpandable: boolean;
|
|
66
|
-
onReorder: (newData: Item[], indexes: {
|
|
68
|
+
onReorder: <S = T>(newData: Item<S>[], indexes: {
|
|
67
69
|
targetIndex: number;
|
|
68
70
|
fromIndex: number;
|
|
69
71
|
}, considerExpanding: string) => void;
|
|
72
|
+
getIsDropValid: <S = T>(active: Item<S>, over: Item<S>, dropIndicatorPosition: 'none' | 'before' | 'after' | 'inside') => boolean;
|
|
70
73
|
maxDragAndDropLevel: number;
|
|
71
74
|
};
|
|
72
|
-
export declare type
|
|
75
|
+
export declare type UseTreeDndkitConfigReturn = {
|
|
73
76
|
dndContextProps: DndContextPropsType;
|
|
74
77
|
sortableContextProps: SortableContextPropsType;
|
|
75
78
|
activeId: string;
|
|
@@ -77,10 +80,11 @@ export declare type useTreeDndkitConfigReturn = {
|
|
|
77
80
|
overId: string;
|
|
78
81
|
depth: number;
|
|
79
82
|
dropIndicatorPosition: DropIndicatorPosition;
|
|
83
|
+
isDropValid: boolean;
|
|
80
84
|
visibleItems: Item[];
|
|
81
85
|
};
|
|
82
|
-
export declare type
|
|
83
|
-
export declare type
|
|
86
|
+
export declare type UseTreeDndkitConfigType = <T = unknown>(args: UseTreeDndkitConfigArgs<T>) => UseTreeDndkitConfigReturn;
|
|
87
|
+
export declare type GetKeyboardCoordinatesArgs = {
|
|
84
88
|
items: Item[];
|
|
85
89
|
active: Active;
|
|
86
90
|
over: Over;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const useTreeActionHandlers: ({ handlePreviewDragStart, handlePreviewDragMove, handlePreviewDragOver, handlePreviewDragEnd, handlePreviewDragCancel, onReorder, flattenedItems, projected, dropIndicatorPosition, }:
|
|
1
|
+
import type { UseTreeActionHandlersReturn, UseTreeActionHandlersArgs } from './types';
|
|
2
|
+
export declare const useTreeActionHandlers: ({ handlePreviewDragStart, handlePreviewDragMove, handlePreviewDragOver, handlePreviewDragEnd, handlePreviewDragCancel, onReorder, flattenedItems, projected, dropIndicatorPosition, isDropValid, }: UseTreeActionHandlersArgs) => UseTreeActionHandlersReturn;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const useTreeDndkitConfig:
|
|
1
|
+
import type { UseTreeDndkitConfigType } from './types';
|
|
2
|
+
export declare const useTreeDndkitConfig: UseTreeDndkitConfigType;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const useTreePreviewHandlers: ({ setOverId, setActiveId, setDropIndicatorPosition, }:
|
|
1
|
+
import type { UseTreePreviewHandlersReturn, UseTreePreviewHandlersArgs } from './types';
|
|
2
|
+
export declare const useTreePreviewHandlers: ({ setOverId, setActiveId, setDropIndicatorPosition, }: UseTreePreviewHandlersArgs) => UseTreePreviewHandlersReturn;
|