cloud-ide-element 1.1.84 → 1.1.85

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.
@@ -9390,6 +9390,7 @@ class CideEleDataGridComponent {
9390
9390
  showManageColumnsModal = signal(false, ...(ngDevMode ? [{ debugName: "showManageColumnsModal" }] : [])); // Show manage columns modal
9391
9391
  groupedColumns = signal([], ...(ngDevMode ? [{ debugName: "groupedColumns" }] : [])); // Columns to group by
9392
9392
  expandedGroups = signal(new Set(), ...(ngDevMode ? [{ debugName: "expandedGroups" }] : [])); // Expanded group keys
9393
+ hasAutoExpandedGroups = false; // Track if we've auto-expanded groups on initial load
9393
9394
  // Export menu state
9394
9395
  showExportMenu = signal(false, ...(ngDevMode ? [{ debugName: "showExportMenu" }] : [])); // Show/hide export format dropdown
9395
9396
  showFilterDropdown = signal(false, ...(ngDevMode ? [{ debugName: "showFilterDropdown" }] : [])); // Show/hide filter dropdown
@@ -9600,15 +9601,33 @@ class CideEleDataGridComponent {
9600
9601
  if (groupableColumns.length > 0) {
9601
9602
  console.log('🔍 Auto-applying grouping for columns:', groupableColumns);
9602
9603
  this.groupedColumns.set(groupableColumns);
9603
- // Expand all groups by default for each grouped column
9604
- groupableColumns.forEach(columnKey => {
9605
- const column = columns.find(c => c.key === columnKey);
9606
- if (column) {
9607
- this.expandAllGroupsForColumn(columnKey);
9608
- }
9609
- });
9604
+ // Reset auto-expand flag so groups will be expanded on first render
9605
+ this.hasAutoExpandedGroups = false;
9606
+ }
9607
+ }
9608
+ }
9609
+ /**
9610
+ * Check if groups should be auto-expanded (only on initial load)
9611
+ */
9612
+ shouldAutoExpandGroups() {
9613
+ // Auto-expand only once on initial load when default grouping is applied
9614
+ if (this.groupedColumns().length > 0) {
9615
+ // Check if this is default grouping (all groupable columns are grouped)
9616
+ const columns = this.mergedConfig().columns || [];
9617
+ const groupableColumns = columns
9618
+ .filter(col => col.groupable === true)
9619
+ .map(col => col.key);
9620
+ const grouped = this.groupedColumns();
9621
+ // If all groupable columns are grouped, this is likely default grouping
9622
+ const isDefaultGrouping = groupableColumns.length > 0 &&
9623
+ groupableColumns.every(key => grouped.includes(key));
9624
+ // Only auto-expand if it's default grouping and we haven't marked it as done yet
9625
+ if (isDefaultGrouping && !this.hasAutoExpandedGroups) {
9626
+ // Mark as done after first check, but allow all groups in this grouping pass to be expanded
9627
+ return true;
9610
9628
  }
9611
9629
  }
9630
+ return false;
9612
9631
  }
