@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
|
@@ -8,16 +8,35 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
|
8
8
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
9
|
};
|
|
10
10
|
import { useContext, useRef } from "react";
|
|
11
|
-
import { fixPositionOnFrozenCells, getSheetIndex, getFlowdata, colLocation, colLocationByIndex, updateContextWithSheetData, api } from "@fileverse-dev/fortune-core";
|
|
11
|
+
import { fixPositionOnFrozenCells, getSheetIndex, getFlowdata, colLocation, colLocationByIndex, updateContextWithSheetData, api, indexToColumnChar, columnCharToIndex } from "@fileverse-dev/fortune-core";
|
|
12
12
|
import WorkbookContext from "../../../context";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
var REF_TOKEN_REGEX = /((?:'(?:[^']|'')+'|[A-Za-z_][A-Za-z0-9_.]*)!)?(\$?)([A-Za-z]+)(\$?)(\d+)(?::(\$?)([A-Za-z]+)(\$?)(\d+))?/g;
|
|
14
|
+
function normalizeSheetName(raw) {
|
|
15
|
+
if (!raw) return "";
|
|
16
|
+
var noBang = raw.endsWith("!") ? raw.slice(0, -1) : raw;
|
|
17
|
+
if (noBang.startsWith("'") && noBang.endsWith("'")) {
|
|
18
|
+
return noBang.slice(1, -1).replace(/''/g, "'");
|
|
19
19
|
}
|
|
20
|
-
return
|
|
20
|
+
return noBang;
|
|
21
|
+
}
|
|
22
|
+
function remapFormulaCols(formula, formulaSheetName, movedSheetName, colMap) {
|
|
23
|
+
return formula.replace(REF_TOKEN_REGEX, function (token, sheetPrefix, colAbs0, col0, rowAbs0, row0, colAbs1, col1, rowAbs1, row1) {
|
|
24
|
+
var refSheet = normalizeSheetName(sheetPrefix) || formulaSheetName;
|
|
25
|
+
if (refSheet !== movedSheetName) return token;
|
|
26
|
+
var colIdx0 = columnCharToIndex(col0);
|
|
27
|
+
var mapped0 = colMap[colIdx0];
|
|
28
|
+
var nextCol0 = mapped0 == null ? col0 : indexToColumnChar(mapped0);
|
|
29
|
+
if (!col1) {
|
|
30
|
+
return "".concat(sheetPrefix || "").concat(colAbs0).concat(nextCol0).concat(rowAbs0).concat(row0);
|
|
31
|
+
}
|
|
32
|
+
var colIdx1 = columnCharToIndex(col1);
|
|
33
|
+
var mapped1 = colMap[colIdx1];
|
|
34
|
+
var nextCol1 = mapped1 == null ? col1 : indexToColumnChar(mapped1);
|
|
35
|
+
return "".concat(sheetPrefix || "").concat(colAbs0).concat(nextCol0).concat(rowAbs0).concat(row0, ":").concat(colAbs1).concat(nextCol1).concat(rowAbs1).concat(row1);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export function numberToColumnName(num) {
|
|
39
|
+
return indexToColumnChar(num);
|
|
21
40
|
}
|
|
22
41
|
export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, selectedLocationRef) {
|
|
23
42
|
var DOUBLE_CLICK_MS = 300;
|
|
@@ -258,62 +277,29 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
|
|
|
258
277
|
d === null || d === void 0 ? void 0 : d.forEach(function (row) {
|
|
259
278
|
row.forEach(function (cell) {
|
|
260
279
|
if (cell) {
|
|
261
|
-
var
|
|
280
|
+
var colMap_1 = {};
|
|
262
281
|
if (sourceIndex_1 < targetIndex) {
|
|
263
282
|
var start = selectedSourceCol === null || selectedSourceCol === void 0 ? void 0 : selectedSourceCol[selectedSourceCol.length - 1];
|
|
264
283
|
var last = selectedTargetCol === null || selectedTargetCol === void 0 ? void 0 : selectedTargetCol[selectedTargetCol.length - 1];
|
|
265
284
|
for (var c = start + 1; c <= last; c += 1) {
|
|
266
|
-
|
|
267
|
-
source: numberToColumnName(c),
|
|
268
|
-
target: numberToColumnName(c - selectedSourceCol.length)
|
|
269
|
-
});
|
|
285
|
+
colMap_1[c] = c - selectedSourceCol.length;
|
|
270
286
|
}
|
|
271
287
|
selectedSourceCol.forEach(function (c, index) {
|
|
272
|
-
|
|
273
|
-
source: numberToColumnName(c),
|
|
274
|
-
target: numberToColumnName(selectedTargetCol[index])
|
|
275
|
-
});
|
|
288
|
+
colMap_1[c] = selectedTargetCol[index];
|
|
276
289
|
});
|
|
277
290
|
} else if (sourceIndex_1 > targetIndex) {
|
|
278
291
|
var start = selectedTargetCol === null || selectedTargetCol === void 0 ? void 0 : selectedTargetCol[0];
|
|
279
292
|
var last = selectedSourceCol === null || selectedSourceCol === void 0 ? void 0 : selectedSourceCol[0];
|
|
280
293
|
for (var c = start; c < last; c += 1) {
|
|
281
|
-
|
|
282
|
-
source: numberToColumnName(c),
|
|
283
|
-
target: numberToColumnName(c + selectedSourceCol.length)
|
|
284
|
-
});
|
|
294
|
+
colMap_1[c] = c + selectedSourceCol.length;
|
|
285
295
|
}
|
|
286
296
|
selectedSourceCol.forEach(function (c, index) {
|
|
287
|
-
|
|
288
|
-
source: numberToColumnName(c),
|
|
289
|
-
target: numberToColumnName(selectedTargetCol[index])
|
|
290
|
-
});
|
|
297
|
+
colMap_1[c] = selectedTargetCol[index];
|
|
291
298
|
});
|
|
292
299
|
}
|
|
293
300
|
if (cell.f) {
|
|
294
|
-
var
|
|
295
|
-
|
|
296
|
-
otherAffectedCols_1.forEach(function (col) {
|
|
297
|
-
var regex = new RegExp("\\b".concat(col.source, "(\\d+)\\b"), "g");
|
|
298
|
-
var match;
|
|
299
|
-
while ((match = regex.exec(formula_1)) !== null) {
|
|
300
|
-
if (/^\d+$/.test(match[1])) {
|
|
301
|
-
replacements_1.push({
|
|
302
|
-
start: match.index,
|
|
303
|
-
end: match.index + match[0].length,
|
|
304
|
-
original: match[0],
|
|
305
|
-
replacement: "".concat(col.target).concat(match[1])
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
replacements_1 === null || replacements_1 === void 0 ? void 0 : replacements_1.sort(function (a, b) {
|
|
311
|
-
return b.start - a.start;
|
|
312
|
-
});
|
|
313
|
-
replacements_1 === null || replacements_1 === void 0 ? void 0 : replacements_1.forEach(function (rep) {
|
|
314
|
-
formula_1 = formula_1.substring(0, rep.start) + rep.replacement + formula_1.substring(rep.end);
|
|
315
|
-
});
|
|
316
|
-
cell.f = formula_1;
|
|
301
|
+
var sheetName = _sheet.name || "";
|
|
302
|
+
cell.f = remapFormulaCols(cell.f, sheetName, sheetName, colMap_1);
|
|
317
303
|
}
|
|
318
304
|
}
|
|
319
305
|
});
|
|
@@ -10,6 +10,29 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
|
10
10
|
import { useContext, useRef } from "react";
|
|
11
11
|
import { fixPositionOnFrozenCells, getSheetIndex, rowLocation, getFlowdata, rowLocationByIndex, updateContextWithSheetData, api } from "@fileverse-dev/fortune-core";
|
|
12
12
|
import WorkbookContext from "../../../context";
|
|
13
|
+
var REF_TOKEN_REGEX = /((?:'(?:[^']|'')+'|[A-Za-z_][A-Za-z0-9_.]*)!)?(\$?)([A-Za-z]+)(\$?)(\d+)(?::(\$?)([A-Za-z]+)(\$?)(\d+))?/g;
|
|
14
|
+
function normalizeSheetName(raw) {
|
|
15
|
+
if (!raw) return "";
|
|
16
|
+
var noBang = raw.endsWith("!") ? raw.slice(0, -1) : raw;
|
|
17
|
+
if (noBang.startsWith("'") && noBang.endsWith("'")) {
|
|
18
|
+
return noBang.slice(1, -1).replace(/''/g, "'");
|
|
19
|
+
}
|
|
20
|
+
return noBang;
|
|
21
|
+
}
|
|
22
|
+
function remapFormulaRows(formula, formulaSheetName, movedSheetName, rowMap) {
|
|
23
|
+
return formula.replace(REF_TOKEN_REGEX, function (token, sheetPrefix, colAbs0, col0, rowAbs0, row0, colAbs1, col1, rowAbs1, row1) {
|
|
24
|
+
var refSheet = normalizeSheetName(sheetPrefix) || formulaSheetName;
|
|
25
|
+
if (refSheet !== movedSheetName) return token;
|
|
26
|
+
var mapped0 = rowMap[parseInt(row0, 10) - 1];
|
|
27
|
+
var nextRow0 = mapped0 == null ? parseInt(row0, 10) : mapped0 + 1;
|
|
28
|
+
if (!row1) {
|
|
29
|
+
return "".concat(sheetPrefix || "").concat(colAbs0).concat(col0).concat(rowAbs0).concat(nextRow0);
|
|
30
|
+
}
|
|
31
|
+
var mapped1 = rowMap[parseInt(row1, 10) - 1];
|
|
32
|
+
var nextRow1 = mapped1 == null ? parseInt(row1, 10) : mapped1 + 1;
|
|
33
|
+
return "".concat(sheetPrefix || "").concat(colAbs0).concat(col0).concat(rowAbs0).concat(nextRow0, ":").concat(colAbs1).concat(col1).concat(rowAbs1).concat(nextRow1);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
13
36
|
export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selectedLocationRef) {
|
|
14
37
|
var DOUBLE_MS = 300;
|
|
15
38
|
var START_DRAG_THRESHOLD_PX = 6;
|
|
@@ -248,62 +271,29 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
|
|
|
248
271
|
d === null || d === void 0 ? void 0 : d.forEach(function (row) {
|
|
249
272
|
row.forEach(function (cell) {
|
|
250
273
|
if (cell) {
|
|
251
|
-
var
|
|
274
|
+
var rowMap_1 = {};
|
|
252
275
|
if (sourceIndex_1 < targetIndex) {
|
|
253
276
|
var start = selectedSourceRow === null || selectedSourceRow === void 0 ? void 0 : selectedSourceRow[selectedSourceRow.length - 1];
|
|
254
277
|
var last = selectedTargetRow === null || selectedTargetRow === void 0 ? void 0 : selectedTargetRow[selectedTargetRow.length - 1];
|
|
255
278
|
for (var c = start + 1; c < last; c += 1) {
|
|
256
|
-
|
|
257
|
-
source: c,
|
|
258
|
-
target: c - selectedSourceRow.length
|
|
259
|
-
});
|
|
279
|
+
rowMap_1[c] = c - selectedSourceRow.length;
|
|
260
280
|
}
|
|
261
281
|
selectedSourceRow.forEach(function (c, index) {
|
|
262
|
-
|
|
263
|
-
source: c,
|
|
264
|
-
target: selectedTargetRow[index]
|
|
265
|
-
});
|
|
282
|
+
rowMap_1[c] = selectedTargetRow[index];
|
|
266
283
|
});
|
|
267
284
|
} else {
|
|
268
285
|
var start = selectedTargetRow === null || selectedTargetRow === void 0 ? void 0 : selectedTargetRow[0];
|
|
269
286
|
var last = selectedSourceRow === null || selectedSourceRow === void 0 ? void 0 : selectedSourceRow[0];
|
|
270
287
|
for (var c = start; c < last; c += 1) {
|
|
271
|
-
|
|
272
|
-
source: c,
|
|
273
|
-
target: c + +selectedSourceRow.length
|
|
274
|
-
});
|
|
288
|
+
rowMap_1[c] = c + selectedSourceRow.length;
|
|
275
289
|
}
|
|
276
290
|
selectedSourceRow.forEach(function (c, index) {
|
|
277
|
-
|
|
278
|
-
source: c,
|
|
279
|
-
target: selectedTargetRow[index]
|
|
280
|
-
});
|
|
291
|
+
rowMap_1[c] = selectedTargetRow[index];
|
|
281
292
|
});
|
|
282
293
|
}
|
|
283
294
|
if (cell.f) {
|
|
284
|
-
var
|
|
285
|
-
|
|
286
|
-
otherAffectedRows_1.forEach(function (_a) {
|
|
287
|
-
var source = _a.source,
|
|
288
|
-
target = _a.target;
|
|
289
|
-
var regex = new RegExp("\\b([A-Z]+)".concat(source, "\\b"), "g");
|
|
290
|
-
var match;
|
|
291
|
-
while ((match = regex.exec(formula_1)) !== null) {
|
|
292
|
-
replacements_1.push({
|
|
293
|
-
start: match.index,
|
|
294
|
-
end: match.index + match[0].length,
|
|
295
|
-
original: match[0],
|
|
296
|
-
replacement: "".concat(match[1]).concat(target)
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
replacements_1.sort(function (a, b) {
|
|
301
|
-
return b.start - a.start;
|
|
302
|
-
});
|
|
303
|
-
replacements_1.forEach(function (rep) {
|
|
304
|
-
formula_1 = formula_1.substring(0, rep.start) + rep.replacement + formula_1.substring(rep.end);
|
|
305
|
-
});
|
|
306
|
-
cell.f = formula_1;
|
|
295
|
+
var sheetName = _sheet.name || "";
|
|
296
|
+
cell.f = remapFormulaRows(cell.f, sheetName, sheetName, rowMap_1);
|
|
307
297
|
}
|
|
308
298
|
}
|
|
309
299
|
});
|
|
@@ -355,7 +345,7 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
|
|
|
355
345
|
}
|
|
356
346
|
(_d = _sheet.calcChain) === null || _d === void 0 ? void 0 : _d.forEach(function (item) {
|
|
357
347
|
if (selectedSourceRow.includes(item.r)) {
|
|
358
|
-
var index = selectedSourceRow.indexOf(item.
|
|
348
|
+
var index = selectedSourceRow.indexOf(item.r);
|
|
359
349
|
item.r = selectedTargetRow[index];
|
|
360
350
|
} else if (item.r > sourceIndex_1 && item.r < targetIndex) {
|
|
361
351
|
item.r -= selectedSourceRow.length;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isFormulaSegmentBoundaryKey(key: string): boolean;
|
|
@@ -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;
|
|
@@ -18,10 +18,105 @@ export function getCursorPosition(editableDiv) {
|
|
|
18
18
|
preRange.setEnd(range.endContainer, range.endOffset);
|
|
19
19
|
return preRange.toString().length;
|
|
20
20
|
}
|
|
21
|
+
export function setCursorPosition(editableDiv, targetOffset) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
editableDiv.focus();
|
|
24
|
+
var selection = window.getSelection();
|
|
25
|
+
if (!selection) return;
|
|
26
|
+
var range = document.createRange();
|
|
27
|
+
var walker = document.createTreeWalker(editableDiv, NodeFilter.SHOW_TEXT);
|
|
28
|
+
var remaining = Math.max(0, targetOffset);
|
|
29
|
+
var node = walker.nextNode();
|
|
30
|
+
while (node) {
|
|
31
|
+
var textLength = (_b = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
32
|
+
if (remaining <= textLength) {
|
|
33
|
+
range.setStart(node, remaining);
|
|
34
|
+
range.collapse(true);
|
|
35
|
+
selection.removeAllRanges();
|
|
36
|
+
selection.addRange(range);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
remaining -= textLength;
|
|
40
|
+
node = walker.nextNode();
|
|
41
|
+
}
|
|
42
|
+
range.selectNodeContents(editableDiv);
|
|
43
|
+
range.collapse(false);
|
|
44
|
+
selection.removeAllRanges();
|
|
45
|
+
selection.addRange(range);
|
|
46
|
+
}
|
|
47
|
+
export function buildFormulaSuggestionText(editableDiv, formulaName) {
|
|
48
|
+
var fullText = editableDiv.innerText || "";
|
|
49
|
+
var selection = window.getSelection();
|
|
50
|
+
var selectionInEditor = !!(selection === null || selection === void 0 ? void 0 : selection.rangeCount) && editableDiv.contains(selection.getRangeAt(0).startContainer);
|
|
51
|
+
var caretOffset = selectionInEditor ? getCursorPosition(editableDiv) : fullText.length;
|
|
52
|
+
var safeCaretOffset = Math.max(0, Math.min(caretOffset, fullText.length));
|
|
53
|
+
var beforeCaret = fullText.slice(0, safeCaretOffset);
|
|
54
|
+
var afterCaret = fullText.slice(safeCaretOffset);
|
|
55
|
+
var replaceStart = safeCaretOffset;
|
|
56
|
+
var tokenMatch = beforeCaret.match(/[A-Za-z_][A-Za-z0-9_]*$/);
|
|
57
|
+
if (tokenMatch) {
|
|
58
|
+
var token = tokenMatch[0];
|
|
59
|
+
var tokenStart = safeCaretOffset - token.length;
|
|
60
|
+
var charBeforeToken = tokenStart > 0 ? beforeCaret[tokenStart - 1] : "";
|
|
61
|
+
if (tokenStart === 0 || /[\s=(,+\-*/&^<>]$/.test(charBeforeToken)) {
|
|
62
|
+
replaceStart = tokenStart;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
var shouldAddOpeningParen = !afterCaret.startsWith("(");
|
|
66
|
+
var insertedText = "".concat(formulaName).concat(shouldAddOpeningParen ? "(" : "");
|
|
67
|
+
var nextText = fullText.slice(0, replaceStart) + insertedText + afterCaret;
|
|
68
|
+
return {
|
|
69
|
+
text: nextText,
|
|
70
|
+
caretOffset: replaceStart + insertedText.length
|
|
71
|
+
};
|
|
72
|
+
}
|
|
21
73
|
export function isLetterNumberPattern(str) {
|
|
22
74
|
var regex = /^[a-zA-Z]+\d+$/;
|
|
23
75
|
return regex.test(str);
|
|
24
76
|
}
|
|
77
|
+
export function shouldShowFormulaFunctionList(editor) {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
if (!editor) return false;
|
|
80
|
+
if (!((_a = editor.innerText) === null || _a === void 0 ? void 0 : _a.includes("="))) return false;
|
|
81
|
+
var parser = new DOMParser();
|
|
82
|
+
var doc = parser.parseFromString("<div>".concat(editor.innerHTML, "</div>"), "text/html");
|
|
83
|
+
var spans = doc.querySelectorAll("span");
|
|
84
|
+
var lastSpan = spans[spans.length - 1];
|
|
85
|
+
var lastText = (_b = lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) !== null && _b !== void 0 ? _b : "";
|
|
86
|
+
return /^=?[A-Za-z]*$/.test(lastText);
|
|
87
|
+
}
|
|
88
|
+
var FORMULA_FUNC_CLASS = "luckysheet-formula-text-func";
|
|
89
|
+
var FORMULA_LPAR_CLASS = "luckysheet-formula-text-lpar";
|
|
90
|
+
export function getFunctionNameFromFormulaCaretSpans(editor) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
if (!editor) return null;
|
|
93
|
+
var sel = window.getSelection();
|
|
94
|
+
if (!(sel === null || sel === void 0 ? void 0 : sel.rangeCount)) return null;
|
|
95
|
+
var range = sel.getRangeAt(0);
|
|
96
|
+
if (!editor.contains(range.startContainer)) return null;
|
|
97
|
+
var n = range.startContainer;
|
|
98
|
+
while (n && n !== editor) {
|
|
99
|
+
if (n.nodeType === Node.ELEMENT_NODE) {
|
|
100
|
+
var elem = n;
|
|
101
|
+
if (elem.classList.contains(FORMULA_FUNC_CLASS)) {
|
|
102
|
+
var next = elem.nextElementSibling;
|
|
103
|
+
if (next === null || next === void 0 ? void 0 : next.classList.contains(FORMULA_LPAR_CLASS)) {
|
|
104
|
+
var name_1 = (_a = elem.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
105
|
+
return name_1 ? name_1.toUpperCase() : null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (elem.classList.contains(FORMULA_LPAR_CLASS)) {
|
|
109
|
+
var prev = elem.previousElementSibling;
|
|
110
|
+
if (prev === null || prev === void 0 ? void 0 : prev.classList.contains(FORMULA_FUNC_CLASS)) {
|
|
111
|
+
var name_2 = (_b = prev.textContent) === null || _b === void 0 ? void 0 : _b.trim();
|
|
112
|
+
return name_2 ? name_2.toUpperCase() : null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
n = n.parentNode;
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
25
120
|
export function removeLastSpan(htmlString) {
|
|
26
121
|
var container = document.createElement("div");
|
|
27
122
|
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:
|
|
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
|
|
805
|
-
|
|
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;
|
|
@@ -10,7 +10,7 @@ var __assign = this && this.__assign || function () {
|
|
|
10
10
|
};
|
|
11
11
|
import React, { useContext, useCallback, useRef, useEffect, useLayoutEffect, useMemo } from "react";
|
|
12
12
|
import "./index.css";
|
|
13
|
-
import { locale, drawArrow, handleCellAreaDoubleClick, handleCellAreaMouseDown, handleContextMenu, handleOverlayMouseMove, handleOverlayMouseUp, selectAll, handleOverlayTouchEnd, handleOverlayTouchStart, createDropCellRange, getCellRowColumn, getCellHyperlink, showLinkCard, isAllowEdit, onCellsMoveStart, insertRowCol, getSheetIndex, fixRowStyleOverflowInFreeze, fixColumnStyleOverflowInFreeze, handleKeydownForZoom } from "@fileverse-dev/fortune-core";
|
|
13
|
+
import { locale, drawArrow, handleCellAreaDoubleClick, handleCellAreaMouseDown, handleContextMenu, handleOverlayMouseMove, handleOverlayMouseUp, selectAll, handleOverlayTouchEnd, handleOverlayTouchStart, createDropCellRange, getCellRowColumn, getCellHyperlink, showLinkCard, isAllowEdit, israngeseleciton, onCellsMoveStart, insertRowCol, getSheetIndex, fixRowStyleOverflowInFreeze, fixColumnStyleOverflowInFreeze, handleKeydownForZoom } from "@fileverse-dev/fortune-core";
|
|
14
14
|
import _ from "lodash";
|
|
15
15
|
import WorkbookContext from "../../context";
|
|
16
16
|
import ColumnHeader from "./ColumnHeader";
|
|
@@ -28,6 +28,22 @@ import { useDialog } from "../../hooks/useDialog";
|
|
|
28
28
|
import DropDownList from "../DataVerification/DropdownList";
|
|
29
29
|
import IframeBoxs from "../IFrameBoxs/iFrameBoxs";
|
|
30
30
|
import ErrorBoxes from "../ErrorState";
|
|
31
|
+
function formulaRangeHighlightHcStyle(hex) {
|
|
32
|
+
var h = hex.replace("#", "");
|
|
33
|
+
if (h.length !== 6) {
|
|
34
|
+
return {
|
|
35
|
+
backgroundColor: hex,
|
|
36
|
+
borderColor: hex
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var r = parseInt(h.slice(0, 2), 16);
|
|
40
|
+
var g = parseInt(h.slice(2, 4), 16);
|
|
41
|
+
var b = parseInt(h.slice(4, 6), 16);
|
|
42
|
+
return {
|
|
43
|
+
backgroundColor: "rgba(".concat(r, ",").concat(g, ",").concat(b, ",0.08)"),
|
|
44
|
+
borderColor: hex
|
|
45
|
+
};
|
|
46
|
+
}
|
|
31
47
|
var SheetOverlay = function SheetOverlay() {
|
|
32
48
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
33
49
|
var _o = useContext(WorkbookContext),
|
|
@@ -49,6 +65,7 @@ var SheetOverlay = function SheetOverlay() {
|
|
|
49
65
|
setContext(function (draftCtx) {
|
|
50
66
|
var _a;
|
|
51
67
|
handleCellAreaMouseDown(draftCtx, refs.globalCache, nativeEvent, refs.cellInput.current, refs.cellArea.current, refs.fxInput.current, refs.canvas.current.getContext("2d"));
|
|
68
|
+
var keepFormulaBarFocused = draftCtx.luckysheetCellUpdate.length > 0 && draftCtx.formulaCache.formulaEditorOwner === "fx" && (draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start || israngeseleciton(draftCtx));
|
|
52
69
|
if (!_.isEmpty((_a = draftCtx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) && refs.cellInput.current) {
|
|
53
70
|
if (!isAllowEdit(draftCtx)) {
|
|
54
71
|
setTimeout(function () {
|
|
@@ -60,7 +77,13 @@ var SheetOverlay = function SheetOverlay() {
|
|
|
60
77
|
} else {
|
|
61
78
|
setTimeout(function () {
|
|
62
79
|
var _a;
|
|
63
|
-
(
|
|
80
|
+
if (keepFormulaBarFocused && refs.fxInput.current) {
|
|
81
|
+
refs.fxInput.current.focus({
|
|
82
|
+
preventScroll: true
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
(_a = refs.cellInput.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
86
|
+
}
|
|
64
87
|
});
|
|
65
88
|
}
|
|
66
89
|
}
|
|
@@ -290,18 +313,7 @@ var SheetOverlay = function SheetOverlay() {
|
|
|
290
313
|
});
|
|
291
314
|
}), /*#__PURE__*/React.createElement("div", {
|
|
292
315
|
className: "fortune-selection-copy-hc",
|
|
293
|
-
style:
|
|
294
|
-
backgroundColor: backgroundColor
|
|
295
|
-
}
|
|
296
|
-
}), ["lt", "rt", "lb", "rb"].map(function (d) {
|
|
297
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
298
|
-
key: d,
|
|
299
|
-
"data-type": d,
|
|
300
|
-
className: "fortune-selection-highlight-".concat(d, " luckysheet-highlight"),
|
|
301
|
-
style: {
|
|
302
|
-
backgroundColor: backgroundColor
|
|
303
|
-
}
|
|
304
|
-
});
|
|
316
|
+
style: formulaRangeHighlightHcStyle(backgroundColor)
|
|
305
317
|
}));
|
|
306
318
|
}), /*#__PURE__*/React.createElement("div", {
|
|
307
319
|
className: "luckysheet-row-count-show luckysheet-count-show",
|
|
@@ -363,7 +363,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
363
363
|
var history = globalCache.current.undoList.pop();
|
|
364
364
|
if (history) {
|
|
365
365
|
setContext(function (ctx_) {
|
|
366
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
366
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
367
367
|
var isBorderUndo = history.patches.some(function (onePatch) {
|
|
368
368
|
var _a;
|
|
369
369
|
return (_a = onePatch.value) === null || _a === void 0 ? void 0 : _a.borderInfo;
|
|
@@ -398,18 +398,15 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
398
398
|
};
|
|
399
399
|
inversedOptions.addSheet.value.celldata = dataToCelldata((_e = inversedOptions.addSheet.value) === null || _e === void 0 ? void 0 : _e.data);
|
|
400
400
|
delete inversedOptions.addSheet.value.data;
|
|
401
|
-
if ((_f = ctx_.hooks) === null || _f === void 0 ? void 0 : _f.afterOrderChanges) {
|
|
402
|
-
ctx_.hooks.afterOrderChanges();
|
|
403
|
-
}
|
|
404
401
|
}
|
|
405
402
|
emitOp(newContext, history.inversePatches, inversedOptions, true);
|
|
406
403
|
emitYjsFromPatches(ctx_, newContext, history.inversePatches);
|
|
407
404
|
var sheetIdxAfterUndo = getSheetIndex(newContext, newContext.currentSheetId);
|
|
408
|
-
var nw = __assign(__assign({}, newContext), sheetIdxAfterUndo != null && ((
|
|
405
|
+
var nw = __assign(__assign({}, newContext), sheetIdxAfterUndo != null && ((_f = newContext.luckysheetfile[sheetIdxAfterUndo]) === null || _f === void 0 ? void 0 : _f.config) != null ? {
|
|
409
406
|
config: newContext.luckysheetfile[sheetIdxAfterUndo].config
|
|
410
407
|
} : {});
|
|
411
408
|
if (isBorderUndo) {
|
|
412
|
-
var nwborderlist = (
|
|
409
|
+
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);
|
|
413
410
|
nw = __assign(__assign({}, nw), {
|
|
414
411
|
config: __assign(__assign({}, nw.config), {
|
|
415
412
|
borderInfo: nwborderlist
|
|
@@ -887,7 +884,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
887
884
|
});
|
|
888
885
|
}
|
|
889
886
|
var nativeEvent = e.nativeEvent;
|
|
890
|
-
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
|
|
887
|
+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ" && context.luckysheetCellUpdate.length === 0) {
|
|
891
888
|
if (e.shiftKey) {
|
|
892
889
|
handleRedo();
|
|
893
890
|
} else {
|
|
@@ -896,7 +893,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
896
893
|
e.stopPropagation();
|
|
897
894
|
return;
|
|
898
895
|
}
|
|
899
|
-
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY") {
|
|
896
|
+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY" && context.luckysheetCellUpdate.length === 0) {
|
|
900
897
|
handleRedo();
|
|
901
898
|
e.stopPropagation();
|
|
902
899
|
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 {};
|