@fileverse-dev/fortune-core 1.3.10-yjs-1 → 1.3.10-yjs-3

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.
@@ -143,32 +143,53 @@ export function sortSelection(ctx, isAsc, colIndex) {
143
143
  sortDataRange(ctx, d, data, colIndex, isAsc, str, edr, c1, c2);
144
144
  }
145
145
  function createRowsOrColumnsForSpilledValues(ctx, startRow, startColumn, spillRows, spillCols) {
146
+ var _a, _b;
146
147
  var flowdata = getFlowdata(ctx);
147
148
  if (!flowdata) return;
149
+ var cellChanges = [];
148
150
  try {
149
151
  var sheetIndex = getSheetIndex(ctx, ctx.currentSheetId);
150
152
  var sheet = ctx.luckysheetfile[sheetIndex];
151
- var requiredRowCount = startRow + spillRows;
152
- var requiredColCount = startColumn + spillCols;
153
- if (sheet.row && sheet.row < requiredRowCount) {
154
- sheet.row = requiredRowCount;
153
+ var requiredRowCount_1 = startRow + spillRows;
154
+ var requiredColCount_1 = startColumn + spillCols;
155
+ if (sheet.row && sheet.row < requiredRowCount_1) {
156
+ sheet.row = requiredRowCount_1;
155
157
  }
156
- if (sheet.column && sheet.column < requiredColCount) {
157
- sheet.column = requiredColCount;
158
+ if (sheet.column && sheet.column < requiredColCount_1) {
159
+ sheet.column = requiredColCount_1;
158
160
  }
159
161
  } catch (error) {
160
162
  console.error("Failed to update sheet metadata for spill operation", error);
161
163
  }
162
- while (flowdata.length < startRow + spillRows) {
164
+ var requiredRowCount = startRow + spillRows;
165
+ var requiredColCount = startColumn + spillCols;
166
+ while (flowdata.length < requiredRowCount) {
163
167
  flowdata.push([]);
164
168
  }
165
- for (var rowIndex = startRow; rowIndex < startRow + spillRows; rowIndex++) {
169
+ for (var rowIndex = startRow; rowIndex < requiredRowCount; rowIndex++) {
166
170
  if (!Array.isArray(flowdata[rowIndex])) {
167
171
  flowdata[rowIndex] = [];
168
172
  }
169
- while (flowdata[rowIndex].length < startColumn + spillCols) {
173
+ var prevLen = flowdata[rowIndex].length;
174
+ while (flowdata[rowIndex].length < requiredColCount) {
170
175
  flowdata[rowIndex].push(null);
171
176
  }
177
+ for (var c = Math.max(prevLen, startColumn); c < requiredColCount; c += 1) {
178
+ cellChanges.push({
179
+ sheetId: ctx.currentSheetId,
180
+ path: ["celldata"],
181
+ value: {
182
+ r: rowIndex,
183
+ c: c,
184
+ v: (_a = flowdata[rowIndex][c]) !== null && _a !== void 0 ? _a : null
185
+ },
186
+ key: "".concat(rowIndex, "_").concat(c),
187
+ type: "update"
188
+ });
189
+ }
190
+ }
191
+ if (cellChanges.length > 0 && ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc)) {
192
+ ctx.hooks.updateCellYdoc(cellChanges);
172
193
  }
173
194
  }
174
195
  export function spillSortResult(ctx, startRow, startCol, formulaResult, flowdata) {
package/es/settings.d.ts CHANGED
@@ -19,6 +19,7 @@ export type Hooks = {
19
19
  cellDataChange?: () => void;
20
20
  hyperlinkChange?: () => void;
21
21
  updateCellYdoc?: (changes: SheetChangePath[]) => void;
22
+ updateAllCell?: (sheetId: string) => void;
22
23
  beforeUpdateCell?: (r: number, c: number, value: any) => boolean;
23
24
  afterUpdateCell?: (row: number, column: number, oldValue: any, newValue: any) => void;
24
25
  afterSelectionChange?: (sheetId: string, selection: Selection) => void;
@@ -216,19 +216,19 @@ var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
216
216
  cell.f = f;
217
217
  cell.m = v.toString();
218
218
  x[c] = cell;
219
+ changes.push({
220
+ sheetId: ctx.currentSheetId,
221
+ path: ["celldata"],
222
+ value: {
223
+ r: r,
224
+ c: c,
225
+ v: d[r][c]
226
+ },
227
+ key: "".concat(r, "_").concat(c),
228
+ type: "update"
229
+ });
219
230
  }
220
231
  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
- });
232
232
  }
233
233
  }
234
234
  if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
@@ -362,7 +362,9 @@ function pasteHandler(ctx, data, borderInfo) {
362
362
  ctx.luckysheetfile[(0, _utils.getSheetIndex)(ctx, ctx.currentSheetId)].config = cfg;
363
363
  }
364
364
  (0, _refresh.jfrefreshgrid)(ctx, null, undefined);
365
- handleFormulaOnPaste(ctx, d);
365
+ if (data.includes("=")) {
366
+ handleFormulaOnPaste(ctx, d);
367
+ }
366
368
  } else {
367
369
  data = data.replace(/\r/g, "");
368
370
  var dataChe = [];
@@ -492,17 +494,17 @@ function pasteHandler(ctx, data, borderInfo) {
492
494
  }
493
495
  x[c + curC] = cell;
494
496
  }
