@fileverse-dev/fortune-react 1.3.10 → 1.3.11-mixed

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.
Files changed (27) hide show
  1. package/es/components/ConditionFormat/ConditionRules.js +15 -5
  2. package/es/components/ConditionFormat/index.js +3 -0
  3. package/es/components/DataVerification/ColorPicker.js +1 -1
  4. package/es/components/SheetOverlay/InputBox.js +112 -75
  5. package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +25 -1
  6. package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +26 -2
  7. package/es/components/SheetOverlay/index.css +6 -0
  8. package/es/components/SheetOverlay/index.js +3 -3
  9. package/es/components/Toolbar/index.js +17 -12
  10. package/es/components/Workbook/api.d.ts +3 -0
  11. package/es/components/Workbook/index.d.ts +3 -0
  12. package/es/components/Workbook/index.js +146 -10
  13. package/es/utils/convertCellsToCrypto.js +17 -0
  14. package/lib/components/ConditionFormat/ConditionRules.js +15 -5
  15. package/lib/components/ConditionFormat/index.js +3 -0
  16. package/lib/components/DataVerification/ColorPicker.js +1 -1
  17. package/lib/components/SheetOverlay/InputBox.js +111 -74
  18. package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +25 -1
  19. package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +26 -2
  20. package/lib/components/SheetOverlay/index.css +6 -0
  21. package/lib/components/SheetOverlay/index.js +3 -3
  22. package/lib/components/Toolbar/index.js +16 -11
  23. package/lib/components/Workbook/api.d.ts +3 -0
  24. package/lib/components/Workbook/index.d.ts +3 -0
  25. package/lib/components/Workbook/index.js +146 -10
  26. package/lib/utils/convertCellsToCrypto.js +17 -0
  27. package/package.json +2 -2
@@ -25,7 +25,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
25
25
  }
26
26
  return to.concat(ar || Array.prototype.slice.call(from));
27
27
  };
28
- import { defaultContext, defaultSettings, initSheetIndex, handleGlobalKeyDown, getSheetIndex, handlePaste, filterPatch, patchToOp, inverseRowColOptions, ensureSheetIndex, insertRowCol, deleteRowCol, groupValuesRefresh, insertDuneChart, getFlowdata, api, handlePasteByClick } from "@fileverse-dev/fortune-core";
28
+ import { defaultContext, defaultSettings, initSheetIndex, handleGlobalKeyDown, getSheetIndex, handlePaste, filterPatch, patchToOp, inverseRowColOptions, ensureSheetIndex, insertRowCol, deleteRowCol, groupValuesRefresh, insertDuneChart, getFlowdata, api, handlePasteByClick, update } from "@fileverse-dev/fortune-core";
29
29
  import React, { useMemo, useState, useCallback, useEffect, useRef, useImperativeHandle } from "react";
30
30
  import "./index.css";
31
31
  import produce, { applyPatches, enablePatches, produceWithPatches } from "immer";
@@ -124,6 +124,12 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
124
124
  });
125
125
  celldata === null || celldata === void 0 ? void 0 : celldata.forEach(function (d) {
126
126
  expandedData_1[d.r][d.c] = d.v;
127
+ var cell = d.v;
128
+ if (cell && cell.ct && cell.ct.t === "d" && (cell.m === undefined || cell.m === null)) {
129
+ try {
130
+ cell.m = update(cell.ct.fa || "General", cell.v);
131
+ } catch (e) {}
132
+ }
127
133
  });
128
134
  draftCtx.luckysheetfile = produce(draftCtx.luckysheetfile, function (d) {
129
135
  d[index].data = expandedData_1;
@@ -142,6 +148,101 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
142
148
  onOp(patchToOp(ctx, patches, options, undo));
143
149
  }
144
150
  }, [onOp]);
