@fileverse-dev/fortune-core 1.3.2 → 1.3.4-date-format-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.
package/es/canvas.js CHANGED
@@ -1012,7 +1012,7 @@ var Canvas = function () {
1012
1012
  renderCtx.clip();
1013
1013
  renderCtx.scale(this.sheetCtx.zoomRatio, this.sheetCtx.zoomRatio);
1014
1014
  var measureText = getMeasureText(value, renderCtx, this.sheetCtx);
1015
- var textMetrics = measureText.width + 14;
1015
+ var textMetrics = measureText.width + 18;
1016
1016
  var oneLineTextHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
1017
1017
  var horizonAlignPos = pos_x + space_width;
1018
1018
  if (horizonAlign === 0) {
@@ -18,6 +18,7 @@ export declare function handleOverlayMouseUp(ctx: Context, globalCache: GlobalCa
18
18
  export declare function handleRowHeaderMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, container: HTMLDivElement, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null): void;
19
19
  export declare function handleColumnHeaderMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, container: HTMLElement, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null): void;
20
20
  export declare function handleColSizeHandleMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, headerContainer: HTMLDivElement, workbookContainer: HTMLDivElement, cellArea: HTMLDivElement): void;
21
+ export declare function handleColSizeHandleDoubleClick(ctx: Context, globalCache: GlobalCache, e: MouseEvent, headerContainer: HTMLDivElement): void;
21
22
  export declare function handleRowSizeHandleMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, headerContainer: HTMLDivElement, workbookContainer: HTMLDivElement, cellArea: HTMLDivElement): void;
22
23
  export declare function handleColFreezeHandleMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, headerContainer: HTMLDivElement, workbookContainer: HTMLDivElement, cellArea: HTMLDivElement): void;
23
24
  export declare function handleRowFreezeHandleMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, headerContainer: HTMLDivElement, workbookContainer: HTMLDivElement, cellArea: HTMLDivElement): void;
@@ -11,6 +11,7 @@ import { onDropCellSelectEnd, onDropCellSelect } from "../modules/dropCell";
11
11
  import { handleFormulaInput, rangeDragColumn, rangeDragRow } from "../modules/formula";
12
12
  import { showLinkCard, onRangeSelectionModalMove, onRangeSelectionModalMoveEnd } from "../modules/hyperlink";
13
13
  import { onSearchDialogMove, onSearchDialogMoveEnd } from "../modules/searchReplace";
14
+ import { getColumnAutoFitWidth } from "../paste-helpers/calculate-range-cell-size";
14
15
  var mouseWheelUniqueTimeout;
15
16
  var scrollLockTimeout;
