import { Bold, Check, CheckSquare, Code, Eye, FileCode, Heading1, Heading2, Heading3, Heading4, Heading, Image as ImageIcon, Italic, Link as LinkIcon, List, ListOrdered, Minus, PencilLine, Quote, Redo2, Search, Sigma, SquareCode, Strikethrough, Table as TableIcon, Type, Underline, Undo2, } from "lucide-react"; import React, { useMemo, useState } from "react"; import { type MarkdownActionType } from "../../domain/notes"; import { useAvailableFonts } from "../../application/state/fontStore"; import type { ActiveTextFormats, NoteEditorMode } from "./InlineMarkdownEditor"; import { EMPTY_ACTIVE_FORMATS } from "./InlineMarkdownEditor"; import { Dropdown, DropdownContent, DropdownTrigger } from "../ui/dropdown"; import { cn } from "../../lib/utils"; export interface NoteToolbarProps { editorMode: NoteEditorMode; onChangeMode: (mode: NoteEditorMode) => void; onAction?: (action: MarkdownActionType) => void; onOpenHostPicker?: () => void; className?: string; noteFontFamily?: string; onChangeNoteFontFamily?: (font: string) => void; noteFontSize?: number; onChangeNoteFontSize?: (size: number) => void; /** Active text-format toggles at the current selection (button highlight). */ activeFormats?: ActiveTextFormats; } const FONT_SIZES = [12, 13, 14, 15, 16, 18, 20]; export const NoteToolbar: React.FC = ({ editorMode, onChangeMode, onAction, className = "", noteFontFamily = "", onChangeNoteFontFamily, noteFontSize = 14, onChangeNoteFontSize, activeFormats = EMPTY_ACTIVE_FORMATS, }) => { const [fontSearch, setFontSearch] = useState(""); // The font tool only controls code block / inline code fonts, so it lists // system monospace fonts (fontStore) rather than the UI font set. const availableSystemFonts = useAvailableFonts(); const systemFontList = useMemo(() => { const defaultOption = { label: "默认等宽字体 (Default)", value: "" }; const list = availableSystemFonts.map((f) => ({ label: f.name, value: f.family, })); return [defaultOption, ...list]; }, [availableSystemFonts]); const filteredFonts = useMemo(() => { if (!fontSearch.trim()) return systemFontList; const query = fontSearch.trim().toLowerCase(); return systemFontList.filter( (f) => f.label.toLowerCase().includes(query) || f.value.toLowerCase().includes(query), ); }, [fontSearch, systemFontList]); const isEditing = editorMode === "edit" || editorMode === "live" || editorMode === "source"; // Highlight style for toggles that are active at the current selection. const formatButtonClass = (active: boolean) => cn( "p-1.5 rounded-md transition-colors", active ? "bg-primary/15 text-primary hover:bg-primary/20 hover:text-primary" : "hover:bg-muted text-muted-foreground hover:text-foreground", ); return (
{/* Left Area: View Mode Segmented Control */}
{/* Middle Area: Formatting Tools (Available in Live Preview & Source Mode) */} {isEditing && (
{/* Undo / Redo */}
{/* Code Font & Typography Settings Dropdown */}
等宽字体 共 {systemFontList.length} 款可用字体
{/* Search Bar */}
setFontSearch(e.target.value)} className="w-full pl-6 pr-2 py-1 rounded border border-border bg-background text-[11px] text-foreground outline-none focus:border-primary placeholder:text-muted-foreground/60" />
{/* Scrollable Font List */}
{filteredFonts.length === 0 ? (
未找到匹配的等宽字体
) : ( filteredFonts.map((f) => ( )) )}
正文字号
{FONT_SIZES.map((sz) => ( ))}
{/* Heading Dropdown (Using Portal Dropdown to avoid clipping) */} {/* Inline Styles */}
{/* Lists */}
{/* Blocks */}
)}
); };