Merge pull request #5497 from xyflow/fix-only-render-visible
skip force rendering nodes that have handles defined
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { HandleConnection, infiniteExtent } from '..';
|
||||
import { Handle, HandleConnection, infiniteExtent, NodeHandle, NodeHandleBounds } from '..';
|
||||
import {
|
||||
NodeBase,
|
||||
CoordinateExtent,
|
||||
@@ -72,6 +72,37 @@ export function updateAbsolutePositions<NodeType extends NodeBase>(
|
||||
}
|
||||
}
|
||||
|
||||
function parseHandles(userNode: NodeBase, internalNode?: InternalNodeBase): NodeHandleBounds | undefined {
|
||||
if (!userNode.handles) {
|
||||
return !userNode.measured ? undefined : internalNode?.internals.handleBounds;
|
||||
}
|
||||
|
||||
const source: Handle[] = [];
|
||||
const target: Handle[] = [];
|
||||
|
||||
for (const handle of userNode.handles) {
|
||||
const handleBounds = {
|
||||
width: handle.width ?? 1,
|
||||
height: handle.height ?? 1,
|
||||
nodeId: userNode.id,
|
||||
x: handle.x,
|
||||
y: handle.y,
|
||||
position: handle.position,
|
||||
type: handle.type,
|
||||
};
|
||||
if (handle.type === 'source') {
|
||||
source.push(handleBounds);
|
||||
} else if (handle.type === 'target') {
|
||||
target.push(handleBounds);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
source,
|
||||
target,
|
||||
};
|
||||
}
|
||||
|
||||
type UpdateNodesOptions<NodeType extends NodeBase> = {
|
||||
nodeOrigin?: NodeOrigin;
|
||||
nodeExtent?: CoordinateExtent;
|
||||
@@ -115,7 +146,7 @@ export function adoptUserNodes<NodeType extends NodeBase>(
|
||||
internals: {
|
||||
positionAbsolute: clampedPosition,
|
||||
// if user re-initializes the node or removes `measured` for whatever reason, we reset the handleBounds so that the node gets re-measured
|
||||
handleBounds: !userNode.measured ? undefined : internalNode?.internals.handleBounds,
|
||||
handleBounds: parseHandles(userNode, internalNode),
|
||||
z: calculateZ(userNode, selectedNodeZ),
|
||||
userNode,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user