Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Theme Toggle #20

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
dist
# dist
.DS_Store
yarn-error.log
Binary file added docs/circom.26dc677c.wasm
Binary file not shown.
Binary file added docs/circomlib.acbc52cb.zip
Binary file not shown.
Binary file added docs/circomspect.516050fc.wasm
Binary file not shown.
Binary file added docs/codicon.ff6b888d.ttf
Binary file not shown.
823 changes: 823 additions & 0 deletions docs/index.48183d15.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/index.a7d6eacf.css

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<script type="module" crossorigin src="./index.48183d15.js"></script>
<link rel="stylesheet" href="./index.a7d6eacf.css">

<meta charset="utf8" />
<title>zkREPL</title>
<link rel="icon" href="./logo.effa8f98.png" />

<div id="root"></div>

Binary file added docs/logo.effa8f98.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,216 changes: 1,216 additions & 0 deletions docs/worker.5884bee1.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/editor.less
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ button {
position: relative;
z-index: 2;
flex-shrink: 0;
display: flex;
justify-content: space-between;

.tab {
display: inline-block;
Expand Down Expand Up @@ -243,6 +245,13 @@ button {
cursor: pointer;
color: #888;
}

.theme {
background: transparent;
width: 32px;
font-size: 18px;
margin-right: 10px;
}
}

.editor {
Expand Down
253 changes: 136 additions & 117 deletions src/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export var circomWorker: Worker
export default function App() {
const [running, setRunning] = React.useState<false | number>(false)
const [messages, setMessages] = React.useState<Message[]>([])
const [theme, setTheme] = React.useState<"vs" | "vs-dark">("vs")
const [editor, setEditor] =
React.useState<monaco.editor.IStandaloneCodeEditor | null>(null)
const modelsRef = React.useRef<monaco.editor.ITextModel[]>([])
Expand Down Expand Up @@ -296,6 +297,18 @@ export default function App() {
logIn()
}
}

const toggleTheme = () => {
if (theme === "vs") {
setTheme("vs-dark");
editor?.updateOptions({ theme: 'vs-dark' })
}
else {
setTheme("vs");
editor?.updateOptions({ theme: 'vs' })
}
}

React.useEffect(() => {
if (monacoEl && !editor) {
const editor = monaco.editor.create(monacoEl.current!, {
Expand Down Expand Up @@ -416,135 +429,141 @@ export default function App() {
<div className="layout">
<div className="primary">
<div className="tabs">
{modelsRef.current.map((file, modelIndex) => {
const deleteFile = (e: React.MouseEvent) => {
if (
(file?.getValue()?.length || 0) < 30 ||
file?.getValue() === codeExample ||
confirm(
`Are you sure you want to remove "${file.uri.path.slice(
1
)}"?`
)
) {
file.dispose()

if (modelsRef.current.length == 1) {
const model = monaco.editor.createModel(
codeExample,
"circom",
new monaco.Uri().with({
path: "main.circom",
})
<div>
{modelsRef.current.map((file, modelIndex) => {
const deleteFile = (e: React.MouseEvent) => {
if (
(file?.getValue()?.length || 0) < 30 ||
file?.getValue() === codeExample ||
confirm(
`Are you sure you want to remove "${file.uri.path.slice(
1
)}"?`
)
modelsRef.current.push(model)
editor!.setModel(model)
}
) {
file.dispose()

if (modelsRef.current.length == 1) {
const model = monaco.editor.createModel(
codeExample,
"circom",
new monaco.Uri().with({
path: "main.circom",
})
)
modelsRef.current.push(model)
editor!.setModel(model)
}

modelsRef.current.splice(modelIndex, 1)
editor?.setModel(modelsRef.current[0])
setMessages((k) => k.slice(0))
e.stopPropagation()
modelsRef.current.splice(modelIndex, 1)
editor?.setModel(modelsRef.current[0])
setMessages((k) => k.slice(0))
e.stopPropagation()
}
}
}

return (
<div
className={
"tab " +
(editor?.getModel()!.uri.path ===
file.uri.path
? "active"
: "inactive")
}
onClick={(e) => {
switchEditor(file)
}}
onMouseUp={(e) => {
if (e.button == 1) {
deleteFile(e)
return (
<div
className={
"tab " +
(editor?.getModel()!.uri.path ===
file.uri.path
? "active"
: "inactive")
}
}}
key={modelIndex}
>
<input
value={file.uri.path.slice(1)}
spellCheck={false}
onChange={(e) => {
const fileName = e.target.value
const fileExists =
modelsRef.current.some(
(k) =>
k.uri.path ===
"/" + fileName
)
if (!fileExists) {
const model =
monaco.editor.createModel(
file.getValue(),
"circom",
new monaco.Uri().with({
path: fileName,
})
)
file.dispose()
modelsRef.current.splice(
modelIndex,
1,
model
)
editor?.setModel(model)
}
e.target.style.width = "0px"
e.target.style.width =
e.target.scrollWidth + 2 + "px"

setMessages((k) => k.slice(0))
onClick={(e) => {
switchEditor(file)
}}
ref={(e) => {
if (e) {
e.style.width = "0px"
e.style.width =
e.scrollWidth + 2 + "px"
onMouseUp={(e) => {
if (e.button == 1) {
deleteFile(e)
}
}}
/>
key={modelIndex}
>
<input
value={file.uri.path.slice(1)}
spellCheck={false}
onChange={(e) => {
const fileName = e.target.value
const fileExists =
modelsRef.current.some(
(k) =>
k.uri.path ===
"/" + fileName
)
if (!fileExists) {
const model =
monaco.editor.createModel(
file.getValue(),
"circom",
new monaco.Uri().with({
path: fileName,
})
)
file.dispose()
modelsRef.current.splice(
modelIndex,
1,
model
)
editor?.setModel(model)
}
e.target.style.width = "0px"
e.target.style.width =
e.target.scrollWidth + 2 + "px"

<div className="x" onClick={deleteFile}>
<div>×</div>
setMessages((k) => k.slice(0))
}}
ref={(e) => {
if (e) {
e.style.width = "0px"
e.style.width =
e.scrollWidth + 2 + "px"
}
}}
/>

<div className="x" onClick={deleteFile}>
<div>×</div>
</div>
</div>
</div>
)
})}

<div
className="add"
onClick={() => {
let fileName = "untitled.circom"
for (
let i = 2;
modelsRef.current.some(
(k) => k.uri.path == "/" + fileName
);
i++
) {
fileName = `untitled${i}.circom`
}
const model = monaco.editor.createModel(
codeExample,
"circom",
new monaco.Uri().with({
path: fileName,
})
)
modelsRef.current.push(model)
editor!.setModel(model)
// trigger a re-render of this react component
setMessages(messages.slice(0))
}}
>
+ Add File
})}

<div
className="add"
onClick={() => {
let fileName = "untitled.circom"
for (
let i = 2;
modelsRef.current.some(
(k) => k.uri.path == "/" + fileName
);
i++
) {
fileName = `untitled${i}.circom`
}
const model = monaco.editor.createModel(
codeExample,
"circom",
new monaco.Uri().with({
path: fileName,
})
)
modelsRef.current.push(model)
editor!.setModel(model)
// trigger a re-render of this react component
setMessages(messages.slice(0))
}}
>
+ Add File
</div>
</div>

<button className="theme" onClick={toggleTheme}>
{theme == 'vs' ? "🌒" : "🌞"}
</button>
</div>

<div className="editor" ref={monacoEl}></div>
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineConfig({
base: "",
build: {
assetsDir: "",
outDir: 'docs',
target: ["es2020"],
},
optimizeDeps: {
Expand Down