@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
|
@@ -9,48 +9,74 @@ var _fortuneCore = require("@fileverse-dev/fortune-core");
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
require("./index.css");
|
|
11
11
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
12
|
+
var _ui = require("@fileverse/ui");
|
|
12
13
|
var _context = _interopRequireDefault(require("../../context"));
|
|
13
14
|
var _ContentEditable = _interopRequireDefault(require("../SheetOverlay/ContentEditable"));
|
|
14
15
|
var _NameBox = _interopRequireDefault(require("./NameBox"));
|
|
15
|
-
var _FormulaSearch = _interopRequireDefault(require("
|
|
16
|
-
var _FormulaHint = _interopRequireDefault(require("
|
|
16
|
+
var _FormulaSearch = _interopRequireDefault(require("../SheetOverlay/FormulaSearch"));
|
|
17
|
+
var _FormulaHint = _interopRequireDefault(require("../SheetOverlay/FormulaHint"));
|
|
17
18
|
var _usePrevious = _interopRequireDefault(require("../../hooks/usePrevious"));
|
|
18
|
-
var
|
|
19
|
-
var
|
|
19
|
+
var _useFormulaEditorHistory = require("../../hooks/useFormulaEditorHistory");
|
|
20
|
+
var _useRerenderOnFormulaCaret = require("../../hooks/useRerenderOnFormulaCaret");
|
|
21
|
+
var _LucideIcon = require("../SheetOverlay/LucideIcon");
|
|
22
|
+
var _helper = require("../SheetOverlay/helper");
|
|
20
23
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
24
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
22
25
|
var FxEditor = function FxEditor() {
|
|
23
|
-
var _a;
|
|
26
|
+
var _a, _b, _c;
|
|
24
27
|
var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
|
|
25
|
-
var
|
|
26
|
-
showSearchHint =
|
|
27
|
-
setShowSearchHint =
|
|
28
|
-
var
|
|
29
|
-
showFormulaHint =
|
|
30
|
-
setShowFormulaHint =
|
|
31
|
-
var
|
|
32
|
-
commaCount =
|
|
33
|
-
setCommaCount =
|
|
34
|
-
var
|
|
35
|
-
context =
|
|
36
|
-
setContext =
|
|
37
|
-
refs =
|
|
28
|
+
var _d = (0, _react.useState)(false),
|
|
29
|
+
showSearchHint = _d[0],
|
|
30
|
+
setShowSearchHint = _d[1];
|
|
31
|
+
var _e = (0, _react.useState)(!hideFormulaHintLocal),
|
|
32
|
+
showFormulaHint = _e[0],
|
|
33
|
+
setShowFormulaHint = _e[1];
|
|
34
|
+
var _f = (0, _react.useState)(0),
|
|
35
|
+
commaCount = _f[0],
|
|
36
|
+
setCommaCount = _f[1];
|
|
37
|
+
var _g = (0, _react.useContext)(_context.default),
|
|
38
|
+
context = _g.context,
|
|
39
|
+
setContext = _g.setContext,
|
|
40
|
+
refs = _g.refs;
|
|
38
41
|
var lastKeyDownEventRef = (0, _react.useRef)(null);
|
|
42
|
+
var _h = (0, _useFormulaEditorHistory.useFormulaEditorHistory)(refs.fxInput, refs.cellInput, refs.fxInput, setContext, "fx"),
|
|
43
|
+
formulaHistoryRef = _h.formulaHistoryRef,
|
|
44
|
+
preTextRef = _h.preTextRef,
|
|
45
|
+
resetFormulaHistory = _h.resetFormulaHistory,
|
|
46
|
+
handleFormulaHistoryUndoRedo = _h.handleFormulaHistoryUndoRedo,
|
|
47
|
+
capturePreFormulaState = _h.capturePreFormulaState,
|
|
48
|
+
appendFormulaHistoryFromPrimaryEditor = _h.appendFormulaHistoryFromPrimaryEditor;
|
|
39
49
|
var inputContainerRef = (0, _react.useRef)(null);
|
|
40
|
-
var
|
|
41
|
-
isHidenRC =
|
|
42
|
-
setIsHidenRC =
|
|
50
|
+
var _j = (0, _react.useState)(false),
|
|
51
|
+
isHidenRC = _j[0],
|
|
52
|
+
setIsHidenRC = _j[1];
|
|
43
53
|
var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
|
|
44
54
|
var prevFirstSelection = (0, _usePrevious.default)(firstSelection);
|
|
55
|
+
var prevCellUpdate = (0, _usePrevious.default)(context.luckysheetCellUpdate);
|
|
45
56
|
var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
|
|
46
57
|
var recentText = (0, _react.useRef)("");
|
|
47
58
|
var handleShowFormulaHint = function handleShowFormulaHint() {
|
|
48
59
|
localStorage.setItem("formulaMore", String(showFormulaHint));
|
|
49
60
|
setShowFormulaHint(!showFormulaHint);
|
|
50
61
|
};
|
|
62
|
+
(0, _react.useEffect)(function () {
|
|
63
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
64
|
+
if (event.key === "F10") {
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
handleShowFormulaHint();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
70
|
+
return function () {
|
|
71
|
+
return window.removeEventListener("keydown", handleKeyDown);
|
|
72
|
+
};
|
|
73
|
+
}, [showFormulaHint]);
|
|
51
74
|
(0, _react.useEffect)(function () {
|
|
52
75
|
var _a;
|
|
53
76
|
setIsHidenRC((0, _fortuneCore.isShowHidenCR)(context));
|
|
77
|
+
if (context.luckysheetCellUpdate.length > 0) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
54
80
|
if (_lodash.default.isEqual(prevFirstSelection, firstSelection) && context.currentSheetId === prevSheetId) {
|
|
55
81
|
return;
|
|
56
82
|
}
|
|
@@ -74,7 +100,55 @@ var FxEditor = function FxEditor() {
|
|
|
74
100
|
} else {
|
|
75
101
|
refs.fxInput.current.innerHTML = "";
|
|
76
102
|
}
|
|
77
|
-
}, [context.luckysheetfile, context.currentSheetId, context.luckysheet_select_save]);
|
|
103
|
+
}, [context.luckysheetfile, context.currentSheetId, context.luckysheet_select_save, context.luckysheetCellUpdate.length]);
|
|
104
|
+
(0, _react.useLayoutEffect)(function () {
|
|
105
|
+
var _a;
|
|
106
|
+
var fxInput = refs.fxInput.current;
|
|
107
|
+
if (context.luckysheetCellUpdate.length === 0 || !fxInput) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (refs.globalCache.doNotUpdateCell) {
|
|
111
|
+
delete refs.globalCache.doNotUpdateCell;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (_lodash.default.isEqual(prevCellUpdate, context.luckysheetCellUpdate) && prevSheetId === context.currentSheetId) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
var _b = context.luckysheetCellUpdate,
|
|
118
|
+
rowIndex = _b[0],
|
|
119
|
+
colIndex = _b[1];
|
|
120
|
+
if (_lodash.default.isNil(rowIndex) || _lodash.default.isNil(colIndex)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
var flowdata = (0, _fortuneCore.getFlowdata)(context);
|
|
124
|
+
if (!flowdata) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[rowIndex]) === null || _a === void 0 ? void 0 : _a[colIndex];
|
|
128
|
+
var value = "";
|
|
129
|
+
if (cell && !refs.globalCache.overwriteCell) {
|
|
130
|
+
if ((0, _fortuneCore.isInlineStringCell)(cell)) {
|
|
131
|
+
value = (0, _fortuneCore.getInlineStringNoStyle)(rowIndex, colIndex, flowdata);
|
|
132
|
+
} else if (cell.f) {
|
|
133
|
+
value = (0, _fortuneCore.getCellValue)(rowIndex, colIndex, flowdata, "f");
|
|
134
|
+
} else {
|
|
135
|
+
value = (0, _fortuneCore.valueShowEs)(rowIndex, colIndex, flowdata);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
refs.globalCache.overwriteCell = false;
|
|
139
|
+
if (!refs.globalCache.ignoreWriteCell && value) {
|
|
140
|
+
fxInput.innerHTML = (0, _fortuneCore.escapeHTMLTag)((0, _fortuneCore.escapeScriptTag)(value));
|
|
141
|
+
} else if (!refs.globalCache.ignoreWriteCell) {
|
|
142
|
+
var valueD = (0, _fortuneCore.getCellValue)(rowIndex, colIndex, flowdata, "f");
|
|
143
|
+
fxInput.innerText = valueD;
|
|
144
|
+
}
|
|
145
|
+
refs.globalCache.ignoreWriteCell = false;
|
|
146
|
+
}, [context.luckysheetCellUpdate, context.luckysheetfile, context.currentSheetId, prevCellUpdate, prevSheetId, refs.fxInput, refs.globalCache]);
|
|
147
|
+
(0, _react.useEffect)(function () {
|
|
148
|
+
if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
|
|
149
|
+
resetFormulaHistory();
|
|
150
|
+
}
|
|
151
|
+
}, [context.luckysheetCellUpdate, resetFormulaHistory]);
|
|
78
152
|
var onFocus = (0, _react.useCallback)(function () {
|
|
79
153
|
var _a, _b;
|
|
80
154
|
if (context.allowEdit === false) {
|
|
@@ -82,6 +156,7 @@ var FxEditor = function FxEditor() {
|
|
|
82
156
|
}
|
|
83
157
|
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 && (0, _fortuneCore.isAllowEdit)(context, context.luckysheet_select_save)) {
|
|
84
158
|
setContext(function (draftCtx) {
|
|
159
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "fx");
|
|
85
160
|
var last = draftCtx.luckysheet_select_save[draftCtx.luckysheet_select_save.length - 1];
|
|
86
161
|
var row_index = last.row_focus;
|
|
87
162
|
var col_index = last.column_focus;
|
|
@@ -89,6 +164,9 @@ var FxEditor = function FxEditor() {
|
|
|
89
164
|
refs.globalCache.doNotFocus = true;
|
|
90
165
|
});
|
|
91
166
|
}
|
|
167
|
+
setContext(function (draftCtx) {
|
|
168
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "fx");
|
|
169
|
+
});
|
|
92
170
|
}, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, refs.globalCache, setContext]);
|
|
93
171
|
var getActiveFormula = (0, _react.useCallback)(function () {
|
|
94
172
|
return document.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -107,12 +185,13 @@ var FxEditor = function FxEditor() {
|
|
|
107
185
|
cellEditor.innerHTML = html;
|
|
108
186
|
}
|
|
109
187
|
(0, _helper.setCursorPosition)(fxEditor, caretOffset);
|
|
188
|
+
setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)(fxEditor));
|
|
110
189
|
setContext(function (draftCtx) {
|
|
111
190
|
draftCtx.functionCandidates = [];
|
|
112
191
|
draftCtx.defaultCandidates = [];
|
|
113
|
-
draftCtx.functionHint = formulaName;
|
|
192
|
+
draftCtx.functionHint = (formulaName || "").toUpperCase();
|
|
114
193
|
});
|
|
115
|
-
}, [setContext]);
|
|
194
|
+
}, [refs.fxInput, setContext]);
|
|
116
195
|
var clearSearchItemActiveClass = (0, _react.useCallback)(function () {
|
|
117
196
|
var activeFormula = getActiveFormula();
|
|
118
197
|
if (activeFormula) {
|
|
@@ -128,10 +207,11 @@ var FxEditor = function FxEditor() {
|
|
|
128
207
|
return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
|
|
129
208
|
};
|
|
130
209
|
var selectActiveFormulaOnClick = (0, _react.useCallback)(function (e) {
|
|
131
|
-
var _a, _b, _c;
|
|
210
|
+
var _a, _b, _c, _d;
|
|
132
211
|
if (e.target.className.includes("sign-fortune")) return;
|
|
133
|
-
|
|
134
|
-
|
|
212
|
+
preTextRef.current = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current.innerText;
|
|
213
|
+
recentText.current = (_b = refs.fxInput) === null || _b === void 0 ? void 0 : _b.current.innerText;
|
|
214
|
+
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;
|
|
135
215
|
var lastSpanText = getLastInputSpanText();
|
|
136
216
|
if (formulaName && !(0, _helper.isLetterNumberPattern)(lastSpanText)) {
|
|
137
217
|
insertSelectedFormula(formulaName);
|
|
@@ -140,18 +220,36 @@ var FxEditor = function FxEditor() {
|
|
|
140
220
|
}
|
|
141
221
|
}, [getActiveFormula, insertSelectedFormula]);
|
|
142
222
|
var onKeyDown = (0, _react.useCallback)(function (e) {
|
|
143
|
-
var _a;
|
|
223
|
+
var _a, _b, _c;
|
|
144
224
|
if (context.allowEdit === false) {
|
|
145
225
|
return;
|
|
146
226
|
}
|
|
227
|
+
setContext(function (draftCtx) {
|
|
228
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "fx");
|
|
229
|
+
});
|
|
147
230
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
|
|
148
231
|
setCommaCount(currentCommaCount);
|
|
149
232
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
150
|
-
|
|
233
|
+
capturePreFormulaState();
|
|
151
234
|
recentText.current = refs.fxInput.current.innerText;
|
|
235
|
+
var key = e.key;
|
|
236
|
+
var currentInputText = ((_c = (_b = refs.fxInput.current) === null || _b === void 0 ? void 0 : _b.innerText) === null || _c === void 0 ? void 0 : _c.trim()) || "";
|
|
152
237
|
if (key === "ArrowLeft" || key === "ArrowRight") {
|
|
153
238
|
e.stopPropagation();
|
|
154
239
|
}
|
|
240
|
+
if ((e.metaKey || e.ctrlKey) && context.luckysheetCellUpdate.length > 0) {
|
|
241
|
+
if (e.code === "KeyZ" || e.code === "KeyY") {
|
|
242
|
+
var shouldUseFormulaHistory = currentInputText.startsWith("=") || formulaHistoryRef.current.active;
|
|
243
|
+
if (shouldUseFormulaHistory) {
|
|
244
|
+
var handledByFormulaHistory = handleFormulaHistoryUndoRedo(e.code === "KeyY" || e.code === "KeyZ" && e.shiftKey);
|
|
245
|
+
if (handledByFormulaHistory) {
|
|
246
|
+
e.preventDefault();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
e.stopPropagation();
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
155
253
|
if ((e.key === "Enter" || e.key === "Tab") && context.luckysheetCellUpdate.length > 0) {
|
|
156
254
|
if (e.altKey || e.metaKey) {
|
|
157
255
|
document.execCommand("insertHTML", false, "\n ");
|
|
@@ -241,7 +339,7 @@ var FxEditor = function FxEditor() {
|
|
|
241
339
|
}
|
|
242
340
|
}
|
|
243
341
|
});
|
|
244
|
-
}, [context.allowEdit, context.luckysheetCellUpdate.length, refs.fxInput, setContext]);
|
|
342
|
+
}, [capturePreFormulaState, context.allowEdit, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, refs.fxInput, setContext]);
|
|
245
343
|
var handleHideShowHint = function handleHideShowHint() {
|
|
246
344
|
var _a, _b, _c, _d;
|
|
247
345
|
var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -265,23 +363,44 @@ var FxEditor = function FxEditor() {
|
|
|
265
363
|
var _a, _b, _c;
|
|
266
364
|
if (context.isFlvReadOnly) return;
|
|
267
365
|
handleHideShowHint();
|
|
268
|
-
|
|
269
|
-
setShowSearchHint(true);
|
|
270
|
-
} else {
|
|
271
|
-
setShowSearchHint(false);
|
|
272
|
-
}
|
|
366
|
+
setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) !== null && _b !== void 0 ? _b : null));
|
|
273
367
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current);
|
|
274
368
|
setCommaCount(currentCommaCount);
|
|
275
369
|
var e = lastKeyDownEventRef.current;
|
|
276
|
-
if (!e)
|
|
370
|
+
if (!e) {
|
|
371
|
+
var fx = refs.fxInput.current;
|
|
372
|
+
var cell = refs.cellInput.current;
|
|
373
|
+
var isFormula = function isFormula(el) {
|
|
374
|
+
var _a, _b;
|
|
375
|
+
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("=")));
|
|
376
|
+
};
|
|
377
|
+
var sel = window.getSelection();
|
|
378
|
+
var editor_1 = null;
|
|
379
|
+
if (sel === null || sel === void 0 ? void 0 : sel.rangeCount) {
|
|
380
|
+
var node = sel.getRangeAt(0).startContainer;
|
|
381
|
+
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;
|
|
382
|
+
}
|
|
383
|
+
if (!editor_1 && isFormula(fx)) editor_1 = fx;else if (!editor_1 && isFormula(cell)) editor_1 = cell;
|
|
384
|
+
if (editor_1) {
|
|
385
|
+
setContext(function (draftCtx) {
|
|
386
|
+
if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) return;
|
|
387
|
+
(0, _fortuneCore.rangeHightlightselected)(draftCtx, editor_1);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
277
392
|
var kcode = e.keyCode;
|
|
278
393
|
if (!kcode) return;
|
|
394
|
+
appendFormulaHistoryFromPrimaryEditor(function () {
|
|
395
|
+
return (0, _helper.getCursorPosition)(refs.fxInput.current);
|
|
396
|
+
});
|
|
279
397
|
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) {
|
|
280
398
|
setContext(function (draftCtx) {
|
|
281
399
|
(0, _fortuneCore.handleFormulaInput)(draftCtx, refs.cellInput.current, refs.fxInput.current, kcode, recentText.current);
|
|
282
400
|
});
|
|
283
401
|
}
|
|
284
|
-
}, [refs.cellInput, refs.fxInput, setContext]);
|
|
402
|
+
}, [appendFormulaHistoryFromPrimaryEditor, context.isFlvReadOnly, refs.cellInput, refs.fxInput, setContext]);
|
|
403
|
+
(0, _useRerenderOnFormulaCaret.useRerenderOnFormulaCaret)(refs.fxInput, context.luckysheetCellUpdate.length > 0);
|
|
285
404
|
var getFunctionNameFromInput = (0, _react.useCallback)(function () {
|
|
286
405
|
var _a, _b, _c, _d;
|
|
287
406
|
var inputText = ((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText) || "";
|
|
@@ -298,8 +417,9 @@ var FxEditor = function FxEditor() {
|
|
|
298
417
|
}
|
|
299
418
|
return null;
|
|
300
419
|
}, []);
|
|
301
|
-
var functionName = context.functionHint
|
|
420
|
+
var functionName = (_c = (_b = (0, _helper.getFunctionNameFromFormulaCaretSpans)(refs.fxInput.current)) !== null && _b !== void 0 ? _b : context.functionHint) !== null && _c !== void 0 ? _c : getFunctionNameFromInput();
|
|
302
421
|
var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
|
|
422
|
+
var showFxFormulaChrome = context.luckysheetCellUpdate.length > 0 && (0, _fortuneCore.getFormulaEditorOwner)(context) === "fx";
|
|
303
423
|
var allowEdit = (0, _react.useMemo)(function () {
|
|
304
424
|
if (context.allowEdit === false) {
|
|
305
425
|
return false;
|
|
@@ -313,9 +433,9 @@ var FxEditor = function FxEditor() {
|
|
|
313
433
|
return true;
|
|
314
434
|
}, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, isHidenRC]);
|
|
315
435
|
var divRef = (0, _react.useRef)(null);
|
|
316
|
-
var
|
|
317
|
-
isResizing =
|
|
318
|
-
setIsResizing =
|
|
436
|
+
var _k = (0, _react.useState)(false),
|
|
437
|
+
isResizing = _k[0],
|
|
438
|
+
setIsResizing = _k[1];
|
|
319
439
|
var startResize = function startResize(e) {
|
|
320
440
|
e.preventDefault();
|
|
321
441
|
setIsResizing(true);
|
|
@@ -361,8 +481,20 @@ var FxEditor = function FxEditor() {
|
|
|
361
481
|
onMouseUp: function onMouseUp() {
|
|
362
482
|
var _a;
|
|
363
483
|
handleHideShowHint();
|
|
364
|
-
|
|
484
|
+
setContext(function (draftCtx) {
|
|
485
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "fx");
|
|
486
|
+
});
|
|
487
|
+
var editor = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current;
|
|
488
|
+
var currentCommaCount = (0, _helper.countCommasBeforeCursor)(editor);
|
|
365
489
|
setCommaCount(currentCommaCount);
|
|
490
|
+
setContext(function (draftCtx) {
|
|
491
|
+
if (draftCtx.formulaCache.rangeSelectionActive !== true) return;
|
|
492
|
+
var clickedInsideManagedRange = (0, _fortuneCore.getFormulaRangeIndexAtCaret)(editor) !== null;
|
|
493
|
+
var atValidInsertionPoint = (0, _fortuneCore.isCaretAtValidFormulaRangeInsertionPoint)(editor);
|
|
494
|
+
if (clickedInsideManagedRange || !atValidInsertionPoint) {
|
|
495
|
+
(0, _fortuneCore.markRangeSelectionDirty)(draftCtx);
|
|
496
|
+
}
|
|
497
|
+
});
|
|
366
498
|
},
|
|
367
499
|
innerRef: function innerRef(e) {
|
|
368
500
|
refs.fxInput.current = e;
|
|
@@ -375,7 +507,7 @@ var FxEditor = function FxEditor() {
|
|
|
375
507
|
onChange: onChange,
|
|
376
508
|
tabIndex: 0,
|
|
377
509
|
allowEdit: allowEdit && !context.isFlvReadOnly
|
|
378
|
-
}), showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaSearch.default, {
|
|
510
|
+
}), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0 || fn) && showFxFormulaChrome && (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaSearch.default, {
|
|
379
511
|
from: "fx",
|
|
380
512
|
onMouseMove: function onMouseMove(e) {
|
|
381
513
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
@@ -391,12 +523,22 @@ var FxEditor = function FxEditor() {
|
|
|
391
523
|
}
|
|
392
524
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
393
525
|
className: "fx-hint"
|
|
394
|
-
}, showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
526
|
+
}, showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
395
527
|
handleShowFormulaHint: handleShowFormulaHint,
|
|
396
528
|
showFormulaHint: showFormulaHint,
|
|
397
529
|
commaCount: commaCount,
|
|
398
530
|
functionName: functionName
|
|
399
|
-
})), !showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(
|
|
531
|
+
})), !showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
|
|
532
|
+
text: "Turn on formula suggestions (F10)",
|
|
533
|
+
placement: "top",
|
|
534
|
+
defaultOpen: true,
|
|
535
|
+
style: {
|
|
536
|
+
position: "absolute",
|
|
537
|
+
top: "-50px",
|
|
538
|
+
left: "-130px",
|
|
539
|
+
width: "210px"
|
|
540
|
+
}
|
|
541
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
400
542
|
className: "luckysheet-hin absolute show-more-btn",
|
|
401
543
|
onClick: function onClick() {
|
|
402
544
|
handleShowFormulaHint();
|
|
@@ -410,7 +552,7 @@ var FxEditor = function FxEditor() {
|
|
|
410
552
|
margin: "auto",
|
|
411
553
|
marginTop: "1px"
|
|
412
554
|
}
|
|
413
|
-
})))))), /*#__PURE__*/_react.default.createElement("div", {
|
|
555
|
+
}))))))))), /*#__PURE__*/_react.default.createElement("div", {
|
|
414
556
|
className: "resize-handle",
|
|
415
557
|
onMouseDown: startResize,
|
|
416
558
|
style: {
|