Merge pull request #5482 from xyflow/fix-is-intersecting
Fix is intersecting
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
'@xyflow/react': patch
|
||||||
|
'@xyflow/svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Make isNodeIntersecting behave the same as getIntersectingNodes
|
||||||
@@ -202,6 +202,11 @@ export function useReactFlow<NodeType extends Node = Node, EdgeType extends Edge
|
|||||||
|
|
||||||
return { deletedNodes: matchingNodes, deletedEdges: matchingEdges };
|
return { deletedNodes: matchingNodes, deletedEdges: matchingEdges };
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Partial is defined as "the 2 nodes/areas are intersecting partially".
|
||||||
|
* If a is contained in b or b is contained in a, they are both
|
||||||
|
* considered fully intersecting.
|
||||||
|
*/
|
||||||
getIntersectingNodes: (nodeOrRect, partially = true, nodes) => {
|
getIntersectingNodes: (nodeOrRect, partially = true, nodes) => {
|
||||||
const isRect = isRectObject(nodeOrRect);
|
const isRect = isRectObject(nodeOrRect);
|
||||||
const nodeRect = isRect ? nodeOrRect : getNodeRect(nodeOrRect);
|
const nodeRect = isRect ? nodeOrRect : getNodeRect(nodeOrRect);
|
||||||
@@ -240,7 +245,11 @@ export function useReactFlow<NodeType extends Node = Node, EdgeType extends Edge
|
|||||||
const overlappingArea = getOverlappingArea(nodeRect, area);
|
const overlappingArea = getOverlappingArea(nodeRect, area);
|
||||||
const partiallyVisible = partially && overlappingArea > 0;
|
const partiallyVisible = partially && overlappingArea > 0;
|
||||||
|
|
||||||
return partiallyVisible || overlappingArea >= nodeRect.width * nodeRect.height;
|
return (
|
||||||
|
partiallyVisible ||
|
||||||
|
overlappingArea >= area.width * area.height ||
|
||||||
|
overlappingArea >= nodeRect.width * nodeRect.height
|
||||||
|
);
|
||||||
},
|
},
|
||||||
updateNode,
|
updateNode,
|
||||||
updateNodeData: (id, dataUpdate, options = { replace: false }) => {
|
updateNodeData: (id, dataUpdate, options = { replace: false }) => {
|
||||||
|
|||||||
@@ -390,6 +390,11 @@ export function useSvelteFlow<NodeType extends Node = Node, EdgeType extends Edg
|
|||||||
|
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Partial is defined as "the 2 nodes/areas are intersecting partially".
|
||||||
|
* If a is contained in b or b is contained in a, they are both
|
||||||
|
* considered fully intersecting.
|
||||||
|
*/
|
||||||
getIntersectingNodes: (
|
getIntersectingNodes: (
|
||||||
nodeOrRect: NodeType | { id: NodeType['id'] } | Rect,
|
nodeOrRect: NodeType | { id: NodeType['id'] } | Rect,
|
||||||
partially = true,
|
partially = true,
|
||||||
@@ -434,7 +439,11 @@ export function useSvelteFlow<NodeType extends Node = Node, EdgeType extends Edg
|
|||||||
const overlappingArea = getOverlappingArea(nodeRect, area);
|
const overlappingArea = getOverlappingArea(nodeRect, area);
|
||||||
const partiallyVisible = partially && overlappingArea > 0;
|
const partiallyVisible = partially && overlappingArea > 0;
|
||||||
|
|
||||||
return partiallyVisible || overlappingArea >= nodeRect.width * nodeRect.height;
|
return (
|
||||||
|
partiallyVisible ||
|
||||||
|
overlappingArea >= area.width * area.height ||
|
||||||
|
overlappingArea >= nodeRect.width * nodeRect.height
|
||||||
|
);
|
||||||
},
|
},
|
||||||
deleteElements: async ({ nodes: nodesToRemove = [], edges: edgesToRemove = [] }) => {
|
deleteElements: async ({ nodes: nodesToRemove = [], edges: edgesToRemove = [] }) => {
|
||||||
const { nodes: matchingNodes, edges: matchingEdges } = await getElementsToRemove<
|
const { nodes: matchingNodes, edges: matchingEdges } = await getElementsToRemove<
|
||||||
|
|||||||
Reference in New Issue
Block a user