@fileverse-dev/fortune-core 1.3.11 → 1.3.12-copyPaste-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 { update, datenum_local } from "../modules/format";
37
+ import { update, genarate } from "../modules/format";
38
38
  import { normalizeSelection, selectionCache } from "../modules/selection";
39
39
  import { getSheetIndex, isAllowEdit } from "../utils";
40
- import { hasPartMC, isRealNum, detectDateFormat } from "../modules/validation";
40
+ import { hasPartMC, isRealNum } 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";
@@ -223,7 +223,7 @@ var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
223
223
  }
224
224
  };
225
225
  function pasteHandler(ctx, data, borderInfo) {
226
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
226
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
227
227
  if (ctx.luckysheet_selection_range) {
228
228
  ctx.luckysheet_selection_range = [];
229
229
  }
@@ -407,25 +407,39 @@ function pasteHandler(ctx, data, borderInfo) {
407
407
  }
408
408
  }
409
409
  if (originCell) {
410
- if (originCell.ct && originCell.ct.t === "d" && !isUrl) {
411
- var df = detectDateFormat(originalValueStr);
412
- if (df) {
413
- var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
414
- originCell.v = datenum_local(dateObj);
415
- } else {
416
- originCell.v = originalValueStr;
417
- }
418
- } else {
419
- originCell.v = isUrl ? originalValueStr : value;
420
- }
421
- if (originCell.ct != null && originCell.ct.fa != null) {
422
- if (originCell.ct.t === "d" && typeof originCell.v !== "number") {
423
- originCell.m = String(originCell.v);
410
+ if (!isUrl) {
411
+ var generated = genarate(originalValueStr);
412
+ if (generated) {
413
+ var genM = generated[0],
414
+ genCt = generated[1],
415
+ genV = generated[2];
416
+ if ((genCt === null || genCt === void 0 ? void 0 : genCt.t) === "d") {
417
+ originCell.v = genV;
418
+ originCell.m = genM !== null && genM !== void 0 ? genM : originalValueStr;
419
+ originCell.ct = genCt;
420
+ } else {
421
+ originCell.v = value;
422
+ if (originCell.ct != null && originCell.ct.fa != null) {
423
+ if (originCell.ct.t === "d" && typeof originCell.v !== "number") {
424
+ originCell.m = String(originCell.v);
425
+ } else {
426
+ originCell.m = update(originCell.ct.fa, originCell.v);
427
+ }
428
+ } else {
429
+ originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
430
+ }
431
+ }
424
432
  } else {
425
- originCell.m = update(originCell.ct.fa, originCell.v);
433
+ originCell.v = value;
434
+ if (originCell.ct != null && originCell.ct.fa != null) {
435
+ originCell.m = update(originCell.ct.fa, originCell.v);
436
+ } else {
437
+ originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
438
+ }
426
439
  }
427
440
  } else {
428
- originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
441
+ originCell.v = originalValueStr;
442
+ originCell.m = originalValueStr;
429
443
  }
430
444
  if (originCell.f != null && originCell.f.length > 0) {
431
445
  originCell.f = "";
@@ -452,19 +466,24 @@ function pasteHandler(ctx, data, borderInfo) {
452
466
  t: "s"
453
467
  };
454
468
  } else {
455
- cell.v = originalValueStr;
456
- cell.m = originalValueStr;
457
- cell.ct = {
458
- fa: "General",
459
- t: "g"
460
- };
461
469
  if (/^0x?[a-fA-F0-9]+$/.test(value)) {
470
+ cell.v = value;
462
471
  cell.m = value;
463
472
  cell.ct = {
464
473
  fa: "@",
465
474
  t: "s"
466
475
  };
467
- cell.v = value;
476
+ } else {
477
+ var _m = (_j = genarate(originalValueStr)) !== null && _j !== void 0 ? _j : [],
478
+ m = _m[0],
479
+ ct = _m[1],
480
+ v = _m[2];
481
+ cell.v = v !== null && v !== void 0 ? v : originalValueStr;
482
+ cell.m = m != null ? String(m) : originalValueStr;
483
+ cell.ct = ct !== null && ct !== void 0 ? ct : {
484
+ fa: "General",
485
+ t: "g"
486
+ };
468
487
  }
469
488
  }
470
489
  if (isUrl && url) {
@@ -495,8 +514,8 @@ function pasteHandler(ctx, data, borderInfo) {
495
514
  }
496
515
  d[r + curR] = x;
497
516
  }
498
- if ((_j = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _j === void 0 ? void 0 : _j.updateCellYdoc) {
499
- (_k = ctx.hooks) === null || _k === void 0 ? void 0 : _k.updateCellYdoc(changes);
517
+ if ((_k = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _k === void 0 ? void 0 : _k.updateCellYdoc) {
518
+ (_l = ctx.hooks) === null || _l === void 0 ? void 0 : _l.updateCellYdoc(changes);
500
519
  }
501
520
  last.row = [curR, curR + rlen - 1];
502
521
  last.column = [curC, curC + clen - 1];
@@ -1041,7 +1041,7 @@ export function getFontStyleByCell(cell, checksAF, checksCF, isCheck) {
1041
1041
  if (key === "it" && valueNum !== 0) {
1042
1042
  style.fontStyle = "italic";
1043
1043
  }
1044
- if (key === "fs" && valueNum !== 10) {
1044
+ if (key === "fs" && !_.isNil(value)) {
1045
1045
  style.fontSize = "".concat(valueNum, "pt");
1046
1046
  }
1047
1047
  if (key === "fc" && value !== "#000000" || ((_a = checksAF === null || checksAF === void 0 ? void 0 : checksAF.length) !== null && _a !== void 0 ? _a : 0) > 0 || (checksCF === null || checksCF === void 0 ? void 0 : checksCF.textColor)) {
@@ -240,20 +240,24 @@ export function genarate(value) {
240
240
  v = datenum_local(dateObj);
241
241
  ct.t = "d";
242
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",
243
+ "yyyy-MM-dd": "yyyy-MM-dd",
244
+ "yyyy-MM-dd HH:mm": "yyyy-MM-dd HH:mm",
245
+ "yyyy-MM-ddTHH:mm": "yyyy-MM-dd HH:mm",
246
+ "yyyy/MM/dd": "yyyy/MM/dd",
247
+ "yyyy/MM/dd HH:mm": "yyyy/MM/dd HH:mm",
248
248
  "yyyy.MM.dd": "yyyy.MM.dd",
249
249
  "MM/dd/yyyy h:mm AM/PM": "MM/dd/yyyy h:mm AM/PM",
250
250
  "MM/dd/yyyy": "MM/dd/yyyy",
251
251
  "M/d/yyyy": "M/d/yyyy",
252
252
  "MM/dd/yy": "MM/dd/yy",
253
253
  "dd/MM/yyyy": "dd/MM/yyyy",
254
- "dd-MM-yyyy": "dd/MM/yyyy",
254
+ "dd-MM-yyyy": "dd-MM-yyyy",
255
255
  "dd.MM.yyyy": "dd.MM.yyyy",
256
- named: "dd/MM/yyyy"
256
+ "named-mdy-full": "mmmm d, yyyy",
257
+ "named-mdy-abbr": "mmm d, yyyy",
258
+ "named-dmy-full": "d mmmm yyyy",
259
+ "named-dmy-abbr": "d mmm yyyy",
260
+ "named-abbr-dashes": "mmm-d-yyyy"
257
261
  };
258
262
  ct.fa = map[df.formatType] || "dd/MM/yyyy";
259
263
  m = SSF.format(ct.fa, v);
@@ -273,6 +277,7 @@ export function update(fmt, v) {
273
277
  return SSF.format(fmt, v);
274
278
  }
275
279
  export function is_date(fmt, v) {
280
+ console.log(SSF.is_date(fmt, v), "is_date");
276
281
  return SSF.is_date(fmt, v);
277
282
  }
278
283
  function fuzzynum(s) {
@@ -291,6 +291,9 @@ function extendCssText(origin, cover, isLimit) {
291
291
  }
292
292
  return newCss;
293
293
  }
294
+ function escapeHtmlAttr(s) {
295
+ return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
296
+ }
294
297
  export function updateInlineStringFormat(ctx, attr, value, cellInput) {
295
298
  var _a, _b, _c;
296
299
  var w = window.getSelection();
@@ -298,6 +301,34 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
298
301
  if (w.rangeCount === 0) return;
299
302
  var range = w.getRangeAt(0);
300
303
  var $textEditor = cellInput;
304
+ if (range.startContainer === $textEditor && range.endContainer === $textEditor && range.collapsed === false) {
305
+ var start = range.startOffset;
306
+ var end = range.endOffset;
307
+ var children = Array.from($textEditor.childNodes).slice(start, end);
308
+ children.forEach(function (node) {
309
+ var _a, _b;
310
+ if (node.nodeType === Node.ELEMENT_NODE) {
311
+ var el = node;
312
+ if (el.tagName === "SPAN") {
313
+ var cssText = getCssText(el.style.cssText, attr, value);
314
+ el.setAttribute("style", cssText);
315
+ }
316
+ } else if (node.nodeType === Node.TEXT_NODE) {
317
+ var text = (_a = node.textContent) !== null && _a !== void 0 ? _a : "";
318
+ if (text.length === 0) return;
319
+ var wrapper = document.createElement("span");
320
+ var cssText = getCssText("", attr, value);
321
+ wrapper.setAttribute("style", cssText);
322
+ wrapper.textContent = text;
323
+ (_b = node.parentNode) === null || _b === void 0 ? void 0 : _b.replaceChild(wrapper, node);
324
+ }
325
+ });
326
+ var newRange = document.createRange();
327
+ newRange.selectNodeContents($textEditor);
328
+ w.removeAllRanges();
329
+ w.addRange(newRange);
330
+ return;
331
+ }
301
332
  if (range.collapsed === true) {
302
333
  return;
303
334
  }
@@ -335,7 +366,7 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
335
366
  cssText = extendCssText(box.style.cssText, cssText);
336
367
  }
337
368
  }
338
- cont += "<span style='".concat(cssText, "'>").concat(left, "</span>");
369
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(left, "</span>");
339
370
  }
340
371
  if (mid !== "") {
341
372
  var cssText = getCssText(span.style.cssText, attr, value);
@@ -345,7 +376,7 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
345
376
  cssText = extendCssText(box.style.cssText, cssText);
346
377
  }
347
378
  }
348
- cont += "<span style='".concat(cssText, "'>").concat(mid, "</span>");
379
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(mid, "</span>");
349
380
  }
350
381
  if (right !== "") {
351
382
  var cssText = span.style.cssText;
@@ -355,7 +386,7 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
355
386
  cssText = extendCssText(box.style.cssText, cssText);
356
387
  }
357
388
  }
358
- cont += "<span style='".concat(cssText, "'>").concat(right, "</span>");
389
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(right, "</span>");
359
390
  }
360
391
  if (((_a = startContainer.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === "SPAN") {
361
392
  spanIndex = _.indexOf($textEditor.querySelectorAll("span"), span);
@@ -398,33 +429,33 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
398
429
  for (var i = 0; i < startSpanIndex; i += 1) {
399
430
  var span = spans[i];
400
431
  var content = span.innerHTML;
401
- cont += "<span style='".concat(span.style.cssText, "'>").concat(content, "</span>");
432
+ cont += "<span style=\"".concat(escapeHtmlAttr(span.style.cssText), "\">").concat(content, "</span>");
402
433
  }
403
434
  if (sleft !== "") {
404
- cont += "<span style='".concat(startSpan.style.cssText, "'>").concat(sleft, "</span>");
435
+ cont += "<span style=\"".concat(escapeHtmlAttr(startSpan.style.cssText), "\">").concat(sleft, "</span>");
405
436
  }
406
437
  if (sright !== "") {
407
438
  var cssText = getCssText(startSpan.style.cssText, attr, value);
408
- cont += "<span style='".concat(cssText, "'>").concat(sright, "</span>");
439
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(sright, "</span>");
409
440
  }
410
441
  if (startSpanIndex < endSpanIndex) {
411
442
  for (var i = startSpanIndex + 1; i < endSpanIndex; i += 1) {
412
443
  var span = spans[i];
413
444
  var content = span.innerHTML;
414
- cont += "<span style='".concat(span.style.cssText, "'>").concat(content, "</span>");
445
+ cont += "<span style=\"".concat(escapeHtmlAttr(span.style.cssText), "\">").concat(content, "</span>");
415
446
  }
416
447
  }
417
448
  if (eleft !== "") {
418
449
  var cssText = getCssText(endSpan.style.cssText, attr, value);
419
- cont += "<span style='".concat(cssText, "'>").concat(eleft, "</span>");
450
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(eleft, "</span>");
420
451
  }
421
452
  if (eright !== "") {
422
- cont += "<span style='".concat(endSpan.style.cssText, "'>").concat(eright, "</span>");
453
+ cont += "<span style=\"".concat(escapeHtmlAttr(endSpan.style.cssText), "\">").concat(eright, "</span>");
423
454
  }
424
455
  for (var i = endSpanIndex + 1; i < spans.length; i += 1) {
425
456
  var span = spans[i];
426
457
  var content = span.innerHTML;
427
- cont += "<span style='".concat(span.style.cssText, "'>").concat(content, "</span>");
458
+ cont += "<span style=\"".concat(escapeHtmlAttr(span.style.cssText), "\">").concat(content, "</span>");
428
459
  }
429
460
  $textEditor.innerHTML = cont;
430
461
  var startSeletedNodeIndex = void 0;
@@ -442,13 +473,10 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
442
473
  }
443
474
  }
444
475
  }
445
- function escapeHtmlAttr(s) {
446
- return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
447
- }
448
476
  function getLinkDataAttrs(span) {
449
477
  var _a, _b;
450
478
  if (((_a = span.dataset) === null || _a === void 0 ? void 0 : _a.linkType) && ((_b = span.dataset) === null || _b === void 0 ? void 0 : _b.linkAddress)) {
451
- return " data-link-type='".concat(escapeHtmlAttr(span.dataset.linkType), "' data-link-address='").concat(escapeHtmlAttr(span.dataset.linkAddress), "'");
479
+ return " data-link-type=\"".concat(escapeHtmlAttr(span.dataset.linkType), "\" data-link-address=\"").concat(escapeHtmlAttr(span.dataset.linkAddress), "\"");
452
480
  }
453
481
  return "";
454
482
  }
@@ -486,7 +514,7 @@ export function applyLinkToSelection(cellInput, linkType, linkAddress) {
486
514
  var box = span.closest("#luckysheet-input-box");
487
515
  if (box != null) cssText = extendCssText(box.style.cssText, cssText);
488
516
  }
489
- cont += "<span style='".concat(cssText, "'").concat(dataAttrs, ">").concat(left, "</span>");
517
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\"").concat(dataAttrs, ">").concat(left, "</span>");
490
518
  }
491
519
  if (mid !== "") {
492
520
  var cssText = getLinkStyleCssText(span.style.cssText);
@@ -494,7 +522,7 @@ export function applyLinkToSelection(cellInput, linkType, linkAddress) {
494
522
  var box = span.closest("#luckysheet-input-box");
495
523
  if (box != null) cssText = extendCssText(box.style.cssText, cssText);
496
524
  }
497
- cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(mid, "</span>");
525
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\" data-link-type=\"").concat(escapeHtmlAttr(linkType), "\" data-link-address=\"").concat(escapeHtmlAttr(linkAddress), "\">").concat(mid, "</span>");
498
526
  }
