UNPKG

ng-zorro-antd

Version:

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

178 lines (172 loc) 6.17 kB
import { CommonModule } from '@angular/common'; import { TemplateRef, Directive, ViewContainerRef, Input, NgModule } from '@angular/core'; /** * @fileoverview added by tsickle * Generated from: string_template_outlet.directive.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzStringTemplateOutletDirective { /** * @param {?} viewContainer * @param {?} templateRef */ constructor(viewContainer, templateRef) { this.viewContainer = viewContainer; this.templateRef = templateRef; this.embeddedViewRef = null; this.nzStringTemplateOutletContext = null; this.nzStringTemplateOutlet = null; } /** * @private * @return {?} */ recreateView() { this.viewContainer.clear(); /** @type {?} */ const isTemplateRef = this.nzStringTemplateOutlet instanceof TemplateRef; /** @type {?} */ const templateRef = (/** @type {?} */ ((isTemplateRef ? this.nzStringTemplateOutlet : this.templateRef))); this.embeddedViewRef = this.viewContainer.createEmbeddedView(templateRef, this.nzStringTemplateOutletContext); } /** * @private * @return {?} */ updateContext() { /** @type {?} */ const newCtx = this.nzStringTemplateOutletContext; /** @type {?} */ const oldCtx = (/** @type {?} */ ((/** @type {?} */ (this.embeddedViewRef)).context)); if (newCtx) { for (const propName of Object.keys(newCtx)) { oldCtx[propName] = newCtx[propName]; } } } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { /** @type {?} */ const shouldRecreateView = (/** * @param {?} ctxChanges * @return {?} */ (ctxChanges) => { const { nzStringTemplateOutletContext, nzStringTemplateOutlet } = ctxChanges; /** @type {?} */ let shouldOutletRecreate = false; if (nzStringTemplateOutlet) { if (nzStringTemplateOutlet.firstChange) { shouldOutletRecreate = true; } else { /** @type {?} */ const isPreviousOutletTemplate = nzStringTemplateOutlet.previousValue instanceof TemplateRef; /** @type {?} */ const isCurrentOutletTemplate = nzStringTemplateOutlet.currentValue instanceof TemplateRef; shouldOutletRecreate = isPreviousOutletTemplate || isCurrentOutletTemplate; } } /** @type {?} */ const hasContextShapeChanged = (/** * @param {?} ctxChange * @return {?} */ (ctxChange) => { /** @type {?} */ const prevCtxKeys = Object.keys(ctxChange.previousValue || {}); /** @type {?} */ const currCtxKeys = Object.keys(ctxChange.currentValue || {}); if (prevCtxKeys.length === currCtxKeys.length) { for (const propName of currCtxKeys) { if (prevCtxKeys.indexOf(propName) === -1) { return true; } } return false; } else { return true; } }); /** @type {?} */ const shouldContextRecreate = nzStringTemplateOutletContext && hasContextShapeChanged(nzStringTemplateOutletContext); return shouldContextRecreate || shouldOutletRecreate; }); /** @type {?} */ const recreateView = shouldRecreateView(changes); if (recreateView) { /** recreate view when context shape or outlet change **/ this.recreateView(); } else { /** update context **/ this.updateContext(); } } } NzStringTemplateOutletDirective.decorators = [ { type: Directive, args: [{ selector: '[nzStringTemplateOutlet]', exportAs: 'nzStringTemplateOutlet' },] } ]; /** @nocollapse */ NzStringTemplateOutletDirective.ctorParameters = () => [ { type: ViewContainerRef }, { type: TemplateRef } ]; NzStringTemplateOutletDirective.propDecorators = { nzStringTemplateOutletContext: [{ type: Input }], nzStringTemplateOutlet: [{ type: Input }] }; if (false) { /** * @type {?} * @private */ NzStringTemplateOutletDirective.prototype.embeddedViewRef; /** @type {?} */ NzStringTemplateOutletDirective.prototype.nzStringTemplateOutletContext; /** @type {?} */ NzStringTemplateOutletDirective.prototype.nzStringTemplateOutlet; /** * @type {?} * @private */ NzStringTemplateOutletDirective.prototype.viewContainer; /** * @type {?} * @private */ NzStringTemplateOutletDirective.prototype.templateRef; } /** * @fileoverview added by tsickle * Generated from: outlet.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzOutletModule { } NzOutletModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule], exports: [NzStringTemplateOutletDirective], declarations: [NzStringTemplateOutletDirective] },] } ]; /** * @fileoverview added by tsickle * Generated from: public-api.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * Generated from: ng-zorro-antd-core-outlet.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NzOutletModule, NzStringTemplateOutletDirective }; //# sourceMappingURL=ng-zorro-antd-core-outlet.js.map