@fileverse-dev/fortune-react 1.3.10 → 1.3.11-input-ref
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/FxEditor/index.js +12 -6
- package/es/components/SheetOverlay/InputBox.js +243 -130
- package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +25 -1
- package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +26 -2
- package/es/components/SheetOverlay/helper.d.ts +5 -0
- package/es/components/SheetOverlay/helper.js +52 -0
- package/es/components/Workbook/index.js +139 -9
- package/es/utils/convertCellsToCrypto.js +17 -0
- package/lib/components/FxEditor/index.js +10 -4
- package/lib/components/SheetOverlay/InputBox.js +241 -128
- package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +25 -1
- package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +26 -2
- package/lib/components/SheetOverlay/helper.d.ts +5 -0
- package/lib/components/SheetOverlay/helper.js +54 -0
- package/lib/components/Workbook/index.js +140 -10
- package/lib/utils/convertCellsToCrypto.js +17 -0
- package/package.json +2 -2
|
@@ -29,57 +29,59 @@ var __assign = void 0 && (void 0).__assign || function () {
|
|
|
29
29
|
return __assign.apply(this, arguments);
|
|
30
30
|
};
|
|
31
31
|
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 =
|
|
32
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
33
|
+
var _o = (0, _react.useContext)(_context.default),
|
|
34
|
+
context = _o.context,
|
|
35
|
+
setContext = _o.setContext,
|
|
36
|
+
refs = _o.refs;
|
|
37
37
|
var inputRef = (0, _react.useRef)(null);
|
|
38
38
|
var lastKeyDownEventRef = (0, _react.useRef)(null);
|
|
39
39
|
var prevCellUpdate = (0, _usePrevious.default)(context.luckysheetCellUpdate);
|
|
40
40
|
var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
|
|
41
|
-
var _o = (0, _react.useState)(false),
|
|
42
|
-
isHidenRC = _o[0],
|
|
43
|
-
setIsHidenRC = _o[1];
|
|
44
41
|
var _p = (0, _react.useState)(false),
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var _q = (0, _react.useState)(
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
isHidenRC = _p[0],
|
|
43
|
+
setIsHidenRC = _p[1];
|
|
44
|
+
var _q = (0, _react.useState)(false),
|
|
45
|
+
isInputBoxActive = _q[0],
|
|
46
|
+
setIsInputBoxActive = _q[1];
|
|
50
47
|
var _r = (0, _react.useState)(""),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var _s = (0, _react.useState)(
|
|
48
|
+
activeCell = _r[0],
|
|
49
|
+
setActiveCell = _r[1];
|
|
50
|
+
var _s = (0, _react.useState)(""),
|
|
51
|
+
activeRefCell = _s[0],
|
|
52
|
+
setActiveRefCell = _s[1];
|
|
53
|
+
var _t = (0, _react.useState)({
|
|
54
54
|
left: 0,
|
|
55
55
|
top: 0
|
|
56
56
|
}),
|
|
57
|
-
frozenPosition =
|
|
58
|
-
setFrozenPosition =
|
|
57
|
+
frozenPosition = _t[0],
|
|
58
|
+
setFrozenPosition = _t[1];
|
|
59
59
|
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 =
|
|
60
|
+
var _u = (0, _react.useState)({}),
|
|
61
|
+
firstSelectionActiveCell = _u[0],
|
|
62
|
+
setFirstSelectionActiveCell = _u[1];
|
|
63
|
+
var _v = (0, _react.useState)(0),
|
|
64
|
+
commaCount = _v[0],
|
|
65
|
+
setCommaCount = _v[1];
|
|
66
66
|
var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
|
|
67
|
-
var
|
|
68
|
-
showFormulaHint =
|
|
69
|
-
setShowFormulaHint =
|
|
70
|
-
var
|
|
71
|
-
showSearchHint =
|
|
72
|
-
setShowSearchHint =
|
|
67
|
+
var _w = (0, _react.useState)(!hideFormulaHintLocal),
|
|
68
|
+
showFormulaHint = _w[0],
|
|
69
|
+
setShowFormulaHint = _w[1];
|
|
70
|
+
var _x = (0, _react.useState)(false),
|
|
71
|
+
showSearchHint = _x[0],
|
|
72
|
+
setShowSearchHint = _x[1];
|
|
73
73
|
var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
|
|
74
74
|
var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
|
|
75
75
|
var preText = (0, _react.useRef)("");
|
|
76
|
-
var placeRef = (0, _react.useRef)("");
|
|
77
76
|
var isComposingRef = (0, _react.useRef)(false);
|
|
77
|
+
var formulaAnchorCellRef = (0, _react.useRef)(null);
|
|
78
|
+
var skipNextAnchorSelectionSyncRef = (0, _react.useRef)(false);
|
|
79
|
+
var lastHandledMouseDragSignatureRef = (0, _react.useRef)("");
|
|
78
80
|
var ZWSP = "\u200B";
|
|
79
81
|
var inputBoxInnerRef = (0, _react.useRef)(null);
|
|
80
|
-
var
|
|
81
|
-
linkSelectionHighlightRects =
|
|
82
|
-
setLinkSelectionHighlightRects =
|
|
82
|
+
var _y = (0, _react.useState)([]),
|
|
83
|
+
linkSelectionHighlightRects = _y[0],
|
|
84
|
+
setLinkSelectionHighlightRects = _y[1];
|
|
83
85
|
var ensureNotEmpty = function ensureNotEmpty() {
|
|
84
86
|
var el = inputRef.current;
|
|
85
87
|
if (!el) return;
|
|
@@ -176,6 +178,34 @@ var InputBox = function InputBox() {
|
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
}, [context.luckysheetCellUpdate]);
|
|
181
|
+
(0, _react.useEffect)(function () {
|
|
182
|
+
var _a;
|
|
183
|
+
if (_lodash.default.isEmpty(context.luckysheetCellUpdate) || !refs.cellInput.current) {
|
|
184
|
+
formulaAnchorCellRef.current = null;
|
|
185
|
+
lastHandledMouseDragSignatureRef.current = "";
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
var inputText = ((_a = refs.cellInput.current.innerText) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
189
|
+
if (!inputText.startsWith("=")) {
|
|
190
|
+
formulaAnchorCellRef.current = null;
|
|
191
|
+
lastHandledMouseDragSignatureRef.current = "";
|
|
192
|
+
}
|
|
193
|
+
}, [context.luckysheetCellUpdate, refs.cellInput]);
|
|
194
|
+
(0, _react.useEffect)(function () {
|
|
195
|
+
if (_lodash.default.isEmpty(context.luckysheetCellUpdate) || _lodash.default.isEmpty(prevCellUpdate) || _lodash.default.isEqual(prevCellUpdate, context.luckysheetCellUpdate)) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
setContext(function (ctx) {
|
|
199
|
+
ctx.formulaRangeHighlight = [];
|
|
200
|
+
ctx.formulaRangeSelect = undefined;
|
|
201
|
+
ctx.formulaCache.selectingRangeIndex = -1;
|
|
202
|
+
ctx.formulaCache.func_selectedrange = undefined;
|
|
203
|
+
ctx.formulaCache.rangestart = false;
|
|
204
|
+
ctx.formulaCache.rangedrag_column_start = false;
|
|
205
|
+
ctx.formulaCache.rangedrag_row_start = false;
|
|
206
|
+
ctx.formulaCache.rangechangeindex = undefined;
|
|
207
|
+
});
|
|
208
|
+
}, [context.luckysheetCellUpdate, prevCellUpdate, setContext]);
|
|
179
209
|
(0, _react.useEffect)(function () {
|
|
180
210
|
setIsHidenRC((0, _fortuneCore.isShowHidenCR)(context));
|
|
181
211
|
}, [context.luckysheet_select_save]);
|
|
@@ -185,61 +215,40 @@ var InputBox = function InputBox() {
|
|
|
185
215
|
setIsInputBoxActive(false);
|
|
186
216
|
}
|
|
187
217
|
}, [firstSelection, (_c = context.rangeDialog) === null || _c === void 0 ? void 0 : _c.show, context.luckysheetCellUpdate]);
|
|
218
|
+
(0, _react.useEffect)(function () {
|
|
219
|
+
if (isInputBoxActive) return;
|
|
220
|
+
setContext(function (ctx) {
|
|
221
|
+
if (_lodash.default.isEmpty(ctx.formulaRangeHighlight) && !ctx.formulaRangeSelect && ctx.formulaCache.selectingRangeIndex === -1 && !ctx.formulaCache.func_selectedrange) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
ctx.formulaRangeHighlight = [];
|
|
225
|
+
ctx.formulaRangeSelect = undefined;
|
|
226
|
+
ctx.formulaCache.selectingRangeIndex = -1;
|
|
227
|
+
ctx.formulaCache.func_selectedrange = undefined;
|
|
228
|
+
ctx.formulaCache.rangestart = false;
|
|
229
|
+
ctx.formulaCache.rangedrag_column_start = false;
|
|
230
|
+
ctx.formulaCache.rangedrag_row_start = false;
|
|
231
|
+
ctx.formulaCache.rangechangeindex = undefined;
|
|
232
|
+
ctx.formulaCache.rangeSelectionActive = null;
|
|
233
|
+
});
|
|
234
|
+
}, [isInputBoxActive, setContext]);
|
|
188
235
|
var getActiveFormula = (0, _react.useCallback)(function () {
|
|
189
236
|
return document.querySelector(".luckysheet-formula-search-item-active");
|
|
190
237
|
}, []);
|
|
191
238
|
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");
|
|
239
|
+
var textEditor = inputRef.current;
|
|
209
240
|
if (!textEditor) return;
|
|
210
|
-
|
|
211
|
-
var
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
var searchTxt = ((_a = (0, _fortuneCore.getrangeseleciton)()) === null || _a === void 0 ? void 0 : _a.textContent) || "";
|
|
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
|
-
}
|
|
241
|
+
var fxEditor = document.getElementById("luckysheet-functionbox-cell");
|
|
242
|
+
var _a = (0, _helper.buildFormulaSuggestionText)(textEditor, formulaName),
|
|
243
|
+
text = _a.text,
|
|
244
|
+
caretOffset = _a.caretOffset;
|
|
245
|
+
var safeText = (0, _fortuneCore.escapeScriptTag)(text);
|
|
246
|
+
var html = safeText.startsWith("=") ? (0, _fortuneCore.functionHTMLGenerate)(safeText) : (0, _fortuneCore.escapeHTMLTag)(safeText);
|
|
247
|
+
textEditor.innerHTML = html;
|
|
248
|
+
if (fxEditor) {
|
|
249
|
+
fxEditor.innerHTML = html;
|
|
250
|
+
}
|
|
251
|
+
(0, _helper.setCursorPosition)(textEditor, caretOffset);
|
|
243
252
|
setContext(function (draftCtx) {
|
|
244
253
|
draftCtx.functionCandidates = [];
|
|
245
254
|
draftCtx.defaultCandidates = [];
|
|
@@ -279,10 +288,135 @@ var InputBox = function InputBox() {
|
|
|
279
288
|
event.stopPropagation();
|
|
280
289
|
event.preventDefault();
|
|
281
290
|
};
|
|
291
|
+
(0, _react.useEffect)(function () {
|
|
292
|
+
var _a;
|
|
293
|
+
var cellInputEl = refs.cellInput.current;
|
|
294
|
+
if (!((_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) || !cellInputEl) return;
|
|
295
|
+
setContext(function (ctx) {
|
|
296
|
+
var _a;
|
|
297
|
+
var currentSelection = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1];
|
|
298
|
+
if (!currentSelection) return;
|
|
299
|
+
var isMouseFormulaRangeDrag = !!ctx.formulaCache.func_selectedrange && (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start);
|
|
300
|
+
if (isMouseFormulaRangeDrag) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
(0, _fortuneCore.israngeseleciton)(ctx);
|
|
304
|
+
var keyboardSyncRangeIndex = (0, _fortuneCore.getFormulaRangeIndexForKeyboardSync)(cellInputEl);
|
|
305
|
+
if (skipNextAnchorSelectionSyncRef.current && formulaAnchorCellRef.current) {
|
|
306
|
+
var _b = formulaAnchorCellRef.current,
|
|
307
|
+
anchorRow = _b[0],
|
|
308
|
+
anchorCol = _b[1];
|
|
309
|
+
var isAnchorSelection = currentSelection.row_focus === anchorRow && currentSelection.column_focus === anchorCol;
|
|
310
|
+
if (isAnchorSelection) {
|
|
311
|
+
skipNextAnchorSelectionSyncRef.current = false;
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
var isFormulaMode = (0, _fortuneCore.isFormulaReferenceInputMode)(ctx);
|
|
316
|
+
if (!isFormulaMode) return;
|
|
317
|
+
if (keyboardSyncRangeIndex !== null) {
|
|
318
|
+
ctx.formulaCache.rangechangeindex = keyboardSyncRangeIndex;
|
|
319
|
+
ctx.formulaCache.rangestart = true;
|
|
320
|
+
ctx.formulaCache.rangedrag_column_start = false;
|
|
321
|
+
ctx.formulaCache.rangedrag_row_start = false;
|
|
322
|
+
} else {
|
|
323
|
+
ctx.formulaCache.rangechangeindex = undefined;
|
|
324
|
+
ctx.formulaCache.rangestart = false;
|
|
325
|
+
}
|
|
326
|
+
ctx.formulaCache.rangeSelectionActive = true;
|
|
327
|
+
_fortuneCore.rangeSetValue === null || _fortuneCore.rangeSetValue === void 0 ? void 0 : (0, _fortuneCore.rangeSetValue)(ctx, cellInputEl, {
|
|
328
|
+
row: currentSelection.row,
|
|
329
|
+
column: currentSelection.column
|
|
330
|
+
}, refs.fxInput.current);
|
|
331
|
+
(0, _fortuneCore.rangeHightlightselected)(ctx, cellInputEl);
|
|
332
|
+
if (!_lodash.default.isNil(ctx.formulaCache.rangechangeindex)) {
|
|
333
|
+
ctx.formulaCache.selectingRangeIndex = ctx.formulaCache.rangechangeindex;
|
|
334
|
+
(0, _fortuneCore.createRangeHightlight)(ctx, cellInputEl.innerHTML, ctx.formulaCache.rangechangeindex);
|
|
335
|
+
var rectFromSelection = (0, _fortuneCore.seletedHighlistByindex)(ctx, currentSelection.row[0], currentSelection.row[1], currentSelection.column[0], currentSelection.column[1]);
|
|
336
|
+
if (rectFromSelection) {
|
|
337
|
+
(0, _fortuneCore.createFormulaRangeSelect)(ctx, {
|
|
338
|
+
rangeIndex: ctx.formulaCache.rangechangeindex || 0,
|
|
339
|
+
left: rectFromSelection.left,
|
|
340
|
+
top: rectFromSelection.top,
|
|
341
|
+
width: rectFromSelection.width,
|
|
342
|
+
height: rectFromSelection.height
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}, [context.luckysheet_select_save, (_d = context.rangeDialog) === null || _d === void 0 ? void 0 : _d.show]);
|
|
348
|
+
var formulaMouseDragSignature = function () {
|
|
349
|
+
var _a, _b, _c, _d;
|
|
350
|
+
var r = context.formulaCache.func_selectedrange;
|
|
351
|
+
if (!r) return "";
|
|
352
|
+
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(":");
|
|
353
|
+
}();
|
|
354
|
+
(0, _react.useEffect)(function () {
|
|
355
|
+
var _a;
|
|
356
|
+
if (!formulaMouseDragSignature) return;
|
|
357
|
+
if (lastHandledMouseDragSignatureRef.current === formulaMouseDragSignature) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (!refs.cellInput.current) return;
|
|
361
|
+
var inputText = ((_a = refs.cellInput.current.innerText) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
362
|
+
if (!inputText.startsWith("=")) return;
|
|
363
|
+
var dragRange = context.formulaCache.func_selectedrange;
|
|
364
|
+
if (!dragRange) return;
|
|
365
|
+
lastHandledMouseDragSignatureRef.current = formulaMouseDragSignature;
|
|
366
|
+
setContext(function (ctx) {
|
|
367
|
+
ctx.luckysheet_select_save = [{
|
|
368
|
+
row: [dragRange.row[0], dragRange.row[1]],
|
|
369
|
+
column: [dragRange.column[0], dragRange.column[1]],
|
|
370
|
+
row_focus: _lodash.default.isNil(dragRange.row_focus) ? dragRange.row[0] : dragRange.row_focus,
|
|
371
|
+
column_focus: _lodash.default.isNil(dragRange.column_focus) ? dragRange.column[0] : dragRange.column_focus
|
|
372
|
+
}];
|
|
373
|
+
});
|
|
374
|
+
}, [formulaMouseDragSignature, context.formulaCache.func_selectedrange, refs.cellInput, setContext]);
|
|
282
375
|
var onKeyDown = (0, _react.useCallback)(function (e) {
|
|
283
376
|
var _a, _b;
|
|
284
377
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
285
378
|
preText.current = inputRef.current.innerText;
|
|
379
|
+
var currentInputText = ((_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) === null || _b === void 0 ? void 0 : _b.trim()) || "";
|
|
380
|
+
if ((e.key === "=" || currentInputText.startsWith("=")) && context.luckysheetCellUpdate.length === 2 && formulaAnchorCellRef.current == null) {
|
|
381
|
+
setContext(function (draftCtx) {
|
|
382
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
383
|
+
});
|
|
384
|
+
formulaAnchorCellRef.current = [context.luckysheetCellUpdate[0], context.luckysheetCellUpdate[1]];
|
|
385
|
+
}
|
|
386
|
+
if (e.key === "(" && currentInputText.startsWith("=")) {
|
|
387
|
+
setContext(function (draftCtx) {
|
|
388
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
if (e.key === "," && context.luckysheetCellUpdate.length > 0 && currentInputText.startsWith("=") && formulaAnchorCellRef.current) {
|
|
392
|
+
setContext(function (draftCtx) {
|
|
393
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
394
|
+
});
|
|
395
|
+
var _c = formulaAnchorCellRef.current,
|
|
396
|
+
anchorRow_1 = _c[0],
|
|
397
|
+
anchorCol_1 = _c[1];
|
|
398
|
+
skipNextAnchorSelectionSyncRef.current = true;
|
|
399
|
+
setTimeout(function () {
|
|
400
|
+
setContext(function (draftCtx) {
|
|
401
|
+
draftCtx.luckysheetCellUpdate = [anchorRow_1, anchorCol_1];
|
|
402
|
+
draftCtx.luckysheet_select_save = [{
|
|
403
|
+
row: [anchorRow_1, anchorRow_1],
|
|
404
|
+
column: [anchorCol_1, anchorCol_1],
|
|
405
|
+
row_focus: anchorRow_1,
|
|
406
|
+
column_focus: anchorCol_1
|
|
407
|
+
}];
|
|
408
|
+
draftCtx.formulaRangeHighlight = [];
|
|
409
|
+
draftCtx.formulaRangeSelect = undefined;
|
|
410
|
+
draftCtx.formulaCache.selectingRangeIndex = -1;
|
|
411
|
+
draftCtx.formulaCache.func_selectedrange = undefined;
|
|
412
|
+
draftCtx.formulaCache.rangechangeindex = undefined;
|
|
413
|
+
draftCtx.formulaCache.rangestart = false;
|
|
414
|
+
draftCtx.formulaCache.rangedrag_column_start = false;
|
|
415
|
+
draftCtx.formulaCache.rangedrag_row_start = false;
|
|
416
|
+
(0, _fortuneCore.moveHighlightCell)(draftCtx, "down", 0, "rangeOfSelect");
|
|
417
|
+
});
|
|
418
|
+
}, 0);
|
|
419
|
+
}
|
|
286
420
|
if (e.metaKey && context.luckysheetCellUpdate.length > 0) {
|
|
287
421
|
if (e.code === "KeyB") {
|
|
288
422
|
(0, _fortuneCore.handleBold)(context, inputRef.current);
|
|
@@ -303,6 +437,7 @@ var InputBox = function InputBox() {
|
|
|
303
437
|
setCommaCount(currentCommaCount);
|
|
304
438
|
}
|
|
305
439
|
var allowListNavigation = true;
|
|
440
|
+
var isArrowKey = e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight";
|
|
306
441
|
if (e.key === "Delete" || e.key === "Backspace") {
|
|
307
442
|
if (isComposingRef.current) requestAnimationFrame(ensureNotEmpty);
|
|
308
443
|
if ((0, _helper.getCursorPosition)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
|
|
@@ -311,39 +446,8 @@ var InputBox = function InputBox() {
|
|
|
311
446
|
}, 5);
|
|
312
447
|
}
|
|
313
448
|
}
|
|
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
|
-
}
|
|
449
|
+
if (isArrowKey && (0, _fortuneCore.isFormulaReferenceInputMode)(context)) {
|
|
450
|
+
allowListNavigation = false;
|
|
347
451
|
}
|
|
348
452
|
if (e.key === "Escape" && context.luckysheetCellUpdate.length > 0) {
|
|
349
453
|
setContext(function (draftCtx) {
|
|
@@ -420,7 +524,7 @@ var InputBox = function InputBox() {
|
|
|
420
524
|
}
|
|
421
525
|
};
|
|
422
526
|
var onChange = (0, _react.useCallback)(function (__, isBlur) {
|
|
423
|
-
var _a;
|
|
527
|
+
var _a, _b, _c;
|
|
424
528
|
if (context.isFlvReadOnly) return;
|
|
425
529
|
handleHideShowHint();
|
|
426
530
|
if (((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
|
|
@@ -433,7 +537,16 @@ var InputBox = function InputBox() {
|
|
|
433
537
|
setCommaCount(currentCommaCount);
|
|
434
538
|
}
|
|
435
539
|
var e = lastKeyDownEventRef.current;
|
|
436
|
-
if (!e)
|
|
540
|
+
if (!e) {
|
|
541
|
+
var cellEl_1 = refs.cellInput.current;
|
|
542
|
+
if (cellEl_1 && (((_b = cellEl_1.innerText) === null || _b === void 0 ? void 0 : _b.trim().startsWith("=")) || ((_c = cellEl_1.textContent) === null || _c === void 0 ? void 0 : _c.trim().startsWith("=")))) {
|
|
543
|
+
setContext(function (draftCtx) {
|
|
544
|
+
if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) return;
|
|
545
|
+
(0, _fortuneCore.rangeHightlightselected)(draftCtx, cellEl_1);
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
437
550
|
var kcode = e.keyCode;
|
|
438
551
|
if (!kcode) return;
|
|
439
552
|
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) {
|
|
@@ -489,7 +602,7 @@ var InputBox = function InputBox() {
|
|
|
489
602
|
zIndex: _lodash.default.isEmpty(context.luckysheetCellUpdate) ? -1 : 19,
|
|
490
603
|
display: "block"
|
|
491
604
|
};
|
|
492
|
-
}, [firstSelection, (
|
|
605
|
+
}, [firstSelection, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
|
|
493
606
|
(0, _react.useEffect)(function () {
|
|
494
607
|
var _a;
|
|
495
608
|
if (firstSelection && !((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) && !isInputBoxActive && !_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
|
|
@@ -505,7 +618,7 @@ var InputBox = function InputBox() {
|
|
|
505
618
|
setIsInputBoxActive(true);
|
|
506
619
|
}
|
|
507
620
|
}
|
|
508
|
-
}, [firstSelection, (
|
|
621
|
+
}, [firstSelection, (_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
|
|
509
622
|
var getAddressIndicatorPosition = (0, _react.useCallback)(function () {
|
|
510
623
|
var _a;
|
|
511
624
|
if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
|
|
@@ -518,7 +631,7 @@ var InputBox = function InputBox() {
|
|
|
518
631
|
left: "0",
|
|
519
632
|
display: "block"
|
|
520
633
|
};
|
|
521
|
-
}, [firstSelection, (
|
|
634
|
+
}, [firstSelection, (_g = context.rangeDialog) === null || _g === void 0 ? void 0 : _g.show]);
|
|
522
635
|
var getCellAddress = (0, _react.useCallback)(function () {
|
|
523
636
|
if (!firstSelection) return "";
|
|
524
637
|
var rowIndex = firstSelection.row_focus || 0;
|
|
@@ -568,10 +681,9 @@ var InputBox = function InputBox() {
|
|
|
568
681
|
};
|
|
569
682
|
});
|
|
570
683
|
setLinkSelectionHighlightRects(relative);
|
|
571
|
-
}, [(
|
|
684
|
+
}, [(_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
685
|
var wraperGetCell = function wraperGetCell() {
|
|
573
686
|
var cell = getCellAddress();
|
|
574
|
-
placeRef.current = cell;
|
|
575
687
|
if (activeRefCell !== cell) {
|
|
576
688
|
setActiveRefCell(cell);
|
|
577
689
|
}
|
|
@@ -595,6 +707,7 @@ var InputBox = function InputBox() {
|
|
|
595
707
|
}, []);
|
|
596
708
|
var functionName = context.functionHint || getFunctionNameFromInput();
|
|
597
709
|
var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
|
|
710
|
+
var inputBoxBaseSelection = isInputBoxActive && firstSelectionActiveCell ? firstSelectionActiveCell : firstSelection;
|
|
598
711
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
599
712
|
className: "luckysheet-input-box",
|
|
600
713
|
id: "luckysheet-input-box",
|
|
@@ -605,16 +718,16 @@ var InputBox = function InputBox() {
|
|
|
605
718
|
onMouseUp: function onMouseUp(e) {
|
|
606
719
|
return e.stopPropagation();
|
|
607
720
|
}
|
|
608
|
-
}, firstSelection && !((
|
|
721
|
+
}, firstSelection && !((_m = context.rangeDialog) === null || _m === void 0 ? void 0 : _m.show) && (/*#__PURE__*/_react.default.createElement("div", {
|
|
609
722
|
className: "luckysheet-cell-address-indicator",
|
|
610
723
|
style: getAddressIndicatorPosition()
|
|
611
724
|
}, wraperGetCell())), /*#__PURE__*/_react.default.createElement("div", {
|
|
612
725
|
ref: inputBoxInnerRef,
|
|
613
726
|
className: "luckysheet-input-box-inner",
|
|
614
|
-
style:
|
|
727
|
+
style: inputBoxBaseSelection ? __assign({
|
|
615
728
|
position: "relative",
|
|
616
|
-
minWidth:
|
|
617
|
-
minHeight:
|
|
729
|
+
minWidth: inputBoxBaseSelection.width,
|
|
730
|
+
minHeight: inputBoxBaseSelection.height
|
|
618
731
|
}, inputBoxStyle) : {
|
|
619
732
|
position: "relative"
|
|
620
733
|
}
|
|
@@ -219,7 +219,7 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
|
|
|
219
219
|
var sheetIdx_1 = (0, _fortuneCore.getSheetIndex)(context, context.currentSheetId);
|
|
220
220
|
if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
|
|
221
221
|
setContext(function (draft) {
|
|
222
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
222
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
223
223
|
var _sheet = draft.luckysheetfile[sheetIdx_1];
|
|
224
224
|
if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
|
|
225
225
|
var rows = _sheet.data;
|
|
@@ -382,6 +382,30 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
|
|
|
382
382
|
}
|
|
383
383
|
});
|
|
384
384
|
(_g = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _g === void 0 ? void 0 : _g.call(window, selectedSourceCol, selectedTargetCol, "column", context.currentSheetId, sourceIndex_1, targetIndex);
|
|
385
|
+
var cellChanges = [];
|
|
386
|
+
var affectedColStart = Math.min(sourceIndex_1, targetIndex);
|
|
387
|
+
var affectedColEnd = Math.max(sourceIndex_1, targetIndex) + selectedSourceCol.length - 1;
|
|
388
|
+
var numRows = rows.length;
|
|
389
|
+
for (var r = 0; r < numRows; r += 1) {
|
|
390
|
+
var row = rows[r];
|
|
391
|
+
for (var c = affectedColStart; c <= affectedColEnd; c += 1) {
|
|
392
|
+
var cell = row === null || row === void 0 ? void 0 : row[c];
|
|
393
|
+
cellChanges.push({
|
|
394
|
+
sheetId: draft.currentSheetId,
|
|
395
|
+
path: ["celldata"],
|
|
396
|
+
value: {
|
|
397
|
+
r: r,
|
|
398
|
+
c: c,
|
|
399
|
+
v: cell !== null && cell !== void 0 ? cell : null
|
|
400
|
+
},
|
|
401
|
+
key: "".concat(r, "_").concat(c),
|
|
402
|
+
type: "update"
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (cellChanges.length > 0 && ((_h = draft.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc)) {
|
|
407
|
+
draft.hooks.updateCellYdoc(cellChanges);
|
|
408
|
+
}
|
|
385
409
|
var rowLen = (d === null || d === void 0 ? void 0 : d.length) || 0;
|
|
386
410
|
_fortuneCore.api.setSelection(draft, [{
|
|
387
411
|
row: [0, rowLen],
|
|
@@ -214,7 +214,7 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
|
|
|
214
214
|
var sheetIdx_1 = (0, _fortuneCore.getSheetIndex)(context, context.currentSheetId);
|
|
215
215
|
if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
|
|
216
216
|
setContext(function (draft) {
|
|
217
|
-
var _a, _b, _c, _d, _e, _f;
|
|
217
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
218
218
|
var _sheet = draft.luckysheetfile[sheetIdx_1];
|
|
219
219
|
if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
|
|
220
220
|
var rows = _sheet.data;
|
|
@@ -371,7 +371,31 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
|
|
|
371
371
|
}
|
|
372
372
|
});
|
|
373
373
|
(_e = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _e === void 0 ? void 0 : _e.call(window, sourceIndex_1, targetIndex, "row", context.currentSheetId);
|
|
374
|
-
var
|
|
374
|
+
var cellChanges = [];
|
|
375
|
+
var affectedRowStart = Math.min(sourceIndex_1, targetIndex);
|
|
376
|
+
var affectedRowEnd = Math.max(sourceIndex_1, targetIndex) + selectedSourceRow.length - 1;
|
|
377
|
+
var numCols = (_g = (_f = d === null || d === void 0 ? void 0 : d[0]) === null || _f === void 0 ? void 0 : _f.length) !== null && _g !== void 0 ? _g : 0;
|
|
378
|
+
for (var r = affectedRowStart; r <= affectedRowEnd; r += 1) {
|
|
379
|
+
var row = rows[r];
|
|
380
|
+
for (var c = 0; c < numCols; c += 1) {
|
|
381
|
+
var cell = row === null || row === void 0 ? void 0 : row[c];
|
|
382
|
+
cellChanges.push({
|
|
383
|
+
sheetId: draft.currentSheetId,
|
|
384
|
+
path: ["celldata"],
|
|
385
|
+
value: {
|
|
386
|
+
r: r,
|
|
387
|
+
c: c,
|
|
388
|
+
v: cell !== null && cell !== void 0 ? cell : null
|
|
389
|
+
},
|
|
390
|
+
key: "".concat(r, "_").concat(c),
|
|
391
|
+
type: "update"
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (cellChanges.length > 0 && ((_h = draft.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc)) {
|
|
396
|
+
draft.hooks.updateCellYdoc(cellChanges);
|
|
397
|
+
}
|
|
398
|
+
var colLen = ((_j = d === null || d === void 0 ? void 0 : d[0]) === null || _j === void 0 ? void 0 : _j.length) || 0;
|
|
375
399
|
_fortuneCore.api.setSelection(draft, [{
|
|
376
400
|
row: [selectedTargetRow[0], selectedTargetRow[selectedTargetRow.length - 1]],
|
|
377
401
|
column: [0, colLen]
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export declare function moveCursorToEnd(editableDiv: HTMLDivElement): void;
|
|
2
2
|
export declare function getCursorPosition(editableDiv: HTMLDivElement): number;
|
|
3
|
+
export declare function setCursorPosition(editableDiv: HTMLDivElement, targetOffset: number): void;
|
|
4
|
+
export declare function buildFormulaSuggestionText(editableDiv: HTMLDivElement, formulaName: string): {
|
|
5
|
+
text: string;
|
|
6
|
+
caretOffset: number;
|
|
7
|
+
};
|
|
3
8
|
export declare function isLetterNumberPattern(str: string): boolean;
|
|
4
9
|
export declare function removeLastSpan(htmlString: string): string;
|
|
5
10
|
export declare function numberToColumn(colNumber: number): string;
|