@canvas-components/list-table 0.3.8 → 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"
@@ -20498,6 +20521,10 @@ function buildListTableRenderSnapshot(params) {
20498
20521
  if (leafColumns.length === 0) {
20499
20522
  return null;
20500
20523
  }
20524
+ const columnMetrics = resolveColumnMetrics({
20525
+ columns: leafColumns,
20526
+ tableWidth: width
20527
+ });
20501
20528
  const headerInfo = buildHeaderTree(normalizedColumns, leafColumns);
20502
20529
  const sourceQueryRows = {
20503
20530
  baseRows: baseRowsOverride ?? getBaseDisplayRows({
@@ -20539,8 +20566,11 @@ function buildListTableRenderSnapshot(params) {
20539
20566
  (col) => col.summary != null || col.summaryTitle != null
20540
20567
  );
20541
20568
  const hasSummary = queryRows.displayRows.length > 0 && options.summaryRowHeight !== 0 && (options.summaryRowHeight != null || hasConfiguredSummary);
20569
+ const hasHorizontalScrollbar = options.scrollbar?.visible !== false && columnMetrics.centerContentWidth - columnMetrics.availableCenterWidth > 1;
20570
+ const horizontalScrollbarReserve = hasSummary && hasHorizontalScrollbar ? scrollbarThickness + Math.max(options.scrollbar?.horizontalBottom ?? 0, 0) : 0;
20571
+ const contentHeight = Math.max(height - horizontalScrollbarReserve, 0);
20542
20572
  const initialBodyLayout = resolveBodyLayout({
20543
- height,
20573
+ height: contentHeight,
20544
20574
  headerHeight,
20545
20575
  summaryRowHeight,
20546
20576
  hasSummary,
@@ -20670,7 +20700,7 @@ function buildListTableRenderSnapshot(params) {
20670
20700
  }
20671
20701
  },
20672
20702
  bodyLayout: resolveBodyLayout({
20673
- height,
20703
+ height: contentHeight,
20674
20704
  headerHeight,
20675
20705
  summaryRowHeight,
20676
20706
  hasSummary,
@@ -20692,7 +20722,7 @@ function buildListTableRenderSnapshot(params) {
20692
20722
  visibleRows: filteredVisibleRows,
20693
20723
  frozenState: frozenRows,
20694
20724
  getRowKey: (row) => row.kind === "data" ? row.rowKey : null,
20695
- height,
20725
+ height: contentHeight,
20696
20726
  headerHeight,
20697
20727
  summaryRowHeight,
20698
20728
  hasSummary,
@@ -20705,7 +20735,7 @@ function buildListTableRenderSnapshot(params) {
20705
20735
  bodyState.frozenRows.scroll.rowIndexMap = plainRowWindow.rowIndexMap;
20706
20736
  bodyState.frozenRows.scroll.rowOffsetMap = plainRowWindow.rowOffsetMap;
20707
20737
  bodyState.bodyLayout = resolveBodyLayout({
20708
- height,
20738
+ height: contentHeight,
20709
20739
  headerHeight,
20710
20740
  summaryRowHeight,
20711
20741
  hasSummary,
@@ -20729,7 +20759,7 @@ function buildListTableRenderSnapshot(params) {
20729
20759
  bodyState.frozenRows.scroll.rowIndexMap = plainRowWindow.rowIndexMap;
20730
20760
  bodyState.frozenRows.scroll.rowOffsetMap = plainRowWindow.rowOffsetMap;
20731
20761
  bodyState.bodyLayout = resolveBodyLayout({
20732
- height,
20762
+ height: contentHeight,
20733
20763
  headerHeight,
20734
20764
  summaryRowHeight,
20735
20765
  hasSummary,
@@ -20740,10 +20770,6 @@ function buildListTableRenderSnapshot(params) {
20740
20770
  scrollRowCount: plainRowWindow.totalRowCount
20741
20771
  });
20742
20772
  }
20743
- let columnMetrics = resolveColumnMetrics({
20744
- columns: leafColumns,
20745
- tableWidth: width
20746
- });
20747
20773
  let viewportResult = computeViewport({
20748
20774
  width,
20749
20775
  height,