@fileverse-dev/fortune-react 1.2.86-pinyin-2 → 1.2.86-pinyin-4

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.
@@ -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 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
+ };
78
+ var ensureNotEmpty = function ensureNotEmpty() {
79
+ var el = rootRef.current;
80
+ if (!el) return;
81
+ if (el.textContent === "") {
82
+ el.innerHTML = "\u200B";
83
+ placeCursorAtEnd(el);
84
+ }
85
+ };
69
86
  var handleShowFormulaHint = function handleShowFormulaHint() {
70
87
  localStorage.setItem("formulaMore", String(showFormulaHint));
71
88
  setShowFormulaHint(!showFormulaHint);
@@ -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 || !inputRef.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) {
@@ -579,6 +599,7 @@ var InputBox = function InputBox() {
579
599
  console.log("onCompositionUpdate", e.currentTarget.innerText);
580
600
  },
581
601
  onCompositionEnd: function onCompositionEnd(e) {
602
+ ensureNotEmpty();
582
603
  var rowIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus) || 0;
583
604
  var colIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus) || 0;
584
605
  console.log("onCompositionEnd", e.currentTarget.innerText, getCellAddress(), rowIndex, colIndex, setCellValue);
@@ -600,6 +621,7 @@ var InputBox = function InputBox() {
600
621
  }
601
622
  },
602
623
  innerRef: function innerRef(e) {
624
+ rootRef.current = e;
603
625
  if (isComposingRef.current) {
604
626
  inputRef.current = null;
605
627
  refs.cellInput.current = null;
@@ -961,7 +961,7 @@ var Toolbar = function Toolbar(_a) {
961
961
  key: name,
962
962
  disabled: refs.globalCache.undoList.length === 0,
963
963
  onClick: function onClick() {
964
- return handleUndo();
964
+ handleUndo();
965
965
  }
966
966
  });
967
967
  }
@@ -15,7 +15,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
15
15
  }
16
16
  return to.concat(ar || Array.prototype.slice.call(from));
17
17
  };
18
- import { defaultContext, defaultSettings, initSheetIndex, handleGlobalKeyDown, getSheetIndex, handlePaste, filterPatch, patchToOp, inverseRowColOptions, ensureSheetIndex, insertRowCol, deleteRowCol, groupValuesRefresh, insertDuneChart, getFlowdata, api, handlePasteByClick } from "@fileverse-dev/fortune-core";
18
+ import { Canvas, defaultContext, defaultSettings, initSheetIndex, handleGlobalKeyDown, getSheetIndex, handlePaste, filterPatch, patchToOp, inverseRowColOptions, ensureSheetIndex, insertRowCol, deleteRowCol, groupValuesRefresh, insertDuneChart, getFlowdata, api, handlePasteByClick } from "@fileverse-dev/fortune-core";
19
19
  import React, { useMemo, useState, useCallback, useEffect, useRef, useImperativeHandle } from "react";
20
20
  import "./index.css";
21
21
  import produce, { applyPatches, enablePatches, produceWithPatches } from "immer";
@@ -248,8 +248,105 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
248
248
  return result;
249
249
  });
250
250
  }, [emitOp]);
