11<script lang="ts" setup>
2- import { getCurrentInstance , inject , nextTick , onBeforeUnmount , onMounted , resolveComponent } from ' vue'
2+ import { getCurrentInstance , inject , nextTick , onBeforeUnmount , onMounted , ref , resolveComponent } from ' vue'
33import { until } from ' @vueuse/core'
44import { NodeWrapper } from ' ../../components'
55import type { GraphNode , HandleConnectable , NodeComponent } from ' ../../types'
@@ -19,20 +19,22 @@ const {
1919 getNodeTypes,
2020 updateNodeDimensions,
2121 emits,
22- } = $ ( useVueFlow () )
22+ } = useVueFlow ()
2323
24- let resizeObserver = $ ref <ResizeObserver >()
24+ const resizeObserver = ref <ResizeObserver >()
2525
26- until (() => getNodes .length > 0 && getNodesInitialized .length === getNodes .length )
26+ const instance = getCurrentInstance ()
27+
28+ until (() => getNodes .value .length > 0 && getNodesInitialized .value .length === getNodes .value .length )
2729 .toBe (true )
2830 .then (() => {
2931 nextTick (() => {
30- emits .nodesInitialized (getNodesInitialized )
32+ emits .nodesInitialized (getNodesInitialized . value )
3133 })
3234 })
3335
3436onMounted (() => {
35- resizeObserver = new ResizeObserver ((entries ) => {
37+ resizeObserver . value = new ResizeObserver ((entries ) => {
3638 const updates = entries .map ((entry ) => {
3739 const id = entry .target .getAttribute (' data-id' ) as string
3840
@@ -47,25 +49,30 @@ onMounted(() => {
4749 })
4850})
4951
50- onBeforeUnmount (() => resizeObserver ?.disconnect ())
52+ onBeforeUnmount (() => resizeObserver . value ?.disconnect ())
5153
5254function draggable(nodeDraggable ? : boolean ) {
53- return typeof nodeDraggable === ' undefined' ? nodesDraggable : nodeDraggable
55+ return typeof nodeDraggable === ' undefined' ? nodesDraggable . value : nodeDraggable
5456}
5557function selectable(nodeSelectable ? : boolean ) {
56- return typeof nodeSelectable === ' undefined' ? elementsSelectable : nodeSelectable
58+ return typeof nodeSelectable === ' undefined' ? elementsSelectable . value : nodeSelectable
5759}
5860function connectable(nodeConnectable ? : HandleConnectable ) {
59- return typeof nodeConnectable === ' undefined' ? nodesConnectable : nodeConnectable
61+ return typeof nodeConnectable === ' undefined' ? nodesConnectable . value : nodeConnectable
6062}
6163function focusable(nodeFocusable ? : boolean ) {
62- return typeof nodeFocusable === ' undefined' ? nodesFocusable : nodeFocusable
64+ return typeof nodeFocusable === ' undefined' ? nodesFocusable . value : nodeFocusable
6365}
6466
6567function getType(type ? : string , template ? : GraphNode [' template' ]) {
6668 const name = type || ' default'
67- let nodeType = template ?? getNodeTypes [name ]
68- const instance = getCurrentInstance ()
69+
70+ const slot = slots ?.[` node-${name } ` ]
71+ if (slot ) {
72+ return slot
73+ }
74+
75+ let nodeType = template ?? getNodeTypes .value [name ]
6976
7077 if (typeof nodeType === ' string' ) {
7178 if (instance ) {
@@ -75,17 +82,14 @@ function getType(type?: string, template?: GraphNode['template']) {
7582 }
7683 }
7784 }
78- if (typeof nodeType !== ' string' ) {
85+
86+ if (nodeType && typeof nodeType !== ' string' ) {
7987 return nodeType
8088 }
8189
82- const slot = slots ?.[` node-${name } ` ]
83- if (! slot ) {
84- emits .error (new VueFlowError (ErrorCode .NODE_TYPE_MISSING , nodeType ))
85- return false
86- }
90+ emits .error (new VueFlowError (ErrorCode .NODE_TYPE_MISSING , nodeType ))
8791
88- return slot
92+ return false
8993}
9094 </script >
9195
0 commit comments