@react-aria/dnd 3.7.3 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/DragManager.main.js +25 -13
- package/dist/DragManager.main.js.map +1 -1
- package/dist/DragManager.mjs +25 -13
- package/dist/DragManager.module.js +25 -13
- package/dist/DragManager.module.js.map +1 -1
- package/dist/DragPreview.main.js +7 -1
- package/dist/DragPreview.main.js.map +1 -1
- package/dist/DragPreview.mjs +8 -2
- package/dist/DragPreview.module.js +8 -2
- package/dist/DragPreview.module.js.map +1 -1
- package/dist/ListDropTargetDelegate.main.js +5 -4
- package/dist/ListDropTargetDelegate.main.js.map +1 -1
- package/dist/ListDropTargetDelegate.mjs +5 -4
- package/dist/ListDropTargetDelegate.module.js +5 -4
- package/dist/ListDropTargetDelegate.module.js.map +1 -1
- package/dist/ar-AE.main.js.map +1 -1
- package/dist/ar-AE.module.js.map +1 -1
- package/dist/bg-BG.main.js.map +1 -1
- package/dist/bg-BG.module.js.map +1 -1
- package/dist/constants.main.js +3 -3
- package/dist/constants.main.js.map +1 -1
- package/dist/constants.mjs +3 -3
- package/dist/constants.module.js +3 -3
- package/dist/constants.module.js.map +1 -1
- package/dist/cs-CZ.main.js.map +1 -1
- package/dist/cs-CZ.module.js.map +1 -1
- package/dist/da-DK.main.js.map +1 -1
- package/dist/da-DK.module.js.map +1 -1
- package/dist/de-DE.main.js.map +1 -1
- package/dist/de-DE.module.js.map +1 -1
- package/dist/el-GR.main.js.map +1 -1
- package/dist/el-GR.module.js.map +1 -1
- package/dist/en-US.main.js.map +1 -1
- package/dist/en-US.module.js.map +1 -1
- package/dist/es-ES.main.js.map +1 -1
- package/dist/es-ES.module.js.map +1 -1
- package/dist/et-EE.main.js.map +1 -1
- package/dist/et-EE.module.js.map +1 -1
- package/dist/fi-FI.main.js.map +1 -1
- package/dist/fi-FI.module.js.map +1 -1
- package/dist/fr-FR.main.js.map +1 -1
- package/dist/fr-FR.module.js.map +1 -1
- package/dist/he-IL.main.js.map +1 -1
- package/dist/he-IL.module.js.map +1 -1
- package/dist/hr-HR.main.js.map +1 -1
- package/dist/hr-HR.module.js.map +1 -1
- package/dist/hu-HU.main.js.map +1 -1
- package/dist/hu-HU.module.js.map +1 -1
- package/dist/it-IT.main.js.map +1 -1
- package/dist/it-IT.module.js.map +1 -1
- package/dist/ja-JP.main.js.map +1 -1
- package/dist/ja-JP.module.js.map +1 -1
- package/dist/ko-KR.main.js.map +1 -1
- package/dist/ko-KR.module.js.map +1 -1
- package/dist/lt-LT.main.js.map +1 -1
- package/dist/lt-LT.module.js.map +1 -1
- package/dist/lv-LV.main.js.map +1 -1
- package/dist/lv-LV.module.js.map +1 -1
- package/dist/nb-NO.main.js.map +1 -1
- package/dist/nb-NO.module.js.map +1 -1
- package/dist/nl-NL.main.js.map +1 -1
- package/dist/nl-NL.module.js.map +1 -1
- package/dist/pl-PL.main.js.map +1 -1
- package/dist/pl-PL.module.js.map +1 -1
- package/dist/pt-BR.main.js.map +1 -1
- package/dist/pt-BR.module.js.map +1 -1
- package/dist/pt-PT.main.js.map +1 -1
- package/dist/pt-PT.module.js.map +1 -1
- package/dist/ro-RO.main.js.map +1 -1
- package/dist/ro-RO.module.js.map +1 -1
- package/dist/ru-RU.main.js.map +1 -1
- package/dist/ru-RU.module.js.map +1 -1
- package/dist/sk-SK.main.js.map +1 -1
- package/dist/sk-SK.module.js.map +1 -1
- package/dist/sl-SI.main.js.map +1 -1
- package/dist/sl-SI.module.js.map +1 -1
- package/dist/sr-SP.main.js.map +1 -1
- package/dist/sr-SP.module.js.map +1 -1
- package/dist/sv-SE.main.js.map +1 -1
- package/dist/sv-SE.module.js.map +1 -1
- package/dist/tr-TR.main.js.map +1 -1
- package/dist/tr-TR.module.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/uk-UA.main.js.map +1 -1
- package/dist/uk-UA.module.js.map +1 -1
- package/dist/useAutoScroll.main.js +5 -5
- package/dist/useAutoScroll.main.js.map +1 -1
- package/dist/useAutoScroll.mjs +5 -5
- package/dist/useAutoScroll.module.js +5 -5
- package/dist/useAutoScroll.module.js.map +1 -1
- package/dist/useClipboard.main.js +13 -7
- package/dist/useClipboard.main.js.map +1 -1
- package/dist/useClipboard.mjs +13 -7
- package/dist/useClipboard.module.js +13 -7
- package/dist/useClipboard.module.js.map +1 -1
- package/dist/useDrag.main.js +2 -2
- package/dist/useDrag.main.js.map +1 -1
- package/dist/useDrag.mjs +2 -2
- package/dist/useDrag.module.js +2 -2
- package/dist/useDrag.module.js.map +1 -1
- package/dist/useDrop.main.js +5 -4
- package/dist/useDrop.main.js.map +1 -1
- package/dist/useDrop.mjs +5 -4
- package/dist/useDrop.module.js +5 -4
- package/dist/useDrop.module.js.map +1 -1
- package/dist/useDropIndicator.main.js +3 -2
- package/dist/useDropIndicator.main.js.map +1 -1
- package/dist/useDropIndicator.mjs +3 -2
- package/dist/useDropIndicator.module.js +3 -2
- package/dist/useDropIndicator.module.js.map +1 -1
- package/dist/useDroppableCollection.main.js +33 -19
- package/dist/useDroppableCollection.main.js.map +1 -1
- package/dist/useDroppableCollection.mjs +33 -19
- package/dist/useDroppableCollection.module.js +33 -19
- package/dist/useDroppableCollection.module.js.map +1 -1
- package/dist/useVirtualDrop.main.js.map +1 -1
- package/dist/useVirtualDrop.module.js.map +1 -1
- package/dist/utils.main.js +5 -3
- package/dist/utils.main.js.map +1 -1
- package/dist/utils.mjs +5 -3
- package/dist/utils.module.js +5 -3
- package/dist/utils.module.js.map +1 -1
- package/dist/zh-CN.main.js.map +1 -1
- package/dist/zh-CN.module.js.map +1 -1
- package/dist/zh-TW.main.js.map +1 -1
- package/dist/zh-TW.module.js.map +1 -1
- package/package.json +15 -14
- package/src/DragManager.ts +26 -24
- package/src/DragPreview.tsx +17 -8
- package/src/ListDropTargetDelegate.ts +8 -5
- package/src/useAutoScroll.ts +6 -6
- package/src/useClipboard.ts +12 -6
- package/src/useDrag.ts +5 -2
- package/src/useDrop.ts +17 -9
- package/src/useDropIndicator.ts +10 -4
- package/src/useDroppableCollection.ts +62 -39
- package/src/useVirtualDrop.ts +3 -2
- package/src/utils.ts +16 -10
|
@@ -54,11 +54,13 @@ function $9fcc7f0d70d084ee$export$2314ca2a3e892862(options) {
|
|
|
54
54
|
if (isFocusedRef.current && options.getItems) e.preventDefault();
|
|
55
55
|
});
|
|
56
56
|
let onCopy = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
57
|
-
var _options_onCopy;
|
|
58
57
|
if (!isFocusedRef.current || !options.getItems) return;
|
|
59
58
|
e.preventDefault();
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
if (e.clipboardData) {
|
|
60
|
+
var _options_onCopy;
|
|
61
|
+
(0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.clipboardData, options.getItems());
|
|
62
|
+
(_options_onCopy = options.onCopy) === null || _options_onCopy === void 0 ? void 0 : _options_onCopy.call(options);
|
|
63
|
+
}
|
|
62
64
|
});
|
|
63
65
|
let onBeforeCut = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
64
66
|
if (isFocusedRef.current && options.onCut && options.getItems) e.preventDefault();
|
|
@@ -66,8 +68,10 @@ function $9fcc7f0d70d084ee$export$2314ca2a3e892862(options) {
|
|
|
66
68
|
let onCut = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
67
69
|
if (!isFocusedRef.current || !options.onCut || !options.getItems) return;
|
|
68
70
|
e.preventDefault();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
if (e.clipboardData) {
|
|
72
|
+
(0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.clipboardData, options.getItems());
|
|
73
|
+
options.onCut();
|
|
74
|
+
}
|
|
71
75
|
});
|
|
72
76
|
let onBeforePaste = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
73
77
|
// Unfortunately, e.clipboardData.types is not available in this event so we always
|
|
@@ -77,8 +81,10 @@ function $9fcc7f0d70d084ee$export$2314ca2a3e892862(options) {
|
|
|
77
81
|
let onPaste = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
78
82
|
if (!isFocusedRef.current || !options.onPaste) return;
|
|
79
83
|
e.preventDefault();
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
if (e.clipboardData) {
|
|
85
|
+
let items = (0, $7252cd45fc48c07c$export$d9e760437831f8b3)(e.clipboardData);
|
|
86
|
+
options.onPaste(items);
|
|
87
|
+
}
|
|
82
88
|
});
|
|
83
89
|
(0, $9Tt78$useEffect)(()=>{
|
|
84
90
|
if (isDisabled) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA0BD,MAAM,qCAAe,IAAI;AACzB,SAAS,6CAAuB,KAAK,EAAE,EAAE;IACvC,IAAI,YAAY,mCAAa,GAAG,CAAC;IACjC,IAAI,CAAC,WAAW;QACd,IAAI,WAAW,IAAI;QACnB,IAAI,WAAW,CAAC;YACd,KAAK,IAAI,WAAW,SAClB,QAAQ;QAEZ;QAEA,YAAY;sBAAC;sBAAU;QAAQ;QAC/B,mCAAa,GAAG,CAAC,OAAO;QAExB,SAAS,gBAAgB,CAAC,OAAO;IACnC;IAEA,UAAU,QAAQ,CAAC,GAAG,CAAC;IACvB,OAAO;QACL,UAAU,QAAQ,CAAC,MAAM,CAAC;QAC1B,IAAI,UAAU,QAAQ,CAAC,IAAI,KAAK,GAAG;YACjC,SAAS,mBAAmB,CAAC,OAAO,UAAU,QAAQ;YACtD,mCAAa,MAAM,CAAC;QACtB;IACF;AACF;AAMO,SAAS,0CAAa,OAAuB;IAClD,IAAI,cAAC,UAAU,EAAC,GAAG;IACnB,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE;IAC1B,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC1B,eAAe,CAAC;YACd,aAAa,OAAO,GAAG;QACzB;IACF;IAEA,IAAI,eAA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QAAY;QAAc;QAAQ;QAAa;QAAO;QAAe;KAAQ;IAEjF,OAAO;QACL,gBAAgB;IAClB;AACF","sources":["packages/@react-aria/dnd/src/useClipboard.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 {chain, useEffectEvent} from '@react-aria/utils';\nimport {DOMAttributes, DragItem, DropItem} from '@react-types/shared';\nimport {readFromDataTransfer, writeToDataTransfer} from './utils';\nimport {useEffect, useRef} from 'react';\nimport {useFocus} from '@react-aria/interactions';\n\nexport interface ClipboardProps {\n /** A function that returns the items to copy. */\n getItems?: () => DragItem[],\n /** Handler that is called when the user triggers a copy interaction. */\n onCopy?: () => void,\n /** Handler that is called when the user triggers a cut interaction. */\n onCut?: () => void,\n /** Handler that is called when the user triggers a paste interaction. */\n onPaste?: (items: DropItem[]) => void,\n /** Whether the clipboard is disabled. */\n isDisabled?: boolean\n}\n\nexport interface ClipboardResult {\n /** Props for the element that will handle clipboard events. */\n clipboardProps: DOMAttributes\n}\n\nconst globalEvents = new Map();\nfunction addGlobalEventListener(event, fn) {\n let eventData = globalEvents.get(event);\n if (!eventData) {\n let handlers = new Set<(e: Event) => void>();\n let listener = (e) => {\n for (let handler of handlers) {\n handler(e);\n }\n };\n\n eventData = {listener, handlers};\n globalEvents.set(event, eventData);\n\n document.addEventListener(event, listener);\n }\n\n eventData.handlers.add(fn);\n return () => {\n eventData.handlers.delete(fn);\n if (eventData.handlers.size === 0) {\n document.removeEventListener(event, eventData.listener);\n globalEvents.delete(event);\n }\n };\n}\n\n/**\n * Handles clipboard interactions for a focusable element. Supports items of multiple\n * data types, and integrates with the operating system native clipboard.\n */\nexport function useClipboard(options: ClipboardProps): ClipboardResult {\n let {isDisabled} = options;\n let isFocusedRef = useRef(false);\n let {focusProps} = useFocus({\n onFocusChange: (isFocused) => {\n isFocusedRef.current = isFocused;\n }\n });\n\n let onBeforeCopy = useEffectEvent((e: ClipboardEvent) => {\n // Enable the \"Copy\" menu item in Safari if this element is focused and copying is supported.\n if (isFocusedRef.current && options.getItems) {\n e.preventDefault();\n }\n });\n\n let onCopy = useEffectEvent((e: ClipboardEvent) => {\n if (!isFocusedRef.current || !options.getItems) {\n return;\n }\n\n e.preventDefault();\n if (e.clipboardData) {\n writeToDataTransfer(e.clipboardData, options.getItems());\n options.onCopy?.();\n }\n });\n\n let onBeforeCut = useEffectEvent((e: ClipboardEvent) => {\n if (isFocusedRef.current && options.onCut && options.getItems) {\n e.preventDefault();\n }\n });\n\n let onCut = useEffectEvent((e: ClipboardEvent) => {\n if (!isFocusedRef.current || !options.onCut || !options.getItems) {\n return;\n }\n\n e.preventDefault();\n if (e.clipboardData) {\n writeToDataTransfer(e.clipboardData, options.getItems());\n options.onCut();\n }\n });\n\n let onBeforePaste = useEffectEvent((e: ClipboardEvent) => {\n // Unfortunately, e.clipboardData.types is not available in this event so we always\n // have to enable the Paste menu item even if the type of data is unsupported.\n if (isFocusedRef.current && options.onPaste) {\n e.preventDefault();\n }\n });\n\n let onPaste = useEffectEvent((e: ClipboardEvent) => {\n if (!isFocusedRef.current || !options.onPaste) {\n return;\n }\n\n e.preventDefault();\n if (e.clipboardData) {\n let items = readFromDataTransfer(e.clipboardData);\n options.onPaste(items);\n }\n });\n\n useEffect(() => {\n if (isDisabled) {\n return;\n }\n return chain(\n addGlobalEventListener('beforecopy', onBeforeCopy),\n addGlobalEventListener('copy', onCopy),\n addGlobalEventListener('beforecut', onBeforeCut),\n addGlobalEventListener('cut', onCut),\n addGlobalEventListener('beforepaste', onBeforePaste),\n addGlobalEventListener('paste', onPaste)\n );\n }, [isDisabled, onBeforeCopy, onCopy, onBeforeCut, onCut, onBeforePaste, onPaste]);\n\n return {\n clipboardProps: focusProps\n };\n}\n"],"names":[],"version":3,"file":"useClipboard.module.js.map"}
|
package/dist/useDrag.main.js
CHANGED
|
@@ -94,6 +94,7 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
|
|
|
94
94
|
// If there is a preview option, use it to render a custom preview image that will
|
|
95
95
|
// appear under the pointer while dragging. If not, the element itself is dragged by the browser.
|
|
96
96
|
if (typeof ((_options_preview = options.preview) === null || _options_preview === void 0 ? void 0 : _options_preview.current) === 'function') options.preview.current(items, (node)=>{
|
|
97
|
+
if (!node) return;
|
|
97
98
|
// Compute the offset that the preview will appear under the mouse.
|
|
98
99
|
// If possible, this is based on the point the user clicked on the target.
|
|
99
100
|
// If the preview is much smaller, then just use the center point of the preview.
|
|
@@ -160,7 +161,6 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
|
|
|
160
161
|
};
|
|
161
162
|
// If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801
|
|
162
163
|
// In this case, we need to manually call onDragEnd on cleanup
|
|
163
|
-
// eslint-disable-next-line arrow-body-style
|
|
164
164
|
(0, $3w36N$reactariautils.useLayoutEffect)(()=>{
|
|
165
165
|
return ()=>{
|
|
166
166
|
if (isDraggingRef.current) {
|
|
@@ -212,7 +212,7 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
|
|
|
212
212
|
let modality = (0, $4620ae0dc40f0031$exports.useDragModality)();
|
|
213
213
|
let message = !isDragging ? $dc204e8ec58447a6$var$MESSAGES[modality].start : $dc204e8ec58447a6$var$MESSAGES[modality].end;
|
|
214
214
|
let descriptionProps = (0, $3w36N$reactariautils.useDescription)(stringFormatter.format(message));
|
|
215
|
-
let interactions;
|
|
215
|
+
let interactions = {};
|
|
216
216
|
if (!hasDragButton) // If there's no separate button to trigger accessible drag and drop mode,
|
|
217
217
|
// then add event handlers to the draggable element itself to start dragging.
|
|
218
218
|
// For keyboard, we use the Enter key in a capturing listener to prevent other
|
package/dist/useDrag.main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA8CD,MAAM,iCAAW;IACf,UAAU;QACR,OAAO;QACP,KAAK;IACP;IACA,OAAO;QACL,OAAO;QACP,KAAK;IACP;IACA,SAAS;QACP,OAAO;QACP,KAAK;IACP;AACF;AAMO,SAAS,0CAAQ,OAAoB;IAC1C,IAAI,iBAAC,aAAa,cAAE,UAAU,EAAC,GAAG;IAClC,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAE;iBACjB;QACA,GAAG;QACH,GAAG;IACL,GAAG,OAAO;IACV,MAAM,OAAO,GAAG;IAChB,IAAI,gBAAgB,CAAA,GAAA,mBAAK,EAAE;IAC3B,IAAI,CAAC,YAAY,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC9C,IAAI,cAAc,CAAC;QACjB,cAAc,OAAO,GAAG;QACxB,iBAAiB;IACnB;IACA,IAAI,qBAAC,iBAAiB,4BAAE,wBAAwB,EAAC,GAAG,CAAA,GAAA,wCAAiB;IACrE,IAAI,wBAAwB,CAAA,GAAA,mBAAK,EAAU;IAE3C,IAAI,cAAc,CAAC;YAyCN;QAxCX,IAAI,EAAE,gBAAgB,EACpB;QAGF,mEAAmE;QACnE,EAAE,eAAe;QAEjB,kHAAkH;QAClH,IAAI,sBAAsB,OAAO,KAAK,WAAW;YAC/C,EAAE,cAAc;YAChB,cAAc,EAAE,MAAM;YACtB,sBAAsB,OAAO,GAAG;YAChC;QACF;QAEA,IAAI,OAAO,QAAQ,WAAW,KAAK,YACjC,QAAQ,WAAW,CAAC;YAClB,MAAM;YACN,GAAG,EAAE,OAAO;YACZ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G,IAAI,CAAA,GAAA,oCAAa,EAAE,EAAE,WAAW,KAAK,sBAAsB,OAAO,KAAK,WAAW;gBAChF,EAAE,cAAc;gBAChB,EAAE,eAAe;gBACjB,cAAc,EAAE,MAAM;YACxB;QACF;IACF;IAGF,IAAI,YACF,OAAO;QACL,WAAW;YACT,WAAW;QACb;QACA,iBAAiB,CAAC;QAClB,YAAY;IACd;IAGF,OAAO;QACL,WAAW;YACT,GAAG,YAAY;YACf,WAAW;yBACX;oBACA;uBACA;QACF;QACA,iBAAiB;YACf,GAAG,gBAAgB;qBACnB;QACF;oBACA;IACF;AACF","sources":["packages/@react-aria/dnd/src/useDrag.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 {DragEndEvent, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, PressEvent, RefObject} from '@react-types/shared';\nimport {DragEvent, HTMLAttributes, useRef, useState} from 'react';\nimport * as DragManager from './DragManager';\nimport {DROP_EFFECT_TO_DROP_OPERATION, DROP_OPERATION, EFFECT_ALLOWED} from './constants';\nimport {globalDropEffect, setGlobalAllowedDropOperations, setGlobalDropEffect, useDragModality, writeToDataTransfer} from './utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {isVirtualClick, isVirtualPointerEvent, useDescription, useGlobalListeners, useLayoutEffect} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface DragOptions {\n /** Handler that is called when a drag operation is started. */\n onDragStart?: (e: DragStartEvent) => void,\n /** Handler that is called when the drag is moved. */\n onDragMove?: (e: DragMoveEvent) => void,\n /** Handler that is called when the drag operation is ended, either as a result of a drop or a cancellation. */\n onDragEnd?: (e: DragEndEvent) => void,\n /** A function that returns the items being dragged. */\n getItems: () => DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer | null>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\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 drag operation is disabled. If true, the element will not be draggable.\n */\n isDisabled?: boolean\n}\n\nexport interface DragResult {\n /** Props for the draggable element. */\n dragProps: HTMLAttributes<HTMLElement>,\n /** Props for the explicit drag button affordance, if any. */\n dragButtonProps: AriaButtonProps,\n /** Whether the element is currently being dragged. */\n isDragging: boolean\n}\n\nconst MESSAGES = {\n keyboard: {\n start: 'dragDescriptionKeyboard',\n end: 'endDragKeyboard'\n },\n touch: {\n start: 'dragDescriptionTouch',\n end: 'endDragTouch'\n },\n virtual: {\n start: 'dragDescriptionVirtual',\n end: 'endDragVirtual'\n }\n};\n\n/**\n * Handles drag 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 useDrag(options: DragOptions): DragResult {\n let {hasDragButton, isDisabled} = options;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let state = useRef({\n options,\n x: 0,\n y: 0\n }).current;\n state.options = options;\n let isDraggingRef = useRef(false);\n let [isDragging, setDraggingState] = useState(false);\n let setDragging = (isDragging) => {\n isDraggingRef.current = isDragging;\n setDraggingState(isDragging);\n };\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n let modalityOnPointerDown = useRef<string>(null);\n\n let onDragStart = (e: DragEvent) => {\n if (e.defaultPrevented) {\n return;\n }\n\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n // If this drag was initiated by a mobile screen reader (e.g. VoiceOver or TalkBack), enter virtual dragging mode.\n if (modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n startDragging(e.target as HTMLElement);\n modalityOnPointerDown.current = null;\n return;\n }\n\n if (typeof options.onDragStart === 'function') {\n options.onDragStart({\n type: 'dragstart',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n let items = options.getItems();\n writeToDataTransfer(e.dataTransfer, items);\n\n let allowed = DROP_OPERATION.all;\n if (typeof options.getAllowedDropOperations === 'function') {\n let allowedOperations = options.getAllowedDropOperations();\n allowed = DROP_OPERATION.none;\n for (let operation of allowedOperations) {\n allowed |= DROP_OPERATION[operation] || DROP_OPERATION.none;\n }\n }\n\n setGlobalAllowedDropOperations(allowed);\n e.dataTransfer.effectAllowed = EFFECT_ALLOWED[allowed] || 'none';\n\n // If there is a preview option, use it to render a custom preview image that will\n // appear under the pointer while dragging. If not, the element itself is dragged by the browser.\n if (typeof options.preview?.current === 'function') {\n options.preview.current(items, node => {\n // Compute the offset that the preview will appear under the mouse.\n // If possible, this is based on the point the user clicked on the target.\n // If the preview is much smaller, then just use the center point of the preview.\n let size = node.getBoundingClientRect();\n let rect = e.currentTarget.getBoundingClientRect();\n let x = e.clientX - rect.x;\n let y = e.clientY - rect.y;\n if (x > size.width || y > size.height) {\n x = size.width / 2;\n y = size.height / 2;\n }\n\n // Rounding height to an even number prevents blurry preview seen on some screens\n let height = 2 * Math.round(size.height / 2);\n node.style.height = `${height}px`;\n\n e.dataTransfer.setDragImage(node, x, y);\n });\n }\n\n // Enforce that drops are handled by useDrop.\n addGlobalListener(window, 'drop', e => {\n e.preventDefault();\n e.stopPropagation();\n console.warn('Drags initiated from the React Aria useDrag hook may only be dropped on a target created with useDrop. This ensures that a keyboard and screen reader accessible alternative is available.');\n }, {once: true});\n state.x = e.clientX;\n state.y = e.clientY;\n\n // Wait a frame before we set dragging to true so that the browser has time to\n // render the preview image before we update the element that has been dragged.\n requestAnimationFrame(() => {\n setDragging(true);\n });\n };\n\n let onDrag = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (e.clientX === state.x && e.clientY === state.y) {\n return;\n }\n\n if (typeof options.onDragMove === 'function') {\n options.onDragMove({\n type: 'dragmove',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n state.x = e.clientX;\n state.y = e.clientY;\n };\n\n let onDragEnd = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (typeof options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: e.clientX,\n y: e.clientY,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[e.dataTransfer.dropEffect]\n };\n\n // Chrome Android always returns none as its dropEffect so we use the drop effect set in useDrop via\n // onDragEnter/onDragOver instead. https://bugs.chromium.org/p/chromium/issues/detail?id=1353951\n if (globalDropEffect) {\n event.dropOperation = DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect];\n }\n options.onDragEnd(event);\n }\n\n setDragging(false);\n removeAllGlobalListeners();\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n };\n\n // If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801\n // In this case, we need to manually call onDragEnd on cleanup\n // eslint-disable-next-line arrow-body-style\n useLayoutEffect(() => {\n return () => {\n if (isDraggingRef.current) {\n if (typeof state.options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: 0,\n y: 0,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect || 'none']\n };\n state.options.onDragEnd(event);\n }\n\n setDragging(false);\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n }\n };\n }, [state]);\n\n let onPress = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard' && e.pointerType !== 'virtual') {\n return;\n }\n\n startDragging(e.target as HTMLElement);\n };\n\n let startDragging = (target: HTMLElement) => {\n if (typeof state.options.onDragStart === 'function') {\n let rect = target.getBoundingClientRect();\n state.options.onDragStart({\n type: 'dragstart',\n x: rect.x + (rect.width / 2),\n y: rect.y + (rect.height / 2)\n });\n }\n\n DragManager.beginDragging({\n element: target,\n items: state.options.getItems(),\n allowedDropOperations: typeof state.options.getAllowedDropOperations === 'function'\n ? state.options.getAllowedDropOperations()\n : ['move', 'copy', 'link'],\n onDragEnd(e) {\n setDragging(false);\n if (typeof state.options.onDragEnd === 'function') {\n state.options.onDragEnd(e);\n }\n }\n }, stringFormatter);\n\n setDragging(true);\n };\n\n let modality = useDragModality();\n let message = !isDragging ? MESSAGES[modality].start : MESSAGES[modality].end;\n\n let descriptionProps = useDescription(stringFormatter.format(message));\n\n let interactions: HTMLAttributes<HTMLElement>;\n if (!hasDragButton) {\n // If there's no separate button to trigger accessible drag and drop mode,\n // then add event handlers to the draggable element itself to start dragging.\n // For keyboard, we use the Enter key in a capturing listener to prevent other\n // events such as selection from also occurring. We attempt to infer whether a\n // pointer event (e.g. long press) came from a touch screen reader, and then initiate\n // dragging in the native onDragStart listener above.\n\n interactions = {\n ...descriptionProps,\n onPointerDown(e) {\n modalityOnPointerDown.current = isVirtualPointerEvent(e.nativeEvent) ? 'virtual' : e.pointerType;\n\n // Try to detect virtual drag passthrough gestures.\n if (e.width < 1 && e.height < 1) {\n // iOS VoiceOver.\n modalityOnPointerDown.current = 'virtual';\n } else {\n let rect = e.currentTarget.getBoundingClientRect();\n let offsetX = e.clientX - rect.x;\n let offsetY = e.clientY - rect.y;\n let centerX = rect.width / 2;\n let centerY = rect.height / 2;\n\n if (Math.abs(offsetX - centerX) <= 0.5 && Math.abs(offsetY - centerY) <= 0.5) {\n // Android TalkBack.\n modalityOnPointerDown.current = 'virtual';\n } else {\n modalityOnPointerDown.current = e.pointerType;\n }\n }\n },\n onKeyDownCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n },\n onKeyUpCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n },\n onClick(e) {\n // Handle NVDA/JAWS in browse mode, and touch screen readers. In this case, no keyboard events are fired.\n if (isVirtualClick(e.nativeEvent) || modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n }\n };\n }\n\n if (isDisabled) {\n return {\n dragProps: {\n draggable: 'false'\n },\n dragButtonProps: {},\n isDragging: false\n };\n }\n\n return {\n dragProps: {\n ...interactions,\n draggable: 'true',\n onDragStart,\n onDrag,\n onDragEnd\n },\n dragButtonProps: {\n ...descriptionProps,\n onPress\n },\n isDragging\n };\n}\n"],"names":[],"version":3,"file":"useDrag.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA8CD,MAAM,iCAAW;IACf,UAAU;QACR,OAAO;QACP,KAAK;IACP;IACA,OAAO;QACL,OAAO;QACP,KAAK;IACP;IACA,SAAS;QACP,OAAO;QACP,KAAK;IACP;AACF;AAMO,SAAS,0CAAQ,OAAoB;IAC1C,IAAI,iBAAC,aAAa,cAAE,UAAU,EAAC,GAAG;IAClC,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAE;iBACjB;QACA,GAAG;QACH,GAAG;IACL,GAAG,OAAO;IACV,MAAM,OAAO,GAAG;IAChB,IAAI,gBAAgB,CAAA,GAAA,mBAAK,EAAE;IAC3B,IAAI,CAAC,YAAY,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC9C,IAAI,cAAc,CAAC;QACjB,cAAc,OAAO,GAAG;QACxB,iBA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AAU,YAAY,OAAO,KAAK,GAAG,CAAC,UAAU,YAAY,KACvE,oBAAoB;gBACpB,sBAAsB,OAAO,GAAG;qBAEhC,sBAAsB,OAAO,GAAG,EAAE,WAAW;YAEjD;QACF;QACA,kBAAiB,CAAC;YAChB,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,IAAI,EAAE,GAAG,KAAK,SAAS;gBACrD,EAAE,cAAc;gBAChB,EAAE,eAAe;YACnB;QACF;QACA,gBAAe,CAAC;YACd,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,IAAI,EAAE,GAAG,KAAK,SAAS;gBACrD,EAAE,cAAc;gBAChB,EAAE,eAAe;gBACjB,cAAc,EAAE,MAAM;YACxB;QACF;QACA,SAAQ,CAAC;YACP,yGAAyG;YACzG,IAAI,CAAA,GAAA,oCAAa,EAAE,EAAE,WAAW,KAAK,sBAAsB,OAAO,KAAK,WAAW;gBAChF,EAAE,cAAc;gBAChB,EAAE,eAAe;gBACjB,cAAc,EAAE,MAAM;YACxB;QACF;IACF;IAGF,IAAI,YACF,OAAO;QACL,WAAW;YACT,WAAW;QACb;QACA,iBAAiB,CAAC;QAClB,YAAY;IACd;IAGF,OAAO;QACL,WAAW;YACT,GAAG,YAAY;YACf,WAAW;yBACX;oBACA;uBACA;QACF;QACA,iBAAiB;YACf,GAAG,gBAAgB;qBACnB;QACF;oBACA;IACF;AACF","sources":["packages/@react-aria/dnd/src/useDrag.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 {DragEndEvent, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, PressEvent, RefObject} from '@react-types/shared';\nimport {DragEvent, HTMLAttributes, useRef, useState} from 'react';\nimport * as DragManager from './DragManager';\nimport {DROP_EFFECT_TO_DROP_OPERATION, DROP_OPERATION, EFFECT_ALLOWED} from './constants';\nimport {globalDropEffect, setGlobalAllowedDropOperations, setGlobalDropEffect, useDragModality, writeToDataTransfer} from './utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {isVirtualClick, isVirtualPointerEvent, useDescription, useGlobalListeners, useLayoutEffect} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface DragOptions {\n /** Handler that is called when a drag operation is started. */\n onDragStart?: (e: DragStartEvent) => void,\n /** Handler that is called when the drag is moved. */\n onDragMove?: (e: DragMoveEvent) => void,\n /** Handler that is called when the drag operation is ended, either as a result of a drop or a cancellation. */\n onDragEnd?: (e: DragEndEvent) => void,\n /** A function that returns the items being dragged. */\n getItems: () => DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer | null>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\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 drag operation is disabled. If true, the element will not be draggable.\n */\n isDisabled?: boolean\n}\n\nexport interface DragResult {\n /** Props for the draggable element. */\n dragProps: HTMLAttributes<HTMLElement>,\n /** Props for the explicit drag button affordance, if any. */\n dragButtonProps: AriaButtonProps,\n /** Whether the element is currently being dragged. */\n isDragging: boolean\n}\n\nconst MESSAGES = {\n keyboard: {\n start: 'dragDescriptionKeyboard',\n end: 'endDragKeyboard'\n },\n touch: {\n start: 'dragDescriptionTouch',\n end: 'endDragTouch'\n },\n virtual: {\n start: 'dragDescriptionVirtual',\n end: 'endDragVirtual'\n }\n};\n\n/**\n * Handles drag 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 useDrag(options: DragOptions): DragResult {\n let {hasDragButton, isDisabled} = options;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let state = useRef({\n options,\n x: 0,\n y: 0\n }).current;\n state.options = options;\n let isDraggingRef = useRef(false);\n let [isDragging, setDraggingState] = useState(false);\n let setDragging = (isDragging) => {\n isDraggingRef.current = isDragging;\n setDraggingState(isDragging);\n };\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n let modalityOnPointerDown = useRef<string>(null);\n\n let onDragStart = (e: DragEvent) => {\n if (e.defaultPrevented) {\n return;\n }\n\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n // If this drag was initiated by a mobile screen reader (e.g. VoiceOver or TalkBack), enter virtual dragging mode.\n if (modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n startDragging(e.target as HTMLElement);\n modalityOnPointerDown.current = null;\n return;\n }\n\n if (typeof options.onDragStart === 'function') {\n options.onDragStart({\n type: 'dragstart',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n let items = options.getItems();\n writeToDataTransfer(e.dataTransfer, items);\n\n let allowed = DROP_OPERATION.all;\n if (typeof options.getAllowedDropOperations === 'function') {\n let allowedOperations = options.getAllowedDropOperations();\n allowed = DROP_OPERATION.none;\n for (let operation of allowedOperations) {\n allowed |= DROP_OPERATION[operation] || DROP_OPERATION.none;\n }\n }\n\n setGlobalAllowedDropOperations(allowed);\n e.dataTransfer.effectAllowed = EFFECT_ALLOWED[allowed] || 'none';\n\n // If there is a preview option, use it to render a custom preview image that will\n // appear under the pointer while dragging. If not, the element itself is dragged by the browser.\n if (typeof options.preview?.current === 'function') {\n options.preview.current(items, node => {\n if (!node) {\n return;\n }\n // Compute the offset that the preview will appear under the mouse.\n // If possible, this is based on the point the user clicked on the target.\n // If the preview is much smaller, then just use the center point of the preview.\n let size = node.getBoundingClientRect();\n let rect = e.currentTarget.getBoundingClientRect();\n let x = e.clientX - rect.x;\n let y = e.clientY - rect.y;\n if (x > size.width || y > size.height) {\n x = size.width / 2;\n y = size.height / 2;\n }\n\n // Rounding height to an even number prevents blurry preview seen on some screens\n let height = 2 * Math.round(size.height / 2);\n node.style.height = `${height}px`;\n\n e.dataTransfer.setDragImage(node, x, y);\n });\n }\n\n // Enforce that drops are handled by useDrop.\n addGlobalListener(window, 'drop', e => {\n e.preventDefault();\n e.stopPropagation();\n console.warn('Drags initiated from the React Aria useDrag hook may only be dropped on a target created with useDrop. This ensures that a keyboard and screen reader accessible alternative is available.');\n }, {once: true});\n state.x = e.clientX;\n state.y = e.clientY;\n\n // Wait a frame before we set dragging to true so that the browser has time to\n // render the preview image before we update the element that has been dragged.\n requestAnimationFrame(() => {\n setDragging(true);\n });\n };\n\n let onDrag = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (e.clientX === state.x && e.clientY === state.y) {\n return;\n }\n\n if (typeof options.onDragMove === 'function') {\n options.onDragMove({\n type: 'dragmove',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n state.x = e.clientX;\n state.y = e.clientY;\n };\n\n let onDragEnd = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (typeof options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: e.clientX,\n y: e.clientY,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[e.dataTransfer.dropEffect]\n };\n\n // Chrome Android always returns none as its dropEffect so we use the drop effect set in useDrop via\n // onDragEnter/onDragOver instead. https://bugs.chromium.org/p/chromium/issues/detail?id=1353951\n if (globalDropEffect) {\n event.dropOperation = DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect];\n }\n options.onDragEnd(event);\n }\n\n setDragging(false);\n removeAllGlobalListeners();\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n };\n\n // If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801\n // In this case, we need to manually call onDragEnd on cleanup\n \n useLayoutEffect(() => {\n return () => {\n if (isDraggingRef.current) {\n if (typeof state.options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: 0,\n y: 0,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect || 'none']\n };\n state.options.onDragEnd(event);\n }\n\n setDragging(false);\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n }\n };\n }, [state]);\n\n let onPress = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard' && e.pointerType !== 'virtual') {\n return;\n }\n\n startDragging(e.target as HTMLElement);\n };\n\n let startDragging = (target: HTMLElement) => {\n if (typeof state.options.onDragStart === 'function') {\n let rect = target.getBoundingClientRect();\n state.options.onDragStart({\n type: 'dragstart',\n x: rect.x + (rect.width / 2),\n y: rect.y + (rect.height / 2)\n });\n }\n\n DragManager.beginDragging({\n element: target,\n items: state.options.getItems(),\n allowedDropOperations: typeof state.options.getAllowedDropOperations === 'function'\n ? state.options.getAllowedDropOperations()\n : ['move', 'copy', 'link'],\n onDragEnd(e) {\n setDragging(false);\n if (typeof state.options.onDragEnd === 'function') {\n state.options.onDragEnd(e);\n }\n }\n }, stringFormatter);\n\n setDragging(true);\n };\n\n let modality = useDragModality();\n let message = !isDragging ? MESSAGES[modality].start : MESSAGES[modality].end;\n\n let descriptionProps = useDescription(stringFormatter.format(message));\n\n let interactions: HTMLAttributes<HTMLElement> = {};\n if (!hasDragButton) {\n // If there's no separate button to trigger accessible drag and drop mode,\n // then add event handlers to the draggable element itself to start dragging.\n // For keyboard, we use the Enter key in a capturing listener to prevent other\n // events such as selection from also occurring. We attempt to infer whether a\n // pointer event (e.g. long press) came from a touch screen reader, and then initiate\n // dragging in the native onDragStart listener above.\n\n interactions = {\n ...descriptionProps,\n onPointerDown(e) {\n modalityOnPointerDown.current = isVirtualPointerEvent(e.nativeEvent) ? 'virtual' : e.pointerType;\n\n // Try to detect virtual drag passthrough gestures.\n if (e.width < 1 && e.height < 1) {\n // iOS VoiceOver.\n modalityOnPointerDown.current = 'virtual';\n } else {\n let rect = e.currentTarget.getBoundingClientRect();\n let offsetX = e.clientX - rect.x;\n let offsetY = e.clientY - rect.y;\n let centerX = rect.width / 2;\n let centerY = rect.height / 2;\n\n if (Math.abs(offsetX - centerX) <= 0.5 && Math.abs(offsetY - centerY) <= 0.5) {\n // Android TalkBack.\n modalityOnPointerDown.current = 'virtual';\n } else {\n modalityOnPointerDown.current = e.pointerType;\n }\n }\n },\n onKeyDownCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n },\n onKeyUpCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n },\n onClick(e) {\n // Handle NVDA/JAWS in browse mode, and touch screen readers. In this case, no keyboard events are fired.\n if (isVirtualClick(e.nativeEvent) || modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n }\n };\n }\n\n if (isDisabled) {\n return {\n dragProps: {\n draggable: 'false'\n },\n dragButtonProps: {},\n isDragging: false\n };\n }\n\n return {\n dragProps: {\n ...interactions,\n draggable: 'true',\n onDragStart,\n onDrag,\n onDragEnd\n },\n dragButtonProps: {\n ...descriptionProps,\n onPress\n },\n isDragging\n };\n}\n"],"names":[],"version":3,"file":"useDrag.main.js.map"}
|
package/dist/useDrag.mjs
CHANGED
|
@@ -88,6 +88,7 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
|
|
|
88
88
|
// If there is a preview option, use it to render a custom preview image that will
|
|
89
89
|
// appear under the pointer while dragging. If not, the element itself is dragged by the browser.
|
|
90
90
|
if (typeof ((_options_preview = options.preview) === null || _options_preview === void 0 ? void 0 : _options_preview.current) === 'function') options.preview.current(items, (node)=>{
|
|
91
|
+
if (!node) return;
|
|
91
92
|
// Compute the offset that the preview will appear under the mouse.
|
|
92
93
|
// If possible, this is based on the point the user clicked on the target.
|
|
93
94
|
// If the preview is much smaller, then just use the center point of the preview.
|
|
@@ -154,7 +155,6 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
|
|
|
154
155
|
};
|
|
155
156
|
// If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801
|
|
156
157
|
// In this case, we need to manually call onDragEnd on cleanup
|
|
157
|
-
// eslint-disable-next-line arrow-body-style
|
|
158
158
|
(0, $72Evg$useLayoutEffect)(()=>{
|
|
159
159
|
return ()=>{
|
|
160
160
|
if (isDraggingRef.current) {
|
|
@@ -206,7 +206,7 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
|
|
|
206
206
|
let modality = (0, $7252cd45fc48c07c$export$49bac5d6d4b352ea)();
|
|
207
207
|
let message = !isDragging ? $8253ed7ece74b463$var$MESSAGES[modality].start : $8253ed7ece74b463$var$MESSAGES[modality].end;
|
|
208
208
|
let descriptionProps = (0, $72Evg$useDescription)(stringFormatter.format(message));
|
|
209
|
-
let interactions;
|
|
209
|
+
let interactions = {};
|
|
210
210
|
if (!hasDragButton) // If there's no separate button to trigger accessible drag and drop mode,
|
|
211
211
|
// then add event handlers to the draggable element itself to start dragging.
|
|
212
212
|
// For keyboard, we use the Enter key in a capturing listener to prevent other
|
package/dist/useDrag.module.js
CHANGED
|
@@ -88,6 +88,7 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
|
|
|
88
88
|
// If there is a preview option, use it to render a custom preview image that will
|
|
89
89
|
// appear under the pointer while dragging. If not, the element itself is dragged by the browser.
|
|
90
90
|
if (typeof ((_options_preview = options.preview) === null || _options_preview === void 0 ? void 0 : _options_preview.current) === 'function') options.preview.current(items, (node)=>{
|
|
91
|
+
if (!node) return;
|
|
91
92
|
// Compute the offset that the preview will appear under the mouse.
|
|
92
93
|
// If possible, this is based on the point the user clicked on the target.
|
|
93
94
|
// If the preview is much smaller, then just use the center point of the preview.
|
|
@@ -154,7 +155,6 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
|
|
|
154
155
|
};
|
|
155
156
|
// If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801
|
|
156
157
|
// In this case, we need to manually call onDragEnd on cleanup
|
|
157
|
-
// eslint-disable-next-line arrow-body-style
|
|
158
158
|
(0, $72Evg$useLayoutEffect)(()=>{
|
|
159
159
|
return ()=>{
|
|
160
160
|
if (isDraggingRef.current) {
|
|
@@ -206,7 +206,7 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
|
|
|
206
206
|
let modality = (0, $7252cd45fc48c07c$export$49bac5d6d4b352ea)();
|
|
207
207
|
let message = !isDragging ? $8253ed7ece74b463$var$MESSAGES[modality].start : $8253ed7ece74b463$var$MESSAGES[modality].end;
|
|
208
208
|
let descriptionProps = (0, $72Evg$useDescription)(stringFormatter.format(message));
|
|
209
|
-
let interactions;
|
|
209
|
+
let interactions = {};
|
|
210
210
|
if (!hasDragButton) // If there's no separate button to trigger accessible drag and drop mode,
|
|
211
211
|
// then add event handlers to the draggable element itself to start dragging.
|
|
212
212
|
// For keyboard, we use the Enter key in a capturing listener to prevent other
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA8CD,MAAM,iCAAW;IACf,UAAU;QACR,OAAO;QACP,KAAK;IACP;IACA,OAAO;QACL,OAAO;QACP,KAAK;IACP;IACA,SAAS;QACP,OAAO;QACP,KAAK;IACP;AACF;AAMO,SAAS,0CAAQ,OAAoB;IAC1C,IAAI,iBAAC,aAAa,cAAE,U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/useDrag.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 {DragEndEvent, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, PressEvent, RefObject} from '@react-types/shared';\nimport {DragEvent, HTMLAttributes, useRef, useState} from 'react';\nimport * as DragManager from './DragManager';\nimport {DROP_EFFECT_TO_DROP_OPERATION, DROP_OPERATION, EFFECT_ALLOWED} from './constants';\nimport {globalDropEffect, setGlobalAllowedDropOperations, setGlobalDropEffect, useDragModality, writeToDataTransfer} from './utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {isVirtualClick, isVirtualPointerEvent, useDescription, useGlobalListeners, useLayoutEffect} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface DragOptions {\n /** Handler that is called when a drag operation is started. */\n onDragStart?: (e: DragStartEvent) => void,\n /** Handler that is called when the drag is moved. */\n onDragMove?: (e: DragMoveEvent) => void,\n /** Handler that is called when the drag operation is ended, either as a result of a drop or a cancellation. */\n onDragEnd?: (e: DragEndEvent) => void,\n /** A function that returns the items being dragged. */\n getItems: () => DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer | null>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\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 drag operation is disabled. If true, the element will not be draggable.\n */\n isDisabled?: boolean\n}\n\nexport interface DragResult {\n /** Props for the draggable element. */\n dragProps: HTMLAttributes<HTMLElement>,\n /** Props for the explicit drag button affordance, if any. */\n dragButtonProps: AriaButtonProps,\n /** Whether the element is currently being dragged. */\n isDragging: boolean\n}\n\nconst MESSAGES = {\n keyboard: {\n start: 'dragDescriptionKeyboard',\n end: 'endDragKeyboard'\n },\n touch: {\n start: 'dragDescriptionTouch',\n end: 'endDragTouch'\n },\n virtual: {\n start: 'dragDescriptionVirtual',\n end: 'endDragVirtual'\n }\n};\n\n/**\n * Handles drag 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 useDrag(options: DragOptions): DragResult {\n let {hasDragButton, isDisabled} = options;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let state = useRef({\n options,\n x: 0,\n y: 0\n }).current;\n state.options = options;\n let isDraggingRef = useRef(false);\n let [isDragging, setDraggingState] = useState(false);\n let setDragging = (isDragging) => {\n isDraggingRef.current = isDragging;\n setDraggingState(isDragging);\n };\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n let modalityOnPointerDown = useRef<string>(null);\n\n let onDragStart = (e: DragEvent) => {\n if (e.defaultPrevented) {\n return;\n }\n\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n // If this drag was initiated by a mobile screen reader (e.g. VoiceOver or TalkBack), enter virtual dragging mode.\n if (modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n startDragging(e.target as HTMLElement);\n modalityOnPointerDown.current = null;\n return;\n }\n\n if (typeof options.onDragStart === 'function') {\n options.onDragStart({\n type: 'dragstart',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n let items = options.getItems();\n writeToDataTransfer(e.dataTransfer, items);\n\n let allowed = DROP_OPERATION.all;\n if (typeof options.getAllowedDropOperations === 'function') {\n let allowedOperations = options.getAllowedDropOperations();\n allowed = DROP_OPERATION.none;\n for (let operation of allowedOperations) {\n allowed |= DROP_OPERATION[operation] || DROP_OPERATION.none;\n }\n }\n\n setGlobalAllowedDropOperations(allowed);\n e.dataTransfer.effectAllowed = EFFECT_ALLOWED[allowed] || 'none';\n\n // If there is a preview option, use it to render a custom preview image that will\n // appear under the pointer while dragging. If not, the element itself is dragged by the browser.\n if (typeof options.preview?.current === 'function') {\n options.preview.current(items, node => {\n // Compute the offset that the preview will appear under the mouse.\n // If possible, this is based on the point the user clicked on the target.\n // If the preview is much smaller, then just use the center point of the preview.\n let size = node.getBoundingClientRect();\n let rect = e.currentTarget.getBoundingClientRect();\n let x = e.clientX - rect.x;\n let y = e.clientY - rect.y;\n if (x > size.width || y > size.height) {\n x = size.width / 2;\n y = size.height / 2;\n }\n\n // Rounding height to an even number prevents blurry preview seen on some screens\n let height = 2 * Math.round(size.height / 2);\n node.style.height = `${height}px`;\n\n e.dataTransfer.setDragImage(node, x, y);\n });\n }\n\n // Enforce that drops are handled by useDrop.\n addGlobalListener(window, 'drop', e => {\n e.preventDefault();\n e.stopPropagation();\n console.warn('Drags initiated from the React Aria useDrag hook may only be dropped on a target created with useDrop. This ensures that a keyboard and screen reader accessible alternative is available.');\n }, {once: true});\n state.x = e.clientX;\n state.y = e.clientY;\n\n // Wait a frame before we set dragging to true so that the browser has time to\n // render the preview image before we update the element that has been dragged.\n requestAnimationFrame(() => {\n setDragging(true);\n });\n };\n\n let onDrag = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (e.clientX === state.x && e.clientY === state.y) {\n return;\n }\n\n if (typeof options.onDragMove === 'function') {\n options.onDragMove({\n type: 'dragmove',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n state.x = e.clientX;\n state.y = e.clientY;\n };\n\n let onDragEnd = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (typeof options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: e.clientX,\n y: e.clientY,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[e.dataTransfer.dropEffect]\n };\n\n // Chrome Android always returns none as its dropEffect so we use the drop effect set in useDrop via\n // onDragEnter/onDragOver instead. https://bugs.chromium.org/p/chromium/issues/detail?id=1353951\n if (globalDropEffect) {\n event.dropOperation = DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect];\n }\n options.onDragEnd(event);\n }\n\n setDragging(false);\n removeAllGlobalListeners();\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n };\n\n // If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801\n // In this case, we need to manually call onDragEnd on cleanup\n // eslint-disable-next-line arrow-body-style\n useLayoutEffect(() => {\n return () => {\n if (isDraggingRef.current) {\n if (typeof state.options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: 0,\n y: 0,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect || 'none']\n };\n state.options.onDragEnd(event);\n }\n\n setDragging(false);\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n }\n };\n }, [state]);\n\n let onPress = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard' && e.pointerType !== 'virtual') {\n return;\n }\n\n startDragging(e.target as HTMLElement);\n };\n\n let startDragging = (target: HTMLElement) => {\n if (typeof state.options.onDragStart === 'function') {\n let rect = target.getBoundingClientRect();\n state.options.onDragStart({\n type: 'dragstart',\n x: rect.x + (rect.width / 2),\n y: rect.y + (rect.height / 2)\n });\n }\n\n DragManager.beginDragging({\n element: target,\n items: state.options.getItems(),\n allowedDropOperations: typeof state.options.getAllowedDropOperations === 'function'\n ? state.options.getAllowedDropOperations()\n : ['move', 'copy', 'link'],\n onDragEnd(e) {\n setDragging(false);\n if (typeof state.options.onDragEnd === 'function') {\n state.options.onDragEnd(e);\n }\n }\n }, stringFormatter);\n\n setDragging(true);\n };\n\n let modality = useDragModality();\n let message = !isDragging ? MESSAGES[modality].start : MESSAGES[modality].end;\n\n let descriptionProps = useDescription(stringFormatter.format(message));\n\n let interactions: HTMLAttributes<HTMLElement>;\n if (!hasDragButton) {\n // If there's no separate button to trigger accessible drag and drop mode,\n // then add event handlers to the draggable element itself to start dragging.\n // For keyboard, we use the Enter key in a capturing listener to prevent other\n // events such as selection from also occurring. We attempt to infer whether a\n // pointer event (e.g. long press) came from a touch screen reader, and then initiate\n // dragging in the native onDragStart listener above.\n\n interactions = {\n ...descriptionProps,\n onPointerDown(e) {\n modalityOnPointerDown.current = isVirtualPointerEvent(e.nativeEvent) ? 'virtual' : e.pointerType;\n\n // Try to detect virtual drag passthrough gestures.\n if (e.width < 1 && e.height < 1) {\n // iOS VoiceOver.\n modalityOnPointerDown.current = 'virtual';\n } else {\n let rect = e.currentTarget.getBoundingClientRect();\n let offsetX = e.clientX - rect.x;\n let offsetY = e.clientY - rect.y;\n let centerX = rect.width / 2;\n let centerY = rect.height / 2;\n\n if (Math.abs(offsetX - centerX) <= 0.5 && Math.abs(offsetY - centerY) <= 0.5) {\n // Android TalkBack.\n modalityOnPointerDown.current = 'virtual';\n } else {\n modalityOnPointerDown.current = e.pointerType;\n }\n }\n },\n onKeyDownCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n },\n onKeyUpCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n },\n onClick(e) {\n // Handle NVDA/JAWS in browse mode, and touch screen readers. In this case, no keyboard events are fired.\n if (isVirtualClick(e.nativeEvent) || modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n }\n };\n }\n\n if (isDisabled) {\n return {\n dragProps: {\n draggable: 'false'\n },\n dragButtonProps: {},\n isDragging: false\n };\n }\n\n return {\n dragProps: {\n ...interactions,\n draggable: 'true',\n onDragStart,\n onDrag,\n onDragEnd\n },\n dragButtonProps: {\n ...descriptionProps,\n onPress\n },\n isDragging\n };\n}\n"],"names":[],"version":3,"file":"useDrag.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA8CD,MAAM,iCAAW;IACf,UAAU;QACR,OAAO;QACP,KAAK;IACP;IACA,OAAO;QACL,OAAO;QACP,KAAK;IACP;IACA,SAAS;QACP,OAAO;QACP,KAAK;IACP;AACF;AAMO,SAAS,0CAAQ,OAAoB;IAC1C,IAAI,iBAAC,aAAa,cAAE,UAAU,EAAC,GAAG;IAClC,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE;iBACjB;QACA,GAAG;QACH,GAAG;IACL,GAAG,OAAO;IACV,MAAM,OAAO,GAAG;IAChB,IAAI,gBAAgB,CAAA,GAAA,aAAK,EAAE;IAC3B,IAAI,CAAC,YAAY,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9C,IAAI,cAAc,CAAC;QACjB,cAAc,OAAO,GAAG;QACxB,iBAAiB;IACnB;IACA,IAAI,qBAAC,iBAAiB,4BAAE,wBAAwB,EAAC,GAAG,CAAA,GAAA,yBAAiB;IACrE,IAAI,wBAAwB,CAAA,GAAA,aAAK,EAAU;IAE3C,IAAI,cAAc,CAAC;YAyCN;QAxCX,IAAI,EAAE,gBAAgB,EACpB;QAGF,mEAAmE;QACnE,EAAE,eAAe;QAEjB,kHAAkH;QAClH,IAAI,sBAAsB,OAAO,KAAK,WAAW;YAC/C,EAAE,cAAc;YAChB,cAAc,EAAE,MAAM;YACtB,sBAAsB,OAAO,GAAG;YAChC;QACF;QAEA,IAAI,OAAO,QAAQ,WAAW,KAAK,YACjC,QA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gBACjB,cAAc,EAAE,MAAM;YACxB;QACF;QACA,SAAQ,CAAC;YACP,yGAAyG;YACzG,IAAI,CAAA,GAAA,qBAAa,EAAE,EAAE,WAAW,KAAK,sBAAsB,OAAO,KAAK,WAAW;gBAChF,EAAE,cAAc;gBAChB,EAAE,eAAe;gBACjB,cAAc,EAAE,MAAM;YACxB;QACF;IACF;IAGF,IAAI,YACF,OAAO;QACL,WAAW;YACT,WAAW;QACb;QACA,iBAAiB,CAAC;QAClB,YAAY;IACd;IAGF,OAAO;QACL,WAAW;YACT,GAAG,YAAY;YACf,WAAW;yBACX;oBACA;uBACA;QACF;QACA,iBAAiB;YACf,GAAG,gBAAgB;qBACnB;QACF;oBACA;IACF;AACF","sources":["packages/@react-aria/dnd/src/useDrag.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 {DragEndEvent, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, PressEvent, RefObject} from '@react-types/shared';\nimport {DragEvent, HTMLAttributes, useRef, useState} from 'react';\nimport * as DragManager from './DragManager';\nimport {DROP_EFFECT_TO_DROP_OPERATION, DROP_OPERATION, EFFECT_ALLOWED} from './constants';\nimport {globalDropEffect, setGlobalAllowedDropOperations, setGlobalDropEffect, useDragModality, writeToDataTransfer} from './utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {isVirtualClick, isVirtualPointerEvent, useDescription, useGlobalListeners, useLayoutEffect} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface DragOptions {\n /** Handler that is called when a drag operation is started. */\n onDragStart?: (e: DragStartEvent) => void,\n /** Handler that is called when the drag is moved. */\n onDragMove?: (e: DragMoveEvent) => void,\n /** Handler that is called when the drag operation is ended, either as a result of a drop or a cancellation. */\n onDragEnd?: (e: DragEndEvent) => void,\n /** A function that returns the items being dragged. */\n getItems: () => DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer | null>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\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 drag operation is disabled. If true, the element will not be draggable.\n */\n isDisabled?: boolean\n}\n\nexport interface DragResult {\n /** Props for the draggable element. */\n dragProps: HTMLAttributes<HTMLElement>,\n /** Props for the explicit drag button affordance, if any. */\n dragButtonProps: AriaButtonProps,\n /** Whether the element is currently being dragged. */\n isDragging: boolean\n}\n\nconst MESSAGES = {\n keyboard: {\n start: 'dragDescriptionKeyboard',\n end: 'endDragKeyboard'\n },\n touch: {\n start: 'dragDescriptionTouch',\n end: 'endDragTouch'\n },\n virtual: {\n start: 'dragDescriptionVirtual',\n end: 'endDragVirtual'\n }\n};\n\n/**\n * Handles drag 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 useDrag(options: DragOptions): DragResult {\n let {hasDragButton, isDisabled} = options;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let state = useRef({\n options,\n x: 0,\n y: 0\n }).current;\n state.options = options;\n let isDraggingRef = useRef(false);\n let [isDragging, setDraggingState] = useState(false);\n let setDragging = (isDragging) => {\n isDraggingRef.current = isDragging;\n setDraggingState(isDragging);\n };\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n let modalityOnPointerDown = useRef<string>(null);\n\n let onDragStart = (e: DragEvent) => {\n if (e.defaultPrevented) {\n return;\n }\n\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n // If this drag was initiated by a mobile screen reader (e.g. VoiceOver or TalkBack), enter virtual dragging mode.\n if (modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n startDragging(e.target as HTMLElement);\n modalityOnPointerDown.current = null;\n return;\n }\n\n if (typeof options.onDragStart === 'function') {\n options.onDragStart({\n type: 'dragstart',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n let items = options.getItems();\n writeToDataTransfer(e.dataTransfer, items);\n\n let allowed = DROP_OPERATION.all;\n if (typeof options.getAllowedDropOperations === 'function') {\n let allowedOperations = options.getAllowedDropOperations();\n allowed = DROP_OPERATION.none;\n for (let operation of allowedOperations) {\n allowed |= DROP_OPERATION[operation] || DROP_OPERATION.none;\n }\n }\n\n setGlobalAllowedDropOperations(allowed);\n e.dataTransfer.effectAllowed = EFFECT_ALLOWED[allowed] || 'none';\n\n // If there is a preview option, use it to render a custom preview image that will\n // appear under the pointer while dragging. If not, the element itself is dragged by the browser.\n if (typeof options.preview?.current === 'function') {\n options.preview.current(items, node => {\n if (!node) {\n return;\n }\n // Compute the offset that the preview will appear under the mouse.\n // If possible, this is based on the point the user clicked on the target.\n // If the preview is much smaller, then just use the center point of the preview.\n let size = node.getBoundingClientRect();\n let rect = e.currentTarget.getBoundingClientRect();\n let x = e.clientX - rect.x;\n let y = e.clientY - rect.y;\n if (x > size.width || y > size.height) {\n x = size.width / 2;\n y = size.height / 2;\n }\n\n // Rounding height to an even number prevents blurry preview seen on some screens\n let height = 2 * Math.round(size.height / 2);\n node.style.height = `${height}px`;\n\n e.dataTransfer.setDragImage(node, x, y);\n });\n }\n\n // Enforce that drops are handled by useDrop.\n addGlobalListener(window, 'drop', e => {\n e.preventDefault();\n e.stopPropagation();\n console.warn('Drags initiated from the React Aria useDrag hook may only be dropped on a target created with useDrop. This ensures that a keyboard and screen reader accessible alternative is available.');\n }, {once: true});\n state.x = e.clientX;\n state.y = e.clientY;\n\n // Wait a frame before we set dragging to true so that the browser has time to\n // render the preview image before we update the element that has been dragged.\n requestAnimationFrame(() => {\n setDragging(true);\n });\n };\n\n let onDrag = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (e.clientX === state.x && e.clientY === state.y) {\n return;\n }\n\n if (typeof options.onDragMove === 'function') {\n options.onDragMove({\n type: 'dragmove',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n state.x = e.clientX;\n state.y = e.clientY;\n };\n\n let onDragEnd = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (typeof options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: e.clientX,\n y: e.clientY,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[e.dataTransfer.dropEffect]\n };\n\n // Chrome Android always returns none as its dropEffect so we use the drop effect set in useDrop via\n // onDragEnter/onDragOver instead. https://bugs.chromium.org/p/chromium/issues/detail?id=1353951\n if (globalDropEffect) {\n event.dropOperation = DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect];\n }\n options.onDragEnd(event);\n }\n\n setDragging(false);\n removeAllGlobalListeners();\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n };\n\n // If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801\n // In this case, we need to manually call onDragEnd on cleanup\n \n useLayoutEffect(() => {\n return () => {\n if (isDraggingRef.current) {\n if (typeof state.options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: 0,\n y: 0,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect || 'none']\n };\n state.options.onDragEnd(event);\n }\n\n setDragging(false);\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n }\n };\n }, [state]);\n\n let onPress = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard' && e.pointerType !== 'virtual') {\n return;\n }\n\n startDragging(e.target as HTMLElement);\n };\n\n let startDragging = (target: HTMLElement) => {\n if (typeof state.options.onDragStart === 'function') {\n let rect = target.getBoundingClientRect();\n state.options.onDragStart({\n type: 'dragstart',\n x: rect.x + (rect.width / 2),\n y: rect.y + (rect.height / 2)\n });\n }\n\n DragManager.beginDragging({\n element: target,\n items: state.options.getItems(),\n allowedDropOperations: typeof state.options.getAllowedDropOperations === 'function'\n ? state.options.getAllowedDropOperations()\n : ['move', 'copy', 'link'],\n onDragEnd(e) {\n setDragging(false);\n if (typeof state.options.onDragEnd === 'function') {\n state.options.onDragEnd(e);\n }\n }\n }, stringFormatter);\n\n setDragging(true);\n };\n\n let modality = useDragModality();\n let message = !isDragging ? MESSAGES[modality].start : MESSAGES[modality].end;\n\n let descriptionProps = useDescription(stringFormatter.format(message));\n\n let interactions: HTMLAttributes<HTMLElement> = {};\n if (!hasDragButton) {\n // If there's no separate button to trigger accessible drag and drop mode,\n // then add event handlers to the draggable element itself to start dragging.\n // For keyboard, we use the Enter key in a capturing listener to prevent other\n // events such as selection from also occurring. We attempt to infer whether a\n // pointer event (e.g. long press) came from a touch screen reader, and then initiate\n // dragging in the native onDragStart listener above.\n\n interactions = {\n ...descriptionProps,\n onPointerDown(e) {\n modalityOnPointerDown.current = isVirtualPointerEvent(e.nativeEvent) ? 'virtual' : e.pointerType;\n\n // Try to detect virtual drag passthrough gestures.\n if (e.width < 1 && e.height < 1) {\n // iOS VoiceOver.\n modalityOnPointerDown.current = 'virtual';\n } else {\n let rect = e.currentTarget.getBoundingClientRect();\n let offsetX = e.clientX - rect.x;\n let offsetY = e.clientY - rect.y;\n let centerX = rect.width / 2;\n let centerY = rect.height / 2;\n\n if (Math.abs(offsetX - centerX) <= 0.5 && Math.abs(offsetY - centerY) <= 0.5) {\n // Android TalkBack.\n modalityOnPointerDown.current = 'virtual';\n } else {\n modalityOnPointerDown.current = e.pointerType;\n }\n }\n },\n onKeyDownCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n },\n onKeyUpCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n },\n onClick(e) {\n // Handle NVDA/JAWS in browse mode, and touch screen readers. In this case, no keyboard events are fired.\n if (isVirtualClick(e.nativeEvent) || modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n }\n };\n }\n\n if (isDisabled) {\n return {\n dragProps: {\n draggable: 'false'\n },\n dragButtonProps: {},\n isDragging: false\n };\n }\n\n return {\n dragProps: {\n ...interactions,\n draggable: 'true',\n onDragStart,\n onDrag,\n onDragEnd\n },\n dragButtonProps: {\n ...descriptionProps,\n onPress\n },\n isDragging\n };\n}\n"],"names":[],"version":3,"file":"useDrag.module.js.map"}
|
package/dist/useDrop.main.js
CHANGED
|
@@ -37,7 +37,7 @@ function $1ca228bc9257ca16$export$ccdee5eaf73cf661(options) {
|
|
|
37
37
|
dragOverElements: new Set(),
|
|
38
38
|
dropEffect: 'none',
|
|
39
39
|
allowedOperations: (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).all,
|
|
40
|
-
dropActivateTimer:
|
|
40
|
+
dropActivateTimer: undefined
|
|
41
41
|
}).current;
|
|
42
42
|
let fireDropEnter = (e)=>{
|
|
43
43
|
setDropTarget(true);
|
|
@@ -102,10 +102,11 @@ function $1ca228bc9257ca16$export$ccdee5eaf73cf661(options) {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
clearTimeout(state.dropActivateTimer);
|
|
105
|
-
if (typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') {
|
|
105
|
+
if (options.onDropActivate && typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') {
|
|
106
|
+
let onDropActivateOptions = options.onDropActivate;
|
|
106
107
|
let rect = e.currentTarget.getBoundingClientRect();
|
|
107
108
|
state.dropActivateTimer = setTimeout(()=>{
|
|
108
|
-
|
|
109
|
+
onDropActivateOptions({
|
|
109
110
|
type: 'dropactivate',
|
|
110
111
|
x: state.x - rect.x,
|
|
111
112
|
y: state.y - rect.y
|
|
@@ -203,7 +204,7 @@ function $1ca228bc9257ca16$export$ccdee5eaf73cf661(options) {
|
|
|
203
204
|
});
|
|
204
205
|
let { ref: ref } = options;
|
|
205
206
|
(0, $AO99w$reactariautils.useLayoutEffect)(()=>{
|
|
206
|
-
if (isDisabled) return;
|
|
207
|
+
if (isDisabled || !ref.current) return;
|
|
207
208
|
return $28e10663603f5ea1$exports.registerDropTarget({
|
|
208
209
|
element: ref.current,
|
|
209
210
|
getDropOperation: getDropOperationKeyboard,
|
package/dist/useDrop.main.js.map
CHANGED
|
@@ -1 +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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F;IACpF,IAAI,mBAAmB,CAAA,GAAA,wCAAa,EAAE,IAAI;IAC1C,IAAI,CAAA,GAAA,2BAAI,KAAK;QACX,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, 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, RefObject} 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 | null>,\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"}
|
|
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,EAOd;QACD,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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BAAiC,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, 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, FocusableElement, DragTypes as IDragTypes, RefObject} 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<FocusableElement | null>,\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: number,\n y: number,\n dragOverElements: Set<Element>,\n dropEffect: DataTransfer['dropEffect'],\n allowedOperations: DROP_OPERATION,\n dropActivateTimer: ReturnType<typeof setTimeout> | undefined\n }>({\n x: 0,\n y: 0,\n dragOverElements: new Set<Element>(),\n dropEffect: 'none',\n allowedOperations: DROP_OPERATION.all,\n dropActivateTimer: undefined\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 (options.onDropActivate && typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') {\n let onDropActivateOptions = options.onDropActivate;\n let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();\n state.dropActivateTimer = setTimeout(() => {\n onDropActivateOptions({\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 || !ref.current) {\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: Array<DropOperation> = [];\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"}
|
package/dist/useDrop.mjs
CHANGED
|
@@ -31,7 +31,7 @@ function $5c06e4929e123553$export$ccdee5eaf73cf661(options) {
|
|
|
31
31
|
dragOverElements: new Set(),
|
|
32
32
|
dropEffect: 'none',
|
|
33
33
|
allowedOperations: (0, $103790afe9474d1c$export$60b7b4bcf3903d8e).all,
|
|
34
|
-
dropActivateTimer:
|
|
34
|
+
dropActivateTimer: undefined
|
|
35
35
|
}).current;
|
|
36
36
|
let fireDropEnter = (e)=>{
|
|
37
37
|
setDropTarget(true);
|
|
@@ -96,10 +96,11 @@ function $5c06e4929e123553$export$ccdee5eaf73cf661(options) {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
clearTimeout(state.dropActivateTimer);
|
|
99
|
-
if (typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') {
|
|
99
|
+
if (options.onDropActivate && typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') {
|
|
100
|
+
let onDropActivateOptions = options.onDropActivate;
|
|
100
101
|
let rect = e.currentTarget.getBoundingClientRect();
|
|
101
102
|
state.dropActivateTimer = setTimeout(()=>{
|
|
102
|
-
|
|
103
|
+
onDropActivateOptions({
|
|
103
104
|
type: 'dropactivate',
|
|
104
105
|
x: state.x - rect.x,
|
|
105
106
|
y: state.y - rect.y
|
|
@@ -197,7 +198,7 @@ function $5c06e4929e123553$export$ccdee5eaf73cf661(options) {
|
|
|
197
198
|
});
|
|
198
199
|
let { ref: ref } = options;
|
|
199
200
|
(0, $j5n4S$useLayoutEffect)(()=>{
|
|
200
|
-
if (isDisabled) return;
|
|
201
|
+
if (isDisabled || !ref.current) return;
|
|
201
202
|
return $67560de7c78cb232$export$c28d9fb4a54e471a({
|
|
202
203
|
element: ref.current,
|
|
203
204
|
getDropOperation: getDropOperationKeyboard,
|
package/dist/useDrop.module.js
CHANGED
|
@@ -31,7 +31,7 @@ function $5c06e4929e123553$export$ccdee5eaf73cf661(options) {
|
|
|
31
31
|
dragOverElements: new Set(),
|
|
32
32
|
dropEffect: 'none',
|
|
33
33
|
allowedOperations: (0, $103790afe9474d1c$export$60b7b4bcf3903d8e).all,
|
|
34
|
-
dropActivateTimer:
|
|
34
|
+
dropActivateTimer: undefined
|
|
35
35
|
}).current;
|
|
36
36
|
let fireDropEnter = (e)=>{
|
|
37
37
|
setDropTarget(true);
|
|
@@ -96,10 +96,11 @@ function $5c06e4929e123553$export$ccdee5eaf73cf661(options) {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
clearTimeout(state.dropActivateTimer);
|
|
99
|
-
if (typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') {
|
|
99
|
+
if (options.onDropActivate && typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') {
|
|
100
|
+
let onDropActivateOptions = options.onDropActivate;
|
|
100
101
|
let rect = e.currentTarget.getBoundingClientRect();
|
|
101
102
|
state.dropActivateTimer = setTimeout(()=>{
|
|
102
|
-
|
|
103
|
+
onDropActivateOptions({
|
|
103
104
|
type: 'dropactivate',
|
|
104
105
|
x: state.x - rect.x,
|
|
105
106
|
y: state.y - rect.y
|
|
@@ -197,7 +198,7 @@ function $5c06e4929e123553$export$ccdee5eaf73cf661(options) {
|
|
|
197
198
|
});
|
|
198
199
|
let { ref: ref } = options;
|
|
199
200
|
(0, $j5n4S$useLayoutEffect)(()=>{
|
|
200
|
-
if (isDisabled) return;
|
|
201
|
+
if (isDisabled || !ref.current) return;
|
|
201
202
|
return $67560de7c78cb232$export$c28d9fb4a54e471a({
|
|
202
203
|
element: ref.current,
|
|
203
204
|
getDropOperation: getDropOperationKeyboard,
|