499
527
  if (right !== "") {
500
528
  var cssText = span.style.cssText;
@@ -502,7 +530,7 @@ export function applyLinkToSelection(cellInput, linkType, linkAddress) {
502
530
  var box = span.closest("#luckysheet-input-box");
503
531
  if (box != null) cssText = extendCssText(box.style.cssText, cssText);
504
532
  }
505
- cont += "<span style='".concat(cssText, "'").concat(dataAttrs, ">").concat(right, "</span>");
533
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\"").concat(dataAttrs, ">").concat(right, "</span>");
506
534
  }
507
535
  if (((_a = startContainer.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === "SPAN") {
508
536
  span.outerHTML = cont;
@@ -532,32 +560,32 @@ export function applyLinkToSelection(cellInput, linkType, linkAddress) {
532
560
  var cont = "";
533
561
  for (var i = 0; i < startSpanIndex; i += 1) {
534
562
  var sp = spans[i];
535
- cont += "<span style='".concat(sp.style.cssText, "'").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
563
+ cont += "<span style=\"".concat(escapeHtmlAttr(sp.style.cssText), "\"").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
536
564
  }
537
565
  if (sleft !== "") {
538
- cont += "<span style='".concat(startSpan.style.cssText, "'").concat(getLinkDataAttrs(startSpan), ">").concat(sleft, "</span>");
566
+ cont += "<span style=\"".concat(escapeHtmlAttr(startSpan.style.cssText), "\"").concat(getLinkDataAttrs(startSpan), ">").concat(sleft, "</span>");
539
567
  }
540
568
  if (sright !== "") {
541
569
  var cssText = getLinkStyleCssText(startSpan.style.cssText);
542
- cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(sright, "</span>");
570
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\" data-link-type=\"").concat(escapeHtmlAttr(linkType), "\" data-link-address=\"").concat(escapeHtmlAttr(linkAddress), "\">").concat(sright, "</span>");
543
571
  }
544
572
  if (startSpanIndex < endSpanIndex) {
545
573
  for (var i = startSpanIndex + 1; i < endSpanIndex; i += 1) {
546
574
  var sp = spans[i];
547
575
  var cssText = getLinkStyleCssText(sp.style.cssText);
548
- cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(sp.innerHTML, "</span>");
576
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\" data-link-type=\"").concat(escapeHtmlAttr(linkType), "\" data-link-address=\"").concat(escapeHtmlAttr(linkAddress), "\">").concat(sp.innerHTML, "</span>");
549
577
  }
550
578
  }
551
579
  if (eleft !== "") {
552
580
  var cssText = getLinkStyleCssText(endSpan.style.cssText);
553
- cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(eleft, "</span>");
581
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\" data-link-type=\"").concat(escapeHtmlAttr(linkType), "\" data-link-address=\"").concat(escapeHtmlAttr(linkAddress), "\">").concat(eleft, "</span>");
554
582
  }
555
583
  if (eright !== "") {
556
- cont += "<span style='".concat(endSpan.style.cssText, "'").concat(getLinkDataAttrs(endSpan), ">").concat(eright, "</span>");
584
+ cont += "<span style=\"".concat(escapeHtmlAttr(endSpan.style.cssText), "\"").concat(getLinkDataAttrs(endSpan), ">").concat(eright, "</span>");
557
585
  }
558
586
  for (var i = endSpanIndex + 1; i < spans.length; i += 1) {
559
587
  var sp = spans[i];
560
- cont += "<span style='".concat(sp.style.cssText, "'").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
588
+ cont += "<span style=\"".concat(escapeHtmlAttr(sp.style.cssText), "\"").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
561
589
  }
562
590
  $textEditor.innerHTML = cont;
563
591
  spans = $textEditor.querySelectorAll("span");
@@ -1186,7 +1186,7 @@ export function rangeValueToHtml(ctx, sheetId, ranges) {
1186
1186
  cpdata += "<tr height=".concat(rowLen, "px >");
1187
1187
  var _loop_3 = function _loop_3(j) {
1188
1188
  var c = colIndexArr[j];
1189
- var column = '<td ${span} style="${style}">';
1189
+ var column = '<td ${span} style="${style}" data-fortune-cell="${cellData}">';
1190
1190
  var cell = (_f = d[r]) === null || _f === void 0 ? void 0 : _f[c];
1191
1191
  if (cell != null) {
1192
1192
  var style = "";
@@ -1397,9 +1397,14 @@ export function rangeValueToHtml(ctx, sheetId, ranges) {
1397
1397
  }
1398
1398
  }
1399
1399
  }
1400
+ var cellData = encodeURIComponent(JSON.stringify(__assign(__assign({}, cell), {
1401
+ _srcRow: r,
1402
+ _srcCol: c
1403
+ })));
1400
1404
  column = replaceHtml(column, {
1401
1405
  style: style,
1402
- span: span
1406
+ span: span,
1407
+ cellData: cellData
1403
1408
  });
1404
1409
  if (_.isNil(c_value)) {
1405
1410
  c_value = getCellValue(r, c, d);
@@ -1449,7 +1454,8 @@ export function rangeValueToHtml(ctx, sheetId, ranges) {
1449
1454
  }
1450
1455
  column = replaceHtml(column, {
1451
1456
  style: style,
1452
- span: ""
1457
+ span: "",
1458
+ cellData: ""
1453
1459
  });
1454
1460
  column += "";
1455
1461
  }
@@ -66,6 +66,7 @@ var MONTH_NAME_MAP = {
66
66
  };
67
67
  var MONTH_NAMES_RE = "january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sep|oct|nov|dec";
68
68
  var MONTH_ABBR_RE = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec";
69
+ var MONTH_ABBR_SET = new Set(MONTH_ABBR_RE.split("|"));
69
70
  function isValidDateParts(year, month, day) {
70
71
  if (year < 1900) return false;
71
72
  if (month < 1 || month > 12) return false;
@@ -280,6 +281,7 @@ export function detectDateFormat(str) {
280
281
  var d = +m[2];
281
282
  var y = +m[3];
282
283
  if (mo && isValidDateParts(y, mo, d)) {
284
+ var isAbbr = MONTH_ABBR_SET.has(m[1].toLowerCase());
283
285
  return {
284
286
  year: y,
285
287
  month: mo,
@@ -287,7 +289,7 @@ export function detectDateFormat(str) {
287
289
  hours: 0,
288
290
  minutes: 0,
289
291
  seconds: 0,
290
- formatType: "named"
292
+ formatType: isAbbr ? "named-mdy-abbr" : "named-mdy-full"
291
293
  };
292
294
  }
293
295
  }
@@ -297,6 +299,7 @@ export function detectDateFormat(str) {
297
299
  var mo = MONTH_NAME_MAP[m[2].toLowerCase()];
298
300
  var y = +m[3];
299
301
  if (mo && isValidDateParts(y, mo, d)) {
302
+ var isAbbr = MONTH_ABBR_SET.has(m[2].toLowerCase());
300
303
  return {
301
304
  year: y,
302
305
  month: mo,
@@ -304,7 +307,7 @@ export function detectDateFormat(str) {
304
307
  hours: 0,
305
308
  minutes: 0,
306
309
  seconds: 0,
307
- formatType: "named"
310
+ formatType: isAbbr ? "named-dmy-abbr" : "named-dmy-full"
308
311
  };
309
312
  }
310
313
  }
@@ -321,7 +324,7 @@ export function detectDateFormat(str) {
321
324
  hours: 0,
322
325
  minutes: 0,
323
326
  seconds: 0,
324
- formatType: "named"
327
+ formatType: "named-abbr-dashes"
325
328
  };
326
329
  }
327
330
  }
@@ -9,11 +9,20 @@ var __assign = this && this.__assign || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __rest = this && this.__rest || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
17
+ }
18
+ return t;
19
+ };
12
20
  import _ from "lodash";
13
21
  import { locale } from "./locale";
14
22
  import { getQKBorder, saveHyperlink } from "./modules";
15
23
  import { getSheetIndex } from "./utils";
16
24
  import { setRowHeight, setColumnWidth } from "./api";
25
+ import { adjustFormulaForPaste } from "./events/paste";
17
26
  export var DEFAULT_FONT_SIZE = 12;
18
27
  var parseStylesheetPairs = function parseStylesheetPairs(styleInner) {
19
28
  var patternReg = /{([^}]*)}/g;
@@ -127,6 +136,28 @@ function brToNewline(str) {
127
136
  }
128
137
  var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
129
138
  var _a, _b, _c, _d;
139
+ var fortuneCellAttr = td.getAttribute("data-fortune-cell");
140
+ if (fortuneCellAttr) {
141
+ try {
142
+ var _e = JSON.parse(decodeURIComponent(fortuneCellAttr)),
143
+ _srcRow = _e._srcRow,
144
+ _srcCol = _e._srcCol,
145
+ parsed = __rest(_e, ["_srcRow", "_srcCol"]);
146
+ var cell_1 = parsed;
147
+ delete cell_1.mc;
148
+ delete cell_1.hl;
149
+ var rowspan_1 = parseInt(td.getAttribute("rowspan") || "1", 10);
150
+ var colspan_1 = parseInt(td.getAttribute("colspan") || "1", 10);
151
+ return {
152
+ cell: cell_1,
153
+ rowspan: Number.isNaN(rowspan_1) ? 1 : rowspan_1,
154
+ colspan: Number.isNaN(colspan_1) ? 1 : colspan_1,
155
+ hyperlink: detectHyperlink(td),
156
+ srcRow: _srcRow,
157
+ srcCol: _srcCol
158
+ };
159
+ } catch (_f) {}
160
+ }
130
161
  var cell = {};
131
162
  var rawText = (td.innerText || td.innerHTML || "").trim();
132
163
  var isLineBreak = rawText.includes("<br />");
@@ -277,10 +308,17 @@ export function handlePastedTable(ctx, html, pasteHandler) {
277
308
  cell = _a.cell,
278
309
  rowspan = _a.rowspan,
279
310
  colspan = _a.colspan,
280
- hyperlink = _a.hyperlink;
311
+ hyperlink = _a.hyperlink,
312
+ srcRow = _a.srcRow,
313
+ srcCol = _a.srcCol;
281
314
  var anchorCol = ctx.luckysheet_select_save[0].column[0];
282
315
  var absoluteRow = anchorRow + localRowIndex;
283
316
  var absoluteCol = anchorCol + localColIndex;
317
+ if (cell.f && srcRow != null && srcCol != null) {
318
+ try {
319
+ cell.f = adjustFormulaForPaste(cell.f, srcCol, srcRow, absoluteCol, absoluteRow);
320
+ } catch (_b) {}
321
+ }
284
322
  pastedMatrix[localRowIndex][localColIndex] = cell;
285
323
  if (hyperlink) {
286
324
  saveHyperlink(ctx, absoluteRow, absoluteCol, hyperlink.href, "webpage", hyperlink.display);
@@ -236,7 +236,7 @@ var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
236
236
  }
237
237
  };
238
238
  function pasteHandler(ctx, data, borderInfo) {
239
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
239
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
240
240
  if (ctx.luckysheet_selection_range) {
241
241
  ctx.luckysheet_selection_range = [];
242
242
  }
@@ -420,25 +420,39 @@ function pasteHandler(ctx, data, borderInfo) {
420
420
  }
421
421
  }
422
422
  if (originCell) {
423
- if (originCell.ct && originCell.ct.t === "d" && !isUrl) {
424
- var df = (0, _validation.detectDateFormat)(originalValueStr);
425
- if (df) {
426
- var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
427
- originCell.v = (0, _format.datenum_local)(dateObj);
428
- } else {
429
- originCell.v = originalValueStr;
430
- }
431
- } else {
432
- originCell.v = isUrl ? originalValueStr : value;
433
- }
434
- if (originCell.ct != null && originCell.ct.fa != null) {
435
- if (originCell.ct.t === "d" && typeof originCell.v !== "number") {
436
- originCell.m = String(originCell.v);
423
+ if (!isUrl) {
424
+ var generated = (0, _format.genarate)(originalValueStr);
425
+ if (generated) {
426
+ var genM = generated[0],
427
+ genCt = generated[1],
428
+ genV = generated[2];
429
+ if ((genCt === null || genCt === void 0 ? void 0 : genCt.t) === "d") {
430
+ originCell.v = genV;
431
+ originCell.m = genM !== null && genM !== void 0 ? genM : originalValueStr;
432
+ originCell.ct = genCt;
433
+ } else {
434
+ originCell.v = value;
435
+ if (originCell.ct != null && originCell.ct.fa != null) {
436
+ if (originCell.ct.t === "d" && typeof originCell.v !== "number") {
437
+ originCell.m = String(originCell.v);
438
+ } else {
439
+ originCell.m = (0, _format.update)(originCell.ct.fa, originCell.v);
440
+ }
441
+ } else {
442
+ originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
443
+ }
444
+ }
437
445
  } else {
438
- originCell.m = (0, _format.update)(originCell.ct.fa, originCell.v);
446
+ originCell.v = value;
447
+ if (originCell.ct != null && originCell.ct.fa != null) {
448
+ originCell.m = (0, _format.update)(originCell.ct.fa, originCell.v);
449
+ } else {
450
+ originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
451
+ }
439
452
  }
440
453
  } else {
441
- originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
454
+ originCell.v = originalValueStr;
455
+ originCell.m = originalValueStr;
442
456
  }
443
457
  if (originCell.f != null && originCell.f.length > 0) {
444
458
  originCell.f = "";
@@ -465,19 +479,24 @@ function pasteHandler(ctx, data, borderInfo) {
465
479
  t: "s"
466
480
  };
467
481
  } else {
468
- cell.v = originalValueStr;
469
- cell.m = originalValueStr;
470
- cell.ct = {
471
- fa: "General",
472
- t: "g"
473
- };
474
482
  if (/^0x?[a-fA-F0-9]+$/.test(value)) {
483
+ cell.v = value;
475
484
  cell.m = value;
476
485
  cell.ct = {
477
486
  fa: "@",
478
487
  t: "s"
479
488
  };
480
- cell.v = value;
489
+ } else {
490
+ var _m = (_j = (0, _format.genarate)(originalValueStr)) !== null && _j !== void 0 ? _j : [],
491
+ m = _m[0],
492
+ ct = _m[1],
493
+ v = _m[2];
494
+ cell.v = v !== null && v !== void 0 ? v : originalValueStr;
495
+ cell.m = m != null ? String(m) : originalValueStr;
496
+ cell.ct = ct !== null && ct !== void 0 ? ct : {
497
+ fa: "General",
498
+ t: "g"
499
+ };
481
500
  }
482
501
  }
483
502
  if (isUrl && url) {
@@ -508,8 +527,8 @@ function pasteHandler(ctx, data, borderInfo) {
508
527
  }
509
528
  d[r + curR] = x;
510
529
  }
511
- if ((_j = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _j === void 0 ? void 0 : _j.updateCellYdoc) {
512
- (_k = ctx.hooks) === null || _k === void 0 ? void 0 : _k.updateCellYdoc(changes);
530
+ if ((_k = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _k === void 0 ? void 0 : _k.updateCellYdoc) {
531
+ (_l = ctx.hooks) === null || _l === void 0 ? void 0 : _l.updateCellYdoc(changes);
513
532
  }
514
533
  last.row = [curR, curR + rlen - 1];
515
534
  last.column = [curC, curC + clen - 1];
@@ -1074,7 +1074,7 @@ function getFontStyleByCell(cell, checksAF, checksCF, isCheck) {
1074
1074
  if (key === "it" && valueNum !== 0) {
1075
1075
  style.fontStyle = "italic";
1076
1076
  }
1077
- if (key === "fs" && valueNum !== 10) {
1077
+ if (key === "fs" && !_lodash.default.isNil(value)) {
1078
1078
  style.fontSize = "".concat(valueNum, "pt");
1079
1079
  }
1080
1080
  if (key === "fc" && value !== "#000000" || ((_a = checksAF === null || checksAF === void 0 ? void 0 : checksAF.length) !== null && _a !== void 0 ? _a : 0) > 0 || (checksCF === null || checksCF === void 0 ? void 0 : checksCF.textColor)) {
@@ -251,20 +251,24 @@ function genarate(value) {
251
251
  v = datenum_local(dateObj);
252
252
  ct.t = "d";
253
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",
254
+ "yyyy-MM-dd": "yyyy-MM-dd",
255
+ "yyyy-MM-dd HH:mm": "yyyy-MM-dd HH:mm",
256
+ "yyyy-MM-ddTHH:mm": "yyyy-MM-dd HH:mm",
257
+ "yyyy/MM/dd": "yyyy/MM/dd",
258
+ "yyyy/MM/dd HH:mm": "yyyy/MM/dd HH:mm",
259
259
  "yyyy.MM.dd": "yyyy.MM.dd",
260
260
  "MM/dd/yyyy h:mm AM/PM": "MM/dd/yyyy h:mm AM/PM",
261
261
  "MM/dd/yyyy": "MM/dd/yyyy",
262
262
  "M/d/yyyy": "M/d/yyyy",
263
263
  "MM/dd/yy": "MM/dd/yy",
264
264
  "dd/MM/yyyy": "dd/MM/yyyy",
265
- "dd-MM-yyyy": "dd/MM/yyyy",
265
+ "dd-MM-yyyy": "dd-MM-yyyy",
266
266
  "dd.MM.yyyy": "dd.MM.yyyy",
267
- named: "dd/MM/yyyy"
267
+ "named-mdy-full": "mmmm d, yyyy",
268
+ "named-mdy-abbr": "mmm d, yyyy",
269
+ "named-dmy-full": "d mmmm yyyy",
270
+ "named-dmy-abbr": "d mmm yyyy",
271
+ "named-abbr-dashes": "mmm-d-yyyy"
268
272
  };
269
273
  ct.fa = map[df.formatType] || "dd/MM/yyyy";
270
274
  m = _ssf.default.format(ct.fa, v);
@@ -284,6 +288,7 @@ function update(fmt, v) {
284
288
  return _ssf.default.format(fmt, v);
285
289
  }
286
290
  function is_date(fmt, v) {
291
+ console.log(_ssf.default.is_date(fmt, v), "is_date");
287
292
  return _ssf.default.is_date(fmt, v);
288
293
  }
289
294
  function fuzzynum(s) {
@@ -307,6 +307,9 @@ function extendCssText(origin, cover, isLimit) {
307
307
  }
308
308
  return newCss;
309
309
  }
310
+ function escapeHtmlAttr(s) {
311
+ return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
312
+ }
310
313
  function updateInlineStringFormat(ctx, attr, value, cellInput) {
311
314
  var _a, _b, _c;
312
315
  var w = window.getSelection();
@@ -314,6 +317,34 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
314
317
  if (w.rangeCount === 0) return;
315
318
  var range = w.getRangeAt(0);
316
319
  var $textEditor = cellInput;
320
+ if (range.startContainer === $textEditor && range.endContainer === $textEditor && range.collapsed === false) {
321
+ var start = range.startOffset;
322
+ var end = range.endOffset;
323
+ var children = Array.from($textEditor.childNodes).slice(start, end);
324
+ children.forEach(function (node) {
325
+ var _a, _b;
326
+ if (node.nodeType === Node.ELEMENT_NODE) {
327
+ var el = node;
328
+ if (el.tagName === "SPAN") {
329
+ var cssText = getCssText(el.style.cssText, attr, value);
330
+ el.setAttribute("style", cssText);
331
+ }
332
+ } else if (node.nodeType === Node.TEXT_NODE) {
333
+ var text = (_a = node.textContent) !== null && _a !== void 0 ? _a : "";
334
+ if (text.length === 0) return;
335
+ var wrapper = document.createElement("span");
336
+ var cssText = getCssText("", attr, value);
337
+ wrapper.setAttribute("style", cssText);
338
+ wrapper.textContent = text;
339
+ (_b = node.parentNode) === null || _b === void 0 ? void 0 : _b.replaceChild(wrapper, node);
340
+ }
341
+ });
342
+ var newRange = document.createRange();
343
+ newRange.selectNodeContents($textEditor);
344
+ w.removeAllRanges();
345
+ w.addRange(newRange);
346
+ return;
347
+ }
317
348
  if (range.collapsed === true) {
318
349
  return;
319
350
  }
@@ -351,7 +382,7 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
351
382
  cssText = extendCssText(box.style.cssText, cssText);
352
383
  }
353
384
  }
354
- cont += "<span style='".concat(cssText, "'>").concat(left, "</span>");
385
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(left, "</span>");
355
386
  }
356
387
  if (mid !== "") {
357
388
  var cssText = getCssText(span.style.cssText, attr, value);
@@ -361,7 +392,7 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
361
392
  cssText = extendCssText(box.style.cssText, cssText);
362
393
  }
363
394
  }
364
- cont += "<span style='".concat(cssText, "'>").concat(mid, "</span>");
395
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(mid, "</span>");
365
396
  }
366
397
  if (right !== "") {
367
398
  var cssText = span.style.cssText;
@@ -371,7 +402,7 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
371
402
  cssText = extendCssText(box.style.cssText, cssText);
372
403
  }
373
404
  }
374
- cont += "<span style='".concat(cssText, "'>").concat(right, "</span>");
405
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(right, "</span>");
375
406
  }
376
407
  if (((_a = startContainer.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === "SPAN") {
377
408
  spanIndex = _lodash.default.indexOf($textEditor.querySelectorAll("span"), span);
@@ -414,33 +445,33 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
414
445
  for (var i = 0; i < startSpanIndex; i += 1) {
415
446
  var span = spans[i];
416
447
  var content = span.innerHTML;
417
- cont += "<span style='".concat(span.style.cssText, "'>").concat(content, "</span>");
448
+ cont += "<span style=\"".concat(escapeHtmlAttr(span.style.cssText), "\">").concat(content, "</span>");
418
449
  }
419
450
  if (sleft !== "") {
420
- cont += "<span style='".concat(startSpan.style.cssText, "'>").concat(sleft, "</span>");
451
+ cont += "<span style=\"".concat(escapeHtmlAttr(startSpan.style.cssText), "\">").concat(sleft, "</span>");
421
452
  }
422
453
  if (sright !== "") {
423
454
  var cssText = getCssText(startSpan.style.cssText, attr, value);
424
- cont += "<span style='".concat(cssText, "'>").concat(sright, "</span>");
455
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(sright, "</span>");
425
456
  }
426
457
  if (startSpanIndex < endSpanIndex) {
427
458
  for (var i = startSpanIndex + 1; i < endSpanIndex; i += 1) {
428
459
  var span = spans[i];
429
460
  var content = span.innerHTML;
430
- cont += "<span style='".concat(span.style.cssText, "'>").concat(content, "</span>");
461
+ cont += "<span style=\"".concat(escapeHtmlAttr(span.style.cssText), "\">").concat(content, "</span>");
431
462
  }
432
463
  }
433
464
  if (eleft !== "") {
434
465
  var cssText = getCssText(endSpan.style.cssText, attr, value);
435
- cont += "<span style='".concat(cssText, "'>").concat(eleft, "</span>");
466
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\">").concat(eleft, "</span>");
436
467
  }
437
468
  if (eright !== "") {
438
- cont += "<span style='".concat(endSpan.style.cssText, "'>").concat(eright, "</span>");
469
+ cont += "<span style=\"".concat(escapeHtmlAttr(endSpan.style.cssText), "\">").concat(eright, "</span>");
439
470
  }
440
471
  for (var i = endSpanIndex + 1; i < spans.length; i += 1) {
441
472
  var span = spans[i];
442
473
  var content = span.innerHTML;
443
- cont += "<span style='".concat(span.style.cssText, "'>").concat(content, "</span>");
474
+ cont += "<span style=\"".concat(escapeHtmlAttr(span.style.cssText), "\">").concat(content, "</span>");
444
475
  }
445
476
  $textEditor.innerHTML = cont;
446
477
  var startSeletedNodeIndex = void 0;
@@ -458,13 +489,10 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
458
489
  }
459
490
  }
460
491
  }
461
- function escapeHtmlAttr(s) {
462
- return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
463
- }
464
492
  function getLinkDataAttrs(span) {
465
493
  var _a, _b;
466
494
  if (((_a = span.dataset) === null || _a === void 0 ? void 0 : _a.linkType) && ((_b = span.dataset) === null || _b === void 0 ? void 0 : _b.linkAddress)) {
467
- return " data-link-type='".concat(escapeHtmlAttr(span.dataset.linkType), "' data-link-address='").concat(escapeHtmlAttr(span.dataset.linkAddress), "'");
495
+ return " data-link-type=\"".concat(escapeHtmlAttr(span.dataset.linkType), "\" data-link-address=\"").concat(escapeHtmlAttr(span.dataset.linkAddress), "\"");
468
496
  }
469
497
  return "";
470
498
  }
@@ -502,7 +530,7 @@ function applyLinkToSelection(cellInput, linkType, linkAddress) {
502
530
  var box = span.closest("#luckysheet-input-box");
503
531
  if (box != null) cssText = extendCssText(box.style.cssText, cssText);
504
532
  }
505
- cont += "<span style='".concat(cssText, "'").concat(dataAttrs, ">").concat(left, "</span>");
533
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\"").concat(dataAttrs, ">").concat(left, "</span>");
506
534
  }
507
535
  if (mid !== "") {
508
536
  var cssText = getLinkStyleCssText(span.style.cssText);
@@ -510,7 +538,7 @@ function applyLinkToSelection(cellInput, linkType, linkAddress) {
510
538
  var box = span.closest("#luckysheet-input-box");
511
539
  if (box != null) cssText = extendCssText(box.style.cssText, cssText);
512
540
  }
513
- cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(mid, "</span>");
541
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\" data-link-type=\"").concat(escapeHtmlAttr(linkType), "\" data-link-address=\"").concat(escapeHtmlAttr(linkAddress), "\">").concat(mid, "</span>");
514
542
  }
