Skip to content

Commit 08d57fa

Browse files
authored
revert(core): block pane ctx menu if panOnDrag includes [2] (right-click) (#2001)
* revert(core): block pane ctx menu if panOnDrag includes [2] (right-click) Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(changeset): add --------- Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
1 parent 1c9732a commit 08d57fa

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

.changeset/young-moles-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": patch
3+
---
4+
5+
Block pane ctx-menu from triggering if panOnDrag includes btn 2 (right-click) and let viewport emit pane ctx menu.

examples/vite/src/Basic/Basic.vue

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts" setup>
2-
import type { Edge, Node, ValidConnectionFunc } from '@vue-flow/core'
3-
import { ConnectionMode, Panel, VueFlow, isNode, useVueFlow } from '@vue-flow/core'
2+
import type { Edge, Node } from '@vue-flow/core'
3+
import { Panel, VueFlow, isNode, useVueFlow } from '@vue-flow/core'
44
55
import { Background } from '@vue-flow/background'
66
import { Controls } from '@vue-flow/controls'
@@ -45,22 +45,10 @@ function resetViewport() {
4545
function toggleclass() {
4646
return nodes.value.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light'))
4747
}
48-
49-
const isValidConnection: ValidConnectionFunc = (...args) => {
50-
console.log(args)
51-
return true
52-
}
5348
</script>
5449

5550
<template>
56-
<VueFlow
57-
:nodes="nodes"
58-
:edges="edges"
59-
:connection-mode="ConnectionMode.Strict"
60-
:is-valid-connection="isValidConnection"
61-
fit-view-on-init
62-
class="vue-flow-basic-example"
63-
>
51+
<VueFlow :nodes="nodes" :edges="edges" class="vue-flow-basic-example" fit-view-on-init>
6452
<Background />
6553
<MiniMap />
6654
<Controls />

packages/core/src/container/Pane/Pane.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts" setup>
2-
import { ref, toRef, watch } from 'vue'
2+
import { shallowRef, toRef, watch } from 'vue'
33
import UserSelection from '../../components/UserSelection/UserSelection.vue'
44
import NodesSelection from '../../components/NodesSelection/NodesSelection.vue'
55
import type { EdgeChange, NodeChange } from '../../types'
@@ -33,15 +33,16 @@ const {
3333
connectionLookup,
3434
defaultEdgeOptions,
3535
connectionStartHandle,
36+
panOnDrag,
3637
} = useVueFlow()
3738
38-
const container = ref<HTMLDivElement | null>(null)
39+
const container = shallowRef<HTMLDivElement | null>(null)
3940
40-
const selectedNodeIds = ref<Set<string>>(new Set())
41+
const selectedNodeIds = shallowRef<Set<string>>(new Set())
4142
42-
const selectedEdgeIds = ref<Set<string>>(new Set())
43+
const selectedEdgeIds = shallowRef<Set<string>>(new Set())
4344
44-
const containerBounds = ref<DOMRect>()
45+
const containerBounds = shallowRef<DOMRect | null>(null)
4546
4647
const hasActiveSelection = toRef(() => elementsSelectable.value && (isSelecting || userSelectionActive.value))
4748
@@ -95,8 +96,10 @@ function onClick(event: MouseEvent) {
9596
}
9697
9798
function onContextMenu(event: MouseEvent) {
98-
event.preventDefault()
99-
event.stopPropagation()
99+
if (Array.isArray(panOnDrag.value) && panOnDrag.value?.includes(2)) {
100+
event.preventDefault()
101+
return
102+
}
100103
101104
emits.paneContextMenu(event)
102105
}
@@ -106,7 +109,7 @@ function onWheel(event: WheelEvent) {
106109
}
107110
108111
function onPointerDown(event: PointerEvent) {
109-
containerBounds.value = vueFlowRef.value?.getBoundingClientRect()
112+
containerBounds.value = vueFlowRef.value?.getBoundingClientRect() ?? null
110113
111114
if (
112115
!elementsSelectable.value ||

0 commit comments

Comments
 (0)