Files
tolaria/src/utils/vaultConfigStore.ts
lucaronin 07a6ef0970 feat: persist editor mode (raw/preview) across note switches
Editor mode is now stored as a global preference in VaultConfig instead of
being tracked per-tab. Toggling raw mode persists across tab switches and
app restarts via the editor_mode field in config/ui.config.md.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 11:41:35 +01:00

44 lines
1.0 KiB
TypeScript

import type { VaultConfig } from '../types'
type SaveFn = (config: VaultConfig) => void
type Listener = () => void
const DEFAULT_CONFIG: VaultConfig = {
zoom: null, view_mode: null, editor_mode: null,
tag_colors: null, status_colors: null, property_display_modes: null,
}
let config: VaultConfig = DEFAULT_CONFIG
let saveFn: SaveFn | null = null
const listeners: Set<Listener> = new Set()
export function getVaultConfig(): VaultConfig {
return config
}
export function bindVaultConfigStore(initial: VaultConfig, save: SaveFn): void {
config = initial
saveFn = save
notify()
}
export function resetVaultConfigStore(): void {
config = DEFAULT_CONFIG
saveFn = null
}
export function updateVaultConfigField<K extends keyof VaultConfig>(key: K, value: VaultConfig[K]): void {
config = { ...config, [key]: value }
saveFn?.(config)
notify()
}
export function subscribeVaultConfig(listener: Listener): () => void {
listeners.add(listener)
return () => { listeners.delete(listener) }
}
function notify(): void {
for (const fn of listeners) fn()
}