UNPKG

ng-zorro-antd

Version:

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

1 lines 11.7 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":["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,CAAC;KACpF;;oHAHU,uBAAuB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAA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