From d017cbfd916e54d34bc2cec94a1ea9c9d4c41340 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Tue, 21 Nov 2023 15:53:12 +0100 Subject: [PATCH] wip --- package.json | 6 +++--- public/squint/js/demo.mjs | 34 ++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 6f66940..935dfb6 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "@lezer/lr": "^1.0.0", "@nextjournal/lezer-clojure": "1.0.0", "squint-cljs": "0.4.57", - "@squint-cljs/macros": "0.1.0", "w3c-keyname": "^2.2.4" }, "comments": { @@ -35,7 +34,7 @@ "build": "shadow-cljs -A:demo release demo livedoc", "test": "shadow-cljs -A:dev release ci-test && node out/node-tests.js", "watch2": "git ls-files | entr yarn test", - "vite:dev": "vite --open -l info --config vite.config.js public/squint", + "vite:dev": "vite --debug hmr --open -l info --config vite.config.js public/squint", "vite:build": "yarn vite build --config vite.config.js public/squint" }, "devDependencies": { @@ -55,7 +54,8 @@ "react-dom": "^17.0.2", "rollup-plugin-analyzer": "^4.0.0", "shadow-cljs": "2.19.5", - "vite": "^4.4.9" + "vite": "^4.4.9", + "@squint-cljs/macros": "0.1.0" }, "exports": { ".": "./dist/nextjournal/clojure_mode.mjs", diff --git a/public/squint/js/demo.mjs b/public/squint/js/demo.mjs index d9e5a22..edff33a 100644 --- a/public/squint/js/demo.mjs +++ b/public/squint/js/demo.mjs @@ -29,12 +29,21 @@ let evalCell = (opts) => { console.log('evalopts', opts.state.doc.toString()); } +function JSONstringify(json) { + json = JSON.stringify(json, function(key, value) { + if (value && typeof value === 'object' && value.constructor != Object) { + return `#object[${value.constructor.name}]`; + } else { + return value; + } + }); + return json; +} + let evalCode = async function (code) { - console.log('code', code); - let js = compileString(code, {repl: true, - context: 'return', - "elide-exports": true}) - console.log('js', js); + let js = compileString(`(do ${code})`, {repl: true, + context: 'return', + "elide-exports": true}) let result; try { result = {value: await eval(`(async function() { ${js} })()`)}; @@ -45,7 +54,7 @@ let evalCode = async function (code) { if (result.error) { document.getElementById("result").innerText = result.ex; } else { - document.getElementById("result").innerText = JSON.stringify(result.value, null, 2); + document.getElementById("result").innerText = '' + JSONstringify(result.value); } } @@ -70,7 +79,7 @@ let extensions = [ theme, foldGutter(), squintExtension({modifier: "Meta"}) ]; -let state = EditorState.create( {doc: `(comment +export let doc = `(comment (fizz-buzz 1) (fizz-buzz 3) (fizz-buzz 5) @@ -83,13 +92,14 @@ let state = EditorState.create( {doc: `(comment 15 "fizzbuzz" 3 "fizz" 5 "buzz" - n))`, - extensions: extensions }); + n))` ; -console.log(state.doc.toString()); -evalCode(state.doc.toString()); +evalCode(doc); + +let state = EditorState.create( {doc: doc, + extensions: extensions }); let editorElt = document.querySelector('#editor'); let editor = new EditorView({state: state, parent: editorElt, - extensions: extensions }); + extensions: extensions })