From 7087db42c02d28bd936a04b5649f1a12fd53b546 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Wed, 3 May 2023 00:48:11 +0530 Subject: [PATCH] fix --- src/data/restore.ts | 4 ++-- src/data/types.ts | 4 +--- src/element/newElement.ts | 21 ++++++++++++++------- src/element/types.ts | 3 --- src/excalidraw-app/index.tsx | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/data/restore.ts b/src/data/restore.ts index c4c041f21b..7af6e4a85a 100644 --- a/src/data/restore.ts +++ b/src/data/restore.ts @@ -1,4 +1,3 @@ -//@ts-nocheck import { ExcalidrawElement, ExcalidrawSelectionElement, @@ -393,7 +392,9 @@ export const restoreElements = ( migratedElement = { ...migratedElement, id: randomId() }; } existingIds.add(migratedElement.id); + //@ts-ignore if (element.children?.length) { + //@ts-ignore const newElements = updateElementChildren(element); if (newElements) { elements.push(...newElements); @@ -552,7 +553,6 @@ export const restore = ( localElements: readonly ExcalidrawElement[] | null | undefined, elementsConfig?: { refreshDimensions?: boolean; repairBindings?: boolean }, ): RestoredDataState => { - console.log(restoreElements(data?.elements, localElements, elementsConfig)); return { elements: restoreElements(data?.elements, localElements, elementsConfig), appState: restoreAppState(data?.appState, localAppState || null), diff --git a/src/data/types.ts b/src/data/types.ts index fd09530855..b8c9592185 100644 --- a/src/data/types.ts +++ b/src/data/types.ts @@ -1,4 +1,4 @@ -import { ExcalidrawElement, ExcalidrawTextContainer } from "../element/types"; +import { ExcalidrawElement } from "../element/types"; import { AppState, BinaryFiles, @@ -8,8 +8,6 @@ import { import type { cleanAppStateForExport } from "../appState"; import { VERSIONS } from "../constants"; -import { ElementConstructorOpts } from "../element/newElement"; - export interface ExportedDataState { type: string; version: number; diff --git a/src/element/newElement.ts b/src/element/newElement.ts index 2c9f68e48d..e16e090b1d 100644 --- a/src/element/newElement.ts +++ b/src/element/newElement.ts @@ -12,6 +12,7 @@ import { ExcalidrawFreeDrawElement, FontFamilyValues, ExcalidrawTextContainer, + NonDeletedExcalidrawElement, } from "../element/types"; import { arrayToMap, @@ -48,6 +49,7 @@ import { } from "../constants"; import { isArrowElement, isTextElement } from "./typeChecks"; import { MarkOptional, Merge, Mutable } from "../utility-types"; +import { Children } from "react"; export type ElementConstructorOpts = MarkOptional< Omit, @@ -647,14 +649,19 @@ export const duplicateElements = ( return clonedElements; }; -export const updateElementChildren = ( - element: { - type: ExcalidrawElement["type"]; - } & MarkOptional, -) => { - const textElement = element.children!.find((child) => child.text !== null); +export const updateElementChildren = (element: { + type: ExcalidrawGenericElement["type"]; + children?: [ + { text: string } & MarkOptional, + ] & + MarkOptional; +}) => { + const textElement = element.children?.find( + ( + child: { text: string } & MarkOptional, + ) => child.text !== null, + ); if (isValidTextContainer(element) && textElement) { - //@ts-ignore const elements = bindTextToContainer(element, textElement); return elements; } diff --git a/src/element/types.ts b/src/element/types.ts index 2fd18f9017..531858e2ff 100644 --- a/src/element/types.ts +++ b/src/element/types.ts @@ -66,9 +66,6 @@ type _ExcalidrawElementBase = Readonly<{ link: string | null; locked: boolean; customData?: Record; - children?: [ - { text: string } & MarkOptional, - ]; }>; export type ExcalidrawSelectionElement = _ExcalidrawElementBase & { diff --git a/src/excalidraw-app/index.tsx b/src/excalidraw-app/index.tsx index 36129c9085..0003b96b66 100644 --- a/src/excalidraw-app/index.tsx +++ b/src/excalidraw-app/index.tsx @@ -349,9 +349,9 @@ const ExcalidrawWrapper = () => { version: 2, source: "http://localhost:3000", elements: [ - //@ts-ignore { type: "rectangle", + //@ts-ignore children: [{ text: "HELLO DAMMMMY" }], }, ],