@fileverse-dev/fortune-react 1.3.12 → 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/ConditionFormat/ConditionRules.js +15 -5
- package/es/components/ConditionFormat/index.js +3 -0
- package/es/components/ContextMenu/index.js +1 -1
- package/es/components/DataVerification/ColorPicker.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 +409 -160
- 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 -39
- package/es/components/SheetOverlay/index.js +29 -17
- package/es/components/Toolbar/index.js +17 -12
- package/es/components/Workbook/api.d.ts +3 -0
- package/es/components/Workbook/index.d.ts +3 -0
- package/es/components/Workbook/index.js +9 -3
- 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/ConditionFormat/ConditionRules.js +15 -5
- package/lib/components/ConditionFormat/index.js +3 -0
- package/lib/components/ContextMenu/index.js +1 -1
- package/lib/components/DataVerification/ColorPicker.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 +407 -158
- 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 -39
- package/lib/components/SheetOverlay/index.js +28 -16
- package/lib/components/Toolbar/index.js +16 -11
- package/lib/components/Workbook/api.d.ts +3 -0
- package/lib/components/Workbook/index.d.ts +3 -0
- package/lib/components/Workbook/index.js +8 -2
- package/lib/hooks/useFormulaEditorHistory.d.ts +24 -0
- package/lib/hooks/useFormulaEditorHistory.js +126 -0
- package/lib/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
- package/lib/hooks/useRerenderOnFormulaCaret.js +34 -0
- package/package.json +2 -2
|
@@ -14,7 +14,10 @@ var _ContentEditable = _interopRequireDefault(require("./ContentEditable"));
|
|
|
14
14
|
var _FormulaSearch = _interopRequireDefault(require("./FormulaSearch"));
|
|
15
15
|
var _FormulaHint = _interopRequireDefault(require("./FormulaHint"));
|
|
16
16
|
var _usePrevious = _interopRequireDefault(require("../../hooks/usePrevious"));
|
|
17
|
+
var _useFormulaEditorHistory = require("../../hooks/useFormulaEditorHistory");
|
|
18
|
+
var _useRerenderOnFormulaCaret = require("../../hooks/useRerenderOnFormulaCaret");
|
|
17
19
|
var _helper = require("./helper");
|
|
20
|
+
var _formulaSegmentBoundary = require("./formula-segment-boundary");
|
|
18
21
|
var _LucideIcon = require("./LucideIcon");
|
|
19
22
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
23
|
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 _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
|
|
@@ -29,57 +32,72 @@ var __assign = void 0 && (void 0).__assign || function () {
|
|
|
29
32
|
return __assign.apply(this, arguments);
|
|
30
33
|
};
|
|
31
34
|
var InputBox = function InputBox() {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
33
|
-
var
|
|
34
|
-
context =
|
|
35
|
-
setContext =
|
|
36
|
-
refs =
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
36
|
+
var _q = (0, _react.useContext)(_context.default),
|
|
37
|
+
context = _q.context,
|
|
38
|
+
setContext = _q.setContext,
|
|
39
|
+
refs = _q.refs;
|
|
37
40
|
var inputRef = (0, _react.useRef)(null);
|
|
38
41
|
var lastKeyDownEventRef = (0, _react.useRef)(null);
|
|
39
42
|
var prevCellUpdate = (0, _usePrevious.default)(context.luckysheetCellUpdate);
|
|
40
43
|
var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
|
|
41
|
-
var
|
|
42
|
-
isHidenRC =
|
|
43
|
-
setIsHidenRC =
|
|
44
|
-
var
|
|
45
|
-
isInputBoxActive =
|
|
46
|
-
setIsInputBoxActive =
|
|
47
|
-
var
|
|
48
|
-
activeCell =
|
|
49
|
-
setActiveCell =
|
|
50
|
-
var
|
|
51
|
-
activeRefCell =
|
|
52
|
-
setActiveRefCell =
|
|
53
|
-
var
|
|
44
|
+
var _r = (0, _react.useState)(false),
|
|
45
|
+
isHidenRC = _r[0],
|
|
46
|
+
setIsHidenRC = _r[1];
|
|
47
|
+
var _s = (0, _react.useState)(false),
|
|
48
|
+
isInputBoxActive = _s[0],
|
|
49
|
+
setIsInputBoxActive = _s[1];
|
|
50
|
+
var _t = (0, _react.useState)(""),
|
|
51
|
+
activeCell = _t[0],
|
|
52
|
+
setActiveCell = _t[1];
|
|
53
|
+
var _u = (0, _react.useState)(""),
|
|
54
|
+
activeRefCell = _u[0],
|
|
55
|
+
setActiveRefCell = _u[1];
|
|
56
|
+
var _v = (0, _react.useState)(false),
|
|
57
|
+
showAddressIndicator = _v[0],
|
|
58
|
+
setShowAddressIndicator = _v[1];
|
|
59
|
+
var scrollAtEditSessionStartRef = (0, _react.useRef)(null);
|
|
60
|
+
var _w = (0, _react.useState)({
|
|
54
61
|
left: 0,
|
|
55
62
|
top: 0
|
|
56
63
|
}),
|
|
57
|
-
frozenPosition =
|
|
58
|
-
setFrozenPosition =
|
|
64
|
+
frozenPosition = _w[0],
|
|
65
|
+
setFrozenPosition = _w[1];
|
|
59
66
|
var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
|
|
60
|
-
var
|
|
61
|
-
firstSelectionActiveCell =
|
|
62
|
-
setFirstSelectionActiveCell =
|
|
63
|
-
var
|
|
64
|
-
commaCount =
|
|
65
|
-
setCommaCount =
|
|
67
|
+
var _x = (0, _react.useState)({}),
|
|
68
|
+
firstSelectionActiveCell = _x[0],
|
|
69
|
+
setFirstSelectionActiveCell = _x[1];
|
|
70
|
+
var _y = (0, _react.useState)(0),
|
|
71
|
+
commaCount = _y[0],
|
|
72
|
+
setCommaCount = _y[1];
|
|
73
|
+
var _z = (0, _react.useState)(false),
|
|
74
|
+
cellEditorIsFormula = _z[0],
|
|
75
|
+
setCellEditorIsFormula = _z[1];
|
|
66
76
|
var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
|
|
67
|
-
var
|
|
68
|
-
showFormulaHint =
|
|
69
|
-
setShowFormulaHint =
|
|
70
|
-
var
|
|
71
|
-
showSearchHint =
|
|
72
|
-
setShowSearchHint =
|
|
77
|
+
var _0 = (0, _react.useState)(!hideFormulaHintLocal),
|
|
78
|
+
showFormulaHint = _0[0],
|
|
79
|
+
setShowFormulaHint = _0[1];
|
|
80
|
+
var _1 = (0, _react.useState)(false),
|
|
81
|
+
showSearchHint = _1[0],
|
|
82
|
+
setShowSearchHint = _1[1];
|
|
73
83
|
var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
|
|
74
84
|
var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
|
|
75
|
-
var preText = (0, _react.useRef)("");
|
|
76
|
-
var placeRef = (0, _react.useRef)("");
|
|
77
85
|
var isComposingRef = (0, _react.useRef)(false);
|
|
86
|
+
var formulaAnchorCellRef = (0, _react.useRef)(null);
|
|
87
|
+
var skipNextAnchorSelectionSyncRef = (0, _react.useRef)(false);
|
|
88
|
+
var lastHandledMouseDragSignatureRef = (0, _react.useRef)("");
|
|
89
|
+
var _2 = (0, _useFormulaEditorHistory.useFormulaEditorHistory)(inputRef, refs.cellInput, refs.fxInput, setContext, "cell"),
|
|
90
|
+
formulaHistoryRef = _2.formulaHistoryRef,
|
|
91
|
+
preTextRef = _2.preTextRef,
|
|
92
|
+
resetFormulaHistory = _2.resetFormulaHistory,
|
|
93
|
+
handleFormulaHistoryUndoRedo = _2.handleFormulaHistoryUndoRedo,
|
|
94
|
+
capturePreFormulaState = _2.capturePreFormulaState,
|
|
95
|
+
appendFormulaHistoryFromPrimaryEditor = _2.appendFormulaHistoryFromPrimaryEditor;
|
|
78
96
|
var ZWSP = "\u200B";
|
|
79
97
|
var inputBoxInnerRef = (0, _react.useRef)(null);
|
|
80
|
-
var
|
|
81
|
-
linkSelectionHighlightRects =
|
|
82
|
-
setLinkSelectionHighlightRects =
|
|
98
|
+
var _3 = (0, _react.useState)([]),
|
|
99
|
+
linkSelectionHighlightRects = _3[0],
|
|
100
|
+
setLinkSelectionHighlightRects = _3[1];
|
|
83
101
|
var ensureNotEmpty = function ensureNotEmpty() {
|
|
84
102
|
var el = inputRef.current;
|
|
85
103
|
if (!el) return;
|
|
@@ -102,12 +120,11 @@ var InputBox = function InputBox() {
|
|
|
102
120
|
return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
|
|
103
121
|
};
|
|
104
122
|
var inputBoxStyle = (0, _react.useMemo)(function () {
|
|
105
|
-
var _a;
|
|
106
123
|
if (firstSelectionActiveCell && context.luckysheetCellUpdate.length > 0) {
|
|
107
124
|
var flowdata = (0, _fortuneCore.getFlowdata)(context);
|
|
108
125
|
if (!flowdata) return {};
|
|
109
126
|
var style = (0, _fortuneCore.getStyleByCell)(context, flowdata, firstSelectionActiveCell.row_focus, firstSelectionActiveCell.column_focus);
|
|
110
|
-
if (
|
|
127
|
+
if (cellEditorIsFormula) {
|
|
111
128
|
style = __assign(__assign({}, style), {
|
|
112
129
|
textAlign: "left"
|
|
113
130
|
});
|
|
@@ -115,7 +132,7 @@ var InputBox = function InputBox() {
|
|
|
115
132
|
return style;
|
|
116
133
|
}
|
|
117
134
|
return {};
|
|
118
|
-
}, [context.luckysheetfile, context.currentSheetId, context.luckysheetCellUpdate, (_b = context === null || context === void 0 ? void 0 : context.luckysheetCellUpdate) === null || _b === void 0 ? void 0 : _b.length, firstSelectionActiveCell]);
|
|
135
|
+
}, [context.luckysheetfile, context.currentSheetId, context.luckysheetCellUpdate, (_b = context === null || context === void 0 ? void 0 : context.luckysheetCellUpdate) === null || _b === void 0 ? void 0 : _b.length, firstSelectionActiveCell, cellEditorIsFormula]);
|
|
119
136
|
(0, _react.useLayoutEffect)(function () {
|
|
120
137
|
var _a;
|
|
121
138
|
if (!context.allowEdit) {
|
|
@@ -135,10 +152,23 @@ var InputBox = function InputBox() {
|
|
|
135
152
|
if (_lodash.default.isEqual(prevCellUpdate, context.luckysheetCellUpdate) && prevSheetId === context.currentSheetId) {
|
|
136
153
|
return;
|
|
137
154
|
}
|
|
155
|
+
var _b = context.luckysheetCellUpdate,
|
|
156
|
+
ur = _b[0],
|
|
157
|
+
uc = _b[1];
|
|
158
|
+
var pending_1 = refs.globalCache.pendingTypeOverCell;
|
|
159
|
+
if (pending_1 && pending_1[0] === ur && pending_1[1] === uc) {
|
|
160
|
+
refs.globalCache.overwriteCell = false;
|
|
161
|
+
if (inputRef.current) {
|
|
162
|
+
setCellEditorIsFormula(inputRef.current.innerText.trim().startsWith("="));
|
|
163
|
+
}
|
|
164
|
+
delete refs.globalCache.doNotFocus;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
138
167
|
var flowdata = (0, _fortuneCore.getFlowdata)(context);
|
|
139
168
|
var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index]) === null || _a === void 0 ? void 0 : _a[col_index];
|
|
169
|
+
var overwrite = refs.globalCache.overwriteCell;
|
|
140
170
|
var value_1 = "";
|
|
141
|
-
if (cell && !
|
|
171
|
+
if (cell && !overwrite) {
|
|
142
172
|
if ((0, _fortuneCore.isInlineStringCell)(cell)) {
|
|
143
173
|
value_1 = (0, _fortuneCore.getInlineStringHTML)(row_index, col_index, flowdata);
|
|
144
174
|
} else if (cell.f) {
|
|
@@ -154,14 +184,20 @@ var InputBox = function InputBox() {
|
|
|
154
184
|
}
|
|
155
185
|
}
|
|
156
186
|
refs.globalCache.overwriteCell = false;
|
|
187
|
+
var wroteEditorFromStoredCell = false;
|
|
157
188
|
if (!refs.globalCache.ignoreWriteCell && inputRef.current && value_1) {
|
|
158
189
|
inputRef.current.innerHTML = (0, _fortuneCore.escapeHTMLTag)((0, _fortuneCore.escapeScriptTag)(value_1));
|
|
159
|
-
|
|
190
|
+
wroteEditorFromStoredCell = true;
|
|
191
|
+
} else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1 && !overwrite) {
|
|
160
192
|
var valueD = (0, _fortuneCore.getCellValue)(row_index, col_index, flowdata, "f");
|
|
161
193
|
inputRef.current.innerText = valueD;
|
|
194
|
+
wroteEditorFromStoredCell = true;
|
|
162
195
|
}
|
|
163
196
|
refs.globalCache.ignoreWriteCell = false;
|
|
164
|
-
if (
|
|
197
|
+
if (inputRef.current) {
|
|
198
|
+
setCellEditorIsFormula(inputRef.current.innerText.trim().startsWith("="));
|
|
199
|
+
}
|
|
200
|
+
if (wroteEditorFromStoredCell && !refs.globalCache.doNotFocus) {
|
|
165
201
|
setTimeout(function () {
|
|
166
202
|
(0, _fortuneCore.moveToEnd)(inputRef.current);
|
|
167
203
|
});
|
|
@@ -174,8 +210,43 @@ var InputBox = function InputBox() {
|
|
|
174
210
|
if (inputRef.current) {
|
|
175
211
|
inputRef.current.innerHTML = "";
|
|
176
212
|
}
|
|
213
|
+
delete refs.globalCache.pendingTypeOverCell;
|
|
214
|
+
setCellEditorIsFormula(false);
|
|
215
|
+
resetFormulaHistory();
|
|
177
216
|
}
|
|
178
|
-
}, [context.luckysheetCellUpdate]);
|
|
217
|
+
}, [context.luckysheetCellUpdate, resetFormulaHistory, refs.globalCache]);
|
|
218
|
+
(0, _react.useEffect)(function () {
|
|
219
|
+
if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) return;
|
|
220
|
+
delete refs.globalCache.pendingTypeOverCell;
|
|
221
|
+
}, [context.luckysheetCellUpdate, refs.globalCache]);
|
|
222
|
+
(0, _react.useEffect)(function () {
|
|
223
|
+
var _a;
|
|
224
|
+
if (_lodash.default.isEmpty(context.luckysheetCellUpdate) || !refs.cellInput.current) {
|
|
225
|
+
formulaAnchorCellRef.current = null;
|
|
226
|
+
lastHandledMouseDragSignatureRef.current = "";
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
var inputText = ((_a = refs.cellInput.current.innerText) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
230
|
+
if (!inputText.startsWith("=")) {
|
|
231
|
+
formulaAnchorCellRef.current = null;
|
|
232
|
+
lastHandledMouseDragSignatureRef.current = "";
|
|
233
|
+
}
|
|
234
|
+
}, [context.luckysheetCellUpdate, refs.cellInput]);
|
|
235
|
+
(0, _react.useEffect)(function () {
|
|
236
|
+
if (_lodash.default.isEmpty(context.luckysheetCellUpdate) || _lodash.default.isEmpty(prevCellUpdate) || _lodash.default.isEqual(prevCellUpdate, context.luckysheetCellUpdate)) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
setContext(function (ctx) {
|
|
240
|
+
ctx.formulaRangeHighlight = [];
|
|
241
|
+
ctx.formulaRangeSelect = undefined;
|
|
242
|
+
ctx.formulaCache.selectingRangeIndex = -1;
|
|
243
|
+
ctx.formulaCache.func_selectedrange = undefined;
|
|
244
|
+
ctx.formulaCache.rangestart = false;
|
|
245
|
+
ctx.formulaCache.rangedrag_column_start = false;
|
|
246
|
+
ctx.formulaCache.rangedrag_row_start = false;
|
|
247
|
+
ctx.formulaCache.rangechangeindex = undefined;
|
|
248
|
+
});
|
|
249
|
+
}, [context.luckysheetCellUpdate, prevCellUpdate, setContext]);
|
|
179
250
|
(0, _react.useEffect)(function () {
|
|
180
251
|
setIsHidenRC((0, _fortuneCore.isShowHidenCR)(context));
|
|
181
252
|
}, [context.luckysheet_select_save]);
|
|
@@ -185,65 +256,45 @@ var InputBox = function InputBox() {
|
|
|
185
256
|
setIsInputBoxActive(false);
|
|
186
257
|
}
|
|
187
258
|
}, [firstSelection, (_c = context.rangeDialog) === null || _c === void 0 ? void 0 : _c.show, context.luckysheetCellUpdate]);
|
|
259
|
+
(0, _react.useEffect)(function () {
|
|
260
|
+
if (isInputBoxActive) return;
|
|
261
|
+
setContext(function (ctx) {
|
|
262
|
+
if (_lodash.default.isEmpty(ctx.formulaRangeHighlight) && !ctx.formulaRangeSelect && ctx.formulaCache.selectingRangeIndex === -1 && !ctx.formulaCache.func_selectedrange) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
ctx.formulaRangeHighlight = [];
|
|
266
|
+
ctx.formulaRangeSelect = undefined;
|
|
267
|
+
ctx.formulaCache.selectingRangeIndex = -1;
|
|
268
|
+
ctx.formulaCache.func_selectedrange = undefined;
|
|
269
|
+
ctx.formulaCache.rangestart = false;
|
|
270
|
+
ctx.formulaCache.rangedrag_column_start = false;
|
|
271
|
+
ctx.formulaCache.rangedrag_row_start = false;
|
|
272
|
+
ctx.formulaCache.rangechangeindex = undefined;
|
|
273
|
+
ctx.formulaCache.rangeSelectionActive = null;
|
|
274
|
+
});
|
|
275
|
+
}, [isInputBoxActive, setContext]);
|
|
188
276
|
var getActiveFormula = (0, _react.useCallback)(function () {
|
|
189
277
|
return document.querySelector(".luckysheet-formula-search-item-active");
|
|
190
278
|
}, []);
|
|
191
279
|
var insertSelectedFormula = (0, _react.useCallback)(function (formulaName) {
|
|
192
|
-
var
|
|
193
|
-
if (/^=[a-zA-Z]+$/.test(inputRef.current.innerText)) {
|
|
194
|
-
var ht = "<span dir=\"auto\" class=\"luckysheet-formula-text-color\">=</span><span dir=\"auto\" class=\"luckysheet-formula-text-func\">".concat(formulaName, "</span><span dir=\"auto\" class=\"luckysheet-formula-text-lpar\">(</span>");
|
|
195
|
-
inputRef.current.innerHTML = ht;
|
|
196
|
-
var fxEditor = document.getElementById("luckysheet-functionbox-cell");
|
|
197
|
-
if (fxEditor) {
|
|
198
|
-
fxEditor.innerHTML = ht;
|
|
199
|
-
}
|
|
200
|
-
(0, _helper.moveCursorToEnd)(inputRef.current);
|
|
201
|
-
setContext(function (draftCtx) {
|
|
202
|
-
draftCtx.functionCandidates = [];
|
|
203
|
-
draftCtx.defaultCandidates = [];
|
|
204
|
-
draftCtx.functionHint = formulaName;
|
|
205
|
-
});
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
var textEditor = document.getElementById("luckysheet-rich-text-editor");
|
|
280
|
+
var textEditor = inputRef.current;
|
|
209
281
|
if (!textEditor) return;
|
|
210
|
-
|
|
211
|
-
var
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
var deleteCount = searchTxt === "=" ? 0 : searchTxt.length;
|
|
223
|
-
if (deleteCount > 0 && range.startContainer.nodeType === Node.TEXT_NODE && textEditor.contains(range.startContainer)) {
|
|
224
|
-
var startOffset = Math.max(range.startOffset - deleteCount, 0);
|
|
225
|
-
var endOffset = range.startOffset;
|
|
226
|
-
range.setStart(range.startContainer, startOffset);
|
|
227
|
-
range.setEnd(range.startContainer, endOffset);
|
|
228
|
-
range.deleteContents();
|
|
229
|
-
}
|
|
230
|
-
textEditor.querySelectorAll(".luckysheet-formula-text-func, .luckysheet-formula-text-lpar").forEach(function (el) {
|
|
231
|
-
return el.remove();
|
|
232
|
-
});
|
|
233
|
-
var funcNode = new DOMParser().parseFromString("<span dir=\"auto\" class=\"luckysheet-formula-text-func\">".concat(formulaName, "</span>"), "text/html").body.firstChild;
|
|
234
|
-
var parNode = new DOMParser().parseFromString("<span dir=\"auto\" class=\"luckysheet-formula-text-lpar\">(</span>", "text/html").body.firstChild;
|
|
235
|
-
if (range && parNode && funcNode) {
|
|
236
|
-
range.insertNode(funcNode);
|
|
237
|
-
range.collapse(false);
|
|
238
|
-
range.insertNode(parNode);
|
|
239
|
-
range.collapse(false);
|
|
240
|
-
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
241
|
-
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
|
242
|
-
}
|
|
282
|
+
var fxEditor = document.getElementById("luckysheet-functionbox-cell");
|
|
283
|
+
var _a = (0, _helper.buildFormulaSuggestionText)(textEditor, formulaName),
|
|
284
|
+
text = _a.text,
|
|
285
|
+
caretOffset = _a.caretOffset;
|
|
286
|
+
var safeText = (0, _fortuneCore.escapeScriptTag)(text);
|
|
287
|
+
var html = safeText.startsWith("=") ? (0, _fortuneCore.functionHTMLGenerate)(safeText) : (0, _fortuneCore.escapeHTMLTag)(safeText);
|
|
288
|
+
textEditor.innerHTML = html;
|
|
289
|
+
if (fxEditor) {
|
|
290
|
+
fxEditor.innerHTML = html;
|
|
291
|
+
}
|
|
292
|
+
(0, _helper.setCursorPosition)(textEditor, caretOffset);
|
|
293
|
+
setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)(textEditor));
|
|
243
294
|
setContext(function (draftCtx) {
|
|
244
295
|
draftCtx.functionCandidates = [];
|
|
245
296
|
draftCtx.defaultCandidates = [];
|
|
246
|
-
draftCtx.functionHint = formulaName;
|
|
297
|
+
draftCtx.functionHint = (formulaName || "").toUpperCase();
|
|
247
298
|
});
|
|
248
299
|
}, [setContext]);
|
|
249
300
|
var clearSearchItemActiveClass = (0, _react.useCallback)(function () {
|
|
@@ -266,7 +317,7 @@ var InputBox = function InputBox() {
|
|
|
266
317
|
var _a, _b;
|
|
267
318
|
if (isComposingRef.current || !inputRef.current) return;
|
|
268
319
|
if (e.target.className.includes("sign-fortune")) return;
|
|
269
|
-
|
|
320
|
+
preTextRef.current = inputRef.current.innerText;
|
|
270
321
|
var formulaName = (_b = (_a = getActiveFormula()) === null || _a === void 0 ? void 0 : _a.querySelector(".luckysheet-formula-search-func")) === null || _b === void 0 ? void 0 : _b.textContent;
|
|
271
322
|
var lastSpanText = getLastInputSpanText();
|
|
272
323
|
if (formulaName && !(0, _helper.isLetterNumberPattern)(lastSpanText)) {
|
|
@@ -279,11 +330,150 @@ var InputBox = function InputBox() {
|
|
|
279
330
|
event.stopPropagation();
|
|
280
331
|
event.preventDefault();
|
|
281
332
|
};
|
|
333
|
+
(0, _react.useEffect)(function () {
|
|
334
|
+
var _a;
|
|
335
|
+
var cellInputEl = refs.cellInput.current;
|
|
336
|
+
if (!((_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) || !cellInputEl) return;
|
|
337
|
+
setContext(function (ctx) {
|
|
338
|
+
var _a;
|
|
339
|
+
var currentSelection = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1];
|
|
340
|
+
if (!currentSelection) return;
|
|
341
|
+
if ((0, _fortuneCore.getFormulaEditorOwner)(ctx) === "fx") {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
(0, _fortuneCore.israngeseleciton)(ctx);
|
|
345
|
+
var keyboardSyncRangeIndex = (0, _fortuneCore.getFormulaRangeIndexForKeyboardSync)(cellInputEl);
|
|
346
|
+
if (skipNextAnchorSelectionSyncRef.current && formulaAnchorCellRef.current) {
|
|
347
|
+
var _b = formulaAnchorCellRef.current,
|
|
348
|
+
anchorRow = _b[0],
|
|
349
|
+
anchorCol = _b[1];
|
|
350
|
+
var isAnchorSelection = currentSelection.row_focus === anchorRow && currentSelection.column_focus === anchorCol;
|
|
351
|
+
if (isAnchorSelection) {
|
|
352
|
+
skipNextAnchorSelectionSyncRef.current = false;
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
var isFormulaMode = (0, _fortuneCore.isFormulaReferenceInputMode)(ctx);
|
|
357
|
+
if (!isFormulaMode) return;
|
|
358
|
+
if (keyboardSyncRangeIndex !== null) {
|
|
359
|
+
ctx.formulaCache.rangechangeindex = keyboardSyncRangeIndex;
|
|
360
|
+
ctx.formulaCache.rangestart = true;
|
|
361
|
+
ctx.formulaCache.rangedrag_column_start = false;
|
|
362
|
+
ctx.formulaCache.rangedrag_row_start = false;
|
|
363
|
+
} else {
|
|
364
|
+
ctx.formulaCache.rangechangeindex = undefined;
|
|
365
|
+
ctx.formulaCache.rangestart = false;
|
|
366
|
+
}
|
|
367
|
+
ctx.formulaCache.rangeSelectionActive = true;
|
|
368
|
+
_fortuneCore.rangeSetValue === null || _fortuneCore.rangeSetValue === void 0 ? void 0 : (0, _fortuneCore.rangeSetValue)(ctx, cellInputEl, {
|
|
369
|
+
row: currentSelection.row,
|
|
370
|
+
column: currentSelection.column
|
|
371
|
+
}, refs.fxInput.current);
|
|
372
|
+
(0, _fortuneCore.rangeHightlightselected)(ctx, cellInputEl);
|
|
373
|
+
if (!_lodash.default.isNil(ctx.formulaCache.rangechangeindex)) {
|
|
374
|
+
ctx.formulaCache.selectingRangeIndex = ctx.formulaCache.rangechangeindex;
|
|
375
|
+
(0, _fortuneCore.createRangeHightlight)(ctx, cellInputEl.innerHTML, ctx.formulaCache.rangechangeindex);
|
|
376
|
+
var rectFromSelection = (0, _fortuneCore.seletedHighlistByindex)(ctx, currentSelection.row[0], currentSelection.row[1], currentSelection.column[0], currentSelection.column[1]);
|
|
377
|
+
if (rectFromSelection) {
|
|
378
|
+
(0, _fortuneCore.createFormulaRangeSelect)(ctx, {
|
|
379
|
+
rangeIndex: ctx.formulaCache.rangechangeindex || 0,
|
|
380
|
+
left: rectFromSelection.left,
|
|
381
|
+
top: rectFromSelection.top,
|
|
382
|
+
width: rectFromSelection.width,
|
|
383
|
+
height: rectFromSelection.height
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}, [context.luckysheet_select_save, (_d = context.rangeDialog) === null || _d === void 0 ? void 0 : _d.show]);
|
|
389
|
+
var formulaMouseDragSignature = function () {
|
|
390
|
+
var _a, _b, _c, _d;
|
|
391
|
+
var r = context.formulaCache.func_selectedrange;
|
|
392
|
+
if (!r) return "";
|
|
393
|
+
return [(_a = r.row) === null || _a === void 0 ? void 0 : _a[0], (_b = r.row) === null || _b === void 0 ? void 0 : _b[1], (_c = r.column) === null || _c === void 0 ? void 0 : _c[0], (_d = r.column) === null || _d === void 0 ? void 0 : _d[1], r.left_move, r.top_move, r.width_move, r.height_move].join(":");
|
|
394
|
+
}();
|
|
395
|
+
(0, _react.useEffect)(function () {
|
|
396
|
+
var _a;
|
|
397
|
+
if (!formulaMouseDragSignature) return;
|
|
398
|
+
if (lastHandledMouseDragSignatureRef.current === formulaMouseDragSignature) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (!refs.cellInput.current) return;
|
|
402
|
+
var inputText = ((_a = refs.cellInput.current.innerText) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
403
|
+
if (!inputText.startsWith("=")) return;
|
|
404
|
+
var dragRange = context.formulaCache.func_selectedrange;
|
|
405
|
+
if (!dragRange) return;
|
|
406
|
+
lastHandledMouseDragSignatureRef.current = formulaMouseDragSignature;
|
|
407
|
+
setContext(function (ctx) {
|
|
408
|
+
ctx.luckysheet_select_save = [{
|
|
409
|
+
row: [dragRange.row[0], dragRange.row[1]],
|
|
410
|
+
column: [dragRange.column[0], dragRange.column[1]],
|
|
411
|
+
row_focus: _lodash.default.isNil(dragRange.row_focus) ? dragRange.row[0] : dragRange.row_focus,
|
|
412
|
+
column_focus: _lodash.default.isNil(dragRange.column_focus) ? dragRange.column[0] : dragRange.column_focus
|
|
413
|
+
}];
|
|
414
|
+
});
|
|
415
|
+
}, [formulaMouseDragSignature, context.formulaCache.func_selectedrange, refs.cellInput, setContext]);
|
|
282
416
|
var onKeyDown = (0, _react.useCallback)(function (e) {
|
|
283
|
-
var _a, _b;
|
|
417
|
+
var _a, _b, _c;
|
|
418
|
+
setContext(function (draftCtx) {
|
|
419
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "cell");
|
|
420
|
+
});
|
|
284
421
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
285
|
-
|
|
286
|
-
|
|
422
|
+
capturePreFormulaState();
|
|
423
|
+
var currentInputText = ((_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) === null || _b === void 0 ? void 0 : _b.trim()) || "";
|
|
424
|
+
if ((e.key === "=" || currentInputText.startsWith("=")) && context.luckysheetCellUpdate.length === 2 && formulaAnchorCellRef.current == null) {
|
|
425
|
+
setContext(function (draftCtx) {
|
|
426
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
427
|
+
});
|
|
428
|
+
formulaAnchorCellRef.current = [context.luckysheetCellUpdate[0], context.luckysheetCellUpdate[1]];
|
|
429
|
+
}
|
|
430
|
+
if (e.key === "(" && currentInputText.startsWith("=")) {
|
|
431
|
+
setContext(function (draftCtx) {
|
|
432
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
if ((0, _formulaSegmentBoundary.isFormulaSegmentBoundaryKey)(e.key) && context.luckysheetCellUpdate.length > 0 && currentInputText.startsWith("=") && formulaAnchorCellRef.current) {
|
|
436
|
+
setContext(function (draftCtx) {
|
|
437
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
438
|
+
});
|
|
439
|
+
var _d = formulaAnchorCellRef.current,
|
|
440
|
+
anchorRow_1 = _d[0],
|
|
441
|
+
anchorCol_1 = _d[1];
|
|
442
|
+
skipNextAnchorSelectionSyncRef.current = true;
|
|
443
|
+
setTimeout(function () {
|
|
444
|
+
setContext(function (draftCtx) {
|
|
445
|
+
var _a, _b;
|
|
446
|
+
draftCtx.luckysheetCellUpdate = [anchorRow_1, anchorCol_1];
|
|
447
|
+
draftCtx.luckysheet_select_save = [{
|
|
448
|
+
row: [anchorRow_1, anchorRow_1],
|
|
449
|
+
column: [anchorCol_1, anchorCol_1],
|
|
450
|
+
row_focus: anchorRow_1,
|
|
451
|
+
column_focus: anchorCol_1
|
|
452
|
+
}];
|
|
453
|
+
draftCtx.formulaRangeSelect = undefined;
|
|
454
|
+
draftCtx.formulaCache.selectingRangeIndex = -1;
|
|
455
|
+
draftCtx.formulaCache.func_selectedrange = undefined;
|
|
456
|
+
draftCtx.formulaCache.rangechangeindex = undefined;
|
|
457
|
+
draftCtx.formulaCache.rangestart = false;
|
|
458
|
+
draftCtx.formulaCache.rangedrag_column_start = false;
|
|
459
|
+
draftCtx.formulaCache.rangedrag_row_start = false;
|
|
460
|
+
(0, _fortuneCore.createRangeHightlight)(draftCtx, ((_a = refs.cellInput.current) === null || _a === void 0 ? void 0 : _a.innerHTML) || ((_b = refs.fxInput.current) === null || _b === void 0 ? void 0 : _b.innerHTML) || "");
|
|
461
|
+
(0, _fortuneCore.moveHighlightCell)(draftCtx, "down", 0, "rangeOfSelect");
|
|
462
|
+
});
|
|
463
|
+
}, 0);
|
|
464
|
+
}
|
|
465
|
+
if ((e.metaKey || e.ctrlKey) && context.luckysheetCellUpdate.length > 0) {
|
|
466
|
+
if (e.code === "KeyZ" || e.code === "KeyY") {
|
|
467
|
+
var shouldUseFormulaHistory = currentInputText.startsWith("=") || formulaHistoryRef.current.active;
|
|
468
|
+
if (shouldUseFormulaHistory) {
|
|
469
|
+
var handledByFormulaHistory = handleFormulaHistoryUndoRedo(e.code === "KeyY" || e.code === "KeyZ" && e.shiftKey);
|
|
470
|
+
if (handledByFormulaHistory) {
|
|
471
|
+
e.preventDefault();
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
e.stopPropagation();
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
287
477
|
if (e.code === "KeyB") {
|
|
288
478
|
(0, _fortuneCore.handleBold)(context, inputRef.current);
|
|
289
479
|
stopPropagation(e);
|
|
@@ -303,7 +493,32 @@ var InputBox = function InputBox() {
|
|
|
303
493
|
setCommaCount(currentCommaCount);
|
|
304
494
|
}
|
|
305
495
|
var allowListNavigation = true;
|
|
496
|
+
var isArrowKey = e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight";
|
|
497
|
+
var isInPlaceEditMode = ((_c = refs.globalCache) === null || _c === void 0 ? void 0 : _c.enteredEditByTyping) !== true;
|
|
306
498
|
if (e.key === "Delete" || e.key === "Backspace") {
|
|
499
|
+
var anchor = formulaAnchorCellRef.current;
|
|
500
|
+
if (anchor != null) {
|
|
501
|
+
var anchorRow_2 = anchor[0],
|
|
502
|
+
anchorCol_2 = anchor[1];
|
|
503
|
+
skipNextAnchorSelectionSyncRef.current = true;
|
|
504
|
+
setTimeout(function () {
|
|
505
|
+
setContext(function (draftCtx) {
|
|
506
|
+
draftCtx.luckysheetCellUpdate = [anchorRow_2, anchorCol_2];
|
|
507
|
+
draftCtx.luckysheet_select_save = [{
|
|
508
|
+
row: [anchorRow_2, anchorRow_2],
|
|
509
|
+
column: [anchorCol_2, anchorCol_2],
|
|
510
|
+
row_focus: anchorRow_2,
|
|
511
|
+
column_focus: anchorCol_2
|
|
512
|
+
}];
|
|
513
|
+
(0, _fortuneCore.markRangeSelectionDirty)(draftCtx);
|
|
514
|
+
var el = refs.cellInput.current;
|
|
515
|
+
if (el && el.innerText.trim().startsWith("=")) {
|
|
516
|
+
(0, _fortuneCore.createRangeHightlight)(draftCtx, el.innerHTML);
|
|
517
|
+
(0, _fortuneCore.rangeHightlightselected)(draftCtx, el);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
}, 0);
|
|
521
|
+
}
|
|
307
522
|
if (isComposingRef.current) requestAnimationFrame(ensureNotEmpty);
|
|
308
523
|
if ((0, _helper.getCursorPosition)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
|
|
309
524
|
setTimeout(function () {
|
|
@@ -311,39 +526,8 @@ var InputBox = function InputBox() {
|
|
|
311
526
|
}, 5);
|
|
312
527
|
}
|
|
313
528
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
refCell = (0, _helper.decrementRow)(placeRef.current);
|
|
317
|
-
} else if (e.key === "ArrowDown") {
|
|
318
|
-
refCell = (0, _helper.incrementRow)(placeRef.current);
|
|
319
|
-
} else if (e.key === "ArrowLeft") {
|
|
320
|
-
refCell = (0, _helper.decrementColumn)(placeRef.current);
|
|
321
|
-
} else if (e.key === "ArrowRight") {
|
|
322
|
-
refCell = (0, _helper.incrementColumn)(placeRef.current);
|
|
323
|
-
}
|
|
324
|
-
if ((e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight") && !((0, _helper.getCursorPosition)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) !== (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length) && e.key === "ArrowRight")) {
|
|
325
|
-
var parser = new DOMParser();
|
|
326
|
-
var doc = parser.parseFromString("<div>".concat((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML, "</div>"), "text/html");
|
|
327
|
-
var spans = doc.querySelectorAll("span");
|
|
328
|
-
var lastSpan = spans[spans.length - 1];
|
|
329
|
-
var notFunctionInit = !((_b = document.getElementById("luckysheet-rich-text-editor")) === null || _b === void 0 ? void 0 : _b.innerText.includes("("));
|
|
330
|
-
var arrowRefNotAllowed = (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes(")")) || notFunctionInit && /^[a-zA-Z]+$/.test(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) && !_lodash.default.includes(["="], lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText);
|
|
331
|
-
if (((lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) === "(" || (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) === "," || (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes(":")) || (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) !== ")") && !(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes('"')) && !(0, _helper.isLetterNumberPattern)(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) && !arrowRefNotAllowed && !/^[a-zA-Z]+$/.test(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText)) {
|
|
332
|
-
allowListNavigation = false;
|
|
333
|
-
inputRef.current.innerHTML = "".concat(inputRef.current.innerHTML, "<span class=\"fortune-formula-functionrange-cell\" rangeindex=\"0\" dir=\"auto\" style=\"color:#c1232b;\">").concat(refCell, "</span>");
|
|
334
|
-
setTimeout(function () {
|
|
335
|
-
(0, _helper.moveCursorToEnd)(inputRef.current);
|
|
336
|
-
}, 1);
|
|
337
|
-
}
|
|
338
|
-
if ((0, _helper.isLetterNumberPattern)(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText)) {
|
|
339
|
-
allowListNavigation = false;
|
|
340
|
-
var htmlR = (0, _helper.removeLastSpan)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerHTML);
|
|
341
|
-
inputRef.current.innerHTML = "".concat(htmlR, "<span class=\"fortune-formula-functionrange-cell\" rangeindex=\"0\" dir=\"auto\" style=\"color:#c1232b;\">").concat(refCell, "</span>");
|
|
342
|
-
(0, _helper.moveCursorToEnd)(inputRef.current);
|
|
343
|
-
setTimeout(function () {
|
|
344
|
-
(0, _helper.moveCursorToEnd)(inputRef.current);
|
|
345
|
-
}, 1);
|
|
346
|
-
}
|
|
529
|
+
if (isArrowKey && (0, _fortuneCore.isFormulaReferenceInputMode)(context)) {
|
|
530
|
+
allowListNavigation = false;
|
|
347
531
|
}
|
|
348
532
|
if (e.key === "Escape" && context.luckysheetCellUpdate.length > 0) {
|
|
349
533
|
setContext(function (draftCtx) {
|
|
@@ -362,7 +546,7 @@ var InputBox = function InputBox() {
|
|
|
362
546
|
e.preventDefault();
|
|
363
547
|
} else if (e.key === "F4" && context.luckysheetCellUpdate.length > 0) {
|
|
364
548
|
e.preventDefault();
|
|
365
|
-
} else if (e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
|
|
549
|
+
} else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0 && allowListNavigation && !(e.shiftKey && isInPlaceEditMode)) {
|
|
366
550
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
367
551
|
var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
|
|
368
552
|
var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -381,7 +565,7 @@ var InputBox = function InputBox() {
|
|
|
381
565
|
}
|
|
382
566
|
}
|
|
383
567
|
e.preventDefault();
|
|
384
|
-
} else if (e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
|
|
568
|
+
} else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0 && allowListNavigation && !(e.shiftKey && isInPlaceEditMode)) {
|
|
385
569
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
386
570
|
var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
|
|
387
571
|
var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -399,7 +583,7 @@ var InputBox = function InputBox() {
|
|
|
399
583
|
}
|
|
400
584
|
e.preventDefault();
|
|
401
585
|
}
|
|
402
|
-
}, [clearSearchItemActiveClass, context.luckysheetCellUpdate.length, selectActiveFormula, setContext, firstSelection]);
|
|
586
|
+
}, [capturePreFormulaState, clearSearchItemActiveClass, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, selectActiveFormula, setContext, firstSelection, refs.cellInput]);
|
|
403
587
|
var handleHideShowHint = function handleHideShowHint() {
|
|
404
588
|
var _a, _b, _c, _d;
|
|
405
589
|
var searchElFx = (_a = document.getElementsByClassName("fx-search")) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -420,36 +604,62 @@ var InputBox = function InputBox() {
|
|
|
420
604
|
}
|
|
421
605
|
};
|
|
422
606
|
var onChange = (0, _react.useCallback)(function (__, isBlur) {
|
|
423
|
-
var _a;
|
|
607
|
+
var _a, _b, _c, _d, _e, _f;
|
|
424
608
|
if (context.isFlvReadOnly) return;
|
|
425
609
|
handleHideShowHint();
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
setShowSearchHint(false);
|
|
430
|
-
}
|
|
610
|
+
var editorText = (_c = (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : "";
|
|
611
|
+
setCellEditorIsFormula(editorText.startsWith("="));
|
|
612
|
+
setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)((_d = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) !== null && _d !== void 0 ? _d : null));
|
|
431
613
|
if (!isComposingRef.current) {
|
|
432
614
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
|
|
433
615
|
setCommaCount(currentCommaCount);
|
|
434
616
|
}
|
|
435
617
|
var e = lastKeyDownEventRef.current;
|
|
436
|
-
if (!e)
|
|
618
|
+
if (!e) {
|
|
619
|
+
var cellEl_1 = refs.cellInput.current;
|
|
620
|
+
if (cellEl_1 && (((_e = cellEl_1.innerText) === null || _e === void 0 ? void 0 : _e.trim().startsWith("=")) || ((_f = cellEl_1.textContent) === null || _f === void 0 ? void 0 : _f.trim().startsWith("=")))) {
|
|
621
|
+
setContext(function (draftCtx) {
|
|
622
|
+
if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) return;
|
|
623
|
+
(0, _fortuneCore.rangeHightlightselected)(draftCtx, cellEl_1);
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
437
628
|
var kcode = e.keyCode;
|
|
438
629
|
if (!kcode) return;
|
|
630
|
+
appendFormulaHistoryFromPrimaryEditor(function () {
|
|
631
|
+
return (0, _helper.getCursorPosition)(inputRef.current);
|
|
632
|
+
});
|
|
439
633
|
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) {
|
|
440
634
|
setContext(function (draftCtx) {
|
|
635
|
+
var _a, _b;
|
|
441
636
|
if ((draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start || (0, _fortuneCore.israngeseleciton)(draftCtx)) && isBlur) return;
|
|
442
637
|
if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) {
|
|
443
638
|
return;
|
|
444
639
|
}
|
|
445
|
-
(0, _fortuneCore.handleFormulaInput)(draftCtx, refs.fxInput.current, refs.cellInput.current, kcode,
|
|
640
|
+
(0, _fortuneCore.handleFormulaInput)(draftCtx, refs.fxInput.current, refs.cellInput.current, kcode, preTextRef.current);
|
|
641
|
+
var cellEl = refs.cellInput.current;
|
|
642
|
+
if (cellEl && (((_a = cellEl.innerText) === null || _a === void 0 ? void 0 : _a.trim().startsWith("=")) || ((_b = cellEl.textContent) === null || _b === void 0 ? void 0 : _b.trim().startsWith("=")))) {
|
|
643
|
+
(0, _fortuneCore.rangeHightlightselected)(draftCtx, cellEl);
|
|
644
|
+
}
|
|
446
645
|
});
|
|
447
646
|
}
|
|
448
|
-
}, [refs.cellInput, refs.fxInput, setContext]);
|
|
647
|
+
}, [refs.cellInput, refs.fxInput, setContext, appendFormulaHistoryFromPrimaryEditor]);
|
|
449
648
|
var onPaste = (0, _react.useCallback)(function (e) {
|
|
649
|
+
var plainText = e.clipboardData.getData("text/plain");
|
|
650
|
+
e.preventDefault();
|
|
450
651
|
if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
|
|
451
|
-
|
|
652
|
+
return;
|
|
452
653
|
}
|
|
654
|
+
document.execCommand("insertText", false, plainText);
|
|
655
|
+
}, [context.luckysheetCellUpdate]);
|
|
656
|
+
var onCopy = (0, _react.useCallback)(function (e) {
|
|
657
|
+
var _a;
|
|
658
|
+
if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) return;
|
|
659
|
+
e.preventDefault();
|
|
660
|
+
var sel = window.getSelection();
|
|
661
|
+
var text = sel && !sel.isCollapsed ? sel.toString() : e.currentTarget.innerText;
|
|
662
|
+
(_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(text).catch(function () {});
|
|
453
663
|
}, [context.luckysheetCellUpdate]);
|
|
454
664
|
var cfg = context.config || {};
|
|
455
665
|
var rowReadOnly = cfg.rowReadOnly || {};
|
|
@@ -489,7 +699,7 @@ var InputBox = function InputBox() {
|
|
|
489
699
|
zIndex: _lodash.default.isEmpty(context.luckysheetCellUpdate) ? -1 : 19,
|
|
490
700
|
display: "block"
|
|
491
701
|
};
|
|
492
|
-
}, [firstSelection, (
|
|
702
|
+
}, [firstSelection, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
|
|
493
703
|
(0, _react.useEffect)(function () {
|
|
494
704
|
var _a;
|
|
495
705
|
if (firstSelection && !((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) && !isInputBoxActive && !_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
|
|
@@ -505,7 +715,7 @@ var InputBox = function InputBox() {
|
|
|
505
715
|
setIsInputBoxActive(true);
|
|
506
716
|
}
|
|
507
717
|
}
|
|
508
|
-
}, [firstSelection, (
|
|
718
|
+
}, [firstSelection, (_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
|
|
509
719
|
var getAddressIndicatorPosition = (0, _react.useCallback)(function () {
|
|
510
720
|
var _a;
|
|
511
721
|
if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
|
|
@@ -518,7 +728,7 @@ var InputBox = function InputBox() {
|
|
|
518
728
|
left: "0",
|
|
519
729
|
display: "block"
|
|
520
730
|
};
|
|
521
|
-
}, [firstSelection, (
|
|
731
|
+
}, [firstSelection, (_g = context.rangeDialog) === null || _g === void 0 ? void 0 : _g.show]);
|
|
522
732
|
var getCellAddress = (0, _react.useCallback)(function () {
|
|
523
733
|
if (!firstSelection) return "";
|
|
524
734
|
var rowIndex = firstSelection.row_focus || 0;
|
|
@@ -534,6 +744,29 @@ var InputBox = function InputBox() {
|
|
|
534
744
|
setFirstSelectionActiveCell((_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]);
|
|
535
745
|
}
|
|
536
746
|
}, [isInputBoxActive]);
|
|
747
|
+
(0, _react.useLayoutEffect)(function () {
|
|
748
|
+
var _a;
|
|
749
|
+
var editing = context.luckysheetCellUpdate.length > 0;
|
|
750
|
+
if (!editing) {
|
|
751
|
+
scrollAtEditSessionStartRef.current = null;
|
|
752
|
+
setShowAddressIndicator(false);
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
var prevLen = (_a = prevCellUpdate === null || prevCellUpdate === void 0 ? void 0 : prevCellUpdate.length) !== null && _a !== void 0 ? _a : 0;
|
|
756
|
+
var startedThisCommit = prevLen === 0;
|
|
757
|
+
if (startedThisCommit || scrollAtEditSessionStartRef.current == null) {
|
|
758
|
+
scrollAtEditSessionStartRef.current = {
|
|
759
|
+
left: context.scrollLeft,
|
|
760
|
+
top: context.scrollTop
|
|
761
|
+
};
|
|
762
|
+
setShowAddressIndicator(false);
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
var b = scrollAtEditSessionStartRef.current;
|
|
766
|
+
if (context.scrollLeft !== b.left || context.scrollTop !== b.top) {
|
|
767
|
+
setShowAddressIndicator(true);
|
|
768
|
+
}
|
|
769
|
+
}, [context.luckysheetCellUpdate, context.scrollLeft, context.scrollTop, prevCellUpdate]);
|
|
537
770
|
(0, _react.useEffect)(function () {
|
|
538
771
|
var handleKeyDown = function handleKeyDown(event) {
|
|
539
772
|
if (event.key === "F10") {
|
|
@@ -568,15 +801,15 @@ var InputBox = function InputBox() {
|
|
|
568
801
|
};
|
|
569
802
|
});
|
|
570
803
|
setLinkSelectionHighlightRects(relative);
|
|
571
|
-
}, [(
|
|
804
|
+
}, [(_h = context.linkCard) === null || _h === void 0 ? void 0 : _h.applyToSelection, (_j = context.linkCard) === null || _j === void 0 ? void 0 : _j.selectionOffsets, (_k = context.linkCard) === null || _k === void 0 ? void 0 : _k.r, (_l = context.linkCard) === null || _l === void 0 ? void 0 : _l.c, context.luckysheetCellUpdate]);
|
|
572
805
|
var wraperGetCell = function wraperGetCell() {
|
|
573
806
|
var cell = getCellAddress();
|
|
574
|
-
placeRef.current = cell;
|
|
575
807
|
if (activeRefCell !== cell) {
|
|
576
808
|
setActiveRefCell(cell);
|
|
577
809
|
}
|
|
578
810
|
return activeCell || cell;
|
|
579
811
|
};
|
|
812
|
+
(0, _useRerenderOnFormulaCaret.useRerenderOnFormulaCaret)(inputRef, context.luckysheetCellUpdate.length > 0);
|
|
580
813
|
var getFunctionNameFromInput = (0, _react.useCallback)(function () {
|
|
581
814
|
var _a, _b;
|
|
582
815
|
var inputText = ((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) || "";
|
|
@@ -593,8 +826,10 @@ var InputBox = function InputBox() {
|
|
|
593
826
|
}
|
|
594
827
|
return null;
|
|
595
828
|
}, []);
|
|
596
|
-
var functionName = context.functionHint
|
|
829
|
+
var functionName = (_o = (_m = (0, _helper.getFunctionNameFromFormulaCaretSpans)(inputRef.current)) !== null && _m !== void 0 ? _m : context.functionHint) !== null && _o !== void 0 ? _o : getFunctionNameFromInput();
|
|
597
830
|
var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
|
|
831
|
+
var showCellFormulaChrome = context.luckysheetCellUpdate.length > 0 && (0, _fortuneCore.getFormulaEditorOwner)(context) === "cell";
|
|
832
|
+
var inputBoxBaseSelection = isInputBoxActive && firstSelectionActiveCell ? firstSelectionActiveCell : firstSelection;
|
|
598
833
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
599
834
|
className: "luckysheet-input-box",
|
|
600
835
|
id: "luckysheet-input-box",
|
|
@@ -605,16 +840,16 @@ var InputBox = function InputBox() {
|
|
|
605
840
|
onMouseUp: function onMouseUp(e) {
|
|
606
841
|
return e.stopPropagation();
|
|
607
842
|
}
|
|
608
|
-
}, firstSelection && !((
|
|
843
|
+
}, firstSelection && !((_p = context.rangeDialog) === null || _p === void 0 ? void 0 : _p.show) && showAddressIndicator && (/*#__PURE__*/_react.default.createElement("div", {
|
|
609
844
|
className: "luckysheet-cell-address-indicator",
|
|
610
845
|
style: getAddressIndicatorPosition()
|
|
611
846
|
}, wraperGetCell())), /*#__PURE__*/_react.default.createElement("div", {
|
|
612
847
|
ref: inputBoxInnerRef,
|
|
613
848
|
className: "luckysheet-input-box-inner",
|
|
614
|
-
style:
|
|
849
|
+
style: inputBoxBaseSelection ? __assign({
|
|
615
850
|
position: "relative",
|
|
616
|
-
minWidth:
|
|
617
|
-
minHeight:
|
|
851
|
+
minWidth: inputBoxBaseSelection.width,
|
|
852
|
+
minHeight: inputBoxBaseSelection.height
|
|
618
853
|
}, inputBoxStyle) : {
|
|
619
854
|
position: "relative"
|
|
620
855
|
}
|
|
@@ -635,10 +870,23 @@ var InputBox = function InputBox() {
|
|
|
635
870
|
},
|
|
636
871
|
onMouseUp: function onMouseUp() {
|
|
637
872
|
handleHideShowHint();
|
|
873
|
+
setContext(function (draftCtx) {
|
|
874
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "cell");
|
|
875
|
+
});
|
|
638
876
|
if (!isComposingRef.current) {
|
|
639
877
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
|
|
640
878
|
setCommaCount(currentCommaCount);
|
|
641
879
|
}
|
|
880
|
+
var editor = inputRef.current;
|
|
881
|
+
if (!editor) return;
|
|
882
|
+
setContext(function (draftCtx) {
|
|
883
|
+
if (draftCtx.formulaCache.rangeSelectionActive !== true) return;
|
|
884
|
+
var clickedInsideManagedRange = (0, _fortuneCore.getFormulaRangeIndexAtCaret)(editor) !== null;
|
|
885
|
+
var atValidInsertionPoint = (0, _fortuneCore.isCaretAtValidFormulaRangeInsertionPoint)(editor);
|
|
886
|
+
if (clickedInsideManagedRange || !atValidInsertionPoint) {
|
|
887
|
+
(0, _fortuneCore.markRangeSelectionDirty)(draftCtx);
|
|
888
|
+
}
|
|
889
|
+
});
|
|
642
890
|
},
|
|
643
891
|
innerRef: function innerRef(e) {
|
|
644
892
|
inputRef.current = e;
|
|
@@ -657,6 +905,7 @@ var InputBox = function InputBox() {
|
|
|
657
905
|
onChange: onChange,
|
|
658
906
|
onKeyDown: onKeyDown,
|
|
659
907
|
onPaste: onPaste,
|
|
908
|
+
onCopy: onCopy,
|
|
660
909
|
allowEdit: edit ? !isHidenRC : edit
|
|
661
910
|
}), linkSelectionHighlightRects.length > 0 && (/*#__PURE__*/_react.default.createElement("div", {
|
|
662
911
|
className: "luckysheet-input-box-link-selection-highlight",
|
|
@@ -681,7 +930,7 @@ var InputBox = function InputBox() {
|
|
|
681
930
|
backgroundColor: "rgba(0, 123, 255, 0.25)"
|
|
682
931
|
}
|
|
683
932
|
});
|
|
684
|
-
})))), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0 || fn) && (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaSearch.default, {
|
|
933
|
+
})))), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0 || fn) && showCellFormulaChrome && (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaSearch.default, {
|
|
685
934
|
onMouseMove: function onMouseMove(e) {
|
|
686
935
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
687
936
|
var hoveredItem = e.target.closest(".luckysheet-formula-search-item");
|
|
@@ -696,12 +945,12 @@ var InputBox = function InputBox() {
|
|
|
696
945
|
}
|
|
697
946
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
698
947
|
className: "cell-hint"
|
|
699
|
-
}, showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
948
|
+
}, showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
700
949
|
handleShowFormulaHint: handleShowFormulaHint,
|
|
701
950
|
showFormulaHint: showFormulaHint,
|
|
702
951
|
commaCount: commaCount,
|
|
703
952
|
functionName: functionName
|
|
704
|
-
})), !showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
|
|
953
|
+
})), !showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
|
|
705
954
|
text: "Turn on formula suggestions (F10)",
|
|
706
955
|
placement: "top",
|
|
707
956
|
defaultOpen: true,
|