hightable
Version:
A dynamic windowed scrolling table component for react
72 lines (71 loc) • 2.39 kB
TypeScript
import type { OrderBy } from '../sort.js';
import type { CustomEventTarget } from '../typedEventTarget.js';
export type Cells = Record<string, any>;
export interface ResolvedValue<T = any> {
value: T;
}
export interface DataFrameEvents {
'resolve': undefined;
}
/**
* UnsortableDataFrame 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 data frame does not support sorting, and the `sortable` property is set to false.
*/
export interface UnsortableDataFrame {
numRows: number;
header: string[];
metadata?: Record<string, any>;
sortable?: false;
getCell({ row, column }: {
row: number;
column: string;
}): ResolvedValue | undefined;
getRowNumber({ row }: {
row: number;
}): ResolvedValue<number> | undefined;
fetch: ({ rowStart, rowEnd, columns, signal }: {
rowStart: number;
rowEnd: number;
columns?: string[];
signal?: AbortSignal;
}) => Promise<void>;
eventTarget?: CustomEventTarget<DataFrameEvents>;
}
/**
* SortableDataFrame 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.
*
* It can be sorted.
*/
export interface SortableDataFrame extends Omit<UnsortableDataFrame, 'sortable'> {
sortable: true;
getCell({ row, column, orderBy }: {
row: number;
column: string;
orderBy?: OrderBy;
}): ResolvedValue | undefined;
getRowNumber({ row, orderBy }: {
row: number;
orderBy?: OrderBy;
}): ResolvedValue<number> | undefined;
fetch: ({ rowStart, rowEnd, columns, orderBy, signal }: {
rowStart: number;
rowEnd: number;
columns?: string[];
orderBy?: OrderBy;
signal?: AbortSignal;
}) => Promise<void>;
eventTarget: CustomEventTarget<DataFrameEvents>;
}
/**
* 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.
*
* It can be sorted or unsorted, see the `sortable` property.
*/
export type DataFrame = SortableDataFrame | UnsortableDataFrame;