@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
|
@@ -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, _m, _o;
|
|
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 _q = (0, _react.useState)(false),
|
|
42
|
-
isHidenRC = _q[0],
|
|
43
|
-
setIsHidenRC = _q[1];
|
|
44
44
|
var _r = (0, _react.useState)(false),
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var _s = (0, _react.useState)(
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
isHidenRC = _r[0],
|
|
46
|
+
setIsHidenRC = _r[1];
|
|
47
|
+
var _s = (0, _react.useState)(false),
|
|
48
|
+
isInputBoxActive = _s[0],
|
|
49
|
+
setIsInputBoxActive = _s[1];
|
|
50
50
|
var _t = (0, _react.useState)(""),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var _u = (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,12 +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
|
-
|
|
142
|
-
var overwriteFirstChar = refs.globalCache.overwriteCellFirstChar;
|
|
143
|
-
if (cell && !refs.globalCache.overwriteCell) {
|
|
171
|
+
if (cell && !overwrite) {
|
|
144
172
|
if ((0, _fortuneCore.isInlineStringCell)(cell)) {
|
|
145
173
|
value_1 = (0, _fortuneCore.getInlineStringHTML)(row_index, col_index, flowdata);
|
|
146
174
|
} else if (cell.f) {
|
|
@@ -156,20 +184,20 @@ var InputBox = function InputBox() {
|
|
|
156
184
|
}
|
|
157
185
|
}
|
|
158
186
|
refs.globalCache.overwriteCell = false;
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
inputRef.current.innerText = overwriteFirstChar !== null && overwriteFirstChar !== void 0 ? overwriteFirstChar : "";
|
|
162
|
-
if (overwriteFirstChar) {
|
|
163
|
-
(0, _fortuneCore.moveToEnd)(inputRef.current);
|
|
164
|
-
}
|
|
165
|
-
} else if (!refs.globalCache.ignoreWriteCell && inputRef.current && value_1) {
|
|
187
|
+
var wroteEditorFromStoredCell = false;
|
|
188
|
+
if (!refs.globalCache.ignoreWriteCell && inputRef.current && value_1) {
|
|
166
189
|
inputRef.current.innerHTML = (0, _fortuneCore.escapeHTMLTag)((0, _fortuneCore.escapeScriptTag)(value_1));
|
|
167
|
-
|
|
190
|
+
wroteEditorFromStoredCell = true;
|
|
191
|
+
} else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1 && !overwrite) {
|
|
168
192
|
var valueD = (0, _fortuneCore.getCellValue)(row_index, col_index, flowdata, "f");
|
|
169
193
|
inputRef.current.innerText = valueD;
|
|
194
|
+
wroteEditorFromStoredCell = true;
|
|
170
195
|
}
|
|
171
196
|
refs.globalCache.ignoreWriteCell = false;
|
|
172
|
-
if (
|
|
197
|
+
if (inputRef.current) {
|
|
198
|
+
setCellEditorIsFormula(inputRef.current.innerText.trim().startsWith("="));
|
|
199
|
+
}
|
|
200
|
+
if (wroteEditorFromStoredCell && !refs.globalCache.doNotFocus) {
|
|
173
201
|
setTimeout(function () {
|
|
174
202
|
(0, _fortuneCore.moveToEnd)(inputRef.current);
|
|
175
203
|
});
|
|
@@ -182,8 +210,43 @@ var InputBox = function InputBox() {
|
|
|
182
210
|
if (inputRef.current) {
|
|
183
211
|
inputRef.current.innerHTML = "";
|
|
184
212
|
}
|
|
213
|
+
delete refs.globalCache.pendingTypeOverCell;
|
|
214
|
+
setCellEditorIsFormula(false);
|
|
215
|
+
resetFormulaHistory();
|
|
185
216
|
}
|
|
186
|
-
}, [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]);
|
|
187
250
|
(0, _react.useEffect)(function () {
|
|
188
251
|
setIsHidenRC((0, _fortuneCore.isShowHidenCR)(context));
|
|
189
252
|
}, [context.luckysheet_select_save]);
|
|
@@ -192,66 +255,46 @@ var InputBox = function InputBox() {
|
|
|
192
255
|
if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) || _lodash.default.isEmpty(context.luckysheetCellUpdate)) {
|
|
193
256
|
setIsInputBoxActive(false);
|
|
194
257
|
}
|
|
195
|
-
}, [firstSelection, (
|
|
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]);
|
|
196
276
|
var getActiveFormula = (0, _react.useCallback)(function () {
|
|
197
277
|
return document.querySelector(".luckysheet-formula-search-item-active");
|
|
198
278
|
}, []);
|
|
199
279
|
var insertSelectedFormula = (0, _react.useCallback)(function (formulaName) {
|
|
200
|
-
var
|
|
201
|
-
if (/^=[a-zA-Z]+$/.test(inputRef.current.innerText)) {
|
|
202
|
-
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>");
|
|
203
|
-
inputRef.current.innerHTML = ht;
|
|
204
|
-
var fxEditor = document.getElementById("luckysheet-functionbox-cell");
|
|
205
|
-
if (fxEditor) {
|
|
206
|
-
fxEditor.innerHTML = ht;
|
|
207
|
-
}
|
|
208
|
-
(0, _helper.moveCursorToEnd)(inputRef.current);
|
|
209
|
-
setContext(function (draftCtx) {
|
|
210
|
-
draftCtx.functionCandidates = [];
|
|
211
|
-
draftCtx.defaultCandidates = [];
|
|
212
|
-
draftCtx.functionHint = formulaName;
|
|
213
|
-
});
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
var textEditor = document.getElementById("luckysheet-rich-text-editor");
|
|
280
|
+
var textEditor = inputRef.current;
|
|
217
281
|
if (!textEditor) return;
|
|
218
|
-
|
|
219
|
-
var
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
var deleteCount = searchTxt === "=" ? 0 : searchTxt.length;
|
|
231
|
-
if (deleteCount > 0 && range.startContainer.nodeType === Node.TEXT_NODE && textEditor.contains(range.startContainer)) {
|
|
232
|
-
var startOffset = Math.max(range.startOffset - deleteCount, 0);
|
|
233
|
-
var endOffset = range.startOffset;
|
|
234
|
-
range.setStart(range.startContainer, startOffset);
|
|
235
|
-
range.setEnd(range.startContainer, endOffset);
|
|
236
|
-
range.deleteContents();
|
|
237
|
-
}
|
|
238
|
-
textEditor.querySelectorAll(".luckysheet-formula-text-func, .luckysheet-formula-text-lpar").forEach(function (el) {
|
|
239
|
-
return el.remove();
|
|
240
|
-
});
|
|
241
|
-
var funcNode = new DOMParser().parseFromString("<span dir=\"auto\" class=\"luckysheet-formula-text-func\">".concat(formulaName, "</span>"), "text/html").body.firstChild;
|
|
242
|
-
var parNode = new DOMParser().parseFromString("<span dir=\"auto\" class=\"luckysheet-formula-text-lpar\">(</span>", "text/html").body.firstChild;
|
|
243
|
-
if (range && parNode && funcNode) {
|
|
244
|
-
range.insertNode(funcNode);
|
|
245
|
-
range.collapse(false);
|
|
246
|
-
range.insertNode(parNode);
|
|
247
|
-
range.collapse(false);
|
|
248
|
-
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
249
|
-
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
|
250
|
-
}
|
|
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));
|
|
251
294
|
setContext(function (draftCtx) {
|
|
252
295
|
draftCtx.functionCandidates = [];
|
|
253
296
|
draftCtx.defaultCandidates = [];
|
|
254
|
-
draftCtx.functionHint = formulaName;
|
|
297
|
+
draftCtx.functionHint = (formulaName || "").toUpperCase();
|
|
255
298
|
});
|
|
256
299
|
}, [setContext]);
|
|
257
300
|
var clearSearchItemActiveClass = (0, _react.useCallback)(function () {
|
|
@@ -274,7 +317,7 @@ var InputBox = function InputBox() {
|
|
|
274
317
|
var _a, _b;
|
|
275
318
|
if (isComposingRef.current || !inputRef.current) return;
|
|
276
319
|
if (e.target.className.includes("sign-fortune")) return;
|
|
277
|
-
|
|
320
|
+
preTextRef.current = inputRef.current.innerText;
|
|
278
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;
|
|
279
322
|
var lastSpanText = getLastInputSpanText();
|
|
280
323
|
if (formulaName && !(0, _helper.isLetterNumberPattern)(lastSpanText)) {
|
|
@@ -288,58 +331,149 @@ var InputBox = function InputBox() {
|
|
|
288
331
|
event.preventDefault();
|
|
289
332
|
};
|
|
290
333
|
(0, _react.useEffect)(function () {
|
|
291
|
-
var _a
|
|
292
|
-
var
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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) {
|
|
331
399
|
return;
|
|
332
400
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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]);
|
|
338
416
|
var onKeyDown = (0, _react.useCallback)(function (e) {
|
|
339
|
-
var _a, _b;
|
|
417
|
+
var _a, _b, _c;
|
|
418
|
+
setContext(function (draftCtx) {
|
|
419
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "cell");
|
|
420
|
+
});
|
|
340
421
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
341
|
-
|
|
342
|
-
|
|
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
|
+
}
|
|
343
477
|
if (e.code === "KeyB") {
|
|
344
478
|
(0, _fortuneCore.handleBold)(context, inputRef.current);
|
|
345
479
|
stopPropagation(e);
|
|
@@ -359,7 +493,32 @@ var InputBox = function InputBox() {
|
|
|
359
493
|
setCommaCount(currentCommaCount);
|
|
360
494
|
}
|
|
361
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;
|
|
362
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
|
+
}
|
|
363
522
|
if (isComposingRef.current) requestAnimationFrame(ensureNotEmpty);
|
|
364
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)) {
|
|
365
524
|
setTimeout(function () {
|
|
@@ -367,20 +526,8 @@ var InputBox = function InputBox() {
|
|
|
367
526
|
}, 5);
|
|
368
527
|
}
|
|
369
528
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
var editorText = ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) || "";
|
|
373
|
-
var lastSpanText = getLastInputSpanText() || "";
|
|
374
|
-
var isA1RangePattern = /^[a-zA-Z]+\d+:[a-zA-Z]+\d+$/.test(lastSpanText);
|
|
375
|
-
var notFunctionInit = !editorText.includes("(");
|
|
376
|
-
var refNotAllowed = lastSpanText.includes(")") || notFunctionInit && /^[a-zA-Z]+$/.test(lastSpanText) && !_lodash.default.includes(["="], lastSpanText);
|
|
377
|
-
var shouldTreatAsRefNavigation = editorText.startsWith("=") && (Boolean((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.querySelector(".fortune-formula-functionrange-cell")) || (0, _helper.isLetterNumberPattern)(lastSpanText) || isA1RangePattern || (lastSpanText === "(" || lastSpanText === "," || lastSpanText.includes(":") || lastSpanText === "=") && !lastSpanText.includes('"') && !refNotAllowed && !/^[a-zA-Z]+$/.test(lastSpanText));
|
|
378
|
-
if (shouldTreatAsRefNavigation) {
|
|
379
|
-
allowListNavigation = false;
|
|
380
|
-
setTimeout(function () {
|
|
381
|
-
if (inputRef.current) (0, _helper.moveCursorToEnd)(inputRef.current);
|
|
382
|
-
}, 1);
|
|
383
|
-
}
|
|
529
|
+
if (isArrowKey && (0, _fortuneCore.isFormulaReferenceInputMode)(context)) {
|
|
530
|
+
allowListNavigation = false;
|
|
384
531
|
}
|
|
385
532
|
if (e.key === "Escape" && context.luckysheetCellUpdate.length > 0) {
|
|
386
533
|
setContext(function (draftCtx) {
|
|
@@ -399,7 +546,7 @@ var InputBox = function InputBox() {
|
|
|
399
546
|
e.preventDefault();
|
|
400
547
|
} else if (e.key === "F4" && context.luckysheetCellUpdate.length > 0) {
|
|
401
548
|
e.preventDefault();
|
|
402
|
-
} 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)) {
|
|
403
550
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
404
551
|
var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
|
|
405
552
|
var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -418,7 +565,7 @@ var InputBox = function InputBox() {
|
|
|
418
565
|
}
|
|
419
566
|
}
|
|
420
567
|
e.preventDefault();
|
|
421
|
-
} 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)) {
|
|
422
569
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
423
570
|
var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
|
|
424
571
|
var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -436,7 +583,7 @@ var InputBox = function InputBox() {
|
|
|
436
583
|
}
|
|
437
584
|
e.preventDefault();
|
|
438
585
|
}
|
|
439
|
-
}, [clearSearchItemActiveClass, context.luckysheetCellUpdate.length, selectActiveFormula, setContext]);
|
|
586
|
+
}, [capturePreFormulaState, clearSearchItemActiveClass, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, selectActiveFormula, setContext, firstSelection, refs.cellInput]);
|
|
440
587
|
var handleHideShowHint = function handleHideShowHint() {
|
|
441
588
|
var _a, _b, _c, _d;
|
|
442
589
|
var searchElFx = (_a = document.getElementsByClassName("fx-search")) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -457,36 +604,62 @@ var InputBox = function InputBox() {
|
|
|
457
604
|
}
|
|
458
605
|
};
|
|
459
606
|
var onChange = (0, _react.useCallback)(function (__, isBlur) {
|
|
460
|
-
var _a;
|
|
607
|
+
var _a, _b, _c, _d, _e, _f;
|
|
461
608
|
if (context.isFlvReadOnly) return;
|
|
462
609
|
handleHideShowHint();
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
setShowSearchHint(false);
|
|
467
|
-
}
|
|
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));
|
|
468
613
|
if (!isComposingRef.current) {
|
|
469
614
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
|
|
470
615
|
setCommaCount(currentCommaCount);
|
|
471
616
|
}
|
|
472
617
|
var e = lastKeyDownEventRef.current;
|
|
473
|
-
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
|
+
}
|
|
474
628
|
var kcode = e.keyCode;
|
|
475
629
|
if (!kcode) return;
|
|
630
|
+
appendFormulaHistoryFromPrimaryEditor(function () {
|
|
631
|
+
return (0, _helper.getCursorPosition)(inputRef.current);
|
|
632
|
+
});
|
|
476
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) {
|
|
477
634
|
setContext(function (draftCtx) {
|
|
635
|
+
var _a, _b;
|
|
478
636
|
if ((draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start || (0, _fortuneCore.israngeseleciton)(draftCtx)) && isBlur) return;
|
|
479
637
|
if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) {
|
|
480
638
|
return;
|
|
481
639
|
}
|
|
482
|
-
(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
|
+
}
|
|
483
645
|
});
|
|
484
646
|
}
|
|
485
|
-
}, [refs.cellInput, refs.fxInput, setContext]);
|
|
647
|
+
}, [refs.cellInput, refs.fxInput, setContext, appendFormulaHistoryFromPrimaryEditor]);
|
|
486
648
|
var onPaste = (0, _react.useCallback)(function (e) {
|
|
649
|
+
var plainText = e.clipboardData.getData("text/plain");
|
|
650
|
+
e.preventDefault();
|
|
487
651
|
if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
|
|
488
|
-
|
|
652
|
+
return;
|
|
489
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 () {});
|
|
490
663
|
}, [context.luckysheetCellUpdate]);
|
|
491
664
|
var cfg = context.config || {};
|
|
492
665
|
var rowReadOnly = cfg.rowReadOnly || {};
|
|
@@ -526,7 +699,7 @@ var InputBox = function InputBox() {
|
|
|
526
699
|
zIndex: _lodash.default.isEmpty(context.luckysheetCellUpdate) ? -1 : 19,
|
|
527
700
|
display: "block"
|
|
528
701
|
};
|
|
529
|
-
}, [firstSelection, (
|
|
702
|
+
}, [firstSelection, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
|
|
530
703
|
(0, _react.useEffect)(function () {
|
|
531
704
|
var _a;
|
|
532
705
|
if (firstSelection && !((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) && !isInputBoxActive && !_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
|
|
@@ -542,7 +715,7 @@ var InputBox = function InputBox() {
|
|
|
542
715
|
setIsInputBoxActive(true);
|
|
543
716
|
}
|
|
544
717
|
}
|
|
545
|
-
}, [firstSelection, (
|
|
718
|
+
}, [firstSelection, (_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
|
|
546
719
|
var getAddressIndicatorPosition = (0, _react.useCallback)(function () {
|
|
547
720
|
var _a;
|
|
548
721
|
if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
|
|
@@ -555,7 +728,7 @@ var InputBox = function InputBox() {
|
|
|
555
728
|
left: "0",
|
|
556
729
|
display: "block"
|
|
557
730
|
};
|
|
558
|
-
}, [firstSelection, (
|
|
731
|
+
}, [firstSelection, (_g = context.rangeDialog) === null || _g === void 0 ? void 0 : _g.show]);
|
|
559
732
|
var getCellAddress = (0, _react.useCallback)(function () {
|
|
560
733
|
if (!firstSelection) return "";
|
|
561
734
|
var rowIndex = firstSelection.row_focus || 0;
|
|
@@ -571,6 +744,29 @@ var InputBox = function InputBox() {
|
|
|
571
744
|
setFirstSelectionActiveCell((_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]);
|
|
572
745
|
}
|
|
573
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]);
|
|
574
770
|
(0, _react.useEffect)(function () {
|
|
575
771
|
var handleKeyDown = function handleKeyDown(event) {
|
|
576
772
|
if (event.key === "F10") {
|
|
@@ -605,15 +801,15 @@ var InputBox = function InputBox() {
|
|
|
605
801
|
};
|
|
606
802
|
});
|
|
607
803
|
setLinkSelectionHighlightRects(relative);
|
|
608
|
-
}, [(
|
|
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]);
|
|
609
805
|
var wraperGetCell = function wraperGetCell() {
|
|
610
806
|
var cell = getCellAddress();
|
|
611
|
-
placeRef.current = cell;
|
|
612
807
|
if (activeRefCell !== cell) {
|
|
613
808
|
setActiveRefCell(cell);
|
|
614
809
|
}
|
|
615
810
|
return activeCell || cell;
|
|
616
811
|
};
|
|
812
|
+
(0, _useRerenderOnFormulaCaret.useRerenderOnFormulaCaret)(inputRef, context.luckysheetCellUpdate.length > 0);
|
|
617
813
|
var getFunctionNameFromInput = (0, _react.useCallback)(function () {
|
|
618
814
|
var _a, _b;
|
|
619
815
|
var inputText = ((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) || "";
|
|
@@ -630,8 +826,10 @@ var InputBox = function InputBox() {
|
|
|
630
826
|
}
|
|
631
827
|
return null;
|
|
632
828
|
}, []);
|
|
633
|
-
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();
|
|
634
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;
|
|
635
833
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
636
834
|
className: "luckysheet-input-box",
|
|
637
835
|
id: "luckysheet-input-box",
|
|
@@ -642,16 +840,16 @@ var InputBox = function InputBox() {
|
|
|
642
840
|
onMouseUp: function onMouseUp(e) {
|
|
643
841
|
return e.stopPropagation();
|
|
644
842
|
}
|
|
645
|
-
}, firstSelection && !((
|
|
843
|
+
}, firstSelection && !((_p = context.rangeDialog) === null || _p === void 0 ? void 0 : _p.show) && showAddressIndicator && (/*#__PURE__*/_react.default.createElement("div", {
|
|
646
844
|
className: "luckysheet-cell-address-indicator",
|
|
647
845
|
style: getAddressIndicatorPosition()
|
|
648
846
|
}, wraperGetCell())), /*#__PURE__*/_react.default.createElement("div", {
|
|
649
847
|
ref: inputBoxInnerRef,
|
|
650
848
|
className: "luckysheet-input-box-inner",
|
|
651
|
-
style:
|
|
849
|
+
style: inputBoxBaseSelection ? __assign({
|
|
652
850
|
position: "relative",
|
|
653
|
-
minWidth:
|
|
654
|
-
minHeight:
|
|
851
|
+
minWidth: inputBoxBaseSelection.width,
|
|
852
|
+
minHeight: inputBoxBaseSelection.height
|
|
655
853
|
}, inputBoxStyle) : {
|
|
656
854
|
position: "relative"
|
|
657
855
|
}
|
|
@@ -672,10 +870,23 @@ var InputBox = function InputBox() {
|
|
|
672
870
|
},
|
|
673
871
|
onMouseUp: function onMouseUp() {
|
|
674
872
|
handleHideShowHint();
|
|
873
|
+
setContext(function (draftCtx) {
|
|
874
|
+
(0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "cell");
|
|
875
|
+
});
|
|
675
876
|
if (!isComposingRef.current) {
|
|
676
877
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
|
|
677
878
|
setCommaCount(currentCommaCount);
|
|
678
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
|
+
});
|
|
679
890
|
},
|
|
680
891
|
innerRef: function innerRef(e) {
|
|
681
892
|
inputRef.current = e;
|
|
@@ -694,6 +905,7 @@ var InputBox = function InputBox() {
|
|
|
694
905
|
onChange: onChange,
|
|
695
906
|
onKeyDown: onKeyDown,
|
|
696
907
|
onPaste: onPaste,
|
|
908
|
+
onCopy: onCopy,
|
|
697
909
|
allowEdit: edit ? !isHidenRC : edit
|
|
698
910
|
}), linkSelectionHighlightRects.length > 0 && (/*#__PURE__*/_react.default.createElement("div", {
|
|
699
911
|
className: "luckysheet-input-box-link-selection-highlight",
|
|
@@ -718,7 +930,7 @@ var InputBox = function InputBox() {
|
|
|
718
930
|
backgroundColor: "rgba(0, 123, 255, 0.25)"
|
|
719
931
|
}
|
|
720
932
|
});
|
|
721
|
-
})))), (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, {
|
|
722
934
|
onMouseMove: function onMouseMove(e) {
|
|
723
935
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
724
936
|
var hoveredItem = e.target.closest(".luckysheet-formula-search-item");
|
|
@@ -733,12 +945,12 @@ var InputBox = function InputBox() {
|
|
|
733
945
|
}
|
|
734
946
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
735
947
|
className: "cell-hint"
|
|
736
|
-
}, showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
948
|
+
}, showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
737
949
|
handleShowFormulaHint: handleShowFormulaHint,
|
|
738
950
|
showFormulaHint: showFormulaHint,
|
|
739
951
|
commaCount: commaCount,
|
|
740
952
|
functionName: functionName
|
|
741
|
-
})), !showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
|
|
953
|
+
})), !showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
|
|
742
954
|
text: "Turn on formula suggestions (F10)",
|
|
743
955
|
placement: "top",
|
|
744
956
|
defaultOpen: true,
|