@extend-ai/react-xlsx 0.7.0 → 0.8.1

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.
@@ -3813,13 +3813,36 @@ function parseWorkbookTableMetadata(archive, workbookSheets) {
3813
3813
  }
3814
3814
  return [{
3815
3815
  displayName: tableNode.getAttribute("displayName") ?? void 0,
3816
+ headerRowCount: parseWorkbookTableCount(tableNode.getAttribute("headerRowCount"), 1),
3816
3817
  headerRowCellStyle: tableNode.getAttribute("headerRowCellStyle") ?? void 0,
3817
3818
  name: tableNode.getAttribute("name") ?? void 0,
3818
- reference: tableNode.getAttribute("ref") ?? void 0
3819
+ reference: tableNode.getAttribute("ref") ?? void 0,
3820
+ totalsRowCount: parseWorkbookTableCount(tableNode.getAttribute("totalsRowCount"), 0),
3821
+ totalsRowShown: parseWorkbookTableBoolean(tableNode.getAttribute("totalsRowShown"), false)
3819
3822
  }];
3820
3823
  });
3821
3824
  });
3822
3825
  }
3826
+ function parseWorkbookTableCount(value, fallback) {
3827
+ if (value === null) {
3828
+ return fallback;
3829
+ }
3830
+ const parsed = Number.parseInt(value, 10);
3831
+ return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
3832
+ }
3833
+ function parseWorkbookTableBoolean(value, fallback) {
3834
+ if (value === null) {
3835
+ return fallback;
3836
+ }
3837
+ const normalized = value.trim().toLowerCase();
3838
+ if (normalized === "0" || normalized === "false" || normalized === "") {
3839
+ return false;
3840
+ }
3841
+ if (normalized === "1" || normalized === "true") {
3842
+ return true;
3843
+ }
3844
+ return fallback;
3845
+ }
3823
3846
  function parseSqrefRanges(sqref) {
3824
3847
  if (!sqref) {
3825
3848
  return [];
@@ -4539,17 +4562,18 @@ function buildSheetList(nextWorkbook, structureAssets, showHiddenSheets = false)
4539
4562
  function mapWorksheetTables(worksheet, metadataForSheet) {
4540
4563
  const rawTables = worksheet?.tables ?? [];
4541
4564
  return rawTables.flatMap((table, index) => {
4542
- const reference = typeof table.reference === "string" ? table.reference : "";
4543
- const parsedRange = parseA1RangeReference2(reference);
4544
- if (!parsedRange) {
4545
- return [];
4546
- }
4547
4565
  const rawColumns = Array.isArray(table.columns) ? table.columns : [];
4548
4566
  const rawName = typeof table.name === "string" ? table.name : `Table${index + 1}`;
4549
4567
  const rawDisplayName = typeof table.displayName === "string" ? table.displayName : typeof table.name === "string" ? table.name : `Table ${index + 1}`;
4550
4568
  const metadata = metadataForSheet?.find(
4551
- (entry) => entry.name && entry.name === rawName || entry.displayName && entry.displayName === rawDisplayName || entry.reference && entry.reference === reference
4569
+ (entry) => entry.name && entry.name === rawName || entry.displayName && entry.displayName === rawDisplayName || entry.reference && entry.reference === table.reference
4552
4570
  );
4571
+ const rawReference = typeof table.reference === "string" ? table.reference : "";
4572
+ const reference = metadata?.reference ?? rawReference;
4573
+ const parsedRange = parseA1RangeReference2(reference);
4574
+ if (!parsedRange) {
4575
+ return [];
4576
+ }
4553
4577
  return [{
4554
4578
  columns: rawColumns.map((column, columnIndex) => ({
4555
4579
  id: typeof column.id === "number" ? column.id ?? columnIndex + 1 : columnIndex + 1,
@@ -4558,17 +4582,47 @@ function mapWorksheetTables(worksheet, metadataForSheet) {
4558
4582
  })),
4559
4583
  displayName: rawDisplayName,
4560
4584
  end: parsedRange.end,
4561
- headerRowCount: typeof table.headerRowCount === "number" ? table.headerRowCount : 1,
4585
+ headerRowCount: metadata?.headerRowCount ?? resolveWorkbookTableCount(table.headerRowCount, 1),
4562
4586
  headerRowCellStyle: metadata?.headerRowCellStyle,
4563
4587
  name: rawName,
4564
4588
  reference,
4565
4589
  start: parsedRange.start,
4566
4590
  styleInfo: table.styleInfo,
4567
- totalsRowCount: typeof table.totalsRowCount === "number" ? table.totalsRowCount : 0,
4568
- totalsRowShown: Boolean(table.totalsRowShown)
4591
+ totalsRowCount: metadata?.totalsRowCount ?? resolveWorkbookTableCount(table.totalsRowCount, 0),
4592
+ totalsRowShown: metadata?.totalsRowShown ?? resolveWorkbookTableBoolean(table.totalsRowShown)
4569
4593
  }];
4570
4594
  });
4571
4595
  }
4596
+ function resolveWorkbookTableCount(value, fallback) {
4597
+ if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
4598
+ return value;
4599
+ }
4600
+ if (typeof value === "string") {
4601
+ const parsed = Number.parseInt(value, 10);
4602
+ if (Number.isFinite(parsed) && parsed >= 0) {
4603
+ return parsed;
4604
+ }
4605
+ }
4606
+ return fallback;
4607
+ }
4608
+ function resolveWorkbookTableBoolean(value) {
4609
+ if (typeof value === "boolean") {
4610
+ return value;
4611
+ }
4612
+ if (typeof value === "number") {
4613
+ return value !== 0;
4614
+ }
4615
+ if (typeof value === "string") {
4616
+ const normalized = value.trim().toLowerCase();
4617
+ if (normalized === "0" || normalized === "false" || normalized === "") {
4618
+ return false;
4619
+ }
4620
+ if (normalized === "1" || normalized === "true") {
4621
+ return true;
4622
+ }
4623
+ }
4624
+ return false;
4625
+ }
4572
4626
  function decodeHtmlEntities(value) {
4573
4627
  return value.replace(/&quot;/g, '"').replace(/&#34;/g, '"').replace(/&apos;/g, "'").replace(/&#39;/g, "'").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
4574
4628
  }