Skip to content

Commit 0544fbd

Browse files
committed
refactor(core): call fitViewOnInit when node dimensions are initially set
1 parent 24c2091 commit 0544fbd

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

packages/core/src/components/Nodes/NodeWrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ const NodeWrapper = defineComponent({
199199
getClass.value,
200200
],
201201
'style': {
202+
visibility: node.value.initialized ? 'visible' : 'hidden',
202203
zIndex: node.value.computedPosition.z ?? zIndex(),
203204
transform: `translate(${node.value.computedPosition.x}px,${node.value.computedPosition.y}px)`,
204205
pointerEvents: props.selectable || props.draggable ? 'all' : 'none',
205-
visibility: node.value.initialized ? 'visible' : 'hidden',
206206
...getStyle.value,
207207
},
208208
'tabIndex': props.focusable ? 0 : undefined,

packages/core/src/composables/useOnInitHandler.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@ export function useOnInitHandler() {
99
(isInitialized) => {
1010
if (isInitialized) {
1111
setTimeout(() => {
12-
// todo: call these when *nodes* are initialized instead of the viewport
13-
// currently doesn't work quite right because the viewport dimensions are not yet available when the nodes are initialized
14-
if (!vfInstance.fitViewOnInitDone.value && vfInstance.fitViewOnInit.value) {
15-
vfInstance.fitView()
16-
}
17-
18-
vfInstance.fitViewOnInitDone.value = true
19-
20-
// Here, we are making all nodes visible once we have the dimensions.
21-
if (!document.querySelector('#vue-flow__initialized-styles')) {
22-
const style = document.createElement('style')
23-
style.id = 'vue-flow__initialized-styles'
24-
document.head.appendChild(style)
25-
26-
const css = `.vue-flow__node { visibility: visible !important; }`
27-
style.appendChild(document.createTextNode(css))
28-
}
29-
3012
vfInstance.emits.init(vfInstance)
3113
vfInstance.emits.paneReady(vfInstance)
3214
}, 1)

packages/core/src/store/actions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { zoomIdentity } from 'd3-zoom'
22
import type { ComputedRef } from 'vue'
3+
import { nextTick } from 'vue'
34
import { until } from '@vueuse/core'
45
import type {
56
Actions,
@@ -180,6 +181,13 @@ export function useActions(
180181
return res
181182
}, [])
182183

184+
if (!state.fitViewOnInitDone && state.fitViewOnInit) {
185+
nextTick(() => {
186+
viewportHelper.value.fitView()
187+
state.fitViewOnInitDone = true
188+
})
189+
}
190+
183191
if (changes.length) {
184192
state.hooks.nodesChange.trigger(changes)
185193
}

0 commit comments

Comments
 (0)