9613
9632
  /**
9614
9633
  * Get the unique identifier for an item
@@ -10034,6 +10053,108 @@ class CideEleDataGridComponent {
10034
10053
  console.log('flattenTreeForDisplay - result:', result.length, 'items');
10035
10054
  return result;
10036
10055
  }
10056
+ /**
10057
+ * Flatten tree structure for grouping while preserving parent-child relationships
10058
+ */
10059
+ flattenTreeForGrouping(treeItems) {
10060
+ const result = [];
10061
+ const treeConfig = this.mergedConfig().tree;
10062
+ if (!treeConfig)
10063
+ return treeItems;
10064
+ const { childrenKey = 'children' } = treeConfig;
10065
+ // Flatten all items (both expanded and collapsed) for grouping
10066
+ const flatten = (items) => {
10067
+ items.forEach(item => {
10068
+ result.push(item);
10069
+ const children = this.getNestedValue(item, childrenKey) || [];
10070
+ if (children.length > 0) {
10071
+ flatten(children);
10072
+ }
10073
+ });
10074
+ };
10075
+ flatten(treeItems);
10076
+ return result;
10077
+ }
10078
+ /**
10079
+ * Restore tree structure within grouped data
10080
+ * This method processes grouped data and restores parent-child relationships
10081
+ */
10082
+ restoreTreeStructureInGroups(groupedData) {
10083
+ const treeConfig = this.mergedConfig().tree;
10084
+ if (!treeConfig)
10085
+ return groupedData;
10086
+ const { primaryKey = '_id', foreignKey, childrenKey = 'children' } = treeConfig;
10087
+ const result = [];
10088
+ const processedItems = new Set();
10089
+ // Helper to find parent in result array (including nested in group headers)
10090
+ const findParentInResult = (parentId) => {
10091
+ const searchInArray = (items) => {
10092
+ for (const item of items) {
10093
+ // Skip group headers for parent search
10094
+ if (item?._isGroupHeader) {
10095
+ continue;
10096
+ }
10097
+ const itemId = String(this.getNestedValue(item, primaryKey) || '');
10098
+ if (itemId === parentId) {
10099
+ return item;
10100
+ }
10101
+ // Check children recursively
10102
+ const children = this.getNestedValue(item, childrenKey) || [];
10103
+ if (children.length > 0) {
10104
+ const found = searchInArray(children);
10105
+ if (found)
10106
+ return found;
10107
+ }
10108
+ }
10109
+ return null;
10110
+ };
10111
+ return searchInArray(result);
10112
+ };
10113
+ // Process each item in grouped data
10114
+ groupedData.forEach(item => {
10115
+ // If it's a group header, add it directly
10116
+ if (item?._isGroupHeader) {
10117
+ result.push(item);
10118
+ return;
10119
+ }
10120
+ const itemId = String(this.getNestedValue(item, primaryKey) || '');
10121
+ if (!itemId || processedItems.has(itemId)) {
10122
+ return;
10123
+ }
10124
+ const parentIdValue = this.getNestedValue(item, foreignKey);
10125
+ const parentId = parentIdValue !== null && parentIdValue !== undefined ? String(parentIdValue) : '';
10126
+ if (parentId) {
10127
+ // Item has a parent - try to find parent
10128
+ const parent = findParentInResult(parentId);
10129
+ if (parent) {
10130
+ // Parent found - add as child
10131
+ let children = this.getNestedValue(parent, childrenKey) || [];
10132
+ if (!Array.isArray(children)) {
10133
+ children = [];
10134
+ }
10135
+ // Check if already added
10136
+ const exists = children.some(child => String(this.getNestedValue(child, primaryKey) || '') === itemId);
10137
+ if (!exists) {
10138
+ children.push(item);
10139
+ this.setNestedValue(parent, childrenKey, children);
10140
+ this.setNestedValue(parent, 'hasChildren', true);
10141
+ processedItems.add(itemId);
10142
+ }
10143
+ }
10144
+ else {
10145
+ // Parent not found yet - add as root for now (will be moved if parent appears later)
10146
+ result.push(item);
10147
+ processedItems.add(itemId);
10148
+ }
10149
+ }
10150
+ else {
10151
+ // No parent - add as root
10152
+ result.push(item);
10153
+ processedItems.add(itemId);
10154
+ }
10155
+ });
10156
+ return result;
10157
+ }
10037
10158
  /**
10038
10159
  * Toggle expand/collapse state of a tree item with unlimited nesting support
10039
10160
  */
@@ -11541,11 +11662,23 @@ class CideEleDataGridComponent {
11541
11662
  console.log('🔍 Using local reordered data for display:', this.localReorderedData.length, 'items');
11542
11663
  return this.localReorderedData;
11543
11664
  }
11544
- const data = this.filteredData();
11665
+ let data = this.filteredData();
11545
11666
  // Apply grouping if any columns are grouped
11546
11667
  const grouped = this.groupedColumns();
11547
11668
  if (grouped.length > 0 && !this.serverSidePagination) {
11548
- return this.getGroupedData(data, grouped);
11669
+ // If tree is enabled, we need to flatten tree first for grouping, then preserve structure
11670
+ const treeConfig = this.mergedConfig().tree;
11671
+ if (treeConfig?.enabled) {
11672
+ // Flatten tree structure for grouping, but preserve parent-child relationships
11673
+ data = this.flattenTreeForGrouping(data);
11674
+ }
11675
+ // Apply grouping
11676
+ data = this.getGroupedData(data, grouped);
11677
+ // If tree is enabled, restore tree structure within groups
11678
+ if (treeConfig?.enabled) {
11679
+ data = this.restoreTreeStructureInGroups(data);
11680
+ }
11681
+ return data;
11549
11682
  }
11550
11683
  // For server-side pagination, the server already provides the correct page of data
