Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download web/src/sheet/ShortcutsPanel.tsx from fsanyoto/runloopable: direct link, hf CLI and curl.
- Browser
- Download file 5.42 kB
-
https://huggingface.co/spaces/fsanyoto/runloopable/resolve/main/web/src/sheet/ShortcutsPanel.tsx
- Command line
-
hf download hf://spaces/fsanyoto/runloopable/web/src/sheet/ShortcutsPanel.tsx
-
curl -L -o ShortcutsPanel.tsx https://huggingface.co/spaces/fsanyoto/runloopable/resolve/main/web/src/sheet/ShortcutsPanel.tsx
5.42 kB
| // 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 ( | |
| <svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-shortcuts-icon"> | |
| <path d="M4.5 4.5l7 7M11.5 4.5l-7 7" /> | |
| </svg> | |
| ); | |
| } | |
| export default function ShortcutsPanel({ open, onClose, storagePrefix = "" }: ShortcutsPanelProps) { | |
| const boxRef = useRef<HTMLDivElement | null>(null); | |
| useEscapeClose(open, onClose, { | |
| cancelEditFirst: true, | |
| container: () => boxRef.current, | |
| }); | |
| if (!open) return null; | |
| return ( | |
| <div | |
| className="sheet-shortcuts" | |
| role="dialog" | |
| aria-label="Keyboard shortcuts" | |
| ref={boxRef} | |
| > | |
| <div className="sheet-shortcuts-head"> | |
| <h2 className="sheet-shortcuts-title">Keyboard shortcuts</h2> | |
| <button | |
| type="button" | |
| className="sheet-shortcuts-close" | |
| aria-label="Close the shortcuts list" | |
| title="Close the shortcuts list" | |
| onMouseDown={(e) => e.preventDefault()} | |
| onClick={onClose} | |
| > | |
| <IconClose /> | |
| </button> | |
| </div> | |
| {/* 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. */} | |
| <ul className="sheet-shortcuts-list"> | |
| {SHORTCUTS.map((entry) => { | |
| const keys = effectiveKeys(entry.id, storagePrefix); | |
| const disabled = keys === "Disabled"; | |
| return ( | |
| <li className="sheet-shortcuts-row" key={entry.id}> | |
| <kbd | |
| className={ | |
| "sheet-shortcuts-keys" + (disabled ? " sheet-shortcuts-keys--off" : "") | |
| } | |
| > | |
| {disabled ? "Disabled" : keys} | |
| </kbd> | |
| <span className="sheet-shortcuts-action">{entry.action}</span> | |
| <span className="sheet-shortcuts-when">{entry.when}</span> | |
| </li> | |
| ); | |
| })} | |
| </ul> | |
| {/* Owner instruction 21 / ruling R7 β the deliberate deviation, said out loud. */} | |
| <p className="sheet-shortcuts-foot"> | |
| Rebinding your own shortcuts is a departure from Excel, which does not allow it. Change | |
| them under Settings, Sheet shortcuts. | |
| </p> | |
| <p className="sheet-shortcuts-foot"> | |
| Press Escape to close this list. | |
| </p> | |
| </div> | |
| ); | |
| } | |