cloud-ide-element 1.1.87 → 1.1.89

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.
@@ -10052,10 +10052,17 @@ class CideEleDataGridComponent {
10052
10052
  if (!treeConfig)
10053
10053
  return treeItems;
10054
10054
  const { childrenKey = 'children' } = treeConfig;
10055
- // Flatten all items (both expanded and collapsed) for grouping
10055
+ // Flatten all items for grouping, but preserve the children structure in each parent
10056
+ // This ensures that when we restore, we can show children when parent is expanded
10056
10057
  const flatten = (items) => {
10057
10058
  items.forEach(item => {
10058
- result.push(item);
10059
+ // Create a copy of the item to add to flat list
10060
+ // But preserve the original children array in the item itself
10061
+ const itemCopy = { ...item };
10062
+ result.push(itemCopy);
10063
+ // Recursively flatten children
10064
+ // Note: The children remain in the original item's children array
10065
+ // They are also added to the flat list for grouping
10059
10066
  const children = this.getNestedValue(item, childrenKey) || [];
10060
10067
  if (children.length > 0) {
10061
10068
  flatten(children);
@@ -10073,78 +10080,75 @@ class CideEleDataGridComponent {
10073
10080
  const treeConfig = this.mergedConfig().tree;
10074
10081
  if (!treeConfig)
10075
10082
  return groupedData;
10076
- const { primaryKey = '_id', foreignKey, childrenKey = 'children' } = treeConfig;
10083
+ const { primaryKey, foreignKey, childrenKey = 'children', expandedKey = 'isExpanded', levelKey = 'level' } = treeConfig;
10077
10084
  const result = [];
10078
- const processedItems = new Set();
10079
- // Helper to find parent in result array (including nested in group headers)
10080
- const findParentInResult = (parentId) => {
10081
- const searchInArray = (items) => {
10082
- for (const item of items) {
10083
- // Skip group headers for parent search
10084
- if (item?._isGroupHeader) {
10085
- continue;
10086
- }
10087
- const itemId = String(this.getNestedValue(item, primaryKey) || '');
10088
- if (itemId === parentId) {
10089
- return item;
10090
- }
10091
- // Check children recursively
10092
- const children = this.getNestedValue(item, childrenKey) || [];
10093
- if (children.length > 0) {
10094
- const found = searchInArray(children);
10095
- if (found)
10096
- return found;
10097
- }
10098
- }
10099
- return null;
10100
- };
10101
- return searchInArray(result);
10102
- };
10103
- // Process each item in grouped data
10085
+ const itemMap = new Map();
10086
+ // First pass: build a map of all items and nest children under parents
10104
10087
  groupedData.forEach(item => {
10105
- // If it's a group header, add it directly
10088
+ // If it's a group header, add it directly to result
10106
10089
  if (item?._isGroupHeader) {
10107
10090
  result.push(item);
10108
10091
  return;
10109
10092
  }
10110
10093
  const itemId = String(this.getNestedValue(item, primaryKey) || '');
10111
- if (!itemId || processedItems.has(itemId)) {
10094
+ if (!itemId) {
10095
+ result.push(item);
10112
10096
  return;
10113
10097
  }
10098
+ // Store item in map
10099
+ itemMap.set(itemId, item);
10100
+ // Get parent ID
10114
10101
  const parentIdValue = this.getNestedValue(item, foreignKey);
10115
- // Extract parent ID generically - handle both string IDs and nested objects
10116
10102
  const parentId = this.extractIdFromForeignKey(parentIdValue, primaryKey);
10117
- if (parentId) {
10118
- // Item has a parent - try to find parent
10119
- const parent = findParentInResult(parentId);
10120
- if (parent) {
10121
- // Parent found - add as child
10122
- let children = this.getNestedValue(parent, childrenKey) || [];
10123
- if (!Array.isArray(children)) {
10124
- children = [];
10125
- }
10126
- // Check if already added
10127
- const exists = children.some(child => String(this.getNestedValue(child, primaryKey) || '') === itemId);
10128
- if (!exists) {
10129
- children.push(item);
10130
- this.setNestedValue(parent, childrenKey, children);
10131
- this.setNestedValue(parent, 'hasChildren', true);
10132
- processedItems.add(itemId);
10133
- }
10103
+ if (parentId && itemMap.has(parentId)) {
10104
+ // Item has a parent - add to parent's children
10105
+ const parent = itemMap.get(parentId);
10106
+ let children = this.getNestedValue(parent, childrenKey) || [];
10107
+ if (!Array.isArray(children)) {
10108
+ children = [];
10134
10109
  }
10135
- else {
10136
- // Parent not found yet - add as root for now (will be moved if parent appears later)
10137
- result.push(item);
10138
- processedItems.add(itemId);
10110
+ // Check if already added
10111
+ const exists = children.some(child => String(this.getNestedValue(child, primaryKey) || '') === itemId);
10112
+ if (!exists) {
10113
+ children.push(item);
10114
+ this.setNestedValue(parent, childrenKey, children);
10115
+ this.setNestedValue(parent, 'hasChildren', true);
10139
10116
  }
10140
10117
  }
10141
10118
  else {
10142
- // No parent - add as root
10119
+ // No parent or parent not found - add as root
10143
10120
  result.push(item);
10144
- processedItems.add(itemId);
10145
10121
  }
10146
10122
  });
10147
- return result;
10123
+ // Second pass: flatten the tree structure for display, showing children when parent is expanded
10124
+ const flattenedResult = [];
10125
+ const processItem = (item, depth = 0) => {
10126
+ // If it's a group header, add it directly
10127
+ if (item?._isGroupHeader) {
10128
+ flattenedResult.push(item);
10129
+ return;
10130
+ }
10131
+ // Add the item with its level
10132
+ const itemWithLevel = {
10133
+ ...item,
10134
+ [levelKey]: depth
10135
+ };
10136
+ flattenedResult.push(itemWithLevel);
10137
+ // Check if item has children and is expanded
10138
+ const children = this.getNestedValue(item, childrenKey) || [];
10139
+ const isExpanded = this.getNestedValue(item, expandedKey) || false;
10140
+ // If item is expanded and has children, recursively process children
10141
+ if (isExpanded && Array.isArray(children) && children.length > 0) {
10142
+ children.forEach(child => {
10143
+ processItem(child, depth + 1);
10144
+ });
10145
+ }
10146
+ };
10147
+ // Process all root items (items that were added directly to result)
10148
+ result.forEach(item => {
10149
+ processItem(item);
10150
+ });
10151
+ return flattenedResult;
10148
10152
  }
10149
10153
  /**
10150
10154
  * Toggle expand/collapse state of a tree item with unlimited nesting support
@@ -11663,12 +11667,12 @@ class CideEleDataGridComponent {
11663
11667
  // If tree is enabled, we need to flatten tree first for grouping, then preserve structure
11664
11668
  const treeConfig = this.mergedConfig().tree;
11665
11669
  if (treeConfig?.enabled) {
11666
- // Flatten tree structure for grouping, but preserve parent-child relationships
11670
+ // Flatten tree structure completely for grouping (all items including children)
11667
11671
  data = this.flattenTreeForGrouping(data);
11668
11672
  }
11669
11673
  // Apply grouping
11670
11674
  data = this.getGroupedData(data, grouped);
11671
- // If tree is enabled, restore tree structure within groups
11675
+ // If tree is enabled, restore tree structure within groups and show children when expanded
11672
11676
  if (treeConfig?.enabled) {
11673
11677
  data = this.restoreTreeStructureInGroups(data);
11674
11678
  }