fix(editor): Hardened fixed point and bound element parsing in restore (#10816)
* fix: Reinforce fixedPoint restore Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Even more hardened boundElement in restore Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Extract constant Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Remove superfluous check from restore Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * chore: Remove non-needed code path Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: More robust number test for fixedPoint parsing Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Validate bindings for element being parsed Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * unrelated type safety --------- Signed-off-by: Mark Tolmacs <mark@lazycat.hu> Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
@@ -155,7 +155,7 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
||||
| ExcalidrawElbowArrowElement["startBinding"]
|
||||
| ExcalidrawElbowArrowElement["endBinding"] = {
|
||||
...binding,
|
||||
fixedPoint: normalizeFixedPoint(binding.fixedPoint ?? [0, 0]),
|
||||
fixedPoint: normalizeFixedPoint(binding.fixedPoint),
|
||||
mode: binding.mode || "orbit",
|
||||
};
|
||||
|
||||
@@ -176,7 +176,7 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
||||
return {
|
||||
elementId: binding.elementId,
|
||||
mode: binding.mode,
|
||||
fixedPoint: normalizeFixedPoint(binding.fixedPoint || [0.5, 0.5]),
|
||||
fixedPoint: normalizeFixedPoint(binding.fixedPoint),
|
||||
} as FixedPointBinding | null;
|
||||
}
|
||||
return null;
|
||||
@@ -185,15 +185,14 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
||||
// binding schema v1 (legacy) -> attempt to migrate to v2
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const targetBoundElement =
|
||||
(targetElementsMap.get(binding.elementId) as ExcalidrawBindableElement) ||
|
||||
undefined;
|
||||
const targetBoundElement = targetElementsMap.get(binding.elementId) as
|
||||
| ExcalidrawBindableElement
|
||||
| undefined;
|
||||
const boundElement =
|
||||
targetBoundElement ||
|
||||
(existingElementsMap?.get(
|
||||
binding.elementId,
|
||||
) as ExcalidrawBindableElement) ||
|
||||
undefined;
|
||||
(existingElementsMap?.get(binding.elementId) as
|
||||
| ExcalidrawBindableElement
|
||||
| undefined);
|
||||
const elementsMap = targetBoundElement
|
||||
? targetElementsMap
|
||||
: existingElementsMap;
|
||||
@@ -208,11 +207,28 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
||||
const mode = isPointInElement(p, boundElement, elementsMap)
|
||||
? "inside"
|
||||
: "orbit";
|
||||
const safeElement = {
|
||||
...element,
|
||||
startBinding: element.startBinding?.elementId
|
||||
? {
|
||||
...element.startBinding,
|
||||
mode,
|
||||
fixedPoint: normalizeFixedPoint(element.startBinding.fixedPoint),
|
||||
}
|
||||
: null,
|
||||
endBinding: element.endBinding?.elementId
|
||||
? {
|
||||
...element.endBinding,
|
||||
mode,
|
||||
fixedPoint: normalizeFixedPoint(element.endBinding.fixedPoint),
|
||||
}
|
||||
: null,
|
||||
};
|
||||
const focusPoint =
|
||||
mode === "inside"
|
||||
? p
|
||||
: projectFixedPointOntoDiagonal(
|
||||
element,
|
||||
safeElement,
|
||||
p,
|
||||
boundElement,
|
||||
startOrEnd,
|
||||
@@ -220,7 +236,7 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
||||
{ value: 1 as NormalizedZoomValue },
|
||||
) || p;
|
||||
const { fixedPoint } = calculateFixedPointForNonElbowArrowBinding(
|
||||
element,
|
||||
safeElement,
|
||||
boundElement,
|
||||
startOrEnd,
|
||||
elementsMap,
|
||||
|
||||
Reference in New Issue
Block a user