@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 +283 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +283 -38
- package/dist/index.js.map +1 -1
- package/dist/{labels-D6GC8goU.d.ts → labels-Ck0Y2Ser.d.cts} +5 -1
- package/dist/{labels-D6GC8goU.d.cts → labels-Ck0Y2Ser.d.ts} +5 -1
- package/dist/locales.cjs +1 -0
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.d.cts +1 -1
- package/dist/locales.d.ts +1 -1
- package/dist/locales.js +1 -0
- package/dist/locales.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { n as defaultLabels, t as DataTableLabels } from "./labels-
|
|
2
|
+
import { n as defaultLabels, t as DataTableLabels } from "./labels-Ck0Y2Ser.cjs";
|
|
3
3
|
import { BoxProps, ComboboxData, ElementProps, Factory, MantineBreakpoint, MantineColor, MantineRadius, MantineSize, MantineSpacing, PopoverProps, StylesApiProps, TableTdProps, TableThProps, TableTrProps, TextInputProps } from "@mantine/core";
|
|
4
4
|
import { Cell as Cell$1, CellData, Column as Column$1, ColumnDef as ColumnDef$1, ColumnFiltersState, ColumnFiltersState as ColumnFiltersState$1, ColumnOrderState, ColumnOrderState as ColumnOrderState$1, ColumnPinningState, ColumnPinningState as ColumnPinningState$1, ColumnSizingState, ColumnSizingState as ColumnSizingState$1, ColumnVisibilityState, ColumnVisibilityState as ColumnVisibilityState$1, ExpandedState, ExpandedState as ExpandedState$1, FilterFn, FilterFnOption, GroupingState, GroupingState as GroupingState$1, Header as Header$1, HeaderGroup as HeaderGroup$1, PaginationState, PaginationState as PaginationState$1, ReactTable, Row as Row$1, RowData, RowData as RowData$1, RowPinningState, RowPinningState as RowPinningState$1, RowSelectionState, RowSelectionState as RowSelectionState$1, SortingState, SortingState as SortingState$1, TableFeatures, TableOptions, aggregationFn_count, aggregationFn_extent, aggregationFn_first, aggregationFn_last, aggregationFn_max, aggregationFn_mean, aggregationFn_median, aggregationFn_min, aggregationFn_sum, aggregationFn_unique, aggregationFn_uniqueCount, flexRender } from "@tanstack/react-table";
|
|
5
5
|
import { CSSProperties, ComponentProps, ComponentType, JSX as JSX$1, KeyboardEvent, MouseEvent, ReactElement, ReactNode, Ref } from "react";
|
|
@@ -859,6 +859,14 @@ declare module "@tanstack/react-table" {
|
|
|
859
859
|
* Single-line truncation with a title tooltip (host vocabulary: `Text.truncate`).
|
|
860
860
|
*/
|
|
861
861
|
truncate?: boolean;
|
|
862
|
+
/**
|
|
863
|
+
* Fit the column to its rendered content and keep it fitted as the content changes: the
|
|
864
|
+
* header, the rendered cells and the footer, each whole (docs/sizing.md#autosize). The fit is
|
|
865
|
+
* the column's width — a user's resize still wins over it, `minSize`/`maxSize` still bound it,
|
|
866
|
+
* and `size` holds the place until the first fit. A `truncate` column fits its typical content
|
|
867
|
+
* and leaves the outliers to the ellipsis.
|
|
868
|
+
*/
|
|
869
|
+
autosize?: boolean;
|
|
862
870
|
/**
|
|
863
871
|
* Header filter UI: a variant shorthand, a config, or a fully custom renderer.
|
|
864
872
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { n as defaultLabels, t as DataTableLabels } from "./labels-
|
|
2
|
+
import { n as defaultLabels, t as DataTableLabels } from "./labels-Ck0Y2Ser.js";
|
|
3
3
|
import { BoxProps, ComboboxData, ElementProps, Factory, MantineBreakpoint, MantineColor, MantineRadius, MantineSize, MantineSpacing, PopoverProps, StylesApiProps, TableTdProps, TableThProps, TableTrProps, TextInputProps } from "@mantine/core";
|
|
4
4
|
import { CSSProperties, ComponentProps, ComponentType, JSX as JSX$1, KeyboardEvent, MouseEvent, ReactElement, ReactNode, Ref } from "react";
|
|
5
5
|
import { Cell as Cell$1, CellData, Column as Column$1, ColumnDef as ColumnDef$1, ColumnFiltersState, ColumnFiltersState as ColumnFiltersState$1, ColumnOrderState, ColumnOrderState as ColumnOrderState$1, ColumnPinningState, ColumnPinningState as ColumnPinningState$1, ColumnSizingState, ColumnSizingState as ColumnSizingState$1, ColumnVisibilityState, ColumnVisibilityState as ColumnVisibilityState$1, ExpandedState, ExpandedState as ExpandedState$1, FilterFn, FilterFnOption, GroupingState, GroupingState as GroupingState$1, Header as Header$1, HeaderGroup as HeaderGroup$1, PaginationState, PaginationState as PaginationState$1, ReactTable, Row as Row$1, RowData, RowData as RowData$1, RowPinningState, RowPinningState as RowPinningState$1, RowSelectionState, RowSelectionState as RowSelectionState$1, SortingState, SortingState as SortingState$1, TableFeatures, TableOptions, aggregationFn_count, aggregationFn_extent, aggregationFn_first, aggregationFn_last, aggregationFn_max, aggregationFn_mean, aggregationFn_median, aggregationFn_min, aggregationFn_sum, aggregationFn_unique, aggregationFn_uniqueCount, flexRender } from "@tanstack/react-table";
|
|
@@ -859,6 +859,14 @@ declare module "@tanstack/react-table" {
|
|
|
859
859
|
* Single-line truncation with a title tooltip (host vocabulary: `Text.truncate`).
|
|
860
860
|
*/
|
|
861
861
|
truncate?: boolean;
|
|
862
|
+
/**
|
|
863
|
+
* Fit the column to its rendered content and keep it fitted as the content changes: the
|
|
864
|
+
* header, the rendered cells and the footer, each whole (docs/sizing.md#autosize). The fit is
|
|
865
|
+
* the column's width — a user's resize still wins over it, `minSize`/`maxSize` still bound it,
|
|
866
|
+
* and `size` holds the place until the first fit. A `truncate` column fits its typical content
|
|
867
|
+
* and leaves the outliers to the ellipsis.
|
|
868
|
+
*/
|
|
869
|
+
autosize?: boolean;
|
|
862
870
|
/**
|
|
863
871
|
* Header filter UI: a variant shorthand, a config, or a fully custom renderer.
|
|
864
872
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1096,6 +1096,7 @@ const defaultLabels = {
|
|
|
1096
1096
|
ungroupColumn: "Ungroup",
|
|
1097
1097
|
columnWidth: "Width",
|
|
1098
1098
|
columnWidthAuto: "Auto",
|
|
1099
|
+
columnWidthFit: "Fit",
|
|
1099
1100
|
resizeColumn: "Drag to resize; double-click to fit content",
|
|
1100
1101
|
reorderColumn: "Drag to reorder column",
|
|
1101
1102
|
filterColumn: (column) => `Filter ${column}`,
|
|
@@ -1332,6 +1333,7 @@ function ColumnsPanelItem({ column, table, labels, icons, index, zone, orderable
|
|
|
1332
1333
|
const canGroup = table.options.enableGrouping === true && column.getCanGroup();
|
|
1333
1334
|
const width = table.atoms.columnSizing.get()[column.id];
|
|
1334
1335
|
const declaredWidth = rawColumnSizing(column.columnDef)?.size ?? table.options.defaultColumn?.size;
|
|
1336
|
+
const widthPlaceholder = column.columnDef.meta?.autosize === true ? labels.columnWidthFit : declaredWidth === void 0 ? labels.columnWidthAuto : String(declaredWidth);
|
|
1335
1337
|
const handleWidthChange = (value) => {
|
|
1336
1338
|
table.setColumnSizing((previous) => {
|
|
1337
1339
|
if (value === "") {
|
|
@@ -1393,7 +1395,7 @@ function ColumnsPanelItem({ column, table, labels, icons, index, zone, orderable
|
|
|
1393
1395
|
classNames: { input: "ledger-columns-panel-width-input" },
|
|
1394
1396
|
max: column.columnDef.maxSize,
|
|
1395
1397
|
min: column.columnDef.minSize,
|
|
1396
|
-
placeholder:
|
|
1398
|
+
placeholder: widthPlaceholder,
|
|
1397
1399
|
size: "xs",
|
|
1398
1400
|
startValue: declaredWidth,
|
|
1399
1401
|
step: 10,
|
|
@@ -3066,34 +3068,66 @@ function TableFooter({ table, ariaRowIndexStart, columnWindow }) {
|
|
|
3066
3068
|
});
|
|
3067
3069
|
}
|
|
3068
3070
|
//#endregion
|
|
3069
|
-
//#region src/autosize
|
|
3071
|
+
//#region src/column-autosize.ts
|
|
3070
3072
|
/**
|
|
3071
|
-
*
|
|
3072
|
-
*
|
|
3073
|
-
*
|
|
3074
|
-
* footer cell, which is rendered content the column has to hold like any other. Writes the result
|
|
3075
|
-
* through `columnSizing`, clamped like an interactive resize.
|
|
3073
|
+
* Fitting columns to their rendered content (docs/sizing.md#autosize) — one measurement behind
|
|
3074
|
+
* both of its uses: the resizer's double-click, which writes the fit as a `columnSizing` entry,
|
|
3075
|
+
* and `meta.autosize`, which keeps a column fitted as its content changes (`use-autosize-widths.ts`).
|
|
3076
3076
|
*
|
|
3077
|
-
*
|
|
3078
|
-
* the
|
|
3077
|
+
* What is measured is what the column has to hold: the header cell, every RENDERED body cell —
|
|
3078
|
+
* under virtualization that is the current window, the industry contract for autosize (unrendered
|
|
3079
|
+
* rows have no boxes to measure) — and the footer cell, which is rendered content like any other.
|
|
3080
|
+
* A cell that spans columns (a merged body cell, a footer total, a detail panel) says nothing about
|
|
3081
|
+
* the width of any one of them, and a cell holding an editor is as wide as the editor makes
|
|
3082
|
+
* itself, not as its value; neither is measured.
|
|
3079
3083
|
*
|
|
3080
3084
|
* A content cell is measured out of the table's layout: for the pass it is a block as wide as its
|
|
3081
3085
|
* content (`display: block; width: max-content`, no wrapping), so its width is the content's, in
|
|
3082
3086
|
* whichever direction that lies. Read in place, a cell is never narrower than its column — a fixed
|
|
3083
3087
|
* table lays every cell at the column's width, and a truncating span clips at it — so a fit could
|
|
3084
|
-
* only ever widen a column. Every cell is switched first and read afterwards, so
|
|
3085
|
-
* costs one reflow, and each gets its own inline styles back
|
|
3088
|
+
* only ever widen a column. Every cell of every column is switched first and read afterwards, so a
|
|
3089
|
+
* pass costs one reflow however many columns it fits, and each cell gets its own inline styles back
|
|
3090
|
+
* before anything paints.
|
|
3086
3091
|
*/
|
|
3087
3092
|
/**
|
|
3088
3093
|
* Breathing room over the tightest fit — content flush against the column edge reads clipped.
|
|
3089
3094
|
*/
|
|
3090
3095
|
const AUTOSIZE_SLACK_PX = 8;
|
|
3091
3096
|
/**
|
|
3092
|
-
* Reserved for the hover-revealed header actions overlay (the filter button) so
|
|
3093
|
-
*
|
|
3097
|
+
* Reserved for the hover-revealed header actions overlay (the filter button) so a fit does not
|
|
3098
|
+
* park the drag line underneath it.
|
|
3094
3099
|
*/
|
|
3095
3100
|
const HEADER_ACTIONS_ALLOWANCE_PX = 28;
|
|
3096
3101
|
/**
|
|
3102
|
+
* Tukey's fence: a value past the third quartile by more than this many interquartile ranges is an
|
|
3103
|
+
* outlier. 1.5 is Tukey's own constant and MUI X's `outliersFactor` default.
|
|
3104
|
+
*/
|
|
3105
|
+
const OUTLIER_FACTOR = 1.5;
|
|
3106
|
+
/**
|
|
3107
|
+
* Linear interpolation between closest ranks (Hyndman–Fan type 7, the spreadsheet and NumPy
|
|
3108
|
+
* default) over ascending `sorted`.
|
|
3109
|
+
*/
|
|
3110
|
+
function quantile(sorted, p) {
|
|
3111
|
+
const rank = (sorted.length - 1) * p;
|
|
3112
|
+
const lower = Math.floor(rank);
|
|
3113
|
+
const below = sorted[lower];
|
|
3114
|
+
const above = sorted[Math.min(lower + 1, sorted.length - 1)];
|
|
3115
|
+
return below + (rank - lower) * (above - below);
|
|
3116
|
+
}
|
|
3117
|
+
/**
|
|
3118
|
+
* The widest of `values` within Tukey's upper fence (Q3 + 1.5 × IQR) — the width that holds every
|
|
3119
|
+
* value but the outliers. A set too uniform to have any (IQR 0) fences at its common value, so a
|
|
3120
|
+
* single long value among identical ones is still the outlier it reads as.
|
|
3121
|
+
*/
|
|
3122
|
+
function fencedMax(values) {
|
|
3123
|
+
if (values.length === 0) return 0;
|
|
3124
|
+
const sorted = values.toSorted((a, b) => a - b);
|
|
3125
|
+
const q1 = quantile(sorted, .25);
|
|
3126
|
+
const q3 = quantile(sorted, .75);
|
|
3127
|
+
const fence = q3 + OUTLIER_FACTOR * (q3 - q1);
|
|
3128
|
+
return sorted.findLast((value) => value <= fence) ?? sorted[0];
|
|
3129
|
+
}
|
|
3130
|
+
/**
|
|
3097
3131
|
* Computed lengths always resolve to `Npx`; strip the unit before coercing.
|
|
3098
3132
|
*/
|
|
3099
3133
|
function asPx(value) {
|
|
@@ -3110,12 +3144,27 @@ function headerCellWidth(th, hasFilter) {
|
|
|
3110
3144
|
const indicatorWidth = indicator ? indicator.offsetWidth + 6 : 0;
|
|
3111
3145
|
return labelText.scrollWidth + indicatorWidth + horizontalPadding(th) + (hasFilter ? HEADER_ACTIONS_ALLOWANCE_PX : 0);
|
|
3112
3146
|
}
|
|
3113
|
-
function
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3147
|
+
function contentCells(main, region, selector) {
|
|
3148
|
+
return [...main.querySelectorAll(`:scope ${region} ${selector}`)].filter((cell) => cell.colSpan <= 1 && !Object.hasOwn(cell.dataset, "editing"));
|
|
3149
|
+
}
|
|
3150
|
+
/**
|
|
3151
|
+
* The width each target's rendered content needs, slack included, in integer pixels — before the
|
|
3152
|
+
* column's own `minSize`/`maxSize`, which are the caller's to apply. A column with nothing rendered
|
|
3153
|
+
* (one a column window left out) has no entry.
|
|
3154
|
+
*/
|
|
3155
|
+
function measureColumnWidths(main, targets) {
|
|
3156
|
+
const columns = targets.map((target) => {
|
|
3157
|
+
const selector = `[data-ledger-column-id="${CSS.escape(target.columnId)}"]`;
|
|
3158
|
+
return {
|
|
3159
|
+
target,
|
|
3160
|
+
header: main.querySelector(`:scope .ledger-header ${selector}`),
|
|
3161
|
+
body: contentCells(main, ".ledger-tbody", selector),
|
|
3162
|
+
footer: contentCells(main, ".ledger-footer", selector)
|
|
3163
|
+
};
|
|
3164
|
+
});
|
|
3165
|
+
const headers = columns.map((column) => column.header).filter((header) => header !== null);
|
|
3166
|
+
const contents = columns.flatMap((column) => [...column.body, ...column.footer]);
|
|
3167
|
+
const cells = [...headers, ...contents];
|
|
3119
3168
|
const previous = cells.map((cell) => {
|
|
3120
3169
|
return {
|
|
3121
3170
|
display: cell.style.display,
|
|
@@ -3124,22 +3173,37 @@ function autosizeColumn(setColumnSizing, { columnId, minSize, maxSize, hasFilter
|
|
|
3124
3173
|
};
|
|
3125
3174
|
});
|
|
3126
3175
|
for (const cell of cells) cell.style.whiteSpace = "nowrap";
|
|
3127
|
-
for (const cell of
|
|
3176
|
+
for (const cell of contents) {
|
|
3128
3177
|
cell.style.display = "block";
|
|
3129
3178
|
cell.style.width = "max-content";
|
|
3130
3179
|
}
|
|
3131
|
-
|
|
3132
|
-
for (const
|
|
3180
|
+
const widths = /* @__PURE__ */ new Map();
|
|
3181
|
+
for (const { target, header, body, footer } of columns) {
|
|
3182
|
+
if (!header && body.length === 0 && footer.length === 0) continue;
|
|
3183
|
+
const bodyWidths = body.map((cell) => cell.scrollWidth);
|
|
3184
|
+
const content = Math.max(header ? headerCellWidth(header, target.hasFilter) : 0, ...footer.map((cell) => cell.scrollWidth), target.truncate ? fencedMax(bodyWidths) : Math.max(0, ...bodyWidths));
|
|
3185
|
+
widths.set(target.columnId, Math.round(content) + AUTOSIZE_SLACK_PX);
|
|
3186
|
+
}
|
|
3133
3187
|
for (const [index, cell] of cells.entries()) {
|
|
3134
3188
|
const styles = previous[index];
|
|
3135
3189
|
cell.style.display = styles?.display ?? "";
|
|
3136
3190
|
cell.style.whiteSpace = styles?.whiteSpace ?? "";
|
|
3137
3191
|
cell.style.width = styles?.width ?? "";
|
|
3138
3192
|
}
|
|
3139
|
-
|
|
3140
|
-
|
|
3193
|
+
return widths;
|
|
3194
|
+
}
|
|
3195
|
+
/**
|
|
3196
|
+
* The resizer's double-click: fit the column once and write the fit through `columnSizing`, clamped
|
|
3197
|
+
* like an interactive resize. The column, its constraints and whether it carries a filter all
|
|
3198
|
+
* arrive from the render that put the handle on screen, for the reason `use-column-resize.ts` gives.
|
|
3199
|
+
*/
|
|
3200
|
+
function autosizeColumn(setColumnSizing, { minSize, maxSize, ...target }, main) {
|
|
3201
|
+
const fitted = measureColumnWidths(main, [target]).get(target.columnId);
|
|
3202
|
+
if (fitted === void 0) return;
|
|
3203
|
+
const next = Math.min(Math.max(fitted, minSize), maxSize);
|
|
3204
|
+
setColumnSizing((previous) => previous[target.columnId] === next ? previous : {
|
|
3141
3205
|
...previous,
|
|
3142
|
-
[columnId]: next
|
|
3206
|
+
[target.columnId]: next
|
|
3143
3207
|
});
|
|
3144
3208
|
}
|
|
3145
3209
|
//#endregion
|
|
@@ -3751,7 +3815,8 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
|
|
|
3751
3815
|
const main = event.currentTarget.closest(".ledger-main");
|
|
3752
3816
|
if (main) autosizeColumn(table.setColumnSizing, {
|
|
3753
3817
|
...resizerSpec,
|
|
3754
|
-
hasFilter: meta?.filter !== void 0
|
|
3818
|
+
hasFilter: meta?.filter !== void 0,
|
|
3819
|
+
truncate: meta?.truncate === true
|
|
3755
3820
|
}, main);
|
|
3756
3821
|
},
|
|
3757
3822
|
...resize.getResizerProps(resizerSpec),
|
|
@@ -3762,6 +3827,160 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
|
|
|
3762
3827
|
});
|
|
3763
3828
|
}
|
|
3764
3829
|
//#endregion
|
|
3830
|
+
//#region src/use-autosize-widths.ts
|
|
3831
|
+
/**
|
|
3832
|
+
* `meta.autosize` (docs/sizing.md#autosize): keeps each such column fitted to its rendered content
|
|
3833
|
+
* and hands the width engine the fits, which rank between a user's resize and the author's `size`.
|
|
3834
|
+
*
|
|
3835
|
+
* When a fit is taken, and what it may do:
|
|
3836
|
+
* - **A new view refits.** Different rows (a new page, a filter, a sort — anything that changes the
|
|
3837
|
+
* row ids or their order), new column definitions (a renderer, a translated header) or another
|
|
3838
|
+
* set of visible columns, another density, or a web font that finished loading: the content is
|
|
3839
|
+
* new, so the widths follow it in both directions.
|
|
3840
|
+
* - **The same rows again only widen.** A refetch that hands back the same rows (a poll, an
|
|
3841
|
+
* edit) may make a cell wider, never a column narrower — otherwise a value that alternates
|
|
3842
|
+
* between short and long would shake the columns on every refresh.
|
|
3843
|
+
* - **Content that arrives with a window only widens, once the scrolling settles.** Under
|
|
3844
|
+
* virtualization the rows and columns scrolled into view were never measured; fitting them on
|
|
3845
|
+
* every window shift would reflow the table each step of a scroll, and narrowing would move the
|
|
3846
|
+
* columns under the reader.
|
|
3847
|
+
* - **A table with no layout waits for one.** In a hidden tab or a collapsed panel every cell
|
|
3848
|
+
* measures zero; the fit is taken when the table is first laid out instead.
|
|
3849
|
+
*
|
|
3850
|
+
* A fit is taken in a layout effect, before the browser paints, so a refit never shows the old
|
|
3851
|
+
* widths for a frame; a column a user resized is left to the user's width and not measured.
|
|
3852
|
+
*/
|
|
3853
|
+
/**
|
|
3854
|
+
* How long a scroll has to rest before the content it brought into view is fitted.
|
|
3855
|
+
*/
|
|
3856
|
+
const SCROLL_SETTLE_MS = 150;
|
|
3857
|
+
const NO_WIDTHS = {};
|
|
3858
|
+
function autosizeTargets(columns, columnSizing) {
|
|
3859
|
+
return columns.flatMap((column) => {
|
|
3860
|
+
const { meta } = column.columnDef;
|
|
3861
|
+
return meta?.autosize === true && !isInternalColumn(column.id) && columnSizing[column.id] === void 0 ? [{
|
|
3862
|
+
columnId: column.id,
|
|
3863
|
+
hasFilter: meta.filter !== void 0,
|
|
3864
|
+
truncate: meta.truncate === true
|
|
3865
|
+
}] : [];
|
|
3866
|
+
});
|
|
3867
|
+
}
|
|
3868
|
+
function sameIds(previous, next) {
|
|
3869
|
+
return previous.length === next.length && previous.every((id, index) => id === next[index]);
|
|
3870
|
+
}
|
|
3871
|
+
/**
|
|
3872
|
+
* The fits after a pass: a column measured takes its new width (in `widen` mode, only if wider), a
|
|
3873
|
+
* column with nothing rendered keeps the width it had, a column no longer fitted drops out.
|
|
3874
|
+
*/
|
|
3875
|
+
function mergeWidths(previous, measured, targets, mode) {
|
|
3876
|
+
const next = {};
|
|
3877
|
+
for (const { columnId } of targets) {
|
|
3878
|
+
const fresh = measured.get(columnId);
|
|
3879
|
+
const held = previous[columnId];
|
|
3880
|
+
const width = fresh === void 0 || held === void 0 ? fresh ?? held : mode === "widen" ? Math.max(held, fresh) : fresh;
|
|
3881
|
+
if (width !== void 0) next[columnId] = width;
|
|
3882
|
+
}
|
|
3883
|
+
const keys = Object.keys(next);
|
|
3884
|
+
return keys.length === Object.keys(previous).length && keys.every((key) => previous[key] === next[key]) ? previous : next;
|
|
3885
|
+
}
|
|
3886
|
+
/**
|
|
3887
|
+
* Bumps whenever web fonts finish loading: text measured in a fallback face is the wrong width.
|
|
3888
|
+
*/
|
|
3889
|
+
function useFontsVersion(enabled) {
|
|
3890
|
+
const [version, setVersion] = useState(0);
|
|
3891
|
+
useEffect(() => {
|
|
3892
|
+
if (!enabled || !("fonts" in document)) return;
|
|
3893
|
+
const bump = () => setVersion((previous) => previous + 1);
|
|
3894
|
+
document.fonts.addEventListener("loadingdone", bump);
|
|
3895
|
+
return () => document.fonts.removeEventListener("loadingdone", bump);
|
|
3896
|
+
}, [enabled]);
|
|
3897
|
+
return version;
|
|
3898
|
+
}
|
|
3899
|
+
function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appearance, virtualized }) {
|
|
3900
|
+
const targets = autosizeTargets(columns, columnSizing);
|
|
3901
|
+
const enabled = targets.length > 0;
|
|
3902
|
+
const fontsVersion = useFontsVersion(enabled);
|
|
3903
|
+
const signature = JSON.stringify([
|
|
3904
|
+
targets,
|
|
3905
|
+
appearance,
|
|
3906
|
+
fontsVersion
|
|
3907
|
+
]);
|
|
3908
|
+
const [widths, setWidths] = useState(NO_WIDTHS);
|
|
3909
|
+
const view = useRef(null);
|
|
3910
|
+
/**
|
|
3911
|
+
* A fit was due while the table had no layout.
|
|
3912
|
+
*/
|
|
3913
|
+
const awaitingLayout = useRef(false);
|
|
3914
|
+
const settleTimer = useRef(void 0);
|
|
3915
|
+
const fit = useEventCallback((mode) => {
|
|
3916
|
+
if (!main) return;
|
|
3917
|
+
if (main.getClientRects().length === 0) {
|
|
3918
|
+
awaitingLayout.current = true;
|
|
3919
|
+
return;
|
|
3920
|
+
}
|
|
3921
|
+
awaitingLayout.current = false;
|
|
3922
|
+
const measured = measureColumnWidths(main, targets);
|
|
3923
|
+
setWidths((previous) => mergeWidths(previous, measured, targets, mode));
|
|
3924
|
+
});
|
|
3925
|
+
const fitWhenSettled = useCallback(() => {
|
|
3926
|
+
clearTimeout(settleTimer.current);
|
|
3927
|
+
settleTimer.current = setTimeout(() => fit("widen"), SCROLL_SETTLE_MS);
|
|
3928
|
+
}, [fit]);
|
|
3929
|
+
useEffect(() => () => clearTimeout(settleTimer.current), []);
|
|
3930
|
+
useLayoutEffect(() => {
|
|
3931
|
+
if (!enabled) {
|
|
3932
|
+
view.current = null;
|
|
3933
|
+
setWidths(NO_WIDTHS);
|
|
3934
|
+
return;
|
|
3935
|
+
}
|
|
3936
|
+
const rowIds = rows.map((row) => row.id);
|
|
3937
|
+
const sameView = view.current !== null && view.current.columns === columns && view.current.signature === signature && sameIds(view.current.rowIds, rowIds);
|
|
3938
|
+
view.current = {
|
|
3939
|
+
columns,
|
|
3940
|
+
signature,
|
|
3941
|
+
rowIds
|
|
3942
|
+
};
|
|
3943
|
+
fit(sameView ? "widen" : "refit");
|
|
3944
|
+
}, [
|
|
3945
|
+
enabled,
|
|
3946
|
+
main,
|
|
3947
|
+
columns,
|
|
3948
|
+
rows,
|
|
3949
|
+
signature,
|
|
3950
|
+
fit
|
|
3951
|
+
]);
|
|
3952
|
+
useEffect(() => {
|
|
3953
|
+
if (enabled && virtualized && widths !== NO_WIDTHS) fitWhenSettled();
|
|
3954
|
+
}, [
|
|
3955
|
+
enabled,
|
|
3956
|
+
virtualized,
|
|
3957
|
+
widths,
|
|
3958
|
+
fitWhenSettled
|
|
3959
|
+
]);
|
|
3960
|
+
useEffect(() => {
|
|
3961
|
+
if (!enabled || !main) return;
|
|
3962
|
+
const observer = new ResizeObserver(() => {
|
|
3963
|
+
if (awaitingLayout.current) fit("refit");
|
|
3964
|
+
else if (virtualized) fitWhenSettled();
|
|
3965
|
+
});
|
|
3966
|
+
observer.observe(main);
|
|
3967
|
+
if (!virtualized || !viewport) return () => observer.disconnect();
|
|
3968
|
+
viewport.addEventListener("scroll", fitWhenSettled, { passive: true });
|
|
3969
|
+
return () => {
|
|
3970
|
+
observer.disconnect();
|
|
3971
|
+
viewport.removeEventListener("scroll", fitWhenSettled);
|
|
3972
|
+
};
|
|
3973
|
+
}, [
|
|
3974
|
+
enabled,
|
|
3975
|
+
main,
|
|
3976
|
+
viewport,
|
|
3977
|
+
virtualized,
|
|
3978
|
+
fit,
|
|
3979
|
+
fitWhenSettled
|
|
3980
|
+
]);
|
|
3981
|
+
return widths;
|
|
3982
|
+
}
|
|
3983
|
+
//#endregion
|
|
3765
3984
|
//#region src/use-column-widths.ts
|
|
3766
3985
|
/**
|
|
3767
3986
|
* The width engine (docs/sizing.md): every visible leaf column resolves to an exact integer
|
|
@@ -3769,8 +3988,9 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
|
|
|
3769
3988
|
* number system — the browser never redistributes anything.
|
|
3770
3989
|
*
|
|
3771
3990
|
* Rules, in order:
|
|
3772
|
-
* - a column with an explicit width (user-resized `columnSizing` entry, else
|
|
3773
|
-
* `size`, else `defaultColumn.size`) is fixed at
|
|
3991
|
+
* - a column with an explicit width (user-resized `columnSizing` entry, else its fitted content
|
|
3992
|
+
* width under `meta.autosize`, else the author's `size`, else `defaultColumn.size`) is fixed at
|
|
3993
|
+
* that width, clamped to its declared min/max;
|
|
3774
3994
|
* - a column without one is a grow column with basis `minSize ?? 80`; container surplus is
|
|
3775
3995
|
* distributed proportionally to the bases (integer floor, remainder in display order), capped
|
|
3776
3996
|
* by maxSize; when the container is too small every grow column falls back to its basis and the
|
|
@@ -3836,7 +4056,7 @@ function resolveColumnWidths(columns, columnSizing, availableWidth) {
|
|
|
3836
4056
|
const byId = {};
|
|
3837
4057
|
const growColumns = [];
|
|
3838
4058
|
for (const column of columns) {
|
|
3839
|
-
const sized = finiteNumber(columnSizing[column.id]) ?? finiteNumber(column.size);
|
|
4059
|
+
const sized = finiteNumber(columnSizing[column.id]) ?? finiteNumber(column.fit) ?? finiteNumber(column.size);
|
|
3840
4060
|
if (sized === void 0) {
|
|
3841
4061
|
const basis = clampWidth(column.minSize ?? DEFAULT_FLEX_BASIS, column.minSize, column.maxSize);
|
|
3842
4062
|
byId[column.id] = basis;
|
|
@@ -3872,7 +4092,7 @@ function minWidthPx(tableMinWidth, viewport) {
|
|
|
3872
4092
|
if (!tableElement) return Number.parseFloat(tableMinWidth) || 0;
|
|
3873
4093
|
return Number.parseFloat(getComputedStyle(tableElement).minWidth) || 0;
|
|
3874
4094
|
}
|
|
3875
|
-
function useColumnWidths(table, columns, viewport, tableMinWidth, injectedWidth) {
|
|
4095
|
+
function useColumnWidths(table, { columns, viewport, tableMinWidth, injectedWidth, autosizeWidths }) {
|
|
3876
4096
|
const [availableWidth, setAvailableWidth] = useState(0);
|
|
3877
4097
|
const measure = useCallback(() => {
|
|
3878
4098
|
if (!viewport) return;
|
|
@@ -3893,12 +4113,14 @@ function useColumnWidths(table, columns, viewport, tableMinWidth, injectedWidth)
|
|
|
3893
4113
|
const raw = rawColumnSizing(column.columnDef);
|
|
3894
4114
|
if (isInternalColumn(column.id)) return {
|
|
3895
4115
|
id: column.id,
|
|
4116
|
+
fit: void 0,
|
|
3896
4117
|
size: raw?.size ?? injectedWidth,
|
|
3897
4118
|
minSize: raw?.minSize ?? injectedWidth,
|
|
3898
4119
|
maxSize: raw?.maxSize ?? injectedWidth
|
|
3899
4120
|
};
|
|
3900
4121
|
return {
|
|
3901
4122
|
id: column.id,
|
|
4123
|
+
fit: autosizeWidths[column.id],
|
|
3902
4124
|
size: raw ? raw.size ?? defaultColumn?.size : column.columnDef.size,
|
|
3903
4125
|
minSize: raw ? raw.minSize ?? defaultColumn?.minSize : column.columnDef.minSize,
|
|
3904
4126
|
maxSize: raw ? raw.maxSize ?? defaultColumn?.maxSize : column.columnDef.maxSize
|
|
@@ -3909,7 +4131,8 @@ function useColumnWidths(table, columns, viewport, tableMinWidth, injectedWidth)
|
|
|
3909
4131
|
columnSizing,
|
|
3910
4132
|
availableWidth,
|
|
3911
4133
|
defaultColumn,
|
|
3912
|
-
injectedWidth
|
|
4134
|
+
injectedWidth,
|
|
4135
|
+
autosizeWidths
|
|
3913
4136
|
]);
|
|
3914
4137
|
const signature = JSON.stringify([resolved.total, Object.entries(resolved.byId)]);
|
|
3915
4138
|
return useMemo(() => resolved, [signature]);
|
|
@@ -6534,7 +6757,8 @@ function useStylesRevision(getStyles, selectors) {
|
|
|
6534
6757
|
//#endregion
|
|
6535
6758
|
//#region src/use-viewport-fit.ts
|
|
6536
6759
|
const UNMEASURED = {
|
|
6537
|
-
|
|
6760
|
+
overflowsX: false,
|
|
6761
|
+
overflowsY: false,
|
|
6538
6762
|
underfilled: false
|
|
6539
6763
|
};
|
|
6540
6764
|
/**
|
|
@@ -6548,10 +6772,12 @@ function useViewportFit(viewport) {
|
|
|
6548
6772
|
if (!viewport) return;
|
|
6549
6773
|
const content = viewport.firstElementChild;
|
|
6550
6774
|
const measure = () => {
|
|
6551
|
-
const
|
|
6775
|
+
const overflowsX = viewport.scrollWidth - viewport.clientWidth > 1;
|
|
6776
|
+
const overflowsY = viewport.scrollHeight - viewport.clientHeight > 1;
|
|
6552
6777
|
const underfilled = content instanceof HTMLElement && viewport.clientHeight - content.offsetHeight >= 1;
|
|
6553
|
-
setFit((previous) => previous.
|
|
6554
|
-
|
|
6778
|
+
setFit((previous) => previous.overflowsX === overflowsX && previous.overflowsY === overflowsY && previous.underfilled === underfilled ? previous : {
|
|
6779
|
+
overflowsX,
|
|
6780
|
+
overflowsY,
|
|
6555
6781
|
underfilled
|
|
6556
6782
|
});
|
|
6557
6783
|
};
|
|
@@ -6814,6 +7040,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
6814
7040
|
setViewport(element);
|
|
6815
7041
|
}, []);
|
|
6816
7042
|
const viewportFit = useViewportFit(viewport);
|
|
7043
|
+
const [main, setMain] = useState(null);
|
|
6817
7044
|
const startLeafColumns = table.getStartVisibleLeafColumns();
|
|
6818
7045
|
const endLeafColumns = table.getEndVisibleLeafColumns();
|
|
6819
7046
|
const displayColumns = [
|
|
@@ -6828,7 +7055,21 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
6828
7055
|
const visibleLeafColumns = useMemo(() => displayColumns, [displayOrderSignature, ledgerColumns]);
|
|
6829
7056
|
const size = sizeProp ?? "sm";
|
|
6830
7057
|
const scale = SIZES[size];
|
|
6831
|
-
const columnWidths = useColumnWidths(table,
|
|
7058
|
+
const columnWidths = useColumnWidths(table, {
|
|
7059
|
+
autosizeWidths: useAutosizeWidths({
|
|
7060
|
+
appearance: size,
|
|
7061
|
+
columnSizing: table.state.columnSizing,
|
|
7062
|
+
columns: visibleLeafColumns,
|
|
7063
|
+
main,
|
|
7064
|
+
rows: table.getRowModel().rows,
|
|
7065
|
+
viewport,
|
|
7066
|
+
virtualized: Boolean(virtualizedRows) || Boolean(virtualizedColumns)
|
|
7067
|
+
}),
|
|
7068
|
+
columns: visibleLeafColumns,
|
|
7069
|
+
injectedWidth: scale.injectedWidth,
|
|
7070
|
+
tableMinWidth,
|
|
7071
|
+
viewport
|
|
7072
|
+
});
|
|
6832
7073
|
const virtualization = virtualizedRows ? {
|
|
6833
7074
|
estimateHeight: typeof virtualizedRows === "object" && virtualizedRows.estimateHeight !== void 0 ? virtualizedRows.estimateHeight : scale.rowHeight,
|
|
6834
7075
|
overscan: typeof virtualizedRows === "object" && virtualizedRows.overscan !== void 0 ? virtualizedRows.overscan : 8
|
|
@@ -7167,7 +7408,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7167
7408
|
]);
|
|
7168
7409
|
const activeRowAnnouncer = useRef(null);
|
|
7169
7410
|
const rowNavigationHintId = `${instanceId}-row-navigation`;
|
|
7170
|
-
const viewportFocusStop = activeRowEnabled || viewportFit.
|
|
7411
|
+
const viewportFocusStop = activeRowEnabled || viewportFit.overflowsX || viewportFit.overflowsY;
|
|
7171
7412
|
const viewportDescribedBy = activeRowEnabled ? [viewportProps?.["aria-describedby"], rowNavigationHintId].filter(Boolean).join(" ") : viewportProps?.["aria-describedby"];
|
|
7172
7413
|
const announceActiveRow = useEventCallback(() => {
|
|
7173
7414
|
const target = activeRowAnnouncer.current;
|
|
@@ -7378,6 +7619,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7378
7619
|
children: labels.rowNavigation
|
|
7379
7620
|
})] }),
|
|
7380
7621
|
/* @__PURE__ */ jsxs("div", {
|
|
7622
|
+
ref: setMain,
|
|
7381
7623
|
"aria-busy": loading || void 0,
|
|
7382
7624
|
"aria-colcount": columnWindow === null ? void 0 : columnWindow.totalLeafCount,
|
|
7383
7625
|
"aria-describedby": ariaDescribedBy,
|
|
@@ -7411,7 +7653,10 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7411
7653
|
scrollbar: { backgroundColor: "transparent" }
|
|
7412
7654
|
},
|
|
7413
7655
|
viewportProps: mergeElementProps(viewportProps, {
|
|
7414
|
-
style: {
|
|
7656
|
+
style: {
|
|
7657
|
+
overscrollBehaviorX: viewportFit.overflowsX ? "none" : "auto",
|
|
7658
|
+
overscrollBehaviorY: viewportFit.overflowsY ? "none" : "auto"
|
|
7659
|
+
},
|
|
7415
7660
|
role: "rowgroup",
|
|
7416
7661
|
"aria-label": viewportProps?.["aria-label"] ?? (viewportFocusStop ? labels.rows : void 0),
|
|
7417
7662
|
"aria-describedby": viewportDescribedBy,
|