Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 21, 2023
1 parent a894bc1 commit 29500e8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions public/squint/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ <h3 class="text-center sans-serif font-bold text-lg mt-0 mb-1">Try evaluating an
<p class="sans-serif text-sm text-center mb-6 mt-0">
In-browser eval is powered by <a href="https://github.com/squint-cljs/squint">Squint</a>.
</p>
<div id="editor" class="rounded-md mb-0 text-sm monospace overflow-auto relative border shadow-lg bg-white">
</div>
<div id="editor" class="rounded-md mb-0 text-sm monospace overflow-auto relative border shadow-lg bg-white"></div>
<div id="result" class="mt-3.mv-4.pl-6" style="white-space: pre-wrap; font-family: var(--code-font)"></div>
</div>
<div class="md:w-1/2 flex-shrink-0 md:px-6 sans-serif">
<ul class="text-lg">
Expand Down
33 changes: 27 additions & 6 deletions public/squint/js/demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,38 @@ let evalCell = (opts) => {
console.log('evalopts', opts.state.doc.toString());
}

let evalAtCursor = async function (opts) {
let state = opts.state;
let code = cursor_node_string(state);
let evalCode = async function (code) {
console.log('code', code);
let js = compileString(code, {repl: true,
context: 'return',
"elide-exports": true});
console.log(js);
console.log('evalAtCursor', await eval(`(async function() { ${js} })()`));
"elide-exports": true})
console.log('js', js);
let result;
try {
result = {value: await eval(`(async function() { ${js} })()`)};
}
catch (e) {
result = {error: true, ex: e};
}
if (result.error) {
document.getElementById("result").innerText = result.ex;
} else {
document.getElementById("result").innerText = JSON.stringify(result.value, null, 2);
}
}

let evalAtCursor = function (opts) {
let state = opts.state;
let code = cursor_node_string(state);
evalCode(code);
}

let squintExtension = ( opts ) => {
return keymap.of([{key: "Alt-Enter", run: evalCell},
{key: opts.modifier + "-Enter",
run: evalAtCursor}])}


let extensions = [ theme, foldGutter(),
syntaxHighlighting(defaultHighlightStyle),
drawSelection(),
Expand All @@ -68,6 +85,10 @@ let state = EditorState.create( {doc: `(comment
5 "buzz"
n))`,
extensions: extensions });

console.log(state.doc.toString());
evalCode(state.doc.toString());

let editorElt = document.querySelector('#editor');
let editor = new EditorView({state: state,
parent: editorElt,
Expand Down

0 comments on commit 29500e8

Please sign in to comment.