@gridkitjs/core 0.0.0-dev-20261107202111 → 0.0.0-dev-20261107212842

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
@@ -217,8 +217,10 @@ interface GridController<Row, Node = string> {
217
217
  /** Collapses every group currently shown — see `collapseAllGroups`. */
218
218
  readonly collapseAllGroups: () => void;
219
219
  /**
220
- * Replaces the page and page size as given; the view clamps a page past
221
- * the last one. An equal pagination reports nothing.
220
+ * Replaces the page and page size. A controlled pagination asks for them
221
+ * as given and the view clamps a page past the last one; an uncontrolled
222
+ * one stores and reports that page clamped. An equal pagination reports
223
+ * nothing.
222
224
  */
223
225
  readonly setPagination: (pagination: PaginationState) => void;
224
226
  /**
@@ -1374,6 +1376,15 @@ interface ToolbarCustomEntry {
1374
1376
  * dropdown of the export commands that show; and a custom entry.
1375
1377
  */
1376
1378
  type ToolbarEntry<Row> = MenuEntry<Row> | "search" | "spacer" | "export" | ToolbarCustomEntry;
1379
+ /**
1380
+ * Attributes of the app's own for a toolbar entry's element, as hooks for
1381
+ * its tests, analytics or styles: an `id` and `data-*` attributes, nothing
1382
+ * that could change what the entry means or does.
1383
+ */
1384
+ interface ToolbarItemAttributes {
1385
+ readonly id?: string | undefined;
1386
+ readonly [name: `data-${string}`]: string;
1387
+ }
1377
1388
  /**
1378
1389
  * A toolbar button ready to draw — a command, or an inline item — with
1379
1390
  * every label a string, every flag a boolean, and `run` bound to the
@@ -1397,6 +1408,8 @@ interface ResolvedToolbarButton {
1397
1408
  readonly pressed: boolean | undefined;
1398
1409
  /** Runs the button, and says whether it ran — see `ResolvedMenuItem.run`. */
1399
1410
  readonly run: () => boolean;
1411
+ /** The app's attributes for its element, from `itemAttributes`. */
1412
+ readonly attributes?: ToolbarItemAttributes | undefined;
1400
1413
  }
1401
1414
  /** A dropdown button, opening the menu its submenu entry lists. */
