From 6196fba286cc511a3b902bb10362bef20a7c64fd Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Tue, 14 Jun 2022 17:56:05 +0530 Subject: [PATCH] docs: migrate example to typescript (#5243) * docs: migrate example to typescript * fix * fix sidebar * fix --- .../excalidraw/example/{App.js => App.tsx} | 271 +++++++++++------- .../example/{index.js => index.tsx} | 0 .../sidebar/{Sidebar.js => Sidebar.tsx} | 6 +- .../excalidraw/webpack.dev-server.config.js | 2 +- 4 files changed, 173 insertions(+), 106 deletions(-) rename src/packages/excalidraw/example/{App.js => App.tsx} (74%) rename src/packages/excalidraw/example/{index.js => index.tsx} (100%) rename src/packages/excalidraw/example/sidebar/{Sidebar.js => Sidebar.tsx} (82%) diff --git a/src/packages/excalidraw/example/App.js b/src/packages/excalidraw/example/App.tsx similarity index 74% rename from src/packages/excalidraw/example/App.js rename to src/packages/excalidraw/example/App.tsx index 9cbe95c0..644a596b 100644 --- a/src/packages/excalidraw/example/App.js +++ b/src/packages/excalidraw/example/App.tsx @@ -1,12 +1,13 @@ import { useEffect, useState, useRef, useCallback } from "react"; -import InitialData from "./initialData"; import Sidebar from "./sidebar/Sidebar"; import "./App.scss"; import initialData from "./initialData"; import { nanoid } from "nanoid"; import { + resolvablePromise, + ResolvablePromise, withBatchedUpdates, withBatchedUpdatesThrottled, } from "../../../utils"; @@ -14,7 +15,42 @@ import { EVENT } from "../../../constants"; import { distance2d } from "../../../math"; import { fileOpen } from "../../../data/filesystem"; import { loadSceneOrLibraryFromBlob } from "../../utils"; +import { + AppState, + BinaryFileData, + ExcalidrawImperativeAPI, + ExcalidrawInitialDataState, + Gesture, + LibraryItems, + PointerDownState as ExcalidrawPointerDownState, +} from "../../../types"; +import { ExcalidrawElement } from "../../../element/types"; +import { ImportedLibraryData } from "../../../data/types"; +declare global { + interface Window { + ExcalidrawLib: any; + } +} + +type Comment = { + x: number; + y: number; + value: string; + id?: string; +}; + +type PointerDownState = { + x: number; + y: number; + hitElement: Comment; + onMove: any; + onUp: any; + hitElementOffsets: { + x: number; + y: number; + }; +}; // This is so that we use the bundled excalidraw.development.js file instead // of the actual source code @@ -28,6 +64,7 @@ const { MIME_TYPES, sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, + restoreElements, } = window.ExcalidrawLib; const COMMENT_SVG = ( @@ -41,7 +78,7 @@ const COMMENT_SVG = ( stroke-width="2" stroke-linecap="round" stroke-linejoin="round" - class="feather feather-message-circle" + className="feather feather-message-circle" > @@ -50,18 +87,6 @@ const COMMENT_ICON_DIMENSION = 32; const COMMENT_INPUT_HEIGHT = 50; const COMMENT_INPUT_WIDTH = 150; -const resolvablePromise = () => { - let resolve; - let reject; - const promise = new Promise((_resolve, _reject) => { - resolve = _resolve; - reject = _reject; - }); - promise.resolve = resolve; - promise.reject = reject; - return promise; -}; - const renderTopRightUI = () => { return ( - {props.children} + {children} ); diff --git a/src/packages/excalidraw/webpack.dev-server.config.js b/src/packages/excalidraw/webpack.dev-server.config.js index 41c40aeb..4e8df899 100644 --- a/src/packages/excalidraw/webpack.dev-server.config.js +++ b/src/packages/excalidraw/webpack.dev-server.config.js @@ -5,7 +5,7 @@ const devConfig = require("./webpack.dev.config"); const devServerConfig = { entry: { - bundle: "./example/index.js", + bundle: "./example/index.tsx", }, // Server Configuration options devServer: {