fix: restoreElementWithProperties drops "parent" property (#5742)

Co-authored-by: Yosyp Buchma <yo@yosyp.co>
Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
Joseph Buchma
2022-10-08 21:42:05 +03:00
committed by GitHub
parent 76cf560914
commit e9a224a0de
5 changed files with 41 additions and 19 deletions

View File

@ -1,3 +1,4 @@
import { PRECEDING_ELEMENT_KEY } from "../../constants";
import { ExcalidrawElement } from "../../element/types";
import { AppState } from "../../types";
@ -6,7 +7,7 @@ export type ReconciledElements = readonly ExcalidrawElement[] & {
};
export type BroadcastedExcalidrawElement = ExcalidrawElement & {
parent?: string;
[PRECEDING_ELEMENT_KEY]?: string;
};
const shouldDiscardRemoteElement = (
@ -71,8 +72,8 @@ export const reconcileElements = (
const local = localElementsData[remoteElement.id];
if (shouldDiscardRemoteElement(localAppState, local?.[0], remoteElement)) {
if (remoteElement.parent) {
delete remoteElement.parent;
if (remoteElement[PRECEDING_ELEMENT_KEY]) {
delete remoteElement[PRECEDING_ELEMENT_KEY];
}
continue;
@ -92,10 +93,12 @@ export const reconcileElements = (
// parent may not be defined in case the remote client is running an older
// excalidraw version
const parent =
remoteElement.parent || remoteElements[remoteElementIdx - 1]?.id || null;
remoteElement[PRECEDING_ELEMENT_KEY] ||
remoteElements[remoteElementIdx - 1]?.id ||
null;
if (parent != null) {
delete remoteElement.parent;
delete remoteElement[PRECEDING_ELEMENT_KEY];
// ^ indicates the element is the first in elements array
if (parent === "^") {