@coldsmirk/ledger-mantine 0.10.2 → 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.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
@@ -2815,7 +2815,10 @@ function DetailRow({ row, renderDetailPanel, colSpan, dragging, dropSide, last,
2815
2815
  colSpan,
2816
2816
  role: "cell",
2817
2817
  ...getStyles("detailPanel"),
2818
- children: renderDetailPanel?.(row)
2818
+ children: /* @__PURE__ */ jsx("div", {
2819
+ "data-detail-content": true,
2820
+ children: renderDetailPanel?.(row)
2821
+ })
2819
2822
  })
2820
2823
  });
2821
2824
  }
@@ -3158,8 +3161,10 @@ function TableFooter({ table, ariaRowIndexStart, columnWindow, filler }) {
3158
3161
  //#region src/column-autosize.ts
3159
3162
  /**
3160
3163
  * Fitting columns to their rendered content (docs/sizing.md#autosize) — one measurement behind
3161
- * both of its uses: the resizer's double-click, which writes the fit as a `columnSizing` entry,
3162
- * and `meta.autosize`, which keeps a column fitted as its content changes (`use-autosize-widths.ts`).
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`).
3163
3168
  *
3164
3169
  * What is measured is what the column has to hold: the header cell, every RENDERED body cell —
3165
3170
  * under virtualization that is the current window, the industry contract for autosize (unrendered
@@ -3235,18 +3240,19 @@ function contentCells(main, region, selector) {
3235
3240
  return [...main.querySelectorAll(`:scope ${region} ${selector}`)].filter((cell) => cell.colSpan <= 1 && !Object.hasOwn(cell.dataset, "editing"));
3236
3241
  }
3237
3242
  /**
3238
- * The width each target's rendered content needs, slack included, in integer pixels — before the
3243
+ * The width each target's rendered extent needs, slack included, in integer pixels — before the
3239
3244
  * column's own `minSize`/`maxSize`, which are the caller's to apply. A column with nothing rendered
3240
3245
  * (one a column window left out) has no entry.
3241
3246
  */
3242
3247
  function measureColumnWidths(main, targets) {
3243
3248
  const columns = targets.map((target) => {
3244
3249
  const selector = `[data-ledger-column-id="${CSS.escape(target.columnId)}"]`;
3250
+ const withContent = target.extent === "content";
3245
3251
  return {
3246
3252
  target,
3247
3253
  header: main.querySelector(`:scope .ledger-header ${selector}`),
3248
- body: contentCells(main, ".ledger-tbody", selector),
3249
- footer: contentCells(main, ".ledger-footer", selector)
3254
+ body: withContent ? contentCells(main, ".ledger-tbody", selector) : [],
3255
+ footer: withContent ? contentCells(main, ".ledger-footer", selector) : []
3250
3256
  };
3251
3257
  });
3252
3258
  const headers = columns.map((column) => column.header).filter((header) => header !== null);
@@ -3285,7 +3291,10 @@ function measureColumnWidths(main, targets) {
3285
3291
  * arrive from the render that put the handle on screen, for the reason `use-column-resize.ts` gives.
3286
3292
  */
3287
3293
  function autosizeColumn(setColumnSizing, { minSize, maxSize, ...target }, main) {
3288
- const fitted = measureColumnWidths(main, [target]).get(target.columnId);
3294
+ const fitted = measureColumnWidths(main, [{
3295
+ ...target,
3296
+ extent: "content"
3297
+ }]).get(target.columnId);
3289
3298
  if (fitted === void 0) return;
3290
3299
  const next = Math.min(Math.max(fitted, minSize), maxSize);
3291
3300
  setColumnSizing((previous) => previous[target.columnId] === next ? previous : {
@@ -3927,8 +3936,13 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
3927
3936
  //#endregion
3928
3937
  //#region src/use-autosize-widths.ts
3929
3938
  /**
3930
- * `meta.autosize` (docs/sizing.md#autosize): keeps each such column fitted to its rendered content
3931
- * and hands the width engine the fits, which rank between a user's resize and the author's `size`.
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.
3932
3946
  *
3933
3947
  * When a fit is taken, and what it may do:
3934
3948
  * - **A new view refits.** Different rows (a new page, a filter, a sort — anything that changes the
@@ -3953,16 +3967,38 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
3953
3967
  */
3954
3968
  const SCROLL_SETTLE_MS = 150;
3955
3969
  const NO_WIDTHS = {};
3956
- function autosizeTargets(columns, columnSizing) {
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) {
3957
3975
  return columns.flatMap((column) => {
3958
3976
  const { meta } = column.columnDef;
3959
- return meta?.autosize === true && !isInternalColumn(column.id) && columnSizing[column.id] === void 0 ? [{
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 ? [] : [{
3960
3980
  columnId: column.id,
3961
- hasFilter: meta.filter !== void 0,
3962
- truncate: meta.truncate === true
3963
- }] : [];
3981
+ extent,
3982
+ hasFilter: meta?.filter !== void 0,
3983
+ truncate: meta?.truncate === true
3984
+ }];
3964
3985
  });
3965
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
+ }
3966
4002
  function sameIds(previous, next) {
3967
4003
  return previous.length === next.length && previous.every((id, index) => id === next[index]);
3968
4004
  }
@@ -3994,8 +4030,8 @@ function useFontsVersion(enabled) {
3994
4030
  }, [enabled]);
3995
4031
  return version;
3996
4032
  }
3997
- function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appearance, virtualized }) {
3998
- const targets = autosizeTargets(columns, columnSizing);
4033
+ function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appearance, virtualized, minSizeFromHeader }) {
4034
+ const targets = autosizeTargets(columns, columnSizing, minSizeFromHeader);
3999
4035
  const enabled = targets.length > 0;
4000
4036
  const fontsVersion = useFontsVersion(enabled);
4001
4037
  const signature = JSON.stringify([
@@ -4076,7 +4112,7 @@ function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appear
4076
4112
  fit,
4077
4113
  fitWhenSettled
4078
4114
  ]);
4079
- return widths;
4115
+ return useMemo(() => byExtent(widths, targets), [widths, signature]);
4080
4116
  }
4081
4117
  //#endregion
4082
4118
  //#region src/use-column-widths.ts
@@ -4086,9 +4122,12 @@ function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appear
4086
4122
  * number system — the browser never redistributes anything.
4087
4123
  *
4088
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;
4089
4128
  * - a column with an explicit width (user-resized `columnSizing` entry, else its fitted content
4090
4129
  * width under `meta.autosize`, else the author's `size`, else `defaultColumn.size`) is fixed at
4091
- * that width, clamped to its declared min/max;
4130
+ * that width, clamped to its minimum and its declared max;
4092
4131
  * - a column without one is a grow column with basis `minSize ?? 80`; container surplus is
4093
4132
  * distributed proportionally to the bases (integer floor, remainder in display order), capped
4094
4133
  * by maxSize; when the container is too small every grow column falls back to its basis and the
@@ -4117,6 +4156,13 @@ function clampWidth(value, min, max) {
4117
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);
4118
4157
  }
4119
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
+ /**
4120
4166
  * Weighted water-filling over integer pixels. Columns that hit maxSize leave the active set and
4121
4167
  * the remaining space is redistributed over columns that can still grow. If every column reaches
4122
4168
  * its cap, maxSize wins and the table intentionally stops short of the viewport.
@@ -4156,16 +4202,18 @@ function resolveColumnWidths(columns, columnSizing, availableWidth) {
4156
4202
  const byId = {};
4157
4203
  const growColumns = [];
4158
4204
  for (const column of columns) {
4159
- const sized = finiteNumber(columnSizing[column.id]) ?? finiteNumber(column.fit) ?? finiteNumber(column.size);
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;
4160
4208
  if (sized === void 0) {
4161
- const basis = clampWidth(column.minSize ?? DEFAULT_FLEX_BASIS, column.minSize, column.maxSize);
4209
+ const basis = clampWidth(column.minSize ?? DEFAULT_FLEX_BASIS, minSize, column.maxSize);
4162
4210
  byId[column.id] = basis;
4163
4211
  growColumns.push({
4164
4212
  id: column.id,
4165
4213
  weight: basis,
4166
4214
  max: normalizedBound(column.maxSize)
4167
4215
  });
4168
- } else byId[column.id] = clampWidth(sized, column.minSize, column.maxSize);
4216
+ } else byId[column.id] = clampWidth(sized, minSize, column.maxSize);
4169
4217
  }
4170
4218
  const baseTotal = columns.reduce((total, column) => total + (byId[column.id] ?? 0), 0);
4171
4219
  const targetWidth = Number.isFinite(availableWidth) ? Math.max(0, Math.round(availableWidth)) : 0;
@@ -4196,11 +4244,18 @@ function minWidthPx(tableMinWidth, viewport) {
4196
4244
  return Number.parseFloat(getComputedStyle(tableElement).minWidth) || 0;
4197
4245
  }
4198
4246
  function useColumnWidths(table, { columns, viewport, tableMinWidth, injectedWidth, autosizeWidths }) {
4199
- const [availableWidth, setAvailableWidth] = useState(0);
4247
+ const [widths, setWidths] = useState({
4248
+ available: 0,
4249
+ viewport: 0
4250
+ });
4200
4251
  const measure = useCallback(() => {
4201
4252
  if (!viewport) return;
4202
- const next = Math.max(viewport.clientWidth, minWidthPx(tableMinWidth, viewport));
4203
- setAvailableWidth((previous) => previous === next ? previous : next);
4253
+ const inner = Math.max(0, Math.round(viewport.clientWidth));
4254
+ const available = Math.max(inner, minWidthPx(tableMinWidth, viewport));
4255
+ setWidths((previous) => previous.available === available && previous.viewport === inner ? previous : {
4256
+ available,
4257
+ viewport: inner
4258
+ });
4204
4259
  }, [viewport, tableMinWidth]);
4205
4260
  useLayoutEffect(() => {
4206
4261
  measure();
@@ -4217,22 +4272,24 @@ function useColumnWidths(table, { columns, viewport, tableMinWidth, injectedWidt
4217
4272
  if (isInternalColumn(column.id)) return {
4218
4273
  id: column.id,
4219
4274
  fit: void 0,
4275
+ headerWidth: void 0,
4220
4276
  size: raw?.size ?? injectedWidth,
4221
4277
  minSize: raw?.minSize ?? injectedWidth,
4222
4278
  maxSize: raw?.maxSize ?? injectedWidth
4223
4279
  };
4224
4280
  return {
4225
4281
  id: column.id,
4226
- fit: autosizeWidths[column.id],
4282
+ fit: autosizeWidths.fits[column.id],
4283
+ headerWidth: autosizeWidths.headerWidths[column.id],
4227
4284
  size: raw ? raw.size ?? defaultColumn?.size : column.columnDef.size,
4228
4285
  minSize: raw ? raw.minSize ?? defaultColumn?.minSize : column.columnDef.minSize,
4229
4286
  maxSize: raw ? raw.maxSize ?? defaultColumn?.maxSize : column.columnDef.maxSize
4230
4287
  };
4231
- }), columnSizing, availableWidth);
4288
+ }), columnSizing, widths.available);
4232
4289
  }, [
4233
4290
  columns,
4234
4291
  columnSizing,
4235
- availableWidth,
4292
+ widths.available,
4236
4293
  defaultColumn,
4237
4294
  injectedWidth,
4238
4295
  autosizeWidths
@@ -4240,9 +4297,15 @@ function useColumnWidths(table, { columns, viewport, tableMinWidth, injectedWidt
4240
4297
  const signature = JSON.stringify([
4241
4298
  resolved.total,
4242
4299
  resolved.filler,
4300
+ widths.viewport,
4243
4301
  Object.entries(resolved.byId)
4244
4302
  ]);
4245
- return useMemo(() => resolved, [signature]);
4303
+ return useMemo(() => {
4304
+ return {
4305
+ ...resolved,
4306
+ viewportWidth: widths.viewport
4307
+ };
4308
+ }, [signature]);
4246
4309
  }
4247
4310
  //#endregion
4248
4311
  //#region src/ledger-features.ts
@@ -6966,6 +7029,7 @@ const defaultProps = {
6966
7029
  withBottomBorder: false,
6967
7030
  size: "sm",
6968
7031
  tabularNums: false,
7032
+ columnMinSizeFromHeader: false,
6969
7033
  virtualizedRows: false,
6970
7034
  virtualizedColumns: false,
6971
7035
  endReachedOffset: 240,
@@ -7105,7 +7169,7 @@ function DataTableFromOptions({ props }) {
7105
7169
  });
7106
7170
  }
7107
7171
  function DataTableCore({ presentation, stylesProps, table }) {
7108
- 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;
7109
7173
  const getStyles = useStyles({
7110
7174
  name: "DataTable",
7111
7175
  classes,
@@ -7168,6 +7232,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7168
7232
  columnSizing: table.state.columnSizing,
7169
7233
  columns: visibleLeafColumns,
7170
7234
  main,
7235
+ minSizeFromHeader: columnMinSizeFromHeader === true,
7171
7236
  rows: table.getRowModel().rows,
7172
7237
  viewport,
7173
7238
  virtualized: Boolean(virtualizedRows) || Boolean(virtualizedColumns)
@@ -7251,6 +7316,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7251
7316
  }
7252
7317
  }
7253
7318
  varsMap["--ledger-pinned-start-width"] = `${leftOffset}px`;
7319
+ if (columnWidths.viewportWidth > 0) varsMap["--ledger-viewport-width"] = `${columnWidths.viewportWidth}px`;
7254
7320
  let rightOffset = 0;
7255
7321
  for (let index = visibleLeafColumns.length - 1; index >= 0; index -= 1) {
7256
7322
  const column = visibleLeafColumns[index];