- editor 自带底栏(wordCount: true)已显示字符数/词数/行数/阅读时间 - 删除自定义 StatusBar 组件、editorStore 的 stats/cursor 状态与事件绑定 - 保留 zenMode 同步(Toolbar 专注按钮消费);自动保存状态由 Toolbar 按钮显示
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { create } from 'zustand'
|
|
import type { ViewMode, ThemeMode } from '../types/settings'
|
|
import type { MarkdownEditor } from '@metona-team/metona-editor'
|
|
|
|
// Module-level getter for the MetonaEditor instance
|
|
// Used by OutlinePanel for heading navigation
|
|
let _getEditor: (() => MarkdownEditor | null) | null = null
|
|
|
|
export function setMetonaEditorGetter(fn: () => MarkdownEditor | null) {
|
|
_getEditor = fn
|
|
}
|
|
|
|
export function getMetonaEditor(): MarkdownEditor | null {
|
|
return _getEditor ? _getEditor() : null
|
|
}
|
|
|
|
const THEME_CYCLE: ThemeMode[] = ['light', 'dark', 'warm']
|
|
|
|
interface EditorState {
|
|
viewMode: ViewMode
|
|
themeMode: ThemeMode
|
|
// AR-03: 外部修改检测状态,替代 DOM CustomEvent
|
|
externallyModified: { filePath: string } | null
|
|
// UX-02: 全局加载状态
|
|
loadingStates: Record<string, boolean>
|
|
// v0.6.0: Zen 模式状态(Toolbar 消费)
|
|
zenMode: boolean
|
|
|
|
setViewMode: (mode: ViewMode) => void
|
|
setThemeMode: (mode: ThemeMode) => void
|
|
cycleTheme: () => ThemeMode
|
|
setExternallyModified: (info: { filePath: string } | null) => void
|
|
// UX-02: 加载状态管理
|
|
setLoading: (key: string, loading: boolean) => void
|
|
isLoading: (key: string) => boolean
|
|
setZenMode: (zen: boolean) => void
|
|
}
|
|
|
|
export const useEditorStore = create<EditorState>((set, get) => ({
|
|
viewMode: 'editor',
|
|
themeMode: 'light',
|
|
externallyModified: null,
|
|
loadingStates: {},
|
|
zenMode: false,
|
|
|
|
setViewMode: (mode: ViewMode) => set({ viewMode: mode }),
|
|
setThemeMode: (mode: ThemeMode) => set({ themeMode: mode }),
|
|
cycleTheme: () => {
|
|
const current = get().themeMode
|
|
const idx = THEME_CYCLE.indexOf(current)
|
|
const next = THEME_CYCLE[(idx + 1) % THEME_CYCLE.length]
|
|
set({ themeMode: next })
|
|
return next
|
|
},
|
|
setExternallyModified: (info: { filePath: string } | null) => set({ externallyModified: info }),
|
|
setLoading: (key: string, loading: boolean) =>
|
|
set(state => ({
|
|
loadingStates: { ...state.loadingStates, [key]: loading },
|
|
})),
|
|
isLoading: (key: string) => get().loadingStates[key] ?? false,
|
|
setZenMode: (zenMode: boolean) => set({ zenMode }),
|
|
}))
|