From 444c4d87125273e8828a8a0cb6a8d2688cde3ca8 Mon Sep 17 00:00:00 2001 From: irfanpena Date: Fri, 16 Aug 2024 15:48:58 +0700 Subject: [PATCH] hotfix --- src/components/Diagram/index.tsx | 85 +++++++++++++++++--------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/src/components/Diagram/index.tsx b/src/components/Diagram/index.tsx index 7542b55..658faf9 100644 --- a/src/components/Diagram/index.tsx +++ b/src/components/Diagram/index.tsx @@ -1,51 +1,56 @@ import BrowserOnly from "@docusaurus/BrowserOnly"; -import { Excalidraw, loadFromBlob } from "@excalidraw/excalidraw"; import { ExcalidrawImperativeAPI } from "@excalidraw/excalidraw/types/types"; -import { useEffect, useState } from "react"; interface DiagramProps { diagramPath: string; } export default function Diagram({ diagramPath }: DiagramProps) { - // return ( - // - // {() => { - const [excalidrawAPI, setExcalidrawAPI] = - useState(null); + + {() => { + const { Excalidraw, loadFromBlob } = + require("@excalidraw/excalidraw") as typeof import("@excalidraw/excalidraw"); + const { useState, useEffect } = + require("react") as typeof import("react"); - useEffect(() => { - if (excalidrawAPI !== null) { - fetch(diagramPath) - .then((res) => res.blob()) - .then((blob) => loadFromBlob(blob, excalidrawAPI.getAppState(), null)) - .then((data) => { - excalidrawAPI.updateScene(data); + function ExcalidrawDiagram({ diagramPath }: DiagramProps) { + const [excalidrawAPI, setExcalidrawAPI] = + useState(null); - // excalidrawAPI.setActiveTool({ type: "hand", locked: true }); - }); - } - }, [excalidrawAPI]); + useEffect(() => { + if (excalidrawAPI !== null) { + fetch(diagramPath) + .then((res) => res.blob()) + .then((blob) => + loadFromBlob(blob, excalidrawAPI.getAppState(), null) + ) + .then((data) => { + excalidrawAPI.updateScene(data); + }); + } + }, [excalidrawAPI]); - return ( -
- setExcalidrawAPI(api)} - isCollaborating={false} - zenModeEnabled={false} - viewModeEnabled={true} - gridModeEnabled={false} - UIOptions={{ - canvasActions: { - export: false, - loadScene: false, - saveToActiveFile: false, - }, - }} - /> -
- ); - // }} - //
- // ); -} + return ( +
+ setExcalidrawAPI(api)} + isCollaborating={false} + zenModeEnabled={false} + viewModeEnabled={true} + gridModeEnabled={false} + UIOptions={{ + canvasActions: { + export: false, + loadScene: false, + saveToActiveFile: false, + }, + }} + /> +
+ ); + } + + return ; + }} +
; +} \ No newline at end of file