ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
1 lines • 11.1 kB
Source Map (JSON)
{"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 booleanAttribute\n} from '@angular/core';\nimport { Subscription } from 'rxjs';\n\nimport { NzResizeObserver, NzResizeObserverFactory } from './resize-observer.service';\n\n@Directive({\n selector: '[nzResizeObserver]',\n providers: [NzResizeObserverFactory]\n})\nexport class NzResizeObserverDirective implements AfterContentInit, OnDestroy, OnChanges {\n @Output() readonly nzResizeObserve = new EventEmitter<ResizeObserverEntry[]>();\n @Input({ transform: booleanAttribute }) 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(\n private nzResizeObserver: NzResizeObserver,\n private elementRef: ElementRef<HTMLElement>\n ) {}\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';\n\n@NgModule({\n imports: [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":["i1.NzResizeObserver"],"mappings":";;;;;AAAA;;;AAGG;AAMH;;AAEG;MAEU,uBAAuB,CAAA;AAClC,IAAA,MAAM,CAAC,QAAgC,EAAA;AACrC,QAAA,OAAO,OAAO,cAAc,KAAK,WAAW,GAAG,IAAI,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC;;uGAFzE,uBAAuB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAvB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA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