@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
@@ -10,7 +10,7 @@ var __assign = this && this.__assign || function () {
10
10
  };
11
11
  import { locale } from "@fileverse-dev/fortune-core";
12
12
  import { Button, TextField, LucideIcon, Tooltip } from "@fileverse/ui";
13
- import React, { useContext, useEffect, useRef, useState } from "react";
13
+ import React, { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
14
14
  import WorkbookContext from "../../../context";
15
15
  import "./index.css";
16
16
  import { DraggableDiv } from "./dragable-div";
@@ -49,29 +49,49 @@ var FormulaHint = function FormulaHint(props) {
49
49
  ETHERSCAN_API_KEY: "Etherscan API key"
50
50
  };
51
51
  var hintRef = useRef(null);
52
- var _h = useState(0),
52
+ var cellHeightPx = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) != null ? Number(firstSelection.height_move) : 24;
53
+ var belowCellTop = cellHeightPx + 4;
54
+ var _h = useState(belowCellTop),
53
55
  top = _h[0],
54
56
  setTop = _h[1];
55
57
  var _j = useState(false),
56
58
  showDelayedHint = _j[0],
57
59
  setShowDelayedHint = _j[1];
58
- var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
59
- var _a, _b, _c, _d, _e, _f;
60
- 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;
61
- var hintHeight = 360;
62
- var inputBoxTop = parseInt(((_c = document.getElementById("luckysheet-input-box")) === null || _c === void 0 ? void 0 : _c.style.top) || "0", 10) - 85;
63
- var inputBottom = inputBoxTop + firstSelection.height_move;
64
- var availableBelow = window.innerHeight - inputBottom;
65
- var hintAbove = hintHeight > availableBelow;
66
- var selectionHeight = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) || 0;
67
- var divOffset = ((_d = hintRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 0;
68
- var topV = hintAbove ? selectionHeight - (divOffset + 30) : selectionHeight + 4;
69
- var el = (_e = document.getElementsByClassName("fx-hint")) === null || _e === void 0 ? void 0 : _e[0];
70
- if (el && ((_f = el === null || el === void 0 ? void 0 : el.style) === null || _f === void 0 ? void 0 : _f.display) !== "none") {
60
+ var measureFormulaHintPlacement = useCallback(function () {
61
+ var _a;
62
+ if ((firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) == null || firstSelection.height_move == null) {
63
+ setTop(belowCellTop);
64
+ return;
65
+ }
66
+ var cellH = Number(firstSelection.height_move) || cellHeightPx;
67
+ var innerEl = hintRef.current;
68
+ var popupHeight = Math.min((innerEl === null || innerEl === void 0 ? void 0 : innerEl.offsetHeight) || 360, 360);
69
+ var inputBox = document.getElementById("luckysheet-input-box");
70
+ var rect = inputBox === null || inputBox === void 0 ? void 0 : inputBox.getBoundingClientRect();
71
+ if (!rect) {
72
+ setTop(cellH + 4);
73
+ return;
74
+ }
75
+ var cellBottomViewport = rect.top + cellH;
76
+ var availableBelow = window.innerHeight - cellBottomViewport - 12;
77
+ var preferBelow = popupHeight <= availableBelow;
78
+ var topV = preferBelow ? cellH + 4 : -(popupHeight + 8);
79
+ var fxHint = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
80
+ if (fxHint && fxHint.style.display !== "none") {
71
81
  topV = 25;
72
82
  }
73
83
  setTop(topV);
74
- };
84
+ }, [belowCellTop, cellHeightPx, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top]);
85
+ useLayoutEffect(function () {
86
+ if (!fn) {
87
+ return undefined;
88
+ }
89
+ measureFormulaHintPlacement();
90
+ var id = requestAnimationFrame(measureFormulaHintPlacement);
91
+ return function () {
92
+ cancelAnimationFrame(id);
93
+ };
94
+ }, [functionName, context.functionHint, measureFormulaHintPlacement, showFormulaHint, commaCount, showFunctionBody]);
75
95
  var hexToRgbString = function hexToRgbString(hex) {
76
96
  hex = hex.replace("#", "");
77
97
  var r = parseInt(hex.substring(0, 2), 16);
@@ -84,14 +104,13 @@ var FormulaHint = function FormulaHint(props) {
84
104
  return bg;
85
105
  };
86
106
  useEffect(function () {
87
- calcuatePopUpPlacement();
88
- }, []);
89
- useEffect(function () {
90
- if (!top) {
91
- setTimeout(function () {
92
- setShowDelayedHint(true);
93
- }, 40);
94
- }
107
+ setShowDelayedHint(false);
108
+ var t = setTimeout(function () {
109
+ return setShowDelayedHint(true);
110
+ }, 40);
111
+ return function () {
112
+ return clearTimeout(t);
113
+ };
95
114
  }, [top]);
96
115
  if (!fn) return null;
97
116
  var fnNameClass = fn.n ? String(fn.n).replace(/[^a-zA-Z0-9-]/g, "-").replace(/-+/g, "-") : "";
@@ -174,7 +193,7 @@ var FormulaHint = function FormulaHint(props) {
174
193
  localStorage.setItem("formula-expand", "".concat(!showFunctionBody));
175
194
  setShouldShowFunctionBody(!showFunctionBody);
176
195
  setTimeout(function () {
177
- calcuatePopUpPlacement();
196
+ measureFormulaHintPlacement();
178
197
  }, 50);
179
198
  }
180
199
  dragHasMoved.current = false;
@@ -277,6 +296,7 @@ var FormulaHint = function FormulaHint(props) {
277
296
  cursor: "auto"
278
297
  }
279
298
  }, fn.API_KEY && (/*#__PURE__*/React.createElement("div", {
299
+ className: "luckysheet-formula-help-content-api",
280
300
  style: {
281
301
  borderLeft: "4px solid ".concat(isKeyAdded ? "#177E23" : "#fb923c"),
282
302
  backgroundColor: "white",
@@ -340,6 +360,7 @@ var FormulaHint = function FormulaHint(props) {
340
360
  className: "fortune-formula-hint__cta min-w-[80px]",
341
361
  "data-testid": "formula-hint-cta-ok"
342
362
  }, "Ok"))))))), /*#__PURE__*/React.createElement("div", {
363
+ id: "luckysheet-formula-help-content-example",
343
364
  style: {
344
365
  backgroundColor: "white",
345
366
  padding: "6px",
@@ -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;
@@ -8,17 +8,27 @@ var __assign = this && this.__assign || function () {
8
8
  };
9
9
  return __assign.apply(this, arguments);
10
10
  };
11
+ var __rest = this && this.__rest || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
15
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
16
+ }
17
+ return t;
18
+ };
11
19
  import _ from "lodash";