495
- changes.push(changes.push({
497
+ changes.push({
496
498
  sheetId: ctx.currentSheetId,
497
499
  path: ["celldata"],
498
500
  value: {
499
- r: r,
500
- c: c,
501
- v: d[r][c]
501
+ r: r + curR,
502
+ c: c + curC,
503
+ v: d[r + curR][c + curC]
502
504
  },
503
- key: "".concat(r, "_").concat(c),
505
+ key: "".concat(r + curR, "_").concat(c + curC),
504
506
  type: "update"
505
- }));
507
+ });
506
508
  }
507
509
  d[r + curR] = x;
508
510
  }
@@ -512,7 +514,9 @@ function pasteHandler(ctx, data, borderInfo) {
512
514
  last.row = [curR, curR + rlen - 1];
513
515
  last.column = [curC, curC + clen - 1];
514
516
  (0, _refresh.jfrefreshgrid)(ctx, null, undefined);
515
- handleFormulaOnPaste(ctx, d);
517
+ if (data.includes("=")) {
518
+ handleFormulaOnPaste(ctx, d);
519
+ }
516
520
  }
517
521
  }
518
522
  function setCellHyperlink(ctx, id, r, c, link) {
@@ -523,7 +527,7 @@ function setCellHyperlink(ctx, id, r, c, link) {
523
527
  ctx.luckysheetfile[index].hyperlink["".concat(r, "_").concat(c)] = link;
524
528
  }
525
529
  function pasteHandlerOfCutPaste(ctx, copyRange) {
526
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
530
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
527
531
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
528
532
  if (!allowEdit || ctx.isFlvReadOnly) return;
529
533
  if (!copyRange) return;
@@ -566,6 +570,7 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
566
570
  if (addr > 0 || addc > 0) {
567
571
  (0, _sheet.expandRowsAndColumns)(d, addr, addc);
568
572
  }
573
+ var changes = [];
569
574
  var borderInfoCompute = (0, _border.getBorderInfoCompute)(ctx, copySheetId);
570
575
  var c_dataVerification = _lodash.default.cloneDeep(ctx.luckysheetfile[(0, _utils.getSheetIndex)(ctx, copySheetId)].dataVerification) || {};
571
576
  var dataVerification = _lodash.default.cloneDeep(ctx.luckysheetfile[(0, _utils.getSheetIndex)(ctx, ctx.currentSheetId)].dataVerification) || {};
@@ -597,6 +602,17 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
597
602
  delete cell.mc;
598
603
  }
599
604
  d[i][j] = null;
605
+ changes.push({
606
+ sheetId: ctx.currentSheetId,
607
+ path: ["celldata"],
608
+ value: {
609
+ r: i,
610
+ c: j,
611
+ v: null
612
+ },
613
+ key: "".concat(i, "_").concat(j),
614
+ type: "update"
615
+ });
600
616
  delete dataVerification["".concat(i, "_").concat(j)];
601
617
  (_f = ctx.luckysheetfile[(0, _utils.getSheetIndex)(ctx, ctx.currentSheetId)].hyperlink) === null || _f === void 0 ? true : delete _f["".concat(i, "_").concat(j)];
602
618
  }
