chore(xyhandle): cleanup
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -52,13 +52,15 @@ 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;
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -171,11 +171,13 @@ function onPointerDown(
|
|||||||
resultHandleDomNode = result.handleDomNode;
|
resultHandleDomNode = result.handleDomNode;
|
||||||
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 fromInternalNode = nodeLookup.get(nodeId);
|
||||||
|
const from = fromInternalNode
|
||||||
|
? getHandlePosition(fromInternalNode, fromHandle, Position.Left, true)
|
||||||
|
: previousConnection.from;
|
||||||
|
|
||||||
|
const newConnection: ConnectionInProgress = {
|
||||||
...previousConnection,
|
...previousConnection,
|
||||||
from,
|
from,
|
||||||
isValid,
|
isValid,
|
||||||
|
|||||||
Reference in New Issue
Block a user