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

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.
@@ -56,31 +56,34 @@ var InputBox = function InputBox() {
56
56
  var _x = useState(0),
57
57
  commaCount = _x[0],
58
58
  setCommaCount = _x[1];
59
+ var _y = useState(false),
60
+ cellEditorIsFormula = _y[0],
61
+ setCellEditorIsFormula = _y[1];
59
62
  var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
60
- var _y = useState(!hideFormulaHintLocal),
61
- showFormulaHint = _y[0],
62
- setShowFormulaHint = _y[1];
63
- var _z = useState(false),
64
- showSearchHint = _z[0],
65
- setShowSearchHint = _z[1];
63
+ var _z = useState(!hideFormulaHintLocal),
64
+ showFormulaHint = _z[0],
65
+ setShowFormulaHint = _z[1];
66
+ var _0 = useState(false),
67
+ showSearchHint = _0[0],
68
+ setShowSearchHint = _0[1];
66
69
  var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
67
70
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
68
71
  var isComposingRef = useRef(false);
69
72
  var formulaAnchorCellRef = useRef(null);
70
73
  var skipNextAnchorSelectionSyncRef = useRef(false);
71
74
  var lastHandledMouseDragSignatureRef = useRef("");
72
- var _0 = useFormulaEditorHistory(inputRef, refs.cellInput, refs.fxInput, setContext, "cell"),
73
- formulaHistoryRef = _0.formulaHistoryRef,
74
- preTextRef = _0.preTextRef,
75
- resetFormulaHistory = _0.resetFormulaHistory,
76
- handleFormulaHistoryUndoRedo = _0.handleFormulaHistoryUndoRedo,
77
- capturePreFormulaState = _0.capturePreFormulaState,
78
- appendFormulaHistoryFromPrimaryEditor = _0.appendFormulaHistoryFromPrimaryEditor;
75
+ var _1 = useFormulaEditorHistory(inputRef, refs.cellInput, refs.fxInput, setContext, "cell"),
76
+ formulaHistoryRef = _1.formulaHistoryRef,
77
+ preTextRef = _1.preTextRef,
78
+ resetFormulaHistory = _1.resetFormulaHistory,
79
+ handleFormulaHistoryUndoRedo = _1.handleFormulaHistoryUndoRedo,
80
+ capturePreFormulaState = _1.capturePreFormulaState,
81
+ appendFormulaHistoryFromPrimaryEditor = _1.appendFormulaHistoryFromPrimaryEditor;
79
82
  var ZWSP = "\u200B";
80
83
  var inputBoxInnerRef = useRef(null);
81
- var _1 = useState([]),
82
- linkSelectionHighlightRects = _1[0],
83
- setLinkSelectionHighlightRects = _1[1];
84
+ var _2 = useState([]),
85
+ linkSelectionHighlightRects = _2[0],
86
+ setLinkSelectionHighlightRects = _2[1];
84
87
  var ensureNotEmpty = function ensureNotEmpty() {
85
88
  var el = inputRef.current;
86
89
  if (!el) return;
@@ -103,12 +106,11 @@ var InputBox = function InputBox() {
103
106
  return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
104
107
  };
105
108
  var inputBoxStyle = useMemo(function () {
106
- var _a;
107
109
  if (firstSelectionActiveCell && context.luckysheetCellUpdate.length > 0) {
108
110
  var flowdata = getFlowdata(context);
109
111
  if (!flowdata) return {};
110
112
  var style = getStyleByCell(context, flowdata, firstSelectionActiveCell.row_focus, firstSelectionActiveCell.column_focus);
111
- if (((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText.charAt(0)) === "=") {
113
+ if (cellEditorIsFormula) {
112
114
  style = __assign(__assign({}, style), {
113
115
  textAlign: "left"
114
116
  });
@@ -116,7 +118,7 @@ var InputBox = function InputBox() {
116
118
  return style;
117
119
  }
118
120
  return {};
119
- }, [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]);
121
+ }, [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]);
120
122
  useLayoutEffect(function () {
121
123
  var _a;
122
124
  if (!context.allowEdit) {
@@ -136,10 +138,23 @@ var InputBox = function InputBox() {
136
138
  if (_.isEqual(prevCellUpdate, context.luckysheetCellUpdate) && prevSheetId === context.currentSheetId) {
137
139
  return;
138
140
  }
141
+ var _b = context.luckysheetCellUpdate,
142
+ ur = _b[0],
143
+ uc = _b[1];
144
+ var pending_1 = refs.globalCache.pendingTypeOverCell;
145
+ if (pending_1 && pending_1[0] === ur && pending_1[1] === uc) {
146
+ refs.globalCache.overwriteCell = false;
147
+ if (inputRef.current) {
148
+ setCellEditorIsFormula(inputRef.current.innerText.trim().startsWith("="));
149
+ }
150
+ delete refs.globalCache.doNotFocus;
151
+ return;
152
+ }
139
153
  var flowdata = getFlowdata(context);
140
154
  var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index]) === null || _a === void 0 ? void 0 : _a[col_index];
155
+ var overwrite = refs.globalCache.overwriteCell;
141
156
  var value_1 = "";
142
- if (cell && !refs.globalCache.overwriteCell) {
157
+ if (cell && !overwrite) {
143
158
  if (isInlineStringCell(cell)) {
144
159
  value_1 = getInlineStringHTML(row_index, col_index, flowdata);
145
160
  } else if (cell.f) {
@@ -155,14 +170,20 @@ var InputBox = function InputBox() {
155
170
  }
156
171
  }
157
172
  refs.globalCache.overwriteCell = false;
173
+ var wroteEditorFromStoredCell = false;
158
174
  if (!refs.globalCache.ignoreWriteCell && inputRef.current && value_1) {
159
175
  inputRef.current.innerHTML = escapeHTMLTag(escapeScriptTag(value_1));
160
- } else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1) {
176
+ wroteEditorFromStoredCell = true;
177
+ } else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1 && !overwrite) {
161
178
  var valueD = getCellValue(row_index, col_index, flowdata, "f");
162
179
  inputRef.current.innerText = valueD;
180
+ wroteEditorFromStoredCell = true;
163
181
  }
164
182
  refs.globalCache.ignoreWriteCell = false;
165
- if (!refs.globalCache.doNotFocus) {
183
+ if (inputRef.current) {
184
+ setCellEditorIsFormula(inputRef.current.innerText.trim().startsWith("="));
185
+ }
186
+ if (wroteEditorFromStoredCell && !refs.globalCache.doNotFocus) {
166
187
  setTimeout(function () {
167
188
  moveToEnd(inputRef.current);
168
189
  });
@@ -175,9 +196,15 @@ var InputBox = function InputBox() {
175
196
  if (inputRef.current) {
176
197
  inputRef.current.innerHTML = "";
177
198
  }
199
+ delete refs.globalCache.pendingTypeOverCell;
200
+ setCellEditorIsFormula(false);
178
201
  resetFormulaHistory();
179
202
  }
180
- }, [context.luckysheetCellUpdate, resetFormulaHistory]);
203
+ }, [context.luckysheetCellUpdate, resetFormulaHistory, refs.globalCache]);
204
+ useEffect(function () {
205
+ if (_.isEmpty(context.luckysheetCellUpdate)) return;
206
+ delete refs.globalCache.pendingTypeOverCell;
207
+ }, [context.luckysheetCellUpdate, refs.globalCache]);
181
208
  useEffect(function () {
182
209
  var _a;
183
210
  if (_.isEmpty(context.luckysheetCellUpdate) || !refs.cellInput.current) {
@@ -468,6 +495,12 @@ var InputBox = function InputBox() {
468
495
  row_focus: anchorRow_2,
469
496
  column_focus: anchorCol_2
470
497
  }];
498
+ markRangeSelectionDirty(draftCtx);
499
+ var el = refs.cellInput.current;
500
+ if (el && el.innerText.trim().startsWith("=")) {
501
+ createRangeHightlight(draftCtx, el.innerHTML);
502
+ rangeHightlightselected(draftCtx, el);
503
+ }
471
504
  });
472
505
  }, 0);
473
506
  }
@@ -498,7 +531,7 @@ var InputBox = function InputBox() {
498
531
  e.preventDefault();
499
532
  } else if (e.key === "F4" && context.luckysheetCellUpdate.length > 0) {
500
533
  e.preventDefault();
501
- } else if (e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
534
+ } else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
502
535
  if (document.getElementById("luckysheet-formula-search-c")) {
503
536
  var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
504
537
  var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
@@ -517,7 +550,7 @@ var InputBox = function InputBox() {
517
550
  }
518
551
  }
519
552
  e.preventDefault();
520
- } else if (e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
553
+ } else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0 && allowListNavigation) {
521
554
  if (document.getElementById("luckysheet-formula-search-c")) {
522
555
  var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
523
556
  var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
@@ -535,7 +568,7 @@ var InputBox = function InputBox() {
535
568
  }
536
569
  e.preventDefault();
537
570
  }
538
- }, [capturePreFormulaState, clearSearchItemActiveClass, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, selectActiveFormula, setContext, firstSelection]);
571
+ }, [capturePreFormulaState, clearSearchItemActiveClass, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, selectActiveFormula, setContext, firstSelection, refs.cellInput]);
539
572
  var handleHideShowHint = function handleHideShowHint() {
540
573
  var _a, _b, _c, _d;
541
574
  var searchElFx = (_a = document.getElementsByClassName("fx-search")) === null || _a === void 0 ? void 0 : _a[0];
@@ -556,10 +589,12 @@ var InputBox = function InputBox() {
556
589
  }
557
590
  };
