@elliemae/ds-drag-and-drop 2.0.0-alpha.12

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.
Files changed (58) hide show
  1. package/cjs/hierarchy/customCollisionDetection.js +70 -0
  2. package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js +121 -0
  3. package/cjs/hierarchy/index.js +9 -0
  4. package/cjs/hierarchy/types.js +2 -0
  5. package/cjs/hierarchy/useHierarchyActionHandlers.js +50 -0
  6. package/cjs/hierarchy/useHierarchyAnnouncements.js +36 -0
  7. package/cjs/hierarchy/useHierarchyDndkitConfig.js +119 -0
  8. package/cjs/hierarchy/useHierarchyPreviewHandlers.js +43 -0
  9. package/cjs/index.js +11 -0
  10. package/cjs/tree/constants.js +12 -0
  11. package/cjs/tree/customCollisionDetection.js +137 -0
  12. package/cjs/tree/getTreeKeyboardCoordinates.js +139 -0
  13. package/cjs/tree/index.js +9 -0
  14. package/cjs/tree/types.js +2 -0
  15. package/cjs/tree/useTreeActionHandlers.js +75 -0
  16. package/cjs/tree/useTreeAnnouncements.js +55 -0
  17. package/cjs/tree/useTreeDndkitConfig.js +142 -0
  18. package/cjs/tree/useTreePreviewHandlers.js +54 -0
  19. package/cjs/tree/utilities.js +52 -0
  20. package/esm/hierarchy/customCollisionDetection.js +66 -0
  21. package/esm/hierarchy/getHierarchyKeyboardCoordinates.js +113 -0
  22. package/esm/hierarchy/index.js +1 -0
  23. package/esm/hierarchy/types.js +1 -0
  24. package/esm/hierarchy/useHierarchyActionHandlers.js +46 -0
  25. package/esm/hierarchy/useHierarchyAnnouncements.js +32 -0
  26. package/esm/hierarchy/useHierarchyDndkitConfig.js +111 -0
  27. package/esm/hierarchy/useHierarchyPreviewHandlers.js +39 -0
  28. package/esm/index.js +2 -0
  29. package/esm/tree/constants.js +10 -0
  30. package/esm/tree/customCollisionDetection.js +133 -0
  31. package/esm/tree/getTreeKeyboardCoordinates.js +131 -0
  32. package/esm/tree/index.js +1 -0
  33. package/esm/tree/types.js +1 -0
  34. package/esm/tree/useTreeActionHandlers.js +71 -0
  35. package/esm/tree/useTreeAnnouncements.js +51 -0
  36. package/esm/tree/useTreeDndkitConfig.js +134 -0
  37. package/esm/tree/useTreePreviewHandlers.js +50 -0
  38. package/esm/tree/utilities.js +47 -0
  39. package/package.json +125 -0
  40. package/types/hierarchy/customCollisionDetection.d.ts +3 -0
  41. package/types/hierarchy/getHierarchyKeyboardCoordinates.d.ts +3 -0
  42. package/types/hierarchy/index.d.ts +1 -0
  43. package/types/hierarchy/types.d.ts +80 -0
  44. package/types/hierarchy/useHierarchyActionHandlers.d.ts +1 -0
  45. package/types/hierarchy/useHierarchyAnnouncements.d.ts +3 -0
  46. package/types/hierarchy/useHierarchyDndkitConfig.d.ts +2 -0
  47. package/types/hierarchy/useHierarchyPreviewHandlers.d.ts +2 -0
  48. package/types/index.d.ts +2 -0
  49. package/types/tree/constants.d.ts +6 -0
  50. package/types/tree/customCollisionDetection.d.ts +4 -0
  51. package/types/tree/getTreeKeyboardCoordinates.d.ts +3 -0
  52. package/types/tree/index.d.ts +1 -0
  53. package/types/tree/types.d.ts +98 -0
  54. package/types/tree/useTreeActionHandlers.d.ts +2 -0
  55. package/types/tree/useTreeAnnouncements.d.ts +4 -0
  56. package/types/tree/useTreeDndkitConfig.d.ts +2 -0
  57. package/types/tree/useTreePreviewHandlers.d.ts +2 -0
  58. package/types/tree/utilities.d.ts +7 -0
