@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,146 +1,152 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
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 useTreePreviewHandlers = require('./useTreePreviewHandlers.js');
17
+ var getTreeKeyboardCoordinates = require('./getTreeKeyboardCoordinates.js');
18
+ var utilities = require('./utilities.js');
19
+ var useTreeActionHandlers = require('./useTreeActionHandlers.js');
20
+ var constants = require('./constants.js');
21
+ var customCollisionDetection = require('./customCollisionDetection.js');
22
+ var useTreeAnnouncements = require('./useTreeAnnouncements.js');
23
+
24
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
25
+
26
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
27
+
28
+ 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; }
29
+
30
+ 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__default["default"](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; }
31
+ // if second parameter is true, the space will be done on the horizontal axis
32
+
33
+ const adjustTranslate = isHorizontalDnD => {
34
+ const func = _ref => {
35
+ let {
36
+ transform
37
+ } = _ref;
38
+
39
+ const newTransform = _objectSpread({}, transform);
40
+
41
+ if (isHorizontalDnD) {
42
+ newTransform.x = transform.x + 25;
43
+ } else {
44
+ newTransform.x = transform.x + 15;
45
+ }
46
+
47
+ return newTransform;
26
48
  };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var useTreeDndkitConfig_exports = {};
29
- __export(useTreeDndkitConfig_exports, {
30
- useTreeDndkitConfig: () => useTreeDndkitConfig
31
- });
32
- var React = __toESM(require("react"));
33
- var import_react = __toESM(require("react"));
34
- var import_core = __toESM(require("@dnd-kit/core"));
35
- var import_sortable = __toESM(require("@dnd-kit/sortable"));
36
- var import_useTreePreviewHandlers = __toESM(require("./useTreePreviewHandlers"));
37
- var import_getTreeKeyboardCoordinates = __toESM(require("./getTreeKeyboardCoordinates"));
38
- var import_utilities = __toESM(require("./utilities"));
39
- var import_useTreeActionHandlers = __toESM(require("./useTreeActionHandlers"));
40
- var import_constants = __toESM(require("./constants"));
41
- var import_customCollisionDetection = __toESM(require("./customCollisionDetection"));
42
- var import_useTreeAnnouncements = __toESM(require("./useTreeAnnouncements"));
43
- const adjustTranslate = (isHorizontalDnD) => ({ transform }) => {
44
- const newTransform = {
45
- ...transform
46
- };
47
- if (isHorizontalDnD) {
48
- newTransform.x = transform.x + 25;
49
- } else {
50
- newTransform.x = transform.x + 15;
51
- }
52
- return newTransform;
49
+
50
+ return func;
53
51
  };
52
+
54
53
  const measuring = {
55
54
  droppable: {
56
- strategy: import_core.MeasuringStrategy.BeforeDragging
55
+ strategy: core.MeasuringStrategy.Always
57
56
  }
58
57
  };
59
- const useTreeDndkitConfig = ({
60
- flattenedItems,
61
- visibleItems: preVisibleItems,
62
- isHorizontalDnD = false,
63
- isExpandable = false,
64
- onReorder,
65
- maxDragAndDropLevel
66
- }) => {
67
- const [activeId, setActiveId] = (0, import_react.useState)("");
68
- const [overId, setOverId] = (0, import_react.useState)("");
69
- const [dropIndicatorPosition, setDropIndicatorPosition] = (0, import_react.useState)(import_constants.DropIndicatorPosition.None);
70
- const [lastPosition, setLastPosition] = (0, import_react.useState)("");
71
- const visibleItems = (0, import_react.useMemo)(() => (0, import_utilities.removeChildrenOf)(preVisibleItems, activeId), [preVisibleItems, activeId]);
72
- const sortedIds = (0, import_react.useMemo)(() => visibleItems.map((item) => item.uid), [visibleItems]);
73
- const visibleItemsDictionary = (0, import_react.useMemo)(() => {
58
+ const useTreeDndkitConfig = _ref2 => {
59
+ var _visibleItemsDictiona, _visibleItemsDictiona2;
60
+
61
+ let {
62
+ flattenedItems,
63
+ visibleItems: preVisibleItems,
64
+ isHorizontalDnD = false,
65
+ isExpandable = false,
66
+ onReorder,
67
+ getIsDropValid = () => true,
68
+ maxDragAndDropLevel
69
+ } = _ref2;
70
+ const [activeId, setActiveId] = react.useState('');
71
+ const [overId, setOverId] = react.useState('');
72
+ const [dropIndicatorPosition, setDropIndicatorPosition] = react.useState(constants.DropIndicatorPosition.None);
73
+ const [lastPosition, setLastPosition] = react.useState(''); // Remove activeId's children
74
+
75
+ const visibleItems = react.useMemo(() => utilities.removeChildrenOf(preVisibleItems, activeId), [preVisibleItems, activeId]); // Sorted ids for the library
76
+
77
+ const sortedIds = react.useMemo(() => visibleItems.map(item => item.uid), [visibleItems]);
78
+ /**
79
+ * Dictionary from UID to ITEM
80
+ * This dictionary is computed since on every DnD move, I need to know the
81
+ * depth of a particular row, so O(1) per DnD move instead of O(#ITEMS)
82
+ */
83
+
84
+ const visibleItemsDictionary = react.useMemo(() => {
85
+ // Using plain for to achieve O(#ITEMS) performance
74
86
  const dictionary = {};
75
- visibleItems.forEach((item) => {
87
+ visibleItems.forEach(item => {
76
88
  dictionary[item.uid] = item;
77
89
  });
78
90
  return dictionary;
79
91
  }, [visibleItems]);
80
- const modifiers = (0, import_react.useMemo)(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
81
- const sensorContext = (0, import_react.useRef)({
92
+ const isDropValid = react.useMemo(() => {
93
+ if (!activeId || !overId) return true;
94
+ return getIsDropValid(visibleItemsDictionary[activeId], visibleItemsDictionary[overId], ['none', 'before', 'after', 'inside'][dropIndicatorPosition]);
95
+ }, [getIsDropValid, visibleItemsDictionary, activeId, overId, dropIndicatorPosition]);
96
+ const modifiers = react.useMemo(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
97
+ const sensorContext = react.useRef({
82
98
  items: visibleItems,
83
99
  dropIndicatorPosition,
84
100
  setDropIndicatorPosition
85
101
  });
86
- (0, import_react.useEffect)(() => {
102
+ react.useEffect(() => {
87
103
  sensorContext.current = {
88
104
  items: visibleItems,
89
105
  dropIndicatorPosition,
90
106
  setDropIndicatorPosition
91
107
  };
92
108
  }, [visibleItems, dropIndicatorPosition, setDropIndicatorPosition]);
93
- const coordinateGetter = (0, import_react.useMemo)(() => (0, import_getTreeKeyboardCoordinates.getTreeKeyboardCoordinates)(sensorContext, isHorizontalDnD, maxDragAndDropLevel), [sensorContext, isHorizontalDnD, maxDragAndDropLevel]);
94
- const sensors = (0, import_core.useSensors)((0, import_core.useSensor)(import_core.PointerSensor), (0, import_core.useSensor)(import_core.KeyboardSensor, {
109
+ const coordinateGetter = react.useMemo(() => getTreeKeyboardCoordinates.getTreeKeyboardCoordinates(sensorContext, isHorizontalDnD, maxDragAndDropLevel), [sensorContext, isHorizontalDnD, maxDragAndDropLevel]);
110
+ const sensors = core.useSensors(core.useSensor(core.PointerSensor), core.useSensor(core.KeyboardSensor, {
95
111
  coordinateGetter
96
- }));
97
- const projected = (0, import_react.useMemo)(() => overId ? (0, import_utilities.getProjection)(visibleItems, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) : null, [overId, visibleItems, visibleItemsDictionary, dropIndicatorPosition, isExpandable]);
98
- const dragPreviewHandlers = (0, import_useTreePreviewHandlers.useTreePreviewHandlers)({
112
+ })); // where is the activeItem being positioned (depth and parent)
113
+
114
+ const projected = react.useMemo(() => overId ? utilities.getProjection(visibleItems, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) : null, [overId, visibleItems, visibleItemsDictionary, dropIndicatorPosition, isExpandable]);
115
+ const dragPreviewHandlers = useTreePreviewHandlers.useTreePreviewHandlers({
99
116
  setActiveId,
100
117
  setOverId,
101
118
  setDropIndicatorPosition
102
119
  });
103
- const dragActionHandlers = (0, import_useTreeActionHandlers.useTreeActionHandlers)({
104
- ...dragPreviewHandlers,
120
+ const dragActionHandlers = useTreeActionHandlers.useTreeActionHandlers(_objectSpread(_objectSpread({}, dragPreviewHandlers), {}, {
105
121
  onReorder,
106
122
  projected,
107
123
  flattenedItems,
108
- dropIndicatorPosition
109
- });
110
- const announcements = (0, import_useTreeAnnouncements.useTreeAnnouncements)(visibleItemsDictionary, dropIndicatorPosition);
111
- const dndContextProps = (0, import_react.useMemo)(() => ({
124
+ dropIndicatorPosition,
125
+ isDropValid
126
+ }));
127
+ const announcements = useTreeAnnouncements.useTreeAnnouncements(visibleItemsDictionary, dropIndicatorPosition);
128
+ const dndContextProps = react.useMemo(() => _objectSpread({
112
129
  announcements,
113
130
  modifiers,
114
131
  sensors,
115
132
  measuring,
116
- collisionDetection: (0, import_customCollisionDetection.customCollisionDetection)(activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition),
117
- ...dragActionHandlers
118
- }), [
119
- announcements,
120
- modifiers,
121
- sensors,
122
- dragActionHandlers,
123
- visibleItemsDictionary,
124
- setDropIndicatorPosition,
125
- activeId,
126
- maxDragAndDropLevel,
127
- lastPosition,
128
- setLastPosition
129
- ]);
130
- const sortableContextProps = (0, import_react.useMemo)(() => ({
133
+ collisionDetection: customCollisionDetection.customCollisionDetection(activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition)
134
+ }, dragActionHandlers), [announcements, modifiers, sensors, dragActionHandlers, visibleItemsDictionary, setDropIndicatorPosition, activeId, maxDragAndDropLevel, lastPosition, setLastPosition]);
135
+ const sortableContextProps = react.useMemo(() => ({
131
136
  items: sortedIds,
132
- strategy: isHorizontalDnD ? import_sortable.horizontalListSortingStrategy : import_sortable.verticalListSortingStrategy
133
- }), [sortedIds, isHorizontalDnD]);
137
+ strategy: () => null
138
+ }), [sortedIds]);
134
139
  return {
135
140
  dndContextProps,
136
141
  sortableContextProps,
142
+ isDropValid,
137
143
  activeId,
138
- activeIndex: visibleItemsDictionary[activeId]?.realIndex ?? -1,
144
+ activeIndex: (_visibleItemsDictiona = (_visibleItemsDictiona2 = visibleItemsDictionary[activeId]) === null || _visibleItemsDictiona2 === void 0 ? void 0 : _visibleItemsDictiona2.realIndex) !== null && _visibleItemsDictiona !== void 0 ? _visibleItemsDictiona : -1,
139
145
  overId,
140
146
  depth: projected ? projected.depth : 0,
141
147
  dropIndicatorPosition,
142
148
  visibleItems
143
149
  };
144
150
  };
145
- module.exports = __toCommonJS(useTreeDndkitConfig_exports);
146
- //# sourceMappingURL=useTreeDndkitConfig.js.map
151
+
152
+ exports.useTreeDndkitConfig = useTreeDndkitConfig;
@@ -1,61 +1,45 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var useTreePreviewHandlers_exports = {};
29
- __export(useTreePreviewHandlers_exports, {
30
- useTreePreviewHandlers: () => useTreePreviewHandlers
31
- });
32
- var React = __toESM(require("react"));
33
- var import_react = __toESM(require("react"));
34
- var import_constants = __toESM(require("./constants"));
35
- const useTreePreviewHandlers = ({
36
- setOverId,
37
- setActiveId,
38
- setDropIndicatorPosition
39
- }) => {
40
- const resetState = (0, import_react.useCallback)(() => {
41
- setOverId("");
42
- setActiveId("");
43
- document.body.style.setProperty("cursor", "");
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var constants = require('./constants.js');
7
+
8
+ const useTreePreviewHandlers = _ref => {
9
+ let {
10
+ setOverId,
11
+ setActiveId,
12
+ setDropIndicatorPosition
13
+ } = _ref;
14
+ const resetState = react.useCallback(() => {
15
+ setOverId('');
16
+ setActiveId('');
17
+ document.body.style.setProperty('cursor', '');
44
18
  }, [setOverId, setActiveId]);
45
- const handlePreviewDragStart = (0, import_react.useCallback)(({ active: { id } }) => {
19
+ const handlePreviewDragStart = react.useCallback(_ref2 => {
20
+ let {
21
+ active: {
22
+ id
23
+ }
24
+ } = _ref2;
46
25
  setActiveId(id);
47
26
  setOverId(id);
48
- setDropIndicatorPosition(import_constants.DropIndicatorPosition.Inside);
49
- document.body.style.setProperty("cursor", "grabbing");
27
+ setDropIndicatorPosition(constants.DropIndicatorPosition.Inside);
28
+ document.body.style.setProperty('cursor', 'grabbing');
50
29
  }, [setActiveId, setDropIndicatorPosition, setOverId]);
51
- const handlePreviewDragMove = (0, import_react.useCallback)(() => null, []);
52
- const handlePreviewDragOver = (0, import_react.useCallback)(({ over }) => {
53
- setOverId(over?.id ?? "");
30
+ const handlePreviewDragMove = react.useCallback(() => null, []);
31
+ const handlePreviewDragOver = react.useCallback(_ref3 => {
32
+ var _over$id;
33
+
34
+ let {
35
+ over
36
+ } = _ref3;
37
+ setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : '');
54
38
  }, [setOverId]);
55
- const handlePreviewDragEnd = (0, import_react.useCallback)(() => {
39
+ const handlePreviewDragEnd = react.useCallback(() => {
56
40
  resetState();
57
41
  }, [resetState]);
58
- const handlePreviewDragCancel = (0, import_react.useCallback)(() => {
42
+ const handlePreviewDragCancel = react.useCallback(() => {
59
43
  resetState();
60
44
  }, [resetState]);
61
45
  return {
@@ -66,5 +50,5 @@ const useTreePreviewHandlers = ({
66
50
  handlePreviewDragCancel
67
51
  };
68
52
  };
69
- module.exports = __toCommonJS(useTreePreviewHandlers_exports);
70
- //# sourceMappingURL=useTreePreviewHandlers.js.map
53
+
54
+ exports.useTreePreviewHandlers = useTreePreviewHandlers;
@@ -1,66 +1,52 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var utilities_exports = {};
29
- __export(utilities_exports, {
30
- getProjection: () => getProjection,
31
- removeChildrenOf: () => removeChildrenOf
32
- });
33
- var React = __toESM(require("react"));
34
- var import_constants = __toESM(require("./constants"));
35
- const getMinDepth = (item) => {
36
- if (item)
37
- return item.depth;
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.filter.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.filter.js');
8
+ var constants = require('./constants.js');
9
+
10
+ const getMinDepth = item => {
11
+ if (item) return item.depth;
38
12
  return 0;
39
13
  };
14
+
40
15
  const getProjection = (items, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) => {
41
16
  const overItemIndex = visibleItemsDictionary[overId].realIndex;
42
17
  const previousItem = items[overItemIndex];
43
18
  const nextItem = items[overItemIndex + 1];
44
- if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside && isExpandable) {
19
+
20
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside && isExpandable) {
45
21
  return {
46
22
  depth: visibleItemsDictionary[overId].depth + 1,
47
23
  parentId: overId
48
24
  };
49
25
  }
50
- if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Before) {
51
- return { depth: getMinDepth(previousItem), parentId: previousItem.parentId };
26
+
27
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Before) {
28
+ return {
29
+ depth: getMinDepth(previousItem),
30
+ parentId: previousItem.parentId
31
+ };
52
32
  }
53
- return { depth: getMinDepth(nextItem), parentId: nextItem?.parentId };
33
+
34
+ return {
35
+ depth: getMinDepth(nextItem),
36
+ parentId: nextItem === null || nextItem === void 0 ? void 0 : nextItem.parentId
37
+ };
54
38
  };
55
39
  const removeChildrenOf = (items, id) => {
56
40
  const excludeParentIds = [id];
57
- return items.filter((item) => {
41
+ return items.filter(item => {
58
42
  if (item.parentId !== null && excludeParentIds.includes(item.parentId)) {
59
43
  excludeParentIds.push(item.uid);
60
44
  return false;
61
45
  }
46
+
62
47
  return true;
63
48
  });
64
49
  };
65
- module.exports = __toCommonJS(utilities_exports);
66
- //# sourceMappingURL=utilities.js.map
50
+
51
+ exports.getProjection = getProjection;
52
+ exports.removeChildrenOf = removeChildrenOf;
@@ -1,22 +1,54 @@
1
- import * as React from "react";
2
- const customCollisionDetection = (activeId, activeParent, dndItems) => ({ droppableContainers, collisionRect }) => {
3
- const entriesWithSameParent = droppableContainers.filter(({ id }) => dndItems.find((item) => item.id === id)?.parentId === activeParent);
4
- const originalContainer = entriesWithSameParent.find(({ id }) => id === activeId);
5
- const originalRect = originalContainer?.rect?.current;
6
- if (!originalRect)
7
- return null;
1
+ import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.filter.js';
4
+ import 'core-js/modules/esnext.async-iterator.find.js';
5
+ import 'core-js/modules/esnext.iterator.find.js';
6
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
7
+ import 'core-js/modules/esnext.iterator.for-each.js';
8
+
9
+ const customCollisionDetection = (activeId, activeParent, dndItems) => _ref => {
10
+ var _originalContainer$re;
11
+
12
+ let {
13
+ droppableContainers,
14
+ collisionRect
15
+ } = _ref;
16
+ const entriesWithSameParent = droppableContainers.filter(_ref2 => {
17
+ var _dndItems$find;
18
+
19
+ let {
20
+ id
21
+ } = _ref2;
22
+ return ((_dndItems$find = dndItems.find(item => item.id === id)) === null || _dndItems$find === void 0 ? void 0 : _dndItems$find.parentId) === activeParent;
23
+ });
24
+ const originalContainer = entriesWithSameParent.find(_ref3 => {
25
+ let {
26
+ id
27
+ } = _ref3;
28
+ return id === activeId;
29
+ });
30
+ const originalRect = originalContainer === null || originalContainer === void 0 ? void 0 : (_originalContainer$re = originalContainer.rect) === null || _originalContainer$re === void 0 ? void 0 : _originalContainer$re.current;
31
+ if (!originalRect) return null;
32
+
8
33
  if (originalRect.offsetLeft <= collisionRect.offsetLeft && collisionRect.offsetLeft <= originalRect.offsetLeft + originalRect.width) {
9
34
  return originalContainer.id;
10
35
  }
36
+
11
37
  const isLeft = collisionRect.offsetLeft <= originalRect.offsetLeft + collisionRect.width / 2 + 5;
12
- let match = null;
38
+ let match = null; // If going to the left, search the closest offset left
39
+ // Otherwise, get the closest offset right
40
+
13
41
  const collisionPoint = collisionRect.offsetLeft + collisionRect.width / 2;
14
- entriesWithSameParent.forEach((entry) => {
42
+ entriesWithSameParent.forEach(entry => {
15
43
  const {
16
- rect: { current: rect }
44
+ rect: {
45
+ current: rect
46
+ }
17
47
  } = entry;
48
+
18
49
  if (rect !== null) {
19
50
  const offsetRight = rect.offsetLeft + rect.width;
51
+
20
52
  if (!match) {
21
53
  match = entry;
22
54
  } else if (match && match.rect.current && isLeft && Math.abs(collisionPoint - rect.offsetLeft) <= Math.abs(collisionPoint - match.rect.current.offsetLeft)) {
@@ -25,11 +57,10 @@ const customCollisionDetection = (activeId, activeParent, dndItems) => ({ droppa
25
57
  match = entry;
26
58
  }
27
59
  }
28
- });
60
+ }); // Typescript believes match is always null for some reason
61
+
29
62
  const matchCastedForSomeReason = match;
30
63
  return matchCastedForSomeReason === null ? null : matchCastedForSomeReason.id;
31
64
  };
32
- export {
33
- customCollisionDetection
34
- };
35
- //# sourceMappingURL=customCollisionDetection.js.map
65
+
66
+ export { customCollisionDetection };