diff --git a/src/visualizer/ui/ComponentTreeView.js b/src/visualizer/ui/ComponentTreeView.js new file mode 100644 index 0000000..f214b1b --- /dev/null +++ b/src/visualizer/ui/ComponentTreeView.js @@ -0,0 +1,200 @@ +/** + * ComponentTreeView - File/Folder-style component hierarchy tree + * + * Displays Vue components in a file explorer-like tree structure: + * - 📁 Folder icon for components with children (expandable) + * - 📄 File icon for leaf components (no children) + * - Expand/collapse functionality with ▶/▼ indicators + * - Visual tree lines showing parent-child relationships + * - Color-coded component names based on performance (green/yellow/orange/red) + * - Badges showing render counts + * - Click to select component and open insights drawer + * + * This is used exclusively in the Split View's center column. + * The tree structure makes it easy to understand component relationships. + */ +export class ComponentTreeView { + constructor(state, options = {}) { + this.state = state + this.onSelect = options.onSelect || (() => {}) + this.container = null + this.treeRoot = null + this.nodeElements = new Map() // Maps node UIDs to DOM elements for quick lookup + this.selectedUid = null + } + + mount(container) { + this.container = container + this.treeRoot = document.createElement('div') + this.treeRoot.className = 'vri-file-tree' + this.container.innerHTML = '' + this.container.appendChild(this.treeRoot) + this.render() + } + + render() { + if (!this.treeRoot) return + + const roots = this.state.getRootNodes() + this.nodeElements.clear() + + if (!roots.length) { + this.treeRoot.innerHTML = ` +