@fileverse-dev/fortune-react 1.2.81 → 1.2.83

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.
@@ -342,11 +342,9 @@ var ConditionRules = function ConditionRules(_a) {
342
342
  var _a;
343
343
  setEditConditionFormatKey(key);
344
344
  setContext(function (ctx) {
345
- var _a, _b, _c, _d;
345
+ var _a, _b;
346
346
  var index = getSheetIndex(ctx, ctx.currentSheetId);
347
- console.log("why set editkey", (_b = (_a = ctx.luckysheetfile[index]) === null || _a === void 0 ? void 0 : _a.conditionRules) === null || _b === void 0 ? void 0 : _b.editKey);
348
- if (((_d = (_c = ctx.luckysheetfile[index]) === null || _c === void 0 ? void 0 : _c.conditionRules) === null || _d === void 0 ? void 0 : _d.editKey) === undefined) {
349
- console.log("set editkey");
347
+ if (((_b = (_a = ctx.luckysheetfile[index]) === null || _a === void 0 ? void 0 : _a.conditionRules) === null || _b === void 0 ? void 0 : _b.editKey) === undefined) {
350
348
  ctx.luckysheetfile[index].conditionRules.editKey = key;
351
349
  }
352
350
  });
@@ -22,7 +22,7 @@ var ErrorBoxes = function ErrorBoxes() {
22
22
  zIndex: 100,
23
23
  borderRadius: "4px"
24
24
  },
25
- className: "shadow-lg flex flex-col gap-2"
25
+ className: "shadow-lg flex flex-col gap-2 break-all"
26
26
  }, /*#__PURE__*/React.createElement("h3", {
27
27
  className: "text-heading-xsm color-text-danger"
28
28
  }, title), /*#__PURE__*/React.createElement("div", {
@@ -11,26 +11,26 @@ import usePrevious from "../../hooks/usePrevious";
11
11
  import { LucideIcon } from "../../components/SheetOverlay/LucideIcon";
12
12
  import { countCommasBeforeCursor, isLetterNumberPattern, moveCursorToEnd } from "../../components/SheetOverlay/helper";
13
13
  var FxEditor = function FxEditor() {
14
- var _a, _b, _c;
14
+ var _a;
15
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
+ var _b = useState(false),
17
+ showSearchHint = _b[0],
18
+ setShowSearchHint = _b[1];
19
+ var _c = useState(!hideFormulaHintLocal),
20
+ showFormulaHint = _c[0],
21
+ setShowFormulaHint = _c[1];
22
+ var _d = useState(0),
23
+ commaCount = _d[0],
24
+ setCommaCount = _d[1];
25
+ var _e = useContext(WorkbookContext),
26
+ context = _e.context,
27
+ setContext = _e.setContext,
28
+ refs = _e.refs;
29
29
  var lastKeyDownEventRef = useRef(null);
30
30
  var inputContainerRef = useRef(null);
31
- var _h = useState(false),
32
- isHidenRC = _h[0],
33
- setIsHidenRC = _h[1];
31
+ var _f = useState(false),
32
+ isHidenRC = _f[0],
33
+ setIsHidenRC = _f[1];
34
34
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
35
35
  var prevFirstSelection = usePrevious(firstSelection);
36
36
  var prevSheetId = usePrevious(context.currentSheetId);
@@ -267,6 +267,24 @@ var FxEditor = function FxEditor() {
267
267
  });
268
268
  }
269
269
  }, [refs.cellInput, refs.fxInput, setContext]);
