import { FocusEvent, MouseEvent, createContext } from "react" import { Control, FieldValues, Path, UseFormRegister } from "react-hook-form" import { CellCoords, CellType } from "./types" type DataGridContextType = { // Grid state anchor: CellCoords | null trapActive: boolean // Cell handlers registerCell: (coords: CellCoords, field: string, type: CellType) => void getIsCellSelected: (coords: CellCoords) => boolean getIsCellDragSelected: (coords: CellCoords) => boolean // Grid handlers setIsEditing: (value: boolean) => void setIsSelecting: (value: boolean) => void setRangeEnd: (coords: CellCoords) => void setSingleRange: (coords: CellCoords) => void // Form state and handlers register: UseFormRegister control: Control getInputChangeHandler: (field: Path) => (next: any, prev: any) => void // Wrapper handlers getWrapperFocusHandler: ( coordinates: CellCoords ) => (e: FocusEvent) => void getWrapperMouseOverHandler: ( coordinates: CellCoords ) => ((e: MouseEvent) => void) | undefined } export const DataGridContext = createContext | null>( null )