Skip to content

Commit f4f2494

Browse files
committed
fix(core): allow control key as pan activation key code (#1707)
* fix(core): allow control key as pan activation key code Signed-off-by: braks <[email protected]> * chore(changeset): add Signed-off-by: braks <[email protected]> * fix(core): allow drag regardless of btn chosen Signed-off-by: braks <[email protected]> * fix(core): prevent browser ctx menu on pane right click Signed-off-by: braks <[email protected]> * chore(core): cleanup useKeyPress handler Signed-off-by: braks <[email protected]> * fix(core): check `panOnDrag` prop for allowed drag buttons Signed-off-by: braks <[email protected]> * chore(changeset): add Signed-off-by: braks <[email protected]> * chore(core): cleanup Signed-off-by: braks <[email protected]> --------- Signed-off-by: braks <[email protected]>
1 parent 7a022c8 commit f4f2494

File tree

6 files changed

+26
-17
lines changed

6 files changed

+26
-17
lines changed

.changeset/four-kiwis-judge.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+
Allow Control key as pan activation key code.

.changeset/plenty-timers-change.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+
Check `panOnDrag` for allowed drag buttons in d3 filter

.changeset/serious-trains-guess.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+
Prevent browser context menu when triggering pane context menu event.

packages/core/src/composables/useKeyPress.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MaybeRefOrGetter } from 'vue'
2-
import { onMounted, ref, toRef, toValue, watch } from 'vue'
2+
import { ref, toRef, toValue, watch } from 'vue'
33
import type { KeyFilter, KeyPredicate } from '@vueuse/core'
44
import { onKeyStroke, useEventListener } from '@vueuse/core'
55

@@ -111,9 +111,7 @@ export function useKeyPress(keyFilter: MaybeRefOrGetter<KeyFilter | boolean | nu
111111
},
112112
)
113113

114-
onMounted(() => {
115-
useEventListener(window, ['blur', 'contextmenu'], reset)
116-
})
114+
useEventListener(['blur', 'contextmenu'], reset)
117115

118116
onKeyStroke(
119117
(...args) => currentFilter(...args),

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const {
1717
emits,
1818
userSelectionActive,
1919
removeSelectedElements,
20-
panOnDrag,
2120
userSelectionRect,
2221
elementsSelectable,
2322
nodesSelectionActive,
@@ -101,10 +100,8 @@ function onClick(event: MouseEvent) {
101100
}
102101
103102
function onContextMenu(event: MouseEvent) {
104-
if (Array.isArray(panOnDrag.value) && panOnDrag.value?.includes(2)) {
105-
event.preventDefault()
106-
return
107-
}
103+
event.preventDefault()
104+
event.stopPropagation()
108105
109106
emits.paneContextMenu(event)
110107
}

packages/core/src/container/Viewport/Viewport.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,9 @@ onMounted(() => {
165165
const eventButton = (event as MouseEvent).button
166166
167167
if (
168-
(shouldPanOnDrag.value === true || (Array.isArray(shouldPanOnDrag.value) && shouldPanOnDrag.value.includes(1))) &&
169168
eventButton === 1 &&
170169
event.type === 'mousedown' &&
171-
((event.target as HTMLElement)?.closest('.vue-flow__node') || (event.target as HTMLElement)?.closest('.vue-flow__edge'))
170+
(isWrappedWithClass(event, 'vue-flow__node') || isWrappedWithClass(event, 'vue-flow__edge'))
172171
) {
173172
return true
174173
}
@@ -228,22 +227,22 @@ onMounted(() => {
228227
229228
// if the pane is only movable using allowed clicks
230229
if (
231-
Array.isArray(shouldPanOnDrag.value) &&
232-
!shouldPanOnDrag.value.includes(eventButton) &&
230+
Array.isArray(panOnDrag.value) &&
231+
!panOnDrag.value.includes(eventButton) &&
233232
(event.type === 'mousedown' || event.type === 'touchstart')
234233
) {
235234
return false
236235
}
237236
238237
// We only allow right clicks if pan on drag is set to right-click
239238
const buttonAllowed =
240-
(Array.isArray(shouldPanOnDrag.value) && shouldPanOnDrag.value.includes(eventButton)) ||
241-
(selectionKeyCode.value === true && Array.isArray(shouldPanOnDrag.value) && !shouldPanOnDrag.value.includes(0)) ||
239+
(Array.isArray(panOnDrag.value) && panOnDrag.value.includes(eventButton)) ||
240+
(selectionKeyCode.value === true && Array.isArray(panOnDrag.value) && !panOnDrag.value.includes(0)) ||
242241
!eventButton ||
243242
eventButton <= 1
244243
245244
// default filter for d3-zoom
246-
return (!event.ctrlKey || event.type === 'wheel') && buttonAllowed
245+
return (!event.ctrlKey || panKeyPressed.value || event.type === 'wheel') && buttonAllowed
247246
})
248247
249248
watch(
@@ -293,7 +292,7 @@ onMounted(() => {
293292
const _isMacOs = isMacOs()
294293
295294
// macOS sets ctrlKey=true for pinch gesture on a trackpad
296-
if (event.ctrlKey && zoomOnPinch.value && _isMacOs) {
295+
if (!panKeyPressed.value && event.ctrlKey && zoomOnPinch.value && _isMacOs) {
297296
const point = pointer(event)
298297
const pinchDelta = wheelDelta(event)
299298
const zoom = currentZoom * 2 ** pinchDelta

0 commit comments

Comments
 (0)