fix(selection): only calculate selection box if selected nodes > 0
This commit is contained in:
@@ -59,6 +59,10 @@ const LayoutFlow = () => {
|
|||||||
setNodes(layoutedNodes);
|
setNodes(layoutedNodes);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const unselect = () => {
|
||||||
|
setNodes((nds) => nds.map((n) => ({ ...n, selected: false })));
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="layoutflow">
|
<div className="layoutflow">
|
||||||
<ReactFlowProvider>
|
<ReactFlowProvider>
|
||||||
@@ -77,7 +81,10 @@ const LayoutFlow = () => {
|
|||||||
<button onClick={() => onLayout('TB')} style={{ marginRight: 10 }}>
|
<button onClick={() => onLayout('TB')} style={{ marginRight: 10 }}>
|
||||||
vertical layout
|
vertical layout
|
||||||
</button>
|
</button>
|
||||||
<button onClick={() => onLayout('LR')}>horizontal layout</button>
|
<button onClick={() => onLayout('LR')} style={{ marginRight: 10 }}>
|
||||||
|
horizontal layout
|
||||||
|
</button>
|
||||||
|
<button onClick={() => unselect()}>unselect nodes</button>
|
||||||
</div>
|
</div>
|
||||||
</ReactFlowProvider>
|
</ReactFlowProvider>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -141,6 +141,10 @@ export const pointToRendererPoint = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getRectOfNodes = (nodes: Node[]): Rect => {
|
export const getRectOfNodes = (nodes: Node[]): Rect => {
|
||||||
|
if (nodes.length === 0) {
|
||||||
|
return { x: 0, y: 0, width: 0, height: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
const box = nodes.reduce(
|
const box = nodes.reduce(
|
||||||
(currBox, { positionAbsolute, position, width, height }) =>
|
(currBox, { positionAbsolute, position, width, height }) =>
|
||||||
getBoundsOfBoxes(
|
getBoundsOfBoxes(
|
||||||
|
|||||||
Reference in New Issue
Block a user