135 lines
6.2 KiB
TypeScript
135 lines
6.2 KiB
TypeScript
import * as React from 'react';
|
|
import { integer } from '@mui/x-internals/types';
|
|
import { Store } from '@mui/x-internals/store';
|
|
import { Colspan } from "./features/colspan.mjs";
|
|
import { Dimensions } from "./features/dimensions.mjs";
|
|
import { Rowspan } from "./features/rowspan.mjs";
|
|
import { Virtualization } from "./features/virtualization/index.mjs";
|
|
import type { Layout } from "./features/virtualization/layout.mjs";
|
|
import type { HeightEntry, RowSpacing } from "./models/dimensions.mjs";
|
|
import type { ColspanParams } from "./features/colspan.mjs";
|
|
import type { DimensionsParams } from "./features/dimensions.mjs";
|
|
import type { VirtualizationParams } from "./features/virtualization/index.mjs";
|
|
import { ColumnWithWidth, FocusedCell, Size, PinnedRows, PinnedColumns, RenderContext, Row, RowEntry } from "./models/index.mjs";
|
|
export type Virtualizer = ReturnType<typeof useVirtualizer>;
|
|
export type VirtualScrollerCompat<L extends Layout = Layout> = Virtualization.State<L>['getters'];
|
|
export type BaseState<L extends Layout = Layout> = Virtualization.State<L> & Dimensions.State;
|
|
export type VirtualizerParams<L extends Layout = Layout> = {
|
|
layout: L;
|
|
dimensions: DimensionsParams;
|
|
virtualization: VirtualizationParams;
|
|
colspan?: ColspanParams;
|
|
initialState?: {
|
|
scroll?: {
|
|
top: number;
|
|
left: number;
|
|
};
|
|
rowSpanning?: Rowspan.State['rowSpanning'];
|
|
virtualization?: Partial<Virtualization.State<L>['virtualization']>;
|
|
};
|
|
/** current page rows */
|
|
rows: RowEntry[];
|
|
/** current page range */
|
|
range: {
|
|
firstRowIndex: integer;
|
|
lastRowIndex: integer;
|
|
} | null;
|
|
rowCount: integer;
|
|
columns?: ColumnWithWidth[];
|
|
pinnedRows?: PinnedRows;
|
|
pinnedColumns?: PinnedColumns;
|
|
disableHorizontalScroll?: boolean;
|
|
disableVerticalScroll?: boolean;
|
|
getRowHeight?: (row: RowEntry) => number | null | undefined | 'auto';
|
|
/**
|
|
* Function that returns the estimated height for a row.
|
|
* Only works if dynamic row height is used.
|
|
* Once the row height is measured this value is discarded.
|
|
* @param rowEntry
|
|
* @returns The estimated row height value. If `null` or `undefined` then the default row height, based on the density, is applied.
|
|
*/
|
|
getEstimatedRowHeight?: (rowEntry: RowEntry) => number | null;
|
|
/**
|
|
* Function that allows to specify the spacing between rows.
|
|
* @param rowEntry
|
|
* @returns The row spacing values.
|
|
*/
|
|
getRowSpacing?: (rowEntry: RowEntry) => RowSpacing;
|
|
/** Update the row height values before they're used.
|
|
* Used to add detail panel heights.
|
|
* @param entry
|
|
* @param rowEntry
|
|
*/
|
|
applyRowHeight?: (entry: HeightEntry, rowEntry: RowEntry) => void;
|
|
virtualizeColumnsWithAutoRowHeight?: boolean;
|
|
resizeThrottleMs?: number;
|
|
onResize?: (lastSize: Size) => void;
|
|
onWheel?: (event: React.WheelEvent) => void;
|
|
onTouchMove?: (event: React.TouchEvent) => void;
|
|
onRenderContextChange?: (c: RenderContext) => void;
|
|
onScrollChange?: (scrollPosition: {
|
|
top: number;
|
|
left: number;
|
|
}, nextRenderContext: RenderContext) => void;
|
|
focusedVirtualCell?: () => FocusedCell | null;
|
|
scrollReset?: any;
|
|
renderRow: (params: {
|
|
id: any;
|
|
model: Row;
|
|
rowIndex: number;
|
|
offsetLeft: number;
|
|
columnsTotalWidth: number;
|
|
baseRowHeight: number | 'auto';
|
|
firstColumnIndex: number;
|
|
lastColumnIndex: number;
|
|
focusedColumnIndex: number | undefined;
|
|
isFirstVisible: boolean;
|
|
isLastVisible: boolean;
|
|
isVirtualFocusRow: boolean;
|
|
showBottomBorder: boolean;
|
|
}) => React.ReactElement;
|
|
renderInfiniteLoadingTrigger?: (id: any) => React.ReactElement;
|
|
};
|
|
type RequiredFields<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
export type ParamsWithDefaults = RequiredFields<VirtualizerParams, 'resizeThrottleMs' | 'columns'> & {
|
|
dimensions: RequiredFields<VirtualizerParams['dimensions'], 'columnsTotalWidth' | 'leftPinnedWidth' | 'rightPinnedWidth' | 'topPinnedHeight' | 'bottomPinnedHeight' | 'autoHeight'>;
|
|
virtualization: RequiredFields<VirtualizerParams['virtualization'], 'isRtl' | 'rowBufferPx' | 'columnBufferPx'>;
|
|
};
|
|
export declare const useVirtualizer: <L extends Layout = Layout<{
|
|
scroller: React.RefObject<HTMLElement | null>;
|
|
container: React.RefObject<HTMLElement | null>;
|
|
} & Record<string, React.RefObject<HTMLElement | null>>>>(params: VirtualizerParams<L>) => {
|
|
store: Store<Dimensions.State & Virtualization.State<L> & Colspan.State & Rowspan.State>;
|
|
api: {
|
|
updateDimensions: (firstUpdate?: boolean) => void;
|
|
debouncedUpdateDimensions: (((firstUpdate?: boolean) => void) & import("@mui/x-internals/throttle").Cancelable) | undefined;
|
|
rowsMeta: {
|
|
getRowHeight: (rowId: import("./models/index.mjs").RowId) => any;
|
|
setLastMeasuredRowIndex: (index: number) => void;
|
|
storeRowHeightMeasurement: (id: import("./models/index.mjs").RowId, height: number) => void;
|
|
hydrateRowsMeta: () => void;
|
|
observeRowHeight: (element: Element, rowId: import("./models/index.mjs").RowId) => () => void | undefined;
|
|
rowHasAutoHeight: (id: import("./models/index.mjs").RowId) => any;
|
|
getRowHeightEntry: (rowId: import("./models/index.mjs").RowId) => any;
|
|
getLastMeasuredRowIndex: () => number;
|
|
resetRowHeights: () => void;
|
|
};
|
|
} & {
|
|
getCellColSpanInfo: (rowId: import("./models/index.mjs").RowId, columnIndex: integer) => import("./models/index.mjs").CellColSpanInfo;
|
|
calculateColSpan: (rowId: import("./models/index.mjs").RowId, minFirstColumn: integer, maxLastColumn: integer, columns: ColumnWithWidth[]) => void;
|
|
getHiddenCellsOrigin: () => Record<import("./models/index.mjs").RowId, Record<number, number>>;
|
|
getters: any;
|
|
setPanels: React.Dispatch<React.SetStateAction<Readonly<Map<any, React.ReactNode>>>>;
|
|
forceUpdateRenderContext: () => void;
|
|
scheduleUpdateRenderContext: () => void;
|
|
} & {
|
|
resetColSpan: () => void;
|
|
getCellColSpanInfo: (rowId: import("./models/index.mjs").RowId, columnIndex: integer) => import("./models/index.mjs").CellColSpanInfo | undefined;
|
|
calculateColSpan: (rowId: import("./models/index.mjs").RowId, minFirstColumn: integer, maxLastColumn: integer, columns: ColumnWithWidth[]) => void;
|
|
} & {
|
|
getHiddenCellsOrigin: () => Record<number, Record<number, number>>;
|
|
} & {
|
|
getViewportPageSize: () => number;
|
|
};
|
|
};
|
|
export {}; |