UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

10 lines 18.1 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@angular/cdk/platform"),require("rxjs"),require("rxjs/operators"),require("@angular/cdk/overlay"),require("@angular/common"),require("@angular/core"),require("@angular/forms"),require("ng-zorro-antd/button"),require("ng-zorro-antd/core"),require("ng-zorro-antd/icon")):"function"==typeof define&&define.amd?define("ng-zorro-antd/menu",["exports","@angular/cdk/platform","rxjs","rxjs/operators","@angular/cdk/overlay","@angular/common","@angular/core","@angular/forms","ng-zorro-antd/button","ng-zorro-antd/core","ng-zorro-antd/icon"],n):n((e["ng-zorro-antd"]=e["ng-zorro-antd"]||{},e["ng-zorro-antd"].menu={}),e.ng.cdk.platform,e.rxjs,e.rxjs.operators,e.ng.cdk.overlay,e.ng.common,e.ng.core,e.ng.forms,e["ng-zorro-antd"].button,e["ng-zorro-antd"].core,e["ng-zorro-antd"].icon)}(this,function(e,n,a,o,t,i,u,r,s,l,p){"use strict";var c=function(e,n){return(c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t])})(e,n)};function d(e,n,t,i){var o,r=arguments.length,s=r<3?n:null===i?i=Object.getOwnPropertyDescriptor(n,t):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,n,t,i);else for(var a=e.length-1;0<=a;a--)(o=e[a])&&(s=(r<3?o(s):3<r?o(n,t,s):o(n,t))||s);return 3<r&&s&&Object.defineProperty(n,t,s),s}function m(e,n){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,n)}function h(e,n){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var i,o,r=t.call(e),s=[];try{for(;(void 0===n||0<n--)&&!(i=r.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(t=r["return"])&&t.call(r)}finally{if(o)throw o.error}}return s}function z(){for(var e=[],n=0;n<arguments.length;n++)e=e.concat(h(arguments[n]));return e}var v=function(n){function e(){var e=null!==n&&n.apply(this,arguments)||this;return e.isInDropDown=!1,e}return function i(e,n){function t(){this.constructor=e}c(e,n),e.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}(e,n),e.decorators=[{type:u.Injectable}],e}(l.NzMenuBaseService),S=function(){function e(e,n){var t=this;this.nzHostSubmenuService=e,this.nzMenuService=n,this.disabled=!1,this.mode="vertical",this.mode$=this.nzMenuService.mode$.pipe(o.map(function(e){return"inline"===e?"inline":"vertical"===e||t.nzHostSubmenuService?"vertical":"horizontal"}),o.tap(function(e){return t.mode=e})),this.level=1,this.level$=new a.BehaviorSubject(1),this.subMenuOpen$=new a.BehaviorSubject(!1),this.open$=new a.BehaviorSubject(!1),this.mouseEnterLeave$=new a.Subject,this.menuOpen$=a.combineLatest(this.subMenuOpen$,this.mouseEnterLeave$).pipe(o.map(function(e){return e[0]||e[1]}),o.auditTime(150),o.distinctUntilChanged(),o.tap(function(e){t.setOpenState(e),t.nzHostSubmenuService&&t.nzHostSubmenuService.subMenuOpen$.next(e)})),this.nzHostSubmenuService&&this.setLevel(this.nzHostSubmenuService.level+1)}return e.prototype.setOpenState=function(e){this.open$.next(e)},e.prototype.onMenuItemClick=function(){this.setMouseEnterState(!1)},e.prototype.setLevel=function(e){this.level$.next(e),this.level=e},e.prototype.setMouseEnterState=function(e){"horizontal"!==this.mode&&"vertical"!==this.mode&&!this.nzMenuService.isInDropDown||this.disabled||this.mouseEnterLeave$.next(e)},e.decorators=[{type:u.Injectable}],e.ctorParameters=function(){return[{type:e,decorators:[{type:u.SkipSelf},{type:u.Optional}]},{type:v}]},e}(),f=function(){function e(e,n,t,i,o){this.nzUpdateHostClassService=e,this.nzMenuService=n,this.nzSubmenuService=t,this.renderer=i,this.elementRef=o,this.el=this.elementRef.nativeElement,this.destroy$=new a.Subject,this.originalPadding=null,this.selected$=new a.Subject,this.nzDisabled=!1,this.nzSelected=!1}return e.prototype.clickMenuItem=function(e){if(this.nzDisabled)return e.preventDefault(),void e.stopPropagation();this.nzMenuService.onMenuItemClick(this),this.nzSubmenuService&&this.nzSubmenuService.onMenuItemClick()},e.prototype.setClassMap=function(){var e,n=this.nzMenuService.isInDropDown?"ant-dropdown-menu-item":"ant-menu-item";this.nzUpdateHostClassService.updateHostClass(this.el,((e={})[""+n]=!0,e[n+"-selected"]=this.nzSelected,e[n+"-disabled"]=this.nzDisabled,e))},e.prototype.setSelectedState=function(e){this.nzSelected=e,this.selected$.next(e),this.setClassMap()},e.prototype.ngOnInit=function(){var n=this,e=this.el.style.paddingLeft;e&&(this.originalPadding=parseInt(e,10)),a.merge(this.nzMenuService.mode$,this.nzMenuService.inlineIndent$,this.nzSubmenuService?this.nzSubmenuService.level$:a.EMPTY).pipe(o.takeUntil(this.destroy$)).subscribe(function(){var e=null;"inline"===n.nzMenuService.mode?e=l.isNotNil(n.nzPaddingLeft)?n.nzPaddingLeft:(n.nzSubmenuService?n.nzSubmenuService.level+1:1)*n.nzMenuService.inlineIndent:e=n.originalPadding;e?n.renderer.setStyle(n.el,"padding-left",e+"px"):n.renderer.removeStyle(n.el,"padding-left")}),this.setClassMap()},e.prototype.ngOnChanges=function(e){e.nzSelected&&this.setSelectedState(this.nzSelected),e.nzDisabled&&this.setClassMap()},e.prototype.ngOnDestroy=function(){this.destroy$.next(),this.destroy$.complete()},e.decorators=[{type:u.Directive,args:[{selector:"[nz-menu-item]",exportAs:"nzMenuItem",providers:[l.NzUpdateHostClassService],host:{"(click)":"clickMenuItem($event)"}}]}],e.ctorParameters=function(){return[{type:l.NzUpdateHostClassService},{type:l.NzMenuBaseService},{type:S,decorators:[{type:u.Optional}]},{type:u.Renderer2},{type:u.ElementRef}]},e.propDecorators={nzPaddingLeft:[{type:u.Input}],nzDisabled:[{type:u.Input}],nzSelected:[{type:u.Input}]},d([l.InputBoolean(),m("design:type",Object)],e.prototype,"nzDisabled",void 0),d([l.InputBoolean(),m("design:type",Object)],e.prototype,"nzSelected",void 0),e}(); /** * @license * Copyright Alibaba.com All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ function y(e,n){return e||n}var g=function(){function e(e,n,t,i,o,r,s){this.elementRef=e,this.nzMenuService=n,this.cdr=t,this.nzSubmenuService=i,this.nzUpdateHostClassService=o,this.platform=r,this.noAnimation=s,this.nzOpen=!1,this.nzDisabled=!1,this.nzOpenChange=new u.EventEmitter,this.placement="rightTop",this.expandState="collapsed",this.overlayPositions=z(l.DEFAULT_SUBMENU_POSITIONS),this.destroy$=new a.Subject,this.isChildMenuSelected=!1,this.isMouseHover=!1}return e.prototype.setOpenState=function(e){this.nzSubmenuService.setOpenState(e)},e.prototype.clickSubMenuTitle=function(){"inline"!==this.nzSubmenuService.mode||this.nzMenuService.isInDropDown||this.nzDisabled||this.setOpenState(!this.nzOpen)},e.prototype.setMouseEnterState=function(e){this.isMouseHover=e,this.setClassMap(),this.nzSubmenuService.setMouseEnterState(e)},e.prototype.setTriggerWidth=function(){"horizontal"===this.nzSubmenuService.mode&&this.platform.isBrowser&&(this.triggerWidth=this.cdkOverlayOrigin.nativeElement.getBoundingClientRect().width)},e.prototype.onPositionChange=function(e){this.placement=l.getPlacementName(e),this.cdr.markForCheck()},e.prototype.setClassMap=function(){var e,n=this.nzMenuService.isInDropDown?"ant-dropdown-menu-submenu":"ant-menu-submenu";this.nzUpdateHostClassService.updateHostClass(this.elementRef.nativeElement,((e={})[""+n]=!0,e[n+"-disabled"]=this.nzDisabled,e[n+"-open"]=this.nzOpen,e[n+"-selected"]=this.isChildMenuSelected,e[n+"-"+this.nzSubmenuService.mode]=!0,e[n+"-active"]=this.isMouseHover&&!this.nzDisabled,e))},e.prototype.ngOnInit=function(){var i=this;a.combineLatest(this.nzSubmenuService.mode$,this.nzSubmenuService.open$).pipe(o.takeUntil(this.destroy$)).subscribe(function(e){var n=e[0],t=e[1];i.expandState=t&&"inline"===n?"expanded":t&&"horizontal"===n?"bottom":t&&"vertical"===n?"active":"collapsed",i.overlayPositions="horizontal"===n?[l.POSITION_MAP.bottomLeft]:[l.POSITION_MAP.rightTop,l.POSITION_MAP.leftTop],t!==i.nzOpen&&(i.nzOpen=t,i.nzOpenChange.emit(i.nzOpen)),i.setClassMap(),i.setTriggerWidth()}),this.nzSubmenuService.menuOpen$.pipe(o.takeUntil(this.destroy$)).subscribe(function(e){i.nzMenuService.menuOpen$.next(e)}),a.merge(this.nzMenuService.mode$,this.nzMenuService.inlineIndent$,this.nzSubmenuService.level$,this.nzSubmenuService.open$,this.nzSubmenuService.mode$).pipe(o.takeUntil(this.destroy$)).subscribe(function(){i.cdr.markForCheck()})},e.prototype.ngAfterContentInit=function(){var n=this;this.setTriggerWidth(),this.listOfNzMenuItemDirective.changes.pipe(o.startWith(!0),o.flatMap(function(){return a.merge.apply(void 0,z([n.listOfNzMenuItemDirective.changes],n.listOfNzMenuItemDirective.map(function(e){return e.selected$})))}),o.map(function(){return n.listOfNzMenuItemDirective.some(function(e){return e.nzSelected})}),o.takeUntil(this.destroy$)).subscribe(function(e){n.isChildMenuSelected=e,n.setClassMap()})},e.prototype.ngOnChanges=function(e){e.nzOpen&&this.nzSubmenuService.setOpenState(this.nzOpen),e.nzDisabled&&(this.nzSubmenuService.disabled=this.nzDisabled,this.setClassMap())},e.prototype.ngOnDestroy=function(){this.destroy$.next(),this.destroy$.complete()},e.decorators=[{type:u.Component,args:[{selector:"[nz-submenu]",exportAs:"nzSubmenu",providers:[S,l.NzUpdateHostClassService],animations:[l.collapseMotion,l.zoomBigMotion,l.slideMotion],encapsulation:u.ViewEncapsulation.None,changeDetection:u.ChangeDetectionStrategy.OnPush,preserveWhitespaces:!1,template:'<div cdkOverlayOrigin\n #origin="cdkOverlayOrigin"\n [class.ant-dropdown-menu-submenu-title]="nzMenuService.isInDropDown"\n [class.ant-menu-submenu-title]="!nzMenuService.isInDropDown"\n [style.paddingLeft.px]="nzMenuService.mode === \'inline\'? (nzPaddingLeft ? nzPaddingLeft : nzSubmenuService.level * nzMenuService.inlineIndent) : null"\n (mouseenter)="setMouseEnterState(true)"\n (mouseleave)="setMouseEnterState(false)"\n (click)="clickSubMenuTitle()">\n <ng-content select="[title]"></ng-content>\n <span *ngIf="nzMenuService.isInDropDown; else notDropdownTpl" class="ant-dropdown-menu-submenu-arrow">\n <i nz-icon type="right" class="anticon-right ant-dropdown-menu-submenu-arrow-icon"></i>\n </span>\n <ng-template #notDropdownTpl><i class="ant-menu-submenu-arrow"></i></ng-template>\n</div>\n<ul *ngIf="nzMenuService.mode === \'inline\'"\n [@collapseMotion]="expandState"\n [nzNoAnimation]="noAnimation?.nzNoAnimation"\n [ngClass]="nzMenuClassName"\n class="ant-menu ant-menu-inline ant-menu-sub">\n <ng-template [ngTemplateOutlet]="subMenuTemplate"></ng-template>\n</ul>\n<ng-template cdkConnectedOverlay\n (positionChange)="onPositionChange($event)"\n [cdkConnectedOverlayPositions]="overlayPositions"\n [cdkConnectedOverlayOrigin]="origin"\n [cdkConnectedOverlayWidth]="triggerWidth"\n [cdkConnectedOverlayOpen]="nzOpen && nzMenuService.mode !== \'inline\'">\n <div class="ant-menu-submenu ant-menu-submenu-popup"\n [@slideMotion]="expandState"\n [@zoomBigMotion]="expandState"\n [nzNoAnimation]="noAnimation?.nzNoAnimation"\n [class.ant-menu-light]="nzMenuService.theme === \'light\'"\n [class.ant-menu-dark]="nzMenuService.theme === \'dark\'"\n [class.ant-menu-submenu-placement-bottomLeft]="nzSubmenuService.mode === \'horizontal\'"\n [class.ant-menu-submenu-placement-rightTop]="nzSubmenuService.mode === \'vertical\' && placement === \'rightTop\'"\n [class.ant-menu-submenu-placement-leftTop]="nzSubmenuService.mode === \'vertical\' && placement === \'leftTop\'"\n (mouseleave)="setMouseEnterState(false)"\n (mouseenter)="setMouseEnterState(true)">\n <ul [class.ant-dropdown-menu]="nzMenuService.isInDropDown"\n [class.ant-menu]="!nzMenuService.isInDropDown"\n [class.ant-dropdown-menu-vertical]="nzMenuService.isInDropDown"\n [class.ant-menu-vertical]="!nzMenuService.isInDropDown"\n [class.ant-dropdown-menu-sub]="nzMenuService.isInDropDown"\n [class.ant-menu-sub]="!nzMenuService.isInDropDown"\n [ngClass]="nzMenuClassName">\n <ng-template [ngTemplateOutlet]="subMenuTemplate"></ng-template>\n </ul>\n </div>\n</ng-template>\n\n<ng-template #subMenuTemplate>\n <ng-content></ng-content>\n</ng-template>',styles:["\n .ant-menu-submenu-placement-bottomLeft {\n top: 6px;\n position: relative;\n }\n\n .ant-menu-submenu-placement-rightTop {\n left: 4px;\n position: relative;\n }\n\n .ant-menu-submenu-placement-leftTop {\n right: 4px;\n position: relative;\n }\n "]}]}],e.ctorParameters=function(){return[{type:u.ElementRef},{type:l.NzMenuBaseService},{type:u.ChangeDetectorRef},{type:S},{type:l.NzUpdateHostClassService},{type:n.Platform},{type:l.NzNoAnimationDirective,decorators:[{type:u.Host},{type:u.Optional}]}]},e.propDecorators={nzMenuClassName:[{type:u.Input}],nzPaddingLeft:[{type:u.Input}],nzOpen:[{type:u.Input}],nzDisabled:[{type:u.Input}],nzOpenChange:[{type:u.Output}],cdkConnectedOverlay:[{type:u.ViewChild,args:[t.CdkConnectedOverlay]}],cdkOverlayOrigin:[{type:u.ViewChild,args:[t.CdkOverlayOrigin,{read:u.ElementRef}]}],listOfNzSubMenuComponent:[{type:u.ContentChildren,args:[e,{descendants:!0}]}],listOfNzMenuItemDirective:[{type:u.ContentChildren,args:[f,{descendants:!0}]}]},d([l.InputBoolean(),m("design:type",Object)],e.prototype,"nzOpen",void 0),d([l.InputBoolean(),m("design:type",Object)],e.prototype,"nzDisabled",void 0),e}(),M=y,b=function(){function e(e,n,t){this.elementRef=e,this.nzMenuService=n,this.nzUpdateHostClassService=t,this.destroy$=new a.Subject,this.listOfOpenedNzSubMenuComponent=[],this.nzInlineIndent=24,this.nzTheme="light",this.nzMode="vertical",this.nzInDropDown=!1,this.nzInlineCollapsed=!1,this.nzSelectable=!this.nzMenuService.isInDropDown,this.nzClick=new u.EventEmitter}return e.prototype.updateInlineCollapse=function(){this.listOfNzMenuItemDirective&&(this.nzInlineCollapsed?(this.listOfOpenedNzSubMenuComponent=this.listOfNzSubMenuComponent.filter(function(e){return e.nzOpen}),this.listOfNzSubMenuComponent.forEach(function(e){return e.setOpenState(!1)}),this.nzMode="vertical"):(this.listOfOpenedNzSubMenuComponent.forEach(function(e){return e.setOpenState(!0)}),this.listOfOpenedNzSubMenuComponent=[],this.nzMode=this.cacheMode),this.nzMenuService.setMode(this.nzMode))},e.prototype.setClassMap=function(){var e,n=this.nzMenuService.isInDropDown?"ant-dropdown-menu":"ant-menu";this.nzUpdateHostClassService.updateHostClass(this.elementRef.nativeElement,((e={})[""+n]=!0,e[n+"-root"]=!0,e[n+"-"+this.nzTheme]=!0,e[n+"-"+this.nzMode]=!0,e[n+"-inline-collapsed"]=this.nzInlineCollapsed,e))},e.prototype.ngOnInit=function(){var e=this;this.setClassMap(),this.nzMenuService.menuItemClick$.pipe(o.takeUntil(this.destroy$)).subscribe(function(n){e.nzClick.emit(n),e.nzSelectable&&e.listOfNzMenuItemDirective.forEach(function(e){return e.setSelectedState(e===n)})})},e.prototype.ngAfterContentInit=function(){this.cacheMode=this.nzMode,this.updateInlineCollapse()},e.prototype.ngOnChanges=function(e){e.nzInlineCollapsed&&this.updateInlineCollapse(),e.nzInlineIndent&&this.nzMenuService.setInlineIndent(this.nzInlineIndent),e.nzInDropDown&&(this.nzMenuService.isInDropDown=this.nzInDropDown),e.nzTheme&&this.nzMenuService.setTheme(this.nzTheme),e.nzMode&&(this.nzMenuService.setMode(this.nzMode),!e.nzMode.isFirstChange()&&this.listOfNzSubMenuComponent&&this.listOfNzSubMenuComponent.forEach(function(e){return e.setOpenState(!1)})),(e.nzTheme||e.nzMode||e.nzInlineCollapsed)&&this.setClassMap()},e.prototype.ngOnDestroy=function(){this.destroy$.next(),this.destroy$.complete()},e.decorators=[{type:u.Directive,args:[{selector:"[nz-menu]",exportAs:"nzMenu",providers:[l.NzUpdateHostClassService,v,{provide:l.NzMenuBaseService,useFactory:M,deps:[[new u.SkipSelf,new u.Optional,l.NzDropdownHigherOrderServiceToken],v]}]}]}],e.ctorParameters=function(){return[{type:u.ElementRef},{type:l.NzMenuBaseService},{type:l.NzUpdateHostClassService}]},e.propDecorators={listOfNzMenuItemDirective:[{type:u.ContentChildren,args:[f,{descendants:!0}]}],listOfNzSubMenuComponent:[{type:u.ContentChildren,args:[g,{descendants:!0}]}],nzInlineIndent:[{type:u.Input}],nzTheme:[{type:u.Input}],nzMode:[{type:u.Input}],nzInDropDown:[{type:u.Input}],nzInlineCollapsed:[{type:u.Input}],nzSelectable:[{type:u.Input}],nzClick:[{type:u.Output}]},d([l.InputBoolean(),m("design:type",Object)],e.prototype,"nzInDropDown",void 0),d([l.InputBoolean(),m("design:type",Object)],e.prototype,"nzInlineCollapsed",void 0),d([l.InputBoolean(),m("design:type",Object)],e.prototype,"nzSelectable",void 0),e}(),O=function(){function e(e,n){this.elementRef=e,this.renderer=n,this.renderer.addClass(e.nativeElement,"ant-menu-item-group")}return e.decorators=[{type:u.Component,args:[{selector:"[nz-menu-group]",exportAs:"nzMenuGroup",changeDetection:u.ChangeDetectionStrategy.OnPush,encapsulation:u.ViewEncapsulation.None,template:'<div class="ant-menu-item-group-title">\n <ng-content select="[title]"></ng-content>\n</div>\n<ul class="ant-menu-item-group-list">\n <ng-content></ng-content>\n</ul>',preserveWhitespaces:!1}]}],e.ctorParameters=function(){return[{type:u.ElementRef},{type:u.Renderer2}]},e}(),C=function(){function e(e,n){this.elementRef=e,this.renderer=n,this.renderer.addClass(e.nativeElement,"ant-dropdown-menu-item-divider")}return e.decorators=[{type:u.Directive,args:[{selector:"[nz-menu-divider]",exportAs:"nzMenuDivider"}]}],e.ctorParameters=function(){return[{type:u.ElementRef},{type:u.Renderer2}]},e}(),I=function(){function e(){}return e.decorators=[{type:u.NgModule,args:[{imports:[i.CommonModule,r.FormsModule,s.NzButtonModule,t.OverlayModule,p.NzIconModule,l.NzNoAnimationModule],declarations:[b,f,g,C,O],exports:[b,f,g,C,O]}]}],e}();e.NzMenuDirective=b,e.NzMenuGroupComponent=O,e.NzMenuDividerDirective=C,e.NzMenuItemDirective=f,e.NzSubMenuComponent=g,e.NzMenuModule=I,e.NzMenuService=v,e.NzSubmenuService=S,e.NzMenuServiceFactory=y,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=ng-zorro-antd-menu.umd.min.js.map