@fileverse-dev/fortune-react 1.3.10 → 1.3.11

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.
@@ -211,7 +211,7 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
211
211
  var sheetIdx_1 = getSheetIndex(context, context.currentSheetId);
212
212
  if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
213
213
  setContext(function (draft) {
214
- var _a, _b, _c, _d, _e, _f, _g;
214
+ var _a, _b, _c, _d, _e, _f, _g, _h;
215
215
  var _sheet = draft.luckysheetfile[sheetIdx_1];
216
216
  if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
217
217
  var rows = _sheet.data;
@@ -374,6 +374,30 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
374
374
  }
375
375
  });
376
376
  (_g = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _g === void 0 ? void 0 : _g.call(window, selectedSourceCol, selectedTargetCol, "column", context.currentSheetId, sourceIndex_1, targetIndex);
377
+ var cellChanges = [];
378
+ var affectedColStart = Math.min(sourceIndex_1, targetIndex);
379
+ var affectedColEnd = Math.max(sourceIndex_1, targetIndex) + selectedSourceCol.length - 1;
380
+ var numRows = rows.length;
381
+ for (var r = 0; r < numRows; r += 1) {
382
+ var row = rows[r];
383
+ for (var c = affectedColStart; c <= affectedColEnd; c += 1) {
384
+ var cell = row === null || row === void 0 ? void 0 : row[c];
385
+ cellChanges.push({
386
+ sheetId: draft.currentSheetId,
387
+ path: ["celldata"],
388
+ value: {
389
+ r: r,
390
+ c: c,
391
+ v: cell !== null && cell !== void 0 ? cell : null
392
+ },
393
+ key: "".concat(r, "_").concat(c),
394
+ type: "update"
395
+ });
396
+ }
397
+ }
398
+ if (cellChanges.length > 0 && ((_h = draft.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc)) {
399
+ draft.hooks.updateCellYdoc(cellChanges);
400
+ }
377
401
  var rowLen = (d === null || d === void 0 ? void 0 : d.length) || 0;
378
402
  api.setSelection(draft, [{
379
403
  row: [0, rowLen],
@@ -207,7 +207,7 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
207
207
  var sheetIdx_1 = getSheetIndex(context, context.currentSheetId);
208
208
  if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
209
209
  setContext(function (draft) {
210
- var _a, _b, _c, _d, _e, _f;
210
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
211
211
  var _sheet = draft.luckysheetfile[sheetIdx_1];
212
212
  if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
213
213
  var rows = _sheet.data;
@@ -364,7 +364,31 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
364
364
  }
365
365
  });
366
366
  (_e = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _e === void 0 ? void 0 : _e.call(window, sourceIndex_1, targetIndex, "row", context.currentSheetId);
367
- var colLen = ((_f = d === null || d === void 0 ? void 0 : d[0]) === null || _f === void 0 ? void 0 : _f.length) || 0;
367
+ var cellChanges = [];
368
+ var affectedRowStart = Math.min(sourceIndex_1, targetIndex);
369
+ var affectedRowEnd = Math.max(sourceIndex_1, targetIndex) + selectedSourceRow.length - 1;
370
+ var numCols = (_g = (_f = d === null || d === void 0 ? void 0 : d[0]) === null || _f === void 0 ? void 0 : _f.length) !== null && _g !== void 0 ? _g : 0;
371
+ for (var r = affectedRowStart; r <= affectedRowEnd; r += 1) {
372
+ var row = rows[r];
373
+ for (var c = 0; c < numCols; c += 1) {
374
+ var cell = row === null || row === void 0 ? void 0 : row[c];
375
+ cellChanges.push({
376
+ sheetId: draft.currentSheetId,
377
+ path: ["celldata"],
378
+ value: {
379
+ r: r,
380
+ c: c,
381
+ v: cell !== null && cell !== void 0 ? cell : null
382
+ },
383
+ key: "".concat(r, "_").concat(c),
384
+ type: "update"
385
+ });
386
+ }
387
+ }
388
+ if (cellChanges.length > 0 && ((_h = draft.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc)) {
389
+ draft.hooks.updateCellYdoc(cellChanges);
390
+ }
391
+ var colLen = ((_j = d === null || d === void 0 ? void 0 : d[0]) === null || _j === void 0 ? void 0 : _j.length) || 0;
368
392
  api.setSelection(draft, [{
369
393
  row: [selectedTargetRow[0], selectedTargetRow[selectedTargetRow.length - 1]],
370
394
  column: [0, colLen]
@@ -142,6 +142,101 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
142
142
  onOp(patchToOp(ctx, patches, options, undo));
143
143
  }
144
144
  }, [onOp]);
145
+ var emitYjsFromPatches = useCallback(function (ctxBefore, ctxAfter, patches) {
146
+ var _a;
147
+ var _b = (_a = ctxBefore.hooks) !== null && _a !== void 0 ? _a : {},
148
+ updateCellYdoc = _b.updateCellYdoc,
149
+ updateAllCell = _b.updateAllCell;
150
+ if (!updateCellYdoc) return;
151
+ var mapFields = new Set(["celldata", "calcChain", "dataBlockCalcFunction", "liveQueryList", "dataVerification", "hyperlink", "conditionRules"]);
152
+ var changeMap = new Map();
153
+ var upsert = function upsert(change) {
154
+ var _a, _b, _c;
155
+ var k = "".concat(change.sheetId, ":").concat((_b = (_a = change.path) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "", ":").concat((_c = change.key) !== null && _c !== void 0 ? _c : "");
156
+ changeMap.set(k, change);
157
+ };
158
+ var upsertCell = function upsertCell(sheetId, r, c) {
159
+ var _a, _b, _c;
160
+ var cell = (_c = (_b = (_a = getFlowdata(ctxAfter, sheetId)) === null || _a === void 0 ? void 0 : _a[r]) === null || _b === void 0 ? void 0 : _b[c]) !== null && _c !== void 0 ? _c : null;
161
+ var key = "".concat(r, "_").concat(c);
162
+ upsert({
163
+ sheetId: sheetId,
164
+ path: ["celldata"],
165
+ key: key,
166
+ value: {
167
+ r: r,
168
+ c: c,
169
+ v: cell
170
+ },
171
+ type: cell == null ? "delete" : "update"
172
+ });
173
+ };
174
+ patches.forEach(function (p) {
175
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
176
+ var path = p.path;
177
+ if ((path === null || path === void 0 ? void 0 : path[0]) !== "luckysheetfile") return;
178
+ var sheetIndex = path[1];
179
+ if (!_.isNumber(sheetIndex)) return;
180
+ var sheetBefore = (_a = ctxBefore.luckysheetfile) === null || _a === void 0 ? void 0 : _a[sheetIndex];
181
+ var sheetAfter = (_b = ctxAfter.luckysheetfile) === null || _b === void 0 ? void 0 : _b[sheetIndex];
182
+ var sheetId = (sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.id) || (sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.id);
183
+ if (!sheetId) return;
184
+ var root = path[2];
185
+ if (root === "data") {
186
+ if (_.isNumber(path[3]) && _.isNumber(path[4])) {
187
+ upsertCell(sheetId, path[3], path[4]);
188
+ return;
189
+ }
190
+ if (_.isNumber(path[3]) && path.length === 4) {
191
+ var r = path[3];
192
+ var beforeRow = (_d = (_c = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _c === void 0 ? void 0 : _c[r]) !== null && _d !== void 0 ? _d : [];
193
+ var afterRow = (_f = (_e = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _e === void 0 ? void 0 : _e[r]) !== null && _f !== void 0 ? _f : [];
194
+ var max = Math.max((_g = beforeRow.length) !== null && _g !== void 0 ? _g : 0, (_h = afterRow.length) !== null && _h !== void 0 ? _h : 0);
195
+ for (var c = 0; c < max; c += 1) {
196
+ if (!_.isEqual((_j = beforeRow[c]) !== null && _j !== void 0 ? _j : null, (_k = afterRow[c]) !== null && _k !== void 0 ? _k : null)) {
197
+ upsertCell(sheetId, r, c);
198
+ }
199
+ }
200
+ return;
201
+ }
202
+ if (path.length === 3) {
203
+ var dataAfter = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data;
204
+ var rows = (_l = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter.length) !== null && _l !== void 0 ? _l : 0;
205
+ var cols = rows > 0 ? (_o = (_m = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter[0]) === null || _m === void 0 ? void 0 : _m.length) !== null && _o !== void 0 ? _o : 0 : 0;
206
+ var size = rows * cols;
207
+ if (size > 50000 && updateAllCell) {
208
+ updateAllCell(sheetId);
209
+ return;
210
+ }
211
+ for (var r = 0; r < rows; r += 1) {
212
+ var beforeRow = (_q = (_p = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _p === void 0 ? void 0 : _p[r]) !== null && _q !== void 0 ? _q : [];
213
+ var afterRow = (_s = (_r = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _r === void 0 ? void 0 : _r[r]) !== null && _s !== void 0 ? _s : [];
214
+ var max = Math.max((_t = beforeRow.length) !== null && _t !== void 0 ? _t : 0, (_u = afterRow.length) !== null && _u !== void 0 ? _u : 0);
215
+ for (var c = 0; c < max; c += 1) {
216
+ if (!_.isEqual((_v = beforeRow[c]) !== null && _v !== void 0 ? _v : null, (_w = afterRow[c]) !== null && _w !== void 0 ? _w : null)) {
217
+ upsertCell(sheetId, r, c);
218
+ }
219
+ }
220
+ }
221
+ }
222
+ return;
223
+ }
224
+ if (typeof root === "string" && mapFields.has(root)) {
225
+ var key = path[3];
226
+ if (typeof key === "string") {
227
+ upsert({
228
+ sheetId: sheetId,
229
+ path: [root],
230
+ key: key,
231
+ value: p.value,
232
+ type: p.op === "remove" || p.value == null ? "delete" : "update"
233
+ });
234
+ }
235
+ }
236
+ });
237
+ var changes = Array.from(changeMap.values());
238
+ if (changes.length > 0) updateCellYdoc(changes);
239
+ }, []);
145
240
  function reduceUndoList(ctx, ctxBefore) {
146
241
  var sheetsId = ctx.luckysheetfile.map(function (sheet) {
147
242
  return sheet.id;
@@ -299,6 +394,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
299
394
  delete inversedOptions.addSheet.value.data;
300
395
  }
301
396
  emitOp(newContext, history.inversePatches, inversedOptions, true);
397
+ emitYjsFromPatches(ctx_, newContext, history.inversePatches);
302
398
  var sheetIdxAfterUndo = getSheetIndex(newContext, newContext.currentSheetId);
303
399
  var nw = __assign(__assign({}, newContext), sheetIdxAfterUndo != null && ((_f = newContext.luckysheetfile[sheetIdxAfterUndo]) === null || _f === void 0 ? void 0 : _f.config) != null ? {
304
400
  config: newContext.luckysheetfile[sheetIdxAfterUndo].config
@@ -327,6 +423,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
327
423
  });
328
424
  globalCache.current.undoList.push(history);
329
425
  emitOp(newContext, history.patches, history.options);
426
+ emitYjsFromPatches(ctx_, newContext, history.patches);
330
427
  var sheetIdxAfterRedo = getSheetIndex(newContext, newContext.currentSheetId);
331
428
  var nw = __assign(__assign({}, newContext), sheetIdxAfterRedo != null && ((_a = newContext.luckysheetfile[sheetIdxAfterRedo]) === null || _a === void 0 ? void 0 : _a.config) != null ? {
332
429
  config: newContext.luckysheetfile[sheetIdxAfterRedo].config
@@ -353,18 +450,13 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
353
450
  useEffect(function () {
354
451
  var _a, _b;
355
452
  setContext(function (ctx) {
356
- var _a, _b;
357
453
  var gridData = getFlowdata(ctx);
358
454
  var cellData = api.dataToCelldata(gridData);
359
- var denominatedUsed = false;
360
- for (var _i = 0, cellData_1 = cellData; _i < cellData_1.length; _i++) {
361
- var cell = cellData_1[_i];
455
+ var denominatedUsed = (cellData !== null && cellData !== void 0 ? cellData : []).some(function (cell) {
456
+ var _a, _b;
362
457
  var value = (_b = (_a = cell === null || cell === void 0 ? void 0 : cell.v) === null || _a === void 0 ? void 0 : _a.m) === null || _b === void 0 ? void 0 : _b.toString();
363
- if ((value === null || value === void 0 ? void 0 : value.includes("BTC")) || (value === null || value === void 0 ? void 0 : value.includes("ETH")) || (value === null || value === void 0 ? void 0 : value.includes("SOL"))) {
364
- denominatedUsed = true;
365
- break;
366
- }
367
- }
458
+ return (value === null || value === void 0 ? void 0 : value.includes("BTC")) || (value === null || value === void 0 ? void 0 : value.includes("ETH")) || (value === null || value === void 0 ? void 0 : value.includes("SOL"));
459
+ });
368
460
  var denoWarn = document.getElementById("denomination-warning");
369
461
  var scrollBar = document.getElementsByClassName("luckysheet-scrollbar-x")[0];
370
462
  if (denominatedUsed && denoWarn) {
@@ -438,6 +530,32 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
438
530
  context.hooks.afterOrderChanges();
439
531
  }
440
532
  }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.order]);
533
+ var sheetColorSig = useMemo(function () {
534
+ var _a;
535
+ return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
536
+ var _a;
537
+ return "".concat(s.id, ":").concat((_a = s.color) !== null && _a !== void 0 ? _a : "");
538
+ }).join("|");
539
+ }, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
540
+ useEffect(function () {
541
+ var _a;
542
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterColorChanges) {
543
+ context.hooks.afterColorChanges();
544
+ }
545
+ }, [sheetColorSig]);
546
+ var sheetHideSig = useMemo(function () {
547
+ var _a;
548
+ return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
549
+ var _a;
550
+ return "".concat(s.id, ":").concat((_a = s.hide) !== null && _a !== void 0 ? _a : 0);
551
+ }).join("|");
552
+ }, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
553
+ useEffect(function () {
554
+ var _a;
555
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterHideChanges) {
556
+ context.hooks.afterHideChanges();
557
+ }
558
+ }, [sheetHideSig]);
441
559
  useEffect(function () {
442
560
  var _a;
443
561
  if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterConfigChanges) {
@@ -504,6 +622,18 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
504
622
  context.hooks.conditionFormatChange();
505
623
  }
506
624
  }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.luckysheet_conditionformat_save]);
625
+ useEffect(function () {
626
+ var _a;
627
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.filterSelectChange) {
628
+ context.hooks.filterSelectChange();
629
+ }
630
+ }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.filter_select]);
631
+ useEffect(function () {
632
+ var _a;
633
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.filterChange) {
634
+ context.hooks.filterChange();
635
+ }
636
+ }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.filter]);
507
637
  useEffect(function () {
508
638
  var _a;
509
639
  if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.hyperlinkChange) {
@@ -274,9 +274,12 @@ export function convertCellsToCrypto(_a) {
274
274
  });
275
275
  });
276
276
  setContext(function (ctx) {
277
+ var _a;
277
278
  var d = getFlowdata(ctx);
278
279
  if (!d || !Array.isArray(d)) return;
280
+ var ydocChanges = [];
279
281
  cellUpdates.forEach(function (_a) {
282
+ var _b, _c;
280
283
  var row = _a.row,
281
284
  col = _a.col,
282
285
  baseValue = _a.baseValue,
@@ -296,7 +299,21 @@ export function convertCellsToCrypto(_a) {
296
299
  cellCp.baseCurrency = baseCurrency.toLowerCase();
297
300
  cellCp.baseCurrencyPrice = baseCurrencyPrice;
298
301
  d[row][col] = cellCp;
302
+ ydocChanges.push({
303
+ sheetId: ctx.currentSheetId,
304
+ path: ["celldata"],
305
+ value: {
306
+ r: row,
307
+ c: col,
308
+ v: (_c = (_b = d[row]) === null || _b === void 0 ? void 0 : _b[col]) !== null && _c !== void 0 ? _c : null
309
+ },
310
+ key: "".concat(row, "_").concat(col),
311
+ type: "update"
312
+ });
299
313
  });
314
+ if (ydocChanges.length > 0 && ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc)) {
315
+ ctx.hooks.updateCellYdoc(ydocChanges);
316
+ }
300
317
  });
301
318
  setContext(function (ctx) {
302
319
  api.calculateSheetFromula(ctx, ctx.currentSheetId);
@@ -219,7 +219,7 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
219
219
  var sheetIdx_1 = (0, _fortuneCore.getSheetIndex)(context, context.currentSheetId);
220
220
  if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
221
221
  setContext(function (draft) {
222
- var _a, _b, _c, _d, _e, _f, _g;
222
+ var _a, _b, _c, _d, _e, _f, _g, _h;
223
223
  var _sheet = draft.luckysheetfile[sheetIdx_1];
224
224
  if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
225
225
  var rows = _sheet.data;
@@ -382,6 +382,30 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
382
382
  }
383
383
  });
384
384
  (_g = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _g === void 0 ? void 0 : _g.call(window, selectedSourceCol, selectedTargetCol, "column", context.currentSheetId, sourceIndex_1, targetIndex);
385
+ var cellChanges = [];
386
+ var affectedColStart = Math.min(sourceIndex_1, targetIndex);
387
+ var affectedColEnd = Math.max(sourceIndex_1, targetIndex) + selectedSourceCol.length - 1;
388
+ var numRows = rows.length;
389
+ for (var r = 0; r < numRows; r += 1) {
390
+ var row = rows[r];
391
+ for (var c = affectedColStart; c <= affectedColEnd; c += 1) {
392
+ var cell = row === null || row === void 0 ? void 0 : row[c];
393
+ cellChanges.push({
394
+ sheetId: draft.currentSheetId,
395
+ path: ["celldata"],
396
+ value: {
397
+ r: r,
398
+ c: c,
399
+ v: cell !== null && cell !== void 0 ? cell : null
400
+ },
401
+ key: "".concat(r, "_").concat(c),
402
+ type: "update"
403
+ });
404
+ }
405
+ }
406
+ if (cellChanges.length > 0 && ((_h = draft.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc)) {
407
+ draft.hooks.updateCellYdoc(cellChanges);
408
+ }
385
409
  var rowLen = (d === null || d === void 0 ? void 0 : d.length) || 0;
386
410
  _fortuneCore.api.setSelection(draft, [{
387
411
  row: [0, rowLen],
@@ -214,7 +214,7 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
214
214
  var sheetIdx_1 = (0, _fortuneCore.getSheetIndex)(context, context.currentSheetId);
215
215
  if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
216
216
  setContext(function (draft) {
217
- var _a, _b, _c, _d, _e, _f;
217
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
218
218
  var _sheet = draft.luckysheetfile[sheetIdx_1];
219
219
  if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
220
220
  var rows = _sheet.data;
@@ -371,7 +371,31 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
371
371
  }
372
372
  });
373
373
  (_e = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _e === void 0 ? void 0 : _e.call(window, sourceIndex_1, targetIndex, "row", context.currentSheetId);
374
- var colLen = ((_f = d === null || d === void 0 ? void 0 : d[0]) === null || _f === void 0 ? void 0 : _f.length) || 0;
374
+ var cellChanges = [];
375
+ var affectedRowStart = Math.min(sourceIndex_1, targetIndex);
376
+ var affectedRowEnd = Math.max(sourceIndex_1, targetIndex) + selectedSourceRow.length - 1;
377
+ var numCols = (_g = (_f = d === null || d === void 0 ? void 0 : d[0]) === null || _f === void 0 ? void 0 : _f.length) !== null && _g !== void 0 ? _g : 0;
378
+ for (var r = affectedRowStart; r <= affectedRowEnd; r += 1) {
379
+ var row = rows[r];
380
+ for (var c = 0; c < numCols; c += 1) {
381
+ var cell = row === null || row === void 0 ? void 0 : row[c];
382
+ cellChanges.push({
383
+ sheetId: draft.currentSheetId,
384
+ path: ["celldata"],
385
+ value: {
386
+ r: r,
387
+ c: c,
388
+ v: cell !== null && cell !== void 0 ? cell : null
389
+ },
390
+ key: "".concat(r, "_").concat(c),
391
+ type: "update"
392
+ });
393
+ }
394
+ }
395
+ if (cellChanges.length > 0 && ((_h = draft.hooks) === null || _h === void 0 ? void 0 : _h.updateCellYdoc)) {
396
+ draft.hooks.updateCellYdoc(cellChanges);
397
+ }
398
+ var colLen = ((_j = d === null || d === void 0 ? void 0 : d[0]) === null || _j === void 0 ? void 0 : _j.length) || 0;
375
399
  _fortuneCore.api.setSelection(draft, [{
376
400
  row: [selectedTargetRow[0], selectedTargetRow[selectedTargetRow.length - 1]],
377
401
  column: [0, colLen]
@@ -25,7 +25,7 @@ var _FilterMenu = _interopRequireDefault(require("../ContextMenu/FilterMenu"));
25
25
  var _SheetList = _interopRequireDefault(require("../SheetList"));
26
26
  var _DunePreview = _interopRequireDefault(require("../DunePreview/DunePreview"));
27
27
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
28
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
28
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
29
29
  var __assign = void 0 && (void 0).__assign || function () {
30
30
  __assign = Object.assign || function (t) {
31
31
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -151,6 +151,101 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
151
151
  onOp((0, _fortuneCore.patchToOp)(ctx, patches, options, undo));
152
152
  }
153
153
  }, [onOp]);
154
+ var emitYjsFromPatches = (0, _react.useCallback)(function (ctxBefore, ctxAfter, patches) {
155
+ var _a;
156
+ var _b = (_a = ctxBefore.hooks) !== null && _a !== void 0 ? _a : {},
157
+ updateCellYdoc = _b.updateCellYdoc,
158
+ updateAllCell = _b.updateAllCell;
159
+ if (!updateCellYdoc) return;
160
+ var mapFields = new Set(["celldata", "calcChain", "dataBlockCalcFunction", "liveQueryList", "dataVerification", "hyperlink", "conditionRules"]);
161
+ var changeMap = new Map();
162
+ var upsert = function upsert(change) {
163
+ var _a, _b, _c;
164
+ var k = "".concat(change.sheetId, ":").concat((_b = (_a = change.path) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "", ":").concat((_c = change.key) !== null && _c !== void 0 ? _c : "");
165
+ changeMap.set(k, change);
166
+ };
167
+ var upsertCell = function upsertCell(sheetId, r, c) {
168
+ var _a, _b, _c;
169
+ var cell = (_c = (_b = (_a = (0, _fortuneCore.getFlowdata)(ctxAfter, sheetId)) === null || _a === void 0 ? void 0 : _a[r]) === null || _b === void 0 ? void 0 : _b[c]) !== null && _c !== void 0 ? _c : null;
170
+ var key = "".concat(r, "_").concat(c);
171
+ upsert({
172
+ sheetId: sheetId,
173
+ path: ["celldata"],
174
+ key: key,
175
+ value: {
176
+ r: r,
177
+ c: c,
178
+ v: cell
179
+ },
180
+ type: cell == null ? "delete" : "update"
181
+ });
182
+ };
183
+ patches.forEach(function (p) {
184
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
185
+ var path = p.path;
186
+ if ((path === null || path === void 0 ? void 0 : path[0]) !== "luckysheetfile") return;
187
+ var sheetIndex = path[1];
188
+ if (!_lodash.default.isNumber(sheetIndex)) return;
189
+ var sheetBefore = (_a = ctxBefore.luckysheetfile) === null || _a === void 0 ? void 0 : _a[sheetIndex];
190
+ var sheetAfter = (_b = ctxAfter.luckysheetfile) === null || _b === void 0 ? void 0 : _b[sheetIndex];
191
+ var sheetId = (sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.id) || (sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.id);
192
+ if (!sheetId) return;
193
+ var root = path[2];
194
+ if (root === "data") {
195
+ if (_lodash.default.isNumber(path[3]) && _lodash.default.isNumber(path[4])) {
196
+ upsertCell(sheetId, path[3], path[4]);
197
+ return;
198
+ }
199
+ if (_lodash.default.isNumber(path[3]) && path.length === 4) {
200
+ var r = path[3];
201
+ var beforeRow = (_d = (_c = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _c === void 0 ? void 0 : _c[r]) !== null && _d !== void 0 ? _d : [];
202
+ var afterRow = (_f = (_e = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _e === void 0 ? void 0 : _e[r]) !== null && _f !== void 0 ? _f : [];
203
+ var max = Math.max((_g = beforeRow.length) !== null && _g !== void 0 ? _g : 0, (_h = afterRow.length) !== null && _h !== void 0 ? _h : 0);
204
+ for (var c = 0; c < max; c += 1) {
205
+ if (!_lodash.default.isEqual((_j = beforeRow[c]) !== null && _j !== void 0 ? _j : null, (_k = afterRow[c]) !== null && _k !== void 0 ? _k : null)) {
206
+ upsertCell(sheetId, r, c);
207
+ }
208
+ }
209
+ return;
210
+ }
211
+ if (path.length === 3) {
212
+ var dataAfter = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data;
213
+ var rows = (_l = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter.length) !== null && _l !== void 0 ? _l : 0;
214
+ var cols = rows > 0 ? (_o = (_m = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter[0]) === null || _m === void 0 ? void 0 : _m.length) !== null && _o !== void 0 ? _o : 0 : 0;
215
+ var size = rows * cols;
216
+ if (size > 50000 && updateAllCell) {
217
+ updateAllCell(sheetId);
218
+ return;
219
+ }
220
+ for (var r = 0; r < rows; r += 1) {
221
+ var beforeRow = (_q = (_p = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _p === void 0 ? void 0 : _p[r]) !== null && _q !== void 0 ? _q : [];
222
+ var afterRow = (_s = (_r = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _r === void 0 ? void 0 : _r[r]) !== null && _s !== void 0 ? _s : [];
223
+ var max = Math.max((_t = beforeRow.length) !== null && _t !== void 0 ? _t : 0, (_u = afterRow.length) !== null && _u !== void 0 ? _u : 0);
224
+ for (var c = 0; c < max; c += 1) {
225
+ if (!_lodash.default.isEqual((_v = beforeRow[c]) !== null && _v !== void 0 ? _v : null, (_w = afterRow[c]) !== null && _w !== void 0 ? _w : null)) {
226
+ upsertCell(sheetId, r, c);
227
+ }
228
+ }
229
+ }
230
+ }
231
+ return;
232
+ }
233
+ if (typeof root === "string" && mapFields.has(root)) {
234
+ var key = path[3];
235
+ if (typeof key === "string") {
236
+ upsert({
237
+ sheetId: sheetId,
238
+ path: [root],
239
+ key: key,
240
+ value: p.value,
241
+ type: p.op === "remove" || p.value == null ? "delete" : "update"
242
+ });
243
+ }
244
+ }
245
+ });
246
+ var changes = Array.from(changeMap.values());
247
+ if (changes.length > 0) updateCellYdoc(changes);
248
+ }, []);
154
249
  function reduceUndoList(ctx, ctxBefore) {
155
250
  var sheetsId = ctx.luckysheetfile.map(function (sheet) {
156
251
  return sheet.id;
@@ -308,6 +403,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
308
403
  delete inversedOptions.addSheet.value.data;
309
404
  }
310
405
  emitOp(newContext, history.inversePatches, inversedOptions, true);
406
+ emitYjsFromPatches(ctx_, newContext, history.inversePatches);
311
407
  var sheetIdxAfterUndo = (0, _fortuneCore.getSheetIndex)(newContext, newContext.currentSheetId);
312
408
  var nw = __assign(__assign({}, newContext), sheetIdxAfterUndo != null && ((_f = newContext.luckysheetfile[sheetIdxAfterUndo]) === null || _f === void 0 ? void 0 : _f.config) != null ? {
313
409
  config: newContext.luckysheetfile[sheetIdxAfterUndo].config
@@ -336,6 +432,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
336
432
  });
337
433
  globalCache.current.undoList.push(history);
338
434
  emitOp(newContext, history.patches, history.options);
435
+ emitYjsFromPatches(ctx_, newContext, history.patches);
339
436
  var sheetIdxAfterRedo = (0, _fortuneCore.getSheetIndex)(newContext, newContext.currentSheetId);
340
437
  var nw = __assign(__assign({}, newContext), sheetIdxAfterRedo != null && ((_a = newContext.luckysheetfile[sheetIdxAfterRedo]) === null || _a === void 0 ? void 0 : _a.config) != null ? {
341
438
  config: newContext.luckysheetfile[sheetIdxAfterRedo].config
@@ -362,18 +459,13 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
362
459
  (0, _react.useEffect)(function () {
363
460
  var _a, _b;
364
461
  setContext(function (ctx) {
365
- var _a, _b;
366
462
  var gridData = (0, _fortuneCore.getFlowdata)(ctx);
367
463
  var cellData = _fortuneCore.api.dataToCelldata(gridData);
368
- var denominatedUsed = false;
369
- for (var _i = 0, cellData_1 = cellData; _i < cellData_1.length; _i++) {
370
- var cell = cellData_1[_i];
464
+ var denominatedUsed = (cellData !== null && cellData !== void 0 ? cellData : []).some(function (cell) {
465
+ var _a, _b;
371
466
  var value = (_b = (_a = cell === null || cell === void 0 ? void 0 : cell.v) === null || _a === void 0 ? void 0 : _a.m) === null || _b === void 0 ? void 0 : _b.toString();
372
- if ((value === null || value === void 0 ? void 0 : value.includes("BTC")) || (value === null || value === void 0 ? void 0 : value.includes("ETH")) || (value === null || value === void 0 ? void 0 : value.includes("SOL"))) {
373
- denominatedUsed = true;
374
- break;
375
- }
376
- }
467
+ return (value === null || value === void 0 ? void 0 : value.includes("BTC")) || (value === null || value === void 0 ? void 0 : value.includes("ETH")) || (value === null || value === void 0 ? void 0 : value.includes("SOL"));
468
+ });
377
469
  var denoWarn = document.getElementById("denomination-warning");
378
470
  var scrollBar = document.getElementsByClassName("luckysheet-scrollbar-x")[0];
379
471
  if (denominatedUsed && denoWarn) {
@@ -447,6 +539,32 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
447
539
  context.hooks.afterOrderChanges();
448
540
  }
449
541
  }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.order]);
542
+ var sheetColorSig = (0, _react.useMemo)(function () {
543
+ var _a;
544
+ return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
545
+ var _a;
546
+ return "".concat(s.id, ":").concat((_a = s.color) !== null && _a !== void 0 ? _a : "");
547
+ }).join("|");
548
+ }, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
549
+ (0, _react.useEffect)(function () {
550
+ var _a;
551
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterColorChanges) {
552
+ context.hooks.afterColorChanges();
553
+ }
554
+ }, [sheetColorSig]);
555
+ var sheetHideSig = (0, _react.useMemo)(function () {
556
+ var _a;
557
+ return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
558
+ var _a;
559
+ return "".concat(s.id, ":").concat((_a = s.hide) !== null && _a !== void 0 ? _a : 0);
560
+ }).join("|");
561
+ }, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
562
+ (0, _react.useEffect)(function () {
563
+ var _a;
564
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterHideChanges) {
565
+ context.hooks.afterHideChanges();
566
+ }
567
+ }, [sheetHideSig]);
450
568
  (0, _react.useEffect)(function () {
451
569
  var _a;
452
570
  if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterConfigChanges) {
@@ -513,6 +631,18 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
513
631
  context.hooks.conditionFormatChange();
514
632
  }
515
633
  }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.luckysheet_conditionformat_save]);
634
+ (0, _react.useEffect)(function () {
635
+ var _a;
636
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.filterSelectChange) {
637
+ context.hooks.filterSelectChange();
638
+ }
639
+ }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.filter_select]);
640
+ (0, _react.useEffect)(function () {
641
+ var _a;
642
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.filterChange) {
643
+ context.hooks.filterChange();
644
+ }
645
+ }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.filter]);
516
646
  (0, _react.useEffect)(function () {
517
647
  var _a;
518
648
  if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.hyperlinkChange) {
@@ -281,9 +281,12 @@ function convertCellsToCrypto(_a) {
281
281
  });
282
282
  });
283
283
  setContext(function (ctx) {
284
+ var _a;
284
285
  var d = (0, _fortuneCore.getFlowdata)(ctx);
285
286
  if (!d || !Array.isArray(d)) return;
287
+ var ydocChanges = [];
286
288
  cellUpdates.forEach(function (_a) {
289
+ var _b, _c;
287
290
  var row = _a.row,
288
291
  col = _a.col,
289
292
  baseValue = _a.baseValue,
@@ -303,7 +306,21 @@ function convertCellsToCrypto(_a) {
303
306
  cellCp.baseCurrency = baseCurrency.toLowerCase();
304
307
  cellCp.baseCurrencyPrice = baseCurrencyPrice;
305
308
  d[row][col] = cellCp;
309
+ ydocChanges.push({
310
+ sheetId: ctx.currentSheetId,
311
+ path: ["celldata"],
312
+ value: {
313
+ r: row,
314
+ c: col,
315
+ v: (_c = (_b = d[row]) === null || _b === void 0 ? void 0 : _b[col]) !== null && _c !== void 0 ? _c : null
316
+ },
317
+ key: "".concat(row, "_").concat(col),
318
+ type: "update"
319
+ });
306
320
  });
321
+ if (ydocChanges.length > 0 && ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc)) {
322
+ ctx.hooks.updateCellYdoc(ydocChanges);
323
+ }
307
324
  });
308
325
  setContext(function (ctx) {
309
326
  _fortuneCore.api.calculateSheetFromula(ctx, ctx.currentSheetId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.3.10",
3
+ "version": "1.3.11",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "module": "es/index.js",
@@ -16,7 +16,7 @@
16
16
  "tsc": "tsc"
17
17
  },
18
18
  "dependencies": {
19
- "@fileverse-dev/fortune-core": "1.3.10",
19
+ "@fileverse-dev/fortune-core": "1.3.11",
20
20
  "@fileverse/ui": "5.0.0",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",