Skip to content

Commit af93fd2

Browse files
authored
refactor(core): replace until watcher with onMounted in handle cmp (#1488)
1 parent 63873ef commit af93fd2

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

packages/core/src/components/Handle/Handle.vue

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts" setup>
2-
import { until } from '@vueuse/core'
3-
import { computed, onUnmounted, ref, toRef } from 'vue'
2+
import { computed, onMounted, onUnmounted, ref, toRef } from 'vue'
43
import type { HandleProps } from '../../types'
54
import { Position } from '../../types'
65
import { useHandle, useNode, useVueFlow } from '../../composables'
@@ -97,38 +96,42 @@ const isConnectable = computed(() => {
9796
9897
// todo: remove this and have users handle this themselves using `updateNodeInternals`
9998
// set up handle bounds if they don't exist yet and the node has been initialized (i.e. the handle was added after the node has already been mounted)
100-
until(() => !!node.dimensions.width && !!node.dimensions.height)
101-
.toBe(true, { flush: 'post' })
102-
.then(() => {
103-
const existingBounds = node.handleBounds[type.value]?.find((b) => b.id === handleId)
99+
onMounted(() => {
100+
// if the node isn't initialized yet, we can't set up the handle bounds
101+
// the handle bounds will be automatically set up when the node is initialized (`updateNodeDimensions`)
102+
if (!node.dimensions.width || !node.dimensions.height) {
103+
return
104+
}
104105
105-
if (!vueFlowRef.value || existingBounds) {
106-
return
107-
}
106+
const existingBounds = node.handleBounds[type.value]?.find((b) => b.id === handleId)
108107
109-
const viewportNode = vueFlowRef.value.querySelector('.vue-flow__transformationpane')
108+
if (!vueFlowRef.value || existingBounds) {
109+
return
110+
}
110111
111-
if (!nodeEl.value || !handle.value || !viewportNode || !handleId) {
112-
return
113-
}
112+
const viewportNode = vueFlowRef.value.querySelector('.vue-flow__transformationpane')
114113
115-
const nodeBounds = nodeEl.value.getBoundingClientRect()
114+
if (!nodeEl.value || !handle.value || !viewportNode || !handleId) {
115+
return
116+
}
117+
118+
const nodeBounds = nodeEl.value.getBoundingClientRect()
116119
117-
const handleBounds = handle.value.getBoundingClientRect()
120+
const handleBounds = handle.value.getBoundingClientRect()
118121
119-
const style = window.getComputedStyle(viewportNode)
120-
const { m22: zoom } = new window.DOMMatrixReadOnly(style.transform)
122+
const style = window.getComputedStyle(viewportNode)
123+
const { m22: zoom } = new window.DOMMatrixReadOnly(style.transform)
121124
122-
const nextBounds = {
123-
id: handleId,
124-
position,
125-
x: (handleBounds.left - nodeBounds.left) / zoom,
126-
y: (handleBounds.top - nodeBounds.top) / zoom,
127-
...getDimensions(handle.value),
128-
}
125+
const nextBounds = {
126+
id: handleId,
127+
position,
128+
x: (handleBounds.left - nodeBounds.left) / zoom,
129+
y: (handleBounds.top - nodeBounds.top) / zoom,
130+
...getDimensions(handle.value),
131+
}
129132
130-
node.handleBounds[type.value] = [...(node.handleBounds[type.value] ?? []), nextBounds]
131-
})
133+
node.handleBounds[type.value] = [...(node.handleBounds[type.value] ?? []), nextBounds]
134+
})
132135
133136
onUnmounted(() => {
134137
// clean up node internals

0 commit comments

Comments
 (0)