@fileverse-dev/fortune-react 1.1.53 → 1.1.54-patch-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,39 +16,39 @@ import ContentEditable from "./ContentEditable";
16
16
  import FormulaSearch from "./FormulaSearch";
17
17
  import FormulaHint from "./FormulaHint";
18
18
  import usePrevious from "../../hooks/usePrevious";
19
- import { moveCursorToEnd, isLetterNumberPattern, removeLastSpan, incrementColumn, decrementColumn, incrementRow, decrementRow } from "./helper";
19
+ import { moveCursorToEnd, getCursorPosition, isLetterNumberPattern, removeLastSpan, incrementColumn, decrementColumn, incrementRow, decrementRow } from "./helper";
20
20
  var InputBox = function InputBox() {
21
- var _a, _b, _c, _d, _e, _f;
22
- var _g = useContext(WorkbookContext),
23
- context = _g.context,
24
- setContext = _g.setContext,
25
- refs = _g.refs;
21
+ var _a, _b, _c, _d, _e, _f, _g;
22
+ var _h = useContext(WorkbookContext),
23
+ context = _h.context,
24
+ setContext = _h.setContext,
25
+ refs = _h.refs;
26
26
  var inputRef = useRef(null);
27
27
  var lastKeyDownEventRef = useRef(null);
28
28
  var prevCellUpdate = usePrevious(context.luckysheetCellUpdate);
29
29
  var prevSheetId = usePrevious(context.currentSheetId);
30
- var _h = useState(false),
31
- isHidenRC = _h[0],
32
- setIsHidenRC = _h[1];
33
30
  var _j = useState(false),
34
- isInputBoxActive = _j[0],
35
- setIsInputBoxActive = _j[1];
36
- var _k = useState(""),
37
- activeCell = _k[0],
38
- setActiveCell = _k[1];
31
+ isHidenRC = _j[0],
32
+ setIsHidenRC = _j[1];
33
+ var _k = useState(false),
34
+ isInputBoxActive = _k[0],
35
+ setIsInputBoxActive = _k[1];
39
36
  var _l = useState(""),
40
- activeRefCell = _l[0],
41
- setActiveRefCell = _l[1];
42
- var _m = useState({
37
+ activeCell = _l[0],
38
+ setActiveCell = _l[1];
39
+ var _m = useState(""),
40
+ activeRefCell = _m[0],
41
+ setActiveRefCell = _m[1];
42
+ var _o = useState({
43
43
  left: 0,
44
44
  top: 0
45
45
  }),
46
- frozenPosition = _m[0],
47
- setFrozenPosition = _m[1];
46
+ frozenPosition = _o[0],
47
+ setFrozenPosition = _o[1];
48
48
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
49
- var _o = useState({}),
50
- firstSelectionActiveCell = _o[0],
51
- setFirstSelectionActiveCell = _o[1];
49
+ var _p = useState({}),
50
+ firstSelectionActiveCell = _p[0],
51
+ setFirstSelectionActiveCell = _p[1];
52
52
  var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
53
53
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
54
54
  var preText = useRef("");
@@ -67,7 +67,7 @@ var InputBox = function InputBox() {
67
67
  return style;
68
68
  }
69
69
  return {};
70
- }, [context.luckysheetfile, context.currentSheetId, context.luckysheetCellUpdate, firstSelectionActiveCell]);
70
+ }, [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]);
71
71
  useLayoutEffect(function () {
72
72
  var _a;
73
73
  if (!context.allowEdit) {
@@ -131,7 +131,7 @@ var InputBox = function InputBox() {
131
131
  if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) || _.isEmpty(context.luckysheetCellUpdate)) {
132
132
  setIsInputBoxActive(false);
133
133
  }
134
- }, [firstSelection, (_b = context.rangeDialog) === null || _b === void 0 ? void 0 : _b.show, context.luckysheetCellUpdate]);
134
+ }, [firstSelection, (_c = context.rangeDialog) === null || _c === void 0 ? void 0 : _c.show, context.luckysheetCellUpdate]);
135
135
  var getActiveFormula = useCallback(function () {
136
136
  return document.querySelector(".luckysheet-formula-search-item-active");
137
137
  }, []);
