@fileverse-dev/fortune-react 1.2.89-mobile-1 → 1.2.90

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.
@@ -8,7 +8,7 @@ var __assign = this && this.__assign || function () {
8
8
  };
9
9
  return __assign.apply(this, arguments);
10
10
  };
11
- import { cancelNormalSelected, getCellValue, getInlineStringHTML, getStyleByCell, isInlineStringCell, moveToEnd, getFlowdata, handleFormulaInput, moveHighlightCell, escapeScriptTag, valueShowEs, createRangeHightlight, isShowHidenCR, israngeseleciton, escapeHTMLTag, isAllowEdit, getrangeseleciton, indexToColumnChar, handleBold, handleItalic, handleUnderline, handleStrikeThrough, setCellValue } from "@fileverse-dev/fortune-core";
11
+ import { cancelNormalSelected, getCellValue, getInlineStringHTML, getStyleByCell, isInlineStringCell, moveToEnd, getFlowdata, handleFormulaInput, moveHighlightCell, escapeScriptTag, valueShowEs, createRangeHightlight, isShowHidenCR, israngeseleciton, escapeHTMLTag, isAllowEdit, getrangeseleciton, indexToColumnChar, handleBold, handleItalic, handleUnderline, handleStrikeThrough } from "@fileverse-dev/fortune-core";
12
12
  import React, { useContext, useEffect, useMemo, useRef, useCallback, useLayoutEffect, useState } from "react";
13
13
  import _ from "lodash";
14
14
  import { Tooltip } from "@fileverse/ui";
