Fix #5633
This commit is contained in:
@@ -14,6 +14,8 @@ import {
|
|||||||
NodeOrigin,
|
NodeOrigin,
|
||||||
CoordinateExtent,
|
CoordinateExtent,
|
||||||
fitViewport,
|
fitViewport,
|
||||||
|
getHandlePosition,
|
||||||
|
Position,
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import { applyEdgeChanges, applyNodeChanges, createSelectionChange, getSelectionChanges } from '../utils/changes';
|
import { applyEdgeChanges, applyNodeChanges, createSelectionChange, getSelectionChanges } from '../utils/changes';
|
||||||
@@ -176,7 +178,7 @@ const createStore = ({
|
|||||||
updateNodePositions: (nodeDragItems, dragging = false) => {
|
updateNodePositions: (nodeDragItems, dragging = false) => {
|
||||||
const parentExpandChildren: ParentExpandChild[] = [];
|
const parentExpandChildren: ParentExpandChild[] = [];
|
||||||
const changes = [];
|
const changes = [];
|
||||||
const { nodeLookup, triggerNodeChanges } = get();
|
const { nodeLookup, triggerNodeChanges, connection, updateConnection } = get();
|
||||||
|
|
||||||
for (const [id, dragItem] of nodeDragItems) {
|
for (const [id, dragItem] of nodeDragItems) {
|
||||||
// we are using the nodelookup to be sure to use the current expandParent and parentId value
|
// we are using the nodelookup to be sure to use the current expandParent and parentId value
|
||||||
@@ -188,13 +190,18 @@ const createStore = ({
|
|||||||
type: 'position',
|
type: 'position',
|
||||||
position: expandParent
|
position: expandParent
|
||||||
? {
|
? {
|
||||||
x: Math.max(0, dragItem.position.x),
|
x: Math.max(0, dragItem.position.x),
|
||||||
y: Math.max(0, dragItem.position.y),
|
y: Math.max(0, dragItem.position.y),
|
||||||
}
|
}
|
||||||
: dragItem.position,
|
: dragItem.position,
|
||||||
dragging,
|
dragging,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (node && connection.inProgress && connection.fromNode.id == node.id) {
|
||||||
|
const updatedFrom = getHandlePosition(node, connection.fromHandle, Position.Left, true);
|
||||||
|
updateConnection({...connection,from: updatedFrom})
|
||||||
|
}
|
||||||
|
|
||||||
if (expandParent && node.parentId) {
|
if (expandParent && node.parentId) {
|
||||||
parentExpandChildren.push({
|
parentExpandChildren.push({
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import {
|
|||||||
updateAbsolutePositions,
|
updateAbsolutePositions,
|
||||||
snapPosition,
|
snapPosition,
|
||||||
calculateNodePosition,
|
calculateNodePosition,
|
||||||
type SetCenterOptions
|
type SetCenterOptions,
|
||||||
|
getHandlePosition,
|
||||||
|
Position
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import type { EdgeTypes, NodeTypes, Node, Edge, FitViewOptions } from '$lib/types';
|
import type { EdgeTypes, NodeTypes, Node, Edge, FitViewOptions } from '$lib/types';
|
||||||
@@ -51,6 +53,13 @@ export function createStore<NodeType extends Node = Node, EdgeType extends Edge
|
|||||||
|
|
||||||
const updateNodePositions: UpdateNodePositions = (nodeDragItems, dragging = false) => {
|
const updateNodePositions: UpdateNodePositions = (nodeDragItems, dragging = false) => {
|
||||||
store.nodes = store.nodes.map((node) => {
|
store.nodes = store.nodes.map((node) => {
|
||||||
|
if (store.connection.inProgress && store.connection.fromNode.id === node.id) {
|
||||||
|
|
||||||
|
store.connection = {
|
||||||
|
...store.connection,
|
||||||
|
from: getHandlePosition(store.nodeLookup.get(node.id), store.connection.fromHandle, Position.Left, true)
|
||||||
|
};
|
||||||
|
}
|
||||||
const dragItem = nodeDragItems.get(node.id);
|
const dragItem = nodeDragItems.get(node.id);
|
||||||
return dragItem ? { ...node, position: dragItem.position, dragging } : node;
|
return dragItem ? { ...node, position: dragItem.position, dragging } : node;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -172,9 +172,12 @@ function onPointerDown(
|
|||||||
connection = result.connection;
|
connection = result.connection;
|
||||||
isValid = isConnectionValid(!!closestHandle, result.isValid);
|
isValid = isConnectionValid(!!closestHandle, result.isValid);
|
||||||
|
|
||||||
|
const fromNodeInternal = nodeLookup.get(nodeId)!;
|
||||||
|
const from = getHandlePosition(fromNodeInternal, fromHandle, Position.Left, true);
|
||||||
|
|
||||||
const newConnection: ConnectionInProgress = {
|
const newConnection: ConnectionInProgress = {
|
||||||
// from stays the same
|
|
||||||
...previousConnection,
|
...previousConnection,
|
||||||
|
from,
|
||||||
isValid,
|
isValid,
|
||||||
to:
|
to:
|
||||||
result.toHandle && isValid
|
result.toHandle && isValid
|
||||||
|
|||||||
Reference in New Issue
Block a user