diff --git a/package.json b/package.json index 43753db4..6ee0ddf8 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "typescript": "^4.4.4", "typescript-transform-paths": "^3.3.1", "unplugin-auto-import": "^0.4.12", - "vite": "^2.6.10", + "vite": "^2.6.14", "vite-svg-loader": "^2.2.0", "vue": "^3.2.22", "vue-router": "^4.0.12", diff --git a/src/container/SelectionPane/SelectionPane.vue b/src/container/SelectionPane/SelectionPane.vue index cff5dfe8..69938c14 100644 --- a/src/container/SelectionPane/SelectionPane.vue +++ b/src/container/SelectionPane/SelectionPane.vue @@ -46,9 +46,13 @@ onMounted(() => { } }) - useKeyPress(props.multiSelectionKeyCode, (keyPressed) => (store.multiSelectionActive = keyPressed)) + useKeyPress(props.multiSelectionKeyCode, (keyPressed) => { + store.multiSelectionActive = keyPressed + }) - useKeyPress(props.selectionKeyCode, (keyPressed) => (selectionKeyPresed.value = keyPressed)) + useKeyPress(props.selectionKeyCode, (keyPressed) => { + selectionKeyPresed.value = keyPressed + }) }) const userSelection = computed(() => selectionKeyPresed.value && (store.selectionActive || store.elementsSelectable)) const nodesSelectionActive = computed(() => store.nodesSelectionActive) diff --git a/src/container/VueFlow/VueFlow.vue b/src/container/VueFlow/VueFlow.vue index 63ed9574..f0d8371f 100644 --- a/src/container/VueFlow/VueFlow.vue +++ b/src/container/VueFlow/VueFlow.vue @@ -15,12 +15,14 @@ import { EdgeTypes, FlowStore, FlowState, + FlowInstance, } 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 { createHooks, initFlow } from '../../composables' +import { createHooks, initFlow, useZoomPanHelper } from '../../composables' +import { onLoadGetElements, onLoadProject, onLoadToObject } from '~/utils' export interface FlowProps extends Partial { id?: string @@ -110,7 +112,7 @@ const options = Object.assign({}, props, store.$state, props) // if there are preloaded elements we overwrite the current elements with the stored ones if (store.elements.length) elements.value = store.elements -const init = (state: FlowState) => { +const init = async (state: FlowState) => { for (const opt of Object.keys(state)) { const val = state[opt as keyof FlowState] if (typeof val !== 'undefined') { @@ -119,7 +121,7 @@ const init = (state: FlowState) => { } else (store as any)[opt] = val } } - store.setElements(elements.value) + await store.setElements(elements.value) store.setMinZoom(state.minZoom) store.setMaxZoom(state.maxZoom) store.setTranslateExtent(state.translateExtent) @@ -145,7 +147,24 @@ watch( }, { flush: 'post', deep: true }, ) -init(options) +const { zoomIn, zoomOut, zoomTo, transform: setTransform, fitView } = useZoomPanHelper(store) + +invoke(async () => { + await init(options) + const instance: FlowInstance = { + fitView: (params = { padding: 0.1 }) => fitView(params), + zoomIn, + zoomOut, + zoomTo, + setTransform, + project: onLoadProject(store), + getElements: onLoadGetElements(store), + toObject: onLoadToObject(store), + } + store.hooks.load.trigger(instance) + store.isReady = true + store.instance = instance +})