@ng-doc/ui-kit
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>
56 lines (52 loc) • 2.28 kB
JavaScript
import * as i0 from '@angular/core';
import { inject, DOCUMENT, NgZone, Injectable } from '@angular/core';
import { toElement } from '@ng-doc/ui-kit/helpers';
import { ngDocZoneDetach } from '@ng-doc/ui-kit/observables';
import { Subject, fromEvent } from 'rxjs';
import { throttleTime, map, filter, takeUntil } from 'rxjs/operators';
class NgDocOverlayStrategy {
constructor() {
this.documentRef = inject(DOCUMENT);
this.ngZone = inject(NgZone);
this.overlayRef = null;
this.destroy$ = new Subject();
}
attach(overlayRef) {
this.overlayRef = overlayRef;
}
enable() {
fromEvent(this.documentRef, 'scroll', { capture: true })
.pipe(ngDocZoneDetach(this.ngZone), throttleTime(10), map((scrollEvent) => scrollEvent.target instanceof Document
? scrollEvent.target.scrollingElement
: scrollEvent.target), filter((target) => target instanceof Node ? target.contains(this.origin) || !this.origin : false), takeUntil(this.destroy$))
.subscribe(() => this.detach());
}
get origin() {
const config = this.overlayRef?.getConfig();
return config?.viewContainerRef
? toElement(config.viewContainerRef.element)
: null;
}
disable() {
this.destroy$.next();
}
detach() {
this.disable();
if (this.overlayRef?.hasAttached()) {
this.ngZone.run(() => {
this.overlayRef?.detach();
});
}
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgDocOverlayStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgDocOverlayStrategy, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgDocOverlayStrategy, decorators: [{
type: Injectable,
args: [{ providedIn: 'root' }]
}], ctorParameters: () => [] });
/**
* Generated bundle index. Do not edit.
*/
export { NgDocOverlayStrategy };
//# sourceMappingURL=ng-doc-ui-kit-services-overlay-strategy.mjs.map