@extend-ai/react-xlsx 0.4.0 → 0.6.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 +44 -15
- 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 +44 -15
- package/dist/index.js.map +1 -1
- package/dist/xlsx-worker.js +15 -7
- package/dist/xlsx-worker.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6009,11 +6009,14 @@ var XlsxWorkerClient = class {
|
|
|
6009
6009
|
}
|
|
6010
6010
|
this.pendingRequests.clear();
|
|
6011
6011
|
}
|
|
6012
|
-
loadWorkbook(buffer) {
|
|
6012
|
+
loadWorkbook(buffer, skipXmlParsing = false) {
|
|
6013
6013
|
const workerBuffer = cloneArrayBufferForTransfer(buffer);
|
|
6014
6014
|
return this.request({
|
|
6015
6015
|
id: 0,
|
|
6016
|
-
payload: {
|
|
6016
|
+
payload: {
|
|
6017
|
+
buffer: workerBuffer,
|
|
6018
|
+
skipXmlParsing
|
|
6019
|
+
},
|
|
6017
6020
|
type: "load"
|
|
6018
6021
|
}, [workerBuffer]);
|
|
6019
6022
|
}
|
|
@@ -6024,11 +6027,14 @@ var XlsxWorkerClient = class {
|
|
|
6024
6027
|
type: "getCellSnapshot"
|
|
6025
6028
|
});
|
|
6026
6029
|
}
|
|
6027
|
-
parseCharts(buffer) {
|
|
6030
|
+
parseCharts(buffer, skipXmlParsing = false) {
|
|
6028
6031
|
const workerBuffer = cloneArrayBufferForTransfer(buffer);
|
|
6029
6032
|
return this.request({
|
|
6030
6033
|
id: 0,
|
|
6031
|
-
payload: {
|
|
6034
|
+
payload: {
|
|
6035
|
+
buffer: workerBuffer,
|
|
6036
|
+
skipXmlParsing
|
|
6037
|
+
},
|
|
6032
6038
|
type: "parseCharts"
|
|
6033
6039
|
}, [workerBuffer]);
|
|
6034
6040
|
}
|
|
@@ -7162,6 +7168,12 @@ function mergeParsedAndApiImages(parsedImages, apiImages) {
|
|
|
7162
7168
|
function isZipWorkbook(bytes) {
|
|
7163
7169
|
return bytes.byteLength >= 4 && bytes[0] === 80 && bytes[1] === 75;
|
|
7164
7170
|
}
|
|
7171
|
+
function isLegacyXlsWorkbook(bytes) {
|
|
7172
|
+
return bytes.byteLength >= 8 && bytes[0] === 208 && bytes[1] === 207 && bytes[2] === 17 && bytes[3] === 224 && bytes[4] === 161 && bytes[5] === 177 && bytes[6] === 26 && bytes[7] === 225;
|
|
7173
|
+
}
|
|
7174
|
+
function shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing = false) {
|
|
7175
|
+
return skipXmlParsing || isLegacyXlsWorkbook(bytes);
|
|
7176
|
+
}
|
|
7165
7177
|
function createBasicWorkbookAssets(workbook) {
|
|
7166
7178
|
const objectUrls = [];
|
|
7167
7179
|
return {
|
|
@@ -7179,8 +7191,8 @@ function createBasicWorkbookAssets(workbook) {
|
|
|
7179
7191
|
themePalette: { colorsByIndex: {} }
|
|
7180
7192
|
};
|
|
7181
7193
|
}
|
|
7182
|
-
function loadWorkbookImageAssets(bytes, workbook) {
|
|
7183
|
-
if (!isZipWorkbook(bytes)) {
|
|
7194
|
+
function loadWorkbookImageAssets(bytes, workbook, skipXmlParsing = false) {
|
|
7195
|
+
if (shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing) || !isZipWorkbook(bytes)) {
|
|
7184
7196
|
return createBasicWorkbookAssets(workbook);
|
|
7185
7197
|
}
|
|
7186
7198
|
const parsedAssets = parseWorkbookImageAssets(bytes);
|
|
@@ -7250,6 +7262,7 @@ function useXlsxViewerController(options) {
|
|
|
7250
7262
|
maxFileSizeBytes = DEFAULT_MAX_FILE_SIZE_BYTES,
|
|
7251
7263
|
readOnly: requestedReadOnly = false,
|
|
7252
7264
|
readOnlyAboveBytes = 0,
|
|
7265
|
+
skipXmlParsing = false,
|
|
7253
7266
|
src,
|
|
7254
7267
|
useWorker = true
|
|
7255
7268
|
} = options;
|
|
@@ -7380,9 +7393,13 @@ function useXlsxViewerController(options) {
|
|
|
7380
7393
|
return assets;
|
|
7381
7394
|
}, []);
|
|
7382
7395
|
const startChartDisplayHydration = React.useCallback((buffer, targetWorkbook, targetSheets) => {
|
|
7396
|
+
const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(buffer), skipXmlParsing);
|
|
7383
7397
|
const visibleSheetIndexByWorkbookSheetIndex2 = buildVisibleSheetIndexMap(targetSheets);
|
|
7384
7398
|
const quickAssets = loadWorkbookChartAssets(targetWorkbook, null, visibleSheetIndexByWorkbookSheetIndex2);
|
|
7385
7399
|
setChartAssets(quickAssets);
|
|
7400
|
+
if (effectiveSkipXmlParsing) {
|
|
7401
|
+
return;
|
|
7402
|
+
}
|
|
7386
7403
|
const hasCharts = quickAssets.chartsByWorkbookSheetIndex.some((sheetCharts) => sheetCharts.length > 0);
|
|
7387
7404
|
if (!hasCharts) {
|
|
7388
7405
|
setIsChartsLoading(false);
|
|
@@ -7444,7 +7461,7 @@ function useXlsxViewerController(options) {
|
|
|
7444
7461
|
runMainThreadFallback();
|
|
7445
7462
|
return;
|
|
7446
7463
|
}
|
|
7447
|
-
void getWorkerClient().parseCharts(buffer).then((result) => {
|
|
7464
|
+
void getWorkerClient().parseCharts(buffer, effectiveSkipXmlParsing).then((result) => {
|
|
7448
7465
|
if (workerTimeoutHandle !== null) {
|
|
7449
7466
|
window.clearTimeout(workerTimeoutHandle);
|
|
7450
7467
|
}
|
|
@@ -7469,15 +7486,20 @@ function useXlsxViewerController(options) {
|
|
|
7469
7486
|
}
|
|
7470
7487
|
triggerFallback();
|
|
7471
7488
|
});
|
|
7472
|
-
}, [getWorkerClient, hasIncompleteWorkerChartSnapshot, setChartAssets, workerSupported]);
|
|
7489
|
+
}, [getWorkerClient, hasIncompleteWorkerChartSnapshot, setChartAssets, skipXmlParsing, workerSupported]);
|
|
7473
7490
|
const loadWorkbookOnMainThread = React.useCallback(async (buffer) => {
|
|
7474
7491
|
const nextParsedWorkbook = await parseWorkbookBuffer(buffer);
|
|
7475
|
-
const
|
|
7492
|
+
const bytes = new Uint8Array(buffer);
|
|
7493
|
+
const nextImageAssets = loadWorkbookImageAssets(
|
|
7494
|
+
bytes,
|
|
7495
|
+
nextParsedWorkbook.workbook,
|
|
7496
|
+
shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing)
|
|
7497
|
+
);
|
|
7476
7498
|
return {
|
|
7477
7499
|
imageAssets: nextImageAssets,
|
|
7478
7500
|
parsedWorkbook: nextParsedWorkbook
|
|
7479
7501
|
};
|
|
7480
|
-
}, []);
|
|
7502
|
+
}, [skipXmlParsing]);
|
|
7481
7503
|
const refreshWorkbookState = React.useCallback((targetWorkbook) => {
|
|
7482
7504
|
const nextSheets = buildSheetList(
|
|
7483
7505
|
targetWorkbook,
|
|
@@ -7576,6 +7598,7 @@ function useXlsxViewerController(options) {
|
|
|
7576
7598
|
const shouldForceReadOnly = shouldForceReadOnlyForBuffer(buffer.byteLength);
|
|
7577
7599
|
setForcedReadOnly(shouldForceReadOnly);
|
|
7578
7600
|
const shouldUseWorkerForLoad = workerSupported && (requestedReadOnly || shouldForceReadOnly);
|
|
7601
|
+
const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(buffer), skipXmlParsing);
|
|
7579
7602
|
if (shouldDeferLoading && buffer.byteLength > deferLoadingAboveBytes) {
|
|
7580
7603
|
deferredBufferRef.current = buffer;
|
|
7581
7604
|
setDeferredLoadFileSize(buffer.byteLength);
|
|
@@ -7588,11 +7611,11 @@ function useXlsxViewerController(options) {
|
|
|
7588
7611
|
}
|
|
7589
7612
|
if (shouldUseWorkerForLoad) {
|
|
7590
7613
|
try {
|
|
7591
|
-
const snapshot = await getWorkerClient().loadWorkbook(buffer);
|
|
7614
|
+
const snapshot = await getWorkerClient().loadWorkbook(buffer, effectiveSkipXmlParsing);
|
|
7592
7615
|
if (!isCurrent || abortController.signal.aborted) {
|
|
7593
7616
|
return;
|
|
7594
7617
|
}
|
|
7595
|
-
if (hasIncompleteWorkerChartSnapshot(snapshot)) {
|
|
7618
|
+
if (!effectiveSkipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
|
|
7596
7619
|
throw new Error("Worker chart payload incomplete");
|
|
7597
7620
|
}
|
|
7598
7621
|
setWorkbook(null);
|
|
@@ -7804,9 +7827,10 @@ function useXlsxViewerController(options) {
|
|
|
7804
7827
|
const shouldForceReadOnly = shouldForceReadOnlyForBuffer(deferredBuffer.byteLength);
|
|
7805
7828
|
setForcedReadOnly(shouldForceReadOnly);
|
|
7806
7829
|
const shouldUseWorkerForLoad = workerSupported && (requestedReadOnly || shouldForceReadOnly);
|
|
7830
|
+
const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(deferredBuffer), skipXmlParsing);
|
|
7807
7831
|
if (shouldUseWorkerForLoad) {
|
|
7808
|
-
void getWorkerClient().loadWorkbook(deferredBuffer).then((snapshot) => {
|
|
7809
|
-
if (hasIncompleteWorkerChartSnapshot(snapshot)) {
|
|
7832
|
+
void getWorkerClient().loadWorkbook(deferredBuffer, effectiveSkipXmlParsing).then((snapshot) => {
|
|
7833
|
+
if (!effectiveSkipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
|
|
7810
7834
|
throw new Error("Worker chart payload incomplete");
|
|
7811
7835
|
}
|
|
7812
7836
|
deferredBufferRef.current = null;
|
|
@@ -7868,7 +7892,12 @@ function useXlsxViewerController(options) {
|
|
|
7868
7892
|
return;
|
|
7869
7893
|
}
|
|
7870
7894
|
void parseWorkbookBuffer(deferredBuffer).then((nextParsedWorkbook) => {
|
|
7871
|
-
const
|
|
7895
|
+
const bytes = new Uint8Array(deferredBuffer);
|
|
7896
|
+
const nextImageAssets = loadWorkbookImageAssets(
|
|
7897
|
+
bytes,
|
|
7898
|
+
nextParsedWorkbook.workbook,
|
|
7899
|
+
shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing)
|
|
7900
|
+
);
|
|
7872
7901
|
deferredBufferRef.current = null;
|
|
7873
7902
|
setDeferredLoadFileSize(null);
|
|
7874
7903
|
setImageAssets(nextImageAssets);
|