@1771technologies/lytenyte-pro
Version:
Blazingly fast headless React data grid with 100s of features.
92 lines (91 loc) • 4.37 kB
TypeScript
import type { AggregationFn, Aggregator, Dimension, DimensionAgg, DimensionSort, FilterFn, GroupFn, GroupIdFn, LeafIdFn, RowGroup, RowLeaf, RowNode, RowSelectionState, RowSource, SortFn } from "@1771technologies/lytenyte-shared";
import type { Column, Field } from "../types/column.js";
import type { GridSpec } from "../types/grid.js";
import type { PivotState } from "./hooks/use-pivot/use-pivot-columns.js";
import type { Props } from "../types/props.js";
export type PivotField<Spec extends GridSpec = GridSpec> = {
field?: Field<Spec["data"]>;
};
export type HavingFilterFn = (node: RowGroup) => boolean;
export interface RowSourceClient<Spec extends GridSpec = GridSpec> extends RowSource<Spec["data"]> {
readonly usePivotProps: () => {
readonly columns?: Column<Spec>[];
readonly onColumnsChange: Props<Spec>["onColumnsChange"];
readonly columnGroupExpansions: Props<Spec>["columnGroupExpansions"];
readonly onColumnGroupExpansionChange: Props<Spec>["onColumnGroupExpansionChange"];
};
readonly rowUpdate: (rows: Map<RowNode<Spec["data"]>, Spec["data"]>) => void;
readonly rowDelete: (rows: RowNode<Spec["data"]>[]) => void;
readonly rowAdd: (rows: Spec["data"][], placement?: "start" | "end" | number) => void;
}
export type LabelFilter = (s: string | null) => boolean;
export interface PivotModel<Spec extends GridSpec = GridSpec> {
readonly columns?: (Column<Spec> | PivotField<Spec>)[];
readonly rows?: (Column<Spec> | PivotField<Spec>)[];
readonly measures?: {
dim: Column<Spec>;
fn: Aggregator<Spec["data"]> | string;
}[];
readonly sort?: SortFn<Spec["data"]> | DimensionSort<Spec["data"]>[] | null;
readonly filter?: (HavingFilterFn | null)[];
readonly rowLabelFilter?: (LabelFilter | null)[];
readonly colLabelFilter?: (LabelFilter | null)[];
}
export interface UseClientDataSourceParams<Spec extends GridSpec = GridSpec, T = Spec["data"]> {
readonly data: T[];
readonly topData?: T[];
readonly botData?: T[];
readonly pivotMode?: boolean;
readonly pivotModel?: PivotModel<Spec>;
readonly pivotGrandTotals?: "top" | "bottom" | null;
readonly pivotColumnProcessor?: (columns: Column<Spec>[]) => Column<Spec>[];
readonly pivotState?: PivotState;
readonly onPivotStateChange?: (p: PivotState) => void;
readonly pivotApplyExistingFilter?: boolean;
readonly rowGroupExpansions?: {
[rowId: string]: boolean | undefined;
};
readonly rowGroupDefaultExpansion?: boolean | number;
readonly rowGroupCollapseBehavior?: "no-collapse" | "last-only" | "full-tree";
readonly rowGroupSuppressLeafExpansion?: boolean;
readonly onRowGroupExpansionChange?: (state: Record<string, boolean | undefined>) => void;
readonly sort?: SortFn<T> | DimensionSort<T>[] | null;
readonly group?: GroupFn<T> | Dimension<T>[];
readonly filter?: FilterFn<T> | FilterFn<T>[] | null;
readonly aggregate?: AggregationFn<T> | DimensionAgg<T>[];
readonly aggregateFns?: Record<string, Aggregator<T>>;
readonly having?: (HavingFilterFn | null)[] | null;
readonly labelFilter?: (LabelFilter | null)[] | null;
readonly leafIdFn?: LeafIdFn<T>;
readonly groupIdFn?: GroupIdFn;
readonly rowsIsolatedSelection?: boolean;
readonly rowSelectKey?: unknown[];
readonly rowSelection?: RowSelectionState;
readonly rowSelectionIdUniverseAdditions?: {
readonly id: string;
readonly root: boolean;
}[];
readonly rowSelectionIdUniverseSubtractions?: Set<string>;
readonly onRowSelectionChange?: (state: RowSelectionState) => void;
readonly onRowsAdded?: (params: {
newData: T[];
placement: "start" | "end" | number;
top: T[];
center: T[];
bottom: T[];
}) => void;
readonly onRowsDeleted?: (params: {
rows: RowLeaf<T>[];
sourceIndices: number[];
top: T[];
center: T[];
bottom: T[];
}) => void;
readonly onRowDataChange?: (params: {
readonly rows: Map<RowNode<T>, T>;
readonly top: Map<number, T>;
readonly bottom: Map<number, T>;
readonly center: Map<number, T>;
}) => void;
}
export declare function useClientDataSource<Spec extends GridSpec = GridSpec>(props: UseClientDataSourceParams<Spec>): RowSourceClient<Spec>;