CursorDeclarationContext.ts
1 import { createContext } from 'react' 2 import type { DOMElement } from '../dom.js' 3 4 export type CursorDeclaration = { 5 /** Display column (terminal cell width) within the declared node */ 6 readonly relativeX: number 7 /** Line number within the declared node */ 8 readonly relativeY: number 9 /** The ink-box DOMElement whose yoga layout provides the absolute origin */ 10 readonly node: DOMElement 11 } 12 13 /** 14 * Setter for the declared cursor position. 15 * 16 * The optional second argument makes `null` a conditional clear: the 17 * declaration is only cleared if the currently-declared node matches 18 * `clearIfNode`. This makes the hook safe for sibling components 19 * (e.g. list items) that transfer focus among themselves — without the 20 * node check, a newly-unfocused item's clear could clobber a 21 * newly-focused sibling's set depending on layout-effect order. 22 */ 23 export type CursorDeclarationSetter = ( 24 declaration: CursorDeclaration | null, 25 clearIfNode?: DOMElement | null, 26 ) => void 27 28 const CursorDeclarationContext = createContext<CursorDeclarationSetter>( 29 () => {}, 30 ) 31 32 export default CursorDeclarationContext