@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,109 +1,123 @@
|
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
event,
|
|
43
|
-
currentCoordinates,
|
|
44
|
-
droppableContainers,
|
|
45
|
-
collisionRect,
|
|
46
|
-
dropIndicatorPosition,
|
|
47
|
-
maxDragAndDropLevel
|
|
48
|
-
}) => {
|
|
49
|
-
if (horizontal.includes(event.code))
|
|
50
|
-
return void 0;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
8
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
9
|
+
require('core-js/modules/esnext.async-iterator.find.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.find.js');
|
|
11
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
12
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
13
|
+
var core = require('@dnd-kit/core');
|
|
14
|
+
var constants = require('./constants.js');
|
|
15
|
+
|
|
16
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
|
+
|
|
18
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
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__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; }
|
|
23
|
+
const directions = [core.KeyboardCode.Down, core.KeyboardCode.Right, core.KeyboardCode.Up, core.KeyboardCode.Left];
|
|
24
|
+
const horizontal = [core.KeyboardCode.Left, core.KeyboardCode.Right];
|
|
25
|
+
[core.KeyboardCode.Up, core.KeyboardCode.Down];
|
|
26
|
+
|
|
27
|
+
const getVerticalKeyboardCoordinates = _ref => {
|
|
28
|
+
var _droppableContainers$, _droppableContainers$2;
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
items,
|
|
32
|
+
active,
|
|
33
|
+
over,
|
|
34
|
+
event,
|
|
35
|
+
currentCoordinates,
|
|
36
|
+
droppableContainers,
|
|
37
|
+
collisionRect,
|
|
38
|
+
dropIndicatorPosition,
|
|
39
|
+
maxDragAndDropLevel
|
|
40
|
+
} = _ref;
|
|
41
|
+
if (horizontal.includes(event.code)) return undefined;
|
|
51
42
|
const overRect = over.rect;
|
|
52
|
-
const layoutRects = [];
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
const layoutRects = []; // Get the reacheable rects depending on the arrow key pressed
|
|
44
|
+
|
|
45
|
+
droppableContainers.forEach(container => {
|
|
46
|
+
if (container !== null && container !== void 0 && container.disabled || !overRect) {
|
|
55
47
|
return;
|
|
56
48
|
}
|
|
49
|
+
|
|
57
50
|
const rect = container.rect.current;
|
|
58
|
-
|
|
51
|
+
|
|
52
|
+
if (rect && event.code === core.KeyboardCode.Down && collisionRect.top - 2 <= rect.offsetTop) {
|
|
59
53
|
layoutRects.push(container);
|
|
60
|
-
} else if (rect && event.code ===
|
|
54
|
+
} else if (rect && event.code === core.KeyboardCode.Up && collisionRect.top >= rect.offsetTop) {
|
|
61
55
|
layoutRects.push(container);
|
|
62
56
|
}
|
|
63
57
|
});
|
|
64
|
-
const closestId =
|
|
58
|
+
const closestId = core.closestCorners({
|
|
65
59
|
collisionRect,
|
|
66
60
|
droppableContainers: layoutRects,
|
|
67
61
|
active
|
|
68
62
|
});
|
|
69
|
-
const closestItem = items.find(
|
|
70
|
-
const closestElement = droppableContainers.get(closestId)
|
|
71
|
-
if (!closestId || !closestItem || !closestElement)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (event.code ===
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
63
|
+
const closestItem = items.find(item => item.uid === closestId);
|
|
64
|
+
const closestElement = (_droppableContainers$ = droppableContainers.get(closestId)) === null || _droppableContainers$ === void 0 ? void 0 : (_droppableContainers$2 = _droppableContainers$.node) === null || _droppableContainers$2 === void 0 ? void 0 : _droppableContainers$2.current;
|
|
65
|
+
if (!closestId || !closestItem || !closestElement) return undefined;
|
|
66
|
+
const closestRect = core.getViewRect(closestElement);
|
|
67
|
+
|
|
68
|
+
if (event.code === core.KeyboardCode.Up) {
|
|
69
|
+
// If the drop indicator is inside (or over ourselves)
|
|
70
|
+
// We are gonna go to the before position
|
|
71
|
+
// Else we are gonna go inside the over rect
|
|
72
|
+
if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside || closestId === active.id || closestItem.depth + 1 > maxDragAndDropLevel) {
|
|
73
|
+
return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
|
|
78
74
|
y: closestRect.top - collisionRect.height / 2
|
|
79
|
-
};
|
|
75
|
+
});
|
|
80
76
|
}
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
|
|
78
|
+
return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
|
|
83
79
|
y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
});
|
|
81
|
+
} // If the drop indicator is inside (or over ourselves)
|
|
82
|
+
// We are gonna go to the after position
|
|
83
|
+
// Else we are gonna go inside the over rect
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside || closestId === active.id || closestItem.depth + 1 > maxDragAndDropLevel) {
|
|
87
|
+
return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
|
|
89
88
|
y: closestRect.top + collisionRect.height / 2
|
|
90
|
-
};
|
|
89
|
+
});
|
|
91
90
|
}
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
|
|
92
|
+
return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
|
|
94
93
|
y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2
|
|
95
|
-
};
|
|
94
|
+
});
|
|
96
95
|
};
|
|
97
|
-
|
|
96
|
+
|
|
97
|
+
const getTreeKeyboardCoordinates = (context, isHorizontalDnD, maxDragAndDropLevel) => (event, _ref2) => {
|
|
98
|
+
let {
|
|
99
|
+
currentCoordinates,
|
|
100
|
+
context: {
|
|
101
|
+
over,
|
|
102
|
+
translatedRect,
|
|
103
|
+
droppableContainers,
|
|
104
|
+
active,
|
|
105
|
+
collisionRect
|
|
106
|
+
}
|
|
107
|
+
} = _ref2;
|
|
108
|
+
|
|
98
109
|
if (directions.includes(event.code)) {
|
|
99
110
|
if (!translatedRect) {
|
|
100
|
-
return
|
|
111
|
+
return undefined;
|
|
101
112
|
}
|
|
113
|
+
|
|
102
114
|
const {
|
|
103
|
-
current: {
|
|
115
|
+
current: {
|
|
116
|
+
items,
|
|
117
|
+
dropIndicatorPosition
|
|
118
|
+
}
|
|
104
119
|
} = context;
|
|
105
|
-
if (!over || !active || !collisionRect)
|
|
106
|
-
return void 0;
|
|
120
|
+
if (!over || !active || !collisionRect) return undefined;
|
|
107
121
|
const args = {
|
|
108
122
|
items,
|
|
109
123
|
active,
|
|
@@ -115,11 +129,11 @@ const getTreeKeyboardCoordinates = (context, isHorizontalDnD, maxDragAndDropLeve
|
|
|
115
129
|
dropIndicatorPosition,
|
|
116
130
|
maxDragAndDropLevel
|
|
117
131
|
};
|
|
118
|
-
if (isHorizontalDnD)
|
|
119
|
-
return void 0;
|
|
132
|
+
if (isHorizontalDnD) return undefined;
|
|
120
133
|
return getVerticalKeyboardCoordinates(args);
|
|
121
134
|
}
|
|
122
|
-
|
|
135
|
+
|
|
136
|
+
return undefined;
|
|
123
137
|
};
|
|
124
|
-
|
|
125
|
-
|
|
138
|
+
|
|
139
|
+
exports.getTreeKeyboardCoordinates = getTreeKeyboardCoordinates;
|
package/cjs/tree/index.js
CHANGED
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
for (let key of __getOwnPropNames(module2))
|
|
11
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
12
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (module2, isNodeMode) => {
|
|
17
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
20
|
-
return (module2, temp) => {
|
|
21
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
22
|
-
};
|
|
23
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
24
|
-
var tree_exports = {};
|
|
25
|
-
var React = __toESM(require("react"));
|
|
26
|
-
__reExport(tree_exports, __toESM(require("./useTreeDndkitConfig")));
|
|
27
|
-
module.exports = __toCommonJS(tree_exports);
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var useTreeDndkitConfig = require('./useTreeDndkitConfig.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.useTreeDndkitConfig = useTreeDndkitConfig.useTreeDndkitConfig;
|
package/cjs/tree/types.js
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 __reExport = (target, module2, copyDefault, desc) => {
|
|
9
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(module2))
|
|
11
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
12
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (module2, isNodeMode) => {
|
|
17
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
20
|
-
return (module2, temp) => {
|
|
21
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
22
|
-
};
|
|
23
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
24
|
-
var types_exports = {};
|
|
25
|
-
var React = __toESM(require("react"));
|
|
26
|
-
module.exports = __toCommonJS(types_exports);
|
|
27
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
@@ -1,85 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 useTreeActionHandlers_exports = {};
|
|
29
|
-
__export(useTreeActionHandlers_exports, {
|
|
30
|
-
useTreeActionHandlers: () => useTreeActionHandlers
|
|
31
|
-
});
|
|
32
|
-
var React = __toESM(require("react"));
|
|
33
|
-
var import_sortable = __toESM(require("@dnd-kit/sortable"));
|
|
34
|
-
var import_lodash = __toESM(require("lodash"));
|
|
35
|
-
var import_react = __toESM(require("react"));
|
|
36
|
-
var import_constants = __toESM(require("./constants"));
|
|
37
|
-
const useTreeActionHandlers = ({
|
|
38
|
-
handlePreviewDragStart,
|
|
39
|
-
handlePreviewDragMove,
|
|
40
|
-
handlePreviewDragOver,
|
|
41
|
-
handlePreviewDragEnd,
|
|
42
|
-
handlePreviewDragCancel,
|
|
43
|
-
onReorder,
|
|
44
|
-
flattenedItems,
|
|
45
|
-
projected,
|
|
46
|
-
dropIndicatorPosition
|
|
47
|
-
}) => {
|
|
48
|
-
const onDragStart = (0, import_react.useCallback)((e) => {
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var sortable = require('@dnd-kit/sortable');
|
|
6
|
+
var lodash = require('lodash');
|
|
7
|
+
var react = require('react');
|
|
8
|
+
var constants = require('./constants.js');
|
|
9
|
+
|
|
10
|
+
const useTreeActionHandlers = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
handlePreviewDragStart,
|
|
13
|
+
handlePreviewDragMove,
|
|
14
|
+
handlePreviewDragOver,
|
|
15
|
+
handlePreviewDragEnd,
|
|
16
|
+
handlePreviewDragCancel,
|
|
17
|
+
onReorder,
|
|
18
|
+
flattenedItems,
|
|
19
|
+
projected,
|
|
20
|
+
dropIndicatorPosition
|
|
21
|
+
} = _ref;
|
|
22
|
+
const onDragStart = react.useCallback(e => {
|
|
49
23
|
handlePreviewDragStart(e);
|
|
50
24
|
}, [handlePreviewDragStart]);
|
|
51
|
-
const onDragMove =
|
|
25
|
+
const onDragMove = react.useCallback(e => {
|
|
52
26
|
handlePreviewDragMove(e);
|
|
53
27
|
}, [handlePreviewDragMove]);
|
|
54
|
-
const onDragOver =
|
|
28
|
+
const onDragOver = react.useCallback(e => {
|
|
55
29
|
handlePreviewDragOver(e);
|
|
56
30
|
}, [handlePreviewDragOver]);
|
|
57
|
-
const onDragEnd =
|
|
31
|
+
const onDragEnd = react.useCallback(e => {
|
|
58
32
|
handlePreviewDragEnd(e);
|
|
59
|
-
const {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
33
|
+
const {
|
|
34
|
+
active,
|
|
35
|
+
over
|
|
36
|
+
} = e;
|
|
37
|
+
if (over === null) return;
|
|
38
|
+
const activeIndex = flattenedItems.findIndex(item => item.uid === active.id);
|
|
63
39
|
let considerExpanding = null;
|
|
64
|
-
let overIndex = flattenedItems.findIndex(
|
|
65
|
-
|
|
40
|
+
let overIndex = flattenedItems.findIndex(item => item.uid === over.id); // If drop indicator is inside, then put it last,
|
|
41
|
+
// It will be reconstructed well later
|
|
42
|
+
|
|
43
|
+
if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside) {
|
|
44
|
+
var _flattenedItems$overI, _flattenedItems$overI2;
|
|
45
|
+
|
|
66
46
|
considerExpanding = over.id;
|
|
67
|
-
overIndex = flattenedItems[overIndex].realIndex + (flattenedItems[overIndex].original.subRows
|
|
68
|
-
}
|
|
47
|
+
overIndex = flattenedItems[overIndex].realIndex + ((_flattenedItems$overI = (_flattenedItems$overI2 = flattenedItems[overIndex].original.subRows) === null || _flattenedItems$overI2 === void 0 ? void 0 : _flattenedItems$overI2.length) !== null && _flattenedItems$overI !== void 0 ? _flattenedItems$overI : 0) + 1;
|
|
48
|
+
} // If we are dropping the item in a new position, or new depth
|
|
49
|
+
|
|
50
|
+
|
|
69
51
|
if (projected && (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth)) {
|
|
52
|
+
// Change parent and depth from projected data
|
|
70
53
|
flattenedItems[activeIndex].parentId = projected.parentId;
|
|
71
|
-
flattenedItems[activeIndex].depth = projected.depth;
|
|
72
|
-
|
|
54
|
+
flattenedItems[activeIndex].depth = projected.depth; // If same index, don't move the array, just copy it
|
|
55
|
+
|
|
56
|
+
const newFlattenedData = activeIndex !== overIndex ? sortable.arrayMove(flattenedItems, activeIndex, overIndex) : lodash.cloneDeep(flattenedItems);
|
|
73
57
|
onReorder(newFlattenedData, {
|
|
74
58
|
targetIndex: overIndex,
|
|
75
59
|
fromIndex: activeIndex
|
|
76
|
-
}, considerExpanding ||
|
|
60
|
+
}, considerExpanding || '');
|
|
77
61
|
}
|
|
78
62
|
}, [handlePreviewDragEnd, flattenedItems, projected, onReorder, dropIndicatorPosition]);
|
|
79
|
-
const onDragCancel =
|
|
63
|
+
const onDragCancel = react.useCallback(e => {
|
|
80
64
|
handlePreviewDragCancel(e);
|
|
81
65
|
}, [handlePreviewDragCancel]);
|
|
82
|
-
return {
|
|
66
|
+
return {
|
|
67
|
+
onDragStart,
|
|
68
|
+
onDragMove,
|
|
69
|
+
onDragOver,
|
|
70
|
+
onDragEnd,
|
|
71
|
+
onDragCancel
|
|
72
|
+
};
|
|
83
73
|
};
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
|
|
75
|
+
exports.useTreeActionHandlers = useTreeActionHandlers;
|
|
@@ -1,68 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
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 useTreeAnnouncements_exports = {};
|
|
29
|
-
__export(useTreeAnnouncements_exports, {
|
|
30
|
-
useTreeAnnouncements: () => useTreeAnnouncements
|
|
31
|
-
});
|
|
32
|
-
var React = __toESM(require("react"));
|
|
33
|
-
var import_react = __toESM(require("react"));
|
|
34
|
-
var import_constants = __toESM(require("./constants"));
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var constants = require('./constants.js');
|
|
7
|
+
|
|
35
8
|
const useTreeAnnouncements = (visibleItemsDictionary, dropIndicatorPosition) => {
|
|
36
|
-
const onDragStart =
|
|
37
|
-
const onDragMove =
|
|
9
|
+
const onDragStart = react.useCallback(id => "Picked up draggable item from position ".concat(visibleItemsDictionary[id].realIndex + 1, "."), [visibleItemsDictionary]);
|
|
10
|
+
const onDragMove = react.useCallback((id, overId) => {
|
|
38
11
|
if (overId) {
|
|
39
12
|
const overIndex = visibleItemsDictionary[overId].realIndex + 1;
|
|
40
|
-
|
|
41
|
-
|
|
13
|
+
|
|
14
|
+
if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside) {
|
|
15
|
+
return "Draggable item was moved inside the item at position ".concat(overIndex, ".");
|
|
42
16
|
}
|
|
43
|
-
|
|
44
|
-
|
|
17
|
+
|
|
18
|
+
if (dropIndicatorPosition === constants.DropIndicatorPosition.Before) {
|
|
19
|
+
return "Draggable item was moved to position ".concat(overIndex - 1, ".");
|
|
45
20
|
}
|
|
46
|
-
|
|
21
|
+
|
|
22
|
+
return "Draggable item was moved to position ".concat(overIndex, ".");
|
|
47
23
|
}
|
|
48
|
-
|
|
24
|
+
|
|
25
|
+
return "Draggable item is no longer over a droppable area.";
|
|
49
26
|
}, [visibleItemsDictionary, dropIndicatorPosition]);
|
|
50
27
|
const onDragOver = onDragMove;
|
|
51
|
-
const onDragEnd =
|
|
28
|
+
const onDragEnd = react.useCallback((id, overId) => {
|
|
52
29
|
if (overId) {
|
|
53
30
|
const overIndex = visibleItemsDictionary[overId].realIndex + 1;
|
|
54
|
-
|
|
55
|
-
|
|
31
|
+
|
|
32
|
+
if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside) {
|
|
33
|
+
return "Draggable item was dropped inside the item at position ".concat(overIndex, ".");
|
|
56
34
|
}
|
|
57
|
-
|
|
58
|
-
|
|
35
|
+
|
|
36
|
+
if (dropIndicatorPosition === constants.DropIndicatorPosition.Before) {
|
|
37
|
+
return "Draggable item was dropped over position ".concat(overIndex - 1, ".");
|
|
59
38
|
}
|
|
60
|
-
|
|
39
|
+
|
|
40
|
+
return "Draggable item was dropped over position ".concat(overIndex, ".");
|
|
61
41
|
}
|
|
62
|
-
|
|
42
|
+
|
|
43
|
+
return "Draggable item was dropped at it's original position.";
|
|
63
44
|
}, [dropIndicatorPosition, visibleItemsDictionary]);
|
|
64
|
-
const onDragCancel =
|
|
65
|
-
return {
|
|
45
|
+
const onDragCancel = react.useCallback(id => "Dragging was cancelled. Draggable item from position ".concat(visibleItemsDictionary[id].realIndex + 1, " was dropped at it's initial position."), [visibleItemsDictionary]);
|
|
46
|
+
return {
|
|
47
|
+
onDragStart,
|
|
48
|
+
onDragOver,
|
|
49
|
+
onDragMove,
|
|
50
|
+
onDragEnd,
|
|
51
|
+
onDragCancel
|
|
52
|
+
};
|
|
66
53
|
};
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
|
|
55
|
+
exports.useTreeAnnouncements = useTreeAnnouncements;
|