@fileverse-dev/fortune-core 1.3.10-yjs-10 → 1.3.11-input-ref

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.
@@ -13,13 +13,19 @@ exports.functionCopy = functionCopy;
13
13
  exports.functionHTMLGenerate = functionHTMLGenerate;
14
14
  exports.functionStrChange = functionStrChange;
15
15
  exports.getAllFunctionGroup = getAllFunctionGroup;
16
+ exports.getFormulaRangeIndexAtCaret = getFormulaRangeIndexAtCaret;
17
+ exports.getFormulaRangeIndexForKeyboardSync = getFormulaRangeIndexForKeyboardSync;
18
+ exports.getLastFormulaRangeIndex = getLastFormulaRangeIndex;
16
19
  exports.getcellrange = getcellrange;
17
20
  exports.getrangeseleciton = getrangeseleciton;
18
21
  exports.groupValuesRefresh = groupValuesRefresh;
19
22
  exports.handleFormulaInput = handleFormulaInput;
20
23
  exports.insertUpdateFunctionGroup = insertUpdateFunctionGroup;
24
+ exports.isFormulaReferenceInputMode = isFormulaReferenceInputMode;
21
25
  exports.iscelldata = iscelldata;
22
26
  exports.israngeseleciton = israngeseleciton;
27
+ exports.markRangeSelectionDirty = markRangeSelectionDirty;
28
+ exports.maybeRecoverDirtyRangeSelection = maybeRecoverDirtyRangeSelection;
23
29
  exports.moveCursorToEnd = moveCursorToEnd;
24
30
  exports.onFormulaRangeDragEnd = onFormulaRangeDragEnd;
25
31
  exports.rangeDrag = rangeDrag;
@@ -86,6 +92,7 @@ var FormulaCache = exports.FormulaCache = function () {
86
92
  var that = this;
87
93
  this.data_parm_index = 0;
88
94
  this.selectingRangeIndex = -1;
95
+ this.rangeSelectionActive = null;
89
96
  this.functionlistMap = {};
90
97
  this.execFunctionGlobalData = {};
91
98
  this.cellTextToIndexList = {};
@@ -1316,8 +1323,7 @@ function setCaretPosition(ctx, textDom, children, pos, parentTextDom) {
1316
1323
  sel === null || sel === void 0 ? void 0 : sel.removeAllRanges();
1317
1324
  sel === null || sel === void 0 ? void 0 : sel.addRange(range);
1318
1325
  el.focus();
1319
- } catch (err) {
1320
- console.error(err);
1326
+ } catch (_c) {
1321
1327
  moveCursorToEnd(parentTextDom);
1322
1328
  }
1323
1329
  }
@@ -1402,7 +1408,7 @@ function getrangeseleciton() {
1402
1408
  return null;
1403
1409
  }
