UNPKG

hightable

Version:

A dynamic windowed scrolling table component for react

48 lines (47 loc) 1.57 kB
import type { OrderBy } from '../sort.js'; import type { CustomEventTarget } from '../typedEventTarget.js'; export type Obj = Record<string, any>; export type Cells = Obj; export interface ResolvedValue<T = any> { value: T; } export interface DataFrameEvents { 'resolve': undefined; } export interface ColumnDescriptor<C extends Obj = Obj> { name: string; sortable?: boolean; metadata?: C; } export type Fetch = ({ rowStart, rowEnd, columns, orderBy, signal }: { rowStart: number; rowEnd: number; columns?: string[]; orderBy?: OrderBy; signal?: AbortSignal; }) => Promise<void>; /** * DataFrame is an interface for a data structure that represents a table of unmutable data. * * The data can be fetched in chunks, and the table can subscribe to changes using the eventTarget. * * The methods getCell, getRowNumber, and fetch should respect the columns' `sortable` property: * - sort along the sortable columns when `orderBy` is provided, * - throw an error if a column within `orderBy` is not sortable. */ export interface DataFrame<M extends Obj = Obj, C extends Obj = Obj> { numRows: number; columnDescriptors: readonly ColumnDescriptor<C>[]; metadata?: M; getCell({ row, column, orderBy }: { row: number; column: string; orderBy?: OrderBy; }): ResolvedValue | undefined; getRowNumber({ row, orderBy }: { row: number; orderBy?: OrderBy; }): ResolvedValue<number> | undefined; fetch?: Fetch; eventTarget?: CustomEventTarget<DataFrameEvents>; }