import { useState } from 'react'; import { VisualElement } from '../../types/blocks'; import { ChevronRight, ChevronDown } from 'lucide-react'; interface ElementTreeProps { elements: VisualElement[]; selectedId: string | null; onSelect: (id: string) => void; onContextMenu?: (e: React.MouseEvent, id: string) => void; depth?: number; } function TreeItem({ element, selectedId, onSelect, onContextMenu, depth, }: { element: VisualElement; selectedId: string | null; onSelect: (id: string) => void; onContextMenu?: (e: React.MouseEvent, id: string) => void; depth: number; }) { const isSelected = selectedId === element.id; const hasChildren = element.children && element.children.length > 0; const [expanded, setExpanded] = useState(true); return (
onSelect(element.id)} onContextMenu={onContextMenu ? (e) => onContextMenu(e, element.id) : undefined} > {hasChildren ? ( ) : ( )} < {element.tagName} > {element.props?.id && #{element.props.id}} {element.props?.textContent && ( "{element.props.textContent}" )}
{hasChildren && expanded && (
{element.children!.map((child) => ( ))}
)}
); } export default function ElementTree(props: ElementTreeProps) { const { elements, selectedId, onSelect, onContextMenu, depth = 0 } = props; if (!elements || elements.length === 0) { return
No elements on the page
; } return (
{elements.map((element) => ( ))}
); }