feat(core): add paneClickDistance (#1542)

* feat(core): add `paneClickDistance`

* chore(changeset): add
This commit is contained in:
Braks
2024-07-15 19:14:01 +02:00
parent 8539731a8a
commit 180109c0ca
6 changed files with 23 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@vue-flow/core": minor
---
Add `paneClickDistance` option. Allows specifying the distance between mousedown and mouseup in which a click would still be registered (by default `0`)
@@ -39,6 +39,7 @@ const {
d3ZoomHandler: storeD3ZoomHandler, d3ZoomHandler: storeD3ZoomHandler,
viewport, viewport,
viewportRef, viewportRef,
paneClickDistance,
} = useVueFlow() } = useVueFlow()
useResizeHandler(viewportRef) useResizeHandler(viewportRef)
@@ -81,7 +82,10 @@ onMounted(() => {
const bbox = viewportElement.getBoundingClientRect() const bbox = viewportElement.getBoundingClientRect()
const d3Zoom = zoom<HTMLDivElement, any>().scaleExtent([minZoom.value, maxZoom.value]).translateExtent(translateExtent.value) const d3Zoom = zoom<HTMLDivElement, unknown>()
.clickDistance(paneClickDistance.value)
.scaleExtent([minZoom.value, maxZoom.value])
.translateExtent(translateExtent.value)
const d3Selection = select(viewportElement).call(d3Zoom) const d3Selection = select(viewportElement).call(d3Zoom)
const d3ZoomHandler = d3Selection.on('wheel.zoom') const d3ZoomHandler = d3Selection.on('wheel.zoom')
+5
View File
@@ -307,6 +307,10 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
updateNodeInternals() updateNodeInternals()
} }
const setPaneClickDistance: Actions['setPaneClickDistance'] = (clickDistance) => {
state.d3Zoom?.clickDistance(clickDistance)
}
const setInteractive: Actions['setInteractive'] = (isInteractive) => { const setInteractive: Actions['setInteractive'] = (isInteractive) => {
state.nodesDraggable = isInteractive state.nodesDraggable = isInteractive
state.nodesConnectable = isInteractive state.nodesConnectable = isInteractive
@@ -863,6 +867,7 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
setMaxZoom, setMaxZoom,
setTranslateExtent, setTranslateExtent,
setNodeExtent, setNodeExtent,
setPaneClickDistance,
removeSelectedElements, removeSelectedElements,
removeSelectedNodes, removeSelectedNodes,
removeSelectedEdges, removeSelectedEdges,
+1
View File
@@ -47,6 +47,7 @@ export function useState(): State {
panOnScroll: false, panOnScroll: false,
panOnScrollSpeed: 0.5, panOnScrollSpeed: 0.5,
panOnScrollMode: PanOnScrollMode.Free, panOnScrollMode: PanOnScrollMode.Free,
paneClickDistance: 0,
panOnDrag: true, panOnDrag: true,
edgeUpdaterRadius: 10, edgeUpdaterRadius: 10,
onlyRenderVisibleElements: false, onlyRenderVisibleElements: false,
+5
View File
@@ -188,6 +188,11 @@ export interface FlowProps {
panOnScroll?: boolean panOnScroll?: boolean
panOnScrollSpeed?: number panOnScrollSpeed?: number
panOnScrollMode?: PanOnScrollMode panOnScrollMode?: PanOnScrollMode
/**
* Distance that the mouse can move between mousedown/up that will trigger a click
* @default 0
*/
paneClickDistance?: number
zoomOnDoubleClick?: boolean zoomOnDoubleClick?: boolean
/** If set to false, scrolling inside the viewport will be disabled and instead the page scroll will be used */ /** If set to false, scrolling inside the viewport will be disabled and instead the page scroll will be used */
preventScrolling?: boolean preventScrolling?: boolean
+2
View File
@@ -127,6 +127,7 @@ export interface State extends Omit<FlowProps, 'id' | 'modelValue'> {
panOnScroll: boolean panOnScroll: boolean
panOnScrollSpeed: number panOnScrollSpeed: number
panOnScrollMode: PanOnScrollMode panOnScrollMode: PanOnScrollMode
paneClickDistance: number
zoomOnDoubleClick: boolean zoomOnDoubleClick: boolean
preventScrolling: boolean preventScrolling: boolean
paneDragging: boolean paneDragging: boolean
@@ -290,6 +291,7 @@ export interface Actions extends Omit<ViewportHelper, 'viewportInitialized'> {
setTranslateExtent: (translateExtent: CoordinateExtent) => void setTranslateExtent: (translateExtent: CoordinateExtent) => void
/** apply extent to nodes */ /** apply extent to nodes */
setNodeExtent: (nodeExtent: CoordinateExtent | CoordinateExtentRange) => void setNodeExtent: (nodeExtent: CoordinateExtent | CoordinateExtentRange) => void
setPaneClickDistance: (distance: number) => void
/** enable/disable node interaction (dragging, selecting etc) */ /** enable/disable node interaction (dragging, selecting etc) */
setInteractive: (isInteractive: boolean) => void setInteractive: (isInteractive: boolean) => void
/** set new state */ /** set new state */