@fileverse-dev/fortune-react 1.3.10-yjs-5 → 1.3.10-yjs-7

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.
@@ -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, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
147
+ var _y = (_a = ctxBefore.hooks) !== null && _a !== void 0 ? _a : {},
148
+ updateCellYdoc = _y.updateCellYdoc,
149
+ updateAllCell = _y.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
+ for (var _i = 0, patches_1 = patches; _i < patches_1.length; _i++) {
175
+ var p = patches_1[_i];
176
+ var path = p.path;
177
+ if ((path === null || path === void 0 ? void 0 : path[0]) !== "luckysheetfile") continue;
178
+ var sheetIndex = path[1];
179
+ if (!_.isNumber(sheetIndex)) continue;
180
+ var sheetBefore = (_b = ctxBefore.luckysheetfile) === null || _b === void 0 ? void 0 : _b[sheetIndex];
181
+ var sheetAfter = (_c = ctxAfter.luckysheetfile) === null || _c === void 0 ? void 0 : _c[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) continue;
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
+ continue;
189
+ }
190
+ if (_.isNumber(path[3]) && path.length === 4) {
191
+ var r = path[3];
192
+ var beforeRow = (_e = (_d = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _d === void 0 ? void 0 : _d[r]) !== null && _e !== void 0 ? _e : [];
193
+ var afterRow = (_g = (_f = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _f === void 0 ? void 0 : _f[r]) !== null && _g !== void 0 ? _g : [];
194
+ var max = Math.max((_h = beforeRow.length) !== null && _h !== void 0 ? _h : 0, (_j = afterRow.length) !== null && _j !== void 0 ? _j : 0);
195
+ for (var c = 0; c < max; c += 1) {
196
+ if (!_.isEqual((_k = beforeRow[c]) !== null && _k !== void 0 ? _k : null, (_l = afterRow[c]) !== null && _l !== void 0 ? _l : null)) {
197
+ upsertCell(sheetId, r, c);
198
+ }
199
+ }
200
+ continue;
201
+ }
202
+ if (path.length === 3) {
203
+ var dataAfter = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data;
204
+ var rows = (_m = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter.length) !== null && _m !== void 0 ? _m : 0;
205
+ var cols = rows > 0 ? (_p = (_o = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter[0]) === null || _o === void 0 ? void 0 : _o.length) !== null && _p !== void 0 ? _p : 0 : 0;
206
+ var size = rows * cols;
207
+ if (size > 50000 && updateAllCell) {
208
+ updateAllCell(sheetId);
209
+ continue;
210
+ }
211
+ for (var r = 0; r < rows; r += 1) {
212
+ var beforeRow = (_r = (_q = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _q === void 0 ? void 0 : _q[r]) !== null && _r !== void 0 ? _r : [];
213
+ var afterRow = (_t = (_s = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _s === void 0 ? void 0 : _s[r]) !== null && _t !== void 0 ? _t : [];
214
+ var max = Math.max((_u = beforeRow.length) !== null && _u !== void 0 ? _u : 0, (_v = afterRow.length) !== null && _v !== void 0 ? _v : 0);
215
+ for (var c = 0; c < max; c += 1) {
216
+ if (!_.isEqual((_w = beforeRow[c]) !== null && _w !== void 0 ? _w : null, (_x = afterRow[c]) !== null && _x !== void 0 ? _x : null)) {
217
+ upsertCell(sheetId, r, c);
218
+ }
219
+ }
220
+ }
221
+ }
222
+ continue;
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
@@ -438,6 +535,32 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
438
535
  context.hooks.afterOrderChanges();
439
536
  }
440
537
  }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.order]);
