@refinitiv-ui/efx-grid 6.0.54 → 6.0.56

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.
@@ -16751,7 +16751,7 @@ GroupDefinitions.getLeafDescendants = function (groupMap, groupId) {
16751
16751
  groupDef = unvisitedGroups[visitedCount++];
16752
16752
  visitedMap[groupDef.id] = true;
16753
16753
  var chdr = groupDef.children;
16754
- var len = chdr.length;
16754
+ var len = chdr ? chdr.length : 0;
16755
16755
  for(var i = 0; i < len; ++i) {
16756
16756
  var childId = chdr[i];
16757
16757
  groupDef = groupMap[childId];
@@ -16771,44 +16771,30 @@ GroupDefinitions.getLeafDescendants = function (groupMap, groupId) {
16771
16771
  /** @private
16772
16772
  * @function
16773
16773
  * @param {Object} obj
16774
- * @return {Object}
16774
+ * @return {Object} Return a new object with guaranteed children property
16775
16775
  */
16776
16776
  GroupDefinitions._cloneObject = function(obj) {
16777
16777
  var newObj = cloneObject(obj);
16778
- if(Array.isArray(newObj.children)) {
16779
- newObj.children = newObj.children;
16778
+ if(Array.isArray(newObj.children)) { // This is to prevent modification from the outside source
16779
+ newObj.children = newObj.children.slice();
16780
16780
  } else {
16781
16781
  newObj.children = [];
16782
16782
  }
16783
16783
  return newObj;
16784
16784
  };
16785
- /** @private
16786
- * @param {Object} groupMap
16787
- * @return {!Object}
16788
- */
16789
- GroupDefinitions._cloneGroupMap = function (groupMap) {
16790
- var outMap = {};
16791
- for(var groupId in groupMap) {
16792
- var groupDef = groupMap[groupId];
16793
- var obj = GroupDefinitions._cloneObject(groupDef);
16794
- obj.children = groupDef.children.slice();
16795
- outMap[groupId] = obj;
16796
- }
16797
- return outMap;
16798
- };
16799
16785
 
16800
16786
  /** @private
16801
16787
  * @function
16802
16788
  * @param {Array.<string>|Object} obj
16803
16789
  * @param {string=} groupId
16804
- * @return {Object}
16790
+ * @return {Object} Return a new object with guaranteed children property
16805
16791
  */
16806
16792
  GroupDefinitions._toGroupDefinition = function(obj, groupId) {
16807
16793
  var groupDef = null;
16808
16794
  if(obj) {
16809
16795
  if(Array.isArray(obj)) {
16810
16796
  groupDef = {
16811
- children: obj
16797
+ children: obj.slice()
16812
16798
  };
16813
16799
  } else {
16814
16800
  groupDef = GroupDefinitions._cloneObject(obj);
@@ -16888,7 +16874,43 @@ GroupDefinitions.prototype.getGroupMap = function () {
16888
16874
  * @return {!Object.<string, Object>}
16889
16875
  */
16890
16876
  GroupDefinitions.prototype.cloneGroupMap = function () {
16891
- return GroupDefinitions._cloneGroupMap(this._groupMap);
16877
+ var groupMap = this._groupMap;
16878
+ var outMap = {};
16879
+ for(var groupId in groupMap) {
16880
+ var groupDef = groupMap[groupId];
16881
+ var obj = GroupDefinitions._cloneObject(groupDef);
16882
+ outMap[groupId] = obj;
16883
+ }
16884
+ return outMap;
16885
+ };
16886
+ /** In case of a children array has been modified outside of GroupDefinitions, this method is needed to re-create internal maps to reflect existing structure
16887
+ * @public
16888
+ */
16889
+ GroupDefinitions.prototype.rebuildMap = function () {
16890
+ var groupMap = this._groupMap;
16891
+ var childToParent = this._childToParent = {};
16892
+
16893
+ // Create child to parent map
16894
+ var groupIds = Object.keys(groupMap);
16895
+ var grpCount = groupIds.length;
16896
+ var i, groupId;
16897
+ for(i = 0; i < grpCount; ++i) {
16898
+ groupId = groupIds[i];
16899
+ var chdr = groupMap[groupId].children;
16900
+ var childCount = chdr ? chdr.length : 0;
16901
+ for (var j = 0; j < childCount; j++) {
16902
+ childToParent[chdr[j]] = groupId;
16903
+ }
16904
+ }
16905
+
16906
+ // Apply a parent id to group definition to make it easier to find depth
16907
+ for(i = 0; i < grpCount; ++i) {
16908
+ groupId = groupIds[i];
16909
+ var parentId = childToParent[groupId];
16910
+ if(parentId) {
16911
+ groupMap[groupId].parentId = parentId;
16912
+ }
16913
+ }
16892
16914
  };
16893
16915
 
16894
16916
  /** Get immediate child ids of the specified group. The returned array can contain both child ids and group ids
@@ -16968,7 +16990,7 @@ GroupDefinitions.prototype.getParentIds = function(childId) {
16968
16990
  };
16969
16991
  /** @public
16970
16992
  * @param {string} childId
16971
- * @param {number=} groupLevel
16993
+ * @param {number=} groupLevel Default is to retrieve immediate parent id. Use 0 to get root (topmost) group id
16972
16994
  * @return {string}
16973
16995
  */
16974
16996
  GroupDefinitions.prototype.getParentId = function (childId, groupLevel) {
@@ -16996,47 +17018,25 @@ GroupDefinitions.prototype.removeAllGroups = function () {
16996
17018
  }
16997
17019
  return false;
16998
17020
  };
16999
- /** Remove all existing group definitions and replace them with the given definitions.
17021
+ /** Remove all existing group definitions and replace them with the given definitions. Note that this method does not check for circular referencing nor duplication of ids
17000
17022
  * @public
17001
17023
  * @param {Array.<Object>=} groupDefs Use null or empty array to remove all existing groups
17002
17024
  */
17003
17025
  GroupDefinitions.prototype.setGroups = function (groupDefs) {
17004
17026
  // Clear existing group structure
17005
17027
  var groupMap = this._groupMap = {};
17006
- var childToParent = this._childToParent = {};
17007
17028
 
17008
17029
  // Create group map
17009
- var i;
17010
17030
  var grpCount = groupDefs ? groupDefs.length : 0;
17011
- var groupId = "";
17012
- for (i = 0; i < grpCount; i++) {
17031
+ for (var i = 0; i < grpCount; i++) {
17013
17032
  var groupDef = groupDefs[i];
17014
- groupId = groupDef.id;
17033
+ var groupId = groupDef.id;
17015
17034
  if(groupId) {
17016
- groupMap[groupId] = groupDef;
17017
- }
17018
- }
17019
-
17020
- // Create child to parent map
17021
- var groupIds = Object.keys(groupMap);
17022
- grpCount = groupIds.length;
17023
- for(i = 0; i < grpCount; ++i) {
17024
- groupId = groupIds[i];
17025
- var children = groupMap[groupId].children;
17026
- var childCount = children.length;
17027
- for (var j = 0; j < childCount; j++) {
17028
- childToParent[children[j]] = groupId;
17035
+ groupMap[groupId] = GroupDefinitions._cloneObject(groupDef);
17029
17036
  }
17030
17037
  }
17031
17038
 
17032
- // Apply a parent id to group definition to make it easier to find depth
17033
- for(i = 0; i < grpCount; ++i) {
17034
- groupId = groupIds[i];
17035
- var parentId = childToParent[groupId];
17036
- if(parentId) {
17037
- groupMap[groupId].parentId = parentId;
17038
- }
17039
- }
17039
+ this.rebuildMap();
17040
17040
  };
17041
17041
  /** Add new group definition to existing group structure. Existing group with the same id will be replaced.
17042
17042
  * @public
@@ -17065,11 +17065,11 @@ GroupDefinitions.prototype.removeGroup = function (groupId) {
17065
17065
  }
17066
17066
  return false;
17067
17067
  };
17068
- /** Replace and update existing group definition. New group is added if the given id has no match. Existing group will be removed of no new definition is given.
17068
+ /** Replace and update existing group definition. A new group will be added, only if the given id has no match. Existing group will be removed of no new definition is given.
17069
17069
  * @public
17070
17070
  * @param {string} groupId
17071
- * @param {Array.<string>|Object=} groupDef
17072
- * @return {string} Return group Id. Return empty string if nothing has been changed.
17071
+ * @param {(Array.<string>|Object)=} groupDef
17072
+ * @return {string} Return group Id. Return empty string, if nothing has been changed
17073
17073
  */
17074
17074
  GroupDefinitions.prototype.setGroup = function (groupId, groupDef) {
17075
17075
  if(!groupId) {
@@ -17090,7 +17090,7 @@ GroupDefinitions.prototype.setGroup = function (groupId, groupDef) {
17090
17090
  }
17091
17091
  this._groupMap[groupId] = newDef;
17092
17092
 
17093
- var chdr = newDef.children;
17093
+ var chdr = newDef.children; // newDef is guaranteed to have children property
17094
17094
  var len = chdr.length;
17095
17095
  for(var i = 0; i < len; ++i) {
17096
17096
  var childId = chdr[i];
@@ -17122,7 +17122,8 @@ GroupDefinitions.prototype._ungroupChildren = function(children) {
17122
17122
  }
17123
17123
  };
17124
17124
 
17125
- /** @public
17125
+ /** Check if the given child id is an immediate child of the given group
17126
+ * @public
17126
17127
  * @param {string} parentId Group id
17127
17128
  * @param {string} childId
17128
17129
  * @return {boolean}
@@ -17132,7 +17133,30 @@ GroupDefinitions.prototype.hasGroupChild = function (parentId, childId) {
17132
17133
  if(childId && groupDef) {
17133
17134
  var chdr = groupDef.children;
17134
17135
  if(chdr) {
17135
- return chdr.indexOf(childId) >= 0;
17136
+ return chdr.indexOf(childId) >= 0; // TODO: Use childToParent map to improve performance
17137
+ }
17138
+ }
17139
+ return false;
17140
+ };
17141
+ /** Check if the specified id is contained within the given group regardless of any group level that the id is in
17142
+ * @public
17143
+ * @param {string} groupId
17144
+ * @param {string} childId
17145
+ * @return {boolean}
17146
+ */
17147
+ GroupDefinitions.prototype.contains = function (groupId, childId) {
17148
+ if(groupId && childId) {
17149
+ if(groupId === childId) {
17150
+ return true;
17151
+ }
17152
+ var levelLimit = 20;
17153
+ var parentId = this._childToParent[childId];
17154
+ while(parentId && levelLimit) { // WARNING: Circular dependency could happen
17155
+ if(groupId === parentId) {
17156
+ return true;
17157
+ }
17158
+ --levelLimit;
17159
+ parentId = this._childToParent[parentId];
17136
17160
  }
17137
17161
  }
17138
17162
  return false;
@@ -17199,7 +17223,7 @@ GroupDefinitions.prototype.unsetParent = function (childId) {
17199
17223
  var parentDef = this._groupMap[parentId];
17200
17224
  if(parentDef) {
17201
17225
  var chdr = parentDef.children;
17202
- if(chdr.length) {
17226
+ if(chdr && chdr.length) {
17203
17227
  var at = chdr.indexOf(childId);
17204
17228
  if (at >= 0) {
17205
17229
  chdr.splice(at, 1); // splice is slow
@@ -17217,7 +17241,7 @@ GroupDefinitions.prototype.removeAllChildren = function(groupId) {
17217
17241
  var grpDef = this._groupMap[groupId];
17218
17242
  if(grpDef) {
17219
17243
  var chdr = grpDef.children;
17220
- var len = chdr.length;
17244
+ var len = chdr ? chdr.length : 0;
17221
17245
  if(len) {
17222
17246
  grpDef.children = [];
17223
17247
  for(var i = 0; i < len; ++i) {
@@ -36103,7 +36127,7 @@ Core.prototype._batches = null;
36103
36127
  * @return {string}
36104
36128
  */
36105
36129
  Core.getVersion = function () {
36106
- return "5.1.70";
36130
+ return "5.1.71";
36107
36131
  };
36108
36132
  /** {@link ElementWrapper#dispose}
36109
36133
  * @override
@@ -40030,7 +40054,14 @@ Core.prototype.stopBatch = function (batchType) {
40030
40054
  if(!batchType){
40031
40055
  return false;
40032
40056
  }
40057
+ // The "columnVisibilityChanged" event is blocked while the "reset" batch operation is in progress, so this event will not be fired until the batch operation succeeds.
40058
+ if(batchType === "reset") {
40059
+ this._disableEvent("columnVisibilityChanged", true);
40060
+ }
40033
40061
  this._dispatch("afterBatchOperation", { batches: this._batches, batchType: batchType });
40062
+ if(batchType === "reset") {
40063
+ this._disableEvent("columnVisibilityChanged", false);
40064
+ }
40034
40065
 
40035
40066
  delete this._batches[batchType];
40036
40067
  if(isEmptyObject(this._batches)){
@@ -44329,15 +44360,6 @@ var cloneRowData = function(fromRowDef, toRowDef) {
44329
44360
  }
44330
44361
  };
44331
44362
 
44332
- /** @private
44333
- * @param {string} sortField
44334
- * @param {Object} elemData
44335
- * @param {number} index
44336
- */
44337
- var mapRowOrder = function (sortField, elemData, index) { // edit name
44338
- elemData[sortField] = index; // Make column for sort with user data array
44339
- };
44340
-
44341
44363
  /** @private
44342
44364
  * @param {RowDefinition} rowDef
44343
44365
  * @return {boolean}
@@ -46589,20 +46611,11 @@ Grid.prototype.updateDataSet = function(records, rowIdentifier) {
46589
46611
  }
46590
46612
 
46591
46613
  // Map new data index
46592
- var newDataMap = {};
46593
46614
  var recordCount = records.length;
46594
- var record, i;
46595
- for (i = 0; i < recordCount; i++) {
46596
- record = records[i];
46597
- newDataMap[record[rowIdentifier]] = record; // Assign a new data map to compare to the previous data
46598
- }
46599
-
46600
46615
  var fieldSorting = "ROW_ORDER"; // TODO: Should be config by options
46601
- records.forEach(mapRowOrder.bind(null, fieldSorting));
46602
-
46603
46616
  var oldDataMap = {};
46604
- var rowDef, id;
46605
- var rowDefs = this.getRowDefinitions(); // WARNING: Filtered and hidden rows are not included
46617
+ var rowDef, id, record, i;
46618
+ var rowDefs = this.getAllRowDefinitions(); // Include the filter/hidden rows
46606
46619
  var rowDefCount = rowDefs.length;
46607
46620
  for (i = 0; i < rowDefCount; i++) {
46608
46621
  rowDef = rowDefs[i];
@@ -46616,26 +46629,35 @@ Grid.prototype.updateDataSet = function(records, rowIdentifier) {
46616
46629
  }
46617
46630
  }
46618
46631
 
46619
- // Check Remove previous data
46620
- for (var rowIdentifierName in oldDataMap) {
46621
- if (oldDataMap[rowIdentifierName] && !newDataMap[rowIdentifierName]) {
46622
- this.removeRow(oldDataMap[rowIdentifierName]); // Slow
46623
- }
46624
- }
46625
-
46626
46632
  // Check Update and Insert
46627
- for (i = 0; i < recordCount; i++) {
46633
+ var idMap = {};
46634
+ var newDataMap = {};
46635
+ for (i = recordCount - 1; i >= 0; i--) {
46628
46636
  record = records[i];
46629
46637
  id = record[rowIdentifier];
46630
46638
  rowDef = oldDataMap[id];
46639
+ newDataMap[id] = record; // Assign a new data map to compare to the previous data
46640
+ record[fieldSorting] = i;
46641
+ if(idMap[id]) { // Prevent assign data in duplicate row
46642
+ continue;
46643
+ }
46644
+ idMap[id] = true;
46631
46645
  if (!rowDef) {
46632
- this.insertRow({ values: newDataMap[id]}); // Insert last position
46646
+ this.insertRow({ values: record}); // Insert last position
46633
46647
  } else {
46634
46648
  rowDef.setRowData(record);
46635
46649
  }
46636
46650
  }
46651
+
46652
+ // Check Remove previous data
46653
+ for (var rowIdentifierName in oldDataMap) {
46654
+ if (oldDataMap[rowIdentifierName] && !newDataMap[rowIdentifierName]) {
46655
+ this.removeRow(oldDataMap[rowIdentifierName]); // Slow
46656
+ }
46657
+ }
46658
+
46637
46659
  // Sorting
46638
- this._dt.sortOnce("ROW_DEF", "a", compareNumber, fieldSorting);
46660
+ this._dt.sortOnce(ROW_DEF, "a", compareNumber, fieldSorting);
46639
46661
  };
46640
46662
  /** @private
46641
46663
  * @param {Array|Object} item