@coldsmirk/ledger-mantine 0.9.1 → 0.10.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.
package/dist/index.cjs CHANGED
@@ -1120,6 +1120,7 @@ const defaultLabels = {
1120
1120
  ungroupColumn: "Ungroup",
1121
1121
  columnWidth: "Width",
1122
1122
  columnWidthAuto: "Auto",
1123
+ columnWidthFit: "Fit",
1123
1124
  resizeColumn: "Drag to resize; double-click to fit content",
1124
1125
  reorderColumn: "Drag to reorder column",
1125
1126
  filterColumn: (column) => `Filter ${column}`,
@@ -1356,6 +1357,7 @@ function ColumnsPanelItem({ column, table, labels, icons, index, zone, orderable
1356
1357
  const canGroup = table.options.enableGrouping === true && column.getCanGroup();
1357
1358
  const width = table.atoms.columnSizing.get()[column.id];
1358
1359
  const declaredWidth = rawColumnSizing(column.columnDef)?.size ?? table.options.defaultColumn?.size;
1360
+ const widthPlaceholder = column.columnDef.meta?.autosize === true ? labels.columnWidthFit : declaredWidth === void 0 ? labels.columnWidthAuto : String(declaredWidth);
1359
1361
  const handleWidthChange = (value) => {
1360
1362
  table.setColumnSizing((previous) => {
1361
1363
  if (value === "") {
@@ -1417,7 +1419,7 @@ function ColumnsPanelItem({ column, table, labels, icons, index, zone, orderable
1417
1419
  classNames: { input: "ledger-columns-panel-width-input" },
1418
1420
  max: column.columnDef.maxSize,
1419
1421
  min: column.columnDef.minSize,
1420
- placeholder: declaredWidth === void 0 ? labels.columnWidthAuto : String(declaredWidth),
1422
+ placeholder: widthPlaceholder,
1421
1423
  size: "xs",
1422
1424
  startValue: declaredWidth,
1423
1425
  step: 10,
@@ -3090,34 +3092,66 @@ function TableFooter({ table, ariaRowIndexStart, columnWindow }) {
3090
3092
  });
3091
3093
  }
3092
3094
  //#endregion
3093
- //#region src/autosize-column.ts
3095
+ //#region src/column-autosize.ts
3094
3096
  /**
3095
- * Fit a column to its rendered content (the resizer's double-click). Measures the header cell,
3096
- * every RENDERED body cell of the column — under virtualization that is the current window, which
3097
- * is the industry contract for autosize (unrendered rows have no boxes to measure) — and the
3098
- * footer cell, which is rendered content the column has to hold like any other. Writes the result
3099
- * through `columnSizing`, clamped like an interactive resize.
3097
+ * Fitting columns to their rendered content (docs/sizing.md#autosize) — one measurement behind
3098
+ * both of its uses: the resizer's double-click, which writes the fit as a `columnSizing` entry,
3099
+ * and `meta.autosize`, which keeps a column fitted as its content changes (`use-autosize-widths.ts`).
3100
3100
  *
3101
- * The column, its constraints and whether it carries a filter all arrive from the render that put
3102
- * the handle on screen, for the reason `use-column-resize.ts` gives.
3101
+ * What is measured is what the column has to hold: the header cell, every RENDERED body cell —
3102
+ * under virtualization that is the current window, the industry contract for autosize (unrendered
3103
+ * rows have no boxes to measure) — and the footer cell, which is rendered content like any other.
3104
+ * A cell that spans columns (a merged body cell, a footer total, a detail panel) says nothing about
3105
+ * the width of any one of them, and a cell holding an editor is as wide as the editor makes
3106
+ * itself, not as its value; neither is measured.
3103
3107
  *
3104
3108
  * A content cell is measured out of the table's layout: for the pass it is a block as wide as its
3105
3109
  * content (`display: block; width: max-content`, no wrapping), so its width is the content's, in
3106
3110
  * whichever direction that lies. Read in place, a cell is never narrower than its column — a fixed
3107
3111
  * table lays every cell at the column's width, and a truncating span clips at it — so a fit could
3108
- * only ever widen a column. Every cell is switched first and read afterwards, so the whole pass
3109
- * costs one reflow, and each gets its own inline styles back before anything paints.
3112
+ * only ever widen a column. Every cell of every column is switched first and read afterwards, so a
3113
+ * pass costs one reflow however many columns it fits, and each cell gets its own inline styles back
3114
+ * before anything paints.
3110
3115
  */
3111
3116
  /**
3112
3117
  * Breathing room over the tightest fit — content flush against the column edge reads clipped.
3113
3118
  */
3114
3119
  const AUTOSIZE_SLACK_PX = 8;
3115
3120
  /**
3116
- * Reserved for the hover-revealed header actions overlay (the filter button) so autosize does
3117
- * not park the drag line underneath it.
3121
+ * Reserved for the hover-revealed header actions overlay (the filter button) so a fit does not
3122
+ * park the drag line underneath it.
3118
3123
  */
3119
3124
  const HEADER_ACTIONS_ALLOWANCE_PX = 28;
3120
3125
  /**
3126
+ * Tukey's fence: a value past the third quartile by more than this many interquartile ranges is an
3127
+ * outlier. 1.5 is Tukey's own constant and MUI X's `outliersFactor` default.
3128
+ */
3129
+ const OUTLIER_FACTOR = 1.5;
3130
+ /**
3131
+ * Linear interpolation between closest ranks (Hyndman–Fan type 7, the spreadsheet and NumPy
3132
+ * default) over ascending `sorted`.
3133
+ */
3134
+ function quantile(sorted, p) {
3135
+ const rank = (sorted.length - 1) * p;
3136
+ const lower = Math.floor(rank);
3137
+ const below = sorted[lower];
3138
+ const above = sorted[Math.min(lower + 1, sorted.length - 1)];
3139
+ return below + (rank - lower) * (above - below);
3140
+ }
3141
+ /**
3142
+ * The widest of `values` within Tukey's upper fence (Q3 + 1.5 × IQR) — the width that holds every
3143
+ * value but the outliers. A set too uniform to have any (IQR 0) fences at its common value, so a
3144
+ * single long value among identical ones is still the outlier it reads as.
3145
+ */
3146
+ function fencedMax(values) {
3147
+ if (values.length === 0) return 0;
3148
+ const sorted = values.toSorted((a, b) => a - b);
3149
+ const q1 = quantile(sorted, .25);
3150
+ const q3 = quantile(sorted, .75);
3151
+ const fence = q3 + OUTLIER_FACTOR * (q3 - q1);
3152
+ return sorted.findLast((value) => value <= fence) ?? sorted[0];
3153
+ }
3154
+ /**
3121
3155
  * Computed lengths always resolve to `Npx`; strip the unit before coercing.
3122
3156
  */
3123
3157
  function asPx(value) {
@@ -3134,12 +3168,27 @@ function headerCellWidth(th, hasFilter) {
3134
3168
  const indicatorWidth = indicator ? indicator.offsetWidth + 6 : 0;
3135
3169
  return labelText.scrollWidth + indicatorWidth + horizontalPadding(th) + (hasFilter ? HEADER_ACTIONS_ALLOWANCE_PX : 0);
3136
3170
  }
3137
- function autosizeColumn(setColumnSizing, { columnId, minSize, maxSize, hasFilter }, main) {
3138
- const selector = `[data-ledger-column-id="${CSS.escape(columnId)}"]`;
3139
- const headerCell = main.querySelector(`:scope .ledger-header ${selector}`);
3140
- const contentCells = [...main.querySelectorAll(`:scope :is(.ledger-tbody, .ledger-footer) ${selector}`)].filter((cell) => cell.colSpan <= 1);
3141
- const cells = headerCell ? [headerCell, ...contentCells] : contentCells;
3142
- if (cells.length === 0) return;
3171
+ function contentCells(main, region, selector) {
3172
+ return [...main.querySelectorAll(`:scope ${region} ${selector}`)].filter((cell) => cell.colSpan <= 1 && !Object.hasOwn(cell.dataset, "editing"));
3173
+ }
3174
+ /**
3175
+ * The width each target's rendered content needs, slack included, in integer pixels — before the
3176
+ * column's own `minSize`/`maxSize`, which are the caller's to apply. A column with nothing rendered
3177
+ * (one a column window left out) has no entry.
3178
+ */
3179
+ function measureColumnWidths(main, targets) {
3180
+ const columns = targets.map((target) => {
3181
+ const selector = `[data-ledger-column-id="${CSS.escape(target.columnId)}"]`;
3182
+ return {
3183
+ target,
3184
+ header: main.querySelector(`:scope .ledger-header ${selector}`),
3185
+ body: contentCells(main, ".ledger-tbody", selector),
3186
+ footer: contentCells(main, ".ledger-footer", selector)
3187
+ };
3188
+ });
3189
+ const headers = columns.map((column) => column.header).filter((header) => header !== null);
3190
+ const contents = columns.flatMap((column) => [...column.body, ...column.footer]);
3191
+ const cells = [...headers, ...contents];
3143
3192
  const previous = cells.map((cell) => {
3144
3193
  return {
3145
3194
  display: cell.style.display,
@@ -3148,22 +3197,37 @@ function autosizeColumn(setColumnSizing, { columnId, minSize, maxSize, hasFilter
3148
3197
  };
3149
3198
  });
3150
3199
  for (const cell of cells) cell.style.whiteSpace = "nowrap";
3151
- for (const cell of contentCells) {
3200
+ for (const cell of contents) {
3152
3201
  cell.style.display = "block";
3153
3202
  cell.style.width = "max-content";
3154
3203
  }
3155
- let content = headerCell ? headerCellWidth(headerCell, hasFilter) : 0;
3156
- for (const cell of contentCells) content = Math.max(content, cell.scrollWidth);
3204
+ const widths = /* @__PURE__ */ new Map();
3205
+ for (const { target, header, body, footer } of columns) {
3206
+ if (!header && body.length === 0 && footer.length === 0) continue;
3207
+ const bodyWidths = body.map((cell) => cell.scrollWidth);
3208
+ const content = Math.max(header ? headerCellWidth(header, target.hasFilter) : 0, ...footer.map((cell) => cell.scrollWidth), target.truncate ? fencedMax(bodyWidths) : Math.max(0, ...bodyWidths));
3209
+ widths.set(target.columnId, Math.round(content) + AUTOSIZE_SLACK_PX);
3210
+ }
3157
3211
  for (const [index, cell] of cells.entries()) {
3158
3212
  const styles = previous[index];
3159
3213
  cell.style.display = styles?.display ?? "";
3160
3214
  cell.style.whiteSpace = styles?.whiteSpace ?? "";
3161
3215
  cell.style.width = styles?.width ?? "";
3162
3216
  }
3163
- const next = Math.min(Math.max(Math.round(content + AUTOSIZE_SLACK_PX), minSize), maxSize);
3164
- setColumnSizing((previous) => previous[columnId] === next ? previous : {
3217
+ return widths;
3218
+ }
3219
+ /**
3220
+ * The resizer's double-click: fit the column once and write the fit through `columnSizing`, clamped
3221
+ * like an interactive resize. The column, its constraints and whether it carries a filter all
3222
+ * arrive from the render that put the handle on screen, for the reason `use-column-resize.ts` gives.
3223
+ */
3224
+ function autosizeColumn(setColumnSizing, { minSize, maxSize, ...target }, main) {
3225
+ const fitted = measureColumnWidths(main, [target]).get(target.columnId);
3226
+ if (fitted === void 0) return;
3227
+ const next = Math.min(Math.max(fitted, minSize), maxSize);
3228
+ setColumnSizing((previous) => previous[target.columnId] === next ? previous : {
3165
3229
  ...previous,
3166
- [columnId]: next
3230
+ [target.columnId]: next
3167
3231
  });
3168
3232
  }
3169
3233
  //#endregion
@@ -3775,7 +3839,8 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
3775
3839
  const main = event.currentTarget.closest(".ledger-main");
3776
3840
  if (main) autosizeColumn(table.setColumnSizing, {
3777
3841
  ...resizerSpec,
3778
- hasFilter: meta?.filter !== void 0
3842
+ hasFilter: meta?.filter !== void 0,
3843
+ truncate: meta?.truncate === true
3779
3844
  }, main);
3780
3845
  },
3781
3846
  ...resize.getResizerProps(resizerSpec),
@@ -3786,6 +3851,160 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
3786
3851
  });
3787
3852
  }
3788
3853
  //#endregion
3854
+ //#region src/use-autosize-widths.ts
3855
+ /**
3856
+ * `meta.autosize` (docs/sizing.md#autosize): keeps each such column fitted to its rendered content
3857
+ * and hands the width engine the fits, which rank between a user's resize and the author's `size`.
3858
+ *
3859
+ * When a fit is taken, and what it may do:
3860
+ * - **A new view refits.** Different rows (a new page, a filter, a sort — anything that changes the
3861
+ * row ids or their order), new column definitions (a renderer, a translated header) or another
3862
+ * set of visible columns, another density, or a web font that finished loading: the content is
3863
+ * new, so the widths follow it in both directions.
3864
+ * - **The same rows again only widen.** A refetch that hands back the same rows (a poll, an
3865
+ * edit) may make a cell wider, never a column narrower — otherwise a value that alternates
3866
+ * between short and long would shake the columns on every refresh.
3867
+ * - **Content that arrives with a window only widens, once the scrolling settles.** Under
3868
+ * virtualization the rows and columns scrolled into view were never measured; fitting them on
3869
+ * every window shift would reflow the table each step of a scroll, and narrowing would move the
3870
+ * columns under the reader.
3871
+ * - **A table with no layout waits for one.** In a hidden tab or a collapsed panel every cell
3872
+ * measures zero; the fit is taken when the table is first laid out instead.
3873
+ *
3874
+ * A fit is taken in a layout effect, before the browser paints, so a refit never shows the old
3875
+ * widths for a frame; a column a user resized is left to the user's width and not measured.
3876
+ */
3877
+ /**
3878
+ * How long a scroll has to rest before the content it brought into view is fitted.
3879
+ */
3880
+ const SCROLL_SETTLE_MS = 150;
3881
+ const NO_WIDTHS = {};
3882
+ function autosizeTargets(columns, columnSizing) {
3883
+ return columns.flatMap((column) => {
3884
+ const { meta } = column.columnDef;
3885
+ return meta?.autosize === true && !isInternalColumn(column.id) && columnSizing[column.id] === void 0 ? [{
3886
+ columnId: column.id,
3887
+ hasFilter: meta.filter !== void 0,
3888
+ truncate: meta.truncate === true
3889
+ }] : [];
3890
+ });
3891
+ }
3892
+ function sameIds(previous, next) {
3893
+ return previous.length === next.length && previous.every((id, index) => id === next[index]);
3894
+ }
3895
+ /**
3896
+ * The fits after a pass: a column measured takes its new width (in `widen` mode, only if wider), a
3897
+ * column with nothing rendered keeps the width it had, a column no longer fitted drops out.
3898
+ */
3899
+ function mergeWidths(previous, measured, targets, mode) {
3900
+ const next = {};
3901
+ for (const { columnId } of targets) {
3902
+ const fresh = measured.get(columnId);
3903
+ const held = previous[columnId];
3904
+ const width = fresh === void 0 || held === void 0 ? fresh ?? held : mode === "widen" ? Math.max(held, fresh) : fresh;
3905
+ if (width !== void 0) next[columnId] = width;
3906
+ }
3907
+ const keys = Object.keys(next);
3908
+ return keys.length === Object.keys(previous).length && keys.every((key) => previous[key] === next[key]) ? previous : next;
3909
+ }
3910
+ /**
3911
+ * Bumps whenever web fonts finish loading: text measured in a fallback face is the wrong width.
3912
+ */
3913
+ function useFontsVersion(enabled) {
3914
+ const [version, setVersion] = (0, react.useState)(0);
3915
+ (0, react.useEffect)(() => {
3916
+ if (!enabled || !("fonts" in document)) return;
3917
+ const bump = () => setVersion((previous) => previous + 1);
3918
+ document.fonts.addEventListener("loadingdone", bump);
3919
+ return () => document.fonts.removeEventListener("loadingdone", bump);
3920
+ }, [enabled]);
3921
+ return version;
3922
+ }
3923
+ function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appearance, virtualized }) {
3924
+ const targets = autosizeTargets(columns, columnSizing);
3925
+ const enabled = targets.length > 0;
3926
+ const fontsVersion = useFontsVersion(enabled);
3927
+ const signature = JSON.stringify([
3928
+ targets,
3929
+ appearance,
3930
+ fontsVersion
3931
+ ]);
3932
+ const [widths, setWidths] = (0, react.useState)(NO_WIDTHS);
3933
+ const view = (0, react.useRef)(null);
3934
+ /**
3935
+ * A fit was due while the table had no layout.
3936
+ */
3937
+ const awaitingLayout = (0, react.useRef)(false);
3938
+ const settleTimer = (0, react.useRef)(void 0);
3939
+ const fit = useEventCallback((mode) => {
3940
+ if (!main) return;
3941
+ if (main.getClientRects().length === 0) {
3942
+ awaitingLayout.current = true;
3943
+ return;
3944
+ }
3945
+ awaitingLayout.current = false;
3946
+ const measured = measureColumnWidths(main, targets);
3947
+ setWidths((previous) => mergeWidths(previous, measured, targets, mode));
3948
+ });
3949
+ const fitWhenSettled = (0, react.useCallback)(() => {
3950
+ clearTimeout(settleTimer.current);
3951
+ settleTimer.current = setTimeout(() => fit("widen"), SCROLL_SETTLE_MS);
3952
+ }, [fit]);
3953
+ (0, react.useEffect)(() => () => clearTimeout(settleTimer.current), []);
3954
+ (0, react.useLayoutEffect)(() => {
3955
+ if (!enabled) {
3956
+ view.current = null;
3957
+ setWidths(NO_WIDTHS);
3958
+ return;
3959
+ }
3960
+ const rowIds = rows.map((row) => row.id);
3961
+ const sameView = view.current !== null && view.current.columns === columns && view.current.signature === signature && sameIds(view.current.rowIds, rowIds);
3962
+ view.current = {
3963
+ columns,
3964
+ signature,
3965
+ rowIds
3966
+ };
3967
+ fit(sameView ? "widen" : "refit");
3968
+ }, [
3969
+ enabled,
3970
+ main,
3971
+ columns,
3972
+ rows,
3973
+ signature,
3974
+ fit
3975
+ ]);
3976
+ (0, react.useEffect)(() => {
3977
+ if (enabled && virtualized && widths !== NO_WIDTHS) fitWhenSettled();
3978
+ }, [
3979
+ enabled,
3980
+ virtualized,
3981
+ widths,
3982
+ fitWhenSettled
3983
+ ]);
3984
+ (0, react.useEffect)(() => {
3985
+ if (!enabled || !main) return;
3986
+ const observer = new ResizeObserver(() => {
3987
+ if (awaitingLayout.current) fit("refit");
3988
+ else if (virtualized) fitWhenSettled();
3989
+ });
3990
+ observer.observe(main);
3991
+ if (!virtualized || !viewport) return () => observer.disconnect();
3992
+ viewport.addEventListener("scroll", fitWhenSettled, { passive: true });
3993
+ return () => {
3994
+ observer.disconnect();
3995
+ viewport.removeEventListener("scroll", fitWhenSettled);
3996
+ };
3997
+ }, [
3998
+ enabled,
3999
+ main,
4000
+ viewport,
4001
+ virtualized,
4002
+ fit,
4003
+ fitWhenSettled
4004
+ ]);
4005
+ return widths;
4006
+ }
4007
+ //#endregion
3789
4008
  //#region src/use-column-widths.ts
3790
4009
  /**
3791
4010
  * The width engine (docs/sizing.md): every visible leaf column resolves to an exact integer
@@ -3793,8 +4012,9 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
3793
4012
  * number system — the browser never redistributes anything.
3794
4013
  *
3795
4014
  * Rules, in order:
3796
- * - a column with an explicit width (user-resized `columnSizing` entry, else the author's
3797
- * `size`, else `defaultColumn.size`) is fixed at that width, clamped to its declared min/max;
4015
+ * - a column with an explicit width (user-resized `columnSizing` entry, else its fitted content
4016
+ * width under `meta.autosize`, else the author's `size`, else `defaultColumn.size`) is fixed at
4017
+ * that width, clamped to its declared min/max;
3798
4018
  * - a column without one is a grow column with basis `minSize ?? 80`; container surplus is
3799
4019
  * distributed proportionally to the bases (integer floor, remainder in display order), capped
3800
4020
  * by maxSize; when the container is too small every grow column falls back to its basis and the
@@ -3860,7 +4080,7 @@ function resolveColumnWidths(columns, columnSizing, availableWidth) {
3860
4080
  const byId = {};
3861
4081
  const growColumns = [];
3862
4082
  for (const column of columns) {
3863
- const sized = finiteNumber(columnSizing[column.id]) ?? finiteNumber(column.size);
4083
+ const sized = finiteNumber(columnSizing[column.id]) ?? finiteNumber(column.fit) ?? finiteNumber(column.size);
3864
4084
  if (sized === void 0) {
3865
4085
  const basis = clampWidth(column.minSize ?? DEFAULT_FLEX_BASIS, column.minSize, column.maxSize);
3866
4086
  byId[column.id] = basis;
@@ -3896,7 +4116,7 @@ function minWidthPx(tableMinWidth, viewport) {
3896
4116
  if (!tableElement) return Number.parseFloat(tableMinWidth) || 0;
3897
4117
  return Number.parseFloat(getComputedStyle(tableElement).minWidth) || 0;
3898
4118
  }
3899
- function useColumnWidths(table, columns, viewport, tableMinWidth, injectedWidth) {
4119
+ function useColumnWidths(table, { columns, viewport, tableMinWidth, injectedWidth, autosizeWidths }) {
3900
4120
  const [availableWidth, setAvailableWidth] = (0, react.useState)(0);
3901
4121
  const measure = (0, react.useCallback)(() => {
3902
4122
  if (!viewport) return;
@@ -3917,12 +4137,14 @@ function useColumnWidths(table, columns, viewport, tableMinWidth, injectedWidth)
3917
4137
  const raw = rawColumnSizing(column.columnDef);
3918
4138
  if (isInternalColumn(column.id)) return {
3919
4139
  id: column.id,
4140
+ fit: void 0,
3920
4141
  size: raw?.size ?? injectedWidth,
3921
4142
  minSize: raw?.minSize ?? injectedWidth,
3922
4143
  maxSize: raw?.maxSize ?? injectedWidth
3923
4144
  };
3924
4145
  return {
3925
4146
  id: column.id,
4147
+ fit: autosizeWidths[column.id],
3926
4148
  size: raw ? raw.size ?? defaultColumn?.size : column.columnDef.size,
3927
4149
  minSize: raw ? raw.minSize ?? defaultColumn?.minSize : column.columnDef.minSize,
3928
4150
  maxSize: raw ? raw.maxSize ?? defaultColumn?.maxSize : column.columnDef.maxSize
@@ -3933,7 +4155,8 @@ function useColumnWidths(table, columns, viewport, tableMinWidth, injectedWidth)
3933
4155
  columnSizing,
3934
4156
  availableWidth,
3935
4157
  defaultColumn,
3936
- injectedWidth
4158
+ injectedWidth,
4159
+ autosizeWidths
3937
4160
  ]);
3938
4161
  const signature = JSON.stringify([resolved.total, Object.entries(resolved.byId)]);
3939
4162
  return (0, react.useMemo)(() => resolved, [signature]);
@@ -6558,7 +6781,8 @@ function useStylesRevision(getStyles, selectors) {
6558
6781
  //#endregion
6559
6782
  //#region src/use-viewport-fit.ts
6560
6783
  const UNMEASURED = {
6561
- overflowing: false,
6784
+ overflowsX: false,
6785
+ overflowsY: false,
6562
6786
  underfilled: false
6563
6787
  };
6564
6788
  /**
@@ -6572,10 +6796,12 @@ function useViewportFit(viewport) {
6572
6796
  if (!viewport) return;
6573
6797
  const content = viewport.firstElementChild;
6574
6798
  const measure = () => {
6575
- const overflowing = viewport.scrollHeight - viewport.clientHeight > 1 || viewport.scrollWidth - viewport.clientWidth > 1;
6799
+ const overflowsX = viewport.scrollWidth - viewport.clientWidth > 1;
6800
+ const overflowsY = viewport.scrollHeight - viewport.clientHeight > 1;
6576
6801
  const underfilled = content instanceof HTMLElement && viewport.clientHeight - content.offsetHeight >= 1;
6577
- setFit((previous) => previous.overflowing === overflowing && previous.underfilled === underfilled ? previous : {
6578
- overflowing,
6802
+ setFit((previous) => previous.overflowsX === overflowsX && previous.overflowsY === overflowsY && previous.underfilled === underfilled ? previous : {
6803
+ overflowsX,
6804
+ overflowsY,
6579
6805
  underfilled
6580
6806
  });
6581
6807
  };
@@ -6838,6 +7064,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
6838
7064
  setViewport(element);
6839
7065
  }, []);
6840
7066
  const viewportFit = useViewportFit(viewport);
7067
+ const [main, setMain] = (0, react.useState)(null);
6841
7068
  const startLeafColumns = table.getStartVisibleLeafColumns();
6842
7069
  const endLeafColumns = table.getEndVisibleLeafColumns();
6843
7070
  const displayColumns = [
@@ -6852,7 +7079,21 @@ function DataTableCore({ presentation, stylesProps, table }) {
6852
7079
  const visibleLeafColumns = (0, react.useMemo)(() => displayColumns, [displayOrderSignature, ledgerColumns]);
6853
7080
  const size = sizeProp ?? "sm";
6854
7081
  const scale = SIZES[size];
6855
- const columnWidths = useColumnWidths(table, visibleLeafColumns, viewport, tableMinWidth, scale.injectedWidth);
7082
+ const columnWidths = useColumnWidths(table, {
7083
+ autosizeWidths: useAutosizeWidths({
7084
+ appearance: size,
7085
+ columnSizing: table.state.columnSizing,
7086
+ columns: visibleLeafColumns,
7087
+ main,
7088
+ rows: table.getRowModel().rows,
7089
+ viewport,
7090
+ virtualized: Boolean(virtualizedRows) || Boolean(virtualizedColumns)
7091
+ }),
7092
+ columns: visibleLeafColumns,
7093
+ injectedWidth: scale.injectedWidth,
7094
+ tableMinWidth,
7095
+ viewport
7096
+ });
6856
7097
  const virtualization = virtualizedRows ? {
6857
7098
  estimateHeight: typeof virtualizedRows === "object" && virtualizedRows.estimateHeight !== void 0 ? virtualizedRows.estimateHeight : scale.rowHeight,
6858
7099
  overscan: typeof virtualizedRows === "object" && virtualizedRows.overscan !== void 0 ? virtualizedRows.overscan : 8
@@ -7191,7 +7432,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7191
7432
  ]);
7192
7433
  const activeRowAnnouncer = (0, react.useRef)(null);
7193
7434
  const rowNavigationHintId = `${instanceId}-row-navigation`;
7194
- const viewportFocusStop = activeRowEnabled || viewportFit.overflowing;
7435
+ const viewportFocusStop = activeRowEnabled || viewportFit.overflowsX || viewportFit.overflowsY;
7195
7436
  const viewportDescribedBy = activeRowEnabled ? [viewportProps?.["aria-describedby"], rowNavigationHintId].filter(Boolean).join(" ") : viewportProps?.["aria-describedby"];
7196
7437
  const announceActiveRow = useEventCallback(() => {
7197
7438
  const target = activeRowAnnouncer.current;
@@ -7402,6 +7643,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7402
7643
  children: labels.rowNavigation
7403
7644
  })] }),
7404
7645
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
7646
+ ref: setMain,
7405
7647
  "aria-busy": loading || void 0,
7406
7648
  "aria-colcount": columnWindow === null ? void 0 : columnWindow.totalLeafCount,
7407
7649
  "aria-describedby": ariaDescribedBy,
@@ -7435,7 +7677,10 @@ function DataTableCore({ presentation, stylesProps, table }) {
7435
7677
  scrollbar: { backgroundColor: "transparent" }
7436
7678
  },
7437
7679
  viewportProps: mergeElementProps(viewportProps, {
7438
- style: { overscrollBehavior: "none" },
7680
+ style: {
7681
+ overscrollBehaviorX: viewportFit.overflowsX ? "none" : "auto",
7682
+ overscrollBehaviorY: viewportFit.overflowsY ? "none" : "auto"
7683
+ },
7439
7684
  role: "rowgroup",
7440
7685
  "aria-label": viewportProps?.["aria-label"] ?? (viewportFocusStop ? labels.rows : void 0),
7441
7686
  "aria-describedby": viewportDescribedBy,