UNPKG

ng-zorro-antd

Version:

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

1 lines 10 kB
{"version":3,"file":"ng-zorro-antd-cdk-resize-observer.mjs","sources":["../../components/cdk/resize-observer/resize-observer.service.ts","../../components/cdk/resize-observer/resize-observer.directive.ts","../../components/cdk/resize-observer/resize-observer.module.ts","../../components/cdk/resize-observer/public-api.ts","../../components/cdk/resize-observer/ng-zorro-antd-cdk-resize-observer.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 { coerceElement } from '@angular/cdk/coercion';\nimport { ElementRef, Injectable, OnDestroy } from '@angular/core';\nimport { Observable, Observer, Subject } from 'rxjs';\n\n/**\n * Factory that creates a new ResizeObserver and allows us to stub it out in unit tests.\n */\n@Injectable({ providedIn: 'root' })\nexport class NzResizeObserverFactory {\n create(callback: ResizeObserverCallback): ResizeObserver | null {\n return typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(callback);\n }\n}\n\n/** An injectable service that allows watching elements for changes to their content. */\n@Injectable({ providedIn: 'root' })\nexport class NzResizeObserver implements OnDestroy {\n /** Keeps track of the existing ResizeObservers so they can be reused. */\n private observedElements = new Map<\n Element,\n {\n observer: ResizeObserver | null;\n stream: Subject<ResizeObserverEntry[]>;\n count: number;\n }\n >();\n\n constructor(private nzResizeObserverFactory: NzResizeObserverFactory) {}\n\n ngOnDestroy(): void {\n this.observedElements.forEach((_, element) => this.cleanupObserver(element));\n }\n\n observe(elementOrRef: Element | ElementRef<Element>): Observable<ResizeObserverEntry[]> {\n const element = coerceElement(elementOrRef);\n\n return new Observable((observer: Observer<ResizeObserverEntry[]>) => {\n const stream = this.observeElement(element);\n const subscription = stream.subscribe(observer);\n\n return () => {\n subscription.unsubscribe();\n this.unobserveElement(element);\n };\n });\n }\n\n /**\n * Observes the given element by using the existing ResizeObserver if available, or creating a\n * new one if not.\n */\n private observeElement(element: Element): Subject<ResizeObserverEntry[]> {\n if (!this.observedElements.has(element)) {\n const stream = new Subject<ResizeObserverEntry[]>();\n const observer = this.nzResizeObserverFactory.create((mutations: ResizeObserverEntry[]) =>\n stream.next(mutations)\n );\n if (observer) {\n observer.observe(element);\n }\n this.observedElements.set(element, { observer, stream, count: 1 });\n } else {\n this.observedElements.get(element)!.count++;\n }\n return this.observedElements.get(element)!.stream;\n }\n\n /**\n * Un-observes the given element and cleans up the underlying ResizeObserver if nobody else is\n * observing this element.\n */\n private unobserveElement(element: Element): void {\n if (this.observedElements.has(element)) {\n this.observedElements.get(element)!.count--;\n if (!this.observedElements.get(element)!.count) {\n this.cleanupObserver(element);\n }\n }\n }\n\n /** Clean up the underlying ResizeObserver for the specified element. */\n private cleanupObserver(element: Element): void {\n if (this.observedElements.has(element)) {\n const { observer, stream } = this.observedElements.get(element)!;\n if (observer) {\n observer.disconnect();\n }\n stream.complete();\n this.observedElements.delete(element);\n }\n }\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 {\n AfterContentInit,\n Directive,\n ElementRef,\n EventEmitter,\n Input,\n OnChanges,\n OnDestroy,\n Output,\n SimpleChanges\n} from '@angular/core';\nimport { Subscription } from 'rxjs';\n\nimport { BooleanInput } from 'ng-zorro-antd/core/types';\nimport { InputBoolean } from 'ng-zorro-antd/core/util';\n\nimport { NzResizeObserver } from './resize-observer.service';\n\n@Directive({\n selector: '[nzResizeObserver]'\n})\nexport class NzResizeObserverDirective implements AfterContentInit, OnDestroy, OnChanges {\n static ngAcceptInputType_nzResizeObserverDisabled: BooleanInput;\n @Output() readonly nzResizeObserve = new EventEmitter<ResizeObserverEntry[]>();\n @Input() @InputBoolean() nzResizeObserverDisabled = false;\n private currentSubscription: Subscription | null = null;\n\n private subscribe(): void {\n this.unsubscribe();\n this.currentSubscription = this.nzResizeObserver.observe(this.elementRef).subscribe(this.nzResizeObserve);\n }\n\n private unsubscribe(): void {\n this.currentSubscription?.unsubscribe();\n }\n\n constructor(private nzResizeObserver: NzResizeObserver, private elementRef: ElementRef<HTMLElement>) {}\n\n ngAfterContentInit(): void {\n if (!this.currentSubscription && !this.nzResizeObserverDisabled) {\n this.subscribe();\n }\n }\n\n ngOnDestroy(): void {\n this.unsubscribe();\n }\n\n ngOnChanges(changes: SimpleChanges): void {\n const { nzResizeObserve } = changes;\n if (nzResizeObserve) {\n if (this.nzResizeObserverDisabled) {\n this.unsubscribe();\n } else {\n this.subscribe();\n }\n }\n }\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 { NzResizeObserverDirective } from './resize-observer.directive';\nimport { NzResizeObserverFactory } from './resize-observer.service';\n\n@NgModule({\n providers: [NzResizeObserverFactory],\n declarations: [NzResizeObserverDirective],\n exports: [NzResizeObserverDirective]\n})\nexport class NzResizeObserverModule {}\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 { NzResizeObserverModule } from './resize-observer.module';\nexport { NzResizeObserverDirective } from './resize-observer.directive';\nexport { NzResizeObserver, NzResizeObserverFactory } from './resize-observer.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAAA;;;;AASA;;;MAIa,uBAAuB;IAClC,MAAM,CAAC,QAAgC;QACrC,OAAO,OAAO,cAAc,KAAK,WAAW,GAAG,IAAI,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC;KACpF;;oHAHU,uBAAuB;wHAAvB,uBAAuB,cADV,MAAM;2FACnB,uBAAuB;kBADnC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;AAOlC;MAEa,gBAAgB;IAW3B,YAAoB,uBAAgD;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