515
543
  if (right !== "") {
516
544
  var cssText = span.style.cssText;
@@ -518,7 +546,7 @@ function applyLinkToSelection(cellInput, linkType, linkAddress) {
518
546
  var box = span.closest("#luckysheet-input-box");
519
547
  if (box != null) cssText = extendCssText(box.style.cssText, cssText);
520
548
  }
521
- cont += "<span style='".concat(cssText, "'").concat(dataAttrs, ">").concat(right, "</span>");
549
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\"").concat(dataAttrs, ">").concat(right, "</span>");
522
550
  }
523
551
  if (((_a = startContainer.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === "SPAN") {
524
552
  span.outerHTML = cont;
@@ -548,32 +576,32 @@ function applyLinkToSelection(cellInput, linkType, linkAddress) {
548
576
  var cont = "";
549
577
  for (var i = 0; i < startSpanIndex; i += 1) {
550
578
  var sp = spans[i];
551
- cont += "<span style='".concat(sp.style.cssText, "'").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
579
+ cont += "<span style=\"".concat(escapeHtmlAttr(sp.style.cssText), "\"").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
552
580
  }
553
581
  if (sleft !== "") {
554
- cont += "<span style='".concat(startSpan.style.cssText, "'").concat(getLinkDataAttrs(startSpan), ">").concat(sleft, "</span>");
582
+ cont += "<span style=\"".concat(escapeHtmlAttr(startSpan.style.cssText), "\"").concat(getLinkDataAttrs(startSpan), ">").concat(sleft, "</span>");
555
583
  }
556
584
  if (sright !== "") {
557
585
  var cssText = getLinkStyleCssText(startSpan.style.cssText);
558
- cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(sright, "</span>");
586
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\" data-link-type=\"").concat(escapeHtmlAttr(linkType), "\" data-link-address=\"").concat(escapeHtmlAttr(linkAddress), "\">").concat(sright, "</span>");
559
587
  }
560
588
  if (startSpanIndex < endSpanIndex) {
561
589
  for (var i = startSpanIndex + 1; i < endSpanIndex; i += 1) {
562
590
  var sp = spans[i];
563
591
  var cssText = getLinkStyleCssText(sp.style.cssText);
564
- cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(sp.innerHTML, "</span>");
592
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\" data-link-type=\"").concat(escapeHtmlAttr(linkType), "\" data-link-address=\"").concat(escapeHtmlAttr(linkAddress), "\">").concat(sp.innerHTML, "</span>");
565
593
  }
566
594
  }
567
595
  if (eleft !== "") {
568
596
  var cssText = getLinkStyleCssText(endSpan.style.cssText);
569
- cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(eleft, "</span>");
597
+ cont += "<span style=\"".concat(escapeHtmlAttr(cssText), "\" data-link-type=\"").concat(escapeHtmlAttr(linkType), "\" data-link-address=\"").concat(escapeHtmlAttr(linkAddress), "\">").concat(eleft, "</span>");
570
598
  }
571
599
  if (eright !== "") {
572
- cont += "<span style='".concat(endSpan.style.cssText, "'").concat(getLinkDataAttrs(endSpan), ">").concat(eright, "</span>");
600
+ cont += "<span style=\"".concat(escapeHtmlAttr(endSpan.style.cssText), "\"").concat(getLinkDataAttrs(endSpan), ">").concat(eright, "</span>");
573
601
  }
574
602
  for (var i = endSpanIndex + 1; i < spans.length; i += 1) {
575
603
  var sp = spans[i];
576
- cont += "<span style='".concat(sp.style.cssText, "'").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
604
+ cont += "<span style=\"".concat(escapeHtmlAttr(sp.style.cssText), "\"").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
577
605
  }
578
606
  $textEditor.innerHTML = cont;
579
607
  spans = $textEditor.querySelectorAll("span");
@@ -1221,7 +1221,7 @@ function rangeValueToHtml(ctx, sheetId, ranges) {
1221
1221
  cpdata += "<tr height=".concat(rowLen, "px >");
1222
1222
  var _loop_3 = function _loop_3(j) {
1223
1223
  var c = colIndexArr[j];
1224
- var column = '<td ${span} style="${style}">';
1224
+ var column = '<td ${span} style="${style}" data-fortune-cell="${cellData}">';
1225
1225
  var cell = (_f = d[r]) === null || _f === void 0 ? void 0 : _f[c];
1226
1226
  if (cell != null) {
1227
1227
  var style = "";
@@ -1432,9 +1432,14 @@ function rangeValueToHtml(ctx, sheetId, ranges) {
1432
1432
  }
1433
1433
  }
1434
1434
  }
1435
+ var cellData = encodeURIComponent(JSON.stringify(__assign(__assign({}, cell), {
1436
+ _srcRow: r,
1437
+ _srcCol: c
1438
+ })));
1435
1439
  column = (0, _utils.replaceHtml)(column, {
1436
1440
  style: style,
1437
- span: span
1441
+ span: span,
1442
+ cellData: cellData
1438
1443
  });
1439
1444
  if (_lodash.default.isNil(c_value)) {
1440
1445
  c_value = (0, _cell.getCellValue)(r, c, d);
@@ -1484,7 +1489,8 @@ function rangeValueToHtml(ctx, sheetId, ranges) {
1484
1489
  }
1485
1490
  column = (0, _utils.replaceHtml)(column, {
1486
1491
  style: style,
1487
- span: ""
1492
+ span: "",
1493
+ cellData: ""
1488
1494
  });
1489
1495
  column += "";
1490
1496
  }
@@ -84,6 +84,7 @@ var MONTH_NAME_MAP = {
84
84
  };
85
85
  var MONTH_NAMES_RE = "january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sep|oct|nov|dec";
86
86
  var MONTH_ABBR_RE = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec";
87
+ var MONTH_ABBR_SET = new Set(MONTH_ABBR_RE.split("|"));
87
88
  function isValidDateParts(year, month, day) {
88
89
  if (year < 1900) return false;
89
90
  if (month < 1 || month > 12) return false;
@@ -298,6 +299,7 @@ function detectDateFormat(str) {
298
299
  var d = +m[2];
299
300
  var y = +m[3];
300
301
  if (mo && isValidDateParts(y, mo, d)) {
302
+ var isAbbr = MONTH_ABBR_SET.has(m[1].toLowerCase());
301
303
  return {
302
304
  year: y,
303
305
  month: mo,
@@ -305,7 +307,7 @@ function detectDateFormat(str) {
305
307
  hours: 0,
306
308
  minutes: 0,
307
309
  seconds: 0,
308
- formatType: "named"
310
+ formatType: isAbbr ? "named-mdy-abbr" : "named-mdy-full"
309
311
  };
310
312
  }
311
313
  }
@@ -315,6 +317,7 @@ function detectDateFormat(str) {
315
317
  var mo = MONTH_NAME_MAP[m[2].toLowerCase()];
316
318
  var y = +m[3];
317
319
  if (mo && isValidDateParts(y, mo, d)) {
320
+ var isAbbr = MONTH_ABBR_SET.has(m[2].toLowerCase());
318
321
  return {
319
322
  year: y,
320
323
  month: mo,
@@ -322,7 +325,7 @@ function detectDateFormat(str) {
322
325
  hours: 0,
323
326
  minutes: 0,
324
327
  seconds: 0,
325
- formatType: "named"
328
+ formatType: isAbbr ? "named-dmy-abbr" : "named-dmy-full"
326
329
  };
327
330
  }
328
331
  }
@@ -339,7 +342,7 @@ function detectDateFormat(str) {
339
342
  hours: 0,
340
343
  minutes: 0,
341
344
  seconds: 0,
342
- formatType: "named"
345
+ formatType: "named-abbr-dashes"
343
346
  };
344
347
  }
345
348
  }
@@ -10,6 +10,7 @@ var _locale = require("./locale");
10
10
  var _modules = require("./modules");
11
11
  var _utils = require("./utils");
12
12
  var _api = require("./api");
13
+ var _paste = require("./events/paste");
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
15
  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); }
15
16
  var __assign = void 0 && (void 0).__assign || function () {
@@ -22,6 +23,14 @@ var __assign = void 0 && (void 0).__assign || function () {
22
23
  };
23
24
  return __assign.apply(this, arguments);
24
25
  };
26
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
27
+ var t = {};
28
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
30
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
31
+ }
32
+ return t;
33
+ };
25
34
  var DEFAULT_FONT_SIZE = exports.DEFAULT_FONT_SIZE = 12;
