fix(wcc-sidebar): sort sidebar items alphabetically and unify grouped and ungrouped items for consistent ordering

This commit is contained in:
2026-01-04 16:51:52 +00:00
parent fe62278d74
commit e625fe9ba6
3 changed files with 37 additions and 13 deletions

View File

@@ -1,5 +1,13 @@
# Changelog
## 2026-01-04 - 3.6.1 - fix(wcc-sidebar)
sort sidebar items alphabetically and unify grouped and ungrouped items for consistent ordering
- Unifies ungrouped elements and groups into a single render list using a RenderItem type with a sortKey.
- Sorts all top-level items alphabetically by element name (case-insensitive via toLowerCase) so sidebar order is deterministic.
- Groups are ordered by the first element's name; individual items inside a group preserve their original order.
- Replaces previous separate rendering paths with a single sorted render pass that returns TemplateResult array.
## 2026-01-04 - 3.6.0 - feat(sidebar)
restructure sidebar layout, add search clear button, and improve scrolling behavior

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@design.estate/dees-wcctools',
version: '3.6.0',
version: '3.6.1',
description: 'A set of web component tools for creating element catalogues, enabling the structured development and documentation of custom elements and pages.'
}

View File

@@ -647,27 +647,43 @@ export class WccSidebar extends DeesElement {
groupedItems.get(group)!.push(entry);
}
const result: TemplateResult[] = [];
// Build a unified list of render items (ungrouped elements and groups)
// Each item has a sortKey (element name or first element name of group)
type RenderItem =
| { type: 'element'; entry: [string, any]; sortKey: string }
| { type: 'group'; groupName: string; items: Array<[string, any]>; sortKey: string };
// Render ungrouped items first
const renderItems: RenderItem[] = [];
// Add ungrouped items
const ungrouped = groupedItems.get(null) || [];
for (const entry of ungrouped) {
result.push(this.renderElementItem(entry, section));
renderItems.push({ type: 'element', entry, sortKey: entry[0].toLowerCase() });
}
// Render grouped items
// Add groups (sorted by their first element's name)
for (const [groupName, items] of groupedItems) {
if (groupName === null) continue;
result.push(html`
<div class="item-group">
<span class="item-group-legend">${groupName}</span>
${items.map((entry) => this.renderElementItem(entry, section))}
</div>
`);
const firstElementName = items[0]?.[0] || '';
renderItems.push({ type: 'group', groupName, items, sortKey: firstElementName.toLowerCase() });
}
return result;
// Sort all items alphabetically by sortKey
renderItems.sort((a, b) => a.sortKey.localeCompare(b.sortKey));
// Render in sorted order
return renderItems.map((item) => {
if (item.type === 'element') {
return this.renderElementItem(item.entry, section);
} else {
return html`
<div class="item-group">
<span class="item-group-legend">${item.groupName}</span>
${item.items.map((entry) => this.renderElementItem(entry, section))}
</div>
`;
}
});
}
}