chore(useReactFlow): cleanup fitView

This commit is contained in:
moklick
2024-09-23 15:01:20 +02:00
parent 5a6869fd40
commit b47a04fb8b
2 changed files with 18 additions and 16 deletions

View File

@@ -3,4 +3,4 @@
'@xyflow/svelte': patch
---
Calculate viewport dimensions in fitView instead of using stored dimensions. Fixes [#4652](https://github.com/xyflow/xyflow/issues/4652)
Calculate viewport dimensions in `fitView` instead of using stored dimensions. Fixes [#4652](https://github.com/xyflow/xyflow/issues/4652)

View File

@@ -66,23 +66,25 @@ const useViewportHelper = (): ViewportHelperFunctions => {
},
fitView: (options) => {
const { nodeLookup, minZoom, maxZoom, panZoom, domNode } = store.getState();
if (!panZoom || !domNode) {
return Promise.resolve(false);
}
const fitViewNodes = getFitViewNodes(nodeLookup, options);
const { width, height } = getDimensions(domNode);
const { width, height } = getDimensions(domNode!);
return panZoom
? fitView(
{
nodes: fitViewNodes,
width,
height,
minZoom,
maxZoom,
panZoom,
},
options
)
: Promise.resolve(false);
return fitView(
{
nodes: fitViewNodes,
width,
height,
minZoom,
maxZoom,
panZoom,
},
options
);
},
setCenter: async (x, y, options) => {
const { width, height, maxZoom, panZoom } = store.getState();