UNPKG

@taiga-ui/cdk

Version:

Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance

66 lines (62 loc) 3.7 kB
import { DOCUMENT } from '@angular/common'; import * as i0 from '@angular/core'; import { inject, ElementRef, Injectable, Directive } from '@angular/core'; import { tuiZoneOptimized } from '@taiga-ui/cdk/observables'; import { TUI_ACTIVE_ELEMENT } from '@taiga-ui/cdk/tokens'; import { tuiIsElement } from '@taiga-ui/cdk/utils/dom'; import { tuiArrayRemove } from '@taiga-ui/cdk/utils/miscellaneous'; import { map, startWith, distinctUntilChanged, skip, share } from 'rxjs'; class TuiActiveZone { constructor() { this.active$ = inject(TUI_ACTIVE_ELEMENT); this.tuiActiveZoneParent = null; this.parent = inject(TuiActiveZone, { skipSelf: true, optional: true }); this.el = inject(ElementRef, { optional: true })?.nativeElement ?? inject(DOCUMENT).documentElement; this.tuiActiveZoneChange = this.active$.pipe(map((element) => tuiIsElement(element) && this.contains(element)), startWith(false), distinctUntilChanged(), skip(1), tuiZoneOptimized(), share()); this.children = []; this.parent?.addSubActiveZone(this); } set tuiActiveZoneParentSetter(zone) { this.tuiActiveZoneParent?.removeSubActiveZone(this); zone?.addSubActiveZone(this); this.tuiActiveZoneParent = zone; } ngOnDestroy() { this.parent?.removeSubActiveZone(this); this.tuiActiveZoneParent?.removeSubActiveZone(this); } contains(node) { return (this.el.contains(node) || this.children.some((item) => item.contains(node))); } // issue: https://github.com/typescript-eslint/typescript-eslint/issues/11770 // eslint-disable-next-line @typescript-eslint/no-unused-private-class-members addSubActiveZone(activeZone) { this.children = [...this.children, activeZone]; } // issue: https://github.com/typescript-eslint/typescript-eslint/issues/11770 // eslint-disable-next-line @typescript-eslint/no-unused-private-class-members removeSubActiveZone(activeZone) { this.children = tuiArrayRemove(this.children, this.children.indexOf(activeZone)); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiActiveZone, deps: [], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.25", type: TuiActiveZone, isStandalone: true, selector: "[tuiActiveZone]:not(ng-container), [tuiActiveZoneChange]:not(ng-container), [tuiActiveZoneParent]:not(ng-container)", inputs: { tuiActiveZoneParentSetter: ["tuiActiveZoneParent", "tuiActiveZoneParentSetter"] }, outputs: { tuiActiveZoneChange: "tuiActiveZoneChange" }, exportAs: ["tuiActiveZone"], ngImport: i0 }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiActiveZone, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiActiveZone, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }, { type: Directive, args: [{ selector: '[tuiActiveZone]:not(ng-container), [tuiActiveZoneChange]:not(ng-container), [tuiActiveZoneParent]:not(ng-container)', inputs: ['tuiActiveZoneParentSetter: tuiActiveZoneParent'], outputs: ['tuiActiveZoneChange'], exportAs: 'tuiActiveZone', }] }], ctorParameters: () => [] }); /** * Generated bundle index. Do not edit. */ export { TuiActiveZone }; //# sourceMappingURL=taiga-ui-cdk-directives-active-zone.mjs.map