@upbound/monarch-blocks 0.15.0 → 0.16.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.
@@ -116,11 +116,13 @@ type DataTablePaginationProps = {
116
116
  /** `'gt'` renders "N+ results" with an explanatory tooltip, for an inexact/server-estimated count. @default 'eq' */
117
117
  rowCountRelation?: RowCountRelation;
118
118
  paginationConfig?: DataTablePaginationConfig;
119
+ /** Disables the controls while the requested page loads; the clicked arrow shows a spinner. @default false */
120
+ loading?: boolean;
119
121
  /** Called with the 1-based page number the user navigated to. */
120
122
  onPageChange: (page: number) => void;
121
123
  onPageSizeChange: (pageSize: number) => void;
122
124
  };
123
- declare function DataTablePagination({ pageIndex, pageSize, rowCount, rowCountRelation, paginationConfig, onPageChange, onPageSizeChange, }: DataTablePaginationProps): React$1.JSX.Element;
125
+ declare function DataTablePagination({ pageIndex, pageSize, rowCount, rowCountRelation, paginationConfig, loading, onPageChange, onPageSizeChange, }: DataTablePaginationProps): React$1.JSX.Element;
124
126
 
125
127
  declare function DataTableHeader<TData extends RowData>({ headerGroups, onAutosizeAll, onAutosizeColumn, onResetColumnSize, stickyHeader, layout, }: {
126
128
  headerGroups: DataTableHeaderGroupInstance<TData>[];
@@ -160,6 +162,7 @@ type SkeletonColumn = {
160
162
  size?: number;
161
163
  minSize?: number;
162
164
  maxSize?: number;
165
+ actions?: boolean;
163
166
  };
164
167
  declare function DataTableSkeletonBody({ rowCount, columns, renderCell, layout, }: {
165
168
  rowCount?: number;
@@ -254,6 +257,10 @@ interface DataTableProps<TData extends RowData> {
254
257
  config: TableHookOptions<TData>;
255
258
  title?: ReactNode;
256
259
  description?: ReactNode;
260
+ /**
261
+ * Shows skeleton rows. After the user changes page or page size, the current rows stay visible
262
+ * instead and the clicked pagination control shows a spinner until `loading` turns off.
263
+ */
257
264
  loading?: boolean;
258
265
  renderSkeletonCell?: (columnId: string) => ReactNode | undefined;
259
266
  showError?: boolean;
@@ -718,7 +718,7 @@ function TimestampCell({ timestamp }) {
718
718
  }
719
719
 
720
720
  // src/data-table/data-table.tsx
721
- import * as React10 from "react";
721
+ import * as React11 from "react";
722
722
  import {
723
723
  useTable
724
724
  } from "@tanstack/react-table";
@@ -3165,6 +3165,7 @@ function FilterToggle({ pressed, onPressedChange, count }) {
3165
3165
  }
3166
3166
 
3167
3167
  // src/data-table/pagination.tsx
3168
+ import * as React7 from "react";
3168
3169
  import { Button as Button6 } from "@upbound/monarch-core";
3169
3170
  import { Icon as Icon7 } from "@upbound/monarch-core";
3170
3171
  import { Label as Label2 } from "@upbound/monarch-core";
@@ -3176,6 +3177,7 @@ import {
3176
3177
  PaginationLink
3177
3178
  } from "@upbound/monarch-core";
3178
3179
  import { Select as Select2, SelectContent as SelectContent2, SelectGroup as SelectGroup2, SelectItem as SelectItem2, SelectTrigger as SelectTrigger2, SelectValue as SelectValue2 } from "@upbound/monarch-core";
3180
+ import { Spinner } from "@upbound/monarch-core";
3179
3181
  import { Tooltip as Tooltip3, TooltipContent as TooltipContent3, TooltipTrigger as TooltipTrigger3 } from "@upbound/monarch-core";
3180
3182
  import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
3181
3183
  var DEFAULT_PAGINATION_CONFIG = {
@@ -3186,6 +3188,12 @@ var DEFAULT_PAGINATION_CONFIG = {
3186
3188
  pageSizeOptions: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
3187
3189
  };
3188
3190
  var PAGE_SIZE_SELECT_ID = "table-page-size-select";
3191
+ var PAGE_ARROWS = {
3192
+ first: { label: "Go to first page", icon: "chevrons-left" },
3193
+ previous: { label: "Go to previous page", icon: "chevron-left" },
3194
+ next: { label: "Go to next page", icon: "chevron-right" },
3195
+ last: { label: "Go to last page", icon: "chevrons-right" }
3196
+ };
3189
3197
  function getPageSizeOptions(pageSizeOptions) {
3190
3198
  return Array.from(new Set(pageSizeOptions)).filter((option) => option > 0).sort((a, b) => a - b);
3191
3199
  }
@@ -3206,9 +3214,11 @@ function DataTablePagination({
3206
3214
  rowCount,
3207
3215
  rowCountRelation = "eq",
3208
3216
  paginationConfig = true,
3217
+ loading = false,
3209
3218
  onPageChange,
3210
3219
  onPageSizeChange
3211
3220
  }) {
3221
+ const [requestedControl, setRequestedControl] = React7.useState(null);
3212
3222
  const isRowCountExact = rowCountRelation === "eq";
3213
3223
  const resolved = typeof paginationConfig === "object" ? __spreadValues(__spreadValues({}, DEFAULT_PAGINATION_CONFIG), paginationConfig) : DEFAULT_PAGINATION_CONFIG;
3214
3224
  const { normalizedPageSizeOptions, effectivePageSize } = normalizePageSizeOptions(pageSize, resolved.pageSizeOptions);
@@ -3216,6 +3226,33 @@ function DataTablePagination({
3216
3226
  const currentPage = pageIndex + 1;
3217
3227
  const mounted = useMounted();
3218
3228
  const locale = mounted ? void 0 : "en-US";
3229
+ const isLoadingControl = (control) => loading && requestedControl === control;
3230
+ const goToPage = (page, control) => {
3231
+ if (loading) return;
3232
+ setRequestedControl(control);
3233
+ onPageChange(page);
3234
+ };
3235
+ const changePageSize = (nextPageSize) => {
3236
+ setRequestedControl(null);
3237
+ onPageSizeChange(nextPageSize);
3238
+ };
3239
+ const renderArrow = (arrow, page, disabled) => {
3240
+ const { label, icon } = PAGE_ARROWS[arrow];
3241
+ const isRequested = isLoadingControl(arrow);
3242
+ return /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
3243
+ Button6,
3244
+ {
3245
+ variant: "outline",
3246
+ size: "icon",
3247
+ "aria-label": label,
3248
+ "aria-busy": isRequested || void 0,
3249
+ "aria-disabled": isRequested || void 0,
3250
+ disabled: !isRequested && (disabled || loading),
3251
+ onClick: () => goToPage(page, arrow),
3252
+ children: isRequested ? /* @__PURE__ */ jsx9(Spinner, {}) : /* @__PURE__ */ jsx9(Icon7, { name: icon, className: "cn-rtl-flip" })
3253
+ }
3254
+ ) });
3255
+ };
3219
3256
  return /* @__PURE__ */ jsxs9("div", { "data-testid": "table-footer", className: "flex items-center justify-between px-2 pt-4", children: [
3220
3257
  resolved.summary ? /* @__PURE__ */ jsxs9("div", { className: "text-body text-muted-foreground", "data-testid": "table-pagination-summary", children: [
3221
3258
  "Showing ",
@@ -3239,34 +3276,22 @@ function DataTablePagination({
3239
3276
  /* @__PURE__ */ jsxs9("div", { className: "flex items-center gap-4", children: [
3240
3277
  resolved.pageSizeSelector && /* @__PURE__ */ jsxs9("div", { className: "flex items-center gap-2", children: [
3241
3278
  /* @__PURE__ */ jsx9(Label2, { htmlFor: PAGE_SIZE_SELECT_ID, className: "font-semibold", children: "Rows per page" }),
3242
- /* @__PURE__ */ jsxs9(Select2, { value: String(effectivePageSize), onValueChange: (value) => onPageSizeChange(Number(value)), children: [
3243
- /* @__PURE__ */ jsx9(SelectTrigger2, { id: PAGE_SIZE_SELECT_ID, size: "sm", className: "w-18", "data-testid": "table-page-size-select", children: /* @__PURE__ */ jsx9(SelectValue2, {}) }),
3244
- /* @__PURE__ */ jsx9(SelectContent2, { align: "end", children: /* @__PURE__ */ jsx9(SelectGroup2, { children: normalizedPageSizeOptions.map((option) => /* @__PURE__ */ jsx9(SelectItem2, { value: String(option), children: option }, option)) }) })
3245
- ] })
3246
- ] }),
3247
- pageCount > 1 && (resolved.arrows || resolved.numbers) && /* @__PURE__ */ jsx9(Pagination, { className: "mx-0 w-auto justify-end", children: /* @__PURE__ */ jsxs9(PaginationContent, { children: [
3248
- resolved.arrows && /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
3249
- Button6,
3250
- {
3251
- variant: "outline",
3252
- size: "icon",
3253
- "aria-label": "Go to first page",
3254
- disabled: currentPage <= 1,
3255
- onClick: () => onPageChange(1),
3256
- children: /* @__PURE__ */ jsx9(Icon7, { name: "chevrons-left", className: "cn-rtl-flip" })
3257
- }
3258
- ) }),
3259
- resolved.arrows && /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
3260
- Button6,
3279
+ /* @__PURE__ */ jsxs9(
3280
+ Select2,
3261
3281
  {
3262
- variant: "outline",
3263
- size: "icon",
3264
- "aria-label": "Go to previous page",
3265
- disabled: currentPage <= 1,
3266
- onClick: () => onPageChange(currentPage - 1),
3267
- children: /* @__PURE__ */ jsx9(Icon7, { name: "chevron-left", className: "cn-rtl-flip" })
3282
+ value: String(effectivePageSize),
3283
+ onValueChange: (value) => changePageSize(Number(value)),
3284
+ disabled: loading,
3285
+ children: [
3286
+ /* @__PURE__ */ jsx9(SelectTrigger2, { id: PAGE_SIZE_SELECT_ID, size: "sm", className: "w-18", "data-testid": "table-page-size-select", children: /* @__PURE__ */ jsx9(SelectValue2, {}) }),
3287
+ /* @__PURE__ */ jsx9(SelectContent2, { align: "end", children: /* @__PURE__ */ jsx9(SelectGroup2, { children: normalizedPageSizeOptions.map((option) => /* @__PURE__ */ jsx9(SelectItem2, { value: String(option), children: option }, option)) }) })
3288
+ ]
3268
3289
  }
3269
- ) }),
3290
+ )
3291
+ ] }),
3292
+ pageCount > 1 && (resolved.arrows || resolved.numbers) && /* @__PURE__ */ jsx9(Pagination, { className: "mx-0 w-auto justify-end", children: /* @__PURE__ */ jsxs9(PaginationContent, { children: [
3293
+ resolved.arrows && renderArrow("first", 1, currentPage <= 1),
3294
+ resolved.arrows && renderArrow("previous", currentPage - 1, currentPage <= 1),
3270
3295
  resolved.numbers && visiblePages.map(
3271
3296
  (page, index) => page === void 0 ? /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(PaginationEllipsis, {}) }, `ellipsis-${index}`) : /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
3272
3297
  PaginationLink,
@@ -3274,43 +3299,27 @@ function DataTablePagination({
3274
3299
  href: "#",
3275
3300
  size: "icon",
3276
3301
  isActive: page === currentPage,
3302
+ "aria-label": `Go to page ${page}`,
3303
+ "aria-busy": isLoadingControl(page) || void 0,
3304
+ "aria-disabled": loading || void 0,
3305
+ className: cn(loading && !isLoadingControl(page) && "opacity-50"),
3277
3306
  onClick: (e) => {
3278
3307
  e.preventDefault();
3279
- onPageChange(page);
3308
+ goToPage(page, page);
3280
3309
  },
3281
- children: page
3310
+ children: isLoadingControl(page) ? /* @__PURE__ */ jsx9(Spinner, {}) : page
3282
3311
  }
3283
3312
  ) }, page)
3284
3313
  ),
3285
- resolved.arrows && /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
3286
- Button6,
3287
- {
3288
- variant: "outline",
3289
- size: "icon",
3290
- "aria-label": "Go to next page",
3291
- disabled: currentPage >= pageCount,
3292
- onClick: () => onPageChange(currentPage + 1),
3293
- children: /* @__PURE__ */ jsx9(Icon7, { name: "chevron-right", className: "cn-rtl-flip" })
3294
- }
3295
- ) }),
3296
- resolved.arrows && /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
3297
- Button6,
3298
- {
3299
- variant: "outline",
3300
- size: "icon",
3301
- "aria-label": "Go to last page",
3302
- disabled: currentPage >= pageCount,
3303
- onClick: () => onPageChange(pageCount),
3304
- children: /* @__PURE__ */ jsx9(Icon7, { name: "chevrons-right", className: "cn-rtl-flip" })
3305
- }
3306
- ) })
3314
+ resolved.arrows && renderArrow("next", currentPage + 1, currentPage >= pageCount),
3315
+ resolved.arrows && renderArrow("last", pageCount, currentPage >= pageCount)
3307
3316
  ] }) })
3308
3317
  ] })
