@fileverse-dev/fortune-core 1.3.10-yjs → 1.3.10-yjs-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -203,19 +203,19 @@ var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
203
203
  cell.f = f;
204
204
  cell.m = v.toString();
205
205
  x[c] = cell;
206
+ changes.push({
207
+ sheetId: ctx.currentSheetId,
208
+ path: ["celldata"],
209
+ value: {
210
+ r: r,
211
+ c: c,
212
+ v: d[r][c]
213
+ },
214
+ key: "".concat(r, "_").concat(c),
215
+ type: "update"
216
+ });
206
217
  }
207
218
  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
- });
219
219
  }
220
220
  }
221
221
  if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
@@ -349,7 +349,9 @@ function pasteHandler(ctx, data, borderInfo) {
349
349
  ctx.luckysheetfile[getSheetIndex(ctx, ctx.currentSheetId)].config = cfg;
350
350
  }
351
351
  jfrefreshgrid(ctx, null, undefined);
352
- handleFormulaOnPaste(ctx, d);
352
+ if (data.includes("=")) {
353
+ handleFormulaOnPaste(ctx, d);
354
+ }
353
355
  } else {
354
356
  data = data.replace(/\r/g, "");
355
357
  var dataChe = [];
@@ -479,17 +481,17 @@ function pasteHandler(ctx, data, borderInfo) {
479
481
  }
480
482
  x[c + curC] = cell;
481
483
  }
482
- changes.push(changes.push({
484
+ changes.push({
483
485
  sheetId: ctx.currentSheetId,
484
486
  path: ["celldata"],
485
487
  value: {
486
- r: r,
487
- c: c,
488
- v: d[r][c]
488
+ r: r + curR,
489
+ c: c + curC,
490
+ v: d[r + curR][c + curC]
489
491
  },
490
- key: "".concat(r, "_").concat(c),
492
+ key: "".concat(r + curR, "_").concat(c + curC),
491
493
  type: "update"
492
- }));
494
+ });
493
495
  }
494
496
  d[r + curR] = x;
495
497
  }
@@ -499,7 +501,9 @@ function pasteHandler(ctx, data, borderInfo) {
499
501
  last.row = [curR, curR + rlen - 1];
500
502
  last.column = [curC, curC + clen - 1];
501
503
  jfrefreshgrid(ctx, null, undefined);
502
- handleFormulaOnPaste(ctx, d);
504
+ if (data.includes("=")) {
505
+ handleFormulaOnPaste(ctx, d);
506
+ }
503
507
  }
504
508
  }
505
509
  function setCellHyperlink(ctx, id, r, c, link) {
@@ -510,7 +514,7 @@ function setCellHyperlink(ctx, id, r, c, link) {
510
514
  ctx.luckysheetfile[index].hyperlink["".concat(r, "_").concat(c)] = link;
511
515
  }
512
516
  function pasteHandlerOfCutPaste(ctx, copyRange) {
513
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
517
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
514
518
  var allowEdit = isAllowEdit(ctx);
515
519
  if (!allowEdit || ctx.isFlvReadOnly) return;
516
520
  if (!copyRange) return;
@@ -553,6 +557,7 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
553
557
  if (addr > 0 || addc > 0) {
554
558
  expandRowsAndColumns(d, addr, addc);
555
559
  }
560
+ var changes = [];
556
561
  var borderInfoCompute = getBorderInfoCompute(ctx, copySheetId);
557
562
  var c_dataVerification = _.cloneDeep(ctx.luckysheetfile[getSheetIndex(ctx, copySheetId)].dataVerification) || {};
558
563
  var dataVerification = _.cloneDeep(ctx.luckysheetfile[getSheetIndex(ctx, ctx.currentSheetId)].dataVerification) || {};
@@ -584,6 +589,17 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
584
589
  delete cell.mc;
585
590
  }
586
591
  d[i][j] = null;
592
+ changes.push({
593
+ sheetId: ctx.currentSheetId,
594
+ path: ["celldata"],
595
+ value: {
596
+ r: i,
597
+ c: j,
598
+ v: null
599
+ },
600
+ key: "".concat(i, "_").concat(j),
601
+ type: "update"
602
+ });
587
603
  delete dataVerification["".concat(i, "_").concat(j)];
588
604
  (_f = ctx.luckysheetfile[getSheetIndex(ctx, ctx.currentSheetId)].hyperlink) === null || _f === void 0 ? true : delete _f["".concat(i, "_").concat(j)];
589
605
  }
