@progress/kendo-angular-treeview
Version:
Kendo UI TreeView for Angular
70 lines (69 loc) • 3.37 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { Directive, ChangeDetectorRef, HostBinding, Input } from '@angular/core';
import { ExpandStateService } from './expand-state.service';
import { LoadingNotificationService } from './loading-notification.service';
import { of } from 'rxjs';
import { delay, filter, switchMap, takeUntil, tap } from 'rxjs/operators';
import * as i0 from "@angular/core";
import * as i1 from "./expand-state.service";
import * as i2 from "./loading-notification.service";
/**
* @hidden
*/
export class LoadingIndicatorDirective {
expandService;
loadingService;
cd;
get loading() {
return this._loading;
}
set loading(value) {
this._loading = value;
this.cd.markForCheck();
}
index;
_loading = false;
subscription;
constructor(expandService, loadingService, cd) {
this.expandService = expandService;
this.loadingService = loadingService;
this.cd = cd;
}
ngOnInit() {
const loadingNotifications = this.loadingService
.changes
.pipe(filter(index => index === this.index));
this.subscription = this.expandService
.changes
.pipe(filter(({ index }) => index === this.index), tap(({ expand }) => {
if (!expand && this.loading) {
this.loading = false;
}
}), filter(({ expand }) => expand), switchMap(x => of(x).pipe(delay(100), takeUntil(loadingNotifications))))
.subscribe(() => this.loading = true);
this.subscription.add(loadingNotifications.subscribe(() => this.loading = false));
}
ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LoadingIndicatorDirective, deps: [{ token: i1.ExpandStateService }, { token: i2.LoadingNotificationService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: LoadingIndicatorDirective, isStandalone: true, selector: "[kendoTreeViewLoading]", inputs: { index: ["kendoTreeViewLoading", "index"] }, host: { properties: { "class.k-i-loading": "this.loading" } }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LoadingIndicatorDirective, decorators: [{
type: Directive,
args: [{
selector: '[kendoTreeViewLoading]',
standalone: true
}]
}], ctorParameters: function () { return [{ type: i1.ExpandStateService }, { type: i2.LoadingNotificationService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { loading: [{
type: HostBinding,
args: ["class.k-i-loading"]
}], index: [{
type: Input,
args: ["kendoTreeViewLoading"]
}] } });