mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: remove bound-arrows from frames (#7157)
This commit is contained in:
parent
5b94cffc74
commit
dde3dac931
7 changed files with 81 additions and 16 deletions
|
@ -43,6 +43,7 @@ import {
|
|||
measureBaseline,
|
||||
} from "../element/textElement";
|
||||
import { normalizeLink } from "./url";
|
||||
import { isValidFrameChild } from "../frame";
|
||||
|
||||
type RestoredAppState = Omit<
|
||||
AppState,
|
||||
|
@ -396,7 +397,7 @@ const repairBoundElement = (
|
|||
};
|
||||
|
||||
/**
|
||||
* Remove an element's frameId if its containing frame is non-existent
|
||||
* resets `frameId` if no longer applicable.
|
||||
*
|
||||
* NOTE mutates elements.
|
||||
*/
|
||||
|
@ -404,12 +405,16 @@ const repairFrameMembership = (
|
|||
element: Mutable<ExcalidrawElement>,
|
||||
elementsMap: Map<string, Mutable<ExcalidrawElement>>,
|
||||
) => {
|
||||
if (element.frameId) {
|
||||
const containingFrame = elementsMap.get(element.frameId);
|
||||
if (!element.frameId) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!containingFrame) {
|
||||
element.frameId = null;
|
||||
}
|
||||
if (
|
||||
!isValidFrameChild(element) ||
|
||||
// target frame not exists
|
||||
!elementsMap.get(element.frameId)
|
||||
) {
|
||||
element.frameId = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -453,6 +458,8 @@ export const restoreElements = (
|
|||
// repair binding. Mutates elements.
|
||||
const restoredElementsMap = arrayToMap(restoredElements);
|
||||
for (const element of restoredElements) {
|
||||
// repair frame membership *after* bindings we do in restoreElement()
|
||||
// since we rely on bindings to be correct
|
||||
if (element.frameId) {
|
||||
repairFrameMembership(element, restoredElementsMap);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue