@progress/kendo-angular-grid 5.5.2 → 6.0.0-dev.202201141020

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.
@@ -9,7 +9,7 @@ export var packageMetadata = {
9
9
  name: '@progress/kendo-angular-grid',
10
10
  productName: 'Kendo UI for Angular',
11
11
  productCodes: ['KENDOUIANGULAR', 'KENDOUICOMPLETE'],
12
- publishDate: 1641921939,
12
+ publishDate: 1642155100,
13
13
  version: '',
14
14
  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'
15
15
  };
@@ -8,7 +8,7 @@ import { GridComponent } from '../grid.component';
8
8
  import { Subscription, merge } from 'rxjs';
9
9
  import { map } from 'rxjs/operators';
10
10
  import { getter } from '@progress/kendo-common';
11
- import { isString } from '../utils';
11
+ import { isPresent, isString } from '../utils';
12
12
  /**
13
13
  * A directive which controls the expanded state of the master detail rows.
14
14
  */
@@ -25,9 +25,12 @@ var ExpandDetailsDirective = /** @class */ (function () {
25
25
  this.expandedDetailKeys = [];
26
26
  /**
27
27
  * Specifies if the items should be initially expanded.
28
+ * When set to `true` items added to the `expandedDetailKeys` collection will be collapsed, and items that are not present in it will be expanded.
29
+ *
28
30
  * @default false
29
31
  */
30
32
  this.initiallyExpanded = false;
33
+ this.expandedState = new Set();
31
34
  this.subscriptions = new Subscription();
32
35
  this.grid.isDetailExpanded = this.isExpanded.bind(this);
33
36
  this.subscriptions.add(merge(this.grid.detailExpand.pipe(map(function (e) { return (tslib_1.__assign({ expand: true }, e)); })), this.grid.detailCollapse.pipe(map(function (e) { return (tslib_1.__assign({ expand: false }, e)); }))).subscribe(this.toggleState.bind(this)));
@@ -65,6 +68,12 @@ var ExpandDetailsDirective = /** @class */ (function () {
65
68
  enumerable: true,
66
69
  configurable: true
67
70
  });
71
+ ExpandDetailsDirective.prototype.ngOnChanges = function (changes) {
72
+ // skip reinitialization if the user data is the same as the last state change
73
+ if (isPresent(changes.expandedDetailKeys) && this.lastExpandedState !== this.expandedDetailKeys) {
74
+ this.expandedState = new Set(this.expandedDetailKeys);
75
+ }
76
+ };
68
77
  ExpandDetailsDirective.prototype.ngOnDestroy = function () {
69
78
  this.subscriptions.unsubscribe();
70
79
  };
@@ -80,18 +89,23 @@ var ExpandDetailsDirective = /** @class */ (function () {
80
89
  */
81
90
  ExpandDetailsDirective.prototype.isExpanded = function (args) {
82
91
  var key = this.keyGetter(args.dataItem);
83
- return this.expandedDetailKeys.indexOf(key) > -1 ? !this.initiallyExpanded : this.initiallyExpanded;
92
+ var hasKey = this.expandedState.has(key);
93
+ // when [initiallyExpanded]="true" a present key means the corresponding detail row is collapsed
94
+ return this.initiallyExpanded ? !hasKey : hasKey;
84
95
  };
85
96
  ExpandDetailsDirective.prototype.toggleState = function (args) {
86
97
  var key = this.keyGetter(args.dataItem);
87
98
  if (Boolean(this.initiallyExpanded) !== args.expand) {
88
- this.expandedDetailKeys.push(key);
99
+ this.expandedState.add(key);
89
100
  }
90
101
  else {
91
- var index = this.expandedDetailKeys.indexOf(key);
92
- this.expandedDetailKeys.splice(index, 1);
102
+ this.expandedState.delete(key);
93
103
  }
94
- this.expandedDetailKeysChange.emit(this.expandedDetailKeys);
104
+ this.notifyChange();
105
+ };
106
+ ExpandDetailsDirective.prototype.notifyChange = function () {
107
+ this.lastExpandedState = Array.from(this.expandedState);
108
+ this.expandedDetailKeysChange.emit(this.lastExpandedState);
95
109
  };
96
110
  tslib_1.__decorate([
97
111
  Output(),
@@ -0,0 +1,91 @@
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
+ * Quick look-up structure for combinations of keys.
9
+ * Similar to the native JS Set, however, working with a couple of keys instead of with a single key.
10
+ * Supports both primitive keys and object keys (compared by reference).
11
+ */
12
+ var PairSet = /** @class */ (function () {
13
+ function PairSet(items, keyXField, keyYField) {
14
+ var _this = this;
15
+ /**
16
+ * Holds a set of Y keys for each defined X key.
17
+ * Each X key creates a map which holds a set of Y keys.
18
+ *
19
+ * Map { 1 => Set { 1, 2, 3 } } // pairs: [1, 1], [1, 2], [1, 3]
20
+ */
21
+ this.keysX = new Map();
22
+ /**
23
+ * Count the each added or deleted key manually to avoid iterating over all items when calling `this.size`.
24
+ */
25
+ this.totalKeysCount = 0;
26
+ if (items && keyXField && keyYField) {
27
+ items.forEach(function (item) { return _this.add(item[keyXField], item[keyYField]); });
28
+ }
29
+ }
30
+ Object.defineProperty(PairSet.prototype, "size", {
31
+ /**
32
+ * Gets the total number of X/Y key pairs.
33
+ */
34
+ get: function () {
35
+ return this.totalKeysCount;
36
+ },
37
+ enumerable: true,
38
+ configurable: true
39
+ });
40
+ /**
41
+ * Adds a couple of items identified as a combination.
42
+ */
43
+ PairSet.prototype.add = function (keyX, keyY) {
44
+ if (!this.keysX.has(keyX)) {
45
+ this.keysX.set(keyX, new Set());
46
+ }
47
+ if (!this.has(keyX, keyY)) {
48
+ this.keysX.get(keyX).add(keyY);
49
+ this.totalKeysCount += 1;
50
+ }
51
+ };
52
+ /**
53
+ * Adds a combination of a couple of items identified together.
54
+ */
55
+ PairSet.prototype.delete = function (keyX, keyY) {
56
+ if (this.has(keyX, keyY)) {
57
+ this.keysX.get(keyX).delete(keyY);
58
+ this.totalKeysCount -= 1;
59
+ }
60
+ };
61
+ /**
62
+ * Checks whether the defined combination is stored.
63
+ */
64
+ PairSet.prototype.has = function (keyX, keyY) {
65
+ return this.keysX.has(keyX) && this.keysX.get(keyX).has(keyY);
66
+ };
67
+ /**
68
+ * Clears all key combinations.
69
+ */
70
+ PairSet.prototype.clear = function () {
71
+ this.keysX.clear();
72
+ this.totalKeysCount = 0;
73
+ };
74
+ /**
75
+ * Converts the persisted data structure to an array of objects,
76
+ * using the provided field names for the object props.
77
+ */
78
+ PairSet.prototype.toArray = function (keyXField, keyYField) {
79
+ return Array.from(this.keysX).reduce(function (pairs, pair) {
80
+ // Array.from(mapInstance) returns an array of arrays [[itemKey1, columnKeysSet1], [itemKey2, columnKeysSet2]]
81
+ var keyX = pair[0], keysY = pair[1];
82
+ Array.from(keysY).forEach(function (keyY) {
83
+ var _a;
84
+ return pairs.push((_a = {}, _a[keyXField] = keyX, _a[keyYField] = keyY, _a));
85
+ });
86
+ return pairs;
87
+ }, []);
88
+ };
89
+ return PairSet;
90
+ }());
91
+ export { PairSet };
@@ -3,9 +3,9 @@
3
3
  * Licensed under commercial license. See LICENSE.md in the project root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
5
  import * as tslib_1 from "tslib";
6
- /* tslint:disable:no-input-rename */
7
6
  import { Input, EventEmitter, Output } from '@angular/core';
8
7
  import { isPresent } from "../utils";
8
+ import { PairSet } from './pair-set';
9
9
  /**
10
10
  * @hidden
11
11
  */
@@ -21,20 +21,33 @@ var Selection = /** @class */ (function () {
21
21
  * Fires when the `selectedKeys` collection has been updated.
22
22
  */
23
23
  this.selectedKeysChange = new EventEmitter();
24
+ this.rowSelectionState = new Set();
25
+ this.cellSelectionState = new PairSet();
24
26
  this.init();
25
27
  }
28
+ Object.defineProperty(Selection.prototype, "isCellSelectionMode", {
29
+ get: function () {
30
+ return isPresent(this.grid.selectable) && this.grid.selectable['cell'];
31
+ },
32
+ enumerable: true,
33
+ configurable: true
34
+ });
35
+ Selection.prototype.ngOnChanges = function (changes) {
36
+ // skip reinitialization if the user data is the same as the last state change
37
+ if (isPresent(changes.selectedKeys) && this.lastSelectionState !== this.selectedKeys) {
38
+ this.setState(this.selectedKeys);
39
+ }
40
+ };
26
41
  Selection.prototype.init = function () {
27
42
  var _this = this;
28
43
  if (!isPresent(this.grid.rowSelected)) {
29
- this.grid.rowSelected = function (row) {
30
- return _this.selectedKeys.indexOf(_this.getItemKey(row)) >= 0;
31
- };
44
+ this.grid.rowSelected = function (row) { return _this.rowSelectionState.has(_this.getItemKey(row)); };
32
45
  }
33
46
  if (!isPresent(this.grid.cellSelected)) {
34
47
  this.grid.cellSelected = function (row, column, colIndex) {
35
48
  var contender = _this.getSelectionItem(row, column, colIndex);
36
49
  return {
37
- selected: _this.selectedKeys.some(function (item) { return item.columnKey === contender.columnKey && item.itemKey === contender.itemKey; }),
50
+ selected: _this.cellSelectionState.has(contender.itemKey, contender.columnKey),
38
51
  item: contender
39
52
  };
40
53
  };
@@ -53,7 +66,8 @@ var Selection = /** @class */ (function () {
53
66
  * @hidden
54
67
  */
55
68
  Selection.prototype.reset = function () {
56
- this.selectedKeys = [];
69
+ this.rowSelectionState.clear();
70
+ this.cellSelectionState.clear();
57
71
  };
58
72
  Selection.prototype.getItemKey = function (row) {
59
73
  if (this.selectionKey) {
@@ -90,45 +104,49 @@ var Selection = /** @class */ (function () {
90
104
  if (selection.selectedRows) {
91
105
  selection.deselectedRows.forEach(function (item) {
92
106
  var itemKey = _this.getItemKey(item);
93
- var itemIndex = _this.selectedKeys.indexOf(itemKey);
94
- if (itemIndex >= 0) {
95
- _this.selectedKeys.splice(itemIndex, 1);
96
- }
107
+ _this.rowSelectionState.delete(itemKey);
97
108
  });
98
- if (this.grid.selectableSettings.mode === "single" && this.selectedKeys.length > 0) {
109
+ if (this.grid.selectableSettings.mode === "single" && this.rowSelectionState.size > 0) {
99
110
  this.reset();
100
111
  }
101
112
  selection.selectedRows.forEach(function (item) {
102
113
  var itemKey = _this.getItemKey(item);
103
- if (_this.selectedKeys.indexOf(itemKey) < 0) {
104
- _this.selectedKeys.push(itemKey);
105
- }
114
+ _this.rowSelectionState.add(itemKey);
106
115
  });
107
116
  }
108
117
  else {
109
- selection.deselectedCells.forEach(function (item) {
110
- var itemIndex = _this.getCellSelectionItemIndex(item);
111
- if (itemIndex >= 0) {
112
- _this.selectedKeys.splice(itemIndex, 1);
113
- }
118
+ selection.deselectedCells.forEach(function (_a) {
119
+ var itemKey = _a.itemKey, columnKey = _a.columnKey;
120
+ _this.cellSelectionState.delete(itemKey, columnKey);
114
121
  });
115
- if (this.grid.selectableSettings.mode === "single" && this.selectedKeys.length > 0) {
122
+ if (this.grid.selectableSettings.mode === "single" && this.cellSelectionState.size > 0) {
116
123
  this.reset();
117
124
  }
118
- selection.selectedCells.forEach(function (item) {
119
- var itemIndex = _this.getCellSelectionItemIndex(item);
120
- if (itemIndex < 0) {
121
- _this.selectedKeys.push(item);
122
- }
125
+ selection.selectedCells.forEach(function (_a) {
126
+ var itemKey = _a.itemKey, columnKey = _a.columnKey;
127
+ _this.cellSelectionState.add(itemKey, columnKey);
123
128
  });
124
129
  }
125
130
  this.cd.markForCheck();
126
- this.selectedKeysChange.emit(this.selectedKeys);
131
+ this.notifyChange();
132
+ };
133
+ Selection.prototype.notifyChange = function () {
134
+ this.lastSelectionState = this.stateToArray();
135
+ this.selectedKeysChange.emit(this.lastSelectionState);
136
+ };
137
+ Selection.prototype.setState = function (selectedKeys) {
138
+ this.reset();
139
+ if (this.isCellSelectionMode) {
140
+ this.cellSelectionState = new PairSet(selectedKeys, 'itemKey', 'columnKey');
141
+ }
142
+ else {
143
+ this.rowSelectionState = new Set(selectedKeys);
144
+ }
127
145
  };
128
- Selection.prototype.getCellSelectionItemIndex = function (item) {
129
- return this.selectedKeys.findIndex(function (selectedItem) {
130
- return selectedItem.itemKey === item.itemKey && selectedItem.columnKey === item.columnKey;
131
- });
146
+ Selection.prototype.stateToArray = function () {
147
+ return this.isCellSelectionMode ?
148
+ this.cellSelectionState.toArray('itemKey', 'columnKey') :
149
+ Array.from(this.rowSelectionState);
132
150
  };
133
151
  tslib_1.__decorate([
134
152
  Input(),
package/dist/es/utils.js CHANGED
@@ -40,9 +40,7 @@ export var isUniversal = function () { return typeof document === 'undefined'; }
40
40
  /**
41
41
  * @hidden
42
42
  */
43
- export var isString = function (value) {
44
- return typeof value === 'string';
45
- };
43
+ export var isString = function (value) { return typeof value === 'string'; };
46
44
  /**
47
45
  * @hidden
48
46
  */