UNPKG

@lidorsystems/integralui-web

Version:

IntegralUI Web - Advanced UI Components for Angular

15 lines (12 loc) 11.4 kB
/* filename: integralui.contextmenu.js version : 20.2.0 Copyright © 2016-2020 Lidor Systems. All rights reserved. This file is part of the "IntegralUI Web" Library. The contents of this file are subject to the IntegralUI Web License, and may not be used except in compliance with the License. A copy of the License should have been installed in the product's root installation directory or it can be found at http://www.lidorsystems.com/products/web/studio/license-agreement.aspx. This SOFTWARE is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Any infringement will be prosecuted under applicable laws. */ "use strict";var __extends=this&&this.__extends||function(){var e=function(t,i){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)if(t.hasOwnProperty(i))e[i]=t[i]})(t,i)};return function(t,i){e(t,i);function n(){this.constructor=t}t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(exports,"__esModule",{value:!0});var core_1=require("@angular/core"),integralui_core_1=require("../components/integralui.core"),integralui_core_2=require("../components/integralui.core"),integralui_common_service_1=require("../services/integralui.common.service"),integralui_data_service_1=require("../services/integralui.data.service"),integralui_menuitem_1=require("../components/integralui.menuitem"),i0=require("@angular/core"),i1=require("../services/integralui.data.service"),i2=require("../services/integralui.common.service"),i3=require("../components/integralui.core"),i4=require("@angular/common"),i5=require("../components/integralui.menuitem"),_c0=["content"];function IntegralUIContextMenuComponent_iui_menuitem_3_Template(e,t){if(1&e)i0.ɵɵelement(0,"iui-menuitem",3);if(2&e){var i=t.$implicit,n=i0.ɵɵnextContext();i0.ɵɵproperty("data",i)("items",i.items)("enabled",i.enabled)("icon",i.icon)("iconUrl",i.iconUrl)("text",i.text)("orientation","vertical")("level",0)("templateRef",n.itemTemplate)("showAnimation",!1)}}var _c1=function(e,t,i){return{top:e,left:t,height:"auto",opacity:i}},IntegralUIContextMenuComponent=function(e){__extends(t,e);function t(t,i,n,o,r){var s=e.call(this,n)||this;s.dataService=t;s.elemRef=i;s.commonService=n;s.cmpResolver=o;s.baseService=r;s.blockDisplay="none";s.blockElemWidth="0";s.blockElemHeight="0";s.blockOverflow="hidden";s.blockOpacity=0;s.tRef=null;s.adjustment={top:0,left:0};s.autoClose=!0;s.direction=integralui_core_2.IntegralUIDirection.None;s.inverse=!1;s.items=[];s.mode="normal";s.position={x:0,y:-9999999};s.itemClick=new core_1.EventEmitter;s.menuOpened=new core_1.EventEmitter;s.menuClosed=new core_1.EventEmitter;s.itemList=[];return s}t.prototype.ngOnInit=function(){this.baseService.setComponent(this);this.dataService.init(this.items);this.generalClassName="iui-contextmenu";this.initStyle()};t.prototype.ngAfterViewInit=function(){var e=this,t=setTimeout(function(){var i=e.cmpResolver.resolveComponentFactory(integralui_core_1.IntegralUITComponent);if(i&&e.contentRef)e.tRef=e.contentRef.createComponent(i);clearTimeout(t)},100)};t.prototype.ngAfterContentInit=function(){var e=this,t=setTimeout(function(){e.elemRef.nativeElement.firstElementChild.focus();clearTimeout(t)},1)};t.prototype.ngOnDestroy=function(){if(this.tRef)this.tRef.destroy()};t.prototype.onBlur=function(e){if(0!=this.autoClose)this.menuClosed.emit({event:e})};t.prototype.onRightClick=function(e){e.preventDefault()};t.prototype.getItemFromComponent=function(e){if(e&&e.data)return e.data;if(this.items){this.itemList=this.contentList.toArray();var t=this.itemList.indexOf(e);if(t>=0&&t<this.items.length)return this.items[t]}return null};t.prototype.invokeMethod=function(e,t){switch(e){case"ITEM_CLICK":this.itemClick.emit({event:t.event,item:this.getItemFromComponent(t.cmp)})}};t.prototype.getSize=function(){return{width:this.elemRef.nativeElement.firstElementChild.offsetWidth,height:this.elemRef.nativeElement.firstElementChild.offsetHeight}};t.prototype.adjustPosition=function(e,t,i,n,o){var r=this,s=r.commonService.getShiftPos();setTimeout(function(){var c=r.getSize(),u=i;if("manual"==t&&o){u.x=o.left+o.width+s.x+r.adjustment.left;u.y=o.bottom+s.y+4+r.adjustment.top;if(r.direction&integralui_core_2.IntegralUIDirection.Above)u.y-=c.height;if(r.inverse||r.direction&integralui_core_2.IntegralUIDirection.Left)u.x-=c.width}if(n)if(u.y+c.height>n.height){var l=u.y+c.height-n.height;u.y-=l}r.position=u;r.menuOpened.emit({event:e})},10)};t.prototype.open=function(e,t,i,n,o){if(this.items){this.blockDisplay="block";this.blockOpacity=1;this.adjustPosition(e,t,i,n,o)}};t.ɵfac=function(e){return new(e||t)(i0.ɵɵdirectiveInject(i1.IntegralUIDataService),i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i2.IntegralUICommonService),i0.ɵɵdirectiveInject(i0.ComponentFactoryResolver),i0.ɵɵdirectiveInject(i3.IntegralUIBaseService))};t.ɵcmp=i0.ɵɵdefineComponent({type:t,selectors:[["iui-contextmenu"]],contentQueries:function(e,t,i){if(1&e)i0.ɵɵcontentQuery(i,integralui_menuitem_1.IntegralUIMenuItem,!1);if(2&e){var n;i0.ɵɵqueryRefresh(n=i0.ɵɵloadQuery())&&(t.contentList=n)}},viewQuery:function(e,t){if(1&e)i0.ɵɵviewQuery(_c0,!0,core_1.ViewContainerRef);if(2&e){var i;i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.contentRef=i.first)}},inputs:{controlStyle:"controlStyle",data:"data",state:"state",adjustment:"adjustment",autoClose:"autoClose",direction:"direction",inverse:"inverse",items:"items",itemTemplate:"itemTemplate",mode:"mode",position:"position"},outputs:{itemClick:"itemClick",menuOpened:"menuOpened",menuClosed:"menuClosed"},features:[i0.ɵɵProvidersFeature([integralui_core_1.IntegralUIBaseService,integralui_data_service_1.IntegralUIDataService]),i0.ɵɵInheritDefinitionFeature],decls:4,vars:7,consts:[["tabindex","999",3,"ngClass","ngStyle","blur","contextmenu"],["content",""],[3,"data","items","enabled","icon","iconUrl","text","orientation","level","templateRef","showAnimation",4,"ngFor","ngForOf"],[3,"data","items","enabled","icon","iconUrl","text","orientation","level","templateRef","showAnimation"]],template:function(e,t){if(1&e){i0.ɵɵelementStart(0,"div",0);i0.ɵɵlistener("blur",function(e){return t.onBlur(e)})("contextmenu",function(e){return t.onRightClick(e)});i0.ɵɵelementStart(1,"ul",null,1);i0.ɵɵtemplate(3,IntegralUIContextMenuComponent_iui_menuitem_3_Template,1,10,"iui-menuitem",2);i0.ɵɵelementEnd();i0.ɵɵelementEnd()}if(2&e){i0.ɵɵproperty("ngClass",t.getControlClass())("ngStyle",i0.ɵɵpureFunction3(3,_c1,t.position.y+"px",t.position.x+"px",t.blockOpacity));i0.ɵɵadvance(3);i0.ɵɵproperty("ngForOf",t.items)}},directives:[i4.NgClass,i4.NgStyle,i4.NgForOf,i5.IntegralUIMenuItem],encapsulation:2});return t}(integralui_core_1.IntegralUIBaseComponent);exports.IntegralUIContextMenuComponent=IntegralUIContextMenuComponent;var IntegralUIContextMenu=function(){function e(e,t,i){this.elemRef=e;this.viewContainer=t;this.cmpResolver=i;this.currentSettings=!1;this.eventList=[];this.isMenuActive=!1;this.winScrollPos={top:0,left:0};this.cmpRef=null;this.templateList=[];this.itemClick=new core_1.EventEmitter;this.menuClick=new core_1.EventEmitter;this.menuOpening=new core_1.EventEmitter;this.menuOpened=new core_1.EventEmitter;this.menuClosed=new core_1.EventEmitter}Object.defineProperty(e.prototype,"settings",{get:function(){return this.currentSettings},set:function(e){if(this.currentSettings!=e){this.currentSettings=e;this.updateTemplate()}},enumerable:!0,configurable:!0});e.prototype.ngAfterContentInit=function(){this.updateTemplate()};e.prototype.updateTemplate=function(){this.itemTemplate=void 0;if(this.templates){this.templateList=this.templates.toArray();for(var e=0;e<this.templateList.length;e++)if(this.templateList[e].settings)switch(this.templateList[e].settings.type){case"menu-item":this.itemTemplate=this.templateList[e].getTemplate()}}};e.prototype.ngOnDestroy=function(){this.closeMenu()};e.prototype.getSize=function(){return{width:this.elemRef.nativeElement.offsetWidth,height:this.elemRef.nativeElement.offsetHeight}};e.prototype.closeMenu=function(e){if(this.cmpRef){if(this.eventList)this.eventList.forEach(function(e){return e.unsubscribe()});this.cmpRef.destroy()}if(e)this.menuClosed.emit({event:e})};e.prototype.onContextMenu=function(e){if("manual"!=this.settings.position)this.processMenuOpen(e)};e.prototype.onMouseDown=function(e){if("manual"==this.settings.position&&(this.settings.buttonType<0||e.which==this.settings.buttonType))this.processMenuOpen(e,"manual")};e.prototype.processMenuOpen=function(e,t){e.preventDefault();var i=this;i.winScrollPos={top:document.documentElement.scrollTop,left:document.documentElement.scrollLeft};var n=i.contextMenuRef?i.contextMenuRef:i.settings?i.settings.appRef:null;if(n){i.closeMenu();var o={cancel:!1,event:e};i.menuOpening.emit(o);if(1!=o.cancel){var r=i.cmpResolver.resolveComponentFactory(IntegralUIContextMenuComponent);if(r){i.cmpRef=n.createComponent(r);if(i.cmpRef){var s=null;if(i.cmpRef.instance)s=i.cmpRef.instance;if(s){i.isMenuActive=!0;s.mode=t;s.items=i.createMenuList(i.settings.items);s.adjustment=i.settings.adjustment?i.settings.adjustment:{top:0,left:0};s.autoClose=void 0!=i.settings.autoClose?i.settings.autoClose:!0;s.direction=i.settings.direction?i.settings.direction:integralui_core_2.IntegralUIDirection.None;s.inverse=void 0!=i.settings.inverse?i.settings.inverse:!1;s.itemTemplate=i.itemTemplate;s.controlStyle=i.settings.style;var c=i.settings.appSize?i.settings.appSize:{width:window.innerWidth,height:window.innerHeight};if("manual"==t)s.open(e,t,{x:0,y:0},c,i.elemRef.nativeElement.getBoundingClientRect());else s.open(e,t,{x:e.pageX,y:e.pageY},c);setTimeout(function(){window.scrollTo(i.winScrollPos.left,i.winScrollPos.top)},5);i.eventList.push(s.itemClick.subscribe(function(e){i.itemClick.emit(e);i.menuClick.emit(e);i.closeMenu(e)}));i.eventList.push(s.menuOpened.subscribe(function(e){i.menuOpened.emit(e)}));i.eventList.push(s.menuClosed.subscribe(function(e){i.closeMenu(e)}));if("manual"==t)e.stopPropagation()}}}}}};e.prototype.createMenuList=function(e){var t=[];if(e)for(var i=0;i<e.length;i++)if(0!=e[i].visible)t.push(e[i]);return t};e.ɵfac=function(t){return new(t||e)(i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i0.ViewContainerRef),i0.ɵɵdirectiveInject(i0.ComponentFactoryResolver))};e.ɵdir=i0.ɵɵdefineDirective({type:e,selectors:[["","iuiContextMenu",""]],contentQueries:function(e,t,i){if(1&e)i0.ɵɵcontentQuery(i,integralui_core_1.IntegralUITemplate,!0);if(2&e){var n;i0.ɵɵqueryRefresh(n=i0.ɵɵloadQuery())&&(t.templates=n)}},hostBindings:function(e,t){if(1&e)i0.ɵɵlistener("contextmenu",function(e){return t.onContextMenu(e)})("mousedown",function(e){return t.onMouseDown(e)})},inputs:{settings:["iuiContextMenu","settings"],contextMenuRef:"contextMenuRef"},outputs:{itemClick:"itemClick",menuClick:"menuClick",menuOpening:"menuOpening",menuOpened:"menuOpened",menuClosed:"menuClosed"}});return e}();exports.IntegralUIContextMenu=IntegralUIContextMenu;