@fileverse-dev/fortune-react 1.3.11-input-ref-1 → 1.3.11-input-ref-3
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/FxEditor/index.js +118 -16
- 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 +74 -33
- package/es/components/SheetOverlay/index.css +5 -38
- package/es/components/SheetOverlay/index.js +26 -14
- package/es/hooks/useRerenderOnFormulaCaret.js +4 -2
- package/lib/components/FxEditor/index.js +117 -15
- 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 +74 -33
- package/lib/components/SheetOverlay/index.css +5 -38
- package/lib/components/SheetOverlay/index.js +25 -13
- package/lib/hooks/useRerenderOnFormulaCaret.js +4 -2
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFlowdata, cancelNormalSelected, getCellValue, updateCell, getInlineStringNoStyle, isInlineStringCell, escapeScriptTag, moveHighlightCell, handleFormulaInput, getFormulaRangeIndexAtCaret, isCaretAtValidFormulaRangeInsertionPoint, markRangeSelectionDirty, rangeHightlightselected, getFormulaEditorOwner, setFormulaEditorOwner, valueShowEs, isShowHidenCR, escapeHTMLTag, functionHTMLGenerate, isAllowEdit } from "@fileverse-dev/fortune-core";
|
|
1
|
+
import { getFlowdata, cancelNormalSelected, getCellValue, updateCell, getInlineStringNoStyle, isInlineStringCell, escapeScriptTag, moveHighlightCell, handleFormulaInput, getFormulaRangeIndexAtCaret, isCaretAtValidFormulaRangeInsertionPoint, markRangeSelectionDirty, rangeHightlightselected, getFormulaEditorOwner, setFormulaEditorOwner, createRangeHightlight, valueShowEs, isShowHidenCR, escapeHTMLTag, functionHTMLGenerate, isAllowEdit, suppressFormulaRangeSelectionForInitialEdit } from "@fileverse-dev/fortune-core";
|
|
2
2
|
import React, { useContext, useState, useCallback, useEffect, useLayoutEffect, useRef, useMemo } from "react";
|
|
3
3
|
import "./index.css";
|
|
4
4
|
import _ from "lodash";
|
|
@@ -46,6 +46,7 @@ var FxEditor = function FxEditor() {
|
|
|
46
46
|
var prevCellUpdate = usePrevious(context.luckysheetCellUpdate);
|
|
47
47
|
var prevSheetId = usePrevious(context.currentSheetId);
|
|
48
48
|
var recentText = useRef("");
|
|
49
|
+
var formulaAnchorCellRef = useRef(null);
|
|
49
50
|
var handleShowFormulaHint = function handleShowFormulaHint() {
|
|
50
51
|
localStorage.setItem("formulaMore", String(showFormulaHint));
|
|
51
52
|
setShowFormulaHint(!showFormulaHint);
|
|
@@ -111,13 +112,20 @@ var FxEditor = function FxEditor() {
|
|
|
111
112
|
if (_.isNil(rowIndex) || _.isNil(colIndex)) {
|
|
112
113
|
return;
|
|
113
114
|
}
|
|
115
|
+
var pending = refs.globalCache.pendingTypeOverCell;
|
|
116
|
+
if (pending && pending[0] === rowIndex && pending[1] === colIndex) {
|
|
117
|
+
refs.globalCache.overwriteCell = false;
|
|
118
|
+
refs.globalCache.ignoreWriteCell = false;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
114
121
|
var flowdata = getFlowdata(context);
|
|
115
122
|
if (!flowdata) {
|
|
116
123
|
return;
|
|
117
124
|
}
|
|
118
125
|
var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[rowIndex]) === null || _a === void 0 ? void 0 : _a[colIndex];
|
|
119
126
|
var value = "";
|
|
120
|
-
|
|
127
|
+
var overwrite = refs.globalCache.overwriteCell;
|
|
128
|
+
if (cell && !overwrite) {
|
|
121
129
|
if (isInlineStringCell(cell)) {
|
|
122
130
|
value = getInlineStringNoStyle(rowIndex, colIndex, flowdata);
|
|
123
131
|
} else if (cell.f) {
|
|
@@ -129,7 +137,7 @@ var FxEditor = function FxEditor() {
|
|
|
129
137
|
refs.globalCache.overwriteCell = false;
|
|
130
138
|
if (!refs.globalCache.ignoreWriteCell && value) {
|
|
131
139
|
fxInput.innerHTML = escapeHTMLTag(escapeScriptTag(value));
|
|
132
|
-
} else if (!refs.globalCache.ignoreWriteCell) {
|
|
140
|
+
} else if (!refs.globalCache.ignoreWriteCell && !overwrite) {
|
|
133
141
|
var valueD = getCellValue(rowIndex, colIndex, flowdata, "f");
|
|
134
142
|
fxInput.innerText = valueD;
|
|
135
143
|
}
|
|
@@ -137,9 +145,21 @@ var FxEditor = function FxEditor() {
|
|
|
137
145
|
}, [context.luckysheetCellUpdate, context.luckysheetfile, context.currentSheetId, prevCellUpdate, prevSheetId, refs.fxInput, refs.globalCache]);
|
|
138
146
|
useEffect(function () {
|
|
139
147
|
if (_.isEmpty(context.luckysheetCellUpdate)) {
|
|
148
|
+
delete refs.globalCache.pendingTypeOverCell;
|
|
140
149
|
resetFormulaHistory();
|
|
141
150
|
}
|
|
142
|
-
}, [context.luckysheetCellUpdate, resetFormulaHistory]);
|
|
151
|
+
}, [context.luckysheetCellUpdate, resetFormulaHistory, refs.globalCache]);
|
|
152
|
+
useEffect(function () {
|
|
153
|
+
var _a;
|
|
154
|
+
if (_.isEmpty(context.luckysheetCellUpdate) || !refs.fxInput.current) {
|
|
155
|
+
formulaAnchorCellRef.current = null;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
var inputText = ((_a = refs.fxInput.current.innerText) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
159
|
+
if (!inputText.startsWith("=")) {
|
|
160
|
+
formulaAnchorCellRef.current = null;
|
|
161
|
+
}
|
|
162
|
+
}, [context.luckysheetCellUpdate, refs.fxInput]);
|
|
143
163
|
var onFocus = useCallback(function () {
|
|
144
164
|
var _a, _b;
|
|
145
165
|
if (context.allowEdit === false) {
|
|
@@ -147,12 +167,25 @@ var FxEditor = function FxEditor() {
|
|
|
147
167
|
}
|
|
148
168
|
if (((_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 && !context.luckysheet_cell_selected_move && isAllowEdit(context, context.luckysheet_select_save)) {
|
|
149
169
|
setContext(function (draftCtx) {
|
|
170
|
+
var _a;
|
|
150
171
|
setFormulaEditorOwner(draftCtx, "fx");
|
|
151
172
|
var last = draftCtx.luckysheet_select_save[draftCtx.luckysheet_select_save.length - 1];
|
|
152
173
|
var row_index = last.row_focus;
|
|
153
174
|
var col_index = last.column_focus;
|
|
154
|
-
|
|
155
|
-
|
|
175
|
+
if (!_.isNil(row_index) && !_.isNil(col_index)) {
|
|
176
|
+
var flowdata = getFlowdata(draftCtx);
|
|
177
|
+
var cellAt = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index]) === null || _a === void 0 ? void 0 : _a[col_index];
|
|
178
|
+
if ((cellAt === null || cellAt === void 0 ? void 0 : cellAt.f) != null && String(cellAt.f).trim() !== "") {
|
|
179
|
+
suppressFormulaRangeSelectionForInitialEdit(draftCtx);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
var currentUpdate = draftCtx.luckysheetCellUpdate || [];
|
|
183
|
+
var alreadyEditingSameCell = currentUpdate.length === 2 && currentUpdate[0] === row_index && currentUpdate[1] === col_index;
|
|
184
|
+
if (!alreadyEditingSameCell) {
|
|
185
|
+
refs.globalCache.doNotUpdateCell = true;
|
|
186
|
+
draftCtx.luckysheetCellUpdate = [row_index, col_index];
|
|
187
|
+
refs.globalCache.doNotFocus = true;
|
|
188
|
+
}
|
|
156
189
|
});
|
|
157
190
|
}
|
|
158
191
|
setContext(function (draftCtx) {
|
|
@@ -211,7 +244,26 @@ var FxEditor = function FxEditor() {
|
|
|
211
244
|
}
|
|
212
245
|
}, [getActiveFormula, insertSelectedFormula]);
|
|
213
246
|
var onKeyDown = useCallback(function (e) {
|
|
214
|
-
var _a, _b, _c;
|
|
247
|
+
var _a, _b, _c, _d;
|
|
248
|
+
if (e.key === "Delete" || e.key === "Backspace") {
|
|
249
|
+
var anchor = formulaAnchorCellRef.current;
|
|
250
|
+
if (anchor != null) {
|
|
251
|
+
var anchorRow_1 = anchor[0],
|
|
252
|
+
anchorCol_1 = anchor[1];
|
|
253
|
+
setTimeout(function () {
|
|
254
|
+
setContext(function (draftCtx) {
|
|
255
|
+
draftCtx.luckysheetCellUpdate = [anchorRow_1, anchorCol_1];
|
|
256
|
+
draftCtx.luckysheet_select_save = [{
|
|
257
|
+
row: [anchorRow_1, anchorRow_1],
|
|
258
|
+
column: [anchorCol_1, anchorCol_1],
|
|
259
|
+
row_focus: anchorRow_1,
|
|
260
|
+
column_focus: anchorCol_1
|
|
261
|
+
}];
|
|
262
|
+
markRangeSelectionDirty(draftCtx);
|
|
263
|
+
});
|
|
264
|
+
}, 0);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
215
267
|
if (context.allowEdit === false) {
|
|
216
268
|
return;
|
|
217
269
|
}
|
|
@@ -225,7 +277,50 @@ var FxEditor = function FxEditor() {
|
|
|
225
277
|
recentText.current = refs.fxInput.current.innerText;
|
|
226
278
|
var key = e.key;
|
|
227
279
|
var currentInputText = ((_c = (_b = refs.fxInput.current) === null || _b === void 0 ? void 0 : _b.innerText) === null || _c === void 0 ? void 0 : _c.trim()) || "";
|
|
228
|
-
if (key === "
|
|
280
|
+
if ((key === "=" || currentInputText.startsWith("=")) && context.luckysheetCellUpdate.length === 2 && formulaAnchorCellRef.current == null) {
|
|
281
|
+
setContext(function (draftCtx) {
|
|
282
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
283
|
+
});
|
|
284
|
+
formulaAnchorCellRef.current = [context.luckysheetCellUpdate[0], context.luckysheetCellUpdate[1]];
|
|
285
|
+
}
|
|
286
|
+
if (key === "(" && currentInputText.startsWith("=")) {
|
|
287
|
+
setContext(function (draftCtx) {
|
|
288
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
if (key === "," && context.luckysheetCellUpdate.length > 0 && currentInputText.startsWith("=") && formulaAnchorCellRef.current) {
|
|
292
|
+
setContext(function (draftCtx) {
|
|
293
|
+
draftCtx.formulaCache.rangeSelectionActive = null;
|
|
294
|
+
});
|
|
295
|
+
var _e = formulaAnchorCellRef.current,
|
|
296
|
+
anchorRow_2 = _e[0],
|
|
297
|
+
anchorCol_2 = _e[1];
|
|
298
|
+
setTimeout(function () {
|
|
299
|
+
setContext(function (draftCtx) {
|
|
300
|
+
var _a, _b;
|
|
301
|
+
draftCtx.luckysheetCellUpdate = [anchorRow_2, anchorCol_2];
|
|
302
|
+
draftCtx.luckysheet_select_save = [{
|
|
303
|
+
row: [anchorRow_2, anchorRow_2],
|
|
304
|
+
column: [anchorCol_2, anchorCol_2],
|
|
305
|
+
row_focus: anchorRow_2,
|
|
306
|
+
column_focus: anchorCol_2
|
|
307
|
+
}];
|
|
308
|
+
draftCtx.formulaRangeSelect = undefined;
|
|
309
|
+
draftCtx.formulaCache.selectingRangeIndex = -1;
|
|
310
|
+
draftCtx.formulaCache.func_selectedrange = undefined;
|
|
311
|
+
draftCtx.formulaCache.rangechangeindex = undefined;
|
|
312
|
+
draftCtx.formulaCache.rangestart = false;
|
|
313
|
+
draftCtx.formulaCache.rangedrag_column_start = false;
|
|
314
|
+
draftCtx.formulaCache.rangedrag_row_start = false;
|
|
315
|
+
createRangeHightlight(draftCtx, ((_a = refs.fxInput.current) === null || _a === void 0 ? void 0 : _a.innerHTML) || ((_b = refs.cellInput.current) === null || _b === void 0 ? void 0 : _b.innerHTML) || "");
|
|
316
|
+
moveHighlightCell(draftCtx, "down", 0, "rangeOfSelect");
|
|
317
|
+
});
|
|
318
|
+
}, 0);
|
|
319
|
+
}
|
|
320
|
+
var isArrowKey = key === "ArrowUp" || key === "ArrowDown" || key === "ArrowLeft" || key === "ArrowRight";
|
|
321
|
+
var isDirectPlainTypeEdit = context.luckysheetCellUpdate.length > 0 && ((_d = refs.globalCache) === null || _d === void 0 ? void 0 : _d.enteredEditByTyping) === true && !currentInputText.startsWith("=");
|
|
322
|
+
var sheetArrowShortcut = isArrowKey && (e.metaKey || e.ctrlKey || e.shiftKey);
|
|
323
|
+
if ((key === "ArrowLeft" || key === "ArrowRight") && !(isDirectPlainTypeEdit && sheetArrowShortcut)) {
|
|
229
324
|
e.stopPropagation();
|
|
230
325
|
}
|
|
231
326
|
if ((e.metaKey || e.ctrlKey) && context.luckysheetCellUpdate.length > 0) {
|
|
@@ -252,7 +347,7 @@ var FxEditor = function FxEditor() {
|
|
|
252
347
|
}
|
|
253
348
|
return;
|
|
254
349
|
}
|
|
255
|
-
if (e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0) {
|
|
350
|
+
if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0) {
|
|
256
351
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
257
352
|
var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
|
|
258
353
|
var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -271,7 +366,7 @@ var FxEditor = function FxEditor() {
|
|
|
271
366
|
}
|
|
272
367
|
}
|
|
273
368
|
e.preventDefault();
|
|
274
|
-
} else if (e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0) {
|
|
369
|
+
} else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0) {
|
|
275
370
|
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
276
371
|
var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
|
|
277
372
|
var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
|
|
@@ -330,7 +425,7 @@ var FxEditor = function FxEditor() {
|
|
|
330
425
|
}
|
|
331
426
|
}
|
|
332
427
|
});
|
|
333
|
-
}, [capturePreFormulaState, context.allowEdit, context.luckysheetCellUpdate
|
|
428
|
+
}, [capturePreFormulaState, context.allowEdit, context.luckysheetCellUpdate, handleFormulaHistoryUndoRedo, refs.cellInput, refs.fxInput, setContext]);
|
|
334
429
|
var handleHideShowHint = function handleHideShowHint() {
|
|
335
430
|
var _a, _b, _c, _d;
|
|
336
431
|
var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -351,11 +446,18 @@ var FxEditor = function FxEditor() {
|
|
|
351
446
|
}
|
|
352
447
|
};
|
|
353
448
|
var onChange = useCallback(function () {
|
|
354
|
-
var _a, _b, _c;
|
|
449
|
+
var _a, _b, _c, _d;
|
|
355
450
|
if (context.isFlvReadOnly) return;
|
|
451
|
+
var fxEl = refs.fxInput.current;
|
|
452
|
+
if (fxEl && context.luckysheetCellUpdate.length === 2 && formulaAnchorCellRef.current == null) {
|
|
453
|
+
var t = ((_a = fxEl.innerText) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
454
|
+
if (t.startsWith("=")) {
|
|
455
|
+
formulaAnchorCellRef.current = [context.luckysheetCellUpdate[0], context.luckysheetCellUpdate[1]];
|
|
456
|
+
}
|
|
457
|
+
}
|
|
356
458
|
handleHideShowHint();
|
|
357
|
-
setShowSearchHint(shouldShowFormulaFunctionList((
|
|
358
|
-
var currentCommaCount = countCommasBeforeCursor((
|
|
459
|
+
setShowSearchHint(shouldShowFormulaFunctionList((_c = (_b = refs.fxInput) === null || _b === void 0 ? void 0 : _b.current) !== null && _c !== void 0 ? _c : null));
|
|
460
|
+
var currentCommaCount = countCommasBeforeCursor((_d = refs.fxInput) === null || _d === void 0 ? void 0 : _d.current);
|
|
359
461
|
setCommaCount(currentCommaCount);
|
|
360
462
|
var e = lastKeyDownEventRef.current;
|
|
361
463
|
if (!e) {
|
|
@@ -390,7 +492,7 @@ var FxEditor = function FxEditor() {
|
|
|
390
492
|
handleFormulaInput(draftCtx, refs.cellInput.current, refs.fxInput.current, kcode, recentText.current);
|
|
391
493
|
});
|
|
392
494
|
}
|
|
393
|
-
}, [appendFormulaHistoryFromPrimaryEditor, context.isFlvReadOnly, refs.cellInput, refs.fxInput, setContext]);
|
|
495
|
+
}, [appendFormulaHistoryFromPrimaryEditor, context.isFlvReadOnly, context.luckysheetCellUpdate, refs.cellInput, refs.fxInput, setContext]);
|
|
394
496
|
useRerenderOnFormulaCaret(refs.fxInput, context.luckysheetCellUpdate.length > 0);
|
|
395
497
|
var getFunctionNameFromInput = useCallback(function () {
|
|
396
498
|
var _a, _b, _c, _d;
|
|
@@ -445,7 +547,7 @@ var FxEditor = function FxEditor() {
|
|
|
445
547
|
document.addEventListener("mouseup", _onMouseUp);
|
|
446
548
|
};
|
|
447
549
|
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
448
|
-
className: "fortune-fx-editor",
|
|
550
|
+
className: showFxFormulaChrome ? "fortune-fx-editor fortune-fx-editor--formula-owner" : "fortune-fx-editor",
|
|
449
551
|
ref: divRef
|
|
450
552
|
}, /*#__PURE__*/React.createElement(NameBox, null), /*#__PURE__*/React.createElement("div", {
|
|
451
553
|
className: "fortune-fx-icon",
|
|
@@ -10,7 +10,7 @@ var __assign = this && this.__assign || function () {
|
|
|
10
10
|
};
|
|
11
11
|
import { locale } from "@fileverse-dev/fortune-core";
|
|
12
12
|
import { Button, TextField, LucideIcon, Tooltip } from "@fileverse/ui";
|
|
13
|
-
import React, { useContext, useEffect, useRef, useState } from "react";
|
|
13
|
+
import React, { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
14
14
|
import WorkbookContext from "../../../context";
|
|
15
15
|
import "./index.css";
|
|
16
16
|
import { DraggableDiv } from "./dragable-div";
|
|
@@ -49,29 +49,49 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
49
49
|
ETHERSCAN_API_KEY: "Etherscan API key"
|
|
50
50
|
};
|
|
51
51
|
var hintRef = useRef(null);
|
|
52
|
-
var
|
|
52
|
+
var cellHeightPx = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) != null ? Number(firstSelection.height_move) : 24;
|
|
53
|
+
var belowCellTop = cellHeightPx + 4;
|
|
54
|
+
var _h = useState(belowCellTop),
|
|
53
55
|
top = _h[0],
|
|
54
56
|
setTop = _h[1];
|
|
55
57
|
var _j = useState(false),
|
|
56
58
|
showDelayedHint = _j[0],
|
|
57
59
|
setShowDelayedHint = _j[1];
|
|
58
|
-
var
|
|
59
|
-
var _a
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
var measureFormulaHintPlacement = useCallback(function () {
|
|
61
|
+
var _a;
|
|
62
|
+
if ((firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) == null || firstSelection.height_move == null) {
|
|
63
|
+
setTop(belowCellTop);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
var cellH = Number(firstSelection.height_move) || cellHeightPx;
|
|
67
|
+
var innerEl = hintRef.current;
|
|
68
|
+
var popupHeight = Math.min((innerEl === null || innerEl === void 0 ? void 0 : innerEl.offsetHeight) || 360, 360);
|
|
69
|
+
var inputBox = document.getElementById("luckysheet-input-box");
|
|
70
|
+
var rect = inputBox === null || inputBox === void 0 ? void 0 : inputBox.getBoundingClientRect();
|
|
71
|
+
if (!rect) {
|
|
72
|
+
setTop(cellH + 4);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var cellBottomViewport = rect.top + cellH;
|
|
76
|
+
var availableBelow = window.innerHeight - cellBottomViewport - 12;
|
|
77
|
+
var preferBelow = popupHeight <= availableBelow;
|
|
78
|
+
var topV = preferBelow ? cellH + 4 : -(popupHeight + 8);
|
|
79
|
+
var fxHint = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
80
|
+
if (fxHint && fxHint.style.display !== "none") {
|
|
71
81
|
topV = 25;
|
|
72
82
|
}
|
|
73
83
|
setTop(topV);
|
|
74
|
-
};
|
|
84
|
+
}, [belowCellTop, cellHeightPx, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top]);
|
|
85
|
+
useLayoutEffect(function () {
|
|
86
|
+
if (!fn) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
measureFormulaHintPlacement();
|
|
90
|
+
var id = requestAnimationFrame(measureFormulaHintPlacement);
|
|
91
|
+
return function () {
|
|
92
|
+
cancelAnimationFrame(id);
|
|
93
|
+
};
|
|
94
|
+
}, [functionName, context.functionHint, measureFormulaHintPlacement, showFormulaHint, commaCount, showFunctionBody]);
|
|
75
95
|
var hexToRgbString = function hexToRgbString(hex) {
|
|
76
96
|
hex = hex.replace("#", "");
|
|
77
97
|
var r = parseInt(hex.substring(0, 2), 16);
|
|
@@ -84,14 +104,13 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
84
104
|
return bg;
|
|
85
105
|
};
|
|
86
106
|
useEffect(function () {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
107
|
+
setShowDelayedHint(false);
|
|
108
|
+
var t = setTimeout(function () {
|
|
109
|
+
return setShowDelayedHint(true);
|
|
110
|
+
}, 40);
|
|
111
|
+
return function () {
|
|
112
|
+
return clearTimeout(t);
|
|
113
|
+
};
|
|
95
114
|
}, [top]);
|
|
96
115
|
if (!fn) return null;
|
|
97
116
|
var fnNameClass = fn.n ? String(fn.n).replace(/[^a-zA-Z0-9-]/g, "-").replace(/-+/g, "-") : "";
|
|
@@ -174,7 +193,7 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
174
193
|
localStorage.setItem("formula-expand", "".concat(!showFunctionBody));
|
|
175
194
|
setShouldShowFunctionBody(!showFunctionBody);
|
|
176
195
|
setTimeout(function () {
|
|
177
|
-
|
|
196
|
+
measureFormulaHintPlacement();
|
|
178
197
|
}, 50);
|
|
179
198
|
}
|
|
180
199
|
dragHasMoved.current = false;
|
|
@@ -277,6 +296,7 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
277
296
|
cursor: "auto"
|
|
278
297
|
}
|
|
279
298
|
}, fn.API_KEY && (/*#__PURE__*/React.createElement("div", {
|
|
299
|
+
className: "luckysheet-formula-help-content-api",
|
|
280
300
|
style: {
|
|
281
301
|
borderLeft: "4px solid ".concat(isKeyAdded ? "#177E23" : "#fb923c"),
|
|
282
302
|
backgroundColor: "white",
|
|
@@ -340,6 +360,7 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
340
360
|
className: "fortune-formula-hint__cta min-w-[80px]",
|
|
341
361
|
"data-testid": "formula-hint-cta-ok"
|
|
342
362
|
}, "Ok"))))))), /*#__PURE__*/React.createElement("div", {
|
|
363
|
+
id: "luckysheet-formula-help-content-example",
|
|
343
364
|
style: {
|
|
344
365
|
backgroundColor: "white",
|
|
345
366
|
padding: "6px",
|
|
@@ -8,17 +8,27 @@ var __assign = this && this.__assign || function () {
|
|
|
8
8
|
};
|
|
9
9
|
return __assign.apply(this, arguments);
|
|
10
10
|
};
|
|
11
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
15
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
};
|
|
11
19
|
import _ from "lodash";
|
|
12
|
-
import React, { useContext,
|
|
20
|
+
import React, { useCallback, useContext, useLayoutEffect, useRef, useState } from "react";
|
|
13
21
|
import { LucideIcon, Tooltip } from "@fileverse/ui";
|
|
14
22
|
import { UNFilter } from "./constant";
|
|
15
23
|
import WorkbookContext from "../../../context";
|
|
16
24
|
import "./index.css";
|
|
17
|
-
var FormulaSearch = function FormulaSearch(
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
var FormulaSearch = function FormulaSearch(_a) {
|
|
26
|
+
var _b, _c, _d;
|
|
27
|
+
var from = _a.from,
|
|
28
|
+
divProps = __rest(_a, ["from"]);
|
|
29
|
+
var _e = useContext(WorkbookContext),
|
|
30
|
+
context = _e.context,
|
|
31
|
+
isAuthorized = _e.settings.isAuthorized;
|
|
22
32
|
var authedFunction = ["COINGECKO", "ETHERSCAN", "DEFILLAMA", "GNOSIS", "BASE", "EOA", "PNL", "SAFE", "BLOCKSCOUT", "LENS", "FARCASTER", "Ethereum", "SMARTCONTRACT", "DUNESIM"];
|
|
23
33
|
var filteredDefaultCandidates = context.defaultCandidates.filter(function (item) {
|
|
24
34
|
return !authedFunction.includes(item.n);
|
|
@@ -30,39 +40,58 @@ var FormulaSearch = function FormulaSearch(props) {
|
|
|
30
40
|
var finalFunctionCandidates = isAuthorized ? context.functionCandidates : context.functionCandidates.filter(function (item) {
|
|
31
41
|
return item.t !== 20;
|
|
32
42
|
});
|
|
33
|
-
var firstSelection = (
|
|
43
|
+
var firstSelection = (_b = context.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b[0];
|
|
44
|
+
var cellHeightPx = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) != null ? Number(firstSelection.height_move) : 24;
|
|
45
|
+
var belowCellTop = cellHeightPx + 4;
|
|
34
46
|
var hintRef = useRef(null);
|
|
35
|
-
var
|
|
36
|
-
top =
|
|
37
|
-
setTop =
|
|
38
|
-
var
|
|
39
|
-
var _a
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
var _f = useState(belowCellTop),
|
|
48
|
+
top = _f[0],
|
|
49
|
+
setTop = _f[1];
|
|
50
|
+
var applyPlacement = useCallback(function () {
|
|
51
|
+
var _a;
|
|
52
|
+
if ((firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) == null || firstSelection.height_move == null) {
|
|
53
|
+
setTop(belowCellTop);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
var fromFx = from === "fx";
|
|
57
|
+
var cellH = Number(firstSelection.height_move) || cellHeightPx;
|
|
58
|
+
if (fromFx) {
|
|
59
|
+
setTop(25);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
var innerEl = hintRef.current;
|
|
63
|
+
var popupHeight = Math.min((innerEl === null || innerEl === void 0 ? void 0 : innerEl.offsetHeight) || 360, 360);
|
|
64
|
+
var inputBox = document.getElementById("luckysheet-input-box");
|
|
65
|
+
var rect = inputBox === null || inputBox === void 0 ? void 0 : inputBox.getBoundingClientRect();
|
|
66
|
+
if (!rect) {
|
|
67
|
+
setTop(cellH + 4);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
var cellBottomViewport = rect.top + cellH;
|
|
71
|
+
var availableBelow = window.innerHeight - cellBottomViewport - 12;
|
|
72
|
+
var preferBelow = popupHeight <= availableBelow;
|
|
73
|
+
var topV = preferBelow ? cellH + 4 : -(popupHeight + 8);
|
|
74
|
+
var fxHint = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
75
|
+
if (fxHint && fxHint.style.display !== "none") {
|
|
51
76
|
topV = 25;
|
|
52
77
|
}
|
|
53
78
|
setTop(topV);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
79
|
+
}, [belowCellTop, cellHeightPx, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top, from]);
|
|
80
|
+
useLayoutEffect(function () {
|
|
81
|
+
applyPlacement();
|
|
82
|
+
var id = requestAnimationFrame(applyPlacement);
|
|
83
|
+
return function () {
|
|
84
|
+
cancelAnimationFrame(id);
|
|
85
|
+
};
|
|
86
|
+
}, [applyPlacement, (_c = context.defaultCandidates) === null || _c === void 0 ? void 0 : _c.length, (_d = context.functionCandidates) === null || _d === void 0 ? void 0 : _d.length, context.functionHint]);
|
|
58
87
|
if (_.isEmpty(context.functionCandidates) && _.isEmpty(context.defaultCandidates)) return null;
|
|
59
88
|
return /*#__PURE__*/React.createElement("div", {
|
|
60
|
-
className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll ".concat(
|
|
89
|
+
className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll ".concat(from === "fx" ? "fx-search" : "cell-search"),
|
|
61
90
|
id: "luckysheet-formula-search-c-p",
|
|
62
91
|
style: {
|
|
63
92
|
top: top
|
|
64
93
|
}
|
|
65
|
-
}, /*#__PURE__*/React.createElement("div", __assign({},
|
|
94
|
+
}, /*#__PURE__*/React.createElement("div", __assign({}, divProps, {
|
|
66
95
|
ref: hintRef,
|
|
67
96
|
id: "luckysheet-formula-search-c",
|
|
68
97
|
className: "luckysheet-formula-search-c"
|