@fileverse-dev/fortune-react 1.2.86-pinyin → 1.2.86-pinyin-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { getFlowdata, cancelNormalSelected, getCellValue, updateCell, getInlineStringNoStyle, isInlineStringCell, escapeScriptTag, moveHighlightCell, handleFormulaInput, rangeHightlightselected, valueShowEs, isShowHidenCR, escapeHTMLTag, isAllowEdit, setCellValue } from "@fileverse-dev/fortune-core";
1
+ import { getFlowdata, cancelNormalSelected, getCellValue, updateCell, getInlineStringNoStyle, isInlineStringCell, escapeScriptTag, moveHighlightCell, handleFormulaInput, rangeHightlightselected, valueShowEs, isShowHidenCR, escapeHTMLTag, isAllowEdit } from "@fileverse-dev/fortune-core";
2
2
  import React, { useContext, useState, useCallback, useEffect, useRef, useMemo } from "react";
3
3
  import "./index.css";
4
4
  import _ from "lodash";
@@ -35,7 +35,6 @@ var FxEditor = function FxEditor() {
35
35
  var prevFirstSelection = usePrevious(firstSelection);
36
36
  var prevSheetId = usePrevious(context.currentSheetId);
37
37
  var recentText = useRef("");
38
- var isComposingRef = useRef(false);
39
38
  var handleShowFormulaHint = function handleShowFormulaHint() {
40
39
  localStorage.setItem("formulaMore", String(showFormulaHint));
41
40
  setShowFormulaHint(!showFormulaHint);
@@ -69,9 +68,6 @@ var FxEditor = function FxEditor() {
69
68
  }, [context.luckysheetfile, context.currentSheetId, context.luckysheet_select_save]);
70
69
  var onFocus = useCallback(function () {
71
70
  var _a, _b;
72
- if (isComposingRef.current) {
73
- return;
74
- }
75
71
  if (context.allowEdit === false) {
76
72
  return;
77
73
  }
@@ -194,13 +190,8 @@ var FxEditor = function FxEditor() {
194
190
  switch (key) {
195
191
  case "Enter":
196
192
  {
197
- if (isComposingRef.current) {
198
- break;
199
- }
200
193
  var lastCellUpdate = _.clone(draftCtx.luckysheetCellUpdate);
201
- if (!isComposingRef.current) {
202
- updateCell(draftCtx, draftCtx.luckysheetCellUpdate[0], draftCtx.luckysheetCellUpdate[1], refs.fxInput.current);
203
- }
194
+ updateCell(draftCtx, draftCtx.luckysheetCellUpdate[0], draftCtx.luckysheetCellUpdate[1], refs.fxInput.current);
204
195
  draftCtx.luckysheet_select_save = [{
205
196
  row: [lastCellUpdate[0], lastCellUpdate[0]],
206
197
  column: [lastCellUpdate[1], lastCellUpdate[1]],
@@ -222,12 +213,12 @@ var FxEditor = function FxEditor() {
222
213
  }
223
214
  case "ArrowLeft":
224
215
  {
225
- if (!isComposingRef.current) rangeHightlightselected(draftCtx, refs.fxInput.current);
216
+ rangeHightlightselected(draftCtx, refs.fxInput.current);
226
217
  break;
227
218
  }
228
219
  case "ArrowRight":
229
220
  {
230
- if (!isComposingRef.current) rangeHightlightselected(draftCtx, refs.fxInput.current);
221
+ rangeHightlightselected(draftCtx, refs.fxInput.current);
231
222
  break;
232
223
  }
233
224
  default:
@@ -257,7 +248,6 @@ var FxEditor = function FxEditor() {
257
248
  };
258
249
  var onChange = useCallback(function () {
259
250
  var _a, _b, _c;
260
- if (isComposingRef.current) return;
261
251
  if (context.isFlvReadOnly) return;
262
252
  handleHideShowHint();
263
253
  if (((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
@@ -353,25 +343,6 @@ var FxEditor = function FxEditor() {
353
343
  ref: inputContainerRef,
354
344
  className: "fortune-fx-input-container"
355
345
  }, /*#__PURE__*/React.createElement(ContentEditable, {
356
- onCompositionStart: function onCompositionStart() {
357
- isComposingRef.current = true;
358
- console.log("onCompositionStart");
359
- },
360
- onCompositionUpdate: function onCompositionUpdate(e) {
361
- window.CompositData = e.currentTarget.innerText;
362
- isComposingRef.current = true;
363
- console.log("onCompositionUpdate", e.currentTarget.innerText);
364
- },
365
- onCompositionEnd: function onCompositionEnd(e) {
366
- var rowIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus) || 0;
367
- var colIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus) || 0;
368
- window.CompositData = e.currentTarget.innerText;
369
- setContext(function (draftCtx) {
370
- setCellValue(draftCtx, rowIndex, colIndex, null, window.CompositData);
371
- window.CompositData = "";
372
- });
373
- isComposingRef.current = false;
374
- },
375
346
  onMouseUp: function onMouseUp() {
376
347
  var _a;
377
348
  handleHideShowHint();
@@ -379,10 +350,6 @@ var FxEditor = function FxEditor() {
379
350
  setCommaCount(currentCommaCount);
380
351
  },
381
352
  innerRef: function innerRef(e) {
382
- if (isComposingRef.current) {
383
- refs.fxInput.current = null;
384
- return;
385
- }
386
353
  refs.fxInput.current = e;
387
354
  },
388
355
  className: "fortune-fx-input",
@@ -65,7 +65,24 @@ 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);
68
69
  var isComposingRef = useRef(false);
70
+ var ensureNotEmpty = function ensureNotEmpty() {
71
+ var el = rootRef.current;
72
+ if (!el) return;
73
+ if (el.textContent === "") {
74
+ el.innerHTML = "\u200B";
75
+ placeCursorAtEnd(el);
76
+ }
77
+ };
78
+ var placeCursorAtEnd = function placeCursorAtEnd(el) {
79
+ var range = document.createRange();
80
+ var sel = window.getSelection();
81
+ range.selectNodeContents(el);
82
+ range.collapse(false);
83
+ sel === null || sel === void 0 ? void 0 : sel.removeAllRanges();
84
+ sel === null || sel === void 0 ? void 0 : sel.addRange(range);
85
+ };
69
86
  var handleShowFormulaHint = function handleShowFormulaHint() {
70
87
  localStorage.setItem("formulaMore", String(showFormulaHint));
71
88
  setShowFormulaHint(!showFormulaHint);
@@ -239,7 +256,7 @@ var InputBox = function InputBox() {
239
256
  }, [getActiveFormula, insertSelectedFormula]);
240
257
  var selectActiveFormulaOnClick = useCallback(function (e) {
241
258
  var _a, _b;
242
- if (isComposingRef.current) return;
259
+ if (isComposingRef.current || !inputRef.current) return;
243
260
  if (e.target.className.includes("sign-fortune")) return;
244
261
  preText.current = inputRef.current.innerText;
245
262
  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;
@@ -256,7 +273,10 @@ var InputBox = function InputBox() {
256
273
  };
257
274
  var onKeyDown = useCallback(function (e) {
258
275
  var _a, _b;
259
- if (isComposingRef.current) return;
276
+ if (isComposingRef.current || !inputRef.current) {
277
+ ensureNotEmpty();
278
+ return;
279
+ }
260
280
  lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
261
281
  preText.current = inputRef.current.innerText;
262
282
  if (e.metaKey) {
@@ -274,8 +294,10 @@ var InputBox = function InputBox() {
274
294
  stopPropagation(e);
275
295
  }
276
296
  }
277
- var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
278
- setCommaCount(currentCommaCount);
297
+ if (!isComposingRef.current) {
298
+ var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
299
+ setCommaCount(currentCommaCount);
300
+ }
279
301
  var allowListNavigation = true;
280
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)) {
281
303
  setTimeout(function () {
@@ -402,8 +424,10 @@ var InputBox = function InputBox() {
402
424
  } else {
403
425
  setShowSearchHint(false);
404
426
  }
405
- var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
406
- setCommaCount(currentCommaCount);
427
+ if (!isComposingRef.current) {
428
+ var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
429
+ setCommaCount(currentCommaCount);
430
+ }
407
431
  var e = lastKeyDownEventRef.current;
408
432
  if (!e) return;
409
433
  var kcode = e.keyCode;
@@ -575,6 +599,7 @@ var InputBox = function InputBox() {
575
599
  console.log("onCompositionUpdate", e.currentTarget.innerText);
576
600
  },
577
601
  onCompositionEnd: function onCompositionEnd(e) {
602
+ ensureNotEmpty();
578
603
  var rowIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus) || 0;
579
604
  var colIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus) || 0;
580
605
  console.log("onCompositionEnd", e.currentTarget.innerText, getCellAddress(), rowIndex, colIndex, setCellValue);
@@ -590,10 +615,13 @@ var InputBox = function InputBox() {
590
615
  return;
591
616
  }
592
617
  handleHideShowHint();
593
- var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
594
- setCommaCount(currentCommaCount);
618
+ if (!isComposingRef.current) {
619
+ var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
620
+ setCommaCount(currentCommaCount);
621
+ }
595
622
  },
596
623
  innerRef: function innerRef(e) {
624
+ rootRef.current = e;
597
625
  if (isComposingRef.current) {
598
626
  inputRef.current = null;
599
627
  refs.cellInput.current = null;
@@ -44,7 +44,6 @@ var FxEditor = function FxEditor() {
44
44
  var prevFirstSelection = (0, _usePrevious.default)(firstSelection);
45
45
  var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
46
46
  var recentText = (0, _react.useRef)("");
47
- var isComposingRef = (0, _react.useRef)(false);
48
47
  var handleShowFormulaHint = function handleShowFormulaHint() {
49
48
  localStorage.setItem("formulaMore", String(showFormulaHint));
50
49
  setShowFormulaHint(!showFormulaHint);
@@ -78,9 +77,6 @@ var FxEditor = function FxEditor() {
78
77
  }, [context.luckysheetfile, context.currentSheetId, context.luckysheet_select_save]);
79
78
  var onFocus = (0, _react.useCallback)(function () {
80
79
  var _a, _b;
81
- if (isComposingRef.current) {
82
- return;
83
- }
84
80
  if (context.allowEdit === false) {
85
81
  return;
86
82
  }
@@ -203,13 +199,8 @@ var FxEditor = function FxEditor() {
203
199
  switch (key) {
204
200
  case "Enter":
205
201
  {
206
- if (isComposingRef.current) {
207
- break;
208
- }
209
202
  var lastCellUpdate = _lodash.default.clone(draftCtx.luckysheetCellUpdate);
210
- if (!isComposingRef.current) {
211
- (0, _fortuneCore.updateCell)(draftCtx, draftCtx.luckysheetCellUpdate[0], draftCtx.luckysheetCellUpdate[1], refs.fxInput.current);
212
- }
203
+ (0, _fortuneCore.updateCell)(draftCtx, draftCtx.luckysheetCellUpdate[0], draftCtx.luckysheetCellUpdate[1], refs.fxInput.current);
213
204
  draftCtx.luckysheet_select_save = [{
214
205
  row: [lastCellUpdate[0], lastCellUpdate[0]],
215
206
  column: [lastCellUpdate[1], lastCellUpdate[1]],
@@ -231,12 +222,12 @@ var FxEditor = function FxEditor() {
231
222
  }
232
223
  case "ArrowLeft":
233
224
  {
234
- if (!isComposingRef.current) (0, _fortuneCore.rangeHightlightselected)(draftCtx, refs.fxInput.current);
225
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, refs.fxInput.current);
235
226
  break;
236
227
  }
237
228
  case "ArrowRight":
238
229
  {
239
- if (!isComposingRef.current) (0, _fortuneCore.rangeHightlightselected)(draftCtx, refs.fxInput.current);
230
+ (0, _fortuneCore.rangeHightlightselected)(draftCtx, refs.fxInput.current);
240
231
  break;
241
232
  }
242
233
  default:
@@ -266,7 +257,6 @@ var FxEditor = function FxEditor() {
266
257
  };
267
258
  var onChange = (0, _react.useCallback)(function () {
268
259
  var _a, _b, _c;
269
- if (isComposingRef.current) return;
270
260
  if (context.isFlvReadOnly) return;
271
261
  handleHideShowHint();
272
262
  if (((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
@@ -362,25 +352,6 @@ var FxEditor = function FxEditor() {
362
352
  ref: inputContainerRef,
363
353
  className: "fortune-fx-input-container"
364
354
  }, /*#__PURE__*/_react.default.createElement(_ContentEditable.default, {
365
- onCompositionStart: function onCompositionStart() {
366
- isComposingRef.current = true;
367
- console.log("onCompositionStart");
368
- },
369
- onCompositionUpdate: function onCompositionUpdate(e) {
370
- window.CompositData = e.currentTarget.innerText;
371
- isComposingRef.current = true;
372
- console.log("onCompositionUpdate", e.currentTarget.innerText);
373
- },
374
- onCompositionEnd: function onCompositionEnd(e) {
375
- var rowIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus) || 0;
376
- var colIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus) || 0;
377
- window.CompositData = e.currentTarget.innerText;
378
- setContext(function (draftCtx) {
379
- (0, _fortuneCore.setCellValue)(draftCtx, rowIndex, colIndex, null, window.CompositData);
380
- window.CompositData = "";
381
- });
382
- isComposingRef.current = false;
383
- },
384
355
  onMouseUp: function onMouseUp() {
385
356
  var _a;
386
357
  handleHideShowHint();
@@ -388,10 +359,6 @@ var FxEditor = function FxEditor() {
388
359
  setCommaCount(currentCommaCount);
389
360
  },
390
361
  innerRef: function innerRef(e) {
391
- if (isComposingRef.current) {
392
- refs.fxInput.current = null;
393
- return;
394
- }
395
362
  refs.fxInput.current = e;
396
363
  },
397
364
  className: "fortune-fx-input",
@@ -74,7 +74,24 @@ 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);
77
78
  var isComposingRef = (0, _react.useRef)(false);
79
+ var ensureNotEmpty = function ensureNotEmpty() {
80
+ var el = rootRef.current;
81
+ if (!el) return;
82
+ if (el.textContent === "") {
83
+ el.innerHTML = "\u200B";
84
+ placeCursorAtEnd(el);
85
+ }
86
+ };
87
+ var placeCursorAtEnd = function placeCursorAtEnd(el) {
88
+ var range = document.createRange();
89
+ var sel = window.getSelection();
90
+ range.selectNodeContents(el);
91
+ range.collapse(false);
92
+ sel === null || sel === void 0 ? void 0 : sel.removeAllRanges();
93
+ sel === null || sel === void 0 ? void 0 : sel.addRange(range);
94
+ };
78
95
  var handleShowFormulaHint = function handleShowFormulaHint() {
79
96
  localStorage.setItem("formulaMore", String(showFormulaHint));
80
97
  setShowFormulaHint(!showFormulaHint);
@@ -248,7 +265,7 @@ var InputBox = function InputBox() {
248
265
  }, [getActiveFormula, insertSelectedFormula]);
249
266
  var selectActiveFormulaOnClick = (0, _react.useCallback)(function (e) {
250
267
  var _a, _b;
251
- if (isComposingRef.current) return;
268
+ if (isComposingRef.current || !inputRef.current) return;
252
269
  if (e.target.className.includes("sign-fortune")) return;
253
270
  preText.current = inputRef.current.innerText;
254
271
  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;
@@ -265,7 +282,10 @@ var InputBox = function InputBox() {
265
282
  };
266
283
  var onKeyDown = (0, _react.useCallback)(function (e) {
267
284
  var _a, _b;
268
- if (isComposingRef.current) return;
285
+ if (isComposingRef.current || !inputRef.current) {
286
+ ensureNotEmpty();
287
+ return;
288
+ }
269
289
  lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
270
290
  preText.current = inputRef.current.innerText;
271
291
  if (e.metaKey) {
@@ -283,8 +303,10 @@ var InputBox = function InputBox() {
283
303
  stopPropagation(e);
284
304
  }
285
305
  }
286
- var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
287
- setCommaCount(currentCommaCount);
306
+ if (!isComposingRef.current) {
307
+ var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
308
+ setCommaCount(currentCommaCount);
309
+ }
288
310
  var allowListNavigation = true;
289
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)) {
290
312
  setTimeout(function () {
@@ -411,8 +433,10 @@ var InputBox = function InputBox() {
411
433
  } else {
412
434
  setShowSearchHint(false);
413
435
  }
414
- var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
415
- setCommaCount(currentCommaCount);
436
+ if (!isComposingRef.current) {
437
+ var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
438
+ setCommaCount(currentCommaCount);
439
+ }
416
440
  var e = lastKeyDownEventRef.current;
417
441
  if (!e) return;
418
442
  var kcode = e.keyCode;
@@ -584,6 +608,7 @@ var InputBox = function InputBox() {
584
608
  console.log("onCompositionUpdate", e.currentTarget.innerText);
585
609
  },
586
610
  onCompositionEnd: function onCompositionEnd(e) {
611
+ ensureNotEmpty();
587
612
  var rowIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus) || 0;
588
613
  var colIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus) || 0;
589
614
  console.log("onCompositionEnd", e.currentTarget.innerText, getCellAddress(), rowIndex, colIndex, _fortuneCore.setCellValue);
@@ -599,10 +624,13 @@ var InputBox = function InputBox() {
599
624
  return;
600
625
  }
601
626
  handleHideShowHint();
602
- var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
603
- setCommaCount(currentCommaCount);
627
+ if (!isComposingRef.current) {
628
+ var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
629
+ setCommaCount(currentCommaCount);
630
+ }
604
631
  },
605
632
  innerRef: function innerRef(e) {
633
+ rootRef.current = e;
606
634
  if (isComposingRef.current) {
607
635
  inputRef.current = null;
608
636
  refs.cellInput.current = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.2.86-pinyin",
3
+ "version": "1.2.86-pinyin-3",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "module": "es/index.js",
@@ -16,7 +16,7 @@
16
16
  "tsc": "tsc"
17
17
  },
18
18
  "dependencies": {
19
- "@fileverse-dev/fortune-core": "1.2.86-pinyin",
19
+ "@fileverse-dev/fortune-core": "1.2.86-pinyin-2",
20
20
  "@fileverse/ui": "^4.1.7-patch-40",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",