@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.cjs CHANGED
@@ -2839,7 +2839,10 @@ function DetailRow({ row, renderDetailPanel, colSpan, dragging, dropSide, last,
2839
2839
  colSpan,
2840
2840
  role: "cell",
2841
2841
  ...getStyles("detailPanel"),
2842
- children: renderDetailPanel?.(row)
2842
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2843
+ "data-detail-content": true,
2844
+ children: renderDetailPanel?.(row)
2845
+ })
2843
2846
  })
2844
2847
  });
2845
2848
  }
@@ -3182,8 +3185,10 @@ function TableFooter({ table, ariaRowIndexStart, columnWindow, filler }) {
3182
3185
  //#region src/column-autosize.ts
3183
3186
  /**
3184
3187
  * Fitting columns to their rendered content (docs/sizing.md#autosize) — one measurement behind
3185
- * both of its uses: the resizer's double-click, which writes the fit as a `columnSizing` entry,
3186
- * and `meta.autosize`, which keeps a column fitted as its content changes (`use-autosize-widths.ts`).
3188
+ * each of its uses: the resizer's double-click, which writes the fit as a `columnSizing` entry,
3189
+ * `meta.autosize`, which keeps a column fitted as its content changes, and
3190
+ * `meta.minSizeFromHeader`, which keeps a column at least as wide as its header
3191
+ * (`use-autosize-widths.ts`).
3187
3192
  *
3188
3193
  * What is measured is what the column has to hold: the header cell, every RENDERED body cell —
3189
3194
  * under virtualization that is the current window, the industry contract for autosize (unrendered
@@ -3259,18 +3264,19 @@ function contentCells(main, region, selector) {
3259
3264
  return [...main.querySelectorAll(`:scope ${region} ${selector}`)].filter((cell) => cell.colSpan <= 1 && !Object.hasOwn(cell.dataset, "editing"));
3260
3265
  }
3261
3266
  /**
3262
- * The width each target's rendered content needs, slack included, in integer pixels — before the
3267
+ * The width each target's rendered extent needs, slack included, in integer pixels — before the
3263
3268
  * column's own `minSize`/`maxSize`, which are the caller's to apply. A column with nothing rendered
3264
3269
  * (one a column window left out) has no entry.
3265
3270
  */
3266
3271
  function measureColumnWidths(main, targets) {
3267
3272
  const columns = targets.map((target) => {
3268
3273
  const selector = `[data-ledger-column-id="${CSS.escape(target.columnId)}"]`;
3274
+ const withContent = target.extent === "content";
3269
3275
  return {
3270
3276
  target,
3271
3277
  header: main.querySelector(`:scope .ledger-header ${selector}`),
3272
- body: contentCells(main, ".ledger-tbody", selector),
3273
- footer: contentCells(main, ".ledger-footer", selector)
3278
+ body: withContent ? contentCells(main, ".ledger-tbody", selector) : [],
3279
+ footer: withContent ? contentCells(main, ".ledger-footer", selector) : []
3274
3280
  };
3275
3281
  });
3276
3282
  const headers = columns.map((column) => column.header).filter((header) => header !== null);
@@ -3309,7 +3315,10 @@ function measureColumnWidths(main, targets) {
3309
3315
  * arrive from the render that put the handle on screen, for the reason `use-column-resize.ts` gives.
3310
3316
  */
3311
3317
  function autosizeColumn(setColumnSizing, { minSize, maxSize, ...target }, main) {
3312
- const fitted = measureColumnWidths(main, [target]).get(target.columnId);
3318
+ const fitted = measureColumnWidths(main, [{
3319
+ ...target,
3320
+ extent: "content"
3321
+ }]).get(target.columnId);
3313
3322
  if (fitted === void 0) return;
3314
3323
  const next = Math.min(Math.max(fitted, minSize), maxSize);
3315
3324
  setColumnSizing((previous) => previous[target.columnId] === next ? previous : {
@@ -3951,8 +3960,13 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
3951
3960
  //#endregion
3952
3961
  //#region src/use-autosize-widths.ts
3953
3962
  /**
3954
- * `meta.autosize` (docs/sizing.md#autosize): keeps each such column fitted to its rendered content
3955
- * and hands the width engine the fits, which rank between a user's resize and the author's `size`.
3963
+ * The widths ledger measures and keeps measured (docs/sizing.md#autosize), for the width engine:
3964
+ * - **fits** — `meta.autosize`: each such column fitted to its rendered content, a width that
3965
+ * ranks between a user's resize and the author's `size`;
3966
+ * - **header widths** — `meta.minSizeFromHeader`, or the table's `columnMinSizeFromHeader`: each
3967
+ * such column's header measured whole, a floor under the column's width
3968
+ * (docs/sizing.md#a-header-held-whole). A column fitted by `autosize` holds its header already
3969
+ * and is not measured twice.
3956
3970
  *
3957
3971
  * When a fit is taken, and what it may do:
3958
3972
  * - **A new view refits.** Different rows (a new page, a filter, a sort — anything that changes the
@@ -3977,16 +3991,38 @@ function HeaderCell({ header, table, reorder, resize, columnWidths, columnSizing
3977
3991
  */
3978
3992
  const SCROLL_SETTLE_MS = 150;
3979
3993
  const NO_WIDTHS = {};
3980
- function autosizeTargets(columns, columnSizing) {
3994
+ /**
3995
+ * What each column has measured: its content under `meta.autosize`, else its header where it asks
3996
+ * never to be narrower than it — nothing for an injected column or one a user resized.
3997
+ */
3998
+ function autosizeTargets(columns, columnSizing, minSizeFromHeader) {
3981
3999
  return columns.flatMap((column) => {
3982
4000
  const { meta } = column.columnDef;
3983
- return meta?.autosize === true && !isInternalColumn(column.id) && columnSizing[column.id] === void 0 ? [{
4001
+ if (isInternalColumn(column.id) || columnSizing[column.id] !== void 0) return [];
4002
+ const extent = meta?.autosize === true ? "content" : meta?.minSizeFromHeader ?? minSizeFromHeader ? "header" : void 0;
4003
+ return extent === void 0 ? [] : [{
3984
4004
  columnId: column.id,
3985
- hasFilter: meta.filter !== void 0,
3986
- truncate: meta.truncate === true
3987
- }] : [];
4005
+ extent,
4006
+ hasFilter: meta?.filter !== void 0,
4007
+ truncate: meta?.truncate === true
4008
+ }];
3988
4009
  });
3989
4010
  }
4011
+ /**
4012
+ * The measured widths, told apart by what each target measured.
4013
+ */
4014
+ function byExtent(widths, targets) {
4015
+ const fits = {};
4016
+ const headerWidths = {};
4017
+ for (const { columnId, extent } of targets) {
4018
+ const width = widths[columnId];
4019
+ if (width !== void 0) (extent === "content" ? fits : headerWidths)[columnId] = width;
4020
+ }
4021
+ return {
4022
+ fits,
4023
+ headerWidths
4024
+ };
4025
+ }
3990
4026
  function sameIds(previous, next) {
3991
4027
  return previous.length === next.length && previous.every((id, index) => id === next[index]);
3992
4028
  }
@@ -4018,8 +4054,8 @@ function useFontsVersion(enabled) {
4018
4054
  }, [enabled]);
4019
4055
  return version;
4020
4056
  }
4021
- function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appearance, virtualized }) {
4022
- const targets = autosizeTargets(columns, columnSizing);
4057
+ function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appearance, virtualized, minSizeFromHeader }) {
4058
+ const targets = autosizeTargets(columns, columnSizing, minSizeFromHeader);
4023
4059
  const enabled = targets.length > 0;
4024
4060
  const fontsVersion = useFontsVersion(enabled);
4025
4061
  const signature = JSON.stringify([
@@ -4100,7 +4136,7 @@ function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appear
4100
4136
  fit,
4101
4137
  fitWhenSettled
4102
4138
  ]);
4103
- return widths;
4139
+ return (0, react.useMemo)(() => byExtent(widths, targets), [widths, signature]);
4104
4140
  }
4105
4141
  //#endregion
4106
4142
  //#region src/use-column-widths.ts
@@ -4110,9 +4146,12 @@ function useAutosizeWidths({ columns, columnSizing, main, viewport, rows, appear
4110
4146
  * number system — the browser never redistributes anything.
4111
4147
  *
4112
4148
  * Rules, in order:
4149
+ * - a column's minimum is its declared `minSize`, raised to its measured header where it asks
4150
+ * never to be narrower than it (`meta.minSizeFromHeader`) — except under a user's resize, which
4151
+ * the declared bounds alone clamp;
4113
4152
  * - a column with an explicit width (user-resized `columnSizing` entry, else its fitted content
4114
4153
  * width under `meta.autosize`, else the author's `size`, else `defaultColumn.size`) is fixed at
4115
- * that width, clamped to its declared min/max;
4154
+ * that width, clamped to its minimum and its declared max;
4116
4155
  * - a column without one is a grow column with basis `minSize ?? 80`; container surplus is
4117
4156
  * distributed proportionally to the bases (integer floor, remainder in display order), capped
4118
4157
  * by maxSize; when the container is too small every grow column falls back to its basis and the
@@ -4141,6 +4180,13 @@ function clampWidth(value, min, max) {
4141
4180
  return Math.min(Math.max(Number.isFinite(value) ? Math.max(0, Math.round(value)) : 0, normalizedBound(min) ?? 0), normalizedBound(max) ?? Number.MAX_SAFE_INTEGER);
4142
4181
  }
4143
4182
  /**
4183
+ * The column's declared `minSize`, raised to its measured header where it has one.
4184
+ */
4185
+ function headerMinSize(column) {
4186
+ const headerWidth = finiteNumber(column.headerWidth);
4187
+ return headerWidth === void 0 ? column.minSize : Math.max(headerWidth, finiteNumber(column.minSize) ?? 0);
4188
+ }
4189
+ /**
4144
4190
  * Weighted water-filling over integer pixels. Columns that hit maxSize leave the active set and
4145
4191
  * the remaining space is redistributed over columns that can still grow. If every column reaches
4146
4192
  * its cap, maxSize wins and the table intentionally stops short of the viewport.
@@ -4180,16 +4226,18 @@ function resolveColumnWidths(columns, columnSizing, availableWidth) {
4180
4226
  const byId = {};
4181
4227
  const growColumns = [];
4182
4228
  for (const column of columns) {
4183
- const sized = finiteNumber(columnSizing[column.id]) ?? finiteNumber(column.fit) ?? finiteNumber(column.size);
4229
+ const resized = finiteNumber(columnSizing[column.id]);
4230
+ const sized = resized ?? finiteNumber(column.fit) ?? finiteNumber(column.size);
4231
+ const minSize = resized === void 0 ? headerMinSize(column) : column.minSize;
4184
4232
  if (sized === void 0) {
4185
- const basis = clampWidth(column.minSize ?? DEFAULT_FLEX_BASIS, column.minSize, column.maxSize);
4233
+ const basis = clampWidth(column.minSize ?? DEFAULT_FLEX_BASIS, minSize, column.maxSize);
4186
4234
  byId[column.id] = basis;
4187
4235
  growColumns.push({
4188
4236
  id: column.id,
4189
4237
  weight: basis,
4190
4238
  max: normalizedBound(column.maxSize)
4191
4239
  });
4192
- } else byId[column.id] = clampWidth(sized, column.minSize, column.maxSize);
4240
+ } else byId[column.id] = clampWidth(sized, minSize, column.maxSize);
4193
4241
  }
4194
4242
  const baseTotal = columns.reduce((total, column) => total + (byId[column.id] ?? 0), 0);
4195
4243
  const targetWidth = Number.isFinite(availableWidth) ? Math.max(0, Math.round(availableWidth)) : 0;
@@ -4220,11 +4268,18 @@ function minWidthPx(tableMinWidth, viewport) {
4220
4268
  return Number.parseFloat(getComputedStyle(tableElement).minWidth) || 0;
4221
4269
  }
4222
4270
  function useColumnWidths(table, { columns, viewport, tableMinWidth, injectedWidth, autosizeWidths }) {
4223
- const [availableWidth, setAvailableWidth] = (0, react.useState)(0);
4271
+ const [widths, setWidths] = (0, react.useState)({
4272
+ available: 0,
4273
+ viewport: 0
4274
+ });
4224
4275
  const measure = (0, react.useCallback)(() => {
4225
4276
  if (!viewport) return;
4226
- const next = Math.max(viewport.clientWidth, minWidthPx(tableMinWidth, viewport));
4227
- setAvailableWidth((previous) => previous === next ? previous : next);
4277
+ const inner = Math.max(0, Math.round(viewport.clientWidth));
4278
+ const available = Math.max(inner, minWidthPx(tableMinWidth, viewport));
4279
+ setWidths((previous) => previous.available === available && previous.viewport === inner ? previous : {
4280
+ available,
4281
+ viewport: inner
4282
+ });
4228
4283
  }, [viewport, tableMinWidth]);
4229
4284
  (0, react.useLayoutEffect)(() => {
4230
4285
  measure();
@@ -4241,22 +4296,24 @@ function useColumnWidths(table, { columns, viewport, tableMinWidth, injectedWidt
4241
4296
  if (isInternalColumn(column.id)) return {
4242
4297
  id: column.id,
4243
4298
  fit: void 0,
4299
+ headerWidth: void 0,
4244
4300
  size: raw?.size ?? injectedWidth,
4245
4301
  minSize: raw?.minSize ?? injectedWidth,
4246
4302
  maxSize: raw?.maxSize ?? injectedWidth
4247
4303
  };
4248
4304
  return {
4249
4305
  id: column.id,
4250
- fit: autosizeWidths[column.id],
4306
+ fit: autosizeWidths.fits[column.id],
4307
+ headerWidth: autosizeWidths.headerWidths[column.id],
4251
4308
  size: raw ? raw.size ?? defaultColumn?.size : column.columnDef.size,
4252
4309
  minSize: raw ? raw.minSize ?? defaultColumn?.minSize : column.columnDef.minSize,
4253
4310
  maxSize: raw ? raw.maxSize ?? defaultColumn?.maxSize : column.columnDef.maxSize
4254
4311
  };
4255
- }), columnSizing, availableWidth);
4312
+ }), columnSizing, widths.available);
4256
4313
  }, [
4257
4314
  columns,
4258
4315
  columnSizing,
4259
- availableWidth,
4316
+ widths.available,
4260
4317
  defaultColumn,
4261
4318
  injectedWidth,
4262
4319
  autosizeWidths
@@ -4264,9 +4321,15 @@ function useColumnWidths(table, { columns, viewport, tableMinWidth, injectedWidt
4264
4321
  const signature = JSON.stringify([
4265
4322
  resolved.total,
4266
4323
  resolved.filler,
4324
+ widths.viewport,
4267
4325
  Object.entries(resolved.byId)
4268
4326
  ]);
4269
- return (0, react.useMemo)(() => resolved, [signature]);
4327
+ return (0, react.useMemo)(() => {
4328
+ return {
4329
+ ...resolved,
4330
+ viewportWidth: widths.viewport
4331
+ };
4332
+ }, [signature]);
4270
4333
  }
4271
4334
  //#endregion
4272
4335
  //#region src/ledger-features.ts
@@ -6990,6 +7053,7 @@ const defaultProps = {
6990
7053
  withBottomBorder: false,
6991
7054
  size: "sm",
6992
7055
  tabularNums: false,
7056
+ columnMinSizeFromHeader: false,
6993
7057
  virtualizedRows: false,
6994
7058
  virtualizedColumns: false,
6995
7059
  endReachedOffset: 240,
@@ -7129,7 +7193,7 @@ function DataTableFromOptions({ props }) {
7129
7193
  });
7130
7194
  }
7131
7195
  function DataTableCore({ presentation, stylesProps, table }) {
7132
- 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;
7196
+ 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;
7133
7197
  const getStyles = (0, _mantine_core.useStyles)({
7134
7198
  name: "DataTable",
7135
7199
  classes,
@@ -7192,6 +7256,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7192
7256
  columnSizing: table.state.columnSizing,
7193
7257
  columns: visibleLeafColumns,
7194
7258
  main,
7259
+ minSizeFromHeader: columnMinSizeFromHeader === true,
7195
7260
  rows: table.getRowModel().rows,
7196
7261
  viewport,
7197
7262
  virtualized: Boolean(virtualizedRows) || Boolean(virtualizedColumns)
@@ -7275,6 +7340,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
7275
7340
  }
7276
7341
  }
7277
7342
  varsMap["--ledger-pinned-start-width"] = `${leftOffset}px`;
7343
+ if (columnWidths.viewportWidth > 0) varsMap["--ledger-viewport-width"] = `${columnWidths.viewportWidth}px`;
7278
7344
  let rightOffset = 0;
7279
7345
  for (let index = visibleLeafColumns.length - 1; index >= 0; index -= 1) {
7280
7346
  const column = visibleLeafColumns[index];