@fileverse-dev/fortune-core 1.3.9 → 1.3.10

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);
@@ -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) {
@@ -1501,7 +1501,7 @@ export function copy(ctx) {
1501
1501
  }
1502
1502
  }
1503
1503
  export function deleteSelectedCellText(ctx) {
1504
- var _a, _b, _c;
1504
+ var _a, _b, _c, _d;
1505
1505
  var allowEdit = isAllowEdit(ctx);
1506
1506
  if (allowEdit === false || ctx.isFlvReadOnly) {
1507
1507
  return "allowEdit";
@@ -1530,6 +1530,7 @@ export function deleteSelectedCellText(ctx) {
1530
1530
  var r2 = selection[s].row[1];
1531
1531
  var c1 = selection[s].column[0];
1532
1532
  var c2 = selection[s].column[1];
1533
+ var changes = [];
1533
1534
  for (var r = r1; r <= r2; r += 1) {
1534
1535
  for (var c = c1; c <= c2; c += 1) {
1535
1536
  var index = getSheetIndex(ctx, ctx.currentSheetId);
@@ -1560,6 +1561,18 @@ export function deleteSelectedCellText(ctx) {
1560
1561
  if (hyperlinkMap && hyperlinkMap["".concat(r, "_").concat(c)]) {
1561
1562
  delete hyperlinkMap["".concat(r, "_").concat(c)];
1562
1563
  }
1564
+ if ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.afterUpdateCell) {
1565
+ ctx.hooks.afterUpdateCell(r, c, null, d[r][c]);
1566
+ }
1567
+ changes.push({
1568
+ sheetId: ctx.currentSheetId,
1569
+ path: ["celldata"],
1570
+ value: {
1571
+ r: r,
1572
+ c: c,
1573
+ v: d[r][c]
1574
+ }
1575
+ });
1563
1576
  }
1564
1577
  }
1565
1578
  }
@@ -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) {
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;
package/lib/api/cell.js CHANGED
@@ -61,8 +61,8 @@ function getCellValue(ctx, row, column, options) {
61
61
  }
62
62
  return ret;
63
63
  }
64
- function setCellValue(ctx, row, column, value, cellInput, options) {
65
- var _a;
64
+ function setCellValue(ctx, row, column, value, cellInput, options, callAfterUpdate) {
65
+ var _a, _b, _c;
66
66
  if (options === void 0) {
67
67
  options = {};
68
68
  }
@@ -123,7 +123,7 @@ function setCellValue(ctx, row, column, value, cellInput, options) {
123
123
  (0, _modules.setCellValue)(ctx, row, column, data, curv);
124
124
  }
125
125
  _lodash.default.forEach(value, function (v, attr) {
126
- if (attr in formatList) {
126
+ if (attr in formatList && callAfterUpdate) {
127
127
  (0, _modules.updateFormatCell)(ctx, data, attr, v, row, row, column, column);
128
128
  } else {
129
129
  cell_1[attr] = v;
@@ -138,6 +138,9 @@ function setCellValue(ctx, row, column, value, cellInput, options) {
138
138
  (0, _modules.setCellValue)(ctx, row, column, data, value);
139
139
  }
140
140
  }
141
+ if (callAfterUpdate && ctx.hooks.afterUpdateCell) {
142
+ (_c = (_b = ctx.hooks).afterUpdateCell) === null || _c === void 0 ? void 0 : _c.call(_b, row, column, null, value);
143
+ }
141
144
  }
142
145
  function clearCell(ctx, row, column, options) {
143
146
  var _a, _b;
@@ -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/lib/api/range.js CHANGED
@@ -92,7 +92,7 @@ function setSelection(ctx, range, options) {
92
92
  ctx.luckysheet_select_save = sheet.luckysheet_select_save;
93
93
  }
94
94
  }
95
- function setCellValuesByRange(ctx, data, range, cellInput, options) {
95
+ function setCellValuesByRange(ctx, data, range, cellInput, options, callAfterUpdate) {
96
96
  if (options === void 0) {
97
97
  options = {};
98
98
  }
@@ -114,7 +114,7 @@ function setCellValuesByRange(ctx, data, range, cellInput, options) {
114
114
  for (var j = 0; j < columnCount; j += 1) {
115
115
  var row = range.row[0] + i;
116
116
  var column = range.column[0] + j;
117
- (0, _cell.setCellValue)(ctx, row, column, data[i][j], cellInput, options);
117
+ (0, _cell.setCellValue)(ctx, row, column, data[i][j], cellInput, options, callAfterUpdate);
118
118
  }
119
119
  }
120
120
  }
@@ -94,6 +94,7 @@ function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow) {
94
94
  var stringOrCellRef = /"(?:\\.|[^"])*"|(\$?[A-Z]+\$?\d+)(?!\s*!)\b/g;
95
95
  var result = formula.replace(stringOrCellRef, function (m, cellRef) {
96
96
  if (!cellRef) return m;
97
+ if (cellRef.startsWith("$")) return m;
97
98
  return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
98
99
  var colIndex = columnLabelIndex(colLetters);
99
100
  var rowIndex = parseInt(rowNum, 10);
@@ -200,27 +201,42 @@ function postPasteCut(ctx, source, target, RowlChange) {
200
201
  (0, _sheet.storeSheetParamALL)(ctx);
201
202
  }
202
203
  var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
203
- var _a;
204
+ var _a, _b, _c;
205
+ var changes = [];
204
206
  for (var r = 0; r < d.length; r += 1) {
205
207
  var x = d[r];
206
208
  for (var c = 0; c < d[0].length; c += 1) {
207
209
  var value = (0, _lodash.isObject)(d[r][c]) ? (_a = d[r][c]) === null || _a === void 0 ? void 0 : _a.v : d[r][c];
208
210
  if (value && String(value).startsWith("=")) {
209
211
  var cell = {};
210
- var _b = (0, _formula.execfunction)(ctx, String(value), r, c, undefined, undefined, true),
211
- v = _b[1],
212
- f = _b[2];
212
+ var _d = (0, _formula.execfunction)(ctx, String(value), r, c, undefined, undefined, true),
213
+ v = _d[1],
214
+ f = _d[2];
213
215
  cell.v = v;
214
216
  cell.f = f;
215
217
  cell.m = v.toString();
216
218
  x[c] = cell;
217
219
  }
218
220
  d[r] = x;
221
+ changes.push({
222
+ sheetId: ctx.currentSheetId,
223
+ path: ["celldata"],
224
+ value: {
225
+ r: r,
226
+ c: c,
227
+ v: d[r][c]
228
+ },
229
+ key: "".concat(r, "_").concat(c),
230
+ type: "update"
231
+ });
219
232
  }
220
233
  }
234
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
235
+ (_c = ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc(changes);
236
+ }
221
237
  };
222
238
  function pasteHandler(ctx, data, borderInfo) {
223
- var _a, _b, _c, _d, _e, _f;
239
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
224
240
  if (ctx.luckysheet_selection_range) {
225
241
  ctx.luckysheet_selection_range = [];
226
242
  }
@@ -268,6 +284,7 @@ function pasteHandler(ctx, data, borderInfo) {
268
284
  }
269
285
  var RowlChange = false;
270
286
  var offsetMC = {};
287
+ var changes = [];
271
288
  for (var h = minh; h <= maxh; h += 1) {
272
289
  var x = d[h];
273
290
  var currentRowLen = ctx.defaultrowlen;
@@ -315,12 +332,26 @@ function pasteHandler(ctx, data, borderInfo) {
315
332
  };
316
333
  (_e = cfg.borderInfo) === null || _e === void 0 ? void 0 : _e.push(bd_obj);
317
334
  }
335
+ changes.push({
336
+ sheetId: ctx.currentSheetId,
337
+ path: ["celldata"],
338
+ value: {
339
+ r: h,
340
+ c: c,
341
+ v: d[h][c]
342
+ },
343
+ key: "".concat(h, "_").concat(c),
344
+ type: "update"
345
+ });
318
346
  }
319
347
  d[h] = x;
320
348
  if (currentRowLen !== ctx.defaultrowlen) {
321
349
  cfg.rowlen[h] = currentRowLen;
322
350
  }
323
351
  }
352
+ if ((_f = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _f === void 0 ? void 0 : _f.updateCellYdoc) {
353
+ (_g = ctx.hooks) === null || _g === void 0 ? void 0 : _g.updateCellYdoc(changes);
354
+ }
324
355
  ctx.luckysheet_select_save = [{
325
356
  row: [minh, maxh],
326
357
  column: [minc, maxc]
@@ -345,7 +376,7 @@ function pasteHandler(ctx, data, borderInfo) {
345
376
  }
346
377
  var d = (0, _context.getFlowdata)(ctx);
347
378
  if (!d) return;
348
- var last = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f[ctx.luckysheet_select_save.length - 1];
379
+ var last = (_h = ctx.luckysheet_select_save) === null || _h === void 0 ? void 0 : _h[ctx.luckysheet_select_save.length - 1];
349
380
  if (!last) return;
350
381
  var curR = last.row == null ? 0 : last.row[0];
351
382
  var curC = last.column == null ? 0 : last.column[0];
@@ -370,6 +401,7 @@ function pasteHandler(ctx, data, borderInfo) {
370
401
  if (!/^(https?:\/\/|www\.)\S+$/i.test(t)) return null;
371
402
  return t.startsWith("http") ? t : "https://".concat(t);
372
403
  };
404
+ var changes = [];
373
405
  for (var r = 0; r < rlen; r += 1) {
374
406
  var x = d[r + curR];
375
407
  for (var c = 0; c < clen; c += 1) {
@@ -460,9 +492,23 @@ function pasteHandler(ctx, data, borderInfo) {
460
492
  }
461
493
  x[c + curC] = cell;
462
494
  }
495
+ changes.push(changes.push({
496
+ sheetId: ctx.currentSheetId,
497
+ path: ["celldata"],
498
+ value: {
499
+ r: r,
500
+ c: c,
501
+ v: d[r][c]
502
+ },
503
+ key: "".concat(r, "_").concat(c),
504
+ type: "update"
505
+ }));
463
506
  }
464
507
  d[r + curR] = x;
465
508
  }
509
+ if ((_j = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _j === void 0 ? void 0 : _j.updateCellYdoc) {
510
+ (_k = ctx.hooks) === null || _k === void 0 ? void 0 : _k.updateCellYdoc(changes);
511
+ }
466
512
  last.row = [curR, curR + rlen - 1];
467
513
  last.column = [curC, curC + clen - 1];
468
514
  (0, _refresh.jfrefreshgrid)(ctx, null, undefined);
@@ -2019,7 +2019,6 @@ function updateDropCell(ctx) {
2019
2019
  var v = formula.execfunction(ctx, f, i, j);
2020
2020
  formula.execFunctionGroup(ctx, j, i, v[1], undefined, d);
2021
2021
  cell.v = v[1], cell.f = v[2];
2022
- console.log(j, i);
2023
2022
  var afterUpdateCell = ctx.hooks.afterUpdateCell;
2024
2023
  if (afterUpdateCell) {
2025
2024
  afterUpdateCell(i, j, null, __assign(__assign({}, cell), {
@@ -728,12 +728,6 @@ function replaceDotsInFunctionName(str) {
728
728
  return "=".concat(fixedFnName).concat(str.substring(openParenIndex));
729
729
  }
730
730
  function execfunction(ctx, txt, r, c, id, calcChainSet, isrefresh, notInsertFunc) {
731
- console.log("execfunction:", {
732
- txt: txt,
733
- r: r,
734
- c: c,
735
- id: id
736
- });
737
731
  var originalTxt = txt;
738
732
  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"))) {
739
733
  txt = replaceDotsInFunctionName(txt);
@@ -851,7 +845,6 @@ function execFunctionGroup(ctx, origin_r, origin_c, value, id, data, isForce) {
851
845
  if (isForce === void 0) {
852
846
  isForce = false;
853
847
  }
854
- console.log("execFunctionGroup", origin_r, origin_c, value, id, data);
855
848
  if (_lodash.default.isNil(data)) {
856
849
  data = (0, _context.getFlowdata)(ctx);
857
850
  }
@@ -57,7 +57,7 @@ function getCellHyperlink(ctx, r, c) {
57
57
  return undefined;
58
58
  }
59
59
  function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress, options) {
60
- var _a;
60
+ var _a, _b, _c;
61
61
  var applyToSelection = (options === null || options === void 0 ? void 0 : options.applyToSelection) && (options === null || options === void 0 ? void 0 : options.cellInput);
62
62
  var sheetIndex = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
63
63
  var flowdata = (0, _context.getFlowdata)(ctx);
@@ -107,6 +107,19 @@ function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress, options) {
107
107
  };
108
108
  flowdata[r][c] = cell;
109
109
  ctx.linkCard = undefined;
110
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
111
+ (_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc([{
112
+ sheetId: ctx.currentSheetId,
113
+ path: ["celldata"],
114
+ value: {
115
+ r: r,
116
+ c: c,
117
+ v: cell
118
+ },
119
+ key: "".concat(r, "_").concat(c),
120
+ type: "update"
121
+ }]);
122
+ }
110
123
  }
111
124
  }
112
125
  function removeHyperlink(ctx, r, c) {
@@ -1536,7 +1536,7 @@ function copy(ctx) {
1536
1536
  }
1537
1537
  }
1538
1538
  function deleteSelectedCellText(ctx) {
1539
- var _a, _b, _c;
1539
+ var _a, _b, _c, _d;
1540
1540
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
1541
1541
  if (allowEdit === false || ctx.isFlvReadOnly) {
1542
1542
  return "allowEdit";
@@ -1565,6 +1565,7 @@ function deleteSelectedCellText(ctx) {
1565
1565
  var r2 = selection[s].row[1];
1566
1566
  var c1 = selection[s].column[0];
1567
1567
  var c2 = selection[s].column[1];
1568
+ var changes = [];
1568
1569
  for (var r = r1; r <= r2; r += 1) {
1569
1570
  for (var c = c1; c <= c2; c += 1) {
1570
1571
  var index = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
@@ -1595,6 +1596,18 @@ function deleteSelectedCellText(ctx) {
1595
1596
  if (hyperlinkMap && hyperlinkMap["".concat(r, "_").concat(c)]) {
1596
1597
  delete hyperlinkMap["".concat(r, "_").concat(c)];
1597
1598
  }
1599
+ if ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.afterUpdateCell) {
1600
+ ctx.hooks.afterUpdateCell(r, c, null, d[r][c]);
1601
+ }
1602
+ changes.push({
1603
+ sheetId: ctx.currentSheetId,
1604
+ path: ["celldata"],
1605
+ value: {
1606
+ r: r,
1607
+ c: c,
1608
+ v: d[r][c]
1609
+ }
1610
+ });
1598
1611
  }
1599
1612
  }
1600
1613
  }
@@ -16,6 +16,16 @@ var _sheet = require("../api/sheet");
16
16
  var _locale = require("../locale");
17
17
  var _utils = require("../utils");
18
18
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
+ var __assign = void 0 && (void 0).__assign || function () {
20
+ __assign = Object.assign || function (t) {
21
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
22
+ s = arguments[i];
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
24
+ }
25
+ return t;
26
+ };
27
+ return __assign.apply(this, arguments);
28
+ };
19
29
  function storeSheetParam(ctx) {
20
30
  var index = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
21
31
  if (index == null) return;
@@ -32,7 +42,7 @@ function storeSheetParamALL(ctx) {
32
42
  ctx.luckysheetfile[index].config = ctx.config;
33
43
  }
34
44
  function changeSheet(ctx, id, isPivotInitial, isNewSheet, isCopySheet) {
35
- var _a, _b;
45
+ var _a, _b, _c, _d;
36
46
  if (id === ctx.currentSheetId) {
37
47
  return;
38
48
  }
@@ -48,14 +58,11 @@ function changeSheet(ctx, id, isPivotInitial, isNewSheet, isCopySheet) {
48
58
  ctx.luckysheetcurrentisPivotTable = false;
49
59
  }
50
60
  if (ctx.hooks.afterActivateSheet) {
51
- setTimeout(function () {
52
- var _a, _b;
53
- (_b = (_a = ctx.hooks).afterActivateSheet) === null || _b === void 0 ? void 0 : _b.call(_a, id);
54
- });
61
+ (_d = (_c = ctx.hooks).afterActivateSheet) === null || _d === void 0 ? void 0 : _d.call(_c, id);
55
62
  }
56
63
  }
57
64
  function addSheet(ctx, settings, newSheetID, isPivotTable, sheetName, sheetData) {
58
- var _a, _b;
65
+ var _a, _b, _c, _d;
59
66
  if (newSheetID === void 0) {
60
67
  newSheetID = undefined;
61
68
  }
@@ -99,18 +106,12 @@ function addSheet(ctx, settings, newSheetID, isPivotTable, sheetName, sheetData)
99
106
  return;
100
107
  }
101
108
  ctx.luckysheetfile.push(sheetconfig);
102
- if (!newSheetID) {
103
- changeSheet(ctx, id, isPivotTable, true);
104
- }
105
109
  if (ctx.hooks.afterAddSheet) {
106
- setTimeout(function () {
107
- var _a, _b;
108
- (_b = (_a = ctx.hooks).afterAddSheet) === null || _b === void 0 ? void 0 : _b.call(_a, sheetconfig);
109
- });
110
+ (_d = (_c = ctx.hooks).afterAddSheet) === null || _d === void 0 ? void 0 : _d.call(_c, __assign({}, sheetconfig));
110
111
  }
111
112
  }
112
113
  function deleteSheet(ctx, id) {
113
- var _a, _b, _c;
114
+ var _a, _b, _c, _d, _e;
114
115
  if (ctx.allowEdit === false) {
115
116
  return;
116
117
  }
@@ -136,10 +137,7 @@ function deleteSheet(ctx, id) {
136
137
  ctx.currentSheetId = (_c = orderSheets === null || orderSheets === void 0 ? void 0 : orderSheets[0]) === null || _c === void 0 ? void 0 : _c.id;
137
138
  }
138
139
  if (ctx.hooks.afterDeleteSheet) {
139
- setTimeout(function () {
140
- var _a, _b;
141
- (_b = (_a = ctx.hooks).afterDeleteSheet) === null || _b === void 0 ? void 0 : _b.call(_a, id);
142
- });
140
+ (_e = (_d = ctx.hooks).afterDeleteSheet) === null || _e === void 0 ? void 0 : _e.call(_d, id);
143
141
  }
144
142
  }
145
143
  function updateSheet(ctx, newData) {
@@ -49,12 +49,13 @@ var _conditionalFormat = require("./conditionalFormat");
49
49
  var _text = require("./text");
50
50
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
51
51
  function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col_ed, canvas) {
52
- 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;
53
- var _7;
52
+ 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;
53
+ var _11;
54
54
  if (_lodash.default.isNil(d) || _lodash.default.isNil(attr)) {
55
55
  return;
56
56
  }
57
57
  if (attr === "ct") {
58
+ var changes = [];
58
59
  for (var r = row_st; r <= row_ed; r += 1) {
59
60
  if (!_lodash.default.isNil(ctx.config.rowhidden) && !_lodash.default.isNil(ctx.config.rowhidden[r])) {
60
61
  continue;
@@ -130,6 +131,20 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
130
131
  m: mask
131
132
  };
132
133
  }
134
+ changes.push({
135
+ sheetId: ctx.currentSheetId,
136
+ path: ["celldata"],
137
+ value: {
138
+ r: r,
139
+ c: c,
140
+ v: d[r][c]
141
+ },
142
+ key: "".concat(r, "_").concat(c),
143
+ type: "update"
144
+ });
145
+ }
146
+ if ((_x = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _x === void 0 ? void 0 : _x.updateCellYdoc) {
147
+ (_y = ctx.hooks) === null || _y === void 0 ? void 0 : _y.updateCellYdoc(changes);
133
148
  }
134
149
  }
135
150
  } else {
@@ -176,6 +191,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
176
191
  if (sheetIndex == null) {
177
192
  return;
178
193
  }
194
+ var changes = [];
179
195
  for (var r = row_st; r <= row_ed; r += 1) {
180
196
  if (!_lodash.default.isNil(ctx.config.rowhidden) && !_lodash.default.isNil(ctx.config.rowhidden[r])) {
181
197
  continue;
@@ -185,11 +201,11 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
185
201
  if (value && _lodash.default.isPlainObject(value)) {
186
202
  (0, _inlineString.updateInlineStringFormatOutside)(value, attr, foucsStatus);
187
203
  value[attr] = foucsStatus;
188
- (_7 = ctx.luckysheetfile[sheetIndex]).config || (_7.config = {});
204
+ (_11 = ctx.luckysheetfile[sheetIndex]).config || (_11.config = {});
189
205
  var cfg = ctx.luckysheetfile[sheetIndex].config;
190
- var cellWidth = ((_x = cfg.columnlen) === null || _x === void 0 ? void 0 : _x[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
206
+ var cellWidth = ((_z = cfg.columnlen) === null || _z === void 0 ? void 0 : _z[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
191
207
  if (attr === "tb" && canvas && foucsStatus === "2") {
192
- var currentColWidth_1 = ((_y = cfg.columnlen) === null || _y === void 0 ? void 0 : _y[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
208
+ var currentColWidth_1 = ((_0 = cfg.columnlen) === null || _0 === void 0 ? void 0 : _0[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
193
209
  var lineCount_1 = 1;
194
210
  var fontString_1 = "10px Arial";
195
211
  if (value.fs) {
@@ -202,9 +218,9 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
202
218
  lineCount_1 = (0, _utils.getLineCount)(value.m, currentColWidth_1, fontString_1);
203
219
  var hOffset = lineCount_1 < 4 ? 1.9 : 1.7;
204
220
  lineCount_1 = lineCount_1 * hOffset + 1;
205
- } 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) {
221
+ } 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) {
206
222
  lineCount_1 -= 1;
207
- 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");
223
+ 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");
208
224
  line.forEach(function (item) {
209
225
  var subLineCount = (0, _utils.getLineCount)(item, currentColWidth_1, fontString_1);
210
226
  lineCount_1 += subLineCount;
@@ -224,7 +240,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
224
240
  });
225
241
  if (!textInfo) return "continue";
226
242
  var rowHeight = _lodash.default.round(textInfo.textHeightAll);
227
- var currentRowHeight = ((_5 = cfg.rowlen) === null || _5 === void 0 ? void 0 : _5[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
243
+ var currentRowHeight = ((_7 = cfg.rowlen) === null || _7 === void 0 ? void 0 : _7[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
228
244
  if (!_lodash.default.isUndefined(rowHeight) && rowHeight > currentRowHeight && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
229
245
  if (_lodash.default.isUndefined(cfg.rowlen)) cfg.rowlen = {};
230
246
  _lodash.default.set(cfg, "rowlen.".concat(r), rowHeight);
@@ -239,7 +255,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
239
255
  });
240
256
  if (!textInfo) return "continue";
241
257
  var newHeight = _lodash.default.round(textInfo.textHeightAll);
242
- var oldHeight = ((_6 = cfg.rowlen) === null || _6 === void 0 ? void 0 : _6[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
258
+ var oldHeight = ((_8 = cfg.rowlen) === null || _8 === void 0 ? void 0 : _8[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
243
259
  var shouldResize = foucsStatus === "2" ? newHeight > oldHeight : true;
244
260
  if (shouldResize && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
245
261
  var padding = 12;
@@ -254,11 +270,25 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
254
270
  };
255
271
  d[r][c][attr] = foucsStatus;
256
272
  }
273
+ changes.push({
274
+ sheetId: ctx.currentSheetId,
275
+ path: ["celldata"],
276
+ value: {
277
+ r: r,
278
+ c: c,
279
+ v: d[r][c]
280
+ },
281
+ key: "".concat(r, "_").concat(c),
282
+ type: "update"
283
+ });
257
284
  };
258
285
  for (var c = col_st; c <= col_ed; c += 1) {
259
286
  _loop_1(c);
260
287
  }
261
288
  }
289
+ if ((_9 = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _9 === void 0 ? void 0 : _9.updateCellYdoc) {
290
+ (_10 = ctx.hooks) === null || _10 === void 0 ? void 0 : _10.updateCellYdoc(changes);
291
+ }
262
292
  }
263
293
  }
264
294
  function updateFormat(ctx, $input, d, attr, foucsStatus, canvas) {
package/lib/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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.3.9",
3
+ "version": "1.3.10",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",