Skip to content

Commit b67ca45

Browse files
committed
disable context menu.
1 parent 70cea02 commit b67ca45

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

src/toolbox/toolbox-item-view.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Dom } from '../core/dom';
2-
import { readMousePosition } from '../core/event-readers';
3-
import { Vector } from '../core/vector';
42
import { StepDefinition, StepsConfiguration } from '../designer-configuration';
53

64
export class ToolboxItemView {
@@ -39,18 +37,15 @@ export class ToolboxItemView {
3937

4038
private constructor(private readonly root: HTMLElement) {}
4139

42-
public bindMousedown(handler: (position: Vector) => void) {
43-
this.root.addEventListener(
44-
'mousedown',
45-
e => {
46-
e.stopPropagation();
47-
handler(readMousePosition(e));
48-
},
49-
false
50-
);
40+
public bindMousedown(handler: (e: MouseEvent) => void) {
41+
this.root.addEventListener('mousedown', handler, false);
5142
}
5243

5344
public bindTouchstart(handler: (e: TouchEvent) => void) {
5445
this.root.addEventListener('touchstart', handler, false);
5546
}
47+
48+
public bindContextMenu(handler: (e: MouseEvent) => void) {
49+
this.root.addEventListener('contextmenu', handler, false);
50+
}
5651
}

src/toolbox/toolbox-item.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DragStepBehavior } from '../behaviors/drag-step-behavior';
2-
import { readTouchPosition } from '../core/event-readers';
2+
import { readMousePosition, readTouchPosition } from '../core/event-readers';
33
import { ObjectCloner } from '../core/object-cloner';
44
import { Uid } from '../core/uid';
55
import { Vector } from '../core/vector';
@@ -14,6 +14,7 @@ export class ToolboxItem {
1414
const item = new ToolboxItem(step, context);
1515
view.bindMousedown(e => item.onMousedown(e));
1616
view.bindTouchstart(e => item.onTouchstart(e));
17+
view.bindContextMenu(e => item.onContextMenu(e));
1718
return item;
1819
}
1920

@@ -26,8 +27,16 @@ export class ToolboxItem {
2627
}
2728
}
2829

29-
private onMousedown(position: Vector) {
30-
this.startDrag(position);
30+
private onMousedown(e: MouseEvent) {
31+
e.stopPropagation();
32+
const isPrimaryButton = e.button === 0;
33+
if (isPrimaryButton) {
34+
this.startDrag(readMousePosition(e));
35+
}
36+
}
37+
38+
private onContextMenu(e: MouseEvent) {
39+
e.preventDefault();
3140
}
3241

3342
private startDrag(position: Vector) {

src/workspace/workspace-view.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export class WorkspaceView {
103103
this.canvas.addEventListener('touchstart', e => handler(readTouchPosition(e)), false);
104104
}
105105

106+
public bindContextMenu(handler: (e: MouseEvent) => void) {
107+
this.canvas.addEventListener('contextmenu', handler, false);
108+
}
109+
106110
public bindWheel(handler: (e: WheelEvent) => void) {
107111
this.canvas.addEventListener('wheel', handler, false);
108112
}

src/workspace/workspace.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class Workspace implements DesignerComponentProvider {
3737

3838
view.bindMouseDown((p, t, b) => workspace.onMouseDown(p, t, b));
3939
view.bindTouchStart(e => workspace.onTouchStart(e));
40+
view.bindContextMenu(e => workspace.onContextMenu(e));
4041
view.bindWheel(e => workspace.onWheel(e));
4142
return workspace;
4243
}
@@ -105,8 +106,11 @@ export class Workspace implements DesignerComponentProvider {
105106
}
106107

107108
private onMouseDown(position: Vector, target: Element, button: number) {
109+
const isPrimaryButton = button === 0;
108110
const isMiddleButton = button === 1;
109-
this.startBehavior(target, position, isMiddleButton);
111+
if (isPrimaryButton || isMiddleButton) {
112+
this.startBehavior(target, position, isMiddleButton);
113+
}
110114
}
111115

112116
private onTouchStart(position: Vector) {
@@ -116,6 +120,10 @@ export class Workspace implements DesignerComponentProvider {
116120
}
117121
}
118122

123+
private onContextMenu(e: MouseEvent) {
124+
e.preventDefault();
125+
}
126+
119127
private startBehavior(target: Element, position: Vector, forceMoveMode: boolean) {
120128
const clickedStep =
121129
!forceMoveMode && !this.context.isMoveModeEnabled ? this.getRootComponent().findByElement(target as Element) : null;

0 commit comments

Comments
 (0)