@fileverse-dev/fortune-core 1.2.90-ydoc-11 → 1.2.90-ydoc-13

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.
@@ -189,28 +189,43 @@ function postPasteCut(ctx, source, target, RowlChange) {
189
189
  storeSheetParamALL(ctx);
190
190
  }
191
191
  var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
192
- var _a;
192
+ var _a, _b, _c;
193
+ var changes = [];
193
194
  for (var r = 0; r < d.length; r += 1) {
194
195
  var x = d[r];
195
196
  for (var c = 0; c < d[0].length; c += 1) {
196
197
  var value = isObject(d[r][c]) ? (_a = d[r][c]) === null || _a === void 0 ? void 0 : _a.v : d[r][c];
197
198
  if (value && String(value).startsWith("=")) {
198
199
  var cell = {};
199
- var _b = execfunction(ctx, String(value), r, c, undefined, undefined, true),
200
- v = _b[1],
201
- f = _b[2];
200
+ var _d = execfunction(ctx, String(value), r, c, undefined, undefined, true),
201
+ v = _d[1],
202
+ f = _d[2];
202
203
  cell.v = v;
203
204
  cell.f = f;
204
205
  cell.m = v.toString();
205
206
  x[c] = cell;
206
207
  }
207
208
  d[r] = x;
209
+ changes.push({
210
+ sheetId: ctx.currentSheetId,
211
+ path: ['celldata'],
212
+ value: {
213
+ r: r,
214
+ c: c,
215
+ v: d[r][c]
216
+ },
217
+ key: r + '_' + c,
218
+ type: 'update'
219
+ });
208
220
  }
209
221
  }
222
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
223
+ (_c = ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc(changes);
224
+ }
210
225
  };
211
226
  function pasteHandler(ctx, data, borderInfo) {
212
227
  var _a;
213
- var _b, _c, _d, _e, _f, _g;
228
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
214
229
  if (ctx.luckysheet_selection_range) {
215
230
  ctx.luckysheet_selection_range = [];
216
231
  }
@@ -258,6 +273,7 @@ function pasteHandler(ctx, data, borderInfo) {
258
273
  }
259
274
  var RowlChange = false;
260
275
  var offsetMC = {};
276
+ var changes = [];
261
277
  for (var h = minh; h <= maxh; h += 1) {
262
278
  var x = d[h];
263
279
  var currentRowLen = ctx.defaultrowlen;
@@ -305,12 +321,26 @@ function pasteHandler(ctx, data, borderInfo) {
305
321
  };
306
322
  (_f = cfg.borderInfo) === null || _f === void 0 ? void 0 : _f.push(bd_obj);
307
323
  }
324
+ changes.push({
325
+ sheetId: ctx.currentSheetId,
326
+ path: ['celldata'],
327
+ value: {
328
+ r: h,
329
+ c: c,
330
+ v: d[h][c]
331
+ },
332
+ key: h + '_' + c,
333
+ type: 'update'
334
+ });
308
335
  }
309
336
  d[h] = x;
310
337
  if (currentRowLen !== ctx.defaultrowlen) {
311
338
  cfg.rowlen[h] = currentRowLen;
312
339
  }
313
340
  }
