@extend-ai/react-xlsx 0.13.2 → 0.13.3

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
@@ -8101,8 +8101,9 @@ function useXlsxViewerController(options) {
8101
8101
  const readOnly = requestedReadOnly || forcedReadOnly;
8102
8102
  const canResizeReadOnly = requestedReadOnly && allowResizeInReadOnly && !forcedReadOnly;
8103
8103
  const workerSupported = useWorker && typeof Worker !== "undefined" && canUseConfiguredWasmSourceInWorker();
8104
- const shouldUseWorker = workerSupported && forcedReadOnly;
8104
+ const canUseWorkerForRequestedReadOnly = requestedReadOnly;
8105
8105
  const shouldForceReadOnlyForBuffer = React.useCallback((bufferByteLength) => !requestedReadOnly && readOnlyAboveBytes > 0 && bufferByteLength > readOnlyAboveBytes, [readOnlyAboveBytes, requestedReadOnly]);
8106
+ const shouldUseWorkerForReadOnlyLoad = React.useCallback((willForceReadOnly) => workerSupported && (willForceReadOnly || canUseWorkerForRequestedReadOnly), [canUseWorkerForRequestedReadOnly, workerSupported]);
8106
8107
  const disposeWorkerClient = React.useCallback(() => {
8107
8108
  workerClientRef.current?.dispose();
8108
8109
  workerClientRef.current = null;
@@ -8153,9 +8154,6 @@ function useXlsxViewerController(options) {
8153
8154
  const hasIncompleteWorkerChartSnapshot = React.useCallback((snapshot) => {
8154
8155
  for (const sheetCharts of snapshot.chartsByWorkbookSheetIndex) {
8155
8156
  for (const chart of sheetCharts) {
8156
- if (!chart.chartPath) {
8157
- return true;
8158
- }
8159
8157
  if (chart.chartType !== "Bubble") {
8160
8158
  continue;
8161
8159
  }
@@ -8402,7 +8400,7 @@ function useXlsxViewerController(options) {
8402
8400
  }
8403
8401
  const shouldForceReadOnly = shouldForceReadOnlyForBuffer(buffer.byteLength);
8404
8402
  setForcedReadOnly(shouldForceReadOnly);
8405
- const shouldUseWorkerForLoad = workerSupported && shouldForceReadOnly;
8403
+ const shouldUseWorkerForLoad = shouldUseWorkerForReadOnlyLoad(shouldForceReadOnly);
8406
8404
  const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(buffer), skipXmlParsing);
8407
8405
  if (shouldDeferLoading && buffer.byteLength > deferLoadingAboveBytes) {
8408
8406
  deferredBufferRef.current = buffer;
@@ -8499,13 +8497,12 @@ function useXlsxViewerController(options) {
8499
8497
  hasIncompleteWorkerChartSnapshot,
8500
8498
  loadWorkbookOnMainThread,
8501
8499
  maxFileSizeBytes,
8502
- requestedReadOnly,
8503
8500
  setImageAssets,
8504
8501
  startChartDisplayHydration,
8505
8502
  shouldFallbackFromWorkerError,
8506
8503
  shouldDeferLoading,
8507
8504
  shouldForceReadOnlyForBuffer,
8508
- workerSupported,
8505
+ shouldUseWorkerForReadOnlyLoad,
8509
8506
  src,
8510
8507
  showHiddenSheets
8511
8508
  ]);
@@ -8634,7 +8631,7 @@ function useXlsxViewerController(options) {
8634
8631
  }
8635
8632
  const shouldForceReadOnly = shouldForceReadOnlyForBuffer(deferredBuffer.byteLength);
8636
8633
  setForcedReadOnly(shouldForceReadOnly);
8637
- const shouldUseWorkerForLoad = workerSupported && shouldForceReadOnly;
8634
+ const shouldUseWorkerForLoad = shouldUseWorkerForReadOnlyLoad(shouldForceReadOnly);
8638
8635
  const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(deferredBuffer), skipXmlParsing);
8639
8636
  if (shouldUseWorkerForLoad) {
8640
8637
  void getWorkerClient().loadWorkbook(deferredBuffer, effectiveSkipXmlParsing, showHiddenSheets).then((snapshot) => {
@@ -8747,14 +8744,13 @@ function useXlsxViewerController(options) {
8747
8744
  disposeWorkerClient,
8748
8745
  getWorkerClient,
8749
8746
  loadWorkbookOnMainThread,
8750
- requestedReadOnly,
8751
8747
  setImageAssets,
8752
8748
  startChartDisplayHydration,
8753
8749
  hasIncompleteWorkerChartSnapshot,
8754
8750
  maxFileSizeBytes,
8755
8751
  shouldFallbackFromWorkerError,
8756
8752
  shouldForceReadOnlyForBuffer,
8757
- workerSupported
8753
+ shouldUseWorkerForReadOnlyLoad
8758
8754
  ]);
8759
8755
  const maybeRecalculateWorkbook = React.useCallback((targetWorkbook) => {
8760
8756
  if (!shouldAutoCalculate) {
@@ -9468,8 +9464,58 @@ function useXlsxViewerController(options) {
9468
9464
  }
9469
9465
  setShouldAutoCalculate(false);
9470
9466
  }, [refreshWorkbookState, workbook]);
9467
+ const applyReadOnlyResizeOverride = React.useCallback((axis, actualIndex, sizePx) => {
9468
+ if (!activeSheet) {
9469
+ return;
9470
+ }
9471
+ const contentSizePx = resolveContentSheetAxisPixels(sizePx, activeSheet.showGridLines);
9472
+ const targetWorkbookSheetIndex = activeSheet.workbookSheetIndex;
9473
+ setSheets((currentSheets) => currentSheets.map((sheet) => {
9474
+ if (sheet.workbookSheetIndex !== targetWorkbookSheetIndex) {
9475
+ return sheet;
9476
+ }
9477
+ if (axis === "column") {
9478
+ const nextColWidthOverridesPx = {
9479
+ ...sheet.colWidthOverridesPx,
9480
+ [actualIndex]: contentSizePx
9481
+ };
9482
+ const nextColWidths = [...sheet.colWidths];
9483
+ const visibleColIndex = sheet.visibleCols.indexOf(actualIndex);
9484
+ if (visibleColIndex >= 0) {
9485
+ nextColWidths[visibleColIndex] = contentSizePx;
9486
+ }
9487
+ return {
9488
+ ...sheet,
9489
+ colWidthOverridesPx: nextColWidthOverridesPx,
9490
+ colWidths: nextColWidths
9491
+ };
9492
+ }
9493
+ const nextRowHeightOverridesPx = {
9494
+ ...sheet.rowHeightOverridesPx,
9495
+ [actualIndex]: contentSizePx
9496
+ };
9497
+ const nextRowHeights = [...sheet.rowHeights];
9498
+ const visibleRowIndex = sheet.visibleRows.indexOf(actualIndex);
9499
+ if (visibleRowIndex >= 0) {
9500
+ nextRowHeights[visibleRowIndex] = contentSizePx;
9501
+ }
9502
+ return {
9503
+ ...sheet,
9504
+ rowHeightOverridesPx: nextRowHeightOverridesPx,
9505
+ rowHeights: nextRowHeights
9506
+ };
9507
+ }));
9508
+ setRevision((current) => current + 1);
9509
+ }, [activeSheet]);
9471
9510
  const resizeColumn = React.useCallback((col, widthPx) => {
9472
- if (readOnly && !canResizeReadOnly || !workbook || !activeSheet) {
9511
+ if (readOnly && !canResizeReadOnly || !activeSheet) {
9512
+ return;
9513
+ }
9514
+ if (isWorkerBacked) {
9515
+ applyReadOnlyResizeOverride("column", col, widthPx);
9516
+ return;
9517
+ }
9518
+ if (!workbook) {
9473
9519
  return;
9474
9520
  }
9475
9521
  recordHistoryBeforeMutation();
@@ -9479,9 +9525,25 @@ function useXlsxViewerController(options) {
9479
9525
  pxToSheetColumnWidth(resolveContentSheetAxisPixels(widthPx, activeSheet.showGridLines))
9480
9526
  );
9481
9527
  refreshWorkbookState(workbook);
9482
- }, [activeSheet, canResizeReadOnly, readOnly, recordHistoryBeforeMutation, refreshWorkbookState, workbook]);
9528
+ }, [
9529
+ activeSheet,
9530
+ applyReadOnlyResizeOverride,
9531
+ canResizeReadOnly,
9532
+ isWorkerBacked,
9533
+ readOnly,
9534
+ recordHistoryBeforeMutation,
9535
+ refreshWorkbookState,
9536
+ workbook
9537
+ ]);
9483
9538
  const resizeRow = React.useCallback((row, heightPx) => {
9484
- if (readOnly && !canResizeReadOnly || !workbook || !activeSheet) {
9539
+ if (readOnly && !canResizeReadOnly || !activeSheet) {
9540
+ return;
9541
+ }
9542
+ if (isWorkerBacked) {
9543
+ applyReadOnlyResizeOverride("row", row, heightPx);
9544
+ return;
9545
+ }
9546
+ if (!workbook) {
9485
9547
  return;
9486
9548
  }
9487
9549
  recordHistoryBeforeMutation();
@@ -9491,7 +9553,16 @@ function useXlsxViewerController(options) {
9491
9553
  pxToSheetRowHeight(resolveContentSheetAxisPixels(heightPx, activeSheet.showGridLines))
9492
9554
  );
9493
9555
  refreshWorkbookState(workbook);
9494
- }, [activeSheet, canResizeReadOnly, readOnly, recordHistoryBeforeMutation, refreshWorkbookState, workbook]);
9556
+ }, [
9557
+ activeSheet,
9558
+ applyReadOnlyResizeOverride,
9559
+ canResizeReadOnly,
9560
+ isWorkerBacked,
9561
+ readOnly,
9562
+ recordHistoryBeforeMutation,
9563
+ refreshWorkbookState,
9564
+ workbook
9565
+ ]);
9495
9566
  const resolveAnchoredObjectRect = React.useCallback((anchor, worksheet) => {
9496
9567
  const resolveAxisSum = (index, getSize) => {
9497
9568
  let total = 0;
@@ -23059,12 +23130,16 @@ function XlsxGrid({
23059
23130
  continue;
23060
23131
  }
23061
23132
  widths[col] = Math.max(
23062
- resolveRenderedSheetAxisPixels(precomputedWidths[index] ?? activeSheet?.defaultColWidthPx ?? DEFAULT_COL_WIDTH2, showGridLines),
23133
+ resolveRenderedSheetAxisPixels(
23134
+ activeSheet?.colWidthOverridesPx[col] ?? precomputedWidths[index] ?? activeSheet?.defaultColWidthPx ?? DEFAULT_COL_WIDTH2,
23135
+ showGridLines
23136
+ ),
23063
23137
  DEFAULT_COL_WIDTH2 / 2
23064
23138
  );
23065
23139
  }
23066
23140
  for (let col = Math.max(0, (activeSheet?.maxUsedCol ?? -1) + 1); col < displayColLimit; col += 1) {
23067
- widths[col] = fallbackWidth;
23141
+ const overrideWidth = activeSheet?.colWidthOverridesPx[col];
23142
+ widths[col] = overrideWidth === void 0 ? fallbackWidth : Math.max(resolveRenderedSheetAxisPixels(overrideWidth, showGridLines), DEFAULT_COL_WIDTH2 / 2);
23068
23143
  }
23069
23144
  return widths;
23070
23145
  },
@@ -23156,12 +23231,16 @@ function XlsxGrid({
23156
23231
  continue;
23157
23232
  }
23158
23233
  heights[row] = Math.max(
23159
- resolveRenderedSheetAxisPixels(precomputedHeights[index] ?? activeSheet?.defaultRowHeightPx ?? DEFAULT_ROW_HEIGHT2, showGridLines),
23234
+ resolveRenderedSheetAxisPixels(
23235
+ activeSheet?.rowHeightOverridesPx[row] ?? precomputedHeights[index] ?? activeSheet?.defaultRowHeightPx ?? DEFAULT_ROW_HEIGHT2,
23236
+ showGridLines
23237
+ ),
23160
23238
  DEFAULT_ROW_HEIGHT2 / 1.5
23161
23239
  );
23162
23240
  }
23163
23241
  for (let row = Math.max(0, (activeSheet?.maxUsedRow ?? -1) + 1); row < displayRowLimit; row += 1) {
23164
- heights[row] = fallbackHeight;
23242
+ const overrideHeight = activeSheet?.rowHeightOverridesPx[row];
23243
+ heights[row] = overrideHeight === void 0 ? fallbackHeight : Math.max(resolveRenderedSheetAxisPixels(overrideHeight, showGridLines), DEFAULT_ROW_HEIGHT2 / 1.5);
23165
23244
  }
23166
23245
  return heights;
23167
23246
  },
@@ -24315,8 +24394,25 @@ function XlsxGrid({
24315
24394
  const [, startSelectionTransition] = React4.useTransition();
24316
24395
  const [asyncViewportRowBatch, setAsyncViewportRowBatch] = React4.useState(null);
24317
24396
  const viewportRequest = React4.useMemo(() => {
24318
- const firstVirtualRowIndex = domExpandedWindow.rowIndices[0];
24319
- const lastVirtualRowIndex = domExpandedWindow.rowIndices[domExpandedWindow.rowIndices.length - 1];
24397
+ const rowIndices = experimentalCanvas ? (() => {
24398
+ if (visibleRows.length === 0 || drawingViewport.height <= 0) {
24399
+ return [];
24400
+ }
24401
+ const indices = new Set(frozenRowVirtualIndices);
24402
+ const viewportStart = Math.max(0, drawingViewport.top - displayHeaderHeight - CANVAS_VIEWPORT_OVERSCAN_PX);
24403
+ const viewportEnd = Math.max(
24404
+ viewportStart,
24405
+ drawingViewport.top + drawingViewport.height - displayHeaderHeight + CANVAS_VIEWPORT_OVERSCAN_PX
24406
+ );
24407
+ const startIndex = findIndexForOffsetPrefix(rowPrefixSums, viewportStart);
24408
+ const endIndex = findIndexForOffsetPrefix(rowPrefixSums, viewportEnd);
24409
+ for (let index = Math.max(0, startIndex); index <= Math.max(startIndex, endIndex); index += 1) {
24410
+ indices.add(index);
24411
+ }
24412
+ return Array.from(indices).sort((left, right) => left - right);
24413
+ })() : domExpandedWindow.rowIndices;
24414
+ const firstVirtualRowIndex = rowIndices[0];
24415
+ const lastVirtualRowIndex = rowIndices[rowIndices.length - 1];
24320
24416
  const firstVisibleRow2 = firstVirtualRowIndex === void 0 ? void 0 : visibleRows[firstVirtualRowIndex];
24321
24417
  const lastVisibleRow2 = lastVirtualRowIndex === void 0 ? void 0 : visibleRows[lastVirtualRowIndex];
24322
24418
  if (firstVisibleRow2 === void 0 || lastVisibleRow2 === void 0 || lastVisibleRow2 < firstVisibleRow2) {
@@ -24329,7 +24425,16 @@ function XlsxGrid({
24329
24425
  endRow,
24330
24426
  startRow
24331
24427
  };
24332
- }, [domExpandedWindow.rowIndices, visibleRows]);
24428
+ }, [
24429
+ displayHeaderHeight,
24430
+ domExpandedWindow.rowIndices,
24431
+ drawingViewport.height,
24432
+ drawingViewport.top,
24433
+ experimentalCanvas,
24434
+ frozenRowVirtualIndices,
24435
+ rowPrefixSums,
24436
+ visibleRows
24437
+ ]);
24333
24438
  const syncViewportRowBatch = React4.useMemo(() => {
24334
24439
  if (!shouldVirtualizeRows || !worksheet || getRowsBatchAsync || !viewportRequest) {
24335
24440
  return null;