@react-stately/dnd
Advanced tools
Comparing version 3.0.0-nightly-987f174ba-241015 to 3.0.0-nightly-993de98ad-241210
@@ -68,5 +68,5 @@ import { Collection, DraggableCollectionEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, Key, Node, RefObject, DragTypes, DroppableCollectionProps, DropTarget } from "@react-types/shared"; | ||
/** Sets the current drop target. */ | ||
setTarget(target: DropTarget): void; | ||
setTarget(target: DropTarget | null): void; | ||
/** Returns whether the given target is equivalent to the current drop target. */ | ||
isDropTarget(target: DropTarget): boolean; | ||
isDropTarget(target: DropTarget | null): boolean; | ||
/** Returns the drop operation for the given parameters. */ | ||
@@ -73,0 +73,0 @@ getDropOperation(e: DropOperationEvent): DropOperation; |
@@ -40,6 +40,7 @@ var $ax21c$react = require("react"); | ||
} | ||
return null; | ||
}; | ||
let defaultGetDropOperation = (0, $ax21c$react.useCallback)((e)=>{ | ||
if (isDisabled) return 'cancel'; | ||
let { target: target, types: types, allowedOperations: allowedOperations, isInternal: isInternal, draggingKeys: draggingKeys } = e; | ||
if (isDisabled || !target) return 'cancel'; | ||
if (acceptedDragTypes === 'all' || acceptedDragTypes.some((type)=>types.has(type))) { | ||
@@ -51,3 +52,3 @@ let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after'); | ||
// Automatically prevent items (i.e. folders) from being dropped on themselves. | ||
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types)); | ||
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types)); | ||
if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) { | ||
@@ -90,7 +91,8 @@ if (getDropOperation) return getDropOperation(target, types, allowedOperations); | ||
}); | ||
targetRef.current = newTarget; | ||
setTarget(newTarget); | ||
targetRef.current = newTarget !== null && newTarget !== void 0 ? newTarget : null; | ||
setTarget(newTarget !== null && newTarget !== void 0 ? newTarget : null); | ||
}, | ||
isDropTarget (dropTarget) { | ||
let target = targetRef.current; | ||
if (!target || !dropTarget) return false; | ||
if ($6ce4cbfbe5e354f1$var$isEqualDropTarget(dropTarget, target)) return true; | ||
@@ -97,0 +99,0 @@ // Check if the targets point at the same point between two items, one referring before, and the other after. |
@@ -34,6 +34,7 @@ import {useState as $lyPoT$useState, useRef as $lyPoT$useRef, useCallback as $lyPoT$useCallback} from "react"; | ||
} | ||
return null; | ||
}; | ||
let defaultGetDropOperation = (0, $lyPoT$useCallback)((e)=>{ | ||
if (isDisabled) return 'cancel'; | ||
let { target: target, types: types, allowedOperations: allowedOperations, isInternal: isInternal, draggingKeys: draggingKeys } = e; | ||
if (isDisabled || !target) return 'cancel'; | ||
if (acceptedDragTypes === 'all' || acceptedDragTypes.some((type)=>types.has(type))) { | ||
@@ -45,3 +46,3 @@ let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after'); | ||
// Automatically prevent items (i.e. folders) from being dropped on themselves. | ||
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types)); | ||
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types)); | ||
if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) { | ||
@@ -84,7 +85,8 @@ if (getDropOperation) return getDropOperation(target, types, allowedOperations); | ||
}); | ||
targetRef.current = newTarget; | ||
setTarget(newTarget); | ||
targetRef.current = newTarget !== null && newTarget !== void 0 ? newTarget : null; | ||
setTarget(newTarget !== null && newTarget !== void 0 ? newTarget : null); | ||
}, | ||
isDropTarget (dropTarget) { | ||
let target = targetRef.current; | ||
if (!target || !dropTarget) return false; | ||
if ($e672e8bc247525d1$var$isEqualDropTarget(dropTarget, target)) return true; | ||
@@ -91,0 +93,0 @@ // Check if the targets point at the same point between two items, one referring before, and the other after. |
{ | ||
"name": "@react-stately/dnd", | ||
"version": "3.0.0-nightly-987f174ba-241015", | ||
"version": "3.0.0-nightly-993de98ad-241210", | ||
"description": "Spectrum UI components in React", | ||
@@ -25,8 +25,8 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@react-stately/selection": "^3.0.0-nightly-987f174ba-241015", | ||
"@react-types/shared": "^3.0.0-nightly-987f174ba-241015", | ||
"@react-stately/selection": "^3.0.0-nightly-993de98ad-241210", | ||
"@react-types/shared": "^3.0.0-nightly-993de98ad-241210", | ||
"@swc/helpers": "^0.5.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^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" | ||
}, | ||
@@ -36,3 +36,3 @@ "publishConfig": { | ||
}, | ||
"stableVersion": "3.4.3" | ||
"stableVersion": "3.5.0" | ||
} |
@@ -72,3 +72,3 @@ /* | ||
let draggingKeys = useRef(new Set<Key>()); | ||
let draggedKey = useRef(null); | ||
let draggedKey = useRef<Key | null>(null); | ||
let getKeys = (key: Key) => { | ||
@@ -75,0 +75,0 @@ // The clicked item is always added to the drag. If it is selected, then all of the |
@@ -44,5 +44,5 @@ /* | ||
/** Sets the current drop target. */ | ||
setTarget(target: DropTarget): void, | ||
setTarget(target: DropTarget | null): void, | ||
/** Returns whether the given target is equivalent to the current drop target. */ | ||
isDropTarget(target: DropTarget): boolean, | ||
isDropTarget(target: DropTarget | null): boolean, | ||
/** Returns the drop operation for the given parameters. */ | ||
@@ -70,6 +70,6 @@ getDropOperation(e: DropOperationEvent): DropOperation | ||
} = props; | ||
let [target, setTarget] = useState<DropTarget>(null); | ||
let targetRef = useRef<DropTarget>(null); | ||
let [target, setTarget] = useState<DropTarget | null>(null); | ||
let targetRef = useRef<DropTarget | null>(null); | ||
let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => { | ||
let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget | null => { | ||
if (target.dropPosition === 'before') { | ||
@@ -82,9 +82,6 @@ let key = collection.getKeyBefore(target.key); | ||
} | ||
return null; | ||
}; | ||
let defaultGetDropOperation = useCallback((e: DropOperationEvent) => { | ||
if (isDisabled) { | ||
return 'cancel'; | ||
} | ||
let { | ||
@@ -98,2 +95,6 @@ target, | ||
if (isDisabled || !target) { | ||
return 'cancel'; | ||
} | ||
if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) { | ||
@@ -105,3 +106,3 @@ let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after'); | ||
// Automatically prevent items (i.e. folders) from being dropped on themselves. | ||
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types)); | ||
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types)); | ||
@@ -149,7 +150,10 @@ if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) { | ||
targetRef.current = newTarget; | ||
setTarget(newTarget); | ||
targetRef.current = newTarget ?? null; | ||
setTarget(newTarget ?? null); | ||
}, | ||
isDropTarget(dropTarget) { | ||
let target = targetRef.current; | ||
if (!target || !dropTarget) { | ||
return false; | ||
} | ||
if (isEqualDropTarget(dropTarget, target)) { | ||
@@ -180,3 +184,3 @@ return true; | ||
function isEqualDropTarget(a: DropTarget, b: DropTarget) { | ||
function isEqualDropTarget(a?: DropTarget | null, b?: DropTarget | null) { | ||
if (!a) { | ||
@@ -183,0 +187,0 @@ return !b; |
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
86736
1019