@progress/kendo-angular-layout 7.0.2-dev.202205251252 → 7.1.0-dev.202206080813

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
  * Copyright © 2021 Progress Software Corporation. All rights reserved.
3
3
  * Licensed under commercial license. See LICENSE.md in the project root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
- import { ElementRef, EventEmitter, OnDestroy } from '@angular/core';
5
+ import { ElementRef, EventEmitter, OnDestroy, SimpleChange } from '@angular/core';
6
6
  import { DrawerMode, DrawerPosition, DrawerAnimation } from './types';
7
7
  import { DrawerTemplateDirective, DrawerItemTemplateDirective, DrawerHeaderTemplateDirective, DrawerFooterTemplateDirective } from './template-directives';
8
8
  import { DrawerService } from './drawer.service';
@@ -10,6 +10,8 @@ import { DrawerSelectEvent } from './events/select-event';
10
10
  import { AnimationBuilder } from '@angular/animations';
11
11
  import { LocalizationService } from '@progress/kendo-angular-l10n';
12
12
  import { DrawerListSelectEvent } from './events/drawer-list-select.event';
13
+ import { DrawerViewItem } from './models/drawer-view-item.interface';
14
+ import { DrawerItemExpandedFn } from './models/drawer-item-expand.interface';
13
15
  import * as i0 from "@angular/core";
14
16
  /**
15
17
  * Represents the [Kendo UI Drawer component for Angular]({% slug overview_drawer %}).
@@ -96,8 +98,12 @@ export declare class DrawerComponent implements OnDestroy {
96
98
  /**
97
99
  * The collection of items that will be rendered in the Drawer.
98
100
  */
99
- set items(items: any[]);
100
- get items(): any[];
101
+ items: any[];
102
+ /**
103
+ * Defines a callback function which determines if an item should be expanded.
104
+ */
105
+ set isItemExpanded(fn: DrawerItemExpandedFn);
106
+ get isItemExpanded(): DrawerItemExpandedFn;
101
107
  /**
102
108
  * @hidden
103
109
  */
