1
1
<script lang="ts" setup>
2
2
import { until } from ' @vueuse/core'
3
3
import { computed , onUnmounted , ref , toRef } from ' vue'
4
- import type { HandleProps } from ' ../../types/handle '
4
+ import type { HandleProps } from ' ../../types'
5
5
import { Position } from ' ../../types'
6
6
import { useHandle , useNode , useVueFlow } from ' ../../composables'
7
7
import { getDimensions , isDef , isMouseEvent } from ' ../../utils'
@@ -11,7 +11,7 @@ const {
11
11
connectable = undefined ,
12
12
connectableStart = true ,
13
13
connectableEnd = true ,
14
- id,
14
+ id : handleId = null ,
15
15
... props
16
16
} = defineProps <HandleProps >()
17
17
@@ -33,26 +33,24 @@ const { id: nodeId, node, nodeEl, connectedEdges } = useNode()
33
33
34
34
const handle = ref <HTMLDivElement >()
35
35
36
- const handleId = toRef (() => id ?? ` ${nodeId }__handle-${position } ` )
37
-
38
36
const isConnectableStart = toRef (() => (typeof connectableStart !== ' undefined' ? connectableStart : true ))
39
37
40
38
const isConnectableEnd = toRef (() => (typeof connectableEnd !== ' undefined' ? connectableEnd : true ))
41
39
42
40
const isConnecting = toRef (
43
41
() =>
44
42
(connectionStartHandle .value ?.nodeId === nodeId &&
45
- connectionStartHandle .value ?.handleId === handleId . value &&
43
+ connectionStartHandle .value ?.handleId === handleId &&
46
44
connectionStartHandle .value ?.type === type .value ) ||
47
45
(connectionEndHandle .value ?.nodeId === nodeId &&
48
- connectionEndHandle .value ?.handleId === handleId . value &&
46
+ connectionEndHandle .value ?.handleId === handleId &&
49
47
connectionEndHandle .value ?.type === type .value ),
50
48
)
51
49
52
50
const isClickConnecting = toRef (
53
51
() =>
54
52
connectionClickStartHandle .value ?.nodeId === nodeId &&
55
- connectionClickStartHandle .value ?.handleId === handleId . value &&
53
+ connectionClickStartHandle .value ?.handleId === handleId &&
56
54
connectionClickStartHandle .value ?.type === type .value ,
57
55
)
58
56
@@ -72,7 +70,7 @@ const isConnectable = computed(() => {
72
70
return false
73
71
}
74
72
75
- return id ? id === handleId . value : true
73
+ return id ? id === handleId : true
76
74
})
77
75
}
78
76
@@ -85,7 +83,7 @@ const isConnectable = computed(() => {
85
83
return false
86
84
}
87
85
88
- return id ? id === handleId . value : true
86
+ return id ? id === handleId : true
89
87
}).length < connectable
90
88
)
91
89
}
@@ -97,19 +95,20 @@ const isConnectable = computed(() => {
97
95
return isDef (connectable ) ? connectable : nodesConnectable .value
98
96
})
99
97
98
+ // todo: remove this and have users handle this themselves using `updateNodeInternals`
100
99
// 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)
101
100
until (() => node .initialized )
102
101
.toBe (true , { flush: ' post' })
103
102
.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 )
105
104
106
105
if (! vueFlowRef .value || existingBounds ) {
107
106
return
108
107
}
109
108
110
109
const viewportNode = vueFlowRef .value .querySelector (' .vue-flow__transformationpane' )
111
110
112
- if (! nodeEl .value || ! handle .value || ! viewportNode || ! handleId . value ) {
111
+ if (! nodeEl .value || ! handle .value || ! viewportNode || ! handleId ) {
113
112
return
114
113
}
115
114
@@ -121,7 +120,7 @@ until(() => node.initialized)
121
120
const { m22 : zoom } = new window .DOMMatrixReadOnly (style .transform )
122
121
123
122
const nextBounds = {
124
- id: handleId . value ,
123
+ id: handleId ,
125
124
position ,
126
125
x: (handleBounds .left - nodeBounds .left ) / zoom ,
127
126
y: (handleBounds .top - nodeBounds .top ) / zoom ,
@@ -135,7 +134,7 @@ onUnmounted(() => {
135
134
// clean up node internals
136
135
const handleBounds = node .handleBounds [type .value ]
137
136
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 )
139
138
}
140
139
})
141
140
0 commit comments