3309
3318
  ] });
3310
3319
  }
3311
3320
 
3312
3321
  // src/data-table/table-primitives.tsx
3313
- import * as React7 from "react";
3322
+ import * as React8 from "react";
3314
3323
  import { flexRender as flexRender2 } from "@tanstack/react-table";
3315
3324
  import { ContextMenu, ContextMenuTrigger } from "@upbound/monarch-core";
3316
3325
  import {
@@ -3641,7 +3650,7 @@ function DataTableHeader({
3641
3650
  }
3642
3651
  return /* @__PURE__ */ jsx10(BaseTableHeader, { children: headerGroups.map((headerGroup, headerGroupIndex) => /* @__PURE__ */ jsx10(BaseTableRow, { children: renderHeaders(headerGroup, headerGroupIndex) }, headerGroup.id)) });
3643
3652
  }
3644
- var DataTableRow = React7.forwardRef(
3653
+ var DataTableRow = React8.forwardRef(
3645
3654
  (_a, ref) => {
3646
3655
  var _b = _a, { hoverable, disabled, className, layout = "auto" } = _b, props = __objRest(_b, ["hoverable", "disabled", "className", "layout"]);
3647
3656
  const classes = cn(
@@ -3744,6 +3753,10 @@ function DataTableGroupRow({
3744
3753
  }
3745
3754
  return /* @__PURE__ */ jsx10(BaseTableRow, { className: "bg-muted/50 hover:bg-muted/50", children: /* @__PURE__ */ jsx10(BaseTableCell, { colSpan, className: "text-foreground border-b font-semibold whitespace-nowrap", children: groupLabel }) });
3746
3755
  }
3756
+ function DefaultSkeletonCell({ actions }) {
3757
+ if (actions) return /* @__PURE__ */ jsx10(Skeleton, { className: "ml-auto size-6" });
3758
+ return /* @__PURE__ */ jsx10("div", { className: "flex h-lh w-full items-center", children: /* @__PURE__ */ jsx10(Skeleton, { className: "h-4 w-full" }) });
3759
+ }
3747
3760
  function DataTableSkeletonBody({
3748
3761
  rowCount = 10,
3749
3762
  columns,
@@ -3760,14 +3773,14 @@ function DataTableSkeletonBody({
3760
3773
  role: "cell",
3761
3774
  className: cn(TABLE_CELL_CLASSES, "flex items-center overflow-hidden"),
3762
3775
  style: { minWidth: col.minSize },
3763
- children: (_a = renderCell == null ? void 0 : renderCell(col.id)) != null ? _a : /* @__PURE__ */ jsx10(Skeleton, { className: "h-4 w-full" })
3776
+ children: (_a = renderCell == null ? void 0 : renderCell(col.id)) != null ? _a : /* @__PURE__ */ jsx10(DefaultSkeletonCell, { actions: col.actions })
3764
3777
  },
3765
3778
  `skeleton-col-${col.id}-row-${rowIndex}`
3766
3779
  ) : /* @__PURE__ */ jsx10(
3767
3780
  BaseTableCell,
3768
3781
  {
3769
3782
  style: { width: col.size, minWidth: col.minSize, maxWidth: col.maxSize },
3770
- children: (_b = renderCell == null ? void 0 : renderCell(col.id)) != null ? _b : /* @__PURE__ */ jsx10(Skeleton, { className: "h-4 w-full" })
3783
+ children: (_b = renderCell == null ? void 0 : renderCell(col.id)) != null ? _b : /* @__PURE__ */ jsx10(DefaultSkeletonCell, { actions: col.actions })
3771
3784
  },
3772
3785
  `skeleton-col-${col.id}-row-${rowIndex}`
3773
3786
  );
@@ -3808,12 +3821,16 @@ function DataTableBody({
3808
3821
  const visibleColumns = columns.filter((column) => !isFilterOnlyColumn(column));
3809
3822
  const colSpan = visibleColumns.length;
3810
3823
  if (tableState === "loading") {
3811
- const skeletonColumns = visibleColumns.map((c) => ({
3812
- id: c.id,
3813
- size: c.columnDef.size,
3814
- minSize: c.columnDef.minSize,
3815
- maxSize: c.columnDef.maxSize
3816
- }));
3824
+ const skeletonColumns = visibleColumns.map((c) => {
3825
+ var _a;
3826
+ return {
3827
+ id: c.id,
3828
+ size: c.columnDef.size,
3829
+ minSize: c.columnDef.minSize,
3830
+ maxSize: c.columnDef.maxSize,
3831
+ actions: !!((_a = c.columnDef.meta) == null ? void 0 : _a.actions)
3832
+ };
3833
+ });
3817
3834
  return /* @__PURE__ */ jsx10(
3818
3835
  DataTableSkeletonBody,
3819
3836
  {
@@ -3832,7 +3849,7 @@ function DataTableBody({
3832
3849
  }
3833
3850
  const isExpanded = !!(((_d = row.getCanExpand) == null ? void 0 : _d.call(row)) && ((_e = row.getIsExpanded) == null ? void 0 : _e.call(row)));
3834
3851
  const expandedRow = renderExpandedRow && isExpanded ? renderExpandedRow(row.original) : null;
3835
- return /* @__PURE__ */ jsxs10(React7.Fragment, { children: [
3852
+ return /* @__PURE__ */ jsxs10(React8.Fragment, { children: [
3836
3853
  /* @__PURE__ */ jsx10(
3837
3854
  DataTableRow,
3838
3855
  __spreadProps(__spreadValues({}, onRowRender ? onRowRender(row.original, row) : {}), {
@@ -3863,10 +3880,10 @@ function DataTableBody({
3863
3880
  }
3864
3881
 
3865
3882
  // src/data-table/view-filter.tsx
3866
- import * as React9 from "react";
3883
+ import * as React10 from "react";
3867
3884
 
3868
3885
  // src/filter-bar/filter-bar.tsx
3869
- import * as React8 from "react";
3886
+ import * as React9 from "react";
3870
3887
  import { Icon as Icon9 } from "@upbound/monarch-core";
3871
3888
  import { Badge as Badge3 } from "@upbound/monarch-core";
3872
3889
  import { Button as Button7 } from "@upbound/monarch-core";
@@ -3966,12 +3983,12 @@ function FilterBar(_a) {
3966
3983
  const remainingFilters = filters.filter((f) => !usedKeys.has(f.key));
3967
3984
  const availableFilters = filters.some(hasOrder) ? remainingFilters : sortBy(remainingFilters, (f) => f.label);
3968
3985
  const shouldShowFilters = availableFilters.length > 0 || activeFilters.length > 0;
3969
- const [pendingOpenKey, setPendingOpenKey] = React8.useState(null);
3986
+ const [pendingOpenKey, setPendingOpenKey] = React9.useState(null);
3970
3987
  function handleAddFilter(key) {
3971
3988
  onAddFilter(key);
3972
3989
  setPendingOpenKey(key);
3973
3990
  }
3974
- const containerRef = React8.useRef(null);
3991
+ const containerRef = React9.useRef(null);
3975
3992
  return /* @__PURE__ */ jsxs11(
3976
3993
  "div",
3977
3994
  __spreadProps(__spreadValues({
@@ -4256,7 +4273,7 @@ function TextFilterChip({
4256
4273
  }) {
4257
4274
  const { label, placeholder } = definition;
4258
4275
  const text = asTextValue(value);
4259
- const [open, setOpen] = React8.useState(!!autoOpen);
4276
+ const [open, setOpen] = React9.useState(!!autoOpen);
4260
4277
  return /* @__PURE__ */ jsxs11(ButtonGroup2, { children: [
4261
4278
  /* @__PURE__ */ jsx11(ButtonGroupText2, { children: label }),
4262
4279
  /* @__PURE__ */ jsxs11(Popover2, { open, onOpenChange: setOpen, children: [
@@ -4286,7 +4303,7 @@ function MultiTextFilterChip({
4286
4303
  }) {
4287
4304
  const { label, placeholder } = definition;
4288
4305
  const tokens = asMultiTextValue(value);
4289
- const [draft, setDraft] = React8.useState("");
4306
+ const [draft, setDraft] = React9.useState("");
4290
4307
  const displayLabel = tokens.length === 0 ? "Any" : tokens.length === 1 ? tokens[0] : `${tokens.length} values`;
4291
4308
  function addToken() {
4292
4309
  const token = draft.trim();
@@ -4474,7 +4491,7 @@ function ViewFilter({
4474
4491
  onColumnFiltersChange,
4475
4492
  className
4476
4493
  }) {
4477
- const filterableColumns = React9.useMemo(
4494
+ const filterableColumns = React10.useMemo(
4478
4495
  () => columns.filter((column) => column.getCanFilter()).flatMap((column) => {
4479
4496
  var _a;
4480
4497
  const filter = (_a = column.columnDef.meta) == null ? void 0 : _a.filter;
@@ -4482,7 +4499,7 @@ function ViewFilter({
4482
4499
  }),
4483
4500
  [columns]
4484
4501
  );
4485
- const filterDefinitions = React9.useMemo(
4502
+ const filterDefinitions = React10.useMemo(
4486
4503
  () => filterableColumns.map(({ key, filter }) => toFilterBarDefinition(key, filter)).sort((a, b) => {
4487
4504
  if (a.order == null && b.order == null) return 0;
4488
4505
  if (a.order == null) return 1;
@@ -4491,11 +4508,11 @@ function ViewFilter({
4491
4508
  }),
4492
4509
  [filterableColumns]
4493
4510
  );
4494
- const emptyValueByKey = React9.useMemo(
4511
+ const emptyValueByKey = React10.useMemo(
4495
4512
  () => new Map(filterableColumns.map(({ key, filter }) => [key, emptyValueFor(filter)])),
4496
4513
  [filterableColumns]
4497
4514
  );
4498
- const activeFilters = React9.useMemo(
4515
+ const activeFilters = React10.useMemo(
4499
4516
  () => columnFilters.map((filter) => ({ key: filter.id, value: filter.value })),
4500
4517
  [columnFilters]
4501
4518
  );
@@ -4544,6 +4561,9 @@ import { Fragment as Fragment7, jsx as jsx14, jsxs as jsxs12 } from "react/jsx-r
4544
4561
  var DEFAULT_PAGE_SIZE = 20;
4545
4562
  var noop = () => {
4546
4563
  };
4564
+ function isSamePage(a, b) {
4565
+ return a.pageIndex === b.pageIndex && a.pageSize === b.pageSize;
4566
+ }
4547
4567
  var STICKY_HEADER_MAX_HEIGHT_CLASS = "max-h-[calc(100svh-250px)]";
4548
4568
  function DataTable({
4549
4569
  id,
@@ -4600,19 +4620,19 @@ function DataTable({
4600
4620
  }) {
4601
4621
  var _a, _b, _c, _d, _e, _f, _g;
4602
4622
  const isGrid = layout === "grid";
4603
- const tableBodyScrollRef = React10.useRef(null);
4604
- const [innerGlobalFilter, setInnerGlobalFilter] = React10.useState("");
4605
- const [innerColumnOrdering, setInnerColumnOrdering] = React10.useState([]);
4606
- const [innerColumnFilters, setInnerColumnFilters] = React10.useState([]);
4607
- const [innerSorting, setInnerSorting] = React10.useState(((_a = config.state) == null ? void 0 : _a.sorting) || []);
4608
- const [innerColumnPinning, setInnerColumnPinning] = React10.useState({ start: [], end: [] });
4609
- const [innerPagination, setInnerPagination] = React10.useState({
4623
+ const tableBodyScrollRef = React11.useRef(null);
4624
+ const [innerGlobalFilter, setInnerGlobalFilter] = React11.useState("");
4625
+ const [innerColumnOrdering, setInnerColumnOrdering] = React11.useState([]);
4626
+ const [innerColumnFilters, setInnerColumnFilters] = React11.useState([]);
4627
+ const [innerSorting, setInnerSorting] = React11.useState(((_a = config.state) == null ? void 0 : _a.sorting) || []);
4628
+ const [innerColumnPinning, setInnerColumnPinning] = React11.useState({ start: [], end: [] });
4629
+ const [innerPagination, setInnerPagination] = React11.useState({
4610
4630
  pageIndex: ((_c = (_b = config.state) == null ? void 0 : _b.pagination) == null ? void 0 : _c.pageIndex) || 0,
4611
4631
  pageSize: ((_e = (_d = config.state) == null ? void 0 : _d.pagination) == null ? void 0 : _e.pageSize) || DEFAULT_PAGE_SIZE
4612
4632
  });
4613
- const [innerGrouping, setInnerGrouping] = React10.useState([]);
4614
- const [innerColumnVisibility, setInnerColumnVisibility] = React10.useState({});
4615
- const [innerExpanded, setInnerExpanded] = React10.useState({});
4633
+ const [innerGrouping, setInnerGrouping] = React11.useState([]);
4634
+ const [innerColumnVisibility, setInnerColumnVisibility] = React11.useState({});
4635
+ const [innerExpanded, setInnerExpanded] = React11.useState({});
4616
4636
  const {
4617
4637
  columnSizing,
4618
4638
  handleColumnSizingChange,
@@ -4639,25 +4659,36 @@ function DataTable({
4639
4659
  const pagination = parentPagination || innerPagination;
4640
4660
  const setPagination = parentSetPagination != null ? parentSetPagination : setInnerPagination;
4641
4661
  const shouldDisablePagination = paginationConfig === false;
4642
- const resetPageIndexOnFilterChange = React10.useCallback(() => {
4662
+ const [pageRequest, setPageRequest] = React11.useState(null);
4663
+ if (pageRequest && !loading && isSamePage(pageRequest.pagination, pagination)) {
4664
+ setPageRequest(null);
4665
+ }
4666
+ const pageLoading = loading && pageRequest !== null;
4667
+ const shownConfig = pageLoading ? __spreadValues(__spreadValues({}, config), pageRequest.rows) : config;
4668
+ const requestPage = (nextPagination) => {
4669
+ const { data, rowCount: rowCount2, rowCountRelation } = config;
4670
+ setPageRequest({ pagination: nextPagination, rows: { data, rowCount: rowCount2, rowCountRelation } });
4671
+ setPagination(nextPagination);
4672
+ };
4673
+ const resetPageIndexOnFilterChange = React11.useCallback(() => {
4643
4674
  if (!serverSidePagination || pagination.pageIndex === 0) return;
4644
4675
  setPagination((prev) => __spreadProps(__spreadValues({}, prev), { pageIndex: 0 }));
4645
4676
  }, [serverSidePagination, pagination.pageIndex, setPagination]);
4646
- const setGlobalFilter = React10.useCallback(
4677
+ const setGlobalFilter = React11.useCallback(
4647
4678
  (value) => {
4648
4679
  applyGlobalFilter(value);
4649
4680
  resetPageIndexOnFilterChange();
4650
4681
  },
4651
4682
  [applyGlobalFilter, resetPageIndexOnFilterChange]
4652
4683
  );
4653
- const setColumnFilters = React10.useCallback(
4684
+ const setColumnFilters = React11.useCallback(
4654
4685
  (value) => {
4655
4686
  applyColumnFilters(value);
4656
4687
  resetPageIndexOnFilterChange();
4657
4688
  },
4658
4689
  [applyColumnFilters, resetPageIndexOnFilterChange]
4659
4690
  );
4660
- React10.useLayoutEffect(() => {
4691
+ React11.useLayoutEffect(() => {
4661
4692
  var _a2;
4662
4693
  if (shouldDisablePagination) return;
4663
4694
  (_a2 = tableBodyScrollRef.current) == null ? void 0 : _a2.scrollTo({ top: 0 });
@@ -4681,8 +4712,8 @@ function DataTable({
4681
4712
  const hasExternalSearch = parentGlobalFilter !== void 0;
4682
4713
  const hasExternalFilters = parentColumnFilters !== void 0;
4683
4714
  const shouldDisableFiltersModels = !!disableFilters && !!disableSearch && !hasExternalSearch && !hasExternalFilters;
4684
- const columns = React10.useMemo(() => withDefaultFilterFns(config.columns), [config.columns]);
4685
- const table = useTable(__spreadProps(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, config), {
4715
+ const columns = React11.useMemo(() => withDefaultFilterFns(config.columns), [config.columns]);
4716
+ const table = useTable(__spreadProps(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, shownConfig), {
4686
4717
  columns,
4687
4718
  features: dataTableFeatures,
4688
4719
  // Row models are registered statically in `dataTableFeatures`, so a disabled stage is switched
@@ -4741,7 +4772,7 @@ function DataTable({
4741
4772
  const orderedVisibleColumns = table.getVisibleLeafColumns().filter((col) => !isFilterOnlyColumn(col));
4742
4773
  const hasFilters = !!celFilterConfig || hasFilterableColumns(flatColumns);
4743
4774
  const showFilterToggle = filterToggleRequested && !disableFilters && hasFilters;
4744
- const [gridMeasuredMins, setGridMeasuredMins] = React10.useState({});
4775
+ const [gridMeasuredMins, setGridMeasuredMins] = React11.useState({});
4745
4776
  const { gridTemplateColumns, gridRootRef, handleAutosizeAll, handleAutosizeColumn, handleResetColumnSize } = useGridLayout({
4746
4777
  layout,
4747
4778
  table,
@@ -4755,7 +4786,7 @@ function DataTable({
4755
4786
  rawHandleAutosizeColumn,
4756
4787
  rawHandleResetColumnSize
4757
4788
  });
4758
- const handleContextCell = React10.useCallback(
4789
+ const handleContextCell = React11.useCallback(
4759
4790
  (filter, cell) => {
4760
4791
  var _a2, _b2;
4761
4792
  if (celFilterConfig == null ? void 0 : celFilterConfig.onContextualFilter) {
@@ -4772,13 +4803,13 @@ function DataTable({
4772
4803
  },
4773
4804
  [celFilterConfig, onContextCell, setColumnFilters, table]
4774
4805
  );
4775
- const handleContextSearch = React10.useCallback(
4806
+ const handleContextSearch = React11.useCallback(
4776
4807
  (searchTerm) => {
4777
4808
  setGlobalFilter(searchTerm);
4778
4809
  },
4779
4810
  [setGlobalFilter]
4780
4811
  );
4781
- const totalTableWidth = React10.useMemo(() => {
4812
+ const totalTableWidth = React11.useMemo(() => {
4782
4813
  if (isGrid) return 0;
4783
4814
  const firstGroup = headerGroups[0];
4784
4815
  if (!firstGroup) return 0;
@@ -4791,7 +4822,7 @@ function DataTable({
4791
4822
  return getColumnFilterCount(value, (_b2 = (_a2 = table.getColumn(columnFilterId)) == null ? void 0 : _a2.columnDef.meta) == null ? void 0 : _b2.filter);
4792
4823
  }
4793
4824
  ).reduce((prev, curr) => prev + curr, 0);
4794
- const tableState = getTableState({ error: !!showError, loading, rowCount });
4825
+ const tableState = getTableState({ error: !!showError, loading: loading && !pageLoading, rowCount });
4795
4826
  const shouldDisable = tableState === "error";
4796
4827
  const shouldRenderTableContent = tableState !== "error" && tableState !== "empty";
4797
4828
  const resetFilters = () => {
@@ -4802,7 +4833,7 @@ function DataTable({
4802
4833
  }
4803
4834
  setGlobalFilter("");
4804
4835
  };
4805
- React10.useEffect(() => {
4836
+ React11.useEffect(() => {
4806
4837
  if (disableColumnReordering) return;
4807
4838
  const allColumnIds = flatColumns.map((col) => col.id);
4808
4839
  const normalizedColumnOrdering = normalizeColumnOrdering(columnOrdering, allColumnIds);
@@ -4928,12 +4959,13 @@ function DataTable({
4928
4959
  DataTablePagination,
4929
4960
  {
4930
4961
  rowCount,
4931
- rowCountRelation: (_g = config.rowCountRelation) != null ? _g : "eq",
4962
+ rowCountRelation: (_g = shownConfig.rowCountRelation) != null ? _g : "eq",
4932
4963
  paginationConfig,
4964
+ loading: pageLoading,
4933
4965
  pageSize: pagination.pageSize,
4934
4966
  pageIndex: pagination.pageIndex,
4935
- onPageChange: (p) => table.setPageIndex(p - 1),
4936
- onPageSizeChange: (nextPageSize) => setPagination((prev) => __spreadProps(__spreadValues({}, prev || pagination), { pageIndex: 0, pageSize: nextPageSize }))
4967
+ onPageChange: (p) => requestPage(__spreadProps(__spreadValues({}, pagination), { pageIndex: p - 1 })),
4968
+ onPageSizeChange: (pageSize) => requestPage({ pageIndex: 0, pageSize })
4937
4969
  }
4938
4970
  )
4939
4971
  ] }) : /* @__PURE__ */ jsx14(