@rowsncolumns/y-spreadsheet 15.1.0 → 16.1.0-beta.0

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.
Files changed (48) hide show
  1. package/Readme.md +4 -1
  2. package/dist/cjs/helpers-v5.d.ts +64 -0
  3. package/dist/cjs/helpers-v5.d.ts.map +1 -0
  4. package/dist/cjs/helpers-v5.js +970 -0
  5. package/dist/cjs/helpers.d.ts +7 -6
  6. package/dist/cjs/helpers.d.ts.map +1 -1
  7. package/dist/cjs/helpers.js +17 -11
  8. package/dist/cjs/index.d.ts +1 -0
  9. package/dist/cjs/index.d.ts.map +1 -1
  10. package/dist/cjs/index.js +1 -0
  11. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  12. package/dist/cjs/types.d.ts +8 -6
  13. package/dist/cjs/types.d.ts.map +1 -1
  14. package/dist/cjs/use-yspreadsheet-v2.d.ts +9 -6
  15. package/dist/cjs/use-yspreadsheet-v2.d.ts.map +1 -1
  16. package/dist/cjs/use-yspreadsheet-v2.js +131 -39
  17. package/dist/cjs/use-yspreadsheet.d.ts +7 -3
  18. package/dist/cjs/use-yspreadsheet.d.ts.map +1 -1
  19. package/dist/cjs/use-yspreadsheet.js +5 -4
  20. package/dist/cjs/vitest.config.d.ts.map +1 -1
  21. package/dist/cjs/vitest.config.js +1 -0
  22. package/dist/cjs/yjs-runtime.d.ts +6 -0
  23. package/dist/cjs/yjs-runtime.d.ts.map +1 -0
  24. package/dist/cjs/yjs-runtime.js +25 -0
  25. package/dist/esm/helpers-v5.d.ts +64 -0
  26. package/dist/esm/helpers-v5.d.ts.map +1 -0
  27. package/dist/esm/helpers-v5.js +733 -0
  28. package/dist/esm/helpers.d.ts +7 -6
  29. package/dist/esm/helpers.d.ts.map +1 -1
  30. package/dist/esm/helpers.js +17 -7
  31. package/dist/esm/index.d.ts +1 -0
  32. package/dist/esm/index.d.ts.map +1 -1
  33. package/dist/esm/index.js +1 -0
  34. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  35. package/dist/esm/types.d.ts +8 -6
  36. package/dist/esm/types.d.ts.map +1 -1
  37. package/dist/esm/use-yspreadsheet-v2.d.ts +9 -6
  38. package/dist/esm/use-yspreadsheet-v2.d.ts.map +1 -1
  39. package/dist/esm/use-yspreadsheet-v2.js +89 -13
  40. package/dist/esm/use-yspreadsheet.d.ts +7 -3
  41. package/dist/esm/use-yspreadsheet.d.ts.map +1 -1
  42. package/dist/esm/use-yspreadsheet.js +3 -2
  43. package/dist/esm/vitest.config.d.ts.map +1 -1
  44. package/dist/esm/vitest.config.js +1 -0
  45. package/dist/esm/yjs-runtime.d.ts +6 -0
  46. package/dist/esm/yjs-runtime.d.ts.map +1 -0
  47. package/dist/esm/yjs-runtime.js +20 -0
  48. package/package.json +7 -1
@@ -7,8 +7,8 @@ var utils_1 = require("@rowsncolumns/utils");
7
7
  var ui_1 = require("@rowsncolumns/ui");
8
8
  var react_1 = require("react");
9
9
  var react_dom_1 = require("react-dom");
10
- var Y = tslib_1.__importStar(require("yjs"));
11
10
  var helpers_1 = require("./helpers");
11
+ var yjs_runtime_1 = require("./yjs-runtime");
12
12
  /**
13
13
  * Convert Y.js events to SheetDataEvent format for incremental processing
14
14
  */
@@ -57,10 +57,11 @@ var observables_1 = require("./observables");
57
57
  // Add a single null entry to the YSheetData
58
58
  var origin = "local";
