@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,71 @@
1
+ import { arrayMove } from '@dnd-kit/sortable';
2
+ import { cloneDeep } from 'lodash';
3
+ import { useCallback } from 'react';
4
+ import { DropIndicatorPosition } from './constants.js';
5
+
6
+ const useTreeActionHandlers = _ref => {
7
+ let {
8
+ handlePreviewDragStart,
9
+ handlePreviewDragMove,
10
+ handlePreviewDragOver,
11
+ handlePreviewDragEnd,
12
+ handlePreviewDragCancel,
13
+ onReorder,
14
+ flattenedItems,
15
+ projected,
16
+ dropIndicatorPosition
17
+ } = _ref;
18
+ const onDragStart = useCallback(e => {
19
+ handlePreviewDragStart(e);
20
+ }, [handlePreviewDragStart]);
21
+ const onDragMove = useCallback(e => {
22
+ handlePreviewDragMove(e);
23
+ }, [handlePreviewDragMove]);
24
+ const onDragOver = useCallback(e => {
25
+ handlePreviewDragOver(e);
26
+ }, [handlePreviewDragOver]);
27
+ const onDragEnd = useCallback(e => {
28
+ handlePreviewDragEnd(e);
29
+ const {
30
+ active,
31
+ over
32
+ } = e;
33
+ if (over === null) return;
34
+ const activeIndex = flattenedItems.findIndex(item => item.uid === active.id);
35
+ let considerExpanding = null;
36
+ let overIndex = flattenedItems.findIndex(item => item.uid === over.id); // If drop indicator is inside, then put it last,
37
+ // It will be reconstructed well later
38
+
39
+ if (dropIndicatorPosition === DropIndicatorPosition.Inside) {
40
+ var _flattenedItems$overI, _flattenedItems$overI2;
41
+
42
+ considerExpanding = over.id;
43
+ 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;
44
+ } // If we are dropping the item in a new position, or new depth
45
+
46
+
47
+ if (projected && (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth)) {
48
+ // Change parent and depth from projected data
49
+ flattenedItems[activeIndex].parentId = projected.parentId;
50
+ flattenedItems[activeIndex].depth = projected.depth; // If same index, don't move the array, just copy it
51
+
52
+ const newFlattenedData = activeIndex !== overIndex ? arrayMove(flattenedItems, activeIndex, overIndex) : cloneDeep(flattenedItems);
53
+ onReorder(newFlattenedData, {
54
+ targetIndex: overIndex,
55
+ fromIndex: activeIndex
56
+ }, considerExpanding || '');
57
+ }
58
+ }, [handlePreviewDragEnd, flattenedItems, projected, onReorder, dropIndicatorPosition]);
59
+ const onDragCancel = useCallback(e => {
60
+ handlePreviewDragCancel(e);
61
+ }, [handlePreviewDragCancel]);
62
+ return {
63
+ onDragStart,
64
+ onDragMove,
65
+ onDragOver,
66
+ onDragEnd,
67
+ onDragCancel
68
+ };
69
+ };
70
+
71
+ export { useTreeActionHandlers };
@@ -0,0 +1,51 @@
1
+ import { useCallback } from 'react';
2
+ import { DropIndicatorPosition } from './constants.js';
3
+
4
+ const useTreeAnnouncements = (visibleItemsDictionary, dropIndicatorPosition) => {
5
+ const onDragStart = useCallback(id => "Picked up draggable item from position ".concat(visibleItemsDictionary[id].realIndex + 1, "."), [visibleItemsDictionary]);
6
+ const onDragMove = useCallback((id, overId) => {
7
+ if (overId) {
8
+ const overIndex = visibleItemsDictionary[overId].realIndex + 1;
9
+
10
+ if (dropIndicatorPosition === DropIndicatorPosition.Inside) {
11
+ return "Draggable item was moved inside the item at position ".concat(overIndex, ".");
12
+ }
13
+
14
+ if (dropIndicatorPosition === DropIndicatorPosition.Before) {
15
+ return "Draggable item was moved to position ".concat(overIndex - 1, ".");
16
+ }
17
+
18
+ return "Draggable item was moved to position ".concat(overIndex, ".");
19
+ }
20
+
21
+ return "Draggable item is no longer over a droppable area.";
22
+ }, [visibleItemsDictionary, dropIndicatorPosition]);
23
+ const onDragOver = onDragMove;
24
+ const onDragEnd = useCallback((id, overId) => {
25
+ if (overId) {
26
+ const overIndex = visibleItemsDictionary[overId].realIndex + 1;
27
+
28
+ if (dropIndicatorPosition === DropIndicatorPosition.Inside) {
29
+ return "Draggable item was dropped inside the item at position ".concat(overIndex, ".");
30
+ }
31
+
32
+ if (dropIndicatorPosition === DropIndicatorPosition.Before) {
33
+ return "Draggable item was dropped over position ".concat(overIndex - 1, ".");
34
+ }
35
+
36
+ return "Draggable item was dropped over position ".concat(overIndex, ".");
37
+ }
38
+
39
+ return "Draggable item was dropped at it's original position.";
40
+ }, [dropIndicatorPosition, visibleItemsDictionary]);
41
+ const onDragCancel = useCallback(id => "Dragging was cancelled. Draggable item from position ".concat(visibleItemsDictionary[id].realIndex + 1, " was dropped at it's initial position."), [visibleItemsDictionary]);
42
+ return {
43
+ onDragStart,
44
+ onDragOver,
45
+ onDragMove,
46
+ onDragEnd,
47
+ onDragCancel
48
+ };
49
+ };
50
+
51
+ export { useTreeAnnouncements };
@@ -0,0 +1,134 @@
1
+ import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.filter.js';
3
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
4
+ import 'core-js/modules/web.dom-collections.iterator.js';
5
+ import 'core-js/modules/esnext.async-iterator.map.js';
6
+ import 'core-js/modules/esnext.iterator.map.js';
7
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
8
+ import 'core-js/modules/esnext.iterator.constructor.js';
9
+ import 'core-js/modules/esnext.iterator.for-each.js';
10
+ import { useState, useMemo, useRef, useEffect } from 'react';
11
+ import { MeasuringStrategy, useSensors, useSensor, PointerSensor, KeyboardSensor } from '@dnd-kit/core';
12
+ import { horizontalListSortingStrategy, verticalListSortingStrategy } from '@dnd-kit/sortable';
13
+ import { useTreePreviewHandlers } from './useTreePreviewHandlers.js';
14
+ import { getTreeKeyboardCoordinates } from './getTreeKeyboardCoordinates.js';
15
+ import { removeChildrenOf, getProjection } from './utilities.js';
16
+ import { useTreeActionHandlers } from './useTreeActionHandlers.js';
17
+ import { DropIndicatorPosition } from './constants.js';
18
+ import { customCollisionDetection } from './customCollisionDetection.js';
19
+ import { useTreeAnnouncements } from './useTreeAnnouncements.js';
20
+
21
+ 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; }
22
+
23
+ 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(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; }
24
+ // if second parameter is true, the space will be done on the horizontal axis
25
+
26
+ const adjustTranslate = isHorizontalDnD => _ref => {
27
+ let {
28
+ transform
29
+ } = _ref;
30
+
31
+ const newTransform = _objectSpread({}, transform);
32
+
33
+ if (isHorizontalDnD) {
34
+ newTransform.x = transform.x + 25;
35
+ } else {
36
+ newTransform.x = transform.x + 15;
37
+ }
38
+
39
+ return newTransform;
40
+ };
41
+
42
+ const measuring = {
43
+ droppable: {
44
+ strategy: MeasuringStrategy.BeforeDragging
45
+ }
46
+ };
47
+ const useTreeDndkitConfig = _ref2 => {
48
+ var _visibleItemsDictiona, _visibleItemsDictiona2;
49
+
50
+ let {
51
+ flattenedItems,
52
+ visibleItems: preVisibleItems,
53
+ isHorizontalDnD = false,
54
+ isExpandable = false,
55
+ onReorder,
56
+ maxDragAndDropLevel
57
+ } = _ref2;
58
+ const [activeId, setActiveId] = useState('');
59
+ const [overId, setOverId] = useState('');
60
+ const [dropIndicatorPosition, setDropIndicatorPosition] = useState(DropIndicatorPosition.None);
61
+ const [lastPosition, setLastPosition] = useState(''); // Remove activeId's children
62
+
63
+ const visibleItems = useMemo(() => removeChildrenOf(preVisibleItems, activeId), [preVisibleItems, activeId]); // Sorted ids for the library
64
+
65
+ const sortedIds = useMemo(() => visibleItems.map(item => item.uid), [visibleItems]);
66
+ /**
67
+ * Dictionary from UID to ITEM
68
+ * This dictionary is computed since on every DnD move, I need to know the
69
+ * depth of a particular row, so O(1) per DnD move instead of O(#ITEMS)
70
+ */
71
+
72
+ const visibleItemsDictionary = useMemo(() => {
73
+ // Using plain for to achieve O(#ITEMS) performance
74
+ const dictionary = {};
75
+ visibleItems.forEach(item => {
76
+ dictionary[item.uid] = item;
77
+ });
78
+ return dictionary;
79
+ }, [visibleItems]);
80
+ const modifiers = useMemo(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
81
+ const sensorContext = useRef({
82
+ items: visibleItems,
83
+ dropIndicatorPosition,
84
+ setDropIndicatorPosition
85
+ });
86
+ useEffect(() => {
87
+ sensorContext.current = {
88
+ items: visibleItems,
89
+ dropIndicatorPosition,
90
+ setDropIndicatorPosition
91
+ };
92
+ }, [visibleItems, dropIndicatorPosition, setDropIndicatorPosition]);
93
+ const coordinateGetter = useMemo(() => getTreeKeyboardCoordinates(sensorContext, isHorizontalDnD, maxDragAndDropLevel), [sensorContext, isHorizontalDnD, maxDragAndDropLevel]);
94
+ const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, {
95
+ coordinateGetter
96
+ })); // where is the activeItem being positioned (depth and parent)
97
+
98
+ const projected = useMemo(() => overId ? getProjection(visibleItems, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) : null, [overId, visibleItems, visibleItemsDictionary, dropIndicatorPosition, isExpandable]);
99
+ const dragPreviewHandlers = useTreePreviewHandlers({
100
+ setActiveId,
101
+ setOverId,
102
+ setDropIndicatorPosition
103
+ });
104
+ const dragActionHandlers = useTreeActionHandlers(_objectSpread(_objectSpread({}, dragPreviewHandlers), {}, {
105
+ onReorder,
106
+ projected,
107
+ flattenedItems,
108
+ dropIndicatorPosition
109
+ }));
110
+ const announcements = useTreeAnnouncements(visibleItemsDictionary, dropIndicatorPosition);
111
+ const dndContextProps = useMemo(() => _objectSpread({
112
+ announcements,
113
+ modifiers,
114
+ sensors,
115
+ measuring,
116
+ collisionDetection: customCollisionDetection(activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition)
117
+ }, dragActionHandlers), [announcements, modifiers, sensors, dragActionHandlers, visibleItemsDictionary, setDropIndicatorPosition, activeId, maxDragAndDropLevel, lastPosition, setLastPosition]);
118
+ const sortableContextProps = useMemo(() => ({
119
+ items: sortedIds,
120
+ strategy: isHorizontalDnD ? horizontalListSortingStrategy : verticalListSortingStrategy
121
+ }), [sortedIds, isHorizontalDnD]);
122
+ return {
123
+ dndContextProps,
124
+ sortableContextProps,
125
+ activeId,
126
+ activeIndex: (_visibleItemsDictiona = (_visibleItemsDictiona2 = visibleItemsDictionary[activeId]) === null || _visibleItemsDictiona2 === void 0 ? void 0 : _visibleItemsDictiona2.realIndex) !== null && _visibleItemsDictiona !== void 0 ? _visibleItemsDictiona : -1,
127
+ overId,
128
+ depth: projected ? projected.depth : 0,
129
+ dropIndicatorPosition,
130
+ visibleItems
131
+ };
132
+ };
133
+
134
+ export { useTreeDndkitConfig };
@@ -0,0 +1,50 @@
1
+ import { useCallback } from 'react';
2
+ import { DropIndicatorPosition } from './constants.js';
3
+
4
+ const useTreePreviewHandlers = _ref => {
5
+ let {
6
+ setOverId,
7
+ setActiveId,
8
+ setDropIndicatorPosition
9
+ } = _ref;
10
+ const resetState = useCallback(() => {
11
+ setOverId('');
12
+ setActiveId('');
13
+ document.body.style.setProperty('cursor', '');
14
+ }, [setOverId, setActiveId]);
15
+ const handlePreviewDragStart = useCallback(_ref2 => {
16
+ let {
17
+ active: {
18
+ id
19
+ }
20
+ } = _ref2;
21
+ setActiveId(id);
22
+ setOverId(id);
23
+ setDropIndicatorPosition(DropIndicatorPosition.Inside);
24
+ document.body.style.setProperty('cursor', 'grabbing');
25
+ }, [setActiveId, setDropIndicatorPosition, setOverId]);
26
+ const handlePreviewDragMove = useCallback(() => null, []);
27
+ const handlePreviewDragOver = useCallback(_ref3 => {
28
+ var _over$id;
29
+
30
+ let {
31
+ over
32
+ } = _ref3;
33
+ setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : '');
34
+ }, [setOverId]);
35
+ const handlePreviewDragEnd = useCallback(() => {
36
+ resetState();
37
+ }, [resetState]);
38
+ const handlePreviewDragCancel = useCallback(() => {
39
+ resetState();
40
+ }, [resetState]);
41
+ return {
42
+ handlePreviewDragStart,
43
+ handlePreviewDragMove,
44
+ handlePreviewDragOver,
45
+ handlePreviewDragEnd,
46
+ handlePreviewDragCancel
47
+ };
48
+ };
49
+
50
+ export { useTreePreviewHandlers };
@@ -0,0 +1,47 @@
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 { DropIndicatorPosition } from './constants.js';
5
+
6
+ const getMinDepth = item => {
7
+ if (item) return item.depth;
8
+ return 0;
9
+ };
10
+
11
+ const getProjection = (items, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) => {
12
+ const overItemIndex = visibleItemsDictionary[overId].realIndex;
13
+ const previousItem = items[overItemIndex];
14
+ const nextItem = items[overItemIndex + 1];
15
+
16
+ if (dropIndicatorPosition === DropIndicatorPosition.Inside && isExpandable) {
17
+ return {
18
+ depth: visibleItemsDictionary[overId].depth + 1,
19
+ parentId: overId
20
+ };
21
+ }
22
+
23
+ if (dropIndicatorPosition === DropIndicatorPosition.Before) {
24
+ return {
25
+ depth: getMinDepth(previousItem),
26
+ parentId: previousItem.parentId
27
+ };
28
+ }
29
+
30
+ return {
31
+ depth: getMinDepth(nextItem),
32
+ parentId: nextItem === null || nextItem === void 0 ? void 0 : nextItem.parentId
33
+ };
34
+ };
35
+ const removeChildrenOf = (items, id) => {
36
+ const excludeParentIds = [id];
37
+ return items.filter(item => {
38
+ if (item.parentId !== null && excludeParentIds.includes(item.parentId)) {
39
+ excludeParentIds.push(item.uid);
40
+ return false;
41
+ }
42
+
43
+ return true;
44
+ });
45
+ };
46
+
47
+ export { getProjection, removeChildrenOf };
package/package.json ADDED
@@ -0,0 +1,125 @@
1
+ {
2
+ "name": "@elliemae/ds-drag-and-drop",
3
+ "version": "2.0.0-rc.10",
4
+ "license": "MIT",
5
+ "description": "ICE MT - Dimsum - Drag And Drop",
6
+ "module": "./esm/index.js",
7
+ "main": "./cjs/index.js",
8
+ "types": "./types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./esm/index.js",
12
+ "require": "./cjs/index.js"
13
+ },
14
+ "./tree/utilities": {
15
+ "import": "./esm/tree/utilities.js",
16
+ "require": "./cjs/tree/utilities.js"
17
+ },
18
+ "./tree/useTreePreviewHandlers": {
19
+ "import": "./esm/tree/useTreePreviewHandlers.js",
20
+ "require": "./cjs/tree/useTreePreviewHandlers.js"
21
+ },
22
+ "./tree/useTreeDndkitConfig": {
23
+ "import": "./esm/tree/useTreeDndkitConfig.js",
24
+ "require": "./cjs/tree/useTreeDndkitConfig.js"
25
+ },
26
+ "./tree/useTreeAnnouncements": {
27
+ "import": "./esm/tree/useTreeAnnouncements.js",
28
+ "require": "./cjs/tree/useTreeAnnouncements.js"
29
+ },
30
+ "./tree/useTreeActionHandlers": {
31
+ "import": "./esm/tree/useTreeActionHandlers.js",
32
+ "require": "./cjs/tree/useTreeActionHandlers.js"
33
+ },
34
+ "./tree/types": {
35
+ "import": "./esm/tree/types.js",
36
+ "require": "./cjs/tree/types.js"
37
+ },
38
+ "./tree": {
39
+ "import": "./esm/tree/index.js",
40
+ "require": "./cjs/tree/index.js"
41
+ },
42
+ "./tree/getTreeKeyboardCoordinates": {
43
+ "import": "./esm/tree/getTreeKeyboardCoordinates.js",
44
+ "require": "./cjs/tree/getTreeKeyboardCoordinates.js"
45
+ },
46
+ "./tree/customCollisionDetection": {
47
+ "import": "./esm/tree/customCollisionDetection.js",
48
+ "require": "./cjs/tree/customCollisionDetection.js"
49
+ },
50
+ "./tree/constants": {
51
+ "import": "./esm/tree/constants.js",
52
+ "require": "./cjs/tree/constants.js"
53
+ },
54
+ "./hierarchy/useHierarchyPreviewHandlers": {
55
+ "import": "./esm/hierarchy/useHierarchyPreviewHandlers.js",
56
+ "require": "./cjs/hierarchy/useHierarchyPreviewHandlers.js"
57
+ },
58
+ "./hierarchy/useHierarchyDndkitConfig": {
59
+ "import": "./esm/hierarchy/useHierarchyDndkitConfig.js",
60
+ "require": "./cjs/hierarchy/useHierarchyDndkitConfig.js"
61
+ },
62
+ "./hierarchy/useHierarchyAnnouncements": {
63
+ "import": "./esm/hierarchy/useHierarchyAnnouncements.js",
64
+ "require": "./cjs/hierarchy/useHierarchyAnnouncements.js"
65
+ },
66
+ "./hierarchy/useHierarchyActionHandlers": {
67
+ "import": "./esm/hierarchy/useHierarchyActionHandlers.js",
68
+ "require": "./cjs/hierarchy/useHierarchyActionHandlers.js"
69
+ },
70
+ "./hierarchy/types": {
71
+ "import": "./esm/hierarchy/types.js",
72
+ "require": "./cjs/hierarchy/types.js"
73
+ },
74
+ "./hierarchy": {
75
+ "import": "./esm/hierarchy/index.js",
76
+ "require": "./cjs/hierarchy/index.js"
77
+ },
78
+ "./hierarchy/getHierarchyKeyboardCoordinates": {
79
+ "import": "./esm/hierarchy/getHierarchyKeyboardCoordinates.js",
80
+ "require": "./cjs/hierarchy/getHierarchyKeyboardCoordinates.js"
81
+ },
82
+ "./hierarchy/customCollisionDetection": {
83
+ "import": "./esm/hierarchy/customCollisionDetection.js",
84
+ "require": "./cjs/hierarchy/customCollisionDetection.js"
85
+ }
86
+ },
87
+ "sideEffects": [
88
+ "*.css",
89
+ "*.scss"
90
+ ],
91
+ "repository": {
92
+ "type": "git",
93
+ "url": "https://git.elliemae.io/platform-ui/dimsum.git"
94
+ },
95
+ "engines": {
96
+ "npm": ">=7",
97
+ "node": ">=14"
98
+ },
99
+ "author": "ICE MT",
100
+ "scripts": {
101
+ "dev": "cross-env NODE_ENV=development && node ../../scripts/build/build.js -w",
102
+ "prebuild": "exit 0",
103
+ "predev": "exit 0",
104
+ "build": "node ../../scripts/build/build.js"
105
+ },
106
+ "dependencies": {
107
+ "@dnd-kit/core": "~4.0.1",
108
+ "@dnd-kit/sortable": "~5.0.0",
109
+ "react-desc": "~4.1.3"
110
+ },
111
+ "devDependencies": {
112
+ "styled-components": "~5.3.3"
113
+ },
114
+ "peerDependencies": {
115
+ "lodash": "^4.17.21",
116
+ "react": "^17.0.2",
117
+ "react-dom": "^17.0.2",
118
+ "styled-components": "^5.3.3"
119
+ },
120
+ "publishConfig": {
121
+ "access": "public",
122
+ "directory": "dist",
123
+ "generateSubmodules": true
124
+ }
125
+ }
@@ -0,0 +1,3 @@
1
+ import { CollisionDetection } from '@dnd-kit/core';
2
+ import { Item } from './types';
3
+ export declare const customCollisionDetection: (activeId: string | null, activeParent: string | undefined, dndItems: Item[]) => CollisionDetection;
@@ -0,0 +1,3 @@
1
+ import { KeyboardCoordinateGetter } from '@dnd-kit/core';
2
+ import { SensorContext } from './types';
3
+ export declare const getHierarchyKeyboardCoordinates: (context: SensorContext, dragOverlayDataTestid: string, isHorizontalDnD: boolean) => KeyboardCoordinateGetter;
@@ -0,0 +1 @@
1
+ export * from './useHierarchyDndkitConfig';
@@ -0,0 +1,82 @@
1
+ import type { Active, Announcements, CollisionDetection, DragEndEvent, DragMoveEvent, DragOverEvent, DragStartEvent, MeasuringConfiguration, Modifier, Over, SensorDescriptor, SensorOptions } from '@dnd-kit/core';
2
+ import { DroppableContainers } from '@dnd-kit/core/dist/store';
3
+ import { Coordinates, DragCancelEvent, ViewRect } from '@dnd-kit/core/dist/types';
4
+ import { MutableRefObject } from 'react';
5
+ export declare type Item = {
6
+ id: string;
7
+ depth: number;
8
+ parentId: string;
9
+ index: number;
10
+ };
11
+ export declare type DndContextPropsType = {
12
+ announcements: Announcements;
13
+ modifiers: Modifier[];
14
+ sensors: SensorDescriptor<SensorOptions>[];
15
+ measuring: Partial<MeasuringConfiguration>;
16
+ collisionDetection: CollisionDetection;
17
+ onDragStart: (e: DragStartEvent) => void;
18
+ onDragMove: (e: DragMoveEvent) => void;
19
+ onDragOver: (e: DragOverEvent) => void;
20
+ onDragEnd: (e: DragEndEvent) => void;
21
+ onDragCancel: (e: DragCancelEvent) => void;
22
+ };
23
+ export declare type useHierarchyPreviewHandlersReturn = {
24
+ handlePreviewDragStart: (e: DragStartEvent) => void;
25
+ handlePreviewDragMove: (e: DragMoveEvent) => void;
26
+ handlePreviewDragOver: (e: DragOverEvent) => void;
27
+ handlePreviewDragEnd: (e: DragEndEvent) => void;
28
+ handlePreviewDragCancel: (e: DragCancelEvent) => void;
29
+ };
30
+ export declare type useHierarchyPreviewHandlersArgs = {
31
+ setOverId: React.Dispatch<React.SetStateAction<string>>;
32
+ setActiveId: React.Dispatch<React.SetStateAction<string>>;
33
+ onPreviewResetState: () => void;
34
+ onPreviewDragStart: () => void;
35
+ };
36
+ export declare type useHierarchyActionHandlersArgs = useHierarchyPreviewHandlersReturn & {
37
+ dndItems: Item[];
38
+ onReorder: (movedItem: Item, indexes: {
39
+ targetIndex: number;
40
+ fromIndex: number;
41
+ }) => void;
42
+ };
43
+ export declare type useHierarchyActionHandlersReturn = {
44
+ onDragStart: (e: DragStartEvent) => void;
45
+ onDragMove: (e: DragMoveEvent) => void;
46
+ onDragOver: (e: DragOverEvent) => void;
47
+ onDragEnd: (e: DragEndEvent) => void;
48
+ onDragCancel: (e: DragCancelEvent) => void;
49
+ };
50
+ export declare type useHierarchyDndkitConfigArgs = {
51
+ indentationWidth?: number;
52
+ dragOverlayDataTestid: string;
53
+ flattenedItems: [Item, unknown][];
54
+ isHorizontalDnD?: boolean;
55
+ onReorder: (movedItem: Item, indexes: {
56
+ targetIndex: number;
57
+ fromIndex: number;
58
+ }) => void;
59
+ onPreviewResetState: () => void;
60
+ onPreviewDragStart: () => void;
61
+ };
62
+ export declare type useHierarchyDndkitConfigType = (args: useHierarchyDndkitConfigArgs) => useHierarchyDndkitConfigReturn;
63
+ export declare type useHierarchyDndkitConfigReturn = {
64
+ dndContextProps: DndContextPropsType;
65
+ activeId: string | null;
66
+ overId: string | null;
67
+ activeIndex: number | undefined;
68
+ };
69
+ export declare type getKeyboardCoordinatesArgs = {
70
+ items: Item[];
71
+ active: Active | null;
72
+ over: Over | null;
73
+ event: KeyboardEvent;
74
+ currentCoordinates: Coordinates;
75
+ droppableContainers: DroppableContainers;
76
+ collisionRect: ViewRect;
77
+ dragOverlayDataTestid: string;
78
+ };
79
+ export declare type SensorContext = MutableRefObject<{
80
+ items: Item[];
81
+ offset?: number;
82
+ }>;
@@ -0,0 +1,2 @@
1
+ import { useHierarchyActionHandlersReturn, useHierarchyActionHandlersArgs } from './types';
2
+ export declare const useHierarchyActionHandlers: ({ handlePreviewDragStart, handlePreviewDragMove, handlePreviewDragOver, handlePreviewDragEnd, handlePreviewDragCancel, onReorder, dndItems, }: useHierarchyActionHandlersArgs) => useHierarchyActionHandlersReturn;
@@ -0,0 +1,3 @@
1
+ import { Announcements } from '@dnd-kit/core';
2
+ import { Item } from './types';
3
+ export declare const useHierarchyAnnouncements: (visibleItemsDictionary: Record<string, Item>) => Announcements;
@@ -0,0 +1,2 @@
1
+ import type { useHierarchyDndkitConfigType } from './types';
2
+ export declare const useHierarchyDndkitConfig: useHierarchyDndkitConfigType;
@@ -0,0 +1,2 @@
1
+ import type { useHierarchyPreviewHandlersReturn, useHierarchyPreviewHandlersArgs } from './types';
2
+ export declare const useHierarchyPreviewHandlers: ({ setOverId, setActiveId, onPreviewResetState, onPreviewDragStart, }: useHierarchyPreviewHandlersArgs) => useHierarchyPreviewHandlersReturn;
@@ -0,0 +1,2 @@
1
+ export * from './hierarchy';
2
+ export * from './tree';
@@ -0,0 +1,6 @@
1
+ export declare enum DropIndicatorPosition {
2
+ None = 0,
3
+ Before = 1,
4
+ After = 2,
5
+ Inside = 3
6
+ }
@@ -0,0 +1,4 @@
1
+ import { CollisionDetection } from '@dnd-kit/core';
2
+ import { DropIndicatorPosition } from './constants';
3
+ import { Item } from './types';
4
+ export declare const customCollisionDetection: (activeId: string, visibleItemsDictionary: Record<string, Item>, setDropIndicatorPosition: React.Dispatch<React.SetStateAction<DropIndicatorPosition>>, maxDragAndDropLevel: number, lastPosition: string, setLastPosition: React.Dispatch<React.SetStateAction<string>>) => CollisionDetection;
@@ -0,0 +1,3 @@
1
+ import { KeyboardCoordinateGetter } from '@dnd-kit/core';
2
+ import type { SensorContext } from './types';
3
+ export declare const getTreeKeyboardCoordinates: (context: SensorContext, isHorizontalDnD: boolean, maxDragAndDropLevel: number) => KeyboardCoordinateGetter;
@@ -0,0 +1 @@
1
+ export * from './useTreeDndkitConfig';