@canvas-components/list-table 0.3.21 → 0.3.22

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
@@ -1362,6 +1362,7 @@ interface HeaderContextMenuConfig {
1362
1362
  onResetDataFormat?: () => void;
1363
1363
  onAutoFitCurrentColumn?: () => void;
1364
1364
  onAutoFitAllColumns?: () => void;
1365
+ onAutoFitFillContainer?: () => void;
1365
1366
  groupingBarVisible?: boolean;
1366
1367
  onToggleGroupingBar?: () => void;
1367
1368
  onChangeDensity?: (density: HeaderContextMenuDensity) => void;
package/dist/index.d.ts CHANGED
@@ -1362,6 +1362,7 @@ interface HeaderContextMenuConfig {
1362
1362
  onResetDataFormat?: () => void;
1363
1363
  onAutoFitCurrentColumn?: () => void;
1364
1364
  onAutoFitAllColumns?: () => void;
1365
+ onAutoFitFillContainer?: () => void;
1365
1366
  groupingBarVisible?: boolean;
1366
1367
  onToggleGroupingBar?: () => void;
1367
1368
  onChangeDensity?: (density: HeaderContextMenuDensity) => void;
package/dist/index.js CHANGED
@@ -929,15 +929,23 @@ function setColumnFixed(columns, targetKey, direction, initialColumns) {
929
929
  }
930
930
  updateColumnFixed(columns, targetKey, direction, initialColumns);
931
931
  }
932
- function setNestedColumnWidth(columns, targetKey, newWidth) {
932
+ function setNestedColumnWidth(columns, targetKey, newWidth, expandMaxWidth = false) {
933
933
  ensureColumnKeysInPlace(columns);
934
934
  for (const column of columns) {
935
935
  if (column.key === targetKey) {
936
936
  column.width = newWidth;
937
+ if (expandMaxWidth && newWidth > (column.maxWidth ?? DEFAULT_MAX_WIDTH)) {
938
+ column.maxWidth = newWidth;
939
+ }
937
940
  return;
938
941
  }
939
942
  if (column.children?.length) {
940
- setNestedColumnWidth(column.children, targetKey, newWidth);
943
+ setNestedColumnWidth(
944
+ column.children,
945
+ targetKey,
946
+ newWidth,
947
+ expandMaxWidth
948
+ );
941
949
  }
942
950
  }
943
951
  }
@@ -1484,6 +1492,7 @@ var ListTableDomHost = class {
1484
1492
  wrapper.style.display = "flex";
1485
1493
  wrapper.style.flexDirection = "column";
1486
1494
  wrapper.style.minWidth = "0";
1495
+ wrapper.style.maxWidth = "100%";
1487
1496
  wrapper.style.boxSizing = "border-box";
1488
1497
  wrapper.style.overflow = "visible";
1489
1498
  const contentLayer = document.createElement("div");
@@ -9113,7 +9122,7 @@ function drawSummaryCell(ctx, rect, column, theme, summaryValues, selectedHeader
9113
9122
  const fontSize = style?.fontSize ?? theme.fontSize;
9114
9123
  const paddingInline = style?.paddingInline ?? 12;
9115
9124
  const paddingBlock = style?.paddingBlock ?? 0;
9116
- const textY = style?.verticalAlign === "top" ? rect.y + paddingBlock + fontSize / 2 : style?.verticalAlign === "bottom" ? rect.y + rect.height - paddingBlock - fontSize / 2 : rect.y + rect.height / 2;
9125
+ const centerY = style?.verticalAlign === "top" ? rect.y + paddingBlock + fontSize / 2 : style?.verticalAlign === "bottom" ? rect.y + rect.height - paddingBlock - fontSize / 2 : rect.y + rect.height / 2;
9117
9126
  if (!cellClip) {
9118
9127
  ctx.restore();
9119
9128
  return;
@@ -9138,7 +9147,7 @@ function drawSummaryCell(ctx, rect, column, theme, summaryValues, selectedHeader
9138
9147
  ctx.clip();
9139
9148
  ctx.fillStyle = style?.color ?? theme.headerTextColor;
9140
9149
  ctx.font = `${style?.fontWeight ?? "600"} ${fontSize}px ${style?.fontFamily ?? theme.fontFamily}`;
9141
- ctx.textBaseline = "middle";
9150
+ ctx.textBaseline = "alphabetic";
9142
9151
  const align = style?.textAlign ?? column.align ?? "left";
9143
9152
  ctx.textAlign = align;
9144
9153
  const contentInsetStart = column.key === inlineContentInset?.columnKey ? inlineContentInset.width : 0;
@@ -9159,9 +9168,15 @@ function drawSummaryCell(ctx, rect, column, theme, summaryValues, selectedHeader
9159
9168
  visibleRect,
9160
9169
  padding: paddingInline
9161
9170
  });
9162
- const textWidth = ctx.measureText(displayText).width;
9171
+ const bounds = measureTextBounds(ctx, displayText);
9172
+ const textY = resolveCenteredTextBaselineY({
9173
+ centerY,
9174
+ ascent: bounds.ascent,
9175
+ descent: bounds.descent
9176
+ });
9177
+ const textWidth = bounds.width;
9163
9178
  const textOriginX = textX - (align === "right" ? textWidth : align === "center" ? textWidth / 2 : 0);
9164
- const textTop = textY - fontSize / 2;
9179
+ const textTop = textY - bounds.ascent;
9165
9180
  const fragmentKey = `summary:${column.key}`;
9166
9181
  drawSelectableTextSelectionBackground({
9167
9182
  ctx,
@@ -9169,7 +9184,7 @@ function drawSummaryCell(ctx, rect, column, theme, summaryValues, selectedHeader
9169
9184
  textSelection,
9170
9185
  textOriginX,
9171
9186
  textTop,
9172
- textHeight: fontSize,
9187
+ textHeight: bounds.height,
9173
9188
  rowIndex: Number.MAX_SAFE_INTEGER,
9174
9189
  columnKey: column.key,
9175
9190
  contentIndex: 0,
@@ -9189,7 +9204,7 @@ function drawSummaryCell(ctx, rect, column, theme, summaryValues, selectedHeader
9189
9204
  x: textOriginX,
9190
9205
  y: textTop,
9191
9206
  width: textWidth,
9192
- height: fontSize
9207
+ height: bounds.height
9193
9208
  },
9194
9209
  cellClip
9195
9210
  ) ?? void 0,
@@ -11303,12 +11318,24 @@ function drawBodyTagContent(params) {
11303
11318
  const textColor = resolveTagTextColor(content, palette.textColor);
11304
11319
  const textIndent = resolveContentTextIndent(content);
11305
11320
  const paddingInline = content.paddingInline ?? TAG_HORIZONTAL_PADDING;
11321
+ const drawLeft = Math.round(cursorX);
11322
+ const drawTop = Math.round(top);
11323
+ const drawWidth = Math.max(Math.round(cursorX + width) - drawLeft, 1);
11324
+ const drawHeight = Math.max(Math.round(top + height) - drawTop, 1);
11306
11325
  ctx.save();
11307
11326
  ctx.globalAlpha *= resolveContentOpacity(content);
11308
- drawRoundedRectPath2(ctx, cursorX, top, width, height, radius);
11327
+ drawRoundedRectPath2(ctx, drawLeft, drawTop, drawWidth, drawHeight, radius);
11309
11328
  ctx.fillStyle = content.style?.backgroundColor ?? palette.backgroundColor;
11310
11329
  ctx.fill();
11311
11330
  if (bordered) {
11331
+ drawRoundedRectPath2(
11332
+ ctx,
11333
+ drawLeft + 0.5,
11334
+ drawTop + 0.5,
11335
+ Math.max(drawWidth - 1, 0),
11336
+ Math.max(drawHeight - 1, 0),
11337
+ Math.max(radius - 0.5, 0)
11338
+ );
11312
11339
  ctx.strokeStyle = palette.borderColor;
11313
11340
  ctx.lineWidth = 1;
11314
11341
  ctx.stroke();
@@ -26058,18 +26085,58 @@ function autoFitListTableColumnWidths(params) {
26058
26085
  );
26059
26086
  }
26060
26087
  const nextWidth = Math.ceil(
26061
- clamp(measuredWidth, column.minWidth, column.maxWidth)
26088
+ params.fillContainerWidth == null ? clamp(measuredWidth, column.minWidth, column.maxWidth) : Math.max(measuredWidth, column.minWidth)
26062
26089
  );
26063
26090
  column.width = nextWidth;
26064
- setNestedColumnWidth(options.columns, column.key, nextWidth);
26091
+ if (params.fillContainerWidth != null) {
26092
+ column.maxWidth = Math.max(column.maxWidth, nextWidth);
26093
+ }
26094
+ setNestedColumnWidth(
26095
+ options.columns,
26096
+ column.key,
26097
+ nextWidth,
26098
+ params.fillContainerWidth != null
26099
+ );
26065
26100
  fitted = true;
26066
26101
  });
26102
+ if (fitted && params.fillContainerWidth != null) {
26103
+ const hostWidth = params.hostWidth;
26104
+ const measuredTotalWidth = leafColumns.reduce(
26105
+ (sum, column) => sum + column.width,
26106
+ 0
26107
+ );
26108
+ const shouldPreserveOverflow = hostWidth != null && measuredTotalWidth > params.fillContainerWidth && measuredTotalWidth <= hostWidth;
26109
+ fillAutoFitColumnWidths(leafColumns, params.fillContainerWidth);
26110
+ if (shouldPreserveOverflow && hostWidth != null) {
26111
+ fillAutoFitColumnWidths(leafColumns, Math.ceil(hostWidth) + 1);
26112
+ }
26113
+ leafColumns.forEach((column) => {
26114
+ if (!isSystemColumnKey(column.key)) {
26115
+ setNestedColumnWidth(options.columns, column.key, column.width, true);
26116
+ }
26117
+ });
26118
+ }
26067
26119
  ctx.restore();
26068
26120
  if (fitted) {
26069
26121
  options.stretchColumns = false;
26070
26122
  }
26071
26123
  return fitted;
26072
26124
  }
26125
+ function fillAutoFitColumnWidths(columns, containerWidth) {
26126
+ let remaining = Math.max(
26127
+ Math.round(
26128
+ containerWidth - columns.reduce((sum, column) => sum + column.width, 0)
26129
+ ),
26130
+ 0
26131
+ );
26132
+ const candidates = columns.filter((column) => !isSystemColumnKey(column.key));
26133
+ candidates.forEach((column, index) => {
26134
+ const extra = Math.ceil(remaining / (candidates.length - index));
26135
+ column.width += extra;
26136
+ column.maxWidth = Math.max(column.maxWidth, column.width);
26137
+ remaining -= extra;
26138
+ });
26139
+ }
26073
26140
  function resolveAutoFitMeasureRows(rows, range = {}) {
26074
26141
  if (rows.length === 0) {
26075
26142
  return [];
@@ -26286,6 +26353,10 @@ function createListTableContextMenuActions(params) {
26286
26353
  params.hideMenu();
26287
26354
  params.onAutoFitAllColumns?.();
26288
26355
  } : void 0,
26356
+ onAutoFitFillContainer: params.onAutoFitFillContainer ? () => {
26357
+ params.hideMenu();
26358
+ params.onAutoFitFillContainer?.();
26359
+ } : void 0,
26289
26360
  onToggleGroupingBar: params.onToggleGroupingBar ? () => {
26290
26361
  params.hideMenu();
26291
26362
  params.onToggleGroupingBar?.();
@@ -26515,6 +26586,7 @@ function buildListTableContextMenuConfig(params) {
26515
26586
  onResetDataFormat: enableReset && isTableSettingsArea ? actions.onResetDataFormat : void 0,
26516
26587
  onAutoFitCurrentColumn: enableColumnWidth && isHeaderArea && !isSelectionColumn && actions.onAutoFitCurrentColumn ? () => actions.onAutoFitCurrentColumn?.(columnKey) : void 0,
26517
26588
  onAutoFitAllColumns: enableColumnWidth && isTableSettingsArea && !isSelectionColumn && actions.onAutoFitAllColumns ? actions.onAutoFitAllColumns : void 0,
26589
+ onAutoFitFillContainer: enableColumnWidth && isTableSettingsArea && !isSelectionColumn && actions.onAutoFitFillContainer ? actions.onAutoFitFillContainer : void 0,
26518
26590
  groupingBarVisible,
26519
26591
  onToggleGroupingBar: enableGrouping && (isTableSettingsArea || groupingBarArea) ? actions.onToggleGroupingBar : void 0,
26520
26592
  onChangeDensity: enableDensity ? actions.onChangeDensity : void 0,
@@ -26723,6 +26795,7 @@ function showHeaderContextMenu(params) {
26723
26795
  onResetDataFormat,
26724
26796
  onAutoFitCurrentColumn,
26725
26797
  onAutoFitAllColumns,
26798
+ onAutoFitFillContainer,
26726
26799
  groupingBarVisible,
26727
26800
  groupingBarArea,
26728
26801
  onToggleGroupingBar,
@@ -26836,6 +26909,7 @@ function showHeaderContextMenu(params) {
26836
26909
  onResetDataFormat,
26837
26910
  onAutoFitCurrentColumn,
26838
26911
  onAutoFitAllColumns,
26912
+ onAutoFitFillContainer,
26839
26913
  onToggleGroupingBar,
26840
26914
  onChangeDensity,
26841
26915
  onChangeZoom,
@@ -28613,6 +28687,9 @@ var ListTableEventController = class {
28613
28687
  onAutoFitAllColumns: () => {
28614
28688
  this.autoFitColumnWidths();
28615
28689
  },
28690
+ onAutoFitFillContainer: () => {
28691
+ this.autoFitColumnWidths(void 0, true);
28692
+ },
28616
28693
  groupingBarVisible: this.host.groupBarVisible,
28617
28694
  groupingBarArea,
28618
28695
  onToggleGroupingBar: () => {
@@ -29833,7 +29910,7 @@ var ListTableEventController = class {
29833
29910
  } catch {
29834
29911
  }
29835
29912
  }
29836
- async autoFitColumnWidths(columnKey) {
29913
+ async autoFitColumnWidths(columnKey, fillContainer = false) {
29837
29914
  const ctx = this.host.canvasElement?.getContext("2d");
29838
29915
  if (!ctx) {
29839
29916
  return;
@@ -29872,7 +29949,9 @@ var ListTableEventController = class {
29872
29949
  columnKeys,
29873
29950
  rowStartIndex: startIndex,
29874
29951
  rowEndIndex: endIndex,
29875
- summaryValues
29952
+ summaryValues,
29953
+ fillContainerWidth: fillContainer ? snapshot?.viewport.width ?? this.host.canvasElement?.clientWidth : void 0,
29954
+ hostWidth: fillContainer ? this.host.canvasElement?.clientWidth || snapshot?.viewport.width : void 0
29876
29955
  });
29877
29956
  if (!changed) {
29878
29957
  return;