fix(nodes,edges): compute type in wrapper

This commit is contained in:
Braks
2022-04-04 21:42:48 +02:00
parent 8e6e85a007
commit 546dd4baaf
4 changed files with 75 additions and 91 deletions
@@ -3,44 +3,10 @@ import EdgeWrapper from '../../components/Edges/EdgeWrapper.vue'
import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue'
import { useVueFlow } from '../../composables'
import { groupEdgesByZLevel } from '../../utils'
import { Slots } from '../../context'
import { EdgeComponent } from '../../types'
import MarkerDefinitions from './MarkerDefinitions.vue'
const { store } = useVueFlow()
const slots = inject(Slots)
const names: Record<string, string> = reactive({})
const getType = (name = 'default') => {
const instance = getCurrentInstance()
let edgeType = store.getEdgeTypes[name]
if (typeof edgeType === 'string') {
if (instance) {
const components = Object.keys(instance.appContext.components)
if (components && components.includes(name)) {
edgeType = resolveComponent(name, false) as EdgeComponent
}
}
}
if (typeof edgeType !== 'string') {
names[name] = name
return edgeType
}
const slot = slots?.[`node-${name}`]
if (!slot?.({})) {
console.warn(`[vueflow]: Edge type "${name}" not found and no edge-slot detected. Using fallback type "default".`)
names[name] = 'default'
return store.getEdgeTypes.default
}
names[name] = name
return slot
}
const sourceNode = controlledComputed(
() => store.connectionNodeId,
() => {
@@ -80,17 +46,10 @@ export default {
:id="edge.id"
:key="edge.id"
:edge="edge"
:name="typeof edge.type !== 'undefined' && typeof names[edge.type] !== 'undefined' ? names[edge.type] : 'default'"
:selectable="typeof edge.selectable === 'undefined' ? store.elementsSelectable : edge.selectable"
:updatable="typeof edge.updatable === 'undefined' ? store.edgesUpdatable : edge.updatable"
>
<template #default="props">
<component :is="getType(edge.type)" v-bind="props" />
</template>
</EdgeWrapper>
<ConnectionLine v-if="connectionLineVisible && sourceNode" :source-node="sourceNode">
<slot name="connection-line" />
</ConnectionLine>
/>
<ConnectionLine v-if="connectionLineVisible && sourceNode" :source-node="sourceNode" />
</g>
</svg>
</template>
@@ -1,41 +1,8 @@
<script lang="ts" setup>
import NodeWrapper from '../../components/Nodes/NodeWrapper.vue'
import { useVueFlow } from '../../composables'
import { NodeComponent } from '../../types'
import { Slots } from '../../context'
const { store } = useVueFlow()
const slots = inject(Slots)
const names: Record<string, string> = reactive({})
const getType = (name = 'default') => {
const instance = getCurrentInstance()
let nodeType = store.getNodeTypes[name]
if (typeof nodeType === 'string') {
if (instance) {
const components = Object.keys(instance.appContext.components)
if (components && components.includes(name)) {
nodeType = resolveComponent(name, false) as NodeComponent
}
}
}
if (typeof nodeType !== 'string') {
names[name] = name
return nodeType
}
const slot = slots?.[`node-${name}`]
if (!slot?.({})) {
console.warn(`[vueflow]: Node type "${name}" not found and no node-slot detected. Using fallback type "default".`)
names[name] = 'default'
return store.getNodeTypes.default
}
names[name] = name
return slot
}
</script>
<script lang="ts">
export default {
@@ -49,15 +16,10 @@ export default {
:id="node.id"
:key="`vue-flow__node-${node.id}`"
:node="node"
:name="typeof node.type !== 'undefined' && typeof names[node.type] !== 'undefined' ? names[node.type] : 'default'"
:draggable="typeof node.draggable === 'undefined' ? store.nodesDraggable : !!node.draggable"
:selectable="typeof node.selectable === 'undefined' ? store.elementsSelectable : !!node.selectable"
:connectable="typeof node.connectable === 'undefined' ? store.nodesConnectable : !!node.connectable"
:snap-grid="node.snapGrid ?? (store.snapToGrid ? store.snapGrid : undefined)"
>
<template #default="props">
<component :is="getType(node.type)" v-bind="props" />
</template>
</NodeWrapper>
/>
</div>
</template>