@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.cjs CHANGED
@@ -7168,6 +7168,12 @@ function mergeParsedAndApiImages(parsedImages, apiImages) {
7168
7168
  function isZipWorkbook(bytes) {
7169
7169
  return bytes.byteLength >= 4 && bytes[0] === 80 && bytes[1] === 75;
7170
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
+ }
7171
7177
  function createBasicWorkbookAssets(workbook) {
7172
7178
  const objectUrls = [];
7173
7179
  return {
@@ -7186,7 +7192,7 @@ function createBasicWorkbookAssets(workbook) {
7186
7192
  };
7187
7193
  }
7188
7194
  function loadWorkbookImageAssets(bytes, workbook, skipXmlParsing = false) {
7189
- if (skipXmlParsing || !isZipWorkbook(bytes)) {
7195
+ if (shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing) || !isZipWorkbook(bytes)) {
7190
7196
  return createBasicWorkbookAssets(workbook);
7191
7197
  }
7192
7198
  const parsedAssets = parseWorkbookImageAssets(bytes);
@@ -7387,10 +7393,11 @@ function useXlsxViewerController(options) {
7387
7393
  return assets;
7388
7394
  }, []);
7389
7395
  const startChartDisplayHydration = React.useCallback((buffer, targetWorkbook, targetSheets) => {
7396
+ const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(buffer), skipXmlParsing);
7390
7397
  const visibleSheetIndexByWorkbookSheetIndex2 = buildVisibleSheetIndexMap(targetSheets);
7391
7398
  const quickAssets = loadWorkbookChartAssets(targetWorkbook, null, visibleSheetIndexByWorkbookSheetIndex2);
7392
7399
  setChartAssets(quickAssets);
7393
- if (skipXmlParsing) {
7400
+ if (effectiveSkipXmlParsing) {
7394
7401
  return;
7395
7402
  }
7396
7403
  const hasCharts = quickAssets.chartsByWorkbookSheetIndex.some((sheetCharts) => sheetCharts.length > 0);
@@ -7454,7 +7461,7 @@ function useXlsxViewerController(options) {
7454
7461
  runMainThreadFallback();
7455
7462
  return;
7456
7463
  }
7457
- void getWorkerClient().parseCharts(buffer, skipXmlParsing).then((result) => {
7464
+ void getWorkerClient().parseCharts(buffer, effectiveSkipXmlParsing).then((result) => {
7458
7465
  if (workerTimeoutHandle !== null) {
7459
7466
  window.clearTimeout(workerTimeoutHandle);
7460
7467
  }
@@ -7482,7 +7489,12 @@ function useXlsxViewerController(options) {
7482
7489
  }, [getWorkerClient, hasIncompleteWorkerChartSnapshot, setChartAssets, skipXmlParsing, workerSupported]);
7483
7490
  const loadWorkbookOnMainThread = React.useCallback(async (buffer) => {
7484
7491
  const nextParsedWorkbook = await parseWorkbookBuffer(buffer);
7485
- const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(buffer), nextParsedWorkbook.workbook, skipXmlParsing);
7492
+ const bytes = new Uint8Array(buffer);
7493
+ const nextImageAssets = loadWorkbookImageAssets(
7494
+ bytes,
7495
+ nextParsedWorkbook.workbook,
7496
+ shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing)
7497
+ );
7486
7498
  return {
7487
7499
  imageAssets: nextImageAssets,
7488
7500
  parsedWorkbook: nextParsedWorkbook
@@ -7586,6 +7598,7 @@ function useXlsxViewerController(options) {
7586
7598
  const shouldForceReadOnly = shouldForceReadOnlyForBuffer(buffer.byteLength);
7587
7599
  setForcedReadOnly(shouldForceReadOnly);
7588
7600
  const shouldUseWorkerForLoad = workerSupported && (requestedReadOnly || shouldForceReadOnly);
7601
+ const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(buffer), skipXmlParsing);
7589
7602
  if (shouldDeferLoading && buffer.byteLength > deferLoadingAboveBytes) {
7590
7603
  deferredBufferRef.current = buffer;
7591
7604
  setDeferredLoadFileSize(buffer.byteLength);
@@ -7598,11 +7611,11 @@ function useXlsxViewerController(options) {
7598
7611
  }
7599
7612
  if (shouldUseWorkerForLoad) {
7600
7613
  try {
7601
- const snapshot = await getWorkerClient().loadWorkbook(buffer, skipXmlParsing);
7614
+ const snapshot = await getWorkerClient().loadWorkbook(buffer, effectiveSkipXmlParsing);
7602
7615
  if (!isCurrent || abortController.signal.aborted) {
7603
7616
  return;
7604
7617
  }
7605
- if (!skipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7618
+ if (!effectiveSkipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7606
7619
  throw new Error("Worker chart payload incomplete");
7607
7620
  }
7608
7621
  setWorkbook(null);
@@ -7814,9 +7827,10 @@ function useXlsxViewerController(options) {
7814
7827
  const shouldForceReadOnly = shouldForceReadOnlyForBuffer(deferredBuffer.byteLength);
7815
7828
  setForcedReadOnly(shouldForceReadOnly);
7816
7829
  const shouldUseWorkerForLoad = workerSupported && (requestedReadOnly || shouldForceReadOnly);
7830
+ const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(new Uint8Array(deferredBuffer), skipXmlParsing);
7817
7831
  if (shouldUseWorkerForLoad) {
7818
- void getWorkerClient().loadWorkbook(deferredBuffer, skipXmlParsing).then((snapshot) => {
7819
- if (!skipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7832
+ void getWorkerClient().loadWorkbook(deferredBuffer, effectiveSkipXmlParsing).then((snapshot) => {
7833
+ if (!effectiveSkipXmlParsing && hasIncompleteWorkerChartSnapshot(snapshot)) {
7820
7834
  throw new Error("Worker chart payload incomplete");
7821
7835
  }
7822
7836
  deferredBufferRef.current = null;
@@ -7878,7 +7892,12 @@ function useXlsxViewerController(options) {
7878
7892
  return;
7879
7893
  }
7880
7894
  void parseWorkbookBuffer(deferredBuffer).then((nextParsedWorkbook) => {
7881
- const nextImageAssets = loadWorkbookImageAssets(new Uint8Array(deferredBuffer), nextParsedWorkbook.workbook, skipXmlParsing);
7895
+ const bytes = new Uint8Array(deferredBuffer);
7896
+ const nextImageAssets = loadWorkbookImageAssets(
7897
+ bytes,
7898
+ nextParsedWorkbook.workbook,
7899
+ shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing)
7900
+ );
7882
7901
  deferredBufferRef.current = null;
7883
7902
  setDeferredLoadFileSize(null);
7884
7903
  setImageAssets(nextImageAssets);