@elliemae/ds-drag-and-drop 2.0.0-rc.10

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 +75 -0
  2. package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js +126 -0
  3. package/cjs/hierarchy/index.js +9 -0
  4. package/cjs/hierarchy/types.js +2 -0
  5. package/cjs/hierarchy/useHierarchyActionHandlers.js +55 -0
  6. package/cjs/hierarchy/useHierarchyAnnouncements.js +36 -0
  7. package/cjs/hierarchy/useHierarchyDndkitConfig.js +122 -0
  8. package/cjs/hierarchy/useHierarchyPreviewHandlers.js +55 -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 +71 -0
  21. package/esm/hierarchy/getHierarchyKeyboardCoordinates.js +118 -0
  22. package/esm/hierarchy/index.js +1 -0
  23. package/esm/hierarchy/types.js +1 -0
  24. package/esm/hierarchy/useHierarchyActionHandlers.js +51 -0
  25. package/esm/hierarchy/useHierarchyAnnouncements.js +32 -0
  26. package/esm/hierarchy/useHierarchyDndkitConfig.js +114 -0
  27. package/esm/hierarchy/useHierarchyPreviewHandlers.js +51 -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 +82 -0
  44. package/types/hierarchy/useHierarchyActionHandlers.d.ts +2 -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,75 @@
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
+ require('core-js/modules/esnext.async-iterator.find.js');
9
+ require('core-js/modules/esnext.iterator.find.js');
10
+ require('core-js/modules/esnext.async-iterator.for-each.js');
11
+ require('core-js/modules/esnext.iterator.for-each.js');
12
+
13
+ const customCollisionDetection = (activeId, activeParent, dndItems) => _ref => {
14
+ var _droppableContainers$, _droppableContainers$2, _originalContainer$re;
15
+
16
+ let {
17
+ droppableContainers,
18
+ collisionRect,
19
+ active
20
+ } = _ref;
21
+ const entriesWithSameParent = droppableContainers.filter(_ref2 => {
22
+ var _dndItems$find;
23
+
24
+ let {
25
+ id
26
+ } = _ref2;
27
+ return ((_dndItems$find = dndItems.find(item => item.id === id)) === null || _dndItems$find === void 0 ? void 0 : _dndItems$find.parentId) === activeParent;
28
+ });
29
+ const dragOverlayRect = (_droppableContainers$ = droppableContainers.find(_ref3 => {
30
+ let {
31
+ id
32
+ } = _ref3;
33
+ return id === active.id;
34
+ })) === null || _droppableContainers$ === void 0 ? void 0 : (_droppableContainers$2 = _droppableContainers$.rect) === null || _droppableContainers$2 === void 0 ? void 0 : _droppableContainers$2.current;
35
+ const originalContainer = entriesWithSameParent.find(_ref4 => {
36
+ let {
37
+ id
38
+ } = _ref4;
39
+ return id === activeId;
40
+ });
41
+ const originalRect = originalContainer === null || originalContainer === void 0 ? void 0 : (_originalContainer$re = originalContainer.rect) === null || _originalContainer$re === void 0 ? void 0 : _originalContainer$re.current;
42
+ if (!originalRect || !dragOverlayRect) return undefined;
43
+
44
+ if (originalRect.offsetLeft <= collisionRect.offsetLeft && collisionRect.offsetLeft <= originalRect.offsetLeft + originalRect.width) {
45
+ return originalContainer.id;
46
+ }
47
+
48
+ const isLeft = collisionRect.offsetLeft <= originalRect.offsetLeft + dragOverlayRect.width / 2 + 5;
49
+ let match = null; // If going to the left, search the closest offset left
50
+ // Otherwise, get the closest offset right
51
+
52
+ const collisionPoint = collisionRect.offsetLeft + dragOverlayRect.width / 2;
53
+ entriesWithSameParent.forEach(entry => {
54
+ const {
55
+ rect: {
56
+ current: rect
57
+ }
58
+ } = entry;
59
+
60
+ if (rect) {
61
+ const offsetRight = rect.offsetLeft + rect.width;
62
+
63
+ if (!match) {
64
+ match = entry;
65
+ } else if (match && match.rect.current && isLeft && Math.abs(collisionPoint - rect.offsetLeft) <= Math.abs(collisionPoint - match.rect.current.offsetLeft)) {
66
+ match = entry;
67
+ } else if (match && match.rect.current && !isLeft && Math.abs(collisionPoint - offsetRight) <= Math.abs(collisionPoint - match.rect.current.offsetLeft - match.rect.current.width)) {
68
+ match = entry;
69
+ }
70
+ }
71
+ });
72
+ return match === null ? null : match.id;
73
+ };
74
+
75
+ exports.customCollisionDetection = customCollisionDetection;
@@ -0,0 +1,126 @@
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.find.js');
7
+ require('core-js/modules/esnext.iterator.constructor.js');
8
+ require('core-js/modules/esnext.iterator.find.js');
9
+ require('core-js/modules/esnext.async-iterator.for-each.js');
10
+ require('core-js/modules/esnext.iterator.for-each.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
+
15
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
+
17
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
18
+
19
+ 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; }
20
+
21
+ 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; }
22
+ const directions = [core.KeyboardCode.Down, core.KeyboardCode.Right, core.KeyboardCode.Up, core.KeyboardCode.Left];
23
+ const vertical = [core.KeyboardCode.Up, core.KeyboardCode.Down];
24
+
25
+ const getHorizontalKeyboardCoordinates = _ref => {
26
+ var _document$querySelect, _document$querySelect2, _droppableContainers$, _droppableContainers$2, _droppableContainers$3, _droppableContainers$4;
27
+
28
+ let {
29
+ items,
30
+ active,
31
+ over,
32
+ event,
33
+ currentCoordinates,
34
+ droppableContainers,
35
+ collisionRect,
36
+ dragOverlayDataTestid
37
+ } = _ref;
38
+ if (vertical.includes(event.code) || !active || !over) return undefined;
39
+ const activeItem = items.find(item => item.id === active.id);
40
+ const overRect = over.rect;
41
+ const layoutRects = []; // Get the reacheable rects depending on the arrow key pressed
42
+
43
+ droppableContainers.forEach(container => {
44
+ var _items$find;
45
+
46
+ if (container !== null && container !== void 0 && container.disabled || !overRect) {
47
+ return;
48
+ }
49
+
50
+ const node = container === null || container === void 0 ? void 0 : container.node.current;
51
+
52
+ if (!node) {
53
+ return;
54
+ }
55
+
56
+ const itemParent = (_items$find = items.find(item => item.id === container.id)) === null || _items$find === void 0 ? void 0 : _items$find.parentId;
57
+ if (itemParent !== (activeItem === null || activeItem === void 0 ? void 0 : activeItem.parentId)) return;
58
+ const rect = core.getViewRect(node);
59
+
60
+ if (event.code === core.KeyboardCode.Left && collisionRect.left > rect.right - 10) {
61
+ layoutRects.push(container);
62
+ } else if (event.code === core.KeyboardCode.Right && collisionRect.left < rect.left) {
63
+ layoutRects.push(container);
64
+ }
65
+ });
66
+ const dragOverlayRect = (_document$querySelect = (_document$querySelect2 = document.querySelector("[data-testid=\"".concat(dragOverlayDataTestid, "\"]"))) === null || _document$querySelect2 === void 0 ? void 0 : _document$querySelect2.getBoundingClientRect()) !== null && _document$querySelect !== void 0 ? _document$querySelect : {
67
+ width: 150,
68
+ left: 0
69
+ };
70
+ const closestId = core.closestCorners({
71
+ droppableContainers: layoutRects,
72
+ collisionRect,
73
+ active
74
+ });
75
+ if (!closestId) return undefined;
76
+ const closestDroppableContainer = (_droppableContainers$ = droppableContainers.get(closestId)) === null || _droppableContainers$ === void 0 ? void 0 : (_droppableContainers$2 = _droppableContainers$.node) === null || _droppableContainers$2 === void 0 ? void 0 : _droppableContainers$2.current;
77
+ const activeDroppableContainer = (_droppableContainers$3 = droppableContainers.get(active === null || active === void 0 ? void 0 : active.id)) === null || _droppableContainers$3 === void 0 ? void 0 : (_droppableContainers$4 = _droppableContainers$3.node) === null || _droppableContainers$4 === void 0 ? void 0 : _droppableContainers$4.current;
78
+ if (!closestDroppableContainer || !activeDroppableContainer) return undefined;
79
+ const closestRect = core.getViewRect(closestDroppableContainer);
80
+ const activeRect = core.getViewRect(activeDroppableContainer);
81
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
82
+ x: closestRect.left + (closestRect.width - dragOverlayRect.width) / 2 + (closestRect.offsetLeft < activeRect.left ? -1 : 1)
83
+ });
84
+ };
85
+
86
+ const getHierarchyKeyboardCoordinates = (context, dragOverlayDataTestid, isHorizontalDnD) => (event, _ref2) => {
87
+ let {
88
+ currentCoordinates,
89
+ context: {
90
+ active,
91
+ over,
92
+ collisionRect,
93
+ droppableContainers
94
+ }
95
+ } = _ref2;
96
+
97
+ if (directions.includes(event.code)) {
98
+ event.preventDefault();
99
+
100
+ if (!collisionRect) {
101
+ return undefined;
102
+ }
103
+
104
+ const {
105
+ current: {
106
+ items
107
+ }
108
+ } = context;
109
+ const args = {
110
+ dragOverlayDataTestid,
111
+ items,
112
+ active,
113
+ over,
114
+ event,
115
+ currentCoordinates,
116
+ droppableContainers,
117
+ collisionRect
118
+ };
119
+ if (isHorizontalDnD) return getHorizontalKeyboardCoordinates(args);
120
+ return undefined;
121
+ }
122
+
123
+ return undefined;
124
+ };
125
+
126
+ exports.getHierarchyKeyboardCoordinates = getHierarchyKeyboardCoordinates;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useHierarchyDndkitConfig = require('./useHierarchyDndkitConfig.js');
6
+
7
+
8
+
9
+ exports.useHierarchyDndkitConfig = useHierarchyDndkitConfig.useHierarchyDndkitConfig;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+
7
+ const useHierarchyActionHandlers = _ref => {
8
+ let {
9
+ handlePreviewDragStart,
10
+ handlePreviewDragMove,
11
+ handlePreviewDragOver,
12
+ handlePreviewDragEnd,
13
+ handlePreviewDragCancel,
14
+ onReorder,
15
+ dndItems
16
+ } = _ref;
17
+ const onDragStart = react.useCallback(e => {
18
+ handlePreviewDragStart(e);
19
+ }, [handlePreviewDragStart]);
20
+ const onDragMove = react.useCallback(e => {
21
+ handlePreviewDragMove(e);
22
+ }, [handlePreviewDragMove]);
23
+ const onDragOver = react.useCallback(e => {
24
+ handlePreviewDragOver(e);
25
+ }, [handlePreviewDragOver]);
26
+ const onDragEnd = react.useCallback(e => {
27
+ handlePreviewDragEnd(e);
28
+ const {
29
+ active,
30
+ over
31
+ } = e;
32
+ if (!over) return;
33
+
34
+ if (active.id !== over.id) {
35
+ const activeIndex = dndItems.findIndex(item => item.id === active.id);
36
+ const overIndex = dndItems.findIndex(item => item.id === over.id);
37
+ onReorder(dndItems[activeIndex], {
38
+ targetIndex: overIndex,
39
+ fromIndex: activeIndex
40
+ });
41
+ }
42
+ }, [handlePreviewDragEnd, dndItems, onReorder]);
43
+ const onDragCancel = react.useCallback(e => {
44
+ handlePreviewDragCancel(e);
45
+ }, [handlePreviewDragCancel]);
46
+ return {
47
+ onDragStart,
48
+ onDragMove,
49
+ onDragOver,
50
+ onDragEnd,
51
+ onDragCancel
52
+ };
53
+ };
54
+
55
+ exports.useHierarchyActionHandlers = useHierarchyActionHandlers;
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+
7
+ const useHierarchyAnnouncements = visibleItemsDictionary => {
8
+ const onDragStart = react.useCallback(id => "Picked up draggable item from position ".concat(visibleItemsDictionary[id].index + 1, "."), [visibleItemsDictionary]);
9
+ const onDragMove = react.useCallback((id, overId) => {
10
+ if (overId) {
11
+ const overIndex = visibleItemsDictionary[overId].index + 1;
12
+ return "Draggable item was moved to position ".concat(overIndex, ".");
13
+ }
14
+
15
+ return "Draggable item is no longer over a droppable area.";
16
+ }, [visibleItemsDictionary]);
17
+ const onDragOver = onDragMove;
18
+ const onDragEnd = react.useCallback((id, overId) => {
19
+ if (overId) {
20
+ const overIndex = visibleItemsDictionary[overId].index + 1;
21
+ return "Draggable item was dropped over position ".concat(overIndex, ".");
22
+ }
23
+
24
+ return "Draggable item was dropped at it's original position.";
25
+ }, [visibleItemsDictionary]);
26
+ const onDragCancel = react.useCallback(id => "Dragging was cancelled. Draggable item from position ".concat(visibleItemsDictionary[id].index + 1, " was dropped at it's initial position."), [visibleItemsDictionary]);
27
+ return {
28
+ onDragStart,
29
+ onDragOver,
30
+ onDragMove,
31
+ onDragEnd,
32
+ onDragCancel
33
+ };
34
+ };
35
+
36
+ exports.useHierarchyAnnouncements = useHierarchyAnnouncements;
@@ -0,0 +1,122 @@
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 useHierarchyActionHandlers = require('./useHierarchyActionHandlers.js');
17
+ var useHierarchyPreviewHandlers = require('./useHierarchyPreviewHandlers.js');
18
+ var getHierarchyKeyboardCoordinates = require('./getHierarchyKeyboardCoordinates.js');
19
+ var customCollisionDetection = require('./customCollisionDetection.js');
20
+ var useHierarchyAnnouncements = require('./useHierarchyAnnouncements.js');
21
+
22
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
23
+
24
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
25
+
26
+ 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; }
27
+
28
+ 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; }
29
+ // if second parameter is true, the space will be done on the horizontal axis
30
+
31
+ const adjustTranslate = isHorizontalDnD => _ref => {
32
+ let {
33
+ transform
34
+ } = _ref;
35
+
36
+ const newTransform = _objectSpread({}, transform);
37
+
38
+ if (isHorizontalDnD) {
39
+ newTransform.y = transform.y + 15;
40
+ } else {
41
+ newTransform.y = transform.y - 35;
42
+ }
43
+
44
+ return newTransform;
45
+ };
46
+
47
+ const measuring = {
48
+ droppable: {
49
+ strategy: core.MeasuringStrategy.Always
50
+ }
51
+ };
52
+
53
+ const noop = () => null;
54
+
55
+ const useHierarchyDndkitConfig = _ref2 => {
56
+ var _itemsDictionary$acti;
57
+
58
+ let {
59
+ flattenedItems,
60
+ dragOverlayDataTestid,
61
+ isHorizontalDnD = false,
62
+ onReorder,
63
+ onPreviewResetState = noop,
64
+ onPreviewDragStart = noop
65
+ } = _ref2;
66
+ const [activeId, setActiveId] = react.useState('');
67
+ const [overId, setOverId] = react.useState('');
68
+ const dndItems = react.useMemo(() => flattenedItems.map(_ref3 => {
69
+ let [item] = _ref3;
70
+ return item;
71
+ }), [flattenedItems]);
72
+ const itemsDictionary = react.useMemo(() => {
73
+ const dictionary = {};
74
+ dndItems.forEach(item => {
75
+ dictionary[item.id] = item;
76
+ });
77
+ return dictionary;
78
+ }, [dndItems]);
79
+ const modifiers = react.useMemo(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
80
+ const sensorContext = react.useRef({
81
+ items: dndItems
82
+ });
83
+ react.useEffect(() => {
84
+ sensorContext.current = {
85
+ items: dndItems
86
+ };
87
+ }, [dndItems]);
88
+ const coordinateGetter = react.useMemo(() => getHierarchyKeyboardCoordinates.getHierarchyKeyboardCoordinates(sensorContext, dragOverlayDataTestid, isHorizontalDnD), [isHorizontalDnD]);
89
+ const sensors = core.useSensors(core.useSensor(core.PointerSensor), core.useSensor(core.KeyboardSensor, {
90
+ coordinateGetter
91
+ }));
92
+ const dragPreviewHandlers = useHierarchyPreviewHandlers.useHierarchyPreviewHandlers({
93
+ setActiveId,
94
+ setOverId,
95
+ onPreviewResetState,
96
+ onPreviewDragStart
97
+ });
98
+ const dragActionHandlers = useHierarchyActionHandlers.useHierarchyActionHandlers(_objectSpread(_objectSpread({}, dragPreviewHandlers), {}, {
99
+ dndItems,
100
+ onReorder
101
+ }));
102
+ const announcements = useHierarchyAnnouncements.useHierarchyAnnouncements(itemsDictionary);
103
+ const dndContextProps = react.useMemo(() => {
104
+ var _itemsDictionary;
105
+
106
+ return _objectSpread({
107
+ announcements,
108
+ modifiers,
109
+ sensors,
110
+ measuring,
111
+ collisionDetection: customCollisionDetection.customCollisionDetection(activeId, (_itemsDictionary = itemsDictionary[activeId !== null && activeId !== void 0 ? activeId : '']) === null || _itemsDictionary === void 0 ? void 0 : _itemsDictionary.parentId, dndItems)
112
+ }, dragActionHandlers);
113
+ }, [announcements, modifiers, sensors, activeId, itemsDictionary, dndItems, dragActionHandlers]);
114
+ return {
115
+ dndContextProps,
116
+ activeId,
117
+ overId,
118
+ activeIndex: activeId ? (_itemsDictionary$acti = itemsDictionary[activeId]) === null || _itemsDictionary$acti === void 0 ? void 0 : _itemsDictionary$acti.index : -1
119
+ };
120
+ };
121
+
122
+ exports.useHierarchyDndkitConfig = useHierarchyDndkitConfig;
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+
7
+ const useHierarchyPreviewHandlers = _ref => {
8
+ let {
9
+ setOverId,
10
+ setActiveId,
11
+ onPreviewResetState,
12
+ onPreviewDragStart
13
+ } = _ref;
14
+ const resetState = react.useCallback(() => {
15
+ setOverId('');
16
+ setActiveId('');
17
+ onPreviewResetState();
18
+ document.body.style.setProperty('cursor', '');
19
+ }, [setOverId, setActiveId, onPreviewResetState]);
20
+ const handlePreviewDragStart = react.useCallback(_ref2 => {
21
+ let {
22
+ active: {
23
+ id
24
+ }
25
+ } = _ref2;
26
+ setActiveId(id);
27
+ setOverId(id);
28
+ document.body.style.setProperty('cursor', 'grabbing');
29
+ onPreviewDragStart();
30
+ }, [setActiveId, setOverId, onPreviewDragStart]);
31
+ const handlePreviewDragMove = react.useCallback(() => null, []);
32
+ const handlePreviewDragOver = react.useCallback(_ref3 => {
33
+ var _over$id;
34
+
35
+ let {
36
+ over
37
+ } = _ref3;
38
+ setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : '');
39
+ }, [setOverId]);
40
+ const handlePreviewDragEnd = react.useCallback(() => {
41
+ resetState();
42
+ }, [resetState]);
43
+ const handlePreviewDragCancel = react.useCallback(() => {
44
+ resetState();
45
+ }, [resetState]);
46
+ return {
47
+ handlePreviewDragStart,
48
+ handlePreviewDragMove,
49
+ handlePreviewDragOver,
50
+ handlePreviewDragEnd,
51
+ handlePreviewDragCancel
52
+ };
53
+ };
54
+
55
+ exports.useHierarchyPreviewHandlers = useHierarchyPreviewHandlers;
package/cjs/index.js ADDED
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useHierarchyDndkitConfig = require('./hierarchy/useHierarchyDndkitConfig.js');
6
+ var useTreeDndkitConfig = require('./tree/useTreeDndkitConfig.js');
7
+
8
+
9
+
10
+ exports.useHierarchyDndkitConfig = useHierarchyDndkitConfig.useHierarchyDndkitConfig;
11
+ exports.useTreeDndkitConfig = useTreeDndkitConfig.useTreeDndkitConfig;
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ exports.DropIndicatorPosition = void 0;
6
+
7
+ (function (DropIndicatorPosition) {
8
+ DropIndicatorPosition[DropIndicatorPosition["None"] = 0] = "None";
9
+ DropIndicatorPosition[DropIndicatorPosition["Before"] = 1] = "Before";
10
+ DropIndicatorPosition[DropIndicatorPosition["After"] = 2] = "After";
11
+ DropIndicatorPosition[DropIndicatorPosition["Inside"] = 3] = "Inside";
12
+ })(exports.DropIndicatorPosition || (exports.DropIndicatorPosition = {}));
@@ -0,0 +1,137 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.find.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.find.js');
8
+ require('core-js/modules/esnext.async-iterator.reduce.js');
9
+ require('core-js/modules/esnext.iterator.reduce.js');
10
+ require('core-js/modules/web.dom-collections.iterator.js');
11
+ var constants = require('./constants.js');
12
+
13
+ const DUMMY_ID = 'DUMMY_ID_INTERNAL_USE_ONLY';
14
+ const RECT_UP = {
15
+ offsetTop: -Infinity,
16
+ offsetLeft: 0,
17
+ // Doesn't matter,
18
+ width: 0,
19
+ // Doesn't matter
20
+ height: 0 // Doesn't matter
21
+
22
+ };
23
+ const RECT_DOWN = {
24
+ offsetTop: Infinity,
25
+ offsetLeft: 0,
26
+ // Doesn't matter,
27
+ width: 0,
28
+ // Doesn't matter
29
+ height: 0 // Doesn't matter
30
+
31
+ }; // Percentage of height to take into consideration when looking for colliding rects
32
+
33
+ const thresholdRatio = 0.2; // Percentage to be inside
34
+
35
+ const insideThreshold = 0.7;
36
+ const customCollisionDetection = (activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition) => _ref => {
37
+ var _originalContainer$re;
38
+
39
+ let {
40
+ droppableContainers,
41
+ collisionRect
42
+ } = _ref;
43
+ const originalContainer = droppableContainers.find(_ref2 => {
44
+ let {
45
+ id
46
+ } = _ref2;
47
+ return id === activeId;
48
+ });
49
+ const originalRect = originalContainer === null || originalContainer === void 0 ? void 0 : (_originalContainer$re = originalContainer.rect) === null || _originalContainer$re === void 0 ? void 0 : _originalContainer$re.current; // We first check if the item was moved up or down
50
+ // This modifies how to search the matching colliding rect
51
+
52
+ let isUp = lastPosition === 'up';
53
+
54
+ if (originalRect) {
55
+ isUp = originalRect.offsetTop > collisionRect.top;
56
+ } // Threshold
57
+
58
+
59
+ const threshold = collisionRect.height * thresholdRatio;
60
+ let collidingContainer = null;
61
+
62
+ if (isUp) {
63
+ // Up -- We need to find the first rectangle downwards
64
+ collidingContainer = droppableContainers.reduce((firstRectDown, container) => {
65
+ const rect = container.rect.current;
66
+
67
+ if (rect && firstRectDown.rect.current) {
68
+ const {
69
+ offsetTop: rectOffsetTop
70
+ } = rect;
71
+ const {
72
+ offsetTop: firstRectDownOffsetTop
73
+ } = firstRectDown.rect.current;
74
+
75
+ if (rectOffsetTop + threshold > collisionRect.top && rectOffsetTop < firstRectDownOffsetTop) {
76
+ return container;
77
+ }
78
+ }
79
+
80
+ return firstRectDown;
81
+ }, {
82
+ id: DUMMY_ID,
83
+ rect: {
84
+ current: RECT_DOWN
85
+ }
86
+ });
87
+ } else {
88
+ // Down -- We need to find the first rectangle upwards
89
+ collidingContainer = droppableContainers.reduce((firstRectUp, container) => {
90
+ const rect = container.rect.current;
91
+
92
+ if (rect && firstRectUp.rect.current) {
93
+ const {
94
+ offsetTop: rectOffsetTop
95
+ } = rect;
96
+ const {
97
+ offsetTop: firstRectUpOffsetTop
98
+ } = firstRectUp.rect.current;
99
+
100
+ if (rectOffsetTop - threshold < collisionRect.top && rectOffsetTop > firstRectUpOffsetTop) {
101
+ return container;
102
+ }
103
+ }
104
+
105
+ return firstRectUp;
106
+ }, {
107
+ id: DUMMY_ID,
108
+ rect: {
109
+ current: RECT_UP
110
+ }
111
+ });
112
+ } // If we didn't find a match, return null
113
+
114
+
115
+ if (collidingContainer.id === DUMMY_ID) {
116
+ return null;
117
+ }
118
+
119
+ const collidingRect = collidingContainer.rect.current;
120
+ if (!collidingRect) return null; // Calculate the intersection interval
121
+
122
+ const [top, bottom] = [Math.max(collisionRect.top, collidingRect.offsetTop), Math.min(collisionRect.bottom, collidingRect.offsetTop + collidingRect.height)]; // Calculate the percentage of intersection
123
+
124
+ const intersectionPercentage = Math.abs(bottom - top) / collidingRect.height;
125
+
126
+ if (intersectionPercentage > insideThreshold && visibleItemsDictionary[collidingContainer.id].depth + 1 <= maxDragAndDropLevel && collidingContainer.id !== activeId) {
127
+ setDropIndicatorPosition(constants.DropIndicatorPosition.Inside);
128
+ } else {
129
+ setDropIndicatorPosition(isUp ? constants.DropIndicatorPosition.Before : constants.DropIndicatorPosition.After);
130
+ }
131
+
132
+ if (isUp && lastPosition !== 'up') setLastPosition('up');else if (!isUp && lastPosition !== 'down') setLastPosition('down'); // Return the id of the match rectangle
133
+
134
+ return collidingContainer.id;
135
+ };
136
+
137
+ exports.customCollisionDetection = customCollisionDetection;