12
- import React, { useContext, useEffect, useRef, useState } from "react";
20
+ import React, { useCallback, useContext, useLayoutEffect, useRef, useState } from "react";
13
21
  import { LucideIcon, Tooltip } from "@fileverse/ui";
14
22
  import { UNFilter } from "./constant";
15
23
  import WorkbookContext from "../../../context";
16
24
  import "./index.css";
17
- var FormulaSearch = function FormulaSearch(props) {
18
- var _a;
19
- var _b = useContext(WorkbookContext),
20
- context = _b.context,
21
- isAuthorized = _b.settings.isAuthorized;
25
+ var FormulaSearch = function FormulaSearch(_a) {
26
+ var _b, _c, _d;
27
+ var from = _a.from,
28
+ divProps = __rest(_a, ["from"]);
29
+ var _e = useContext(WorkbookContext),
30
+ context = _e.context,
31
+ isAuthorized = _e.settings.isAuthorized;
22
32
  var authedFunction = ["COINGECKO", "ETHERSCAN", "DEFILLAMA", "GNOSIS", "BASE", "EOA", "PNL", "SAFE", "BLOCKSCOUT", "LENS", "FARCASTER", "Ethereum", "SMARTCONTRACT", "DUNESIM"];
23
33
  var filteredDefaultCandidates = context.defaultCandidates.filter(function (item) {
24
34
  return !authedFunction.includes(item.n);
@@ -30,39 +40,58 @@ var FormulaSearch = function FormulaSearch(props) {
30
40
  var finalFunctionCandidates = isAuthorized ? context.functionCandidates : context.functionCandidates.filter(function (item) {
31
41
  return item.t !== 20;
32
42
  });
33
- var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
43
+ var firstSelection = (_b = context.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b[0];
44
+ var cellHeightPx = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) != null ? Number(firstSelection.height_move) : 24;
45
+ var belowCellTop = cellHeightPx + 4;
34
46
  var hintRef = useRef(null);
35
- var _c = useState(0),
36
- top = _c[0],
37
- setTop = _c[1];
38
- var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
39
- var _a, _b, _c, _d, _e, _f;
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
- var hintHeight = 360;
42
- var inputBoxTop = parseInt(((_c = document.getElementById("luckysheet-input-box")) === null || _c === void 0 ? void 0 : _c.style.top) || "0", 10) - 85;
43
- var inputBottom = inputBoxTop + firstSelection.height_move;
44
- var availableBelow = window.innerHeight - inputBottom;
45
- var hintAbove = hintHeight > availableBelow;
46
- var selectionHeight = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) || 0;
47
- var divOffset = ((_d = hintRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 0;
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") {
47
+ var _f = useState(belowCellTop),
48
+ top = _f[0],
49
+ setTop = _f[1];
50
+ var applyPlacement = useCallback(function () {
51
+ var _a;
52
+ if ((firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) == null || firstSelection.height_move == null) {
53
+ setTop(belowCellTop);
54
+ return;
55
+ }
56
+ var fromFx = from === "fx";
57
+ var cellH = Number(firstSelection.height_move) || cellHeightPx;
58
+ if (fromFx) {
59
+ setTop(25);
60
+ return;
61
+ }
62
+ var innerEl = hintRef.current;
63
+ var popupHeight = Math.min((innerEl === null || innerEl === void 0 ? void 0 : innerEl.offsetHeight) || 360, 360);
64
+ var inputBox = document.getElementById("luckysheet-input-box");
65
+ var rect = inputBox === null || inputBox === void 0 ? void 0 : inputBox.getBoundingClientRect();
66
+ if (!rect) {
67
+ setTop(cellH + 4);
68
+ return;
69
+ }
70
+ var cellBottomViewport = rect.top + cellH;
71
+ var availableBelow = window.innerHeight - cellBottomViewport - 12;
72
+ var preferBelow = popupHeight <= availableBelow;
73
+ var topV = preferBelow ? cellH + 4 : -(popupHeight + 8);
74
+ var fxHint = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
75
+ if (fxHint && fxHint.style.display !== "none") {
51
76
  topV = 25;
52
77
  }
53
78
  setTop(topV);
54
- };
55
- useEffect(function () {
56
- calcuatePopUpPlacement();
57
- });
79
+ }, [belowCellTop, cellHeightPx, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top, from]);
80
+ useLayoutEffect(function () {
81
+ applyPlacement();
82
+ var id = requestAnimationFrame(applyPlacement);
83
+ return function () {
84
+ cancelAnimationFrame(id);
85
+ };
86
+ }, [applyPlacement, (_c = context.defaultCandidates) === null || _c === void 0 ? void 0 : _c.length, (_d = context.functionCandidates) === null || _d === void 0 ? void 0 : _d.length, context.functionHint]);
58
87
  if (_.isEmpty(context.functionCandidates) && _.isEmpty(context.defaultCandidates)) return null;
59
88
  return /*#__PURE__*/React.createElement("div", {
60
- className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll ".concat((props === null || props === void 0 ? void 0 : props.from) === "fx" ? "fx-search" : "cell-search"),
89
+ className: "flex color-border-default border flex-col luckysheet-formula-search-c-p custom-scroll ".concat(from === "fx" ? "fx-search" : "cell-search"),
61
90
  id: "luckysheet-formula-search-c-p",
62
91
  style: {
63
92
  top: top
64
93
  }
65
- }, /*#__PURE__*/React.createElement("div", __assign({}, props, {
94
+ }, /*#__PURE__*/React.createElement("div", __assign({}, divProps, {
66
95
  ref: hintRef,
67
96
  id: "luckysheet-formula-search-c",
68
97
  className: "luckysheet-formula-search-c"