@react-aria/dnd 3.5.4-nightly.4555 → 3.5.4-nightly.4558
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/dist/DragManager.main.js +444 -0
- package/dist/DragManager.main.js.map +1 -0
- package/dist/DragManager.mjs +435 -0
- package/dist/DragManager.module.js +435 -0
- package/dist/DragManager.module.js.map +1 -0
- package/dist/DragPreview.main.js +59 -0
- package/dist/DragPreview.main.js.map +1 -0
- package/dist/DragPreview.mjs +50 -0
- package/dist/DragPreview.module.js +50 -0
- package/dist/DragPreview.module.js.map +1 -0
- package/dist/ListDropTargetDelegate.main.js +119 -0
- package/dist/ListDropTargetDelegate.main.js.map +1 -0
- package/dist/ListDropTargetDelegate.mjs +114 -0
- package/dist/ListDropTargetDelegate.module.js +114 -0
- package/dist/ListDropTargetDelegate.module.js.map +1 -0
- package/dist/ar-AE.mjs +1 -1
- package/dist/bg-BG.mjs +1 -1
- package/dist/constants.main.js +65 -0
- package/dist/constants.main.js.map +1 -0
- package/dist/constants.mjs +53 -0
- package/dist/constants.module.js +53 -0
- package/dist/constants.module.js.map +1 -0
- package/dist/cs-CZ.mjs +1 -1
- package/dist/da-DK.mjs +1 -1
- package/dist/de-DE.mjs +1 -1
- package/dist/el-GR.mjs +1 -1
- package/dist/en-US.mjs +1 -1
- package/dist/es-ES.mjs +1 -1
- package/dist/et-EE.mjs +1 -1
- package/dist/fi-FI.mjs +1 -1
- package/dist/fr-FR.mjs +1 -1
- package/dist/he-IL.mjs +1 -1
- package/dist/hr-HR.mjs +1 -1
- package/dist/hu-HU.mjs +1 -1
- package/dist/import.mjs +12 -2582
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/it-IT.mjs +1 -1
- package/dist/ja-JP.mjs +1 -1
- package/dist/ko-KR.mjs +1 -1
- package/dist/lt-LT.mjs +1 -1
- package/dist/lv-LV.mjs +1 -1
- package/dist/main.js +27 -2597
- package/dist/main.js.map +1 -1
- package/dist/module.js +12 -2582
- package/dist/module.js.map +1 -1
- package/dist/nb-NO.mjs +1 -1
- package/dist/nl-NL.mjs +1 -1
- package/dist/pl-PL.mjs +1 -1
- package/dist/pt-BR.mjs +1 -1
- package/dist/pt-PT.mjs +1 -1
- package/dist/ro-RO.mjs +1 -1
- package/dist/ru-RU.mjs +1 -1
- package/dist/sk-SK.mjs +1 -1
- package/dist/sl-SI.mjs +1 -1
- package/dist/sr-SP.mjs +1 -1
- package/dist/sv-SE.mjs +1 -1
- package/dist/tr-TR.mjs +1 -1
- package/dist/uk-UA.mjs +1 -1
- package/dist/useAutoScroll.main.js +89 -0
- package/dist/useAutoScroll.main.js.map +1 -0
- package/dist/useAutoScroll.mjs +84 -0
- package/dist/useAutoScroll.module.js +84 -0
- package/dist/useAutoScroll.module.js.map +1 -0
- package/dist/useClipboard.main.js +107 -0
- package/dist/useClipboard.main.js.map +1 -0
- package/dist/useClipboard.mjs +102 -0
- package/dist/useClipboard.module.js +102 -0
- package/dist/useClipboard.module.js.map +1 -0
- package/dist/useDrag.main.js +279 -0
- package/dist/useDrag.main.js.map +1 -0
- package/dist/useDrag.mjs +274 -0
- package/dist/useDrag.module.js +274 -0
- package/dist/useDrag.module.js.map +1 -0
- package/dist/useDraggableCollection.main.js +27 -0
- package/dist/useDraggableCollection.main.js.map +1 -0
- package/dist/useDraggableCollection.mjs +22 -0
- package/dist/useDraggableCollection.module.js +22 -0
- package/dist/useDraggableCollection.module.js.map +1 -0
- package/dist/useDraggableItem.main.js +128 -0
- package/dist/useDraggableItem.main.js.map +1 -0
- package/dist/useDraggableItem.mjs +123 -0
- package/dist/useDraggableItem.module.js +123 -0
- package/dist/useDraggableItem.module.js.map +1 -0
- package/dist/useDrop.main.js +299 -0
- package/dist/useDrop.main.js.map +1 -0
- package/dist/useDrop.mjs +294 -0
- package/dist/useDrop.module.js +294 -0
- package/dist/useDrop.module.js.map +1 -0
- package/dist/useDropIndicator.main.js +93 -0
- package/dist/useDropIndicator.main.js.map +1 -0
- package/dist/useDropIndicator.mjs +88 -0
- package/dist/useDropIndicator.module.js +88 -0
- package/dist/useDropIndicator.module.js.map +1 -0
- package/dist/useDroppableCollection.main.js +583 -0
- package/dist/useDroppableCollection.main.js.map +1 -0
- package/dist/useDroppableCollection.mjs +578 -0
- package/dist/useDroppableCollection.module.js +578 -0
- package/dist/useDroppableCollection.module.js.map +1 -0
- package/dist/useDroppableItem.main.js +79 -0
- package/dist/useDroppableItem.main.js.map +1 -0
- package/dist/useDroppableItem.mjs +74 -0
- package/dist/useDroppableItem.module.js +74 -0
- package/dist/useDroppableItem.module.js.map +1 -0
- package/dist/useVirtualDrop.main.js +56 -0
- package/dist/useVirtualDrop.main.js.map +1 -0
- package/dist/useVirtualDrop.mjs +51 -0
- package/dist/useVirtualDrop.module.js +51 -0
- package/dist/useVirtualDrop.module.js.map +1 -0
- package/dist/utils.main.js +283 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +255 -0
- package/dist/utils.module.js +255 -0
- package/dist/utils.module.js.map +1 -0
- package/dist/zh-CN.mjs +1 -1
- package/dist/zh-TW.mjs +1 -1
- package/package.json +11 -11
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import {clearGlobalDnDState as $7252cd45fc48c07c$export$70936501603e6c57, DIRECTORY_DRAG_TYPE as $7252cd45fc48c07c$export$990fced5dfac2637, droppableCollectionMap as $7252cd45fc48c07c$export$dfdf5deeaf27473f, getTypes as $7252cd45fc48c07c$export$e1d41611756c6326, globalDndState as $7252cd45fc48c07c$export$6ca6700462636d0b, isInternalDropOperation as $7252cd45fc48c07c$export$78bf638634500fa5, setDropCollectionRef as $7252cd45fc48c07c$export$dac8db29d42db9a1} from "./utils.module.js";
|
|
2
|
+
import {registerDropTarget as $67560de7c78cb232$export$c28d9fb4a54e471a} from "./DragManager.module.js";
|
|
3
|
+
import {useAutoScroll as $80d9daea3067eff3$export$6323452ca4533ed8} from "./useAutoScroll.module.js";
|
|
4
|
+
import {useDrop as $5c06e4929e123553$export$ccdee5eaf73cf661} from "./useDrop.module.js";
|
|
5
|
+
import {useRef as $4ZR0C$useRef, useCallback as $4ZR0C$useCallback, useEffect as $4ZR0C$useEffect} from "react";
|
|
6
|
+
import {useLayoutEffect as $4ZR0C$useLayoutEffect, useId as $4ZR0C$useId, mergeProps as $4ZR0C$mergeProps} from "@react-aria/utils";
|
|
7
|
+
import {setInteractionModality as $4ZR0C$setInteractionModality} from "@react-aria/interactions";
|
|
8
|
+
import {useLocale as $4ZR0C$useLocale} from "@react-aria/i18n";
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const $4b52e4eff84e5217$var$DROP_POSITIONS = [
|
|
29
|
+
"before",
|
|
30
|
+
"on",
|
|
31
|
+
"after"
|
|
32
|
+
];
|
|
33
|
+
const $4b52e4eff84e5217$var$DROP_POSITIONS_RTL = [
|
|
34
|
+
"after",
|
|
35
|
+
"on",
|
|
36
|
+
"before"
|
|
37
|
+
];
|
|
38
|
+
function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
|
|
39
|
+
let localState = (0, $4ZR0C$useRef)({
|
|
40
|
+
props: props,
|
|
41
|
+
state: state,
|
|
42
|
+
nextTarget: null,
|
|
43
|
+
dropOperation: null
|
|
44
|
+
}).current;
|
|
45
|
+
localState.props = props;
|
|
46
|
+
localState.state = state;
|
|
47
|
+
let defaultOnDrop = (0, $4ZR0C$useCallback)(async (e)=>{
|
|
48
|
+
let { onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, acceptedDragTypes: acceptedDragTypes = "all", shouldAcceptItemDrop: shouldAcceptItemDrop } = localState.props;
|
|
49
|
+
let { draggingKeys: draggingKeys } = (0, $7252cd45fc48c07c$export$6ca6700462636d0b);
|
|
50
|
+
let isInternal = (0, $7252cd45fc48c07c$export$78bf638634500fa5)(ref);
|
|
51
|
+
let { target: target, dropOperation: dropOperation, items: items } = e;
|
|
52
|
+
let filteredItems = items;
|
|
53
|
+
if (acceptedDragTypes !== "all" || shouldAcceptItemDrop) filteredItems = items.filter((item)=>{
|
|
54
|
+
let itemTypes;
|
|
55
|
+
if (item.kind === "directory") itemTypes = new Set([
|
|
56
|
+
(0, $7252cd45fc48c07c$export$990fced5dfac2637)
|
|
57
|
+
]);
|
|
58
|
+
else itemTypes = item.kind === "file" ? new Set([
|
|
59
|
+
item.type
|
|
60
|
+
]) : item.types;
|
|
61
|
+
if (acceptedDragTypes === "all" || acceptedDragTypes.some((type)=>itemTypes.has(type))) {
|
|
62
|
+
// If we are performing a on item drop, check if the item in question accepts the dropped item since the item may have heavier restrictions
|
|
63
|
+
// than the droppable collection itself
|
|
64
|
+
if (target.type === "item" && target.dropPosition === "on" && shouldAcceptItemDrop) return shouldAcceptItemDrop(target, itemTypes);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
});
|
|
69
|
+
if (filteredItems.length > 0) {
|
|
70
|
+
if (target.type === "root" && onRootDrop) await onRootDrop({
|
|
71
|
+
items: filteredItems,
|
|
72
|
+
dropOperation: dropOperation
|
|
73
|
+
});
|
|
74
|
+
if (target.type === "item") {
|
|
75
|
+
if (target.dropPosition === "on" && onItemDrop) await onItemDrop({
|
|
76
|
+
items: filteredItems,
|
|
77
|
+
dropOperation: dropOperation,
|
|
78
|
+
isInternal: isInternal,
|
|
79
|
+
target: target
|
|
80
|
+
});
|
|
81
|
+
if (target.dropPosition !== "on") {
|
|
82
|
+
if (!isInternal && onInsert) await onInsert({
|
|
83
|
+
items: filteredItems,
|
|
84
|
+
dropOperation: dropOperation,
|
|
85
|
+
target: target
|
|
86
|
+
});
|
|
87
|
+
if (isInternal && onReorder) await onReorder({
|
|
88
|
+
keys: draggingKeys,
|
|
89
|
+
dropOperation: dropOperation,
|
|
90
|
+
target: target
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, [
|
|
96
|
+
localState,
|
|
97
|
+
ref
|
|
98
|
+
]);
|
|
99
|
+
let autoScroll = (0, $80d9daea3067eff3$export$6323452ca4533ed8)(ref);
|
|
100
|
+
let { dropProps: dropProps } = (0, $5c06e4929e123553$export$ccdee5eaf73cf661)({
|
|
101
|
+
ref: ref,
|
|
102
|
+
onDropEnter () {
|
|
103
|
+
state.setTarget(localState.nextTarget);
|
|
104
|
+
},
|
|
105
|
+
onDropMove (e) {
|
|
106
|
+
state.setTarget(localState.nextTarget);
|
|
107
|
+
autoScroll.move(e.x, e.y);
|
|
108
|
+
},
|
|
109
|
+
getDropOperationForPoint (types, allowedOperations, x, y) {
|
|
110
|
+
let { draggingKeys: draggingKeys, dropCollectionRef: dropCollectionRef } = (0, $7252cd45fc48c07c$export$6ca6700462636d0b);
|
|
111
|
+
let isInternal = (0, $7252cd45fc48c07c$export$78bf638634500fa5)(ref);
|
|
112
|
+
let isValidDropTarget = (target)=>state.getDropOperation({
|
|
113
|
+
target: target,
|
|
114
|
+
types: types,
|
|
115
|
+
allowedOperations: allowedOperations,
|
|
116
|
+
isInternal: isInternal,
|
|
117
|
+
draggingKeys: draggingKeys
|
|
118
|
+
}) !== "cancel";
|
|
119
|
+
let target = props.dropTargetDelegate.getDropTargetFromPoint(x, y, isValidDropTarget);
|
|
120
|
+
if (!target) {
|
|
121
|
+
localState.dropOperation = "cancel";
|
|
122
|
+
localState.nextTarget = null;
|
|
123
|
+
return "cancel";
|
|
124
|
+
}
|
|
125
|
+
localState.dropOperation = state.getDropOperation({
|
|
126
|
+
target: target,
|
|
127
|
+
types: types,
|
|
128
|
+
allowedOperations: allowedOperations,
|
|
129
|
+
isInternal: isInternal,
|
|
130
|
+
draggingKeys: draggingKeys
|
|
131
|
+
});
|
|
132
|
+
// If the target doesn't accept the drop, see if the root accepts it instead.
|
|
133
|
+
if (localState.dropOperation === "cancel") {
|
|
134
|
+
let rootTarget = {
|
|
135
|
+
type: "root"
|
|
136
|
+
};
|
|
137
|
+
let dropOperation = state.getDropOperation({
|
|
138
|
+
target: rootTarget,
|
|
139
|
+
types: types,
|
|
140
|
+
allowedOperations: allowedOperations,
|
|
141
|
+
isInternal: isInternal,
|
|
142
|
+
draggingKeys: draggingKeys
|
|
143
|
+
});
|
|
144
|
+
if (dropOperation !== "cancel") {
|
|
145
|
+
target = rootTarget;
|
|
146
|
+
localState.dropOperation = dropOperation;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Only set dropCollectionRef if there is a valid drop target since we cleanup dropCollectionRef in onDropExit
|
|
150
|
+
// which only runs when leaving a valid drop target or if the dropEffect become none (mouse dnd only).
|
|
151
|
+
if (target && localState.dropOperation !== "cancel" && (ref === null || ref === void 0 ? void 0 : ref.current) !== (dropCollectionRef === null || dropCollectionRef === void 0 ? void 0 : dropCollectionRef.current)) (0, $7252cd45fc48c07c$export$dac8db29d42db9a1)(ref);
|
|
152
|
+
localState.nextTarget = localState.dropOperation === "cancel" ? null : target;
|
|
153
|
+
return localState.dropOperation;
|
|
154
|
+
},
|
|
155
|
+
onDropExit () {
|
|
156
|
+
(0, $7252cd45fc48c07c$export$dac8db29d42db9a1)(undefined);
|
|
157
|
+
state.setTarget(null);
|
|
158
|
+
autoScroll.stop();
|
|
159
|
+
},
|
|
160
|
+
onDropActivate (e) {
|
|
161
|
+
var _state_target, _state_target1;
|
|
162
|
+
if (((_state_target = state.target) === null || _state_target === void 0 ? void 0 : _state_target.type) === "item" && ((_state_target1 = state.target) === null || _state_target1 === void 0 ? void 0 : _state_target1.dropPosition) === "on" && typeof props.onDropActivate === "function") props.onDropActivate({
|
|
163
|
+
type: "dropactivate",
|
|
164
|
+
x: e.x,
|
|
165
|
+
y: e.y,
|
|
166
|
+
target: state.target
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
onDrop (e) {
|
|
170
|
+
(0, $7252cd45fc48c07c$export$dac8db29d42db9a1)(ref);
|
|
171
|
+
if (state.target) onDrop(e, state.target);
|
|
172
|
+
// If there wasn't a collection being tracked as a dragged collection, then we are in a case where a non RSP drag is dropped on a
|
|
173
|
+
// RSP collection and thus we don't need to preserve the global DnD state for onDragEnd
|
|
174
|
+
let { draggingCollectionRef: draggingCollectionRef } = (0, $7252cd45fc48c07c$export$6ca6700462636d0b);
|
|
175
|
+
if (draggingCollectionRef == null) (0, $7252cd45fc48c07c$export$70936501603e6c57)();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
let droppingState = (0, $4ZR0C$useRef)(null);
|
|
179
|
+
let onDrop = (0, $4ZR0C$useCallback)((e, target)=>{
|
|
180
|
+
var _state_collection_getItem;
|
|
181
|
+
let { state: state } = localState;
|
|
182
|
+
// Focus the collection.
|
|
183
|
+
state.selectionManager.setFocused(true);
|
|
184
|
+
// Save some state of the collection/selection before the drop occurs so we can compare later.
|
|
185
|
+
let focusedKey = state.selectionManager.focusedKey;
|
|
186
|
+
// If parent key was dragged, we want to use it instead (i.e. focus row instead of cell after dropping)
|
|
187
|
+
if ((0, $7252cd45fc48c07c$export$6ca6700462636d0b).draggingKeys.has((_state_collection_getItem = state.collection.getItem(focusedKey)) === null || _state_collection_getItem === void 0 ? void 0 : _state_collection_getItem.parentKey)) {
|
|
188
|
+
focusedKey = state.collection.getItem(focusedKey).parentKey;
|
|
189
|
+
state.selectionManager.setFocusedKey(focusedKey);
|
|
190
|
+
}
|
|
191
|
+
droppingState.current = {
|
|
192
|
+
timeout: null,
|
|
193
|
+
focusedKey: focusedKey,
|
|
194
|
+
collection: state.collection,
|
|
195
|
+
selectedKeys: state.selectionManager.selectedKeys
|
|
196
|
+
};
|
|
197
|
+
let onDropFn = localState.props.onDrop || defaultOnDrop;
|
|
198
|
+
onDropFn({
|
|
199
|
+
type: "drop",
|
|
200
|
+
x: e.x,
|
|
201
|
+
y: e.y,
|
|
202
|
+
target: target,
|
|
203
|
+
items: e.items,
|
|
204
|
+
dropOperation: e.dropOperation
|
|
205
|
+
});
|
|
206
|
+
// Wait for a short time period after the onDrop is called to allow the data to be read asynchronously
|
|
207
|
+
// and for React to re-render. If an insert occurs during this time, it will be selected/focused below.
|
|
208
|
+
// If items are not "immediately" inserted by the onDrop handler, the application will need to handle
|
|
209
|
+
// selecting and focusing those items themselves.
|
|
210
|
+
droppingState.current.timeout = setTimeout(()=>{
|
|
211
|
+
// If focus didn't move already (e.g. due to an insert), and the user dropped on an item,
|
|
212
|
+
// focus that item and show the focus ring to give the user feedback that the drop occurred.
|
|
213
|
+
// Also show the focus ring if the focused key is not selected, e.g. in case of a reorder.
|
|
214
|
+
let { state: state } = localState;
|
|
215
|
+
if (target.type === "item" && target.dropPosition === "on" && state.collection.getItem(target.key) != null) {
|
|
216
|
+
state.selectionManager.setFocusedKey(target.key);
|
|
217
|
+
state.selectionManager.setFocused(true);
|
|
218
|
+
(0, $4ZR0C$setInteractionModality)("keyboard");
|
|
219
|
+
} else if (!state.selectionManager.isSelected(focusedKey)) (0, $4ZR0C$setInteractionModality)("keyboard");
|
|
220
|
+
droppingState.current = null;
|
|
221
|
+
}, 50);
|
|
222
|
+
}, [
|
|
223
|
+
localState,
|
|
224
|
+
defaultOnDrop
|
|
225
|
+
]);
|
|
226
|
+
// eslint-disable-next-line arrow-body-style
|
|
227
|
+
(0, $4ZR0C$useEffect)(()=>{
|
|
228
|
+
return ()=>{
|
|
229
|
+
if (droppingState.current) clearTimeout(droppingState.current.timeout);
|
|
230
|
+
};
|
|
231
|
+
}, []);
|
|
232
|
+
(0, $4ZR0C$useLayoutEffect)(()=>{
|
|
233
|
+
// If an insert occurs during a drop, we want to immediately select these items to give
|
|
234
|
+
// feedback to the user that a drop occurred. Only do this if the selection didn't change
|
|
235
|
+
// since the drop started so we don't override if the user or application did something.
|
|
236
|
+
if (droppingState.current && state.selectionManager.isFocused && state.collection.size > droppingState.current.collection.size && state.selectionManager.isSelectionEqual(droppingState.current.selectedKeys)) {
|
|
237
|
+
let newKeys = new Set();
|
|
238
|
+
for (let key of state.collection.getKeys())if (!droppingState.current.collection.getItem(key)) newKeys.add(key);
|
|
239
|
+
state.selectionManager.setSelectedKeys(newKeys);
|
|
240
|
+
// If the focused item didn't change since the drop occurred, also focus the first
|
|
241
|
+
// inserted item. If selection is disabled, then also show the focus ring so there
|
|
242
|
+
// is some indication that items were added.
|
|
243
|
+
if (state.selectionManager.focusedKey === droppingState.current.focusedKey) {
|
|
244
|
+
let first = newKeys.keys().next().value;
|
|
245
|
+
let item = state.collection.getItem(first);
|
|
246
|
+
// If this is a cell, focus the parent row.
|
|
247
|
+
if ((item === null || item === void 0 ? void 0 : item.type) === "cell") first = item.parentKey;
|
|
248
|
+
state.selectionManager.setFocusedKey(first);
|
|
249
|
+
if (state.selectionManager.selectionMode === "none") (0, $4ZR0C$setInteractionModality)("keyboard");
|
|
250
|
+
}
|
|
251
|
+
droppingState.current = null;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
let { direction: direction } = (0, $4ZR0C$useLocale)();
|
|
255
|
+
(0, $4ZR0C$useEffect)(()=>{
|
|
256
|
+
let getNextTarget = (target, wrap = true, horizontal = false)=>{
|
|
257
|
+
if (!target) return {
|
|
258
|
+
type: "root"
|
|
259
|
+
};
|
|
260
|
+
let { keyboardDelegate: keyboardDelegate } = localState.props;
|
|
261
|
+
let nextKey;
|
|
262
|
+
if ((target === null || target === void 0 ? void 0 : target.type) === "item") nextKey = horizontal ? keyboardDelegate.getKeyRightOf(target.key) : keyboardDelegate.getKeyBelow(target.key);
|
|
263
|
+
else nextKey = horizontal && direction === "rtl" ? keyboardDelegate.getLastKey() : keyboardDelegate.getFirstKey();
|
|
264
|
+
let dropPositions = horizontal && direction === "rtl" ? $4b52e4eff84e5217$var$DROP_POSITIONS_RTL : $4b52e4eff84e5217$var$DROP_POSITIONS;
|
|
265
|
+
let dropPosition = dropPositions[0];
|
|
266
|
+
if (target.type === "item") {
|
|
267
|
+
// If the the keyboard delegate returned the next key in the collection,
|
|
268
|
+
// first try the other positions in the current key. Otherwise (e.g. in a grid layout),
|
|
269
|
+
// jump to the same drop position in the new key.
|
|
270
|
+
let nextCollectionKey = horizontal && direction === "rtl" ? localState.state.collection.getKeyBefore(target.key) : localState.state.collection.getKeyAfter(target.key);
|
|
271
|
+
if (nextKey == null || nextKey === nextCollectionKey) {
|
|
272
|
+
let positionIndex = dropPositions.indexOf(target.dropPosition);
|
|
273
|
+
let nextDropPosition = dropPositions[positionIndex + 1];
|
|
274
|
+
if (positionIndex < dropPositions.length - 1 && !(nextDropPosition === dropPositions[2] && nextKey != null)) return {
|
|
275
|
+
type: "item",
|
|
276
|
+
key: target.key,
|
|
277
|
+
dropPosition: nextDropPosition
|
|
278
|
+
};
|
|
279
|
+
// If the last drop position was 'after', then 'before' on the next key is equivalent.
|
|
280
|
+
// Switch to 'on' instead.
|
|
281
|
+
if (target.dropPosition === dropPositions[2]) dropPosition = "on";
|
|
282
|
+
} else dropPosition = target.dropPosition;
|
|
283
|
+
}
|
|
284
|
+
if (nextKey == null) {
|
|
285
|
+
if (wrap) return {
|
|
286
|
+
type: "root"
|
|
287
|
+
};
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
type: "item",
|
|
292
|
+
key: nextKey,
|
|
293
|
+
dropPosition: dropPosition
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
let getPreviousTarget = (target, wrap = true, horizontal = false)=>{
|
|
297
|
+
let { keyboardDelegate: keyboardDelegate } = localState.props;
|
|
298
|
+
let nextKey;
|
|
299
|
+
if ((target === null || target === void 0 ? void 0 : target.type) === "item") nextKey = horizontal ? keyboardDelegate.getKeyLeftOf(target.key) : keyboardDelegate.getKeyAbove(target.key);
|
|
300
|
+
else nextKey = horizontal && direction === "rtl" ? keyboardDelegate.getFirstKey() : keyboardDelegate.getLastKey();
|
|
301
|
+
let dropPositions = horizontal && direction === "rtl" ? $4b52e4eff84e5217$var$DROP_POSITIONS_RTL : $4b52e4eff84e5217$var$DROP_POSITIONS;
|
|
302
|
+
let dropPosition = !target || target.type === "root" ? dropPositions[2] : "on";
|
|
303
|
+
if ((target === null || target === void 0 ? void 0 : target.type) === "item") {
|
|
304
|
+
// If the the keyboard delegate returned the previous key in the collection,
|
|
305
|
+
// first try the other positions in the current key. Otherwise (e.g. in a grid layout),
|
|
306
|
+
// jump to the same drop position in the new key.
|
|
307
|
+
let prevCollectionKey = horizontal && direction === "rtl" ? localState.state.collection.getKeyAfter(target.key) : localState.state.collection.getKeyBefore(target.key);
|
|
308
|
+
if (nextKey == null || nextKey === prevCollectionKey) {
|
|
309
|
+
let positionIndex = dropPositions.indexOf(target.dropPosition);
|
|
310
|
+
let nextDropPosition = dropPositions[positionIndex - 1];
|
|
311
|
+
if (positionIndex > 0 && nextDropPosition !== dropPositions[2]) return {
|
|
312
|
+
type: "item",
|
|
313
|
+
key: target.key,
|
|
314
|
+
dropPosition: nextDropPosition
|
|
315
|
+
};
|
|
316
|
+
// If the last drop position was 'before', then 'after' on the previous key is equivalent.
|
|
317
|
+
// Switch to 'on' instead.
|
|
318
|
+
if (target.dropPosition === dropPositions[0]) dropPosition = "on";
|
|
319
|
+
} else dropPosition = target.dropPosition;
|
|
320
|
+
}
|
|
321
|
+
if (nextKey == null) {
|
|
322
|
+
if (wrap) return {
|
|
323
|
+
type: "root"
|
|
324
|
+
};
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
type: "item",
|
|
329
|
+
key: nextKey,
|
|
330
|
+
dropPosition: dropPosition
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
let nextValidTarget = (target, types, allowedDropOperations, getNextTarget, wrap = true)=>{
|
|
334
|
+
let seenRoot = 0;
|
|
335
|
+
let operation;
|
|
336
|
+
let { draggingKeys: draggingKeys } = (0, $7252cd45fc48c07c$export$6ca6700462636d0b);
|
|
337
|
+
let isInternal = (0, $7252cd45fc48c07c$export$78bf638634500fa5)(ref);
|
|
338
|
+
do {
|
|
339
|
+
let nextTarget = getNextTarget(target, wrap);
|
|
340
|
+
if (!nextTarget) return null;
|
|
341
|
+
target = nextTarget;
|
|
342
|
+
operation = localState.state.getDropOperation({
|
|
343
|
+
target: nextTarget,
|
|
344
|
+
types: types,
|
|
345
|
+
allowedOperations: allowedDropOperations,
|
|
346
|
+
isInternal: isInternal,
|
|
347
|
+
draggingKeys: draggingKeys
|
|
348
|
+
});
|
|
349
|
+
if (target.type === "root") seenRoot++;
|
|
350
|
+
}while (operation === "cancel" && !localState.state.isDropTarget(target) && seenRoot < 2);
|
|
351
|
+
if (operation === "cancel") return null;
|
|
352
|
+
return target;
|
|
353
|
+
};
|
|
354
|
+
return $67560de7c78cb232$export$c28d9fb4a54e471a({
|
|
355
|
+
element: ref.current,
|
|
356
|
+
getDropOperation (types, allowedOperations) {
|
|
357
|
+
if (localState.state.target) {
|
|
358
|
+
let { draggingKeys: draggingKeys } = (0, $7252cd45fc48c07c$export$6ca6700462636d0b);
|
|
359
|
+
let isInternal = (0, $7252cd45fc48c07c$export$78bf638634500fa5)(ref);
|
|
360
|
+
return localState.state.getDropOperation({
|
|
361
|
+
target: localState.state.target,
|
|
362
|
+
types: types,
|
|
363
|
+
allowedOperations: allowedOperations,
|
|
364
|
+
isInternal: isInternal,
|
|
365
|
+
draggingKeys: draggingKeys
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
// Check if any of the targets accept the drop.
|
|
369
|
+
// TODO: should we have a faster way of doing this or e.g. for pagination?
|
|
370
|
+
let target = nextValidTarget(null, types, allowedOperations, getNextTarget);
|
|
371
|
+
return target ? "move" : "cancel";
|
|
372
|
+
},
|
|
373
|
+
onDropEnter (e, drag) {
|
|
374
|
+
let types = (0, $7252cd45fc48c07c$export$e1d41611756c6326)(drag.items);
|
|
375
|
+
let selectionManager = localState.state.selectionManager;
|
|
376
|
+
let target;
|
|
377
|
+
// Update the drop collection ref tracker for useDroppableItem's getDropOperation isInternal check
|
|
378
|
+
(0, $7252cd45fc48c07c$export$dac8db29d42db9a1)(ref);
|
|
379
|
+
// When entering the droppable collection for the first time, the default drop target
|
|
380
|
+
// is after the focused key.
|
|
381
|
+
let key = selectionManager.focusedKey;
|
|
382
|
+
let dropPosition = "after";
|
|
383
|
+
// If the focused key is a cell, get the parent item instead.
|
|
384
|
+
// For now, we assume that individual cells cannot be dropped on.
|
|
385
|
+
let item = localState.state.collection.getItem(key);
|
|
386
|
+
if ((item === null || item === void 0 ? void 0 : item.type) === "cell") key = item.parentKey;
|
|
387
|
+
// If the focused item is also selected, the default drop target is after the last selected item.
|
|
388
|
+
// But if the focused key is the first selected item, then default to before the first selected item.
|
|
389
|
+
// This is to make reordering lists slightly easier. If you select top down, we assume you want to
|
|
390
|
+
// move the items down. If you select bottom up, we assume you want to move the items up.
|
|
391
|
+
if (selectionManager.isSelected(key)) {
|
|
392
|
+
if (selectionManager.selectedKeys.size > 1 && selectionManager.firstSelectedKey === key) dropPosition = "before";
|
|
393
|
+
else key = selectionManager.lastSelectedKey;
|
|
394
|
+
}
|
|
395
|
+
if (key != null) {
|
|
396
|
+
target = {
|
|
397
|
+
type: "item",
|
|
398
|
+
key: key,
|
|
399
|
+
dropPosition: dropPosition
|
|
400
|
+
};
|
|
401
|
+
let { draggingKeys: draggingKeys } = (0, $7252cd45fc48c07c$export$6ca6700462636d0b);
|
|
402
|
+
let isInternal = (0, $7252cd45fc48c07c$export$78bf638634500fa5)(ref);
|
|
403
|
+
var _nextValidTarget;
|
|
404
|
+
// If the default target is not valid, find the next one that is.
|
|
405
|
+
if (localState.state.getDropOperation({
|
|
406
|
+
target: target,
|
|
407
|
+
types: types,
|
|
408
|
+
allowedOperations: drag.allowedDropOperations,
|
|
409
|
+
isInternal: isInternal,
|
|
410
|
+
draggingKeys: draggingKeys
|
|
411
|
+
}) === "cancel") target = (_nextValidTarget = nextValidTarget(target, types, drag.allowedDropOperations, getNextTarget, false)) !== null && _nextValidTarget !== void 0 ? _nextValidTarget : nextValidTarget(target, types, drag.allowedDropOperations, getPreviousTarget, false);
|
|
412
|
+
}
|
|
413
|
+
// If no focused key, then start from the root.
|
|
414
|
+
if (!target) target = nextValidTarget(null, types, drag.allowedDropOperations, getNextTarget);
|
|
415
|
+
localState.state.setTarget(target);
|
|
416
|
+
},
|
|
417
|
+
onDropExit () {
|
|
418
|
+
(0, $7252cd45fc48c07c$export$dac8db29d42db9a1)(undefined);
|
|
419
|
+
localState.state.setTarget(null);
|
|
420
|
+
},
|
|
421
|
+
onDropTargetEnter (target) {
|
|
422
|
+
localState.state.setTarget(target);
|
|
423
|
+
},
|
|
424
|
+
onDropActivate (e) {
|
|
425
|
+
var _localState_state_target, _localState_state_target1;
|
|
426
|
+
if (((_localState_state_target = localState.state.target) === null || _localState_state_target === void 0 ? void 0 : _localState_state_target.type) === "item" && ((_localState_state_target1 = localState.state.target) === null || _localState_state_target1 === void 0 ? void 0 : _localState_state_target1.dropPosition) === "on" && typeof localState.props.onDropActivate === "function") localState.props.onDropActivate({
|
|
427
|
+
type: "dropactivate",
|
|
428
|
+
x: e.x,
|
|
429
|
+
y: e.y,
|
|
430
|
+
target: localState.state.target
|
|
431
|
+
});
|
|
432
|
+
},
|
|
433
|
+
onDrop (e, target) {
|
|
434
|
+
(0, $7252cd45fc48c07c$export$dac8db29d42db9a1)(ref);
|
|
435
|
+
if (localState.state.target) onDrop(e, target || localState.state.target);
|
|
436
|
+
},
|
|
437
|
+
onKeyDown (e, drag) {
|
|
438
|
+
let { keyboardDelegate: keyboardDelegate } = localState.props;
|
|
439
|
+
let types = (0, $7252cd45fc48c07c$export$e1d41611756c6326)(drag.items);
|
|
440
|
+
switch(e.key){
|
|
441
|
+
case "ArrowDown":
|
|
442
|
+
if (keyboardDelegate.getKeyBelow) {
|
|
443
|
+
let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, getNextTarget);
|
|
444
|
+
localState.state.setTarget(target);
|
|
445
|
+
}
|
|
446
|
+
break;
|
|
447
|
+
case "ArrowUp":
|
|
448
|
+
if (keyboardDelegate.getKeyAbove) {
|
|
449
|
+
let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, getPreviousTarget);
|
|
450
|
+
localState.state.setTarget(target);
|
|
451
|
+
}
|
|
452
|
+
break;
|
|
453
|
+
case "ArrowLeft":
|
|
454
|
+
if (keyboardDelegate.getKeyLeftOf) {
|
|
455
|
+
let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getPreviousTarget(target, wrap, true));
|
|
456
|
+
localState.state.setTarget(target);
|
|
457
|
+
}
|
|
458
|
+
break;
|
|
459
|
+
case "ArrowRight":
|
|
460
|
+
if (keyboardDelegate.getKeyRightOf) {
|
|
461
|
+
let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, true));
|
|
462
|
+
localState.state.setTarget(target);
|
|
463
|
+
}
|
|
464
|
+
break;
|
|
465
|
+
case "Home":
|
|
466
|
+
if (keyboardDelegate.getFirstKey) {
|
|
467
|
+
let target = nextValidTarget(null, types, drag.allowedDropOperations, getNextTarget);
|
|
468
|
+
localState.state.setTarget(target);
|
|
469
|
+
}
|
|
470
|
+
break;
|
|
471
|
+
case "End":
|
|
472
|
+
if (keyboardDelegate.getLastKey) {
|
|
473
|
+
let target = nextValidTarget(null, types, drag.allowedDropOperations, getPreviousTarget);
|
|
474
|
+
localState.state.setTarget(target);
|
|
475
|
+
}
|
|
476
|
+
break;
|
|
477
|
+
case "PageDown":
|
|
478
|
+
if (keyboardDelegate.getKeyPageBelow) {
|
|
479
|
+
let target = localState.state.target;
|
|
480
|
+
if (!target) target = nextValidTarget(null, types, drag.allowedDropOperations, getNextTarget);
|
|
481
|
+
else {
|
|
482
|
+
// If on the root, go to the item a page below the top. Otherwise a page below the current item.
|
|
483
|
+
let nextKey = keyboardDelegate.getKeyPageBelow(target.type === "item" ? target.key : keyboardDelegate.getFirstKey());
|
|
484
|
+
let dropPosition = target.type === "item" ? target.dropPosition : "after";
|
|
485
|
+
// If there is no next key, or we are starting on the last key, jump to the last possible position.
|
|
486
|
+
if (nextKey == null || target.type === "item" && target.key === keyboardDelegate.getLastKey()) {
|
|
487
|
+
nextKey = keyboardDelegate.getLastKey();
|
|
488
|
+
dropPosition = "after";
|
|
489
|
+
}
|
|
490
|
+
target = {
|
|
491
|
+
type: "item",
|
|
492
|
+
key: nextKey,
|
|
493
|
+
dropPosition: dropPosition
|
|
494
|
+
};
|
|
495
|
+
// If the target does not accept the drop, find the next valid target.
|
|
496
|
+
// If no next valid target, find the previous valid target.
|
|
497
|
+
let { draggingCollectionRef: draggingCollectionRef, draggingKeys: draggingKeys } = (0, $7252cd45fc48c07c$export$6ca6700462636d0b);
|
|
498
|
+
let isInternal = (draggingCollectionRef === null || draggingCollectionRef === void 0 ? void 0 : draggingCollectionRef.current) === (ref === null || ref === void 0 ? void 0 : ref.current);
|
|
499
|
+
let operation = localState.state.getDropOperation({
|
|
500
|
+
target: target,
|
|
501
|
+
types: types,
|
|
502
|
+
allowedOperations: drag.allowedDropOperations,
|
|
503
|
+
isInternal: isInternal,
|
|
504
|
+
draggingKeys: draggingKeys
|
|
505
|
+
});
|
|
506
|
+
var _nextValidTarget;
|
|
507
|
+
if (operation === "cancel") target = (_nextValidTarget = nextValidTarget(target, types, drag.allowedDropOperations, getNextTarget, false)) !== null && _nextValidTarget !== void 0 ? _nextValidTarget : nextValidTarget(target, types, drag.allowedDropOperations, getPreviousTarget, false);
|
|
508
|
+
}
|
|
509
|
+
localState.state.setTarget(target !== null && target !== void 0 ? target : localState.state.target);
|
|
510
|
+
}
|
|
511
|
+
break;
|
|
512
|
+
case "PageUp":
|
|
513
|
+
{
|
|
514
|
+
if (!keyboardDelegate.getKeyPageAbove) break;
|
|
515
|
+
let target = localState.state.target;
|
|
516
|
+
if (!target) target = nextValidTarget(null, types, drag.allowedDropOperations, getPreviousTarget);
|
|
517
|
+
else if (target.type === "item") {
|
|
518
|
+
// If at the top already, switch to the root. Otherwise navigate a page up.
|
|
519
|
+
if (target.key === keyboardDelegate.getFirstKey()) target = {
|
|
520
|
+
type: "root"
|
|
521
|
+
};
|
|
522
|
+
else {
|
|
523
|
+
let nextKey = keyboardDelegate.getKeyPageAbove(target.key);
|
|
524
|
+
let dropPosition = target.dropPosition;
|
|
525
|
+
if (nextKey == null) {
|
|
526
|
+
nextKey = keyboardDelegate.getFirstKey();
|
|
527
|
+
dropPosition = "before";
|
|
528
|
+
}
|
|
529
|
+
target = {
|
|
530
|
+
type: "item",
|
|
531
|
+
key: nextKey,
|
|
532
|
+
dropPosition: dropPosition
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
// If the target does not accept the drop, find the previous valid target.
|
|
536
|
+
// If no next valid target, find the next valid target.
|
|
537
|
+
let { draggingKeys: draggingKeys } = (0, $7252cd45fc48c07c$export$6ca6700462636d0b);
|
|
538
|
+
let isInternal = (0, $7252cd45fc48c07c$export$78bf638634500fa5)(ref);
|
|
539
|
+
let operation = localState.state.getDropOperation({
|
|
540
|
+
target: target,
|
|
541
|
+
types: types,
|
|
542
|
+
allowedOperations: drag.allowedDropOperations,
|
|
543
|
+
isInternal: isInternal,
|
|
544
|
+
draggingKeys: draggingKeys
|
|
545
|
+
});
|
|
546
|
+
var _nextValidTarget1;
|
|
547
|
+
if (operation === "cancel") target = (_nextValidTarget1 = nextValidTarget(target, types, drag.allowedDropOperations, getPreviousTarget, false)) !== null && _nextValidTarget1 !== void 0 ? _nextValidTarget1 : nextValidTarget(target, types, drag.allowedDropOperations, getNextTarget, false);
|
|
548
|
+
}
|
|
549
|
+
localState.state.setTarget(target !== null && target !== void 0 ? target : localState.state.target);
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
}, [
|
|
556
|
+
localState,
|
|
557
|
+
ref,
|
|
558
|
+
onDrop,
|
|
559
|
+
direction
|
|
560
|
+
]);
|
|
561
|
+
let id = (0, $4ZR0C$useId)();
|
|
562
|
+
(0, $7252cd45fc48c07c$export$dfdf5deeaf27473f).set(state, {
|
|
563
|
+
id: id,
|
|
564
|
+
ref: ref
|
|
565
|
+
});
|
|
566
|
+
return {
|
|
567
|
+
collectionProps: (0, $4ZR0C$mergeProps)(dropProps, {
|
|
568
|
+
id: id,
|
|
569
|
+
// Remove description from collection element. If dropping on the entire collection,
|
|
570
|
+
// there should be a drop indicator that has this description, so no need to double announce.
|
|
571
|
+
"aria-describedby": null
|
|
572
|
+
})
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
export {$4b52e4eff84e5217$export$f4e2f423c21f7b04 as useDroppableCollection};
|
|
578
|
+
//# sourceMappingURL=useDroppableCollection.module.js.map
|