@fileverse-dev/fortune-react 1.2.22 → 1.2.24
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 +97 -10
- package/es/components/SheetOverlay/FormulaHint/index.js +7 -2
- package/es/components/SheetOverlay/FormulaSearch/index.js +5 -1
- package/es/components/SheetOverlay/InputBox.js +24 -6
- package/lib/components/FxEditor/index.js +97 -10
- package/lib/components/SheetOverlay/FormulaHint/index.js +7 -2
- package/lib/components/SheetOverlay/FormulaSearch/index.js +5 -1
- package/lib/components/SheetOverlay/InputBox.js +24 -6
- package/package.json +2 -2
|
@@ -5,23 +5,40 @@ import _ from "lodash";
|
|
|
5
5
|
import WorkbookContext from "../../context";
|
|
6
6
|
import ContentEditable from "../SheetOverlay/ContentEditable";
|
|
7
7
|
import NameBox from "./NameBox";
|
|
8
|
+
import FormulaSearch from "../../components/SheetOverlay/FormulaSearch";
|
|
9
|
+
import FormulaHint from "../../components/SheetOverlay/FormulaHint";
|
|
8
10
|
import usePrevious from "../../hooks/usePrevious";
|
|
9
11
|
import { LucideIcon } from "../../components/SheetOverlay/LucideIcon";
|
|
12
|
+
import { countCommasBeforeCursor } from "../../components/SheetOverlay/helper";
|
|
10
13
|
var FxEditor = function FxEditor() {
|
|
11
|
-
var _a;
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
|
|
16
|
+
var _d = useState(false),
|
|
17
|
+
showSearchHint = _d[0],
|
|
18
|
+
setShowSearchHint = _d[1];
|
|
19
|
+
var _e = useState(!hideFormulaHintLocal),
|
|
20
|
+
showFormulaHint = _e[0],
|
|
21
|
+
setShowFormulaHint = _e[1];
|
|
22
|
+
var _f = useState(0),
|
|
23
|
+
commaCount = _f[0],
|
|
24
|
+
setCommaCount = _f[1];
|
|
25
|
+
var _g = useContext(WorkbookContext),
|
|
26
|
+
context = _g.context,
|
|
27
|
+
setContext = _g.setContext,
|
|
28
|
+
refs = _g.refs;
|
|
16
29
|
var lastKeyDownEventRef = useRef(null);
|
|
17
30
|
var inputContainerRef = useRef(null);
|
|
18
|
-
var
|
|
19
|
-
isHidenRC =
|
|
20
|
-
setIsHidenRC =
|
|
31
|
+
var _h = useState(false),
|
|
32
|
+
isHidenRC = _h[0],
|
|
33
|
+
setIsHidenRC = _h[1];
|
|
21
34
|
var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
|
|
22
35
|
var prevFirstSelection = usePrevious(firstSelection);
|
|
23
36
|
var prevSheetId = usePrevious(context.currentSheetId);
|
|
24
37
|
var recentText = useRef("");
|
|
38
|
+
var handleShowFormulaHint = function handleShowFormulaHint() {
|
|
39
|
+
localStorage.setItem("formulaMore", String(showFormulaHint));
|
|
40
|
+
setShowFormulaHint(!showFormulaHint);
|
|
41
|
+
};
|
|
25
42
|
useEffect(function () {
|
|
26
43
|
var _a;
|
|
27
44
|
setIsHidenRC(isShowHidenCR(context));
|
|
@@ -65,9 +82,12 @@ var FxEditor = function FxEditor() {
|
|
|
65
82
|
}
|
|
66
83
|
}, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, refs.globalCache, setContext]);
|
|
67
84
|
var onKeyDown = useCallback(function (e) {
|
|
85
|
+
var _a;
|
|
68
86
|
if (context.allowEdit === false) {
|
|
69
87
|
return;
|
|
70
88
|
}
|
|
89
|
+
var currentCommaCount = countCommasBeforeCursor((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
|
|
90
|
+
setCommaCount(currentCommaCount);
|
|
71
91
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
72
92
|
var key = e.key;
|
|
73
93
|
recentText.current = refs.fxInput.current.innerText;
|
|
@@ -116,7 +136,32 @@ var FxEditor = function FxEditor() {
|
|
|
116
136
|
}
|
|
117
137
|
});
|
|
118
138
|
}, [context.allowEdit, context.luckysheetCellUpdate.length, refs.fxInput, setContext]);
|
|
139
|
+
var getLastInputSpanText = function getLastInputSpanText() {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
var parser = new DOMParser();
|
|
142
|
+
var doc = parser.parseFromString("<div>".concat((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerHTML, "</div>"), "text/html");
|
|
143
|
+
var spans = doc.querySelectorAll("span");
|
|
144
|
+
var lastSpan = spans[spans.length - 1];
|
|
145
|
+
return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
|
|
146
|
+
};
|
|
119
147
|
var onChange = useCallback(function () {
|
|
148
|
+
var _a, _b, _c, _d, _e;
|
|
149
|
+
if (context.isFlvReadOnly) return;
|
|
150
|
+
var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
151
|
+
var fxHint = (_b = document.getElementsByClassName("fx-hint")) === null || _b === void 0 ? void 0 : _b[0];
|
|
152
|
+
if (el) {
|
|
153
|
+
el.style.display = "none";
|
|
154
|
+
}
|
|
155
|
+
if (fxHint) {
|
|
156
|
+
fxHint.style.display = "block";
|
|
157
|
+
}
|
|
158
|
+
if (((_d = (_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current) === null || _d === void 0 ? void 0 : _d.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
|
|
159
|
+
setShowSearchHint(true);
|
|
160
|
+
} else {
|
|
161
|
+
setShowSearchHint(false);
|
|
162
|
+
}
|
|
163
|
+
var currentCommaCount = countCommasBeforeCursor((_e = refs.fxInput) === null || _e === void 0 ? void 0 : _e.current);
|
|
164
|
+
setCommaCount(currentCommaCount);
|
|
120
165
|
var e = lastKeyDownEventRef.current;
|
|
121
166
|
if (!e) return;
|
|
122
167
|
var kcode = e.keyCode;
|
|
@@ -156,6 +201,19 @@ var FxEditor = function FxEditor() {
|
|
|
156
201
|
ref: inputContainerRef,
|
|
157
202
|
className: "fortune-fx-input-container"
|
|
158
203
|
}, /*#__PURE__*/React.createElement(ContentEditable, {
|
|
204
|
+
onMouseUp: function onMouseUp() {
|
|
205
|
+
var _a, _b, _c;
|
|
206
|
+
var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
207
|
+
var fxHint = (_b = document.getElementsByClassName("fx-hint")) === null || _b === void 0 ? void 0 : _b[0];
|
|
208
|
+
if (el) {
|
|
209
|
+
el.style.display = "none";
|
|
210
|
+
}
|
|
211
|
+
if (fxHint) {
|
|
212
|
+
fxHint.style.display = "block";
|
|
213
|
+
}
|
|
214
|
+
var currentCommaCount = countCommasBeforeCursor((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current);
|
|
215
|
+
setCommaCount(currentCommaCount);
|
|
216
|
+
},
|
|
159
217
|
innerRef: function innerRef(e) {
|
|
160
218
|
refs.fxInput.current = e;
|
|
161
219
|
},
|
|
@@ -166,7 +224,36 @@ var FxEditor = function FxEditor() {
|
|
|
166
224
|
onKeyDown: onKeyDown,
|
|
167
225
|
onChange: onChange,
|
|
168
226
|
tabIndex: 0,
|
|
169
|
-
allowEdit: allowEdit
|
|
170
|
-
})
|
|
227
|
+
allowEdit: allowEdit && !context.isFlvReadOnly
|
|
228
|
+
}), showSearchHint && /*#__PURE__*/React.createElement(FormulaSearch, {
|
|
229
|
+
onMouseMove: function onMouseMove(e) {
|
|
230
|
+
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
231
|
+
var hoveredItem = e.target.closest(".luckysheet-formula-search-item");
|
|
232
|
+
if (!hoveredItem) return;
|
|
233
|
+
hoveredItem.classList.add("luckysheet-formula-search-item-active");
|
|
234
|
+
}
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
}
|
|
237
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
238
|
+
className: "fx-hint"
|
|
239
|
+
}, context.functionHint && ((_c = (_b = refs.fxInput) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.innerText.includes("(")) && (/*#__PURE__*/React.createElement(FormulaHint, {
|
|
240
|
+
handleShowFormulaHint: handleShowFormulaHint,
|
|
241
|
+
showFormulaHint: showFormulaHint,
|
|
242
|
+
commaCount: commaCount
|
|
243
|
+
})), context.functionHint && !showFormulaHint && (/*#__PURE__*/React.createElement("div", {
|
|
244
|
+
className: "luckysheet-hin absolute show-more-btn",
|
|
245
|
+
onClick: function onClick() {
|
|
246
|
+
handleShowFormulaHint();
|
|
247
|
+
}
|
|
248
|
+
}, /*#__PURE__*/React.createElement(LucideIcon, {
|
|
249
|
+
name: "DSheetTextDisabled",
|
|
250
|
+
fill: "black",
|
|
251
|
+
style: {
|
|
252
|
+
width: "14px",
|
|
253
|
+
height: "14px",
|
|
254
|
+
margin: "auto",
|
|
255
|
+
marginTop: "1px"
|
|
256
|
+
}
|
|
257
|
+
}))))));
|
|
171
258
|
};
|
|
172
259
|
export default FxEditor;
|
|
@@ -55,7 +55,7 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
55
55
|
showDelayedHint = _g[0],
|
|
56
56
|
setShowDelayedHint = _g[1];
|
|
57
57
|
var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
|
|
58
|
-
var _a, _b, _c, _d;
|
|
58
|
+
var _a, _b, _c, _d, _e, _f;
|
|
59
59
|
if (!((_a = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) === null || _a === void 0 ? void 0 : _a.toString()) || !((_b = firstSelection.height_move) === null || _b === void 0 ? void 0 : _b.toString()) || !hintRef.current) return;
|
|
60
60
|
var hintHeight = 360;
|
|
61
61
|
var inputBoxTop = parseInt(((_c = document.getElementById("luckysheet-input-box")) === null || _c === void 0 ? void 0 : _c.style.top) || "0", 10) - 85;
|
|
@@ -64,7 +64,12 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
64
64
|
var hintAbove = hintHeight > availableBelow;
|
|
65
65
|
var selectionHeight = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) || 0;
|
|
66
66
|
var divOffset = ((_d = hintRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 0;
|
|
67
|
-
|
|
67
|
+
var topV = hintAbove ? selectionHeight - (divOffset + 30) : selectionHeight + 4;
|
|
68
|
+
var el = (_e = document.getElementsByClassName('fx-hint')) === null || _e === void 0 ? void 0 : _e[0];
|
|
69
|
+
if (el && ((_f = el === null || el === void 0 ? void 0 : el.style) === null || _f === void 0 ? void 0 : _f.display) !== 'none') {
|
|
70
|
+
topV = 25;
|
|
71
|
+
}
|
|
72
|
+
setTop(topV);
|
|
68
73
|
};
|
|
69
74
|
var hexToRgbString = function hexToRgbString(hex) {
|
|
70
75
|
hex = hex.replace("#", "");
|
|
@@ -36,7 +36,7 @@ var FormulaSearch = function FormulaSearch(props) {
|
|
|
36
36
|
top = _c[0],
|
|
37
37
|
setTop = _c[1];
|
|
38
38
|
var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
|
|
39
|
-
var _a, _b, _c, _d;
|
|
39
|
+
var _a, _b, _c, _d, _e, _f;
|
|
40
40
|
if (!((_a = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) === null || _a === void 0 ? void 0 : _a.toString()) || !((_b = firstSelection.height_move) === null || _b === void 0 ? void 0 : _b.toString()) || !hintRef.current) return;
|
|
41
41
|
var hintHeight = 360;
|
|
42
42
|
var inputBoxTop = parseInt(((_c = document.getElementById("luckysheet-input-box")) === null || _c === void 0 ? void 0 : _c.style.top) || "0", 10) - 85;
|
|
@@ -46,6 +46,10 @@ var FormulaSearch = function FormulaSearch(props) {
|
|
|
46
46
|
var selectionHeight = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) || 0;
|
|
47
47
|
var divOffset = ((_d = hintRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 0;
|
|
48
48
|
var topV = hintAbove ? selectionHeight - (divOffset + 80) : selectionHeight + 4;
|
|
49
|
+
var el = (_e = document.getElementsByClassName('fx-hint')) === null || _e === void 0 ? void 0 : _e[0];
|
|
50
|
+
if (el && ((_f = el === null || el === void 0 ? void 0 : el.style) === null || _f === void 0 ? void 0 : _f.display) !== 'none') {
|
|
51
|
+
topV = 25;
|
|
52
|
+
}
|
|
49
53
|
setTop(topV);
|
|
50
54
|
};
|
|
51
55
|
useEffect(function () {
|
|
@@ -246,7 +246,6 @@ var InputBox = function InputBox() {
|
|
|
246
246
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
247
247
|
preText.current = inputRef.current.innerText;
|
|
248
248
|
var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
|
|
249
|
-
console.log("currentCommaCount", currentCommaCount);
|
|
250
249
|
setCommaCount(currentCommaCount);
|
|
251
250
|
var allowListNavigation = true;
|
|
252
251
|
if ((e.key === "Delete" || e.key === "Backspace") && getCursorPosition(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
|
|
@@ -344,8 +343,16 @@ var InputBox = function InputBox() {
|
|
|
344
343
|
}
|
|
345
344
|
}, [clearSearchItemActiveClass, context.luckysheetCellUpdate.length, selectActiveFormula, setContext, firstSelection]);
|
|
346
345
|
var onChange = useCallback(function (__, isBlur) {
|
|
347
|
-
var _a;
|
|
348
|
-
|
|
346
|
+
var _a, _b, _c;
|
|
347
|
+
var el = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
348
|
+
var elCell = (_b = document.getElementsByClassName("cell-hint")) === null || _b === void 0 ? void 0 : _b[0];
|
|
349
|
+
if (el) {
|
|
350
|
+
el.style.display = "none";
|
|
351
|
+
}
|
|
352
|
+
if (elCell) {
|
|
353
|
+
elCell.style.display = "block";
|
|
354
|
+
}
|
|
355
|
+
if (((_c = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _c === void 0 ? void 0 : _c.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
|
|
349
356
|
setShowSearchHint(true);
|
|
350
357
|
} else {
|
|
351
358
|
setShowSearchHint(false);
|
|
@@ -496,6 +503,15 @@ var InputBox = function InputBox() {
|
|
|
496
503
|
}, inputBoxStyle) : {}
|
|
497
504
|
}, /*#__PURE__*/React.createElement(ContentEditable, {
|
|
498
505
|
onMouseUp: function onMouseUp() {
|
|
506
|
+
var _a, _b;
|
|
507
|
+
var el = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
508
|
+
var elCell = (_b = document.getElementsByClassName("cell-hint")) === null || _b === void 0 ? void 0 : _b[0];
|
|
509
|
+
if (el) {
|
|
510
|
+
el.style.display = "none";
|
|
511
|
+
}
|
|
512
|
+
if (elCell) {
|
|
513
|
+
elCell.style.display = "block";
|
|
514
|
+
}
|
|
499
515
|
var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
|
|
500
516
|
setCommaCount(currentCommaCount);
|
|
501
517
|
},
|
|
@@ -503,7 +519,7 @@ var InputBox = function InputBox() {
|
|
|
503
519
|
inputRef.current = e;
|
|
504
520
|
refs.cellInput.current = e;
|
|
505
521
|
},
|
|
506
|
-
className: "luckysheet-cell-input",
|
|
522
|
+
className: "luckysheet-cell-input cell-input",
|
|
507
523
|
id: "luckysheet-rich-text-editor",
|
|
508
524
|
style: {
|
|
509
525
|
transform: "scale(".concat(context.zoomRatio, ")"),
|
|
@@ -530,7 +546,9 @@ var InputBox = function InputBox() {
|
|
|
530
546
|
onMouseDown: function onMouseDown(e) {
|
|
531
547
|
selectActiveFormulaOnClick(e);
|
|
532
548
|
}
|
|
533
|
-
})),
|
|
549
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
550
|
+
className: "cell-hint"
|
|
551
|
+
}, showFormulaHint && fn && ((_h = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _h === void 0 ? void 0 : _h.innerText.includes("(")) && (/*#__PURE__*/React.createElement(FormulaHint, {
|
|
534
552
|
handleShowFormulaHint: handleShowFormulaHint,
|
|
535
553
|
showFormulaHint: showFormulaHint,
|
|
536
554
|
commaCount: commaCount
|
|
@@ -558,6 +576,6 @@ var InputBox = function InputBox() {
|
|
|
558
576
|
margin: "auto",
|
|
559
577
|
marginTop: "1px"
|
|
560
578
|
}
|
|
561
|
-
})))))));
|
|
579
|
+
}))))))));
|
|
562
580
|
};
|
|
563
581
|
export default InputBox;
|
|
@@ -12,25 +12,42 @@ var _lodash = _interopRequireDefault(require("lodash"));
|
|
|
12
12
|
var _context = _interopRequireDefault(require("../../context"));
|
|
13
13
|
var _ContentEditable = _interopRequireDefault(require("../SheetOverlay/ContentEditable"));
|
|
14
14
|
var _NameBox = _interopRequireDefault(require("./NameBox"));
|
|
15
|
+
var _FormulaSearch = _interopRequireDefault(require("../../components/SheetOverlay/FormulaSearch"));
|
|
16
|
+
var _FormulaHint = _interopRequireDefault(require("../../components/SheetOverlay/FormulaHint"));
|
|
15
17
|
var _usePrevious = _interopRequireDefault(require("../../hooks/usePrevious"));
|
|
16
18
|
var _LucideIcon = require("../../components/SheetOverlay/LucideIcon");
|
|
19
|
+
var _helper = require("../../components/SheetOverlay/helper");
|
|
17
20
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
21
|
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); }
|
|
19
22
|
var FxEditor = function FxEditor() {
|
|
20
|
-
var _a;
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
|
|
25
|
+
var _d = (0, _react.useState)(false),
|
|
26
|
+
showSearchHint = _d[0],
|
|
27
|
+
setShowSearchHint = _d[1];
|
|
28
|
+
var _e = (0, _react.useState)(!hideFormulaHintLocal),
|
|
29
|
+
showFormulaHint = _e[0],
|
|
30
|
+
setShowFormulaHint = _e[1];
|
|
31
|
+
var _f = (0, _react.useState)(0),
|
|
32
|
+
commaCount = _f[0],
|
|
33
|
+
setCommaCount = _f[1];
|
|
34
|
+
var _g = (0, _react.useContext)(_context.default),
|
|
35
|
+
context = _g.context,
|
|
36
|
+
setContext = _g.setContext,
|
|
37
|
+
refs = _g.refs;
|
|
25
38
|
var lastKeyDownEventRef = (0, _react.useRef)(null);
|
|
26
39
|
var inputContainerRef = (0, _react.useRef)(null);
|
|
27
|
-
var
|
|
28
|
-
isHidenRC =
|
|
29
|
-
setIsHidenRC =
|
|
40
|
+
var _h = (0, _react.useState)(false),
|
|
41
|
+
isHidenRC = _h[0],
|
|
42
|
+
setIsHidenRC = _h[1];
|
|
30
43
|
var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
|
|
31
44
|
var prevFirstSelection = (0, _usePrevious.default)(firstSelection);
|
|
32
45
|
var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
|
|
33
46
|
var recentText = (0, _react.useRef)("");
|
|
47
|
+
var handleShowFormulaHint = function handleShowFormulaHint() {
|
|
48
|
+
localStorage.setItem("formulaMore", String(showFormulaHint));
|
|
49
|
+
setShowFormulaHint(!showFormulaHint);
|
|
50
|
+
};
|
|
34
51
|
(0, _react.useEffect)(function () {
|
|
35
52
|
var _a;
|
|
36
53
|
setIsHidenRC((0, _fortuneCore.isShowHidenCR)(context));
|
|
@@ -74,9 +91,12 @@ var FxEditor = function FxEditor() {
|
|
|
74
91
|
}
|
|
75
92
|
}, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, refs.globalCache, setContext]);
|
|
76
93
|
var onKeyDown = (0, _react.useCallback)(function (e) {
|
|
94
|
+
var _a;
|
|
77
95
|
if (context.allowEdit === false) {
|
|
78
96
|
return;
|
|
79
97
|
}
|
|
98
|
+
var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
|
|
99
|
+
setCommaCount(currentCommaCount);
|
|
80
100
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
81
101
|
var key = e.key;
|
|
82
102
|
recentText.current = refs.fxInput.current.innerText;
|
|
@@ -125,7 +145,32 @@ var FxEditor = function FxEditor() {
|
|
|
125
145
|
}
|
|
126
146
|
});
|
|
127
147
|
}, [context.allowEdit, context.luckysheetCellUpdate.length, refs.fxInput, setContext]);
|
|
148
|
+
var getLastInputSpanText = function getLastInputSpanText() {
|
|
149
|
+
var _a, _b;
|
|
150
|
+
var parser = new DOMParser();
|
|
151
|
+
var doc = parser.parseFromString("<div>".concat((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerHTML, "</div>"), "text/html");
|
|
152
|
+
var spans = doc.querySelectorAll("span");
|
|
153
|
+
var lastSpan = spans[spans.length - 1];
|
|
154
|
+
return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
|
|
155
|
+
};
|
|
128
156
|
var onChange = (0, _react.useCallback)(function () {
|
|
157
|
+
var _a, _b, _c, _d, _e;
|
|
158
|
+
if (context.isFlvReadOnly) return;
|
|
159
|
+
var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
160
|
+
var fxHint = (_b = document.getElementsByClassName("fx-hint")) === null || _b === void 0 ? void 0 : _b[0];
|
|
161
|
+
if (el) {
|
|
162
|
+
el.style.display = "none";
|
|
163
|
+
}
|
|
164
|
+
if (fxHint) {
|
|
165
|
+
fxHint.style.display = "block";
|
|
166
|
+
}
|
|
167
|
+
if (((_d = (_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current) === null || _d === void 0 ? void 0 : _d.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
|
|
168
|
+
setShowSearchHint(true);
|
|
169
|
+
} else {
|
|
170
|
+
setShowSearchHint(false);
|
|
171
|
+
}
|
|
172
|
+
var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_e = refs.fxInput) === null || _e === void 0 ? void 0 : _e.current);
|
|
173
|
+
setCommaCount(currentCommaCount);
|
|
129
174
|
var e = lastKeyDownEventRef.current;
|
|
130
175
|
if (!e) return;
|
|
131
176
|
var kcode = e.keyCode;
|
|
@@ -165,6 +210,19 @@ var FxEditor = function FxEditor() {
|
|
|
165
210
|
ref: inputContainerRef,
|
|
166
211
|
className: "fortune-fx-input-container"
|
|
167
212
|
}, /*#__PURE__*/_react.default.createElement(_ContentEditable.default, {
|
|
213
|
+
onMouseUp: function onMouseUp() {
|
|
214
|
+
var _a, _b, _c;
|
|
215
|
+
var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
216
|
+
var fxHint = (_b = document.getElementsByClassName("fx-hint")) === null || _b === void 0 ? void 0 : _b[0];
|
|
217
|
+
if (el) {
|
|
218
|
+
el.style.display = "none";
|
|
219
|
+
}
|
|
220
|
+
if (fxHint) {
|
|
221
|
+
fxHint.style.display = "block";
|
|
222
|
+
}
|
|
223
|
+
var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current);
|
|
224
|
+
setCommaCount(currentCommaCount);
|
|
225
|
+
},
|
|
168
226
|
innerRef: function innerRef(e) {
|
|
169
227
|
refs.fxInput.current = e;
|
|
170
228
|
},
|
|
@@ -175,7 +233,36 @@ var FxEditor = function FxEditor() {
|
|
|
175
233
|
onKeyDown: onKeyDown,
|
|
176
234
|
onChange: onChange,
|
|
177
235
|
tabIndex: 0,
|
|
178
|
-
allowEdit: allowEdit
|
|
179
|
-
})
|
|
236
|
+
allowEdit: allowEdit && !context.isFlvReadOnly
|
|
237
|
+
}), showSearchHint && /*#__PURE__*/_react.default.createElement(_FormulaSearch.default, {
|
|
238
|
+
onMouseMove: function onMouseMove(e) {
|
|
239
|
+
if (document.getElementById("luckysheet-formula-search-c")) {
|
|
240
|
+
var hoveredItem = e.target.closest(".luckysheet-formula-search-item");
|
|
241
|
+
if (!hoveredItem) return;
|
|
242
|
+
hoveredItem.classList.add("luckysheet-formula-search-item-active");
|
|
243
|
+
}
|
|
244
|
+
e.preventDefault();
|
|
245
|
+
}
|
|
246
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
247
|
+
className: "fx-hint"
|
|
248
|
+
}, context.functionHint && ((_c = (_b = refs.fxInput) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.innerText.includes("(")) && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
249
|
+
handleShowFormulaHint: handleShowFormulaHint,
|
|
250
|
+
showFormulaHint: showFormulaHint,
|
|
251
|
+
commaCount: commaCount
|
|
252
|
+
})), context.functionHint && !showFormulaHint && (/*#__PURE__*/_react.default.createElement("div", {
|
|
253
|
+
className: "luckysheet-hin absolute show-more-btn",
|
|
254
|
+
onClick: function onClick() {
|
|
255
|
+
handleShowFormulaHint();
|
|
256
|
+
}
|
|
257
|
+
}, /*#__PURE__*/_react.default.createElement(_LucideIcon.LucideIcon, {
|
|
258
|
+
name: "DSheetTextDisabled",
|
|
259
|
+
fill: "black",
|
|
260
|
+
style: {
|
|
261
|
+
width: "14px",
|
|
262
|
+
height: "14px",
|
|
263
|
+
margin: "auto",
|
|
264
|
+
marginTop: "1px"
|
|
265
|
+
}
|
|
266
|
+
}))))));
|
|
180
267
|
};
|
|
181
268
|
var _default = exports.default = FxEditor;
|
|
@@ -64,7 +64,7 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
64
64
|
showDelayedHint = _g[0],
|
|
65
65
|
setShowDelayedHint = _g[1];
|
|
66
66
|
var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
|
|
67
|
-
var _a, _b, _c, _d;
|
|
67
|
+
var _a, _b, _c, _d, _e, _f;
|
|
68
68
|
if (!((_a = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) === null || _a === void 0 ? void 0 : _a.toString()) || !((_b = firstSelection.height_move) === null || _b === void 0 ? void 0 : _b.toString()) || !hintRef.current) return;
|
|
69
69
|
var hintHeight = 360;
|
|
70
70
|
var inputBoxTop = parseInt(((_c = document.getElementById("luckysheet-input-box")) === null || _c === void 0 ? void 0 : _c.style.top) || "0", 10) - 85;
|
|
@@ -73,7 +73,12 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
73
73
|
var hintAbove = hintHeight > availableBelow;
|
|
74
74
|
var selectionHeight = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) || 0;
|
|
75
75
|
var divOffset = ((_d = hintRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 0;
|
|
76
|
-
|
|
76
|
+
var topV = hintAbove ? selectionHeight - (divOffset + 30) : selectionHeight + 4;
|
|
77
|
+
var el = (_e = document.getElementsByClassName('fx-hint')) === null || _e === void 0 ? void 0 : _e[0];
|
|
78
|
+
if (el && ((_f = el === null || el === void 0 ? void 0 : el.style) === null || _f === void 0 ? void 0 : _f.display) !== 'none') {
|
|
79
|
+
topV = 25;
|
|
80
|
+
}
|
|
81
|
+
setTop(topV);
|
|
77
82
|
};
|
|
78
83
|
var hexToRgbString = function hexToRgbString(hex) {
|
|
79
84
|
hex = hex.replace("#", "");
|
|
@@ -45,7 +45,7 @@ var FormulaSearch = function FormulaSearch(props) {
|
|
|
45
45
|
top = _c[0],
|
|
46
46
|
setTop = _c[1];
|
|
47
47
|
var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
|
|
48
|
-
var _a, _b, _c, _d;
|
|
48
|
+
var _a, _b, _c, _d, _e, _f;
|
|
49
49
|
if (!((_a = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) === null || _a === void 0 ? void 0 : _a.toString()) || !((_b = firstSelection.height_move) === null || _b === void 0 ? void 0 : _b.toString()) || !hintRef.current) return;
|
|
50
50
|
var hintHeight = 360;
|
|
51
51
|
var inputBoxTop = parseInt(((_c = document.getElementById("luckysheet-input-box")) === null || _c === void 0 ? void 0 : _c.style.top) || "0", 10) - 85;
|
|
@@ -55,6 +55,10 @@ var FormulaSearch = function FormulaSearch(props) {
|
|
|
55
55
|
var selectionHeight = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) || 0;
|
|
56
56
|
var divOffset = ((_d = hintRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 0;
|
|
57
57
|
var topV = hintAbove ? selectionHeight - (divOffset + 80) : selectionHeight + 4;
|
|
58
|
+
var el = (_e = document.getElementsByClassName('fx-hint')) === null || _e === void 0 ? void 0 : _e[0];
|
|
59
|
+
if (el && ((_f = el === null || el === void 0 ? void 0 : el.style) === null || _f === void 0 ? void 0 : _f.display) !== 'none') {
|
|
60
|
+
topV = 25;
|
|
61
|
+
}
|
|
58
62
|
setTop(topV);
|
|
59
63
|
};
|
|
60
64
|
(0, _react.useEffect)(function () {
|
|
@@ -255,7 +255,6 @@ var InputBox = function InputBox() {
|
|
|
255
255
|
lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
|
|
256
256
|
preText.current = inputRef.current.innerText;
|
|
257
257
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
|
|
258
|
-
console.log("currentCommaCount", currentCommaCount);
|
|
259
258
|
setCommaCount(currentCommaCount);
|
|
260
259
|
var allowListNavigation = true;
|
|
261
260
|
if ((e.key === "Delete" || e.key === "Backspace") && (0, _helper.getCursorPosition)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
|
|
@@ -353,8 +352,16 @@ var InputBox = function InputBox() {
|
|
|
353
352
|
}
|
|
354
353
|
}, [clearSearchItemActiveClass, context.luckysheetCellUpdate.length, selectActiveFormula, setContext, firstSelection]);
|
|
355
354
|
var onChange = (0, _react.useCallback)(function (__, isBlur) {
|
|
356
|
-
var _a;
|
|
357
|
-
|
|
355
|
+
var _a, _b, _c;
|
|
356
|
+
var el = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
357
|
+
var elCell = (_b = document.getElementsByClassName("cell-hint")) === null || _b === void 0 ? void 0 : _b[0];
|
|
358
|
+
if (el) {
|
|
359
|
+
el.style.display = "none";
|
|
360
|
+
}
|
|
361
|
+
if (elCell) {
|
|
362
|
+
elCell.style.display = "block";
|
|
363
|
+
}
|
|
364
|
+
if (((_c = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _c === void 0 ? void 0 : _c.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
|
|
358
365
|
setShowSearchHint(true);
|
|
359
366
|
} else {
|
|
360
367
|
setShowSearchHint(false);
|
|
@@ -505,6 +512,15 @@ var InputBox = function InputBox() {
|
|
|
505
512
|
}, inputBoxStyle) : {}
|
|
506
513
|
}, /*#__PURE__*/_react.default.createElement(_ContentEditable.default, {
|
|
507
514
|
onMouseUp: function onMouseUp() {
|
|
515
|
+
var _a, _b;
|
|
516
|
+
var el = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
|
|
517
|
+
var elCell = (_b = document.getElementsByClassName("cell-hint")) === null || _b === void 0 ? void 0 : _b[0];
|
|
518
|
+
if (el) {
|
|
519
|
+
el.style.display = "none";
|
|
520
|
+
}
|
|
521
|
+
if (elCell) {
|
|
522
|
+
elCell.style.display = "block";
|
|
523
|
+
}
|
|
508
524
|
var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
|
|
509
525
|
setCommaCount(currentCommaCount);
|
|
510
526
|
},
|
|
@@ -512,7 +528,7 @@ var InputBox = function InputBox() {
|
|
|
512
528
|
inputRef.current = e;
|
|
513
529
|
refs.cellInput.current = e;
|
|
514
530
|
},
|
|
515
|
-
className: "luckysheet-cell-input",
|
|
531
|
+
className: "luckysheet-cell-input cell-input",
|
|
516
532
|
id: "luckysheet-rich-text-editor",
|
|
517
533
|
style: {
|
|
518
534
|
transform: "scale(".concat(context.zoomRatio, ")"),
|
|
@@ -539,7 +555,9 @@ var InputBox = function InputBox() {
|
|
|
539
555
|
onMouseDown: function onMouseDown(e) {
|
|
540
556
|
selectActiveFormulaOnClick(e);
|
|
541
557
|
}
|
|
542
|
-
})),
|
|
558
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
559
|
+
className: "cell-hint"
|
|
560
|
+
}, showFormulaHint && fn && ((_h = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _h === void 0 ? void 0 : _h.innerText.includes("(")) && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
|
|
543
561
|
handleShowFormulaHint: handleShowFormulaHint,
|
|
544
562
|
showFormulaHint: showFormulaHint,
|
|
545
563
|
commaCount: commaCount
|
|
@@ -567,6 +585,6 @@ var InputBox = function InputBox() {
|
|
|
567
585
|
margin: "auto",
|
|
568
586
|
marginTop: "1px"
|
|
569
587
|
}
|
|
570
|
-
})))))));
|
|
588
|
+
}))))))));
|
|
571
589
|
};
|
|
572
590
|
var _default = exports.default = InputBox;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fileverse-dev/fortune-react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.24",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"tsc": "tsc"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@fileverse-dev/fortune-core": "1.2.
|
|
19
|
+
"@fileverse-dev/fortune-core": "1.2.24",
|
|
20
20
|
"@fileverse/ui": "^4.1.7-patch-40",
|
|
21
21
|
"@tippyjs/react": "^4.2.6",
|
|
22
22
|
"@types/regenerator-runtime": "^0.13.6",
|