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

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.
@@ -57,7 +57,7 @@ function getCellHyperlink(ctx, r, c) {
57
57
  return undefined;
58
58
  }
59
59
  function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress, options) {
60
- var _a, _b, _c;
60
+ var _a, _b, _c, _d;
61
61
  var applyToSelection = (options === null || options === void 0 ? void 0 : options.applyToSelection) && (options === null || options === void 0 ? void 0 : options.cellInput);
62
62
  var sheetIndex = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
63
63
  var flowdata = (0, _context.getFlowdata)(ctx);
@@ -77,8 +77,30 @@ function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress, options) {
77
77
  id: ctx.currentSheetId
78
78
  };
79
79
  flowdata[r][c] = cell;
80
+ if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc) {
81
+ ctx.hooks.updateCellYdoc([{
82
+ sheetId: ctx.currentSheetId,
83
+ path: ["hyperlink"],
84
+ key: "".concat(r, "_").concat(c),
85
+ value: {
86
+ linkType: linkType,
87
+ linkAddress: linkAddress
88
+ },
89
+ type: "update"
90
+ }, {
91
+ sheetId: ctx.currentSheetId,
92
+ path: ["celldata"],
93
+ value: {
94
+ r: r,
95
+ c: c,
96
+ v: cell
97
+ },
98
+ key: "".concat(r, "_").concat(c),
99
+ type: "update"
100
+ }]);
101
+ }
80
102
  }
81
- var offsets = (_a = ctx.linkCard) === null || _a === void 0 ? void 0 : _a.selectionOffsets;
103
+ var offsets = (_b = ctx.linkCard) === null || _b === void 0 ? void 0 : _b.selectionOffsets;
82
104
  if (offsets) {
83
105
  (0, _cursor.setSelectionByCharacterOffset)(options.cellInput, offsets.start, offsets.end);
84
106
  }
@@ -107,8 +129,8 @@ function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress, options) {
107
129
  };
108
130
  flowdata[r][c] = cell;
109
131
  ctx.linkCard = undefined;
