// frontend/components/tasks/RichNotes.tsx — contentEditable 리치 노트 "use client"; import { useEffect, useRef } from "react"; import { Icon } from "@/components/Icon"; import type { IconName } from "@/components/icons/paths"; type Tool = { cmd: string; val?: string; icon?: IconName; txt?: string; title?: string }; const NOTE_TOOLS: Tool[] = [ { cmd: "formatBlock", val: "h3", txt: "제목" }, { cmd: "bold", icon: "bold", title: "굵게" }, { cmd: "italic", icon: "italic", title: "기울임" }, { cmd: "insertUnorderedList", icon: "list", title: "글머리 목록" }, { cmd: "insertOrderedList", icon: "hash", title: "번호 목록" }, { cmd: "formatBlock", val: "blockquote", icon: "quote", title: "인용" }, ]; export function RichNotes({ taskId, value, onChange, }: { taskId: string; value: string; onChange: (html: string) => void; }) { const ref = useRef(null); useEffect(() => { if (ref.current) ref.current.innerHTML = value || ""; // taskId 변경 시에만 외부값으로 리셋 (편집 중 덮어쓰기 방지) // eslint-disable-next-line react-hooks/exhaustive-deps }, [taskId]); const exec = (cmd: string, val?: string) => { ref.current?.focus(); // execCommand: 프로토타입과 동일(현재 deprecated이나 MVP 한정 사용) document.execCommand(cmd, false, val); if (ref.current) onChange(ref.current.innerHTML); }; return (
{NOTE_TOOLS.map((t, i) => ( ))}
ref.current && onChange(ref.current.innerHTML)} />
); }