251
+ var repaint = function repaint() {
252
+ var _a, _b, _c, _d, _e;
253
+ console.log("repaint");
254
+ var tableCanvas = new Canvas(refs.canvas.current, context);
255
+ var freeze = (_a = refs.globalCache.freezen) === null || _a === void 0 ? void 0 : _a[sheet.id];
256
+ if (((_b = freeze === null || freeze === void 0 ? void 0 : freeze.horizontal) === null || _b === void 0 ? void 0 : _b.freezenhorizontaldata) || ((_c = freeze === null || freeze === void 0 ? void 0 : freeze.vertical) === null || _c === void 0 ? void 0 : _c.freezenverticaldata)) {
257
+ var horizontalData = (_d = freeze === null || freeze === void 0 ? void 0 : freeze.horizontal) === null || _d === void 0 ? void 0 : _d.freezenhorizontaldata;
258
+ var verticallData = (_e = freeze === null || freeze === void 0 ? void 0 : freeze.vertical) === null || _e === void 0 ? void 0 : _e.freezenverticaldata;
259
+ if (horizontalData && verticallData) {
260
+ var horizontalPx = horizontalData[0],
261
+ horizontalScrollTop = horizontalData[2];
262
+ var verticalPx = verticallData[0],
263
+ verticalScrollWidth = verticallData[2];
264
+ tableCanvas.drawMain({
265
+ scrollWidth: context.scrollLeft + verticalPx - verticalScrollWidth,
266
+ scrollHeight: context.scrollTop + horizontalPx - horizontalScrollTop,
267
+ offsetLeft: verticalPx - verticalScrollWidth + context.rowHeaderWidth,
268
+ offsetTop: horizontalPx - horizontalScrollTop + context.columnHeaderHeight,
269
+ clear: true
270
+ });
271
+ tableCanvas.drawMain({
272
+ scrollWidth: context.scrollLeft + verticalPx - verticalScrollWidth,
273
+ scrollHeight: horizontalScrollTop,
274
+ drawHeight: horizontalPx,
275
+ offsetLeft: verticalPx - verticalScrollWidth + context.rowHeaderWidth
276
+ });
277
+ tableCanvas.drawMain({
278
+ scrollWidth: verticalScrollWidth,
279
+ scrollHeight: context.scrollTop + horizontalPx - horizontalScrollTop,
280
+ drawWidth: verticalPx,
281
+ offsetTop: horizontalPx - horizontalScrollTop + context.columnHeaderHeight
282
+ });
283
+ tableCanvas.drawMain({
284
+ scrollWidth: verticalScrollWidth,
285
+ scrollHeight: horizontalScrollTop,
286
+ drawWidth: verticalPx,
287
+ drawHeight: horizontalPx
288
+ });
289
+ tableCanvas.drawColumnHeader(context.scrollLeft + verticalPx - verticalScrollWidth, undefined, verticalPx - verticalScrollWidth + context.rowHeaderWidth);
290
+ tableCanvas.drawColumnHeader(verticalScrollWidth, verticalPx);
291
+ tableCanvas.drawRowHeader(context.scrollTop + horizontalPx - horizontalScrollTop, undefined, horizontalPx - horizontalScrollTop + context.columnHeaderHeight);
292
+ tableCanvas.drawRowHeader(horizontalScrollTop, horizontalPx);
293
+ tableCanvas.drawFreezeLine({
294
+ horizontalTop: horizontalPx - horizontalScrollTop + context.columnHeaderHeight - 2,
295
+ verticalLeft: verticalPx - verticalScrollWidth + context.rowHeaderWidth - 2
296
+ });
297
+ } else if (horizontalData) {
298
+ var horizontalPx = horizontalData[0],
299
+ horizontalScrollTop = horizontalData[2];
300
+ tableCanvas.drawMain({
301
+ scrollWidth: context.scrollLeft,
302
+ scrollHeight: context.scrollTop + horizontalPx - horizontalScrollTop,
303
+ offsetTop: horizontalPx - horizontalScrollTop + context.columnHeaderHeight,
304
+ clear: true
305
+ });
306
+ tableCanvas.drawMain({
307
+ scrollWidth: context.scrollLeft,
308
+ scrollHeight: horizontalScrollTop,
309
+ drawHeight: horizontalPx
310
+ });
311
+ tableCanvas.drawColumnHeader(context.scrollLeft);
312
+ tableCanvas.drawRowHeader(context.scrollTop + horizontalPx - horizontalScrollTop, undefined, horizontalPx - horizontalScrollTop + context.columnHeaderHeight);
313
+ tableCanvas.drawRowHeader(horizontalScrollTop, horizontalPx);
314
+ tableCanvas.drawFreezeLine({
315
+ horizontalTop: horizontalPx - horizontalScrollTop + context.columnHeaderHeight - 2
316
+ });
317
+ } else if (verticallData) {
318
+ var verticalPx = verticallData[0],
319
+ verticalScrollWidth = verticallData[2];
320
+ tableCanvas.drawMain({
321
+ scrollWidth: context.scrollLeft + verticalPx - verticalScrollWidth,
322
+ scrollHeight: context.scrollTop,
323
+ offsetLeft: verticalPx - verticalScrollWidth + context.rowHeaderWidth
324
+ });
325
+ tableCanvas.drawMain({
326
+ scrollWidth: verticalScrollWidth,
327
+ scrollHeight: context.scrollTop,
328
+ drawWidth: verticalPx
329
+ });
330
+ tableCanvas.drawRowHeader(context.scrollTop);
331
+ tableCanvas.drawColumnHeader(context.scrollLeft + verticalPx - verticalScrollWidth, undefined, verticalPx - verticalScrollWidth + context.rowHeaderWidth);
332
+ tableCanvas.drawColumnHeader(verticalScrollWidth, verticalPx);
333
+ tableCanvas.drawFreezeLine({
334
+ verticalLeft: verticalPx - verticalScrollWidth + context.rowHeaderWidth - 2
335
+ });
336
+ }
337
+ } else {
338
+ tableCanvas.drawMain({
339
+ scrollWidth: context.scrollLeft,
340
+ scrollHeight: context.scrollTop,
341
+ clear: true
342
+ });
343
+ tableCanvas.drawColumnHeader(context.scrollLeft);
344
+ tableCanvas.drawRowHeader(context.scrollTop);
345
+ }
346
+ };
251
347
  var handleUndo = useCallback(function () {
252
348
  var history = globalCache.current.undoList.pop();
349
+ console.log("undo", history);
253
350
  if (history) {
254
351
  setContext(function (ctx_) {
255
352
  var _a, _b, _c, _d, _e;
@@ -287,6 +384,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
287
384
  emitOp(newContext, history.inversePatches, inversedOptions, true);
288
385
  return newContext;
289
386
  });
387
+ repaint();
290
388
  }
291
389
  }, [emitOp]);