@@ -696,6 +712,17 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
696
712
  value = copyData[h - minh][c - minc];
697
713
  }
698
714
  x[c] = _lodash.default.cloneDeep(value);
715
+ changes.push({
716
+ sheetId: ctx.currentSheetId,
717
+ path: ["celldata"],
718
+ value: {
719
+ r: h,
720
+ c: c,
721
+ v: d[h][c]
722
+ },
723
+ key: "".concat(h, "_").concat(c),
724
+ type: "update"
725
+ });
699
726
  if (value != null && copyHasMC && ((_k = x[c]) === null || _k === void 0 ? void 0 : _k.mc)) {
700
727
  if (x[c].mc.rs != null) {
701
728
  x[c].mc.r = h;
@@ -716,6 +743,9 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
716
743
  }
717
744
  last.row = [minh, maxh];
718
745
  last.column = [minc, maxc];
746
+ if (changes.length > 0 && ((_l = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _l === void 0 ? void 0 : _l.updateCellYdoc)) {
747
+ ctx.hooks.updateCellYdoc(changes);
748
+ }
719
749
  if (copyRowlChange) {}
720
750
  var source;
721
751
  var target;
@@ -798,7 +828,7 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
798
828
  }
799
829
  source_curCdformat[i].cellrange = emptyRange;
800
830
  if (emptyRange2.length > 0) {
801
- var ruleObj = (_l = source_curCdformat[i]) !== null && _l !== void 0 ? _l : {};
831
+ var ruleObj = (_m = source_curCdformat[i]) !== null && _m !== void 0 ? _m : {};
802
832
  ruleObj.cellrange = emptyRange2;
803
833
  ruleArr.push(ruleObj);
804
834
  }
@@ -902,7 +932,7 @@ function pasteHandlerOfCutPaste(ctx, copyRange) {
902
932
  }
903
933
  }
904
934
  function pasteHandlerOfCopyPaste(ctx, copyRange) {
905
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
935
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
906
936
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
907
937
  if (!allowEdit || ctx.isFlvReadOnly) return;
908
938
  if (!copyRange) return;
@@ -993,6 +1023,7 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
993
1023
  if (addr > 0 || addc > 0) {
994
1024
  (0, _sheet.expandRowsAndColumns)(d, addr, addc);
995
1025
  }
1026
+ var changes = [];
996
1027
  var borderInfoCompute = (0, _border.getBorderInfoCompute)(ctx, copySheetIndex);
997
1028
  var c_dataVerification = _lodash.default.cloneDeep(ctx.luckysheetfile[(0, _utils.getSheetIndex)(ctx, copySheetIndex)].dataVerification) || {};
998
1029
  var dataVerification = null;
@@ -1154,6 +1185,17 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
1154
1185
  };
1155
1186
  }
1156
1187
  }
1188
+ changes.push({
1189
+ sheetId: ctx.currentSheetId,
1190
+ path: ["celldata"],
1191
+ value: {
1192
+ r: h,
1193
+ c: c,
1194
+ v: d[h][c]
1195
+ },
1196
+ key: "".concat(h, "_").concat(c),
1197
+ type: "update"
1198
+ });
1157
1199
  }
1158
1200
  d[h] = x;
1159
1201
  }
@@ -1261,6 +1303,9 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
1261
1303
  }
1262
1304
  }
1263
1305
  }
