UNPKG

@progress/kendo-angular-dropdowns

Version:

A wide variety of native Angular dropdown components including AutoComplete, ComboBox, DropDownList, DropDownTree, MultiColumnComboBox, MultiSelect, and MultiSelectTree

77 lines (76 loc) 3.49 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 { getHierarchicalItemLevel, valueFrom } from '../../common/util'; import * as i0 from "@angular/core"; /** * @hidden * * A directive which manages the in-memory checked state of the MultiSelectTree nodes. */ export class BaseCheckDirective { /** * @hidden * The flag is needed in order to determine how to construct the items map keys. * If `true`, then the key consists of the item's value and level (depth), * else the key consists of the item's value and 0 (no leveling required) */ isHeterogeneous; addItem(item) { if (this.isItemChecked(item)) { return; } const level = getHierarchicalItemLevel(item.index); const key = this.getKey(item, level); const candidate = { ...item, level, key }; this.checkedItems.push(candidate); this.checkedKeys.add(key); } removeItem(item) { if (!this.isItemChecked(item)) { return; } const level = getHierarchicalItemLevel(item.index); const key = this.getKey(item, level); const candidate = { ...item, level, key }; this.checkedItems = this.checkedItems .filter(item => { const valueMatch = valueFrom(item, this.valueField) === valueFrom(candidate, this.valueField); const levelMatch = item.level === candidate.level; return this.isHeterogeneous ? !(valueMatch && levelMatch) : !valueMatch; }); this.checkedKeys.delete(key); } isItemChecked(item) { const level = item.index.split('_').length - 1; item.level = level; const key = this.getKey(item, level); return this.checkedKeys.has(key); } updateItems() { this.checkedItems = this.checkedItems || []; this.checkedKeys = new Set(this.checkedItems.map(item => item.key)); } /** * Adds the item's depth to the item's value to allow duplicate values on different levels. * * @param item - The checked key. * @returns { string } - A string key consisting of the item's `valueField` value and its depth (depth is 0 if data is homogeneous). */ getKey(item, level) { return valueFrom(item, this.valueField) + '_' + (this.isHeterogeneous ? level : 0); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseCheckDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: BaseCheckDirective, inputs: { valueField: "valueField", checkedItems: "checkedItems", isHeterogeneous: "isHeterogeneous" }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseCheckDirective, decorators: [{ type: Directive }], propDecorators: { valueField: [{ type: Input }], checkedItems: [{ type: Input }], isHeterogeneous: [{ type: Input }] } });