@@ -148,11 +154,12 @@ export declare class DrawerComponent implements OnDestroy {
148
154
  * @hidden
149
155
  */
150
156
  itemTemplate: DrawerItemTemplateDirective;
157
+ viewItems: DrawerViewItem[];
151
158
  private animationEnd;
152
159
  private dynamicRTLSubscription;
153
160
  private rtl;
154
- private _items;
155
161
  constructor(element: ElementRef, builder: AnimationBuilder, localizationService: LocalizationService, drawerService: DrawerService);
162
+ ngOnChanges(changes: SimpleChange): void;
156
163
  ngOnDestroy(): void;
157
164
  /**
158
165
  * @hidden
@@ -177,5 +184,5 @@ export declare class DrawerComponent implements OnDestroy {
177
184
  private animate;
178
185
  private createPlayer;
179
186
  static ɵfac: i0.ɵɵFactoryDeclaration<DrawerComponent, never>;
180
- static ɵcmp: i0.ɵɵComponentDeclaration<DrawerComponent, "kendo-drawer", ["kendoDrawer"], { "mode": "mode"; "position": "position"; "mini": "mini"; "expanded": "expanded"; "width": "width"; "miniWidth": "miniWidth"; "autoCollapse": "autoCollapse"; "items": "items"; "animation": "animation"; }, { "expand": "expand"; "collapse": "collapse"; "select": "select"; "expandedChange": "expandedChange"; }, ["drawerTemplate", "footerTemplate", "headerTemplate", "itemTemplate"], never>;
187
+ static ɵcmp: i0.ɵɵComponentDeclaration<DrawerComponent, "kendo-drawer", ["kendoDrawer"], { "mode": "mode"; "position": "position"; "mini": "mini"; "expanded": "expanded"; "width": "width"; "miniWidth": "miniWidth"; "autoCollapse": "autoCollapse"; "items": "items"; "isItemExpanded": "isItemExpanded"; "animation": "animation"; }, { "expand": "expand"; "collapse": "collapse"; "select": "select"; "expandedChange": "expandedChange"; }, ["drawerTemplate", "footerTemplate", "headerTemplate", "itemTemplate"], never>;
181
188
  }
@@ -2,15 +2,31 @@
2
2
  * Copyright © 2021 Progress Software Corporation. All rights reserved.
3
3
  * Licensed under commercial license. See LICENSE.md in the project root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
+ import { DrawerItemExpandedFn } from './models/drawer-item-expand.interface';
6
+ import { DrawerViewItem } from './models/drawer-view-item.interface';
5
7
  import * as i0 from "@angular/core";
8
+ /**
9
+ * @hidden
10
+ */
11
+ export declare const defaultIsItemExpanded: (_item: any) => boolean;
6
12
  /**
7
13
  * @hidden
8
14
  */
9
15
  export declare class DrawerService {
10
16
  owner: any;
11
17
  selectedIndices: Array<number>;
18
+ viewData: Set<DrawerViewItem>;
19
+ private originalItems;
20
+ private idxCounter;
21
+ init(): void;
22
+ get view(): Array<DrawerViewItem>;
23
+ private populateViewData;
24
+ private resetViewData;
25
+ private loadChildren;
26
+ isItemExpanded: DrawerItemExpandedFn;
12
27
  onSelect(selectedIdx: number): void;
13
- initSelection(): void;
28
+ private setSelection;
29
+ resetSelection(): void;
14
30
  static ɵfac: i0.ɵɵFactoryDeclaration<DrawerService, never>;
15
31
  static ɵprov: i0.ɵɵInjectableDeclaration<DrawerService>;
16
32
  }
@@ -2,17 +2,18 @@
2
2
  * Copyright © 2021 Progress Software Corporation. All rights reserved.
3
3
  * Licensed under commercial license. See LICENSE.md in the project root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
- import { TemplateRef, ElementRef, Renderer2 } from "@angular/core";
5
+ import { TemplateRef, ElementRef, Renderer2, AfterViewInit } from "@angular/core";
6
6
  import { DrawerService } from './drawer.service';
7
+ import { DrawerViewItem } from "./models/drawer-view-item.interface";
7
8
  import * as i0 from "@angular/core";
8
9
  /**
9
10
  * @hidden
10
11
  */
11
- export declare class DrawerItemComponent {
12
+ export declare class DrawerItemComponent implements AfterViewInit {
12
13
  drawer: DrawerService;
13
14
  private element;
14
15
  private renderer;
15
- item: any;
16
+ viewItem: DrawerViewItem;
16
17
  index: number;
17
18
  itemTemplate: TemplateRef<any>;
18
19
  mini: boolean;
@@ -24,14 +25,9 @@ export declare class DrawerItemComponent {
24
25
  get selectedClass(): boolean;
25
26
  get label(): boolean;
26
27
  constructor(drawer: DrawerService, element: ElementRef, renderer: Renderer2);
27
- /**
28
- * @hidden
29
- */
30
28
  ngAfterViewInit(): void;
31
- /**
32
- * @hidden
33
- */
34
29
  get iconClasses(): string[];
30
+ get item(): any;
35
31
  static ɵfac: i0.ɵɵFactoryDeclaration<DrawerItemComponent, never>;
36
- static ɵcmp: i0.ɵɵComponentDeclaration<DrawerItemComponent, "[kendoDrawerItem]", never, { "item": "item"; "index": "index"; "itemTemplate": "itemTemplate"; "mini": "mini"; "expanded": "expanded"; "disabled": "disabled"; "cssClass": "cssClass"; "cssStyle": "cssStyle"; }, {}, never, never>;
32
+ static ɵcmp: i0.ɵɵComponentDeclaration<DrawerItemComponent, "[kendoDrawerItem]", never, { "viewItem": "viewItem"; "index": "index"; "itemTemplate": "itemTemplate"; "mini": "mini"; "expanded": "expanded"; "disabled": "disabled"; "cssClass": "cssClass"; "cssStyle": "cssStyle"; }, {}, never, never>;
37
33
  }
@@ -2,9 +2,10 @@
2
2
  * Copyright © 2021 Progress Software Corporation. All rights reserved.
3
3
  * Licensed under commercial license. See LICENSE.md in the project root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
- import { ElementRef, NgZone, OnDestroy, OnInit, Renderer2, TemplateRef, ChangeDetectorRef, EventEmitter } from "@angular/core";
5
+ import { ElementRef, NgZone, OnDestroy, OnInit, Renderer2, TemplateRef, EventEmitter } from "@angular/core";
6
6
  import { DrawerService } from './drawer.service';
7
7
  import { DrawerListSelectEvent } from './events/drawer-list-select.event';
8
+ import { DrawerViewItem } from './models/drawer-view-item.interface';
8
9
  import * as i0 from "@angular/core";
9
10
  /**
10
11
  * @hidden
@@ -13,22 +14,21 @@ export declare class DrawerListComponent implements OnInit, OnDestroy {
13
14
  private drawerService;
14
15
  private renderer;
15
16
  private ngZone;
16
- private changeDetector;
17
17
  element: ElementRef;
18
- items: any[];
19
18
  itemTemplate: TemplateRef<any>;
20
19
  mini: boolean;
21
20
  expanded: boolean;
21
+ view: DrawerViewItem[];
22
22
  select: EventEmitter<DrawerListSelectEvent>;
23
23
  private subscriptions;
24
- constructor(drawerService: DrawerService, renderer: Renderer2, ngZone: NgZone, changeDetector: ChangeDetectorRef, element: ElementRef);
24
+ constructor(drawerService: DrawerService, renderer: Renderer2, ngZone: NgZone, element: ElementRef);
25
25
  ngOnInit(): void;
26
26
  ngOnDestroy(): void;
27
- private initialSelection;
27
+ identifyItem(_index: number, viewItem: DrawerViewItem): any;
28
28
  private initDomEvents;
29
29
  private clickHandler;
30
30
  private keyDownHandler;
31
31
  private getDrawerItemIndex;
32
32
  static ɵfac: i0.ɵɵFactoryDeclaration<DrawerListComponent, never>;
33
- static ɵcmp: i0.ɵɵComponentDeclaration<DrawerListComponent, "[kendoDrawerList]", never, { "items": "items"; "itemTemplate": "itemTemplate"; "mini": "mini"; "expanded": "expanded"; }, { "select": "select"; }, never, never>;
33
+ static ɵcmp: i0.ɵɵComponentDeclaration<DrawerListComponent, "[kendoDrawerList]", never, { "itemTemplate": "itemTemplate"; "mini": "mini"; "expanded": "expanded"; "view": "view"; }, { "select": "select"; }, never, never>;
34
34
  }
@@ -0,0 +1,8 @@
1
+ /**-----------------------------------------------------------------------------------------
2
+ * Copyright © 2021 Progress Software Corporation. All rights reserved.
3
+ * Licensed under commercial license. See LICENSE.md in the project root for more information
4
+ *-------------------------------------------------------------------------------------------*/
5
+ /**
6
+ * Represents the callback that is used by the [isItemExpanded]({% slug api_layout_drawercomponent %}#toc-isItemExpanded) property. ([see example]({% slug hierarchical_drawer %})).
7
+ */
8
+ export declare type DrawerItemExpandedFn = (item: any) => boolean;
@@ -31,6 +31,14 @@ export interface DrawerItem {
31
31
  * Allows the usage of custom icons.
32
32
  */
33
33
  iconClass?: string;
34
+ /**
35
+ * Specifies the id of the Drawer item.
36
+ */
37
+ id?: number | string;
38
+ /**
39
+ * Specifies the parentId of the Drawer item.
40
+ */
41
+ parentId?: number | string;
34
42
  /**
35
43
  * Specifies if the Drawer item is initially selected.
36
44
  */
@@ -0,0 +1,29 @@
1
+ /**-----------------------------------------------------------------------------------------
2
+ * Copyright © 2021 Progress Software Corporation. All rights reserved.
3
+ * Licensed under commercial license. See LICENSE.md in the project root for more information
4
+ *-------------------------------------------------------------------------------------------*/
5
+ /**
6
+ * @hidden
7
+ */
8
+ export interface DrawerViewItem {
9
+ /**
10
+ * A reference to the original data item
11
+ */
12
+ item: any;
13
+ /**
14
+ * The item index in the view data items collection
15
+ */
16
+ index: number;
17
+ /**
18
+ * The hierarchical level of the item
19
+ */
20
+ level: number;
21
+ /**
22
+ * Indicates whether the item has children
23
+ */
24
+ hasChildren: boolean;
25
+ /**
26
+ * Indicates whether the item is currently expanded
27
+ */
28
+ isExpanded: boolean;
29
+ }
@@ -2,7 +2,7 @@
2
2
  * Copyright © 2021 Progress Software Corporation. All rights reserved.
3
3
  * Licensed under commercial license. See LICENSE.md in the project root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
- import { Component, ContentChild, EventEmitter, HostBinding, Input, Output } from '@angular/core';
5
+ import { Component, ContentChild, EventEmitter, HostBinding, Input, Output, isDevMode } from '@angular/core';
6
6
  import { validatePackage } from '@progress/kendo-licensing';
7
7
  import { packageMetadata } from '../package-metadata';
8
8
  import { DrawerTemplateDirective, DrawerItemTemplateDirective, DrawerHeaderTemplateDirective, DrawerFooterTemplateDirective } from './template-directives';
@@ -97,6 +97,10 @@ export class DrawerComponent {
97
97
  * or the overlay is clicked. Defaults to `true`.
98
98
  */
99
99
  this.autoCollapse = true;
100
+ /**
101
+ * The collection of items that will be rendered in the Drawer.
102
+ */
103
+ this.items = [];
100
104
  /**
101
105
  * Specifies the animation settings of the Drawer.
102
106
  * ([see example]({% slug interaction_drawer %}#toc-toggling-between-states)).
@@ -129,7 +133,6 @@ export class DrawerComponent {
129
133
  this.expandedChange = new EventEmitter();
130
134
  this.animationEnd = new EventEmitter();
131
135
  this.rtl = false;
132
- this._items = [];
133
136
  validatePackage(packageMetadata);
134
137
  this.dynamicRTLSubscription = this.localizationService.changes.subscribe(({ rtl }) => {
135
138
  this.rtl = rtl;
@@ -162,16 +165,23 @@ export class DrawerComponent {
162
165
  return this.drawerWidth;
163
166
  }
164
167
  /**
165
- * The collection of items that will be rendered in the Drawer.
168
+ * Defines a callback function which determines if an item should be expanded.
166
169
  */
167
- set items(items) {
168
- if (isPresent(items)) {
169
- this._items = items;
170
- this.drawerService.initSelection();
170
+ set isItemExpanded(fn) {
171
+ if (isDevMode && isPresent(fn) && typeof fn !== 'function') {
172
+ throw new Error(`isItemExpanded must be a function, but received ${JSON.stringify(fn)}.`);
171
173
  }
174
+ this.drawerService.isItemExpanded = fn;
172
175
  }
173
- get items() {
174
- return this._items;
176
+ get isItemExpanded() {
177
+ return this.drawerService.isItemExpanded;
178
+ }
179
+ ngOnChanges(changes) {
180
+ if (changes && changes['items']) {
181
+ this.drawerService.resetSelection();
182
+ this.drawerService.init();
183
+ this.viewItems = this.drawerService.view;
184
+ }
175
185
  }
176
186
  ngOnDestroy() {
177
187
  if (this.dynamicRTLSubscription) {
@@ -263,14 +273,14 @@ export class DrawerComponent {
263
273
  }
264
274
  }
265
275
  DrawerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: DrawerComponent, deps: [{ token: i0.ElementRef }, { token: i1.AnimationBuilder }, { token: i2.LocalizationService }, { token: i3.DrawerService }], target: i0.ɵɵFactoryTarget.Component });
266
- DrawerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: DrawerComponent, selector: "kendo-drawer", inputs: { mode: "mode", position: "position", mini: "mini", expanded: "expanded", width: "width", miniWidth: "miniWidth", autoCollapse: "autoCollapse", items: "items", animation: "animation" }, outputs: { expand: "expand", collapse: "collapse", select: "select", expandedChange: "expandedChange" }, host: { properties: { "class.k-widget": "this.hostClasses", "class.k-drawer": "this.hostClasses", "class.k-drawer-start": "this.startPositionClass", "class.k-drawer-end": "this.endPositionClass", "style.transform": "this.overlayTransofrmStyles", "style.flexBasis.px": "this.flexStyles", "attr.dir": "this.direction" } }, providers: [
276
+ DrawerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: DrawerComponent, selector: "kendo-drawer", inputs: { mode: "mode", position: "position", mini: "mini", expanded: "expanded", width: "width", miniWidth: "miniWidth", autoCollapse: "autoCollapse", items: "items", isItemExpanded: "isItemExpanded", animation: "animation" }, outputs: { expand: "expand", collapse: "collapse", select: "select", expandedChange: "expandedChange" }, host: { properties: { "class.k-widget": "this.hostClasses", "class.k-drawer": "this.hostClasses", "class.k-drawer-start": "this.startPositionClass", "class.k-drawer-end": "this.endPositionClass", "style.transform": "this.overlayTransofrmStyles", "style.flexBasis.px": "this.flexStyles", "attr.dir": "this.direction" } }, providers: [
267
277
  LocalizationService,
268
278
  DrawerService,
269
279
  {
270
280
  provide: L10N_PREFIX,
271
281
  useValue: 'kendo.drawer'
272
282
  }
273
- ], queries: [{ propertyName: "drawerTemplate", first: true, predicate: DrawerTemplateDirective, descendants: true }, { propertyName: "footerTemplate", first: true, predicate: DrawerFooterTemplateDirective, descendants: true }, { propertyName: "headerTemplate", first: true, predicate: DrawerHeaderTemplateDirective, descendants: true }, { propertyName: "itemTemplate", first: true, predicate: DrawerItemTemplateDirective, descendants: true }], exportAs: ["kendoDrawer"], ngImport: i0, template: `
283
+ ], queries: [{ propertyName: "drawerTemplate", first: true, predicate: DrawerTemplateDirective, descendants: true }, { propertyName: "footerTemplate", first: true, predicate: DrawerFooterTemplateDirective, descendants: true }, { propertyName: "headerTemplate", first: true, predicate: DrawerHeaderTemplateDirective, descendants: true }, { propertyName: "itemTemplate", first: true, predicate: DrawerItemTemplateDirective, descendants: true }], exportAs: ["kendoDrawer"], usesOnChanges: true, ngImport: i0, template: `
274
284
  <div class="k-drawer-wrapper" *ngIf="expanded || mini" [style.width.px]="drawerWidth">
275
285
  <ng-container *ngIf="!drawerTemplate">
276
286
  <ng-template *ngIf="headerTemplate"
@@ -279,7 +289,9 @@ DrawerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", versio
279
289
 
280
290
  <ul kendoDrawerList
281
291
  (select)="onSelect($event)"
282
- [items]="items" [mini]="mini" [expanded]="expanded"
292
+ [mini]="mini"
293
+ [expanded]="expanded"
294
+ [view]="viewItems"
283
295
  [itemTemplate]="itemTemplate?.templateRef"
284
296
  class="k-drawer-items">
285
297
  </ul>
@@ -293,7 +305,7 @@ DrawerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", versio
293
305
  [ngTemplateOutlet]="drawerTemplate?.templateRef">
294
306
  </ng-template>
295
307
  </div>
296
- `, isInline: true, components: [{ type: i4.DrawerListComponent, selector: "[kendoDrawerList]", inputs: ["items", "itemTemplate", "mini", "expanded"], outputs: ["select"] }], directives: [{ type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i5.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }] });
308
+ `, isInline: true, components: [{ type: i4.DrawerListComponent, selector: "[kendoDrawerList]", inputs: ["itemTemplate", "mini", "expanded", "view"], outputs: ["select"] }], directives: [{ type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i5.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }] });
297
309
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: DrawerComponent, decorators: [{
298
310
  type: Component,
299
311
  args: [{
@@ -316,7 +328,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
316
328
 
317
329
  <ul kendoDrawerList
318
330
  (select)="onSelect($event)"
319
- [items]="items" [mini]="mini" [expanded]="expanded"
331
+ [mini]="mini"
332
+ [expanded]="expanded"
333
+ [view]="viewItems"
320
334
  [itemTemplate]="itemTemplate?.templateRef"
321
335
  class="k-drawer-items">
322
336
  </ul>
@@ -366,6 +380,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
366
380
  type: Input
367
381
  }], items: [{
368
382
  type: Input
383
+ }], isItemExpanded: [{
384
+ type: Input
369
385
  }], direction: [{
370
386
  type: HostBinding,
371
387
  args: ['attr.dir']
@@ -3,13 +3,56 @@
3
3
  * Licensed under commercial license. See LICENSE.md in the project root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
5
  import { Injectable } from '@angular/core';
6
+ import { isPresent } from '../common/util';
6
7
  import * as i0 from "@angular/core";
8
+ /**
9
+ * @hidden
10
+ */
11
+ export const defaultIsItemExpanded = (_item) => false;
7
12
  /**
8
13
  * @hidden
9
14
  */
10
15
  export class DrawerService {
11
16
  constructor() {
12
17
  this.selectedIndices = [];
18
+ this.originalItems = [];
19
+ this.idxCounter = 0;
20
+ this.isItemExpanded = defaultIsItemExpanded;
21
+ }
22
+ init() {
23
+ this.resetViewData();
24
+ this.originalItems = this.owner.items || [];
25
+ let rootItems = this.originalItems.filter(item => !isPresent(item.parentId));
26
+ this.populateViewData(rootItems);
27
+ }
28
+ get view() {
29
+ return Array.from(this.viewData);
30
+ }
31
+ populateViewData(items, level = 0) {
32
+ items.forEach((item) => {
33
+ this.setSelection(item);
34
+ const children = this.loadChildren(item);
35
+ const isExpanded = this.isItemExpanded(item);
36
+ this.viewData.add({
37
+ item: item,
38
+ index: this.idxCounter++,
39
+ level: level,
40
+ hasChildren: children.length > 0,
41
+ isExpanded: isExpanded
42
+ });
43
+ if (children.length > 0 && isExpanded) {
44
+ this.populateViewData(children, level + 1);
45
+ }
46
+ });
47
+ }
48
+ resetViewData() {
49
+ this.idxCounter = 0;
50
+ this.viewData = new Set();
51
+ }
52
+ loadChildren(item) {
53
+ return this.originalItems.filter(i => {
54
+ return isPresent(i.parentId) && (i.parentId === item.id);
55
+ });
13
56
  }
14
57
  onSelect(selectedIdx) {
15
58
  this.selectedIndices = [selectedIdx];
@@ -18,15 +61,14 @@ export class DrawerService {
18
61
  drawer.toggle(false);
19
62
  }
20
63
  }
21
- initSelection() {
22
- const items = this.owner.items;
23
- this.selectedIndices = [];
24
- for (let i = 0; i < items.length; i++) {
25
- if (items[i].selected) {
26
- this.selectedIndices.push(i);
27
- }
64
+ setSelection(item) {
65
+ if (this.selectedIndices.length === 0 && item.selected) {
66
+ this.selectedIndices.push(this.idxCounter);
28
67
  }
29
68
  }
69
+ resetSelection() {
70
+ this.selectedIndices = [];
71
+ }
30
72
  }
31
73
  DrawerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: DrawerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
32
74
  DrawerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: DrawerService });
@@ -25,18 +25,13 @@ export class DrawerItemComponent {
25
25
  get label() {
26
26
  return this.item.text ? this.item.text : null;
27
27
  }
28
- /**
29
- * @hidden
30
- */
31
28
  ngAfterViewInit() {
32
- const link = nestedLink(this.element.nativeElement, DRAWER_LINK_SELECTOR);
29
+ const elem = this.element.nativeElement;
30
+ const link = nestedLink(elem, DRAWER_LINK_SELECTOR);
33
31
  if (link) {
34
32
  this.renderer.removeAttribute(link, 'tabindex');
35
33
  }
36
34
  }
37
- /**
38
- * @hidden
39
- */
40
35
  get iconClasses() {
41
36
  const classes = [];
42
37
  if (this.item.icon) {
@@ -47,18 +42,31 @@ export class DrawerItemComponent {
47
42
  }
48
43
  return classes;
49
44
  }
45
+ get item() {
46
+ return this.viewItem.item;
47
+ }
50
48
  }
51
49
  DrawerItemComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: DrawerItemComponent, deps: [{ token: i1.DrawerService }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
52
- DrawerItemComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: DrawerItemComponent, selector: "[kendoDrawerItem]", inputs: { item: "item", index: "index", itemTemplate: "itemTemplate", mini: "mini", expanded: "expanded", disabled: "disabled", cssClass: "cssClass", cssStyle: "cssStyle" }, host: { properties: { "attr.aria-disabled": "this.disabledClass", "class.k-state-disabled": "this.disabledClass", "attr.aria-selected": "this.selectedClass", "class.k-state-selected": "this.selectedClass", "attr.aria-label": "this.label" } }, ngImport: i0, template: `
50
+ DrawerItemComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: DrawerItemComponent, selector: "[kendoDrawerItem]", inputs: { viewItem: "viewItem", index: "index", itemTemplate: "itemTemplate", mini: "mini", expanded: "expanded", disabled: "disabled", cssClass: "cssClass", cssStyle: "cssStyle" }, host: { properties: { "attr.aria-disabled": "this.disabledClass", "class.k-state-disabled": "this.disabledClass", "attr.aria-selected": "this.selectedClass", "class.k-state-selected": "this.selectedClass", "attr.aria-label": "this.label" } }, ngImport: i0, template: `
53
51
  <ng-template *ngIf="itemTemplate; else defaultTemplate"
54
52
  [ngTemplateOutlet]="itemTemplate"
55
- [ngTemplateOutletContext]="{ $implicit: item }">
53
+ [ngTemplateOutletContext]="{
54
+ $implicit: item,
55
+ isItemExpanded: viewItem.isExpanded,
56
+ hasChildren: viewItem.hasChildren,
57
+ level: viewItem.level
58
+ }">
56
59
  </ng-template>
57
60
 
58
61
  <ng-template #defaultTemplate>
59
62
  <ng-container *ngIf="expanded">
60
63
  <span [ngClass]="iconClasses"></span>
61
64
  <span class="k-item-text">{{ item.text }}</span>
65
+ <span *ngIf="viewItem.hasChildren"
66
+ class="k-icon k-drawer-toggle"
67
+ [class.k-i-arrow-chevron-up]="viewItem.isExpanded"
68
+ [class.k-i-arrow-chevron-down]="!viewItem.isExpanded"
69
+ ></span>
62
70
  </ng-container>
63
71
  <ng-container *ngIf="mini && !expanded">
64
72
  <span [ngClass]="iconClasses"></span>
@@ -73,13 +81,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
73
81
  template: `
74
82
  <ng-template *ngIf="itemTemplate; else defaultTemplate"
75
83
  [ngTemplateOutlet]="itemTemplate"
76
- [ngTemplateOutletContext]="{ $implicit: item }">
84
+ [ngTemplateOutletContext]="{
85
+ $implicit: item,
86
+ isItemExpanded: viewItem.isExpanded,
87
+ hasChildren: viewItem.hasChildren,
88
+ level: viewItem.level
89
+ }">
77
90
  </ng-template>
78
91
 
79
92
  <ng-template #defaultTemplate>
80
93
  <ng-container *ngIf="expanded">
81
94
  <span [ngClass]="iconClasses"></span>
82
95
  <span class="k-item-text">{{ item.text }}</span>
96
+ <span *ngIf="viewItem.hasChildren"
97
+ class="k-icon k-drawer-toggle"
98
+ [class.k-i-arrow-chevron-up]="viewItem.isExpanded"
99
+ [class.k-i-arrow-chevron-down]="!viewItem.isExpanded"
100
+ ></span>
83
101
  </ng-container>
84
102
  <ng-container *ngIf="mini && !expanded">
85
103
  <span [ngClass]="iconClasses"></span>
@@ -87,7 +105,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
87
105
  </ng-template>
88
106
  `
89
107
  }]
90
- }], ctorParameters: function () { return [{ type: i1.DrawerService }, { type: i0.ElementRef }, { type: i0.Renderer2 }]; }, propDecorators: { item: [{
108
+ }], ctorParameters: function () { return [{ type: i1.DrawerService }, { type: i0.ElementRef }, { type: i0.Renderer2 }]; }, propDecorators: { viewItem: [{
91
109
  type: Input
92
110
  }], index: [{
93
111
  type: Input
@@ -17,27 +17,24 @@ import * as i3 from "@angular/common";
17
17
  * @hidden
18
18
  */
19
19
  export class DrawerListComponent {
20
- constructor(drawerService, renderer, ngZone, changeDetector, element) {
20
+ constructor(drawerService, renderer, ngZone, element) {
21
21
  this.drawerService = drawerService;
22
22
  this.renderer = renderer;
23
23
  this.ngZone = ngZone;
24
- this.changeDetector = changeDetector;
25
24
  this.element = element;
25
+ this.view = [];
26
26
  this.select = new EventEmitter();
27
27
  this.subscriptions = new Subscription();
28
28
  }
29
29
  ngOnInit() {
30
- this.initialSelection();
31
30
  this.initDomEvents();
32
31
  }
33
32
  ngOnDestroy() {
34
33
  this.subscriptions.unsubscribe();
35
34
  }
36
- initialSelection() {
37
- /* Differentiates a user selected item */
38
- if (this.drawerService.selectedIndices.length === 0) {
39
- this.drawerService.initSelection();
40
- }
35
+ identifyItem(_index, viewItem) {
36
+ var _a;
37
+ return (_a = viewItem.item.id) !== null && _a !== void 0 ? _a : viewItem.index;
41
38
  }
42
39
  initDomEvents() {
43
40
  if (!this.element) {
@@ -50,26 +47,27 @@ export class DrawerListComponent {
50
47
  });
51
48
  }
52
49
  clickHandler(e) {
53
- const itemIdx = this.getDrawerItemIndex(e.target);
54
- const item = this.items[itemIdx];
55
- if (!item) {
50
+ const viewItemIdx = this.getDrawerItemIndex(e.target);
51
+ const viewItem = this.view[viewItemIdx];
52
+ if (!viewItem) {
56
53
  return;
57
54
  }
58
- if (item.disabled) {
55
+ if (viewItem.item.disabled) {
59
56
  e.preventDefault();
60
57
  return;
61
58
  }
62
59
  const args = {
63
- index: itemIdx,
64
- item: item,
60
+ index: viewItem.index,
61
+ item: viewItem.item,
65
62
  originalEvent: e
66
63
  };
67
64
  this.ngZone.run(() => {
68
65
  const event = new DrawerListSelectEvent(args);
69
66
  this.select.emit(event);
70
67
  if (!event.isDefaultPrevented()) {
71
- this.drawerService.onSelect(itemIdx);
72
- this.changeDetector.detectChanges();
68
+ this.drawerService.onSelect(viewItemIdx);
69
+ this.drawerService.init();
70
+ this.view = this.drawerService.view;
73
71
  }
74
72
  });
75
73
  }
@@ -92,45 +90,45 @@ export class DrawerListComponent {
92
90
  }
93
91
  }
94
92
  }
95
- DrawerListComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: DrawerListComponent, deps: [{ token: i1.DrawerService }, { token: i0.Renderer2 }, { token: i0.NgZone }, { token: i0.ChangeDetectorRef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
96
- DrawerListComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: DrawerListComponent, selector: "[kendoDrawerList]", inputs: { items: "items", itemTemplate: "itemTemplate", mini: "mini", expanded: "expanded" }, outputs: { select: "select" }, ngImport: i0, template: "\n <ng-container *ngFor=\"let item of items; let idx = index\">\n <li *ngIf=\"!item.separator\" kendoDrawerItem\n class=\"k-drawer-item\"\n [item]=\"item\"\n [index]=\"idx\"\n [mini]=\"mini\"\n [expanded]=\"expanded\"\n [itemTemplate]=\"itemTemplate\"\n [attr.data-kendo-drawer-index]=\"idx\"\n [ngClass]=\"item.cssClass\"\n [ngStyle]=\"item.cssStyle\"\n tabindex=\"0\">\n </li>\n\n <li *ngIf=\"item.separator\"\n class=\"k-drawer-item k-drawer-separator\"\n [ngClass]=\"item.cssClass\"\n [ngStyle]=\"item.cssStyle\">\n &nbsp;\n </li>\n </ng-container>\n ", isInline: true, components: [{ type: i2.DrawerItemComponent, selector: "[kendoDrawerItem]", inputs: ["item", "index", "itemTemplate", "mini", "expanded", "disabled", "cssClass", "cssStyle"] }], directives: [{ type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i3.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] });
93
+ DrawerListComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: DrawerListComponent, deps: [{ token: i1.DrawerService }, { token: i0.Renderer2 }, { token: i0.NgZone }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
94
+ DrawerListComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: DrawerListComponent, selector: "[kendoDrawerList]", inputs: { itemTemplate: "itemTemplate", mini: "mini", expanded: "expanded", view: "view" }, outputs: { select: "select" }, ngImport: i0, template: "\n <ng-container *ngFor=\"let v of view; trackBy:identifyItem; let idx = index\">\n <li *ngIf=\"!v.item.separator\" kendoDrawerItem\n class=\"k-drawer-item {{expanded ? ' k-level-' + v.level : ''}}\"\n [viewItem]=\"v\"\n [index]=\"idx\"\n [mini]=\"mini\"\n [expanded]=\"expanded\"\n [itemTemplate]=\"itemTemplate\"\n [attr.data-kendo-drawer-index]=\"v.index\"\n [ngClass]=\"v.item.cssClass\"\n [ngStyle]=\"v.item.cssStyle\"\n tabindex=\"0\">\n </li>\n\n <li *ngIf=\"v.item.separator\"\n class=\"k-drawer-item k-drawer-separator\"\n [ngClass]=\"v.item.cssClass\"\n [ngStyle]=\"v.item.cssStyle\">\n &nbsp;\n </li>\n </ng-container>\n ", isInline: true, components: [{ type: i2.DrawerItemComponent, selector: "[kendoDrawerItem]", inputs: ["viewItem", "index", "itemTemplate", "mini", "expanded", "disabled", "cssClass", "cssStyle"] }], directives: [{ type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i3.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] });
97
95
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: DrawerListComponent, decorators: [{
98
96
  type: Component,
99
97
  args: [{
100
98
  // eslint-disable-next-line @angular-eslint/component-selector
101
99
  selector: '[kendoDrawerList]',
102
100
  template: `
103
- <ng-container *ngFor="let item of items; let idx = index">
104
- <li *ngIf="!item.separator" kendoDrawerItem
105
- class="k-drawer-item"
106
- [item]="item"
101
+ <ng-container *ngFor="let v of view; trackBy:identifyItem; let idx = index">
102
+ <li *ngIf="!v.item.separator" kendoDrawerItem
103
+ class="k-drawer-item {{expanded ? ' k-level-' + v.level : ''}}"
104
+ [viewItem]="v"
107
105
  [index]="idx"
108
106
  [mini]="mini"
109
107
  [expanded]="expanded"
110
108
  [itemTemplate]="itemTemplate"
111
- [attr.${DRAWER_ITEM_INDEX}]="idx"
112
- [ngClass]="item.cssClass"
113
- [ngStyle]="item.cssStyle"
109
+ [attr.${DRAWER_ITEM_INDEX}]="v.index"
110
+ [ngClass]="v.item.cssClass"
111
+ [ngStyle]="v.item.cssStyle"
114
112
  tabindex="0">
115
113
  </li>
116
114
 
117
- <li *ngIf="item.separator"
115
+ <li *ngIf="v.item.separator"
118
116
  class="k-drawer-item k-drawer-separator"
119
- [ngClass]="item.cssClass"
120
- [ngStyle]="item.cssStyle">
117
+ [ngClass]="v.item.cssClass"
118
+ [ngStyle]="v.item.cssStyle">
121
119
  &nbsp;
122
120
  </li>
123
121
  </ng-container>
124
122
  `
125
123
  }]
126
- }], ctorParameters: function () { return [{ type: i1.DrawerService }, { type: i0.Renderer2 }, { type: i0.NgZone }, { type: i0.ChangeDetectorRef }, { type: i0.ElementRef }]; }, propDecorators: { items: [{
127
- type: Input
128
- }], itemTemplate: [{
124
+ }], ctorParameters: function () { return [{ type: i1.DrawerService }, { type: i0.Renderer2 }, { type: i0.NgZone }, { type: i0.ElementRef }]; }, propDecorators: { itemTemplate: [{
129
125
  type: Input
130
126
  }], mini: [{
131
127
  type: Input
132
128
  }], expanded: [{
133
129
  type: Input
130
+ }], view: [{
131
+ type: Input
134
132
  }], select: [{
135
133
  type: Output
136
134
  }] } });