341
+ if ((_g = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _g === void 0 ? void 0 : _g.updateCellYdoc) {
342
+ (_h = ctx.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc(changes);
343
+ }
314
344
  ctx.luckysheet_select_save = [{
315
345
  row: [minh, maxh],
316
346
  column: [minc, maxc]
@@ -335,7 +365,7 @@ function pasteHandler(ctx, data, borderInfo) {
335
365
  }
336
366
  var d = getFlowdata(ctx);
337
367
  if (!d) return;
338
- var last = (_g = ctx.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g[ctx.luckysheet_select_save.length - 1];
368
+ var last = (_j = ctx.luckysheet_select_save) === null || _j === void 0 ? void 0 : _j[ctx.luckysheet_select_save.length - 1];
339
369
  if (!last) return;
340
370
  var curR = last.row == null ? 0 : last.row[0];
341
371
  var curC = last.column == null ? 0 : last.column[0];
@@ -360,6 +390,7 @@ function pasteHandler(ctx, data, borderInfo) {
360
390
  if (!/^(https?:\/\/|www\.)\S+$/i.test(t)) return null;
361
391
  return t.startsWith("http") ? t : "https://".concat(t);
362
392
  };
393
+ var changes = [];
363
394
  for (var r = 0; r < rlen; r += 1) {
364
395
  var x = d[r + curR];
365
396
  for (var c = 0; c < clen; c += 1) {
@@ -432,9 +463,23 @@ function pasteHandler(ctx, data, borderInfo) {
432
463
  }
433
464
  x[c + curC] = cell;
434
465
  }
466
+ changes.push(changes.push({
467
+ sheetId: ctx.currentSheetId,
468
+ path: ['celldata'],
469
+ value: {
470
+ r: r,
471
+ c: c,
472
+ v: d[r][c]
473
+ },
474
+ key: r + '_' + c,
475
+ type: 'update'
476
+ }));
435
477
  }
436
478
  d[r + curR] = x;
437
479
  }
480
+ if ((_k = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _k === void 0 ? void 0 : _k.updateCellYdoc) {
481
+ (_l = ctx.hooks) === null || _l === void 0 ? void 0 : _l.updateCellYdoc(changes);
482
+ }
438
483
  last.row = [curR, curR + rlen - 1];
439
484
  last.column = [curC, curC + clen - 1];
440
485
  jfrefreshgrid(ctx, null, undefined);
@@ -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);
@@ -1556,6 +1557,15 @@ export function deleteSelectedCellText(ctx) {
1556
1557
  if ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.afterUpdateCell) {
1557
1558
  ctx.hooks.afterUpdateCell(r, c, null, d[r][c]);
1558
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
+ });
1559
1569
  }
1560
1570
  }
1561
1571
  }
@@ -15,13 +15,14 @@ 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, _7, _8, _9;
19
- var _10;
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
  console.log("updateFormatCell", row_st, row_ed, col_st, col_ed);
21
21
  if (_.isNil(d) || _.isNil(attr)) {
22
22
  return;
23
23
  }
