@coco-vexel/coco-office-editor 1.0.2 → 1.0.4
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 +79 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +79 -21
- package/dist/index.js.map +1 -1
- package/dist/spreadsheet.cjs +79 -21
- package/dist/spreadsheet.cjs.map +1 -1
- package/dist/spreadsheet.d.cts +2 -1
- package/dist/spreadsheet.d.ts +2 -1
- package/dist/spreadsheet.js +79 -21
- package/dist/spreadsheet.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -16776,7 +16776,7 @@ function buildSpreadsheetSheetRenderModel(sheet, styles, options = {}) {
|
|
|
16776
16776
|
maxColumn = Math.max(maxColumn, column.max);
|
|
16777
16777
|
}
|
|
16778
16778
|
for (const cell of sheet.cells) {
|
|
16779
|
-
const renderCell = toRenderCell(cell, styles, options.formulaResults);
|
|
16779
|
+
const renderCell = toRenderCell(cell, styles, options.formulaResults, options.date1904);
|
|
16780
16780
|
cellsByAddress.set(cell.address, renderCell);
|
|
16781
16781
|
cellsByRowColumn.set(rowColumnKey(cell.row, cell.column), renderCell);
|
|
16782
16782
|
maxRow = Math.max(maxRow, cell.row);
|
|
@@ -16792,7 +16792,7 @@ function buildSpreadsheetSheetRenderModel(sheet, styles, options = {}) {
|
|
|
16792
16792
|
kind: "formula",
|
|
16793
16793
|
value: null
|
|
16794
16794
|
};
|
|
16795
|
-
const renderCell = toRenderCell(virtualCell, styles, options.formulaResults);
|
|
16795
|
+
const renderCell = toRenderCell(virtualCell, styles, options.formulaResults, options.date1904);
|
|
16796
16796
|
cellsByAddress.set(address, renderCell);
|
|
16797
16797
|
cellsByRowColumn.set(rowColumnKey(parsed.row, parsed.column), renderCell);
|
|
16798
16798
|
maxRow = Math.max(maxRow, parsed.row);
|
|
@@ -16845,7 +16845,7 @@ function getRenderCell(model, row, column) {
|
|
|
16845
16845
|
return model.cellsByRowColumn.get(rowColumnKey(row, column));
|
|
16846
16846
|
}
|
|
16847
16847
|
__name(getRenderCell, "getRenderCell");
|
|
16848
|
-
function toRenderCell(cell, styles, formulaResults) {
|
|
16848
|
+
function toRenderCell(cell, styles, formulaResults, date1904 = false) {
|
|
16849
16849
|
var _a, _b;
|
|
16850
16850
|
const formulaResult = formulaResults == null ? void 0 : formulaResults.get(cell.address);
|
|
16851
16851
|
const resultValue = formulaResult && !formulaResult.error ? formulaResult.value : void 0;
|
|
@@ -16856,16 +16856,16 @@ function toRenderCell(cell, styles, formulaResults) {
|
|
|
16856
16856
|
address: cell.address,
|
|
16857
16857
|
kind: cell.kind,
|
|
16858
16858
|
value,
|
|
16859
|
-
displayText: cellToDisplayText(cell, styles, value, formulaResult),
|
|
16859
|
+
displayText: cellToDisplayText(cell, styles, value, formulaResult, date1904),
|
|
16860
16860
|
formula: cell.formula,
|
|
16861
16861
|
styleId: cell.styleId,
|
|
16862
16862
|
source: cell
|
|
16863
16863
|
};
|
|
16864
16864
|
}
|
|
16865
16865
|
__name(toRenderCell, "toRenderCell");
|
|
16866
|
-
function cellToDisplayText(cell, styles, value, formulaResult) {
|
|
16866
|
+
function cellToDisplayText(cell, styles, value, formulaResult, date1904 = false) {
|
|
16867
16867
|
if (formulaResult == null ? void 0 : formulaResult.error) return formulaResult.displayText;
|
|
16868
|
-
if (value !== null) return formatSpreadsheetDisplayValue(value, numberFormatCodeForCell(cell, styles));
|
|
16868
|
+
if (value !== null) return formatSpreadsheetDisplayValue(value, numberFormatCodeForCell(cell, styles), date1904);
|
|
16869
16869
|
return "";
|
|
16870
16870
|
}
|
|
16871
16871
|
__name(cellToDisplayText, "cellToDisplayText");
|
|
@@ -16874,13 +16874,13 @@ function numberFormatCodeForCell(cell, styles) {
|
|
|
16874
16874
|
return (_b = styles.cellFormats[(_a = cell.styleId) != null ? _a : 0]) == null ? void 0 : _b.numberFormatCode;
|
|
16875
16875
|
}
|
|
16876
16876
|
__name(numberFormatCodeForCell, "numberFormatCodeForCell");
|
|
16877
|
-
function formatSpreadsheetDisplayValue(value, formatCode) {
|
|
16877
|
+
function formatSpreadsheetDisplayValue(value, formatCode, date1904 = false) {
|
|
16878
16878
|
if (value === null) return "";
|
|
16879
16879
|
if (typeof value !== "number" || !formatCode) return String(value);
|
|
16880
16880
|
const normalized = formatCode.toLowerCase();
|
|
16881
16881
|
if (normalized.includes("%")) return `${formatFixedNumber(value * 100, decimalPlaces(formatCode))}%`;
|
|
16882
16882
|
if (normalized.includes("$")) return `$${formatFixedNumber(value, decimalPlaces(formatCode), true)}`;
|
|
16883
|
-
if (
|
|
16883
|
+
if (looksLikeDateTimeFormat(normalized)) return formatExcelSerialDateTime(value, normalized, date1904);
|
|
16884
16884
|
if (formatCode.includes(",")) return formatFixedNumber(value, decimalPlaces(formatCode), true);
|
|
16885
16885
|
if (formatCode.includes(".")) return formatFixedNumber(value, decimalPlaces(formatCode));
|
|
16886
16886
|
return String(value);
|
|
@@ -16900,20 +16900,71 @@ function formatFixedNumber(value, digits, grouping = false) {
|
|
|
16900
16900
|
}).format(value);
|
|
16901
16901
|
}
|
|
16902
16902
|
__name(formatFixedNumber, "formatFixedNumber");
|
|
16903
|
-
function
|
|
16903
|
+
function looksLikeDateTimeFormat(formatCode) {
|
|
16904
|
+
const knownFormats = [
|
|
16905
|
+
"d-mmm",
|
|
16906
|
+
"mmm-yy",
|
|
16907
|
+
"h:mm am/pm",
|
|
16908
|
+
"h:mm:ss am/pm",
|
|
16909
|
+
"h:mm",
|
|
16910
|
+
"h:mm:ss",
|
|
16911
|
+
"mm:ss",
|
|
16912
|
+
"[h]:mm:ss",
|
|
16913
|
+
"mmss.0"
|
|
16914
|
+
];
|
|
16915
|
+
if (knownFormats.includes(formatCode)) return true;
|
|
16904
16916
|
return /(^|[^a-z])y{2,4}([^a-z]|$)/.test(formatCode) && /(^|[^a-z])d{1,2}([^a-z]|$)/.test(formatCode);
|
|
16905
16917
|
}
|
|
16906
|
-
__name(
|
|
16907
|
-
function
|
|
16918
|
+
__name(looksLikeDateTimeFormat, "looksLikeDateTimeFormat");
|
|
16919
|
+
function formatExcelSerialDateTime(serial, formatCode, date1904) {
|
|
16908
16920
|
if (!Number.isFinite(serial)) return String(serial);
|
|
16909
|
-
const
|
|
16910
|
-
const
|
|
16911
|
-
const
|
|
16912
|
-
const
|
|
16913
|
-
const
|
|
16921
|
+
const wholeDays = Math.floor(serial);
|
|
16922
|
+
const dayFraction = serial - wholeDays;
|
|
16923
|
+
const totalSeconds = Math.round(dayFraction * 86400) % 86400;
|
|
16924
|
+
const hour = Math.floor(totalSeconds / 3600);
|
|
16925
|
+
const minute = Math.floor(totalSeconds % 3600 / 60);
|
|
16926
|
+
const second = totalSeconds % 60;
|
|
16927
|
+
const hour12 = hour % 12 || 12;
|
|
16928
|
+
const amPm = hour < 12 ? "AM" : "PM";
|
|
16929
|
+
const pad = /* @__PURE__ */ __name((value) => String(value).padStart(2, "0"), "pad");
|
|
16930
|
+
if (formatCode === "h:mm am/pm") return `${hour12}:${pad(minute)} ${amPm}`;
|
|
16931
|
+
if (formatCode === "h:mm:ss am/pm") return `${hour12}:${pad(minute)}:${pad(second)} ${amPm}`;
|
|
16932
|
+
if (formatCode === "h:mm") return `${hour}:${pad(minute)}`;
|
|
16933
|
+
if (formatCode === "h:mm:ss") return `${hour}:${pad(minute)}:${pad(second)}`;
|
|
16934
|
+
if (formatCode === "mm:ss") return `${pad(minute)}:${pad(second)}`;
|
|
16935
|
+
if (formatCode === "[h]:mm:ss") return `${Math.floor(serial * 24)}:${pad(minute)}:${pad(second)}`;
|
|
16936
|
+
if (formatCode === "mmss.0") return `${pad(minute)}${pad(second)}.0`;
|
|
16937
|
+
const phantomLeapDay = !date1904 && wholeDays === 60;
|
|
16938
|
+
const epoch = date1904 ? Date.UTC(1904, 0, 1) : Date.UTC(1899, 11, 30);
|
|
16939
|
+
const date = new Date(epoch + wholeDays * 864e5);
|
|
16940
|
+
const year = phantomLeapDay ? 1900 : date.getUTCFullYear();
|
|
16941
|
+
const monthNumber = phantomLeapDay ? 2 : date.getUTCMonth() + 1;
|
|
16942
|
+
const dayNumber = phantomLeapDay ? 29 : date.getUTCDate();
|
|
16943
|
+
const month = pad(monthNumber);
|
|
16944
|
+
const day = pad(dayNumber);
|
|
16945
|
+
const shortYear = pad(year % 100);
|
|
16946
|
+
const monthName = [
|
|
16947
|
+
"Jan",
|
|
16948
|
+
"Feb",
|
|
16949
|
+
"Mar",
|
|
16950
|
+
"Apr",
|
|
16951
|
+
"May",
|
|
16952
|
+
"Jun",
|
|
16953
|
+
"Jul",
|
|
16954
|
+
"Aug",
|
|
16955
|
+
"Sep",
|
|
16956
|
+
"Oct",
|
|
16957
|
+
"Nov",
|
|
16958
|
+
"Dec"
|
|
16959
|
+
][monthNumber - 1];
|
|
16960
|
+
if (formatCode === "mm-dd-yy") return `${month}-${day}-${shortYear}`;
|
|
16961
|
+
if (formatCode === "d-mmm-yy") return `${dayNumber}-${monthName}-${shortYear}`;
|
|
16962
|
+
if (formatCode === "d-mmm") return `${dayNumber}-${monthName}`;
|
|
16963
|
+
if (formatCode === "mmm-yy") return `${monthName}-${shortYear}`;
|
|
16964
|
+
if (formatCode === "m/d/yy h:mm") return `${monthNumber}/${dayNumber}/${shortYear} ${hour}:${pad(minute)}`;
|
|
16914
16965
|
return `${year}-${month}-${day}`;
|
|
16915
16966
|
}
|
|
16916
|
-
__name(
|
|
16967
|
+
__name(formatExcelSerialDateTime, "formatExcelSerialDateTime");
|
|
16917
16968
|
var DEFAULT_ROW_HEIGHT = 22;
|
|
16918
16969
|
var DEFAULT_COLUMN_WIDTH = 96;
|
|
16919
16970
|
var DEFAULT_ROW_HEADER_WIDTH = 48;
|
|
@@ -18354,7 +18405,10 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
18354
18405
|
activeSheetName: firstSheet.name,
|
|
18355
18406
|
formulaResults,
|
|
18356
18407
|
formulaEngine,
|
|
18357
|
-
activeSheet: buildSpreadsheetSheetRenderModel(firstSheet, model.styles, {
|
|
18408
|
+
activeSheet: buildSpreadsheetSheetRenderModel(firstSheet, model.styles, {
|
|
18409
|
+
formulaResults,
|
|
18410
|
+
date1904: model.date1904
|
|
18411
|
+
})
|
|
18358
18412
|
}, options);
|
|
18359
18413
|
}
|
|
18360
18414
|
isReadOnly() {
|
|
@@ -18445,7 +18499,8 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
18445
18499
|
this.state.formulaResults = formulaResults;
|
|
18446
18500
|
this.state.formulaEngine = formulaEngine;
|
|
18447
18501
|
this.state.activeSheet = buildSpreadsheetSheetRenderModel(sheet, this.state.model.styles, {
|
|
18448
|
-
formulaResults
|
|
18502
|
+
formulaResults,
|
|
18503
|
+
date1904: this.state.model.date1904
|
|
18449
18504
|
});
|
|
18450
18505
|
}
|
|
18451
18506
|
async addSheet(name) {
|
|
@@ -18503,7 +18558,10 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
18503
18558
|
activeSheetName: sheet.name,
|
|
18504
18559
|
formulaResults,
|
|
18505
18560
|
formulaEngine,
|
|
18506
|
-
activeSheet: buildSpreadsheetSheetRenderModel(sheet, model.styles, {
|
|
18561
|
+
activeSheet: buildSpreadsheetSheetRenderModel(sheet, model.styles, {
|
|
18562
|
+
formulaResults,
|
|
18563
|
+
date1904: model.date1904
|
|
18564
|
+
})
|
|
18507
18565
|
});
|
|
18508
18566
|
}
|
|
18509
18567
|
async setCellValue(address, value, historyOptions = {}) {
|
|
@@ -18958,7 +19016,7 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
18958
19016
|
this.state.activeSheet = buildSpreadsheetSheetRenderModel(
|
|
18959
19017
|
this.state.activeSheet.source,
|
|
18960
19018
|
this.state.model.styles,
|
|
18961
|
-
{ formulaResults: this.state.formulaResults }
|
|
19019
|
+
{ formulaResults: this.state.formulaResults, date1904: this.state.model.date1904 }
|
|
18962
19020
|
);
|
|
18963
19021
|
}
|
|
18964
19022
|
async runUserMutation(options, mutate) {
|