@fileverse-dev/fortune-react 1.3.13-create-3 → 1.3.13-create-5

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 (35) hide show
  1. package/es/components/FxEditor/index.js +73 -18
  2. package/es/components/SheetOverlay/ContentEditable.js +4 -3
  3. package/es/components/SheetOverlay/InputBox.js +193 -44
  4. package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +4 -27
  5. package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +4 -25
  6. package/es/components/SheetOverlay/formula-segment-boundary.js +1 -1
  7. package/es/components/SheetOverlay/helper.d.ts +7 -0
  8. package/es/components/SheetOverlay/helper.js +75 -0
  9. package/es/components/SheetOverlay/index.css +10 -83
  10. package/es/components/SheetOverlay/index.js +1 -26
  11. package/es/components/Toolbar/ColorPicker.js +3 -2
  12. package/es/components/Toolbar/CustomColor.js +7 -3
  13. package/es/components/Toolbar/index.js +11 -2
  14. package/es/hooks/useFormulaEditorHistory.d.ts +4 -4
  15. package/es/hooks/useFormulaEditorHistory.js +87 -59
  16. package/es/hooks/useRerenderOnFormulaCaret.d.ts +1 -1
  17. package/es/hooks/useRerenderOnFormulaCaret.js +6 -3
  18. package/lib/components/FxEditor/index.js +72 -17
  19. package/lib/components/SheetOverlay/ContentEditable.js +4 -3
  20. package/lib/components/SheetOverlay/InputBox.js +192 -43
  21. package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +3 -26
  22. package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +3 -24
  23. package/lib/components/SheetOverlay/formula-segment-boundary.js +1 -1
  24. package/lib/components/SheetOverlay/helper.d.ts +7 -0
  25. package/lib/components/SheetOverlay/helper.js +79 -0
  26. package/lib/components/SheetOverlay/index.css +10 -83
  27. package/lib/components/SheetOverlay/index.js +1 -26
  28. package/lib/components/Toolbar/ColorPicker.js +3 -2
  29. package/lib/components/Toolbar/CustomColor.js +7 -3
  30. package/lib/components/Toolbar/index.js +10 -1
  31. package/lib/hooks/useFormulaEditorHistory.d.ts +4 -4
  32. package/lib/hooks/useFormulaEditorHistory.js +85 -58
  33. package/lib/hooks/useRerenderOnFormulaCaret.d.ts +1 -1
  34. package/lib/hooks/useRerenderOnFormulaCaret.js +5 -2
  35. package/package.json +2 -2
@@ -41,12 +41,11 @@ var FxEditor = function FxEditor() {
41
41
  refs = _g.refs;
42
42
  var lastKeyDownEventRef = (0, _react.useRef)(null);
43
43
  var _h = (0, _useFormulaEditorHistory.useFormulaEditorHistory)(refs.fxInput, refs.cellInput, refs.fxInput, setContext, "fx"),
44
- formulaHistoryRef = _h.formulaHistoryRef,
45
44
  preTextRef = _h.preTextRef,
46
45
  resetFormulaHistory = _h.resetFormulaHistory,
47
46
  handleFormulaHistoryUndoRedo = _h.handleFormulaHistoryUndoRedo,
48
- capturePreFormulaState = _h.capturePreFormulaState,
49
- appendFormulaHistoryFromPrimaryEditor = _h.appendFormulaHistoryFromPrimaryEditor;
47
+ capturePreEditorHistoryState = _h.capturePreEditorHistoryState,
48
+ appendEditorHistoryFromPrimaryEditor = _h.appendEditorHistoryFromPrimaryEditor;
50
49
  var inputContainerRef = (0, _react.useRef)(null);
51
50
  var _j = (0, _react.useState)(false),
52
51
  isHidenRC = _j[0],
@@ -288,7 +287,20 @@ var FxEditor = function FxEditor() {
288
287
  var currentCommaCount = (0, _helper.countCommasBeforeCursor)((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
289
288
  setCommaCount(currentCommaCount);
290
289
  lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
291
- capturePreFormulaState();
290
+ if (!(0, _helper.isEditorUndoRedoKeyEvent)(e.nativeEvent)) {
291
+ capturePreEditorHistoryState();
292
+ }
293
+ var isPotentialContentKey = !e.metaKey && !e.ctrlKey && !e.altKey && (e.key.length === 1 || e.key === "Backspace" || e.key === "Delete" || e.key === "Enter" || e.key === "Tab");
294
+ if (isPotentialContentKey) {
295
+ requestAnimationFrame(function () {
296
+ requestAnimationFrame(function () {
297
+ if ((0, _fortuneCore.getFormulaEditorOwner)(context) !== "fx") return;
298
+ appendEditorHistoryFromPrimaryEditor(function () {
299
+ return (0, _helper.getCursorPosition)(refs.fxInput.current);
300
+ });
301
+ });
302
+ });
303
+ }
292
304
  recentText.current = refs.fxInput.current.innerText;
293
305
  var key = e.key;
294
306
  var currentInputText = ((_c = (_b = refs.fxInput.current) === null || _b === void 0 ? void 0 : _b.innerText) === null || _c === void 0 ? void 0 : _c.trim()) || "";
@@ -340,14 +352,20 @@ var FxEditor = function FxEditor() {
340
352
  }
341
353
  if ((e.metaKey || e.ctrlKey) && context.luckysheetCellUpdate.length > 0) {
342
354
  if (e.code === "KeyZ" || e.code === "KeyY") {
343
- var shouldUseFormulaHistory = currentInputText.startsWith("=") || formulaHistoryRef.current.active;
344
- if (shouldUseFormulaHistory) {
345
- var handledByFormulaHistory = handleFormulaHistoryUndoRedo(e.code === "KeyY" || e.code === "KeyZ" && e.shiftKey);
346
- if (handledByFormulaHistory) {
347
- e.preventDefault();
348
- }
349
- }
355
+ var isRedo_1 = e.code === "KeyY" || e.code === "KeyZ" && e.shiftKey;
356
+ e.preventDefault();
350
357
  e.stopPropagation();
358
+ var _attempt_ = function attempt_1(triesLeft) {
359
+ var handled = handleFormulaHistoryUndoRedo(isRedo_1);
360
+ if (handled) return;
361
+ if (triesLeft <= 0) return;
362
+ requestAnimationFrame(function () {
363
+ requestAnimationFrame(function () {
364
+ return _attempt_(triesLeft - 1);
365
+ });
366
+ });
367
+ };
368
+ _attempt_(2);
351
369
  return;
352
370
  }
353
371
  }
@@ -440,7 +458,7 @@ var FxEditor = function FxEditor() {
440
458
  }
441
459
  }
442
460
  });
443
- }, [capturePreFormulaState, context.allowEdit, context.luckysheetCellUpdate, handleFormulaHistoryUndoRedo, refs.cellInput, refs.fxInput, setContext]);
461
+ }, [capturePreEditorHistoryState, context.allowEdit, context.luckysheetCellUpdate, handleFormulaHistoryUndoRedo, refs.cellInput, refs.fxInput, setContext]);
444
462
  var handleHideShowHint = function handleHideShowHint() {
445
463
  var _a, _b, _c, _d;
446
464
  var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
@@ -492,23 +510,55 @@ var FxEditor = function FxEditor() {
492
510
  if (editor_1) {
493
511
  setContext(function (draftCtx) {
494
512
  if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) return;
513
+ if ((0, _fortuneCore.getFormulaEditorOwner)(draftCtx) !== "fx") return;
514
+ if (draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start) {
515
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, editor_1);
516
+ return;
517
+ }
518
+ draftCtx.formulaCache.selectingRangeIndex = -1;
519
+ (0, _fortuneCore.createRangeHightlight)(draftCtx, editor_1.innerHTML);
495
520
  (0, _fortuneCore.rangeHightlightselected)(draftCtx, editor_1);
496
521
  });
497
522
  }
