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