UNPKG

@progress/kendo-angular-layout

Version:

Kendo UI for Angular Layout Package - a collection of components to create professional application layoyts

106 lines (105 loc) 3.86 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Injectable } from '@angular/core'; import { isPresent } from '../common/util'; import * as i0 from "@angular/core"; /** * @hidden */ export const defaultIsItemExpanded = (_item) => false; /** * @hidden */ export class DrawerService { owner; selectedIndices = []; viewData; focusIndex = 0; originalItems = []; idxCounter = 0; init() { this.resetViewData(); this.originalItems = this.owner.items || []; const rootItems = this.originalItems.filter(item => !isPresent(item.parentId)); this.populateViewData(rootItems); } get view() { return Array.from(this.viewData); } changeFocusedItem(items, keyName, renderer) { const currentItem = items.get(this.focusIndex); let nextItem; if (keyName === 'arrowUp') { if (this.focusIndex === 0) { nextItem = items.get(items.length - 1); this.focusIndex = items.length - 1; } else { nextItem = items.get(this.focusIndex - 1); this.focusIndex = this.focusIndex - 1; } } else if (keyName === 'arrowDown') { if (this.focusIndex === items.length - 1) { nextItem = items.get(0); this.focusIndex = 0; } else { nextItem = items.get(this.focusIndex + 1); this.focusIndex = this.focusIndex + 1; } } renderer.setAttribute(currentItem.nativeElement, 'tabindex', '-1'); renderer.setAttribute(nextItem.nativeElement, 'tabindex', '0'); nextItem.nativeElement.focus(); } populateViewData(items, level = 0) { items.forEach((item) => { this.setSelection(item); const children = this.loadChildren(item); const isExpanded = this.isItemExpanded(item); this.viewData.add({ item: item, index: this.idxCounter++, level: level, hasChildren: children.length > 0, isExpanded: isExpanded }); if (children.length > 0 && isExpanded) { this.populateViewData(children, level + 1); } }); } resetViewData() { this.idxCounter = 0; this.viewData = new Set(); } loadChildren(item) { return this.originalItems.filter(i => { return isPresent(i.parentId) && (i.parentId === item.id); }); } isItemExpanded = defaultIsItemExpanded; onSelect(selectedIdx) { this.selectedIndices = [selectedIdx]; const drawer = this.owner; if (drawer.autoCollapse && !drawer.minimized) { drawer.toggle(false); } } setSelection(item) { if (this.selectedIndices.length === 0 && item.selected) { this.selectedIndices.push(this.idxCounter); } } resetSelection() { this.selectedIndices = []; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DrawerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DrawerService }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DrawerService, decorators: [{ type: Injectable }] });