@gridkitjs/react 0.7.0 → 0.8.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,7 +59,11 @@ 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. */
@@ -81,6 +85,17 @@ interface DataGridApi<Row> {
81
85
  getColumnSort(): ColumnSortState;
82
86
  getGroupBy(): GroupByState;
83
87
  getGroupExpansion(): GroupExpansionState;
88
+ /** The active page and page size. Meaningful even when `paginated` is off — it stays at page 0 over the grid's whole (single) page. */
89
+ getPagination(): PaginationState;
90
+ /** How many pages the current `pagination.pageSize` splits the grid's rows into — `1` whenever `paginated` is off. */
91
+ getPageCount(): number;
92
+ /**
93
+ * The grand-total aggregate results — every active aggregate computed over
94
+ * the whole filtered/sorted dataset, ungrouped and unpaginated. A specific
95
+ * group's own results are read off `getDisplayRows()` instead, on that
96
+ * group header's `aggregates` field.
97
+ */
98
+ getAggregates(): AggregateResults;
84
99
  getRowSelection(): SelectionState;
85
100
  getColumnSelection(): SelectionState;
86
101
  getCellSelection(): CellSelectionState;
@@ -96,10 +111,27 @@ interface DataGridApi<Row> {
96
111
  expandAllGroups(): void;
97
112
  /** 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
113
  collapseAllGroups(): void;
114
+ /** Moves to the given page, clamped into range. */
115
+ goToPage(pageIndex: number): void;
116
+ /** Moves to the next page. A no-op on the last page. */
117
+ nextPage(): void;
118
+ /** Moves to the previous page. A no-op on the first page. */
119
+ previousPage(): void;
120
+ /** Changes the page size, resetting to the first page. */
121
+ setPageSize(pageSize: number): void;
99
122
  /** Scrolls the row with the given id into view, if it is currently shown. */
100
123
  scrollToRow(rowId: string, options?: ScrollIntoViewOptions): void;
101
124
  /** Scrolls the column with the given id into view. */
102
125
  scrollToColumn(columnId: string, options?: ScrollIntoViewOptions): void;
126
+ /**
127
+ * Registers `listener` to be called after any render in which the grid's
128
+ * internal state may have changed — every getter above may return a
129
+ * different value once `listener` fires, not just one. Returns an
130
+ * unsubscribe function. The primitive the `use*State` hooks under
131
+ * `packages/react/src/DataGrid/hooks/` build on; most consumers should
132
+ * reach for one of those instead of calling `subscribe` directly.
133
+ */
134
+ subscribe(listener: () => void): () => void;
103
135
  }
104
136
  type Borders = "horizontal" | "vertical" | "all" | "none";
105
137
  /**
@@ -127,6 +159,40 @@ interface HoverableConfig {
127
159
  columns?: boolean;
128
160
  cells?: boolean;
129
161
  }
162
+ /**
163
+ * Everything a `pager.template` render prop needs to rebuild the built-in
164
+ * pager's UI itself. Passed fresh on every render where pagination-relevant
165
+ * state changed, so it's current by construction — unlike `DataGridApi`'s
166
+ * imperative methods and snapshot getters, which carry no "something
167
+ * changed, re-render" signal of their own.
168
+ */
169
+ interface PagerTemplateContext {
170
+ /** Same shape as `DataGridApi.getPagination()` — 0-based `pageIndex`. */
171
+ pagination: PaginationState;
172
+ /** `pagination.pageIndex + 1`, clamped — the display-ready page number. */
173
+ currentPage: number;
174
+ pageCount: number;
175
+ /** Passthrough of `pager.sizeOptions`, undefined when not given. */
176
+ pageSizeOptions: readonly number[] | undefined;
177
+ /** 0-based, same as `DataGridApi.goToPage` — not `currentPage`'s numbering. */
178
+ goToPage: (pageIndex: number) => void;
179
+ nextPage: () => void;
180
+ previousPage: () => void;
181
+ setPageSize: (pageSize: number) => void;
182
+ }
183
+ /** Presentation options for the grid's built-in pager. */
184
+ interface PagerConfig {
185
+ /** Page sizes offered by the built-in pager's page-size control. */
186
+ sizeOptions?: readonly number[] | undefined;
187
+ /** Defaults to `"compact"` — today's Prev/status/Next. */
188
+ variant?: "compact" | "numbered" | undefined;
189
+ /** Numbered variant only. How many pages to always show at each end. Defaults to 1. */
190
+ boundaryCount?: number | undefined;
191
+ /** Numbered variant only. How many pages to show on each side of the current page. Defaults to 1. */
192
+ siblingCount?: number | undefined;
193
+ /** Replaces the built-in pager entirely when given. `variant` is ignored. */
194
+ template?: ((context: PagerTemplateContext) => ReactNode) | undefined;
195
+ }
130
196
  interface DataGridProps<Row> extends SelectionCallbacks<Row> {
131
197
  columns?: readonly ColumnDefinition<Row>[] | undefined;
132
198
  dataSource?: readonly Row[] | undefined;
@@ -248,6 +314,41 @@ interface DataGridProps<Row> extends SelectionCallbacks<Row> {
248
314
  onGroupExpansionChange?: ((event: GroupExpansionEvent) => void) | undefined;
249
315
  /** The filter to start with — every applied entry, ANDed together. Uncontrolled. */
250
316
  defaultFilter?: FilterState<Row> | undefined;
317
+ /**
318
+ * Whether the grid's rows are split into pages. A page's unit is a
319
+ * top-level group or a bare data row, never a leaf row — a group is never
320
+ * split across a page boundary. Off by default, matching `sortableColumns`.
321
+ */
322
+ paginated?: boolean | undefined;
323
+ /**
324
+ * The page and page size to start on. Uncontrolled. Defaults to
325
+ * `{ pageIndex: 0, pageSize: 25 }` when `paginated` is on and this is
326
+ * omitted.
327
+ */
328
+ defaultPagination?: PaginationState | undefined;
329
+ /** Presentation options for the built-in pager. */
330
+ pager?: PagerConfig | undefined;
331
+ /** Called once when the user changes the page or the page size. */
332
+ onPaginationChange?: ((event: PaginationChangeEvent) => void) | undefined;
333
+ /**
334
+ * Aggregates to compute — a subtotal per group (rendered in that group's
335
+ * header) plus a grand total over the whole filtered/grouped dataset
336
+ * (rendered in a footer). Always computed over every row, never scoped to
337
+ * the current page. A plain controlled prop, unlike `sort`/`filter`/
338
+ * `groupBy`/`pagination`: there is no built-in UI for a user to add or
339
+ * remove an aggregate interactively, so there is no `defaultAggregates`/
340
+ * `onAggregatesChange` pair to go with it.
341
+ */
342
+ aggregates?: AggregateState<Row> | undefined;
343
+ /**
344
+ * Where a group's own aggregate results render. `"inline"` (the default)
345
+ * keeps them as text in the group header, next to its leaf-row count.
346
+ * `"row"` instead renders a dedicated row after that group's last visible
347
+ * entry, with each aggregate's value in the `<td>` for its own column —
348
+ * the same alignment the grand-total footer's own cells have. Has no
349
+ * effect when `aggregates` is empty or omitted.
350
+ */
351
+ groupAggregateDisplay?: GroupAggregateDisplay | undefined;
251
352
  /**
252
353
  * The grid's accessible name, announced when it takes focus. A grid without
253
354
  * one is read only as "grid", which says nothing about which grid.
@@ -261,6 +362,112 @@ interface DataGridProps<Row> extends SelectionCallbacks<Row> {
261
362
  /** Imperative handle for reading live grid state and triggering actions. */
262
363
  ref?: Ref<DataGridApi<Row>> | undefined;
263
364
  }
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;
365
+ 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, aggregates, groupAggregateDisplay, label, labelledBy, ref, ...callbacks }: DataGridProps<Row>): react.JSX.Element;
366
+
367
+ interface PaginationStateApi {
368
+ pagination: PaginationState;
369
+ pageCount: number;
370
+ goToPage: (pageIndex: number) => void;
371
+ nextPage: () => void;
372
+ previousPage: () => void;
373
+ setPageSize: (pageSize: number) => void;
374
+ }
375
+ /**
376
+ * Reactive pagination state read off a mounted `DataGridComponent`'s `ref`,
377
+ * for building a pager entirely outside the grid's own DOM — a toolbar or
378
+ * sidebar `pager.template` can't reach. Updates on every pagination change,
379
+ * including the silent page-0 reset a filter/sort/group change triggers,
380
+ * which carries no `onPaginationChange` of its own.
381
+ *
382
+ * Before the grid mounts, `pagination` reads `{ pageIndex: 0, pageSize: 0 }`
383
+ * and `pageCount` reads `0`; the actions are no-ops until then.
384
+ */
385
+ declare function usePaginationState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): PaginationStateApi;
386
+
387
+ interface GroupByStateApi {
388
+ groupBy: GroupByState;
389
+ groupExpansion: GroupExpansionState;
390
+ expandAllGroups: () => void;
391
+ collapseAllGroups: () => void;
392
+ }
393
+ /**
394
+ * Reactive group-by and group-expansion state read off a mounted
395
+ * `DataGridComponent`'s `ref`, for a group-by bar or summary sidebar living
396
+ * outside the grid's own DOM.
397
+ *
398
+ * `DataGridApi` has no per-group toggle action today, only
399
+ * `expandAllGroups`/`collapseAllGroups` — a custom group-by UI needing to
400
+ * toggle a single group has no imperative action to call yet. A specific
401
+ * group's own computed aggregates are read off `getDisplayRows()`'s
402
+ * per-header `aggregates` field instead of a getter here — see
403
+ * `useAggregateState` for the grand-total equivalent.
404
+ *
405
+ * Before the grid mounts, both fields read as empty and the actions are
406
+ * no-ops.
407
+ */
408
+ declare function useGroupByState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): GroupByStateApi;
409
+
410
+ /**
411
+ * Reactive column-sort state read off a mounted `DataGridComponent`'s `ref`,
412
+ * for a sort indicator living outside the grid's own DOM.
413
+ *
414
+ * `DataGridApi` has no sort-mutating action today — sort stays uncontrolled
415
+ * via `defaultColumnSort`/the grid's own header UI, the same gap
416
+ * `useGroupByState` has for group-by. Reads only.
417
+ *
418
+ * Before the grid mounts, reads as an empty array.
419
+ */
420
+ declare function useColumnSortState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): ColumnSortState;
421
+
422
+ interface SelectionStateApi {
423
+ rowSelection: SelectionState;
424
+ columnSelection: SelectionState;
425
+ cellSelection: CellSelectionState;
426
+ clearSelection: () => void;
427
+ selectAllRows: () => void;
428
+ }
429
+ /**
430
+ * Reactive row/column/cell selection state read off a mounted
431
+ * `DataGridComponent`'s `ref`, for a "N rows selected" toolbar living
432
+ * outside the grid's own DOM. One combined hook rather than three, matching
433
+ * how `useGridSelection` already treats all three as one concern
434
+ * internally.
435
+ *
436
+ * Before the grid mounts, the row/column fields read as empty arrays and
437
+ * the cell field reads `null`; the actions are no-ops.
438
+ */
439
+ declare function useSelectionState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): SelectionStateApi;
440
+
441
+ /**
442
+ * Reactive grand-total aggregate results read off a mounted
443
+ * `DataGridComponent`'s `ref`, for a summary footer or bar living outside
444
+ * the grid's own DOM — mirroring the built-in one the grid renders itself.
445
+ *
446
+ * Read-only: `getAggregates` is already read-only on `DataGridApi`, computed
447
+ * over the whole filtered/sorted dataset rather than driven by any action.
448
+ * A specific group's own subtotal is read off `getDisplayRows()`'s
449
+ * per-header `aggregates` field instead — see `useGroupByState`.
450
+ *
451
+ * Before the grid mounts, reads as an empty map.
452
+ */
453
+ declare function useAggregateState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): AggregateResults;
454
+
455
+ /**
456
+ * Reactive column-sizing state read off a mounted `DataGridComponent`'s
457
+ * `ref`. Read-only — sizing stays uncontrolled via `defaultColumnSizing`/the
458
+ * grid's own resize handles, the same gap `useColumnSortState` has for sort.
459
+ *
460
+ * Before the grid mounts, reads as an empty object.
461
+ */
462
+ declare function useColumnSizingState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): ColumnSizingState;
463
+
464
+ /**
465
+ * Reactive column-order state read off a mounted `DataGridComponent`'s
466
+ * `ref`. Read-only — order stays uncontrolled via `defaultColumnOrder`/the
467
+ * grid's own header drag, the same gap `useColumnSortState` has for sort.
468
+ *
469
+ * Before the grid mounts, reads as an empty array.
470
+ */
471
+ declare function useColumnOrderState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): ColumnOrderState;
265
472
 
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 };
473
+ 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 PagerConfig, type PagerTemplateContext, type PaginationStateApi, type ResizeMode, type ResolvedColumn, type SelectedCell, type SelectedColumn, type SelectionStateApi, useAggregateState, useColumnOrderState, useColumnSizingState, useColumnSortState, useGroupByState, usePaginationState, useSelectionState };