@ptsecurity/mosaic 14.10.2 → 14.10.4

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.
@@ -346,7 +346,7 @@ class McTreeNodeToggleBaseDirective extends McTreeNodeToggleMixinBase {
346
346
  this.treeNode = treeNode;
347
347
  this._recursive = false;
348
348
  this.tree.treeControl.filterValue
349
- .pipe(map((value) => value?.length > 0))
349
+ .pipe(map((value) => !!value && value.length > 0))
350
350
  .subscribe((state) => this.disabled = state);
351
351
  }
352
352
  get recursive() {
@@ -929,61 +929,61 @@ class FlatTreeControl extends BaseTreeControl {
929
929
  hasValue(value) {
930
930
  return this.dataNodes.find((node) => this.compareValues(this.getValue(node), value));
931
931
  }
932
- filterNodes(value) {
932
+ filterNodes(value = null) {
933
933
  this.saveExpansionState();
934
- this.filterModel.clear();
935
- this.expansionModel.clear();
936
- const filteredNodes = this.dataNodes
937
- .filter((node) => this.compareViewValues(this.getViewValue(node), value));
934
+ const filteredNodes = [];
938
935
  const filteredNodesWithTheirParents = new Set();
939
- filteredNodes.forEach((filteredNode) => {
940
- this.getParents(filteredNode, [])
941
- .forEach((node) => {
936
+ for (const node of this.dataNodes) {
937
+ if (this.compareViewValues(this.getViewValue(node), value)) {
938
+ filteredNodes.push(node);
939
+ }
940
+ }
941
+ for (const filteredNode of filteredNodes) {
942
+ for (const node of this.getParents(filteredNode, [])) {
942
943
  filteredNodesWithTheirParents.add(node);
943
- this.expandDataNode(node);
944
- });
944
+ }
945
945
  filteredNodesWithTheirParents.add(filteredNode);
946
- this.expandDataNode(filteredNode);
947
946
  if (this.isExpandable(filteredNode)) {
948
947
  const childNodeLevel = this.getLevel(filteredNode) + 1;
949
- this.getDescendants(filteredNode)
950
- .filter((childNode) => this.getLevel(childNode) === childNodeLevel)
951
- .filter((childNode) => !this.isExpandable(childNode) || !this.hasFilteredDescendant(childNode, filteredNodes))
952
- .forEach((childNode) => {
953
- filteredNodesWithTheirParents.add(childNode);
954
- this.expandDataNode(childNode);
955
- });
948
+ for (const childNode of this.getDescendants(filteredNode)) {
949
+ if (this.getLevel(childNode) === childNodeLevel &&
950
+ (!this.isExpandable(childNode) || !this.hasFilteredDescendant(childNode, filteredNodes))) {
951
+ filteredNodesWithTheirParents.add(childNode);
952
+ }
953
+ }
956
954
  }
957
- });
955
+ }
956
+ this.filterModel.clear();
958
957
  this.filterModel.select(...Array.from(filteredNodesWithTheirParents));
958
+ // set current expansion state according to filtered tree
959
+ this.expansionModel.setSelection(...Array.from(filteredNodesWithTheirParents).filter((node) => this.isExpandable(node)));
959
960
  this.updateFilterValue(value);
960
961
  this.restoreExpansionState();
961
962
  }
962
963
  updateFilterValue(value) {
963
964
  Promise.resolve().then(() => this.filterValue.next(value));
964
965
  }
965
- expandDataNode(dataNode) {
966
- if (this.isExpandable(dataNode)) {
967
- this.expansionModel.select(dataNode);
968
- }
969
- }
970
966
  saveExpansionState() {
971
- if (this.filterValue.value === '') {
967
+ if (!this.filterValue.value) {
972
968
  this.expandedItemsBeforeFiltration = this.expansionModel.selected;
973
969
  }
974
970
  }
975
971
  restoreExpansionState() {
976
- if (this.filterValue.value === '') {
977
- this.expansionModel.clear();
978
- this.expansionModel.select(...this.expandedItemsBeforeFiltration);
972
+ if (!this.filterValue.value) {
973
+ this.expansionModel.setSelection(...this.expandedItemsBeforeFiltration);
979
974
  }
980
975
  }
981
976
  hasFilteredDescendant(dataNode, filteredNodes) {
982
- const filteredViewValues = filteredNodes
983
- .map((node) => this.getViewValue(node));
984
- return this.getDescendants(dataNode)
985
- .filter((node) => filteredViewValues.includes(this.getViewValue(node)))
986
- .length > 0;
977
+ const filteredViewValues = [];
978
+ for (const node of filteredNodes) {
979
+ filteredViewValues.push(this.getViewValue(node));
980
+ }
981
+ for (const node of this.getDescendants(dataNode)) {
982
+ if (filteredViewValues.includes(this.getViewValue(node))) {
983
+ return true;
984
+ }
985
+ }
986
+ return false;
987
987
  }
988
988
  }
989
989