@progress/kendo-angular-treeview 5.4.3 → 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, SimpleChanges, OnChanges } from '@angular/core';
6
6
  import { ExpandableComponent } from './expandable-component';
7
7
  import { Subscription } from 'rxjs';
8
8
  import { TreeItem } from './treeitem.interface';
@@ -17,7 +17,7 @@ interface ExpandTreeItem extends TreeItem {
17
17
  * A directive which manages the expanded state of the TreeView.
18
18
  * ([see example]({% slug expandedstate_treeview %})).
19
19
  */
20
- export declare class ExpandDirective implements OnDestroy {
20
+ export declare class ExpandDirective implements OnDestroy, OnChanges {
21
21
  protected component: ExpandableComponent;
22
22
  /**
23
23
  * @hidden
@@ -43,10 +43,18 @@ export declare class ExpandDirective implements OnDestroy {
43
43
  */
44
44
  expandedKeys: any[];
45
45
  protected subscriptions: Subscription;
46
- private _expandedKeys;
46
+ /**
47
+ * Reflectes the internal `expandedKeys` state.
48
+ */
49
+ private state;
47
50
  private originalExpandedKeys;
48
51
  private isFiltered;
52
+ /**
53
+ * Holds the last emitted `expandedKeys` collection.
54
+ */
55
+ private lastChange;
49
56
  constructor(component: ExpandableComponent);
57
+ ngOnChanges(changes: SimpleChanges): void;
50
58
  ngOnDestroy(): void;
51
59
  /**
52
60
  * @hidden
@@ -62,5 +70,6 @@ export declare class ExpandDirective implements OnDestroy {
62
70
  * Fills array with the expand key of every node.
63
71
  */
64
72
  private getEveryExpandKey;
73
+ private notify;
65
74
  }
66
75
  export {};
@@ -8,6 +8,7 @@ import { ExpandableComponent } from './expandable-component';
8
8
  import { Subscription, merge } from 'rxjs';
9
9
  import { map } from 'rxjs/operators';
10
10
  import { isArrayWithAtLeastOneItem, isBoolean, sameValues } from './utils';
11
+ import { isChanged } from '@progress/kendo-angular-common';
11
12
  const DEFAULT_FILTER_EXPAND_SETTINGS = {
12
13
  maxAutoExpandResults: -1,
13
14
  expandMatches: false,
@@ -31,8 +32,11 @@ let ExpandDirective = class ExpandDirective {
31
32
  */
32
33
  this.expandedKeysChange = new EventEmitter();
33
34
  this.subscriptions = new Subscription();
34
- this._expandedKeys = [];
35
- this.originalExpandedKeys = [];
35
+ /**
36
+ * Reflectes the internal `expandedKeys` state.
37
+ */
38
+ this.state = new Set();
39
+ this.originalExpandedKeys = new Set();
36
40
  this.isFiltered = false;
37
41
  /**
38
42
  * Fills array with the correct expand keys according to wrapper metadata.
@@ -64,7 +68,7 @@ let ExpandDirective = class ExpandDirective {
64
68
  if (this.component.filterStateChange) {
65
69
  this.subscriptions.add(this.component.filterStateChange.subscribe(this.handleAutoExpand.bind(this)));
66
70
  }
67
- this.component.isExpanded = (dataItem, index) => this.expandedKeys.indexOf(this.itemKey({ dataItem, index })) > -1;
71
+ this.component.isExpanded = (dataItem, index) => this.state.has(this.itemKey({ dataItem, index }));
68
72
  }
69
73
  /**
70
74
  * @hidden
@@ -76,14 +80,10 @@ let ExpandDirective = class ExpandDirective {
76
80
  const settings = isBoolean(this.expandOnFilter) ? { enabled: this.expandOnFilter } : Object.assign({}, this.expandOnFilter, { enabled: true });
77
81
  return Object.assign({}, DEFAULT_FILTER_EXPAND_SETTINGS, settings);
78
82
  }
79
- /**
80
- * Defines the collection that will store the expanded keys.
81
- */
82
- get expandedKeys() {
83
- return this._expandedKeys;
84
- }
85
- set expandedKeys(keys) {
86
- this._expandedKeys = keys;
83
+ ngOnChanges(changes) {
84
+ if (isChanged('expandedKeys', changes, false) && changes.expandedKeys.currentValue !== this.lastChange) {
85
+ this.state = new Set(changes.expandedKeys.currentValue);
86
+ }
87
87
  }
88
88
  ngOnDestroy() {
89
89
  this.subscriptions.unsubscribe();
@@ -103,19 +103,19 @@ let ExpandDirective = class ExpandDirective {
103
103
  return e.index;
104
104
  }
105
105
  toggleExpand({ index, dataItem, expand }) {
106
- const item = this.itemKey({ index, dataItem });
107
- const idx = this.expandedKeys.indexOf(item);
106
+ const key = this.itemKey({ index, dataItem });
107
+ const isExpanded = this.state.has(key);
108
108
  let notify = false;
109
- if (idx > -1 && !expand) {
110
- this.expandedKeys.splice(idx, 1);
109
+ if (isExpanded && !expand) {
110
+ this.state.delete(key);
111
111
  notify = true;
112
112
  }
113
- else if (idx === -1 && expand) {
114
- this.expandedKeys.push(item);
113
+ else if (!isExpanded && expand) {
114
+ this.state.add(key);
115
115
  notify = true;
116
116
  }
117
117
  if (notify) {
118
- this.expandedKeysChange.emit(this.expandedKeys);
118
+ this.notify();
119
119
  }
120
120
  }
121
121
  handleAutoExpand({ nodes, matchCount, term }) {
@@ -124,7 +124,7 @@ let ExpandDirective = class ExpandDirective {
124
124
  }
125
125
  const { maxAutoExpandResults, expandMatches: autoExpandMatches, expandedOnClear } = this.filterExpandSettings;
126
126
  if (!this.isFiltered) {
127
- this.originalExpandedKeys = this.expandedKeys.slice();
127
+ this.originalExpandedKeys = new Set(this.state);
128
128
  }
129
129
  const exitingFilteredState = this.isFiltered && !term;
130
130
  const maxExceeded = maxAutoExpandResults !== -1 && matchCount > maxAutoExpandResults;
@@ -132,18 +132,18 @@ let ExpandDirective = class ExpandDirective {
132
132
  if (exitAutoExpandedState) {
133
133
  switch (expandedOnClear) {
134
134
  case "initial": {
135
- if (!sameValues(this.expandedKeys, this.originalExpandedKeys)) {
136
- this.expandedKeys = this.originalExpandedKeys;
137
- this.expandedKeysChange.emit(this.expandedKeys);
135
+ if (!sameValues(this.state, this.originalExpandedKeys)) {
136
+ this.state = this.originalExpandedKeys;
137
+ this.notify();
138
138
  }
139
139
  break;
140
140
  }
141
141
  case "all": {
142
- this.expandedKeys = nodes.reduce((acc, rootNode) => {
142
+ this.state = new Set(nodes.reduce((acc, rootNode) => {
143
143
  this.getEveryExpandKey(acc, rootNode);
144
144
  return acc;
145
- }, []);
146
- this.expandedKeysChange.emit(this.expandedKeys);
145
+ }, []));
146
+ this.notify();
147
147
  break;
148
148
  }
149
149
  case "unchanged": {
@@ -151,9 +151,9 @@ let ExpandDirective = class ExpandDirective {
151
151
  }
152
152
  case "none":
153
153
  default: {
154
- if (this.expandedKeys.length !== 0) {
155
- this.expandedKeys = [];
156
- this.expandedKeysChange.emit(this.expandedKeys);
154
+ if (this.state.size !== 0) {
155
+ this.state.clear();
156
+ this.notify();
157
157
  }
158
158
  break;
159
159
  }
@@ -161,16 +161,20 @@ let ExpandDirective = class ExpandDirective {
161
161
  this.isFiltered = false;
162
162
  return;
163
163
  }
164
- const indicesToExpand = nodes.reduce((acc, rootNode) => {
164
+ const indicesToExpand = new Set(nodes.reduce((acc, rootNode) => {
165
165
  this.updateExpandedNodes(acc, rootNode, autoExpandMatches);
166
166
  return acc;
167
- }, []);
168
- if (!sameValues(this.expandedKeys, indicesToExpand)) {
169
- this.expandedKeys = indicesToExpand;
170
- this.expandedKeysChange.emit(this.expandedKeys);
167
+ }, []));
168
+ if (!sameValues(this.state, indicesToExpand)) {
169
+ this.state = indicesToExpand;
170
+ this.notify();
171
171
  }
172
172
  this.isFiltered = true;
173
173
  }
174
+ notify() {
175
+ this.lastChange = Array.from(this.state);
176
+ this.expandedKeysChange.emit(this.lastChange);
177
+ }
174
178
  };
175
179
  tslib_1.__decorate([
176
180
  Input(),
@@ -191,9 +195,8 @@ tslib_1.__decorate([
191
195
  ], ExpandDirective.prototype, "expandedKeysChange", void 0);
192
196
  tslib_1.__decorate([
193
197
  Input(),
194
- tslib_1.__metadata("design:type", Array),
195
- tslib_1.__metadata("design:paramtypes", [Array])
196
- ], ExpandDirective.prototype, "expandedKeys", null);
198
+ tslib_1.__metadata("design:type", Array)
199
+ ], ExpandDirective.prototype, "expandedKeys", void 0);
197
200
  ExpandDirective = tslib_1.__decorate([
198
201
  Directive({ selector: '[kendoTreeViewExpandable]' }),
199
202
  tslib_1.__metadata("design:paramtypes", [ExpandableComponent])