@gridkitjs/react 0.6.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, ResolvedColumn as ResolvedColumn$1, ColumnSizingState, ColumnOrderState, ColumnSortState, SelectionState, CellSelectionState, SelectableConfig, ColumnSizeDefaults, ColumnResizeEvent, ColumnOrderEvent, ColumnSortEvent, 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,20 +59,43 @@ 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
71
  /** The grid's `<table>` element. */
68
72
  readonly table: HTMLTableElement | null;
69
- /** Rows as currently filtered and sorted — what's rendered. */
73
+ /** Rows as currently filtered and sorted — what's rendered, ungrouped. */
70
74
  getRows(): readonly ResolvedRow<Row>[];
75
+ /**
76
+ * `getRows()` regrouped into the active `groupBy` — group headers
77
+ * interleaved with data rows, in render order. Identical to `getRows()`
78
+ * when `groupBy` is empty.
79
+ */
80
+ getDisplayRows(): readonly DisplayRow<Row>[];
71
81
  /** Columns as currently sized and ordered — what's rendered. */
72
82
  getColumns(): readonly ResolvedColumn<Row>[];
73
83
  getColumnSizing(): ColumnSizingState;
74
84
  getColumnOrder(): ColumnOrderState;
75
85
  getColumnSort(): ColumnSortState;
86
+ getGroupBy(): GroupByState;
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;
76
99
  getRowSelection(): SelectionState;
77
100
  getColumnSelection(): SelectionState;
78
101
  getCellSelection(): CellSelectionState;
@@ -84,10 +107,31 @@ interface DataGridApi<Row> {
84
107
  focusCell(rowIndex: number, columnIndex: number): void;
85
108
  clearSelection(): void;
86
109
  selectAllRows(): void;
110
+ /** Expands every group at once — there is no dedicated UI control for it. */
111
+ expandAllGroups(): void;
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. */
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;
87
122
  /** Scrolls the row with the given id into view, if it is currently shown. */
88
123
  scrollToRow(rowId: string, options?: ScrollIntoViewOptions): void;
89
124
  /** Scrolls the column with the given id into view. */
90
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;
91
135
  }
92
136
  type Borders = "horizontal" | "vertical" | "all" | "none";
93
137
  /**
@@ -99,11 +143,56 @@ type Borders = "horizontal" | "vertical" | "all" | "none";
99
143
  * nothing else, and the grid scrolls or leaves a gap accordingly.
100
144
  */
101
145
  type ResizeMode = "fit" | "fixed";
146
+ /**
147
+ * How the group-by bar's visibility follows the active grouping. `"always"`
148
+ * renders it even with an empty `groupBy` — a fixed drop target and a
149
+ * constant reminder grouping exists. `"never"` never renders it, for a grid
150
+ * driving `groupBy` entirely by its own UI (a header toggle, `Alt+ArrowDown`)
151
+ * or programmatically. `"auto"` renders it once `groupBy` is non-empty, or
152
+ * while a header drag eligible to drop into it is in progress — so there is
153
+ * always somewhere to drop the very first column, even from a fully empty
154
+ * grouping.
155
+ */
156
+ type GroupByBarVisibility = "always" | "auto" | "never";
102
157
  interface HoverableConfig {
103
158
  rows?: boolean;
104
159
  columns?: boolean;
105
160
  cells?: boolean;
106
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
+ }
107
196
  interface DataGridProps<Row> extends SelectionCallbacks<Row> {
108
197
  columns?: readonly ColumnDefinition<Row>[] | undefined;
109
198
  dataSource?: readonly Row[] | undefined;
@@ -187,8 +276,79 @@ interface DataGridProps<Row> extends SelectionCallbacks<Row> {
187
276
  * clear back to "none".
188
277
  */
189
278
  onColumnSortChange?: ((event: ColumnSortEvent) => void) | undefined;
279
+ /**
280
+ * Whether columns can be grouped by — a header's click/`Alt+ArrowDown`
281
+ * toggle — unless a column says otherwise. The grouping itself still
282
+ * applies when this is off, via `defaultGroupBy` or the imperative API;
283
+ * this only gates that one interaction, the same way `sortableColumns`
284
+ * gates the sort toggle without disabling `defaultColumnSort`. Independent
285
+ * of `groupByBarVisibility` and `groupByDraggableColumns`, which gate the
286
+ * bar and the drag-in gesture respectively.
287
+ */
288
+ groupableColumns?: boolean | undefined;
289
+ /**
290
+ * Whether a groupable header shows its group-toggle icon, unless a column
291
+ * says otherwise. Purely a rendering choice: `Alt+ArrowDown` keeps working
292
+ * on a groupable header with the icon hidden.
293
+ */
294
+ groupToggleIconColumns?: boolean | undefined;
295
+ /**
296
+ * Whether a column's header may be dragged into the group-by bar to add
297
+ * it to the grouping, unless a column says otherwise. Independent of
298
+ * `groupableColumns`: a column can be groupable via its header's
299
+ * click/keyboard toggle, via this drag, both, or neither.
300
+ */
301
+ groupByDraggableColumns?: boolean | undefined;
302
+ /** How the group-by bar's visibility follows the active grouping. */
303
+ groupByBarVisibility?: GroupByBarVisibility | undefined;
304
+ /** The group-by stack to start with, outer to inner. Uncontrolled. */
305
+ defaultGroupBy?: GroupByState | undefined;
306
+ /**
307
+ * Called once when the user changes the group-by stack — adding, removing,
308
+ * or reordering a level.
309
+ */
310
+ onGroupByChange?: ((event: GroupByEvent) => void) | undefined;
311
+ /** Group keys collapsed to start with — every other group starts expanded. Uncontrolled. */
312
+ defaultGroupExpansion?: GroupExpansionState | undefined;
313
+ /** Called once when the user expands or collapses a group, or every group at once. */
314
+ onGroupExpansionChange?: ((event: GroupExpansionEvent) => void) | undefined;
190
315
  /** The filter to start with — every applied entry, ANDed together. Uncontrolled. */
191
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;
192
352
  /**
193
353
  * The grid's accessible name, announced when it takes focus. A grid without
194
354
  * one is read only as "grid", which says nothing about which grid.
@@ -202,6 +362,112 @@ interface DataGridProps<Row> extends SelectionCallbacks<Row> {
202
362
  /** Imperative handle for reading live grid state and triggering actions. */
203
363
  ref?: Ref<DataGridApi<Row>> | undefined;
204
364
  }
205
- declare function DataGridComponent<Row>({ dataSource, columns, getRowId, borders, hoverable, selectable, defaultRowSelection, defaultColumnSelection, defaultCellSelection, resizableColumns, reorderableColumns, resizeMode, defaultColumnSizing, defaultColumnOrder, columnSizeDefaults, onColumnResize, onColumnOrderChange, sortableColumns, defaultColumnSort, onColumnSortChange, 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;
206
472
 
207
- export { type Borders, type CellSelectEvent, type CellSelectionChangeEvent, type ColumnDefinition, type ColumnSelectEvent, type ColumnSelectionChangeEvent, type ColumnsSelectEvent, type DataGridApi, DataGridComponent, type DataGridProps, 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 };