@react-stately/dnd
Advanced tools
Comparing version 3.3.1-nightly.4624 to 3.3.1
@@ -60,3 +60,3 @@ var $ijIvR$react = require("react"); | ||
setDragging(true); | ||
if (typeof onDragStart === "function") onDragStart({ | ||
if (typeof onDragStart === 'function') onDragStart({ | ||
...event, | ||
@@ -67,3 +67,3 @@ keys: keys | ||
moveDrag (event) { | ||
if (typeof onDragMove === "function") onDragMove({ | ||
if (typeof onDragMove === 'function') onDragMove({ | ||
...event, | ||
@@ -75,3 +75,3 @@ keys: draggingKeys.current | ||
let { isInternal: isInternal } = event; | ||
if (typeof onDragEnd === "function") onDragEnd({ | ||
if (typeof onDragEnd === 'function') onDragEnd({ | ||
...event, | ||
@@ -78,0 +78,0 @@ keys: draggingKeys.current, |
@@ -54,3 +54,3 @@ import {useState as $8rdZD$useState, useRef as $8rdZD$useRef} from "react"; | ||
setDragging(true); | ||
if (typeof onDragStart === "function") onDragStart({ | ||
if (typeof onDragStart === 'function') onDragStart({ | ||
...event, | ||
@@ -61,3 +61,3 @@ keys: keys | ||
moveDrag (event) { | ||
if (typeof onDragMove === "function") onDragMove({ | ||
if (typeof onDragMove === 'function') onDragMove({ | ||
...event, | ||
@@ -69,3 +69,3 @@ keys: draggingKeys.current | ||
let { isInternal: isInternal } = event; | ||
if (typeof onDragEnd === "function") onDragEnd({ | ||
if (typeof onDragEnd === 'function') onDragEnd({ | ||
...event, | ||
@@ -72,0 +72,0 @@ keys: draggingKeys.current, |
@@ -21,19 +21,19 @@ var $ax21c$react = require("react"); | ||
function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) { | ||
let { acceptedDragTypes: acceptedDragTypes = "all", isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props; | ||
let { acceptedDragTypes: acceptedDragTypes = 'all', isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props; | ||
let [target, setTarget] = (0, $ax21c$react.useState)(null); | ||
let targetRef = (0, $ax21c$react.useRef)(null); | ||
let getOppositeTarget = (target)=>{ | ||
if (target.dropPosition === "before") { | ||
if (target.dropPosition === 'before') { | ||
let key = collection.getKeyBefore(target.key); | ||
return key != null ? { | ||
type: "item", | ||
type: 'item', | ||
key: key, | ||
dropPosition: "after" | ||
dropPosition: 'after' | ||
} : null; | ||
} else if (target.dropPosition === "after") { | ||
} else if (target.dropPosition === 'after') { | ||
let key = collection.getKeyAfter(target.key); | ||
return key != null ? { | ||
type: "item", | ||
type: 'item', | ||
key: key, | ||
dropPosition: "before" | ||
dropPosition: 'before' | ||
} : null; | ||
@@ -43,11 +43,11 @@ } | ||
let defaultGetDropOperation = (0, $ax21c$react.useCallback)((e)=>{ | ||
if (isDisabled) return "cancel"; | ||
if (isDisabled) return 'cancel'; | ||
let { target: target, types: types, allowedOperations: allowedOperations, isInternal: isInternal, draggingKeys: draggingKeys } = e; | ||
if (acceptedDragTypes === "all" || acceptedDragTypes.some((type)=>types.has(type))) { | ||
let isValidInsert = onInsert && target.type === "item" && !isInternal && (target.dropPosition === "before" || target.dropPosition === "after"); | ||
let isValidReorder = onReorder && target.type === "item" && isInternal && (target.dropPosition === "before" || target.dropPosition === "after"); | ||
if (acceptedDragTypes === 'all' || acceptedDragTypes.some((type)=>types.has(type))) { | ||
let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after'); | ||
let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after'); | ||
// Feedback was that internal root drop was weird so preventing that from happening | ||
let isValidRootDrop = onRootDrop && target.type === "root" && !isInternal; | ||
let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal; | ||
// 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 && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types)); | ||
if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) { | ||
@@ -58,3 +58,3 @@ if (getDropOperation) return getDropOperation(target, types, allowedOperations); | ||
} | ||
return "cancel"; | ||
return 'cancel'; | ||
}, [ | ||
@@ -79,4 +79,4 @@ isDisabled, | ||
let target = targetRef.current; | ||
if (target && typeof props.onDropExit === "function") props.onDropExit({ | ||
type: "dropexit", | ||
if (target && typeof props.onDropExit === 'function') props.onDropExit({ | ||
type: 'dropexit', | ||
x: 0, | ||
@@ -86,4 +86,4 @@ y: 0, | ||
}); | ||
if (newTarget && typeof onDropEnter === "function") onDropEnter({ | ||
type: "dropenter", | ||
if (newTarget && typeof onDropEnter === 'function') onDropEnter({ | ||
type: 'dropenter', | ||
x: 0, | ||
@@ -100,3 +100,3 @@ y: 0, | ||
// Check if the targets point at the same point between two items, one referring before, and the other after. | ||
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === "item" && (target === null || target === void 0 ? void 0 : target.type) === "item" && dropTarget.key !== target.key && dropTarget.dropPosition !== target.dropPosition && dropTarget.dropPosition !== "on" && target.dropPosition !== "on") return $6ce4cbfbe5e354f1$var$isEqualDropTarget(getOppositeTarget(dropTarget), target) || $6ce4cbfbe5e354f1$var$isEqualDropTarget(dropTarget, getOppositeTarget(target)); | ||
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === 'item' && (target === null || target === void 0 ? void 0 : target.type) === 'item' && dropTarget.key !== target.key && dropTarget.dropPosition !== target.dropPosition && dropTarget.dropPosition !== 'on' && target.dropPosition !== 'on') return $6ce4cbfbe5e354f1$var$isEqualDropTarget(getOppositeTarget(dropTarget), target) || $6ce4cbfbe5e354f1$var$isEqualDropTarget(dropTarget, getOppositeTarget(target)); | ||
return false; | ||
@@ -112,6 +112,6 @@ }, | ||
switch(a.type){ | ||
case "root": | ||
return (b === null || b === void 0 ? void 0 : b.type) === "root"; | ||
case "item": | ||
return (b === null || b === void 0 ? void 0 : b.type) === "item" && (b === null || b === void 0 ? void 0 : b.key) === a.key && (b === null || b === void 0 ? void 0 : b.dropPosition) === a.dropPosition; | ||
case 'root': | ||
return (b === null || b === void 0 ? void 0 : b.type) === 'root'; | ||
case 'item': | ||
return (b === null || b === void 0 ? void 0 : b.type) === 'item' && (b === null || b === void 0 ? void 0 : b.key) === a.key && (b === null || b === void 0 ? void 0 : b.dropPosition) === a.dropPosition; | ||
} | ||
@@ -118,0 +118,0 @@ } |
@@ -15,19 +15,19 @@ import {useState as $lyPoT$useState, useRef as $lyPoT$useRef, useCallback as $lyPoT$useCallback} from "react"; | ||
function $e672e8bc247525d1$export$926850f6ecef79d0(props) { | ||
let { acceptedDragTypes: acceptedDragTypes = "all", isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props; | ||
let { acceptedDragTypes: acceptedDragTypes = 'all', isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props; | ||
let [target, setTarget] = (0, $lyPoT$useState)(null); | ||
let targetRef = (0, $lyPoT$useRef)(null); | ||
let getOppositeTarget = (target)=>{ | ||
if (target.dropPosition === "before") { | ||
if (target.dropPosition === 'before') { | ||
let key = collection.getKeyBefore(target.key); | ||
return key != null ? { | ||
type: "item", | ||
type: 'item', | ||
key: key, | ||
dropPosition: "after" | ||
dropPosition: 'after' | ||
} : null; | ||
} else if (target.dropPosition === "after") { | ||
} else if (target.dropPosition === 'after') { | ||
let key = collection.getKeyAfter(target.key); | ||
return key != null ? { | ||
type: "item", | ||
type: 'item', | ||
key: key, | ||
dropPosition: "before" | ||
dropPosition: 'before' | ||
} : null; | ||
@@ -37,11 +37,11 @@ } | ||
let defaultGetDropOperation = (0, $lyPoT$useCallback)((e)=>{ | ||
if (isDisabled) return "cancel"; | ||
if (isDisabled) return 'cancel'; | ||
let { target: target, types: types, allowedOperations: allowedOperations, isInternal: isInternal, draggingKeys: draggingKeys } = e; | ||
if (acceptedDragTypes === "all" || acceptedDragTypes.some((type)=>types.has(type))) { | ||
let isValidInsert = onInsert && target.type === "item" && !isInternal && (target.dropPosition === "before" || target.dropPosition === "after"); | ||
let isValidReorder = onReorder && target.type === "item" && isInternal && (target.dropPosition === "before" || target.dropPosition === "after"); | ||
if (acceptedDragTypes === 'all' || acceptedDragTypes.some((type)=>types.has(type))) { | ||
let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after'); | ||
let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after'); | ||
// Feedback was that internal root drop was weird so preventing that from happening | ||
let isValidRootDrop = onRootDrop && target.type === "root" && !isInternal; | ||
let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal; | ||
// 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 && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types)); | ||
if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) { | ||
@@ -52,3 +52,3 @@ if (getDropOperation) return getDropOperation(target, types, allowedOperations); | ||
} | ||
return "cancel"; | ||
return 'cancel'; | ||
}, [ | ||
@@ -73,4 +73,4 @@ isDisabled, | ||
let target = targetRef.current; | ||
if (target && typeof props.onDropExit === "function") props.onDropExit({ | ||
type: "dropexit", | ||
if (target && typeof props.onDropExit === 'function') props.onDropExit({ | ||
type: 'dropexit', | ||
x: 0, | ||
@@ -80,4 +80,4 @@ y: 0, | ||
}); | ||
if (newTarget && typeof onDropEnter === "function") onDropEnter({ | ||
type: "dropenter", | ||
if (newTarget && typeof onDropEnter === 'function') onDropEnter({ | ||
type: 'dropenter', | ||
x: 0, | ||
@@ -94,3 +94,3 @@ y: 0, | ||
// Check if the targets point at the same point between two items, one referring before, and the other after. | ||
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === "item" && (target === null || target === void 0 ? void 0 : target.type) === "item" && dropTarget.key !== target.key && dropTarget.dropPosition !== target.dropPosition && dropTarget.dropPosition !== "on" && target.dropPosition !== "on") return $e672e8bc247525d1$var$isEqualDropTarget(getOppositeTarget(dropTarget), target) || $e672e8bc247525d1$var$isEqualDropTarget(dropTarget, getOppositeTarget(target)); | ||
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === 'item' && (target === null || target === void 0 ? void 0 : target.type) === 'item' && dropTarget.key !== target.key && dropTarget.dropPosition !== target.dropPosition && dropTarget.dropPosition !== 'on' && target.dropPosition !== 'on') return $e672e8bc247525d1$var$isEqualDropTarget(getOppositeTarget(dropTarget), target) || $e672e8bc247525d1$var$isEqualDropTarget(dropTarget, getOppositeTarget(target)); | ||
return false; | ||
@@ -106,6 +106,6 @@ }, | ||
switch(a.type){ | ||
case "root": | ||
return (b === null || b === void 0 ? void 0 : b.type) === "root"; | ||
case "item": | ||
return (b === null || b === void 0 ? void 0 : b.type) === "item" && (b === null || b === void 0 ? void 0 : b.key) === a.key && (b === null || b === void 0 ? void 0 : b.dropPosition) === a.dropPosition; | ||
case 'root': | ||
return (b === null || b === void 0 ? void 0 : b.type) === 'root'; | ||
case 'item': | ||
return (b === null || b === void 0 ? void 0 : b.type) === 'item' && (b === null || b === void 0 ? void 0 : b.key) === a.key && (b === null || b === void 0 ? void 0 : b.dropPosition) === a.dropPosition; | ||
} | ||
@@ -112,0 +112,0 @@ } |
{ | ||
"name": "@react-stately/dnd", | ||
"version": "3.3.1-nightly.4624+d80999e89", | ||
"version": "3.3.1", | ||
"description": "Spectrum UI components in React", | ||
@@ -25,4 +25,4 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@react-stately/selection": "3.0.0-nightly.2912+d80999e89", | ||
"@react-types/shared": "3.0.0-nightly.2912+d80999e89", | ||
"@react-stately/selection": "^3.15.1", | ||
"@react-types/shared": "^3.23.1", | ||
"@swc/helpers": "^0.5.0" | ||
@@ -36,3 +36,3 @@ }, | ||
}, | ||
"gitHead": "d80999e897b4d4db9fcfb4e9b8fcdc9fdd700882" | ||
"gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433" | ||
} |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
0
96506
+ Added@react-stately/collections@3.12.0(transitive)
+ Added@react-stately/selection@3.18.0(transitive)
+ Added@react-stately/utils@3.10.5(transitive)
+ Added@react-types/shared@3.26.0(transitive)
Updated@react-types/shared@^3.23.1