import { CellContext, ColumnDef, ColumnMeta, Row, VisibilityState, } from "@tanstack/react-table" import React, { PropsWithChildren, ReactNode, RefObject } from "react" import { FieldErrors, FieldPath, FieldValues, Path, PathValue, } from "react-hook-form" export type DataGridColumnType = | "text" | "multiline-text" | "number" | "boolean" | "togglable-number" export type DataGridCoordinates = { row: number col: number } export interface DataGridCellProps { context: CellContext } export interface DataGridCellContext extends CellContext { /** * The index of the column in the grid. */ columnIndex: number /** * The index of the row in the grid. */ rowIndex: number } export type DataGridRowError = { message: string to: () => void } export type DataGridErrorRenderProps = { errors: FieldErrors rowErrors: DataGridRowError[] } export interface DataGridCellRenderProps { container: DataGridCellContainerProps input: InputProps } type InputAttributes = { "data-row": number "data-col": number "data-cell-id": string "data-field": string } export interface InputProps { ref: RefObject onBlur: () => void onFocus: () => void onChange: (next: any, prev: any) => void "data-row": number "data-col": number "data-cell-id": string "data-field": string } type InnerAttributes = { "data-container-id": string } interface InnerProps { ref: RefObject onMouseOver: ((e: React.MouseEvent) => void) | undefined onMouseDown: ((e: React.MouseEvent) => void) | undefined onKeyDown: (e: React.KeyboardEvent) => void onFocus: (e: React.FocusEvent) => void "data-container-id": string } interface OverlayProps { onMouseDown: (e: React.MouseEvent) => void } export interface DataGridCellContainerProps extends PropsWithChildren<{}> { field: string innerProps: InnerProps overlayProps: OverlayProps isAnchor: boolean isSelected: boolean isDragSelected: boolean placeholder?: ReactNode showOverlay: boolean outerComponent?: ReactNode } export type DataGridCellSnapshot< TFieldValues extends FieldValues = FieldValues > = { field: string value: PathValue> } export type FieldContext = { row: Row column: ColumnDef } export type FieldFunction = ( context: FieldContext ) => FieldPath | null export type InternalColumnMeta = { name: string field?: FieldFunction } & ( | { field: FieldFunction type: DataGridColumnType } | { field?: null | undefined; type?: never } ) & ColumnMeta export type GridCell = { field: FieldPath type: DataGridColumnType enabled: boolean } export type Grid = (GridCell | null)[][] export type CellMetadata = { id: string field: string type: DataGridColumnType inputAttributes: InputAttributes innerAttributes: InnerAttributes } export type CellErrorMetadata = { field: string | null accessor: string | null } export type VisibilitySnapshot = { rows: VisibilityState columns: VisibilityState } export type GridColumnOption = { id: string name: string checked: boolean disabled: boolean } export type DataGridToggleableNumber = { quantity: number | string checked: boolean disabledToggle: boolean }