@fileverse-dev/fortune-react 1.3.11-input-ref → 1.3.11-input-ref-1
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 +190 -48
- package/es/components/SheetOverlay/InputBox.js +114 -59
- package/es/components/SheetOverlay/helper.d.ts +2 -0
- package/es/components/SheetOverlay/helper.js +43 -0
- package/es/components/SheetOverlay/index.css +1 -1
- 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 +26 -0
- package/lib/components/ContextMenu/index.js +1 -1
- package/lib/components/FxEditor/index.js +188 -46
- package/lib/components/SheetOverlay/InputBox.js +112 -57
- package/lib/components/SheetOverlay/helper.d.ts +2 -0
- package/lib/components/SheetOverlay/helper.js +45 -0
- package/lib/components/SheetOverlay/index.css +1 -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 +32 -0
- package/package.json +2 -2
|
@@ -129,7 +129,7 @@ import "./index.css";
|
|
|
129
129
|
import Menu from "./Menu";
|
|
130
130
|
import "tippy.js/dist/tippy.css";
|
|
131
131
|
import SVGIcon from "../SVGIcon";
|
|
132
|
-
import { LucideIcon as LocalLucidIcon } from "
|
|
132
|
+
import { LucideIcon as LocalLucidIcon } from "../SheetOverlay/LucideIcon";
|
|
133
133
|
var ContextMenu = function ContextMenu() {
|
|
134
134
|
var showDialog = useDialog().showDialog;
|
|
135
135
|
var containerRef = useRef(null);
|
|
@@ -1,47 +1,73 @@
|
|
|
1
|
-
import { getFlowdata, cancelNormalSelected, getCellValue, updateCell, getInlineStringNoStyle, isInlineStringCell, escapeScriptTag, moveHighlightCell, handleFormulaInput, rangeHightlightselected, valueShowEs, isShowHidenCR, escapeHTMLTag, functionHTMLGenerate, isAllowEdit } from "@fileverse-dev/fortune-core";
|
|
2
|
-
import React, { useContext, useState, useCallback, useEffect, useRef, useMemo } from "react";
|
|
1
|
+
import { getFlowdata, cancelNormalSelected, getCellValue, updateCell, getInlineStringNoStyle, isInlineStringCell, escapeScriptTag, moveHighlightCell, handleFormulaInput, getFormulaRangeIndexAtCaret, isCaretAtValidFormulaRangeInsertionPoint, markRangeSelectionDirty, rangeHightlightselected, getFormulaEditorOwner, setFormulaEditorOwner, valueShowEs, isShowHidenCR, escapeHTMLTag, functionHTMLGenerate, isAllowEdit } from "@fileverse-dev/fortune-core";
|
|
2
|
+
import React, { useContext, useState, useCallback, useEffect, useLayoutEffect, useRef, useMemo } from "react";
|
|
3
3
|
import "./index.css";
|
|
4
4
|
import _ from "lodash";
|
|
5
|
+
import { Tooltip } from "@fileverse/ui";
|
|
5
6
|
import WorkbookContext from "../../context";
|
|
6
7
|
import ContentEditable from "../SheetOverlay/ContentEditable";
|
|
7
8
|
import NameBox from "./NameBox";
|
|
8
|
-
import FormulaSearch from "
|
|
9
|
-
import FormulaHint from "
|
|
9
|
+
import FormulaSearch from "../SheetOverlay/FormulaSearch";
|
|
10
|
+
import FormulaHint from "../SheetOverlay/FormulaHint";
|
|
10
11
|
import usePrevious from "../../hooks/usePrevious";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
12
|
+
import { useFormulaEditorHistory } from "../../hooks/useFormulaEditorHistory";
|
|
13
|
+
import { useRerenderOnFormulaCaret } from "../../hooks/useRerenderOnFormulaCaret";
|
|
14
|
+
import { LucideIcon } from "../SheetOverlay/LucideIcon";
|
|
15
|
+
import { countCommasBeforeCursor, getCursorPosition, getFunctionNameFromFormulaCaretSpans, isLetterNumberPattern, setCursorPosition, buildFormulaSuggestionText, shouldShowFormulaFunctionList } from "../SheetOverlay/helper";
|
|
13
16
|
var FxEditor = function FxEditor() {
|
|
14
|
-
var _a;
|
|
17
|
+
var _a, _b, _c;
|
|
15
18
|
var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
|
|
16
|
-
var
|
|
17
|
-
showSearchHint =
|
|
18
|
-
setShowSearchHint =
|
|
19
|
-
var
|
|
20
|
-
showFormulaHint =
|
|
21
|
-
setShowFormulaHint =
|
|
22
|
-
var
|
|
23
|
-
commaCount =
|
|
24
|
-
setCommaCount =
|
|
25
|
-
var
|
|
26
|
-
context =
|
|
27
|
-
setContext =
|
|
28
|
-
refs =
|
|
19
|
+
var _d = useState(false),
|
|
20
|
+
showSearchHint = _d[0],
|
|
21
|
+
setShowSearchHint = _d[1];
|
|
22
|
+
var _e = useState(!hideFormulaHintLocal),
|
|
23
|
+
showFormulaHint = _e[0],
|
|
24
|
+
setShowFormulaHint = _e[1];
|
|
25
|
+
var _f = useState(0),
|
|
26
|
+
commaCount = _f[0],
|
|
27
|
+
setCommaCount = _f[1];
|
|
28
|
+
var _g = useContext(WorkbookContext),
|
|
29
|
+
context = _g.context,
|
|
30
|
+
setContext = _g.setContext,
|
|
31
|
+
refs = _g.refs;
|
|
29
32
|
var lastKeyDownEventRef = useRef(null);
|
|
33
|
+
var _h = useFormulaEditorHistory(refs.fxInput, refs.cellInput, refs.fxInput, setContext, "fx"),
|
|
34
|
+
formulaHistoryRef = _h.formulaHistoryRef,
|
|
35
|
+
preTextRef = _h.preTextRef,
|
|
36
|
+
resetFormulaHistory = _h.resetFormulaHistory,
|
|
37
|
+
handleFormulaHistoryUndoRedo = _h.handleFormulaHistoryUndoRedo,
|
|
38
|
+
capturePreFormulaState = _h.capturePreFormulaState,
|
|
39
|
+
appendFormulaHistoryFromPrimaryEditor = _h.appendFormulaHistoryFromPrimaryEditor;
|
|
30
40
|
var inputContainerRef = useRef(null);
|
|
31
|
-
var
|
|
32
|
-
isHidenRC =
|
|
33
|
-
setIsHidenRC =
|
|
41
|
+
var _j = useState(false),
|
|
42
|
+
isHidenRC = _j[0],
|
|
43
|
+
setIsHidenRC = _j[1];
|
|
34
44
|
var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
|
|
35
45
|
var prevFirstSelection = usePrevious(firstSelection);
|
|
46
|
+
var prevCellUpdate = usePrevious(context.luckysheetCellUpdate);
|
|
36
47
|
var prevSheetId = usePrevious(context.currentSheetId);
|
|
37
48
|
var recentText = useRef("");
|
|
38
49
|
var handleShowFormulaHint = function handleShowFormulaHint() {
|
|
39
50
|
localStorage.setItem("formulaMore", String(showFormulaHint));
|
|
40
51
|
setShowFormulaHint(!showFormulaHint);
|
|
41
52
|
};
|
|
53
|
+
useEffect(function () {
|
|
54
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
55
|
+
if (event.key === "F10") {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
handleShowFormulaHint();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
61
|
+
return function () {
|
|
62
|
+
return window.removeEventListener("keydown", handleKeyDown);
|
|
63
|
+
};
|
|
64
|
+
}, [showFormulaHint]);
|
|
42
65
|
useEffect(function () {
|
|
43
66
|
var _a;
|
|
44
67
|
setIsHidenRC(isShowHidenCR(context));
|
|
68
|
+
if (context.luckysheetCellUpdate.length > 0) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
45
71
|
if (_.isEqual(prevFirstSelection, firstSelection) && context.currentSheetId === prevSheetId) {
|
|
46
72
|
return;
|
|
47
73
|
}
|
|
@@ -65,7 +91,55 @@ var FxEditor = function FxEditor() {
|
|
|
65
91
|
} else {
|
|
66
92
|
refs.fxInput.current.innerHTML = "";
|
|
67
93
|
}
|
|
68
|
-
}, [context.luckysheetfile, context.currentSheetId, context.luckysheet_select_save]);
|
|
94
|
+
}, [context.luckysheetfile, context.currentSheetId, context.luckysheet_select_save, context.luckysheetCellUpdate.length]);
|
|
95
|
+
useLayoutEffect(function () {
|
|
96
|
+
var _a;
|
|
97
|
+
var fxInput = refs.fxInput.current;
|
|
98
|
+
if (context.luckysheetCellUpdate.length === 0 || !fxInput) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (refs.globalCache.doNotUpdateCell) {
|
|
102
|
+
delete refs.globalCache.doNotUpdateCell;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (_.isEqual(prevCellUpdate, context.luckysheetCellUpdate) && prevSheetId === context.currentSheetId) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
var _b = context.luckysheetCellUpdate,
|
|
109
|
+
rowIndex = _b[0],
|
|
110
|
+
colIndex = _b[1];
|
|
111
|
+
if (_.isNil(rowIndex) || _.isNil(colIndex)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
var flowdata = getFlowdata(context);
|
|
115
|
+
if (!flowdata) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[rowIndex]) === null || _a === void 0 ? void 0 : _a[colIndex];
|
|
119
|
+
var value = "";
|
|
120
|
+
if (cell && !refs.globalCache.overwriteCell) {
|
|
121
|
+
if (isInlineStringCell(cell)) {
|
|
122
|
+
value = getInlineStringNoStyle(rowIndex, colIndex, flowdata);
|
|
123
|
+
} else if (cell.f) {
|
|
124
|
+
value = getCellValue(rowIndex, colIndex, flowdata, "f");
|
|
125
|
+
} else {
|
|
126
|
+
value = valueShowEs(rowIndex, colIndex, flowdata);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
refs.globalCache.overwriteCell = false;
|
|
130
|
+
if (!refs.globalCache.ignoreWriteCell && value) {
|
|
131
|
+
fxInput.innerHTML = escapeHTMLTag(escapeScriptTag(value));
|
|
132
|
+
} else if (!refs.globalCache.ignoreWriteCell) {
|
|
133
|
+
var valueD = getCellValue(rowIndex, colIndex, flowdata, "f");
|
|
134
|
+
fxInput.innerText = valueD;
|
|
135
|
+
}
|
|
136
|
+
refs.globalCache.ignoreWriteCell = false;
|
|
137
|
+
}, [context.luckysheetCellUpdate, context.luckysheetfile, context.currentSheetId, prevCellUpdate, prevSheetId, refs.fxInput, refs.globalCache]);
|
|
138
|
+
useEffect(function () {
|
|
139
|
+
if (_.isEmpty(context.luckysheetCellUpdate)) {
|
|
140
|
+
resetFormulaHistory();
|
|
141
|
+
}
|
|
142
|
+
}, [context.luckysheetCellUpdate, resetFormulaHistory]);
|
|
69
143
|
var onFocus = useCallback(function () {
|
|
70
144
|
var _a, _b;
|
|
71
145
|
if (context.allowEdit === false) {
|
|
@@ -73,6 +147,7 @@ var FxEditor = function FxEditor() {
|
|
|
73
147
|
}
|
|
74
148
|
if (((_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 && !context.luckysheet_cell_selected_move && isAllowEdit(context, context.luckysheet_select_save)) {
|
|
75
149
|
setContext(function (draftCtx) {
|
|
150
|
+
setFormulaEditorOwner(draftCtx, "fx");
|
|
76
151
|
var last = draftCtx.luckysheet_select_save[draftCtx.luckysheet_select_save.length - 1];
|
|
77
152
|
var row_index = last.row_focus;
|
|
78
153
|
var col_index = last.column_focus;
|
|
@@ -80,6 +155,9 @@ var FxEditor = function FxEditor() {
|
|
|
80
155
|
refs.globalCache.doNotFocus = true;
|
|
81
156
|
});
|
|
82
157
|
}
|
|
158
|
+
setContext(function (draftCtx) {
|
|
159
|
+
setFormulaEditorOwner(draftCtx, "fx");
|
|
160
|
+
});
|
|
83
161
|
}, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, refs.globalCache, setContext]);
|
|
84
162
|
var getActiveFormula = useCallback(function () {
|
|
85
163
|
return document.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -98,12 +176,13 @@ var FxEditor = function FxEditor() {
|
|
|
98
176
|
cellEditor.innerHTML = html;
|
|
99
177
|
}
|
|
100
178
|
setCursorPosition(fxEditor, caretOffset);
|
|
179
|
+
setShowSearchHint(shouldShowFormulaFunctionList(fxEditor));
|
|
101
180
|
setContext(function (draftCtx) {
|
|
102
181
|
draftCtx.functionCandidates = [];
|
|
103
182
|
draftCtx.defaultCandidates = [];
|
|
104
|
-
draftCtx.functionHint = formulaName;
|
|
183
|
+
draftCtx.functionHint = (formulaName || "").toUpperCase();
|
|
105
184
|
});
|
|
106
|
-
}, [setContext]);
|
|
185
|
+
}, [refs.fxInput, setContext]);
|
|
107
186
|
var clearSearchItemActiveClass = useCallback(function () {
|
|
108
187
|
var activeFormula = getActiveFormula();
|
|
109
188
|
if (activeFormula) {
|
|
@@ -119,10 +198,11 @@ var FxEditor = function FxEditor() {
|
|
|
119
198
|
return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
|
|
120
199
|
};
|
|
121
200
|
var selectActiveFormulaOnClick = useCallback(function (e) {
|
|
122
|
-
var _a, _b, _c;
|
|
201
|
+
var _a, _b, _c, _d;
|
|
123
202
|
if (e.target.className.includes("sign-fortune")) return;
|
|
124
|
-
|
|
125
|
-
|
|
203
|
+
preTextRef.current = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current.innerText;
|
|
204
|
+
recentText.current = (_b = refs.fxInput) === null || _b === void 0 ? void 0 : _b.current.innerText;
|
|
205
|
+
var formulaName = (_d = (_c = getActiveFormula()) === null || _c === void 0 ? void 0 : _c.querySelector(".luckysheet-formula-search-func")) === null || _d === void 0 ? void 0 : _d.textContent;
|
|
126
206
|
var lastSpanText = getLastInputSpanText();
|
|
127
207
|
if (formulaName && !isLetterNumberPattern(lastSpanText)) {
|
|
128
208
|
insertSelectedFormula(formulaName);
|
|
@@ -131,18 +211,36 @@ var FxEditor = function FxEditor() {
|
|
|
131
211
|
}
|
|
132
212
|
}, [getActiveFormula, insertSelectedFormula]);
|
|
133
213
|
var onKeyDown = useCallback(function (e) {
|
|
134
|
-
var _a;
|
|
214
|
+
var _a, _b, _c;
|
|
135
215
|
if (context.allowEdit === false) {
|
|
136
216
|
return;
|
|
137
217
|
}
|
|
218
|
+
setContext(function (draftCtx) {
|
|
219
|
+
setFormulaEditorOwner(draftCtx, "fx");
|
|
220
|
+
});
|
|
138
221
|
var currentCommaCount = countCommasBeforeCursor((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
|
|
139
222
|
setCommaCount(currentCommaCount);
|
|
140
223
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
141
|
-
|
|
224
|
+
capturePreFormulaState();
|
|
142
225
|
recentText.current = refs.fxInput.current.innerText;
|
|
226
|
+
var key = e.key;
|
|
227
|
+
var currentInputText = ((_c = (_b = refs.fxInput.current) === null || _b === void 0 ? void 0 : _b.innerText) === null || _c === void 0 ? void 0 : _c.trim()) || "";
|
|
143
228
|
if (key === "ArrowLeft" || key === "ArrowRight") {
|
|
144
229
|
e.stopPropagation();
|
|
145
230
|
}
|
|
231
|
+
if ((e.metaKey || e.ctrlKey) && context.luckysheetCellUpdate.length > 0) {
|
|
232
|
+
if (e.code === "KeyZ" || e.code === "KeyY") {
|
|
233
|
+
var shouldUseFormulaHistory = currentInputText.startsWith("=") || formulaHistoryRef.current.active;
|
|
234
|
+
if (shouldUseFormulaHistory) {
|
|
235
|
+
var handledByFormulaHistory = handleFormulaHistoryUndoRedo(e.code === "KeyY" || e.code === "KeyZ" && e.shiftKey);
|
|
236
|
+
if (handledByFormulaHistory) {
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
e.stopPropagation();
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
146
244
|
if ((e.key === "Enter" || e.key === "Tab") && context.luckysheetCellUpdate.length > 0) {
|
|
147
245
|
if (e.altKey || e.metaKey) {
|
|
148
246
|
document.execCommand("insertHTML", false, "\n ");
|
|
@@ -232,7 +330,7 @@ var FxEditor = function FxEditor() {
|
|
|
232
330
|
}
|
|
233
331
|
}
|
|
234
332
|
});
|
|
235
|
-
}, [context.allowEdit, context.luckysheetCellUpdate.length, refs.fxInput, setContext]);
|
|
333
|
+
}, [capturePreFormulaState, context.allowEdit, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, refs.fxInput, setContext]);
|
|
236
334
|
var handleHideShowHint = function handleHideShowHint() {
|
|
237
335
|
var _a, _b, _c, _d;
|
|
238
336
|
var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -256,23 +354,44 @@ var FxEditor = function FxEditor() {
|
|
|
256
354
|
var _a, _b, _c;
|
|
257
355
|
if (context.isFlvReadOnly) return;
|
|
258
356
|
handleHideShowHint();
|
|
259
|
-
|
|
260
|
-
setShowSearchHint(true);
|
|
261
|
-
} else {
|
|
262
|
-
setShowSearchHint(false);
|
|
263
|
-
}
|
|
357
|
+
setShowSearchHint(shouldShowFormulaFunctionList((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) !== null && _b !== void 0 ? _b : null));
|
|
264
358
|
var currentCommaCount = countCommasBeforeCursor((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current);
|
|
265
359
|
setCommaCount(currentCommaCount);
|
|
266
360
|
var e = lastKeyDownEventRef.current;
|
|
267
|
-
if (!e)
|
|
361
|
+
if (!e) {
|
|
362
|
+
var fx = refs.fxInput.current;
|
|
363
|
+
var cell = refs.cellInput.current;
|
|
364
|
+
var isFormula = function isFormula(el) {
|
|
365
|
+
var _a, _b;
|
|
366
|
+
return !!(((_a = el === null || el === void 0 ? void 0 : el.innerText) === null || _a === void 0 ? void 0 : _a.trim().startsWith("=")) || ((_b = el === null || el === void 0 ? void 0 : el.textContent) === null || _b === void 0 ? void 0 : _b.trim().startsWith("=")));
|
|
367
|
+
};
|
|
368
|
+
var sel = window.getSelection();
|
|
369
|
+
var editor_1 = null;
|
|
370
|
+
if (sel === null || sel === void 0 ? void 0 : sel.rangeCount) {
|
|
371
|
+
var node = sel.getRangeAt(0).startContainer;
|
|
372
|
+
if ((fx === null || fx === void 0 ? void 0 : fx.contains(node)) && isFormula(fx)) editor_1 = fx;else if ((cell === null || cell === void 0 ? void 0 : cell.contains(node)) && isFormula(cell)) editor_1 = cell;
|
|
373
|
+
}
|
|
374
|
+
if (!editor_1 && isFormula(fx)) editor_1 = fx;else if (!editor_1 && isFormula(cell)) editor_1 = cell;
|
|
375
|
+
if (editor_1) {
|
|
376
|
+
setContext(function (draftCtx) {
|
|
377
|
+
if (!isAllowEdit(draftCtx, draftCtx.luckysheet_select_save)) return;
|
|
378
|
+
rangeHightlightselected(draftCtx, editor_1);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
268
383
|
var kcode = e.keyCode;
|
|
269
384
|
if (!kcode) return;
|
|
385
|
+
appendFormulaHistoryFromPrimaryEditor(function () {
|
|
386
|
+
return getCursorPosition(refs.fxInput.current);
|
|
387
|
+
});
|
|
270
388
|
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) {
|
|
271
389
|
setContext(function (draftCtx) {
|
|
272
390
|
handleFormulaInput(draftCtx, refs.cellInput.current, refs.fxInput.current, kcode, recentText.current);
|
|
273
391
|
});
|
|
274
392
|
}
|
|
275
|
-
}, [refs.cellInput, refs.fxInput, setContext]);
|
|
393
|
+
}, [appendFormulaHistoryFromPrimaryEditor, context.isFlvReadOnly, refs.cellInput, refs.fxInput, setContext]);
|
|
394
|
+
useRerenderOnFormulaCaret(refs.fxInput, context.luckysheetCellUpdate.length > 0);
|
|
276
395
|
var getFunctionNameFromInput = useCallback(function () {
|
|
277
396
|
var _a, _b, _c, _d;
|
|
278
397
|
var inputText = ((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText) || "";
|
|
@@ -289,8 +408,9 @@ var FxEditor = function FxEditor() {
|
|
|
289
408
|
}
|
|
290
409
|
return null;
|
|
291
410
|
}, []);
|
|
292
|
-
var functionName = context.functionHint
|
|
411
|
+
var functionName = (_c = (_b = getFunctionNameFromFormulaCaretSpans(refs.fxInput.current)) !== null && _b !== void 0 ? _b : context.functionHint) !== null && _c !== void 0 ? _c : getFunctionNameFromInput();
|
|
293
412
|
var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
|
|
413
|
+
var showFxFormulaChrome = context.luckysheetCellUpdate.length > 0 && getFormulaEditorOwner(context) === "fx";
|
|
294
414
|
var allowEdit = useMemo(function () {
|
|
295
415
|
if (context.allowEdit === false) {
|
|
296
416
|
return false;
|
|
@@ -304,9 +424,9 @@ var FxEditor = function FxEditor() {
|
|
|
304
424
|
return true;
|
|
305
425
|
}, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, isHidenRC]);
|
|
306
426
|
var divRef = useRef(null);
|
|
307
|
-
var
|
|
308
|
-
isResizing =
|
|
309
|
-
setIsResizing =
|
|
427
|
+
var _k = useState(false),
|
|
428
|
+
isResizing = _k[0],
|
|
429
|
+
setIsResizing = _k[1];
|
|
310
430
|
var startResize = function startResize(e) {
|
|
311
431
|
e.preventDefault();
|
|
312
432
|
setIsResizing(true);
|
|
@@ -352,8 +472,20 @@ var FxEditor = function FxEditor() {
|
|
|
352
472
|
onMouseUp: function onMouseUp() {
|
|
353
473
|
var _a;
|
|
354
474
|
handleHideShowHint();
|
|
355
|
-
|
|
475
|
+
setContext(function (draftCtx) {
|
|
476
|
+
setFormulaEditorOwner(draftCtx, "fx");
|
|
477
|
+
});
|
|
478
|
+
var editor = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current;
|
|
479
|
+
var currentCommaCount = countCommasBeforeCursor(editor);
|
|
356
480
|
setCommaCount(currentCommaCount);
|
|
481
|
+
setContext(function (draftCtx) {
|
|
482
|
+
if (draftCtx.formulaCache.rangeSelectionActive !== true) return;
|
|
483
|
+
var clickedInsideManagedRange = getFormulaRangeIndexAtCaret(editor) !== null;
|
|
484
|
+
var atValidInsertionPoint = isCaretAtValidFormulaRangeInsertionPoint(editor);
|
|
485
|
+
if (clickedInsideManagedRange || !atValidInsertionPoint) {
|
|
486
|
+
markRangeSelectionDirty(draftCtx);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
357
489
|
},
|
|
358
490
|
innerRef: function innerRef(e) {
|
|
359
491
|
refs.fxInput.current = e;
|
|
@@ -366,7 +498,7 @@ var FxEditor = function FxEditor() {
|
|
|
366
498
|
onChange: onChange,
|
|
367
499
|
tabIndex: 0,
|
|
368
500
|
allowEdit: allowEdit && !context.isFlvReadOnly
|
|
369
|
-
}), showSearchHint && (/*#__PURE__*/React.createElement(FormulaSearch, {
|
|
501
|
+
}), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0 || fn) && showFxFormulaChrome && (/*#__PURE__*/React.createElement(React.Fragment, null, showSearchHint && (/*#__PURE__*/React.createElement(FormulaSearch, {
|
|
370
502
|
from: "fx",
|
|
371
503
|
onMouseMove: function onMouseMove(e) {
|
|
372
504
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
@@ -382,12 +514,22 @@ var FxEditor = function FxEditor() {
|
|
|
382
514
|
}
|
|
383
515
|
})), /*#__PURE__*/React.createElement("div", {
|
|
384
516
|
className: "fx-hint"
|
|
385
|
-
}, showFormulaHint && fn && (/*#__PURE__*/React.createElement(FormulaHint, {
|
|
517
|
+
}, showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/React.createElement(FormulaHint, {
|
|
386
518
|
handleShowFormulaHint: handleShowFormulaHint,
|
|
387
519
|
showFormulaHint: showFormulaHint,
|
|
388
520
|
commaCount: commaCount,
|
|
389
521
|
functionName: functionName
|
|
390
|
-
})), !showFormulaHint && fn && (/*#__PURE__*/React.createElement(
|
|
522
|
+
})), !showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/React.createElement(Tooltip, {
|
|
523
|
+
text: "Turn on formula suggestions (F10)",
|
|
524
|
+
placement: "top",
|
|
525
|
+
defaultOpen: true,
|
|
526
|
+
style: {
|
|
527
|
+
position: "absolute",
|
|
528
|
+
top: "-50px",
|
|
529
|
+
left: "-130px",
|
|
530
|
+
width: "210px"
|
|
531
|
+
}
|
|
532
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
391
533
|
className: "luckysheet-hin absolute show-more-btn",
|
|
392
534
|
onClick: function onClick() {
|
|
393
535
|
handleShowFormulaHint();
|
|
@@ -401,7 +543,7 @@ var FxEditor = function FxEditor() {
|
|
|
401
543
|
margin: "auto",
|
|
402
544
|
marginTop: "1px"
|
|
403
545
|
}
|
|
404
|
-
})))))), /*#__PURE__*/React.createElement("div", {
|
|
546
|
+
}))))))))), /*#__PURE__*/React.createElement("div", {
|
|
405
547
|
className: "resize-handle",
|
|
406
548
|
onMouseDown: startResize,
|
|
407
549
|
style: {
|