@@ -0,0 +1,139 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
6
+ require('core-js/modules/esnext.async-iterator.for-each.js');
7
+ require('core-js/modules/esnext.iterator.constructor.js');
8
+ require('core-js/modules/esnext.iterator.for-each.js');
9
+ require('core-js/modules/esnext.async-iterator.find.js');
10
+ require('core-js/modules/esnext.iterator.find.js');
11
+ require('core-js/modules/esnext.async-iterator.filter.js');
12
+ require('core-js/modules/esnext.iterator.filter.js');
13
+ var core = require('@dnd-kit/core');
14
+ var constants = require('./constants.js');
15
+
16
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
+
18
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
19
+
20
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
21
+
22
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
+ const directions = [core.KeyboardCode.Down, core.KeyboardCode.Right, core.KeyboardCode.Up, core.KeyboardCode.Left];
24
+ const horizontal = [core.KeyboardCode.Left, core.KeyboardCode.Right];
25
+ [core.KeyboardCode.Up, core.KeyboardCode.Down];
26
+
27
+ const getVerticalKeyboardCoordinates = _ref => {
28
+ var _droppableContainers$, _droppableContainers$2;
29
+
30
+ let {
31
+ items,
32
+ active,
33
+ over,
34
+ event,
35
+ currentCoordinates,
36
+ droppableContainers,
37
+ collisionRect,
38
+ dropIndicatorPosition,
39
+ maxDragAndDropLevel
40
+ } = _ref;
41
+ if (horizontal.includes(event.code)) return undefined;
42
+ const overRect = over.rect;
43
+ const layoutRects = []; // Get the reacheable rects depending on the arrow key pressed
44
+
45
+ droppableContainers.forEach(container => {
46
+ if (container !== null && container !== void 0 && container.disabled || !overRect) {
47
+ return;
48
+ }
49
+
50
+ const rect = container.rect.current;
51
+
52
+ if (rect && event.code === core.KeyboardCode.Down && collisionRect.top - 2 <= rect.offsetTop) {
53
+ layoutRects.push(container);
54
+ } else if (rect && event.code === core.KeyboardCode.Up && collisionRect.top >= rect.offsetTop) {
55
+ layoutRects.push(container);
56
+ }
57
+ });
58
+ const closestId = core.closestCorners({
59
+ collisionRect,
60
+ droppableContainers: layoutRects,
61
+ active
62
+ });
63
+ const closestItem = items.find(item => item.uid === closestId);
64
+ const closestElement = (_droppableContainers$ = droppableContainers.get(closestId)) === null || _droppableContainers$ === void 0 ? void 0 : (_droppableContainers$2 = _droppableContainers$.node) === null || _droppableContainers$2 === void 0 ? void 0 : _droppableContainers$2.current;
65
+ if (!closestId || !closestItem || !closestElement) return undefined;
66
+ const closestRect = core.getViewRect(closestElement);
67
+
68
+ if (event.code === core.KeyboardCode.Up) {
69
+ // If the drop indicator is inside (or over ourselves)
70
+ // We are gonna go to the before position
71
+ // Else we are gonna go inside the over rect
72
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside || closestId === active.id || closestItem.depth + 1 > maxDragAndDropLevel) {
73
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
74
+ y: closestRect.top - collisionRect.height / 2
75
+ });
76
+ }
77
+
78
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
79
+ y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2
80
+ });
81
+ } // If the drop indicator is inside (or over ourselves)
82
+ // We are gonna go to the after position
83
+ // Else we are gonna go inside the over rect
84
+
85
+
86
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside || closestId === active.id || closestItem.depth + 1 > maxDragAndDropLevel) {
87
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
88
+ y: closestRect.top + collisionRect.height / 2
89
+ });
90
+ }
91
+
92
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
93
+ y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2
94
+ });
95
+ };
96
+
97
+ const getTreeKeyboardCoordinates = (context, isHorizontalDnD, maxDragAndDropLevel) => (event, _ref2) => {
98
+ let {
99
+ currentCoordinates,
100
+ context: {
101
+ over,
102
+ translatedRect,
103
+ droppableContainers,
104
+ active,
105
+ collisionRect
106
+ }
107
+ } = _ref2;
108
+
109
+ if (directions.includes(event.code)) {
110
+ if (!translatedRect) {
111
+ return undefined;
112
+ }
113
+
114
+ const {
115
+ current: {
116
+ items,
117
+ dropIndicatorPosition
118
+ }
119
+ } = context;
120
+ if (!over || !active || !collisionRect) return undefined;
121
+ const args = {
122
+ items,
123
+ active,
124
+ over,
125
+ event,
126
+ currentCoordinates,
127
+ droppableContainers,
128
+ collisionRect,
129
+ dropIndicatorPosition,
130
+ maxDragAndDropLevel
131
+ };
132
+ if (isHorizontalDnD) return undefined;
133
+ return getVerticalKeyboardCoordinates(args);
134
+ }
135
+
136
+ return undefined;
137
+ };
138
+
139
+ exports.getTreeKeyboardCoordinates = getTreeKeyboardCoordinates;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useTreeDndkitConfig = require('./useTreeDndkitConfig.js');
6
+
7
+
8
+
9
+ exports.useTreeDndkitConfig = useTreeDndkitConfig.useTreeDndkitConfig;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var sortable = require('@dnd-kit/sortable');
6
+ var lodash = require('lodash');
7
+ var react = require('react');
8
+ var constants = require('./constants.js');
9
+
10
+ const useTreeActionHandlers = _ref => {
11
+ let {
12
+ handlePreviewDragStart,
13
+ handlePreviewDragMove,
14
+ handlePreviewDragOver,
15
+ handlePreviewDragEnd,
16
+ handlePreviewDragCancel,
17
+ onReorder,
18
+ flattenedItems,
19
+ projected,
20
+ dropIndicatorPosition
21
+ } = _ref;
22
+ const onDragStart = react.useCallback(e => {
23
+ handlePreviewDragStart(e);
24
+ }, [handlePreviewDragStart]);
25
+ const onDragMove = react.useCallback(e => {
26
+ handlePreviewDragMove(e);
27
+ }, [handlePreviewDragMove]);
28
+ const onDragOver = react.useCallback(e => {
29
+ handlePreviewDragOver(e);
30
+ }, [handlePreviewDragOver]);
31
+ const onDragEnd = react.useCallback(e => {
32
+ handlePreviewDragEnd(e);
33
+ const {
34
+ active,
35
+ over
36
+ } = e;
37
+ if (over === null) return;
38
+ const activeIndex = flattenedItems.findIndex(item => item.uid === active.id);
39
+ let considerExpanding = null;
40
+ let overIndex = flattenedItems.findIndex(item => item.uid === over.id); // If drop indicator is inside, then put it last,
41
+ // It will be reconstructed well later
42
+
43
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside) {
44
+ var _flattenedItems$overI, _flattenedItems$overI2;
45
+
46
+ considerExpanding = over.id;
47
+ overIndex = flattenedItems[overIndex].realIndex + ((_flattenedItems$overI = (_flattenedItems$overI2 = flattenedItems[overIndex].original.subRows) === null || _flattenedItems$overI2 === void 0 ? void 0 : _flattenedItems$overI2.length) !== null && _flattenedItems$overI !== void 0 ? _flattenedItems$overI : 0) + 1;
48
+ } // If we are dropping the item in a new position, or new depth
49
+
50
+
51
+ if (projected && (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth)) {
52
+ // Change parent and depth from projected data
53
+ flattenedItems[activeIndex].parentId = projected.parentId;
54
+ flattenedItems[activeIndex].depth = projected.depth; // If same index, don't move the array, just copy it
55
+
56
+ const newFlattenedData = activeIndex !== overIndex ? sortable.arrayMove(flattenedItems, activeIndex, overIndex) : lodash.cloneDeep(flattenedItems);
57
+ onReorder(newFlattenedData, {
58
+ targetIndex: overIndex,
59
+ fromIndex: activeIndex
60
+ }, considerExpanding || '');
61
+ }
62
+ }, [handlePreviewDragEnd, flattenedItems, projected, onReorder, dropIndicatorPosition]);
63
+ const onDragCancel = react.useCallback(e => {
64
+ handlePreviewDragCancel(e);
65
+ }, [handlePreviewDragCancel]);
66
+ return {
67
+ onDragStart,
68
+ onDragMove,
69
+ onDragOver,
70
+ onDragEnd,
71
+ onDragCancel
72
+ };
73
+ };
74
+
75
+ exports.useTreeActionHandlers = useTreeActionHandlers;
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var constants = require('./constants.js');
7
+
8
+ const useTreeAnnouncements = (visibleItemsDictionary, dropIndicatorPosition) => {
9
+ const onDragStart = react.useCallback(id => "Picked up draggable item from position ".concat(visibleItemsDictionary[id].realIndex + 1, "."), [visibleItemsDictionary]);
10
+ const onDragMove = react.useCallback((id, overId) => {
11
+ if (overId) {
12
+ const overIndex = visibleItemsDictionary[overId].realIndex + 1;
13
+
14
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside) {
15
+ return "Draggable item was moved inside the item at position ".concat(overIndex, ".");
16
+ }
17
+
18
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Before) {
19
+ return "Draggable item was moved to position ".concat(overIndex - 1, ".");
20
+ }
21
+
22
+ return "Draggable item was moved to position ".concat(overIndex, ".");
23
+ }
24
+
25
+ return "Draggable item is no longer over a droppable area.";
26
+ }, [visibleItemsDictionary, dropIndicatorPosition]);
27
+ const onDragOver = onDragMove;
28
+ const onDragEnd = react.useCallback((id, overId) => {
29
+ if (overId) {
30
+ const overIndex = visibleItemsDictionary[overId].realIndex + 1;
31
+
32
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside) {
33
+ return "Draggable item was dropped inside the item at position ".concat(overIndex, ".");
34
+ }
35
+
36
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Before) {
37
+ return "Draggable item was dropped over position ".concat(overIndex - 1, ".");
38
+ }
39
+
40
+ return "Draggable item was dropped over position ".concat(overIndex, ".");
41
+ }
42
+
43
+ return "Draggable item was dropped at it's original position.";
44
+ }, [dropIndicatorPosition, visibleItemsDictionary]);
45
+ const onDragCancel = react.useCallback(id => "Dragging was cancelled. Draggable item from position ".concat(visibleItemsDictionary[id].realIndex + 1, " was dropped at it's initial position."), [visibleItemsDictionary]);
46
+ return {
47
+ onDragStart,
48
+ onDragOver,
49
+ onDragMove,
50
+ onDragEnd,
51
+ onDragCancel
52
+ };
53
+ };
54
+
55
+ exports.useTreeAnnouncements = useTreeAnnouncements;
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
6
+ require('core-js/modules/web.dom-collections.iterator.js');
7
+ require('core-js/modules/esnext.async-iterator.map.js');
8
+ require('core-js/modules/esnext.iterator.map.js');
9
+ require('core-js/modules/esnext.async-iterator.for-each.js');
10
+ require('core-js/modules/esnext.iterator.constructor.js');
11
+ require('core-js/modules/esnext.iterator.for-each.js');
12
+ require('core-js/modules/esnext.async-iterator.filter.js');
13
+ require('core-js/modules/esnext.iterator.filter.js');
14
+ var react = require('react');
15
+ var core = require('@dnd-kit/core');
16
+ var sortable = require('@dnd-kit/sortable');
17
+ var useTreePreviewHandlers = require('./useTreePreviewHandlers.js');
18
+ var getTreeKeyboardCoordinates = require('./getTreeKeyboardCoordinates.js');
19
+ var utilities = require('./utilities.js');
20
+ var useTreeActionHandlers = require('./useTreeActionHandlers.js');
21
+ var constants = require('./constants.js');
22
+ var customCollisionDetection = require('./customCollisionDetection.js');
23
+ var useTreeAnnouncements = require('./useTreeAnnouncements.js');
24
+
25
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
26
+
27
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
28
+
29
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
30
+
31
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
32
+ // if second parameter is true, the space will be done on the horizontal axis
33
+
34
+ const adjustTranslate = isHorizontalDnD => _ref => {
35
+ let {
36
+ transform
37
+ } = _ref;
38
+
39
+ const newTransform = _objectSpread({}, transform);
40
+
41
+ if (isHorizontalDnD) {
42
+ newTransform.x = transform.x + 25;
43
+ } else {
44
+ newTransform.x = transform.x + 15;
45
+ }
46
+
47
+ return newTransform;
48
+ };
49
+
50
+ const measuring = {
51
+ droppable: {
52
+ strategy: core.MeasuringStrategy.BeforeDragging
53
+ }
54
+ };
55
+ const useTreeDndkitConfig = _ref2 => {
56
+ var _visibleItemsDictiona, _visibleItemsDictiona2;
57
+
58
+ let {
59
+ flattenedItems,
60
+ visibleItems: preVisibleItems,
61
+ isHorizontalDnD = false,
62
+ isExpandable = false,
63
+ onReorder,
64
+ maxDragAndDropLevel
65
+ } = _ref2;
66
+ const [activeId, setActiveId] = react.useState('');
67
+ const [overId, setOverId] = react.useState('');
68
+ const [dropIndicatorPosition, setDropIndicatorPosition] = react.useState(constants.DropIndicatorPosition.None);
69
+ const [lastPosition, setLastPosition] = react.useState(''); // Remove activeId's children
70
+
71
+ const visibleItems = react.useMemo(() => utilities.removeChildrenOf(preVisibleItems, activeId), [preVisibleItems, activeId]); // Sorted ids for the library
72
+
73
+ const sortedIds = react.useMemo(() => visibleItems.map(item => item.uid), [visibleItems]);
74
+ /**
75
+ * Dictionary from UID to ITEM
76
+ * This dictionary is computed since on every DnD move, I need to know the
77
+ * depth of a particular row, so O(1) per DnD move instead of O(#ITEMS)
78
+ */
79
+
80
+ const visibleItemsDictionary = react.useMemo(() => {
81
+ // Using plain for to achieve O(#ITEMS) performance
82
+ const dictionary = {};
83
+ visibleItems.forEach(item => {
84
+ dictionary[item.uid] = item;
85
+ });
86
+ return dictionary;
87
+ }, [visibleItems]);
88
+ const modifiers = react.useMemo(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
89
+ const sensorContext = react.useRef({
90
+ items: visibleItems,
91
+ dropIndicatorPosition,
92
+ setDropIndicatorPosition
93
+ });
94
+ react.useEffect(() => {
95
+ sensorContext.current = {
96
+ items: visibleItems,
97
+ dropIndicatorPosition,
98
+ setDropIndicatorPosition
99
+ };
100
+ }, [visibleItems, dropIndicatorPosition, setDropIndicatorPosition]);
101
+ const coordinateGetter = react.useMemo(() => getTreeKeyboardCoordinates.getTreeKeyboardCoordinates(sensorContext, isHorizontalDnD, maxDragAndDropLevel), [sensorContext, isHorizontalDnD, maxDragAndDropLevel]);
102
+ const sensors = core.useSensors(core.useSensor(core.PointerSensor), core.useSensor(core.KeyboardSensor, {
103
+ coordinateGetter
104
+ })); // where is the activeItem being positioned (depth and parent)
105
+
106
+ const projected = react.useMemo(() => overId ? utilities.getProjection(visibleItems, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) : null, [overId, visibleItems, visibleItemsDictionary, dropIndicatorPosition, isExpandable]);
107
+ const dragPreviewHandlers = useTreePreviewHandlers.useTreePreviewHandlers({
108
+ setActiveId,
109
+ setOverId,
110
+ setDropIndicatorPosition
111
+ });
112
+ const dragActionHandlers = useTreeActionHandlers.useTreeActionHandlers(_objectSpread(_objectSpread({}, dragPreviewHandlers), {}, {
113
+ onReorder,
114
+ projected,
115
+ flattenedItems,
116
+ dropIndicatorPosition
117
+ }));
118
+ const announcements = useTreeAnnouncements.useTreeAnnouncements(visibleItemsDictionary, dropIndicatorPosition);
119
+ const dndContextProps = react.useMemo(() => _objectSpread({
120
+ announcements,
121
+ modifiers,
122
+ sensors,
123
+ measuring,
124
+ collisionDetection: customCollisionDetection.customCollisionDetection(activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition)
125
+ }, dragActionHandlers), [announcements, modifiers, sensors, dragActionHandlers, visibleItemsDictionary, setDropIndicatorPosition, activeId, maxDragAndDropLevel, lastPosition, setLastPosition]);
126
+ const sortableContextProps = react.useMemo(() => ({
127
+ items: sortedIds,
128
+ strategy: isHorizontalDnD ? sortable.horizontalListSortingStrategy : sortable.verticalListSortingStrategy
129
+ }), [sortedIds, isHorizontalDnD]);
130
+ return {
131
+ dndContextProps,
132
+ sortableContextProps,
133
+ activeId,
134
+ activeIndex: (_visibleItemsDictiona = (_visibleItemsDictiona2 = visibleItemsDictionary[activeId]) === null || _visibleItemsDictiona2 === void 0 ? void 0 : _visibleItemsDictiona2.realIndex) !== null && _visibleItemsDictiona !== void 0 ? _visibleItemsDictiona : -1,
135
+ overId,
136
+ depth: projected ? projected.depth : 0,
137
+ dropIndicatorPosition,
138
+ visibleItems
139
+ };
140
+ };
141
+
142
+ exports.useTreeDndkitConfig = useTreeDndkitConfig;
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var constants = require('./constants.js');
7
+
8
+ const useTreePreviewHandlers = _ref => {
9
+ let {
10
+ setOverId,
11
+ setActiveId,
12
+ setDropIndicatorPosition
13
+ } = _ref;
14
+ const resetState = react.useCallback(() => {
15
+ setOverId('');
16
+ setActiveId('');
17
+ document.body.style.setProperty('cursor', '');
18
+ }, [setOverId, setActiveId]);
19
+ const handlePreviewDragStart = react.useCallback(_ref2 => {
20
+ let {
21
+ active: {
22
+ id
23
+ }
24
+ } = _ref2;
25
+ setActiveId(id);
26
+ setOverId(id);
27
+ setDropIndicatorPosition(constants.DropIndicatorPosition.Inside);
28
+ document.body.style.setProperty('cursor', 'grabbing');
29
+ }, [setActiveId, setDropIndicatorPosition, setOverId]);
30
+ const handlePreviewDragMove = react.useCallback(() => null, []);
31
+ const handlePreviewDragOver = react.useCallback(_ref3 => {
32
+ var _over$id;
33
+
34
+ let {
35
+ over
36
+ } = _ref3;
37
+ setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : '');
38
+ }, [setOverId]);
39
+ const handlePreviewDragEnd = react.useCallback(() => {
40
+ resetState();
41
+ }, [resetState]);
42
+ const handlePreviewDragCancel = react.useCallback(() => {
43
+ resetState();
44
+ }, [resetState]);
45
+ return {
46
+ handlePreviewDragStart,
47
+ handlePreviewDragMove,
48
+ handlePreviewDragOver,
49
+ handlePreviewDragEnd,
50
+ handlePreviewDragCancel
51
+ };
52
+ };
53
+
54
+ exports.useTreePreviewHandlers = useTreePreviewHandlers;
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.filter.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.filter.js');
8
+ var constants = require('./constants.js');
9
+
10
+ const getMinDepth = item => {
11
+ if (item) return item.depth;
12
+ return 0;
13
+ };
14
+
15
+ const getProjection = (items, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) => {
16
+ const overItemIndex = visibleItemsDictionary[overId].realIndex;
17
+ const previousItem = items[overItemIndex];
18
+ const nextItem = items[overItemIndex + 1];
19
+
20
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside && isExpandable) {
21
+ return {
22
+ depth: visibleItemsDictionary[overId].depth + 1,
23
+ parentId: overId
24
+ };
25
+ }
26
+
27
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Before) {
28
+ return {
29
+ depth: getMinDepth(previousItem),
30
+ parentId: previousItem.parentId
31
+ };
32
+ }
33
+
34
+ return {
35
+ depth: getMinDepth(nextItem),
36
+ parentId: nextItem === null || nextItem === void 0 ? void 0 : nextItem.parentId
37
+ };
38
+ };
39
+ const removeChildrenOf = (items, id) => {
40
+ const excludeParentIds = [id];
41
+ return items.filter(item => {
42
+ if (item.parentId !== null && excludeParentIds.includes(item.parentId)) {
43
+ excludeParentIds.push(item.uid);
44
+ return false;
45
+ }
46
+
47
+ return true;
48
+ });
49
+ };
50
+
51
+ exports.getProjection = getProjection;
52
+ exports.removeChildrenOf = removeChildrenOf;
@@ -0,0 +1,66 @@
1
+ import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.filter.js';
4
+ import 'core-js/modules/esnext.async-iterator.find.js';
5
+ import 'core-js/modules/esnext.iterator.find.js';
6
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
7
+ import 'core-js/modules/esnext.iterator.for-each.js';
8
+
9
+ const customCollisionDetection = (activeId, activeParent, dndItems) => _ref => {
10
+ var _originalContainer$re;
11
+
12
+ let {
13
+ droppableContainers,
14
+ collisionRect
15
+ } = _ref;
16
+ const entriesWithSameParent = droppableContainers.filter(_ref2 => {
17
+ var _dndItems$find;
18
+
19
+ let {
20
+ id
21
+ } = _ref2;
22
+ return ((_dndItems$find = dndItems.find(item => item.id === id)) === null || _dndItems$find === void 0 ? void 0 : _dndItems$find.parentId) === activeParent;
23
+ });
24
+ const originalContainer = entriesWithSameParent.find(_ref3 => {
25
+ let {
26
+ id
27
+ } = _ref3;
28
+ return id === activeId;
29
+ });
30
+ const originalRect = originalContainer === null || originalContainer === void 0 ? void 0 : (_originalContainer$re = originalContainer.rect) === null || _originalContainer$re === void 0 ? void 0 : _originalContainer$re.current;
31
+ if (!originalRect) return null;
32
+
33
+ if (originalRect.offsetLeft <= collisionRect.offsetLeft && collisionRect.offsetLeft <= originalRect.offsetLeft + originalRect.width) {
34
+ return originalContainer.id;
35
+ }
36
+
37
+ const isLeft = collisionRect.offsetLeft <= originalRect.offsetLeft + collisionRect.width / 2 + 5;
38
+ let match = null; // If going to the left, search the closest offset left
39
+ // Otherwise, get the closest offset right
40
+
41
+ const collisionPoint = collisionRect.offsetLeft + collisionRect.width / 2;
42
+ entriesWithSameParent.forEach(entry => {
43
+ const {
44
+ rect: {
45
+ current: rect
46
+ }
47
+ } = entry;
48
+
49
+ if (rect !== null) {
50
+ const offsetRight = rect.offsetLeft + rect.width;
51
+
52
+ if (!match) {
53
+ match = entry;
54
+ } else if (match && match.rect.current && isLeft && Math.abs(collisionPoint - rect.offsetLeft) <= Math.abs(collisionPoint - match.rect.current.offsetLeft)) {
55
+ match = entry;
56
+ } else if (match && match.rect.current && !isLeft && Math.abs(collisionPoint - offsetRight) <= Math.abs(collisionPoint - match.rect.current.offsetLeft - match.rect.current.width)) {
57
+ match = entry;
58
+ }
59
+ }
60
+ }); // Typescript believes match is always null for some reason
61
+
62
+ const matchCastedForSomeReason = match;
63
+ return matchCastedForSomeReason === null ? null : matchCastedForSomeReason.id;
64
+ };
65
+
66
+ export { customCollisionDetection };