@rowsncolumns/y-spreadsheet 16.1.2 → 17.0.1

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 (46) hide show
  1. package/Readme.md +21 -6
  2. package/dist/cjs/helpers-v5.d.ts +11 -11
  3. package/dist/cjs/helpers-v5.d.ts.map +1 -1
  4. package/dist/cjs/helpers-v5.js +34 -32
  5. package/dist/cjs/helpers.d.ts +17 -19
  6. package/dist/cjs/helpers.d.ts.map +1 -1
  7. package/dist/cjs/helpers.js +89 -86
  8. package/dist/cjs/observables.d.ts +7 -7
  9. package/dist/cjs/observables.d.ts.map +1 -1
  10. package/dist/cjs/observables.js +35 -47
  11. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  12. package/dist/cjs/types.d.ts +96 -19
  13. package/dist/cjs/types.d.ts.map +1 -1
  14. package/dist/cjs/use-yspreadsheet-v2.d.ts +11 -10
  15. package/dist/cjs/use-yspreadsheet-v2.d.ts.map +1 -1
  16. package/dist/cjs/use-yspreadsheet-v2.js +91 -110
  17. package/dist/cjs/use-yspreadsheet.d.ts +6 -6
  18. package/dist/cjs/use-yspreadsheet.d.ts.map +1 -1
  19. package/dist/cjs/use-yspreadsheet.js +38 -74
  20. package/dist/cjs/yjs-runtime.js +5 -5
  21. package/dist/cjs/ynodes.d.ts +61 -0
  22. package/dist/cjs/ynodes.d.ts.map +1 -0
  23. package/dist/cjs/ynodes.js +224 -0
  24. package/dist/esm/helpers-v5.d.ts +11 -11
  25. package/dist/esm/helpers-v5.d.ts.map +1 -1
  26. package/dist/esm/helpers-v5.js +34 -32
  27. package/dist/esm/helpers.d.ts +17 -19
  28. package/dist/esm/helpers.d.ts.map +1 -1
  29. package/dist/esm/helpers.js +90 -87
  30. package/dist/esm/observables.d.ts +7 -7
  31. package/dist/esm/observables.d.ts.map +1 -1
  32. package/dist/esm/observables.js +21 -25
  33. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  34. package/dist/esm/types.d.ts +96 -19
  35. package/dist/esm/types.d.ts.map +1 -1
  36. package/dist/esm/use-yspreadsheet-v2.d.ts +11 -10
  37. package/dist/esm/use-yspreadsheet-v2.d.ts.map +1 -1
  38. package/dist/esm/use-yspreadsheet-v2.js +88 -108
  39. package/dist/esm/use-yspreadsheet.d.ts +6 -6
  40. package/dist/esm/use-yspreadsheet.d.ts.map +1 -1
  41. package/dist/esm/use-yspreadsheet.js +17 -43
  42. package/dist/esm/yjs-runtime.js +5 -5
  43. package/dist/esm/ynodes.d.ts +61 -0
  44. package/dist/esm/ynodes.d.ts.map +1 -0
  45. package/dist/esm/ynodes.js +146 -0
  46. package/package.json +9 -8
@@ -5,17 +5,17 @@ import { useCallback, useMemo, useRef, useState } from "react";
5
5
  import { flushSync } from "react-dom";
6
6
  import { addSheetDataPatches, addSheetDataPatchesV5, addSheetDataPatchesV3, applyMapPatches, createCellReaderV5, createCellKeyV3, filterErrorCellPatches, getCellDataFromYSheetData, mergeErrorEffectiveValueIntoCellData, processSheetDataEvents, shouldPersistErrorCellPatch, processSheetDataEventsV3, processSheetDataChangesV5, readStyleOverlayV5, sheetDataV2ToV3, sheetDataV3ToV2, sheetDataV5ToV2, updateArrayType, validateSheets, } from "./helpers";
7
7
  import { resolveYjsRuntime } from "./yjs-runtime";
8
+ import { arrayJson, changedKeys as changedKeysOf, childDelta, listDelete, mapJson, } from "./ynodes";
8
9
  /**
9
10
  * Convert Y.js events to SheetDataEvent format for incremental processing
11
+ * (read inside the observer: a delta is computed from its transaction)
10
12
  */
