diff --git a/.gitignore b/.gitignore index c6e3baf7..59488e74 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* + +.claude +CLAUDE.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 8069f151..9d73430f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Unreleased +### v2.1.0 + +- Upgrade mermaid to 11.12.1 +- Add ERD support + ### Features - Support ClassDef for styling the nodes by [@ad1992](https://github.com/ad1992) in https://github.com/excalidraw/mermaid-to-excalidraw/pull/71 diff --git a/package.json b/package.json index 5578427d..f7f43fb2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@excalidraw/mermaid-to-excalidraw", - "version": "1.1.4", + "version": "2.1.1", "description": "Mermaid to Excalidraw Diagrams", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -11,7 +11,8 @@ "scripts": { "build": "rimraf -rf ./dist && cross-env tsc -b src", "test:code": "eslint --max-warnings=0 --ext .js,.ts,.tsx .", - "start": "vite playground", + "dev": "vite playground --mode development", + "start": "vite playground --mode development", "build:playground": "tsc --noEmit --project ./playground/tsconfig.json && vite build playground", "preview": "yarn run build:playground && vite preview --outDir ./public", "test": "vitest", @@ -20,15 +21,15 @@ }, "dependencies": { "@excalidraw/markdown-to-text": "0.1.2", - "mermaid": "10.9.4", - "nanoid": "4.0.2", - "react-split": "^2.0.14" + "@mermaid-js/parser": "^0.6.3", + "mermaid": "^11.12.1", + "nanoid": "4.0.2" }, "devDependencies": { "@babel/core": "7.12.0", "@excalidraw/eslint-config": "1.0.3", - "@excalidraw/excalidraw": "0.17.1-7381-cdf6d3e", - "@types/mermaid": "9.2.0", + "@excalidraw/excalidraw": "^0.18.0-816c81c", + "@types/mermaid": "^9.2.0", "@types/react": "18.2.14", "@types/react-dom": "18.2.4", "@typescript-eslint/eslint-plugin": "5.59.9", diff --git a/playground/CustomTest.tsx b/playground/CustomTest.tsx index 5b6c061a..1f851007 100644 --- a/playground/CustomTest.tsx +++ b/playground/CustomTest.tsx @@ -1,5 +1,7 @@ +import { useState, useEffect } from "react"; import { MermaidDiagram } from "./MermaidDiagram.tsx"; import type { ActiveTestCaseIndex, MermaidData } from "./index.tsx"; +import { usePersistedSectionState } from "./usePersistedSectionState.ts"; interface CustomTestProps { onChange: ( @@ -10,57 +12,112 @@ interface CustomTestProps { activeTestCaseIndex: ActiveTestCaseIndex; } +const STORAGE_KEY = "mermaid-to-excalidraw-definition"; + const CustomTest = ({ onChange, mermaidData, activeTestCaseIndex, }: CustomTestProps) => { const isActive = activeTestCaseIndex === "custom"; + const { + isExpanded: isParsedDataExpanded, + handleToggle: handleParsedDataToggle, + } = usePersistedSectionState("custom:parsed-data"); + const [textareaValue, setTextareaValue] = useState(() => { + // Load from localStorage on initial mount + try { + return localStorage.getItem(STORAGE_KEY) || ""; + } catch { + return ""; + } + }); + + // Update textarea when mermaidData changes from external source + useEffect(() => { + if (mermaidData.definition && activeTestCaseIndex !== "custom") { + setTextareaValue(mermaidData.definition); + } + }, [mermaidData.definition, activeTestCaseIndex]); + return ( <>
{ e.preventDefault(); const formData = new FormData(e.target as HTMLFormElement); + const definition = formData.get("mermaid-input")?.toString() || ""; - onChange(formData.get("mermaid-input")?.toString() || "", "custom"); + // Save to localStorage + try { + localStorage.setItem(STORAGE_KEY, definition); + } catch (error) { + console.error("Failed to save to localStorage:", error); + } + + onChange(definition, "custom"); }} > +