From 05929299d3608d570d64af2a91709f6681bd268a Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Wed, 16 Mar 2022 16:02:26 +0100 Subject: [PATCH] refactor(zoom): Move paneReady event to transformation pane mounted hook * await dimensions in fitView function --- src/composables/useZoomPanHelper.ts | 8 +- .../TransformationPane/TransformationPane.vue | 27 ++++- src/container/VueFlow/VueFlow.vue | 2 +- src/container/ZoomPane/ZoomPane.vue | 109 ++++++------------ 4 files changed, 70 insertions(+), 76 deletions(-) diff --git a/src/composables/useZoomPanHelper.ts b/src/composables/useZoomPanHelper.ts index ebbeb22a..d6b7688a 100644 --- a/src/composables/useZoomPanHelper.ts +++ b/src/composables/useZoomPanHelper.ts @@ -1,5 +1,6 @@ import { zoomIdentity } from 'd3-zoom' import useVueFlow from './useVueFlow' +import useWindow from './useWindow' import { getRectOfNodes, pointToRendererPoint, getTransformForBounds } from '~/utils' import { GraphNode, FlowStore, UseZoomPanHelper, D3Selection } from '~/types' @@ -21,13 +22,18 @@ export default (store: FlowStore = useVueFlow().store): UseZoomPanHelper => ({ y: store.transform[1], zoom: store.transform[2], }), - fitView: ( + fitView: async ( options = { padding: DEFAULT_PADDING, includeHiddenNodes: false, duration: 0, }, ) => { + // if ssr we can't wait for dimensions, they'll never really exist + const window = useWindow() + if ('screen' in window) + await until(store.dimensions).toMatch(({ height, width }) => !isNaN(width) && width > 0 && !isNaN(height) && height > 0) + if (!store.getNodes.length) return let nodes: GraphNode[] = [] diff --git a/src/container/TransformationPane/TransformationPane.vue b/src/container/TransformationPane/TransformationPane.vue index 70ed24d8..b2294a13 100644 --- a/src/container/TransformationPane/TransformationPane.vue +++ b/src/container/TransformationPane/TransformationPane.vue @@ -1,11 +1,36 @@