canvu-react 0.4.79 → 0.4.80
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 +33 -0
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.js +33 -0
- package/dist/realtime.js.map +1 -1
- package/dist/realtimeNative.cjs +33 -0
- package/dist/realtimeNative.cjs.map +1 -1
- package/dist/realtimeNative.js +33 -0
- package/dist/realtimeNative.js.map +1 -1
- package/package.json +1 -1
package/dist/realtime.cjs
CHANGED
|
@@ -2120,6 +2120,38 @@ function normalizeRealtimeItem(item) {
|
|
|
2120
2120
|
normalized.childrenSvg = "";
|
|
2121
2121
|
return normalized;
|
|
2122
2122
|
}
|
|
2123
|
+
function reorderYItemsToMatchLocalItems(yItems, items) {
|
|
2124
|
+
const currentItems = readVectorItems(yItems);
|
|
2125
|
+
const currentItemsById = /* @__PURE__ */ new Map();
|
|
2126
|
+
for (const currentItem of currentItems) {
|
|
2127
|
+
const id = getItemId(currentItem);
|
|
2128
|
+
if (id) currentItemsById.set(id, currentItem);
|
|
2129
|
+
}
|
|
2130
|
+
const orderedItems = [];
|
|
2131
|
+
const orderedIds = /* @__PURE__ */ new Set();
|
|
2132
|
+
for (const item of items) {
|
|
2133
|
+
const id = getItemId(item);
|
|
2134
|
+
if (!id) continue;
|
|
2135
|
+
const currentItem = currentItemsById.get(id);
|
|
2136
|
+
if (!currentItem) continue;
|
|
2137
|
+
orderedItems.push(currentItem);
|
|
2138
|
+
orderedIds.add(id);
|
|
2139
|
+
}
|
|
2140
|
+
for (const currentItem of currentItems) {
|
|
2141
|
+
const id = getItemId(currentItem);
|
|
2142
|
+
if (!id || !orderedIds.has(id)) orderedItems.push(currentItem);
|
|
2143
|
+
}
|
|
2144
|
+
const alreadyOrdered = currentItems.length === orderedItems.length && currentItems.every((currentItem, index) => {
|
|
2145
|
+
const nextItem = orderedItems[index];
|
|
2146
|
+
return nextItem ? getItemId(currentItem) === getItemId(nextItem) : false;
|
|
2147
|
+
});
|
|
2148
|
+
if (alreadyOrdered) return;
|
|
2149
|
+
if (yItems.length > 0) yItems.delete(0, yItems.length);
|
|
2150
|
+
yItems.insert(
|
|
2151
|
+
0,
|
|
2152
|
+
orderedItems.map((item) => vectorItemToYMap(item))
|
|
2153
|
+
);
|
|
2154
|
+
}
|
|
2123
2155
|
function applyLocalItemsToYDoc(board, options) {
|
|
2124
2156
|
const { items, origin } = options;
|
|
2125
2157
|
const addedIds = [];
|
|
@@ -2163,6 +2195,7 @@ function applyLocalItemsToYDoc(board, options) {
|
|
|
2163
2195
|
board.yItems.push([yMap]);
|
|
2164
2196
|
addedIds.push(id);
|
|
2165
2197
|
}
|
|
2198
|
+
reorderYItemsToMatchLocalItems(board.yItems, items);
|
|
2166
2199
|
}, origin);
|
|
2167
2200
|
return { addedIds, removedIds };
|
|
2168
2201
|
}
|