@fileverse-dev/fortune-react 1.3.12 → 1.3.13-create-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/ConditionFormat/ConditionRules.js +15 -5
- package/es/components/ConditionFormat/index.js +3 -0
- package/es/components/ContextMenu/index.js +1 -1
- package/es/components/DataVerification/ColorPicker.js +1 -1
- package/es/components/FxEditor/index.js +316 -60
- package/es/components/SheetOverlay/FormulaHint/index.js +46 -25
- package/es/components/SheetOverlay/FormulaSearch/index.d.ts +3 -1
- package/es/components/SheetOverlay/FormulaSearch/index.js +58 -29
- package/es/components/SheetOverlay/InputBox.js +409 -160
- package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +34 -48
- package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +31 -41
- package/es/components/SheetOverlay/formula-segment-boundary.d.ts +1 -0
- package/es/components/SheetOverlay/formula-segment-boundary.js +4 -0
- package/es/components/SheetOverlay/helper.d.ts +7 -0
- package/es/components/SheetOverlay/helper.js +95 -0
- package/es/components/SheetOverlay/index.css +6 -39
- package/es/components/SheetOverlay/index.js +29 -17
- package/es/components/Toolbar/index.js +17 -12
- package/es/components/Workbook/api.d.ts +3 -0
- package/es/components/Workbook/index.d.ts +3 -0
- package/es/components/Workbook/index.js +9 -3
- package/es/hooks/useFormulaEditorHistory.d.ts +24 -0
- package/es/hooks/useFormulaEditorHistory.js +119 -0
- package/es/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
- package/es/hooks/useRerenderOnFormulaCaret.js +28 -0
- package/lib/components/ConditionFormat/ConditionRules.js +15 -5
- package/lib/components/ConditionFormat/index.js +3 -0
- package/lib/components/ContextMenu/index.js +1 -1
- package/lib/components/DataVerification/ColorPicker.js +1 -1
- package/lib/components/FxEditor/index.js +314 -58
- package/lib/components/SheetOverlay/FormulaHint/index.js +45 -24
- package/lib/components/SheetOverlay/FormulaSearch/index.d.ts +3 -1
- package/lib/components/SheetOverlay/FormulaSearch/index.js +57 -28
- package/lib/components/SheetOverlay/InputBox.js +407 -158
- package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +33 -47
- package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +31 -41
- package/lib/components/SheetOverlay/formula-segment-boundary.d.ts +1 -0
- package/lib/components/SheetOverlay/formula-segment-boundary.js +10 -0
- package/lib/components/SheetOverlay/helper.d.ts +7 -0
- package/lib/components/SheetOverlay/helper.js +99 -0
- package/lib/components/SheetOverlay/index.css +6 -39
- package/lib/components/SheetOverlay/index.js +28 -16
- package/lib/components/Toolbar/index.js +16 -11
- package/lib/components/Workbook/api.d.ts +3 -0
- package/lib/components/Workbook/index.d.ts +3 -0
- package/lib/components/Workbook/index.js +8 -2
- package/lib/hooks/useFormulaEditorHistory.d.ts +24 -0
- package/lib/hooks/useFormulaEditorHistory.js +126 -0
- package/lib/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
- package/lib/hooks/useRerenderOnFormulaCaret.js +34 -0
- package/package.json +2 -2
|
@@ -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,44 +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
|
-
.fortune-formula-functionrange-highlight .luckysheet-highlight {
|
|
834
|
-
position: absolute;
|
|
835
|
-
z-index: 19;
|
|
836
|
-
border: 1px solid #fff;
|
|
837
|
-
background: #0188fb;
|
|
838
|
-
width: 6px;
|
|
839
|
-
height: 6px;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
809
|
.fortune-presence-username {
|
|
843
810
|
position: absolute;
|
|
844
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",
|
|
@@ -375,18 +387,18 @@ var SheetOverlay = function SheetOverlay() {
|
|
|
375
387
|
}), ((_h = (_g = context.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0) > 0 && (/*#__PURE__*/React.createElement("div", {
|
|
376
388
|
id: "luckysheet-cell-selected-boxs"
|
|
377
389
|
}, context.luckysheet_select_save.map(function (selection, index) {
|
|
378
|
-
var _a, _b;
|
|
390
|
+
var _a, _b, _c, _d;
|
|
379
391
|
return /*#__PURE__*/React.createElement("div", {
|
|
380
392
|
key: index,
|
|
381
393
|
id: "luckysheet-cell-selected",
|
|
382
|
-
className: "luckysheet-cell-selected",
|
|
394
|
+
className: "luckysheet-cell-selected".concat(((_b = (_a = context.luckysheetCellUpdate) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 ? " luckysheet-cell-selected-edit-mode" : ""),
|
|
383
395
|
style: _.assign({
|
|
384
396
|
left: selection.left_move,
|
|
385
397
|
top: selection.top_move,
|
|
386
398
|
width: selection.width_move ? selection.width_move - 1.8 : selection.width_move,
|
|
387
399
|
height: selection.height_move ? selection.height_move - 1.8 : selection.height_move,
|
|
388
400
|
display: "block"
|
|
389
|
-
}, fixRowStyleOverflowInFreeze(context, selection.row[0], selection.row[1], (
|
|
401
|
+
}, fixRowStyleOverflowInFreeze(context, selection.row[0], selection.row[1], (_c = refs.globalCache.freezen) === null || _c === void 0 ? void 0 : _c[context.currentSheetId]), fixColumnStyleOverflowInFreeze(context, selection.column[0], selection.column[1], (_d = refs.globalCache.freezen) === null || _d === void 0 ? void 0 : _d[context.currentSheetId])),
|
|
390
402
|
onMouseDown: function onMouseDown(e) {
|
|
391
403
|
e.stopPropagation();
|
|
392
404
|
var nativeEvent = e.nativeEvent;
|
|
@@ -123,7 +123,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
|
123
123
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
124
124
|
};
|
|
125
125
|
import React, { useContext, useCallback, useRef, useEffect, useState } from "react";
|
|
126
|
-
import { toolbarItemClickHandler, handleTextBackground, handleTextColor, handleTextSize, normalizedCellAttr, getFlowdata, newComment, editComment, deleteComment, showHideComment, showHideAllComments, autoSelectionFormula, handleSum, locale, handleMerge, handleBorder, toolbarItemSelectedFunc, handleFreeze, insertImage, showImgChooser, updateFormat, handleSort, handleHorizontalAlign, handleVerticalAlign, handleScreenShot, createFilter, clearFilter, applyLocation, insertDuneChart, api, getSheetIndex } from "@fileverse-dev/fortune-core";
|
|
126
|
+
import { toolbarItemClickHandler, handleTextBackground, handleTextColor, handleTextSize, normalizedCellAttr, getFlowdata, newComment, editComment, deleteComment, showHideComment, showHideAllComments, autoSelectionFormula, handleSum, locale, handleMerge, handleBorder, toolbarItemSelectedFunc, handleFreeze, insertImage, showImgChooser, updateFormat, handleSort, handleHorizontalAlign, handleVerticalAlign, handleScreenShot, createFilter, clearFilter, applyLocation, insertDuneChart, api, getSheetIndex, is_date } from "@fileverse-dev/fortune-core";
|
|
127
127
|
import _ from "lodash";
|
|
128
128
|
import { IconButton, LucideIcon, Tooltip, Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem } from "@fileverse/ui";
|
|
129
129
|
import DataVerificationPortal from "./dataVerificationPortal";
|
|
@@ -649,7 +649,7 @@ var Toolbar = function Toolbar(_a) {
|
|
|
649
649
|
}
|
|
650
650
|
}, [cell, refs.globalCache]);
|
|
651
651
|
var getToolbarItem = useCallback(function (name, i) {
|
|
652
|
-
var _a, _b, _c, _d, _e, _f
|
|
652
|
+
var _a, _b, _c, _d, _e, _f;
|
|
653
653
|
var tooltip = toolbar[name];
|
|
654
654
|
if (name === "|") {
|
|
655
655
|
return /*#__PURE__*/React.createElement(Divider, {
|
|
@@ -714,10 +714,15 @@ var Toolbar = function Toolbar(_a) {
|
|
|
714
714
|
return v.value === (curr_2 === null || curr_2 === void 0 ? void 0 : curr_2.fa);
|
|
715
715
|
});
|
|
716
716
|
if ((curr_2 === null || curr_2 === void 0 ? void 0 : curr_2.fa) != null) {
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
717
|
+
var hasTime = /[hH]:/.test(curr_2.fa);
|
|
718
|
+
if (curr_2.t === "d") {
|
|
719
|
+
currentFmt_1 = hasTime ? "Date time" : "Date";
|
|
720
|
+
} else if (curr_2.t === "n" || curr_2.fa.includes("#,##0") || curr_2.fa === "0" || curr_2.fa === "0.00") {
|
|
720
721
|
currentFmt_1 = "Number";
|
|
722
|
+
} else if (is_date(curr_2.fa)) {
|
|
723
|
+
currentFmt_1 = hasTime ? "Date time" : "Date";
|
|
724
|
+
} else if (format != null) {
|
|
725
|
+
currentFmt_1 = format.text;
|
|
721
726
|
} else {
|
|
722
727
|
currentFmt_1 = defaultFormat[defaultFormat.length - 1].text;
|
|
723
728
|
}
|
|
@@ -872,9 +877,9 @@ var Toolbar = function Toolbar(_a) {
|
|
|
872
877
|
value: 2
|
|
873
878
|
}];
|
|
874
879
|
return /*#__PURE__*/React.createElement(Combo, {
|
|
875
|
-
iconId: ((
|
|
880
|
+
iconId: ((_a = _.find(items_1, function (item) {
|
|
876
881
|
return "".concat(item.value) === "".concat(cell === null || cell === void 0 ? void 0 : cell.ht);
|
|
877
|
-
})) === null ||
|
|
882
|
+
})) === null || _a === void 0 ? void 0 : _a.title) || "align-left",
|
|
878
883
|
key: name,
|
|
879
884
|
tooltip: toolbar.horizontalAlign,
|
|
880
885
|
showArrow: false
|
|
@@ -924,9 +929,9 @@ var Toolbar = function Toolbar(_a) {
|
|
|
924
929
|
value: 2
|
|
925
930
|
}];
|
|
926
931
|
return /*#__PURE__*/React.createElement(Combo, {
|
|
927
|
-
iconId: ((
|
|
932
|
+
iconId: ((_b = _.find(items_2, function (item) {
|
|
928
933
|
return "".concat(item.value) === "".concat(cell === null || cell === void 0 ? void 0 : cell.vt);
|
|
929
|
-
})) === null ||
|
|
934
|
+
})) === null || _b === void 0 ? void 0 : _b.title) || "align-top",
|
|
930
935
|
key: name,
|
|
931
936
|
tooltip: toolbar.verticalAlign,
|
|
932
937
|
showArrow: false
|
|
@@ -1167,7 +1172,7 @@ var Toolbar = function Toolbar(_a) {
|
|
|
1167
1172
|
});
|
|
1168
1173
|
}
|
|
1169
1174
|
if (name === "comment") {
|
|
1170
|
-
var last = (
|
|
1175
|
+
var last = (_c = context.luckysheet_select_save) === null || _c === void 0 ? void 0 : _c[context.luckysheet_select_save.length - 1];
|
|
1171
1176
|
var row_index_1 = last === null || last === void 0 ? void 0 : last.row_focus;
|
|
1172
1177
|
var col_index_1 = last === null || last === void 0 ? void 0 : last.column_focus;
|
|
1173
1178
|
if (!last) {
|
|
@@ -1182,7 +1187,7 @@ var Toolbar = function Toolbar(_a) {
|
|
|
1182
1187
|
}
|
|
1183
1188
|
}
|
|
1184
1189
|
var itemData_1;
|
|
1185
|
-
if (((
|
|
1190
|
+
if (((_e = (_d = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index_1]) === null || _d === void 0 ? void 0 : _d[col_index_1]) === null || _e === void 0 ? void 0 : _e.ps) != null) {
|
|
1186
1191
|
itemData_1 = [{
|
|
1187
1192
|
key: "edit",
|
|
1188
1193
|
text: comment.edit,
|
|
@@ -1695,7 +1700,7 @@ var Toolbar = function Toolbar(_a) {
|
|
|
1695
1700
|
iconId: name,
|
|
1696
1701
|
tooltip: tooltip,
|
|
1697
1702
|
key: name,
|
|
1698
|
-
selected: (
|
|
1703
|
+
selected: (_f = toolbarItemSelectedFunc(name)) === null || _f === void 0 ? void 0 : _f(cell),
|
|
1699
1704
|
onClick: function onClick() {
|
|
1700
1705
|
return setContext(function (draftCtx) {
|
|
1701
1706
|
var _a;
|
|
@@ -728,6 +728,8 @@ export declare function generateAPIs(context: Context, setContext: (recipe: (ctx
|
|
|
728
728
|
conditionformat_equal_title: string;
|
|
729
729
|
conditionformat_textContains: string;
|
|
730
730
|
conditionformat_textContains_title: string;
|
|
731
|
+
conditionformat_empty: string;
|
|
732
|
+
conditionformat_empty_title: string;
|
|
731
733
|
conditionformat_occurrenceDate: string;
|
|
732
734
|
conditionformat_occurrenceDate_title: string;
|
|
733
735
|
conditionformat_duplicateValue: string;
|
|
@@ -830,6 +832,7 @@ export declare function generateAPIs(context: Context, setContext: (recipe: (ctx
|
|
|
830
832
|
between2: string;
|
|
831
833
|
contain: string;
|
|
832
834
|
textContains: string;
|
|
835
|
+
empty: string;
|
|
833
836
|
duplicateValue: string;
|
|
834
837
|
uniqueValue: string;
|
|
835
838
|
top: string;
|
|
@@ -735,6 +735,8 @@ declare const Workbook: React.ForwardRefExoticComponent<Settings & AdditionalPro
|
|
|
735
735
|
conditionformat_equal_title: string;
|
|
736
736
|
conditionformat_textContains: string;
|
|
737
737
|
conditionformat_textContains_title: string;
|
|
738
|
+
conditionformat_empty: string;
|
|
739
|
+
conditionformat_empty_title: string;
|
|
738
740
|
conditionformat_occurrenceDate: string;
|
|
739
741
|
conditionformat_occurrenceDate_title: string;
|
|
740
742
|
conditionformat_duplicateValue: string;
|
|
@@ -837,6 +839,7 @@ declare const Workbook: React.ForwardRefExoticComponent<Settings & AdditionalPro
|
|
|
837
839
|
between2: string;
|
|
838
840
|
contain: string;
|
|
839
841
|
textContains: string;
|
|
842
|
+
empty: string;
|
|
840
843
|
duplicateValue: string;
|
|
841
844
|
uniqueValue: string;
|
|
842
845
|
top: string;
|