ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
23 lines (21 loc) • 11 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/cdk/portal"),require("@angular/core"),require("rxjs"),require("@angular/cdk/overlay"),require("ng-zorro-antd/core/services"),require("ng-zorro-antd/core/config"),require("ng-zorro-antd/core/util"),require("rxjs/operators"),require("@angular/common"),require("ng-zorro-antd/core/outlet"),require("ng-zorro-antd/icon"),require("ng-zorro-antd/core/animation")):"function"==typeof define&&define.amd?define("ng-zorro-antd/message",["exports","@angular/cdk/portal","@angular/core","rxjs","@angular/cdk/overlay","ng-zorro-antd/core/services","ng-zorro-antd/core/config","ng-zorro-antd/core/util","rxjs/operators","@angular/common","ng-zorro-antd/core/outlet","ng-zorro-antd/icon","ng-zorro-antd/core/animation"],t):t(((e=e||self)["ng-zorro-antd"]=e["ng-zorro-antd"]||{},e["ng-zorro-antd"].message={}),e.ng.cdk.portal,e.ng.core,e.rxjs,e.ng.cdk.overlay,e["ng-zorro-antd"].core.services,e["ng-zorro-antd"].core.config,e["ng-zorro-antd"].core.util,e.rxjs.operators,e.ng.common,e["ng-zorro-antd"].core.outlet,e["ng-zorro-antd"].icon,e["ng-zorro-antd"].core.animation)}(this,(function(e,t,n,o,r,i,s,a,c,u,p,h,g){"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 l=function(e,t){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function f(e,t){function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var d=function(){return(d=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function y(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)s.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 s}function m(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(y(arguments[t]));return e}var v=0,z=function(){function e(e,t,n){this.nzSingletonService=e,this.overlay=t,this.injector=n}return e.prototype.remove=function(e){this.container&&(e?this.container.remove(e):this.container.removeAll())},e.prototype.getInstanceId=function(){return this.componentPrefix+"-"+v++},e.prototype.withContainer=function(e){var n=this.nzSingletonService.getSingletonWithKey(this.componentPrefix);if(n)return n;var o=this.overlay.create({hasBackdrop:!1,scrollStrategy:this.overlay.scrollStrategies.noop(),positionStrategy:this.overlay.position().global()}),r=new t.ComponentPortal(e,null,this.injector),i=o.attach(r);return o.overlayElement.style.zIndex="1010",n||(this.container=n=i.instance,this.nzSingletonService.registerSingletonWithKey(this.componentPrefix,n)),n},e}();var C=function(){function e(e,t){this.cdr=e,this.nzConfigService=t,this.instances=[],this.destroy$=new o.Subject,this.updateConfig()}return e.prototype.ngOnInit=function(){this.subscribeConfigChange()},e.prototype.ngOnDestroy=function(){this.destroy$.next(),this.destroy$.complete()},e.prototype.create=function(e){var t=this.onCreate(e);return this.instances.length>=this.config.nzMaxStack&&(this.instances=this.instances.slice(1)),this.instances=m(this.instances,[t]),this.readyInstances(),t},e.prototype.remove=function(e,t){var n=this;void 0===t&&(t=!1),this.instances.some((function(o,r){return o.messageId===e&&(n.instances.splice(r,1),n.instances=m(n.instances),n.onRemove(o,t),n.readyInstances(),!0)}))},e.prototype.removeAll=function(){var e=this;this.instances.forEach((function(t){return e.onRemove(t,!1)})),this.instances=[],this.readyInstances()},e.prototype.onCreate=function(e){return e.options=this.mergeOptions(e.options),e.onClose=new o.Subject,e},e.prototype.onRemove=function(e,t){e.onClose.next(t),e.onClose.complete()},e.prototype.readyInstances=function(){this.cdr.detectChanges()},e.prototype.mergeOptions=function(e){var t=this.config,n=t.nzDuration,o=t.nzAnimate,r=t.nzPauseOnHover;return d({nzDuration:n,nzAnimate:o,nzPauseOnHover:r},e)},e}();var S=function(){function e(e){this.cdr=e,this.destroyed=new n.EventEmitter,this.eraseTimer=null}return e.prototype.ngOnInit=function(){this.options=this.instance.options,this.options.nzAnimate&&(this.instance.state="enter"),this.autoClose=this.options.nzDuration>0,this.autoClose&&(this.initErase(),this.startEraseTimeout())},e.prototype.ngOnDestroy=function(){this.autoClose&&this.clearEraseTimeout()},e.prototype.onEnter=function(){this.autoClose&&this.options.nzPauseOnHover&&(this.clearEraseTimeout(),this.updateTTL())},e.prototype.onLeave=function(){this.autoClose&&this.options.nzPauseOnHover&&this.startEraseTimeout()},e.prototype.destroy=function(e){var t=this;void 0===e&&(e=!1),this.options.nzAnimate?(this.instance.state="leave",this.cdr.detectChanges(),setTimeout((function(){t.destroyed.next({id:t.instance.messageId,userAction:e})}),200)):this.destroyed.next({id:this.instance.messageId,userAction:e})},e.prototype.initErase=function(){this.eraseTTL=this.options.nzDuration,this.eraseTimingStart=Date.now()},e.prototype.updateTTL=function(){this.autoClose&&(this.eraseTTL-=Date.now()-this.eraseTimingStart)},e.prototype.startEraseTimeout=function(){var e=this;this.eraseTTL>0?(this.clearEraseTimeout(),this.eraseTimer=setTimeout((function(){return e.destroy()}),this.eraseTTL),this.eraseTimingStart=Date.now()):this.destroy()},e.prototype.clearEraseTimeout=function(){null!==this.eraseTimer&&(clearTimeout(this.eraseTimer),this.eraseTimer=null)},e}();var T={nzAnimate:!0,nzDuration:3e3,nzMaxStack:7,nzPauseOnHover:!0,nzTop:24},I=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.destroy$=new o.Subject,r.instances=[],r}return f(t,e),t.prototype.subscribeConfigChange=function(){var e=this;this.nzConfigService.getConfigChangeEventForComponent("message").pipe(c.takeUntil(this.destroy$)).subscribe((function(){return e.updateConfig()}))},t.prototype.updateConfig=function(){this.config=d(d(d({},T),this.config),this.nzConfigService.getConfigForComponent("message")),this.top=a.toCssPixel(this.config.nzTop),this.cdr.markForCheck()},t.decorators=[{type:n.Component,args:[{changeDetection:n.ChangeDetectionStrategy.OnPush,encapsulation:n.ViewEncapsulation.None,selector:"nz-message-container",exportAs:"nzMessageContainer",preserveWhitespaces:!1,template:'\n <div class="ant-message" [style.top]="top">\n <nz-message *ngFor="let instance of instances" [instance]="instance" (destroyed)="remove($event.id, $event.userAction)"></nz-message>\n </div>\n '}]}],t.ctorParameters=function(){return[{type:n.ChangeDetectorRef},{type:s.NzConfigService}]},t}(C);var w=function(){function e(){}return e.decorators=[{type:n.NgModule}],e}(),O=function(e){function t(t,n,o){var r=e.call(this,t,n,o)||this;return r.componentPrefix="message-",r}return f(t,e),t.prototype.success=function(e,t){return this.createInstance({type:"success",content:e},t)},t.prototype.error=function(e,t){return this.createInstance({type:"error",content:e},t)},t.prototype.info=function(e,t){return this.createInstance({type:"info",content:e},t)},t.prototype.warning=function(e,t){return this.createInstance({type:"warning",content:e},t)},t.prototype.loading=function(e,t){return this.createInstance({type:"loading",content:e},t)},t.prototype.create=function(e,t,n){return this.createInstance({type:e,content:t},n)},t.prototype.createInstance=function(e,t){return this.container=this.withContainer(I),this.container.create(d(d({},e),{createdAt:new Date,messageId:this.getInstanceId(),options:t}))},t.decorators=[{type:n.Injectable,args:[{providedIn:w}]}],t.ctorParameters=function(){return[{type:i.NzSingletonService},{type:r.Overlay},{type:n.Injector}]},t.ɵprov=n.ɵɵdefineInjectable({factory:function(){return new t(n.ɵɵinject(i.NzSingletonService),n.ɵɵinject(r.Overlay),n.ɵɵinject(n.INJECTOR))},token:t,providedIn:w}),t}(z);var x=function(e){function t(t){var o=e.call(this,t)||this;return o.destroyed=new n.EventEmitter,o}return f(t,e),t.decorators=[{type:n.Component,args:[{changeDetection:n.ChangeDetectionStrategy.OnPush,encapsulation:n.ViewEncapsulation.None,selector:"nz-message",exportAs:"nzMessage",preserveWhitespaces:!1,animations:[g.moveUpMotion],template:'\n <div class="ant-message-notice" [@moveUpMotion]="instance.state" (mouseenter)="onEnter()" (mouseleave)="onLeave()">\n <div class="ant-message-notice-content">\n <div class="ant-message-custom-content" [ngClass]="\'ant-message-\' + instance.type">\n <ng-container [ngSwitch]="instance.type">\n <i *ngSwitchCase="\'success\'" nz-icon nzType="check-circle"></i>\n <i *ngSwitchCase="\'info\'" nz-icon nzType="info-circle"></i>\n <i *ngSwitchCase="\'warning\'" nz-icon nzType="exclamation-circle"></i>\n <i *ngSwitchCase="\'error\'" nz-icon nzType="close-circle"></i>\n <i *ngSwitchCase="\'loading\'" nz-icon nzType="loading"></i>\n </ng-container>\n <ng-container *nzStringTemplateOutlet="instance.content">\n <span [innerHTML]="instance.content"></span>\n </ng-container>\n </div>\n </div>\n </div>\n '}]}],t.ctorParameters=function(){return[{type:n.ChangeDetectorRef}]},t.propDecorators={instance:[{type:n.Input}],destroyed:[{type:n.Output}]},t}(S);var M=function(){function e(){}return e.decorators=[{type:n.NgModule,args:[{imports:[u.CommonModule,r.OverlayModule,h.NzIconModule,p.NzOutletModule,w],declarations:[I,x],entryComponents:[I]}]}],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
*/e.NzMNComponent=S,e.NzMNContainerComponent=C,e.NzMNService=z,e.NzMessageComponent=x,e.NzMessageContainerComponent=I,e.NzMessageModule=M,e.NzMessageService=O,e.NzMessageServiceModule=w,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-zorro-antd-message.umd.min.js.map