chore(docs): update useHandle docs

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2024-08-30 09:36:14 +02:00
parent 564d5931a5
commit 940b08e080
+25 -18
View File
@@ -149,8 +149,10 @@ console.log(nodeId.value) // '1'
## [useHandle](/typedocs/functions/useHandle) ## [useHandle](/typedocs/functions/useHandle)
Instead of using the Handle component you can use the useHandle composable to create your own custom nodes. `useHandle` Instead of using the Handle component you can use the useHandle composable to create your own custom nodes.
provides you with a mouseDown- and click-handler functions that you can apply to the element you want to use as a
`useHandle`
provides you with a pointerDown- and click-handler functions that you can apply to the element you want to use as a
node-handle. node-handle.
This is how the default handle component is built: This is how the default handle component is built:
@@ -167,40 +169,45 @@ const props = withDefaults(defineProps<HandleProps>(), {
connectable: true, connectable: true,
}) })
const { id, hooks, connectionStartHandle } = useVueFlow()
const nodeId = inject(NodeId, '') const nodeId = inject(NodeId, '')
const { onMouseDown, onClick } = useHandle() const { id, hooks, connectionStartHandle } = useVueFlow()
const onMouseDownHandler = (event: MouseEvent) =>
onMouseDown(event, props.id ?? null, nodeId, props.type === 'target', props.isValidConnection, undefined, (connection) => const { handlePointerDown, handleClick } = useHandle({
hooks.value.connect.trigger(connection), nodeId,
) handleId: props.id,
const onClickHandler = (event: MouseEvent) => onClick(event, props.id ?? null, nodeId, props.type, props.isValidConnection) isValidConnection: props.isValidConnection,
type: props.type,
})
const onMouseDownHandler = (event: MouseEvent) => handlePointerDown(event)
const onClickHandler = (event: MouseEvent) => handleClick(event)
</script> </script>
<script lang="ts"> <script lang="ts">
export default { export default {
name: 'Handle', name: 'CustomHandle',
} }
</script> </script>
<template> <template>
<div <div
:data-handleid="props.id" :data-handleid="id"
:data-nodeid="nodeId" :data-nodeid="nodeId"
:data-handlepos="props.position" :data-handlepos="position"
class="vue-flow__handle nodrag" class="vue-flow__handle nodrag"
:class="[ :class="[
`vue-flow__handle-${props.position}`, `vue-flow__handle-${position}`,
`vue-flow__handle-${id}`, `vue-flow__handle-${id}`,
{ {
source: props.type !== 'target', source: type !== 'target',
target: props.type === 'target', target: type === 'target',
connectable: props.connectable, connectable: connectable,
connecting: connecting:
connectionStartHandle?.nodeId === nodeId && connectionStartHandle?.nodeId === nodeId &&
connectionStartHandle?.handleId === props.id && connectionStartHandle?.handleId === id &&
connectionStartHandle?.type === props.type, connectionStartHandle?.type === type,
}, },
]" ]"
@mousedown="onMouseDownHandler" @mousedown="onMouseDownHandler"