import React from 'react' import { File, Folder, ChevronRight } from '../Icons' import type { FileNode } from '../../types/file' interface FileTreeProps { nodes: FileNode[] depth: number expandedDirs: string[] toggleDir: (path: string) => void activeFilePath: string | null onFileClick: (path: string) => void } /** AR-02: 从 Sidebar.tsx 提取的递归文件树组件 */ export const FileTree = React.memo(function FileTree({ nodes, depth, expandedDirs, toggleDir, activeFilePath, onFileClick, }: FileTreeProps) { return ( <> {nodes.map((node: FileNode) => { const isExpanded = node.type === 'dir' && expandedDirs.includes(node.path) const isActive = node.type === 'file' && node.path === activeFilePath return (
{ if (node.type === 'dir') { toggleDir(node.path) } else { onFileClick(node.path) } }} onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault() if (node.type === 'dir') { toggleDir(node.path) } else { onFileClick(node.path) } } }} > {node.type === 'dir' ? ( <> ) : ( <> )} {node.name}
{isExpanded && node.children && (
)}
) })} ) }) FileTree.displayName = 'FileTree'