CursorDeclarationContext.ts
ink/components/CursorDeclarationContext.ts
33
Lines
1119
Bytes
2
Exports
2
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with repo-context, ui-flow. It contains 33 lines, 2 detected imports, and 2 detected exports.
Important relationships
Detected exports
CursorDeclarationCursorDeclarationSetter
Keywords
nodedomelementdeclaredreadonlycreatecontextcursordeclarationwithinmakescleardeclaration
Detected imports
react../dom.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
import { createContext } from 'react'
import type { DOMElement } from '../dom.js'
export type CursorDeclaration = {
/** Display column (terminal cell width) within the declared node */
readonly relativeX: number
/** Line number within the declared node */
readonly relativeY: number
/** The ink-box DOMElement whose yoga layout provides the absolute origin */
readonly node: DOMElement
}
/**
* Setter for the declared cursor position.
*
* The optional second argument makes `null` a conditional clear: the
* declaration is only cleared if the currently-declared node matches
* `clearIfNode`. This makes the hook safe for sibling components
* (e.g. list items) that transfer focus among themselves — without the
* node check, a newly-unfocused item's clear could clobber a
* newly-focused sibling's set depending on layout-effect order.
*/
export type CursorDeclarationSetter = (
declaration: CursorDeclaration | null,
clearIfNode?: DOMElement | null,
) => void
const CursorDeclarationContext = createContext<CursorDeclarationSetter>(
() => {},
)
export default CursorDeclarationContext