From 668fed1dc4b65b008df605417d74141dfab61a0d Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Sat, 20 Nov 2021 18:22:05 +0100 Subject: [PATCH] feat: Add dedicated default loading component * add option to pass a transition name Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com> --- examples/Stress/StressExample.vue | 13 +- src/components/Loading/LoadingIndicator.vue | 18 +++ src/container/VueFlow/VueFlow.vue | 138 ++++++++++++-------- src/store/utils.ts | 2 +- src/types/store.ts | 15 +-- src/types/types.ts | 16 ++- 6 files changed, 137 insertions(+), 65 deletions(-) create mode 100644 src/components/Loading/LoadingIndicator.vue diff --git a/examples/Stress/StressExample.vue b/examples/Stress/StressExample.vue index 68d24c35..66675ebf 100644 --- a/examples/Stress/StressExample.vue +++ b/examples/Stress/StressExample.vue @@ -51,7 +51,7 @@ const updateElements = () => { + diff --git a/src/components/Loading/LoadingIndicator.vue b/src/components/Loading/LoadingIndicator.vue new file mode 100644 index 00000000..9dcefbea --- /dev/null +++ b/src/components/Loading/LoadingIndicator.vue @@ -0,0 +1,18 @@ + + diff --git a/src/container/VueFlow/VueFlow.vue b/src/container/VueFlow/VueFlow.vue index 07dcb792..f1bf220a 100644 --- a/src/container/VueFlow/VueFlow.vue +++ b/src/container/VueFlow/VueFlow.vue @@ -16,11 +16,13 @@ import { FlowStore, FlowState, FlowInstance, + Loading, } from '../../types' -import ZoomPane from '../../container/ZoomPane/ZoomPane.vue' -import SelectionPane from '../../container/SelectionPane/SelectionPane.vue' -import NodeRenderer from '../../container/NodeRenderer/NodeRenderer.vue' -import EdgeRenderer from '../../container/EdgeRenderer/EdgeRenderer.vue' +import ZoomPane from '../ZoomPane/ZoomPane.vue' +import SelectionPane from '../SelectionPane/SelectionPane.vue' +import NodeRenderer from '../NodeRenderer/NodeRenderer.vue' +import EdgeRenderer from '../EdgeRenderer/EdgeRenderer.vue' +import LoadingIndicator from '../../components/Loading/LoadingIndicator.vue' import { createHooks, initFlow, useZoomPanHelper } from '../../composables' import { onLoadGetElements, onLoadProject, onLoadToObject } from '../../utils' @@ -62,7 +64,7 @@ export interface FlowProps extends Partial { zoomOnDoubleClick?: boolean edgeUpdaterRadius?: number storageKey?: string - showLoadingIndicator?: boolean + loading?: Loading } const emit = defineEmits([...Object.keys(createHooks()), 'update:elements', 'update:modelValue']) @@ -104,7 +106,7 @@ const props = withDefaults(defineProps(), { panOnScrollMode: PanOnScrollMode.Free, paneMoveable: true, edgeUpdaterRadius: 10, - showLoadingIndicator: false, + loading: false, }) const store = initFlow(emit, typeof props.storageKey === 'string' ? props.storageKey : props.id, props.store) const elements = useVModel(props, props.elements.length ? 'elements' : 'modelValue', emit) @@ -169,57 +171,89 @@ invoke(async () => { store.hooks.load.trigger(instance) store.instance = instance }) + +const transitionName = computed(() => { + let name = '' + if (typeof store.loading === 'object' && store.loading.transition) { + if (typeof store.loading.transition === 'string') name = store.loading.transition + else name = store.loading.transition.name + } + return name +}) + +const transitionMode = computed(() => { + let mode = '' + if (typeof store.loading === 'object' && store.loading.transition) { + if (typeof store.loading.transition !== 'string') mode = store.loading.transition.mode + } + return mode +})