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