diff --git a/node_modules/y-excalidraw/dist/y-excalidraw.cjs b/node_modules/y-excalidraw/dist/y-excalidraw.cjs
index 169b24a..7e8d58c 100644
--- a/node_modules/y-excalidraw/dist/y-excalidraw.cjs
+++ b/node_modules/y-excalidraw/dist/y-excalidraw.cjs
@@ -152,7 +152,12 @@ var getDeltaOperationsForElements = (lastKnownElements, newElements, bulkify = t
         leftSortIndex = opsTracker.idMap[opsTracker.elementIds[toIndex - 1]]?.pos || null;
         rightSortIndex = opsTracker.idMap[opsTracker.elementIds[toIndex]]?.pos || null;
       }
-      const newSortIndex = (0, import_fractional_indexing.generateKeyBetween)(leftSortIndex, rightSortIndex);
+      let newSortIndex;
+      try {
+        newSortIndex = (0, import_fractional_indexing.generateKeyBetween)(leftSortIndex, rightSortIndex);
+      } catch (e) {
+        newSortIndex = (0, import_fractional_indexing.generateKeyBetween)(leftSortIndex, null);
+      }
       opsTracker.elementIds = moveArrayItem(opsTracker.elementIds, fromIndex, toIndex, true);
       opsTracker.idMap[id].pos = newSortIndex;
       _updateIdIndexLookup();
diff --git a/node_modules/y-excalidraw/dist/y-excalidraw.js b/node_modules/y-excalidraw/dist/y-excalidraw.js
index 84ad536..8fb25b3 100644
--- a/node_modules/y-excalidraw/dist/y-excalidraw.js
+++ b/node_modules/y-excalidraw/dist/y-excalidraw.js
@@ -118,7 +118,13 @@ var getDeltaOperationsForElements = (lastKnownElements, newElements, bulkify = t
         leftSortIndex = opsTracker.idMap[opsTracker.elementIds[toIndex - 1]]?.pos || null;
         rightSortIndex = opsTracker.idMap[opsTracker.elementIds[toIndex]]?.pos || null;
       }
-      const newSortIndex = generateKeyBetween(leftSortIndex, rightSortIndex);
+      let newSortIndex;
+      try {
+        newSortIndex = generateKeyBetween(leftSortIndex, rightSortIndex);
+      } catch (e) {
+        // При дубликатах pos (например после вставки изображения) left >= right
+        newSortIndex = generateKeyBetween(leftSortIndex, null);
+      }
       opsTracker.elementIds = moveArrayItem(opsTracker.elementIds, fromIndex, toIndex, true);
       opsTracker.idMap[id].pos = newSortIndex;
       _updateIdIndexLookup();
@@ -393,6 +399,7 @@ var ExcalidrawBinding = class {
     this.collaborators = collaborators;
   }
   setupUndoRedo(excalidrawDom) {
+    if (!excalidrawDom) return;
     this.undoManager.addTrackedOrigin(this);
     this.subscriptions.push(() => this.undoManager.removeTrackedOrigin(this));
     const _keyPressHandler = (event) => {
@@ -420,12 +427,12 @@ var ExcalidrawBinding = class {
       if (!undoButton || !undoButton.isConnected) {
         undoButton?.removeEventListener("click", _undoBtnHandler);
         undoButton = excalidrawDom.querySelector('[aria-label="Undo"]');
-        undoButton.addEventListener("click", _undoBtnHandler);
+        if (undoButton) undoButton.addEventListener("click", _undoBtnHandler);
       }
       if (!redoButton || !redoButton.isConnected) {
         redoButton?.removeEventListener("click", _redoBtnHandler);
         redoButton = excalidrawDom.querySelector('[aria-label="Redo"]');
-        redoButton.addEventListener("click", _redoBtnHandler);
+        if (redoButton) redoButton.addEventListener("click", _redoBtnHandler);
       }
     };
     const ro = new ResizeObserver(debounce(_resizeListener, 100));