@@ -683,6 +699,17 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
683
699
  value = copyData[h - minh][c - minc];
684
700
  }
685
701
  x[c] = _.cloneDeep(value);
702
+ changes.push({
703
+ sheetId: ctx.currentSheetId,
704
+ path: ["celldata"],
705
+ value: {
706
+ r: h,
707
+ c: c,
708
+ v: d[h][c]
709
+ },
710
+ key: "".concat(h, "_").concat(c),
711
+ type: "update"
712
+ });
686
713
  if (value != null && copyHasMC && ((_k = x[c]) === null || _k === void 0 ? void 0 : _k.mc)) {
687
714
  if (x[c].mc.rs != null) {
688
715
  x[c].mc.r = h;
@@ -703,6 +730,9 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
703
730
  }
704
731
  last.row = [minh, maxh];
705
732
  last.column = [minc, maxc];
733
+ if (changes.length > 0 && ((_l = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _l === void 0 ? void 0 : _l.updateCellYdoc)) {
734
+ ctx.hooks.updateCellYdoc(changes);
735
+ }
706
736
  if (copyRowlChange) {}
707
737
  var source;
708
738
  var target;
@@ -785,7 +815,7 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
785
815
  }
786
816
  source_curCdformat[i].cellrange = emptyRange;
787
817
  if (emptyRange2.length > 0) {
788
- var ruleObj = (_l = source_curCdformat[i]) !== null && _l !== void 0 ? _l : {};
818
+ var ruleObj = (_m = source_curCdformat[i]) !== null && _m !== void 0 ? _m : {};
789
819
  ruleObj.cellrange = emptyRange2;
790
820
  ruleArr.push(ruleObj);
791
821
  }
@@ -889,7 +919,7 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
889
919
  }
890
920
  }
891
921
  function pasteHandlerOfCopyPaste(ctx, copyRange) {
892
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
922
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
893
923
  var allowEdit = isAllowEdit(ctx);
894
924
  if (!allowEdit || ctx.isFlvReadOnly) return;
895
925
  if (!copyRange) return;
@@ -980,6 +1010,7 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
980
1010
  if (addr > 0 || addc > 0) {
981
1011
  expandRowsAndColumns(d, addr, addc);
982
1012
  }
1013
+ var changes = [];
983
1014
  var borderInfoCompute = getBorderInfoCompute(ctx, copySheetIndex);
984
1015
  var c_dataVerification = _.cloneDeep(ctx.luckysheetfile[getSheetIndex(ctx, copySheetIndex)].dataVerification) || {};
985
1016
  var dataVerification = null;
@@ -1141,6 +1172,17 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
1141
1172
  };
1142
1173
  }
1143
1174
  }
1175
+ changes.push({
1176
+ sheetId: ctx.currentSheetId,
1177
+ path: ["celldata"],
1178
+ value: {
1179
+ r: h,
1180
+ c: c,
1181
+ v: d[h][c]
1182
+ },
1183
+ key: "".concat(h, "_").concat(c),
1184
+ type: "update"
1185
+ });
1144
1186
  }
1145
1187
  d[h] = x;
1146
1188
  }
@@ -1248,6 +1290,9 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
1248
1290
  }
1249
1291
  }
1250
1292
  }
