canvu-react 0.4.7 → 0.4.8
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 +32 -2
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.js +32 -2
- package/dist/realtime.js.map +1 -1
- package/package.json +1 -1
package/dist/realtime.cjs
CHANGED
|
@@ -2021,6 +2021,7 @@ function createYjsBoardDoc() {
|
|
|
2021
2021
|
doc,
|
|
2022
2022
|
yItems,
|
|
2023
2023
|
lastServerConfirmedIds: /* @__PURE__ */ new Set(),
|
|
2024
|
+
lastServerConfirmedItemSerializations: /* @__PURE__ */ new Map(),
|
|
2024
2025
|
serverItemSeenAt: /* @__PURE__ */ new Map()
|
|
2025
2026
|
};
|
|
2026
2027
|
}
|
|
@@ -2077,6 +2078,10 @@ function valuesEqual(left, right) {
|
|
|
2077
2078
|
return false;
|
|
2078
2079
|
}
|
|
2079
2080
|
}
|
|
2081
|
+
function serializeItem(value) {
|
|
2082
|
+
const item = value instanceof Y__namespace.Map ? yMapToVectorItem(value) : value;
|
|
2083
|
+
return JSON.stringify(item);
|
|
2084
|
+
}
|
|
2080
2085
|
function updateYMapInPlace(yMap, next) {
|
|
2081
2086
|
const nextKeys = /* @__PURE__ */ new Set();
|
|
2082
2087
|
for (const [key, value] of Object.entries(next)) {
|
|
@@ -2146,6 +2151,14 @@ function applyServerSnapshotToYDoc(board, options) {
|
|
|
2146
2151
|
if (!id) continue;
|
|
2147
2152
|
const existing = indexYItemsById(board.yItems).get(id);
|
|
2148
2153
|
if (existing) {
|
|
2154
|
+
const currentSerialized = serializeItem(existing.yMap);
|
|
2155
|
+
const incomingSerialized = serializeItem(item);
|
|
2156
|
+
const confirmedSerialized = board.lastServerConfirmedItemSerializations.get(id);
|
|
2157
|
+
const hasPendingLocalChange = confirmedSerialized === void 0 ? currentSerialized !== incomingSerialized : currentSerialized !== confirmedSerialized && currentSerialized !== incomingSerialized;
|
|
2158
|
+
if (hasPendingLocalChange) {
|
|
2159
|
+
board.serverItemSeenAt.set(id, now);
|
|
2160
|
+
continue;
|
|
2161
|
+
}
|
|
2149
2162
|
updateYMapInPlace(existing.yMap, item);
|
|
2150
2163
|
board.serverItemSeenAt.set(id, now);
|
|
2151
2164
|
continue;
|
|
@@ -2156,9 +2169,13 @@ function applyServerSnapshotToYDoc(board, options) {
|
|
|
2156
2169
|
}
|
|
2157
2170
|
}, origin);
|
|
2158
2171
|
board.lastServerConfirmedIds = /* @__PURE__ */ new Set();
|
|
2172
|
+
board.lastServerConfirmedItemSerializations = /* @__PURE__ */ new Map();
|
|
2159
2173
|
for (const item of snapshotItems) {
|
|
2160
2174
|
const id = getItemId(item);
|
|
2161
|
-
if (id)
|
|
2175
|
+
if (id) {
|
|
2176
|
+
board.lastServerConfirmedIds.add(id);
|
|
2177
|
+
board.lastServerConfirmedItemSerializations.set(id, serializeItem(item));
|
|
2178
|
+
}
|
|
2162
2179
|
}
|
|
2163
2180
|
}
|
|
2164
2181
|
function replaceYDocWithSnapshot(board, options) {
|
|
@@ -2173,11 +2190,13 @@ function replaceYDocWithSnapshot(board, options) {
|
|
|
2173
2190
|
}
|
|
2174
2191
|
}, origin);
|
|
2175
2192
|
board.lastServerConfirmedIds = /* @__PURE__ */ new Set();
|
|
2193
|
+
board.lastServerConfirmedItemSerializations = /* @__PURE__ */ new Map();
|
|
2176
2194
|
board.serverItemSeenAt = /* @__PURE__ */ new Map();
|
|
2177
2195
|
for (const item of snapshotItems) {
|
|
2178
2196
|
const id = getItemId(item);
|
|
2179
2197
|
if (id) {
|
|
2180
2198
|
board.lastServerConfirmedIds.add(id);
|
|
2199
|
+
board.lastServerConfirmedItemSerializations.set(id, serializeItem(item));
|
|
2181
2200
|
board.serverItemSeenAt.set(id, now);
|
|
2182
2201
|
}
|
|
2183
2202
|
}
|
|
@@ -2189,7 +2208,8 @@ function getLocallyPendingItemIds(board) {
|
|
|
2189
2208
|
if (!yMap) continue;
|
|
2190
2209
|
const id = getItemId(yMap);
|
|
2191
2210
|
if (!id) continue;
|
|
2192
|
-
|
|
2211
|
+
const confirmedSerialized = board.lastServerConfirmedItemSerializations.get(id);
|
|
2212
|
+
if (!confirmedSerialized || serializeItem(yMap) !== confirmedSerialized) {
|
|
2193
2213
|
pending.add(id);
|
|
2194
2214
|
}
|
|
2195
2215
|
}
|
|
@@ -2729,6 +2749,7 @@ function useRealtimeSession(options) {
|
|
|
2729
2749
|
restoredFromBinary = decodeYDocState(board, draft.yDocState);
|
|
2730
2750
|
if (restoredFromBinary) {
|
|
2731
2751
|
const allIds = /* @__PURE__ */ new Set();
|
|
2752
|
+
const allItems = readVectorItems(board.yItems);
|
|
2732
2753
|
for (let i = 0; i < board.yItems.length; i++) {
|
|
2733
2754
|
const yMap = board.yItems.get(i);
|
|
2734
2755
|
if (!yMap) continue;
|
|
@@ -2737,9 +2758,17 @@ function useRealtimeSession(options) {
|
|
|
2737
2758
|
}
|
|
2738
2759
|
const pendingIds = new Set(draft.pendingIds ?? []);
|
|
2739
2760
|
board.lastServerConfirmedIds = /* @__PURE__ */ new Set();
|
|
2761
|
+
board.lastServerConfirmedItemSerializations = /* @__PURE__ */ new Map();
|
|
2740
2762
|
for (const id of allIds) {
|
|
2741
2763
|
if (!pendingIds.has(id)) {
|
|
2742
2764
|
board.lastServerConfirmedIds.add(id);
|
|
2765
|
+
const item = allItems.find((candidate) => candidate.id === id);
|
|
2766
|
+
if (item) {
|
|
2767
|
+
board.lastServerConfirmedItemSerializations.set(
|
|
2768
|
+
id,
|
|
2769
|
+
JSON.stringify(item)
|
|
2770
|
+
);
|
|
2771
|
+
}
|
|
2743
2772
|
}
|
|
2744
2773
|
}
|
|
2745
2774
|
}
|
|
@@ -2750,6 +2779,7 @@ function useRealtimeSession(options) {
|
|
|
2750
2779
|
origin: ORIGIN_BOOTSTRAP
|
|
2751
2780
|
});
|
|
2752
2781
|
board.lastServerConfirmedIds = /* @__PURE__ */ new Set();
|
|
2782
|
+
board.lastServerConfirmedItemSerializations = /* @__PURE__ */ new Map();
|
|
2753
2783
|
}
|
|
2754
2784
|
}
|
|
2755
2785
|
const items = board ? readVectorItems(board.yItems) : draft.items;
|