| 12345678910111213141516 |
- !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<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};var c=function(){function e(e,t){this.template=e,this.elementRef=t,this.divider=!1,this.enabled=!0,this.passive=!1,this.visible=!0,this.execute=new o.EventEmitter,this.isActive=!1}return Object.defineProperty(e.prototype,"disabled",{get:function(){return this.passive||this.divider||!this.evaluateIfFunction(this.enabled,this.currentItem)},enumerable:!0,configurable:!0}),e.prototype.evaluateIfFunction=function(e,t){return e instanceof Function?e(t):e},e.prototype.setActiveStyles=function(){this.isActive=!0},e.prototype.setInactiveStyles=function(){this.isActive=!1},e.prototype.triggerExecute=function(e,t){this.evaluateIfFunction(this.enabled,e)&&this.execute.emit({event:t,item:e})},e.decorators=[{type:o.Directive,args:[{selector:"[contextMenuItem]"}]}],e.ctorParameters=function(){return[{type:o.TemplateRef},{type:o.ElementRef}]},e.propDecorators={subMenu:[{type:o.Input}],divider:[{type:o.Input}],enabled:[{type:o.Input}],passive:[{type:o.Input}],visible:[{type:o.Input}],execute:[{type:o.Output}]},e}();var l=new o.InjectionToken("CONTEXT_MENU_OPTIONS");var p=function(){function e(e,t,n){this.changeDetector=e,this.elementRef=t,this.options=n,this.menuItems=[],this.isLeaf=!1,this.execute=new o.EventEmitter,this.openSubMenu=new o.EventEmitter,this.closeLeafMenu=new o.EventEmitter,this.closeAllMenus=new o.EventEmitter,this.autoFocus=!1,this.useBootstrap4=!1,this.subscription=new i.Subscription,n&&(this.autoFocus=n.autoFocus,this.useBootstrap4=n.useBootstrap4)}return e.prototype.ngOnInit=function(){var e=this;this.menuItems.forEach((function(t){t.currentItem=e.item,e.subscription.add(t.execute.subscribe((function(n){return e.execute.emit(u({},n,{menuItem:t}))})))}));var t=new o.QueryList;t.reset(this.menuItems),this._keyManager=new a.ActiveDescendantKeyManager(t).withWrap()},e.prototype.ngAfterViewInit=function(){var e=this;this.autoFocus&&setTimeout((function(){return e.focus()})),this.overlay.updatePosition()},e.prototype.ngOnDestroy=function(){this.subscription.unsubscribe()},e.prototype.focus=function(){this.autoFocus&&this.menuElement.nativeElement.focus()},e.prototype.stopEvent=function(e){e.stopPropagation()},e.prototype.isMenuItemEnabled=function(e){return this.evaluateIfFunction(e&&e.enabled)},e.prototype.isMenuItemVisible=function(e){return this.evaluateIfFunction(e&&e.visible)},e.prototype.evaluateIfFunction=function(e){return e instanceof Function?e(this.item):e},e.prototype.isDisabled=function(e){return e.enabled&&!e.enabled(this.item)},e.prototype.onKeyEvent=function(e){this.isLeaf&&this._keyManager.onKeydown(e)},e.prototype.keyboardOpenSubMenu=function(e){if(this.isLeaf){this.cancelEvent(e);var t=this.menuItems[this._keyManager.activeItemIndex];t&&this.onOpenSubMenu(t)}},e.prototype.keyboardMenuItemSelect=function(e){if(this.isLeaf){this.cancelEvent(e);var t=this.menuItems[this._keyManager.activeItemIndex];t&&this.onMenuItemSelect(t,e)}},e.prototype.onCloseLeafMenu=function(e){this.isLeaf&&(this.cancelEvent(e),this.closeLeafMenu.emit({exceptRootMenu:37===e.keyCode,event:e}))},e.prototype.closeMenu=function(e){"click"===e.type&&2===e.button||this.closeAllMenus.emit({event:e})},e.prototype.onOpenSubMenu=function(e,t){var n=this.menuItemElements.toArray()[this._keyManager.activeItemIndex],o=n&&n.nativeElement;this.openSubMenu.emit({anchorElement:o,contextMenu:e.subMenu,event:t,item:this.item,parentContextMenu:this})},e.prototype.onMenuItemSelect=function(e,t){t.preventDefault(),t.stopPropagation(),this.onOpenSubMenu(e,t),e.subMenu||e.triggerExecute(this.item,t)},e.prototype.cancelEvent=function(e){if(e){var t=e.target;["INPUT","TEXTAREA","SELECT"].indexOf(t.tagName)>-1||t.isContentEditable||(e.preventDefault(),e.stopPropagation())}},e.decorators=[{type:o.Component,args:[{selector:"context-menu-content",template:'\n <div\n class="dropdown open show ngx-contextmenu"\n [ngClass]="menuClass"\n tabindex="0"\n >\n <ul\n #menu\n class="dropdown-menu show"\n style="position: static; float: none;"\n tabindex="0"\n >\n <li\n #li\n *ngFor="let menuItem of menuItems; let i = index"\n [class.disabled]="!isMenuItemEnabled(menuItem)"\n [class.divider]="menuItem.divider"\n [class.dropdown-divider]="useBootstrap4 && menuItem.divider"\n [class.active]="menuItem.isActive && isMenuItemEnabled(menuItem)"\n [attr.role]="menuItem.divider ? \'separator\' : undefined"\n >\n <a\n *ngIf="!menuItem.divider && !menuItem.passive"\n href\n [class.dropdown-item]="useBootstrap4"\n [class.active]="menuItem.isActive && isMenuItemEnabled(menuItem)"\n [class.disabled]="useBootstrap4 && !isMenuItemEnabled(menuItem)"\n [class.hasSubMenu]="!!menuItem.subMenu"\n (click)="onMenuItemSelect(menuItem, $event)"\n (mouseenter)="onOpenSubMenu(menuItem, $event)"\n >\n <ng-template\n [ngTemplateOutlet]="menuItem.template"\n [ngTemplateOutletContext]="{ $implicit: item }"\n ></ng-template>\n </a>\n\n <span\n (click)="stopEvent($event)"\n (contextmenu)="stopEvent($event)"\n class="passive"\n *ngIf="!menuItem.divider && menuItem.passive"\n [class.dropdown-item]="useBootstrap4"\n [class.disabled]="useBootstrap4 && !isMenuItemEnabled(menuItem)"\n >\n <ng-template\n [ngTemplateOutlet]="menuItem.template"\n [ngTemplateOutletContext]="{ $implicit: item }"\n ></ng-template>\n </span>\n </li>\n </ul>\n </div>\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
|