@fileverse-dev/fortune-core 1.3.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.
- package/es/api/range.js +20 -0
- package/es/api/sheet.js +30 -2
- package/es/events/keyboard.js +50 -15
- package/es/events/mouse.js +36 -20
- package/es/events/paste.js +77 -28
- package/es/modules/cell.js +59 -2
- package/es/modules/comment.js +129 -24
- package/es/modules/dataVerification.js +34 -1
- package/es/modules/dropCell.js +65 -1
- package/es/modules/formula.d.ts +7 -0
- package/es/modules/formula.js +356 -45
- package/es/modules/hyperlink.js +52 -5
- package/es/modules/merge.js +93 -1
- package/es/modules/moveCells.js +35 -9
- package/es/modules/rowcol.js +75 -2
- package/es/modules/searchReplace.js +58 -2
- package/es/modules/selection.js +152 -42
- package/es/modules/sort.js +74 -9
- package/es/modules/splitColumn.js +21 -0
- package/es/modules/toolbar.js +46 -3
- package/es/settings.d.ts +5 -0
- package/lib/api/range.js +20 -0
- package/lib/api/sheet.js +29 -1
- package/lib/events/keyboard.js +49 -14
- package/lib/events/mouse.js +35 -19
- package/lib/events/paste.js +77 -28
- package/lib/modules/cell.js +59 -2
- package/lib/modules/comment.js +129 -24
- package/lib/modules/dataVerification.js +34 -1
- package/lib/modules/dropCell.js +65 -1
- package/lib/modules/formula.d.ts +7 -0
- package/lib/modules/formula.js +362 -45
- package/lib/modules/hyperlink.js +52 -5
- package/lib/modules/merge.js +93 -1
- package/lib/modules/moveCells.js +35 -9
- package/lib/modules/rowcol.js +75 -2
- package/lib/modules/searchReplace.js +58 -2
- package/lib/modules/selection.js +152 -42
- package/lib/modules/sort.js +74 -9
- package/lib/modules/splitColumn.js +21 -0
- package/lib/modules/toolbar.js +46 -3
- package/lib/settings.d.ts +5 -0
- package/package.json +1 -1
package/es/modules/formula.js
CHANGED
|
@@ -55,6 +55,7 @@ var FormulaCache = function () {
|
|
|
55
55
|
var that = this;
|
|
56
56
|
this.data_parm_index = 0;
|
|
57
57
|
this.selectingRangeIndex = -1;
|
|
58
|
+
this.rangeSelectionActive = null;
|
|
58
59
|
this.functionlistMap = {};
|
|
59
60
|
this.execFunctionGlobalData = {};
|
|
60
61
|
this.cellTextToIndexList = {};
|
|
@@ -785,6 +786,7 @@ function insertUpdateDynamicArray(ctx, dynamicArrayItem) {
|
|
|
785
786
|
return dynamicArray;
|
|
786
787
|
}
|
|
787
788
|
export function groupValuesRefresh(ctx) {
|
|
789
|
+
var _a, _b, _c;
|
|
788
790
|
var luckysheetfile = ctx.luckysheetfile;
|
|
789
791
|
if (ctx.groupValuesRefreshData.length > 0) {
|
|
790
792
|
for (var i = 0; i < ctx.groupValuesRefreshData.length; i += 1) {
|
|
@@ -807,6 +809,19 @@ export function groupValuesRefresh(ctx) {
|
|
|
807
809
|
updateValue.v = item.v;
|
|
808
810
|
updateValue.f = item.f;
|
|
809
811
|
setCellValue(ctx, item.r, item.c, data, updateValue);
|
|
812
|
+
if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc) {
|
|
813
|
+
ctx.hooks.updateCellYdoc([{
|
|
814
|
+
sheetId: item.id,
|
|
815
|
+
path: ["celldata"],
|
|
816
|
+
value: {
|
|
817
|
+
r: item.r,
|
|
818
|
+
c: item.c,
|
|
819
|
+
v: (_c = (_b = data === null || data === void 0 ? void 0 : data[item.r]) === null || _b === void 0 ? void 0 : _b[item.c]) !== null && _c !== void 0 ? _c : null
|
|
820
|
+
},
|
|
821
|
+
key: "".concat(item.r, "_").concat(item.c),
|
|
822
|
+
type: "update"
|
|
823
|
+
}]);
|
|
824
|
+
}
|
|
810
825
|
}
|
|
811
826
|
ctx.groupValuesRefreshData = [];
|
|
812
827
|
}
|
|
@@ -1272,8 +1287,7 @@ export function setCaretPosition(ctx, textDom, children, pos, parentTextDom) {
|
|
|
1272
1287
|
sel === null || sel === void 0 ? void 0 : sel.removeAllRanges();
|
|
1273
1288
|
sel === null || sel === void 0 ? void 0 : sel.addRange(range);
|
|
1274
1289
|
el.focus();
|
|
1275
|
-
} catch (
|
|
1276
|
-
console.error(err);
|
|
1290
|
+
} catch (_c) {
|
|
1277
1291
|
moveCursorToEnd(parentTextDom);
|
|
1278
1292
|
}
|
|
1279
1293
|
}
|
|
@@ -1358,7 +1372,7 @@ export function getrangeseleciton() {
|
|
|
1358
1372
|
return null;
|
|
1359
1373
|
}
|
|
1360
1374
|
function helpFunctionExe($editer, currSelection, ctx) {
|
|
1361
|
-
var _a;
|
|
1375
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1362
1376
|
var functionlist = locale(ctx).functionlist;
|
|
1363
1377
|
if (_.isEmpty(ctx.formulaCache.functionlistMap)) {
|
|
1364
1378
|
for (var i_1 = 0; i_1 < functionlist.length; i_1 += 1) {
|
|
@@ -1369,22 +1383,23 @@ function helpFunctionExe($editer, currSelection, ctx) {
|
|
|
1369
1383
|
return null;
|
|
1370
1384
|
}
|
|
1371
1385
|
var $prev = currSelection;
|
|
1372
|
-
var $span = $editer.querySelectorAll("span");
|
|
1373
|
-
var
|
|
1386
|
+
var $span = Array.from($editer.querySelectorAll("span"));
|
|
1387
|
+
var selectionSpan = currSelection.nodeType === Node.ELEMENT_NODE ? currSelection.closest("span") : (_a = currSelection.parentElement) === null || _a === void 0 ? void 0 : _a.closest("span");
|
|
1388
|
+
var currentIndex = selectionSpan ? $span.indexOf(selectionSpan) : -1;
|
|
1374
1389
|
var i = currentIndex;
|
|
1375
|
-
if ($prev == null) {
|
|
1390
|
+
if ($prev == null || currentIndex < 0 || !$span[currentIndex]) {
|
|
1376
1391
|
return null;
|
|
1377
1392
|
}
|
|
1378
1393
|
var funcName = null;
|
|
1379
1394
|
var paramindex = null;
|
|
1380
|
-
if ($span[i].classList.contains("luckysheet-formula-text-func")) {
|
|
1395
|
+
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")) {
|
|
1381
1396
|
funcName = $span[i].textContent;
|
|
1382
1397
|
} else {
|
|
1383
1398
|
var $cur = null;
|
|
1384
1399
|
var exceptIndex = [-1, -1];
|
|
1385
1400
|
while (--i > 0) {
|
|
1386
1401
|
$cur = $span[i];
|
|
1387
|
-
if ($cur.classList.contains("luckysheet-formula-text-func") || _.trim($cur.textContent || "").toUpperCase() in ctx.formulaCache.functionlistMap) {
|
|
1402
|
+
if (((_d = $cur === null || $cur === void 0 ? void 0 : $cur.classList) === null || _d === void 0 ? void 0 : _d.contains("luckysheet-formula-text-func")) || _.trim($cur.textContent || "").toUpperCase() in ctx.formulaCache.functionlistMap) {
|
|
1388
1403
|
funcName = $cur.textContent;
|
|
1389
1404
|
paramindex = null;
|
|
1390
1405
|
var endstate = true;
|
|
@@ -1396,13 +1411,13 @@ function helpFunctionExe($editer, currSelection, ctx) {
|
|
|
1396
1411
|
continue;
|
|
1397
1412
|
}
|
|
1398
1413
|
$cur = $span[a];
|
|
1399
|
-
if ($cur.classList.contains("luckysheet-formula-text-rpar")) {
|
|
1414
|
+
if ((_e = $cur === null || $cur === void 0 ? void 0 : $cur.classList) === null || _e === void 0 ? void 0 : _e.contains("luckysheet-formula-text-rpar")) {
|
|
1400
1415
|
exceptIndex = [i, a];
|
|
1401
1416
|
funcName = null;
|
|
1402
1417
|
endstate = false;
|
|
1403
1418
|
break;
|
|
1404
1419
|
}
|
|
1405
|
-
if ($cur.classList.contains("luckysheet-formula-text-comma")) {
|
|
1420
|
+
if ((_f = $cur === null || $cur === void 0 ? void 0 : $cur.classList) === null || _f === void 0 ? void 0 : _f.contains("luckysheet-formula-text-comma")) {
|
|
1406
1421
|
paramindex += 1;
|
|
1407
1422
|
}
|
|
1408
1423
|
}
|
|
@@ -1435,6 +1450,7 @@ export function rangeHightlightselected(ctx, $editor) {
|
|
|
1435
1450
|
var funcName = helpFunctionExe($editor, currSelection, ctx);
|
|
1436
1451
|
ctx.functionHint = funcName === null || funcName === void 0 ? void 0 : funcName.toUpperCase();
|
|
1437
1452
|
ctx.functionCandidates = [];
|
|
1453
|
+
ctx.defaultCandidates = [];
|
|
1438
1454
|
}
|
|
1439
1455
|
}
|
|
1440
1456
|
function functionHTML(txt) {
|
|
@@ -1585,6 +1601,99 @@ function getRangeIndexes($editor) {
|
|
|
1585
1601
|
});
|
|
1586
1602
|
return res;
|
|
1587
1603
|
}
|
|
1604
|
+
export function getLastFormulaRangeIndex($editor) {
|
|
1605
|
+
var spans = Array.from($editor.querySelectorAll("span")).filter(function (span) {
|
|
1606
|
+
var _a;
|
|
1607
|
+
return (_a = span.textContent) === null || _a === void 0 ? void 0 : _a.trim().length;
|
|
1608
|
+
});
|
|
1609
|
+
var lastSpan = spans[spans.length - 1];
|
|
1610
|
+
if (!lastSpan) return null;
|
|
1611
|
+
if (!lastSpan.classList.contains("fortune-formula-functionrange-cell")) {
|
|
1612
|
+
return null;
|
|
1613
|
+
}
|
|
1614
|
+
var indexStr = lastSpan.getAttribute("rangeindex");
|
|
1615
|
+
if (!indexStr) return null;
|
|
1616
|
+
var rangeIndex = parseInt(indexStr, 10);
|
|
1617
|
+
return Number.isNaN(rangeIndex) ? null : rangeIndex;
|
|
1618
|
+
}
|
|
1619
|
+
export function getFormulaRangeIndexAtCaret($editor) {
|
|
1620
|
+
var sel = window.getSelection();
|
|
1621
|
+
if (!sel || sel.rangeCount === 0) return null;
|
|
1622
|
+
var anchorNode = sel.anchorNode;
|
|
1623
|
+
if (!anchorNode) return null;
|
|
1624
|
+
var el = anchorNode.nodeType === Node.ELEMENT_NODE ? anchorNode : anchorNode.parentElement;
|
|
1625
|
+
if (!el) return null;
|
|
1626
|
+
var cell = el.closest(".fortune-formula-functionrange-cell");
|
|
1627
|
+
if (!cell || !$editor.contains(cell)) return null;
|
|
1628
|
+
var ri = cell.getAttribute("rangeindex");
|
|
1629
|
+
if (!ri) return null;
|
|
1630
|
+
var n = parseInt(ri, 10);
|
|
1631
|
+
return Number.isNaN(n) ? null : n;
|
|
1632
|
+
}
|
|
1633
|
+
function hasCommaOrAnotherRefAfterRangeCell(cell) {
|
|
1634
|
+
var _a, _b;
|
|
1635
|
+
var n = cell.nextSibling;
|
|
1636
|
+
while (n) {
|
|
1637
|
+
if (n.nodeType === Node.ELEMENT_NODE) {
|
|
1638
|
+
var e = n;
|
|
1639
|
+
if ((_a = e.classList) === null || _a === void 0 ? void 0 : _a.contains("luckysheet-formula-text-comma")) return true;
|
|
1640
|
+
if ((_b = e.classList) === null || _b === void 0 ? void 0 : _b.contains("fortune-formula-functionrange-cell")) return true;
|
|
1641
|
+
}
|
|
1642
|
+
n = n.nextSibling;
|
|
1643
|
+
}
|
|
1644
|
+
return false;
|
|
1645
|
+
}
|
|
1646
|
+
export function markRangeSelectionDirty(ctx) {
|
|
1647
|
+
ctx.formulaCache.rangeSelectionActive = false;
|
|
1648
|
+
ctx.formulaRangeHighlight = [];
|
|
1649
|
+
ctx.formulaRangeSelect = undefined;
|
|
1650
|
+
ctx.formulaCache.selectingRangeIndex = -1;
|
|
1651
|
+
ctx.formulaCache.func_selectedrange = undefined;
|
|
1652
|
+
ctx.formulaCache.rangestart = false;
|
|
1653
|
+
ctx.formulaCache.rangedrag_column_start = false;
|
|
1654
|
+
ctx.formulaCache.rangedrag_row_start = false;
|
|
1655
|
+
ctx.formulaCache.rangechangeindex = undefined;
|
|
1656
|
+
}
|
|
1657
|
+
export function getFormulaRangeIndexForKeyboardSync($editor) {
|
|
1658
|
+
var atCaret = getFormulaRangeIndexAtCaret($editor);
|
|
1659
|
+
if (atCaret !== null) return atCaret;
|
|
1660
|
+
var lastIdx = getLastFormulaRangeIndex($editor);
|
|
1661
|
+
if (lastIdx === null) return null;
|
|
1662
|
+
var cell = $editor.querySelector("span.fortune-formula-functionrange-cell[rangeindex=\"".concat(lastIdx, "\"]"));
|
|
1663
|
+
if (!cell) return null;
|
|
1664
|
+
var sel = window.getSelection();
|
|
1665
|
+
if (!(sel === null || sel === void 0 ? void 0 : sel.anchorNode)) return lastIdx;
|
|
1666
|
+
var caretRange = document.createRange();
|
|
1667
|
+
try {
|
|
1668
|
+
caretRange.setStart(sel.anchorNode, sel.anchorOffset);
|
|
1669
|
+
caretRange.collapse(true);
|
|
1670
|
+
} catch (_a) {
|
|
1671
|
+
return lastIdx;
|
|
1672
|
+
}
|
|
1673
|
+
var cellRange = document.createRange();
|
|
1674
|
+
try {
|
|
1675
|
+
cellRange.selectNodeContents(cell);
|
|
1676
|
+
} catch (_b) {
|
|
1677
|
+
return lastIdx;
|
|
1678
|
+
}
|
|
1679
|
+
if (caretRange.compareBoundaryPoints(Range.START_TO_START, cellRange) < 0) {
|
|
1680
|
+
return null;
|
|
1681
|
+
}
|
|
1682
|
+
var afterCell = document.createRange();
|
|
1683
|
+
try {
|
|
1684
|
+
afterCell.setStartAfter(cell);
|
|
1685
|
+
afterCell.collapse(true);
|
|
1686
|
+
} catch (_c) {
|
|
1687
|
+
return lastIdx;
|
|
1688
|
+
}
|
|
1689
|
+
if (caretRange.compareBoundaryPoints(Range.START_TO_START, afterCell) >= 0) {
|
|
1690
|
+
if (hasCommaOrAnotherRefAfterRangeCell(cell)) {
|
|
1691
|
+
return null;
|
|
1692
|
+
}
|
|
1693
|
+
return lastIdx;
|
|
1694
|
+
}
|
|
1695
|
+
return lastIdx;
|
|
1696
|
+
}
|
|
1588
1697
|
export function handleFormulaInput(ctx, $copyTo, $editor, kcode, preText, refreshRangeSelect) {
|
|
1589
1698
|
var _a, _b, _c, _d, _e, _f;
|
|
1590
1699
|
if (refreshRangeSelect === void 0) {
|
|
@@ -1592,6 +1701,13 @@ export function handleFormulaInput(ctx, $copyTo, $editor, kcode, preText, refres
|
|
|
1592
1701
|
}
|
|
1593
1702
|
if (!$editor) return;
|
|
1594
1703
|
try {
|
|
1704
|
+
var isBackspaceOrDelete = kcode === 8 || kcode === 46;
|
|
1705
|
+
var isAlphaNumeric = kcode >= 48 && kcode <= 57 || kcode >= 65 && kcode <= 90 || kcode >= 97 && kcode <= 122;
|
|
1706
|
+
if (ctx.formulaCache.rangeSelectionActive === true) {
|
|
1707
|
+
if (isBackspaceOrDelete || isAlphaNumeric) {
|
|
1708
|
+
markRangeSelectionDirty(ctx);
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1595
1711
|
var value1 = void 0;
|
|
1596
1712
|
var value1txt = preText !== null && preText !== void 0 ? preText : $editor.innerText;
|
|
1597
1713
|
var value = $editor.innerText;
|
|
@@ -1822,61 +1938,204 @@ function functionStrChange_range(txt, type, rc, orient, stindex, step) {
|
|
|
1822
1938
|
}
|
|
1823
1939
|
return "";
|
|
1824
1940
|
}
|
|
1941
|
+
function setRangeSetValueToFromCaretPosition(ctx, editor, sel) {
|
|
1942
|
+
if (sel.rangeCount === 0 || !sel.anchorNode) return false;
|
|
1943
|
+
if (!editor.contains(sel.anchorNode)) return false;
|
|
1944
|
+
var range = sel.getRangeAt(0).cloneRange();
|
|
1945
|
+
range.collapse(true);
|
|
1946
|
+
var startContainer = range.startContainer,
|
|
1947
|
+
startOffset = range.startOffset;
|
|
1948
|
+
if (startContainer.nodeType === Node.TEXT_NODE) {
|
|
1949
|
+
if (startOffset === 0) {
|
|
1950
|
+
var textParent = startContainer.parentElement;
|
|
1951
|
+
if (textParent === editor) {
|
|
1952
|
+
var prev = startContainer.previousSibling;
|
|
1953
|
+
if (prev) {
|
|
1954
|
+
ctx.formulaCache.rangeSetValueTo = prev;
|
|
1955
|
+
return true;
|
|
1956
|
+
}
|
|
1957
|
+
return false;
|
|
1958
|
+
}
|
|
1959
|
+
var el = textParent;
|
|
1960
|
+
while (el && el !== editor) {
|
|
1961
|
+
if (el.previousSibling) {
|
|
1962
|
+
ctx.formulaCache.rangeSetValueTo = el.previousSibling;
|
|
1963
|
+
return true;
|
|
1964
|
+
}
|
|
1965
|
+
el = el.parentElement;
|
|
1966
|
+
}
|
|
1967
|
+
return false;
|
|
1968
|
+
}
|
|
1969
|
+
var p = startContainer.parentElement;
|
|
1970
|
+
if (p && editor.contains(p)) {
|
|
1971
|
+
ctx.formulaCache.rangeSetValueTo = p;
|
|
1972
|
+
return true;
|
|
1973
|
+
}
|
|
1974
|
+
return false;
|
|
1975
|
+
}
|
|
1976
|
+
if (startContainer.nodeType === Node.ELEMENT_NODE && startContainer === editor) {
|
|
1977
|
+
if (startOffset > 0) {
|
|
1978
|
+
var prev = startContainer.childNodes[startOffset - 1];
|
|
1979
|
+
if (prev) {
|
|
1980
|
+
ctx.formulaCache.rangeSetValueTo = prev;
|
|
1981
|
+
return true;
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
return false;
|
|
1985
|
+
}
|
|
1986
|
+
if (startContainer.nodeType === Node.ELEMENT_NODE) {
|
|
1987
|
+
if (startOffset > 0) {
|
|
1988
|
+
var prev = startContainer.childNodes[startOffset - 1];
|
|
1989
|
+
if (prev) {
|
|
1990
|
+
ctx.formulaCache.rangeSetValueTo = prev;
|
|
1991
|
+
return true;
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
var el = startContainer;
|
|
1995
|
+
while (el && el !== editor) {
|
|
1996
|
+
if (el.previousSibling) {
|
|
1997
|
+
ctx.formulaCache.rangeSetValueTo = el.previousSibling;
|
|
1998
|
+
return true;
|
|
1999
|
+
}
|
|
2000
|
+
el = el.parentElement;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
return false;
|
|
2004
|
+
}
|
|
1825
2005
|
export function israngeseleciton(ctx, istooltip) {
|
|
1826
|
-
var _a, _b, _c;
|
|
2006
|
+
var _a, _b, _c, _d;
|
|
1827
2007
|
if (istooltip == null) {
|
|
1828
2008
|
istooltip = false;
|
|
1829
2009
|
}
|
|
1830
2010
|
var currSelection = window.getSelection();
|
|
1831
|
-
if (currSelection == null)
|
|
2011
|
+
if (currSelection == null) {
|
|
2012
|
+
return false;
|
|
2013
|
+
}
|
|
1832
2014
|
var anchor = currSelection.anchorNode;
|
|
1833
|
-
if (!
|
|
2015
|
+
if (!anchor) {
|
|
2016
|
+
return false;
|
|
2017
|
+
}
|
|
1834
2018
|
var anchorOffset = currSelection.anchorOffset;
|
|
1835
2019
|
var anchorElement = anchor;
|
|
1836
2020
|
var parentElement = anchor.parentNode;
|
|
2021
|
+
var allowRangeInsertionAtCaret = function allowRangeInsertionAtCaret() {
|
|
2022
|
+
var _a, _b;
|
|
2023
|
+
if (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || ctx.formulaCache.rangeSelectionActive === true) {
|
|
2024
|
+
return true;
|
|
2025
|
+
}
|
|
2026
|
+
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");
|
|
2027
|
+
if (!editor || currSelection.rangeCount === 0) {
|
|
2028
|
+
return true;
|
|
2029
|
+
}
|
|
2030
|
+
var inputText = editor.innerText.trim();
|
|
2031
|
+
if (!inputText.startsWith("=")) {
|
|
2032
|
+
return false;
|
|
2033
|
+
}
|
|
2034
|
+
if (/^=\s*[A-Za-z_][A-Za-z0-9_]*$/.test(inputText)) {
|
|
2035
|
+
return false;
|
|
2036
|
+
}
|
|
2037
|
+
var caretRange = currSelection.getRangeAt(0).cloneRange();
|
|
2038
|
+
var preCaretRange = document.createRange();
|
|
2039
|
+
preCaretRange.selectNodeContents(editor);
|
|
2040
|
+
preCaretRange.setEnd(caretRange.endContainer, caretRange.endOffset);
|
|
2041
|
+
var caretOffset = preCaretRange.toString().length;
|
|
2042
|
+
var textAfter = editor.innerText.slice(caretOffset);
|
|
2043
|
+
var remaining = textAfter.replace(/^\s+/, "");
|
|
2044
|
+
if (remaining.length === 0) {
|
|
2045
|
+
return true;
|
|
2046
|
+
}
|
|
2047
|
+
var first = remaining[0];
|
|
2048
|
+
if (first === "," || first === ")" || first === "&" || first in operatorjson) {
|
|
2049
|
+
return true;
|
|
2050
|
+
}
|
|
2051
|
+
return false;
|
|
2052
|
+
};
|
|
1837
2053
|
if (((_a = anchor === null || anchor === void 0 ? void 0 : anchor.parentNode) === null || _a === void 0 ? void 0 : _a.nodeName.toLowerCase()) === "span" && anchorOffset !== 0) {
|
|
1838
|
-
var txt = _.trim(anchor.textContent);
|
|
2054
|
+
var txt = _.trim((_b = anchor.textContent) !== null && _b !== void 0 ? _b : "");
|
|
1839
2055
|
var lasttxt = "";
|
|
1840
2056
|
if (txt.length === 0 && anchor.parentNode.previousSibling) {
|
|
1841
2057
|
var ahr = anchor.parentNode.previousSibling;
|
|
1842
2058
|
txt = _.trim(ahr.textContent || "");
|
|
1843
|
-
lasttxt = txt.
|
|
1844
|
-
ctx.formulaCache.rangeSetValueTo = anchor.parentNode;
|
|
2059
|
+
lasttxt = txt.slice(-1);
|
|
1845
2060
|
} else {
|
|
1846
|
-
lasttxt = txt.
|
|
1847
|
-
ctx.formulaCache.rangeSetValueTo = anchor.parentNode;
|
|
2061
|
+
lasttxt = anchorOffset > 0 ? txt.charAt(anchorOffset - 1) : "";
|
|
1848
2062
|
}
|
|
1849
2063
|
if (istooltip && (lasttxt === "(" || lasttxt === ",") || !istooltip && (lasttxt === "(" || lasttxt === "," || lasttxt === "=" || lasttxt in operatorjson || lasttxt === "&")) {
|
|
1850
|
-
|
|
2064
|
+
ctx.formulaCache.rangeSetValueTo = anchor.parentNode;
|
|
2065
|
+
return allowRangeInsertionAtCaret();
|
|
1851
2066
|
}
|
|
1852
2067
|
} else if (anchorElement.id === "luckysheet-rich-text-editor" || anchorElement.id === "luckysheet-functionbox-cell") {
|
|
1853
|
-
var
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
var ahr = anchorElement.querySelectorAll("span");
|
|
1857
|
-
txt = _.trim(ahr[ahr.length - 2].innerText);
|
|
1858
|
-
txt = _.trim(ahr[ahr.length - 2].innerText);
|
|
1859
|
-
ctx.formulaCache.rangeSetValueTo = ahr;
|
|
2068
|
+
var editorEl = anchorElement;
|
|
2069
|
+
if (currSelection.rangeCount > 0 && setRangeSetValueToFromCaretPosition(ctx, editorEl, currSelection) && allowRangeInsertionAtCaret()) {
|
|
2070
|
+
return true;
|
|
1860
2071
|
}
|
|
1861
|
-
var
|
|
2072
|
+
var spans = editorEl.querySelectorAll("span");
|
|
2073
|
+
var txt = _.trim((_c = _.last(spans)) === null || _c === void 0 ? void 0 : _c.innerText);
|
|
2074
|
+
var refSpan = _.last(spans);
|
|
2075
|
+
if (txt.length === 0 && spans.length > 1) {
|
|
2076
|
+
txt = _.trim(spans[spans.length - 2].innerText);
|
|
2077
|
+
refSpan = spans[spans.length - 2];
|
|
2078
|
+
}
|
|
2079
|
+
var lasttxt = txt.slice(-1);
|
|
1862
2080
|
if (istooltip && (lasttxt === "(" || lasttxt === ",") || !istooltip && (lasttxt === "(" || lasttxt === "," || lasttxt === "=" || lasttxt in operatorjson || lasttxt === "&")) {
|
|
1863
|
-
|
|
2081
|
+
ctx.formulaCache.rangeSetValueTo = refSpan;
|
|
2082
|
+
return allowRangeInsertionAtCaret();
|
|
1864
2083
|
}
|
|
1865
2084
|
} else if (parentElement.id === "luckysheet-rich-text-editor" || parentElement.id === "luckysheet-functionbox-cell" || anchorOffset === 0) {
|
|
1866
2085
|
if (anchorOffset === 0) {
|
|
1867
2086
|
anchor = anchor.parentNode;
|
|
1868
2087
|
}
|
|
1869
|
-
if (!anchor)
|
|
1870
|
-
|
|
2088
|
+
if (!anchor) {
|
|
2089
|
+
return false;
|
|
2090
|
+
}
|
|
2091
|
+
if (((_d = anchor.previousSibling) === null || _d === void 0 ? void 0 : _d.textContent) == null) {
|
|
2092
|
+
return false;
|
|
2093
|
+
}
|
|
1871
2094
|
if (anchor.previousSibling) {
|
|
1872
2095
|
var txt = _.trim(anchor.previousSibling.textContent);
|
|
1873
|
-
var lasttxt = txt.
|
|
1874
|
-
ctx.formulaCache.rangeSetValueTo = anchor.previousSibling;
|
|
2096
|
+
var lasttxt = txt.slice(-1);
|
|
1875
2097
|
if (istooltip && (lasttxt === "(" || lasttxt === ",") || !istooltip && (lasttxt === "(" || lasttxt === "," || lasttxt === "=" || lasttxt in operatorjson || lasttxt === "&")) {
|
|
1876
|
-
|
|
2098
|
+
ctx.formulaCache.rangeSetValueTo = anchor.previousSibling;
|
|
2099
|
+
return allowRangeInsertionAtCaret();
|
|
1877
2100
|
}
|
|
1878
2101
|
}
|
|
1879
2102
|
}
|
|
2103
|
+
if (!istooltip && (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || ctx.formulaCache.rangeSelectionActive === true)) {
|
|
2104
|
+
var editor = document.getElementById("luckysheet-rich-text-editor") || document.getElementById("luckysheet-functionbox-cell");
|
|
2105
|
+
if (editor && currSelection.rangeCount > 0 && setRangeSetValueToFromCaretPosition(ctx, editor, currSelection) && allowRangeInsertionAtCaret()) {
|
|
2106
|
+
return true;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
return false;
|
|
2110
|
+
}
|
|
2111
|
+
export function isFormulaReferenceInputMode(ctx) {
|
|
2112
|
+
var editor = document.getElementById("luckysheet-rich-text-editor");
|
|
2113
|
+
var inputText = ((editor === null || editor === void 0 ? void 0 : editor.innerText) || "").trim();
|
|
2114
|
+
var hasRangeToken = (editor === null || editor === void 0 ? void 0 : editor.querySelector("span.fortune-formula-functionrange-cell")) != null;
|
|
2115
|
+
if (!!ctx.formulaCache.rangestart || !!ctx.formulaCache.rangedrag_column_start || !!ctx.formulaCache.rangedrag_row_start || hasRangeToken || ctx.formulaCache.rangeSelectionActive === true) {
|
|
2116
|
+
return true;
|
|
2117
|
+
}
|
|
2118
|
+
if (!inputText.startsWith("=")) {
|
|
2119
|
+
return false;
|
|
2120
|
+
}
|
|
2121
|
+
if (/^=\s*[A-Za-z_][A-Za-z0-9_]*$/.test(inputText)) {
|
|
2122
|
+
return false;
|
|
2123
|
+
}
|
|
2124
|
+
return israngeseleciton(ctx);
|
|
2125
|
+
}
|
|
2126
|
+
export function maybeRecoverDirtyRangeSelection(ctx) {
|
|
2127
|
+
if (ctx.formulaCache.rangeSelectionActive !== false) {
|
|
2128
|
+
return false;
|
|
2129
|
+
}
|
|
2130
|
+
var editor = document.getElementById("luckysheet-rich-text-editor");
|
|
2131
|
+
if (!editor) {
|
|
2132
|
+
return false;
|
|
2133
|
+
}
|
|
2134
|
+
var inputText = (editor.innerText || "").trim();
|
|
2135
|
+
if (inputText.startsWith("=") && israngeseleciton(ctx)) {
|
|
2136
|
+
ctx.formulaCache.rangeSelectionActive = null;
|
|
2137
|
+
return true;
|
|
2138
|
+
}
|
|
1880
2139
|
return false;
|
|
1881
2140
|
}
|
|
1882
2141
|
export function functionStrChange(txt, type, rc, orient, stindex, step) {
|
|
@@ -1974,18 +2233,22 @@ export function functionStrChange(txt, type, rc, orient, stindex, step) {
|
|
|
1974
2233
|
return function_str;
|
|
1975
2234
|
}
|
|
1976
2235
|
export function rangeSetValue(ctx, cellInput, selected, fxInput) {
|
|
1977
|
-
var _a, _b, _c, _d, _e;
|
|
2236
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1978
2237
|
var parser = new DOMParser();
|
|
1979
2238
|
var doc = parser.parseFromString("<div>".concat(cellInput.innerHTML, "</div>"), "text/html");
|
|
1980
2239
|
var spans = doc.querySelectorAll("span");
|
|
1981
2240
|
var lastSpan = spans[spans.length - 1];
|
|
1982
|
-
|
|
2241
|
+
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;
|
|
2242
|
+
if (lastSpan && isLetterNumberPattern(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) && !isManagedRangeSpan) {
|
|
1983
2243
|
var htmlR = removeLastSpan(cellInput.innerHTML);
|
|
1984
2244
|
cellInput.innerHTML = "".concat(htmlR);
|
|
2245
|
+
cellInput.focus();
|
|
2246
|
+
var kids = cellInput.childNodes;
|
|
2247
|
+
ctx.formulaCache.rangeSetValueTo = kids.length > 0 ? kids[kids.length - 1] : undefined;
|
|
1985
2248
|
}
|
|
1986
2249
|
var $editor = cellInput;
|
|
1987
2250
|
var $copyTo = fxInput;
|
|
1988
|
-
if (((
|
|
2251
|
+
if (((_c = document.activeElement) === null || _c === void 0 ? void 0 : _c.id) === "luckysheet-functionbox-cell") {
|
|
1989
2252
|
$editor = fxInput;
|
|
1990
2253
|
$copyTo = cellInput;
|
|
1991
2254
|
}
|
|
@@ -2000,20 +2263,23 @@ export function rangeSetValue(ctx, cellInput, selected, fxInput) {
|
|
|
2000
2263
|
} else {
|
|
2001
2264
|
range = getRangetxt(ctx, ctx.currentSheetId, selected, ctx.formulaCache.rangetosheet);
|
|
2002
2265
|
}
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
}
|
|
2266
|
+
var activeRangeFlow = ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || ctx.formulaCache.rangeSelectionActive === true;
|
|
2267
|
+
var spanToReplace = !_.isNil(ctx.formulaCache.rangechangeindex) ? $editor.querySelector("span[rangeindex='".concat(ctx.formulaCache.rangechangeindex, "']")) : null;
|
|
2268
|
+
if (activeRangeFlow && spanToReplace) {
|
|
2269
|
+
spanToReplace.innerHTML = range;
|
|
2270
|
+
setCaretPosition(ctx, spanToReplace, 0, range.length);
|
|
2009
2271
|
} else {
|
|
2010
2272
|
var function_str = "<span class=\"fortune-formula-functionrange-cell\" rangeindex=\"".concat(functionHTMLIndex, "\" dir=\"auto\" style=\"color:").concat(colors[functionHTMLIndex], ";\">").concat(range, "</span>");
|
|
2011
2273
|
var newEle = parseElement(function_str);
|
|
2012
2274
|
var refEle = ctx.formulaCache.rangeSetValueTo;
|
|
2275
|
+
if (refEle && !refEle.parentNode) {
|
|
2276
|
+
israngeseleciton(ctx);
|
|
2277
|
+
refEle = ctx.formulaCache.rangeSetValueTo;
|
|
2278
|
+
}
|
|
2013
2279
|
if (refEle && refEle.parentNode) {
|
|
2014
|
-
var leftPar = (
|
|
2015
|
-
if ((
|
|
2016
|
-
(
|
|
2280
|
+
var leftPar = (_d = document.getElementsByClassName("luckysheet-formula-text-lpar")) === null || _d === void 0 ? void 0 : _d[0];
|
|
2281
|
+
if ((_e = leftPar === null || leftPar === void 0 ? void 0 : leftPar.parentElement) === null || _e === void 0 ? void 0 : _e.classList.contains("luckysheet-formula-text-color")) {
|
|
2282
|
+
(_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);
|
|
2017
2283
|
} else {
|
|
2018
2284
|
refEle.parentNode.insertBefore(newEle, refEle.nextSibling);
|
|
2019
2285
|
}
|
|
@@ -2053,6 +2319,7 @@ function setRangeSelect(container, left, top, height, width) {
|
|
|
2053
2319
|
rangeElement.style.width = "".concat(width, "px");
|
|
2054
2320
|
}
|
|
2055
2321
|
export function rangeDrag(ctx, e, cellInput, scrollLeft, scrollTop, container, fxInput) {
|
|
2322
|
+
ctx.formulaCache.rangeSelectionActive = true;
|
|
2056
2323
|
var func_selectedrange = ctx.formulaCache.func_selectedrange;
|
|
2057
2324
|
if (!func_selectedrange || func_selectedrange.left == null || func_selectedrange.height == null || func_selectedrange.top == null || func_selectedrange.width == null) return;
|
|
2058
2325
|
var rect = container.getBoundingClientRect();
|
|
@@ -2108,6 +2375,20 @@ export function rangeDrag(ctx, e, cellInput, scrollLeft, scrollTop, container, f
|
|
|
2108
2375
|
func_selectedrange.width_move = width;
|
|
2109
2376
|
func_selectedrange.top_move = top;
|
|
2110
2377
|
func_selectedrange.height_move = height;
|
|
2378
|
+
ctx.luckysheet_select_save = [{
|
|
2379
|
+
row: [rowseleted[0], rowseleted[1]],
|
|
2380
|
+
column: [columnseleted[0], columnseleted[1]],
|
|
2381
|
+
row_focus: row_index,
|
|
2382
|
+
column_focus: col_index,
|
|
2383
|
+
left: left,
|
|
2384
|
+
top: top,
|
|
2385
|
+
width: width,
|
|
2386
|
+
height: height,
|
|
2387
|
+
left_move: left,
|
|
2388
|
+
top_move: top,
|
|
2389
|
+
width_move: width,
|
|
2390
|
+
height_move: height
|
|
2391
|
+
}];
|
|
2111
2392
|
rangeSetValue(ctx, cellInput, {
|
|
2112
2393
|
row: rowseleted,
|
|
2113
2394
|
column: columnseleted
|
|
@@ -2116,6 +2397,7 @@ export function rangeDrag(ctx, e, cellInput, scrollLeft, scrollTop, container, f
|
|
|
2116
2397
|
e.preventDefault();
|
|
2117
2398
|
}
|
|
2118
2399
|
export function rangeDragColumn(ctx, e, cellInput, scrollLeft, scrollTop, container, fxInput) {
|
|
2400
|
+
ctx.formulaCache.rangeSelectionActive = true;
|
|
2119
2401
|
var func_selectedrange = ctx.formulaCache.func_selectedrange;
|
|
2120
2402
|
if (!func_selectedrange || func_selectedrange.left == null || func_selectedrange.height == null || func_selectedrange.top == null || func_selectedrange.width == null) return;
|
|
2121
2403
|
var mouse = mousePosition(e.pageX, e.pageY, ctx);
|
|
@@ -2151,6 +2433,20 @@ export function rangeDragColumn(ctx, e, cellInput, scrollLeft, scrollTop, contai
|
|
|
2151
2433
|
func_selectedrange.column = columnseleted;
|
|
2152
2434
|
func_selectedrange.left_move = left;
|
|
2153
2435
|
func_selectedrange.width_move = width;
|
|
2436
|
+
ctx.luckysheet_select_save = [{
|
|
2437
|
+
row: [0, row_index],
|
|
2438
|
+
column: [columnseleted[0], columnseleted[1]],
|
|
2439
|
+
row_focus: 0,
|
|
2440
|
+
column_focus: col_index,
|
|
2441
|
+
left: left,
|
|
2442
|
+
top: row_pre,
|
|
2443
|
+
width: width,
|
|
2444
|
+
height: row - row_pre - 1,
|
|
2445
|
+
left_move: left,
|
|
2446
|
+
top_move: row_pre,
|
|
2447
|
+
width_move: width,
|
|
2448
|
+
height_move: row - row_pre - 1
|
|
2449
|
+
}];
|
|
2154
2450
|
rangeSetValue(ctx, cellInput, {
|
|
2155
2451
|
row: [null, null],
|
|
2156
2452
|
column: columnseleted
|
|
@@ -2158,6 +2454,7 @@ export function rangeDragColumn(ctx, e, cellInput, scrollLeft, scrollTop, contai
|
|
|
2158
2454
|
setRangeSelect(container, left, row_pre, row - row_pre - 1, width);
|
|
2159
2455
|
}
|
|
2160
2456
|
export function rangeDragRow(ctx, e, cellInput, scrollLeft, scrollTop, container, fxInput) {
|
|
2457
|
+
ctx.formulaCache.rangeSelectionActive = true;
|
|
2161
2458
|
var func_selectedrange = ctx.formulaCache.func_selectedrange;
|
|
2162
2459
|
if (!func_selectedrange || func_selectedrange.left == null || func_selectedrange.height == null || func_selectedrange.top == null || func_selectedrange.width == null) return;
|
|
2163
2460
|
var mouse = mousePosition(e.pageX, e.pageY, ctx);
|
|
@@ -2193,6 +2490,20 @@ export function rangeDragRow(ctx, e, cellInput, scrollLeft, scrollTop, container
|
|
|
2193
2490
|
func_selectedrange.row = rowseleted;
|
|
2194
2491
|
func_selectedrange.top_move = top;
|
|
2195
2492
|
func_selectedrange.height_move = height;
|
|
2493
|
+
ctx.luckysheet_select_save = [{
|
|
2494
|
+
row: [rowseleted[0], rowseleted[1]],
|
|
2495
|
+
column: [0, col_index],
|
|
2496
|
+
row_focus: row_index,
|
|
2497
|
+
column_focus: 0,
|
|
2498
|
+
left: col_pre,
|
|
2499
|
+
top: top,
|
|
2500
|
+
width: col - col_pre - 1,
|
|
2501
|
+
height: height,
|
|
2502
|
+
left_move: col_pre,
|
|
2503
|
+
top_move: top,
|
|
2504
|
+
width_move: col - col_pre - 1,
|
|
2505
|
+
height_move: height
|
|
2506
|
+
}];
|
|
2196
2507
|
rangeSetValue(ctx, cellInput, {
|
|
2197
2508
|
row: rowseleted,
|
|
2198
2509
|
column: [null, null]
|