@fileverse-dev/fortune-react 1.3.12-mixed-a → 1.3.13-create-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/es/components/ContextMenu/index.js +1 -1
  2. package/es/components/FxEditor/index.js +316 -60
  3. package/es/components/SheetOverlay/FormulaHint/index.js +46 -25
  4. package/es/components/SheetOverlay/FormulaSearch/index.d.ts +3 -1
  5. package/es/components/SheetOverlay/FormulaSearch/index.js +58 -29
  6. package/es/components/SheetOverlay/InputBox.js +406 -194
  7. package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +34 -48
  8. package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +31 -41
  9. package/es/components/SheetOverlay/formula-segment-boundary.d.ts +1 -0
  10. package/es/components/SheetOverlay/formula-segment-boundary.js +4 -0
  11. package/es/components/SheetOverlay/helper.d.ts +7 -0
  12. package/es/components/SheetOverlay/helper.js +95 -0
  13. package/es/components/SheetOverlay/index.css +6 -45
  14. package/es/components/SheetOverlay/index.js +26 -14
  15. package/es/components/Workbook/index.js +5 -8
  16. package/es/hooks/useFormulaEditorHistory.d.ts +24 -0
  17. package/es/hooks/useFormulaEditorHistory.js +119 -0
  18. package/es/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
  19. package/es/hooks/useRerenderOnFormulaCaret.js +28 -0
  20. package/lib/components/ContextMenu/index.js +1 -1
  21. package/lib/components/FxEditor/index.js +314 -58
  22. package/lib/components/SheetOverlay/FormulaHint/index.js +45 -24
  23. package/lib/components/SheetOverlay/FormulaSearch/index.d.ts +3 -1
  24. package/lib/components/SheetOverlay/FormulaSearch/index.js +57 -28
  25. package/lib/components/SheetOverlay/InputBox.js +404 -192
  26. package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +33 -47
  27. package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +31 -41
  28. package/lib/components/SheetOverlay/formula-segment-boundary.d.ts +1 -0
  29. package/lib/components/SheetOverlay/formula-segment-boundary.js +10 -0
  30. package/lib/components/SheetOverlay/helper.d.ts +7 -0
  31. package/lib/components/SheetOverlay/helper.js +99 -0
  32. package/lib/components/SheetOverlay/index.css +6 -45
  33. package/lib/components/SheetOverlay/index.js +25 -13
  34. package/lib/components/Workbook/index.js +5 -8
  35. package/lib/hooks/useFormulaEditorHistory.d.ts +24 -0
  36. package/lib/hooks/useFormulaEditorHistory.js +126 -0
  37. package/lib/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
  38. package/lib/hooks/useRerenderOnFormulaCaret.js +34 -0
  39. package/package.json +2 -2
@@ -1,4 +1,6 @@
1
1
  import React from "react";
2
2
  import "./index.css";
3
- declare const FormulaSearch: React.FC<React.HTMLAttributes<HTMLDivElement>>;
3
+ declare const FormulaSearch: React.FC<React.HTMLAttributes<HTMLDivElement> & {
4
+ from?: string;
5
+ }>;
4
6
  export default FormulaSearch;
@@ -23,11 +23,21 @@ var __assign = void 0 && (void 0).__assign || function () {
23
23
  };
24
24
  return __assign.apply(this, arguments);
25
25
  };
