@canvas-components/list-table 0.3.9 → 0.3.10

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.js CHANGED
@@ -2846,8 +2846,8 @@ function resolveContentTextDecoration(content) {
2846
2846
  function resolveContentTextIndent(content) {
2847
2847
  return content.style?.textIndent ?? 0;
2848
2848
  }
2849
- function resolveContentTextAlign(content) {
2850
- return content.style?.textAlign ?? "left";
2849
+ function resolveContentTextAlign(content, fallback = "left") {
2850
+ return content.style?.textAlign ?? fallback;
2851
2851
  }
2852
2852
  function resolveContentLayoutWidth(content, intrinsicWidth) {
2853
2853
  return Math.max(content.style?.width ?? intrinsicWidth, intrinsicWidth);
@@ -5880,7 +5880,7 @@ function drawBodyTagContent(params) {
5880
5880
  fontFamily: resolveContentFontFamily(content, theme)
5881
5881
  });
5882
5882
  ctx.textAlign = "left";
5883
- ctx.textBaseline = "middle";
5883
+ ctx.textBaseline = "alphabetic";
5884
5884
  const bounds = measureTextBounds(ctx, content.text);
5885
5885
  const textBoxWidth = Math.max(width - paddingInline * 2, 0);
5886
5886
  const textX = resolveAlignedTextX({
@@ -5888,9 +5888,14 @@ function drawBodyTagContent(params) {
5888
5888
  boxWidth: textBoxWidth,
5889
5889
  textWidth: bounds.width,
5890
5890
  textIndent,
5891
- textAlign: resolveContentTextAlign(content)
5891
+ textAlign: resolveContentTextAlign(content, "center")
5892
5892
  });
5893
5893
  const centerY = rect.y + rect.height / 2;
5894
+ const textY = resolveCenteredTextBaselineY({
5895
+ centerY,
5896
+ ascent: bounds.ascent,
5897
+ descent: bounds.descent
5898
+ });
5894
5899
  drawSelectableTextSelectionBackground({
5895
5900
  ctx,
5896
5901
  text: content.text,
@@ -5900,11 +5905,11 @@ function drawBodyTagContent(params) {
5900
5905
  fragmentKey,
5901
5906
  textSelection,
5902
5907
  textOriginX: textX,
5903
- textTop: centerY - bounds.ascent,
5908
+ textTop: textY - bounds.ascent,
5904
5909
  textHeight: bounds.height,
5905
5910
  color: theme.textSelectionBackgroundColor ?? "#99c2ff"
5906
5911
  });
5907
- ctx.fillText(content.text, textX, centerY);
5912
+ ctx.fillText(content.text, textX, textY);
5908
5913
  const textFont = ctx.font;
5909
5914
  drawTextDecoration({
5910
5915
  ctx,
@@ -5926,7 +5931,7 @@ function drawBodyTagContent(params) {
5926
5931
  contentIndex,
5927
5932
  fragmentKey,
5928
5933
  textOriginX: textX,
5929
- textTop: centerY - bounds.ascent,
5934
+ textTop: textY - bounds.ascent,
5930
5935
  textWidth: bounds.width,
5931
5936
  textHeight: bounds.height,
5932
5937
  fixed: column.fixed,
@@ -5969,7 +5974,7 @@ function applyTagTextStyle(ctx, content, theme) {
5969
5974
  fontFamily: resolveContentFontFamily(content, theme)
5970
5975
  });
5971
5976
  ctx.textAlign = "left";
5972
- ctx.textBaseline = "middle";
5977
+ ctx.textBaseline = "alphabetic";
5973
5978
  }
5974
5979
  function resolveTagPalette(content) {
5975
5980
  if (content.style?.backgroundColor || content.style?.color || content.backgroundColor || content.borderColor || content.textColor) {
@@ -6789,7 +6794,7 @@ function drawBodyCellContents(params) {
6789
6794
  rect: lineRect,
6790
6795
  visibleRect: lineVisibleRect,
6791
6796
  lineWidth: line.width,
6792
- align: column.align
6797
+ align: resolveBodyContentLineAlign(line, column.align)
6793
6798
  });
6794
6799
  line.items.forEach((item, itemIndex) => {
6795
6800
  if (itemIndex > 0) {
@@ -7916,6 +7921,12 @@ function resolveLineStartX(rect, lineWidth, align) {
7916
7921
  }
7917
7922
  return rect.x;
7918
7923
  }
7924
+ function resolveBodyContentLineAlign(line, columnAlign) {
7925
+ if (columnAlign != null) {
7926
+ return columnAlign;
7927
+ }
7928
+ return line.items.length > 0 && line.items.every((item) => item.content.type === "tag") ? "center" : columnAlign;
7929
+ }
7919
7930
  function resolveStickyLineStartX(params) {
7920
7931
  const { rect, visibleRect, lineWidth, align } = params;
7921
7932
  const preferredX = resolveLineStartX(rect, lineWidth, align);
@@ -18373,8 +18384,9 @@ async function getColumnConfig(key) {
18373
18384
  // src/services/column-config-service.ts
18374
18385
  function applyStoredColumnConfig(columns, storedColumns) {
18375
18386
  if (!storedColumns) {
18376
- return;
18387
+ return false;
18377
18388
  }
18389
+ let columnWidthsChanged = false;
18378
18390
  const applyToColumns = (cols) => {
18379
18391
  for (const col of cols) {
18380
18392
  if (!col.key) {
@@ -18382,6 +18394,9 @@ function applyStoredColumnConfig(columns, storedColumns) {
18382
18394
  }
18383
18395
  const stored = storedColumns[col.key];
18384
18396
  if (stored) {
18397
+ if ((col.width ?? 160) !== stored.width) {
18398
+ columnWidthsChanged = true;
18399
+ }
18385
18400
  col.width = stored.width;
18386
18401
  col.hidden = !!stored.hidden;
18387
18402
  if ("align" in stored) {
@@ -18426,6 +18441,7 @@ function applyStoredColumnConfig(columns, storedColumns) {
18426
18441
  }
18427
18442
  };
18428
18443
  applyToColumns(columns);
18444
+ return columnWidthsChanged;
18429
18445
  }
18430
18446
  function buildStoredColumnConfig(columns, sortState, filterState, zoom, summaryRowHeight, density) {
18431
18447
  const result = {};
@@ -18545,7 +18561,7 @@ async function loadListTableStoredConfig(params) {
18545
18561
  if (!stored) {
18546
18562
  return null;
18547
18563
  }
18548
- applyStoredColumnConfig(columns, stored.columns);
18564
+ const columnWidthsChanged = applyStoredColumnConfig(columns, stored.columns);
18549
18565
  return {
18550
18566
  sortState: stored.sort?.key ? {
18551
18567
  key: stored.sort.key,
@@ -18554,7 +18570,8 @@ async function loadListTableStoredConfig(params) {
18554
18570
  filterState: stored.filters ? stored.filters : null,
18555
18571
  zoom: typeof stored.zoom === "number" && Number.isFinite(stored.zoom) && stored.zoom > 0 ? stored.zoom : null,
18556
18572
  summaryRowHeight: typeof stored.summaryRowHeight === "number" && Number.isFinite(stored.summaryRowHeight) && stored.summaryRowHeight >= 0 ? stored.summaryRowHeight : null,
18557
- density: stored.density === 26 || stored.density === 32 || stored.density === 48 || stored.density === 56 || stored.density === "auto" ? stored.density : null
18573
+ density: stored.density === 26 || stored.density === 32 || stored.density === 48 || stored.density === 56 || stored.density === "auto" ? stored.density : null,
18574
+ columnWidthsChanged
18558
18575
  };
18559
18576
  }
18560
18577
 
@@ -18587,6 +18604,12 @@ var ListTablePersistenceController = class {
18587
18604
  this.options.canvasHost.setContentZoom(nextZoom);
18588
18605
  }
18589
18606
  let currentOptions = this.options.getOptions();
18607
+ if (stored.columnWidthsChanged && currentOptions.stretchColumns !== false) {
18608
+ currentOptions = {
18609
+ ...currentOptions,
18610
+ stretchColumns: false
18611
+ };
18612
+ }
18590
18613
  if (stored.density != null) {
18591
18614
  const densitySizes = resolveDensitySizes(
18592
18615
  stored.density === "auto" ? "auto" : stored.density === 26 ? "ultra-compact" : stored.density === 32 ? "compact" : stored.density === 56 ? "comfortable" : "middle"