fix: zoom pan helper not being initialized timely

This commit is contained in:
Braks
2021-10-21 13:46:15 +02:00
parent c062601874
commit ca2901bc01
7 changed files with 51 additions and 47 deletions
@@ -14,10 +14,6 @@ export interface ControlProps extends HTMLAttributes {
showFitView?: boolean
showInteractive?: boolean
fitViewParams?: FitViewParams
onZoomIn?: () => void
onZoomOut?: () => void
onFitView?: () => void
onInteractiveChange?: (interactiveStatus: boolean) => void
}
const props = withDefaults(defineProps<ControlProps>(), {
@@ -25,6 +21,8 @@ const props = withDefaults(defineProps<ControlProps>(), {
showFitView: true,
showInteractive: true,
})
// todo define types for events
const emit = defineEmits(['zoom-in', 'zoom-out', 'fit-view', 'interaction-change'])
const store = useStore()
const { zoomIn, zoomOut, fitView } = useZoomPanHelper()
@@ -34,22 +32,22 @@ const mapClasses = ['vue-flow__controls']
const onZoomInHandler = () => {
zoomIn?.()
props.onZoomIn?.()
emit('zoom-in')
}
const onZoomOutHandler = () => {
zoomOut?.()
props.onZoomOut?.()
emit('zoom-out')
}
const onFitViewHandler = () => {
fitView?.(props.fitViewParams)
props.onFitView?.()
emit('fit-view')
}
const onInteractiveChangeHandler = () => {
store.setInteractive?.(!isInteractive.value)
props.onInteractiveChange?.(!isInteractive.value)
emit('interaction-change', !isInteractive.value)
}
</script>
<template>