@fileverse-dev/fortune-core 1.3.5 → 1.3.6-right

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.
@@ -1541,6 +1541,8 @@ export function deleteSelectedCellText(ctx) {
1541
1541
  var cell = d[r][c];
1542
1542
  delete cell.m;
1543
1543
  delete cell.v;
1544
+ delete cell.fc;
1545
+ delete cell.un;
1544
1546
  if (cell.f != null) {
1545
1547
  delete cell.f;
1546
1548
  delFunctionGroup(ctx, r, c, ctx.currentSheetId);
@@ -1613,6 +1615,8 @@ export function deleteSelectedCellFormat(ctx) {
1613
1615
  return "success";
1614
1616
  }
1615
1617
  export function fillRightData(ctx) {
1618
+ var _a, _b, _c, _d;
1619
+ var _e, _f, _g;
1616
1620
  var allowEdit = isAllowEdit(ctx);
1617
1621
  if (allowEdit === false) {
1618
1622
  return "allowEdit";
@@ -1640,10 +1644,111 @@ export function fillRightData(ctx) {
1640
1644
  var r2 = selection[s].row[1];
1641
1645
  var c1 = selection[s].column[0];
1642
1646
  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);
1647
+ var sheetIndex = getSheetIndex(ctx, ctx.currentSheetId);
1648
+ var file = sheetIndex != null ? ctx.luckysheetfile[sheetIndex] : null;
1649
+ var dataVerification = file === null || file === void 0 ? void 0 : file.dataVerification;
1650
+ var hyperlink = file === null || file === void 0 ? void 0 : file.hyperlink;
1651
+ var cdformat = file === null || file === void 0 ? void 0 : file.luckysheet_conditionformat_save;
1652
+ var isSingleCell = r1 === r2 && c1 === c2;
1653
+ if (isSingleCell) {
1654
+ if (c1 - 1 >= 0 && d[r1]) {
1655
+ var srcRow = r1;
1656
+ var srcCol = c1 - 1;
1657
+ var prev = d[r1][c1 - 1];
1658
+ d[r1][c1] = prev != null ? __assign({}, prev) : {};
1659
+ if (file != null) {
1660
+ var srcKey = "".concat(srcRow, "_").concat(srcCol);
1661
+ var tgtKey = "".concat(r1, "_").concat(c1);
1662
+ if (dataVerification != null) {
1663
+ var dv = dataVerification[srcKey];
1664
+ if (dv != null) {
1665
+ console.log("[fillRightData] dataVerification copy from", {
1666
+ row: srcRow,
1667
+ col: srcCol
1668
+ }, "→", {
1669
+ row: r1,
1670
+ col: c1
1671
+ }, dv);
1672
+ file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_a = {}, _a[tgtKey] = _.cloneDeep(dv), _a));
1673
+ }
1674
+ }
1675
+ if (hyperlink != null && hyperlink[srcKey] != null) {
1676
+ file.hyperlink = __assign(__assign({}, file.hyperlink || {}), (_b = {}, _b[tgtKey] = _.cloneDeep(hyperlink[srcKey]), _b));
1677
+ var tgtCell = d[r1][c1];
1678
+ if (tgtCell != null) tgtCell.hl = {
1679
+ r: r1,
1680
+ c: c1,
1681
+ id: ctx.currentSheetId
1682
+ };
1683
+ }
1684
+ if (cdformat != null && cdformat.length > 0) {
1685
+ for (var i = 0; i < cdformat.length; i += 1) {
1686
+ var ranges = cdformat[i].cellrange;
1687
+ if (!ranges) continue;
1688
+ for (var j = 0; j < ranges.length; j += 1) {
1689
+ var cr = ranges[j];
1690
+ if (srcRow >= cr.row[0] && srcRow <= cr.row[1] && srcCol >= cr.column[0] && srcCol <= cr.column[1]) {
1691
+ ranges.push({
1692
+ row: [r1, r1],
1693
+ column: [c1, c1]
1694
+ });
1695
+ break;
1696
+ }
1697
+ }
1698
+ }
1699
+ }
1700
+ }
1701
+ }
1702
+ } else {
1703
+ for (var r = r1; r <= r2; r += 1) {
1704
+ var sourceCell = (_e = d[r]) === null || _e === void 0 ? void 0 : _e[c1];
1705
+ for (var c = c1 + 1; c <= c2; c += 1) {
1706
+ if (d[r]) {
1707
+ d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (_f = d[r][c]) !== null && _f !== void 0 ? _f : {};
1708
+ }
1709
+ if (file != null) {
1710
+ var srcKey = "".concat(r, "_").concat(c1);
1711
+ var tgtKey = "".concat(r, "_").concat(c);
1712
+ if (dataVerification != null) {
1713
+ var dv = dataVerification[srcKey];
1714
+ if (dv != null) {
1715
+ console.log("[fillRightData] dataVerification copy from", {
1716
+ row: r,
1717
+ col: c1
1718
+ }, "→", {
1719
+ row: r,
1720
+ col: c
1721
+ }, dv);
1722
+ file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_c = {}, _c[tgtKey] = _.cloneDeep(dv), _c));
1723
+ }
1724
+ }
1725
+ if (hyperlink != null && hyperlink[srcKey] != null) {
1726
+ file.hyperlink = __assign(__assign({}, file.hyperlink || {}), (_d = {}, _d[tgtKey] = _.cloneDeep(hyperlink[srcKey]), _d));
1727
+ var tgtCell = (_g = d[r]) === null || _g === void 0 ? void 0 : _g[c];
1728
+ if (tgtCell != null) tgtCell.hl = {
1729
+ r: r,
1730
+ c: c,
1731
+ id: ctx.currentSheetId
1732
+ };
1733
+ }
1734
+ if (cdformat != null && cdformat.length > 0) {
1735
+ for (var i = 0; i < cdformat.length; i += 1) {
1736
+ var ranges = cdformat[i].cellrange;
1737
+ if (!ranges) continue;
1738
+ for (var j = 0; j < ranges.length; j += 1) {
1739
+ var cr = ranges[j];
1740
+ if (r >= cr.row[0] && r <= cr.row[1] && c1 >= cr.column[0] && c1 <= cr.column[1]) {
1741
+ ranges.push({
1742
+ row: [r, r],
1743
+ column: [c, c]
1744
+ });
1745
+ break;
1746
+ }
1747
+ }
1748
+ }
1749
+ }
1750
+ }
1751
+ }
1647
1752
  }
1648
1753
  }