11
13
  const convertToSheetDataEvents = (events, yjs) => {
12
- return events.map((event) => {
13
- const isYArrayEvent = event instanceof yjs.YArrayEvent;
14
+ return events.map(({ event, path }) => {
15
+ const isYArrayEvent = yjs.isArray(event.target);
14
16
  return {
15
- path: event.path,
16
- delta: isYArrayEvent
17
- ? event.changes.delta
18
- : undefined,
17
+ path,
18
+ delta: isYArrayEvent ? childDelta(event) : undefined,
19
19
  isYArrayEvent,
20
20
  };
21
21
  });
@@ -26,13 +26,13 @@ const convertToSheetDataEvents = (events, yjs) => {
26
26
  * before sheetData observer has updated React state.
27
27
  */
28
28
  const getUserEnteredValueFromYDoc = (ySheetData, sheetId, rowIndex, columnIndex) => {
29
- const sheet = ySheetData.get(String(sheetId));
29
+ const sheet = ySheetData.getAttr(String(sheetId));
30
30
  if (!sheet || rowIndex >= sheet.length)
31
31
  return undefined;
32
32
  const row = sheet.get(rowIndex);
33
33
  if (!row)
34
34
  return undefined;
35
- const values = row.get("values");
35
+ const values = row.getAttr("values");
36
36
  if (!values || columnIndex >= values.length)
37
37
  return undefined;
38
38
  const cell = values.get(columnIndex);
@@ -46,7 +46,7 @@ const getUserEnteredValueFromYDoc = (ySheetData, sheetId, rowIndex, columnIndex)
46
46
  */
47
47
  const getUserEnteredValueFromYDocV3 = (ySheetDataV3, sheetId, rowIndex, columnIndex) => {
48
48
  const cellKey = createCellKeyV3(sheetId, rowIndex, columnIndex);
49
- const cellDataV3 = ySheetDataV3.get(cellKey);
49
+ const cellDataV3 = ySheetDataV3.getAttr(cellKey);
50
50
  return getExtendedValueFormula(getCellUserEnteredValue(cellDataV3?.value));
51
51
  };
52
52
  import { createDeepObservable, createObservable, createSheetDataObservable, getPatchDeltasFromEvent, } from "./observables";
@@ -95,14 +95,14 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
95
95
  useIsomorphicLayoutEffect(() => {
96
96
  isLeaderRef.current = isLeader;
97
97
  }, [isLeader]);
98
- const ySheetDataV2 = useMemo(() => doc.getMap("sheetDataV2"), [doc]);
98
+ const ySheetDataV2 = useMemo(() => doc.get("sheetDataV2"), [doc]);
99
99
  // V3: Flat map structure - Map<cellKey, CellDataV3>
100
100
  // cellKey format: `${sheetId}!${A1Address}` (e.g., "1!A1", "2!B5")
101
- const ySheetDataV3 = useMemo(() => doc.getMap("sheetDataV3"), [doc]);
101
+ const ySheetDataV3 = useMemo(() => doc.get("sheetDataV3"), [doc]);
102
102
  // Doc metadata - used as fallback for version when prop is undefined
103
- const yDocMeta = useMemo(() => doc.getMap("docMeta"), [doc]);
103
+ const yDocMeta = useMemo(() => doc.get("docMeta"), [doc]);
104
104
  // V5: the engine marks the doc in `docMeta`; read live (the marker may arrive with a sync)
105
- const isV5Doc = useCallback(() => sheetDataVersion === "v5" || yDocMeta.get("sheetDataVersion") === "v5", [sheetDataVersion, yDocMeta]);
105
+ const isV5Doc = useCallback(() => sheetDataVersion === "v5" || yDocMeta.getAttr("sheetDataVersion") === "v5", [sheetDataVersion, yDocMeta]);
106
106
  // V5: the composed style plane, folded on a full read and on a remote style
107
107
  // change, updated in place by this hook's own writes
108
108
  const stylesV5Ref = useRef(null);
@@ -111,9 +111,9 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
111
111
  stylesV5Ref.current = readStyleOverlayV5(doc);
112
112
  return sheetDataV5ToV2(doc, stylesV5Ref.current);
113
113
  }, [doc]);
114
- const yDisableRecalc = useMemo(() => doc.getMap("disableRecalc"), [doc]);
114
+ const yDisableRecalc = useMemo(() => doc.get("disableRecalc"), [doc]);
115
115
  // Recalc cells
116
- const yRecalcCells = useMemo(() => doc.getArray("recalcCells"), [doc]);
116
+ const yRecalcCells = useMemo(() => doc.get("recalcCells"), [doc]);
117
117
  // Make sure initialSheets is always filled
118
118
  const getInitialSheets = useCallback(() => {
119
119
  if (initialSheets.length) {
@@ -122,10 +122,10 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
122
122
  return [createNewSheet(1, "Sheet1")];
123
123
  }, [initialSheets]);
124
124
  // cellxfs
125
- const yCellXfs = useMemo(() => doc.getMap("cellXfs"), [doc]);
125
+ const yCellXfs = useMemo(() => doc.get("cellXfs"), [doc]);
126
126
  // Shared strings - always use Map for new storage, Array kept for migration
127
- const ySharedStringsArray = useMemo(() => doc.getArray("sharedStrings"), [doc]);
128
- const ySharedStringsMap = useMemo(() => doc.getMap("sharedStringsMap"), [doc]);
127
+ const ySharedStringsArray = useMemo(() => doc.get("sharedStrings"), [doc]);
128
+ const ySharedStringsMap = useMemo(() => doc.get("sharedStringsMap"), [doc]);
129
129
  // Track if initial sync has changed active sheet
130
130
  const isActiveSheetChanged = useRef(false);
131
131
  /**
@@ -156,60 +156,51 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
156
156
  return newMap;
157
157
  });
158
158
  }, [onChangeSharedStrings]);
159
+ // Each root with the kind it is read as (a root carries no type on the wire)
159
160
  const documentMap = useMemo(() => {
160
161
  const entries = [
161
- ["sheets", [doc.getArray("sheets"), onChangeSheets]],
162
- ["tables", [doc.getArray("tables"), onChangeTables]],
163
- [
164
- "embeds",
165
- [doc.getArray("embeds"), onChangeEmbeds],
166
- ],
167
- [
168
- "charts",
169
- [doc.getArray("charts"), onChangeCharts],
170
- ],
162
+ ["sheets", [doc.get("sheets"), onChangeSheets, "array"]],
163
+ ["tables", [doc.get("tables"), onChangeTables, "array"]],
164
+ ["embeds", [doc.get("embeds"), onChangeEmbeds, "array"]],
165
+ ["charts", [doc.get("charts"), onChangeCharts, "array"]],
171
166
  [
172
167
  "conditionalFormats",
173
168
  [
174
- doc.getArray("conditionalFormats"),
169
+ doc.get("conditionalFormats"),
175
170
  onChangeConditionalFormats,
171
+ "array",
176
172
  ],
177
173
  ],
178
174
  [
179
175
  "dataValidations",
180
- [
181
- doc.getArray("dataValidations"),
182
- onChangeDataValidations,
183
- ],
176
+ [doc.get("dataValidations"), onChangeDataValidations, "array"],
184
177
  ],
185
178
  [
186
179
  "pivotTables",
187
- [doc.getArray("pivotTables"), onChangePivotTables],
180
+ [doc.get("pivotTables"), onChangePivotTables, "array"],
188
181
  ],
189
182
  [
190
183
  "namedRanges",
191
- [doc.getArray("namedRanges"), onChangeNamedRanges],
184
+ [doc.get("namedRanges"), onChangeNamedRanges, "array"],
192
185
  ],
193
186
  [
194
187
  "protectedRanges",
195
- [
196
- doc.getArray("protectedRanges"),
197
- onChangeProtectedRanges,
198
- ],
199
- ],
200
- [
201
- "citations",
202
- [doc.getArray("citations"), onChangeCitations],
188
+ [doc.get("protectedRanges"), onChangeProtectedRanges, "array"],
203
189
  ],
190
+ ["citations", [doc.get("citations"), onChangeCitations, "array"]],
204
191
  [
205
192
  "sharedStrings",
206
- [ySharedStringsMap, handleSharedStringsMapChange],
193
+ [ySharedStringsMap, handleSharedStringsMapChange, "map"],
207
194
  ],
208
195
  ...(supportLegacySharedStringsArray
209
196
  ? [
210
197
  [
211
198
  "sharedStringsArray",
212
- [ySharedStringsArray, handleSharedStringsArrayChange],
199
+ [
200
+ ySharedStringsArray,
201
+ handleSharedStringsArrayChange,
202
+ "array",
203
+ ],
213
204
  ],
214
205
  ]
215
206
  : []),
@@ -235,8 +226,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
235
226
  ]);
236
227
  // Get backlog of recalc cells from backend
237
228
  const getBacklog = useCallback(() => {
238
- return yRecalcCells
239
- .toArray()
229
+ return yRecalcCells.toArray()
240
230
  .flatMap((entry) => entry.patches)
241
231
  .filter(([, , source]) => source === "backend" || source === "agent");
242
232
  }, [yRecalcCells]);
@@ -325,7 +315,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
325
315
  // Both formats are now supported simultaneously via handleSharedStringsMapChange
326
316
  // and handleSharedStringsArrayChange callbacks.
327
317
  const arrayData = ySharedStringsArray.toArray();
328
- const mapData = ySharedStringsMap.toJSON();
318
+ const mapData = mapJson(ySharedStringsMap, yjs);
329
319
  const hasArrayData = arrayData.length > 0;
330
320
  const isMapEmpty = Object.keys(mapData).length === 0;
331
321
  // Migrate if array has data and map is empty
@@ -333,15 +323,15 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
333
323
  doc.transact(() => {
334
324
  // Convert array to map with string keys
335
325
  arrayData.forEach((value, index) => {
336
- ySharedStringsMap.set(String(index), value);
326
+ ySharedStringsMap.setAttr(String(index), value);
337
327
  });
338
328
  // Optional: Clear the old array to save space
339
329
  // Uncomment if you want to remove old data after migration
340
330
  // ySharedStringsArray.delete(0, ySharedStringsArray.length);
341
331
  }, "migration");
342
332
  }
343
- for (const [mappingKey, [ydoc, callback]] of documentMap.entries()) {
344
- let value = ydoc.toJSON();
333
+ for (const [mappingKey, [ydoc, callback, kind]] of documentMap.entries()) {
334
+ let value = kind === "map" ? mapJson(ydoc, yjs) : arrayJson(ydoc, yjs);
345
335
  if (mappingKey === "sheets") {
346
336
  const sheets = (Array.isArray(value) && value.length
347
337
  ? validateSheets(value)
@@ -370,9 +360,9 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
370
360
  else if (useV3) {
371
361
  // Check if we need to migrate from V2 to V3
372
362
  // Use prop if provided, otherwise fall back to yDocMeta for backwards compatibility
373
- const resolvedVersion = sheetDataVersion ?? yDocMeta.get("sheetDataVersion");
363
+ const resolvedVersion = sheetDataVersion ?? yDocMeta.getAttr("sheetDataVersion");
374
364
  if (resolvedVersion !== "v3") {
375
- const v2Data = ySheetDataV2.toJSON();
365
+ const v2Data = mapJson(ySheetDataV2, yjs);
376
366
  const hasV2Data = Object.keys(v2Data).length > 0;
377
367
  if (hasV2Data) {
378
368
  // Migrate V2 data to V3
@@ -380,12 +370,12 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
380
370
  const v3Data = sheetDataV2ToV3(v2Data);
381
371
  // Add all V3 entries to the Y.Map
382
372
  for (const [key, cellData] of v3Data.entries()) {
383
- ySheetDataV3.set(key, cellData);
373
+ ySheetDataV3.setAttr(key, cellData);
384
374
  }
385
375
  // Optionally clear V2 data after migration
386
376
  if (deleteV2AfterMigration) {
387
- for (const sheetId of ySheetDataV2.keys()) {
388
- ySheetDataV2.delete(sheetId);
377
+ for (const sheetId of ySheetDataV2.attrKeys()) {
378
+ ySheetDataV2.deleteAttr(sheetId);
389
379
  }
390
380
  }
391
381
  }, "migrate-v2-to-v3");
@@ -398,15 +388,15 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
398
388
  }
399
389
  }
400
390
  // V3: Convert flat map to V2 format for React state
401
- const v3Data = ySheetDataV3.toJSON();
391
+ const v3Data = mapJson(ySheetDataV3, yjs);
402
392
  const v3Map = new Map(Object.entries(v3Data));
403
393
  onChangeSheetData?.(sheetDataV3ToV2(v3Map));
404
394
  }
405
395
  else {
406
- onChangeSheetData?.(ySheetDataV2.toJSON());
396
+ onChangeSheetData?.(mapJson(ySheetDataV2, yjs));
407
397
  }
408
398
  // Cellxfs
409
- const cellXfs = new Map(Object.entries(yCellXfs.toJSON() ?? {}));
399
+ const cellXfs = new Map(Object.entries(mapJson(yCellXfs, yjs) ?? {}));
410
400
  onChangeCellXfs?.(cellXfs);
411
401
  }, [
412
402
  documentMap,
@@ -427,6 +417,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
427
417
  deleteV2AfterMigration,
428
418
  isV5Doc,
429
419
  readSheetDataV5,
420
+ yjs,
430
421
  ]);
431
422
  /**
432
423
  * Replay the backend/agent recalc backlog into the local graph — and, on
@@ -442,7 +433,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
442
433
  syncRecalcCells(backlog, "backend");
443
434
  if (isLeaderRef.current) {
444
435
  doc.transact(() => {
445
- yRecalcCells.delete(0, yRecalcCells.length);
436
+ listDelete(yRecalcCells, 0, yRecalcCells.length);
446
437
  }, origin);
447
438
  }
448
439
  }, [getBacklog, syncRecalcCells, doc, yRecalcCells]);
@@ -504,7 +495,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
504
495
  if (useV3)
505
496
  return; // Skip V2 observer in V3 mode
506
497
  // Subscribe to sheet data
507
- const subscription = createSheetDataObservable(ySheetDataV2).subscribe((events) => {
498
+ const subscription = createSheetDataObservable(ySheetDataV2, yjs).subscribe((events) => {
508
499
  /**
509
500
  * Disable recalc is a flag that is set ONLY locally
510
501
  * when a calculation completes
@@ -513,14 +504,14 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
513
504
  * and updating it, which is not necessary
514
505
  */
515
506
  if (events.length) {
516
- const origin = events?.[0]?.transaction?.origin;
507
+ const origin = events?.[0]?.event.transaction?.origin;
517
508
  if (origin !== "local" || observesLocal()) {
518
509
  // Convert Y.js events to SheetDataEvent format and apply incremental updates
519
510
  const sheetDataEvents = convertToSheetDataEvents(events, yjs);
520
511
  onChangeSheetData((prevSheetData) => {
521
- const result = processSheetDataEvents(sheetDataEvents, prevSheetData, ySheetDataV2);
512
+ const result = processSheetDataEvents(sheetDataEvents, prevSheetData, ySheetDataV2, yjs);
522
513
  // Fall back to full serialization only if incremental update fails
523
- return result ?? ySheetDataV2.toJSON();
514
+ return result ?? mapJson(ySheetDataV2, yjs);
524
515
  });
525
516
  }
526
517
  }
@@ -528,20 +519,18 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
528
519
  return () => {
529
520
  subscription.unsubscribe();
530
521
  };
531
- }, [onChangeSheetData, ySheetDataV2, useV3, observesLocal]);
522
+ }, [onChangeSheetData, ySheetDataV2, useV3, yjs, observesLocal]);
532
523
  // Only for sheet Data (V3 mode)
