@fileverse-dev/fortune-core 1.2.99-data-validation-fix-1 → 1.2.99-ydoc-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.
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
  }
package/es/api/sheet.js CHANGED
@@ -173,23 +173,22 @@ export function calculateSheetFromula(ctx, id) {
173
173
  }
174
174
  }
175
175
  export function calculateReferencedCellSheetFromula(ctx, id, refCell) {
176
- var _a, _b, _c, _d, _e, _f;
176
+ var _a, _b, _c, _d, _e;
177
177
  var index = getSheetIndex(ctx, id);
178
178
  if (!ctx.luckysheetfile[index].data) return;
179
179
  var _loop_1 = function _loop_1(r) {
180
180
  var _loop_2 = function _loop_2(c) {
181
- console.log(refCell, (_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f);
182
181
  var isRef = false;
183
- if (refCell && ((_b = ctx.luckysheetfile[index].data[r][c]) === null || _b === void 0 ? void 0 : _b.f) && !((_c = ctx.luckysheetfile[index].data[r][c]) === null || _c === void 0 ? void 0 : _c.isDataBlockFormula)) {
182
+ if (refCell && ((_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f) && !((_b = ctx.luckysheetfile[index].data[r][c]) === null || _b === void 0 ? void 0 : _b.isDataBlockFormula)) {
184
183
  isRef = refCell.some(function (cell) {
185
184
  var _a;
186
185
  return isCellReferenced((_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f, cell);
187
186
  });
188
187
  }
189
- if (!isRef || !((_d = ctx.luckysheetfile[index].data[r][c]) === null || _d === void 0 ? void 0 : _d.f) || ((_e = ctx.luckysheetfile[index].data[r][c]) === null || _e === void 0 ? void 0 : _e.isDataBlockFormula)) {
188
+ if (!isRef || !((_c = ctx.luckysheetfile[index].data[r][c]) === null || _c === void 0 ? void 0 : _c.f) || ((_d = ctx.luckysheetfile[index].data[r][c]) === null || _d === void 0 ? void 0 : _d.isDataBlockFormula)) {
190
189
  return "continue";
191
190
  }
192
- var result = execfunction(ctx, (_f = ctx.luckysheetfile[index].data[r][c]) === null || _f === void 0 ? void 0 : _f.f, r, c, id);
191
+ var result = execfunction(ctx, (_e = ctx.luckysheetfile[index].data[r][c]) === null || _e === void 0 ? void 0 : _e.f, r, c, id);
193
192
  var isValueArray = Array.isArray(result[1]);
194
193
  if (isValueArray) {
195
194
  var value = {
package/es/context.d.ts CHANGED
@@ -53,11 +53,6 @@ export type Context = {
53
53
  optionLabel_es: any;
54
54
  optionLabel_hi: any;
55
55
  dataRegulation?: DataRegulationProps;
56
- updateScope?: "current" | "all";
57
- sourceCell?: {
58
- row: number;
59
- col: number;
60
- };
61
56
  };
62
57
  dataVerificationDropDownList?: boolean;
63
58
  conditionRules: ConditionRulesProps;
@@ -82,7 +82,6 @@ export function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow)
82
82
  var result = formula.replace(stringOrCellRef, function (m, cellRef) {
83
83
  if (!cellRef) return m;
84
84
  if (cellRef.startsWith("$")) return m;
85
- console.log(m, "cellRef", cellRef);
86
85
  return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
87
86
  var colIndex = columnLabelIndex(colLetters);
88
87
  var rowIndex = parseInt(rowNum, 10);
@@ -189,28 +188,43 @@ function postPasteCut(ctx, source, target, RowlChange) {
189
188
  storeSheetParamALL(ctx);
190
189
  }
191
190
  var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
192
- var _a;
191
+ var _a, _b, _c;
192
+ var changes = [];
193
193
  for (var r = 0; r < d.length; r += 1) {
194
194
  var x = d[r];
195
195
  for (var c = 0; c < d[0].length; c += 1) {
196
196
  var value = isObject(d[r][c]) ? (_a = d[r][c]) === null || _a === void 0 ? void 0 : _a.v : d[r][c];
197
197
  if (value && String(value).startsWith("=")) {
198
198
  var cell = {};
199
- var _b = execfunction(ctx, String(value), r, c, undefined, undefined, true),
200
- v = _b[1],
201
- f = _b[2];
199
+ var _d = execfunction(ctx, String(value), r, c, undefined, undefined, true),
200
+ v = _d[1],
201
+ f = _d[2];
202
202
  cell.v = v;
203
203
  cell.f = f;
204
204
  cell.m = v.toString();
205
205
  x[c] = cell;
206
206
  }
207
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
+ });
208
219
  }
209
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
+ }
210
224
  };
211
225
  function pasteHandler(ctx, data, borderInfo) {
212
226
  var _a;
213
- var _b, _c, _d, _e, _f, _g;
227
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
214
228
  if (ctx.luckysheet_selection_range) {
215
229
  ctx.luckysheet_selection_range = [];
216
230
  }
@@ -258,6 +272,7 @@ function pasteHandler(ctx, data, borderInfo) {
258
272
  }
259
273
  var RowlChange = false;
260
274
  var offsetMC = {};
275
+ var changes = [];
261
276
  for (var h = minh; h <= maxh; h += 1) {
262
277
  var x = d[h];
263
278
  var currentRowLen = ctx.defaultrowlen;
@@ -305,12 +320,26 @@ function pasteHandler(ctx, data, borderInfo) {
305
320
  };
306
321
  (_f = cfg.borderInfo) === null || _f === void 0 ? void 0 : _f.push(bd_obj);
307
322
  }
323
+ changes.push({
324
+ sheetId: ctx.currentSheetId,
325
+ path: ["celldata"],
326
+ value: {
327
+ r: h,
328
+ c: c,
329
+ v: d[h][c]
330
+ },
331
+ key: "".concat(h, "_").concat(c),
332
+ type: "update"
333
+ });
308
334
  }
309
335
  d[h] = x;
310
336
  if (currentRowLen !== ctx.defaultrowlen) {
311
337
  cfg.rowlen[h] = currentRowLen;
312
338
  }
313
339
  }
340
+ if ((_g = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _g === void 0 ? void 0 : _g.updateCellYdoc) {
341
+ (_h = ctx.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc(changes);
342
+ }
314
343
  ctx.luckysheet_select_save = [{
315
344
  row: [minh, maxh],
316
345
  column: [minc, maxc]
@@ -335,7 +364,7 @@ function pasteHandler(ctx, data, borderInfo) {
335
364
  }
336
365
  var d = getFlowdata(ctx);
337
366
  if (!d) return;
338
- var last = (_g = ctx.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g[ctx.luckysheet_select_save.length - 1];
367
+ var last = (_j = ctx.luckysheet_select_save) === null || _j === void 0 ? void 0 : _j[ctx.luckysheet_select_save.length - 1];
339
368
  if (!last) return;
340
369
  var curR = last.row == null ? 0 : last.row[0];
341
370
  var curC = last.column == null ? 0 : last.column[0];
@@ -360,6 +389,7 @@ function pasteHandler(ctx, data, borderInfo) {
360
389
  if (!/^(https?:\/\/|www\.)\S+$/i.test(t)) return null;
361
390
  return t.startsWith("http") ? t : "https://".concat(t);
362
391
  };
392
+ var changes = [];
363
393
  for (var r = 0; r < rlen; r += 1) {
364
394
  var x = d[r + curR];
365
395
  for (var c = 0; c < clen; c += 1) {
@@ -432,9 +462,23 @@ function pasteHandler(ctx, data, borderInfo) {
432
462
  }
433
463
  x[c + curC] = cell;
434
464
  }
465
+ changes.push(changes.push({
466
+ sheetId: ctx.currentSheetId,
467
+ path: ["celldata"],
468
+ value: {
469
+ r: r,
470
+ c: c,
471
+ v: d[r][c]
472
+ },
473
+ key: "".concat(r, "_").concat(c),
474
+ type: "update"
475
+ }));
435
476
  }
436
477
  d[r + curR] = x;
437
478
  }
479
+ if ((_k = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _k === void 0 ? void 0 : _k.updateCellYdoc) {
480
+ (_l = ctx.hooks) === null || _l === void 0 ? void 0 : _l.updateCellYdoc(changes);
481
+ }
438
482
  last.row = [curR, curR + rlen - 1];
439
483
  last.column = [curC, curC + clen - 1];
440
484
  jfrefreshgrid(ctx, null, undefined);
@@ -1013,7 +1057,6 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
1013
1057
  var isError = false;
1014
1058
  try {
1015
1059
  adjustedFormula = adjustFormulaForPaste(value.f, c_c1, c_r1, c, h);
1016
- console.log("adjustedFormula", adjustedFormula);
1017
1060
  } catch (error) {
1018
1061
  isError = true;
1019
1062
  value.error = {
@@ -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
  }
@@ -39,6 +39,7 @@ export function getCellHyperlink(ctx, r, c) {
39
39
  return undefined;
40
40
  }
41
41
  export function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress) {
42
+ var _a, _b;
42
43
  var sheetIndex = getSheetIndex(ctx, ctx.currentSheetId);
43
44
  var flowdata = getFlowdata(ctx);
44
45
  if (sheetIndex != null && flowdata != null && linkType && linkAddress) {
@@ -59,6 +60,19 @@ export function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress) {
59
60
  };
60
61
  flowdata[r][c] = cell;
61
62
  ctx.linkCard = undefined;
63
+ if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc) {
64
+ (_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc([{
65
+ sheetId: ctx.currentSheetId,
66
+ path: ["celldata"],
67
+ value: {
68
+ r: r,
69
+ c: c,
70
+ v: cell
71
+ },
72
+ key: "".concat(r, "_").concat(c),
73
+ type: "update"
74
+ }]);
75
+ }
62
76
  }
63
77
  }
64
78
  export function removeHyperlink(ctx, r, c) {
@@ -1496,7 +1496,7 @@ export function copy(ctx) {
1496
1496
  }
1497
1497
  }
1498
1498
  export function deleteSelectedCellText(ctx) {
1499
- var _a, _b, _c;
1499
+ var _a, _b, _c, _d;
1500
1500
  var allowEdit = isAllowEdit(ctx);
1501
1501
  if (allowEdit === false || ctx.isFlvReadOnly) {
1502
1502
  return "allowEdit";
@@ -1525,6 +1525,7 @@ export function deleteSelectedCellText(ctx) {
1525
1525
  var r2 = selection[s].row[1];
1526
1526
  var c1 = selection[s].column[0];
1527
1527
  var c2 = selection[s].column[1];
1528
+ var changes = [];
1528
1529
  for (var r = r1; r <= r2; r += 1) {
1529
1530
  for (var c = c1; c <= c2; c += 1) {
1530
1531
  var index = getSheetIndex(ctx, ctx.currentSheetId);
@@ -1553,6 +1554,18 @@ export function deleteSelectedCellText(ctx) {
1553
1554
  if (hyperlinkMap && hyperlinkMap["".concat(r, "_").concat(c)]) {
1554
1555
  delete hyperlinkMap["".concat(r, "_").concat(c)];
1555
1556
  }
1557
+ if ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.afterUpdateCell) {
1558
+ ctx.hooks.afterUpdateCell(r, c, null, d[r][c]);
1559
+ }
1560
+ changes.push({
1561
+ sheetId: ctx.currentSheetId,
1562
+ path: ["celldata"],
1563
+ value: {
1564
+ r: r,
1565
+ c: c,
1566
+ v: d[r][c]
1567
+ }
1568
+ });
1556
1569
  }
1557
1570
  }
1558
1571
  }
@@ -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) {
@@ -15,12 +15,13 @@ import { showLinkCard } from "./hyperlink";
15
15
  import { cfSplitRange } from "./conditionalFormat";
16
16
  import { clearMeasureTextCache, getCellTextInfo } from "./text";
17
17
  export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col_ed, canvas) {
18
- 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;
19
- var _7;
18
+ 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;
19
+ var _11;
20
20
  if (_.isNil(d) || _.isNil(attr)) {
21
21
  return;
22
22
  }
23
23
  if (attr === "ct") {
24
+ var changes = [];
24
25
  for (var r = row_st; r <= row_ed; r += 1) {
25
26
  if (!_.isNil(ctx.config.rowhidden) && !_.isNil(ctx.config.rowhidden[r])) {
26
27
  continue;
@@ -72,6 +73,20 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
72
73
  m: mask
73
74
  };
74
75
  }
76
+ changes.push({
77
+ sheetId: ctx.currentSheetId,
78
+ path: ["celldata"],
79
+ value: {
80
+ r: r,
81
+ c: c,
82
+ v: d[r][c]
83
+ },
84
+ key: "".concat(r, "_").concat(c),
85
+ type: "update"
86
+ });
87
+ }
88
+ if ((_x = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _x === void 0 ? void 0 : _x.updateCellYdoc) {
89
+ (_y = ctx.hooks) === null || _y === void 0 ? void 0 : _y.updateCellYdoc(changes);
75
90
  }
76
91
  }
77
92
  } else {
@@ -118,6 +133,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
118
133
  if (sheetIndex == null) {
119
134
  return;
120
135
  }
136
+ var changes = [];
121
137
  for (var r = row_st; r <= row_ed; r += 1) {
122
138
  if (!_.isNil(ctx.config.rowhidden) && !_.isNil(ctx.config.rowhidden[r])) {
123
139
  continue;
@@ -127,11 +143,11 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
127
143
  if (value && _.isPlainObject(value)) {
128
144
  updateInlineStringFormatOutside(value, attr, foucsStatus);
129
145
  value[attr] = foucsStatus;
130
- (_7 = ctx.luckysheetfile[sheetIndex]).config || (_7.config = {});
146
+ (_11 = ctx.luckysheetfile[sheetIndex]).config || (_11.config = {});
131
147
  var cfg = ctx.luckysheetfile[sheetIndex].config;
132
- var cellWidth = ((_x = cfg.columnlen) === null || _x === void 0 ? void 0 : _x[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
148
+ var cellWidth = ((_z = cfg.columnlen) === null || _z === void 0 ? void 0 : _z[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
133
149
  if (attr === "tb" && canvas && foucsStatus === "2") {
134
- var currentColWidth_1 = ((_y = cfg.columnlen) === null || _y === void 0 ? void 0 : _y[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
150
+ var currentColWidth_1 = ((_0 = cfg.columnlen) === null || _0 === void 0 ? void 0 : _0[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
135
151
  var lineCount_1 = 1;
136
152
  var fontString_1 = "10px Arial";
137
153
  if (value.fs) {
@@ -144,9 +160,9 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
144
160
  lineCount_1 = getLineCount(value.m, currentColWidth_1, fontString_1);
145
161
  var hOffset = lineCount_1 < 4 ? 1.9 : 1.7;
146
162
  lineCount_1 = lineCount_1 * hOffset + 1;
147
- } 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) {
163
+ } 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) {
148
164
  lineCount_1 -= 1;
149
- 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");
165
+ 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");
150
166
  line.forEach(function (item) {
151
167
  var subLineCount = getLineCount(item, currentColWidth_1, fontString_1);
152
168
  lineCount_1 += subLineCount;
@@ -166,7 +182,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
166
182
  });
167
183
  if (!textInfo) return "continue";
168
184
  var rowHeight = _.round(textInfo.textHeightAll);
169
- var currentRowHeight = ((_5 = cfg.rowlen) === null || _5 === void 0 ? void 0 : _5[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
185
+ var currentRowHeight = ((_7 = cfg.rowlen) === null || _7 === void 0 ? void 0 : _7[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
170
186
  if (!_.isUndefined(rowHeight) && rowHeight > currentRowHeight && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
171
187
  if (_.isUndefined(cfg.rowlen)) cfg.rowlen = {};
172
188
  _.set(cfg, "rowlen.".concat(r), rowHeight);
@@ -181,7 +197,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
181
197
  });
182
198
  if (!textInfo) return "continue";
183
199
  var newHeight = _.round(textInfo.textHeightAll);
184
- var oldHeight = ((_6 = cfg.rowlen) === null || _6 === void 0 ? void 0 : _6[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
200
+ var oldHeight = ((_8 = cfg.rowlen) === null || _8 === void 0 ? void 0 : _8[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
185
201
  var shouldResize = foucsStatus === "2" ? newHeight > oldHeight : true;
186
202
  if (shouldResize && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
187
203
  var padding = 12;
@@ -196,11 +212,25 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
196
212
  };
197
213
  d[r][c][attr] = foucsStatus;
198
214
  }
215
+ changes.push({
216
+ sheetId: ctx.currentSheetId,
217
+ path: ["celldata"],
218
+ value: {
219
+ r: r,
220
+ c: c,
221
+ v: d[r][c]
222
+ },
223
+ key: "".concat(r, "_").concat(c),
224
+ type: "update"
225
+ });
199
226
  };
200
227
  for (var c = col_st; c <= col_ed; c += 1) {
201
228
  _loop_1(c);
202
229
  }
203
230
  }
231
+ if ((_9 = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _9 === void 0 ? void 0 : _9.updateCellYdoc) {
232
+ (_10 = ctx.hooks) === null || _10 === void 0 ? void 0 : _10.updateCellYdoc(changes);
233
+ }
204
234
  }
205
235
  }
206
236
  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
  }
package/lib/api/sheet.js CHANGED
@@ -191,23 +191,22 @@ function calculateSheetFromula(ctx, id) {
191
191
  }
192
192
  }
193
193
  function calculateReferencedCellSheetFromula(ctx, id, refCell) {
194
- var _a, _b, _c, _d, _e, _f;
194
+ var _a, _b, _c, _d, _e;
195
195
  var index = (0, _utils.getSheetIndex)(ctx, id);
196
196
  if (!ctx.luckysheetfile[index].data) return;
197
197
  var _loop_1 = function _loop_1(r) {
198
198
  var _loop_2 = function _loop_2(c) {
199
- console.log(refCell, (_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f);
200
199
  var isRef = false;
201
- if (refCell && ((_b = ctx.luckysheetfile[index].data[r][c]) === null || _b === void 0 ? void 0 : _b.f) && !((_c = ctx.luckysheetfile[index].data[r][c]) === null || _c === void 0 ? void 0 : _c.isDataBlockFormula)) {
200
+ if (refCell && ((_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f) && !((_b = ctx.luckysheetfile[index].data[r][c]) === null || _b === void 0 ? void 0 : _b.isDataBlockFormula)) {
202
201
  isRef = refCell.some(function (cell) {
203
202
  var _a;
204
203
  return isCellReferenced((_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f, cell);
205
204
  });
206
205
  }
207
- if (!isRef || !((_d = ctx.luckysheetfile[index].data[r][c]) === null || _d === void 0 ? void 0 : _d.f) || ((_e = ctx.luckysheetfile[index].data[r][c]) === null || _e === void 0 ? void 0 : _e.isDataBlockFormula)) {
206
+ if (!isRef || !((_c = ctx.luckysheetfile[index].data[r][c]) === null || _c === void 0 ? void 0 : _c.f) || ((_d = ctx.luckysheetfile[index].data[r][c]) === null || _d === void 0 ? void 0 : _d.isDataBlockFormula)) {
208
207
  return "continue";
209
208
  }
210
- var result = (0, _2.execfunction)(ctx, (_f = ctx.luckysheetfile[index].data[r][c]) === null || _f === void 0 ? void 0 : _f.f, r, c, id);
209
+ var result = (0, _2.execfunction)(ctx, (_e = ctx.luckysheetfile[index].data[r][c]) === null || _e === void 0 ? void 0 : _e.f, r, c, id);
211
210
  var isValueArray = Array.isArray(result[1]);
212
211
  if (isValueArray) {
213
212
  var value = {
package/lib/context.d.ts CHANGED
@@ -53,11 +53,6 @@ export type Context = {
53
53
  optionLabel_es: any;
54
54
  optionLabel_hi: any;
55
55
  dataRegulation?: DataRegulationProps;
56
- updateScope?: "current" | "all";
57
- sourceCell?: {
58
- row: number;
59
- col: number;
60
- };
61
56
  };
62
57
  dataVerificationDropDownList?: boolean;
63
58
  conditionRules: ConditionRulesProps;
@@ -95,7 +95,6 @@ function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow) {
95
95
  var result = formula.replace(stringOrCellRef, function (m, cellRef) {
96
96
  if (!cellRef) return m;
97
97
  if (cellRef.startsWith("$")) return m;
98
- console.log(m, "cellRef", cellRef);
99
98
  return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
100
99
  var colIndex = columnLabelIndex(colLetters);
101
100
  var rowIndex = parseInt(rowNum, 10);
@@ -202,28 +201,43 @@ function postPasteCut(ctx, source, target, RowlChange) {
202
201
  (0, _sheet.storeSheetParamALL)(ctx);
203
202
  }
204
203
  var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
205
- var _a;
204
+ var _a, _b, _c;
205
+ var changes = [];
206
206
  for (var r = 0; r < d.length; r += 1) {
207
207
  var x = d[r];
208
208
  for (var c = 0; c < d[0].length; c += 1) {
209
209
  var value = (0, _lodash.isObject)(d[r][c]) ? (_a = d[r][c]) === null || _a === void 0 ? void 0 : _a.v : d[r][c];
210
210
  if (value && String(value).startsWith("=")) {
211
211
  var cell = {};
212
- var _b = (0, _formula.execfunction)(ctx, String(value), r, c, undefined, undefined, true),
213
- v = _b[1],
214
- 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];
215
215
  cell.v = v;
216
216
  cell.f = f;
217
217
  cell.m = v.toString();
218
218
  x[c] = cell;
219
219
  }
220
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
+ });
221
232
  }
222
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
+ }
223
237
  };
224
238
  function pasteHandler(ctx, data, borderInfo) {
225
239
  var _a;
226
- var _b, _c, _d, _e, _f, _g;
240
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
227
241
  if (ctx.luckysheet_selection_range) {
228
242
  ctx.luckysheet_selection_range = [];
229
243
  }
@@ -271,6 +285,7 @@ function pasteHandler(ctx, data, borderInfo) {
271
285
  }
272
286
  var RowlChange = false;
273
287
  var offsetMC = {};
288
+ var changes = [];
274
289
  for (var h = minh; h <= maxh; h += 1) {
275
290
  var x = d[h];
276
291
  var currentRowLen = ctx.defaultrowlen;
@@ -318,12 +333,26 @@ function pasteHandler(ctx, data, borderInfo) {
318
333
  };
319
334
  (_f = cfg.borderInfo) === null || _f === void 0 ? void 0 : _f.push(bd_obj);
320
335
  }
336
+ changes.push({
337
+ sheetId: ctx.currentSheetId,
338
+ path: ["celldata"],
339
+ value: {
340
+ r: h,
341
+ c: c,
342
+ v: d[h][c]
343
+ },
344
+ key: "".concat(h, "_").concat(c),
345
+ type: "update"
346
+ });
321
347
  }
322
348
  d[h] = x;
323
349
  if (currentRowLen !== ctx.defaultrowlen) {
324
350
  cfg.rowlen[h] = currentRowLen;
325
351
  }
326
352
  }
353
+ if ((_g = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _g === void 0 ? void 0 : _g.updateCellYdoc) {
354
+ (_h = ctx.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc(changes);
355
+ }
327
356
  ctx.luckysheet_select_save = [{
328
357
  row: [minh, maxh],
329
358
  column: [minc, maxc]
@@ -348,7 +377,7 @@ function pasteHandler(ctx, data, borderInfo) {
348
377
  }
349
378
  var d = (0, _context.getFlowdata)(ctx);
350
379
  if (!d) return;
351
- var last = (_g = ctx.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g[ctx.luckysheet_select_save.length - 1];
380
+ var last = (_j = ctx.luckysheet_select_save) === null || _j === void 0 ? void 0 : _j[ctx.luckysheet_select_save.length - 1];
352
381
  if (!last) return;
353
382
  var curR = last.row == null ? 0 : last.row[0];
354
383
  var curC = last.column == null ? 0 : last.column[0];
@@ -373,6 +402,7 @@ function pasteHandler(ctx, data, borderInfo) {
373
402
  if (!/^(https?:\/\/|www\.)\S+$/i.test(t)) return null;
374
403
  return t.startsWith("http") ? t : "https://".concat(t);
375
404
  };
405
+ var changes = [];
376
406
  for (var r = 0; r < rlen; r += 1) {
377
407
  var x = d[r + curR];
378
408
  for (var c = 0; c < clen; c += 1) {
@@ -445,9 +475,23 @@ function pasteHandler(ctx, data, borderInfo) {
445
475
  }
446
476
  x[c + curC] = cell;
447
477
  }
478
+ changes.push(changes.push({
479
+ sheetId: ctx.currentSheetId,
480
+ path: ["celldata"],
481
+ value: {
482
+ r: r,
483
+ c: c,
484
+ v: d[r][c]
485
+ },
486
+ key: "".concat(r, "_").concat(c),
487
+ type: "update"
488
+ }));
448
489
  }
449
490
  d[r + curR] = x;
450
491
  }
492
+ if ((_k = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _k === void 0 ? void 0 : _k.updateCellYdoc) {
493
+ (_l = ctx.hooks) === null || _l === void 0 ? void 0 : _l.updateCellYdoc(changes);
494
+ }
451
495
  last.row = [curR, curR + rlen - 1];
452
496
  last.column = [curC, curC + clen - 1];
453
497
  (0, _refresh.jfrefreshgrid)(ctx, null, undefined);
@@ -1026,7 +1070,6 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
1026
1070
  var isError = false;
1027
1071
  try {
1028
1072
  adjustedFormula = adjustFormulaForPaste(value.f, c_c1, c_r1, c, h);
1029
- console.log("adjustedFormula", adjustedFormula);
1030
1073
  } catch (error) {
1031
1074
  isError = true;
1032
1075
  value.error = {
@@ -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
  }
@@ -55,6 +55,7 @@ function getCellHyperlink(ctx, r, c) {
55
55
  return undefined;
56
56
  }
57
57
  function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress) {
58
+ var _a, _b;
58
59
  var sheetIndex = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
59
60
  var flowdata = (0, _context.getFlowdata)(ctx);
60
61
  if (sheetIndex != null && flowdata != null && linkType && linkAddress) {
@@ -75,6 +76,19 @@ function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress) {
75
76
  };
76
77
  flowdata[r][c] = cell;
77
78
  ctx.linkCard = undefined;
79
+ if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc) {
80
+ (_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc([{
81
+ sheetId: ctx.currentSheetId,
82
+ path: ["celldata"],
83
+ value: {
84
+ r: r,
85
+ c: c,
86
+ v: cell
87
+ },
88
+ key: "".concat(r, "_").concat(c),
89
+ type: "update"
90
+ }]);
91
+ }
78
92
  }
79
93
  }
80
94
  function removeHyperlink(ctx, r, c) {
@@ -1531,7 +1531,7 @@ function copy(ctx) {
1531
1531
  }
1532
1532
  }
1533
1533
  function deleteSelectedCellText(ctx) {
1534
- var _a, _b, _c;
1534
+ var _a, _b, _c, _d;
1535
1535
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
1536
1536
  if (allowEdit === false || ctx.isFlvReadOnly) {
1537
1537
  return "allowEdit";
@@ -1560,6 +1560,7 @@ function deleteSelectedCellText(ctx) {
1560
1560
  var r2 = selection[s].row[1];
1561
1561
  var c1 = selection[s].column[0];
1562
1562
  var c2 = selection[s].column[1];
1563
+ var changes = [];
1563
1564
  for (var r = r1; r <= r2; r += 1) {
1564
1565
  for (var c = c1; c <= c2; c += 1) {
1565
1566
  var index = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
@@ -1588,6 +1589,18 @@ function deleteSelectedCellText(ctx) {
1588
1589
  if (hyperlinkMap && hyperlinkMap["".concat(r, "_").concat(c)]) {
1589
1590
  delete hyperlinkMap["".concat(r, "_").concat(c)];
1590
1591
  }
1592
+ if ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.afterUpdateCell) {
1593
+ ctx.hooks.afterUpdateCell(r, c, null, d[r][c]);
1594
+ }
1595
+ changes.push({
1596
+ sheetId: ctx.currentSheetId,
1597
+ path: ["celldata"],
1598
+ value: {
1599
+ r: r,
1600
+ c: c,
1601
+ v: d[r][c]
1602
+ }
1603
+ });
1591
1604
  }
1592
1605
  }
1593
1606
  }
@@ -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) {
@@ -48,12 +48,13 @@ var _conditionalFormat = require("./conditionalFormat");
48
48
  var _text = require("./text");
49
49
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
50
50
  function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col_ed, canvas) {
51
- 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;
52
- var _7;
51
+ 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;
52
+ var _11;
53
53
  if (_lodash.default.isNil(d) || _lodash.default.isNil(attr)) {
54
54
  return;
55
55
  }
56
56
  if (attr === "ct") {
57
+ var changes = [];
57
58
  for (var r = row_st; r <= row_ed; r += 1) {
58
59
  if (!_lodash.default.isNil(ctx.config.rowhidden) && !_lodash.default.isNil(ctx.config.rowhidden[r])) {
59
60
  continue;
@@ -105,6 +106,20 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
105
106
  m: mask
106
107
  };
107
108
  }
109
+ changes.push({
110
+ sheetId: ctx.currentSheetId,
111
+ path: ["celldata"],
112
+ value: {
113
+ r: r,
114
+ c: c,
115
+ v: d[r][c]
116
+ },
117
+ key: "".concat(r, "_").concat(c),
118
+ type: "update"
119
+ });
120
+ }
121
+ if ((_x = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _x === void 0 ? void 0 : _x.updateCellYdoc) {
122
+ (_y = ctx.hooks) === null || _y === void 0 ? void 0 : _y.updateCellYdoc(changes);
108
123
  }
109
124
  }
110
125
  } else {
@@ -151,6 +166,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
151
166
  if (sheetIndex == null) {
152
167
  return;
153
168
  }
169
+ var changes = [];
154
170
  for (var r = row_st; r <= row_ed; r += 1) {
155
171
  if (!_lodash.default.isNil(ctx.config.rowhidden) && !_lodash.default.isNil(ctx.config.rowhidden[r])) {
156
172
  continue;
@@ -160,11 +176,11 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
160
176
  if (value && _lodash.default.isPlainObject(value)) {
161
177
  (0, _inlineString.updateInlineStringFormatOutside)(value, attr, foucsStatus);
162
178
  value[attr] = foucsStatus;
163
- (_7 = ctx.luckysheetfile[sheetIndex]).config || (_7.config = {});
179
+ (_11 = ctx.luckysheetfile[sheetIndex]).config || (_11.config = {});
164
180
  var cfg = ctx.luckysheetfile[sheetIndex].config;
165
- var cellWidth = ((_x = cfg.columnlen) === null || _x === void 0 ? void 0 : _x[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
181
+ var cellWidth = ((_z = cfg.columnlen) === null || _z === void 0 ? void 0 : _z[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
166
182
  if (attr === "tb" && canvas && foucsStatus === "2") {
167
- var currentColWidth_1 = ((_y = cfg.columnlen) === null || _y === void 0 ? void 0 : _y[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
183
+ var currentColWidth_1 = ((_0 = cfg.columnlen) === null || _0 === void 0 ? void 0 : _0[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
168
184
  var lineCount_1 = 1;
169
185
  var fontString_1 = "10px Arial";
170
186
  if (value.fs) {
@@ -177,9 +193,9 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
177
193
  lineCount_1 = (0, _utils.getLineCount)(value.m, currentColWidth_1, fontString_1);
178
194
  var hOffset = lineCount_1 < 4 ? 1.9 : 1.7;
179
195
  lineCount_1 = lineCount_1 * hOffset + 1;
180
- } 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) {
196
+ } 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) {
181
197
  lineCount_1 -= 1;
182
- 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");
198
+ 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");
183
199
  line.forEach(function (item) {
184
200
  var subLineCount = (0, _utils.getLineCount)(item, currentColWidth_1, fontString_1);
185
201
  lineCount_1 += subLineCount;
@@ -199,7 +215,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
199
215
  });
200
216
  if (!textInfo) return "continue";
201
217
  var rowHeight = _lodash.default.round(textInfo.textHeightAll);
202
- var currentRowHeight = ((_5 = cfg.rowlen) === null || _5 === void 0 ? void 0 : _5[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
218
+ var currentRowHeight = ((_7 = cfg.rowlen) === null || _7 === void 0 ? void 0 : _7[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
203
219
  if (!_lodash.default.isUndefined(rowHeight) && rowHeight > currentRowHeight && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
204
220
  if (_lodash.default.isUndefined(cfg.rowlen)) cfg.rowlen = {};
205
221
  _lodash.default.set(cfg, "rowlen.".concat(r), rowHeight);
@@ -214,7 +230,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
214
230
  });
215
231
  if (!textInfo) return "continue";
216
232
  var newHeight = _lodash.default.round(textInfo.textHeightAll);
217
- var oldHeight = ((_6 = cfg.rowlen) === null || _6 === void 0 ? void 0 : _6[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
233
+ var oldHeight = ((_8 = cfg.rowlen) === null || _8 === void 0 ? void 0 : _8[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
218
234
  var shouldResize = foucsStatus === "2" ? newHeight > oldHeight : true;
219
235
  if (shouldResize && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
220
236
  var padding = 12;
@@ -229,11 +245,25 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
229
245
  };
230
246
  d[r][c][attr] = foucsStatus;
231
247
  }
248
+ changes.push({
249
+ sheetId: ctx.currentSheetId,
250
+ path: ["celldata"],
251
+ value: {
252
+ r: r,
253
+ c: c,
254
+ v: d[r][c]
255
+ },
256
+ key: "".concat(r, "_").concat(c),
257
+ type: "update"
258
+ });
232
259
  };
233
260
  for (var c = col_st; c <= col_ed; c += 1) {
234
261
  _loop_1(c);
235
262
  }
236
263
  }
264
+ if ((_9 = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _9 === void 0 ? void 0 : _9.updateCellYdoc) {
265
+ (_10 = ctx.hooks) === null || _10 === void 0 ? void 0 : _10.updateCellYdoc(changes);
266
+ }
237
267
  }
238
268
  }
239
269
  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.2.99-data-validation-fix-1",
3
+ "version": "1.2.99-ydoc-1",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",