Merge pull request #5350 from xyflow/fix/node-drag-snap-grid
xydrag: only send position changes if changed
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@xyflow/system': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Only send node position updates if positions changed
|
||||||
@@ -104,6 +104,7 @@ export function XYDrag<OnNodeDrag extends (e: any, nodes: any, node: any) => voi
|
|||||||
let dragStarted = false;
|
let dragStarted = false;
|
||||||
let d3Selection: Selection<Element, unknown, null, undefined> | null = null;
|
let d3Selection: Selection<Element, unknown, null, undefined> | null = null;
|
||||||
let abortDrag = false; // prevents unintentional dragging on multitouch
|
let abortDrag = false; // prevents unintentional dragging on multitouch
|
||||||
|
let nodePositionsChanged = false;
|
||||||
|
|
||||||
// public functions
|
// public functions
|
||||||
function update({
|
function update({
|
||||||
@@ -191,6 +192,8 @@ export function XYDrag<OnNodeDrag extends (e: any, nodes: any, node: any) => voi
|
|||||||
dragItem.internals.positionAbsolute = positionAbsolute;
|
dragItem.internals.positionAbsolute = positionAbsolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodePositionsChanged = nodePositionsChanged || hasChange;
|
||||||
|
|
||||||
if (!hasChange) {
|
if (!hasChange) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -294,6 +297,7 @@ export function XYDrag<OnNodeDrag extends (e: any, nodes: any, node: any) => voi
|
|||||||
containerBounds = domNode?.getBoundingClientRect() || null;
|
containerBounds = domNode?.getBoundingClientRect() || null;
|
||||||
|
|
||||||
abortDrag = false;
|
abortDrag = false;
|
||||||
|
nodePositionsChanged = false;
|
||||||
|
|
||||||
if (nodeDragThreshold === 0) {
|
if (nodeDragThreshold === 0) {
|
||||||
startDrag(event);
|
startDrag(event);
|
||||||
@@ -354,7 +358,10 @@ export function XYDrag<OnNodeDrag extends (e: any, nodes: any, node: any) => voi
|
|||||||
if (dragItems.size > 0) {
|
if (dragItems.size > 0) {
|
||||||
const { nodeLookup, updateNodePositions, onNodeDragStop, onSelectionDragStop } = getStoreItems();
|
const { nodeLookup, updateNodePositions, onNodeDragStop, onSelectionDragStop } = getStoreItems();
|
||||||
|
|
||||||
updateNodePositions(dragItems, false);
|
if (nodePositionsChanged) {
|
||||||
|
updateNodePositions(dragItems, false);
|
||||||
|
nodePositionsChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (onDragStop || onNodeDragStop || (!nodeId && onSelectionDragStop)) {
|
if (onDragStop || onNodeDragStop || (!nodeId && onSelectionDragStop)) {
|
||||||
const [currentNode, currentNodes] = getEventHandlerParams({
|
const [currentNode, currentNodes] = getEventHandlerParams({
|
||||||
|
|||||||
Reference in New Issue
Block a user