@gridkitjs/core 0.0.0-dev-20261107195236 → 0.0.0-dev-20261107203826

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
@@ -1374,6 +1374,15 @@ interface ToolbarCustomEntry {
1374
1374
  * dropdown of the export commands that show; and a custom entry.
1375
1375
  */
1376
1376
  type ToolbarEntry<Row> = MenuEntry<Row> | "search" | "spacer" | "export" | ToolbarCustomEntry;
1377
+ /**
1378
+ * Attributes of the app's own for a toolbar entry's element, as hooks for
1379
+ * its tests, analytics or styles: an `id` and `data-*` attributes, nothing
1380
+ * that could change what the entry means or does.
1381
+ */
1382
+ interface ToolbarItemAttributes {
1383
+ readonly id?: string | undefined;
1384
+ readonly [name: `data-${string}`]: string;
1385
+ }
1377
1386
  /**
1378
1387
  * A toolbar button ready to draw — a command, or an inline item — with
1379
1388
  * every label a string, every flag a boolean, and `run` bound to the
@@ -1397,6 +1406,8 @@ interface ResolvedToolbarButton {
1397
1406
  readonly pressed: boolean | undefined;
1398
1407
  /** Runs the button, and says whether it ran — see `ResolvedMenuItem.run`. */
1399
1408
  readonly run: () => boolean;
1409
+ /** The app's attributes for its element, from `itemAttributes`. */
1410
+ readonly attributes?: ToolbarItemAttributes | undefined;
1400
1411
  }
1401
1412
  /** A dropdown button, opening the menu its submenu entry lists. */
