@gridkitjs/react 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
- import { ReactNode, Ref } from 'react';
3
- import { RowSelectEvent, RowsSelectEvent, RowSelectionChangeEvent, CellSelectEvent as CellSelectEvent$1, CellSelectionChangeEvent as CellSelectionChangeEvent$1, ColumnDefinition as ColumnDefinition$1, ColumnSelectEvent as ColumnSelectEvent$1, ColumnSelectionChangeEvent as ColumnSelectionChangeEvent$1, ColumnsSelectEvent as ColumnsSelectEvent$1, ResolvedRow, DisplayRow, ResolvedColumn as ResolvedColumn$1, ColumnSizingState, ColumnOrderState, ColumnSortState, GroupByState, GroupExpansionState, SelectionState, CellSelectionState, SelectableConfig, ColumnSizeDefaults, ColumnResizeEvent, ColumnOrderEvent, ColumnSortEvent, GroupByEvent, GroupExpansionEvent, FilterState, SelectedCell as SelectedCell$1, SelectedColumn as SelectedColumn$1 } from '@gridkitjs/core';
2
+ import { ReactNode, Ref, RefObject } from 'react';
3
+ import { RowSelectEvent, RowsSelectEvent, RowSelectionChangeEvent, CellSelectEvent as CellSelectEvent$1, CellSelectionChangeEvent as CellSelectionChangeEvent$1, ColumnDefinition as ColumnDefinition$1, ColumnSelectEvent as ColumnSelectEvent$1, ColumnSelectionChangeEvent as ColumnSelectionChangeEvent$1, ColumnsSelectEvent as ColumnsSelectEvent$1, ResolvedRow, DisplayRow, ResolvedColumn as ResolvedColumn$1, ColumnSizingState, ColumnOrderState, ColumnSortState, GroupByState, GroupExpansionState, PaginationState, AggregateResults, SelectionState, CellSelectionState, SelectableConfig, ColumnSizeDefaults, ColumnResizeEvent, ColumnOrderEvent, ColumnSortEvent, GroupByEvent, GroupExpansionEvent, FilterState, PaginationChangeEvent, AggregateState, GroupAggregateDisplay, SelectedCell as SelectedCell$1, SelectedColumn as SelectedColumn$1 } from '@gridkitjs/core';
4
4
  export { CellSelectionMode, CellSelectionState, CellTemplateContext, ColumnResizeEvent, ColumnSizeDefaults, ColumnSizingState, ResolvedRow, RowSelectEvent, RowSelectionChangeEvent, RowsSelectEvent, SelectableConfig, SelectedCellRef, SelectionMode, SelectionState } from '@gridkitjs/core';
5
5
 
6
6
  /**
@@ -59,12 +59,21 @@ type CellSelectionChangeEvent<Row> = CellSelectionChangeEvent$1<Row, ReactNode>;
59
59
  * and the actions are the ones every grid ref carries (focus, clear/select
60
60
  * all, scroll-to). Sizing, order, sort, and selection stay uncontrolled via
61
61
  * their existing `default*` props — this is not a second, imperative-only
62
- * way to drive that same state.
62
+ * way to drive that same state. `subscribe` doesn't change that: it's a
63
+ * read/notify channel for reacting to state that already lives here, not a
64
+ * write path — nothing becomes newly *driven* through the ref by its
65
+ * existence. See `packages/react/src/DataGrid/hooks/` for the public hooks
66
+ * built on it.
63
67
  */
