import { KeyboardEvent } from 'react'; export interface EditableGridKeyboardNavOptions { /** Whether a column accepts focus/edit — read-only columns are skipped by nav. */ isColumnEditable: (colKey: string) => boolean; /** * Bring a row into view before focusing it (virtualized mode) — typically * `virtualizer.scrollToIndex`. Harmless/no-op when not virtualizing. */ ensureRowVisible?: (rowIndex: number) => void; } /** * useEditableGridKeyboardNav — roving spreadsheet focus for `EditableGrid`. * * Focus is tracked by a `Map` keyed `${rowId}:${columnKey}` (NEVER by array * index — the grid's stable-rowId contract, legacy anti-pattern #2). Navigation * derives neighbours from the CURRENT order arrays (held in refs so the handler * closes over live data without re-binding every keystroke) and SKIPS read-only * columns: * - Tab / Shift+Tab → next / previous editable cell (wraps across rows); at * the grid boundary it does NOT preventDefault, so focus escapes the grid * naturally (no WCAG keyboard trap) * - Enter / Shift+Enter, ArrowDown / ArrowUp → down / up the same column * - ArrowLeft / ArrowRight → previous / next editable column in the same row, * but ONLY when the caret is at the field edge (intra-cell editing wins first) * * `