diff --git a/packages/core/src/components/Handle/Handle.vue b/packages/core/src/components/Handle/Handle.vue index 20ae1073..d491b822 100644 --- a/packages/core/src/components/Handle/Handle.vue +++ b/packages/core/src/components/Handle/Handle.vue @@ -3,17 +3,17 @@ import { isFunction, isString } from '@vueuse/core' import type { Position } from '../../types' import type { HandleProps } from '../../types/handle' -const { position = 'top' as Position, connectable = true, id, isValidConnection, ...props } = defineProps() +const { position = 'top' as Position, connectable, id, isValidConnection, ...props } = defineProps() const type = toRef(props, 'type', 'source') -const { connectionStartHandle, vueFlowRef, nodesConnectable } = $(useVueFlow()) +const { connectionStartHandle, vueFlowRef, nodesConnectable, noDragClassName } = useVueFlow() const { id: nodeId, node, nodeEl, connectedEdges } = useNode() const handle = ref() -const handleId = $computed(() => id ?? `${nodeId}__handle-${position}`) +const handleId = computed(() => id ?? `${nodeId}__handle-${position}`) const { handlePointerDown, handleClick } = useHandle({ nodeId, @@ -25,50 +25,52 @@ const { handlePointerDown, handleClick } = useHandle({ const isConnectable = computed(() => { if (isString(connectable) && connectable === 'single') { return !connectedEdges.value.some((edge) => { - const handle = edge[`${type.value}Handle`] + const id = edge[`${type.value}Handle`] - if (edge[type.value] !== nodeId) return false + if (edge[type.value] !== nodeId) { + return false + } - return handle ? handle === handleId : true + return id ? id === handleId.value : true }) - } else if (isFunction(connectable)) { + } + + if (isFunction(connectable)) { return connectable(node, connectedEdges.value) } - return isDef(connectable) ? connectable : nodesConnectable + return isDef(connectable) ? connectable : nodesConnectable.value }) -onMounted(() => { - // 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) - until(() => node.initialized) - .toBe(true) - .then(() => { - const existingBounds = node.handleBounds[type.value]?.find((b) => b.id === handleId) +// 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) +until(() => node.initialized) + .toBe(true, { flush: 'post' }) + .then(() => { + const existingBounds = node.handleBounds[type.value]?.find((b) => b.id === handleId.value) - if (!vueFlowRef || existingBounds) return + if (!vueFlowRef.value || existingBounds) return - const viewportNode = vueFlowRef.querySelector('.vue-flow__transformationpane') + const viewportNode = vueFlowRef.value.querySelector('.vue-flow__transformationpane') - if (!nodeEl || !handle.value || !viewportNode || !handleId) return + if (!nodeEl || !handle.value || !viewportNode || !handleId.value) return - const nodeBounds = nodeEl.value.getBoundingClientRect() + const nodeBounds = nodeEl.value.getBoundingClientRect() - const handleBounds = handle.value.getBoundingClientRect() + const handleBounds = handle.value.getBoundingClientRect() - const style = window.getComputedStyle(viewportNode) - const { m22: zoom } = new window.DOMMatrixReadOnly(style.transform) + const style = window.getComputedStyle(viewportNode) + const { m22: zoom } = new window.DOMMatrixReadOnly(style.transform) - const nextBounds = { - id: handleId, - position, - x: (handleBounds.left - nodeBounds.left) / zoom, - y: (handleBounds.top - nodeBounds.top) / zoom, - ...getDimensions(handle.value), - } + const nextBounds = { + id: handleId.value, + position, + x: (handleBounds.left - nodeBounds.left) / zoom, + y: (handleBounds.top - nodeBounds.top) / zoom, + ...getDimensions(handle.value), + } - node.handleBounds[type.value] = [...(node.handleBounds[type.value] ?? []), nextBounds] - }) -}) + node.handleBounds[type.value] = [...(node.handleBounds[type.value] ?? []), nextBounds] + })