import { html, nothing, type TemplateResult } from 'lit'; import type { NuiTreeViewState, TreeNode } from './types.js'; export type { NuiTreeViewState } from './types.js'; export interface NuiTreeHandlers { onToggle: (node: TreeNode) => void; onNodeClick: (node: TreeNode) => void; } function renderNode(node: TreeNode, handlers: NuiTreeHandlers): TemplateResult { const hasChildren = node.children && node.children.length > 0; const isExpanded = !!node.expanded; return html`
handlers.onNodeClick(node)} > ${ hasChildren ? html`` : html`` } ${ node.icon ? html`` : nothing } ${ node.type === 'url' ? html` { // If it's a URL link, let it navigate, but still trigger node click handlers.onNodeClick(node); }} >${node.label || ''}` : html`${node.label || ''}` }
${ hasChildren && isExpanded ? html` ` : nothing }
`; } export function renderTree( state: NuiTreeViewState, handlers: NuiTreeHandlers, ): TemplateResult { const nodes = state.value || []; return html`
`; }