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.js
CHANGED
|
@@ -2095,6 +2095,38 @@ function normalizeRealtimeItem(item) {
|
|
|
2095
2095
|
normalized.childrenSvg = "";
|
|
2096
2096
|
return normalized;
|
|
2097
2097
|
}
|
|
2098
|
+
function reorderYItemsToMatchLocalItems(yItems, items) {
|
|
2099
|
+
const currentItems = readVectorItems(yItems);
|
|
2100
|
+
const currentItemsById = /* @__PURE__ */ new Map();
|
|
2101
|
+
for (const currentItem of currentItems) {
|
|
2102
|
+
const id = getItemId(currentItem);
|
|
2103
|
+
if (id) currentItemsById.set(id, currentItem);
|
|
2104
|
+
}
|
|
2105
|
+
const orderedItems = [];
|
|
2106
|
+
const orderedIds = /* @__PURE__ */ new Set();
|
|
2107
|
+
for (const item of items) {
|
|
2108
|
+
const id = getItemId(item);
|
|
2109
|
+
if (!id) continue;
|
|
2110
|
+
const currentItem = currentItemsById.get(id);
|
|
2111
|
+
if (!currentItem) continue;
|
|
2112
|
+
orderedItems.push(currentItem);
|
|
2113
|
+
orderedIds.add(id);
|
|
2114
|
+
}
|
|
2115
|
+
for (const currentItem of currentItems) {
|
|
2116
|
+
const id = getItemId(currentItem);
|
|
2117
|
+
if (!id || !orderedIds.has(id)) orderedItems.push(currentItem);
|
|
2118
|
+
}
|
|
2119
|
+
const alreadyOrdered = currentItems.length === orderedItems.length && currentItems.every((currentItem, index) => {
|
|
2120
|
+
const nextItem = orderedItems[index];
|
|
2121
|
+
return nextItem ? getItemId(currentItem) === getItemId(nextItem) : false;
|
|
2122
|
+
});
|
|
2123
|
+
if (alreadyOrdered) return;
|
|
2124
|
+
if (yItems.length > 0) yItems.delete(0, yItems.length);
|
|
2125
|
+
yItems.insert(
|
|
2126
|
+
0,
|
|
2127
|
+
orderedItems.map((item) => vectorItemToYMap(item))
|
|
2128
|
+
);
|
|
2129
|
+
}
|
|
2098
2130
|
function applyLocalItemsToYDoc(board, options) {
|
|
2099
2131
|
const { items, origin } = options;
|
|
2100
2132
|
const addedIds = [];
|
|
@@ -2138,6 +2170,7 @@ function applyLocalItemsToYDoc(board, options) {
|
|
|
2138
2170
|
board.yItems.push([yMap]);
|
|
2139
2171
|
addedIds.push(id);
|
|
2140
2172
|
}
|
|
2173
|
+
reorderYItemsToMatchLocalItems(board.yItems, items);
|
|
2141
2174
|
}, origin);
|
|
2142
2175
|
return { addedIds, removedIds };
|
|
2143
2176
|
}
|