@elliemae/ds-drag-and-drop 2.2.0-alpha.3 → 2.2.0-next.2

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 (82) hide show
  1. package/cjs/hierarchy/customCollisionDetection.js +50 -44
  2. package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js +91 -78
  3. package/cjs/hierarchy/index.js +9 -28
  4. package/cjs/hierarchy/types.js +2 -27
  5. package/cjs/hierarchy/useHierarchyActionHandlers.js +35 -53
  6. package/cjs/hierarchy/useHierarchyAnnouncements.js +26 -45
  7. package/cjs/hierarchy/useHierarchyDndkitConfig.js +83 -77
  8. package/cjs/hierarchy/useHierarchyPreviewHandlers.js +27 -48
  9. package/cjs/index.js +11 -29
  10. package/cjs/tree/constants.js +12 -41
  11. package/cjs/tree/customCollisionDetection.js +128 -93
  12. package/cjs/tree/getTreeKeyboardCoordinates.js +100 -87
  13. package/cjs/tree/index.js +9 -28
  14. package/cjs/tree/types.js +2 -27
  15. package/cjs/tree/useTreeActionHandlers.js +56 -67
  16. package/cjs/tree/useTreeAnnouncements.js +40 -53
  17. package/cjs/tree/useTreeDndkitConfig.js +108 -102
  18. package/cjs/tree/useTreePreviewHandlers.js +37 -53
  19. package/cjs/tree/utilities.js +30 -44
  20. package/esm/hierarchy/customCollisionDetection.js +46 -15
  21. package/esm/hierarchy/getHierarchyKeyboardCoordinates.js +76 -42
  22. package/esm/hierarchy/index.js +1 -3
  23. package/esm/hierarchy/types.js +1 -2
  24. package/esm/hierarchy/useHierarchyActionHandlers.js +31 -24
  25. package/esm/hierarchy/useHierarchyAnnouncements.js +20 -14
  26. package/esm/hierarchy/useHierarchyDndkitConfig.js +66 -45
  27. package/esm/hierarchy/useHierarchyPreviewHandlers.js +19 -15
  28. package/esm/index.js +2 -4
  29. package/esm/tree/constants.js +10 -12
  30. package/esm/tree/customCollisionDetection.js +124 -64
  31. package/esm/tree/getTreeKeyboardCoordinates.js +83 -49
  32. package/esm/tree/index.js +1 -3
  33. package/esm/tree/types.js +1 -2
  34. package/esm/tree/useTreeActionHandlers.js +50 -36
  35. package/esm/tree/useTreeAnnouncements.js +30 -18
  36. package/esm/tree/useTreeDndkitConfig.js +89 -68
  37. package/esm/tree/useTreePreviewHandlers.js +28 -19
  38. package/esm/tree/utilities.js +23 -13
  39. package/package.json +1 -1
  40. package/types/hierarchy/types.d.ts +1 -1
  41. package/types/tree/types.d.ts +17 -13
  42. package/types/tree/useTreeActionHandlers.d.ts +2 -2
  43. package/types/tree/useTreeDndkitConfig.d.ts +2 -2
  44. package/types/tree/useTreePreviewHandlers.d.ts +2 -2
  45. package/cjs/hierarchy/customCollisionDetection.js.map +0 -7
  46. package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js.map +0 -7
  47. package/cjs/hierarchy/index.js.map +0 -7
  48. package/cjs/hierarchy/types.js.map +0 -7
  49. package/cjs/hierarchy/useHierarchyActionHandlers.js.map +0 -7
  50. package/cjs/hierarchy/useHierarchyAnnouncements.js.map +0 -7
  51. package/cjs/hierarchy/useHierarchyDndkitConfig.js.map +0 -7
  52. package/cjs/hierarchy/useHierarchyPreviewHandlers.js.map +0 -7
  53. package/cjs/index.js.map +0 -7
  54. package/cjs/tree/constants.js.map +0 -7
  55. package/cjs/tree/customCollisionDetection.js.map +0 -7
  56. package/cjs/tree/getTreeKeyboardCoordinates.js.map +0 -7
  57. package/cjs/tree/index.js.map +0 -7
  58. package/cjs/tree/types.js.map +0 -7
  59. package/cjs/tree/useTreeActionHandlers.js.map +0 -7
  60. package/cjs/tree/useTreeAnnouncements.js.map +0 -7
  61. package/cjs/tree/useTreeDndkitConfig.js.map +0 -7
  62. package/cjs/tree/useTreePreviewHandlers.js.map +0 -7
  63. package/cjs/tree/utilities.js.map +0 -7
  64. package/esm/hierarchy/customCollisionDetection.js.map +0 -7
  65. package/esm/hierarchy/getHierarchyKeyboardCoordinates.js.map +0 -7
  66. package/esm/hierarchy/index.js.map +0 -7
  67. package/esm/hierarchy/types.js.map +0 -7
  68. package/esm/hierarchy/useHierarchyActionHandlers.js.map +0 -7
  69. package/esm/hierarchy/useHierarchyAnnouncements.js.map +0 -7
  70. package/esm/hierarchy/useHierarchyDndkitConfig.js.map +0 -7
  71. package/esm/hierarchy/useHierarchyPreviewHandlers.js.map +0 -7
  72. package/esm/index.js.map +0 -7
  73. package/esm/tree/constants.js.map +0 -7
  74. package/esm/tree/customCollisionDetection.js.map +0 -7
  75. package/esm/tree/getTreeKeyboardCoordinates.js.map +0 -7
  76. package/esm/tree/index.js.map +0 -7
  77. package/esm/tree/types.js.map +0 -7
  78. package/esm/tree/useTreeActionHandlers.js.map +0 -7
  79. package/esm/tree/useTreeAnnouncements.js.map +0 -7
  80. package/esm/tree/useTreeDndkitConfig.js.map +0 -7
  81. package/esm/tree/useTreePreviewHandlers.js.map +0 -7
  82. package/esm/tree/utilities.js.map +0 -7
@@ -1,57 +1,90 @@
1
- import * as React from "react";
2
- import { useState, useEffect, useMemo, useRef } from "react";
3
- import {
4
- useSensor,
5
- useSensors,
6
- KeyboardSensor,
7
- PointerSensor,
8
- MeasuringStrategy
9
- } from "@dnd-kit/core";
10
- import { horizontalListSortingStrategy, verticalListSortingStrategy } from "@dnd-kit/sortable";
11
- import { useTreePreviewHandlers } from "./useTreePreviewHandlers";
12
- import { getTreeKeyboardCoordinates } from "./getTreeKeyboardCoordinates";
13
- import { getProjection, removeChildrenOf } from "./utilities";
14
- import { useTreeActionHandlers } from "./useTreeActionHandlers";
15
- import { DropIndicatorPosition } from "./constants";
16
- import { customCollisionDetection } from "./customCollisionDetection";
17
- import { useTreeAnnouncements } from "./useTreeAnnouncements";
18
- const adjustTranslate = (isHorizontalDnD) => ({ transform }) => {
19
- const newTransform = {
20
- ...transform
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 { useTreePreviewHandlers } from './useTreePreviewHandlers.js';
13
+ import { getTreeKeyboardCoordinates } from './getTreeKeyboardCoordinates.js';
14
+ import { removeChildrenOf, getProjection } from './utilities.js';
15
+ import { useTreeActionHandlers } from './useTreeActionHandlers.js';
16
+ import { DropIndicatorPosition } from './constants.js';
17
+ import { customCollisionDetection } from './customCollisionDetection.js';
18
+ import { useTreeAnnouncements } from './useTreeAnnouncements.js';
19
+
20
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
+ // if second parameter is true, the space will be done on the horizontal axis
24
+
25
+ const adjustTranslate = isHorizontalDnD => {
26
+ const func = _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;
21
40
  };
22
- if (isHorizontalDnD) {
23
- newTransform.x = transform.x + 25;
24
- } else {
25
- newTransform.x = transform.x + 15;
26
- }
27
- return newTransform;
41
+
42
+ return func;
28
43
  };
44
+
29
45
  const measuring = {
30
46
  droppable: {
31
- strategy: MeasuringStrategy.BeforeDragging
47
+ strategy: MeasuringStrategy.Always
32
48
  }
33
49
  };
34
- const useTreeDndkitConfig = ({
35
- flattenedItems,
36
- visibleItems: preVisibleItems,
37
- isHorizontalDnD = false,
38
- isExpandable = false,
39
- onReorder,
40
- maxDragAndDropLevel
41
- }) => {
42
- const [activeId, setActiveId] = useState("");
43
- const [overId, setOverId] = useState("");
50
+ const useTreeDndkitConfig = _ref2 => {
51
+ var _visibleItemsDictiona, _visibleItemsDictiona2;
52
+
53
+ let {
54
+ flattenedItems,
55
+ visibleItems: preVisibleItems,
56
+ isHorizontalDnD = false,
57
+ isExpandable = false,
58
+ onReorder,
59
+ getIsDropValid = () => true,
60
+ maxDragAndDropLevel
61
+ } = _ref2;
62
+ const [activeId, setActiveId] = useState('');
63
+ const [overId, setOverId] = useState('');
44
64
  const [dropIndicatorPosition, setDropIndicatorPosition] = useState(DropIndicatorPosition.None);
45
- const [lastPosition, setLastPosition] = useState("");
46
- const visibleItems = useMemo(() => removeChildrenOf(preVisibleItems, activeId), [preVisibleItems, activeId]);
47
- const sortedIds = useMemo(() => visibleItems.map((item) => item.uid), [visibleItems]);
65
+ const [lastPosition, setLastPosition] = useState(''); // Remove activeId's children
66
+
67
+ const visibleItems = useMemo(() => removeChildrenOf(preVisibleItems, activeId), [preVisibleItems, activeId]); // Sorted ids for the library
68
+
69
+ const sortedIds = useMemo(() => visibleItems.map(item => item.uid), [visibleItems]);
70
+ /**
71
+ * Dictionary from UID to ITEM
72
+ * This dictionary is computed since on every DnD move, I need to know the
73
+ * depth of a particular row, so O(1) per DnD move instead of O(#ITEMS)
74
+ */
75
+
48
76
  const visibleItemsDictionary = useMemo(() => {
77
+ // Using plain for to achieve O(#ITEMS) performance
49
78
  const dictionary = {};
50
- visibleItems.forEach((item) => {
79
+ visibleItems.forEach(item => {
51
80
  dictionary[item.uid] = item;
52
81
  });
53
82
  return dictionary;
54
83
  }, [visibleItems]);
84
+ const isDropValid = useMemo(() => {
85
+ if (!activeId || !overId) return true;
86
+ return getIsDropValid(visibleItemsDictionary[activeId], visibleItemsDictionary[overId], ['none', 'before', 'after', 'inside'][dropIndicatorPosition]);
87
+ }, [getIsDropValid, visibleItemsDictionary, activeId, overId, dropIndicatorPosition]);
55
88
  const modifiers = useMemo(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
56
89
  const sensorContext = useRef({
57
90
  items: visibleItems,
@@ -68,56 +101,44 @@ const useTreeDndkitConfig = ({
68
101
  const coordinateGetter = useMemo(() => getTreeKeyboardCoordinates(sensorContext, isHorizontalDnD, maxDragAndDropLevel), [sensorContext, isHorizontalDnD, maxDragAndDropLevel]);
69
102
  const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, {
70
103
  coordinateGetter
71
- }));
104
+ })); // where is the activeItem being positioned (depth and parent)
105
+
72
106
  const projected = useMemo(() => overId ? getProjection(visibleItems, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) : null, [overId, visibleItems, visibleItemsDictionary, dropIndicatorPosition, isExpandable]);
73
107
  const dragPreviewHandlers = useTreePreviewHandlers({
74
108
  setActiveId,
75
109
  setOverId,
76
110
  setDropIndicatorPosition
77
111
  });
78
- const dragActionHandlers = useTreeActionHandlers({
79
- ...dragPreviewHandlers,
112
+ const dragActionHandlers = useTreeActionHandlers(_objectSpread(_objectSpread({}, dragPreviewHandlers), {}, {
80
113
  onReorder,
81
114
  projected,
82
115
  flattenedItems,
83
- dropIndicatorPosition
84
- });
116
+ dropIndicatorPosition,
117
+ isDropValid
118
+ }));
85
119
  const announcements = useTreeAnnouncements(visibleItemsDictionary, dropIndicatorPosition);
86
- const dndContextProps = useMemo(() => ({
120
+ const dndContextProps = useMemo(() => _objectSpread({
87
121
  announcements,
88
122
  modifiers,
89
123
  sensors,
90
124
  measuring,
91
- collisionDetection: customCollisionDetection(activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition),
92
- ...dragActionHandlers
93
- }), [
94
- announcements,
95
- modifiers,
96
- sensors,
97
- dragActionHandlers,
98
- visibleItemsDictionary,
99
- setDropIndicatorPosition,
100
- activeId,
101
- maxDragAndDropLevel,
102
- lastPosition,
103
- setLastPosition
104
- ]);
125
+ collisionDetection: customCollisionDetection(activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition)
126
+ }, dragActionHandlers), [announcements, modifiers, sensors, dragActionHandlers, visibleItemsDictionary, setDropIndicatorPosition, activeId, maxDragAndDropLevel, lastPosition, setLastPosition]);
105
127
  const sortableContextProps = useMemo(() => ({
106
128
  items: sortedIds,
107
- strategy: isHorizontalDnD ? horizontalListSortingStrategy : verticalListSortingStrategy
108
- }), [sortedIds, isHorizontalDnD]);
129
+ strategy: () => null
130
+ }), [sortedIds]);
109
131
  return {
110
132
  dndContextProps,
111
133
  sortableContextProps,
134
+ isDropValid,
112
135
  activeId,
113
- activeIndex: visibleItemsDictionary[activeId]?.realIndex ?? -1,
136
+ activeIndex: (_visibleItemsDictiona = (_visibleItemsDictiona2 = visibleItemsDictionary[activeId]) === null || _visibleItemsDictiona2 === void 0 ? void 0 : _visibleItemsDictiona2.realIndex) !== null && _visibleItemsDictiona !== void 0 ? _visibleItemsDictiona : -1,
114
137
  overId,
115
138
  depth: projected ? projected.depth : 0,
116
139
  dropIndicatorPosition,
117
140
  visibleItems
118
141
  };
119
142
  };
120
- export {
121
- useTreeDndkitConfig
122
- };
123
- //# sourceMappingURL=useTreeDndkitConfig.js.map
143
+
144
+ export { useTreeDndkitConfig };
@@ -1,25 +1,36 @@
1
- import * as React from "react";
2
- import { useCallback } from "react";
3
- import { DropIndicatorPosition } from "./constants";
4
- const useTreePreviewHandlers = ({
5
- setOverId,
6
- setActiveId,
7
- setDropIndicatorPosition
8
- }) => {
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;
9
10
  const resetState = useCallback(() => {
10
- setOverId("");
11
- setActiveId("");
12
- document.body.style.setProperty("cursor", "");
11
+ setOverId('');
12
+ setActiveId('');
13
+ document.body.style.setProperty('cursor', '');
13
14
  }, [setOverId, setActiveId]);
14
- const handlePreviewDragStart = useCallback(({ active: { id } }) => {
15
+ const handlePreviewDragStart = useCallback(_ref2 => {
16
+ let {
17
+ active: {
18
+ id
19
+ }
20
+ } = _ref2;
15
21
  setActiveId(id);
16
22
  setOverId(id);
17
23
  setDropIndicatorPosition(DropIndicatorPosition.Inside);
18
- document.body.style.setProperty("cursor", "grabbing");
24
+ document.body.style.setProperty('cursor', 'grabbing');
19
25
  }, [setActiveId, setDropIndicatorPosition, setOverId]);
20
26
  const handlePreviewDragMove = useCallback(() => null, []);
21
- const handlePreviewDragOver = useCallback(({ over }) => {
22
- setOverId(over?.id ?? "");
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 : '');
23
34
  }, [setOverId]);
24
35
  const handlePreviewDragEnd = useCallback(() => {
25
36
  resetState();
@@ -35,7 +46,5 @@ const useTreePreviewHandlers = ({
35
46
  handlePreviewDragCancel
36
47
  };
37
48
  };
38
- export {
39
- useTreePreviewHandlers
40
- };
41
- //# sourceMappingURL=useTreePreviewHandlers.js.map
49
+
50
+ export { useTreePreviewHandlers };
@@ -1,37 +1,47 @@
1
- import * as React from "react";
2
- import { DropIndicatorPosition } from "./constants";
3
- const getMinDepth = (item) => {
4
- if (item)
5
- return item.depth;
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;
6
8
  return 0;
7
9
  };
10
+
8
11
  const getProjection = (items, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) => {
9
12
  const overItemIndex = visibleItemsDictionary[overId].realIndex;
10
13
  const previousItem = items[overItemIndex];
11
14
  const nextItem = items[overItemIndex + 1];
15
+
12
16
  if (dropIndicatorPosition === DropIndicatorPosition.Inside && isExpandable) {
13
17
  return {
14
18
  depth: visibleItemsDictionary[overId].depth + 1,
15
19
  parentId: overId
16
20
  };
17
21
  }
22
+
18
23
  if (dropIndicatorPosition === DropIndicatorPosition.Before) {
19
- return { depth: getMinDepth(previousItem), parentId: previousItem.parentId };
24
+ return {
25
+ depth: getMinDepth(previousItem),
26
+ parentId: previousItem.parentId
27
+ };
20
28
  }
21
- return { depth: getMinDepth(nextItem), parentId: nextItem?.parentId };
29
+
30
+ return {
31
+ depth: getMinDepth(nextItem),
32
+ parentId: nextItem === null || nextItem === void 0 ? void 0 : nextItem.parentId
33
+ };
22
34
  };
23
35
  const removeChildrenOf = (items, id) => {
24
36
  const excludeParentIds = [id];
25
- return items.filter((item) => {
37
+ return items.filter(item => {
26
38
  if (item.parentId !== null && excludeParentIds.includes(item.parentId)) {
27
39
  excludeParentIds.push(item.uid);
28
40
  return false;
29
41
  }
42
+
30
43
  return true;
31
44
  });
32
45
  };
33
- export {
34
- getProjection,
35
- removeChildrenOf
36
- };
37
- //# sourceMappingURL=utilities.js.map
46
+
47
+ export { getProjection, removeChildrenOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-drag-and-drop",
3
- "version": "2.2.0-alpha.3",
3
+ "version": "2.2.0-next.2",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Drag And Drop",
6
6
  "module": "./esm/index.js",
@@ -64,7 +64,7 @@ export declare type useHierarchyDndkitConfigReturn = {
64
64
  overId: string | null;
65
65
  activeIndex: number | undefined;
66
66
  };
67
- export declare type getKeyboardCoordinatesArgs = {
67
+ export declare type GetKeyboardCoordinatesArgs = {
68
68
  items: Item[];
69
69
  active: Active | null;
70
70
  over: Over | null;
@@ -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
- original: Record<string, Record<string, any>>;
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 useTreePreviewHandlersReturn = {
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 useTreePreviewHandlersArgs = {
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 useTreeActionHandlersArgs = useTreePreviewHandlersReturn & {
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 useTreeActionHandlersReturn = {
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 useTreeDndkitConfigArgs = {
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 useTreeDndkitConfigReturn = {
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 useTreeDndkitConfigType = (args: useTreeDndkitConfigArgs) => useTreeDndkitConfigReturn;
83
- export declare type getKeyboardCoordinatesArgs = {
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 { useTreeActionHandlersReturn, useTreeActionHandlersArgs } from './types';
2
- export declare const useTreeActionHandlers: ({ handlePreviewDragStart, handlePreviewDragMove, handlePreviewDragOver, handlePreviewDragEnd, handlePreviewDragCancel, onReorder, flattenedItems, projected, dropIndicatorPosition, }: useTreeActionHandlersArgs) => useTreeActionHandlersReturn;
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 { useTreeDndkitConfigType } from './types';
2
- export declare const useTreeDndkitConfig: useTreeDndkitConfigType;
1
+ import type { UseTreeDndkitConfigType } from './types';
2
+ export declare const useTreeDndkitConfig: UseTreeDndkitConfigType;
@@ -1,2 +1,2 @@
1
- import type { useTreePreviewHandlersReturn, useTreePreviewHandlersArgs } from './types';
2
- export declare const useTreePreviewHandlers: ({ setOverId, setActiveId, setDropIndicatorPosition, }: useTreePreviewHandlersArgs) => useTreePreviewHandlersReturn;
1
+ import type { UseTreePreviewHandlersReturn, UseTreePreviewHandlersArgs } from './types';
2
+ export declare const useTreePreviewHandlers: ({ setOverId, setActiveId, setDropIndicatorPosition, }: UseTreePreviewHandlersArgs) => UseTreePreviewHandlersReturn;
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/hierarchy/customCollisionDetection.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["import { CollisionDetection, DroppableContainer } from '@dnd-kit/core';\nimport { Item } from './types';\n\nexport const customCollisionDetection =\n (activeId: string | null, activeParent: string | undefined, dndItems: Item[]): CollisionDetection =>\n ({ droppableContainers, collisionRect }) => {\n const entriesWithSameParent = droppableContainers.filter(\n ({ id }) => dndItems.find((item) => item.id === id)?.parentId === activeParent,\n );\n\n const originalContainer = entriesWithSameParent.find(({ id }) => id === activeId);\n const originalRect = originalContainer?.rect?.current;\n\n if (!originalRect) return null;\n\n if (\n originalRect.offsetLeft <= collisionRect.offsetLeft &&\n collisionRect.offsetLeft <= originalRect.offsetLeft + originalRect.width\n ) {\n return originalContainer.id;\n }\n\n const isLeft = collisionRect.offsetLeft <= originalRect.offsetLeft + collisionRect.width / 2 + 5;\n\n let match: DroppableContainer | null = null;\n // If going to the left, search the closest offset left\n // Otherwise, get the closest offset right\n const collisionPoint = collisionRect.offsetLeft + collisionRect.width / 2;\n entriesWithSameParent.forEach((entry) => {\n const {\n rect: { current: rect },\n } = entry;\n\n if (rect !== null) {\n const offsetRight = rect.offsetLeft + rect.width;\n\n if (!match) {\n match = entry;\n } else if (\n match &&\n match.rect.current &&\n isLeft &&\n Math.abs(collisionPoint - rect.offsetLeft) <= Math.abs(collisionPoint - match.rect.current.offsetLeft)\n ) {\n match = entry;\n } else if (\n match &&\n match.rect.current &&\n !isLeft &&\n Math.abs(collisionPoint - offsetRight) <=\n Math.abs(collisionPoint - match.rect.current.offsetLeft - match.rect.current.width)\n ) {\n match = entry;\n }\n }\n });\n // Typescript believes match is always null for some reason\n const matchCastedForSomeReason = match as DroppableContainer | null;\n return matchCastedForSomeReason === null ? null : matchCastedForSomeReason.id;\n };\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADGhB,MAAM,2BACX,CAAC,UAAyB,cAAkC,aAC5D,CAAC,EAAE,qBAAqB,oBAAoB;AAC1C,QAAM,wBAAwB,oBAAoB,OAChD,CAAC,EAAE,SAAS,SAAS,KAAK,CAAC,SAAS,KAAK,OAAO,KAAK,aAAa;AAGpE,QAAM,oBAAoB,sBAAsB,KAAK,CAAC,EAAE,SAAS,OAAO;AACxE,QAAM,eAAe,mBAAmB,MAAM;AAE9C,MAAI,CAAC;AAAc,WAAO;AAE1B,MACE,aAAa,cAAc,cAAc,cACzC,cAAc,cAAc,aAAa,aAAa,aAAa,OACnE;AACA,WAAO,kBAAkB;AAAA;AAG3B,QAAM,SAAS,cAAc,cAAc,aAAa,aAAa,cAAc,QAAQ,IAAI;AAE/F,MAAI,QAAmC;AAGvC,QAAM,iBAAiB,cAAc,aAAa,cAAc,QAAQ;AACxE,wBAAsB,QAAQ,CAAC,UAAU;AACvC,UAAM;AAAA,MACJ,MAAM,EAAE,SAAS;AAAA,QACf;AAEJ,QAAI,SAAS,MAAM;AACjB,YAAM,cAAc,KAAK,aAAa,KAAK;AAE3C,UAAI,CAAC,OAAO;AACV,gBAAQ;AAAA,iBAER,SACA,MAAM,KAAK,WACX,UACA,KAAK,IAAI,iBAAiB,KAAK,eAAe,KAAK,IAAI,iBAAiB,MAAM,KAAK,QAAQ,aAC3F;AACA,gBAAQ;AAAA,iBAER,SACA,MAAM,KAAK,WACX,CAAC,UACD,KAAK,IAAI,iBAAiB,gBACxB,KAAK,IAAI,iBAAiB,MAAM,KAAK,QAAQ,aAAa,MAAM,KAAK,QAAQ,QAC/E;AACA,gBAAQ;AAAA;AAAA;AAAA;AAKd,QAAM,2BAA2B;AACjC,SAAO,6BAA6B,OAAO,OAAO,yBAAyB;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/hierarchy/getHierarchyKeyboardCoordinates.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["import { closestCorners, getViewRect, KeyboardCode, KeyboardCoordinateGetter, DroppableContainer } from '@dnd-kit/core';\nimport { Coordinates } from '@dnd-kit/core/dist/types';\n\nimport { GetKeyboardCoordinatesArgs, SensorContext } from './types';\n\nconst directions: string[] = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];\n\nconst vertical: string[] = [KeyboardCode.Up, KeyboardCode.Down];\n\nconst getHorizontalKeyboardCoordinates = ({\n items,\n active,\n over,\n event,\n currentCoordinates,\n droppableContainers,\n collisionRect,\n}: GetKeyboardCoordinatesArgs): Coordinates | undefined => {\n if (vertical.includes(event.code) || !active || !over) return undefined;\n\n const activeItem = items.find((item) => item.id === active.id);\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 node = container?.node.current;\n if (!node) {\n return;\n }\n const itemParent = items.find((item) => item.id === container.id)?.parentId;\n if (itemParent !== activeItem?.parentId) return;\n const rect = getViewRect(node);\n if (event.code === KeyboardCode.Left && collisionRect.left > rect.right - 10) {\n layoutRects.push(container);\n } else if (event.code === KeyboardCode.Right && collisionRect.left < rect.left) {\n layoutRects.push(container);\n }\n });\n\n const closestId = closestCorners({ droppableContainers: layoutRects, collisionRect, active });\n\n if (!closestId) return undefined;\n\n const closestDroppableContainer = droppableContainers.get(closestId)?.node?.current;\n const activeDroppableContainer = droppableContainers.get(active?.id)?.node?.current;\n\n if (!closestDroppableContainer || !activeDroppableContainer) return undefined;\n\n const closestRect = getViewRect(closestDroppableContainer);\n const activeRect = getViewRect(activeDroppableContainer);\n return {\n ...currentCoordinates,\n x:\n closestRect.left +\n (closestRect.width - collisionRect.width) / 2 +\n (closestRect.offsetLeft < activeRect.left ? -1 : 1),\n };\n};\n\nexport const getHierarchyKeyboardCoordinates: (\n context: SensorContext,\n dragOverlayDataTestid: string,\n isHorizontalDnD: boolean,\n) => KeyboardCoordinateGetter =\n (context, dragOverlayDataTestid, isHorizontalDnD) =>\n (event, { currentCoordinates, context: { active, over, collisionRect, droppableContainers } }) => {\n if (directions.includes(event.code)) {\n event.preventDefault();\n if (!collisionRect) {\n return undefined;\n }\n\n const {\n current: { items },\n } = context;\n\n const args = {\n dragOverlayDataTestid,\n items,\n active,\n over,\n event,\n currentCoordinates,\n droppableContainers,\n collisionRect,\n };\n\n if (isHorizontalDnD) return getHorizontalKeyboardCoordinates(args);\n return undefined;\n }\n return undefined;\n };\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,kBAAwG;AAKxG,MAAM,aAAuB,CAAC,yBAAa,MAAM,yBAAa,OAAO,yBAAa,IAAI,yBAAa;AAEnG,MAAM,WAAqB,CAAC,yBAAa,IAAI,yBAAa;AAE1D,MAAM,mCAAmC,CAAC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACyD;AACzD,MAAI,SAAS,SAAS,MAAM,SAAS,CAAC,UAAU,CAAC;AAAM,WAAO;AAE9D,QAAM,aAAa,MAAM,KAAK,CAAC,SAAS,KAAK,OAAO,OAAO;AAE3D,QAAM,WAAW,KAAK;AAEtB,QAAM,cAAoC;AAG1C,sBAAoB,QAAQ,CAAC,cAAc;AACzC,QAAI,WAAW,YAAY,CAAC,UAAU;AACpC;AAAA;AAEF,UAAM,OAAO,WAAW,KAAK;AAC7B,QAAI,CAAC,MAAM;AACT;AAAA;AAEF,UAAM,aAAa,MAAM,KAAK,CAAC,SAAS,KAAK,OAAO,UAAU,KAAK;AACnE,QAAI,eAAe,YAAY;AAAU;AACzC,UAAM,OAAO,6BAAY;AACzB,QAAI,MAAM,SAAS,yBAAa,QAAQ,cAAc,OAAO,KAAK,QAAQ,IAAI;AAC5E,kBAAY,KAAK;AAAA,eACR,MAAM,SAAS,yBAAa,SAAS,cAAc,OAAO,KAAK,MAAM;AAC9E,kBAAY,KAAK;AAAA;AAAA;AAIrB,QAAM,YAAY,gCAAe,EAAE,qBAAqB,aAAa,eAAe;AAEpF,MAAI,CAAC;AAAW,WAAO;AAEvB,QAAM,4BAA4B,oBAAoB,IAAI,YAAY,MAAM;AAC5E,QAAM,2BAA2B,oBAAoB,IAAI,QAAQ,KAAK,MAAM;AAE5E,MAAI,CAAC,6BAA6B,CAAC;AAA0B,WAAO;AAEpE,QAAM,cAAc,6BAAY;AAChC,QAAM,aAAa,6BAAY;AAC/B,SAAO;AAAA,OACF;AAAA,IACH,GACE,YAAY,OACX,aAAY,QAAQ,cAAc,SAAS,IAC3C,aAAY,aAAa,WAAW,OAAO,KAAK;AAAA;AAAA;AAIhD,MAAM,kCAKX,CAAC,SAAS,uBAAuB,oBACjC,CAAC,OAAO,EAAE,oBAAoB,SAAS,EAAE,QAAQ,MAAM,eAAe,4BAA4B;AAChG,MAAI,WAAW,SAAS,MAAM,OAAO;AACnC,UAAM;AACN,QAAI,CAAC,eAAe;AAClB,aAAO;AAAA;AAGT,UAAM;AAAA,MACJ,SAAS,EAAE;AAAA,QACT;AAEJ,UAAM,OAAO;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAGF,QAAI;AAAiB,aAAO,iCAAiC;AAC7D,WAAO;AAAA;AAET,SAAO;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/hierarchy/index.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["export * from './useHierarchyDndkitConfig';\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA,YAAuB;ADAvB,8BAAc;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 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 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
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA,YAAuB;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/hierarchy/useHierarchyActionHandlers.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["import { useCallback } from 'react';\nimport { DragStartEvent, DragMoveEvent, DragEndEvent, DragCancelEvent } from '@dnd-kit/core';\nimport { UseHierarchyActionHandlersReturn, UseHierarchyActionHandlersArgs } from './types';\n\nexport const useHierarchyActionHandlers = ({\n handlePreviewDragStart,\n handlePreviewDragMove,\n handlePreviewDragEnd,\n handlePreviewDragCancel,\n onReorder,\n dndItems,\n}: UseHierarchyActionHandlersArgs): UseHierarchyActionHandlersReturn => {\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 onDragEnd = useCallback(\n (e: DragEndEvent) => {\n handlePreviewDragEnd(e);\n const { active, over } = e;\n\n if (!over) return;\n\n if (active.id !== over.id) {\n const activeIndex = dndItems.findIndex((item) => item.id === active.id);\n const overIndex = dndItems.findIndex((item) => item.id === over.id);\n\n onReorder(dndItems[activeIndex], {\n targetIndex: overIndex,\n fromIndex: activeIndex,\n });\n }\n },\n [handlePreviewDragEnd, dndItems, onReorder],\n );\n\n const onDragCancel = useCallback(\n (e: DragCancelEvent) => {\n handlePreviewDragCancel(e);\n },\n [handlePreviewDragCancel],\n );\n\n return { onDragStart, onDragMove, onDragEnd, onDragCancel };\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAA4B;AAIrB,MAAM,6BAA6B,CAAC;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACsE;AACtE,QAAM,cAAc,8BAClB,CAAC,MAAsB;AACrB,2BAAuB;AAAA,KAEzB,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,CAAC;AAAM;AAEX,QAAI,OAAO,OAAO,KAAK,IAAI;AACzB,YAAM,cAAc,SAAS,UAAU,CAAC,SAAS,KAAK,OAAO,OAAO;AACpE,YAAM,YAAY,SAAS,UAAU,CAAC,SAAS,KAAK,OAAO,KAAK;AAEhE,gBAAU,SAAS,cAAc;AAAA,QAC/B,aAAa;AAAA,QACb,WAAW;AAAA;AAAA;AAAA,KAIjB,CAAC,sBAAsB,UAAU;AAGnC,QAAM,eAAe,8BACnB,CAAC,MAAuB;AACtB,4BAAwB;AAAA,KAE1B,CAAC;AAGH,SAAO,EAAE,aAAa,YAAY,WAAW;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/hierarchy/useHierarchyAnnouncements.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["import { Announcements } from '@dnd-kit/core';\nimport { useCallback } from 'react';\nimport { Item } from './types';\n\nexport const useHierarchyAnnouncements = (visibleItemsDictionary: Record<string, Item>): Announcements => {\n const onDragStart = useCallback(\n (id: string) => `Picked up draggable item from position ${visibleItemsDictionary[id].index + 1}.`,\n [visibleItemsDictionary],\n );\n\n const onDragMove = useCallback(\n (id: string, overId: string) => {\n if (overId) {\n const overIndex = visibleItemsDictionary[overId].index + 1;\n return `Draggable item was moved to position ${overIndex}.`;\n }\n\n return `Draggable item is no longer over a droppable area.`;\n },\n [visibleItemsDictionary],\n );\n\n const onDragOver = onDragMove;\n\n const onDragEnd = useCallback(\n (id: string, overId: string) => {\n if (overId) {\n const overIndex = visibleItemsDictionary[overId].index + 1;\n return `Draggable item was dropped over position ${overIndex}.`;\n }\n\n return `Draggable item was dropped at it's original position.`;\n },\n [visibleItemsDictionary],\n );\n\n const onDragCancel = useCallback(\n (id: string) =>\n `Dragging was cancelled. Draggable item from position ${\n visibleItemsDictionary[id].index + 1\n } was dropped at it's initial position.`,\n [visibleItemsDictionary],\n );\n\n return { onDragStart, onDragOver, onDragMove, onDragEnd, onDragCancel };\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAA4B;AAGrB,MAAM,4BAA4B,CAAC,2BAAgE;AACxG,QAAM,cAAc,8BAClB,CAAC,OAAe,0CAA0C,uBAAuB,IAAI,QAAQ,MAC7F,CAAC;AAGH,QAAM,aAAa,8BACjB,CAAC,IAAY,WAAmB;AAC9B,QAAI,QAAQ;AACV,YAAM,YAAY,uBAAuB,QAAQ,QAAQ;AACzD,aAAO,wCAAwC;AAAA;AAGjD,WAAO;AAAA,KAET,CAAC;AAGH,QAAM,aAAa;AAEnB,QAAM,YAAY,8BAChB,CAAC,IAAY,WAAmB;AAC9B,QAAI,QAAQ;AACV,YAAM,YAAY,uBAAuB,QAAQ,QAAQ;AACzD,aAAO,4CAA4C;AAAA;AAGrD,WAAO;AAAA,KAET,CAAC;AAGH,QAAM,eAAe,8BACnB,CAAC,OACC,wDACE,uBAAuB,IAAI,QAAQ,2CAEvC,CAAC;AAGH,SAAO,EAAE,aAAa,YAAY,YAAY,WAAW;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/hierarchy/useHierarchyDndkitConfig.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 { useHierarchyActionHandlers } from './useHierarchyActionHandlers';\nimport { useHierarchyPreviewHandlers } from './useHierarchyPreviewHandlers';\nimport type { UseHierarchyDndkitConfigType, SensorContext, Item } from './types';\nimport { getHierarchyKeyboardCoordinates } from './getHierarchyKeyboardCoordinates';\nimport { customCollisionDetection } from './customCollisionDetection';\nimport { useHierarchyAnnouncements } from './useHierarchyAnnouncements';\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 =\n (isHorizontalDnD: boolean): Modifier =>\n ({ transform }) => {\n const newTransform = {\n ...transform,\n };\n if (isHorizontalDnD) {\n newTransform.y = transform.y + 15;\n } else {\n newTransform.y = transform.y - 35;\n }\n return newTransform;\n };\n\nconst measuring: Partial<MeasuringConfiguration> = {\n droppable: {\n strategy: MeasuringStrategy.Always,\n },\n};\n\nconst noop = () => null;\n\nexport const useHierarchyDndkitConfig: UseHierarchyDndkitConfigType = ({\n flattenedItems,\n dragOverlayDataTestid,\n isHorizontalDnD = false,\n onReorder,\n onPreviewResetState = noop,\n onPreviewDragStart = noop,\n}) => {\n const [activeId, setActiveId] = useState('');\n\n const dndItems = useMemo(() => flattenedItems.map(([item]) => item), [flattenedItems]);\n\n const itemsDictionary = useMemo(() => {\n const dictionary: Record<string, Item> = {};\n dndItems.forEach((item) => {\n dictionary[item.id] = item;\n });\n return dictionary;\n }, [dndItems]);\n\n const modifiers: Modifier[] = useMemo(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);\n\n const sensorContext: SensorContext = useRef({\n items: dndItems,\n });\n\n useEffect(() => {\n sensorContext.current = {\n items: dndItems,\n };\n }, [dndItems]);\n\n const coordinateGetter = useMemo(\n () => getHierarchyKeyboardCoordinates(sensorContext, dragOverlayDataTestid, isHorizontalDnD),\n [isHorizontalDnD],\n );\n\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor, {\n coordinateGetter,\n }),\n );\n\n const dragPreviewHandlers = useHierarchyPreviewHandlers({\n setActiveId,\n onPreviewResetState,\n onPreviewDragStart,\n });\n\n const dragActionHandlers = useHierarchyActionHandlers({\n ...dragPreviewHandlers,\n dndItems,\n onReorder,\n });\n\n const announcements = useHierarchyAnnouncements(itemsDictionary);\n\n const dndContextProps = useMemo(\n () => ({\n announcements,\n modifiers,\n sensors,\n measuring,\n collisionDetection: customCollisionDetection(activeId, itemsDictionary[activeId ?? '']?.parentId, dndItems),\n ...dragActionHandlers,\n }),\n [announcements, modifiers, sensors, activeId, itemsDictionary, dndItems, dragActionHandlers],\n );\n\n return {\n dndContextProps,\n activeId,\n activeIndex: activeId ? itemsDictionary[activeId]?.index : -1,\n };\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAAqD;AACrD,kBAQO;AACP,wCAA2C;AAC3C,yCAA4C;AAE5C,6CAAgD;AAChD,sCAAyC;AACzC,uCAA0C;AAI1C,MAAM,kBACJ,CAAC,oBACD,CAAC,EAAE,gBAAgB;AACjB,QAAM,eAAe;AAAA,OAChB;AAAA;AAEL,MAAI,iBAAiB;AACnB,iBAAa,IAAI,UAAU,IAAI;AAAA,SAC1B;AACL,iBAAa,IAAI,UAAU,IAAI;AAAA;AAEjC,SAAO;AAAA;AAGX,MAAM,YAA6C;AAAA,EACjD,WAAW;AAAA,IACT,UAAU,8BAAkB;AAAA;AAAA;AAIhC,MAAM,OAAO,MAAM;AAEZ,MAAM,2BAAyD,CAAC;AAAA,EACrE;AAAA,EACA;AAAA,EACA,kBAAkB;AAAA,EAClB;AAAA,EACA,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,MACjB;AACJ,QAAM,CAAC,UAAU,eAAe,2BAAS;AAEzC,QAAM,WAAW,0BAAQ,MAAM,eAAe,IAAI,CAAC,CAAC,UAAU,OAAO,CAAC;AAEtE,QAAM,kBAAkB,0BAAQ,MAAM;AACpC,UAAM,aAAmC;AACzC,aAAS,QAAQ,CAAC,SAAS;AACzB,iBAAW,KAAK,MAAM;AAAA;AAExB,WAAO;AAAA,KACN,CAAC;AAEJ,QAAM,YAAwB,0BAAQ,MAAM,CAAC,gBAAgB,mBAAmB,CAAC;AAEjF,QAAM,gBAA+B,yBAAO;AAAA,IAC1C,OAAO;AAAA;AAGT,8BAAU,MAAM;AACd,kBAAc,UAAU;AAAA,MACtB,OAAO;AAAA;AAAA,KAER,CAAC;AAEJ,QAAM,mBAAmB,0BACvB,MAAM,4EAAgC,eAAe,uBAAuB,kBAC5E,CAAC;AAGH,QAAM,UAAU,4BACd,2BAAU,4BACV,2BAAU,4BAAgB;AAAA,IACxB;AAAA;AAIJ,QAAM,sBAAsB,oEAA4B;AAAA,IACtD;AAAA,IACA;AAAA,IACA;AAAA;AAGF,QAAM,qBAAqB,kEAA2B;AAAA,OACjD;AAAA,IACH;AAAA,IACA;AAAA;AAGF,QAAM,gBAAgB,gEAA0B;AAEhD,QAAM,kBAAkB,0BACtB,MAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,oBAAoB,8DAAyB,UAAU,gBAAgB,YAAY,KAAK,UAAU;AAAA,OAC/F;AAAA,MAEL,CAAC,eAAe,WAAW,SAAS,UAAU,iBAAiB,UAAU;AAG3E,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,aAAa,WAAW,gBAAgB,WAAW,QAAQ;AAAA;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/hierarchy/useHierarchyPreviewHandlers.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["import { useCallback } from 'react';\nimport { DragStartEvent, DragOverEvent } from '@dnd-kit/core';\nimport type { useHierarchyPreviewHandlersReturn, useHierarchyPreviewHandlersArgs } from './types';\n\nexport const useHierarchyPreviewHandlers = ({\n setActiveId,\n onPreviewResetState,\n onPreviewDragStart,\n}: useHierarchyPreviewHandlersArgs): useHierarchyPreviewHandlersReturn => {\n const resetState = useCallback(() => {\n setActiveId('');\n onPreviewResetState();\n\n document.body.style.setProperty('cursor', '');\n }, [setActiveId, onPreviewResetState]);\n\n const handlePreviewDragStart = useCallback(\n ({ active: { id } }: DragStartEvent) => {\n setActiveId(id);\n document.body.style.setProperty('cursor', 'grabbing');\n onPreviewDragStart();\n },\n [setActiveId, onPreviewDragStart],\n );\n\n const handlePreviewDragMove = useCallback(() => null, []);\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 handlePreviewDragEnd,\n handlePreviewDragCancel,\n };\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAA4B;AAIrB,MAAM,8BAA8B,CAAC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,MACwE;AACxE,QAAM,aAAa,8BAAY,MAAM;AACnC,gBAAY;AACZ;AAEA,aAAS,KAAK,MAAM,YAAY,UAAU;AAAA,KACzC,CAAC,aAAa;AAEjB,QAAM,yBAAyB,8BAC7B,CAAC,EAAE,QAAQ,EAAE,WAA2B;AACtC,gBAAY;AACZ,aAAS,KAAK,MAAM,YAAY,UAAU;AAC1C;AAAA,KAEF,CAAC,aAAa;AAGhB,QAAM,wBAAwB,8BAAY,MAAM,MAAM;AAEtD,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;AAAA;",
6
- "names": []
7
- }
package/cjs/index.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.tsx", "../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["export * from './hierarchy';\nexport * from './tree';\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA,YAAuB;ADAvB,wBAAc;AACd,wBAAc;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/tree/constants.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["export enum DropIndicatorPosition {\n None = 0,\n Before = 1,\n After = 2,\n Inside = 3,\n}", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAhB,IAAK,wBAAL,kBAAK,2BAAL;AACL,0DAAO,KAAP;AACA,4DAAS,KAAT;AACA,2DAAQ,KAAR;AACA,4DAAS,KAAT;AAJU;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 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 =\n (\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 ({ 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.bottom, 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", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,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,2BACX,CACE,UACA,wBACA,0BACA,qBACA,cACA,oBAEF,CAAC,EAAE,qBAAqB,oBAAoB;AAC1C,QAAM,oBAAoB,oBAAoB,KAAK,CAAC,EAAE,SAAS,OAAO;AACtE,QAAM,eAAe,mBAAmB,MAAM;AAI9C,MAAI,OAAO,iBAAiB;AAC5B,MAAI,cAAc;AAChB,WAAO,aAAa,YAAY,cAAc;AAAA;AAIhD,QAAM,YAAY,cAAc,SAAS;AAEzC,MAAI,qBAAgD;AAEpD,MAAI,MAAM;AAER,yBAAqB,oBAAoB,OACvC,CAAC,eAAe,cAAc;AAC5B,YAAM,OAAO,UAAU,KAAK;AAC5B,UAAI,QAAQ,cAAc,KAAK,SAAS;AACtC,cAAM,EAAE,WAAW,kBAAkB;AACrC,cAAM,EAAE,WAAW,2BAA2B,cAAc,KAAK;AACjE,YAAI,gBAAgB,YAAY,cAAc,OAAO,gBAAgB,wBAAwB;AAC3F,iBAAO;AAAA;AAAA;AAGX,aAAO;AAAA,OAET,EAAE,IAAI,UAAU,MAAM,EAAE,SAAS;AAAA,SAE9B;AAEL,yBAAqB,oBAAoB,OACvC,CAAC,aAAa,cAAc;AAC1B,YAAM,OAAO,UAAU,KAAK;AAC5B,UAAI,QAAQ,YAAY,KAAK,SAAS;AACpC,cAAM,EAAE,WAAW,kBAAkB;AACrC,cAAM,EAAE,WAAW,yBAAyB,YAAY,KAAK;AAC7D,YAAI,gBAAgB,YAAY,cAAc,OAAO,gBAAgB,sBAAsB;AACzF,iBAAO;AAAA;AAAA;AAGX,aAAO;AAAA,OAET,EAAE,IAAI,UAAU,MAAM,EAAE,SAAS;AAAA;AAKrC,MAAI,mBAAmB,OAAO,UAAU;AACtC,WAAO;AAAA;AAGT,QAAM,gBAAgB,mBAAmB,KAAK;AAE9C,MAAI,CAAC;AAAe,WAAO;AAG3B,QAAM,CAAC,KAAK,UAAU;AAAA,IACpB,KAAK,IAAI,cAAc,KAAK,cAAc;AAAA,IAC1C,KAAK,IAAI,cAAc,QAAQ,cAAc,YAAY,cAAc;AAAA;AAIzE,QAAM,yBAAyB,KAAK,IAAI,SAAS,OAAO,cAAc;AAEtE,MACE,yBAAyB,mBACzB,uBAAuB,mBAAmB,IAAI,QAAQ,KAAK,uBAC3D,mBAAmB,OAAO,UAC1B;AACA,6BAAyB,uCAAsB;AAAA,SAC1C;AACL,6BAAyB,OAAO,uCAAsB,SAAS,uCAAsB;AAAA;AAGvF,MAAI,QAAQ,iBAAiB;AAAM,oBAAgB;AAAA,WAC1C,CAAC,QAAQ,iBAAiB;AAAQ,oBAAgB;AAG3D,SAAO,mBAAmB;AAAA;",
6
- "names": []
7
- }