import { Component , ViewEncapsulation , OnInit , OnDestroy , HostListener , ViewChild , AfterViewInit , Inject } from '@angular/core' ; import { MatMenuTrigger } from '@angular/material/menu' ; import { Subject } from 'rxjs' ; import { takeUntil } from 'rxjs/operators' ; import { ContentActionRef } from '@alfresco/adf-extensions' ; import { ContextMenuOverlayRef } from './context-menu-overlay' ; import { CONTEXT_MENU_DIRECTION } from './direction.token' ; import { Direction } from '@angular/cdk/bidi' ; import { AppExtensionService } from '@alfresco/aca-shared' ; @ Component ( { selector : 'aca-context-menu' , templateUrl : './context-menu.component.html' , host : { class : 'aca-context-menu-holder' } , encapsulation : ViewEncapsulation . None } ) export class ContextMenuComponent implements OnInit , OnDestroy , AfterViewInit { private onDestroy$ : Subject < boolean > = new Subject < boolean > ( ) ; actions : Array < ContentActionRef > = [ ] ; @ ViewChild ( MatMenuTrigger ) trigger : MatMenuTrigger ; @ HostListener ( 'document:keydown.Escape' , [ '$event' ] ) handleKeydownEscape ( event ) { if ( event ) { if ( this . contextMenuOverlayRef ) { this . contextMenuOverlayRef . close ( ) ; } } } constructor ( private contextMenuOverlayRef , private extensions , @ Inject ( CONTEXT_MENU_DIRECTION ) public direction ) { } onClickOutsideEvent ( ) { if ( this . contextMenuOverlayRef ) { this . contextMenuOverlayRef . close ( ) ; } } runAction ( actionId ) { this . extensions . runActionById ( actionId ) ; } ngOnDestroy ( ) { this . onDestroy$ . next ( true ) ; this . onDestroy$ . complete ( ) ; } ngOnInit ( ) { this . extensions . getAllowedContextMenuActions ( ) . pipe ( takeUntil ( this . onDestroy$ ) ) . subscribe ( ( actions ) => ( this . actions = actions ) ) ; } ngAfterViewInit ( ) { setTimeout ( ( ) => this . trigger . openMenu ( ) , 0 ) ; } trackByActionId ( _ , obj ) { return obj . id ; } }