1404
1410
  function helpFunctionExe($editer, currSelection, ctx) {
1405
- var _a;
1411
+ var _a, _b, _c, _d, _e, _f;
1406
1412
  var functionlist = (0, _locale.locale)(ctx).functionlist;
1407
1413
  if (_lodash.default.isEmpty(ctx.formulaCache.functionlistMap)) {
1408
1414
  for (var i_1 = 0; i_1 < functionlist.length; i_1 += 1) {
@@ -1413,22 +1419,23 @@ function helpFunctionExe($editer, currSelection, ctx) {
1413
1419
  return null;
1414
1420
  }
1415
1421
  var $prev = currSelection;
1416
- var $span = $editer.querySelectorAll("span");
1417
- var currentIndex = _lodash.default.indexOf((_a = currSelection.parentNode) === null || _a === void 0 ? void 0 : _a.childNodes, currSelection);
1422
+ var $span = Array.from($editer.querySelectorAll("span"));
1423
+ var selectionSpan = currSelection.nodeType === Node.ELEMENT_NODE ? currSelection.closest("span") : (_a = currSelection.parentElement) === null || _a === void 0 ? void 0 : _a.closest("span");
1424
+ var currentIndex = selectionSpan ? $span.indexOf(selectionSpan) : -1;
1418
1425
  var i = currentIndex;
1419
- if ($prev == null) {
1426
+ if ($prev == null || currentIndex < 0 || !$span[currentIndex]) {
1420
1427
  return null;
1421
1428
  }
1422
1429
  var funcName = null;
1423
1430
  var paramindex = null;
1424
- if ($span[i].classList.contains("luckysheet-formula-text-func")) {
1431
+ if ((_c = (_b = $span[i]) === null || _b === void 0 ? void 0 : _b.classList) === null || _c === void 0 ? void 0 : _c.contains("luckysheet-formula-text-func")) {
1425
1432
  funcName = $span[i].textContent;
1426
1433
  } else {
1427
1434
  var $cur = null;
1428
1435
  var exceptIndex = [-1, -1];
1429
1436
  while (--i > 0) {
1430
1437
  $cur = $span[i];
1431
- if ($cur.classList.contains("luckysheet-formula-text-func") || _lodash.default.trim($cur.textContent || "").toUpperCase() in ctx.formulaCache.functionlistMap) {
1438
+ if (((_d = $cur === null || $cur === void 0 ? void 0 : $cur.classList) === null || _d === void 0 ? void 0 : _d.contains("luckysheet-formula-text-func")) || _lodash.default.trim($cur.textContent || "").toUpperCase() in ctx.formulaCache.functionlistMap) {
1432
1439
  funcName = $cur.textContent;
1433
1440
  paramindex = null;
1434
1441
  var endstate = true;
@@ -1440,13 +1447,13 @@ function helpFunctionExe($editer, currSelection, ctx) {
1440
1447
  continue;
1441
1448
  }
1442
1449
  $cur = $span[a];
1443
- if ($cur.classList.contains("luckysheet-formula-text-rpar")) {
1450
+ if ((_e = $cur === null || $cur === void 0 ? void 0 : $cur.classList) === null || _e === void 0 ? void 0 : _e.contains("luckysheet-formula-text-rpar")) {
1444
1451
  exceptIndex = [i, a];
1445
1452
  funcName = null;
1446
1453
  endstate = false;
1447
1454
  break;
1448
1455
  }
1449
- if ($cur.classList.contains("luckysheet-formula-text-comma")) {
1456
+ if ((_f = $cur === null || $cur === void 0 ? void 0 : $cur.classList) === null || _f === void 0 ? void 0 : _f.contains("luckysheet-formula-text-comma")) {
1450
1457
  paramindex += 1;
1451
1458
  }
1452
1459
  }
@@ -1479,6 +1486,7 @@ function rangeHightlightselected(ctx, $editor) {
1479
1486
  var funcName = helpFunctionExe($editor, currSelection, ctx);
1480
1487
  ctx.functionHint = funcName === null || funcName === void 0 ? void 0 : funcName.toUpperCase();
1481
1488
  ctx.functionCandidates = [];
1489
+ ctx.defaultCandidates = [];
1482
1490
  }
1483
1491
  }
1484
1492
  function functionHTML(txt) {
@@ -1629,6 +1637,99 @@ function getRangeIndexes($editor) {
1629
1637
  });
1630
1638
  return res;
1631
1639
  }
1640
+ function getLastFormulaRangeIndex($editor) {
1641
+ var spans = Array.from($editor.querySelectorAll("span")).filter(function (span) {
1642
+ var _a;
1643
+ return (_a = span.textContent) === null || _a === void 0 ? void 0 : _a.trim().length;
1644
+ });
1645
+ var lastSpan = spans[spans.length - 1];
1646
+ if (!lastSpan) return null;
1647
+ if (!lastSpan.classList.contains("fortune-formula-functionrange-cell")) {
1648
+ return null;
1649
+ }
1650
+ var indexStr = lastSpan.getAttribute("rangeindex");
1651
+ if (!indexStr) return null;
1652
+ var rangeIndex = parseInt(indexStr, 10);
1653
+ return Number.isNaN(rangeIndex) ? null : rangeIndex;
1654
+ }
1655
+ function getFormulaRangeIndexAtCaret($editor) {
1656
+ var sel = window.getSelection();
1657
+ if (!sel || sel.rangeCount === 0) return null;
1658
+ var anchorNode = sel.anchorNode;
1659
+ if (!anchorNode) return null;
1660
+ var el = anchorNode.nodeType === Node.ELEMENT_NODE ? anchorNode : anchorNode.parentElement;
1661
+ if (!el) return null;
1662
+ var cell = el.closest(".fortune-formula-functionrange-cell");
1663
+ if (!cell || !$editor.contains(cell)) return null;
1664
+ var ri = cell.getAttribute("rangeindex");
1665
+ if (!ri) return null;
1666
+ var n = parseInt(ri, 10);
1667
+ return Number.isNaN(n) ? null : n;
1668
+ }
1669
+ function hasCommaOrAnotherRefAfterRangeCell(cell) {
1670
+ var _a, _b;
1671
+ var n = cell.nextSibling;
1672
+ while (n) {
1673
+ if (n.nodeType === Node.ELEMENT_NODE) {
1674
+ var e = n;
1675
+ if ((_a = e.classList) === null || _a === void 0 ? void 0 : _a.contains("luckysheet-formula-text-comma")) return true;
1676
+ if ((_b = e.classList) === null || _b === void 0 ? void 0 : _b.contains("fortune-formula-functionrange-cell")) return true;
1677
+ }
1678
+ n = n.nextSibling;
1679
+ }
1680
+ return false;
1681
+ }
1682
+ function markRangeSelectionDirty(ctx) {
1683
+ ctx.formulaCache.rangeSelectionActive = false;
1684
+ ctx.formulaRangeHighlight = [];
1685
+ ctx.formulaRangeSelect = undefined;
1686
+ ctx.formulaCache.selectingRangeIndex = -1;
1687
+ ctx.formulaCache.func_selectedrange = undefined;
1688
+ ctx.formulaCache.rangestart = false;
1689
+ ctx.formulaCache.rangedrag_column_start = false;
1690
+ ctx.formulaCache.rangedrag_row_start = false;
1691
+ ctx.formulaCache.rangechangeindex = undefined;
1692
+ }
1693
+ function getFormulaRangeIndexForKeyboardSync($editor) {
1694
+ var atCaret = getFormulaRangeIndexAtCaret($editor);
1695
+ if (atCaret !== null) return atCaret;
1696
+ var lastIdx = getLastFormulaRangeIndex($editor);
1697
+ if (lastIdx === null) return null;
1698
+ var cell = $editor.querySelector("span.fortune-formula-functionrange-cell[rangeindex=\"".concat(lastIdx, "\"]"));
1699
+ if (!cell) return null;
1700
+ var sel = window.getSelection();
1701
+ if (!(sel === null || sel === void 0 ? void 0 : sel.anchorNode)) return lastIdx;
1702
+ var caretRange = document.createRange();
1703
+ try {
1704
+ caretRange.setStart(sel.anchorNode, sel.anchorOffset);
1705
+ caretRange.collapse(true);
1706
+ } catch (_a) {
1707
+ return lastIdx;
1708
+ }
1709
+ var cellRange = document.createRange();
1710
+ try {
1711
+ cellRange.selectNodeContents(cell);
1712
+ } catch (_b) {
1713
+ return lastIdx;
1714
+ }
1715
+ if (caretRange.compareBoundaryPoints(Range.START_TO_START, cellRange) < 0) {
1716
+ return null;
1717
+ }
1718
+ var afterCell = document.createRange();
1719
+ try {
1720
+ afterCell.setStartAfter(cell);
1721
+ afterCell.collapse(true);
1722
+ } catch (_c) {
1723
+ return lastIdx;
1724
+ }
1725
+ if (caretRange.compareBoundaryPoints(Range.START_TO_START, afterCell) >= 0) {
1726
+ if (hasCommaOrAnotherRefAfterRangeCell(cell)) {
1727
+ return null;
1728
+ }
1729
+ return lastIdx;
1730
+ }
1731
+ return lastIdx;
1732
+ }
1632
1733
  function handleFormulaInput(ctx, $copyTo, $editor, kcode, preText, refreshRangeSelect) {
1633
1734
  var _a, _b, _c, _d, _e, _f;
1634
1735
  if (refreshRangeSelect === void 0) {
@@ -1636,6 +1737,13 @@ function handleFormulaInput(ctx, $copyTo, $editor, kcode, preText, refreshRangeS
1636
1737
  }
1637
1738
  if (!$editor) return;
1638
1739
  try {
1740
+ var isBackspaceOrDelete = kcode === 8 || kcode === 46;
1741
+ var isAlphaNumeric = kcode >= 48 && kcode <= 57 || kcode >= 65 && kcode <= 90 || kcode >= 97 && kcode <= 122;
1742
+ if (ctx.formulaCache.rangeSelectionActive === true) {
1743
+ if (isBackspaceOrDelete || isAlphaNumeric) {
1744
+ markRangeSelectionDirty(ctx);
1745
+ }
1746
+ }
1639
1747
  var value1 = void 0;
1640
1748
  var value1txt = preText !== null && preText !== void 0 ? preText : $editor.innerText;
1641
1749
  var value = $editor.innerText;
@@ -1866,61 +1974,204 @@ function functionStrChange_range(txt, type, rc, orient, stindex, step) {
1866
1974
  }
1867
1975
  return "";
1868
1976
  }
1977
+ function setRangeSetValueToFromCaretPosition(ctx, editor, sel) {
1978
+ if (sel.rangeCount === 0 || !sel.anchorNode) return false;
1979
+ if (!editor.contains(sel.anchorNode)) return false;
1980
+ var range = sel.getRangeAt(0).cloneRange();
1981
+ range.collapse(true);
1982
+ var startContainer = range.startContainer,
1983
+ startOffset = range.startOffset;
1984
+ if (startContainer.nodeType === Node.TEXT_NODE) {
1985
+ if (startOffset === 0) {
1986
+ var textParent = startContainer.parentElement;
1987
+ if (textParent === editor) {
1988
+ var prev = startContainer.previousSibling;
1989
+ if (prev) {
1990
+ ctx.formulaCache.rangeSetValueTo = prev;
1991
+ return true;
1992
+ }
1993
+ return false;
1994
+ }
1995
+ var el = textParent;
1996
+ while (el && el !== editor) {
1997
+ if (el.previousSibling) {
1998
+ ctx.formulaCache.rangeSetValueTo = el.previousSibling;
1999
+ return true;
2000
+ }
2001
+ el = el.parentElement;
2002
+ }
2003
+ return false;
2004
+ }
2005
+ var p = startContainer.parentElement;
2006
+ if (p && editor.contains(p)) {
2007
+ ctx.formulaCache.rangeSetValueTo = p;
2008
+ return true;
2009
+ }
2010
+ return false;
2011
+ }
2012
+ if (startContainer.nodeType === Node.ELEMENT_NODE && startContainer === editor) {
2013
+ if (startOffset > 0) {
2014
+ var prev = startContainer.childNodes[startOffset - 1];
2015
+ if (prev) {
2016
+ ctx.formulaCache.rangeSetValueTo = prev;
2017
+ return true;
2018
+ }
2019
+ }
2020
+ return false;
2021
+ }
2022
+ if (startContainer.nodeType === Node.ELEMENT_NODE) {
2023
+ if (startOffset > 0) {
2024
+ var prev = startContainer.childNodes[startOffset - 1];
2025
+ if (prev) {
2026
+ ctx.formulaCache.rangeSetValueTo = prev;
2027
+ return true;
2028
+ }
2029
+ }
2030
+ var el = startContainer;
2031
+ while (el && el !== editor) {
2032
+ if (el.previousSibling) {
2033
+ ctx.formulaCache.rangeSetValueTo = el.previousSibling;
2034
+ return true;
2035
+ }
2036
+ el = el.parentElement;
2037
+ }
2038
+ }
2039
+ return false;
2040
+ }
1869
2041
  function israngeseleciton(ctx, istooltip) {
1870
- var _a, _b, _c;
2042
+ var _a, _b, _c, _d;
1871
2043
  if (istooltip == null) {
1872
2044
  istooltip = false;
1873
2045
  }
1874
2046
  var currSelection = window.getSelection();
1875
- if (currSelection == null) return false;
2047
+ if (currSelection == null) {
2048
+ return false;
2049
+ }
1876
2050
  var anchor = currSelection.anchorNode;
1877
- if (!(anchor === null || anchor === void 0 ? void 0 : anchor.textContent)) return false;
2051
+ if (!anchor) {
2052
+ return false;
2053
+ }
1878
2054
  var anchorOffset = currSelection.anchorOffset;
1879
2055
  var anchorElement = anchor;
1880
2056
  var parentElement = anchor.parentNode;
2057
+ var allowRangeInsertionAtCaret = function allowRangeInsertionAtCaret() {
2058
+ var _a, _b;
2059
+ if (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || ctx.formulaCache.rangeSelectionActive === true) {
2060
+ return true;
2061
+ }
2062
+ var editor = ((_a = anchorElement.closest) === null || _a === void 0 ? void 0 : _a.call(anchorElement, "#luckysheet-rich-text-editor, #luckysheet-functionbox-cell")) || ((_b = parentElement.closest) === null || _b === void 0 ? void 0 : _b.call(parentElement, "#luckysheet-rich-text-editor, #luckysheet-functionbox-cell")) || document.getElementById("luckysheet-rich-text-editor");
2063
+ if (!editor || currSelection.rangeCount === 0) {
2064
+ return true;
2065
+ }
2066
+ var inputText = editor.innerText.trim();
2067
+ if (!inputText.startsWith("=")) {
2068
+ return false;
2069
+ }
2070
+ if (/^=\s*[A-Za-z_][A-Za-z0-9_]*$/.test(inputText)) {
2071
+ return false;
2072
+ }
2073
+ var caretRange = currSelection.getRangeAt(0).cloneRange();
2074
+ var preCaretRange = document.createRange();
2075
+ preCaretRange.selectNodeContents(editor);
2076
+ preCaretRange.setEnd(caretRange.endContainer, caretRange.endOffset);
2077
+ var caretOffset = preCaretRange.toString().length;
2078
+ var textAfter = editor.innerText.slice(caretOffset);
2079
+ var remaining = textAfter.replace(/^\s+/, "");
2080
+ if (remaining.length === 0) {
2081
+ return true;
2082
+ }
2083
+ var first = remaining[0];
2084
+ if (first === "," || first === ")" || first === "&" || first in operatorjson) {
2085
+ return true;
2086
+ }
2087
+ return false;
2088
+ };
1881
2089
  if (((_a = anchor === null || anchor === void 0 ? void 0 : anchor.parentNode) === null || _a === void 0 ? void 0 : _a.nodeName.toLowerCase()) === "span" && anchorOffset !== 0) {
1882
- var txt = _lodash.default.trim(anchor.textContent);
2090
+ var txt = _lodash.default.trim((_b = anchor.textContent) !== null && _b !== void 0 ? _b : "");
1883
2091
  var lasttxt = "";
1884
2092
  if (txt.length === 0 && anchor.parentNode.previousSibling) {
1885
2093
  var ahr = anchor.parentNode.previousSibling;
1886
2094
  txt = _lodash.default.trim(ahr.textContent || "");
1887
- lasttxt = txt.substring(txt.length - 1, 1);
1888
- ctx.formulaCache.rangeSetValueTo = anchor.parentNode;
2095
+ lasttxt = txt.slice(-1);
1889
2096
  } else {
1890
- lasttxt = txt.substring(anchorOffset - 1, 1);
1891
- ctx.formulaCache.rangeSetValueTo = anchor.parentNode;
2097
+ lasttxt = anchorOffset > 0 ? txt.charAt(anchorOffset - 1) : "";
1892
2098
  }
1893
2099
  if (istooltip && (lasttxt === "(" || lasttxt === ",") || !istooltip && (lasttxt === "(" || lasttxt === "," || lasttxt === "=" || lasttxt in operatorjson || lasttxt === "&")) {
1894
- return true;
2100
+ ctx.formulaCache.rangeSetValueTo = anchor.parentNode;
2101
+ return allowRangeInsertionAtCaret();
1895
2102
  }
1896
2103
  } else if (anchorElement.id === "luckysheet-rich-text-editor" || anchorElement.id === "luckysheet-functionbox-cell") {
1897
- var txt = _lodash.default.trim((_b = _lodash.default.last(anchorElement.querySelectorAll("span"))) === null || _b === void 0 ? void 0 : _b.innerText);
1898
- ctx.formulaCache.rangeSetValueTo = _lodash.default.last(anchorElement.querySelectorAll("span"));
1899
- if (txt.length === 0 && anchorElement.querySelectorAll("span").length > 1) {
1900
- var ahr = anchorElement.querySelectorAll("span");
1901
- txt = _lodash.default.trim(ahr[ahr.length - 2].innerText);
1902
- txt = _lodash.default.trim(ahr[ahr.length - 2].innerText);
1903
- ctx.formulaCache.rangeSetValueTo = ahr;
2104
+ var editorEl = anchorElement;
2105
+ if (currSelection.rangeCount > 0 && setRangeSetValueToFromCaretPosition(ctx, editorEl, currSelection) && allowRangeInsertionAtCaret()) {
2106
+ return true;
1904
2107
  }
1905
- var lasttxt = txt.substring(txt.length - 1, 1);
2108
+ var spans = editorEl.querySelectorAll("span");
2109
+ var txt = _lodash.default.trim((_c = _lodash.default.last(spans)) === null || _c === void 0 ? void 0 : _c.innerText);
2110
+ var refSpan = _lodash.default.last(spans);
2111
+ if (txt.length === 0 && spans.length > 1) {
2112
+ txt = _lodash.default.trim(spans[spans.length - 2].innerText);
2113
+ refSpan = spans[spans.length - 2];
2114
+ }
2115
+ var lasttxt = txt.slice(-1);
1906
2116
  if (istooltip && (lasttxt === "(" || lasttxt === ",") || !istooltip && (lasttxt === "(" || lasttxt === "," || lasttxt === "=" || lasttxt in operatorjson || lasttxt === "&")) {
1907
- return true;
2117
+ ctx.formulaCache.rangeSetValueTo = refSpan;
2118
+ return allowRangeInsertionAtCaret();
1908
2119
  }
1909
2120
  } else if (parentElement.id === "luckysheet-rich-text-editor" || parentElement.id === "luckysheet-functionbox-cell" || anchorOffset === 0) {
1910
2121
  if (anchorOffset === 0) {
1911
2122
  anchor = anchor.parentNode;
1912
2123
  }
1913
- if (!anchor) return false;
1914
- if (((_c = anchor.previousSibling) === null || _c === void 0 ? void 0 : _c.textContent) == null) return false;
2124
+ if (!anchor) {
2125
+ return false;
2126
+ }
2127
+ if (((_d = anchor.previousSibling) === null || _d === void 0 ? void 0 : _d.textContent) == null) {
2128
+ return false;
2129
+ }
1915
2130
  if (anchor.previousSibling) {
1916
2131
  var txt = _lodash.default.trim(anchor.previousSibling.textContent);
1917
- var lasttxt = txt.substring(txt.length - 1, 1);
1918
- ctx.formulaCache.rangeSetValueTo = anchor.previousSibling;
2132
+ var lasttxt = txt.slice(-1);
1919
2133
  if (istooltip && (lasttxt === "(" || lasttxt === ",") || !istooltip && (lasttxt === "(" || lasttxt === "," || lasttxt === "=" || lasttxt in operatorjson || lasttxt === "&")) {
1920
- return true;
2134
+ ctx.formulaCache.rangeSetValueTo = anchor.previousSibling;
2135
+ return allowRangeInsertionAtCaret();
1921
2136
  }
1922
2137
  }
1923
2138
  }
2139
+ if (!istooltip && (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || ctx.formulaCache.rangeSelectionActive === true)) {
2140
+ var editor = document.getElementById("luckysheet-rich-text-editor") || document.getElementById("luckysheet-functionbox-cell");
2141
+ if (editor && currSelection.rangeCount > 0 && setRangeSetValueToFromCaretPosition(ctx, editor, currSelection) && allowRangeInsertionAtCaret()) {
2142
+ return true;
2143
+ }
2144
+ }
2145
+ return false;
2146
+ }
2147
+ function isFormulaReferenceInputMode(ctx) {
2148
+ var editor = document.getElementById("luckysheet-rich-text-editor");
2149
+ var inputText = ((editor === null || editor === void 0 ? void 0 : editor.innerText) || "").trim();
2150
+ var hasRangeToken = (editor === null || editor === void 0 ? void 0 : editor.querySelector("span.fortune-formula-functionrange-cell")) != null;
2151
+ if (!!ctx.formulaCache.rangestart || !!ctx.formulaCache.rangedrag_column_start || !!ctx.formulaCache.rangedrag_row_start || hasRangeToken || ctx.formulaCache.rangeSelectionActive === true) {
2152
+ return true;
2153
+ }
2154
+ if (!inputText.startsWith("=")) {
2155
+ return false;
2156
+ }
2157
+ if (/^=\s*[A-Za-z_][A-Za-z0-9_]*$/.test(inputText)) {
2158
+ return false;
2159
+ }
2160
+ return israngeseleciton(ctx);
2161
+ }
2162
+ function maybeRecoverDirtyRangeSelection(ctx) {
2163
+ if (ctx.formulaCache.rangeSelectionActive !== false) {
2164
+ return false;
2165
+ }
2166
+ var editor = document.getElementById("luckysheet-rich-text-editor");
2167
+ if (!editor) {
2168
+ return false;
2169
+ }
2170
+ var inputText = (editor.innerText || "").trim();
2171
+ if (inputText.startsWith("=") && israngeseleciton(ctx)) {
2172
+ ctx.formulaCache.rangeSelectionActive = null;
2173
+ return true;
2174
+ }
1924
2175
  return false;
1925
2176
  }
1926
2177
  function functionStrChange(txt, type, rc, orient, stindex, step) {
@@ -2018,18 +2269,22 @@ function functionStrChange(txt, type, rc, orient, stindex, step) {
2018
2269
  return function_str;
2019
2270
  }
2020
2271
  function rangeSetValue(ctx, cellInput, selected, fxInput) {
2021
- var _a, _b, _c, _d, _e;
2272
+ var _a, _b, _c, _d, _e, _f, _g;
2022
2273
  var parser = new DOMParser();
2023
2274
  var doc = parser.parseFromString("<div>".concat(cellInput.innerHTML, "</div>"), "text/html");
2024
2275
  var spans = doc.querySelectorAll("span");
2025
2276
  var lastSpan = spans[spans.length - 1];
2026
- if (lastSpan && (0, _index.isLetterNumberPattern)(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText)) {
2277
+ var isManagedRangeSpan = (_b = (_a = lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.classList) === null || _a === void 0 ? void 0 : _a.contains("fortune-formula-functionrange-cell")) !== null && _b !== void 0 ? _b : false;
2278
+ if (lastSpan && (0, _index.isLetterNumberPattern)(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) && !isManagedRangeSpan) {
2027
2279
  var htmlR = (0, _index.removeLastSpan)(cellInput.innerHTML);
2028
2280
  cellInput.innerHTML = "".concat(htmlR);
2281
+ cellInput.focus();
2282
+ var kids = cellInput.childNodes;
2283
+ ctx.formulaCache.rangeSetValueTo = kids.length > 0 ? kids[kids.length - 1] : undefined;
2029
2284
  }
2030
2285
  var $editor = cellInput;
2031
2286
  var $copyTo = fxInput;
2032
- if (((_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.id) === "luckysheet-functionbox-cell") {
2287
+ if (((_c = document.activeElement) === null || _c === void 0 ? void 0 : _c.id) === "luckysheet-functionbox-cell") {
2033
2288
  $editor = fxInput;
2034
2289
  $copyTo = cellInput;
2035
2290
  }
@@ -2044,20 +2299,23 @@ function rangeSetValue(ctx, cellInput, selected, fxInput) {
2044
2299
  } else {
2045
2300
  range = (0, _cell.getRangetxt)(ctx, ctx.currentSheetId, selected, ctx.formulaCache.rangetosheet);
2046
2301
  }
2047
- if (!israngeseleciton(ctx) && (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start)) {
2048
- var span = $editor.querySelector("span[rangeindex='".concat(ctx.formulaCache.rangechangeindex, "']"));
2049
- if (span) {
2050
- span.innerHTML = range;
2051
- setCaretPosition(ctx, span, 0, range.length);
2052
- }
2302
+ var activeRangeFlow = ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || ctx.formulaCache.rangeSelectionActive === true;
2303
+ var spanToReplace = !_lodash.default.isNil(ctx.formulaCache.rangechangeindex) ? $editor.querySelector("span[rangeindex='".concat(ctx.formulaCache.rangechangeindex, "']")) : null;
2304
+ if (activeRangeFlow && spanToReplace) {
2305
+ spanToReplace.innerHTML = range;
2306
+ setCaretPosition(ctx, spanToReplace, 0, range.length);
2053
2307
  } else {
2054
2308
  var function_str = "<span class=\"fortune-formula-functionrange-cell\" rangeindex=\"".concat(functionHTMLIndex, "\" dir=\"auto\" style=\"color:").concat(_color.colors[functionHTMLIndex], ";\">").concat(range, "</span>");
2055
2309
  var newEle = parseElement(function_str);
2056
2310
  var refEle = ctx.formulaCache.rangeSetValueTo;
2311
+ if (refEle && !refEle.parentNode) {
2312
+ israngeseleciton(ctx);
2313
+ refEle = ctx.formulaCache.rangeSetValueTo;
2314
+ }
2057
2315
  if (refEle && refEle.parentNode) {
2058
- var leftPar = (_b = document.getElementsByClassName("luckysheet-formula-text-lpar")) === null || _b === void 0 ? void 0 : _b[0];
2059
- if ((_c = leftPar === null || leftPar === void 0 ? void 0 : leftPar.parentElement) === null || _c === void 0 ? void 0 : _c.classList.contains("luckysheet-formula-text-color")) {
2060
- (_e = (_d = document.getElementsByClassName("luckysheet-formula-text-lpar")) === null || _d === void 0 ? void 0 : _d[0].parentNode) === null || _e === void 0 ? void 0 : _e.appendChild(newEle);
2316
+ var leftPar = (_d = document.getElementsByClassName("luckysheet-formula-text-lpar")) === null || _d === void 0 ? void 0 : _d[0];
2317
+ if ((_e = leftPar === null || leftPar === void 0 ? void 0 : leftPar.parentElement) === null || _e === void 0 ? void 0 : _e.classList.contains("luckysheet-formula-text-color")) {
2318
+ (_g = (_f = document.getElementsByClassName("luckysheet-formula-text-lpar")) === null || _f === void 0 ? void 0 : _f[0].parentNode) === null || _g === void 0 ? void 0 : _g.appendChild(newEle);
2061
2319
  } else {
2062
2320
  refEle.parentNode.insertBefore(newEle, refEle.nextSibling);
2063
2321
  }
@@ -2097,6 +2355,7 @@ function setRangeSelect(container, left, top, height, width) {
2097
2355
  rangeElement.style.width = "".concat(width, "px");
2098
2356
  }
2099
2357
  function rangeDrag(ctx, e, cellInput, scrollLeft, scrollTop, container, fxInput) {
2358
+ ctx.formulaCache.rangeSelectionActive = true;
2100
2359
  var func_selectedrange = ctx.formulaCache.func_selectedrange;
2101
2360
  if (!func_selectedrange || func_selectedrange.left == null || func_selectedrange.height == null || func_selectedrange.top == null || func_selectedrange.width == null) return;
2102
2361
  var rect = container.getBoundingClientRect();
@@ -2152,6 +2411,20 @@ function rangeDrag(ctx, e, cellInput, scrollLeft, scrollTop, container, fxInput)
2152
2411
  func_selectedrange.width_move = width;
2153
2412
  func_selectedrange.top_move = top;
2154
2413
  func_selectedrange.height_move = height;
2414
+ ctx.luckysheet_select_save = [{
2415
+ row: [rowseleted[0], rowseleted[1]],
2416
+ column: [columnseleted[0], columnseleted[1]],
2417
+ row_focus: row_index,
2418
+ column_focus: col_index,
2419
+ left: left,
2420
+ top: top,
2421
+ width: width,
2422
+ height: height,
2423
+ left_move: left,
2424
+ top_move: top,
2425
+ width_move: width,
2426
+ height_move: height
2427
+ }];
2155
2428
  rangeSetValue(ctx, cellInput, {
2156
2429
  row: rowseleted,
2157
2430
  column: columnseleted
@@ -2160,6 +2433,7 @@ function rangeDrag(ctx, e, cellInput, scrollLeft, scrollTop, container, fxInput)
2160
2433
  e.preventDefault();
2161
2434
  }
2162
2435
  function rangeDragColumn(ctx, e, cellInput, scrollLeft, scrollTop, container, fxInput) {
2436
+ ctx.formulaCache.rangeSelectionActive = true;
2163
2437
  var func_selectedrange = ctx.formulaCache.func_selectedrange;
2164
2438
  if (!func_selectedrange || func_selectedrange.left == null || func_selectedrange.height == null || func_selectedrange.top == null || func_selectedrange.width == null) return;
2165
2439
  var mouse = (0, _location.mousePosition)(e.pageX, e.pageY, ctx);
@@ -2195,6 +2469,20 @@ function rangeDragColumn(ctx, e, cellInput, scrollLeft, scrollTop, container, fx
2195
2469
  func_selectedrange.column = columnseleted;
2196
2470
  func_selectedrange.left_move = left;
2197
2471
  func_selectedrange.width_move = width;
2472
+ ctx.luckysheet_select_save = [{
2473
+ row: [0, row_index],
2474
+ column: [columnseleted[0], columnseleted[1]],
2475
+ row_focus: 0,
2476
+ column_focus: col_index,
2477
+ left: left,
2478
+ top: row_pre,
2479
+ width: width,
2480
+ height: row - row_pre - 1,
2481
+ left_move: left,
2482
+ top_move: row_pre,
2483
+ width_move: width,
2484
+ height_move: row - row_pre - 1
2485
+ }];
2198
2486
  rangeSetValue(ctx, cellInput, {
2199
2487
  row: [null, null],
2200
2488
  column: columnseleted
@@ -2202,6 +2490,7 @@ function rangeDragColumn(ctx, e, cellInput, scrollLeft, scrollTop, container, fx
2202
2490
  setRangeSelect(container, left, row_pre, row - row_pre - 1, width);
2203
2491
  }
2204
2492
  function rangeDragRow(ctx, e, cellInput, scrollLeft, scrollTop, container, fxInput) {
2493
+ ctx.formulaCache.rangeSelectionActive = true;
2205
2494
  var func_selectedrange = ctx.formulaCache.func_selectedrange;
2206
2495
  if (!func_selectedrange || func_selectedrange.left == null || func_selectedrange.height == null || func_selectedrange.top == null || func_selectedrange.width == null) return;
2207
2496
  var mouse = (0, _location.mousePosition)(e.pageX, e.pageY, ctx);
@@ -2237,6 +2526,20 @@ function rangeDragRow(ctx, e, cellInput, scrollLeft, scrollTop, container, fxInp
2237
2526
  func_selectedrange.row = rowseleted;
2238
2527
  func_selectedrange.top_move = top;
2239
2528
  func_selectedrange.height_move = height;
2529
+ ctx.luckysheet_select_save = [{
2530
+ row: [rowseleted[0], rowseleted[1]],
2531
+ column: [0, col_index],
2532
+ row_focus: row_index,
2533
+ column_focus: 0,
2534
+ left: col_pre,
2535
+ top: top,
2536
+ width: col - col_pre - 1,
2537
+ height: height,
2538
+ left_move: col_pre,
2539
+ top_move: top,
2540
+ width_move: col - col_pre - 1,
2541
+ height_move: height
2542
+ }];
2240
2543
  rangeSetValue(ctx, cellInput, {
2241
2544
  row: rowseleted,
2242
2545
  column: [null, null]
@@ -1760,13 +1760,6 @@ function fillRightData(ctx) {
1760
1760
  if (dataVerification != null) {
1761
1761
  var dv = dataVerification[srcKey];
1762
1762
  if (dv != null) {
1763
- console.log("[fillRightData] dataVerification copy from", {
1764
- row: srcRow,
1765
- col: srcCol
1766
- }, "→", {
1767
- row: r1,
1768
- col: c1
1769
- }, dv);
1770
1763
  file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_a = {}, _a[tgtKey] = _lodash.default.cloneDeep(dv), _a));
1771
1764
  }
1772
1765
  }
@@ -1821,13 +1814,6 @@ function fillRightData(ctx) {
1821
1814
  if (dataVerification != null) {
1822
1815
  var dv = dataVerification[srcKey];
1823
1816
  if (dv != null) {
1824
- console.log("[fillRightData] dataVerification copy from", {
1825
- row: r,
1826
- col: c1
1827
- }, "→", {
1828
- row: r,
1829
- col: c
1830
- }, dv);
1831
1817
  file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_c = {}, _c[tgtKey] = _lodash.default.cloneDeep(dv), _c));
1832
1818
  }
1833
1819
  }
@@ -1928,13 +1914,6 @@ function fillDownData(ctx) {
1928
1914
  if (dataVerification != null) {
1929
1915
  var dv = dataVerification[srcKey];
1930
1916
  if (dv != null) {
1931
- console.log("[fillDownData] dataVerification copy from", {
1932
- row: srcRow,
1933
- col: srcCol
1934
- }, "→", {
1935
- row: r1,
1936
- col: c1
1937
- }, dv);
1938
1917
  file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_a = {}, _a[tgtKey] = _lodash.default.cloneDeep(dv), _a));
1939
1918
  }
1940
1919
  }
@@ -1988,13 +1967,6 @@ function fillDownData(ctx) {
1988
1967
  if (dataVerification != null) {
1989
1968
  var dv = dataVerification[srcKey];
1990
1969
  if (dv != null) {
1991
- console.log("[fillDownData] dataVerification copy from", {
1992
- row: r1,
1993
- col: c
1994
- }, "→", {
1995
- row: r,
1996
- col: c
1997
- }, dv);
1998
1970
  file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_c = {}, _c[tgtKey] = _lodash.default.cloneDeep(dv), _c));
1999
1971
  }
2000
1972
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.3.10-yjs-10",
3
+ "version": "1.3.11-input-ref",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",