Browse Source

fix drag and drop (#6553)

pull/6555/head
mohamed yahia 7 months ago
committed by GitHub
parent
commit
d2d87dfd2b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 25
      packages/core/src/utils/sorter/DropLocationDeterminer.ts

25
packages/core/src/utils/sorter/DropLocationDeterminer.ts

@ -117,6 +117,7 @@ export class DropLocationDeterminer<T, NodeType extends SortableTreeNode<T>> ext
this.adjustForScroll(); this.adjustForScroll();
const { targetNode: lastTargetNode } = this.lastMoveData; const { targetNode: lastTargetNode } = this.lastMoveData;
this.eventHandlers.onMouseMove?.(mouseEvent); this.eventHandlers.onMouseMove?.(mouseEvent);
this.cacheContainerPosition();
const { mouseXRelative: mouseX, mouseYRelative: mouseY } = this.getMousePositionRelativeToContainer( const { mouseXRelative: mouseX, mouseYRelative: mouseY } = this.getMousePositionRelativeToContainer(
mouseEvent.clientX, mouseEvent.clientX,
mouseEvent.clientY, mouseEvent.clientY,
@ -279,17 +280,6 @@ export class DropLocationDeterminer<T, NodeType extends SortableTreeNode<T>> ext
return newHoveredNode; return newHoveredNode;
} }
/**
* Checks if the target node has changed and returns the last one if they are identical.
*
* @param targetNode - The newly calculated target node.
* @returns The new or reused target node.
*/
private getOrReuseTargetNode(targetNode?: NodeType): NodeType | undefined {
const lastTargetNode = this.lastMoveData.targetNode;
return targetNode?.equals(lastTargetNode) ? lastTargetNode : targetNode;
}
private getMouseTargetElement(mouseEvent: MouseEvent) { private getMouseTargetElement(mouseEvent: MouseEvent) {
const customTarget = this.containerContext.customTarget; const customTarget = this.containerContext.customTarget;
let mouseTarget = this.containerContext.document.elementFromPoint( let mouseTarget = this.containerContext.document.elementFromPoint(
@ -382,16 +372,22 @@ export class DropLocationDeterminer<T, NodeType extends SortableTreeNode<T>> ext
targetNode: lastTargetNode, targetNode: lastTargetNode,
hoveredNode: lastHoveredNode, hoveredNode: lastHoveredNode,
hoveredIndex: lastHoveredIndex, hoveredIndex: lastHoveredIndex,
mouseEvent: lastMouseEvent,
} = this.lastMoveData; } = this.lastMoveData;
const sameHoveredNode = targetNode.equals(lastHoveredNode); const sameHoveredNode = targetNode.equals(lastHoveredNode);
targetNode.nodeDimensions = sameHoveredNode ? lastHoveredNode!.nodeDimensions! : this.getDim(targetNode.element!); targetNode.nodeDimensions = sameHoveredNode ? lastHoveredNode!.nodeDimensions! : this.getDim(targetNode.element!);
const hoverIndex = this.getIndexInParent(targetNode, targetNode.nodeDimensions!, mouseX, mouseY); const hoverIndex = this.getIndexInParent(targetNode, targetNode.nodeDimensions!, mouseX, mouseY);
const sameHoveredIndex = hoverIndex === lastHoveredIndex; const sameHoveredIndex = hoverIndex === lastHoveredIndex;
const sameHoverPosition = sameHoveredNode && sameHoveredIndex; const isWithinDropArea = targetNode.isWithinDropBounds(mouseX, mouseY);
const sameHoverPosition =
sameHoveredNode &&
sameHoveredIndex &&
isWithinDropArea === targetNode.isWithinDropBounds(lastMouseEvent?.clientX ?? 0, lastMouseEvent?.clientY ?? 0);
if (sameHoverPosition && lastTargetNode) return lastTargetNode; if (sameHoverPosition && lastTargetNode) return lastTargetNode;
if (!targetNode.isWithinDropBounds(mouseX, mouseY)) { if (!isWithinDropArea) {
return this.handleParentTraversal(targetNode, mouseX, mouseY); return this.handleParentTraversal(targetNode, mouseX, mouseY);
} }
@ -532,7 +528,8 @@ export class DropLocationDeterminer<T, NodeType extends SortableTreeNode<T>> ext
* *
* @private * @private
*/ */
private cacheContainerPosition(container: HTMLElement): void { private cacheContainerPosition(): void {
const container = this.containerContext.container;
const containerOffset = offset(container); const containerOffset = offset(container);
const containerOffsetTop = this.positionOptions.windowMargin ? Math.abs(containerOffset.top) : containerOffset.top; const containerOffsetTop = this.positionOptions.windowMargin ? Math.abs(containerOffset.top) : containerOffset.top;
const containerOffsetLeft = this.positionOptions.windowMargin const containerOffsetLeft = this.positionOptions.windowMargin

Loading…
Cancel
Save