@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.
Files changed (39) hide show
  1. package/es/components/ContextMenu/index.js +1 -1
  2. package/es/components/FxEditor/index.js +316 -60
  3. package/es/components/SheetOverlay/FormulaHint/index.js +46 -25
  4. package/es/components/SheetOverlay/FormulaSearch/index.d.ts +3 -1
  5. package/es/components/SheetOverlay/FormulaSearch/index.js +58 -29
  6. package/es/components/SheetOverlay/InputBox.js +406 -194
  7. package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +34 -48
  8. package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +31 -41
  9. package/es/components/SheetOverlay/formula-segment-boundary.d.ts +1 -0
  10. package/es/components/SheetOverlay/formula-segment-boundary.js +4 -0
  11. package/es/components/SheetOverlay/helper.d.ts +7 -0
  12. package/es/components/SheetOverlay/helper.js +95 -0
  13. package/es/components/SheetOverlay/index.css +6 -45
  14. package/es/components/SheetOverlay/index.js +26 -14
  15. package/es/components/Workbook/index.js +5 -8
  16. package/es/hooks/useFormulaEditorHistory.d.ts +24 -0
  17. package/es/hooks/useFormulaEditorHistory.js +119 -0
  18. package/es/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
  19. package/es/hooks/useRerenderOnFormulaCaret.js +28 -0
  20. package/lib/components/ContextMenu/index.js +1 -1
  21. package/lib/components/FxEditor/index.js +314 -58
  22. package/lib/components/SheetOverlay/FormulaHint/index.js +45 -24
  23. package/lib/components/SheetOverlay/FormulaSearch/index.d.ts +3 -1
  24. package/lib/components/SheetOverlay/FormulaSearch/index.js +57 -28
  25. package/lib/components/SheetOverlay/InputBox.js +404 -192
  26. package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +33 -47
  27. package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +31 -41
  28. package/lib/components/SheetOverlay/formula-segment-boundary.d.ts +1 -0
  29. package/lib/components/SheetOverlay/formula-segment-boundary.js +10 -0
  30. package/lib/components/SheetOverlay/helper.d.ts +7 -0
  31. package/lib/components/SheetOverlay/helper.js +99 -0
  32. package/lib/components/SheetOverlay/index.css +6 -45
  33. package/lib/components/SheetOverlay/index.js +25 -13
  34. package/lib/components/Workbook/index.js +5 -8
  35. package/lib/hooks/useFormulaEditorHistory.d.ts +24 -0
  36. package/lib/hooks/useFormulaEditorHistory.js +126 -0
  37. package/lib/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
  38. package/lib/hooks/useRerenderOnFormulaCaret.js +34 -0
  39. package/package.json +2 -2
@@ -18,14 +18,33 @@ var __spreadArray = void 0 && (void 0).__spreadArray || function (to, from, pack
18
18
  }
19
19
  return to.concat(ar || Array.prototype.slice.call(from));
20
20
  };
