@elliemae/ds-drag-and-drop 2.3.0-alpha.2 → 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/types.js.map +1 -1
- package/cjs/tree/customCollisionDetection.js +56 -53
- package/cjs/tree/customCollisionDetection.js.map +2 -2
- package/cjs/tree/getTreeKeyboardCoordinates.js +0 -1
- package/cjs/tree/getTreeKeyboardCoordinates.js.map +2 -2
- package/cjs/tree/types.js.map +1 -1
- package/cjs/tree/useTreeActionHandlers.js +5 -4
- package/cjs/tree/useTreeActionHandlers.js.map +2 -2
- package/cjs/tree/useTreeDndkitConfig.js +24 -14
- package/cjs/tree/useTreeDndkitConfig.js.map +2 -2
- package/cjs/tree/useTreePreviewHandlers.js.map +1 -1
- package/esm/tree/customCollisionDetection.js +56 -53
- package/esm/tree/customCollisionDetection.js.map +2 -2
- package/esm/tree/getTreeKeyboardCoordinates.js +0 -1
- package/esm/tree/getTreeKeyboardCoordinates.js.map +2 -2
- package/esm/tree/useTreeActionHandlers.js +5 -4
- package/esm/tree/useTreeActionHandlers.js.map +2 -2
- package/esm/tree/useTreeDndkitConfig.js +24 -14
- package/esm/tree/useTreeDndkitConfig.js.map +2 -2
- package/esm/tree/useTreePreviewHandlers.js.map +1 -1
- 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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hierarchy/types.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import type {\n Active,\n Announcements,\n CollisionDetection,\n DragEndEvent,\n DragMoveEvent,\n DragOverEvent,\n DragStartEvent,\n MeasuringConfiguration,\n Modifier,\n Over,\n SensorDescriptor,\n SensorOptions,\n} from '@dnd-kit/core';\nimport { DroppableContainers } from '@dnd-kit/core/dist/store';\nimport { Coordinates, DragCancelEvent, ViewRect } from '@dnd-kit/core/dist/types';\nimport { MutableRefObject } from 'react';\n\nexport type Item = {\n id: string;\n depth: number;\n parentId: string;\n index: number;\n};\n\nexport type DndContextPropsType = {\n announcements: Announcements;\n modifiers: Modifier[];\n sensors: SensorDescriptor<SensorOptions>[];\n measuring: Partial<MeasuringConfiguration>;\n collisionDetection: CollisionDetection;\n onDragStart: (e: DragStartEvent) => void;\n onDragMove: (e: DragMoveEvent) => void;\n onDragOver: (e: DragOverEvent) => void;\n onDragEnd: (e: DragEndEvent) => void;\n onDragCancel: (e: DragCancelEvent) => void;\n};\n\nexport type useHierarchyPreviewHandlersReturn = {\n handlePreviewDragStart: (e: DragStartEvent) => void;\n handlePreviewDragMove: (e: DragMoveEvent) => void;\n handlePreviewDragEnd: (e: DragEndEvent) => void;\n handlePreviewDragCancel: (e: DragCancelEvent) => void;\n};\n\nexport type useHierarchyPreviewHandlersArgs = {\n setActiveId: React.Dispatch<React.SetStateAction<string>>;\n onPreviewResetState: () => void;\n onPreviewDragStart: () => void;\n};\n\nexport type useHierarchyActionHandlersArgs = useHierarchyPreviewHandlersReturn & {\n dndItems: Item[];\n onReorder: (movedItem: Item, indexes: { targetIndex: number; fromIndex: number }) => void;\n};\n\nexport type useHierarchyActionHandlersReturn = {\n onDragStart: (e: DragStartEvent) => void;\n onDragMove: (e: DragMoveEvent) => void;\n onDragOver: (e: DragOverEvent) => void;\n onDragEnd: (e: DragEndEvent) => void;\n onDragCancel: (e: DragCancelEvent) => void;\n};\n\nexport type useHierarchyDndkitConfigArgs = {\n indentationWidth?: number;\n dragOverlayDataTestid: string;\n flattenedItems: [Item, unknown][];\n isHorizontalDnD?: boolean;\n onReorder: (movedItem: Item, indexes: { targetIndex: number; fromIndex: number }) => void;\n onPreviewResetState: () => void;\n onPreviewDragStart: () => void;\n};\n\nexport type useHierarchyDndkitConfigType = (args: useHierarchyDndkitConfigArgs) => useHierarchyDndkitConfigReturn;\n\nexport type useHierarchyDndkitConfigReturn = {\n dndContextProps: DndContextPropsType;\n activeId: string | null;\n overId: string | null;\n activeIndex: number | undefined;\n};\n\nexport type
|
|
4
|
+
"sourcesContent": ["import type {\n Active,\n Announcements,\n CollisionDetection,\n DragEndEvent,\n DragMoveEvent,\n DragOverEvent,\n DragStartEvent,\n MeasuringConfiguration,\n Modifier,\n Over,\n SensorDescriptor,\n SensorOptions,\n} from '@dnd-kit/core';\nimport { DroppableContainers } from '@dnd-kit/core/dist/store';\nimport { Coordinates, DragCancelEvent, ViewRect } from '@dnd-kit/core/dist/types';\nimport { MutableRefObject } from 'react';\n\nexport type Item = {\n id: string;\n depth: number;\n parentId: string;\n index: number;\n};\n\nexport type DndContextPropsType = {\n announcements: Announcements;\n modifiers: Modifier[];\n sensors: SensorDescriptor<SensorOptions>[];\n measuring: Partial<MeasuringConfiguration>;\n collisionDetection: CollisionDetection;\n onDragStart: (e: DragStartEvent) => void;\n onDragMove: (e: DragMoveEvent) => void;\n onDragOver: (e: DragOverEvent) => void;\n onDragEnd: (e: DragEndEvent) => void;\n onDragCancel: (e: DragCancelEvent) => void;\n};\n\nexport type useHierarchyPreviewHandlersReturn = {\n handlePreviewDragStart: (e: DragStartEvent) => void;\n handlePreviewDragMove: (e: DragMoveEvent) => void;\n handlePreviewDragEnd: (e: DragEndEvent) => void;\n handlePreviewDragCancel: (e: DragCancelEvent) => void;\n};\n\nexport type useHierarchyPreviewHandlersArgs = {\n setActiveId: React.Dispatch<React.SetStateAction<string>>;\n onPreviewResetState: () => void;\n onPreviewDragStart: () => void;\n};\n\nexport type useHierarchyActionHandlersArgs = useHierarchyPreviewHandlersReturn & {\n dndItems: Item[];\n onReorder: (movedItem: Item, indexes: { targetIndex: number; fromIndex: number }) => void;\n};\n\nexport type useHierarchyActionHandlersReturn = {\n onDragStart: (e: DragStartEvent) => void;\n onDragMove: (e: DragMoveEvent) => void;\n onDragOver: (e: DragOverEvent) => void;\n onDragEnd: (e: DragEndEvent) => void;\n onDragCancel: (e: DragCancelEvent) => void;\n};\n\nexport type useHierarchyDndkitConfigArgs = {\n indentationWidth?: number;\n dragOverlayDataTestid: string;\n flattenedItems: [Item, unknown][];\n isHorizontalDnD?: boolean;\n onReorder: (movedItem: Item, indexes: { targetIndex: number; fromIndex: number }) => void;\n onPreviewResetState: () => void;\n onPreviewDragStart: () => void;\n};\n\nexport type useHierarchyDndkitConfigType = (args: useHierarchyDndkitConfigArgs) => useHierarchyDndkitConfigReturn;\n\nexport type useHierarchyDndkitConfigReturn = {\n dndContextProps: DndContextPropsType;\n activeId: string | null;\n overId: string | null;\n activeIndex: number | undefined;\n};\n\nexport type GetKeyboardCoordinatesArgs = {\n items: Item[];\n active: Active | null;\n over: Over | null;\n event: KeyboardEvent;\n currentCoordinates: Coordinates;\n droppableContainers: DroppableContainers;\n collisionRect: ViewRect;\n dragOverlayDataTestid: string;\n};\n\nexport type SensorContext = MutableRefObject<{\n items: Item[];\n offset?: number;\n}>;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA,YAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -46,61 +46,64 @@ const RECT_DOWN = {
|
|
|
46
46
|
};
|
|
47
47
|
const thresholdRatio = 0.2;
|
|
48
48
|
const insideThreshold = 0.7;
|
|
49
|
-
const customCollisionDetection = (activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition) =>
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
const customCollisionDetection = (activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition) => {
|
|
50
|
+
const func = ({ droppableContainers, collisionRect }) => {
|
|
51
|
+
const originalContainer = droppableContainers.find(({ id }) => id === activeId);
|
|
52
|
+
const originalRect = originalContainer?.rect?.current;
|
|
53
|
+
let isUp = lastPosition === "up";
|
|
54
|
+
if (originalRect) {
|
|
55
|
+
isUp = originalRect.offsetTop > collisionRect.top;
|
|
56
|
+
}
|
|
57
|
+
const threshold = collisionRect.height * thresholdRatio;
|
|
58
|
+
let collidingContainer = null;
|
|
59
|
+
if (isUp) {
|
|
60
|
+
collidingContainer = droppableContainers.reduce((firstRectDown, container) => {
|
|
61
|
+
const rect = container.rect.current;
|
|
62
|
+
if (rect && firstRectDown.rect.current) {
|
|
63
|
+
const { offsetTop: rectOffsetTop } = rect;
|
|
64
|
+
const { offsetTop: firstRectDownOffsetTop } = firstRectDown.rect.current;
|
|
65
|
+
if (rectOffsetTop + threshold > collisionRect.top && rectOffsetTop < firstRectDownOffsetTop) {
|
|
66
|
+
return container;
|
|
67
|
+
}
|
|
66
68
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
return firstRectDown;
|
|
70
|
+
}, { id: DUMMY_ID, rect: { current: RECT_DOWN } });
|
|
71
|
+
} else {
|
|
72
|
+
collidingContainer = droppableContainers.reduce((firstRectUp, container) => {
|
|
73
|
+
const rect = container.rect.current;
|
|
74
|
+
if (rect && firstRectUp.rect.current) {
|
|
75
|
+
const { offsetTop: rectOffsetTop } = rect;
|
|
76
|
+
const { offsetTop: firstRectUpOffsetTop } = firstRectUp.rect.current;
|
|
77
|
+
if (rectOffsetTop - threshold < collisionRect.top && rectOffsetTop > firstRectUpOffsetTop) {
|
|
78
|
+
return container;
|
|
79
|
+
}
|
|
78
80
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
81
|
+
return firstRectUp;
|
|
82
|
+
}, { id: DUMMY_ID, rect: { current: RECT_UP } });
|
|
83
|
+
}
|
|
84
|
+
if (collidingContainer.id === DUMMY_ID) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const collidingRect = collidingContainer.rect.current;
|
|
88
|
+
if (!collidingRect)
|
|
89
|
+
return null;
|
|
90
|
+
const [top, bottom] = [
|
|
91
|
+
Math.max(collisionRect.top, collidingRect.offsetTop),
|
|
92
|
+
Math.min(collisionRect.top + collisionRect.height, collidingRect.offsetTop + collidingRect.height)
|
|
93
|
+
];
|
|
94
|
+
const intersectionPercentage = Math.abs(bottom - top) / collidingRect.height;
|
|
95
|
+
if (intersectionPercentage > insideThreshold && visibleItemsDictionary[collidingContainer.id].depth + 1 <= maxDragAndDropLevel && collidingContainer.id !== activeId) {
|
|
96
|
+
setDropIndicatorPosition(import_constants.DropIndicatorPosition.Inside);
|
|
97
|
+
} else {
|
|
98
|
+
setDropIndicatorPosition(isUp ? import_constants.DropIndicatorPosition.Before : import_constants.DropIndicatorPosition.After);
|
|
99
|
+
}
|
|
100
|
+
if (isUp && lastPosition !== "up")
|
|
101
|
+
setLastPosition("up");
|
|
102
|
+
else if (!isUp && lastPosition !== "down")
|
|
103
|
+
setLastPosition("down");
|
|
104
|
+
return collidingContainer.id;
|
|
105
|
+
};
|
|
106
|
+
return func;
|
|
104
107
|
};
|
|
105
108
|
module.exports = __toCommonJS(customCollisionDetection_exports);
|
|
106
109
|
//# sourceMappingURL=customCollisionDetection.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tree/customCollisionDetection.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/indent */\n/* eslint-disable max-params */\nimport { CollisionDetection, DroppableContainer, LayoutRect } from '@dnd-kit/core';\nimport { DropIndicatorPosition } from './constants';\nimport { Item } from './types';\n\nconst DUMMY_ID = 'DUMMY_ID_INTERNAL_USE_ONLY';\nconst RECT_UP: LayoutRect = {\n offsetTop: -Infinity,\n offsetLeft: 0, // Doesn't matter,\n width: 0, // Doesn't matter\n height: 0, // Doesn't matter\n};\nconst RECT_DOWN: LayoutRect = {\n offsetTop: Infinity,\n offsetLeft: 0, // Doesn't matter,\n width: 0, // Doesn't matter\n height: 0, // Doesn't matter\n};\n\n// Percentage of height to take into consideration when looking for colliding rects\nconst thresholdRatio = 0.2;\n// Percentage to be inside\nconst insideThreshold = 0.7;\n\nexport const customCollisionDetection
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-statements */\n/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/indent */\n/* eslint-disable max-params */\nimport { CollisionDetection, DroppableContainer, LayoutRect } from '@dnd-kit/core';\nimport { DropIndicatorPosition } from './constants';\nimport { Item } from './types';\n\nconst DUMMY_ID = 'DUMMY_ID_INTERNAL_USE_ONLY';\nconst RECT_UP: LayoutRect = {\n offsetTop: -Infinity,\n offsetLeft: 0, // Doesn't matter,\n width: 0, // Doesn't matter\n height: 0, // Doesn't matter\n};\nconst RECT_DOWN: LayoutRect = {\n offsetTop: Infinity,\n offsetLeft: 0, // Doesn't matter,\n width: 0, // Doesn't matter\n height: 0, // Doesn't matter\n};\n\n// Percentage of height to take into consideration when looking for colliding rects\nconst thresholdRatio = 0.2;\n// Percentage to be inside\nconst insideThreshold = 0.7;\n\nexport const customCollisionDetection = (\n activeId: string,\n visibleItemsDictionary: Record<string, Item>,\n setDropIndicatorPosition: React.Dispatch<React.SetStateAction<DropIndicatorPosition>>,\n maxDragAndDropLevel: number,\n lastPosition: string,\n setLastPosition: React.Dispatch<React.SetStateAction<string>>,\n): CollisionDetection => {\n const func: CollisionDetection = ({ droppableContainers, collisionRect }) => {\n const originalContainer = droppableContainers.find(({ id }) => id === activeId);\n const originalRect = originalContainer?.rect?.current;\n\n // We first check if the item was moved up or down\n // This modifies how to search the matching colliding rect\n let isUp = lastPosition === 'up';\n if (originalRect) {\n isUp = originalRect.offsetTop > collisionRect.top;\n }\n\n // Threshold\n const threshold = collisionRect.height * thresholdRatio;\n\n let collidingContainer: DroppableContainer | null = null;\n\n if (isUp) {\n // Up -- We need to find the first rectangle downwards\n collidingContainer = droppableContainers.reduce(\n (firstRectDown, container) => {\n const rect = container.rect.current;\n if (rect && firstRectDown.rect.current) {\n const { offsetTop: rectOffsetTop } = rect;\n const { offsetTop: firstRectDownOffsetTop } = firstRectDown.rect.current;\n if (rectOffsetTop + threshold > collisionRect.top && rectOffsetTop < firstRectDownOffsetTop) {\n return container;\n }\n }\n return firstRectDown;\n },\n { id: DUMMY_ID, rect: { current: RECT_DOWN } } as DroppableContainer,\n );\n } else {\n // Down -- We need to find the first rectangle upwards\n collidingContainer = droppableContainers.reduce(\n (firstRectUp, container) => {\n const rect = container.rect.current;\n if (rect && firstRectUp.rect.current) {\n const { offsetTop: rectOffsetTop } = rect;\n const { offsetTop: firstRectUpOffsetTop } = firstRectUp.rect.current;\n if (rectOffsetTop - threshold < collisionRect.top && rectOffsetTop > firstRectUpOffsetTop) {\n return container;\n }\n }\n return firstRectUp;\n },\n { id: DUMMY_ID, rect: { current: RECT_UP } } as DroppableContainer,\n );\n }\n\n // If we didn't find a match, return null\n if (collidingContainer.id === DUMMY_ID) {\n return null;\n }\n\n const collidingRect = collidingContainer.rect.current;\n\n if (!collidingRect) return null;\n\n // Calculate the intersection interval\n const [top, bottom] = [\n Math.max(collisionRect.top, collidingRect.offsetTop),\n Math.min(collisionRect.top + collisionRect.height, collidingRect.offsetTop + collidingRect.height),\n ];\n\n // Calculate the percentage of intersection\n const intersectionPercentage = Math.abs(bottom - top) / collidingRect.height;\n\n if (\n intersectionPercentage > insideThreshold &&\n visibleItemsDictionary[collidingContainer.id].depth + 1 <= maxDragAndDropLevel &&\n collidingContainer.id !== activeId\n ) {\n setDropIndicatorPosition(DropIndicatorPosition.Inside);\n } else {\n setDropIndicatorPosition(isUp ? DropIndicatorPosition.Before : DropIndicatorPosition.After);\n }\n\n if (isUp && lastPosition !== 'up') setLastPosition('up');\n else if (!isUp && lastPosition !== 'down') setLastPosition('down');\n\n // Return the id of the match rectangle\n return collidingContainer.id;\n };\n return func;\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADKvB,uBAAsC;AAGtC,MAAM,WAAW;AACjB,MAAM,UAAsB;AAAA,EAC1B,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,QAAQ;AAAA;AAEV,MAAM,YAAwB;AAAA,EAC5B,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,QAAQ;AAAA;AAIV,MAAM,iBAAiB;AAEvB,MAAM,kBAAkB;AAEjB,MAAM,2BAA2B,CACtC,UACA,wBACA,0BACA,qBACA,cACA,oBACuB;AACvB,QAAM,OAA2B,CAAC,EAAE,qBAAqB,oBAAoB;AAC3E,UAAM,oBAAoB,oBAAoB,KAAK,CAAC,EAAE,SAAS,OAAO;AACtE,UAAM,eAAe,mBAAmB,MAAM;AAI9C,QAAI,OAAO,iBAAiB;AAC5B,QAAI,cAAc;AAChB,aAAO,aAAa,YAAY,cAAc;AAAA;AAIhD,UAAM,YAAY,cAAc,SAAS;AAEzC,QAAI,qBAAgD;AAEpD,QAAI,MAAM;AAER,2BAAqB,oBAAoB,OACvC,CAAC,eAAe,cAAc;AAC5B,cAAM,OAAO,UAAU,KAAK;AAC5B,YAAI,QAAQ,cAAc,KAAK,SAAS;AACtC,gBAAM,EAAE,WAAW,kBAAkB;AACrC,gBAAM,EAAE,WAAW,2BAA2B,cAAc,KAAK;AACjE,cAAI,gBAAgB,YAAY,cAAc,OAAO,gBAAgB,wBAAwB;AAC3F,mBAAO;AAAA;AAAA;AAGX,eAAO;AAAA,SAET,EAAE,IAAI,UAAU,MAAM,EAAE,SAAS;AAAA,WAE9B;AAEL,2BAAqB,oBAAoB,OACvC,CAAC,aAAa,cAAc;AAC1B,cAAM,OAAO,UAAU,KAAK;AAC5B,YAAI,QAAQ,YAAY,KAAK,SAAS;AACpC,gBAAM,EAAE,WAAW,kBAAkB;AACrC,gBAAM,EAAE,WAAW,yBAAyB,YAAY,KAAK;AAC7D,cAAI,gBAAgB,YAAY,cAAc,OAAO,gBAAgB,sBAAsB;AACzF,mBAAO;AAAA;AAAA;AAGX,eAAO;AAAA,SAET,EAAE,IAAI,UAAU,MAAM,EAAE,SAAS;AAAA;AAKrC,QAAI,mBAAmB,OAAO,UAAU;AACtC,aAAO;AAAA;AAGT,UAAM,gBAAgB,mBAAmB,KAAK;AAE9C,QAAI,CAAC;AAAe,aAAO;AAG3B,UAAM,CAAC,KAAK,UAAU;AAAA,MACpB,KAAK,IAAI,cAAc,KAAK,cAAc;AAAA,MAC1C,KAAK,IAAI,cAAc,MAAM,cAAc,QAAQ,cAAc,YAAY,cAAc;AAAA;AAI7F,UAAM,yBAAyB,KAAK,IAAI,SAAS,OAAO,cAAc;AAEtE,QACE,yBAAyB,mBACzB,uBAAuB,mBAAmB,IAAI,QAAQ,KAAK,uBAC3D,mBAAmB,OAAO,UAC1B;AACA,+BAAyB,uCAAsB;AAAA,WAC1C;AACL,+BAAyB,OAAO,uCAAsB,SAAS,uCAAsB;AAAA;AAGvF,QAAI,QAAQ,iBAAiB;AAAM,sBAAgB;AAAA,aAC1C,CAAC,QAAQ,iBAAiB;AAAQ,sBAAgB;AAG3D,WAAO,mBAAmB;AAAA;AAE5B,SAAO;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -34,7 +34,6 @@ var import_core = require("@dnd-kit/core");
|
|
|
34
34
|
var import_constants = require("./constants");
|
|
35
35
|
const directions = [import_core.KeyboardCode.Down, import_core.KeyboardCode.Right, import_core.KeyboardCode.Up, import_core.KeyboardCode.Left];
|
|
36
36
|
const horizontal = [import_core.KeyboardCode.Left, import_core.KeyboardCode.Right];
|
|
37
|
-
const vertical = [import_core.KeyboardCode.Up, import_core.KeyboardCode.Down];
|
|
38
37
|
const getVerticalKeyboardCoordinates = ({
|
|
39
38
|
items,
|
|
40
39
|
active,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tree/getTreeKeyboardCoordinates.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable complexity */\nimport { closestCorners, getViewRect, KeyboardCode, KeyboardCoordinateGetter, DroppableContainer } from '@dnd-kit/core';\nimport { Coordinates } from '@dnd-kit/core/dist/types';\nimport type { GetKeyboardCoordinatesArgs, SensorContext } from './types';\nimport { DropIndicatorPosition } from './constants';\n\nconst directions: string[] = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];\n\nconst horizontal: string[] = [KeyboardCode.Left, KeyboardCode.Right];\n\nconst getVerticalKeyboardCoordinates = ({\n items,\n active,\n over,\n event,\n currentCoordinates,\n droppableContainers,\n collisionRect,\n dropIndicatorPosition,\n maxDragAndDropLevel,\n}: GetKeyboardCoordinatesArgs): Coordinates | undefined => {\n if (horizontal.includes(event.code)) return undefined;\n\n const overRect = over.rect;\n\n const layoutRects: DroppableContainer[] = [];\n\n // Get the reacheable rects depending on the arrow key pressed\n droppableContainers.forEach((container) => {\n if (container?.disabled || !overRect) {\n return;\n }\n const rect = container.rect.current;\n if (rect && event.code === KeyboardCode.Down && collisionRect.top - 2 <= rect.offsetTop) {\n layoutRects.push(container);\n } else if (rect && event.code === KeyboardCode.Up && collisionRect.top >= rect.offsetTop) {\n layoutRects.push(container);\n }\n });\n\n const closestId = closestCorners({\n collisionRect,\n droppableContainers: layoutRects,\n active,\n });\n\n const closestItem = items.find((item) => item.uid === closestId);\n\n const closestElement = droppableContainers.get(closestId)?.node?.current;\n\n if (!closestId || !closestItem || !closestElement) return undefined;\n\n const closestRect = getViewRect(closestElement);\n\n if (event.code === KeyboardCode.Up) {\n // If the drop indicator is inside (or over ourselves)\n // We are gonna go to the before position\n // Else we are gonna go inside the over rect\n if (\n dropIndicatorPosition === DropIndicatorPosition.Inside ||\n closestId === active.id ||\n closestItem.depth + 1 > maxDragAndDropLevel\n ) {\n return {\n ...currentCoordinates,\n y: closestRect.top - collisionRect.height / 2,\n };\n }\n return {\n ...currentCoordinates,\n y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2,\n };\n }\n // If the drop indicator is inside (or over ourselves)\n // We are gonna go to the after position\n // Else we are gonna go inside the over rect\n if (\n dropIndicatorPosition === DropIndicatorPosition.Inside ||\n closestId === active.id ||\n closestItem.depth + 1 > maxDragAndDropLevel\n ) {\n return {\n ...currentCoordinates,\n y: closestRect.top + collisionRect.height / 2,\n };\n }\n return {\n ...currentCoordinates,\n y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2,\n };\n};\n\nexport const getTreeKeyboardCoordinates: (\n context: SensorContext,\n isHorizontalDnD: boolean,\n maxDragAndDropLevel: number,\n) => KeyboardCoordinateGetter =\n (context, isHorizontalDnD, maxDragAndDropLevel) =>\n (event, { currentCoordinates, context: { over, translatedRect, droppableContainers, active, collisionRect } }) => {\n if (directions.includes(event.code)) {\n if (!translatedRect) {\n return undefined;\n }\n\n const {\n current: { items, dropIndicatorPosition },\n } = context;\n\n if (!over || !active || !collisionRect) return undefined;\n\n const args = {\n items,\n active,\n over,\n event,\n currentCoordinates,\n droppableContainers,\n collisionRect,\n dropIndicatorPosition,\n maxDragAndDropLevel,\n };\n\n if (isHorizontalDnD) return undefined;\n return getVerticalKeyboardCoordinates(args);\n }\n return undefined;\n };\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,kBAAwG;AAGxG,uBAAsC;AAEtC,MAAM,aAAuB,CAAC,yBAAa,MAAM,yBAAa,OAAO,yBAAa,IAAI,yBAAa;AAEnG,MAAM,aAAuB,CAAC,yBAAa,MAAM,yBAAa;AAE9D,MAAM,iCAAiC,CAAC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACyD;AACzD,MAAI,WAAW,SAAS,MAAM;AAAO,WAAO;AAE5C,QAAM,WAAW,KAAK;AAEtB,QAAM,cAAoC;AAG1C,sBAAoB,QAAQ,CAAC,cAAc;AACzC,QAAI,WAAW,YAAY,CAAC,UAAU;AACpC;AAAA;AAEF,UAAM,OAAO,UAAU,KAAK;AAC5B,QAAI,QAAQ,MAAM,SAAS,yBAAa,QAAQ,cAAc,MAAM,KAAK,KAAK,WAAW;AACvF,kBAAY,KAAK;AAAA,eACR,QAAQ,MAAM,SAAS,yBAAa,MAAM,cAAc,OAAO,KAAK,WAAW;AACxF,kBAAY,KAAK;AAAA;AAAA;AAIrB,QAAM,YAAY,gCAAe;AAAA,IAC/B;AAAA,IACA,qBAAqB;AAAA,IACrB;AAAA;AAGF,QAAM,cAAc,MAAM,KAAK,CAAC,SAAS,KAAK,QAAQ;AAEtD,QAAM,iBAAiB,oBAAoB,IAAI,YAAY,MAAM;AAEjE,MAAI,CAAC,aAAa,CAAC,eAAe,CAAC;AAAgB,WAAO;AAE1D,QAAM,cAAc,6BAAY;AAEhC,MAAI,MAAM,SAAS,yBAAa,IAAI;AAIlC,QACE,0BAA0B,uCAAsB,UAChD,cAAc,OAAO,MACrB,YAAY,QAAQ,IAAI,qBACxB;AACA,aAAO;AAAA,WACF;AAAA,QACH,GAAG,YAAY,MAAM,cAAc,SAAS;AAAA;AAAA;AAGhD,WAAO;AAAA,SACF;AAAA,MACH,GAAG,YAAY,MAAM,KAAK,IAAI,YAAY,SAAS,cAAc,UAAU;AAAA;AAAA;AAM/E,MACE,0BAA0B,uCAAsB,UAChD,cAAc,OAAO,MACrB,YAAY,QAAQ,IAAI,qBACxB;AACA,WAAO;AAAA,SACF;AAAA,MACH,GAAG,YAAY,MAAM,cAAc,SAAS;AAAA;AAAA;AAGhD,SAAO;AAAA,OACF;AAAA,IACH,GAAG,YAAY,MAAM,KAAK,IAAI,YAAY,SAAS,cAAc,UAAU;AAAA;AAAA;AAIxE,MAAM,6BAKX,CAAC,SAAS,iBAAiB,wBAC3B,CAAC,OAAO,EAAE,oBAAoB,SAAS,EAAE,MAAM,gBAAgB,qBAAqB,QAAQ,sBAAsB;AAChH,MAAI,WAAW,SAAS,MAAM,OAAO;AACnC,QAAI,CAAC,gBAAgB;AACnB,aAAO;AAAA;AAGT,UAAM;AAAA,MACJ,SAAS,EAAE,OAAO;AAAA,QAChB;AAEJ,QAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;AAAe,aAAO;AAE/C,UAAM,OAAO;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAGF,QAAI;AAAiB,aAAO;AAC5B,WAAO,+BAA+B;AAAA;AAExC,SAAO;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/cjs/tree/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tree/types.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import {\n Active,\n Announcements,\n CollisionDetection,\n DragCancelEvent,\n DragEndEvent,\n DragMoveEvent,\n DragOverEvent,\n DragStartEvent,\n DroppableContainers,\n MeasuringConfiguration,\n Modifier,\n Over,\n ViewRect,\n} from '@dnd-kit/core';\nimport type { SensorDescriptor, SensorOptions } from '@dnd-kit/core/dist/sensors';\nimport type { SortingStrategy } from '@dnd-kit/sortable';\nimport { Coordinates } from '@dnd-kit/core/dist/types';\nimport React, { MutableRefObject } from 'react';\nimport { DropIndicatorPosition } from './constants';\n\nexport type Item = {\n uid: string;\n depth: number;\n parentId: string;\n realIndex: number;\n original:
|
|
4
|
+
"sourcesContent": ["import {\n Active,\n Announcements,\n CollisionDetection,\n DragCancelEvent,\n DragEndEvent,\n DragMoveEvent,\n DragOverEvent,\n DragStartEvent,\n DroppableContainers,\n MeasuringConfiguration,\n Modifier,\n Over,\n ViewRect,\n} from '@dnd-kit/core';\nimport type { SensorDescriptor, SensorOptions } from '@dnd-kit/core/dist/sensors';\nimport type { SortingStrategy } from '@dnd-kit/sortable';\nimport { Coordinates } from '@dnd-kit/core/dist/types';\nimport React, { MutableRefObject } from 'react';\nimport { DropIndicatorPosition } from './constants';\n\nexport type Item<T = unknown> = {\n uid: string;\n depth: number;\n parentId: string | null;\n realIndex: number;\n childrenCount: number;\n original: T;\n};\n\nexport type DndContextPropsType = {\n announcements: Announcements;\n modifiers: Modifier[];\n sensors: SensorDescriptor<SensorOptions>[];\n measuring: Partial<MeasuringConfiguration>;\n collisionDetection: CollisionDetection;\n onDragStart: (e: DragStartEvent) => void;\n onDragMove: (e: DragMoveEvent) => void;\n onDragOver: (e: DragOverEvent) => void;\n onDragEnd: (e: DragEndEvent) => void;\n onDragCancel: (e: DragCancelEvent) => void;\n};\n\nexport type SortableContextPropsType = {\n items: string[];\n strategy: SortingStrategy;\n};\n\nexport type UseTreePreviewHandlersReturn = {\n handlePreviewDragStart: (e: DragStartEvent) => void;\n handlePreviewDragMove: (e: DragMoveEvent) => void;\n handlePreviewDragOver: (e: DragOverEvent) => void;\n handlePreviewDragEnd: (e: DragEndEvent) => void;\n handlePreviewDragCancel: (e: DragCancelEvent) => void;\n};\nexport type UseTreePreviewHandlersArgs = {\n setOverId: React.Dispatch<React.SetStateAction<string>>;\n setActiveId: React.Dispatch<React.SetStateAction<string>>;\n setDropIndicatorPosition: React.Dispatch<React.SetStateAction<DropIndicatorPosition>>;\n};\n\nexport type UseTreeActionHandlersArgs<T = unknown> = UseTreePreviewHandlersReturn & {\n dropIndicatorPosition: DropIndicatorPosition;\n flattenedItems: Item[];\n projected: {\n depth: number;\n parentId: string;\n } | null;\n onReorder: <S = T>(\n newData: Item<S>[],\n indexes: { targetIndex: number; fromIndex: number },\n considerExpanding: string,\n ) => void;\n isDropValid: boolean;\n};\n\nexport type UseTreeActionHandlersReturn = {\n onDragStart: (e: DragStartEvent) => void;\n onDragMove: (e: DragMoveEvent) => void;\n onDragOver: (e: DragOverEvent) => void;\n onDragEnd: (e: DragEndEvent) => void;\n onDragCancel: (e: DragCancelEvent) => void;\n};\n\nexport type UseTreeDndkitConfigArgs<T> = {\n flattenedItems: Item[];\n visibleItems: Item[];\n isHorizontalDnD?: boolean;\n isExpandable: boolean;\n onReorder: <S = T>(\n newData: Item<S>[],\n indexes: { targetIndex: number; fromIndex: number },\n considerExpanding: string,\n ) => void;\n getIsDropValid: <S = T>(\n active: Item<S>,\n over: Item<S>,\n dropIndicatorPosition: 'none' | 'before' | 'after' | 'inside',\n ) => boolean;\n maxDragAndDropLevel: number;\n};\n\nexport type UseTreeDndkitConfigReturn = {\n dndContextProps: DndContextPropsType;\n sortableContextProps: SortableContextPropsType;\n activeId: string;\n activeIndex: number;\n overId: string;\n depth: number;\n dropIndicatorPosition: DropIndicatorPosition;\n isDropValid: boolean;\n visibleItems: Item[];\n};\n\nexport type UseTreeDndkitConfigType = <T = unknown>(args: UseTreeDndkitConfigArgs<T>) => UseTreeDndkitConfigReturn;\n\nexport type GetKeyboardCoordinatesArgs = {\n items: Item[];\n active: Active;\n over: Over;\n event: KeyboardEvent;\n currentCoordinates: Coordinates;\n droppableContainers: DroppableContainers;\n collisionRect: ViewRect;\n dropIndicatorPosition: DropIndicatorPosition;\n maxDragAndDropLevel: number;\n};\n\nexport type SensorContext = MutableRefObject<{\n items: Item[];\n dropIndicatorPosition: DropIndicatorPosition;\n setDropIndicatorPosition: React.Dispatch<React.SetStateAction<DropIndicatorPosition>>;\n}>;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA,YAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -43,7 +43,8 @@ const useTreeActionHandlers = ({
|
|
|
43
43
|
onReorder,
|
|
44
44
|
flattenedItems,
|
|
45
45
|
projected,
|
|
46
|
-
dropIndicatorPosition
|
|
46
|
+
dropIndicatorPosition,
|
|
47
|
+
isDropValid
|
|
47
48
|
}) => {
|
|
48
49
|
const onDragStart = (0, import_react.useCallback)((e) => {
|
|
49
50
|
handlePreviewDragStart(e);
|
|
@@ -57,14 +58,14 @@ const useTreeActionHandlers = ({
|
|
|
57
58
|
const onDragEnd = (0, import_react.useCallback)((e) => {
|
|
58
59
|
handlePreviewDragEnd(e);
|
|
59
60
|
const { active, over } = e;
|
|
60
|
-
if (over === null)
|
|
61
|
+
if (over === null || !isDropValid)
|
|
61
62
|
return;
|
|
62
63
|
const activeIndex = flattenedItems.findIndex((item) => item.uid === active.id);
|
|
63
64
|
let considerExpanding = null;
|
|
64
65
|
let overIndex = flattenedItems.findIndex((item) => item.uid === over.id);
|
|
65
66
|
if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside) {
|
|
66
67
|
considerExpanding = over.id;
|
|
67
|
-
overIndex = flattenedItems[overIndex].realIndex +
|
|
68
|
+
overIndex = flattenedItems[overIndex].realIndex + flattenedItems[overIndex].childrenCount + 1;
|
|
68
69
|
}
|
|
69
70
|
if (projected && (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth)) {
|
|
70
71
|
flattenedItems[activeIndex].parentId = projected.parentId;
|
|
@@ -75,7 +76,7 @@ const useTreeActionHandlers = ({
|
|
|
75
76
|
fromIndex: activeIndex
|
|
76
77
|
}, considerExpanding || "");
|
|
77
78
|
}
|
|
78
|
-
}, [handlePreviewDragEnd, flattenedItems, projected, onReorder
|
|
79
|
+
}, [handlePreviewDragEnd, isDropValid, flattenedItems, dropIndicatorPosition, projected, onReorder]);
|
|
79
80
|
const onDragCancel = (0, import_react.useCallback)((e) => {
|
|
80
81
|
handlePreviewDragCancel(e);
|
|
81
82
|
}, [handlePreviewDragCancel]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 {
|
|
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,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;
|
|
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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -32,7 +32,6 @@ __export(useTreeDndkitConfig_exports, {
|
|
|
32
32
|
var React = __toESM(require("react"));
|
|
33
33
|
var import_react = require("react");
|
|
34
34
|
var import_core = require("@dnd-kit/core");
|
|
35
|
-
var import_sortable = require("@dnd-kit/sortable");
|
|
36
35
|
var import_useTreePreviewHandlers = require("./useTreePreviewHandlers");
|
|
37
36
|
var import_getTreeKeyboardCoordinates = require("./getTreeKeyboardCoordinates");
|
|
38
37
|
var import_utilities = require("./utilities");
|
|
@@ -40,20 +39,23 @@ var import_useTreeActionHandlers = require("./useTreeActionHandlers");
|
|
|
40
39
|
var import_constants = require("./constants");
|
|
41
40
|
var import_customCollisionDetection = require("./customCollisionDetection");
|
|
42
41
|
var import_useTreeAnnouncements = require("./useTreeAnnouncements");
|
|
43
|
-
const adjustTranslate = (isHorizontalDnD) =>
|
|
44
|
-
const
|
|
45
|
-
|
|
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;
|
|
46
53
|
};
|
|
47
|
-
|
|
48
|
-
newTransform.x = transform.x + 25;
|
|
49
|
-
} else {
|
|
50
|
-
newTransform.x = transform.x + 15;
|
|
51
|
-
}
|
|
52
|
-
return newTransform;
|
|
54
|
+
return func;
|
|
53
55
|
};
|
|
54
56
|
const measuring = {
|
|
55
57
|
droppable: {
|
|
56
|
-
strategy: import_core.MeasuringStrategy.
|
|
58
|
+
strategy: import_core.MeasuringStrategy.Always
|
|
57
59
|
}
|
|
58
60
|
};
|
|
59
61
|
const useTreeDndkitConfig = ({
|
|
@@ -62,6 +64,7 @@ const useTreeDndkitConfig = ({
|
|
|
62
64
|
isHorizontalDnD = false,
|
|
63
65
|
isExpandable = false,
|
|
64
66
|
onReorder,
|
|
67
|
+
getIsDropValid = () => true,
|
|
65
68
|
maxDragAndDropLevel
|
|
66
69
|
}) => {
|
|
67
70
|
const [activeId, setActiveId] = (0, import_react.useState)("");
|
|
@@ -77,6 +80,11 @@ const useTreeDndkitConfig = ({
|
|
|
77
80
|
});
|
|
78
81
|
return dictionary;
|
|
79
82
|
}, [visibleItems]);
|
|
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]);
|
|
80
88
|
const modifiers = (0, import_react.useMemo)(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
|
|
81
89
|
const sensorContext = (0, import_react.useRef)({
|
|
82
90
|
items: visibleItems,
|
|
@@ -105,7 +113,8 @@ const useTreeDndkitConfig = ({
|
|
|
105
113
|
onReorder,
|
|
106
114
|
projected,
|
|
107
115
|
flattenedItems,
|
|
108
|
-
dropIndicatorPosition
|
|
116
|
+
dropIndicatorPosition,
|
|
117
|
+
isDropValid
|
|
109
118
|
});
|
|
110
119
|
const announcements = (0, import_useTreeAnnouncements.useTreeAnnouncements)(visibleItemsDictionary, dropIndicatorPosition);
|
|
111
120
|
const dndContextProps = (0, import_react.useMemo)(() => ({
|
|
@@ -129,11 +138,12 @@ const useTreeDndkitConfig = ({
|
|
|
129
138
|
]);
|
|
130
139
|
const sortableContextProps = (0, import_react.useMemo)(() => ({
|
|
131
140
|
items: sortedIds,
|
|
132
|
-
strategy:
|
|
133
|
-
}), [sortedIds
|
|
141
|
+
strategy: () => null
|
|
142
|
+
}), [sortedIds]);
|
|
134
143
|
return {
|
|
135
144
|
dndContextProps,
|
|
136
145
|
sortableContextProps,
|
|
146
|
+
isDropValid,
|
|
137
147
|
activeId,
|
|
138
148
|
activeIndex: visibleItemsDictionary[activeId]?.realIndex ?? -1,
|
|
139
149
|
overId,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAAqD;AACrD,kBAQO;AACP,
|
|
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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 {
|
|
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
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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,61 +15,64 @@ const RECT_DOWN = {
|
|
|
15
15
|
};
|
|
16
16
|
const thresholdRatio = 0.2;
|
|
17
17
|
const insideThreshold = 0.7;
|
|
18
|
-
const customCollisionDetection = (activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition) =>
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
const customCollisionDetection = (activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition) => {
|
|
19
|
+
const func = ({ droppableContainers, collisionRect }) => {
|
|
20
|
+
const originalContainer = droppableContainers.find(({ id }) => id === activeId);
|
|
21
|
+
const originalRect = originalContainer?.rect?.current;
|
|
22
|
+
let isUp = lastPosition === "up";
|
|
23
|
+
if (originalRect) {
|
|
24
|
+
isUp = originalRect.offsetTop > collisionRect.top;
|
|
25
|
+
}
|
|
26
|
+
const threshold = collisionRect.height * thresholdRatio;
|
|
27
|
+
let collidingContainer = null;
|
|
28
|
+
if (isUp) {
|
|
29
|
+
collidingContainer = droppableContainers.reduce((firstRectDown, container) => {
|
|
30
|
+
const rect = container.rect.current;
|
|
31
|
+
if (rect && firstRectDown.rect.current) {
|
|
32
|
+
const { offsetTop: rectOffsetTop } = rect;
|
|
33
|
+
const { offsetTop: firstRectDownOffsetTop } = firstRectDown.rect.current;
|
|
34
|
+
if (rectOffsetTop + threshold > collisionRect.top && rectOffsetTop < firstRectDownOffsetTop) {
|
|
35
|
+
return container;
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
return firstRectDown;
|
|
39
|
+
}, { id: DUMMY_ID, rect: { current: RECT_DOWN } });
|
|
40
|
+
} else {
|
|
41
|
+
collidingContainer = droppableContainers.reduce((firstRectUp, container) => {
|
|
42
|
+
const rect = container.rect.current;
|
|
43
|
+
if (rect && firstRectUp.rect.current) {
|
|
44
|
+
const { offsetTop: rectOffsetTop } = rect;
|
|
45
|
+
const { offsetTop: firstRectUpOffsetTop } = firstRectUp.rect.current;
|
|
46
|
+
if (rectOffsetTop - threshold < collisionRect.top && rectOffsetTop > firstRectUpOffsetTop) {
|
|
47
|
+
return container;
|
|
48
|
+
}
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
50
|
+
return firstRectUp;
|
|
51
|
+
}, { id: DUMMY_ID, rect: { current: RECT_UP } });
|
|
52
|
+
}
|
|
53
|
+
if (collidingContainer.id === DUMMY_ID) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const collidingRect = collidingContainer.rect.current;
|
|
57
|
+
if (!collidingRect)
|
|
58
|
+
return null;
|
|
59
|
+
const [top, bottom] = [
|
|
60
|
+
Math.max(collisionRect.top, collidingRect.offsetTop),
|
|
61
|
+
Math.min(collisionRect.top + collisionRect.height, collidingRect.offsetTop + collidingRect.height)
|
|
62
|
+
];
|
|
63
|
+
const intersectionPercentage = Math.abs(bottom - top) / collidingRect.height;
|
|
64
|
+
if (intersectionPercentage > insideThreshold && visibleItemsDictionary[collidingContainer.id].depth + 1 <= maxDragAndDropLevel && collidingContainer.id !== activeId) {
|
|
65
|
+
setDropIndicatorPosition(DropIndicatorPosition.Inside);
|
|
66
|
+
} else {
|
|
67
|
+
setDropIndicatorPosition(isUp ? DropIndicatorPosition.Before : DropIndicatorPosition.After);
|
|
68
|
+
}
|
|
69
|
+
if (isUp && lastPosition !== "up")
|
|
70
|
+
setLastPosition("up");
|
|
71
|
+
else if (!isUp && lastPosition !== "down")
|
|
72
|
+
setLastPosition("down");
|
|
73
|
+
return collidingContainer.id;
|
|
74
|
+
};
|
|
75
|
+
return func;
|
|
73
76
|
};
|
|
74
77
|
export {
|
|
75
78
|
customCollisionDetection
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tree/customCollisionDetection.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/indent */\n/* eslint-disable max-params */\nimport { CollisionDetection, DroppableContainer, LayoutRect } from '@dnd-kit/core';\nimport { DropIndicatorPosition } from './constants';\nimport { Item } from './types';\n\nconst DUMMY_ID = 'DUMMY_ID_INTERNAL_USE_ONLY';\nconst RECT_UP: LayoutRect = {\n offsetTop: -Infinity,\n offsetLeft: 0, // Doesn't matter,\n width: 0, // Doesn't matter\n height: 0, // Doesn't matter\n};\nconst RECT_DOWN: LayoutRect = {\n offsetTop: Infinity,\n offsetLeft: 0, // Doesn't matter,\n width: 0, // Doesn't matter\n height: 0, // Doesn't matter\n};\n\n// Percentage of height to take into consideration when looking for colliding rects\nconst thresholdRatio = 0.2;\n// Percentage to be inside\nconst insideThreshold = 0.7;\n\nexport const customCollisionDetection
|
|
5
|
-
"mappings": "AAAA;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/indent */\n/* eslint-disable max-params */\nimport { CollisionDetection, DroppableContainer, LayoutRect } from '@dnd-kit/core';\nimport { DropIndicatorPosition } from './constants';\nimport { Item } from './types';\n\nconst DUMMY_ID = 'DUMMY_ID_INTERNAL_USE_ONLY';\nconst RECT_UP: LayoutRect = {\n offsetTop: -Infinity,\n offsetLeft: 0, // Doesn't matter,\n width: 0, // Doesn't matter\n height: 0, // Doesn't matter\n};\nconst RECT_DOWN: LayoutRect = {\n offsetTop: Infinity,\n offsetLeft: 0, // Doesn't matter,\n width: 0, // Doesn't matter\n height: 0, // Doesn't matter\n};\n\n// Percentage of height to take into consideration when looking for colliding rects\nconst thresholdRatio = 0.2;\n// Percentage to be inside\nconst insideThreshold = 0.7;\n\nexport const customCollisionDetection = (\n activeId: string,\n visibleItemsDictionary: Record<string, Item>,\n setDropIndicatorPosition: React.Dispatch<React.SetStateAction<DropIndicatorPosition>>,\n maxDragAndDropLevel: number,\n lastPosition: string,\n setLastPosition: React.Dispatch<React.SetStateAction<string>>,\n): CollisionDetection => {\n const func: CollisionDetection = ({ droppableContainers, collisionRect }) => {\n const originalContainer = droppableContainers.find(({ id }) => id === activeId);\n const originalRect = originalContainer?.rect?.current;\n\n // We first check if the item was moved up or down\n // This modifies how to search the matching colliding rect\n let isUp = lastPosition === 'up';\n if (originalRect) {\n isUp = originalRect.offsetTop > collisionRect.top;\n }\n\n // Threshold\n const threshold = collisionRect.height * thresholdRatio;\n\n let collidingContainer: DroppableContainer | null = null;\n\n if (isUp) {\n // Up -- We need to find the first rectangle downwards\n collidingContainer = droppableContainers.reduce(\n (firstRectDown, container) => {\n const rect = container.rect.current;\n if (rect && firstRectDown.rect.current) {\n const { offsetTop: rectOffsetTop } = rect;\n const { offsetTop: firstRectDownOffsetTop } = firstRectDown.rect.current;\n if (rectOffsetTop + threshold > collisionRect.top && rectOffsetTop < firstRectDownOffsetTop) {\n return container;\n }\n }\n return firstRectDown;\n },\n { id: DUMMY_ID, rect: { current: RECT_DOWN } } as DroppableContainer,\n );\n } else {\n // Down -- We need to find the first rectangle upwards\n collidingContainer = droppableContainers.reduce(\n (firstRectUp, container) => {\n const rect = container.rect.current;\n if (rect && firstRectUp.rect.current) {\n const { offsetTop: rectOffsetTop } = rect;\n const { offsetTop: firstRectUpOffsetTop } = firstRectUp.rect.current;\n if (rectOffsetTop - threshold < collisionRect.top && rectOffsetTop > firstRectUpOffsetTop) {\n return container;\n }\n }\n return firstRectUp;\n },\n { id: DUMMY_ID, rect: { current: RECT_UP } } as DroppableContainer,\n );\n }\n\n // If we didn't find a match, return null\n if (collidingContainer.id === DUMMY_ID) {\n return null;\n }\n\n const collidingRect = collidingContainer.rect.current;\n\n if (!collidingRect) return null;\n\n // Calculate the intersection interval\n const [top, bottom] = [\n Math.max(collisionRect.top, collidingRect.offsetTop),\n Math.min(collisionRect.top + collisionRect.height, collidingRect.offsetTop + collidingRect.height),\n ];\n\n // Calculate the percentage of intersection\n const intersectionPercentage = Math.abs(bottom - top) / collidingRect.height;\n\n if (\n intersectionPercentage > insideThreshold &&\n visibleItemsDictionary[collidingContainer.id].depth + 1 <= maxDragAndDropLevel &&\n collidingContainer.id !== activeId\n ) {\n setDropIndicatorPosition(DropIndicatorPosition.Inside);\n } else {\n setDropIndicatorPosition(isUp ? DropIndicatorPosition.Before : DropIndicatorPosition.After);\n }\n\n if (isUp && lastPosition !== 'up') setLastPosition('up');\n else if (!isUp && lastPosition !== 'down') setLastPosition('down');\n\n // Return the id of the match rectangle\n return collidingContainer.id;\n };\n return func;\n};\n"],
|
|
5
|
+
"mappings": "AAAA;ACKA;AAGA,MAAM,WAAW;AACjB,MAAM,UAAsB;AAAA,EAC1B,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,QAAQ;AAAA;AAEV,MAAM,YAAwB;AAAA,EAC5B,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,QAAQ;AAAA;AAIV,MAAM,iBAAiB;AAEvB,MAAM,kBAAkB;AAEjB,MAAM,2BAA2B,CACtC,UACA,wBACA,0BACA,qBACA,cACA,oBACuB;AACvB,QAAM,OAA2B,CAAC,EAAE,qBAAqB,oBAAoB;AAC3E,UAAM,oBAAoB,oBAAoB,KAAK,CAAC,EAAE,SAAS,OAAO;AACtE,UAAM,eAAe,mBAAmB,MAAM;AAI9C,QAAI,OAAO,iBAAiB;AAC5B,QAAI,cAAc;AAChB,aAAO,aAAa,YAAY,cAAc;AAAA;AAIhD,UAAM,YAAY,cAAc,SAAS;AAEzC,QAAI,qBAAgD;AAEpD,QAAI,MAAM;AAER,2BAAqB,oBAAoB,OACvC,CAAC,eAAe,cAAc;AAC5B,cAAM,OAAO,UAAU,KAAK;AAC5B,YAAI,QAAQ,cAAc,KAAK,SAAS;AACtC,gBAAM,EAAE,WAAW,kBAAkB;AACrC,gBAAM,EAAE,WAAW,2BAA2B,cAAc,KAAK;AACjE,cAAI,gBAAgB,YAAY,cAAc,OAAO,gBAAgB,wBAAwB;AAC3F,mBAAO;AAAA;AAAA;AAGX,eAAO;AAAA,SAET,EAAE,IAAI,UAAU,MAAM,EAAE,SAAS;AAAA,WAE9B;AAEL,2BAAqB,oBAAoB,OACvC,CAAC,aAAa,cAAc;AAC1B,cAAM,OAAO,UAAU,KAAK;AAC5B,YAAI,QAAQ,YAAY,KAAK,SAAS;AACpC,gBAAM,EAAE,WAAW,kBAAkB;AACrC,gBAAM,EAAE,WAAW,yBAAyB,YAAY,KAAK;AAC7D,cAAI,gBAAgB,YAAY,cAAc,OAAO,gBAAgB,sBAAsB;AACzF,mBAAO;AAAA;AAAA;AAGX,eAAO;AAAA,SAET,EAAE,IAAI,UAAU,MAAM,EAAE,SAAS;AAAA;AAKrC,QAAI,mBAAmB,OAAO,UAAU;AACtC,aAAO;AAAA;AAGT,UAAM,gBAAgB,mBAAmB,KAAK;AAE9C,QAAI,CAAC;AAAe,aAAO;AAG3B,UAAM,CAAC,KAAK,UAAU;AAAA,MACpB,KAAK,IAAI,cAAc,KAAK,cAAc;AAAA,MAC1C,KAAK,IAAI,cAAc,MAAM,cAAc,QAAQ,cAAc,YAAY,cAAc;AAAA;AAI7F,UAAM,yBAAyB,KAAK,IAAI,SAAS,OAAO,cAAc;AAEtE,QACE,yBAAyB,mBACzB,uBAAuB,mBAAmB,IAAI,QAAQ,KAAK,uBAC3D,mBAAmB,OAAO,UAC1B;AACA,+BAAyB,sBAAsB;AAAA,WAC1C;AACL,+BAAyB,OAAO,sBAAsB,SAAS,sBAAsB;AAAA;AAGvF,QAAI,QAAQ,iBAAiB;AAAM,sBAAgB;AAAA,aAC1C,CAAC,QAAQ,iBAAiB;AAAQ,sBAAgB;AAG3D,WAAO,mBAAmB;AAAA;AAE5B,SAAO;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,7 +3,6 @@ import { closestCorners, getViewRect, KeyboardCode } from "@dnd-kit/core";
|
|
|
3
3
|
import { DropIndicatorPosition } from "./constants";
|
|
4
4
|
const directions = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];
|
|
5
5
|
const horizontal = [KeyboardCode.Left, KeyboardCode.Right];
|
|
6
|
-
const vertical = [KeyboardCode.Up, KeyboardCode.Down];
|
|
7
6
|
const getVerticalKeyboardCoordinates = ({
|
|
8
7
|
items,
|
|
9
8
|
active,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tree/getTreeKeyboardCoordinates.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "
|
|
5
|
-
"mappings": "AAAA;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nimport { closestCorners, getViewRect, KeyboardCode, KeyboardCoordinateGetter, DroppableContainer } from '@dnd-kit/core';\nimport { Coordinates } from '@dnd-kit/core/dist/types';\nimport type { GetKeyboardCoordinatesArgs, SensorContext } from './types';\nimport { DropIndicatorPosition } from './constants';\n\nconst directions: string[] = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];\n\nconst horizontal: string[] = [KeyboardCode.Left, KeyboardCode.Right];\n\nconst getVerticalKeyboardCoordinates = ({\n items,\n active,\n over,\n event,\n currentCoordinates,\n droppableContainers,\n collisionRect,\n dropIndicatorPosition,\n maxDragAndDropLevel,\n}: GetKeyboardCoordinatesArgs): Coordinates | undefined => {\n if (horizontal.includes(event.code)) return undefined;\n\n const overRect = over.rect;\n\n const layoutRects: DroppableContainer[] = [];\n\n // Get the reacheable rects depending on the arrow key pressed\n droppableContainers.forEach((container) => {\n if (container?.disabled || !overRect) {\n return;\n }\n const rect = container.rect.current;\n if (rect && event.code === KeyboardCode.Down && collisionRect.top - 2 <= rect.offsetTop) {\n layoutRects.push(container);\n } else if (rect && event.code === KeyboardCode.Up && collisionRect.top >= rect.offsetTop) {\n layoutRects.push(container);\n }\n });\n\n const closestId = closestCorners({\n collisionRect,\n droppableContainers: layoutRects,\n active,\n });\n\n const closestItem = items.find((item) => item.uid === closestId);\n\n const closestElement = droppableContainers.get(closestId)?.node?.current;\n\n if (!closestId || !closestItem || !closestElement) return undefined;\n\n const closestRect = getViewRect(closestElement);\n\n if (event.code === KeyboardCode.Up) {\n // If the drop indicator is inside (or over ourselves)\n // We are gonna go to the before position\n // Else we are gonna go inside the over rect\n if (\n dropIndicatorPosition === DropIndicatorPosition.Inside ||\n closestId === active.id ||\n closestItem.depth + 1 > maxDragAndDropLevel\n ) {\n return {\n ...currentCoordinates,\n y: closestRect.top - collisionRect.height / 2,\n };\n }\n return {\n ...currentCoordinates,\n y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2,\n };\n }\n // If the drop indicator is inside (or over ourselves)\n // We are gonna go to the after position\n // Else we are gonna go inside the over rect\n if (\n dropIndicatorPosition === DropIndicatorPosition.Inside ||\n closestId === active.id ||\n closestItem.depth + 1 > maxDragAndDropLevel\n ) {\n return {\n ...currentCoordinates,\n y: closestRect.top + collisionRect.height / 2,\n };\n }\n return {\n ...currentCoordinates,\n y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2,\n };\n};\n\nexport const getTreeKeyboardCoordinates: (\n context: SensorContext,\n isHorizontalDnD: boolean,\n maxDragAndDropLevel: number,\n) => KeyboardCoordinateGetter =\n (context, isHorizontalDnD, maxDragAndDropLevel) =>\n (event, { currentCoordinates, context: { over, translatedRect, droppableContainers, active, collisionRect } }) => {\n if (directions.includes(event.code)) {\n if (!translatedRect) {\n return undefined;\n }\n\n const {\n current: { items, dropIndicatorPosition },\n } = context;\n\n if (!over || !active || !collisionRect) return undefined;\n\n const args = {\n items,\n active,\n over,\n event,\n currentCoordinates,\n droppableContainers,\n collisionRect,\n dropIndicatorPosition,\n maxDragAndDropLevel,\n };\n\n if (isHorizontalDnD) return undefined;\n return getVerticalKeyboardCoordinates(args);\n }\n return undefined;\n };\n"],
|
|
5
|
+
"mappings": "AAAA;ACCA;AAGA;AAEA,MAAM,aAAuB,CAAC,aAAa,MAAM,aAAa,OAAO,aAAa,IAAI,aAAa;AAEnG,MAAM,aAAuB,CAAC,aAAa,MAAM,aAAa;AAE9D,MAAM,iCAAiC,CAAC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACyD;AACzD,MAAI,WAAW,SAAS,MAAM;AAAO,WAAO;AAE5C,QAAM,WAAW,KAAK;AAEtB,QAAM,cAAoC;AAG1C,sBAAoB,QAAQ,CAAC,cAAc;AACzC,QAAI,WAAW,YAAY,CAAC,UAAU;AACpC;AAAA;AAEF,UAAM,OAAO,UAAU,KAAK;AAC5B,QAAI,QAAQ,MAAM,SAAS,aAAa,QAAQ,cAAc,MAAM,KAAK,KAAK,WAAW;AACvF,kBAAY,KAAK;AAAA,eACR,QAAQ,MAAM,SAAS,aAAa,MAAM,cAAc,OAAO,KAAK,WAAW;AACxF,kBAAY,KAAK;AAAA;AAAA;AAIrB,QAAM,YAAY,eAAe;AAAA,IAC/B;AAAA,IACA,qBAAqB;AAAA,IACrB;AAAA;AAGF,QAAM,cAAc,MAAM,KAAK,CAAC,SAAS,KAAK,QAAQ;AAEtD,QAAM,iBAAiB,oBAAoB,IAAI,YAAY,MAAM;AAEjE,MAAI,CAAC,aAAa,CAAC,eAAe,CAAC;AAAgB,WAAO;AAE1D,QAAM,cAAc,YAAY;AAEhC,MAAI,MAAM,SAAS,aAAa,IAAI;AAIlC,QACE,0BAA0B,sBAAsB,UAChD,cAAc,OAAO,MACrB,YAAY,QAAQ,IAAI,qBACxB;AACA,aAAO;AAAA,WACF;AAAA,QACH,GAAG,YAAY,MAAM,cAAc,SAAS;AAAA;AAAA;AAGhD,WAAO;AAAA,SACF;AAAA,MACH,GAAG,YAAY,MAAM,KAAK,IAAI,YAAY,SAAS,cAAc,UAAU;AAAA;AAAA;AAM/E,MACE,0BAA0B,sBAAsB,UAChD,cAAc,OAAO,MACrB,YAAY,QAAQ,IAAI,qBACxB;AACA,WAAO;AAAA,SACF;AAAA,MACH,GAAG,YAAY,MAAM,cAAc,SAAS;AAAA;AAAA;AAGhD,SAAO;AAAA,OACF;AAAA,IACH,GAAG,YAAY,MAAM,KAAK,IAAI,YAAY,SAAS,cAAc,UAAU;AAAA;AAAA;AAIxE,MAAM,6BAKX,CAAC,SAAS,iBAAiB,wBAC3B,CAAC,OAAO,EAAE,oBAAoB,SAAS,EAAE,MAAM,gBAAgB,qBAAqB,QAAQ,sBAAsB;AAChH,MAAI,WAAW,SAAS,MAAM,OAAO;AACnC,QAAI,CAAC,gBAAgB;AACnB,aAAO;AAAA;AAGT,UAAM;AAAA,MACJ,SAAS,EAAE,OAAO;AAAA,QAChB;AAEJ,QAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;AAAe,aAAO;AAE/C,UAAM,OAAO;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAGF,QAAI;AAAiB,aAAO;AAC5B,WAAO,+BAA+B;AAAA;AAExC,SAAO;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,7 +12,8 @@ const useTreeActionHandlers = ({
|
|
|
12
12
|
onReorder,
|
|
13
13
|
flattenedItems,
|
|
14
14
|
projected,
|
|
15
|
-
dropIndicatorPosition
|
|
15
|
+
dropIndicatorPosition,
|
|
16
|
+
isDropValid
|
|
16
17
|
}) => {
|
|
17
18
|
const onDragStart = useCallback((e) => {
|
|
18
19
|
handlePreviewDragStart(e);
|
|
@@ -26,14 +27,14 @@ const useTreeActionHandlers = ({
|
|
|
26
27
|
const onDragEnd = useCallback((e) => {
|
|
27
28
|
handlePreviewDragEnd(e);
|
|
28
29
|
const { active, over } = e;
|
|
29
|
-
if (over === null)
|
|
30
|
+
if (over === null || !isDropValid)
|
|
30
31
|
return;
|
|
31
32
|
const activeIndex = flattenedItems.findIndex((item) => item.uid === active.id);
|
|
32
33
|
let considerExpanding = null;
|
|
33
34
|
let overIndex = flattenedItems.findIndex((item) => item.uid === over.id);
|
|
34
35
|
if (dropIndicatorPosition === DropIndicatorPosition.Inside) {
|
|
35
36
|
considerExpanding = over.id;
|
|
36
|
-
overIndex = flattenedItems[overIndex].realIndex +
|
|
37
|
+
overIndex = flattenedItems[overIndex].realIndex + flattenedItems[overIndex].childrenCount + 1;
|
|
37
38
|
}
|
|
38
39
|
if (projected && (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth)) {
|
|
39
40
|
flattenedItems[activeIndex].parentId = projected.parentId;
|
|
@@ -44,7 +45,7 @@ const useTreeActionHandlers = ({
|
|
|
44
45
|
fromIndex: activeIndex
|
|
45
46
|
}, considerExpanding || "");
|
|
46
47
|
}
|
|
47
|
-
}, [handlePreviewDragEnd, flattenedItems, projected, onReorder
|
|
48
|
+
}, [handlePreviewDragEnd, isDropValid, flattenedItems, dropIndicatorPosition, projected, onReorder]);
|
|
48
49
|
const onDragCancel = useCallback((e) => {
|
|
49
50
|
handlePreviewDragCancel(e);
|
|
50
51
|
}, [handlePreviewDragCancel]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tree/useTreeActionHandlers.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { arrayMove } from '@dnd-kit/sortable';\nimport { cloneDeep } from 'lodash';\nimport { useCallback } from 'react';\nimport type { DragStartEvent, DragMoveEvent, DragEndEvent, DragOverEvent, DragCancelEvent } from '@dnd-kit/core';\nimport { DropIndicatorPosition } from './constants';\nimport type {
|
|
5
|
-
"mappings": "AAAA;ACAA;AACA;AACA;AAEA;AAGO,MAAM,wBAAwB,CAAC;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MAC4D;AAC5D,QAAM,cAAc,YAClB,CAAC,MAAsB;AACrB,2BAAuB;AAAA,KAEzB,CAAC;AAGH,QAAM,aAAa,YACjB,CAAC,MAAqB;AACpB,0BAAsB;AAAA,KAExB,CAAC;AAGH,QAAM,aAAa,YACjB,CAAC,MAAqB;AACpB,0BAAsB;AAAA,KAExB,CAAC;AAGH,QAAM,YAAY,YAChB,CAAC,MAAoB;AACnB,yBAAqB;AACrB,UAAM,EAAE,QAAQ,SAAS;AAEzB,QAAI,SAAS;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { arrayMove } from '@dnd-kit/sortable';\nimport { cloneDeep } from 'lodash';\nimport { useCallback } from 'react';\nimport type { DragStartEvent, DragMoveEvent, DragEndEvent, DragOverEvent, DragCancelEvent } from '@dnd-kit/core';\nimport { DropIndicatorPosition } from './constants';\nimport type { UseTreeActionHandlersReturn, UseTreeActionHandlersArgs } from './types';\n\nexport const useTreeActionHandlers = ({\n handlePreviewDragStart,\n handlePreviewDragMove,\n handlePreviewDragOver,\n handlePreviewDragEnd,\n handlePreviewDragCancel,\n onReorder,\n flattenedItems,\n projected,\n dropIndicatorPosition,\n isDropValid,\n}: UseTreeActionHandlersArgs): UseTreeActionHandlersReturn => {\n const onDragStart = useCallback(\n (e: DragStartEvent) => {\n handlePreviewDragStart(e);\n },\n [handlePreviewDragStart],\n );\n\n const onDragMove = useCallback(\n (e: DragMoveEvent) => {\n handlePreviewDragMove(e);\n },\n [handlePreviewDragMove],\n );\n\n const onDragOver = useCallback(\n (e: DragOverEvent) => {\n handlePreviewDragOver(e);\n },\n [handlePreviewDragOver],\n );\n\n const onDragEnd = useCallback(\n (e: DragEndEvent) => {\n handlePreviewDragEnd(e);\n const { active, over } = e;\n\n if (over === null || !isDropValid) return;\n\n const activeIndex = flattenedItems.findIndex((item) => item.uid === active.id);\n\n let considerExpanding = null;\n\n let overIndex = flattenedItems.findIndex((item) => item.uid === over.id);\n // If drop indicator is inside, then put it last,\n // It will be reconstructed well later\n if (dropIndicatorPosition === DropIndicatorPosition.Inside) {\n considerExpanding = over.id;\n overIndex = flattenedItems[overIndex].realIndex + flattenedItems[overIndex].childrenCount + 1;\n }\n\n // If we are dropping the item in a new position, or new depth\n if (projected && (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth)) {\n // Change parent and depth from projected data\n flattenedItems[activeIndex].parentId = projected.parentId;\n flattenedItems[activeIndex].depth = projected.depth;\n\n // If same index, don't move the array, just copy it\n const newFlattenedData =\n activeIndex !== overIndex ? arrayMove(flattenedItems, activeIndex, overIndex) : cloneDeep(flattenedItems);\n\n onReorder(\n newFlattenedData,\n {\n targetIndex: overIndex,\n fromIndex: activeIndex,\n },\n considerExpanding || '',\n );\n }\n },\n [handlePreviewDragEnd, isDropValid, flattenedItems, dropIndicatorPosition, projected, onReorder],\n );\n\n const onDragCancel = useCallback(\n (e: DragCancelEvent) => {\n handlePreviewDragCancel(e);\n },\n [handlePreviewDragCancel],\n );\n\n return { onDragStart, onDragMove, onDragOver, onDragEnd, onDragCancel };\n};\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;AACA;AAEA;AAGO,MAAM,wBAAwB,CAAC;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MAC4D;AAC5D,QAAM,cAAc,YAClB,CAAC,MAAsB;AACrB,2BAAuB;AAAA,KAEzB,CAAC;AAGH,QAAM,aAAa,YACjB,CAAC,MAAqB;AACpB,0BAAsB;AAAA,KAExB,CAAC;AAGH,QAAM,aAAa,YACjB,CAAC,MAAqB;AACpB,0BAAsB;AAAA,KAExB,CAAC;AAGH,QAAM,YAAY,YAChB,CAAC,MAAoB;AACnB,yBAAqB;AACrB,UAAM,EAAE,QAAQ,SAAS;AAEzB,QAAI,SAAS,QAAQ,CAAC;AAAa;AAEnC,UAAM,cAAc,eAAe,UAAU,CAAC,SAAS,KAAK,QAAQ,OAAO;AAE3E,QAAI,oBAAoB;AAExB,QAAI,YAAY,eAAe,UAAU,CAAC,SAAS,KAAK,QAAQ,KAAK;AAGrE,QAAI,0BAA0B,sBAAsB,QAAQ;AAC1D,0BAAoB,KAAK;AACzB,kBAAY,eAAe,WAAW,YAAY,eAAe,WAAW,gBAAgB;AAAA;AAI9F,QAAI,aAAc,iBAAgB,aAAa,eAAe,aAAa,UAAU,UAAU,QAAQ;AAErG,qBAAe,aAAa,WAAW,UAAU;AACjD,qBAAe,aAAa,QAAQ,UAAU;AAG9C,YAAM,mBACJ,gBAAgB,YAAY,UAAU,gBAAgB,aAAa,aAAa,UAAU;AAE5F,gBACE,kBACA;AAAA,QACE,aAAa;AAAA,QACb,WAAW;AAAA,SAEb,qBAAqB;AAAA;AAAA,KAI3B,CAAC,sBAAsB,aAAa,gBAAgB,uBAAuB,WAAW;AAGxF,QAAM,eAAe,YACnB,CAAC,MAAuB;AACtB,4BAAwB;AAAA,KAE1B,CAAC;AAGH,SAAO,EAAE,aAAa,YAAY,YAAY,WAAW;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
PointerSensor,
|
|
8
8
|
MeasuringStrategy
|
|
9
9
|
} from "@dnd-kit/core";
|
|
10
|
-
import { horizontalListSortingStrategy, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
11
10
|
import { useTreePreviewHandlers } from "./useTreePreviewHandlers";
|
|
12
11
|
import { getTreeKeyboardCoordinates } from "./getTreeKeyboardCoordinates";
|
|
13
12
|
import { getProjection, removeChildrenOf } from "./utilities";
|
|
@@ -15,20 +14,23 @@ import { useTreeActionHandlers } from "./useTreeActionHandlers";
|
|
|
15
14
|
import { DropIndicatorPosition } from "./constants";
|
|
16
15
|
import { customCollisionDetection } from "./customCollisionDetection";
|
|
17
16
|
import { useTreeAnnouncements } from "./useTreeAnnouncements";
|
|
18
|
-
const adjustTranslate = (isHorizontalDnD) =>
|
|
19
|
-
const
|
|
20
|
-
|
|
17
|
+
const adjustTranslate = (isHorizontalDnD) => {
|
|
18
|
+
const func = ({ transform }) => {
|
|
19
|
+
const newTransform = {
|
|
20
|
+
...transform
|
|
21
|
+
};
|
|
22
|
+
if (isHorizontalDnD) {
|
|
23
|
+
newTransform.x = transform.x + 25;
|
|
24
|
+
} else {
|
|
25
|
+
newTransform.x = transform.x + 15;
|
|
26
|
+
}
|
|
27
|
+
return newTransform;
|
|
21
28
|
};
|
|
22
|
-
|
|
23
|
-
newTransform.x = transform.x + 25;
|
|
24
|
-
} else {
|
|
25
|
-
newTransform.x = transform.x + 15;
|
|
26
|
-
}
|
|
27
|
-
return newTransform;
|
|
29
|
+
return func;
|
|
28
30
|
};
|
|
29
31
|
const measuring = {
|
|
30
32
|
droppable: {
|
|
31
|
-
strategy: MeasuringStrategy.
|
|
33
|
+
strategy: MeasuringStrategy.Always
|
|
32
34
|
}
|
|
33
35
|
};
|
|
34
36
|
const useTreeDndkitConfig = ({
|
|
@@ -37,6 +39,7 @@ const useTreeDndkitConfig = ({
|
|
|
37
39
|
isHorizontalDnD = false,
|
|
38
40
|
isExpandable = false,
|
|
39
41
|
onReorder,
|
|
42
|
+
getIsDropValid = () => true,
|
|
40
43
|
maxDragAndDropLevel
|
|
41
44
|
}) => {
|
|
42
45
|
const [activeId, setActiveId] = useState("");
|
|
@@ -52,6 +55,11 @@ const useTreeDndkitConfig = ({
|
|
|
52
55
|
});
|
|
53
56
|
return dictionary;
|
|
54
57
|
}, [visibleItems]);
|
|
58
|
+
const isDropValid = useMemo(() => {
|
|
59
|
+
if (!activeId || !overId)
|
|
60
|
+
return true;
|
|
61
|
+
return getIsDropValid(visibleItemsDictionary[activeId], visibleItemsDictionary[overId], ["none", "before", "after", "inside"][dropIndicatorPosition]);
|
|
62
|
+
}, [getIsDropValid, visibleItemsDictionary, activeId, overId, dropIndicatorPosition]);
|
|
55
63
|
const modifiers = useMemo(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
|
|
56
64
|
const sensorContext = useRef({
|
|
57
65
|
items: visibleItems,
|
|
@@ -80,7 +88,8 @@ const useTreeDndkitConfig = ({
|
|
|
80
88
|
onReorder,
|
|
81
89
|
projected,
|
|
82
90
|
flattenedItems,
|
|
83
|
-
dropIndicatorPosition
|
|
91
|
+
dropIndicatorPosition,
|
|
92
|
+
isDropValid
|
|
84
93
|
});
|
|
85
94
|
const announcements = useTreeAnnouncements(visibleItemsDictionary, dropIndicatorPosition);
|
|
86
95
|
const dndContextProps = useMemo(() => ({
|
|
@@ -104,11 +113,12 @@ const useTreeDndkitConfig = ({
|
|
|
104
113
|
]);
|
|
105
114
|
const sortableContextProps = useMemo(() => ({
|
|
106
115
|
items: sortedIds,
|
|
107
|
-
strategy:
|
|
108
|
-
}), [sortedIds
|
|
116
|
+
strategy: () => null
|
|
117
|
+
}), [sortedIds]);
|
|
109
118
|
return {
|
|
110
119
|
dndContextProps,
|
|
111
120
|
sortableContextProps,
|
|
121
|
+
isDropValid,
|
|
112
122
|
activeId,
|
|
113
123
|
activeIndex: visibleItemsDictionary[activeId]?.realIndex ?? -1,
|
|
114
124
|
overId,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 {
|
|
5
|
-
"mappings": "AAAA;ACCA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AACA;AACA;
|
|
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": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 {
|
|
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
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
6
|
"names": []
|
|
7
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;
|