@fileverse-dev/fortune-react 1.3.11-input-ref → 1.3.11-input-ref-2
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/components/ContextMenu/index.js +1 -1
- package/es/components/FxEditor/index.js +296 -55
- package/es/components/SheetOverlay/FormulaHint/index.js +46 -25
- package/es/components/SheetOverlay/FormulaSearch/index.d.ts +3 -1
- package/es/components/SheetOverlay/FormulaSearch/index.js +58 -29
- package/es/components/SheetOverlay/InputBox.js +164 -69
- package/es/components/SheetOverlay/helper.d.ts +2 -0
- package/es/components/SheetOverlay/helper.js +43 -0
- package/es/components/SheetOverlay/index.css +4 -4
- package/es/components/SheetOverlay/index.js +9 -2
- package/es/components/Workbook/index.js +2 -2
- package/es/hooks/useFormulaEditorHistory.d.ts +24 -0
- package/es/hooks/useFormulaEditorHistory.js +119 -0
- package/es/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
- package/es/hooks/useRerenderOnFormulaCaret.js +28 -0
- package/lib/components/ContextMenu/index.js +1 -1
- package/lib/components/FxEditor/index.js +294 -53
- package/lib/components/SheetOverlay/FormulaHint/index.js +45 -24
- package/lib/components/SheetOverlay/FormulaSearch/index.d.ts +3 -1
- package/lib/components/SheetOverlay/FormulaSearch/index.js +57 -28
- package/lib/components/SheetOverlay/InputBox.js +162 -67
- package/lib/components/SheetOverlay/helper.d.ts +2 -0
- package/lib/components/SheetOverlay/helper.js +45 -0
- package/lib/components/SheetOverlay/index.css +4 -4
- package/lib/components/SheetOverlay/index.js +8 -1
- package/lib/components/Workbook/index.js +2 -2
- package/lib/hooks/useFormulaEditorHistory.d.ts +24 -0
- package/lib/hooks/useFormulaEditorHistory.js +126 -0
- package/lib/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
- package/lib/hooks/useRerenderOnFormulaCaret.js +34 -0
- package/package.json +2 -2
|
@@ -23,11 +23,21 @@ var __assign = void 0 && (void 0).__assign || function () {
|
|
|
23
23
|
};
|
|
24
24
|
return __assign.apply(this, arguments);
|
|
25
25
|
};
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
};
|
|
34
|
+
var FormulaSearch = function FormulaSearch(_a) {
|
|
35
|
+
var _b, _c, _d;
|
|
36
|
+
var from = _a.from,
|
|
37
|
+
divProps = __rest(_a, ["from"]);
|
|
38
|
+
var _e = (0, _react.useContext)(_context.default),
|
|
39
|
+
context = _e.context,
|
|
40
|
+
isAuthorized = _e.settings.isAuthorized;
|
|
31
41
|
var authedFunction = ["COINGECKO", "ETHERSCAN", "DEFILLAMA", "GNOSIS", "BASE", "EOA", "PNL", "SAFE", "BLOCKSCOUT", "LENS", "FARCASTER", "Ethereum", "SMARTCONTRACT", "DUNESIM"];
|
|
32
42
|
var filteredDefaultCandidates = context.defaultCandidates.filter(function (item) {
|
|
33
43
|
return !authedFunction.includes(item.n);
|
|
@@ -39,39 +49,58 @@ var FormulaSearch = function FormulaSearch(props) {
|
|
|
39
49
|
var finalFunctionCandidates = isAuthorized ? context.functionCandidates : context.functionCandidates.filter(function (item) {
|
|
40
50
|
return item.t !== 20;
|
|
41
51
|
});
|
|
42
|
-
var firstSelection = (
|
|
52
|
+
var firstSelection = (_b = context.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b[0];
|
|
53
|
+
var cellHeightPx = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) != null ? Number(firstSelection.height_move) : 24;
|
|
54
|
+
var belowCellTop = cellHeightPx + 4;
|
|
43
55
|
var hintRef = (0, _react.useRef)(null);
|
|
44
|
-
var
|
|
45
|
-
top =
|
|
46
|
-
setTop =
|
|
47
|
-
var
|
|
48
|
-
var _a
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
var _f = (0, _react.useState)(belowCellTop),
|
|
57
|
+
top = _f[0],
|
|
58
|
+
setTop = _f[1];
|
|
59
|
+
var applyPlacement = (0, _react.useCallback)(function () {
|
|
60
|
+
var _a;
|
|
61
|
+
if ((firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) == null || firstSelection.height_move == null) {
|
|
62
|
+
setTop(belowCellTop);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
var fromFx = from === "fx";
|
|
66
|
+
var cellH = Number(firstSelection.height_move) || cellHeightPx;
|
|
67
|
+
if (fromFx) {
|
|
68
|
+
setTop(25);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
var innerEl = hintRef.current;
|
|
72
|
+
var popupHeight = Math.min((innerEl === null || innerEl === void 0 ? void 0 : innerEl.offsetHeight) || 360, 360);
|
|
73
|
+
var inputBox = document.getElementById("luckysheet-input-box");
|
|
74
|
+
var rect = inputBox === null || inputBox === void 0 ? void 0 : inputBox.getBoundingClientRect();
|
|
75
|
+
if (!rect) {
|
|
76
|
+
setTop(cellH + 4);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
var cellBottomViewport = rect.top + cellH;
|
|
80
|
+
var availableBelow = window.innerHeight - cellBottomViewport - 12;
|
|
81
|
+
var preferBelow = popupHeight <= availableBelow;
|
|
82
|
+
var topV = preferBelow ? cellH + 4 : -(popupHeight + 8);
|
|
83
|
+
var fxHint = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
84
|
+
if (fxHint && fxHint.style.display !== "none") {
|
|
60
85
|
topV = 25;
|
|
61
86
|
}
|
|
62
87
|
setTop(topV);
|
|
63
|
-
};
|
|
64
|
-
(0, _react.
|
|
65
|
-
|
|
66
|
-
|
|
88
|
+
}, [belowCellTop, cellHeightPx, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top, from]);
|
|
89
|
+
(0, _react.useLayoutEffect)(function () {
|
|
90
|
+
applyPlacement();
|
|
91
|
+
var id = requestAnimationFrame(applyPlacement);
|
|
92
|
+
return function () {
|
|
93
|
+
cancelAnimationFrame(id);
|
|
94
|
+
};
|
|
95
|
+
}, [applyPlacement, (_c = context.defaultCandidates) === null || _c === void 0 ? void 0 : _c.length, (_d = context.functionCandidates) === null || _d === void 0 ? void 0 : _d.length, context.functionHint]);
|
|
67
96
|
if (_lodash.default.isEmpty(context.functionCandidates) && _lodash.default.isEmpty(context.defaultCandidates)) return null;
|
|
68
97
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
69
|
-
className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll ".concat(
|
|
98
|
+
className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll ".concat(from === "fx" ? "fx-search" : "cell-search"),
|
|
70
99
|
id: "luckysheet-formula-search-c-p",
|
|
71
100
|
style: {
|
|
72
101
|
top: top
|
|
73
102
|
}
|
|
74
|
-
}, /*#__PURE__*/_react.default.createElement("div", __assign({},
|
|
103
|
+
}, /*#__PURE__*/_react.default.createElement("div", __assign({}, divProps, {
|
|
75
104
|
ref: hintRef,
|
|
76
105
|
id: "luckysheet-formula-search-c",
|
|
77
106
|
className: "luckysheet-formula-search-c"
|
|
@@ -14,6 +14,8 @@ var _ContentEditable = _interopRequireDefault(require("./ContentEditable"));
|
|
|
14
14
|
var _FormulaSearch = _interopRequireDefault(require("./FormulaSearch"));
|
|
15
15
|
var _FormulaHint = _interopRequireDefault(require("./FormulaHint"));
|
|
16
16
|
var _usePrevious = _interopRequireDefault(require("../../hooks/usePrevious"));
|
|
17
|
+
var _useFormulaEditorHistory = require("../../hooks/useFormulaEditorHistory");
|
|
18
|
+
var _useRerenderOnFormulaCaret = require("../../hooks/useRerenderOnFormulaCaret");
|
|
17
19
|
var _helper = require("./helper");
|
|
18
20
|
var _LucideIcon = require("./LucideIcon");
|
|
19
21
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -29,59 +31,68 @@ var __assign = void 0 && (void 0).__assign || function () {
|
|
|
29
31
|
return __assign.apply(this, arguments);
|
|
30
32
|
};
|
|
31
33
|
var InputBox = function InputBox() {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
33
|
-
var
|
|
34
|
-
context =
|
|
35
|
-
setContext =
|
|
36
|
-
refs =
|
|
34
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
35
|
+
var _q = (0, _react.useContext)(_context.default),
|
|
36
|
+
context = _q.context,
|
|
37
|
+
setContext = _q.setContext,
|
|
38
|
+
refs = _q.refs;
|
|
37
39
|
var inputRef = (0, _react.useRef)(null);
|
|
38
40
|
var lastKeyDownEventRef = (0, _react.useRef)(null);
|
|
39
41
|
var prevCellUpdate = (0, _usePrevious.default)(context.luckysheetCellUpdate);
|
|
40
42
|
var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
|
|
41
|
-
var
|
|
42
|
-
isHidenRC =
|
|
43
|
-
setIsHidenRC =
|
|
44
|
-
var
|
|
45
|
-
isInputBoxActive =
|
|
46
|
-
setIsInputBoxActive =
|
|
47
|
-
var
|
|
48
|
-
activeCell =
|
|
49
|
-
setActiveCell =
|
|
50
|
-
var
|
|
51
|
-
activeRefCell =
|
|
52
|
-
setActiveRefCell =
|
|
53
|
-
var
|
|
43
|
+
var _r = (0, _react.useState)(false),
|
|
44
|
+
isHidenRC = _r[0],
|
|
45
|
+
setIsHidenRC = _r[1];
|
|
46
|
+
var _s = (0, _react.useState)(false),
|
|
47
|
+
isInputBoxActive = _s[0],
|
|
48
|
+
setIsInputBoxActive = _s[1];
|
|
49
|
+
var _t = (0, _react.useState)(""),
|
|
50
|
+
activeCell = _t[0],
|
|
51
|
+
setActiveCell = _t[1];
|
|
52
|
+
var _u = (0, _react.useState)(""),
|
|
53
|
+
activeRefCell = _u[0],
|
|
54
|
+
setActiveRefCell = _u[1];
|
|
55
|
+
var _v = (0, _react.useState)({
|
|
54
56
|
left: 0,
|
|
55
57
|
top: 0
|
|
56
58
|
}),
|
|
57
|
-
frozenPosition =
|
|
58
|
-
setFrozenPosition =
|
|
59
|
+
frozenPosition = _v[0],
|
|
60
|
+
setFrozenPosition = _v[1];
|
|
59
61
|
var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
|
|
60
|
-
var
|
|
61
|
-
firstSelectionActiveCell =
|
|
62
|
-
setFirstSelectionActiveCell =
|
|
63
|
-
var
|
|
64
|
-
commaCount =
|
|
65
|
-
setCommaCount =
|
|
62
|
+
var _w = (0, _react.useState)({}),
|
|
63
|
+
firstSelectionActiveCell = _w[0],
|
|
64
|
+
setFirstSelectionActiveCell = _w[1];
|
|
65
|
+
var _x = (0, _react.useState)(0),
|
|
66
|
+
commaCount = _x[0],
|
|
67
|
+
setCommaCount = _x[1];
|
|
68
|
+
var _y = (0, _react.useState)(false),
|
|
69
|
+
cellEditorIsFormula = _y[0],
|
|
70
|
+
setCellEditorIsFormula = _y[1];
|
|
66
71
|
var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
|
|
67
|
-
var
|
|
68
|
-
showFormulaHint =
|
|
69
|
-
setShowFormulaHint =
|
|
70
|
-
var
|
|
71
|
-
showSearchHint =
|
|
72
|
-
setShowSearchHint =
|
|
72
|
+
var _z = (0, _react.useState)(!hideFormulaHintLocal),
|
|
73
|
+
showFormulaHint = _z[0],
|
|
74
|
+
setShowFormulaHint = _z[1];
|
|
75
|
+
var _0 = (0, _react.useState)(false),
|
|
76
|
+
showSearchHint = _0[0],
|
|
77
|
+
setShowSearchHint = _0[1];
|
|
73
78
|
var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
|
|
74
79
|
var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
|
|
75
|
-
var preText = (0, _react.useRef)("");
|
|
76
80
|
var isComposingRef = (0, _react.useRef)(false);
|
|
77
81
|
var formulaAnchorCellRef = (0, _react.useRef)(null);
|
|
78
82
|
var skipNextAnchorSelectionSyncRef = (0, _react.useRef)(false);
|
|
79
83
|
var lastHandledMouseDragSignatureRef = (0, _react.useRef)("");
|
|
84
|
+
var _1 = (0, _useFormulaEditorHistory.useFormulaEditorHistory)(inputRef, refs.cellInput, refs.fxInput, setContext, "cell"),
|
|
85
|
+
formulaHistoryRef = _1.formulaHistoryRef,
|
|
86
|
+
preTextRef = _1.preTextRef,
|
|
87
|
+
resetFormulaHistory = _1.resetFormulaHistory,
|
|
88
|
+
handleFormulaHistoryUndoRedo = _1.handleFormulaHistoryUndoRedo,
|
|
89
|
+
capturePreFormulaState = _1.capturePreFormulaState,
|
|
90
|
+
appendFormulaHistoryFromPrimaryEditor = _1.appendFormulaHistoryFromPrimaryEditor;
|
|
80
91
|
var ZWSP = "\u200B";
|
|
81
92
|
var inputBoxInnerRef = (0, _react.useRef)(null);
|
|
82
|
-
var
|
|
83
|
-
linkSelectionHighlightRects =
|
|
84
|
-
setLinkSelectionHighlightRects =
|
|
93
|
+
var _2 = (0, _react.useState)([]),
|
|
94
|
+
linkSelectionHighlightRects = _2[0],
|
|
95
|
+
setLinkSelectionHighlightRects = _2[1];
|
|
85
96
|
var ensureNotEmpty = function ensureNotEmpty() {
|
|
86
97
|
var el = inputRef.current;
|
|
87
98
|
if (!el) return;
|
|
@@ -104,12 +115,11 @@ var InputBox = function InputBox() {
|
|
|
104
115
|
return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
|
|
105
116
|
};
|
|
106
117
|
var inputBoxStyle = (0, _react.useMemo)(function () {
|
|
107
|
-
var _a;
|
|
108
118
|
if (firstSelectionActiveCell && context.luckysheetCellUpdate.length > 0) {
|
|
109
119
|
var flowdata = (0, _fortuneCore.getFlowdata)(context);
|
|
110
120
|
if (!flowdata) return {};
|
|
111
121
|
var style = (0, _fortuneCore.getStyleByCell)(context, flowdata, firstSelectionActiveCell.row_focus, firstSelectionActiveCell.column_focus);
|
|
112
|
-
if (
|
|
122
|
+
if (cellEditorIsFormula) {
|
|
113
123
|
style = __assign(__assign({}, style), {
|
|
114
124
|
textAlign: "left"
|
|
115
125
|
});
|
|
@@ -117,7 +127,7 @@ var InputBox = function InputBox() {
|
|
|
117
127
|
return style;
|
|
118
128
|
}
|
|
119
129
|
return {};
|
|
120
|
-
}, [context.luckysheetfile, context.currentSheetId, context.luckysheetCellUpdate, (_b = context === null || context === void 0 ? void 0 : context.luckysheetCellUpdate) === null || _b === void 0 ? void 0 : _b.length, firstSelectionActiveCell]);
|
|
130
|
+
}, [context.luckysheetfile, context.currentSheetId, context.luckysheetCellUpdate, (_b = context === null || context === void 0 ? void 0 : context.luckysheetCellUpdate) === null || _b === void 0 ? void 0 : _b.length, firstSelectionActiveCell, cellEditorIsFormula]);
|
|
121
131
|
(0, _react.useLayoutEffect)(function () {
|
|
122
132
|
var _a;
|
|
123
133
|
if (!context.allowEdit) {
|
|
@@ -137,10 +147,23 @@ var InputBox = function InputBox() {
|
|
|
137
147
|
if (_lodash.default.isEqual(prevCellUpdate, context.luckysheetCellUpdate) && prevSheetId === context.currentSheetId) {
|
|
138
148
|
return;
|
|
139
149
|
}
|
|
150
|
+
var _b = context.luckysheetCellUpdate,
|
|
151
|
+
ur = _b[0],
|
|
152
|
+
uc = _b[1];
|
|
153
|
+
var pending_1 = refs.globalCache.pendingTypeOverCell;
|
|
154
|
+
if (pending_1 && pending_1[0] === ur && pending_1[1] === uc) {
|
|
155
|
+
refs.globalCache.overwriteCell = false;
|
|
156
|
+
if (inputRef.current) {
|
|
157
|
+
setCellEditorIsFormula(inputRef.current.innerText.trim().startsWith("="));
|
|
158
|
+
}
|
|
159
|
+
delete refs.globalCache.doNotFocus;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
140
162
|
var flowdata = (0, _fortuneCore.getFlowdata)(context);
|
|
141
163
|
var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index]) === null || _a === void 0 ? void 0 : _a[col_index];
|
|
164
|
+
var overwrite = refs.globalCache.overwriteCell;
|
|
142
165
|
var value_1 = "";
|
|
143
|
-
if (cell && !
|
|
166
|
+
if (cell && !overwrite) {
|
|
144
167
|
if ((0, _fortuneCore.isInlineStringCell)(cell)) {
|
|
145
168
|
value_1 = (0, _fortuneCore.getInlineStringHTML)(row_index, col_index, flowdata);
|
|
146
169
|
} else if (cell.f) {
|
|
@@ -156,14 +179,20 @@ var InputBox = function InputBox() {
|
|
|
156
179
|
}
|
|
157
180
|
}
|
|
158
181
|
refs.globalCache.overwriteCell = false;
|
|
182
|
+
var wroteEditorFromStoredCell = false;
|
|
159
183
|
if (!refs.globalCache.ignoreWriteCell && inputRef.current && value_1) {
|
|
160
184
|
inputRef.current.innerHTML = (0, _fortuneCore.escapeHTMLTag)((0, _fortuneCore.escapeScriptTag)(value_1));
|
|
161
|
-
|
|
185
|
+
wroteEditorFromStoredCell = true;
|
|
186
|
+
} else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1 && !overwrite) {
|
|
162
187
|
var valueD = (0, _fortuneCore.getCellValue)(row_index, col_index, flowdata, "f");
|
|
163
188
|
inputRef.current.innerText = valueD;
|
|
189
|
+
wroteEditorFromStoredCell = true;
|
|
164
190
|
}
|
|
165
191
|
refs.globalCache.ignoreWriteCell = false;
|
|
166
|
-
if (
|
|
192
|
+
if (inputRef.current) {
|
|
193
|
+
setCellEditorIsFormula(inputRef.current.innerText.trim().startsWith("="));
|
|
194
|
+
}
|
|
195
|
+
if (wroteEditorFromStoredCell && !refs.globalCache.doNotFocus) {
|
|
167
196
|
setTimeout(function () {
|
|
168
197
|
(0, _fortuneCore.moveToEnd)(inputRef.current);
|
|
169
198
|
});
|
|
@@ -176,8 +205,15 @@ var InputBox = function InputBox() {
|
|
|
176
205
|
if (inputRef.current) {
|
|
177
206
|
inputRef.current.innerHTML = "";
|
|
178
207
|
}
|
|
208
|
+
delete refs.globalCache.pendingTypeOverCell;
|
|
209
|
+
setCellEditorIsFormula(false);
|
|
210
|
+
resetFormulaHistory();
|
|
179
211
|
}
|
|
180
|
-
}, [context.luckysheetCellUpdate]);
|
|
212
|
+
}, [context.luckysheetCellUpdate, resetFormulaHistory, refs.globalCache]);
|
|
213
|
+
(0, _react.useEffect)(function () {
|
|
214
|
+
if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) return;
|
|
215
|
+
delete refs.globalCache.pendingTypeOverCell;
|
|
216
|
+
}, [context.luckysheetCellUpdate, refs.globalCache]);
|
|
181
217
|
(0, _react.useEffect)(function () {
|
|
182
218
|
var _a;
|
|
183
219
|
if (_lodash.default.isEmpty(context.luckysheetCellUpdate) || !refs.cellInput.current) {
|
|
@@ -249,10 +285,11 @@ var InputBox = function InputBox() {
|
|
|
249
285
|
fxEditor.innerHTML = html;
|
|
250
286
|
}
|
|
251
287
|
(0, _helper.setCursorPosition)(textEditor, caretOffset);
|
|
288
|
+
setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)(textEditor));
|
|
252
289
|
setContext(function (draftCtx) {
|
|
253
290
|
draftCtx.functionCandidates = [];
|
|
254
291
|
draftCtx.defaultCandidates = [];
|
|
255
|
-
draftCtx.functionHint = formulaName;
|
|
292
|
+
draftCtx.functionHint = (formulaName || "").toUpperCase();
|
|
256
293
|
});
|
|
257
294
|
}, [setContext]);
|
|
258
295
|
var clearSearchItemActiveClass = (0, _react.useCallback)(function () {
|
|
@@ -275,7 +312,7 @@ var InputBox = function InputBox() {
|
|
|
275
312
|
var _a, _b;
|
|
276
313
|
if (isComposingRef.current || !inputRef.current) return;
|
|
277
314
|
if (e.target.className.includes("sign-fortune")) return;
|
|
278
|
-
|
|
315
|
+
preTextRef.current = inputRef.current.innerText;
|
|
279
316
|
var formulaName = (_b = (_a = getActiveFormula()) === null || _a === void 0 ? void 0 : _a.querySelector(".luckysheet-formula-search-func")) === null || _b === void 0 ? void 0 : _b.textContent;
|
|
280
317
|
var lastSpanText = getLastInputSpanText();
|
|
281
318
|
if (formulaName && !(0, _helper.isLetterNumberPattern)(lastSpanText)) {
|
|
@@ -296,8 +333,7 @@ var InputBox = function InputBox() {
|
|
|
296
333
|
var _a;
|
|
297
334
|
var currentSelection = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1];
|
|
298
335
|
if (!currentSelection) return;
|
|
299
|
-
|
|
300
|
-
if (isMouseFormulaRangeDrag) {
|
|
336
|
+
if ((0, _fortuneCore.getFormulaEditorOwner)(ctx) === "fx") {
|
|
301
337
|
return;
|
|
302
338
|
}
|
|
303
339
|
(0, _fortuneCore.israngeseleciton)(ctx);
|
|
@@ -374,8 +410,11 @@ var InputBox = function InputBox() {
|
|
|
374
410
|
}, [formulaMouseDragSignature, context.formulaCache.func_selectedrange, refs.cellInput, setContext]);
|
|
375
411
|
var onKeyDown = (0, _react.useCallback)(function (e) {
|
|
376
412
|
var _a, _b;
|
|
413
|
+
setContext(function (draftCtx) {
|
|
414
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "cell");
|
|
415
|
+
});
|
|
377
416
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
378
|
-
|
|
417
|
+
capturePreFormulaState();
|
|
379
418
|
var currentInputText = ((_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) === null || _b === void 0 ? void 0 : _b.trim()) || "";
|
|
380
419
|
if ((e.key === "=" || currentInputText.startsWith("=")) && context.luckysheetCellUpdate.length === 2 && formulaAnchorCellRef.current == null) {
|
|
381
420
|
setContext(function (draftCtx) {
|
|
@@ -398,6 +437,7 @@ var InputBox = function InputBox() {
|
|
|
398
437
|
skipNextAnchorSelectionSyncRef.current = true;
|
|
399
438
|
setTimeout(function () {
|
|
400
439
|
setContext(function (draftCtx) {
|
|
440
|
+
var _a, _b;
|
|
401
441
|
draftCtx.luckysheetCellUpdate = [anchorRow_1, anchorCol_1];
|
|
402
442
|
draftCtx.luckysheet_select_save = [{
|
|
403
443
|
row: [anchorRow_1, anchorRow_1],
|
|
@@ -405,7 +445,6 @@ var InputBox = function InputBox() {
|
|
|
405
445
|
row_focus: anchorRow_1,
|
|
406
446
|
column_focus: anchorCol_1
|
|
407
447
|
}];
|
|
408
|
-
draftCtx.formulaRangeHighlight = [];
|
|
409
448
|
draftCtx.formulaRangeSelect = undefined;
|
|
410
449
|
draftCtx.formulaCache.selectingRangeIndex = -1;
|
|
411
450
|
draftCtx.formulaCache.func_selectedrange = undefined;
|
|
@@ -413,11 +452,23 @@ var InputBox = function InputBox() {
|
|
|
413
452
|
draftCtx.formulaCache.rangestart = false;
|
|
414
453
|
draftCtx.formulaCache.rangedrag_column_start = false;
|
|
415
454
|
draftCtx.formulaCache.rangedrag_row_start = false;
|
|
455
|
+
(0, _fortuneCore.createRangeHightlight)(draftCtx, ((_a = refs.cellInput.current) === null || _a === void 0 ? void 0 : _a.innerHTML) || ((_b = refs.fxInput.current) === null || _b === void 0 ? void 0 : _b.innerHTML) || "");
|
|
416
456
|
(0, _fortuneCore.moveHighlightCell)(draftCtx, "down", 0, "rangeOfSelect");
|
|
417
457
|
});
|
|
418
458
|
}, 0);
|
|
419
459
|
}
|
|
420
|
-
if (e.metaKey && context.luckysheetCellUpdate.length > 0) {
|
|
460
|
+
if ((e.metaKey || e.ctrlKey) && context.luckysheetCellUpdate.length > 0) {
|
|
461
|
+
if (e.code === "KeyZ" || e.code === "KeyY") {
|
|
462
|
+
var shouldUseFormulaHistory = currentInputText.startsWith("=") || formulaHistoryRef.current.active;
|
|
463
|
+
if (shouldUseFormulaHistory) {
|
|
464
|
+
var handledByFormulaHistory = handleFormulaHistoryUndoRedo(e.code === "KeyY" || e.code === "KeyZ" && e.shiftKey);
|
|
465
|
+
if (handledByFormulaHistory) {
|
|
466
|
+
e.preventDefault();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
e.stopPropagation();
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
421
472
|
if (e.code === "KeyB") {
|
|
422
473
|
(0, _fortuneCore.handleBold)(context, inputRef.current);
|
|
423
474
|
stopPropagation(e);
|
|
@@ -439,6 +490,29 @@ var InputBox = function InputBox() {
|
|
|
439
490
|
var allowListNavigation = true;
|
|
440
491
|
var isArrowKey = e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight";
|
|
441
492
|
if (e.key === "Delete" || e.key === "Backspace") {
|
|
493
|
+
var anchor = formulaAnchorCellRef.current;
|
|
494
|
+
if (anchor != null) {
|
|
495
|
+
var anchorRow_2 = anchor[0],
|
|
496
|
+
anchorCol_2 = anchor[1];
|
|
497
|
+
skipNextAnchorSelectionSyncRef.current = true;
|
|
498
|
+
setTimeout(function () {
|
|
499
|
+
setContext(function (draftCtx) {
|
|
500
|
+
draftCtx.luckysheetCellUpdate = [anchorRow_2, anchorCol_2];
|
|
501
|
+
draftCtx.luckysheet_select_save = [{
|
|
502
|
+
row: [anchorRow_2, anchorRow_2],
|
|
503
|
+
column: [anchorCol_2, anchorCol_2],
|
|
504
|
+
row_focus: anchorRow_2,
|
|
505
|
+
column_focus: anchorCol_2
|
|
506
|
+
}];
|
|
507
|
+
(0, _fortuneCore.markRangeSelectionDirty)(draftCtx);
|
|
508
|
+
var el = refs.cellInput.current;
|
|
509
|
+
if (el && el.innerText.trim().startsWith("=")) {
|
|
510
|
+
(0, _fortuneCore.createRangeHightlight)(draftCtx, el.innerHTML);
|
|
511
|
+
(0, _fortuneCore.rangeHightlightselected)(draftCtx, el);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
}, 0);
|
|
515
|
+
}
|
|
442
516
|
if (isComposingRef.current) requestAnimationFrame(ensureNotEmpty);
|
|
443
517
|
if ((0, _helper.getCursorPosition)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
|
|
444
518
|
setTimeout(function () {
|
|
@@ -466,7 +540,7 @@ var InputBox = function InputBox() {
|
|
|
466
540
|
e.preventDefault();
|
|
467
541
|
} else if (e.key === "F4" && context.luckysheetCellUpdate.length > 0) {
|
|
468
542
|
e.preventDefault();
|
|
469
|
-
} else if (e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
|
|
543
|
+
} else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
|
|
470
544
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
471
545
|
var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
|
|
472
546
|
var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -485,7 +559,7 @@ var InputBox = function InputBox() {
|
|
|
485
559
|
}
|
|
486
560
|
}
|
|
487
561
|
e.preventDefault();
|
|
488
|
-
} else if (e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
|
|
562
|
+
} else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
|
|
489
563
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
490
564
|
var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
|
|
491
565
|
var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -503,7 +577,7 @@ var InputBox = function InputBox() {
|
|
|
503
577
|
}
|
|
504
578
|
e.preventDefault();
|
|
505
579
|
}
|
|
506
|
-
}, [clearSearchItemActiveClass, context.luckysheetCellUpdate.length, selectActiveFormula, setContext, firstSelection]);
|
|
580
|
+
}, [capturePreFormulaState, clearSearchItemActiveClass, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, selectActiveFormula, setContext, firstSelection, refs.cellInput]);
|
|
507
581
|
var handleHideShowHint = function handleHideShowHint() {
|
|
508
582
|
var _a, _b, _c, _d;
|
|
509
583
|
var searchElFx = (_a = document.getElementsByClassName("fx-search")) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -524,14 +598,12 @@ var InputBox = function InputBox() {
|
|
|
524
598
|
}
|
|
525
599
|
};
|
|
526
600
|
var onChange = (0, _react.useCallback)(function (__, isBlur) {
|
|
527
|
-
var _a, _b, _c;
|
|
601
|
+
var _a, _b, _c, _d, _e, _f;
|
|
528
602
|
if (context.isFlvReadOnly) return;
|
|
529
603
|
handleHideShowHint();
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
setShowSearchHint(false);
|
|
534
|
-
}
|
|
604
|
+
var editorText = (_c = (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : "";
|
|
605
|
+
setCellEditorIsFormula(editorText.startsWith("="));
|
|
606
|
+
setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)((_d = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) !== null && _d !== void 0 ? _d : null));
|
|
535
607
|
if (!isComposingRef.current) {
|
|
536
608
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
|
|
537
609
|
setCommaCount(currentCommaCount);
|
|
@@ -539,7 +611,7 @@ var InputBox = function InputBox() {
|
|
|
539
611
|
var e = lastKeyDownEventRef.current;
|
|
540
612
|
if (!e) {
|
|
541
613
|
var cellEl_1 = refs.cellInput.current;
|
|
542
|
-
if (cellEl_1 && (((
|
|
614
|
+
if (cellEl_1 && (((_e = cellEl_1.innerText) === null || _e === void 0 ? void 0 : _e.trim().startsWith("=")) || ((_f = cellEl_1.textContent) === null || _f === void 0 ? void 0 : _f.trim().startsWith("=")))) {
|
|
543
615
|
setContext(function (draftCtx) {
|
|
544
616
|
if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) return;
|
|
545
617
|
(0, _fortuneCore.rangeHightlightselected)(draftCtx, cellEl_1);
|
|
@@ -549,16 +621,24 @@ var InputBox = function InputBox() {
|
|
|
549
621
|
}
|
|
550
622
|
var kcode = e.keyCode;
|
|
551
623
|
if (!kcode) return;
|
|
624
|
+
appendFormulaHistoryFromPrimaryEditor(function () {
|
|
625
|
+
return (0, _helper.getCursorPosition)(inputRef.current);
|
|
626
|
+
});
|
|
552
627
|
if (!(kcode >= 112 && kcode <= 123 || kcode <= 46 || kcode === 144 || kcode === 108 || e.ctrlKey || e.altKey || e.shiftKey && (kcode === 37 || kcode === 38 || kcode === 39 || kcode === 40)) || kcode === 8 || kcode === 32 || kcode === 46 || e.ctrlKey && kcode === 86) {
|
|
553
628
|
setContext(function (draftCtx) {
|
|
629
|
+
var _a, _b;
|
|
554
630
|
if ((draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start || (0, _fortuneCore.israngeseleciton)(draftCtx)) && isBlur) return;
|
|
555
631
|
if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) {
|
|
556
632
|
return;
|
|
557
633
|
}
|
|
558
|
-
(0, _fortuneCore.handleFormulaInput)(draftCtx, refs.fxInput.current, refs.cellInput.current, kcode,
|
|
634
|
+
(0, _fortuneCore.handleFormulaInput)(draftCtx, refs.fxInput.current, refs.cellInput.current, kcode, preTextRef.current);
|
|
635
|
+
var cellEl = refs.cellInput.current;
|
|
636
|
+
if (cellEl && (((_a = cellEl.innerText) === null || _a === void 0 ? void 0 : _a.trim().startsWith("=")) || ((_b = cellEl.textContent) === null || _b === void 0 ? void 0 : _b.trim().startsWith("=")))) {
|
|
637
|
+
(0, _fortuneCore.rangeHightlightselected)(draftCtx, cellEl);
|
|
638
|
+
}
|
|
559
639
|
});
|
|
560
640
|
}
|
|
561
|
-
}, [refs.cellInput, refs.fxInput, setContext]);
|
|
641
|
+
}, [refs.cellInput, refs.fxInput, setContext, appendFormulaHistoryFromPrimaryEditor]);
|
|
562
642
|
var onPaste = (0, _react.useCallback)(function (e) {
|
|
563
643
|
if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
|
|
564
644
|
e.preventDefault();
|
|
@@ -689,6 +769,7 @@ var InputBox = function InputBox() {
|
|
|
689
769
|
}
|
|
690
770
|
return activeCell || cell;
|
|
691
771
|
};
|
|
772
|
+
(0, _useRerenderOnFormulaCaret.useRerenderOnFormulaCaret)(inputRef, context.luckysheetCellUpdate.length > 0);
|
|
692
773
|
var getFunctionNameFromInput = (0, _react.useCallback)(function () {
|
|
693
774
|
var _a, _b;
|
|
694
775
|
var inputText = ((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) || "";
|
|
@@ -705,8 +786,9 @@ var InputBox = function InputBox() {
|
|
|
705
786
|
}
|
|
706
787
|
return null;
|
|
707
788
|
}, []);
|
|
708
|
-
var functionName = context.functionHint
|
|
789
|
+
var functionName = (_o = (_m = (0, _helper.getFunctionNameFromFormulaCaretSpans)(inputRef.current)) !== null && _m !== void 0 ? _m : context.functionHint) !== null && _o !== void 0 ? _o : getFunctionNameFromInput();
|
|
709
790
|
var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
|
|
791
|
+
var showCellFormulaChrome = context.luckysheetCellUpdate.length > 0 && (0, _fortuneCore.getFormulaEditorOwner)(context) === "cell";
|
|
710
792
|
var inputBoxBaseSelection = isInputBoxActive && firstSelectionActiveCell ? firstSelectionActiveCell : firstSelection;
|
|
711
793
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
712
794
|
className: "luckysheet-input-box",
|
|
@@ -718,7 +800,7 @@ var InputBox = function InputBox() {
|
|
|
718
800
|
onMouseUp: function onMouseUp(e) {
|
|
719
801
|
return e.stopPropagation();
|
|
720
802
|
}
|
|
721
|
-
}, firstSelection && !((
|
|
803
|
+
}, firstSelection && !((_p = context.rangeDialog) === null || _p === void 0 ? void 0 : _p.show) && (/*#__PURE__*/_react.default.createElement("div", {
|
|
722
804
|
className: "luckysheet-cell-address-indicator",
|
|
723
805
|
style: getAddressIndicatorPosition()
|
|
724
806
|
}, wraperGetCell())), /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -748,10 +830,23 @@ var InputBox = function InputBox() {
|
|
|
748
830
|
},
|
|
749
831
|
onMouseUp: function onMouseUp() {
|
|
750
832
|
handleHideShowHint();
|
|
833
|
+
setContext(function (draftCtx) {
|
|
834
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "cell");
|
|
835
|
+
});
|
|
751
836
|
if (!isComposingRef.current) {
|
|
752
837
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
|
|
753
838
|
setCommaCount(currentCommaCount);
|
|
754
839
|
}
|
|
840
|
+
var editor = inputRef.current;
|
|
841
|
+
if (!editor) return;
|
|
842
|
+
setContext(function (draftCtx) {
|
|
843
|
+
if (draftCtx.formulaCache.rangeSelectionActive !== true) return;
|
|
844
|
+
var clickedInsideManagedRange = (0, _fortuneCore.getFormulaRangeIndexAtCaret)(editor) !== null;
|
|
845
|
+
var atValidInsertionPoint = (0, _fortuneCore.isCaretAtValidFormulaRangeInsertionPoint)(editor);
|
|
846
|
+
if (clickedInsideManagedRange || !atValidInsertionPoint) {
|
|
847
|
+
(0, _fortuneCore.markRangeSelectionDirty)(draftCtx);
|
|
848
|
+
}
|
|
849
|
+
});
|
|
755
850
|
},
|
|
756
851
|
innerRef: function innerRef(e) {
|
|
757
852
|
inputRef.current = e;
|
|
@@ -794,7 +889,7 @@ var InputBox = function InputBox() {
|
|
|
794
889
|
backgroundColor: "rgba(0, 123, 255, 0.25)"
|
|
795
890
|
}
|
|
796
891
|
});
|
|
797
|
-
})))), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0 || fn) && (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaSearch.default, {
|
|
892
|
+
})))), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0 || fn) && showCellFormulaChrome && (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaSearch.default, {
|
|
798
893
|
onMouseMove: function onMouseMove(e) {
|
|
799
894
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
800
895
|
var hoveredItem = e.target.closest(".luckysheet-formula-search-item");
|
|
@@ -809,12 +904,12 @@ var InputBox = function InputBox() {
|
|
|
809
904
|
}
|
|
810
905
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
811
906
|
className: "cell-hint"
|
|
812
|
-
}, showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
907
|
+
}, showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
813
908
|
handleShowFormulaHint: handleShowFormulaHint,
|
|
814
909
|
showFormulaHint: showFormulaHint,
|
|
815
910
|
commaCount: commaCount,
|
|
816
911
|
functionName: functionName
|
|
817
|
-
})), !showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
|
|
912
|
+
})), !showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
|
|
818
913
|
text: "Turn on formula suggestions (F10)",
|
|
819
914
|
placement: "top",
|
|
820
915
|
defaultOpen: true,
|
|
@@ -6,6 +6,8 @@ export declare function buildFormulaSuggestionText(editableDiv: HTMLDivElement,
|
|
|
6
6
|
caretOffset: number;
|
|
7
7
|
};
|
|
8
8
|
export declare function isLetterNumberPattern(str: string): boolean;
|
|
9
|
+
export declare function shouldShowFormulaFunctionList(editor: HTMLDivElement | null): boolean;
|
|
10
|
+
export declare function getFunctionNameFromFormulaCaretSpans(editor: HTMLDivElement | null): string | null;
|
|
9
11
|
export declare function removeLastSpan(htmlString: string): string;
|
|
10
12
|
export declare function numberToColumn(colNumber: number): string;
|
|
11
13
|
export declare function incrementColumn(cell: string): string;
|
|
@@ -8,6 +8,7 @@ exports.countCommasBeforeCursor = countCommasBeforeCursor;
|
|
|
8
8
|
exports.decrementColumn = decrementColumn;
|
|
9
9
|
exports.decrementRow = decrementRow;
|
|
10
10
|
exports.getCursorPosition = getCursorPosition;
|
|
11
|
+
exports.getFunctionNameFromFormulaCaretSpans = getFunctionNameFromFormulaCaretSpans;
|
|
11
12
|
exports.incrementColumn = incrementColumn;
|
|
12
13
|
exports.incrementRow = incrementRow;
|
|
13
14
|
exports.isLetterNumberPattern = isLetterNumberPattern;
|
|
@@ -15,6 +16,7 @@ exports.moveCursorToEnd = moveCursorToEnd;
|
|
|
15
16
|
exports.numberToColumn = numberToColumn;
|
|
16
17
|
exports.removeLastSpan = removeLastSpan;
|
|
17
18
|
exports.setCursorPosition = setCursorPosition;
|
|
19
|
+
exports.shouldShowFormulaFunctionList = shouldShowFormulaFunctionList;
|
|
18
20
|
function moveCursorToEnd(editableDiv) {
|
|
19
21
|
editableDiv.focus();
|
|
20
22
|
var range = document.createRange();
|
|
@@ -91,6 +93,49 @@ function isLetterNumberPattern(str) {
|
|
|
91
93
|
var regex = /^[a-zA-Z]+\d+$/;
|
|
92
94
|
return regex.test(str);
|
|
93
95
|
}
|
|
96
|
+
function shouldShowFormulaFunctionList(editor) {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
if (!editor) return false;
|
|
99
|
+
if (!((_a = editor.innerText) === null || _a === void 0 ? void 0 : _a.includes("="))) return false;
|
|
100
|
+
var parser = new DOMParser();
|
|
101
|
+
var doc = parser.parseFromString("<div>".concat(editor.innerHTML, "</div>"), "text/html");
|
|
102
|
+
var spans = doc.querySelectorAll("span");
|
|
103
|
+
var lastSpan = spans[spans.length - 1];
|
|
104
|
+
var lastText = (_b = lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) !== null && _b !== void 0 ? _b : "";
|
|
105
|
+
return /^=?[A-Za-z]*$/.test(lastText);
|
|
106
|
+
}
|
|
107
|
+
var FORMULA_FUNC_CLASS = "luckysheet-formula-text-func";
|
|
108
|
+
var FORMULA_LPAR_CLASS = "luckysheet-formula-text-lpar";
|
|
109
|
+
function getFunctionNameFromFormulaCaretSpans(editor) {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
if (!editor) return null;
|
|
112
|
+
var sel = window.getSelection();
|
|
113
|
+
if (!(sel === null || sel === void 0 ? void 0 : sel.rangeCount)) return null;
|
|
114
|
+
var range = sel.getRangeAt(0);
|
|
115
|
+
if (!editor.contains(range.startContainer)) return null;
|
|
116
|
+
var n = range.startContainer;
|
|
117
|
+
while (n && n !== editor) {
|
|
118
|
+
if (n.nodeType === Node.ELEMENT_NODE) {
|
|
119
|
+
var elem = n;
|
|
120
|
+
if (elem.classList.contains(FORMULA_FUNC_CLASS)) {
|
|
121
|
+
var next = elem.nextElementSibling;
|
|
122
|
+
if (next === null || next === void 0 ? void 0 : next.classList.contains(FORMULA_LPAR_CLASS)) {
|
|
123
|
+
var name_1 = (_a = elem.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
124
|
+
return name_1 ? name_1.toUpperCase() : null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (elem.classList.contains(FORMULA_LPAR_CLASS)) {
|
|
128
|
+
var prev = elem.previousElementSibling;
|
|
129
|
+
if (prev === null || prev === void 0 ? void 0 : prev.classList.contains(FORMULA_FUNC_CLASS)) {
|
|
130
|
+
var name_2 = (_b = prev.textContent) === null || _b === void 0 ? void 0 : _b.trim();
|
|
131
|
+
return name_2 ? name_2.toUpperCase() : null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
n = n.parentNode;
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
94
139
|
function removeLastSpan(htmlString) {
|
|
95
140
|
var container = document.createElement("div");
|
|
96
141
|
container.innerHTML = htmlString;
|