@fileverse-dev/fortune-core 1.3.2-format-1 → 1.3.3

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 + 18;
1015
+ var textMetrics = measureText.width + 14;
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) {
@@ -1668,6 +1669,55 @@ export function handleColSizeHandleMouseDown(ctx, globalCache, e, headerContaine
1668
1669
  ctx.luckysheet_cols_change_size_start = [_x, col_index];
1669
1670
  e.stopPropagation();
1670
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
+ }
1671
1721
  export function handleRowSizeHandleMouseDown(ctx, globalCache, e, headerContainer, workbookContainer, cellArea) {
1672
1722
  var _a;
1673
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;
113
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
114
114
  if (ctx.allowEdit === false || ctx.isFlvReadOnly) return;
115
115
  if (_.isNil(d)) {
116
116
  d = getFlowdata(ctx);
@@ -276,7 +276,10 @@ 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(",")) {
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
+ }
280
283
  fa = getNumberFormat(String(vupdate), commaPresent);
281
284
  }
282
285
  vupdate = parseFloat(vupdate);
@@ -286,9 +289,6 @@ export function setCellValue(ctx, r, c, d, v) {
286
289
  t: "n"
287
290
  });
288
291
  }
289
- if (!cell.ht) {
290
- cell.ht = 2;
291
- }
292
292
  }
293
293
  var mask = update(fa, vupdate);
294
294
  if (mask === vupdate) {
@@ -33,36 +33,21 @@ 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
- }
42
36
  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
- }
57
37
  continue;
58
38
  }
59
39
  if (foucsStatus !== "@" && isRealNum(value)) {
60
40
  value = Number(value);
61
41
  }
62
- if (foucsStatus === "General" || foucsStatus === 0) {
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) {
63
49
  type = isRealNum(value) ? "n" : "g";
64
50
  }
65
- var mask = update(foucsStatus, value);
66
51
  if (cell && _.isPlainObject(cell)) {
67
52
  cell.m = "".concat(mask);
68
53
  if (_.isNil(cell.ct)) {
@@ -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 + 18;
1022
+ var textMetrics = measureText.width + 14;
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;
@@ -1688,6 +1690,55 @@ function handleColSizeHandleMouseDown(ctx, globalCache, e, headerContainer, work
1688
1690
  ctx.luckysheet_cols_change_size_start = [_x, col_index];
1689
1691
  e.stopPropagation();
1690
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
+ }
1691
1742
  function handleRowSizeHandleMouseDown(ctx, globalCache, e, headerContainer, workbookContainer, cellArea) {
1692
1743
  var _a;
1693
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;
146
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
147
147
  if (ctx.allowEdit === false || ctx.isFlvReadOnly) return;
148
148
  if (_lodash.default.isNil(d)) {
149
149
  d = (0, _context.getFlowdata)(ctx);
@@ -309,7 +309,10 @@ 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(",")) {
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
+ }
313
316
  fa = (0, _utils.getNumberFormat)(String(vupdate), commaPresent);
314
317
  }
315
318
  vupdate = parseFloat(vupdate);
@@ -319,9 +322,6 @@ function setCellValue(ctx, r, c, d, v) {
319
322
  t: "n"
320
323
  });
321
324
  }
322
- if (!cell.ht) {
323
- cell.ht = 2;
324
- }
325
325
  }
326
326
  var mask = (0, _format.update)(fa, vupdate);
327
327
  if (mask === vupdate) {
@@ -66,36 +66,21 @@ 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
- }
75
69
  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
- }
90
70
  continue;
91
71
  }
92
72
  if (foucsStatus !== "@" && (0, _validation.isRealNum)(value)) {
93
73
  value = Number(value);
94
74
  }
95
- if (foucsStatus === "General" || foucsStatus === 0) {
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) {
96
82
  type = (0, _validation.isRealNum)(value) ? "n" : "g";
97
83
  }
98
- var mask = (0, _format.update)(foucsStatus, value);
99
84
  if (cell && _lodash.default.isPlainObject(cell)) {
100
85
  cell.m = "".concat(mask);
101
86
  if (_lodash.default.isNil(cell.ct)) {
@@ -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-format-1",
3
+ "version": "1.3.3",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",