feat(node-editor): fit view on init

This commit is contained in:
blessedcoolant 2023-07-11 18:22:50 +12:00
parent c3adb301a0
commit acea304348

View File

@ -7,8 +7,10 @@ import {
OnConnectEnd, OnConnectEnd,
OnConnectStart, OnConnectStart,
OnEdgesChange, OnEdgesChange,
OnInit,
OnNodesChange, OnNodesChange,
ReactFlow, ReactFlow,
ReactFlowInstance,
} from 'reactflow'; } from 'reactflow';
import { import {
connectionEnded, connectionEnded,
@ -67,6 +69,10 @@ export const Flow = () => {
dispatch(connectionEnded()); dispatch(connectionEnded());
}, [dispatch]); }, [dispatch]);
const onInit: OnInit = useCallback((v: ReactFlowInstance) => {
if (v) v.fitView();
}, []);
return ( return (
<ReactFlow <ReactFlow
nodeTypes={nodeTypes} nodeTypes={nodeTypes}
@ -77,6 +83,7 @@ export const Flow = () => {
onConnectStart={onConnectStart} onConnectStart={onConnectStart}
onConnect={onConnect} onConnect={onConnect}
onConnectEnd={onConnectEnd} onConnectEnd={onConnectEnd}
onInit={onInit}
defaultEdgeOptions={{ defaultEdgeOptions={{
style: { strokeWidth: 2 }, style: { strokeWidth: 2 },
}} }}