diff --git a/.github/workflows/webeditor.yml b/.github/workflows/web_editor.yml similarity index 97% rename from .github/workflows/webeditor.yml rename to .github/workflows/web_editor.yml index de9b87d..ce03540 100644 --- a/.github/workflows/webeditor.yml +++ b/.github/workflows/web_editor.yml @@ -85,8 +85,8 @@ jobs: - name: Precompile SWI-Prolog files to qlf run: pnpm build:swipl-public-qlf - - name: Build Clojurescript web editor app - run: pnpm build:webeditor + - name: Build web editor app + run: pnpm build:web-editor - name: Setup Pages uses: actions/configure-pages@v5 diff --git a/package.json b/package.json index e097358..6b6214e 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,12 @@ }, "scripts": { "preinstall": "npx only-allow pnpm", - "start": "shadow-cljs watch webeditor", - "build:webeditor": "shadow-cljs release webeditor", + "start": "shadow-cljs watch web-editor", + "build:web-editor": "shadow-cljs release web-editor", "build:browser-esm-lib": "shadow-cljs release browser-esm-lib", "build:py-node-lib": "shadow-cljs release py-node-lib", "build:node-lib": "shadow-cljs release node-lib", - "build:all": "shadow-cljs release webeditor && shadow-cljs release browser-esm-lib && shadow-cljs release node-lib && shadow-cljs release py-node-lib", + "build:all": "shadow-cljs release web-editor && shadow-cljs release browser-esm-lib && shadow-cljs release node-lib && shadow-cljs release py-node-lib", "build:swipl-qlfs": "cd public/resources/swipl && swipl -t 'qcompile(prelude, [include(user)])' && cd ../../../src/l4_lp_py/swipl/prolog && swipl -t 'qcompile(prelude, [include(user)])' && cd ../../../../../../../", "build:swipl-public-qlf": "cd public/resources/swipl && swipl -t 'qcompile(prelude, [include(user)])'", "run:node-eg": "poetry run node public/node_example_usage.js", diff --git a/shadow-cljs.edn b/shadow-cljs.edn index ba1acfb..d4697ff 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -2,12 +2,12 @@ {:deps true :dev-http {8000 "public"} :builds - {:webeditor + {:web-editor {:target :esm :output-dir "public/js" - :modules {:l4_webeditor {:init-fn l4-lp.webeditor.main/init!}} - :devtools {:before-load l4-lp.webeditor.main/stop! - :after-load l4-lp.webeditor.main/start!} + :modules {:l4_web_editor {:init-fn l4-lp.web-editor.main/init!}} + :devtools {:before-load l4-lp.web-editor.main/stop! + :after-load l4-lp.web-editor.main/start!} :compiler-options {:output-feature-set :es2021 :externs ["datascript/externs.js"]}} diff --git a/src/l4_lp/swipl/js/wasm_query.cljs b/src/l4_lp/swipl/js/wasm_query.cljs index e1f656c..1de67f5 100644 --- a/src/l4_lp/swipl/js/wasm_query.cljs +++ b/src/l4_lp/swipl/js/wasm_query.cljs @@ -5,8 +5,10 @@ [promesa.core :as prom] [shadow.esm :refer [dynamic-import]])) -(def ^:private swipl-wasm-cdn-url - "https://SWI-Prolog.github.io/npm-swipl-wasm/3/7/5/dynamic-import.js") +(def ^:private swipl-constructor + (prom/let [cdn-url "https://SWI-Prolog.github.io/npm-swipl-wasm/3/7/5/dynamic-import.js" + mod (dynamic-import cdn-url)] + (jsi/get mod :SWIPL))) (def ^:private prelude-qlf-url "resources/swipl/prelude.qlf") @@ -17,10 +19,8 @@ ;; TODO: Document and clean up this function. (defn query-and-trace! [program goal] (prom/let - [^js swipl-mod (dynamic-import swipl-wasm-cdn-url) - swipl (-> swipl-mod - (jsi/get :SWIPL) - (new #js {:arguments #js ["-q"]})) + [Swipl swipl-constructor + swipl (Swipl. #js {:arguments #js ["-q"]}) stack-trace (transient []) diff --git a/src/l4_lp/webeditor/codemirror_editor.cljs b/src/l4_lp/web_editor/codemirror_editor.cljs similarity index 93% rename from src/l4_lp/webeditor/codemirror_editor.cljs rename to src/l4_lp/web_editor/codemirror_editor.cljs index 93c4515..5b99786 100644 --- a/src/l4_lp/webeditor/codemirror_editor.cljs +++ b/src/l4_lp/web_editor/codemirror_editor.cljs @@ -1,4 +1,4 @@ -(ns l4-lp.webeditor.codemirror-editor +(ns l4-lp.web-editor.codemirror-editor (:require ["@codemirror/commands" :as cm-cmds] ["@codemirror/language" :as cm-lang] ["@codemirror/state" :as cm-state] @@ -6,7 +6,7 @@ ["@nextjournal/clojure-mode" :as cm-clj] ["@uiw/codemirror-theme-solarized" :as cm-solarized] [applied-science.js-interop :as jsi] - [l4-lp.webeditor.guifier :refer [query-and-trace-and-guifier!]])) + [l4-lp.web-editor.guifier :refer [query-and-trace-and-guifier!]])) ;; https://blog.jakubholy.net/2023/interactive-code-snippets-fulcro/ ;; https://github.com/nextjournal/clojure-mode diff --git a/src/l4_lp/webeditor/guifier.cljs b/src/l4_lp/web_editor/guifier.cljs similarity index 72% rename from src/l4_lp/webeditor/guifier.cljs rename to src/l4_lp/web_editor/guifier.cljs index 0f7d051..cd2546a 100644 --- a/src/l4_lp/webeditor/guifier.cljs +++ b/src/l4_lp/web_editor/guifier.cljs @@ -1,4 +1,4 @@ -(ns l4-lp.webeditor.guifier +(ns l4-lp.web-editor.guifier (:require [applied-science.js-interop :as jsi] [l4-lp.swipl.js.wasm-query :as swipl-wasm-query] [l4-lp.syntax.l4-to-prolog :as l4->prolog] @@ -6,14 +6,12 @@ [shadow.esm :refer [dynamic-import]])) (def ^:private guifier - {:cdn-url "https://cdn.jsdelivr.net/npm/guifier@1.0.24/dist/Guifier.js" - :element-id "guifier" - :constructor (atom nil)}) - -(defn init! [] - (prom/let [guifier-mod (dynamic-import (:cdn-url guifier)) - Guifier (jsi/get guifier-mod :default)] - (reset! (:constructor guifier) Guifier))) + {:element-id "guifier" + :constructor + (prom/let + [cdn-url "https://cdn.jsdelivr.net/npm/guifier@1.0.24/dist/Guifier.js" + mod (dynamic-import cdn-url)] + (jsi/get mod :default))}) (def ^:private query (-> "query" l4->prolog/l4->prolog-str)) @@ -31,7 +29,7 @@ stack-trace (swipl-wasm-query/query-and-trace-js! program query) - Guifier @(:constructor guifier)] + Guifier (:constructor guifier)] (Guifier. #js {:data stack-trace :dataType "js" :elementSelector (str "#" (:element-id guifier)) diff --git a/src/l4_lp/webeditor/main.cljs b/src/l4_lp/web_editor/main.cljs similarity index 87% rename from src/l4_lp/webeditor/main.cljs rename to src/l4_lp/web_editor/main.cljs index 04c9340..11e20e2 100644 --- a/src/l4_lp/webeditor/main.cljs +++ b/src/l4_lp/web_editor/main.cljs @@ -1,10 +1,8 @@ -(ns l4-lp.webeditor.main +(ns l4-lp.web-editor.main (:require [applied-science.js-interop :as jsi] [hoplon.core :as h] [hoplon.goog] - [l4-lp.webeditor.codemirror-editor :refer [bind-editor!]] - [l4-lp.webeditor.guifier :as guifier] - [promesa.core :as prom])) + [l4-lp.web-editor.codemirror-editor :refer [bind-editor!]])) (def ^:private initial-editor-text ";; Enter an L4 program here, and then press M-Enter to evaluate the query. @@ -74,6 +72,5 @@ DECIDE b of 0 and _ OTHERWISE") (defn init! [] (mount-components!) - (prom/let [_ (guifier/init!)] - (bind-editor! initial-editor-text) - (start!))) \ No newline at end of file + (bind-editor! initial-editor-text) + (start!)) \ No newline at end of file