1649
1754
  }
@@ -1651,6 +1756,8 @@ export function fillRightData(ctx) {
1651
1756
  return "success";
1652
1757
  }
1653
1758
  export function fillDownData(ctx) {
1759
+ var _a, _b, _c, _d;
1760
+ var _e, _f, _g;
1654
1761
  var allowEdit = isAllowEdit(ctx);
1655
1762
  if (allowEdit === false) {
1656
1763
  return "allowEdit";
@@ -1678,10 +1785,111 @@ export function fillDownData(ctx) {
1678
1785
  var r2 = selection[s].row[1];
1679
1786
  var c1 = selection[s].column[0];
1680
1787
  var c2 = selection[s].column[1];
1681
- for (var r = r1; r <= r2; r += 1) {
1788
+ var sheetIndex = getSheetIndex(ctx, ctx.currentSheetId);
1789
+ var file = sheetIndex != null ? ctx.luckysheetfile[sheetIndex] : null;
1790
+ var dataVerification = file === null || file === void 0 ? void 0 : file.dataVerification;
1791
+ var hyperlink = file === null || file === void 0 ? void 0 : file.hyperlink;
1792
+ var cdformat = file === null || file === void 0 ? void 0 : file.luckysheet_conditionformat_save;
1793
+ var isSingleCell = r1 === r2 && c1 === c2;
1794
+ if (isSingleCell) {
1795
+ if (r1 - 1 >= 0 && d[r1 - 1]) {
1796
+ var srcRow = r1 - 1;
1797
+ var srcCol = c1;
1798
+ var prev = d[r1 - 1][c1];
1799
+ if (!d[r1]) d[r1] = [];
1800
+ d[r1][c1] = prev != null ? __assign({}, prev) : {};
1801
+ if (file != null) {
1802
+ var srcKey = "".concat(srcRow, "_").concat(srcCol);
1803
+ var tgtKey = "".concat(r1, "_").concat(c1);
1804
+ if (dataVerification != null) {
1805
+ var dv = dataVerification[srcKey];
1806
+ if (dv != null) {
1807
+ console.log("[fillDownData] dataVerification copy from", {
1808
+ row: srcRow,
1809
+ col: srcCol
1810
+ }, "→", {
1811
+ row: r1,
1812
+ col: c1
1813
+ }, dv);
1814
+ file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_a = {}, _a[tgtKey] = _.cloneDeep(dv), _a));
1815
+ }
1816
+ }
1817
+ if (hyperlink != null && hyperlink[srcKey] != null) {
1818
+ file.hyperlink = __assign(__assign({}, file.hyperlink || {}), (_b = {}, _b[tgtKey] = _.cloneDeep(hyperlink[srcKey]), _b));
1819
+ var tgtCell = d[r1][c1];
1820
+ if (tgtCell != null) tgtCell.hl = {
1821
+ r: r1,
1822
+ c: c1,
1823
+ id: ctx.currentSheetId
1824
+ };
1825
+ }
1826
+ if (cdformat != null && cdformat.length > 0) {
1827
+ for (var i = 0; i < cdformat.length; i += 1) {
1828
+ var ranges = cdformat[i].cellrange;
1829
+ if (!ranges) continue;
1830
+ for (var j = 0; j < ranges.length; j += 1) {
1831
+ var cr = ranges[j];
1832
+ if (srcRow >= cr.row[0] && srcRow <= cr.row[1] && srcCol >= cr.column[0] && srcCol <= cr.column[1]) {
1833
+ ranges.push({
1834
+ row: [r1, r1],
1835
+ column: [c1, c1]
1836
+ });
1837
+ break;
1838
+ }
1839
+ }
1840
+ }
1841
+ }
1842
+ }
1843
+ }
1844
+ } else {
1682
1845
  for (var c = c1; c <= c2; c += 1) {
1683
- var previousCell = d[r - 1][c];
1684
- d[r][c] = __assign({}, previousCell);
1846
+ var sourceCell = (_e = d[r1]) === null || _e === void 0 ? void 0 : _e[c];
1847
+ for (var r = r1 + 1; r <= r2; r += 1) {
1848
+ if (!d[r]) d[r] = [];
1849
+ d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (_f = d[r][c]) !== null && _f !== void 0 ? _f : {};
1850
+ if (file != null) {
1851
+ var srcKey = "".concat(r1, "_").concat(c);
1852
+ var tgtKey = "".concat(r, "_").concat(c);
1853
+ if (dataVerification != null) {
1854
+ var dv = dataVerification[srcKey];
1855
+ if (dv != null) {
1856
+ console.log("[fillDownData] dataVerification copy from", {
1857
+ row: r1,
1858
+ col: c
1859
+ }, "→", {
1860
+ row: r,
1861
+ col: c
1862
+ }, dv);
1863
+ file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_c = {}, _c[tgtKey] = _.cloneDeep(dv), _c));
1864
+ }
1865
+ }
1866
+ if (hyperlink != null && hyperlink[srcKey] != null) {
1867
+ file.hyperlink = __assign(__assign({}, file.hyperlink || {}), (_d = {}, _d[tgtKey] = _.cloneDeep(hyperlink[srcKey]), _d));
1868
+ var tgtCell = (_g = d[r]) === null || _g === void 0 ? void 0 : _g[c];
1869
+ if (tgtCell != null) tgtCell.hl = {
1870
+ r: r,
1871
+ c: c,
1872
+ id: ctx.currentSheetId
1873
+ };
1874
+ }
1875
+ if (cdformat != null && cdformat.length > 0) {
1876
+ for (var i = 0; i < cdformat.length; i += 1) {
1877
+ var ranges = cdformat[i].cellrange;
1878
+ if (!ranges) continue;
1879
+ for (var j = 0; j < ranges.length; j += 1) {
1880
+ var cr = ranges[j];
1881
+ if (r1 >= cr.row[0] && r1 <= cr.row[1] && c >= cr.column[0] && c <= cr.column[1]) {
1882
+ ranges.push({
1883
+ row: [r, r],
1884
+ column: [c, c]
1885
+ });
1886
+ break;
1887
+ }
1888
+ }
1889
+ }
1890
+ }
1891
+ }
1892
+ }
1685
1893
  }
1686
1894
  }
1687
1895
  }
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,
@@ -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;