1402
1415
  interface ResolvedToolbarMenu {
@@ -1408,12 +1421,16 @@ interface ResolvedToolbarMenu {
1408
1421
  readonly icon?: string | undefined;
1409
1422
  /** Never empty: a dropdown with nothing to show is left out. */
1410
1423
  readonly items: readonly ResolvedMenuEntry[];
1424
+ /** The app's attributes for its element, from `itemAttributes`. */
1425
+ readonly attributes?: ToolbarItemAttributes | undefined;
1411
1426
  }
1412
1427
  /** The search box, over the grid's global text filter. */
1413
1428
  interface ResolvedToolbarSearch {
1414
1429
  readonly type: "search";
1415
1430
  /** Always `"search"`. */
1416
1431
  readonly key: string;
1432
+ /** The app's attributes for its element, from `itemAttributes`. */
1433
+ readonly attributes?: ToolbarItemAttributes | undefined;
1417
1434
  }
1418
1435
  /** The free space between the entries either side of it. */
1419
1436
  interface ResolvedToolbarSpacer {
@@ -1427,6 +1444,8 @@ interface ResolvedToolbarCustom {
1427
1444
  readonly id: string;
1428
1445
  /** The same as `id`. */
1429
1446
  readonly key: string;
1447
+ /** The app's attributes for its element, from `itemAttributes`. */
1448
+ readonly attributes?: ToolbarItemAttributes | undefined;
1430
1449
  }
1431
1450
  /**
1432
1451
  * One entry of a toolbar as `resolveToolbar` hands it to a renderer to draw.
@@ -1436,12 +1455,21 @@ interface ResolvedToolbarCustom {
1436
1455
  */
1437
1456
  type ResolvedToolbarItem = ResolvedToolbarButton | ResolvedToolbarMenu | ResolvedToolbarSearch | ResolvedToolbarSpacer | ResolvedMenuSeparator | ResolvedToolbarCustom;
1438
1457
 
1439
- /** A grid's toolbar: what it lists, and what a screen reader calls it. */
1458
+ /**
1459
+ * A grid's toolbar: what it lists, what a screen reader calls it, and the
1460
+ * attributes of the app's own its entries' elements carry.
1461
+ */
1440
1462
  interface GridToolbarOptions<Row> {
1441
1463
  /** The toolbar's entries, in order. Left out, the defaults. */
1442
1464
  readonly items?: readonly ToolbarEntry<Row>[] | undefined;
1443
1465
  /** The toolbar's accessible name. Left out, `messages.toolbarLabel`. */
1444
1466
  readonly label?: string | undefined;
1467
+ /**
1468
+ * Attributes for entries' elements, by the entry's key: a command's,
1469
+ * inline item's, dropdown's or custom entry's id, `"search"` or
1470
+ * `"export"`. A key naming no entry, or a separator or spacer, is ignored.
1471
+ */
1472
+ readonly itemAttributes?: Readonly<Record<string, ToolbarItemAttributes>> | undefined;
1445
1473
  }
1446
1474
  /**
1447
1475
  * What a toolbar lists unless the grid says otherwise: the search box, then
@@ -3035,6 +3063,8 @@ interface ToolbarResolveOptions<Row> {
3035
3063
  * opens a panel anchors it there.
3036
3064
  */
3037
3065
  readonly contextFor: (target: GridToolbarTarget) => GridCommandContext<Row>;
3066
+ /** Attributes for entries' elements, by key — see `GridToolbarOptions`. */
3067
+ readonly itemAttributes?: Readonly<Record<string, ToolbarItemAttributes>> | undefined;
3038
3068
  }
3039
3069
  /**
3040
3070
  * A toolbar's entries resolved against the grid, ready to draw, by the
@@ -3050,6 +3080,8 @@ interface ToolbarResolveOptions<Row> {
3050
3080
  * - `"search"`, `"spacer"` and custom entries stay as they are.
3051
3081
  * - Separators never lead, trail, double up or sit next to a spacer, which
3052
3082
  * already parts what is on either side of it.
3083
+ * - A button, dropdown, search box or custom entry whose key
3084
+ * `itemAttributes` names carries those `attributes`.
3053
3085
  *
3054
3086
  * Resolve again whenever the grid changes, so each button's label, flags
3055
3087
  * and `run` follow its state.
@@ -4259,4 +4291,4 @@ declare const excelFilter: {
4259
4291
  };
4260
4292
  };
4261
4293
 
4262
- 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 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 };
4294
+ 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
@@ -1861,6 +1861,21 @@ function createGridController(initial) {
1861
1861
  }
1862
1862
  }
1863
1863
  state = SLICE_KEYS.every((key) => next[key] === state[key]) ? state : next;
1864
+ storeShownPage();
1865
+ }
1866
+ function storeShownPage() {
1867
+ const stored = storedPagination(state.pagination);
1868
+ if (stored !== state.pagination) {
1869
+ own.pagination = stored;
1870
+ state = { ...state, pagination: stored };
1871
+ }
1872
+ }
1873
+ function storedPagination(pagination) {
1874
+ if (options.paginated !== true || isControlled("pagination")) {
1875
+ return pagination;
1876
+ }
1877
+ const { pageCount, pageIndex } = pageOf(pagination);
1878
+ return pageCount === 0 || pageIndex === pagination.pageIndex ? pagination : { ...pagination, pageIndex };
1864
1879
  }
1865
1880
  function notify() {
1866
1881
  for (const listener of [...listeners]) {
@@ -1951,14 +1966,16 @@ function createGridController(initial) {
1951
1966
  options.onGroupExpansionChange?.({ groupId, expansion: next });
1952
1967
  });
1953
1968
  }
1954
- function commitPagination(next) {
1969
+ function commitPagination(asked) {
1970
+ const next = heldReports === void 0 ? storedPagination(asked) : asked;
1955
1971
  if (samePagination(state.pagination, next)) {
1956
1972
  return;
1957
1973
  }
1958
1974
  commit("pagination", next, () => {
1975
+ const pagination = isControlled("pagination") ? next : own.pagination;
1959
1976
  options.onPaginationChange?.({
1960
- pagination: next,
1961
- pageCount: pageOf(next).pageCount
1977
+ pagination,
1978
+ pageCount: pageOf(pagination).pageCount
1962
1979
  });
1963
1980
  });
1964
1981
  }
@@ -4206,7 +4223,14 @@ function exportMenu() {
4206
4223
  };
4207
4224
  }
4208
4225
  function resolveToolbar(entries, options) {
4209
- const { commands, contextFor } = options;
4226
+ const { commands, contextFor, itemAttributes } = options;
4227
+ function withAttributes(item) {
4228
+ if (item.type === "separator" || item.type === "spacer" || itemAttributes === void 0 || !Object.hasOwn(itemAttributes, item.key)) {
4229
+ return item;
4230
+ }
4231
+ const attributes = itemAttributes[item.key];
4232
+ return attributes === void 0 ? item : { ...item, attributes };
4233
+ }
4210
4234
  function resolveEntry(entry, index) {
4211
4235
  if (entry === "search") {
4212
4236
  return { type: "search", key: "search" };
@@ -4238,7 +4262,7 @@ function resolveToolbar(entries, options) {
4238
4262
  return { ...item, type: "button", key: item.id, pressed: checked };
4239
4263
  }
4240
4264
  return collapseSeparators(
4241
- entries.map(resolveEntry).filter((entry) => entry !== null),
4265
+ entries.map(resolveEntry).filter((entry) => entry !== null).map(withAttributes),
4242
4266
  isSpacer
4243
4267
  );
4244
4268
  }