@progress/kendo-angular-treeview 5.4.2-dev.202111011443 → 6.0.0-dev.202112021059

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 { EventEmitter, OnDestroy } from '@angular/core';
5
+ import { EventEmitter, OnDestroy, OnChanges, SimpleChanges } from '@angular/core';
6
6
  import { TreeViewComponent } from '../treeview.component';
7
7
  import { SelectableSettings } from './selectable-settings';
8
8
  import { Subscription } from 'rxjs';
@@ -11,7 +11,7 @@ import { TreeItem } from '../treeitem.interface';
11
11
  * A directive which manages the in-memory selection state of the TreeView node
12
12
  * ([see example]({% slug selection_treeview %})).
13
13
  */
14
- export declare class SelectDirective implements OnDestroy {
14
+ export declare class SelectDirective implements OnDestroy, OnChanges {
15
15
  protected treeView: TreeViewComponent;
16
16
  /**
17
17
  * @hidden
@@ -39,8 +39,16 @@ export declare class SelectDirective implements OnDestroy {
39
39
  protected subscriptions: Subscription;
40
40
  private readonly options;
41
41
  private selectActions;
42
- private _selectedKeys;
42
+ /**
43
+ * Reflectes the internal `selectedKeys` state.
44
+ */
45
+ private state;
46
+ /**
47
+ * Holds the last emitted `selectedKeys` collection.
48
+ */
49
+ private lastChange;
43
50
  constructor(treeView: TreeViewComponent);
51
+ ngOnChanges(changes: SimpleChanges): void;
44
52
  ngOnDestroy(): void;
45
53
  protected itemKey(e: any): any;
46
54
  protected select(e: any): void;
@@ -7,6 +7,7 @@ import { Directive, EventEmitter, HostBinding, Input, Output } from '@angular/co
7
7
  import { TreeViewComponent } from '../treeview.component';
8
8
  import { isBoolean, isPresent, noop } from '../utils';
9
9
  import { Subscription } from 'rxjs';
10
+ import { isChanged } from '@progress/kendo-angular-common';
10
11
  /**
11
12
  * A directive which manages the in-memory selection state of the TreeView node
12
13
  * ([see example]({% slug selection_treeview %})).
@@ -23,9 +24,12 @@ let SelectDirective = class SelectDirective {
23
24
  'multiple': (e) => this.selectMultiple(e),
24
25
  'single': (e) => this.selectSingle(e)
25
26
  };
26
- this._selectedKeys = [];
27
+ /**
28
+ * Reflectes the internal `selectedKeys` state.
29
+ */
30
+ this.state = new Set();
27
31
  this.subscriptions.add(this.treeView.selectionChange.subscribe(this.select.bind(this)));
28
- this.treeView.isSelected = (dataItem, index) => (this.selectedKeys.indexOf(this.itemKey({ dataItem, index })) > -1);
32
+ this.treeView.isSelected = (dataItem, index) => (this.state.has(this.itemKey({ dataItem, index })));
29
33
  }
30
34
  /**
31
35
  * @hidden
@@ -33,16 +37,6 @@ let SelectDirective = class SelectDirective {
33
37
  set isSelected(value) {
34
38
  this.treeView.isSelected = value;
35
39
  }
36
- /**
37
- * Defines the collection that will store the selected keys
38
- * ([see example]({% slug selection_treeview %}#toc-selection-modes)).
39
- */
40
- get selectedKeys() {
41
- return this._selectedKeys;
42
- }
43
- set selectedKeys(keys) {
44
- this._selectedKeys = keys;
45
- }
46
40
  get getAriaMultiselectable() {
47
41
  return this.options.mode === 'multiple';
48
42
  }
@@ -57,6 +51,11 @@ let SelectDirective = class SelectDirective {
57
51
  const selectionSettings = isBoolean(this.selection) ? { enabled: this.selection } : this.selection;
58
52
  return Object.assign(defaultOptions, selectionSettings);
59
53
  }
54
+ ngOnChanges(changes) {
55
+ if (isChanged('selectedKeys', changes, false) && changes.selectedKeys.currentValue !== this.lastChange) {
56
+ this.state = new Set(changes.selectedKeys.currentValue);
57
+ }
58
+ }
60
59
  ngOnDestroy() {
61
60
  this.subscriptions.unsubscribe();
62
61
  }
@@ -81,29 +80,29 @@ let SelectDirective = class SelectDirective {
81
80
  }
82
81
  selectSingle(node) {
83
82
  const key = this.itemKey(node);
84
- if (this.selectedKeys[0] === key) {
85
- return;
83
+ if (!this.state.has(key)) {
84
+ this.state.clear();
85
+ this.state.add(key);
86
+ this.notify();
86
87
  }
87
- this.selectedKeys = [key];
88
- this.notify();
89
88
  }
90
89
  selectMultiple(node) {
91
90
  const key = this.itemKey(node);
92
- const idx = this.selectedKeys.indexOf(key);
93
- const isSelected = idx > -1;
91
+ const isSelected = this.state.has(key);
94
92
  if (!isPresent(key)) {
95
93
  return;
96
94
  }
97
95
  if (isSelected) {
98
- this.selectedKeys.splice(idx, 1);
96
+ this.state.delete(key);
99
97
  }
100
98
  else {
101
- this.selectedKeys.push(key);
99
+ this.state.add(key);
102
100
  }
103
101
  this.notify();
104
102
  }
105
103
  notify() {
106
- this.selectedKeysChange.emit(this.selectedKeys.slice());
104
+ this.lastChange = Array.from(this.state);
105
+ this.selectedKeysChange.emit(this.lastChange);
107
106
  }
108
107
  };
109
108
  tslib_1.__decorate([
@@ -121,9 +120,8 @@ tslib_1.__decorate([
121
120
  ], SelectDirective.prototype, "selection", void 0);
122
121
  tslib_1.__decorate([
123
122
  Input(),
124
- tslib_1.__metadata("design:type", Array),
125
- tslib_1.__metadata("design:paramtypes", [Array])
126
- ], SelectDirective.prototype, "selectedKeys", null);
123
+ tslib_1.__metadata("design:type", Array)
124
+ ], SelectDirective.prototype, "selectedKeys", void 0);
127
125
  tslib_1.__decorate([
128
126
  Output(),
129
127
  tslib_1.__metadata("design:type", EventEmitter)
@@ -32,6 +32,8 @@ export interface TreeViewFilterSettings {
32
32
  * Determines the behavior of the filtering algorithm.
33
33
  * - `"strict"`—does not show child nodes of filter matches. Instead, only matching nodes themselves are displayed.
34
34
  * - `"lenient"`—all child nodes of each filter match are included in the filter results.
35
+ *
36
+ * The default mode is `"lenient"`
35
37
  */
36
38
  mode?: "strict" | "lenient";
37
39
  }
@@ -25,9 +25,10 @@ import { FilterState } from './filter-state.interface';
25
25
  * Represents the [Kendo UI TreeView component for Angular]({% slug overview_treeview %}).
26
26
  *
27
27
  * @example
28
- * {% meta height:350 %}
29
- * {% embed_file basic-usage/app.component.ts preview %}
30
- * {% embed_file basic-usage/app.module.ts %}
28
+ * {% meta height:450 %}
29
+ * {% embed_file get-started/app.component.ts preview %}
30
+ * {% embed_file get-started/app.module.ts %}
31
+ * {% embed_file shared/main.ts %}
31
32
  * {% endmeta %}
32
33
  */
33
34
  export declare class TreeViewComponent implements OnChanges, OnInit, OnDestroy, DataBoundComponent {
@@ -145,18 +146,30 @@ export declare class TreeViewComponent implements OnChanges, OnInit, OnDestroy,
145
146
  nodeDblClick: EventEmitter<NodeClickEvent>;
146
147
  /**
147
148
  * @hidden
149
+ *
150
+ * Queries the template for a node template declaration.
151
+ * Ignored if a `[nodeTemplate]` value is explicitly provided.
148
152
  */
149
- nodeTemplate: NodeTemplateDirective;
153
+ nodeTemplateQuery: NodeTemplateDirective;
150
154
  /**
151
155
  * @hidden
156
+ *
157
+ * Defines the template for each node.
158
+ * Takes precedence over nested templates in the TreeView tag.
152
159
  */
153
160
  nodeTemplateRef: NodeTemplateDirective;
154
161
  /**
155
162
  * @hidden
163
+ *
164
+ * Queries the template for a load-more button template declaration.
165
+ * Ignored if a `[loadMoreButtonTemplate]` value is explicitly provided.
156
166
  */
157
- loadMoreButtonTemplate: LoadMoreButtonTemplateDirective;
167
+ loadMoreButtonTemplateQuery: LoadMoreButtonTemplateDirective;
158
168
  /**
159
169
  * @hidden
170
+ *
171
+ * Defines the template for each load-more button.
172
+ * Takes precedence over nested templates in the TreeView tag.
160
173
  */
161
174
  loadMoreButtonTemplateRef: LoadMoreButtonTemplateDirective;
162
175
  /**
@@ -272,6 +285,8 @@ export declare class TreeViewComponent implements OnChanges, OnInit, OnDestroy,
272
285
  private _isExpanded;
273
286
  private _isSelected;
274
287
  private _hasChildren;
288
+ private _nodeTemplateRef;
289
+ private _loadMoreButtonTemplateRef;
275
290
  private subscriptions;
276
291
  private domSubscriptions;
277
292
  constructor(element: ElementRef<HTMLElement>, changeDetectorRef: ChangeDetectorRef, expandService: ExpandStateService, navigationService: NavigationService, nodeChildrenService: NodeChildrenService, selectionService: SelectionService, treeViewLookupService: TreeViewLookupService, ngZone: NgZone, renderer: Renderer2, dataChangeNotification: DataChangeNotificationService, localization: LocalizationService);
@@ -52,9 +52,10 @@ const providers = [
52
52
  * Represents the [Kendo UI TreeView component for Angular]({% slug overview_treeview %}).
53
53
  *
54
54
  * @example
55
- * {% meta height:350 %}
56
- * {% embed_file basic-usage/app.component.ts preview %}
57
- * {% embed_file basic-usage/app.module.ts %}
55
+ * {% meta height:450 %}
56
+ * {% embed_file get-started/app.component.ts preview %}
57
+ * {% embed_file get-started/app.module.ts %}
58
+ * {% embed_file shared/main.ts %}
58
59
  * {% endmeta %}
59
60
  */
60
61
  let TreeViewComponent = class TreeViewComponent {
@@ -247,15 +248,27 @@ let TreeViewComponent = class TreeViewComponent {
247
248
  }
248
249
  /**
249
250
  * @hidden
251
+ *
252
+ * Defines the template for each node.
253
+ * Takes precedence over nested templates in the TreeView tag.
250
254
  */
251
255
  set nodeTemplateRef(template) {
252
- this.nodeTemplate = template;
256
+ this._nodeTemplateRef = template;
257
+ }
258
+ get nodeTemplateRef() {
259
+ return this._nodeTemplateRef || this.nodeTemplateQuery;
253
260
  }
254
261
  /**
255
262
  * @hidden
263
+ *
264
+ * Defines the template for each load-more button.
265
+ * Takes precedence over nested templates in the TreeView tag.
256
266
  */
257
267
  set loadMoreButtonTemplateRef(template) {
258
- this.loadMoreButtonTemplate = template;
268
+ this._loadMoreButtonTemplateRef = template;
269
+ }
270
+ get loadMoreButtonTemplateRef() {
271
+ return this._loadMoreButtonTemplateRef || this.loadMoreButtonTemplateQuery;
259
272
  }
260
273
  /**
261
274
  * The nodes which will be displayed by the TreeView
@@ -653,18 +666,18 @@ tslib_1.__decorate([
653
666
  tslib_1.__metadata("design:type", EventEmitter)
654
667
  ], TreeViewComponent.prototype, "nodeDblClick", void 0);
655
668
  tslib_1.__decorate([
656
- ContentChild(NodeTemplateDirective, { static: true }),
669
+ ContentChild(NodeTemplateDirective, { static: false }),
657
670
  tslib_1.__metadata("design:type", NodeTemplateDirective)
658
- ], TreeViewComponent.prototype, "nodeTemplate", void 0);
671
+ ], TreeViewComponent.prototype, "nodeTemplateQuery", void 0);
659
672
  tslib_1.__decorate([
660
673
  Input('nodeTemplate'),
661
674
  tslib_1.__metadata("design:type", NodeTemplateDirective),
662
675
  tslib_1.__metadata("design:paramtypes", [NodeTemplateDirective])
663
676
  ], TreeViewComponent.prototype, "nodeTemplateRef", null);
664
677
  tslib_1.__decorate([
665
- ContentChild(LoadMoreButtonTemplateDirective, { static: true }),
678
+ ContentChild(LoadMoreButtonTemplateDirective, { static: false }),
666
679
  tslib_1.__metadata("design:type", LoadMoreButtonTemplateDirective)
667
- ], TreeViewComponent.prototype, "loadMoreButtonTemplate", void 0);
680
+ ], TreeViewComponent.prototype, "loadMoreButtonTemplateQuery", void 0);
668
681
  tslib_1.__decorate([
669
682
  Input('loadMoreButtonTemplate'),
670
683
  tslib_1.__metadata("design:type", LoadMoreButtonTemplateDirective),
@@ -765,8 +778,8 @@ TreeViewComponent = tslib_1.__decorate([
765
778
  [isExpanded]="isExpanded"
766
779
  [isSelected]="isSelected"
767
780
  [isVisible]="isVisible"
768
- [nodeTemplateRef]="nodeTemplate?.templateRef"
769
- [loadMoreButtonTemplateRef]="loadMoreButtonTemplate?.templateRef"
781
+ [nodeTemplateRef]="nodeTemplateRef?.templateRef"
782
+ [loadMoreButtonTemplateRef]="loadMoreButtonTemplateRef?.templateRef"
770
783
  [textField]="textField"
771
784
  [nodes]="fetchNodes"
772
785
  [loadMoreService]="loadMoreService"
@@ -125,9 +125,8 @@ export declare const fetchLoadedDescendants: (lookup: TreeItemLookup, filterExpr
125
125
  /**
126
126
  * @hidden
127
127
  *
128
- * Compares two arrays to determine whether all unique elements in one, are present in the other.
128
+ * Compares two Seets to determine whether all unique elements in one, are present in the other.
129
129
  * Important:
130
130
  * - it disregards the element order
131
- * - it disregards element repetitions - sameValues([1, 1, 2], [1, 2, 2]) will return true
132
131
  */
133
- export declare const sameValues: (a: any[], b: any[]) => boolean;
132
+ export declare const sameValues: (as: Set<any>, bs: Set<any>) => boolean;
@@ -282,16 +282,14 @@ export const fetchLoadedDescendants = (lookup, filterExpression) => {
282
282
  /**
283
283
  * @hidden
284
284
  *
285
- * Compares two arrays to determine whether all unique elements in one, are present in the other.
285
+ * Compares two Seets to determine whether all unique elements in one, are present in the other.
286
286
  * Important:
287
287
  * - it disregards the element order
288
- * - it disregards element repetitions - sameValues([1, 1, 2], [1, 2, 2]) will return true
289
288
  */
290
- export const sameValues = (a, b) => {
291
- if (a.length !== b.length) {
289
+ export const sameValues = (as, bs) => {
290
+ if (as.size !== bs.size) {
292
291
  return false;
293
292
  }
294
- const values = new Set(b);
295
- return a.every(v => values.has(v));
293
+ return Array.from(as).every(v => bs.has(v));
296
294
  };
297
295
  export { ɵ0, ɵ1, ɵ2, ɵ3, ɵ4, ɵ5, ɵ6, ɵ7, ɵ8, ɵ9 };