import { useEffect, useRef, useState } from "react"; /** * A pinned note on a phone. * * There is no margin to write in: a page narrow enough to read on a phone leaves * no white space beside it, and stealing 200px for a column would make the * document itself unreadable. So the note comes up from the bottom instead — * over the page rather than beside it, but only while it is being read or * written, and within reach of a thumb rather than at the top of the screen. * * The page stays visible above it, so the passage the note is about is still * there while writing about it. */ export function PdfNoteSheet({ T, note, number, onChange, onClose, onRemove }) { const [draft, setDraft] = useState(note.text); const areaRef = useRef(null); useEffect(() => setDraft(note.text), [note.id]); const commit = () => { if (draft !== note.text) onChange(draft); }; const close = () => { commit(); onClose(); }; useEffect(() => { const onKey = (e) => { if (e.key === "Escape") close(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }); return (