@coldsmirk/ledger-mantine 0.9.2 → 0.10.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 +435 -77
- 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 +436 -78
- 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/dist/styles.css +19 -0
- package/package.json +1 -1
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:
|
|
1422
|
+
placeholder: widthPlaceholder,
|
|
1421
1423
|
size: "xs",
|
|
1422
1424
|
startValue: declaredWidth,
|
|
1423
1425
|
step: 10,
|
|
@@ -2263,12 +2265,64 @@ function useColumnWindow({ enabled, overscan, viewport, centerColumnIds, widths,
|
|
|
2263
2265
|
]);
|
|
2264
2266
|
}
|
|
2265
2267
|
/**
|
|
2266
|
-
*
|
|
2267
|
-
*
|
|
2268
|
+
* What each rendered col holds, in colgroup order: a column, a spacer standing for the columns a
|
|
2269
|
+
* window left out, or the filler (docs/sizing.md#the-filler). Its length is what a full-width
|
|
2270
|
+
* cell (detail panel, loader row) spans; a row with no cells of its own (the skeleton) draws one
|
|
2271
|
+
* cell per entry.
|
|
2268
2272
|
*/
|
|
2269
|
-
function
|
|
2270
|
-
|
|
2271
|
-
|
|
2273
|
+
function renderedCols(view, leafColumnCount, pinnedEndCount, filler) {
|
|
2274
|
+
const columns = (count) => Array.from({ length: count }, () => "column");
|
|
2275
|
+
const fillerCol = filler ? ["filler"] : [];
|
|
2276
|
+
if (view === null) return [
|
|
2277
|
+
...columns(leafColumnCount - pinnedEndCount),
|
|
2278
|
+
...fillerCol,
|
|
2279
|
+
...columns(pinnedEndCount)
|
|
2280
|
+
];
|
|
2281
|
+
return [
|
|
2282
|
+
...columns(view.pinnedStartCount),
|
|
2283
|
+
...view.start > 0 ? ["spacer"] : [],
|
|
2284
|
+
...columns(view.end - view.start),
|
|
2285
|
+
...view.end < view.centerCount ? ["spacer"] : [],
|
|
2286
|
+
...fillerCol,
|
|
2287
|
+
...columns(view.pinnedEndCount)
|
|
2288
|
+
];
|
|
2289
|
+
}
|
|
2290
|
+
/**
|
|
2291
|
+
* Where the filler's cell stands in a row (docs/sizing.md#the-filler): before the first cell of
|
|
2292
|
+
* the end-pinned zone — so after the scrolling columns and a trailing spacer — or last where no
|
|
2293
|
+
* column is pinned to the end. The same index in every row, since every row tiles one colgroup.
|
|
2294
|
+
*/
|
|
2295
|
+
function fillerIndex(cells, inEndZone) {
|
|
2296
|
+
const index = cells.findIndex((cell) => inEndZone(cell));
|
|
2297
|
+
return index === -1 ? cells.length : index;
|
|
2298
|
+
}
|
|
2299
|
+
/**
|
|
2300
|
+
* A row's rendered cells with the filler's cell put in its place (`fillerIndex`) — a `td`, or a
|
|
2301
|
+
* `th` in the header — or as they are where the row carries none. The cell is empty and, like a
|
|
2302
|
+
* spacer's, out of the accessibility tree: no cell of the ARIA table.
|
|
2303
|
+
*/
|
|
2304
|
+
function withFillerCell(cells, filler) {
|
|
2305
|
+
const nodes = cells.map((cell) => cell.node);
|
|
2306
|
+
if (filler === null) return nodes;
|
|
2307
|
+
const at = fillerIndex(cells, (cell) => cell.endZone);
|
|
2308
|
+
const fillerCell = (0, react.createElement)(filler, {
|
|
2309
|
+
key: "ledger:filler",
|
|
2310
|
+
"aria-hidden": true,
|
|
2311
|
+
"data-ledger-filler": true
|
|
2312
|
+
});
|
|
2313
|
+
return [
|
|
2314
|
+
...nodes.slice(0, at),
|
|
2315
|
+
fillerCell,
|
|
2316
|
+
...nodes.slice(at)
|
|
2317
|
+
];
|
|
2318
|
+
}
|
|
2319
|
+
/**
|
|
2320
|
+
* A header or footer cell's zone is its own leaves': v9 splits a group at every pinning
|
|
2321
|
+
* boundary, so each instance covers one zone — while the group column's `getIsPinned()` answers
|
|
2322
|
+
* for all its leaves at once, and would put a group's scrolling half in the end zone.
|
|
2323
|
+
*/
|
|
2324
|
+
function headerInEndZone(header) {
|
|
2325
|
+
return header.getLeafHeaders()[0]?.column.getIsPinned() === "end";
|
|
2272
2326
|
}
|
|
2273
2327
|
/**
|
|
2274
2328
|
* A leaf-level row's cells against the window. `cells` is the full display-ordered list, so a
|
|
@@ -2674,7 +2728,7 @@ function DataCell({ cell, editing, rowEditing, isFirstDataCell, depth, rowSpan,
|
|
|
2674
2728
|
children: content
|
|
2675
2729
|
});
|
|
2676
2730
|
}
|
|
2677
|
-
function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editingRow, dragging, dropSide, selected, active, activatable, expanded, depth, spanning, columnWindow, pinnedPosition, pinnedOffset, virtualIndex, measureRef, ariaRowIndex }) {
|
|
2731
|
+
function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editingRow, dragging, dropSide, selected, active, activatable, expanded, depth, spanning, columnWindow, filler, pinnedPosition, pinnedOffset, virtualIndex, measureRef, ariaRowIndex }) {
|
|
2678
2732
|
const { getStyles, onRowClick, onRowActivate, onRowDoubleClick, onRowContextMenu, rowProps, activeRowEnabled, setActiveRow } = useDataTableContext();
|
|
2679
2733
|
const cells = row.getVisibleCells();
|
|
2680
2734
|
const firstDataCellIndex = cells.findIndex((cell) => !isInternalColumn(cell.column.id));
|
|
@@ -2729,26 +2783,40 @@ function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editing
|
|
|
2729
2783
|
rowSpan: spanning ? cell.getRowSpan() : 1
|
|
2730
2784
|
}, cell.id);
|
|
2731
2785
|
};
|
|
2732
|
-
|
|
2786
|
+
const placed = (cell, displayIndex) => {
|
|
2787
|
+
return {
|
|
2788
|
+
node: renderCell(cell, displayIndex),
|
|
2789
|
+
endZone: cell.column.getIsPinned() === "end"
|
|
2790
|
+
};
|
|
2791
|
+
};
|
|
2792
|
+
const fillerCell = filler ? "td" : null;
|
|
2793
|
+
if (columnWindow === null) return withFillerCell(cells.map((cell, index) => placed(cell, index)), fillerCell);
|
|
2733
2794
|
const segments = windowRowCells(cells, columnWindow);
|
|
2734
2795
|
const windowedStart = columnWindow.pinnedStartCount + columnWindow.start;
|
|
2735
2796
|
const trailingStart = cells.length - columnWindow.pinnedEndCount;
|
|
2736
|
-
return
|
|
2737
|
-
segments.leading.map((cell, index) =>
|
|
2738
|
-
columnWindow.start > 0
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
columnWindow.end < columnWindow.centerCount && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
2744
|
-
"aria-hidden": true,
|
|
2745
|
-
"data-ledger-spacer": true
|
|
2746
|
-
}),
|
|
2747
|
-
segments.trailing.map((cell, index) => renderCell(cell, trailingStart + index))
|
|
2748
|
-
] });
|
|
2797
|
+
return withFillerCell([
|
|
2798
|
+
...segments.leading.map((cell, index) => placed(cell, index)),
|
|
2799
|
+
...columnWindow.start > 0 ? [spacerCell("leading")] : [],
|
|
2800
|
+
...segments.windowed.map((cell, index) => placed(cell, windowedStart + index)),
|
|
2801
|
+
...columnWindow.end < columnWindow.centerCount ? [spacerCell("trailing")] : [],
|
|
2802
|
+
...segments.trailing.map((cell, index) => placed(cell, trailingStart + index))
|
|
2803
|
+
], fillerCell);
|
|
2749
2804
|
}
|
|
2750
2805
|
}
|
|
2751
2806
|
const DataRow = (0, react.memo)(DataRowImpl);
|
|
2807
|
+
/**
|
|
2808
|
+
* A spacer's cell over a spacer col (docs/virtualization.md#column-virtualization), placed in its
|
|
2809
|
+
* row as the scrolling columns' — never the end zone's.
|
|
2810
|
+
*/
|
|
2811
|
+
function spacerCell(edge) {
|
|
2812
|
+
return {
|
|
2813
|
+
node: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
2814
|
+
"aria-hidden": true,
|
|
2815
|
+
"data-ledger-spacer": true
|
|
2816
|
+
}, `ledger:spacer-${edge}`),
|
|
2817
|
+
endZone: false
|
|
2818
|
+
};
|
|
2819
|
+
}
|
|
2752
2820
|
function DetailRow({ row, renderDetailPanel, colSpan, dragging, dropSide, last, pinnedPosition, pinnedOffset, virtualIndex, measureRef, ariaRowIndex }) {
|
|
2753
2821
|
const { getStyles } = useDataTableContext();
|
|
2754
2822
|
const pinnedStyle = pinnedPosition === "top" ? { top: `${pinnedOffset ?? 0}px` } : pinnedPosition === "bottom" ? { bottom: `${pinnedOffset ?? 0}px` } : void 0;
|
|
@@ -2772,15 +2840,15 @@ function DetailRow({ row, renderDetailPanel, colSpan, dragging, dropSide, last,
|
|
|
2772
2840
|
})
|
|
2773
2841
|
});
|
|
2774
2842
|
}
|
|
2775
|
-
function SkeletonRows({ rowCount,
|
|
2843
|
+
function SkeletonRows({ rowCount, cols, ariaRowIndexStart }) {
|
|
2776
2844
|
const { getStyles } = useDataTableContext();
|
|
2777
2845
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: Array.from({ length: rowCount }, (_, rowIndex) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Table.Tr, {
|
|
2778
2846
|
"aria-rowindex": ariaRowIndexStart === void 0 ? void 0 : ariaRowIndexStart + rowIndex,
|
|
2779
2847
|
"data-last": rowIndex === rowCount - 1 || void 0,
|
|
2780
2848
|
role: "row",
|
|
2781
2849
|
...getStyles("row"),
|
|
2782
|
-
children:
|
|
2783
|
-
"data-leading":
|
|
2850
|
+
children: cols.map((col, colIndex) => col === "column" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Table.Td, {
|
|
2851
|
+
"data-leading": colIndex === 0 || void 0,
|
|
2784
2852
|
role: "cell",
|
|
2785
2853
|
...getStyles("cell"),
|
|
2786
2854
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Skeleton, {
|
|
@@ -2788,7 +2856,13 @@ function SkeletonRows({ rowCount, columnCount, ariaRowIndexStart }) {
|
|
|
2788
2856
|
my: "calc((1lh - 10px) / 2)",
|
|
2789
2857
|
radius: "sm"
|
|
2790
2858
|
})
|
|
2791
|
-
},
|
|
2859
|
+
}, colIndex) : col === "spacer" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
2860
|
+
"aria-hidden": true,
|
|
2861
|
+
"data-ledger-spacer": true
|
|
2862
|
+
}, colIndex) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
2863
|
+
"aria-hidden": true,
|
|
2864
|
+
"data-ledger-filler": true
|
|
2865
|
+
}, colIndex))
|
|
2792
2866
|
}, rowIndex)) });
|
|
2793
2867
|
}
|
|
2794
2868
|
function LoaderRow({ colSpan, ariaRowIndex }) {
|
|
@@ -2839,7 +2913,7 @@ function LoadMoreErrorRow({ colSpan, message, ariaRowIndex, onRetry }) {
|
|
|
2839
2913
|
})
|
|
2840
2914
|
});
|
|
2841
2915
|
}
|
|
2842
|
-
function TableBody({ table, virtualization, columnWindow, viewportRef, loading, loadingMore, loadMoreError, onLoadMoreRetry, reorderSourceId, reorderTarget, skeletonRowCount, onVirtualizerChange }) {
|
|
2916
|
+
function TableBody({ table, virtualization, columnWindow, filler, viewportRef, loading, loadingMore, loadMoreError, onLoadMoreRetry, reorderSourceId, reorderTarget, skeletonRowCount, onVirtualizerChange }) {
|
|
2843
2917
|
const { getStyles, withColumnHeaders } = useDataTableContext();
|
|
2844
2918
|
const ledger = table.options.meta?.ledger;
|
|
2845
2919
|
const withDetailPanels = Boolean(ledger?.renderDetailPanel);
|
|
@@ -2886,8 +2960,8 @@ function TableBody({ table, virtualization, columnWindow, viewportRef, loading,
|
|
|
2886
2960
|
virtualizer,
|
|
2887
2961
|
onVirtualizerChange
|
|
2888
2962
|
]);
|
|
2889
|
-
const
|
|
2890
|
-
const fullWidthColSpan =
|
|
2963
|
+
const cols = renderedCols(columnWindow, table.getVisibleLeafColumns().length, table.getEndVisibleLeafColumns().length, filler);
|
|
2964
|
+
const fullWidthColSpan = cols.length;
|
|
2891
2965
|
const totalDisplayRowCount = topDisplayRows.length + centerDisplayRows.length + bottomDisplayRows.length;
|
|
2892
2966
|
const canCommitCell = Boolean(ledger?.onEditCommit);
|
|
2893
2967
|
const canCommitRow = Boolean(ledger?.onRowEditCommit);
|
|
@@ -2915,7 +2989,7 @@ function TableBody({ table, virtualization, columnWindow, viewportRef, loading,
|
|
|
2915
2989
|
...getStyles("tbody"),
|
|
2916
2990
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SkeletonRows, {
|
|
2917
2991
|
ariaRowIndexStart: virtualEnabled ? headerRowCount + 1 : void 0,
|
|
2918
|
-
|
|
2992
|
+
cols,
|
|
2919
2993
|
rowCount: skeletonRowCount
|
|
2920
2994
|
})
|
|
2921
2995
|
});
|
|
@@ -2968,6 +3042,7 @@ function TableBody({ table, virtualization, columnWindow, viewportRef, loading,
|
|
|
2968
3042
|
dropSide,
|
|
2969
3043
|
editingRow: editingRowId === row.id && (ledger?.editing.row.active(row.id) ?? false),
|
|
2970
3044
|
expanded: row.getIsExpanded(),
|
|
3045
|
+
filler,
|
|
2971
3046
|
last,
|
|
2972
3047
|
measureRef: options.measureRef,
|
|
2973
3048
|
pinKey,
|
|
@@ -3059,7 +3134,7 @@ function visibleFooterGroups(table) {
|
|
|
3059
3134
|
function tableHasFooter(table) {
|
|
3060
3135
|
return visibleFooterGroups(table).length > 0;
|
|
3061
3136
|
}
|
|
3062
|
-
function TableFooter({ table, ariaRowIndexStart, columnWindow }) {
|
|
3137
|
+
function TableFooter({ table, ariaRowIndexStart, columnWindow, filler }) {
|
|
3063
3138
|
const { getStyles, footerRowProps } = useDataTableContext();
|
|
3064
3139
|
const renderCell = (footer, colSpan, ariaColIndex) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Table.Td, {
|
|
3065
3140
|
...mergeElementProps(resolveElementProps(footer.column.columnDef.meta?.footerCellProps, footer), {
|
|
@@ -3082,42 +3157,85 @@ function TableFooter({ table, ariaRowIndexStart, columnWindow }) {
|
|
|
3082
3157
|
role: "row",
|
|
3083
3158
|
...getStyles("footerRow")
|
|
3084
3159
|
}),
|
|
3085
|
-
children: columnWindow === null ? footerGroup.headers.map((footer) =>
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3160
|
+
children: withFillerCell(columnWindow === null ? footerGroup.headers.map((footer) => {
|
|
3161
|
+
return {
|
|
3162
|
+
node: renderCell(footer, void 0, void 0),
|
|
3163
|
+
endZone: headerInEndZone(footer)
|
|
3164
|
+
};
|
|
3165
|
+
}) : windowHeaderCells(footerGroup.headers, columnWindow).map((cell) => cell.kind === "spacer" ? {
|
|
3166
|
+
node: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
3167
|
+
"aria-hidden": true,
|
|
3168
|
+
"data-ledger-spacer": true
|
|
3169
|
+
}, `ledger:spacer-${cell.edge}`),
|
|
3170
|
+
endZone: false
|
|
3171
|
+
} : {
|
|
3172
|
+
node: renderCell(cell.header, cell.colSpan, cell.ariaColIndex),
|
|
3173
|
+
endZone: headerInEndZone(cell.header)
|
|
3174
|
+
}), filler ? "td" : null)
|
|
3089
3175
|
}, footerGroup.id))
|
|
3090
3176
|
});
|
|
3091
3177
|
}
|
|
3092
3178
|
//#endregion
|
|
3093
|
-
//#region src/autosize
|
|
3179
|
+
//#region src/column-autosize.ts
|
|
3094
3180
|
/**
|
|
3095
|
-
*
|
|
3096
|
-
*
|
|
3097
|
-
*
|
|
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.
|
|
3181
|
+
* Fitting columns to their rendered content (docs/sizing.md#autosize) — one measurement behind
|
|
3182
|
+
* both of its uses: the resizer's double-click, which writes the fit as a `columnSizing` entry,
|
|
3183
|
+
* and `meta.autosize`, which keeps a column fitted as its content changes (`use-autosize-widths.ts`).
|
|
3100
3184
|
*
|
|
3101
|
-
*
|
|
3102
|
-
* the
|
|
3185
|
+
* What is measured is what the column has to hold: the header cell, every RENDERED body cell —
|
|
3186
|
+
* under virtualization that is the current window, the industry contract for autosize (unrendered
|
|
3187
|
+
* rows have no boxes to measure) — and the footer cell, which is rendered content like any other.
|
|
3188
|
+
* A cell that spans columns (a merged body cell, a footer total, a detail panel) says nothing about
|
|
3189
|
+
* the width of any one of them, and a cell holding an editor is as wide as the editor makes
|
|
3190
|
+
* itself, not as its value; neither is measured.
|
|
3103
3191
|
*
|
|
3104
3192
|
* A content cell is measured out of the table's layout: for the pass it is a block as wide as its
|
|
3105
3193
|
* content (`display: block; width: max-content`, no wrapping), so its width is the content's, in
|
|
3106
3194
|
* whichever direction that lies. Read in place, a cell is never narrower than its column — a fixed
|
|
3107
3195
|
* 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
|
|
3109
|
-
* costs one reflow, and each gets its own inline styles back
|
|
3196
|
+
* only ever widen a column. Every cell of every column is switched first and read afterwards, so a
|
|
3197
|
+
* pass costs one reflow however many columns it fits, and each cell gets its own inline styles back
|
|
3198
|
+
* before anything paints.
|
|
3110
3199
|
*/
|
|
3111
3200
|
/**
|
|
3112
3201
|
* Breathing room over the tightest fit — content flush against the column edge reads clipped.
|
|
3113
3202
|
*/
|
|
3114
3203
|
const AUTOSIZE_SLACK_PX = 8;
|
|
3115
3204
|
/**
|
|
3116
|
-
* Reserved for the hover-revealed header actions overlay (the filter button) so
|
|
3117
|
-
*
|
|
3205
|
+
* Reserved for the hover-revealed header actions overlay (the filter button) so a fit does not
|
|
3206
|
+
* park the drag line underneath it.
|
|
3118
3207
|
*/
|
|
3119
3208
|
const HEADER_ACTIONS_ALLOWANCE_PX = 28;
|
|
3120
3209
|
/**
|
|
3210
|
+
* Tukey's fence: a value past the third quartile by more than this many interquartile ranges is an
|
|
3211
|
+
* outlier. 1.5 is Tukey's own constant and MUI X's `outliersFactor` default.
|
|
3212
|
+
*/
|
|
3213
|
+
const OUTLIER_FACTOR = 1.5;
|
|
3214
|
+
/**
|
|
3215
|
+
* Linear interpolation between closest ranks (Hyndman–Fan type 7, the spreadsheet and NumPy
|
|
3216
|
+
* default) over ascending `sorted`.
|
|
3217
|
+
*/
|
|
3218
|
+
function quantile(sorted, p) {
|
|
3219
|
+
const rank = (sorted.length - 1) * p;
|
|
3220
|
+
const lower = Math.floor(rank);
|
|
3221
|
+
const below = sorted[lower];
|
|
3222
|
+
const above = sorted[Math.min(lower + 1, sorted.length - 1)];
|
|
3223
|
+
return below + (rank - lower) * (above - below);
|
|
3224
|
+
}
|
|
3225
|
+
/**
|
|
3226
|
+
* The widest of `values` within Tukey's upper fence (Q3 + 1.5 × IQR) — the width that holds every
|
|
3227
|
+
* value but the outliers. A set too uniform to have any (IQR 0) fences at its common value, so a
|
|
3228
|
+
* single long value among identical ones is still the outlier it reads as.
|
|
3229
|
+
*/
|
|
3230
|
+
function fencedMax(values) {
|
|
3231
|
+
if (values.length === 0) return 0;
|
|
3232
|
+
const sorted = values.toSorted((a, b) => a - b);
|
|
3233
|
+
const q1 = quantile(sorted, .25);
|
|
3234
|
+
const q3 = quantile(sorted, .75);
|
|
3235
|
+
const fence = q3 + OUTLIER_FACTOR * (q3 - q1);
|
|
3236
|
+
return sorted.findLast((value) => value <= fence) ?? sorted[0];
|
|
3237
|
+
}
|
|
3238
|
+
/**
|
|
3121
3239
|
* Computed lengths always resolve to `Npx`; strip the unit before coercing.
|
|
3122
3240
|
*/
|
|
3123
3241
|
function asPx(value) {
|
|
@@ -3134,12 +3252,27 @@ function headerCellWidth(th, hasFilter) {
|
|
|
3134
3252
|
const indicatorWidth = indicator ? indicator.offsetWidth + 6 : 0;
|
|
3135
3253
|
return labelText.scrollWidth + indicatorWidth + horizontalPadding(th) + (hasFilter ? HEADER_ACTIONS_ALLOWANCE_PX : 0);
|
|
3136
3254
|
}
|
|
3137
|
-
function
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3255
|
+
function contentCells(main, region, selector) {
|
|
3256
|
+
return [...main.querySelectorAll(`:scope ${region} ${selector}`)].filter((cell) => cell.colSpan <= 1 && !Object.hasOwn(cell.dataset, "editing"));
|
|
3257
|
+
}
|
|
3258
|
+
/**
|
|
3259
|
+
* The width each target's rendered content needs, slack included, in integer pixels — before the
|
|
3260
|
+
* column's own `minSize`/`maxSize`, which are the caller's to apply. A column with nothing rendered
|
|
3261
|
+
* (one a column window left out) has no entry.
|
|
3262
|
+
*/
|
|
3263
|
+
function measureColumnWidths(main, targets) {
|
|
3264
|
+
const columns = targets.map((target) => {
|
|
3265
|
+
const selector = `[data-ledger-column-id="${CSS.escape(target.columnId)}"]`;
|
|
3266
|
+
return {
|
|
3267
|
+
target,
|
|
3268
|
+
header: main.querySelector(`:scope .ledger-header ${selector}`),
|
|
3269
|
+
body: contentCells(main, ".ledger-tbody", selector),
|
|
3270
|
+
footer: contentCells(main, ".ledger-footer", selector)
|
|
3271
|
+
};
|
|
3272
|
+
});
|
|
3273
|
+
const headers = columns.map((column) => column.header).filter((header) => header !== null);
|
|
3274
|
+
const contents = columns.flatMap((column) => [...column.body, ...column.footer]);
|
|
3275
|
+
const cells = [...headers, ...contents];
|
|
3143
3276
|
const previous = cells.map((cell) => {
|
|
3144
3277
|
return {
|
|
3145
3278
|
display: cell.style.display,
|
|
@@ -3148,22 +3281,37 @@ function autosizeColumn(setColumnSizing, { columnId, minSize, maxSize, hasFilter
|
|
|
3148
3281
|
};
|
|
3149
3282
|
});
|
|
3150
3283
|
for (const cell of cells) cell.style.whiteSpace = "nowrap";
|
|
3151
|
-
for (const cell of
|
|
3284
|
+
for (const cell of contents) {
|
|
3152
3285
|
cell.style.display = "block";
|
|
3153
3286
|
cell.style.width = "max-content";
|
|
3154
3287
|
}
|
|
3155
|
-
|
|
3156
|
-
for (const
|
|
3288
|
+
const widths = /* @__PURE__ */ new Map();
|
|
3289
|
+
for (const { target, header, body, footer } of columns) {
|
|
3290
|
+
if (!header && body.length === 0 && footer.length === 0) continue;
|
|
3291
|
+
const bodyWidths = body.map((cell) => cell.scrollWidth);
|
|
3292
|
+
const content = Math.max(header ? headerCellWidth(header, target.hasFilter) : 0, ...footer.map((cell) => cell.scrollWidth), target.truncate ? fencedMax(bodyWidths) : Math.max(0, ...bodyWidths));
|
|
3293
|
+
widths.set(target.columnId, Math.round(content) + AUTOSIZE_SLACK_PX);
|
|
3294
|
+
}
|
|
3157
3295
|
for (const [index, cell] of cells.entries()) {
|
|
3158
3296
|
const styles = previous[index];
|
|
3159
3297
|
cell.style.display = styles?.display ?? "";
|
|
3160
3298
|
cell.style.whiteSpace = styles?.whiteSpace ?? "";
|
|
3161
3299
|
cell.style.width = styles?.width ?? "";
|
|
3162
3300
|
}
|
|
3163
|
-
|
|
3164
|
-
|
|
3301
|
+
return widths;
|
|
3302
|
+
}
|
|
3303
|
+
/**
|
|
3304
|
+
* The resizer's double-click: fit the column once and write the fit through `columnSizing`, clamped
|
|
3305
|
+
* like an interactive resize. The column, its constraints and whether it carries a filter all
|
|
3306
|
+
* arrive from the render that put the handle on screen, for the reason `use-column-resize.ts` gives.
|
|
3307
|
+
*/
|
|
3308
|
+
function autosizeColumn(setColumnSizing, { minSize, maxSize, ...target }, main) {
|
|
3309
|
+
const fitted = measureColumnWidths(main, [target]).get(target.columnId);
|
|
3310
|
+
if (fitted === void 0) return;
|
|
3311
|
+
const next = Math.min(Math.max(fitted, minSize), maxSize);
|
|
3312
|
+
setColumnSizing((previous) => previous[target.columnId] === next ? previous : {
|
|
3165
3313
|
...previous,
|
|
3166
|
-
[columnId]: next
|
|
3314
|
+
[target.columnId]: next
|
|
3167
3315
|
});
|
|
3168
3316
|
}
|
|
3169
3317
|
//#endregion
|
|
@@ -3629,7 +3777,7 @@ function useColumnResize(setColumnSizing) {
|
|
|
3629
3777
|
* which carries whatever render pass ran last — a discarded one included
|
|
3630
3778
|
* (docs/architecture.md).
|
|
3631
3779
|
*/
|
|
3632
|
-
function TableHeader({ table, columnWidths, columnSizing, columnWindow }) {
|
|
3780
|
+
function TableHeader({ table, columnWidths, columnSizing, columnWindow, filler }) {
|
|
3633
3781
|
const { getStyles, virtualizedRows, headerRowProps } = useDataTableContext();
|
|
3634
3782
|
const reorder = useColumnReorder(table);
|
|
3635
3783
|
const resize = useColumnResize(table.setColumnSizing);
|
|
@@ -3651,10 +3799,21 @@ function TableHeader({ table, columnWidths, columnSizing, columnWindow }) {
|
|
|
3651
3799
|
role: "row",
|
|
3652
3800
|
...getStyles("headerRow")
|
|
3653
3801
|
}),
|
|
3654
|
-
children: columnWindow === null ? headerGroup.headers.map((header) =>
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3802
|
+
children: withFillerCell(columnWindow === null ? headerGroup.headers.map((header) => {
|
|
3803
|
+
return {
|
|
3804
|
+
node: renderCell(header, void 0, void 0),
|
|
3805
|
+
endZone: headerInEndZone(header)
|
|
3806
|
+
};
|
|
3807
|
+
}) : windowHeaderCells(headerGroup.headers, columnWindow).map((cell) => cell.kind === "spacer" ? {
|
|
3808
|
+
node: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
|
|
3809
|
+
"aria-hidden": true,
|
|
3810
|
+
"data-ledger-spacer": true
|
|
3811
|
+
}, `ledger:spacer-${cell.edge}`),
|
|
3812
|
+
endZone: false
|
|
3813
|
+
} : {
|
|
3814
|
+
node: renderCell(cell.header, cell.colSpan, cell.ariaColIndex),
|
|
3815
|
+
endZone: headerInEndZone(cell.header)
|
|
3816
|
+
}), filler ? "th" : null)
|
|
3658
3817
|
}, headerGroup.id))
|
|
3659
3818
|
});
|
|
3660
3819
|
}
|
|
@@ -3775,7 +3934,8 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
|
|
|
3775
3934
|
const main = event.currentTarget.closest(".ledger-main");
|
|
3776
3935
|
if (main) autosizeColumn(table.setColumnSizing, {
|
|
3777
3936
|
...resizerSpec,
|
|
3778
|
-
hasFilter: meta?.filter !== void 0
|
|
3937
|
+
hasFilter: meta?.filter !== void 0,
|
|
3938
|
+
truncate: meta?.truncate === true
|
|
3779
3939
|
}, main);
|
|
3780
3940
|
},
|
|
3781
3941
|
...resize.getResizerProps(resizerSpec),
|
|
@@ -3786,6 +3946,160 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
|
|
|
3786
3946
|
});
|
|
3787
3947
|
}
|
|
3788
3948
|
//#endregion
|
|
3949
|
+
//#region src/use-autosize-widths.ts
|
|
3950
|
+
/**
|
|
3951
|
+
* `meta.autosize` (docs/sizing.md#autosize): keeps each such column fitted to its rendered content
|
|
3952
|
+
* and hands the width engine the fits, which rank between a user's resize and the author's `size`.
|
|
3953
|
+
*
|
|
3954
|
+
* When a fit is taken, and what it may do:
|
|
3955
|
+
* - **A new view refits.** Different rows (a new page, a filter, a sort — anything that changes the
|
|
3956
|
+
* row ids or their order), new column definitions (a renderer, a translated header) or another
|
|
3957
|
+
* set of visible columns, another density, or a web font that finished loading: the content is
|
|
3958
|
+
* new, so the widths follow it in both directions.
|
|
3959
|
+
* - **The same rows again only widen.** A refetch that hands back the same rows (a poll, an
|
|
3960
|
+
* edit) may make a cell wider, never a column narrower — otherwise a value that alternates
|
|
3961
|
+
* between short and long would shake the columns on every refresh.
|
|
3962
|
+
* - **Content that arrives with a window only widens, once the scrolling settles.** Under
|
|
3963
|
+
* virtualization the rows and columns scrolled into view were never measured; fitting them on
|
|
3964
|
+
* every window shift would reflow the table each step of a scroll, and narrowing would move the
|
|
3965
|
+
* columns under the reader.
|
|
3966
|
+
* - **A table with no layout waits for one.** In a hidden tab or a collapsed panel every cell
|
|
3967
|
+
* measures zero; the fit is taken when the table is first laid out instead.
|
|
3968
|
+
*
|
|
3969
|
+
* A fit is taken in a layout effect, before the browser paints, so a refit never shows the old
|
|
3970
|
+
* widths for a frame; a column a user resized is left to the user's width and not measured.
|
|
3971
|
+
*/
|
|
3972
|
+
/**
|
|
3973
|
+
* How long a scroll has to rest before the content it brought into view is fitted.
|
|
3974
|
+
*/
|
|
3975
|
+
const SCROLL_SETTLE_MS = 150;
|
|
3976
|
+
const NO_WIDTHS = {};
|
|
3977
|
+
function autosizeTargets(columns, columnSizing) {
|
|
3978
|
+
return columns.flatMap((column) => {
|
|
3979
|
+
const { meta } = column.columnDef;
|
|
3980
|
+
return meta?.autosize === true && !isInternalColumn(column.id) && columnSizing[column.id] === void 0 ? [{
|
|
3981
|
+
columnId: column.id,
|
|
3982
|
+
hasFilter: meta.filter !== void 0,
|
|
3983
|
+
truncate: meta.truncate === true
|
|
3984
|
+
}] : [];
|
|
3985
|
+
});
|
|
3986
|
+
}
|
|
3987
|
+
function sameIds(previous, next) {
|
|
3988
|
+
return previous.length === next.length && previous.every((id, index) => id === next[index]);
|
|
3989
|
+
}
|
|
3990
|
+
/**
|
|
3991
|
+
* The fits after a pass: a column measured takes its new width (in `widen` mode, only if wider), a
|
|
3992
|
+
* column with nothing rendered keeps the width it had, a column no longer fitted drops out.
|
|
3993
|
+
*/
|
|
3994
|
+
function mergeWidths(previous, measured, targets, mode) {
|
|
3995
|
+
const next = {};
|
|
3996
|
+
for (const { columnId } of targets) {
|
|
3997
|
+
const fresh = measured.get(columnId);
|
|
3998
|
+
const held = previous[columnId];
|
|
3999
|
+
const width = fresh === void 0 || held === void 0 ? fresh ?? held : mode === "widen" ? Math.max(held, fresh) : fresh;
|
|
4000
|
+
if (width !== void 0) next[columnId] = width;
|
|
4001
|
+
}
|
|
4002
|
+
const keys = Object.keys(next);
|
|
4003
|
+
return keys.length === Object.keys(previous).length && keys.every((key) => previous[key] === next[key]) ? previous : next;
|
|
4004
|
+
}
|
|
4005
|
+
/**
|
|
4006
|
+
* Bumps whenever web fonts finish loading: text measured in a fallback face is the wrong width.
|
|
4007
|
+
*/
|
|
4008
|
+
function useFontsVersion(enabled) {
|
|
4009
|
+
const [version, setVersion] = (0, react.useState)(0);
|
|
4010
|
+
(0, react.useEffect)(() => {
|
|
4011
|
+
if (!enabled || !("fonts" in document)) return;
|
|
4012
|
+
const bump = () => setVersion((previous) => previous + 1);
|
|
4013
|
+
document.fonts.addEventListener("loadingdone", bump);
|
|
4014
|
+
return () => document.fonts.removeEventListener("loadingdone", bump);
|
|
4015
|
+
}, [enabled]);
|
|
4016
|
+
return version;
|
|
4017
|
+
}
|
|
4018
|
+
function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appearance, virtualized }) {
|
|
4019
|
+
const targets = autosizeTargets(columns, columnSizing);
|
|
4020
|
+
const enabled = targets.length > 0;
|
|
4021
|
+
const fontsVersion = useFontsVersion(enabled);
|
|
4022
|
+
const signature = JSON.stringify([
|
|
4023
|
+
targets,
|
|
4024
|
+
appearance,
|
|
4025
|
+
fontsVersion
|
|
4026
|
+
]);
|
|
4027
|
+
const [widths, setWidths] = (0, react.useState)(NO_WIDTHS);
|
|
4028
|
+
const view = (0, react.useRef)(null);
|
|
4029
|
+
/**
|
|
4030
|
+
* A fit was due while the table had no layout.
|
|
4031
|
+
*/
|
|
4032
|
+
const awaitingLayout = (0, react.useRef)(false);
|
|
4033
|
+
const settleTimer = (0, react.useRef)(void 0);
|
|
4034
|
+
const fit = useEventCallback((mode) => {
|
|
4035
|
+
if (!main) return;
|
|
4036
|
+
if (main.getClientRects().length === 0) {
|
|
4037
|
+
awaitingLayout.current = true;
|
|
4038
|
+
return;
|
|
4039
|
+
}
|
|
4040
|
+
awaitingLayout.current = false;
|
|
4041
|
+
const measured = measureColumnWidths(main, targets);
|
|
4042
|
+
setWidths((previous) => mergeWidths(previous, measured, targets, mode));
|
|
4043
|
+
});
|
|
4044
|
+
const fitWhenSettled = (0, react.useCallback)(() => {
|
|
4045
|
+
clearTimeout(settleTimer.current);
|
|
4046
|
+
settleTimer.current = setTimeout(() => fit("widen"), SCROLL_SETTLE_MS);
|
|
4047
|
+
}, [fit]);
|
|
4048
|
+
(0, react.useEffect)(() => () => clearTimeout(settleTimer.current), []);
|
|
4049
|
+
(0, react.useLayoutEffect)(() => {
|
|
4050
|
+
if (!enabled) {
|
|
4051
|
+
view.current = null;
|
|
4052
|
+
setWidths(NO_WIDTHS);
|
|
4053
|
+
return;
|
|
4054
|
+
}
|
|
4055
|
+
const rowIds = rows.map((row) => row.id);
|
|
4056
|
+
const sameView = view.current !== null && view.current.columns === columns && view.current.signature === signature && sameIds(view.current.rowIds, rowIds);
|
|
4057
|
+
view.current = {
|
|
4058
|
+
columns,
|
|
4059
|
+
signature,
|
|
4060
|
+
rowIds
|
|
4061
|
+
};
|
|
4062
|
+
fit(sameView ? "widen" : "refit");
|
|
4063
|
+
}, [
|
|
4064
|
+
enabled,
|
|
4065
|
+
main,
|
|
4066
|
+
columns,
|
|
4067
|
+
rows,
|
|
4068
|
+
signature,
|
|
4069
|
+
fit
|
|
4070
|
+
]);
|
|
4071
|
+
(0, react.useEffect)(() => {
|
|
4072
|
+
if (enabled && virtualized && widths !== NO_WIDTHS) fitWhenSettled();
|
|
4073
|
+
}, [
|
|
4074
|
+
enabled,
|
|
4075
|
+
virtualized,
|
|
4076
|
+
widths,
|
|
4077
|
+
fitWhenSettled
|
|
4078
|
+
]);
|
|
4079
|
+
(0, react.useEffect)(() => {
|
|
4080
|
+
if (!enabled || !main) return;
|
|
4081
|
+
const observer = new ResizeObserver(() => {
|
|
4082
|
+
if (awaitingLayout.current) fit("refit");
|
|
4083
|
+
else if (virtualized) fitWhenSettled();
|
|
4084
|
+
});
|
|
4085
|
+
observer.observe(main);
|
|
4086
|
+
if (!virtualized || !viewport) return () => observer.disconnect();
|
|
4087
|
+
viewport.addEventListener("scroll", fitWhenSettled, { passive: true });
|
|
4088
|
+
return () => {
|
|
4089
|
+
observer.disconnect();
|
|
4090
|
+
viewport.removeEventListener("scroll", fitWhenSettled);
|
|
4091
|
+
};
|
|
4092
|
+
}, [
|
|
4093
|
+
enabled,
|
|
4094
|
+
main,
|
|
4095
|
+
viewport,
|
|
4096
|
+
virtualized,
|
|
4097
|
+
fit,
|
|
4098
|
+
fitWhenSettled
|
|
4099
|
+
]);
|
|
4100
|
+
return widths;
|
|
4101
|
+
}
|
|
4102
|
+
//#endregion
|
|
3789
4103
|
//#region src/use-column-widths.ts
|
|
3790
4104
|
/**
|
|
3791
4105
|
* The width engine (docs/sizing.md): every visible leaf column resolves to an exact integer
|
|
@@ -3793,14 +4107,17 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
|
|
|
3793
4107
|
* number system — the browser never redistributes anything.
|
|
3794
4108
|
*
|
|
3795
4109
|
* Rules, in order:
|
|
3796
|
-
* - a column with an explicit width (user-resized `columnSizing` entry, else
|
|
3797
|
-
* `size`, else `defaultColumn.size`) is fixed at
|
|
4110
|
+
* - a column with an explicit width (user-resized `columnSizing` entry, else its fitted content
|
|
4111
|
+
* width under `meta.autosize`, else the author's `size`, else `defaultColumn.size`) is fixed at
|
|
4112
|
+
* that width, clamped to its declared min/max;
|
|
3798
4113
|
* - a column without one is a grow column with basis `minSize ?? 80`; container surplus is
|
|
3799
4114
|
* distributed proportionally to the bases (integer floor, remainder in display order), capped
|
|
3800
4115
|
* by maxSize; when the container is too small every grow column falls back to its basis and the
|
|
3801
4116
|
* table overflows into horizontal scroll;
|
|
3802
4117
|
* - with no grow columns at all, surplus distributes proportionally over every column up to each
|
|
3803
|
-
* maxSize. Hard maximums win over filling the viewport
|
|
4118
|
+
* maxSize. Hard maximums win over filling the viewport: what no column may take is the filler,
|
|
4119
|
+
* an empty col between the scrolling columns and the end-pinned ones that every row carries a
|
|
4120
|
+
* cell of, so the table still spans the viewport (docs/sizing.md#the-filler).
|
|
3804
4121
|
*
|
|
3805
4122
|
* Author sizing comes from the raw-definition registry (`rawColumnSizing`), never from
|
|
3806
4123
|
* `column.columnDef` — TanStack merges `size: 150, minSize: 20` defaults into every resolved
|
|
@@ -3860,7 +4177,7 @@ function resolveColumnWidths(columns, columnSizing, availableWidth) {
|
|
|
3860
4177
|
const byId = {};
|
|
3861
4178
|
const growColumns = [];
|
|
3862
4179
|
for (const column of columns) {
|
|
3863
|
-
const sized = finiteNumber(columnSizing[column.id]) ?? finiteNumber(column.size);
|
|
4180
|
+
const sized = finiteNumber(columnSizing[column.id]) ?? finiteNumber(column.fit) ?? finiteNumber(column.size);
|
|
3864
4181
|
if (sized === void 0) {
|
|
3865
4182
|
const basis = clampWidth(column.minSize ?? DEFAULT_FLEX_BASIS, column.minSize, column.maxSize);
|
|
3866
4183
|
byId[column.id] = basis;
|
|
@@ -3872,7 +4189,8 @@ function resolveColumnWidths(columns, columnSizing, availableWidth) {
|
|
|
3872
4189
|
} else byId[column.id] = clampWidth(sized, column.minSize, column.maxSize);
|
|
3873
4190
|
}
|
|
3874
4191
|
const baseTotal = columns.reduce((total, column) => total + (byId[column.id] ?? 0), 0);
|
|
3875
|
-
const
|
|
4192
|
+
const targetWidth = Number.isFinite(availableWidth) ? Math.max(0, Math.round(availableWidth)) : 0;
|
|
4193
|
+
const surplus = targetWidth - baseTotal;
|
|
3876
4194
|
if (surplus > 0) distributeSurplus(byId, growColumns.length > 0 ? growColumns : columns.map((column) => {
|
|
3877
4195
|
return {
|
|
3878
4196
|
id: column.id,
|
|
@@ -3880,9 +4198,11 @@ function resolveColumnWidths(columns, columnSizing, availableWidth) {
|
|
|
3880
4198
|
max: normalizedBound(column.maxSize)
|
|
3881
4199
|
};
|
|
3882
4200
|
}), surplus);
|
|
4201
|
+
const total = columns.reduce((sum, column) => sum + (byId[column.id] ?? 0), 0);
|
|
3883
4202
|
return {
|
|
3884
4203
|
byId,
|
|
3885
|
-
total
|
|
4204
|
+
total,
|
|
4205
|
+
filler: Math.max(0, targetWidth - total)
|
|
3886
4206
|
};
|
|
3887
4207
|
}
|
|
3888
4208
|
/**
|
|
@@ -3896,7 +4216,7 @@ function minWidthPx(tableMinWidth, viewport) {
|
|
|
3896
4216
|
if (!tableElement) return Number.parseFloat(tableMinWidth) || 0;
|
|
3897
4217
|
return Number.parseFloat(getComputedStyle(tableElement).minWidth) || 0;
|
|
3898
4218
|
}
|
|
3899
|
-
function useColumnWidths(table, columns, viewport, tableMinWidth, injectedWidth) {
|
|
4219
|
+
function useColumnWidths(table, { columns, viewport, tableMinWidth, injectedWidth, autosizeWidths }) {
|
|
3900
4220
|
const [availableWidth, setAvailableWidth] = (0, react.useState)(0);
|
|
3901
4221
|
const measure = (0, react.useCallback)(() => {
|
|
3902
4222
|
if (!viewport) return;
|
|
@@ -3917,12 +4237,14 @@ function useColumnWidths(table, columns, viewport, tableMinWidth, injectedWidth)
|
|
|
3917
4237
|
const raw = rawColumnSizing(column.columnDef);
|
|
3918
4238
|
if (isInternalColumn(column.id)) return {
|
|
3919
4239
|
id: column.id,
|
|
4240
|
+
fit: void 0,
|
|
3920
4241
|
size: raw?.size ?? injectedWidth,
|
|
3921
4242
|
minSize: raw?.minSize ?? injectedWidth,
|
|
3922
4243
|
maxSize: raw?.maxSize ?? injectedWidth
|
|
3923
4244
|
};
|
|
3924
4245
|
return {
|
|
3925
4246
|
id: column.id,
|
|
4247
|
+
fit: autosizeWidths[column.id],
|
|
3926
4248
|
size: raw ? raw.size ?? defaultColumn?.size : column.columnDef.size,
|
|
3927
4249
|
minSize: raw ? raw.minSize ?? defaultColumn?.minSize : column.columnDef.minSize,
|
|
3928
4250
|
maxSize: raw ? raw.maxSize ?? defaultColumn?.maxSize : column.columnDef.maxSize
|
|
@@ -3933,9 +4255,14 @@ function useColumnWidths(table, columns, viewport, tableMinWidth, injectedWidth)
|
|
|
3933
4255
|
columnSizing,
|
|
3934
4256
|
availableWidth,
|
|
3935
4257
|
defaultColumn,
|
|
3936
|
-
injectedWidth
|
|
4258
|
+
injectedWidth,
|
|
4259
|
+
autosizeWidths
|
|
4260
|
+
]);
|
|
4261
|
+
const signature = JSON.stringify([
|
|
4262
|
+
resolved.total,
|
|
4263
|
+
resolved.filler,
|
|
4264
|
+
Object.entries(resolved.byId)
|
|
3937
4265
|
]);
|
|
3938
|
-
const signature = JSON.stringify([resolved.total, Object.entries(resolved.byId)]);
|
|
3939
4266
|
return (0, react.useMemo)(() => resolved, [signature]);
|
|
3940
4267
|
}
|
|
3941
4268
|
//#endregion
|
|
@@ -6841,6 +7168,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
6841
7168
|
setViewport(element);
|
|
6842
7169
|
}, []);
|
|
6843
7170
|
const viewportFit = useViewportFit(viewport);
|
|
7171
|
+
const [main, setMain] = (0, react.useState)(null);
|
|
6844
7172
|
const startLeafColumns = table.getStartVisibleLeafColumns();
|
|
6845
7173
|
const endLeafColumns = table.getEndVisibleLeafColumns();
|
|
6846
7174
|
const displayColumns = [
|
|
@@ -6855,7 +7183,21 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
6855
7183
|
const visibleLeafColumns = (0, react.useMemo)(() => displayColumns, [displayOrderSignature, ledgerColumns]);
|
|
6856
7184
|
const size = sizeProp ?? "sm";
|
|
6857
7185
|
const scale = SIZES[size];
|
|
6858
|
-
const columnWidths = useColumnWidths(table,
|
|
7186
|
+
const columnWidths = useColumnWidths(table, {
|
|
7187
|
+
autosizeWidths: useAutosizeWidths({
|
|
7188
|
+
appearance: size,
|
|
7189
|
+
columnSizing: table.state.columnSizing,
|
|
7190
|
+
columns: visibleLeafColumns,
|
|
7191
|
+
main,
|
|
7192
|
+
rows: table.getRowModel().rows,
|
|
7193
|
+
viewport,
|
|
7194
|
+
virtualized: Boolean(virtualizedRows) || Boolean(virtualizedColumns)
|
|
7195
|
+
}),
|
|
7196
|
+
columns: visibleLeafColumns,
|
|
7197
|
+
injectedWidth: scale.injectedWidth,
|
|
7198
|
+
tableMinWidth,
|
|
7199
|
+
viewport
|
|
7200
|
+
});
|
|
6859
7201
|
const virtualization = virtualizedRows ? {
|
|
6860
7202
|
estimateHeight: typeof virtualizedRows === "object" && virtualizedRows.estimateHeight !== void 0 ? virtualizedRows.estimateHeight : scale.rowHeight,
|
|
6861
7203
|
overscan: typeof virtualizedRows === "object" && virtualizedRows.overscan !== void 0 ? virtualizedRows.overscan : 8
|
|
@@ -6944,7 +7286,17 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
6944
7286
|
columnWidths,
|
|
6945
7287
|
tableState.columnPinning
|
|
6946
7288
|
]);
|
|
6947
|
-
const
|
|
7289
|
+
const filler = columnWidths.filler > 0;
|
|
7290
|
+
const fillerCol = filler && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("col", {
|
|
7291
|
+
"data-ledger-filler": true,
|
|
7292
|
+
style: { width: columnWidths.filler }
|
|
7293
|
+
}, "ledger:filler");
|
|
7294
|
+
const endCols = pinnedEndCount === 0 ? [] : visibleLeafColumns.slice(-pinnedEndCount).map((column) => leafCol(column));
|
|
7295
|
+
const colElements = columnWindow === null ? [
|
|
7296
|
+
...visibleLeafColumns.slice(0, visibleLeafColumns.length - pinnedEndCount).map((column) => leafCol(column)),
|
|
7297
|
+
fillerCol,
|
|
7298
|
+
...endCols
|
|
7299
|
+
] : [
|
|
6948
7300
|
...visibleLeafColumns.slice(0, pinnedStartCount).map((column) => leafCol(column)),
|
|
6949
7301
|
columnWindow.start > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("col", {
|
|
6950
7302
|
"data-ledger-spacer": true,
|
|
@@ -6955,7 +7307,8 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
6955
7307
|
"data-ledger-spacer": true,
|
|
6956
7308
|
style: { width: columnWindow.trailingSpace }
|
|
6957
7309
|
}, "ledger:spacer-trailing"),
|
|
6958
|
-
|
|
7310
|
+
fillerCol,
|
|
7311
|
+
...endCols
|
|
6959
7312
|
];
|
|
6960
7313
|
const rowsLength = table.getRowModel().rows.length;
|
|
6961
7314
|
const errorActive = Boolean(error) && !loading;
|
|
@@ -7300,8 +7653,9 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7300
7653
|
tabularNums,
|
|
7301
7654
|
verticalSpacing: verticalSpacing ?? scale.verticalSpacing
|
|
7302
7655
|
};
|
|
7656
|
+
const tableWidth = columnWidths.total + columnWidths.filler;
|
|
7303
7657
|
const tableStyleProps = () => getStyles("table", { style: {
|
|
7304
|
-
width:
|
|
7658
|
+
width: tableWidth > 0 ? tableWidth : void 0,
|
|
7305
7659
|
minWidth: toPx(tableMinWidth),
|
|
7306
7660
|
borderCollapse: "separate",
|
|
7307
7661
|
borderSpacing: 0,
|
|
@@ -7405,6 +7759,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7405
7759
|
children: labels.rowNavigation
|
|
7406
7760
|
})] }),
|
|
7407
7761
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
7762
|
+
ref: setMain,
|
|
7408
7763
|
"aria-busy": loading || void 0,
|
|
7409
7764
|
"aria-colcount": columnWindow === null ? void 0 : columnWindow.totalLeafCount,
|
|
7410
7765
|
"aria-describedby": ariaDescribedBy,
|
|
@@ -7424,6 +7779,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7424
7779
|
columnSizing: tableState.columnSizing,
|
|
7425
7780
|
columnWidths: columnWidths.byId,
|
|
7426
7781
|
columnWindow,
|
|
7782
|
+
filler,
|
|
7427
7783
|
table: erasedTable
|
|
7428
7784
|
})]
|
|
7429
7785
|
})
|
|
@@ -7455,6 +7811,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7455
7811
|
...tableStyleProps(),
|
|
7456
7812
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("colgroup", { children: colElements }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TableBody, {
|
|
7457
7813
|
columnWindow,
|
|
7814
|
+
filler,
|
|
7458
7815
|
loading: loading === true,
|
|
7459
7816
|
loadingMore: loadingMore === true,
|
|
7460
7817
|
loadMoreError: loadMoreError ?? false,
|
|
@@ -7536,6 +7893,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7536
7893
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("colgroup", { children: colElements }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TableFooter, {
|
|
7537
7894
|
ariaRowIndexStart: virtualEnabled ? footerAriaRowIndexStart : void 0,
|
|
7538
7895
|
columnWindow,
|
|
7896
|
+
filler,
|
|
7539
7897
|
table: erasedTable
|
|
7540
7898
|
})]
|
|
7541
7899
|
})
|