diff --git a/example/src/DragNDrop/index.tsx b/example/src/DragNDrop/index.tsx
index d004d092..1c8f9ddb 100644
--- a/example/src/DragNDrop/index.tsx
+++ b/example/src/DragNDrop/index.tsx
@@ -31,7 +31,7 @@ const DnDFlow = () => {
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
const onConnect = (params: Connection | Edge) => setEdges((eds) => addEdge(params, eds));
- const onPaneReady = (rfi: ReactFlowInstance) => setReactFlowInstance(rfi);
+ const onInit = (rfi: ReactFlowInstance) => setReactFlowInstance(rfi);
const onDrop = (event: DragEvent) => {
event.preventDefault();
@@ -60,7 +60,7 @@ const DnDFlow = () => {
onEdgesChange={onEdgesChange}
onNodesChange={onNodesChange}
onConnect={onConnect}
- onPaneReady={onPaneReady}
+ onInit={onInit}
onDrop={onDrop}
onDragOver={onDragOver}
>
diff --git a/example/src/EdgeTypes/index.tsx b/example/src/EdgeTypes/index.tsx
index 1ed3c9c6..4d6862a0 100644
--- a/example/src/EdgeTypes/index.tsx
+++ b/example/src/EdgeTypes/index.tsx
@@ -15,7 +15,7 @@ import ReactFlow, {
} from 'react-flow-renderer';
import { getElements } from './utils';
-const onPaneReady = (reactFlowInstance: ReactFlowInstance) => {
+const onInit = (reactFlowInstance: ReactFlowInstance) => {
reactFlowInstance.fitView();
console.log(reactFlowInstance.getNodes());
};
@@ -36,7 +36,7 @@ const EdgeTypesFlow = () => {
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
- onPaneReady={onPaneReady}
+ onInit={onInit}
onConnect={onConnect}
minZoom={0.2}
zoomOnScroll={false}
diff --git a/example/src/Edges/index.tsx b/example/src/Edges/index.tsx
index d98e7c68..50ea0157 100644
--- a/example/src/Edges/index.tsx
+++ b/example/src/Edges/index.tsx
@@ -18,7 +18,7 @@ import ReactFlow, {
import CustomEdge from './CustomEdge';
import CustomEdge2 from './CustomEdge2';
-const onPaneReady = (reactFlowInstance: ReactFlowInstance) => reactFlowInstance.fitView();
+const onInit = (reactFlowInstance: ReactFlowInstance) => reactFlowInstance.fitView();
const onNodeDragStop = (_: MouseEvent, node: Node) => console.log('drag stop', node);
const onNodeClick = (_: MouseEvent, node: Node) => console.log('click', node);
@@ -121,7 +121,7 @@ const EdgesFlow = () => {
onNodeClick={onNodeClick}
onConnect={onConnect}
onNodeDragStop={onNodeDragStop}
- onPaneReady={onPaneReady}
+ onInit={onInit}
snapToGrid={true}
edgeTypes={edgeTypes}
>
diff --git a/example/src/Empty/index.tsx b/example/src/Empty/index.tsx
index d7645a2b..1d6e7a6b 100644
--- a/example/src/Empty/index.tsx
+++ b/example/src/Empty/index.tsx
@@ -13,7 +13,7 @@ import ReactFlow, {
ReactFlowInstance,
} from 'react-flow-renderer';
-const onPaneReady = (reactFlowInstance: ReactFlowInstance) => console.log('flow loaded:', reactFlowInstance);
+const onInit = (reactFlowInstance: ReactFlowInstance) => console.log('flow loaded:', reactFlowInstance);
const onNodeClick = (_: MouseEvent, node: Node) => console.log('click', node);
const onNodeDragStop = (_: MouseEvent, node: Node) => console.log('drag stop', node);
@@ -38,7 +38,7 @@ const EmptyFlow = () => {
reactFlowInstance.fitView();
+const onInit = (reactFlowInstance: ReactFlowInstance) => reactFlowInstance.fitView();
const { nodes: initialNodes, edges: initialEdges } = createElements();
@@ -40,7 +40,7 @@ const FloatingEdges = () => {
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
- onPaneReady={onPaneReady}
+ onInit={onInit}
edgeTypes={edgeTypes}
connectionLineComponent={FloatingConnectionLine}
>
diff --git a/example/src/Layouting/index.tsx b/example/src/Layouting/index.tsx
index 4f7868cf..88170feb 100644
--- a/example/src/Layouting/index.tsx
+++ b/example/src/Layouting/index.tsx
@@ -67,7 +67,7 @@ const LayoutFlow = () => {
edges={edges}
onConnect={onConnect}
nodeExtent={nodeExtent}
- onPaneReady={() => onLayout('TB')}
+ onInit={() => onLayout('TB')}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
>
diff --git a/example/src/NestedNodes/index.tsx b/example/src/NestedNodes/index.tsx
index d213c202..c5c1d7b6 100644
--- a/example/src/NestedNodes/index.tsx
+++ b/example/src/NestedNodes/index.tsx
@@ -91,7 +91,7 @@ const NestedFlow = () => {
const onConnect = useCallback((connection: Connection) => {
setEdges((eds) => addEdge(connection, eds));
}, []);
- const onPaneReady = useCallback((reactFlowInstance: ReactFlowInstance) => setRfInstance(reactFlowInstance), []);
+ const onInit = useCallback((reactFlowInstance: ReactFlowInstance) => setRfInstance(reactFlowInstance), []);
const updatePos = () => {
setNodes((nds) => {
@@ -131,7 +131,7 @@ const NestedFlow = () => {
{
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
- fitViewOnInit
+ fitView
>
diff --git a/example/src/Stress/index.tsx b/example/src/Stress/index.tsx
index 0e196a3d..d1804051 100644
--- a/example/src/Stress/index.tsx
+++ b/example/src/Stress/index.tsx
@@ -16,7 +16,7 @@ import { getNodesAndEdges } from './utils';
const buttonWrapperStyles: CSSProperties = { position: 'absolute', right: 10, top: 10, zIndex: 4 };
-const onPaneReady = (reactFlowInstance: ReactFlowInstance) => {
+const onInit = (reactFlowInstance: ReactFlowInstance) => {
reactFlowInstance.fitView();
console.log(reactFlowInstance.getNodes());
};
@@ -55,13 +55,7 @@ const StressFlow = () => {
}, []);
return (
-
+
diff --git a/example/src/Subflow/index.tsx b/example/src/Subflow/index.tsx
index c624ca0d..5c08ff06 100644
--- a/example/src/Subflow/index.tsx
+++ b/example/src/Subflow/index.tsx
@@ -113,7 +113,7 @@ const BasicFlow = () => {
const onConnect = useCallback((connection: Connection) => {
setEdges((eds) => addEdge(connection, eds));
}, []);
- const onPaneReady = useCallback((reactFlowInstance: ReactFlowInstance) => setRfInstance(reactFlowInstance), []);
+ const onInit = useCallback((reactFlowInstance: ReactFlowInstance) => setRfInstance(reactFlowInstance), []);
const updatePos = () => {
setNodes((nds) => {
@@ -155,7 +155,7 @@ const BasicFlow = () => {
{
maxZoom={4}
onlyRenderVisibleElements={false}
nodeTypes={nodeTypes}
- fitViewOnInit
+ fitView
>
diff --git a/example/src/UpdatableEdge/index.tsx b/example/src/UpdatableEdge/index.tsx
index eb34f063..0ec44c1e 100644
--- a/example/src/UpdatableEdge/index.tsx
+++ b/example/src/UpdatableEdge/index.tsx
@@ -53,7 +53,7 @@ const initialNodes: Node[] = [
const initialEdges = [{ id: 'e1-2', source: '1', target: '2', label: 'This is a draggable edge' }];
-const onPaneReady = (reactFlowInstance: ReactFlowInstance) => reactFlowInstance.fitView();
+const onInit = (reactFlowInstance: ReactFlowInstance) => reactFlowInstance.fitView();
const onEdgeUpdateStart = (_: React.MouseEvent, edge: Edge) => console.log('start update', edge);
const onEdgeUpdateEnd = (_: MouseEvent, edge: Edge) => console.log('end update', edge);
@@ -79,7 +79,7 @@ const UpdatableEdge = () => {
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
- onPaneReady={onPaneReady}
+ onInit={onInit}
snapToGrid={true}
onEdgeUpdate={onEdgeUpdate}
onConnect={onConnect}
diff --git a/example/src/UseZoomPanHelper/index.tsx b/example/src/UseZoomPanHelper/index.tsx
index 32fd0eba..55aeae65 100644
--- a/example/src/UseZoomPanHelper/index.tsx
+++ b/example/src/UseZoomPanHelper/index.tsx
@@ -33,7 +33,7 @@ const UseZoomPanHelperFlow = () => {
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
const onConnect = (params: Connection | Edge) => setEdges((eds) => addEdge(params, eds));
- const { project, setCenter, zoomIn, zoomOut } = useReactFlow();
+ const { project, setCenter, zoomIn, zoomOut, fitView } = useReactFlow();
const onPaneClick = useCallback(
(evt) => {
@@ -55,7 +55,7 @@ const UseZoomPanHelperFlow = () => {
const onNodeClick = useCallback(
(_, element) => {
const { x, y } = element.position;
- setCenter(x, y, { zoom: 1 });
+ setCenter(x, y, { zoom: 1, duration: 1200 });
},
[setCenter]
);
@@ -69,10 +69,14 @@ const UseZoomPanHelperFlow = () => {
onNodeClick={onNodeClick}
onConnect={onConnect}
onPaneClick={onPaneClick}
+ fitView
+ fitViewOptions={{ duration: 1200, padding: 0.2 }}
+ maxZoom={Infinity}
>
+
diff --git a/example/src/Validation/index.tsx b/example/src/Validation/index.tsx
index b643db18..247302c5 100644
--- a/example/src/Validation/index.tsx
+++ b/example/src/Validation/index.tsx
@@ -70,7 +70,7 @@ const ValidationFlow = () => {
onConnectStart={onConnectStart}
onConnectStop={onConnectStop}
onConnectEnd={onConnectEnd}
- fitViewOnInit
+ fitView
/>
);
};
diff --git a/package-lock.json b/package-lock.json
index 62a83756..fe08d4af 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14,7 +14,7 @@
"d3-selection": "^3.0.0",
"d3-zoom": "^3.0.0",
"react-draggable": "^4.4.4",
- "zustand": "^3.6.7"
+ "zustand": "^3.6.9"
},
"devDependencies": {
"@babel/core": "^7.16.5",
diff --git a/package.json b/package.json
index 7eabbee5..36646344 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
"d3-selection": "^3.0.0",
"d3-zoom": "^3.0.0",
"react-draggable": "^4.4.4",
- "zustand": "^3.6.7"
+ "zustand": "^3.6.9"
},
"devDependencies": {
"@babel/core": "^7.16.5",
diff --git a/src/additional-components/Controls/index.tsx b/src/additional-components/Controls/index.tsx
index 04048d3e..bcf08c67 100644
--- a/src/additional-components/Controls/index.tsx
+++ b/src/additional-components/Controls/index.tsx
@@ -25,7 +25,7 @@ const Controls: FC = ({
showZoom = true,
showFitView = true,
showInteractive = true,
- fitViewParams,
+ fitViewOptions,
onZoomIn,
onZoomOut,
onFitView,
@@ -51,9 +51,9 @@ const Controls: FC = ({
}, [zoomOut, onZoomOut]);
const onFitViewHandler = useCallback(() => {
- fitView?.(fitViewParams);
+ fitView?.(fitViewOptions);
onFitView?.();
- }, [fitView, fitViewParams, onFitView]);
+ }, [fitView, fitViewOptions, onFitView]);
const onInteractiveChangeHandler = useCallback(() => {
store.setState({
diff --git a/src/additional-components/MiniMap/index.tsx b/src/additional-components/MiniMap/index.tsx
index 43d8fb1f..7b579d28 100644
--- a/src/additional-components/MiniMap/index.tsx
+++ b/src/additional-components/MiniMap/index.tsx
@@ -5,7 +5,7 @@ import shallow from 'zustand/shallow';
import MiniMapNode from './MiniMapNode';
import { useStore } from '../../store';
-import { getRectOfNodeInternals } from '../../utils/graph';
+import { getRectOfNodes } from '../../utils/graph';
import { getBoundsofRects } from '../../utils';
import { MiniMapProps, GetMiniMapNodeAttribute, ReactFlowState, Rect } from '../../types';
@@ -48,7 +48,7 @@ const MiniMap = ({
const hasNodes = nodeInternals && nodeInternals.size > 0;
// @TODO: work with nodeInternals instead of converting it to an array
const nodes = Array.from(nodeInternals).map(([_, node]) => node);
- const bb = getRectOfNodeInternals(nodes);
+ const bb = getRectOfNodes(nodes);
const viewBB: Rect = {
x: -tX / tScale,
y: -tY / tScale,
diff --git a/src/components/Attribution/index.tsx b/src/components/Attribution/index.tsx
index e65abc4e..b87375c6 100644
--- a/src/components/Attribution/index.tsx
+++ b/src/components/Attribution/index.tsx
@@ -4,12 +4,12 @@ import cc from 'classcat';
import { AttributionPosition, ProOptions } from '../../types';
type AttributionProps = {
- pro?: ProOptions;
+ proOptions?: ProOptions;
position?: AttributionPosition;
};
-function Attribution({ pro, position = 'bottom-right' }: AttributionProps) {
- if (pro?.account === 'paid-subscription' && pro?.hideAttribution) {
+function Attribution({ proOptions, position = 'bottom-right' }: AttributionProps) {
+ if (proOptions?.account === 'paid-subscription' && proOptions?.hideAttribution) {
return null;
}
diff --git a/src/components/Nodes/wrapNode.tsx b/src/components/Nodes/wrapNode.tsx
index 8a15f0c4..6c9e74c0 100644
--- a/src/components/Nodes/wrapNode.tsx
+++ b/src/components/Nodes/wrapNode.tsx
@@ -40,7 +40,6 @@ export default (NodeComponent: ComponentType) => {
sourcePosition,
targetPosition,
hidden,
- isInitialized,
snapToGrid,
snapGrid,
dragging,
@@ -60,11 +59,9 @@ export default (NodeComponent: ComponentType) => {
zIndex,
transform: `translate(${xPos}px,${yPos}px)`,
pointerEvents: hasPointerEvents ? 'all' : 'none',
- // prevents jumping of nodes on start
- opacity: isInitialized ? 1 : 0,
...style,
}),
- [zIndex, xPos, yPos, hasPointerEvents, isInitialized, style]
+ [zIndex, xPos, yPos, hasPointerEvents, style]
);
const node = useMemo(() => ({ id, type, position: { x: xPos, y: yPos }, data }), [id, type, xPos, yPos, data]);
diff --git a/src/components/NodesSelection/index.tsx b/src/components/NodesSelection/index.tsx
index 3373776a..0924ff11 100644
--- a/src/components/NodesSelection/index.tsx
+++ b/src/components/NodesSelection/index.tsx
@@ -10,7 +10,7 @@ import shallow from 'zustand/shallow';
import { useStore } from '../../store';
import { Node, ReactFlowState } from '../../types';
-import { getRectOfNodeInternals } from '../../utils/graph';
+import { getRectOfNodes } from '../../utils/graph';
export interface NodesSelectionProps {
onSelectionDragStart?: (event: MouseEvent, nodes: Node[]) => void;
@@ -55,7 +55,7 @@ function NodesSelection({
[tX, tY, tScale]
);
- const selectedNodesBbox = useMemo(() => getRectOfNodeInternals(selectedNodes), [selectedNodes]);
+ const selectedNodesBbox = useMemo(() => getRectOfNodes(selectedNodes), [selectedNodes]);
const innerStyle = useMemo(
() => ({
diff --git a/src/components/StoreUpdater/index.tsx b/src/components/StoreUpdater/index.tsx
index 49707d53..634e8bbd 100644
--- a/src/components/StoreUpdater/index.tsx
+++ b/src/components/StoreUpdater/index.tsx
@@ -17,6 +17,7 @@ import {
ConnectionMode,
SnapGrid,
DefaultEdgeOptions,
+ FitViewOptions,
} from '../../types';
interface StoreUpdaterProps {
@@ -40,9 +41,10 @@ interface StoreUpdaterProps {
snapToGrid?: boolean;
snapGrid?: SnapGrid;
translateExtent?: CoordinateExtent;
- fitViewOnInit: boolean;
connectOnClick: boolean;
defaultEdgeOptions?: DefaultEdgeOptions;
+ fitView?: boolean;
+ fitViewOptions?: FitViewOptions;
}
const selector = (s: ReactFlowState) => ({
@@ -94,9 +96,10 @@ const StoreUpdater = ({
snapGrid,
snapToGrid,
translateExtent,
- fitViewOnInit,
connectOnClick,
defaultEdgeOptions,
+ fitView,
+ fitViewOptions,
}: StoreUpdaterProps) => {
const {
setNodes,
@@ -127,12 +130,13 @@ const StoreUpdater = ({
useDirectStoreUpdater('nodesDraggable', nodesDraggable, store.setState);
useDirectStoreUpdater('nodesConnectable', nodesConnectable, store.setState);
useDirectStoreUpdater('elementsSelectable', elementsSelectable, store.setState);
- useDirectStoreUpdater('fitViewOnInit', fitViewOnInit, store.setState);
useDirectStoreUpdater('snapToGrid', snapToGrid, store.setState);
useDirectStoreUpdater('snapGrid', snapGrid, store.setState);
useDirectStoreUpdater('onNodesChange', onNodesChange, store.setState);
useDirectStoreUpdater('onEdgesChange', onEdgesChange, store.setState);
useDirectStoreUpdater('connectOnClick', connectOnClick, store.setState);
+ useDirectStoreUpdater('fitViewOnInit', fitView, store.setState);
+ useDirectStoreUpdater('fitViewOnInitOptions', fitViewOptions, store.setState);
useStoreUpdater(nodes, setNodes);
useStoreUpdater(edges, setEdges);
diff --git a/src/container/GraphView/index.tsx b/src/container/GraphView/index.tsx
index a77a7212..07b4a872 100644
--- a/src/container/GraphView/index.tsx
+++ b/src/container/GraphView/index.tsx
@@ -4,7 +4,7 @@ import FlowRenderer from '../FlowRenderer';
import NodeRenderer from '../NodeRenderer';
import EdgeRenderer from '../EdgeRenderer';
import Viewport from '../Viewport';
-import useOnPaneReadyHandler from '../../hooks/useOnPaneReadyHandler';
+import useOnInitHandler from '../../hooks/useOnInitHandler';
import { NodeTypesType, EdgeTypesType, ConnectionLineType, KeyCode, ReactFlowProps } from '../../types';
export interface GraphViewProps extends Omit {
@@ -30,7 +30,7 @@ const GraphView = ({
onMove,
onMoveStart,
onMoveEnd,
- onPaneReady,
+ onInit,
onNodeClick,
onEdgeClick,
onNodeDoubleClick,
@@ -82,7 +82,7 @@ const GraphView = ({
noWheelClassName,
noPanClassName,
}: GraphViewProps) => {
- useOnPaneReadyHandler(onPaneReady);
+ useOnInitHandler(onInit);
return (
{
const { scale, nodesDraggable, nodesConnectable, elementsSelectable, updateNodeDimensions, snapGrid, snapToGrid } =
useStore(selector, shallow);
const nodes = useVisibleNodes(props.onlyRenderVisibleElements);
- const reseizeObserverRef = useRef();
+ const resizeObserverRef = useRef();
const resizeObserver = useMemo(() => {
if (typeof ResizeObserver === 'undefined') {
@@ -54,14 +54,14 @@ const NodeRenderer = (props: NodeRendererProps) => {
updateNodeDimensions(updates);
});
- reseizeObserverRef.current = observer;
+ resizeObserverRef.current = observer;
return observer;
}, []);
useEffect(() => {
return () => {
- reseizeObserverRef?.current?.disconnect();
+ resizeObserverRef?.current?.disconnect();
};
}, []);
@@ -78,8 +78,6 @@ const NodeRenderer = (props: NodeRendererProps) => {
const isDraggable = !!(node.draggable || (nodesDraggable && typeof node.draggable === 'undefined'));
const isSelectable = !!(node.selectable || (elementsSelectable && typeof node.selectable === 'undefined'));
const isConnectable = !!(node.connectable || (nodesConnectable && typeof node.connectable === 'undefined'));
- const isInitialized =
- node.width && node.height && typeof node.width !== 'undefined' && typeof node.height !== 'undefined';
return (
{
xPos={node.positionAbsolute?.x ?? 0}
yPos={node.positionAbsolute?.y ?? 0}
dragging={!!node.dragging}
- isInitialized={!!isInitialized}
snapGrid={snapGrid}
snapToGrid={snapToGrid}
selectNodesOnDrag={props.selectNodesOnDrag}
diff --git a/src/container/ReactFlow/index.tsx b/src/container/ReactFlow/index.tsx
index 4b822423..3c4779c7 100644
--- a/src/container/ReactFlow/index.tsx
+++ b/src/container/ReactFlow/index.tsx
@@ -46,7 +46,7 @@ const ReactFlow: FunctionComponent = forwardRef = forwardRef = forwardRef
= forwardRef
{onSelectionChange && }
{children}
-
+
);
diff --git a/src/hooks/useOnPaneReadyHandler.ts b/src/hooks/useOnInitHandler.ts
similarity index 54%
rename from src/hooks/useOnPaneReadyHandler.ts
rename to src/hooks/useOnInitHandler.ts
index 80a59623..28f4c8aa 100644
--- a/src/hooks/useOnPaneReadyHandler.ts
+++ b/src/hooks/useOnInitHandler.ts
@@ -1,19 +1,18 @@
import { useEffect, useRef } from 'react';
import useReactFlow from './useReactFlow';
-import { OnPaneReady } from '../types';
+import { OnInit } from '../types';
-function useOnPaneReadyHandler(onPaneReady: OnPaneReady