Skip to content

Commit

Permalink
feat(contextmenu): accessor for contextmenu
Browse files Browse the repository at this point in the history
review className and accessor for contextMenu

#16 #41
  • Loading branch information
bubkoo committed Dec 19, 2019
1 parent eea4f5b commit 8460572
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/x6/src/core/view.ts
Expand Up @@ -1906,7 +1906,7 @@ export class View extends Primer<View.EventArgs> {
// events in Firefox and Chrome
graph.addMouseListener({
mouseDown() {
graph.contextMenuHandler.hideMenu()
graph.hideContextMenu()
},
mouseMove() {},
mouseUp() {},
Expand Down
30 changes: 30 additions & 0 deletions packages/x6/src/graph/contextmenu-accessor.ts
@@ -0,0 +1,30 @@
import { BaseGraph } from './base-graph'

export class ContextMenuAccessor extends BaseGraph {
hideContextMenu() {
this.contextMenuHandler.hide()
return this
}

isContextMenuEnabled() {
return this.contextMenuHandler.isEnabled()
}

enableContextMenu() {
if (!this.isContextMenuEnabled()) {
this.contextMenuHandler.enable()
}
return this
}

disableContextMenu() {
if (this.isContextMenuEnabled()) {
this.contextMenuHandler.disable()
}
return this
}

isContextMenuActive() {
return this.contextMenuHandler.isShowing()
}
}
5 changes: 4 additions & 1 deletion packages/x6/src/graph/graph.ts
Expand Up @@ -13,6 +13,7 @@ import { RetrievalAccessor } from './retrieval-accessor'
import { OverlayAccessor } from './overlay-accessor'
import { ConnectionAccessor } from './connection-accessor'
import { TooltipAccessor } from './tooltip-accessor'
import { ContextMenuAccessor } from './contextmenu-accessor'
import { RubberbandAccessor } from './rubberband-accessor'
import { CollapseAccessor } from './collapse-accessor'
import { KeyboardAccessor } from './keyboard-accessor'
Expand Down Expand Up @@ -116,7 +117,8 @@ export interface Graph
ConnectionAccessor,
ValidationAccessor,
MouseWheelAccessor,
RubberbandAccessor {}
RubberbandAccessor,
ContextMenuAccessor {}

util.applyMixins(
Graph,
Expand Down Expand Up @@ -146,4 +148,5 @@ util.applyMixins(
ValidationAccessor,
RubberbandAccessor,
MouseWheelAccessor,
ContextMenuAccessor,
)
24 changes: 17 additions & 7 deletions packages/x6/src/handler/contextmenu/handler.ts
Expand Up @@ -2,7 +2,7 @@ import * as util from '../../util'
import { Graph } from '../../graph'
import { MouseHandler } from '../handler-mouse'
import { MouseEventEx, DomEvent, Disposable } from '../../common'
import { ContextMenuOptions, ShowContextMenuArgs } from './option'
import { ShowContextMenuArgs } from './option'

export class ContextMenuHandler extends MouseHandler {
/**
Expand Down Expand Up @@ -46,7 +46,7 @@ export class ContextMenuHandler extends MouseHandler {
}

protected config() {
const options = this.graph.options.contextMenu as ContextMenuOptions
const options = this.graph.options.contextMenu

this.isLeftButton = options.isLeftButton
this.selectOnPopup = options.selectCellsOnContextMenu
Expand All @@ -57,7 +57,17 @@ export class ContextMenuHandler extends MouseHandler {
this.setEnadled(options.enabled)
}

isPopupTrigger(e: MouseEventEx) {
enable() {
this.graph.options.contextMenu.enabled = true
super.enable()
}

disable() {
this.graph.options.contextMenu.enabled = false
super.disable()
}

isValidTrigger(e: MouseEventEx) {
return (
e.isPopupTrigger() ||
(this.isLeftButton && DomEvent.isLeftMouseButton(e.getEvent()))
Expand All @@ -68,12 +78,12 @@ export class ContextMenuHandler extends MouseHandler {
const evt = e.getEvent()
if (this.isEnabled() && !DomEvent.isMultiTouchEvent(evt)) {
const me = DomEvent.getMainEvent(evt) as MouseEvent
this.triggerX = e.getGraphX()
this.triggerY = e.getGraphY()
this.startX = me.screenX
this.startY = me.screenY
this.validTrigger = this.isPopupTrigger(e)
this.triggerX = e.getGraphX()
this.triggerY = e.getGraphY()
this.inTolerance = true
this.validTrigger = this.isValidTrigger(e)
}
}

Expand Down Expand Up @@ -125,7 +135,7 @@ export class ContextMenuHandler extends MouseHandler {
this.inTolerance = false
}

hideMenu() {
hide() {
this.showing = false
this.doHide && this.doHide()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/handler/tooltip/handler.ts
Expand Up @@ -106,7 +106,7 @@ export class TooltipHandler extends MouseHandler {
!this.disposed &&
!this.isMouseDown() &&
!this.graph.isEditing() &&
!this.graph.contextMenuHandler.isShowing()
!this.graph.isContextMenuActive()
)
}

Expand Down

0 comments on commit 8460572

Please sign in to comment.