151
+ var emitYjsFromPatches = useCallback(function (ctxBefore, ctxAfter, patches) {
152
+ var _a;
153
+ var _b = (_a = ctxBefore.hooks) !== null && _a !== void 0 ? _a : {},
154
+ updateCellYdoc = _b.updateCellYdoc,
155
+ updateAllCell = _b.updateAllCell;
156
+ if (!updateCellYdoc) return;
157
+ var mapFields = new Set(["celldata", "calcChain", "dataBlockCalcFunction", "liveQueryList", "dataVerification", "hyperlink", "conditionRules"]);
158
+ var changeMap = new Map();
159
+ var upsert = function upsert(change) {
160
+ var _a, _b, _c;
161
+ var k = "".concat(change.sheetId, ":").concat((_b = (_a = change.path) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "", ":").concat((_c = change.key) !== null && _c !== void 0 ? _c : "");
162
+ changeMap.set(k, change);
163
+ };
164
+ var upsertCell = function upsertCell(sheetId, r, c) {
165
+ var _a, _b, _c;
166
+ var cell = (_c = (_b = (_a = getFlowdata(ctxAfter, sheetId)) === null || _a === void 0 ? void 0 : _a[r]) === null || _b === void 0 ? void 0 : _b[c]) !== null && _c !== void 0 ? _c : null;
167
+ var key = "".concat(r, "_").concat(c);
168
+ upsert({
169
+ sheetId: sheetId,
170
+ path: ["celldata"],
171
+ key: key,
172
+ value: {
173
+ r: r,
174
+ c: c,
175
+ v: cell
176
+ },
177
+ type: cell == null ? "delete" : "update"
178
+ });
179
+ };
180
+ patches.forEach(function (p) {
181
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
182
+ var path = p.path;
183
+ if ((path === null || path === void 0 ? void 0 : path[0]) !== "luckysheetfile") return;
184
+ var sheetIndex = path[1];
185
+ if (!_.isNumber(sheetIndex)) return;
186
+ var sheetBefore = (_a = ctxBefore.luckysheetfile) === null || _a === void 0 ? void 0 : _a[sheetIndex];
187
+ var sheetAfter = (_b = ctxAfter.luckysheetfile) === null || _b === void 0 ? void 0 : _b[sheetIndex];
188
+ var sheetId = (sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.id) || (sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.id);
189
+ if (!sheetId) return;
190
+ var root = path[2];
191
+ if (root === "data") {
192
+ if (_.isNumber(path[3]) && _.isNumber(path[4])) {
193
+ upsertCell(sheetId, path[3], path[4]);
194
+ return;
195
+ }
196
+ if (_.isNumber(path[3]) && path.length === 4) {
197
+ var r = path[3];
198
+ var beforeRow = (_d = (_c = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _c === void 0 ? void 0 : _c[r]) !== null && _d !== void 0 ? _d : [];
199
+ var afterRow = (_f = (_e = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _e === void 0 ? void 0 : _e[r]) !== null && _f !== void 0 ? _f : [];
200
+ var max = Math.max((_g = beforeRow.length) !== null && _g !== void 0 ? _g : 0, (_h = afterRow.length) !== null && _h !== void 0 ? _h : 0);
201
+ for (var c = 0; c < max; c += 1) {
202
+ if (!_.isEqual((_j = beforeRow[c]) !== null && _j !== void 0 ? _j : null, (_k = afterRow[c]) !== null && _k !== void 0 ? _k : null)) {
203
+ upsertCell(sheetId, r, c);
204
+ }
205
+ }
206
+ return;
207
+ }
208
+ if (path.length === 3) {
209
+ var dataAfter = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data;
210
+ var rows = (_l = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter.length) !== null && _l !== void 0 ? _l : 0;
211
+ var cols = rows > 0 ? (_o = (_m = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter[0]) === null || _m === void 0 ? void 0 : _m.length) !== null && _o !== void 0 ? _o : 0 : 0;
212
+ var size = rows * cols;
213
+ if (size > 50000 && updateAllCell) {
214
+ updateAllCell(sheetId);
215
+ return;
216
+ }
217
+ for (var r = 0; r < rows; r += 1) {
218
+ var beforeRow = (_q = (_p = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _p === void 0 ? void 0 : _p[r]) !== null && _q !== void 0 ? _q : [];
219
+ var afterRow = (_s = (_r = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _r === void 0 ? void 0 : _r[r]) !== null && _s !== void 0 ? _s : [];
220
+ var max = Math.max((_t = beforeRow.length) !== null && _t !== void 0 ? _t : 0, (_u = afterRow.length) !== null && _u !== void 0 ? _u : 0);
221
+ for (var c = 0; c < max; c += 1) {
222
+ if (!_.isEqual((_v = beforeRow[c]) !== null && _v !== void 0 ? _v : null, (_w = afterRow[c]) !== null && _w !== void 0 ? _w : null)) {
223
+ upsertCell(sheetId, r, c);
224
+ }
225
+ }
226
+ }
227
+ }
228
+ return;
229
+ }
230
+ if (typeof root === "string" && mapFields.has(root)) {
231
+ var key = path[3];
232
+ if (typeof key === "string") {
233
+ upsert({
234
+ sheetId: sheetId,
235
+ path: [root],
236
+ key: key,
237
+ value: p.value,
238
+ type: p.op === "remove" || p.value == null ? "delete" : "update"
239
+ });
240
+ }
241
+ }
242
+ });
243
+ var changes = Array.from(changeMap.values());
244
+ if (changes.length > 0) updateCellYdoc(changes);
245
+ }, []);
145
246
  function reduceUndoList(ctx, ctxBefore) {
146
247
  var sheetsId = ctx.luckysheetfile.map(function (sheet) {
147
248
  return sheet.id;
@@ -299,6 +400,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
299
400
  delete inversedOptions.addSheet.value.data;
300
401
  }
301
402
  emitOp(newContext, history.inversePatches, inversedOptions, true);
403
+ emitYjsFromPatches(ctx_, newContext, history.inversePatches);
302
404
  var sheetIdxAfterUndo = getSheetIndex(newContext, newContext.currentSheetId);
303
405
  var nw = __assign(__assign({}, newContext), sheetIdxAfterUndo != null && ((_f = newContext.luckysheetfile[sheetIdxAfterUndo]) === null || _f === void 0 ? void 0 : _f.config) != null ? {
304
406
  config: newContext.luckysheetfile[sheetIdxAfterUndo].config
@@ -327,6 +429,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
327
429
  });
328
430
  globalCache.current.undoList.push(history);
329
431
  emitOp(newContext, history.patches, history.options);
432
+ emitYjsFromPatches(ctx_, newContext, history.patches);
330
433
  var sheetIdxAfterRedo = getSheetIndex(newContext, newContext.currentSheetId);
331
434
  var nw = __assign(__assign({}, newContext), sheetIdxAfterRedo != null && ((_a = newContext.luckysheetfile[sheetIdxAfterRedo]) === null || _a === void 0 ? void 0 : _a.config) != null ? {
332
435
  config: newContext.luckysheetfile[sheetIdxAfterRedo].config
@@ -353,18 +456,13 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
353
456
  useEffect(function () {
354
457
  var _a, _b;
355
458
  setContext(function (ctx) {
356
- var _a, _b;
357
459
  var gridData = getFlowdata(ctx);
358
460
  var cellData = api.dataToCelldata(gridData);
359
- var denominatedUsed = false;
360
- for (var _i = 0, cellData_1 = cellData; _i < cellData_1.length; _i++) {
361
- var cell = cellData_1[_i];
461
+ var denominatedUsed = (cellData !== null && cellData !== void 0 ? cellData : []).some(function (cell) {
462
+ var _a, _b;
362
463
  var value = (_b = (_a = cell === null || cell === void 0 ? void 0 : cell.v) === null || _a === void 0 ? void 0 : _a.m) === null || _b === void 0 ? void 0 : _b.toString();
363
- if ((value === null || value === void 0 ? void 0 : value.includes("BTC")) || (value === null || value === void 0 ? void 0 : value.includes("ETH")) || (value === null || value === void 0 ? void 0 : value.includes("SOL"))) {
364
- denominatedUsed = true;
365
- break;
366
- }
367
- }
464
+ return (value === null || value === void 0 ? void 0 : value.includes("BTC")) || (value === null || value === void 0 ? void 0 : value.includes("ETH")) || (value === null || value === void 0 ? void 0 : value.includes("SOL"));
465
+ });
368
466
  var denoWarn = document.getElementById("denomination-warning");
369
467
  var scrollBar = document.getElementsByClassName("luckysheet-scrollbar-x")[0];
370
468
  if (denominatedUsed && denoWarn) {
@@ -438,6 +536,32 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
438
536
  context.hooks.afterOrderChanges();
439
537
  }
440
538
  }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.order]);
539
+ var sheetColorSig = useMemo(function () {
540
+ var _a;
541
+ return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
542
+ var _a;
543
+ return "".concat(s.id, ":").concat((_a = s.color) !== null && _a !== void 0 ? _a : "");
544
+ }).join("|");
545
+ }, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
546
+ useEffect(function () {
547
+ var _a;
548
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterColorChanges) {
549
+ context.hooks.afterColorChanges();
550
+ }
551
+ }, [sheetColorSig]);
552
+ var sheetHideSig = useMemo(function () {
553
+ var _a;
554
+ return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
555
+ var _a;
556
+ return "".concat(s.id, ":").concat((_a = s.hide) !== null && _a !== void 0 ? _a : 0);
557
+ }).join("|");
558
+ }, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
559
+ useEffect(function () {
560
+ var _a;
561
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterHideChanges) {
562
+ context.hooks.afterHideChanges();
563
+ }
564
+ }, [sheetHideSig]);
441
565
  useEffect(function () {
442
566
  var _a;
443
567
  if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterConfigChanges) {
@@ -504,6 +628,18 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
504
628
  context.hooks.conditionFormatChange();
505
629
  }
506
630
  }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.luckysheet_conditionformat_save]);
631
+ useEffect(function () {
632
+ var _a;
633
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.filterSelectChange) {
634
+ context.hooks.filterSelectChange();
635
+ }
636
+ }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.filter_select]);
637
+ useEffect(function () {
638
+ var _a;
639
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.filterChange) {
640
+ context.hooks.filterChange();
641
+ }
642
+ }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.filter]);
507
643
  useEffect(function () {
508
644
  var _a;
509
645
  if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.hyperlinkChange) {
@@ -274,9 +274,12 @@ export function convertCellsToCrypto(_a) {
274
274
  });
275
275
  });
