@fileverse-dev/fortune-react 1.2.89 → 1.2.90-bold-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.
@@ -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, 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)) {
@@ -280,12 +275,8 @@ var InputBox = function InputBox() {
280
275
  lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
281
276
  preText.current = inputRef.current.innerText;
282
277
  if (e.metaKey) {
283
- if (e.code === "KeyB") {
284
- handleBold(context, inputRef.current);
285
- stopPropagation(e);
286
- } else if (e.code === "KeyI") {
278
+ if (e.code === "KeyB") {} else if (e.code === "KeyI") {
287
279
  handleItalic(context, inputRef.current);
288
- stopPropagation(e);
289
280
  } else if (e.code === "KeyU") {
290
281
  handleUnderline(context, inputRef.current);
291
282
  stopPropagation(e);
@@ -299,10 +290,13 @@ var InputBox = function InputBox() {
299
290
  setCommaCount(currentCommaCount);
300
291
  }
301
292
  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);
293
+ if (e.key === "Delete" || e.key === "Backspace") {
294
+ requestAnimationFrame(ensureNotEmpty);
295
+ if (getCursorPosition(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
296
+ setTimeout(function () {
297
+ moveCursorToEnd(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
298
+ }, 5);
299
+ }
306
300
  }
307
301
  var refCell = placeRef.current;
308
302
  if (e.key === "ArrowUp") {
@@ -414,9 +408,6 @@ var InputBox = function InputBox() {
414
408
  };
415
409
  var onChange = useCallback(function (__, isBlur) {
416
410
  var _a;
417
- if (isComposingRef.current) {
418
- return;
419
- }
420
411
  if (context.isFlvReadOnly) return;
421
412
  handleHideShowHint();
422
413
  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 +434,6 @@ var InputBox = function InputBox() {
443
434
  }
444
435
  }, [refs.cellInput, refs.fxInput, setContext]);
445
436
  var onPaste = useCallback(function (e) {
446
- if (isComposingRef.current) return;
447
437
  if (_.isEmpty(context.luckysheetCellUpdate)) {
448
438
  e.preventDefault();
449
439
  }
@@ -591,29 +581,15 @@ var InputBox = function InputBox() {
591
581
  }, /*#__PURE__*/React.createElement(ContentEditable, {
592
582
  onCompositionStart: function onCompositionStart() {
593
583
  isComposingRef.current = true;
594
- console.log("onCompositionStart");
595
584
  },
596
- onCompositionUpdate: function onCompositionUpdate(e) {
597
- window.CompositData = e.currentTarget.innerText;
585
+ onCompositionUpdate: function onCompositionUpdate() {
598
586
  isComposingRef.current = true;
599
- console.log("onCompositionUpdate", e.currentTarget.innerText);
600
587
  },
601
- onCompositionEnd: function onCompositionEnd(e) {
588
+ onCompositionEnd: function onCompositionEnd() {
602
589
  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
590
  isComposingRef.current = false;
612
591
  },
613
592
  onMouseUp: function onMouseUp() {
614
- if (isComposingRef.current) {
615
- return;
616
- }
617
593
  handleHideShowHint();
618
594
  if (!isComposingRef.current) {
619
595
  var currentCommaCount = countCommasBeforeCursor(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
@@ -621,12 +597,6 @@ var InputBox = function InputBox() {
621
597
  }
622
598
  },
623
599
  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
600
  inputRef.current = e;
631
601
  refs.cellInput.current = e;
632
602
  },
@@ -503,6 +503,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
503
503
  var resetDeleteRowTimer;
504
504
  var onKeyDown = useCallback(function (e) {
505
505
  var _a, _b;
506
+ console.log("onKeyDown", e);
506
507
  var _c = ref.current,
507
508
  getSelection = _c.getSelection,
508
509
  getSheet = _c.getSheet,
@@ -644,6 +645,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
644
645
  return;
645
646
  }
646
647
  setContextWithProduce(function (draftCtx) {
648
+ console.log("handleGlobalKeyDown");
647
649
  handleGlobalKeyDown(draftCtx, cellInput.current, fxInput.current, nativeEvent, globalCache.current, handleUndo, handleRedo, canvas.current.getContext("2d"));
648
650
  });
649
651
  }, [handleRedo, handleUndo, setContextWithProduce]);
@@ -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)) {
@@ -289,12 +284,8 @@ var InputBox = function InputBox() {
289
284
  lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
290
285
  preText.current = inputRef.current.innerText;
291
286
  if (e.metaKey) {
292
- if (e.code === "KeyB") {
293
- (0, _fortuneCore.handleBold)(context, inputRef.current);
294
- stopPropagation(e);
295
- } else if (e.code === "KeyI") {
287
+ if (e.code === "KeyB") {} else if (e.code === "KeyI") {
296
288
  (0, _fortuneCore.handleItalic)(context, inputRef.current);
297
- stopPropagation(e);
298
289
  } else if (e.code === "KeyU") {
299
290
  (0, _fortuneCore.handleUnderline)(context, inputRef.current);
300
291
  stopPropagation(e);
@@ -308,10 +299,13 @@ var InputBox = function InputBox() {
308
299
  setCommaCount(currentCommaCount);
309
300
  }
310
301
  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);
302
+ if (e.key === "Delete" || e.key === "Backspace") {
303
+ requestAnimationFrame(ensureNotEmpty);
304
+ if ((0, _helper.getCursorPosition)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerText.length)) {
305
+ setTimeout(function () {
306
+ (0, _helper.moveCursorToEnd)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
307
+ }, 5);
308
+ }
315
309
  }
316
310
  var refCell = placeRef.current;
317
311
  if (e.key === "ArrowUp") {
@@ -423,9 +417,6 @@ var InputBox = function InputBox() {
423
417
  };
424
418
  var onChange = (0, _react.useCallback)(function (__, isBlur) {
425
419
  var _a;
426
- if (isComposingRef.current) {
427
- return;
428
- }
429
420
  if (context.isFlvReadOnly) return;
430
421
  handleHideShowHint();
431
422
  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 +443,6 @@ var InputBox = function InputBox() {
452
443
  }
453
444
  }, [refs.cellInput, refs.fxInput, setContext]);
454
445
  var onPaste = (0, _react.useCallback)(function (e) {
455
- if (isComposingRef.current) return;
456
446
  if (_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
457
447
  e.preventDefault();
458
448
  }
@@ -600,29 +590,15 @@ var InputBox = function InputBox() {
600
590
  }, /*#__PURE__*/_react.default.createElement(_ContentEditable.default, {
601
591
  onCompositionStart: function onCompositionStart() {
602
592
  isComposingRef.current = true;
603
- console.log("onCompositionStart");
604
593
  },
605
- onCompositionUpdate: function onCompositionUpdate(e) {
606
- window.CompositData = e.currentTarget.innerText;
594
+ onCompositionUpdate: function onCompositionUpdate() {
607
595
  isComposingRef.current = true;
608
- console.log("onCompositionUpdate", e.currentTarget.innerText);
609
596
  },
610
- onCompositionEnd: function onCompositionEnd(e) {
597
+ onCompositionEnd: function onCompositionEnd() {
611
598
  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
599
  isComposingRef.current = false;
621
600
  },
622
601
  onMouseUp: function onMouseUp() {
623
- if (isComposingRef.current) {
624
- return;
625
- }
626
602
  handleHideShowHint();
627
603
  if (!isComposingRef.current) {
628
604
  var currentCommaCount = (0, _helper.countCommasBeforeCursor)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current);
@@ -630,12 +606,6 @@ var InputBox = function InputBox() {
630
606
  }
631
607
  },
632
608
  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
609
  inputRef.current = e;
640
610
  refs.cellInput.current = e;
641
611
  },
@@ -512,6 +512,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
512
512
  var resetDeleteRowTimer;
513
513
  var onKeyDown = (0, _react.useCallback)(function (e) {
514
514
  var _a, _b;
515
+ console.log("onKeyDown", e);
515
516
  var _c = ref.current,
516
517
  getSelection = _c.getSelection,
517
518
  getSheet = _c.getSheet,
@@ -653,6 +654,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
653
654
  return;
654
655
  }
655
656
  setContextWithProduce(function (draftCtx) {
657
+ console.log("handleGlobalKeyDown");
656
658
  (0, _fortuneCore.handleGlobalKeyDown)(draftCtx, cellInput.current, fxInput.current, nativeEvent, globalCache.current, handleUndo, handleRedo, canvas.current.getContext("2d"));
657
659
  });
658
660
  }, [handleRedo, handleUndo, setContextWithProduce]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.2.89",
3
+ "version": "1.2.90-bold-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.2.89",
19
+ "@fileverse-dev/fortune-core": "1.2.90-bold-1",
20
20
  "@fileverse/ui": "^4.1.7-patch-40",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",