refactor(core): allow adding edges with missing source or target nodes

This commit is contained in:
braks
2023-10-30 13:36:07 +01:00
committed by Braks
parent b195ff86fb
commit 7e7e0fb8cb
2 changed files with 29 additions and 23 deletions
@@ -5,7 +5,15 @@ import type { Connection, EdgeComponent, EdgeUpdatable, GraphEdge, HandleType, M
import { ConnectionMode, Position } from '~/types' import { ConnectionMode, Position } from '~/types'
import { useEdgeHooks, useHandle, useVueFlow } from '~/composables' import { useEdgeHooks, useHandle, useVueFlow } from '~/composables'
import { EdgeId, EdgeRef } from '~/context' import { EdgeId, EdgeRef } from '~/context'
import { ARIA_EDGE_DESC_KEY, elementSelectionKeys, getEdgePositions, getHandle, getMarkerId } from '~/utils' import {
ARIA_EDGE_DESC_KEY,
ErrorCode,
VueFlowError,
elementSelectionKeys,
getEdgePositions,
getHandle,
getMarkerId,
} from '~/utils'
interface Props { interface Props {
id: string id: string
@@ -36,6 +44,7 @@ const EdgeWrapper = defineComponent({
findNode, findNode,
isValidConnection, isValidConnection,
multiSelectionActive, multiSelectionActive,
hooks: flowHooks,
} = useVueFlow() } = useVueFlow()
const hooks = useEdgeHooks(props.edge, emits) const hooks = useEdgeHooks(props.edge, emits)
@@ -74,7 +83,25 @@ const EdgeWrapper = defineComponent({
const sourceNode = findNode(edge.source) const sourceNode = findNode(edge.source)
const targetNode = findNode(edge.target) const targetNode = findNode(edge.target)
if (!sourceNode || !targetNode || !edge || sourceNode.hidden || targetNode.hidden) { if (!sourceNode && !targetNode) {
flowHooks.value.error.trigger(new VueFlowError(ErrorCode.EDGE_SOURCE_TARGET_MISSING, edge.id, edge.source, edge.target))
return null
}
if (!sourceNode) {
flowHooks.value.error.trigger(new VueFlowError(ErrorCode.EDGE_SOURCE_MISSING, edge.id, edge.source))
return null
}
if (!targetNode) {
flowHooks.value.error.trigger(new VueFlowError(ErrorCode.EDGE_TARGET_MISSING, edge.id, edge.target))
return null
}
if (!edge || sourceNode.hidden || targetNode.hidden) {
return null return null
} }
-21
View File
@@ -489,27 +489,6 @@ export function useActions(
const sourceNode = findNode(edge.source)! const sourceNode = findNode(edge.source)!
const targetNode = findNode(edge.target)! const targetNode = findNode(edge.target)!
const missingSource = !sourceNode || typeof sourceNode === 'undefined'
const missingTarget = !targetNode || typeof targetNode === 'undefined'
if (missingSource && missingTarget) {
state.hooks.error.trigger(new VueFlowError(ErrorCode.EDGE_SOURCE_TARGET_MISSING, edge.id, edge.source, edge.target))
return edgeChanges
}
if (missingSource) {
state.hooks.error.trigger(new VueFlowError(ErrorCode.EDGE_SOURCE_MISSING, edge.id, edge.source))
return edgeChanges
}
if (missingTarget) {
state.hooks.error.trigger(new VueFlowError(ErrorCode.EDGE_TARGET_MISSING, edge.id, edge.target))
return edgeChanges
}
edgeChanges.push( edgeChanges.push(
createAdditionChange<GraphEdge>({ createAdditionChange<GraphEdge>({
...edge, ...edge,