Skip to content

Commit c822f9c

Browse files
committed
refactor(core,handle): remove auto-generated handle ids
1 parent 5703647 commit c822f9c

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
22
import { until } from '@vueuse/core'
33
import { computed, onUnmounted, ref, toRef } from 'vue'
4-
import type { HandleProps } from '../../types/handle'
4+
import type { HandleProps } from '../../types'
55
import { Position } from '../../types'
66
import { useHandle, useNode, useVueFlow } from '../../composables'
77
import { getDimensions, isDef, isMouseEvent } from '../../utils'
@@ -11,7 +11,7 @@ const {
1111
connectable = undefined,
1212
connectableStart = true,
1313
connectableEnd = true,
14-
id,
14+
id: handleId = null,
1515
...props
1616
} = defineProps<HandleProps>()
1717
@@ -33,26 +33,24 @@ const { id: nodeId, node, nodeEl, connectedEdges } = useNode()
3333
3434
const handle = ref<HTMLDivElement>()
3535
36-
const handleId = toRef(() => id ?? `${nodeId}__handle-${position}`)
37-
3836
const isConnectableStart = toRef(() => (typeof connectableStart !== 'undefined' ? connectableStart : true))
3937
4038
const isConnectableEnd = toRef(() => (typeof connectableEnd !== 'undefined' ? connectableEnd : true))
4139
4240
const isConnecting = toRef(
4341
() =>
4442
(connectionStartHandle.value?.nodeId === nodeId &&
45-
connectionStartHandle.value?.handleId === handleId.value &&
43+
connectionStartHandle.value?.handleId === handleId &&
4644
connectionStartHandle.value?.type === type.value) ||
4745
(connectionEndHandle.value?.nodeId === nodeId &&
48-
connectionEndHandle.value?.handleId === handleId.value &&
46+
connectionEndHandle.value?.handleId === handleId &&
4947
connectionEndHandle.value?.type === type.value),
5048
)
5149
5250
const isClickConnecting = toRef(
5351
() =>
5452
connectionClickStartHandle.value?.nodeId === nodeId &&
55-
connectionClickStartHandle.value?.handleId === handleId.value &&
53+
connectionClickStartHandle.value?.handleId === handleId &&
5654
connectionClickStartHandle.value?.type === type.value,
5755
)
5856
@@ -72,7 +70,7 @@ const isConnectable = computed(() => {
7270
return false
7371
}
7472
75-
return id ? id === handleId.value : true
73+
return id ? id === handleId : true
7674
})
7775
}
7876
@@ -85,7 +83,7 @@ const isConnectable = computed(() => {
8583
return false
8684
}
8785
88-
return id ? id === handleId.value : true
86+
return id ? id === handleId : true
8987
}).length < connectable
9088
)
9189
}
@@ -97,19 +95,20 @@ const isConnectable = computed(() => {
9795
return isDef(connectable) ? connectable : nodesConnectable.value
9896
})
9997
98+
// todo: remove this and have users handle this themselves using `updateNodeInternals`
10099
// 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)
101100
until(() => node.initialized)
102101
.toBe(true, { flush: 'post' })
103102
.then(() => {
104-
const existingBounds = node.handleBounds[type.value]?.find((b) => b.id === handleId.value)
103+
const existingBounds = node.handleBounds[type.value]?.find((b) => b.id === handleId)
105104
106105
if (!vueFlowRef.value || existingBounds) {
107106
return
108107
}
109108
110109
const viewportNode = vueFlowRef.value.querySelector('.vue-flow__transformationpane')
111110
112-
if (!nodeEl.value || !handle.value || !viewportNode || !handleId.value) {
111+
if (!nodeEl.value || !handle.value || !viewportNode || !handleId) {
113112
return
114113
}
115114
@@ -121,7 +120,7 @@ until(() => node.initialized)
121120
const { m22: zoom } = new window.DOMMatrixReadOnly(style.transform)
122121
123122
const nextBounds = {
124-
id: handleId.value,
123+
id: handleId,
125124
position,
126125
x: (handleBounds.left - nodeBounds.left) / zoom,
127126
y: (handleBounds.top - nodeBounds.top) / zoom,
@@ -135,7 +134,7 @@ onUnmounted(() => {
135134
// clean up node internals
136135
const handleBounds = node.handleBounds[type.value]
137136
if (handleBounds) {
138-
node.handleBounds[type.value] = handleBounds.filter((b) => b.id !== handleId.value)
137+
node.handleBounds[type.value] = handleBounds.filter((b) => b.id !== handleId)
139138
}
140139
})
141140

0 commit comments

Comments
 (0)