@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.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
  }
@@ -7114,6 +7120,12 @@ function mergeParsedAndApiImages(parsedImages, apiImages) {
7114
7120
  function isZipWorkbook(bytes) {
7115
7121
  return bytes.byteLength >= 4 && bytes[0] === 80 && bytes[1] === 75;
7116
7122
  }
7123
+ function isLegacyXlsWorkbook(bytes) {
7124
+ 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;
7125
+ }
7126
+ function shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing = false) {
7127
+ return skipXmlParsing || isLegacyXlsWorkbook(bytes);
7128
+ }
7117
7129
  function createBasicWorkbookAssets(workbook) {
7118
7130
  const objectUrls = [];
7119
7131
  return {
@@ -7131,8 +7143,8 @@ function createBasicWorkbookAssets(workbook) {
7131
7143
  themePalette: { colorsByIndex: {} }
7132
7144
  };
7133
7145
  }
7134
- function loadWorkbookImageAssets(bytes, workbook) {
7135
- if (!isZipWorkbook(bytes)) {
7146
+ function loadWorkbookImageAssets(bytes, workbook, skipXmlParsing = false) {
7147
+ if (shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing) || !isZipWorkbook(bytes)) {
7136
7148
  return createBasicWorkbookAssets(workbook);
7137
7149
  }
7138
7150
  const parsedAssets = parseWorkbookImageAssets(bytes);
@@ -7202,6 +7214,7 @@ function useXlsxViewerController(options) {
7202
7214
  maxFileSizeBytes = DEFAULT_MAX_FILE_SIZE_BYTES,
7203
7215
  readOnly: requestedReadOnly = false,
7204
7216
  readOnlyAboveBytes = 0,
7217
+ skipXmlParsing = false,
7205
7218
  src,
7206
7219
  useWorker = true
7207
7220
  } = options;
@@ -7332,9 +7345,13 @@ function useXlsxViewerController(options) {
7332
7345
  return assets;
7333
7346
  }, []);
7334
7347
  const startChartDisplayHydration = React.useCallback((buffer, targetWorkbook, targetSheets) => {
7348
+ const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(buffer), skipXmlParsing);
7335
7349
  const visibleSheetIndexByWorkbookSheetIndex2 = buildVisibleSheetIndexMap(targetSheets);
7336
7350
  const quickAssets = loadWorkbookChartAssets(targetWorkbook, null, visibleSheetIndexByWorkbookSheetIndex2);
7337
7351
  setChartAssets(quickAssets);
7352
+ if (effectiveSkipXmlParsing) {
7353
+ return;
7354
+ }
7338
7355
  const hasCharts = quickAssets.chartsByWorkbookSheetIndex.some((sheetCharts) => sheetCharts.length > 0);
7339
7356
  if (!hasCharts) {
7340
7357
  setIsChartsLoading(false);
@@ -7396,7 +7413,7 @@ function useXlsxViewerController(options) {
7396
7413
  runMainThreadFallback();
7397
7414
  return;
7398
7415
  }
7399
- void getWorkerClient().parseCharts(buffer).then((result) => {
7416
+ void getWorkerClient().parseCharts(buffer, effectiveSkipXmlParsing).then((result) => {
7400
7417
  if (workerTimeoutHandle !== null) {
7401
7418
  window.clearTimeout(workerTimeoutHandle);
7402
7419
  }
@@ -7421,15 +7438,20 @@ function useXlsxViewerController(options) {
7421
7438
  }
7422
7439
  triggerFallback();
7423
7440
  });
7424
- }, [getWorkerClient, hasIncompleteWorkerChartSnapshot, setChartAssets, workerSupported]);
7441
+ }, [getWorkerClient, hasIncompleteWorkerChartSnapshot, setChartAssets, skipXmlParsing, workerSupported]);
7425
7442
  const loadWorkbookOnMainThread = React.useCallback(async (buffer) => {
7426
7443
  const nextParsedWorkbook = await parseWorkbookBuffer(buffer);
7427
- const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(buffer), nextParsedWorkbook.workbook);
7444
+ const bytes = new Uint8Array(buffer);
7445
+ const nextImageAssets = loadWorkbookImageAssets(
7446
+ bytes,
7447
+ nextParsedWorkbook.workbook,
7448
+ shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing)
7449
+ );
7428
7450
  return {
7429
7451
  imageAssets: nextImageAssets,
7430
7452
  parsedWorkbook: nextParsedWorkbook
7431
7453
  };
7432
- }, []);
7454
+ }, [skipXmlParsing]);
7433
7455
  const refreshWorkbookState = React.useCallback((targetWorkbook) => {
7434
7456
  const nextSheets = buildSheetList(
7435
7457
  targetWorkbook,
@@ -7528,6 +7550,7 @@ function useXlsxViewerController(options) {
7528
7550
  const shouldForceReadOnly = shouldForceReadOnlyForBuffer(buffer.byteLength);
7529
7551
  setForcedReadOnly(shouldForceReadOnly);
7530
7552
  const shouldUseWorkerForLoad = workerSupported && (requestedReadOnly || shouldForceReadOnly);
7553
+ const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(buffer), skipXmlParsing);
7531
7554
  if (shouldDeferLoading && buffer.byteLength > deferLoadingAboveBytes) {
7532
7555
  deferredBufferRef.current = buffer;
7533
7556
  setDeferredLoadFileSize(buffer.byteLength);
@@ -7540,11 +7563,11 @@ function useXlsxViewerController(options) {
7540
7563
  }
7541
7564
  if (shouldUseWorkerForLoad) {
7542
7565
  try {
7543
- const snapshot = await getWorkerClient().loadWorkbook(buffer);
7566
+ const snapshot = await getWorkerClient().loadWorkbook(buffer, effectiveSkipXmlParsing);
7544
7567
  if (!isCurrent || abortController.signal.aborted) {
7545
7568
  return;
7546
7569
  }
7547
- if (hasIncompleteWorkerChartSnapshot(snapshot)) {
7570
+ if (!effectiveSkipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7548
7571
  throw new Error("Worker chart payload incomplete");
7549
7572
  }
7550
7573
  setWorkbook(null);
@@ -7756,9 +7779,10 @@ function useXlsxViewerController(options) {
7756
7779
  const shouldForceReadOnly = shouldForceReadOnlyForBuffer(deferredBuffer.byteLength);
7757
7780
  setForcedReadOnly(shouldForceReadOnly);
7758
7781
  const shouldUseWorkerForLoad = workerSupported && (requestedReadOnly || shouldForceReadOnly);
7782
+ const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(deferredBuffer), skipXmlParsing);
7759
7783
  if (shouldUseWorkerForLoad) {
7760
- void getWorkerClient().loadWorkbook(deferredBuffer).then((snapshot) => {
7761
- if (hasIncompleteWorkerChartSnapshot(snapshot)) {
7784
+ void getWorkerClient().loadWorkbook(deferredBuffer, effectiveSkipXmlParsing).then((snapshot) => {
7785
+ if (!effectiveSkipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7762
7786
  throw new Error("Worker chart payload incomplete");
7763
7787
  }
7764
7788
  deferredBufferRef.current = null;
@@ -7820,7 +7844,12 @@ function useXlsxViewerController(options) {
7820
7844
  return;
7821
7845
  }
7822
7846
  void parseWorkbookBuffer(deferredBuffer).then((nextParsedWorkbook) => {
7823
- const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(deferredBuffer), nextParsedWorkbook.workbook);
7847
+ const bytes = new Uint8Array(deferredBuffer);
7848
+ const nextImageAssets = loadWorkbookImageAssets(
7849
+ bytes,
7850
+ nextParsedWorkbook.workbook,
7851
+ shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing)
7852
+ );
7824
7853
  deferredBufferRef.current = null;
7825
7854
  setDeferredLoadFileSize(null);
7826
7855
  setImageAssets(nextImageAssets);