954 lines
29 KiB
TypeScript
954 lines
29 KiB
TypeScript
import * as plugins from '../wcctools.plugins.js';
|
|
import { DeesElement, property, html, customElement, type TemplateResult, state } from '@design.estate/dees-element';
|
|
import { WccDashboard, getSectionItems } from './wcc-dashboard.js';
|
|
import type { TTemplateFactory } from './wcctools.helpers.js';
|
|
import { getDemoCount, hasMultipleDemos } from './wcctools.helpers.js';
|
|
import type { IWccSection, TElementType } from '../wcctools.interfaces.js';
|
|
import { WccContextmenu } from './wcc-contextmenu.js';
|
|
|
|
@customElement('wcc-sidebar')
|
|
export class WccSidebar extends DeesElement {
|
|
@property({ attribute: false })
|
|
accessor selectedItem: DeesElement | TTemplateFactory;
|
|
|
|
@property({ attribute: false })
|
|
accessor selectedType: TElementType;
|
|
|
|
@property()
|
|
accessor dashboardRef: WccDashboard;
|
|
|
|
@property()
|
|
accessor isNative: boolean = false;
|
|
|
|
// Track which elements are expanded (for multi-demo elements)
|
|
@state()
|
|
accessor expandedElements: Set<string> = new Set();
|
|
|
|
// Track which sections are collapsed
|
|
@state()
|
|
accessor collapsedSections: Set<string> = new Set();
|
|
|
|
// Search query for filtering sidebar items
|
|
@property()
|
|
accessor searchQuery: string = '';
|
|
|
|
// Pinned items as Set of "sectionName::itemName"
|
|
@property({ attribute: false })
|
|
accessor pinnedItems: Set<string> = new Set();
|
|
|
|
// Sidebar width (resizable)
|
|
@property({ type: Number })
|
|
accessor sidebarWidth: number = 200;
|
|
|
|
// Track if currently resizing
|
|
@state()
|
|
accessor isResizing: boolean = false;
|
|
|
|
// Delayed hide for native mode transition
|
|
@state()
|
|
accessor isHidden: boolean = false;
|
|
|
|
// Track if menu is scrolled for header shadow
|
|
@state()
|
|
accessor isMenuScrolled: boolean = false;
|
|
|
|
private sectionsInitialized = false;
|
|
|
|
/**
|
|
* Returns the scrollable container element (.menu) for external scroll management
|
|
*/
|
|
public get scrollableContainer(): HTMLElement | null {
|
|
return this.shadowRoot?.querySelector('.menu') as HTMLElement | null;
|
|
}
|
|
|
|
public render(): TemplateResult {
|
|
return html`
|
|
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" rel="stylesheet" />
|
|
<style>
|
|
:host {
|
|
/* CSS Variables - Always dark theme to match wcc-properties */
|
|
--background: #0a0a0a;
|
|
--foreground: #e5e5e5;
|
|
--card: #0f0f0f;
|
|
--card-foreground: #f0f0f0;
|
|
--muted: #1a1a1a;
|
|
--muted-foreground: #666;
|
|
--accent: #222;
|
|
--accent-foreground: #fff;
|
|
--border: rgba(255, 255, 255, 0.06);
|
|
--input: #141414;
|
|
--primary: #3b82f6;
|
|
--primary-foreground: #fff;
|
|
--ring: #3b82f6;
|
|
--radius: 4px;
|
|
|
|
display: ${this.isHidden ? 'none' : 'flex'};
|
|
flex-direction: column;
|
|
border-right: 1px solid rgba(255, 255, 255, 0.08);
|
|
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
|
font-size: 14px;
|
|
box-sizing: border-box;
|
|
position: absolute;
|
|
left: 0px;
|
|
width: ${this.sidebarWidth}px;
|
|
top: 0px;
|
|
bottom: 0px;
|
|
overflow: hidden;
|
|
background: var(--background);
|
|
color: var(--foreground);
|
|
}
|
|
|
|
.sidebar-header {
|
|
flex-shrink: 0;
|
|
transition: box-shadow 0.2s ease, border-color 0.2s ease;
|
|
border-bottom: 1px solid transparent;
|
|
position: relative;
|
|
z-index: 1;
|
|
}
|
|
|
|
.sidebar-header.scrolled {
|
|
box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.4);
|
|
border-bottom-color: var(--border);
|
|
}
|
|
|
|
.menu {
|
|
flex: 1;
|
|
min-height: 0;
|
|
overflow-y: auto;
|
|
overflow-x: hidden;
|
|
padding: 0.5rem 0;
|
|
}
|
|
|
|
.section-header {
|
|
padding: 0.3rem 0.75rem;
|
|
font-size: 0.65rem;
|
|
font-weight: 500;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.08em;
|
|
color: #888;
|
|
margin: 0;
|
|
margin-top: 0.5rem;
|
|
background: rgba(59, 130, 246, 0.03);
|
|
border-bottom: 1px solid var(--border);
|
|
border-top: 1px solid var(--border);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
cursor: pointer;
|
|
user-select: none;
|
|
transition: all 0.15s ease;
|
|
}
|
|
|
|
.section-header:first-child {
|
|
margin-top: 0;
|
|
}
|
|
|
|
.section-header:hover {
|
|
background: rgba(59, 130, 246, 0.08);
|
|
}
|
|
|
|
.section-header .expand-icon {
|
|
font-size: 14px;
|
|
opacity: 0.5;
|
|
transition: transform 0.2s ease;
|
|
}
|
|
|
|
.section-header.collapsed .expand-icon {
|
|
transform: rotate(-90deg);
|
|
}
|
|
|
|
.section-header .section-icon {
|
|
font-size: 14px;
|
|
opacity: 0.6;
|
|
}
|
|
|
|
.section-content {
|
|
overflow: hidden;
|
|
}
|
|
|
|
.section-content.collapsed {
|
|
display: none;
|
|
}
|
|
|
|
.material-symbols-outlined {
|
|
font-family: 'Material Symbols Outlined';
|
|
font-weight: normal;
|
|
font-style: normal;
|
|
font-size: 16px;
|
|
display: inline-block;
|
|
line-height: 1;
|
|
text-transform: none;
|
|
letter-spacing: normal;
|
|
word-wrap: normal;
|
|
white-space: nowrap;
|
|
direction: ltr;
|
|
font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
|
|
opacity: 0.5;
|
|
}
|
|
|
|
.selectOption {
|
|
user-select: none;
|
|
position: relative;
|
|
margin: 0.125rem 0.5rem;
|
|
padding: 0.5rem 0.75rem;
|
|
transition: all 0.15s ease;
|
|
display: grid;
|
|
grid-template-columns: 20px 1fr;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
border-radius: var(--radius);
|
|
cursor: pointer;
|
|
font-size: 0.75rem;
|
|
color: #999;
|
|
background: transparent;
|
|
}
|
|
|
|
.selectOption.folder {
|
|
grid-template-columns: 16px 1fr;
|
|
}
|
|
|
|
.selectOption.folder .text {
|
|
margin-left: 4px;
|
|
}
|
|
|
|
.selectOption .expand-icon {
|
|
font-size: 14px;
|
|
opacity: 0.5;
|
|
transition: transform 0.2s ease;
|
|
}
|
|
|
|
.selectOption.expanded .expand-icon {
|
|
transform: rotate(90deg);
|
|
}
|
|
|
|
.selectOption:hover {
|
|
background: rgba(59, 130, 246, 0.05);
|
|
color: #bbb;
|
|
}
|
|
|
|
.selectOption:hover .material-symbols-outlined {
|
|
opacity: 0.7;
|
|
}
|
|
|
|
.selectOption.selected {
|
|
background: rgba(59, 130, 246, 0.15);
|
|
color: var(--primary);
|
|
}
|
|
|
|
.selectOption.selected .material-symbols-outlined {
|
|
opacity: 1;
|
|
font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
|
|
}
|
|
|
|
.selectOption.selected:hover {
|
|
background: rgba(59, 130, 246, 0.2);
|
|
color: var(--primary);
|
|
}
|
|
|
|
.selectOption .text {
|
|
display: block;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
font-weight: 400;
|
|
}
|
|
|
|
.demo-children {
|
|
margin-left: 1rem;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.demo-child {
|
|
user-select: none;
|
|
position: relative;
|
|
margin: 0.125rem 0.5rem;
|
|
padding: 0.35rem 0.75rem;
|
|
transition: all 0.15s ease;
|
|
display: grid;
|
|
grid-template-columns: 16px 1fr;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
border-radius: var(--radius);
|
|
cursor: pointer;
|
|
font-size: 0.7rem;
|
|
color: #777;
|
|
background: transparent;
|
|
}
|
|
|
|
.demo-child:hover {
|
|
background: rgba(59, 130, 246, 0.05);
|
|
color: #bbb;
|
|
}
|
|
|
|
.demo-child.selected {
|
|
background: rgba(59, 130, 246, 0.15);
|
|
color: var(--primary);
|
|
}
|
|
|
|
.demo-child .material-symbols-outlined {
|
|
font-size: 14px;
|
|
}
|
|
|
|
::-webkit-scrollbar {
|
|
width: 8px;
|
|
}
|
|
|
|
::-webkit-scrollbar-track {
|
|
background: transparent;
|
|
}
|
|
|
|
::-webkit-scrollbar-thumb {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
border-radius: 4px;
|
|
}
|
|
|
|
::-webkit-scrollbar-thumb:hover {
|
|
background: rgba(255, 255, 255, 0.2);
|
|
}
|
|
|
|
.search-container {
|
|
padding: 0.5rem;
|
|
border-bottom: 1px solid var(--border);
|
|
position: relative;
|
|
}
|
|
|
|
.search-input {
|
|
width: 100%;
|
|
box-sizing: border-box;
|
|
background: var(--input);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
padding: 0.5rem 1.75rem 0.5rem 0.75rem;
|
|
color: var(--foreground);
|
|
font-size: 0.75rem;
|
|
font-family: inherit;
|
|
outline: none;
|
|
transition: border-color 0.15s ease;
|
|
}
|
|
|
|
.search-input:focus {
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.search-input::placeholder {
|
|
color: var(--muted-foreground);
|
|
}
|
|
|
|
.search-clear {
|
|
position: absolute;
|
|
right: 0.75rem;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
background: none;
|
|
border: none;
|
|
padding: 0.25rem;
|
|
cursor: pointer;
|
|
color: var(--muted-foreground);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
border-radius: 2px;
|
|
transition: color 0.15s ease, background 0.15s ease;
|
|
}
|
|
|
|
.search-clear:hover {
|
|
color: var(--foreground);
|
|
background: rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.search-clear .material-symbols-outlined {
|
|
font-size: 14px;
|
|
opacity: 1;
|
|
}
|
|
|
|
.highlight {
|
|
background: rgba(59, 130, 246, 0.3);
|
|
border-radius: 2px;
|
|
}
|
|
|
|
/* Pinned item highlight in original section */
|
|
.selectOption.pinned {
|
|
background: rgba(245, 158, 11, 0.08);
|
|
}
|
|
|
|
.selectOption.pinned:hover {
|
|
background: rgba(245, 158, 11, 0.12);
|
|
}
|
|
|
|
.selectOption.pinned.selected {
|
|
background: rgba(245, 158, 11, 0.18);
|
|
}
|
|
|
|
/* Pinned section styling */
|
|
.section-header.pinned-section {
|
|
background: rgba(245, 158, 11, 0.08);
|
|
color: #f59e0b;
|
|
}
|
|
|
|
.section-header.pinned-section:hover {
|
|
background: rgba(245, 158, 11, 0.12);
|
|
}
|
|
|
|
.section-header.pinned-section .section-icon {
|
|
opacity: 0.8;
|
|
}
|
|
|
|
/* Section tag pill for pinned items */
|
|
.section-tag {
|
|
font-size: 0.5rem;
|
|
color: #888;
|
|
margin-left: auto;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.02em;
|
|
background: rgba(255, 255, 255, 0.06);
|
|
padding: 0.15rem 0.4rem;
|
|
border-radius: 9999px;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
/* Group container */
|
|
.item-group {
|
|
margin: 0.375rem 0.375rem;
|
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
border-radius: 6px;
|
|
padding: 0.25rem 0;
|
|
background: rgba(255, 255, 255, 0.01);
|
|
}
|
|
|
|
.item-group-legend {
|
|
font-size: 0.55rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
color: #555;
|
|
padding: 0.125rem 0.625rem 0.25rem;
|
|
display: block;
|
|
}
|
|
|
|
.item-group .selectOption {
|
|
margin-left: 0.25rem;
|
|
margin-right: 0.25rem;
|
|
}
|
|
|
|
/* Resize handle */
|
|
.resize-handle {
|
|
position: absolute;
|
|
top: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
width: 4px;
|
|
cursor: col-resize;
|
|
background: transparent;
|
|
transition: background 0.15s ease;
|
|
z-index: 10;
|
|
}
|
|
|
|
.resize-handle:hover {
|
|
background: rgba(59, 130, 246, 0.3);
|
|
}
|
|
|
|
.resize-handle.active {
|
|
background: var(--primary);
|
|
}
|
|
</style>
|
|
<div class="sidebar-header ${this.isMenuScrolled ? 'scrolled' : ''}">
|
|
<div class="search-container">
|
|
<input
|
|
type="text"
|
|
class="search-input"
|
|
placeholder="Search..."
|
|
.value=${this.searchQuery}
|
|
@input=${this.handleSearchInput}
|
|
/>
|
|
${this.searchQuery ? html`
|
|
<button class="search-clear" @click=${this.clearSearch}>
|
|
<i class="material-symbols-outlined">close</i>
|
|
</button>
|
|
` : null}
|
|
</div>
|
|
${this.renderPinnedSection()}
|
|
</div>
|
|
<div class="menu" @scroll=${this.handleMenuScroll}>
|
|
${this.renderSections()}
|
|
</div>
|
|
<div
|
|
class="resize-handle ${this.isResizing ? 'active' : ''}"
|
|
@mousedown=${this.startResize}
|
|
></div>
|
|
`;
|
|
}
|
|
|
|
/**
|
|
* Initialize collapsed sections from section config
|
|
*/
|
|
private initCollapsedSections() {
|
|
if (this.sectionsInitialized || !this.dashboardRef?.sections) return;
|
|
|
|
const collapsed = new Set<string>();
|
|
for (const section of this.dashboardRef.sections) {
|
|
if (section.collapsed) {
|
|
collapsed.add(section.name);
|
|
}
|
|
}
|
|
this.collapsedSections = collapsed;
|
|
this.sectionsInitialized = true;
|
|
}
|
|
|
|
// ============ Pinning helpers ============
|
|
|
|
private getPinKey(sectionName: string, itemName: string): string {
|
|
return `${sectionName}::${itemName}`;
|
|
}
|
|
|
|
private isPinned(sectionName: string, itemName: string): boolean {
|
|
return this.pinnedItems.has(this.getPinKey(sectionName, itemName));
|
|
}
|
|
|
|
private togglePin(sectionName: string, itemName: string) {
|
|
const key = this.getPinKey(sectionName, itemName);
|
|
const newPinned = new Set(this.pinnedItems);
|
|
if (newPinned.has(key)) {
|
|
newPinned.delete(key);
|
|
} else {
|
|
newPinned.add(key);
|
|
}
|
|
this.pinnedItems = newPinned;
|
|
this.dispatchEvent(new CustomEvent('pinnedChanged', { detail: newPinned }));
|
|
}
|
|
|
|
private showContextMenu(e: MouseEvent, sectionName: string, itemName: string) {
|
|
const isPinned = this.isPinned(sectionName, itemName);
|
|
WccContextmenu.show(e, [
|
|
{
|
|
name: isPinned ? 'Unpin' : 'Pin',
|
|
iconName: isPinned ? 'push_pin' : 'push_pin',
|
|
action: () => this.togglePin(sectionName, itemName),
|
|
},
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Render the PINNED section (only if there are pinned items)
|
|
*/
|
|
private renderPinnedSection() {
|
|
if (!this.dashboardRef?.sections || this.pinnedItems.size === 0) {
|
|
return null;
|
|
}
|
|
|
|
const isCollapsed = this.collapsedSections.has('__pinned__');
|
|
|
|
// Collect pinned items with their original section info
|
|
// Pinned items are NOT filtered by search - they always remain visible
|
|
const pinnedEntries: Array<{ sectionName: string; itemName: string; item: any; section: IWccSection }> = [];
|
|
|
|
for (const key of this.pinnedItems) {
|
|
const [sectionName, itemName] = key.split('::');
|
|
const section = this.dashboardRef.sections.find(s => s.name === sectionName);
|
|
if (section) {
|
|
const entries = getSectionItems(section);
|
|
const found = entries.find(([name]) => name === itemName);
|
|
if (found) {
|
|
pinnedEntries.push({ sectionName, itemName, item: found[1], section });
|
|
}
|
|
}
|
|
}
|
|
|
|
if (pinnedEntries.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
return html`
|
|
<div
|
|
class="section-header pinned-section ${isCollapsed ? 'collapsed' : ''}"
|
|
@click=${() => this.toggleSectionCollapsed('__pinned__')}
|
|
>
|
|
<i class="material-symbols-outlined expand-icon">expand_more</i>
|
|
<i class="material-symbols-outlined section-icon">push_pin</i>
|
|
<span>Pinned</span>
|
|
</div>
|
|
<div class="section-content ${isCollapsed ? 'collapsed' : ''}">
|
|
${pinnedEntries.map(({ sectionName, itemName, item, section }) => {
|
|
const isSelected = this.selectedItem === item;
|
|
const type = section.type === 'elements' ? 'element' : 'page';
|
|
const icon = section.type === 'elements' ? 'featured_video' : 'insert_drive_file';
|
|
|
|
return html`
|
|
<div
|
|
class="selectOption ${isSelected ? 'selected' : ''}"
|
|
@click=${async () => {
|
|
await plugins.deesDomtools.DomTools.setupDomTools();
|
|
this.selectItem(type, itemName, item, 0, section);
|
|
}}
|
|
@contextmenu=${(e: MouseEvent) => this.showContextMenu(e, sectionName, itemName)}
|
|
>
|
|
<i class="material-symbols-outlined">${icon}</i>
|
|
<div class="text">${this.highlightMatch(itemName)}</div>
|
|
<span class="section-tag">${sectionName}</span>
|
|
</div>
|
|
`;
|
|
})}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
/**
|
|
* Render all sections
|
|
*/
|
|
private renderSections() {
|
|
if (!this.dashboardRef?.sections) {
|
|
return null;
|
|
}
|
|
|
|
this.initCollapsedSections();
|
|
|
|
return this.dashboardRef.sections.map((section) => {
|
|
// Check if section has any matching items
|
|
const entries = getSectionItems(section);
|
|
const filteredEntries = entries.filter(([name]) => this.matchesSearch(name));
|
|
|
|
// Hide section if no items match the search
|
|
if (filteredEntries.length === 0 && this.searchQuery) {
|
|
return null;
|
|
}
|
|
|
|
const isCollapsed = this.collapsedSections.has(section.name);
|
|
const sectionIcon = section.icon || (section.type === 'pages' ? 'insert_drive_file' : 'widgets');
|
|
|
|
return html`
|
|
<div
|
|
class="section-header ${isCollapsed ? 'collapsed' : ''}"
|
|
@click=${() => this.toggleSectionCollapsed(section.name)}
|
|
>
|
|
<i class="material-symbols-outlined expand-icon">expand_more</i>
|
|
${section.icon ? html`<i class="material-symbols-outlined section-icon">${section.icon}</i>` : null}
|
|
<span>${section.name}</span>
|
|
</div>
|
|
<div class="section-content ${isCollapsed ? 'collapsed' : ''}">
|
|
${this.renderSectionItems(section)}
|
|
</div>
|
|
`;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Render items for a section
|
|
*/
|
|
private renderSectionItems(section: IWccSection) {
|
|
const entries = getSectionItems(section);
|
|
// Filter entries by search query
|
|
const filteredEntries = entries.filter(([name]) => this.matchesSearch(name));
|
|
|
|
if (section.type === 'pages') {
|
|
return filteredEntries.map(([pageName, item]) => {
|
|
const isPinned = this.isPinned(section.name, pageName);
|
|
return html`
|
|
<div
|
|
class="selectOption ${this.selectedItem === item ? 'selected' : ''} ${isPinned ? 'pinned' : ''}"
|
|
@click=${async () => {
|
|
await plugins.deesDomtools.DomTools.setupDomTools();
|
|
this.selectItem('page', pageName, item, 0, section);
|
|
}}
|
|
@contextmenu=${(e: MouseEvent) => this.showContextMenu(e, section.name, pageName)}
|
|
>
|
|
<i class="material-symbols-outlined">insert_drive_file</i>
|
|
<div class="text">${this.highlightMatch(pageName)}</div>
|
|
</div>
|
|
`;
|
|
});
|
|
} else {
|
|
// type === 'elements' - group by demoGroup
|
|
const groupedItems = new Map<string | null, Array<[string, any]>>();
|
|
|
|
for (const entry of filteredEntries) {
|
|
const [, item] = entry;
|
|
const group = (item as any).demoGroup || null;
|
|
if (!groupedItems.has(group)) {
|
|
groupedItems.set(group, []);
|
|
}
|
|
groupedItems.get(group)!.push(entry);
|
|
}
|
|
|
|
// 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 };
|
|
|
|
const renderItems: RenderItem[] = [];
|
|
|
|
// Add ungrouped items
|
|
const ungrouped = groupedItems.get(null) || [];
|
|
for (const entry of ungrouped) {
|
|
renderItems.push({ type: 'element', entry, sortKey: entry[0].toLowerCase() });
|
|
}
|
|
|
|
// Add groups (sorted by their first element's name)
|
|
for (const [groupName, items] of groupedItems) {
|
|
if (groupName === null) continue;
|
|
const firstElementName = items[0]?.[0] || '';
|
|
renderItems.push({ type: 'group', groupName, items, sortKey: firstElementName.toLowerCase() });
|
|
}
|
|
|
|
// 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>
|
|
`;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Render a single element item (used by renderSectionItems)
|
|
*/
|
|
private renderElementItem(entry: [string, any], section: IWccSection): TemplateResult {
|
|
const [elementName, item] = entry;
|
|
const anonItem = item as any;
|
|
const demoCount = anonItem.demo ? getDemoCount(anonItem.demo) : 0;
|
|
const isMultiDemo = anonItem.demo && hasMultipleDemos(anonItem.demo);
|
|
const isExpanded = this.expandedElements.has(elementName);
|
|
const isSelected = this.selectedItem === item;
|
|
const isPinned = this.isPinned(section.name, elementName);
|
|
|
|
if (isMultiDemo) {
|
|
// Multi-demo element - render as expandable folder
|
|
return html`
|
|
<div
|
|
class="selectOption folder ${isExpanded ? 'expanded' : ''} ${isSelected ? 'selected' : ''} ${isPinned ? 'pinned' : ''}"
|
|
@click=${() => this.toggleExpanded(elementName)}
|
|
@contextmenu=${(e: MouseEvent) => this.showContextMenu(e, section.name, elementName)}
|
|
>
|
|
<i class="material-symbols-outlined expand-icon">chevron_right</i>
|
|
<div class="text">${this.highlightMatch(elementName)}</div>
|
|
</div>
|
|
${isExpanded ? html`
|
|
<div class="demo-children">
|
|
${Array.from({ length: demoCount }, (_, i) => {
|
|
const demoIndex = i;
|
|
const isThisDemoSelected = isSelected && this.dashboardRef.selectedDemoIndex === demoIndex;
|
|
return html`
|
|
<div
|
|
class="demo-child ${isThisDemoSelected ? 'selected' : ''}"
|
|
@click=${async () => {
|
|
await plugins.deesDomtools.DomTools.setupDomTools();
|
|
this.selectItem('element', elementName, item, demoIndex, section);
|
|
}}
|
|
>
|
|
<i class="material-symbols-outlined">play_circle</i>
|
|
<div class="text">demo${demoIndex + 1}</div>
|
|
</div>
|
|
`;
|
|
})}
|
|
</div>
|
|
` : null}
|
|
`;
|
|
} else {
|
|
// Single demo element
|
|
return html`
|
|
<div
|
|
class="selectOption ${isSelected ? 'selected' : ''} ${isPinned ? 'pinned' : ''}"
|
|
@click=${async () => {
|
|
await plugins.deesDomtools.DomTools.setupDomTools();
|
|
this.selectItem('element', elementName, item, 0, section);
|
|
}}
|
|
@contextmenu=${(e: MouseEvent) => this.showContextMenu(e, section.name, elementName)}
|
|
>
|
|
<i class="material-symbols-outlined">featured_video</i>
|
|
<div class="text">${this.highlightMatch(elementName)}</div>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
private toggleSectionCollapsed(sectionName: string) {
|
|
const newSet = new Set(this.collapsedSections);
|
|
if (newSet.has(sectionName)) {
|
|
newSet.delete(sectionName);
|
|
} else {
|
|
newSet.add(sectionName);
|
|
}
|
|
this.collapsedSections = newSet;
|
|
}
|
|
|
|
private toggleExpanded(elementName: string) {
|
|
const newSet = new Set(this.expandedElements);
|
|
if (newSet.has(elementName)) {
|
|
newSet.delete(elementName);
|
|
} else {
|
|
newSet.add(elementName);
|
|
}
|
|
this.expandedElements = newSet;
|
|
}
|
|
|
|
private handleSearchInput(e: Event) {
|
|
const input = e.target as HTMLInputElement;
|
|
this.searchQuery = input.value;
|
|
this.dispatchEvent(new CustomEvent('searchChanged', { detail: this.searchQuery }));
|
|
}
|
|
|
|
private clearSearch() {
|
|
this.searchQuery = '';
|
|
this.dispatchEvent(new CustomEvent('searchChanged', { detail: this.searchQuery }));
|
|
}
|
|
|
|
private handleMenuScroll(e: Event) {
|
|
const target = e.target as HTMLElement;
|
|
this.isMenuScrolled = target.scrollTop > 0;
|
|
}
|
|
|
|
private matchesSearch(name: string): boolean {
|
|
if (!this.searchQuery) return true;
|
|
return name.toLowerCase().includes(this.searchQuery.toLowerCase());
|
|
}
|
|
|
|
private highlightMatch(text: string): TemplateResult {
|
|
if (!this.searchQuery) return html`${text}`;
|
|
const lowerText = text.toLowerCase();
|
|
const lowerQuery = this.searchQuery.toLowerCase();
|
|
const index = lowerText.indexOf(lowerQuery);
|
|
if (index === -1) return html`${text}`;
|
|
const before = text.slice(0, index);
|
|
const match = text.slice(index, index + this.searchQuery.length);
|
|
const after = text.slice(index + this.searchQuery.length);
|
|
return html`${before}<span class="highlight">${match}</span>${after}`;
|
|
}
|
|
|
|
protected updated(changedProperties: Map<string, unknown>) {
|
|
super.updated(changedProperties);
|
|
|
|
// Handle delayed hide for native mode transition
|
|
if (changedProperties.has('isNative')) {
|
|
if (this.isNative) {
|
|
// Delay hiding until frame animation completes
|
|
setTimeout(() => {
|
|
this.isHidden = true;
|
|
}, 300);
|
|
} else {
|
|
// Show immediately when exiting native mode
|
|
this.isHidden = false;
|
|
}
|
|
}
|
|
|
|
// Auto-expand folder when a multi-demo element is selected
|
|
if (changedProperties.has('selectedItem') && this.selectedItem && this.dashboardRef?.sections) {
|
|
// Find the element in any section
|
|
for (const section of this.dashboardRef.sections) {
|
|
if (section.type !== 'elements') continue;
|
|
|
|
const entries = getSectionItems(section);
|
|
const found = entries.find(([_, item]) => item === this.selectedItem);
|
|
if (found) {
|
|
const [elementName, item] = found;
|
|
const anonItem = item as any;
|
|
if (anonItem.demo && hasMultipleDemos(anonItem.demo)) {
|
|
if (!this.expandedElements.has(elementName)) {
|
|
const newSet = new Set(this.expandedElements);
|
|
newSet.add(elementName);
|
|
this.expandedElements = newSet;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// ============ Resize functionality ============
|
|
|
|
private startResize = (e: MouseEvent) => {
|
|
e.preventDefault();
|
|
this.isResizing = true;
|
|
const startX = e.clientX;
|
|
const startWidth = this.sidebarWidth;
|
|
|
|
// Cache references once at start
|
|
const frame = this.dashboardRef?.shadowRoot?.querySelector('wcc-frame') as any;
|
|
const properties = this.dashboardRef?.shadowRoot?.querySelector('wcc-properties') as any;
|
|
|
|
// Disable frame transition during resize
|
|
if (frame) {
|
|
frame.isResizing = true;
|
|
}
|
|
|
|
const onMouseMove = (e: MouseEvent) => {
|
|
const newWidth = Math.min(400, Math.max(150, startWidth + (e.clientX - startX)));
|
|
this.sidebarWidth = newWidth;
|
|
// Update frame and properties directly
|
|
if (frame) {
|
|
frame.sidebarWidth = newWidth;
|
|
}
|
|
if (properties) {
|
|
properties.sidebarWidth = newWidth;
|
|
}
|
|
};
|
|
|
|
const onMouseUp = () => {
|
|
this.isResizing = false;
|
|
document.removeEventListener('mousemove', onMouseMove);
|
|
document.removeEventListener('mouseup', onMouseUp);
|
|
// Re-enable frame transition
|
|
if (frame) {
|
|
frame.isResizing = false;
|
|
}
|
|
// Dispatch event on release for URL persistence
|
|
this.dispatchEvent(new CustomEvent('widthChanged', { detail: this.sidebarWidth }));
|
|
};
|
|
|
|
document.addEventListener('mousemove', onMouseMove);
|
|
document.addEventListener('mouseup', onMouseUp);
|
|
};
|
|
|
|
public selectItem(
|
|
typeArg: TElementType,
|
|
itemNameArg: string,
|
|
itemArg: TTemplateFactory | DeesElement,
|
|
demoIndex: number = 0,
|
|
section?: IWccSection
|
|
) {
|
|
console.log('selected item');
|
|
console.log(itemNameArg);
|
|
console.log(itemArg);
|
|
console.log('demo index:', demoIndex);
|
|
console.log('section:', section?.name);
|
|
|
|
this.selectedItem = itemArg;
|
|
this.selectedType = typeArg;
|
|
this.dashboardRef.selectedDemoIndex = demoIndex;
|
|
|
|
// Set the selected section on dashboard
|
|
if (section) {
|
|
this.dashboardRef.selectedSection = section;
|
|
}
|
|
|
|
this.dispatchEvent(
|
|
new CustomEvent('selectedType', {
|
|
detail: typeArg
|
|
})
|
|
);
|
|
this.dispatchEvent(
|
|
new CustomEvent('selectedItemName', {
|
|
detail: itemNameArg
|
|
})
|
|
);
|
|
this.dispatchEvent(
|
|
new CustomEvent('selectedItem', {
|
|
detail: itemArg
|
|
})
|
|
);
|
|
|
|
this.dashboardRef.buildUrl();
|
|
|
|
// Force re-render to update demo child selection indicator
|
|
this.requestUpdate();
|
|
}
|
|
}
|