64
68
  interface DataGridApi<Row> {
65
69
  /** The grid's scrollable viewport element. */
66
70
  readonly element: HTMLDivElement | null;
67
- /** The grid's `<table>` element. */
71
+ /**
72
+ * The grid's row-area `<table>` element — the one holding `<tbody>`. The
73
+ * header and, when aggregates are active, footer render as their own
74
+ * sibling `<table>`s outside this one; use `element` to reach the whole
75
+ * scrollable viewport instead.
76
+ */
68
77
  readonly table: HTMLTableElement | null;
69
78
  /** Rows as currently filtered and sorted — what's rendered, ungrouped. */
70
79
  getRows(): readonly ResolvedRow<Row>[];
@@ -81,6 +90,17 @@ interface DataGridApi<Row> {
81
90
  getColumnSort(): ColumnSortState;
82
91
  getGroupBy(): GroupByState;
83
92
  getGroupExpansion(): GroupExpansionState;
93
+ /** The active page and page size. Meaningful even when `paginated` is off — it stays at page 0 over the grid's whole (single) page. */
94
+ getPagination(): PaginationState;
95
+ /** How many pages the current `pagination.pageSize` splits the grid's rows into — `1` whenever `paginated` is off. */
96
+ getPageCount(): number;
97
+ /**
98
+ * The grand-total aggregate results — every active aggregate computed over
99
+ * the whole filtered/sorted dataset, ungrouped and unpaginated. A specific
100
+ * group's own results are read off `getDisplayRows()` instead, on that
101
+ * group header's `aggregates` field.
102
+ */
103
+ getAggregates(): AggregateResults;
84
104
  getRowSelection(): SelectionState;
85
105
  getColumnSelection(): SelectionState;
86
106
  getCellSelection(): CellSelectionState;
@@ -96,10 +116,27 @@ interface DataGridApi<Row> {
96
116
  expandAllGroups(): void;
97
117
  /** Collapses every group currently shown at once — see `collapseAllGroups` in `@gridkitjs/core` for what "currently shown" means for a group already nested under a collapsed one. */
98
118
  collapseAllGroups(): void;
119
+ /** Moves to the given page, clamped into range. */
120
+ goToPage(pageIndex: number): void;
121
+ /** Moves to the next page. A no-op on the last page. */
122
+ nextPage(): void;
123
+ /** Moves to the previous page. A no-op on the first page. */
124
+ previousPage(): void;
125
+ /** Changes the page size, resetting to the first page. */
126
+ setPageSize(pageSize: number): void;
99
127
  /** Scrolls the row with the given id into view, if it is currently shown. */
100
128
  scrollToRow(rowId: string, options?: ScrollIntoViewOptions): void;
101
129
  /** Scrolls the column with the given id into view. */
102
130
  scrollToColumn(columnId: string, options?: ScrollIntoViewOptions): void;
131
+ /**
132
+ * Registers `listener` to be called after any render in which the grid's
133
+ * internal state may have changed — every getter above may return a
134
+ * different value once `listener` fires, not just one. Returns an
135
+ * unsubscribe function. The primitive the `use*State` hooks under
136
+ * `packages/react/src/DataGrid/hooks/` build on; most consumers should
137
+ * reach for one of those instead of calling `subscribe` directly.
138
+ */
139
+ subscribe(listener: () => void): () => void;
103
140
  }
104
141
  type Borders = "horizontal" | "vertical" | "all" | "none";
105
142
  /**
@@ -127,6 +164,65 @@ interface HoverableConfig {
127
164
  columns?: boolean;
128
165
  cells?: boolean;
129
166
  }
167
+ /**
168
+ * Everything a `pager.template` render prop needs to rebuild the built-in
169
+ * pager's UI itself. Passed fresh on every render where pagination-relevant
170
+ * state changed, so it's current by construction — unlike `DataGridApi`'s
171
+ * imperative methods and snapshot getters, which carry no "something
172
+ * changed, re-render" signal of their own.
173
+ */
174
+ interface PagerTemplateContext {
175
+ /** Same shape as `DataGridApi.getPagination()` — 0-based `pageIndex`. */
176
+ pagination: PaginationState;
177
+ /** `pagination.pageIndex + 1`, clamped — the display-ready page number. */
178
+ currentPage: number;
179
+ pageCount: number;
180
+ /** Passthrough of `pager.sizeOptions`, undefined when not given. */
181
+ pageSizeOptions: readonly number[] | undefined;
182
+ /** 0-based, same as `DataGridApi.goToPage` — not `currentPage`'s numbering. */
183
+ goToPage: (pageIndex: number) => void;
184
+ nextPage: () => void;
185
+ previousPage: () => void;
186
+ setPageSize: (pageSize: number) => void;
187
+ }
188
+ /** Presentation options for the grid's built-in pager. */
189
+ interface PagerConfig {
190
+ /** Page sizes offered by the built-in pager's page-size control. */
191
+ sizeOptions?: readonly number[] | undefined;
192
+ /** Defaults to `"compact"` — today's Prev/status/Next. */
193
+ variant?: "compact" | "numbered" | undefined;
194
+ /** Numbered variant only. How many pages to always show at each end. Defaults to 1. */
195
+ boundaryCount?: number | undefined;
196
+ /** Numbered variant only. How many pages to show on each side of the current page. Defaults to 1. */
197
+ siblingCount?: number | undefined;
198
+ /** Replaces the built-in pager entirely when given. `variant` is ignored. */
199
+ template?: ((context: PagerTemplateContext) => ReactNode) | undefined;
200
+ }
201
+ /**
202
+ * Loads more rows as the user scrolls near the bottom, in place of paging.
203
+ * Appends only — there is no equivalent of `paginated`'s reset-to-page-0 for
204
+ * a result set that shrinks out from under the current position.
205
+ */
206
+ interface InfiniteScrollConfig {
207
+ /** Whether a further `onLoadMore` could still return more rows. `false` removes the sentinel entirely, so no further scrolling can trigger a load. */
208
+ readonly hasMore: boolean;
209
+ /**
210
+ * Called at most once per genuine threshold-crossing: fires when the
211
+ * sentinel comes within `rootMargin` of the body's viewport, and not again
212
+ * until `isLoadingMore` has gone back to `false`.
213
+ */
214
+ readonly onLoadMore: () => void;
215
+ /** Whether a load triggered by `onLoadMore` is still in flight. Suppresses further calls to it until this goes back to `false`. */
216
+ readonly isLoadingMore?: boolean | undefined;
217
+ /**
218
+ * `IntersectionObserver`'s `rootMargin` — how far from the bottom of the
219
+ * scrollable body `onLoadMore` fires, ahead of the sentinel actually
220
+ * scrolling into view. Defaults to `"200px"`.
221
+ */
222
+ readonly rootMargin?: string | undefined;
223
+ /** Replaces the built-in "Loading more…" row. */
224
+ readonly loadingTemplate?: (() => ReactNode) | undefined;
225
+ }
130
226
  interface DataGridProps<Row> extends SelectionCallbacks<Row> {
131
227
  columns?: readonly ColumnDefinition<Row>[] | undefined;
132
228
  dataSource?: readonly Row[] | undefined;
@@ -248,6 +344,78 @@ interface DataGridProps<Row> extends SelectionCallbacks<Row> {
248
344
  onGroupExpansionChange?: ((event: GroupExpansionEvent) => void) | undefined;
249
345
  /** The filter to start with — every applied entry, ANDed together. Uncontrolled. */
250
346
  defaultFilter?: FilterState<Row> | undefined;
347
+ /**
348
+ * Whether the grid's rows are split into pages. A page's unit is a
349
+ * top-level group or a bare data row, never a leaf row — a group is never
350
+ * split across a page boundary. Off by default, matching `sortableColumns`.
351
+ */
352
+ paginated?: boolean | undefined;
353
+ /**
354
+ * The page and page size to start on. Uncontrolled. Defaults to
355
+ * `{ pageIndex: 0, pageSize: 25 }` when `paginated` is on and this is
356
+ * omitted.
357
+ */
358
+ defaultPagination?: PaginationState | undefined;
359
+ /** Presentation options for the built-in pager. */
360
+ pager?: PagerConfig | undefined;
361
+ /** Called once when the user changes the page or the page size. */
362
+ onPaginationChange?: ((event: PaginationChangeEvent) => void) | undefined;
363
+ /**
364
+ * Loads more rows as the user scrolls near the bottom, instead of paging.
365
+ * Mutually exclusive with `paginated` — setting both logs a dev-time
366
+ * `console.error` and only `paginated` takes effect. Recommended (not
367
+ * required) alongside `virtualized` for a dataset that grows without
368
+ * bound, so the mounted row count never grows with it either.
369
+ */
370
+ infiniteScroll?: InfiniteScrollConfig | undefined;
371
+ /**
372
+ * Aggregates to compute — a subtotal per group (rendered in that group's
373
+ * header) plus a grand total over the whole filtered/grouped dataset
374
+ * (rendered in a footer). Always computed over every row, never scoped to
375
+ * the current page. A plain controlled prop, unlike `sort`/`filter`/
376
+ * `groupBy`/`pagination`: there is no built-in UI for a user to add or
377
+ * remove an aggregate interactively, so there is no `defaultAggregates`/
378
+ * `onAggregatesChange` pair to go with it.
379
+ */
380
+ aggregates?: AggregateState<Row> | undefined;
381
+ /**
382
+ * Where a group's own aggregate results render. `"inline"` (the default)
383
+ * keeps them as text in the group header, next to its leaf-row count.
384
+ * `"row"` instead renders a dedicated row after that group's last visible
385
+ * entry, with each aggregate's value in the `<td>` for its own column —
386
+ * the same alignment the grand-total footer's own cells have. Has no
387
+ * effect when `aggregates` is empty or omitted.
388
+ */
389
+ groupAggregateDisplay?: GroupAggregateDisplay | undefined;
390
+ /**
391
+ * Bounds the row area's height, independently scrollable — the grid's own
392
+ * chrome (group-by bar, header, footer, pager) stays outside it and
393
+ * always visible. A number is pixels; a string is passed through as a CSS
394
+ * length (e.g. "60vh"). Omitted, the body's height stays content-driven,
395
+ * same as today.
396
+ */
397
+ height?: number | string | undefined;
398
+ /**
399
+ * Renders only the rows near the current scroll position rather than every
400
+ * row at once — for a dataset too large to mount in full. Requires
401
+ * `height` to be set; a grid without a bounded body has no viewport to
402
+ * window rows against (a dev-time console warning fires when it's
403
+ * missing). Off by default, matching every other opt-in behavior here.
404
+ */
405
+ virtualized?: boolean | undefined;
406
+ /**
407
+ * Rows rendered outside the visible range on each side, to reduce
408
+ * blank-frame flashes on fast scrolling. Only meaningful with `virtualized`
409
+ * on.
410
+ */
411
+ overscan?: number | undefined;
412
+ /**
413
+ * Assumed height for a row never yet measured — only matters for the very
414
+ * first paint and for `scrollToRow`'s initial jump before it corrects
415
+ * itself against that row's real, measured height. Only meaningful with
416
+ * `virtualized` on.
417
+ */
418
+ estimatedRowHeight?: number | undefined;
251
419
  /**
252
420
  * The grid's accessible name, announced when it takes focus. A grid without
253
421
  * one is read only as "grid", which says nothing about which grid.
@@ -261,6 +429,112 @@ interface DataGridProps<Row> extends SelectionCallbacks<Row> {
261
429
  /** Imperative handle for reading live grid state and triggering actions. */
262
430
  ref?: Ref<DataGridApi<Row>> | undefined;
263
431
  }
264
- declare function DataGridComponent<Row>({ dataSource, columns, getRowId, borders, hoverable, selectable, defaultRowSelection, defaultColumnSelection, defaultCellSelection, resizableColumns, reorderableColumns, resizeMode, defaultColumnSizing, defaultColumnOrder, columnSizeDefaults, onColumnResize, onColumnOrderChange, sortableColumns, defaultColumnSort, onColumnSortChange, groupableColumns, groupToggleIconColumns, groupByDraggableColumns, groupByBarVisibility, defaultGroupBy, onGroupByChange, defaultGroupExpansion, onGroupExpansionChange, defaultFilter, label, labelledBy, ref, ...callbacks }: DataGridProps<Row>): react.JSX.Element;
432
+ declare function DataGridComponent<Row>({ dataSource, columns, getRowId, borders, hoverable, selectable, defaultRowSelection, defaultColumnSelection, defaultCellSelection, resizableColumns, reorderableColumns, resizeMode, defaultColumnSizing, defaultColumnOrder, columnSizeDefaults, onColumnResize, onColumnOrderChange, sortableColumns, defaultColumnSort, onColumnSortChange, groupableColumns, groupToggleIconColumns, groupByDraggableColumns, groupByBarVisibility, defaultGroupBy, onGroupByChange, defaultGroupExpansion, onGroupExpansionChange, defaultFilter, paginated, defaultPagination, pager, onPaginationChange, infiniteScroll, aggregates, groupAggregateDisplay, height, virtualized, overscan, estimatedRowHeight, label, labelledBy, ref, ...callbacks }: DataGridProps<Row>): react.JSX.Element;
433
+
434
+ interface PaginationStateApi {
435
+ pagination: PaginationState;
436
+ pageCount: number;
437
+ goToPage: (pageIndex: number) => void;
438
+ nextPage: () => void;
439
+ previousPage: () => void;
440
+ setPageSize: (pageSize: number) => void;
441
+ }
442
+ /**
443
+ * Reactive pagination state read off a mounted `DataGridComponent`'s `ref`,
444
+ * for building a pager entirely outside the grid's own DOM — a toolbar or
445
+ * sidebar `pager.template` can't reach. Updates on every pagination change,
446
+ * including the silent page-0 reset a filter/sort/group change triggers,
447
+ * which carries no `onPaginationChange` of its own.
448
+ *
449
+ * Before the grid mounts, `pagination` reads `{ pageIndex: 0, pageSize: 0 }`
450
+ * and `pageCount` reads `0`; the actions are no-ops until then.
451
+ */
452
+ declare function usePaginationState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): PaginationStateApi;
453
+
454
+ interface GroupByStateApi {
455
+ groupBy: GroupByState;
456
+ groupExpansion: GroupExpansionState;
457
+ expandAllGroups: () => void;
458
+ collapseAllGroups: () => void;
459
+ }
460
+ /**
461
+ * Reactive group-by and group-expansion state read off a mounted
462
+ * `DataGridComponent`'s `ref`, for a group-by bar or summary sidebar living
463
+ * outside the grid's own DOM.
464
+ *
465
+ * `DataGridApi` has no per-group toggle action today, only
466
+ * `expandAllGroups`/`collapseAllGroups` — a custom group-by UI needing to
467
+ * toggle a single group has no imperative action to call yet. A specific
468
+ * group's own computed aggregates are read off `getDisplayRows()`'s
469
+ * per-header `aggregates` field instead of a getter here — see
470
+ * `useAggregateState` for the grand-total equivalent.
471
+ *
472
+ * Before the grid mounts, both fields read as empty and the actions are
473
+ * no-ops.
474
+ */
475
+ declare function useGroupByState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): GroupByStateApi;
476
+
477
+ /**
478
+ * Reactive column-sort state read off a mounted `DataGridComponent`'s `ref`,
479
+ * for a sort indicator living outside the grid's own DOM.
480
+ *
481
+ * `DataGridApi` has no sort-mutating action today — sort stays uncontrolled
482
+ * via `defaultColumnSort`/the grid's own header UI, the same gap
483
+ * `useGroupByState` has for group-by. Reads only.
484
+ *
485
+ * Before the grid mounts, reads as an empty array.
486
+ */
487
+ declare function useColumnSortState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): ColumnSortState;
488
+
489
+ interface SelectionStateApi {
490
+ rowSelection: SelectionState;
491
+ columnSelection: SelectionState;
492
+ cellSelection: CellSelectionState;
493
+ clearSelection: () => void;
494
+ selectAllRows: () => void;
495
+ }
496
+ /**
497
+ * Reactive row/column/cell selection state read off a mounted
498
+ * `DataGridComponent`'s `ref`, for a "N rows selected" toolbar living
499
+ * outside the grid's own DOM. One combined hook rather than three, matching
500
+ * how `useGridSelection` already treats all three as one concern
501
+ * internally.
502
+ *
503
+ * Before the grid mounts, the row/column fields read as empty arrays and
504
+ * the cell field reads `null`; the actions are no-ops.
505
+ */
506
+ declare function useSelectionState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): SelectionStateApi;
507
+
508
+ /**
509
+ * Reactive grand-total aggregate results read off a mounted
510
+ * `DataGridComponent`'s `ref`, for a summary footer or bar living outside
511
+ * the grid's own DOM — mirroring the built-in one the grid renders itself.
512
+ *
513
+ * Read-only: `getAggregates` is already read-only on `DataGridApi`, computed
514
+ * over the whole filtered/sorted dataset rather than driven by any action.
515
+ * A specific group's own subtotal is read off `getDisplayRows()`'s
516
+ * per-header `aggregates` field instead — see `useGroupByState`.
517
+ *
518
+ * Before the grid mounts, reads as an empty map.
519
+ */
520
+ declare function useAggregateState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): AggregateResults;
521
+
522
+ /**
523
+ * Reactive column-sizing state read off a mounted `DataGridComponent`'s
524
+ * `ref`. Read-only — sizing stays uncontrolled via `defaultColumnSizing`/the
525
+ * grid's own resize handles, the same gap `useColumnSortState` has for sort.
526
+ *
527
+ * Before the grid mounts, reads as an empty object.
528
+ */
529
+ declare function useColumnSizingState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): ColumnSizingState;
530
+
531
+ /**
532
+ * Reactive column-order state read off a mounted `DataGridComponent`'s
533
+ * `ref`. Read-only — order stays uncontrolled via `defaultColumnOrder`/the
534
+ * grid's own header drag, the same gap `useColumnSortState` has for sort.
535
+ *
536
+ * Before the grid mounts, reads as an empty array.
537
+ */
538
+ declare function useColumnOrderState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): ColumnOrderState;
265
539
 
266
- export { type Borders, type CellSelectEvent, type CellSelectionChangeEvent, type ColumnDefinition, type ColumnSelectEvent, type ColumnSelectionChangeEvent, type ColumnsSelectEvent, type DataGridApi, DataGridComponent, type DataGridProps, type GroupByBarVisibility, type HoverableConfig, type ResizeMode, type ResolvedColumn, type SelectedCell, type SelectedColumn };
540
+ export { type Borders, type CellSelectEvent, type CellSelectionChangeEvent, type ColumnDefinition, type ColumnSelectEvent, type ColumnSelectionChangeEvent, type ColumnsSelectEvent, type DataGridApi, DataGridComponent, type DataGridProps, type GroupByBarVisibility, type GroupByStateApi, type HoverableConfig, type InfiniteScrollConfig, type PagerConfig, type PagerTemplateContext, type PaginationStateApi, type ResizeMode, type ResolvedColumn, type SelectedCell, type SelectedColumn, type SelectionStateApi, useAggregateState, useColumnOrderState, useColumnSizingState, useColumnSortState, useGroupByState, usePaginationState, useSelectionState };