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 +4 -31
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.js +4 -31
- package/dist/realtime.js.map +1 -1
- package/package.json +1 -1
package/dist/realtime.js
CHANGED
|
@@ -2116,32 +2116,6 @@ function applyServerSnapshotToYDoc(board, options) {
|
|
|
2116
2116
|
const { items: snapshotItems, origin } = options;
|
|
2117
2117
|
const now = Date.now();
|
|
2118
2118
|
board.doc.transact(() => {
|
|
2119
|
-
const snapshotIds = /* @__PURE__ */ new Set();
|
|
2120
|
-
const snapshotById = /* @__PURE__ */ new Map();
|
|
2121
|
-
for (const item of snapshotItems) {
|
|
2122
|
-
const id = getItemId(item);
|
|
2123
|
-
if (!id) continue;
|
|
2124
|
-
snapshotIds.add(id);
|
|
2125
|
-
snapshotById.set(id, item);
|
|
2126
|
-
}
|
|
2127
|
-
const currentIndex = indexYItemsById(board.yItems);
|
|
2128
|
-
const toDeleteIds = [];
|
|
2129
|
-
for (const [id] of currentIndex) {
|
|
2130
|
-
if (snapshotIds.has(id)) continue;
|
|
2131
|
-
if (board.lastServerConfirmedIds.has(id)) {
|
|
2132
|
-
toDeleteIds.push(id);
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
if (toDeleteIds.length > 0) {
|
|
2136
|
-
const refreshed = indexYItemsById(board.yItems);
|
|
2137
|
-
const sortedIndices = toDeleteIds.map((id) => ({ id, index: refreshed.get(id)?.index })).filter(
|
|
2138
|
-
(entry) => entry.index != null
|
|
2139
|
-
).sort((a, b) => b.index - a.index);
|
|
2140
|
-
for (const { id, index } of sortedIndices) {
|
|
2141
|
-
board.yItems.delete(index, 1);
|
|
2142
|
-
board.serverItemSeenAt.delete(id);
|
|
2143
|
-
}
|
|
2144
|
-
}
|
|
2145
2119
|
for (const item of snapshotItems) {
|
|
2146
2120
|
const id = getItemId(item);
|
|
2147
2121
|
if (!id) continue;
|
|
@@ -2556,7 +2530,10 @@ function useRealtimeSession(options) {
|
|
|
2556
2530
|
removeRealtimeOfflineDraft(roomId);
|
|
2557
2531
|
return;
|
|
2558
2532
|
}
|
|
2559
|
-
|
|
2533
|
+
const board = boardRef.current;
|
|
2534
|
+
const draft = localDraftRef.current;
|
|
2535
|
+
const draftToWrite = board && draft.yDocState == null ? { ...draft, yDocState: encodeYDocState(board) } : draft;
|
|
2536
|
+
writeRealtimeOfflineDraft(draftToWrite);
|
|
2560
2537
|
}, [clearDraftPersistSchedule, roomId]);
|
|
2561
2538
|
const scheduleDraftPersistence = useCallback(() => {
|
|
2562
2539
|
clearDraftPersistSchedule();
|
|
@@ -2675,7 +2652,6 @@ function useRealtimeSession(options) {
|
|
|
2675
2652
|
baseRevision,
|
|
2676
2653
|
items: mergedItems,
|
|
2677
2654
|
updatedAt: nowMs(),
|
|
2678
|
-
yDocState: encodeYDocState(board),
|
|
2679
2655
|
pendingIds: Array.from(pendingIds)
|
|
2680
2656
|
});
|
|
2681
2657
|
scheduleDraftPersistenceRef.current?.();
|
|
@@ -2783,7 +2759,6 @@ function useRealtimeSession(options) {
|
|
|
2783
2759
|
baseRevision: serverDocument.revision,
|
|
2784
2760
|
items: mergedItems,
|
|
2785
2761
|
updatedAt: nowMs(),
|
|
2786
|
-
yDocState: encodeYDocState(board),
|
|
2787
2762
|
pendingIds: Array.from(pendingIds)
|
|
2788
2763
|
});
|
|
2789
2764
|
outboundInFlightRef.current = null;
|
|
@@ -3098,7 +3073,6 @@ function useRealtimeSession(options) {
|
|
|
3098
3073
|
baseRevision: currentRevisionRef.current,
|
|
3099
3074
|
items: mergedItems,
|
|
3100
3075
|
updatedAt: nowMs(),
|
|
3101
|
-
yDocState: board ? encodeYDocState(board) : void 0,
|
|
3102
3076
|
pendingIds: board ? Array.from(getLocallyPendingItemIds(board)) : void 0
|
|
3103
3077
|
});
|
|
3104
3078
|
queuedDirtyRef.current = true;
|
|
@@ -3214,7 +3188,6 @@ function useRealtimeSession(options) {
|
|
|
3214
3188
|
baseRevision: currentRevisionRef.current,
|
|
3215
3189
|
items: mergedItems,
|
|
3216
3190
|
updatedAt: nowMs(),
|
|
3217
|
-
yDocState: encodeYDocState(board),
|
|
3218
3191
|
pendingIds: Array.from(pendingIds)
|
|
3219
3192
|
});
|
|
3220
3193
|
}
|