UNPKG

@progress/kendo-angular-treeview

Version:
83 lines (82 loc) 3.96 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Directive, ElementRef, Input, Renderer2 } from '@angular/core'; import { NavigationService } from './navigation/navigation.service'; import { SelectionService } from './selection/selection.service'; import { isSelected } from './default-callbacks'; import { Subscription } from 'rxjs'; import { filter } from 'rxjs/operators'; import * as i0 from "@angular/core"; import * as i1 from "./navigation/navigation.service"; import * as i2 from "./selection/selection.service"; /** * @hidden * * A directive which manages the expanded state of the TreeView. */ export class TreeViewItemContentDirective { element; navigationService; selectionService; renderer; dataItem; index; initialSelection = false; isSelected = isSelected; subscriptions = new Subscription(); constructor(element, navigationService, selectionService, renderer) { this.element = element; this.navigationService = navigationService; this.selectionService = selectionService; this.renderer = renderer; this.subscriptions.add(this.navigationService.moves .subscribe(this.updateFocusClass.bind(this))); this.subscriptions.add(this.navigationService.selects .pipe(filter((index) => index === this.index)) .subscribe((index) => this.selectionService.select(index, this.dataItem))); this.subscriptions.add(this.selectionService.changes .subscribe(() => { this.updateSelectionClass(this.isSelected(this.dataItem, this.index)); })); } ngOnChanges(changes) { if (changes['initialSelection']) { this.updateSelectionClass(this.initialSelection); } if (changes['index']) { this.updateFocusClass(); } } ngOnDestroy() { this.subscriptions.unsubscribe(); } updateFocusClass() { this.render(this.navigationService.isActive(this.index), 'k-focus'); } updateSelectionClass(selected) { this.render(selected, 'k-selected'); } render(addClass, className) { const action = addClass ? 'addClass' : 'removeClass'; this.renderer[action](this.element.nativeElement, className); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TreeViewItemContentDirective, deps: [{ token: i0.ElementRef }, { token: i1.NavigationService }, { token: i2.SelectionService }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: TreeViewItemContentDirective, isStandalone: true, selector: "[kendoTreeViewItemContent]", inputs: { dataItem: "dataItem", index: "index", initialSelection: "initialSelection", isSelected: "isSelected" }, usesOnChanges: true, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TreeViewItemContentDirective, decorators: [{ type: Directive, args: [{ selector: '[kendoTreeViewItemContent]', standalone: true }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.NavigationService }, { type: i2.SelectionService }, { type: i0.Renderer2 }]; }, propDecorators: { dataItem: [{ type: Input }], index: [{ type: Input }], initialSelection: [{ type: Input }], isSelected: [{ type: Input }] } });