-.context-menu {
+.eg-context-menu {
+ /* These fonts were applied specifically for the MARC editor
+ * context menus. Might want to make these optional. */
font-family: 'Lucida Console', Monaco, monospace;
+
+ /* put a hard limit on the popover width */
max-width: 550px;
}
-.context-menu .popover-body {
+.eg-context-menu .popover-body {
max-height: 400px;
+
+ /* Text exceeding the max-height / max-width will results in scrolls.
+ * In most cases, this should not happen. */
overflow-y: auto;
overflow-x: auto;
}
-.context-menu .popover-body .menu-entry {
+.eg-context-menu .popover-body .menu-entry {
+ /* force the menu to expand horizontally to display the text */
white-space: nowrap;
}
-.context-menu .popover-body .menu-entry:hover {
+.eg-context-menu .popover-body .menu-entry:hover {
background-color: #f8f9fa;
}
-import {Component, Input, Output, OnInit, EventEmitter, Directive, ViewChild,
- ViewEncapsulation, ComponentFactoryResolver, TemplateRef} from '@angular/core';
+import {Component, Input, Output, AfterViewInit, EventEmitter, Directive, ViewChild,
+ Renderer2, ViewEncapsulation, ComponentFactoryResolver, TemplateRef} from '@angular/core';
import {NgbPopover} from '@ng-bootstrap/ng-bootstrap';
/**
encapsulation: ViewEncapsulation.None
})
-export class ContextMenuComponent implements OnInit {
+export class ContextMenuComponent implements AfterViewInit {
@Input() menuEntries: ContextMenuEntry[] = [];
@Output() entrySelected: EventEmitter<ContextMenuEntry>;
- @ViewChild('menuTemplate', {static: false}) public menuTemplate: TemplateRef<any>;
+ @ViewChild('menuTemplate', {static: false})
+ public menuTemplate: TemplateRef<any>;
- constructor() {
+ randId = Math.floor(Math.random() * 10000000);
+
+ constructor(private renderer: Renderer2) {
this.entrySelected = new EventEmitter<ContextMenuEntry>();
}
- ngOnInit() {}
+ ngAfterViewInit() {
+ }
+
+ grabFocus() {
+ // ARG TODO
+ const link = this.renderer.selectRootElement(`[id='${this.randId}']`);
+ setTimeout(() => {
+ console.log('focusing ', link);
+ link.focus();
+ }, 400);
+ }
entryClicked(entry: ContextMenuEntry) {
+ console.log('emitting ', entry);
this.entrySelected.emit(entry);
}
}
menuComp: ContextMenuComponent;
- triggers = 'contextmenu';
- popoverClass = 'context-menu';
+ triggers = 'contextmenu'; // TODO TODO
+ popoverClass = 'eg-context-menu';
@Input() set egContextMenu(menuComp: ContextMenuComponent) {
this.menuComp = menuComp;
open() {
- // Note the popover will automatically close in most cases,
- // but context menus typically preventDefault() from firing,
- // which prevents right-click from closing existing menus.
+ // The popover will automatically close in most cases, but
+ // context menus preventDefault(), which prevents right-click on
+ // other context menus from firing the close operation. Or at
+ // least, that's my assumption. This fixes it.
if (ContextMenuDirective.activeMenu) {
- ContextMenuDirective.activeMenu.close();
+ ContextMenuDirective.activeMenu.close();
}
if (!this.menuComp.menuEntries ||
this.ngbPopover = this.menuComp.menuTemplate;
ContextMenuDirective.activeMenu = this;
+
super.open();
+
+ // ARG TODO
+ setTimeout(() => this.menuComp.grabFocus());
}
}
editInput: any; // <input/> or <div contenteditable/>
maxLength: number = null;
- contextMenuEntries: ContextMenuEntry[];
-
constructor(
private renderer: Renderer2,
private tagTable: TagTableService) {}
case 'sfc':
this.maxLength = 1;
this.watchForFocusRequests();
- this.contextMenuEntries =
- this.tagTable.getSubfieldCodes(this.field.tag);
break;
case 'sfv':
}
}
+ // These are served dynamically to handle cases where a tag or
+ // subfield is modified in place.
+ contextMenuEntries(): ContextMenuEntry[] {
+ if (!this.field) { return; } // LDR tag
+
+ switch(this.fieldType) {
+ case 'tag': return [];
+
+ case 'sfc':
+ return this.tagTable.getSubfieldCodes(this.field.tag);
+
+ case 'sfv':
+ return this.tagTable.getSubfieldValues(
+ this.field.tag, this.subfield[0]);
+ }
+
+ return null;
+ }
+
getContent(): string {
if (this.fieldText) { return this.fieldText; } // read-only
evt.preventDefault();
}
-
contextMenuChange(value: string) {
this.setContent(value);
}