Skip to content

Commit

Permalink
fix: repair invalid binding on restore & fix type check (excalidraw#8133
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dwelle authored Jun 13, 2024
1 parent d2f67e6 commit 4dc4590
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
22 changes: 21 additions & 1 deletion packages/excalidraw/data/restore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
ExcalidrawElement,
ExcalidrawElementType,
ExcalidrawLinearElement,
ExcalidrawSelectionElement,
ExcalidrawTextElement,
FontFamilyValues,
Expand All @@ -21,7 +22,11 @@ import {
isInvisiblySmallElement,
refreshTextDimensions,
} from "../element";
import { isTextElement, isUsingAdaptiveRadius } from "../element/typeChecks";
import {
isLinearElement,
isTextElement,
isUsingAdaptiveRadius,
} from "../element/typeChecks";
import { randomId } from "../random";
import {
DEFAULT_FONT_FAMILY,
Expand Down Expand Up @@ -460,6 +465,21 @@ export const restoreElements = (
),
);
}

if (isLinearElement(element)) {
if (
element.startBinding &&
!restoredElementsMap.has(element.startBinding.elementId)
) {
(element as Mutable<ExcalidrawLinearElement>).startBinding = null;
}
if (
element.endBinding &&
!restoredElementsMap.has(element.endBinding.elementId)
) {
(element as Mutable<ExcalidrawLinearElement>).endBinding = null;
}
}
}

return restoredElements;
Expand Down
6 changes: 2 additions & 4 deletions packages/excalidraw/element/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,8 @@ const getOriginalBindingIfStillCloseOfLinearElementEdge = (
? linearElement.startBinding?.elementId
: linearElement.endBinding?.elementId;
if (elementId) {
const element = elementsMap.get(
elementId,
) as NonDeleted<ExcalidrawBindableElement>;
if (bindingBorderTest(element, coors, app)) {
const element = elementsMap.get(elementId);
if (isBindableElement(element) && bindingBorderTest(element, coors, app)) {
return element;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/excalidraw/element/typeChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const isBindingElementType = (
};

export const isBindableElement = (
element: ExcalidrawElement | null,
element: ExcalidrawElement | null | undefined,
includeLocked = true,
): element is ExcalidrawBindableElement => {
return (
Expand Down

0 comments on commit 4dc4590

Please sign in to comment.