59
59
  var useYSpreadsheetV2 = function (_a) {
60
- var onChangeSheetData = _a.onChangeSheetData, onChangeSheets = _a.onChangeSheets, onChangeTables = _a.onChangeTables, onChangeCharts = _a.onChangeCharts, onChangeEmbeds = _a.onChangeEmbeds, onChangeConditionalFormats = _a.onChangeConditionalFormats, onChangeDataValidations = _a.onChangeDataValidations, onChangeCitations = _a.onChangeCitations, onAfterBroadcastPatch = _a.onAfterBroadcastPatch, recalcCellsMaxEntries = _a.recalcCellsMaxEntries, onChangeNamedRanges = _a.onChangeNamedRanges, onChangeProtectedRanges = _a.onChangeProtectedRanges, onChangePivotTables = _a.onChangePivotTables, enqueueCalculation = _a.enqueueCalculation, enqueueGraphOperation = _a.enqueueGraphOperation, reevaluateDerivationsForCells = _a.reevaluateDerivationsForCells, onChangeCellXfs = _a.onChangeCellXfs, onChangeSharedStrings = _a.onChangeSharedStrings, calculateNow = _a.calculateNow, onChangeActiveSheet = _a.onChangeActiveSheet, clientOnlyFunctionPattern = _a.clientOnlyFunctionPattern, initialSheets = _a.initialSheets, awarenessScopeId = _a.awarenessScopeId, _b = _a.canWrite, canWrite = _b === void 0 ? true : _b, userId = _a.userId, title = _a.title, sheetId = _a.sheetId, activeCell = _a.activeCell, kind = _a.kind, agentInitiator = _a.agentInitiator, selections = _a.selections, doc = _a.doc, provider = _a.provider, _c = _a.yjs, yjs = _c === void 0 ? Y : _c, _d = _a.useV3, useV3 = _d === void 0 ? false : _d, _e = _a.sheetDataVersion, sheetDataVersion = _e === void 0 ? "v2" : _e, onMigrationComplete = _a.onMigrationComplete, _f = _a.deleteV2AfterMigration, deleteV2AfterMigration = _f === void 0 ? false : _f, _g = _a.skipInitialSync, skipInitialSync = _g === void 0 ? false : _g, _h = _a.supportLegacySharedStringsArray, supportLegacySharedStringsArray = _h === void 0 ? false : _h;
61
- var _j = tslib_1.__read((0, react_1.useState)(false), 2), synced = _j[0], setSynced = _j[1];
62
- var _k = tslib_1.__read((0, react_1.useState)([]), 2), users = _k[0], setUsers = _k[1];
63
- var _l = tslib_1.__read((0, react_1.useState)(false), 2), isLeader = _l[0], setIsLeader = _l[1];
60
+ var onChangeSheetData = _a.onChangeSheetData, onChangeSheets = _a.onChangeSheets, onChangeTables = _a.onChangeTables, onChangeCharts = _a.onChangeCharts, onChangeEmbeds = _a.onChangeEmbeds, onChangeConditionalFormats = _a.onChangeConditionalFormats, onChangeDataValidations = _a.onChangeDataValidations, onChangeCitations = _a.onChangeCitations, onAfterBroadcastPatch = _a.onAfterBroadcastPatch, recalcCellsMaxEntries = _a.recalcCellsMaxEntries, onChangeNamedRanges = _a.onChangeNamedRanges, onChangeProtectedRanges = _a.onChangeProtectedRanges, onChangePivotTables = _a.onChangePivotTables, enqueueCalculation = _a.enqueueCalculation, enqueueGraphOperation = _a.enqueueGraphOperation, reevaluateDerivationsForCells = _a.reevaluateDerivationsForCells, onChangeCellXfs = _a.onChangeCellXfs, onChangeSharedStrings = _a.onChangeSharedStrings, calculateNow = _a.calculateNow, onChangeActiveSheet = _a.onChangeActiveSheet, clientOnlyFunctionPattern = _a.clientOnlyFunctionPattern, initialSheets = _a.initialSheets, awarenessScopeId = _a.awarenessScopeId, _b = _a.canWrite, canWrite = _b === void 0 ? true : _b, userId = _a.userId, title = _a.title, sheetId = _a.sheetId, activeCell = _a.activeCell, kind = _a.kind, agentInitiator = _a.agentInitiator, selections = _a.selections, doc = _a.doc, provider = _a.provider, yjsRuntime = _a.yjs, _c = _a.useV3, useV3 = _c === void 0 ? false : _c, _d = _a.sheetDataVersion, sheetDataVersion = _d === void 0 ? "v2" : _d, onMigrationComplete = _a.onMigrationComplete, _e = _a.deleteV2AfterMigration, deleteV2AfterMigration = _e === void 0 ? false : _e, _f = _a.skipInitialSync, skipInitialSync = _f === void 0 ? false : _f, _g = _a.supportLegacySharedStringsArray, supportLegacySharedStringsArray = _g === void 0 ? false : _g;
61
+ var yjs = (0, yjs_runtime_1.resolveYjsRuntime)(yjsRuntime);
62
+ var _h = tslib_1.__read((0, react_1.useState)(false), 2), synced = _h[0], setSynced = _h[1];
63
+ var _j = tslib_1.__read((0, react_1.useState)([]), 2), users = _j[0], setUsers = _j[1];
64
+ var _k = tslib_1.__read((0, react_1.useState)(false), 2), isLeader = _k[0], setIsLeader = _k[1];
64
65
  var isLeaderRef = (0, react_1.useRef)(false);
65
66
  var resolvedAwarenessScopeId = awarenessScopeId;
66
67
  // Listen to awareness
@@ -109,6 +110,18 @@ var useYSpreadsheetV2 = function (_a) {
109
110
  var ySheetDataV3 = (0, react_1.useMemo)(function () { return doc.getMap("sheetDataV3"); }, [doc]);
110
111
  // Doc metadata - used as fallback for version when prop is undefined
111
112
  var yDocMeta = (0, react_1.useMemo)(function () { return doc.getMap("docMeta"); }, [doc]);
113
+ // V5: the engine marks the doc in `docMeta`; read live (the marker may arrive with a sync)
114
+ var isV5Doc = (0, react_1.useCallback)(function () {
115
+ return sheetDataVersion === "v5" || yDocMeta.get("sheetDataVersion") === "v5";
116
+ }, [sheetDataVersion, yDocMeta]);
117
+ // V5: the composed style plane, folded on a full read and on a remote style
118
+ // change, updated in place by this hook's own writes
119
+ var stylesV5Ref = (0, react_1.useRef)(null);
120
+ var stylesV5 = (0, react_1.useCallback)(function () { var _a; return ((_a = stylesV5Ref.current) !== null && _a !== void 0 ? _a : (stylesV5Ref.current = (0, helpers_1.readStyleOverlayV5)(doc))); }, [doc]);
121
+ var readSheetDataV5 = (0, react_1.useCallback)(function () {
122
+ stylesV5Ref.current = (0, helpers_1.readStyleOverlayV5)(doc);
123
+ return (0, helpers_1.sheetDataV5ToV2)(doc, stylesV5Ref.current);
124
+ }, [doc]);
112
125
  var yDisableRecalc = (0, react_1.useMemo)(function () { return doc.getMap("disableRecalc"); }, [doc]);
113
126
  // Recalc cells
114
127
  var yRecalcCells = (0, react_1.useMemo)(function () { return doc.getArray("recalcCells"); }, [doc]);
@@ -260,6 +273,7 @@ var useYSpreadsheetV2 = function (_a) {
260
273
  // Trigger cell recalcs
261
274
  var syncRecalcCells = (0, react_1.useCallback)(function (recalcCells, origin) {
262
275
  var e_2, _a;
276
+ var readV5 = isV5Doc() ? (0, helpers_1.createCellReaderV5)(doc, stylesV5()) : null;
263
277
  try {
264
278
  for (var recalcCells_1 = tslib_1.__values(recalcCells), recalcCells_1_1 = recalcCells_1.next(); !recalcCells_1_1.done; recalcCells_1_1 = recalcCells_1.next()) {
265
279
  var _b = tslib_1.__read(recalcCells_1_1.value, 3), _1 = _b[0], position = _b[1], source = _b[2];
@@ -267,9 +281,11 @@ var useYSpreadsheetV2 = function (_a) {
267
281
  var isAgent = source === "agent"; // Agent already does the calculation
268
282
  // Read directly from Y.js to avoid race condition where recalcCells
269
283
  // observer fires before sheetData observer has updated React state
270
- var formulaValue = useV3
271
- ? getUserEnteredValueFromYDocV3(ySheetDataV3, position.sheetId, position.rowIndex, position.columnIndex)
272
- : getUserEnteredValueFromYDoc(ySheetDataV2, position.sheetId, position.rowIndex, position.columnIndex);
284
+ var formulaValue = readV5
285
+ ? (0, utils_1.getExtendedValueFormula)((0, utils_1.getCellUserEnteredValue)(readV5(position.sheetId, position.rowIndex, position.columnIndex)))
286
+ : useV3
287
+ ? getUserEnteredValueFromYDocV3(ySheetDataV3, position.sheetId, position.rowIndex, position.columnIndex)
288
+ : getUserEnteredValueFromYDoc(ySheetDataV2, position.sheetId, position.rowIndex, position.columnIndex);
273
289
  // Was this from a changeBatch event in the back-end?
274
290
  // To support client functions to run only
275
291
  var isChangeBatch = position.force && isAgent;
@@ -337,6 +353,9 @@ var useYSpreadsheetV2 = function (_a) {
337
353
  ySheetDataV3,
338
354
  useV3,
339
355
  reevaluateDerivationsForCells,
356
+ isV5Doc,
357
+ doc,
358
+ stylesV5,
340
359
  ]);
341
360
  // Setup initial sync
342
361
  var setupInitialSync = (0, react_1.useCallback)(function () {
@@ -393,8 +412,12 @@ var useYSpreadsheetV2 = function (_a) {
393
412
  }
394
413
  finally { if (e_3) throw e_3.error; }
395
414
  }
396
- // Load sheet data based on V2 or V3 mode
397
- if (useV3) {
415
+ // Load sheet data based on V2, V3 or V5 mode
416
+ if (isV5Doc()) {
417
+ // V5: hot plane keyed by line ids; never migrated to V3
418
+ onChangeSheetData === null || onChangeSheetData === void 0 ? void 0 : onChangeSheetData(readSheetDataV5());
419
+ }
420
+ else if (useV3) {
398
421
  // Check if we need to migrate from V2 to V3
399
422
  // Use prop if provided, otherwise fall back to yDocMeta for backwards compatibility
400
423
  var resolvedVersion = sheetDataVersion !== null && sheetDataVersion !== void 0 ? sheetDataVersion : yDocMeta.get("sheetDataVersion");
@@ -473,6 +496,8 @@ var useYSpreadsheetV2 = function (_a) {
473
496
  sheetDataVersion,
474
497
  onMigrationComplete,
475
498
  deleteV2AfterMigration,
499
+ isV5Doc,
500
+ readSheetDataV5,
476
501
  ]);
477
502
  /**
478
503
  * Replay the backend/agent recalc backlog into the local graph — and, on
@@ -615,6 +640,58 @@ var useYSpreadsheetV2 = function (_a) {
615
640
  ySheetDataV3.unobserve(callback);
616
641
  };
617
642
  }, [onChangeSheetData, ySheetDataV3, useV3]);
643
+ // Only for sheet Data (V5 docs): `rncCells`, `rncNotes`, the style planes and
644
+ // every sheet's id arrays. A change of an id array, a style plane (or of
645
+ // `docMeta`): full re-read; a cell or note change alone is applied
646
+ // incrementally. Roots are matched by name in `doc.share`, so a root a peer
647
+ // created after this effect ran is seen too.
648
+ (0, ui_1.useIsomorphicLayoutEffect)(function () {
649
+ var callback = function (transaction) {
650
+ var e_6, _a;
651
+ if (transaction.origin === "local" || !isV5Doc())
652
+ return;
653
+ var full = false;
654
+ var cellKeys = [];
655
+ try {
656
+ for (var _b = tslib_1.__values(doc.share), _c = _b.next(); !_c.done; _c = _b.next()) {
657
+ var _d = tslib_1.__read(_c.value, 2), name_1 = _d[0], type = _d[1];
658
+ var changed = transaction.changed.get(type);
659
+ if (!changed)
660
+ continue;
661
+ if (name_1 === "rncCells" || name_1 === "rncNotes") {
662
+ changed.forEach(function (key) { return key !== null && cellKeys.push(key); });
663
+ }
664
+ else if (name_1 === "docMeta" ||
665
+ name_1 === "rncCellStylesLog" ||
666
+ name_1 === "rncCellStyles" ||
667
+ name_1.startsWith("rncRowIds:") ||
668
+ name_1.startsWith("rncColIds:")) {
669
+ full = true;
670
+ }
671
+ }
672
+ }
673
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
674
+ finally {
675
+ try {
676
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
677
+ }
678
+ finally { if (e_6) throw e_6.error; }
679
+ }
680
+ if (full) {
681
+ onChangeSheetData(readSheetDataV5());
682
+ }
683
+ else if (cellKeys.length) {
684
+ onChangeSheetData(function (prevSheetData) {
685
+ var _a;
686
+ return (_a = (0, helpers_1.processSheetDataChangesV5)(cellKeys, prevSheetData, doc, stylesV5())) !== null && _a !== void 0 ? _a : prevSheetData;
687
+ });
688
+ }
689
+ };
690
+ doc.on("afterTransaction", callback);
691
+ return function () {
692
+ doc.off("afterTransaction", callback);
693
+ };
694
+ }, [doc, onChangeSheetData, isV5Doc, readSheetDataV5, stylesV5]);
618
695
  // CellXfs
619
696
  (0, ui_1.useIsomorphicLayoutEffect)(function () {
620
697
  // Subscribe to sheet data
@@ -632,16 +709,16 @@ var useYSpreadsheetV2 = function (_a) {
632
709
  }, [onChangeCellXfs, yCellXfs]);
633
710
  // All others
634
711
  (0, ui_1.useIsomorphicLayoutEffect)(function () {
635
- var e_6, _a;
712
+ var e_7, _a;
636
713
  var subs = [];
637
714
  var _loop_1 = function (mappingKey, ydoc, callback) {
638
715
  // Only observe Arrays (shared strings Map is handled separately if needed)
639
716
  if (ydoc instanceof yjs.Array) {
640
717
  var subscription = (0, observables_1.createDeepObservable)(ydoc).subscribe(function (events) {
641
- var e_7, _a;
718
+ var e_8, _a;
642
719
  var _b;
643
720
  try {
644
- for (var events_1 = (e_7 = void 0, tslib_1.__values(events)), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) {
721
+ for (var events_1 = (e_8 = void 0, tslib_1.__values(events)), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) {
645
722
  var event_1 = events_1_1.value;
646
723
  if (event_1.transaction.origin !== "local") {
647
724
  var json = ydoc.toJSON();
@@ -654,12 +731,12 @@ var useYSpreadsheetV2 = function (_a) {
654
731
  }
655
732
  }
656
733
  }
657
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
734
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
658
735
  finally {
659
736
  try {
660
737
  if (events_1_1 && !events_1_1.done && (_a = events_1.return)) _a.call(events_1);
661
738
  }
662
- finally { if (e_7) throw e_7.error; }
739
+ finally { if (e_8) throw e_8.error; }
663
740
  }
664
741
  });
665
742
  subs.push(subscription);
@@ -685,12 +762,12 @@ var useYSpreadsheetV2 = function (_a) {
685
762
  _loop_1(mappingKey, ydoc, callback);
686
763
  }
687
764
  }
688
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
765
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
689
766
  finally {
690
767
  try {
691
768
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
692
769
  }
693
- finally { if (e_6) throw e_6.error; }
770
+ finally { if (e_7) throw e_7.error; }
694
771
  }
695
772
  return function () {
696
773
  subs.forEach(function (sub) { return sub.unsubscribe(); });
@@ -720,7 +797,7 @@ var useYSpreadsheetV2 = function (_a) {
720
797
  // Skip the first recalc cells change
721
798
  var sub = (0, observables_1.createObservable)(yRecalcCells).subscribe(onRecalcCellsChange);
722
799
  return function () {
723
- var e_8, _a;
800
+ var e_9, _a;
724
801
  sub.unsubscribe();
725
802
  try {
726
803
  for (var pending_1 = tslib_1.__values(pending), pending_1_1 = pending_1.next(); !pending_1_1.done; pending_1_1 = pending_1.next()) {
@@ -728,18 +805,18 @@ var useYSpreadsheetV2 = function (_a) {
728
805
  clearTimeout(timer);
729
806
  }
730
807
  }
731
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
808
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
732
809
  finally {
733
810
  try {
734
811
  if (pending_1_1 && !pending_1_1.done && (_a = pending_1.return)) _a.call(pending_1);
735
812
  }
736
- finally { if (e_8) throw e_8.error; }
813
+ finally { if (e_9) throw e_9.error; }
737
814
  }
738
815
  };
739
816
  }, [syncRecalcCells, recalcCellsMaxEntries, synced, yRecalcCells]);
740
817
  // Broadcast patch
741
818
  var onBroadcastPatch = (0, react_1.useCallback)(function (patches) {
742
- var e_9, _a, e_10, _b;
819
+ var e_10, _a, e_11, _b;
743
820
  var _c;
744
821
  // Ignore push flag
745
822
  var disableRecalc = Boolean(patches.find(function (_a) {
@@ -775,12 +852,12 @@ var useYSpreadsheetV2 = function (_a) {
775
852
  }
776
853
  }
777
854
  }
778
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
855
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
779
856
  finally {
780
857
  try {
781
858
  if (patches_1_1 && !patches_1_1.done && (_a = patches_1.return)) _a.call(patches_1);
782
859
  }
783
- finally { if (e_9) throw e_9.error; }
860
+ finally { if (e_10) throw e_10.error; }
784
861
  }
785
862
  // Containment for this non-leader write path: an error may only
786
863
  // fill a cell with no effective value (the blank-after-reload case)
@@ -791,13 +868,19 @@ var useYSpreadsheetV2 = function (_a) {
791
868
  // write merges ONLY the error effective value into the existing doc
792
869
  // cell, preserving every other persisted field.
793
870
  var persistableErrorCellPatches_1 = [];
871
+ var isV5_1 = isV5Doc();
872
+ var readV5 = isV5_1 && errorCellPatches.length
873
+ ? (0, helpers_1.createCellReaderV5)(doc, stylesV5())
874
+ : null;
794
875
  try {
795
876
  for (var errorCellPatches_1 = tslib_1.__values(errorCellPatches), errorCellPatches_1_1 = errorCellPatches_1.next(); !errorCellPatches_1_1.done; errorCellPatches_1_1 = errorCellPatches_1.next()) {
796
877
  var errorPatch = errorCellPatches_1_1.value;
797
878
  var _f = tslib_1.__read(errorPatch.path, 4), patchSheetId = _f[0], rowIndex = _f[1], columnIndex = _f[3];
798
- var currentCellData = useV3
799
- ? (_c = ySheetDataV3.get((0, helpers_1.createCellKeyV3)(Number(patchSheetId), Number(rowIndex), Number(columnIndex)))) === null || _c === void 0 ? void 0 : _c.value
800
- : (0, helpers_1.getCellDataFromYSheetData)(ySheetDataV2, patchSheetId, Number(rowIndex), Number(columnIndex));
879
+ var currentCellData = readV5
880
+ ? readV5(Number(patchSheetId), Number(rowIndex), Number(columnIndex))
881
+ : useV3
882
+ ? (_c = ySheetDataV3.get((0, helpers_1.createCellKeyV3)(Number(patchSheetId), Number(rowIndex), Number(columnIndex)))) === null || _c === void 0 ? void 0 : _c.value
883
+ : (0, helpers_1.getCellDataFromYSheetData)(ySheetDataV2, patchSheetId, Number(rowIndex), Number(columnIndex));
801
884
  var incomingCellData = errorPatch.value;
802
885
  if (!(0, helpers_1.shouldPersistErrorCellPatch)(currentCellData, incomingCellData)) {
803
886
  continue;
@@ -805,16 +888,19 @@ var useYSpreadsheetV2 = function (_a) {
805
888
  persistableErrorCellPatches_1.push(tslib_1.__assign(tslib_1.__assign({}, errorPatch), { value: (0, helpers_1.mergeErrorEffectiveValueIntoCellData)(currentCellData, incomingCellData) }));
806
889
  }
807
890
  }
808
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
891
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
809
892
  finally {
810
893
  try {
811
894
  if (errorCellPatches_1_1 && !errorCellPatches_1_1.done && (_b = errorCellPatches_1.return)) _b.call(errorCellPatches_1);
812
895
  }
813
- finally { if (e_10) throw e_10.error; }
896
+ finally { if (e_11) throw e_11.error; }
814
897
  }
815
898
  if (persistableErrorCellPatches_1.length) {
816
899
  doc.transact(function () {
817
- if (useV3) {
900
+ if (isV5_1) {
901
+ (0, helpers_1.addSheetDataPatchesV5)(doc, persistableErrorCellPatches_1, origin, stylesV5());
902
+ }
903
+ else if (useV3) {
818
904
  (0, helpers_1.addSheetDataPatchesV3)(ySheetDataV3, persistableErrorCellPatches_1);
819
905
  }
820
906
  else {
@@ -824,8 +910,9 @@ var useYSpreadsheetV2 = function (_a) {
824
910
  }
825
911
  return;
826
912
  }
913
+ var isV5 = isV5Doc();
827
914
  doc.transact(function () {
828
- var e_11, _a, e_12, _b;
915
+ var e_12, _a, e_13, _b;
829
916
  var _c, _d, _e, _f;
830
917
  try {
831
918
  for (var patches_2 = tslib_1.__values(patches), patches_2_1 = patches_2.next(); !patches_2_1.done; patches_2_1 = patches_2.next()) {
@@ -840,7 +927,10 @@ var useYSpreadsheetV2 = function (_a) {
840
927
  var patchKey = type === "redo" ? "patches" : "inversePatches";
841
928
  if (patch.sheetData) {
842
929
  var patches_3 = (_c = patch.sheetData) === null || _c === void 0 ? void 0 : _c[patchKey];
843
- if (useV3) {
930
+ if (isV5) {
931
+ (0, helpers_1.addSheetDataPatchesV5)(doc, patches_3, origin, stylesV5());
932
+ }
933
+ else if (useV3) {
844
934
  (0, helpers_1.addSheetDataPatchesV3)(ySheetDataV3, patches_3);
845
935
  }
846
936
  else {
@@ -852,7 +942,7 @@ var useYSpreadsheetV2 = function (_a) {
852
942
  (0, helpers_1.applyMapPatches)(yCellXfs, patches_4);
853
943
  }
854
944
  try {
855
- for (var _j = (e_12 = void 0, tslib_1.__values(documentMap.entries())), _k = _j.next(); !_k.done; _k = _j.next()) {
945
+ for (var _j = (e_13 = void 0, tslib_1.__values(documentMap.entries())), _k = _j.next(); !_k.done; _k = _j.next()) {
856
946
  var _l = tslib_1.__read(_k.value, 2), mappingKey = _l[0], _m = tslib_1.__read(_l[1], 1), ydoc = _m[0];
857
947
  if (patch === null || patch === void 0 ? void 0 : patch[mappingKey]) {
858
948
  var patches_5 = (_e = patch[mappingKey]) === null || _e === void 0 ? void 0 : _e[patchKey];
@@ -871,12 +961,12 @@ var useYSpreadsheetV2 = function (_a) {
871
961
  }
872
962
  }
873
963
  }
874
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
964
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
875
965
  finally {
876
966
  try {
877
967
  if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
878
968
  }
879
- finally { if (e_12) throw e_12.error; }
969
+ finally { if (e_13) throw e_13.error; }
880
970
  }
881
971
  // Recalc cells
882
972
  if ((_f = patch.recalcCells) === null || _f === void 0 ? void 0 : _f[type]) {
@@ -893,12 +983,12 @@ var useYSpreadsheetV2 = function (_a) {
893
983
  }
894
984
  }
895
985
  }
896
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
986
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
897
987
  finally {
898
988
  try {
899
989
  if (patches_2_1 && !patches_2_1.done && (_a = patches_2.return)) _a.call(patches_2);
900
990
  }
901
- finally { if (e_11) throw e_11.error; }
991
+ finally { if (e_12) throw e_12.error; }
902
992
  }
903
993
  }, origin);
904
994
  onAfterBroadcastPatch === null || onAfterBroadcastPatch === void 0 ? void 0 : onAfterBroadcastPatch(patches, doc);
@@ -915,6 +1005,8 @@ var useYSpreadsheetV2 = function (_a) {
915
1005
  isLeader,
916
1006
  recalcCellsMaxEntries,
917
1007
  useV3,
1008
+ isV5Doc,
1009
+ stylesV5,
918
1010
  ]);
919
1011
  // Listen to active cell change
920
1012
  (0, ui_1.useIsomorphicLayoutEffect)(function () {
@@ -935,7 +1027,7 @@ var useYSpreadsheetV2 = function (_a) {
935
1027
  // Awareness
936
1028
  (0, ui_1.useIsomorphicLayoutEffect)(function () {
937
1029
  var onChangeAwareness = function () {
938
- var e_13, _a;
1030
+ var e_14, _a;
939
1031
  var _b, _c, _d, _e, _f;
940
1032
  if (awareness) {
941
1033
  var collaborators = [];
@@ -975,12 +1067,12 @@ var useYSpreadsheetV2 = function (_a) {
975
1067
  });
976
1068
  }
977
1069
  }
978
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
1070
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
979
1071
  finally {
980
1072
  try {
981
1073
  if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
982
1074
  }
983
- finally { if (e_13) throw e_13.error; }
1075
+ finally { if (e_14) throw e_14.error; }
984
1076
  }
985
1077
  setUsers(collaborators);
986
1078
  }
@@ -3,7 +3,7 @@ import type { CellInterface } from "@rowsncolumns/grid";
3
3
  import type { CellData, Collaborator, ConditionalFormatRule, DataValidationRuleRecord, EmbeddedChart, EmbeddedObject, NamedRange, ProtectedRange, Sheet, TableView } from "@rowsncolumns/spreadsheet";
4
4
  import type { CalculateNowOptions, CalculationOperation, HistoryType, SheetData, SpreadsheetPatch } from "@rowsncolumns/spreadsheet-state";
5
5
  import type { Patch } from "immer";
6
- import * as Y from "yjs";
6
+ import type * as Y from "yjs";
7
7
  import type { CollabProviderLike, YjsRuntime } from "./types";
8
8
  export type useYSpreadsheetProps<T extends CellData, S extends Sheet, C extends EmbeddedChart, O extends EmbeddedObject> = {
9
9
  userId: string | number;
@@ -12,7 +12,11 @@ export type useYSpreadsheetProps<T extends CellData, S extends Sheet, C extends
12
12
  activeCell?: CellInterface;
13
13
  provider?: HocuspocusProvider | CollabProviderLike | any;
14
14
  doc: Y.Doc;
15
- /** The Yjs implementation `doc` belongs to; defaults to `yjs` (see `YjsRuntime`). */
15
+ /**
16
+ * The Yjs implementation `doc` belongs to, e.g. `import * as Y from "yjs"`.
17
+ * Falls back to the runtime registered with `setDefaultYjsRuntime`; with
18
+ * neither, the hook throws (see `YjsRuntime`).
19
+ */
16
20
  yjs?: YjsRuntime;
17
21
  calculateNow(options?: CalculateNowOptions): void;
18
22
  onChangeSheetData: React.Dispatch<React.SetStateAction<SheetData<T>>>;
@@ -33,7 +37,7 @@ export type useYSpreadsheetProps<T extends CellData, S extends Sheet, C extends
33
37
  * Does not load initial data
34
38
  * @returns
35
39
  */
36
- export declare const useYSpreadsheet: <T extends CellData, S extends Sheet, C extends EmbeddedChart, O extends EmbeddedObject>({ onChangeSheetData, onChangeSheets, onChangeTables, onChangeCharts, onChangeEmbeds, onChangeConditionalFormats, onChangeDataValidations, onChangeNamedRanges, onChangeProtectedRanges, onError, enqueueCalculation, calculateNow, userId, title, sheetId, activeCell, doc, provider, yjs, }: useYSpreadsheetProps<T, S, C, O>) => {
40
+ export declare const useYSpreadsheet: <T extends CellData, S extends Sheet, C extends EmbeddedChart, O extends EmbeddedObject>({ onChangeSheetData, onChangeSheets, onChangeTables, onChangeCharts, onChangeEmbeds, onChangeConditionalFormats, onChangeDataValidations, onChangeNamedRanges, onChangeProtectedRanges, onError, enqueueCalculation, calculateNow, userId, title, sheetId, activeCell, doc, provider, yjs: yjsRuntime, }: useYSpreadsheetProps<T, S, C, O>) => {
37
41
  onBroadcastPatch: (patches: [patch: SpreadsheetPatch<Patch>, type?: HistoryType | undefined][]) => void;
38
42
  users: Collaborator[];
39
43
  synced: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"use-yspreadsheet.d.ts","sourceRoot":"","sources":["../../use-yspreadsheet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,cAAc,EACd,UAAU,EACV,cAAc,EACd,KAAK,EACL,SAAS,EACV,MAAM,2BAA2B,CAAC;AAKnC,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,EAEX,SAAS,EACT,gBAAgB,EACjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAInC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,KAAK,EACV,kBAAkB,EAIlB,UAAU,EACX,MAAM,SAAS,CAAC;AAgBjB,MAAM,MAAM,oBAAoB,CAC9B,CAAC,SAAS,QAAQ,EAClB,CAAC,SAAS,KAAK,EACf,CAAC,SAAS,aAAa,EACvB,CAAC,SAAS,cAAc,IACtB;IACF,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,QAAQ,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,GAAG,CAAC;IACzD,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC;IACX,qFAAqF;IACrF,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAClD,iBAAiB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK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AM,eAAe,GAC1B,CAAC,SAAS,QAAQ,EAClB,CAAC,SAAS,KAAK,EACf,CAAC,SAAS,aAAa,EACvB,CAAC,SAAS,cAAc,EACxB,0SAoBC,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;gCA2SpB,CACP,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAC9B,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,CAC/B,EAAE;;;CAwDR,CAAC"}
@@ -6,7 +6,7 @@ var spreadsheet_1 = require("@rowsncolumns/spreadsheet");
6
6
  var immer_1 = require("immer");
7
7
  var uniqBy_1 = tslib_1.__importDefault(require("lodash/uniqBy"));
8
8
  var react_1 = require("react");
9
- var Y = tslib_1.__importStar(require("yjs"));
9
+ var yjs_runtime_1 = require("./yjs-runtime");
10
10
  var getStateVector = function (doc, yjs) {
11
11
  return yjs.encodeStateVector(doc);
12
12
  };
@@ -22,9 +22,10 @@ var getUpdatesBetween = function (doc, stateVector1, stateVector2, yjs) {
22
22
  * @returns
23
23
  */
24
24
  var useYSpreadsheet = function (_a) {
25
- var onChangeSheetData = _a.onChangeSheetData, onChangeSheets = _a.onChangeSheets, onChangeTables = _a.onChangeTables, onChangeCharts = _a.onChangeCharts, onChangeEmbeds = _a.onChangeEmbeds, onChangeConditionalFormats = _a.onChangeConditionalFormats, onChangeDataValidations = _a.onChangeDataValidations, onChangeNamedRanges = _a.onChangeNamedRanges, onChangeProtectedRanges = _a.onChangeProtectedRanges, onError = _a.onError, enqueueCalculation = _a.enqueueCalculation, calculateNow = _a.calculateNow, userId = _a.userId, title = _a.title, sheetId = _a.sheetId, activeCell = _a.activeCell, doc = _a.doc, provider = _a.provider, _b = _a.yjs, yjs = _b === void 0 ? Y : _b;
26
- var _c = tslib_1.__read((0, react_1.useState)([]), 2), users = _c[0], setUsers = _c[1];
27
- var _d = tslib_1.__read((0, react_1.useState)(false), 2), synced = _d[0], setSynced = _d[1];
25
+ var onChangeSheetData = _a.onChangeSheetData, onChangeSheets = _a.onChangeSheets, onChangeTables = _a.onChangeTables, onChangeCharts = _a.onChangeCharts, onChangeEmbeds = _a.onChangeEmbeds, onChangeConditionalFormats = _a.onChangeConditionalFormats, onChangeDataValidations = _a.onChangeDataValidations, onChangeNamedRanges = _a.onChangeNamedRanges, onChangeProtectedRanges = _a.onChangeProtectedRanges, onError = _a.onError, enqueueCalculation = _a.enqueueCalculation, calculateNow = _a.calculateNow, userId = _a.userId, title = _a.title, sheetId = _a.sheetId, activeCell = _a.activeCell, doc = _a.doc, provider = _a.provider, yjsRuntime = _a.yjs;
26
+ var yjs = (0, yjs_runtime_1.resolveYjsRuntime)(yjsRuntime);
27
+ var _b = tslib_1.__read((0, react_1.useState)([]), 2), users = _b[0], setUsers = _b[1];
28
+ var _c = tslib_1.__read((0, react_1.useState)(false), 2), synced = _c[0], setSynced = _c[1];
28
29
  var previousStateVectorRef = (0, react_1.useRef)(undefined);
29
30
  var currentStateVectorRef = (0, react_1.useRef)(undefined);
30
31
  // Recalc cells
@@ -1 +1 @@
1
- {"version":3,"file":"vitest.config.d.ts","sourceRoot":"","sources":["../../vitest.config.ts"],"names":[],"mappings":";AAEA,wBAsBG"}
1
+ {"version":3,"file":"vitest.config.d.ts","sourceRoot":"","sources":["../../vitest.config.ts"],"names":[],"mappings":";AAEA,wBAuBG"}
@@ -5,6 +5,7 @@ exports.default = (0, config_1.defineConfig)({
5
5
  test: {
6
6
  globals: true,
7
7
  environment: "jsdom",
8
+ setupFiles: ["./__tests__/setup-yjs-runtime.ts"],
8
9
  // ✅ correct location for deps.inline
9
10
  deps: {
10
11
  inline: ["konva", "react-konva"],
@@ -0,0 +1,6 @@
1
+ import type { YjsRuntime } from "./types";
2
+ /** Registers (or, with `undefined`, clears) the runtime used when a call passes none. */
3
+ export declare const setDefaultYjsRuntime: (runtime: YjsRuntime | undefined) => void;
4
+ /** The runtime a call works with: the one it was given, else the registered default. */
5
+ export declare const resolveYjsRuntime: (runtime?: YjsRuntime) => YjsRuntime;
6
+ //# sourceMappingURL=yjs-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yjs-runtime.d.ts","sourceRoot":"","sources":["../../yjs-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAW1C,yFAAyF;AACzF,eAAO,MAAM,oBAAoB,GAAI,SAAS,UAAU,GAAG,SAAS,KAAG,IAEtE,CAAC;AAEF,wFAAwF;AACxF,eAAO,MAAM,iBAAiB,GAAI,UAAU,UAAU,KAAG,UAQxD,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveYjsRuntime = exports.setDefaultYjsRuntime = void 0;
4
+ /**
5
+ * y-spreadsheet does not import a Yjs implementation: every helper and hook
6
+ * takes the namespace of the implementation the document belongs to (`yjs`,
7
+ * or a yjs-13-compatible layer over `@y/y` 14). A host that always works with
8
+ * one implementation can register it once here instead of passing it on every
9
+ * call; a runtime passed to a call wins over the registered one.
10
+ */
11
+ var defaultYjsRuntime;
12
+ /** Registers (or, with `undefined`, clears) the runtime used when a call passes none. */
13
+ var setDefaultYjsRuntime = function (runtime) {
14
+ defaultYjsRuntime = runtime;
15
+ };
16
+ exports.setDefaultYjsRuntime = setDefaultYjsRuntime;
17
+ /** The runtime a call works with: the one it was given, else the registered default. */
18
+ var resolveYjsRuntime = function (runtime) {
19
+ var resolved = runtime !== null && runtime !== void 0 ? runtime : defaultYjsRuntime;
20
+ if (!resolved) {
21
+ throw new Error("@rowsncolumns/y-spreadsheet: no Yjs runtime. Pass `yjs` (the namespace of the Yjs implementation the document belongs to, e.g. `import * as Y from \"yjs\"`) or register one with setDefaultYjsRuntime(Y). The package does not import yjs itself.");
22
+ }
23
+ return resolved;
24
+ };
25
+ exports.resolveYjsRuntime = resolveYjsRuntime;
@@ -0,0 +1,64 @@
1
+ import type { CellData, CellFormat } from "@rowsncolumns/spreadsheet";
2
+ import type { SheetData } from "@rowsncolumns/spreadsheet-state";
3
+ import type { Patch } from "immer";
4
+ import type * as Y from "yjs";
5
+ /** A parsed v5 cell key; line ids as decimal strings (an id can exceed 2^53). */
6
+ export type ParsedCellKeyV5 = {
7
+ sheetId: number;
8
+ rowId: string;
9
+ colId: string;
10
+ };
11
+ /** The composed style plane: cell key → format (`StyleOverlay`). */
12
+ export type StyleOverlayV5 = Map<string, CellFormat>;
13
+ /**
14
+ * A sheet's line ids in grid order (position = index + 1), as decimal strings.
15
+ * Later duplicates and non-id values are skipped, as the engine's index does.
16
+ */
17
+ export declare const readLineIds: (doc: Y.Doc, sheetId: number, axis: "row" | "column") => string[];
18
+ /** The `rncCells` / `rncNotes` key of a cell by its line ids. */
19
+ export declare const createCellKeyV5: (sheetId: number, rowId: string, colId: string) => string;
20
+ /** Parse a v5 key `"{sheetId}:{rowId}:{colId}"`; null when malformed. */
21
+ export declare const parseCellKeyV5: (key: string) => ParsedCellKeyV5 | null;
22
+ /**
23
+ * The composed style plane of a v5 doc (`refold_style_overlay`): the legacy
24
+ * `rncCellStyles` seed (`"{sheetId}!{A1}"`, the client-0 ids of that position)
25
+ * with every `rncCellStylesLog` buffer folded on in array order. Walks the log.
26
+ */
27
+ export declare const readStyleOverlayV5: (doc: Y.Doc) => StyleOverlayV5;
28
+ /**
29
+ * A v5 doc as V2 `SheetData` (same shape as `sheetDataV3ToV2`), hot plane only:
30
+ * every key of `rncCells`, `rncNotes` and the composed style plane composed as
31
+ * `composeCell` does (tombstones and orphans skipped).
32
+ */
33
+ export declare const sheetDataV5ToV2: <T extends CellData>(doc: Y.Doc, styles?: ReadonlyMap<string, CellFormat>) => SheetData<T>;
34
+ /**
35
+ * A reader of the cell at a 1-based position (`composeCell`), line ids read once
36
+ * per sheet. Undefined when nothing is there or the line is unnamed.
37
+ */
38
+ export declare const createCellReaderV5: <T extends CellData = CellData>(doc: Y.Doc, styles?: ReadonlyMap<string, CellFormat>) => (sheetId: number, rowIndex: number, columnIndex: number) => T | undefined;
39
+ /** `createCellReaderV5` for one cell (reads both id arrays: O(lines)). */
40
+ export declare const getCellV5: <T extends CellData = CellData>(doc: Y.Doc, sheetId: number, rowIndex: number, columnIndex: number, styles?: ReadonlyMap<string, CellFormat>) => T | undefined;
41
+ /**
42
+ * Apply changed `rncCells` / `rncNotes` keys to `currentSheetData` (copy-on-write,
43
+ * like `processSheetDataEventsV3`), `uf` from `styles`. Only valid while no id
44
+ * array and no style changed (those need `sheetDataV5ToV2`). Null when nothing changed.
45
+ */
46
+ export declare const processSheetDataChangesV5: <T extends CellData>(changedKeys: Iterable<string>, currentSheetData: SheetData<T>, doc: Y.Doc, styles?: ReadonlyMap<string, CellFormat>) => SheetData<T> | null;
47
+ /**
48
+ * Apply immer `SheetData` patches to a v5 doc in one transaction (`origin`, the
49
+ * caller's; nested in an open transaction it joins that one). Positional, like
50
+ * the v3 path: a row insert/delete arrives as rewritten rows and is applied as
51
+ * cell writes/removals at each position's line ids; no line is inserted or
52
+ * deleted. Writes past an axis name lines (client-0 padding, `ensure_lines`).
53
+ * `uf` changes append ONE `STYLE_LOG_V2` buffer to `rncCellStylesLog` and stay
54
+ * inline on the cell. `styles`, when given, is the caller's composed style plane
55
+ * (`readStyleOverlayV5`), used instead of folding the log and updated in place.
56
+ */
57
+ export declare const addSheetDataPatchesV5: (doc: Y.Doc, patches: Patch[] | undefined, origin?: unknown, styles?: StyleOverlayV5) => void;
58
+ /** Set one cell of a v5 doc (see `addSheetDataPatchesV5`). */
59
+ export declare const setCellV5: (doc: Y.Doc, sheetId: number, rowIndex: number, columnIndex: number, value: CellData) => void;
60
+ /** Remove one cell of a v5 doc (see `addSheetDataPatchesV5`). */
61
+ export declare const deleteCellV5: (doc: Y.Doc, sheetId: number, rowIndex: number, columnIndex: number) => void;
62
+ /** Remove every cell of a sheet of a v5 doc; its line ids and dimensions stay. */
63
+ export declare const deleteSheetV5: (doc: Y.Doc, sheetId: number) => void;
64
+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