UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

486 lines (479 loc) 15.5 kB
import { Directive, ElementRef, Renderer2, NgZone, Input, Optional, Host, NgModule } from '@angular/core'; import { MediaMatcher, LayoutModule } from '@angular/cdk/layout'; import { Platform, PlatformModule } from '@angular/cdk/platform'; import { responsiveMap, NzUpdateHostClassService, NzDomEventService, isNotNil } from 'ng-zorro-antd/core'; import { Subject } from 'rxjs'; import { takeUntil, finalize, startWith } from 'rxjs/operators'; import { __assign } from 'tslib'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzRowDirective = /** @class */ (function () { function NzRowDirective(elementRef, renderer, nzUpdateHostClassService, mediaMatcher, ngZone, platform, nzDomEventService) { this.elementRef = elementRef; this.renderer = renderer; this.nzUpdateHostClassService = nzUpdateHostClassService; this.mediaMatcher = mediaMatcher; this.ngZone = ngZone; this.platform = platform; this.nzDomEventService = nzDomEventService; this.nzAlign = 'top'; this.nzJustify = 'start'; this.el = this.elementRef.nativeElement; this.prefixCls = 'ant-row'; this.actualGutter$ = new Subject(); this.destroy$ = new Subject(); } /** * @return {?} */ NzRowDirective.prototype.calculateGutter = /** * @return {?} */ function () { if (typeof this.nzGutter !== 'object') { return this.nzGutter; } else if (this.breakPoint && this.nzGutter[this.breakPoint]) { return this.nzGutter[this.breakPoint]; } else { return 0; } }; /** * @return {?} */ NzRowDirective.prototype.updateGutter = /** * @return {?} */ function () { /** @type {?} */ var actualGutter = this.calculateGutter(); if (this.actualGutter !== actualGutter) { this.actualGutter = actualGutter; this.actualGutter$.next(this.actualGutter); this.renderer.setStyle(this.el, 'margin-left', "-" + this.actualGutter / 2 + "px"); this.renderer.setStyle(this.el, 'margin-right', "-" + this.actualGutter / 2 + "px"); } }; /** * @return {?} */ NzRowDirective.prototype.watchMedia = /** * @return {?} */ function () { var _this = this; Object.keys(responsiveMap).map((/** * @param {?} screen * @return {?} */ function (screen) { /** @type {?} */ var castBP = (/** @type {?} */ (screen)); /** @type {?} */ var matchBelow = _this.mediaMatcher.matchMedia(responsiveMap[castBP]).matches; if (matchBelow) { _this.breakPoint = castBP; } })); this.updateGutter(); }; /** temp solution since no method add classMap to host https://github.com/angular/angular/issues/7289*/ /** * temp solution since no method add classMap to host https://github.com/angular/angular/issues/7289 * @return {?} */ NzRowDirective.prototype.setClassMap = /** * temp solution since no method add classMap to host https://github.com/angular/angular/issues/7289 * @return {?} */ function () { var _a; /** @type {?} */ var classMap = (_a = {}, _a["" + this.prefixCls] = !this.nzType, _a[this.prefixCls + "-" + this.nzType] = this.nzType, _a[this.prefixCls + "-" + this.nzType + "-" + this.nzAlign] = this.nzType && this.nzAlign, _a[this.prefixCls + "-" + this.nzType + "-" + this.nzJustify] = this.nzType && this.nzJustify, _a); this.nzUpdateHostClassService.updateHostClass(this.el, classMap); }; /** * @return {?} */ NzRowDirective.prototype.ngOnInit = /** * @return {?} */ function () { this.setClassMap(); this.watchMedia(); }; /** * @param {?} changes * @return {?} */ NzRowDirective.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { if (changes.nzType || changes.nzAlign || changes.nzJustify) { this.setClassMap(); } if (changes.nzGutter) { this.updateGutter(); } }; /** * @return {?} */ NzRowDirective.prototype.ngAfterViewInit = /** * @return {?} */ function () { var _this = this; if (this.platform.isBrowser) { this.nzDomEventService .registerResizeListener() .pipe(takeUntil(this.destroy$), finalize((/** * @return {?} */ function () { return _this.nzDomEventService.unregisterResizeListener(); }))) .subscribe((/** * @return {?} */ function () { return _this.watchMedia(); })); } }; /** * @return {?} */ NzRowDirective.prototype.ngOnDestroy = /** * @return {?} */ function () { this.destroy$.next(); this.destroy$.complete(); }; NzRowDirective.decorators = [ { type: Directive, args: [{ selector: '[nz-row],nz-row', exportAs: 'nzRow', providers: [NzUpdateHostClassService] },] } ]; /** @nocollapse */ NzRowDirective.ctorParameters = function () { return [ { type: ElementRef }, { type: Renderer2 }, { type: NzUpdateHostClassService }, { type: MediaMatcher }, { type: NgZone }, { type: Platform }, { type: NzDomEventService } ]; }; NzRowDirective.propDecorators = { nzType: [{ type: Input }], nzAlign: [{ type: Input }], nzJustify: [{ type: Input }], nzGutter: [{ type: Input }] }; return NzRowDirective; }()); if (false) { /** @type {?} */ NzRowDirective.prototype.nzType; /** @type {?} */ NzRowDirective.prototype.nzAlign; /** @type {?} */ NzRowDirective.prototype.nzJustify; /** @type {?} */ NzRowDirective.prototype.nzGutter; /** * @type {?} * @private */ NzRowDirective.prototype.el; /** * @type {?} * @private */ NzRowDirective.prototype.prefixCls; /** * @type {?} * @private */ NzRowDirective.prototype.breakPoint; /** @type {?} */ NzRowDirective.prototype.actualGutter; /** @type {?} */ NzRowDirective.prototype.actualGutter$; /** @type {?} */ NzRowDirective.prototype.destroy$; /** @type {?} */ NzRowDirective.prototype.elementRef; /** @type {?} */ NzRowDirective.prototype.renderer; /** @type {?} */ NzRowDirective.prototype.nzUpdateHostClassService; /** @type {?} */ NzRowDirective.prototype.mediaMatcher; /** @type {?} */ NzRowDirective.prototype.ngZone; /** @type {?} */ NzRowDirective.prototype.platform; /** * @type {?} * @private */ NzRowDirective.prototype.nzDomEventService; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function EmbeddedProperty() { } if (false) { /** @type {?|undefined} */ EmbeddedProperty.prototype.span; /** @type {?|undefined} */ EmbeddedProperty.prototype.pull; /** @type {?|undefined} */ EmbeddedProperty.prototype.push; /** @type {?|undefined} */ EmbeddedProperty.prototype.offset; /** @type {?|undefined} */ EmbeddedProperty.prototype.order; } var NzColDirective = /** @class */ (function () { function NzColDirective(nzUpdateHostClassService, elementRef, nzRowDirective, renderer) { this.nzUpdateHostClassService = nzUpdateHostClassService; this.elementRef = elementRef; this.nzRowDirective = nzRowDirective; this.renderer = renderer; this.el = this.elementRef.nativeElement; this.prefixCls = 'ant-col'; this.destroy$ = new Subject(); } /** temp solution since no method add classMap to host https://github.com/angular/angular/issues/7289*/ /** * temp solution since no method add classMap to host https://github.com/angular/angular/issues/7289 * @return {?} */ NzColDirective.prototype.setClassMap = /** * temp solution since no method add classMap to host https://github.com/angular/angular/issues/7289 * @return {?} */ function () { var _a; /** @type {?} */ var classMap = __assign((_a = {}, _a[this.prefixCls + "-" + this.nzSpan] = isNotNil(this.nzSpan), _a[this.prefixCls + "-order-" + this.nzOrder] = isNotNil(this.nzOrder), _a[this.prefixCls + "-offset-" + this.nzOffset] = isNotNil(this.nzOffset), _a[this.prefixCls + "-pull-" + this.nzPull] = isNotNil(this.nzPull), _a[this.prefixCls + "-push-" + this.nzPush] = isNotNil(this.nzPush), _a), this.generateClass()); this.nzUpdateHostClassService.updateHostClass(this.el, classMap); }; /** * @return {?} */ NzColDirective.prototype.generateClass = /** * @return {?} */ function () { var _this = this; /** @type {?} */ var listOfSizeInputName = ['nzXs', 'nzSm', 'nzMd', 'nzLg', 'nzXl', 'nzXXl']; /** @type {?} */ var listClassMap = {}; listOfSizeInputName.forEach((/** * @param {?} name * @return {?} */ function (name) { /** @type {?} */ var sizeName = name.replace('nz', '').toLowerCase(); if (isNotNil(_this[name])) { if (typeof _this[name] === 'number' || typeof _this[name] === 'string') { listClassMap[_this.prefixCls + "-" + sizeName + "-" + _this[name]] = true; } else { /** @type {?} */ var embedded_1 = (/** @type {?} */ (_this[name])); /** @type {?} */ var prefixArray = ['span', 'pull', 'push', 'offset', 'order']; prefixArray.forEach((/** * @param {?} prefix * @return {?} */ function (prefix) { /** @type {?} */ var prefixClass = prefix === 'span' ? '-' : "-" + prefix + "-"; listClassMap[_this.prefixCls + "-" + sizeName + prefixClass + embedded_1[prefix]] = embedded_1 && isNotNil(embedded_1[prefix]); })); } } })); return listClassMap; }; /** * @return {?} */ NzColDirective.prototype.ngOnChanges = /** * @return {?} */ function () { this.setClassMap(); }; /** * @return {?} */ NzColDirective.prototype.ngAfterViewInit = /** * @return {?} */ function () { var _this = this; if (this.nzRowDirective) { this.nzRowDirective.actualGutter$ .pipe(startWith(this.nzRowDirective.actualGutter), takeUntil(this.destroy$)) .subscribe((/** * @param {?} actualGutter * @return {?} */ function (actualGutter) { _this.renderer.setStyle(_this.el, 'padding-left', actualGutter / 2 + "px"); _this.renderer.setStyle(_this.el, 'padding-right', actualGutter / 2 + "px"); })); } }; /** * @return {?} */ NzColDirective.prototype.ngOnInit = /** * @return {?} */ function () { this.setClassMap(); }; /** * @return {?} */ NzColDirective.prototype.ngOnDestroy = /** * @return {?} */ function () { this.destroy$.next(); this.destroy$.complete(); }; NzColDirective.decorators = [ { type: Directive, args: [{ selector: '[nz-col],nz-col', exportAs: 'nzCol', providers: [NzUpdateHostClassService] },] } ]; /** @nocollapse */ NzColDirective.ctorParameters = function () { return [ { type: NzUpdateHostClassService }, { type: ElementRef }, { type: NzRowDirective, decorators: [{ type: Optional }, { type: Host }] }, { type: Renderer2 } ]; }; NzColDirective.propDecorators = { nzSpan: [{ type: Input }], nzOrder: [{ type: Input }], nzOffset: [{ type: Input }], nzPush: [{ type: Input }], nzPull: [{ type: Input }], nzXs: [{ type: Input }], nzSm: [{ type: Input }], nzMd: [{ type: Input }], nzLg: [{ type: Input }], nzXl: [{ type: Input }], nzXXl: [{ type: Input }] }; return NzColDirective; }()); if (false) { /** * @type {?} * @private */ NzColDirective.prototype.el; /** * @type {?} * @private */ NzColDirective.prototype.prefixCls; /** * @type {?} * @protected */ NzColDirective.prototype.destroy$; /** @type {?} */ NzColDirective.prototype.nzSpan; /** @type {?} */ NzColDirective.prototype.nzOrder; /** @type {?} */ NzColDirective.prototype.nzOffset; /** @type {?} */ NzColDirective.prototype.nzPush; /** @type {?} */ NzColDirective.prototype.nzPull; /** @type {?} */ NzColDirective.prototype.nzXs; /** @type {?} */ NzColDirective.prototype.nzSm; /** @type {?} */ NzColDirective.prototype.nzMd; /** @type {?} */ NzColDirective.prototype.nzLg; /** @type {?} */ NzColDirective.prototype.nzXl; /** @type {?} */ NzColDirective.prototype.nzXXl; /** * @type {?} * @private */ NzColDirective.prototype.nzUpdateHostClassService; /** * @type {?} * @private */ NzColDirective.prototype.elementRef; /** @type {?} */ NzColDirective.prototype.nzRowDirective; /** @type {?} */ NzColDirective.prototype.renderer; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzGridModule = /** @class */ (function () { function NzGridModule() { } NzGridModule.decorators = [ { type: NgModule, args: [{ declarations: [NzColDirective, NzRowDirective], exports: [NzColDirective, NzRowDirective], imports: [CommonModule, LayoutModule, PlatformModule] },] } ]; return NzGridModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NzColDirective, NzGridModule, NzRowDirective }; //# sourceMappingURL=ng-zorro-antd-grid.js.map