UNPKG

@progress/kendo-angular-tooltip

Version:

Kendo UI Tooltip for Angular - A highly customizable and easily themeable tooltip from the creators developers trust for professional Angular components.

72 lines (71 loc) 3.14 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Injectable, NgZone } from '@angular/core'; import { BehaviorSubject, combineLatest, Subject, Subscription } from 'rxjs'; import { auditTime } from 'rxjs/operators'; import * as i0 from "@angular/core"; /** * @hidden */ export class PopoverService { ngZone; _pointerOverPopup = new BehaviorSubject(null); _pointerOverAnchor = new BehaviorSubject(null); _focusInsidePopover = new BehaviorSubject(null); _hidePopover = new Subject(); _isOrigin; originAnchor; currentAnchor; subs = new Subscription(); constructor(ngZone) { this.ngZone = ngZone; this.monitor(); } ngOnDestroy() { this.subs.unsubscribe(); } get isPopoverHovered() { return this._pointerOverPopup.asObservable(); } emitPopoverState(isHovered) { this.ngZone.run(_ => this._pointerOverPopup.next(isHovered)); } get isAnchorHovered() { return this._pointerOverAnchor.asObservable(); } emitAnchorState(isHovered, anchor) { this._isOrigin = this.originAnchor === anchor; this.currentAnchor = anchor; if (isHovered) { this.originAnchor = anchor; } this.ngZone.run(_ => this._pointerOverAnchor.next(isHovered)); } get isFocusInsidePopover() { return this._focusInsidePopover.asObservable(); } emitFocusInsidePopover(isFocused) { this.ngZone.run(_ => this._focusInsidePopover.next(isFocused)); this._focusInsidePopover.next(null); } get hidePopover() { return this._hidePopover.asObservable(); } monitor() { this.subs.add(combineLatest(this.isPopoverHovered, this.isAnchorHovered).pipe( // `auditTime` is used because the `mouseleave` event is emitted before `mouseenter` // i.e. there is a millisecond in which the pointer leaves the first target (e.g. anchor) and hasn't reached the second one (e.g. popup) // resulting in both observables emitting `false` auditTime(20)).subscribe(val => { const [isPopoverHovered, isAnchorHovered] = val; this._hidePopover.next([isPopoverHovered, isAnchorHovered, this._isOrigin, this.currentAnchor]); })); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PopoverService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PopoverService }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PopoverService, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: i0.NgZone }]; } });