Skip to content

Commit

Permalink
optional context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed Mar 1, 2018
1 parent b968962 commit 4409e5c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected] format');
Expand Down
4 changes: 2 additions & 2 deletions src/editorview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 4409e5c

Please sign in to comment.