@particle-academy/holy-sheet 2.1.0 → 2.2.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
@@ -509,16 +509,6 @@ var Normalizer = class {
509
509
  }
510
510
  normalizeSheet(sheet) {
511
511
  const name = String(sheet.name);
512
- if (sheet.cells != null) {
513
- return new Sheet(
514
- name,
515
- this.normalizeCellMap(sheet.cells),
516
- this.normalizeMerges(sheet.mergedRegions ?? []),
517
- this.normalizeColumnWidths(sheet.columnWidths ?? {}),
518
- toInt(sheet.frozenRows ?? 0),
519
- toInt(sheet.frozenCols ?? 0)
520
- );
521
- }
522
512
  const cells = /* @__PURE__ */ new Map();
523
513
  const columns = sheet.columns ?? [];
524
514
  const rows = sheet.rows ?? [];
@@ -570,6 +560,22 @@ var Normalizer = class {
570
560
  cells.set(address, new Cell(address, null, `${excelFunc}(${rangeStart}:${rangeEnd})`, combined));
571
561
  }
572
562
  }
563
+ if (sheet.cells != null) {
564
+ for (const [address, cell] of this.normalizeCellMap(sheet.cells)) {
565
+ const beneath = cells.get(address);
566
+ cells.set(
567
+ address,
568
+ beneath?.format ? new Cell(
569
+ cell.address,
570
+ cell.value,
571
+ cell.formula,
572
+ beneath.format.mergeWith(cell.format),
573
+ cell.comment,
574
+ cell.cachedValue
575
+ ) : cell
576
+ );
577
+ }
578
+ }
573
579
  return new Sheet(
574
580
  name,
575
581
  cells,
@@ -582,12 +588,20 @@ var Normalizer = class {
582
588
  normalizeCellMap(map) {
583
589
  const cells = /* @__PURE__ */ new Map();
584
590
  for (const [address, cellData] of Object.entries(map)) {
585
- const format = cellData && isPlainObject(cellData.format) ? CellFormat.fromInput(cellData.format) : null;
586
- const comment = cellData && isPlainObject(cellData.comment) ? new CellComment(
591
+ if (!isPlainObject(cellData)) {
592
+ const [bare, formula] = promoteFormula(cellData);
593
+ cells.set(
594
+ address,
595
+ new Cell(address, formula !== null ? null : this.coerceValue(bare, null), formula)
596
+ );
597
+ continue;
598
+ }
599
+ const format = isPlainObject(cellData.format) ? CellFormat.fromInput(cellData.format) : null;
600
+ const comment = isPlainObject(cellData.comment) ? new CellComment(
587
601
  String(cellData.comment.text ?? ""),
588
602
  cellData.comment.author ?? null,
589
603
  cellData.comment.color ?? null
590
- ) : null;
604
+ ) : typeof cellData.comment === "string" ? new CellComment(cellData.comment) : null;
591
605
  const rawValue = cellData?.value ?? null;
592
606
  cells.set(
593
607
  address,
@@ -660,7 +674,13 @@ var Normalizer = class {
660
674
  value.computedValue ?? null
661
675
  );
662
676
  }
663
- return new Cell(address, this.coerceValue(value, columnFormat), null, columnFormat);
677
+ const [bare, formula] = promoteFormula(value);
678
+ return new Cell(
679
+ address,
680
+ formula !== null ? null : this.coerceValue(bare, columnFormat),
681
+ formula,
682
+ columnFormat
683
+ );
664
684
  }
665
685
  coerceValue(value, format) {
666
686
  if (value === null || value === void 0) return null;
@@ -682,6 +702,12 @@ var Normalizer = class {
682
702
  return value;
683
703
  }
684
704
  };
705
+ function promoteFormula(value) {
706
+ if (typeof value === "string" && value.length > 1 && value[0] === "=") {
707
+ return [null, value.slice(1)];
708
+ }
709
+ return [value, null];
710
+ }
685
711
  function toInt(v) {
686
712
  const n = Math.trunc(Number(v));
687
713
  return Number.isFinite(n) ? n : 0;