11551
11684
  // For client-side pagination, we need to slice the data
@@ -11587,6 +11720,9 @@ class CideEleDataGridComponent {
11587
11720
  const displayValueGetter = column.valueGetter || column.key;
11588
11721
  const groupKeyGetter = column.dataValueGetter || column.valueGetter || column.key;
11589
11722
  const groups = new Map();
11723
+ // Check if tree structure is enabled
11724
+ const treeConfig = this.mergedConfig().tree;
11725
+ const childrenKey = treeConfig?.childrenKey || 'children';
11590
11726
  // Group the data by current column
11591
11727
  data.forEach(row => {
11592
11728
  // Get raw value for grouping key
@@ -11624,6 +11760,9 @@ class CideEleDataGridComponent {
11624
11760
  });
11625
11761
  // Flatten groups into display array
11626
11762
  const result = [];
11763
+ const expanded = this.expandedGroups();
11764
+ const newExpanded = new Set(expanded);
11765
+ const shouldAutoExpand = this.shouldAutoExpandGroups();
11627
11766
  groups.forEach((group, groupKey) => {
11628
11767
  // Add group header row
11629
11768
  const groupHeader = {
@@ -11637,19 +11776,58 @@ class CideEleDataGridComponent {
11637
11776
  _groupPath: level > 0 ? this.buildGroupPath(group.rows[0], groupColumns, level) : []
11638
11777
  };
11639
11778
  result.push(groupHeader);
11640
- // Add group rows if expanded
11641
- if (this.isGroupExpanded(groupKey)) {
11642
- // If there are more grouping levels, recursively group the rows
11779
+ // Auto-expand groups by default if they're not explicitly collapsed
11780
+ // This ensures groups are expanded on initial load
11781
+ const isExpanded = expanded.has(groupKey);
11782
+ if (shouldAutoExpand && !isExpanded) {
11783
+ // Add to expanded set if auto-expanding
11784
+ newExpanded.add(groupKey);
11785
+ }
11786
+ // Show group rows if expanded or should be auto-expanded
11787
+ if (isExpanded || (shouldAutoExpand && !isExpanded)) {
11788
+ // Process rows while preserving tree structure
11789
+ const processedRows = [];
11790
+ group.rows.forEach(row => {
11791
+ // Check if this row has children (tree structure)
11792
+ const children = treeConfig?.enabled ? this.getNestedValue(row, childrenKey) : undefined;
11793
+ if (children && Array.isArray(children) && children.length > 0) {
11794
+ // This row has children - preserve tree structure
11795
+ const processedRow = { ...row };
11796
+ // Recursively process children if there are more grouping levels
11797
+ if (level + 1 < groupColumns.length) {
11798
+ // Apply grouping to children
11799
+ const groupedChildren = this.groupDataRecursive(children, groupColumns, level + 1);
11800
+ // Update the row with grouped children
11801
+ this.setNestedValue(processedRow, childrenKey, groupedChildren);
11802
+ }
11803
+ else {
11804
+ // No more grouping levels, but preserve children structure
11805
+ this.setNestedValue(processedRow, childrenKey, children);
11806
+ }
11807
+ processedRows.push(processedRow);
11808
+ }
11809
+ else {
11810
+ // Regular row without children
11811
+ processedRows.push(row);
11812
+ }
11813
+ });
11814
+ // If there are more grouping levels, recursively group the processed rows
11643
11815
  if (level + 1 < groupColumns.length) {
11644
- const nestedGroups = this.groupDataRecursive(group.rows, groupColumns, level + 1);
11816
+ const nestedGroups = this.groupDataRecursive(processedRows, groupColumns, level + 1);
11645
11817
  result.push(...nestedGroups);
11646
11818
  }
11647
11819
  else {
11648
- // Last level, just add the rows
11649
- result.push(...group.rows);
11820
+ // Last level, add the processed rows (with preserved tree structure)
11821
+ result.push(...processedRows);
11650
11822
  }
11651
11823
  }
11652
11824
  });
11825
+ // Update expanded groups set if we auto-expanded any
11826
+ if (shouldAutoExpand && newExpanded.size > expanded.size) {
11827
+ this.expandedGroups.set(newExpanded);
11828
+ // Mark that we've auto-expanded groups so we don't do it again on subsequent renders
11829
+ this.hasAutoExpandedGroups = true;
11830
+ }
11653
11831
  return result;
11654
11832
  }
11655
11833
  /**