26
35
  var parseStylesheetPairs = function parseStylesheetPairs(styleInner) {
27
36
  var patternReg = /{([^}]*)}/g;
@@ -135,6 +144,28 @@ function brToNewline(str) {
135
144
  }
136
145
  var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
137
146
  var _a, _b, _c, _d;
147
+ var fortuneCellAttr = td.getAttribute("data-fortune-cell");
148
+ if (fortuneCellAttr) {
149
+ try {
150
+ var _e = JSON.parse(decodeURIComponent(fortuneCellAttr)),
151
+ _srcRow = _e._srcRow,
152
+ _srcCol = _e._srcCol,
153
+ parsed = __rest(_e, ["_srcRow", "_srcCol"]);
154
+ var cell_1 = parsed;
155
+ delete cell_1.mc;
156
+ delete cell_1.hl;
157
+ var rowspan_1 = parseInt(td.getAttribute("rowspan") || "1", 10);
158
+ var colspan_1 = parseInt(td.getAttribute("colspan") || "1", 10);
159
+ return {
160
+ cell: cell_1,
161
+ rowspan: Number.isNaN(rowspan_1) ? 1 : rowspan_1,
162
+ colspan: Number.isNaN(colspan_1) ? 1 : colspan_1,
163
+ hyperlink: detectHyperlink(td),
164
+ srcRow: _srcRow,
165
+ srcCol: _srcCol
166
+ };
167
+ } catch (_f) {}
168
+ }
138
169
  var cell = {};
