1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import {
|
11 | ChangeEvent,
|
12 | ComponentType,
|
13 | CSSProperties,
|
14 | DependencyList,
|
15 | EffectCallback,
|
16 | MouseEvent,
|
17 | ReactElement,
|
18 | ReactNode,
|
19 | } from "react";
|
20 |
|
21 | export {};
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | export interface TableOptions<D extends object> extends UseTableOptions<D> {}
|
34 |
|
35 | export interface TableInstance<D extends object = {}>
|
36 | extends Omit<TableOptions<D>, "columns" | "pageCount">, UseTableInstanceProps<D>
|
37 | {}
|
38 |
|
39 | export interface TableState<D extends object = {}> {
|
40 | hiddenColumns?: Array<IdType<D>> | undefined;
|
41 | }
|
42 |
|
43 | export interface Hooks<D extends object = {}> extends UseTableHooks<D> {}
|
44 |
|
45 | export interface Cell<D extends object = {}, V = any> extends UseTableCellProps<D, V> {}
|
46 |
|
47 | export interface ColumnInterface<D extends object = {}> extends UseTableColumnOptions<D> {}
|
48 |
|
49 | export interface ColumnInterfaceBasedOnValue<D extends object = {}, V = any> {
|
50 | Cell?: Renderer<CellProps<D, V>> | undefined;
|
51 | }
|
52 |
|
53 | export interface ColumnGroupInterface<D extends object> {
|
54 | columns: Array<Column<D>>;
|
55 | }
|
56 |
|
57 | export type ColumnGroup<D extends object = {}> =
|
58 | & ColumnInterface<D>
|
59 | & ColumnGroupInterface<D>
|
60 | & (
|
61 | | { Header: string }
|
62 | | ({ id: IdType<D> } & {
|
63 | Header: Renderer<HeaderProps<D>>;
|
64 | })
|
65 | )
|
66 |
|
67 | & { accessor?: Accessor<D> | undefined };
|
68 |
|
69 | type ValueOf<T> = T[keyof T];
|
70 |
|
71 |
|
72 | export type ColumnWithStrictAccessor<D extends object = {}> =
|
73 | & ColumnInterface<D>
|
74 | & ValueOf<
|
75 | {
|
76 | [K in keyof D]: {
|
77 | accessor: K;
|
78 | } & ColumnInterfaceBasedOnValue<D, D[K]>;
|
79 | }
|
80 | >;
|
81 |
|
82 | export type ColumnWithLooseAccessor<D extends object = {}> =
|
83 | & ColumnInterface<D>
|
84 | & ColumnInterfaceBasedOnValue<D>
|
85 | & (
|
86 | | { Header: string }
|
87 | | { id: IdType<D> }
|
88 | | { accessor: keyof D extends never ? IdType<D> : never }
|
89 | )
|
90 | & { accessor?: (keyof D extends never ? IdType<D> | Accessor<D> : Accessor<D>) | undefined };
|
91 |
|
92 | export type Column<D extends object = {}> =
|
93 | | ColumnGroup<D>
|
94 | | ColumnWithLooseAccessor<D>
|
95 | | ColumnWithStrictAccessor<D>;
|
96 |
|
97 | export interface ColumnInstance<D extends object = {}>
|
98 | extends Omit<ColumnInterface<D>, "id">, ColumnInterfaceBasedOnValue<D>, UseTableColumnProps<D>
|
99 | {}
|
100 |
|
101 | export interface HeaderGroup<D extends object = {}> extends ColumnInstance<D>, UseTableHeaderGroupProps<D> {}
|
102 |
|
103 | export interface Row<D extends object = {}> extends UseTableRowProps<D> {}
|
104 |
|
105 | export interface TableCommonProps {
|
106 | style?: CSSProperties | undefined;
|
107 | className?: string | undefined;
|
108 | role?: string | undefined;
|
109 | }
|
110 |
|
111 | export interface TableProps extends TableCommonProps {}
|
112 |
|
113 | export interface TableBodyProps extends TableCommonProps {}
|
114 |
|
115 | export interface TableKeyedProps extends TableCommonProps {
|
116 | key: React.Key;
|
117 | }
|
118 |
|
119 | export interface TableHeaderGroupProps extends TableKeyedProps {}
|
120 |
|
121 | export interface TableFooterGroupProps extends TableKeyedProps {}
|
122 |
|
123 | export interface TableHeaderProps extends TableKeyedProps {}
|
124 |
|
125 | export interface TableFooterProps extends TableKeyedProps {}
|
126 |
|
127 | export interface TableRowProps extends TableKeyedProps {}
|
128 |
|
129 | export interface TableCellProps extends TableKeyedProps {}
|
130 |
|
131 | export interface TableToggleCommonProps extends TableCommonProps {
|
132 | onChange?: ((e: ChangeEvent) => void) | undefined;
|
133 | checked?: boolean | undefined;
|
134 | title?: string | undefined;
|
135 | indeterminate?: boolean | undefined;
|
136 | }
|
137 |
|
138 | export interface MetaBase<D extends object> {
|
139 | instance: TableInstance<D>;
|
140 | userProps: any;
|
141 | }
|
142 |
|
143 | // inspired by ExtendState in https://github.com/reduxjs/redux/blob/master/src/types/store.ts
|
144 | export type Meta<D extends object, Extension = never, M = MetaBase<D>> = [Extension] extends [never] ? M
|
145 | : M & Extension;
|
146 |
|
147 | // #region useTable
|
148 | export function useTable<D extends object = {}>(
|
149 | options: TableOptions<D>,
|
150 | ...plugins: Array<PluginHook<D>>
|
151 | ): TableInstance<D>;
|
152 |
|
153 | /**
|
154 | * NOTE: To use custom options, use "Interface Merging" to add the custom options
|
155 | */
|
156 | export type UseTableOptions<D extends object> =
|
157 | & {
|
158 | columns: ReadonlyArray<Column<D>>;
|
159 | data: readonly D[];
|
160 | }
|
161 | & Partial<{
|
162 | initialState: Partial<TableState<D>>;
|
163 | stateReducer: (
|
164 | newState: TableState<D>,
|
165 | action: ActionType,
|
166 | previousState: TableState<D>,
|
167 | instance?: TableInstance<D>,
|
168 | ) => TableState<D>;
|
169 | useControlledState: (state: TableState<D>, meta: Meta<D>) => TableState<D>;
|
170 | defaultColumn: Partial<Column<D>>;
|
171 | getSubRows: (originalRow: D, relativeIndex: number) => D[];
|
172 | getRowId: (originalRow: D, relativeIndex: number, parent?: Row<D>) => string;
|
173 | autoResetHiddenColumns: boolean;
|
174 | }>;
|
175 |
|
176 | export type PropGetter<D extends object, Props, T extends object = never, P = Partial<Props>> =
|
177 | | ((props: P, meta: Meta<D, T>) => P | P[])
|
178 | | P
|
179 | | P[];
|
180 |
|
181 | export type TablePropGetter<D extends object> = PropGetter<D, TableProps>;
|
182 |
|
183 | export type TableBodyPropGetter<D extends object> = PropGetter<D, TableBodyProps>;
|
184 |
|
185 | export type HeaderPropGetter<D extends object> = PropGetter<D, TableHeaderProps, { column: HeaderGroup<D> }>;
|
186 |
|
187 | export type FooterGroupPropGetter<D extends object> = PropGetter<D, TableFooterGroupProps, { column: HeaderGroup<D> }>;
|
188 |
|
189 | export type HeaderGroupPropGetter<D extends object> = PropGetter<D, TableHeaderGroupProps, { column: HeaderGroup<D> }>;
|
190 |
|
191 | export type FooterPropGetter<D extends object> = PropGetter<D, TableFooterProps, { column: HeaderGroup<D> }>;
|
192 |
|
193 | export type RowPropGetter<D extends object> = PropGetter<D, TableRowProps, { row: Row<D> }>;
|
194 |
|
195 | export type CellPropGetter<D extends object> = PropGetter<D, TableCellProps, { cell: Cell<D> }>;
|
196 |
|
197 | export interface ReducerTableState<D extends object> extends TableState<D>, Record<string, any> {}
|
198 |
|
199 | export interface UseTableHooks<D extends object> extends Record<string, any> {
|
200 | useOptions: Array<(options: TableOptions<D>, args: TableOptions<D>) => TableOptions<D>>;
|
201 | stateReducers: Array<
|
202 | (
|
203 | newState: TableState<D>,
|
204 | action: ActionType,
|
205 | previousState?: TableState<D>,
|
206 | instance?: TableInstance<D>,
|
207 | ) => ReducerTableState<D> | undefined
|
208 | >;
|
209 | columns: Array<(columns: Array<Column<D>>, meta: Meta<D>) => Array<Column<D>>>;
|
210 | columnsDeps: Array<(deps: any[], meta: Meta<D>) => any[]>;
|
211 | allColumns: Array<(allColumns: Array<ColumnInstance<D>>, meta: Meta<D>) => Array<Column<D>>>;
|
212 | allColumnsDeps: Array<(deps: any[], meta: Meta<D>) => any[]>;
|
213 | visibleColumns: Array<(allColumns: Array<ColumnInstance<D>>, meta: Meta<D>) => Array<Column<D>>>;
|
214 | visibleColumnsDeps: Array<(deps: any[], meta: Meta<D>) => any[]>;
|
215 | headerGroups: Array<(allColumns: Array<HeaderGroup<D>>, meta: Meta<D>) => Array<HeaderGroup<D>>>;
|
216 | headerGroupsDeps: Array<(deps: any[], meta: Meta<D>) => any[]>;
|
217 | useInstanceBeforeDimensions: Array<(instance: TableInstance<D>) => void>;
|
218 | useInstance: Array<(instance: TableInstance<D>) => void>;
|
219 | prepareRow: Array<(row: Row<D>, meta: Meta<D>) => void>;
|
220 | useControlledState: Array<(state: TableState<D>, meta: Meta<D>) => TableState<D>>;
|
221 |
|
222 | getTableProps: Array<TablePropGetter<D>>;
|
223 | getTableBodyProps: Array<TableBodyPropGetter<D>>;
|
224 | getHeaderGroupProps: Array<HeaderGroupPropGetter<D>>;
|
225 | getFooterGroupProps: Array<FooterGroupPropGetter<D>>;
|
226 | getHeaderProps: Array<HeaderPropGetter<D>>;
|
227 | getFooterProps: Array<FooterPropGetter<D>>;
|
228 | getRowProps: Array<RowPropGetter<D>>;
|
229 | getCellProps: Array<CellPropGetter<D>>;
|
230 | useFinalInstance: Array<(instance: TableInstance<D>) => void>;
|
231 | }
|
232 |
|
233 | export interface UseTableColumnOptions<D extends object> {
|
234 | id?: IdType<D> | undefined;
|
235 | Header?: Renderer<HeaderProps<D>> | undefined;
|
236 | Footer?: Renderer<FooterProps<D>> | undefined;
|
237 | width?: number | string | undefined;
|
238 | minWidth?: number | undefined;
|
239 | maxWidth?: number | undefined;
|
240 | }
|
241 |
|
242 | type UpdateHiddenColumns<D extends object> = (oldHidden: Array<IdType<D>>) => Array<IdType<D>>;
|
243 |
|
244 | export interface TableToggleHideAllColumnProps extends TableToggleCommonProps {}
|
245 |
|
246 | export interface UseTableInstanceProps<D extends object> {
|
247 | state: TableState<D>;
|
248 | plugins: Array<PluginHook<D>>;
|
249 | dispatch: TableDispatch;
|
250 | columns: Array<ColumnInstance<D>>;
|
251 | allColumns: Array<ColumnInstance<D>>;
|
252 | visibleColumns: Array<ColumnInstance<D>>;
|
253 | headerGroups: Array<HeaderGroup<D>>;
|
254 | footerGroups: Array<HeaderGroup<D>>;
|
255 | headers: Array<ColumnInstance<D>>;
|
256 | flatHeaders: Array<ColumnInstance<D>>;
|
257 | rows: Array<Row<D>>;
|
258 | rowsById: Record<string, Row<D>>;
|
259 | getTableProps: (propGetter?: TablePropGetter<D>) => TableProps;
|
260 | getTableBodyProps: (propGetter?: TableBodyPropGetter<D>) => TableBodyProps;
|
261 | prepareRow: (row: Row<D>) => void;
|
262 | flatRows: Array<Row<D>>;
|
263 | totalColumnsWidth: number;
|
264 | allColumnsHidden: boolean;
|
265 | toggleHideColumn: (columnId: IdType<D>, value?: boolean) => void;
|
266 | setHiddenColumns: (param: Array<IdType<D>> | UpdateHiddenColumns<D>) => void;
|
267 | toggleHideAllColumns: (value?: boolean) => void;
|
268 | getToggleHideAllColumnsProps: (props?: Partial<TableToggleHideAllColumnProps>) => TableToggleHideAllColumnProps;
|
269 | getHooks: () => Hooks<D>;
|
270 | }
|
271 |
|
272 | export interface UseTableHeaderGroupProps<D extends object> {
|
273 | headers: Array<HeaderGroup<D>>;
|
274 | getHeaderGroupProps: (propGetter?: HeaderGroupPropGetter<D>) => TableHeaderProps;
|
275 | getFooterGroupProps: (propGetter?: FooterGroupPropGetter<D>) => TableFooterProps;
|
276 | totalHeaderCount: number;
|
277 | }
|
278 |
|
279 | export interface UseTableColumnProps<D extends object> {
|
280 | id: IdType<D>;
|
281 | columns?: Array<ColumnInstance<D>> | undefined;
|
282 | isVisible: boolean;
|
283 | render: (type: "Header" | "Footer" | string, props?: object) => ReactNode;
|
284 | totalLeft: number;
|
285 | totalWidth: number;
|
286 | getHeaderProps: (propGetter?: HeaderPropGetter<D>) => TableHeaderProps;
|
287 | getFooterProps: (propGetter?: FooterPropGetter<D>) => TableFooterProps;
|
288 | toggleHidden: (value?: boolean) => void;
|
289 | parent?: ColumnInstance<D> | undefined;
|
290 | getToggleHiddenProps: (userProps?: any) => any;
|
291 | depth: number;
|
292 | placeholderOf?: ColumnInstance | undefined;
|
293 | }
|
294 |
|
295 | export interface UseTableRowProps<D extends object> {
|
296 | cells: Array<Cell<D>>;
|
297 | allCells: Array<Cell<D>>;
|
298 | values: Record<IdType<D>, CellValue>;
|
299 | getRowProps: (propGetter?: RowPropGetter<D>) => TableRowProps;
|
300 | index: number;
|
301 | original: D;
|
302 | id: string;
|
303 | subRows: Array<Row<D>>;
|
304 | }
|
305 |
|
306 | export interface UseTableCellProps<D extends object, V = any> {
|
307 | column: ColumnInstance<D>;
|
308 | row: Row<D>;
|
309 | value: CellValue<V>;
|
310 | getCellProps: (propGetter?: CellPropGetter<D>) => TableCellProps;
|
311 | render: (type: "Cell" | string, userProps?: object) => ReactNode;
|
312 | }
|
313 |
|
314 | export type HeaderProps<D extends object> = TableInstance<D> & {
|
315 | column: ColumnInstance<D>;
|
316 | };
|
317 |
|
318 | export type FooterProps<D extends object> = TableInstance<D> & {
|
319 | column: ColumnInstance<D>;
|
320 | };
|
321 |
|
322 | export type CellProps<D extends object, V = any> = TableInstance<D> & {
|
323 | column: ColumnInstance<D>;
|
324 | row: Row<D>;
|
325 | cell: Cell<D, V>;
|
326 | value: CellValue<V>;
|
327 | };
|
328 |
|
329 | export type Accessor<D extends object> = (
|
330 | originalRow: D,
|
331 | index: number,
|
332 | sub: {
|
333 | subRows: D[];
|
334 | depth: number;
|
335 | data: D[];
|
336 | },
|
337 | ) => CellValue;
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 | export function useAbsoluteLayout<D extends object = {}>(hooks: Hooks<D>): void;
|
345 |
|
346 | export namespace useAbsoluteLayout {
|
347 | const pluginName = "useAbsoluteLayout";
|
348 | }
|
349 |
|
350 |
|
351 |
|
352 | export function useBlockLayout<D extends object = {}>(hooks: Hooks<D>): void;
|
353 |
|
354 | export namespace useBlockLayout {
|
355 | const pluginName = "useBlockLayout";
|
356 | }
|
357 |
|
358 |
|
359 |
|
360 | export function useColumnOrder<D extends object = {}>(hooks: Hooks<D>): void;
|
361 |
|
362 | export namespace useColumnOrder {
|
363 | const pluginName = "useColumnOrder";
|
364 | }
|
365 |
|
366 | export interface UseColumnOrderState<D extends object> {
|
367 | columnOrder: Array<IdType<D>>;
|
368 | }
|
369 |
|
370 | export interface UseColumnOrderInstanceProps<D extends object> {
|
371 | setColumnOrder: (updater: ((columnOrder: Array<IdType<D>>) => Array<IdType<D>>) | Array<IdType<D>>) => void;
|
372 | }
|
373 |
|
374 |
|
375 |
|
376 |
|
377 | export function useExpanded<D extends object = {}>(hooks: Hooks<D>): void;
|
378 |
|
379 | export namespace useExpanded {
|
380 | const pluginName = "useExpanded";
|
381 | }
|
382 |
|
383 | export interface TableExpandedToggleProps extends TableKeyedProps {}
|
384 |
|
385 | export type UseExpandedOptions<D extends object> = Partial<{
|
386 | manualExpandedKey: IdType<D>;
|
387 | paginateExpandedRows: boolean;
|
388 | expandSubRows: boolean;
|
389 | autoResetExpanded?: boolean | undefined;
|
390 | }>;
|
391 |
|
392 | export interface UseExpandedHooks<D extends object> {
|
393 | getToggleRowsExpandedProps: Array<PropGetter<D, TableCommonProps>>;
|
394 | getToggleAllRowsExpandedProps: Array<PropGetter<D, TableCommonProps>>;
|
395 | }
|
396 |
|
397 | export interface UseExpandedState<D extends object> {
|
398 | expanded: Record<IdType<D>, boolean>;
|
399 | }
|
400 |
|
401 | export interface UseExpandedInstanceProps<D extends object> {
|
402 | preExpandedRows: Array<Row<D>>;
|
403 | expandedRows: Array<Row<D>>;
|
404 | rows: Array<Row<D>>;
|
405 | expandedDepth: number;
|
406 | isAllRowsExpanded: boolean;
|
407 | toggleRowExpanded: (id: Array<IdType<D>>, value?: boolean) => void;
|
408 | toggleAllRowsExpanded: (value?: boolean) => void;
|
409 | }
|
410 |
|
411 | export interface UseExpandedRowProps<D extends object> {
|
412 | isExpanded: boolean;
|
413 | canExpand: boolean;
|
414 | subRows: Array<Row<D>>;
|
415 | toggleRowExpanded: (value?: boolean) => void;
|
416 | getToggleRowExpandedProps: (props?: Partial<TableExpandedToggleProps>) => TableExpandedToggleProps;
|
417 | depth: number;
|
418 | }
|
419 |
|
420 |
|
421 |
|
422 |
|
423 | export function useFilters<D extends object = {}>(hooks: Hooks<D>): void;
|
424 |
|
425 | export namespace useFilters {
|
426 | const pluginName = "useFilters";
|
427 | }
|
428 |
|
429 | export type UseFiltersOptions<D extends object> = Partial<{
|
430 | manualFilters: boolean;
|
431 | disableFilters: boolean;
|
432 | defaultCanFilter: boolean;
|
433 | filterTypes: FilterTypes<D>;
|
434 | autoResetFilters?: boolean | undefined;
|
435 | }>;
|
436 |
|
437 | export interface UseFiltersState<D extends object> {
|
438 | filters: Filters<D>;
|
439 | }
|
440 |
|
441 | export type UseFiltersColumnOptions<D extends object> = Partial<{
|
442 | Filter: Renderer<FilterProps<D>>;
|
443 | disableFilters: boolean;
|
444 | defaultCanFilter: boolean;
|
445 | filter: FilterType<D> | DefaultFilterTypes | string;
|
446 | }>;
|
447 |
|
448 | export interface UseFiltersInstanceProps<D extends object> {
|
449 | preFilteredRows: Array<Row<D>>;
|
450 | preFilteredFlatRows: Array<Row<D>>;
|
451 | preFilteredRowsById: Record<string, Row<D>>;
|
452 | filteredRows: Array<Row<D>>;
|
453 | filteredFlatRows: Array<Row<D>>;
|
454 | filteredRowsById: Record<string, Row<D>>;
|
455 | rows: Array<Row<D>>;
|
456 | flatRows: Array<Row<D>>;
|
457 | rowsById: Record<string, Row<D>>;
|
458 | setFilter: (columnId: IdType<D>, updater: ((filterValue: FilterValue) => FilterValue) | FilterValue) => void;
|
459 | setAllFilters: (updater: Filters<D> | ((filters: Filters<D>) => Filters<D>)) => void;
|
460 | }
|
461 |
|
462 | export interface UseFiltersColumnProps<D extends object> {
|
463 | canFilter: boolean;
|
464 | setFilter: (updater: ((filterValue: FilterValue) => FilterValue) | FilterValue) => void;
|
465 | filterValue: FilterValue;
|
466 | preFilteredRows: Array<Row<D>>;
|
467 | filteredRows: Array<Row<D>>;
|
468 | }
|
469 |
|
470 | export type FilterProps<D extends object> = HeaderProps<D>;
|
471 | export type FilterValue = any;
|
472 | export type Filters<D extends object> = Array<{ id: IdType<D>; value: FilterValue }>;
|
473 | export type FilterTypes<D extends object> = Record<string, FilterType<D>>;
|
474 |
|
475 | export type DefaultFilterTypes =
|
476 | | "text"
|
477 | | "exactText"
|
478 | | "exactTextCase"
|
479 | | "includes"
|
480 | | "includesAll"
|
481 | | "exact"
|
482 | | "equals"
|
483 | | "between";
|
484 |
|
485 | export interface FilterType<D extends object> {
|
486 | (rows: Array<Row<D>>, columnIds: Array<IdType<D>>, filterValue: FilterValue): Array<Row<D>>;
|
487 |
|
488 | autoRemove?: ((filterValue: FilterValue) => boolean) | undefined;
|
489 | }
|
490 |
|
491 | // #endregion
|
492 |
|
493 | // #region useFlexLayout
|
494 | export function useFlexLayout<D extends object = {}>(hooks: Hooks<D>): void;
|
495 |
|
496 | export namespace useFlexLayout {
|
497 | const pluginName = "useFlexLayout";
|
498 | }
|
499 | // #endregion
|
500 |
|
501 | // #region useGridLayout
|
502 | export function useGridLayout<D extends object = {}>(hooks: Hooks<D>): void;
|
503 |
|
504 | export namespace useGridLayout {
|
505 | const pluginName = "useGridLayout";
|
506 | }
|
507 | // #endregion
|
508 |
|
509 | // #region useGlobalFilter
|
510 | export function useGlobalFilter<D extends object = {}>(hooks: Hooks<D>): void;
|
511 |
|
512 | export namespace useGlobalFilter {
|
513 | const pluginName = "useGlobalFilter";
|
514 | }
|
515 |
|
516 | export type UseGlobalFiltersOptions<D extends object> = Partial<{
|
517 | globalFilter: ((rows: Array<Row<D>>, columnIds: Array<IdType<D>>, filterValue: any) => Array<Row<D>>) | string;
|
518 | manualGlobalFilter: boolean;
|
519 | filterTypes: FilterTypes<D>;
|
520 | autoResetGlobalFilter?: boolean | undefined;
|
521 | disableGlobalFilter?: boolean | undefined;
|
522 | }>;
|
523 |
|
524 | export interface UseGlobalFiltersState<D extends object> {
|
525 | globalFilter: any;
|
526 | }
|
527 |
|
528 | export type UseGlobalFiltersColumnOptions<D extends object> = Partial<{
|
529 | disableGlobalFilter?: boolean | undefined;
|
530 | }>;
|
531 |
|
532 | export interface UseGlobalFiltersInstanceProps<D extends object> {
|
533 | preGlobalFilteredRows: Array<Row<D>>;
|
534 | preGlobalFilteredFlatRows: Array<Row<D>>;
|
535 | preGlobalFilteredRowsById: Record<string, Row<D>>;
|
536 | globalFilteredRows: Array<Row<D>>;
|
537 | globalFilteredFlatRows: Array<Row<D>>;
|
538 | globalFilteredRowsById: Record<string, Row<D>>;
|
539 | rows: Array<Row<D>>;
|
540 | flatRows: Array<Row<D>>;
|
541 | rowsById: Record<string, Row<D>>;
|
542 | setGlobalFilter: (filterValue: FilterValue) => void;
|
543 | }
|
544 |
|
545 |
|
546 |
|
547 |
|
548 | export function useGroupBy<D extends object = {}>(hooks: Hooks<D>): void;
|
549 |
|
550 | export namespace useGroupBy {
|
551 | const pluginName = "useGroupBy";
|
552 | }
|
553 |
|
554 | export interface TableGroupByToggleProps {
|
555 | title?: string | undefined;
|
556 | style?: CSSProperties | undefined;
|
557 | onClick?: ((e: MouseEvent) => void) | undefined;
|
558 | }
|
559 |
|
560 | export type UseGroupByOptions<D extends object> = Partial<{
|
561 | manualGroupBy: boolean;
|
562 | disableGroupBy: boolean;
|
563 | defaultCanGroupBy: boolean;
|
564 | aggregations: Record<string, AggregatorFn<D>>;
|
565 | groupByFn: (rows: Array<Row<D>>, columnId: IdType<D>) => Record<string, Array<Row<D>>>;
|
566 | autoResetGroupBy?: boolean | undefined;
|
567 | }>;
|
568 |
|
569 | export interface UseGroupByHooks<D extends object> {
|
570 | getGroupByToggleProps: Array<HeaderGroupPropGetter<D>>;
|
571 | }
|
572 |
|
573 | export interface UseGroupByState<D extends object> {
|
574 | groupBy: Array<IdType<D>>;
|
575 | }
|
576 |
|
577 | export type UseGroupByColumnOptions<D extends object> = Partial<{
|
578 | aggregate: Aggregator<D>;
|
579 | Aggregated: Renderer<CellProps<D>>;
|
580 | disableGroupBy: boolean;
|
581 | defaultCanGroupBy: boolean;
|
582 | }>;
|
583 |
|
584 | export interface UseGroupByInstanceProps<D extends object> {
|
585 | preGroupedRows: Array<Row<D>>;
|
586 | preGroupedFlatRows: Array<Row<D>>;
|
587 | preGroupedRowsById: Record<string, Row<D>>;
|
588 | groupedRows: Array<Row<D>>;
|
589 | groupedFlatRows: Array<Row<D>>;
|
590 | groupedRowsById: Record<string, Row<D>>;
|
591 | onlyGroupedFlatRows: Array<Row<D>>;
|
592 | onlyGroupedRowsById: Record<string, Row<D>>;
|
593 | nonGroupedFlatRows: Array<Row<D>>;
|
594 | nonGroupedRowsById: Record<string, Row<D>>;
|
595 | rows: Array<Row<D>>;
|
596 | flatRows: Array<Row<D>>;
|
597 | rowsById: Record<string, Row<D>>;
|
598 | toggleGroupBy: (columnId: IdType<D>, value?: boolean) => void;
|
599 | }
|
600 |
|
601 | export interface UseGroupByColumnProps<D extends object> {
|
602 | canGroupBy: boolean;
|
603 | isGrouped: boolean;
|
604 | groupedIndex: number;
|
605 | toggleGroupBy: () => void;
|
606 | getGroupByToggleProps: (props?: Partial<TableGroupByToggleProps>) => TableGroupByToggleProps;
|
607 | }
|
608 |
|
609 | export interface UseGroupByRowProps<D extends object> {
|
610 | isGrouped: boolean;
|
611 | groupByID: IdType<D>;
|
612 | groupByVal: string;
|
613 | values: Record<IdType<D>, AggregatedValue>;
|
614 | subRows: Array<Row<D>>;
|
615 | leafRows: Array<Row<D>>;
|
616 | depth: number;
|
617 | id: string;
|
618 | index: number;
|
619 | }
|
620 |
|
621 | export interface UseGroupByCellProps<D extends object> {
|
622 | isGrouped: boolean;
|
623 | isPlaceholder: boolean;
|
624 | isAggregated: boolean;
|
625 | }
|
626 |
|
627 | export type DefaultAggregators = "sum" | "average" | "median" | "uniqueCount" | "count";
|
628 |
|
629 | export type AggregatorFn<D extends object> = (
|
630 | columnValues: CellValue[],
|
631 | rows: Array<Row<D>>,
|
632 | isAggregated: boolean,
|
633 | ) => AggregatedValue;
|
634 | export type Aggregator<D extends object> = AggregatorFn<D> | DefaultAggregators | string;
|
635 | export type AggregatedValue = any;
|
636 |
|
637 |
|
638 |
|
639 | export function usePagination<D extends object = {}>(hooks: Hooks<D>): void;
|
640 |
|
641 | export namespace usePagination {
|
642 | const pluginName = "usePagination";
|
643 | }
|
644 |
|
645 | export type UsePaginationOptions<D extends object> = Partial<{
|
646 | pageCount: number;
|
647 | manualPagination: boolean;
|
648 | autoResetPage?: boolean | undefined;
|
649 | paginateExpandedRows: boolean;
|
650 | }>;
|
651 |
|
652 | export interface UsePaginationState<D extends object> {
|
653 | pageSize: number;
|
654 | pageIndex: number;
|
655 | }
|
656 |
|
657 | export interface UsePaginationInstanceProps<D extends object> {
|
658 | page: Array<Row<D>>;
|
659 | pageCount: number;
|
660 | pageOptions: number[];
|
661 | canPreviousPage: boolean;
|
662 | canNextPage: boolean;
|
663 | gotoPage: (updater: ((pageIndex: number) => number) | number) => void;
|
664 | previousPage: () => void;
|
665 | nextPage: () => void;
|
666 | setPageSize: (pageSize: number) => void;
|
667 | }
|
668 |
|
669 |
|
670 |
|
671 |
|
672 | export function useResizeColumns<D extends object = {}>(hooks: Hooks<D>): void;
|
673 |
|
674 | export namespace useResizeColumns {
|
675 | const pluginName = "useResizeColumns";
|
676 | }
|
677 |
|
678 | export interface UseResizeColumnsOptions<D extends object> {
|
679 | disableResizing?: boolean | undefined;
|
680 | autoResetResize?: boolean | undefined;
|
681 | }
|
682 |
|
683 | export interface UseResizeColumnsState<D extends object> {
|
684 | columnResizing: {
|
685 | startX?: number | undefined;
|
686 | columnWidth: number;
|
687 | headerIdWidths: Record<string, number>;
|
688 | columnWidths: any;
|
689 | isResizingColumn?: string | undefined;
|
690 | };
|
691 | }
|
692 |
|
693 | export interface UseResizeColumnsColumnOptions<D extends object> {
|
694 | disableResizing?: boolean | undefined;
|
695 | }
|
696 |
|
697 | export interface TableResizerProps {}
|
698 |
|
699 | export interface UseResizeColumnsColumnProps<D extends object> {
|
700 | getResizerProps: (props?: Partial<TableResizerProps>) => TableResizerProps;
|
701 | canResize: boolean;
|
702 | isResizing: boolean;
|
703 | }
|
704 |
|
705 |
|
706 |
|
707 |
|
708 | export function useRowSelect<D extends object = {}>(hooks: Hooks<D>): void;
|
709 |
|
710 | export namespace useRowSelect {
|
711 | const pluginName = "useRowSelect";
|
712 | }
|
713 |
|
714 | export interface TableToggleAllRowsSelectedProps extends TableToggleCommonProps {}
|
715 |
|
716 | export interface TableToggleRowsSelectedProps extends TableToggleCommonProps {}
|
717 |
|
718 | export type UseRowSelectOptions<D extends object> = Partial<{
|
719 | manualRowSelectedKey: IdType<D>;
|
720 | autoResetSelectedRows: boolean;
|
721 | selectSubRows: boolean;
|
722 | }>;
|
723 |
|
724 | export interface UseRowSelectHooks<D extends object> {
|
725 | getToggleRowSelectedProps: Array<PropGetter<D, TableToggleRowsSelectedProps>>;
|
726 | getToggleAllRowsSelectedProps: Array<PropGetter<D, TableToggleAllRowsSelectedProps>>;
|
727 | getToggleAllPageRowsSelectedProps: Array<PropGetter<D, TableToggleAllRowsSelectedProps>>;
|
728 | }
|
729 |
|
730 | export interface UseRowSelectState<D extends object> {
|
731 | selectedRowIds: Record<IdType<D>, boolean>;
|
732 | }
|
733 |
|
734 | export interface UseRowSelectInstanceProps<D extends object> {
|
735 | toggleRowSelected: (rowId: IdType<D>, set?: boolean) => void;
|
736 | toggleAllRowsSelected: (value?: boolean) => void;
|
737 | getToggleAllRowsSelectedProps: (
|
738 | props?: Partial<TableToggleAllRowsSelectedProps>,
|
739 | ) => TableToggleAllRowsSelectedProps;
|
740 | getToggleAllPageRowsSelectedProps: (
|
741 | props?: Partial<TableToggleAllRowsSelectedProps>,
|
742 | ) => TableToggleAllRowsSelectedProps;
|
743 | isAllRowsSelected: boolean;
|
744 | selectedFlatRows: Array<Row<D>>;
|
745 | }
|
746 |
|
747 | export interface UseRowSelectRowProps<D extends object> {
|
748 | isSelected: boolean;
|
749 | isSomeSelected: boolean;
|
750 | toggleRowSelected: (set?: boolean) => void;
|
751 | getToggleRowSelectedProps: (props?: Partial<TableToggleRowsSelectedProps>) => TableToggleRowsSelectedProps;
|
752 | }
|
753 |
|
754 |
|
755 |
|
756 |
|
757 | export function useRowState<D extends object = {}>(hooks: Hooks<D>): void;
|
758 |
|
759 | export namespace useRowState {
|
760 | const pluginName = "useRowState";
|
761 | }
|
762 |
|
763 | export type UseRowStateOptions<D extends object> = Partial<{
|
764 | initialRowStateAccessor: (row: Row<D>) => UseRowStateLocalState<D>;
|
765 | getResetRowStateDeps: (instance: TableInstance<D>) => any[];
|
766 | autoResetRowState?: boolean | undefined;
|
767 | }>;
|
768 |
|
769 | export interface UseRowStateState<D extends object> {
|
770 | rowState: Record<string, { cellState: UseRowStateLocalState<D> }>;
|
771 | }
|
772 |
|
773 | export interface UseRowStateInstanceProps<D extends object> {
|
774 | setRowState: (rowPath: string[], updater: UseRowUpdater) => void;
|
775 | setCellState: (rowPath: string[], columnId: IdType<D>, updater: UseRowUpdater) => void;
|
776 | }
|
777 |
|
778 | export interface UseRowStateRowProps<D extends object> {
|
779 | state: UseRowStateLocalState<D>;
|
780 | setState: (updater: UseRowUpdater) => void;
|
781 | }
|
782 |
|
783 | export interface UseRowStateCellProps<D extends object> {
|
784 | state: UseRowStateLocalState<D>;
|
785 | setState: (updater: UseRowUpdater) => void;
|
786 | }
|
787 |
|
788 | export type UseRowUpdater<T = unknown> = T | ((prev: T) => T);
|
789 | export type UseRowStateLocalState<D extends object, T = unknown> = Record<IdType<D>, T>;
|
790 | // #endregion
|
791 |
|
792 | // #region useSortBy
|
793 | export function useSortBy<D extends object = {}>(hooks: Hooks<D>): void;
|
794 |
|
795 | export namespace useSortBy {
|
796 | const pluginName = "useSortBy";
|
797 | }
|
798 |
|
799 | export interface TableSortByToggleProps {
|
800 | title?: string | undefined;
|
801 | style?: CSSProperties | undefined;
|
802 | onClick?: ((e: MouseEvent) => void) | undefined;
|
803 | }
|
804 |
|
805 | export type UseSortByOptions<D extends object> = Partial<{
|
806 | manualSortBy: boolean;
|
807 | disableSortBy: boolean;
|
808 | defaultCanSort: boolean;
|
809 | disableMultiSort: boolean;
|
810 | isMultiSortEvent: (e: MouseEvent) => boolean;
|
811 | maxMultiSortColCount: number;
|
812 | disableSortRemove: boolean;
|
813 | disabledMultiRemove: boolean;
|
814 | orderByFn: (rows: Array<Row<D>>, sortFns: Array<OrderByFn<D>>, directions: boolean[]) => Array<Row<D>>;
|
815 | sortTypes: Record<string, SortByFn<D>>;
|
816 | autoResetSortBy?: boolean | undefined;
|
817 | }>;
|
818 |
|
819 | export interface UseSortByHooks<D extends object> {
|
820 | getSortByToggleProps: Array<PropGetter<D, TableCommonProps>>;
|
821 | }
|
822 |
|
823 | export interface UseSortByState<D extends object> {
|
824 | sortBy: Array<SortingRule<D>>;
|
825 | }
|
826 |
|
827 | export type UseSortByColumnOptions<D extends object> = Partial<{
|
828 | defaultCanSort: boolean;
|
829 | disableSortBy: boolean;
|
830 | sortDescFirst: boolean;
|
831 | sortInverted: boolean;
|
832 | sortType: SortByFn<D> | DefaultSortTypes | string;
|
833 | }>;
|
834 |
|
835 | export interface UseSortByInstanceProps<D extends object> {
|
836 | rows: Array<Row<D>>;
|
837 | preSortedRows: Array<Row<D>>;
|
838 | setSortBy: (sortBy: Array<SortingRule<D>>) => void;
|
839 | toggleSortBy: (columnId: IdType<D>, descending?: boolean, isMulti?: boolean) => void;
|
840 | }
|
841 |
|
842 | export interface UseSortByColumnProps<D extends object> {
|
843 | canSort: boolean;
|
844 | toggleSortBy: (descending?: boolean, multi?: boolean) => void;
|
845 | getSortByToggleProps: (props?: Partial<TableSortByToggleProps>) => TableSortByToggleProps;
|
846 | clearSortBy: () => void;
|
847 | isSorted: boolean;
|
848 | sortedIndex: number;
|
849 | isSortedDesc: boolean | undefined;
|
850 | }
|
851 |
|
852 | export type OrderByFn<D extends object> = (rowA: Row<D>, rowB: Row<D>) => number;
|
853 | export type SortByFn<D extends object> = (rowA: Row<D>, rowB: Row<D>, columnId: IdType<D>, desc?: boolean) => number;
|
854 |
|
855 | export type DefaultSortTypes = "alphanumeric" | "datetime" | "basic" | "string" | "number";
|
856 |
|
857 | export interface SortingRule<D> {
|
858 | id: IdType<D>;
|
859 | desc?: boolean | undefined;
|
860 | }
|
861 |
|
862 |
|
863 |
|
864 |
|
865 | export const actions: Record<string, string>;
|
866 | export type ActionType = { type: string } & Record<string, any>;
|
867 | export const defaultColumn: Partial<Column> & Record<string, any>;
|
868 |
|
869 |
|
870 | export type StringKey<D> = Extract<keyof D, string>;
|
871 | export type IdType<D> = StringKey<D> | string;
|
872 | export type CellValue<V = any> = V;
|
873 |
|
874 | export type Renderer<Props> = ComponentType<Props> | ReactElement | string | number | readonly ReactNode[];
|
875 |
|
876 | export interface PluginHook<D extends object> {
|
877 | (hooks: Hooks<D>): void;
|
878 | pluginName?: string | undefined;
|
879 | }
|
880 |
|
881 | export type TableDispatch<A = any> = (action: A) => void;
|
882 |
|
883 |
|
884 | export function defaultOrderByFn<D extends object = {}>(
|
885 | arr: Array<Row<D>>,
|
886 | funcs: Array<OrderByFn<D>>,
|
887 | dirs: boolean[],
|
888 | ): Array<Row<D>>;
|
889 |
|
890 | export function defaultGroupByFn<D extends object = {}>(
|
891 | rows: Array<Row<D>>,
|
892 | columnId: IdType<D>,
|
893 | ): Record<string, Array<Row<D>>>;
|
894 |
|
895 | export function makePropGetter(hooks: Hooks, ...meta: any[]): any;
|
896 |
|
897 | export function reduceHooks<T extends object = {}>(hooks: Hooks, initial: T, ...args: any[]): T;
|
898 |
|
899 | export function loopHooks(hooks: Hooks, ...args: any[]): void;
|
900 |
|
901 | export function ensurePluginOrder<D extends object = {}>(
|
902 | plugins: Array<PluginHook<D>>,
|
903 | befores: string[],
|
904 | pluginName: string,
|
905 | ): void;
|
906 |
|
907 | export function functionalUpdate<D extends object = {}>(
|
908 | updater: any,
|
909 | old: Partial<TableState<D>>,
|
910 | ): Partial<TableState<D>>;
|
911 |
|
912 | export function useGetLatest<T>(obj: T): () => T;
|
913 |
|
914 | export function safeUseLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
|
915 |
|
916 | export function useMountedLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
|
917 |
|
918 | export function useAsyncDebounce<F extends (...args: any[]) => any>(defaultFn: F, defaultWait?: number): F;
|
919 |
|
920 | export function makeRenderer(instance: TableInstance, column: ColumnInstance, meta?: any): ReactElement;
|