-
-
Notifications
You must be signed in to change notification settings - Fork 209
/
Controls.vue
101 lines (91 loc) 路 2.85 KB
/
Controls.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<script lang="ts" setup>
import { Panel, useVueFlow } from '@vue-flow/core'
import type { PanelPosition } from '@vue-flow/core'
import type { ControlProps } from './types'
import ControlButton from './ControlButton.vue'
import PlusIcon from './icons/plus.svg'
import MinusIcon from './icons/minus.svg'
import FitView from './icons/fitview.svg'
import Lock from './icons/lock.svg'
import Unlock from './icons/unlock.svg'
const {
showZoom = true,
showFitView = true,
showInteractive = true,
fitViewParams,
position = 'bottom-left' as PanelPosition,
} = defineProps<ControlProps>()
const emit = defineEmits<{
(event: 'zoomIn'): void
(event: 'zoomOut'): void
(event: 'fitView'): void
(event: 'interactionChange', active: boolean): void
}>()
const { nodesDraggable, nodesConnectable, elementsSelectable, setInteractive, zoomIn, zoomOut, fitView } = $(useVueFlow())
const isInteractive = computed(() => nodesDraggable && nodesConnectable && elementsSelectable)
const onZoomInHandler = () => {
zoomIn()
emit('zoomIn')
}
const onZoomOutHandler = () => {
zoomOut()
emit('zoomOut')
}
const onFitViewHandler = () => {
fitView(fitViewParams)
emit('fitView')
}
const onInteractiveChangeHandler = () => {
setInteractive(!isInteractive.value)
emit('interactionChange', !isInteractive.value)
}
</script>
<script lang="ts">
export default {
name: 'Controls',
compatConfig: { MODE: 3 },
}
</script>
<template>
<Panel class="vue-flow__controls" :position="position">
<slot name="top"></slot>
<template v-if="showZoom">
<slot name="control-zoom-in">
<ControlButton class="vue-flow__controls-zoomin" @click="onZoomInHandler">
<slot name="icon-zoom-in">
<component :is="PlusIcon" />
</slot>
</ControlButton>
</slot>
<slot name="control-zoom-out">
<ControlButton class="vue-flow__controls-zoomout" @click="onZoomOutHandler">
<slot name="icon-zoom-out">
<component :is="MinusIcon" />
</slot>
</ControlButton>
</slot>
</template>
<template v-if="showFitView">
<slot name="control-fit-view">
<ControlButton class="vue-flow__controls-fitview" @click="onFitViewHandler">
<slot name="icon-fit-view">
<component :is="FitView" />
</slot>
</ControlButton>
</slot>
</template>
<template v-if="showInteractive">
<slot name="control-interactive">
<ControlButton v-if="showInteractive" class="vue-flow__controls-interactive" @click="onInteractiveChangeHandler">
<slot v-if="isInteractive" name="icon-unlock">
<component :is="Unlock" />
</slot>
<slot v-if="!isInteractive" name="icon-lock">
<component :is="Lock" />
</slot>
</ControlButton>
</slot>
</template>
<slot></slot>
</Panel>
</template>