diff --git a/src/contextmenu.js b/src/contextmenu.js index c3fefaf1..aac70f03 100644 --- a/src/contextmenu.js +++ b/src/contextmenu.js @@ -3,8 +3,9 @@ import template from './templates/menu.pug'; export class ContextMenu { - constructor(items: Object, searchBar: boolean = true) { + constructor(items: Object, searchBar: boolean = true, disabled = false) { this.visible = false; + this.disabled = disabled; this.x = 0; this.y = 0; this.default = { @@ -58,6 +59,8 @@ export class ContextMenu { } show(x: number, y: number, items: ?Object = null, searchBar: ?boolean = null, onClick = null) { + if (this.disabled) return; + this.visible = true; this.items = items || this.default.items; this.searchBar = searchBar || this.default.searchBar; diff --git a/src/editor.js b/src/editor.js index b512c3e6..5877e478 100644 --- a/src/editor.js +++ b/src/editor.js @@ -13,7 +13,7 @@ import { Utils } from './utils'; export class NodeEditor { - constructor(id: string, container: HTMLElement, components: Component[], menu: ContextMenu) { + constructor(id: string, container: HTMLElement, components: Component[], menu: ?ContextMenu) { if (!Utils.isValidId(id)) throw new Error('ID should be valid to name@0.1.0 format'); diff --git a/src/editorview.js b/src/editorview.js index 885466e4..45ea6ecb 100644 --- a/src/editorview.js +++ b/src/editorview.js @@ -10,14 +10,14 @@ const zoomMargin = 0.9; export class EditorView { - constructor(editor: NodeEditor, container: HTMLElement, menu: ContextMenu) { + constructor(editor: NodeEditor, container: HTMLElement, menu: ?ContextMenu) { this.editor = editor; this.pickedOutput = null; this.container = d3.select(container).attr('tabindex', 1); this.mouse = [0, 0]; this.transform = d3.zoomIdentity; - this.contextMenu = menu; + this.contextMenu = menu || new ContextMenu({}, true, true); this.container .on('click', () => {