26
- var FormulaSearch = function FormulaSearch(props) {
27
- var _a;
28
- var _b = (0, _react.useContext)(_context.default),
29
- context = _b.context,
30
- isAuthorized = _b.settings.isAuthorized;
26
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
27
+ var t = {};
28
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
30
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
31
+ }
32
+ return t;
33
+ };
34
+ var FormulaSearch = function FormulaSearch(_a) {
35
+ var _b, _c, _d;
36
+ var from = _a.from,
37
+ divProps = __rest(_a, ["from"]);
38
+ var _e = (0, _react.useContext)(_context.default),
39
+ context = _e.context,
40
+ isAuthorized = _e.settings.isAuthorized;
31
41
  var authedFunction = ["COINGECKO", "ETHERSCAN", "DEFILLAMA", "GNOSIS", "BASE", "EOA", "PNL", "SAFE", "BLOCKSCOUT", "LENS", "FARCASTER", "Ethereum", "SMARTCONTRACT", "DUNESIM"];
32
42
  var filteredDefaultCandidates = context.defaultCandidates.filter(function (item) {
33
43
  return !authedFunction.includes(item.n);
@@ -39,39 +49,58 @@ var FormulaSearch = function FormulaSearch(props) {
39
49
  var finalFunctionCandidates = isAuthorized ? context.functionCandidates : context.functionCandidates.filter(function (item) {
40
50
  return item.t !== 20;
41
51
  });
42
- var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
52
+ var firstSelection = (_b = context.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b[0];
53
+ var cellHeightPx = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) != null ? Number(firstSelection.height_move) : 24;
54
+ var belowCellTop = cellHeightPx + 4;
43
55
  var hintRef = (0, _react.useRef)(null);
44
- var _c = (0, _react.useState)(0),
45
- top = _c[0],
46
- setTop = _c[1];
47
- var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
48
- var _a, _b, _c, _d, _e, _f;
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
- var hintHeight = 360;
51
- var inputBoxTop = parseInt(((_c = document.getElementById("luckysheet-input-box")) === null || _c === void 0 ? void 0 : _c.style.top) || "0", 10) - 85;
52
- var inputBottom = inputBoxTop + firstSelection.height_move;
53
- var availableBelow = window.innerHeight - inputBottom;
54
- var hintAbove = hintHeight > availableBelow;
55
- var selectionHeight = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) || 0;
56
- var divOffset = ((_d = hintRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 0;
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") {
56
+ var _f = (0, _react.useState)(belowCellTop),
57
+ top = _f[0],
58
+ setTop = _f[1];
59
+ var applyPlacement = (0, _react.useCallback)(function () {
60
+ var _a;
61
+ if ((firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) == null || firstSelection.height_move == null) {
62
+ setTop(belowCellTop);
63
+ return;
64
+ }
65
+ var fromFx = from === "fx";
66
+ var cellH = Number(firstSelection.height_move) || cellHeightPx;
67
+ if (fromFx) {
68
+ setTop(25);
69
+ return;
70
+ }
71
+ var innerEl = hintRef.current;
72
+ var popupHeight = Math.min((innerEl === null || innerEl === void 0 ? void 0 : innerEl.offsetHeight) || 360, 360);
73
+ var inputBox = document.getElementById("luckysheet-input-box");
74
+ var rect = inputBox === null || inputBox === void 0 ? void 0 : inputBox.getBoundingClientRect();
75
+ if (!rect) {
76
+ setTop(cellH + 4);
77
+ return;
78
+ }
79
+ var cellBottomViewport = rect.top + cellH;
80
+ var availableBelow = window.innerHeight - cellBottomViewport - 12;
81
+ var preferBelow = popupHeight <= availableBelow;
82
+ var topV = preferBelow ? cellH + 4 : -(popupHeight + 8);
83
+ var fxHint = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
84
+ if (fxHint && fxHint.style.display !== "none") {
60
85
  topV = 25;
61
86
  }
62
87
  setTop(topV);
63
- };
64
- (0, _react.useEffect)(function () {
65
- calcuatePopUpPlacement();
66
- });
88
+ }, [belowCellTop, cellHeightPx, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top, from]);
89
+ (0, _react.useLayoutEffect)(function () {
90
+ applyPlacement();
91
+ var id = requestAnimationFrame(applyPlacement);
92
+ return function () {
93
+ cancelAnimationFrame(id);
94
+ };
95
+ }, [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]);
67
96
  if (_lodash.default.isEmpty(context.functionCandidates) && _lodash.default.isEmpty(context.defaultCandidates)) return null;
68
97
  return /*#__PURE__*/_react.default.createElement("div", {
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"),
98
+ className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll ".concat(from === "fx" ? "fx-search" : "cell-search"),
70
99
  id: "luckysheet-formula-search-c-p",
71
100
  style: {
72
101
  top: top
73
102
  }
74
- }, /*#__PURE__*/_react.default.createElement("div", __assign({}, props, {
103
+ }, /*#__PURE__*/_react.default.createElement("div", __assign({}, divProps, {
75
104
  ref: hintRef,
76
105
  id: "luckysheet-formula-search-c",
77
106
  className: "luckysheet-formula-search-c"