292
390
  var handleRedo = useCallback(function () {
@@ -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 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
+ };
87
+ var ensureNotEmpty = function ensureNotEmpty() {
88
+ var el = rootRef.current;
89
+ if (!el) return;
90
+ if (el.textContent === "") {
91
+ el.innerHTML = "\u200B";
92
+ placeCursorAtEnd(el);
93
+ }
94
+ };
78
95
  var handleShowFormulaHint = function handleShowFormulaHint() {
79
96
  localStorage.setItem("formulaMore", String(showFormulaHint));
80
97
  setShowFormulaHint(!showFormulaHint);
@@ -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 || !inputRef.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) {
@@ -588,6 +608,7 @@ var InputBox = function InputBox() {
588
608
  console.log("onCompositionUpdate", e.currentTarget.innerText);
589
609
  },
590
610
  onCompositionEnd: function onCompositionEnd(e) {
611
+ ensureNotEmpty();
591
612
  var rowIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus) || 0;
592
613
  var colIndex = (firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus) || 0;
593
614
  console.log("onCompositionEnd", e.currentTarget.innerText, getCellAddress(), rowIndex, colIndex, _fortuneCore.setCellValue);
@@ -609,6 +630,7 @@ var InputBox = function InputBox() {
609
630
  }
610
631
  },
611
632
  innerRef: function innerRef(e) {
633
+ rootRef.current = e;
612
634
  if (isComposingRef.current) {
613
635
  inputRef.current = null;
614
636
  refs.cellInput.current = null;
@@ -970,7 +970,7 @@ var Toolbar = function Toolbar(_a) {
970
970
  key: name,
971
971
  disabled: refs.globalCache.undoList.length === 0,
972
972
  onClick: function onClick() {
973
- return handleUndo();
973
+ handleUndo();
974
974
  }
975
975
  });
976
976
  }
@@ -257,8 +257,105 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
257
257
  return result;
258
258
  });
259
259
  }, [emitOp]);
