@extend-ai/react-xlsx 0.4.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 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: { buffer: workerBuffer },
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: { buffer: workerBuffer },
6034
+ payload: {
6035
+ buffer: workerBuffer,
6036
+ skipXmlParsing
6037
+ },
6032
6038
  type: "parseCharts"
6033
6039
  }, [workerBuffer]);
6034
6040
  }
@@ -7179,8 +7185,8 @@ function createBasicWorkbookAssets(workbook) {
7179
7185
  themePalette: { colorsByIndex: {} }
7180
7186
  };
7181
7187
  }
7182
- function loadWorkbookImageAssets(bytes, workbook) {
7183
- if (!isZipWorkbook(bytes)) {
7188
+ function loadWorkbookImageAssets(bytes, workbook, skipXmlParsing = false) {
7189
+ if (skipXmlParsing || !isZipWorkbook(bytes)) {
7184
7190
  return createBasicWorkbookAssets(workbook);
7185
7191
  }
7186
7192
  const parsedAssets = parseWorkbookImageAssets(bytes);
@@ -7250,6 +7256,7 @@ function useXlsxViewerController(options) {
7250
7256
  maxFileSizeBytes = DEFAULT_MAX_FILE_SIZE_BYTES,
7251
7257
  readOnly: requestedReadOnly = false,
7252
7258
  readOnlyAboveBytes = 0,
7259
+ skipXmlParsing = false,
7253
7260
  src,
7254
7261
  useWorker = true
7255
7262
  } = options;
@@ -7383,6 +7390,9 @@ function useXlsxViewerController(options) {
7383
7390
  const visibleSheetIndexByWorkbookSheetIndex2 = buildVisibleSheetIndexMap(targetSheets);
7384
7391
  const quickAssets = loadWorkbookChartAssets(targetWorkbook, null, visibleSheetIndexByWorkbookSheetIndex2);
7385
7392
  setChartAssets(quickAssets);
7393
+ if (skipXmlParsing) {
7394
+ return;
7395
+ }
7386
7396
  const hasCharts = quickAssets.chartsByWorkbookSheetIndex.some((sheetCharts) => sheetCharts.length > 0);
7387
7397
  if (!hasCharts) {
7388
7398
  setIsChartsLoading(false);
@@ -7444,7 +7454,7 @@ function useXlsxViewerController(options) {
7444
7454
  runMainThreadFallback();
7445
7455
  return;
7446
7456
  }
7447
- void getWorkerClient().parseCharts(buffer).then((result) => {
7457
+ void getWorkerClient().parseCharts(buffer, skipXmlParsing).then((result) => {
7448
7458
  if (workerTimeoutHandle !== null) {
7449
7459
  window.clearTimeout(workerTimeoutHandle);
7450
7460
  }
@@ -7469,15 +7479,15 @@ function useXlsxViewerController(options) {
7469
7479
  }
7470
7480
  triggerFallback();
7471
7481
  });
7472
- }, [getWorkerClient, hasIncompleteWorkerChartSnapshot, setChartAssets, workerSupported]);
7482
+ }, [getWorkerClient, hasIncompleteWorkerChartSnapshot, setChartAssets, skipXmlParsing, workerSupported]);
7473
7483
  const loadWorkbookOnMainThread = React.useCallback(async (buffer) => {
7474
7484
  const nextParsedWorkbook = await parseWorkbookBuffer(buffer);
7475
- const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(buffer), nextParsedWorkbook.workbook);
7485
+ const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(buffer), nextParsedWorkbook.workbook, skipXmlParsing);
7476
7486
  return {
7477
7487
  imageAssets: nextImageAssets,
7478
7488
  parsedWorkbook: nextParsedWorkbook
7479
7489
  };
7480
- }, []);
7490
+ }, [skipXmlParsing]);
7481
7491
  const refreshWorkbookState = React.useCallback((targetWorkbook) => {
7482
7492
  const nextSheets = buildSheetList(
7483
7493
  targetWorkbook,
@@ -7588,11 +7598,11 @@ function useXlsxViewerController(options) {
7588
7598
  }
7589
7599
  if (shouldUseWorkerForLoad) {
7590
7600
  try {
7591
- const snapshot = await getWorkerClient().loadWorkbook(buffer);
7601
+ const snapshot = await getWorkerClient().loadWorkbook(buffer, skipXmlParsing);
7592
7602
  if (!isCurrent || abortController.signal.aborted) {
7593
7603
  return;
7594
7604
  }
7595
- if (hasIncompleteWorkerChartSnapshot(snapshot)) {
7605
+ if (!skipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7596
7606
  throw new Error("Worker chart payload incomplete");
7597
7607
  }
7598
7608
  setWorkbook(null);
@@ -7805,8 +7815,8 @@ function useXlsxViewerController(options) {
7805
7815
  setForcedReadOnly(shouldForceReadOnly);
7806
7816
  const shouldUseWorkerForLoad = workerSupported && (requestedReadOnly || shouldForceReadOnly);
7807
7817
  if (shouldUseWorkerForLoad) {
7808
- void getWorkerClient().loadWorkbook(deferredBuffer).then((snapshot) => {
7809
- if (hasIncompleteWorkerChartSnapshot(snapshot)) {
7818
+ void getWorkerClient().loadWorkbook(deferredBuffer, skipXmlParsing).then((snapshot) => {
7819
+ if (!skipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7810
7820
  throw new Error("Worker chart payload incomplete");
7811
7821
  }
7812
7822
  deferredBufferRef.current = null;
@@ -7868,7 +7878,7 @@ function useXlsxViewerController(options) {
7868
7878
  return;
7869
7879
  }
7870
7880
  void parseWorkbookBuffer(deferredBuffer).then((nextParsedWorkbook) => {
7871
- const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(deferredBuffer), nextParsedWorkbook.workbook);
7881
+ const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(deferredBuffer), nextParsedWorkbook.workbook, skipXmlParsing);
7872
7882
  deferredBufferRef.current = null;
7873
7883
  setDeferredLoadFileSize(null);
7874
7884
  setImageAssets(nextImageAssets);