@fileverse-dev/fortune-react 1.3.10 → 1.3.11-input-ref-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 +200 -52
- package/es/components/SheetOverlay/InputBox.js +318 -150
- package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +25 -1
- package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +26 -2
- package/es/components/SheetOverlay/helper.d.ts +7 -0
- package/es/components/SheetOverlay/helper.js +95 -0
- package/es/components/SheetOverlay/index.css +1 -1
- package/es/components/Workbook/index.js +141 -11
- 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 +26 -0
- package/es/utils/convertCellsToCrypto.js +17 -0
- package/lib/components/ContextMenu/index.js +1 -1
- package/lib/components/FxEditor/index.js +198 -50
- package/lib/components/SheetOverlay/InputBox.js +316 -148
- package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +25 -1
- package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +26 -2
- package/lib/components/SheetOverlay/helper.d.ts +7 -0
- package/lib/components/SheetOverlay/helper.js +99 -0
- package/lib/components/SheetOverlay/index.css +1 -1
- package/lib/components/Workbook/index.js +142 -12
- 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 +32 -0
- package/lib/utils/convertCellsToCrypto.js +17 -0
- package/package.json +2 -2
|
@@ -211,7 +211,7 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
|
|
|
211
211
|
var sheetIdx_1 = getSheetIndex(context, context.currentSheetId);
|
|
212
212
|
if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
|
|
213
213
|
setContext(function (draft) {
|
|
214
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
214
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
215
215
|
var _sheet = draft.luckysheetfile[sheetIdx_1];
|
|
216
216
|
if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
|
|
217
217
|
var rows = _sheet.data;
|
|
@@ -374,6 +374,30 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
|
|
|
374
374
|
}
|
|
375
375
|
});
|
|
376
376
|
(_g = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _g === void 0 ? void 0 : _g.call(window, selectedSourceCol, selectedTargetCol, "column", context.currentSheetId, sourceIndex_1, targetIndex);
|
|
377
|
+
var cellChanges = [];
|
|
378
|
+
var affectedColStart = Math.min(sourceIndex_1, targetIndex);
|
|
379
|
+
var affectedColEnd = Math.max(sourceIndex_1, targetIndex) + selectedSourceCol.length - 1;
|
|
380
|
+
var numRows = rows.length;
|
|
381
|
+
for (var r = 0; r < numRows; r += 1) {
|
|
382
|
+
var row = rows[r];
|
|
383
|
+
for (var c = affectedColStart; c <= affectedColEnd; c += 1) {
|
|
384
|
+
var cell = row === null || row === void 0 ? void 0 : row[c];
|
|
385
|
+
cellChanges.push({
|
|
386
|
+
sheetId: draft.currentSheetId,
|
|
387
|
+
path: ["celldata"],
|
|
388
|
+
value: {
|
|
389
|
+
r: r,
|
|
390
|
+
c: c,
|
|
391
|
+
v: cell !== null && cell !== void 0 ? cell : null
|
|
392
|
+
},
|
|
393
|
+
key: "".concat(r, "_").concat(c),
|
|
394
|
+
type: "update"
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (cellChanges.length > 0 && ((_h = draft.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc)) {
|
|
399
|
+
draft.hooks.updateCellYdoc(cellChanges);
|
|
400
|
+
}
|
|
377
401
|
var rowLen = (d === null || d === void 0 ? void 0 : d.length) || 0;
|
|
378
402
|
api.setSelection(draft, [{
|
|
379
403
|
row: [0, rowLen],
|
|
@@ -207,7 +207,7 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
|
|
|
207
207
|
var sheetIdx_1 = getSheetIndex(context, context.currentSheetId);
|
|
208
208
|
if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
|
|
209
209
|
setContext(function (draft) {
|
|
210
|
-
var _a, _b, _c, _d, _e, _f;
|
|
210
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
211
211
|
var _sheet = draft.luckysheetfile[sheetIdx_1];
|
|
212
212
|
if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
|
|
213
213
|
var rows = _sheet.data;
|
|
@@ -364,7 +364,31 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
|
|
|
364
364
|
}
|
|
365
365
|
});
|
|
366
366
|
(_e = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _e === void 0 ? void 0 : _e.call(window, sourceIndex_1, targetIndex, "row", context.currentSheetId);
|
|
367
|
-
var
|
|
367
|
+
var cellChanges = [];
|
|
368
|
+
var affectedRowStart = Math.min(sourceIndex_1, targetIndex);
|
|
369
|
+
var affectedRowEnd = Math.max(sourceIndex_1, targetIndex) + selectedSourceRow.length - 1;
|
|
370
|
+
var numCols = (_g = (_f = d === null || d === void 0 ? void 0 : d[0]) === null || _f === void 0 ? void 0 : _f.length) !== null && _g !== void 0 ? _g : 0;
|
|
371
|
+
for (var r = affectedRowStart; r <= affectedRowEnd; r += 1) {
|
|
372
|
+
var row = rows[r];
|
|
373
|
+
for (var c = 0; c < numCols; c += 1) {
|
|
374
|
+
var cell = row === null || row === void 0 ? void 0 : row[c];
|
|
375
|
+
cellChanges.push({
|
|
376
|
+
sheetId: draft.currentSheetId,
|
|
377
|
+
path: ["celldata"],
|
|
378
|
+
value: {
|
|
379
|
+
r: r,
|
|
380
|
+
c: c,
|
|
381
|
+
v: cell !== null && cell !== void 0 ? cell : null
|
|
382
|
+
},
|
|
383
|
+
key: "".concat(r, "_").concat(c),
|
|
384
|
+
type: "update"
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (cellChanges.length > 0 && ((_h = draft.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc)) {
|
|
389
|
+
draft.hooks.updateCellYdoc(cellChanges);
|
|
390
|
+
}
|
|
391
|
+
var colLen = ((_j = d === null || d === void 0 ? void 0 : d[0]) === null || _j === void 0 ? void 0 : _j.length) || 0;
|
|
368
392
|
api.setSelection(draft, [{
|
|
369
393
|
row: [selectedTargetRow[0], selectedTargetRow[selectedTargetRow.length - 1]],
|
|
370
394
|
column: [0, colLen]
|
|
@@ -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;
|
|
@@ -142,6 +142,101 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
142
142
|
onOp(patchToOp(ctx, patches, options, undo));
|
|
143
143
|
}
|
|
144
144
|
}, [onOp]);
|
|
145
|
+
var emitYjsFromPatches = useCallback(function (ctxBefore, ctxAfter, patches) {
|
|
146
|
+
var _a;
|
|
147
|
+
var _b = (_a = ctxBefore.hooks) !== null && _a !== void 0 ? _a : {},
|
|
148
|
+
updateCellYdoc = _b.updateCellYdoc,
|
|
149
|
+
updateAllCell = _b.updateAllCell;
|
|
150
|
+
if (!updateCellYdoc) return;
|
|
151
|
+
var mapFields = new Set(["celldata", "calcChain", "dataBlockCalcFunction", "liveQueryList", "dataVerification", "hyperlink", "conditionRules"]);
|
|
152
|
+
var changeMap = new Map();
|
|
153
|
+
var upsert = function upsert(change) {
|
|
154
|
+
var _a, _b, _c;
|
|
155
|
+
var k = "".concat(change.sheetId, ":").concat((_b = (_a = change.path) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "", ":").concat((_c = change.key) !== null && _c !== void 0 ? _c : "");
|
|
156
|
+
changeMap.set(k, change);
|
|
157
|
+
};
|
|
158
|
+
var upsertCell = function upsertCell(sheetId, r, c) {
|
|
159
|
+
var _a, _b, _c;
|
|
160
|
+
var cell = (_c = (_b = (_a = getFlowdata(ctxAfter, sheetId)) === null || _a === void 0 ? void 0 : _a[r]) === null || _b === void 0 ? void 0 : _b[c]) !== null && _c !== void 0 ? _c : null;
|
|
161
|
+
var key = "".concat(r, "_").concat(c);
|
|
162
|
+
upsert({
|
|
163
|
+
sheetId: sheetId,
|
|
164
|
+
path: ["celldata"],
|
|
165
|
+
key: key,
|
|
166
|
+
value: {
|
|
167
|
+
r: r,
|
|
168
|
+
c: c,
|
|
169
|
+
v: cell
|
|
170
|
+
},
|
|
171
|
+
type: cell == null ? "delete" : "update"
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
patches.forEach(function (p) {
|
|
175
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
176
|
+
var path = p.path;
|
|
177
|
+
if ((path === null || path === void 0 ? void 0 : path[0]) !== "luckysheetfile") return;
|
|
178
|
+
var sheetIndex = path[1];
|
|
179
|
+
if (!_.isNumber(sheetIndex)) return;
|
|
180
|
+
var sheetBefore = (_a = ctxBefore.luckysheetfile) === null || _a === void 0 ? void 0 : _a[sheetIndex];
|
|
181
|
+
var sheetAfter = (_b = ctxAfter.luckysheetfile) === null || _b === void 0 ? void 0 : _b[sheetIndex];
|
|
182
|
+
var sheetId = (sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.id) || (sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.id);
|
|
183
|
+
if (!sheetId) return;
|
|
184
|
+
var root = path[2];
|
|
185
|
+
if (root === "data") {
|
|
186
|
+
if (_.isNumber(path[3]) && _.isNumber(path[4])) {
|
|
187
|
+
upsertCell(sheetId, path[3], path[4]);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (_.isNumber(path[3]) && path.length === 4) {
|
|
191
|
+
var r = path[3];
|
|
192
|
+
var beforeRow = (_d = (_c = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _c === void 0 ? void 0 : _c[r]) !== null && _d !== void 0 ? _d : [];
|
|
193
|
+
var afterRow = (_f = (_e = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _e === void 0 ? void 0 : _e[r]) !== null && _f !== void 0 ? _f : [];
|
|
194
|
+
var max = Math.max((_g = beforeRow.length) !== null && _g !== void 0 ? _g : 0, (_h = afterRow.length) !== null && _h !== void 0 ? _h : 0);
|
|
195
|
+
for (var c = 0; c < max; c += 1) {
|
|
196
|
+
if (!_.isEqual((_j = beforeRow[c]) !== null && _j !== void 0 ? _j : null, (_k = afterRow[c]) !== null && _k !== void 0 ? _k : null)) {
|
|
197
|
+
upsertCell(sheetId, r, c);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (path.length === 3) {
|
|
203
|
+
var dataAfter = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data;
|
|
204
|
+
var rows = (_l = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter.length) !== null && _l !== void 0 ? _l : 0;
|
|
205
|
+
var cols = rows > 0 ? (_o = (_m = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter[0]) === null || _m === void 0 ? void 0 : _m.length) !== null && _o !== void 0 ? _o : 0 : 0;
|
|
206
|
+
var size = rows * cols;
|
|
207
|
+
if (size > 50000 && updateAllCell) {
|
|
208
|
+
updateAllCell(sheetId);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
for (var r = 0; r < rows; r += 1) {
|
|
212
|
+
var beforeRow = (_q = (_p = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _p === void 0 ? void 0 : _p[r]) !== null && _q !== void 0 ? _q : [];
|
|
213
|
+
var afterRow = (_s = (_r = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _r === void 0 ? void 0 : _r[r]) !== null && _s !== void 0 ? _s : [];
|
|
214
|
+
var max = Math.max((_t = beforeRow.length) !== null && _t !== void 0 ? _t : 0, (_u = afterRow.length) !== null && _u !== void 0 ? _u : 0);
|
|
215
|
+
for (var c = 0; c < max; c += 1) {
|
|
216
|
+
if (!_.isEqual((_v = beforeRow[c]) !== null && _v !== void 0 ? _v : null, (_w = afterRow[c]) !== null && _w !== void 0 ? _w : null)) {
|
|
217
|
+
upsertCell(sheetId, r, c);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (typeof root === "string" && mapFields.has(root)) {
|
|
225
|
+
var key = path[3];
|
|
226
|
+
if (typeof key === "string") {
|
|
227
|
+
upsert({
|
|
228
|
+
sheetId: sheetId,
|
|
229
|
+
path: [root],
|
|
230
|
+
key: key,
|
|
231
|
+
value: p.value,
|
|
232
|
+
type: p.op === "remove" || p.value == null ? "delete" : "update"
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
var changes = Array.from(changeMap.values());
|
|
238
|
+
if (changes.length > 0) updateCellYdoc(changes);
|
|
239
|
+
}, []);
|
|
145
240
|
function reduceUndoList(ctx, ctxBefore) {
|
|
146
241
|
var sheetsId = ctx.luckysheetfile.map(function (sheet) {
|
|
147
242
|
return sheet.id;
|
|
@@ -299,6 +394,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
299
394
|
delete inversedOptions.addSheet.value.data;
|
|
300
395
|
}
|
|
301
396
|
emitOp(newContext, history.inversePatches, inversedOptions, true);
|
|
397
|
+
emitYjsFromPatches(ctx_, newContext, history.inversePatches);
|
|
302
398
|
var sheetIdxAfterUndo = getSheetIndex(newContext, newContext.currentSheetId);
|
|
303
399
|
var nw = __assign(__assign({}, newContext), sheetIdxAfterUndo != null && ((_f = newContext.luckysheetfile[sheetIdxAfterUndo]) === null || _f === void 0 ? void 0 : _f.config) != null ? {
|
|
304
400
|
config: newContext.luckysheetfile[sheetIdxAfterUndo].config
|
|
@@ -327,6 +423,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
327
423
|
});
|
|
328
424
|
globalCache.current.undoList.push(history);
|
|
329
425
|
emitOp(newContext, history.patches, history.options);
|
|
426
|
+
emitYjsFromPatches(ctx_, newContext, history.patches);
|
|
330
427
|
var sheetIdxAfterRedo = getSheetIndex(newContext, newContext.currentSheetId);
|
|
331
428
|
var nw = __assign(__assign({}, newContext), sheetIdxAfterRedo != null && ((_a = newContext.luckysheetfile[sheetIdxAfterRedo]) === null || _a === void 0 ? void 0 : _a.config) != null ? {
|
|
332
429
|
config: newContext.luckysheetfile[sheetIdxAfterRedo].config
|
|
@@ -353,18 +450,13 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
353
450
|
useEffect(function () {
|
|
354
451
|
var _a, _b;
|
|
355
452
|
setContext(function (ctx) {
|
|
356
|
-
var _a, _b;
|
|
357
453
|
var gridData = getFlowdata(ctx);
|
|
358
454
|
var cellData = api.dataToCelldata(gridData);
|
|
359
|
-
var denominatedUsed =
|
|
360
|
-
|
|
361
|
-
var cell = cellData_1[_i];
|
|
455
|
+
var denominatedUsed = (cellData !== null && cellData !== void 0 ? cellData : []).some(function (cell) {
|
|
456
|
+
var _a, _b;
|
|
362
457
|
var value = (_b = (_a = cell === null || cell === void 0 ? void 0 : cell.v) === null || _a === void 0 ? void 0 : _a.m) === null || _b === void 0 ? void 0 : _b.toString();
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
458
|
+
return (value === null || value === void 0 ? void 0 : value.includes("BTC")) || (value === null || value === void 0 ? void 0 : value.includes("ETH")) || (value === null || value === void 0 ? void 0 : value.includes("SOL"));
|
|
459
|
+
});
|
|
368
460
|
var denoWarn = document.getElementById("denomination-warning");
|
|
369
461
|
var scrollBar = document.getElementsByClassName("luckysheet-scrollbar-x")[0];
|
|
370
462
|
if (denominatedUsed && denoWarn) {
|
|
@@ -438,6 +530,32 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
438
530
|
context.hooks.afterOrderChanges();
|
|
439
531
|
}
|
|
440
532
|
}, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.order]);
|
|
533
|
+
var sheetColorSig = useMemo(function () {
|
|
534
|
+
var _a;
|
|
535
|
+
return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
|
|
536
|
+
var _a;
|
|
537
|
+
return "".concat(s.id, ":").concat((_a = s.color) !== null && _a !== void 0 ? _a : "");
|
|
538
|
+
}).join("|");
|
|
539
|
+
}, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
|
|
540
|
+
useEffect(function () {
|
|
541
|
+
var _a;
|
|
542
|
+
if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterColorChanges) {
|
|
543
|
+
context.hooks.afterColorChanges();
|
|
544
|
+
}
|
|
545
|
+
}, [sheetColorSig]);
|
|
546
|
+
var sheetHideSig = useMemo(function () {
|
|
547
|
+
var _a;
|
|
548
|
+
return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
|
|
549
|
+
var _a;
|
|
550
|
+
return "".concat(s.id, ":").concat((_a = s.hide) !== null && _a !== void 0 ? _a : 0);
|
|
551
|
+
}).join("|");
|
|
552
|
+
}, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
|
|
553
|
+
useEffect(function () {
|
|
554
|
+
var _a;
|
|
555
|
+
if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterHideChanges) {
|
|
556
|
+
context.hooks.afterHideChanges();
|
|
557
|
+
}
|
|
558
|
+
}, [sheetHideSig]);
|
|
441
559
|
useEffect(function () {
|
|
442
560
|
var _a;
|
|
443
561
|
if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterConfigChanges) {
|
|
@@ -504,6 +622,18 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
504
622
|
context.hooks.conditionFormatChange();
|
|
505
623
|
}
|
|
506
624
|
}, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.luckysheet_conditionformat_save]);
|
|
625
|
+
useEffect(function () {
|
|
626
|
+
var _a;
|
|
627
|
+
if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.filterSelectChange) {
|
|
628
|
+
context.hooks.filterSelectChange();
|
|
629
|
+
}
|
|
630
|
+
}, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.filter_select]);
|
|
631
|
+
useEffect(function () {
|
|
632
|
+
var _a;
|
|
633
|
+
if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.filterChange) {
|
|
634
|
+
context.hooks.filterChange();
|
|
635
|
+
}
|
|
636
|
+
}, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.filter]);
|
|
507
637
|
useEffect(function () {
|
|
508
638
|
var _a;
|
|
509
639
|
if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.hyperlinkChange) {
|
|
@@ -748,7 +878,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
748
878
|
});
|
|
749
879
|
}
|
|
750
880
|
var nativeEvent = e.nativeEvent;
|
|
751
|
-
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
|
|
881
|
+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ" && context.luckysheetCellUpdate.length === 0) {
|
|
752
882
|
if (e.shiftKey) {
|
|
753
883
|
handleRedo();
|
|
754
884
|
} else {
|
|
@@ -757,7 +887,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
757
887
|
e.stopPropagation();
|
|
758
888
|
return;
|
|
759
889
|
}
|
|
760
|
-
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY") {
|
|
890
|
+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY" && context.luckysheetCellUpdate.length === 0) {
|
|
761
891
|
handleRedo();
|
|
762
892
|
e.stopPropagation();
|
|
763
893
|
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 {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
import { escapeScriptTag, functionHTMLGenerate, escapeHTMLTag, handleFormulaInput } from "@fileverse-dev/fortune-core";
|
|
4
|
+
import { setCursorPosition } from "../components/SheetOverlay/helper";
|
|
5
|
+
var MAX_FORMULA_HISTORY = 100;
|
|
6
|
+
export function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, setContext, primary) {
|
|
7
|
+
var preTextRef = useRef("");
|
|
8
|
+
var preFormulaSpanValuesRef = useRef(null);
|
|
9
|
+
var formulaHistoryRef = useRef({
|
|
10
|
+
active: false,
|
|
11
|
+
entries: [],
|
|
12
|
+
index: -1
|
|
13
|
+
});
|
|
14
|
+
var resetFormulaHistory = useCallback(function () {
|
|
15
|
+
formulaHistoryRef.current = {
|
|
16
|
+
active: false,
|
|
17
|
+
entries: [],
|
|
18
|
+
index: -1
|
|
19
|
+
};
|
|
20
|
+
preFormulaSpanValuesRef.current = null;
|
|
21
|
+
}, []);
|
|
22
|
+
var pushFormulaHistoryEntry = useCallback(function (entry) {
|
|
23
|
+
var history = formulaHistoryRef.current;
|
|
24
|
+
var current = history.entries[history.index];
|
|
25
|
+
if (current && current.spanValues.length > 0 && entry.spanValues.length > 0 && _.isEqual(current.spanValues, entry.spanValues)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (current && current.spanValues.length === 0 && entry.spanValues.length === 0 && current.text === entry.text && current.caret === entry.caret) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
var nextEntries = history.entries.slice(0, history.index + 1);
|
|
32
|
+
nextEntries.push(entry);
|
|
33
|
+
if (nextEntries.length > MAX_FORMULA_HISTORY) {
|
|
34
|
+
nextEntries.shift();
|
|
35
|
+
}
|
|
36
|
+
history.entries = nextEntries;
|
|
37
|
+
history.index = nextEntries.length - 1;
|
|
38
|
+
history.active = true;
|
|
39
|
+
}, []);
|
|
40
|
+
var applyFormulaHistoryEntry = useCallback(function (entry) {
|
|
41
|
+
var primaryEl = primaryRef.current;
|
|
42
|
+
if (!primaryEl) return;
|
|
43
|
+
var safeText = escapeScriptTag(entry.text || "");
|
|
44
|
+
var html = safeText.startsWith("=") ? functionHTMLGenerate(safeText) : escapeHTMLTag(safeText);
|
|
45
|
+
var cell = cellInputRef.current;
|
|
46
|
+
var fx = fxInputRef.current;
|
|
47
|
+
primaryEl.innerHTML = html;
|
|
48
|
+
if (primary === "cell") {
|
|
49
|
+
if (fx) fx.innerHTML = html;
|
|
50
|
+
} else if (cell) {
|
|
51
|
+
cell.innerHTML = html;
|
|
52
|
+
}
|
|
53
|
+
setCursorPosition(primaryEl, Math.min(entry.caret, entry.text.length));
|
|
54
|
+
setContext(function (draftCtx) {
|
|
55
|
+
if (primary === "cell") {
|
|
56
|
+
if (!cellInputRef.current) return;
|
|
57
|
+
handleFormulaInput(draftCtx, fxInputRef.current, cellInputRef.current, 0);
|
|
58
|
+
} else {
|
|
59
|
+
if (!fxInputRef.current) return;
|
|
60
|
+
handleFormulaInput(draftCtx, cellInputRef.current, fxInputRef.current, 0);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}, [cellInputRef, fxInputRef, primary, primaryRef, setContext]);
|
|
64
|
+
var handleFormulaHistoryUndoRedo = useCallback(function (isRedo) {
|
|
65
|
+
var history = formulaHistoryRef.current;
|
|
66
|
+
if (!history.active || history.entries.length === 0) return false;
|
|
67
|
+
var nextIndex = isRedo ? history.index + 1 : history.index - 1;
|
|
68
|
+
if (nextIndex < 0 || nextIndex >= history.entries.length) return true;
|
|
69
|
+
history.index = nextIndex;
|
|
70
|
+
applyFormulaHistoryEntry(history.entries[nextIndex]);
|
|
71
|
+
return true;
|
|
72
|
+
}, [applyFormulaHistoryEntry]);
|
|
73
|
+
var capturePreFormulaState = useCallback(function () {
|
|
74
|
+
var el = primaryRef.current;
|
|
75
|
+
if (!el) return;
|
|
76
|
+
preTextRef.current = el.innerText;
|
|
77
|
+
preFormulaSpanValuesRef.current = Array.from(el.querySelectorAll("span.fortune-formula-functionrange-cell")).map(function (node) {
|
|
78
|
+
var _a;
|
|
79
|
+
return (_a = node.textContent) !== null && _a !== void 0 ? _a : "";
|
|
80
|
+
});
|
|
81
|
+
}, [primaryRef]);
|
|
82
|
+
var appendFormulaHistoryFromPrimaryEditor = useCallback(function (getCaret) {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
var el = primaryRef.current;
|
|
85
|
+
if (!el) return;
|
|
86
|
+
var currentText = el.innerText || "";
|
|
87
|
+
if (currentText.startsWith("=")) {
|
|
88
|
+
var caret = getCaret();
|
|
89
|
+
var spanValues = Array.from(el.querySelectorAll("span.fortune-formula-functionrange-cell")).map(function (node) {
|
|
90
|
+
var _a;
|
|
91
|
+
return (_a = node.textContent) !== null && _a !== void 0 ? _a : "";
|
|
92
|
+
});
|
|
93
|
+
if (!formulaHistoryRef.current.active) {
|
|
94
|
+
var seedText = preTextRef.current || "";
|
|
95
|
+
pushFormulaHistoryEntry({
|
|
96
|
+
text: seedText,
|
|
97
|
+
caret: Math.min(caret, seedText.length),
|
|
98
|
+
spanValues: (_b = (_a = preFormulaSpanValuesRef.current) !== null && _a !== void 0 ? _a : spanValues) !== null && _b !== void 0 ? _b : []
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
pushFormulaHistoryEntry({
|
|
102
|
+
text: currentText,
|
|
103
|
+
caret: caret,
|
|
104
|
+
spanValues: spanValues
|
|
105
|
+
});
|
|
106
|
+
} else if (formulaHistoryRef.current.active) {
|
|
107
|
+
resetFormulaHistory();
|
|
108
|
+
}
|
|
109
|
+
}, [primaryRef, pushFormulaHistoryEntry, resetFormulaHistory]);
|
|
110
|
+
return {
|
|
111
|
+
formulaHistoryRef: formulaHistoryRef,
|
|
112
|
+
preTextRef: preTextRef,
|
|
113
|
+
preFormulaSpanValuesRef: preFormulaSpanValuesRef,
|
|
114
|
+
resetFormulaHistory: resetFormulaHistory,
|
|
115
|
+
handleFormulaHistoryUndoRedo: handleFormulaHistoryUndoRedo,
|
|
116
|
+
capturePreFormulaState: capturePreFormulaState,
|
|
117
|
+
appendFormulaHistoryFromPrimaryEditor: appendFormulaHistoryFromPrimaryEditor
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
export function useRerenderOnFormulaCaret(editorRef, editSessionActive) {
|
|
3
|
+
var _a = useState(0),
|
|
4
|
+
bump = _a[1];
|
|
5
|
+
useEffect(function () {
|
|
6
|
+
if (!editSessionActive) return;
|
|
7
|
+
var onSelectionChange = function onSelectionChange() {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
var el = editorRef.current;
|
|
10
|
+
if (!el) return;
|
|
11
|
+
var text = (_b = (_a = el.innerText) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
|
|
12
|
+
if (!text.startsWith("=")) return;
|
|
13
|
+
var sel = window.getSelection();
|
|
14
|
+
if (!(sel === null || sel === void 0 ? void 0 : sel.rangeCount) || !el.contains(sel.getRangeAt(0).startContainer)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
bump(function (n) {
|
|
18
|
+
return n + 1;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
document.addEventListener("selectionchange", onSelectionChange);
|
|
22
|
+
return function () {
|
|
23
|
+
return document.removeEventListener("selectionchange", onSelectionChange);
|
|
24
|
+
};
|
|
25
|
+
}, [editSessionActive, editorRef]);
|
|
26
|
+
}
|
|
@@ -274,9 +274,12 @@ export function convertCellsToCrypto(_a) {
|
|
|
274
274
|
});
|
|
275
275
|
});
|
|
276
276
|
setContext(function (ctx) {
|
|
277
|
+
var _a;
|
|
277
278
|
var d = getFlowdata(ctx);
|
|
278
279
|
if (!d || !Array.isArray(d)) return;
|
|
280
|
+
var ydocChanges = [];
|
|
279
281
|
cellUpdates.forEach(function (_a) {
|
|
282
|
+
var _b, _c;
|
|
280
283
|
var row = _a.row,
|
|
281
284
|
col = _a.col,
|
|
282
285
|
baseValue = _a.baseValue,
|
|
@@ -296,7 +299,21 @@ export function convertCellsToCrypto(_a) {
|
|
|
296
299
|
cellCp.baseCurrency = baseCurrency.toLowerCase();
|
|
297
300
|
cellCp.baseCurrencyPrice = baseCurrencyPrice;
|
|
298
301
|
d[row][col] = cellCp;
|
|
302
|
+
ydocChanges.push({
|
|
303
|
+
sheetId: ctx.currentSheetId,
|
|
304
|
+
path: ["celldata"],
|
|
305
|
+
value: {
|
|
306
|
+
r: row,
|
|
307
|
+
c: col,
|
|
308
|
+
v: (_c = (_b = d[row]) === null || _b === void 0 ? void 0 : _b[col]) !== null && _c !== void 0 ? _c : null
|
|
309
|
+
},
|
|
310
|
+
key: "".concat(row, "_").concat(col),
|
|
311
|
+
type: "update"
|
|
312
|
+
});
|
|
299
313
|
});
|
|
314
|
+
if (ydocChanges.length > 0 && ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc)) {
|
|
315
|
+
ctx.hooks.updateCellYdoc(ydocChanges);
|
|
316
|
+
}
|
|
300
317
|
});
|
|
301
318
|
setContext(function (ctx) {
|
|
302
319
|
api.calculateSheetFromula(ctx, ctx.currentSheetId);
|
|
@@ -21,7 +21,7 @@ require("./index.css");
|
|
|
21
21
|
var _Menu = _interopRequireDefault(require("./Menu"));
|
|
22
22
|
require("tippy.js/dist/tippy.css");
|
|
23
23
|
var _SVGIcon = _interopRequireDefault(require("../SVGIcon"));
|
|
24
|
-
var _LucideIcon = require("
|
|
24
|
+
var _LucideIcon = require("../SheetOverlay/LucideIcon");
|
|
25
25
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
26
26
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
27
27
|
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|