Skip to content

Commit 3e446fa

Browse files
committed
feat(core): allow passing a number as connectable prop
1 parent 590fa2a commit 3e446fa

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/core/src/components/Handle/Handle.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { computed, ref } from 'vue'
44
import type { HandleProps } from '../../types/handle'
55
import { Position } from '../../types'
66
import { useHandle, useNode, useVueFlow } from '../../composables'
7-
import { getDimensions, isDef, isFunction, isMouseEvent, isString } from '../../utils'
7+
import { getDimensions, isDef, isFunction, isMouseEvent, isNumber, isString } from '../../utils'
88
99
const {
1010
position = Position.Top,
@@ -59,6 +59,20 @@ const isConnectable = computed(() => {
5959
})
6060
}
6161
62+
if (isNumber(connectable)) {
63+
return (
64+
connectedEdges.value.filter((edge) => {
65+
const id = edge[`${type.value}Handle`]
66+
67+
if (edge[type.value] !== nodeId) {
68+
return false
69+
}
70+
71+
return id ? id === handleId.value : true
72+
}).length < connectable
73+
)
74+
}
75+
6276
if (isFunction(connectable)) {
6377
return connectable(node, connectedEdges.value)
6478
}

packages/core/src/types/handle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export type HandleConnectableFunc = (node: GraphNode, connectedEdges: GraphEdge[
4646
*
4747
* if set to single and the handle already has more than one connection, it will act the same as setting it to false
4848
*/
49-
export type HandleConnectable = boolean | 'single' | HandleConnectableFunc
49+
export type HandleConnectable = boolean | number | 'single' | HandleConnectableFunc
5050

5151
export interface HandleProps {
5252
/** Unique id of handle element */

0 commit comments

Comments
 (0)