Skip to content

Commit 49953ab

Browse files
committed
Add playground folder
1 parent 5d41c5b commit 49953ab

File tree

10 files changed

+765
-2
lines changed

10 files changed

+765
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"packages": [
55
"packages/mdx",
66
"examples/*",
7+
"playground",
78
"site"
89
]
910
},

playground/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
27+
# Contentlayer
28+
.contentlayer

playground/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.jsx"></script>
12+
</body>
13+
</html>

playground/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "playground",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vite build",
8+
"preview": "vite preview"
9+
},
10+
"dependencies": {
11+
"@code-hike/mdx": "^0.5.1",
12+
"@codemirror/basic-setup": "^0.20.0",
13+
"@codemirror/commands": "^0.20.0",
14+
"@codemirror/lang-markdown": "^0.20.1",
15+
"@codemirror/state": "^0.20.0",
16+
"@codemirror/view": "^0.20.5",
17+
"@mdx-js/mdx": "^2.1.1",
18+
"@monaco-editor/react": "^4.4.5",
19+
"react": "^17.0.2",
20+
"react-dom": "^17.0.2"
21+
},
22+
"devDependencies": {
23+
"@types/react": "^17.0.2",
24+
"@types/react-dom": "^17.0.2",
25+
"@vitejs/plugin-react": "^1.3.0",
26+
"vite": "^2.9.9"
27+
}
28+
}

playground/src/app.jsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { useRef, useEffect } from "react";
2+
import * as runtime from "react/jsx-runtime.js";
3+
import Editor from "@monaco-editor/react";
4+
import { useState } from "react";
5+
6+
import { compile, run } from "@mdx-js/mdx";
7+
8+
const defaultCode = `
9+
# Hello
10+
11+
This is a markdown editor.
12+
13+
~~~py foo.py
14+
print "Hello, world!";
15+
~~~
16+
17+
`;
18+
19+
function App() {
20+
const [code, setCode] = useState(defaultCode);
21+
const [Content, setContent] = useState(undefined);
22+
function handleEditorChange(value, event) {
23+
setCode(value);
24+
}
25+
26+
useEffect(() => {
27+
compile(code, { outputFormat: "function-body" })
28+
.then((c) => run(String(c), runtime))
29+
.then((x) => setContent(x.default));
30+
}, [code]);
31+
return (
32+
<div className="app">
33+
<header>
34+
<h1>Code Hike</h1> v0.5.1
35+
</header>
36+
<main>
37+
<Editor
38+
className="editor"
39+
onChange={handleEditorChange}
40+
defaultLanguage="markdown"
41+
theme="vs-dark"
42+
defaultValue={defaultCode}
43+
options={{
44+
// https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.IEditorConstructionOptions.html
45+
minimap: {
46+
enabled: false,
47+
},
48+
lineNumbers: "off",
49+
scrollBeyondLastLine: false,
50+
hideCursorInOverviewRuler: true,
51+
matchBrackets: false,
52+
overviewRulerBorder: false,
53+
renderLineHighlight: "none",
54+
wordWrap: "on",
55+
tabSize: 2,
56+
}}
57+
/>
58+
<div className="preview">{Content}</div>
59+
</main>
60+
</div>
61+
);
62+
}
63+
64+
export default App;

playground/src/favicon.svg

Lines changed: 15 additions & 0 deletions
Loading

playground/src/index.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
body {
2+
margin: 0;
3+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
4+
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
5+
sans-serif;
6+
-webkit-font-smoothing: antialiased;
7+
-moz-osx-font-smoothing: grayscale;
8+
}
9+
10+
html,
11+
body,
12+
#root {
13+
height: 100%;
14+
}
15+
16+
.app {
17+
display: flex;
18+
flex-direction: column;
19+
width: 100%;
20+
height: 100%;
21+
}
22+
header {
23+
background-color: cadetblue;
24+
display: flex;
25+
align-items: baseline;
26+
gap: 0.4rem;
27+
padding: 0 1rem;
28+
}
29+
30+
header h1 {
31+
margin: 0;
32+
}
33+
34+
main {
35+
display: flex;
36+
flex: 1 1 auto;
37+
overflow: hidden;
38+
}
39+
40+
.editor {
41+
min-width: 400px;
42+
/* background-color: #222;
43+
color: white; */
44+
}
45+
46+
.preview {
47+
min-width: 600px;
48+
border-left: 2px solid cadetblue;
49+
padding: 1em;
50+
}

playground/src/main.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import App from "./app";
4+
import "./index.css";
5+
6+
ReactDOM.render(
7+
<React.StrictMode>
8+
<App />
9+
</React.StrictMode>,
10+
document.getElementById("root")
11+
);

playground/vite.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vite'
2+
import react from '@vitejs/plugin-react'
3+
4+
// https://vitejs.dev/config/
5+
export default defineConfig({
6+
plugins: [react()]
7+
})

0 commit comments

Comments
 (0)