Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add paneClickDistance #1542

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/four-deers-judge.md
Original file line number Diff line number Diff line change
@@ -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`)
6 changes: 5 additions & 1 deletion packages/core/src/container/Viewport/Viewport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const {
d3ZoomHandler: storeD3ZoomHandler,
viewport,
viewportRef,
paneClickDistance,
} = useVueFlow()

useResizeHandler(viewportRef)
Expand Down Expand Up @@ -81,7 +82,10 @@ onMounted(() => {

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 d3ZoomHandler = d3Selection.on('wheel.zoom')

Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
updateNodeInternals()
}

const setPaneClickDistance: Actions['setPaneClickDistance'] = (clickDistance) => {
state.d3Zoom?.clickDistance(clickDistance)
}

const setInteractive: Actions['setInteractive'] = (isInteractive) => {
state.nodesDraggable = isInteractive
state.nodesConnectable = isInteractive
Expand Down Expand Up @@ -863,6 +867,7 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
setMaxZoom,
setTranslateExtent,
setNodeExtent,
setPaneClickDistance,
removeSelectedElements,
removeSelectedNodes,
removeSelectedEdges,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/store/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function useState(): State {
panOnScroll: false,
panOnScrollSpeed: 0.5,
panOnScrollMode: PanOnScrollMode.Free,
paneClickDistance: 0,
panOnDrag: true,
edgeUpdaterRadius: 10,
onlyRenderVisibleElements: false,
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/types/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ export interface FlowProps {
panOnScroll?: boolean
panOnScrollSpeed?: number
panOnScrollMode?: PanOnScrollMode
/**
* Distance that the mouse can move between mousedown/up that will trigger a click
* @default 0
*/
paneClickDistance?: number
zoomOnDoubleClick?: boolean
/** If set to false, scrolling inside the viewport will be disabled and instead the page scroll will be used */
preventScrolling?: boolean
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/types/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export interface State extends Omit<FlowProps, 'id' | 'modelValue'> {
panOnScroll: boolean
panOnScrollSpeed: number
panOnScrollMode: PanOnScrollMode
paneClickDistance: number
zoomOnDoubleClick: boolean
preventScrolling: boolean
paneDragging: boolean
Expand Down Expand Up @@ -285,6 +286,7 @@ export interface Actions extends Omit<ViewportHelper, 'viewportInitialized'> {
setTranslateExtent: (translateExtent: CoordinateExtent) => void
/** apply extent to nodes */
setNodeExtent: (nodeExtent: CoordinateExtent | CoordinateExtentRange) => void
setPaneClickDistance: (distance: number) => void
/** enable/disable node interaction (dragging, selecting etc) */
setInteractive: (isInteractive: boolean) => void
/** set new state */
Expand Down
Loading