"use client"; import { useState, type ComponentType } from "react"; import { BookOpenCheck, Focus, ListOrdered, ListTree, Maximize2, ShieldCheck, Type, MessageSquare } from "lucide-react"; import { cn } from "@/lib/utils"; import type { BooleanPageOptionKey, DocumentStats, PageFont, PageLayoutDensity, PageOptionsState } from "@/types/page-options"; import { DocumentTaskPanel } from "@/components/document-task-panel"; import { Button } from "@/components/ui/button"; import { useAppPreferencesStore, type ThemeMode } from "@/store/app-preferences"; type TabId = "page" | "custom" | "global"; const TABS: Array<{ id: TabId; label: string }> = [ { id: "page", label: "页面选项" }, { id: "custom", label: "自定义页面" }, { id: "global", label: "全局选项" }, ]; const OPTION_META: Record< BooleanPageOptionKey, { label: string; description: string; icon: ComponentType<{ className?: string }> } > = { wideLayout: { label: "自适应宽度", description: "让编辑区域根据屏幕自动铺满", icon: Maximize2, }, smallText: { label: "小字体", description: "使用更紧凑的字号排版", icon: Type, }, showHeadingNumbers: { label: "标题编号", description: "自动为标题添加编号", icon: ListOrdered, }, showToc: { label: "显示目录", description: "在右侧展示目录导航", icon: ListTree, }, protectEditing: { label: "编辑保护", description: "保护内容避免误触修改", icon: ShieldCheck, }, showWordCount: { label: "字数提示", description: "实时展示字数和块统计", icon: BookOpenCheck, }, collapseBacklinks: { label: "折叠反向引用", description: "默认折叠页面底部的反向引用列表", icon: Focus, }, hideChildPages: { label: "隐藏子页面", description: "隐藏通过 /ym 创建的子页面块(不会删除内容)", icon: Focus, }, showBlockRefCount: { label: "显示块引用数字", description: "显示块被引用次数(当前为占位,后续补齐)", icon: Focus, }, }; const PAGE_OPTIONS: BooleanPageOptionKey[] = [ "wideLayout", "smallText", "showHeadingNumbers", "showToc", "protectEditing", "showWordCount", ]; const CUSTOM_PAGE_OPTIONS: BooleanPageOptionKey[] = ["collapseBacklinks", "hideChildPages", "showBlockRefCount"]; interface PageOptionsSidebarProps { documentId: string; options: PageOptionsState; stats?: DocumentStats; onToggle: (key: BooleanPageOptionKey) => void; onSetPageFont?: (font: PageFont) => void; onSetLayoutDensity?: (density: PageLayoutDensity) => void; onSetEmbedDefaultToCursor?: () => void; onClearEmbedDefault?: () => void; onExport: () => void; onOpenHistory: () => void; onOpenComments?: () => void; onUndo?: () => void; onRedo?: () => void; onDeletePage?: () => void; onOpenMoveEmbedPicker?: () => void; onCopyPageLink?: (includeTitle: boolean) => void; onCopyPageReference?: (mode: "inline" | "embed") => void; onAddToTemplates?: () => void; } export function PageOptionsSidebar({ documentId, options, stats, onToggle, onSetPageFont, onSetLayoutDensity, onSetEmbedDefaultToCursor, onClearEmbedDefault, onExport, onOpenHistory, onOpenComments, onUndo, onRedo, onDeletePage, onOpenMoveEmbedPicker, onCopyPageLink, onCopyPageReference, onAddToTemplates, }: PageOptionsSidebarProps) { const [activeTab, setActiveTab] = useState("page"); const theme = useAppPreferencesStore((s) => s.theme); const showStructure = useAppPreferencesStore((s) => s.showStructure); const spellCheck = useAppPreferencesStore((s) => s.spellCheck); const flightMode = useAppPreferencesStore((s) => s.flightMode); const setTheme = useAppPreferencesStore((s) => s.setTheme); const setShowStructure = useAppPreferencesStore((s) => s.setShowStructure); const setSpellCheck = useAppPreferencesStore((s) => s.setSpellCheck); const setFlightMode = useAppPreferencesStore((s) => s.setFlightMode); return ( ); } function OptionToggleGroup({ title, optionKeys, options, onToggle, }: { title: string; optionKeys: BooleanPageOptionKey[]; options: PageOptionsState; onToggle: (key: BooleanPageOptionKey) => void; }) { return (
{title}
{optionKeys.map((key) => ( ))}
); } function OptionToggle({ optionKey, options, onToggle, }: { optionKey: BooleanPageOptionKey; options: PageOptionsState; onToggle: (key: BooleanPageOptionKey) => void; }) { const meta = OPTION_META[optionKey]; const Icon = meta.icon; const active = options[optionKey]; return ( ); } function StatsCell({ label, value }: { label: string; value: number }) { return (
{label}
{value}
); } function PreferenceRow({ title, description, enabled, onToggle, }: { title: string; description: string; enabled: boolean; onToggle: () => void; }) { return (
{title}
{description}
); }