110
- if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
111
- (_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc([{
132
+ if ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc) {
133
+ (_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.updateCellYdoc([{
112
134
  sheetId: ctx.currentSheetId,
113
135
  path: ["celldata"],
114
136
  value: {
@@ -123,11 +145,12 @@ function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress, options) {
123
145
  }
124
146
  }
125
147
  function removeHyperlink(ctx, r, c) {
126
- var _a, _b, _c;
148
+ var _a, _b, _c, _d;
127
149
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
128
150
  if (!allowEdit) return;
129
151
  var sheetIndex = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
130
152
  var flowdata = (0, _context.getFlowdata)(ctx);
153
+ var updatedCell = null;
131
154
  if (flowdata != null && sheetIndex != null) {
132
155
  var hyperlink = _lodash.default.omit(ctx.luckysheetfile[sheetIndex].hyperlink, "".concat(r, "_").concat(c));
133
156
  _lodash.default.set(ctx.luckysheetfile[sheetIndex], "hyperlink", hyperlink);
@@ -136,9 +159,33 @@ function removeHyperlink(ctx, r, c) {
136
159
  (_a = flowdata[r][c]) === null || _a === void 0 ? true : delete _a.hl;
137
160
  (_b = flowdata[r][c]) === null || _b === void 0 ? true : delete _b.un;
138
161
  (_c = flowdata[r][c]) === null || _c === void 0 ? true : delete _c.fc;
162
+ updatedCell = flowdata[r][c];
139
163
  }
140
164
  }
141
165
  ctx.linkCard = undefined;
166
+ if ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.updateCellYdoc) {
167
+ var changes = [{
168
+ sheetId: ctx.currentSheetId,
169
+ path: ["hyperlink"],
170
+ key: "".concat(r, "_").concat(c),
171
+ value: null,
172
+ type: "delete"
173
+ }];
174
+ if (updatedCell != null) {
175
+ changes.push({
176
+ sheetId: ctx.currentSheetId,
177
+ path: ["celldata"],
178
+ value: {
179
+ r: r,
180
+ c: c,
181
+ v: updatedCell
182
+ },
183
+ key: "".concat(r, "_").concat(c),
184
+ type: "update"
185
+ });
186
+ }
187
+ ctx.hooks.updateCellYdoc(changes);
188
+ }
142
189
  }
143
190
  function showLinkCard(ctx, r, c, options, isEditing, isMouseDown) {
144
191
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -120,9 +120,6 @@ var emitCellRangeToYdoc = function emitCellRangeToYdoc(ctx, sheetId, d, r1, r2,
120
120
  });
121
121
  }
122
122
  }
123
- changes.forEach(function (change) {
124
- console.log("emitCellRangeToYdoc", change, __assign({}, change.value.v));
125
- });
126
123
  if (changes.length > 0) ctx.hooks.updateCellYdoc(changes);
127
124
  };
128
125
  function insertRowCol(ctx, op, changeSelection) {
@@ -271,7 +271,7 @@ function onSearchDialogMoveEnd(globalCache) {
271
271
  _lodash.default.set(globalCache, "searchDialog.moveProps", undefined);
272
272
  }
273
273
  function replace(ctx, searchText, replaceText, checkModes) {
274
- var _a, _b;
274
+ var _a, _b, _c, _d, _e, _f, _g, _h;
275
275
  var findAndReplace = (0, _locale.locale)(ctx).findAndReplace;
276
276
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
277
277
  if (!allowEdit) {
@@ -318,6 +318,19 @@ function replace(ctx, searchText, replaceText, checkModes) {
318
318
  c = searchIndexArr[count].c;
319
319
  var v = replaceText;
320
320
  (0, _cell.setCellValue)(ctx, r, c, d, v);
321
+ if ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc) {
322
+ ctx.hooks.updateCellYdoc([{
323
+ sheetId: ctx.currentSheetId,
324
+ path: ["celldata"],
325
+ value: {
326
+ r: r,
327
+ c: c,
328
+ v: (_e = (_d = d === null || d === void 0 ? void 0 : d[r]) === null || _d === void 0 ? void 0 : _d[c]) !== null && _e !== void 0 ? _e : null
329
+ },
330
+ key: "".concat(r, "_").concat(c),
331
+ type: "update"
332
+ }]);
333
+ }
321
334
  } else {
322
335
  var reg = void 0;
323
336
  if (checkModes.caseCheck) {
@@ -329,6 +342,19 @@ function replace(ctx, searchText, replaceText, checkModes) {
329
342
  c = searchIndexArr[count].c;
330
343
  var v = (0, _format.valueShowEs)(r, c, d).toString().replace(reg, replaceText);
331
344
  (0, _cell.setCellValue)(ctx, r, c, d, v);
345
+ if ((_f = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _f === void 0 ? void 0 : _f.updateCellYdoc) {
346
+ ctx.hooks.updateCellYdoc([{
347
+ sheetId: ctx.currentSheetId,
348
+ path: ["celldata"],
349
+ value: {
350
+ r: r,
351
+ c: c,
352
+ v: (_h = (_g = d === null || d === void 0 ? void 0 : d[r]) === null || _g === void 0 ? void 0 : _g[c]) !== null && _h !== void 0 ? _h : null
353
+ },
354
+ key: "".concat(r, "_").concat(c),
355
+ type: "update"
356
+ }]);
357
+ }
332
358
  }
333
359
  ctx.luckysheet_select_save = (0, _selection.normalizeSelection)(ctx, [{
334
360
  row: [r, r],
@@ -338,7 +364,7 @@ function replace(ctx, searchText, replaceText, checkModes) {
338
364
  return null;
339
365
  }
340
366
  function replaceAll(ctx, searchText, replaceText, checkModes) {
341
- var _a;
367
+ var _a, _b, _c, _d, _e, _f, _g, _h;
342
368
  var findAndReplace = (0, _locale.locale)(ctx).findAndReplace;
343
369
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
344
370
  if (!allowEdit) {
@@ -362,6 +388,7 @@ function replaceAll(ctx, searchText, replaceText, checkModes) {
362
388
  return findAndReplace.noReplceTip;
363
389
  }
364
390
  var d = flowdata;
391
+ var cellChanges = [];
365
392
  var replaceCount = 0;
366
393
  if (checkModes.wordCheck) {
367
394
  for (var i = 0; i < searchIndexArr.length; i += 1) {
@@ -369,6 +396,19 @@ function replaceAll(ctx, searchText, replaceText, checkModes) {
369
396
  var c = searchIndexArr[i].c;
370
397
  var v = replaceText;
371
398
  (0, _cell.setCellValue)(ctx, r, c, d, v);
399
+ if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
400
+ cellChanges.push({
401
+ sheetId: ctx.currentSheetId,
402
+ path: ["celldata"],
403
+ value: {
404
+ r: r,
405
+ c: c,
406
+ v: (_d = (_c = d === null || d === void 0 ? void 0 : d[r]) === null || _c === void 0 ? void 0 : _c[c]) !== null && _d !== void 0 ? _d : null
407
+ },
408
+ key: "".concat(r, "_").concat(c),
409
+ type: "update"
410
+ });
411
+ }
372
412
  range.push({
373
413
  row: [r, r],
374
414
  column: [c, c]
@@ -387,6 +427,19 @@ function replaceAll(ctx, searchText, replaceText, checkModes) {
387
427
  var c = searchIndexArr[i].c;
388
428
  var v = (0, _format.valueShowEs)(r, c, d).toString().replace(reg, replaceText);
389
429
  (0, _cell.setCellValue)(ctx, r, c, d, v);
430
+ if ((_e = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _e === void 0 ? void 0 : _e.updateCellYdoc) {
431
+ cellChanges.push({
432
+ sheetId: ctx.currentSheetId,
433
+ path: ["celldata"],
434
+ value: {
435
+ r: r,
436
+ c: c,
437
+ v: (_g = (_f = d === null || d === void 0 ? void 0 : d[r]) === null || _f === void 0 ? void 0 : _f[c]) !== null && _g !== void 0 ? _g : null
438
+ },
439
+ key: "".concat(r, "_").concat(c),
440
+ type: "update"
441
+ });
442
+ }
390
443
  range.push({
391
444
  row: [r, r],
392
445
  column: [c, c]
@@ -394,6 +447,9 @@ function replaceAll(ctx, searchText, replaceText, checkModes) {
394
447
  replaceCount += 1;
395
448
  }
396
449
  }
450
+ if (cellChanges.length > 0 && ((_h = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc)) {
451
+ ctx.hooks.updateCellYdoc(cellChanges);
452
+ }
397
453
  ctx.luckysheet_select_save = (0, _selection.normalizeSelection)(ctx, range);
398
454
  var succeedInfo = (0, _utils.replaceHtml)(findAndReplace.successTip, {
399
455
  xlength: replaceCount
@@ -1551,7 +1551,7 @@ function copy(ctx) {
1551
1551
  }
1552
1552
  }
1553
1553
  function deleteSelectedCellText(ctx) {
1554
- var _a, _b, _c, _d, _e;
1554
+ var _a, _b, _c, _d, _e, _f;
1555
1555
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
1556
1556
  if (allowEdit === false || ctx.isFlvReadOnly) {
1557
1557
  return "allowEdit";
@@ -1561,7 +1561,6 @@ function deleteSelectedCellText(ctx) {
1561
1561
  var d = (0, _context.getFlowdata)(ctx);
1562
1562
  if (!d) return "dataNullError";
1563
1563
  var has_PartMC = false;
1564
- var cellChanges = [];
1565
1564
  for (var s = 0; s < selection.length; s += 1) {
1566
1565
  var r1 = selection[s].row[0];
1567
1566
  var r2 = selection[s].row[1];
@@ -1615,20 +1614,22 @@ function deleteSelectedCellText(ctx) {
1615
1614
  if ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.afterUpdateCell) {
1616
1615
  ctx.hooks.afterUpdateCell(r, c, null, d[r][c]);
1617
1616
  }
1618
- changes.push({
1619
- sheetId: ctx.currentSheetId,
1620
- path: ["celldata"],
1621
- value: {
1622
- r: r,
1623
- c: c,
1624
- v: d[r][c]
1625
- },
1626
- key: "".concat(r, "_").concat(c),
1627
- type: "update"
1628
- });
1617
+ if (!((_e = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _e === void 0 ? void 0 : _e.afterUpdateCell)) {
1618
+ changes.push({
1619
+ sheetId: ctx.currentSheetId,
1620
+ path: ["celldata"],
1621
+ value: {
1622
+ r: r,
1623
+ c: c,
1624
+ v: d[r][c]
1625
+ },
1626
+ key: "".concat(r, "_").concat(c),
1627
+ type: "update"
1628
+ });
1629
+ }
1629
1630
  }
1630
1631
  }
1631
- if (changes.length > 0 && ((_e = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _e === void 0 ? void 0 : _e.updateCellYdoc)) {
1632
+ if (changes.length > 0 && ((_f = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _f === void 0 ? void 0 : _f.updateCellYdoc)) {
1632
1633
  ctx.hooks.updateCellYdoc(changes);
1633
1634
  }
1634
1635
  }
@@ -78,6 +78,7 @@ function orderbydata(isAsc, index, data) {
78
78
  };
79
79
  }
80
80
  function sortDataRange(ctx, sheetData, dataRange, index, isAsc, str, edr, stc, edc) {
81
+ var _a, _b;
81
82
  var sortedData = orderbydata(isAsc, index, dataRange).sortedData;
82
83
  for (var r = str; r <= edr; r += 1) {
83
84
  for (var c = stc; c <= edc; c += 1) {
@@ -89,6 +90,26 @@ function sortDataRange(ctx, sheetData, dataRange, index, isAsc, str, edr, stc, e
89
90
  row: [str, edr],
90
91
  column: [stc, edc]
91
92
  }]);
93
+ if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc) {
94
+ var changes = [];
95
+ for (var r = str; r <= edr; r += 1) {
96
+ var row = sheetData[r] || [];
97
+ for (var c = stc; c <= edc; c += 1) {
98
+ changes.push({
99
+ sheetId: ctx.currentSheetId,
100
+ path: ["celldata"],
101
+ value: {
102
+ r: r,
103
+ c: c,
104
+ v: (_b = row === null || row === void 0 ? void 0 : row[c]) !== null && _b !== void 0 ? _b : null
105
+ },
106
+ key: "".concat(r, "_").concat(c),
107
+ type: "update"
108
+ });
109
+ }
110
+ }
111
+ if (changes.length > 0) ctx.hooks.updateCellYdoc(changes);
112
+ }
92
113
  }
93
114
  function sortSelection(ctx, isAsc, colIndex) {
94
115
  var _a;
@@ -203,6 +224,7 @@ function createRowsOrColumnsForSpilledValues(ctx, startRow, startColumn, spillRo
203
224
  }
204
225
  }
205
226
  function spillSortResult(ctx, startRow, startCol, formulaResult, flowdata) {
227
+ var _a, _b;
206
228
  var formulaString = formulaResult === null || formulaResult === void 0 ? void 0 : formulaResult.f;
207
229
  var formulaValue = formulaResult === null || formulaResult === void 0 ? void 0 : formulaResult.v;
208
230
  if (typeof formulaString !== "string" || !(/= *SORT\s*\(/i.test(formulaString) || /= *XLOOKUP\s*\(/i.test(formulaString) || /= *SEQUENCE\s*\(/i.test(formulaString))) return false;
@@ -234,5 +256,27 @@ function spillSortResult(ctx, startRow, startCol, formulaResult, flowdata) {
234
256
  });
235
257
  }
236
258
  }
259
+ if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc) {
260
+ var cellChanges = [];
261
+ for (var r = 0; r < rowCount; r += 1) {
262
+ var rr = startRow + r;
263
+ var row = (sheetData === null || sheetData === void 0 ? void 0 : sheetData[rr]) || [];
264
+ for (var c = 0; c < colCount; c += 1) {
265
+ var cc = startCol + c;
266
+ cellChanges.push({
267
+ sheetId: ctx.currentSheetId,
268
+ path: ["celldata"],
269
+ value: {
270
+ r: rr,
271
+ c: cc,
272
+ v: (_b = row === null || row === void 0 ? void 0 : row[cc]) !== null && _b !== void 0 ? _b : null
273
+ },
274
+ key: "".concat(rr, "_").concat(cc),
275
+ type: "update"
276
+ });
277
+ }
278
+ }
279
+ if (cellChanges.length > 0) ctx.hooks.updateCellYdoc(cellChanges);
280
+ }
237
281
  return true;
238
282
  }
@@ -23,14 +23,35 @@ function getNullData(rlen, clen) {
23
23
  return arr;
24
24
  }
25
25
  function updateMoreCell(r, c, dataMatrix, ctx) {
26
+ var _a;
26
27
  if (ctx.allowEdit === false) return;
27
28
  var flowdata = (0, _context.getFlowdata)(ctx);
29
+ var cellChanges = [];
28
30
  dataMatrix.forEach(function (datas, i) {
29
31
  datas.forEach(function (data, j) {
32
+ var _a, _b, _c;
30
33
  var v = dataMatrix[i][j];
31
34
  (0, _cell.setCellValue)(ctx, r + i, c + j, flowdata, v);
35
+ if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc) {
36
+ var rr = r + i;
37
+ var cc = c + j;
38
+ cellChanges.push({
39
+ sheetId: ctx.currentSheetId,
40
+ path: ["celldata"],
41
+ value: {
42
+ r: rr,
43
+ c: cc,
44
+ v: (_c = (_b = flowdata === null || flowdata === void 0 ? void 0 : flowdata[rr]) === null || _b === void 0 ? void 0 : _b[cc]) !== null && _c !== void 0 ? _c : null
45
+ },
46
+ key: "".concat(rr, "_").concat(cc),
47
+ type: "update"
48
+ });
49
+ }
32
50
  });
33
51
  });
52
+ if (cellChanges.length > 0 && ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc)) {
53
+ ctx.hooks.updateCellYdoc(cellChanges);
54
+ }
34
55
  }
35
56
  function getRegStr(regStr, splitSymbols) {
36
57
  regStr = "";
@@ -429,7 +429,8 @@ function activeFormulaInput(cellInput, fxInput, ctx, row_index, col_index, rowh,
429
429
  });
430
430
  }
431
431
  function backFormulaInput(d, r, c, rowh, columnh, formula, ctx) {
432
- var _a;
432
+ var _a, _b, _c;
433
+ var _d;
433
434
  var f = "=".concat(formula.toUpperCase(), "(").concat((0, _cell.getRangetxt)(ctx, ctx.currentSheetId, {
434
435
  row: rowh,
435
436
  column: columnh
@@ -440,7 +441,20 @@ function backFormulaInput(d, r, c, rowh, columnh, formula, ctx) {
440
441
  f: v[2]
441
442
  };
442
443
  (0, _cell.setCellValue)(ctx, r, c, d, value);
443
- (_a = ctx.formulaCache).execFunctionExist || (_a.execFunctionExist = []);
444
+ if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc) {
445
+ ctx.hooks.updateCellYdoc([{
446
+ sheetId: ctx.currentSheetId,
447
+ path: ["celldata"],
448
+ value: {
449
+ r: r,
450
+ c: c,
451
+ v: (_c = (_b = d === null || d === void 0 ? void 0 : d[r]) === null || _b === void 0 ? void 0 : _b[c]) !== null && _c !== void 0 ? _c : null
452
+ },
453
+ key: "".concat(r, "_").concat(c),
454
+ type: "update"
455
+ }]);
456
+ }
457
+ (_d = ctx.formulaCache).execFunctionExist || (_d.execFunctionExist = []);
444
458
  ctx.formulaCache.execFunctionExist.push({
445
459
  r: r,
446
460
  c: c,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.3.10-yjs-3",
3
+ "version": "1.3.10-yjs-5",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",