@extend-ai/react-xlsx 0.5.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.js CHANGED
@@ -7120,6 +7120,12 @@ function mergeParsedAndApiImages(parsedImages, apiImages) {
7120
7120
  function isZipWorkbook(bytes) {
7121
7121
  return bytes.byteLength >= 4 && bytes[0] === 80 && bytes[1] === 75;
7122
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
+ }
7123
7129
  function createBasicWorkbookAssets(workbook) {
7124
7130
  const objectUrls = [];
7125
7131
  return {
@@ -7138,7 +7144,7 @@ function createBasicWorkbookAssets(workbook) {
7138
7144
  };
7139
7145
  }
7140
7146
  function loadWorkbookImageAssets(bytes, workbook, skipXmlParsing = false) {
7141
- if (skipXmlParsing || !isZipWorkbook(bytes)) {
7147
+ if (shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing) || !isZipWorkbook(bytes)) {
7142
7148
  return createBasicWorkbookAssets(workbook);
7143
7149
  }
7144
7150
  const parsedAssets = parseWorkbookImageAssets(bytes);
@@ -7339,10 +7345,11 @@ function useXlsxViewerController(options) {
7339
7345
  return assets;
7340
7346
  }, []);
7341
7347
  const startChartDisplayHydration = React.useCallback((buffer, targetWorkbook, targetSheets) => {
7348
+ const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(buffer), skipXmlParsing);
7342
7349
  const visibleSheetIndexByWorkbookSheetIndex2 = buildVisibleSheetIndexMap(targetSheets);
7343
7350
  const quickAssets = loadWorkbookChartAssets(targetWorkbook, null, visibleSheetIndexByWorkbookSheetIndex2);
7344
7351
  setChartAssets(quickAssets);
7345
- if (skipXmlParsing) {
7352
+ if (effectiveSkipXmlParsing) {
7346
7353
  return;
7347
7354
  }
7348
7355
  const hasCharts = quickAssets.chartsByWorkbookSheetIndex.some((sheetCharts) => sheetCharts.length > 0);
@@ -7406,7 +7413,7 @@ function useXlsxViewerController(options) {
7406
7413
  runMainThreadFallback();
7407
7414
  return;
7408
7415
  }
7409
- void getWorkerClient().parseCharts(buffer, skipXmlParsing).then((result) => {
7416
+ void getWorkerClient().parseCharts(buffer, effectiveSkipXmlParsing).then((result) => {
7410
7417
  if (workerTimeoutHandle !== null) {
7411
7418
  window.clearTimeout(workerTimeoutHandle);
7412
7419
  }
@@ -7434,7 +7441,12 @@ function useXlsxViewerController(options) {
7434
7441
  }, [getWorkerClient, hasIncompleteWorkerChartSnapshot, setChartAssets, skipXmlParsing, workerSupported]);
7435
7442
  const loadWorkbookOnMainThread = React.useCallback(async (buffer) => {
7436
7443
  const nextParsedWorkbook = await parseWorkbookBuffer(buffer);
7437
- const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(buffer), nextParsedWorkbook.workbook, skipXmlParsing);
7444
+ const bytes = new Uint8Array(buffer);
7445
+ const nextImageAssets = loadWorkbookImageAssets(
7446
+ bytes,
7447
+ nextParsedWorkbook.workbook,
7448
+ shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing)
7449
+ );
7438
7450
  return {
7439
7451
  imageAssets: nextImageAssets,
7440
7452
  parsedWorkbook: nextParsedWorkbook
@@ -7538,6 +7550,7 @@ function useXlsxViewerController(options) {
7538
7550
  const shouldForceReadOnly = shouldForceReadOnlyForBuffer(buffer.byteLength);
7539
7551
  setForcedReadOnly(shouldForceReadOnly);
7540
7552
  const shouldUseWorkerForLoad = workerSupported && (requestedReadOnly || shouldForceReadOnly);
7553
+ const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(buffer), skipXmlParsing);
7541
7554
  if (shouldDeferLoading && buffer.byteLength > deferLoadingAboveBytes) {
7542
7555
  deferredBufferRef.current = buffer;
7543
7556
  setDeferredLoadFileSize(buffer.byteLength);
@@ -7550,11 +7563,11 @@ function useXlsxViewerController(options) {
7550
7563
  }
7551
7564
  if (shouldUseWorkerForLoad) {
7552
7565
  try {
7553
- const snapshot = await getWorkerClient().loadWorkbook(buffer, skipXmlParsing);
7566
+ const snapshot = await getWorkerClient().loadWorkbook(buffer, effectiveSkipXmlParsing);
7554
7567
  if (!isCurrent || abortController.signal.aborted) {
7555
7568
  return;
7556
7569
  }
7557
- if (!skipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7570
+ if (!effectiveSkipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7558
7571
  throw new Error("Worker chart payload incomplete");
7559
7572
  }
7560
7573
  setWorkbook(null);
@@ -7766,9 +7779,10 @@ function useXlsxViewerController(options) {
7766
7779
  const shouldForceReadOnly = shouldForceReadOnlyForBuffer(deferredBuffer.byteLength);
7767
7780
  setForcedReadOnly(shouldForceReadOnly);
7768
7781
  const shouldUseWorkerForLoad = workerSupported && (requestedReadOnly || shouldForceReadOnly);
7782
+ const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(deferredBuffer), skipXmlParsing);
7769
7783
  if (shouldUseWorkerForLoad) {
7770
- void getWorkerClient().loadWorkbook(deferredBuffer, skipXmlParsing).then((snapshot) => {
7771
- if (!skipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7784
+ void getWorkerClient().loadWorkbook(deferredBuffer, effectiveSkipXmlParsing).then((snapshot) => {
7785
+ if (!effectiveSkipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7772
7786
  throw new Error("Worker chart payload incomplete");
7773
7787
  }
7774
7788
  deferredBufferRef.current = null;
@@ -7830,7 +7844,12 @@ function useXlsxViewerController(options) {
7830
7844
  return;
7831
7845
  }
7832
7846
  void parseWorkbookBuffer(deferredBuffer).then((nextParsedWorkbook) => {
7833
- const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(deferredBuffer), nextParsedWorkbook.workbook, skipXmlParsing);
7847
+ const bytes = new Uint8Array(deferredBuffer);
7848
+ const nextImageAssets = loadWorkbookImageAssets(
7849
+ bytes,
7850
+ nextParsedWorkbook.workbook,
7851
+ shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing)
7852
+ );
7834
7853
  deferredBufferRef.current = null;
7835
7854
  setDeferredLoadFileSize(null);
7836
7855
  setImageAssets(nextImageAssets);