558
591
  var onChange = useCallback(function (__, isBlur) {
559
- var _a, _b, _c;
592
+ var _a, _b, _c, _d, _e, _f;
560
593
  if (context.isFlvReadOnly) return;
561
594
  handleHideShowHint();
562
- setShowSearchHint(shouldShowFormulaFunctionList((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) !== null && _a !== void 0 ? _a : null));
595
+ 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 : "";
596
+ setCellEditorIsFormula(editorText.startsWith("="));
597
+ setShowSearchHint(shouldShowFormulaFunctionList((_d = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) !== null && _d !== void 0 ? _d : null));
563
598
  if (!isComposingRef.current) {
564
599
  var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
565
600
  setCommaCount(currentCommaCount);
@@ -567,7 +602,7 @@ var InputBox = function InputBox() {
567
602
  var e = lastKeyDownEventRef.current;
568
603
  if (!e) {
569
604
  var cellEl_1 = refs.cellInput.current;
570
- 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("=")))) {
605
+ 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("=")))) {
571
606
  setContext(function (draftCtx) {
572
607
  if (!isAllowEdit(draftCtx, draftCtx.luckysheet_select_save)) return;
573
608
  rangeHightlightselected(draftCtx, cellEl_1);
@@ -582,11 +617,16 @@ var InputBox = function InputBox() {
582
617
  });
583
618
  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) {
584
619
  setContext(function (draftCtx) {
620
+ var _a, _b;
585
621
  if ((draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start || israngeseleciton(draftCtx)) && isBlur) return;
586
622
  if (!isAllowEdit(draftCtx, draftCtx.luckysheet_select_save)) {
587
623
  return;
588
624
  }
589
625
  handleFormulaInput(draftCtx, refs.fxInput.current, refs.cellInput.current, kcode, preTextRef.current);
626
+ var cellEl = refs.cellInput.current;
627
+ 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("=")))) {
628
+ rangeHightlightselected(draftCtx, cellEl);
629
+ }
590
630
  });
