ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
16 lines (14 loc) • 16.3 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/cdk/a11y"),require("@angular/cdk/keycodes"),require("@angular/cdk/overlay"),require("@angular/cdk/portal"),require("@angular/common"),require("@angular/core"),require("ng-zorro-antd/core/config"),require("ng-zorro-antd/core/util"),require("rxjs"),require("rxjs/operators"),require("ng-zorro-antd/core/no-animation"),require("ng-zorro-antd/core/outlet"),require("ng-zorro-antd/icon")):"function"==typeof define&&define.amd?define("ng-zorro-antd/drawer",["exports","@angular/cdk/a11y","@angular/cdk/keycodes","@angular/cdk/overlay","@angular/cdk/portal","@angular/common","@angular/core","ng-zorro-antd/core/config","ng-zorro-antd/core/util","rxjs","rxjs/operators","ng-zorro-antd/core/no-animation","ng-zorro-antd/core/outlet","ng-zorro-antd/icon"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["ng-zorro-antd"]=e["ng-zorro-antd"]||{},e["ng-zorro-antd"].drawer={}),e.ng.cdk.a11y,e.ng.cdk.keycodes,e.ng.cdk.overlay,e.ng.cdk.portal,e.ng.common,e.ng.core,e["ng-zorro-antd"].core.config,e["ng-zorro-antd"].core.util,e.rxjs,e.rxjs.operators,e["ng-zorro-antd"].core["no-animation"],e["ng-zorro-antd"].core.outlet,e["ng-zorro-antd"].icon)}(this,(function(e,t,n,o,r,a,i,s,l,c,p,u,f,y){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var d=function(e,t){return(d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function h(e,t,n,o){var r,a=arguments.length,i=a<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,o);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(i=(a<3?r(i):a>3?r(t,n,i):r(t,n))||i);return a>3&&i&&Object.defineProperty(t,n,i),i}function g(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}Object.create;Object.create;var m=function(){},v=function(e){function t(t,n,o,r,a,s,l,p,u){var f=e.call(this)||this;return f.document=t,f.nzConfigService=n,f.renderer=o,f.overlay=r,f.injector=a,f.changeDetectorRef=s,f.focusTrapFactory=l,f.viewContainerRef=p,f.overlayKeyboardDispatcher=u,f._nzModuleName="drawer",f.nzCloseIcon="close",f.nzClosable=!0,f.nzMaskClosable=!0,f.nzMask=!0,f.nzCloseOnNavigation=!0,f.nzNoAnimation=!1,f.nzKeyboard=!0,f.nzPlacement="right",f.nzMaskStyle={},f.nzBodyStyle={},f.nzWidth=256,f.nzHeight=256,f.nzZIndex=1e3,f.nzOffsetX=0,f.nzOffsetY=0,f.componentInstance=null,f.nzOnViewInit=new i.EventEmitter,f.nzOnClose=new i.EventEmitter,f.destroy$=new c.Subject,f.placementChanging=!1,f.placementChangeTimeoutId=-1,f.isOpen=!1,f.templateContext={$implicit:void 0,drawerRef:f},f.nzAfterOpen=new c.Subject,f.nzAfterClose=new c.Subject,f}return function(e,t){function n(){this.constructor=e}d(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),Object.defineProperty(t.prototype,"nzVisible",{get:function(){return this.isOpen},set:function(e){this.isOpen=e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"offsetTransform",{get:function(){if(!this.isOpen||this.nzOffsetX+this.nzOffsetY===0)return null;switch(this.nzPlacement){case"left":return"translateX("+this.nzOffsetX+"px)";case"right":return"translateX(-"+this.nzOffsetX+"px)";case"top":return"translateY("+this.nzOffsetY+"px)";case"bottom":return"translateY(-"+this.nzOffsetY+"px)"}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transform",{get:function(){if(this.isOpen)return null;switch(this.nzPlacement){case"left":return"translateX(-100%)";case"right":return"translateX(100%)";case"top":return"translateY(-100%)";case"bottom":return"translateY(100%)"}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this.isLeftOrRight?l.toCssPixel(this.nzWidth):null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this.isLeftOrRight?null:l.toCssPixel(this.nzHeight)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isLeftOrRight",{get:function(){return"left"===this.nzPlacement||"right"===this.nzPlacement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"afterOpen",{get:function(){return this.nzAfterOpen.asObservable()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"afterClose",{get:function(){return this.nzAfterClose.asObservable()},enumerable:!1,configurable:!0}),t.prototype.isTemplateRef=function(e){return e instanceof i.TemplateRef},t.prototype.ngOnInit=function(){this.attachOverlay(),this.updateOverlayStyle(),this.updateBodyOverflow(),this.templateContext={$implicit:this.nzContentParams,drawerRef:this},this.changeDetectorRef.detectChanges()},t.prototype.ngAfterViewInit=function(){var e=this;this.attachBodyContent(),setTimeout((function(){e.nzOnViewInit.emit()}))},t.prototype.ngOnChanges=function(e){var t=e.nzPlacement;e.nzVisible&&(e.nzVisible.currentValue?this.open():this.close());t&&!t.isFirstChange()&&this.triggerPlacementChangeCycleOnce()},t.prototype.ngOnDestroy=function(){this.destroy$.next(),this.destroy$.complete(),clearTimeout(this.placementChangeTimeoutId),this.disposeOverlay()},t.prototype.getAnimationDuration=function(){return this.nzNoAnimation?0:300},t.prototype.triggerPlacementChangeCycleOnce=function(){var e=this;this.nzNoAnimation||(this.placementChanging=!0,this.changeDetectorRef.markForCheck(),clearTimeout(this.placementChangeTimeoutId),this.placementChangeTimeoutId=setTimeout((function(){e.placementChanging=!1,e.changeDetectorRef.markForCheck()}),this.getAnimationDuration()))},t.prototype.close=function(e){var t=this;this.isOpen=!1,this.updateOverlayStyle(),this.overlayKeyboardDispatcher.remove(this.overlayRef),this.changeDetectorRef.detectChanges(),setTimeout((function(){t.updateBodyOverflow(),t.restoreFocus(),t.nzAfterClose.next(e),t.nzAfterClose.complete(),t.componentInstance=null}),this.getAnimationDuration())},t.prototype.open=function(){var e=this;this.attachOverlay(),this.isOpen=!0,this.overlayKeyboardDispatcher.add(this.overlayRef),this.updateOverlayStyle(),this.updateBodyOverflow(),this.savePreviouslyFocusedElement(),this.trapFocus(),this.changeDetectorRef.detectChanges(),setTimeout((function(){e.nzAfterOpen.next()}),this.getAnimationDuration())},t.prototype.getContentComponent=function(){return this.componentInstance},t.prototype.closeClick=function(){this.nzOnClose.emit()},t.prototype.maskClick=function(){this.nzMaskClosable&&this.nzMask&&this.nzOnClose.emit()},t.prototype.attachBodyContent=function(){if(this.bodyPortalOutlet.dispose(),this.nzContent instanceof i.Type){var e=i.Injector.create({parent:this.injector,providers:[{provide:m,useValue:this}]}),t=new r.ComponentPortal(this.nzContent,null,e),n=this.bodyPortalOutlet.attachComponentPortal(t);this.componentInstance=n.instance,Object.assign(n.instance,this.nzContentParams),n.changeDetectorRef.detectChanges()}},t.prototype.attachOverlay=function(){var e=this;this.overlayRef||(this.portal=new r.TemplatePortal(this.drawerTemplate,this.viewContainerRef),this.overlayRef=this.overlay.create(this.getOverlayConfig())),this.overlayRef&&!this.overlayRef.hasAttached()&&(this.overlayRef.attach(this.portal),this.overlayRef.keydownEvents().pipe(p.takeUntil(this.destroy$)).subscribe((function(t){t.keyCode===n.ESCAPE&&e.isOpen&&e.nzKeyboard&&e.nzOnClose.emit()})),this.overlayRef.detachments().pipe(p.takeUntil(this.destroy$)).subscribe((function(){e.disposeOverlay()})))},t.prototype.disposeOverlay=function(){var e;null===(e=this.overlayRef)||void 0===e||e.dispose(),this.overlayRef=null},t.prototype.getOverlayConfig=function(){return new o.OverlayConfig({disposeOnNavigation:this.nzCloseOnNavigation,positionStrategy:this.overlay.position().global(),scrollStrategy:this.overlay.scrollStrategies.block()})},t.prototype.updateOverlayStyle=function(){this.overlayRef&&this.overlayRef.overlayElement&&this.renderer.setStyle(this.overlayRef.overlayElement,"pointer-events",this.isOpen?"auto":"none")},t.prototype.updateBodyOverflow=function(){this.overlayRef&&(this.isOpen?this.overlayRef.getConfig().scrollStrategy.enable():this.overlayRef.getConfig().scrollStrategy.disable())},t.prototype.savePreviouslyFocusedElement=function(){this.document&&!this.previouslyFocusedElement&&(this.previouslyFocusedElement=this.document.activeElement,this.previouslyFocusedElement&&"function"==typeof this.previouslyFocusedElement.blur&&this.previouslyFocusedElement.blur())},t.prototype.trapFocus=function(){!this.focusTrap&&this.overlayRef&&this.overlayRef.overlayElement&&(this.focusTrap=this.focusTrapFactory.create(this.overlayRef.overlayElement),this.focusTrap.focusInitialElement())},t.prototype.restoreFocus=function(){this.previouslyFocusedElement&&"function"==typeof this.previouslyFocusedElement.focus&&this.previouslyFocusedElement.focus(),this.focusTrap&&this.focusTrap.destroy()},t}(m);v.decorators=[{type:i.Component,args:[{selector:"nz-drawer",exportAs:"nzDrawer",template:'\n <ng-template #drawerTemplate>\n <div\n class="ant-drawer"\n [nzNoAnimation]="nzNoAnimation"\n [class.ant-drawer-open]="isOpen"\n [class.no-mask]="!nzMask"\n [class.ant-drawer-top]="nzPlacement === \'top\'"\n [class.ant-drawer-bottom]="nzPlacement === \'bottom\'"\n [class.ant-drawer-right]="nzPlacement === \'right\'"\n [class.ant-drawer-left]="nzPlacement === \'left\'"\n [style.transform]="offsetTransform"\n [style.transition]="placementChanging ? \'none\' : null"\n [style.zIndex]="nzZIndex"\n >\n <div class="ant-drawer-mask" (click)="maskClick()" *ngIf="nzMask" [ngStyle]="nzMaskStyle"></div>\n <div\n class="ant-drawer-content-wrapper {{ nzWrapClassName }}"\n [style.width]="width"\n [style.height]="height"\n [style.transform]="transform"\n [style.transition]="placementChanging ? \'none\' : null"\n >\n <div class="ant-drawer-content">\n <div class="ant-drawer-wrapper-body" [style.height]="isLeftOrRight ? \'100%\' : null">\n <div *ngIf="nzTitle || nzClosable" [class.ant-drawer-header]="!!nzTitle" [class.ant-drawer-header-no-title]="!nzTitle">\n <div *ngIf="nzTitle" class="ant-drawer-title">\n <ng-container *nzStringTemplateOutlet="nzTitle"><div [innerHTML]="nzTitle"></div></ng-container>\n </div>\n <button *ngIf="nzClosable" (click)="closeClick()" aria-label="Close" class="ant-drawer-close" style="--scroll-bar: 0px;">\n <ng-container *nzStringTemplateOutlet="nzCloseIcon; let closeIcon">\n <i nz-icon [nzType]="closeIcon"></i>\n </ng-container>\n </button>\n </div>\n <div class="ant-drawer-body" [ngStyle]="nzBodyStyle">\n <ng-template cdkPortalOutlet></ng-template>\n <ng-container *ngIf="isTemplateRef(nzContent)">\n <ng-container *ngTemplateOutlet="$any(nzContent); context: templateContext"></ng-container>\n </ng-container>\n <ng-content *ngIf="!nzContent"></ng-content>\n </div>\n <div *ngIf="nzFooter" class="ant-drawer-footer">\n <ng-container *nzStringTemplateOutlet="nzFooter"><div [innerHTML]="nzFooter"></div></ng-container>\n </div>\n </div>\n </div>\n </div>\n </div>\n </ng-template>\n ',preserveWhitespaces:!1,changeDetection:i.ChangeDetectionStrategy.OnPush}]}],v.ctorParameters=function(){return[{type:void 0,decorators:[{type:i.Optional},{type:i.Inject,args:[a.DOCUMENT]}]},{type:s.NzConfigService},{type:i.Renderer2},{type:o.Overlay},{type:i.Injector},{type:i.ChangeDetectorRef},{type:t.FocusTrapFactory},{type:i.ViewContainerRef},{type:o.OverlayKeyboardDispatcher}]},v.propDecorators={nzContent:[{type:i.Input}],nzCloseIcon:[{type:i.Input}],nzClosable:[{type:i.Input}],nzMaskClosable:[{type:i.Input}],nzMask:[{type:i.Input}],nzCloseOnNavigation:[{type:i.Input}],nzNoAnimation:[{type:i.Input}],nzKeyboard:[{type:i.Input}],nzTitle:[{type:i.Input}],nzFooter:[{type:i.Input}],nzPlacement:[{type:i.Input}],nzMaskStyle:[{type:i.Input}],nzBodyStyle:[{type:i.Input}],nzWrapClassName:[{type:i.Input}],nzWidth:[{type:i.Input}],nzHeight:[{type:i.Input}],nzZIndex:[{type:i.Input}],nzOffsetX:[{type:i.Input}],nzOffsetY:[{type:i.Input}],nzVisible:[{type:i.Input}],nzOnViewInit:[{type:i.Output}],nzOnClose:[{type:i.Output}],drawerTemplate:[{type:i.ViewChild,args:["drawerTemplate",{static:!0}]}],bodyPortalOutlet:[{type:i.ViewChild,args:[r.CdkPortalOutlet,{static:!1}]}]},h([l.InputBoolean(),g("design:type",Boolean)],v.prototype,"nzClosable",void 0),h([s.WithConfig(),l.InputBoolean(),g("design:type",Boolean)],v.prototype,"nzMaskClosable",void 0),h([s.WithConfig(),l.InputBoolean(),g("design:type",Boolean)],v.prototype,"nzMask",void 0),h([s.WithConfig(),l.InputBoolean(),g("design:type",Boolean)],v.prototype,"nzCloseOnNavigation",void 0),h([l.InputBoolean(),g("design:type",Object)],v.prototype,"nzNoAnimation",void 0),h([l.InputBoolean(),g("design:type",Boolean)],v.prototype,"nzKeyboard",void 0);var z=function(){};z.decorators=[{type:i.NgModule}];var O=function(){};O.decorators=[{type:i.NgModule,args:[{imports:[a.CommonModule,o.OverlayModule,r.PortalModule,y.NzIconModule,f.NzOutletModule,u.NzNoAnimationModule,z],exports:[v],declarations:[v],entryComponents:[v]}]}];var b=function(){function e(e,t){var n=this;this.overlay=e,this.options=t,this.unsubscribe$=new c.Subject;var o=this.options,a=o.nzOnCancel,i=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}(o,["nzOnCancel"]);this.overlayRef=this.overlay.create(),this.drawerRef=this.overlayRef.attach(new r.ComponentPortal(v)).instance,this.updateOptions(i),this.drawerRef.savePreviouslyFocusedElement(),this.drawerRef.nzOnViewInit.pipe(p.takeUntil(this.unsubscribe$)).subscribe((function(){n.drawerRef.open()})),this.drawerRef.nzOnClose.subscribe((function(){a?a().then((function(e){!1!==e&&n.drawerRef.close()})):n.drawerRef.close()})),this.drawerRef.afterClose.pipe(p.takeUntil(this.unsubscribe$)).subscribe((function(){n.overlayRef.dispose(),n.drawerRef=null,n.unsubscribe$.next(),n.unsubscribe$.complete()}))}return e.prototype.getInstance=function(){return this.drawerRef},e.prototype.updateOptions=function(e){Object.assign(this.drawerRef,e)},e}(),C=function(){function e(e){this.overlay=e}return e.prototype.create=function(e){return new b(this.overlay,e).getInstance()},e}();C.ɵprov=i.ɵɵdefineInjectable({factory:function(){return new C(i.ɵɵinject(o.Overlay))},token:C,providedIn:z}),C.decorators=[{type:i.Injectable,args:[{providedIn:z}]}],C.ctorParameters=function(){return[{type:o.Overlay}]},e.DRAWER_ANIMATE_DURATION=300,e.DrawerBuilderForService=b,e.NzDrawerComponent=v,e.NzDrawerModule=O,e.NzDrawerRef=m,e.NzDrawerService=C,e.NzDrawerServiceModule=z,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-zorro-antd-drawer.umd.min.js.map