@fileverse-dev/fortune-core 1.3.5-hyper-2 → 1.3.6

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.
@@ -12,7 +12,6 @@ var __assign = this && this.__assign || function () {
12
12
  import _ from "lodash";
13
13
  import { locale } from "./locale";
14
14
  import { getQKBorder, saveHyperlink } from "./modules";
15
- import { genarate } from "./modules/format";
16
15
  import { getSheetIndex } from "./utils";
17
16
  import { setRowHeight, setColumnWidth } from "./api";
18
17
  export var DEFAULT_FONT_SIZE = 12;
@@ -127,8 +126,7 @@ function brToNewline(str) {
127
126
  return str.replace(/<br\s*\/?>/gi, "\n");
128
127
  }
129
128
  var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
130
- var _a;
131
- var _b, _c, _d, _e;
129
+ var _a, _b, _c, _d;
132
130
  var cell = {};
133
131
  var rawText = (td.innerText || td.innerHTML || "").trim();
134
132
  var isLineBreak = rawText.includes("<br />");
@@ -146,22 +144,24 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
146
144
  })
147
145
  });
148
146
  } else {
149
- var mask = genarate(rawText);
150
- _a = mask || [], cell.m = _a[0], cell.ct = _a[1], cell.v = _a[2];
147
+ cell.v = rawText;
148
+ cell.m = rawText;
149
+ cell.ct = {
150
+ fa: "General",
151
+ t: "g"
152
+ };
151
153
  if (HEX_REGEX.test(rawText)) {
152
154
  cell.ct = {
153
155
  fa: "@",
154
156
  t: "s"
155
157
  };
156
- cell.m = rawText;
157
- cell.v = rawText;
158
158
  }
159
159
  }
160
- if (((_b = td.style) === null || _b === void 0 ? void 0 : _b.alignItems) === "center") {
160
+ if (((_a = td.style) === null || _a === void 0 ? void 0 : _a.alignItems) === "center") {
161
161
  cell.vt = 0;
162
- } else if (((_c = td.style) === null || _c === void 0 ? void 0 : _c.alignItems) === "flex-end") {
162
+ } else if (((_b = td.style) === null || _b === void 0 ? void 0 : _b.alignItems) === "flex-end") {
163
163
  cell.vt = 2;
164
- } else if (((_d = td.style) === null || _d === void 0 ? void 0 : _d.alignItems) === "flex-start") {
164
+ } else if (((_c = td.style) === null || _c === void 0 ? void 0 : _c.alignItems) === "flex-start") {
165
165
  cell.vt = 1;
166
166
  }
167
167
  var styleBlock = typeof classStyles[".".concat(td.className)] === "string" ? classStyles[".".concat(td.className)] : "";
@@ -188,7 +188,7 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
188
188
  } else {
189
189
  cell.ht = 1;
190
190
  }
191
- if (((_e = td === null || td === void 0 ? void 0 : td.style) === null || _e === void 0 ? void 0 : _e["overflow-wrap"]) === "anywhere") {
191
+ if (((_d = td === null || td === void 0 ? void 0 : td.style) === null || _d === void 0 ? void 0 : _d["overflow-wrap"]) === "anywhere") {
192
192
  cell.tb = "2";
193
193
  } else {
194
194
  cell.tb = "2";
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) {
@@ -220,14 +220,13 @@ var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
220
220
  }
221
221
  };