276
276
  setContext(function (ctx) {
277
+ var _a;
277
278
  var d = getFlowdata(ctx);
278
279
  if (!d || !Array.isArray(d)) return;
280
+ var ydocChanges = [];
279
281
  cellUpdates.forEach(function (_a) {
282
+ var _b, _c;
280
283
  var row = _a.row,
281
284
  col = _a.col,
282
285
  baseValue = _a.baseValue,
@@ -296,7 +299,21 @@ export function convertCellsToCrypto(_a) {
296
299
  cellCp.baseCurrency = baseCurrency.toLowerCase();
297
300
  cellCp.baseCurrencyPrice = baseCurrencyPrice;
298
301
  d[row][col] = cellCp;
302
+ ydocChanges.push({
303
+ sheetId: ctx.currentSheetId,
304
+ path: ["celldata"],
305
+ value: {
306
+ r: row,
307
+ c: col,
308
+ v: (_c = (_b = d[row]) === null || _b === void 0 ? void 0 : _b[col]) !== null && _c !== void 0 ? _c : null
309
+ },
310
+ key: "".concat(row, "_").concat(col),
311
+ type: "update"
312
+ });
299
313
  });
314
+ if (ydocChanges.length > 0 && ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc)) {
315
+ ctx.hooks.updateCellYdoc(ydocChanges);
316
+ }
300
317
  });