1306
+ if (changes.length > 0 && ((_s = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _s === void 0 ? void 0 : _s.updateCellYdoc)) {
1307
+ ctx.hooks.updateCellYdoc(changes);
1308
+ }
1264
1309
  if (copyRowlChange || addr > 0 || addc > 0) {
1265
1310
  (0, _refresh.jfrefreshgrid)(ctx, d, ctx.luckysheet_select_save);
1266
1311
  } else {
@@ -842,7 +842,7 @@ function updateCell(ctx, r, c, $input, value, canvas) {
842
842
  var newValue_1 = _lodash.default.cloneDeep(d[r][c]);
843
843
  setTimeout(function () {
844
844
  var _a, _b;
845
- return (_b = (_a = ctx.hooks).afterUpdateCell) === null || _b === void 0 ? void 0 : _b.call(_a, r, c, null, newValue_1);
845
+ return (_b = (_a = ctx.hooks).afterUpdateCell) === null || _b === void 0 ? void 0 : _b.call(_a, r, c, oldValue_1, newValue_1);
846
846
  });
847
847
  }
848
848
  ctx.formulaCache.execFunctionGlobalData = null;
@@ -191,7 +191,7 @@ function setEditingComment(ctx, flowdata, r, c) {
191
191
  ctx.editingCommentBox = getCommentBoxByRC(ctx, flowdata, r, c);
192
192
  }
193
193
  function removeEditingComment(ctx, globalCache) {
194
- var _a, _b;
194
+ var _a, _b, _c;
195
195
  var editingCommentBoxEle = globalCache.editingCommentBoxEle;
196
196
  ctx.editingCommentBox = undefined;
197
197
  var r = editingCommentBoxEle === null || editingCommentBoxEle === void 0 ? void 0 : editingCommentBoxEle.dataset.r;
@@ -215,6 +215,19 @@ function removeEditingComment(ctx, globalCache) {
215
215
  return v.rc !== "".concat(r, "_").concat(c);
216
216
  });
217
217
  }
218
+ if ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc) {
219
+ ctx.hooks.updateCellYdoc([{
220
+ sheetId: ctx.currentSheetId,
221
+ path: ["celldata"],
222
+ value: {
223
+ r: r,
224
+ c: c,
225
+ v: cell
226
+ },
227
+ key: "".concat(r, "_").concat(c),
228
+ type: "update"
229
+ }]);
230
+ }
218
231
  if (ctx.hooks.afterUpdateComment) {
219
232
  setTimeout(function () {
220
233
  var _a, _b;
@@ -223,7 +236,7 @@ function removeEditingComment(ctx, globalCache) {
223
236
  }
224
237
  }
225
238
  function newComment(ctx, globalCache, r, c) {
226
- var _a, _b;
239
+ var _a, _b, _c, _d;
227
240
  if (((_b = (_a = ctx.hooks).beforeInsertComment) === null || _b === void 0 ? void 0 : _b.call(_a, r, c)) === false) {
228
241
  return;
229
242
  }
@@ -248,6 +261,19 @@ function newComment(ctx, globalCache, r, c) {
248
261
  ctx.editingCommentBox = __assign(__assign({}, getCommentBoxByRC(ctx, flowdata, r, c)), {
249
262
  autoFocus: true
250
263
  });
264
+ if ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc) {
265
+ ctx.hooks.updateCellYdoc([{
266
+ sheetId: ctx.currentSheetId,
267
+ path: ["celldata"],
268
+ value: {
269
+ r: r,
270
+ c: c,
271
+ v: (_d = flowdata[r][c]) !== null && _d !== void 0 ? _d : null
272
+ },
273
+ key: "".concat(r, "_").concat(c),
274
+ type: "update"
275
+ }]);
276
+ }
251
277
  if (ctx.hooks.afterInsertComment) {
252
278
  setTimeout(function () {
253
279
  var _a, _b;
@@ -274,7 +300,7 @@ function editComment(ctx, globalCache, r, c) {
274
300
  }
275
301
  }
276
302
  function deleteComment(ctx, globalCache, r, c) {
277
- var _a, _b;
303
+ var _a, _b, _c;
278
304
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
279
305
  if (!allowEdit) return;
280
306
  if (((_b = (_a = ctx.hooks).beforeDeleteComment) === null || _b === void 0 ? void 0 : _b.call(_a, r, c)) === false) {
@@ -285,6 +311,19 @@ function deleteComment(ctx, globalCache, r, c) {
285
311
  var cell = flowdata[r][c];
286
312
  if (!cell) return;
287
313
  cell.ps = undefined;
314
+ if ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc) {
315
+ ctx.hooks.updateCellYdoc([{
316
+ sheetId: ctx.currentSheetId,
317
+ path: ["celldata"],
318
+ value: {
319
+ r: r,
320
+ c: c,
321
+ v: cell
322
+ },
323
+ key: "".concat(r, "_").concat(c),
324
+ type: "update"
325
+ }]);
326
+ }
288
327
  if (ctx.hooks.afterDeleteComment) {
289
328
  setTimeout(function () {
290
329
  var _a, _b;
@@ -304,7 +343,7 @@ function showComments(ctx, commentShowCells) {
304
343
  }
305
344
  }
306
345
  function showHideComment(ctx, globalCache, r, c) {
307
- var _a;
346
+ var _a, _b, _c;
308
347
  var flowdata = (0, _context.getFlowdata)(ctx);
309
348
  var comment = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[r][c]) === null || _a === void 0 ? void 0 : _a.ps;
310
349
  if (!comment) return;
@@ -318,9 +357,23 @@ function showHideComment(ctx, globalCache, r, c) {
318
357
  } else {
319
358
  comment.isShow = true;
320
359
  }
360
+ var cell = (_b = flowdata === null || flowdata === void 0 ? void 0 : flowdata[r]) === null || _b === void 0 ? void 0 : _b[c];
361
+ if (cell && ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc)) {
362
+ ctx.hooks.updateCellYdoc([{
363
+ sheetId: ctx.currentSheetId,
364
+ path: ["celldata"],
365
+ value: {
366
+ r: r,
367
+ c: c,
368
+ v: cell
369
+ },
370
+ key: "".concat(r, "_").concat(c),
371
+ type: "update"
372
+ }]);
373
+ }
321
374
  }
322
375
  function showHideAllComments(ctx) {
323
- var _a, _b;
376
+ var _a, _b, _c, _d, _e;
324
377
  var flowdata = (0, _context.getFlowdata)(ctx);
325
378
  if (!flowdata) return;
326
379
  var isAllShow = true;
@@ -341,29 +394,55 @@ function showHideAllComments(ctx) {
341
394
  }
342
395
  var rcs = [];
343
396
  if (allComments.length > 0) {
397
+ var cellChanges = [];
344
398
  if (isAllShow) {
345
399
  for (var i = 0; i < allComments.length; i += 1) {
346
- var _c = allComments[i],
347
- r = _c.r,
348
- c = _c.c;
400
+ var _f = allComments[i],
401
+ r = _f.r,
402
+ c = _f.c;
349
403
  var comment = (_a = flowdata[r][c]) === null || _a === void 0 ? void 0 : _a.ps;
350
404
  if (comment === null || comment === void 0 ? void 0 : comment.isShow) {
351
405
  comment.isShow = false;
352
406
  rcs.push("".concat(r, "_").concat(c));
407
+ cellChanges.push({
408
+ sheetId: ctx.currentSheetId,
409
+ path: ["celldata"],
410
+ value: {
411
+ r: r,
412
+ c: c,
413
+ v: (_b = flowdata[r][c]) !== null && _b !== void 0 ? _b : null
414
+ },
415
+ key: "".concat(r, "_").concat(c),
416
+ type: "update"
417
+ });
353
418
  }
354
419
  }
355
420
  ctx.commentBoxes = [];
356
421
  } else {
357
422
  for (var i = 0; i < allComments.length; i += 1) {
358
- var _d = allComments[i],
359
- r = _d.r,
360
- c = _d.c;
361
- var comment = (_b = flowdata[r][c]) === null || _b === void 0 ? void 0 : _b.ps;
423
+ var _g = allComments[i],
424
+ r = _g.r,
425
+ c = _g.c;
426
+ var comment = (_c = flowdata[r][c]) === null || _c === void 0 ? void 0 : _c.ps;
362
427
  if (comment && !comment.isShow) {
363
428
  comment.isShow = true;
429
+ cellChanges.push({
430
+ sheetId: ctx.currentSheetId,
431
+ path: ["celldata"],
432
+ value: {
433
+ r: r,
434
+ c: c,
435
+ v: (_d = flowdata[r][c]) !== null && _d !== void 0 ? _d : null
436
+ },
437
+ key: "".concat(r, "_").concat(c),
438
+ type: "update"
439
+ });
364
440
  }
365
441
  }
366
442
  }
443
+ if (cellChanges.length > 0 && ((_e = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _e === void 0 ? void 0 : _e.updateCellYdoc)) {
444
+ ctx.hooks.updateCellYdoc(cellChanges);
445
+ }
367
446
  }
368
447
  }
369
448
  function removeOverShowComment(ctx) {
@@ -525,13 +604,13 @@ function onCommentBoxResize(ctx, globalCache, e) {
525
604
  return false;
526
605
  }
527
606
  function onCommentBoxResizeEnd(ctx, globalCache) {
528
- var _a;
607
+ var _a, _b;
529
608
  if ((_a = globalCache.commentBox) === null || _a === void 0 ? void 0 : _a.resizingId) {
530
- var _b = globalCache.commentBox,
531
- resizingId = _b.resizingId,
532
- _c = _b.commentRC,
533
- r = _c.r,
534
- c = _c.c;
609
+ var _c = globalCache.commentBox,
610
+ resizingId = _c.resizingId,
611
+ _d = _c.commentRC,
612
+ r = _d.r,
613
+ c = _d.c;
535
614
  globalCache.commentBox.resizingId = undefined;
536
615
  var position = getCommentBoxPosition(resizingId);
537
616
  if (position) {
@@ -547,6 +626,19 @@ function onCommentBoxResizeEnd(ctx, globalCache) {
547
626
  cell.ps.width = width / ctx.zoomRatio;
548
627
  cell.ps.height = height / ctx.zoomRatio;
549
628
  setEditingComment(ctx, flowdata, r, c);
629
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
630
+ ctx.hooks.updateCellYdoc([{
631
+ sheetId: ctx.currentSheetId,
632
+ path: ["celldata"],
633
+ value: {
634
+ r: r,
635
+ c: c,
636
+ v: cell
637
+ },
638
+ key: "".concat(r, "_").concat(c),
639
+ type: "update"
640
+ }]);
641
+ }
550
642
  }
551
643
  }
552
644
  }
@@ -598,13 +690,13 @@ function onCommentBoxMove(ctx, globalCache, e) {
598
690
  return false;
599
691
  }
600
692
  function onCommentBoxMoveEnd(ctx, globalCache) {
601
- var _a;
693
+ var _a, _b;
602
694
  if ((_a = globalCache.commentBox) === null || _a === void 0 ? void 0 : _a.movingId) {
603
- var _b = globalCache.commentBox,
604
- movingId = _b.movingId,
605
- _c = _b.commentRC,
606
- r = _c.r,
607
- c = _c.c;
695
+ var _c = globalCache.commentBox,
696
+ movingId = _c.movingId,
697
+ _d = _c.commentRC,
698
+ r = _d.r,
699
+ c = _d.c;
608
700
  globalCache.commentBox.movingId = undefined;
609
701
  var position = getCommentBoxPosition(movingId);
610
702
  if (position) {
@@ -616,6 +708,19 @@ function onCommentBoxMoveEnd(ctx, globalCache) {
616
708
  cell.ps.left = left / ctx.zoomRatio;
617
709
  cell.ps.top = top_5 / ctx.zoomRatio;
618
710
  setEditingComment(ctx, flowdata, r, c);
711
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
712
+ ctx.hooks.updateCellYdoc([{
713
+ sheetId: ctx.currentSheetId,
714
+ path: ["celldata"],
715
+ value: {
716
+ r: r,
717
+ c: c,
718
+ v: cell
719
+ },
720
+ key: "".concat(r, "_").concat(c),
721
+ type: "update"
722
+ }]);
723
+ }
619
724
  }
620
725
  }
621
726
  }
@@ -67,8 +67,66 @@ var refreshLocalMergeData = function refreshLocalMergeData(merge_new, file) {
67
67
  }
68
68
  });
69
69
  };
70
+ var getMergeBounds = function getMergeBounds(mergeMap) {
71
+ if (!mergeMap) return null;
72
+ var minR = Infinity;
73
+ var minC = Infinity;
74
+ var maxR = -Infinity;
75
+ var maxC = -Infinity;
76
+ Object.values(mergeMap).forEach(function (mc) {
77
+ var _a, _b;
78
+ if (!mc) return;
79
+ var r = Number(mc.r);
80
+ var c = Number(mc.c);
81
+ var rs = Number((_a = mc.rs) !== null && _a !== void 0 ? _a : 1);
82
+ var cs = Number((_b = mc.cs) !== null && _b !== void 0 ? _b : 1);
83
+ if (!Number.isFinite(r) || !Number.isFinite(c)) return;
84
+ minR = Math.min(minR, r);
85
+ minC = Math.min(minC, c);
86
+ maxR = Math.max(maxR, r + Math.max(1, rs) - 1);
87
+ maxC = Math.max(maxC, c + Math.max(1, cs) - 1);
88
+ });
89
+ if (minR === Infinity) return null;
90
+ return {
91
+ minR: minR,
92
+ minC: minC,
93
+ maxR: maxR,
94
+ maxC: maxC
95
+ };
96
+ };
97
+ var emitCellRangeToYdoc = function emitCellRangeToYdoc(ctx, sheetId, d, r1, r2, c1, c2) {
98
+ var _a, _b, _c, _d;
99
+ if (!((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc)) return;
100
+ if (!d || !Array.isArray(d) || d.length === 0) return;
101
+ var rowEnd = Math.min(r2, d.length - 1);
102
+ var colEnd = Math.min(c2, ((_c = (_b = d[0]) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) - 1);
103
+ var rowStart = Math.max(0, r1);
104
+ var colStart = Math.max(0, c1);
105
+ if (rowStart > rowEnd || colStart > colEnd) return;
106
+ var changes = [];
107
+ for (var r = rowStart; r <= rowEnd; r += 1) {
108
+ var row = d[r] || [];
109
+ for (var c = colStart; c <= colEnd; c += 1) {
110
+ changes.push({
111
+ sheetId: sheetId,
112
+ path: ["celldata"],
113
+ value: {
114
+ r: r,
115
+ c: c,
116
+ v: (_d = row === null || row === void 0 ? void 0 : row[c]) !== null && _d !== void 0 ? _d : null
117
+ },
118
+ key: "".concat(r, "_").concat(c),
119
+ type: "update"
120
+ });
121
+ }
122
+ }
123
+ changes.forEach(function (change) {
124
+ console.log("emitCellRangeToYdoc", change, __assign({}, change.value.v));
125
+ });
126
+ if (changes.length > 0) ctx.hooks.updateCellYdoc(changes);
127
+ };
70
128
  function insertRowCol(ctx, op, changeSelection) {
71
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
129
+ 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;
72
130
  if (changeSelection === void 0) {
73
131
  changeSelection = true;
74
132
  }
@@ -1033,9 +1091,19 @@ function insertRowCol(ctx, op, changeSelection) {
1033
1091
  }
1034
1092
  }
1035
1093
  refreshLocalMergeData(merge_new, file);
1094
+ var mergeBounds = getMergeBounds(cfg.merge);
1095
+ if (type === "row") {
1096
+ var baseStart = direction === "lefttop" ? index : index + 1;
1097
+ var startR = mergeBounds ? Math.min(baseStart, mergeBounds.minR) : baseStart;
1098
+ 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);
1099
+ } else {
1100
+ var baseStart = direction === "lefttop" ? index : index + 1;
1101
+ var startC = mergeBounds ? Math.min(baseStart, mergeBounds.minC) : baseStart;
1102
+ 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);
1103
+ }
1036
1104
  }
1037
1105
  function deleteRowCol(ctx, op) {
1038
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
1106
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
1039
1107
  var type = op.type;
1040
1108
  var start = op.start,
1041
1109
  end = op.end,
@@ -1755,6 +1823,14 @@ function deleteRowCol(ctx, op) {
1755
1823
  file.dataVerification = newDataVerification;
1756
1824
  file.hyperlink = newHyperlink;
1757
1825
  refreshLocalMergeData(merge_new, file);
1826
+ var mergeBounds = getMergeBounds(cfg.merge);
1827
+ if (type === "row") {
1828
+ var startR = mergeBounds ? Math.min(start, mergeBounds.minR) : start;
1829
+ 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);
1830
+ } else {
1831
+ var startC = mergeBounds ? Math.min(start, mergeBounds.minC) : start;
1832
+ 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);
1833
+ }
1758
1834
  if (file.id === ctx.currentSheetId) {
1759
1835
  ctx.config = cfg;
1760
1836
  } else {}