@react-aria/dnd 3.9.3 → 3.10.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/dist/DragManager.main.js +79 -12
- package/dist/DragManager.main.js.map +1 -1
- package/dist/DragManager.mjs +79 -12
- package/dist/DragManager.module.js +79 -12
- package/dist/DragManager.module.js.map +1 -1
- package/dist/DropTargetKeyboardNavigation.main.js +201 -0
- package/dist/DropTargetKeyboardNavigation.main.js.map +1 -0
- package/dist/DropTargetKeyboardNavigation.mjs +196 -0
- package/dist/DropTargetKeyboardNavigation.module.js +196 -0
- package/dist/DropTargetKeyboardNavigation.module.js.map +1 -0
- package/dist/ListDropTargetDelegate.main.js.map +1 -1
- package/dist/ListDropTargetDelegate.module.js.map +1 -1
- package/dist/types.d.ts +7 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useDrop.main.js.map +1 -1
- package/dist/useDrop.module.js.map +1 -1
- package/dist/useDropIndicator.main.js +15 -7
- package/dist/useDropIndicator.main.js.map +1 -1
- package/dist/useDropIndicator.mjs +15 -7
- package/dist/useDropIndicator.module.js +15 -7
- package/dist/useDropIndicator.module.js.map +1 -1
- package/dist/useDroppableCollection.main.js +23 -98
- package/dist/useDroppableCollection.main.js.map +1 -1
- package/dist/useDroppableCollection.mjs +23 -98
- package/dist/useDroppableCollection.module.js +23 -98
- package/dist/useDroppableCollection.module.js.map +1 -1
- package/dist/useDroppableItem.main.js +4 -2
- package/dist/useDroppableItem.main.js.map +1 -1
- package/dist/useDroppableItem.mjs +4 -2
- package/dist/useDroppableItem.module.js +4 -2
- package/dist/useDroppableItem.module.js.map +1 -1
- package/package.json +17 -12
- package/src/.DS_Store +0 -0
- package/src/DragManager.ts +66 -17
- package/src/DropTargetKeyboardNavigation.ts +273 -0
- package/src/ListDropTargetDelegate.ts +1 -1
- package/src/useDrop.ts +0 -1
- package/src/useDropIndicator.ts +17 -11
- package/src/useDroppableCollection.ts +23 -123
- package/src/useDroppable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,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,oBAA0C,EAAE;IAChD,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 {DOMAttributes, DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropMoveEvent, DropOperation, FocusableElement, DragTypes as IDragTypes, RefObject} from '@react-types/shared';\nimport {DragEvent, 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 {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: DOMAttributes,\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"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAsDD,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,WAAW,KAAK,YAAY;YAC7C,IAAI,OAAO,AAAC,EAAE,aAAa,CAAiB,qBAAqB;YACjE,QAAQ,WAAW,CAAC;gBAClB,MAAM;gBACN,GAAG,EAAE,OAAO,GAAG,KAAK,CAAC;gBACrB,GAAG,EAAE,OAAO,GAAG,KAAK,CAAC;YACvB;QACF;IACF;IAEA,IAAI,eAAe,CAAC;QAClB,cAAc;QAEd,IAAI,OAAO,QAAQ,UAAU,KAAK,YAAY;YAC5C,IAAI,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,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,oBAA0C,EAAE;IAChD,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 {DOMAttributes, DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropMoveEvent, DropOperation, FocusableElement, DragTypes as IDragTypes, RefObject} from '@react-types/shared';\nimport {DragEvent, 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 {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 */\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: DOMAttributes,\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"}
|
|
@@ -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,eAAO,EAAE;IAC7C,IAAI,QAAQ,CAAA,GAAA,aAAK,EAOd;QACD,GAAG;QACH,GAAG;QACH,kBAAkB,IAAI;QACtB,YAAY;QACZ,mBAAmB,CAAA,GAAA,yCAAa,EA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B,CAAA,GAAA,yCAAa,EAAE,IAAI,EAC7C,kBAAkB,IAAI,CAAC;IAGzB,OAAO;AACT;AAEA,SAAS,uCAAiB,iBAAiC,EAAE,SAAwB;IACnF,IAAI,KAAK,CAAA,GAAA,yCAAa,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 {DOMAttributes, DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropMoveEvent, DropOperation, FocusableElement, DragTypes as IDragTypes, RefObject} from '@react-types/shared';\nimport {DragEvent, 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 {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: DOMAttributes,\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';\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AA,GAAA,yCAAa,EAAE,IAAI;QAGzC,IAAI,EAAE,OAAO,EACX,oBAAoB,CAAA,GAAA,yCAAa,EAAE,IAAI;IAE3C;IAEA,IAAI,kBACF,OAAO,oBAAoB;IAG7B,OAAO;AACT;AAEA,SAAS,+CAAyB,qBAAqC;IACrE,IAAI,oBAA0C,EAAE;IAChD,IAAI,wBAAwB,CAAA,GAAA,yCAAa,EAAE,IAAI,EAC7C,kBAAkB,IAAI,CAAC;IAGzB,IAAI,wBAAwB,CAAA,GAAA,yCAAa,EAAE,IAAI,EAC7C,kBAAkB,IAAI,CAAC;IAGzB,IAAI,wBAAwB,CAAA,GAAA,yCAAa,EAAE,IAAI,EAC7C,kBAAkB,IAAI,CAAC;IAGzB,OAAO;AACT;AAEA,SAAS,uCAAiB,iBAAiC,EAAE,SAAwB;IACnF,IAAI,KAAK,CAAA,GAAA,yCAAa,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 {DOMAttributes, DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropMoveEvent, DropOperation, FocusableElement, DragTypes as IDragTypes, RefObject} from '@react-types/shared';\nimport {DragEvent, 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 {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 */\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: DOMAttributes,\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.module.js.map"}
|
|
@@ -55,18 +55,26 @@ function $c5557edbed563ebf$export$8d0e41d2815afac5(props, state, ref) {
|
|
|
55
55
|
else {
|
|
56
56
|
let before;
|
|
57
57
|
let after;
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
if (target.dropPosition === 'before') {
|
|
59
|
+
var _collection_getItem;
|
|
60
|
+
let prevKey = (_collection_getItem = collection.getItem(target.key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.prevKey;
|
|
61
|
+
let prevNode = prevKey != null ? collection.getItem(prevKey) : null;
|
|
62
|
+
before = (prevNode === null || prevNode === void 0 ? void 0 : prevNode.type) === 'item' ? prevNode.key : null;
|
|
63
|
+
} else before = target.key;
|
|
64
|
+
if (target.dropPosition === 'after') {
|
|
65
|
+
var _collection_getItem1;
|
|
66
|
+
let nextKey = (_collection_getItem1 = collection.getItem(target.key)) === null || _collection_getItem1 === void 0 ? void 0 : _collection_getItem1.nextKey;
|
|
67
|
+
let nextNode = nextKey != null ? collection.getItem(nextKey) : null;
|
|
68
|
+
after = (nextNode === null || nextNode === void 0 ? void 0 : nextNode.type) === 'item' ? nextNode.key : null;
|
|
69
|
+
} else after = target.key;
|
|
70
|
+
if (before != null && after != null) label = stringFormatter.format('insertBetween', {
|
|
63
71
|
beforeItemText: getText(before),
|
|
64
72
|
afterItemText: getText(after)
|
|
65
73
|
});
|
|
66
|
-
else if (before) label = stringFormatter.format('insertAfter', {
|
|
74
|
+
else if (before != null) label = stringFormatter.format('insertAfter', {
|
|
67
75
|
itemText: getText(before)
|
|
68
76
|
});
|
|
69
|
-
else if (after) label = stringFormatter.format('insertBefore', {
|
|
77
|
+
else if (after != null) label = stringFormatter.format('insertBefore', {
|
|
70
78
|
itemText: getText(after)
|
|
71
79
|
});
|
|
72
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAmCM,SAAS,0CAAiB,KAAyB,EAAE,KAA+B,EAAE,GAAkC;IAC7H,IAAI,UAAC,MAAM,EAAC,GAAG;IACf,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,cAAc;IAClB,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,0CAAe,EAAE,OAAO,OAAO;IACjD,IAAI,KAAK,CAAA,GAAA,2BAAI;IACb,IAAI,UAAU,CAAC;YAIJ,0BAAkC;YAAlC,2BAAA;QAHT,IAAI,OAAO,MACT,OAAO;aAEP,OAAO,CAAA,OAAA,CAAA,6BAAA,2BAAA,WAAW,YAAY,cAAvB,+CAAA,8BAAA,YAA0B,kBAA1B,uCAAA,6BAAkC,sBAAA,WAAW,OAAO,CAAC,kBAAnB,0CAAA,oBAAyB,SAAS,cAApE,kBAAA,OAAwE;IAEnF;IAEA,IAAI,QAAQ;IACZ,IAAI;IACJ,IAAI,OAAO,IAAI,KAAK,QAAQ;QAC1B,QAAQ,gBAAgB,MAAM,CAAC;QAC/B,aAAa,GAAG,GAAG,CAAC,EA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AC/C,cAAc;YACd,mBAAmB;YACnB,eAAe;YACf,UAAU;QACZ;sBACA;QACA,qFAAqF;QACrF,yGAAyG;QACzG,0FAA0F;QAC1F,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC/B;AACF","sources":["packages/@react-aria/dnd/src/useDropIndicator.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 * as DragManager from './DragManager';\nimport {DroppableCollectionState} from '@react-stately/dnd';\nimport {DropTarget, FocusableElement, Key, RefObject} from '@react-types/shared';\nimport {getDroppableCollectionId} from './utils';\nimport {HTMLAttributes} from 'react';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useDroppableItem} from './useDroppableItem';\nimport {useId} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface DropIndicatorProps {\n /** The drop target that the drop indicator represents. */\n target: DropTarget,\n /** The ref to the activate button. */\n activateButtonRef?: RefObject<FocusableElement | null>\n}\n\nexport interface DropIndicatorAria {\n /** Props for the drop indicator element. */\n dropIndicatorProps: HTMLAttributes<HTMLElement>,\n /** Whether the drop indicator is currently the active drop target. */\n isDropTarget: boolean,\n /**\n * Whether the drop indicator is hidden, both visually and from assistive technology.\n * Use this to determine whether to omit the element from the DOM entirely.\n */\n isHidden: boolean\n}\n\n/**\n * Handles drop interactions for a target within a droppable collection.\n */\nexport function useDropIndicator(props: DropIndicatorProps, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>): DropIndicatorAria {\n let {target} = props;\n let {collection} = state;\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let dragSession = DragManager.useDragSession();\n let {dropProps} = useDroppableItem(props, state, ref);\n let id = useId();\n let getText = (key: Key | null) => {\n if (key == null) {\n return '';\n } else {\n return collection.getTextValue?.(key) ?? collection.getItem(key)?.textValue ?? '';\n }\n };\n\n let label = '';\n let labelledBy: string | undefined;\n if (target.type === 'root') {\n label = stringFormatter.format('dropOnRoot');\n labelledBy = `${id} ${getDroppableCollectionId(state)}`;\n } else if (target.dropPosition === 'on') {\n label = stringFormatter.format('dropOnItem', {\n itemText: getText(target.key)\n });\n } else {\n let before: Key | null | undefined;\n let after: Key | null | undefined;\n if (target.dropPosition === 'before') {\n let prevKey = collection.getItem(target.key)?.prevKey;\n let prevNode = prevKey != null ? collection.getItem(prevKey) : null;\n before = prevNode?.type === 'item' ? prevNode.key : null;\n } else {\n before = target.key;\n }\n\n if (target.dropPosition === 'after') {\n let nextKey = collection.getItem(target.key)?.nextKey;\n let nextNode = nextKey != null ? collection.getItem(nextKey) : null;\n after = nextNode?.type === 'item' ? nextNode.key : null;\n } else {\n after = target.key;\n }\n\n if (before != null && after != null) {\n label = stringFormatter.format('insertBetween', {\n beforeItemText: getText(before),\n afterItemText: getText(after)\n });\n } else if (before != null) {\n label = stringFormatter.format('insertAfter', {\n itemText: getText(before)\n });\n } else if (after != null) {\n label = stringFormatter.format('insertBefore', {\n itemText: getText(after)\n });\n }\n }\n\n let isDropTarget = state.isDropTarget(target);\n let ariaHidden = !dragSession ? 'true' : dropProps['aria-hidden'];\n return {\n dropIndicatorProps: {\n ...dropProps,\n id,\n 'aria-roledescription': stringFormatter.format('dropIndicator'),\n 'aria-label': label,\n 'aria-labelledby': labelledBy,\n 'aria-hidden': ariaHidden,\n tabIndex: -1\n },\n isDropTarget,\n // If aria-hidden, we are either not in a drag session or the drop target is invalid.\n // In that case, there's no need to render anything at all unless we need to show the indicator visually.\n // This can happen when dragging using the native DnD API as opposed to keyboard dragging.\n isHidden: !isDropTarget && !!ariaHidden\n };\n}\n"],"names":[],"version":3,"file":"useDropIndicator.main.js.map"}
|
|
@@ -49,18 +49,26 @@ function $ddf25448c71fc93a$export$8d0e41d2815afac5(props, state, ref) {
|
|
|
49
49
|
else {
|
|
50
50
|
let before;
|
|
51
51
|
let after;
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
if (target.dropPosition === 'before') {
|
|
53
|
+
var _collection_getItem;
|
|
54
|
+
let prevKey = (_collection_getItem = collection.getItem(target.key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.prevKey;
|
|
55
|
+
let prevNode = prevKey != null ? collection.getItem(prevKey) : null;
|
|
56
|
+
before = (prevNode === null || prevNode === void 0 ? void 0 : prevNode.type) === 'item' ? prevNode.key : null;
|
|
57
|
+
} else before = target.key;
|
|
58
|
+
if (target.dropPosition === 'after') {
|
|
59
|
+
var _collection_getItem1;
|
|
60
|
+
let nextKey = (_collection_getItem1 = collection.getItem(target.key)) === null || _collection_getItem1 === void 0 ? void 0 : _collection_getItem1.nextKey;
|
|
61
|
+
let nextNode = nextKey != null ? collection.getItem(nextKey) : null;
|
|
62
|
+
after = (nextNode === null || nextNode === void 0 ? void 0 : nextNode.type) === 'item' ? nextNode.key : null;
|
|
63
|
+
} else after = target.key;
|
|
64
|
+
if (before != null && after != null) label = stringFormatter.format('insertBetween', {
|
|
57
65
|
beforeItemText: getText(before),
|
|
58
66
|
afterItemText: getText(after)
|
|
59
67
|
});
|
|
60
|
-
else if (before) label = stringFormatter.format('insertAfter', {
|
|
68
|
+
else if (before != null) label = stringFormatter.format('insertAfter', {
|
|
61
69
|
itemText: getText(before)
|
|
62
70
|
});
|
|
63
|
-
else if (after) label = stringFormatter.format('insertBefore', {
|
|
71
|
+
else if (after != null) label = stringFormatter.format('insertBefore', {
|
|
64
72
|
itemText: getText(after)
|
|
65
73
|
});
|
|
66
74
|
}
|
|
@@ -49,18 +49,26 @@ function $ddf25448c71fc93a$export$8d0e41d2815afac5(props, state, ref) {
|
|
|
49
49
|
else {
|
|
50
50
|
let before;
|
|
51
51
|
let after;
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
if (target.dropPosition === 'before') {
|
|
53
|
+
var _collection_getItem;
|
|
54
|
+
let prevKey = (_collection_getItem = collection.getItem(target.key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.prevKey;
|
|
55
|
+
let prevNode = prevKey != null ? collection.getItem(prevKey) : null;
|
|
56
|
+
before = (prevNode === null || prevNode === void 0 ? void 0 : prevNode.type) === 'item' ? prevNode.key : null;
|
|
57
|
+
} else before = target.key;
|
|
58
|
+
if (target.dropPosition === 'after') {
|
|
59
|
+
var _collection_getItem1;
|
|
60
|
+
let nextKey = (_collection_getItem1 = collection.getItem(target.key)) === null || _collection_getItem1 === void 0 ? void 0 : _collection_getItem1.nextKey;
|
|
61
|
+
let nextNode = nextKey != null ? collection.getItem(nextKey) : null;
|
|
62
|
+
after = (nextNode === null || nextNode === void 0 ? void 0 : nextNode.type) === 'item' ? nextNode.key : null;
|
|
63
|
+
} else after = target.key;
|
|
64
|
+
if (before != null && after != null) label = stringFormatter.format('insertBetween', {
|
|
57
65
|
beforeItemText: getText(before),
|
|
58
66
|
afterItemText: getText(after)
|
|
59
67
|
});
|
|
60
|
-
else if (before) label = stringFormatter.format('insertAfter', {
|
|
68
|
+
else if (before != null) label = stringFormatter.format('insertAfter', {
|
|
61
69
|
itemText: getText(before)
|
|
62
70
|
});
|
|
63
|
-
else if (after) label = stringFormatter.format('insertBefore', {
|
|
71
|
+
else if (after != null) label = stringFormatter.format('insertBefore', {
|
|
64
72
|
itemText: getText(after)
|
|
65
73
|
});
|
|
66
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CA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AO,YAAY,KAAK,SAAS;gBACrB;YAAd,IAAI,WAAU,uBAAA,WAAW,OAAO,CAAC,OAAO,GAAG,eAA7B,2CAAA,qBAAgC,OAAO;YACrD,IAAI,WAAW,WAAW,OAAO,WAAW,OAAO,CAAC,WAAW;YAC/D,QAAQ,CAAA,qBAAA,+BAAA,SAAU,IAAI,MAAK,SAAS,SAAS,GAAG,GAAG;QACrD,OACE,QAAQ,OAAO,GAAG;QAGpB,IAAI,UAAU,QAAQ,SAAS,MAC7B,QAAQ,gBAAgB,MAAM,CAAC,iBAAiB;YAC9C,gBAAgB,QAAQ;YACxB,eAAe,QAAQ;QACzB;aACK,IAAI,UAAU,MACnB,QAAQ,gBAAgB,MAAM,CAAC,eAAe;YAC5C,UAAU,QAAQ;QACpB;aACK,IAAI,SAAS,MAClB,QAAQ,gBAAgB,MAAM,CAAC,gBAAgB;YAC7C,UAAU,QAAQ;QACpB;IAEJ;IAEA,IAAI,eAAe,MAAM,YAAY,CAAC;IACtC,IAAI,aAAa,CAAC,cAAc,SAAS,SAAS,CAAC,cAAc;IACjE,OAAO;QACL,oBAAoB;YAClB,GAAG,SAAS;gBACZ;YACA,wBAAwB,gBAAgB,MAAM,CAAC;YAC/C,cAAc;YACd,mBAAmB;YACnB,eAAe;YACf,UAAU;QACZ;sBACA;QACA,qFAAqF;QACrF,yGAAyG;QACzG,0FAA0F;QAC1F,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC/B;AACF","sources":["packages/@react-aria/dnd/src/useDropIndicator.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 * as DragManager from './DragManager';\nimport {DroppableCollectionState} from '@react-stately/dnd';\nimport {DropTarget, FocusableElement, Key, RefObject} from '@react-types/shared';\nimport {getDroppableCollectionId} from './utils';\nimport {HTMLAttributes} from 'react';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useDroppableItem} from './useDroppableItem';\nimport {useId} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface DropIndicatorProps {\n /** The drop target that the drop indicator represents. */\n target: DropTarget,\n /** The ref to the activate button. */\n activateButtonRef?: RefObject<FocusableElement | null>\n}\n\nexport interface DropIndicatorAria {\n /** Props for the drop indicator element. */\n dropIndicatorProps: HTMLAttributes<HTMLElement>,\n /** Whether the drop indicator is currently the active drop target. */\n isDropTarget: boolean,\n /**\n * Whether the drop indicator is hidden, both visually and from assistive technology.\n * Use this to determine whether to omit the element from the DOM entirely.\n */\n isHidden: boolean\n}\n\n/**\n * Handles drop interactions for a target within a droppable collection.\n */\nexport function useDropIndicator(props: DropIndicatorProps, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>): DropIndicatorAria {\n let {target} = props;\n let {collection} = state;\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let dragSession = DragManager.useDragSession();\n let {dropProps} = useDroppableItem(props, state, ref);\n let id = useId();\n let getText = (key: Key | null) => {\n if (key == null) {\n return '';\n } else {\n return collection.getTextValue?.(key) ?? collection.getItem(key)?.textValue ?? '';\n }\n };\n\n let label = '';\n let labelledBy: string | undefined;\n if (target.type === 'root') {\n label = stringFormatter.format('dropOnRoot');\n labelledBy = `${id} ${getDroppableCollectionId(state)}`;\n } else if (target.dropPosition === 'on') {\n label = stringFormatter.format('dropOnItem', {\n itemText: getText(target.key)\n });\n } else {\n let before: Key | null | undefined;\n let after: Key | null | undefined;\n if (target.dropPosition === 'before') {\n let prevKey = collection.getItem(target.key)?.prevKey;\n let prevNode = prevKey != null ? collection.getItem(prevKey) : null;\n before = prevNode?.type === 'item' ? prevNode.key : null;\n } else {\n before = target.key;\n }\n\n if (target.dropPosition === 'after') {\n let nextKey = collection.getItem(target.key)?.nextKey;\n let nextNode = nextKey != null ? collection.getItem(nextKey) : null;\n after = nextNode?.type === 'item' ? nextNode.key : null;\n } else {\n after = target.key;\n }\n\n if (before != null && after != null) {\n label = stringFormatter.format('insertBetween', {\n beforeItemText: getText(before),\n afterItemText: getText(after)\n });\n } else if (before != null) {\n label = stringFormatter.format('insertAfter', {\n itemText: getText(before)\n });\n } else if (after != null) {\n label = stringFormatter.format('insertBefore', {\n itemText: getText(after)\n });\n }\n }\n\n let isDropTarget = state.isDropTarget(target);\n let ariaHidden = !dragSession ? 'true' : dropProps['aria-hidden'];\n return {\n dropIndicatorProps: {\n ...dropProps,\n id,\n 'aria-roledescription': stringFormatter.format('dropIndicator'),\n 'aria-label': label,\n 'aria-labelledby': labelledBy,\n 'aria-hidden': ariaHidden,\n tabIndex: -1\n },\n isDropTarget,\n // If aria-hidden, we are either not in a drag session or the drop target is invalid.\n // In that case, there's no need to render anything at all unless we need to show the indicator visually.\n // This can happen when dragging using the native DnD API as opposed to keyboard dragging.\n isHidden: !isDropTarget && !!ariaHidden\n };\n}\n"],"names":[],"version":3,"file":"useDropIndicator.module.js.map"}
|