@coldsmirk/ledger-mantine 0.11.1 → 0.12.1

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.cjs CHANGED
@@ -1670,6 +1670,67 @@ function ledgerCommands(meta) {
1670
1670
  return meta;
1671
1671
  }
1672
1672
  //#endregion
1673
+ //#region src/load-more-retry.ts
1674
+ /**
1675
+ * The retry of a next page that could not be read. Pressed, it is held — the row and its button
1676
+ * stay, the focus with them, and a press asks nothing — until the page is answered: `loadingMore`
1677
+ * said and unsaid, or, from a host that never says it, new `data` or a new `loadMoreError`. A host
1678
+ * may keep `loadMoreError` while it asks again or clear it; the row stays either way.
1679
+ */
1680
+ function useLoadMoreRetry({ data, loadingMore, loadMoreError, askAgain, viewportRef }) {
1681
+ const [asked, setAsked] = (0, react.useState)(null);
1682
+ if (asked) {
1683
+ if (loadingMore) {
1684
+ if (!asked.loadingSeen) setAsked({
1685
+ ...asked,
1686
+ loadingSeen: true
1687
+ });
1688
+ } else if (asked.loadingSeen || loadMoreError !== asked.loadMoreError || data !== asked.data) setAsked(null);
1689
+ }
1690
+ const held = asked !== null || loadingMore;
1691
+ const retry = useEventCallback(() => {
1692
+ if (held) return;
1693
+ setAsked({
1694
+ data,
1695
+ loadMoreError,
1696
+ loadingSeen: false
1697
+ });
1698
+ askAgain?.();
1699
+ });
1700
+ const [viewportHoldsHandedFocus, setViewportHoldsHandedFocus] = (0, react.useState)(false);
1701
+ const release = useEventCallback(() => setViewportHoldsHandedFocus(true));
1702
+ (0, react.useLayoutEffect)(() => {
1703
+ if (viewportHoldsHandedFocus) viewportRef.current?.focus({ preventScroll: true });
1704
+ }, [viewportHoldsHandedFocus, viewportRef]);
1705
+ const onViewportBlur = useEventCallback((event) => {
1706
+ if (event.target === event.currentTarget) setViewportHoldsHandedFocus(false);
1707
+ });
1708
+ const shown = asked !== null || Boolean(loadMoreError);
1709
+ const canRetry = askAgain !== void 0;
1710
+ return {
1711
+ row: (0, react.useMemo)(() => {
1712
+ if (shown) return {
1713
+ kind: "retry",
1714
+ failure: loadMoreError,
1715
+ held,
1716
+ retry: canRetry ? retry : void 0,
1717
+ release
1718
+ };
1719
+ return loadingMore ? { kind: "loading" } : null;
1720
+ }, [
1721
+ shown,
1722
+ loadMoreError,
1723
+ held,
1724
+ canRetry,
1725
+ retry,
1726
+ release,
1727
+ loadingMore
1728
+ ]),
1729
+ viewportHoldsHandedFocus,
1730
+ onViewportBlur
1731
+ };
1732
+ }
1733
+ //#endregion
1673
1734
  //#region src/pagination-bar.tsx
