From 3f21dc764dcc9fe1d28762f749c3dc411a80efa7 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Fri, 10 Feb 2023 13:04:05 +0100 Subject: [PATCH] refactor(core): fit view initially when node dimensions are updated Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- packages/core/src/store/actions.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index 42d2668b..3ab5a1e4 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -21,6 +21,8 @@ import type { } from '~/types' export function useActions(state: State, getters: ComputedGetters): Actions { + let fitViewOnInitDone = false + const updateNodeInternals: Actions['updateNodeInternals'] = (ids) => { state.hooks.updateNodeInternals.trigger(ids) } @@ -151,6 +153,13 @@ export function useActions(state: State, getters: ComputedGetters): Actions { return res }, []) + if (state.fitViewOnInit && !fitViewOnInitDone) { + paneReady().then((helper) => { + helper.fitView() + fitViewOnInitDone = true + }) + } + if (changes.length) state.hooks.nodesChange.trigger(changes) }