Merge branch 'main' into fix-fit-view-origin

This commit is contained in:
peterkogo
2024-09-19 11:54:48 +02:00
3 changed files with 18 additions and 5 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@xyflow/react': patch
'@xyflow/svelte': patch
---
Calculate viewport dimensions in fitView instead of using stored dimensions. Fixes [#4652](https://github.com/xyflow/xyflow/issues/4652)
@@ -6,6 +6,7 @@ import {
fitView,
type XYPosition,
rendererPointToPoint,
getDimensions,
} from '@xyflow/system';
import { useStoreApi } from '../hooks/useStore';
@@ -64,9 +65,11 @@ const useViewportHelper = (): ViewportHelperFunctions => {
return { x, y, zoom };
},
fitView: (options) => {
const { nodeLookup, width, height, minZoom, maxZoom, panZoom } = store.getState();
const { nodeLookup, minZoom, maxZoom, panZoom, domNode } = store.getState();
const fitViewNodes = getFitViewNodes(nodeLookup, options);
const { width, height } = getDimensions(domNode!);
return panZoom
? fitView(
{
+8 -4
View File
@@ -20,7 +20,8 @@ import {
type ConnectionState,
type NodeOrigin,
getFitViewNodes,
updateAbsolutePositions
updateAbsolutePositions,
getDimensions
} from '@xyflow/system';
import type { EdgeTypes, NodeTypes, Node, Edge, FitViewOptions } from '$lib/types';
@@ -156,18 +157,21 @@ export function createStore({
function fitView(options?: FitViewOptions) {
const panZoom = get(store.panZoom);
const domNode = get(store.domNode);
if (!panZoom) {
if (!panZoom || !domNode) {
return Promise.resolve(false);
}
const { width, height } = getDimensions(domNode);
const fitViewNodes = getFitViewNodes(get(store.nodeLookup), options);
return fitViewSystem(
{
nodes: fitViewNodes,
width: get(store.width),
height: get(store.height),
width,
height,
minZoom: get(store.minZoom),
maxZoom: get(store.maxZoom),
panZoom