@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 +126 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +126 -21
- package/dist/index.js.map +1 -1
- package/dist/xlsx-worker.js +108 -38
- package/dist/xlsx-worker.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8050,8 +8050,9 @@ function useXlsxViewerController(options) {
|
|
|
8050
8050
|
const readOnly = requestedReadOnly || forcedReadOnly;
|
|
8051
8051
|
const canResizeReadOnly = requestedReadOnly && allowResizeInReadOnly && !forcedReadOnly;
|
|
8052
8052
|
const workerSupported = useWorker && typeof Worker !== "undefined" && canUseConfiguredWasmSourceInWorker();
|
|
8053
|
-
const
|
|
8053
|
+
const canUseWorkerForRequestedReadOnly = requestedReadOnly;
|
|
8054
8054
|
const shouldForceReadOnlyForBuffer = React.useCallback((bufferByteLength) => !requestedReadOnly && readOnlyAboveBytes > 0 && bufferByteLength > readOnlyAboveBytes, [readOnlyAboveBytes, requestedReadOnly]);
|
|
8055
|
+
const shouldUseWorkerForReadOnlyLoad = React.useCallback((willForceReadOnly) => workerSupported && (willForceReadOnly || canUseWorkerForRequestedReadOnly), [canUseWorkerForRequestedReadOnly, workerSupported]);
|
|
8055
8056
|
const disposeWorkerClient = React.useCallback(() => {
|
|
8056
8057
|
workerClientRef.current?.dispose();
|
|
8057
8058
|
workerClientRef.current = null;
|
|
@@ -8102,9 +8103,6 @@ function useXlsxViewerController(options) {
|
|
|
8102
8103
|
const hasIncompleteWorkerChartSnapshot = React.useCallback((snapshot) => {
|
|
8103
8104
|
for (const sheetCharts of snapshot.chartsByWorkbookSheetIndex) {
|
|
8104
8105
|
for (const chart of sheetCharts) {
|
|
8105
|
-
if (!chart.chartPath) {
|
|
8106
|
-
return true;
|
|
8107
|
-
}
|
|
8108
8106
|
if (chart.chartType !== "Bubble") {
|
|
8109
8107
|
continue;
|
|
8110
8108
|
}
|
|
@@ -8351,7 +8349,7 @@ function useXlsxViewerController(options) {
|
|
|
8351
8349
|
}
|
|
8352
8350
|
const shouldForceReadOnly = shouldForceReadOnlyForBuffer(buffer.byteLength);
|
|
8353
8351
|
setForcedReadOnly(shouldForceReadOnly);
|
|
8354
|
-
const shouldUseWorkerForLoad =
|
|
8352
|
+
const shouldUseWorkerForLoad = shouldUseWorkerForReadOnlyLoad(shouldForceReadOnly);
|
|
8355
8353
|
const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(buffer), skipXmlParsing);
|
|
8356
8354
|
if (shouldDeferLoading && buffer.byteLength > deferLoadingAboveBytes) {
|
|
8357
8355
|
deferredBufferRef.current = buffer;
|
|
@@ -8448,13 +8446,12 @@ function useXlsxViewerController(options) {
|
|
|
8448
8446
|
hasIncompleteWorkerChartSnapshot,
|
|
8449
8447
|
loadWorkbookOnMainThread,
|
|
8450
8448
|
maxFileSizeBytes,
|
|
8451
|
-
requestedReadOnly,
|
|
8452
8449
|
setImageAssets,
|
|
8453
8450
|
startChartDisplayHydration,
|
|
8454
8451
|
shouldFallbackFromWorkerError,
|
|
8455
8452
|
shouldDeferLoading,
|
|
8456
8453
|
shouldForceReadOnlyForBuffer,
|
|
8457
|
-
|
|
8454
|
+
shouldUseWorkerForReadOnlyLoad,
|
|
8458
8455
|
src,
|
|
8459
8456
|
showHiddenSheets
|
|
8460
8457
|
]);
|
|
@@ -8583,7 +8580,7 @@ function useXlsxViewerController(options) {
|
|
|
8583
8580
|
}
|
|
8584
8581
|
const shouldForceReadOnly = shouldForceReadOnlyForBuffer(deferredBuffer.byteLength);
|
|
8585
8582
|
setForcedReadOnly(shouldForceReadOnly);
|
|
8586
|
-
const shouldUseWorkerForLoad =
|
|
8583
|
+
const shouldUseWorkerForLoad = shouldUseWorkerForReadOnlyLoad(shouldForceReadOnly);
|
|
8587
8584
|
const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(deferredBuffer), skipXmlParsing);
|
|
8588
8585
|
if (shouldUseWorkerForLoad) {
|
|
8589
8586
|
void getWorkerClient().loadWorkbook(deferredBuffer, effectiveSkipXmlParsing, showHiddenSheets).then((snapshot) => {
|
|
@@ -8696,14 +8693,13 @@ function useXlsxViewerController(options) {
|
|
|
8696
8693
|
disposeWorkerClient,
|
|
8697
8694
|
getWorkerClient,
|
|
8698
8695
|
loadWorkbookOnMainThread,
|
|
8699
|
-
requestedReadOnly,
|
|
8700
8696
|
setImageAssets,
|
|
8701
8697
|
startChartDisplayHydration,
|
|
8702
8698
|
hasIncompleteWorkerChartSnapshot,
|
|
8703
8699
|
maxFileSizeBytes,
|
|
8704
8700
|
shouldFallbackFromWorkerError,
|
|
8705
8701
|
shouldForceReadOnlyForBuffer,
|
|
8706
|
-
|
|
8702
|
+
shouldUseWorkerForReadOnlyLoad
|
|
8707
8703
|
]);
|
|
8708
8704
|
const maybeRecalculateWorkbook = React.useCallback((targetWorkbook) => {
|
|
8709
8705
|
if (!shouldAutoCalculate) {
|
|
@@ -9417,8 +9413,58 @@ function useXlsxViewerController(options) {
|
|
|
9417
9413
|
}
|
|
9418
9414
|
setShouldAutoCalculate(false);
|
|
9419
9415
|
}, [refreshWorkbookState, workbook]);
|
|
9416
|
+
const applyReadOnlyResizeOverride = React.useCallback((axis, actualIndex, sizePx) => {
|
|
9417
|
+
if (!activeSheet) {
|
|
9418
|
+
return;
|
|
9419
|
+
}
|
|
9420
|
+
const contentSizePx = resolveContentSheetAxisPixels(sizePx, activeSheet.showGridLines);
|
|
9421
|
+
const targetWorkbookSheetIndex = activeSheet.workbookSheetIndex;
|
|
9422
|
+
setSheets((currentSheets) => currentSheets.map((sheet) => {
|
|
9423
|
+
if (sheet.workbookSheetIndex !== targetWorkbookSheetIndex) {
|
|
9424
|
+
return sheet;
|
|
9425
|
+
}
|
|
9426
|
+
if (axis === "column") {
|
|
9427
|
+
const nextColWidthOverridesPx = {
|
|
9428
|
+
...sheet.colWidthOverridesPx,
|
|
9429
|
+
[actualIndex]: contentSizePx
|
|
9430
|
+
};
|
|
9431
|
+
const nextColWidths = [...sheet.colWidths];
|
|
9432
|
+
const visibleColIndex = sheet.visibleCols.indexOf(actualIndex);
|
|
9433
|
+
if (visibleColIndex >= 0) {
|
|
9434
|
+
nextColWidths[visibleColIndex] = contentSizePx;
|
|
9435
|
+
}
|
|
9436
|
+
return {
|
|
9437
|
+
...sheet,
|
|
9438
|
+
colWidthOverridesPx: nextColWidthOverridesPx,
|
|
9439
|
+
colWidths: nextColWidths
|
|
9440
|
+
};
|
|
9441
|
+
}
|
|
9442
|
+
const nextRowHeightOverridesPx = {
|
|
9443
|
+
...sheet.rowHeightOverridesPx,
|
|
9444
|
+
[actualIndex]: contentSizePx
|
|
9445
|
+
};
|
|
9446
|
+
const nextRowHeights = [...sheet.rowHeights];
|
|
9447
|
+
const visibleRowIndex = sheet.visibleRows.indexOf(actualIndex);
|
|
9448
|
+
if (visibleRowIndex >= 0) {
|
|
9449
|
+
nextRowHeights[visibleRowIndex] = contentSizePx;
|
|
9450
|
+
}
|
|
9451
|
+
return {
|
|
9452
|
+
...sheet,
|
|
9453
|
+
rowHeightOverridesPx: nextRowHeightOverridesPx,
|
|
9454
|
+
rowHeights: nextRowHeights
|
|
9455
|
+
};
|
|
9456
|
+
}));
|
|
9457
|
+
setRevision((current) => current + 1);
|
|
9458
|
+
}, [activeSheet]);
|
|
9420
9459
|
const resizeColumn = React.useCallback((col, widthPx) => {
|
|
9421
|
-
if (readOnly && !canResizeReadOnly || !
|
|
9460
|
+
if (readOnly && !canResizeReadOnly || !activeSheet) {
|
|
9461
|
+
return;
|
|
9462
|
+
}
|
|
9463
|
+
if (isWorkerBacked) {
|
|
9464
|
+
applyReadOnlyResizeOverride("column", col, widthPx);
|
|
9465
|
+
return;
|
|
9466
|
+
}
|
|
9467
|
+
if (!workbook) {
|
|
9422
9468
|
return;
|
|
9423
9469
|
}
|
|
9424
9470
|
recordHistoryBeforeMutation();
|
|
@@ -9428,9 +9474,25 @@ function useXlsxViewerController(options) {
|
|
|
9428
9474
|
pxToSheetColumnWidth(resolveContentSheetAxisPixels(widthPx, activeSheet.showGridLines))
|
|
9429
9475
|
);
|
|
9430
9476
|
refreshWorkbookState(workbook);
|
|
9431
|
-
}, [
|
|
9477
|
+
}, [
|
|
9478
|
+
activeSheet,
|
|
9479
|
+
applyReadOnlyResizeOverride,
|
|
9480
|
+
canResizeReadOnly,
|
|
9481
|
+
isWorkerBacked,
|
|
9482
|
+
readOnly,
|
|
9483
|
+
recordHistoryBeforeMutation,
|
|
9484
|
+
refreshWorkbookState,
|
|
9485
|
+
workbook
|
|
9486
|
+
]);
|
|
9432
9487
|
const resizeRow = React.useCallback((row, heightPx) => {
|
|
9433
|
-
if (readOnly && !canResizeReadOnly || !
|
|
9488
|
+
if (readOnly && !canResizeReadOnly || !activeSheet) {
|
|
9489
|
+
return;
|
|
9490
|
+
}
|
|
9491
|
+
if (isWorkerBacked) {
|
|
9492
|
+
applyReadOnlyResizeOverride("row", row, heightPx);
|
|
9493
|
+
return;
|
|
9494
|
+
}
|
|
9495
|
+
if (!workbook) {
|
|
9434
9496
|
return;
|
|
9435
9497
|
}
|
|
9436
9498
|
recordHistoryBeforeMutation();
|
|
@@ -9440,7 +9502,16 @@ function useXlsxViewerController(options) {
|
|
|
9440
9502
|
pxToSheetRowHeight(resolveContentSheetAxisPixels(heightPx, activeSheet.showGridLines))
|
|
9441
9503
|
);
|
|
9442
9504
|
refreshWorkbookState(workbook);
|
|
9443
|
-
}, [
|
|
9505
|
+
}, [
|
|
9506
|
+
activeSheet,
|
|
9507
|
+
applyReadOnlyResizeOverride,
|
|
9508
|
+
canResizeReadOnly,
|
|
9509
|
+
isWorkerBacked,
|
|
9510
|
+
readOnly,
|
|
9511
|
+
recordHistoryBeforeMutation,
|
|
9512
|
+
refreshWorkbookState,
|
|
9513
|
+
workbook
|
|
9514
|
+
]);
|
|
9444
9515
|
const resolveAnchoredObjectRect = React.useCallback((anchor, worksheet) => {
|
|
9445
9516
|
const resolveAxisSum = (index, getSize) => {
|
|
9446
9517
|
let total = 0;
|
|
@@ -23025,12 +23096,16 @@ function XlsxGrid({
|
|
|
23025
23096
|
continue;
|
|
23026
23097
|
}
|
|
23027
23098
|
widths[col] = Math.max(
|
|
23028
|
-
resolveRenderedSheetAxisPixels(
|
|
23099
|
+
resolveRenderedSheetAxisPixels(
|
|
23100
|
+
activeSheet?.colWidthOverridesPx[col] ?? precomputedWidths[index] ?? activeSheet?.defaultColWidthPx ?? DEFAULT_COL_WIDTH2,
|
|
23101
|
+
showGridLines
|
|
23102
|
+
),
|
|
23029
23103
|
DEFAULT_COL_WIDTH2 / 2
|
|
23030
23104
|
);
|
|
23031
23105
|
}
|
|
23032
23106
|
for (let col = Math.max(0, (activeSheet?.maxUsedCol ?? -1) + 1); col < displayColLimit; col += 1) {
|
|
23033
|
-
|
|
23107
|
+
const overrideWidth = activeSheet?.colWidthOverridesPx[col];
|
|
23108
|
+
widths[col] = overrideWidth === void 0 ? fallbackWidth : Math.max(resolveRenderedSheetAxisPixels(overrideWidth, showGridLines), DEFAULT_COL_WIDTH2 / 2);
|
|
23034
23109
|
}
|
|
23035
23110
|
return widths;
|
|
23036
23111
|
},
|
|
@@ -23122,12 +23197,16 @@ function XlsxGrid({
|
|
|
23122
23197
|
continue;
|
|
23123
23198
|
}
|
|
23124
23199
|
heights[row] = Math.max(
|
|
23125
|
-
resolveRenderedSheetAxisPixels(
|
|
23200
|
+
resolveRenderedSheetAxisPixels(
|
|
23201
|
+
activeSheet?.rowHeightOverridesPx[row] ?? precomputedHeights[index] ?? activeSheet?.defaultRowHeightPx ?? DEFAULT_ROW_HEIGHT2,
|
|
23202
|
+
showGridLines
|
|
23203
|
+
),
|
|
23126
23204
|
DEFAULT_ROW_HEIGHT2 / 1.5
|
|
23127
23205
|
);
|
|
23128
23206
|
}
|
|
23129
23207
|
for (let row = Math.max(0, (activeSheet?.maxUsedRow ?? -1) + 1); row < displayRowLimit; row += 1) {
|
|
23130
|
-
|
|
23208
|
+
const overrideHeight = activeSheet?.rowHeightOverridesPx[row];
|
|
23209
|
+
heights[row] = overrideHeight === void 0 ? fallbackHeight : Math.max(resolveRenderedSheetAxisPixels(overrideHeight, showGridLines), DEFAULT_ROW_HEIGHT2 / 1.5);
|
|
23131
23210
|
}
|
|
23132
23211
|
return heights;
|
|
23133
23212
|
},
|
|
@@ -24281,8 +24360,25 @@ function XlsxGrid({
|
|
|
24281
24360
|
const [, startSelectionTransition] = React4.useTransition();
|
|
24282
24361
|
const [asyncViewportRowBatch, setAsyncViewportRowBatch] = React4.useState(null);
|
|
24283
24362
|
const viewportRequest = React4.useMemo(() => {
|
|
24284
|
-
const
|
|
24285
|
-
|
|
24363
|
+
const rowIndices = experimentalCanvas ? (() => {
|
|
24364
|
+
if (visibleRows.length === 0 || drawingViewport.height <= 0) {
|
|
24365
|
+
return [];
|
|
24366
|
+
}
|
|
24367
|
+
const indices = new Set(frozenRowVirtualIndices);
|
|
24368
|
+
const viewportStart = Math.max(0, drawingViewport.top - displayHeaderHeight - CANVAS_VIEWPORT_OVERSCAN_PX);
|
|
24369
|
+
const viewportEnd = Math.max(
|
|
24370
|
+
viewportStart,
|
|
24371
|
+
drawingViewport.top + drawingViewport.height - displayHeaderHeight + CANVAS_VIEWPORT_OVERSCAN_PX
|
|
24372
|
+
);
|
|
24373
|
+
const startIndex = findIndexForOffsetPrefix(rowPrefixSums, viewportStart);
|
|
24374
|
+
const endIndex = findIndexForOffsetPrefix(rowPrefixSums, viewportEnd);
|
|
24375
|
+
for (let index = Math.max(0, startIndex); index <= Math.max(startIndex, endIndex); index += 1) {
|
|
24376
|
+
indices.add(index);
|
|
24377
|
+
}
|
|
24378
|
+
return Array.from(indices).sort((left, right) => left - right);
|
|
24379
|
+
})() : domExpandedWindow.rowIndices;
|
|
24380
|
+
const firstVirtualRowIndex = rowIndices[0];
|
|
24381
|
+
const lastVirtualRowIndex = rowIndices[rowIndices.length - 1];
|
|
24286
24382
|
const firstVisibleRow2 = firstVirtualRowIndex === void 0 ? void 0 : visibleRows[firstVirtualRowIndex];
|
|
24287
24383
|
const lastVisibleRow2 = lastVirtualRowIndex === void 0 ? void 0 : visibleRows[lastVirtualRowIndex];
|
|
24288
24384
|
if (firstVisibleRow2 === void 0 || lastVisibleRow2 === void 0 || lastVisibleRow2 < firstVisibleRow2) {
|
|
@@ -24295,7 +24391,16 @@ function XlsxGrid({
|
|
|
24295
24391
|
endRow,
|
|
24296
24392
|
startRow
|
|
24297
24393
|
};
|
|
24298
|
-
}, [
|
|
24394
|
+
}, [
|
|
24395
|
+
displayHeaderHeight,
|
|
24396
|
+
domExpandedWindow.rowIndices,
|
|
24397
|
+
drawingViewport.height,
|
|
24398
|
+
drawingViewport.top,
|
|
24399
|
+
experimentalCanvas,
|
|
24400
|
+
frozenRowVirtualIndices,
|
|
24401
|
+
rowPrefixSums,
|
|
24402
|
+
visibleRows
|
|
24403
|
+
]);
|
|
24299
24404
|
const syncViewportRowBatch = React4.useMemo(() => {
|
|
24300
24405
|
if (!shouldVirtualizeRows || !worksheet || getRowsBatchAsync || !viewportRequest) {
|
|
24301
24406
|
return null;
|