@extend-ai/react-xlsx 0.12.0 → 0.12.2

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
@@ -17145,6 +17145,15 @@ function resolveCanvasLineHeight(style, fallbackFontSize = 12) {
17145
17145
  }
17146
17146
  return fontSizePx * 1.2;
17147
17147
  }
17148
+ function resolveCanvasTextMiddleY(verticalAlign, contentTop, contentHeight, lineHeight) {
17149
+ if (verticalAlign === "top") {
17150
+ return contentTop + lineHeight / 2;
17151
+ }
17152
+ if (verticalAlign === "middle") {
17153
+ return contentTop + contentHeight / 2;
17154
+ }
17155
+ return contentTop + contentHeight - lineHeight / 2;
17156
+ }
17148
17157
  function resolveCanvasWrapIndex(context, text, maxWidth) {
17149
17158
  if (text.length <= 1) {
17150
17159
  return text.length;
@@ -23644,9 +23653,6 @@ function XlsxGrid({
23644
23653
  };
23645
23654
  }, [activeSheet, asyncViewportRowBatch, getRowsBatchAsync, shouldVirtualizeRows, startBatchTransition, viewportRequest]);
23646
23655
  const viewportRowBatch = getRowsBatchAsync ? asyncViewportRowBatch : syncViewportRowBatch;
23647
- React4.useEffect(() => {
23648
- cellRenderCacheRef.current.clear();
23649
- }, [activeSheetIndex, displayColLimit, displayRowLimit, getCellStyle, palette, revision, viewportRowBatch, worksheet, zoomFactor]);
23650
23656
  React4.useEffect(() => {
23651
23657
  setAsyncViewportRowBatch(null);
23652
23658
  }, [activeSheetIndex, revision]);
@@ -23665,9 +23671,39 @@ function XlsxGrid({
23665
23671
  () => activeSheet ? chartRangeHighlights.filter((highlight) => highlight.workbookSheetIndex === activeSheet.workbookSheetIndex) : [],
23666
23672
  [activeSheet, chartRangeHighlights]
23667
23673
  );
23668
- React4.useEffect(() => {
23674
+ const cellRenderCacheInvalidationKey = React4.useMemo(
23675
+ () => [
23676
+ activeSheetChartHighlights,
23677
+ activeSheetIndex,
23678
+ displayColLimit,
23679
+ displayRowLimit,
23680
+ getCellStyle,
23681
+ palette,
23682
+ revision,
23683
+ selectedChartId,
23684
+ viewportRowBatch,
23685
+ worksheet,
23686
+ zoomFactor
23687
+ ],
23688
+ [
23689
+ activeSheetChartHighlights,
23690
+ activeSheetIndex,
23691
+ displayColLimit,
23692
+ displayRowLimit,
23693
+ getCellStyle,
23694
+ palette,
23695
+ revision,
23696
+ selectedChartId,
23697
+ viewportRowBatch,
23698
+ worksheet,
23699
+ zoomFactor
23700
+ ]
23701
+ );
23702
+ const cellRenderCacheInvalidationRef = React4.useRef(null);
23703
+ if (cellRenderCacheInvalidationRef.current !== cellRenderCacheInvalidationKey) {
23669
23704
  cellRenderCacheRef.current.clear();
23670
- }, [activeSheetChartHighlights, selectedChartId]);
23705
+ cellRenderCacheInvalidationRef.current = cellRenderCacheInvalidationKey;
23706
+ }
23671
23707
  const getCellData = React4.useCallback((row, col) => {
23672
23708
  const cacheKey = `${row}:${col}`;
23673
23709
  const cached = cellRenderCacheRef.current.get(cacheKey);
@@ -23874,6 +23910,7 @@ function XlsxGrid({
23874
23910
  }, [
23875
23911
  activeSheet,
23876
23912
  activeSheetChartHighlights,
23913
+ cellRenderCacheInvalidationKey,
23877
23914
  colIndexByActual,
23878
23915
  colPrefixSums,
23879
23916
  displayDefaultColWidth,
@@ -26377,8 +26414,9 @@ function XlsxGrid({
26377
26414
  const textColor = canvasCellStyle.textColor;
26378
26415
  const shouldEllipsizeText = canvasCellStyle.textOverflowEllipsis;
26379
26416
  const shouldWrapText = canvasCellStyle.usesWrappedText || rawText.includes("\n");
26417
+ const singleLineHeight = cellData.shrinkToFitFontSizePx ? resolveCanvasLineHeight(cellStyle, cellData.shrinkToFitFontSizePx) : resolveCanvasLineHeight(cellStyle, 12 * zoomFactor);
26380
26418
  if (cellData.textRotationDeg && rawText.length > 0) {
26381
- const textY = contentTop + contentHeight / 2;
26419
+ const textY = resolveCanvasTextMiddleY(cellStyle.verticalAlign, contentTop, contentHeight, singleLineHeight);
26382
26420
  const rotationOriginX = contentLeft + contentWidth / 2;
26383
26421
  paneContext.save();
26384
26422
  paneContext.translate(rotationOriginX, textY);
@@ -26418,7 +26456,7 @@ function XlsxGrid({
26418
26456
  });
26419
26457
  } else if (spillMaxWidth != null) {
26420
26458
  const text = shouldEllipsizeText ? truncateCanvasText(paneContext, rawText, maxTextWidth) : rawText;
26421
- const textY = contentTop + contentHeight / 2;
26459
+ const textY = resolveCanvasTextMiddleY(cellStyle.verticalAlign, contentTop, contentHeight, singleLineHeight);
26422
26460
  deferredSpillTextsByPane[pane].push({
26423
26461
  align,
26424
26462
  clipHeight: contentHeight + textClipOverscan * 2,
@@ -26438,7 +26476,7 @@ function XlsxGrid({
26438
26476
  });
26439
26477
  } else {
26440
26478
  const text = cellData.shrinkToFit ? rawText : shouldEllipsizeText ? truncateCanvasText(paneContext, rawText, maxTextWidth) : rawText;
26441
- const textY = contentTop + contentHeight / 2;
26479
+ const textY = resolveCanvasTextMiddleY(cellStyle.verticalAlign, contentTop, contentHeight, singleLineHeight);
26442
26480
  paneContext.fillText(text, textX, textY);
26443
26481
  drawCanvasTextDecorations(paneContext, {
26444
26482
  align,
@@ -29867,13 +29905,14 @@ function useXlsxViewerThumbnails(options = {}) {
29867
29905
  const align = canvasCellStyle.textAlign;
29868
29906
  context.textAlign = align;
29869
29907
  const textX = align === "right" ? contentLeft + contentWidth : align === "center" ? contentLeft + contentWidth / 2 : contentLeft;
29870
- const textY = contentTop + contentHeight / 2;
29871
29908
  const trailingInset = cellData.conditionalIcon ? 18 : 0;
29872
29909
  const maxTextWidth = Math.max(0, contentWidth - trailingInset);
29910
+ const singleLineHeight = resolveCanvasLineHeight(cellData.style, 12);
29873
29911
  if (cellData.textRotationDeg) {
29912
+ const alignedTextY = resolveCanvasTextMiddleY(cellData.style.verticalAlign, contentTop, contentHeight, singleLineHeight);
29874
29913
  const rotationOriginX = contentLeft + contentWidth / 2;
29875
29914
  context.save();
29876
- context.translate(rotationOriginX, textY);
29915
+ context.translate(rotationOriginX, alignedTextY);
29877
29916
  context.rotate(cellData.textRotationDeg * Math.PI / 180);
29878
29917
  context.fillText(
29879
29918
  rawText,
@@ -29896,7 +29935,7 @@ function useXlsxViewerThumbnails(options = {}) {
29896
29935
  });
29897
29936
  } else {
29898
29937
  const text = canvasCellStyle.textOverflowEllipsis ? truncateCanvasText(context, rawText, maxTextWidth) : rawText;
29899
- context.fillText(text, textX, textY);
29938
+ context.fillText(text, textX, resolveCanvasTextMiddleY(cellData.style.verticalAlign, contentTop, contentHeight, singleLineHeight));
29900
29939
  }
29901
29940
  }
29902
29941
  if (cellData.conditionalIcon) {