@fileverse-dev/fortune-react 1.2.25 → 1.2.27

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.
@@ -9,7 +9,7 @@ import FormulaSearch from "../../components/SheetOverlay/FormulaSearch";
9
9
  import FormulaHint from "../../components/SheetOverlay/FormulaHint";
10
10
  import usePrevious from "../../hooks/usePrevious";
11
11
  import { LucideIcon } from "../../components/SheetOverlay/LucideIcon";
12
- import { countCommasBeforeCursor } from "../../components/SheetOverlay/helper";
12
+ import { countCommasBeforeCursor, isLetterNumberPattern, moveCursorToEnd } from "../../components/SheetOverlay/helper";
13
13
  var FxEditor = function FxEditor() {
14
14
  var _a, _b, _c;
15
15
  var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
@@ -81,6 +81,26 @@ var FxEditor = function FxEditor() {
81
81
  });
82
82
  }
83
83
  }, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, refs.globalCache, setContext]);
84
+ var getActiveFormula = useCallback(function () {
85
+ return document.querySelector(".luckysheet-formula-search-item-active");
86
+ }, []);
87
+ var insertSelectedFormula = useCallback(function (formulaName) {
88
+ if (/^=[a-zA-Z]+$/.test(refs.fxInput.current.innerText)) {
89
+ var ht = "<span dir=\"auto\" class=\"luckysheet-formula-text-color\">=</span><span dir=\"auto\" class=\"luckysheet-formula-text-func\">".concat(formulaName, "</span><span dir=\"auto\" class=\"luckysheet-formula-text-lpar\">(</span>");
90
+ refs.fxInput.current.innerHTML = ht;
91
+ var cellEditor = document.getElementById("luckysheet-rich-text-editor");
92
+ if (cellEditor) {
93
+ cellEditor.innerHTML = ht;
94
+ }
95
+ moveCursorToEnd(refs.fxInput.current);
96
+ setContext(function (draftCtx) {
97
+ draftCtx.functionCandidates = [];
98
+ draftCtx.defaultCandidates = [];
99
+ draftCtx.functionHint = formulaName;
100
+ });
101
+ return;
102
+ }
103
+ }, [setContext]);
84
104
  var onKeyDown = useCallback(function (e) {
85
105
  var _a;
86
106
  if (context.allowEdit === false) {
@@ -94,6 +114,54 @@ var FxEditor = function FxEditor() {
94
114
  if (key === "ArrowLeft" || key === "ArrowRight") {
95
115
  e.stopPropagation();
96
116
  }
117
+ if (e.key === "Enter" && context.luckysheetCellUpdate.length > 0) {
118
+ if (e.altKey || e.metaKey) {
119
+ document.execCommand("insertHTML", false, "\n ");
120
+ document.execCommand("delete", false);
121
+ e.stopPropagation();
122
+ } else {
123
+ var event_1 = e;
124
+ selectActiveFormulaOnClick(event_1);
125
+ }
126
+ return;
127
+ }
128
+ if (e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0) {
129
+ if (document.getElementById("luckysheet-formula-search-c")) {
130
+ var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
131
+ var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
132
+ var previousItem = activeItem ? activeItem.previousElementSibling : null;
133
+ while (previousItem && !previousItem.classList.contains("luckysheet-formula-search-item")) {
134
+ previousItem = previousItem.previousElementSibling;
135
+ }
136
+ if (!previousItem) {
137
+ var items = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelectorAll(".luckysheet-formula-search-item");
138
+ var lastItem = items === null || items === void 0 ? void 0 : items[items.length - 1];
139
+ previousItem = lastItem || null;
140
+ }
141
+ clearSearchItemActiveClass();
142
+ if (previousItem) {
143
+ previousItem.classList.add("luckysheet-formula-search-item-active");
144
+ }
145
+ }
146
+ e.preventDefault();
147
+ } else if (e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0) {
148
+ if (document.getElementById("luckysheet-formula-search-c")) {
149
+ var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
150
+ var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
151
+ var nextItem = activeItem ? activeItem.nextElementSibling : null;
152
+ while (nextItem && !nextItem.classList.contains("luckysheet-formula-search-item")) {
153
+ nextItem = nextItem.nextElementSibling;
154
+ }
155
+ if (!nextItem) {
156
+ nextItem = (formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item")) || null;
157
+ }
158
+ clearSearchItemActiveClass();
159
+ if (nextItem) {
160
+ nextItem.classList.add("luckysheet-formula-search-item-active");
161
+ }
162
+ }
163
+ e.preventDefault();
164
+ }
97
165
  setContext(function (draftCtx) {
98
166
  if (context.luckysheetCellUpdate.length > 0) {
99
167
  switch (key) {
@@ -144,23 +212,35 @@ var FxEditor = function FxEditor() {
144
212
  var lastSpan = spans[spans.length - 1];
145
213
  return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
146
214
  };
147
- var onChange = useCallback(function () {
148
- var _a, _b, _c, _d, _e;
149
- if (context.isFlvReadOnly) return;
215
+ var handleHideShowHint = function handleHideShowHint() {
216
+ var _a, _b, _c, _d;
150
217
  var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
151
218
  var fxHint = (_b = document.getElementsByClassName("fx-hint")) === null || _b === void 0 ? void 0 : _b[0];
219
+ var searchElFx = (_c = document.getElementsByClassName("fx-search")) === null || _c === void 0 ? void 0 : _c[0];
220
+ var searchElCell = (_d = document.getElementsByClassName("cell-search")) === null || _d === void 0 ? void 0 : _d[0];
221
+ if (searchElFx) {
222
+ searchElFx.style.display = "block";
223
+ }
224
+ if (searchElCell) {
225
+ searchElCell.style.display = "none";
226
+ }
152
227
  if (el) {
153
228
  el.style.display = "none";
154
229
  }
155
230
  if (fxHint) {
156
231
  fxHint.style.display = "block";
157
232
  }
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())) {
233
+ };
234
+ var onChange = useCallback(function () {
235
+ var _a, _b, _c;
236
+ if (context.isFlvReadOnly) return;
237
+ handleHideShowHint();
238
+ if (((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
159
239
  setShowSearchHint(true);
160
240
  } else {
161
241
  setShowSearchHint(false);
162
242
  }
163
- var currentCommaCount = countCommasBeforeCursor((_e = refs.fxInput) === null || _e === void 0 ? void 0 : _e.current);
243
+ var currentCommaCount = countCommasBeforeCursor((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current);
164
244
  setCommaCount(currentCommaCount);
165
245
  var e = lastKeyDownEventRef.current;
166
246
  if (!e) return;
@@ -184,6 +264,24 @@ var FxEditor = function FxEditor() {
184
264
  }
185
265
  return true;
186
266
  }, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, isHidenRC]);
267
+ var selectActiveFormulaOnClick = useCallback(function (e) {
268
+ var _a, _b, _c;
269
+ if (e.target.className.includes("sign-fortune")) return;
270
+ recentText.current = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current.innerText;
271
+ var formulaName = (_c = (_b = getActiveFormula()) === null || _b === void 0 ? void 0 : _b.querySelector(".luckysheet-formula-search-func")) === null || _c === void 0 ? void 0 : _c.textContent;
272
+ var lastSpanText = getLastInputSpanText();
273
+ if (formulaName && !isLetterNumberPattern(lastSpanText)) {
274
+ insertSelectedFormula(formulaName);
275
+ e.preventDefault();
276
+ e.stopPropagation();
277
+ }
278
+ }, [getActiveFormula, insertSelectedFormula]);
279
+ var clearSearchItemActiveClass = useCallback(function () {
280
+ var activeFormula = getActiveFormula();
281
+ if (activeFormula) {
282
+ activeFormula.classList.remove("luckysheet-formula-search-item-active");
283
+ }
284
+ }, [getActiveFormula]);
187
285
  return /*#__PURE__*/React.createElement("div", {
188
286
  className: "fortune-fx-editor"
189
287
  }, /*#__PURE__*/React.createElement(NameBox, null), /*#__PURE__*/React.createElement("div", {
@@ -202,16 +300,9 @@ var FxEditor = function FxEditor() {
202
300
  className: "fortune-fx-input-container"
203
301
  }, /*#__PURE__*/React.createElement(ContentEditable, {
204
302
  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);
303
+ var _a;
304
+ handleHideShowHint();
305
+ var currentCommaCount = countCommasBeforeCursor((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
215
306
  setCommaCount(currentCommaCount);
216
307
  },
217
308
  innerRef: function innerRef(e) {
@@ -226,13 +317,18 @@ var FxEditor = function FxEditor() {
226
317
  tabIndex: 0,
227
318
  allowEdit: allowEdit && !context.isFlvReadOnly
228
319
  }), showSearchHint && (/*#__PURE__*/React.createElement(FormulaSearch, {
320
+ from: "fx",
229
321
  onMouseMove: function onMouseMove(e) {
230
322
  if (document.getElementById("luckysheet-formula-search-c")) {
231
323
  var hoveredItem = e.target.closest(".luckysheet-formula-search-item");
232
324
  if (!hoveredItem) return;
325
+ clearSearchItemActiveClass();
233
326
  hoveredItem.classList.add("luckysheet-formula-search-item-active");
234
327
  }
235
328
  e.preventDefault();
329
+ },
330
+ onMouseDown: function onMouseDown(e) {
331
+ selectActiveFormulaOnClick(e);
236
332
  }
237
333
  })), /*#__PURE__*/React.createElement("div", {
238
334
  className: "fx-hint"
@@ -57,7 +57,7 @@ var FormulaSearch = function FormulaSearch(props) {
57
57
  });
58
58
  if (_.isEmpty(context.functionCandidates) && _.isEmpty(context.defaultCandidates)) return null;
59
59
  return /*#__PURE__*/React.createElement("div", {
60
- className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll",
60
+ className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll ".concat((props === null || props === void 0 ? void 0 : props.from) === "fx" ? "fx-search" : "cell-search"),
61
61
  id: "luckysheet-formula-search-c-p",
62
62
  style: {
63
63
  top: top
@@ -164,6 +164,10 @@ var InputBox = function InputBox() {
164
164
  if (/^=[a-zA-Z]+$/.test(inputRef.current.innerText)) {
165
165
  var ht = "<span dir=\"auto\" class=\"luckysheet-formula-text-color\">=</span><span dir=\"auto\" class=\"luckysheet-formula-text-func\">".concat(formulaName, "</span><span dir=\"auto\" class=\"luckysheet-formula-text-lpar\">(</span>");
166
166
  inputRef.current.innerHTML = ht;
167
+ var fxEditor = document.getElementById("luckysheet-functionbox-cell");
168
+ if (fxEditor) {
169
+ fxEditor.innerHTML = ht;
170
+ }
167
171
  moveCursorToEnd(inputRef.current);
168
172
  setContext(function (draftCtx) {
169
173
  draftCtx.functionCandidates = [];
@@ -342,17 +346,30 @@ var InputBox = function InputBox() {
342
346
  e.preventDefault();
343
347
  }
344
348
  }, [clearSearchItemActiveClass, context.luckysheetCellUpdate.length, selectActiveFormula, setContext, firstSelection]);
345
- var onChange = useCallback(function (__, isBlur) {
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
+ var handleHideShowHint = function handleHideShowHint() {
350
+ var _a, _b, _c, _d;
351
+ var searchElFx = (_a = document.getElementsByClassName("fx-search")) === null || _a === void 0 ? void 0 : _a[0];
352
+ var searchElCell = (_b = document.getElementsByClassName("cell-search")) === null || _b === void 0 ? void 0 : _b[0];
353
+ if (searchElFx) {
354
+ searchElFx.style.display = "none";
355
+ }
356
+ if (searchElCell) {
357
+ searchElCell.style.display = "block";
358
+ }
359
+ var el = (_c = document.getElementsByClassName("fx-hint")) === null || _c === void 0 ? void 0 : _c[0];
360
+ var elCell = (_d = document.getElementsByClassName("cell-hint")) === null || _d === void 0 ? void 0 : _d[0];
349
361
  if (el) {
350
362
  el.style.display = "none";
351
363
  }
352
364
  if (elCell) {
353
365
  elCell.style.display = "block";
354
366
  }
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())) {
367
+ };
368
+ var onChange = useCallback(function (__, isBlur) {
369
+ var _a;
370
+ if (context.isFlvReadOnly) return;
371
+ handleHideShowHint();
372
+ if (((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
356
373
  setShowSearchHint(true);
357
374
  } else {
358
375
  setShowSearchHint(false);
@@ -503,15 +520,7 @@ var InputBox = function InputBox() {
503
520
  }, inputBoxStyle) : {}
504
521
  }, /*#__PURE__*/React.createElement(ContentEditable, {
505
522
  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
- }
523
+ handleHideShowHint();
515
524
  var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
516
525
  setCommaCount(currentCommaCount);
517
526
  },
@@ -90,6 +90,26 @@ var FxEditor = function FxEditor() {
90
90
  });
91
91
  }
92
92
  }, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, refs.globalCache, setContext]);
93
+ var getActiveFormula = (0, _react.useCallback)(function () {
94
+ return document.querySelector(".luckysheet-formula-search-item-active");
95
+ }, []);
96
+ var insertSelectedFormula = (0, _react.useCallback)(function (formulaName) {
97
+ if (/^=[a-zA-Z]+$/.test(refs.fxInput.current.innerText)) {
98
+ var ht = "<span dir=\"auto\" class=\"luckysheet-formula-text-color\">=</span><span dir=\"auto\" class=\"luckysheet-formula-text-func\">".concat(formulaName, "</span><span dir=\"auto\" class=\"luckysheet-formula-text-lpar\">(</span>");
99
+ refs.fxInput.current.innerHTML = ht;
100
+ var cellEditor = document.getElementById("luckysheet-rich-text-editor");
101
+ if (cellEditor) {
102
+ cellEditor.innerHTML = ht;
103
+ }
104
+ (0, _helper.moveCursorToEnd)(refs.fxInput.current);
105
+ setContext(function (draftCtx) {
106
+ draftCtx.functionCandidates = [];
107
+ draftCtx.defaultCandidates = [];
108
+ draftCtx.functionHint = formulaName;
109
+ });
110
+ return;
111
+ }
112
+ }, [setContext]);
93
113
  var onKeyDown = (0, _react.useCallback)(function (e) {
94
114
  var _a;
95
115
  if (context.allowEdit === false) {
@@ -103,6 +123,54 @@ var FxEditor = function FxEditor() {
103
123
  if (key === "ArrowLeft" || key === "ArrowRight") {
104
124
  e.stopPropagation();
105
125
  }
126
+ if (e.key === "Enter" && context.luckysheetCellUpdate.length > 0) {
127
+ if (e.altKey || e.metaKey) {
128
+ document.execCommand("insertHTML", false, "\n ");
129
+ document.execCommand("delete", false);
130
+ e.stopPropagation();
131
+ } else {
132
+ var event_1 = e;
133
+ selectActiveFormulaOnClick(event_1);
134
+ }
135
+ return;
136
+ }
137
+ if (e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0) {
138
+ if (document.getElementById("luckysheet-formula-search-c")) {
139
+ var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
140
+ var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
141
+ var previousItem = activeItem ? activeItem.previousElementSibling : null;
142
+ while (previousItem && !previousItem.classList.contains("luckysheet-formula-search-item")) {
143
+ previousItem = previousItem.previousElementSibling;
144
+ }
145
+ if (!previousItem) {
146
+ var items = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelectorAll(".luckysheet-formula-search-item");
147
+ var lastItem = items === null || items === void 0 ? void 0 : items[items.length - 1];
148
+ previousItem = lastItem || null;
149
+ }
150
+ clearSearchItemActiveClass();
151
+ if (previousItem) {
152
+ previousItem.classList.add("luckysheet-formula-search-item-active");
153
+ }
154
+ }
155
+ e.preventDefault();
156
+ } else if (e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0) {
157
+ if (document.getElementById("luckysheet-formula-search-c")) {
158
+ var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
159
+ var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
160
+ var nextItem = activeItem ? activeItem.nextElementSibling : null;
161
+ while (nextItem && !nextItem.classList.contains("luckysheet-formula-search-item")) {
162
+ nextItem = nextItem.nextElementSibling;
163
+ }
164
+ if (!nextItem) {
165
+ nextItem = (formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item")) || null;
166
+ }
167
+ clearSearchItemActiveClass();
168
+ if (nextItem) {
169
+ nextItem.classList.add("luckysheet-formula-search-item-active");
170
+ }
171
+ }
172
+ e.preventDefault();
173
+ }
106
174
  setContext(function (draftCtx) {
107
175
  if (context.luckysheetCellUpdate.length > 0) {
108
176
  switch (key) {
@@ -153,23 +221,35 @@ var FxEditor = function FxEditor() {
153
221
  var lastSpan = spans[spans.length - 1];
154
222
  return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
155
223
  };
156
- var onChange = (0, _react.useCallback)(function () {
157
- var _a, _b, _c, _d, _e;
158
- if (context.isFlvReadOnly) return;
224
+ var handleHideShowHint = function handleHideShowHint() {
225
+ var _a, _b, _c, _d;
159
226
  var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
160
227
  var fxHint = (_b = document.getElementsByClassName("fx-hint")) === null || _b === void 0 ? void 0 : _b[0];
228
+ var searchElFx = (_c = document.getElementsByClassName("fx-search")) === null || _c === void 0 ? void 0 : _c[0];
229
+ var searchElCell = (_d = document.getElementsByClassName("cell-search")) === null || _d === void 0 ? void 0 : _d[0];
230
+ if (searchElFx) {
231
+ searchElFx.style.display = "block";
232
+ }
233
+ if (searchElCell) {
234
+ searchElCell.style.display = "none";
235
+ }
161
236
  if (el) {
162
237
  el.style.display = "none";
163
238
  }
164
239
  if (fxHint) {
165
240
  fxHint.style.display = "block";
166
241
  }
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())) {
242
+ };
243
+ var onChange = (0, _react.useCallback)(function () {
244
+ var _a, _b, _c;
245
+ if (context.isFlvReadOnly) return;
246
+ handleHideShowHint();
247
+ if (((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
168
248
  setShowSearchHint(true);
169
249
  } else {
170
250
  setShowSearchHint(false);
171
251
  }
172
- var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_e = refs.fxInput) === null || _e === void 0 ? void 0 : _e.current);
252
+ var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current);
173
253
  setCommaCount(currentCommaCount);
174
254
  var e = lastKeyDownEventRef.current;
175
255
  if (!e) return;
@@ -193,6 +273,24 @@ var FxEditor = function FxEditor() {
193
273
  }
194
274
  return true;
195
275
  }, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, isHidenRC]);
276
+ var selectActiveFormulaOnClick = (0, _react.useCallback)(function (e) {
277
+ var _a, _b, _c;
278
+ if (e.target.className.includes("sign-fortune")) return;
279
+ recentText.current = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current.innerText;
280
+ var formulaName = (_c = (_b = getActiveFormula()) === null || _b === void 0 ? void 0 : _b.querySelector(".luckysheet-formula-search-func")) === null || _c === void 0 ? void 0 : _c.textContent;
281
+ var lastSpanText = getLastInputSpanText();
282
+ if (formulaName && !(0, _helper.isLetterNumberPattern)(lastSpanText)) {
283
+ insertSelectedFormula(formulaName);
284
+ e.preventDefault();
285
+ e.stopPropagation();
286
+ }
287
+ }, [getActiveFormula, insertSelectedFormula]);
288
+ var clearSearchItemActiveClass = (0, _react.useCallback)(function () {
289
+ var activeFormula = getActiveFormula();
290
+ if (activeFormula) {
291
+ activeFormula.classList.remove("luckysheet-formula-search-item-active");
292
+ }
293
+ }, [getActiveFormula]);
196
294
  return /*#__PURE__*/_react.default.createElement("div", {
197
295
  className: "fortune-fx-editor"
198
296
  }, /*#__PURE__*/_react.default.createElement(_NameBox.default, null), /*#__PURE__*/_react.default.createElement("div", {
@@ -211,16 +309,9 @@ var FxEditor = function FxEditor() {
211
309
  className: "fortune-fx-input-container"
212
310
  }, /*#__PURE__*/_react.default.createElement(_ContentEditable.default, {
213
311
  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);
312
+ var _a;
313
+ handleHideShowHint();
314
+ var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
224
315
  setCommaCount(currentCommaCount);
225
316
  },
226
317
  innerRef: function innerRef(e) {
@@ -235,13 +326,18 @@ var FxEditor = function FxEditor() {
235
326
  tabIndex: 0,
236
327
  allowEdit: allowEdit && !context.isFlvReadOnly
237
328
  }), showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaSearch.default, {
329
+ from: "fx",
238
330
  onMouseMove: function onMouseMove(e) {
239
331
  if (document.getElementById("luckysheet-formula-search-c")) {
240
332
  var hoveredItem = e.target.closest(".luckysheet-formula-search-item");
241
333
  if (!hoveredItem) return;
334
+ clearSearchItemActiveClass();
242
335
  hoveredItem.classList.add("luckysheet-formula-search-item-active");
243
336
  }
244
337
  e.preventDefault();
338
+ },
339
+ onMouseDown: function onMouseDown(e) {
340
+ selectActiveFormulaOnClick(e);
245
341
  }
246
342
  })), /*#__PURE__*/_react.default.createElement("div", {
247
343
  className: "fx-hint"
@@ -66,7 +66,7 @@ var FormulaSearch = function FormulaSearch(props) {
66
66
  });
67
67
  if (_lodash.default.isEmpty(context.functionCandidates) && _lodash.default.isEmpty(context.defaultCandidates)) return null;
68
68
  return /*#__PURE__*/_react.default.createElement("div", {
69
- className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll",
69
+ className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll ".concat((props === null || props === void 0 ? void 0 : props.from) === "fx" ? "fx-search" : "cell-search"),
70
70
  id: "luckysheet-formula-search-c-p",
71
71
  style: {
72
72
  top: top
@@ -173,6 +173,10 @@ var InputBox = function InputBox() {
173
173
  if (/^=[a-zA-Z]+$/.test(inputRef.current.innerText)) {
174
174
  var ht = "<span dir=\"auto\" class=\"luckysheet-formula-text-color\">=</span><span dir=\"auto\" class=\"luckysheet-formula-text-func\">".concat(formulaName, "</span><span dir=\"auto\" class=\"luckysheet-formula-text-lpar\">(</span>");
175
175
  inputRef.current.innerHTML = ht;
176
+ var fxEditor = document.getElementById("luckysheet-functionbox-cell");
177
+ if (fxEditor) {
178
+ fxEditor.innerHTML = ht;
179
+ }
176
180
  (0, _helper.moveCursorToEnd)(inputRef.current);
177
181
  setContext(function (draftCtx) {
178
182
  draftCtx.functionCandidates = [];
@@ -351,17 +355,30 @@ var InputBox = function InputBox() {
351
355
  e.preventDefault();
352
356
  }
353
357
  }, [clearSearchItemActiveClass, context.luckysheetCellUpdate.length, selectActiveFormula, setContext, firstSelection]);
354
- var onChange = (0, _react.useCallback)(function (__, isBlur) {
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
+ var handleHideShowHint = function handleHideShowHint() {
359
+ var _a, _b, _c, _d;
360
+ var searchElFx = (_a = document.getElementsByClassName("fx-search")) === null || _a === void 0 ? void 0 : _a[0];
361
+ var searchElCell = (_b = document.getElementsByClassName("cell-search")) === null || _b === void 0 ? void 0 : _b[0];
362
+ if (searchElFx) {
363
+ searchElFx.style.display = "none";
364
+ }
365
+ if (searchElCell) {
366
+ searchElCell.style.display = "block";
367
+ }
368
+ var el = (_c = document.getElementsByClassName("fx-hint")) === null || _c === void 0 ? void 0 : _c[0];
369
+ var elCell = (_d = document.getElementsByClassName("cell-hint")) === null || _d === void 0 ? void 0 : _d[0];
358
370
  if (el) {
359
371
  el.style.display = "none";
360
372
  }
361
373
  if (elCell) {
362
374
  elCell.style.display = "block";
363
375
  }
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())) {
376
+ };
377
+ var onChange = (0, _react.useCallback)(function (__, isBlur) {
378
+ var _a;
379
+ if (context.isFlvReadOnly) return;
380
+ handleHideShowHint();
381
+ if (((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
365
382
  setShowSearchHint(true);
366
383
  } else {
367
384
  setShowSearchHint(false);
@@ -512,15 +529,7 @@ var InputBox = function InputBox() {
512
529
  }, inputBoxStyle) : {}
513
530
  }, /*#__PURE__*/_react.default.createElement(_ContentEditable.default, {
514
531
  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
- }
532
+ handleHideShowHint();
524
533
  var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
525
534
  setCommaCount(currentCommaCount);
526
535
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.2.25",
3
+ "version": "1.2.27",
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.25",
19
+ "@fileverse-dev/fortune-core": "1.2.27",
20
20
  "@fileverse/ui": "^4.1.7-patch-40",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",