This commit is contained in:
Aakansha Doshi 2023-05-03 00:48:11 +05:30
parent 15b5295baf
commit 7087db42c0
5 changed files with 18 additions and 16 deletions

View file

@ -1,4 +1,3 @@
//@ts-nocheck
import { import {
ExcalidrawElement, ExcalidrawElement,
ExcalidrawSelectionElement, ExcalidrawSelectionElement,
@ -393,7 +392,9 @@ export const restoreElements = (
migratedElement = { ...migratedElement, id: randomId() }; migratedElement = { ...migratedElement, id: randomId() };
} }
existingIds.add(migratedElement.id); existingIds.add(migratedElement.id);
//@ts-ignore
if (element.children?.length) { if (element.children?.length) {
//@ts-ignore
const newElements = updateElementChildren(element); const newElements = updateElementChildren(element);
if (newElements) { if (newElements) {
elements.push(...newElements); elements.push(...newElements);
@ -552,7 +553,6 @@ export const restore = (
localElements: readonly ExcalidrawElement[] | null | undefined, localElements: readonly ExcalidrawElement[] | null | undefined,
elementsConfig?: { refreshDimensions?: boolean; repairBindings?: boolean }, elementsConfig?: { refreshDimensions?: boolean; repairBindings?: boolean },
): RestoredDataState => { ): RestoredDataState => {
console.log(restoreElements(data?.elements, localElements, elementsConfig));
return { return {
elements: restoreElements(data?.elements, localElements, elementsConfig), elements: restoreElements(data?.elements, localElements, elementsConfig),
appState: restoreAppState(data?.appState, localAppState || null), appState: restoreAppState(data?.appState, localAppState || null),

View file

@ -1,4 +1,4 @@
import { ExcalidrawElement, ExcalidrawTextContainer } from "../element/types"; import { ExcalidrawElement } from "../element/types";
import { import {
AppState, AppState,
BinaryFiles, BinaryFiles,
@ -8,8 +8,6 @@ import {
import type { cleanAppStateForExport } from "../appState"; import type { cleanAppStateForExport } from "../appState";
import { VERSIONS } from "../constants"; import { VERSIONS } from "../constants";
import { ElementConstructorOpts } from "../element/newElement";
export interface ExportedDataState { export interface ExportedDataState {
type: string; type: string;
version: number; version: number;

View file

@ -12,6 +12,7 @@ import {
ExcalidrawFreeDrawElement, ExcalidrawFreeDrawElement,
FontFamilyValues, FontFamilyValues,
ExcalidrawTextContainer, ExcalidrawTextContainer,
NonDeletedExcalidrawElement,
} from "../element/types"; } from "../element/types";
import { import {
arrayToMap, arrayToMap,
@ -48,6 +49,7 @@ import {
} from "../constants"; } from "../constants";
import { isArrowElement, isTextElement } from "./typeChecks"; import { isArrowElement, isTextElement } from "./typeChecks";
import { MarkOptional, Merge, Mutable } from "../utility-types"; import { MarkOptional, Merge, Mutable } from "../utility-types";
import { Children } from "react";
export type ElementConstructorOpts = MarkOptional< export type ElementConstructorOpts = MarkOptional<
Omit<ExcalidrawGenericElement, "id" | "type" | "isDeleted" | "updated">, Omit<ExcalidrawGenericElement, "id" | "type" | "isDeleted" | "updated">,
@ -647,14 +649,19 @@ export const duplicateElements = (
return clonedElements; return clonedElements;
}; };
export const updateElementChildren = ( export const updateElementChildren = (element: {
element: { type: ExcalidrawGenericElement["type"];
type: ExcalidrawElement["type"]; children?: [
} & MarkOptional<ElementConstructorOpts, "x" | "y">, { text: string } & MarkOptional<ElementConstructorOpts, "x" | "y">,
) => { ] &
const textElement = element.children!.find((child) => child.text !== null); MarkOptional<ElementConstructorOpts, "x" | "y">;
}) => {
const textElement = element.children?.find(
(
child: { text: string } & MarkOptional<ElementConstructorOpts, "x" | "y">,
) => child.text !== null,
);
if (isValidTextContainer(element) && textElement) { if (isValidTextContainer(element) && textElement) {
//@ts-ignore
const elements = bindTextToContainer(element, textElement); const elements = bindTextToContainer(element, textElement);
return elements; return elements;
} }

View file

@ -66,9 +66,6 @@ type _ExcalidrawElementBase = Readonly<{
link: string | null; link: string | null;
locked: boolean; locked: boolean;
customData?: Record<string, any>; customData?: Record<string, any>;
children?: [
{ text: string } & MarkOptional<ElementConstructorOpts, "x" | "y">,
];
}>; }>;
export type ExcalidrawSelectionElement = _ExcalidrawElementBase & { export type ExcalidrawSelectionElement = _ExcalidrawElementBase & {

View file

@ -349,9 +349,9 @@ const ExcalidrawWrapper = () => {
version: 2, version: 2,
source: "http://localhost:3000", source: "http://localhost:3000",
elements: [ elements: [
//@ts-ignore
{ {
type: "rectangle", type: "rectangle",
//@ts-ignore
children: [{ text: "HELLO DAMMMMY" }], children: [{ text: "HELLO DAMMMMY" }],
}, },
], ],