@@ -149,8 +149,10 @@ console.log(nodeId.value) // '1'
149
149
150
150
## [ useHandle] ( /typedocs/functions/useHandle )
151
151
152
- Instead of using the Handle component you can use the useHandle composable to create your own custom nodes. ` useHandle `
153
- provides you with a mouseDown- and click-handler functions that you can apply to the element you want to use as a
152
+ Instead of using the Handle component you can use the useHandle composable to create your own custom nodes.
153
+
154
+ ` useHandle `
155
+ provides you with a pointerDown- and click-handler functions that you can apply to the element you want to use as a
154
156
node-handle.
155
157
156
158
This is how the default handle component is built:
@@ -167,40 +169,45 @@ const props = withDefaults(defineProps<HandleProps>(), {
167
169
connectable: true,
168
170
})
169
171
170
- const { id, hooks, connectionStartHandle } = useVueFlow()
171
172
const nodeId = inject(NodeId, '')
172
173
173
- const { onMouseDown, onClick } = useHandle()
174
- const onMouseDownHandler = (event: MouseEvent) =>
175
- onMouseDown(event, props.id ?? null, nodeId, props.type === 'target', props.isValidConnection, undefined, (connection) =>
176
- hooks.value.connect.trigger(connection),
177
- )
178
- const onClickHandler = (event: MouseEvent) => onClick(event, props.id ?? null, nodeId, props.type, props.isValidConnection)
174
+ const { id, hooks, connectionStartHandle } = useVueFlow()
175
+
176
+ const { handlePointerDown, handleClick } = useHandle({
177
+ nodeId,
178
+ handleId: props.id,
179
+ isValidConnection: props.isValidConnection,
180
+ type: props.type,
181
+ })
182
+
183
+ const onMouseDownHandler = (event: MouseEvent) => handlePointerDown(event)
184
+
185
+ const onClickHandler = (event: MouseEvent) => handleClick(event)
179
186
</script>
180
187
181
188
<script lang="ts">
182
189
export default {
183
- name: 'Handle ',
190
+ name: 'CustomHandle ',
184
191
}
185
192
</script>
186
193
187
194
<template>
188
195
<div
189
- :data-handleid="props. id"
196
+ :data-handleid="id"
190
197
:data-nodeid="nodeId"
191
- :data-handlepos="props. position"
198
+ :data-handlepos="position"
192
199
class="vue-flow__handle nodrag"
193
200
:class="[
194
- `vue-flow__handle-${props. position}`,
201
+ `vue-flow__handle-${position}`,
195
202
`vue-flow__handle-${id}`,
196
203
{
197
- source: props. type !== 'target',
198
- target: props. type === 'target',
199
- connectable: props. connectable,
204
+ source: type !== 'target',
205
+ target: type === 'target',
206
+ connectable: connectable,
200
207
connecting:
201
208
connectionStartHandle?.nodeId === nodeId &&
202
- connectionStartHandle?.handleId === props. id &&
203
- connectionStartHandle?.type === props. type,
209
+ connectionStartHandle?.handleId === id &&
210
+ connectionStartHandle?.type === type,
204
211
},
205
212
]"
206
213
@mousedown="onMouseDownHandler"
0 commit comments