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 @@
+
+
+
+ {{ props.label }}
+
+
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
+})
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
- Almost ready...
-
-
-
+
+
diff --git a/src/store/utils.ts b/src/store/utils.ts
index ea73edbd..540e4a5a 100644
--- a/src/store/utils.ts
+++ b/src/store/utils.ts
@@ -88,7 +88,7 @@ export const initialState = (): FlowState => ({
isReady: false,
hooks: createHooks(),
- showLoadingIndicator: false,
+ loading: false,
vueFlowVersion: typeof __VUE_FLOW_VERSION__ !== 'undefined' ? __VUE_FLOW_VERSION__ : '-',
})
diff --git a/src/types/store.ts b/src/types/store.ts
index 56ca3d93..e764899f 100644
--- a/src/types/store.ts
+++ b/src/types/store.ts
@@ -20,13 +20,9 @@ import { D3Selection, D3Zoom, D3ZoomHandler } from './panel'
import { FlowHooks } from './hooks'
export interface FlowState extends FlowOptions {
- dimensions: Dimensions
- transform: Transform
elements: Elements
nodes: Node[]
- nodeTypes?: NodeTypes
edges: Edge[]
- edgeTypes?: EdgeTypes
selectedElements?: Elements
selectedNodesBbox: Rect
@@ -37,11 +33,13 @@ export interface FlowState extends FlowOptions {
maxZoom: number
translateExtent: TranslateExtent
nodeExtent: NodeExtent
+ dimensions: Dimensions
+ transform: Transform
nodesSelectionActive: boolean
selectionActive: boolean
-
userSelectionRect: SelectionRect
+ multiSelectionActive: boolean
connectionNodeId?: ElementId
connectionHandleId?: ElementId
@@ -56,10 +54,6 @@ export interface FlowState extends FlowOptions {
nodesConnectable: boolean
elementsSelectable: boolean
- multiSelectionActive: boolean
-
- vueFlowVersion: string
-
onConnect?: OnConnectFunc
onConnectStart?: OnConnectStartFunc
onConnectStop?: OnConnectStopFunc
@@ -67,8 +61,9 @@ export interface FlowState extends FlowOptions {
isReady: boolean
hooks: FlowHooks
- storageKey?: string
instance?: FlowInstance
+
+ vueFlowVersion: string
}
export interface FlowGetters {
diff --git a/src/types/types.ts b/src/types/types.ts
index 989ea4b2..58866457 100644
--- a/src/types/types.ts
+++ b/src/types/types.ts
@@ -78,6 +78,20 @@ export type FitViewFunc = (fitViewOptions?: FitViewParams) => void
export type ProjectFunc = (position: XYPosition) => XYPosition
export type ToObjectFunc = () => FlowExportObject
+export type Loading =
+ | {
+ label: string
+ transition?:
+ | string
+ | {
+ name: string
+ mode: string
+ }
+ style: CSSProperties
+ class: string
+ }
+ | boolean
+
export type FlowInstance = {
zoomIn: () => void
zoomOut: () => void
@@ -126,5 +140,5 @@ export interface FlowOptions {
zoomOnDoubleClick?: boolean
edgeUpdaterRadius?: number
storageKey?: string
- showLoadingIndicator?: boolean
+ loading?: Loading
}