301
318
  setContext(function (ctx) {
302
319
  api.calculateSheetFromula(ctx, ctx.currentSheetId);
@@ -303,6 +303,10 @@ var ConditionRules = function ConditionRules(_a) {
303
303
  text: "textContains",
304
304
  value: "()",
305
305
  label: "Text Contains"
306
+ }, {
307
+ text: "empty",
308
+ value: "",
309
+ label: "Empty"
306
310
  }, {
307
311
  text: "occurrenceDate",
308
312
  value: conditionformat.yesterday,
@@ -343,7 +347,7 @@ var ConditionRules = function ConditionRules(_a) {
343
347
  marginBottom: "16px"
344
348
  }
345
349
  }, matchedConditionFormatKey.map(function (key) {
346
- var _a, _b;
350
+ var _a, _b, _c;
347
351
  return /*#__PURE__*/_react.default.createElement("div", {
348
352
  onClick: function onClick() {
349
353
  var _a;
@@ -394,10 +398,10 @@ var ConditionRules = function ConditionRules(_a) {
394
398
  }, /*#__PURE__*/_react.default.createElement("h3", {
395
399
  className: "fortune-condition-rules__heading condition-list-type",
396
400
  "data-testid": "condition-rules-heading-".concat(key)
397
- }, conditionformat[allConditionFormats[key].conditionName], " ", (_a = allConditionFormats[key].conditionValue) === null || _a === void 0 ? void 0 : _a[0]), /*#__PURE__*/_react.default.createElement("p", {
401
+ }, conditionformat[allConditionFormats[key].conditionName], allConditionFormats[key].conditionName !== "empty" && " ".concat((_b = (_a = allConditionFormats[key].conditionValue) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "")), /*#__PURE__*/_react.default.createElement("p", {
398
402
  className: "fortune-condition-rules__para condition-list-range",
399
403
  "data-testid": "condition-rules-para-".concat(key)
400
- }, (_b = allConditionFormats[key].cellrange) === null || _b === void 0 ? void 0 : _b.map(function (range) {
404
+ }, (_c = allConditionFormats[key].cellrange) === null || _c === void 0 ? void 0 : _c.map(function (range) {
401
405
  var startCol = (0, _helper.numberToColumn)(range.column[0] + 1);
402
406
  var endCol = (0, _helper.numberToColumn)(range.column[1] + 1);
403
407
  var startRow = range.row[0] + 1;
@@ -476,6 +480,12 @@ var ConditionRules = function ConditionRules(_a) {
476
480
  }, "Format cells if"), /*#__PURE__*/_react.default.createElement(_ui.Select, {
477
481
  value: type,
478
482
  onValueChange: function onValueChange(value) {
483
+ if (value === "empty" || type === "empty") {
484
+ setContext(function (ctx) {
485
+ ctx.conditionRules.rulesValue = "";
486
+ });
487
+ setEditConditionFormatValue(null);
488
+ }
479
489
  setType(value);
480
490
  }
481
491
  }, /*#__PURE__*/_react.default.createElement(_ui.SelectTrigger, null, /*#__PURE__*/_react.default.createElement(_ui.SelectValue, null, /*#__PURE__*/_react.default.createElement("div", {
@@ -813,7 +823,7 @@ var ConditionRules = function ConditionRules(_a) {
813
823
  },
814
824
  tabIndex: 0
815
825
  }, button.cancel), editConditionFormatKey !== null ? (/*#__PURE__*/_react.default.createElement(_ui.Button, {
816
- disabled: context.conditionRules.rulesValue === "",
826
+ disabled: context.conditionRules.rulesValue === "" && type !== "empty",
817
827
  variant: "default",
818
828
  style: {
819
829
  minWidth: "80px"
@@ -823,7 +833,7 @@ var ConditionRules = function ConditionRules(_a) {
823
833
  },
824
834
  tabIndex: 0
825
835
  }, "Update rule")) : (/*#__PURE__*/_react.default.createElement(_ui.Button, {
826
- disabled: context.conditionRules.rulesValue === "",
836
+ disabled: context.conditionRules.rulesValue === "" && type !== "empty",
827
837
  variant: "default",
828
838
  style: {
829
839
  minWidth: "80px"
@@ -116,6 +116,9 @@ var ConditionalFormat = function ConditionalFormat(_a) {
116
116
  }, {
117
117
  text: "textContains",
118
118
  value: "()"
119
+ }, {
120
+ text: "empty",
121
+ value: ""
119
122
  }, {
120
123
  text: "occurrenceDate",
121
124
  value: conditionformat.yesterday
@@ -14,7 +14,7 @@ var TEXT_COLORS = exports.TEXT_COLORS = [{
14
14
  value: "228, 232, 237"
15
15
  }, {
16
16
  name: "White",
17
- value: "249, 249, 249"
17
+ value: "219, 233, 236"
18
18
  }, {
19
19
  name: "Pink",
20
20
  value: "244, 217, 227"
@@ -29,47 +29,47 @@ var __assign = void 0 && (void 0).__assign || function () {
29
29
  return __assign.apply(this, arguments);
30
30
  };
31
31
  var InputBox = function InputBox() {
32
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
33
- var _m = (0, _react.useContext)(_context.default),
34
- context = _m.context,
35
- setContext = _m.setContext,
36
- refs = _m.refs;
32
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
33
+ var _p = (0, _react.useContext)(_context.default),
34
+ context = _p.context,
35
+ setContext = _p.setContext,
36
+ refs = _p.refs;
37
37
  var inputRef = (0, _react.useRef)(null);
38
38
  var lastKeyDownEventRef = (0, _react.useRef)(null);
39
39
  var prevCellUpdate = (0, _usePrevious.default)(context.luckysheetCellUpdate);
40
40
  var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
41
- var _o = (0, _react.useState)(false),
42
- isHidenRC = _o[0],
43
- setIsHidenRC = _o[1];
44
- var _p = (0, _react.useState)(false),
45
- isInputBoxActive = _p[0],
46
- setIsInputBoxActive = _p[1];
47
- var _q = (0, _react.useState)(""),
48
- activeCell = _q[0],
49
- setActiveCell = _q[1];
50
- var _r = (0, _react.useState)(""),
51
- activeRefCell = _r[0],
52
- setActiveRefCell = _r[1];
53
- var _s = (0, _react.useState)({
41
+ var _q = (0, _react.useState)(false),
42
+ isHidenRC = _q[0],
43
+ setIsHidenRC = _q[1];
44
+ var _r = (0, _react.useState)(false),
45
+ isInputBoxActive = _r[0],
46
+ setIsInputBoxActive = _r[1];
47
+ var _s = (0, _react.useState)(""),
48
+ activeCell = _s[0],
49
+ setActiveCell = _s[1];
50
+ var _t = (0, _react.useState)(""),
51
+ activeRefCell = _t[0],
52
+ setActiveRefCell = _t[1];
53
+ var _u = (0, _react.useState)({
54
54
  left: 0,
55
55
  top: 0
56
56
  }),
57
- frozenPosition = _s[0],
58
- setFrozenPosition = _s[1];
57
+ frozenPosition = _u[0],
58
+ setFrozenPosition = _u[1];
59
59
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
60
- var _t = (0, _react.useState)({}),
61
- firstSelectionActiveCell = _t[0],
62
- setFirstSelectionActiveCell = _t[1];
63
- var _u = (0, _react.useState)(0),
64
- commaCount = _u[0],
65
- setCommaCount = _u[1];
60
+ var _v = (0, _react.useState)({}),
61
+ firstSelectionActiveCell = _v[0],
62
+ setFirstSelectionActiveCell = _v[1];
63
+ var _w = (0, _react.useState)(0),
64
+ commaCount = _w[0],
65
+ setCommaCount = _w[1];
66
66
  var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
67
- var _v = (0, _react.useState)(!hideFormulaHintLocal),
68
- showFormulaHint = _v[0],
69
- setShowFormulaHint = _v[1];
70
- var _w = (0, _react.useState)(false),
71
- showSearchHint = _w[0],
72
- setShowSearchHint = _w[1];
67
+ var _x = (0, _react.useState)(!hideFormulaHintLocal),
68
+ showFormulaHint = _x[0],
69
+ setShowFormulaHint = _x[1];
70
+ var _y = (0, _react.useState)(false),
71
+ showSearchHint = _y[0],
72
+ setShowSearchHint = _y[1];
73
73
  var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
74
74
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
75
75
  var preText = (0, _react.useRef)("");
@@ -77,9 +77,9 @@ var InputBox = function InputBox() {
77
77
  var isComposingRef = (0, _react.useRef)(false);
78
78
  var ZWSP = "\u200B";
79
79
  var inputBoxInnerRef = (0, _react.useRef)(null);
80
- var _x = (0, _react.useState)([]),
81
- linkSelectionHighlightRects = _x[0],
82
- setLinkSelectionHighlightRects = _x[1];
80
+ var _z = (0, _react.useState)([]),
81
+ linkSelectionHighlightRects = _z[0],
82
+ setLinkSelectionHighlightRects = _z[1];
83
83
  var ensureNotEmpty = function ensureNotEmpty() {
84
84
  var el = inputRef.current;
85
85
  if (!el) return;
@@ -115,7 +115,7 @@ var InputBox = function InputBox() {
115
115
  return style;
116
116
  }
117
117
  return {};
118
- }, [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]);
118
+ }, [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, (_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.innerText]);
119
119
  (0, _react.useLayoutEffect)(function () {
120
120
  var _a;
121
121
  if (!context.allowEdit) {
@@ -138,6 +138,8 @@ var InputBox = function InputBox() {
138
138
  var flowdata = (0, _fortuneCore.getFlowdata)(context);
139
139
  var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index]) === null || _a === void 0 ? void 0 : _a[col_index];
140
140
  var value_1 = "";
141
+ var wasOverwrite = refs.globalCache.overwriteCell;
142
+ var overwriteFirstChar = refs.globalCache.overwriteCellFirstChar;
141
143
  if (cell && !refs.globalCache.overwriteCell) {
142
144
  if ((0, _fortuneCore.isInlineStringCell)(cell)) {
143
145
  value_1 = (0, _fortuneCore.getInlineStringHTML)(row_index, col_index, flowdata);
@@ -154,9 +156,15 @@ var InputBox = function InputBox() {
154
156
  }
155
157
  }
156
158
  refs.globalCache.overwriteCell = false;
157
- if (!refs.globalCache.ignoreWriteCell && inputRef.current && value_1) {
159
+ delete refs.globalCache.overwriteCellFirstChar;
160
+ if (wasOverwrite && inputRef.current) {
161
+ inputRef.current.innerText = overwriteFirstChar !== null && overwriteFirstChar !== void 0 ? overwriteFirstChar : "";
162
+ if (overwriteFirstChar) {
163
+ (0, _fortuneCore.moveToEnd)(inputRef.current);
164
+ }
165
+ } else if (!refs.globalCache.ignoreWriteCell && inputRef.current && value_1) {
158
166
  inputRef.current.innerHTML = (0, _fortuneCore.escapeHTMLTag)((0, _fortuneCore.escapeScriptTag)(value_1));
159
- } else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1) {
167
+ } else if (!refs.globalCache.ignoreWriteCell && inputRef.current && !value_1 && !wasOverwrite) {
160
168
  var valueD = (0, _fortuneCore.getCellValue)(row_index, col_index, flowdata, "f");
161
169
  inputRef.current.innerText = valueD;
162
170
  }
@@ -184,7 +192,7 @@ var InputBox = function InputBox() {
184
192
  if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) || _lodash.default.isEmpty(context.luckysheetCellUpdate)) {
185
193
  setIsInputBoxActive(false);
186
194
  }
187
- }, [firstSelection, (_c = context.rangeDialog) === null || _c === void 0 ? void 0 : _c.show, context.luckysheetCellUpdate]);
195
+ }, [firstSelection, (_d = context.rangeDialog) === null || _d === void 0 ? void 0 : _d.show, context.luckysheetCellUpdate]);
188
196
  var getActiveFormula = (0, _react.useCallback)(function () {
189
197
  return document.querySelector(".luckysheet-formula-search-item-active");
190
198
  }, []);
@@ -279,6 +287,54 @@ var InputBox = function InputBox() {
279
287
  event.stopPropagation();
280
288
  event.preventDefault();
281
289
  };
290
+ (0, _react.useEffect)(function () {
291
+ var _a, _b;
292
+ var selection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
293
+ var editor = inputRef.current;
294
+ if (!selection || !editor || !isInputBoxActive || ((_b = context.rangeDialog) === null || _b === void 0 ? void 0 : _b.show)) {
295
+ return;
296
+ }
297
+ var rowSel = selection.row;
298
+ var colSel = selection.column;
299
+ if (!rowSel || !colSel || rowSel.length < 2 || colSel.length < 2) return;
300
+ var rowStart = Math.min(rowSel[0], rowSel[1]);
301
+ var rowEnd = Math.max(rowSel[0], rowSel[1]);
302
+ var colStart = Math.min(colSel[0], colSel[1]);
303
+ var colEnd = Math.max(colSel[0], colSel[1]);
304
+ var startRef = "".concat((0, _fortuneCore.indexToColumnChar)(colStart)).concat(rowStart + 1);
305
+ var endRef = "".concat((0, _fortuneCore.indexToColumnChar)(colEnd)).concat(rowEnd + 1);
306
+ var refText = startRef === endRef ? startRef : "".concat(startRef, ":").concat(endRef);
307
+ var editorText = editor.innerText || "";
308
+ if (!editorText.startsWith("=")) return;
309
+ var spans = editor.querySelectorAll("span");
310
+ var lastSpan = spans[spans.length - 1];
311
+ var lastSpanText = (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) || "";
312
+ var isA1RangePattern = /^[a-zA-Z]+\d+:[a-zA-Z]+\d+$/.test(lastSpanText);
313
+ var notFunctionInit = !editorText.includes("(");
314
+ var refNotAllowed = lastSpanText.includes(")") || notFunctionInit && /^[a-zA-Z]+$/.test(lastSpanText) && !_lodash.default.includes(["="], lastSpanText);
315
+ var shouldHandleRef = (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.classList.contains("fortune-formula-functionrange-cell")) || (0, _helper.isLetterNumberPattern)(lastSpanText) || isA1RangePattern || (lastSpanText === "(" || lastSpanText === "," || lastSpanText.includes(":") || lastSpanText === "=") && !lastSpanText.includes('"') && !refNotAllowed && !/^[a-zA-Z]+$/.test(lastSpanText);
316
+ if (!shouldHandleRef) return;
317
+ var refSpanHtml = "<span class=\"fortune-formula-functionrange-cell\" rangeindex=\"0\" dir=\"auto\" style=\"color:#c1232b;\">".concat(refText, "</span>");
318
+ if (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.classList.contains("fortune-formula-functionrange-cell")) {
319
+ if (lastSpan.textContent !== refText) lastSpan.textContent = refText;
320
+ setTimeout(function () {
321
+ return (0, _helper.moveCursorToEnd)(editor);
322
+ }, 1);
323
+ return;
324
+ }
325
+ if ((0, _helper.isLetterNumberPattern)(lastSpanText) || isA1RangePattern) {
326
+ var htmlR = (0, _helper.removeLastSpan)(editor.innerHTML);
327
+ editor.innerHTML = "".concat(htmlR).concat(refSpanHtml);
328
+ setTimeout(function () {
329
+ return (0, _helper.moveCursorToEnd)(editor);
330
+ }, 1);
331
+ return;
332
+ }
333
+ editor.innerHTML = "".concat(editor.innerHTML).concat(refSpanHtml);
334
+ setTimeout(function () {
335
+ return (0, _helper.moveCursorToEnd)(editor);
336
+ }, 1);
337
+ }, [context.luckysheet_select_save, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show, isInputBoxActive]);
282
338
  var onKeyDown = (0, _react.useCallback)(function (e) {
283
339
  var _a, _b;
284
340
  lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
@@ -311,37 +367,18 @@ var InputBox = function InputBox() {
311
367
  }, 5);
312
368
  }
313
369
  }
314
- var refCell = placeRef.current;
315
- if (e.key === "ArrowUp") {
316
- refCell = (0, _helper.decrementRow)(placeRef.current);
317
- } else if (e.key === "ArrowDown") {
318
- refCell = (0, _helper.incrementRow)(placeRef.current);
319
- } else if (e.key === "ArrowLeft") {
320
- refCell = (0, _helper.decrementColumn)(placeRef.current);
321
- } else if (e.key === "ArrowRight") {
322
- refCell = (0, _helper.incrementColumn)(placeRef.current);
323
- }
324
- 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")) {
325
- var parser = new DOMParser();
326
- 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");
327
- var spans = doc.querySelectorAll("span");
328
- var lastSpan = spans[spans.length - 1];
329
- var notFunctionInit = !((_b = document.getElementById("luckysheet-rich-text-editor")) === null || _b === void 0 ? void 0 : _b.innerText.includes("("));
330
- var arrowRefNotAllowed = (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes(")")) || notFunctionInit && /^[a-zA-Z]+$/.test(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) && !_lodash.default.includes(["="], lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText);
331
- if (((lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) === "(" || (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) === "," || (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes(":")) || (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) !== ")") && !(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes('"')) && !(0, _helper.isLetterNumberPattern)(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) && !arrowRefNotAllowed && !/^[a-zA-Z]+$/.test(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText)) {
332
- allowListNavigation = false;
333
- inputRef.current.innerHTML = "".concat(inputRef.current.innerHTML, "<span class=\"fortune-formula-functionrange-cell\" rangeindex=\"0\" dir=\"auto\" style=\"color:#c1232b;\">").concat(refCell, "</span>");
334
- setTimeout(function () {
335
- (0, _helper.moveCursorToEnd)(inputRef.current);
336
- }, 1);
337
- }
338
- if ((0, _helper.isLetterNumberPattern)(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText)) {
370
+ var isArrowKey = e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight";
371
+ if (isArrowKey && !((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")) {
372
+ var editorText = ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.innerText) || "";
373
+ var lastSpanText = getLastInputSpanText() || "";
374
+ var isA1RangePattern = /^[a-zA-Z]+\d+:[a-zA-Z]+\d+$/.test(lastSpanText);
375
+ var notFunctionInit = !editorText.includes("(");
376
+ var refNotAllowed = lastSpanText.includes(")") || notFunctionInit && /^[a-zA-Z]+$/.test(lastSpanText) && !_lodash.default.includes(["="], lastSpanText);
377
+ var shouldTreatAsRefNavigation = editorText.startsWith("=") && (Boolean((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.querySelector(".fortune-formula-functionrange-cell")) || (0, _helper.isLetterNumberPattern)(lastSpanText) || isA1RangePattern || (lastSpanText === "(" || lastSpanText === "," || lastSpanText.includes(":") || lastSpanText === "=") && !lastSpanText.includes('"') && !refNotAllowed && !/^[a-zA-Z]+$/.test(lastSpanText));
378
+ if (shouldTreatAsRefNavigation) {
339
379
  allowListNavigation = false;
340
- var htmlR = (0, _helper.removeLastSpan)(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.innerHTML);
341
- inputRef.current.innerHTML = "".concat(htmlR, "<span class=\"fortune-formula-functionrange-cell\" rangeindex=\"0\" dir=\"auto\" style=\"color:#c1232b;\">").concat(refCell, "</span>");
342
- (0, _helper.moveCursorToEnd)(inputRef.current);
343
380
  setTimeout(function () {
344
- (0, _helper.moveCursorToEnd)(inputRef.current);
381
+ if (inputRef.current) (0, _helper.moveCursorToEnd)(inputRef.current);
345
382
  }, 1);
346
383
  }
347
384
  }
@@ -399,7 +436,7 @@ var InputBox = function InputBox() {
399
436
  }
400
437
  e.preventDefault();
401
438
  }
402
- }, [clearSearchItemActiveClass, context.luckysheetCellUpdate.length, selectActiveFormula, setContext, firstSelection]);
439
+ }, [clearSearchItemActiveClass, context.luckysheetCellUpdate.length, selectActiveFormula, setContext]);
403
440
  var handleHideShowHint = function handleHideShowHint() {
404
441
  var _a, _b, _c, _d;
405
442
  var searchElFx = (_a = document.getElementsByClassName("fx-search")) === null || _a === void 0 ? void 0 : _a[0];
@@ -489,7 +526,7 @@ var InputBox = function InputBox() {
489
526
  zIndex: _lodash.default.isEmpty(context.luckysheetCellUpdate) ? -1 : 19,
490
527
  display: "block"
491
528
  };
492
- }, [firstSelection, (_d = context.rangeDialog) === null || _d === void 0 ? void 0 : _d.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
529
+ }, [firstSelection, (_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
493
530
  (0, _react.useEffect)(function () {
494
531
  var _a;
495
532
  if (firstSelection && !((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) && !isInputBoxActive && !_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
@@ -505,7 +542,7 @@ var InputBox = function InputBox() {
505
542
  setIsInputBoxActive(true);
506
543
  }
507
544
  }
508
- }, [firstSelection, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
545
+ }, [firstSelection, (_g = context.rangeDialog) === null || _g === void 0 ? void 0 : _g.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
509
546
  var getAddressIndicatorPosition = (0, _react.useCallback)(function () {
510
547
  var _a;
511
548
  if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
@@ -518,7 +555,7 @@ var InputBox = function InputBox() {
518
555
  left: "0",
519
556
  display: "block"
520
557
  };
521
- }, [firstSelection, (_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show]);
558
+ }, [firstSelection, (_h = context.rangeDialog) === null || _h === void 0 ? void 0 : _h.show]);
522
559
  var getCellAddress = (0, _react.useCallback)(function () {
523
560
  if (!firstSelection) return "";
524
561
  var rowIndex = firstSelection.row_focus || 0;
@@ -568,7 +605,7 @@ var InputBox = function InputBox() {
568
605
  };
569
606
  });
570
607
  setLinkSelectionHighlightRects(relative);
571
- }, [(_g = context.linkCard) === null || _g === void 0 ? void 0 : _g.applyToSelection, (_h = context.linkCard) === null || _h === void 0 ? void 0 : _h.selectionOffsets, (_j = context.linkCard) === null || _j === void 0 ? void 0 : _j.r, (_k = context.linkCard) === null || _k === void 0 ? void 0 : _k.c, context.luckysheetCellUpdate]);
608
+ }, [(_j = context.linkCard) === null || _j === void 0 ? void 0 : _j.applyToSelection, (_k = context.linkCard) === null || _k === void 0 ? void 0 : _k.selectionOffsets, (_l = context.linkCard) === null || _l === void 0 ? void 0 : _l.r, (_m = context.linkCard) === null || _m === void 0 ? void 0 : _m.c, context.luckysheetCellUpdate]);
572
609
  var wraperGetCell = function wraperGetCell() {
573
610
  var cell = getCellAddress();
574
611
  placeRef.current = cell;
@@ -605,7 +642,7 @@ var InputBox = function InputBox() {
605
642
  onMouseUp: function onMouseUp(e) {
606
643
  return e.stopPropagation();
607
644
  }
608
- }, firstSelection && !((_l = context.rangeDialog) === null || _l === void 0 ? void 0 : _l.show) && (/*#__PURE__*/_react.default.createElement("div", {
645
+ }, firstSelection && !((_o = context.rangeDialog) === null || _o === void 0 ? void 0 : _o.show) && (/*#__PURE__*/_react.default.createElement("div", {
609
646
  className: "luckysheet-cell-address-indicator",
610
647
  style: getAddressIndicatorPosition()
611
648
  }, wraperGetCell())), /*#__PURE__*/_react.default.createElement("div", {