chore(xyhandle): cleanup

This commit is contained in:
moklick
2025-11-25 11:01:27 +01:00
parent 99453f0993
commit f617616dc9
3 changed files with 22 additions and 18 deletions

View File

@@ -190,16 +190,16 @@ const createStore = ({
type: 'position',
position: expandParent
? {
x: Math.max(0, dragItem.position.x),
y: Math.max(0, dragItem.position.y),
}
x: Math.max(0, dragItem.position.x),
y: Math.max(0, dragItem.position.y),
}
: dragItem.position,
dragging,
};
if (node && connection.inProgress && connection.fromNode.id == node.id) {
if (node && connection.inProgress && connection.fromNode.id === node.id) {
const updatedFrom = getHandlePosition(node, connection.fromHandle, Position.Left, true);
updateConnection({...connection,from: updatedFrom})
updateConnection({ ...connection, from: updatedFrom });
}
if (expandParent && node.parentId) {

View File

@@ -52,13 +52,15 @@ export function createStore<NodeType extends Node = Node, EdgeType extends Edge
}
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 internalNode = store.nodeLookup.get(node.id);
if (internalNode) {
store.connection = {
...store.connection,
from: getHandlePosition(internalNode, store.connection.fromHandle, Position.Left, true)
};
}
}
const dragItem = nodeDragItems.get(node.id);
return dragItem ? { ...node, position: dragItem.position, dragging } : node;

View File

@@ -93,8 +93,8 @@ function onPointerDown(
position: fromHandleInternal.position,
};
const fromNodeInternal = nodeLookup.get(nodeId)!;
const from = getHandlePosition(fromNodeInternal, fromHandle, Position.Left, true);
const fromInternalNode = nodeLookup.get(nodeId)!;
const from = getHandlePosition(fromInternalNode, fromHandle, Position.Left, true);
let previousConnection: ConnectionInProgress = {
inProgress: true,
@@ -103,7 +103,7 @@ function onPointerDown(
from,
fromHandle,
fromPosition: fromHandle.position,
fromNode: fromNodeInternal,
fromNode: fromInternalNode,
to: position,
toHandle: null,
@@ -171,11 +171,13 @@ function onPointerDown(
resultHandleDomNode = result.handleDomNode;
connection = result.connection;
isValid = isConnectionValid(!!closestHandle, result.isValid);
const fromNodeInternal = nodeLookup.get(nodeId)!;
const from = getHandlePosition(fromNodeInternal, fromHandle, Position.Left, true);
const newConnection: ConnectionInProgress = {
const fromInternalNode = nodeLookup.get(nodeId);
const from = fromInternalNode
? getHandlePosition(fromInternalNode, fromHandle, Position.Left, true)
: previousConnection.from;
const newConnection: ConnectionInProgress = {
...previousConnection,
from,
isValid,