!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/cdk/overlay"),require("@angular/common"),require("@angular/core"),require("rxjs"),require("rxjs/operators"),require("@angular/cdk/portal"),require("@angular/cdk/a11y")):"function"==typeof define&&define.amd?define("ngx-contextmenu",["exports","@angular/cdk/overlay","@angular/common","@angular/core","rxjs","rxjs/operators","@angular/cdk/portal","@angular/cdk/a11y"],t):t((e=e||self)["ngx-contextmenu"]={},e.ng.cdk.overlay,e.ng.common,e.ng.core,e.rxjs,e.rxjs.operators,e.ng.cdk.portal,e.ng.cdk.a11y)}(this,(function(e,t,n,o,i,s,r,a){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */var u=function(){return(u=Object.assign||function(e){for(var t,n=1,o=arguments.length;n-1||t.isContentEditable||(e.preventDefault(),e.stopPropagation())}},e.decorators=[{type:o.Component,args:[{selector:"context-menu-content",template:'\n \n \n \n \n \n \n\n \n \n \n \n \n \n ',styles:["\n .passive {\n display: block;\n padding: 3px 20px;\n clear: both;\n font-weight: normal;\n line-height: @line-height-base;\n white-space: nowrap;\n }\n .hasSubMenu:before {\n content: '▶';\n float: right;\n }\n "]}]}],e.ctorParameters=function(){return[{type:o.ChangeDetectorRef},{type:o.ElementRef},{type:void 0,decorators:[{type:o.Optional},{type:o.Inject,args:[l]}]}]},e.propDecorators={menuItems:[{type:o.Input}],item:[{type:o.Input}],event:[{type:o.Input}],parentContextMenu:[{type:o.Input}],menuClass:[{type:o.Input}],overlay:[{type:o.Input}],isLeaf:[{type:o.Input}],execute:[{type:o.Output}],openSubMenu:[{type:o.Output}],closeLeafMenu:[{type:o.Output}],closeAllMenus:[{type:o.Output}],menuElement:[{type:o.ViewChild,args:["menu",{static:!0}]}],menuItemElements:[{type:o.ViewChildren,args:["li"]}],onKeyEvent:[{type:o.HostListener,args:["window:keydown.ArrowDown",["$event"]]},{type:o.HostListener,args:["window:keydown.ArrowUp",["$event"]]}],keyboardOpenSubMenu:[{type:o.HostListener,args:["window:keydown.ArrowRight",["$event"]]}],keyboardMenuItemSelect:[{type:o.HostListener,args:["window:keydown.Enter",["$event"]]},{type:o.HostListener,args:["window:keydown.Space",["$event"]]}],onCloseLeafMenu:[{type:o.HostListener,args:["window:keydown.Escape",["$event"]]},{type:o.HostListener,args:["window:keydown.ArrowLeft",["$event"]]}],closeMenu:[{type:o.HostListener,args:["document:click",["$event"]]},{type:o.HostListener,args:["document:contextmenu",["$event"]]}]},e}();var h=function(){function e(e,t){this.overlay=e,this.scrollStrategy=t,this.isDestroyingLeafMenu=!1,this.show=new i.Subject,this.triggerClose=new i.Subject,this.close=new i.Subject,this.overlays=[],this.fakeElement={getBoundingClientRect:function(){return{bottom:0,height:0,left:0,right:0,top:0,width:0}}}}return e.prototype.openContextMenu=function(e){var t=e.anchorElement,n=e.event,i=e.parentContextMenu;if(i){a=this.overlay.position().connectedTo(new o.ElementRef(n?n.target:t),{originX:"end",originY:"top"},{overlayX:"start",overlayY:"top"}).withFallbackPosition({originX:"start",originY:"top"},{overlayX:"end",overlayY:"top"}).withFallbackPosition({originX:"end",originY:"bottom"},{overlayX:"start",overlayY:"bottom"}).withFallbackPosition({originX:"start",originY:"bottom"},{overlayX:"end",overlayY:"bottom"});var s=this.overlay.create({positionStrategy:a,panelClass:"ngx-contextmenu",scrollStrategy:this.scrollStrategy.close()});this.destroySubMenus(i),this.overlays=this.overlays.concat(s),this.attachContextMenu(s,e)}else{var r=n;this.fakeElement.getBoundingClientRect=function(){return{bottom:r.clientY,height:0,left:r.clientX,right:r.clientX,top:r.clientY,width:0}},this.closeAllContextMenus({eventType:"cancel",event:n});var a=this.overlay.position().connectedTo(new o.ElementRef(t||this.fakeElement),{originX:"start",originY:"bottom"},{overlayX:"start",overlayY:"top"}).withFallbackPosition({originX:"start",originY:"top"},{overlayX:"start",overlayY:"bottom"}).withFallbackPosition({originX:"end",originY:"top"},{overlayX:"start",overlayY:"top"}).withFallbackPosition({originX:"start",originY:"top"},{overlayX:"end",overlayY:"top"}).withFallbackPosition({originX:"end",originY:"center"},{overlayX:"start",overlayY:"center"}).withFallbackPosition({originX:"start",originY:"center"},{overlayX:"end",overlayY:"center"});this.overlays=[this.overlay.create({positionStrategy:a,panelClass:"ngx-contextmenu",scrollStrategy:this.scrollStrategy.close()})],this.attachContextMenu(this.overlays[0],e)}},e.prototype.attachContextMenu=function(e,t){var n=this,o=t.event,s=t.item,a=t.menuItems,c=t.menuClass,l=e.attach(new r.ComponentPortal(p));l.instance.event=o,l.instance.item=s,l.instance.menuItems=a,l.instance.overlay=e,l.instance.isLeaf=!0,l.instance.menuClass=c,e.contextMenu=l.instance;var h=new i.Subscription;h.add(l.instance.execute.asObservable().subscribe((function(e){return n.closeAllContextMenus(u({eventType:"execute"},e))}))),h.add(l.instance.closeAllMenus.asObservable().subscribe((function(e){return n.closeAllContextMenus(u({eventType:"cancel"},e))}))),h.add(l.instance.closeLeafMenu.asObservable().subscribe((function(e){return n.destroyLeafMenu(e)}))),h.add(l.instance.openSubMenu.asObservable().subscribe((function(e){n.destroySubMenus(l.instance),e.contextMenu?(l.instance.isLeaf=!1,n.show.next(e)):l.instance.isLeaf=!0}))),l.onDestroy((function(){a.forEach((function(e){return e.isActive=!1})),h.unsubscribe()})),l.changeDetectorRef.detectChanges()},e.prototype.closeAllContextMenus=function(e){this.overlays&&(this.close.next(e),this.overlays.forEach((function(e,t){e.detach(),e.dispose()}))),this.overlays=[]},e.prototype.getLastAttachedOverlay=function(){for(var e=this.overlays[this.overlays.length-1];this.overlays.length>1&&e&&!e.hasAttached();)e.detach(),e.dispose(),this.overlays=this.overlays.slice(0,-1),e=this.overlays[this.overlays.length-1];return e},e.prototype.destroyLeafMenu=function(e){var t=this,n=void 0===e?{}:e,o=n.exceptRootMenu,i=n.event;this.isDestroyingLeafMenu||(this.isDestroyingLeafMenu=!0,setTimeout((function(){var e=t.getLastAttachedOverlay();t.overlays.length>1&&e&&(e.detach(),e.dispose()),!o&&t.overlays.length>0&&e&&(t.close.next({eventType:"cancel",event:i}),e.detach(),e.dispose());var n=t.getLastAttachedOverlay();n&&(n.contextMenu.isLeaf=!0),t.isDestroyingLeafMenu=!1})))},e.prototype.destroySubMenus=function(e){var t=e.overlay,n=this.overlays.indexOf(t);this.overlays.slice(n+1).forEach((function(e){e.detach(),e.dispose()}))},e.prototype.isLeafMenu=function(e){var t=this.getLastAttachedOverlay();return e.overlay===t},e.decorators=[{type:o.Injectable}],e.ctorParameters=function(){return[{type:t.Overlay},{type:t.ScrollStrategyOptions}]},e}();var m=function(){function e(e,t,n,s){var r=this;this._contextMenuService=e,this.changeDetector=t,this.elementRef=n,this.options=s,this.menuClass="",this.autoFocus=!1,this.useBootstrap4=!1,this.disabled=!1,this.close=new o.EventEmitter,this.open=new o.EventEmitter,this.visibleMenuItems=[],this.links=[],this.subscription=new i.Subscription,s&&(this.autoFocus=s.autoFocus,this.useBootstrap4=s.useBootstrap4),this.subscription.add(e.show.subscribe((function(e){r.onMenuEvent(e)})))}return e.prototype.ngOnDestroy=function(){this.subscription.unsubscribe()},e.prototype.onMenuEvent=function(e){var t=this;if(!this.disabled){var n=e.contextMenu,o=e.event,i=e.item;n&&n!==this||(this.event=o,this.item=i,this.setVisibleMenuItems(),this._contextMenuService.openContextMenu(u({},e,{menuItems:this.visibleMenuItems,menuClass:this.menuClass})),this._contextMenuService.close.asObservable().pipe(s.first()).subscribe((function(e){return t.close.emit(e)})),this.open.next(e))}},e.prototype.isMenuItemVisible=function(e){return this.evaluateIfFunction(e.visible)},e.prototype.setVisibleMenuItems=function(){var e=this;this.visibleMenuItems=this.menuItems.filter((function(t){return e.isMenuItemVisible(t)}))},e.prototype.evaluateIfFunction=function(e){return e instanceof Function?e(this.item):e},e.decorators=[{type:o.Component,args:[{encapsulation:o.ViewEncapsulation.None,selector:"context-menu",template:" ",styles:["\n .cdk-overlay-container {\n position: fixed;\n z-index: 1000;\n pointer-events: none;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n }\n .ngx-contextmenu.cdk-overlay-pane {\n position: absolute;\n pointer-events: auto;\n box-sizing: border-box;\n }\n "]}]}],e.ctorParameters=function(){return[{type:h},{type:o.ChangeDetectorRef},{type:o.ElementRef},{type:void 0,decorators:[{type:o.Optional},{type:o.Inject,args:[l]}]}]},e.propDecorators={menuClass:[{type:o.Input}],autoFocus:[{type:o.Input}],useBootstrap4:[{type:o.Input}],disabled:[{type:o.Input}],close:[{type:o.Output}],open:[{type:o.Output}],menuItems:[{type:o.ContentChildren,args:[c]}],menuElement:[{type:o.ViewChild,args:["menu",{static:!1}]}]},e}();var y=function(){function e(e){this.contextMenuService=e}return e.prototype.onContextMenu=function(e){this.contextMenu.disabled||(this.contextMenuService.show.next({contextMenu:this.contextMenu,event:e,item:this.contextMenuSubject}),e.preventDefault(),e.stopPropagation())},e.decorators=[{type:o.Directive,args:[{selector:"[contextMenu]"}]}],e.ctorParameters=function(){return[{type:h}]},e.propDecorators={contextMenuSubject:[{type:o.Input}],contextMenu:[{type:o.Input}],onContextMenu:[{type:o.HostListener,args:["contextmenu",["$event"]]}]},e}();var v=function(){function e(){}return e.forRoot=function(t){return{ngModule:e,providers:[h,{provide:l,useValue:t}]}},e.decorators=[{type:o.NgModule,args:[{declarations:[y,m,p,c],entryComponents:[p],exports:[y,m,c],imports:[n.CommonModule,t.OverlayModule]}]}],e}();e.ContextMenuComponent=m,e.ContextMenuModule=v,e.ContextMenuService=h,e.ɵa=y,e.ɵb=c,e.ɵc=l,e.ɵd=p,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ngx-contextmenu.umd.min.js.map