591
631
  }
592
632
  }, [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;
@@ -10,7 +10,7 @@ var __assign = this && this.__assign || function () {
10
10
  };
11
11
  import React, { useContext, useCallback, useRef, useEffect, useLayoutEffect, useMemo } from "react";
12
12
  import "./index.css";
13
- import { locale, drawArrow, handleCellAreaDoubleClick, handleCellAreaMouseDown, handleContextMenu, handleOverlayMouseMove, handleOverlayMouseUp, selectAll, handleOverlayTouchEnd, handleOverlayTouchStart, createDropCellRange, getCellRowColumn, getCellHyperlink, showLinkCard, isAllowEdit, onCellsMoveStart, insertRowCol, getSheetIndex, fixRowStyleOverflowInFreeze, fixColumnStyleOverflowInFreeze, handleKeydownForZoom } from "@fileverse-dev/fortune-core";
13
+ import { locale, drawArrow, handleCellAreaDoubleClick, handleCellAreaMouseDown, handleContextMenu, handleOverlayMouseMove, handleOverlayMouseUp, selectAll, handleOverlayTouchEnd, handleOverlayTouchStart, createDropCellRange, getCellRowColumn, getCellHyperlink, showLinkCard, isAllowEdit, israngeseleciton, onCellsMoveStart, insertRowCol, getSheetIndex, fixRowStyleOverflowInFreeze, fixColumnStyleOverflowInFreeze, handleKeydownForZoom } from "@fileverse-dev/fortune-core";
14
14
  import _ from "lodash";
15
15
  import WorkbookContext from "../../context";
16
16
  import ColumnHeader from "./ColumnHeader";
@@ -49,6 +49,7 @@ var SheetOverlay = function SheetOverlay() {
49
49
  setContext(function (draftCtx) {
50
50
  var _a;
51
51
  handleCellAreaMouseDown(draftCtx, refs.globalCache, nativeEvent, refs.cellInput.current, refs.cellArea.current, refs.fxInput.current, refs.canvas.current.getContext("2d"));
52
+ var keepFormulaBarFocused = draftCtx.luckysheetCellUpdate.length > 0 && draftCtx.formulaCache.formulaEditorOwner === "fx" && (draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start || israngeseleciton(draftCtx));
52
53
  if (!_.isEmpty((_a = draftCtx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) && refs.cellInput.current) {
53
54
  if (!isAllowEdit(draftCtx)) {
54
55
  setTimeout(function () {
@@ -60,7 +61,13 @@ var SheetOverlay = function SheetOverlay() {
60
61
  } else {
61
62
  setTimeout(function () {
62
63
  var _a;
63
- (_a = refs.cellInput.current) === null || _a === void 0 ? void 0 : _a.focus();
64
+ if (keepFormulaBarFocused && refs.fxInput.current) {
65
+ refs.fxInput.current.focus({
66
+ preventScroll: true
67
+ });
68
+ } else {
69
+ (_a = refs.cellInput.current) === null || _a === void 0 ? void 0 : _a.focus();
70
+ }
64
71
  });
65
72
  }
66
73
  }
@@ -3,7 +3,9 @@ export function useRerenderOnFormulaCaret(editorRef, editSessionActive) {
3
3
  var _a = useState(0),
4
4
  bump = _a[1];
5
5
  useEffect(function () {
6
- if (!editSessionActive) return;
6
+ if (!editSessionActive) {
7
+ return function () {};
8
+ }
7
9
  var onSelectionChange = function onSelectionChange() {
8
10
  var _a, _b;
9
11
  var el = editorRef.current;
@@ -20,7 +22,7 @@ export function useRerenderOnFormulaCaret(editorRef, editSessionActive) {
20
22
  };
21
23
  document.addEventListener("selectionchange", onSelectionChange);
22
24
  return function () {
23
- return document.removeEventListener("selectionchange", onSelectionChange);
25
+ document.removeEventListener("selectionchange", onSelectionChange);
24
26
  };
25
27
  }, [editSessionActive, editorRef]);
26
28
  }
@@ -55,6 +55,7 @@ var FxEditor = function FxEditor() {
55
55
  var prevCellUpdate = (0, _usePrevious.default)(context.luckysheetCellUpdate);
56
56
  var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
57
57
  var recentText = (0, _react.useRef)("");
58
+ var formulaAnchorCellRef = (0, _react.useRef)(null);
58
59
  var handleShowFormulaHint = function handleShowFormulaHint() {
59
60
  localStorage.setItem("formulaMore", String(showFormulaHint));
60
61
  setShowFormulaHint(!showFormulaHint);
@@ -120,13 +121,20 @@ var FxEditor = function FxEditor() {
120
121
  if (_lodash.default.isNil(rowIndex) || _lodash.default.isNil(colIndex)) {
121
122
  return;
122
123
  }
124
+ var pending = refs.globalCache.pendingTypeOverCell;
125
+ if (pending && pending[0] === rowIndex && pending[1] === colIndex) {
126
+ refs.globalCache.overwriteCell = false;
127
+ refs.globalCache.ignoreWriteCell = false;
128
+ return;
129
+ }
123
130
  var flowdata = (0, _fortuneCore.getFlowdata)(context);
124
131
  if (!flowdata) {
125
132
  return;
126
133
  }
127
134
  var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[rowIndex]) === null || _a === void 0 ? void 0 : _a[colIndex];
128
135
  var value = "";
129
- if (cell && !refs.globalCache.overwriteCell) {
136
+ var overwrite = refs.globalCache.overwriteCell;
137
+ if (cell && !overwrite) {
130
138
  if ((0, _fortuneCore.isInlineStringCell)(cell)) {
131
139
  value = (0, _fortuneCore.getInlineStringNoStyle)(rowIndex, colIndex, flowdata);
132
140
  } else if (cell.f) {
@@ -138,7 +146,7 @@ var FxEditor = function FxEditor() {
138
146
  refs.globalCache.overwriteCell = false;
139
147
  if (!refs.globalCache.ignoreWriteCell && value) {
140
148
  fxInput.innerHTML = (0, _fortuneCore.escapeHTMLTag)((0, _fortuneCore.escapeScriptTag)(value));
141
- } else if (!refs.globalCache.ignoreWriteCell) {
149
+ } else if (!refs.globalCache.ignoreWriteCell && !overwrite) {
142
150
  var valueD = (0, _fortuneCore.getCellValue)(rowIndex, colIndex, flowdata, "f");
143
151
  fxInput.innerText = valueD;
144
152
  }
@@ -146,9 +154,21 @@ var FxEditor = function FxEditor() {
146
154
  }, [context.luckysheetCellUpdate, context.luckysheetfile, context.currentSheetId, prevCellUpdate, prevSheetId, refs.fxInput, refs.globalCache]);
147
155
  (0, _react.useEffect)(function () {
148
156
  if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
157
+ delete refs.globalCache.pendingTypeOverCell;
149
158
  resetFormulaHistory();
150
159
  }
151
- }, [context.luckysheetCellUpdate, resetFormulaHistory]);
160
+ }, [context.luckysheetCellUpdate, resetFormulaHistory, refs.globalCache]);
161
+ (0, _react.useEffect)(function () {
162
+ var _a;
163
+ if (_lodash.default.isEmpty(context.luckysheetCellUpdate) || !refs.fxInput.current) {
164
+ formulaAnchorCellRef.current = null;
165
+ return;
166
+ }
167
+ var inputText = ((_a = refs.fxInput.current.innerText) === null || _a === void 0 ? void 0 : _a.trim()) || "";
168
+ if (!inputText.startsWith("=")) {
169
+ formulaAnchorCellRef.current = null;
170
+ }
171
+ }, [context.luckysheetCellUpdate, refs.fxInput]);
152
172
  var onFocus = (0, _react.useCallback)(function () {
153
173
  var _a, _b;
154
174
  if (context.allowEdit === false) {
@@ -156,12 +176,25 @@ var FxEditor = function FxEditor() {
156
176
  }
157
177
  if (((_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 && !context.luckysheet_cell_selected_move && (0, _fortuneCore.isAllowEdit)(context, context.luckysheet_select_save)) {
158
178
  setContext(function (draftCtx) {
179
+ var _a;
159
180
  (0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "fx");
160
181
  var last = draftCtx.luckysheet_select_save[draftCtx.luckysheet_select_save.length - 1];
161
182
  var row_index = last.row_focus;
162
183
  var col_index = last.column_focus;
163
- draftCtx.luckysheetCellUpdate = [row_index, col_index];
164
- refs.globalCache.doNotFocus = true;
184
+ if (!_lodash.default.isNil(row_index) && !_lodash.default.isNil(col_index)) {
185
+ var flowdata = (0, _fortuneCore.getFlowdata)(draftCtx);
186
+ var cellAt = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index]) === null || _a === void 0 ? void 0 : _a[col_index];
187
+ if ((cellAt === null || cellAt === void 0 ? void 0 : cellAt.f) != null && String(cellAt.f).trim() !== "") {
188
+ (0, _fortuneCore.suppressFormulaRangeSelectionForInitialEdit)(draftCtx);
189
+ }
190
+ }
191
+ var currentUpdate = draftCtx.luckysheetCellUpdate || [];
192
+ var alreadyEditingSameCell = currentUpdate.length === 2 && currentUpdate[0] === row_index && currentUpdate[1] === col_index;
193
+ if (!alreadyEditingSameCell) {
194
+ refs.globalCache.doNotUpdateCell = true;
195
+ draftCtx.luckysheetCellUpdate = [row_index, col_index];
196
+ refs.globalCache.doNotFocus = true;
197
+ }
165
198
  });
166
199
  }
167
200
  setContext(function (draftCtx) {
@@ -221,6 +254,25 @@ var FxEditor = function FxEditor() {
221
254
  }, [getActiveFormula, insertSelectedFormula]);
222
255
  var onKeyDown = (0, _react.useCallback)(function (e) {
223
256
  var _a, _b, _c;
257
+ if (e.key === "Delete" || e.key === "Backspace") {
258
+ var anchor = formulaAnchorCellRef.current;
259
+ if (anchor != null) {
260
+ var anchorRow_1 = anchor[0],
261
+ anchorCol_1 = anchor[1];
262
+ setTimeout(function () {
263
+ setContext(function (draftCtx) {
264
+ draftCtx.luckysheetCellUpdate = [anchorRow_1, anchorCol_1];
265
+ draftCtx.luckysheet_select_save = [{
266
+ row: [anchorRow_1, anchorRow_1],
267
+ column: [anchorCol_1, anchorCol_1],
268
+ row_focus: anchorRow_1,
269
+ column_focus: anchorCol_1
270
+ }];
271
+ (0, _fortuneCore.markRangeSelectionDirty)(draftCtx);
272
+ });
273
+ }, 0);
274
+ }
275
+ }
224
276
  if (context.allowEdit === false) {
225
277
  return;
226
278
  }
@@ -234,6 +286,46 @@ var FxEditor = function FxEditor() {
234
286
  recentText.current = refs.fxInput.current.innerText;
235
287
  var key = e.key;
236
288
  var currentInputText = ((_c = (_b = refs.fxInput.current) === null || _b === void 0 ? void 0 : _b.innerText) === null || _c === void 0 ? void 0 : _c.trim()) || "";
289
+ if ((key === "=" || currentInputText.startsWith("=")) && context.luckysheetCellUpdate.length === 2 && formulaAnchorCellRef.current == null) {
290
+ setContext(function (draftCtx) {
291
+ draftCtx.formulaCache.rangeSelectionActive = null;
292
+ });
293
+ formulaAnchorCellRef.current = [context.luckysheetCellUpdate[0], context.luckysheetCellUpdate[1]];
294
+ }
295
+ if (key === "(" && currentInputText.startsWith("=")) {
296
+ setContext(function (draftCtx) {
297
+ draftCtx.formulaCache.rangeSelectionActive = null;
298
+ });
299
+ }
300
+ if (key === "," && context.luckysheetCellUpdate.length > 0 && currentInputText.startsWith("=") && formulaAnchorCellRef.current) {
301
+ setContext(function (draftCtx) {
302
+ draftCtx.formulaCache.rangeSelectionActive = null;
303
+ });
304
+ var _d = formulaAnchorCellRef.current,
305
+ anchorRow_2 = _d[0],
306
+ anchorCol_2 = _d[1];
307
+ setTimeout(function () {
308
+ setContext(function (draftCtx) {
309
+ var _a, _b;
310
+ draftCtx.luckysheetCellUpdate = [anchorRow_2, anchorCol_2];
311
+ draftCtx.luckysheet_select_save = [{
312
+ row: [anchorRow_2, anchorRow_2],
313
+ column: [anchorCol_2, anchorCol_2],
314
+ row_focus: anchorRow_2,
315
+ column_focus: anchorCol_2
316
+ }];
317
+ draftCtx.formulaRangeSelect = undefined;
318
+ draftCtx.formulaCache.selectingRangeIndex = -1;
319
+ draftCtx.formulaCache.func_selectedrange = undefined;
320
+ draftCtx.formulaCache.rangechangeindex = undefined;
321
+ draftCtx.formulaCache.rangestart = false;
322
+ draftCtx.formulaCache.rangedrag_column_start = false;
323
+ draftCtx.formulaCache.rangedrag_row_start = false;
324
+ (0, _fortuneCore.createRangeHightlight)(draftCtx, ((_a = refs.fxInput.current) === null || _a === void 0 ? void 0 : _a.innerHTML) || ((_b = refs.cellInput.current) === null || _b === void 0 ? void 0 : _b.innerHTML) || "");
325
+ (0, _fortuneCore.moveHighlightCell)(draftCtx, "down", 0, "rangeOfSelect");
326
+ });
327
+ }, 0);
328
+ }
237
329
  if (key === "ArrowLeft" || key === "ArrowRight") {
238
330
  e.stopPropagation();
239
331
  }
@@ -261,7 +353,7 @@ var FxEditor = function FxEditor() {
261
353
  }
262
354
  return;
263
355
  }
264
- if (e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0) {
356
+ if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowUp" && context.luckysheetCellUpdate.length > 0) {
265
357
  if (document.getElementById("luckysheet-formula-search-c")) {
266
358
  var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
267
359
  var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
@@ -280,7 +372,7 @@ var FxEditor = function FxEditor() {
280
372
  }
281
373
  }
282
374
  e.preventDefault();
283
- } else if (e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0) {
375
+ } else if (!(e.metaKey || e.ctrlKey) && e.key === "ArrowDown" && context.luckysheetCellUpdate.length > 0) {
284
376
  if (document.getElementById("luckysheet-formula-search-c")) {
285
377
  var formulaSearchContainer = document.getElementById("luckysheet-formula-search-c");
286
378
  var activeItem = formulaSearchContainer === null || formulaSearchContainer === void 0 ? void 0 : formulaSearchContainer.querySelector(".luckysheet-formula-search-item-active");
@@ -339,7 +431,7 @@ var FxEditor = function FxEditor() {
339
431
  }
340
432
  }
341
433
  });
342
- }, [capturePreFormulaState, context.allowEdit, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, refs.fxInput, setContext]);
434
+ }, [capturePreFormulaState, context.allowEdit, context.luckysheetCellUpdate, handleFormulaHistoryUndoRedo, refs.cellInput, refs.fxInput, setContext]);
343
435
  var handleHideShowHint = function handleHideShowHint() {
344
436
  var _a, _b, _c, _d;
345
437
  var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
@@ -360,11 +452,18 @@ var FxEditor = function FxEditor() {
360
452
  }
361
453
  };
362
454
  var onChange = (0, _react.useCallback)(function () {
363
- var _a, _b, _c;
455
+ var _a, _b, _c, _d;
364
456
  if (context.isFlvReadOnly) return;
457
+ var fxEl = refs.fxInput.current;
458
+ if (fxEl && context.luckysheetCellUpdate.length === 2 && formulaAnchorCellRef.current == null) {
459
+ var t = ((_a = fxEl.innerText) === null || _a === void 0 ? void 0 : _a.trim()) || "";
460
+ if (t.startsWith("=")) {
461
+ formulaAnchorCellRef.current = [context.luckysheetCellUpdate[0], context.luckysheetCellUpdate[1]];
462
+ }
463
+ }
365
464
  handleHideShowHint();
366
- setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) !== null && _b !== void 0 ? _b : null));
367
- var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current);
465
+ setShowSearchHint((0, _helper.shouldShowFormulaFunctionList)((_c = (_b = refs.fxInput) === null || _b === void 0 ? void 0 : _b.current) !== null && _c !== void 0 ? _c : null));
466
+ var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_d = refs.fxInput) === null || _d === void 0 ? void 0 : _d.current);
368
467
  setCommaCount(currentCommaCount);
369
468
  var e = lastKeyDownEventRef.current;
370
469
  if (!e) {
@@ -399,7 +498,7 @@ var FxEditor = function FxEditor() {
399
498
  (0, _fortuneCore.handleFormulaInput)(draftCtx, refs.cellInput.current, refs.fxInput.current, kcode, recentText.current);
400
499
  });
401
500
  }
402
- }, [appendFormulaHistoryFromPrimaryEditor, context.isFlvReadOnly, refs.cellInput, refs.fxInput, setContext]);
501
+ }, [appendFormulaHistoryFromPrimaryEditor, context.isFlvReadOnly, context.luckysheetCellUpdate, refs.cellInput, refs.fxInput, setContext]);
403
502
  (0, _useRerenderOnFormulaCaret.useRerenderOnFormulaCaret)(refs.fxInput, context.luckysheetCellUpdate.length > 0);
404
503
  var getFunctionNameFromInput = (0, _react.useCallback)(function () {
405
504
  var _a, _b, _c, _d;
@@ -454,7 +553,7 @@ var FxEditor = function FxEditor() {
454
553
  document.addEventListener("mouseup", _onMouseUp);
455
554
  };
456
555
  return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
457
- className: "fortune-fx-editor",
556
+ className: showFxFormulaChrome ? "fortune-fx-editor fortune-fx-editor--formula-owner" : "fortune-fx-editor",
458
557
  ref: divRef
459
558
  }, /*#__PURE__*/_react.default.createElement(_NameBox.default, null), /*#__PURE__*/_react.default.createElement("div", {
460
559
  className: "fortune-fx-icon",
@@ -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;