preserve z-index by pushing all elements first and then add bindings

This commit is contained in:
Aakansha Doshi
2023-08-02 20:40:39 +05:30
parent dcc4c28041
commit 93008d6a8d
2 changed files with 360 additions and 354 deletions
+13 -7
View File
@@ -441,20 +441,26 @@ export const convertToExcalidrawElements = (
if (!elements) {
return [];
}
// Push all elements to array as there could be cases where element id
// is referenced before element is created
elements.forEach((element) => {
let elementId = element.id || regenerateId(null);
// To make sure every element has a unique id
// To make sure every element has a unique id since regenerateId appends
// _copy to the original id and if it exists we need to generate again
// hence a loop
while (excalidrawElements.hasElementWithId(elementId)) {
elementId = regenerateId(elementId);
}
if (!ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(element.type)) {
excalidrawElements.add(element as ExcalidrawElement);
return;
}
const elementWithId = { ...element, id: elementId };
excalidrawElements.add(elementWithId as ExcalidrawElement);
});
const pushedElements =
excalidrawElements.get() as readonly ExcalidrawProgrammaticElement[];
pushedElements.forEach((element) => {
const elementWithId = { ...element };
if (
(elementWithId.type === "rectangle" ||