@fileverse-dev/fortune-core 1.3.10-copyPaste-3 → 1.3.10-input-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.
@@ -378,10 +378,10 @@ export function handleArrowKey(ctx, e) {
378
378
  }
379
379
  }
380
380
  export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, handleRedo, canvas) {
381
- var _a, _b, _c;
381
+ var _a, _b, _c, _d;
382
382
  return __awaiter(this, void 0, void 0, function () {
383
- var kcode, kstr, allowEdit, isFxInput, ignoredKeys, restCod, last, row_index, col_index, last, row_index, col_index;
384
- return __generator(this, function (_d) {
383
+ var kcode, kstr, allowEdit, isFxInput, ignoredKeys, restCod, last, row_index, col_index, isEditing, inputText, isFormulaEdit, enteredByTyping, last, row_index, col_index;
384
+ return __generator(this, function (_e) {
385
385
  if (e.shiftKey && e.code === "Space") {
386
386
  e.stopImmediatePropagation();
387
387
  e.stopPropagation();
@@ -475,7 +475,18 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
475
475
  jfrefreshgrid(ctx, null, undefined);
476
476
  e.preventDefault();
477
477
  } else if (kstr === "ArrowUp" || kstr === "ArrowDown" || kstr === "ArrowLeft" || kstr === "ArrowRight") {
478
- handleArrowKey(ctx, e);
478
+ isEditing = ctx.luckysheetCellUpdate.length > 0;
479
+ inputText = (_d = cellInput === null || cellInput === void 0 ? void 0 : cellInput.innerText) !== null && _d !== void 0 ? _d : "";
480
+ isFormulaEdit = isEditing && inputText.trim().startsWith("=");
481
+ enteredByTyping = cache.enteredEditByTyping === true;
482
+ if (isEditing && !isFormulaEdit && enteredByTyping) {
483
+ updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
484
+ cache.enteredEditByTyping = false;
485
+ handleArrowKey(ctx, e);
486
+ e.preventDefault();
487
+ } else {
488
+ handleArrowKey(ctx, e);
489
+ }
479
490
  } else if (!(kcode >= 112 && kcode <= 123 || kcode <= 46 || kcode === 144 || kcode === 108 || e.ctrlKey || e.altKey || e.shiftKey && (kcode === 37 || kcode === 38 || kcode === 39 || kcode === 40)) || kcode === 8 || kcode === 32 || kcode === 46 || kcode === 0 || e.ctrlKey && kcode === 86) {
480
491
  if (!allowEdit) return [2];
481
492
  if (String.fromCharCode(kcode) != null && !_.isEmpty(ctx.luckysheet_select_save) && kstr !== "CapsLock" && kstr !== "Win" && kcode !== 18) {
@@ -484,7 +495,10 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
484
495
  col_index = last.column_focus;
485
496
  ctx.luckysheetCellUpdate = [row_index, col_index];
486
497
  cache.overwriteCell = true;
498
+ cache.overwriteCellFirstChar = e.key;
499
+ cache.enteredEditByTyping = true;
487
500
  handleFormulaInput(ctx, fxInput, cellInput, kcode);
501
+ e.preventDefault();
488
502
  }
489
503
  }
490
504
  }
@@ -487,6 +487,7 @@ export function handleCellAreaDoubleClick(ctx, globalCache, settings, e, contain
487
487
  row_index = row_focus;
488
488
  col_index = column_focus;
489
489
  }
490
+ globalCache.enteredEditByTyping = false;
490
491
  luckysheetUpdateCell(ctx, row_index, col_index);
491
492
  }
492
493
  export function handleContextMenu(ctx, settings, e, workbookContainer, container, area) {
@@ -1041,7 +1041,7 @@ export function getFontStyleByCell(cell, checksAF, checksCF, isCheck) {
1041
1041
  if (key === "it" && valueNum !== 0) {
1042
1042
  style.fontStyle = "italic";
1043
1043
  }
1044
- if (key === "fs" && !_.isNil(value)) {
1044
+ if (key === "fs" && valueNum !== 10) {
1045
1045
  style.fontSize = "".concat(valueNum, "pt");
1046
1046
  }
1047
1047
  if (key === "fc" && value !== "#000000" || ((_a = checksAF === null || checksAF === void 0 ? void 0 : checksAF.length) !== null && _a !== void 0 ? _a : 0) > 0 || (checksCF === null || checksCF === void 0 ? void 0 : checksCF.textColor)) {
@@ -1171,7 +1171,7 @@ export function rangeValueToHtml(ctx, sheetId, ranges) {
1171
1171
  cpdata += "<tr height=".concat(rowLen, "px >");
1172
1172
  var _loop_3 = function _loop_3(j) {
1173
1173
  var c = colIndexArr[j];
1174
- var column = '<td ${span} style="${style}" data-fortune-cell="${cellData}">';
1174
+ var column = '<td ${span} style="${style}">';
1175
1175
  var cell = (_f = d[r]) === null || _f === void 0 ? void 0 : _f[c];
1176
1176
  if (cell != null) {
1177
1177
  var style = "";
@@ -1382,14 +1382,9 @@ export function rangeValueToHtml(ctx, sheetId, ranges) {
1382
1382
  }
1383
1383
  }
1384
1384
  }
1385
- var cellData = encodeURIComponent(JSON.stringify(__assign(__assign({}, cell), {
1386
- _srcRow: r,
1387
- _srcCol: c
1388
- })));
1389
1385
  column = replaceHtml(column, {
1390
1386
  style: style,
1391
- span: span,
1392
- cellData: cellData
1387
+ span: span
1393
1388
  });
1394
1389
  if (_.isNil(c_value)) {
1395
1390
  c_value = getCellValue(r, c, d);
@@ -1439,8 +1434,7 @@ export function rangeValueToHtml(ctx, sheetId, ranges) {
1439
1434
  }
1440
1435
  column = replaceHtml(column, {
1441
1436
  style: style,
1442
- span: "",
1443
- cellData: ""
1437
+ span: ""
1444
1438
  });
1445
1439
  column += "";
1446
1440
  }
@@ -9,20 +9,11 @@ var __assign = this && this.__assign || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- var __rest = this && this.__rest || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
17
- }
18
- return t;
19
- };
20
12
  import _ from "lodash";
21
13
  import { locale } from "./locale";
22
14
  import { getQKBorder, saveHyperlink } from "./modules";
23
15
  import { getSheetIndex } from "./utils";
24
16
  import { setRowHeight, setColumnWidth } from "./api";
25
- import { adjustFormulaForPaste } from "./events/paste";
26
17
  export var DEFAULT_FONT_SIZE = 12;
27
18
  var parseStylesheetPairs = function parseStylesheetPairs(styleInner) {
28
19
  var patternReg = /{([^}]*)}/g;
@@ -136,28 +127,6 @@ function brToNewline(str) {
136
127
  }
137
128
  var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
138
129
  var _a, _b, _c, _d;
139
- var fortuneCellAttr = td.getAttribute("data-fortune-cell");
140
- if (fortuneCellAttr) {
141
- try {
142
- var _e = JSON.parse(decodeURIComponent(fortuneCellAttr)),
143
- _srcRow = _e._srcRow,
144
- _srcCol = _e._srcCol,
145
- parsed = __rest(_e, ["_srcRow", "_srcCol"]);
146
- var cell_1 = parsed;
147
- delete cell_1.mc;
148
- delete cell_1.hl;
149
- var rowspan_1 = parseInt(td.getAttribute("rowspan") || "1", 10);
150
- var colspan_1 = parseInt(td.getAttribute("colspan") || "1", 10);
151
- return {
152
- cell: cell_1,
153
- rowspan: Number.isNaN(rowspan_1) ? 1 : rowspan_1,
154
- colspan: Number.isNaN(colspan_1) ? 1 : colspan_1,
155
- hyperlink: detectHyperlink(td),
156
- srcRow: _srcRow,
157
- srcCol: _srcCol
158
- };
159
- } catch (_f) {}
160
- }
161
130
  var cell = {};
162
131
  var rawText = (td.innerText || td.innerHTML || "").trim();
163
132
  var isLineBreak = rawText.includes("<br />");
@@ -308,17 +277,10 @@ export function handlePastedTable(ctx, html, pasteHandler) {
308
277
  cell = _a.cell,
309
278
  rowspan = _a.rowspan,
310
279
  colspan = _a.colspan,
311
- hyperlink = _a.hyperlink,
312
- srcRow = _a.srcRow,
313
- srcCol = _a.srcCol;
280
+ hyperlink = _a.hyperlink;
314
281
  var anchorCol = ctx.luckysheet_select_save[0].column[0];
315
282
  var absoluteRow = anchorRow + localRowIndex;
316
283
  var absoluteCol = anchorCol + localColIndex;
317
- if (cell.f && srcRow != null && srcCol != null) {
318
- try {
319
- cell.f = adjustFormulaForPaste(cell.f, srcCol, srcRow, absoluteCol, absoluteRow);
320
- } catch (_b) {}
321
- }
322
284
  pastedMatrix[localRowIndex][localColIndex] = cell;
323
285
  if (hyperlink) {
324
286
  saveHyperlink(ctx, absoluteRow, absoluteCol, hyperlink.href, "webpage", hyperlink.display);
package/es/types.d.ts CHANGED
@@ -328,6 +328,8 @@ export type GlobalCache = {
328
328
  verticalScrollLock?: boolean;
329
329
  horizontalScrollLock?: boolean;
330
330
  overwriteCell?: boolean;
331
+ overwriteCellFirstChar?: string;
332
+ enteredEditByTyping?: boolean;
331
333
  ignoreWriteCell?: boolean;
332
334
  doNotFocus?: boolean;
333
335
  doNotUpdateCell?: boolean;
@@ -388,10 +388,10 @@ function handleArrowKey(ctx, e) {
388
388
  }
389
389
  }
390
390
  function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, handleRedo, canvas) {
391
- var _a, _b, _c;
391
+ var _a, _b, _c, _d;
392
392
  return __awaiter(this, void 0, void 0, function () {
393
- var kcode, kstr, allowEdit, isFxInput, ignoredKeys, restCod, last, row_index, col_index, last, row_index, col_index;
394
- return __generator(this, function (_d) {
393
+ var kcode, kstr, allowEdit, isFxInput, ignoredKeys, restCod, last, row_index, col_index, isEditing, inputText, isFormulaEdit, enteredByTyping, last, row_index, col_index;
394
+ return __generator(this, function (_e) {
395
395
  if (e.shiftKey && e.code === "Space") {
396
396
  e.stopImmediatePropagation();
397
397
  e.stopPropagation();
@@ -485,7 +485,18 @@ function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, hand
485
485
  (0, _refresh.jfrefreshgrid)(ctx, null, undefined);
486
486
  e.preventDefault();
487
487
  } else if (kstr === "ArrowUp" || kstr === "ArrowDown" || kstr === "ArrowLeft" || kstr === "ArrowRight") {
488
- handleArrowKey(ctx, e);
488
+ isEditing = ctx.luckysheetCellUpdate.length > 0;
489
+ inputText = (_d = cellInput === null || cellInput === void 0 ? void 0 : cellInput.innerText) !== null && _d !== void 0 ? _d : "";
490
+ isFormulaEdit = isEditing && inputText.trim().startsWith("=");
491
+ enteredByTyping = cache.enteredEditByTyping === true;
492
+ if (isEditing && !isFormulaEdit && enteredByTyping) {
493
+ (0, _cell.updateCell)(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
494
+ cache.enteredEditByTyping = false;
495
+ handleArrowKey(ctx, e);
496
+ e.preventDefault();
497
+ } else {
498
+ handleArrowKey(ctx, e);
499
+ }
489
500
  } else if (!(kcode >= 112 && kcode <= 123 || kcode <= 46 || kcode === 144 || kcode === 108 || e.ctrlKey || e.altKey || e.shiftKey && (kcode === 37 || kcode === 38 || kcode === 39 || kcode === 40)) || kcode === 8 || kcode === 32 || kcode === 46 || kcode === 0 || e.ctrlKey && kcode === 86) {
490
501
  if (!allowEdit) return [2];
491
502
  if (String.fromCharCode(kcode) != null && !_lodash.default.isEmpty(ctx.luckysheet_select_save) && kstr !== "CapsLock" && kstr !== "Win" && kcode !== 18) {
@@ -494,7 +505,10 @@ function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, hand
494
505
  col_index = last.column_focus;
495
506
  ctx.luckysheetCellUpdate = [row_index, col_index];
496
507
  cache.overwriteCell = true;
508
+ cache.overwriteCellFirstChar = e.key;
509
+ cache.enteredEditByTyping = true;
497
510
  (0, _formula.handleFormulaInput)(ctx, fxInput, cellInput, kcode);
511
+ e.preventDefault();
498
512
  }
499
513
  }
500
514
  }
@@ -508,6 +508,7 @@ function handleCellAreaDoubleClick(ctx, globalCache, settings, e, container) {
508
508
  row_index = row_focus;
509
509
  col_index = column_focus;
510
510
  }
511
+ globalCache.enteredEditByTyping = false;
511
512
  (0, _cell.luckysheetUpdateCell)(ctx, row_index, col_index);
512
513
  }
513
514
  function handleContextMenu(ctx, settings, e, workbookContainer, container, area) {
@@ -1074,7 +1074,7 @@ function getFontStyleByCell(cell, checksAF, checksCF, isCheck) {
1074
1074
  if (key === "it" && valueNum !== 0) {
1075
1075
  style.fontStyle = "italic";
1076
1076
  }
1077
- if (key === "fs" && !_lodash.default.isNil(value)) {
1077
+ if (key === "fs" && valueNum !== 10) {
1078
1078
  style.fontSize = "".concat(valueNum, "pt");
1079
1079
  }
1080
1080
  if (key === "fc" && value !== "#000000" || ((_a = checksAF === null || checksAF === void 0 ? void 0 : checksAF.length) !== null && _a !== void 0 ? _a : 0) > 0 || (checksCF === null || checksCF === void 0 ? void 0 : checksCF.textColor)) {
@@ -1206,7 +1206,7 @@ function rangeValueToHtml(ctx, sheetId, ranges) {
1206
1206
  cpdata += "<tr height=".concat(rowLen, "px >");
1207
1207
  var _loop_3 = function _loop_3(j) {
1208
1208
  var c = colIndexArr[j];
1209
- var column = '<td ${span} style="${style}" data-fortune-cell="${cellData}">';
1209
+ var column = '<td ${span} style="${style}">';
1210
1210
  var cell = (_f = d[r]) === null || _f === void 0 ? void 0 : _f[c];
1211
1211
  if (cell != null) {
1212
1212
  var style = "";
@@ -1417,14 +1417,9 @@ function rangeValueToHtml(ctx, sheetId, ranges) {
1417
1417
  }
1418
1418
  }
1419
1419
  }
1420
- var cellData = encodeURIComponent(JSON.stringify(__assign(__assign({}, cell), {
1421
- _srcRow: r,
1422
- _srcCol: c
1423
- })));
1424
1420
  column = (0, _utils.replaceHtml)(column, {
1425
1421
  style: style,
1426
- span: span,
1427
- cellData: cellData
1422
+ span: span
1428
1423
  });
1429
1424
  if (_lodash.default.isNil(c_value)) {
1430
1425
  c_value = (0, _cell.getCellValue)(r, c, d);
@@ -1474,8 +1469,7 @@ function rangeValueToHtml(ctx, sheetId, ranges) {
1474
1469
  }
1475
1470
  column = (0, _utils.replaceHtml)(column, {
1476
1471
  style: style,
1477
- span: "",
1478
- cellData: ""
1472
+ span: ""
1479
1473
  });
1480
1474
  column += "";
1481
1475
  }
@@ -10,7 +10,6 @@ var _locale = require("./locale");
10
10
  var _modules = require("./modules");
11
11
  var _utils = require("./utils");
12
12
  var _api = require("./api");
13
- var _paste = require("./events/paste");
14
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
14
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
16
15
  var __assign = void 0 && (void 0).__assign || function () {
@@ -23,14 +22,6 @@ var __assign = void 0 && (void 0).__assign || function () {
23
22
  };
24
23
  return __assign.apply(this, arguments);
25
24
  };
26
- var __rest = void 0 && (void 0).__rest || function (s, e) {
27
- var t = {};
28
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
29
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
30
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
31
- }
32
- return t;
33
- };
34
25
  var DEFAULT_FONT_SIZE = exports.DEFAULT_FONT_SIZE = 12;
35
26
  var parseStylesheetPairs = function parseStylesheetPairs(styleInner) {
36
27
  var patternReg = /{([^}]*)}/g;
@@ -144,28 +135,6 @@ function brToNewline(str) {
144
135
  }
145
136
  var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
146
137
  var _a, _b, _c, _d;
147
- var fortuneCellAttr = td.getAttribute("data-fortune-cell");
148
- if (fortuneCellAttr) {
149
- try {
150
- var _e = JSON.parse(decodeURIComponent(fortuneCellAttr)),
151
- _srcRow = _e._srcRow,
152
- _srcCol = _e._srcCol,
153
- parsed = __rest(_e, ["_srcRow", "_srcCol"]);
154
- var cell_1 = parsed;
155
- delete cell_1.mc;
156
- delete cell_1.hl;
157
- var rowspan_1 = parseInt(td.getAttribute("rowspan") || "1", 10);
158
- var colspan_1 = parseInt(td.getAttribute("colspan") || "1", 10);
159
- return {
160
- cell: cell_1,
161
- rowspan: Number.isNaN(rowspan_1) ? 1 : rowspan_1,
162
- colspan: Number.isNaN(colspan_1) ? 1 : colspan_1,
163
- hyperlink: detectHyperlink(td),
164
- srcRow: _srcRow,
165
- srcCol: _srcCol
166
- };
167
- } catch (_f) {}
168
- }
169
138
  var cell = {};
170
139
  var rawText = (td.innerText || td.innerHTML || "").trim();
171
140
  var isLineBreak = rawText.includes("<br />");
@@ -316,17 +285,10 @@ function handlePastedTable(ctx, html, pasteHandler) {
316
285
  cell = _a.cell,
317
286
  rowspan = _a.rowspan,
318
287
  colspan = _a.colspan,
319
- hyperlink = _a.hyperlink,
320
- srcRow = _a.srcRow,
321
- srcCol = _a.srcCol;
288
+ hyperlink = _a.hyperlink;
322
289
  var anchorCol = ctx.luckysheet_select_save[0].column[0];
323
290
  var absoluteRow = anchorRow + localRowIndex;
324
291
  var absoluteCol = anchorCol + localColIndex;
325
- if (cell.f && srcRow != null && srcCol != null) {
326
- try {
327
- cell.f = (0, _paste.adjustFormulaForPaste)(cell.f, srcCol, srcRow, absoluteCol, absoluteRow);
328
- } catch (_b) {}
329
- }
330
292
  pastedMatrix[localRowIndex][localColIndex] = cell;
331
293
  if (hyperlink) {
332
294
  (0, _modules.saveHyperlink)(ctx, absoluteRow, absoluteCol, hyperlink.href, "webpage", hyperlink.display);
package/lib/types.d.ts CHANGED
@@ -328,6 +328,8 @@ export type GlobalCache = {
328
328
  verticalScrollLock?: boolean;
329
329
  horizontalScrollLock?: boolean;
330
330
  overwriteCell?: boolean;
331
+ overwriteCellFirstChar?: string;
332
+ enteredEditByTyping?: boolean;
331
333
  ignoreWriteCell?: boolean;
332
334
  doNotFocus?: boolean;
333
335
  doNotUpdateCell?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.3.10-copyPaste-3",
3
+ "version": "1.3.10-input-1",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",