@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.d.cts CHANGED
@@ -507,6 +507,7 @@ interface UseXlsxViewerControllerOptions {
507
507
  maxFileSizeBytes?: number;
508
508
  readOnly?: boolean;
509
509
  readOnlyAboveBytes?: number;
510
+ skipXmlParsing?: boolean;
510
511
  src?: string;
511
512
  useWorker?: boolean;
512
513
  }
package/dist/index.d.ts CHANGED
@@ -507,6 +507,7 @@ interface UseXlsxViewerControllerOptions {
507
507
  maxFileSizeBytes?: number;
508
508
  readOnly?: boolean;
509
509
  readOnlyAboveBytes?: number;
510
+ skipXmlParsing?: boolean;
510
511
  src?: string;
511
512
  useWorker?: boolean;
512
513
  }
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: { buffer: workerBuffer },
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: { buffer: workerBuffer },
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);