mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
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:
parent
76cf560914
commit
e9a224a0de
5 changed files with 41 additions and 19 deletions
|
@ -18,6 +18,7 @@ import throttle from "lodash.throttle";
|
|||
import { newElementWith } from "../../element/mutateElement";
|
||||
import { BroadcastedExcalidrawElement } from "./reconciliation";
|
||||
import { encryptData } from "../../data/encryption";
|
||||
import { PRECEDING_ELEMENT_KEY } from "../../constants";
|
||||
|
||||
class Portal {
|
||||
collab: TCollabClass;
|
||||
|
@ -152,7 +153,7 @@ class Portal {
|
|||
acc.push({
|
||||
...element,
|
||||
// z-index info for the reconciler
|
||||
parent: idx === 0 ? "^" : elements[idx - 1]?.id,
|
||||
[PRECEDING_ELEMENT_KEY]: idx === 0 ? "^" : elements[idx - 1]?.id,
|
||||
});
|
||||
}
|
||||
return acc;
|
||||
|
|
|
@ -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 === "^") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue