ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
447 lines (436 loc) • 20.8 kB
JavaScript
import { ComponentPortal } from '@angular/cdk/portal';
import * as i0 from '@angular/core';
import { Directive, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, NgModule, Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { filter, take, takeUntil } from 'rxjs/operators';
import * as i1 from 'ng-zorro-antd/core/config';
import { toCssPixel } from 'ng-zorro-antd/core/util';
import { moveUpMotion } from 'ng-zorro-antd/core/animation';
import * as i1$1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2 from 'ng-zorro-antd/icon';
import { NzIconModule } from 'ng-zorro-antd/icon';
import * as i3 from 'ng-zorro-antd/core/outlet';
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import * as i1$2 from 'ng-zorro-antd/core/services';
import * as i2$1 from '@angular/cdk/overlay';
import { OverlayModule } from '@angular/cdk/overlay';
import { BidiModule } from '@angular/cdk/bidi';
let globalCounter = 0;
class NzMNService {
constructor(nzSingletonService, overlay, injector) {
this.nzSingletonService = nzSingletonService;
this.overlay = overlay;
this.injector = injector;
}
remove(id) {
if (this.container) {
if (id) {
this.container.remove(id);
}
else {
this.container.removeAll();
}
}
}
getInstanceId() {
return `${this.componentPrefix}-${globalCounter++}`;
}
withContainer(ctor) {
let containerInstance = this.nzSingletonService.getSingletonWithKey(this.componentPrefix);
if (containerInstance) {
return containerInstance;
}
const overlayRef = this.overlay.create({
hasBackdrop: false,
scrollStrategy: this.overlay.scrollStrategies.noop(),
positionStrategy: this.overlay.position().global()
});
const componentPortal = new ComponentPortal(ctor, null, this.injector);
const componentRef = overlayRef.attach(componentPortal);
const overlayPane = overlayRef.overlayElement;
overlayPane.style.zIndex = '1010';
if (!containerInstance) {
this.container = containerInstance = componentRef.instance;
this.nzSingletonService.registerSingletonWithKey(this.componentPrefix, containerInstance);
}
return containerInstance;
}
}
class NzMNContainerComponent {
constructor(cdr, nzConfigService) {
this.cdr = cdr;
this.nzConfigService = nzConfigService;
this.instances = [];
this.destroy$ = new Subject();
this.updateConfig();
}
ngOnInit() {
this.subscribeConfigChange();
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
create(data) {
const instance = this.onCreate(data);
if (this.instances.length >= this.config.nzMaxStack) {
this.instances = this.instances.slice(1);
}
this.instances = [...this.instances, instance];
this.readyInstances();
return instance;
}
remove(id, userAction = false) {
this.instances.some((instance, index) => {
if (instance.messageId === id) {
this.instances.splice(index, 1);
this.instances = [...this.instances];
this.onRemove(instance, userAction);
this.readyInstances();
return true;
}
return false;
});
}
removeAll() {
this.instances.forEach(i => this.onRemove(i, false));
this.instances = [];
this.readyInstances();
}
onCreate(instance) {
instance.options = this.mergeOptions(instance.options);
instance.onClose = new Subject();
return instance;
}
onRemove(instance, userAction) {
instance.onClose.next(userAction);
instance.onClose.complete();
}
readyInstances() {
this.cdr.detectChanges();
}
mergeOptions(options) {
const { nzDuration, nzAnimate, nzPauseOnHover } = this.config;
return { nzDuration, nzAnimate, nzPauseOnHover, ...options };
}
}
NzMNContainerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMNContainerComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i1.NzConfigService }], target: i0.ɵɵFactoryTarget.Directive });
NzMNContainerComponent.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.5", type: NzMNContainerComponent, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMNContainerComponent, decorators: [{
type: Directive
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i1.NzConfigService }]; } });
class NzMNComponent {
constructor(cdr) {
this.cdr = cdr;
this.destroyed = new EventEmitter();
this.animationStateChanged = new Subject();
this.userAction = false;
this.eraseTimer = null;
}
ngOnInit() {
this.options = this.instance.options;
if (this.options.nzAnimate) {
this.instance.state = 'enter';
this.animationStateChanged
.pipe(filter(event => event.phaseName === 'done' && event.toState === 'leave'), take(1))
.subscribe(() => {
clearTimeout(this.closeTimer);
this.destroyed.next({ id: this.instance.messageId, userAction: this.userAction });
});
}
this.autoClose = this.options.nzDuration > 0;
if (this.autoClose) {
this.initErase();
this.startEraseTimeout();
}
}
ngOnDestroy() {
if (this.autoClose) {
this.clearEraseTimeout();
}
this.animationStateChanged.complete();
}
onEnter() {
if (this.autoClose && this.options.nzPauseOnHover) {
this.clearEraseTimeout();
this.updateTTL();
}
}
onLeave() {
if (this.autoClose && this.options.nzPauseOnHover) {
this.startEraseTimeout();
}
}
destroy(userAction = false) {
this.userAction = userAction;
if (this.options.nzAnimate) {
this.instance.state = 'leave';
this.cdr.detectChanges();
this.closeTimer = setTimeout(() => {
this.closeTimer = undefined;
this.destroyed.next({ id: this.instance.messageId, userAction });
}, 200);
}
else {
this.destroyed.next({ id: this.instance.messageId, userAction });
}
}
initErase() {
this.eraseTTL = this.options.nzDuration;
this.eraseTimingStart = Date.now();
}
updateTTL() {
if (this.autoClose) {
this.eraseTTL -= Date.now() - this.eraseTimingStart;
}
}
startEraseTimeout() {
if (this.eraseTTL > 0) {
this.clearEraseTimeout();
this.eraseTimer = setTimeout(() => this.destroy(), this.eraseTTL);
this.eraseTimingStart = Date.now();
}
else {
this.destroy();
}
}
clearEraseTimeout() {
if (this.eraseTimer !== null) {
clearTimeout(this.eraseTimer);
this.eraseTimer = null;
}
}
}
NzMNComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMNComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
NzMNComponent.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.5", type: NzMNComponent, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMNComponent, decorators: [{
type: Directive
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; } });
/**
* 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
*/
class NzMessageComponent extends NzMNComponent {
constructor(cdr) {
super(cdr);
this.destroyed = new EventEmitter();
}
}
NzMessageComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
NzMessageComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzMessageComponent, selector: "nz-message", inputs: { instance: "instance" }, outputs: { destroyed: "destroyed" }, exportAs: ["nzMessage"], usesInheritance: true, ngImport: i0, template: `
<div
class="ant-message-notice"
[ ]="instance.state"
( .done)="animationStateChanged.next($event)"
(mouseenter)="onEnter()"
(mouseleave)="onLeave()"
>
<div class="ant-message-notice-content">
<div class="ant-message-custom-content" [ngClass]="'ant-message-' + instance.type">
<ng-container [ngSwitch]="instance.type">
<i *ngSwitchCase="'success'" nz-icon nzType="check-circle"></i>
<i *ngSwitchCase="'info'" nz-icon nzType="info-circle"></i>
<i *ngSwitchCase="'warning'" nz-icon nzType="exclamation-circle"></i>
<i *ngSwitchCase="'error'" nz-icon nzType="close-circle"></i>
<i *ngSwitchCase="'loading'" nz-icon nzType="loading"></i>
</ng-container>
<ng-container *nzStringTemplateOutlet="instance.content">
<span [innerHTML]="instance.content"></span>
</ng-container>
</div>
</div>
</div>
`, isInline: true, directives: [{ type: i1$1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1$1.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { type: i1$1.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { type: i2.NzIconDirective, selector: "[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { type: i3.NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }], animations: [moveUpMotion], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageComponent, decorators: [{
type: Component,
args: [{
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
selector: 'nz-message',
exportAs: 'nzMessage',
preserveWhitespaces: false,
animations: [moveUpMotion],
template: `
<div
class="ant-message-notice"
[ ]="instance.state"
( .done)="animationStateChanged.next($event)"
(mouseenter)="onEnter()"
(mouseleave)="onLeave()"
>
<div class="ant-message-notice-content">
<div class="ant-message-custom-content" [ngClass]="'ant-message-' + instance.type">
<ng-container [ngSwitch]="instance.type">
<i *ngSwitchCase="'success'" nz-icon nzType="check-circle"></i>
<i *ngSwitchCase="'info'" nz-icon nzType="info-circle"></i>
<i *ngSwitchCase="'warning'" nz-icon nzType="exclamation-circle"></i>
<i *ngSwitchCase="'error'" nz-icon nzType="close-circle"></i>
<i *ngSwitchCase="'loading'" nz-icon nzType="loading"></i>
</ng-container>
<ng-container *nzStringTemplateOutlet="instance.content">
<span [innerHTML]="instance.content"></span>
</ng-container>
</div>
</div>
</div>
`
}]
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { instance: [{
type: Input
}], destroyed: [{
type: Output
}] } });
const NZ_CONFIG_COMPONENT_NAME = 'message';
const NZ_MESSAGE_DEFAULT_CONFIG = {
nzAnimate: true,
nzDuration: 3000,
nzMaxStack: 7,
nzPauseOnHover: true,
nzTop: 24,
nzDirection: 'ltr'
};
class NzMessageContainerComponent extends NzMNContainerComponent {
constructor(cdr, nzConfigService) {
super(cdr, nzConfigService);
this.dir = 'ltr';
const config = this.nzConfigService.getConfigForComponent(NZ_CONFIG_COMPONENT_NAME);
this.dir = config?.nzDirection || 'ltr';
}
subscribeConfigChange() {
this.nzConfigService
.getConfigChangeEventForComponent(NZ_CONFIG_COMPONENT_NAME)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.updateConfig();
const config = this.nzConfigService.getConfigForComponent(NZ_CONFIG_COMPONENT_NAME);
if (config) {
const { nzDirection } = config;
this.dir = nzDirection || this.dir;
}
});
}
updateConfig() {
this.config = {
...NZ_MESSAGE_DEFAULT_CONFIG,
...this.config,
...this.nzConfigService.getConfigForComponent(NZ_CONFIG_COMPONENT_NAME)
};
this.top = toCssPixel(this.config.nzTop);
this.cdr.markForCheck();
}
}
NzMessageContainerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageContainerComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i1.NzConfigService }], target: i0.ɵɵFactoryTarget.Component });
NzMessageContainerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzMessageContainerComponent, selector: "nz-message-container", exportAs: ["nzMessageContainer"], usesInheritance: true, ngImport: i0, template: `
<div class="ant-message" [class.ant-message-rtl]="dir === 'rtl'" [style.top]="top">
<nz-message
*ngFor="let instance of instances"
[instance]="instance"
(destroyed)="remove($event.id, $event.userAction)"
></nz-message>
</div>
`, isInline: true, components: [{ type: NzMessageComponent, selector: "nz-message", inputs: ["instance"], outputs: ["destroyed"], exportAs: ["nzMessage"] }], directives: [{ type: i1$1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageContainerComponent, decorators: [{
type: Component,
args: [{
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
selector: 'nz-message-container',
exportAs: 'nzMessageContainer',
preserveWhitespaces: false,
template: `
<div class="ant-message" [class.ant-message-rtl]="dir === 'rtl'" [style.top]="top">
<nz-message
*ngFor="let instance of instances"
[instance]="instance"
(destroyed)="remove($event.id, $event.userAction)"
></nz-message>
</div>
`
}]
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i1.NzConfigService }]; } });
/**
* 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
*/
class NzMessageServiceModule {
}
NzMessageServiceModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageServiceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
NzMessageServiceModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageServiceModule });
NzMessageServiceModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageServiceModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageServiceModule, decorators: [{
type: NgModule
}] });
class NzMessageService extends NzMNService {
constructor(nzSingletonService, overlay, injector) {
super(nzSingletonService, overlay, injector);
this.componentPrefix = 'message-';
}
success(content, options) {
return this.createInstance({ type: 'success', content }, options);
}
error(content, options) {
return this.createInstance({ type: 'error', content }, options);
}
info(content, options) {
return this.createInstance({ type: 'info', content }, options);
}
warning(content, options) {
return this.createInstance({ type: 'warning', content }, options);
}
loading(content, options) {
return this.createInstance({ type: 'loading', content }, options);
}
create(type, content, options) {
return this.createInstance({ type, content }, options);
}
createInstance(message, options) {
this.container = this.withContainer(NzMessageContainerComponent);
return this.container.create({
...message,
...{
createdAt: new Date(),
messageId: this.getInstanceId(),
options
}
});
}
}
NzMessageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageService, deps: [{ token: i1$2.NzSingletonService }, { token: i2$1.Overlay }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
NzMessageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageService, providedIn: NzMessageServiceModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageService, decorators: [{
type: Injectable,
args: [{
providedIn: NzMessageServiceModule
}]
}], ctorParameters: function () { return [{ type: i1$2.NzSingletonService }, { type: i2$1.Overlay }, { type: i0.Injector }]; } });
/**
* 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
*/
class NzMessageModule {
}
NzMessageModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
NzMessageModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageModule, declarations: [NzMessageContainerComponent, NzMessageComponent], imports: [BidiModule, CommonModule, OverlayModule, NzIconModule, NzOutletModule, NzMessageServiceModule] });
NzMessageModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageModule, imports: [[BidiModule, CommonModule, OverlayModule, NzIconModule, NzOutletModule, NzMessageServiceModule]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzMessageModule, decorators: [{
type: NgModule,
args: [{
imports: [BidiModule, CommonModule, OverlayModule, NzIconModule, NzOutletModule, NzMessageServiceModule],
declarations: [NzMessageContainerComponent, NzMessageComponent],
entryComponents: [NzMessageContainerComponent]
}]
}] });
/**
* 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
*/
/**
* 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
*/
/**
* Generated bundle index. Do not edit.
*/
export { NzMNComponent, NzMNContainerComponent, NzMNService, NzMessageComponent, NzMessageContainerComponent, NzMessageModule, NzMessageService, NzMessageServiceModule };
//# sourceMappingURL=ng-zorro-antd-message.mjs.map