fix lost handle bounds

This commit is contained in:
peterkogo
2025-01-15 13:19:53 +01:00
parent ce6fcc7a82
commit a989fa9a8b
3 changed files with 50 additions and 48 deletions
@@ -25,8 +25,6 @@
onnodecontextmenu onnodecontextmenu
}: NodeWrapperProps & NodeEvents = $props(); }: NodeWrapperProps & NodeEvents = $props();
// $inspect(node);
let { let {
data = {}, data = {},
selected = false, selected = false,
+1 -1
View File
@@ -51,7 +51,7 @@ export type {
EdgeTypes, EdgeTypes,
DefaultEdgeOptions DefaultEdgeOptions
} from '$lib/types/edges'; } from '$lib/types/edges';
export type { HandleProps, FitViewOptions } from '$lib/types/general'; export type { HandleProps, FitViewOptions, OnBeforeDelete } from '$lib/types/general';
export type { Node, NodeTypes, BuiltInNode, NodeProps, InternalNode } from '$lib/types/nodes'; export type { Node, NodeTypes, BuiltInNode, NodeProps, InternalNode } from '$lib/types/nodes';
export type { SvelteFlowStore } from '$lib/store/types'; export type { SvelteFlowStore } from '$lib/store/types';
export * from '$lib/types/events'; export * from '$lib/types/events';
+10 -6
View File
@@ -87,6 +87,7 @@ export function adoptUserNodes<NodeType extends NodeBase>(
options?: UpdateNodesOptions<NodeType> options?: UpdateNodesOptions<NodeType>
) { ) {
const _options = mergeObjects(adoptUserNodesDefaultOptions, options); const _options = mergeObjects(adoptUserNodesDefaultOptions, options);
const tmpLookup = new Map(nodeLookup); const tmpLookup = new Map(nodeLookup);
const selectedNodeZ: number = _options?.elevateNodesOnSelect ? 1000 : 0; const selectedNodeZ: number = _options?.elevateNodesOnSelect ? 1000 : 0;
@@ -345,7 +346,9 @@ export function updateNodeInternals<NodeType extends InternalNodeBase>(
}, },
}); });
updatedInternals = true; updatedInternals = true;
} else { continue;
}
const dimensions = getDimensions(update.nodeElement); const dimensions = getDimensions(update.nodeElement);
const dimensionChanged = node.measured.width !== dimensions.width || node.measured.height !== dimensions.height; const dimensionChanged = node.measured.width !== dimensions.width || node.measured.height !== dimensions.height;
const doUpdate = !!( const doUpdate = !!(
@@ -365,7 +368,7 @@ export function updateNodeInternals<NodeType extends InternalNodeBase>(
positionAbsolute = clampPosition(positionAbsolute, extent, dimensions); positionAbsolute = clampPosition(positionAbsolute, extent, dimensions);
} }
nodeLookup.set(node.id, { const newNode = {
...node, ...node,
measured: dimensions, measured: dimensions,
internals: { internals: {
@@ -376,10 +379,12 @@ export function updateNodeInternals<NodeType extends InternalNodeBase>(
target: getHandleBounds('target', update.nodeElement, nodeBounds, zoom, node.id), target: getHandleBounds('target', update.nodeElement, nodeBounds, zoom, node.id),
}, },
}, },
}); };
nodeLookup.set(node.id, newNode);
if (node.parentId) { if (node.parentId) {
updateChildNode(node, nodeLookup, parentLookup, { nodeOrigin }); updateChildNode(newNode, nodeLookup, parentLookup, { nodeOrigin });
} }
updatedInternals = true; updatedInternals = true;
@@ -395,13 +400,12 @@ export function updateNodeInternals<NodeType extends InternalNodeBase>(
parentExpandChildren.push({ parentExpandChildren.push({
id: node.id, id: node.id,
parentId: node.parentId, parentId: node.parentId,
rect: nodeToRect(node, nodeOrigin), rect: nodeToRect(newNode, nodeOrigin),
}); });
} }
} }
} }
} }
}
if (parentExpandChildren.length > 0) { if (parentExpandChildren.length > 0) {
const parentExpandChanges = handleExpandParent(parentExpandChildren, nodeLookup, parentLookup, nodeOrigin); const parentExpandChanges = handleExpandParent(parentExpandChildren, nodeLookup, parentLookup, nodeOrigin);