21
- function numberToColumnName(num) {
22
- var columnName = "";
23
- while (num >= 0) {
24
- var remainder = num % 26;
25
- columnName = String.fromCharCode(65 + remainder) + columnName;
26
- num = Math.floor(num / 26) - 1;
21
+ var REF_TOKEN_REGEX = /((?:'(?:[^']|'')+'|[A-Za-z_][A-Za-z0-9_.]*)!)?(\$?)([A-Za-z]+)(\$?)(\d+)(?::(\$?)([A-Za-z]+)(\$?)(\d+))?/g;
22
+ function normalizeSheetName(raw) {
23
+ if (!raw) return "";
24
+ var noBang = raw.endsWith("!") ? raw.slice(0, -1) : raw;
25
+ if (noBang.startsWith("'") && noBang.endsWith("'")) {
26
+ return noBang.slice(1, -1).replace(/''/g, "'");
27
27
  }
28
- return columnName;
28
+ return noBang;
29
+ }
30
+ function remapFormulaCols(formula, formulaSheetName, movedSheetName, colMap) {
31
+ return formula.replace(REF_TOKEN_REGEX, function (token, sheetPrefix, colAbs0, col0, rowAbs0, row0, colAbs1, col1, rowAbs1, row1) {
32
+ var refSheet = normalizeSheetName(sheetPrefix) || formulaSheetName;
33
+ if (refSheet !== movedSheetName) return token;
34
+ var colIdx0 = (0, _fortuneCore.columnCharToIndex)(col0);
35
+ var mapped0 = colMap[colIdx0];
36
+ var nextCol0 = mapped0 == null ? col0 : (0, _fortuneCore.indexToColumnChar)(mapped0);
37
+ if (!col1) {
38
+ return "".concat(sheetPrefix || "").concat(colAbs0).concat(nextCol0).concat(rowAbs0).concat(row0);
39
+ }
40
+ var colIdx1 = (0, _fortuneCore.columnCharToIndex)(col1);
41
+ var mapped1 = colMap[colIdx1];
42
+ var nextCol1 = mapped1 == null ? col1 : (0, _fortuneCore.indexToColumnChar)(mapped1);
43
+ return "".concat(sheetPrefix || "").concat(colAbs0).concat(nextCol0).concat(rowAbs0).concat(row0, ":").concat(colAbs1).concat(nextCol1).concat(rowAbs1).concat(row1);
44
+ });
45
+ }
46
+ function numberToColumnName(num) {
47
+ return (0, _fortuneCore.indexToColumnChar)(num);
29
48
  }
30
49
  var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, selectedLocationRef) {
31
50
  var DOUBLE_CLICK_MS = 300;
@@ -266,62 +285,29 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
266
285
  d === null || d === void 0 ? void 0 : d.forEach(function (row) {
267
286
  row.forEach(function (cell) {
268
287
  if (cell) {
269
- var otherAffectedCols_1 = [];
288
+ var colMap_1 = {};
270
289
  if (sourceIndex_1 < targetIndex) {
271
290
  var start = selectedSourceCol === null || selectedSourceCol === void 0 ? void 0 : selectedSourceCol[selectedSourceCol.length - 1];
272
291
  var last = selectedTargetCol === null || selectedTargetCol === void 0 ? void 0 : selectedTargetCol[selectedTargetCol.length - 1];
273
292
  for (var c = start + 1; c <= last; c += 1) {
274
- otherAffectedCols_1.push({
275
- source: numberToColumnName(c),
276
- target: numberToColumnName(c - selectedSourceCol.length)
277
- });
293
+ colMap_1[c] = c - selectedSourceCol.length;
278
294
  }
279
295
  selectedSourceCol.forEach(function (c, index) {
280
- otherAffectedCols_1.push({
281
- source: numberToColumnName(c),
282
- target: numberToColumnName(selectedTargetCol[index])
283
- });
296
+ colMap_1[c] = selectedTargetCol[index];
284
297
  });
285
298
  } else if (sourceIndex_1 > targetIndex) {
286
299
  var start = selectedTargetCol === null || selectedTargetCol === void 0 ? void 0 : selectedTargetCol[0];
287
300
  var last = selectedSourceCol === null || selectedSourceCol === void 0 ? void 0 : selectedSourceCol[0];
288
301
  for (var c = start; c < last; c += 1) {
289
- otherAffectedCols_1.push({
290
- source: numberToColumnName(c),
291
- target: numberToColumnName(c + selectedSourceCol.length)
292
- });
302
+ colMap_1[c] = c + selectedSourceCol.length;
293
303
  }
294
304
  selectedSourceCol.forEach(function (c, index) {
295
- otherAffectedCols_1.push({
296
- source: numberToColumnName(c),
297
- target: numberToColumnName(selectedTargetCol[index])
298
- });
305
+ colMap_1[c] = selectedTargetCol[index];
299
306
  });
300
307
  }
301
308
  if (cell.f) {
302
- var formula_1 = cell.f;
303
- var replacements_1 = [];
304
- otherAffectedCols_1.forEach(function (col) {
305
- var regex = new RegExp("\\b".concat(col.source, "(\\d+)\\b"), "g");
306
- var match;
307
- while ((match = regex.exec(formula_1)) !== null) {
308
- if (/^\d+$/.test(match[1])) {
309
- replacements_1.push({
310
- start: match.index,
311
- end: match.index + match[0].length,
312
- original: match[0],
313
- replacement: "".concat(col.target).concat(match[1])
314
- });
315
- }
316
- }
317
- });
318
- replacements_1 === null || replacements_1 === void 0 ? void 0 : replacements_1.sort(function (a, b) {
319
- return b.start - a.start;
320
- });
321
- replacements_1 === null || replacements_1 === void 0 ? void 0 : replacements_1.forEach(function (rep) {
322
- formula_1 = formula_1.substring(0, rep.start) + rep.replacement + formula_1.substring(rep.end);
323
- });
324
- cell.f = formula_1;
309
+ var sheetName = _sheet.name || "";
310
+ cell.f = remapFormulaCols(cell.f, sheetName, sheetName, colMap_1);
325
311
  }
326
312
  }
327
313
  });
@@ -17,6 +17,29 @@ var __spreadArray = void 0 && (void 0).__spreadArray || function (to, from, pack
17
17
  }
18
18
  return to.concat(ar || Array.prototype.slice.call(from));
19
19
  };
20
+ var REF_TOKEN_REGEX = /((?:'(?:[^']|'')+'|[A-Za-z_][A-Za-z0-9_.]*)!)?(\$?)([A-Za-z]+)(\$?)(\d+)(?::(\$?)([A-Za-z]+)(\$?)(\d+))?/g;
21
+ function normalizeSheetName(raw) {
22
+ if (!raw) return "";
23
+ var noBang = raw.endsWith("!") ? raw.slice(0, -1) : raw;
24
+ if (noBang.startsWith("'") && noBang.endsWith("'")) {
25
+ return noBang.slice(1, -1).replace(/''/g, "'");
26
+ }
27
+ return noBang;
28
+ }
29
+ function remapFormulaRows(formula, formulaSheetName, movedSheetName, rowMap) {
30
+ return formula.replace(REF_TOKEN_REGEX, function (token, sheetPrefix, colAbs0, col0, rowAbs0, row0, colAbs1, col1, rowAbs1, row1) {
31
+ var refSheet = normalizeSheetName(sheetPrefix) || formulaSheetName;
32
+ if (refSheet !== movedSheetName) return token;
33
+ var mapped0 = rowMap[parseInt(row0, 10) - 1];
34
+ var nextRow0 = mapped0 == null ? parseInt(row0, 10) : mapped0 + 1;
35
+ if (!row1) {
36
+ return "".concat(sheetPrefix || "").concat(colAbs0).concat(col0).concat(rowAbs0).concat(nextRow0);
37
+ }
38
+ var mapped1 = rowMap[parseInt(row1, 10) - 1];
39
+ var nextRow1 = mapped1 == null ? parseInt(row1, 10) : mapped1 + 1;
40
+ return "".concat(sheetPrefix || "").concat(colAbs0).concat(col0).concat(rowAbs0).concat(nextRow0, ":").concat(colAbs1).concat(col1).concat(rowAbs1).concat(nextRow1);
41
+ });
42
+ }
20
43
  var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(containerRef, selectedLocationRef) {
21
44
  var DOUBLE_MS = 300;
22
45
  var START_DRAG_THRESHOLD_PX = 6;
@@ -255,62 +278,29 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
255
278
  d === null || d === void 0 ? void 0 : d.forEach(function (row) {
256
279
  row.forEach(function (cell) {
257
280
  if (cell) {
258
- var otherAffectedRows_1 = [];
281
+ var rowMap_1 = {};
259
282
  if (sourceIndex_1 < targetIndex) {
260
283
  var start = selectedSourceRow === null || selectedSourceRow === void 0 ? void 0 : selectedSourceRow[selectedSourceRow.length - 1];
261
284
  var last = selectedTargetRow === null || selectedTargetRow === void 0 ? void 0 : selectedTargetRow[selectedTargetRow.length - 1];
262
285
  for (var c = start + 1; c < last; c += 1) {
263
- otherAffectedRows_1.push({
264
- source: c,
265
- target: c - selectedSourceRow.length
266
- });
286
+ rowMap_1[c] = c - selectedSourceRow.length;
267
287
  }
268
288
  selectedSourceRow.forEach(function (c, index) {
269
- otherAffectedRows_1.push({
270
- source: c,
271
- target: selectedTargetRow[index]
272
- });
289
+ rowMap_1[c] = selectedTargetRow[index];
273
290
  });
274
291
  } else {
275
292
  var start = selectedTargetRow === null || selectedTargetRow === void 0 ? void 0 : selectedTargetRow[0];
276
293
  var last = selectedSourceRow === null || selectedSourceRow === void 0 ? void 0 : selectedSourceRow[0];
277
294
  for (var c = start; c < last; c += 1) {
278
- otherAffectedRows_1.push({
279
- source: c,
280
- target: c + +selectedSourceRow.length
281
- });
295
+ rowMap_1[c] = c + selectedSourceRow.length;
282
296
  }
283
297
  selectedSourceRow.forEach(function (c, index) {
284
- otherAffectedRows_1.push({
285
- source: c,
286
- target: selectedTargetRow[index]
287
- });
298
+ rowMap_1[c] = selectedTargetRow[index];
288
299
  });
289
300
  }
290
301
  if (cell.f) {
291
- var formula_1 = cell.f;
292
- var replacements_1 = [];
293
- otherAffectedRows_1.forEach(function (_a) {
294
- var source = _a.source,
295
- target = _a.target;
296
- var regex = new RegExp("\\b([A-Z]+)".concat(source, "\\b"), "g");
297
- var match;
298
- while ((match = regex.exec(formula_1)) !== null) {
299
- replacements_1.push({
300
- start: match.index,
301
- end: match.index + match[0].length,
302
- original: match[0],
303
- replacement: "".concat(match[1]).concat(target)
304
- });
305
- }
306
- });
307
- replacements_1.sort(function (a, b) {
308
- return b.start - a.start;
309
- });
310
- replacements_1.forEach(function (rep) {
311
- formula_1 = formula_1.substring(0, rep.start) + rep.replacement + formula_1.substring(rep.end);
312
- });
313
- cell.f = formula_1;
302
+ var sheetName = _sheet.name || "";
303
+ cell.f = remapFormulaRows(cell.f, sheetName, sheetName, rowMap_1);
314
304
  }
315
305
  }
316
306
  });
@@ -362,7 +352,7 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
362
352
  }
363
353
  (_d = _sheet.calcChain) === null || _d === void 0 ? void 0 : _d.forEach(function (item) {
364
354
  if (selectedSourceRow.includes(item.r)) {
365
- var index = selectedSourceRow.indexOf(item.c);
355
+ var index = selectedSourceRow.indexOf(item.r);
366
356
  item.r = selectedTargetRow[index];
367
357
  } else if (item.r > sourceIndex_1 && item.r < targetIndex) {
368
358
  item.r -= selectedSourceRow.length;
@@ -0,0 +1 @@
1
+ export declare function isFormulaSegmentBoundaryKey(key: string): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isFormulaSegmentBoundaryKey = isFormulaSegmentBoundaryKey;
7
+ var FORMULA_SEGMENT_BOUNDARY_KEYS = new Set([",", "+", "-", "*", "/", "%", "^", "&"]);
8
+ function isFormulaSegmentBoundaryKey(key) {
9
+ return FORMULA_SEGMENT_BOUNDARY_KEYS.has(key);
10
+ }
@@ -1,6 +1,13 @@
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;
9
+ export declare function shouldShowFormulaFunctionList(editor: HTMLDivElement | null): boolean;
10
+ export declare function getFunctionNameFromFormulaCaretSpans(editor: HTMLDivElement | null): string | null;
4
11
  export declare function removeLastSpan(htmlString: string): string;
5
12
  export declare function numberToColumn(colNumber: number): string;
6
13
  export declare function incrementColumn(cell: string): string;
@@ -3,16 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.buildFormulaSuggestionText = buildFormulaSuggestionText;
6
7
  exports.countCommasBeforeCursor = countCommasBeforeCursor;
7
8
  exports.decrementColumn = decrementColumn;
8
9
  exports.decrementRow = decrementRow;
9
10
  exports.getCursorPosition = getCursorPosition;
11
+ exports.getFunctionNameFromFormulaCaretSpans = getFunctionNameFromFormulaCaretSpans;
10
12
  exports.incrementColumn = incrementColumn;
11
13
  exports.incrementRow = incrementRow;
12
14
  exports.isLetterNumberPattern = isLetterNumberPattern;
13
15
  exports.moveCursorToEnd = moveCursorToEnd;
14
16
  exports.numberToColumn = numberToColumn;
15
17
  exports.removeLastSpan = removeLastSpan;
18
+ exports.setCursorPosition = setCursorPosition;
19
+ exports.shouldShowFormulaFunctionList = shouldShowFormulaFunctionList;
16
20
  function moveCursorToEnd(editableDiv) {
17
21
  editableDiv.focus();
18
22
  var range = document.createRange();
@@ -33,10 +37,105 @@ function getCursorPosition(editableDiv) {
33
37
  preRange.setEnd(range.endContainer, range.endOffset);
34
38
  return preRange.toString().length;
35
39
  }
40
+ function setCursorPosition(editableDiv, targetOffset) {
41
+ var _a, _b;
42
+ editableDiv.focus();
43
+ var selection = window.getSelection();
44
+ if (!selection) return;
45
+ var range = document.createRange();
46
+ var walker = document.createTreeWalker(editableDiv, NodeFilter.SHOW_TEXT);
47
+ var remaining = Math.max(0, targetOffset);
48
+ var node = walker.nextNode();
49
+ while (node) {
50
+ var textLength = (_b = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
51
+ if (remaining <= textLength) {
52
+ range.setStart(node, remaining);
53
+ range.collapse(true);
54
+ selection.removeAllRanges();
55
+ selection.addRange(range);
56
+ return;
57
+ }
58
+ remaining -= textLength;
59
+ node = walker.nextNode();
60
+ }
61
+ range.selectNodeContents(editableDiv);
62
+ range.collapse(false);
63
+ selection.removeAllRanges();
64
+ selection.addRange(range);
65
+ }
66
+ function buildFormulaSuggestionText(editableDiv, formulaName) {
67
+ var fullText = editableDiv.innerText || "";
68
+ var selection = window.getSelection();
69
+ var selectionInEditor = !!(selection === null || selection === void 0 ? void 0 : selection.rangeCount) && editableDiv.contains(selection.getRangeAt(0).startContainer);
70
+ var caretOffset = selectionInEditor ? getCursorPosition(editableDiv) : fullText.length;
71
+ var safeCaretOffset = Math.max(0, Math.min(caretOffset, fullText.length));
72
+ var beforeCaret = fullText.slice(0, safeCaretOffset);
73
+ var afterCaret = fullText.slice(safeCaretOffset);
74
+ var replaceStart = safeCaretOffset;
75
+ var tokenMatch = beforeCaret.match(/[A-Za-z_][A-Za-z0-9_]*$/);
76
+ if (tokenMatch) {
77
+ var token = tokenMatch[0];
78
+ var tokenStart = safeCaretOffset - token.length;
79
+ var charBeforeToken = tokenStart > 0 ? beforeCaret[tokenStart - 1] : "";
80
+ if (tokenStart === 0 || /[\s=(,+\-*/&^<>]$/.test(charBeforeToken)) {
81
+ replaceStart = tokenStart;
82
+ }
83
+ }
84
+ var shouldAddOpeningParen = !afterCaret.startsWith("(");
85
+ var insertedText = "".concat(formulaName).concat(shouldAddOpeningParen ? "(" : "");
86
+ var nextText = fullText.slice(0, replaceStart) + insertedText + afterCaret;
87
+ return {
88
+ text: nextText,
89
+ caretOffset: replaceStart + insertedText.length
90
+ };
91
+ }
36
92
  function isLetterNumberPattern(str) {
37
93
  var regex = /^[a-zA-Z]+\d+$/;
38
94
  return regex.test(str);
39
95
  }
96
+ function shouldShowFormulaFunctionList(editor) {
97
+ var _a, _b;
98
+ if (!editor) return false;
99
+ if (!((_a = editor.innerText) === null || _a === void 0 ? void 0 : _a.includes("="))) return false;
100
+ var parser = new DOMParser();
101
+ var doc = parser.parseFromString("<div>".concat(editor.innerHTML, "</div>"), "text/html");
102
+ var spans = doc.querySelectorAll("span");
103
+ var lastSpan = spans[spans.length - 1];
104
+ var lastText = (_b = lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) !== null && _b !== void 0 ? _b : "";
105
+ return /^=?[A-Za-z]*$/.test(lastText);
106
+ }
107
+ var FORMULA_FUNC_CLASS = "luckysheet-formula-text-func";
108
+ var FORMULA_LPAR_CLASS = "luckysheet-formula-text-lpar";
109
+ function getFunctionNameFromFormulaCaretSpans(editor) {
110
+ var _a, _b;
111
+ if (!editor) return null;
112
+ var sel = window.getSelection();
113
+ if (!(sel === null || sel === void 0 ? void 0 : sel.rangeCount)) return null;
114
+ var range = sel.getRangeAt(0);
115
+ if (!editor.contains(range.startContainer)) return null;
116
+ var n = range.startContainer;
117
+ while (n && n !== editor) {
118
+ if (n.nodeType === Node.ELEMENT_NODE) {
119
+ var elem = n;
120
+ if (elem.classList.contains(FORMULA_FUNC_CLASS)) {
121
+ var next = elem.nextElementSibling;
122
+ if (next === null || next === void 0 ? void 0 : next.classList.contains(FORMULA_LPAR_CLASS)) {
123
+ var name_1 = (_a = elem.textContent) === null || _a === void 0 ? void 0 : _a.trim();
124
+ return name_1 ? name_1.toUpperCase() : null;
125
+ }
126
+ }
127
+ if (elem.classList.contains(FORMULA_LPAR_CLASS)) {
128
+ var prev = elem.previousElementSibling;
129
+ if (prev === null || prev === void 0 ? void 0 : prev.classList.contains(FORMULA_FUNC_CLASS)) {
130
+ var name_2 = (_b = prev.textContent) === null || _b === void 0 ? void 0 : _b.trim();
131
+ return name_2 ? name_2.toUpperCase() : null;
132
+ }
133
+ }
134
+ }
135
+ n = n.parentNode;
136
+ }
137
+ return null;
138
+ }
40
139
  function removeLastSpan(htmlString) {
41
140
  var container = document.createElement("div");
42
141
  container.innerHTML = htmlString;
@@ -336,9 +336,9 @@
336
336
  overflow: hidden;
337
337
  white-space: pre-wrap;
338
338
  outline: none;
339
- -webkit-box-shadow: 0 2px 5px rgb(0 0 0 / 40%);
340
- -moz-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
341
- box-shadow: 0 2px 5px rgb(0 0 0 / 40%);
339
+ /* -webkit-box-shadow: 0 2px 5px rgb(0 0 0 / 40%);
340
+ -moz-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); */
341
+ /* box-shadow: 0 2px 5px rgb(0 0 0 / 40%); */
342
342
  word-wrap: break-word;
343
343
  background-color: rgb(255, 255, 255);
344
344
  font-size: 13px;
@@ -356,7 +356,7 @@
356
356
  }
357
357
 
358
358
  .luckysheet-formula-text-color {
359
- color: black;
359
+ color: darkred;
360
360
  }
361
361
 
362
362
  .luckysheet-formula-text-string {
@@ -801,50 +801,11 @@
801
801
  }
802
802
 
803
803
  .fortune-formula-functionrange-highlight .fortune-selection-copy-hc {
804
- border: 2px solid #5e5e5e;
805
- opacity: 0.03;
804
+ border-width: 2px;
805
+ border-style: dotted;
806
806
  z-index: initial;
807
807
  }
808
808
 
809
- .fortune-selection-highlight-lt {
810
- left: -3px;
811
- top: -3px;
812
- cursor: se-resize;
813
- }
814
-
815
- .fortune-selection-highlight-rt {
816
- right: -3px;
817
- top: -3px;
818
- cursor: ne-resize;
819
- }
820
-
821
- .fortune-selection-highlight-lb {
822
- left: -3px;
823
- bottom: -3px;
824
- cursor: ne-resize;
825
- }
826
-
827
- .fortune-selection-highlight-rb {
828
- right: -3px;
829
- bottom: -3px;
830
- cursor: se-resize;
831
- }
832
-
833
- /* FLV: show blue dashed border for active selection while in edit mode */
834
- .luckysheet-cell-selected-edit-mode .luckysheet-cs-inner-border {
835
- border: 2px dashed #12a5ff;
836
- border-radius: 1px;
837
- }
838
-
839
- .fortune-formula-functionrange-highlight .luckysheet-highlight {
840
- position: absolute;
841
- z-index: 19;
842
- border: 1px solid #fff;
843
- background: #0188fb;
844
- width: 6px;
845
- height: 6px;
846
- }
847
-
848
809
  .fortune-presence-username {
849
810
  position: absolute;
850
811
  padding-left: 6px;
@@ -37,6 +37,22 @@ var __assign = void 0 && (void 0).__assign || function () {
37
37
  };
38
38
  return __assign.apply(this, arguments);
39
39
  };
40
+ function formulaRangeHighlightHcStyle(hex) {
41
+ var h = hex.replace("#", "");
42
+ if (h.length !== 6) {
43
+ return {
44
+ backgroundColor: hex,
45
+ borderColor: hex
46
+ };
47
+ }
48
+ var r = parseInt(h.slice(0, 2), 16);
49
+ var g = parseInt(h.slice(2, 4), 16);
50
+ var b = parseInt(h.slice(4, 6), 16);
51
+ return {
52
+ backgroundColor: "rgba(".concat(r, ",").concat(g, ",").concat(b, ",0.08)"),
53
+ borderColor: hex
54
+ };
55
+ }
40
56
  var SheetOverlay = function SheetOverlay() {
41
57
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
42
58
  var _o = (0, _react.useContext)(_context.default),
@@ -58,6 +74,7 @@ var SheetOverlay = function SheetOverlay() {
58
74
  setContext(function (draftCtx) {
59
75
  var _a;
60
76
  (0, _fortuneCore.handleCellAreaMouseDown)(draftCtx, refs.globalCache, nativeEvent, refs.cellInput.current, refs.cellArea.current, refs.fxInput.current, refs.canvas.current.getContext("2d"));
77
+ var keepFormulaBarFocused = draftCtx.luckysheetCellUpdate.length > 0 && draftCtx.formulaCache.formulaEditorOwner === "fx" && (draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start || (0, _fortuneCore.israngeseleciton)(draftCtx));
61
78
  if (!_lodash.default.isEmpty((_a = draftCtx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) && refs.cellInput.current) {
62
79
  if (!(0, _fortuneCore.isAllowEdit)(draftCtx)) {
63
80
  setTimeout(function () {
@@ -69,7 +86,13 @@ var SheetOverlay = function SheetOverlay() {
69
86
  } else {
70
87
  setTimeout(function () {
71
88
  var _a;
72
- (_a = refs.cellInput.current) === null || _a === void 0 ? void 0 : _a.focus();
89
+ if (keepFormulaBarFocused && refs.fxInput.current) {
90
+ refs.fxInput.current.focus({
91
+ preventScroll: true
92
+ });
93
+ } else {
94
+ (_a = refs.cellInput.current) === null || _a === void 0 ? void 0 : _a.focus();
95
+ }
73
96
  });
74
97
  }
75
98
  }
@@ -299,18 +322,7 @@ var SheetOverlay = function SheetOverlay() {
299
322
  });
300
323
  }), /*#__PURE__*/_react.default.createElement("div", {
301
324
  className: "fortune-selection-copy-hc",
302
- style: {
303
- backgroundColor: backgroundColor
304
- }
305
- }), ["lt", "rt", "lb", "rb"].map(function (d) {
306
- return /*#__PURE__*/_react.default.createElement("div", {
307
- key: d,
308
- "data-type": d,
309
- className: "fortune-selection-highlight-".concat(d, " luckysheet-highlight"),
310
- style: {
311
- backgroundColor: backgroundColor
312
- }
313
- });
325
+ style: formulaRangeHighlightHcStyle(backgroundColor)
314
326
  }));
315
327
  }), /*#__PURE__*/_react.default.createElement("div", {
316
328
  className: "luckysheet-row-count-show luckysheet-count-show",
@@ -372,7 +372,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
372
372
  var history = globalCache.current.undoList.pop();
373
373
  if (history) {
374
374
  setContext(function (ctx_) {
375
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
375
+ var _a, _b, _c, _d, _e, _f, _g, _h;
376
376
  var isBorderUndo = history.patches.some(function (onePatch) {
377
377
  var _a;
378
378
  return (_a = onePatch.value) === null || _a === void 0 ? void 0 : _a.borderInfo;
@@ -407,18 +407,15 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
407
407
  };
408
408
  inversedOptions.addSheet.value.celldata = dataToCelldata((_e = inversedOptions.addSheet.value) === null || _e === void 0 ? void 0 : _e.data);
409
409
  delete inversedOptions.addSheet.value.data;
410
- if ((_f = ctx_.hooks) === null || _f === void 0 ? void 0 : _f.afterOrderChanges) {
411
- ctx_.hooks.afterOrderChanges();
412
- }
413
410
  }
414
411
  emitOp(newContext, history.inversePatches, inversedOptions, true);
415
412
  emitYjsFromPatches(ctx_, newContext, history.inversePatches);
416
413
  var sheetIdxAfterUndo = (0, _fortuneCore.getSheetIndex)(newContext, newContext.currentSheetId);
417
- var nw = __assign(__assign({}, newContext), sheetIdxAfterUndo != null && ((_g = newContext.luckysheetfile[sheetIdxAfterUndo]) === null || _g === void 0 ? void 0 : _g.config) != null ? {
414
+ var nw = __assign(__assign({}, newContext), sheetIdxAfterUndo != null && ((_f = newContext.luckysheetfile[sheetIdxAfterUndo]) === null || _f === void 0 ? void 0 : _f.config) != null ? {
418
415
  config: newContext.luckysheetfile[sheetIdxAfterUndo].config
419
416
  } : {});
420
417
  if (isBorderUndo) {
421
- var nwborderlist = (_j = (_h = nw === null || nw === void 0 ? void 0 : nw.config) === null || _h === void 0 ? void 0 : _h.borderInfo) === null || _j === void 0 ? void 0 : _j.slice(0, -1);
418
+ var nwborderlist = (_h = (_g = nw === null || nw === void 0 ? void 0 : nw.config) === null || _g === void 0 ? void 0 : _g.borderInfo) === null || _h === void 0 ? void 0 : _h.slice(0, -1);
422
419
  nw = __assign(__assign({}, nw), {
423
420
  config: __assign(__assign({}, nw.config), {
424
421
  borderInfo: nwborderlist
@@ -896,7 +893,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
896
893
  });
897
894
  }
898
895
  var nativeEvent = e.nativeEvent;
899
- if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
896
+ if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ" && context.luckysheetCellUpdate.length === 0) {
900
897
  if (e.shiftKey) {
901
898
  handleRedo();
902
899
  } else {
@@ -905,7 +902,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
905
902
  e.stopPropagation();
906
903
  return;
907
904
  }
908
- if ((e.ctrlKey || e.metaKey) && e.code === "KeyY") {
905
+ if ((e.ctrlKey || e.metaKey) && e.code === "KeyY" && context.luckysheetCellUpdate.length === 0) {
909
906
  handleRedo();
910
907
  e.stopPropagation();
911
908
  e.preventDefault();
@@ -0,0 +1,24 @@
1
+ import { type RefObject } from "react";
2
+ import { type Context } from "@fileverse-dev/fortune-core";
3
+ import type { SetContextOptions } from "../context";
4
+ export type FormulaHistoryEntry = {
5
+ text: string;
6
+ caret: number;
7
+ spanValues: string[];
8
+ };
9
+ export type FormulaEditorHistoryPrimary = "cell" | "fx";
10
+ type SetContext = (recipe: (ctx: Context) => void, options?: SetContextOptions) => void;
11
+ export declare function useFormulaEditorHistory(primaryRef: RefObject<HTMLDivElement | null>, cellInputRef: RefObject<HTMLDivElement | null>, fxInputRef: RefObject<HTMLDivElement | null>, setContext: SetContext, primary: FormulaEditorHistoryPrimary): {
12
+ formulaHistoryRef: RefObject<{
13
+ active: boolean;
14
+ entries: FormulaHistoryEntry[];
15
+ index: number;
16
+ }>;
17
+ preTextRef: RefObject<string>;
18
+ preFormulaSpanValuesRef: RefObject<string[] | null>;
19
+ resetFormulaHistory: () => void;
20
+ handleFormulaHistoryUndoRedo: (isRedo: boolean) => boolean;
21
+ capturePreFormulaState: () => void;
22
+ appendFormulaHistoryFromPrimaryEditor: (getCaret: () => number) => void;
23
+ };
24
+ export {};