From 3e446fab68af6a4e18eaded6b2735c28f8644df0 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:04:56 +0200 Subject: [PATCH] feat(core): allow passing a number as connectable prop --- packages/core/src/components/Handle/Handle.vue | 16 +++++++++++++++- packages/core/src/types/handle.ts | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/core/src/components/Handle/Handle.vue b/packages/core/src/components/Handle/Handle.vue index 9187c216..0a9721d9 100644 --- a/packages/core/src/components/Handle/Handle.vue +++ b/packages/core/src/components/Handle/Handle.vue @@ -4,7 +4,7 @@ import { computed, ref } from 'vue' import type { HandleProps } from '../../types/handle' import { Position } from '../../types' import { useHandle, useNode, useVueFlow } from '../../composables' -import { getDimensions, isDef, isFunction, isMouseEvent, isString } from '../../utils' +import { getDimensions, isDef, isFunction, isMouseEvent, isNumber, isString } from '../../utils' const { position = Position.Top, @@ -59,6 +59,20 @@ const isConnectable = computed(() => { }) } + if (isNumber(connectable)) { + return ( + connectedEdges.value.filter((edge) => { + const id = edge[`${type.value}Handle`] + + if (edge[type.value] !== nodeId) { + return false + } + + return id ? id === handleId.value : true + }).length < connectable + ) + } + if (isFunction(connectable)) { return connectable(node, connectedEdges.value) } diff --git a/packages/core/src/types/handle.ts b/packages/core/src/types/handle.ts index f4368b99..45dd1671 100644 --- a/packages/core/src/types/handle.ts +++ b/packages/core/src/types/handle.ts @@ -46,7 +46,7 @@ export type HandleConnectableFunc = (node: GraphNode, connectedEdges: GraphEdge[ * * if set to single and the handle already has more than one connection, it will act the same as setting it to false */ -export type HandleConnectable = boolean | 'single' | HandleConnectableFunc +export type HandleConnectable = boolean | number | 'single' | HandleConnectableFunc export interface HandleProps { /** Unique id of handle element */