@elliemae/ds-drag-and-drop 2.2.0-alpha.2 → 2.2.0-beta.0
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.
- package/cjs/hierarchy/customCollisionDetection.js +50 -44
- package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js +91 -78
- package/cjs/hierarchy/index.js +9 -28
- package/cjs/hierarchy/types.js +2 -27
- package/cjs/hierarchy/useHierarchyActionHandlers.js +35 -53
- package/cjs/hierarchy/useHierarchyAnnouncements.js +26 -45
- package/cjs/hierarchy/useHierarchyDndkitConfig.js +83 -77
- package/cjs/hierarchy/useHierarchyPreviewHandlers.js +27 -48
- package/cjs/index.js +11 -29
- package/cjs/tree/constants.js +12 -41
- package/cjs/tree/customCollisionDetection.js +95 -64
- package/cjs/tree/getTreeKeyboardCoordinates.js +101 -87
- package/cjs/tree/index.js +9 -28
- package/cjs/tree/types.js +2 -27
- package/cjs/tree/useTreeActionHandlers.js +56 -66
- package/cjs/tree/useTreeAnnouncements.js +40 -53
- package/cjs/tree/useTreeDndkitConfig.js +91 -95
- package/cjs/tree/useTreePreviewHandlers.js +37 -53
- package/cjs/tree/utilities.js +30 -44
- package/esm/hierarchy/customCollisionDetection.js +46 -15
- package/esm/hierarchy/getHierarchyKeyboardCoordinates.js +76 -42
- package/esm/hierarchy/index.js +1 -3
- package/esm/hierarchy/types.js +1 -2
- package/esm/hierarchy/useHierarchyActionHandlers.js +31 -24
- package/esm/hierarchy/useHierarchyAnnouncements.js +20 -14
- package/esm/hierarchy/useHierarchyDndkitConfig.js +66 -45
- package/esm/hierarchy/useHierarchyPreviewHandlers.js +19 -15
- package/esm/index.js +2 -4
- package/esm/tree/constants.js +10 -12
- package/esm/tree/customCollisionDetection.js +89 -33
- package/esm/tree/getTreeKeyboardCoordinates.js +84 -49
- package/esm/tree/index.js +1 -3
- package/esm/tree/types.js +1 -2
- package/esm/tree/useTreeActionHandlers.js +50 -35
- package/esm/tree/useTreeAnnouncements.js +30 -18
- package/esm/tree/useTreeDndkitConfig.js +70 -59
- package/esm/tree/useTreePreviewHandlers.js +28 -19
- package/esm/tree/utilities.js +23 -13
- package/package.json +1 -1
- package/cjs/hierarchy/customCollisionDetection.js.map +0 -7
- package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js.map +0 -7
- package/cjs/hierarchy/index.js.map +0 -7
- package/cjs/hierarchy/types.js.map +0 -7
- package/cjs/hierarchy/useHierarchyActionHandlers.js.map +0 -7
- package/cjs/hierarchy/useHierarchyAnnouncements.js.map +0 -7
- package/cjs/hierarchy/useHierarchyDndkitConfig.js.map +0 -7
- package/cjs/hierarchy/useHierarchyPreviewHandlers.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/cjs/tree/constants.js.map +0 -7
- package/cjs/tree/customCollisionDetection.js.map +0 -7
- package/cjs/tree/getTreeKeyboardCoordinates.js.map +0 -7
- package/cjs/tree/index.js.map +0 -7
- package/cjs/tree/types.js.map +0 -7
- package/cjs/tree/useTreeActionHandlers.js.map +0 -7
- package/cjs/tree/useTreeAnnouncements.js.map +0 -7
- package/cjs/tree/useTreeDndkitConfig.js.map +0 -7
- package/cjs/tree/useTreePreviewHandlers.js.map +0 -7
- package/cjs/tree/utilities.js.map +0 -7
- package/esm/hierarchy/customCollisionDetection.js.map +0 -7
- package/esm/hierarchy/getHierarchyKeyboardCoordinates.js.map +0 -7
- package/esm/hierarchy/index.js.map +0 -7
- package/esm/hierarchy/types.js.map +0 -7
- package/esm/hierarchy/useHierarchyActionHandlers.js.map +0 -7
- package/esm/hierarchy/useHierarchyAnnouncements.js.map +0 -7
- package/esm/hierarchy/useHierarchyDndkitConfig.js.map +0 -7
- package/esm/hierarchy/useHierarchyPreviewHandlers.js.map +0 -7
- package/esm/index.js.map +0 -7
- package/esm/tree/constants.js.map +0 -7
- package/esm/tree/customCollisionDetection.js.map +0 -7
- package/esm/tree/getTreeKeyboardCoordinates.js.map +0 -7
- package/esm/tree/index.js.map +0 -7
- package/esm/tree/types.js.map +0 -7
- package/esm/tree/useTreeActionHandlers.js.map +0 -7
- package/esm/tree/useTreeAnnouncements.js.map +0 -7
- package/esm/tree/useTreeDndkitConfig.js.map +0 -7
- package/esm/tree/useTreePreviewHandlers.js.map +0 -7
- package/esm/tree/utilities.js.map +0 -7
|
@@ -1,146 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
7
|
+
require('core-js/modules/esnext.async-iterator.map.js');
|
|
8
|
+
require('core-js/modules/esnext.iterator.map.js');
|
|
9
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
11
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
12
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
13
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
14
|
+
var react = require('react');
|
|
15
|
+
var core = require('@dnd-kit/core');
|
|
16
|
+
var sortable = require('@dnd-kit/sortable');
|
|
17
|
+
var useTreePreviewHandlers = require('./useTreePreviewHandlers.js');
|
|
18
|
+
var getTreeKeyboardCoordinates = require('./getTreeKeyboardCoordinates.js');
|
|
19
|
+
var utilities = require('./utilities.js');
|
|
20
|
+
var useTreeActionHandlers = require('./useTreeActionHandlers.js');
|
|
21
|
+
var constants = require('./constants.js');
|
|
22
|
+
var customCollisionDetection = require('./customCollisionDetection.js');
|
|
23
|
+
var useTreeAnnouncements = require('./useTreeAnnouncements.js');
|
|
24
|
+
|
|
25
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
26
|
+
|
|
27
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
28
|
+
|
|
29
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
30
|
+
|
|
31
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = 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; }
|
|
32
|
+
// if second parameter is true, the space will be done on the horizontal axis
|
|
33
|
+
|
|
34
|
+
const adjustTranslate = isHorizontalDnD => _ref => {
|
|
35
|
+
let {
|
|
36
|
+
transform
|
|
37
|
+
} = _ref;
|
|
38
|
+
|
|
39
|
+
const newTransform = _objectSpread({}, transform);
|
|
40
|
+
|
|
47
41
|
if (isHorizontalDnD) {
|
|
48
42
|
newTransform.x = transform.x + 25;
|
|
49
43
|
} else {
|
|
50
44
|
newTransform.x = transform.x + 15;
|
|
51
45
|
}
|
|
46
|
+
|
|
52
47
|
return newTransform;
|
|
53
48
|
};
|
|
49
|
+
|
|
54
50
|
const measuring = {
|
|
55
51
|
droppable: {
|
|
56
|
-
strategy:
|
|
52
|
+
strategy: core.MeasuringStrategy.BeforeDragging
|
|
57
53
|
}
|
|
58
54
|
};
|
|
59
|
-
const useTreeDndkitConfig =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const [
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
55
|
+
const useTreeDndkitConfig = _ref2 => {
|
|
56
|
+
var _visibleItemsDictiona, _visibleItemsDictiona2;
|
|
57
|
+
|
|
58
|
+
let {
|
|
59
|
+
flattenedItems,
|
|
60
|
+
visibleItems: preVisibleItems,
|
|
61
|
+
isHorizontalDnD = false,
|
|
62
|
+
isExpandable = false,
|
|
63
|
+
onReorder,
|
|
64
|
+
maxDragAndDropLevel
|
|
65
|
+
} = _ref2;
|
|
66
|
+
const [activeId, setActiveId] = react.useState('');
|
|
67
|
+
const [overId, setOverId] = react.useState('');
|
|
68
|
+
const [dropIndicatorPosition, setDropIndicatorPosition] = react.useState(constants.DropIndicatorPosition.None);
|
|
69
|
+
const [lastPosition, setLastPosition] = react.useState(''); // Remove activeId's children
|
|
70
|
+
|
|
71
|
+
const visibleItems = react.useMemo(() => utilities.removeChildrenOf(preVisibleItems, activeId), [preVisibleItems, activeId]); // Sorted ids for the library
|
|
72
|
+
|
|
73
|
+
const sortedIds = react.useMemo(() => visibleItems.map(item => item.uid), [visibleItems]);
|
|
74
|
+
/**
|
|
75
|
+
* Dictionary from UID to ITEM
|
|
76
|
+
* This dictionary is computed since on every DnD move, I need to know the
|
|
77
|
+
* depth of a particular row, so O(1) per DnD move instead of O(#ITEMS)
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
const visibleItemsDictionary = react.useMemo(() => {
|
|
81
|
+
// Using plain for to achieve O(#ITEMS) performance
|
|
74
82
|
const dictionary = {};
|
|
75
|
-
visibleItems.forEach(
|
|
83
|
+
visibleItems.forEach(item => {
|
|
76
84
|
dictionary[item.uid] = item;
|
|
77
85
|
});
|
|
78
86
|
return dictionary;
|
|
79
87
|
}, [visibleItems]);
|
|
80
|
-
const modifiers =
|
|
81
|
-
const sensorContext =
|
|
88
|
+
const modifiers = react.useMemo(() => [adjustTranslate(isHorizontalDnD)], [isHorizontalDnD]);
|
|
89
|
+
const sensorContext = react.useRef({
|
|
82
90
|
items: visibleItems,
|
|
83
91
|
dropIndicatorPosition,
|
|
84
92
|
setDropIndicatorPosition
|
|
85
93
|
});
|
|
86
|
-
|
|
94
|
+
react.useEffect(() => {
|
|
87
95
|
sensorContext.current = {
|
|
88
96
|
items: visibleItems,
|
|
89
97
|
dropIndicatorPosition,
|
|
90
98
|
setDropIndicatorPosition
|
|
91
99
|
};
|
|
92
100
|
}, [visibleItems, dropIndicatorPosition, setDropIndicatorPosition]);
|
|
93
|
-
const coordinateGetter =
|
|
94
|
-
const sensors =
|
|
101
|
+
const coordinateGetter = react.useMemo(() => getTreeKeyboardCoordinates.getTreeKeyboardCoordinates(sensorContext, isHorizontalDnD, maxDragAndDropLevel), [sensorContext, isHorizontalDnD, maxDragAndDropLevel]);
|
|
102
|
+
const sensors = core.useSensors(core.useSensor(core.PointerSensor), core.useSensor(core.KeyboardSensor, {
|
|
95
103
|
coordinateGetter
|
|
96
|
-
}));
|
|
97
|
-
|
|
98
|
-
const
|
|
104
|
+
})); // where is the activeItem being positioned (depth and parent)
|
|
105
|
+
|
|
106
|
+
const projected = react.useMemo(() => overId ? utilities.getProjection(visibleItems, visibleItemsDictionary, overId, dropIndicatorPosition, isExpandable) : null, [overId, visibleItems, visibleItemsDictionary, dropIndicatorPosition, isExpandable]);
|
|
107
|
+
const dragPreviewHandlers = useTreePreviewHandlers.useTreePreviewHandlers({
|
|
99
108
|
setActiveId,
|
|
100
109
|
setOverId,
|
|
101
110
|
setDropIndicatorPosition
|
|
102
111
|
});
|
|
103
|
-
const dragActionHandlers = (
|
|
104
|
-
...dragPreviewHandlers,
|
|
112
|
+
const dragActionHandlers = useTreeActionHandlers.useTreeActionHandlers(_objectSpread(_objectSpread({}, dragPreviewHandlers), {}, {
|
|
105
113
|
onReorder,
|
|
106
114
|
projected,
|
|
107
115
|
flattenedItems,
|
|
108
116
|
dropIndicatorPosition
|
|
109
|
-
});
|
|
110
|
-
const announcements =
|
|
111
|
-
const dndContextProps =
|
|
117
|
+
}));
|
|
118
|
+
const announcements = useTreeAnnouncements.useTreeAnnouncements(visibleItemsDictionary, dropIndicatorPosition);
|
|
119
|
+
const dndContextProps = react.useMemo(() => _objectSpread({
|
|
112
120
|
announcements,
|
|
113
121
|
modifiers,
|
|
114
122
|
sensors,
|
|
115
123
|
measuring,
|
|
116
|
-
collisionDetection:
|
|
117
|
-
|
|
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)(() => ({
|
|
124
|
+
collisionDetection: customCollisionDetection.customCollisionDetection(activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition)
|
|
125
|
+
}, dragActionHandlers), [announcements, modifiers, sensors, dragActionHandlers, visibleItemsDictionary, setDropIndicatorPosition, activeId, maxDragAndDropLevel, lastPosition, setLastPosition]);
|
|
126
|
+
const sortableContextProps = react.useMemo(() => ({
|
|
131
127
|
items: sortedIds,
|
|
132
|
-
strategy: isHorizontalDnD ?
|
|
128
|
+
strategy: isHorizontalDnD ? sortable.horizontalListSortingStrategy : sortable.verticalListSortingStrategy
|
|
133
129
|
}), [sortedIds, isHorizontalDnD]);
|
|
134
130
|
return {
|
|
135
131
|
dndContextProps,
|
|
136
132
|
sortableContextProps,
|
|
137
133
|
activeId,
|
|
138
|
-
activeIndex: visibleItemsDictionary[activeId]
|
|
134
|
+
activeIndex: (_visibleItemsDictiona = (_visibleItemsDictiona2 = visibleItemsDictionary[activeId]) === null || _visibleItemsDictiona2 === void 0 ? void 0 : _visibleItemsDictiona2.realIndex) !== null && _visibleItemsDictiona !== void 0 ? _visibleItemsDictiona : -1,
|
|
139
135
|
overId,
|
|
140
136
|
depth: projected ? projected.depth : 0,
|
|
141
137
|
dropIndicatorPosition,
|
|
142
138
|
visibleItems
|
|
143
139
|
};
|
|
144
140
|
};
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
|
|
142
|
+
exports.useTreeDndkitConfig = useTreeDndkitConfig;
|
|
@@ -1,61 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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 =
|
|
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(
|
|
49
|
-
document.body.style.setProperty(
|
|
27
|
+
setDropIndicatorPosition(constants.DropIndicatorPosition.Inside);
|
|
28
|
+
document.body.style.setProperty('cursor', 'grabbing');
|
|
50
29
|
}, [setActiveId, setDropIndicatorPosition, setOverId]);
|
|
51
|
-
const handlePreviewDragMove =
|
|
52
|
-
const handlePreviewDragOver =
|
|
53
|
-
|
|
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 =
|
|
39
|
+
const handlePreviewDragEnd = react.useCallback(() => {
|
|
56
40
|
resetState();
|
|
57
41
|
}, [resetState]);
|
|
58
|
-
const handlePreviewDragCancel =
|
|
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
|
-
|
|
70
|
-
|
|
53
|
+
|
|
54
|
+
exports.useTreePreviewHandlers = useTreePreviewHandlers;
|
package/cjs/tree/utilities.js
CHANGED
|
@@ -1,66 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
|
|
26
|
+
|
|
27
|
+
if (dropIndicatorPosition === constants.DropIndicatorPosition.Before) {
|
|
28
|
+
return {
|
|
29
|
+
depth: getMinDepth(previousItem),
|
|
30
|
+
parentId: previousItem.parentId
|
|
31
|
+
};
|
|
52
32
|
}
|
|
53
|
-
|
|
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(
|
|
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
|
-
|
|
66
|
-
|
|
50
|
+
|
|
51
|
+
exports.getProjection = getProjection;
|
|
52
|
+
exports.removeChildrenOf = removeChildrenOf;
|
|
@@ -1,22 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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(
|
|
42
|
+
entriesWithSameParent.forEach(entry => {
|
|
15
43
|
const {
|
|
16
|
-
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
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=customCollisionDetection.js.map
|
|
65
|
+
|
|
66
|
+
export { customCollisionDetection };
|