- 渲染管线迁移至 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)
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { create } from 'zustand'
|
|
import type { FileNode } from '../types/file'
|
|
import { settingsRepository } from '../db/settingsRepository'
|
|
|
|
interface SidebarState {
|
|
isVisible: boolean
|
|
rootPath: string | null
|
|
tree: FileNode[]
|
|
expandedDirs: string[]
|
|
sidebarWidth: number
|
|
_loaded: boolean
|
|
|
|
setVisible: (visible: boolean) => void
|
|
setRootPath: (path: string | null) => void
|
|
setTree: (tree: FileNode[]) => void
|
|
toggleDir: (path: string) => void
|
|
expandDirs: (paths: string[]) => void
|
|
setSidebarWidth: (width: number) => void
|
|
}
|
|
|
|
export const useSidebarStore = create<SidebarState>(set => ({
|
|
isVisible: true,
|
|
rootPath: null,
|
|
tree: [],
|
|
expandedDirs: [],
|
|
sidebarWidth: 240,
|
|
_loaded: false,
|
|
|
|
setVisible: (visible: boolean) => {
|
|
set({ isVisible: visible })
|
|
settingsRepository.save({ sidebarCollapsed: !visible })
|
|
},
|
|
setRootPath: (path: string | null) => set({ rootPath: path }),
|
|
setTree: (tree: FileNode[]) => set({ tree }),
|
|
toggleDir: (path: string) =>
|
|
set(state => ({
|
|
expandedDirs: state.expandedDirs.includes(path)
|
|
? state.expandedDirs.filter(p => p !== path)
|
|
: [...state.expandedDirs, path],
|
|
})),
|
|
expandDirs: (paths: string[]) =>
|
|
set(state => {
|
|
const newDirs = paths.filter(p => !state.expandedDirs.includes(p))
|
|
return newDirs.length > 0 ? { expandedDirs: [...state.expandedDirs, ...newDirs] } : state
|
|
}),
|
|
setSidebarWidth: (width: number) => {
|
|
set({ sidebarWidth: width })
|
|
settingsRepository.save({ sidebarWidth: width })
|
|
},
|
|
}))
|