@react-aria/dnd
Advanced tools
Comparing version 3.0.0-nightly-0ddbe6f95-241021 to 3.0.0-nightly-101d0772b-250111
@@ -24,4 +24,3 @@ | ||
* governing permissions and limitations under the License. | ||
*/ var $76b1e110a27b1ccd$export$60b7b4bcf3903d8e; | ||
(function(DROP_OPERATION) { | ||
*/ var $76b1e110a27b1ccd$export$60b7b4bcf3903d8e = /*#__PURE__*/ function(DROP_OPERATION) { | ||
DROP_OPERATION[DROP_OPERATION["none"] = 0] = "none"; | ||
@@ -33,3 +32,4 @@ DROP_OPERATION[DROP_OPERATION["cancel"] = 0] = "cancel"; | ||
DROP_OPERATION[DROP_OPERATION["all"] = 7] = "all"; | ||
})($76b1e110a27b1ccd$export$60b7b4bcf3903d8e || ($76b1e110a27b1ccd$export$60b7b4bcf3903d8e = {})); | ||
return DROP_OPERATION; | ||
}({}); | ||
const $76b1e110a27b1ccd$export$9bbdfc78cf083e16 = { | ||
@@ -36,0 +36,0 @@ ...$76b1e110a27b1ccd$export$60b7b4bcf3903d8e, |
@@ -11,4 +11,3 @@ /* | ||
* governing permissions and limitations under the License. | ||
*/ var $103790afe9474d1c$export$60b7b4bcf3903d8e; | ||
(function(DROP_OPERATION) { | ||
*/ var $103790afe9474d1c$export$60b7b4bcf3903d8e = /*#__PURE__*/ function(DROP_OPERATION) { | ||
DROP_OPERATION[DROP_OPERATION["none"] = 0] = "none"; | ||
@@ -20,3 +19,4 @@ DROP_OPERATION[DROP_OPERATION["cancel"] = 0] = "cancel"; | ||
DROP_OPERATION[DROP_OPERATION["all"] = 7] = "all"; | ||
})($103790afe9474d1c$export$60b7b4bcf3903d8e || ($103790afe9474d1c$export$60b7b4bcf3903d8e = {})); | ||
return DROP_OPERATION; | ||
}({}); | ||
const $103790afe9474d1c$export$9bbdfc78cf083e16 = { | ||
@@ -23,0 +23,0 @@ ...$103790afe9474d1c$export$60b7b4bcf3903d8e, |
@@ -54,4 +54,6 @@ var $4620ae0dc40f0031$exports = require("./utils.main.js"); | ||
requestAnimationFrame(()=>{ | ||
$28e10663603f5ea1$var$dragSession.setup(); | ||
if ((0, $4620ae0dc40f0031$exports.getDragModality)() === 'keyboard') $28e10663603f5ea1$var$dragSession.next(); | ||
if ($28e10663603f5ea1$var$dragSession) { | ||
$28e10663603f5ea1$var$dragSession.setup(); | ||
if ((0, $4620ae0dc40f0031$exports.getDragModality)() === 'keyboard') $28e10663603f5ea1$var$dragSession.next(); | ||
} | ||
}); | ||
@@ -129,2 +131,3 @@ for (let cb of $28e10663603f5ea1$var$subscriptions)cb(); | ||
teardown() { | ||
var _this_mutationObserver, _this_restoreAriaHidden, _this; | ||
document.removeEventListener('keydown', this.onKeyDown, true); | ||
@@ -137,4 +140,4 @@ document.removeEventListener('keyup', this.onKeyUp, true); | ||
for (let event of $28e10663603f5ea1$var$CANCELED_EVENTS)document.removeEventListener(event, this.cancelEvent, true); | ||
this.mutationObserver.disconnect(); | ||
this.restoreAriaHidden(); | ||
(_this_mutationObserver = this.mutationObserver) === null || _this_mutationObserver === void 0 ? void 0 : _this_mutationObserver.disconnect(); | ||
(_this_restoreAriaHidden = (_this = this).restoreAriaHidden) === null || _this_restoreAriaHidden === void 0 ? void 0 : _this_restoreAriaHidden.call(_this); | ||
} | ||
@@ -330,5 +333,5 @@ onKeyDown(e) { | ||
} | ||
if (item !== this.currentDropItem) { | ||
if (item && typeof this.currentDropTarget.onDropTargetEnter === 'function') this.currentDropTarget.onDropTargetEnter(item === null || item === void 0 ? void 0 : item.target); | ||
item === null || item === void 0 ? void 0 : item.element.focus(); | ||
if (item != null && item !== this.currentDropItem) { | ||
if (this.currentDropTarget && typeof this.currentDropTarget.onDropTargetEnter === 'function') this.currentDropTarget.onDropTargetEnter(item.target); | ||
item.element.focus(); | ||
this.currentDropItem = item; | ||
@@ -345,2 +348,6 @@ // Announce first drop target after drag start announcement finishes. | ||
end() { | ||
var // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent). | ||
// This corrects state such as whether focus ring should appear. | ||
// useDroppableCollection handles this itself, so this is only for standalone drop zones. | ||
_document_activeElement; | ||
this.teardown(); | ||
@@ -358,6 +365,3 @@ $28e10663603f5ea1$var$endDragging(); | ||
} | ||
if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent). | ||
// This corrects state such as whether focus ring should appear. | ||
// useDroppableCollection handles this itself, so this is only for standalone drop zones. | ||
document.activeElement.dispatchEvent(new FocusEvent('focusin', { | ||
if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) (_document_activeElement = document.activeElement) === null || _document_activeElement === void 0 ? void 0 : _document_activeElement.dispatchEvent(new FocusEvent('focusin', { | ||
bubbles: true | ||
@@ -393,2 +397,3 @@ })); | ||
let rect = this.currentDropTarget.element.getBoundingClientRect(); | ||
var _item_target; | ||
this.currentDropTarget.onDrop({ | ||
@@ -400,3 +405,3 @@ type: 'drop', | ||
dropOperation: this.dropOperation | ||
}, item === null || item === void 0 ? void 0 : item.target); | ||
}, (_item_target = item === null || item === void 0 ? void 0 : item.target) !== null && _item_target !== void 0 ? _item_target : null); | ||
} | ||
@@ -413,6 +418,13 @@ this.end(); | ||
y: rect.top + rect.height / 2 | ||
}); | ||
}, null); | ||
} | ||
} | ||
constructor(target, stringFormatter){ | ||
this.validDropTargets = []; | ||
this.currentDropTarget = null; | ||
this.currentDropItem = null; | ||
this.dropOperation = null; | ||
this.mutationObserver = null; | ||
this.restoreAriaHidden = null; | ||
this.isVirtualClick = false; | ||
this.dragTarget = target; | ||
@@ -419,0 +431,0 @@ this.stringFormatter = stringFormatter; |
@@ -44,4 +44,6 @@ import {getDragModality as $7252cd45fc48c07c$export$1fb2158d224b542c, getTypes as $7252cd45fc48c07c$export$e1d41611756c6326} from "./utils.module.js"; | ||
requestAnimationFrame(()=>{ | ||
$67560de7c78cb232$var$dragSession.setup(); | ||
if ((0, $7252cd45fc48c07c$export$1fb2158d224b542c)() === 'keyboard') $67560de7c78cb232$var$dragSession.next(); | ||
if ($67560de7c78cb232$var$dragSession) { | ||
$67560de7c78cb232$var$dragSession.setup(); | ||
if ((0, $7252cd45fc48c07c$export$1fb2158d224b542c)() === 'keyboard') $67560de7c78cb232$var$dragSession.next(); | ||
} | ||
}); | ||
@@ -119,2 +121,3 @@ for (let cb of $67560de7c78cb232$var$subscriptions)cb(); | ||
teardown() { | ||
var _this_mutationObserver, _this_restoreAriaHidden, _this; | ||
document.removeEventListener('keydown', this.onKeyDown, true); | ||
@@ -127,4 +130,4 @@ document.removeEventListener('keyup', this.onKeyUp, true); | ||
for (let event of $67560de7c78cb232$var$CANCELED_EVENTS)document.removeEventListener(event, this.cancelEvent, true); | ||
this.mutationObserver.disconnect(); | ||
this.restoreAriaHidden(); | ||
(_this_mutationObserver = this.mutationObserver) === null || _this_mutationObserver === void 0 ? void 0 : _this_mutationObserver.disconnect(); | ||
(_this_restoreAriaHidden = (_this = this).restoreAriaHidden) === null || _this_restoreAriaHidden === void 0 ? void 0 : _this_restoreAriaHidden.call(_this); | ||
} | ||
@@ -320,5 +323,5 @@ onKeyDown(e) { | ||
} | ||
if (item !== this.currentDropItem) { | ||
if (item && typeof this.currentDropTarget.onDropTargetEnter === 'function') this.currentDropTarget.onDropTargetEnter(item === null || item === void 0 ? void 0 : item.target); | ||
item === null || item === void 0 ? void 0 : item.element.focus(); | ||
if (item != null && item !== this.currentDropItem) { | ||
if (this.currentDropTarget && typeof this.currentDropTarget.onDropTargetEnter === 'function') this.currentDropTarget.onDropTargetEnter(item.target); | ||
item.element.focus(); | ||
this.currentDropItem = item; | ||
@@ -335,2 +338,6 @@ // Announce first drop target after drag start announcement finishes. | ||
end() { | ||
var // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent). | ||
// This corrects state such as whether focus ring should appear. | ||
// useDroppableCollection handles this itself, so this is only for standalone drop zones. | ||
_document_activeElement; | ||
this.teardown(); | ||
@@ -348,6 +355,3 @@ $67560de7c78cb232$var$endDragging(); | ||
} | ||
if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) // Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent). | ||
// This corrects state such as whether focus ring should appear. | ||
// useDroppableCollection handles this itself, so this is only for standalone drop zones. | ||
document.activeElement.dispatchEvent(new FocusEvent('focusin', { | ||
if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) (_document_activeElement = document.activeElement) === null || _document_activeElement === void 0 ? void 0 : _document_activeElement.dispatchEvent(new FocusEvent('focusin', { | ||
bubbles: true | ||
@@ -383,2 +387,3 @@ })); | ||
let rect = this.currentDropTarget.element.getBoundingClientRect(); | ||
var _item_target; | ||
this.currentDropTarget.onDrop({ | ||
@@ -390,3 +395,3 @@ type: 'drop', | ||
dropOperation: this.dropOperation | ||
}, item === null || item === void 0 ? void 0 : item.target); | ||
}, (_item_target = item === null || item === void 0 ? void 0 : item.target) !== null && _item_target !== void 0 ? _item_target : null); | ||
} | ||
@@ -403,6 +408,13 @@ this.end(); | ||
y: rect.top + rect.height / 2 | ||
}); | ||
}, null); | ||
} | ||
} | ||
constructor(target, stringFormatter){ | ||
this.validDropTargets = []; | ||
this.currentDropTarget = null; | ||
this.currentDropItem = null; | ||
this.dropOperation = null; | ||
this.mutationObserver = null; | ||
this.restoreAriaHidden = null; | ||
this.isVirtualClick = false; | ||
this.dragTarget = target; | ||
@@ -409,0 +421,0 @@ this.stringFormatter = stringFormatter; |
@@ -26,6 +26,7 @@ var $l6JIF$reactdom = require("react-dom"); | ||
function $2dccaca1f4baa446$var$DragPreview(props, ref) { | ||
const $2dccaca1f4baa446$export$905ab40ac2179daa = /*#__PURE__*/ (0, ($parcel$interopDefault($l6JIF$react))).forwardRef(function DragPreview(props, ref) { | ||
let render = props.children; | ||
let [children, setChildren] = (0, $l6JIF$react.useState)(null); | ||
let domRef = (0, $l6JIF$react.useRef)(null); | ||
let raf = (0, $l6JIF$react.useRef)(undefined); | ||
(0, $l6JIF$react.useImperativeHandle)(ref, ()=>(items, callback)=>{ | ||
@@ -40,3 +41,3 @@ // This will be called during the onDragStart event by useDrag. We need to render the | ||
// Remove the preview from the DOM after a frame so the browser has time to paint. | ||
requestAnimationFrame(()=>{ | ||
raf.current = requestAnimationFrame(()=>{ | ||
setChildren(null); | ||
@@ -47,2 +48,7 @@ }); | ||
]); | ||
(0, $l6JIF$react.useEffect)(()=>{ | ||
return ()=>{ | ||
if (raf.current) cancelAnimationFrame(raf.current); | ||
}; | ||
}, []); | ||
if (!children) return null; | ||
@@ -58,6 +64,5 @@ return /*#__PURE__*/ (0, ($parcel$interopDefault($l6JIF$react))).createElement("div", { | ||
}, children); | ||
} | ||
let $2dccaca1f4baa446$export$905ab40ac2179daa = /*#__PURE__*/ (0, ($parcel$interopDefault($l6JIF$react))).forwardRef($2dccaca1f4baa446$var$DragPreview); | ||
}); | ||
//# sourceMappingURL=DragPreview.main.js.map |
import {flushSync as $eLjnH$flushSync} from "react-dom"; | ||
import $eLjnH$react, {useState as $eLjnH$useState, useRef as $eLjnH$useRef, useImperativeHandle as $eLjnH$useImperativeHandle} from "react"; | ||
import $eLjnH$react, {useState as $eLjnH$useState, useRef as $eLjnH$useRef, useImperativeHandle as $eLjnH$useImperativeHandle, useEffect as $eLjnH$useEffect} from "react"; | ||
@@ -16,6 +16,7 @@ /* | ||
function $ad0e3f3d9c50e4ba$var$DragPreview(props, ref) { | ||
const $ad0e3f3d9c50e4ba$export$905ab40ac2179daa = /*#__PURE__*/ (0, $eLjnH$react).forwardRef(function DragPreview(props, ref) { | ||
let render = props.children; | ||
let [children, setChildren] = (0, $eLjnH$useState)(null); | ||
let domRef = (0, $eLjnH$useRef)(null); | ||
let raf = (0, $eLjnH$useRef)(undefined); | ||
(0, $eLjnH$useImperativeHandle)(ref, ()=>(items, callback)=>{ | ||
@@ -30,3 +31,3 @@ // This will be called during the onDragStart event by useDrag. We need to render the | ||
// Remove the preview from the DOM after a frame so the browser has time to paint. | ||
requestAnimationFrame(()=>{ | ||
raf.current = requestAnimationFrame(()=>{ | ||
setChildren(null); | ||
@@ -37,2 +38,7 @@ }); | ||
]); | ||
(0, $eLjnH$useEffect)(()=>{ | ||
return ()=>{ | ||
if (raf.current) cancelAnimationFrame(raf.current); | ||
}; | ||
}, []); | ||
if (!children) return null; | ||
@@ -48,4 +54,3 @@ return /*#__PURE__*/ (0, $eLjnH$react).createElement("div", { | ||
}, children); | ||
} | ||
let $ad0e3f3d9c50e4ba$export$905ab40ac2179daa = /*#__PURE__*/ (0, $eLjnH$react).forwardRef($ad0e3f3d9c50e4ba$var$DragPreview); | ||
}); | ||
@@ -52,0 +57,0 @@ |
@@ -30,3 +30,3 @@ | ||
getDropTargetFromPoint(x, y, isValidDropTarget) { | ||
if (this.collection[Symbol.iterator]().next().done) return { | ||
if (this.collection[Symbol.iterator]().next().done || !this.ref.current) return { | ||
type: 'root' | ||
@@ -45,3 +45,3 @@ }; | ||
let elementMap = new Map(); | ||
for (let item of elements)if (item instanceof HTMLElement) elementMap.set(item.dataset.key, item); | ||
for (let item of elements)if (item instanceof HTMLElement && item.dataset.key != null) elementMap.set(item.dataset.key, item); | ||
// TODO: assume that only item type items are valid drop targets. This is to prevent a crash when dragging over the loader | ||
@@ -60,2 +60,3 @@ // row since it doesn't have a data-key set on it. Will eventually need to handle the case with drag and drop and loaders located between rows aka tree. | ||
let element = elementMap.get(String(item.key)); | ||
if (!element) break; | ||
let rect = element.getBoundingClientRect(); | ||
@@ -104,4 +105,4 @@ let update = (isGreater)=>{ | ||
let element = elementMap.get(String(item.key)); | ||
rect = element.getBoundingClientRect(); | ||
if (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect))) return { | ||
rect = element === null || element === void 0 ? void 0 : element.getBoundingClientRect(); | ||
if (rect && (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect)))) return { | ||
type: 'item', | ||
@@ -108,0 +109,0 @@ key: item.key, |
@@ -24,3 +24,3 @@ class $3ca85212bf8898e4$export$fbd65d14c79e28cc { | ||
getDropTargetFromPoint(x, y, isValidDropTarget) { | ||
if (this.collection[Symbol.iterator]().next().done) return { | ||
if (this.collection[Symbol.iterator]().next().done || !this.ref.current) return { | ||
type: 'root' | ||
@@ -39,3 +39,3 @@ }; | ||
let elementMap = new Map(); | ||
for (let item of elements)if (item instanceof HTMLElement) elementMap.set(item.dataset.key, item); | ||
for (let item of elements)if (item instanceof HTMLElement && item.dataset.key != null) elementMap.set(item.dataset.key, item); | ||
// TODO: assume that only item type items are valid drop targets. This is to prevent a crash when dragging over the loader | ||
@@ -54,2 +54,3 @@ // row since it doesn't have a data-key set on it. Will eventually need to handle the case with drag and drop and loaders located between rows aka tree. | ||
let element = elementMap.get(String(item.key)); | ||
if (!element) break; | ||
let rect = element.getBoundingClientRect(); | ||
@@ -98,4 +99,4 @@ let update = (isGreater)=>{ | ||
let element = elementMap.get(String(item.key)); | ||
rect = element.getBoundingClientRect(); | ||
if (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect))) return { | ||
rect = element === null || element === void 0 ? void 0 : element.getBoundingClientRect(); | ||
if (rect && (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect)))) return { | ||
type: 'item', | ||
@@ -102,0 +103,0 @@ key: item.key, |
@@ -1,2 +0,2 @@ | ||
import { DirectoryDropItem, DropItem, FileDropItem, TextDropItem, DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropMoveEvent, DropOperation, DragTypes, RefObject, DroppableCollectionProps, DropTargetDelegate, KeyboardDelegate, DropTarget, DragEndEvent, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, Key, DOMAttributes, Direction, Node, Orientation } from "@react-types/shared"; | ||
import { DirectoryDropItem, DropItem, FileDropItem, TextDropItem, DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropMoveEvent, DropOperation, FocusableElement, DragTypes, RefObject, DroppableCollectionProps, DropTargetDelegate, KeyboardDelegate, DropTarget, DragEndEvent, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, Key, DOMAttributes, Direction, Node, Orientation } from "@react-types/shared"; | ||
import { AriaButtonProps } from "@react-types/button"; | ||
@@ -16,3 +16,3 @@ import React, { HTMLAttributes, JSX } from "react"; | ||
/** A ref for the droppable element. */ | ||
ref: RefObject<HTMLElement | null>; | ||
ref: RefObject<FocusableElement | null>; | ||
/** | ||
@@ -180,5 +180,5 @@ * A function returning the drop operation to be performed when items matching the given types are dropped | ||
export interface DragPreviewProps { | ||
children: (items: DragItem[]) => JSX.Element; | ||
children: (items: DragItem[]) => JSX.Element | null; | ||
} | ||
export let DragPreview: React.ForwardRefExoticComponent<DragPreviewProps & React.RefAttributes<DragPreviewRenderer>>; | ||
export const DragPreview: React.ForwardRefExoticComponent<DragPreviewProps & React.RefAttributes<DragPreviewRenderer | null>>; | ||
export interface ClipboardProps { | ||
@@ -185,0 +185,0 @@ /** A function that returns the items to copy. */ |
@@ -38,3 +38,3 @@ var $8QIlU$reactariautils = require("@react-aria/utils"); | ||
let state = (0, $8QIlU$react.useRef)({ | ||
timer: null, | ||
timer: undefined, | ||
dx: 0, | ||
@@ -47,3 +47,3 @@ dy: 0 | ||
cancelAnimationFrame(state.timer); | ||
state.timer = null; | ||
state.timer = undefined; | ||
} | ||
@@ -56,4 +56,4 @@ }; | ||
let scroll = (0, $8QIlU$react.useCallback)(()=>{ | ||
if (scrollableX.current) scrollableRef.current.scrollLeft += state.dx; | ||
if (scrollableY.current) scrollableRef.current.scrollTop += state.dy; | ||
if (scrollableX.current && scrollableRef.current) scrollableRef.current.scrollLeft += state.dx; | ||
if (scrollableY.current && scrollableRef.current) scrollableRef.current.scrollTop += state.dy; | ||
if (state.timer) state.timer = requestAnimationFrame(scroll); | ||
@@ -85,3 +85,3 @@ }, [ | ||
cancelAnimationFrame(state.timer); | ||
state.timer = null; | ||
state.timer = undefined; | ||
} | ||
@@ -88,0 +88,0 @@ } |
@@ -32,3 +32,3 @@ import {isScrollable as $2wNms$isScrollable, getScrollParent as $2wNms$getScrollParent, isWebKit as $2wNms$isWebKit, isIOS as $2wNms$isIOS} from "@react-aria/utils"; | ||
let state = (0, $2wNms$useRef)({ | ||
timer: null, | ||
timer: undefined, | ||
dx: 0, | ||
@@ -41,3 +41,3 @@ dy: 0 | ||
cancelAnimationFrame(state.timer); | ||
state.timer = null; | ||
state.timer = undefined; | ||
} | ||
@@ -50,4 +50,4 @@ }; | ||
let scroll = (0, $2wNms$useCallback)(()=>{ | ||
if (scrollableX.current) scrollableRef.current.scrollLeft += state.dx; | ||
if (scrollableY.current) scrollableRef.current.scrollTop += state.dy; | ||
if (scrollableX.current && scrollableRef.current) scrollableRef.current.scrollLeft += state.dx; | ||
if (scrollableY.current && scrollableRef.current) scrollableRef.current.scrollTop += state.dy; | ||
if (state.timer) state.timer = requestAnimationFrame(scroll); | ||
@@ -79,3 +79,3 @@ }, [ | ||
cancelAnimationFrame(state.timer); | ||
state.timer = null; | ||
state.timer = undefined; | ||
} | ||
@@ -82,0 +82,0 @@ } |
@@ -63,7 +63,9 @@ var $4620ae0dc40f0031$exports = require("./utils.main.js"); | ||
let onCopy = (0, $gAFdr$reactariautils.useEffectEvent)((e)=>{ | ||
var _options_onCopy; | ||
if (!isFocusedRef.current || !options.getItems) return; | ||
e.preventDefault(); | ||
(0, $4620ae0dc40f0031$exports.writeToDataTransfer)(e.clipboardData, options.getItems()); | ||
(_options_onCopy = options.onCopy) === null || _options_onCopy === void 0 ? void 0 : _options_onCopy.call(options); | ||
if (e.clipboardData) { | ||
var _options_onCopy; | ||
(0, $4620ae0dc40f0031$exports.writeToDataTransfer)(e.clipboardData, options.getItems()); | ||
(_options_onCopy = options.onCopy) === null || _options_onCopy === void 0 ? void 0 : _options_onCopy.call(options); | ||
} | ||
}); | ||
@@ -76,4 +78,6 @@ let onBeforeCut = (0, $gAFdr$reactariautils.useEffectEvent)((e)=>{ | ||
e.preventDefault(); | ||
(0, $4620ae0dc40f0031$exports.writeToDataTransfer)(e.clipboardData, options.getItems()); | ||
options.onCut(); | ||
if (e.clipboardData) { | ||
(0, $4620ae0dc40f0031$exports.writeToDataTransfer)(e.clipboardData, options.getItems()); | ||
options.onCut(); | ||
} | ||
}); | ||
@@ -88,4 +92,6 @@ let onBeforePaste = (0, $gAFdr$reactariautils.useEffectEvent)((e)=>{ | ||
e.preventDefault(); | ||
let items = (0, $4620ae0dc40f0031$exports.readFromDataTransfer)(e.clipboardData); | ||
options.onPaste(items); | ||
if (e.clipboardData) { | ||
let items = (0, $4620ae0dc40f0031$exports.readFromDataTransfer)(e.clipboardData); | ||
options.onPaste(items); | ||
} | ||
}); | ||
@@ -92,0 +98,0 @@ (0, $gAFdr$react.useEffect)(()=>{ |
@@ -57,7 +57,9 @@ import {readFromDataTransfer as $7252cd45fc48c07c$export$d9e760437831f8b3, writeToDataTransfer as $7252cd45fc48c07c$export$f9c1490890ddd063} from "./utils.module.js"; | ||
let onCopy = (0, $9Tt78$useEffectEvent)((e)=>{ | ||
var _options_onCopy; | ||
if (!isFocusedRef.current || !options.getItems) return; | ||
e.preventDefault(); | ||
(0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.clipboardData, options.getItems()); | ||
(_options_onCopy = options.onCopy) === null || _options_onCopy === void 0 ? void 0 : _options_onCopy.call(options); | ||
if (e.clipboardData) { | ||
var _options_onCopy; | ||
(0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.clipboardData, options.getItems()); | ||
(_options_onCopy = options.onCopy) === null || _options_onCopy === void 0 ? void 0 : _options_onCopy.call(options); | ||
} | ||
}); | ||
@@ -70,4 +72,6 @@ let onBeforeCut = (0, $9Tt78$useEffectEvent)((e)=>{ | ||
e.preventDefault(); | ||
(0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.clipboardData, options.getItems()); | ||
options.onCut(); | ||
if (e.clipboardData) { | ||
(0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.clipboardData, options.getItems()); | ||
options.onCut(); | ||
} | ||
}); | ||
@@ -82,4 +86,6 @@ let onBeforePaste = (0, $9Tt78$useEffectEvent)((e)=>{ | ||
e.preventDefault(); | ||
let items = (0, $7252cd45fc48c07c$export$d9e760437831f8b3)(e.clipboardData); | ||
options.onPaste(items); | ||
if (e.clipboardData) { | ||
let items = (0, $7252cd45fc48c07c$export$d9e760437831f8b3)(e.clipboardData); | ||
options.onPaste(items); | ||
} | ||
}); | ||
@@ -86,0 +92,0 @@ (0, $9Tt78$useEffect)(()=>{ |
@@ -97,2 +97,3 @@ var $28e10663603f5ea1$exports = require("./DragManager.main.js"); | ||
if (typeof ((_options_preview = options.preview) === null || _options_preview === void 0 ? void 0 : _options_preview.current) === 'function') options.preview.current(items, (node)=>{ | ||
if (!node) return; | ||
// Compute the offset that the preview will appear under the mouse. | ||
@@ -215,3 +216,3 @@ // If possible, this is based on the point the user clicked on the target. | ||
let descriptionProps = (0, $3w36N$reactariautils.useDescription)(stringFormatter.format(message)); | ||
let interactions; | ||
let interactions = {}; | ||
if (!hasDragButton) // If there's no separate button to trigger accessible drag and drop mode, | ||
@@ -218,0 +219,0 @@ // then add event handlers to the draggable element itself to start dragging. |
@@ -91,2 +91,3 @@ import {beginDragging as $67560de7c78cb232$export$549dbcf8649bf3b2} from "./DragManager.module.js"; | ||
if (typeof ((_options_preview = options.preview) === null || _options_preview === void 0 ? void 0 : _options_preview.current) === 'function') options.preview.current(items, (node)=>{ | ||
if (!node) return; | ||
// Compute the offset that the preview will appear under the mouse. | ||
@@ -209,3 +210,3 @@ // If possible, this is based on the point the user clicked on the target. | ||
let descriptionProps = (0, $72Evg$useDescription)(stringFormatter.format(message)); | ||
let interactions; | ||
let interactions = {}; | ||
if (!hasDragButton) // If there's no separate button to trigger accessible drag and drop mode, | ||
@@ -212,0 +213,0 @@ // then add event handlers to the draggable element itself to start dragging. |
@@ -40,3 +40,3 @@ var $28e10663603f5ea1$exports = require("./DragManager.main.js"); | ||
allowedOperations: (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).all, | ||
dropActivateTimer: null | ||
dropActivateTimer: undefined | ||
}).current; | ||
@@ -106,6 +106,7 @@ let fireDropEnter = (e)=>{ | ||
clearTimeout(state.dropActivateTimer); | ||
if (typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') { | ||
if (options.onDropActivate && typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') { | ||
let onDropActivateOptions = options.onDropActivate; | ||
let rect = e.currentTarget.getBoundingClientRect(); | ||
state.dropActivateTimer = setTimeout(()=>{ | ||
options.onDropActivate({ | ||
onDropActivateOptions({ | ||
type: 'dropactivate', | ||
@@ -208,3 +209,3 @@ x: state.x - rect.x, | ||
(0, $AO99w$reactariautils.useLayoutEffect)(()=>{ | ||
if (isDisabled) return; | ||
if (isDisabled || !ref.current) return; | ||
return $28e10663603f5ea1$exports.registerDropTarget({ | ||
@@ -211,0 +212,0 @@ element: ref.current, |
@@ -34,3 +34,3 @@ import {registerDropTarget as $67560de7c78cb232$export$c28d9fb4a54e471a} from "./DragManager.module.js"; | ||
allowedOperations: (0, $103790afe9474d1c$export$60b7b4bcf3903d8e).all, | ||
dropActivateTimer: null | ||
dropActivateTimer: undefined | ||
}).current; | ||
@@ -100,6 +100,7 @@ let fireDropEnter = (e)=>{ | ||
clearTimeout(state.dropActivateTimer); | ||
if (typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') { | ||
if (options.onDropActivate && typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') { | ||
let onDropActivateOptions = options.onDropActivate; | ||
let rect = e.currentTarget.getBoundingClientRect(); | ||
state.dropActivateTimer = setTimeout(()=>{ | ||
options.onDropActivate({ | ||
onDropActivateOptions({ | ||
type: 'dropactivate', | ||
@@ -202,3 +203,3 @@ x: state.x - rect.x, | ||
(0, $j5n4S$useLayoutEffect)(()=>{ | ||
if (isDisabled) return; | ||
if (isDisabled || !ref.current) return; | ||
return $67560de7c78cb232$export$c28d9fb4a54e471a({ | ||
@@ -205,0 +206,0 @@ element: ref.current, |
@@ -43,4 +43,5 @@ var $28e10663603f5ea1$exports = require("./DragManager.main.js"); | ||
var _collection_getTextValue, _collection_getItem; | ||
var _collection_getTextValue1; | ||
return (_collection_getTextValue1 = (_collection_getTextValue = collection.getTextValue) === null || _collection_getTextValue === void 0 ? void 0 : _collection_getTextValue.call(collection, key)) !== null && _collection_getTextValue1 !== void 0 ? _collection_getTextValue1 : (_collection_getItem = collection.getItem(key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.textValue; | ||
var _collection_getTextValue1, _ref; | ||
if (key == null) return ''; | ||
else return (_ref = (_collection_getTextValue1 = (_collection_getTextValue = collection.getTextValue) === null || _collection_getTextValue === void 0 ? void 0 : _collection_getTextValue.call(collection, key)) !== null && _collection_getTextValue1 !== void 0 ? _collection_getTextValue1 : (_collection_getItem = collection.getItem(key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.textValue) !== null && _ref !== void 0 ? _ref : ''; | ||
}; | ||
@@ -47,0 +48,0 @@ let label = ''; |
@@ -37,4 +37,5 @@ import {useDragSession as $67560de7c78cb232$export$418e185dd3f1b968} from "./DragManager.module.js"; | ||
var _collection_getTextValue, _collection_getItem; | ||
var _collection_getTextValue1; | ||
return (_collection_getTextValue1 = (_collection_getTextValue = collection.getTextValue) === null || _collection_getTextValue === void 0 ? void 0 : _collection_getTextValue.call(collection, key)) !== null && _collection_getTextValue1 !== void 0 ? _collection_getTextValue1 : (_collection_getItem = collection.getItem(key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.textValue; | ||
var _collection_getTextValue1, _ref; | ||
if (key == null) return ''; | ||
else return (_ref = (_collection_getTextValue1 = (_collection_getTextValue = collection.getTextValue) === null || _collection_getTextValue === void 0 ? void 0 : _collection_getTextValue.call(collection, key)) !== null && _collection_getTextValue1 !== void 0 ? _collection_getTextValue1 : (_collection_getItem = collection.getItem(key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.textValue) !== null && _ref !== void 0 ? _ref : ''; | ||
}; | ||
@@ -41,0 +42,0 @@ let label = ''; |
@@ -109,6 +109,6 @@ var $4620ae0dc40f0031$exports = require("./utils.main.js"); | ||
onDropEnter () { | ||
state.setTarget(localState.nextTarget); | ||
if (localState.nextTarget != null) state.setTarget(localState.nextTarget); | ||
}, | ||
onDropMove (e) { | ||
state.setTarget(localState.nextTarget); | ||
if (localState.nextTarget != null) state.setTarget(localState.nextTarget); | ||
autoScroll.move(e.x, e.y); | ||
@@ -209,5 +209,7 @@ }, | ||
} | ||
} else if (state.selectionManager.focusedKey === prevFocusedKey && isInternal && target.type === 'item' && target.dropPosition !== 'on' && draggingKeys.has((_state_collection_getItem = state.collection.getItem(prevFocusedKey)) === null || _state_collection_getItem === void 0 ? void 0 : _state_collection_getItem.parentKey)) { | ||
} else if (prevFocusedKey != null && state.selectionManager.focusedKey === prevFocusedKey && isInternal && target.type === 'item' && target.dropPosition !== 'on' && draggingKeys.has((_state_collection_getItem = state.collection.getItem(prevFocusedKey)) === null || _state_collection_getItem === void 0 ? void 0 : _state_collection_getItem.parentKey)) { | ||
var _state_collection_getItem1; | ||
var _state_collection_getItem_parentKey; | ||
// Focus row instead of cell when reordering. | ||
state.selectionManager.setFocusedKey(state.collection.getItem(prevFocusedKey).parentKey); | ||
state.selectionManager.setFocusedKey((_state_collection_getItem_parentKey = (_state_collection_getItem1 = state.collection.getItem(prevFocusedKey)) === null || _state_collection_getItem1 === void 0 ? void 0 : _state_collection_getItem1.parentKey) !== null && _state_collection_getItem_parentKey !== void 0 ? _state_collection_getItem_parentKey : null); | ||
(0, $foOxf$reactariainteractions.setInteractionModality)('keyboard'); | ||
@@ -220,3 +222,3 @@ } else if (state.selectionManager.focusedKey === prevFocusedKey && target.type === 'item' && target.dropPosition === 'on' && state.collection.getItem(target.key) != null) { | ||
(0, $foOxf$reactariainteractions.setInteractionModality)('keyboard'); | ||
} else if (!state.selectionManager.isSelected(state.selectionManager.focusedKey)) (0, $foOxf$reactariainteractions.setInteractionModality)('keyboard'); | ||
} else if (state.selectionManager.focusedKey != null && !state.selectionManager.isSelected(state.selectionManager.focusedKey)) (0, $foOxf$reactariainteractions.setInteractionModality)('keyboard'); | ||
state.selectionManager.setFocused(true); | ||
@@ -231,3 +233,3 @@ } | ||
droppingState.current = { | ||
timeout: null, | ||
timeout: undefined, | ||
focusedKey: state.selectionManager.focusedKey, | ||
@@ -273,3 +275,5 @@ collection: state.collection, | ||
(0, $foOxf$react.useEffect)(()=>{ | ||
if (!ref.current) return; | ||
let getNextTarget = (target, wrap = true, horizontal = false)=>{ | ||
var _keyboardDelegate_getKeyRightOf, _keyboardDelegate_getKeyBelow, _keyboardDelegate_getLastKey, _keyboardDelegate_getFirstKey; | ||
if (!target) return { | ||
@@ -280,4 +284,4 @@ type: 'root' | ||
let nextKey; | ||
if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? keyboardDelegate.getKeyRightOf(target.key) : keyboardDelegate.getKeyBelow(target.key); | ||
else nextKey = horizontal && direction === 'rtl' ? keyboardDelegate.getLastKey() : keyboardDelegate.getFirstKey(); | ||
if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? (_keyboardDelegate_getKeyRightOf = keyboardDelegate.getKeyRightOf) === null || _keyboardDelegate_getKeyRightOf === void 0 ? void 0 : _keyboardDelegate_getKeyRightOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyBelow = keyboardDelegate.getKeyBelow) === null || _keyboardDelegate_getKeyBelow === void 0 ? void 0 : _keyboardDelegate_getKeyBelow.call(keyboardDelegate, target.key); | ||
else nextKey = horizontal && direction === 'rtl' ? (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate) : (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate); | ||
let dropPositions = horizontal && direction === 'rtl' ? $7f93a158ac20b90a$var$DROP_POSITIONS_RTL : $7f93a158ac20b90a$var$DROP_POSITIONS; | ||
@@ -316,6 +320,7 @@ let dropPosition = dropPositions[0]; | ||
let getPreviousTarget = (target, wrap = true, horizontal = false)=>{ | ||
var _keyboardDelegate_getKeyLeftOf, _keyboardDelegate_getKeyAbove, _keyboardDelegate_getFirstKey, _keyboardDelegate_getLastKey; | ||
let { keyboardDelegate: keyboardDelegate } = localState.props; | ||
let nextKey; | ||
if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? keyboardDelegate.getKeyLeftOf(target.key) : keyboardDelegate.getKeyAbove(target.key); | ||
else nextKey = horizontal && direction === 'rtl' ? keyboardDelegate.getFirstKey() : keyboardDelegate.getLastKey(); | ||
if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? (_keyboardDelegate_getKeyLeftOf = keyboardDelegate.getKeyLeftOf) === null || _keyboardDelegate_getKeyLeftOf === void 0 ? void 0 : _keyboardDelegate_getKeyLeftOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyAbove = keyboardDelegate.getKeyAbove) === null || _keyboardDelegate_getKeyAbove === void 0 ? void 0 : _keyboardDelegate_getKeyAbove.call(keyboardDelegate, target.key); | ||
else nextKey = horizontal && direction === 'rtl' ? (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate) : (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate); | ||
let dropPositions = horizontal && direction === 'rtl' ? $7f93a158ac20b90a$var$DROP_POSITIONS_RTL : $7f93a158ac20b90a$var$DROP_POSITIONS; | ||
@@ -397,3 +402,3 @@ let dropPosition = !target || target.type === 'root' ? dropPositions[2] : 'on'; | ||
let selectionManager = localState.state.selectionManager; | ||
let target; | ||
let target = null; | ||
// Update the drop collection ref tracker for useDroppableItem's getDropOperation isInternal check | ||
@@ -407,3 +412,3 @@ (0, $4620ae0dc40f0031$exports.setDropCollectionRef)(ref); | ||
// For now, we assume that individual cells cannot be dropped on. | ||
let item = localState.state.collection.getItem(key); | ||
let item = key != null ? localState.state.collection.getItem(key) : null; | ||
if ((item === null || item === void 0 ? void 0 : item.type) === 'cell') key = item.parentKey; | ||
@@ -414,3 +419,3 @@ // If the focused item is also selected, the default drop target is after the last selected item. | ||
// move the items down. If you select bottom up, we assume you want to move the items up. | ||
if (selectionManager.isSelected(key)) { | ||
if (key != null && selectionManager.isSelected(key)) { | ||
if (selectionManager.selectedKeys.size > 1 && selectionManager.firstSelectedKey === key) dropPosition = 'before'; | ||
@@ -506,10 +511,17 @@ else key = selectionManager.lastSelectedKey; | ||
else { | ||
var _keyboardDelegate_getFirstKey, _keyboardDelegate_getLastKey; | ||
// If on the root, go to the item a page below the top. Otherwise a page below the current item. | ||
let nextKey = keyboardDelegate.getKeyPageBelow(target.type === 'item' ? target.key : keyboardDelegate.getFirstKey()); | ||
let targetKey = (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate); | ||
if (target.type === 'item') targetKey = target.key; | ||
let nextKey = null; | ||
if (targetKey != null) nextKey = keyboardDelegate.getKeyPageBelow(targetKey); | ||
let dropPosition = target.type === 'item' ? target.dropPosition : 'after'; | ||
// If there is no next key, or we are starting on the last key, jump to the last possible position. | ||
if (nextKey == null || target.type === 'item' && target.key === keyboardDelegate.getLastKey()) { | ||
nextKey = keyboardDelegate.getLastKey(); | ||
if (nextKey == null || target.type === 'item' && target.key === ((_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate))) { | ||
var _keyboardDelegate_getLastKey1; | ||
var _keyboardDelegate_getLastKey2; | ||
nextKey = (_keyboardDelegate_getLastKey2 = (_keyboardDelegate_getLastKey1 = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey1 === void 0 ? void 0 : _keyboardDelegate_getLastKey1.call(keyboardDelegate)) !== null && _keyboardDelegate_getLastKey2 !== void 0 ? _keyboardDelegate_getLastKey2 : null; | ||
dropPosition = 'after'; | ||
} | ||
if (nextKey == null) break; | ||
target = { | ||
@@ -543,4 +555,5 @@ type: 'item', | ||
else if (target.type === 'item') { | ||
var _keyboardDelegate_getFirstKey1; | ||
// If at the top already, switch to the root. Otherwise navigate a page up. | ||
if (target.key === keyboardDelegate.getFirstKey()) target = { | ||
if (target.key === ((_keyboardDelegate_getFirstKey1 = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey1 === void 0 ? void 0 : _keyboardDelegate_getFirstKey1.call(keyboardDelegate))) target = { | ||
type: 'root' | ||
@@ -552,5 +565,7 @@ }; | ||
if (nextKey == null) { | ||
nextKey = keyboardDelegate.getFirstKey(); | ||
var _keyboardDelegate_getFirstKey2; | ||
nextKey = (_keyboardDelegate_getFirstKey2 = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey2 === void 0 ? void 0 : _keyboardDelegate_getFirstKey2.call(keyboardDelegate); | ||
dropPosition = 'before'; | ||
} | ||
if (nextKey == null) break; | ||
target = { | ||
@@ -557,0 +572,0 @@ type: 'item', |
@@ -103,6 +103,6 @@ import {clearGlobalDnDState as $7252cd45fc48c07c$export$70936501603e6c57, DIRECTORY_DRAG_TYPE as $7252cd45fc48c07c$export$990fced5dfac2637, droppableCollectionMap as $7252cd45fc48c07c$export$dfdf5deeaf27473f, getTypes as $7252cd45fc48c07c$export$e1d41611756c6326, globalDndState as $7252cd45fc48c07c$export$6ca6700462636d0b, isInternalDropOperation as $7252cd45fc48c07c$export$78bf638634500fa5, setDropCollectionRef as $7252cd45fc48c07c$export$dac8db29d42db9a1} from "./utils.module.js"; | ||
onDropEnter () { | ||
state.setTarget(localState.nextTarget); | ||
if (localState.nextTarget != null) state.setTarget(localState.nextTarget); | ||
}, | ||
onDropMove (e) { | ||
state.setTarget(localState.nextTarget); | ||
if (localState.nextTarget != null) state.setTarget(localState.nextTarget); | ||
autoScroll.move(e.x, e.y); | ||
@@ -203,5 +203,7 @@ }, | ||
} | ||
} else if (state.selectionManager.focusedKey === prevFocusedKey && isInternal && target.type === 'item' && target.dropPosition !== 'on' && draggingKeys.has((_state_collection_getItem = state.collection.getItem(prevFocusedKey)) === null || _state_collection_getItem === void 0 ? void 0 : _state_collection_getItem.parentKey)) { | ||
} else if (prevFocusedKey != null && state.selectionManager.focusedKey === prevFocusedKey && isInternal && target.type === 'item' && target.dropPosition !== 'on' && draggingKeys.has((_state_collection_getItem = state.collection.getItem(prevFocusedKey)) === null || _state_collection_getItem === void 0 ? void 0 : _state_collection_getItem.parentKey)) { | ||
var _state_collection_getItem1; | ||
var _state_collection_getItem_parentKey; | ||
// Focus row instead of cell when reordering. | ||
state.selectionManager.setFocusedKey(state.collection.getItem(prevFocusedKey).parentKey); | ||
state.selectionManager.setFocusedKey((_state_collection_getItem_parentKey = (_state_collection_getItem1 = state.collection.getItem(prevFocusedKey)) === null || _state_collection_getItem1 === void 0 ? void 0 : _state_collection_getItem1.parentKey) !== null && _state_collection_getItem_parentKey !== void 0 ? _state_collection_getItem_parentKey : null); | ||
(0, $4ZR0C$setInteractionModality)('keyboard'); | ||
@@ -214,3 +216,3 @@ } else if (state.selectionManager.focusedKey === prevFocusedKey && target.type === 'item' && target.dropPosition === 'on' && state.collection.getItem(target.key) != null) { | ||
(0, $4ZR0C$setInteractionModality)('keyboard'); | ||
} else if (!state.selectionManager.isSelected(state.selectionManager.focusedKey)) (0, $4ZR0C$setInteractionModality)('keyboard'); | ||
} else if (state.selectionManager.focusedKey != null && !state.selectionManager.isSelected(state.selectionManager.focusedKey)) (0, $4ZR0C$setInteractionModality)('keyboard'); | ||
state.selectionManager.setFocused(true); | ||
@@ -225,3 +227,3 @@ } | ||
droppingState.current = { | ||
timeout: null, | ||
timeout: undefined, | ||
focusedKey: state.selectionManager.focusedKey, | ||
@@ -267,3 +269,5 @@ collection: state.collection, | ||
(0, $4ZR0C$useEffect)(()=>{ | ||
if (!ref.current) return; | ||
let getNextTarget = (target, wrap = true, horizontal = false)=>{ | ||
var _keyboardDelegate_getKeyRightOf, _keyboardDelegate_getKeyBelow, _keyboardDelegate_getLastKey, _keyboardDelegate_getFirstKey; | ||
if (!target) return { | ||
@@ -274,4 +278,4 @@ type: 'root' | ||
let nextKey; | ||
if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? keyboardDelegate.getKeyRightOf(target.key) : keyboardDelegate.getKeyBelow(target.key); | ||
else nextKey = horizontal && direction === 'rtl' ? keyboardDelegate.getLastKey() : keyboardDelegate.getFirstKey(); | ||
if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? (_keyboardDelegate_getKeyRightOf = keyboardDelegate.getKeyRightOf) === null || _keyboardDelegate_getKeyRightOf === void 0 ? void 0 : _keyboardDelegate_getKeyRightOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyBelow = keyboardDelegate.getKeyBelow) === null || _keyboardDelegate_getKeyBelow === void 0 ? void 0 : _keyboardDelegate_getKeyBelow.call(keyboardDelegate, target.key); | ||
else nextKey = horizontal && direction === 'rtl' ? (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate) : (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate); | ||
let dropPositions = horizontal && direction === 'rtl' ? $4b52e4eff84e5217$var$DROP_POSITIONS_RTL : $4b52e4eff84e5217$var$DROP_POSITIONS; | ||
@@ -310,6 +314,7 @@ let dropPosition = dropPositions[0]; | ||
let getPreviousTarget = (target, wrap = true, horizontal = false)=>{ | ||
var _keyboardDelegate_getKeyLeftOf, _keyboardDelegate_getKeyAbove, _keyboardDelegate_getFirstKey, _keyboardDelegate_getLastKey; | ||
let { keyboardDelegate: keyboardDelegate } = localState.props; | ||
let nextKey; | ||
if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? keyboardDelegate.getKeyLeftOf(target.key) : keyboardDelegate.getKeyAbove(target.key); | ||
else nextKey = horizontal && direction === 'rtl' ? keyboardDelegate.getFirstKey() : keyboardDelegate.getLastKey(); | ||
if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? (_keyboardDelegate_getKeyLeftOf = keyboardDelegate.getKeyLeftOf) === null || _keyboardDelegate_getKeyLeftOf === void 0 ? void 0 : _keyboardDelegate_getKeyLeftOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyAbove = keyboardDelegate.getKeyAbove) === null || _keyboardDelegate_getKeyAbove === void 0 ? void 0 : _keyboardDelegate_getKeyAbove.call(keyboardDelegate, target.key); | ||
else nextKey = horizontal && direction === 'rtl' ? (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate) : (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate); | ||
let dropPositions = horizontal && direction === 'rtl' ? $4b52e4eff84e5217$var$DROP_POSITIONS_RTL : $4b52e4eff84e5217$var$DROP_POSITIONS; | ||
@@ -391,3 +396,3 @@ let dropPosition = !target || target.type === 'root' ? dropPositions[2] : 'on'; | ||
let selectionManager = localState.state.selectionManager; | ||
let target; | ||
let target = null; | ||
// Update the drop collection ref tracker for useDroppableItem's getDropOperation isInternal check | ||
@@ -401,3 +406,3 @@ (0, $7252cd45fc48c07c$export$dac8db29d42db9a1)(ref); | ||
// For now, we assume that individual cells cannot be dropped on. | ||
let item = localState.state.collection.getItem(key); | ||
let item = key != null ? localState.state.collection.getItem(key) : null; | ||
if ((item === null || item === void 0 ? void 0 : item.type) === 'cell') key = item.parentKey; | ||
@@ -408,3 +413,3 @@ // If the focused item is also selected, the default drop target is after the last selected item. | ||
// move the items down. If you select bottom up, we assume you want to move the items up. | ||
if (selectionManager.isSelected(key)) { | ||
if (key != null && selectionManager.isSelected(key)) { | ||
if (selectionManager.selectedKeys.size > 1 && selectionManager.firstSelectedKey === key) dropPosition = 'before'; | ||
@@ -500,10 +505,17 @@ else key = selectionManager.lastSelectedKey; | ||
else { | ||
var _keyboardDelegate_getFirstKey, _keyboardDelegate_getLastKey; | ||
// If on the root, go to the item a page below the top. Otherwise a page below the current item. | ||
let nextKey = keyboardDelegate.getKeyPageBelow(target.type === 'item' ? target.key : keyboardDelegate.getFirstKey()); | ||
let targetKey = (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate); | ||
if (target.type === 'item') targetKey = target.key; | ||
let nextKey = null; | ||
if (targetKey != null) nextKey = keyboardDelegate.getKeyPageBelow(targetKey); | ||
let dropPosition = target.type === 'item' ? target.dropPosition : 'after'; | ||
// If there is no next key, or we are starting on the last key, jump to the last possible position. | ||
if (nextKey == null || target.type === 'item' && target.key === keyboardDelegate.getLastKey()) { | ||
nextKey = keyboardDelegate.getLastKey(); | ||
if (nextKey == null || target.type === 'item' && target.key === ((_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate))) { | ||
var _keyboardDelegate_getLastKey1; | ||
var _keyboardDelegate_getLastKey2; | ||
nextKey = (_keyboardDelegate_getLastKey2 = (_keyboardDelegate_getLastKey1 = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey1 === void 0 ? void 0 : _keyboardDelegate_getLastKey1.call(keyboardDelegate)) !== null && _keyboardDelegate_getLastKey2 !== void 0 ? _keyboardDelegate_getLastKey2 : null; | ||
dropPosition = 'after'; | ||
} | ||
if (nextKey == null) break; | ||
target = { | ||
@@ -537,4 +549,5 @@ type: 'item', | ||
else if (target.type === 'item') { | ||
var _keyboardDelegate_getFirstKey1; | ||
// If at the top already, switch to the root. Otherwise navigate a page up. | ||
if (target.key === keyboardDelegate.getFirstKey()) target = { | ||
if (target.key === ((_keyboardDelegate_getFirstKey1 = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey1 === void 0 ? void 0 : _keyboardDelegate_getFirstKey1.call(keyboardDelegate))) target = { | ||
type: 'root' | ||
@@ -546,5 +559,7 @@ }; | ||
if (nextKey == null) { | ||
nextKey = keyboardDelegate.getFirstKey(); | ||
var _keyboardDelegate_getFirstKey2; | ||
nextKey = (_keyboardDelegate_getFirstKey2 = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey2 === void 0 ? void 0 : _keyboardDelegate_getFirstKey2.call(keyboardDelegate); | ||
dropPosition = 'before'; | ||
} | ||
if (nextKey == null) break; | ||
target = { | ||
@@ -551,0 +566,0 @@ type: 'item', |
@@ -48,3 +48,3 @@ var $76b1e110a27b1ccd$exports = require("./constants.main.js"); | ||
function $4620ae0dc40f0031$export$3093291712f09a77(state) { | ||
let { id: id } = $4620ae0dc40f0031$export$dfdf5deeaf27473f.get(state); | ||
let { id: id } = $4620ae0dc40f0031$export$dfdf5deeaf27473f.get(state) || {}; | ||
if (!id) throw new Error('Droppable item outside a droppable collection'); | ||
@@ -54,3 +54,3 @@ return id; | ||
function $4620ae0dc40f0031$export$7e397efd01d3db27(state) { | ||
let { ref: ref } = $4620ae0dc40f0031$export$dfdf5deeaf27473f.get(state); | ||
let { ref: ref } = $4620ae0dc40f0031$export$dfdf5deeaf27473f.get(state) || {}; | ||
if (!ref) throw new Error('Droppable item outside a droppable collection'); | ||
@@ -145,2 +145,3 @@ return ref; | ||
let items = []; | ||
if (!dataTransfer) return items; | ||
// If our custom drag type is available, use that. This is a JSON serialized | ||
@@ -208,2 +209,3 @@ // representation of all items in the drag, set when there are multiple items | ||
function $4620ae0dc40f0031$var$createFileItem(file) { | ||
if (!file) throw new Error('No file provided'); | ||
return { | ||
@@ -210,0 +212,0 @@ kind: 'file', |
@@ -19,3 +19,3 @@ import {CUSTOM_DRAG_TYPE as $103790afe9474d1c$export$fd9f9fc120c5402d, DROP_OPERATION as $103790afe9474d1c$export$60b7b4bcf3903d8e, GENERIC_TYPE as $103790afe9474d1c$export$f8fc6581787339b3, NATIVE_DRAG_TYPES as $103790afe9474d1c$export$4a7729b856e9a690} from "./constants.module.js"; | ||
function $7252cd45fc48c07c$export$3093291712f09a77(state) { | ||
let { id: id } = $7252cd45fc48c07c$export$dfdf5deeaf27473f.get(state); | ||
let { id: id } = $7252cd45fc48c07c$export$dfdf5deeaf27473f.get(state) || {}; | ||
if (!id) throw new Error('Droppable item outside a droppable collection'); | ||
@@ -25,3 +25,3 @@ return id; | ||
function $7252cd45fc48c07c$export$7e397efd01d3db27(state) { | ||
let { ref: ref } = $7252cd45fc48c07c$export$dfdf5deeaf27473f.get(state); | ||
let { ref: ref } = $7252cd45fc48c07c$export$dfdf5deeaf27473f.get(state) || {}; | ||
if (!ref) throw new Error('Droppable item outside a droppable collection'); | ||
@@ -116,2 +116,3 @@ return ref; | ||
let items = []; | ||
if (!dataTransfer) return items; | ||
// If our custom drag type is available, use that. This is a JSON serialized | ||
@@ -179,2 +180,3 @@ // representation of all items in the drag, set when there are multiple items | ||
function $7252cd45fc48c07c$var$createFileItem(file) { | ||
if (!file) throw new Error('No file provided'); | ||
return { | ||
@@ -181,0 +183,0 @@ kind: 'file', |
{ | ||
"name": "@react-aria/dnd", | ||
"version": "3.0.0-nightly-0ddbe6f95-241021", | ||
"version": "3.0.0-nightly-101d0772b-250111", | ||
"description": "Spectrum UI components in React", | ||
@@ -25,21 +25,20 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@internationalized/string": "^3.0.0-nightly-0ddbe6f95-241021", | ||
"@react-aria/i18n": "^3.0.0-nightly-0ddbe6f95-241021", | ||
"@react-aria/interactions": "^3.0.0-nightly-0ddbe6f95-241021", | ||
"@react-aria/live-announcer": "^3.0.0-nightly-0ddbe6f95-241021", | ||
"@react-aria/overlays": "^3.0.0-nightly-0ddbe6f95-241021", | ||
"@react-aria/utils": "^3.0.0-nightly-0ddbe6f95-241021", | ||
"@react-stately/dnd": "^3.0.0-nightly-0ddbe6f95-241021", | ||
"@react-types/button": "^3.0.0-nightly-0ddbe6f95-241021", | ||
"@react-types/shared": "^3.0.0-nightly-0ddbe6f95-241021", | ||
"@internationalized/string": "3.0.0-nightly-101d0772b-250111", | ||
"@react-aria/i18n": "3.0.0-nightly-101d0772b-250111", | ||
"@react-aria/interactions": "3.0.0-nightly-101d0772b-250111", | ||
"@react-aria/live-announcer": "3.0.0-nightly-101d0772b-250111", | ||
"@react-aria/overlays": "3.0.0-nightly-101d0772b-250111", | ||
"@react-aria/utils": "3.0.0-nightly-101d0772b-250111", | ||
"@react-stately/dnd": "3.0.0-nightly-101d0772b-250111", | ||
"@react-types/button": "3.0.0-nightly-101d0772b-250111", | ||
"@react-types/shared": "3.0.0-nightly-101d0772b-250111", | ||
"@swc/helpers": "^0.5.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0", | ||
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0" | ||
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1", | ||
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"stableVersion": "3.7.4" | ||
} | ||
} |
@@ -23,3 +23,3 @@ /* | ||
let dropItems = new Map<Element, DroppableItem>(); | ||
let dragSession: DragSession = null; | ||
let dragSession: DragSession | null = null; | ||
let subscriptions = new Set<() => void>(); | ||
@@ -33,5 +33,5 @@ | ||
onDropExit?: (e: DropExitEvent) => void, | ||
onDropTargetEnter?: (target?: DroppableCollectionTarget) => void, | ||
onDropActivate?: (e: DropActivateEvent, target?: DroppableCollectionTarget) => void, | ||
onDrop?: (e: DropEvent, target?: DroppableCollectionTarget) => void, | ||
onDropTargetEnter?: (target: DroppableCollectionTarget | null) => void, | ||
onDropActivate?: (e: DropActivateEvent, target: DroppableCollectionTarget | null) => void, | ||
onDrop?: (e: DropEvent, target: DroppableCollectionTarget | null) => void, | ||
onKeyDown?: (e: KeyboardEvent, dragTarget: DragTarget) => void | ||
@@ -76,5 +76,7 @@ } | ||
requestAnimationFrame(() => { | ||
dragSession.setup(); | ||
if (getDragModality() === 'keyboard') { | ||
dragSession.next(); | ||
if (dragSession) { | ||
dragSession.setup(); | ||
if (getDragModality() === 'keyboard') { | ||
dragSession.next(); | ||
} | ||
} | ||
@@ -160,10 +162,10 @@ }); | ||
dragTarget: DragTarget; | ||
validDropTargets: DropTarget[]; | ||
currentDropTarget: DropTarget; | ||
currentDropItem: DroppableItem; | ||
dropOperation: DropOperation; | ||
private mutationObserver: MutationObserver; | ||
private restoreAriaHidden: () => void; | ||
validDropTargets: DropTarget[] = []; | ||
currentDropTarget: DropTarget | null = null; | ||
currentDropItem: DroppableItem | null = null; | ||
dropOperation: DropOperation | null = null; | ||
private mutationObserver: MutationObserver | null = null; | ||
private restoreAriaHidden: (() => void) | null = null; | ||
private stringFormatter: LocalizedStringFormatter; | ||
private isVirtualClick: boolean; | ||
private isVirtualClick: boolean = false; | ||
private initialFocused: boolean; | ||
@@ -217,4 +219,4 @@ | ||
this.mutationObserver.disconnect(); | ||
this.restoreAriaHidden(); | ||
this.mutationObserver?.disconnect(); | ||
this.restoreAriaHidden?.(); | ||
} | ||
@@ -460,3 +462,3 @@ | ||
setCurrentDropTarget(dropTarget: DropTarget, item?: DroppableItem) { | ||
setCurrentDropTarget(dropTarget: DropTarget | null, item?: DroppableItem) { | ||
if (dropTarget !== this.currentDropTarget) { | ||
@@ -490,8 +492,8 @@ if (this.currentDropTarget && typeof this.currentDropTarget.onDropExit === 'function') { | ||
if (item !== this.currentDropItem) { | ||
if (item && typeof this.currentDropTarget.onDropTargetEnter === 'function') { | ||
this.currentDropTarget.onDropTargetEnter(item?.target); | ||
if (item != null && item !== this.currentDropItem) { | ||
if (this.currentDropTarget && typeof this.currentDropTarget.onDropTargetEnter === 'function') { | ||
this.currentDropTarget.onDropTargetEnter(item.target); | ||
} | ||
item?.element.focus(); | ||
item.element.focus(); | ||
this.currentDropItem = item; | ||
@@ -530,3 +532,3 @@ | ||
// useDroppableCollection handles this itself, so this is only for standalone drop zones. | ||
document.activeElement.dispatchEvent(new FocusEvent('focusin', {bubbles: true})); | ||
document.activeElement?.dispatchEvent(new FocusEvent('focusin', {bubbles: true})); | ||
} | ||
@@ -578,3 +580,3 @@ | ||
dropOperation: this.dropOperation | ||
}, item?.target); | ||
}, item?.target ?? null); | ||
} | ||
@@ -593,3 +595,3 @@ | ||
y: rect.top + (rect.height / 2) | ||
}); | ||
}, null); | ||
} | ||
@@ -596,0 +598,0 @@ } |
@@ -75,7 +75,7 @@ import {Direction, DropTarget, DropTargetDelegate, Node, Orientation, RefObject} from '@react-types/shared'; | ||
getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget { | ||
if (this.collection[Symbol.iterator]().next().done) { | ||
if (this.collection[Symbol.iterator]().next().done || !this.ref.current) { | ||
return {type: 'root'}; | ||
} | ||
let rect = this.ref.current.getBoundingClientRect(); | ||
let rect: DOMRect | undefined = this.ref.current.getBoundingClientRect(); | ||
let primary = this.orientation === 'horizontal' ? x : y; | ||
@@ -94,3 +94,3 @@ let secondary = this.orientation === 'horizontal' ? y : x; | ||
for (let item of elements) { | ||
if (item instanceof HTMLElement) { | ||
if (item instanceof HTMLElement && item.dataset.key != null) { | ||
elementMap.set(item.dataset.key, item); | ||
@@ -111,2 +111,5 @@ } | ||
let element = elementMap.get(String(item.key)); | ||
if (!element) { | ||
break; | ||
} | ||
let rect = element.getBoundingClientRect(); | ||
@@ -160,5 +163,5 @@ let update = (isGreater: boolean) => { | ||
let element = elementMap.get(String(item.key)); | ||
rect = element.getBoundingClientRect(); | ||
rect = element?.getBoundingClientRect(); | ||
if (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect))) { | ||
if (rect && (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect)))) { | ||
return { | ||
@@ -165,0 +168,0 @@ type: 'item', |
@@ -32,4 +32,4 @@ /* | ||
let state = useRef({ | ||
timer: null, | ||
let state = useRef<{timer: ReturnType<typeof requestAnimationFrame> | undefined, dx: number, dy: number}>({ | ||
timer: undefined, | ||
dx: 0, | ||
@@ -43,3 +43,3 @@ dy: 0 | ||
cancelAnimationFrame(state.timer); | ||
state.timer = null; | ||
state.timer = undefined; | ||
} | ||
@@ -51,6 +51,6 @@ }; | ||
let scroll = useCallback(() => { | ||
if (scrollableX.current) { | ||
if (scrollableX.current && scrollableRef.current) { | ||
scrollableRef.current.scrollLeft += state.dx; | ||
} | ||
if (scrollableY.current) { | ||
if (scrollableY.current && scrollableRef.current) { | ||
scrollableRef.current.scrollTop += state.dy; | ||
@@ -99,3 +99,3 @@ } | ||
cancelAnimationFrame(state.timer); | ||
state.timer = null; | ||
state.timer = undefined; | ||
} | ||
@@ -102,0 +102,0 @@ } |
@@ -90,4 +90,6 @@ /* | ||
e.preventDefault(); | ||
writeToDataTransfer(e.clipboardData, options.getItems()); | ||
options.onCopy?.(); | ||
if (e.clipboardData) { | ||
writeToDataTransfer(e.clipboardData, options.getItems()); | ||
options.onCopy?.(); | ||
} | ||
}); | ||
@@ -107,4 +109,6 @@ | ||
e.preventDefault(); | ||
writeToDataTransfer(e.clipboardData, options.getItems()); | ||
options.onCut(); | ||
if (e.clipboardData) { | ||
writeToDataTransfer(e.clipboardData, options.getItems()); | ||
options.onCut(); | ||
} | ||
}); | ||
@@ -126,4 +130,6 @@ | ||
e.preventDefault(); | ||
let items = readFromDataTransfer(e.clipboardData); | ||
options.onPaste(items); | ||
if (e.clipboardData) { | ||
let items = readFromDataTransfer(e.clipboardData); | ||
options.onPaste(items); | ||
} | ||
}); | ||
@@ -130,0 +136,0 @@ |
@@ -137,2 +137,5 @@ /* | ||
options.preview.current(items, node => { | ||
if (!node) { | ||
return; | ||
} | ||
// Compute the offset that the preview will appear under the mouse. | ||
@@ -283,3 +286,3 @@ // If possible, this is based on the point the user clicked on the target. | ||
let interactions: HTMLAttributes<HTMLElement>; | ||
let interactions: HTMLAttributes<HTMLElement> = {}; | ||
if (!hasDragButton) { | ||
@@ -286,0 +289,0 @@ // If there's no separate button to trigger accessible drag and drop mode, |
@@ -18,3 +18,3 @@ /* | ||
import {DROP_EFFECT_TO_DROP_OPERATION, DROP_OPERATION, DROP_OPERATION_ALLOWED, DROP_OPERATION_TO_DROP_EFFECT} from './constants'; | ||
import {DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropMoveEvent, DropOperation, DragTypes as IDragTypes, RefObject} from '@react-types/shared'; | ||
import {DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropMoveEvent, DropOperation, FocusableElement, DragTypes as IDragTypes, RefObject} from '@react-types/shared'; | ||
import {isIPad, isMac, useEffectEvent, useLayoutEffect} from '@react-aria/utils'; | ||
@@ -25,3 +25,3 @@ import {useVirtualDrop} from './useVirtualDrop'; | ||
/** A ref for the droppable element. */ | ||
ref: RefObject<HTMLElement | null>, | ||
ref: RefObject<FocusableElement | null>, | ||
/** | ||
@@ -77,9 +77,16 @@ * A function returning the drop operation to be performed when items matching the given types are dropped | ||
let [isDropTarget, setDropTarget] = useState(false); | ||
let state = useRef({ | ||
let state = useRef<{ | ||
x: number, | ||
y: number, | ||
dragOverElements: Set<Element>, | ||
dropEffect: DataTransfer['dropEffect'], | ||
allowedOperations: DROP_OPERATION, | ||
dropActivateTimer: ReturnType<typeof setTimeout> | undefined | ||
}>({ | ||
x: 0, | ||
y: 0, | ||
dragOverElements: new Set<Element>(), | ||
dropEffect: 'none' as DataTransfer['dropEffect'], | ||
dropEffect: 'none', | ||
allowedOperations: DROP_OPERATION.all, | ||
dropActivateTimer: null | ||
dropActivateTimer: undefined | ||
}).current; | ||
@@ -170,6 +177,7 @@ | ||
if (typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') { | ||
if (options.onDropActivate && typeof options.onDropActivate === 'function' && state.dropEffect !== 'none') { | ||
let onDropActivateOptions = options.onDropActivate; | ||
let rect = (e.currentTarget as HTMLElement).getBoundingClientRect(); | ||
state.dropActivateTimer = setTimeout(() => { | ||
options.onDropActivate({ | ||
onDropActivateOptions({ | ||
type: 'dropactivate', | ||
@@ -322,3 +330,3 @@ x: state.x - rect.x, | ||
useLayoutEffect(() => { | ||
if (isDisabled) { | ||
if (isDisabled || !ref.current) { | ||
return; | ||
@@ -423,3 +431,3 @@ } | ||
function allowedOperationsToArray(allowedOperationsBits: DROP_OPERATION) { | ||
let allowedOperations = []; | ||
let allowedOperations: Array<DropOperation> = []; | ||
if (allowedOperationsBits & DROP_OPERATION.move) { | ||
@@ -426,0 +434,0 @@ allowedOperations.push('move'); |
@@ -52,6 +52,12 @@ /* | ||
let id = useId(); | ||
let getText = (key: Key) => collection.getTextValue?.(key) ?? collection.getItem(key)?.textValue; | ||
let getText = (key: Key | null) => { | ||
if (key == null) { | ||
return ''; | ||
} else { | ||
return collection.getTextValue?.(key) ?? collection.getItem(key)?.textValue ?? ''; | ||
} | ||
}; | ||
let label = ''; | ||
let labelledBy: string; | ||
let labelledBy: string | undefined; | ||
if (target.type === 'root') { | ||
@@ -65,4 +71,4 @@ label = stringFormatter.format('dropOnRoot'); | ||
} else { | ||
let before: Key | null; | ||
let after: Key | null; | ||
let before: Key | null | undefined; | ||
let after: Key | null | undefined; | ||
if (collection.getFirstKey() === target.key && target.dropPosition === 'before') { | ||
@@ -69,0 +75,0 @@ before = null; |
@@ -59,8 +59,8 @@ /* | ||
collection: Collection<Node<unknown>>, | ||
focusedKey: Key, | ||
focusedKey: Key | null, | ||
selectedKeys: Set<Key>, | ||
target: DropTarget, | ||
draggingKeys: Set<Key>, | ||
draggingKeys: Set<Key | null | undefined>, | ||
isInternal: boolean, | ||
timeout: ReturnType<typeof setTimeout> | ||
timeout: ReturnType<typeof setTimeout> | undefined | ||
} | ||
@@ -76,3 +76,8 @@ | ||
export function useDroppableCollection(props: DroppableCollectionOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>): DroppableCollectionResult { | ||
let localState = useRef({ | ||
let localState = useRef<{ | ||
props: DroppableCollectionOptions, | ||
state: DroppableCollectionState, | ||
nextTarget: DropTarget | null, | ||
dropOperation: DropOperation | null | ||
}>({ | ||
props, | ||
@@ -154,6 +159,10 @@ state, | ||
onDropEnter() { | ||
state.setTarget(localState.nextTarget); | ||
if (localState.nextTarget != null) { | ||
state.setTarget(localState.nextTarget); | ||
} | ||
}, | ||
onDropMove(e) { | ||
state.setTarget(localState.nextTarget); | ||
if (localState.nextTarget != null) { | ||
state.setTarget(localState.nextTarget); | ||
} | ||
autoScroll.move(e.x, e.y); | ||
@@ -234,3 +243,3 @@ }, | ||
} = droppingState.current; | ||
// If an insert occurs during a drop, we want to immediately select these items to give | ||
@@ -271,2 +280,3 @@ // feedback to the user that a drop occurred. Only do this if the selection didn't change | ||
} else if ( | ||
prevFocusedKey != null && | ||
state.selectionManager.focusedKey === prevFocusedKey && | ||
@@ -279,8 +289,8 @@ isInternal && | ||
// Focus row instead of cell when reordering. | ||
state.selectionManager.setFocusedKey(state.collection.getItem(prevFocusedKey).parentKey); | ||
state.selectionManager.setFocusedKey(state.collection.getItem(prevFocusedKey)?.parentKey ?? null); | ||
setInteractionModality('keyboard'); | ||
} else if ( | ||
state.selectionManager.focusedKey === prevFocusedKey && | ||
target.type === 'item' && | ||
target.dropPosition === 'on' && | ||
target.type === 'item' && | ||
target.dropPosition === 'on' && | ||
state.collection.getItem(target.key) != null | ||
@@ -293,3 +303,3 @@ ) { | ||
setInteractionModality('keyboard'); | ||
} else if (!state.selectionManager.isSelected(state.selectionManager.focusedKey)) { | ||
} else if (state.selectionManager.focusedKey != null && !state.selectionManager.isSelected(state.selectionManager.focusedKey)) { | ||
setInteractionModality('keyboard'); | ||
@@ -304,6 +314,6 @@ } | ||
let {state} = localState; | ||
// Save some state of the collection/selection before the drop occurs so we can compare later. | ||
droppingState.current = { | ||
timeout: null, | ||
timeout: undefined, | ||
focusedKey: state.selectionManager.focusedKey, | ||
@@ -354,3 +364,7 @@ collection: state.collection, | ||
useEffect(() => { | ||
let getNextTarget = (target: DropTarget, wrap = true, horizontal = false): DropTarget => { | ||
if (!ref.current) { | ||
return; | ||
} | ||
let getNextTarget = (target: DropTarget | null | undefined, wrap = true, horizontal = false): DropTarget | null => { | ||
if (!target) { | ||
@@ -363,7 +377,7 @@ return { | ||
let {keyboardDelegate} = localState.props; | ||
let nextKey: Key; | ||
let nextKey: Key | null | undefined; | ||
if (target?.type === 'item') { | ||
nextKey = horizontal ? keyboardDelegate.getKeyRightOf(target.key) : keyboardDelegate.getKeyBelow(target.key); | ||
nextKey = horizontal ? keyboardDelegate.getKeyRightOf?.(target.key) : keyboardDelegate.getKeyBelow?.(target.key); | ||
} else { | ||
nextKey = horizontal && direction === 'rtl' ? keyboardDelegate.getLastKey() : keyboardDelegate.getFirstKey(); | ||
nextKey = horizontal && direction === 'rtl' ? keyboardDelegate.getLastKey?.() : keyboardDelegate.getFirstKey?.(); | ||
} | ||
@@ -416,9 +430,9 @@ let dropPositions = horizontal && direction === 'rtl' ? DROP_POSITIONS_RTL : DROP_POSITIONS; | ||
let getPreviousTarget = (target: DropTarget, wrap = true, horizontal = false): DropTarget => { | ||
let getPreviousTarget = (target: DropTarget | null | undefined, wrap = true, horizontal = false): DropTarget | null => { | ||
let {keyboardDelegate} = localState.props; | ||
let nextKey: Key; | ||
let nextKey: Key | null | undefined; | ||
if (target?.type === 'item') { | ||
nextKey = horizontal ? keyboardDelegate.getKeyLeftOf(target.key) : keyboardDelegate.getKeyAbove(target.key); | ||
nextKey = horizontal ? keyboardDelegate.getKeyLeftOf?.(target.key) : keyboardDelegate.getKeyAbove?.(target.key); | ||
} else { | ||
nextKey = horizontal && direction === 'rtl' ? keyboardDelegate.getFirstKey() : keyboardDelegate.getLastKey(); | ||
nextKey = horizontal && direction === 'rtl' ? keyboardDelegate.getFirstKey?.() : keyboardDelegate.getLastKey?.(); | ||
} | ||
@@ -472,8 +486,8 @@ let dropPositions = horizontal && direction === 'rtl' ? DROP_POSITIONS_RTL : DROP_POSITIONS; | ||
let nextValidTarget = ( | ||
target: DropTarget, | ||
target: DropTarget | null | undefined, | ||
types: Set<string>, | ||
allowedDropOperations: DropOperation[], | ||
getNextTarget: (target: DropTarget, wrap: boolean) => DropTarget, | ||
getNextTarget: (target: DropTarget | null | undefined, wrap: boolean) => DropTarget | null, | ||
wrap = true | ||
): DropTarget => { | ||
): DropTarget | null => { | ||
let seenRoot = 0; | ||
@@ -524,3 +538,3 @@ let operation: DropOperation; | ||
let selectionManager = localState.state.selectionManager; | ||
let target: DropTarget; | ||
let target: DropTarget | null = null; | ||
// Update the drop collection ref tracker for useDroppableItem's getDropOperation isInternal check | ||
@@ -531,3 +545,3 @@ setDropCollectionRef(ref); | ||
// is after the focused key. | ||
let key = selectionManager.focusedKey; | ||
let key: Key | null | undefined = selectionManager.focusedKey; | ||
let dropPosition: DropPosition = 'after'; | ||
@@ -537,3 +551,3 @@ | ||
// For now, we assume that individual cells cannot be dropped on. | ||
let item = localState.state.collection.getItem(key); | ||
let item = key != null ? localState.state.collection.getItem(key) : null; | ||
if (item?.type === 'cell') { | ||
@@ -547,3 +561,3 @@ key = item.parentKey; | ||
// move the items down. If you select bottom up, we assume you want to move the items up. | ||
if (selectionManager.isSelected(key)) { | ||
if (key != null && selectionManager.isSelected(key)) { | ||
if (selectionManager.selectedKeys.size > 1 && selectionManager.firstSelectedKey === key) { | ||
@@ -659,15 +673,21 @@ dropPosition = 'before'; | ||
// If on the root, go to the item a page below the top. Otherwise a page below the current item. | ||
let nextKey = keyboardDelegate.getKeyPageBelow( | ||
target.type === 'item' | ||
? target.key | ||
: keyboardDelegate.getFirstKey() | ||
); | ||
let targetKey = keyboardDelegate.getFirstKey?.(); | ||
if (target.type === 'item') { | ||
targetKey = target.key; | ||
} | ||
let nextKey: Key | null = null; | ||
if (targetKey != null) { | ||
nextKey = keyboardDelegate.getKeyPageBelow(targetKey); | ||
} | ||
let dropPosition = target.type === 'item' ? target.dropPosition : 'after'; | ||
// If there is no next key, or we are starting on the last key, jump to the last possible position. | ||
if (nextKey == null || (target.type === 'item' && target.key === keyboardDelegate.getLastKey())) { | ||
nextKey = keyboardDelegate.getLastKey(); | ||
if (nextKey == null || (target.type === 'item' && target.key === keyboardDelegate.getLastKey?.())) { | ||
nextKey = keyboardDelegate.getLastKey?.() ?? null; | ||
dropPosition = 'after'; | ||
} | ||
if (nextKey == null) { | ||
break; | ||
} | ||
target = { | ||
@@ -704,3 +724,3 @@ type: 'item', | ||
// If at the top already, switch to the root. Otherwise navigate a page up. | ||
if (target.key === keyboardDelegate.getFirstKey()) { | ||
if (target.key === keyboardDelegate.getFirstKey?.()) { | ||
target = { | ||
@@ -710,9 +730,12 @@ type: 'root' | ||
} else { | ||
let nextKey = keyboardDelegate.getKeyPageAbove(target.key); | ||
let nextKey: Key | null | undefined = keyboardDelegate.getKeyPageAbove(target.key); | ||
let dropPosition = target.dropPosition; | ||
if (nextKey == null) { | ||
nextKey = keyboardDelegate.getFirstKey(); | ||
nextKey = keyboardDelegate.getFirstKey?.(); | ||
dropPosition = 'before'; | ||
} | ||
if (nextKey == null) { | ||
break; | ||
} | ||
target = { | ||
@@ -719,0 +742,0 @@ type: 'item', |
@@ -13,3 +13,4 @@ /* | ||
import {DOMAttributes} from '@react-types/shared'; | ||
import {AriaButtonProps} from '@react-types/button'; | ||
import {DOMAttributes} from 'react'; | ||
import * as DragManager from './DragManager'; | ||
@@ -23,3 +24,3 @@ // @ts-ignore | ||
interface VirtualDropResult { | ||
dropProps: DOMAttributes | ||
dropProps: AriaButtonProps & DOMAttributes<HTMLDivElement> | ||
} | ||
@@ -26,0 +27,0 @@ |
@@ -27,3 +27,3 @@ /* | ||
export function getDroppableCollectionId(state: DroppableCollectionState) { | ||
let {id} = droppableCollectionMap.get(state); | ||
let {id} = droppableCollectionMap.get(state) || {}; | ||
if (!id) { | ||
@@ -37,3 +37,3 @@ throw new Error('Droppable item outside a droppable collection'); | ||
export function getDroppableCollectionRef(state: DroppableCollectionState) { | ||
let {ref} = droppableCollectionMap.get(state); | ||
let {ref} = droppableCollectionMap.get(state) || {}; | ||
if (!ref) { | ||
@@ -57,3 +57,3 @@ throw new Error('Droppable item outside a droppable collection'); | ||
function mapModality(modality: string) { | ||
function mapModality(modality: string | null) { | ||
if (!modality) { | ||
@@ -97,3 +97,3 @@ modality = 'virtual'; | ||
let needsCustomData = false; | ||
let customData = []; | ||
let customData: Array<{}> = []; | ||
for (let item of items) { | ||
@@ -184,2 +184,5 @@ let types = Object.keys(item); | ||
let items: DropItem[] = []; | ||
if (!dataTransfer) { | ||
return items; | ||
} | ||
@@ -222,3 +225,3 @@ // If our custom drag type is available, use that. This is a JSON serialized | ||
if (typeof item.webkitGetAsEntry === 'function') { | ||
let entry: FileSystemEntry = item.webkitGetAsEntry(); | ||
let entry: FileSystemEntry | null = item.webkitGetAsEntry(); | ||
// eslint-disable-next-line max-depth | ||
@@ -278,3 +281,6 @@ if (!entry) { | ||
function createFileItem(file: File): FileDropItem { | ||
function createFileItem(file: File | null): FileDropItem { | ||
if (!file) { | ||
throw new Error('No file provided'); | ||
} | ||
return { | ||
@@ -358,3 +364,3 @@ kind: 'file', | ||
export function setDropCollectionRef(ref: RefObject<HTMLElement | null>) { | ||
export function setDropCollectionRef(ref?: RefObject<HTMLElement | null>) { | ||
globalDndState.dropCollectionRef = ref; | ||
@@ -379,4 +385,4 @@ } | ||
type DropEffect = 'none' | 'copy' | 'link' | 'move'; | ||
export let globalDropEffect: DropEffect; | ||
export function setGlobalDropEffect(dropEffect: DropEffect) { | ||
export let globalDropEffect: DropEffect | undefined; | ||
export function setGlobalDropEffect(dropEffect: DropEffect | undefined) { | ||
globalDropEffect = dropEffect; | ||
@@ -383,0 +389,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1726111
16216
+ Added@internationalized/date@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@internationalized/message@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@internationalized/number@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@internationalized/string@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-aria/focus@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-aria/i18n@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-aria/interactions@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-aria/live-announcer@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-aria/overlays@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-aria/ssr@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-aria/utils@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-aria/visually-hidden@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-stately/collections@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-stately/dnd@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-stately/overlays@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-stately/selection@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-stately/utils@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-types/button@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-types/overlays@3.0.0-nightly-101d0772b-250111(transitive)
+ Added@react-types/shared@3.0.0-nightly-101d0772b-250111(transitive)
- Removed@internationalized/date@3.6.0(transitive)
- Removed@internationalized/message@3.1.6(transitive)
- Removed@internationalized/number@3.6.0(transitive)
- Removed@internationalized/string@3.2.5(transitive)
- Removed@react-aria/focus@3.19.0(transitive)
- Removed@react-aria/i18n@3.12.4(transitive)
- Removed@react-aria/interactions@3.22.5(transitive)
- Removed@react-aria/live-announcer@3.4.1(transitive)
- Removed@react-aria/overlays@3.24.0(transitive)
- Removed@react-aria/ssr@3.9.7(transitive)
- Removed@react-aria/utils@3.26.0(transitive)
- Removed@react-aria/visually-hidden@3.8.18(transitive)
- Removed@react-stately/collections@3.12.0(transitive)
- Removed@react-stately/dnd@3.5.0(transitive)
- Removed@react-stately/overlays@3.6.12(transitive)
- Removed@react-stately/selection@3.18.0(transitive)
- Removed@react-stately/utils@3.10.5(transitive)
- Removed@react-types/button@3.10.1(transitive)
- Removed@react-types/overlays@3.8.11(transitive)
- Removed@react-types/shared@3.26.0(transitive)
Updated@internationalized/string@3.0.0-nightly-101d0772b-250111
Updated@react-aria/interactions@3.0.0-nightly-101d0772b-250111
Updated@react-aria/live-announcer@3.0.0-nightly-101d0772b-250111