fix(react): dont allow invalid selection rect

This commit is contained in:
moklick
2024-05-02 18:02:38 +02:00
parent ec2592966e
commit ad3a803abb
3 changed files with 17 additions and 19 deletions
@@ -54,26 +54,24 @@ const DefaultNodes = () => {
const updateNodePositions = () => { const updateNodePositions = () => {
instance.setNodes((nodes) => instance.setNodes((nodes) =>
nodes.map((node) => { nodes.map((node) => ({
node.position = { ...node,
position: {
x: Math.random() * 400, x: Math.random() * 400,
y: Math.random() * 400, y: Math.random() * 400,
}; },
}))
return node;
})
); );
}; };
const updateEdgeColors = () => { const updateEdgeColors = () => {
instance.setEdges((edges) => instance.setEdges((edges) =>
edges.map((edge) => { edges.map((edge) => ({
edge.style = { ...edge,
style: {
stroke: '#ff5050', stroke: '#ff5050',
}; },
}))
return edge;
})
); );
}; };
@@ -44,10 +44,10 @@ export default function NodeInspector() {
<ViewportPortal> <ViewportPortal>
<div className="react-flow__devtools-nodeinspector"> <div className="react-flow__devtools-nodeinspector">
{nodes.map((node) => { {nodes.map((node) => {
const x = node.computed?.positionAbsolute?.x || 0; const x = node?.position?.x || 0;
const y = node.computed?.positionAbsolute?.y || 0; const y = node?.position?.y || 0;
const width = node.computed?.width || 0; const width = node.measured?.width || 0;
const height = node.computed?.height || 0; const height = node.measured?.height || 0;
return ( return (
<NodeInfo <NodeInfo
@@ -5,7 +5,7 @@
import { useRef, useEffect, type MouseEvent, type KeyboardEvent } from 'react'; import { useRef, useEffect, type MouseEvent, type KeyboardEvent } from 'react';
import cc from 'classcat'; import cc from 'classcat';
import { shallow } from 'zustand/shallow'; import { shallow } from 'zustand/shallow';
import { getInternalNodesBounds } from '@xyflow/system'; import { getInternalNodesBounds, isNumeric } from '@xyflow/system';
import { useStore, useStoreApi } from '../../hooks/useStore'; import { useStore, useStoreApi } from '../../hooks/useStore';
import { useDrag } from '../../hooks/useDrag'; import { useDrag } from '../../hooks/useDrag';
@@ -26,8 +26,8 @@ const selector = (s: ReactFlowState) => {
}); });
return { return {
width, width: isNumeric(width) ? width : null,
height, height: isNumeric(height) ? height : null,
userSelectionActive: s.userSelectionActive, userSelectionActive: s.userSelectionActive,
transformString: `translate(${s.transform[0]}px,${s.transform[1]}px) scale(${s.transform[2]}) translate(${x}px,${y}px)`, transformString: `translate(${s.transform[0]}px,${s.transform[1]}px) scale(${s.transform[2]}) translate(${x}px,${y}px)`,
}; };