fix: move slots outside of zoom pane

* avoids zoom gesture events bubbling to zoom pane and causing elements over flow to trigger zoom when they shouldn't

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-18 03:06:21 +01:00
parent 091ed3eeb4
commit 812a7da2fe
4 changed files with 18 additions and 8 deletions
@@ -31,22 +31,22 @@ const isInteractive = computed(() => store.nodesDraggable && store.nodesConnecta
const mapClasses = ['vue-flow__controls'] const mapClasses = ['vue-flow__controls']
const onZoomInHandler = () => { const onZoomInHandler = () => {
zoomIn?.() zoomIn()
emit('zoom-in') emit('zoom-in')
} }
const onZoomOutHandler = () => { const onZoomOutHandler = () => {
zoomOut?.() zoomOut()
emit('zoom-out') emit('zoom-out')
} }
const onFitViewHandler = () => { const onFitViewHandler = () => {
fitView?.(props.fitViewParams) fitView(props.fitViewParams)
emit('fit-view') emit('fit-view')
} }
const onInteractiveChangeHandler = () => { const onInteractiveChangeHandler = () => {
store.setInteractive?.(!isInteractive.value) store.setInteractive(!isInteractive.value)
emit('interaction-change', !isInteractive.value) emit('interaction-change', !isInteractive.value)
} }
</script> </script>
+10 -3
View File
@@ -51,10 +51,17 @@ onMounted(() => {
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)
</script>
<script lang="ts">
export default {
inheritAttrs: false,
}
</script> </script>
<template> <template>
<slot></slot> <slot></slot>
<UserSelection v-if="selectionKeyPresed && (store.selectionActive || store.elementsSelectable)" id="user-selection" /> <UserSelection v-if="userSelection" id="user-selection" />
<NodesSelection v-if="store.nodesSelectionActive" id="nodes-selection" /> <NodesSelection v-if="nodesSelectionActive" id="nodes-selection" />
<div class="vue-flow__pane" @click.self="onClick" @contextmenu="onContextMenu" @wheel="onWheel" /> <div class="vue-flow__pane" @click="onClick" @contextmenu="onContextMenu" @wheel="onWheel" />
</template> </template>
+1 -1
View File
@@ -186,8 +186,8 @@ const edgeTypes = computed(() => {
</template> </template>
</EdgeRenderer> </EdgeRenderer>
</SelectionPane> </SelectionPane>
<slot v-bind="{ ...props, store, hooks }"></slot>
</ZoomPane> </ZoomPane>
<slot v-bind="{ ...props, store, hooks }"></slot>
</div> </div>
</template> </template>
<style> <style>
+3
View File
@@ -142,6 +142,9 @@ invoke(async () => {
const keyPress = useKeyPress(props.selectionKeyCode) const keyPress = useKeyPress(props.selectionKeyCode)
d3z.filter((event: MouseEvent) => { d3z.filter((event: MouseEvent) => {
event.stopPropagation()
event.stopImmediatePropagation()
event.preventDefault()
const pinchZoom = props.zoomOnPinch && event.ctrlKey const pinchZoom = props.zoomOnPinch && event.ctrlKey
// if all interactions are disabled, we prevent all zoom events // if all interactions are disabled, we prevent all zoom events