24
24
  if (attr === "ct") {
25
+ var changes = [];
25
26
  for (var r = row_st; r <= row_ed; r += 1) {
26
27
  if (!_.isNil(ctx.config.rowhidden) && !_.isNil(ctx.config.rowhidden[r])) {
27
28
  continue;
@@ -73,9 +74,20 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
73
74
  m: mask
74
75
  };
75
76
  }
76
- if ((_x = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _x === void 0 ? void 0 : _x.afterUpdateCell) {
77
- (_z = (_y = ctx.hooks) === null || _y === void 0 ? void 0 : _y.afterUpdateCell) === null || _z === void 0 ? void 0 : _z.call(_y, r, c, null, d[r][c]);
78
- }
77
+ changes.push({
78
+ sheetId: ctx.currentSheetId,
79
+ path: ['celldata'],
80
+ value: {
81
+ r: r,
82
+ c: c,
83
+ v: d[r][c]
84
+ },
85
+ key: r + '_' + c,
86
+ type: 'update'
87
+ });
88
+ }
89
+ if ((_x = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _x === void 0 ? void 0 : _x.updateCellYdoc) {
90
+ (_y = ctx.hooks) === null || _y === void 0 ? void 0 : _y.updateCellYdoc(changes);
79
91
  }
80
92
  }
81
93
  } else {
@@ -122,6 +134,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
122
134
  if (sheetIndex == null) {
123
135
  return;
124
136
  }
137
+ var changes = [];
125
138
  for (var r = row_st; r <= row_ed; r += 1) {
126
139
  if (!_.isNil(ctx.config.rowhidden) && !_.isNil(ctx.config.rowhidden[r])) {
127
140
  continue;
@@ -131,11 +144,11 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
131
144
  if (value && _.isPlainObject(value)) {
132
145
  updateInlineStringFormatOutside(value, attr, foucsStatus);
133
146
  value[attr] = foucsStatus;
134
- (_10 = ctx.luckysheetfile[sheetIndex]).config || (_10.config = {});
147
+ (_11 = ctx.luckysheetfile[sheetIndex]).config || (_11.config = {});
135
148
  var cfg = ctx.luckysheetfile[sheetIndex].config;
136
- var cellWidth = ((_0 = cfg.columnlen) === null || _0 === void 0 ? void 0 : _0[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
149
+ var cellWidth = ((_z = cfg.columnlen) === null || _z === void 0 ? void 0 : _z[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
137
150
  if (attr === "tb" && canvas && foucsStatus === "2") {
138
- var currentColWidth_1 = ((_1 = cfg.columnlen) === null || _1 === void 0 ? void 0 : _1[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
151
+ var currentColWidth_1 = ((_0 = cfg.columnlen) === null || _0 === void 0 ? void 0 : _0[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
139
152
  var lineCount_1 = 1;
140
153
  var fontString_1 = "10px Arial";
141
154
  if (value.fs) {
@@ -148,9 +161,9 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
148
161
  lineCount_1 = getLineCount(value.m, currentColWidth_1, fontString_1);
149
162
  var hOffset = lineCount_1 < 4 ? 1.9 : 1.7;
150
163
  lineCount_1 = lineCount_1 * hOffset + 1;
151
- } else if ((_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) {
164
+ } 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) {
152
165
  lineCount_1 -= 1;
153
- var line = (_7 = (_6 = (_5 = value === null || value === void 0 ? void 0 : value.ct) === null || _5 === void 0 ? void 0 : _5.s) === null || _6 === void 0 ? void 0 : _6[0]) === null || _7 === void 0 ? void 0 : _7.v.split("\n");
166
+ 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");
154
167
  line.forEach(function (item) {
155
168
  var subLineCount = getLineCount(item, currentColWidth_1, fontString_1);
156
169
  lineCount_1 += subLineCount;
@@ -170,7 +183,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
170
183
  });
171
184
  if (!textInfo) return "continue";
172
185
  var rowHeight = _.round(textInfo.textHeightAll);
173
- var currentRowHeight = ((_8 = cfg.rowlen) === null || _8 === void 0 ? void 0 : _8[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
186
+ var currentRowHeight = ((_7 = cfg.rowlen) === null || _7 === void 0 ? void 0 : _7[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
174
187
  if (!_.isUndefined(rowHeight) && rowHeight > currentRowHeight && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
175
188
  if (_.isUndefined(cfg.rowlen)) cfg.rowlen = {};
176
189
  _.set(cfg, "rowlen.".concat(r), rowHeight);
@@ -185,7 +198,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
185
198
  });
186
199
  if (!textInfo) return "continue";
187
200
  var newHeight = _.round(textInfo.textHeightAll);
188
- var oldHeight = ((_9 = cfg.rowlen) === null || _9 === void 0 ? void 0 : _9[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
201
+ var oldHeight = ((_8 = cfg.rowlen) === null || _8 === void 0 ? void 0 : _8[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
189
202
  var shouldResize = foucsStatus === "2" ? newHeight > oldHeight : true;
190
203
  if (shouldResize && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
191
204
  var padding = 12;
@@ -200,11 +213,25 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
200
213
  };
201
214
  d[r][c][attr] = foucsStatus;
202
215
  }
216
+ changes.push({
217
+ sheetId: ctx.currentSheetId,
218
+ path: ['celldata'],
219
+ value: {
220
+ r: r,
221
+ c: c,
222
+ v: d[r][c]
223
+ },
224
+ key: "".concat(r, "_").concat(c),
225
+ type: "update"
226
+ });
203
227
  };
204
228
  for (var c = col_st; c <= col_ed; c += 1) {
205
229
  _loop_1(c);
206
230
  }
207
231
  }
232
+ if ((_9 = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _9 === void 0 ? void 0 : _9.updateCellYdoc) {
233
+ (_10 = ctx.hooks) === null || _10 === void 0 ? void 0 : _10.updateCellYdoc(changes);
234
+ }
208
235
  }
209
236
  }
210
237
  export function updateFormat(ctx, $input, d, attr, foucsStatus, canvas) {
package/es/settings.d.ts CHANGED
@@ -1,5 +1,12 @@
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 = {
4
11
  calcChainChange?: () => void;
5
12
  sheetLengthChange?: () => void;
@@ -11,6 +18,7 @@ export type Hooks = {
11
18
  conditionFormatChange?: () => void;
12
19
  cellDataChange?: () => void;
13
20
  hyperlinkChange?: () => void;
21
+ updateCellYdoc?: (changes: SheetChangePath[]) => void;
14
22
  beforeUpdateCell?: (r: number, c: number, value: any) => boolean;
15
23
  afterUpdateCell?: (row: number, column: number, oldValue: any, newValue: any) => void;
16
24
  afterSelectionChange?: (sheetId: string, selection: Selection) => void;
@@ -202,28 +202,43 @@ function postPasteCut(ctx, source, target, RowlChange) {
202
202
  (0, _sheet.storeSheetParamALL)(ctx);
203
203
  }
204
204
  var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
205
- var _a;
205
+ var _a, _b, _c;
206
+ var changes = [];
206
207
  for (var r = 0; r < d.length; r += 1) {
207
208
  var x = d[r];
208
209
  for (var c = 0; c < d[0].length; c += 1) {
209
210
  var value = (0, _lodash.isObject)(d[r][c]) ? (_a = d[r][c]) === null || _a === void 0 ? void 0 : _a.v : d[r][c];
210
211
  if (value && String(value).startsWith("=")) {
211
212
  var cell = {};
212
- var _b = (0, _formula.execfunction)(ctx, String(value), r, c, undefined, undefined, true),
213
- v = _b[1],
214
- f = _b[2];
213
+ var _d = (0, _formula.execfunction)(ctx, String(value), r, c, undefined, undefined, true),
214
+ v = _d[1],
215
+ f = _d[2];
215
216
  cell.v = v;
216
217
  cell.f = f;
217
218
  cell.m = v.toString();
218
219
  x[c] = cell;
219
220
  }
220
221
  d[r] = x;
222
+ changes.push({
223
+ sheetId: ctx.currentSheetId,
224
+ path: ['celldata'],
225
+ value: {
226
+ r: r,
227
+ c: c,
228
+ v: d[r][c]
229
+ },
230
+ key: r + '_' + c,
231
+ type: 'update'
232
+ });
221
233
  }
222
234
  }
235
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
236
+ (_c = ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc(changes);
237
+ }
223
238
  };
224
239
  function pasteHandler(ctx, data, borderInfo) {
225
240
  var _a;
226
- var _b, _c, _d, _e, _f, _g;
241
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
227
242
  if (ctx.luckysheet_selection_range) {
228
243
  ctx.luckysheet_selection_range = [];
229
244
  }
@@ -271,6 +286,7 @@ function pasteHandler(ctx, data, borderInfo) {
271
286
  }
272
287
  var RowlChange = false;
273
288
  var offsetMC = {};
289
+ var changes = [];
274
290
  for (var h = minh; h <= maxh; h += 1) {
275
291
  var x = d[h];
276
292
  var currentRowLen = ctx.defaultrowlen;
@@ -318,12 +334,26 @@ function pasteHandler(ctx, data, borderInfo) {
318
334
  };
319
335
  (_f = cfg.borderInfo) === null || _f === void 0 ? void 0 : _f.push(bd_obj);
320
336
  }
337
+ changes.push({
338
+ sheetId: ctx.currentSheetId,
339
+ path: ['celldata'],
340
+ value: {
341
+ r: h,
342
+ c: c,
343
+ v: d[h][c]
344
+ },
345
+ key: h + '_' + c,
346
+ type: 'update'
347
+ });
321
348
  }
322
349
  d[h] = x;
323
350
  if (currentRowLen !== ctx.defaultrowlen) {
324
351
  cfg.rowlen[h] = currentRowLen;
325
352
  }
326
353
  }
354
+ if ((_g = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _g === void 0 ? void 0 : _g.updateCellYdoc) {
355
+ (_h = ctx.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc(changes);
356
+ }
327
357
  ctx.luckysheet_select_save = [{
328
358
  row: [minh, maxh],
329
359
  column: [minc, maxc]
@@ -348,7 +378,7 @@ function pasteHandler(ctx, data, borderInfo) {
348
378
  }
349
379
  var d = (0, _context.getFlowdata)(ctx);
350
380
  if (!d) return;
351
- var last = (_g = ctx.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g[ctx.luckysheet_select_save.length - 1];
381
+ var last = (_j = ctx.luckysheet_select_save) === null || _j === void 0 ? void 0 : _j[ctx.luckysheet_select_save.length - 1];
352
382
  if (!last) return;
353
383
  var curR = last.row == null ? 0 : last.row[0];
354
384
  var curC = last.column == null ? 0 : last.column[0];
@@ -373,6 +403,7 @@ function pasteHandler(ctx, data, borderInfo) {
373
403
  if (!/^(https?:\/\/|www\.)\S+$/i.test(t)) return null;
374
404
  return t.startsWith("http") ? t : "https://".concat(t);
375
405
  };
406
+ var changes = [];
376
407
  for (var r = 0; r < rlen; r += 1) {
377
408
  var x = d[r + curR];
378
409
  for (var c = 0; c < clen; c += 1) {
@@ -445,9 +476,23 @@ function pasteHandler(ctx, data, borderInfo) {
445
476
  }
446
477
  x[c + curC] = cell;
447
478
  }
479
+ changes.push(changes.push({
480
+ sheetId: ctx.currentSheetId,
481
+ path: ['celldata'],
482
+ value: {
483
+ r: r,
484
+ c: c,
485
+ v: d[r][c]
486
+ },
487
+ key: r + '_' + c,
488
+ type: 'update'
489
+ }));
448
490
  }
449
491
  d[r + curR] = x;
450
492
  }
493
+ if ((_k = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _k === void 0 ? void 0 : _k.updateCellYdoc) {
494
+ (_l = ctx.hooks) === null || _l === void 0 ? void 0 : _l.updateCellYdoc(changes);
495
+ }
451
496
  last.row = [curR, curR + rlen - 1];
452
497
  last.column = [curC, curC + clen - 1];
453
498
  (0, _refresh.jfrefreshgrid)(ctx, null, undefined);
@@ -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);
@@ -1591,6 +1592,15 @@ function deleteSelectedCellText(ctx) {
1591
1592
  if ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.afterUpdateCell) {
1592
1593
  ctx.hooks.afterUpdateCell(r, c, null, d[r][c]);
1593
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
+ });
1594
1604
  }
1595
1605
  }
1596
1606
  }
@@ -48,13 +48,14 @@ 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, _7, _8, _9;
52
- var _10;
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
  console.log("updateFormatCell", row_st, row_ed, col_st, col_ed);
54
54
  if (_lodash.default.isNil(d) || _lodash.default.isNil(attr)) {
55
55
  return;
56
56
  }
57
57
  if (attr === "ct") {
58
+ var changes = [];
58
59
  for (var r = row_st; r <= row_ed; r += 1) {
59
60
  if (!_lodash.default.isNil(ctx.config.rowhidden) && !_lodash.default.isNil(ctx.config.rowhidden[r])) {
60
61
  continue;
@@ -106,9 +107,20 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
106
107
  m: mask
107
108
  };
108
109
  }
109
- if ((_x = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _x === void 0 ? void 0 : _x.afterUpdateCell) {
110
- (_z = (_y = ctx.hooks) === null || _y === void 0 ? void 0 : _y.afterUpdateCell) === null || _z === void 0 ? void 0 : _z.call(_y, r, c, null, d[r][c]);
111
- }
110
+ changes.push({
111
+ sheetId: ctx.currentSheetId,
112
+ path: ['celldata'],
113
+ value: {
114
+ r: r,
115
+ c: c,
116
+ v: d[r][c]
117
+ },
118
+ key: r + '_' + c,
119
+ type: 'update'
120
+ });
121
+ }
122
+ if ((_x = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _x === void 0 ? void 0 : _x.updateCellYdoc) {
123
+ (_y = ctx.hooks) === null || _y === void 0 ? void 0 : _y.updateCellYdoc(changes);
112
124
  }
113
125
  }
114
126
  } else {
@@ -155,6 +167,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
155
167
  if (sheetIndex == null) {
156
168
  return;
157
169
  }
170
+ var changes = [];
158
171
  for (var r = row_st; r <= row_ed; r += 1) {
159
172
  if (!_lodash.default.isNil(ctx.config.rowhidden) && !_lodash.default.isNil(ctx.config.rowhidden[r])) {
160
173
  continue;
@@ -164,11 +177,11 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
164
177
  if (value && _lodash.default.isPlainObject(value)) {
165
178
  (0, _inlineString.updateInlineStringFormatOutside)(value, attr, foucsStatus);
166
179
  value[attr] = foucsStatus;
167
- (_10 = ctx.luckysheetfile[sheetIndex]).config || (_10.config = {});
180
+ (_11 = ctx.luckysheetfile[sheetIndex]).config || (_11.config = {});
168
181
  var cfg = ctx.luckysheetfile[sheetIndex].config;
169
- var cellWidth = ((_0 = cfg.columnlen) === null || _0 === void 0 ? void 0 : _0[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
182
+ var cellWidth = ((_z = cfg.columnlen) === null || _z === void 0 ? void 0 : _z[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
170
183
  if (attr === "tb" && canvas && foucsStatus === "2") {
171
- var currentColWidth_1 = ((_1 = cfg.columnlen) === null || _1 === void 0 ? void 0 : _1[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
184
+ var currentColWidth_1 = ((_0 = cfg.columnlen) === null || _0 === void 0 ? void 0 : _0[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
172
185
  var lineCount_1 = 1;
173
186
  var fontString_1 = "10px Arial";
174
187
  if (value.fs) {
@@ -181,9 +194,9 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
181
194
  lineCount_1 = (0, _utils.getLineCount)(value.m, currentColWidth_1, fontString_1);
182
195
  var hOffset = lineCount_1 < 4 ? 1.9 : 1.7;
183
196
  lineCount_1 = lineCount_1 * hOffset + 1;
184
- } else if ((_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) {
197
+ } 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) {
185
198
  lineCount_1 -= 1;
186
- var line = (_7 = (_6 = (_5 = value === null || value === void 0 ? void 0 : value.ct) === null || _5 === void 0 ? void 0 : _5.s) === null || _6 === void 0 ? void 0 : _6[0]) === null || _7 === void 0 ? void 0 : _7.v.split("\n");
199
+ 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");
187
200
  line.forEach(function (item) {
188
201
  var subLineCount = (0, _utils.getLineCount)(item, currentColWidth_1, fontString_1);
189
202
  lineCount_1 += subLineCount;
@@ -203,7 +216,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
203
216
  });
204
217
  if (!textInfo) return "continue";
205
218
  var rowHeight = _lodash.default.round(textInfo.textHeightAll);
206
- var currentRowHeight = ((_8 = cfg.rowlen) === null || _8 === void 0 ? void 0 : _8[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
219
+ var currentRowHeight = ((_7 = cfg.rowlen) === null || _7 === void 0 ? void 0 : _7[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
207
220
  if (!_lodash.default.isUndefined(rowHeight) && rowHeight > currentRowHeight && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
208
221
  if (_lodash.default.isUndefined(cfg.rowlen)) cfg.rowlen = {};
209
222
  _lodash.default.set(cfg, "rowlen.".concat(r), rowHeight);
@@ -218,7 +231,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
218
231
  });
219
232
  if (!textInfo) return "continue";
220
233
  var newHeight = _lodash.default.round(textInfo.textHeightAll);
221
- var oldHeight = ((_9 = cfg.rowlen) === null || _9 === void 0 ? void 0 : _9[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
234
+ var oldHeight = ((_8 = cfg.rowlen) === null || _8 === void 0 ? void 0 : _8[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
222
235
  var shouldResize = foucsStatus === "2" ? newHeight > oldHeight : true;
223
236
  if (shouldResize && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
224
237
  var padding = 12;
@@ -233,11 +246,25 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
233
246
  };
234
247
  d[r][c][attr] = foucsStatus;
235
248
  }
249
+ changes.push({
250
+ sheetId: ctx.currentSheetId,
251
+ path: ['celldata'],
252
+ value: {
253
+ r: r,
254
+ c: c,
255
+ v: d[r][c]
256
+ },
257
+ key: "".concat(r, "_").concat(c),
258
+ type: "update"
259
+ });
236
260
  };
237
261
  for (var c = col_st; c <= col_ed; c += 1) {
238
262
  _loop_1(c);
239
263
  }
240
264
  }
265
+ if ((_9 = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _9 === void 0 ? void 0 : _9.updateCellYdoc) {
266
+ (_10 = ctx.hooks) === null || _10 === void 0 ? void 0 : _10.updateCellYdoc(changes);
267
+ }
241
268
  }
242
269
  }
243
270
  function updateFormat(ctx, $input, d, attr, foucsStatus, canvas) {
package/lib/settings.d.ts CHANGED
@@ -1,5 +1,12 @@
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 = {
4
11
  calcChainChange?: () => void;
5
12
  sheetLengthChange?: () => void;
@@ -11,6 +18,7 @@ export type Hooks = {
11
18
  conditionFormatChange?: () => void;
12
19
  cellDataChange?: () => void;
13
20
  hyperlinkChange?: () => void;
21
+ updateCellYdoc?: (changes: SheetChangePath[]) => void;
14
22
  beforeUpdateCell?: (r: number, c: number, value: any) => boolean;
15
23
  afterUpdateCell?: (row: number, column: number, oldValue: any, newValue: any) => void;
16
24
  afterSelectionChange?: (sheetId: string, selection: Selection) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.2.90-ydoc-11",
3
+ "version": "1.2.90-ydoc-13",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",