@@ -65,22 +65,15 @@ var InputBox = function InputBox() {
65
65
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
66
66
  var preText = useRef("");
67
67
  var placeRef = useRef("");
68
- var rootRef = useRef(null);
69
68
  var isComposingRef = useRef(false);
70
- var placeCursorAtEnd = function placeCursorAtEnd(el) {
71
- var range = document.createRange();
72
- var sel = window.getSelection();
73
- range.selectNodeContents(el);
74
- range.collapse(false);
75
- sel === null || sel === void 0 ? void 0 : sel.removeAllRanges();
76
- sel === null || sel === void 0 ? void 0 : sel.addRange(range);
77
- };
69
+ var ZWSP = "\u200B";
78
70
  var ensureNotEmpty = function ensureNotEmpty() {
79
- var el = rootRef.current;
71
+ var el = inputRef.current;
80
72
  if (!el) return;
81
- if (el.textContent === "") {
82
- el.innerHTML = "\u200B";
83
- placeCursorAtEnd(el);
73
+ var text = el.textContent;
74
+ if (!text || text === ZWSP) {
75
+ el.innerHTML = ZWSP;
76
+ moveCursorToEnd(el);
84
77
  }
85
78
  };
86
79
  var handleShowFormulaHint = function handleShowFormulaHint() {
@@ -148,7 +141,12 @@ var InputBox = function InputBox() {
148
141
  }
149
142
  }
150
143
  refs.globalCache.overwriteCell = false;
151
- if (!refs.globalCache.ignoreWriteCell && inputRef.current) inputRef.current.innerHTML = escapeHTMLTag(escapeScriptTag(value_1));
144
+ if (!refs.globalCache.ignoreWriteCell && inputRef.current && value_1) {
145
+ inputRef.current.innerHTML = escapeHTMLTag(escapeScriptTag(value_1));
146
+ } else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1) {
147
+ var valueD = getCellValue(row_index, col_index, flowdata, "f");
148
+ inputRef.current.innerText = valueD;
149
+ }
152
150
  refs.globalCache.ignoreWriteCell = false;
153
151
  if (!refs.globalCache.doNotFocus) {
154
152
  setTimeout(function () {
@@ -170,7 +168,6 @@ var InputBox = function InputBox() {
170
168
  }, [context.luckysheet_select_save]);
171
169
  useEffect(function () {
172
170
  var _a;
173
- if (isComposingRef.current) return;
174
171
  if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) || _.isEmpty(context.luckysheetCellUpdate)) {
175
172
  setIsInputBoxActive(false);
176
173
  }
@@ -180,7 +177,6 @@ var InputBox = function InputBox() {
180
177
  }, []);
181
178
  var insertSelectedFormula = useCallback(function (formulaName) {
182
179
  var _a;
183
- if (isComposingRef.current) return;
184
180
  if (/^=[a-zA-Z]+$/.test(inputRef.current.innerText)) {
185
181
  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>");
186
182
  inputRef.current.innerHTML = ht;
@@ -245,7 +241,6 @@ var InputBox = function InputBox() {
245
241
  }, [getActiveFormula]);
246
242
  var selectActiveFormula = useCallback(function (e) {
247
243
  var _a, _b;
248
- if (isComposingRef.current) return;
249
244
  var formulaName = (_b = (_a = getActiveFormula()) === null || _a === void 0 ? void 0 : _a.querySelector(".luckysheet-formula-search-func")) === null || _b === void 0 ? void 0 : _b.textContent;
250
245
  var lastSpanText = getLastInputSpanText();
251
246
  if (formulaName && !isLetterNumberPattern(lastSpanText)) {
@@ -299,10 +294,13 @@ var InputBox = function InputBox() {
299
294
  setCommaCount(currentCommaCount);
300
295
  }
301
296
  var allowListNavigation = true;
302
- 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)) {
303
- setTimeout(function () {
304
- moveCursorToEnd(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
305
- }, 5);
297
+ if (e.key === "Delete" || e.key === "Backspace") {
298
+ requestAnimationFrame(ensureNotEmpty);
299
+ if (getCursorPosition(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
300
+ setTimeout(function () {
301
+ moveCursorToEnd(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
302
+ }, 5);
303
+ }
306
304
  }
307
305
  var refCell = placeRef.current;
308
306
  if (e.key === "ArrowUp") {
@@ -414,9 +412,6 @@ var InputBox = function InputBox() {
414
412
  };
415
413
  var onChange = useCallback(function (__, isBlur) {
416
414
  var _a;
417
- if (isComposingRef.current) {
418
- return;
419
- }
420
415
  if (context.isFlvReadOnly) return;
421
416
  handleHideShowHint();
422
417
  if (((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
@@ -443,7 +438,6 @@ var InputBox = function InputBox() {
443
438
  }
444
439
  }, [refs.cellInput, refs.fxInput, setContext]);
445
440
  var onPaste = useCallback(function (e) {
446
- if (isComposingRef.current) return;
447
441
  if (_.isEmpty(context.luckysheetCellUpdate)) {
448
442
  e.preventDefault();
449
443
  }
@@ -591,29 +585,15 @@ var InputBox = function InputBox() {
591
585
  }, /*#__PURE__*/React.createElement(ContentEditable, {
592
586
  onCompositionStart: function onCompositionStart() {
593
587
  isComposingRef.current = true;
594
- console.log("onCompositionStart");
595
588
  },
596
- onCompositionUpdate: function onCompositionUpdate(e) {
597
- window.CompositData = e.currentTarget.innerText;
589
+ onCompositionUpdate: function onCompositionUpdate() {
598
590
  isComposingRef.current = true;
599
- console.log("onCompositionUpdate", e.currentTarget.innerText);
600
591
  },
601
- onCompositionEnd: function onCompositionEnd(e) {
592
+ onCompositionEnd: function onCompositionEnd() {
602
593
  ensureNotEmpty();
603
- var rowIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus) || 0;
604
- var colIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus) || 0;
605
- console.log("onCompositionEnd", e.currentTarget.innerText, getCellAddress(), rowIndex, colIndex, setCellValue);
606
- window.CompositData = e.currentTarget.innerText;
607
- setContext(function (draftCtx) {
608
- setCellValue(draftCtx, rowIndex, colIndex, null, window.CompositData);
609
- window.CompositData = "";
610
- });
611
594
  isComposingRef.current = false;
612
595
  },
613
596
  onMouseUp: function onMouseUp() {
614
- if (isComposingRef.current) {
615
- return;
616
- }
617
597
  handleHideShowHint();
618
598
  if (!isComposingRef.current) {
619
599
  var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
@@ -621,12 +601,6 @@ var InputBox = function InputBox() {
621
601
  }
622
602
  },
623
603
  innerRef: function innerRef(e) {
624
- rootRef.current = e;
625
- if (isComposingRef.current) {
626
- inputRef.current = null;
627
- refs.cellInput.current = null;
628
- return;
629
- }
630
604
  inputRef.current = e;
631
605
  refs.cellInput.current = e;
632
606
  },
@@ -74,22 +74,15 @@ var InputBox = function InputBox() {
74
74
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
75
75
  var preText = (0, _react.useRef)("");
76
76
  var placeRef = (0, _react.useRef)("");
77
- var rootRef = (0, _react.useRef)(null);
78
77
  var isComposingRef = (0, _react.useRef)(false);
79
- var placeCursorAtEnd = function placeCursorAtEnd(el) {
80
- var range = document.createRange();
81
- var sel = window.getSelection();
82
- range.selectNodeContents(el);
83
- range.collapse(false);
84
- sel === null || sel === void 0 ? void 0 : sel.removeAllRanges();
85
- sel === null || sel === void 0 ? void 0 : sel.addRange(range);
86
- };
78
+ var ZWSP = "\u200B";
87
79
  var ensureNotEmpty = function ensureNotEmpty() {
88
- var el = rootRef.current;
80
+ var el = inputRef.current;
89
81
  if (!el) return;
90
- if (el.textContent === "") {
91
- el.innerHTML = "\u200B";
92
- placeCursorAtEnd(el);
82
+ var text = el.textContent;
83
+ if (!text || text === ZWSP) {
84
+ el.innerHTML = ZWSP;
85
+ (0, _helper.moveCursorToEnd)(el);
93
86
  }
94
87
  };
95
88
  var handleShowFormulaHint = function handleShowFormulaHint() {
@@ -157,7 +150,12 @@ var InputBox = function InputBox() {
157
150
  }
158
151
  }
159
152
  refs.globalCache.overwriteCell = false;
160
- if (!refs.globalCache.ignoreWriteCell && inputRef.current) inputRef.current.innerHTML = (0, _fortuneCore.escapeHTMLTag)((0, _fortuneCore.escapeScriptTag)(value_1));
153
+ if (!refs.globalCache.ignoreWriteCell && inputRef.current && value_1) {
154
+ inputRef.current.innerHTML = (0, _fortuneCore.escapeHTMLTag)((0, _fortuneCore.escapeScriptTag)(value_1));
155
+ } else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1) {
156
+ var valueD = (0, _fortuneCore.getCellValue)(row_index, col_index, flowdata, "f");
157
+ inputRef.current.innerText = valueD;
158
+ }
161
159
  refs.globalCache.ignoreWriteCell = false;
162
160
  if (!refs.globalCache.doNotFocus) {
163
161
  setTimeout(function () {
@@ -179,7 +177,6 @@ var InputBox = function InputBox() {
179
177
  }, [context.luckysheet_select_save]);
180
178
  (0, _react.useEffect)(function () {
181
179
  var _a;
182
- if (isComposingRef.current) return;
183
180
  if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) || _lodash.default.isEmpty(context.luckysheetCellUpdate)) {
184
181
  setIsInputBoxActive(false);
185
182
  }
@@ -189,7 +186,6 @@ var InputBox = function InputBox() {
189
186
  }, []);
190
187
  var insertSelectedFormula = (0, _react.useCallback)(function (formulaName) {
191
188
  var _a;
192
- if (isComposingRef.current) return;
193
189
  if (/^=[a-zA-Z]+$/.test(inputRef.current.innerText)) {
194
190
  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>");
195
191
  inputRef.current.innerHTML = ht;
@@ -254,7 +250,6 @@ var InputBox = function InputBox() {
254
250
  }, [getActiveFormula]);
255
251
  var selectActiveFormula = (0, _react.useCallback)(function (e) {
256
252
  var _a, _b;
257
- if (isComposingRef.current) return;
258
253
  var formulaName = (_b = (_a = getActiveFormula()) === null || _a === void 0 ? void 0 : _a.querySelector(".luckysheet-formula-search-func")) === null || _b === void 0 ? void 0 : _b.textContent;
259
254
  var lastSpanText = getLastInputSpanText();
260
255
  if (formulaName && !(0, _helper.isLetterNumberPattern)(lastSpanText)) {
@@ -308,10 +303,13 @@ var InputBox = function InputBox() {
308
303
  setCommaCount(currentCommaCount);
309
304
  }
310
305
  var allowListNavigation = true;
311
- 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)) {
312
- setTimeout(function () {
313
- (0, _helper.moveCursorToEnd)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
314
- }, 5);
306
+ if (e.key === "Delete" || e.key === "Backspace") {
307
+ requestAnimationFrame(ensureNotEmpty);
308
+ if ((0, _helper.getCursorPosition)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
309
+ setTimeout(function () {
310
+ (0, _helper.moveCursorToEnd)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
311
+ }, 5);
312
+ }
315
313
  }
316
314
  var refCell = placeRef.current;
317
315
  if (e.key === "ArrowUp") {
@@ -423,9 +421,6 @@ var InputBox = function InputBox() {
423
421
  };
424
422
  var onChange = (0, _react.useCallback)(function (__, isBlur) {
425
423
  var _a;
426
- if (isComposingRef.current) {
427
- return;
428
- }
429
424
  if (context.isFlvReadOnly) return;
430
425
  handleHideShowHint();
431
426
  if (((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
@@ -452,7 +447,6 @@ var InputBox = function InputBox() {
452
447
  }
453
448
  }, [refs.cellInput, refs.fxInput, setContext]);
454
449
  var onPaste = (0, _react.useCallback)(function (e) {
455
- if (isComposingRef.current) return;
456
450
  if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
457
451
  e.preventDefault();
458
452
  }
@@ -600,29 +594,15 @@ var InputBox = function InputBox() {
600
594
  }, /*#__PURE__*/_react.default.createElement(_ContentEditable.default, {
601
595
  onCompositionStart: function onCompositionStart() {
602
596
  isComposingRef.current = true;
603
- console.log("onCompositionStart");
604
597
  },
605
- onCompositionUpdate: function onCompositionUpdate(e) {
606
- window.CompositData = e.currentTarget.innerText;
598
+ onCompositionUpdate: function onCompositionUpdate() {
607
599
  isComposingRef.current = true;
608
- console.log("onCompositionUpdate", e.currentTarget.innerText);
609
600
  },
610
- onCompositionEnd: function onCompositionEnd(e) {
601
+ onCompositionEnd: function onCompositionEnd() {
611
602
  ensureNotEmpty();
612
- var rowIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus) || 0;
613
- var colIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus) || 0;
614
- console.log("onCompositionEnd", e.currentTarget.innerText, getCellAddress(), rowIndex, colIndex, _fortuneCore.setCellValue);
615
- window.CompositData = e.currentTarget.innerText;
616
- setContext(function (draftCtx) {
617
- (0, _fortuneCore.setCellValue)(draftCtx, rowIndex, colIndex, null, window.CompositData);
618
- window.CompositData = "";
619
- });
620
603
  isComposingRef.current = false;
621
604
  },
622
605
  onMouseUp: function onMouseUp() {
623
- if (isComposingRef.current) {
624
- return;
625
- }
626
606
  handleHideShowHint();
627
607
  if (!isComposingRef.current) {
628
608
  var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
@@ -630,12 +610,6 @@ var InputBox = function InputBox() {
630
610
  }
631
611
  },
632
612
  innerRef: function innerRef(e) {
633
- rootRef.current = e;
634
- if (isComposingRef.current) {
635
- inputRef.current = null;
636
- refs.cellInput.current = null;
637
- return;
638
- }
639
613
  inputRef.current = e;
640
614
  refs.cellInput.current = e;
641
615
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.2.89-mobile-1",
3
+ "version": "1.2.90",
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.2.89-mobile-1",
19
+ "@fileverse-dev/fortune-core": "1.2.90",
20
20
  "@fileverse/ui": "^4.1.7-patch-40",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",