// sheet/ShortcutsPanel.tsx — W51-T17, the Ctrl+/ panel (ruling R7, contract C8).
//
// ⭐⭐ THIS FILE CONTAINS NO CHORDS. Every row it renders comes from `shortcuts.ts::SHORTCUTS`,
// the same table `SheetGrid.tsx::onKeyDown` matches against, so the panel cannot advertise a key
// the handler does not answer and the handler cannot answer a key the panel does not show.
// `verify_api.py` asserts BOTH halves of that: this file maps over the table, and no chord shaped
// string literal survives in its own source. A hand written list that happens to agree today is
// exactly the defect the clause exists to stop, and it would agree right up until somebody added
// the thirty first shortcut.
//
// ⛔ IT IS A REACT COMPONENT AND IS NEVER NODE COMPILED, which is why it MAY import the base kit
// (`../ui/useEscapeClose`). `shortcuts.ts` may not: tsc's emitted root moves with the import
// graph and the Sheet's node proofs `require` `sheetState.js` at the top of the out directory.
//
// ⭐⭐ CONTRACT C8, AMENDMENT A2 — THE ESCAPE DECISION, MADE DELIBERATELY AND SAID OUT LOUD.
// A2 makes "first Escape cancels a live text edit, the second closes" OPT IN per overlay and
// names the Sheet's right side panels as the family that opts in. This is one of those panels, so
// it opts IN and passes its own `container`, which is what lets the arbiter decide whether the
// focus is inside it at all. In practice the option is inert here, because the panel holds no
// text input to cancel; opting in keeps the family's rule true rather than leaving one member of
// it behaving differently for a reason nobody would remember.
//
// ⛔ THERE IS NO SECOND ESCAPE LISTENER. `useEscapeClose` is the one arbiter, topmost wins, and a
// `document.addEventListener("keydown", …)` added here would race it and win or lose depending on
// registration order.
//
// ⚠ DESIGN CONTRACT: sentence case, scale tokens only and no literal font-size, tokens never
// hues, inline SVG on `currentColor` and no emoji, 150 ms ease-out on opacity and transform, and
// no em dash or en dash in any string that reaches a screen.
import { useRef } from "react";
import { useEscapeClose } from "../ui/useEscapeClose";
import { effectiveKeys, SHORTCUTS } from "./shortcuts";
// W52-T19 -- the `.sheet-shortcuts-keys--off` rule only; see that file's own header for why a
// component-owned side-effect import is this repo's existing way to add a wave-52 rule without
// editing `index.css` or another lane's `styles/wave51/sheet-engine.css`.
import "../styles/wave52/ribbon.css";
export interface ShortcutsPanelProps {
storagePrefix?: string;
open: boolean;
onClose: () => void;
}
/** The close cross. An inline SVG on `currentColor`, never a glyph and never an emoji. */
function IconClose() {
return (
);
}
export default function ShortcutsPanel({ open, onClose, storagePrefix = "" }: ShortcutsPanelProps) {
const boxRef = useRef(null);
useEscapeClose(open, onClose, {
cancelEditFirst: true,
container: () => boxRef.current,
});
if (!open) return null;
return (
Keyboard shortcuts
{/* S68-T28: Paste Special is included by the same table and effectiveKeys as every row.
⭐⭐ ONE ROW PER TABLE ENTRY, AND NOTHING ELSE. No filter, no slice and no second list:
the panel's contents ARE the table, which is the only shape in which the two cannot
drift. `when` is shown because a shortcut that needs a selection and one that does not
are different promises, and a panel that hides the difference teaches the wrong thing. */}