@fileverse-dev/fortune-core 1.3.5 → 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.
package/es/api/sheet.js CHANGED
@@ -1,3 +1,14 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var __assign = this && this.__assign || function () {
3
+ __assign = Object.assign || function (t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  import _ from "lodash";
2
13
  import { v4 as uuidv4 } from "uuid";
3
14
  import { dataToCelldata, getSheet } from "./common";
@@ -135,6 +146,7 @@ function generateCopySheetName(ctx, sheetId) {
135
146
  return sheetCopyName;
136
147
  }
137
148
  export function copySheet(ctx, sheetId) {
149
+ var _a, _b, _c;
138
150
  var index = getSheetIndex(ctx, sheetId);
139
151
  var order = ctx.luckysheetfile[index].order + 1;
140
152
  var sheetName = generateCopySheetName(ctx, sheetId);
@@ -144,8 +156,32 @@ export function copySheet(ctx, sheetId) {
144
156
  sheetData.celldata = dataToCelldata(sheetData.data);
145
157
  delete sheetData.data;
146
158
  api.addSheet(ctx, undefined, uuidv4(), ctx.luckysheetfile[index].isPivotTable, sheetName, sheetData);
159
+ var newSheetIndex = ctx.luckysheetfile.length - 1;
160
+ var newSheet = ctx.luckysheetfile[newSheetIndex];
161
+ var newSheetId = newSheet.id;
162
+ if ((_a = newSheet.calcChain) === null || _a === void 0 ? void 0 : _a.length) {
163
+ newSheet.calcChain = newSheet.calcChain.map(function (entry) {
164
+ return __assign(__assign({}, entry), {
165
+ id: newSheetId
166
+ });
167
+ });
168
+ }
169
+ if ((_b = newSheet.dynamicArray) === null || _b === void 0 ? void 0 : _b.length) {
170
+ newSheet.dynamicArray = newSheet.dynamicArray.map(function (entry) {
171
+ return entry && _typeof(entry) === "object" && "id" in entry ? __assign(__assign({}, entry), {
172
+ id: newSheetId
173
+ }) : entry;
174
+ });
175
+ }
176
+ if ((_c = newSheet.dynamicArray_compute) === null || _c === void 0 ? void 0 : _c.length) {
177
+ newSheet.dynamicArray_compute = newSheet.dynamicArray_compute.map(function (entry) {
178
+ return entry && _typeof(entry) === "object" && "id" in entry ? __assign(__assign({}, entry), {
179
+ id: newSheetId
180
+ }) : entry;
181
+ });
182
+ }
147
183
  var sheetOrderList = {};
148
- sheetOrderList[ctx.luckysheetfile[ctx.luckysheetfile.length - 1].id] = order;
184
+ sheetOrderList[newSheetId] = order;
149
185
  api.setSheetOrder(ctx, sheetOrderList);
150
186
  }
151
187
  export function calculateSheetFromula(ctx, id) {
@@ -173,23 +209,22 @@ export function calculateSheetFromula(ctx, id) {
173
209
  }
174
210
  }
175
211
  export function calculateReferencedCellSheetFromula(ctx, id, refCell) {
176
- var _a, _b, _c, _d, _e, _f;
212
+ var _a, _b, _c, _d, _e;
177
213
  var index = getSheetIndex(ctx, id);
178
214
  if (!ctx.luckysheetfile[index].data) return;
179
215
  var _loop_1 = function _loop_1(r) {
180
216
  var _loop_2 = function _loop_2(c) {
181
- console.log(refCell, (_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f);
182
217
  var isRef = false;
183
- if (refCell && ((_b = ctx.luckysheetfile[index].data[r][c]) === null || _b === void 0 ? void 0 : _b.f) && !((_c = ctx.luckysheetfile[index].data[r][c]) === null || _c === void 0 ? void 0 : _c.isDataBlockFormula)) {
218
+ if (refCell && ((_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f) && !((_b = ctx.luckysheetfile[index].data[r][c]) === null || _b === void 0 ? void 0 : _b.isDataBlockFormula)) {
184
219
  isRef = refCell.some(function (cell) {
185
220
  var _a;
186
221
  return isCellReferenced((_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f, cell);
187
222
  });
188
223
  }
189
- if (!isRef || !((_d = ctx.luckysheetfile[index].data[r][c]) === null || _d === void 0 ? void 0 : _d.f) || ((_e = ctx.luckysheetfile[index].data[r][c]) === null || _e === void 0 ? void 0 : _e.isDataBlockFormula)) {
224
+ if (!isRef || !((_c = ctx.luckysheetfile[index].data[r][c]) === null || _c === void 0 ? void 0 : _c.f) || ((_d = ctx.luckysheetfile[index].data[r][c]) === null || _d === void 0 ? void 0 : _d.isDataBlockFormula)) {
190
225
  return "continue";
191
226
  }
192
- var result = execfunction(ctx, (_f = ctx.luckysheetfile[index].data[r][c]) === null || _f === void 0 ? void 0 : _f.f, r, c, id);
227
+ var result = execfunction(ctx, (_e = ctx.luckysheetfile[index].data[r][c]) === null || _e === void 0 ? void 0 : _e.f, r, c, id);
193
228
  var isValueArray = Array.isArray(result[1]);
194
229
  if (isValueArray) {
195
230
  var value = {
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) {
@@ -139,7 +139,7 @@ export function handleGlobalEnter(ctx, cellInput, e, canvas) {
139
139
  row_focus: lastCellUpdate[0],
140
140
  column_focus: lastCellUpdate[1]
141
141
  }];
142
- moveHighlightCell(ctx, "down", 1, "rangeOfSelect");
142
+ moveHighlightCell(ctx, "down", hideCRCount(ctx, "ArrowDown"), "rangeOfSelect");
143
143
  e.preventDefault();
144
144
  } else {
145
145
  if (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0) {
@@ -434,9 +434,9 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
434
434
  updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
435
435
  }
436
436
  if (e.shiftKey) {
437
- moveHighlightCell(ctx, "right", -1, "rangeOfSelect");
437
+ moveHighlightCell(ctx, "right", -hideCRCount(ctx, "ArrowLeft"), "rangeOfSelect");
438
438
  } else {
439
- moveHighlightCell(ctx, "right", 1, "rangeOfSelect");
439
+ moveHighlightCell(ctx, "right", hideCRCount(ctx, "ArrowRight"), "rangeOfSelect");
440
440
  }
441
441
  e.preventDefault();
442
442
  } else if (kstr === "F2") {
@@ -145,7 +145,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
145
145
  _a = margeset.row, row_pre = _a[0], row = _a[1], row_index = _a[2], row_index_ed = _a[3];
146
146
  _b = margeset.column, col_pre = _b[0], col = _b[1], col_index = _b[2], col_index_ed = _b[3];
147
147
  }
148
- showLinkCard(ctx, row_index, col_index, false, true);
148
+ showLinkCard(ctx, row_index, col_index, undefined, false, true);
149
149
  if (((_e = (_d = ctx.hooks).beforeCellMouseDown) === null || _e === void 0 ? void 0 : _e.call(_d, (_f = flowdata[row_index]) === null || _f === void 0 ? void 0 : _f[col_index], {
150
150
  row: row_index,
151
151
  column: col_index,
@@ -34,10 +34,10 @@ import { handlePastedTable } from "../paste-table-helpers";
34
34
  import { getFlowdata } from "../context";
35
35
  import { execfunction } from "../modules/formula";
36
36
  import { getdatabyselection } from "../modules/cell";
37
- import { genarate, update } from "../modules/format";
37
+ import { update, datenum_local } from "../modules/format";
38
38
  import { normalizeSelection, selectionCache } from "../modules/selection";
39
39
  import { getSheetIndex, isAllowEdit } from "../utils";
40
- import { hasPartMC, isRealNum } from "../modules/validation";
40
+ import { hasPartMC, isRealNum, detectDateFormat } from "../modules/validation";
41
41
  import { getBorderInfoCompute } from "../modules/border";
42
42
  import { expandRowsAndColumns, storeSheetParamALL } from "../modules/sheet";
43
43
  import { jfrefreshgrid } from "../modules/refresh";
@@ -78,11 +78,9 @@ export function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow)
78
78
  var rowOffset = destRow - srcRow;
79
79
  var hadInvalid = false;
80
80
  var cellRefRegex = /\b(\$?)([A-Z]+)(\$?)(\d+)\b/g;
81
- var stringOrCellRef = /"(?:\\.|[^"])*"|(?<!\$)([A-Z]+\d+\b)/g;
81
+ var stringOrCellRef = /"(?:\\.|[^"])*"|(\$?[A-Z]+\$?\d+)(?!\s*!)\b/g;
82
82
  var result = formula.replace(stringOrCellRef, function (m, cellRef) {
83
83
  if (!cellRef) return m;
84
- if (cellRef.startsWith("$")) return m;
85
- console.log(m, "cellRef", cellRef);
86
84
  return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
87
85
  var colIndex = columnLabelIndex(colLetters);
88
86
  var rowIndex = parseInt(rowNum, 10);
@@ -209,14 +207,13 @@ var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
209
207
  }
210
208
  };
211
209
  function pasteHandler(ctx, data, borderInfo) {
212
- var _a;
213
- var _b, _c, _d, _e, _f, _g;
210
+ var _a, _b, _c, _d, _e, _f;
214
211
  if (ctx.luckysheet_selection_range) {
215
212
  ctx.luckysheet_selection_range = [];
216
213
  }
217
214
  var allowEdit = isAllowEdit(ctx);
218
215
  if (!allowEdit || ctx.isFlvReadOnly) return;
219
- if (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) !== 1) {
216
+ if (((_b = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) !== 1) {
220
217
  return;
221
218
  }
222
219
  if (_typeof(data) === "object") {
@@ -265,7 +262,7 @@ function pasteHandler(ctx, data, borderInfo) {
265
262
  currentRowLen = cfg.rowlen[h];
266
263
  }
267
264
  for (var c = minc; c <= maxc; c += 1) {
268
- if ((_d = x === null || x === void 0 ? void 0 : x[c]) === null || _d === void 0 ? void 0 : _d.mc) {
265
+ if ((_c = x === null || x === void 0 ? void 0 : x[c]) === null || _c === void 0 ? void 0 : _c.mc) {
269
266
  if ("rs" in x[c].mc) {
270
267
  delete cfg.merge["".concat(x[c].mc.r, "_").concat(x[c].mc.c)];
271
268
  }
@@ -276,7 +273,7 @@ function pasteHandler(ctx, data, borderInfo) {
276
273
  value = data[h - minh][c - minc];
277
274
  }
278
275
  x[c] = value;
279
- if (value != null && ((_e = x === null || x === void 0 ? void 0 : x[c]) === null || _e === void 0 ? void 0 : _e.mc)) {
276
+ if (value != null && ((_d = x === null || x === void 0 ? void 0 : x[c]) === null || _d === void 0 ? void 0 : _d.mc)) {
280
277
  if (x[c].mc.rs != null) {
281
278
  x[c].mc.r = h;
282
279
  x[c].mc.c = c;
@@ -303,7 +300,7 @@ function pasteHandler(ctx, data, borderInfo) {
303
300
  b: borderInfo["".concat(h - minh, "_").concat(c - minc)].b
304
301
  }
305
302
  };
306
- (_f = cfg.borderInfo) === null || _f === void 0 ? void 0 : _f.push(bd_obj);
303
+ (_e = cfg.borderInfo) === null || _e === void 0 ? void 0 : _e.push(bd_obj);
307
304
  }
308
305
  }
309
306
  d[h] = x;
@@ -335,7 +332,7 @@ function pasteHandler(ctx, data, borderInfo) {
335
332
  }
336
333
  var d = getFlowdata(ctx);
337
334
  if (!d) return;
338
- var last = (_g = ctx.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g[ctx.luckysheet_select_save.length - 1];
335
+ var last = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f[ctx.luckysheet_select_save.length - 1];
339
336
  if (!last) return;
340
337
  var curR = last.row == null ? 0 : last.row[0];
341
338
  var curC = last.column == null ? 0 : last.column[0];
@@ -376,9 +373,23 @@ function pasteHandler(ctx, data, borderInfo) {
376
373
  }
377
374
  }
378
375
  if (originCell) {
379
- originCell.v = isUrl ? originalValueStr : value;
376
+ if (originCell.ct && originCell.ct.t === "d" && !isUrl) {
377
+ var df = detectDateFormat(originalValueStr);
378
+ if (df) {
379
+ var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
380
+ originCell.v = datenum_local(dateObj);
381
+ } else {
382
+ originCell.v = originalValueStr;
383
+ }
384
+ } else {
385
+ originCell.v = isUrl ? originalValueStr : value;
386
+ }
380
387
  if (originCell.ct != null && originCell.ct.fa != null) {
381
- originCell.m = update(originCell.ct.fa, originCell.v);
388
+ if (originCell.ct.t === "d" && typeof originCell.v !== "number") {
389
+ originCell.m = String(originCell.v);
390
+ } else {
391
+ originCell.m = update(originCell.ct.fa, originCell.v);
392
+ }
382
393
  } else {
383
394
  originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
384
395
  }
@@ -407,8 +418,12 @@ function pasteHandler(ctx, data, borderInfo) {
407
418
  t: "s"
408
419
  };
409
420
  } else {
410
- var mask = genarate(value);
411
- _a = mask, cell.m = _a[0], cell.ct = _a[1], cell.v = _a[2];
421
+ cell.v = originalValueStr;
422
+ cell.m = originalValueStr;
423
+ cell.ct = {
424
+ fa: "General",
425
+ t: "g"
426
+ };
412
427
  if (/^0x?[a-fA-F0-9]+$/.test(value)) {
413
428
  cell.m = value;
414
429
  cell.ct = {
@@ -1011,9 +1026,10 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
1011
1026
  if (!_.isNil(value) && !_.isNil(value.f)) {
1012
1027
  var adjustedFormula = value.f;
1013
1028
  var isError = false;
1029
+ var srcRow = c_r1 + (h - mth);
1030
+ var srcCol = c_c1 + (c - mtc);
1014
1031
  try {
1015
- adjustedFormula = adjustFormulaForPaste(value.f, c_c1, c_r1, c, h);
1016
- console.log("adjustedFormula", adjustedFormula);
1032
+ adjustedFormula = adjustFormulaForPaste(value.f, srcCol, srcRow, c, h);
1017
1033
  } catch (error) {
1018
1034
  isError = true;
1019
1035
  value.error = {
@@ -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"
@@ -6,3 +6,4 @@ export declare function getSelectionCharacterOffsets(element: Node): {
6
6
  end: number;
7
7
  } | null;
8
8
  export declare function setSelectionByCharacterOffset(element: HTMLDivElement, start: number, end: number): void;
9
+ export declare function getRangeRectsByCharacterOffset(element: HTMLDivElement, start: number, end: number): DOMRect[];
@@ -114,4 +114,39 @@ export function setSelectionByCharacterOffset(element, start, end) {
114
114
  sel.removeAllRanges();
115
115
  sel.addRange(range);
116
116
  }
117
+ }
118
+ export function getRangeRectsByCharacterOffset(element, start, end) {
119
+ if (start >= end) return [];
120
+ var charIndex = 0;
121
+ var startNode = null;
122
+ var startOffset = 0;
123
+ var endNode = null;
124
+ var endOffset = 0;
125
+ function walk(node) {
126
+ if (node.nodeType === Node.TEXT_NODE) {
127
+ var len = (node.textContent || "").length;
128
+ if (startNode == null && charIndex + len > start) {
129
+ startNode = node;
130
+ startOffset = start - charIndex;
131
+ }
132
+ if (endNode == null && charIndex + len >= end) {
133
+ endNode = node;
134
+ endOffset = end - charIndex;
135
+ return true;
136
+ }
137
+ charIndex += len;
138
+ return false;
139
+ }
140
+ for (var i = 0; i < node.childNodes.length; i += 1) {
141
+ if (walk(node.childNodes[i])) return true;
142
+ }
143
+ return false;
144
+ }
145
+ walk(element);
146
+ if (!startNode || !endNode) return [];
147
+ var range = document.createRange();
148
+ range.setStart(startNode, startOffset);
149
+ range.setEnd(endNode, endOffset);
150
+ var rects = range.getClientRects();
151
+ return Array.from(rects);
117
152
  }
@@ -1,6 +1,6 @@
1
1
  import numeral from "numeral";
2
2
  import _ from "lodash";
3
- import { isRealNum, valueIsError, isdatetime } from "./validation";
3
+ import { isRealNum, valueIsError, detectDateFormat } from "./validation";
4
4
  import SSF from "./ssf";
5
5
  import { getCellValue } from "./cell";
6
6
  var base1904 = new Date(1900, 2, 1, 0, 0, 0);
@@ -10,29 +10,6 @@ export function datenum_local(v, date1904) {
10
10
  if (date1904) epoch -= 1461 * 24 * 60 * 60 * 1000;else if (v >= base1904) epoch += 24 * 60 * 60 * 1000;
11
11
  return (epoch - dnthresh_utc) / (24 * 60 * 60 * 1000);
12
12
  }
13
- var good_pd_date = new Date("2017-02-19T19:06:09.000Z");
14
- if (Number.isNaN(good_pd_date.getFullYear())) good_pd_date = new Date("2/19/17");
15
- var good_pd = good_pd_date.getFullYear() === 2017;
16
- function parseDate(str, fixdate) {
17
- var d = new Date(str);
18
- if (good_pd) {
19
- if (!_.isNil(fixdate)) {
20
- if (fixdate > 0) d.setTime(d.getTime() + d.getTimezoneOffset() * 60 * 1000);else if (fixdate < 0) d.setTime(d.getTime() - d.getTimezoneOffset() * 60 * 1000);
21
- }
22
- return d;
23
- }
24
- if (str instanceof Date) return str;
25
- if (good_pd_date.getFullYear() === 1917 && !Number.isNaN(d.getFullYear())) {
26
- var s = d.getFullYear();
27
- if (str.indexOf("".concat(s)) > -1) return d;
28
- d.setFullYear(d.getFullYear() + 100);
29
- return d;
30
- }
31
- var n = str.match(/\d+/g) || ["2017", "2", "19", "0", "0", "0"];
32
- var out = new Date(+n[0], +n[1] - 1, +n[2], +n[3] || 0, +n[4] || 0, +n[5] || 0);
33
- if (str.indexOf("Z") > -1) out = new Date(out.getTime() - out.getTimezoneOffset() * 60 * 1000);
34
- return out;
35
- }
36
13
  export function genarate(value) {
37
14
  var m = null;
38
15
  var ct = {};
@@ -256,23 +233,37 @@ export function genarate(value) {
256
233
  t: "n"
257
234
  };
258
235
  v = parseFloat(value);
259
- } else if (isdatetime(value) && (value.toString().indexOf(".") > -1 || value.toString().indexOf(":") > -1 || value.toString().length < 16)) {
260
- v = datenum_local(parseDate(value.toString().replace(/-/g, "/")));
261
- if (v.toString().indexOf(".") > -1) {
262
- if (value.toString().length > 18) {
263
- ct.fa = "yyyy-MM-dd hh:mm:ss";
264
- } else if (value.toString().length > 11) {
265
- ct.fa = "yyyy-MM-dd hh:mm";
266
- } else {
267
- ct.fa = "yyyy-MM-dd";
268
- }
236
+ } else if (typeof value === "string") {
237
+ var df = detectDateFormat(value.toString());
238
+ if (df) {
239
+ var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
240
+ v = datenum_local(dateObj);
241
+ ct.t = "d";
242
+ var map = {
243
+ "yyyy-MM-dd": "dd/MM/yyyy",
244
+ "yyyy-MM-dd HH:mm": "dd/MM/yyyy",
245
+ "yyyy-MM-ddTHH:mm": "dd/MM/yyyy",
246
+ "yyyy/MM/dd": "dd/MM/yyyy",
247
+ "yyyy/MM/dd HH:mm": "dd/MM/yyyy",
248
+ "yyyy.MM.dd": "yyyy.MM.dd",
249
+ "MM/dd/yyyy h:mm AM/PM": "MM/dd/yyyy h:mm AM/PM",
250
+ "MM/dd/yyyy": "MM/dd/yyyy",
251
+ "M/d/yyyy": "M/d/yyyy",
252
+ "MM/dd/yy": "MM/dd/yy",
253
+ "dd/MM/yyyy": "dd/MM/yyyy",
254
+ "dd-MM-yyyy": "dd/MM/yyyy",
255
+ "dd.MM.yyyy": "dd.MM.yyyy",
256
+ named: "dd/MM/yyyy"
257
+ };
258
+ ct.fa = map[df.formatType] || "dd/MM/yyyy";
259
+ m = SSF.format(ct.fa, v);
269
260
  } else {
270
- ct.fa = "yyyy-MM-dd";
261
+ m = value.toString();
262
+ ct.fa = "General";
263
+ ct.t = "g";
271
264
  }
272
- ct.t = "d";
273
- m = SSF.format(ct.fa, v);
274
265
  } else {
275
- m = value;
266
+ m = value.toString();
276
267
  ct.fa = "General";
277
268
  ct.t = "g";
278
269
  }
@@ -13,14 +13,14 @@ export declare function saveHyperlink(ctx: Context, r: number, c: number, linkTe
13
13
  cellInput?: HTMLDivElement | null;
14
14
  }): void;
15
15
  export declare function removeHyperlink(ctx: Context, r: number, c: number): void;
16
- export declare function showLinkCard(ctx: Context, r: number, c: number, isEditing?: boolean, isMouseDown?: boolean, options?: {
16
+ export declare function showLinkCard(ctx: Context, r: number, c: number, options?: {
17
17
  applyToSelection?: boolean;
18
18
  originText?: string;
19
19
  selectionOffsets?: {
20
20
  start: number;
21
21
  end: number;
22
22
  };
23
- }): void;
23
+ }, isEditing?: boolean, isMouseDown?: boolean): void;
24
24
  export declare function goToLink(ctx: Context, r: number, c: number, linkType: string, linkAddress: string, scrollbarX: HTMLDivElement, scrollbarY: HTMLDivElement): void;
25
25
  export declare function isLinkValid(ctx: Context, linkType: string, linkAddress: string): {
26
26
  isValid: boolean;
@@ -111,7 +111,7 @@ export function removeHyperlink(ctx, r, c) {
111
111
  }
112
112
  ctx.linkCard = undefined;
113
113
  }
114
- export function showLinkCard(ctx, r, c, isEditing, isMouseDown, options) {
114
+ export function showLinkCard(ctx, r, c, options, isEditing, isMouseDown) {
115
115
  var _a, _b, _c, _d, _e, _f, _g, _h;
116
116
  if (isEditing === void 0) {
117
117
  isEditing = false;
@@ -130,7 +130,11 @@ export function showLinkCard(ctx, r, c, isEditing, isMouseDown, options) {
130
130
  if (isEditing || link != null && (!((_f = ctx.linkCard) === null || _f === void 0 ? void 0 : _f.isEditing) || isMouseDown) || ((_g = ctx.linkCard) === null || _g === void 0 ? void 0 : _g.sheetId) !== ctx.currentSheetId) {
131
131
  var col_pre = c - 1 === -1 ? 0 : ctx.visibledatacolumn[c - 1];
132
132
  var row = ctx.visibledatarow[r];
133
- var originText = (options === null || options === void 0 ? void 0 : options.originText) !== undefined ? options.originText : (cell === null || cell === void 0 ? void 0 : cell.v) == null ? "" : "".concat(cell.v);
133
+ var originText = function () {
134
+ if ((options === null || options === void 0 ? void 0 : options.originText) !== undefined) return options.originText;
135
+ if ((cell === null || cell === void 0 ? void 0 : cell.v) == null) return "";
136
+ return "".concat(cell.v);
137
+ }();
134
138
  ctx.linkCard = {
135
139
  sheetId: ctx.currentSheetId,
136
140
  r: r,
@@ -1613,6 +1613,7 @@ export function deleteSelectedCellFormat(ctx) {
1613
1613
  return "success";
1614
1614
  }
1615
1615
  export function fillRightData(ctx) {
1616
+ var _a, _b;
1616
1617
  var allowEdit = isAllowEdit(ctx);
1617
1618
  if (allowEdit === false) {
1618
1619
  return "allowEdit";
@@ -1640,10 +1641,20 @@ export function fillRightData(ctx) {
1640
1641
  var r2 = selection[s].row[1];
1641
1642
  var c1 = selection[s].column[0];
1642
1643
  var c2 = selection[s].column[1];
1643
- for (var r = r1; r <= r2; r += 1) {
1644
- for (var c = c1; c <= c2; c += 1) {
1645
- var previousCell = d[r][c - 1];
1646
- d[r][c] = __assign({}, previousCell);
1644
+ var isSingleCell = r1 === r2 && c1 === c2;
1645
+ if (isSingleCell) {
1646
+ if (c1 - 1 >= 0 && d[r1]) {
1647
+ var prev = d[r1][c1 - 1];
1648
+ d[r1][c1] = prev != null ? __assign({}, prev) : {};
1649
+ }
1650
+ } else {
1651
+ for (var r = r1; r <= r2; r += 1) {
1652
+ var sourceCell = (_a = d[r]) === null || _a === void 0 ? void 0 : _a[c1];
1653
+ for (var c = c1 + 1; c <= c2; c += 1) {
1654
+ if (d[r]) {
1655
+ d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (_b = d[r][c]) !== null && _b !== void 0 ? _b : {};
1656
+ }
1657
+ }
1647
1658
  }
1648
1659
  }
1649
1660
  }
@@ -1651,6 +1662,7 @@ export function fillRightData(ctx) {
1651
1662
  return "success";
1652
1663
  }
1653
1664
  export function fillDownData(ctx) {
1665
+ var _a, _b;
1654
1666
  var allowEdit = isAllowEdit(ctx);
1655
1667
  if (allowEdit === false) {
1656
1668
  return "allowEdit";
@@ -1678,10 +1690,20 @@ export function fillDownData(ctx) {
1678
1690
  var r2 = selection[s].row[1];
1679
1691
  var c1 = selection[s].column[0];
1680
1692
  var c2 = selection[s].column[1];
1681
- for (var r = r1; r <= r2; r += 1) {
1693
+ var isSingleCell = r1 === r2 && c1 === c2;
1694
+ if (isSingleCell) {
1695
+ if (r1 - 1 >= 0 && d[r1 - 1]) {
1696
+ var prev = d[r1 - 1][c1];
1697
+ if (!d[r1]) d[r1] = [];
1698
+ d[r1][c1] = prev != null ? __assign({}, prev) : {};
1699
+ }
1700
+ } else {
1682
1701
  for (var c = c1; c <= c2; c += 1) {
1683
- var previousCell = d[r - 1][c];
1684
- d[r][c] = __assign({}, previousCell);
1702
+ var sourceCell = (_a = d[r1]) === null || _a === void 0 ? void 0 : _a[c];
1703
+ for (var r = r1 + 1; r <= r2; r += 1) {
1704
+ if (!d[r]) d[r] = [];
1705
+ d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (_b = d[r][c]) !== null && _b !== void 0 ? _b : {};
1706
+ }
1685
1707
  }
1686
1708
  }
1687
1709
  }
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;
@@ -4,14 +4,14 @@ import { getFlowdata } from "../context";
4
4
  import { getSheetIndex, isAllowEdit, getLineCount } from "../utils";
5
5
  import { getRangetxt, isAllSelectedCellsInStatus, normalizedAttr, setCellValue } from "./cell";
6
6
  import { colors } from "./color";
7
- import { genarate, is_date, update } from "./format";
8
7
  import { getSelectionCharacterOffsets } from "./cursor";
8
+ import { datenum_local, genarate, is_date, update } from "./format";
9
9
  import { execfunction, execFunctionGroup, israngeseleciton, rangeSetValue, setCaretPosition, createFormulaRangeSelect } from "./formula";
10
10
  import { inlineStyleAffectAttribute, updateInlineStringFormat, updateInlineStringFormatOutside } from "./inline-string";
11
11
  import { colLocationByIndex, rowLocationByIndex } from "./location";
12
12
  import { normalizeSelection, selectionCopyShow, selectIsOverlap } from "./selection";
13
13
  import { sortSelection } from "./sort";
14
- import { hasPartMC, isdatatypemulti, isRealNull, isRealNum } from "./validation";
14
+ import { detectDateFormat, hasPartMC, isdatatypemulti, isRealNull, isRealNum } from "./validation";
15
15
  import { showLinkCard } from "./hyperlink";
16
16
  import { cfSplitRange } from "./conditionalFormat";
17
17
  import { clearMeasureTextCache, getCellTextInfo } from "./text";
@@ -34,21 +34,42 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
34
34
  } else {
35
35
  value = cell;
36
36
  }
37
+ var type = "n";
38
+ 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) {
39
+ type = "d";
40
+ } else if (foucsStatus === "@" || foucsStatus === 49) {
41
+ type = "s";
42
+ }
37
43
  if (_.isNil(value)) {
44
+ if (!_.isNil(d[r])) {
45
+ if (_.isNil(d[r][c])) {
46
+ d[r][c] = {
47
+ ct: {
48
+ fa: foucsStatus,
49
+ t: type
50
+ }
51
+ };
52
+ } else if (_.isPlainObject(d[r][c])) {
53
+ if (_.isNil(d[r][c].ct)) d[r][c].ct = {};
54
+ d[r][c].ct.fa = foucsStatus;
55
+ d[r][c].ct.t = type;
56
+ }
57
+ }
38
58
  continue;
39
59
  }
40
60
  if (foucsStatus !== "@" && isRealNum(value)) {
41
61
  value = Number(value);
62
+ } else if (type === "d" && typeof value === "string") {
63
+ var dateInfo = detectDateFormat(value);
64
+ if (dateInfo) {
65
+ var dateObj = new Date(dateInfo.year, dateInfo.month - 1, dateInfo.day, dateInfo.hours, dateInfo.minutes, dateInfo.seconds);
66
+ value = datenum_local(dateObj);
67
+ }
42
68
  }
43
- var mask = update(foucsStatus, value);
44
- var type = "n";
45
- 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) {
46
- type = "d";
47
- } else if (foucsStatus === "@" || foucsStatus === 49) {
48
- type = "s";
49
- } else if (foucsStatus === "General" || foucsStatus === 0) {
69
+ if (foucsStatus === "General" || foucsStatus === 0) {
50
70
  type = isRealNum(value) ? "n" : "g";
51
71
  }
72
+ var mask = update(foucsStatus, value);
52
73
  if (cell && _.isPlainObject(cell)) {
53
74
  cell.m = "".concat(mask);
54
75
  if (_.isNil(cell.ct)) {
@@ -56,7 +77,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
56
77
  }
57
78
  cell.ct.fa = foucsStatus;
58
79
  cell.ct.t = type;
59
- cell.v = String(value);
80
+ cell.v = typeof value === "number" ? value : String(value);
60
81
  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);
61
82
  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);
62
83
  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);
@@ -69,7 +90,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
69
90
  fa: foucsStatus,
70
91
  t: type
71
92
  },
72
- v: value,
93
+ v: typeof value === "number" ? value : value,
73
94
  m: mask
74
95
  };
75
96
  }
@@ -995,11 +1016,11 @@ export function handleLink(ctx, cellInput) {
995
1016
  }
996
1017
  }
997
1018
  }
998
- showLinkCard(ctx, r, c, true, false, {
1019
+ showLinkCard(ctx, r, c, {
999
1020
  applyToSelection: applyToSelection || undefined,
1000
1021
  originText: originText,
1001
1022
  selectionOffsets: selectionOffsets
1002
- });
1023
+ }, true, false);
1003
1024
  }
1004
1025
  var handlerMap = {
1005
1026
  "currency-format": handleCurrencyFormat,