260
+ var repaint = function repaint() {
261
+ var _a, _b, _c, _d, _e;
262
+ console.log("repaint");
263
+ var tableCanvas = new _fortuneCore.Canvas(refs.canvas.current, context);
264
+ var freeze = (_a = refs.globalCache.freezen) === null || _a === void 0 ? void 0 : _a[sheet.id];
265
+ if (((_b = freeze === null || freeze === void 0 ? void 0 : freeze.horizontal) === null || _b === void 0 ? void 0 : _b.freezenhorizontaldata) || ((_c = freeze === null || freeze === void 0 ? void 0 : freeze.vertical) === null || _c === void 0 ? void 0 : _c.freezenverticaldata)) {
266
+ var horizontalData = (_d = freeze === null || freeze === void 0 ? void 0 : freeze.horizontal) === null || _d === void 0 ? void 0 : _d.freezenhorizontaldata;
267
+ var verticallData = (_e = freeze === null || freeze === void 0 ? void 0 : freeze.vertical) === null || _e === void 0 ? void 0 : _e.freezenverticaldata;
268
+ if (horizontalData && verticallData) {
269
+ var horizontalPx = horizontalData[0],
270
+ horizontalScrollTop = horizontalData[2];
271
+ var verticalPx = verticallData[0],
272
+ verticalScrollWidth = verticallData[2];
273
+ tableCanvas.drawMain({
274
+ scrollWidth: context.scrollLeft + verticalPx - verticalScrollWidth,
275
+ scrollHeight: context.scrollTop + horizontalPx - horizontalScrollTop,
276
+ offsetLeft: verticalPx - verticalScrollWidth + context.rowHeaderWidth,
277
+ offsetTop: horizontalPx - horizontalScrollTop + context.columnHeaderHeight,
278
+ clear: true
279
+ });
280
+ tableCanvas.drawMain({
281
+ scrollWidth: context.scrollLeft + verticalPx - verticalScrollWidth,
282
+ scrollHeight: horizontalScrollTop,
283
+ drawHeight: horizontalPx,
284
+ offsetLeft: verticalPx - verticalScrollWidth + context.rowHeaderWidth
285
+ });
286
+ tableCanvas.drawMain({
287
+ scrollWidth: verticalScrollWidth,
288
+ scrollHeight: context.scrollTop + horizontalPx - horizontalScrollTop,
289
+ drawWidth: verticalPx,
290
+ offsetTop: horizontalPx - horizontalScrollTop + context.columnHeaderHeight
291
+ });
292
+ tableCanvas.drawMain({
293
+ scrollWidth: verticalScrollWidth,
294
+ scrollHeight: horizontalScrollTop,
295
+ drawWidth: verticalPx,
296
+ drawHeight: horizontalPx
297
+ });
298
+ tableCanvas.drawColumnHeader(context.scrollLeft + verticalPx - verticalScrollWidth, undefined, verticalPx - verticalScrollWidth + context.rowHeaderWidth);
299
+ tableCanvas.drawColumnHeader(verticalScrollWidth, verticalPx);
300
+ tableCanvas.drawRowHeader(context.scrollTop + horizontalPx - horizontalScrollTop, undefined, horizontalPx - horizontalScrollTop + context.columnHeaderHeight);
301
+ tableCanvas.drawRowHeader(horizontalScrollTop, horizontalPx);
302
+ tableCanvas.drawFreezeLine({
303
+ horizontalTop: horizontalPx - horizontalScrollTop + context.columnHeaderHeight - 2,
304
+ verticalLeft: verticalPx - verticalScrollWidth + context.rowHeaderWidth - 2
305
+ });
306
+ } else if (horizontalData) {
307
+ var horizontalPx = horizontalData[0],
308
+ horizontalScrollTop = horizontalData[2];
309
+ tableCanvas.drawMain({
310
+ scrollWidth: context.scrollLeft,
311
+ scrollHeight: context.scrollTop + horizontalPx - horizontalScrollTop,
312
+ offsetTop: horizontalPx - horizontalScrollTop + context.columnHeaderHeight,
313
+ clear: true
314
+ });
315
+ tableCanvas.drawMain({
316
+ scrollWidth: context.scrollLeft,
317
+ scrollHeight: horizontalScrollTop,
318
+ drawHeight: horizontalPx
319
+ });
320
+ tableCanvas.drawColumnHeader(context.scrollLeft);
321
+ tableCanvas.drawRowHeader(context.scrollTop + horizontalPx - horizontalScrollTop, undefined, horizontalPx - horizontalScrollTop + context.columnHeaderHeight);
322
+ tableCanvas.drawRowHeader(horizontalScrollTop, horizontalPx);
323
+ tableCanvas.drawFreezeLine({
324
+ horizontalTop: horizontalPx - horizontalScrollTop + context.columnHeaderHeight - 2
325
+ });
326
+ } else if (verticallData) {
327
+ var verticalPx = verticallData[0],
328
+ verticalScrollWidth = verticallData[2];
329
+ tableCanvas.drawMain({
330
+ scrollWidth: context.scrollLeft + verticalPx - verticalScrollWidth,
331
+ scrollHeight: context.scrollTop,
332
+ offsetLeft: verticalPx - verticalScrollWidth + context.rowHeaderWidth
333
+ });
334
+ tableCanvas.drawMain({
335
+ scrollWidth: verticalScrollWidth,
336
+ scrollHeight: context.scrollTop,
337
+ drawWidth: verticalPx
338
+ });
339
+ tableCanvas.drawRowHeader(context.scrollTop);
340
+ tableCanvas.drawColumnHeader(context.scrollLeft + verticalPx - verticalScrollWidth, undefined, verticalPx - verticalScrollWidth + context.rowHeaderWidth);
341
+ tableCanvas.drawColumnHeader(verticalScrollWidth, verticalPx);
342
+ tableCanvas.drawFreezeLine({
343
+ verticalLeft: verticalPx - verticalScrollWidth + context.rowHeaderWidth - 2
344
+ });
345
+ }
346
+ } else {
347
+ tableCanvas.drawMain({
348
+ scrollWidth: context.scrollLeft,
349
+ scrollHeight: context.scrollTop,
350
+ clear: true
351
+ });
352
+ tableCanvas.drawColumnHeader(context.scrollLeft);
353
+ tableCanvas.drawRowHeader(context.scrollTop);
354
+ }
355
+ };
260
356
  var handleUndo = (0, _react.useCallback)(function () {
261
357
  var history = globalCache.current.undoList.pop();
358
+ console.log("undo", history);
262
359
  if (history) {
263
360
  setContext(function (ctx_) {
264
361
  var _a, _b, _c, _d, _e;
@@ -296,6 +393,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
296
393
  emitOp(newContext, history.inversePatches, inversedOptions, true);
297
394
  return newContext;
298
395
  });
396
+ repaint();
299
397
  }
300
398
  }, [emitOp]);
301
399
  var handleRedo = (0, _react.useCallback)(function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.2.86-pinyin-2",
3
+ "version": "1.2.86-pinyin-4",
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-2",
19
+ "@fileverse-dev/fortune-core": "1.2.86-pinyin-4",
20
20
  "@fileverse/ui": "^4.1.7-patch-40",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",