@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.
@@ -10,6 +10,7 @@ var expandable_component_1 = require("./expandable-component");
10
10
  var rxjs_1 = require("rxjs");
11
11
  var operators_1 = require("rxjs/operators");
12
12
  var utils_1 = require("./utils");
13
+ var kendo_angular_common_1 = require("@progress/kendo-angular-common");
13
14
  var DEFAULT_FILTER_EXPAND_SETTINGS = {
14
15
  maxAutoExpandResults: -1,
15
16
  expandMatches: false,
@@ -34,8 +35,11 @@ var ExpandDirective = /** @class */ (function () {
34
35
  */
35
36
  this.expandedKeysChange = new core_1.EventEmitter();
36
37
  this.subscriptions = new rxjs_1.Subscription();
37
- this._expandedKeys = [];
38
- this.originalExpandedKeys = [];
38
+ /**
39
+ * Reflectes the internal `expandedKeys` state.
40
+ */
41
+ this.state = new Set();
42
+ this.originalExpandedKeys = new Set();
39
43
  this.isFiltered = false;
40
44
  /**
41
45
  * Fills array with the correct expand keys according to wrapper metadata.
@@ -68,7 +72,7 @@ var ExpandDirective = /** @class */ (function () {
68
72
  this.subscriptions.add(this.component.filterStateChange.subscribe(this.handleAutoExpand.bind(this)));
69
73
  }
70
74
  this.component.isExpanded = function (dataItem, index) {
71
- return _this.expandedKeys.indexOf(_this.itemKey({ dataItem: dataItem, index: index })) > -1;
75
+ return _this.state.has(_this.itemKey({ dataItem: dataItem, index: index }));
72
76
  };
73
77
  }
74
78
  Object.defineProperty(ExpandDirective.prototype, "isExpanded", {
@@ -89,19 +93,11 @@ var ExpandDirective = /** @class */ (function () {
89
93
  enumerable: true,
90
94
  configurable: true
91
95
  });
92
- Object.defineProperty(ExpandDirective.prototype, "expandedKeys", {
93
- /**
94
- * Defines the collection that will store the expanded keys.
95
- */
96
- get: function () {
97
- return this._expandedKeys;
98
- },
99
- set: function (keys) {
100
- this._expandedKeys = keys;
101
- },
102
- enumerable: true,
103
- configurable: true
104
- });
96
+ ExpandDirective.prototype.ngOnChanges = function (changes) {
97
+ if (kendo_angular_common_1.isChanged('expandedKeys', changes, false) && changes.expandedKeys.currentValue !== this.lastChange) {
98
+ this.state = new Set(changes.expandedKeys.currentValue);
99
+ }
100
+ };
105
101
  ExpandDirective.prototype.ngOnDestroy = function () {
106
102
  this.subscriptions.unsubscribe();
107
103
  };
@@ -121,19 +117,19 @@ var ExpandDirective = /** @class */ (function () {
121
117
  };
122
118
  ExpandDirective.prototype.toggleExpand = function (_a) {
123
119
  var index = _a.index, dataItem = _a.dataItem, expand = _a.expand;
124
- var item = this.itemKey({ index: index, dataItem: dataItem });
125
- var idx = this.expandedKeys.indexOf(item);
120
+ var key = this.itemKey({ index: index, dataItem: dataItem });
121
+ var isExpanded = this.state.has(key);
126
122
  var notify = false;
127
- if (idx > -1 && !expand) {
128
- this.expandedKeys.splice(idx, 1);
123
+ if (isExpanded && !expand) {
124
+ this.state.delete(key);
129
125
  notify = true;
130
126
  }
131
- else if (idx === -1 && expand) {
132
- this.expandedKeys.push(item);
127
+ else if (!isExpanded && expand) {
128
+ this.state.add(key);
133
129
  notify = true;
134
130
  }
135
131
  if (notify) {
136
- this.expandedKeysChange.emit(this.expandedKeys);
132
+ this.notify();
137
133
  }
138
134
  };
139
135
  ExpandDirective.prototype.handleAutoExpand = function (_a) {
@@ -144,7 +140,7 @@ var ExpandDirective = /** @class */ (function () {
144
140
  }
145
141
  var _b = this.filterExpandSettings, maxAutoExpandResults = _b.maxAutoExpandResults, autoExpandMatches = _b.expandMatches, expandedOnClear = _b.expandedOnClear;
146
142
  if (!this.isFiltered) {
147
- this.originalExpandedKeys = this.expandedKeys.slice();
143
+ this.originalExpandedKeys = new Set(this.state);
148
144
  }
149
145
  var exitingFilteredState = this.isFiltered && !term;
150
146
  var maxExceeded = maxAutoExpandResults !== -1 && matchCount > maxAutoExpandResults;
@@ -152,18 +148,18 @@ var ExpandDirective = /** @class */ (function () {
152
148
  if (exitAutoExpandedState) {
153
149
  switch (expandedOnClear) {
154
150
  case "initial": {
155
- if (!utils_1.sameValues(this.expandedKeys, this.originalExpandedKeys)) {
156
- this.expandedKeys = this.originalExpandedKeys;
157
- this.expandedKeysChange.emit(this.expandedKeys);
151
+ if (!utils_1.sameValues(this.state, this.originalExpandedKeys)) {
152
+ this.state = this.originalExpandedKeys;
153
+ this.notify();
158
154
  }
159
155
  break;
160
156
  }
161
157
  case "all": {
162
- this.expandedKeys = nodes.reduce(function (acc, rootNode) {
158
+ this.state = new Set(nodes.reduce(function (acc, rootNode) {
163
159
  _this.getEveryExpandKey(acc, rootNode);
164
160
  return acc;
165
- }, []);
166
- this.expandedKeysChange.emit(this.expandedKeys);
161
+ }, []));
162
+ this.notify();
167
163
  break;
168
164
  }
169
165
  case "unchanged": {
@@ -171,9 +167,9 @@ var ExpandDirective = /** @class */ (function () {
171
167
  }
172
168
  case "none":
173
169
  default: {
174
- if (this.expandedKeys.length !== 0) {
175
- this.expandedKeys = [];
176
- this.expandedKeysChange.emit(this.expandedKeys);
170
+ if (this.state.size !== 0) {
171
+ this.state.clear();
172
+ this.notify();
177
173
  }
178
174
  break;
179
175
  }
@@ -181,16 +177,20 @@ var ExpandDirective = /** @class */ (function () {
181
177
  this.isFiltered = false;
182
178
  return;
183
179
  }
184
- var indicesToExpand = nodes.reduce(function (acc, rootNode) {
180
+ var indicesToExpand = new Set(nodes.reduce(function (acc, rootNode) {
185
181
  _this.updateExpandedNodes(acc, rootNode, autoExpandMatches);
186
182
  return acc;
187
- }, []);
188
- if (!utils_1.sameValues(this.expandedKeys, indicesToExpand)) {
189
- this.expandedKeys = indicesToExpand;
190
- this.expandedKeysChange.emit(this.expandedKeys);
183
+ }, []));
184
+ if (!utils_1.sameValues(this.state, indicesToExpand)) {
185
+ this.state = indicesToExpand;
186
+ this.notify();
191
187
  }
192
188
  this.isFiltered = true;
193
189
  };
190
+ ExpandDirective.prototype.notify = function () {
191
+ this.lastChange = Array.from(this.state);
192
+ this.expandedKeysChange.emit(this.lastChange);
193
+ };
194
194
  tslib_1.__decorate([
195
195
  core_1.Input(),
196
196
  tslib_1.__metadata("design:type", Function),
@@ -210,9 +210,8 @@ var ExpandDirective = /** @class */ (function () {
210
210
  ], ExpandDirective.prototype, "expandedKeysChange", void 0);
211
211
  tslib_1.__decorate([
212
212
  core_1.Input(),
213
- tslib_1.__metadata("design:type", Array),
214
- tslib_1.__metadata("design:paramtypes", [Array])
215
- ], ExpandDirective.prototype, "expandedKeys", null);
213
+ tslib_1.__metadata("design:type", Array)
214
+ ], ExpandDirective.prototype, "expandedKeys", void 0);
216
215
  ExpandDirective = tslib_1.__decorate([
217
216
  core_1.Directive({ selector: '[kendoTreeViewExpandable]' }),
218
217
  tslib_1.__metadata("design:paramtypes", [expandable_component_1.ExpandableComponent])
@@ -11,7 +11,7 @@ exports.packageMetadata = {
11
11
  name: '@progress/kendo-angular-treeview',
12
12
  productName: 'Kendo UI for Angular',
13
13
  productCodes: ['KENDOUIANGULAR', 'KENDOUICOMPLETE'],
14
- publishDate: 1638439762,
14
+ publishDate: 1638442548,
15
15
  version: '',
16
16
  licensingDocsUrl: 'https://www.telerik.com/kendo-angular-ui/my-license/?utm_medium=product&utm_source=kendoangular&utm_campaign=kendo-ui-angular-purchase-license-keys-warning'
17
17
  };
@@ -9,6 +9,7 @@ var core_1 = require("@angular/core");
9
9
  var treeview_component_1 = require("../treeview.component");
10
10
  var utils_1 = require("../utils");
11
11
  var rxjs_1 = require("rxjs");
12
+ var kendo_angular_common_1 = require("@progress/kendo-angular-common");
12
13
  /**
13
14
  * A directive which manages the in-memory selection state of the TreeView node
14
15
  * ([see example]({% slug selection_treeview %})).
@@ -26,9 +27,12 @@ var SelectDirective = /** @class */ (function () {
26
27
  'multiple': function (e) { return _this.selectMultiple(e); },
27
28
  'single': function (e) { return _this.selectSingle(e); }
28
29
  };
29
- this._selectedKeys = [];
30
+ /**
31
+ * Reflectes the internal `selectedKeys` state.
32
+ */
33
+ this.state = new Set();
30
34
  this.subscriptions.add(this.treeView.selectionChange.subscribe(this.select.bind(this)));
31
- this.treeView.isSelected = function (dataItem, index) { return (_this.selectedKeys.indexOf(_this.itemKey({ dataItem: dataItem, index: index })) > -1); };
35
+ this.treeView.isSelected = function (dataItem, index) { return (_this.state.has(_this.itemKey({ dataItem: dataItem, index: index }))); };
32
36
  }
33
37
  Object.defineProperty(SelectDirective.prototype, "isSelected", {
34
38
  /**
@@ -40,20 +44,6 @@ var SelectDirective = /** @class */ (function () {
40
44
  enumerable: true,
41
45
  configurable: true
42
46
  });
43
- Object.defineProperty(SelectDirective.prototype, "selectedKeys", {
44
- /**
45
- * Defines the collection that will store the selected keys
46
- * ([see example]({% slug selection_treeview %}#toc-selection-modes)).
47
- */
48
- get: function () {
49
- return this._selectedKeys;
50
- },
51
- set: function (keys) {
52
- this._selectedKeys = keys;
53
- },
54
- enumerable: true,
55
- configurable: true
56
- });
57
47
  Object.defineProperty(SelectDirective.prototype, "getAriaMultiselectable", {
58
48
  get: function () {
59
49
  return this.options.mode === 'multiple';
@@ -76,6 +66,11 @@ var SelectDirective = /** @class */ (function () {
76
66
  enumerable: true,
77
67
  configurable: true
78
68
  });
69
+ SelectDirective.prototype.ngOnChanges = function (changes) {
70
+ if (kendo_angular_common_1.isChanged('selectedKeys', changes, false) && changes.selectedKeys.currentValue !== this.lastChange) {
71
+ this.state = new Set(changes.selectedKeys.currentValue);
72
+ }
73
+ };
79
74
  SelectDirective.prototype.ngOnDestroy = function () {
80
75
  this.subscriptions.unsubscribe();
81
76
  };
@@ -100,29 +95,29 @@ var SelectDirective = /** @class */ (function () {
100
95
  };
101
96
  SelectDirective.prototype.selectSingle = function (node) {
102
97
  var key = this.itemKey(node);
103
- if (this.selectedKeys[0] === key) {
104
- return;
98
+ if (!this.state.has(key)) {
99
+ this.state.clear();
100
+ this.state.add(key);
101
+ this.notify();
105
102
  }
106
- this.selectedKeys = [key];
107
- this.notify();
108
103
  };
109
104
  SelectDirective.prototype.selectMultiple = function (node) {
110
105
  var key = this.itemKey(node);
111
- var idx = this.selectedKeys.indexOf(key);
112
- var isSelected = idx > -1;
106
+ var isSelected = this.state.has(key);
113
107
  if (!utils_1.isPresent(key)) {
114
108
  return;
115
109
  }
116
110
  if (isSelected) {
117
- this.selectedKeys.splice(idx, 1);
111
+ this.state.delete(key);
118
112
  }
119
113
  else {
120
- this.selectedKeys.push(key);
114
+ this.state.add(key);
121
115
  }
122
116
  this.notify();
123
117
  };
124
118
  SelectDirective.prototype.notify = function () {
125
- this.selectedKeysChange.emit(this.selectedKeys.slice());
119
+ this.lastChange = Array.from(this.state);
120
+ this.selectedKeysChange.emit(this.lastChange);
126
121
  };
127
122
  tslib_1.__decorate([
128
123
  core_1.Input(),
@@ -139,9 +134,8 @@ var SelectDirective = /** @class */ (function () {
139
134
  ], SelectDirective.prototype, "selection", void 0);
140
135
  tslib_1.__decorate([
141
136
  core_1.Input(),
142
- tslib_1.__metadata("design:type", Array),
143
- tslib_1.__metadata("design:paramtypes", [Array])
144
- ], SelectDirective.prototype, "selectedKeys", null);
137
+ tslib_1.__metadata("design:type", Array)
138
+ ], SelectDirective.prototype, "selectedKeys", void 0);
145
139
  tslib_1.__decorate([
146
140
  core_1.Output(),
147
141
  tslib_1.__metadata("design:type", core_1.EventEmitter)
package/dist/npm/utils.js CHANGED
@@ -298,15 +298,13 @@ exports.fetchLoadedDescendants = function (lookup, filterExpression) {
298
298
  /**
299
299
  * @hidden
300
300
  *
301
- * Compares two arrays to determine whether all unique elements in one, are present in the other.
301
+ * Compares two Seets to determine whether all unique elements in one, are present in the other.
302
302
  * Important:
303
303
  * - it disregards the element order
304
- * - it disregards element repetitions - sameValues([1, 1, 2], [1, 2, 2]) will return true
305
304
  */
306
- exports.sameValues = function (a, b) {
307
- if (a.length !== b.length) {
305
+ exports.sameValues = function (as, bs) {
306
+ if (as.size !== bs.size) {
308
307
  return false;
309
308
  }
310
- var values = new Set(b);
311
- return a.every(function (v) { return values.has(v); });
309
+ return Array.from(as).every(function (v) { return bs.has(v); });
312
310
  };