ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
16 lines (14 loc) • 12.7 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/cdk/keycodes"),require("@angular/cdk/overlay"),require("@angular/cdk/portal"),require("@angular/core"),require("ng-zorro-antd/core/overlay"),require("ng-zorro-antd/core/util"),require("rxjs"),require("rxjs/operators"),require("@angular/common"),require("@angular/forms"),require("ng-zorro-antd/button"),require("ng-zorro-antd/core/no-animation"),require("ng-zorro-antd/core/outlet"),require("ng-zorro-antd/icon"),require("ng-zorro-antd/menu"),require("ng-zorro-antd/core/animation")):"function"==typeof define&&define.amd?define("ng-zorro-antd/dropdown",["exports","@angular/cdk/keycodes","@angular/cdk/overlay","@angular/cdk/portal","@angular/core","ng-zorro-antd/core/overlay","ng-zorro-antd/core/util","rxjs","rxjs/operators","@angular/common","@angular/forms","ng-zorro-antd/button","ng-zorro-antd/core/no-animation","ng-zorro-antd/core/outlet","ng-zorro-antd/icon","ng-zorro-antd/menu","ng-zorro-antd/core/animation"],t):t(((e=e||self)["ng-zorro-antd"]=e["ng-zorro-antd"]||{},e["ng-zorro-antd"].dropdown={}),e.ng.cdk.keycodes,e.ng.cdk.overlay,e.ng.cdk.portal,e.ng.core,e["ng-zorro-antd"].core.overlay,e["ng-zorro-antd"].core.util,e.rxjs,e.rxjs.operators,e.ng.common,e.ng.forms,e["ng-zorro-antd"].button,e["ng-zorro-antd"].core["no-animation"],e["ng-zorro-antd"].core.outlet,e["ng-zorro-antd"].icon,e["ng-zorro-antd"].menu,e["ng-zorro-antd"].core.animation)}(this,(function(e,t,n,o,r,i,a,s,l,p,u,c,d,y,f,h,v){"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.
***************************************************************************** */function g(e,t,n,o){var r,i=arguments.length,a=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,o);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(i<3?r(a):i>3?r(t,n,a):r(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function m(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function z(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a}var b=[i.POSITION_MAP.bottomLeft,i.POSITION_MAP.bottomRight,i.POSITION_MAP.topRight,i.POSITION_MAP.topLeft],w=function(){function e(e,t,n){this.elementRef=e,this.overlay=t,this.viewContainerRef=n,this.overlayRef=null,this.destroy$=new s.Subject,this.positionStrategy=this.overlay.position().flexibleConnectedTo(this.elementRef.nativeElement).withLockedPosition(),this.inputVisible$=new s.BehaviorSubject(!1),this.nzTrigger$=new s.BehaviorSubject("hover"),this.overlayClose$=new s.Subject,this.nzDropdownMenu=null,this.nzTrigger="hover",this.nzMatchWidthElement=null,this.nzBackdrop=!0,this.nzClickHide=!0,this.nzDisabled=!1,this.nzVisible=!1,this.nzOverlayClassName=null,this.nzOverlayStyle={},this.nzPlacement="bottomLeft",this.nzVisibleChange=new r.EventEmitter}return e.prototype.setDropdownMenuValue=function(e,t){this.nzDropdownMenu&&this.nzDropdownMenu.setValue(e,t)},e.prototype.ngOnInit=function(){var e=this;this.positionStrategy.positionChanges.pipe(l.takeUntil(this.destroy$)).subscribe((function(t){e.setDropdownMenuValue("dropDownPosition",t.connectionPair.originY)}))},e.prototype.ngAfterViewInit=function(){var e=this;if(this.nzDropdownMenu){var n=this.elementRef.nativeElement,r=s.merge(s.fromEvent(n,"mouseenter").pipe(l.mapTo(!0)),s.fromEvent(n,"mouseleave").pipe(l.mapTo(!1))),a=this.nzDropdownMenu.mouseState$,p=s.merge(a,r),u=s.fromEvent(n,"click").pipe(l.mapTo(!0)),c=this.nzTrigger$.pipe(l.switchMap((function(e){return"hover"===e?p:"click"===e?u:s.EMPTY}))),d=this.nzDropdownMenu.descendantMenuItemClick$.pipe(l.filter((function(){return e.nzClickHide})),l.mapTo(!1)),y=s.merge(c,d,this.overlayClose$).pipe(l.filter((function(){return!e.nzDisabled}))),f=s.merge(this.inputVisible$,y);s.combineLatest([f,this.nzDropdownMenu.isChildSubMenuOpen$]).pipe(l.map((function(e){var t=z(e,2),n=t[0],o=t[1];return n||o})),l.auditTime(150),l.distinctUntilChanged(),l.takeUntil(this.destroy$)).subscribe((function(r){var a=(e.nzMatchWidthElement?e.nzMatchWidthElement.nativeElement:n).getBoundingClientRect().width;if(e.nzVisible!==r&&e.nzVisibleChange.emit(r),e.nzVisible=r,r){if(e.overlayRef){var p=e.overlayRef.getConfig();p.minWidth=a,p.hasBackdrop="click"===e.nzTrigger}else e.overlayRef=e.overlay.create({positionStrategy:e.positionStrategy,minWidth:a,disposeOnNavigation:!0,hasBackdrop:"click"===e.nzTrigger,backdropClass:e.nzBackdrop?void 0:"nz-overlay-transparent-backdrop",scrollStrategy:e.overlay.scrollStrategies.reposition()}),s.merge(e.overlayRef.backdropClick(),e.overlayRef.detachments(),e.overlayRef.keydownEvents().pipe(l.filter((function(e){return e.keyCode===t.ESCAPE&&!t.hasModifierKey(e)})))).pipe(l.mapTo(!1),l.takeUntil(e.destroy$)).subscribe(e.overlayClose$);e.positionStrategy.withPositions(function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(z(arguments[t]));return e}([i.POSITION_MAP[e.nzPlacement]],b)),e.portal&&e.portal.templateRef===e.nzDropdownMenu.templateRef||(e.portal=new o.TemplatePortal(e.nzDropdownMenu.templateRef,e.viewContainerRef)),e.overlayRef.attach(e.portal)}else e.overlayRef&&e.overlayRef.detach()}))}},e.prototype.ngOnDestroy=function(){this.destroy$.next(),this.destroy$.complete(),this.overlayRef&&(this.overlayRef.dispose(),this.overlayRef=null)},e.prototype.ngOnChanges=function(e){var t=e.nzVisible,n=e.nzPlacement,o=e.nzDisabled,r=e.nzOverlayClassName,i=e.nzOverlayStyle;e.nzTrigger&&this.nzTrigger$.next(this.nzTrigger),t&&this.inputVisible$.next(this.nzVisible),o&&this.nzDisabled&&this.inputVisible$.next(!1),r&&this.setDropdownMenuValue("nzOverlayClassName",this.nzOverlayClassName),i&&this.setDropdownMenuValue("nzOverlayStyle",this.nzOverlayStyle),n&&this.setDropdownMenuValue("dropDownPosition",-1!==this.nzPlacement.indexOf("top")?"top":"bottom")},e.decorators=[{type:r.Directive,args:[{selector:"[nz-dropdown]",exportAs:"nzDropdown",host:{"[attr.disabled]":"nzDisabled ? '' : null","[class.ant-dropdown-trigger]":"true"}}]}],e.ctorParameters=function(){return[{type:r.ElementRef},{type:n.Overlay},{type:r.ViewContainerRef}]},e.propDecorators={nzDropdownMenu:[{type:r.Input}],nzTrigger:[{type:r.Input}],nzMatchWidthElement:[{type:r.Input}],nzBackdrop:[{type:r.Input}],nzClickHide:[{type:r.Input}],nzDisabled:[{type:r.Input}],nzVisible:[{type:r.Input}],nzOverlayClassName:[{type:r.Input}],nzOverlayStyle:[{type:r.Input}],nzPlacement:[{type:r.Input}],nzVisibleChange:[{type:r.Output}]},g([a.InputBoolean(),m("design:type",Object)],e.prototype,"nzBackdrop",void 0),g([a.InputBoolean(),m("design:type",Object)],e.prototype,"nzClickHide",void 0),g([a.InputBoolean(),m("design:type",Object)],e.prototype,"nzDisabled",void 0),g([a.InputBoolean(),m("design:type",Object)],e.prototype,"nzVisible",void 0),e}();var M=function(){function e(){}return e.decorators=[{type:r.NgModule}],e}(),C=function(){function e(){}return e.decorators=[{type:r.Directive,args:[{selector:"a[nz-dropdown]",host:{"[class.ant-dropdown-link]":"true"}}]}],e}(),R=function(){function e(e,t,n){this.renderer=e,this.nzButtonGroupComponent=t,this.elementRef=n}return e.prototype.ngAfterViewInit=function(){var e=this.renderer.parentNode(this.elementRef.nativeElement);this.nzButtonGroupComponent&&e&&this.renderer.addClass(e,"ant-dropdown-button")},e.decorators=[{type:r.Directive,args:[{selector:"[nz-button][nz-dropdown]"}]}],e.ctorParameters=function(){return[{type:r.Renderer2},{type:c.NzButtonGroupComponent,decorators:[{type:r.Host},{type:r.Optional}]},{type:r.ElementRef}]},e}();var D=function(){function e(e,t,n,o,r,i){this.cdr=e,this.elementRef=t,this.renderer=n,this.viewContainerRef=o,this.nzMenuService=r,this.noAnimation=i,this.dropDownPosition="bottom",this.mouseState$=new s.BehaviorSubject(!1),this.isChildSubMenuOpen$=this.nzMenuService.isChildSubMenuOpen$,this.descendantMenuItemClick$=this.nzMenuService.descendantMenuItemClick$,this.nzOverlayClassName=null,this.nzOverlayStyle={}}return e.prototype.setMouseState=function(e){this.mouseState$.next(e)},e.prototype.setValue=function(e,t){this[e]=t,this.cdr.markForCheck()},e.prototype.ngAfterContentInit=function(){this.renderer.removeChild(this.renderer.parentNode(this.elementRef.nativeElement),this.elementRef.nativeElement)},e.decorators=[{type:r.Component,args:[{selector:"nz-dropdown-menu",exportAs:"nzDropdownMenu",animations:[v.slideMotion],providers:[h.MenuService,{provide:h.NzIsMenuInsideDropDownToken,useValue:!0}],template:'\n <ng-template>\n <div\n class="ant-dropdown"\n [ngClass]="nzOverlayClassName"\n [ngStyle]="nzOverlayStyle"\n [@slideMotion]="dropDownPosition"\n [@.disabled]="noAnimation?.nzNoAnimation"\n [nzNoAnimation]="noAnimation?.nzNoAnimation"\n (mouseenter)="setMouseState(true)"\n (mouseleave)="setMouseState(false)"\n >\n <ng-content></ng-content>\n </div>\n </ng-template>\n ',preserveWhitespaces:!1,encapsulation:r.ViewEncapsulation.None,changeDetection:r.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[{type:r.ChangeDetectorRef},{type:r.ElementRef},{type:r.Renderer2},{type:r.ViewContainerRef},{type:h.MenuService},{type:d.NzNoAnimationDirective,decorators:[{type:r.Host},{type:r.Optional}]}]},e.propDecorators={templateRef:[{type:r.ViewChild,args:[r.TemplateRef,{static:!0}]}]},e}();var S=function(){function e(){}return e.decorators=[{type:r.NgModule,args:[{imports:[p.CommonModule,n.OverlayModule,u.FormsModule,c.NzButtonModule,h.NzMenuModule,f.NzIconModule,d.NzNoAnimationModule,i.NzOverlayModule,M,y.NzOutletModule],entryComponents:[D],declarations:[w,C,D,R],exports:[h.NzMenuModule,w,C,D,R]}]}],e}(),O=[new n.ConnectionPositionPair({originX:"start",originY:"top"},{overlayX:"start",overlayY:"top"}),new n.ConnectionPositionPair({originX:"start",originY:"top"},{overlayX:"start",overlayY:"bottom"}),new n.ConnectionPositionPair({originX:"start",originY:"top"},{overlayX:"end",overlayY:"bottom"}),new n.ConnectionPositionPair({originX:"start",originY:"top"},{overlayX:"end",overlayY:"top"})],k=function(){function e(e){this.overlay=e,this.overlayRef=null,this.closeSubscription=s.Subscription.EMPTY}return e.prototype.create=function(e,t){var n=this;this.close(!0);var r=e.x,i=e.y;e instanceof MouseEvent&&e.preventDefault();var a=this.overlay.position().flexibleConnectedTo({x:r,y:i}).withPositions(O);this.overlayRef=this.overlay.create({positionStrategy:a,disposeOnNavigation:!0,scrollStrategy:this.overlay.scrollStrategies.close()}),a.positionChanges.subscribe((function(e){t.setValue("dropDownPosition","bottom"===e.connectionPair.overlayY?"top":"bottom")})),this.closeSubscription=s.merge(t.descendantMenuItemClick$,s.fromEvent(document,"click").pipe(l.filter((function(e){return!!n.overlayRef&&!n.overlayRef.overlayElement.contains(e.target)})),l.filter((function(e){return 2!==e.button})),l.take(1))).subscribe((function(){n.close()})),this.overlayRef.attach(new o.TemplatePortal(t.templateRef,t.viewContainerRef))},e.prototype.close=function(e){void 0===e&&(e=!1),this.overlayRef&&(this.overlayRef.detach(),e&&this.overlayRef.dispose(),this.overlayRef=null,this.closeSubscription.unsubscribe())},e.decorators=[{type:r.Injectable,args:[{providedIn:M}]}],e.ctorParameters=function(){return[{type:n.Overlay}]},e.ɵprov=r.ɵɵdefineInjectable({factory:function(){return new e(r.ɵɵinject(n.Overlay))},token:e,providedIn:M}),e}();e.NzContextMenuService=k,e.NzContextMenuServiceModule=M,e.NzDropDownADirective=C,e.NzDropDownDirective=w,e.NzDropDownModule=S,e.NzDropdownButtonDirective=R,e.NzDropdownMenuComponent=D,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-zorro-antd-dropdown.umd.min.js.map