UNPKG

@progress/kendo-angular-treeview

Version:
93 lines (92 loc) 3.45 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, Input } from "@angular/core"; import { DataBoundComponent } from "./data-bound-component"; import { DEFAULT_FILTER_SETTINGS } from "./treeview-filter-settings"; import { filterTree, isPresent } from "./utils"; import * as i0 from "@angular/core"; import * as i1 from "./data-bound-component"; /** * @hidden */ export class FilteringBase { component; /** * Stores the unfiltered nodes */ filterData; visibleNodes = new Set(); /** * The settings which are applied when performing a filter on the component's data. */ set filterSettings(settings) { this._filterSettings = { ...DEFAULT_FILTER_SETTINGS, ...settings }; } get filterSettings() { return this._filterSettings; } _filterSettings = DEFAULT_FILTER_SETTINGS; /** * Applies a filter and changes the visibility of the component's nodes accordingly. */ set filter(term) { this.handleFilterChange(term); } constructor(component) { this.component = component; } /** * @hidden */ handleFilterChange(term) { if (!this.filterData) { return; } this.resetNodesVisibility(this.filterData); if (term) { filterTree(this.filterData, term, this.filterSettings, this.component.textField); } this.updateVisibleNodes(this.filterData); if (isPresent(this.component.filterStateChange)) { this.component.filterStateChange.emit({ nodes: this.filterData, matchCount: this.visibleNodes.size, term, filterSettings: this.filterSettings }); } } updateVisibleNodes(items) { items.forEach((wrapper) => { if (wrapper.visible) { this.visibleNodes.add(wrapper.dataItem); } if (wrapper.children) { this.updateVisibleNodes(wrapper.children); } }); } resetNodesVisibility(items) { this.visibleNodes.clear(); items.forEach((wrapper) => { wrapper.visible = true; if (wrapper.children) { this.resetNodesVisibility(wrapper.children); } }); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FilteringBase, deps: [{ token: i1.DataBoundComponent }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: FilteringBase, inputs: { filterSettings: "filterSettings", filter: "filter" }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FilteringBase, decorators: [{ type: Directive }], ctorParameters: function () { return [{ type: i1.DataBoundComponent }]; }, propDecorators: { filterSettings: [{ type: Input }], filter: [{ type: Input }] } });