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
+5 -5
View File
@@ -190,16 +190,16 @@ 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) { if (node && connection.inProgress && connection.fromNode.id === node.id) {
const updatedFrom = getHandlePosition(node, connection.fromHandle, Position.Left, true); const updatedFrom = getHandlePosition(node, connection.fromHandle, Position.Left, true);
updateConnection({...connection,from: updatedFrom}) updateConnection({ ...connection, from: updatedFrom });
} }
if (expandParent && node.parentId) { if (expandParent && node.parentId) {
+7 -5
View File
@@ -54,11 +54,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) { if (store.connection.inProgress && store.connection.fromNode.id === node.id) {
const internalNode = store.nodeLookup.get(node.id);
store.connection = { if (internalNode) {
...store.connection, store.connection = {
from: getHandlePosition(store.nodeLookup.get(node.id), store.connection.fromHandle, Position.Left, true) ...store.connection,
}; from: getHandlePosition(internalNode, 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;
+7 -5
View File
@@ -93,8 +93,8 @@ function onPointerDown(
position: fromHandleInternal.position, position: fromHandleInternal.position,
}; };
const fromNodeInternal = nodeLookup.get(nodeId)!; const fromInternalNode = nodeLookup.get(nodeId)!;
const from = getHandlePosition(fromNodeInternal, fromHandle, Position.Left, true); const from = getHandlePosition(fromInternalNode, fromHandle, Position.Left, true);
let previousConnection: ConnectionInProgress = { let previousConnection: ConnectionInProgress = {
inProgress: true, inProgress: true,
@@ -103,7 +103,7 @@ function onPointerDown(
from, from,
fromHandle, fromHandle,
fromPosition: fromHandle.position, fromPosition: fromHandle.position,
fromNode: fromNodeInternal, fromNode: fromInternalNode,
to: position, to: position,
toHandle: null, toHandle: null,
@@ -172,8 +172,10 @@ function onPointerDown(
connection = result.connection; connection = result.connection;
isValid = isConnectionValid(!!closestHandle, result.isValid); isValid = isConnectionValid(!!closestHandle, result.isValid);
const fromNodeInternal = nodeLookup.get(nodeId)!; const fromInternalNode = nodeLookup.get(nodeId);
const from = getHandlePosition(fromNodeInternal, fromHandle, Position.Left, true); const from = fromInternalNode
? getHandlePosition(fromInternalNode, fromHandle, Position.Left, true)
: previousConnection.from;
const newConnection: ConnectionInProgress = { const newConnection: ConnectionInProgress = {
...previousConnection, ...previousConnection,