fix: suspension not working properly
* move invoke to vueflow to suspend * await dimensions in Node/Edge-wrapper components * await nodes/edges in renderer * await elements in VueFlow Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useHandle, useStore } from '../../composables'
|
import { useHandle, useStore } from '../../composables'
|
||||||
import { ConnectionMode, Edge, EdgePositions, Position } from '../../types'
|
import { ConnectionMode, Edge, EdgePositions, Position } from '../../types'
|
||||||
|
import { getEdgePositions, getHandle, getSourceTargetNodes, isEdgeVisible } from '../../container/EdgeRenderer/utils'
|
||||||
|
import { isEdge } from '../../utils'
|
||||||
import EdgeAnchor from './EdgeAnchor.vue'
|
import EdgeAnchor from './EdgeAnchor.vue'
|
||||||
import { getEdgePositions, getHandle, getSourceTargetNodes, isEdgeVisible } from '~/container/EdgeRenderer/utils'
|
|
||||||
import { isEdge } from '~/utils'
|
|
||||||
|
|
||||||
interface EdgeProps {
|
interface EdgeProps {
|
||||||
edge: Edge
|
edge: Edge
|
||||||
|
|||||||
@@ -148,33 +148,48 @@ onMounted(() => {
|
|||||||
@move="onDrag"
|
@move="onDrag"
|
||||||
@stop="onDragStop"
|
@stop="onDragStop"
|
||||||
>
|
>
|
||||||
<Suspense>
|
<div
|
||||||
<div
|
ref="node-element"
|
||||||
ref="node-element"
|
:class="[
|
||||||
:class="[
|
'vue-flow__node',
|
||||||
'vue-flow__node',
|
`vue-flow__node-${props.node.type}`,
|
||||||
`vue-flow__node-${props.node.type}`,
|
{
|
||||||
{
|
selected,
|
||||||
selected,
|
selectable: selectable,
|
||||||
selectable: selectable,
|
},
|
||||||
},
|
props.node.class,
|
||||||
props.node.class,
|
]"
|
||||||
]"
|
:style="{
|
||||||
:style="{
|
zIndex: selected ? 10 : 3,
|
||||||
zIndex: selected ? 10 : 3,
|
transform: `translate(${props.node.__rf?.position?.x}px,${props.node.__rf?.position?.y}px)`,
|
||||||
transform: `translate(${props.node.__rf?.position?.x}px,${props.node.__rf?.position?.y}px)`,
|
pointerEvents: selectable || draggable ? 'all' : 'none',
|
||||||
pointerEvents: selectable || draggable ? 'all' : 'none',
|
opacity: props.node.__rf?.width !== null && props.node.__rf?.height !== null ? 1 : 0,
|
||||||
opacity: props.node.__rf?.width !== null && props.node.__rf?.height !== null ? 1 : 0,
|
...props.node.style,
|
||||||
...props.node.style,
|
}"
|
||||||
|
:data-id="props.node.id"
|
||||||
|
@mouseenter="onMouseEnterHandler"
|
||||||
|
@mousemove="onMouseMoveHandler"
|
||||||
|
@mouseleave="onMouseLeaveHandler"
|
||||||
|
@contextmenu="onContextMenuHandler"
|
||||||
|
@click="onSelectNodeHandler"
|
||||||
|
>
|
||||||
|
<slot
|
||||||
|
v-bind="{
|
||||||
|
id: props.node.id,
|
||||||
|
data: props.node.data,
|
||||||
|
type: props.node.type,
|
||||||
|
xPos: props.node.__rf?.position?.x,
|
||||||
|
yPos: props.node.__rf?.position?.y,
|
||||||
|
selected,
|
||||||
|
connectable,
|
||||||
|
sourcePosition: props.node.sourcePosition,
|
||||||
|
targetPosition: props.node.targetPosition,
|
||||||
|
dragging: props.node.__rf?.isDragging,
|
||||||
}"
|
}"
|
||||||
:data-id="props.node.id"
|
|
||||||
@mouseenter="onMouseEnterHandler"
|
|
||||||
@mousemove="onMouseMoveHandler"
|
|
||||||
@mouseleave="onMouseLeaveHandler"
|
|
||||||
@contextmenu="onContextMenuHandler"
|
|
||||||
@click="onSelectNodeHandler"
|
|
||||||
>
|
>
|
||||||
<slot
|
<component
|
||||||
|
:is="type"
|
||||||
|
v-if="typeof type !== 'boolean'"
|
||||||
v-bind="{
|
v-bind="{
|
||||||
id: props.node.id,
|
id: props.node.id,
|
||||||
data: props.node.data,
|
data: props.node.data,
|
||||||
@@ -187,25 +202,8 @@ onMounted(() => {
|
|||||||
targetPosition: props.node.targetPosition,
|
targetPosition: props.node.targetPosition,
|
||||||
dragging: props.node.__rf?.isDragging,
|
dragging: props.node.__rf?.isDragging,
|
||||||
}"
|
}"
|
||||||
>
|
/>
|
||||||
<component
|
</slot>
|
||||||
:is="type"
|
</div>
|
||||||
v-if="typeof type !== 'boolean'"
|
|
||||||
v-bind="{
|
|
||||||
id: props.node.id,
|
|
||||||
data: props.node.data,
|
|
||||||
type: props.node.type,
|
|
||||||
xPos: props.node.__rf?.position?.x,
|
|
||||||
yPos: props.node.__rf?.position?.y,
|
|
||||||
selected,
|
|
||||||
connectable,
|
|
||||||
sourcePosition: props.node.sourcePosition,
|
|
||||||
targetPosition: props.node.targetPosition,
|
|
||||||
dragging: props.node.__rf?.isDragging,
|
|
||||||
}"
|
|
||||||
/>
|
|
||||||
</slot>
|
|
||||||
</div>
|
|
||||||
</Suspense>
|
|
||||||
</DraggableCore>
|
</DraggableCore>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { CSSProperties } from 'vue'
|
import { CSSProperties } from 'vue'
|
||||||
import { ConnectionLineType, Edge as TEdge } from '../../types'
|
import { invoke } from '@vueuse/core'
|
||||||
|
import { ConnectionLineType } from '../../types'
|
||||||
import { useStore } from '../../composables'
|
import { useStore } from '../../composables'
|
||||||
import Edge from '../../components/Edges/Edge.vue'
|
import Edge from '../../components/Edges/Edge.vue'
|
||||||
import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue'
|
import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue'
|
||||||
@@ -22,6 +23,11 @@ const props = withDefaults(defineProps<EdgeRendererProps>(), {
|
|||||||
|
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
|
|
||||||
|
invoke(async () => {
|
||||||
|
await until(store.getNodes).toMatch((y) => y && y.length > 0)
|
||||||
|
await until(store.transform).toMatch(([x, y, z]) => !isNaN(x) && x !== 0 && !isNaN(y) && y !== 0 && isNaN(z) && z !== 1)
|
||||||
|
})
|
||||||
|
|
||||||
const sourceNode = computed(() => store.nodes.find((n) => n.id === store.connectionNodeId))
|
const sourceNode = computed(() => store.nodes.find((n) => n.id === store.connectionNodeId))
|
||||||
const connectionLineVisible = computed(
|
const connectionLineVisible = computed(
|
||||||
() => !!(store.nodesConnectable && sourceNode.value && store.connectionNodeId && store.connectionHandleType),
|
() => !!(store.nodesConnectable && sourceNode.value && store.connectionNodeId && store.connectionHandleType),
|
||||||
|
|||||||
@@ -13,17 +13,16 @@ const props = withDefaults(defineProps<NodeRendererProps>(), {
|
|||||||
|
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
|
|
||||||
|
invoke(async () => {
|
||||||
|
await until(store.getNodes).toMatch((y) => y && y.length > 0)
|
||||||
|
await until(store.transform).toMatch(([x, y, z]) => !isNaN(x) && x !== 0 && !isNaN(y) && y !== 0 && isNaN(z) && z !== 1)
|
||||||
|
})
|
||||||
const transform = computed(() => `translate(${store.transform[0]}px,${store.transform[1]}px) scale(${store.transform[2]})`)
|
const transform = computed(() => `translate(${store.transform[0]}px,${store.transform[1]}px) scale(${store.transform[2]})`)
|
||||||
const snapGrid = computed(() => (store.snapToGrid ? store.snapGrid : undefined))
|
const snapGrid = computed(() => (store.snapToGrid ? store.snapGrid : undefined))
|
||||||
|
|
||||||
invoke(async () => {
|
|
||||||
await until(store.getNodes).toMatch((y) => y.length > 0)
|
|
||||||
await until(store.transform).toMatch(([x, y, z]) => x !== 0 && y !== 0 && z !== 1)
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="vue-flow__nodes" :style="{ transform }">
|
<Suspense>
|
||||||
<Suspense>
|
<div class="vue-flow__nodes" :style="{ transform }">
|
||||||
<Node
|
<Node
|
||||||
v-for="node of store.getNodes"
|
v-for="node of store.getNodes"
|
||||||
:key="node.id"
|
:key="node.id"
|
||||||
@@ -35,6 +34,6 @@ invoke(async () => {
|
|||||||
<slot :name="`node-${node.type}`" v-bind="nodeProps"></slot>
|
<slot :name="`node-${node.type}`" v-bind="nodeProps"></slot>
|
||||||
</template>
|
</template>
|
||||||
</Node>
|
</Node>
|
||||||
</Suspense>
|
</div>
|
||||||
</div>
|
</Suspense>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { CSSProperties, onBeforeUnmount } from 'vue'
|
import { CSSProperties, onBeforeUnmount } from 'vue'
|
||||||
import diff from 'microdiff'
|
import diff from 'microdiff'
|
||||||
|
import { invoke } from '@vueuse/core'
|
||||||
import {
|
import {
|
||||||
ConnectionLineType,
|
ConnectionLineType,
|
||||||
ConnectionMode,
|
ConnectionMode,
|
||||||
@@ -126,7 +127,7 @@ const init = (state: FlowState) => {
|
|||||||
}
|
}
|
||||||
onBeforeUnmount(() => store?.$dispose())
|
onBeforeUnmount(() => store?.$dispose())
|
||||||
|
|
||||||
init(options)
|
onMounted(() => init(options))
|
||||||
watch(elements, (val) => store.setElements(val), { flush: 'post', deep: true })
|
watch(elements, (val) => store.setElements(val), { flush: 'post', deep: true })
|
||||||
watch(
|
watch(
|
||||||
() => store.elements,
|
() => store.elements,
|
||||||
@@ -146,6 +147,7 @@ watch(
|
|||||||
},
|
},
|
||||||
{ flush: 'pre', deep: true },
|
{ flush: 'pre', deep: true },
|
||||||
)
|
)
|
||||||
|
invoke(async () => await until(store.elements).toMatch((y) => y.length > 0))
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="vue-flow">
|
<div class="vue-flow">
|
||||||
|
|||||||
@@ -185,7 +185,6 @@ store.dimensions = {
|
|||||||
|
|
||||||
invoke(async () => {
|
invoke(async () => {
|
||||||
await until(() => !isNaN(width.value) && width.value > 0 && !isNaN(height.value) && height.value > 0).toBeTruthy()
|
await until(() => !isNaN(width.value) && width.value > 0 && !isNaN(height.value) && height.value > 0).toBeTruthy()
|
||||||
await until(store.elements).toMatch((y) => y.length > 0)
|
|
||||||
const instance: FlowInstance = {
|
const instance: FlowInstance = {
|
||||||
fitView: (params = { padding: 0.1 }) => fitView(params),
|
fitView: (params = { padding: 0.1 }) => fitView(params),
|
||||||
zoomIn,
|
zoomIn,
|
||||||
|
|||||||
Reference in New Issue
Block a user