UNPKG

ng-zorro-antd

Version:

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

1 lines 8.54 kB
{"version":3,"file":"ng-zorro-antd-core-outlet.mjs","sources":["../../components/core/outlet/string_template_outlet.directive.ts","../../components/core/outlet/outlet.module.ts","../../components/core/outlet/public-api.ts","../../components/core/outlet/ng-zorro-antd-core-outlet.ts"],"sourcesContent":["/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport {\n Directive,\n EmbeddedViewRef,\n Input,\n OnChanges,\n SimpleChange,\n SimpleChanges,\n TemplateRef,\n ViewContainerRef\n} from '@angular/core';\n\nimport { NzSafeAny } from 'ng-zorro-antd/core/types';\n\n@Directive({\n selector: '[nzStringTemplateOutlet]',\n exportAs: 'nzStringTemplateOutlet',\n standalone: true\n})\nexport class NzStringTemplateOutletDirective<_T = unknown> implements OnChanges {\n private embeddedViewRef: EmbeddedViewRef<NzSafeAny> | null = null;\n private context = new NzStringTemplateOutletContext();\n @Input() nzStringTemplateOutletContext: NzSafeAny | null = null;\n @Input() nzStringTemplateOutlet: NzSafeAny | TemplateRef<NzSafeAny> = null;\n\n static ngTemplateContextGuard<T>(\n _dir: NzStringTemplateOutletDirective<T>,\n _ctx: NzSafeAny\n ): _ctx is NzStringTemplateOutletContext {\n return true;\n }\n\n private recreateView(): void {\n this.viewContainer.clear();\n const isTemplateRef = this.nzStringTemplateOutlet instanceof TemplateRef;\n const templateRef = (isTemplateRef ? this.nzStringTemplateOutlet : this.templateRef) as NzSafeAny;\n this.embeddedViewRef = this.viewContainer.createEmbeddedView(\n templateRef,\n isTemplateRef ? this.nzStringTemplateOutletContext : this.context\n );\n }\n\n private updateContext(): void {\n const isTemplateRef = this.nzStringTemplateOutlet instanceof TemplateRef;\n const newCtx = isTemplateRef ? this.nzStringTemplateOutletContext : this.context;\n const oldCtx = this.embeddedViewRef!.context as NzSafeAny;\n if (newCtx) {\n for (const propName of Object.keys(newCtx)) {\n oldCtx[propName] = newCtx[propName];\n }\n }\n }\n\n constructor(\n private viewContainer: ViewContainerRef,\n private templateRef: TemplateRef<NzSafeAny>\n ) {}\n\n ngOnChanges(changes: SimpleChanges): void {\n const { nzStringTemplateOutletContext, nzStringTemplateOutlet } = changes;\n const shouldRecreateView = (): boolean => {\n let shouldOutletRecreate = false;\n if (nzStringTemplateOutlet) {\n if (nzStringTemplateOutlet.firstChange) {\n shouldOutletRecreate = true;\n } else {\n const isPreviousOutletTemplate = nzStringTemplateOutlet.previousValue instanceof TemplateRef;\n const isCurrentOutletTemplate = nzStringTemplateOutlet.currentValue instanceof TemplateRef;\n shouldOutletRecreate = isPreviousOutletTemplate || isCurrentOutletTemplate;\n }\n }\n const hasContextShapeChanged = (ctxChange: SimpleChange): boolean => {\n const prevCtxKeys = Object.keys(ctxChange.previousValue || {});\n const currCtxKeys = Object.keys(ctxChange.currentValue || {});\n if (prevCtxKeys.length === currCtxKeys.length) {\n for (const propName of currCtxKeys) {\n if (prevCtxKeys.indexOf(propName) === -1) {\n return true;\n }\n }\n return false;\n } else {\n return true;\n }\n };\n const shouldContextRecreate =\n nzStringTemplateOutletContext && hasContextShapeChanged(nzStringTemplateOutletContext);\n return shouldContextRecreate || shouldOutletRecreate;\n };\n\n if (nzStringTemplateOutlet) {\n this.context.$implicit = nzStringTemplateOutlet.currentValue;\n }\n\n const recreateView = shouldRecreateView();\n if (recreateView) {\n /** recreate view when context shape or outlet change **/\n this.recreateView();\n } else {\n /** update context **/\n this.updateContext();\n }\n }\n}\n\nexport class NzStringTemplateOutletContext {\n public $implicit: NzSafeAny;\n}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { NgModule } from '@angular/core';\n\nimport { NzStringTemplateOutletDirective } from './string_template_outlet.directive';\n\n@NgModule({\n imports: [NzStringTemplateOutletDirective],\n exports: [NzStringTemplateOutletDirective]\n})\nexport class NzOutletModule {}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nexport { NzOutletModule } from './outlet.module';\nexport { NzStringTemplateOutletDirective } from './string_template_outlet.directive';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAAA;;;AAGG;MAoBU,+BAA+B,CAAA;AAM1C,IAAA,OAAO,sBAAsB,CAC3B,IAAwC,EACxC,IAAe,EAAA;AAEf,QAAA,OAAO,IAAI,CAAC;KACb;IAEO,YAAY,GAAA;AAClB,QAAA,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;AAC3B,QAAA,MAAM,aAAa,GAAG,IAAI,CAAC,sBAAsB,YAAY,WAAW,CAAC;AACzE,QAAA,MAAM,WAAW,IAAI,aAAa,GAAG,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,WAAW,CAAc,CAAC;QAClG,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAC1D,WAAW,EACX,aAAa,GAAG,IAAI,CAAC,6BAA6B,GAAG,IAAI,CAAC,OAAO,CAClE,CAAC;KACH;IAEO,aAAa,GAAA;AACnB,QAAA,MAAM,aAAa,GAAG,IAAI,CAAC,sBAAsB,YAAY,WAAW,CAAC;AACzE,QAAA,MAAM,MAAM,GAAG,aAAa,GAAG,IAAI,CAAC,6BAA6B,GAAG,IAAI,CAAC,OAAO,CAAC;AACjF,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,eAAgB,CAAC,OAAoB,CAAC;QAC1D,IAAI,MAAM,EAAE;YACV,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;gBAC1C,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;aACrC;SACF;KACF;IAED,WACU,CAAA,aAA+B,E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