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 <78412429+bcakmakoglu@users.noreply.github.com> * chore(changeset): add Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * fix(core): allow drag regardless of btn chosen Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * fix(core): prevent browser ctx menu on pane right click Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(core): cleanup useKeyPress handler Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * fix(core): check `panOnDrag` prop for allowed drag buttons Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(changeset): add Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(core): cleanup Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --------- Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@vue-flow/core": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Allow Control key as pan activation key code.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@vue-flow/core": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Check `panOnDrag` for allowed drag buttons in d3 filter
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@vue-flow/core": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Prevent browser context menu when triggering pane context menu event.
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { MaybeRefOrGetter } from 'vue'
|
import type { MaybeRefOrGetter } from 'vue'
|
||||||
import { onMounted, ref, toRef, toValue, watch } from 'vue'
|
import { ref, toRef, toValue, watch } from 'vue'
|
||||||
import type { KeyFilter, KeyPredicate } from '@vueuse/core'
|
import type { KeyFilter, KeyPredicate } from '@vueuse/core'
|
||||||
import { onKeyStroke, useEventListener } from '@vueuse/core'
|
import { onKeyStroke, useEventListener } from '@vueuse/core'
|
||||||
|
|
||||||
@@ -111,9 +111,7 @@ export function useKeyPress(keyFilter: MaybeRefOrGetter<KeyFilter | boolean | nu
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
onMounted(() => {
|
useEventListener(['blur', 'contextmenu'], reset)
|
||||||
useEventListener(window, ['blur', 'contextmenu'], reset)
|
|
||||||
})
|
|
||||||
|
|
||||||
onKeyStroke(
|
onKeyStroke(
|
||||||
(...args) => currentFilter(...args),
|
(...args) => currentFilter(...args),
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ const {
|
|||||||
emits,
|
emits,
|
||||||
userSelectionActive,
|
userSelectionActive,
|
||||||
removeSelectedElements,
|
removeSelectedElements,
|
||||||
panOnDrag,
|
|
||||||
userSelectionRect,
|
userSelectionRect,
|
||||||
elementsSelectable,
|
elementsSelectable,
|
||||||
nodesSelectionActive,
|
nodesSelectionActive,
|
||||||
@@ -101,10 +100,8 @@ function onClick(event: MouseEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onContextMenu(event: MouseEvent) {
|
function onContextMenu(event: MouseEvent) {
|
||||||
if (Array.isArray(panOnDrag.value) && panOnDrag.value?.includes(2)) {
|
event.preventDefault()
|
||||||
event.preventDefault()
|
event.stopPropagation()
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
emits.paneContextMenu(event)
|
emits.paneContextMenu(event)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,10 +165,9 @@ onMounted(() => {
|
|||||||
const eventButton = (event as MouseEvent).button
|
const eventButton = (event as MouseEvent).button
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(shouldPanOnDrag.value === true || (Array.isArray(shouldPanOnDrag.value) && shouldPanOnDrag.value.includes(1))) &&
|
|
||||||
eventButton === 1 &&
|
eventButton === 1 &&
|
||||||
event.type === 'mousedown' &&
|
event.type === 'mousedown' &&
|
||||||
((event.target as HTMLElement)?.closest('.vue-flow__node') || (event.target as HTMLElement)?.closest('.vue-flow__edge'))
|
(isWrappedWithClass(event, 'vue-flow__node') || isWrappedWithClass(event, 'vue-flow__edge'))
|
||||||
) {
|
) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -228,8 +227,8 @@ onMounted(() => {
|
|||||||
|
|
||||||
// if the pane is only movable using allowed clicks
|
// if the pane is only movable using allowed clicks
|
||||||
if (
|
if (
|
||||||
Array.isArray(shouldPanOnDrag.value) &&
|
Array.isArray(panOnDrag.value) &&
|
||||||
!shouldPanOnDrag.value.includes(eventButton) &&
|
!panOnDrag.value.includes(eventButton) &&
|
||||||
(event.type === 'mousedown' || event.type === 'touchstart')
|
(event.type === 'mousedown' || event.type === 'touchstart')
|
||||||
) {
|
) {
|
||||||
return false
|
return false
|
||||||
@@ -237,13 +236,13 @@ onMounted(() => {
|
|||||||
|
|
||||||
// We only allow right clicks if pan on drag is set to right-click
|
// We only allow right clicks if pan on drag is set to right-click
|
||||||
const buttonAllowed =
|
const buttonAllowed =
|
||||||
(Array.isArray(shouldPanOnDrag.value) && shouldPanOnDrag.value.includes(eventButton)) ||
|
(Array.isArray(panOnDrag.value) && panOnDrag.value.includes(eventButton)) ||
|
||||||
(selectionKeyCode.value === true && Array.isArray(shouldPanOnDrag.value) && !shouldPanOnDrag.value.includes(0)) ||
|
(selectionKeyCode.value === true && Array.isArray(panOnDrag.value) && !panOnDrag.value.includes(0)) ||
|
||||||
!eventButton ||
|
!eventButton ||
|
||||||
eventButton <= 1
|
eventButton <= 1
|
||||||
|
|
||||||
// default filter for d3-zoom
|
// default filter for d3-zoom
|
||||||
return (!event.ctrlKey || event.type === 'wheel') && buttonAllowed
|
return (!event.ctrlKey || panKeyPressed.value || event.type === 'wheel') && buttonAllowed
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
@@ -293,7 +292,7 @@ onMounted(() => {
|
|||||||
const _isMacOs = isMacOs()
|
const _isMacOs = isMacOs()
|
||||||
|
|
||||||
// macOS sets ctrlKey=true for pinch gesture on a trackpad
|
// macOS sets ctrlKey=true for pinch gesture on a trackpad
|
||||||
if (event.ctrlKey && zoomOnPinch.value && _isMacOs) {
|
if (!panKeyPressed.value && event.ctrlKey && zoomOnPinch.value && _isMacOs) {
|
||||||
const point = pointer(event)
|
const point = pointer(event)
|
||||||
const pinchDelta = wheelDelta(event)
|
const pinchDelta = wheelDelta(event)
|
||||||
const zoom = currentZoom * 2 ** pinchDelta
|
const zoom = currentZoom * 2 ** pinchDelta
|
||||||
|
|||||||
Reference in New Issue
Block a user