139
170
  var rawText = (td.innerText || td.innerHTML || "").trim();
140
171
  var isLineBreak = rawText.includes("<br />");
@@ -285,10 +316,17 @@ function handlePastedTable(ctx, html, pasteHandler) {
285
316
  cell = _a.cell,
286
317
  rowspan = _a.rowspan,
287
318
  colspan = _a.colspan,
288
- hyperlink = _a.hyperlink;
319
+ hyperlink = _a.hyperlink,
320
+ srcRow = _a.srcRow,
321
+ srcCol = _a.srcCol;
289
322
  var anchorCol = ctx.luckysheet_select_save[0].column[0];
290
323
  var absoluteRow = anchorRow + localRowIndex;
291
324
  var absoluteCol = anchorCol + localColIndex;
325
+ if (cell.f && srcRow != null && srcCol != null) {
326
+ try {
327
+ cell.f = (0, _paste.adjustFormulaForPaste)(cell.f, srcCol, srcRow, absoluteCol, absoluteRow);
328
+ } catch (_b) {}
329
+ }
292
330
  pastedMatrix[localRowIndex][localColIndex] = cell;
293
331
  if (hyperlink) {
294
332
  (0, _modules.saveHyperlink)(ctx, absoluteRow, absoluteCol, hyperlink.href, "webpage", hyperlink.display);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.3.11",
3
+ "version": "1.3.12-copyPaste-4",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",