@fileverse-dev/fortune-core 1.3.9 → 1.3.10-copyPaste-2

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.
package/es/api/cell.d.ts CHANGED
@@ -4,7 +4,7 @@ import { CommonOptions } from "./common";
4
4
  export declare function getCellValue(ctx: Context, row: number, column: number, options?: CommonOptions & {
5
5
  type?: keyof Cell;
6
6
  }): any;
7
- export declare function setCellValue(ctx: Context, row: number, column: number, value: any, cellInput: HTMLDivElement | null, options?: CommonOptions): void;
7
+ export declare function setCellValue(ctx: Context, row: number, column: number, value: any, cellInput: HTMLDivElement | null, options?: CommonOptions, callAfterUpdate?: boolean): void;
8
8
  export declare function clearCell(ctx: Context, row: number, column: number, options?: CommonOptions): void;
9
9
  export declare function setCellFormat(ctx: Context, row: number, column: number, attr: keyof Cell, value: any, options?: CommonOptions): void;
10
10
  export declare function autoFillCell(ctx: Context, copyRange: SingleRange, applyRange: SingleRange, direction: "up" | "down" | "left" | "right"): void;
package/es/api/cell.js CHANGED
@@ -50,8 +50,8 @@ export function getCellValue(ctx, row, column, options) {
50
50
  }
51
51
  return ret;
52
52
  }
