Merge pull request #4569 from xyflow/fix-intersections

Fix intersections in Svelte Flow
This commit is contained in:
Moritz Klack
2024-08-19 15:22:34 +02:00
committed by GitHub
4 changed files with 39 additions and 14 deletions
+25 -8
View File
@@ -14,7 +14,7 @@ import {
getViewportForBounds,
getElementsToRemove,
rendererPointToPoint,
nodeHasDimensions
evaluateAbsolutePosition
} from '@xyflow/system';
import { useStore } from '$lib/store';
@@ -247,15 +247,32 @@ export function useSvelteFlow(): {
edges,
domNode,
nodeLookup,
edgeLookup
edgeLookup,
nodeOrigin
} = useStore();
const getNodeRect = (nodeOrRect: Node | { id: Node['id'] }): Rect | null => {
const node =
isNode(nodeOrRect) && nodeHasDimensions(nodeOrRect)
? nodeOrRect
: get(nodeLookup).get(nodeOrRect.id);
return node ? nodeToRect(node) : null;
const getNodeRect = (node: Node | { id: Node['id'] }): Rect | null => {
const $nodeLookup = get(nodeLookup);
const nodeToUse = isNode(node) ? node : $nodeLookup.get(node.id)!;
const position = nodeToUse.parentId
? evaluateAbsolutePosition(
nodeToUse.position,
nodeToUse.measured,
nodeToUse.parentId,
$nodeLookup,
get(nodeOrigin)
)
: nodeToUse.position;
const nodeWithPosition = {
id: nodeToUse.id,
position,
width: nodeToUse.measured?.width ?? nodeToUse.width,
height: nodeToUse.measured?.height ?? nodeToUse.height,
data: nodeToUse.data
};
return nodeToRect(nodeWithPosition);
};
const updateNode = (