@fileverse-dev/fortune-react 1.3.11-input-ref-1 → 1.3.11-input-ref-3

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.
@@ -58,29 +58,49 @@ var FormulaHint = function FormulaHint(props) {
58
58
  ETHERSCAN_API_KEY: "Etherscan API key"
59
59
  };
60
60
  var hintRef = (0, _react.useRef)(null);
61
- var _h = (0, _react.useState)(0),
61
+ var cellHeightPx = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) != null ? Number(firstSelection.height_move) : 24;
62
+ var belowCellTop = cellHeightPx + 4;
63
+ var _h = (0, _react.useState)(belowCellTop),
62
64
  top = _h[0],
63
65
  setTop = _h[1];
64
66
  var _j = (0, _react.useState)(false),
65
67
  showDelayedHint = _j[0],
66
68
  setShowDelayedHint = _j[1];
67
- var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
68
- var _a, _b, _c, _d, _e, _f;
69
- 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;
70
- var hintHeight = 360;
71
- var inputBoxTop = parseInt(((_c = document.getElementById("luckysheet-input-box")) === null || _c === void 0 ? void 0 : _c.style.top) || "0", 10) - 85;
72
- var inputBottom = inputBoxTop + firstSelection.height_move;
73
- var availableBelow = window.innerHeight - inputBottom;
74
- var hintAbove = hintHeight > availableBelow;
75
- var selectionHeight = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) || 0;
76
- var divOffset = ((_d = hintRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 0;
77
- var topV = hintAbove ? selectionHeight - (divOffset + 30) : selectionHeight + 4;
78
- var el = (_e = document.getElementsByClassName("fx-hint")) === null || _e === void 0 ? void 0 : _e[0];
79
- if (el && ((_f = el === null || el === void 0 ? void 0 : el.style) === null || _f === void 0 ? void 0 : _f.display) !== "none") {
69
+ var measureFormulaHintPlacement = (0, _react.useCallback)(function () {
70
+ var _a;
71
+ if ((firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) == null || firstSelection.height_move == null) {
72
+ setTop(belowCellTop);
73
+ return;
74
+ }
75
+ var cellH = Number(firstSelection.height_move) || cellHeightPx;
76
+ var innerEl = hintRef.current;
77
+ var popupHeight = Math.min((innerEl === null || innerEl === void 0 ? void 0 : innerEl.offsetHeight) || 360, 360);
78
+ var inputBox = document.getElementById("luckysheet-input-box");
79
+ var rect = inputBox === null || inputBox === void 0 ? void 0 : inputBox.getBoundingClientRect();
80
+ if (!rect) {
81
+ setTop(cellH + 4);
82
+ return;
83
+ }
84
+ var cellBottomViewport = rect.top + cellH;
85
+ var availableBelow = window.innerHeight - cellBottomViewport - 12;
86
+ var preferBelow = popupHeight <= availableBelow;
87
+ var topV = preferBelow ? cellH + 4 : -(popupHeight + 8);
88
+ var fxHint = (_a = document.getElementsByClassName("fx-hint")) === null || _a === void 0 ? void 0 : _a[0];
89
+ if (fxHint && fxHint.style.display !== "none") {
80
90
  topV = 25;
81
91
  }
82
92
  setTop(topV);
83
- };
93
+ }, [belowCellTop, cellHeightPx, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move, firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top]);
94
+ (0, _react.useLayoutEffect)(function () {
95
+ if (!fn) {
96
+ return undefined;
97
+ }
98
+ measureFormulaHintPlacement();
99
+ var id = requestAnimationFrame(measureFormulaHintPlacement);
100
+ return function () {
101
+ cancelAnimationFrame(id);
102
+ };
103
+ }, [functionName, context.functionHint, measureFormulaHintPlacement, showFormulaHint, commaCount, showFunctionBody]);
84
104
  var hexToRgbString = function hexToRgbString(hex) {
85
105
  hex = hex.replace("#", "");
86
106
  var r = parseInt(hex.substring(0, 2), 16);
@@ -93,14 +113,13 @@ var FormulaHint = function FormulaHint(props) {
93
113
  return bg;
94
114
  };
95
115
  (0, _react.useEffect)(function () {
96
- calcuatePopUpPlacement();
97
- }, []);
98
- (0, _react.useEffect)(function () {
99
- if (!top) {
100
- setTimeout(function () {
101
- setShowDelayedHint(true);
102
- }, 40);
103
- }
116
+ setShowDelayedHint(false);
117
+ var t = setTimeout(function () {
118
+ return setShowDelayedHint(true);
119
+ }, 40);
120
+ return function () {
121
+ return clearTimeout(t);
122
+ };
104
123
  }, [top]);
105
124
  if (!fn) return null;
106
125
  var fnNameClass = fn.n ? String(fn.n).replace(/[^a-zA-Z0-9-]/g, "-").replace(/-+/g, "-") : "";
@@ -183,7 +202,7 @@ var FormulaHint = function FormulaHint(props) {
183
202
  localStorage.setItem("formula-expand", "".concat(!showFunctionBody));
184
203
  setShouldShowFunctionBody(!showFunctionBody);
185
204
  setTimeout(function () {
186
- calcuatePopUpPlacement();
205
+ measureFormulaHintPlacement();
187
206
  }, 50);
188
207
  }
189
208
  dragHasMoved.current = false;
@@ -286,6 +305,7 @@ var FormulaHint = function FormulaHint(props) {
286
305
  cursor: "auto"
287
306
  }
288
307
  }, fn.API_KEY && (/*#__PURE__*/_react.default.createElement("div", {
308
+ className: "luckysheet-formula-help-content-api",
289
309
  style: {
290
310
  borderLeft: "4px solid ".concat(isKeyAdded ? "#177E23" : "#fb923c"),
291
311
  backgroundColor: "white",
@@ -349,6 +369,7 @@ var FormulaHint = function FormulaHint(props) {
349
369
  className: "fortune-formula-hint__cta min-w-[80px]",
350
370
  "data-testid": "formula-hint-cta-ok"
351
371
  }, "Ok"))))))), /*#__PURE__*/_react.default.createElement("div", {
372
+ id: "luckysheet-formula-help-content-example",
352
373
  style: {
353
374
  backgroundColor: "white",
354
375
  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;
@@ -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"
@@ -65,31 +65,34 @@ var InputBox = function InputBox() {
65
65
  var _x = (0, _react.useState)(0),
66
66
  commaCount = _x[0],
67
67
  setCommaCount = _x[1];
68
+ var _y = (0, _react.useState)(false),
69
+ cellEditorIsFormula = _y[0],
70
+ setCellEditorIsFormula = _y[1];
68
71
  var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
69
- var _y = (0, _react.useState)(!hideFormulaHintLocal),
70
- showFormulaHint = _y[0],
71
- setShowFormulaHint = _y[1];
72
- var _z = (0, _react.useState)(false),
73
- showSearchHint = _z[0],
74
- setShowSearchHint = _z[1];
72
+ var _z = (0, _react.useState)(!hideFormulaHintLocal),
73
+ showFormulaHint = _z[0],
74
+ setShowFormulaHint = _z[1];
75
+ var _0 = (0, _react.useState)(false),
76
+ showSearchHint = _0[0],
77
+ setShowSearchHint = _0[1];
75
78
  var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
76
79
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
77
80
  var isComposingRef = (0, _react.useRef)(false);
78
81
  var formulaAnchorCellRef = (0, _react.useRef)(null);
79
82
  var skipNextAnchorSelectionSyncRef = (0, _react.useRef)(false);
80
83
  var lastHandledMouseDragSignatureRef = (0, _react.useRef)("");
81
- var _0 = (0, _useFormulaEditorHistory.useFormulaEditorHistory)(inputRef, refs.cellInput, refs.fxInput, setContext, "cell"),
82
- formulaHistoryRef = _0.formulaHistoryRef,
83
- preTextRef = _0.preTextRef,
84
- resetFormulaHistory = _0.resetFormulaHistory,
85
- handleFormulaHistoryUndoRedo = _0.handleFormulaHistoryUndoRedo,
86
- capturePreFormulaState = _0.capturePreFormulaState,
87
- appendFormulaHistoryFromPrimaryEditor = _0.appendFormulaHistoryFromPrimaryEditor;
84
+ var _1 = (0, _useFormulaEditorHistory.useFormulaEditorHistory)(inputRef, refs.cellInput, refs.fxInput, setContext, "cell"),
85
+ formulaHistoryRef = _1.formulaHistoryRef,
86
+ preTextRef = _1.preTextRef,
87
+ resetFormulaHistory = _1.resetFormulaHistory,
88
+ handleFormulaHistoryUndoRedo = _1.handleFormulaHistoryUndoRedo,
89
+ capturePreFormulaState = _1.capturePreFormulaState,
90
+ appendFormulaHistoryFromPrimaryEditor = _1.appendFormulaHistoryFromPrimaryEditor;
88
91
  var ZWSP = "\u200B";
89
92
  var inputBoxInnerRef = (0, _react.useRef)(null);
90
- var _1 = (0, _react.useState)([]),
91
- linkSelectionHighlightRects = _1[0],
92
- setLinkSelectionHighlightRects = _1[1];
93
+ var _2 = (0, _react.useState)([]),
94
+ linkSelectionHighlightRects = _2[0],
95
+ setLinkSelectionHighlightRects = _2[1];
93
96
  var ensureNotEmpty = function ensureNotEmpty() {
94
97
  var el = inputRef.current;
95
98
  if (!el) return;
@@ -112,12 +115,11 @@ var InputBox = function InputBox() {
112
115
  return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
113
116
  };
114
117
  var inputBoxStyle = (0, _react.useMemo)(function () {
115
- var _a;
116
118
  if (firstSelectionActiveCell && context.luckysheetCellUpdate.length > 0) {
117
119
  var flowdata = (0, _fortuneCore.getFlowdata)(context);
118
120
  if (!flowdata) return {};
119
121
  var style = (0, _fortuneCore.getStyleByCell)(context, flowdata, firstSelectionActiveCell.row_focus, firstSelectionActiveCell.column_focus);
120
- if (((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText.charAt(0)) === "=") {
122
+ if (cellEditorIsFormula) {
121
123
  style = __assign(__assign({}, style), {
122
124
  textAlign: "left"
123
125
  });
@@ -125,7 +127,7 @@ var InputBox = function InputBox() {
125
127
  return style;
126
128
  }
127
129
  return {};
128
- }, [context.luckysheetfile, context.currentSheetId, context.luckysheetCellUpdate, (_b = context === null || context === void 0 ? void 0 : context.luckysheetCellUpdate) === null || _b === void 0 ? void 0 : _b.length, firstSelectionActiveCell]);
130
+ }, [context.luckysheetfile, context.currentSheetId, context.luckysheetCellUpdate, (_b = context === null || context === void 0 ? void 0 : context.luckysheetCellUpdate) === null || _b === void 0 ? void 0 : _b.length, firstSelectionActiveCell, cellEditorIsFormula]);
129
131
  (0, _react.useLayoutEffect)(function () {
130
132
  var _a;
131
133
  if (!context.allowEdit) {
@@ -145,10 +147,23 @@ var InputBox = function InputBox() {
145
147
  if (_lodash.default.isEqual(prevCellUpdate, context.luckysheetCellUpdate) && prevSheetId === context.currentSheetId) {
146
148
  return;
147
149
  }
150
+ var _b = context.luckysheetCellUpdate,
151
+ ur = _b[0],
152
+ uc = _b[1];
153
+ var pending_1 = refs.globalCache.pendingTypeOverCell;
154
+ if (pending_1 && pending_1[0] === ur && pending_1[1] === uc) {
155
+ refs.globalCache.overwriteCell = false;
156
+ if (inputRef.current) {
157
+ setCellEditorIsFormula(inputRef.current.innerText.trim().startsWith("="));
158
+ }
159
+ delete refs.globalCache.doNotFocus;
160
+ return;
161
+ }
148
162
  var flowdata = (0, _fortuneCore.getFlowdata)(context);
149
163
  var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index]) === null || _a === void 0 ? void 0 : _a[col_index];
164
+ var overwrite = refs.globalCache.overwriteCell;
150
165
  var value_1 = "";
151
- if (cell && !refs.globalCache.overwriteCell) {
166
+ if (cell && !overwrite) {
152
167
  if ((0, _fortuneCore.isInlineStringCell)(cell)) {
153
168
  value_1 = (0, _fortuneCore.getInlineStringHTML)(row_index, col_index, flowdata);
154
169
  } else if (cell.f) {
@@ -164,14 +179,20 @@ var InputBox = function InputBox() {
164
179
  }
165
180
  }
166
181
  refs.globalCache.overwriteCell = false;
182
+ var wroteEditorFromStoredCell = false;
167
183
  if (!refs.globalCache.ignoreWriteCell && inputRef.current && value_1) {
168
184
  inputRef.current.innerHTML = (0, _fortuneCore.escapeHTMLTag)((0, _fortuneCore.escapeScriptTag)(value_1));
169
- } else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1) {
185
+ wroteEditorFromStoredCell = true;
186
+ } else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1 && !overwrite) {
170
187
  var valueD = (0, _fortuneCore.getCellValue)(row_index, col_index, flowdata, "f");
171
188
  inputRef.current.innerText = valueD;
189
+ wroteEditorFromStoredCell = true;
172
190
  }
173
191
  refs.globalCache.ignoreWriteCell = false;
174
- if (!refs.globalCache.doNotFocus) {
192
+ if (inputRef.current) {
193
+ setCellEditorIsFormula(inputRef.current.innerText.trim().startsWith("="));
194
+ }
195
+ if (wroteEditorFromStoredCell && !refs.globalCache.doNotFocus) {
175
196
  setTimeout(function () {
176
197
  (0, _fortuneCore.moveToEnd)(inputRef.current);
177
198
  });
@@ -184,9 +205,15 @@ var InputBox = function InputBox() {
184
205
  if (inputRef.current) {
185
206
  inputRef.current.innerHTML = "";
186
207
  }
208
+ delete refs.globalCache.pendingTypeOverCell;
209
+ setCellEditorIsFormula(false);
187
210
  resetFormulaHistory();
188
211
  }
189
- }, [context.luckysheetCellUpdate, resetFormulaHistory]);
212
+ }, [context.luckysheetCellUpdate, resetFormulaHistory, refs.globalCache]);
213
+ (0, _react.useEffect)(function () {
214
+ if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) return;
215
+ delete refs.globalCache.pendingTypeOverCell;
216
+ }, [context.luckysheetCellUpdate, refs.globalCache]);
190
217
  (0, _react.useEffect)(function () {
191
218
  var _a;
192
219
  if (_lodash.default.isEmpty(context.luckysheetCellUpdate) || !refs.cellInput.current) {
@@ -382,7 +409,7 @@ var InputBox = function InputBox() {
382
409
  });
383
410
  }, [formulaMouseDragSignature, context.formulaCache.func_selectedrange, refs.cellInput, setContext]);
384
411
  var onKeyDown = (0, _react.useCallback)(function (e) {
385
- var _a, _b;
412
+ var _a, _b, _c;
386
413
  setContext(function (draftCtx) {
387
414
  (0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "cell");
388
415
  });
@@ -404,9 +431,9 @@ var InputBox = function InputBox() {
404
431
  setContext(function (draftCtx) {
405
432
  draftCtx.formulaCache.rangeSelectionActive = null;
406
433
  });
407
- var _c = formulaAnchorCellRef.current,
408
- anchorRow_1 = _c[0],
409
- anchorCol_1 = _c[1];
434
+ var _d = formulaAnchorCellRef.current,
435
+ anchorRow_1 = _d[0],
436
+ anchorCol_1 = _d[1];
410
437
  skipNextAnchorSelectionSyncRef.current = true;
411
438
  setTimeout(function () {
412
439
  setContext(function (draftCtx) {
@@ -462,6 +489,7 @@ var InputBox = function InputBox() {
462
489
  }
463
490
  var allowListNavigation = true;
464
491
  var isArrowKey = e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight";
492
+ var isInPlaceEditMode = ((_c = refs.globalCache) === null || _c === void 0 ? void 0 : _c.enteredEditByTyping) !== true;
465
493
  if (e.key === "Delete" || e.key === "Backspace") {
466
494
  var anchor = formulaAnchorCellRef.current;
467
495
  if (anchor != null) {
@@ -477,6 +505,12 @@ var InputBox = function InputBox() {
477
505
  row_focus: anchorRow_2,
478
506
  column_focus: anchorCol_2
479
507
  }];
508
+ (0, _fortuneCore.markRangeSelectionDirty)(draftCtx);
509
+ var el = refs.cellInput.current;
510
+ if (el && el.innerText.trim().startsWith("=")) {
511
+ (0, _fortuneCore.createRangeHightlight)(draftCtx, el.innerHTML);
512
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, el);
513
+ }
480
514
  });
481
515
  }, 0);
482
516
  }
@@ -507,7 +541,7 @@ var InputBox = function InputBox() {
507
541
  e.preventDefault();
508
542
  } else if (e.key === "F4" && context.luckysheetCellUpdate.length > 0) {
509
543
  e.preventDefault();
510
- } else if (e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
544
+ } else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0 && allowListNavigation && !(e.shiftKey && isInPlaceEditMode)) {
511
545
  if (document.getElementById("luckysheet-formula-search-c")) {
512
546
  var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
513
547
  var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
@@ -526,7 +560,7 @@ var InputBox = function InputBox() {
526
560
  }
527
561
  }
528
562
  e.preventDefault();
529
- } else if (e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
563
+ } else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0 && allowListNavigation && !(e.shiftKey && isInPlaceEditMode)) {
530
564
  if (document.getElementById("luckysheet-formula-search-c")) {
531
565
  var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
532
566
  var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
@@ -544,7 +578,7 @@ var InputBox = function InputBox() {
544
578
  }
545
579
  e.preventDefault();
546
580
  }
547
- }, [capturePreFormulaState, clearSearchItemActiveClass, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, selectActiveFormula, setContext, firstSelection]);
581
+ }, [capturePreFormulaState, clearSearchItemActiveClass, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, selectActiveFormula, setContext, firstSelection, refs.cellInput]);
548
582
  var handleHideShowHint = function handleHideShowHint() {
549
583
  var _a, _b, _c, _d;
550
584
  var searchElFx = (_a = document.getElementsByClassName("fx-search")) === null || _a === void 0 ? void 0 : _a[0];
@@ -565,10 +599,12 @@ var InputBox = function InputBox() {
565
599
  }
566
600
  };
567
601
  var onChange = (0, _react.useCallback)(function (__, isBlur) {
568
- var _a, _b, _c;
602
+ var _a, _b, _c, _d, _e, _f;
569
603
  if (context.isFlvReadOnly) return;
570
604
  handleHideShowHint();
571
- setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) !== null && _a !== void 0 ? _a : null));
605
+ var editorText = (_c = (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : "";
606
+ setCellEditorIsFormula(editorText.startsWith("="));
607
+ setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)((_d = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) !== null && _d !== void 0 ? _d : null));
572
608
  if (!isComposingRef.current) {
573
609
  var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
574
610
  setCommaCount(currentCommaCount);
@@ -576,7 +612,7 @@ var InputBox = function InputBox() {
576
612
  var e = lastKeyDownEventRef.current;
577
613
  if (!e) {
578
614
  var cellEl_1 = refs.cellInput.current;
579
- if (cellEl_1 && (((_b = cellEl_1.innerText) === null || _b === void 0 ? void 0 : _b.trim().startsWith("=")) || ((_c = cellEl_1.textContent) === null || _c === void 0 ? void 0 : _c.trim().startsWith("=")))) {
615
+ if (cellEl_1 && (((_e = cellEl_1.innerText) === null || _e === void 0 ? void 0 : _e.trim().startsWith("=")) || ((_f = cellEl_1.textContent) === null || _f === void 0 ? void 0 : _f.trim().startsWith("=")))) {
580
616
  setContext(function (draftCtx) {
581
617
  if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) return;
582
618
  (0, _fortuneCore.rangeHightlightselected)(draftCtx, cellEl_1);
@@ -591,11 +627,16 @@ var InputBox = function InputBox() {
591
627
  });
592
628
  if (!(kcode >= 112 && kcode <= 123 || kcode <= 46 || kcode === 144 || kcode === 108 || e.ctrlKey || e.altKey || e.shiftKey && (kcode === 37 || kcode === 38 || kcode === 39 || kcode === 40)) || kcode === 8 || kcode === 32 || kcode === 46 || e.ctrlKey && kcode === 86) {
593
629
  setContext(function (draftCtx) {
630
+ var _a, _b;
594
631
  if ((draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start || (0, _fortuneCore.israngeseleciton)(draftCtx)) && isBlur) return;
595
632
  if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) {
596
633
  return;
597
634
  }
598
635
  (0, _fortuneCore.handleFormulaInput)(draftCtx, refs.fxInput.current, refs.cellInput.current, kcode, preTextRef.current);
636
+ var cellEl = refs.cellInput.current;
637
+ if (cellEl && (((_a = cellEl.innerText) === null || _a === void 0 ? void 0 : _a.trim().startsWith("=")) || ((_b = cellEl.textContent) === null || _b === void 0 ? void 0 : _b.trim().startsWith("=")))) {
638
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, cellEl);
639
+ }
599
640
  });
600
641
  }
601
642
  }, [refs.cellInput, refs.fxInput, setContext, appendFormulaHistoryFromPrimaryEditor]);
@@ -336,9 +336,9 @@
336
336
  overflow: hidden;
337
337
  white-space: pre-wrap;
338
338
  outline: none;
339
- -webkit-box-shadow: 0 2px 5px rgb(0 0 0 / 40%);
340
- -moz-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
341
- box-shadow: 0 2px 5px rgb(0 0 0 / 40%);
339
+ /* -webkit-box-shadow: 0 2px 5px rgb(0 0 0 / 40%);
340
+ -moz-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); */
341
+ /* box-shadow: 0 2px 5px rgb(0 0 0 / 40%); */
342
342
  word-wrap: break-word;
343
343
  background-color: rgb(255, 255, 255);
344
344
  font-size: 13px;
@@ -801,44 +801,11 @@
801
801
  }
802
802
 
803
803
  .fortune-formula-functionrange-highlight .fortune-selection-copy-hc {
804
- border: 2px solid #5e5e5e;
805
- opacity: 0.03;
804
+ border-width: 2px;
805
+ border-style: dotted;
806
806
  z-index: initial;
807
807
  }
808
808
 
809
- .fortune-selection-highlight-lt {
810
- left: -3px;
811
- top: -3px;
812
- cursor: se-resize;
813
- }
814
-
815
- .fortune-selection-highlight-rt {
816
- right: -3px;
817
- top: -3px;
818
- cursor: ne-resize;
819
- }
820
-
821
- .fortune-selection-highlight-lb {
822
- left: -3px;
823
- bottom: -3px;
824
- cursor: ne-resize;
825
- }
826
-
827
- .fortune-selection-highlight-rb {
828
- right: -3px;
829
- bottom: -3px;
830
- cursor: se-resize;
831
- }
832
-
833
- .fortune-formula-functionrange-highlight .luckysheet-highlight {
834
- position: absolute;
835
- z-index: 19;
836
- border: 1px solid #fff;
837
- background: #0188fb;
838
- width: 6px;
839
- height: 6px;
840
- }
841
-
842
809
  .fortune-presence-username {
843
810
  position: absolute;
844
811
  padding-left: 6px;
@@ -37,6 +37,22 @@ var __assign = void 0 && (void 0).__assign || function () {
37
37
  };
38
38
  return __assign.apply(this, arguments);
39
39
  };
40
+ function formulaRangeHighlightHcStyle(hex) {
41
+ var h = hex.replace("#", "");
42
+ if (h.length !== 6) {
43
+ return {
44
+ backgroundColor: hex,
45
+ borderColor: hex
46
+ };
47
+ }
48
+ var r = parseInt(h.slice(0, 2), 16);
49
+ var g = parseInt(h.slice(2, 4), 16);
50
+ var b = parseInt(h.slice(4, 6), 16);
51
+ return {
52
+ backgroundColor: "rgba(".concat(r, ",").concat(g, ",").concat(b, ",0.08)"),
53
+ borderColor: hex
54
+ };
55
+ }
40
56
  var SheetOverlay = function SheetOverlay() {
41
57
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
42
58
  var _o = (0, _react.useContext)(_context.default),
@@ -58,6 +74,7 @@ var SheetOverlay = function SheetOverlay() {
58
74
  setContext(function (draftCtx) {
59
75
  var _a;
60
76
  (0, _fortuneCore.handleCellAreaMouseDown)(draftCtx, refs.globalCache, nativeEvent, refs.cellInput.current, refs.cellArea.current, refs.fxInput.current, refs.canvas.current.getContext("2d"));
77
+ var keepFormulaBarFocused = draftCtx.luckysheetCellUpdate.length > 0 && draftCtx.formulaCache.formulaEditorOwner === "fx" && (draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start || (0, _fortuneCore.israngeseleciton)(draftCtx));
61
78
  if (!_lodash.default.isEmpty((_a = draftCtx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) && refs.cellInput.current) {
62
79
  if (!(0, _fortuneCore.isAllowEdit)(draftCtx)) {
63
80
  setTimeout(function () {
@@ -69,7 +86,13 @@ var SheetOverlay = function SheetOverlay() {
69
86
  } else {
70
87
  setTimeout(function () {
71
88
  var _a;
72
- (_a = refs.cellInput.current) === null || _a === void 0 ? void 0 : _a.focus();
89
+ if (keepFormulaBarFocused && refs.fxInput.current) {
90
+ refs.fxInput.current.focus({
91
+ preventScroll: true
92
+ });
93
+ } else {
94
+ (_a = refs.cellInput.current) === null || _a === void 0 ? void 0 : _a.focus();
95
+ }
73
96
  });
74
97
  }
75
98
  }
@@ -299,18 +322,7 @@ var SheetOverlay = function SheetOverlay() {
299
322
  });
300
323
  }), /*#__PURE__*/_react.default.createElement("div", {
301
324
  className: "fortune-selection-copy-hc",
302
- style: {
303
- backgroundColor: backgroundColor
304
- }
305
- }), ["lt", "rt", "lb", "rb"].map(function (d) {
306
- return /*#__PURE__*/_react.default.createElement("div", {
307
- key: d,
308
- "data-type": d,
309
- className: "fortune-selection-highlight-".concat(d, " luckysheet-highlight"),
310
- style: {
311
- backgroundColor: backgroundColor
312
- }
313
- });
325
+ style: formulaRangeHighlightHcStyle(backgroundColor)
314
326
  }));
315
327
  }), /*#__PURE__*/_react.default.createElement("div", {
316
328
  className: "luckysheet-row-count-show luckysheet-count-show",
@@ -9,7 +9,9 @@ function useRerenderOnFormulaCaret(editorRef, editSessionActive) {
9
9
  var _a = (0, _react.useState)(0),
10
10
  bump = _a[1];
11
11
  (0, _react.useEffect)(function () {
12
- if (!editSessionActive) return;
12
+ if (!editSessionActive) {
13
+ return function () {};
14
+ }
13
15
  var onSelectionChange = function onSelectionChange() {
14
16
  var _a, _b;
15
17
  var el = editorRef.current;
@@ -26,7 +28,7 @@ function useRerenderOnFormulaCaret(editorRef, editSessionActive) {
26
28
  };
27
29
  document.addEventListener("selectionchange", onSelectionChange);
28
30
  return function () {
29
- return document.removeEventListener("selectionchange", onSelectionChange);
31
+ document.removeEventListener("selectionchange", onSelectionChange);
30
32
  };
31
33
  }, [editSessionActive, editorRef]);
32
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.3.11-input-ref-1",
3
+ "version": "1.3.11-input-ref-3",
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.3.11-input-ref-1",
19
+ "@fileverse-dev/fortune-core": "1.3.11-input-ref-3",
20
20
  "@fileverse/ui": "5.0.0",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",