update: dont render nodes, edges if dimensions dont return a truthy value

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-20 03:18:09 +01:00
parent 68b7d99a9c
commit 2b87d53c10
4 changed files with 73 additions and 93 deletions
@@ -1,6 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { CSSProperties } from 'vue' import { CSSProperties } from 'vue'
import { invoke } from '@vueuse/core'
import { ConnectionLineType } from '../../types' 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'
@@ -23,11 +22,6 @@ 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),
@@ -1,5 +1,4 @@
<script lang="ts" setup> <script lang="ts" setup>
import { invoke } from '@vueuse/core'
import { useStore } from '../../composables' import { useStore } from '../../composables'
import Node from '../../components/Nodes/Node.vue' import Node from '../../components/Nodes/Node.vue'
@@ -13,15 +12,10 @@ 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))
</script> </script>
<template> <template>
<Suspense>
<div class="vue-flow__nodes" :style="{ transform }"> <div class="vue-flow__nodes" :style="{ transform }">
<Node <Node
v-for="node of store.getNodes" v-for="node of store.getNodes"
@@ -35,5 +29,4 @@ const snapGrid = computed(() => (store.snapToGrid ? store.snapGrid : undefined))
</template> </template>
</Node> </Node>
</div> </div>
</Suspense>
</template> </template>
+3 -6
View File
@@ -127,7 +127,6 @@ const init = (state: FlowState) => {
} }
onBeforeUnmount(() => store?.$dispose()) onBeforeUnmount(() => store?.$dispose())
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,
@@ -147,11 +146,10 @@ watch(
}, },
{ flush: 'pre', deep: true }, { flush: 'pre', deep: true },
) )
invoke(async () => await until(store.elements).toMatch((y) => y.length > 0)) init(options)
</script> </script>
<template> <template>
<div class="vue-flow"> <div class="vue-flow">
<Suspense>
<ZoomPane <ZoomPane
:selection-key-code="store.selectionKeyCode" :selection-key-code="store.selectionKeyCode"
:zoom-activation-key-code="store.zoomActivationKeyCode" :zoom-activation-key-code="store.zoomActivationKeyCode"
@@ -165,7 +163,7 @@ invoke(async () => await until(store.elements).toMatch((y) => y.length > 0))
:pan-on-scroll-mode="store.panOnScrollMode" :pan-on-scroll-mode="store.panOnScrollMode"
:pane-moveable="store.paneMoveable" :pane-moveable="store.paneMoveable"
> >
<template #default="zoomPaneProps"> <template v-if="store.dimensions.width > 0 && !isNaN(store.dimensions.width)" #default="zoomPaneProps">
<SelectionPane <SelectionPane
:delete-key-code="store.deleteKeyCode" :delete-key-code="store.deleteKeyCode"
:multi-selection-key-code="store.multiSelectionKeyCode" :multi-selection-key-code="store.multiSelectionKeyCode"
@@ -193,8 +191,7 @@ invoke(async () => await until(store.elements).toMatch((y) => y.length > 0))
<slot name="zoom-pane" v-bind="zoomPaneProps"></slot> <slot name="zoom-pane" v-bind="zoomPaneProps"></slot>
</template> </template>
</ZoomPane> </ZoomPane>
</Suspense> <slot v-bind="{ store }"></slot>
<slot v-bind="{ ...props, store }"></slot>
</div> </div>
</template> </template>
<style> <style>
+3 -7
View File
@@ -34,7 +34,6 @@ const props = withDefaults(defineProps<ZoomPaneProps>(), {
paneMoveable: true, paneMoveable: true,
}) })
const store = useStore() const store = useStore()
const zoomPaneEl = templateRef<HTMLDivElement>('zoomPane', null) const zoomPaneEl = templateRef<HTMLDivElement>('zoomPane', null)
const viewChanged = (prevTransform: FlowTransform, eventTransform: ZoomTransform): boolean => const viewChanged = (prevTransform: FlowTransform, eventTransform: ZoomTransform): boolean =>
@@ -185,8 +184,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)
await nextTick(() => {
const instance: FlowInstance = { const instance: FlowInstance = {
fitView: (params = { padding: 0.1 }) => fitView(params), fitView: (params = { padding: 0.1 }) => fitView(params),
zoomIn, zoomIn,
@@ -201,7 +198,6 @@ invoke(async () => {
store.isReady = true store.isReady = true
store.instance = instance store.instance = instance
}) })
})
watch( watch(
[width, height], [width, height],
@@ -223,8 +219,8 @@ watch(
) )
</script> </script>
<template> <template>
<Suspense>
<div ref="zoomPane" class="vue-flow__renderer vue-flow__zoompane"> <div ref="zoomPane" class="vue-flow__renderer vue-flow__zoompane">
<Suspense>
<slot <slot
v-bind="{ v-bind="{
transform, transform,
@@ -235,7 +231,7 @@ watch(
setTransform, setTransform,
fitView, fitView,
}" }"
></slot> />
</div>
</Suspense> </Suspense>
</div>
</template> </template>