@refinitiv-ui/efx-grid 6.0.53 → 6.0.55

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.
@@ -11432,7 +11432,7 @@ GroupDefinitions.getLeafDescendants = function (groupMap, groupId) {
11432
11432
  groupDef = unvisitedGroups[visitedCount++];
11433
11433
  visitedMap[groupDef.id] = true;
11434
11434
  var chdr = groupDef.children;
11435
- var len = chdr.length;
11435
+ var len = chdr ? chdr.length : 0;
11436
11436
  for(var i = 0; i < len; ++i) {
11437
11437
  var childId = chdr[i];
11438
11438
  groupDef = groupMap[childId];
@@ -11452,44 +11452,30 @@ GroupDefinitions.getLeafDescendants = function (groupMap, groupId) {
11452
11452
  /** @private
11453
11453
  * @function
11454
11454
  * @param {Object} obj
11455
- * @return {Object}
11455
+ * @return {Object} Return a new object with guaranteed children property
11456
11456
  */
11457
11457
  GroupDefinitions._cloneObject = function(obj) {
11458
11458
  var newObj = cloneObject(obj);
11459
- if(Array.isArray(newObj.children)) {
11460
- newObj.children = newObj.children;
11459
+ if(Array.isArray(newObj.children)) { // This is to prevent modification from the outside source
11460
+ newObj.children = newObj.children.slice();
11461
11461
  } else {
11462
11462
  newObj.children = [];
11463
11463
  }
11464
11464
  return newObj;
11465
11465
  };
11466
- /** @private
11467
- * @param {Object} groupMap
11468
- * @return {!Object}
11469
- */
11470
- GroupDefinitions._cloneGroupMap = function (groupMap) {
11471
- var outMap = {};
11472
- for(var groupId in groupMap) {
11473
- var groupDef = groupMap[groupId];
11474
- var obj = GroupDefinitions._cloneObject(groupDef);
11475
- obj.children = groupDef.children.slice();
11476
- outMap[groupId] = obj;
11477
- }
11478
- return outMap;
11479
- };
11480
11466
 
11481
11467
  /** @private
11482
11468
  * @function
11483
11469
  * @param {Array.<string>|Object} obj
11484
11470
  * @param {string=} groupId
11485
- * @return {Object}
11471
+ * @return {Object} Return a new object with guaranteed children property
11486
11472
  */
11487
11473
  GroupDefinitions._toGroupDefinition = function(obj, groupId) {
11488
11474
  var groupDef = null;
11489
11475
  if(obj) {
11490
11476
  if(Array.isArray(obj)) {
11491
11477
  groupDef = {
11492
- children: obj
11478
+ children: obj.slice()
11493
11479
  };
11494
11480
  } else {
11495
11481
  groupDef = GroupDefinitions._cloneObject(obj);
@@ -11569,7 +11555,43 @@ GroupDefinitions.prototype.getGroupMap = function () {
11569
11555
  * @return {!Object.<string, Object>}
11570
11556
  */
11571
11557
  GroupDefinitions.prototype.cloneGroupMap = function () {
11572
- return GroupDefinitions._cloneGroupMap(this._groupMap);
11558
+ var groupMap = this._groupMap;
11559
+ var outMap = {};
11560
+ for(var groupId in groupMap) {
11561
+ var groupDef = groupMap[groupId];
11562
+ var obj = GroupDefinitions._cloneObject(groupDef);
11563
+ outMap[groupId] = obj;
11564
+ }
11565
+ return outMap;
11566
+ };
11567
+ /** 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
11568
+ * @public
11569
+ */
11570
+ GroupDefinitions.prototype.rebuildMap = function () {
11571
+ var groupMap = this._groupMap;
11572
+ var childToParent = this._childToParent = {};
11573
+
11574
+ // Create child to parent map
11575
+ var groupIds = Object.keys(groupMap);
11576
+ var grpCount = groupIds.length;
11577
+ var i, groupId;
11578
+ for(i = 0; i < grpCount; ++i) {
11579
+ groupId = groupIds[i];
11580
+ var chdr = groupMap[groupId].children;
11581
+ var childCount = chdr ? chdr.length : 0;
11582
+ for (var j = 0; j < childCount; j++) {
11583
+ childToParent[chdr[j]] = groupId;
11584
+ }
11585
+ }
11586
+
11587
+ // Apply a parent id to group definition to make it easier to find depth
11588
+ for(i = 0; i < grpCount; ++i) {
11589
+ groupId = groupIds[i];
11590
+ var parentId = childToParent[groupId];
11591
+ if(parentId) {
11592
+ groupMap[groupId].parentId = parentId;
11593
+ }
11594
+ }
11573
11595
  };
11574
11596
 
11575
11597
  /** Get immediate child ids of the specified group. The returned array can contain both child ids and group ids
@@ -11649,7 +11671,7 @@ GroupDefinitions.prototype.getParentIds = function(childId) {
11649
11671
  };
11650
11672
  /** @public
11651
11673
  * @param {string} childId
11652
- * @param {number=} groupLevel
11674
+ * @param {number=} groupLevel Default is to retrieve immediate parent id. Use 0 to get root (topmost) group id
11653
11675
  * @return {string}
11654
11676
  */
11655
11677
  GroupDefinitions.prototype.getParentId = function (childId, groupLevel) {
@@ -11677,47 +11699,25 @@ GroupDefinitions.prototype.removeAllGroups = function () {
11677
11699
  }
11678
11700
  return false;
11679
11701
  };
11680
- /** Remove all existing group definitions and replace them with the given definitions.
11702
+ /** 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
11681
11703
  * @public
11682
11704
  * @param {Array.<Object>=} groupDefs Use null or empty array to remove all existing groups
11683
11705
  */
11684
11706
  GroupDefinitions.prototype.setGroups = function (groupDefs) {
11685
11707
  // Clear existing group structure
11686
11708
  var groupMap = this._groupMap = {};
11687
- var childToParent = this._childToParent = {};
11688
11709
 
11689
11710
  // Create group map
11690
- var i;
11691
11711
  var grpCount = groupDefs ? groupDefs.length : 0;
11692
- var groupId = "";
11693
- for (i = 0; i < grpCount; i++) {
11712
+ for (var i = 0; i < grpCount; i++) {
11694
11713
  var groupDef = groupDefs[i];
11695
- groupId = groupDef.id;
11714
+ var groupId = groupDef.id;
11696
11715
  if(groupId) {
11697
- groupMap[groupId] = groupDef;
11716
+ groupMap[groupId] = GroupDefinitions._cloneObject(groupDef);
11698
11717
  }
11699
11718
  }
11700
11719
 
11701
- // Create child to parent map
11702
- var groupIds = Object.keys(groupMap);
11703
- grpCount = groupIds.length;
11704
- for(i = 0; i < grpCount; ++i) {
11705
- groupId = groupIds[i];
11706
- var children = groupMap[groupId].children;
11707
- var childCount = children.length;
11708
- for (var j = 0; j < childCount; j++) {
11709
- childToParent[children[j]] = groupId;
11710
- }
11711
- }
11712
-
11713
- // Apply a parent id to group definition to make it easier to find depth
11714
- for(i = 0; i < grpCount; ++i) {
11715
- groupId = groupIds[i];
11716
- var parentId = childToParent[groupId];
11717
- if(parentId) {
11718
- groupMap[groupId].parentId = parentId;
11719
- }
11720
- }
11720
+ this.rebuildMap();
11721
11721
  };
11722
11722
  /** Add new group definition to existing group structure. Existing group with the same id will be replaced.
11723
11723
  * @public
@@ -11746,11 +11746,11 @@ GroupDefinitions.prototype.removeGroup = function (groupId) {
11746
11746
  }
11747
11747
  return false;
11748
11748
  };
11749
- /** 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.
11749
+ /** 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.
11750
11750
  * @public
11751
11751
  * @param {string} groupId
11752
- * @param {Array.<string>|Object=} groupDef
11753
- * @return {string} Return group Id. Return empty string if nothing has been changed.
11752
+ * @param {(Array.<string>|Object)=} groupDef
11753
+ * @return {string} Return group Id. Return empty string, if nothing has been changed
11754
11754
  */
11755
11755
  GroupDefinitions.prototype.setGroup = function (groupId, groupDef) {
11756
11756
  if(!groupId) {
@@ -11771,7 +11771,7 @@ GroupDefinitions.prototype.setGroup = function (groupId, groupDef) {
11771
11771
  }
11772
11772
  this._groupMap[groupId] = newDef;
11773
11773
 
11774
- var chdr = newDef.children;
11774
+ var chdr = newDef.children; // newDef is guaranteed to have children property
11775
11775
  var len = chdr.length;
11776
11776
  for(var i = 0; i < len; ++i) {
11777
11777
  var childId = chdr[i];
@@ -11803,7 +11803,8 @@ GroupDefinitions.prototype._ungroupChildren = function(children) {
11803
11803
  }
11804
11804
  };
11805
11805
 
11806
- /** @public
11806
+ /** Check if the given child id is an immediate child of the given group
11807
+ * @public
11807
11808
  * @param {string} parentId Group id
11808
11809
  * @param {string} childId
11809
11810
  * @return {boolean}
@@ -11813,7 +11814,30 @@ GroupDefinitions.prototype.hasGroupChild = function (parentId, childId) {
11813
11814
  if(childId && groupDef) {
11814
11815
  var chdr = groupDef.children;
11815
11816
  if(chdr) {
11816
- return chdr.indexOf(childId) >= 0;
11817
+ return chdr.indexOf(childId) >= 0; // TODO: Use childToParent map to improve performance
11818
+ }
11819
+ }
11820
+ return false;
11821
+ };
11822
+ /** Check if the specified id is contained within the given group regardless of any group level that the id is in
11823
+ * @public
11824
+ * @param {string} groupId
11825
+ * @param {string} childId
11826
+ * @return {boolean}
11827
+ */
11828
+ GroupDefinitions.prototype.contains = function (groupId, childId) {
11829
+ if(groupId && childId) {
11830
+ if(groupId === childId) {
11831
+ return true;
11832
+ }
11833
+ var levelLimit = 20;
11834
+ var parentId = this._childToParent[childId];
11835
+ while(parentId && levelLimit) { // WARNING: Circular dependency could happen
11836
+ if(groupId === parentId) {
11837
+ return true;
11838
+ }
11839
+ --levelLimit;
11840
+ parentId = this._childToParent[parentId];
11817
11841
  }
11818
11842
  }
11819
11843
  return false;
@@ -11880,7 +11904,7 @@ GroupDefinitions.prototype.unsetParent = function (childId) {
11880
11904
  var parentDef = this._groupMap[parentId];
11881
11905
  if(parentDef) {
11882
11906
  var chdr = parentDef.children;
11883
- if(chdr.length) {
11907
+ if(chdr && chdr.length) {
11884
11908
  var at = chdr.indexOf(childId);
11885
11909
  if (at >= 0) {
11886
11910
  chdr.splice(at, 1); // splice is slow
@@ -11898,7 +11922,7 @@ GroupDefinitions.prototype.removeAllChildren = function(groupId) {
11898
11922
  var grpDef = this._groupMap[groupId];
11899
11923
  if(grpDef) {
11900
11924
  var chdr = grpDef.children;
11901
- var len = chdr.length;
11925
+ var len = chdr ? chdr.length : 0;
11902
11926
  if(len) {
11903
11927
  grpDef.children = [];
11904
11928
  for(var i = 0; i < len; ++i) {
@@ -26029,7 +26053,7 @@ Core_Core.prototype._batches = null;
26029
26053
  * @return {string}
26030
26054
  */
26031
26055
  Core_Core.getVersion = function () {
26032
- return "5.1.70";
26056
+ return "5.1.72";
26033
26057
  };
26034
26058
  /** {@link ElementWrapper#dispose}
26035
26059
  * @override
@@ -29912,18 +29936,21 @@ Core_Core.prototype.getValidColumnList = function (colIds, columnMap) {
29912
29936
  };
29913
29937
 
29914
29938
  /** @public
29915
- * @description Create mapping object from an array of strings
29916
- * @param {Array.<string>=} colIds
29939
+ * @description Create mapping object from an array of strings or column indices
29940
+ * @param {Array.<string|number>=} colRefs
29917
29941
  * @return {!Object} Column mapping object
29918
29942
  */
29919
- Core_Core.prototype.createColumnMap = function (colIds) {
29920
- if(!colIds){
29921
- colIds = this.getColumnIds();
29943
+ Core_Core.prototype.createColumnMap = function (colRefs) {
29944
+ if(!colRefs){
29945
+ colRefs = this.getColumnIds();
29922
29946
  }
29923
29947
  var mappingObj = {};
29924
- var count = colIds.length;
29948
+ var count = colRefs.length;
29925
29949
  for(var i = 0; i < count; i++){
29926
- var colId = colIds[i];
29950
+ var colId = colRefs[i];
29951
+ if(typeof colId === "number"){
29952
+ colId = this.getColumnId(colId);
29953
+ }
29927
29954
  if(colId){
29928
29955
  mappingObj[colId] = true;
29929
29956
  }
@@ -29956,7 +29983,14 @@ Core_Core.prototype.stopBatch = function (batchType) {
29956
29983
  if(!batchType){
29957
29984
  return false;
29958
29985
  }
29986
+ // 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.
29987
+ if(batchType === "reset") {
29988
+ this._disableEvent("columnVisibilityChanged", true);
29989
+ }
29959
29990
  this._dispatch("afterBatchOperation", { batches: this._batches, batchType: batchType });
29991
+ if(batchType === "reset") {
29992
+ this._disableEvent("columnVisibilityChanged", false);
29993
+ }
29960
29994
 
29961
29995
  delete this._batches[batchType];
29962
29996
  if(isEmptyObject(this._batches)){