Merge pull request #4477 from xyflow/nodesbounds

Added getNodesBounds function to useReactFlow/useSvelteFlow
This commit is contained in:
Moritz Klack
2024-09-05 16:32:06 +02:00
committed by GitHub
6 changed files with 69 additions and 12 deletions
+5
View File
@@ -3,6 +3,7 @@ import {
EdgeRemoveChange,
evaluateAbsolutePosition,
getElementsToRemove,
getNodesBounds,
getOverlappingArea,
isRectObject,
NodeRemoveChange,
@@ -230,6 +231,10 @@ export function useReactFlow<NodeType extends Node = Node, EdgeType extends Edge
options
);
},
getNodesBounds: (nodes: (NodeType | InternalNode | string)[]): Rect => {
const { nodeLookup, nodeOrigin } = store.getState();
return getNodesBounds(nodes, { nodeLookup, nodeOrigin });
},
getHandleConnections: ({ type, id, nodeId }) =>
Array.from(
store
+8
View File
@@ -173,6 +173,14 @@ export type GeneralHelpers<NodeType extends Node = Node, EdgeType extends Edge =
dataUpdate: Partial<EdgeType['data']> | ((edge: EdgeType) => Partial<EdgeType['data']>),
options?: { replace: boolean }
) => void;
/**
* Returns the bounds of the given nodes or node ids.
*
* @param nodes - the nodes or node ids to calculate the bounds for
*
* @returns the bounds of the given nodes
*/
getNodesBounds: (nodes: (NodeType | InternalNode | string)[]) => Rect;
/**
* Gets all connections for a given handle belonging to a specific node.
*