Files
MarkLite/src/renderer/components/FileTree/FileTree.tsx
T
thzxx ee5f35177e release: v0.6.0 — 内置解析器迁移 / Toast 全面接入 / Sqlark 深度集成
- 渲染管线迁移至 MetonaEditor 内置解析器,移除 unified/rehype 全家桶(9 个依赖)
- 修复相对路径图片修复的目录前缀碰撞与路径解析 bug
- ConfirmDialog/useConfirm/LoadingSpinner/useDocStats 移除,改用 MeToast.confirm/loading/promise
- 新增状态栏(字数/行数/阅读时间/光标位置)、Zen 模式、数据备份导出导入
- Sqlark: 版本化迁移(addMigration/migrateTo)、subscribe 表变更、备份 exportAll/importTable
- 数据库损坏自愈:异常退出残留残缺 SSTable 导致打开失败时自动重建
- 大纲导航改用 scrollToLine 官方 API
- 修复 rollup 平台包互删(postinstall 自动补齐)+ 集成测试(fake-indexeddb)
2026-08-09 16:50:06 +08:00

96 lines
2.9 KiB
TypeScript

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 (
<React.Fragment key={node.path}>
<div
className={`tree-item ${isActive ? 'active' : ''}`}
style={{ paddingLeft: 8 + depth * 16 + 'px' }}
role="treeitem"
aria-expanded={node.type === 'dir' ? isExpanded : undefined}
aria-selected={isActive}
aria-label={node.name}
tabIndex={0}
onClick={() => {
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' ? (
<>
<span className={`tree-arrow ${isExpanded ? 'expanded' : ''}`} aria-hidden="true">
<ChevronRight size={10} />
</span>
<span className="tree-icon" aria-hidden="true">
<Folder size={14} />
</span>
</>
) : (
<>
<span style={{ width: '16px', flexShrink: 0 }} />
<span className="tree-icon" aria-hidden="true">
<File size={14} />
</span>
</>
)}
<span className="tree-name">{node.name}</span>
</div>
{isExpanded && node.children && (
<div role="group">
<FileTree
nodes={node.children}
depth={depth + 1}
expandedDirs={expandedDirs}
toggleDir={toggleDir}
activeFilePath={activeFilePath}
onFileClick={onFileClick}
/>
</div>
)}
</React.Fragment>
)
})}
</>
)
})
FileTree.displayName = 'FileTree'