1293
+ if (changes.length > 0 && ((_s = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _s === void 0 ? void 0 : _s.updateCellYdoc)) {
1294
+ ctx.hooks.updateCellYdoc(changes);
1295
+ }
1251
1296
  if (copyRowlChange || addr > 0 || addc > 0) {
1252
1297
  jfrefreshgrid(ctx, d, ctx.luckysheet_select_save);
1253
1298
  } else {
@@ -110,12 +110,13 @@ export function getCellValue(r, c, data, attr) {
110
110
  return retv;
111
111
  }
112
112
  export function setCellValue(ctx, r, c, d, v) {
113
- var _a, _b, _c, _d, _e, _f, _g;
113
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
114
114
  if (ctx.allowEdit === false || ctx.isFlvReadOnly) return;
115
115
  if (_.isNil(d)) {
116
116
  d = getFlowdata(ctx);
117
117
  }
118
118
  if (!d) return;
119
+ var oldValue = _.cloneDeep(d[r][c]);
119
120
  var cell = d[r][c];
120
121
  var vupdate;
121
122
  if (_.isPlainObject(v)) {
@@ -163,6 +164,9 @@ export function setCellValue(ctx, r, c, d, v) {
163
164
  cell = null;
164
165
  }
165
166
  d[r][c] = cell;
167
+ if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.afterUpdateCell) {
168
+ ctx.hooks.afterUpdateCell(r, c, oldValue, (_b = d[r][c]) !== null && _b !== void 0 ? _b : null);
169
+ }
166
170
  return;
167
171
  }
168
172
  if (isRealNull(cell) || (_.isString(cell) || _.isNumber(cell)) && cell === v) {
@@ -185,21 +189,21 @@ export function setCellValue(ctx, r, c, d, v) {
185
189
  t: "s"
186
190
  };
187
191
  cell.v = vupdateStr;
188
- } else if (vupdateStr.toUpperCase() === "TRUE" && (_.isNil((_a = cell.ct) === null || _a === void 0 ? void 0 : _a.fa) || ((_b = cell.ct) === null || _b === void 0 ? void 0 : _b.fa) !== "@")) {
192
+ } else if (vupdateStr.toUpperCase() === "TRUE" && (_.isNil((_c = cell.ct) === null || _c === void 0 ? void 0 : _c.fa) || ((_d = cell.ct) === null || _d === void 0 ? void 0 : _d.fa) !== "@")) {
189
193
  cell.m = "TRUE";
190
194
  cell.ct = {
191
195
  fa: "General",
192
196
  t: "b"
193
197
  };
194
198
  cell.v = true;
195
- } else if (vupdateStr.toUpperCase() === "FALSE" && (_.isNil((_c = cell.ct) === null || _c === void 0 ? void 0 : _c.fa) || ((_d = cell.ct) === null || _d === void 0 ? void 0 : _d.fa) !== "@")) {
199
+ } else if (vupdateStr.toUpperCase() === "FALSE" && (_.isNil((_e = cell.ct) === null || _e === void 0 ? void 0 : _e.fa) || ((_f = cell.ct) === null || _f === void 0 ? void 0 : _f.fa) !== "@")) {
196
200
  cell.m = "FALSE";
197
201
  cell.ct = {
198
202
  fa: "General",
199
203
  t: "b"
200
204
  };
201
205
  cell.v = false;
202
- } else if (vupdateStr.substr(-1) === "%" && isRealNum(vupdateStr.substring(0, vupdateStr.length - 1)) && (_.isNil((_e = cell.ct) === null || _e === void 0 ? void 0 : _e.fa) || ((_f = cell.ct) === null || _f === void 0 ? void 0 : _f.fa) !== "@")) {
206
+ } else if (vupdateStr.substr(-1) === "%" && isRealNum(vupdateStr.substring(0, vupdateStr.length - 1)) && (_.isNil((_g = cell.ct) === null || _g === void 0 ? void 0 : _g.fa) || ((_h = cell.ct) === null || _h === void 0 ? void 0 : _h.fa) !== "@")) {
203
207
  cell.ct = {
204
208
  fa: "0%",
205
209
  t: "n"
@@ -229,7 +233,7 @@ export function setCellValue(ctx, r, c, d, v) {
229
233
  var isDigit = /^\d+$/.test(vupdate);
230
234
  if (isDigit) {
231
235
  var flowdata = getFlowdata(ctx);
232
- var args = (_g = getContentInParentheses(cell === null || cell === void 0 ? void 0 : cell.f)) === null || _g === void 0 ? void 0 : _g.split(",");
236
+ var args = (_j = getContentInParentheses(cell === null || cell === void 0 ? void 0 : cell.f)) === null || _j === void 0 ? void 0 : _j.split(",");
233
237
  var cellRefs = args === null || args === void 0 ? void 0 : args.map(function (arg) {
234
238
  return arg.trim().toUpperCase();
235
239
  });
@@ -352,6 +356,9 @@ export function setCellValue(ctx, r, c, d, v) {
352
356
  }
353
357
  }
354
358
  d[r][c] = cell;
359
+ if ((_k = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _k === void 0 ? void 0 : _k.afterUpdateCell) {
360
+ ctx.hooks.afterUpdateCell(r, c, oldValue, (_l = d[r][c]) !== null && _l !== void 0 ? _l : null);
361
+ }
355
362
  if (ctx.luckysheet_selection_range) {
356
363
  ctx.luckysheet_selection_range = [];
357
364
  }
@@ -809,7 +816,7 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
809
816
  var newValue_1 = _.cloneDeep(d[r][c]);
810
817
  setTimeout(function () {
811
818
  var _a, _b;
812
- return (_b = (_a = ctx.hooks).afterUpdateCell) === null || _b === void 0 ? void 0 : _b.call(_a, r, c, null, newValue_1);
819
+ return (_b = (_a = ctx.hooks).afterUpdateCell) === null || _b === void 0 ? void 0 : _b.call(_a, r, c, oldValue_1, newValue_1);
813
820
  });
814
821
  }
815
822
  ctx.formulaCache.execFunctionGlobalData = null;
@@ -859,13 +866,6 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
859
866
  }
860
867
  }
861
868
  }
862
- if (ctx.hooks.afterUpdateCell) {
863
- var newValue_2 = _.cloneDeep(flowdata[r][c]);
864
- var afterUpdateCell_1 = ctx.hooks.afterUpdateCell;
865
- setTimeout(function () {
866
- afterUpdateCell_1 === null || afterUpdateCell_1 === void 0 ? void 0 : afterUpdateCell_1(r, c, oldValue_1, newValue_2);
867
- });
868
- }
869
869
  ctx.formulaCache.execFunctionGlobalData = null;
870
870
  } catch (e) {
871
871
  console.error(e);
@@ -163,7 +163,7 @@ export function setEditingComment(ctx, flowdata, r, c) {
163
163
  ctx.editingCommentBox = getCommentBoxByRC(ctx, flowdata, r, c);
164
164
  }
165
165
  export function removeEditingComment(ctx, globalCache) {
166
- var _a, _b;
166
+ var _a, _b, _c;
167
167
  var editingCommentBoxEle = globalCache.editingCommentBoxEle;
168
168
  ctx.editingCommentBox = undefined;
169
169
  var r = editingCommentBoxEle === null || editingCommentBoxEle === void 0 ? void 0 : editingCommentBoxEle.dataset.r;
@@ -187,6 +187,19 @@ export function removeEditingComment(ctx, globalCache) {
187
187
  return v.rc !== "".concat(r, "_").concat(c);
188
188
  });
189
189
  }
190
+ if ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc) {
191
+ ctx.hooks.updateCellYdoc([{
192
+ sheetId: ctx.currentSheetId,
193
+ path: ["celldata"],
194
+ value: {
195
+ r: r,
196
+ c: c,
197
+ v: cell
198
+ },
199
+ key: "".concat(r, "_").concat(c),
200
+ type: "update"
201
+ }]);
202
+ }
190
203
  if (ctx.hooks.afterUpdateComment) {
191
204
  setTimeout(function () {
192
205
  var _a, _b;
@@ -195,7 +208,7 @@ export function removeEditingComment(ctx, globalCache) {
195
208
  }
196
209
  }
197
210
  export function newComment(ctx, globalCache, r, c) {
198
- var _a, _b;
211
+ var _a, _b, _c, _d;
199
212
  if (((_b = (_a = ctx.hooks).beforeInsertComment) === null || _b === void 0 ? void 0 : _b.call(_a, r, c)) === false) {
200
213
  return;
201
214
  }
@@ -220,6 +233,19 @@ export function newComment(ctx, globalCache, r, c) {
220
233
  ctx.editingCommentBox = __assign(__assign({}, getCommentBoxByRC(ctx, flowdata, r, c)), {
221
234
  autoFocus: true
222
235
  });
236
+ if ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc) {
237
+ ctx.hooks.updateCellYdoc([{
238
+ sheetId: ctx.currentSheetId,
239
+ path: ["celldata"],
240
+ value: {
241
+ r: r,
242
+ c: c,
243
+ v: (_d = flowdata[r][c]) !== null && _d !== void 0 ? _d : null
244
+ },
245
+ key: "".concat(r, "_").concat(c),
246
+ type: "update"
247
+ }]);
248
+ }
223
249
  if (ctx.hooks.afterInsertComment) {
224
250
  setTimeout(function () {
225
251
  var _a, _b;
@@ -246,7 +272,7 @@ export function editComment(ctx, globalCache, r, c) {
246
272
  }
247
273
  }
248
274
  export function deleteComment(ctx, globalCache, r, c) {
249
- var _a, _b;
275
+ var _a, _b, _c;
250
276
  var allowEdit = isAllowEdit(ctx);
251
277
  if (!allowEdit) return;
252
278
  if (((_b = (_a = ctx.hooks).beforeDeleteComment) === null || _b === void 0 ? void 0 : _b.call(_a, r, c)) === false) {
@@ -257,6 +283,19 @@ export function deleteComment(ctx, globalCache, r, c) {
257
283
  var cell = flowdata[r][c];
258
284
  if (!cell) return;
259
285
  cell.ps = undefined;
286
+ if ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc) {
287
+ ctx.hooks.updateCellYdoc([{
288
+ sheetId: ctx.currentSheetId,
289
+ path: ["celldata"],
290
+ value: {
291
+ r: r,
292
+ c: c,
293
+ v: cell
294
+ },
295
+ key: "".concat(r, "_").concat(c),
296
+ type: "update"
297
+ }]);
298
+ }
260
299
  if (ctx.hooks.afterDeleteComment) {
261
300
  setTimeout(function () {
262
301
  var _a, _b;
@@ -276,7 +315,7 @@ export function showComments(ctx, commentShowCells) {
276
315
  }
277
316
  }
278
317
  export function showHideComment(ctx, globalCache, r, c) {
279
- var _a;
318
+ var _a, _b, _c;
280
319
  var flowdata = getFlowdata(ctx);
281
320
  var comment = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[r][c]) === null || _a === void 0 ? void 0 : _a.ps;
282
321
  if (!comment) return;
@@ -290,9 +329,23 @@ export function showHideComment(ctx, globalCache, r, c) {
290
329
  } else {
291
330
  comment.isShow = true;
292
331
  }
332
+ var cell = (_b = flowdata === null || flowdata === void 0 ? void 0 : flowdata[r]) === null || _b === void 0 ? void 0 : _b[c];
333
+ if (cell && ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc)) {
334
+ ctx.hooks.updateCellYdoc([{
335
+ sheetId: ctx.currentSheetId,
336
+ path: ["celldata"],
337
+ value: {
338
+ r: r,
339
+ c: c,
340
+ v: cell
341
+ },
342
+ key: "".concat(r, "_").concat(c),
343
+ type: "update"
344
+ }]);
345
+ }
293
346
  }
294
347
  export function showHideAllComments(ctx) {
295
- var _a, _b;
348
+ var _a, _b, _c, _d, _e;
296
349
  var flowdata = getFlowdata(ctx);
297
350
  if (!flowdata) return;
298
351
  var isAllShow = true;
@@ -313,29 +366,55 @@ export function showHideAllComments(ctx) {
313
366
  }
314
367
  var rcs = [];
315
368
  if (allComments.length > 0) {
369
+ var cellChanges = [];
316
370
  if (isAllShow) {
317
371
  for (var i = 0; i < allComments.length; i += 1) {
318
- var _c = allComments[i],
319
- r = _c.r,
320
- c = _c.c;
372
+ var _f = allComments[i],
373
+ r = _f.r,
374
+ c = _f.c;
321
375
  var comment = (_a = flowdata[r][c]) === null || _a === void 0 ? void 0 : _a.ps;
322
376
  if (comment === null || comment === void 0 ? void 0 : comment.isShow) {
323
377
  comment.isShow = false;
324
378
  rcs.push("".concat(r, "_").concat(c));
379
+ cellChanges.push({
380
+ sheetId: ctx.currentSheetId,
381
+ path: ["celldata"],
382
+ value: {
383
+ r: r,
384
+ c: c,
385
+ v: (_b = flowdata[r][c]) !== null && _b !== void 0 ? _b : null
386
+ },
387
+ key: "".concat(r, "_").concat(c),
388
+ type: "update"
389
+ });
325
390
  }
326
391
  }
327
392
  ctx.commentBoxes = [];
328
393
  } else {
329
394
  for (var i = 0; i < allComments.length; i += 1) {
330
- var _d = allComments[i],
331
- r = _d.r,
332
- c = _d.c;
333
- var comment = (_b = flowdata[r][c]) === null || _b === void 0 ? void 0 : _b.ps;
395
+ var _g = allComments[i],
396
+ r = _g.r,
397
+ c = _g.c;
398
+ var comment = (_c = flowdata[r][c]) === null || _c === void 0 ? void 0 : _c.ps;
334
399
  if (comment && !comment.isShow) {
335
400
  comment.isShow = true;
401
+ cellChanges.push({
402
+ sheetId: ctx.currentSheetId,
403
+ path: ["celldata"],
404
+ value: {
405
+ r: r,
406
+ c: c,
407
+ v: (_d = flowdata[r][c]) !== null && _d !== void 0 ? _d : null
408
+ },
409
+ key: "".concat(r, "_").concat(c),
410
+ type: "update"
411
+ });
336
412
  }
337
413
  }
338
414
  }
415
+ if (cellChanges.length > 0 && ((_e = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _e === void 0 ? void 0 : _e.updateCellYdoc)) {
416
+ ctx.hooks.updateCellYdoc(cellChanges);
417
+ }
339
418
  }
340
419
  }
341
420
  export function removeOverShowComment(ctx) {
@@ -497,13 +576,13 @@ export function onCommentBoxResize(ctx, globalCache, e) {
497
576
  return false;
498
577
  }
499
578
  export function onCommentBoxResizeEnd(ctx, globalCache) {
500
- var _a;
579
+ var _a, _b;
501
580
  if ((_a = globalCache.commentBox) === null || _a === void 0 ? void 0 : _a.resizingId) {
502
- var _b = globalCache.commentBox,
503
- resizingId = _b.resizingId,
504
- _c = _b.commentRC,
505
- r = _c.r,
506
- c = _c.c;
581
+ var _c = globalCache.commentBox,
582
+ resizingId = _c.resizingId,
583
+ _d = _c.commentRC,
584
+ r = _d.r,
585
+ c = _d.c;
507
586
  globalCache.commentBox.resizingId = undefined;
508
587
  var position = getCommentBoxPosition(resizingId);
509
588
  if (position) {
@@ -519,6 +598,19 @@ export function onCommentBoxResizeEnd(ctx, globalCache) {
519
598
  cell.ps.width = width / ctx.zoomRatio;
520
599
  cell.ps.height = height / ctx.zoomRatio;
521
600
  setEditingComment(ctx, flowdata, r, c);
601
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
602
+ ctx.hooks.updateCellYdoc([{
603
+ sheetId: ctx.currentSheetId,
604
+ path: ["celldata"],
605
+ value: {
606
+ r: r,
607
+ c: c,
608
+ v: cell
609
+ },
610
+ key: "".concat(r, "_").concat(c),
611
+ type: "update"
612
+ }]);
613
+ }
522
614
  }
523
615
  }
524
616
  }
@@ -570,13 +662,13 @@ export function onCommentBoxMove(ctx, globalCache, e) {
570
662
  return false;
571
663
  }
572
664
  export function onCommentBoxMoveEnd(ctx, globalCache) {
573
- var _a;
665
+ var _a, _b;
574
666
  if ((_a = globalCache.commentBox) === null || _a === void 0 ? void 0 : _a.movingId) {
575
- var _b = globalCache.commentBox,
576
- movingId = _b.movingId,
577
- _c = _b.commentRC,
578
- r = _c.r,
579
- c = _c.c;
667
+ var _c = globalCache.commentBox,
668
+ movingId = _c.movingId,
669
+ _d = _c.commentRC,
670
+ r = _d.r,
671
+ c = _d.c;
580
672
  globalCache.commentBox.movingId = undefined;
581
673
  var position = getCommentBoxPosition(movingId);
582
674
  if (position) {
@@ -588,6 +680,19 @@ export function onCommentBoxMoveEnd(ctx, globalCache) {
588
680
  cell.ps.left = left / ctx.zoomRatio;
589
681
  cell.ps.top = top_5 / ctx.zoomRatio;
590
682
  setEditingComment(ctx, flowdata, r, c);
683
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
684
+ ctx.hooks.updateCellYdoc([{
685
+ sheetId: ctx.currentSheetId,
686
+ path: ["celldata"],
687
+ value: {
688
+ r: r,
689
+ c: c,
690
+ v: cell
691
+ },
692
+ key: "".concat(r, "_").concat(c),
693
+ type: "update"
694
+ }]);
695
+ }
591
696
  }
592
697
  }
593
698
  }
@@ -54,8 +54,63 @@ var refreshLocalMergeData = function refreshLocalMergeData(merge_new, file) {
54
54
  }
55
55
  });
56
56
  };
57
+ var getMergeBounds = function getMergeBounds(mergeMap) {
58
+ if (!mergeMap) return null;
59
+ var minR = Infinity;
60
+ var minC = Infinity;
61
+ var maxR = -Infinity;
62
+ var maxC = -Infinity;
63
+ Object.values(mergeMap).forEach(function (mc) {
64
+ var _a, _b;
65
+ if (!mc) return;
66
+ var r = Number(mc.r);
67
+ var c = Number(mc.c);
68
+ var rs = Number((_a = mc.rs) !== null && _a !== void 0 ? _a : 1);
69
+ var cs = Number((_b = mc.cs) !== null && _b !== void 0 ? _b : 1);
70
+ if (!Number.isFinite(r) || !Number.isFinite(c)) return;
71
+ minR = Math.min(minR, r);
72
+ minC = Math.min(minC, c);
73
+ maxR = Math.max(maxR, r + Math.max(1, rs) - 1);
74
+ maxC = Math.max(maxC, c + Math.max(1, cs) - 1);
75
+ });
76
+ if (minR === Infinity) return null;
77
+ return {
78
+ minR: minR,
79
+ minC: minC,
80
+ maxR: maxR,
81
+ maxC: maxC
82
+ };
83
+ };
84
+ var emitCellRangeToYdoc = function emitCellRangeToYdoc(ctx, sheetId, d, r1, r2, c1, c2) {
85
+ var _a, _b, _c, _d;
86
+ if (!((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc)) return;
87
+ if (!d || !Array.isArray(d) || d.length === 0) return;
88
+ var rowEnd = Math.min(r2, d.length - 1);
89
+ var colEnd = Math.min(c2, ((_c = (_b = d[0]) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) - 1);
90
+ var rowStart = Math.max(0, r1);
91
+ var colStart = Math.max(0, c1);
92
+ if (rowStart > rowEnd || colStart > colEnd) return;
93
+ var changes = [];
94
+ for (var r = rowStart; r <= rowEnd; r += 1) {
95
+ var row = d[r] || [];
96
+ for (var c = colStart; c <= colEnd; c += 1) {
97
+ changes.push({
98
+ sheetId: sheetId,
99
+ path: ["celldata"],
100
+ value: {
101
+ r: r,
102
+ c: c,
103
+ v: (_d = row === null || row === void 0 ? void 0 : row[c]) !== null && _d !== void 0 ? _d : null
104
+ },
105
+ key: "".concat(r, "_").concat(c),
106
+ type: "update"
107
+ });
108
+ }
109
+ }
110
+ if (changes.length > 0) ctx.hooks.updateCellYdoc(changes);
111
+ };
57
112
  export function insertRowCol(ctx, op, changeSelection) {
58
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
113
+ 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;
59
114
  if (changeSelection === void 0) {
60
115
  changeSelection = true;
61
116
  }
@@ -1020,9 +1075,22 @@ export function insertRowCol(ctx, op, changeSelection) {
1020
1075
  }
1021
1076
  }
1022
1077
  refreshLocalMergeData(merge_new, file);
1078
+ var mergeBounds = getMergeBounds(cfg.merge);
1079
+ if (type === "row") {
1080
+ var baseStart = direction === "lefttop" ? index : index + 1;
1081
+ var startR = mergeBounds ? Math.min(baseStart, mergeBounds.minR) : baseStart;
1082
+ emitCellRangeToYdoc(ctx, id, d, startR, d.length - 1, 0, ((_y = (_x = d[0]) === null || _x === void 0 ? void 0 : _x.length) !== null && _y !== void 0 ? _y : 1) - 1);
1083
+ } else {
1084
+ var baseStart = direction === "lefttop" ? index : index + 1;
1085
+ var startC = mergeBounds ? Math.min(baseStart, mergeBounds.minC) : baseStart;
1086
+ emitCellRangeToYdoc(ctx, id, d, 0, d.length - 1, startC, ((_0 = (_z = d[0]) === null || _z === void 0 ? void 0 : _z.length) !== null && _0 !== void 0 ? _0 : 1) - 1);
1087
+ }
1088
+ if ((_1 = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _1 === void 0 ? void 0 : _1.updateAllCell) {
1089
+ ctx.hooks.updateAllCell(id);
1090
+ }
1023
1091
  }
1024
1092
  export function deleteRowCol(ctx, op) {
1025
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
1093
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
1026
1094
  var type = op.type;
1027
1095
  var start = op.start,
1028
1096
  end = op.end,
@@ -1742,6 +1810,17 @@ export function deleteRowCol(ctx, op) {
1742
1810
  file.dataVerification = newDataVerification;
1743
1811
  file.hyperlink = newHyperlink;
1744
1812
  refreshLocalMergeData(merge_new, file);
1813
+ var mergeBounds = getMergeBounds(cfg.merge);
1814
+ if (type === "row") {
1815
+ var startR = mergeBounds ? Math.min(start, mergeBounds.minR) : start;
1816
+ emitCellRangeToYdoc(ctx, id, d, startR, d.length - 1, 0, ((_s = (_r = d[0]) === null || _r === void 0 ? void 0 : _r.length) !== null && _s !== void 0 ? _s : 1) - 1);
1817
+ } else {
1818
+ var startC = mergeBounds ? Math.min(start, mergeBounds.minC) : start;
1819
+ emitCellRangeToYdoc(ctx, id, d, 0, d.length - 1, startC, ((_u = (_t = d[0]) === null || _t === void 0 ? void 0 : _t.length) !== null && _u !== void 0 ? _u : 1) - 1);
1820
+ }
1821
+ if ((_v = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _v === void 0 ? void 0 : _v.updateAllCell) {
1822
+ ctx.hooks.updateAllCell(id);
1823
+ }
1745
1824
  if (file.id === ctx.currentSheetId) {
1746
1825
  ctx.config = cfg;
1747
1826
  } else {}