@coldsmirk/ledger-mantine 0.12.0 → 0.12.2

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
@@ -3010,11 +3071,19 @@ function LoaderRow({ colSpan, ariaRowIndex }) {
3010
3071
  })
3011
3072
  });
3012
3073
  }
3013
- function LoadMoreErrorRow({ colSpan, message, ariaRowIndex, onRetry }) {
3074
+ function LoadMoreRetryRow({ colSpan, ariaRowIndex, failure, held, retry, release }) {
3014
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]);
3015
3083
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Table.Tr, {
3016
- "data-error": true,
3017
3084
  "aria-rowindex": ariaRowIndex,
3085
+ "data-error": !held || void 0,
3086
+ "data-pending": held || void 0,
3018
3087
  role: "row",
3019
3088
  ...getStyles("loaderRow"),
3020
3089
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Table.Td, {
@@ -3023,22 +3092,34 @@ function LoadMoreErrorRow({ colSpan, message, ariaRowIndex, onRetry }) {
3023
3092
  role: "cell",
3024
3093
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3025
3094
  ...getStyles("loaderRowContent"),
3026
- 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", {
3027
3099
  role: "alert",
3028
- children: message === true ? labels.loadMoreError : message
3029
- }), 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,
3030
3106
  color: "gray",
3031
- leftSection: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(icons.retry, { size: 14 }),
3107
+ "data-disabled": held || void 0,
3032
3108
  size: "compact-xs",
3033
3109
  variant: "subtle",
3034
- 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,
3035
3116
  children: labels.retry
3036
3117
  })]
3037
3118
  })
3038
3119
  })
3039
3120
  });
3040
3121
  }
3041
- function TableBody({ table, virtualization, initialScroll, 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 }) {
3042
3123
  const { getStyles, withColumnHeaders } = useDataTableContext();
3043
3124
  const ledger = table.options.meta?.ledger;
3044
3125
  const withDetailPanels = Boolean(ledger?.renderDetailPanel);
@@ -3130,7 +3211,7 @@ function TableBody({ table, virtualization, initialScroll, columnWindow, filler,
3130
3211
  const editingCell = ledger?.editing.cell ?? null;
3131
3212
  const editingRowId = ledger?.editing.mode === "row" ? ledger.editing.row.id : null;
3132
3213
  const activeRowId = ledger?.activeRow.enabled ? ledger.activeRow.id : null;
3133
- const trailingRowCount = loadMoreError || loadingMore ? 1 : 0;
3214
+ const trailingRowCount = loadMoreRow ? 1 : 0;
3134
3215
  const zoneRows = {
3135
3216
  top: topDisplayRows,
3136
3217
  center: centerDisplayRows,
@@ -3233,12 +3314,14 @@ function TableBody({ table, virtualization, initialScroll, columnWindow, filler,
3233
3314
  pinnedOffset: pinnedRowOffsets.offsets.bottom[displayIndex],
3234
3315
  pinnedPosition: "bottom"
3235
3316
  })),
3236
- loadMoreError ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadMoreErrorRow, {
3317
+ loadMoreRow?.kind === "retry" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadMoreRetryRow, {
3237
3318
  ariaRowIndex: virtualEnabled ? headerRowCount + totalDisplayRowCount + 1 : void 0,
3238
3319
  colSpan: fullWidthColSpan,
3239
- message: loadMoreError,
3240
- onRetry: onLoadMoreRetry
3241
- }) : 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, {
3242
3325
  ariaRowIndex: virtualEnabled ? headerRowCount + totalDisplayRowCount + 1 : void 0,
3243
3326
  colSpan: fullWidthColSpan
3244
3327
  })
@@ -7154,6 +7237,7 @@ const classes = {
7154
7237
  empty: "ledger-empty",
7155
7238
  loaderRow: "ledger-loader-row",
7156
7239
  loaderRowContent: "ledger-loader-row-content",
7240
+ loaderRowRetry: "ledger-loader-row-retry",
7157
7241
  paginationBar: "ledger-pagination-bar"
7158
7242
  };
7159
7243
  /**
@@ -7534,10 +7618,17 @@ function DataTableCore({ presentation, stylesProps, table }) {
7534
7618
  hasEndReachedHandler,
7535
7619
  maybeFireEndReached
7536
7620
  ]);
7537
- const retryLoadMore = useEventCallback(() => {
7538
- lastEndReachedData.current = null;
7621
+ const askForMoreAgain = useEventCallback(() => {
7622
+ lastEndReachedData.current = currentData;
7539
7623
  onEndReached?.();
7540
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
+ });
7541
7632
  const [scrollEdges, setScrollEdges] = (0, react.useState)({
7542
7633
  start: false,
7543
7634
  end: false
@@ -7605,7 +7696,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7605
7696
  rowPinningActive,
7606
7697
  withDetailPanels
7607
7698
  ]);
7608
- 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);
7609
7700
  const footerRowCount = visibleFooterGroups(table).length;
7610
7701
  const ariaRowCount = headerRowCount + bodyAriaRowCount + footerRowCount;
7611
7702
  const footerAriaRowIndexStart = headerRowCount + bodyAriaRowCount + 1;
@@ -8010,9 +8101,10 @@ function DataTableCore({ presentation, stylesProps, table }) {
8010
8101
  overscrollBehaviorY: viewportFit.overflowsY ? "none" : "auto"
8011
8102
  },
8012
8103
  role: "rowgroup",
8013
- "aria-label": viewportProps?.["aria-label"] ?? (viewportFocusStop ? labels.rows : void 0),
8104
+ "aria-label": viewportProps?.["aria-label"] ?? (viewportFocusStop || loadMoreRetry.viewportHoldsHandedFocus ? labels.rows : void 0),
8014
8105
  "aria-describedby": viewportDescribedBy,
8015
- tabIndex: viewportFocusStop ? 0 : void 0,
8106
+ tabIndex: viewportFocusStop ? 0 : loadMoreRetry.viewportHoldsHandedFocus ? -1 : void 0,
8107
+ onBlur: loadMoreRetry.onViewportBlur,
8016
8108
  ...activeRowEnabled && { onKeyDown: handleActiveRowKeyDown }
8017
8109
  }),
8018
8110
  onScrollPositionChange: handleScrollPositionChange,
@@ -8025,15 +8117,13 @@ function DataTableCore({ presentation, stylesProps, table }) {
8025
8117
  filler,
8026
8118
  initialScroll: initialScrollData,
8027
8119
  loading: loading === true,
8028
- loadingMore: loadingMore === true,
8029
- loadMoreError: loadMoreError ?? false,
8120
+ loadMoreRow: loadMoreRetry.row,
8030
8121
  reorderSourceId: rowOrderingEnabled ? rowReorder.sourceId : null,
8031
8122
  reorderTarget: rowOrderingEnabled ? rowReorder.target : null,
8032
8123
  skeletonRowCount,
8033
8124
  table: erasedTable,
8034
8125
  viewportRef,
8035
8126
  virtualization,
8036
- onLoadMoreRetry: onEndReached ? retryLoadMore : void 0,
8037
8127
  onVirtualizerChange: handleVirtualizerChange
8038
8128
  })]
8039
8129
  }),