refactor(core): resolve slots before returning default component (#1013)

This commit is contained in:
Braks
2023-07-10 19:20:26 +02:00
parent 82e79a6113
commit 5838454086
5 changed files with 49 additions and 28 deletions
@@ -22,6 +22,8 @@ const {
emits,
} = useVueFlow()
const instance = getCurrentInstance()
function selectable(edgeSelectable?: boolean) {
return typeof edgeSelectable === 'undefined' ? elementsSelectable.value : edgeSelectable
}
@@ -34,8 +36,13 @@ function focusable(edgeFocusable?: boolean) {
function getType(type?: string, template?: GraphEdge['template']) {
const name = type || 'default'
const slot = slots?.[`edge-${name}`]
if (slot) {
return slot
}
let edgeType = template ?? getEdgeTypes.value[name]
const instance = getCurrentInstance()
if (typeof edgeType === 'string') {
if (instance) {
@@ -45,17 +52,14 @@ function getType(type?: string, template?: GraphEdge['template']) {
}
}
}
if (edgeType && typeof edgeType !== 'string') {
return edgeType
}
const slot = slots?.[`edge-${name}`]
if (!slot) {
emits.error(new VueFlowError(ErrorCode.EDGE_TYPE_MISSING, edgeType))
return false
}
emits.error(new VueFlowError(ErrorCode.EDGE_TYPE_MISSING, edgeType))
return slot
return false
}
</script>