@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
|
@@ -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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
303
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
292
|
-
|
|
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.
|
|
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:
|
|
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;
|
|
@@ -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
|
-
(
|
|
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",
|
|
@@ -384,18 +396,18 @@ var SheetOverlay = function SheetOverlay() {
|
|
|
384
396
|
}), ((_h = (_g = context.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0) > 0 && (/*#__PURE__*/_react.default.createElement("div", {
|
|
385
397
|
id: "luckysheet-cell-selected-boxs"
|
|
386
398
|
}, context.luckysheet_select_save.map(function (selection, index) {
|
|
387
|
-
var _a, _b;
|
|
399
|
+
var _a, _b, _c, _d;
|
|
388
400
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
389
401
|
key: index,
|
|
390
402
|
id: "luckysheet-cell-selected",
|
|
391
|
-
className: "luckysheet-cell-selected",
|
|
403
|
+
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" : ""),
|
|
392
404
|
style: _lodash.default.assign({
|
|
393
405
|
left: selection.left_move,
|
|
394
406
|
top: selection.top_move,
|
|
395
407
|
width: selection.width_move ? selection.width_move - 1.8 : selection.width_move,
|
|
396
408
|
height: selection.height_move ? selection.height_move - 1.8 : selection.height_move,
|
|
397
409
|
display: "block"
|
|
398
|
-
}, (0, _fortuneCore.fixRowStyleOverflowInFreeze)(context, selection.row[0], selection.row[1], (
|
|
410
|
+
}, (0, _fortuneCore.fixRowStyleOverflowInFreeze)(context, selection.row[0], selection.row[1], (_c = refs.globalCache.freezen) === null || _c === void 0 ? void 0 : _c[context.currentSheetId]), (0, _fortuneCore.fixColumnStyleOverflowInFreeze)(context, selection.column[0], selection.column[1], (_d = refs.globalCache.freezen) === null || _d === void 0 ? void 0 : _d[context.currentSheetId])),
|
|
399
411
|
onMouseDown: function onMouseDown(e) {
|
|
400
412
|
e.stopPropagation();
|
|
401
413
|
var nativeEvent = e.nativeEvent;
|
|
@@ -658,7 +658,7 @@ var Toolbar = function Toolbar(_a) {
|
|
|
658
658
|
}
|
|
659
659
|
}, [cell, refs.globalCache]);
|
|
660
660
|
var getToolbarItem = (0, _react.useCallback)(function (name, i) {
|
|
661
|
-
var _a, _b, _c, _d, _e, _f
|
|
661
|
+
var _a, _b, _c, _d, _e, _f;
|
|
662
662
|
var tooltip = toolbar[name];
|
|
663
663
|
if (name === "|") {
|
|
664
664
|
return /*#__PURE__*/_react.default.createElement(_Divider.default, {
|
|
@@ -723,10 +723,15 @@ var Toolbar = function Toolbar(_a) {
|
|
|
723
723
|
return v.value === (curr_2 === null || curr_2 === void 0 ? void 0 : curr_2.fa);
|
|
724
724
|
});
|
|
725
725
|
if ((curr_2 === null || curr_2 === void 0 ? void 0 : curr_2.fa) != null) {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
726
|
+
var hasTime = /[hH]:/.test(curr_2.fa);
|
|
727
|
+
if (curr_2.t === "d") {
|
|
728
|
+
currentFmt_1 = hasTime ? "Date time" : "Date";
|
|
729
|
+
} else if (curr_2.t === "n" || curr_2.fa.includes("#,##0") || curr_2.fa === "0" || curr_2.fa === "0.00") {
|
|
729
730
|
currentFmt_1 = "Number";
|
|
731
|
+
} else if ((0, _fortuneCore.is_date)(curr_2.fa)) {
|
|
732
|
+
currentFmt_1 = hasTime ? "Date time" : "Date";
|
|
733
|
+
} else if (format != null) {
|
|
734
|
+
currentFmt_1 = format.text;
|
|
730
735
|
} else {
|
|
731
736
|
currentFmt_1 = defaultFormat[defaultFormat.length - 1].text;
|
|
732
737
|
}
|
|
@@ -881,9 +886,9 @@ var Toolbar = function Toolbar(_a) {
|
|
|
881
886
|
value: 2
|
|
882
887
|
}];
|
|
883
888
|
return /*#__PURE__*/_react.default.createElement(_Combo.default, {
|
|
884
|
-
iconId: ((
|
|
889
|
+
iconId: ((_a = _lodash.default.find(items_1, function (item) {
|
|
885
890
|
return "".concat(item.value) === "".concat(cell === null || cell === void 0 ? void 0 : cell.ht);
|
|
886
|
-
})) === null ||
|
|
891
|
+
})) === null || _a === void 0 ? void 0 : _a.title) || "align-left",
|
|
887
892
|
key: name,
|
|
888
893
|
tooltip: toolbar.horizontalAlign,
|
|
889
894
|
showArrow: false
|
|
@@ -933,9 +938,9 @@ var Toolbar = function Toolbar(_a) {
|
|
|
933
938
|
value: 2
|
|
934
939
|
}];
|
|
935
940
|
return /*#__PURE__*/_react.default.createElement(_Combo.default, {
|
|
936
|
-
iconId: ((
|
|
941
|
+
iconId: ((_b = _lodash.default.find(items_2, function (item) {
|
|
937
942
|
return "".concat(item.value) === "".concat(cell === null || cell === void 0 ? void 0 : cell.vt);
|
|
938
|
-
})) === null ||
|
|
943
|
+
})) === null || _b === void 0 ? void 0 : _b.title) || "align-top",
|
|
939
944
|
key: name,
|
|
940
945
|
tooltip: toolbar.verticalAlign,
|
|
941
946
|
showArrow: false
|
|
@@ -1176,7 +1181,7 @@ var Toolbar = function Toolbar(_a) {
|
|
|
1176
1181
|
});
|
|
1177
1182
|
}
|
|
1178
1183
|
if (name === "comment") {
|
|
1179
|
-
var last = (
|
|
1184
|
+
var last = (_c = context.luckysheet_select_save) === null || _c === void 0 ? void 0 : _c[context.luckysheet_select_save.length - 1];
|
|
1180
1185
|
var row_index_1 = last === null || last === void 0 ? void 0 : last.row_focus;
|
|
1181
1186
|
var col_index_1 = last === null || last === void 0 ? void 0 : last.column_focus;
|
|
1182
1187
|
if (!last) {
|
|
@@ -1191,7 +1196,7 @@ var Toolbar = function Toolbar(_a) {
|
|
|
1191
1196
|
}
|
|
1192
1197
|
}
|
|
1193
1198
|
var itemData_1;
|
|
1194
|
-
if (((
|
|
1199
|
+
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) {
|
|
1195
1200
|
itemData_1 = [{
|
|
1196
1201
|
key: "edit",
|
|
1197
1202
|
text: comment.edit,
|
|
@@ -1704,7 +1709,7 @@ var Toolbar = function Toolbar(_a) {
|
|
|
1704
1709
|
iconId: name,
|
|
1705
1710
|
tooltip: tooltip,
|
|
1706
1711
|
key: name,
|
|
1707
|
-
selected: (
|
|
1712
|
+
selected: (_f = (0, _fortuneCore.toolbarItemSelectedFunc)(name)) === null || _f === void 0 ? void 0 : _f(cell),
|
|
1708
1713
|
onClick: function onClick() {
|
|
1709
1714
|
return setContext(function (draftCtx) {
|
|
1710
1715
|
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;
|