"use client"; /** * TASK-0123 — the shared "AI writing actions" menu list (the four tools + * the translate language picker). Reused by every entry point so the labels, * order and testids are identical: * - the selection toolbar's "AI" dropdown (multi-block selection); * - the block context menu's "Writing tools" submenu (single block); * - the block hover toolbar (⋯) "Writing tools" submenu (single block). * * `onPick(action, language?)` fires when a non-translate action is chosen, or * when a language (or "Other…") is picked under Translate. The parent owns * opening the `WritingDialog`; this component is a pure menu list. * * Pinned testids (do not rename): `writing-action-*`, `writing-language-*`, * `writing-language-other`. */ import { useState } from "react"; import { Check, Languages, ListChecks, Sparkles, Wand2 } from "lucide-react"; import { cn } from "@/lib/utils"; import { WRITING_LANGUAGES, type WritingAction } from "@/lib/ai"; const ACTIONS: { action: WritingAction; label: string; icon: typeof Sparkles }[] = [ { action: "summarize", label: "Summarize", icon: ListChecks }, { action: "rewrite", label: "Rewrite", icon: Wand2 }, { action: "improve", label: "Improve writing", icon: Sparkles }, { action: "translate", label: "Translate…", icon: Languages } ]; export interface WritingActionsListProps { onPick: (action: WritingAction, language?: string) => void; } export function WritingActionsList({ onPick }: WritingActionsListProps) { const [langOpen, setLangOpen] = useState(false); const [otherOpen, setOtherOpen] = useState(false); const [otherDraft, setOtherDraft] = useState(""); const pick = (action: WritingAction, language?: string) => { setLangOpen(false); setOtherOpen(false); setOtherDraft(""); onPick(action, language); }; return ( <> {ACTIONS.map(({ action, label, icon: Icon }) => { const isTranslate = action === "translate"; return (
{isTranslate && langOpen ? (

Translate to

{WRITING_LANGUAGES.map((l) => ( ))} {otherOpen ? ( setOtherDraft(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter" && otherDraft.trim()) pick("translate", otherDraft.trim().slice(0, 64)); }} placeholder="Other language…" aria-label="Other language" maxLength={64} className="mx-1 my-1 block w-full rounded-md border border-primary bg-background px-2 py-1 text-xs outline-none" /> ) : ( )}
) : null}
); })} ); }