@agorapulse/ui-components 20.1.6 → 20.1.7

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.
@@ -1730,15 +1730,47 @@ class NavSelectorState {
1730
1730
  if (!leaf.selectable) {
1731
1731
  return;
1732
1732
  }
1733
- if (this.multipleModeEnabled()) {
1734
- this.entries.update(entries => NavSelectorMultiSelect.selectInMultipleMode(entries, leaf.uid));
1735
- }
1736
- else {
1737
- this.entries.update(entries => NavSelectorSingleSelect.select(entries, leaf.uid));
1738
- }
1733
+ this.entries.update(entries => {
1734
+ let updatedEntries = entries;
1735
+ if (leaf.foldable) {
1736
+ const options = this.getFoldingOptions();
1737
+ const unfoldedLeafUids = this.findUnfoldedLeafUids(entries);
1738
+ for (const uid of unfoldedLeafUids) {
1739
+ updatedEntries = NavSelectorFolding.fold(updatedEntries, uid, options);
1740
+ }
1741
+ }
1742
+ if (this.multipleModeEnabled()) {
1743
+ return NavSelectorMultiSelect.selectInMultipleMode(updatedEntries, leaf.uid);
1744
+ }
1745
+ else {
1746
+ return NavSelectorSingleSelect.select(updatedEntries, leaf.uid);
1747
+ }
1748
+ });
1739
1749
  }
1740
1750
  onLeafToggleFolding(leaf) {
1741
- this.entries.update(entries => NavSelectorFolding.toggleFolding(entries, leaf.uid, this.getFoldingOptions()));
1751
+ this.entries.update(entries => {
1752
+ const options = this.getFoldingOptions();
1753
+ // Find all unfolded leaves and fold them first
1754
+ let updatedEntries = entries;
1755
+ const unfoldedLeafUids = this.findUnfoldedLeafUids(entries);
1756
+ for (const uid of unfoldedLeafUids) {
1757
+ updatedEntries = NavSelectorFolding.fold(updatedEntries, uid, options);
1758
+ }
1759
+ // Then unfold the clicked leaf
1760
+ return NavSelectorFolding.toggleFolding(updatedEntries, leaf.uid, options);
1761
+ });
1762
+ }
1763
+ findUnfoldedLeafUids(entries) {
1764
+ const unfoldedUids = [];
1765
+ for (const entry of entries) {
1766
+ if (isInternalNavSelectorEntryALeaf(entry) && entry.foldable && !entry.folded) {
1767
+ unfoldedUids.push(entry.uid);
1768
+ }
1769
+ else if (isInternalNavSelectorEntryANode(entry)) {
1770
+ unfoldedUids.push(...this.findUnfoldedLeafUids(entry.children));
1771
+ }
1772
+ }
1773
+ return unfoldedUids;
1742
1774
  }
1743
1775
  onLeafDetailClicked(leafDetail) {
1744
1776
  this.entries.update(entries => NavSelectorSingleSelect.select(entries, leafDetail.uid));
@@ -1788,12 +1820,18 @@ class NavSelectorState {
1788
1820
  entries = NavSelectorMultiSelect.selectInMultipleMode(entries, uid);
1789
1821
  }
1790
1822
  for (const uid of uidToSelect) {
1791
- entries = NavSelectorFolding.unfoldParents(entries, uid, { multipleMode: true, minified: !this.expanded() });
1823
+ entries = NavSelectorFolding.unfoldParents(entries, uid, {
1824
+ multipleMode: true,
1825
+ minified: !this.expanded(),
1826
+ });
1792
1827
  }
1793
1828
  }
1794
1829
  else {
1795
1830
  entries = NavSelectorSingleSelect.select(entries, uids[0]);
1796
- entries = NavSelectorFolding.unfoldParents(entries, uids[0], { multipleMode: false, minified: !this.expanded() });
1831
+ entries = NavSelectorFolding.unfoldParents(entries, uids[0], {
1832
+ multipleMode: false,
1833
+ minified: !this.expanded(),
1834
+ });
1797
1835
  }
1798
1836
  this.entries.set(entries);
1799
1837
  }