@fileverse-dev/fortune-react 1.3.10 → 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 +200 -52
- package/es/components/SheetOverlay/InputBox.js +318 -150
- package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +25 -1
- package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +26 -2
- package/es/components/SheetOverlay/helper.d.ts +7 -0
- package/es/components/SheetOverlay/helper.js +95 -0
- package/es/components/SheetOverlay/index.css +1 -1
- package/es/components/Workbook/index.js +141 -11
- 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/es/utils/convertCellsToCrypto.js +17 -0
- package/lib/components/ContextMenu/index.js +1 -1
- package/lib/components/FxEditor/index.js +198 -50
- package/lib/components/SheetOverlay/InputBox.js +316 -148
- package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +25 -1
- package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +26 -2
- package/lib/components/SheetOverlay/helper.d.ts +7 -0
- package/lib/components/SheetOverlay/helper.js +99 -0
- package/lib/components/SheetOverlay/index.css +1 -1
- package/lib/components/Workbook/index.js +142 -12
- 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/lib/utils/convertCellsToCrypto.js +17 -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,24 +164,34 @@ 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");
|
|
95
173
|
}, []);
|
|
96
174
|
var insertSelectedFormula = (0, _react.useCallback)(function (formulaName) {
|
|
97
|
-
var
|
|
98
|
-
|
|
175
|
+
var fxEditor = refs.fxInput.current;
|
|
176
|
+
if (!fxEditor) return;
|
|
99
177
|
var cellEditor = document.getElementById("luckysheet-rich-text-editor");
|
|
178
|
+
var _a = (0, _helper.buildFormulaSuggestionText)(fxEditor, formulaName),
|
|
179
|
+
text = _a.text,
|
|
180
|
+
caretOffset = _a.caretOffset;
|
|
181
|
+
var safeText = (0, _fortuneCore.escapeScriptTag)(text);
|
|
182
|
+
var html = safeText.startsWith("=") ? (0, _fortuneCore.functionHTMLGenerate)(safeText) : (0, _fortuneCore.escapeHTMLTag)(safeText);
|
|
183
|
+
fxEditor.innerHTML = html;
|
|
100
184
|
if (cellEditor) {
|
|
101
|
-
cellEditor.innerHTML =
|
|
185
|
+
cellEditor.innerHTML = html;
|
|
102
186
|
}
|
|
103
|
-
(0, _helper.
|
|
187
|
+
(0, _helper.setCursorPosition)(fxEditor, caretOffset);
|
|
188
|
+
setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)(fxEditor));
|
|
104
189
|
setContext(function (draftCtx) {
|
|
105
190
|
draftCtx.functionCandidates = [];
|
|
106
191
|
draftCtx.defaultCandidates = [];
|
|
107
|
-
draftCtx.functionHint = formulaName;
|
|
192
|
+
draftCtx.functionHint = (formulaName || "").toUpperCase();
|
|
108
193
|
});
|
|
109
|
-
}, [setContext]);
|
|
194
|
+
}, [refs.fxInput, setContext]);
|
|
110
195
|
var clearSearchItemActiveClass = (0, _react.useCallback)(function () {
|
|
111
196
|
var activeFormula = getActiveFormula();
|
|
112
197
|
if (activeFormula) {
|
|
@@ -122,10 +207,11 @@ var FxEditor = function FxEditor() {
|
|
|
122
207
|
return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
|
|
123
208
|
};
|
|
124
209
|
var selectActiveFormulaOnClick = (0, _react.useCallback)(function (e) {
|
|
125
|
-
var _a, _b, _c;
|
|
210
|
+
var _a, _b, _c, _d;
|
|
126
211
|
if (e.target.className.includes("sign-fortune")) return;
|
|
127
|
-
|
|
128
|
-
|
|
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;
|
|
129
215
|
var lastSpanText = getLastInputSpanText();
|
|
130
216
|
if (formulaName && !(0, _helper.isLetterNumberPattern)(lastSpanText)) {
|
|
131
217
|
insertSelectedFormula(formulaName);
|
|
@@ -134,18 +220,36 @@ var FxEditor = function FxEditor() {
|
|
|
134
220
|
}
|
|
135
221
|
}, [getActiveFormula, insertSelectedFormula]);
|
|
136
222
|
var onKeyDown = (0, _react.useCallback)(function (e) {
|
|
137
|
-
var _a;
|
|
223
|
+
var _a, _b, _c;
|
|
138
224
|
if (context.allowEdit === false) {
|
|
139
225
|
return;
|
|
140
226
|
}
|
|
227
|
+
setContext(function (draftCtx) {
|
|
228
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "fx");
|
|
229
|
+
});
|
|
141
230
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
|
|
142
231
|
setCommaCount(currentCommaCount);
|
|
143
232
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
144
|
-
|
|
233
|
+
capturePreFormulaState();
|
|
145
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()) || "";
|
|
146
237
|
if (key === "ArrowLeft" || key === "ArrowRight") {
|
|
147
238
|
e.stopPropagation();
|
|
148
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
|
+
}
|
|
149
253
|
if ((e.key === "Enter" || e.key === "Tab") && context.luckysheetCellUpdate.length > 0) {
|
|
150
254
|
if (e.altKey || e.metaKey) {
|
|
151
255
|
document.execCommand("insertHTML", false, "\n ");
|
|
@@ -235,7 +339,7 @@ var FxEditor = function FxEditor() {
|
|
|
235
339
|
}
|
|
236
340
|
}
|
|
237
341
|
});
|
|
238
|
-
}, [context.allowEdit, context.luckysheetCellUpdate.length, refs.fxInput, setContext]);
|
|
342
|
+
}, [capturePreFormulaState, context.allowEdit, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, refs.fxInput, setContext]);
|
|
239
343
|
var handleHideShowHint = function handleHideShowHint() {
|
|
240
344
|
var _a, _b, _c, _d;
|
|
241
345
|
var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -259,23 +363,44 @@ var FxEditor = function FxEditor() {
|
|
|
259
363
|
var _a, _b, _c;
|
|
260
364
|
if (context.isFlvReadOnly) return;
|
|
261
365
|
handleHideShowHint();
|
|
262
|
-
|
|
263
|
-
setShowSearchHint(true);
|
|
264
|
-
} else {
|
|
265
|
-
setShowSearchHint(false);
|
|
266
|
-
}
|
|
366
|
+
setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) !== null && _b !== void 0 ? _b : null));
|
|
267
367
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current);
|
|
268
368
|
setCommaCount(currentCommaCount);
|
|
269
369
|
var e = lastKeyDownEventRef.current;
|
|
270
|
-
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
|
+
}
|
|
271
392
|
var kcode = e.keyCode;
|
|
272
393
|
if (!kcode) return;
|
|
394
|
+
appendFormulaHistoryFromPrimaryEditor(function () {
|
|
395
|
+
return (0, _helper.getCursorPosition)(refs.fxInput.current);
|
|
396
|
+
});
|
|
273
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) {
|
|
274
398
|
setContext(function (draftCtx) {
|
|
275
399
|
(0, _fortuneCore.handleFormulaInput)(draftCtx, refs.cellInput.current, refs.fxInput.current, kcode, recentText.current);
|
|
276
400
|
});
|
|
277
401
|
}
|
|
278
|
-
}, [refs.cellInput, refs.fxInput, setContext]);
|
|
402
|
+
}, [appendFormulaHistoryFromPrimaryEditor, context.isFlvReadOnly, refs.cellInput, refs.fxInput, setContext]);
|
|
403
|
+
(0, _useRerenderOnFormulaCaret.useRerenderOnFormulaCaret)(refs.fxInput, context.luckysheetCellUpdate.length > 0);
|
|
279
404
|
var getFunctionNameFromInput = (0, _react.useCallback)(function () {
|
|
280
405
|
var _a, _b, _c, _d;
|
|
281
406
|
var inputText = ((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText) || "";
|
|
@@ -292,8 +417,9 @@ var FxEditor = function FxEditor() {
|
|
|
292
417
|
}
|
|
293
418
|
return null;
|
|
294
419
|
}, []);
|
|
295
|
-
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();
|
|
296
421
|
var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
|
|
422
|
+
var showFxFormulaChrome = context.luckysheetCellUpdate.length > 0 && (0, _fortuneCore.getFormulaEditorOwner)(context) === "fx";
|
|
297
423
|
var allowEdit = (0, _react.useMemo)(function () {
|
|
298
424
|
if (context.allowEdit === false) {
|
|
299
425
|
return false;
|
|
@@ -307,9 +433,9 @@ var FxEditor = function FxEditor() {
|
|
|
307
433
|
return true;
|
|
308
434
|
}, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, isHidenRC]);
|
|
309
435
|
var divRef = (0, _react.useRef)(null);
|
|
310
|
-
var
|
|
311
|
-
isResizing =
|
|
312
|
-
setIsResizing =
|
|
436
|
+
var _k = (0, _react.useState)(false),
|
|
437
|
+
isResizing = _k[0],
|
|
438
|
+
setIsResizing = _k[1];
|
|
313
439
|
var startResize = function startResize(e) {
|
|
314
440
|
e.preventDefault();
|
|
315
441
|
setIsResizing(true);
|
|
@@ -355,8 +481,20 @@ var FxEditor = function FxEditor() {
|
|
|
355
481
|
onMouseUp: function onMouseUp() {
|
|
356
482
|
var _a;
|
|
357
483
|
handleHideShowHint();
|
|
358
|
-
|
|
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);
|
|
359
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
|
+
});
|
|
360
498
|
},
|
|
361
499
|
innerRef: function innerRef(e) {
|
|
362
500
|
refs.fxInput.current = e;
|
|
@@ -369,7 +507,7 @@ var FxEditor = function FxEditor() {
|
|
|
369
507
|
onChange: onChange,
|
|
370
508
|
tabIndex: 0,
|
|
371
509
|
allowEdit: allowEdit && !context.isFlvReadOnly
|
|
372
|
-
}), 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, {
|
|
373
511
|
from: "fx",
|
|
374
512
|
onMouseMove: function onMouseMove(e) {
|
|
375
513
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
@@ -385,12 +523,22 @@ var FxEditor = function FxEditor() {
|
|
|
385
523
|
}
|
|
386
524
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
387
525
|
className: "fx-hint"
|
|
388
|
-
}, showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
526
|
+
}, showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
389
527
|
handleShowFormulaHint: handleShowFormulaHint,
|
|
390
528
|
showFormulaHint: showFormulaHint,
|
|
391
529
|
commaCount: commaCount,
|
|
392
530
|
functionName: functionName
|
|
393
|
-
})), !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", {
|
|
394
542
|
className: "luckysheet-hin absolute show-more-btn",
|
|
395
543
|
onClick: function onClick() {
|
|
396
544
|
handleShowFormulaHint();
|
|
@@ -404,7 +552,7 @@ var FxEditor = function FxEditor() {
|
|
|
404
552
|
margin: "auto",
|
|
405
553
|
marginTop: "1px"
|
|
406
554
|
}
|
|
407
|
-
})))))), /*#__PURE__*/_react.default.createElement("div", {
|
|
555
|
+
}))))))))), /*#__PURE__*/_react.default.createElement("div", {
|
|
408
556
|
className: "resize-handle",
|
|
409
557
|
onMouseDown: startResize,
|
|
410
558
|
style: {
|