@taiga-ui/kit
Version:
Taiga UI Angular main components kit
71 lines (66 loc) • 3.49 kB
JavaScript
import { __decorate, __param } from 'tslib';
import { Inject, ElementRef, HostListener, Directive, NgModule } from '@angular/core';
import { isPresent, typedFromEvent, isNativeFocusedIn, setNativeMouseFocused, TuiDestroyService } from '@taiga-ui/cdk';
import { TuiHostedDropdownComponent } from '@taiga-ui/core';
import { merge, of, timer, Observable } from 'rxjs';
import { debounceTime, map, filter, share, tap, switchMap, mapTo, debounce, distinctUntilChanged, takeUntil } from 'rxjs/operators';
var TuiDropdownHoverDirective = /** @class */ (function () {
function TuiDropdownHoverDirective(destroy$, _a, dropdown) {
var nativeElement = _a.nativeElement;
this.dropdown = dropdown;
var dropdown$ = dropdown.openChange.pipe(
// Give change detection time to open dropdown
debounceTime(0), map(function () { return dropdown.dropdown; }), filter(isPresent), share());
var open$ = merge(typedFromEvent(nativeElement, 'mouseenter'), typedFromEvent(nativeElement, 'click').pipe(tap(function (e) { return e.stopImmediatePropagation(); })), dropdown$.pipe(switchMap(function (element) {
return merge(typedFromEvent(element, 'focusin'), typedFromEvent(element, 'mouseenter'));
}))).pipe(mapTo(true));
var close$ = merge(typedFromEvent(nativeElement, 'mouseleave'), dropdown$.pipe(switchMap(function (element) {
return typedFromEvent(element, 'mouseleave').pipe(filter(function () { return !isNativeFocusedIn(element); }));
}))).pipe(mapTo(false));
merge(open$, close$)
.pipe(debounce(function (value) { return (value ? of(value) : timer(300)); }), distinctUntilChanged(), takeUntil(destroy$))
.subscribe(function (open) {
dropdown.updateOpen(open);
});
}
TuiDropdownHoverDirective.prototype.onMouseEnter = function () {
var nativeFocusableElement = this.dropdown.nativeFocusableElement;
if (nativeFocusableElement) {
setNativeMouseFocused(nativeFocusableElement);
}
};
TuiDropdownHoverDirective.ctorParameters = function () { return [
{ type: Observable, decorators: [{ type: Inject, args: [TuiDestroyService,] }] },
{ type: ElementRef, decorators: [{ type: Inject, args: [ElementRef,] }] },
{ type: TuiHostedDropdownComponent, decorators: [{ type: Inject, args: [TuiHostedDropdownComponent,] }] }
]; };
__decorate([
HostListener('mouseenter')
], TuiDropdownHoverDirective.prototype, "onMouseEnter", null);
TuiDropdownHoverDirective = __decorate([
Directive({
selector: 'tui-hosted-dropdown[tuiDropdownHover]',
providers: [TuiDestroyService],
}),
__param(0, Inject(TuiDestroyService)),
__param(1, Inject(ElementRef)),
__param(2, Inject(TuiHostedDropdownComponent))
], TuiDropdownHoverDirective);
return TuiDropdownHoverDirective;
}());
var TuiDropdownHoverModule = /** @class */ (function () {
function TuiDropdownHoverModule() {
}
TuiDropdownHoverModule = __decorate([
NgModule({
declarations: [TuiDropdownHoverDirective],
exports: [TuiDropdownHoverDirective],
})
], TuiDropdownHoverModule);
return TuiDropdownHoverModule;
}());
/**
* Generated bundle index. Do not edit.
*/
export { TuiDropdownHoverDirective, TuiDropdownHoverModule };
//# sourceMappingURL=taiga-ui-kit-directives-dropdown-hover.js.map