16
17
  export function handleGlobalWheel(ctx, e, cache, scrollbarX, scrollbarY) {
@@ -733,7 +734,6 @@ export function mouseRender(ctx, globalCache, e, cellInput, scrollX, scrollY, co
733
734
  return;
734
735
  }
735
736
  if (ctx.luckysheet_select_status) {
736
- console.log("ctx.scrollLeft", ctx.scrollLeft);
737
737
  var mouseX = e.pageX - rect.left - window.scrollX;
738
738
  var mouseY = e.pageY - rect.top - window.scrollY;
739
739
  var _x = mouseX - ctx.rowHeaderWidth + ctx.scrollLeft;
@@ -1669,6 +1669,55 @@ export function handleColSizeHandleMouseDown(ctx, globalCache, e, headerContaine
1669
1669
  ctx.luckysheet_cols_change_size_start = [_x, col_index];
1670
1670
  e.stopPropagation();
1671
1671
  }
1672
+ export function handleColSizeHandleDoubleClick(ctx, globalCache, e, headerContainer) {
1673
+ var _a, _b, _c, _d, _e, _f, _g;
1674
+ var scrollLeft = ctx.scrollLeft;
1675
+ var mouseX = e.pageX - headerContainer.getBoundingClientRect().left - window.scrollX;
1676
+ var _x = mouseX + scrollLeft;
1677
+ var freeze = (_a = globalCache.freezen) === null || _a === void 0 ? void 0 : _a[ctx.currentSheetId];
1678
+ var x = fixPositionOnFrozenCells(freeze, _x, 0, mouseX, 0).x;
1679
+ var col_location = colLocation(x, ctx.visibledatacolumn);
1680
+ var col_index = col_location[2];
1681
+ var cfg = ctx.config;
1682
+ if (cfg.columnlen == null) {
1683
+ cfg.columnlen = {};
1684
+ }
1685
+ if (cfg.customWidth == null) {
1686
+ cfg.customWidth = {};
1687
+ }
1688
+ var applyAutoFit = function applyAutoFit(colIdx) {
1689
+ var autoWidth = getColumnAutoFitWidth(ctx, colIdx);
1690
+ cfg.columnlen[colIdx] = autoWidth;
1691
+ cfg.customWidth[colIdx] = 1;
1692
+ };
1693
+ var changeColumnSelected = false;
1694
+ if (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0) {
1695
+ (_e = (_d = ctx.luckysheet_select_save) === null || _d === void 0 ? void 0 : _d.filter(function (select) {
1696
+ return select.column_select;
1697
+ })) === null || _e === void 0 ? void 0 : _e.some(function (select) {
1698
+ if (col_index >= select.column[0] && col_index <= select.column[1]) {
1699
+ changeColumnSelected = true;
1700
+ }
1701
+ return changeColumnSelected;
1702
+ });
1703
+ }
1704
+ if (changeColumnSelected) {
1705
+ (_g = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f.filter(function (select) {
1706
+ return select.column_select;
1707
+ })) === null || _g === void 0 ? void 0 : _g.forEach(function (select) {
1708
+ for (var c = select.column[0]; c <= select.column[1]; c += 1) {
1709
+ applyAutoFit(c);
1710
+ }
1711
+ });
1712
+ } else {
1713
+ applyAutoFit(col_index);
1714
+ }
1715
+ ctx.config = cfg;
1716
+ var idx = getSheetIndex(ctx, ctx.currentSheetId);
1717
+ if (idx == null) return;
1718
+ ctx.luckysheetfile[idx].config = ctx.config;
1719
+ e.stopPropagation();
1720
+ }
1672
1721
  export function handleRowSizeHandleMouseDown(ctx, globalCache, e, headerContainer, workbookContainer, cellArea) {
1673
1722
  var _a;
1674
1723
  removeEditingComment(ctx, globalCache);
@@ -110,7 +110,7 @@ export function getCellValue(r, c, data, attr) {
110
110
  return retv;
111
111
  }
112
112
  export function setCellValue(ctx, r, c, d, v) {
113
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
113
+ var _a, _b, _c, _d, _e, _f, _g;
114
114
  if (ctx.allowEdit === false || ctx.isFlvReadOnly) return;
115
115
  if (_.isNil(d)) {
116
116
  d = getFlowdata(ctx);
@@ -276,10 +276,7 @@ export function setCellValue(ctx, r, c, d, v) {
276
276
  } else if (!_.isNil(cell.ct) && !_.isNil(cell.ct.fa) && cell.ct.fa !== "General") {
277
277
  var fa = cell.ct.fa;
278
278
  if (isRealNum(vupdate)) {
279
- if (commaPresent && !fa.includes(",") || String(vupdate).includes(".") && ((_j = (_h = String(vupdate).split(".")) === null || _h === void 0 ? void 0 : _h[1]) === null || _j === void 0 ? void 0 : _j.length) !== ((_l = (_k = fa.split(".")) === null || _k === void 0 ? void 0 : _k[1]) === null || _l === void 0 ? void 0 : _l.length) || fa.includes(",") !== String(vupdate).includes(",")) {
280
- if (fa.includes(",") !== String(vupdate).includes(",")) {
281
- commaPresent = true;
282
- }
279
+ if (commaPresent && !fa.includes(",")) {
283
280
  fa = getNumberFormat(String(vupdate), commaPresent);
284
281
  }
285
282
  vupdate = parseFloat(vupdate);
@@ -289,6 +286,9 @@ export function setCellValue(ctx, r, c, d, v) {
289
286
  t: "n"
290
287
  });
291
288
  }
289
+ if (_.isNil(cell.ht)) {
290
+ cell.ht = 2;
291
+ }
292
292
  }
293
293
  var mask = update(fa, vupdate);
294
294
  if (mask === vupdate) {
@@ -317,7 +317,9 @@ export function setCellValue(ctx, r, c, d, v) {
317
317
  var strValue = String(vupdate);
318
318
  var format = getNumberFormat(strValue, commaPresent);
319
319
  cell.m = v.m ? v.m : update(format, cell.v);
320
- cell.ht = (v === null || v === void 0 ? void 0 : v.ht) ? cell.ht : 2;
320
+ if (_.isNil(cell.ht)) {
321
+ cell.ht = 2;
322
+ }
321
323
  cell.ct = {
322
324
  fa: format,
323
325
  t: "n"
package/es/modules/ssf.js CHANGED
@@ -1364,7 +1364,7 @@ var make_ssf = function make_ssf(SSF) {
1364
1364
  if (typeof n !== "number" || !Number.isFinite(n)) return null;
1365
1365
  if (!Number.isInteger(n)) return null;
1366
1366
  if (n < 0) return null;
1367
- var minSec = 0; // 1970-01-01
1367
+ var minSec = 100000; // Excel serial numbers max ~73050 for year 2100; avoids collision
1368
1368
  var maxSec = 4102444800; // ~2100-01-01
1369
1369
  var minMs = minSec * 1000;
1370
1370
  var maxMs = maxSec * 1000;
@@ -33,21 +33,42 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
33
33
  } else {
34
34
  value = cell;
35
35
  }
36
+ var type = "n";
37
+ if (is_date(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47) {
38
+ type = "d";
39
+ } else if (foucsStatus === "@" || foucsStatus === 49) {
40
+ type = "s";
41
+ }
36
42
  if (_.isNil(value)) {
43
+ if (!_.isNil(d[r])) {
44
+ if (_.isNil(d[r][c])) {
45
+ d[r][c] = {
46
+ ct: {
47
+ fa: foucsStatus,
48
+ t: type
49
+ }
50
+ };
51
+ } else if (_.isPlainObject(d[r][c])) {
52
+ if (_.isNil(d[r][c].ct)) d[r][c].ct = {};
53
+ d[r][c].ct.fa = foucsStatus;
54
+ d[r][c].ct.t = type;
55
+ }
56
+ }
37
57
  continue;
38
58
  }
39
59
  if (foucsStatus !== "@" && isRealNum(value)) {
40
60
  value = Number(value);
61
+ } else if (type === "d" && typeof value === "string") {
62
+ var dateMask = genarate(value);
63
+ if (dateMask && dateMask[1].t === "d") {
64
+ var numericSerial = dateMask[2];
65
+ value = numericSerial;
66
+ }
41
67
  }
42
- var mask = update(foucsStatus, value);
43
- var type = "n";
44
- if (is_date(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47) {
45
- type = "d";
46
- } else if (foucsStatus === "@" || foucsStatus === 49) {
47
- type = "s";
48
- } else if (foucsStatus === "General" || foucsStatus === 0) {
68
+ if (foucsStatus === "General" || foucsStatus === 0) {
49
69
  type = isRealNum(value) ? "n" : "g";
50
70
  }
71
+ var mask = update(foucsStatus, value);
51
72
  if (cell && _.isPlainObject(cell)) {
52
73
  cell.m = "".concat(mask);
53
74
  if (_.isNil(cell.ct)) {
@@ -55,7 +76,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
55
76
  }
56
77
  cell.ct.fa = foucsStatus;
57
78
  cell.ct.t = type;
58
- cell.v = String(value);
79
+ cell.v = typeof value === "number" ? value : String(value);
59
80
  cell.fc = cell.fc || ((_f = (_e = (_d = cell.ct) === null || _d === void 0 ? void 0 : _d.s) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.fc);
60
81
  cell.bl = cell.bl || ((_j = (_h = (_g = cell.ct) === null || _g === void 0 ? void 0 : _g.s) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.bl);
61
82
  cell.it = cell.it || ((_m = (_l = (_k = cell.ct) === null || _k === void 0 ? void 0 : _k.s) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.it);
@@ -68,7 +89,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
68
89
  fa: foucsStatus,
69
90
  t: type
70
91
  },
71
- v: value,
92
+ v: typeof value === "number" ? value : value,
72
93
  m: mask
73
94
  };
74
95
  }
@@ -727,7 +748,6 @@ export function handleVerticalAlign(ctx, cellInput, value) {
727
748
  setAttr(ctx, cellInput, "vt", value);
728
749
  }
729
750
  export function handleFormatPainter(ctx) {
730
- console.log("handleFormatPainter", ctx);
731
751
  var allowEdit = isAllowEdit(ctx);
732
752
  if (!allowEdit) return;
733
753
  if (ctx.luckysheet_select_save == null || ctx.luckysheet_select_save.length === 0) {
@@ -3,6 +3,7 @@ export declare function calculateRangeCellSize(ctx: Context, sheetId: string, st
3
3
  rowMax: Record<number, number>;
4
4
  colMax: Record<number, number>;
5
5
  };
6
+ export declare function getColumnAutoFitWidth(ctx: Context, colIndex: number): number;
6
7
  export declare const updateSheetCellSizes: (ctx: Context, sheetIndex: number, measurements: {
7
8
  rowMax: Record<number, number>;
8
9
  colMax: Record<number, number>;
@@ -101,6 +101,45 @@ export function calculateRangeCellSize(ctx, sheetId, startRow, endRow, startCol,
101
101
  colMax: maxColumnWidths
102
102
  };
103
103
  }
104
+ export function getColumnAutoFitWidth(ctx, colIndex) {
105
+ var _a, _b;
106
+ var flowdata = getFlowdata(ctx);
107
+ if (!flowdata) return ctx.defaultcollen;
108
+ var rowCount = flowdata.length;
109
+ var cellSizeMeasurer = document.getElementById("fs-cell-measurer");
110
+ if (!cellSizeMeasurer) {
111
+ cellSizeMeasurer = document.createElement("div");
112
+ cellSizeMeasurer.id = "fs-cell-measurer";
113
+ Object.assign(cellSizeMeasurer.style, {
114
+ position: "fixed",
115
+ left: "-99999px",
116
+ top: "-99999px",
117
+ visibility: "hidden",
118
+ lineHeight: "1.3",
119
+ whiteSpace: "pre",
120
+ wordBreak: "normal",
121
+ overflowWrap: "break-word"
122
+ });
123
+ document.body.appendChild(cellSizeMeasurer);
124
+ }
125
+ var maxWidth = ctx.defaultcollen;
126
+ for (var row = 0; row < rowCount; row++) {
127
+ var cell = (_a = flowdata[row]) === null || _a === void 0 ? void 0 : _a[colIndex];
128
+ if (!cell) continue;
129
+ if (cell.mc && cell.mc.rs == null) continue;
130
+ var text = getCellDisplayText(cell);
131
+ if (!text) continue;
132
+ applyFontOnMeasurer(cell, cellSizeMeasurer);
133
+ var fontSizePt = (_b = cell.fs) !== null && _b !== void 0 ? _b : ctx.defaultFontSize;
134
+ cellSizeMeasurer.style.fontSize = "".concat(fontSizePt, "pt");
135
+ cellSizeMeasurer.style.whiteSpace = "pre";
136
+ cellSizeMeasurer.style.width = "auto";
137
+ cellSizeMeasurer.textContent = text;
138
+ var intrinsicWidth = Math.ceil(cellSizeMeasurer.scrollWidth + 12);
139
+ if (intrinsicWidth > maxWidth) maxWidth = intrinsicWidth;
140
+ }
141
+ return maxWidth;
142
+ }
104
143
  export var updateSheetCellSizes = function updateSheetCellSizes(ctx, sheetIndex, measurements, maxColumnWidth) {
105
144
  var _a;
106
145
  if (maxColumnWidth === void 0) {
package/lib/canvas.js CHANGED
@@ -1019,7 +1019,7 @@ var Canvas = exports.Canvas = function () {
1019
1019
  renderCtx.clip();
1020
1020
  renderCtx.scale(this.sheetCtx.zoomRatio, this.sheetCtx.zoomRatio);
1021
1021
  var measureText = (0, _text.getMeasureText)(value, renderCtx, this.sheetCtx);
1022
- var textMetrics = measureText.width + 14;
1022
+ var textMetrics = measureText.width + 18;
1023
1023
  var oneLineTextHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
1024
1024
  var horizonAlignPos = pos_x + space_width;
1025
1025
  if (horizonAlign === 0) {
@@ -18,6 +18,7 @@ export declare function handleOverlayMouseUp(ctx: Context, globalCache: GlobalCa
18
18
  export declare function handleRowHeaderMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, container: HTMLDivElement, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null): void;
19
19
  export declare function handleColumnHeaderMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, container: HTMLElement, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null): void;
20
20
  export declare function handleColSizeHandleMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, headerContainer: HTMLDivElement, workbookContainer: HTMLDivElement, cellArea: HTMLDivElement): void;
21
+ export declare function handleColSizeHandleDoubleClick(ctx: Context, globalCache: GlobalCache, e: MouseEvent, headerContainer: HTMLDivElement): void;
21
22
  export declare function handleRowSizeHandleMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, headerContainer: HTMLDivElement, workbookContainer: HTMLDivElement, cellArea: HTMLDivElement): void;
22
23
  export declare function handleColFreezeHandleMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, headerContainer: HTMLDivElement, workbookContainer: HTMLDivElement, cellArea: HTMLDivElement): void;
23
24
  export declare function handleRowFreezeHandleMouseDown(ctx: Context, globalCache: GlobalCache, e: MouseEvent, headerContainer: HTMLDivElement, workbookContainer: HTMLDivElement, cellArea: HTMLDivElement): void;
@@ -7,6 +7,7 @@ exports.fixPositionOnFrozenCells = fixPositionOnFrozenCells;
7
7
  exports.handleCellAreaDoubleClick = handleCellAreaDoubleClick;
8
8
  exports.handleCellAreaMouseDown = handleCellAreaMouseDown;
9
9
  exports.handleColFreezeHandleMouseDown = handleColFreezeHandleMouseDown;
10
+ exports.handleColSizeHandleDoubleClick = handleColSizeHandleDoubleClick;
10
11
  exports.handleColSizeHandleMouseDown = handleColSizeHandleMouseDown;
11
12
  exports.handleColumnHeaderMouseDown = handleColumnHeaderMouseDown;
12
13
  exports.handleContextMenu = handleContextMenu;
@@ -30,6 +31,7 @@ var _dropCell = require("../modules/dropCell");
30
31
  var _formula = require("../modules/formula");
31
32
  var _hyperlink = require("../modules/hyperlink");
32
33
  var _searchReplace = require("../modules/searchReplace");
34
+ var _calculateRangeCellSize = require("../paste-helpers/calculate-range-cell-size");
33
35
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
34
36
  var mouseWheelUniqueTimeout;
35
37
  var scrollLockTimeout;
@@ -753,7 +755,6 @@ function mouseRender(ctx, globalCache, e, cellInput, scrollX, scrollY, container
753
755
  return;
754
756
  }
755
757
  if (ctx.luckysheet_select_status) {
756
- console.log("ctx.scrollLeft", ctx.scrollLeft);
757
758
  var mouseX = e.pageX - rect.left - window.scrollX;
758
759
  var mouseY = e.pageY - rect.top - window.scrollY;
759
760
  var _x = mouseX - ctx.rowHeaderWidth + ctx.scrollLeft;
@@ -1689,6 +1690,55 @@ function handleColSizeHandleMouseDown(ctx, globalCache, e, headerContainer, work
1689
1690
  ctx.luckysheet_cols_change_size_start = [_x, col_index];
1690
1691
  e.stopPropagation();
1691
1692
  }
1693
+ function handleColSizeHandleDoubleClick(ctx, globalCache, e, headerContainer) {
1694
+ var _a, _b, _c, _d, _e, _f, _g;
1695
+ var scrollLeft = ctx.scrollLeft;
1696
+ var mouseX = e.pageX - headerContainer.getBoundingClientRect().left - window.scrollX;
1697
+ var _x = mouseX + scrollLeft;
1698
+ var freeze = (_a = globalCache.freezen) === null || _a === void 0 ? void 0 : _a[ctx.currentSheetId];
1699
+ var x = fixPositionOnFrozenCells(freeze, _x, 0, mouseX, 0).x;
1700
+ var col_location = (0, _location.colLocation)(x, ctx.visibledatacolumn);
1701
+ var col_index = col_location[2];
1702
+ var cfg = ctx.config;
1703
+ if (cfg.columnlen == null) {
1704
+ cfg.columnlen = {};
1705
+ }
1706
+ if (cfg.customWidth == null) {
1707
+ cfg.customWidth = {};
1708
+ }
1709
+ var applyAutoFit = function applyAutoFit(colIdx) {
1710
+ var autoWidth = (0, _calculateRangeCellSize.getColumnAutoFitWidth)(ctx, colIdx);
1711
+ cfg.columnlen[colIdx] = autoWidth;
1712
+ cfg.customWidth[colIdx] = 1;
1713
+ };
1714
+ var changeColumnSelected = false;
1715
+ if (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0) {
1716
+ (_e = (_d = ctx.luckysheet_select_save) === null || _d === void 0 ? void 0 : _d.filter(function (select) {
1717
+ return select.column_select;
1718
+ })) === null || _e === void 0 ? void 0 : _e.some(function (select) {
1719
+ if (col_index >= select.column[0] && col_index <= select.column[1]) {
1720
+ changeColumnSelected = true;
1721
+ }
1722
+ return changeColumnSelected;
1723
+ });
1724
+ }
1725
+ if (changeColumnSelected) {
1726
+ (_g = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f.filter(function (select) {
1727
+ return select.column_select;
1728
+ })) === null || _g === void 0 ? void 0 : _g.forEach(function (select) {
1729
+ for (var c = select.column[0]; c <= select.column[1]; c += 1) {
1730
+ applyAutoFit(c);
1731
+ }
1732
+ });
1733
+ } else {
1734
+ applyAutoFit(col_index);
1735
+ }
1736
+ ctx.config = cfg;
1737
+ var idx = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
1738
+ if (idx == null) return;
1739
+ ctx.luckysheetfile[idx].config = ctx.config;
1740
+ e.stopPropagation();
1741
+ }
1692
1742
  function handleRowSizeHandleMouseDown(ctx, globalCache, e, headerContainer, workbookContainer, cellArea) {
1693
1743
  var _a;
1694
1744
  (0, _modules.removeEditingComment)(ctx, globalCache);
@@ -143,7 +143,7 @@ function getCellValue(r, c, data, attr) {
143
143
  return retv;
144
144
  }
145
145
  function setCellValue(ctx, r, c, d, v) {
146
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
146
+ var _a, _b, _c, _d, _e, _f, _g;
147
147
  if (ctx.allowEdit === false || ctx.isFlvReadOnly) return;
148
148
  if (_lodash.default.isNil(d)) {
149
149
  d = (0, _context.getFlowdata)(ctx);
@@ -309,10 +309,7 @@ function setCellValue(ctx, r, c, d, v) {
309
309
  } else if (!_lodash.default.isNil(cell.ct) && !_lodash.default.isNil(cell.ct.fa) && cell.ct.fa !== "General") {
310
310
  var fa = cell.ct.fa;
311
311
  if ((0, _validation.isRealNum)(vupdate)) {
312
- if (commaPresent && !fa.includes(",") || String(vupdate).includes(".") && ((_j = (_h = String(vupdate).split(".")) === null || _h === void 0 ? void 0 : _h[1]) === null || _j === void 0 ? void 0 : _j.length) !== ((_l = (_k = fa.split(".")) === null || _k === void 0 ? void 0 : _k[1]) === null || _l === void 0 ? void 0 : _l.length) || fa.includes(",") !== String(vupdate).includes(",")) {
313
- if (fa.includes(",") !== String(vupdate).includes(",")) {
314
- commaPresent = true;
315
- }
312
+ if (commaPresent && !fa.includes(",")) {
316
313
  fa = (0, _utils.getNumberFormat)(String(vupdate), commaPresent);
317
314
  }
318
315
  vupdate = parseFloat(vupdate);
@@ -322,6 +319,9 @@ function setCellValue(ctx, r, c, d, v) {
322
319
  t: "n"
323
320
  });
324
321
  }
322
+ if (_lodash.default.isNil(cell.ht)) {
323
+ cell.ht = 2;
324
+ }
325
325
  }
326
326
  var mask = (0, _format.update)(fa, vupdate);
327
327
  if (mask === vupdate) {
@@ -350,7 +350,9 @@ function setCellValue(ctx, r, c, d, v) {
350
350
  var strValue = String(vupdate);
351
351
  var format = (0, _utils.getNumberFormat)(strValue, commaPresent);
352
352
  cell.m = v.m ? v.m : (0, _format.update)(format, cell.v);
353
- cell.ht = (v === null || v === void 0 ? void 0 : v.ht) ? cell.ht : 2;
353
+ if (_lodash.default.isNil(cell.ht)) {
354
+ cell.ht = 2;
355
+ }
354
356
  cell.ct = {
355
357
  fa: format,
356
358
  t: "n"
@@ -1370,7 +1370,7 @@ var make_ssf = function make_ssf(SSF) {
1370
1370
  if (typeof n !== "number" || !Number.isFinite(n)) return null;
1371
1371
  if (!Number.isInteger(n)) return null;
1372
1372
  if (n < 0) return null;
1373
- var minSec = 0; // 1970-01-01
1373
+ var minSec = 100000; // Excel serial numbers max ~73050 for year 2100; avoids collision
1374
1374
  var maxSec = 4102444800; // ~2100-01-01
1375
1375
  var minMs = minSec * 1000;
1376
1376
  var maxMs = maxSec * 1000;
@@ -66,21 +66,42 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
66
66
  } else {
67
67
  value = cell;
68
68
  }
69
+ var type = "n";
70
+ if ((0, _format.is_date)(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47) {
71
+ type = "d";
72
+ } else if (foucsStatus === "@" || foucsStatus === 49) {
73
+ type = "s";
74
+ }
69
75
  if (_lodash.default.isNil(value)) {
76
+ if (!_lodash.default.isNil(d[r])) {
77
+ if (_lodash.default.isNil(d[r][c])) {
78
+ d[r][c] = {
79
+ ct: {
80
+ fa: foucsStatus,
81
+ t: type
82
+ }
83
+ };
84
+ } else if (_lodash.default.isPlainObject(d[r][c])) {
85
+ if (_lodash.default.isNil(d[r][c].ct)) d[r][c].ct = {};
86
+ d[r][c].ct.fa = foucsStatus;
87
+ d[r][c].ct.t = type;
88
+ }
89
+ }
70
90
  continue;
71
91
  }
72
92
  if (foucsStatus !== "@" && (0, _validation.isRealNum)(value)) {
73
93
  value = Number(value);
94
+ } else if (type === "d" && typeof value === "string") {
95
+ var dateMask = (0, _format.genarate)(value);
96
+ if (dateMask && dateMask[1].t === "d") {
97
+ var numericSerial = dateMask[2];
98
+ value = numericSerial;
99
+ }
74
100
  }
75
- var mask = (0, _format.update)(foucsStatus, value);
76
- var type = "n";
77
- if ((0, _format.is_date)(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47) {
78
- type = "d";
79
- } else if (foucsStatus === "@" || foucsStatus === 49) {
80
- type = "s";
81
- } else if (foucsStatus === "General" || foucsStatus === 0) {
101
+ if (foucsStatus === "General" || foucsStatus === 0) {
82
102
  type = (0, _validation.isRealNum)(value) ? "n" : "g";
83
103
  }
104
+ var mask = (0, _format.update)(foucsStatus, value);
84
105
  if (cell && _lodash.default.isPlainObject(cell)) {
85
106
  cell.m = "".concat(mask);
86
107
  if (_lodash.default.isNil(cell.ct)) {
@@ -88,7 +109,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
88
109
  }
89
110
  cell.ct.fa = foucsStatus;
90
111
  cell.ct.t = type;
91
- cell.v = String(value);
112
+ cell.v = typeof value === "number" ? value : String(value);
92
113
  cell.fc = cell.fc || ((_f = (_e = (_d = cell.ct) === null || _d === void 0 ? void 0 : _d.s) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.fc);
93
114
  cell.bl = cell.bl || ((_j = (_h = (_g = cell.ct) === null || _g === void 0 ? void 0 : _g.s) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.bl);
94
115
  cell.it = cell.it || ((_m = (_l = (_k = cell.ct) === null || _k === void 0 ? void 0 : _k.s) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.it);
@@ -101,7 +122,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
101
122
  fa: foucsStatus,
102
123
  t: type
103
124
  },
104
- v: value,
125
+ v: typeof value === "number" ? value : value,
105
126
  m: mask
106
127
  };
107
128
  }
@@ -760,7 +781,6 @@ function handleVerticalAlign(ctx, cellInput, value) {
760
781
  setAttr(ctx, cellInput, "vt", value);
761
782
  }
762
783
  function handleFormatPainter(ctx) {
763
- console.log("handleFormatPainter", ctx);
764
784
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
765
785
  if (!allowEdit) return;
766
786
  if (ctx.luckysheet_select_save == null || ctx.luckysheet_select_save.length === 0) {
@@ -3,6 +3,7 @@ export declare function calculateRangeCellSize(ctx: Context, sheetId: string, st
3
3
  rowMax: Record<number, number>;
4
4
  colMax: Record<number, number>;
5
5
  };
6
+ export declare function getColumnAutoFitWidth(ctx: Context, colIndex: number): number;
6
7
  export declare const updateSheetCellSizes: (ctx: Context, sheetIndex: number, measurements: {
7
8
  rowMax: Record<number, number>;
8
9
  colMax: Record<number, number>;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.calculateRangeCellSize = calculateRangeCellSize;
7
+ exports.getColumnAutoFitWidth = getColumnAutoFitWidth;
7
8
  exports.updateSheetCellSizes = void 0;
8
9
  var _pasteTableHelpers = require("../paste-table-helpers");
9
10
  var _utils = require("../utils");
@@ -108,6 +109,45 @@ function calculateRangeCellSize(ctx, sheetId, startRow, endRow, startCol, endCol
108
109
  colMax: maxColumnWidths
109
110
  };
110
111
  }
112
+ function getColumnAutoFitWidth(ctx, colIndex) {
113
+ var _a, _b;
114
+ var flowdata = (0, _context.getFlowdata)(ctx);
115
+ if (!flowdata) return ctx.defaultcollen;
116
+ var rowCount = flowdata.length;
117
+ var cellSizeMeasurer = document.getElementById("fs-cell-measurer");
118
+ if (!cellSizeMeasurer) {
119
+ cellSizeMeasurer = document.createElement("div");
120
+ cellSizeMeasurer.id = "fs-cell-measurer";
121
+ Object.assign(cellSizeMeasurer.style, {
122
+ position: "fixed",
123
+ left: "-99999px",
124
+ top: "-99999px",
125
+ visibility: "hidden",
126
+ lineHeight: "1.3",
127
+ whiteSpace: "pre",
128
+ wordBreak: "normal",
129
+ overflowWrap: "break-word"
130
+ });
131
+ document.body.appendChild(cellSizeMeasurer);
132
+ }
133
+ var maxWidth = ctx.defaultcollen;
134
+ for (var row = 0; row < rowCount; row++) {
135
+ var cell = (_a = flowdata[row]) === null || _a === void 0 ? void 0 : _a[colIndex];
136
+ if (!cell) continue;
137
+ if (cell.mc && cell.mc.rs == null) continue;
138
+ var text = getCellDisplayText(cell);
139
+ if (!text) continue;
140
+ applyFontOnMeasurer(cell, cellSizeMeasurer);
141
+ var fontSizePt = (_b = cell.fs) !== null && _b !== void 0 ? _b : ctx.defaultFontSize;
142
+ cellSizeMeasurer.style.fontSize = "".concat(fontSizePt, "pt");
143
+ cellSizeMeasurer.style.whiteSpace = "pre";
144
+ cellSizeMeasurer.style.width = "auto";
145
+ cellSizeMeasurer.textContent = text;
146
+ var intrinsicWidth = Math.ceil(cellSizeMeasurer.scrollWidth + 12);
147
+ if (intrinsicWidth > maxWidth) maxWidth = intrinsicWidth;
148
+ }
149
+ return maxWidth;
150
+ }
111
151
  var updateSheetCellSizes = exports.updateSheetCellSizes = function updateSheetCellSizes(ctx, sheetIndex, measurements, maxColumnWidth) {
112
152
  var _a;
113
153
  if (maxColumnWidth === void 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.3.2",
3
+ "version": "1.3.4-date-format-1",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",