1674
1735
  /**
1675
1736
  * The pagination bar: summary on the start side, rows-per-page and page controls on the end
@@ -1773,6 +1834,125 @@ function DataTablePagination(props) {
1773
1834
  });
1774
1835
  }
1775
1836
  //#endregion
1837
+ //#region src/scroll-snapshot.ts
1838
+ /**
1839
+ * Opaque scroll-restoration snapshots (`docs/virtualization.md#restoring-scroll-position`).
1840
+ *
1841
+ * A snapshot captures plain, JSON-serializable scroll geometry — the viewport's offsets, its last
1842
+ * known dimensions, and TanStack Virtual's measured row heights (`takeSnapshot()`) — tagged with a
1843
+ * shape version so storage/history payloads from another version of ledger fail validation instead
1844
+ * of restoring corrupt numbers.
1845
+ */
1846
+ const SCROLL_SNAPSHOT_VERSION = 1;
1847
+ function isRecord$1(value) {
1848
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1849
+ }
1850
+ function isFiniteNumber$1(value) {
1851
+ return typeof value === "number" && Number.isFinite(value);
1852
+ }
1853
+ function isNonNegativeFinite(value) {
1854
+ return isFiniteNumber$1(value) && value >= 0;
1855
+ }
1856
+ function isNonNegativeInteger(value) {
1857
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
1858
+ }
1859
+ function isViewportRect(value) {
1860
+ if (!isRecord$1(value)) return false;
1861
+ return isNonNegativeFinite(value.width) && isNonNegativeFinite(value.height);
1862
+ }
1863
+ function isSerializedVirtualItem(value) {
1864
+ if (!isRecord$1(value)) return false;
1865
+ const validKey = typeof value.key === "string" || isFiniteNumber$1(value.key);
1866
+ return isNonNegativeInteger(value.index) && validKey && isFiniteNumber$1(value.start) && isNonNegativeFinite(value.size) && isFiniteNumber$1(value.end) && isNonNegativeInteger(value.lane);
1867
+ }
1868
+ /**
1869
+ * Validates an unknown value — such as one read back from `sessionStorage` or router history
1870
+ * state — as a {@link DataTableScrollSnapshot} written by this version of ledger.
1871
+ */
1872
+ function isDataTableScrollSnapshot(value) {
1873
+ if (!isRecord$1(value) || value.version !== SCROLL_SNAPSHOT_VERSION) return false;
1874
+ if (!isNonNegativeFinite(value.scrollTop) || !isFiniteNumber$1(value.scrollLeft)) return false;
1875
+ if (value.viewport !== null && !isViewportRect(value.viewport)) return false;
1876
+ return value.measurements === null || Array.isArray(value.measurements) && value.measurements.every(isSerializedVirtualItem);
1877
+ }
1878
+ /**
1879
+ * Validates and unwraps a snapshot at the component boundary. Invalid or mismatched-version
1880
+ * payloads degrade to `null` instead of throwing.
1881
+ */
1882
+ function readScrollSnapshot(value) {
1883
+ if (!isDataTableScrollSnapshot(value)) return null;
1884
+ return value;
1885
+ }
1886
+ function readViewportRect(viewport, virtualizer) {
1887
+ const virtualRect = virtualizer?.scrollRect;
1888
+ if (virtualRect && virtualRect.width > 0 && virtualRect.height > 0) return {
1889
+ width: Math.round(virtualRect.width),
1890
+ height: Math.round(virtualRect.height)
1891
+ };
1892
+ const width = Math.round(viewport.offsetWidth);
1893
+ const height = Math.round(viewport.offsetHeight);
1894
+ if (width > 0 && height > 0) return {
1895
+ width,
1896
+ height
1897
+ };
1898
+ return null;
1899
+ }
1900
+ function serializeVirtualMeasurements(virtualizer) {
1901
+ const items = [];
1902
+ for (const item of virtualizer.takeSnapshot()) {
1903
+ if (typeof item.key !== "string" && !(typeof item.key === "number" && Number.isFinite(item.key))) continue;
1904
+ items.push({
1905
+ index: item.index,
1906
+ key: item.key,
1907
+ start: item.start,
1908
+ size: item.size,
1909
+ end: item.end,
1910
+ lane: item.lane
1911
+ });
1912
+ }
1913
+ return items;
1914
+ }
1915
+ /**
1916
+ * Captures the viewport's current scroll offsets, dimensions, and measured virtualizer row heights
1917
+ * as an opaque plain-data snapshot. Returns `null` while the viewport is not mounted.
1918
+ */
1919
+ function captureScrollSnapshot(viewport, virtualizer) {
1920
+ if (!viewport) return null;
1921
+ const rawTop = Number.isFinite(viewport.scrollTop) ? viewport.scrollTop : 0;
1922
+ const scrollTop = Math.max(0, rawTop);
1923
+ const scrollLeft = Number.isFinite(viewport.scrollLeft) ? viewport.scrollLeft : 0;
1924
+ return {
1925
+ version: SCROLL_SNAPSHOT_VERSION,
1926
+ scrollTop,
1927
+ scrollLeft,
1928
+ viewport: readViewportRect(viewport, virtualizer),
1929
+ measurements: virtualizer === null ? null : serializeVirtualMeasurements(virtualizer)
1930
+ };
1931
+ }
1932
+ /**
1933
+ * Resolves a validated snapshot into the mount-only options TanStack Virtual expects, clamped to
1934
+ * the rows the table mounts with so a snapshot taken on a longer table lands at the end instead of
1935
+ * past it. Returns `null` when there is no snapshot or no rows to restore into.
1936
+ */
1937
+ function resolveInitialVirtualRestore(snapshot, rowKeys, estimateHeight) {
1938
+ if (snapshot === null || rowKeys.length === 0) return null;
1939
+ const measurements = [];
1940
+ const sizeByKey = /* @__PURE__ */ new Map();
1941
+ if (snapshot.measurements !== null) for (const item of snapshot.measurements) {
1942
+ sizeByKey.set(item.key, item.size);
1943
+ measurements.push({ ...item });
1944
+ }
1945
+ let totalHeight = 0;
1946
+ for (const key of rowKeys) totalHeight += sizeByKey.get(key) ?? estimateHeight;
1947
+ const viewportHeight = snapshot.viewport?.height ?? 0;
1948
+ const maxOffset = viewportHeight > 0 ? Math.max(0, totalHeight - viewportHeight) : totalHeight;
1949
+ return {
1950
+ offset: Math.min(snapshot.scrollTop, maxOffset),
1951
+ measurements,
1952
+ rect: snapshot.viewport ? { ...snapshot.viewport } : void 0
1953
+ };
1954
+ }
1955
+ //#endregion
1776
1956
  //#region src/search.tsx
