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
+1 -1
View File
@@ -3,4 +3,4 @@
'@xyflow/svelte': patch '@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)
+17 -15
View File
@@ -66,23 +66,25 @@ const useViewportHelper = (): ViewportHelperFunctions => {
}, },
fitView: (options) => { fitView: (options) => {
const { nodeLookup, minZoom, maxZoom, panZoom, domNode } = store.getState(); const { nodeLookup, minZoom, maxZoom, panZoom, domNode } = store.getState();
if (!panZoom || !domNode) {
return Promise.resolve(false);
}
const fitViewNodes = getFitViewNodes(nodeLookup, options); const fitViewNodes = getFitViewNodes(nodeLookup, options);
const { width, height } = getDimensions(domNode);
const { width, height } = getDimensions(domNode!); return fitView(
{
return panZoom nodes: fitViewNodes,
? fitView( width,
{ height,
nodes: fitViewNodes, minZoom,
width, maxZoom,
height, panZoom,
minZoom, },
maxZoom, options
panZoom, );
},
options
)
: Promise.resolve(false);
}, },
setCenter: async (x, y, options) => { setCenter: async (x, y, options) => {
const { width, height, maxZoom, panZoom } = store.getState(); const { width, height, maxZoom, panZoom } = store.getState();