222
222
  function pasteHandler(ctx, data, borderInfo) {
223
- var _a;
224
- var _b, _c, _d, _e, _f, _g;
223
+ var _a, _b, _c, _d, _e, _f;
225
224
  if (ctx.luckysheet_selection_range) {
226
225
  ctx.luckysheet_selection_range = [];
227
226
  }
228
227
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
229
228
  if (!allowEdit || ctx.isFlvReadOnly) return;
230
- if (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) !== 1) {
229
+ if (((_b = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) !== 1) {
231
230
  return;
232
231
  }
233
232
  if (_typeof(data) === "object") {
@@ -276,7 +275,7 @@ function pasteHandler(ctx, data, borderInfo) {
276
275
  currentRowLen = cfg.rowlen[h];
277
276
  }
278
277
  for (var c = minc; c <= maxc; c += 1) {
279
- if ((_d = x === null || x === void 0 ? void 0 : x[c]) === null || _d === void 0 ? void 0 : _d.mc) {
278
+ if ((_c = x === null || x === void 0 ? void 0 : x[c]) === null || _c === void 0 ? void 0 : _c.mc) {
280
279
  if ("rs" in x[c].mc) {
281
280
  delete cfg.merge["".concat(x[c].mc.r, "_").concat(x[c].mc.c)];
282
281
  }
@@ -287,7 +286,7 @@ function pasteHandler(ctx, data, borderInfo) {
287
286
  value = data[h - minh][c - minc];
288
287
  }
289
288
  x[c] = value;
290
- if (value != null && ((_e = x === null || x === void 0 ? void 0 : x[c]) === null || _e === void 0 ? void 0 : _e.mc)) {
289
+ if (value != null && ((_d = x === null || x === void 0 ? void 0 : x[c]) === null || _d === void 0 ? void 0 : _d.mc)) {
291
290
  if (x[c].mc.rs != null) {
292
291
  x[c].mc.r = h;
293
292
  x[c].mc.c = c;
@@ -314,7 +313,7 @@ function pasteHandler(ctx, data, borderInfo) {
314
313
  b: borderInfo["".concat(h - minh, "_").concat(c - minc)].b
315
314
  }
316
315
  };
317
- (_f = cfg.borderInfo) === null || _f === void 0 ? void 0 : _f.push(bd_obj);
316
+ (_e = cfg.borderInfo) === null || _e === void 0 ? void 0 : _e.push(bd_obj);
318
317
  }
319
318
  }
320
319
  d[h] = x;
@@ -346,7 +345,7 @@ function pasteHandler(ctx, data, borderInfo) {
346
345
  }
347
346
  var d = (0, _context.getFlowdata)(ctx);
348
347
  if (!d) return;
349
- var last = (_g = ctx.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g[ctx.luckysheet_select_save.length - 1];
348
+ var last = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f[ctx.luckysheet_select_save.length - 1];
350
349
  if (!last) return;
351
350
  var curR = last.row == null ? 0 : last.row[0];
352
351
  var curC = last.column == null ? 0 : last.column[0];
@@ -387,9 +386,23 @@ function pasteHandler(ctx, data, borderInfo) {
387
386
  }
388
387
  }
389
388
  if (originCell) {
390
- originCell.v = isUrl ? originalValueStr : value;
389
+ if (originCell.ct && originCell.ct.t === "d" && !isUrl) {
390
+ var df = (0, _validation.detectDateFormat)(originalValueStr);
391
+ if (df) {
392
+ var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
393
+ originCell.v = (0, _format.datenum_local)(dateObj);
394
+ } else {
395
+ originCell.v = originalValueStr;
396
+ }
397
+ } else {
398
+ originCell.v = isUrl ? originalValueStr : value;
399
+ }
391
400
  if (originCell.ct != null && originCell.ct.fa != null) {
392
- originCell.m = (0, _format.update)(originCell.ct.fa, originCell.v);
401
+ if (originCell.ct.t === "d" && typeof originCell.v !== "number") {
402
+ originCell.m = String(originCell.v);
403
+ } else {
404
+ originCell.m = (0, _format.update)(originCell.ct.fa, originCell.v);
405
+ }
393
406
  } else {
394
407
  originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
395
408
  }
@@ -418,8 +431,12 @@ function pasteHandler(ctx, data, borderInfo) {
418
431
  t: "s"
419
432
  };
420
433
  } else {
421
- var mask = (0, _format.genarate)(value);
422
- _a = mask, cell.m = _a[0], cell.ct = _a[1], cell.v = _a[2];
434
+ cell.v = originalValueStr;
435
+ cell.m = originalValueStr;
436
+ cell.ct = {
437
+ fa: "General",
438
+ t: "g"
439
+ };
423
440
  if (/^0x?[a-fA-F0-9]+$/.test(value)) {
424
441
  cell.m = value;
425
442
  cell.ct = {
@@ -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"
@@ -21,29 +21,6 @@ function datenum_local(v, date1904) {
21
21
  if (date1904) epoch -= 1461 * 24 * 60 * 60 * 1000;else if (v >= base1904) epoch += 24 * 60 * 60 * 1000;
22
22
  return (epoch - dnthresh_utc) / (24 * 60 * 60 * 1000);
23
23
  }
24
- var good_pd_date = new Date("2017-02-19T19:06:09.000Z");
25
- if (Number.isNaN(good_pd_date.getFullYear())) good_pd_date = new Date("2/19/17");
26
- var good_pd = good_pd_date.getFullYear() === 2017;
27
- function parseDate(str, fixdate) {
28
- var d = new Date(str);
29
- if (good_pd) {
30
- if (!_lodash.default.isNil(fixdate)) {
31
- if (fixdate > 0) d.setTime(d.getTime() + d.getTimezoneOffset() * 60 * 1000);else if (fixdate < 0) d.setTime(d.getTime() - d.getTimezoneOffset() * 60 * 1000);
32
- }
33
- return d;
34
- }
35
- if (str instanceof Date) return str;
36
- if (good_pd_date.getFullYear() === 1917 && !Number.isNaN(d.getFullYear())) {
37
- var s = d.getFullYear();
38
- if (str.indexOf("".concat(s)) > -1) return d;
39
- d.setFullYear(d.getFullYear() + 100);
40
- return d;
41
- }
42
- var n = str.match(/\d+/g) || ["2017", "2", "19", "0", "0", "0"];
43
- var out = new Date(+n[0], +n[1] - 1, +n[2], +n[3] || 0, +n[4] || 0, +n[5] || 0);
44
- if (str.indexOf("Z") > -1) out = new Date(out.getTime() - out.getTimezoneOffset() * 60 * 1000);
45
- return out;
46
- }
47
24
  function genarate(value) {
48
25
  var m = null;
49
26
  var ct = {};
@@ -267,23 +244,37 @@ function genarate(value) {
267
244
  t: "n"
268
245
  };
269
246
  v = parseFloat(value);
270
- } else if ((0, _validation.isdatetime)(value) && (value.toString().indexOf(".") > -1 || value.toString().indexOf(":") > -1 || value.toString().length < 16)) {
271
- v = datenum_local(parseDate(value.toString().replace(/-/g, "/")));
272
- if (v.toString().indexOf(".") > -1) {
273
- if (value.toString().length > 18) {
274
- ct.fa = "yyyy-MM-dd hh:mm:ss";
275
- } else if (value.toString().length > 11) {
276
- ct.fa = "yyyy-MM-dd hh:mm";
277
- } else {
278
- ct.fa = "yyyy-MM-dd";
279
- }
247
+ } else if (typeof value === "string") {
248
+ var df = (0, _validation.detectDateFormat)(value.toString());
249
+ if (df) {
250
+ var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
251
+ v = datenum_local(dateObj);
252
+ ct.t = "d";
253
+ var map = {
254
+ "yyyy-MM-dd": "dd/MM/yyyy",
255
+ "yyyy-MM-dd HH:mm": "dd/MM/yyyy",
256
+ "yyyy-MM-ddTHH:mm": "dd/MM/yyyy",
257
+ "yyyy/MM/dd": "dd/MM/yyyy",
258
+ "yyyy/MM/dd HH:mm": "dd/MM/yyyy",
259
+ "yyyy.MM.dd": "yyyy.MM.dd",
260
+ "MM/dd/yyyy h:mm AM/PM": "MM/dd/yyyy h:mm AM/PM",
261
+ "MM/dd/yyyy": "MM/dd/yyyy",
262
+ "M/d/yyyy": "M/d/yyyy",
263
+ "MM/dd/yy": "MM/dd/yy",
264
+ "dd/MM/yyyy": "dd/MM/yyyy",
265
+ "dd-MM-yyyy": "dd/MM/yyyy",
266
+ "dd.MM.yyyy": "dd.MM.yyyy",
267
+ named: "dd/MM/yyyy"
268
+ };
269
+ ct.fa = map[df.formatType] || "dd/MM/yyyy";
270
+ m = _ssf.default.format(ct.fa, v);
280
271
  } else {
281
- ct.fa = "yyyy-MM-dd";
272
+ m = value.toString();
273
+ ct.fa = "General";
274
+ ct.t = "g";
282
275
  }
283
- ct.t = "d";
284
- m = _ssf.default.format(ct.fa, v);
285
276
  } else {
286
- m = value;
277
+ m = value.toString();
287
278
  ct.fa = "General";
288
279
  ct.t = "g";
289
280
  }
@@ -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;
@@ -36,8 +36,8 @@ var _context = require("../context");
36
36
  var _utils = require("../utils");
37
37
  var _cell = require("./cell");
38
38
  var _color = require("./color");
39
- var _format = require("./format");
40
39
  var _cursor = require("./cursor");
40
+ var _format = require("./format");
41
41
  var _formula2 = require("./formula");
42
42
  var _inlineString = require("./inline-string");
43
43
  var _location = require("./location");
@@ -67,21 +67,42 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
67
67
  } else {
68
68
  value = cell;
69
69
  }
70
+ var type = "n";
71
+ 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) {
72
+ type = "d";
73
+ } else if (foucsStatus === "@" || foucsStatus === 49) {
74
+ type = "s";
75
+ }
70
76
  if (_lodash.default.isNil(value)) {
77
+ if (!_lodash.default.isNil(d[r])) {
78
+ if (_lodash.default.isNil(d[r][c])) {
79
+ d[r][c] = {
80
+ ct: {
81
+ fa: foucsStatus,
82
+ t: type
83
+ }
84
+ };
85
+ } else if (_lodash.default.isPlainObject(d[r][c])) {
86
+ if (_lodash.default.isNil(d[r][c].ct)) d[r][c].ct = {};
87
+ d[r][c].ct.fa = foucsStatus;
88
+ d[r][c].ct.t = type;
89
+ }
90
+ }
71
91
  continue;
72
92
  }
73
93
  if (foucsStatus !== "@" && (0, _validation.isRealNum)(value)) {
74
94
  value = Number(value);
95
+ } else if (type === "d" && typeof value === "string") {
96
+ var dateInfo = (0, _validation.detectDateFormat)(value);
97
+ if (dateInfo) {
98
+ var dateObj = new Date(dateInfo.year, dateInfo.month - 1, dateInfo.day, dateInfo.hours, dateInfo.minutes, dateInfo.seconds);
99
+ value = (0, _format.datenum_local)(dateObj);
100
+ }
75
101
  }
76
- var mask = (0, _format.update)(foucsStatus, value);
77
- var type = "n";
78
- 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) {
79
- type = "d";
80
- } else if (foucsStatus === "@" || foucsStatus === 49) {
81
- type = "s";
82
- } else if (foucsStatus === "General" || foucsStatus === 0) {
102
+ if (foucsStatus === "General" || foucsStatus === 0) {
83
103
  type = (0, _validation.isRealNum)(value) ? "n" : "g";
84
104
  }
105
+ var mask = (0, _format.update)(foucsStatus, value);
85
106
  if (cell && _lodash.default.isPlainObject(cell)) {
86
107
  cell.m = "".concat(mask);
87
108
  if (_lodash.default.isNil(cell.ct)) {
@@ -89,7 +110,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
89
110
  }
90
111
  cell.ct.fa = foucsStatus;
91
112
  cell.ct.t = type;
92
- cell.v = String(value);
113
+ cell.v = typeof value === "number" ? value : String(value);
93
114
  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);
94
115
  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);
95
116
  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);
@@ -102,7 +123,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
102
123
  fa: foucsStatus,
103
124
  t: type
104
125
  },
105
- v: value,
126
+ v: typeof value === "number" ? value : value,
106
127
  m: mask
107
128
  };
108
129
  }
@@ -15,6 +15,16 @@ export declare function valueIsError(value: string): boolean;
15
15
  export declare function isRealNull(val: any): boolean;
16
16
  export declare function isHexValue(str: string): boolean;
17
17
  export declare function isRealNum(val: any): boolean;
18
+ export type DateFormatInfo = {
19
+ year: number;
20
+ month: number;
21
+ day: number;
22
+ hours: number;
23
+ minutes: number;
24
+ seconds: number;
25
+ formatType: string;
26
+ };
27
+ export declare function detectDateFormat(str: string): DateFormatInfo | null;
18
28
  export declare function isdatetime(s: any): boolean;
19
29
  export declare function diff(now: any, then: any): number;
20
30
  export declare function isdatatypemulti(s: any): any;