533
524
  useIsomorphicLayoutEffect(() => {
534
525
  if (!useV3)
535
526
  return; // Skip V3 observer in V2 mode
536
527
  // Subscribe to V3 sheet data (flat Map)
537
528
  const callback = (event) => {
538
- if (event.transaction.origin !== "local" || observesLocal()) {
539
- // Extract changes synchronously - Yjs requires accessing event.changes
540
- // within the event handler, not in a deferred callback like setState
541
- const changedKeys = new Map();
542
- event.changes.keys.forEach((change, key) => {
543
- changedKeys.set(key, { action: change.action });
544
- });
529
+ if (event.transaction.origin !== "local" ||
530
+ observesLocal()) {
531
+ // Extract changes synchronously - they are read from the document as
532
+ // the event leaves it, not in a deferred callback like setState
533
+ const changedKeys = changedKeysOf(event);
545
534
  // Now we can safely use the extracted data in the async setState callback
546
535
  onChangeSheetData((prevSheetData) => {
547
536
  const result = processSheetDataEventsV3(changedKeys, prevSheetData, ySheetDataV3);
@@ -549,7 +538,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
549
538
  return result;
550
539
  }
551
540
  // Fall back to full conversion
552
- const v3Data = ySheetDataV3.toJSON();
541
+ const v3Data = mapJson(ySheetDataV3, yjs);
553
542
  const v3Map = new Map(Object.entries(v3Data));
554
543
  return sheetDataV3ToV2(v3Map);
555
544
  });
@@ -559,7 +548,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
559
548
  return () => {
560
549
  ySheetDataV3.unobserve(callback);
561
550
  };
562
- }, [onChangeSheetData, ySheetDataV3, useV3, observesLocal]);
551
+ }, [onChangeSheetData, ySheetDataV3, useV3, yjs, observesLocal]);
563
552
  // Only for sheet Data (V5 docs): `rncCells`, `rncNotes`, the style planes and
