fix(handles): only check for matching handle id if an id exists

This commit is contained in:
braks
2022-10-12 16:10:48 +02:00
committed by Braks
parent bc80807285
commit a7845c6032
2 changed files with 11 additions and 2 deletions

View File

@@ -27,7 +27,10 @@ const { onMouseDown, onClick } = useHandle({
const isConnectable = computed(() => {
if (isString(connectable) && connectable === 'single') {
return !connectedEdges.value.some((edge) => edge[type.value] === nodeId && edge[`${type.value}Handle`] === handleId)
return !connectedEdges.value.some((edge) => {
const handle = edge[`${type.value}Handle`]
return edge[type.value] === nodeId && !!handle ? edge[`${type.value}Handle`] === handleId : true
})
} else if (isFunction(connectable)) {
return connectable(node, connectedEdges.value)
}

View File

@@ -22,7 +22,13 @@ export type ValidConnectionFunc = (
elements: { edges: GraphEdge[]; sourceNode: GraphNode; targetNode: GraphNode },
) => boolean
/** set to true to allow unlimited connections, single for only one connection or use a cb function to determine connect-ability */
/**
* set to true to allow unlimited connections,
* single for only one connection
* or use a cb function to determine connect-ability
*
* 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' | ((node: GraphNode, connectedEdges: GraphEdge[]) => boolean)
export interface HandleProps {