{"version":3,"file":"ng-zorro-antd-core-outlet.mjs","names":[],"sources":["../../components/core/outlet/string-template-outlet.directive.ts","../../components/core/outlet/outlet.module.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  inject,\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';\nimport { isTemplateRef } from 'ng-zorro-antd/core/util';\n\n@Directive({\n  selector: '[nzStringTemplateOutlet]',\n  exportAs: 'nzStringTemplateOutlet'\n})\nexport class NzStringTemplateOutletDirective<_T = unknown> implements OnChanges {\n  private viewContainer = inject(ViewContainerRef);\n  private templateRef = inject(TemplateRef<NzSafeAny>);\n\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    if (isTemplateRef(this.nzStringTemplateOutlet)) {\n      this.embeddedViewRef = this.viewContainer.createEmbeddedView(\n        this.nzStringTemplateOutlet,\n        this.nzStringTemplateOutletContext\n      );\n    } else {\n      this.embeddedViewRef = this.viewContainer.createEmbeddedView(this.templateRef, this.context);\n    }\n  }\n\n  private updateContext(): void {\n    const newCtx = isTemplateRef(this.nzStringTemplateOutlet) ? 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  ngOnChanges(changes: SimpleChanges): void {\n    const { nzStringTemplateOutletContext, nzStringTemplateOutlet } = changes;\n    const shouldRecreateView = (): boolean => {\n      let shouldOutletRecreate = false;\n      if (nzStringTemplateOutlet) {\n        shouldOutletRecreate =\n          nzStringTemplateOutlet.firstChange ||\n          isTemplateRef(nzStringTemplateOutlet.previousValue) ||\n          isTemplateRef(nzStringTemplateOutlet.currentValue);\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"],"mappings":";;;AAwBA,IAAa,kCAAb,MAAa,gCAA+B;CAClC,gBAAgB,OAAO,gBAAgB;CACvC,cAAc,OAAO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