564
553
  // every sheet's id arrays. A change of an id array, a style plane (or of
565
554
  // `docMeta`): full re-read; a cell or note change alone is applied
@@ -567,7 +556,8 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
567
556
  // created after this effect ran is seen too.
568
557
  useIsomorphicLayoutEffect(() => {
569
558
  const callback = (transaction) => {
570
- if ((transaction.origin === "local" && !observesLocal()) || !isV5Doc())
559
+ if ((transaction.origin === "local" && !observesLocal()) ||
560
+ !isV5Doc())
571
561
  return;
572
562
  let full = false;
573
563
  const cellKeys = [];
@@ -597,20 +587,14 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
597
587
  return () => {
598
588
  doc.off("afterTransaction", callback);
599
589
  };
600
- }, [
601
- doc,
602
- onChangeSheetData,
603
- isV5Doc,
604
- readSheetDataV5,
605
- stylesV5,
606
- observesLocal,
607
- ]);
590
+ }, [doc, onChangeSheetData, isV5Doc, readSheetDataV5, stylesV5, observesLocal]);
608
591
  // CellXfs
609
592
  useIsomorphicLayoutEffect(() => {
610
593
  // Subscribe to sheet data
611
594
  const callback = (event) => {
612
- if (event.transaction.origin !== "local" || observesLocal()) {
613
- const cellXfs = new Map(Object.entries(yCellXfs.toJSON() ?? {}));
595
+ if (event.transaction.origin !== "local" ||
596
+ observesLocal()) {
597
+ const cellXfs = new Map(Object.entries(mapJson(yCellXfs, yjs) ?? {}));
614
598
  onChangeCellXfs?.(cellXfs);
615
599
  }
616
600
  };
@@ -618,17 +602,18 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
618
602
  return () => {
619
603
  yCellXfs.unobserve(callback);
620
604
  };
621
- }, [onChangeCellXfs, yCellXfs, observesLocal]);
605
+ }, [onChangeCellXfs, yCellXfs, yjs, observesLocal]);
622
606
  // All others