498
523
  return;
499
524
  }
525
+ if ((0, _helper.isEditorUndoRedoKeyEvent)(e)) {
526
+ return;
527
+ }
500
528
  var kcode = e.keyCode;
501
529
  if (!kcode) return;
502
- appendFormulaHistoryFromPrimaryEditor(function () {
503
- return (0, _helper.getCursorPosition)(refs.fxInput.current);
504
- });
505
530
  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) {
506
531
  setContext(function (draftCtx) {
507
532
  (0, _fortuneCore.handleFormulaInput)(draftCtx, refs.cellInput.current, refs.fxInput.current, kcode, recentText.current);
508
533
  });
509
534
  }
510
- }, [appendFormulaHistoryFromPrimaryEditor, context.isFlvReadOnly, context.luckysheetCellUpdate, refs.cellInput, refs.fxInput, setContext]);
511
- (0, _useRerenderOnFormulaCaret.useRerenderOnFormulaCaret)(refs.fxInput, context.luckysheetCellUpdate.length > 0);
535
+ requestAnimationFrame(function () {
536
+ if ((0, _fortuneCore.getFormulaEditorOwner)(context) !== "fx") return;
537
+ appendEditorHistoryFromPrimaryEditor(function () {
538
+ return (0, _helper.getCursorPosition)(refs.fxInput.current);
539
+ });
540
+ });
541
+ }, [appendEditorHistoryFromPrimaryEditor, context.isFlvReadOnly, context.luckysheetCellUpdate, refs.cellInput, refs.fxInput, setContext]);
542
+ var refreshFxFormulaRangeHighlights = (0, _react.useCallback)(function () {
543
+ var el = refs.fxInput.current;
544
+ if (!el) return;
545
+ setContext(function (draftCtx) {
546
+ var _a, _b;
547
+ if (draftCtx.luckysheetCellUpdate.length === 0) return;
548
+ if ((0, _fortuneCore.getFormulaEditorOwner)(draftCtx) !== "fx") return;
549
+ if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) return;
550
+ var t = (_b = (_a = el.innerText) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
551
+ if (!t.startsWith("=")) return;
552
+ if (draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start) {
553
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, el);
554
+ return;
555
+ }
556
+ draftCtx.formulaCache.selectingRangeIndex = -1;
557
+ (0, _fortuneCore.createRangeHightlight)(draftCtx, el.innerHTML);
558
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, el);
559
+ });
560
+ }, [refs.fxInput, setContext]);
561
+ (0, _useRerenderOnFormulaCaret.useRerenderOnFormulaCaret)(refs.fxInput, context.luckysheetCellUpdate.length > 0, refreshFxFormulaRangeHighlights);
512
562
  var getFunctionNameFromInput = (0, _react.useCallback)(function () {
513
563
  var _a, _b, _c, _d;
514
564
  var inputText = ((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText) || "";
@@ -596,11 +646,16 @@ var FxEditor = function FxEditor() {
596
646
  var currentCommaCount = (0, _helper.countCommasBeforeCursor)(editor);
597
647
  setCommaCount(currentCommaCount);
598
648
  setContext(function (draftCtx) {
649
+ var _a;
599
650
  if (draftCtx.formulaCache.rangeSelectionActive !== true) return;
600
651
  var clickedInsideManagedRange = (0, _fortuneCore.getFormulaRangeIndexAtCaret)(editor) !== null;
601
652
  var atValidInsertionPoint = (0, _fortuneCore.isCaretAtValidFormulaRangeInsertionPoint)(editor);
602
653
  if (clickedInsideManagedRange || !atValidInsertionPoint) {
603
654
  (0, _fortuneCore.markRangeSelectionDirty)(draftCtx);
655
+ if ((_a = editor.innerText) === null || _a === void 0 ? void 0 : _a.trim().startsWith("=")) {
656
+ (0, _fortuneCore.createRangeHightlight)(draftCtx, editor.innerHTML);
657
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, editor);
658
+ }
604
659
  }
605
660
  });
606
661
  },
@@ -50,10 +50,11 @@ var ContentEditable = function ContentEditable(_a) {
50
50
  if (root.current != null) {
51
51
  html = root.current.innerHTML;
52
52
  }
53
- if (onChange && html !== lastHtml.current) {
54
- onChange(html || "", isBlur);
53
+ var htmlStr = html || "";
54
+ if (onChange && htmlStr !== lastHtml.current) {
55
+ onChange(htmlStr, isBlur);
55
56
  }
56
- lastHtml.current = html || "";
57
+ lastHtml.current = htmlStr;
57
58
  }, [root, onChange]);
58
59
  var innerRef = props.innerRef,
59
60
  _onBlur = props.onBlur;
@@ -31,6 +31,20 @@ var __assign = void 0 && (void 0).__assign || function () {
31
31
  };
32
32
  return __assign.apply(this, arguments);
33
33
  };
34
+ var CELL_EDIT_INPUT_EXTRA_RIGHT_PX = 10;
35
+ function measureCellEditorContentWidth(el) {
36
+ var _a;
37
+ if (!el) return 0;
38
+ try {
39
+ var range = document.createRange();
40
+ range.selectNodeContents(el);
41
+ var w = range.getBoundingClientRect().width;
42
+ (_a = range.detach) === null || _a === void 0 ? void 0 : _a.call(range);
43
+ return w;
44
+ } catch (_b) {
45
+ return el.scrollWidth;
46
+ }
47
+ }
34
48
  var InputBox = function InputBox() {
35
49
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
36
50
  var _q = (0, _react.useContext)(_context.default),
@@ -80,24 +94,29 @@ var InputBox = function InputBox() {
80
94
  var _1 = (0, _react.useState)(false),
81
95
  showSearchHint = _1[0],
82
96
  setShowSearchHint = _1[1];
97
+ var _2 = (0, _react.useState)(0),
98
+ editorLayoutTick = _2[0],
99
+ setEditorLayoutTick = _2[1];
100
+ var _3 = (0, _react.useState)(false),
101
+ cellEditorExtendRight = _3[0],
102
+ setCellEditorExtendRight = _3[1];
83
103
  var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
84
104
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
85
105
  var isComposingRef = (0, _react.useRef)(false);
86
106
  var formulaAnchorCellRef = (0, _react.useRef)(null);
87
107
  var skipNextAnchorSelectionSyncRef = (0, _react.useRef)(false);
88
108
  var lastHandledMouseDragSignatureRef = (0, _react.useRef)("");
89
- var _2 = (0, _useFormulaEditorHistory.useFormulaEditorHistory)(inputRef, refs.cellInput, refs.fxInput, setContext, "cell"),
90
- formulaHistoryRef = _2.formulaHistoryRef,
91
- preTextRef = _2.preTextRef,
92
- resetFormulaHistory = _2.resetFormulaHistory,
93
- handleFormulaHistoryUndoRedo = _2.handleFormulaHistoryUndoRedo,
94
- capturePreFormulaState = _2.capturePreFormulaState,
95
- appendFormulaHistoryFromPrimaryEditor = _2.appendFormulaHistoryFromPrimaryEditor;
109
+ var _4 = (0, _useFormulaEditorHistory.useFormulaEditorHistory)(inputRef, refs.cellInput, refs.fxInput, setContext, "cell"),
110
+ preTextRef = _4.preTextRef,
111
+ resetFormulaHistory = _4.resetFormulaHistory,
112
+ handleFormulaHistoryUndoRedo = _4.handleFormulaHistoryUndoRedo,
113
+ capturePreEditorHistoryState = _4.capturePreEditorHistoryState,
114
+ appendEditorHistoryFromPrimaryEditor = _4.appendEditorHistoryFromPrimaryEditor;
96
115
  var ZWSP = "\u200B";
97
116
  var inputBoxInnerRef = (0, _react.useRef)(null);
98
- var _3 = (0, _react.useState)([]),
99
- linkSelectionHighlightRects = _3[0],
100
- setLinkSelectionHighlightRects = _3[1];
117
+ var _5 = (0, _react.useState)([]),
118
+ linkSelectionHighlightRects = _5[0],
119
+ setLinkSelectionHighlightRects = _5[1];
101
120
  var ensureNotEmpty = function ensureNotEmpty() {
102
121
  var el = inputRef.current;
103
122
  if (!el) return;
@@ -414,12 +433,25 @@ var InputBox = function InputBox() {
414
433
  });
415
434
  }, [formulaMouseDragSignature, context.formulaCache.func_selectedrange, refs.cellInput, setContext]);
416
435
  var onKeyDown = (0, _react.useCallback)(function (e) {
417
- var _a, _b, _c;
436
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
418
437
  setContext(function (draftCtx) {
419
438
  (0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "cell");
420
439
  });
421
440
  lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
422
- capturePreFormulaState();
441
+ if (!(0, _helper.isEditorUndoRedoKeyEvent)(e.nativeEvent)) {
442
+ capturePreEditorHistoryState();
443
+ }
444
+ var isPotentialContentKey = !e.metaKey && !e.ctrlKey && !e.altKey && (e.key.length === 1 || e.key === "Backspace" || e.key === "Delete" || e.key === "Enter" || e.key === "Tab");
445
+ if (isPotentialContentKey) {
446
+ requestAnimationFrame(function () {
447
+ requestAnimationFrame(function () {
448
+ if ((0, _fortuneCore.getFormulaEditorOwner)(context) !== "cell") return;
449
+ appendEditorHistoryFromPrimaryEditor(function () {
450
+ return (0, _helper.getCursorPosition)(inputRef.current);
451
+ });
452
+ });
453
+ });
454
+ }
423
455
  var currentInputText = ((_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) === null || _b === void 0 ? void 0 : _b.trim()) || "";
424
456
  if ((e.key === "=" || currentInputText.startsWith("=")) && context.luckysheetCellUpdate.length === 2 && formulaAnchorCellRef.current == null) {
425
457
  setContext(function (draftCtx) {
@@ -436,9 +468,9 @@ var InputBox = function InputBox() {
436
468
  setContext(function (draftCtx) {
437
469
  draftCtx.formulaCache.rangeSelectionActive = null;
438
470
  });
439
- var _d = formulaAnchorCellRef.current,
440
- anchorRow_1 = _d[0],
441
- anchorCol_1 = _d[1];
471
+ var _m = formulaAnchorCellRef.current,
472
+ anchorRow_1 = _m[0],
473
+ anchorCol_1 = _m[1];
442
474
  skipNextAnchorSelectionSyncRef.current = true;
443
475
  setTimeout(function () {
444
476
  setContext(function (draftCtx) {
@@ -464,39 +496,93 @@ var InputBox = function InputBox() {
464
496
  }
465
497
  if ((e.metaKey || e.ctrlKey) && context.luckysheetCellUpdate.length > 0) {
466
498
  if (e.code === "KeyZ" || e.code === "KeyY") {
467
- var shouldUseFormulaHistory = currentInputText.startsWith("=") || formulaHistoryRef.current.active;
468
- if (shouldUseFormulaHistory) {
469
- var handledByFormulaHistory = handleFormulaHistoryUndoRedo(e.code === "KeyY" || e.code === "KeyZ" && e.shiftKey);
470
- if (handledByFormulaHistory) {
471
- e.preventDefault();
472
- }
473
- }
499
+ var isRedo_1 = e.code === "KeyY" || e.code === "KeyZ" && e.shiftKey;
500
+ e.preventDefault();
474
501
  e.stopPropagation();
502
+ var _attempt_ = function attempt_1(triesLeft) {
503
+ var handled = handleFormulaHistoryUndoRedo(isRedo_1);
504
+ if (handled) return;
505
+ if (triesLeft <= 0) return;
506
+ requestAnimationFrame(function () {
507
+ requestAnimationFrame(function () {
508
+ return _attempt_(triesLeft - 1);
509
+ });
510
+ });
511
+ };
512
+ _attempt_(2);
475
513
  return;
476
514
  }
477
515
  if (e.code === "KeyB") {
516
+ var beforeHtml_1 = (_d = (_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.innerHTML) !== null && _d !== void 0 ? _d : "";
478
517
  (0, _fortuneCore.handleBold)(context, inputRef.current);
479
- appendFormulaHistoryFromPrimaryEditor(function () {
480
- return (0, _helper.getCursorPosition)(inputRef.current);
481
- });
518
+ var _pushFormattingSnapshot_ = function pushFormattingSnapshot_1(triesLeft) {
519
+ requestAnimationFrame(function () {
520
+ var _a, _b;
521
+ var afterHtml = (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML) !== null && _b !== void 0 ? _b : "";
522
+ if (afterHtml !== beforeHtml_1 || triesLeft <= 0) {
523
+ appendEditorHistoryFromPrimaryEditor(function () {
524
+ return (0, _helper.getCursorPosition)(inputRef.current);
525
+ });
526
+ return;
527
+ }
528
+ _pushFormattingSnapshot_(triesLeft - 1);
529
+ });
530
+ };
531
+ _pushFormattingSnapshot_(2);
482
532
  stopPropagation(e);
483
533
  } else if (e.code === "KeyI") {
534
+ var beforeHtml_2 = (_f = (_e = inputRef.current) === null || _e === void 0 ? void 0 : _e.innerHTML) !== null && _f !== void 0 ? _f : "";
484
535
  (0, _fortuneCore.handleItalic)(context, inputRef.current);
485
- appendFormulaHistoryFromPrimaryEditor(function () {
486
- return (0, _helper.getCursorPosition)(inputRef.current);
487
- });
536
+ var _pushFormattingSnapshot_2 = function pushFormattingSnapshot_2(triesLeft) {
537
+ requestAnimationFrame(function () {
538
+ var _a, _b;
539
+ var afterHtml = (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML) !== null && _b !== void 0 ? _b : "";
540
+ if (afterHtml !== beforeHtml_2 || triesLeft <= 0) {
541
+ appendEditorHistoryFromPrimaryEditor(function () {
542
+ return (0, _helper.getCursorPosition)(inputRef.current);
543
+ });
544
+ return;
545
+ }
546
+ _pushFormattingSnapshot_2(triesLeft - 1);
547
+ });
548
+ };
549
+ _pushFormattingSnapshot_2(2);
488
550
  stopPropagation(e);
489
551
  } else if (e.code === "KeyU") {
552
+ var beforeHtml_3 = (_h = (_g = inputRef.current) === null || _g === void 0 ? void 0 : _g.innerHTML) !== null && _h !== void 0 ? _h : "";
490
553
  (0, _fortuneCore.handleUnderline)(context, inputRef.current);
491
- appendFormulaHistoryFromPrimaryEditor(function () {
492
- return (0, _helper.getCursorPosition)(inputRef.current);
493
- });
554
+ var _pushFormattingSnapshot_3 = function pushFormattingSnapshot_3(triesLeft) {
555
+ requestAnimationFrame(function () {
556
+ var _a, _b;
557
+ var afterHtml = (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML) !== null && _b !== void 0 ? _b : "";
558
+ if (afterHtml !== beforeHtml_3 || triesLeft <= 0) {
559
+ appendEditorHistoryFromPrimaryEditor(function () {
560
+ return (0, _helper.getCursorPosition)(inputRef.current);
561
+ });
562
+ return;
563
+ }
564
+ _pushFormattingSnapshot_3(triesLeft - 1);
565
+ });
566
+ };
567
+ _pushFormattingSnapshot_3(2);
494
568
  stopPropagation(e);
495
569
  } else if (e.code === "KeyS") {
570
+ var beforeHtml_4 = (_k = (_j = inputRef.current) === null || _j === void 0 ? void 0 : _j.innerHTML) !== null && _k !== void 0 ? _k : "";
496
571
  (0, _fortuneCore.handleStrikeThrough)(context, inputRef.current);
497
- appendFormulaHistoryFromPrimaryEditor(function () {
498
- return (0, _helper.getCursorPosition)(inputRef.current);
499
- });
572
+ var _pushFormattingSnapshot_4 = function pushFormattingSnapshot_4(triesLeft) {
573
+ requestAnimationFrame(function () {
574
+ var _a, _b;
575
+ var afterHtml = (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML) !== null && _b !== void 0 ? _b : "";
576
+ if (afterHtml !== beforeHtml_4 || triesLeft <= 0) {
577
+ appendEditorHistoryFromPrimaryEditor(function () {
578
+ return (0, _helper.getCursorPosition)(inputRef.current);
579
+ });
580
+ return;
581
+ }
582
+ _pushFormattingSnapshot_4(triesLeft - 1);
583
+ });
584
+ };
585
+ _pushFormattingSnapshot_4(2);
500
586
  stopPropagation(e);
501
587
  }
502
588
  }
@@ -506,7 +592,7 @@ var InputBox = function InputBox() {
506
592
  }
507
593
  var allowListNavigation = true;
508
594
  var isArrowKey = e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight";
509
- var isInPlaceEditMode = ((_c = refs.globalCache) === null || _c === void 0 ? void 0 : _c.enteredEditByTyping) !== true;
595
+ var isInPlaceEditMode = ((_l = refs.globalCache) === null || _l === void 0 ? void 0 : _l.enteredEditByTyping) !== true;
510
596
  if (e.key === "Delete" || e.key === "Backspace") {
511
597
  var anchor = formulaAnchorCellRef.current;
512
598
  if (anchor != null) {
@@ -595,7 +681,7 @@ var InputBox = function InputBox() {
595
681
  }
596
682
  e.preventDefault();
597
683
  }
598
- }, [capturePreFormulaState, clearSearchItemActiveClass, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, selectActiveFormula, setContext, firstSelection, refs.cellInput]);
684
+ }, [capturePreEditorHistoryState, clearSearchItemActiveClass, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, selectActiveFormula, setContext, firstSelection, refs.cellInput]);
599
685
  var handleHideShowHint = function handleHideShowHint() {
600
686
  var _a, _b, _c, _d;
601
687
  var searchElFx = (_a = document.getElementsByClassName("fx-search")) === null || _a === void 0 ? void 0 : _a[0];
@@ -637,11 +723,11 @@ var InputBox = function InputBox() {
637
723
  }
638
724
  return;
639
725
  }
726
+ if ((0, _helper.isEditorUndoRedoKeyEvent)(e)) {
727
+ return;
728
+ }
640
729
  var kcode = e.keyCode;
641
730
  if (!kcode) return;
642
- appendFormulaHistoryFromPrimaryEditor(function () {
643
- return (0, _helper.getCursorPosition)(inputRef.current);
644
- });
645
731
  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) {
646
732
  setContext(function (draftCtx) {
647
733
  var _a, _b;
@@ -656,7 +742,13 @@ var InputBox = function InputBox() {
656
742
  }
657
743
  });
658
744
  }
659
- }, [refs.cellInput, refs.fxInput, setContext, appendFormulaHistoryFromPrimaryEditor]);
745
+ requestAnimationFrame(function () {
746
+ if ((0, _fortuneCore.getFormulaEditorOwner)(context) !== "cell") return;
747
+ appendEditorHistoryFromPrimaryEditor(function () {
748
+ return (0, _helper.getCursorPosition)(inputRef.current);
749
+ });
750
+ });
751
+ }, [refs.cellInput, refs.fxInput, setContext, appendEditorHistoryFromPrimaryEditor]);
660
752
  var onPaste = (0, _react.useCallback)(function (e) {
661
753
  var plainText = e.clipboardData.getData("text/plain");
662
754
  e.preventDefault();
@@ -677,6 +769,19 @@ var InputBox = function InputBox() {
677
769
  var rowReadOnly = cfg.rowReadOnly || {};
678
770
  var colReadOnly = cfg.colReadOnly || {};
679
771
  var edit = !((colReadOnly[col_index] || rowReadOnly[row_index]) && context.allowEdit === true);
772
+ var onInputBoxInnerMouseDown = (0, _react.useCallback)(function (e) {
773
+ if (!edit || isHidenRC || context.luckysheetCellUpdate.length === 0) {
774
+ return;
775
+ }
776
+ var editor = refs.cellInput.current;
777
+ if (!editor) return;
778
+ if (editor.contains(e.target)) return;
779
+ e.preventDefault();
780
+ (0, _helper.moveCursorToEnd)(editor);
781
+ setContext(function (draftCtx) {
782
+ (0, _fortuneCore.setFormulaEditorOwner)(draftCtx, "cell");
783
+ });
784
+ }, [edit, isHidenRC, context.luckysheetCellUpdate.length, refs.cellInput, setContext]);
680
785
  var getInputBoxPosition = (0, _react.useCallback)(function () {
681
786
  var _a;
682
787
  if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
@@ -814,6 +919,20 @@ var InputBox = function InputBox() {
814
919
  });
815
920
  setLinkSelectionHighlightRects(relative);
816
921
  }, [(_h = context.linkCard) === null || _h === void 0 ? void 0 : _h.applyToSelection, (_j = context.linkCard) === null || _j === void 0 ? void 0 : _j.selectionOffsets, (_k = context.linkCard) === null || _k === void 0 ? void 0 : _k.r, (_l = context.linkCard) === null || _l === void 0 ? void 0 : _l.c, context.luckysheetCellUpdate]);
922
+ (0, _react.useLayoutEffect)(function () {
923
+ if (context.luckysheetCellUpdate.length === 0) {
924
+ setCellEditorExtendRight(false);
925
+ return;
926
+ }
927
+ var baseSel = isInputBoxActive && firstSelectionActiveCell ? firstSelectionActiveCell : firstSelection;
928
+ var cellW = baseSel === null || baseSel === void 0 ? void 0 : baseSel.width;
929
+ if (cellW == null || !inputRef.current) {
930
+ setCellEditorExtendRight(false);
931
+ return;
932
+ }
933
+ var contentW = measureCellEditorContentWidth(inputRef.current);
934
+ setCellEditorExtendRight(contentW + CELL_EDIT_INPUT_EXTRA_RIGHT_PX > cellW);
935
+ }, [editorLayoutTick, context.luckysheetCellUpdate.length, isInputBoxActive, firstSelectionActiveCell, firstSelection, context.zoomRatio]);
817
936
  var wraperGetCell = function wraperGetCell() {
818
937
  var cell = getCellAddress();
819
938
  if (activeRefCell !== cell) {
@@ -821,7 +940,26 @@ var InputBox = function InputBox() {
821
940
  }
822
941
  return activeCell || cell;
823
942
  };
824
- (0, _useRerenderOnFormulaCaret.useRerenderOnFormulaCaret)(inputRef, context.luckysheetCellUpdate.length > 0);
943
+ var refreshCellFormulaRangeHighlights = (0, _react.useCallback)(function () {
944
+ var el = inputRef.current;
945
+ if (!el) return;
946
+ setContext(function (draftCtx) {
947
+ var _a, _b;
948
+ if (draftCtx.luckysheetCellUpdate.length === 0) return;
949
+ if ((0, _fortuneCore.getFormulaEditorOwner)(draftCtx) !== "cell") return;
950
+ if (!(0, _fortuneCore.isAllowEdit)(draftCtx, draftCtx.luckysheet_select_save)) return;
951
+ var t = (_b = (_a = el.innerText) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
952
+ if (!t.startsWith("=")) return;
953
+ if (draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start) {
954
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, el);
955
+ return;
956
+ }
957
+ draftCtx.formulaCache.selectingRangeIndex = -1;
958
+ (0, _fortuneCore.createRangeHightlight)(draftCtx, el.innerHTML);
959
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, el);
960
+ });
961
+ }, [setContext]);
962
+ (0, _useRerenderOnFormulaCaret.useRerenderOnFormulaCaret)(inputRef, context.luckysheetCellUpdate.length > 0, refreshCellFormulaRangeHighlights);
825
963
  var getFunctionNameFromInput = (0, _react.useCallback)(function () {
826
964
  var _a, _b;
827
965
  var inputText = ((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) || "";
@@ -858,11 +996,14 @@ var InputBox = function InputBox() {
858
996
  }, wraperGetCell())), /*#__PURE__*/_react.default.createElement("div", {
859
997
  ref: inputBoxInnerRef,
860
998
  className: "luckysheet-input-box-inner",
861
- style: inputBoxBaseSelection ? __assign({
999
+ onMouseDown: onInputBoxInnerMouseDown,
1000
+ style: inputBoxBaseSelection ? __assign(__assign({
862
1001
  position: "relative",
863
1002
  minWidth: inputBoxBaseSelection.width,
864
1003
  minHeight: inputBoxBaseSelection.height
865
- }, inputBoxStyle) : {
1004
+ }, inputBoxStyle), cellEditorExtendRight ? {
1005
+ paddingRight: 2 + CELL_EDIT_INPUT_EXTRA_RIGHT_PX
1006
+ } : {}) : {
866
1007
  position: "relative"
867
1008
  }
868
1009
  }, /*#__PURE__*/_react.default.createElement(_ContentEditable.default, {
@@ -879,6 +1020,9 @@ var InputBox = function InputBox() {
879
1020
  }
880
1021
  ensureNotEmpty();
881
1022
  isComposingRef.current = false;
1023
+ setEditorLayoutTick(function (t) {
1024
+ return t + 1;
1025
+ });
882
1026
  },
883
1027
  onMouseUp: function onMouseUp() {
884
1028
  handleHideShowHint();
@@ -892,11 +1036,16 @@ var InputBox = function InputBox() {
892
1036
  var editor = inputRef.current;
893
1037
  if (!editor) return;
894
1038
  setContext(function (draftCtx) {
1039
+ var _a;
895
1040
  if (draftCtx.formulaCache.rangeSelectionActive !== true) return;
896
1041
  var clickedInsideManagedRange = (0, _fortuneCore.getFormulaRangeIndexAtCaret)(editor) !== null;
897
1042
  var atValidInsertionPoint = (0, _fortuneCore.isCaretAtValidFormulaRangeInsertionPoint)(editor);
898
1043
  if (clickedInsideManagedRange || !atValidInsertionPoint) {
899
1044
  (0, _fortuneCore.markRangeSelectionDirty)(draftCtx);
1045
+ if ((_a = editor.innerText) === null || _a === void 0 ? void 0 : _a.trim().startsWith("=")) {
1046
+ (0, _fortuneCore.createRangeHightlight)(draftCtx, editor.innerHTML);
1047
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, editor);
1048
+ }
900
1049
  }
901
1050
  });
902
1051
  },
@@ -18,31 +18,6 @@ var __spreadArray = void 0 && (void 0).__spreadArray || function (to, from, pack
18
18
  }
19
19
  return to.concat(ar || Array.prototype.slice.call(from));
20
20
  };
21
- var REF_TOKEN_REGEX = /((?:'(?:[^']|'')+'|[A-Za-z_][A-Za-z0-9_.]*)!)?(\$?)([A-Za-z]+)(\$?)(\d+)(?::(\$?)([A-Za-z]+)(\$?)(\d+))?/g;
22
- function normalizeSheetName(raw) {
23
- if (!raw) return "";
24
- var noBang = raw.endsWith("!") ? raw.slice(0, -1) : raw;
25
- if (noBang.startsWith("'") && noBang.endsWith("'")) {
26
- return noBang.slice(1, -1).replace(/''/g, "'");
27
- }
28
- return noBang;
29
- }
30
- function remapFormulaCols(formula, formulaSheetName, movedSheetName, colMap) {
31
- return formula.replace(REF_TOKEN_REGEX, function (token, sheetPrefix, colAbs0, col0, rowAbs0, row0, colAbs1, col1, rowAbs1, row1) {
32
- var refSheet = normalizeSheetName(sheetPrefix) || formulaSheetName;
33
- if (refSheet !== movedSheetName) return token;
34
- var colIdx0 = (0, _fortuneCore.columnCharToIndex)(col0);
35
- var mapped0 = colMap[colIdx0];
36
- var nextCol0 = mapped0 == null ? col0 : (0, _fortuneCore.indexToColumnChar)(mapped0);
37
- if (!col1) {
38
- return "".concat(sheetPrefix || "").concat(colAbs0).concat(nextCol0).concat(rowAbs0).concat(row0);
39
- }
40
- var colIdx1 = (0, _fortuneCore.columnCharToIndex)(col1);
41
- var mapped1 = colMap[colIdx1];
42
- var nextCol1 = mapped1 == null ? col1 : (0, _fortuneCore.indexToColumnChar)(mapped1);
43
- return "".concat(sheetPrefix || "").concat(colAbs0).concat(nextCol0).concat(rowAbs0).concat(row0, ":").concat(colAbs1).concat(nextCol1).concat(rowAbs1).concat(row1);
44
- });
45
- }
46
21
  function numberToColumnName(num) {
47
22
  return (0, _fortuneCore.indexToColumnChar)(num);
48
23
  }
@@ -307,7 +282,9 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
307
282
  }
308
283
  if (cell.f) {
309
284
  var sheetName = _sheet.name || "";
310
- cell.f = remapFormulaCols(cell.f, sheetName, sheetName, colMap_1);
285
+ cell.f = (0, _fortuneCore.remapFormulaReferencesByMap)(cell.f, sheetName, sheetName, {
286
+ colMap: colMap_1
287
+ });
311
288
  }
312
289
  }
313
290
  });
@@ -17,29 +17,6 @@ var __spreadArray = void 0 && (void 0).__spreadArray || function (to, from, pack
17
17
  }
18
18
  return to.concat(ar || Array.prototype.slice.call(from));
19
19
  };
20
- var REF_TOKEN_REGEX = /((?:'(?:[^']|'')+'|[A-Za-z_][A-Za-z0-9_.]*)!)?(\$?)([A-Za-z]+)(\$?)(\d+)(?::(\$?)([A-Za-z]+)(\$?)(\d+))?/g;
21
- function normalizeSheetName(raw) {
22
- if (!raw) return "";
23
- var noBang = raw.endsWith("!") ? raw.slice(0, -1) : raw;
24
- if (noBang.startsWith("'") && noBang.endsWith("'")) {
25
- return noBang.slice(1, -1).replace(/''/g, "'");
26
- }
27
- return noBang;
28
- }
29
- function remapFormulaRows(formula, formulaSheetName, movedSheetName, rowMap) {
30
- return formula.replace(REF_TOKEN_REGEX, function (token, sheetPrefix, colAbs0, col0, rowAbs0, row0, colAbs1, col1, rowAbs1, row1) {
31
- var refSheet = normalizeSheetName(sheetPrefix) || formulaSheetName;
32
- if (refSheet !== movedSheetName) return token;
33
- var mapped0 = rowMap[parseInt(row0, 10) - 1];
34
- var nextRow0 = mapped0 == null ? parseInt(row0, 10) : mapped0 + 1;
35
- if (!row1) {
36
- return "".concat(sheetPrefix || "").concat(colAbs0).concat(col0).concat(rowAbs0).concat(nextRow0);
37
- }
38
- var mapped1 = rowMap[parseInt(row1, 10) - 1];
39
- var nextRow1 = mapped1 == null ? parseInt(row1, 10) : mapped1 + 1;
40
- return "".concat(sheetPrefix || "").concat(colAbs0).concat(col0).concat(rowAbs0).concat(nextRow0, ":").concat(colAbs1).concat(col1).concat(rowAbs1).concat(nextRow1);
41
- });
42
- }
43
20
  var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(containerRef, selectedLocationRef) {
44
21
  var DOUBLE_MS = 300;
45
22
  var START_DRAG_THRESHOLD_PX = 6;
@@ -300,7 +277,9 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
300
277
  }
301
278
  if (cell.f) {
302
279
  var sheetName = _sheet.name || "";
303
- cell.f = remapFormulaRows(cell.f, sheetName, sheetName, rowMap_1);
280
+ cell.f = (0, _fortuneCore.remapFormulaReferencesByMap)(cell.f, sheetName, sheetName, {
281
+ rowMap: rowMap_1
282
+ });
304
283
  }
305
284
  }
306
285
  });
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isFormulaSegmentBoundaryKey = isFormulaSegmentBoundaryKey;
7
- var FORMULA_SEGMENT_BOUNDARY_KEYS = new Set([",", "+", "-", "*", "/", "%", "^", "&"]);
7
+ var FORMULA_SEGMENT_BOUNDARY_KEYS = new Set([",", "+", "-", "*", "/", "%", "^", "&", ">", "<", ")"]);
8
8
  function isFormulaSegmentBoundaryKey(key) {
9
9
  return FORMULA_SEGMENT_BOUNDARY_KEYS.has(key);
10
10
  }
@@ -1,6 +1,13 @@
1
1
  export declare function moveCursorToEnd(editableDiv: HTMLDivElement): void;
2
2
  export declare function getCursorPosition(editableDiv: HTMLDivElement): number;
3
+ export declare function getSelectionOffsets(editableDiv: HTMLDivElement): {
4
+ start: number;
5
+ end: number;
6
+ };
7
+ export declare function isEditorUndoRedoKeyEvent(e: KeyboardEvent): boolean;
8
+ export declare function shouldUseCustomEditorHistory(editorInnerTextTrimmed: string, historyActive: boolean): boolean;
3
9
  export declare function setCursorPosition(editableDiv: HTMLDivElement, targetOffset: number): void;
10
+ export declare function setSelectionOffsets(editableDiv: HTMLDivElement, startOffset: number, endOffset: number): void;
4
11
  export declare function buildFormulaSuggestionText(editableDiv: HTMLDivElement, formulaName: string): {
5
12
  text: string;
6
13
  caretOffset: number;