ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
596 lines (575 loc) • 22.3 kB
JavaScript
import { Component, ChangeDetectionStrategy, Input, TemplateRef, ViewEncapsulation, ElementRef, Renderer2, ContentChild, ViewChild, NgZone, ChangeDetectorRef, ContentChildren, Directive, Optional, HostBinding, NgModule } from '@angular/core';
import { __decorate, __metadata } from 'tslib';
import { InputBoolean } from 'ng-zorro-antd/core/util';
import { Subject, defer, of, merge, BehaviorSubject } from 'rxjs';
import { take, switchMap, takeUntil } from 'rxjs/operators';
import { Directionality, BidiModule } from '@angular/cdk/bidi';
import { CommonModule } from '@angular/common';
import { NzAvatarModule } from 'ng-zorro-antd/avatar';
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import { NzEmptyModule } from 'ng-zorro-antd/empty';
import { NzGridModule } from 'ng-zorro-antd/grid';
import { NzSpinModule } from 'ng-zorro-antd/spin';
/**
* 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
*/
class NzListItemMetaTitleComponent {
}
NzListItemMetaTitleComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-item-meta-title',
exportAs: 'nzListItemMetaTitle',
template: `
<h4 class="ant-list-item-meta-title">
<ng-content></ng-content>
</h4>
`,
changeDetection: ChangeDetectionStrategy.OnPush
},] }
];
class NzListItemMetaDescriptionComponent {
}
NzListItemMetaDescriptionComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-item-meta-description',
exportAs: 'nzListItemMetaDescription',
template: `
<div class="ant-list-item-meta-description">
<ng-content></ng-content>
</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush
},] }
];
class NzListItemMetaAvatarComponent {
}
NzListItemMetaAvatarComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-item-meta-avatar',
exportAs: 'nzListItemMetaAvatar',
template: `
<div class="ant-list-item-meta-avatar">
<nz-avatar *ngIf="nzSrc" [nzSrc]="nzSrc"></nz-avatar>
<ng-content *ngIf="!nzSrc"></ng-content>
</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush
},] }
];
NzListItemMetaAvatarComponent.propDecorators = {
nzSrc: [{ type: Input }]
};
/**
* 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 NzListItemMetaComponent {
constructor(elementRef, renderer) {
this.elementRef = elementRef;
this.renderer = renderer;
this.avatarStr = '';
this.renderer.addClass(elementRef.nativeElement, 'ant-list-item-meta');
}
set nzAvatar(value) {
if (value instanceof TemplateRef) {
this.avatarStr = '';
this.avatarTpl = value;
}
else {
this.avatarStr = value;
}
}
}
NzListItemMetaComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-item-meta, [nz-list-item-meta]',
exportAs: 'nzListItemMeta',
template: `
<!--Old API Start-->
<nz-list-item-meta-avatar *ngIf="avatarStr" [nzSrc]="avatarStr"></nz-list-item-meta-avatar>
<nz-list-item-meta-avatar *ngIf="avatarTpl">
<ng-container [ngTemplateOutlet]="avatarTpl"></ng-container>
</nz-list-item-meta-avatar>
<!--Old API End-->
<ng-content select="nz-list-item-meta-avatar"></ng-content>
<div *ngIf="nzTitle || nzDescription || descriptionComponent || titleComponent" class="ant-list-item-meta-content">
<!--Old API Start-->
<nz-list-item-meta-title *ngIf="nzTitle && !titleComponent">
<ng-container *nzStringTemplateOutlet="nzTitle">{{ nzTitle }}</ng-container>
</nz-list-item-meta-title>
<nz-list-item-meta-description *ngIf="nzDescription && !descriptionComponent">
<ng-container *nzStringTemplateOutlet="nzDescription">{{ nzDescription }}</ng-container>
</nz-list-item-meta-description>
<!--Old API End-->
<ng-content select="nz-list-item-meta-title"></ng-content>
<ng-content select="nz-list-item-meta-description"></ng-content>
</div>
`,
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
},] }
];
NzListItemMetaComponent.ctorParameters = () => [
{ type: ElementRef },
{ type: Renderer2 }
];
NzListItemMetaComponent.propDecorators = {
nzAvatar: [{ type: Input }],
nzTitle: [{ type: Input }],
nzDescription: [{ type: Input }],
descriptionComponent: [{ type: ContentChild, args: [NzListItemMetaDescriptionComponent,] }],
titleComponent: [{ type: ContentChild, args: [NzListItemMetaTitleComponent,] }]
};
/**
* 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 NzListItemExtraComponent {
constructor() { }
}
NzListItemExtraComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-item-extra, [nz-list-item-extra]',
exportAs: 'nzListItemExtra',
changeDetection: ChangeDetectionStrategy.OnPush,
template: ` <ng-content></ng-content> `,
host: {
class: 'ant-list-item-extra'
}
},] }
];
NzListItemExtraComponent.ctorParameters = () => [];
class NzListItemActionComponent {
constructor() { }
}
NzListItemActionComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-item-action',
exportAs: 'nzListItemAction',
changeDetection: ChangeDetectionStrategy.OnPush,
template: ` <ng-template><ng-content></ng-content></ng-template> `
},] }
];
NzListItemActionComponent.ctorParameters = () => [];
NzListItemActionComponent.propDecorators = {
templateRef: [{ type: ViewChild, args: [TemplateRef,] }]
};
class NzListItemActionsComponent {
constructor(ngZone, cdr) {
this.ngZone = ngZone;
this.cdr = cdr;
this.nzActions = [];
this.actions = [];
this.destroy$ = new Subject();
this.inputActionChanges$ = new Subject();
this.contentChildrenChanges$ = defer(() => {
if (this.nzListItemActions) {
return of(null);
}
return this.ngZone.onStable.asObservable().pipe(take(1), switchMap(() => this.contentChildrenChanges$));
});
merge(this.contentChildrenChanges$, this.inputActionChanges$)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
if (this.nzActions.length) {
this.actions = this.nzActions;
}
else {
this.actions = this.nzListItemActions.map(action => action.templateRef);
}
this.cdr.detectChanges();
});
}
ngOnChanges() {
this.inputActionChanges$.next(null);
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
NzListItemActionsComponent.decorators = [
{ type: Component, args: [{
selector: 'ul[nz-list-item-actions]',
exportAs: 'nzListItemActions',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<li *ngFor="let i of actions; let last = last">
<ng-template [ngTemplateOutlet]="i"></ng-template>
<em *ngIf="!last" class="ant-list-item-action-split"></em>
</li>
`,
host: {
class: 'ant-list-item-action'
}
},] }
];
NzListItemActionsComponent.ctorParameters = () => [
{ type: NgZone },
{ type: ChangeDetectorRef }
];
NzListItemActionsComponent.propDecorators = {
nzActions: [{ type: Input }],
nzListItemActions: [{ type: ContentChildren, args: [NzListItemActionComponent,] }]
};
/**
* 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 NzListEmptyComponent {
}
NzListEmptyComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-empty',
exportAs: 'nzListHeader',
changeDetection: ChangeDetectionStrategy.OnPush,
template: ` <nz-embed-empty [nzComponentName]="'list'" [specificContent]="nzNoResult"></nz-embed-empty> `,
host: {
class: 'ant-list-empty-text'
}
},] }
];
NzListEmptyComponent.propDecorators = {
nzNoResult: [{ type: Input }]
};
class NzListHeaderComponent {
}
NzListHeaderComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-header',
exportAs: 'nzListHeader',
changeDetection: ChangeDetectionStrategy.OnPush,
template: ` <ng-content></ng-content> `,
host: {
class: 'ant-list-header'
}
},] }
];
class NzListFooterComponent {
}
NzListFooterComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-footer',
exportAs: 'nzListFooter',
changeDetection: ChangeDetectionStrategy.OnPush,
template: ` <ng-content></ng-content> `,
host: {
class: 'ant-list-footer'
}
},] }
];
class NzListPaginationComponent {
}
NzListPaginationComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-pagination',
exportAs: 'nzListPagination',
changeDetection: ChangeDetectionStrategy.OnPush,
template: ` <ng-content></ng-content> `,
host: {
class: 'ant-list-pagination'
}
},] }
];
class NzListLoadMoreDirective {
}
NzListLoadMoreDirective.decorators = [
{ type: Directive, args: [{
selector: 'nz-list-load-more',
exportAs: 'nzListLoadMoreDirective'
},] }
];
class NzListGridDirective {
}
NzListGridDirective.decorators = [
{ type: Directive, args: [{
selector: 'nz-list[nzGrid]',
host: {
class: 'ant-list-grid'
}
},] }
];
/**
* 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 NzListComponent {
constructor(elementRef, directionality) {
this.elementRef = elementRef;
this.directionality = directionality;
this.nzBordered = false;
this.nzGrid = '';
this.nzItemLayout = 'horizontal';
this.nzRenderItem = null;
this.nzLoading = false;
this.nzLoadMore = null;
this.nzSize = 'default';
this.nzSplit = true;
this.hasSomethingAfterLastItem = false;
this.dir = 'ltr';
this.itemLayoutNotifySource = new BehaviorSubject(this.nzItemLayout);
this.destroy$ = new Subject();
// TODO: move to host after View Engine deprecation
this.elementRef.nativeElement.classList.add('ant-list');
}
get itemLayoutNotify$() {
return this.itemLayoutNotifySource.asObservable();
}
ngOnInit() {
var _a;
this.dir = this.directionality.value;
(_a = this.directionality.change) === null || _a === void 0 ? void 0 : _a.pipe(takeUntil(this.destroy$)).subscribe((direction) => {
this.dir = direction;
});
}
getSomethingAfterLastItem() {
return !!(this.nzLoadMore ||
this.nzPagination ||
this.nzFooter ||
this.nzListFooterComponent ||
this.nzListPaginationComponent ||
this.nzListLoadMoreDirective);
}
ngOnChanges(changes) {
if (changes.nzItemLayout) {
this.itemLayoutNotifySource.next(this.nzItemLayout);
}
}
ngOnDestroy() {
this.itemLayoutNotifySource.unsubscribe();
this.destroy$.next();
this.destroy$.complete();
}
ngAfterContentInit() {
this.hasSomethingAfterLastItem = this.getSomethingAfterLastItem();
}
}
NzListComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list, [nz-list]',
exportAs: 'nzList',
template: `
<ng-template #itemsTpl>
<div class="ant-list-items">
<ng-container *ngFor="let item of nzDataSource; let index = index">
<ng-template [ngTemplateOutlet]="nzRenderItem" [ngTemplateOutletContext]="{ $implicit: item, index: index }"></ng-template>
</ng-container>
<ng-content></ng-content>
</div>
</ng-template>
<nz-list-header *ngIf="nzHeader">
<ng-container *nzStringTemplateOutlet="nzHeader">{{ nzHeader }}</ng-container>
</nz-list-header>
<ng-content select="nz-list-header"></ng-content>
<nz-spin [nzSpinning]="nzLoading">
<ng-container>
<div *ngIf="nzLoading && nzDataSource && nzDataSource.length === 0" [style.min-height.px]="53"></div>
<div *ngIf="nzGrid && nzDataSource; else itemsTpl" nz-row [nzGutter]="nzGrid.gutter || null">
<div
nz-col
[nzSpan]="nzGrid.span || null"
[nzXs]="nzGrid.xs || null"
[nzSm]="nzGrid.sm || null"
[nzMd]="nzGrid.md || null"
[nzLg]="nzGrid.lg || null"
[nzXl]="nzGrid.xl || null"
[nzXXl]="nzGrid.xxl || null"
*ngFor="let item of nzDataSource; let index = index"
>
<ng-template [ngTemplateOutlet]="nzRenderItem" [ngTemplateOutletContext]="{ $implicit: item, index: index }"></ng-template>
</div>
</div>
<nz-list-empty *ngIf="!nzLoading && nzDataSource && nzDataSource.length === 0" [nzNoResult]="nzNoResult"></nz-list-empty>
</ng-container>
</nz-spin>
<nz-list-footer *ngIf="nzFooter">
<ng-container *nzStringTemplateOutlet="nzFooter">{{ nzFooter }}</ng-container>
</nz-list-footer>
<ng-content select="nz-list-footer, [nz-list-footer]"></ng-content>
<ng-template [ngTemplateOutlet]="nzLoadMore"></ng-template>
<ng-content select="nz-list-load-more, [nz-list-load-more]"></ng-content>
<nz-list-pagination *ngIf="nzPagination">
<ng-template [ngTemplateOutlet]="nzPagination"></ng-template>
</nz-list-pagination>
<ng-content select="nz-list-pagination, [nz-list-pagination]"></ng-content>
`,
preserveWhitespaces: false,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'[class.ant-list-rtl]': `dir === 'rtl'`,
'[class.ant-list-vertical]': 'nzItemLayout === "vertical"',
'[class.ant-list-lg]': 'nzSize === "large"',
'[class.ant-list-sm]': 'nzSize === "small"',
'[class.ant-list-split]': 'nzSplit',
'[class.ant-list-bordered]': 'nzBordered',
'[class.ant-list-loading]': 'nzLoading',
'[class.ant-list-something-after-last-item]': 'hasSomethingAfterLastItem'
}
},] }
];
NzListComponent.ctorParameters = () => [
{ type: ElementRef },
{ type: Directionality, decorators: [{ type: Optional }] }
];
NzListComponent.propDecorators = {
nzDataSource: [{ type: Input }],
nzBordered: [{ type: Input }],
nzGrid: [{ type: Input }],
nzHeader: [{ type: Input }],
nzFooter: [{ type: Input }],
nzItemLayout: [{ type: Input }],
nzRenderItem: [{ type: Input }],
nzLoading: [{ type: Input }],
nzLoadMore: [{ type: Input }],
nzPagination: [{ type: Input }],
nzSize: [{ type: Input }],
nzSplit: [{ type: Input }],
nzNoResult: [{ type: Input }],
nzListFooterComponent: [{ type: ContentChild, args: [NzListFooterComponent,] }],
nzListPaginationComponent: [{ type: ContentChild, args: [NzListPaginationComponent,] }],
nzListLoadMoreDirective: [{ type: ContentChild, args: [NzListLoadMoreDirective,] }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzListComponent.prototype, "nzBordered", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzListComponent.prototype, "nzLoading", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzListComponent.prototype, "nzSplit", void 0);
/**
* 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 NzListItemComponent {
constructor(elementRef, renderer, parentComp, cdr) {
this.parentComp = parentComp;
this.cdr = cdr;
this.nzActions = [];
this.nzExtra = null;
this.nzNoFlex = false;
renderer.addClass(elementRef.nativeElement, 'ant-list-item');
}
get isVerticalAndExtra() {
return this.itemLayout === 'vertical' && (!!this.listItemExtraDirective || !!this.nzExtra);
}
ngAfterViewInit() {
this.itemLayout$ = this.parentComp.itemLayoutNotify$.subscribe(val => {
this.itemLayout = val;
this.cdr.detectChanges();
});
}
ngOnDestroy() {
if (this.itemLayout$) {
this.itemLayout$.unsubscribe();
}
}
}
NzListItemComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-list-item, [nz-list-item]',
exportAs: 'nzListItem',
template: `
<ng-template #actionsTpl>
<ul nz-list-item-actions *ngIf="nzActions && nzActions.length > 0" [nzActions]="nzActions"></ul>
<ng-content select="nz-list-item-actions, [nz-list-item-actions]"></ng-content>
</ng-template>
<ng-template #contentTpl>
<ng-content select="nz-list-item-meta, [nz-list-item-meta]"></ng-content>
<ng-content></ng-content>
<ng-container *ngIf="nzContent">
<ng-container *nzStringTemplateOutlet="nzContent">{{ nzContent }}</ng-container>
</ng-container>
</ng-template>
<ng-template #extraTpl>
<ng-content select="nz-list-item-extra, [nz-list-item-extra]"></ng-content>
</ng-template>
<ng-template #simpleTpl>
<ng-template [ngTemplateOutlet]="contentTpl"></ng-template>
<ng-template [ngTemplateOutlet]="nzExtra"></ng-template>
<ng-template [ngTemplateOutlet]="extraTpl"></ng-template>
<ng-template [ngTemplateOutlet]="actionsTpl"></ng-template>
</ng-template>
<ng-container *ngIf="isVerticalAndExtra; else simpleTpl">
<div class="ant-list-item-main">
<ng-template [ngTemplateOutlet]="contentTpl"></ng-template>
<ng-template [ngTemplateOutlet]="actionsTpl"></ng-template>
</div>
<nz-list-item-extra *ngIf="nzExtra">
<ng-template [ngTemplateOutlet]="nzExtra"></ng-template>
</nz-list-item-extra>
<ng-template [ngTemplateOutlet]="extraTpl"></ng-template>
</ng-container>
`,
preserveWhitespaces: false,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
},] }
];
NzListItemComponent.ctorParameters = () => [
{ type: ElementRef },
{ type: Renderer2 },
{ type: NzListComponent },
{ type: ChangeDetectorRef }
];
NzListItemComponent.propDecorators = {
nzActions: [{ type: Input }],
nzContent: [{ type: Input }],
nzExtra: [{ type: Input }],
nzNoFlex: [{ type: Input }, { type: HostBinding, args: ['class.ant-list-item-no-flex',] }],
listItemExtraDirective: [{ type: ContentChild, args: [NzListItemExtraComponent,] }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Boolean)
], NzListItemComponent.prototype, "nzNoFlex", void 0);
/**
* 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
*/
const DIRECTIVES = [
NzListComponent,
NzListHeaderComponent,
NzListFooterComponent,
NzListPaginationComponent,
NzListEmptyComponent,
NzListItemComponent,
NzListItemMetaComponent,
NzListItemMetaTitleComponent,
NzListItemMetaDescriptionComponent,
NzListItemMetaAvatarComponent,
NzListItemActionsComponent,
NzListItemActionComponent,
NzListItemExtraComponent,
NzListLoadMoreDirective,
NzListGridDirective
];
class NzListModule {
}
NzListModule.decorators = [
{ type: NgModule, args: [{
imports: [BidiModule, CommonModule, NzSpinModule, NzGridModule, NzAvatarModule, NzOutletModule, NzEmptyModule],
declarations: [DIRECTIVES],
exports: [DIRECTIVES]
},] }
];
/**
* 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 { NzListComponent, NzListEmptyComponent, NzListFooterComponent, NzListGridDirective, NzListHeaderComponent, NzListItemActionComponent, NzListItemActionsComponent, NzListItemComponent, NzListItemExtraComponent, NzListItemMetaAvatarComponent, NzListItemMetaComponent, NzListItemMetaDescriptionComponent, NzListItemMetaTitleComponent, NzListLoadMoreDirective, NzListModule, NzListPaginationComponent };
//# sourceMappingURL=ng-zorro-antd-list.js.map