623
607
  useIsomorphicLayoutEffect(() => {
624
608
  const subs = [];
625
- for (const [mappingKey, [ydoc, callback]] of documentMap.entries()) {
609
+ for (const [mappingKey, [ydoc, callback, kind]] of documentMap.entries()) {
626
610
  // Only observe Arrays (shared strings Map is handled separately if needed)
627
- if (ydoc instanceof yjs.Array) {
628
- const subscription = createDeepObservable(ydoc).subscribe((events) => {
629
- for (const event of events) {
630
- if (event.transaction.origin !== "local" || observesLocal()) {
631
- let json = ydoc.toJSON();
611
+ if (kind === "array") {
612
+ const subscription = createDeepObservable(ydoc, yjs).subscribe((events) => {
613
+ for (const { event } of events) {
614
+ if (event.transaction.origin !== "local" ||
615
+ observesLocal()) {
616
+ let json = arrayJson(ydoc, yjs);
632
617
  if (Array.isArray(json) &&
633
618
  json.length &&
634
619
  json[0]?.userId) {
@@ -640,11 +625,12 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
640
625
  });
641
626
  subs.push(subscription);
642
627
  }
643
- else if (ydoc instanceof yjs.Map && mappingKey === "sharedStrings") {
628
+ else if (kind === "map" && mappingKey === "sharedStrings") {
644
629
  // Handle shared strings Map observation
645
630
  const callback_map = (event) => {
646
- if (event.transaction.origin !== "local" || observesLocal()) {
647
- const json = ydoc.toJSON();
631
+ if (event.transaction.origin !== "local" ||
632
+ observesLocal()) {
633
+ const json = mapJson(ydoc, yjs);
648
634
  const sharedStringsMap = new Map(Object.entries(json ?? {}));
649
635
  callback?.(sharedStringsMap);
650
636
  }
@@ -658,7 +644,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
658
644
  return () => {
659
645
  subs.forEach((sub) => sub.unsubscribe());
660
646
  };
661
- }, [documentMap, observesLocal]);
647
+ }, [documentMap, yjs, observesLocal]);
662
648
  // Only for recalc cells
663
649
  useIsomorphicLayoutEffect(() => {
664
650
  if (!synced) {
@@ -688,13 +674,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
688
674
  for (const timer of pending)
689
675
  clearTimeout(timer);
690
676
  };
691
- }, [
692
- syncRecalcCells,
693
- recalcCellsMaxEntries,
694
- synced,
695
- yRecalcCells,
696
- observesLocal,
697
- ]);
677
+ }, [syncRecalcCells, recalcCellsMaxEntries, synced, yRecalcCells, observesLocal]);
698
678
  // Broadcast patch
699
679
  const onBroadcastPatch = useCallback((patches) => {
700
680
  // Ignore push flag
@@ -740,7 +720,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
740
720
  const currentCellData = readV5
741
721
  ? readV5(Number(patchSheetId), Number(rowIndex), Number(columnIndex))
742
722
  : useV3
743
- ? ySheetDataV3.get(createCellKeyV3(Number(patchSheetId), Number(rowIndex), Number(columnIndex)))?.value
723
+ ? ySheetDataV3.getAttr(createCellKeyV3(Number(patchSheetId), Number(rowIndex), Number(columnIndex)))?.value
744
724
  : getCellDataFromYSheetData(ySheetDataV2, patchSheetId, Number(rowIndex), Number(columnIndex));
745
725
  const incomingCellData = errorPatch.value;
746
726
  if (!shouldPersistErrorCellPatch(currentCellData, incomingCellData)) {
@@ -793,14 +773,14 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
793
773
  const patches = patch.cellXfs?.[patchKey];
794
774
  applyMapPatches(yCellXfs, patches);
795
775
  }
796
- for (const [mappingKey, [ydoc]] of documentMap.entries()) {
776
+ for (const [mappingKey, [ydoc, , kind]] of documentMap.entries()) {
797
777
  if (patch?.[mappingKey]) {
798
778
  const patches = patch[mappingKey]?.[patchKey];
799
779
  // Handle shared strings Map (always use Map now)
800
- if (mappingKey === "sharedStrings" && ydoc instanceof yjs.Map) {
780
+ if (mappingKey === "sharedStrings" && kind === "map") {
801
781
  applyMapPatches(ydoc, patches);
802
782
  }
803
- else if (ydoc instanceof yjs.Array) {
783
+ else if (kind === "array") {
804
784
  // Check if we are updating sheets
805
785
  if (mappingKey === "sheets" && ydoc.length === 0) {
806
786
  // Add initial sheets
@@ -814,7 +794,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
814
794
  if (patch.recalcCells?.[type]) {
815
795
  if (isLeader) {
816
796
  // Remove old cells
817
- yRecalcCells.delete(0, yRecalcCells.length);
797
+ listDelete(yRecalcCells, 0, yRecalcCells.length);
818
798
  }
819
799
  yRecalcCells.push([
820
800
  {
@@ -3,19 +3,19 @@ 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 type * as Y from "yjs";
7
- import type { CollabProviderLike, YjsRuntime } from "./types";
6
+ import type { CollabProviderLike, YDoc, YjsRuntime } from "./types";
8
7
  export type useYSpreadsheetProps<T extends CellData, S extends Sheet, C extends EmbeddedChart, O extends EmbeddedObject> = {
9
8
  userId: string | number;
10
9
  title: string;
11
10
  sheetId: number;
12
11
  activeCell?: CellInterface;
13
12
  provider?: HocuspocusProvider | CollabProviderLike | any;
14
- doc: Y.Doc;
13
+ /** The `@y/y` 14 document (its roots are read with `doc.get(name)`). */
14
+ doc: YDoc;
15
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`).
16
+ * The host's node operations and update functions for `doc` (see
17
+ * `YjsRuntime`). Falls back to the runtime registered with
18
+ * `setDefaultYjsRuntime`; with neither, the hook throws.
19
19
  */
20
20
  yjs?: YjsRuntime;
21
21
  calculateNow(options?: CalculateNowOptions): void;
@@ -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,KAAK,CAAC,MAAM,KAAK,CAAC;AAE9B,OAAO,KAAK,EACV,kBAAkB,EAIlB,UAAU,EACX,MAAM,SAAS,CAAC;AAiBjB,MAAM,MAAM,oBAAoB,CAC9B,CAAC,SAAS,QAAQ,EAClB,CAAC,SAAS,KAAK,EACf,CAAC,SAAS,aAAa,EACvB,CAAC,SAAS,cAAc,IACtB;IACF,MAAM,EAAE,MAAM,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CAAC,qBAAqB,EAAE,CAAC,CAC9C,CAAC;IACF,uBAAuB,CAAC,EAAE,KAAK,CAAC,QAAQ,CACtC,KAAK,CAAC,cAAc,CAAC,wBAAwB,EAAE,CAAC,CACjD,CAAC;IACF,kBAAkB,EAAE,CAAC,SAAS,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC9D,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,mBAAmB,CAAC,IAAI,IAAI,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,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;gCA0QpB,CACP,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAC9B,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,CAC/B,EAAE;;;CAwDR,CAAC"}
@@ -3,6 +3,7 @@ import { applyPatches } from "immer";
3
3
  import uniqBy from "lodash/uniqBy";
4
4
  import { useCallback, useMemo, useRef, useState } from "react";
5
5
  import { resolveYjsRuntime } from "./yjs-runtime";
6
+ import { insertedValues } from "./ynodes";
6
7
  const getStateVector = (doc, yjs) => yjs.encodeStateVector(doc);
7
8
  // Function to get updates between two state vectors
8
9
  const getUpdatesBetween = (doc, stateVector1, stateVector2, yjs) => {
@@ -22,52 +23,31 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
22
23
  const previousStateVectorRef = useRef(undefined);
23
24
  const currentStateVectorRef = useRef(undefined);
24
25
  // Recalc cells
25
- const yRecalcCells = useMemo(() => doc.getArray("recalcCells"), [doc]);
26
- const yDisableRecalc = doc.getMap("disableRecalc");
26
+ const yRecalcCells = useMemo(() => doc.get("recalcCells"), [doc]);
27
+ const yDisableRecalc = doc.get("disableRecalc");
27
28
  // Counter
28
29
  // Create a counter to keep track of when the last sync was done
29
30
  const docSyncCounterRef = useRef(new Map());
30
31
  // Create a doc map
31
32
  const docMap = useMemo(() => {
32
33
  const docMap = new Map([
33
- [
34
- "sheets",
35
- [doc.getArray("sheets"), onChangeSheets, "sheetId"],
36
- ],
37
- [
38
- "sheetData",
39
- [doc.getArray("sheetData"), onChangeSheetData],
40
- ],
41
- ["tables", [doc.getArray("tables"), onChangeTables, "id"]],
42
- ["embeds", [doc.getArray("embeds"), onChangeEmbeds, "id"]],
43
- ["charts", [doc.getArray("charts"), onChangeCharts, "id"]],
34
+ ["sheets", [doc.get("sheets"), onChangeSheets, "sheetId"]],
35
+ ["sheetData", [doc.get("sheetData"), onChangeSheetData]],
36
+ ["tables", [doc.get("tables"), onChangeTables, "id"]],
37
+ ["embeds", [doc.get("embeds"), onChangeEmbeds, "id"]],
38
+ ["charts", [doc.get("charts"), onChangeCharts, "id"]],
44
39
  [
45
40
  "conditionalFormats",
46
- [
47
- doc.getArray("conditionalFormats"),
48
- onChangeConditionalFormats,
49
- "id",
50
- ],
41
+ [doc.get("conditionalFormats"), onChangeConditionalFormats, "id"],
51
42
  ],
52
43
  [
53
44
  "dataValidations",
54
- [
55
- doc.getArray("dataValidations"),
56
- onChangeDataValidations,
57
- "id",
58
- ],
59
- ],
60
- [
61
- "namedRanges",
62
- [doc.getArray("namedRanges"), onChangeNamedRanges, "id"],
45
+ [doc.get("dataValidations"), onChangeDataValidations, "id"],
63
46
  ],
47
+ ["namedRanges", [doc.get("namedRanges"), onChangeNamedRanges, "id"]],
64
48
  [
65
49
  "protectedRanges",
66
- [
67
- doc.getArray("protectedRanges"),
68
- onChangeProtectedRanges,
69
- "id",
70
- ],
50
+ [doc.get("protectedRanges"), onChangeProtectedRanges, "id"],
71
51
  ],
72
52
  ]);
73
53
  return docMap;
@@ -111,7 +91,7 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
111
91
  };
112
92
  for (const [mappingKey, [_, setStateFn, idKey]] of docMap) {
113
93
  const startCounter = docSyncCounterRef.current.get(mappingKey) ?? 0;
114
- const [patches, endCounter] = getInitialPatches(syncedDoc.getArray(mappingKey), startCounter);
94
+ const [patches, endCounter] = getInitialPatches(syncedDoc.get(mappingKey), startCounter);
115
95
  if (patches.length) {
116
96
  docSyncCounterRef.current.set(mappingKey, endCounter);
117
97
  setStateFn?.((prev) => {
@@ -194,15 +174,9 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
194
174
  const getPatchDeltasFromEvent = (event) => {
195
175
  const patches = [];
196
176
  if (event.transaction.origin !== "locale") {
197
- for (const changes of event.changes.delta) {
198
- for (const type in changes) {
199
- if (type === "insert" && changes[type] !== undefined) {
200
- for (const { patches: userPatches } of changes[type]) {
201
- for (const patch of userPatches) {
202
- patches.push(patch);
203
- }
204
- }
205
- }
177
+ for (const { patches: userPatches } of insertedValues(event)) {
178
+ for (const patch of userPatches) {
179
+ patches.push(patch);
206
180
  }
207
181
  }
208
182
  }
@@ -229,7 +203,7 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
229
203
  for (const [_, [doc, setStateFn]] of docMap) {
230
204
  const callback = (event) => {
231
205
  const patches = getPatchDeltasFromEvent(event);
232
- const disableRecalc = yDisableRecalc.get("disableRecalc");
206
+ const disableRecalc = yDisableRecalc.getAttr("disableRecalc");
233
207
  if (event.transaction.origin !== "local" && disableRecalc !== true) {
234
208
  if (patches.length) {
235
209
  setStateFn?.((prev) => {
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * y-spreadsheet does not import a Yjs implementation: every helper and hook
3
- * takes the namespace of the implementation the document belongs to (`yjs`,
4
- * or a yjs-13-compatible layer over `@y/y` 14). A host that always works with
5
- * one implementation can register it once here instead of passing it on every
6
- * call; a runtime passed to a call wins over the registered one.
3
+ * takes the host's node operations for the `@y/y` 14 document it works on
4
+ * (`YjsRuntime`). A host that always works with one runtime can register it
5
+ * once here instead of passing it on every call; a runtime passed to a call
6
+ * wins over the registered one.
7
7
  */
8
8
  let defaultYjsRuntime;
9
9
  /** Registers (or, with `undefined`, clears) the runtime used when a call passes none. */
@@ -14,7 +14,7 @@ export const setDefaultYjsRuntime = (runtime) => {
14
14
  export const resolveYjsRuntime = (runtime) => {
15
15
  const resolved = runtime ?? defaultYjsRuntime;
16
16
  if (!resolved) {
17
- 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.");
17
+ throw new Error("@rowsncolumns/y-spreadsheet: no Yjs runtime. Pass `yjs` (the host's YjsRuntime for its @y/y 14 documents: createMap / createArray / isMap / isArray, getPathTo, Doc and the update functions) or register one with setDefaultYjsRuntime(runtime). The package does not import a Yjs implementation itself.");
18
18
  }
19
19
  return resolved;
20
20
  };