@coldsmirk/ledger-mantine 0.10.3 → 0.11.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 +71 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +71 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -867,6 +867,14 @@ declare module "@tanstack/react-table" {
|
|
|
867
867
|
* and leaves the outliers to the ellipsis.
|
|
868
868
|
*/
|
|
869
869
|
autosize?: boolean;
|
|
870
|
+
/**
|
|
871
|
+
* Never narrower than the column's header — its label, its sort mark, the room its filter
|
|
872
|
+
* button takes and its padding, measured as `autosize` measures a header and kept measured
|
|
873
|
+
* (docs/sizing.md#a-header-held-whole). The measured header raises the column's `minSize`;
|
|
874
|
+
* a user's resize still wins over it, and `maxSize` still caps it. Overrides the table's
|
|
875
|
+
* `columnMinSizeFromHeader` either way.
|
|
876
|
+
*/
|
|
877
|
+
minSizeFromHeader?: boolean;
|
|
870
878
|
/**
|
|
871
879
|
* Header filter UI: a variant shorthand, a config, or a fully custom renderer.
|
|
872
880
|
*/
|
|
@@ -1040,6 +1048,11 @@ interface DataTableBaseProps<TData extends RowData$1> extends BoxProps, StylesAp
|
|
|
1040
1048
|
horizontalSpacing?: MantineSpacing;
|
|
1041
1049
|
tabularNums?: boolean;
|
|
1042
1050
|
tableMinWidth?: number | string;
|
|
1051
|
+
/**
|
|
1052
|
+
* Holds every column at least as wide as its header unless its own `meta.minSizeFromHeader`
|
|
1053
|
+
* says otherwise (docs/sizing.md#a-header-held-whole).
|
|
1054
|
+
*/
|
|
1055
|
+
columnMinSizeFromHeader?: boolean;
|
|
1043
1056
|
/**
|
|
1044
1057
|
* Row virtualization ([virtualization.md](../docs/virtualization.md)): the body renders a
|
|
1045
1058
|
* measured window of rows between two spacer rows.
|
package/dist/index.d.ts
CHANGED
|
@@ -867,6 +867,14 @@ declare module "@tanstack/react-table" {
|
|
|
867
867
|
* and leaves the outliers to the ellipsis.
|
|
868
868
|
*/
|
|
869
869
|
autosize?: boolean;
|
|
870
|
+
/**
|
|
871
|
+
* Never narrower than the column's header — its label, its sort mark, the room its filter
|
|
872
|
+
* button takes and its padding, measured as `autosize` measures a header and kept measured
|
|
873
|
+
* (docs/sizing.md#a-header-held-whole). The measured header raises the column's `minSize`;
|
|
874
|
+
* a user's resize still wins over it, and `maxSize` still caps it. Overrides the table's
|
|
875
|
+
* `columnMinSizeFromHeader` either way.
|
|
876
|
+
*/
|
|
877
|
+
minSizeFromHeader?: boolean;
|
|
870
878
|
/**
|
|
871
879
|
* Header filter UI: a variant shorthand, a config, or a fully custom renderer.
|
|
872
880
|
*/
|
|
@@ -1040,6 +1048,11 @@ interface DataTableBaseProps<TData extends RowData$1> extends BoxProps, StylesAp
|
|
|
1040
1048
|
horizontalSpacing?: MantineSpacing;
|
|
1041
1049
|
tabularNums?: boolean;
|
|
1042
1050
|
tableMinWidth?: number | string;
|
|
1051
|
+
/**
|
|
1052
|
+
* Holds every column at least as wide as its header unless its own `meta.minSizeFromHeader`
|
|
1053
|
+
* says otherwise (docs/sizing.md#a-header-held-whole).
|
|
1054
|
+
*/
|
|
1055
|
+
columnMinSizeFromHeader?: boolean;
|
|
1043
1056
|
/**
|
|
1044
1057
|
* Row virtualization ([virtualization.md](../docs/virtualization.md)): the body renders a
|
|
1045
1058
|
* measured window of rows between two spacer rows.
|
package/dist/index.js
CHANGED
|
@@ -3161,8 +3161,10 @@ function TableFooter({ table, ariaRowIndexStart, columnWindow, filler }) {
|
|
|
3161
3161
|
//#region src/column-autosize.ts
|
|
3162
3162
|
/**
|
|
3163
3163
|
* Fitting columns to their rendered content (docs/sizing.md#autosize) — one measurement behind
|
|
3164
|
-
*
|
|
3165
|
-
*
|
|
3164
|
+
* each of its uses: the resizer's double-click, which writes the fit as a `columnSizing` entry,
|
|
3165
|
+
* `meta.autosize`, which keeps a column fitted as its content changes, and
|
|
3166
|
+
* `meta.minSizeFromHeader`, which keeps a column at least as wide as its header
|
|
3167
|
+
* (`use-autosize-widths.ts`).
|
|
3166
3168
|
*
|
|
3167
3169
|
* What is measured is what the column has to hold: the header cell, every RENDERED body cell —
|
|
3168
3170
|
* under virtualization that is the current window, the industry contract for autosize (unrendered
|
|
@@ -3238,18 +3240,19 @@ function contentCells(main, region, selector) {
|
|
|
3238
3240
|
return [...main.querySelectorAll(`:scope ${region} ${selector}`)].filter((cell) => cell.colSpan <= 1 && !Object.hasOwn(cell.dataset, "editing"));
|
|
3239
3241
|
}
|
|
3240
3242
|
/**
|
|
3241
|
-
* The width each target's rendered
|
|
3243
|
+
* The width each target's rendered extent needs, slack included, in integer pixels — before the
|
|
3242
3244
|
* column's own `minSize`/`maxSize`, which are the caller's to apply. A column with nothing rendered
|
|
3243
3245
|
* (one a column window left out) has no entry.
|
|
3244
3246
|
*/
|
|
3245
3247
|
function measureColumnWidths(main, targets) {
|
|
3246
3248
|
const columns = targets.map((target) => {
|
|
3247
3249
|
const selector = `[data-ledger-column-id="${CSS.escape(target.columnId)}"]`;
|
|
3250
|
+
const withContent = target.extent === "content";
|
|
3248
3251
|
return {
|
|
3249
3252
|
target,
|
|
3250
3253
|
header: main.querySelector(`:scope .ledger-header ${selector}`),
|
|
3251
|
-
body: contentCells(main, ".ledger-tbody", selector),
|
|
3252
|
-
footer: contentCells(main, ".ledger-footer", selector)
|
|
3254
|
+
body: withContent ? contentCells(main, ".ledger-tbody", selector) : [],
|
|
3255
|
+
footer: withContent ? contentCells(main, ".ledger-footer", selector) : []
|
|
3253
3256
|
};
|
|
3254
3257
|
});
|
|
3255
3258
|
const headers = columns.map((column) => column.header).filter((header) => header !== null);
|
|
@@ -3288,7 +3291,10 @@ function measureColumnWidths(main, targets) {
|
|
|
3288
3291
|
* arrive from the render that put the handle on screen, for the reason `use-column-resize.ts` gives.
|
|
3289
3292
|
*/
|
|
3290
3293
|
function autosizeColumn(setColumnSizing, { minSize, maxSize, ...target }, main) {
|
|
3291
|
-
const fitted = measureColumnWidths(main, [
|
|
3294
|
+
const fitted = measureColumnWidths(main, [{
|
|
3295
|
+
...target,
|
|
3296
|
+
extent: "content"
|
|
3297
|
+
}]).get(target.columnId);
|
|
3292
3298
|
if (fitted === void 0) return;
|
|
3293
3299
|
const next = Math.min(Math.max(fitted, minSize), maxSize);
|
|
3294
3300
|
setColumnSizing((previous) => previous[target.columnId] === next ? previous : {
|
|
@@ -3930,8 +3936,13 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
|
|
|
3930
3936
|
//#endregion
|
|
3931
3937
|
//#region src/use-autosize-widths.ts
|
|
3932
3938
|
/**
|
|
3933
|
-
*
|
|
3934
|
-
*
|
|
3939
|
+
* The widths ledger measures and keeps measured (docs/sizing.md#autosize), for the width engine:
|
|
3940
|
+
* - **fits** — `meta.autosize`: each such column fitted to its rendered content, a width that
|
|
3941
|
+
* ranks between a user's resize and the author's `size`;
|
|
3942
|
+
* - **header widths** — `meta.minSizeFromHeader`, or the table's `columnMinSizeFromHeader`: each
|
|
3943
|
+
* such column's header measured whole, a floor under the column's width
|
|
3944
|
+
* (docs/sizing.md#a-header-held-whole). A column fitted by `autosize` holds its header already
|
|
3945
|
+
* and is not measured twice.
|
|
3935
3946
|
*
|
|
3936
3947
|
* When a fit is taken, and what it may do:
|
|
3937
3948
|
* - **A new view refits.** Different rows (a new page, a filter, a sort — anything that changes the
|
|
@@ -3956,16 +3967,38 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
|
|
|
3956
3967
|
*/
|
|
3957
3968
|
const SCROLL_SETTLE_MS = 150;
|
|
3958
3969
|
const NO_WIDTHS = {};
|
|
3959
|
-
|
|
3970
|
+
/**
|
|
3971
|
+
* What each column has measured: its content under `meta.autosize`, else its header where it asks
|
|
3972
|
+
* never to be narrower than it — nothing for an injected column or one a user resized.
|
|
3973
|
+
*/
|
|
3974
|
+
function autosizeTargets(columns, columnSizing, minSizeFromHeader) {
|
|
3960
3975
|
return columns.flatMap((column) => {
|
|
3961
3976
|
const { meta } = column.columnDef;
|
|
3962
|
-
|
|
3977
|
+
if (isInternalColumn(column.id) || columnSizing[column.id] !== void 0) return [];
|
|
3978
|
+
const extent = meta?.autosize === true ? "content" : meta?.minSizeFromHeader ?? minSizeFromHeader ? "header" : void 0;
|
|
3979
|
+
return extent === void 0 ? [] : [{
|
|
3963
3980
|
columnId: column.id,
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3981
|
+
extent,
|
|
3982
|
+
hasFilter: meta?.filter !== void 0,
|
|
3983
|
+
truncate: meta?.truncate === true
|
|
3984
|
+
}];
|
|
3967
3985
|
});
|
|
3968
3986
|
}
|
|
3987
|
+
/**
|
|
3988
|
+
* The measured widths, told apart by what each target measured.
|
|
3989
|
+
*/
|
|
3990
|
+
function byExtent(widths, targets) {
|
|
3991
|
+
const fits = {};
|
|
3992
|
+
const headerWidths = {};
|
|
3993
|
+
for (const { columnId, extent } of targets) {
|
|
3994
|
+
const width = widths[columnId];
|
|
3995
|
+
if (width !== void 0) (extent === "content" ? fits : headerWidths)[columnId] = width;
|
|
3996
|
+
}
|
|
3997
|
+
return {
|
|
3998
|
+
fits,
|
|
3999
|
+
headerWidths
|
|
4000
|
+
};
|
|
4001
|
+
}
|
|
3969
4002
|
function sameIds(previous, next) {
|
|
3970
4003
|
return previous.length === next.length && previous.every((id, index) => id === next[index]);
|
|
3971
4004
|
}
|
|
@@ -3997,8 +4030,8 @@ function useFontsVersion(enabled) {
|
|
|
3997
4030
|
}, [enabled]);
|
|
3998
4031
|
return version;
|
|
3999
4032
|
}
|
|
4000
|
-
function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appearance, virtualized }) {
|
|
4001
|
-
const targets = autosizeTargets(columns, columnSizing);
|
|
4033
|
+
function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appearance, virtualized, minSizeFromHeader }) {
|
|
4034
|
+
const targets = autosizeTargets(columns, columnSizing, minSizeFromHeader);
|
|
4002
4035
|
const enabled = targets.length > 0;
|
|
4003
4036
|
const fontsVersion = useFontsVersion(enabled);
|
|
4004
4037
|
const signature = JSON.stringify([
|
|
@@ -4079,7 +4112,7 @@ function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appear
|
|
|
4079
4112
|
fit,
|
|
4080
4113
|
fitWhenSettled
|
|
4081
4114
|
]);
|
|
4082
|
-
return widths;
|
|
4115
|
+
return useMemo(() => byExtent(widths, targets), [widths, signature]);
|
|
4083
4116
|
}
|
|
4084
4117
|
//#endregion
|
|
4085
4118
|
//#region src/use-column-widths.ts
|
|
@@ -4089,9 +4122,12 @@ function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appear
|
|
|
4089
4122
|
* number system — the browser never redistributes anything.
|
|
4090
4123
|
*
|
|
4091
4124
|
* Rules, in order:
|
|
4125
|
+
* - a column's minimum is its declared `minSize`, raised to its measured header where it asks
|
|
4126
|
+
* never to be narrower than it (`meta.minSizeFromHeader`) — except under a user's resize, which
|
|
4127
|
+
* the declared bounds alone clamp;
|
|
4092
4128
|
* - a column with an explicit width (user-resized `columnSizing` entry, else its fitted content
|
|
4093
4129
|
* width under `meta.autosize`, else the author's `size`, else `defaultColumn.size`) is fixed at
|
|
4094
|
-
* that width, clamped to its declared
|
|
4130
|
+
* that width, clamped to its minimum and its declared max;
|
|
4095
4131
|
* - a column without one is a grow column with basis `minSize ?? 80`; container surplus is
|
|
4096
4132
|
* distributed proportionally to the bases (integer floor, remainder in display order), capped
|
|
4097
4133
|
* by maxSize; when the container is too small every grow column falls back to its basis and the
|
|
@@ -4120,6 +4156,13 @@ function clampWidth(value, min, max) {
|
|
|
4120
4156
|
return Math.min(Math.max(Number.isFinite(value) ? Math.max(0, Math.round(value)) : 0, normalizedBound(min) ?? 0), normalizedBound(max) ?? Number.MAX_SAFE_INTEGER);
|
|
4121
4157
|
}
|
|
4122
4158
|
/**
|
|
4159
|
+
* The column's declared `minSize`, raised to its measured header where it has one.
|
|
4160
|
+
*/
|
|
4161
|
+
function headerMinSize(column) {
|
|
4162
|
+
const headerWidth = finiteNumber(column.headerWidth);
|
|
4163
|
+
return headerWidth === void 0 ? column.minSize : Math.max(headerWidth, finiteNumber(column.minSize) ?? 0);
|
|
4164
|
+
}
|
|
4165
|
+
/**
|
|
4123
4166
|
* Weighted water-filling over integer pixels. Columns that hit maxSize leave the active set and
|
|
4124
4167
|
* the remaining space is redistributed over columns that can still grow. If every column reaches
|
|
4125
4168
|
* its cap, maxSize wins and the table intentionally stops short of the viewport.
|
|
@@ -4159,16 +4202,18 @@ function resolveColumnWidths(columns, columnSizing, availableWidth) {
|
|
|
4159
4202
|
const byId = {};
|
|
4160
4203
|
const growColumns = [];
|
|
4161
4204
|
for (const column of columns) {
|
|
4162
|
-
const
|
|
4205
|
+
const resized = finiteNumber(columnSizing[column.id]);
|
|
4206
|
+
const sized = resized ?? finiteNumber(column.fit) ?? finiteNumber(column.size);
|
|
4207
|
+
const minSize = resized === void 0 ? headerMinSize(column) : column.minSize;
|
|
4163
4208
|
if (sized === void 0) {
|
|
4164
|
-
const basis = clampWidth(column.minSize ?? DEFAULT_FLEX_BASIS,
|
|
4209
|
+
const basis = clampWidth(column.minSize ?? DEFAULT_FLEX_BASIS, minSize, column.maxSize);
|
|
4165
4210
|
byId[column.id] = basis;
|
|
4166
4211
|
growColumns.push({
|
|
4167
4212
|
id: column.id,
|
|
4168
4213
|
weight: basis,
|
|
4169
4214
|
max: normalizedBound(column.maxSize)
|
|
4170
4215
|
});
|
|
4171
|
-
} else byId[column.id] = clampWidth(sized,
|
|
4216
|
+
} else byId[column.id] = clampWidth(sized, minSize, column.maxSize);
|
|
4172
4217
|
}
|
|
4173
4218
|
const baseTotal = columns.reduce((total, column) => total + (byId[column.id] ?? 0), 0);
|
|
4174
4219
|
const targetWidth = Number.isFinite(availableWidth) ? Math.max(0, Math.round(availableWidth)) : 0;
|
|
@@ -4227,13 +4272,15 @@ function useColumnWidths(table, { columns, viewport, tableMinWidth, injectedWidt
|
|
|
4227
4272
|
if (isInternalColumn(column.id)) return {
|
|
4228
4273
|
id: column.id,
|
|
4229
4274
|
fit: void 0,
|
|
4275
|
+
headerWidth: void 0,
|
|
4230
4276
|
size: raw?.size ?? injectedWidth,
|
|
4231
4277
|
minSize: raw?.minSize ?? injectedWidth,
|
|
4232
4278
|
maxSize: raw?.maxSize ?? injectedWidth
|
|
4233
4279
|
};
|
|
4234
4280
|
return {
|
|
4235
4281
|
id: column.id,
|
|
4236
|
-
fit: autosizeWidths[column.id],
|
|
4282
|
+
fit: autosizeWidths.fits[column.id],
|
|
4283
|
+
headerWidth: autosizeWidths.headerWidths[column.id],
|
|
4237
4284
|
size: raw ? raw.size ?? defaultColumn?.size : column.columnDef.size,
|
|
4238
4285
|
minSize: raw ? raw.minSize ?? defaultColumn?.minSize : column.columnDef.minSize,
|
|
4239
4286
|
maxSize: raw ? raw.maxSize ?? defaultColumn?.maxSize : column.columnDef.maxSize
|
|
@@ -6982,6 +7029,7 @@ const defaultProps = {
|
|
|
6982
7029
|
withBottomBorder: false,
|
|
6983
7030
|
size: "sm",
|
|
6984
7031
|
tabularNums: false,
|
|
7032
|
+
columnMinSizeFromHeader: false,
|
|
6985
7033
|
virtualizedRows: false,
|
|
6986
7034
|
virtualizedColumns: false,
|
|
6987
7035
|
endReachedOffset: 240,
|
|
@@ -7121,7 +7169,7 @@ function DataTableFromOptions({ props }) {
|
|
|
7121
7169
|
});
|
|
7122
7170
|
}
|
|
7123
7171
|
function DataTableCore({ presentation, stylesProps, table }) {
|
|
7124
|
-
const { striped, stripedColor: _stripedColor, highlightOnHover, highlightOnHoverColor: _highlightOnHoverColor, withTableBorder, withColumnBorders, withRowBorders, withBottomBorder, borderColor: _borderColor, radius: _radius, size: sizeProp, verticalSpacing, horizontalSpacing, tabularNums, tableMinWidth, virtualizedRows, virtualizedColumns, onEndReached, endReachedOffset, loadingMore, loadMoreError, loading, emptyState, error, onRetry, withColumnHeaders, withPaginationBar, pageSizeOptions, onRowClick, onRowActivate, onRowDoubleClick, onRowContextMenu, rowProps, headerRowProps, footerRowProps, viewportProps, labels: labelsProp, icons: iconsProp, handleRef, ref: rootRef, classNames, styles, unstyled, vars, className, style, attributes, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...others } = presentation;
|
|
7172
|
+
const { striped, stripedColor: _stripedColor, highlightOnHover, highlightOnHoverColor: _highlightOnHoverColor, withTableBorder, withColumnBorders, withRowBorders, withBottomBorder, borderColor: _borderColor, radius: _radius, size: sizeProp, verticalSpacing, horizontalSpacing, tabularNums, tableMinWidth, columnMinSizeFromHeader, virtualizedRows, virtualizedColumns, onEndReached, endReachedOffset, loadingMore, loadMoreError, loading, emptyState, error, onRetry, withColumnHeaders, withPaginationBar, pageSizeOptions, onRowClick, onRowActivate, onRowDoubleClick, onRowContextMenu, rowProps, headerRowProps, footerRowProps, viewportProps, labels: labelsProp, icons: iconsProp, handleRef, ref: rootRef, classNames, styles, unstyled, vars, className, style, attributes, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...others } = presentation;
|
|
7125
7173
|
const getStyles = useStyles({
|
|
7126
7174
|
name: "DataTable",
|
|
7127
7175
|
classes,
|
|
@@ -7184,6 +7232,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7184
7232
|
columnSizing: table.state.columnSizing,
|
|
7185
7233
|
columns: visibleLeafColumns,
|
|
7186
7234
|
main,
|
|
7235
|
+
minSizeFromHeader: columnMinSizeFromHeader === true,
|
|
7187
7236
|
rows: table.getRowModel().rows,
|
|
7188
7237
|
viewport,
|
|
7189
7238
|
virtualized: Boolean(virtualizedRows) || Boolean(virtualizedColumns)
|