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