@@ -141,6 +141,11 @@ var InputBox = function InputBox() {
141
141
  var ht = "<span dir=\"auto\" class=\"luckysheet-formula-text-color\">=</span><span dir=\"auto\" class=\"luckysheet-formula-text-func\">".concat(formulaName, "</span><span dir=\"auto\" class=\"luckysheet-formula-text-lpar\">(</span>");
142
142
  inputRef.current.innerHTML = ht;
143
143
  moveCursorToEnd(inputRef.current);
144
+ setContext(function (draftCtx) {
145
+ draftCtx.functionCandidates = [];
146
+ draftCtx.defaultCandidates = [];
147
+ draftCtx.functionHint = formulaName;
148
+ });
144
149
  return;
145
150
  }
146
151
  var textEditor = document.getElementById("luckysheet-rich-text-editor");
@@ -215,6 +220,11 @@ var InputBox = function InputBox() {
215
220
  lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
216
221
  preText.current = inputRef.current.innerText;
217
222
  var allowListNavigation = true;
223
+ if ((e.key === "Delete" || e.key === "Backspace") && getCursorPosition(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
224
+ setTimeout(function () {
225
+ moveCursorToEnd(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
226
+ }, 5);
227
+ }
218
228
  var refCell = placeRef.current;
219
229
  if (e.key === "ArrowUp") {
220
230
  refCell = decrementRow(placeRef.current);
@@ -225,7 +235,7 @@ var InputBox = function InputBox() {
225
235
  } else if (e.key === "ArrowRight") {
226
236
  refCell = incrementColumn(placeRef.current);
227
237
  }
228
- if (e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight") {
238
+ if ((e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight") && !(getCursorPosition(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) !== (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length) && e.key === "ArrowRight")) {
229
239
  var parser = new DOMParser();
230
240
  var doc = parser.parseFromString("<div>".concat((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML, "</div>"), "text/html");
231
241
  var spans = doc.querySelectorAll("span");
@@ -362,7 +372,7 @@ var InputBox = function InputBox() {
362
372
  zIndex: _.isEmpty(context.luckysheetCellUpdate) ? -1 : 19,
363
373
  display: "block"
364
374
  };
365
- }, [firstSelection, (_c = context.rangeDialog) === null || _c === void 0 ? void 0 : _c.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
375
+ }, [firstSelection, (_d = context.rangeDialog) === null || _d === void 0 ? void 0 : _d.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
366
376
  useEffect(function () {
367
377
  var _a;
368
378
  if (firstSelection && !((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) && !isInputBoxActive && !_.isEmpty(context.luckysheetCellUpdate)) {
@@ -378,7 +388,7 @@ var InputBox = function InputBox() {
378
388
  setIsInputBoxActive(true);
379
389
  }
380
390
  }
381
- }, [firstSelection, (_d = context.rangeDialog) === null || _d === void 0 ? void 0 : _d.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
391
+ }, [firstSelection, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
382
392
  var getAddressIndicatorPosition = useCallback(function () {
383
393
  var _a;
384
394
  if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
@@ -391,7 +401,7 @@ var InputBox = function InputBox() {
391
401
  left: "0",
392
402
  display: "block"
393
403
  };
394
- }, [firstSelection, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show]);
404
+ }, [firstSelection, (_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show]);
395
405
  var getCellAddress = useCallback(function () {
396
406
  if (!firstSelection) return "";
397
407
  var rowIndex = firstSelection.row_focus || 0;
@@ -424,7 +434,7 @@ var InputBox = function InputBox() {
424
434
  onMouseUp: function onMouseUp(e) {
425
435
  return e.stopPropagation();
426
436
  }
427
- }, firstSelection && !((_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show) && (/*#__PURE__*/React.createElement("div", {
437
+ }, firstSelection && !((_g = context.rangeDialog) === null || _g === void 0 ? void 0 : _g.show) && (/*#__PURE__*/React.createElement("div", {
428
438
  className: "luckysheet-cell-address-indicator",
429
439
  style: getAddressIndicatorPosition()
430
440
  }, wraperGetCell())), /*#__PURE__*/React.createElement("div", {
@@ -1,4 +1,5 @@
1
1
  export declare function moveCursorToEnd(editableDiv: HTMLDivElement): void;
2
+ export declare function getCursorPosition(editableDiv: HTMLDivElement): number;
2
3
  export declare function isLetterNumberPattern(str: string): boolean;
3
4
  export declare function removeLastSpan(htmlString: string): string;
4
5
  export declare function incrementColumn(cell: string): string;
@@ -9,6 +9,15 @@ export function moveCursorToEnd(editableDiv) {
9
9
  selection.addRange(range);
10
10
  }
11
11
  }
12
+ export function getCursorPosition(editableDiv) {
13
+ var selection = window.getSelection();
14
+ if (!selection || selection.rangeCount === 0) return 0;
15
+ var range = selection.getRangeAt(0);
16
+ var preRange = range.cloneRange();
17
+ preRange.selectNodeContents(editableDiv);
18
+ preRange.setEnd(range.endContainer, range.endOffset);
19
+ return preRange.toString().length;
20
+ }
12
21
  export function isLetterNumberPattern(str) {
13
22
  var regex = /^[a-zA-Z]+\d+$/;
14
23
  return regex.test(str);
@@ -27,37 +27,37 @@ var __assign = void 0 && (void 0).__assign || function () {
27
27
  return __assign.apply(this, arguments);
28
28
  };
29
29
  var InputBox = function InputBox() {
30
- var _a, _b, _c, _d, _e, _f;
31
- var _g = (0, _react.useContext)(_context.default),
32
- context = _g.context,
33
- setContext = _g.setContext,
34
- refs = _g.refs;
30
+ var _a, _b, _c, _d, _e, _f, _g;
31
+ var _h = (0, _react.useContext)(_context.default),
32
+ context = _h.context,
33
+ setContext = _h.setContext,
34
+ refs = _h.refs;
35
35
  var inputRef = (0, _react.useRef)(null);
36
36
  var lastKeyDownEventRef = (0, _react.useRef)(null);
37
37
  var prevCellUpdate = (0, _usePrevious.default)(context.luckysheetCellUpdate);
38
38
  var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
39
- var _h = (0, _react.useState)(false),
40
- isHidenRC = _h[0],
41
- setIsHidenRC = _h[1];
42
39
  var _j = (0, _react.useState)(false),
43
- isInputBoxActive = _j[0],
44
- setIsInputBoxActive = _j[1];
45
- var _k = (0, _react.useState)(""),
46
- activeCell = _k[0],
47
- setActiveCell = _k[1];
40
+ isHidenRC = _j[0],
41
+ setIsHidenRC = _j[1];
42
+ var _k = (0, _react.useState)(false),
43
+ isInputBoxActive = _k[0],
44
+ setIsInputBoxActive = _k[1];
48
45
  var _l = (0, _react.useState)(""),
49
- activeRefCell = _l[0],
50
- setActiveRefCell = _l[1];
51
- var _m = (0, _react.useState)({
46
+ activeCell = _l[0],
47
+ setActiveCell = _l[1];
48
+ var _m = (0, _react.useState)(""),
49
+ activeRefCell = _m[0],
50
+ setActiveRefCell = _m[1];
51
+ var _o = (0, _react.useState)({
52
52
  left: 0,
53
53
  top: 0
54
54
  }),
55
- frozenPosition = _m[0],
56
- setFrozenPosition = _m[1];
55
+ frozenPosition = _o[0],
56
+ setFrozenPosition = _o[1];
57
57
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
58
- var _o = (0, _react.useState)({}),
59
- firstSelectionActiveCell = _o[0],
60
- setFirstSelectionActiveCell = _o[1];
58
+ var _p = (0, _react.useState)({}),
59
+ firstSelectionActiveCell = _p[0],
60
+ setFirstSelectionActiveCell = _p[1];
61
61
  var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
62
62
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
63
63
  var preText = (0, _react.useRef)("");
@@ -76,7 +76,7 @@ var InputBox = function InputBox() {
76
76
  return style;
77
77
  }
78
78
  return {};
79
- }, [context.luckysheetfile, context.currentSheetId, context.luckysheetCellUpdate, firstSelectionActiveCell]);
79
+ }, [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]);
80
80
  (0, _react.useLayoutEffect)(function () {
81
81
  var _a;
82
82
  if (!context.allowEdit) {
@@ -140,7 +140,7 @@ var InputBox = function InputBox() {
140
140
  if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) || _lodash.default.isEmpty(context.luckysheetCellUpdate)) {
141
141
  setIsInputBoxActive(false);
142
142
  }
143
- }, [firstSelection, (_b = context.rangeDialog) === null || _b === void 0 ? void 0 : _b.show, context.luckysheetCellUpdate]);
143
+ }, [firstSelection, (_c = context.rangeDialog) === null || _c === void 0 ? void 0 : _c.show, context.luckysheetCellUpdate]);
144
144
  var getActiveFormula = (0, _react.useCallback)(function () {
145
145
  return document.querySelector(".luckysheet-formula-search-item-active");
146
146
  }, []);
@@ -150,6 +150,11 @@ var InputBox = function InputBox() {
150
150
  var ht = "<span dir=\"auto\" class=\"luckysheet-formula-text-color\">=</span><span dir=\"auto\" class=\"luckysheet-formula-text-func\">".concat(formulaName, "</span><span dir=\"auto\" class=\"luckysheet-formula-text-lpar\">(</span>");
151
151
  inputRef.current.innerHTML = ht;
152
152
  (0, _helper.moveCursorToEnd)(inputRef.current);
153
+ setContext(function (draftCtx) {
154
+ draftCtx.functionCandidates = [];
155
+ draftCtx.defaultCandidates = [];
156
+ draftCtx.functionHint = formulaName;
157
+ });
153
158
  return;
154
159
  }
155
160
  var textEditor = document.getElementById("luckysheet-rich-text-editor");
@@ -224,6 +229,11 @@ var InputBox = function InputBox() {
224
229
  lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
225
230
  preText.current = inputRef.current.innerText;
226
231
  var allowListNavigation = true;
232
+ if ((e.key === "Delete" || e.key === "Backspace") && (0, _helper.getCursorPosition)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
233
+ setTimeout(function () {
234
+ (0, _helper.moveCursorToEnd)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
235
+ }, 5);
236
+ }
227
237
  var refCell = placeRef.current;
228
238
  if (e.key === "ArrowUp") {
229
239
  refCell = (0, _helper.decrementRow)(placeRef.current);
@@ -234,7 +244,7 @@ var InputBox = function InputBox() {
234
244
  } else if (e.key === "ArrowRight") {
235
245
  refCell = (0, _helper.incrementColumn)(placeRef.current);
236
246
  }
237
- if (e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight") {
247
+ if ((e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight") && !((0, _helper.getCursorPosition)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) !== (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length) && e.key === "ArrowRight")) {
238
248
  var parser = new DOMParser();
239
249
  var doc = parser.parseFromString("<div>".concat((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML, "</div>"), "text/html");
240
250
  var spans = doc.querySelectorAll("span");
@@ -371,7 +381,7 @@ var InputBox = function InputBox() {
371
381
  zIndex: _lodash.default.isEmpty(context.luckysheetCellUpdate) ? -1 : 19,
372
382
  display: "block"
373
383
  };
374
- }, [firstSelection, (_c = context.rangeDialog) === null || _c === void 0 ? void 0 : _c.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
384
+ }, [firstSelection, (_d = context.rangeDialog) === null || _d === void 0 ? void 0 : _d.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
375
385
  (0, _react.useEffect)(function () {
376
386
  var _a;
377
387
  if (firstSelection && !((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) && !isInputBoxActive && !_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
@@ -387,7 +397,7 @@ var InputBox = function InputBox() {
387
397
  setIsInputBoxActive(true);
388
398
  }
389
399
  }
390
- }, [firstSelection, (_d = context.rangeDialog) === null || _d === void 0 ? void 0 : _d.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
400
+ }, [firstSelection, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
391
401
  var getAddressIndicatorPosition = (0, _react.useCallback)(function () {
392
402
  var _a;
393
403
  if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
@@ -400,7 +410,7 @@ var InputBox = function InputBox() {
400
410
  left: "0",
401
411
  display: "block"
402
412
  };
403
- }, [firstSelection, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show]);
413
+ }, [firstSelection, (_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show]);
404
414
  var getCellAddress = (0, _react.useCallback)(function () {
405
415
  if (!firstSelection) return "";
406
416
  var rowIndex = firstSelection.row_focus || 0;
@@ -433,7 +443,7 @@ var InputBox = function InputBox() {
433
443
  onMouseUp: function onMouseUp(e) {
434
444
  return e.stopPropagation();
435
445
  }
436
- }, firstSelection && !((_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show) && (/*#__PURE__*/_react.default.createElement("div", {
446
+ }, firstSelection && !((_g = context.rangeDialog) === null || _g === void 0 ? void 0 : _g.show) && (/*#__PURE__*/_react.default.createElement("div", {
437
447
  className: "luckysheet-cell-address-indicator",
438
448
  style: getAddressIndicatorPosition()
439
449
  }, wraperGetCell())), /*#__PURE__*/_react.default.createElement("div", {
@@ -1,4 +1,5 @@
1
1
  export declare function moveCursorToEnd(editableDiv: HTMLDivElement): void;
2
+ export declare function getCursorPosition(editableDiv: HTMLDivElement): number;
2
3
  export declare function isLetterNumberPattern(str: string): boolean;
3
4
  export declare function removeLastSpan(htmlString: string): string;
4
5
  export declare function incrementColumn(cell: string): string;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.decrementColumn = decrementColumn;
7
7
  exports.decrementRow = decrementRow;
8
+ exports.getCursorPosition = getCursorPosition;
8
9
  exports.incrementColumn = incrementColumn;
9
10
  exports.incrementRow = incrementRow;
10
11
  exports.isLetterNumberPattern = isLetterNumberPattern;
@@ -21,6 +22,15 @@ function moveCursorToEnd(editableDiv) {
21
22
  selection.addRange(range);
22
23
  }
23
24
  }
25
+ function getCursorPosition(editableDiv) {
26
+ var selection = window.getSelection();
27
+ if (!selection || selection.rangeCount === 0) return 0;
28
+ var range = selection.getRangeAt(0);
29
+ var preRange = range.cloneRange();
30
+ preRange.selectNodeContents(editableDiv);
31
+ preRange.setEnd(range.endContainer, range.endOffset);
32
+ return preRange.toString().length;
33
+ }
24
34
  function isLetterNumberPattern(str) {
25
35
  var regex = /^[a-zA-Z]+\d+$/;
26
36
  return regex.test(str);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.1.53",
3
+ "version": "1.1.54-patch-1",
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.1.53",
19
+ "@fileverse-dev/fortune-core": "^1.1.54",
20
20
  "@fileverse/ui": "^4.1.7-patch-21",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",