538
+ var sheetColorSig = useMemo(function () {
539
+ var _a;
540
+ return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
541
+ var _a;
542
+ return "".concat(s.id, ":").concat((_a = s.color) !== null && _a !== void 0 ? _a : "");
543
+ }).join("|");
544
+ }, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
545
+ useEffect(function () {
546
+ var _a;
547
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterColorChanges) {
548
+ context.hooks.afterColorChanges();
549
+ }
550
+ }, [sheetColorSig]);
551
+ var sheetHideSig = useMemo(function () {
552
+ var _a;
553
+ return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
554
+ var _a;
555
+ return "".concat(s.id, ":").concat((_a = s.hide) !== null && _a !== void 0 ? _a : 0);
556
+ }).join("|");
557
+ }, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
558
+ useEffect(function () {
559
+ var _a;
560
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterHideChanges) {
561
+ context.hooks.afterHideChanges();
562
+ }
563
+ }, [sheetHideSig]);
441
564
  useEffect(function () {
442
565
  var _a;
443
566
  if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterConfigChanges) {
@@ -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, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
156
+ var _y = (_a = ctxBefore.hooks) !== null && _a !== void 0 ? _a : {},
157
+ updateCellYdoc = _y.updateCellYdoc,
158
+ updateAllCell = _y.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
+ for (var _i = 0, patches_1 = patches; _i < patches_1.length; _i++) {
184
+ var p = patches_1[_i];
185
+ var path = p.path;
186
+ if ((path === null || path === void 0 ? void 0 : path[0]) !== "luckysheetfile") continue;
187
+ var sheetIndex = path[1];
188
+ if (!_lodash.default.isNumber(sheetIndex)) continue;
189
+ var sheetBefore = (_b = ctxBefore.luckysheetfile) === null || _b === void 0 ? void 0 : _b[sheetIndex];
190
+ var sheetAfter = (_c = ctxAfter.luckysheetfile) === null || _c === void 0 ? void 0 : _c[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) continue;
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
+ continue;
198
+ }
199
+ if (_lodash.default.isNumber(path[3]) && path.length === 4) {
200
+ var r = path[3];
201
+ var beforeRow = (_e = (_d = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _d === void 0 ? void 0 : _d[r]) !== null && _e !== void 0 ? _e : [];
202
+ var afterRow = (_g = (_f = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _f === void 0 ? void 0 : _f[r]) !== null && _g !== void 0 ? _g : [];
203
+ var max = Math.max((_h = beforeRow.length) !== null && _h !== void 0 ? _h : 0, (_j = afterRow.length) !== null && _j !== void 0 ? _j : 0);
204
+ for (var c = 0; c < max; c += 1) {
205
+ if (!_lodash.default.isEqual((_k = beforeRow[c]) !== null && _k !== void 0 ? _k : null, (_l = afterRow[c]) !== null && _l !== void 0 ? _l : null)) {
206
+ upsertCell(sheetId, r, c);
207
+ }
208
+ }
209
+ continue;
210
+ }
211
+ if (path.length === 3) {
212
+ var dataAfter = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data;
213
+ var rows = (_m = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter.length) !== null && _m !== void 0 ? _m : 0;
214
+ var cols = rows > 0 ? (_p = (_o = dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter[0]) === null || _o === void 0 ? void 0 : _o.length) !== null && _p !== void 0 ? _p : 0 : 0;
215
+ var size = rows * cols;
216
+ if (size > 50000 && updateAllCell) {
217
+ updateAllCell(sheetId);
218
+ continue;
219
+ }
220
+ for (var r = 0; r < rows; r += 1) {
221
+ var beforeRow = (_r = (_q = sheetBefore === null || sheetBefore === void 0 ? void 0 : sheetBefore.data) === null || _q === void 0 ? void 0 : _q[r]) !== null && _r !== void 0 ? _r : [];
222
+ var afterRow = (_t = (_s = sheetAfter === null || sheetAfter === void 0 ? void 0 : sheetAfter.data) === null || _s === void 0 ? void 0 : _s[r]) !== null && _t !== void 0 ? _t : [];
223
+ var max = Math.max((_u = beforeRow.length) !== null && _u !== void 0 ? _u : 0, (_v = afterRow.length) !== null && _v !== void 0 ? _v : 0);
224
+ for (var c = 0; c < max; c += 1) {
225
+ if (!_lodash.default.isEqual((_w = beforeRow[c]) !== null && _w !== void 0 ? _w : null, (_x = afterRow[c]) !== null && _x !== void 0 ? _x : null)) {
226
+ upsertCell(sheetId, r, c);
227
+ }
228
+ }
229
+ }
230
+ }
231
+ continue;
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
@@ -447,6 +544,32 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
447
544
  context.hooks.afterOrderChanges();
448
545
  }
449
546
  }, [currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.order]);
547
+ var sheetColorSig = (0, _react.useMemo)(function () {
548
+ var _a;
549
+ return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
550
+ var _a;
551
+ return "".concat(s.id, ":").concat((_a = s.color) !== null && _a !== void 0 ? _a : "");
552
+ }).join("|");
553
+ }, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
554
+ (0, _react.useEffect)(function () {
555
+ var _a;
556
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterColorChanges) {
557
+ context.hooks.afterColorChanges();
558
+ }
559
+ }, [sheetColorSig]);
560
+ var sheetHideSig = (0, _react.useMemo)(function () {
561
+ var _a;
562
+ return ((_a = context === null || context === void 0 ? void 0 : context.luckysheetfile) !== null && _a !== void 0 ? _a : []).map(function (s) {
563
+ var _a;
564
+ return "".concat(s.id, ":").concat((_a = s.hide) !== null && _a !== void 0 ? _a : 0);
565
+ }).join("|");
566
+ }, [context === null || context === void 0 ? void 0 : context.luckysheetfile]);
567
+ (0, _react.useEffect)(function () {
568
+ var _a;
569
+ if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterHideChanges) {
570
+ context.hooks.afterHideChanges();
571
+ }
572
+ }, [sheetHideSig]);
450
573
  (0, _react.useEffect)(function () {
451
574
  var _a;
452
575
  if ((_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.afterConfigChanges) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.3.10-yjs-5",
3
+ "version": "1.3.10-yjs-7",
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-yjs-5",
19
+ "@fileverse-dev/fortune-core": "1.3.10-yjs-7",
20
20
  "@fileverse/ui": "5.0.0",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",