1777
1957
  /**
1778
1958
  * `DataTable.Search` — the global-filter input, debounced. A standalone compound: takes the
@@ -2891,11 +3071,19 @@ function LoaderRow({ colSpan, ariaRowIndex }) {
2891
3071
  })
2892
3072
  });
2893
3073
  }
2894
- function LoadMoreErrorRow({ colSpan, message, ariaRowIndex, onRetry }) {
3074
+ function LoadMoreRetryRow({ colSpan, ariaRowIndex, failure, held, retry, release }) {
2895
3075
  const { getStyles, labels, icons } = useDataTableContext();
3076
+ const retryButton = (0, react.useRef)(null);
3077
+ (0, react.useLayoutEffect)(() => {
3078
+ const button = retryButton.current;
3079
+ return () => {
3080
+ if (button && button.ownerDocument.activeElement === button) release();
3081
+ };
3082
+ }, [release]);
2896
3083
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Table.Tr, {
2897
- "data-error": true,
2898
3084
  "aria-rowindex": ariaRowIndex,
3085
+ "data-error": !held || void 0,
3086
+ "data-pending": held || void 0,
2899
3087
  role: "row",
2900
3088
  ...getStyles("loaderRow"),
2901
3089
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Table.Td, {
@@ -2904,22 +3092,34 @@ function LoadMoreErrorRow({ colSpan, message, ariaRowIndex, onRetry }) {
2904
3092
  role: "cell",
2905
3093
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2906
3094
  ...getStyles("loaderRowContent"),
2907
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3095
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3096
+ role: "status",
3097
+ children: held && labels.loadingMore
3098
+ }), !held && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2908
3099
  role: "alert",
2909
- children: message === true ? labels.loadMoreError : message
2910
- }), onRetry && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Button, {
3100
+ children: failure === true ? labels.loadMoreError : failure
3101
+ })] }), retry && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Button, {
3102
+ ref: retryButton,
3103
+ ...getStyles("loaderRowRetry"),
3104
+ "aria-busy": held || void 0,
3105
+ "aria-disabled": held || void 0,
2911
3106
  color: "gray",
2912
- leftSection: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(icons.retry, { size: 14 }),
3107
+ "data-disabled": held || void 0,
2913
3108
  size: "compact-xs",
2914
3109
  variant: "subtle",
2915
- onClick: onRetry,
3110
+ leftSection: held ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Loader, {
3111
+ "aria-hidden": true,
3112
+ color: "var(--button-color)",
3113
+ size: 14
3114
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(icons.retry, { size: 14 }),
3115
+ onClick: retry,
2916
3116
  children: labels.retry
2917
3117
  })]
2918
3118
  })
2919
3119
  })
2920
3120
  });
2921
3121
  }
2922
- function TableBody({ table, virtualization, columnWindow, filler, viewportRef, loading, loadingMore, loadMoreError, onLoadMoreRetry, reorderSourceId, reorderTarget, skeletonRowCount, onVirtualizerChange }) {
3122
+ function TableBody({ table, virtualization, initialScroll, columnWindow, filler, viewportRef, loading, loadMoreRow, reorderSourceId, reorderTarget, skeletonRowCount, onVirtualizerChange }) {
2923
3123
  const { getStyles, withColumnHeaders } = useDataTableContext();
2924
3124
  const ledger = table.options.meta?.ledger;
2925
3125
  const withDetailPanels = Boolean(ledger?.renderDetailPanel);
@@ -2947,18 +3147,24 @@ function TableBody({ table, virtualization, columnWindow, filler, viewportRef, l
2947
3147
  const getItemKey = (0, react.useCallback)((index) => centerDisplayRows[index]?.key ?? index, [centerDisplayRows]);
2948
3148
  const estimateHeight = virtualization?.estimateHeight ?? DEFAULT_ESTIMATED_ROW_HEIGHT;
2949
3149
  const estimateSize = (0, react.useCallback)(() => estimateHeight, [estimateHeight]);
3150
+ const [initialRestore] = (0, react.useState)(() => virtualization === null ? null : resolveInitialVirtualRestore(initialScroll, centerDisplayRows.map((row) => row.key), estimateHeight));
2950
3151
  const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
2951
3152
  count: centerDisplayRows.length,
2952
3153
  enabled: virtualization !== null,
2953
3154
  estimateSize,
2954
3155
  getItemKey,
2955
3156
  getScrollElement: () => viewportRef.current,
3157
+ ...initialRestore !== null && {
3158
+ initialMeasurementsCache: initialRestore.measurements,
3159
+ initialOffset: initialRestore.offset,
3160
+ ...initialRestore.rect !== void 0 && { initialRect: initialRestore.rect }
3161
+ },
2956
3162
  measureElement: measureRow,
2957
3163
  overscan: virtualization?.overscan ?? DEFAULT_OVERSCAN,
2958
3164
  useFlushSync: false
2959
3165
  });
2960
3166
  const virtualEnabled = virtualization !== null;
2961
- (0, react.useEffect)(() => {
3167
+ (0, react.useLayoutEffect)(() => {
2962
3168
  onVirtualizerChange(virtualEnabled ? virtualizer : null);
2963
3169
  return () => onVirtualizerChange(null);
2964
3170
  }, [
@@ -3005,7 +3211,7 @@ function TableBody({ table, virtualization, columnWindow, filler, viewportRef, l
3005
3211
  const editingCell = ledger?.editing.cell ?? null;
3006
3212
  const editingRowId = ledger?.editing.mode === "row" ? ledger.editing.row.id : null;
3007
3213
  const activeRowId = ledger?.activeRow.enabled ? ledger.activeRow.id : null;
3008
- const trailingRowCount = loadMoreError || loadingMore ? 1 : 0;
3214
+ const trailingRowCount = loadMoreRow ? 1 : 0;
3009
3215
  const zoneRows = {
3010
3216
  top: topDisplayRows,
3011
3217
  center: centerDisplayRows,
@@ -3108,12 +3314,14 @@ function TableBody({ table, virtualization, columnWindow, filler, viewportRef, l
3108
3314
  pinnedOffset: pinnedRowOffsets.offsets.bottom[displayIndex],
3109
3315
  pinnedPosition: "bottom"
3110
3316
  })),
3111
- loadMoreError ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadMoreErrorRow, {
3317
+ loadMoreRow?.kind === "retry" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadMoreRetryRow, {
3112
3318
  ariaRowIndex: virtualEnabled ? headerRowCount + totalDisplayRowCount + 1 : void 0,
3113
3319
  colSpan: fullWidthColSpan,
3114
- message: loadMoreError,
3115
- onRetry: onLoadMoreRetry
3116
- }) : loadingMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoaderRow, {
3320
+ failure: loadMoreRow.failure,
3321
+ held: loadMoreRow.held,
3322
+ release: loadMoreRow.release,
3323
+ retry: loadMoreRow.retry
3324
+ }) : loadMoreRow?.kind === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoaderRow, {
3117
3325
  ariaRowIndex: virtualEnabled ? headerRowCount + totalDisplayRowCount + 1 : void 0,
3118
3326
  colSpan: fullWidthColSpan
3119
3327
  })
@@ -7029,6 +7237,7 @@ const classes = {
7029
7237
  empty: "ledger-empty",
7030
7238
  loaderRow: "ledger-loader-row",
7031
7239
  loaderRowContent: "ledger-loader-row-content",
7240
+ loaderRowRetry: "ledger-loader-row-retry",
7032
7241
  paginationBar: "ledger-pagination-bar"
7033
7242
  };
7034
7243
  /**
@@ -7193,7 +7402,7 @@ function DataTableFromOptions({ props }) {
7193
7402
  });
7194
7403
  }
7195
7404
  function DataTableCore({ presentation, stylesProps, table }) {
7196
- const { striped, stripedColor: _stripedColor, highlightOnHover, highlightOnHoverColor: _highlightOnHoverColor, withTableBorder, withColumnBorders, withRowBorders, withBottomBorder, borderColor: _borderColor, radius: _radius, size: sizeProp, verticalSpacing, horizontalSpacing, tabularNums, tableMinWidth, columnMinSizeFromHeader, virtualizedRows, virtualizedColumns, onEndReached, endReachedOffset, loadingMore, loadMoreError, loading, emptyState, error, onRetry, withColumnHeaders, withPaginationBar, pageSizeOptions, onRowClick, onRowActivate, onRowDoubleClick, onRowContextMenu, rowProps, headerRowProps, footerRowProps, viewportProps, labels: labelsProp, icons: iconsProp, handleRef, ref: rootRef, classNames, styles, unstyled, vars, className, style, attributes, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...others } = presentation;
7405
+ const { striped, stripedColor: _stripedColor, highlightOnHover, highlightOnHoverColor: _highlightOnHoverColor, withTableBorder, withColumnBorders, withRowBorders, withBottomBorder, borderColor: _borderColor, radius: _radius, size: sizeProp, verticalSpacing, horizontalSpacing, tabularNums, tableMinWidth, columnMinSizeFromHeader, virtualizedRows, virtualizedColumns, initialScroll, onEndReached, endReachedOffset, loadingMore, loadMoreError, loading, emptyState, error, onRetry, withColumnHeaders, withPaginationBar, pageSizeOptions, onRowClick, onRowActivate, onRowDoubleClick, onRowContextMenu, rowProps, headerRowProps, footerRowProps, viewportProps, labels: labelsProp, icons: iconsProp, handleRef, ref: rootRef, classNames, styles, unstyled, vars, className, style, attributes, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...others } = presentation;
7197
7406
  const getStyles = (0, _mantine_core.useStyles)({
7198
7407
  name: "DataTable",
7199
7408
  classes,
@@ -7266,6 +7475,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7266
7475
  tableMinWidth,
7267
7476
  viewport
7268
7477
  });
7478
+ const [initialScrollData] = (0, react.useState)(() => readScrollSnapshot(initialScroll));
7269
7479
  const virtualization = virtualizedRows ? {
7270
7480
  estimateHeight: typeof virtualizedRows === "object" && virtualizedRows.estimateHeight !== void 0 ? virtualizedRows.estimateHeight : scale.rowHeight,
7271
7481
  overscan: typeof virtualizedRows === "object" && virtualizedRows.overscan !== void 0 ? virtualizedRows.overscan : 8
@@ -7408,10 +7618,17 @@ function DataTableCore({ presentation, stylesProps, table }) {
7408
7618
  hasEndReachedHandler,
7409
7619
  maybeFireEndReached
7410
7620
  ]);
7411
- const retryLoadMore = useEventCallback(() => {
7621
+ const askForMoreAgain = useEventCallback(() => {
7412
7622
  lastEndReachedData.current = null;
7413
7623
  onEndReached?.();
7414
7624
  });
7625
+ const loadMoreRetry = useLoadMoreRetry({
7626
+ data: currentData,
7627
+ loadingMore: loadingMore === true,
7628
+ loadMoreError: loadMoreError ?? false,
7629
+ askAgain: onEndReached ? askForMoreAgain : void 0,
7630
+ viewportRef
7631
+ });
7415
7632
  const [scrollEdges, setScrollEdges] = (0, react.useState)({
7416
7633
  start: false,
7417
7634
  end: false
@@ -7479,7 +7696,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7479
7696
  rowPinningActive,
7480
7697
  withDetailPanels
7481
7698
  ]);
7482
- const bodyAriaRowCount = loading && logicalDisplayRowCount === 0 ? skeletonRowCount : logicalDisplayRowCount + (loadMoreError || loadingMore ? 1 : 0) + (isEmpty || errorActive ? 1 : 0);
7699
+ const bodyAriaRowCount = loading && logicalDisplayRowCount === 0 ? skeletonRowCount : logicalDisplayRowCount + (loadMoreRetry.row ? 1 : 0) + (isEmpty || errorActive ? 1 : 0);
7483
7700
  const footerRowCount = visibleFooterGroups(table).length;
7484
7701
  const ariaRowCount = headerRowCount + bodyAriaRowCount + footerRowCount;
7485
7702
  const footerAriaRowIndexStart = headerRowCount + bodyAriaRowCount + 1;
@@ -7488,6 +7705,19 @@ function DataTableCore({ presentation, stylesProps, table }) {
7488
7705
  if (!element) return;
7489
7706
  for (const mirror of [headerViewportRef.current, footerViewportRef.current]) if (mirror && mirror.scrollLeft !== element.scrollLeft) mirror.scrollLeft = element.scrollLeft;
7490
7707
  });
7708
+ const initialScrollApplied = (0, react.useRef)(false);
7709
+ (0, react.useLayoutEffect)(() => {
7710
+ if (initialScrollApplied.current || initialScrollData === null) return;
7711
+ const element = viewportRef.current;
7712
+ if (!element) return;
7713
+ initialScrollApplied.current = true;
7714
+ if (!virtualEnabled && initialScrollData.scrollTop > 0 && rowsLength > 0) element.scrollTop = initialScrollData.scrollTop;
7715
+ if (initialScrollData.scrollLeft !== 0) {
7716
+ element.scrollLeft = initialScrollData.scrollLeft;
7717
+ mirrorBodyScrollLeft();
7718
+ updateScrollEdges();
7719
+ }
7720
+ }, []);
7491
7721
  (0, react.useEffect)(() => {
7492
7722
  updateScrollEdges();
7493
7723
  mirrorBodyScrollLeft();
@@ -7583,6 +7813,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7583
7813
  left: rtl ? -target : target
7584
7814
  });
7585
7815
  });
7816
+ const getScrollSnapshot = (0, react.useCallback)(() => captureScrollSnapshot(viewportRef.current, virtualizerRef.current), []);
7586
7817
  (0, react.useImperativeHandle)(handleRef, () => {
7587
7818
  return {
7588
7819
  table,
@@ -7592,6 +7823,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7592
7823
  scrollToRow: scrollRowIntoView,
7593
7824
  scrollToIndex: scrollIndexIntoView,
7594
7825
  scrollToColumn: scrollColumnIntoView,
7826
+ getScrollSnapshot,
7595
7827
  startEditing: (rowId, columnId) => {
7596
7828
  const editing = table.options.meta?.ledger?.editing;
7597
7829
  if (!editing) return;
@@ -7612,7 +7844,8 @@ function DataTableCore({ presentation, stylesProps, table }) {
7612
7844
  table,
7613
7845
  scrollRowIntoView,
7614
7846
  scrollIndexIntoView,
7615
- scrollColumnIntoView
7847
+ scrollColumnIntoView,
7848
+ getScrollSnapshot
7616
7849
  ]);
7617
7850
  const activeRowAnnouncer = (0, react.useRef)(null);
7618
7851
  const rowNavigationHintId = `${instanceId}-row-navigation`;
@@ -7868,9 +8101,10 @@ function DataTableCore({ presentation, stylesProps, table }) {
7868
8101
  overscrollBehaviorY: viewportFit.overflowsY ? "none" : "auto"
7869
8102
  },
7870
8103
  role: "rowgroup",
7871
- "aria-label": viewportProps?.["aria-label"] ?? (viewportFocusStop ? labels.rows : void 0),
8104
+ "aria-label": viewportProps?.["aria-label"] ?? (viewportFocusStop || loadMoreRetry.viewportHoldsHandedFocus ? labels.rows : void 0),
7872
8105
  "aria-describedby": viewportDescribedBy,
7873
- tabIndex: viewportFocusStop ? 0 : void 0,
8106
+ tabIndex: viewportFocusStop ? 0 : loadMoreRetry.viewportHoldsHandedFocus ? -1 : void 0,
8107
+ onBlur: loadMoreRetry.onViewportBlur,
7874
8108
  ...activeRowEnabled && { onKeyDown: handleActiveRowKeyDown }
7875
8109
  }),
7876
8110
  onScrollPositionChange: handleScrollPositionChange,
@@ -7881,16 +8115,15 @@ function DataTableCore({ presentation, stylesProps, table }) {
7881
8115
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("colgroup", { children: colElements }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TableBody, {
7882
8116
  columnWindow,
7883
8117
  filler,
8118
+ initialScroll: initialScrollData,
7884
8119
  loading: loading === true,
7885
- loadingMore: loadingMore === true,
7886
- loadMoreError: loadMoreError ?? false,
8120
+ loadMoreRow: loadMoreRetry.row,
7887
8121
  reorderSourceId: rowOrderingEnabled ? rowReorder.sourceId : null,
7888
8122
  reorderTarget: rowOrderingEnabled ? rowReorder.target : null,
7889
8123
  skeletonRowCount,
7890
8124
  table: erasedTable,
7891
8125
  viewportRef,
7892
8126
  virtualization,
7893
- onLoadMoreRetry: onEndReached ? retryLoadMore : void 0,
7894
8127
  onVirtualizerChange: handleVirtualizerChange
7895
8128
  })]
7896
8129
  }),
@@ -8086,6 +8319,7 @@ Object.defineProperty(exports, "flexRender", {
8086
8319
  return _tanstack_react_table.flexRender;
8087
8320
  }
8088
8321
  });
8322
+ exports.isDataTableScrollSnapshot = isDataTableScrollSnapshot;
8089
8323
  exports.numberEditor = numberEditor;
8090
8324
  exports.selectEditor = selectEditor;
8091
8325
  exports.textEditor = textEditor;