@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,123 @@
|
|
|
1
|
+
import {clearGlobalDnDState as $7252cd45fc48c07c$export$70936501603e6c57, isInternalDropOperation as $7252cd45fc48c07c$export$78bf638634500fa5, setDraggingKeys as $7252cd45fc48c07c$export$72cb63bdda528276, useDragModality as $7252cd45fc48c07c$export$49bac5d6d4b352ea} from "./utils.mjs";
|
|
2
|
+
import $91Fvt$intlStringsmodulejs from "./intlStrings.mjs";
|
|
3
|
+
import {useDrag as $8253ed7ece74b463$export$7941f8aafa4b6021} from "./useDrag.mjs";
|
|
4
|
+
import {useDescription as $91Fvt$useDescription} from "@react-aria/utils";
|
|
5
|
+
import {useLocalizedStringFormatter as $91Fvt$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function $parcel$interopDefault(a) {
|
|
9
|
+
return a && a.__esModule ? a.default : a;
|
|
10
|
+
}
|
|
11
|
+
/*
|
|
12
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
13
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
+
* governing permissions and limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const $fd98cf7cbf233429$var$MESSAGES = {
|
|
27
|
+
keyboard: {
|
|
28
|
+
selected: "dragSelectedKeyboard",
|
|
29
|
+
notSelected: "dragDescriptionKeyboard"
|
|
30
|
+
},
|
|
31
|
+
touch: {
|
|
32
|
+
selected: "dragSelectedLongPress",
|
|
33
|
+
notSelected: "dragDescriptionLongPress"
|
|
34
|
+
},
|
|
35
|
+
virtual: {
|
|
36
|
+
selected: "dragDescriptionVirtual",
|
|
37
|
+
notSelected: "dragDescriptionVirtual"
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function $fd98cf7cbf233429$export$b35afafff42da2d9(props, state) {
|
|
41
|
+
let stringFormatter = (0, $91Fvt$useLocalizedStringFormatter)((0, ($parcel$interopDefault($91Fvt$intlStringsmodulejs))), "@react-aria/dnd");
|
|
42
|
+
let isDisabled = state.isDisabled || state.selectionManager.isDisabled(props.key);
|
|
43
|
+
let { dragProps: dragProps, dragButtonProps: dragButtonProps } = (0, $8253ed7ece74b463$export$7941f8aafa4b6021)({
|
|
44
|
+
getItems () {
|
|
45
|
+
return state.getItems(props.key);
|
|
46
|
+
},
|
|
47
|
+
preview: state.preview,
|
|
48
|
+
getAllowedDropOperations: state.getAllowedDropOperations,
|
|
49
|
+
hasDragButton: props.hasDragButton,
|
|
50
|
+
onDragStart (e) {
|
|
51
|
+
state.startDrag(props.key, e);
|
|
52
|
+
// Track draggingKeys for useDroppableCollection's default onDrop handler and useDroppableCollectionState's default getDropOperation
|
|
53
|
+
(0, $7252cd45fc48c07c$export$72cb63bdda528276)(state.draggingKeys);
|
|
54
|
+
},
|
|
55
|
+
onDragMove (e) {
|
|
56
|
+
state.moveDrag(e);
|
|
57
|
+
},
|
|
58
|
+
onDragEnd (e) {
|
|
59
|
+
let { dropOperation: dropOperation } = e;
|
|
60
|
+
let isInternal = dropOperation === "cancel" ? false : (0, $7252cd45fc48c07c$export$78bf638634500fa5)();
|
|
61
|
+
state.endDrag({
|
|
62
|
+
...e,
|
|
63
|
+
keys: state.draggingKeys,
|
|
64
|
+
isInternal: isInternal
|
|
65
|
+
});
|
|
66
|
+
(0, $7252cd45fc48c07c$export$70936501603e6c57)();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
let item = state.collection.getItem(props.key);
|
|
70
|
+
let numKeysForDrag = state.getKeysForDrag(props.key).size;
|
|
71
|
+
let isSelected = numKeysForDrag > 1 && state.selectionManager.isSelected(props.key);
|
|
72
|
+
let dragButtonLabel;
|
|
73
|
+
let description;
|
|
74
|
+
// Override description to include selected item count.
|
|
75
|
+
let modality = (0, $7252cd45fc48c07c$export$49bac5d6d4b352ea)();
|
|
76
|
+
if (!props.hasDragButton && state.selectionManager.selectionMode !== "none") {
|
|
77
|
+
let msg = $fd98cf7cbf233429$var$MESSAGES[modality][isSelected ? "selected" : "notSelected"];
|
|
78
|
+
if (props.hasAction && modality === "keyboard") msg += "Alt";
|
|
79
|
+
if (isSelected) description = stringFormatter.format(msg, {
|
|
80
|
+
count: numKeysForDrag
|
|
81
|
+
});
|
|
82
|
+
else description = stringFormatter.format(msg);
|
|
83
|
+
// Remove the onClick handler from useDrag. Long pressing will be required on touch devices,
|
|
84
|
+
// and NVDA/JAWS are always in forms mode within collection components.
|
|
85
|
+
delete dragProps.onClick;
|
|
86
|
+
} else if (isSelected) dragButtonLabel = stringFormatter.format("dragSelectedItems", {
|
|
87
|
+
count: numKeysForDrag
|
|
88
|
+
});
|
|
89
|
+
else {
|
|
90
|
+
var _state_collection_getTextValue, _state_collection;
|
|
91
|
+
var _state_collection_getTextValue1, _ref;
|
|
92
|
+
let itemText = (_ref = (_state_collection_getTextValue1 = (_state_collection_getTextValue = (_state_collection = state.collection).getTextValue) === null || _state_collection_getTextValue === void 0 ? void 0 : _state_collection_getTextValue.call(_state_collection, props.key)) !== null && _state_collection_getTextValue1 !== void 0 ? _state_collection_getTextValue1 : item === null || item === void 0 ? void 0 : item.textValue) !== null && _ref !== void 0 ? _ref : "";
|
|
93
|
+
dragButtonLabel = stringFormatter.format("dragItem", {
|
|
94
|
+
itemText: itemText
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
let descriptionProps = (0, $91Fvt$useDescription)(description);
|
|
98
|
+
if (description) Object.assign(dragProps, descriptionProps);
|
|
99
|
+
if (!props.hasDragButton && props.hasAction) {
|
|
100
|
+
let { onKeyDownCapture: onKeyDownCapture, onKeyUpCapture: onKeyUpCapture } = dragProps;
|
|
101
|
+
if (modality === "touch") // Remove long press description if an action is present, because in that case long pressing selects the item.
|
|
102
|
+
delete dragProps["aria-describedby"];
|
|
103
|
+
// Require Alt key if there is a conflicting action.
|
|
104
|
+
dragProps.onKeyDownCapture = (e)=>{
|
|
105
|
+
if (e.altKey) onKeyDownCapture === null || onKeyDownCapture === void 0 ? void 0 : onKeyDownCapture(e);
|
|
106
|
+
};
|
|
107
|
+
dragProps.onKeyUpCapture = (e)=>{
|
|
108
|
+
if (e.altKey) onKeyUpCapture === null || onKeyUpCapture === void 0 ? void 0 : onKeyUpCapture(e);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
dragProps: isDisabled ? {} : dragProps,
|
|
113
|
+
dragButtonProps: {
|
|
114
|
+
...dragButtonProps,
|
|
115
|
+
isDisabled: isDisabled,
|
|
116
|
+
"aria-label": dragButtonLabel
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
export {$fd98cf7cbf233429$export$b35afafff42da2d9 as useDraggableItem};
|
|
123
|
+
//# sourceMappingURL=useDraggableItem.mjs.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {clearGlobalDnDState as $7252cd45fc48c07c$export$70936501603e6c57, isInternalDropOperation as $7252cd45fc48c07c$export$78bf638634500fa5, setDraggingKeys as $7252cd45fc48c07c$export$72cb63bdda528276, useDragModality as $7252cd45fc48c07c$export$49bac5d6d4b352ea} from "./utils.module.js";
|
|
2
|
+
import $91Fvt$intlStringsmodulejs from "./intlStrings.module.js";
|
|
3
|
+
import {useDrag as $8253ed7ece74b463$export$7941f8aafa4b6021} from "./useDrag.module.js";
|
|
4
|
+
import {useDescription as $91Fvt$useDescription} from "@react-aria/utils";
|
|
5
|
+
import {useLocalizedStringFormatter as $91Fvt$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function $parcel$interopDefault(a) {
|
|
9
|
+
return a && a.__esModule ? a.default : a;
|
|
10
|
+
}
|
|
11
|
+
/*
|
|
12
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
13
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
+
* governing permissions and limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const $fd98cf7cbf233429$var$MESSAGES = {
|
|
27
|
+
keyboard: {
|
|
28
|
+
selected: "dragSelectedKeyboard",
|
|
29
|
+
notSelected: "dragDescriptionKeyboard"
|
|
30
|
+
},
|
|
31
|
+
touch: {
|
|
32
|
+
selected: "dragSelectedLongPress",
|
|
33
|
+
notSelected: "dragDescriptionLongPress"
|
|
34
|
+
},
|
|
35
|
+
virtual: {
|
|
36
|
+
selected: "dragDescriptionVirtual",
|
|
37
|
+
notSelected: "dragDescriptionVirtual"
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function $fd98cf7cbf233429$export$b35afafff42da2d9(props, state) {
|
|
41
|
+
let stringFormatter = (0, $91Fvt$useLocalizedStringFormatter)((0, ($parcel$interopDefault($91Fvt$intlStringsmodulejs))), "@react-aria/dnd");
|
|
42
|
+
let isDisabled = state.isDisabled || state.selectionManager.isDisabled(props.key);
|
|
43
|
+
let { dragProps: dragProps, dragButtonProps: dragButtonProps } = (0, $8253ed7ece74b463$export$7941f8aafa4b6021)({
|
|
44
|
+
getItems () {
|
|
45
|
+
return state.getItems(props.key);
|
|
46
|
+
},
|
|
47
|
+
preview: state.preview,
|
|
48
|
+
getAllowedDropOperations: state.getAllowedDropOperations,
|
|
49
|
+
hasDragButton: props.hasDragButton,
|
|
50
|
+
onDragStart (e) {
|
|
51
|
+
state.startDrag(props.key, e);
|
|
52
|
+
// Track draggingKeys for useDroppableCollection's default onDrop handler and useDroppableCollectionState's default getDropOperation
|
|
53
|
+
(0, $7252cd45fc48c07c$export$72cb63bdda528276)(state.draggingKeys);
|
|
54
|
+
},
|
|
55
|
+
onDragMove (e) {
|
|
56
|
+
state.moveDrag(e);
|
|
57
|
+
},
|
|
58
|
+
onDragEnd (e) {
|
|
59
|
+
let { dropOperation: dropOperation } = e;
|
|
60
|
+
let isInternal = dropOperation === "cancel" ? false : (0, $7252cd45fc48c07c$export$78bf638634500fa5)();
|
|
61
|
+
state.endDrag({
|
|
62
|
+
...e,
|
|
63
|
+
keys: state.draggingKeys,
|
|
64
|
+
isInternal: isInternal
|
|
65
|
+
});
|
|
66
|
+
(0, $7252cd45fc48c07c$export$70936501603e6c57)();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
let item = state.collection.getItem(props.key);
|
|
70
|
+
let numKeysForDrag = state.getKeysForDrag(props.key).size;
|
|
71
|
+
let isSelected = numKeysForDrag > 1 && state.selectionManager.isSelected(props.key);
|
|
72
|
+
let dragButtonLabel;
|
|
73
|
+
let description;
|
|
74
|
+
// Override description to include selected item count.
|
|
75
|
+
let modality = (0, $7252cd45fc48c07c$export$49bac5d6d4b352ea)();
|
|
76
|
+
if (!props.hasDragButton && state.selectionManager.selectionMode !== "none") {
|
|
77
|
+
let msg = $fd98cf7cbf233429$var$MESSAGES[modality][isSelected ? "selected" : "notSelected"];
|
|
78
|
+
if (props.hasAction && modality === "keyboard") msg += "Alt";
|
|
79
|
+
if (isSelected) description = stringFormatter.format(msg, {
|
|
80
|
+
count: numKeysForDrag
|
|
81
|
+
});
|
|
82
|
+
else description = stringFormatter.format(msg);
|
|
83
|
+
// Remove the onClick handler from useDrag. Long pressing will be required on touch devices,
|
|
84
|
+
// and NVDA/JAWS are always in forms mode within collection components.
|
|
85
|
+
delete dragProps.onClick;
|
|
86
|
+
} else if (isSelected) dragButtonLabel = stringFormatter.format("dragSelectedItems", {
|
|
87
|
+
count: numKeysForDrag
|
|
88
|
+
});
|
|
89
|
+
else {
|
|
90
|
+
var _state_collection_getTextValue, _state_collection;
|
|
91
|
+
var _state_collection_getTextValue1, _ref;
|
|
92
|
+
let itemText = (_ref = (_state_collection_getTextValue1 = (_state_collection_getTextValue = (_state_collection = state.collection).getTextValue) === null || _state_collection_getTextValue === void 0 ? void 0 : _state_collection_getTextValue.call(_state_collection, props.key)) !== null && _state_collection_getTextValue1 !== void 0 ? _state_collection_getTextValue1 : item === null || item === void 0 ? void 0 : item.textValue) !== null && _ref !== void 0 ? _ref : "";
|
|
93
|
+
dragButtonLabel = stringFormatter.format("dragItem", {
|
|
94
|
+
itemText: itemText
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
let descriptionProps = (0, $91Fvt$useDescription)(description);
|
|
98
|
+
if (description) Object.assign(dragProps, descriptionProps);
|
|
99
|
+
if (!props.hasDragButton && props.hasAction) {
|
|
100
|
+
let { onKeyDownCapture: onKeyDownCapture, onKeyUpCapture: onKeyUpCapture } = dragProps;
|
|
101
|
+
if (modality === "touch") // Remove long press description if an action is present, because in that case long pressing selects the item.
|
|
102
|
+
delete dragProps["aria-describedby"];
|
|
103
|
+
// Require Alt key if there is a conflicting action.
|
|
104
|
+
dragProps.onKeyDownCapture = (e)=>{
|
|
105
|
+
if (e.altKey) onKeyDownCapture === null || onKeyDownCapture === void 0 ? void 0 : onKeyDownCapture(e);
|
|
106
|
+
};
|
|
107
|
+
dragProps.onKeyUpCapture = (e)=>{
|
|
108
|
+
if (e.altKey) onKeyUpCapture === null || onKeyUpCapture === void 0 ? void 0 : onKeyUpCapture(e);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
dragProps: isDisabled ? {} : dragProps,
|
|
113
|
+
dragButtonProps: {
|
|
114
|
+
...dragButtonProps,
|
|
115
|
+
isDisabled: isDisabled,
|
|
116
|
+
"aria-label": dragButtonLabel
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
export {$fd98cf7cbf233429$export$b35afafff42da2d9 as useDraggableItem};
|
|
123
|
+
//# sourceMappingURL=useDraggableItem.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAqCD,MAAM,iCA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,cAAc;QAChB;IACF;AACF","sources":["packages/@react-aria/dnd/src/useDraggableItem.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {clearGlobalDnDState, isInternalDropOperation, setDraggingKeys, useDragModality} from './utils';\nimport {DraggableCollectionState} from '@react-stately/dnd';\nimport {HTMLAttributes} from 'react';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {Key} from '@react-types/shared';\nimport {useDescription} from '@react-aria/utils';\nimport {useDrag} from './useDrag';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface DraggableItemProps {\n /** The key of the draggable item within the collection. */\n key: Key,\n /**\n * Whether the item has an explicit focusable drag affordance to initiate accessible drag and drop mode.\n * If true, the dragProps will omit these event handlers, and they will be applied to dragButtonProps instead.\n */\n hasDragButton?: boolean,\n /**\n * Whether the item has a primary action (e.g. Enter key or long press) that would\n * conflict with initiating accessible drag and drop. If true, the Alt key must be held to\n * start dragging with a keyboard, and long press is disabled until selection mode is entered.\n * This should be passed from the associated collection item hook (e.g. useOption, useGridListItem, etc.).\n */\n hasAction?: boolean\n}\n\nexport interface DraggableItemResult {\n /** Props for the draggable item. */\n dragProps: HTMLAttributes<HTMLElement>,\n /** Props for the explicit drag button affordance, if any. */\n dragButtonProps: AriaButtonProps\n}\n\nconst MESSAGES = {\n keyboard: {\n selected: 'dragSelectedKeyboard',\n notSelected: 'dragDescriptionKeyboard'\n },\n touch: {\n selected: 'dragSelectedLongPress',\n notSelected: 'dragDescriptionLongPress'\n },\n virtual: {\n selected: 'dragDescriptionVirtual',\n notSelected: 'dragDescriptionVirtual'\n }\n};\n\n/**\n * Handles drag interactions for an item within a draggable collection.\n */\nexport function useDraggableItem(props: DraggableItemProps, state: DraggableCollectionState): DraggableItemResult {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let isDisabled = state.isDisabled || state.selectionManager.isDisabled(props.key);\n let {dragProps, dragButtonProps} = useDrag({\n getItems() {\n return state.getItems(props.key);\n },\n preview: state.preview,\n getAllowedDropOperations: state.getAllowedDropOperations,\n hasDragButton: props.hasDragButton,\n onDragStart(e) {\n state.startDrag(props.key, e);\n // Track draggingKeys for useDroppableCollection's default onDrop handler and useDroppableCollectionState's default getDropOperation\n setDraggingKeys(state.draggingKeys);\n },\n onDragMove(e) {\n state.moveDrag(e);\n },\n onDragEnd(e) {\n let {dropOperation} = e;\n let isInternal = dropOperation === 'cancel' ? false : isInternalDropOperation();\n state.endDrag({...e, keys: state.draggingKeys, isInternal});\n clearGlobalDnDState();\n }\n });\n\n let item = state.collection.getItem(props.key);\n let numKeysForDrag = state.getKeysForDrag(props.key).size;\n let isSelected = numKeysForDrag > 1 && state.selectionManager.isSelected(props.key);\n let dragButtonLabel: string | undefined;\n let description: string | undefined;\n\n // Override description to include selected item count.\n let modality = useDragModality();\n if (!props.hasDragButton && state.selectionManager.selectionMode !== 'none') {\n let msg = MESSAGES[modality][isSelected ? 'selected' : 'notSelected'];\n if (props.hasAction && modality === 'keyboard') {\n msg += 'Alt';\n }\n\n if (isSelected) {\n description = stringFormatter.format(msg, {count: numKeysForDrag});\n } else {\n description = stringFormatter.format(msg);\n }\n\n // Remove the onClick handler from useDrag. Long pressing will be required on touch devices,\n // and NVDA/JAWS are always in forms mode within collection components.\n delete dragProps.onClick;\n } else {\n if (isSelected) {\n dragButtonLabel = stringFormatter.format('dragSelectedItems', {count: numKeysForDrag});\n } else {\n let itemText = state.collection.getTextValue?.(props.key) ?? item?.textValue ?? '';\n dragButtonLabel = stringFormatter.format('dragItem', {itemText});\n }\n }\n\n let descriptionProps = useDescription(description);\n if (description) {\n Object.assign(dragProps, descriptionProps);\n }\n\n if (!props.hasDragButton && props.hasAction) {\n let {onKeyDownCapture, onKeyUpCapture} = dragProps;\n if (modality === 'touch') {\n // Remove long press description if an action is present, because in that case long pressing selects the item.\n delete dragProps['aria-describedby'];\n }\n\n // Require Alt key if there is a conflicting action.\n dragProps.onKeyDownCapture = e => {\n if (e.altKey) {\n onKeyDownCapture?.(e);\n }\n };\n\n dragProps.onKeyUpCapture = e => {\n if (e.altKey) {\n onKeyUpCapture?.(e);\n }\n };\n }\n\n return {\n dragProps: isDisabled ? {} : dragProps,\n dragButtonProps: {\n ...dragButtonProps,\n isDisabled,\n 'aria-label': dragButtonLabel\n }\n };\n}\n"],"names":[],"version":3,"file":"useDraggableItem.module.js.map"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
var $28e10663603f5ea1$exports = require("./DragManager.main.js");
|
|
2
|
+
var $4620ae0dc40f0031$exports = require("./utils.main.js");
|
|
3
|
+
var $76b1e110a27b1ccd$exports = require("./constants.main.js");
|
|
4
|
+
var $419982e205c8e8dc$exports = require("./useVirtualDrop.main.js");
|
|
5
|
+
var $AO99w$react = require("react");
|
|
6
|
+
var $AO99w$reactariautils = require("@react-aria/utils");
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function $parcel$export(e, n, v, s) {
|
|
10
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
$parcel$export(module.exports, "useDrop", () => $1ca228bc9257ca16$export$ccdee5eaf73cf661);
|
|
14
|
+
/*
|
|
15
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
16
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
17
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
18
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
+
*
|
|
20
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
21
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
22
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
23
|
+
* governing permissions and limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const $1ca228bc9257ca16$var$DROP_ACTIVATE_TIMEOUT = 800;
|
|
31
|
+
function $1ca228bc9257ca16$export$ccdee5eaf73cf661(options) {
|
|
32
|
+
let { hasDropButton: hasDropButton, isDisabled: isDisabled } = options;
|
|
33
|
+
let [isDropTarget, setDropTarget] = (0, $AO99w$react.useState)(false);
|
|
34
|
+
let state = (0, $AO99w$react.useRef)({
|
|
35
|
+
x: 0,
|
|
36
|
+
y: 0,
|
|
37
|
+
dragOverElements: new Set(),
|
|
38
|
+
dropEffect: "none",
|
|
39
|
+
allowedOperations: (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).all,
|
|
40
|
+
dropActivateTimer: null
|
|
41
|
+
}).current;
|
|
42
|
+
let fireDropEnter = (e)=>{
|
|
43
|
+
setDropTarget(true);
|
|
44
|
+
if (typeof options.onDropEnter === "function") {
|
|
45
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
46
|
+
options.onDropEnter({
|
|
47
|
+
type: "dropenter",
|
|
48
|
+
x: e.clientX - rect.x,
|
|
49
|
+
y: e.clientY - rect.y
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
let fireDropExit = (e)=>{
|
|
54
|
+
setDropTarget(false);
|
|
55
|
+
if (typeof options.onDropExit === "function") {
|
|
56
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
57
|
+
options.onDropExit({
|
|
58
|
+
type: "dropexit",
|
|
59
|
+
x: e.clientX - rect.x,
|
|
60
|
+
y: e.clientY - rect.y
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
let onDragOver = (e)=>{
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
let allowedOperations = $1ca228bc9257ca16$var$getAllowedOperations(e);
|
|
68
|
+
if (e.clientX === state.x && e.clientY === state.y && allowedOperations === state.allowedOperations) {
|
|
69
|
+
e.dataTransfer.dropEffect = state.dropEffect;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
state.x = e.clientX;
|
|
73
|
+
state.y = e.clientY;
|
|
74
|
+
let prevDropEffect = state.dropEffect;
|
|
75
|
+
// Update drop effect if allowed drop operations changed (e.g. user pressed modifier key).
|
|
76
|
+
if (allowedOperations !== state.allowedOperations) {
|
|
77
|
+
let allowedOps = $1ca228bc9257ca16$var$allowedOperationsToArray(allowedOperations);
|
|
78
|
+
let dropOperation = allowedOps[0];
|
|
79
|
+
if (typeof options.getDropOperation === "function") {
|
|
80
|
+
let types = new (0, $4620ae0dc40f0031$exports.DragTypes)(e.dataTransfer);
|
|
81
|
+
dropOperation = $1ca228bc9257ca16$var$getDropOperation(allowedOperations, options.getDropOperation(types, allowedOps));
|
|
82
|
+
}
|
|
83
|
+
state.dropEffect = (0, $76b1e110a27b1ccd$exports.DROP_OPERATION_TO_DROP_EFFECT)[dropOperation] || "none";
|
|
84
|
+
}
|
|
85
|
+
if (typeof options.getDropOperationForPoint === "function") {
|
|
86
|
+
let types = new (0, $4620ae0dc40f0031$exports.DragTypes)(e.dataTransfer);
|
|
87
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
88
|
+
let dropOperation = $1ca228bc9257ca16$var$getDropOperation(allowedOperations, options.getDropOperationForPoint(types, $1ca228bc9257ca16$var$allowedOperationsToArray(allowedOperations), state.x - rect.x, state.y - rect.y));
|
|
89
|
+
state.dropEffect = (0, $76b1e110a27b1ccd$exports.DROP_OPERATION_TO_DROP_EFFECT)[dropOperation] || "none";
|
|
90
|
+
}
|
|
91
|
+
state.allowedOperations = allowedOperations;
|
|
92
|
+
e.dataTransfer.dropEffect = state.dropEffect;
|
|
93
|
+
// If the drop operation changes, update state and fire events appropriately.
|
|
94
|
+
if (state.dropEffect === "none" && prevDropEffect !== "none") fireDropExit(e);
|
|
95
|
+
else if (state.dropEffect !== "none" && prevDropEffect === "none") fireDropEnter(e);
|
|
96
|
+
if (typeof options.onDropMove === "function" && state.dropEffect !== "none") {
|
|
97
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
98
|
+
options.onDropMove({
|
|
99
|
+
type: "dropmove",
|
|
100
|
+
x: state.x - rect.x,
|
|
101
|
+
y: state.y - rect.y
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
clearTimeout(state.dropActivateTimer);
|
|
105
|
+
if (typeof options.onDropActivate === "function" && state.dropEffect !== "none") {
|
|
106
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
107
|
+
state.dropActivateTimer = setTimeout(()=>{
|
|
108
|
+
options.onDropActivate({
|
|
109
|
+
type: "dropactivate",
|
|
110
|
+
x: state.x - rect.x,
|
|
111
|
+
y: state.y - rect.y
|
|
112
|
+
});
|
|
113
|
+
}, $1ca228bc9257ca16$var$DROP_ACTIVATE_TIMEOUT);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
let onDragEnter = (e)=>{
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
e.stopPropagation();
|
|
119
|
+
state.dragOverElements.add(e.target);
|
|
120
|
+
if (state.dragOverElements.size > 1) return;
|
|
121
|
+
let allowedOperationsBits = $1ca228bc9257ca16$var$getAllowedOperations(e);
|
|
122
|
+
let allowedOperations = $1ca228bc9257ca16$var$allowedOperationsToArray(allowedOperationsBits);
|
|
123
|
+
let dropOperation = allowedOperations[0];
|
|
124
|
+
if (typeof options.getDropOperation === "function") {
|
|
125
|
+
let types = new (0, $4620ae0dc40f0031$exports.DragTypes)(e.dataTransfer);
|
|
126
|
+
dropOperation = $1ca228bc9257ca16$var$getDropOperation(allowedOperationsBits, options.getDropOperation(types, allowedOperations));
|
|
127
|
+
}
|
|
128
|
+
if (typeof options.getDropOperationForPoint === "function") {
|
|
129
|
+
let types = new (0, $4620ae0dc40f0031$exports.DragTypes)(e.dataTransfer);
|
|
130
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
131
|
+
dropOperation = $1ca228bc9257ca16$var$getDropOperation(allowedOperationsBits, options.getDropOperationForPoint(types, allowedOperations, e.clientX - rect.x, e.clientY - rect.y));
|
|
132
|
+
}
|
|
133
|
+
state.x = e.clientX;
|
|
134
|
+
state.y = e.clientY;
|
|
135
|
+
state.allowedOperations = allowedOperationsBits;
|
|
136
|
+
state.dropEffect = (0, $76b1e110a27b1ccd$exports.DROP_OPERATION_TO_DROP_EFFECT)[dropOperation] || "none";
|
|
137
|
+
e.dataTransfer.dropEffect = state.dropEffect;
|
|
138
|
+
if (dropOperation !== "cancel") fireDropEnter(e);
|
|
139
|
+
};
|
|
140
|
+
let onDragLeave = (e)=>{
|
|
141
|
+
e.preventDefault();
|
|
142
|
+
e.stopPropagation();
|
|
143
|
+
// We would use e.relatedTarget to detect if the drag is still inside the drop target,
|
|
144
|
+
// but it is always null in WebKit. https://bugs.webkit.org/show_bug.cgi?id=66547
|
|
145
|
+
// Instead, we track all of the targets of dragenter events in a set, and remove them
|
|
146
|
+
// in dragleave. When the set becomes empty, we've left the drop target completely.
|
|
147
|
+
// We must also remove any elements that are no longer in the DOM, because dragleave
|
|
148
|
+
// events will never be fired for these. This can happen, for example, with drop
|
|
149
|
+
// indicators between items, which disappear when the drop target changes.
|
|
150
|
+
state.dragOverElements.delete(e.target);
|
|
151
|
+
for (let element of state.dragOverElements)if (!e.currentTarget.contains(element)) state.dragOverElements.delete(element);
|
|
152
|
+
if (state.dragOverElements.size > 0) return;
|
|
153
|
+
if (state.dropEffect !== "none") fireDropExit(e);
|
|
154
|
+
clearTimeout(state.dropActivateTimer);
|
|
155
|
+
};
|
|
156
|
+
let onDrop = (e)=>{
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
e.stopPropagation();
|
|
159
|
+
// Track drop effect in global state for Chrome Android. https://bugs.chromium.org/p/chromium/issues/detail?id=1353951
|
|
160
|
+
// Android onDragEnd always returns "none" as its drop effect.
|
|
161
|
+
(0, $4620ae0dc40f0031$exports.setGlobalDropEffect)(state.dropEffect);
|
|
162
|
+
if (typeof options.onDrop === "function") {
|
|
163
|
+
let dropOperation = (0, $76b1e110a27b1ccd$exports.DROP_EFFECT_TO_DROP_OPERATION)[state.dropEffect];
|
|
164
|
+
let items = (0, $4620ae0dc40f0031$exports.readFromDataTransfer)(e.dataTransfer);
|
|
165
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
166
|
+
let event = {
|
|
167
|
+
type: "drop",
|
|
168
|
+
x: e.clientX - rect.x,
|
|
169
|
+
y: e.clientY - rect.y,
|
|
170
|
+
items: items,
|
|
171
|
+
dropOperation: dropOperation
|
|
172
|
+
};
|
|
173
|
+
options.onDrop(event);
|
|
174
|
+
}
|
|
175
|
+
let dndStateSnapshot = {
|
|
176
|
+
...(0, $4620ae0dc40f0031$exports.globalDndState)
|
|
177
|
+
};
|
|
178
|
+
state.dragOverElements.clear();
|
|
179
|
+
fireDropExit(e);
|
|
180
|
+
clearTimeout(state.dropActivateTimer);
|
|
181
|
+
// 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
|
|
182
|
+
// RSP collection and thus we don't need to preserve the global drop effect
|
|
183
|
+
if (dndStateSnapshot.draggingCollectionRef == null) (0, $4620ae0dc40f0031$exports.setGlobalDropEffect)(undefined);
|
|
184
|
+
else // Otherwise we need to preserve the global dnd state for onDragEnd's isInternal check.
|
|
185
|
+
// At the moment fireDropExit may clear dropCollectionRef (i.e. useDroppableCollection's provided onDropExit, required to clear dropCollectionRef when exiting a valid drop target)
|
|
186
|
+
(0, $4620ae0dc40f0031$exports.setGlobalDnDState)(dndStateSnapshot);
|
|
187
|
+
};
|
|
188
|
+
let onDropEnter = (0, $AO99w$reactariautils.useEffectEvent)((e)=>{
|
|
189
|
+
if (typeof options.onDropEnter === "function") options.onDropEnter(e);
|
|
190
|
+
});
|
|
191
|
+
let onDropExit = (0, $AO99w$reactariautils.useEffectEvent)((e)=>{
|
|
192
|
+
if (typeof options.onDropExit === "function") options.onDropExit(e);
|
|
193
|
+
});
|
|
194
|
+
let onDropActivate = (0, $AO99w$reactariautils.useEffectEvent)((e)=>{
|
|
195
|
+
if (typeof options.onDropActivate === "function") options.onDropActivate(e);
|
|
196
|
+
});
|
|
197
|
+
let onKeyboardDrop = (0, $AO99w$reactariautils.useEffectEvent)((e)=>{
|
|
198
|
+
if (typeof options.onDrop === "function") options.onDrop(e);
|
|
199
|
+
});
|
|
200
|
+
let getDropOperationKeyboard = (0, $AO99w$reactariautils.useEffectEvent)((types, allowedOperations)=>{
|
|
201
|
+
if (options.getDropOperation) return options.getDropOperation(types, allowedOperations);
|
|
202
|
+
return allowedOperations[0];
|
|
203
|
+
});
|
|
204
|
+
let { ref: ref } = options;
|
|
205
|
+
(0, $AO99w$reactariautils.useLayoutEffect)(()=>{
|
|
206
|
+
if (isDisabled) return;
|
|
207
|
+
return $28e10663603f5ea1$exports.registerDropTarget({
|
|
208
|
+
element: ref.current,
|
|
209
|
+
getDropOperation: getDropOperationKeyboard,
|
|
210
|
+
onDropEnter (e) {
|
|
211
|
+
setDropTarget(true);
|
|
212
|
+
onDropEnter(e);
|
|
213
|
+
},
|
|
214
|
+
onDropExit (e) {
|
|
215
|
+
setDropTarget(false);
|
|
216
|
+
onDropExit(e);
|
|
217
|
+
},
|
|
218
|
+
onDrop: onKeyboardDrop,
|
|
219
|
+
onDropActivate: onDropActivate
|
|
220
|
+
});
|
|
221
|
+
}, [
|
|
222
|
+
isDisabled,
|
|
223
|
+
ref,
|
|
224
|
+
getDropOperationKeyboard,
|
|
225
|
+
onDropEnter,
|
|
226
|
+
onDropExit,
|
|
227
|
+
onKeyboardDrop,
|
|
228
|
+
onDropActivate
|
|
229
|
+
]);
|
|
230
|
+
let { dropProps: dropProps } = (0, $419982e205c8e8dc$exports.useVirtualDrop)();
|
|
231
|
+
if (isDisabled) return {
|
|
232
|
+
dropProps: {},
|
|
233
|
+
dropButtonProps: {
|
|
234
|
+
isDisabled: true
|
|
235
|
+
},
|
|
236
|
+
isDropTarget: false
|
|
237
|
+
};
|
|
238
|
+
return {
|
|
239
|
+
dropProps: {
|
|
240
|
+
...!hasDropButton && dropProps,
|
|
241
|
+
onDragEnter: onDragEnter,
|
|
242
|
+
onDragOver: onDragOver,
|
|
243
|
+
onDragLeave: onDragLeave,
|
|
244
|
+
onDrop: onDrop
|
|
245
|
+
},
|
|
246
|
+
dropButtonProps: {
|
|
247
|
+
...hasDropButton && dropProps
|
|
248
|
+
},
|
|
249
|
+
isDropTarget: isDropTarget
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function $1ca228bc9257ca16$var$getAllowedOperations(e) {
|
|
253
|
+
let allowedOperations = (0, $76b1e110a27b1ccd$exports.DROP_OPERATION_ALLOWED)[e.dataTransfer.effectAllowed];
|
|
254
|
+
// WebKit always sets effectAllowed to "copyMove" on macOS, and "all" on iOS, regardless of what was
|
|
255
|
+
// set during the dragstart event: https://bugs.webkit.org/show_bug.cgi?id=178058
|
|
256
|
+
//
|
|
257
|
+
// Android Chrome also sets effectAllowed to "copyMove" in all cases: https://bugs.chromium.org/p/chromium/issues/detail?id=1359182
|
|
258
|
+
//
|
|
259
|
+
// If the drag started within the page, we can use a global variable to get the real allowed operations.
|
|
260
|
+
// This needs to be intersected with the actual effectAllowed, which may have been filtered based on modifier keys.
|
|
261
|
+
// Unfortunately, this means that link operations do not work at all in Safari.
|
|
262
|
+
if (0, $4620ae0dc40f0031$exports.globalAllowedDropOperations) allowedOperations &= (0, $4620ae0dc40f0031$exports.globalAllowedDropOperations);
|
|
263
|
+
// Chrome and Safari on macOS will automatically filter effectAllowed when pressing modifier keys,
|
|
264
|
+
// allowing the user to switch between move, link, and copy operations. Firefox on macOS and all
|
|
265
|
+
// Windows browsers do not do this, so do it ourselves instead. The exact keys are platform dependent.
|
|
266
|
+
// https://ux.stackexchange.com/questions/83748/what-are-the-most-common-modifier-keys-for-dragging-objects-with-a-mouse
|
|
267
|
+
//
|
|
268
|
+
// Note that none of these modifiers are ever set in WebKit due to a bug: https://bugs.webkit.org/show_bug.cgi?id=77465
|
|
269
|
+
// However, Safari does update effectAllowed correctly, so we can just rely on that.
|
|
270
|
+
let allowedModifiers = (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).none;
|
|
271
|
+
if ((0, $AO99w$reactariautils.isMac)()) {
|
|
272
|
+
if (e.altKey) allowedModifiers |= (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).copy;
|
|
273
|
+
// Chrome and Safari both use the Control key for link, even though Finder uses Command + Option.
|
|
274
|
+
// iPadOS doesn't support link operations and will not fire the drop event at all if dropEffect is set to link.
|
|
275
|
+
// https://bugs.webkit.org/show_bug.cgi?id=244701
|
|
276
|
+
if (e.ctrlKey && !(0, $AO99w$reactariautils.isIPad)()) allowedModifiers |= (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).link;
|
|
277
|
+
if (e.metaKey) allowedModifiers |= (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).move;
|
|
278
|
+
} else {
|
|
279
|
+
if (e.altKey) allowedModifiers |= (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).link;
|
|
280
|
+
if (e.shiftKey) allowedModifiers |= (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).move;
|
|
281
|
+
if (e.ctrlKey) allowedModifiers |= (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).copy;
|
|
282
|
+
}
|
|
283
|
+
if (allowedModifiers) return allowedOperations & allowedModifiers;
|
|
284
|
+
return allowedOperations;
|
|
285
|
+
}
|
|
286
|
+
function $1ca228bc9257ca16$var$allowedOperationsToArray(allowedOperationsBits) {
|
|
287
|
+
let allowedOperations = [];
|
|
288
|
+
if (allowedOperationsBits & (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).move) allowedOperations.push("move");
|
|
289
|
+
if (allowedOperationsBits & (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).copy) allowedOperations.push("copy");
|
|
290
|
+
if (allowedOperationsBits & (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).link) allowedOperations.push("link");
|
|
291
|
+
return allowedOperations;
|
|
292
|
+
}
|
|
293
|
+
function $1ca228bc9257ca16$var$getDropOperation(allowedOperations, operation) {
|
|
294
|
+
let op = (0, $76b1e110a27b1ccd$exports.DROP_OPERATION)[operation];
|
|
295
|
+
return allowedOperations & op ? operation : "cancel";
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
//# sourceMappingURL=useDrop.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAuDD,MAAM,8CAAwB;AAMvB,SAAS,0CAAQ,OAAoB;IAC1C,IAAI,iBAAC,aAAa,cAAE,UAAU,EAAC,GAAG;IAClC,IAAI,CAAC,cAAc,cAAc,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC7C,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAE;QACjB,GAAG;QACH,GAAG;QACH,kBAAkB,IAAI;QACtB,YAAY;QACZ,mBAAmB,CAAA,GAAA,wCAAa,EAAE,GAAG;QACrC,mBAAmB;IACrB,GAAG,OAAO;IAEV,IAAI,gBAAgB,CAAC;QACnB,cAAc;QAEd,IAAI,OAAO,QAAQ,WAAW,KAAK,YAAY;YAC7C,IAAI,OAAO,AAAC,EAAE,aAAa,CAAiB,qBAAqB;YACjE,QAAQ,WAAW,CAAC;gBAClB,MAAM;gBACN,GAAG,EAAE,OAAO,GAAG,KAAK,CAAC;gBACrB,GAAG,EAAE,OAAO,GAAG,KAAK,CAAC;YACvB;QACF;IACF;IAEA,IAAI,eAAe,CAAC;QAClB,cAAc;QAEd,IAAI,OAAO,Q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,IAAI,EAAE,MAAM,EACV,oBAAoB,CAAA,GAAA,wCAAa,EAAE,IAAI;QAGzC,iGAAiG;QACjG,+GAA+G;QAC/G,iDAAiD;QACjD,IAAI,EAAE,OAAO,IAAI,CAAC,CAAA,GAAA,4BAAK,KACrB,oBAAoB,CAAA,GAAA,wCAAa,EAAE,IAAI;QAGzC,IAAI,EAAE,OAAO,EACX,oBAAoB,CAAA,GAAA,wCAAa,EAAE,IAAI;IAE3C,OAAO;QACL,IAAI,EAAE,MAAM,EACV,oBAAoB,CAAA,GAAA,wCAAa,EAAE,IAAI;QAGzC,IAAI,EAAE,QAAQ,EACZ,oBAAoB,CAAA,GAAA,wCAAa,EAAE,IAAI;QAGzC,IAAI,EAAE,OAAO,EACX,oBAAoB,CAAA,GAAA,wCAAa,EAAE,IAAI;IAE3C;IAEA,IAAI,kBACF,OAAO,oBAAoB;IAG7B,OAAO;AACT;AAEA,SAAS,+CAAyB,qBAAqC;IACrE,IAAI,oBAAoB,EAAE;IAC1B,IAAI,wBAAwB,CAAA,GAAA,wCAAa,EAAE,IAAI,EAC7C,kBAAkB,IAAI,CAAC;IAGzB,IAAI,wBAAwB,CAAA,GAAA,wCAAa,EAAE,IAAI,EAC7C,kBAAkB,IAAI,CAAC;IAGzB,IAAI,wBAAwB,CAAA,GAAA,wCAAa,EAAE,IAAI,EAC7C,kBAAkB,IAAI,CAAC;IAGzB,OAAO;AACT;AAEA,SAAS,uCAAiB,iBAAiC,EAAE,SAAwB;IACnF,IAAI,KAAK,CAAA,GAAA,wCAAa,CAAC,CAAC,UAAU;IAClC,OAAO,oBAAoB,KAAK,YAAY;AAC9C","sources":["packages/@react-aria/dnd/src/useDrop.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {DragEvent, HTMLAttributes, RefObject, useRef, useState} from 'react';\nimport * as DragManager from './DragManager';\nimport {DragTypes, globalAllowedDropOperations, globalDndState, readFromDataTransfer, setGlobalDnDState, setGlobalDropEffect} from './utils';\nimport {DROP_EFFECT_TO_DROP_OPERATION, DROP_OPERATION, DROP_OPERATION_ALLOWED, DROP_OPERATION_TO_DROP_EFFECT} from './constants';\nimport {DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropMoveEvent, DropOperation, DragTypes as IDragTypes} from '@react-types/shared';\nimport {isIPad, isMac, useEffectEvent, useLayoutEffect} from '@react-aria/utils';\nimport {useVirtualDrop} from './useVirtualDrop';\n\nexport interface DropOptions {\n /** A ref for the droppable element. */\n ref: RefObject<HTMLElement>,\n /**\n * A function returning the drop operation to be performed when items matching the given types are dropped\n * on the drop target.\n */\n getDropOperation?: (types: IDragTypes, allowedOperations: DropOperation[]) => DropOperation,\n /** A function that returns the drop operation for a specific point within the target. */\n getDropOperationForPoint?: (types: IDragTypes, allowedOperations: DropOperation[], x: number, y: number) => DropOperation,\n /** Handler that is called when a valid drag enters the drop target. */\n onDropEnter?: (e: DropEnterEvent) => void,\n /** Handler that is called when a valid drag is moved within the drop target. */\n onDropMove?: (e: DropMoveEvent) => void,\n /**\n * Handler that is called after a valid drag is held over the drop target for a period of time.\n * This typically opens the item so that the user can drop within it.\n * @private\n */\n onDropActivate?: (e: DropActivateEvent) => void,\n /** Handler that is called when a valid drag exits the drop target. */\n onDropExit?: (e: DropExitEvent) => void,\n /** Handler that is called when a valid drag is dropped on the drop target. */\n onDrop?: (e: DropEvent) => void,\n /**\n * Whether the item has an explicit focusable drop affordance to initiate accessible drag and drop mode.\n * If true, the dropProps will omit these event handlers, and they will be applied to dropButtonProps instead.\n */\n hasDropButton?: boolean,\n /**\n * Whether the drop target is disabled. If true, the drop target will not accept any drops.\n */\n isDisabled?: boolean\n}\n\nexport interface DropResult {\n /** Props for the droppable element. */\n dropProps: HTMLAttributes<HTMLElement>,\n /** Whether the drop target is currently focused or hovered. */\n isDropTarget: boolean,\n /** Props for the explicit drop button affordance, if any. */\n dropButtonProps?: AriaButtonProps\n}\n\nconst DROP_ACTIVATE_TIMEOUT = 800;\n\n/**\n * Handles drop interactions for an element, with support for traditional mouse and touch\n * based drag and drop, in addition to full parity for keyboard and screen reader users.\n */\nexport function useDrop(options: DropOptions): DropResult {\n let {hasDropButton, isDisabled} = options;\n let [isDropTarget, setDropTarget] = useState(false);\n let state = useRef({\n x: 0,\n y: 0,\n dragOverElements: new Set<Element>(),\n dropEffect: 'none' as DataTransfer['dropEffect'],\n allowedOperations: DROP_OPERATION.all,\n dropActivateTimer: null\n }).current;\n\n let fireDropEnter = (e: DragEvent) => {\n setDropTarget(true);\n\n if (typeof options.onDropEnter === 'function') {\n let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();\n options.onDropEnter({\n type: 'dropenter',\n x: e.clientX - rect.x,\n y: e.clientY - rect.y\n });\n }\n };\n\n let fireDropExit = (e: DragEvent) => {\n setDropTarget(false);\n\n if (typeof options.onDropExit === 'function') {\n let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();\n options.onDropExit({\n type: 'dropexit',\n x: e.clientX - rect.x,\n y: e.clientY - rect.y\n });\n }\n };\n\n let onDragOver = (e: DragEvent) => {\n e.preventDefault();\n e.stopPropagation();\n\n let allowedOperations = getAllowedOperations(e);\n if (e.clientX === state.x && e.clientY === state.y && allowedOperations === state.allowedOperations) {\n e.dataTransfer.dropEffect = state.dropEffect;\n return;\n }\n\n state.x = e.clientX;\n state.y = e.clientY;\n\n let prevDropEffect = state.dropEffect;\n\n // Update drop effect if allowed drop operations changed (e.g. user pressed modifier key).\n if (allowedOperations !== state.allowedOperations) {\n let allowedOps = allowedOperationsToArray(allowedOperations);\n let dropOperation = allowedOps[0];\n if (typeof options.getDropOperation === 'function') {\n let types = new DragTypes(e.dataTransfer);\n dropOperation = getDropOperation(allowedOperations, options.getDropOperation(types, allowedOps));\n }\n state.dropEffect = DROP_OPERATION_TO_DROP_EFFECT[dropOperation] || 'none';\n }\n\n if (typeof options.getDropOperationForPoint === 'function') {\n let types = new DragTypes(e.dataTransfer);\n let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();\n let dropOperation = getDropOperation(\n allowedOperations,\n options.getDropOperationForPoint(types, allowedOperationsToArray(allowedOperations), state.x - rect.x, state.y - rect.y)\n );\n state.dropEffect = DROP_OPERATION_TO_DROP_EFFECT[dropOperation] || 'none';\n }\n\n state.allowedOperations = allowedOperations;\n e.dataTransfer.dropEffect = state.dropEffect;\n\n // If the drop operation changes, update state and fire events appropriately.\n if (state.dropEffect === 'none' && prevDropEffect !== 'none') {\n fireDropExit(e);\n } else if (state.dropEffect !== 'none' && prevDropEffect === 'none') {\n fireDropEnter(e);\n }\n\n if (typeof options.onDropMove === 'function' && state.dropEffect !== 'none') {\n let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();\n options.onDropMove({\n type: 'dropmove',\n x: state.x - rect.x,\n y: state.y - rect.y\n });\n }\n\n clearTimeout(state.dropActivateTimer);\n\n if (typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') {\n let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();\n state.dropActivateTimer = setTimeout(() => {\n options.onDropActivate({\n type: 'dropactivate',\n x: state.x - rect.x,\n y: state.y - rect.y\n });\n }, DROP_ACTIVATE_TIMEOUT);\n }\n };\n\n let onDragEnter = (e: DragEvent) => {\n e.preventDefault();\n e.stopPropagation();\n state.dragOverElements.add(e.target as Element);\n if (state.dragOverElements.size > 1) {\n return;\n }\n\n let allowedOperationsBits = getAllowedOperations(e);\n let allowedOperations = allowedOperationsToArray(allowedOperationsBits);\n let dropOperation = allowedOperations[0];\n\n if (typeof options.getDropOperation === 'function') {\n let types = new DragTypes(e.dataTransfer);\n dropOperation = getDropOperation(allowedOperationsBits, options.getDropOperation(types, allowedOperations));\n }\n\n if (typeof options.getDropOperationForPoint === 'function') {\n let types = new DragTypes(e.dataTransfer);\n let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();\n dropOperation = getDropOperation(\n allowedOperationsBits,\n options.getDropOperationForPoint(types, allowedOperations, e.clientX - rect.x, e.clientY - rect.y)\n );\n }\n\n state.x = e.clientX;\n state.y = e.clientY;\n state.allowedOperations = allowedOperationsBits;\n state.dropEffect = DROP_OPERATION_TO_DROP_EFFECT[dropOperation] || 'none';\n e.dataTransfer.dropEffect = state.dropEffect;\n\n if (dropOperation !== 'cancel') {\n fireDropEnter(e);\n }\n };\n\n let onDragLeave = (e: DragEvent) => {\n e.preventDefault();\n e.stopPropagation();\n\n // We would use e.relatedTarget to detect if the drag is still inside the drop target,\n // but it is always null in WebKit. https://bugs.webkit.org/show_bug.cgi?id=66547\n // Instead, we track all of the targets of dragenter events in a set, and remove them\n // in dragleave. When the set becomes empty, we've left the drop target completely.\n // We must also remove any elements that are no longer in the DOM, because dragleave\n // events will never be fired for these. This can happen, for example, with drop\n // indicators between items, which disappear when the drop target changes.\n\n state.dragOverElements.delete(e.target as Element);\n for (let element of state.dragOverElements) {\n if (!e.currentTarget.contains(element)) {\n state.dragOverElements.delete(element);\n }\n }\n\n if (state.dragOverElements.size > 0) {\n return;\n }\n\n if (state.dropEffect !== 'none') {\n fireDropExit(e);\n }\n\n clearTimeout(state.dropActivateTimer);\n };\n\n let onDrop = (e: DragEvent) => {\n e.preventDefault();\n e.stopPropagation();\n // Track drop effect in global state for Chrome Android. https://bugs.chromium.org/p/chromium/issues/detail?id=1353951\n // Android onDragEnd always returns \"none\" as its drop effect.\n setGlobalDropEffect(state.dropEffect);\n\n if (typeof options.onDrop === 'function') {\n let dropOperation = DROP_EFFECT_TO_DROP_OPERATION[state.dropEffect];\n let items = readFromDataTransfer(e.dataTransfer);\n\n let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();\n let event: DropEvent = {\n type: 'drop',\n x: e.clientX - rect.x,\n y: e.clientY - rect.y,\n items,\n dropOperation\n };\n\n options.onDrop(event);\n }\n\n let dndStateSnapshot = {...globalDndState};\n state.dragOverElements.clear();\n fireDropExit(e);\n clearTimeout(state.dropActivateTimer);\n // 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\n // RSP collection and thus we don't need to preserve the global drop effect\n if (dndStateSnapshot.draggingCollectionRef == null) {\n setGlobalDropEffect(undefined);\n } else {\n // Otherwise we need to preserve the global dnd state for onDragEnd's isInternal check.\n // At the moment fireDropExit may clear dropCollectionRef (i.e. useDroppableCollection's provided onDropExit, required to clear dropCollectionRef when exiting a valid drop target)\n setGlobalDnDState(dndStateSnapshot);\n }\n };\n\n let onDropEnter = useEffectEvent((e: DropEnterEvent) => {\n if (typeof options.onDropEnter === 'function') {\n options.onDropEnter(e);\n }\n });\n\n let onDropExit = useEffectEvent((e: DropExitEvent) => {\n if (typeof options.onDropExit === 'function') {\n options.onDropExit(e);\n }\n });\n\n let onDropActivate = useEffectEvent((e: DropActivateEvent) => {\n if (typeof options.onDropActivate === 'function') {\n options.onDropActivate(e);\n }\n });\n\n let onKeyboardDrop = useEffectEvent((e: DropEvent) => {\n if (typeof options.onDrop === 'function') {\n options.onDrop(e);\n }\n });\n\n let getDropOperationKeyboard = useEffectEvent((types: IDragTypes, allowedOperations: DropOperation[]) => {\n if (options.getDropOperation) {\n return options.getDropOperation(types, allowedOperations);\n }\n\n return allowedOperations[0];\n });\n\n let {ref} = options;\n useLayoutEffect(() => {\n if (isDisabled) {\n return;\n }\n return DragManager.registerDropTarget({\n element: ref.current,\n getDropOperation: getDropOperationKeyboard,\n onDropEnter(e) {\n setDropTarget(true);\n onDropEnter(e);\n },\n onDropExit(e) {\n setDropTarget(false);\n onDropExit(e);\n },\n onDrop: onKeyboardDrop,\n onDropActivate\n });\n }, [isDisabled, ref, getDropOperationKeyboard, onDropEnter, onDropExit, onKeyboardDrop, onDropActivate]);\n\n let {dropProps} = useVirtualDrop();\n if (isDisabled) {\n return {\n dropProps: {},\n dropButtonProps: {isDisabled: true},\n isDropTarget: false\n };\n }\n return {\n dropProps: {\n ...(!hasDropButton && dropProps),\n onDragEnter,\n onDragOver,\n onDragLeave,\n onDrop\n },\n dropButtonProps: {...(hasDropButton && dropProps)},\n isDropTarget\n };\n}\n\nfunction getAllowedOperations(e: DragEvent) {\n let allowedOperations = DROP_OPERATION_ALLOWED[e.dataTransfer.effectAllowed];\n\n // WebKit always sets effectAllowed to \"copyMove\" on macOS, and \"all\" on iOS, regardless of what was\n // set during the dragstart event: https://bugs.webkit.org/show_bug.cgi?id=178058\n //\n // Android Chrome also sets effectAllowed to \"copyMove\" in all cases: https://bugs.chromium.org/p/chromium/issues/detail?id=1359182\n //\n // If the drag started within the page, we can use a global variable to get the real allowed operations.\n // This needs to be intersected with the actual effectAllowed, which may have been filtered based on modifier keys.\n // Unfortunately, this means that link operations do not work at all in Safari.\n if (globalAllowedDropOperations) {\n allowedOperations &= globalAllowedDropOperations;\n }\n\n // Chrome and Safari on macOS will automatically filter effectAllowed when pressing modifier keys,\n // allowing the user to switch between move, link, and copy operations. Firefox on macOS and all\n // Windows browsers do not do this, so do it ourselves instead. The exact keys are platform dependent.\n // https://ux.stackexchange.com/questions/83748/what-are-the-most-common-modifier-keys-for-dragging-objects-with-a-mouse\n //\n // Note that none of these modifiers are ever set in WebKit due to a bug: https://bugs.webkit.org/show_bug.cgi?id=77465\n // However, Safari does update effectAllowed correctly, so we can just rely on that.\n let allowedModifiers = DROP_OPERATION.none;\n if (isMac()) {\n if (e.altKey) {\n allowedModifiers |= DROP_OPERATION.copy;\n }\n\n // Chrome and Safari both use the Control key for link, even though Finder uses Command + Option.\n // iPadOS doesn't support link operations and will not fire the drop event at all if dropEffect is set to link.\n // https://bugs.webkit.org/show_bug.cgi?id=244701\n if (e.ctrlKey && !isIPad()) {\n allowedModifiers |= DROP_OPERATION.link;\n }\n\n if (e.metaKey) {\n allowedModifiers |= DROP_OPERATION.move;\n }\n } else {\n if (e.altKey) {\n allowedModifiers |= DROP_OPERATION.link;\n }\n\n if (e.shiftKey) {\n allowedModifiers |= DROP_OPERATION.move;\n }\n\n if (e.ctrlKey) {\n allowedModifiers |= DROP_OPERATION.copy;\n }\n }\n\n if (allowedModifiers) {\n return allowedOperations & allowedModifiers;\n }\n\n return allowedOperations;\n}\n\nfunction allowedOperationsToArray(allowedOperationsBits: DROP_OPERATION) {\n let allowedOperations = [];\n if (allowedOperationsBits & DROP_OPERATION.move) {\n allowedOperations.push('move');\n }\n\n if (allowedOperationsBits & DROP_OPERATION.copy) {\n allowedOperations.push('copy');\n }\n\n if (allowedOperationsBits & DROP_OPERATION.link) {\n allowedOperations.push('link');\n }\n\n return allowedOperations;\n}\n\nfunction getDropOperation(allowedOperations: DROP_OPERATION, operation: DropOperation) {\n let op = DROP_OPERATION[operation];\n return allowedOperations & op ? operation : 'cancel';\n}\n"],"names":[],"version":3,"file":"useDrop.main.js.map"}
|