1402
1413
  interface ResolvedToolbarMenu {
@@ -1408,12 +1419,16 @@ interface ResolvedToolbarMenu {
1408
1419
  readonly icon?: string | undefined;
1409
1420
  /** Never empty: a dropdown with nothing to show is left out. */
1410
1421
  readonly items: readonly ResolvedMenuEntry[];
1422
+ /** The app's attributes for its element, from `itemAttributes`. */
1423
+ readonly attributes?: ToolbarItemAttributes | undefined;
1411
1424
  }
1412
1425
  /** The search box, over the grid's global text filter. */
1413
1426
  interface ResolvedToolbarSearch {
1414
1427
  readonly type: "search";
1415
1428
  /** Always `"search"`. */
1416
1429
  readonly key: string;
1430
+ /** The app's attributes for its element, from `itemAttributes`. */
1431
+ readonly attributes?: ToolbarItemAttributes | undefined;
1417
1432
  }
1418
1433
  /** The free space between the entries either side of it. */
1419
1434
  interface ResolvedToolbarSpacer {
@@ -1427,6 +1442,8 @@ interface ResolvedToolbarCustom {
1427
1442
  readonly id: string;
1428
1443
  /** The same as `id`. */
1429
1444
  readonly key: string;
1445
+ /** The app's attributes for its element, from `itemAttributes`. */
1446
+ readonly attributes?: ToolbarItemAttributes | undefined;
1430
1447
  }
1431
1448
  /**
1432
1449
  * One entry of a toolbar as `resolveToolbar` hands it to a renderer to draw.
@@ -1436,12 +1453,21 @@ interface ResolvedToolbarCustom {
1436
1453
  */
1437
1454
  type ResolvedToolbarItem = ResolvedToolbarButton | ResolvedToolbarMenu | ResolvedToolbarSearch | ResolvedToolbarSpacer | ResolvedMenuSeparator | ResolvedToolbarCustom;
1438
1455
 
1439
- /** A grid's toolbar: what it lists, and what a screen reader calls it. */
1456
+ /**
1457
+ * A grid's toolbar: what it lists, what a screen reader calls it, and the
1458
+ * attributes of the app's own its entries' elements carry.
1459
+ */
1440
1460
  interface GridToolbarOptions<Row> {
1441
1461
  /** The toolbar's entries, in order. Left out, the defaults. */
1442
1462
  readonly items?: readonly ToolbarEntry<Row>[] | undefined;
1443
1463
  /** The toolbar's accessible name. Left out, `messages.toolbarLabel`. */
1444
1464
  readonly label?: string | undefined;
1465
+ /**
1466
+ * Attributes for entries' elements, by the entry's key: a command's,
1467
+ * inline item's, dropdown's or custom entry's id, `"search"` or
1468
+ * `"export"`. A key naming no entry, or a separator or spacer, is ignored.
1469
+ */
1470
+ readonly itemAttributes?: Readonly<Record<string, ToolbarItemAttributes>> | undefined;
1445
1471
  }
1446
1472
  /**
1447
1473
  * What a toolbar lists unless the grid says otherwise: the search box, then
@@ -1732,11 +1758,23 @@ interface GridOptions<Row> {
1732
1758
  */
1733
1759
  filterMenu?: GridFilterMenuOptions | undefined;
1734
1760
  /**
1735
- * Whether the grid's rows are split into pages. A page's unit is a
1736
- * top-level group or a bare data row, never a leaf row — a group is never
1737
- * split across a page boundary. Off by default, matching `sortableColumns`.
1761
+ * Whether the grid's rows are split into pages. Off by default, matching
1762
+ * `sortableColumns`. What a page's `pageSize` counts once the rows are
1763
+ * grouped is `paginationUnit`'s choice.
1738
1764
  */
1739
1765
  paginated?: boolean | undefined;
1766
+ /**
1767
+ * What `pageSize` counts in a grouped grid. `"group"` (the default) counts
1768
+ * top-level groups, each with everything beneath it, so a page never
1769
+ * splits a group but can grow as large as its groups. `"row"` counts data
1770
+ * rows, plus collapsed group headers, which stand in for their hidden
1771
+ * rows: every page holds `pageSize` of them, and a page continuing a group
1772
+ * starts with that group's headers again, with a group's summary row on
1773
+ * the page holding its last row. An ungrouped grid pages by data rows
1774
+ * under either. Selection, export and aggregates behave the same under
1775
+ * either unit.
1776
+ */
1777
+ paginationUnit?: PaginationUnit | undefined;
1740
1778
  /**
1741
1779
  * The page and page size to start on. Uncontrolled. Defaults to
1742
1780
  * `{ pageIndex: 0, pageSize: 25 }` when `paginated` is on and this is
@@ -1749,9 +1787,9 @@ interface GridOptions<Row> {
1749
1787
  * them itself, starting from `defaultPagination`.
1750
1788
  *
1751
1789
  * The grid sends an uncontrolled pagination back to the first page when
1752
- * the filter, sort or grouping changes; a controlled one is the parent's
1753
- * to reset alongside that change. Until it does, the grid shows the last
1754
- * page that exists rather than an empty one.
1790
+ * the filter, sort, grouping or `paginationUnit` changes; a controlled
1791
+ * one is the parent's to reset alongside that change. Until it does, the
1792
+ * grid shows the last page that exists rather than an empty one.
1755
1793
  */
1756
1794
  pagination?: PaginationState | undefined;
1757
1795
  /** Called once when the user changes the page or the page size. */
@@ -2219,6 +2257,15 @@ interface PaginationState {
2219
2257
  readonly pageIndex: number;
2220
2258
  readonly pageSize: number;
2221
2259
  }
2260
+ /**
2261
+ * What a grouped grid's `pageSize` counts. `"group"` counts top-level groups,
2262
+ * each with everything beneath it, so a page never splits a group. `"row"`
2263
+ * counts data rows and collapsed group headers, so every page holds
2264
+ * `pageSize` of them however large the groups are; a page continuing a group
2265
+ * starts with that group's headers again. An ungrouped grid pages by data
2266
+ * rows under either.
2267
+ */
2268
+ type PaginationUnit = "group" | "row";
2222
2269
  /** Reports a user page/page-size change whole — the one to persist from, mirroring ColumnSortEvent. */
2223
2270
  interface PaginationChangeEvent {
2224
2271
  readonly pagination: PaginationState;
@@ -2857,6 +2904,8 @@ type GridViewState<Row> = Omit<GridState<Row>, "rowSelection" | "columnSelection
2857
2904
  interface GridViewOptions<Row> {
2858
2905
  /** Whether `pageRows` is one page of `displayRows` rather than all of it. Defaults to `false`. */
2859
2906
  readonly paginated?: boolean | undefined;
2907
+ /** What a page's `pageSize` counts once grouped. Defaults to `"group"`. */
2908
+ readonly paginationUnit?: PaginationUnit | undefined;
2860
2909
  readonly aggregates?: AggregateState<Row> | undefined;
2861
2910
  /** Defaults to `"inline"`. */
2862
2911
  readonly groupAggregateDisplay?: GroupAggregateDisplay | undefined;
@@ -3012,6 +3061,8 @@ interface ToolbarResolveOptions<Row> {
3012
3061
  * opens a panel anchors it there.
3013
3062
  */
3014
3063
  readonly contextFor: (target: GridToolbarTarget) => GridCommandContext<Row>;
3064
+ /** Attributes for entries' elements, by key — see `GridToolbarOptions`. */
3065
+ readonly itemAttributes?: Readonly<Record<string, ToolbarItemAttributes>> | undefined;
3015
3066
  }
3016
3067
  /**
3017
3068
  * A toolbar's entries resolved against the grid, ready to draw, by the
@@ -3027,6 +3078,8 @@ interface ToolbarResolveOptions<Row> {
3027
3078
  * - `"search"`, `"spacer"` and custom entries stay as they are.
3028
3079
  * - Separators never lead, trail, double up or sit next to a spacer, which
3029
3080
  * already parts what is on either side of it.
3081
+ * - A button, dropdown, search box or custom entry whose key
3082
+ * `itemAttributes` names carries those `attributes`.
3030
3083
  *
3031
3084
  * Resolve again whenever the grid changes, so each button's label, flags
3032
3085
  * and `run` follow its state.
@@ -3636,18 +3689,27 @@ interface PaginatedRows<Row> {
3636
3689
  */
3637
3690
  readonly pageIndex: number;
3638
3691
  }
3692
+ interface PaginateRowsOptions {
3693
+ /** What `pageSize` counts — see `PaginationUnit`. Defaults to `"group"`. */
3694
+ readonly unit?: PaginationUnit | undefined;
3695
+ }
3639
3696
  /**
3640
- * `rows` sliced into pages of `pagination.pageSize` units — see `unitsOf`
3641
- * for what a unit is. `pageIndex` is clamped into range, `pageSize <= 0` is
3642
- * clamped to `1` (this codebase's general tolerance for stale/odd stored
3643
- * state, matching `sortRows`/`filterRows`), and the returned page's
3644
- * `rowIndex` is renumbered to be page-relative — 0-based from the top of the
3645
- * page, header rows included, mirroring `groupRows`'s own renumbering
3646
- * invariant. `datasetIndex` is left untouched: the stages ahead of this one
3647
- * set it to each row's position in the whole displayed result, which stays
3648
- * the same whichever page is showing.
3649
- */
3650
- declare function paginateRows<Row>(rows: readonly DisplayRow<Row>[], pagination: PaginationState): PaginatedRows<Row>;
3697
+ * `rows` sliced into pages of `pagination.pageSize` units — see
3698
+ * `groupUnitsOf` and `rowUnitsOf` for what a unit is under each
3699
+ * `options.unit`. A page opens with its first unit's enclosing headers, so
3700
+ * under `"row"` a header repeated from the page before is the same
3701
+ * `DisplayRow`, and toggling it toggles its group on every page.
3702
+ *
3703
+ * `pageIndex` is clamped into range, `pageSize <= 0` is clamped to `1`
3704
+ * (this codebase's general tolerance for stale/odd stored state, matching
3705
+ * `sortRows`/`filterRows`), and the returned page's `rowIndex` is renumbered
3706
+ * to be page-relative — 0-based from the top of the page, header rows
3707
+ * included, mirroring `groupRows`'s own renumbering invariant.
3708
+ * `datasetIndex` is left untouched: the stages ahead of this one set it to
3709
+ * each row's position in the whole displayed result, which stays the same
3710
+ * whichever page is showing.
3711
+ */
3712
+ declare function paginateRows<Row>(rows: readonly DisplayRow<Row>[], pagination: PaginationState, options?: PaginateRowsOptions): PaginatedRows<Row>;
3651
3713
 
3652
3714
  type PaginationWindowEntry = number | "ellipsis";
3653
3715
  /**
@@ -4227,4 +4289,4 @@ declare const excelFilter: {
4227
4289
  };
4228
4290
  };
4229
4291
 
4230
- export { type AggregateFn, type AggregateResults, type AggregateSpec, type AggregateState, type Borders, type BuiltInAggregate, type BuiltInCommandIcon, type BuiltInCommandId, type CellSelectEvent, type CellSelectionChangeEvent, type CellSelectionMode, type CellSelectionState, type CellTemplateContext, type ColumnAlignment, type ColumnChooserEntry, type ColumnChooserInput, type ColumnChooserModel, type ColumnChooserToggle, type ColumnConstraints, type ColumnDefinition, type ColumnFilterMenuOptions, type ColumnFilterShape, type ColumnOrderEvent, type ColumnOrderState, type ColumnResizeEvent, type ColumnResizeSession, type ColumnResolveOptions, type ColumnSelectEvent, type ColumnSelectionChangeEvent, type ColumnSizeDefaults, type ColumnSizingState, type ColumnSortEntry, type ColumnSortEvent, type ColumnSortState, type ColumnType, type ColumnValueCacheQuery, type ColumnValueOption, type ColumnValueOptions, type ColumnValueOptionsCache, type ColumnValueQuery, type ColumnVisibilityEvent, type ColumnVisibilityState, type ColumnWrapConfig, type ColumnsSelectEvent, type ConditionRowDraft, type ContextMenuOpenChangeEvent, type CopyContent, type CopyRequest, type CopySource, type CsvOptions, DEFAULT_COLUMN_SIZES, DEFAULT_FILTER_VALUE_LIMIT, type DataColumn, type DisplayRow, type DropSide, type ExportCell, type ExportColumn, type ExportDataRow, type ExportFile, type ExportFileSource, type ExportGroupRow, type ExportGroupSummaryRow, type ExportOptions, type ExportRow, type ExportScalar, type ExportSource, type ExportTable, type ExportTotalRow, type ExportWriteContext, type ExportWriter, type FieldPath, type FilterChangeEvent, type FilterChecklist, type FilterChecklistItem, type FilterChecklistOptions, type FilterEditorAction, type FilterEditorDraft, type FilterEntry, type FilterMenuUi, type FilterOperator, type FilterOperatorFamily, type FilterPredicate, type FilterScalar, type FilterState, type FooterTemplateContext, type FormatLocale, type GridCommand, type GridCommandActions, type GridCommandContext, type GridCommandContextInput, type GridCommandEvent, type GridCommandHost, type GridCommandSource, type GridCommandTarget, type GridContextMenuArea, type GridContextMenuEntries, type GridContextMenuOptions, type GridContextMenuRequest, type GridContextMenuTarget, type GridController, type GridControllerOptions, type GridExportOptions, type GridFilterMenuOptions, type GridFocus, type GridMessages, type GridOptions, type GridPanelKind, type GridState, type GridToolbarOptions, type GridToolbarTarget, type GridView, type GridViewInput, type GridViewOptions, type GridViewState, type GroupAggregateDisplay, type GroupByBarVisibility, type GroupByEntry, type GroupByEvent, type GroupByState, type GroupExpansionEvent, type GroupExpansionState, type GroupFilterEntry, HEADER_ROW, type HoverableConfig, type HtmlTableOptions, type JsonOptions, KEYBOARD_STEP, type KeyShortcutCapabilities, type MenuEntry, type MenuItemEntry, type MenuMove, type MenuResolveOptions, type MenuSubmenuEntry, type NavigationModifiers, type OperatorFilterEntry, type PaginatedRows, type PaginationChangeEvent, type PaginationState, type PaginationWindowEntry, type ParsedConditionRows, type PredicateFilterEntry, type PrintDocument, type PrintOptions, type PrintOrientation, type PrintPage, type PrintSource, type ResizeMode, type ResolvedColumn, type ResolvedColumnFilterMenu, type ResolvedGroupRow, type ResolvedGroupSummaryRow, type ResolvedMenuEntry, type ResolvedMenuItem, type ResolvedMenuSeparator, type ResolvedMenuSubmenu, type ResolvedRow, type ResolvedToolbarButton, type ResolvedToolbarCustom, type ResolvedToolbarItem, type ResolvedToolbarMenu, type ResolvedToolbarSearch, type ResolvedToolbarSpacer, type RowHeights, type RowPointerEvent, type RowProps, type RowSelectEvent, type RowSelectionChangeEvent, type RowsSelectEvent, type SelectAllState, type SelectIntent, type SelectableConfig, type SelectedCell, type SelectedCellRef, type SelectedColumn, type SelectionCallbacks, type SelectionDiff, type SelectionDiffEvent, type SelectionMode, type SelectionState, type SerializedFilterEntry, type SerializedFilterScalar, type SerializedFilterState, type SerializedGridState, type SerializedGroupFilterEntry, type SerializedOperatorFilterEntry, type SerializedValueFilterEntry, type SortDirection, type TextFilterEntry, type ToolbarCustomEntry, type ToolbarEntry, type ToolbarFitInput, type ToolbarResolveOptions, type ToolbarSplit, type TsvOptions, type ValueFilterEntry, type VisibleRange, accessDotted, alignmentForType, applyColumnOrder, applyColumnResize, applyColumnVisibility, applySelectionIntent, beginColumnResize, buildExportTable, buildKeyShortcuts, buildPrintDocument, builtInCommands, clampColumnWidth, clampFocus, clearAllFilters, clearSelection, collapseAllGroups, columnValueOptions, compareValues, computeAggregates, conditionRowsFrom, conditionsFromRows, contextMenuEntries, copyContent, createColumnValueOptionsCache, createCommandContext, createDefaultMessages, createGridController, createGridViewResolver, csvWriter, defaultContextMenu, defaultFilterOperators, defaultMessages, defaultToolbar, defineColumnsFromRows, describeColumnFilter, diffSelection, draftToFilter, excelFilter, expandAllGroups, exportFile, exportPrintDocument, filterChecklist, filterEditorReducer, filterOperandArity, filterOperatorFamily, filterQueryFor, filterRows, fitColumnsToWidth, fitToolbarItems, formatAggregateValue, formatCellValue, formatFilterOperand, formatGroupValue, getColumnId, groupRowId, groupRows, hasContextMenu, initialFilterEditorDraft, intentOf, isColumnFiltered, isColumnVisible, isPinnedToolbarItem, isSameCell, jsonWriter, matchesQuery, moveColumnBefore, moveGroupByBefore, movesColumn, movesGroupBy, nextFocusForKey, nextMenuIndex, paginateRows, paginationWindow, parseFilterOperand, resolveCell, resolveColumnChooser, resolveColumnConstraints, resolveColumnFilterMenu, resolveColumnHeaderText, resolveColumnLabel, resolveColumnWidths, resolveColumns, resolveCommands, resolveDataColumns, resolveDropBefore, resolveExportWriters, resolveGridView, resolveKeyboardDropTarget, resolveMenu, resolveMessages, resolveRowId, resolveRows, resolveShownRows, resolveToolbar, revertColumnSize, runCommand, searchTextOf, selectAll, selectAllState, selectCell, selectOnly, selectRange, serializeGridState, setColumnFilter, setColumnVisibility, setSearchText, sizeColumnToContent, sortDirectionFor, sortPriorityFor, sortRows, splitToolbarItems, toCsv, toHtmlTable, toJson, toTsv, toggleCellSelection, toggleColumnSort, toggleGroupExpansion, toggleSelection, toolbarEntries, totalColumnWidth, typeaheadIndex, visibleFilterOptions, visibleRange, withGroupAggregates };
4292
+ export { type AggregateFn, type AggregateResults, type AggregateSpec, type AggregateState, type Borders, type BuiltInAggregate, type BuiltInCommandIcon, type BuiltInCommandId, type CellSelectEvent, type CellSelectionChangeEvent, type CellSelectionMode, type CellSelectionState, type CellTemplateContext, type ColumnAlignment, type ColumnChooserEntry, type ColumnChooserInput, type ColumnChooserModel, type ColumnChooserToggle, type ColumnConstraints, type ColumnDefinition, type ColumnFilterMenuOptions, type ColumnFilterShape, type ColumnOrderEvent, type ColumnOrderState, type ColumnResizeEvent, type ColumnResizeSession, type ColumnResolveOptions, type ColumnSelectEvent, type ColumnSelectionChangeEvent, type ColumnSizeDefaults, type ColumnSizingState, type ColumnSortEntry, type ColumnSortEvent, type ColumnSortState, type ColumnType, type ColumnValueCacheQuery, type ColumnValueOption, type ColumnValueOptions, type ColumnValueOptionsCache, type ColumnValueQuery, type ColumnVisibilityEvent, type ColumnVisibilityState, type ColumnWrapConfig, type ColumnsSelectEvent, type ConditionRowDraft, type ContextMenuOpenChangeEvent, type CopyContent, type CopyRequest, type CopySource, type CsvOptions, DEFAULT_COLUMN_SIZES, DEFAULT_FILTER_VALUE_LIMIT, type DataColumn, type DisplayRow, type DropSide, type ExportCell, type ExportColumn, type ExportDataRow, type ExportFile, type ExportFileSource, type ExportGroupRow, type ExportGroupSummaryRow, type ExportOptions, type ExportRow, type ExportScalar, type ExportSource, type ExportTable, type ExportTotalRow, type ExportWriteContext, type ExportWriter, type FieldPath, type FilterChangeEvent, type FilterChecklist, type FilterChecklistItem, type FilterChecklistOptions, type FilterEditorAction, type FilterEditorDraft, type FilterEntry, type FilterMenuUi, type FilterOperator, type FilterOperatorFamily, type FilterPredicate, type FilterScalar, type FilterState, type FooterTemplateContext, type FormatLocale, type GridCommand, type GridCommandActions, type GridCommandContext, type GridCommandContextInput, type GridCommandEvent, type GridCommandHost, type GridCommandSource, type GridCommandTarget, type GridContextMenuArea, type GridContextMenuEntries, type GridContextMenuOptions, type GridContextMenuRequest, type GridContextMenuTarget, type GridController, type GridControllerOptions, type GridExportOptions, type GridFilterMenuOptions, type GridFocus, type GridMessages, type GridOptions, type GridPanelKind, type GridState, type GridToolbarOptions, type GridToolbarTarget, type GridView, type GridViewInput, type GridViewOptions, type GridViewState, type GroupAggregateDisplay, type GroupByBarVisibility, type GroupByEntry, type GroupByEvent, type GroupByState, type GroupExpansionEvent, type GroupExpansionState, type GroupFilterEntry, HEADER_ROW, type HoverableConfig, type HtmlTableOptions, type JsonOptions, KEYBOARD_STEP, type KeyShortcutCapabilities, type MenuEntry, type MenuItemEntry, type MenuMove, type MenuResolveOptions, type MenuSubmenuEntry, type NavigationModifiers, type OperatorFilterEntry, type PaginateRowsOptions, type PaginatedRows, type PaginationChangeEvent, type PaginationState, type PaginationUnit, type PaginationWindowEntry, type ParsedConditionRows, type PredicateFilterEntry, type PrintDocument, type PrintOptions, type PrintOrientation, type PrintPage, type PrintSource, type ResizeMode, type ResolvedColumn, type ResolvedColumnFilterMenu, type ResolvedGroupRow, type ResolvedGroupSummaryRow, type ResolvedMenuEntry, type ResolvedMenuItem, type ResolvedMenuSeparator, type ResolvedMenuSubmenu, type ResolvedRow, type ResolvedToolbarButton, type ResolvedToolbarCustom, type ResolvedToolbarItem, type ResolvedToolbarMenu, type ResolvedToolbarSearch, type ResolvedToolbarSpacer, type RowHeights, type RowPointerEvent, type RowProps, type RowSelectEvent, type RowSelectionChangeEvent, type RowsSelectEvent, type SelectAllState, type SelectIntent, type SelectableConfig, type SelectedCell, type SelectedCellRef, type SelectedColumn, type SelectionCallbacks, type SelectionDiff, type SelectionDiffEvent, type SelectionMode, type SelectionState, type SerializedFilterEntry, type SerializedFilterScalar, type SerializedFilterState, type SerializedGridState, type SerializedGroupFilterEntry, type SerializedOperatorFilterEntry, type SerializedValueFilterEntry, type SortDirection, type TextFilterEntry, type ToolbarCustomEntry, type ToolbarEntry, type ToolbarFitInput, type ToolbarItemAttributes, type ToolbarResolveOptions, type ToolbarSplit, type TsvOptions, type ValueFilterEntry, type VisibleRange, accessDotted, alignmentForType, applyColumnOrder, applyColumnResize, applyColumnVisibility, applySelectionIntent, beginColumnResize, buildExportTable, buildKeyShortcuts, buildPrintDocument, builtInCommands, clampColumnWidth, clampFocus, clearAllFilters, clearSelection, collapseAllGroups, columnValueOptions, compareValues, computeAggregates, conditionRowsFrom, conditionsFromRows, contextMenuEntries, copyContent, createColumnValueOptionsCache, createCommandContext, createDefaultMessages, createGridController, createGridViewResolver, csvWriter, defaultContextMenu, defaultFilterOperators, defaultMessages, defaultToolbar, defineColumnsFromRows, describeColumnFilter, diffSelection, draftToFilter, excelFilter, expandAllGroups, exportFile, exportPrintDocument, filterChecklist, filterEditorReducer, filterOperandArity, filterOperatorFamily, filterQueryFor, filterRows, fitColumnsToWidth, fitToolbarItems, formatAggregateValue, formatCellValue, formatFilterOperand, formatGroupValue, getColumnId, groupRowId, groupRows, hasContextMenu, initialFilterEditorDraft, intentOf, isColumnFiltered, isColumnVisible, isPinnedToolbarItem, isSameCell, jsonWriter, matchesQuery, moveColumnBefore, moveGroupByBefore, movesColumn, movesGroupBy, nextFocusForKey, nextMenuIndex, paginateRows, paginationWindow, parseFilterOperand, resolveCell, resolveColumnChooser, resolveColumnConstraints, resolveColumnFilterMenu, resolveColumnHeaderText, resolveColumnLabel, resolveColumnWidths, resolveColumns, resolveCommands, resolveDataColumns, resolveDropBefore, resolveExportWriters, resolveGridView, resolveKeyboardDropTarget, resolveMenu, resolveMessages, resolveRowId, resolveRows, resolveShownRows, resolveToolbar, revertColumnSize, runCommand, searchTextOf, selectAll, selectAllState, selectCell, selectOnly, selectRange, serializeGridState, setColumnFilter, setColumnVisibility, setSearchText, sizeColumnToContent, sortDirectionFor, sortPriorityFor, sortRows, splitToolbarItems, toCsv, toHtmlTable, toJson, toTsv, toggleCellSelection, toggleColumnSort, toggleGroupExpansion, toggleSelection, toolbarEntries, totalColumnWidth, typeaheadIndex, visibleFilterOptions, visibleRange, withGroupAggregates };
package/dist/index.js CHANGED
@@ -411,7 +411,8 @@ function resolveKeyboardDropTarget(orderedIds, columnId, direction) {
411
411
  }
412
412
 
413
413
  // src/util/paging.ts
414
- function unitsOf(rows) {
414
+ var NO_HEADERS = [];
415
+ function groupUnitsOf(rows) {
415
416
  const units = [];
416
417
  let start = 0;
417
418
  let openedByGroup = false;
@@ -423,7 +424,7 @@ function unitsOf(rows) {
423
424
  const isTopLevelHeader = "kind" in entry && entry.kind === "group" && entry.level === 0;
424
425
  const isBoundary = index !== start && (isTopLevelHeader || !openedByGroup);
425
426
  if (isBoundary) {
426
- units.push({ start, end: index });
427
+ units.push({ start, end: index, headers: NO_HEADERS });
427
428
  start = index;
428
429
  openedByGroup = isTopLevelHeader;
429
430
  } else if (index === start) {
@@ -431,13 +432,38 @@ function unitsOf(rows) {
431
432
  }
432
433
  }
433
434
  if (start < rows.length) {
434
- units.push({ start, end: rows.length });
435
+ units.push({ start, end: rows.length, headers: NO_HEADERS });
435
436
  }
436
437
  return units;
437
438
  }
438
- function paginateRows(rows, pagination) {
439
+ function rowUnitsOf(rows) {
440
+ const units = [];
441
+ let open = NO_HEADERS;
442
+ for (let index = 0; index < rows.length; index++) {
443
+ const entry = rows[index];
444
+ if (entry === void 0) {
445
+ continue;
446
+ }
447
+ if (!("kind" in entry)) {
448
+ units.push({ start: index, end: index + 1, headers: open });
449
+ } else if (entry.kind === "group") {
450
+ const ancestors = open.slice(0, entry.level);
451
+ open = entry.expanded ? [...ancestors, entry] : ancestors;
452
+ if (!entry.expanded) {
453
+ units.push({ start: index, end: index + 1, headers: ancestors });
454
+ }
455
+ } else {
456
+ const last = units.at(-1);
457
+ if (last !== void 0) {
458
+ units[units.length - 1] = { ...last, end: index + 1 };
459
+ }
460
+ }
461
+ }
462
+ return units;
463
+ }
464
+ function paginateRows(rows, pagination, options = {}) {
439
465
  const pageSize = Math.max(1, pagination.pageSize);
440
- const units = unitsOf(rows);
466
+ const units = options.unit === "row" ? rowUnitsOf(rows) : groupUnitsOf(rows);
441
467
  const pageCount = Math.ceil(units.length / pageSize);
442
468
  if (pageCount === 0) {
443
469
  return { rows: [], pageCount: 0, pageIndex: 0 };
@@ -448,7 +474,10 @@ function paginateRows(rows, pagination) {
448
474
  if (firstUnit === void 0 || lastUnit === void 0) {
449
475
  return { rows: [], pageCount, pageIndex };
450
476
  }
451
- const page = rows.slice(firstUnit.start, lastUnit.end);
477
+ const page = [
478
+ ...firstUnit.headers,
479
+ ...rows.slice(firstUnit.start, lastUnit.end)
480
+ ];
452
481
  const renumbered = page.map(
453
482
  (entry, index) => entry.rowIndex === index ? entry : { ...entry, rowIndex: index }
454
483
  );
@@ -1250,8 +1279,8 @@ function totalAggregates(rows, aggregates, dataColumns) {
1250
1279
  dataColumns
1251
1280
  );
1252
1281
  }
1253
- function paginate(displayRows, paginated, pagination) {
1254
- return paginated ? paginateRows(displayRows, pagination) : { rows: displayRows, pageCount: 1, pageIndex: 0 };
1282
+ function paginate(displayRows, paginated, pagination, unit) {
1283
+ return paginated ? paginateRows(displayRows, pagination, { unit }) : { rows: displayRows, pageCount: 1, pageIndex: 0 };
1255
1284
  }
1256
1285
  function narrowToDataRows(pageRows, rows, reshaped) {
1257
1286
  return reshaped ? pageRows.filter((entry) => !("kind" in entry)) : rows;
@@ -1312,7 +1341,12 @@ function createGridViewResolver() {
1312
1341
  rows: pageRows,
1313
1342
  pageCount,
1314
1343
  pageIndex
1315
- } = page(displayRows, paginated, state.pagination);
1344
+ } = page(
1345
+ displayRows,
1346
+ paginated,
1347
+ state.pagination,
1348
+ options.paginationUnit ?? "group"
1349
+ );
1316
1350
  return assemble(
1317
1351
  dataColumns,
1318
1352
  columns,
@@ -1759,11 +1793,12 @@ function definedColumns(columns, rows) {
1759
1793
  }
1760
1794
  return NO_COLUMNS;
1761
1795
  }
1762
- function pagingInputsOf(state) {
1796
+ function pagingInputsOf(state, options) {
1763
1797
  return {
1764
1798
  filter: state.filter,
1765
1799
  columnSort: state.columnSort,
1766
- groupBy: state.groupBy
1800
+ groupBy: state.groupBy,
1801
+ paginationUnit: options.paginationUnit ?? "group"
1767
1802
  };
1768
1803
  }
1769
1804
  function createGridController(initial) {
@@ -1775,7 +1810,7 @@ function createGridController(initial) {
1775
1810
  const reportedConflicts = /* @__PURE__ */ new Set();
1776
1811
  let heldReports;
1777
1812
  let state = resolveSlices();
1778
- let pagingInputs = pagingInputsOf(state);
1813
+ let pagingInputs = pagingInputsOf(state, options);
1779
1814
  reportConflicts();
1780
1815
  function controlledValue(key) {
1781
1816
  const controlled = options;
@@ -1817,8 +1852,9 @@ function createGridController(initial) {
1817
1852
  }
1818
1853
  function refresh() {
1819
1854
  let next = resolveSlices();
1820
- if (next.filter !== pagingInputs.filter || next.columnSort !== pagingInputs.columnSort || next.groupBy !== pagingInputs.groupBy) {
1821
- pagingInputs = pagingInputsOf(next);
1855
+ const inputs = pagingInputsOf(next, options);
1856
+ if (inputs.filter !== pagingInputs.filter || inputs.columnSort !== pagingInputs.columnSort || inputs.groupBy !== pagingInputs.groupBy || inputs.paginationUnit !== pagingInputs.paginationUnit) {
1857
+ pagingInputs = inputs;
1822
1858
  if (!isControlled("pagination") && own.pagination.pageIndex !== 0) {
1823
1859
  own.pagination = { ...own.pagination, pageIndex: 0 };
1824
1860
  next = { ...next, pagination: own.pagination };
@@ -1854,6 +1890,7 @@ function createGridController(initial) {
1854
1890
  state,
1855
1891
  options: {
1856
1892
  paginated: options.paginated,
1893
+ paginationUnit: options.paginationUnit,
1857
1894
  aggregates: options.aggregates,
1858
1895
  groupAggregateDisplay: options.groupAggregateDisplay,
1859
1896
  columnSizeDefaults: options.columnSizeDefaults,
@@ -1921,20 +1958,22 @@ function createGridController(initial) {
1921
1958
  commit("pagination", next, () => {
1922
1959
  options.onPaginationChange?.({
1923
1960
  pagination: next,
1924
- pageCount: paginateRows(getView().displayRows, next).pageCount
1961
+ pageCount: pageOf(next).pageCount
1925
1962
  });
1926
1963
  });
1927
1964
  }
1965
+ function pageOf(pagination) {
1966
+ return paginateRows(getView().displayRows, pagination, {
1967
+ unit: options.paginationUnit
1968
+ });
1969
+ }
1928
1970
  function goToPage(pageIndex) {
1929
1971
  const current = state.pagination;
1930
- const clamped = paginateRows(getView().displayRows, {
1931
- ...current,
1932
- pageIndex
1933
- }).pageIndex;
1972
+ const clamped = pageOf({ ...current, pageIndex }).pageIndex;
1934
1973
  commitPagination({ ...current, pageIndex: clamped });
1935
1974
  }
1936
1975
  function shownPageIndex() {
1937
- return paginateRows(getView().displayRows, state.pagination).pageIndex;
1976
+ return pageOf(state.pagination).pageIndex;
1938
1977
  }
1939
1978
  const selection = createSelectionActions({
1940
1979
  getState: () => state,
@@ -1961,7 +2000,7 @@ function createGridController(initial) {
1961
2000
  heldReports = void 0;
1962
2001
  }
1963
2002
  if (saved.pagination !== void 0) {
1964
- pagingInputs = pagingInputsOf(resolveSlices());
2003
+ pagingInputs = pagingInputsOf(resolveSlices(), options);
1965
2004
  }
1966
2005
  refresh();
1967
2006
  for (const report of reports) {
@@ -2123,7 +2162,7 @@ function createGridController(initial) {
2123
2162
  const first = { pageIndex: 0, pageSize };
2124
2163
  commitPagination({
2125
2164
  ...first,
2126
- pageIndex: paginateRows(getView().displayRows, first).pageIndex
2165
+ pageIndex: pageOf(first).pageIndex
2127
2166
  });
2128
2167
  }
2129
2168
  };
@@ -4167,7 +4206,14 @@ function exportMenu() {
4167
4206
  };
4168
4207
  }
4169
4208
  function resolveToolbar(entries, options) {
4170
- const { commands, contextFor } = options;
4209
+ const { commands, contextFor, itemAttributes } = options;
4210
+ function withAttributes(item) {
4211
+ if (item.type === "separator" || item.type === "spacer" || itemAttributes === void 0 || !Object.hasOwn(itemAttributes, item.key)) {
4212
+ return item;
4213
+ }
4214
+ const attributes = itemAttributes[item.key];
4215
+ return attributes === void 0 ? item : { ...item, attributes };
4216
+ }
4171
4217
  function resolveEntry(entry, index) {
4172
4218
  if (entry === "search") {
4173
4219
  return { type: "search", key: "search" };
@@ -4199,7 +4245,7 @@ function resolveToolbar(entries, options) {
4199
4245
  return { ...item, type: "button", key: item.id, pressed: checked };
4200
4246
  }
4201
4247
  return collapseSeparators(
4202
- entries.map(resolveEntry).filter((entry) => entry !== null),
4248
+ entries.map(resolveEntry).filter((entry) => entry !== null).map(withAttributes),
4203
4249
  isSpacer
4204
4250
  );
4205
4251
  }