270
+ var getFunctionNameFromInput = useCallback(function () {
271
+ var _a, _b, _c, _d;
272
+ var inputText = ((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText) || "";
273
+ if (!inputText.startsWith("=")) return null;
274
+ var functionMatch = inputText.match(/^=([A-Za-z_][A-Za-z0-9_]*)\s*\(/);
275
+ if (functionMatch) {
276
+ return functionMatch[1].toUpperCase();
277
+ }
278
+ if ((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current) {
279
+ var funcSpan = refs.fxInput.current.querySelector(".luckysheet-formula-text-func");
280
+ if (funcSpan) {
281
+ return ((_d = funcSpan.textContent) === null || _d === void 0 ? void 0 : _d.toUpperCase()) || null;
282
+ }
283
+ }
284
+ return null;
285
+ }, []);
286
+ var functionName = context.functionHint || getFunctionNameFromInput();
287
+ var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
270
288
  var allowEdit = useMemo(function () {
271
289
  if (context.allowEdit === false) {
272
290
  return false;
@@ -280,9 +298,9 @@ var FxEditor = function FxEditor() {
280
298
  return true;
281
299
  }, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, isHidenRC]);
282
300
  var divRef = useRef(null);
283
- var _j = useState(false),
284
- isResizing = _j[0],
285
- setIsResizing = _j[1];
301
+ var _g = useState(false),
302
+ isResizing = _g[0],
303
+ setIsResizing = _g[1];
286
304
  var startResize = function startResize(e) {
287
305
  e.preventDefault();
288
306
  setIsResizing(true);
@@ -358,11 +376,12 @@ var FxEditor = function FxEditor() {
358
376
  }
359
377
  })), /*#__PURE__*/React.createElement("div", {
360
378
  className: "fx-hint"
361
- }, 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, {
379
+ }, showFormulaHint && fn && (/*#__PURE__*/React.createElement(FormulaHint, {
362
380
  handleShowFormulaHint: handleShowFormulaHint,
363
381
  showFormulaHint: showFormulaHint,
364
- commaCount: commaCount
365
- })), context.functionHint && !showFormulaHint && (/*#__PURE__*/React.createElement("div", {
382
+ commaCount: commaCount,
383
+ functionName: functionName
384
+ })), !showFormulaHint && fn && (/*#__PURE__*/React.createElement("div", {
366
385
  className: "luckysheet-hin absolute show-more-btn",
367
386
  onClick: function onClick() {
368
387
  handleShowFormulaHint();
@@ -18,12 +18,13 @@ var FormulaHint = function FormulaHint(props) {
18
18
  var _a;
19
19
  var showFormulaHint = props.showFormulaHint,
20
20
  handleShowFormulaHint = props.handleShowFormulaHint,
21
- commaCount = props.commaCount;
21
+ commaCount = props.commaCount,
22
+ functionName = props.functionName;
22
23
  var dragHasMoved = useRef(false);
23
24
  var context = useContext(WorkbookContext).context;
24
25
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
25
26
  var formulaMore = locale(context).formulaMore;
26
- var fn = context.formulaCache.functionlistMap[context.functionHint];
27
+ var fn = functionName ? context.formulaCache.functionlistMap[functionName] : context.formulaCache.functionlistMap[(context === null || context === void 0 ? void 0 : context.functionHint) || ""];
27
28
  var _b = useState(localStorage.getItem(fn === null || fn === void 0 ? void 0 : fn.API_KEY)),
28
29
  API_KEY = _b[0],
29
30
  setAPI_KEY = _b[1];
@@ -20,47 +20,47 @@ import usePrevious from "../../hooks/usePrevious";
20
20
  import { moveCursorToEnd, getCursorPosition, isLetterNumberPattern, removeLastSpan, incrementColumn, decrementColumn, incrementRow, decrementRow, countCommasBeforeCursor } from "./helper";
21
21
  import { LucideIcon } from "./LucideIcon";
22
22
  var InputBox = function InputBox() {
23
- var _a, _b, _c, _d, _e, _f, _g, _h;
24
- var _j = useContext(WorkbookContext),
25
- context = _j.context,
26
- setContext = _j.setContext,
27
- refs = _j.refs;
23
+ var _a, _b, _c, _d, _e, _f, _g;
24
+ var _h = useContext(WorkbookContext),
25
+ context = _h.context,
26
+ setContext = _h.setContext,
27
+ refs = _h.refs;
28
28
  var inputRef = useRef(null);
29
29
  var lastKeyDownEventRef = useRef(null);
30
30
  var prevCellUpdate = usePrevious(context.luckysheetCellUpdate);
31
31
  var prevSheetId = usePrevious(context.currentSheetId);
32
+ var _j = useState(false),
33
+ isHidenRC = _j[0],
34
+ setIsHidenRC = _j[1];
32
35
  var _k = useState(false),
33
- isHidenRC = _k[0],
34
- setIsHidenRC = _k[1];
35
- var _l = useState(false),
36
- isInputBoxActive = _l[0],
37
- setIsInputBoxActive = _l[1];
36
+ isInputBoxActive = _k[0],
37
+ setIsInputBoxActive = _k[1];
38
+ var _l = useState(""),
39
+ activeCell = _l[0],
40
+ setActiveCell = _l[1];
38
41
  var _m = useState(""),
39
- activeCell = _m[0],
40
- setActiveCell = _m[1];
41
- var _o = useState(""),
42
- activeRefCell = _o[0],
43
- setActiveRefCell = _o[1];
44
- var _p = useState({
42
+ activeRefCell = _m[0],
43
+ setActiveRefCell = _m[1];
44
+ var _o = useState({
45
45
  left: 0,
46
46
  top: 0
47
47
  }),
48
- frozenPosition = _p[0],
49
- setFrozenPosition = _p[1];
48
+ frozenPosition = _o[0],
49
+ setFrozenPosition = _o[1];
50
50
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
51
- var _q = useState({}),
52
- firstSelectionActiveCell = _q[0],
53
- setFirstSelectionActiveCell = _q[1];
54
- var _r = useState(0),
55
- commaCount = _r[0],
56
- setCommaCount = _r[1];
51
+ var _p = useState({}),
52
+ firstSelectionActiveCell = _p[0],
53
+ setFirstSelectionActiveCell = _p[1];
54
+ var _q = useState(0),
55
+ commaCount = _q[0],
56
+ setCommaCount = _q[1];
57
57
  var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
58
- var _s = useState(!hideFormulaHintLocal),
59
- showFormulaHint = _s[0],
60
- setShowFormulaHint = _s[1];
61
- var _t = useState(false),
62
- showSearchHint = _t[0],
63
- setShowSearchHint = _t[1];
58
+ var _r = useState(!hideFormulaHintLocal),
59
+ showFormulaHint = _r[0],
60
+ setShowFormulaHint = _r[1];
61
+ var _s = useState(false),
62
+ showSearchHint = _s[0],
63
+ setShowSearchHint = _s[1];
64
64
  var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
65
65
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
66
66
  var preText = useRef("");
@@ -517,7 +517,24 @@ var InputBox = function InputBox() {
517
517
  }
518
518
  return activeCell || cell;
519
519
  };
520
- var fn = context.formulaCache.functionlistMap[context.functionHint];
520
+ var getFunctionNameFromInput = useCallback(function () {
521
+ var _a, _b;
522
+ var inputText = ((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) || "";
523
+ if (!inputText.startsWith("=")) return null;
524
+ var functionMatch = inputText.match(/^=([A-Za-z_][A-Za-z0-9_]*)\s*\(/);
525
+ if (functionMatch) {
526
+ return functionMatch[1].toUpperCase();
527
+ }
528
+ if (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) {
529
+ var funcSpan = inputRef.current.querySelector(".luckysheet-formula-text-func");
530
+ if (funcSpan) {
531
+ return ((_b = funcSpan.textContent) === null || _b === void 0 ? void 0 : _b.toUpperCase()) || null;
532
+ }
533
+ }
534
+ return null;
535
+ }, []);
536
+ var functionName = context.functionHint || getFunctionNameFromInput();
537
+ var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
521
538
  return /*#__PURE__*/React.createElement("div", {
522
539
  className: "luckysheet-input-box",
523
540
  id: "luckysheet-input-box",
@@ -561,7 +578,7 @@ var InputBox = function InputBox() {
561
578
  onKeyDown: onKeyDown,
562
579
  onPaste: onPaste,
563
580
  allowEdit: edit ? !isHidenRC : edit
564
- })), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0) && (/*#__PURE__*/React.createElement(React.Fragment, null, showSearchHint && (/*#__PURE__*/React.createElement(FormulaSearch, {
581
+ })), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0 || fn) && (/*#__PURE__*/React.createElement(React.Fragment, null, showSearchHint && (/*#__PURE__*/React.createElement(FormulaSearch, {
565
582
  onMouseMove: function onMouseMove(e) {
566
583
  if (document.getElementById("luckysheet-formula-search-c")) {
567
584
  var hoveredItem = e.target.closest(".luckysheet-formula-search-item");
@@ -576,10 +593,11 @@ var InputBox = function InputBox() {
576
593
  }
577
594
  })), /*#__PURE__*/React.createElement("div", {
578
595
  className: "cell-hint"
579
- }, 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, {
596
+ }, showFormulaHint && fn && (/*#__PURE__*/React.createElement(FormulaHint, {
580
597
  handleShowFormulaHint: handleShowFormulaHint,
581
598
  showFormulaHint: showFormulaHint,
582
- commaCount: commaCount
599
+ commaCount: commaCount,
600
+ functionName: functionName
583
601
  })), !showFormulaHint && fn && (/*#__PURE__*/React.createElement(Tooltip, {
584
602
  text: "Turn on formula suggestions (F10)",
585
603
  placement: "top",
@@ -351,11 +351,9 @@ var ConditionRules = function ConditionRules(_a) {
351
351
  var _a;
352
352
  setEditConditionFormatKey(key);
353
353
  setContext(function (ctx) {
354
- var _a, _b, _c, _d;
354
+ var _a, _b;
355
355
  var index = (0, _fortuneCore.getSheetIndex)(ctx, ctx.currentSheetId);
356
- console.log("why set editkey", (_b = (_a = ctx.luckysheetfile[index]) === null || _a === void 0 ? void 0 : _a.conditionRules) === null || _b === void 0 ? void 0 : _b.editKey);
357
- if (((_d = (_c = ctx.luckysheetfile[index]) === null || _c === void 0 ? void 0 : _c.conditionRules) === null || _d === void 0 ? void 0 : _d.editKey) === undefined) {
358
- console.log("set editkey");
356
+ if (((_b = (_a = ctx.luckysheetfile[index]) === null || _a === void 0 ? void 0 : _a.conditionRules) === null || _b === void 0 ? void 0 : _b.editKey) === undefined) {
359
357
  ctx.luckysheetfile[index].conditionRules.editKey = key;
360
358
  }
361
359
  });
@@ -31,7 +31,7 @@ var ErrorBoxes = function ErrorBoxes() {
31
31
  zIndex: 100,
32
32
  borderRadius: "4px"
33
33
  },
34
- className: "shadow-lg flex flex-col gap-2"
34
+ className: "shadow-lg flex flex-col gap-2 break-all"
35
35
  }, /*#__PURE__*/_react.default.createElement("h3", {
36
36
  className: "text-heading-xsm color-text-danger"
37
37
  }, title), /*#__PURE__*/_react.default.createElement("div", {
@@ -20,26 +20,26 @@ var _helper = require("../../components/SheetOverlay/helper");
20
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
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); }
22
22
  var FxEditor = function FxEditor() {
23
- var _a, _b, _c;
23
+ var _a;
24
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
+ var _b = (0, _react.useState)(false),
26
+ showSearchHint = _b[0],
27
+ setShowSearchHint = _b[1];
28
+ var _c = (0, _react.useState)(!hideFormulaHintLocal),
29
+ showFormulaHint = _c[0],
30
+ setShowFormulaHint = _c[1];
31
+ var _d = (0, _react.useState)(0),
32
+ commaCount = _d[0],
33
+ setCommaCount = _d[1];
34
+ var _e = (0, _react.useContext)(_context.default),
35
+ context = _e.context,
36
+ setContext = _e.setContext,
37
+ refs = _e.refs;
38
38
  var lastKeyDownEventRef = (0, _react.useRef)(null);
39
39
  var inputContainerRef = (0, _react.useRef)(null);
40
- var _h = (0, _react.useState)(false),
41
- isHidenRC = _h[0],
42
- setIsHidenRC = _h[1];
40
+ var _f = (0, _react.useState)(false),
41
+ isHidenRC = _f[0],
42
+ setIsHidenRC = _f[1];
43
43
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
44
44
  var prevFirstSelection = (0, _usePrevious.default)(firstSelection);
45
45
  var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
@@ -276,6 +276,24 @@ var FxEditor = function FxEditor() {
276
276
  });
277
277
  }
278
278
  }, [refs.cellInput, refs.fxInput, setContext]);
279
+ var getFunctionNameFromInput = (0, _react.useCallback)(function () {
280
+ var _a, _b, _c, _d;
281
+ var inputText = ((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText) || "";
282
+ if (!inputText.startsWith("=")) return null;
283
+ var functionMatch = inputText.match(/^=([A-Za-z_][A-Za-z0-9_]*)\s*\(/);
284
+ if (functionMatch) {
285
+ return functionMatch[1].toUpperCase();
286
+ }
287
+ if ((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current) {
288
+ var funcSpan = refs.fxInput.current.querySelector(".luckysheet-formula-text-func");
289
+ if (funcSpan) {
290
+ return ((_d = funcSpan.textContent) === null || _d === void 0 ? void 0 : _d.toUpperCase()) || null;
291
+ }
292
+ }
293
+ return null;
294
+ }, []);
295
+ var functionName = context.functionHint || getFunctionNameFromInput();
296
+ var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
279
297
  var allowEdit = (0, _react.useMemo)(function () {
280
298
  if (context.allowEdit === false) {
281
299
  return false;
@@ -289,9 +307,9 @@ var FxEditor = function FxEditor() {
289
307
  return true;
290
308
  }, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, isHidenRC]);
291
309
  var divRef = (0, _react.useRef)(null);
292
- var _j = (0, _react.useState)(false),
293
- isResizing = _j[0],
294
- setIsResizing = _j[1];
310
+ var _g = (0, _react.useState)(false),
311
+ isResizing = _g[0],
312
+ setIsResizing = _g[1];
295
313
  var startResize = function startResize(e) {
296
314
  e.preventDefault();
297
315
  setIsResizing(true);
@@ -367,11 +385,12 @@ var FxEditor = function FxEditor() {
367
385
  }
368
386
  })), /*#__PURE__*/_react.default.createElement("div", {
369
387
  className: "fx-hint"
370
- }, 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, {
388
+ }, showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
371
389
  handleShowFormulaHint: handleShowFormulaHint,
372
390
  showFormulaHint: showFormulaHint,
373
- commaCount: commaCount
374
- })), context.functionHint && !showFormulaHint && (/*#__PURE__*/_react.default.createElement("div", {
391
+ commaCount: commaCount,
392
+ functionName: functionName
393
+ })), !showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement("div", {
375
394
  className: "luckysheet-hin absolute show-more-btn",
376
395
  onClick: function onClick() {
377
396
  handleShowFormulaHint();
@@ -27,12 +27,13 @@ var FormulaHint = function FormulaHint(props) {
27
27
  var _a;
28
28
  var showFormulaHint = props.showFormulaHint,
29
29
  handleShowFormulaHint = props.handleShowFormulaHint,
30
- commaCount = props.commaCount;
30
+ commaCount = props.commaCount,
31
+ functionName = props.functionName;
31
32
  var dragHasMoved = (0, _react.useRef)(false);
32
33
  var context = (0, _react.useContext)(_context.default).context;
33
34
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
34
35
  var formulaMore = (0, _fortuneCore.locale)(context).formulaMore;
35
- var fn = context.formulaCache.functionlistMap[context.functionHint];
36
+ var fn = functionName ? context.formulaCache.functionlistMap[functionName] : context.formulaCache.functionlistMap[(context === null || context === void 0 ? void 0 : context.functionHint) || ""];
36
37
  var _b = (0, _react.useState)(localStorage.getItem(fn === null || fn === void 0 ? void 0 : fn.API_KEY)),
37
38
  API_KEY = _b[0],
38
39
  setAPI_KEY = _b[1];
@@ -17,7 +17,7 @@ var _usePrevious = _interopRequireDefault(require("../../hooks/usePrevious"));
17
17
  var _helper = require("./helper");
18
18
  var _LucideIcon = require("./LucideIcon");
19
19
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
- 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 _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
20
+ 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); }
21
21
  var __assign = void 0 && (void 0).__assign || function () {
22
22
  __assign = Object.assign || function (t) {
23
23
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -29,47 +29,47 @@ var __assign = void 0 && (void 0).__assign || function () {
29
29
  return __assign.apply(this, arguments);
30
30
  };
31
31
  var InputBox = function InputBox() {
32
- var _a, _b, _c, _d, _e, _f, _g, _h;
33
- var _j = (0, _react.useContext)(_context.default),
34
- context = _j.context,
35
- setContext = _j.setContext,
36
- refs = _j.refs;
32
+ var _a, _b, _c, _d, _e, _f, _g;
33
+ var _h = (0, _react.useContext)(_context.default),
34
+ context = _h.context,
35
+ setContext = _h.setContext,
36
+ refs = _h.refs;
37
37
  var inputRef = (0, _react.useRef)(null);
38
38
  var lastKeyDownEventRef = (0, _react.useRef)(null);
39
39
  var prevCellUpdate = (0, _usePrevious.default)(context.luckysheetCellUpdate);
40
40
  var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
41
+ var _j = (0, _react.useState)(false),
42
+ isHidenRC = _j[0],
43
+ setIsHidenRC = _j[1];
41
44
  var _k = (0, _react.useState)(false),
42
- isHidenRC = _k[0],
43
- setIsHidenRC = _k[1];
44
- var _l = (0, _react.useState)(false),
45
- isInputBoxActive = _l[0],
46
- setIsInputBoxActive = _l[1];
45
+ isInputBoxActive = _k[0],
46
+ setIsInputBoxActive = _k[1];
47
+ var _l = (0, _react.useState)(""),
48
+ activeCell = _l[0],
49
+ setActiveCell = _l[1];
47
50
  var _m = (0, _react.useState)(""),
48
- activeCell = _m[0],
49
- setActiveCell = _m[1];
50
- var _o = (0, _react.useState)(""),
51
- activeRefCell = _o[0],
52
- setActiveRefCell = _o[1];
53
- var _p = (0, _react.useState)({
51
+ activeRefCell = _m[0],
52
+ setActiveRefCell = _m[1];
53
+ var _o = (0, _react.useState)({
54
54
  left: 0,
55
55
  top: 0
56
56
  }),
57
- frozenPosition = _p[0],
58
- setFrozenPosition = _p[1];
57
+ frozenPosition = _o[0],
58
+ setFrozenPosition = _o[1];
59
59
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
60
- var _q = (0, _react.useState)({}),
61
- firstSelectionActiveCell = _q[0],
62
- setFirstSelectionActiveCell = _q[1];
63
- var _r = (0, _react.useState)(0),
64
- commaCount = _r[0],
65
- setCommaCount = _r[1];
60
+ var _p = (0, _react.useState)({}),
61
+ firstSelectionActiveCell = _p[0],
62
+ setFirstSelectionActiveCell = _p[1];
63
+ var _q = (0, _react.useState)(0),
64
+ commaCount = _q[0],
65
+ setCommaCount = _q[1];
66
66
  var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
67
- var _s = (0, _react.useState)(!hideFormulaHintLocal),
68
- showFormulaHint = _s[0],
69
- setShowFormulaHint = _s[1];
70
- var _t = (0, _react.useState)(false),
71
- showSearchHint = _t[0],
72
- setShowSearchHint = _t[1];
67
+ var _r = (0, _react.useState)(!hideFormulaHintLocal),
68
+ showFormulaHint = _r[0],
69
+ setShowFormulaHint = _r[1];
70
+ var _s = (0, _react.useState)(false),
71
+ showSearchHint = _s[0],
72
+ setShowSearchHint = _s[1];
73
73
  var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
74
74
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
75
75
  var preText = (0, _react.useRef)("");
@@ -526,7 +526,24 @@ var InputBox = function InputBox() {
526
526
  }
527
527
  return activeCell || cell;
528
528
  };
529
- var fn = context.formulaCache.functionlistMap[context.functionHint];
529
+ var getFunctionNameFromInput = (0, _react.useCallback)(function () {
530
+ var _a, _b;
531
+ var inputText = ((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) || "";
532
+ if (!inputText.startsWith("=")) return null;
533
+ var functionMatch = inputText.match(/^=([A-Za-z_][A-Za-z0-9_]*)\s*\(/);
534
+ if (functionMatch) {
535
+ return functionMatch[1].toUpperCase();
536
+ }
537
+ if (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) {
538
+ var funcSpan = inputRef.current.querySelector(".luckysheet-formula-text-func");
539
+ if (funcSpan) {
540
+ return ((_b = funcSpan.textContent) === null || _b === void 0 ? void 0 : _b.toUpperCase()) || null;
541
+ }
542
+ }
543
+ return null;
544
+ }, []);
545
+ var functionName = context.functionHint || getFunctionNameFromInput();
546
+ var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
530
547
  return /*#__PURE__*/_react.default.createElement("div", {
531
548
  className: "luckysheet-input-box",
532
549
  id: "luckysheet-input-box",
@@ -570,7 +587,7 @@ var InputBox = function InputBox() {
570
587
  onKeyDown: onKeyDown,
571
588
  onPaste: onPaste,
572
589
  allowEdit: edit ? !isHidenRC : edit
573
- })), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0) && (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaSearch.default, {
590
+ })), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0 || fn) && (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, showSearchHint && (/*#__PURE__*/_react.default.createElement(_FormulaSearch.default, {
574
591
  onMouseMove: function onMouseMove(e) {
575
592
  if (document.getElementById("luckysheet-formula-search-c")) {
576
593
  var hoveredItem = e.target.closest(".luckysheet-formula-search-item");
@@ -585,10 +602,11 @@ var InputBox = function InputBox() {
585
602
  }
586
603
  })), /*#__PURE__*/_react.default.createElement("div", {
587
604
  className: "cell-hint"
588
- }, 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, {
605
+ }, showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_FormulaHint.default, {
589
606
  handleShowFormulaHint: handleShowFormulaHint,
590
607
  showFormulaHint: showFormulaHint,
591
- commaCount: commaCount
608
+ commaCount: commaCount,
609
+ functionName: functionName
592
610
  })), !showFormulaHint && fn && (/*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
593
611
  text: "Turn on formula suggestions (F10)",
594
612
  placement: "top",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.2.81",
3
+ "version": "1.2.83",
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.81",
19
+ "@fileverse-dev/fortune-core": "1.2.83",
20
20
  "@fileverse/ui": "^4.1.7-patch-40",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",