refactor: ♻️ add options for preventDefault
in event handlers
This commit is contained in:
@ -132,6 +132,10 @@ export namespace Options {
|
||||
*/
|
||||
preventDefaultContextMenu: boolean
|
||||
|
||||
preventDefaultDblClick: boolean
|
||||
|
||||
preventDefaultMouseDown: boolean
|
||||
|
||||
/**
|
||||
* Prevents default action when an empty graph area is clicked.
|
||||
* Setting the option to `false` will make the graph pannable
|
||||
@ -753,6 +757,8 @@ export namespace Options {
|
||||
moveThreshold: 0,
|
||||
clickThreshold: 0,
|
||||
magnetThreshold: 0,
|
||||
preventDefaultDblClick: true,
|
||||
preventDefaultMouseDown: false,
|
||||
preventDefaultContextMenu: true,
|
||||
preventDefaultBlankAction: true,
|
||||
interacting: {
|
||||
|
@ -93,7 +93,10 @@ export class GraphView extends View {
|
||||
}
|
||||
|
||||
protected onDblClick(evt: JQuery.DoubleClickEvent) {
|
||||
evt.preventDefault()
|
||||
if (this.options.preventDefaultDblClick) {
|
||||
evt.preventDefault()
|
||||
}
|
||||
|
||||
const e = this.normalizeEvent(evt)
|
||||
const view = this.findView(e.target)
|
||||
|
||||
@ -188,10 +191,13 @@ export class GraphView extends View {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.options.preventDefaultMouseDown) {
|
||||
e.preventDefault()
|
||||
}
|
||||
|
||||
const localPoint = this.graph.snapToGrid(e.clientX, e.clientY)
|
||||
|
||||
if (view) {
|
||||
e.preventDefault()
|
||||
view.onMouseDown(e, localPoint.x, localPoint.y)
|
||||
} else {
|
||||
if (this.options.preventDefaultBlankAction) {
|
||||
|
Reference in New Issue
Block a user