From 13473046670a5947ef450e2b17cf2a37c6350eaf Mon Sep 17 00:00:00 2001
From: Braks <78412429+bcakmakoglu@users.noreply.github.com>
Date: Wed, 30 Mar 2022 15:54:59 +0200
Subject: [PATCH] update(nodes): support fragments as node slots
---
package/src/components/Nodes/NodeWrapper.vue | 47 +++----------------
.../container/NodeRenderer/NodeRenderer.vue | 40 +++++++++++++++-
2 files changed, 46 insertions(+), 41 deletions(-)
diff --git a/package/src/components/Nodes/NodeWrapper.vue b/package/src/components/Nodes/NodeWrapper.vue
index 009b710f..b0a91ec6 100644
--- a/package/src/components/Nodes/NodeWrapper.vue
+++ b/package/src/components/Nodes/NodeWrapper.vue
@@ -1,12 +1,13 @@
@@ -164,7 +132,7 @@ export default {
:key="`node-${node.id}`"
:class="[
'vue-flow__node',
- `vue-flow__node-${name}`,
+ `vue-flow__node-${props.name}`,
store.noPanClassName,
{
dragging: node.dragging,
@@ -187,8 +155,7 @@ export default {
@click="onSelectNodeHandler"
@dblclick="onDoubleClick"
>
-
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 = 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
+}