@extend-ai/react-xlsx 0.3.0 → 0.5.0
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 +42 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +42 -16
- package/dist/index.js.map +1 -1
- package/dist/xlsx-worker.js +7 -7
- package/dist/xlsx-worker.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -5961,11 +5961,14 @@ var XlsxWorkerClient = class {
|
|
|
5961
5961
|
}
|
|
5962
5962
|
this.pendingRequests.clear();
|
|
5963
5963
|
}
|
|
5964
|
-
loadWorkbook(buffer) {
|
|
5964
|
+
loadWorkbook(buffer, skipXmlParsing = false) {
|
|
5965
5965
|
const workerBuffer = cloneArrayBufferForTransfer(buffer);
|
|
5966
5966
|
return this.request({
|
|
5967
5967
|
id: 0,
|
|
5968
|
-
payload: {
|
|
5968
|
+
payload: {
|
|
5969
|
+
buffer: workerBuffer,
|
|
5970
|
+
skipXmlParsing
|
|
5971
|
+
},
|
|
5969
5972
|
type: "load"
|
|
5970
5973
|
}, [workerBuffer]);
|
|
5971
5974
|
}
|
|
@@ -5976,11 +5979,14 @@ var XlsxWorkerClient = class {
|
|
|
5976
5979
|
type: "getCellSnapshot"
|
|
5977
5980
|
});
|
|
5978
5981
|
}
|
|
5979
|
-
parseCharts(buffer) {
|
|
5982
|
+
parseCharts(buffer, skipXmlParsing = false) {
|
|
5980
5983
|
const workerBuffer = cloneArrayBufferForTransfer(buffer);
|
|
5981
5984
|
return this.request({
|
|
5982
5985
|
id: 0,
|
|
5983
|
-
payload: {
|
|
5986
|
+
payload: {
|
|
5987
|
+
buffer: workerBuffer,
|
|
5988
|
+
skipXmlParsing
|
|
5989
|
+
},
|
|
5984
5990
|
type: "parseCharts"
|
|
5985
5991
|
}, [workerBuffer]);
|
|
5986
5992
|
}
|
|
@@ -7131,8 +7137,8 @@ function createBasicWorkbookAssets(workbook) {
|
|
|
7131
7137
|
themePalette: { colorsByIndex: {} }
|
|
7132
7138
|
};
|
|
7133
7139
|
}
|
|
7134
|
-
function loadWorkbookImageAssets(bytes, workbook) {
|
|
7135
|
-
if (!isZipWorkbook(bytes)) {
|
|
7140
|
+
function loadWorkbookImageAssets(bytes, workbook, skipXmlParsing = false) {
|
|
7141
|
+
if (skipXmlParsing || !isZipWorkbook(bytes)) {
|
|
7136
7142
|
return createBasicWorkbookAssets(workbook);
|
|
7137
7143
|
}
|
|
7138
7144
|
const parsedAssets = parseWorkbookImageAssets(bytes);
|
|
@@ -7202,6 +7208,7 @@ function useXlsxViewerController(options) {
|
|
|
7202
7208
|
maxFileSizeBytes = DEFAULT_MAX_FILE_SIZE_BYTES,
|
|
7203
7209
|
readOnly: requestedReadOnly = false,
|
|
7204
7210
|
readOnlyAboveBytes = 0,
|
|
7211
|
+
skipXmlParsing = false,
|
|
7205
7212
|
src,
|
|
7206
7213
|
useWorker = true
|
|
7207
7214
|
} = options;
|
|
@@ -7335,6 +7342,9 @@ function useXlsxViewerController(options) {
|
|
|
7335
7342
|
const visibleSheetIndexByWorkbookSheetIndex2 = buildVisibleSheetIndexMap(targetSheets);
|
|
7336
7343
|
const quickAssets = loadWorkbookChartAssets(targetWorkbook, null, visibleSheetIndexByWorkbookSheetIndex2);
|
|
7337
7344
|
setChartAssets(quickAssets);
|
|
7345
|
+
if (skipXmlParsing) {
|
|
7346
|
+
return;
|
|
7347
|
+
}
|
|
7338
7348
|
const hasCharts = quickAssets.chartsByWorkbookSheetIndex.some((sheetCharts) => sheetCharts.length > 0);
|
|
7339
7349
|
if (!hasCharts) {
|
|
7340
7350
|
setIsChartsLoading(false);
|
|
@@ -7396,7 +7406,7 @@ function useXlsxViewerController(options) {
|
|
|
7396
7406
|
runMainThreadFallback();
|
|
7397
7407
|
return;
|
|
7398
7408
|
}
|
|
7399
|
-
void getWorkerClient().parseCharts(buffer).then((result) => {
|
|
7409
|
+
void getWorkerClient().parseCharts(buffer, skipXmlParsing).then((result) => {
|
|
7400
7410
|
if (workerTimeoutHandle !== null) {
|
|
7401
7411
|
window.clearTimeout(workerTimeoutHandle);
|
|
7402
7412
|
}
|
|
@@ -7421,15 +7431,15 @@ function useXlsxViewerController(options) {
|
|
|
7421
7431
|
}
|
|
7422
7432
|
triggerFallback();
|
|
7423
7433
|
});
|
|
7424
|
-
}, [getWorkerClient, hasIncompleteWorkerChartSnapshot, setChartAssets, workerSupported]);
|
|
7434
|
+
}, [getWorkerClient, hasIncompleteWorkerChartSnapshot, setChartAssets, skipXmlParsing, workerSupported]);
|
|
7425
7435
|
const loadWorkbookOnMainThread = React.useCallback(async (buffer) => {
|
|
7426
7436
|
const nextParsedWorkbook = await parseWorkbookBuffer(buffer);
|
|
7427
|
-
const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(buffer), nextParsedWorkbook.workbook);
|
|
7437
|
+
const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(buffer), nextParsedWorkbook.workbook, skipXmlParsing);
|
|
7428
7438
|
return {
|
|
7429
7439
|
imageAssets: nextImageAssets,
|
|
7430
7440
|
parsedWorkbook: nextParsedWorkbook
|
|
7431
7441
|
};
|
|
7432
|
-
}, []);
|
|
7442
|
+
}, [skipXmlParsing]);
|
|
7433
7443
|
const refreshWorkbookState = React.useCallback((targetWorkbook) => {
|
|
7434
7444
|
const nextSheets = buildSheetList(
|
|
7435
7445
|
targetWorkbook,
|
|
@@ -7540,11 +7550,11 @@ function useXlsxViewerController(options) {
|
|
|
7540
7550
|
}
|
|
7541
7551
|
if (shouldUseWorkerForLoad) {
|
|
7542
7552
|
try {
|
|
7543
|
-
const snapshot = await getWorkerClient().loadWorkbook(buffer);
|
|
7553
|
+
const snapshot = await getWorkerClient().loadWorkbook(buffer, skipXmlParsing);
|
|
7544
7554
|
if (!isCurrent || abortController.signal.aborted) {
|
|
7545
7555
|
return;
|
|
7546
7556
|
}
|
|
7547
|
-
if (hasIncompleteWorkerChartSnapshot(snapshot)) {
|
|
7557
|
+
if (!skipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
|
|
7548
7558
|
throw new Error("Worker chart payload incomplete");
|
|
7549
7559
|
}
|
|
7550
7560
|
setWorkbook(null);
|
|
@@ -7757,8 +7767,8 @@ function useXlsxViewerController(options) {
|
|
|
7757
7767
|
setForcedReadOnly(shouldForceReadOnly);
|
|
7758
7768
|
const shouldUseWorkerForLoad = workerSupported && (requestedReadOnly || shouldForceReadOnly);
|
|
7759
7769
|
if (shouldUseWorkerForLoad) {
|
|
7760
|
-
void getWorkerClient().loadWorkbook(deferredBuffer).then((snapshot) => {
|
|
7761
|
-
if (hasIncompleteWorkerChartSnapshot(snapshot)) {
|
|
7770
|
+
void getWorkerClient().loadWorkbook(deferredBuffer, skipXmlParsing).then((snapshot) => {
|
|
7771
|
+
if (!skipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
|
|
7762
7772
|
throw new Error("Worker chart payload incomplete");
|
|
7763
7773
|
}
|
|
7764
7774
|
deferredBufferRef.current = null;
|
|
@@ -7820,7 +7830,7 @@ function useXlsxViewerController(options) {
|
|
|
7820
7830
|
return;
|
|
7821
7831
|
}
|
|
7822
7832
|
void parseWorkbookBuffer(deferredBuffer).then((nextParsedWorkbook) => {
|
|
7823
|
-
const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(deferredBuffer), nextParsedWorkbook.workbook);
|
|
7833
|
+
const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(deferredBuffer), nextParsedWorkbook.workbook, skipXmlParsing);
|
|
7824
7834
|
deferredBufferRef.current = null;
|
|
7825
7835
|
setDeferredLoadFileSize(null);
|
|
7826
7836
|
setImageAssets(nextImageAssets);
|
|
@@ -18536,6 +18546,12 @@ function renderFileTooLarge(fileTooLargeState, renderProps, palette) {
|
|
|
18536
18546
|
}
|
|
18537
18547
|
return defaultNode;
|
|
18538
18548
|
}
|
|
18549
|
+
function renderCustomFileTooLarge(fileTooLargeState, renderProps, palette) {
|
|
18550
|
+
if (fileTooLargeState === void 0) {
|
|
18551
|
+
return void 0;
|
|
18552
|
+
}
|
|
18553
|
+
return renderFileTooLarge(fileTooLargeState, renderProps, palette);
|
|
18554
|
+
}
|
|
18539
18555
|
function renderDefaultChartLoadingCard(rect) {
|
|
18540
18556
|
const bars = [18, 32, 24];
|
|
18541
18557
|
const barWidth = Math.max(8, Math.min(12, Math.round(rect.width * 0.018)));
|
|
@@ -22864,7 +22880,17 @@ function XlsxViewerInner({
|
|
|
22864
22880
|
toolbar
|
|
22865
22881
|
}) {
|
|
22866
22882
|
const palette = useViewerPalette(isDark);
|
|
22867
|
-
|
|
22883
|
+
const { displayFileName, error } = controller;
|
|
22884
|
+
const customFileTooLarge = error instanceof XlsxFileSizeLimitExceededError ? renderCustomFileTooLarge(
|
|
22885
|
+
fileTooLargeState,
|
|
22886
|
+
{
|
|
22887
|
+
displayFileName,
|
|
22888
|
+
fileSizeBytes: error.fileSizeBytes,
|
|
22889
|
+
maxFileSizeBytes: error.maxFileSizeBytes
|
|
22890
|
+
},
|
|
22891
|
+
palette
|
|
22892
|
+
) : void 0;
|
|
22893
|
+
return /* @__PURE__ */ jsx3(ViewerAppearanceContext.Provider, { value: { isDark }, children: /* @__PURE__ */ jsx3(ViewerContext.Provider, { value: controller, children: customFileTooLarge !== void 0 ? customFileTooLarge : /* @__PURE__ */ jsxs3(
|
|
22868
22894
|
"div",
|
|
22869
22895
|
{
|
|
22870
22896
|
className: classNames("react-xlsx-viewer", className),
|