@fileverse-dev/fortune-react 1.3.12-mixed-a → 1.3.13-create-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 +316 -60
- 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 +406 -194
- package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +34 -48
- package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +31 -41
- package/es/components/SheetOverlay/formula-segment-boundary.d.ts +1 -0
- package/es/components/SheetOverlay/formula-segment-boundary.js +4 -0
- package/es/components/SheetOverlay/helper.d.ts +7 -0
- package/es/components/SheetOverlay/helper.js +95 -0
- package/es/components/SheetOverlay/index.css +6 -45
- package/es/components/SheetOverlay/index.js +26 -14
- package/es/components/Workbook/index.js +5 -8
- 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 +314 -58
- 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 +404 -192
- package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +33 -47
- package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +31 -41
- package/lib/components/SheetOverlay/formula-segment-boundary.d.ts +1 -0
- package/lib/components/SheetOverlay/formula-segment-boundary.js +10 -0
- package/lib/components/SheetOverlay/helper.d.ts +7 -0
- package/lib/components/SheetOverlay/helper.js +99 -0
- package/lib/components/SheetOverlay/index.css +6 -45
- package/lib/components/SheetOverlay/index.js +25 -13
- package/lib/components/Workbook/index.js +5 -8
- 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
|
@@ -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,75 @@
|
|
|
1
|
-
import { getFlowdata, cancelNormalSelected, getCellValue, updateCell, getInlineStringNoStyle, isInlineStringCell, escapeScriptTag, moveHighlightCell, handleFormulaInput, rangeHightlightselected, valueShowEs, isShowHidenCR, escapeHTMLTag, 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, createRangeHightlight, valueShowEs, isShowHidenCR, escapeHTMLTag, functionHTMLGenerate, isAllowEdit, suppressFormulaRangeSelectionForInitialEdit } 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";
|
|
16
|
+
import { isFormulaSegmentBoundaryKey } from "../SheetOverlay/formula-segment-boundary";
|
|
13
17
|
var FxEditor = function FxEditor() {
|
|
14
|
-
var _a;
|
|
18
|
+
var _a, _b, _c;
|
|
15
19
|
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 =
|
|
20
|
+
var _d = useState(false),
|
|
21
|
+
showSearchHint = _d[0],
|
|
22
|
+
setShowSearchHint = _d[1];
|
|
23
|
+
var _e = useState(!hideFormulaHintLocal),
|
|
24
|
+
showFormulaHint = _e[0],
|
|
25
|
+
setShowFormulaHint = _e[1];
|
|
26
|
+
var _f = useState(0),
|
|
27
|
+
commaCount = _f[0],
|
|
28
|
+
setCommaCount = _f[1];
|
|
29
|
+
var _g = useContext(WorkbookContext),
|
|
30
|
+
context = _g.context,
|
|
31
|
+
setContext = _g.setContext,
|
|
32
|
+
refs = _g.refs;
|
|
29
33
|
var lastKeyDownEventRef = useRef(null);
|
|
34
|
+
var _h = useFormulaEditorHistory(refs.fxInput, refs.cellInput, refs.fxInput, setContext, "fx"),
|
|
35
|
+
formulaHistoryRef = _h.formulaHistoryRef,
|
|
36
|
+
preTextRef = _h.preTextRef,
|
|
37
|
+
resetFormulaHistory = _h.resetFormulaHistory,
|
|
38
|
+
handleFormulaHistoryUndoRedo = _h.handleFormulaHistoryUndoRedo,
|
|
39
|
+
capturePreFormulaState = _h.capturePreFormulaState,
|
|
40
|
+
appendFormulaHistoryFromPrimaryEditor = _h.appendFormulaHistoryFromPrimaryEditor;
|
|
30
41
|
var inputContainerRef = useRef(null);
|
|
31
|
-
var
|
|
32
|
-
isHidenRC =
|
|
33
|
-
setIsHidenRC =
|
|
42
|
+
var _j = useState(false),
|
|
43
|
+
isHidenRC = _j[0],
|
|
44
|
+
setIsHidenRC = _j[1];
|
|
34
45
|
var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
|
|
35
46
|
var prevFirstSelection = usePrevious(firstSelection);
|
|
47
|
+
var prevCellUpdate = usePrevious(context.luckysheetCellUpdate);
|
|
36
48
|
var prevSheetId = usePrevious(context.currentSheetId);
|
|
37
49
|
var recentText = useRef("");
|
|
50
|
+
var formulaAnchorCellRef = useRef(null);
|
|
38
51
|
var handleShowFormulaHint = function handleShowFormulaHint() {
|
|
39
52
|
localStorage.setItem("formulaMore", String(showFormulaHint));
|
|
40
53
|
setShowFormulaHint(!showFormulaHint);
|
|
41
54
|
};
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
57
|
+
if (event.key === "F10") {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
handleShowFormulaHint();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
63
|
+
return function () {
|
|
64
|
+
return window.removeEventListener("keydown", handleKeyDown);
|
|
65
|
+
};
|
|
66
|
+
}, [showFormulaHint]);
|
|
42
67
|
useEffect(function () {
|
|
43
68
|
var _a;
|
|
44
69
|
setIsHidenRC(isShowHidenCR(context));
|
|
70
|
+
if (context.luckysheetCellUpdate.length > 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
45
73
|
if (_.isEqual(prevFirstSelection, firstSelection) && context.currentSheetId === prevSheetId) {
|
|
46
74
|
return;
|
|
47
75
|
}
|
|
@@ -65,7 +93,74 @@ var FxEditor = function FxEditor() {
|
|
|
65
93
|
} else {
|
|
66
94
|
refs.fxInput.current.innerHTML = "";
|
|
67
95
|
}
|
|
68
|
-
}, [context.luckysheetfile, context.currentSheetId, context.luckysheet_select_save]);
|
|
96
|
+
}, [context.luckysheetfile, context.currentSheetId, context.luckysheet_select_save, context.luckysheetCellUpdate.length]);
|
|
97
|
+
useLayoutEffect(function () {
|
|
98
|
+
var _a;
|
|
99
|
+
var fxInput = refs.fxInput.current;
|
|
100
|
+
if (context.luckysheetCellUpdate.length === 0 || !fxInput) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (refs.globalCache.doNotUpdateCell) {
|
|
104
|
+
delete refs.globalCache.doNotUpdateCell;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (_.isEqual(prevCellUpdate, context.luckysheetCellUpdate) && prevSheetId === context.currentSheetId) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
var _b = context.luckysheetCellUpdate,
|
|
111
|
+
rowIndex = _b[0],
|
|
112
|
+
colIndex = _b[1];
|
|
113
|
+
if (_.isNil(rowIndex) || _.isNil(colIndex)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
var pending = refs.globalCache.pendingTypeOverCell;
|
|
117
|
+
if (pending && pending[0] === rowIndex && pending[1] === colIndex) {
|
|
118
|
+
refs.globalCache.overwriteCell = false;
|
|
119
|
+
refs.globalCache.ignoreWriteCell = false;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
var flowdata = getFlowdata(context);
|
|
123
|
+
if (!flowdata) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[rowIndex]) === null || _a === void 0 ? void 0 : _a[colIndex];
|
|
127
|
+
var value = "";
|
|
128
|
+
var overwrite = refs.globalCache.overwriteCell;
|
|
129
|
+
if (cell && !overwrite) {
|
|
130
|
+
if (isInlineStringCell(cell)) {
|
|
131
|
+
value = getInlineStringNoStyle(rowIndex, colIndex, flowdata);
|
|
132
|
+
} else if (cell.f) {
|
|
133
|
+
value = getCellValue(rowIndex, colIndex, flowdata, "f");
|
|
134
|
+
} else {
|
|
135
|
+
value = valueShowEs(rowIndex, colIndex, flowdata);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
refs.globalCache.overwriteCell = false;
|
|
139
|
+
if (!refs.globalCache.ignoreWriteCell && value) {
|
|
140
|
+
fxInput.innerHTML = escapeHTMLTag(escapeScriptTag(value));
|
|
141
|
+
} else if (!refs.globalCache.ignoreWriteCell && !overwrite) {
|
|
142
|
+
var valueD = 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
|
+
useEffect(function () {
|
|
148
|
+
if (_.isEmpty(context.luckysheetCellUpdate)) {
|
|
149
|
+
delete refs.globalCache.pendingTypeOverCell;
|
|
150
|
+
resetFormulaHistory();
|
|
151
|
+
}
|
|
152
|
+
}, [context.luckysheetCellUpdate, resetFormulaHistory, refs.globalCache]);
|
|
153
|
+
useEffect(function () {
|
|
154
|
+
var _a;
|
|
155
|
+
if (_.isEmpty(context.luckysheetCellUpdate) || !refs.fxInput.current) {
|
|
156
|
+
formulaAnchorCellRef.current = null;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
var inputText = ((_a = refs.fxInput.current.innerText) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
160
|
+
if (!inputText.startsWith("=")) {
|
|
161
|
+
formulaAnchorCellRef.current = null;
|
|
162
|
+
}
|
|
163
|
+
}, [context.luckysheetCellUpdate, refs.fxInput]);
|
|
69
164
|
var onFocus = useCallback(function () {
|
|
70
165
|
var _a, _b;
|
|
71
166
|
if (context.allowEdit === false) {
|
|
@@ -73,31 +168,55 @@ var FxEditor = function FxEditor() {
|
|
|
73
168
|
}
|
|
74
169
|
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
170
|
setContext(function (draftCtx) {
|
|
171
|
+
var _a;
|
|
172
|
+
setFormulaEditorOwner(draftCtx, "fx");
|
|
76
173
|
var last = draftCtx.luckysheet_select_save[draftCtx.luckysheet_select_save.length - 1];
|
|
77
174
|
var row_index = last.row_focus;
|
|
78
175
|
var col_index = last.column_focus;
|
|
79
|
-
|
|
80
|
-
|
|
176
|
+
if (!_.isNil(row_index) && !_.isNil(col_index)) {
|
|
177
|
+
var flowdata = getFlowdata(draftCtx);
|
|
178
|
+
var cellAt = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index]) === null || _a === void 0 ? void 0 : _a[col_index];
|
|
179
|
+
if ((cellAt === null || cellAt === void 0 ? void 0 : cellAt.f) != null && String(cellAt.f).trim() !== "") {
|
|
180
|
+
suppressFormulaRangeSelectionForInitialEdit(draftCtx);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
var currentUpdate = draftCtx.luckysheetCellUpdate || [];
|
|
184
|
+
var alreadyEditingSameCell = currentUpdate.length === 2 && currentUpdate[0] === row_index && currentUpdate[1] === col_index;
|
|
185
|
+
if (!alreadyEditingSameCell) {
|
|
186
|
+
refs.globalCache.doNotUpdateCell = true;
|
|
187
|
+
draftCtx.luckysheetCellUpdate = [row_index, col_index];
|
|
188
|
+
refs.globalCache.doNotFocus = true;
|
|
189
|
+
}
|
|
81
190
|
});
|
|
82
191
|
}
|
|
192
|
+
setContext(function (draftCtx) {
|
|
193
|
+
setFormulaEditorOwner(draftCtx, "fx");
|
|
194
|
+
});
|
|
83
195
|
}, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, refs.globalCache, setContext]);
|
|
84
196
|
var getActiveFormula = useCallback(function () {
|
|
85
197
|
return document.querySelector(".luckysheet-formula-search-item-active");
|
|
86
198
|
}, []);
|
|
87
199
|
var insertSelectedFormula = useCallback(function (formulaName) {
|
|
88
|
-
var
|
|
89
|
-
|
|
200
|
+
var fxEditor = refs.fxInput.current;
|
|
201
|
+
if (!fxEditor) return;
|
|
90
202
|
var cellEditor = document.getElementById("luckysheet-rich-text-editor");
|
|
203
|
+
var _a = buildFormulaSuggestionText(fxEditor, formulaName),
|
|
204
|
+
text = _a.text,
|
|
205
|
+
caretOffset = _a.caretOffset;
|
|
206
|
+
var safeText = escapeScriptTag(text);
|
|
207
|
+
var html = safeText.startsWith("=") ? functionHTMLGenerate(safeText) : escapeHTMLTag(safeText);
|
|
208
|
+
fxEditor.innerHTML = html;
|
|
91
209
|
if (cellEditor) {
|
|
92
|
-
cellEditor.innerHTML =
|
|
210
|
+
cellEditor.innerHTML = html;
|
|
93
211
|
}
|
|
94
|
-
|
|
212
|
+
setCursorPosition(fxEditor, caretOffset);
|
|
213
|
+
setShowSearchHint(shouldShowFormulaFunctionList(fxEditor));
|
|
95
214
|
setContext(function (draftCtx) {
|
|
96
215
|
draftCtx.functionCandidates = [];
|
|
97
216
|
draftCtx.defaultCandidates = [];
|
|
98
|
-
draftCtx.functionHint = formulaName;
|
|
217
|
+
draftCtx.functionHint = (formulaName || "").toUpperCase();
|
|
99
218
|
});
|
|
100
|
-
}, [setContext]);
|
|
219
|
+
}, [refs.fxInput, setContext]);
|
|
101
220
|
var clearSearchItemActiveClass = useCallback(function () {
|
|
102
221
|
var activeFormula = getActiveFormula();
|
|
103
222
|
if (activeFormula) {
|
|
@@ -113,10 +232,11 @@ var FxEditor = function FxEditor() {
|
|
|
113
232
|
return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
|
|
114
233
|
};
|
|
115
234
|
var selectActiveFormulaOnClick = useCallback(function (e) {
|
|
116
|
-
var _a, _b, _c;
|
|
235
|
+
var _a, _b, _c, _d;
|
|
117
236
|
if (e.target.className.includes("sign-fortune")) return;
|
|
118
|
-
|
|
119
|
-
|
|
237
|
+
preTextRef.current = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current.innerText;
|
|
238
|
+
recentText.current = (_b = refs.fxInput) === null || _b === void 0 ? void 0 : _b.current.innerText;
|
|
239
|
+
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;
|
|
120
240
|
var lastSpanText = getLastInputSpanText();
|
|
121
241
|
if (formulaName && !isLetterNumberPattern(lastSpanText)) {
|
|
122
242
|
insertSelectedFormula(formulaName);
|
|
@@ -125,18 +245,103 @@ var FxEditor = function FxEditor() {
|
|
|
125
245
|
}
|
|
126
246
|
}, [getActiveFormula, insertSelectedFormula]);
|
|
127
247
|
var onKeyDown = useCallback(function (e) {
|
|
128
|
-
var _a;
|
|
248
|
+
var _a, _b, _c, _d;
|
|
249
|
+
if (e.key === "Delete" || e.key === "Backspace") {
|
|
250
|
+
var anchor = formulaAnchorCellRef.current;
|
|
251
|
+
if (anchor != null) {
|
|
252
|
+
var anchorRow_1 = anchor[0],
|
|
253
|
+
anchorCol_1 = anchor[1];
|
|
254
|
+
setTimeout(function () {
|
|
255
|
+
setContext(function (draftCtx) {
|
|
256
|
+
draftCtx.luckysheetCellUpdate = [anchorRow_1, anchorCol_1];
|
|
257
|
+
draftCtx.luckysheet_select_save = [{
|
|
258
|
+
row: [anchorRow_1, anchorRow_1],
|
|
259
|
+
column: [anchorCol_1, anchorCol_1],
|
|
260
|
+
row_focus: anchorRow_1,
|
|
261
|
+
column_focus: anchorCol_1
|
|
262
|
+
}];
|
|
263
|
+
markRangeSelectionDirty(draftCtx);
|
|
264
|
+
var el = refs.fxInput.current;
|
|
265
|
+
if (el && el.innerText.trim().startsWith("=")) {
|
|
266
|
+
createRangeHightlight(draftCtx, el.innerHTML);
|
|
267
|
+
rangeHightlightselected(draftCtx, el);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}, 0);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
129
273
|
if (context.allowEdit === false) {
|
|
130
274
|
return;
|
|
131
275
|
}
|
|
276
|
+
setContext(function (draftCtx) {
|
|
277
|
+
setFormulaEditorOwner(draftCtx, "fx");
|
|
278
|
+
});
|
|
132
279
|
var currentCommaCount = countCommasBeforeCursor((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
|
|
133
280
|
setCommaCount(currentCommaCount);
|
|
134
281
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
135
|
-
|
|
282
|
+
capturePreFormulaState();
|
|
136
283
|
recentText.current = refs.fxInput.current.innerText;
|
|
137
|
-
|
|
284
|
+
var key = e.key;
|
|
285
|
+
var currentInputText = ((_c = (_b = refs.fxInput.current) === null || _b === void 0 ? void 0 : _b.innerText) === null || _c === void 0 ? void 0 : _c.trim()) || "";
|
|
286
|
+
if ((key === "=" || currentInputText.startsWith("=")) && context.luckysheetCellUpdate.length === 2 && formulaAnchorCellRef.current == null) {
|
|
287
|
+
setContext(function (draftCtx) {
|
|
288
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
289
|
+
});
|
|
290
|
+
formulaAnchorCellRef.current = [context.luckysheetCellUpdate[0], context.luckysheetCellUpdate[1]];
|
|
291
|
+
}
|
|
292
|
+
if (key === "(" && currentInputText.startsWith("=")) {
|
|
293
|
+
setContext(function (draftCtx) {
|
|
294
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
if (isFormulaSegmentBoundaryKey(key) && context.luckysheetCellUpdate.length > 0 && currentInputText.startsWith("=") && formulaAnchorCellRef.current) {
|
|
298
|
+
setContext(function (draftCtx) {
|
|
299
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
300
|
+
});
|
|
301
|
+
var _e = formulaAnchorCellRef.current,
|
|
302
|
+
anchorRow_2 = _e[0],
|
|
303
|
+
anchorCol_2 = _e[1];
|
|
304
|
+
setTimeout(function () {
|
|
305
|
+
setContext(function (draftCtx) {
|
|
306
|
+
var _a, _b;
|
|
307
|
+
draftCtx.luckysheetCellUpdate = [anchorRow_2, anchorCol_2];
|
|
308
|
+
draftCtx.luckysheet_select_save = [{
|
|
309
|
+
row: [anchorRow_2, anchorRow_2],
|
|
310
|
+
column: [anchorCol_2, anchorCol_2],
|
|
311
|
+
row_focus: anchorRow_2,
|
|
312
|
+
column_focus: anchorCol_2
|
|
313
|
+
}];
|
|
314
|
+
draftCtx.formulaRangeSelect = undefined;
|
|
315
|
+
draftCtx.formulaCache.selectingRangeIndex = -1;
|
|
316
|
+
draftCtx.formulaCache.func_selectedrange = undefined;
|
|
317
|
+
draftCtx.formulaCache.rangechangeindex = undefined;
|
|
318
|
+
draftCtx.formulaCache.rangestart = false;
|
|
319
|
+
draftCtx.formulaCache.rangedrag_column_start = false;
|
|
320
|
+
draftCtx.formulaCache.rangedrag_row_start = false;
|
|
321
|
+
createRangeHightlight(draftCtx, ((_a = refs.fxInput.current) === null || _a === void 0 ? void 0 : _a.innerHTML) || ((_b = refs.cellInput.current) === null || _b === void 0 ? void 0 : _b.innerHTML) || "");
|
|
322
|
+
moveHighlightCell(draftCtx, "down", 0, "rangeOfSelect");
|
|
323
|
+
});
|
|
324
|
+
}, 0);
|
|
325
|
+
}
|
|
326
|
+
var isArrowKey = key === "ArrowUp" || key === "ArrowDown" || key === "ArrowLeft" || key === "ArrowRight";
|
|
327
|
+
var isDirectPlainTypeEdit = context.luckysheetCellUpdate.length > 0 && ((_d = refs.globalCache) === null || _d === void 0 ? void 0 : _d.enteredEditByTyping) === true && !currentInputText.startsWith("=");
|
|
328
|
+
var sheetArrowShortcut = isArrowKey && (e.metaKey || e.ctrlKey || e.shiftKey);
|
|
329
|
+
if ((key === "ArrowLeft" || key === "ArrowRight") && !(isDirectPlainTypeEdit && sheetArrowShortcut)) {
|
|
138
330
|
e.stopPropagation();
|
|
139
331
|
}
|
|
332
|
+
if ((e.metaKey || e.ctrlKey) && context.luckysheetCellUpdate.length > 0) {
|
|
333
|
+
if (e.code === "KeyZ" || e.code === "KeyY") {
|
|
334
|
+
var shouldUseFormulaHistory = currentInputText.startsWith("=") || formulaHistoryRef.current.active;
|
|
335
|
+
if (shouldUseFormulaHistory) {
|
|
336
|
+
var handledByFormulaHistory = handleFormulaHistoryUndoRedo(e.code === "KeyY" || e.code === "KeyZ" && e.shiftKey);
|
|
337
|
+
if (handledByFormulaHistory) {
|
|
338
|
+
e.preventDefault();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
e.stopPropagation();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
140
345
|
if ((e.key === "Enter" || e.key === "Tab") && context.luckysheetCellUpdate.length > 0) {
|
|
141
346
|
if (e.altKey || e.metaKey) {
|
|
142
347
|
document.execCommand("insertHTML", false, "\n ");
|
|
@@ -148,7 +353,7 @@ var FxEditor = function FxEditor() {
|
|
|
148
353
|
}
|
|
149
354
|
return;
|
|
150
355
|
}
|
|
151
|
-
if (e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0) {
|
|
356
|
+
if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0) {
|
|
152
357
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
153
358
|
var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
|
|
154
359
|
var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -167,7 +372,7 @@ var FxEditor = function FxEditor() {
|
|
|
167
372
|
}
|
|
168
373
|
}
|
|
169
374
|
e.preventDefault();
|
|
170
|
-
} else if (e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0) {
|
|
375
|
+
} else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0) {
|
|
171
376
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
172
377
|
var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
|
|
173
378
|
var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -226,7 +431,7 @@ var FxEditor = function FxEditor() {
|
|
|
226
431
|
}
|
|
227
432
|
}
|
|
228
433
|
});
|
|
229
|
-
}, [context.allowEdit, context.luckysheetCellUpdate.
|
|
434
|
+
}, [capturePreFormulaState, context.allowEdit, context.luckysheetCellUpdate, handleFormulaHistoryUndoRedo, refs.cellInput, refs.fxInput, setContext]);
|
|
230
435
|
var handleHideShowHint = function handleHideShowHint() {
|
|
231
436
|
var _a, _b, _c, _d;
|
|
232
437
|
var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -247,26 +452,54 @@ var FxEditor = function FxEditor() {
|
|
|
247
452
|
}
|
|
248
453
|
};
|
|
249
454
|
var onChange = useCallback(function () {
|
|
250
|
-
var _a, _b, _c;
|
|
455
|
+
var _a, _b, _c, _d;
|
|
251
456
|
if (context.isFlvReadOnly) return;
|
|
252
|
-
|
|
253
|
-
if (
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
457
|
+
var fxEl = refs.fxInput.current;
|
|
458
|
+
if (fxEl && context.luckysheetCellUpdate.length === 2 && formulaAnchorCellRef.current == null) {
|
|
459
|
+
var t = ((_a = fxEl.innerText) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
460
|
+
if (t.startsWith("=")) {
|
|
461
|
+
formulaAnchorCellRef.current = [context.luckysheetCellUpdate[0], context.luckysheetCellUpdate[1]];
|
|
462
|
+
}
|
|
257
463
|
}
|
|
258
|
-
|
|
464
|
+
handleHideShowHint();
|
|
465
|
+
setShowSearchHint(shouldShowFormulaFunctionList((_c = (_b = refs.fxInput) === null || _b === void 0 ? void 0 : _b.current) !== null && _c !== void 0 ? _c : null));
|
|
466
|
+
var currentCommaCount = countCommasBeforeCursor((_d = refs.fxInput) === null || _d === void 0 ? void 0 : _d.current);
|
|
259
467
|
setCommaCount(currentCommaCount);
|
|
260
468
|
var e = lastKeyDownEventRef.current;
|
|
261
|
-
if (!e)
|
|
469
|
+
if (!e) {
|
|
470
|
+
var fx = refs.fxInput.current;
|
|
471
|
+
var cell = refs.cellInput.current;
|
|
472
|
+
var isFormula = function isFormula(el) {
|
|
473
|
+
var _a, _b;
|
|
474
|
+
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("=")));
|
|
475
|
+
};
|
|
476
|
+
var sel = window.getSelection();
|
|
477
|
+
var editor_1 = null;
|
|
478
|
+
if (sel === null || sel === void 0 ? void 0 : sel.rangeCount) {
|
|
479
|
+
var node = sel.getRangeAt(0).startContainer;
|
|
480
|
+
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;
|
|
481
|
+
}
|
|
482
|
+
if (!editor_1 && isFormula(fx)) editor_1 = fx;else if (!editor_1 && isFormula(cell)) editor_1 = cell;
|
|
483
|
+
if (editor_1) {
|
|
484
|
+
setContext(function (draftCtx) {
|
|
485
|
+
if (!isAllowEdit(draftCtx, draftCtx.luckysheet_select_save)) return;
|
|
486
|
+
rangeHightlightselected(draftCtx, editor_1);
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
262
491
|
var kcode = e.keyCode;
|
|
263
492
|
if (!kcode) return;
|
|
493
|
+
appendFormulaHistoryFromPrimaryEditor(function () {
|
|
494
|
+
return getCursorPosition(refs.fxInput.current);
|
|
495
|
+
});
|
|
264
496
|
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) {
|
|
265
497
|
setContext(function (draftCtx) {
|
|
266
498
|
handleFormulaInput(draftCtx, refs.cellInput.current, refs.fxInput.current, kcode, recentText.current);
|
|
267
499
|
});
|
|
268
500
|
}
|
|
269
|
-
}, [refs.cellInput, refs.fxInput, setContext]);
|
|
501
|
+
}, [appendFormulaHistoryFromPrimaryEditor, context.isFlvReadOnly, context.luckysheetCellUpdate, refs.cellInput, refs.fxInput, setContext]);
|
|
502
|
+
useRerenderOnFormulaCaret(refs.fxInput, context.luckysheetCellUpdate.length > 0);
|
|
270
503
|
var getFunctionNameFromInput = useCallback(function () {
|
|
271
504
|
var _a, _b, _c, _d;
|
|
272
505
|
var inputText = ((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText) || "";
|
|
@@ -283,8 +516,9 @@ var FxEditor = function FxEditor() {
|
|
|
283
516
|
}
|
|
284
517
|
return null;
|
|
285
518
|
}, []);
|
|
286
|
-
var functionName = context.functionHint
|
|
519
|
+
var functionName = (_c = (_b = getFunctionNameFromFormulaCaretSpans(refs.fxInput.current)) !== null && _b !== void 0 ? _b : context.functionHint) !== null && _c !== void 0 ? _c : getFunctionNameFromInput();
|
|
287
520
|
var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
|
|
521
|
+
var showFxFormulaChrome = context.luckysheetCellUpdate.length > 0 && getFormulaEditorOwner(context) === "fx";
|
|
288
522
|
var allowEdit = useMemo(function () {
|
|
289
523
|
if (context.allowEdit === false) {
|
|
290
524
|
return false;
|
|
@@ -298,9 +532,9 @@ var FxEditor = function FxEditor() {
|
|
|
298
532
|
return true;
|
|
299
533
|
}, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, isHidenRC]);
|
|
300
534
|
var divRef = useRef(null);
|
|
301
|
-
var
|
|
302
|
-
isResizing =
|
|
303
|
-
setIsResizing =
|
|
535
|
+
var _k = useState(false),
|
|
536
|
+
isResizing = _k[0],
|
|
537
|
+
setIsResizing = _k[1];
|
|
304
538
|
var startResize = function startResize(e) {
|
|
305
539
|
e.preventDefault();
|
|
306
540
|
setIsResizing(true);
|
|
@@ -319,7 +553,7 @@ var FxEditor = function FxEditor() {
|
|
|
319
553
|
document.addEventListener("mouseup", _onMouseUp);
|
|
320
554
|
};
|
|
321
555
|
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
322
|
-
className: "fortune-fx-editor",
|
|
556
|
+
className: showFxFormulaChrome ? "fortune-fx-editor fortune-fx-editor--formula-owner" : "fortune-fx-editor",
|
|
323
557
|
ref: divRef
|
|
324
558
|
}, /*#__PURE__*/React.createElement(NameBox, null), /*#__PURE__*/React.createElement("div", {
|
|
325
559
|
className: "fortune-fx-icon",
|
|
@@ -346,8 +580,20 @@ var FxEditor = function FxEditor() {
|
|
|
346
580
|
onMouseUp: function onMouseUp() {
|
|
347
581
|
var _a;
|
|
348
582
|
handleHideShowHint();
|
|
349
|
-
|
|
583
|
+
setContext(function (draftCtx) {
|
|
584
|
+
setFormulaEditorOwner(draftCtx, "fx");
|
|
585
|
+
});
|
|
586
|
+
var editor = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current;
|
|
587
|
+
var currentCommaCount = countCommasBeforeCursor(editor);
|
|
350
588
|
setCommaCount(currentCommaCount);
|
|
589
|
+
setContext(function (draftCtx) {
|
|
590
|
+
if (draftCtx.formulaCache.rangeSelectionActive !== true) return;
|
|
591
|
+
var clickedInsideManagedRange = getFormulaRangeIndexAtCaret(editor) !== null;
|
|
592
|
+
var atValidInsertionPoint = isCaretAtValidFormulaRangeInsertionPoint(editor);
|
|
593
|
+
if (clickedInsideManagedRange || !atValidInsertionPoint) {
|
|
594
|
+
markRangeSelectionDirty(draftCtx);
|
|
595
|
+
}
|
|
596
|
+
});
|
|
351
597
|
},
|
|
352
598
|
innerRef: function innerRef(e) {
|
|
353
599
|
refs.fxInput.current = e;
|
|
@@ -360,7 +606,7 @@ var FxEditor = function FxEditor() {
|
|
|
360
606
|
onChange: onChange,
|
|
361
607
|
tabIndex: 0,
|
|
362
608
|
allowEdit: allowEdit && !context.isFlvReadOnly
|
|
363
|
-
}), showSearchHint && (/*#__PURE__*/React.createElement(FormulaSearch, {
|
|
609
|
+
}), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0 || fn) && showFxFormulaChrome && (/*#__PURE__*/React.createElement(React.Fragment, null, showSearchHint && (/*#__PURE__*/React.createElement(FormulaSearch, {
|
|
364
610
|
from: "fx",
|
|
365
611
|
onMouseMove: function onMouseMove(e) {
|
|
366
612
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
@@ -376,12 +622,22 @@ var FxEditor = function FxEditor() {
|
|
|
376
622
|
}
|
|
377
623
|
})), /*#__PURE__*/React.createElement("div", {
|
|
378
624
|
className: "fx-hint"
|
|
379
|
-
}, showFormulaHint && fn && (/*#__PURE__*/React.createElement(FormulaHint, {
|
|
625
|
+
}, showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/React.createElement(FormulaHint, {
|
|
380
626
|
handleShowFormulaHint: handleShowFormulaHint,
|
|
381
627
|
showFormulaHint: showFormulaHint,
|
|
382
628
|
commaCount: commaCount,
|
|
383
629
|
functionName: functionName
|
|
384
|
-
})), !showFormulaHint && fn && (/*#__PURE__*/React.createElement(
|
|
630
|
+
})), !showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/React.createElement(Tooltip, {
|
|
631
|
+
text: "Turn on formula suggestions (F10)",
|
|
632
|
+
placement: "top",
|
|
633
|
+
defaultOpen: true,
|
|
634
|
+
style: {
|
|
635
|
+
position: "absolute",
|
|
636
|
+
top: "-50px",
|
|
637
|
+
left: "-130px",
|
|
638
|
+
width: "210px"
|
|
639
|
+
}
|
|
640
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
385
641
|
className: "luckysheet-hin absolute show-more-btn",
|
|
386
642
|
onClick: function onClick() {
|
|
387
643
|
handleShowFormulaHint();
|
|
@@ -395,7 +651,7 @@ var FxEditor = function FxEditor() {
|
|
|
395
651
|
margin: "auto",
|
|
396
652
|
marginTop: "1px"
|
|
397
653
|
}
|
|
398
|
-
})))))), /*#__PURE__*/React.createElement("div", {
|
|
654
|
+
}))))))))), /*#__PURE__*/React.createElement("div", {
|
|
399
655
|
className: "resize-handle",
|
|
400
656
|
onMouseDown: startResize,
|
|
401
657
|
style: {
|