53
- export function setCellValue(ctx, row, column, value, cellInput, options) {
54
- var _a;
53
+ export function setCellValue(ctx, row, column, value, cellInput, options, callAfterUpdate) {
54
+ var _a, _b, _c;
55
55
  if (options === void 0) {
56
56
  options = {};
57
57
  }
@@ -112,7 +112,7 @@ export function setCellValue(ctx, row, column, value, cellInput, options) {
112
112
  setCellValueInternal(ctx, row, column, data, curv);
113
113
  }
114
114
  _.forEach(value, function (v, attr) {
115
- if (attr in formatList) {
115
+ if (attr in formatList && callAfterUpdate) {
116
116
  updateFormatCell(ctx, data, attr, v, row, row, column, column);
117
117
  } else {
118
118
  cell_1[attr] = v;
@@ -127,6 +127,9 @@ export function setCellValue(ctx, row, column, value, cellInput, options) {
127
127
  setCellValueInternal(ctx, row, column, data, value);
128
128
  }
129
129
  }
130
+ if (callAfterUpdate && ctx.hooks.afterUpdateCell) {
131
+ (_c = (_b = ctx.hooks).afterUpdateCell) === null || _c === void 0 ? void 0 : _c.call(_b, row, column, null, value);
132
+ }
130
133
  }
131
134
  export function clearCell(ctx, row, column, options) {
132
135
  var _a, _b;
package/es/api/range.d.ts CHANGED
@@ -18,5 +18,5 @@ export declare function getSelectionCoordinates(ctx: Context): string[];
18
18
  export declare function getCellsByRange(ctx: Context, range: Selection, options?: CommonOptions): (Cell | null)[][];
19
19
  export declare function getHtmlByRange(ctx: Context, range: Range, options?: CommonOptions): string | null;
20
20
  export declare function setSelection(ctx: Context, range: Range, options: CommonOptions): void;
21
- export declare function setCellValuesByRange(ctx: Context, data: any[][], range: SingleRange, cellInput: HTMLDivElement | null, options?: CommonOptions): void;
21
+ export declare function setCellValuesByRange(ctx: Context, data: any[][], range: SingleRange, cellInput: HTMLDivElement | null, options?: CommonOptions, callAfterUpdate?: boolean): void;
22
22
  export declare function setCellFormatByRange(ctx: Context, attr: keyof Cell, value: any, range: Range | SingleRange, options?: CommonOptions): void;
package/es/api/range.js CHANGED
@@ -77,7 +77,7 @@ export function setSelection(ctx, range, options) {
77
77
  ctx.luckysheet_select_save = sheet.luckysheet_select_save;
78
78
  }
79
79
  }
80
- export function setCellValuesByRange(ctx, data, range, cellInput, options) {
80
+ export function setCellValuesByRange(ctx, data, range, cellInput, options, callAfterUpdate) {
81
81
  if (options === void 0) {
82
82
  options = {};
83
83
  }
@@ -99,7 +99,7 @@ export function setCellValuesByRange(ctx, data, range, cellInput, options) {
99
99
  for (var j = 0; j < columnCount; j += 1) {
100
100
  var row = range.row[0] + i;
101
101
  var column = range.column[0] + j;
102
- setCellValue(ctx, row, column, data[i][j], cellInput, options);
102
+ setCellValue(ctx, row, column, data[i][j], cellInput, options, callAfterUpdate);
103
103
  }
104
104
  }
105
105
  }
@@ -81,6 +81,7 @@ export function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow)
81
81
  var stringOrCellRef = /"(?:\\.|[^"])*"|(\$?[A-Z]+\$?\d+)(?!\s*!)\b/g;
82
82
  var result = formula.replace(stringOrCellRef, function (m, cellRef) {
83
83
  if (!cellRef) return m;
84
+ if (cellRef.startsWith("$")) return m;
84
85
  return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
85
86
  var colIndex = columnLabelIndex(colLetters);
86
87
  var rowIndex = parseInt(rowNum, 10);
@@ -187,27 +188,42 @@ function postPasteCut(ctx, source, target, RowlChange) {
187
188
  storeSheetParamALL(ctx);
188
189
  }
189
190
  var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
190
- var _a;
191
+ var _a, _b, _c;
192
+ var changes = [];
191
193
  for (var r = 0; r < d.length; r += 1) {
192
194
  var x = d[r];
193
195
  for (var c = 0; c < d[0].length; c += 1) {
194
196
  var value = isObject(d[r][c]) ? (_a = d[r][c]) === null || _a === void 0 ? void 0 : _a.v : d[r][c];
195
197
  if (value && String(value).startsWith("=")) {
196
198
  var cell = {};
197
- var _b = execfunction(ctx, String(value), r, c, undefined, undefined, true),
198
- v = _b[1],
199
- f = _b[2];
199
+ var _d = execfunction(ctx, String(value), r, c, undefined, undefined, true),
200
+ v = _d[1],
201
+ f = _d[2];
200
202
  cell.v = v;
201
203
  cell.f = f;
202
204
  cell.m = v.toString();
203
205
  x[c] = cell;
204
206
  }
205
207
  d[r] = x;
208
+ changes.push({
209
+ sheetId: ctx.currentSheetId,
210
+ path: ["celldata"],
211
+ value: {
212
+ r: r,
213
+ c: c,
214
+ v: d[r][c]
215
+ },
216
+ key: "".concat(r, "_").concat(c),
217
+ type: "update"
218
+ });
206
219
  }
207
220
  }
221
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
222
+ (_c = ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc(changes);
223
+ }
208
224
  };
209
225
  function pasteHandler(ctx, data, borderInfo) {
210
- var _a, _b, _c, _d, _e, _f;
226
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
211
227
  if (ctx.luckysheet_selection_range) {
212
228
  ctx.luckysheet_selection_range = [];
213
229
  }
@@ -255,6 +271,7 @@ function pasteHandler(ctx, data, borderInfo) {
255
271
  }
256
272
  var RowlChange = false;
257
273
  var offsetMC = {};
274
+ var changes = [];
258
275
  for (var h = minh; h <= maxh; h += 1) {
259
276
  var x = d[h];
260
277
  var currentRowLen = ctx.defaultrowlen;
@@ -302,12 +319,26 @@ function pasteHandler(ctx, data, borderInfo) {
302
319
  };
303
320
  (_e = cfg.borderInfo) === null || _e === void 0 ? void 0 : _e.push(bd_obj);
304
321
  }
322
+ changes.push({
323
+ sheetId: ctx.currentSheetId,
324
+ path: ["celldata"],
325
+ value: {
326
+ r: h,
327
+ c: c,
328
+ v: d[h][c]
329
+ },
330
+ key: "".concat(h, "_").concat(c),
331
+ type: "update"
332
+ });
305
333
  }
306
334
  d[h] = x;
307
335
  if (currentRowLen !== ctx.defaultrowlen) {
308
336
  cfg.rowlen[h] = currentRowLen;
309
337
  }
310
338
  }
339
+ if ((_f = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _f === void 0 ? void 0 : _f.updateCellYdoc) {
340
+ (_g = ctx.hooks) === null || _g === void 0 ? void 0 : _g.updateCellYdoc(changes);
341
+ }
311
342
  ctx.luckysheet_select_save = [{
312
343
  row: [minh, maxh],
313
344
  column: [minc, maxc]
@@ -332,7 +363,7 @@ function pasteHandler(ctx, data, borderInfo) {
332
363
  }
333
364
  var d = getFlowdata(ctx);
334
365
  if (!d) return;
335
- var last = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f[ctx.luckysheet_select_save.length - 1];
366
+ var last = (_h = ctx.luckysheet_select_save) === null || _h === void 0 ? void 0 : _h[ctx.luckysheet_select_save.length - 1];
336
367
  if (!last) return;
337
368
  var curR = last.row == null ? 0 : last.row[0];
338
369
  var curC = last.column == null ? 0 : last.column[0];
@@ -357,6 +388,7 @@ function pasteHandler(ctx, data, borderInfo) {
357
388
  if (!/^(https?:\/\/|www\.)\S+$/i.test(t)) return null;
358
389
  return t.startsWith("http") ? t : "https://".concat(t);
359
390
  };
391
+ var changes = [];
360
392
  for (var r = 0; r < rlen; r += 1) {
361
393
  var x = d[r + curR];
362
394
  for (var c = 0; c < clen; c += 1) {
@@ -447,9 +479,23 @@ function pasteHandler(ctx, data, borderInfo) {
447
479
  }
448
480
  x[c + curC] = cell;
449
481
  }
482
+ changes.push(changes.push({
483
+ sheetId: ctx.currentSheetId,
484
+ path: ["celldata"],
485
+ value: {
486
+ r: r,
487
+ c: c,
488
+ v: d[r][c]
489
+ },
490
+ key: "".concat(r, "_").concat(c),
491
+ type: "update"
492
+ }));
450
493
  }
451
494
  d[r + curR] = x;
452
495
  }
496
+ if ((_j = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _j === void 0 ? void 0 : _j.updateCellYdoc) {
497
+ (_k = ctx.hooks) === null || _k === void 0 ? void 0 : _k.updateCellYdoc(changes);
498
+ }
453
499
  last.row = [curR, curR + rlen - 1];
454
500
  last.column = [curC, curC + clen - 1];
455
501
  jfrefreshgrid(ctx, null, undefined);
@@ -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" && valueNum !== 10) {
1044
+ if (key === "fs" && !_.isNil(value)) {
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)) {
@@ -2003,7 +2003,6 @@ export function updateDropCell(ctx) {
2003
2003
  var v = formula.execfunction(ctx, f, i, j);
2004
2004
  formula.execFunctionGroup(ctx, j, i, v[1], undefined, d);
2005
2005
  cell.v = v[1], cell.f = v[2];
2006
- console.log(j, i);
2007
2006
  var afterUpdateCell = ctx.hooks.afterUpdateCell;
2008
2007
  if (afterUpdateCell) {
2009
2008
  afterUpdateCell(i, j, null, __assign(__assign({}, cell), {
@@ -698,12 +698,6 @@ function replaceDotsInFunctionName(str) {
698
698
  return "=".concat(fixedFnName).concat(str.substring(openParenIndex));
699
699
  }
700
700
  export function execfunction(ctx, txt, r, c, id, calcChainSet, isrefresh, notInsertFunc) {
701
- console.log("execfunction:", {
702
- txt: txt,
703
- r: r,
704
- c: c,
705
- id: id
706
- });
707
701
  var originalTxt = txt;
708
702
  if ((txt === null || txt === void 0 ? void 0 : txt.toUpperCase().includes("NETWORKDAYS.INTL")) || (txt === null || txt === void 0 ? void 0 : txt.toUpperCase().includes("WORKDAY.INTL"))) {
709
703
  txt = replaceDotsInFunctionName(txt);
@@ -821,7 +815,6 @@ export function execFunctionGroup(ctx, origin_r, origin_c, value, id, data, isFo
821
815
  if (isForce === void 0) {
822
816
  isForce = false;
823
817
  }
824
- console.log("execFunctionGroup", origin_r, origin_c, value, id, data);
825
818
  if (_.isNil(data)) {
826
819
  data = getFlowdata(ctx);
827
820
  }
@@ -41,7 +41,7 @@ export function getCellHyperlink(ctx, r, c) {
41
41
  return undefined;
42
42
  }
43
43
  export function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress, options) {
44
- var _a;
44
+ var _a, _b, _c;
45
45
  var applyToSelection = (options === null || options === void 0 ? void 0 : options.applyToSelection) && (options === null || options === void 0 ? void 0 : options.cellInput);
46
46
  var sheetIndex = getSheetIndex(ctx, ctx.currentSheetId);
47
47
  var flowdata = getFlowdata(ctx);
@@ -91,6 +91,19 @@ export function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress, option
91
91
  };
92
92
  flowdata[r][c] = cell;
93
93
  ctx.linkCard = undefined;
94
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
95
+ (_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc([{
96
+ sheetId: ctx.currentSheetId,
97
+ path: ["celldata"],
98
+ value: {
99
+ r: r,
100
+ c: c,
101
+ v: cell
102
+ },
103
+ key: "".concat(r, "_").concat(c),
104
+ type: "update"
105
+ }]);
106
+ }
94
107
  }
95
108
  }
96
109
  export function removeHyperlink(ctx, r, c) {
@@ -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}">';
1174
+ var column = '<td ${span} style="${style}" data-fortune-cell="${cellData}">';
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,9 +1382,14 @@ 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
+ })));
1385
1389
  column = replaceHtml(column, {
1386
1390
  style: style,
1387
- span: span
1391
+ span: span,
1392
+ cellData: cellData
1388
1393
  });
1389
1394
  if (_.isNil(c_value)) {
1390
1395
  c_value = getCellValue(r, c, d);
@@ -1434,7 +1439,8 @@ export function rangeValueToHtml(ctx, sheetId, ranges) {
1434
1439
  }
1435
1440
  column = replaceHtml(column, {
1436
1441
  style: style,
1437
- span: ""
1442
+ span: "",
1443
+ cellData: ""
1438
1444
  });
1439
1445
  column += "";
1440
1446
  }
@@ -1501,9 +1507,9 @@ export function copy(ctx) {
1501
1507
  }
1502
1508
  }
1503
1509
  export function deleteSelectedCellText(ctx) {
1504
- var _a, _b, _c;
1510
+ var _a, _b, _c, _d;
1505
1511
  var allowEdit = isAllowEdit(ctx);
1506
- if (allowEdit === false || ctx.isFlvReadOnly) {
1512
+ if (allowEdit === false) {
1507
1513
  return "allowEdit";
1508
1514
  }
1509
1515
  var selection = ctx.luckysheet_select_save;
@@ -1530,6 +1536,7 @@ export function deleteSelectedCellText(ctx) {
1530
1536
  var r2 = selection[s].row[1];
1531
1537
  var c1 = selection[s].column[0];
1532
1538
  var c2 = selection[s].column[1];
1539
+ var changes = [];
1533
1540
  for (var r = r1; r <= r2; r += 1) {
1534
1541
  for (var c = c1; c <= c2; c += 1) {
1535
1542
  var index = getSheetIndex(ctx, ctx.currentSheetId);
@@ -1560,6 +1567,18 @@ export function deleteSelectedCellText(ctx) {
1560
1567
  if (hyperlinkMap && hyperlinkMap["".concat(r, "_").concat(c)]) {
1561
1568
  delete hyperlinkMap["".concat(r, "_").concat(c)];
1562
1569
  }
1570
+ if ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.afterUpdateCell) {
1571
+ ctx.hooks.afterUpdateCell(r, c, null, d[r][c]);
1572
+ }
1573
+ changes.push({
1574
+ sheetId: ctx.currentSheetId,
1575
+ path: ["celldata"],
1576
+ value: {
1577
+ r: r,
1578
+ c: c,
1579
+ v: d[r][c]
1580
+ }
1581
+ });
1563
1582
  }
1564
1583
  }
1565
1584
  }
@@ -1,3 +1,13 @@
1
+ var __assign = this && this.__assign || function () {
2
+ __assign = Object.assign || function (t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
6
+ }
7
+ return t;
8
+ };
9
+ return __assign.apply(this, arguments);
10
+ };
1
11
  import _ from "lodash";
2
12
  import { v4 as uuidv4 } from "uuid";
3
13
  import { initSheetData } from "../api/sheet";
@@ -19,7 +29,7 @@ export function storeSheetParamALL(ctx) {
19
29
  ctx.luckysheetfile[index].config = ctx.config;
20
30
  }
21
31
  export function changeSheet(ctx, id, isPivotInitial, isNewSheet, isCopySheet) {
22
- var _a, _b;
32
+ var _a, _b, _c, _d;
23
33
  if (id === ctx.currentSheetId) {
24
34
  return;
25
35
  }
@@ -35,14 +45,11 @@ export function changeSheet(ctx, id, isPivotInitial, isNewSheet, isCopySheet) {
35
45
  ctx.luckysheetcurrentisPivotTable = false;
36
46
  }
37
47
  if (ctx.hooks.afterActivateSheet) {
38
- setTimeout(function () {
39
- var _a, _b;
40
- (_b = (_a = ctx.hooks).afterActivateSheet) === null || _b === void 0 ? void 0 : _b.call(_a, id);
41
- });
48
+ (_d = (_c = ctx.hooks).afterActivateSheet) === null || _d === void 0 ? void 0 : _d.call(_c, id);
42
49
  }
43
50
  }
44
51
  export function addSheet(ctx, settings, newSheetID, isPivotTable, sheetName, sheetData) {
45
- var _a, _b;
52
+ var _a, _b, _c, _d;
46
53
  if (newSheetID === void 0) {
47
54
  newSheetID = undefined;
48
55
  }
@@ -86,18 +93,12 @@ export function addSheet(ctx, settings, newSheetID, isPivotTable, sheetName, she
86
93
  return;
87
94
  }
88
95
  ctx.luckysheetfile.push(sheetconfig);
89
- if (!newSheetID) {
90
- changeSheet(ctx, id, isPivotTable, true);
91
- }
92
96
  if (ctx.hooks.afterAddSheet) {
93
- setTimeout(function () {
94
- var _a, _b;
95
- (_b = (_a = ctx.hooks).afterAddSheet) === null || _b === void 0 ? void 0 : _b.call(_a, sheetconfig);
96
- });
97
+ (_d = (_c = ctx.hooks).afterAddSheet) === null || _d === void 0 ? void 0 : _d.call(_c, __assign({}, sheetconfig));
97
98
  }
98
99
  }
99
100
  export function deleteSheet(ctx, id) {
100
- var _a, _b, _c;
101
+ var _a, _b, _c, _d, _e;
101
102
  if (ctx.allowEdit === false) {
102
103
  return;
103
104
  }
@@ -123,10 +124,7 @@ export function deleteSheet(ctx, id) {
123
124
  ctx.currentSheetId = (_c = orderSheets === null || orderSheets === void 0 ? void 0 : orderSheets[0]) === null || _c === void 0 ? void 0 : _c.id;
124
125
  }
125
126
  if (ctx.hooks.afterDeleteSheet) {
126
- setTimeout(function () {
127
- var _a, _b;
128
- (_b = (_a = ctx.hooks).afterDeleteSheet) === null || _b === void 0 ? void 0 : _b.call(_a, id);
129
- });
127
+ (_e = (_d = ctx.hooks).afterDeleteSheet) === null || _e === void 0 ? void 0 : _e.call(_d, id);
130
128
  }
131
129
  }
132
130
  export function updateSheet(ctx, newData) {
@@ -16,12 +16,13 @@ import { showLinkCard } from "./hyperlink";
16
16
  import { cfSplitRange } from "./conditionalFormat";
17
17
  import { clearMeasureTextCache, getCellTextInfo } from "./text";
18
18
  export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col_ed, canvas) {
19
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
20
- var _7;
19
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
20
+ var _11;
21
21
  if (_.isNil(d) || _.isNil(attr)) {
22
22
  return;
23
23
  }
24
24
  if (attr === "ct") {
25
+ var changes = [];
25
26
  for (var r = row_st; r <= row_ed; r += 1) {
26
27
  if (!_.isNil(ctx.config.rowhidden) && !_.isNil(ctx.config.rowhidden[r])) {
27
28
  continue;
@@ -97,6 +98,20 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
97
98
  m: mask
98
99
  };
99
100
  }
101
+ changes.push({
102
+ sheetId: ctx.currentSheetId,
103
+ path: ["celldata"],
104
+ value: {
105
+ r: r,
106
+ c: c,
107
+ v: d[r][c]
108
+ },
109
+ key: "".concat(r, "_").concat(c),
110
+ type: "update"
111
+ });
112
+ }
113
+ if ((_x = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _x === void 0 ? void 0 : _x.updateCellYdoc) {
114
+ (_y = ctx.hooks) === null || _y === void 0 ? void 0 : _y.updateCellYdoc(changes);
100
115
  }
101
116
  }
102
117
  } else {
@@ -143,6 +158,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
143
158
  if (sheetIndex == null) {
144
159
  return;
145
160
  }
161
+ var changes = [];
146
162
  for (var r = row_st; r <= row_ed; r += 1) {
147
163
  if (!_.isNil(ctx.config.rowhidden) && !_.isNil(ctx.config.rowhidden[r])) {
148
164
  continue;
@@ -152,11 +168,11 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
152
168
  if (value && _.isPlainObject(value)) {
153
169
  updateInlineStringFormatOutside(value, attr, foucsStatus);
154
170
  value[attr] = foucsStatus;
155
- (_7 = ctx.luckysheetfile[sheetIndex]).config || (_7.config = {});
171
+ (_11 = ctx.luckysheetfile[sheetIndex]).config || (_11.config = {});
156
172
  var cfg = ctx.luckysheetfile[sheetIndex].config;
157
- var cellWidth = ((_x = cfg.columnlen) === null || _x === void 0 ? void 0 : _x[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
173
+ var cellWidth = ((_z = cfg.columnlen) === null || _z === void 0 ? void 0 : _z[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
158
174
  if (attr === "tb" && canvas && foucsStatus === "2") {
159
- var currentColWidth_1 = ((_y = cfg.columnlen) === null || _y === void 0 ? void 0 : _y[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
175
+ var currentColWidth_1 = ((_0 = cfg.columnlen) === null || _0 === void 0 ? void 0 : _0[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
160
176
  var lineCount_1 = 1;
161
177
  var fontString_1 = "10px Arial";
162
178
  if (value.fs) {
@@ -169,9 +185,9 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
169
185
  lineCount_1 = getLineCount(value.m, currentColWidth_1, fontString_1);
170
186
  var hOffset = lineCount_1 < 4 ? 1.9 : 1.7;
171
187
  lineCount_1 = lineCount_1 * hOffset + 1;
172
- } else if ((_1 = (_0 = (_z = value === null || value === void 0 ? void 0 : value.ct) === null || _z === void 0 ? void 0 : _z.s) === null || _0 === void 0 ? void 0 : _0[0]) === null || _1 === void 0 ? void 0 : _1.v) {
188
+ } else if ((_3 = (_2 = (_1 = value === null || value === void 0 ? void 0 : value.ct) === null || _1 === void 0 ? void 0 : _1.s) === null || _2 === void 0 ? void 0 : _2[0]) === null || _3 === void 0 ? void 0 : _3.v) {
173
189
  lineCount_1 -= 1;
174
- var line = (_4 = (_3 = (_2 = value === null || value === void 0 ? void 0 : value.ct) === null || _2 === void 0 ? void 0 : _2.s) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.v.split("\n");
190
+ var line = (_6 = (_5 = (_4 = value === null || value === void 0 ? void 0 : value.ct) === null || _4 === void 0 ? void 0 : _4.s) === null || _5 === void 0 ? void 0 : _5[0]) === null || _6 === void 0 ? void 0 : _6.v.split("\n");
175
191
  line.forEach(function (item) {
176
192
  var subLineCount = getLineCount(item, currentColWidth_1, fontString_1);
177
193
  lineCount_1 += subLineCount;
@@ -191,7 +207,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
191
207
  });
192
208
  if (!textInfo) return "continue";
193
209
  var rowHeight = _.round(textInfo.textHeightAll);
194
- var currentRowHeight = ((_5 = cfg.rowlen) === null || _5 === void 0 ? void 0 : _5[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
210
+ var currentRowHeight = ((_7 = cfg.rowlen) === null || _7 === void 0 ? void 0 : _7[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
195
211
  if (!_.isUndefined(rowHeight) && rowHeight > currentRowHeight && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
196
212
  if (_.isUndefined(cfg.rowlen)) cfg.rowlen = {};
197
213
  _.set(cfg, "rowlen.".concat(r), rowHeight);
@@ -206,7 +222,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
206
222
  });
207
223
  if (!textInfo) return "continue";
208
224
  var newHeight = _.round(textInfo.textHeightAll);
209
- var oldHeight = ((_6 = cfg.rowlen) === null || _6 === void 0 ? void 0 : _6[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
225
+ var oldHeight = ((_8 = cfg.rowlen) === null || _8 === void 0 ? void 0 : _8[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
210
226
  var shouldResize = foucsStatus === "2" ? newHeight > oldHeight : true;
211
227
  if (shouldResize && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
212
228
  var padding = 12;
@@ -221,11 +237,25 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
221
237
  };
222
238
  d[r][c][attr] = foucsStatus;
223
239
  }
240
+ changes.push({
241
+ sheetId: ctx.currentSheetId,
242
+ path: ["celldata"],
243
+ value: {
244
+ r: r,
245
+ c: c,
246
+ v: d[r][c]
247
+ },
248
+ key: "".concat(r, "_").concat(c),
249
+ type: "update"
250
+ });
224
251
  };
225
252
  for (var c = col_st; c <= col_ed; c += 1) {
226
253
  _loop_1(c);
227
254
  }
228
255
  }
256
+ if ((_9 = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _9 === void 0 ? void 0 : _9.updateCellYdoc) {
257
+ (_10 = ctx.hooks) === null || _10 === void 0 ? void 0 : _10.updateCellYdoc(changes);
258
+ }
229
259
  }
230
260
  }
231
261
  export function updateFormat(ctx, $input, d, attr, foucsStatus, canvas) {
@@ -9,11 +9,20 @@ 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
+ };
12
20
  import _ from "lodash";
13
21
  import { locale } from "./locale";
14
22
  import { getQKBorder, saveHyperlink } from "./modules";
15
23
  import { getSheetIndex } from "./utils";
16
24
  import { setRowHeight, setColumnWidth } from "./api";
25
+ import { adjustFormulaForPaste } from "./events/paste";
17
26
  export var DEFAULT_FONT_SIZE = 12;
18
27
  var parseStylesheetPairs = function parseStylesheetPairs(styleInner) {
19
28
  var patternReg = /{([^}]*)}/g;
@@ -127,6 +136,28 @@ function brToNewline(str) {
127
136
  }
128
137
  var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
129
138
  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
+ }
130
161
  var cell = {};
131
162
  var rawText = (td.innerText || td.innerHTML || "").trim();
132
163
  var isLineBreak = rawText.includes("<br />");
@@ -277,10 +308,17 @@ export function handlePastedTable(ctx, html, pasteHandler) {
277
308
  cell = _a.cell,
278
309
  rowspan = _a.rowspan,
279
310
  colspan = _a.colspan,
280
- hyperlink = _a.hyperlink;
311
+ hyperlink = _a.hyperlink,
312
+ srcRow = _a.srcRow,
313
+ srcCol = _a.srcCol;
281
314
  var anchorCol = ctx.luckysheet_select_save[0].column[0];
282
315
  var absoluteRow = anchorRow + localRowIndex;
283
316
  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
+ }
284
322
  pastedMatrix[localRowIndex][localColIndex] = cell;
285
323
  if (hyperlink) {
286
324
  saveHyperlink(ctx, absoluteRow, absoluteCol, hyperlink.href, "webpage", hyperlink.display);
package/es/settings.d.ts CHANGED
@@ -1,6 +1,24 @@
1
1
  import React from "react";
2
2
  import { Sheet, Selection, CellMatrix, Cell } from "./types";
3
+ type SheetChangePath = {
4
+ sheetId: string;
5
+ path: string[];
6
+ key?: string;
7
+ value: any;
8
+ type?: "update" | "delete";
9
+ };
3
10
  export type Hooks = {
11
+ calcChainChange?: () => void;
12
+ sheetLengthChange?: () => void;
13
+ dataVerificationChange?: () => void;
14
+ liveQueryChange?: () => void;
15
+ imageListChange?: () => void;
16
+ iframeListChange?: () => void;
17
+ conditionRulesChange?: () => void;
18
+ conditionFormatChange?: () => void;
19
+ cellDataChange?: () => void;
20
+ hyperlinkChange?: () => void;
21
+ updateCellYdoc?: (changes: SheetChangePath[]) => void;
4
22
  beforeUpdateCell?: (r: number, c: number, value: any) => boolean;
5
23
  afterUpdateCell?: (row: number, column: number, oldValue: any, newValue: any) => void;
6
24
  afterSelectionChange?: (sheetId: string, selection: Selection) => void;
@@ -56,6 +74,15 @@ export type Hooks = {
56
74
  afterDeleteSheet?: (id: string) => void;
57
75
  beforeUpdateSheetName?: (id: string, oldName: string, newName: string) => boolean;
58
76
  afterUpdateSheetName?: (id: string, oldName: string, newName: string) => void;
77
+ afterImagesChange?: () => void;
78
+ afterIframesChange?: () => void;
79
+ afterFrozenChange?: () => void;
80
+ afterOrderChanges?: () => void;
81
+ afterConfigChanges?: () => void;
82
+ afterColRowChanges?: () => void;
83
+ afterShowGridLinesChange?: () => void;
84
+ afterNameChanges?: () => void;
85
+ afterStatusChanges?: () => void;
59
86
  };
60
87
  type CommentUIDragFn = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
61
88
  export type Settings = {
package/lib/api/cell.d.ts CHANGED
@@ -4,7 +4,7 @@ import { CommonOptions } from "./common";
4
4
  export declare function getCellValue(ctx: Context, row: number, column: number, options?: CommonOptions & {
5
5
  type?: keyof Cell;
6
6
  }): any;
7
- export declare function setCellValue(ctx: Context, row: number, column: number, value: any, cellInput: HTMLDivElement | null, options?: CommonOptions): void;
7
+ export declare function setCellValue(ctx: Context, row: number, column: number, value: any, cellInput: HTMLDivElement | null, options?: CommonOptions, callAfterUpdate?: boolean): void;
8
8
  export declare function clearCell(ctx: Context, row: number, column: number, options?: CommonOptions): void;
9
9
  export declare function setCellFormat(ctx: Context, row: number, column: number, attr: keyof Cell, value: any, options?: CommonOptions): void;
10
10
  export declare function autoFillCell(ctx: Context, copyRange: SingleRange, applyRange: SingleRange, direction: "up" | "down" | "left" | "right"): void;