canvu-react 0.4.0 → 0.4.2

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.
package/dist/realtime.cjs CHANGED
@@ -2141,32 +2141,6 @@ function applyServerSnapshotToYDoc(board, options) {
2141
2141
  const { items: snapshotItems, origin } = options;
2142
2142
  const now = Date.now();
2143
2143
  board.doc.transact(() => {
2144
- const snapshotIds = /* @__PURE__ */ new Set();
2145
- const snapshotById = /* @__PURE__ */ new Map();
2146
- for (const item of snapshotItems) {
2147
- const id = getItemId(item);
2148
- if (!id) continue;
2149
- snapshotIds.add(id);
2150
- snapshotById.set(id, item);
2151
- }
2152
- const currentIndex = indexYItemsById(board.yItems);
2153
- const toDeleteIds = [];
2154
- for (const [id] of currentIndex) {
2155
- if (snapshotIds.has(id)) continue;
2156
- if (board.lastServerConfirmedIds.has(id)) {
2157
- toDeleteIds.push(id);
2158
- }
2159
- }
2160
- if (toDeleteIds.length > 0) {
2161
- const refreshed = indexYItemsById(board.yItems);
2162
- const sortedIndices = toDeleteIds.map((id) => ({ id, index: refreshed.get(id)?.index })).filter(
2163
- (entry) => entry.index != null
2164
- ).sort((a, b) => b.index - a.index);
2165
- for (const { id, index } of sortedIndices) {
2166
- board.yItems.delete(index, 1);
2167
- board.serverItemSeenAt.delete(id);
2168
- }
2169
- }
2170
2144
  for (const item of snapshotItems) {
2171
2145
  const id = getItemId(item);
2172
2146
  if (!id) continue;
@@ -2581,7 +2555,10 @@ function useRealtimeSession(options) {
2581
2555
  removeRealtimeOfflineDraft(roomId);
2582
2556
  return;
2583
2557
  }
2584
- writeRealtimeOfflineDraft(localDraftRef.current);
2558
+ const board = boardRef.current;
2559
+ const draft = localDraftRef.current;
2560
+ const draftToWrite = board && draft.yDocState == null ? { ...draft, yDocState: encodeYDocState(board) } : draft;
2561
+ writeRealtimeOfflineDraft(draftToWrite);
2585
2562
  }, [clearDraftPersistSchedule, roomId]);
2586
2563
  const scheduleDraftPersistence = react.useCallback(() => {
2587
2564
  clearDraftPersistSchedule();
@@ -2700,7 +2677,6 @@ function useRealtimeSession(options) {
2700
2677
  baseRevision,
2701
2678
  items: mergedItems,
2702
2679
  updatedAt: nowMs(),
2703
- yDocState: encodeYDocState(board),
2704
2680
  pendingIds: Array.from(pendingIds)
2705
2681
  });
2706
2682
  scheduleDraftPersistenceRef.current?.();
@@ -2808,7 +2784,6 @@ function useRealtimeSession(options) {
2808
2784
  baseRevision: serverDocument.revision,
2809
2785
  items: mergedItems,
2810
2786
  updatedAt: nowMs(),
2811
- yDocState: encodeYDocState(board),
2812
2787
  pendingIds: Array.from(pendingIds)
2813
2788
  });
2814
2789
  outboundInFlightRef.current = null;
@@ -3123,7 +3098,6 @@ function useRealtimeSession(options) {
3123
3098
  baseRevision: currentRevisionRef.current,
3124
3099
  items: mergedItems,
3125
3100
  updatedAt: nowMs(),
3126
- yDocState: board ? encodeYDocState(board) : void 0,
3127
3101
  pendingIds: board ? Array.from(getLocallyPendingItemIds(board)) : void 0
3128
3102
  });
3129
3103
  queuedDirtyRef.current = true;
@@ -3239,7 +3213,6 @@ function useRealtimeSession(options) {
3239
3213
  baseRevision: currentRevisionRef.current,
3240
3214
  items: mergedItems,
3241
3215
  updatedAt: nowMs(),
3242
- yDocState: encodeYDocState(board),
3243
3216
  pendingIds: Array.from(pendingIds)
3244
3217
  });
3245
3218
  }