Skip to content

Commit

Permalink
feat(panning): add a new eventType 'mouseWheelDown'
Browse files Browse the repository at this point in the history
  • Loading branch information
aMoonkin committed Oct 11, 2023
1 parent 443210c commit 9664d9a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/x6/src/graph/panning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export class PanningManager extends Base {
this.onRightMouseDown = this.onRightMouseDown.bind(this)
Dom.Event.on(this.graph.container, 'mousedown', this.onRightMouseDown)
}

if (eventTypes.includes('mouseWheelDown')) {
this.onMouseWheelDown = this.onMouseWheelDown.bind(this)
Dom.Event.on(this.graph.container, 'mousedown', this.onMouseWheelDown)
}

if (eventTypes.includes('mouseWheel')) {
this.mousewheelHandle = new Dom.MouseWheelHandle(
this.graph.container,
Expand All @@ -57,6 +63,9 @@ export class PanningManager extends Base {
if (eventTypes.includes('rightMouseDown')) {
Dom.Event.off(this.graph.container, 'mousedown', this.onRightMouseDown)
}
if (eventTypes.includes('mouseWheelDown')) {
Dom.Event.off(this.graph.container, 'mousedown', this.onMouseWheelDown)
}
if (eventTypes.includes('mouseWheel')) {
if (this.mousewheelHandle) {
this.mousewheelHandle.disable()
Expand Down Expand Up @@ -137,6 +146,12 @@ export class PanningManager extends Base {
}
}

protected onMouseWheelDown(e: Dom.MouseDownEvent) {
if (e.button === 1 && this.allowPanning(e, true)) {
this.startPanning(e)
}
}

protected allowMouseWheel(e: WheelEvent) {
return this.pannable && !e.ctrlKey
}
Expand Down Expand Up @@ -195,7 +210,11 @@ export class PanningManager extends Base {
}

export namespace PanningManager {
type EventType = 'leftMouseDown' | 'rightMouseDown' | 'mouseWheel'
type EventType =
| 'leftMouseDown'
| 'rightMouseDown'
| 'mouseWheel'
| 'mouseWheelDown'
export interface Options {
enabled?: boolean
modifiers?: string | ModifierKey[] | null
Expand Down

0 comments on commit 9664d9a

Please sign in to comment.