-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tldraw example * Drop devtools
- Loading branch information
Showing
3 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createWebView } from "../src/lib.ts"; | ||
import * as esbuild from "npm:esbuild"; | ||
|
||
const tldrawApp = ` | ||
import { Tldraw } from "tldraw"; | ||
import { createRoot } from "react-dom/client"; | ||
function App() { | ||
return ( | ||
<> | ||
<div style={{ position: "absolute", inset: 0 }}> | ||
<Tldraw cameraOptions={{ wheelBehavior: "zoom" }} /> | ||
</div> | ||
</> | ||
); | ||
} | ||
createRoot(document.querySelector("main")).render(<App />); | ||
`; | ||
|
||
const app = await esbuild.transform(tldrawApp, { | ||
loader: "jsx", | ||
jsx: "automatic", | ||
target: "esnext", | ||
format: "esm", | ||
minify: false, | ||
sourcemap: false, | ||
}); | ||
|
||
const webview = await createWebView({ | ||
title: "TLDraw", | ||
html: ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" /> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@500;700&display=swap"/> | ||
<link rel="stylesheet" href="https://esm.sh/[email protected]/tldraw.css"/> | ||
<style> body { font-family: "Inter"; } </style> | ||
</head> | ||
<body> | ||
<main></main> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"tldraw": "https://esm.sh/[email protected]?bundle-deps", | ||
"react/jsx-runtime": "https://esm.sh/[email protected]/jsx-runtime?bundle-deps", | ||
"react-dom/client": "https://esm.sh/[email protected]/client?bundle-deps" | ||
} | ||
} | ||
</script> | ||
<script type="module"> | ||
${app.code} | ||
</script> | ||
</body> | ||
</html> | ||
`, | ||
}); | ||
|
||
await webview.waitUntilClosed(); |