refactor(react): pass fitView for ssr

This commit is contained in:
moklick
2023-10-23 16:01:22 +02:00
parent f2b36f2d33
commit 52a47a7a26
5 changed files with 20 additions and 5 deletions
+3 -1
View File
@@ -29,15 +29,17 @@ const createRFStore = ({
edges,
width,
height,
fitView,
}: {
nodes?: Node[];
edges?: Edge[];
width?: number;
height?: number;
fitView?: boolean;
}) =>
createWithEqualityFn<ReactFlowState>(
(set, get) => ({
...getInitialState({ nodes, edges, width, height }),
...getInitialState({ nodes, edges, width, height, fitView }),
setNodes: (nodes: Node[]) => {
const { nodes: storeNodes, nodeOrigin, elevateNodesOnSelect } = get();
const nextNodes = updateNodes(nodes, storeNodes, { nodeOrigin, elevateNodesOnSelect });
+4 -2
View File
@@ -15,17 +15,19 @@ const getInitialState = ({
edges = [],
width,
height,
fitView,
}: {
nodes?: Node[];
edges?: Edge[];
width?: number;
height?: number;
fitView?: boolean;
} = {}): ReactFlowStore => {
const nextNodes = updateNodes(nodes, [], { nodeOrigin: [0, 0], elevateNodesOnSelect: false });
let transform: Transform = [0, 0, 1];
if (width && height) {
if (fitView && width && height) {
const nodesWithDimensions = nextNodes.map((node) => ({
...node,
width: node.size?.width,
@@ -89,7 +91,7 @@ const getInitialState = ({
autoPanOnConnect: true,
autoPanOnNodeDrag: true,
connectionRadius: 20,
onError: devWarn,
onError: () => null,
isValidConnection: undefined,
lib: 'react',