From 43f1ec02f012a18c35d5596243a1ebb9ea253dd4 Mon Sep 17 00:00:00 2001 From: Chris Badahdah Date: Mon, 2 Dec 2024 23:34:46 -0700 Subject: [PATCH] Trying out Standard Clojure formatter --- .joyride/src/portal/format.cljs | 59 + deps.edn | 3 - dev/cljs/user.cljs | 2 +- dev/notebook/ci.clj | 13 +- dev/notebook/data.clj | 9 +- dev/notebook/scittle.clj | 89 +- dev/portal/runtime/debug.clj | 15 +- dev/portal/setup.cljs | 35 +- dev/portal/share.clj | 36 +- dev/reveal.clj | 3 +- dev/tasks/build.clj | 37 +- dev/tasks/check.clj | 9 +- dev/tasks/ci.clj | 7 +- dev/tasks/clean.clj | 7 +- dev/tasks/cljr.clj | 9 +- dev/tasks/deploy.clj | 9 +- dev/tasks/deps.clj | 3 +- dev/tasks/dev.clj | 21 +- dev/tasks/docs.clj | 103 +- dev/tasks/e2e.clj | 21 +- dev/tasks/format.clj | 7 +- dev/tasks/ide.clj | 7 +- dev/tasks/ijverify.clj | 3 +- dev/tasks/info.clj | 21 +- dev/tasks/jar.clj | 5 +- dev/tasks/kondo.clj | 25 +- dev/tasks/load.clj | 18 +- dev/tasks/package.clj | 33 +- dev/tasks/parallel.clj | 71 +- dev/tasks/planck.clj | 3 +- dev/tasks/prepl.cljc | 29 +- dev/tasks/pwa.clj | 85 +- dev/tasks/test.clj | 23 +- dev/tasks/tools.clj | 36 +- dev/tasks/version.clj | 26 +- dev/user.clj | 2 +- dev/workspace.cljs | 45 +- .../portal/extensions/intellij/factory.clj | 60 +- .../portal/extensions/intellij/file.clj | 26 +- .../portal/extensions/intellij/theme.clj | 36 +- package-lock.json | 474 +++++ package.json | 1 + src/examples/data.cljc | 1844 +++++++++-------- src/examples/default_visualizer.clj | 12 +- src/examples/fetch.cljs | 20 +- src/examples/hacker_news.cljc | 24 +- src/examples/macros.cljc | 7 +- src/portal/api.cljc | 47 +- src/portal/async.cljc | 55 +- src/portal/client/clr.clj | 31 +- src/portal/client/common.cljs | 46 +- src/portal/client/jvm.clj | 29 +- src/portal/client/node.cljs | 30 +- src/portal/client/planck.cljs | 5 +- src/portal/client/web.cljs | 2 +- src/portal/console.cljc | 48 +- src/portal/extensions/electron.cljs | 41 +- src/portal/extensions/pwa.cljs | 83 +- src/portal/extensions/vs_code.cljs | 143 +- src/portal/extensions/vs_code_notebook.cljs | 43 +- src/portal/main.clj | 14 +- src/portal/main.cljs | 1 - src/portal/nrepl.clj | 122 +- src/portal/resources.cljc | 33 +- src/portal/runtime.cljc | 307 +-- src/portal/runtime/browser.cljc | 170 +- src/portal/runtime/clr/assembly.clj | 26 +- src/portal/runtime/clr/client.clj | 29 +- src/portal/runtime/clr/launcher.clj | 65 +- src/portal/runtime/clr/server.clj | 93 +- src/portal/runtime/cson.cljc | 201 +- src/portal/runtime/datafy.cljc | 5 +- src/portal/runtime/edn.cljc | 35 +- src/portal/runtime/fs.cljc | 51 +- src/portal/runtime/index.cljc | 47 +- src/portal/runtime/json.cljc | 17 +- src/portal/runtime/json_buffer.cljc | 36 +- src/portal/runtime/jvm/client.clj | 37 +- src/portal/runtime/jvm/commands.clj | 13 +- src/portal/runtime/jvm/editor.clj | 87 +- src/portal/runtime/jvm/launcher.clj | 86 +- src/portal/runtime/jvm/server.clj | 99 +- src/portal/runtime/macros.cljc | 7 +- src/portal/runtime/node/client.cljs | 54 +- src/portal/runtime/node/launcher.cljs | 92 +- src/portal/runtime/node/server.cljs | 98 +- src/portal/runtime/npm.cljc | 74 +- src/portal/runtime/rpc.cljc | 20 +- src/portal/runtime/shell.cljc | 20 +- src/portal/runtime/transit.cljc | 23 +- src/portal/runtime/web/client.cljs | 10 +- src/portal/runtime/web/launcher.cljs | 30 +- src/portal/shadow/preload.cljs | 9 +- src/portal/shadow/remote.clj | 7 +- src/portal/shadow/remote.cljs | 63 +- src/portal/shortcuts.cljs | 15 +- src/portal/spec.cljc | 9 +- src/portal/sync.cljc | 3 +- src/portal/ui/api.cljs | 27 +- src/portal/ui/app.cljs | 292 +-- src/portal/ui/cljs.cljs | 3 +- src/portal/ui/commands.cljs | 627 +++--- src/portal/ui/connection_status.cljs | 50 +- src/portal/ui/core.cljs | 40 +- src/portal/ui/drag_and_drop.cljs | 48 +- src/portal/ui/embed.cljs | 72 +- src/portal/ui/filter.cljc | 62 +- src/portal/ui/html.cljs | 48 +- src/portal/ui/icons.cljs | 69 +- src/portal/ui/inspector.cljs | 414 ++-- src/portal/ui/lazy.cljc | 3 +- src/portal/ui/lazy.cljs | 65 +- src/portal/ui/load.cljs | 53 +- src/portal/ui/options.cljs | 17 +- src/portal/ui/parsers.cljs | 5 +- src/portal/ui/react.cljc | 19 +- src/portal/ui/repl/sci/eval.cljs | 72 +- src/portal/ui/repl/sci/import.cljc | 61 +- src/portal/ui/repl/sci/libs.cljs | 225 +- src/portal/ui/rpc.cljs | 121 +- src/portal/ui/rpc/runtime.cljs | 48 +- src/portal/ui/select.cljs | 18 +- src/portal/ui/state.cljs | 100 +- src/portal/ui/styled.cljs | 51 +- src/portal/ui/theme.cljs | 75 +- src/portal/ui/viewer/bin.cljs | 34 +- src/portal/ui/viewer/bytes.cljs | 3 +- src/portal/ui/viewer/charts.cljs | 12 +- src/portal/ui/viewer/cljdoc.cljs | 140 +- src/portal/ui/viewer/code.cljs | 184 +- src/portal/ui/viewer/color.cljs | 16 +- src/portal/ui/viewer/csv.cljs | 10 +- src/portal/ui/viewer/date_time.cljs | 18 +- src/portal/ui/viewer/deref.cljs | 22 +- src/portal/ui/viewer/diff.cljs | 58 +- src/portal/ui/viewer/diff_text.cljs | 148 +- src/portal/ui/viewer/duration.cljs | 3 +- src/portal/ui/viewer/edn.cljs | 10 +- src/portal/ui/viewer/exception.cljs | 116 +- src/portal/ui/viewer/hiccup.cljs | 188 +- src/portal/ui/viewer/html.cljs | 10 +- src/portal/ui/viewer/http.cljs | 20 +- src/portal/ui/viewer/image.cljs | 12 +- src/portal/ui/viewer/json.cljs | 8 +- src/portal/ui/viewer/jwt.cljs | 12 +- src/portal/ui/viewer/log.cljs | 68 +- src/portal/ui/viewer/markdown.cljs | 204 +- src/portal/ui/viewer/pprint.cljs | 22 +- src/portal/ui/viewer/prepl.cljs | 100 +- src/portal/ui/viewer/relative_time.cljs | 48 +- src/portal/ui/viewer/source_location.cljs | 26 +- src/portal/ui/viewer/spec.cljs | 102 +- src/portal/ui/viewer/table.cljs | 344 +-- src/portal/ui/viewer/test_report.cljs | 80 +- src/portal/ui/viewer/text.cljs | 82 +- src/portal/ui/viewer/transit.cljs | 10 +- src/portal/ui/viewer/tree.cljs | 160 +- src/portal/ui/viewer/vega.cljs | 96 +- src/portal/ui/viewer/vega_lite.cljs | 8 +- src/portal/viewer.cljc | 4 +- src/portal/web.cljs | 27 +- test/portal/bench.cljc | 23 +- test/portal/client_test.cljc | 41 +- test/portal/e2e.clj | 3 +- test/portal/runtime/api_test.clj | 11 +- test/portal/runtime/api_test.cljs | 9 +- test/portal/runtime/bench_cson.cljc | 195 +- test/portal/runtime/cson_test.cljc | 110 +- test/portal/runtime/edn_test.cljc | 7 +- test/portal/runtime/fs_test.cljc | 9 +- test/portal/runtime/json_buffer_test.cljc | 5 +- test/portal/runtime/jvm/editor_test.clj | 77 +- test/portal/runtime/npm_test.cljc | 21 +- test/portal/runtime/shell_test.cljc | 7 +- test/portal/runtime_test.cljc | 25 +- test/portal/test_clr.clj | 52 +- test/portal/test_planck.cljs | 19 +- test/portal/test_runner.clj | 33 +- test/portal/test_runner.cljs | 13 +- test/portal/test_runtime_runner.cljs | 47 +- test/portal/test_ui_runner.cljs | 21 +- test/portal/ui/state_test.cljs | 5 +- 182 files changed, 6414 insertions(+), 5553 deletions(-) create mode 100644 .joyride/src/portal/format.cljs diff --git a/.joyride/src/portal/format.cljs b/.joyride/src/portal/format.cljs new file mode 100644 index 00000000..02e83134 --- /dev/null +++ b/.joyride/src/portal/format.cljs @@ -0,0 +1,59 @@ +(ns portal.format + (:require + ["path" :as path] + ["vscode" :as vscode])) + +(defn- get-workspace-folder [] + (let [^js uri (-> vscode/workspace .-workspaceFolders (aget 0) .-uri) + fs-path (.-fsPath uri)] + (if-not (undefined? fs-path) fs-path (.-path uri)))) + +(defn- get-standard-npm-path [] + (path/join (get-workspace-folder) + "node_modules" + "@chrisoakman/standard-clojure-style" + "dist/standard-clojure-style.js")) + +(def ^:private standard (js/require (get-standard-npm-path))) + +;; (js/require "@chrisoakman/standard-clojure-style") + +;; ("./package.json") + +;; (defn- require-string [src file-name] +;; (let [Module (js/require "module") +;; ^js m (Module. file-name (some-> js/module .-parent))] +;; (set! (.-filename m) file-name) +;; (._compile m src file-name) +;; (.-exports m))) + +;; (defn require-url [url] +;; (-> (js/fetch url) +;; (.then #(.text %)) +;; (.then #(require-string % "standard-clojure-style.js")))) + +;; (defonce lib (atom nil)) + +;; (when-not @lib +;; (-> (require-url "https://raw.githubusercontent.com/oakmac/standard-clojure-style-js/refs/heads/master/lib/standard-clojure-style.js") +;; (.then #(reset! lib %)))) + +(defn formatter [model _options _token] + (let [code (.-out (.format standard (.getText model)))] + #js [(.replace vscode/TextEdit + (vscode.Range. + (.. (.lineAt model 0) -range -start) + (.. (.lineAt model (dec (.-lineCount model))) -range -end)) + code)])) + +(comment + (.registerDocumentFormattingEditProvider + vscode/languages "clojure" + #js {:displayName "Clojure Standard Formatter" + :provideDocumentFormattingEdits (fn [& args] (apply formatter args))}) + + (require '[portal.api :as p]) + (p/open {:launcher :vs-code}) + (add-tap #'p/submit) + + ,) \ No newline at end of file diff --git a/deps.edn b/deps.edn index 388878ac..7a45045a 100644 --- a/deps.edn +++ b/deps.edn @@ -56,9 +56,6 @@ {:extra-paths ["dev"] :main-opts ["-m" "tasks.kondo"] :extra-deps {clj-kondo/clj-kondo {:mvn/version "2024.08.01"}}} - :cljfmt - {:main-opts ["-m" "cljfmt.main"] - :extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}}} :cider {:extra-deps {nrepl/nrepl {:mvn/version "1.3.0"} diff --git a/dev/cljs/user.cljs b/dev/cljs/user.cljs index 8fc5af6e..ea5b559e 100644 --- a/dev/cljs/user.cljs +++ b/dev/cljs/user.cljs @@ -24,4 +24,4 @@ (require '[examples.data :refer [data]]) (dotimes [_i 25] (tap> data)) - comment) \ No newline at end of file + comment) diff --git a/dev/notebook/ci.clj b/dev/notebook/ci.clj index 1f5c4db0..2f1e0191 100644 --- a/dev/notebook/ci.clj +++ b/dev/notebook/ci.clj @@ -1,10 +1,11 @@ (ns notebook.ci - (:require [tasks.build :refer [build install]] - [tasks.check :as check] - [tasks.format :as fmt] - [tasks.parallel :refer [with-out-data]] - [tasks.test :as test] - [tasks.tools :as tool])) + (:require + [tasks.build :refer [build install]] + [tasks.check :as check] + [tasks.format :as fmt] + [tasks.parallel :refer [with-out-data]] + [tasks.test :as test] + [tasks.tools :as tool])) (check/cloc) (with-out-data (fmt/check)) (with-out-data (check/clj-kondo)) diff --git a/dev/notebook/data.clj b/dev/notebook/data.clj index 7d48f43f..aa9bebf4 100644 --- a/dev/notebook/data.clj +++ b/dev/notebook/data.clj @@ -1,7 +1,8 @@ (ns notebook.data - (:require [examples.data :as d] - [portal.colors :as c] - [portal.viewer :as v])) + (:require + [examples.data :as d] + [portal.colors :as c] + [portal.viewer :as v])) (::d/hacker-news d/data) @@ -24,7 +25,7 @@ (v/tree d/hiccup) (v/hiccup - [:portal.viewer/markdown (::d/markdown d/string-data)]) + [:portal.viewer/markdown (::d/markdown d/string-data)]) (-> d/exception-data) diff --git a/dev/notebook/scittle.clj b/dev/notebook/scittle.clj index 4ce04fcb..921271ee 100644 --- a/dev/notebook/scittle.clj +++ b/dev/notebook/scittle.clj @@ -1,9 +1,10 @@ (ns notebook.scittle - (:require [clojure.java.browse :as browse] - [clojure.string :as str] - [hiccup.page :as page] - [portal.api :as p] - [portal.viewer :as v])) + (:require + [clojure.java.browse :as browse] + [clojure.string :as str] + [hiccup.page :as page] + [portal.api :as p] + [portal.viewer :as v])) (def portal-dev (p/open {:mode :dev :launcher false})) @@ -21,8 +22,8 @@ (defn div-and-script [id widget] [[:div {:id id}] (scittle-script - (list 'dom/render (list 'fn [] widget) - (list '.getElementById 'js/document id)))]) + (list 'dom/render (list 'fn [] widget) + (list '.getElementById 'js/document id)))]) (defn pr-str-with-meta [value] (binding [*print-meta* true] @@ -33,51 +34,51 @@ (defn page [widgets] (page/html5 - [:head] - (into - [:body - (page/include-js "https://unpkg.com/react@18/umd/react.production.min.js" - "https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" - "https://scicloj.github.io/scittle/js/scittle.js" - "https://scicloj.github.io/scittle/js/scittle.reagent.js" - (portal-main-url portal-dev)) - (scittle-script '(ns main - (:require [reagent.core :as r] - [reagent.dom :as dom])) - '(defn portal-viewer [{:keys [edn-str]}] - (let [embed (js/portal_api.embed)] - [:div - [:div - {:ref (fn [el] - (.renderOutputItem embed - (clj->js {:mime "x-application/edn" - :theme "portal.colors/nord-light" - :text (fn [] edn-str)}) - el))}]])))] - (->> widgets - (map-indexed (fn [i widget] - (div-and-script (str "widget" i) - widget))) - (apply concat))))) + [:head] + (into + [:body + (page/include-js "https://unpkg.com/react@18/umd/react.production.min.js" + "https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" + "https://scicloj.github.io/scittle/js/scittle.js" + "https://scicloj.github.io/scittle/js/scittle.reagent.js" + (portal-main-url portal-dev)) + (scittle-script '(ns main + (:require [reagent.core :as r] + [reagent.dom :as dom])) + '(defn portal-viewer [{:keys [edn-str]}] + (let [embed (js/portal_api.embed)] + [:div + [:div + {:ref (fn [el] + (.renderOutputItem embed + (clj->js {:mime "x-application/edn" + :theme "portal.colors/nord-light" + :text (fn [] edn-str)}) + el))}]])))] + (->> widgets + (map-indexed (fn [i widget] + (div-and-script (str "widget" i) + widget))) + (apply concat))))) (defn img [url] (v/hiccup - [:img {:height 50 :width 50 - :src url}])) + [:img {:height 50 :width 50 + :src url}])) (defn md [text] (v/hiccup [:portal.viewer/markdown text])) (defn vega-lite-point-plot [data] (v/hiccup - [:portal.viewer/vega-lite - (-> {:data {:values data}, - :mark "point" - :encoding - {:size {:field "w" :type "quantitative"} - :x {:field "x", :type "quantitative"}, - :y {:field "y", :type "quantitative"}, - :fill {:field "z", :type "nominal"}}})])) + [:portal.viewer/vega-lite + (-> {:data {:values data} + :mark "point" + :encoding + {:size {:field "w" :type "quantitative"} + :x {:field "x", :type "quantitative"} + :y {:field "y", :type "quantitative"} + :fill {:field "z", :type "nominal"}}})])) (defn random-data [n] (->> (repeatedly n #(- (rand) 0.5)) @@ -110,4 +111,4 @@ (map portal-widget) page (spit "target/scittle.html")) - (browse/browse-url "target/scittle.html")) \ No newline at end of file + (browse/browse-url "target/scittle.html")) diff --git a/dev/portal/runtime/debug.clj b/dev/portal/runtime/debug.clj index fa3dd0fe..eed6389e 100644 --- a/dev/portal/runtime/debug.clj +++ b/dev/portal/runtime/debug.clj @@ -1,6 +1,7 @@ (ns portal.runtime.debug - (:require [portal.api :as p] - [portal.runtime :as rt])) + (:require + [portal.api :as p] + [portal.runtime :as rt])) (defn- section [title value] [(name title) @@ -28,10 +29,10 @@ (defn open [session] (p/inspect - (dashboard session) - (-> (:options session) - (dissoc :debug) - (assoc :window-title "portal-debug-server")))) + (dashboard session) + (-> (:options session) + (dissoc :debug) + (assoc :window-title "portal-debug-server")))) (defn close [instance] - (when instance (p/close instance))) \ No newline at end of file + (when instance (p/close instance))) diff --git a/dev/portal/setup.cljs b/dev/portal/setup.cljs index 9bece275..be5e0d53 100644 --- a/dev/portal/setup.cljs +++ b/dev/portal/setup.cljs @@ -1,18 +1,19 @@ (ns portal.setup - (:require [clojure.datafy :refer [datafy]] - [examples.data :refer [data]] - [portal.client.web :as remote] - [portal.console :as log] - [portal.runtime :as rt] - #_[portal.shadow.remote :as remote] - [portal.shortcuts :as shortcuts] - [portal.ui.api :as api] - [portal.ui.commands :as commands] - [portal.ui.inspector :as ins] - [portal.ui.rpc :as rpc] - [portal.ui.select :as select] - [portal.ui.state :as state] - [portal.web :as p])) + (:require + [clojure.datafy :refer [datafy]] + [examples.data :refer [data]] + [portal.client.web :as remote] + [portal.console :as log] + [portal.runtime :as rt] + #_[portal.shadow.remote :as remote] + [portal.shortcuts :as shortcuts] + [portal.ui.api :as api] + [portal.ui.commands :as commands] + [portal.ui.inspector :as ins] + [portal.ui.rpc :as rpc] + [portal.ui.select :as select] + [portal.ui.state :as state] + [portal.web :as p])) (defonce tap-list (atom (with-meta (list) @@ -89,9 +90,9 @@ (section "Selection Index" select/selection-index)]]}) (p/set-defaults! - {:mode :dev - :value (dashboard) - :window-title "portal-ui-runtime"}) + {:mode :dev + :value (dashboard) + :window-title "portal-ui-runtime"}) (defn- error-handler [event] #_(tap> (or (.-error event) (.-reason event))) diff --git a/dev/portal/share.clj b/dev/portal/share.clj index d7ff1739..0f04c42e 100644 --- a/dev/portal/share.clj +++ b/dev/portal/share.clj @@ -1,10 +1,12 @@ (ns portal.share - (:require [clojure.pprint :as pp] - [clojure.string :as str] - [org.httpkit.client :as http] - [portal.api :as p] - [portal.runtime.json :as json]) - (:import [java.net URL])) + (:require + [clojure.pprint :as pp] + [clojure.string :as str] + [org.httpkit.client :as http] + [portal.api :as p] + [portal.runtime.json :as json]) + (:import + (java.net URL))) (defn- pprint [value] (binding [*print-meta* true] @@ -12,14 +14,14 @@ (defn- create-gist [content] (-> @(http/post - "https://api.github.com/gists" - {:basic-auth [(System/getenv "GIT_USERNAME") - (System/getenv "GIT_PASSWORD")] - :headers {"Accept" "application/vnd.github.v3+json"} - :body (json/write - {:public false - :description "Portal Share" - :files {"data.clj" {:content content}}})}) + "https://api.github.com/gists" + {:basic-auth [(System/getenv "GIT_USERNAME") + (System/getenv "GIT_PASSWORD")] + :headers {"Accept" "application/vnd.github.v3+json"} + :body (json/write + {:public false + :description "Portal Share" + :files {"data.clj" {:content content}}})}) :body json/read (get-in [:files :data.clj :raw_url]))) @@ -34,9 +36,9 @@ (defn- shorten-url [url] (-> @(http/post - "https://url.api.stdlib.com/temporary@0.3.0/create/" - {:headers {"Content-Type" "application/json"} - :body (json/write {:url url :ttl 86400})}) + "https://url.api.stdlib.com/temporary@0.3.0/create/" + {:headers {"Content-Type" "application/json"} + :body (json/write {:url url :ttl 86400})}) :body json/read :link_url)) diff --git a/dev/reveal.clj b/dev/reveal.clj index 40df1acd..fc764553 100644 --- a/dev/reveal.clj +++ b/dev/reveal.clj @@ -1,4 +1,5 @@ (ns reveal - (:require [vlaaad.reveal :as r])) + (:require + [vlaaad.reveal :as r])) (comment (r/tap-log)) diff --git a/dev/tasks/build.clj b/dev/tasks/build.clj index 30bede70..bf07e75b 100644 --- a/dev/tasks/build.clj +++ b/dev/tasks/build.clj @@ -1,26 +1,27 @@ (ns tasks.build - (:require [babashka.fs :as fs] - [tasks.docs :refer [docs]] - [tasks.info :refer [version]] - [tasks.tools :refer [*cwd* gradle npm npx shadow]])) + (:require + [babashka.fs :as fs] + [tasks.docs :refer [docs]] + [tasks.info :refer [version]] + [tasks.tools :refer [*cwd* gradle npm npx shadow]])) (defn install [] (when (seq - (fs/modified-since - "node_modules" - ["package.json" "package-lock.json"])) + (fs/modified-since + "node_modules" + ["package.json" "package-lock.json"])) (npm :ci))) (defn main-js [] (when (seq - (fs/modified-since - "resources/portal/main.js" - (concat - ["deps.edn" - "package.json" - "package-lock.json" - "shadow-cljs.edn"] - (fs/glob "src/portal/ui" "**.cljs")))) + (fs/modified-since + "resources/portal/main.js" + (concat + ["deps.edn" + "package.json" + "package-lock.json" + "shadow-cljs.edn"] + (fs/glob "src/portal/ui" "**.cljs")))) (install) (shadow :release :client)) (fs/copy "resources/icon.svg" @@ -30,9 +31,9 @@ (defn ws-js [] (let [out "resources/portal/ws.js"] (when (seq - (fs/modified-since - out - ["package.json" "package-lock.json"])) + (fs/modified-since + out + ["package.json" "package-lock.json"])) (install) (npx :browserify "--node" diff --git a/dev/tasks/check.clj b/dev/tasks/check.clj index 3516364d..18218c49 100644 --- a/dev/tasks/check.clj +++ b/dev/tasks/check.clj @@ -1,8 +1,9 @@ (ns tasks.check - (:require [portal.runtime.json :as json] - [portal.viewer :as v] - [tasks.format :as fmt] - [tasks.tools :refer [*cwd* clj gradle sh]])) + (:require + [portal.runtime.json :as json] + [portal.viewer :as v] + [tasks.format :as fmt] + [tasks.tools :refer [*cwd* clj gradle sh]])) (defn cloc [] (-> (sh :cloc "--json" :src :dev :test) diff --git a/dev/tasks/ci.clj b/dev/tasks/ci.clj index a030e580..9492584f 100644 --- a/dev/tasks/ci.clj +++ b/dev/tasks/ci.clj @@ -1,7 +1,8 @@ (ns tasks.ci - (:require [tasks.check :refer [check check*]] - [tasks.test :refer [test test*] :as test] - [tasks.tools :refer [clj]])) + (:require + [tasks.check :refer [check check*]] + [tasks.test :as test :refer [test test*]] + [tasks.tools :refer [clj]])) (def ^:private commands ["-M:cljfmt" diff --git a/dev/tasks/clean.clj b/dev/tasks/clean.clj index 15ade99e..42048a6c 100644 --- a/dev/tasks/clean.clj +++ b/dev/tasks/clean.clj @@ -1,7 +1,8 @@ (ns tasks.clean - (:require [babashka.fs :as fs] - [io.aviso.ansi :as a] - [tasks.info :refer [version]])) + (:require + [babashka.fs :as fs] + [io.aviso.ansi :as a] + [tasks.info :refer [version]])) (defn rm [path] (when (fs/exists? path) diff --git a/dev/tasks/cljr.clj b/dev/tasks/cljr.clj index 5c7f8790..664eb127 100644 --- a/dev/tasks/cljr.clj +++ b/dev/tasks/cljr.clj @@ -1,13 +1,14 @@ (ns tasks.cljr - (:require [clojure.string :as str] - [tasks.tools :refer [*opts* cljr]])) + (:require + [clojure.string :as str] + [tasks.tools :refer [*opts* cljr]])) (defn repl [] (binding [*opts* {:inherit true :extra-env {"CLOJURE_LOAD_PATH" (str/join - (System/getProperty "path.separator") - ["src" "resources" "dev" "test"])}}] + (System/getProperty "path.separator") + ["src" "resources" "dev" "test"])}}] (cljr "--eval" "((requiring-resolve 'tasks.prepl/prepl))" "--repl"))) (defn -main [] (repl)) diff --git a/dev/tasks/deploy.clj b/dev/tasks/deploy.clj index 4784fa66..7f0fa603 100644 --- a/dev/tasks/deploy.clj +++ b/dev/tasks/deploy.clj @@ -1,8 +1,9 @@ (ns tasks.deploy - (:require [tasks.ci :refer [ci]] - [tasks.info :refer [options]] - [tasks.package :as pkg] - [tasks.tools :refer [*cwd* clj gradle npx]])) + (:require + [tasks.ci :refer [ci]] + [tasks.info :refer [options]] + [tasks.package :as pkg] + [tasks.tools :refer [*cwd* clj gradle npx]])) (defn- deploy-vscode [] (binding [*cwd* "extension-vscode"] diff --git a/dev/tasks/deps.clj b/dev/tasks/deps.clj index 41d2d5a1..3cdd7ff6 100644 --- a/dev/tasks/deps.clj +++ b/dev/tasks/deps.clj @@ -1,5 +1,6 @@ (ns tasks.deps - (:require [tasks.tools :refer [*cwd* clj git npm]])) + (:require + [tasks.tools :refer [*cwd* clj git npm]])) (defn check-deps [] (npm :outdated) diff --git a/dev/tasks/dev.clj b/dev/tasks/dev.clj index d14b2e04..2018b725 100644 --- a/dev/tasks/dev.clj +++ b/dev/tasks/dev.clj @@ -1,9 +1,10 @@ (ns tasks.dev - (:require [clojure.core.server :as server] - [clojure.java.io :as io] - [org.httpkit.server :as http] - [tasks.build :refer [build]] - [tasks.tools :refer [*opts* clj]])) + (:require + [clojure.core.server :as server] + [clojure.java.io :as io] + [org.httpkit.server :as http] + [tasks.build :refer [build]] + [tasks.tools :refer [*opts* clj]])) (defrecord Edn [edn]) @@ -44,11 +45,11 @@ (let [server (http/run-server #'proxy-tap> {:legacy-return-value? false}) port (http/server-port server)] (start-server - {:name "bb" - :port 0 - :server-daemon false - :args [{:valf pr-str* ::port port}] - :accept `io-prepl}))) + {:name "bb" + :port 0 + :server-daemon false + :args [{:valf pr-str* ::port port}] + :accept `io-prepl}))) (defn dev "Start dev server." diff --git a/dev/tasks/docs.clj b/dev/tasks/docs.clj index 9b91f9f9..8e4a85df 100644 --- a/dev/tasks/docs.clj +++ b/dev/tasks/docs.clj @@ -1,13 +1,14 @@ (ns tasks.docs - (:require [clojure.edn :as edn] - [clojure.java.io :as io] - [clojure.pprint :refer [pprint]] - [clojure.walk :as walk] - [examples.data :as d] - [portal.api :as p] - [portal.colors :as c] - [portal.runtime.cson :as cson] - [portal.viewer :as v])) + (:require + [clojure.edn :as edn] + [clojure.java.io :as io] + [clojure.pprint :refer [pprint]] + [clojure.walk :as walk] + [examples.data :as d] + [portal.api :as p] + [portal.colors :as c] + [portal.runtime.cson :as cson] + [portal.viewer :as v])) (def ^:private flex {:gap 9 @@ -21,24 +22,24 @@ (->> (ns-publics namespace) (sort-by first) (keep - (fn [[symbol-name v]] - (let [m (meta v)] - (when-not (:no-doc m) - [(name symbol-name) - {:hiccup - (v/hiccup - [:div - {:style flex} - [:h2 [:portal.viewer/inspector v]] - (into - [:<>] - (map-indexed - (fn [idx itm] - ^{:key idx} - [:portal.viewer/pr-str (concat [symbol-name] itm)]) - (:arglists m))) - (when-let [doc (:doc m)] - [:portal.viewer/markdown doc])])}])))) + (fn [[symbol-name v]] + (let [m (meta v)] + (when-not (:no-doc m) + [(name symbol-name) + {:hiccup + (v/hiccup + [:div + {:style flex} + [:h2 [:portal.viewer/inspector v]] + (into + [:<>] + (map-indexed + (fn [idx itm] + ^{:key idx} + [:portal.viewer/pr-str (concat [symbol-name] itm)]) + (:arglists m))) + (when-let [doc (:doc m)] + [:portal.viewer/markdown doc])])}])))) (into [(name namespace)]))) (defn- ->loc [v] @@ -127,9 +128,9 @@ ::v/source-location {:examples '[{:file "clojure/core.clj", :line 75, :column 1, :ns clojure.core} {:file "clojure/core.clj", :line 183, :column 1, :ns clojure.core} - {:file "clojure/java/io.clj", - :line 418, - :column 1, + {:file "clojure/java/io.clj" + :line 418 + :column 1 :ns clojure.java.io} {:file "portal/api.cljc", :line 72, :column 1, :ns portal.api} {:file "portal/api.cljc", :line 196, :column 1, :ns portal.api}] @@ -150,11 +151,11 @@ [:pre {} [:code {:class "clojure"} spec]]]) (when examples (into - [:div {:style (dissoc flex :padding :width)} - [:h2 "Examples"]] - (map-indexed - (fn [idx itm] ^{:key idx} [(:name entry) itm]) - examples)))]}]) + [:div {:style (dissoc flex :padding :width)} + [:h2 "Examples"]] + (map-indexed + (fn [idx itm] ^{:key idx} [(:name entry) itm]) + examples)))]}]) (defn- save-viewers [] (spit "resources/viewers.edn" @@ -174,27 +175,27 @@ info (cond-> (merge viewer info) file (into - (->> (slurp (io/resource file)) - (re-seq #"(?s);;;([^\n]+)\n(.*);;;") - (map - (fn [[_ k v]] [(edn/read-string k) v])))))] + (->> (slurp (io/resource file)) + (re-seq #"(?s);;;([^\n]+)\n(.*);;;") + (map + (fn [[_ k v]] [(edn/read-string k) v])))))] :when (or (:doc info) (:examples info) (:spec info))] (->render info)))) (defn gen-docs [] (update - (walk/postwalk - (fn [v] - (let [file (:file v)] - (cond-> v - file (assoc :markdown (slurp file)) - (and (vector? v) (= (first v) "Viewers")) - (concat (gen-viewer-docs))))) - (edn/read-string (slurp "doc/cljdoc.edn"))) - :cljdoc.doc/tree - into - [(->docs 'portal.api) - #_(->docs 'portal.client.jvm)])) + (walk/postwalk + (fn [v] + (let [file (:file v)] + (cond-> v + file (assoc :markdown (slurp file)) + (and (vector? v) (= (first v) "Viewers")) + (concat (gen-viewer-docs))))) + (edn/read-string (slurp "doc/cljdoc.edn"))) + :cljdoc.doc/tree + into + [(->docs 'portal.api) + #_(->docs 'portal.client.jvm)])) (defn docs [] (println "=> Generating docs") diff --git a/dev/tasks/e2e.clj b/dev/tasks/e2e.clj index 5c483a1b..058a80da 100644 --- a/dev/tasks/e2e.clj +++ b/dev/tasks/e2e.clj @@ -1,24 +1,25 @@ (ns tasks.e2e - (:require [babashka.process :as p] - [clojure.java.io :as io] - [portal.e2e :as e2e] - [tasks.build :refer [build]])) + (:require + [babashka.process :as p] + [clojure.java.io :as io] + [portal.e2e :as e2e] + [tasks.build :refer [build]])) (def e2e-envs {:jvm [:clojure "-M" "-e" "(set! *warn-on-reflection* true)" "-r"] :node [:clojure "-Sdeps" (pr-str - {:deps - {'org.clojure/clojurescript - {:mvn/version "1.10.844"}}}) + {:deps + {'org.clojure/clojurescript + {:mvn/version "1.10.844"}}}) "-M" "-m" :cljs.main "-re" :node] :web [:clojure "-Sdeps" (pr-str - {:deps - {'org.clojure/clojurescript - {:mvn/version "1.10.844"}}}) + {:deps + {'org.clojure/clojurescript + {:mvn/version "1.10.844"}}}) "-M" "-m" :cljs.main] :bb [:bb] :nbb [:npx :nbb] diff --git a/dev/tasks/format.clj b/dev/tasks/format.clj index 08e5eec7..ecaf6181 100644 --- a/dev/tasks/format.clj +++ b/dev/tasks/format.clj @@ -1,14 +1,15 @@ (ns tasks.format - (:require [tasks.tools :refer [clj]])) + (:require + [tasks.tools :refer [npx]])) (defn check [] - (clj "-M:cljfmt" :check + (npx "@chrisoakman/standard-clojure-style" :check :dev :src :test "extension-intellij/src/main/clojure")) (defn fix "Run cljfmt formatter." [] - (clj "-M:cljfmt" :fix + (npx "@chrisoakman/standard-clojure-style" :fix :dev :src :test "extension-intellij/src/main/clojure")) diff --git a/dev/tasks/ide.clj b/dev/tasks/ide.clj index 20c1bda0..b94216f7 100644 --- a/dev/tasks/ide.clj +++ b/dev/tasks/ide.clj @@ -1,6 +1,7 @@ (ns tasks.ide - (:require [clojure.string :as str] - [tasks.tools :refer [*cwd* gradle]])) + (:require + [clojure.string :as str] + [tasks.tools :refer [*cwd* gradle]])) (def plugins {"2021.3" ["com.cursiveclojure.cursive:1.12.2-2021.3" "com.intellij.java"] @@ -14,4 +15,4 @@ (let [platform (or version "2023.3")] (gradle "runIde" (str "-PplatformVersion=" platform) - (str "-PplatformPlugins=" (str/join ", " (get plugins platform))))))) \ No newline at end of file + (str "-PplatformPlugins=" (str/join ", " (get plugins platform))))))) diff --git a/dev/tasks/ijverify.clj b/dev/tasks/ijverify.clj index e8dfa79d..6b2101ee 100644 --- a/dev/tasks/ijverify.clj +++ b/dev/tasks/ijverify.clj @@ -1,5 +1,4 @@ -(ns tasks.ijverify - #_(:require [tasks.tools :refer [gradle *cwd*]])) +(ns tasks.ijverify) (defn verify "Run Intellij Plugin Verification." diff --git a/dev/tasks/info.clj b/dev/tasks/info.clj index f31ccac4..624a3f21 100644 --- a/dev/tasks/info.clj +++ b/dev/tasks/info.clj @@ -1,6 +1,7 @@ (ns tasks.info - (:require [clojure.java.shell :refer [sh]] - [clojure.string :as str])) + (:require + [clojure.java.shell :refer [sh]] + [clojure.string :as str])) (def version "0.58.3") @@ -9,18 +10,18 @@ (defn- provided [deps] (reduce-kv - (fn [m k v] - (assoc m k (assoc v :scope "provided"))) - {} - deps)) + (fn [m k v] + (assoc m k (assoc v :scope "provided"))) + {} + deps)) (defn- get-deps [] (let [deps (read-string (slurp "deps.edn"))] (merge - (:deps deps) - (provided (get-in deps [:aliases :cider :extra-deps])) - (provided (get-in deps [:aliases :cljs :extra-deps])) - (provided (get-in deps [:aliases :plk :extra-deps]))))) + (:deps deps) + (provided (get-in deps [:aliases :cider :extra-deps])) + (provided (get-in deps [:aliases :cljs :extra-deps])) + (provided (get-in deps [:aliases :plk :extra-deps]))))) (def options {:lib 'djblue/portal diff --git a/dev/tasks/jar.clj b/dev/tasks/jar.clj index fdd7c95f..54656de8 100644 --- a/dev/tasks/jar.clj +++ b/dev/tasks/jar.clj @@ -1,6 +1,7 @@ (ns tasks.jar - (:require [clojure.tools.build.api :as b] - [tasks.info :refer [options]])) + (:require + [clojure.tools.build.api :as b] + [tasks.info :refer [options]])) (defn -main [] (let [{:keys [class-dir jar-file]} options] diff --git a/dev/tasks/kondo.clj b/dev/tasks/kondo.clj index 547a9f9e..42dbc6a2 100644 --- a/dev/tasks/kondo.clj +++ b/dev/tasks/kondo.clj @@ -1,8 +1,9 @@ (ns tasks.kondo - (:require [clj-kondo.core :as core] - [clj-kondo.main :as kondo] - [clojure.string :as str] - [portal.client.jvm :as p])) + (:require + [clj-kondo.core :as core] + [clj-kondo.main :as kondo] + [clojure.string :as str] + [portal.client.jvm :as p])) (defn- file->ns [file] (some-> file @@ -15,14 +16,14 @@ (let [submit (partial p/submit {:port port :encoding :cson})] (doseq [{:keys [col row filename level message type]} findings] (submit - {:level (get {:warning :warn :fail :fatal} level level) - :type type - :column col - :ns (file->ns filename) - :line row - :file filename - :result message - :time (java.util.Date.)}))) + {:level (get {:warning :warn :fail :fatal} level level) + :type type + :column col + :ns (file->ns filename) + :line row + :file filename + :result message + :time (java.util.Date.)}))) (f data))) (def ^:private config diff --git a/dev/tasks/load.clj b/dev/tasks/load.clj index 6860bc2c..7d1572c4 100644 --- a/dev/tasks/load.clj +++ b/dev/tasks/load.clj @@ -1,6 +1,8 @@ (ns tasks.load - (:require [clojure.java.io :as io]) - (:import [java.io File PushbackReader])) + (:require + [clojure.java.io :as io]) + (:import + (java.io File PushbackReader))) (defn- read-ns-form [file] (binding [*read-eval* false @@ -24,12 +26,12 @@ (defn- get-failures [source-paths] (sequence - (comp - (mapcat (comp file-seq io/file)) - (map #(.getAbsolutePath ^File %)) - (filter #(re-matches #".*\.cljc?$" %)) - (keep check-ns)) - source-paths)) + (comp + (mapcat (comp file-seq io/file)) + (map #(.getAbsolutePath ^File %)) + (filter #(re-matches #".*\.cljc?$" %)) + (keep check-ns)) + source-paths)) (defn check [source-paths] (let [failures (count (get-failures source-paths))] diff --git a/dev/tasks/package.clj b/dev/tasks/package.clj index 8f47bf4b..8b0000b2 100644 --- a/dev/tasks/package.clj +++ b/dev/tasks/package.clj @@ -1,9 +1,10 @@ (ns tasks.package - (:require [babashka.fs :as fs] - [hiccup.core :refer [html]] - [tasks.build :refer [build extensions]] - [tasks.info :refer [options version]] - [tasks.tools :refer [clj]])) + (:require + [babashka.fs :as fs] + [hiccup.core :refer [html]] + [tasks.build :refer [build extensions]] + [tasks.info :refer [options version]] + [tasks.tools :refer [clj]])) (defn- options->licenses [{:keys [license]}] [:licenses @@ -77,8 +78,8 @@ (defn- xml-str [hiccup] (str - "" - (html {:mode :xml} hiccup))) + "" + (html {:mode :xml} hiccup))) (defn generate [options] (-> options options->hiccup xml-str)) @@ -91,9 +92,9 @@ (defn pom [] (let [target (pom-file options)] (when (seq - (fs/modified-since - target - ["deps.edn"])) + (fs/modified-since + target + ["deps.edn"])) (println "=>" "writing" (str target)) (fs/create-dirs (fs/parent target)) (spit (str target) (generate options))))) @@ -104,12 +105,12 @@ (build) (pom) (when (seq - (fs/modified-since - (str "target/portal-" version ".jar") - (concat - ["pom.xml"] - (fs/glob "src" "**") - (fs/glob "resources" "**")))) + (fs/modified-since + (str "target/portal-" version ".jar") + (concat + ["pom.xml"] + (fs/glob "src" "**") + (fs/glob "resources" "**")))) (clj "-M:dev" "-m" :tasks.jar))) (defn all diff --git a/dev/tasks/parallel.clj b/dev/tasks/parallel.clj index 73ad74a3..3a3b2d59 100644 --- a/dev/tasks/parallel.clj +++ b/dev/tasks/parallel.clj @@ -1,17 +1,18 @@ (ns tasks.parallel - (:require [org.httpkit.server :as http] - [portal.runtime.cson :as cson] - [portal.viewer :as v] - [tasks.tools :refer [*opts*]])) + (:require + [org.httpkit.server :as http] + [portal.runtime.cson :as cson] + [portal.viewer :as v] + [tasks.tools :refer [*opts*]])) (def ^:private ^:dynamic *sessions* nil) (defn- create-sessions [] (atom (with-meta [] (v/for - {:stdio [] - :results {} - :done (promise) - :start (System/currentTimeMillis)} + {:stdio [] + :results {} + :done (promise) + :start (System/currentTimeMillis)} {:start :portal.viewer/date-time :time :portal.viewer/duration-ms})))) @@ -26,16 +27,16 @@ (defn- append-result [sessions id result] (let [{:keys [stdio results done]} (meta - (swap! - sessions - (fn [sessions] - (let [m (meta sessions) - results (-> m - :results - (assoc id result))] - (with-meta - sessions - (assoc m :results results))))))] + (swap! + sessions + (fn [sessions] + (let [m (meta sessions) + results (-> m + :results + (assoc id result))] + (with-meta + sessions + (assoc m :results results))))))] (when (= (count stdio) (count results)) (let [start (:start (meta @sessions)) stop (System/currentTimeMillis)] @@ -44,15 +45,15 @@ (defn- append-stdio [sessions id data] (swap! - sessions - (fn [sessions] - (let [m (meta sessions) - stdio (-> m - :stdio - (update id conj data))] - (with-meta - (into [] (apply concat stdio)) - (assoc m :stdio stdio)))))) + sessions + (fn [sessions] + (let [m (meta sessions) + stdio (-> m + :stdio + (update id conj data))] + (with-meta + (into [] (apply concat stdio)) + (assoc m :stdio stdio)))))) (def ^:dynamic *portal* true) @@ -60,17 +61,17 @@ (let [sessions *sessions* id (new-session sessions) server (http/run-server - (fn [request] - (append-stdio sessions id {:tag :tap :val (cson/read (slurp (:body request)))}) - {:status 200}) - {:port 0 :legacy-return-value? false}) + (fn [request] + (append-stdio sessions id {:tag :tap :val (cson/read (slurp (:body request)))}) + {:status 200}) + {:port 0 :legacy-return-value? false}) port (http/server-port server) out (PrintWriter-on - (fn [val] - (append-stdio sessions id {:tag :out :val val})) nil) + (fn [val] + (append-stdio sessions id {:tag :out :val val})) nil) err (PrintWriter-on - (fn [val] - (append-stdio sessions id {:tag :err :val val})) nil)] + (fn [val] + (append-stdio sessions id {:tag :err :val val})) nil)] (try (binding [*out* out *err* err diff --git a/dev/tasks/planck.clj b/dev/tasks/planck.clj index cd8c00ea..2dd175cf 100644 --- a/dev/tasks/planck.clj +++ b/dev/tasks/planck.clj @@ -1,5 +1,6 @@ (ns tasks.planck - (:require [tasks.tools :refer [sh]])) + (:require + [tasks.tools :refer [sh]])) (defn setup [] (sh :sudo :add-apt-repository "ppa:mfikes/planck") diff --git a/dev/tasks/prepl.cljc b/dev/tasks/prepl.cljc index 6d2366fa..82c24fc2 100644 --- a/dev/tasks/prepl.cljc +++ b/dev/tasks/prepl.cljc @@ -1,13 +1,14 @@ (ns tasks.prepl - (:require [clojure.core.server :as server] - [portal.runtime.fs :as fs]) - #?(:clj - (:import - (java.net Socket)) - :cljr - (:import - (System.Net.Sockets TcpListener) - (System.Threading Thread)))) + (:require + [clojure.core.server :as server] + [portal.runtime.fs :as fs]) + (:import + #?@(:clj + [(java.net Socket)] + + :cljr + [(System.Net.Sockets TcpListener) + (System.Threading Thread)]))) (defn- get-runtime [] #?(:bb :bb :clj :clj :cljr :cljr)) @@ -38,8 +39,8 @@ (defn prepl [] (start-server - {:name (name (get-runtime)) - :port 0 - :server-daemon false - :args [{:valf -pr-str}] - :accept `server/io-prepl})) + {:name (name (get-runtime)) + :port 0 + :server-daemon false + :args [{:valf -pr-str}] + :accept `server/io-prepl})) diff --git a/dev/tasks/pwa.clj b/dev/tasks/pwa.clj index c7eb014e..4dd24eec 100644 --- a/dev/tasks/pwa.clj +++ b/dev/tasks/pwa.clj @@ -1,52 +1,53 @@ (ns tasks.pwa - (:require [babashka.fs :as fs] - [clojure.java.browse :refer [browse-url]] - [clojure.java.io :as io] - [hiccup.core :refer [html]] - [portal.colors :as c] - [portal.runtime.cson :as cson] - [portal.runtime.json :as json] - [tasks.build :refer [install]] - [tasks.docs :as docs] - [tasks.tools :refer [shadow]])) + (:require + [babashka.fs :as fs] + [clojure.java.browse :refer [browse-url]] + [clojure.java.io :as io] + [hiccup.core :refer [html]] + [portal.colors :as c] + [portal.runtime.cson :as cson] + [portal.runtime.json :as json] + [tasks.build :refer [install]] + [tasks.docs :as docs] + [tasks.tools :refer [shadow]])) (defn- manifest-json [settings] (json/write - {:short_name "Portal" - :name (:name settings) - :description "A clojure tool to navigate through your data." - :icons - [{:type "image/svg+xml" - :sizes "512x512" - :src "icon.svg"}] - :handle_links "preferred" - :scope (:host settings) - :start_url (:host settings) - :display "standalone" - :display_override ["minimal-ui"]})) + {:short_name "Portal" + :name (:name settings) + :description "A clojure tool to navigate through your data." + :icons + [{:type "image/svg+xml" + :sizes "512x512" + :src "icon.svg"}] + :handle_links "preferred" + :scope (:host settings) + :start_url (:host settings) + :display "standalone" + :display_override ["minimal-ui"]})) (defn- index-html [settings] (str - "" - (html - [:html - {:lang "en"} - [:head - [:title "portal"] - [:meta {:charset "UTF-8"}] - [:meta {:name "viewport" - :content "width=device-width, initial-scale=1"}] - [:link {:rel :manifest :href "manifest.json"}] - [:meta {:name "theme-color" :content (::c/background2 settings)}]] - [:body - {:style - (identity ;; because hiccup is a macro - {:margin 0 - :overflow "hidden" - :min-height "100vh" - :background (::c/background settings)})} - [:div {:id "root"}] - [:script {:src "main.js"}]]]))) + "" + (html + [:html + {:lang "en"} + [:head + [:title "portal"] + [:meta {:charset "UTF-8"}] + [:meta {:name "viewport" + :content "width=device-width, initial-scale=1"}] + [:link {:rel :manifest :href "manifest.json"}] + [:meta {:name "theme-color" :content (::c/background2 settings)}]] + [:body + {:style + (identity ;; because hiccup is a macro + {:margin 0 + :overflow "hidden" + :min-height "100vh" + :background (::c/background settings)})} + [:div {:id "root"}] + [:script {:src "main.js"}]]]))) (defmethod print-method (Class/forName "[B") [v ^java.io.Writer w] (.write w "#portal/bin \"") diff --git a/dev/tasks/test.clj b/dev/tasks/test.clj index 84d92320..a9d1ad0b 100644 --- a/dev/tasks/test.clj +++ b/dev/tasks/test.clj @@ -1,19 +1,20 @@ (ns tasks.test (:refer-clojure :exclude [test]) - (:require [babashka.fs :as fs] - [clojure.string :as str] - [tasks.build :refer [build install]] - [tasks.tools :as t])) + (:require + [babashka.fs :as fs] + [clojure.string :as str] + [tasks.build :refer [build install]] + [tasks.tools :as t])) (defn cljs* [deps main] (let [version (get-in deps ['org.clojure/clojurescript :mvn/version]) out (str "target/" (name main) "." version ".js")] (when (seq - (fs/modified-since - out - (concat - (fs/glob "src" "**") - (fs/glob "test" "**")))) + (fs/modified-since + out + (concat + (fs/glob "src" "**") + (fs/glob "test" "**")))) (t/clj "-Sdeps" (pr-str {:deps deps}) "-M:test" "-m" :cljs.main @@ -38,8 +39,8 @@ (defn- setup* [version] (t/clj - "-Sforce" "-Spath" "-Sdeps" - (pr-str {:deps {'org.clojure/clojurescript {:mvn/version version}}}))) + "-Sforce" "-Spath" "-Sdeps" + (pr-str {:deps {'org.clojure/clojurescript {:mvn/version version}}}))) (defn setup [] (setup* "1.10.773") diff --git a/dev/tasks/tools.clj b/dev/tasks/tools.clj index 63e4d06f..9aa15fd2 100644 --- a/dev/tasks/tools.clj +++ b/dev/tasks/tools.clj @@ -1,9 +1,11 @@ (ns tasks.tools - (:require [babashka.process :as p] - [clojure.java.io :as io] - [clojure.string :as str] - [io.aviso.ansi :as a]) - (:import [java.time Duration])) + (:require + [babashka.process :as p] + [clojure.java.io :as io] + [clojure.string :as str] + [io.aviso.ansi :as a]) + (:import + (java.time Duration))) (def ^:dynamic *cwd* nil) (def ^:dynamic *opts* nil) @@ -17,15 +19,15 @@ s (mod (.toSeconds duration) 60) ms (mod ms 1000)] (str - (a/bold-blue "->") - " " - (a/bold-yellow - (str - (when (> h 0) - (str h " hours, ")) - (when (> m 0) - (str m " minutes, ")) - s "." ms " seconds"))))) + (a/bold-blue "->") + " " + (a/bold-yellow + (str + (when (> h 0) + (str h " hours, ")) + (when (> m 0) + (str m " minutes, ")) + s "." ms " seconds"))))) (def ^:private in-bb? (some? (System/getProperty "babashka.version"))) @@ -52,9 +54,9 @@ (.flush *err*)) (binding [*out* *err*] (println - (str (format-millis (- (now) start)) - (when-not (zero? exit) - (str " " (a/bold-red (str "(exit: " exit ")"))))))) + (str (format-millis (- (now) start)) + (when-not (zero? exit) + (str " " (a/bold-red (str "(exit: " exit ")"))))))) (when-not (zero? exit) (throw (ex-info (str "Non-zero exit code: " (str/join " " (map name args))) diff --git a/dev/tasks/version.clj b/dev/tasks/version.clj index e06e0a12..3182724b 100644 --- a/dev/tasks/version.clj +++ b/dev/tasks/version.clj @@ -1,17 +1,19 @@ (ns tasks.version - (:require [clojure.string :as str] - [tasks.info :refer [version]] - [tasks.tools :refer [git]]) - (:import [java.time LocalDateTime] - [java.time.format DateTimeFormatter])) + (:require + [clojure.string :as str] + [tasks.info :refer [version]] + [tasks.tools :refer [git]]) + (:import + (java.time LocalDateTime) + (java.time.format DateTimeFormatter))) (defn- find-version [file-name] (first (re-find #"(\d+)\.(\d+)\.(\d+)" (slurp file-name)))) (defn- get-date [] (.format - (DateTimeFormatter/ofPattern "yyyy-MM-dd") - (LocalDateTime/now))) + (DateTimeFormatter/ofPattern "yyyy-MM-dd") + (LocalDateTime/now))) (defn- changelog [version] (let [content (slurp "CHANGELOG.md")] @@ -30,11 +32,11 @@ (defn- version-updates [next-version] (let [current-version (find-version "src/portal/runtime/index.cljc")] (merge - (changelog next-version) - (zipmap - files - (for [file files] - (str/replace (slurp file) current-version next-version)))))) + (changelog next-version) + (zipmap + files + (for [file files] + (str/replace (slurp file) current-version next-version)))))) (defn- set-version [version] (doseq [[file-name content] (version-updates version)] diff --git a/dev/user.clj b/dev/user.clj index 410bb5ce..2b7cf2de 100644 --- a/dev/user.clj +++ b/dev/user.clj @@ -35,4 +35,4 @@ (p/repl portal) (require '[examples.data :refer [data]]) - (dotimes [_i 25] (tap> data))) \ No newline at end of file + (dotimes [_i 25] (tap> data))) diff --git a/dev/workspace.cljs b/dev/workspace.cljs index 1cbdbf08..38e0d17e 100644 --- a/dev/workspace.cljs +++ b/dev/workspace.cljs @@ -1,13 +1,14 @@ (ns workspace - (:require ["./hello" :as hello] - ["@fortawesome/free-solid-svg-icons/faArrowDown" :refer [faArrowDown]] - ["react" :as react] - [portal.colors :as c] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.styled :as s] - [portal.ui.theme :as theme] - [reagent.core :as r])) + (:require + ["./hello" :as hello] + ["@fortawesome/free-solid-svg-icons/faArrowDown" :refer [faArrowDown]] + ["react" :as react] + [portal.colors :as c] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.styled :as s] + [portal.ui.theme :as theme] + [reagent.core :as r])) (.log js/console hello/world) @@ -16,19 +17,19 @@ (defn button [props & children] (let [theme (theme/use-theme)] (into - [s/button - (merge - {:style - {:border :none - :cursor :pointer - :padding (:padding theme) - :font-size (:font-size theme) - :border-radius (:border-radius theme) - :background (::c/boolean theme) - :font-family (:font-family theme) - :color (::c/text theme)}} - props)] - children))) + [s/button + (merge + {:style + {:border :none + :cursor :pointer + :padding (:padding theme) + :font-size (:font-size theme) + :border-radius (:border-radius theme) + :background (::c/boolean theme) + :font-family (:font-family theme) + :color (::c/text theme)}} + props)] + children))) (defn app [] (let [theme (theme/use-theme) diff --git a/extension-intellij/src/main/clojure/portal/extensions/intellij/factory.clj b/extension-intellij/src/main/clojure/portal/extensions/intellij/factory.clj index 64cd91dd..2b589682 100644 --- a/extension-intellij/src/main/clojure/portal/extensions/intellij/factory.clj +++ b/extension-intellij/src/main/clojure/portal/extensions/intellij/factory.clj @@ -1,9 +1,10 @@ (ns portal.extensions.intellij.factory - (:require [clojure.edn :as edn] - [clojure.java.io :as io] - [org.httpkit.server :as http] - [portal.extensions.intellij.file :as file] - [portal.extensions.intellij.theme :as theme]) + (:require + [clojure.edn :as edn] + [clojure.java.io :as io] + [org.httpkit.server :as http] + [portal.extensions.intellij.file :as file] + [portal.extensions.intellij.theme :as theme]) (:import (com.intellij.openapi.diagnostic Logger) (com.intellij.openapi.project Project) @@ -17,13 +18,8 @@ (org.cef.handler CefLoadHandler) (portal.extensions.intellij WithLoader)) (:gen-class - :main false :extends portal.extensions.intellij.WithLoader - :implements [com.intellij.ide.ui.UISettingsListener - com.intellij.openapi.editor.colors.EditorColorsListener - com.intellij.openapi.wm.ToolWindowFactory - com.intellij.openapi.project.DumbAware] - :name portal.extensions.intellij.Factory)) + :implements undefined)) (deftype PortalLogger []) @@ -41,10 +37,10 @@ (defn- get-options [] (pr-str - (pr-str - {:theme ::theme - :themes - {::theme (theme/get-theme)}}))) + (pr-str + {:theme ::theme + :themes + {::theme (theme/get-theme)}}))) (defn- patch-options ([] @@ -86,9 +82,9 @@ (not (:server m)) (assoc :server (http/run-server #(handler % project) {:port 0 :legacy-return-value? false}))))) (write-config - project - {:host "localhost" - :port (http/server-port (get-in @instances [project :server]))})) + project + {:host "localhost" + :port (http/server-port (get-in @instances [project :server]))})) (defn as-function ^Function [f] (reify Function @@ -115,20 +111,20 @@ (defn- setup-load-handler [^JBCefBrowser browser js-query] (.addLoadHandler - (.getJBCefClient browser) - (reify CefLoadHandler - (onLoadingStateChange [_this _browser _isLoading _canGoBack _canGoForward]) - (onLoadStart [_this _browser _frame _transitionType] - (info "Starting loading") - (inject-js-error-handler browser js-query)) - (onLoadEnd [_this browser _frame _httpStatusCode] - (info "Patching options") - (patch-options browser)) - (onLoadError [_this _browser _frame errorCode errorText failedUrl] - (throw (ex-info errorText {:errorCode errorCode - :errorText errorText - :failedUrl failedUrl})))) - (.getCefBrowser browser))) + (.getJBCefClient browser) + (reify CefLoadHandler + (onLoadingStateChange [_this _browser _isLoading _canGoBack _canGoForward]) + (onLoadStart [_this _browser _frame _transitionType] + (info "Starting loading") + (inject-js-error-handler browser js-query)) + (onLoadEnd [_this browser _frame _httpStatusCode] + (info "Patching options") + (patch-options browser)) + (onLoadError [_this _browser _frame errorCode errorText failedUrl] + (throw (ex-info errorText {:errorCode errorCode + :errorText errorText + :failedUrl failedUrl})))) + (.getCefBrowser browser))) (defn- init-browser [^JBCefBrowser browser] (info "Initializing browser") diff --git a/extension-intellij/src/main/clojure/portal/extensions/intellij/file.clj b/extension-intellij/src/main/clojure/portal/extensions/intellij/file.clj index 24b2984b..7d77921a 100644 --- a/extension-intellij/src/main/clojure/portal/extensions/intellij/file.clj +++ b/extension-intellij/src/main/clojure/portal/extensions/intellij/file.clj @@ -8,19 +8,19 @@ (defn- ->descriptor ^OpenFileDescriptor [^Project project {:keys [file line column]}] (OpenFileDescriptor. - project - (.findFileByUrl - (VirtualFileManager/getInstance) - (str "file://" file)) - (if line (dec line) 0) - (if column (dec column) 0))) + project + (.findFileByUrl + (VirtualFileManager/getInstance) + (str "file://" file)) + (if line (dec line) 0) + (if column (dec column) 0))) (defn open [^Project project info] (.invokeLater - (ApplicationManager/getApplication) - (fn [] - (.runReadAction - (ApplicationManager/getApplication) - ^Runnable - (fn [] - (.navigate (->descriptor project info) true)))))) + (ApplicationManager/getApplication) + (fn [] + (.runReadAction + (ApplicationManager/getApplication) + ^Runnable + (fn [] + (.navigate (->descriptor project info) true)))))) diff --git a/extension-intellij/src/main/clojure/portal/extensions/intellij/theme.clj b/extension-intellij/src/main/clojure/portal/extensions/intellij/theme.clj index f4a5ba75..6df88b44 100644 --- a/extension-intellij/src/main/clojure/portal/extensions/intellij/theme.clj +++ b/extension-intellij/src/main/clojure/portal/extensions/intellij/theme.clj @@ -68,32 +68,32 @@ ([^EditorColorsScheme theme key] (let [defaults (.getScheme (EditorColorsManager/getInstance) EditorColorsManager/DEFAULT_SCHEME_NAME)] (some-> - (if-let [attrs (language-colors key)] - (cond - (instance? ColorKey attrs) - (.getColor theme ^ColorKey attrs) + (if-let [attrs (language-colors key)] + (cond + (instance? ColorKey attrs) + (.getColor theme ^ColorKey attrs) - (instance? TextAttributesKey attrs) - (or - (some-> theme (.getAttributes ^TextAttributesKey attrs) .getForegroundColor) - (some-> defaults (.getAttributes ^TextAttributesKey attrs) .getForegroundColor))) - (.getColor theme (ColorKey/createColorKey (name key)))) - format-color)))) + (instance? TextAttributesKey attrs) + (or + (some-> theme (.getAttributes ^TextAttributesKey attrs) .getForegroundColor) + (some-> defaults (.getAttributes ^TextAttributesKey attrs) .getForegroundColor))) + (.getColor theme (ColorKey/createColorKey (name key)))) + format-color)))) (defn- get-font ([] (get-font - (.getGlobalScheme (EditorColorsManager/getInstance)))) + (.getGlobalScheme (EditorColorsManager/getInstance)))) ([^EditorColorsScheme theme] {:font-size (.getConsoleFontSize theme) :font-family (str (pr-str (.getConsoleFontName theme)) ", monospace")})) (defn resolve-theme [m] (reduce-kv - (fn [out k v] - (assoc out k (get-color v))) - {} - m)) + (fn [out k v] + (assoc out k (get-color v))) + {} + m)) (def theme-mapping {:portal.colors/background :CONSOLE_BACKGROUND_KEY @@ -120,9 +120,9 @@ (get-keys (.getGlobalScheme (EditorColorsManager/getInstance)))) ([^AbstractColorsScheme theme] (concat - (keys language-colors) - (for [^ColorKey key (.getColorKeys theme)] - (keyword (.getExternalName key)))))) + (keys language-colors) + (for [^ColorKey key (.getColorKeys theme)] + (keyword (.getExternalName key)))))) (comment (tap> (get-theme)) diff --git a/package-lock.json b/package-lock.json index 6064850f..a8f466dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,12 +23,80 @@ "vega-lite": "^5.1.1" }, "devDependencies": { + "@chrisoakman/standard-clojure-style": "^0.18.0", "browserify": "^16.5.2", "nbb": "^1.2.187", "source-map-support": "^0.5.20", "ws": "^8.17.1" } }, + "node_modules/@chrisoakman/standard-clojure-style": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/@chrisoakman/standard-clojure-style/-/standard-clojure-style-0.18.0.tgz", + "integrity": "sha512-2fasAuHjARXobtPsb56EtumaqD8i7ptWlpaZUXNNlzmJFkKG7ZR/mlqKOiT1CBYNTonIpgWzxbTKbLkCiG/KrA==", + "dev": true, + "license": "ISC", + "dependencies": { + "edn-data": "1.1.2", + "fs-plus": "3.1.1", + "glob": "11.0.0", + "yargs": "17.7.2", + "yoctocolors": "2.1.1" + }, + "bin": { + "standard-clj": "cli.mjs" + } + }, + "node_modules/@chrisoakman/standard-clojure-style/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@chrisoakman/standard-clojure-style/node_modules/glob": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-11.0.0.tgz", + "integrity": "sha512-9UiX/Bl6J2yaBbxKoEBRm4Cipxgok8kQYcOPEhScPwebu2I0HoQOuYdIO6S3hLuWoZgpDpwQZMzTFxgpkyT76g==", + "dev": true, + "license": "ISC", + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^4.0.1", + "minimatch": "^10.0.0", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^2.0.0" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@chrisoakman/standard-clojure-style/node_modules/minimatch": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", + "integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/@fortawesome/fontawesome-common-types": { "version": "0.2.36", "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.36.tgz", @@ -74,6 +142,109 @@ "react": ">=16.x" } }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@isaacs/cliui/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@isaacs/cliui/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", @@ -171,6 +342,13 @@ "util": "^0.10.4" } }, + "node_modules/async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha512-nSVgobk4rv61R9PUSDtYt7mPVB2olxNR5RWJcAsH676/ef11bUZwvu7+RGYrYauVdDPcO519v68wRhXQtxsV9w==", + "dev": true, + "license": "MIT" + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -597,6 +775,21 @@ "sha.js": "^2.4.8" } }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/crypto-browserify": { "version": "3.12.0", "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz", @@ -968,6 +1161,23 @@ "readable-stream": "^2.0.2" } }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true, + "license": "MIT" + }, + "node_modules/edn-data": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/edn-data/-/edn-data-1.1.2.tgz", + "integrity": "sha512-RI1i17URvOrBtSNEccbsXkuUZdc67QUBMqXGF62KPek85EdFGS2UKw76hNhOBl5kK4h7V4d32Ut15b/XVwKEXA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/elliptic": { "version": "6.6.0", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.6.0.tgz", @@ -1053,6 +1263,36 @@ "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", "dev": true }, + "node_modules/foreground-child": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", + "integrity": "sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg==", + "dev": true, + "license": "ISC", + "dependencies": { + "cross-spawn": "^7.0.0", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/fs-plus": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/fs-plus/-/fs-plus-3.1.1.tgz", + "integrity": "sha512-Se2PJdOWXqos1qVTkvqqjb0CSnfBnwwD+pq+z4ksT+e97mEShod/hrNg0TRCCsXPbJzcIq+NuzQhigunMWMJUA==", + "dev": true, + "license": "MIT", + "dependencies": { + "async": "^1.5.2", + "mkdirp": "^0.5.1", + "rimraf": "^2.5.2", + "underscore-plus": "1.x" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -1389,6 +1629,29 @@ "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", "dev": true }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, + "node_modules/jackspeak": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.2.tgz", + "integrity": "sha512-bZsjR/iRjl1Nk1UkjGpAzLNfQtzuijhn2g+pbZb98HQ1Gk8vM9hfbxeMBP+M2/UUdwj0RqGG3mlvk2MsAqwvEw==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -1554,6 +1817,29 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/minipass": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, + "node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, + "license": "MIT", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, "node_modules/mkdirp-classic": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", @@ -1680,6 +1966,13 @@ "integrity": "sha512-gjcpUc3clBf9+210TRaDWbf+rZZZEshZ+DlXMRCeAjp0xhTrnQsKHypIy1J3d5hKdUzj69t708EHtU8P6bUn0A==", "dev": true }, + "node_modules/package-json-from-dist": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", + "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==", + "dev": true, + "license": "BlueOak-1.0.0" + }, "node_modules/pako": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", @@ -1728,6 +2021,16 @@ "node": ">=0.10.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", @@ -1743,6 +2046,33 @@ "node": ">= 0.8.0" } }, + "node_modules/path-scurry": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-2.0.0.tgz", + "integrity": "sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "lru-cache": "^11.0.0", + "minipass": "^7.1.2" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/path-scurry/node_modules/lru-cache": { + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.2.tgz", + "integrity": "sha512-123qHRfJBmo2jXDbo/a5YOQrJoHF/GNQTLzQ5+IdK5pWpceK17yRc6ozlWd25FxvGKQbIUs91fDFkXmDHTKcyA==", + "dev": true, + "license": "ISC", + "engines": { + "node": "20 || >=22" + } + }, "node_modules/pbkdf2": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.2.tgz", @@ -1948,6 +2278,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", + "dev": true, + "license": "ISC", + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + } + }, "node_modules/ripemd160": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", @@ -2065,6 +2409,29 @@ "fast-safe-stringify": "^2.0.7" } }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/shell-quote": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", @@ -2092,6 +2459,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/simple-concat": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", @@ -2218,6 +2598,22 @@ "node": ">=8" } }, + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", @@ -2229,6 +2625,20 @@ "node": ">=8" } }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/subarg": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/subarg/-/subarg-1.0.0.tgz", @@ -2352,6 +2762,22 @@ "undeclared-identifiers": "bin.js" } }, + "node_modules/underscore": { + "version": "1.13.7", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.7.tgz", + "integrity": "sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==", + "dev": true, + "license": "MIT" + }, + "node_modules/underscore-plus": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/underscore-plus/-/underscore-plus-1.7.0.tgz", + "integrity": "sha512-A3BEzkeicFLnr+U/Q3EyWwJAQPbA19mtZZ4h+lLq3ttm9kn8WC4R3YpuJZEXmWdLjYP47Zc8aLZm9kwdv+zzvA==", + "dev": true, + "dependencies": { + "underscore": "^1.9.1" + } + }, "node_modules/url": { "version": "0.11.3", "resolved": "https://registry.npmjs.org/url/-/url-0.11.3.tgz", @@ -2821,6 +3247,22 @@ "webidl-conversions": "^3.0.0" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -2837,6 +3279,25 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", @@ -2910,6 +3371,19 @@ "engines": { "node": ">=12" } + }, + "node_modules/yoctocolors": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/yoctocolors/-/yoctocolors-2.1.1.tgz", + "integrity": "sha512-GQHQqAopRhwU8Kt1DDM8NjibDXHC8eoh1erhGAJPEyveY9qqVeXvVikNKrDz69sHowPMorbPUrH/mx8c50eiBQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } } } } diff --git a/package.json b/package.json index bb1a6fb0..ff522ed7 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "vega-lite": "^5.1.1" }, "devDependencies": { + "@chrisoakman/standard-clojure-style": "^0.18.0", "browserify": "^16.5.2", "nbb": "^1.2.187", "source-map-support": "^0.5.20", diff --git a/src/examples/data.cljc b/src/examples/data.cljc index 7568aec5..61b4c92b 100644 --- a/src/examples/data.cljc +++ b/src/examples/data.cljc @@ -1,19 +1,27 @@ (ns examples.data - (:require #?(:clj [clojure.java.io :as io]) - #?(:org.babashka/nbb [clojure.core] - :default [examples.hacker-news :as hn]) - [clojure.pprint :as pp] - [examples.macros :refer [read-file]] - [portal.colors :as c] - [portal.viewer :as v]) - #?(:clj (:import [java.io ByteArrayOutputStream File] - [java.net URI] - [java.util Date] - [java.util UUID]) - :org.babashka/nbb (:import) - :cljs (:import [goog.math Long]) - :cljr (:import [System DateTime Guid Uri] - [System.IO File]))) + (:require + [clojure.pprint :as pp] + [examples.macros :refer [read-file]] + [portal.colors :as c] + [portal.viewer :as v] + #?@(:clj + [[clojure.java.io :as io] + [examples.hacker-news :as hn]] + + :default + [[examples.hacker-news :as hn]])) + (:import + #?@(:clj + [(java.io ByteArrayOutputStream File) + (java.net URI) + (java.util Date UUID)] + + :cljr + [(System DateTime Guid Uri) + (System.IO File)] + + :cljs + [(goog.math Long)]))) #?(:clj (defn slurp-bytes [x] @@ -116,145 +124,145 @@ ::atom (atom ::hello) ::function println (with-meta 'symbol-key-with-meta {:a :b}) ::value - ;;TODO: fix me, causes infinite loop in demo - ;;::range (range) + ;; TODO: fix me, causes infinite loop in demo + ;; ::range (range) ::record #?(:bb {:x 0 :y 0} :default (->Point 0 0))}) (def map-reflection-data (v/table - '{asTransient - [{:name asTransient - :return-type - clojure.lang.ITransientMap - :declaring-class - clojure.lang.PersistentArrayMap - :parameter-types [] - :exception-types [] - :flags #{:public}} - {:name asTransient - :return-type - clojure.lang.ITransientCollection - :declaring-class - clojure.lang.PersistentArrayMap - :parameter-types [] - :exception-types [] - :flags #{:public :bridge :synthetic}}] - assoc - [{:name assoc - :return-type - clojure.lang.IPersistentMap - :declaring-class - clojure.lang.PersistentArrayMap - :parameter-types [java.lang.Object java.lang.Object] - :exception-types [] - :flags #{:public}} - {:name assoc - :return-type clojure.lang.Associative - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [java.lang.Object] - :exception-types [] - :flags #{:public :bridge :synthetic}}] - PersistentArrayMap - [{:name clojure.lang.PersistentArrayMap - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [clojure.lang.IPersistentMap java.lang.Object<>] - :exception-types [] - :flags #{:public}} - {:name clojure.lang.PersistentArrayMap - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [] - :exception-types [] - :flags #{:protected}} - {:name clojure.lang.PersistentArrayMap - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [java.lang.Object<>] - :exception-types [] - :flags #{:public}}] - count - [{:name count - :return-type int - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [] - :exception-types [] - :flags #{:public}}] - create - [{:name create - :return-type clojure.lang.PersistentArrayMap - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types - [java.lang.Object<>] - :exception-types [] - :flags #{:varargs}} - {:name create - :return-type clojure.lang.IPersistentMap - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [java.util.Map] - :exception-types [] - :flags #{:public :static}}] - empty - [{:name empty - :return-type clojure.lang.IPersistentMap - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [] - :exception-types [] - :flags #{:public}} - {:name empty - :return-type clojure.lang.IPersistentCollection - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [] - :exception-types [] - :flags #{:public :bridge :synthetic}}] - meta - [{:name meta - :return-type clojure.lang.IPersistentMap - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [] - :exception-types [] - :flags #{:public}}] - withMeta - [{:name withMeta - :return-type clojure.lang.IObj - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [clojure.lang.IPersistentMap] - :exception-types [] - :flags #{:public :bridge :synthetic}} - {:name withMeta - :return-type clojure.lang.PersistentArrayMap - :declaring-class clojure.lang.PersistentArrayMap - :parameter-types [clojure.lang.IPersistentMap] - :exception-types [] - :flags #{:public}}]} - {:columns [:flags :parameter-types :return-type]})) + '{asTransient + [{:name asTransient + :return-type + clojure.lang.ITransientMap + :declaring-class + clojure.lang.PersistentArrayMap + :parameter-types [] + :exception-types [] + :flags #{:public}} + {:name asTransient + :return-type + clojure.lang.ITransientCollection + :declaring-class + clojure.lang.PersistentArrayMap + :parameter-types [] + :exception-types [] + :flags #{:public :bridge :synthetic}}] + assoc + [{:name assoc + :return-type + clojure.lang.IPersistentMap + :declaring-class + clojure.lang.PersistentArrayMap + :parameter-types [java.lang.Object java.lang.Object] + :exception-types [] + :flags #{:public}} + {:name assoc + :return-type clojure.lang.Associative + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [java.lang.Object] + :exception-types [] + :flags #{:public :bridge :synthetic}}] + PersistentArrayMap + [{:name clojure.lang.PersistentArrayMap + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [clojure.lang.IPersistentMap java.lang.Object<>] + :exception-types [] + :flags #{:public}} + {:name clojure.lang.PersistentArrayMap + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [] + :exception-types [] + :flags #{:protected}} + {:name clojure.lang.PersistentArrayMap + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [java.lang.Object<>] + :exception-types [] + :flags #{:public}}] + count + [{:name count + :return-type int + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [] + :exception-types [] + :flags #{:public}}] + create + [{:name create + :return-type clojure.lang.PersistentArrayMap + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types + [java.lang.Object<>] + :exception-types [] + :flags #{:varargs}} + {:name create + :return-type clojure.lang.IPersistentMap + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [java.util.Map] + :exception-types [] + :flags #{:public :static}}] + empty + [{:name empty + :return-type clojure.lang.IPersistentMap + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [] + :exception-types [] + :flags #{:public}} + {:name empty + :return-type clojure.lang.IPersistentCollection + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [] + :exception-types [] + :flags #{:public :bridge :synthetic}}] + meta + [{:name meta + :return-type clojure.lang.IPersistentMap + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [] + :exception-types [] + :flags #{:public}}] + withMeta + [{:name withMeta + :return-type clojure.lang.IObj + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [clojure.lang.IPersistentMap] + :exception-types [] + :flags #{:public :bridge :synthetic}} + {:name withMeta + :return-type clojure.lang.PersistentArrayMap + :declaring-class clojure.lang.PersistentArrayMap + :parameter-types [clojure.lang.IPersistentMap] + :exception-types [] + :flags #{:public}}]} + {:columns [:flags :parameter-types :return-type]})) (def diff-data (v/diff - [{::removed "value" - ::same-key "same-value" - ::change-type #{1 2} - ::deep-change {:a 0} - ::set #{0 1 2} - ::vector [::a ::removed ::b] - ::different-value ::old-key} - {::added "value" - ::same-key "same-value" - ::change-type {:a :b :c :d} - ::deep-change {:a 1} - ::set #{1 2 3} - ::vector [::a ::added ::b] - ::different-value ::new-key}])) + [{::removed "value" + ::same-key "same-value" + ::change-type #{1 2} + ::deep-change {:a 0} + ::set #{0 1 2} + ::vector [::a ::removed ::b] + ::different-value ::old-key} + {::added "value" + ::same-key "same-value" + ::change-type {:a :b :c :d} + ::deep-change {:a 1} + ::set #{1 2 3} + ::vector [::a ::added ::b] + ::different-value ::new-key}])) (def diff-text-data (v/diff-text - [(with-out-str (pp/pprint (first diff-data))) - (with-out-str (pp/pprint (second diff-data)))])) + [(with-out-str (pp/pprint (first diff-data))) + (with-out-str (pp/pprint (second diff-data)))])) (def string-data (v/for - {::json "{\"hello\": 123}" - ::edn "^{:portal.viewer/default :portal.viewer/tree} {:hello 123}" - ::csv "a,b,c\n1,2,3\n4,5,6" - ::markdown (read-file "README.md") - ::jwt "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiSm9lIENvZGVyIn0.5dlp7GmziL2QS06sZgK4mtaqv0_xX4oFUuTDh1zHK4U"} + {::json "{\"hello\": 123}" + ::edn "^{:portal.viewer/default :portal.viewer/tree} {:hello 123}" + ::csv "a,b,c\n1,2,3\n4,5,6" + ::markdown (read-file "README.md") + ::jwt "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiSm9lIENvZGVyIn0.5dlp7GmziL2QS06sZgK4mtaqv0_xX4oFUuTDh1zHK4U"} {::json ::v/json ::edn ::v/edn ::csv ::v/csv @@ -263,71 +271,71 @@ (def hiccup (v/hiccup - [:<> - [:h1 "Hello, I'm hiccup"] - [:a {:href "https://github.com/djblue/portal"} "djblue/portal"] - [::v/inspector {:hello :world}]])) + [:<> + [:h1 "Hello, I'm hiccup"] + [:a {:href "https://github.com/djblue/portal"} "djblue/portal"] + [::v/inspector {:hello :world}]])) (defn- sin [x] #?(:cljr (Math/Sin x) :default (Math/sin x))) (def line-chart (v/vega-lite - {:$schema "https://vega.github.io/schema/vega-lite/v5.json" - :data {:values - (map #(-> {:time % :value (sin %)}) - (range 0 (* 2 3.14) 0.25))} - :encoding {:x {:field "time" :type "quantitative"} - :y {:field "value" :type "quantitative"}} - :mark "line"})) + {:$schema "https://vega.github.io/schema/vega-lite/v5.json" + :data {:values + (map #(-> {:time % :value (sin %)}) + (range 0 (* 2 3.14) 0.25))} + :encoding {:x {:field "time" :type "quantitative"} + :y {:field "value" :type "quantitative"}} + :mark "line"})) (def bar-chart (v/vega-lite - {:$schema "https://vega.github.io/schema/vega-lite/v5.json" - :data - {:values - [{:a "A", :b 28} - {:a "B", :b 55} - {:a "C", :b 43} - {:a "D", :b 91} - {:a "E", :b 81} - {:a "F", :b 53}]} - :mark "bar" - :encoding - {:x - {:field "a" - :type "nominal" - :axis {:labelAngle 0}} - :y {:field "b", :type "quantitative"}}})) + {:$schema "https://vega.github.io/schema/vega-lite/v5.json" + :data + {:values + [{:a "A", :b 28} + {:a "B", :b 55} + {:a "C", :b 43} + {:a "D", :b 91} + {:a "E", :b 81} + {:a "F", :b 53}]} + :mark "bar" + :encoding + {:x + {:field "a" + :type "nominal" + :axis {:labelAngle 0}} + :y {:field "b", :type "quantitative"}}})) (def pie-chart (v/vega-lite - {:$schema "https://vega.github.io/schema/vega-lite/v5.json" - :description "A simple pie chart with labels." - :data - {:values - [{:category "a", :value 4} - {:category "b", :value 6} - {:category "c", :value 10} - {:category "d", :value 3} - {:category "e", :value 7} - {:category "f", :value 8}]} - :encoding - {:theta - {:field "value" - :type "quantitative" - :stack true} - :color - {:field "category" - :type "nominal" - :legend nil}} - :layer - [{:mark {:type "arc", :outerRadius 80}} - {:mark {:type "text", :radius 90} - :encoding - {:text - {:field "category", :type "nominal"}}}] - :view {:stroke nil}})) + {:$schema "https://vega.github.io/schema/vega-lite/v5.json" + :description "A simple pie chart with labels." + :data + {:values + [{:category "a", :value 4} + {:category "b", :value 6} + {:category "c", :value 10} + {:category "d", :value 3} + {:category "e", :value 7} + {:category "f", :value 8}]} + :encoding + {:theta + {:field "value" + :type "quantitative" + :stack true} + :color + {:field "category" + :type "nominal" + :legend nil}} + :layer + [{:mark {:type "arc", :outerRadius 80}} + {:mark {:type "text", :radius 90} + :encoding + {:text + {:field "category", :type "nominal"}}}] + :view {:stroke nil}})) (def tabular-data (map #(-> {:x % :y (sin %)}) @@ -340,744 +348,744 @@ (def scatter-chart (v/vega-lite - {:$schema "https://vega.github.io/schema/vega-lite/v5.json" - :description - "A scatterplot showing horsepower and miles per gallons for various cars." - :data {:url "https://vega.github.io/vega-lite/data/cars.json"} - :mark "point" - :encoding - {:x - {:field "Horsepower", :type "quantitative"} - :y - {:field "Miles_per_Gallon" - :type "quantitative"}}})) + {:$schema "https://vega.github.io/schema/vega-lite/v5.json" + :description + "A scatterplot showing horsepower and miles per gallons for various cars." + :data {:url "https://vega.github.io/vega-lite/data/cars.json"} + :mark "point" + :encoding + {:x + {:field "Horsepower", :type "quantitative"} + :y + {:field "Miles_per_Gallon" + :type "quantitative"}}})) (def vconcat-chart (v/vega-lite - {:$schema "https://vega.github.io/schema/vega-lite/v5.json" - :data {:url "https://vega.github.io/editor/data/weather.csv"}, - :transform [{:filter "datum.location === 'Seattle'"}], - :vconcat - [{:mark "bar", - :encoding - {:x {:timeUnit "month", :field "date", :type "ordinal"}, - :y - {:aggregate "mean", :field "precipitation", :type "quantitative"}}} - {:mark "point", - :encoding - {:x {:field "temp_min", :type "quantitative", :bin true}, - :y {:field "temp_max", :type "quantitative", :bin true}, - :size {:aggregate "count", :type "quantitative"}}}]})) + {:$schema "https://vega.github.io/schema/vega-lite/v5.json" + :data {:url "https://vega.github.io/editor/data/weather.csv"} + :transform [{:filter "datum.location === 'Seattle'"}] + :vconcat + [{:mark "bar" + :encoding + {:x {:timeUnit "month", :field "date", :type "ordinal"} + :y + {:aggregate "mean", :field "precipitation", :type "quantitative"}}} + {:mark "point" + :encoding + {:x {:field "temp_min", :type "quantitative", :bin true} + :y {:field "temp_max", :type "quantitative", :bin true} + :size {:aggregate "count", :type "quantitative"}}}]})) (def hconcat-chart (v/vega-lite - {:$schema "https://vega.github.io/schema/vega-lite/v5.json" - :data {:url "https://vega.github.io/editor/data/weather.csv"}, - :transform [{:filter "datum.location === 'Seattle'"}], - :hconcat - [{:mark "bar", - :encoding - {:x {:timeUnit "month", :field "date", :type "ordinal"}, - :y {:aggregate "mean", :field "precipitation"}}} - {:mark "point", - :encoding - {:x {:field "temp_min", :bin true}, - :y {:field "temp_max", :bin true}, - :size {:aggregate "count"}}}]})) + {:$schema "https://vega.github.io/schema/vega-lite/v5.json" + :data {:url "https://vega.github.io/editor/data/weather.csv"} + :transform [{:filter "datum.location === 'Seattle'"}] + :hconcat + [{:mark "bar" + :encoding + {:x {:timeUnit "month", :field "date", :type "ordinal"} + :y {:aggregate "mean", :field "precipitation"}}} + {:mark "point" + :encoding + {:x {:field "temp_min", :bin true} + :y {:field "temp_max", :bin true} + :size {:aggregate "count"}}}]})) (def geographic-data (v/vega-lite - {:$schema "https://vega.github.io/schema/vega-lite/v5.json" - :data {:url "https://vega.github.io/vega-lite/data/airports.csv"} - :projection {:type "albersUsa"} - :mark "circle" - :encoding - {:longitude - {:field "longitude", :type "quantitative"} - :latitude - {:field "latitude", :type "quantitative"} - :size {:value 10}} - :config {:view {:stroke "transparent"}}})) + {:$schema "https://vega.github.io/schema/vega-lite/v5.json" + :data {:url "https://vega.github.io/vega-lite/data/airports.csv"} + :projection {:type "albersUsa"} + :mark "circle" + :encoding + {:longitude + {:field "longitude", :type "quantitative"} + :latitude + {:field "latitude", :type "quantitative"} + :size {:value 10}} + :config {:view {:stroke "transparent"}}})) (def histogram-heatmap-2D (v/vega-lite - {:$schema "https://vega.github.io/schema/vega-lite/v5.json" - :data {:url "https://vega.github.io/vega-lite/data/movies.json"} - :transform - [{:filter - {:and - [{:field "IMDB Rating", :valid true} - {:field "Rotten Tomatoes Rating" - :valid true}]}}] - :mark "rect" - :height 400 - :encoding - {:x - {:bin {:maxbins 60} - :field "IMDB Rating" - :type "quantitative"} - :y - {:bin {:maxbins 40} - :field "Rotten Tomatoes Rating" - :type "quantitative"} - :color - {:aggregate "count", :type "quantitative"}} - :config {:view {:stroke "transparent"}}})) + {:$schema "https://vega.github.io/schema/vega-lite/v5.json" + :data {:url "https://vega.github.io/vega-lite/data/movies.json"} + :transform + [{:filter + {:and + [{:field "IMDB Rating", :valid true} + {:field "Rotten Tomatoes Rating" + :valid true}]}}] + :mark "rect" + :height 400 + :encoding + {:x + {:bin {:maxbins 60} + :field "IMDB Rating" + :type "quantitative"} + :y + {:bin {:maxbins 40} + :field "Rotten Tomatoes Rating" + :type "quantitative"} + :color + {:aggregate "count", :type "quantitative"}} + :config {:view {:stroke "transparent"}}})) (def force-directed (v/vega - {:title "Force Directed Layout" - :description - "A node-link diagram with force-directed layout, depicting character co-occurrence in the novel Les Misérables." - :scales - [{:name "color" - :type "ordinal" - :domain {:data "node-data", :field "group"} - :range {:scheme "category20c"}}] - :marks - [{:name "nodes" - :type "symbol" - :zindex 1 - :from {:data "node-data"} - :on - [{:trigger "fix" - :modify "node" - :values - "fix === true ? {fx: node.x, fy: node.y} : {fx: fix[0], fy: fix[1]}"} - {:trigger "!fix" - :modify "node" - :values "{fx: null, fy: null}"}] - :encode - {:enter - {:fill {:scale "color", :field "group"} - :stroke {:value "white"}} - :update - {:size - {:signal "2 * nodeRadius * nodeRadius"} - :cursor {:value "pointer"}}} - :transform - [{:type "force" - :iterations 300 - :restart {:signal "restart"} - :static {:signal "static"} - :signal "force" - :forces - [{:force "center" - :x {:signal "cx"} - :y {:signal "cy"}} - {:force "collide" - :radius {:signal "nodeRadius"}} - {:force "nbody" - :strength {:signal "nodeCharge"}} - {:force "link" - :links "link-data" - :distance {:signal "linkDistance"}}]}]} - {:type "path" - :from {:data "link-data"} - :interactive false - :encode - {:update - {:stroke {:value "#ccc"} - :strokeWidth {:value 0.5}}} - :transform - [{:type "linkpath" - :require {:signal "force"} - :shape "line" - :sourceX "datum.source.x" - :sourceY "datum.source.y" - :targetX "datum.target.x" - :targetY "datum.target.y"}]}] - :$schema - "https://vega.github.io/schema/vega/v5.json" - :signals - [{:name "cx", :update "width / 2"} - {:name "cy", :update "height / 2"} - {:name "nodeRadius" - :value 8 - :bind - {:input "range", :min 1, :max 50, :step 1}} - {:name "nodeCharge" - :value -30 - :bind - {:input "range" - :min -100 - :max 10 - :step 1}} - {:name "linkDistance" - :value 30 - :bind - {:input "range", :min 5, :max 100, :step 1}} - {:name "static" - :value true - :bind {:input "checkbox"}} - {:description - "State variable for active node fix status." - :name "fix" - :value false - :on - [{:events - "symbol:mouseout[!event.buttons], window:mouseup" - :update "false"} - {:events "symbol:mouseover" - :update "fix || true"} - {:events - "[symbol:mousedown, window:mouseup] > window:mousemove!" - :update "xy()" - :force true}]} - {:description - "Graph node most recently interacted with." - :name "node" - :value nil - :on - [{:events "symbol:mouseover" - :update "fix === true ? item() : node"}]} - {:description - "Flag to restart Force simulation upon data changes." - :name "restart" - :value false - :on - [{:events {:signal "fix"} - :update "fix && fix.length"}]}] - :data - [{:name "node-data" - :url "https://vega.github.io/vega-lite/data/miserables.json" - :format {:type "json", :property "nodes"}} - {:name "link-data" - :url "https://vega.github.io/vega-lite/data/miserables.json" - :format {:type "json", :property "links"}}]})) + {:title "Force Directed Layout" + :description + "A node-link diagram with force-directed layout, depicting character co-occurrence in the novel Les Misérables." + :scales + [{:name "color" + :type "ordinal" + :domain {:data "node-data", :field "group"} + :range {:scheme "category20c"}}] + :marks + [{:name "nodes" + :type "symbol" + :zindex 1 + :from {:data "node-data"} + :on + [{:trigger "fix" + :modify "node" + :values + "fix === true ? {fx: node.x, fy: node.y} : {fx: fix[0], fy: fix[1]}"} + {:trigger "!fix" + :modify "node" + :values "{fx: null, fy: null}"}] + :encode + {:enter + {:fill {:scale "color", :field "group"} + :stroke {:value "white"}} + :update + {:size + {:signal "2 * nodeRadius * nodeRadius"} + :cursor {:value "pointer"}}} + :transform + [{:type "force" + :iterations 300 + :restart {:signal "restart"} + :static {:signal "static"} + :signal "force" + :forces + [{:force "center" + :x {:signal "cx"} + :y {:signal "cy"}} + {:force "collide" + :radius {:signal "nodeRadius"}} + {:force "nbody" + :strength {:signal "nodeCharge"}} + {:force "link" + :links "link-data" + :distance {:signal "linkDistance"}}]}]} + {:type "path" + :from {:data "link-data"} + :interactive false + :encode + {:update + {:stroke {:value "#ccc"} + :strokeWidth {:value 0.5}}} + :transform + [{:type "linkpath" + :require {:signal "force"} + :shape "line" + :sourceX "datum.source.x" + :sourceY "datum.source.y" + :targetX "datum.target.x" + :targetY "datum.target.y"}]}] + :$schema + "https://vega.github.io/schema/vega/v5.json" + :signals + [{:name "cx", :update "width / 2"} + {:name "cy", :update "height / 2"} + {:name "nodeRadius" + :value 8 + :bind + {:input "range", :min 1, :max 50, :step 1}} + {:name "nodeCharge" + :value -30 + :bind + {:input "range" + :min -100 + :max 10 + :step 1}} + {:name "linkDistance" + :value 30 + :bind + {:input "range", :min 5, :max 100, :step 1}} + {:name "static" + :value true + :bind {:input "checkbox"}} + {:description + "State variable for active node fix status." + :name "fix" + :value false + :on + [{:events + "symbol:mouseout[!event.buttons], window:mouseup" + :update "false"} + {:events "symbol:mouseover" + :update "fix || true"} + {:events + "[symbol:mousedown, window:mouseup] > window:mousemove!" + :update "xy()" + :force true}]} + {:description + "Graph node most recently interacted with." + :name "node" + :value nil + :on + [{:events "symbol:mouseover" + :update "fix === true ? item() : node"}]} + {:description + "Flag to restart Force simulation upon data changes." + :name "restart" + :value false + :on + [{:events {:signal "fix"} + :update "fix && fix.length"}]}] + :data + [{:name "node-data" + :url "https://vega.github.io/vega-lite/data/miserables.json" + :format {:type "json", :property "nodes"}} + {:name "link-data" + :url "https://vega.github.io/vega-lite/data/miserables.json" + :format {:type "json", :property "links"}}]})) (def radial-tree (v/vega - {:title "Radial Tree" - :description - "An example of a radial layout for a node-link diagram of hierarchical data." - :scales - [{:name "color" - :type "linear" - :range {:scheme "magma"} - :domain {:data "tree", :field "depth"} - :zero true}] - :marks - [{:type "path" - :from {:data "links"} - :encode - {:update - {:x {:signal "originX"} - :y {:signal "originY"} - :path {:field "path"} - :stroke {:value "#ccc"}}}} - {:type "symbol" - :from {:data "tree"} - :encode - {:enter - {:size {:value 100} - :stroke {:value "#fff"}} - :update - {:x {:field "x"} - :y {:field "y"} - :fill {:scale "color", :field "depth"}}}} - {:type "text" - :from {:data "tree"} - :encode - {:enter - {:text {:field "name"} - :fontSize {:value 9} - :fill {:value "#fff"} - :baseline {:value "middle"}} - :update - {:x {:field "x"} - :y {:field "y"} - :dx - {:signal "(datum.leftside ? -1 : 1) * 6"} - :angle - {:signal - "datum.leftside ? datum.angle - 180 : datum.angle"} - :align - {:signal - "datum.leftside ? 'right' : 'left'"} - :opacity {:signal "labels ? 1 : 0"}}}}] - :$schema - "https://vega.github.io/schema/vega/v5.json" - :signals - [{:name "labels" - :value true - :bind {:input "checkbox"}} - {:name "radius" - :value 280 - :bind {:input "range", :min 20, :max 600}} - {:name "extent" - :value 360 - :bind - {:input "range", :min 0, :max 360, :step 1}} - {:name "rotate" - :value 0 - :bind - {:input "range", :min 0, :max 360, :step 1}} - {:name "layout" - :value "tidy" - :bind - {:input "radio" - :options ["tidy" "cluster"]}} - {:name "links" - :value "line" - :bind - {:input "select" - :options - ["line" "curve" "diagonal" "orthogonal"]}} - {:name "originX", :update "width / 2"} - {:name "originY", :update "height / 2"}] - :data - [{:name "tree" - :url "https://vega.github.io/vega-lite/data/flare.json" - :transform - [{:type "stratify" - :key "id" - :parentKey "parent"} - {:type "tree" - :method {:signal "layout"} - :size [1 {:signal "radius"}] - :as ["alpha" "radius" "depth" "children"]} - {:type "formula" - :expr - "(rotate + extent * datum.alpha + 270) % 360" - :as "angle"} - {:type "formula" - :expr "PI * datum.angle / 180" - :as "radians"} - {:type "formula" - :expr "inrange(datum.angle, [90, 270])" - :as "leftside"} - {:type "formula" - :expr - "originX + datum.radius * cos(datum.radians)" - :as "x"} - {:type "formula" - :expr - "originY + datum.radius * sin(datum.radians)" - :as "y"}]} - {:name "links" - :source "tree" - :transform - [{:type "treelinks"} - {:type "linkpath" - :shape {:signal "links"} - :orient "radial" - :sourceX "source.radians" - :sourceY "source.radius" - :targetX "target.radians" - :targetY "target.radius"}]}]})) + {:title "Radial Tree" + :description + "An example of a radial layout for a node-link diagram of hierarchical data." + :scales + [{:name "color" + :type "linear" + :range {:scheme "magma"} + :domain {:data "tree", :field "depth"} + :zero true}] + :marks + [{:type "path" + :from {:data "links"} + :encode + {:update + {:x {:signal "originX"} + :y {:signal "originY"} + :path {:field "path"} + :stroke {:value "#ccc"}}}} + {:type "symbol" + :from {:data "tree"} + :encode + {:enter + {:size {:value 100} + :stroke {:value "#fff"}} + :update + {:x {:field "x"} + :y {:field "y"} + :fill {:scale "color", :field "depth"}}}} + {:type "text" + :from {:data "tree"} + :encode + {:enter + {:text {:field "name"} + :fontSize {:value 9} + :fill {:value "#fff"} + :baseline {:value "middle"}} + :update + {:x {:field "x"} + :y {:field "y"} + :dx + {:signal "(datum.leftside ? -1 : 1) * 6"} + :angle + {:signal + "datum.leftside ? datum.angle - 180 : datum.angle"} + :align + {:signal + "datum.leftside ? 'right' : 'left'"} + :opacity {:signal "labels ? 1 : 0"}}}}] + :$schema + "https://vega.github.io/schema/vega/v5.json" + :signals + [{:name "labels" + :value true + :bind {:input "checkbox"}} + {:name "radius" + :value 280 + :bind {:input "range", :min 20, :max 600}} + {:name "extent" + :value 360 + :bind + {:input "range", :min 0, :max 360, :step 1}} + {:name "rotate" + :value 0 + :bind + {:input "range", :min 0, :max 360, :step 1}} + {:name "layout" + :value "tidy" + :bind + {:input "radio" + :options ["tidy" "cluster"]}} + {:name "links" + :value "line" + :bind + {:input "select" + :options + ["line" "curve" "diagonal" "orthogonal"]}} + {:name "originX", :update "width / 2"} + {:name "originY", :update "height / 2"}] + :data + [{:name "tree" + :url "https://vega.github.io/vega-lite/data/flare.json" + :transform + [{:type "stratify" + :key "id" + :parentKey "parent"} + {:type "tree" + :method {:signal "layout"} + :size [1 {:signal "radius"}] + :as ["alpha" "radius" "depth" "children"]} + {:type "formula" + :expr + "(rotate + extent * datum.alpha + 270) % 360" + :as "angle"} + {:type "formula" + :expr "PI * datum.angle / 180" + :as "radians"} + {:type "formula" + :expr "inrange(datum.angle, [90, 270])" + :as "leftside"} + {:type "formula" + :expr + "originX + datum.radius * cos(datum.radians)" + :as "x"} + {:type "formula" + :expr + "originY + datum.radius * sin(datum.radians)" + :as "y"}]} + {:name "links" + :source "tree" + :transform + [{:type "treelinks"} + {:type "linkpath" + :shape {:signal "links"} + :orient "radial" + :sourceX "source.radians" + :sourceY "source.radius" + :targetX "target.radians" + :targetY "target.radius"}]}]})) (def sunburst (v/vega - {:title "Sunburst" - :description - "An example of a space-fulling radial layout for hierarchical data." - :scales - [{:name "color" - :type "ordinal" - :domain {:data "tree", :field "depth"} - :range {:scheme "tableau20"}}] - :marks - [{:type "arc" - :from {:data "tree"} - :encode - {:enter - {:x {:signal "width / 2"} - :y {:signal "height / 2"} - :fill {:scale "color", :field "depth"} - :tooltip - {:signal - "datum.name + (datum.size ? ', ' + datum.size + ' bytes' : '')"}} - :update - {:startAngle {:field "a0"} - :endAngle {:field "a1"} - :innerRadius {:field "r0"} - :outerRadius {:field "r1"} - :stroke {:value "white"} - :strokeWidth {:value 0.5} - :zindex {:value 0}} - :hover - {:stroke {:value "red"} - :strokeWidth {:value 2} - :zindex {:value 1}}}}] - :$schema - "https://vega.github.io/schema/vega/v5.json" - :data - [{:name "tree" - :url "https://vega.github.io/vega-lite/data/flare.json" - :transform - [{:type "stratify" - :key "id" - :parentKey "parent"} - {:type "partition" - :field "size" - :sort {:field "value"} - :size - [{:signal "2 * PI"} - {:signal "width / 2"}] - :as - ["a0" - "r0" - "a1" - "r1" - "depth" - "children"]}]}]})) + {:title "Sunburst" + :description + "An example of a space-fulling radial layout for hierarchical data." + :scales + [{:name "color" + :type "ordinal" + :domain {:data "tree", :field "depth"} + :range {:scheme "tableau20"}}] + :marks + [{:type "arc" + :from {:data "tree"} + :encode + {:enter + {:x {:signal "width / 2"} + :y {:signal "height / 2"} + :fill {:scale "color", :field "depth"} + :tooltip + {:signal + "datum.name + (datum.size ? ', ' + datum.size + ' bytes' : '')"}} + :update + {:startAngle {:field "a0"} + :endAngle {:field "a1"} + :innerRadius {:field "r0"} + :outerRadius {:field "r1"} + :stroke {:value "white"} + :strokeWidth {:value 0.5} + :zindex {:value 0}} + :hover + {:stroke {:value "red"} + :strokeWidth {:value 2} + :zindex {:value 1}}}}] + :$schema + "https://vega.github.io/schema/vega/v5.json" + :data + [{:name "tree" + :url "https://vega.github.io/vega-lite/data/flare.json" + :transform + [{:type "stratify" + :key "id" + :parentKey "parent"} + {:type "partition" + :field "size" + :sort {:field "value"} + :size + [{:signal "2 * PI"} + {:signal "width / 2"}] + :as + ["a0" + "r0" + "a1" + "r1" + "depth" + "children"]}]}]})) (def log-data (mapv - #(-> % - (v/log) - (v/for {:time ::v/date-time})) - [{:ns 'user - :time #inst "2006-03-24T14:49:31+00:00" - :level :info - :column 1 - :line 1 - :result :hello/clj - :runtime :clj - :form :hello/clj} - {:ns 'user - :time #inst "2009-02-03T00:25:17-06:00" - :level :debug - :column 1 - :line 2 - :result :hello/cljr - :runtime :cljr - :form :hello/cljr} - {:ns 'cljs.user - :time #inst "2011-06-02T19:45:57-04:00" - :level :warn - :column 1 - :line 3 - :result :hello/cljs - :runtime :cljs - :form :hello/cljs} - {:ns 'tasks - :time #inst "2019-08-09T14:51:42+02:00" - :level :error - :column 1 - :line 4 - :result :hello/bb - :runtime :bb - :form :hello/bb} - {:ns 'portal.api - :time #inst "2020-06-02T18:43:08-07:00" - :level :info - :column 1 - :line 5 - :result :hello/portal - :runtime :portal - :form :hello/portal} - {:ns 'nbb.core - :time #inst "2021-07-27T15:38:51+02:00" - :level :debug - :column 1 - :line 6 - :result :hello/nbb - :runtime :nbb - :form :hello/nbb} - {:ns 'joyride.core - :time #inst "2022-04-24T00:24:46+02:00" - :level :error - :column 1 - :line 7 - :result :hello/joyride - :runtime :joyride - :form :hello/joyride}])) + #(-> % + (v/log) + (v/for {:time ::v/date-time})) + [{:ns 'user + :time #inst "2006-03-24T14:49:31+00:00" + :level :info + :column 1 + :line 1 + :result :hello/clj + :runtime :clj + :form :hello/clj} + {:ns 'user + :time #inst "2009-02-03T00:25:17-06:00" + :level :debug + :column 1 + :line 2 + :result :hello/cljr + :runtime :cljr + :form :hello/cljr} + {:ns 'cljs.user + :time #inst "2011-06-02T19:45:57-04:00" + :level :warn + :column 1 + :line 3 + :result :hello/cljs + :runtime :cljs + :form :hello/cljs} + {:ns 'tasks + :time #inst "2019-08-09T14:51:42+02:00" + :level :error + :column 1 + :line 4 + :result :hello/bb + :runtime :bb + :form :hello/bb} + {:ns 'portal.api + :time #inst "2020-06-02T18:43:08-07:00" + :level :info + :column 1 + :line 5 + :result :hello/portal + :runtime :portal + :form :hello/portal} + {:ns 'nbb.core + :time #inst "2021-07-27T15:38:51+02:00" + :level :debug + :column 1 + :line 6 + :result :hello/nbb + :runtime :nbb + :form :hello/nbb} + {:ns 'joyride.core + :time #inst "2022-04-24T00:24:46+02:00" + :level :error + :column 1 + :line 7 + :result :hello/joyride + :runtime :joyride + :form :hello/joyride}])) (defn- profile-ms [v] (v/for v - {:min ::v/duration-ns, - :mean ::v/duration-ns, - :p75 ::v/duration-ns, - :p99 ::v/duration-ns, - :p25 ::v/duration-ns, - :p90 ::v/duration-ns, - :max ::v/duration-ns, - :mad ::v/duration-ns, - :loc ::v/source-location, - :p50 ::v/duration-ns, - :sum ::v/duration-ns, + {:min ::v/duration-ns + :mean ::v/duration-ns + :p75 ::v/duration-ns + :p99 ::v/duration-ns + :p25 ::v/duration-ns + :p90 ::v/duration-ns + :max ::v/duration-ns + :mad ::v/duration-ns + :loc ::v/source-location + :p50 ::v/duration-ns + :sum ::v/duration-ns :p95 ::v/duration-ns})) (def profile-data (v/table - {:get-x - (profile-ms - {:min 500379167, - :mean 5.0368755E8, - :p75 5.05059583E8, - :mad-sum 8368282.0, - :p99 5.0514774364E8, - :n 5, - :p25 5.02811792E8, - :p90 5.051146834E8, - :var 3.5110970180224E12, - :max 505151417, - :mad 1673656.4, - :loc - {:ns 'user, - :line 16, - :column 6, - :file "/Users/chris/repos/portal/examples/tufte/src/user.clj"}, - :last 505151417, - :p50 5.05035791E8, - :sum 2518437750, - :p95 5.051330502E8, - :var-sum 1.7555485090112E13}), - :get-y - (profile-ms - {:min 352537834, - :mean 6.41027925E8, - :p75 9.79101417E8, - :mad-sum 1.388414716E9, - :p99 9.964393760400001E8, - :n 5, - :p25 4.0308575E8, - :p90 9.899376414000001E8, - :var 8.1823301849941472E16, - :max 997161791, - :mad 2.776829432E8, - :loc - {:ns 'user, - :line 17, - :column 6, - :file "/Users/chris/repos/portal/examples/tufte/src/user.clj"}, - :last 352537834, - :p50 4.73252833E8, - :sum 3205139625, - :p95 9.935497162E8, - :var-sum 4.0911650924970739E17})} - {:columns [:n :min :max :mean :sum :loc]})) + {:get-x + (profile-ms + {:min 500379167 + :mean 5.0368755E8 + :p75 5.05059583E8 + :mad-sum 8368282.0 + :p99 5.0514774364E8 + :n 5 + :p25 5.02811792E8 + :p90 5.051146834E8 + :var 3.5110970180224E12 + :max 505151417 + :mad 1673656.4 + :loc + {:ns 'user + :line 16 + :column 6 + :file "/Users/chris/repos/portal/examples/tufte/src/user.clj"} + :last 505151417 + :p50 5.05035791E8 + :sum 2518437750 + :p95 5.051330502E8 + :var-sum 1.7555485090112E13}) + :get-y + (profile-ms + {:min 352537834 + :mean 6.41027925E8 + :p75 9.79101417E8 + :mad-sum 1.388414716E9 + :p99 9.964393760400001E8 + :n 5 + :p25 4.0308575E8 + :p90 9.899376414000001E8 + :var 8.1823301849941472E16 + :max 997161791 + :mad 2.776829432E8 + :loc + {:ns 'user + :line 17 + :column 6 + :file "/Users/chris/repos/portal/examples/tufte/src/user.clj"} + :last 352537834 + :p50 4.73252833E8 + :sum 3205139625 + :p95 9.935497162E8 + :var-sum 4.0911650924970739E17})} + {:columns [:n :min :max :mean :sum :loc]})) (def table-data {::coll-of-maps (v/table log-data {:columns [:level :ns :result :runtime :time]}) ::nested-maps (v/table - {:ClojureScript {:nFiles 75 :blank 969 :comment 66 :code 7889} - :ClojureC {:nFiles 27 :blank 337 :comment 3 :code 2785} - :Clojure {:nFiles 41 :blank 288 :comment 11 :code 1909} - :SUM {:blank 1594 :comment 80 :code 12583 :nFiles 143}} - {:columns [:nFiles :blank :comment :code]}) + {:ClojureScript {:nFiles 75 :blank 969 :comment 66 :code 7889} + :ClojureC {:nFiles 27 :blank 337 :comment 3 :code 2785} + :Clojure {:nFiles 41 :blank 288 :comment 11 :code 1909} + :SUM {:blank 1594 :comment 80 :code 12583 :nFiles 143}} + {:columns [:nFiles :blank :comment :code]}) ::coll-of-vectors (v/table - [[1 0 0 0 0] - [0 1 0 0 0] - [0 0 1 0 0] - [0 0 0 1 0] - [0 0 0 0 1]] - {:columns [:a :b :c :d :e]}) + [[1 0 0 0 0] + [0 1 0 0 0] + [0 0 1 0 0] + [0 0 0 1 0] + [0 0 0 0 1]] + {:columns [:a :b :c :d :e]}) ::multi-map map-reflection-data}) (def test-report (v/test-report - [{:type :begin-test-ns - :ns (if *ns* *ns* 'examples.data)} - {:type :begin-test-var - :var #'test-report} - {:type :pass, - :expected '(= 0 0), - :actual '(= 0 0), - :message nil} - {:file "NO_SOURCE_FILE", - :type :fail, - :line 8, - :expected '(= 0 (inc 0)), - :actual '(not (= 0 1)), - :message nil} - {:type :end-test-var - :var #'test-report} - {:type :end-test-ns - :ns (if *ns* *ns* 'examples.data)}])) + [{:type :begin-test-ns + :ns (if *ns* *ns* 'examples.data)} + {:type :begin-test-var + :var #'test-report} + {:type :pass + :expected '(= 0 0) + :actual '(= 0 0) + :message nil} + {:file "NO_SOURCE_FILE" + :type :fail + :line 8 + :expected '(= 0 (inc 0)) + :actual '(not (= 0 1)) + :message nil} + {:type :end-test-var + :var #'test-report} + {:type :end-test-ns + :ns (if *ns* *ns* 'examples.data)}])) (def prepl-data (v/prepl - [{:val - "=> clojure -M:cljfmt check dev src test extension-intellij/src/main/clojure\n", - :tag :out} - {:val "-> 6.872 seconds \n\n", :tag :out} - {:val - "=> clojure -M:kondo --lint dev src test extension-intellij/src/main/clojure\n", - :tag :out} - {:val "-> 8.537 seconds \n\n", :tag :out} - {:val "=> clojure -M:cider:check\n", - :tag :out} - {:val "-> 3.77 seconds \n\n", :tag :out} - {:val - "=> ./gradlew --warning-mode all checkClojure\n", - :tag :out} - {:val "-> 1.477 seconds \n\n", :tag :out} - {:val - "=> clojure -Sdeps {:deps #:org.clojure{clojurescript #:mvn{:version \"1.10.773\"}}} -M:test -m cljs.main --output-dir target/cljs-output-1.10.773 --target node --output-to target/test.1.10.773.js --compile portal.test-runner\n", - :tag :out} - {:val "-> 5.470 seconds \n\n", :tag :out} - {:val "=> node target/test.1.10.773.js\n", - :tag :out} - {:val "-> 0.540 seconds \n\n", :tag :out} - {:val - "=> clojure -Sdeps {:deps #:org.clojure{clojurescript #:mvn{:version \"1.10.844\"}}} -M:test -m cljs.main --output-dir target/cljs-output-1.10.844 --target node --output-to target/test.1.10.844.js --compile portal.test-runner\n", - :tag :out} - {:val "-> 6.328 seconds \n\n", :tag :out} - {:val "=> node target/test.1.10.844.js\n", - :tag :out} - {:val "-> 0.307 seconds \n\n", :tag :out} - {:val - "=> planck -c src:test -m portal.test-planck\n", - :tag :out} - {:val "-> 2.39 seconds \n\n", :tag :out} - {:val - "=> clojure -M:cljs:shadow -m shadow.cljs.devtools.cli release client\n", - :tag :out} - {:val "-> 38.140 seconds \n\n", :tag :out} - {:val - "=> clojure -M:test -m portal.test-runner\n", - :tag :out} - {:val "-> 4.777 seconds \n\n", :tag :out} - {:val "=> bb -m portal.test-runner\n", - :tag :out} - {:val "-> 1.408 seconds \n\n", :tag :out}])) + [{:val + "=> clojure -M:cljfmt check dev src test extension-intellij/src/main/clojure\n" + :tag :out} + {:val "-> 6.872 seconds \n\n", :tag :out} + {:val + "=> clojure -M:kondo --lint dev src test extension-intellij/src/main/clojure\n" + :tag :out} + {:val "-> 8.537 seconds \n\n", :tag :out} + {:val "=> clojure -M:cider:check\n" + :tag :out} + {:val "-> 3.77 seconds \n\n", :tag :out} + {:val + "=> ./gradlew --warning-mode all checkClojure\n" + :tag :out} + {:val "-> 1.477 seconds \n\n", :tag :out} + {:val + "=> clojure -Sdeps {:deps #:org.clojure{clojurescript #:mvn{:version \"1.10.773\"}}} -M:test -m cljs.main --output-dir target/cljs-output-1.10.773 --target node --output-to target/test.1.10.773.js --compile portal.test-runner\n" + :tag :out} + {:val "-> 5.470 seconds \n\n", :tag :out} + {:val "=> node target/test.1.10.773.js\n" + :tag :out} + {:val "-> 0.540 seconds \n\n", :tag :out} + {:val + "=> clojure -Sdeps {:deps #:org.clojure{clojurescript #:mvn{:version \"1.10.844\"}}} -M:test -m cljs.main --output-dir target/cljs-output-1.10.844 --target node --output-to target/test.1.10.844.js --compile portal.test-runner\n" + :tag :out} + {:val "-> 6.328 seconds \n\n", :tag :out} + {:val "=> node target/test.1.10.844.js\n" + :tag :out} + {:val "-> 0.307 seconds \n\n", :tag :out} + {:val + "=> planck -c src:test -m portal.test-planck\n" + :tag :out} + {:val "-> 2.39 seconds \n\n", :tag :out} + {:val + "=> clojure -M:cljs:shadow -m shadow.cljs.devtools.cli release client\n" + :tag :out} + {:val "-> 38.140 seconds \n\n", :tag :out} + {:val + "=> clojure -M:test -m portal.test-runner\n" + :tag :out} + {:val "-> 4.777 seconds \n\n", :tag :out} + {:val "=> bb -m portal.test-runner\n" + :tag :out} + {:val "-> 1.408 seconds \n\n", :tag :out}])) (def exception-data (v/ex - '{:runtime :clj - :cause "My message", - :via - [{:type clojure.lang.ExceptionInfo, - :at [clojure.lang.AFn applyToHelper "AFn.java" 156], - :message "My message", - :data {:my :data}}], - :trace - [[clojure.lang.AFn applyToHelper "AFn.java" 156] - [clojure.lang.AFn applyTo "AFn.java" 144] - [clojure.lang.Compiler$InvokeExpr eval "Compiler.java" 3706] - [clojure.lang.Compiler$MapExpr eval "Compiler.java" 3058] - [clojure.lang.Compiler$DefExpr eval "Compiler.java" 457] - [clojure.lang.Compiler eval "Compiler.java" 7186] - [clojure.lang.Compiler load "Compiler.java" 7640] - [clojure.lang.RT loadResourceScript "RT.java" 381] - [clojure.lang.RT loadResourceScript "RT.java" 372] - [clojure.lang.RT load "RT.java" 459] - [clojure.lang.RT load "RT.java" 424] - [clojure.core$load$fn__6856 invoke "core.clj" 6115] - [clojure.core$load invokeStatic "core.clj" 6114] - [clojure.core$load doInvoke "core.clj" 6098] - [clojure.lang.RestFn invoke "RestFn.java" 408] - [clojure.core$load_one invokeStatic "core.clj" 5897] - [clojure.core$load_one invoke "core.clj" 5892] - [clojure.core$load_lib$fn__6796 invoke "core.clj" 5937] - [clojure.core$load_lib invokeStatic "core.clj" 5936] - [clojure.core$load_lib doInvoke "core.clj" 5917] - [clojure.lang.RestFn applyTo "RestFn.java" 142] - [clojure.core$apply invokeStatic "core.clj" 669] - [clojure.core$load_libs invokeStatic "core.clj" 5974] - [clojure.core$load_libs doInvoke "core.clj" 5958] - [clojure.lang.RestFn applyTo "RestFn.java" 137] - [clojure.core$apply invokeStatic "core.clj" 669] - [clojure.core$require invokeStatic "core.clj" 5996] - [clojure.core$require doInvoke "core.clj" 5996] - [clojure.lang.RestFn invoke "RestFn.java" 408] - [user$eval42500 invokeStatic "NO_SOURCE_FILE" 90] - [user$eval42500 invoke "NO_SOURCE_FILE" 90] - [clojure.lang.Compiler eval "Compiler.java" 7181] - [clojure.lang.Compiler eval "Compiler.java" 7136] - [clojure.core$eval invokeStatic "core.clj" 3202] - [clojure.core$eval invoke "core.clj" 3198] - [clojure.main$repl$read_eval_print__9110$fn__9113 - invoke - "main.clj" - 437] - [clojure.main$repl$read_eval_print__9110 invoke "main.clj" 437] - [clojure.main$repl$fn__9119 invoke "main.clj" 458] - [clojure.main$repl invokeStatic "main.clj" 458] - [clojure.main$repl doInvoke "main.clj" 368] - [clojure.lang.RestFn invoke "RestFn.java" 805] - [companion.jvm$evaluate_clj$fn__40139 invoke "NO_SOURCE_FILE" 115] - [clojure.core$with_redefs_fn invokeStatic "core.clj" 7516] - [clojure.core$with_redefs_fn invoke "core.clj" 7500] - [companion.jvm$evaluate_clj invokeStatic "NO_SOURCE_FILE" 112] - [companion.jvm$evaluate_clj invoke "NO_SOURCE_FILE" 102] - [companion.jvm$eval37720$fn__37721 invoke "jvm.clj" 248] - [clojure.lang.MultiFn invoke "MultiFn.java" 229] - [companion.jvm$evaluate invokeStatic "jvm.clj" 424] - [companion.jvm$evaluate invoke "jvm.clj" 422] - [user$eval42498 invokeStatic "NO_SOURCE_FILE" 1308] - [user$eval42498 invoke "NO_SOURCE_FILE" 1308] - [clojure.lang.Compiler eval "Compiler.java" 7181] - [clojure.lang.Compiler eval "Compiler.java" 7136] - [clojure.core$eval invokeStatic "core.clj" 3202] - [clojure.core$eval invoke "core.clj" 3198] - [shadow.cljs.devtools.server.socket_repl$repl$fn__17976 - invoke - "socket_repl.clj" - 61] - [clojure.main$repl$read_eval_print__9110$fn__9113 - invoke - "main.clj" - 437] - [clojure.main$repl$read_eval_print__9110 invoke "main.clj" 437] - [clojure.main$repl$fn__9119 invoke "main.clj" 458] - [clojure.main$repl invokeStatic "main.clj" 458] - [clojure.main$repl doInvoke "main.clj" 368] - [clojure.lang.RestFn invoke "RestFn.java" 805] - [shadow.cljs.devtools.server.socket_repl$repl - invokeStatic - "socket_repl.clj" - 28] - [shadow.cljs.devtools.server.socket_repl$repl - invoke - "socket_repl.clj" - 26] - [shadow.cljs.devtools.server.socket_repl$connection_loop - invokeStatic - "socket_repl.clj" - 102] - [shadow.cljs.devtools.server.socket_repl$connection_loop - invoke - "socket_repl.clj" - 72] - [shadow.cljs.devtools.server.socket_repl$start$fn__17995$fn__17996$fn__17998 - invoke - "socket_repl.clj" - 142] - [clojure.lang.AFn run "AFn.java" 22] - [java.lang.Thread run "Thread.java" 829]], - :data {:my :data}})) + '{:runtime :clj + :cause "My message" + :via + [{:type clojure.lang.ExceptionInfo + :at [clojure.lang.AFn applyToHelper "AFn.java" 156] + :message "My message" + :data {:my :data}}] + :trace + [[clojure.lang.AFn applyToHelper "AFn.java" 156] + [clojure.lang.AFn applyTo "AFn.java" 144] + [clojure.lang.Compiler$InvokeExpr eval "Compiler.java" 3706] + [clojure.lang.Compiler$MapExpr eval "Compiler.java" 3058] + [clojure.lang.Compiler$DefExpr eval "Compiler.java" 457] + [clojure.lang.Compiler eval "Compiler.java" 7186] + [clojure.lang.Compiler load "Compiler.java" 7640] + [clojure.lang.RT loadResourceScript "RT.java" 381] + [clojure.lang.RT loadResourceScript "RT.java" 372] + [clojure.lang.RT load "RT.java" 459] + [clojure.lang.RT load "RT.java" 424] + [clojure.core$load$fn__6856 invoke "core.clj" 6115] + [clojure.core$load invokeStatic "core.clj" 6114] + [clojure.core$load doInvoke "core.clj" 6098] + [clojure.lang.RestFn invoke "RestFn.java" 408] + [clojure.core$load_one invokeStatic "core.clj" 5897] + [clojure.core$load_one invoke "core.clj" 5892] + [clojure.core$load_lib$fn__6796 invoke "core.clj" 5937] + [clojure.core$load_lib invokeStatic "core.clj" 5936] + [clojure.core$load_lib doInvoke "core.clj" 5917] + [clojure.lang.RestFn applyTo "RestFn.java" 142] + [clojure.core$apply invokeStatic "core.clj" 669] + [clojure.core$load_libs invokeStatic "core.clj" 5974] + [clojure.core$load_libs doInvoke "core.clj" 5958] + [clojure.lang.RestFn applyTo "RestFn.java" 137] + [clojure.core$apply invokeStatic "core.clj" 669] + [clojure.core$require invokeStatic "core.clj" 5996] + [clojure.core$require doInvoke "core.clj" 5996] + [clojure.lang.RestFn invoke "RestFn.java" 408] + [user$eval42500 invokeStatic "NO_SOURCE_FILE" 90] + [user$eval42500 invoke "NO_SOURCE_FILE" 90] + [clojure.lang.Compiler eval "Compiler.java" 7181] + [clojure.lang.Compiler eval "Compiler.java" 7136] + [clojure.core$eval invokeStatic "core.clj" 3202] + [clojure.core$eval invoke "core.clj" 3198] + [clojure.main$repl$read_eval_print__9110$fn__9113 + invoke + "main.clj" + 437] + [clojure.main$repl$read_eval_print__9110 invoke "main.clj" 437] + [clojure.main$repl$fn__9119 invoke "main.clj" 458] + [clojure.main$repl invokeStatic "main.clj" 458] + [clojure.main$repl doInvoke "main.clj" 368] + [clojure.lang.RestFn invoke "RestFn.java" 805] + [companion.jvm$evaluate_clj$fn__40139 invoke "NO_SOURCE_FILE" 115] + [clojure.core$with_redefs_fn invokeStatic "core.clj" 7516] + [clojure.core$with_redefs_fn invoke "core.clj" 7500] + [companion.jvm$evaluate_clj invokeStatic "NO_SOURCE_FILE" 112] + [companion.jvm$evaluate_clj invoke "NO_SOURCE_FILE" 102] + [companion.jvm$eval37720$fn__37721 invoke "jvm.clj" 248] + [clojure.lang.MultiFn invoke "MultiFn.java" 229] + [companion.jvm$evaluate invokeStatic "jvm.clj" 424] + [companion.jvm$evaluate invoke "jvm.clj" 422] + [user$eval42498 invokeStatic "NO_SOURCE_FILE" 1308] + [user$eval42498 invoke "NO_SOURCE_FILE" 1308] + [clojure.lang.Compiler eval "Compiler.java" 7181] + [clojure.lang.Compiler eval "Compiler.java" 7136] + [clojure.core$eval invokeStatic "core.clj" 3202] + [clojure.core$eval invoke "core.clj" 3198] + [shadow.cljs.devtools.server.socket_repl$repl$fn__17976 + invoke + "socket_repl.clj" + 61] + [clojure.main$repl$read_eval_print__9110$fn__9113 + invoke + "main.clj" + 437] + [clojure.main$repl$read_eval_print__9110 invoke "main.clj" 437] + [clojure.main$repl$fn__9119 invoke "main.clj" 458] + [clojure.main$repl invokeStatic "main.clj" 458] + [clojure.main$repl doInvoke "main.clj" 368] + [clojure.lang.RestFn invoke "RestFn.java" 805] + [shadow.cljs.devtools.server.socket_repl$repl + invokeStatic + "socket_repl.clj" + 28] + [shadow.cljs.devtools.server.socket_repl$repl + invoke + "socket_repl.clj" + 26] + [shadow.cljs.devtools.server.socket_repl$connection_loop + invokeStatic + "socket_repl.clj" + 102] + [shadow.cljs.devtools.server.socket_repl$connection_loop + invoke + "socket_repl.clj" + 72] + [shadow.cljs.devtools.server.socket_repl$start$fn__17995$fn__17996$fn__17998 + invoke + "socket_repl.clj" + 142] + [clojure.lang.AFn run "AFn.java" 22] + [java.lang.Thread run "Thread.java" 829]] + :data {:my :data}})) (def http-requests (mapv - v/http - [{:request-method :get - :uri "https://djblue.github.io/portal/"} - {:request-method :post - :uri "https://djblue.github.io/portal/"} - {:request-method :put - :uri "https://djblue.github.io/portal/"} - {:request-method :patch - :uri "https://djblue.github.io/portal/"} - {:request-method :delete - :uri "https://djblue.github.io/portal/"} - {:request-method :options - :uri "https://djblue.github.io/portal/"}])) + v/http + [{:request-method :get + :uri "https://djblue.github.io/portal/"} + {:request-method :post + :uri "https://djblue.github.io/portal/"} + {:request-method :put + :uri "https://djblue.github.io/portal/"} + {:request-method :patch + :uri "https://djblue.github.io/portal/"} + {:request-method :delete + :uri "https://djblue.github.io/portal/"} + {:request-method :options + :uri "https://djblue.github.io/portal/"}])) (def http-responses (mapv - v/http - [{:status 100 - :headers {:content-type "text/html; charset=utf-8"} - :body "hi"} - {:status 200 - :headers {:content-type "text/html; charset=utf-8"} - :body "hi"} - {:status 300 - :headers {:content-type "text/html; charset=utf-8"} - :body "hi"} - {:status 400 - :headers {:content-type "text/html; charset=utf-8"} - :body "hi"} - {:status 500 - :headers {:content-type "text/html; charset=utf-8"} - :body "hi"}])) + v/http + [{:status 100 + :headers {:content-type "text/html; charset=utf-8"} + :body "hi"} + {:status 200 + :headers {:content-type "text/html; charset=utf-8"} + :body "hi"} + {:status 300 + :headers {:content-type "text/html; charset=utf-8"} + :body "hi"} + {:status 400 + :headers {:content-type "text/html; charset=utf-8"} + :body "hi"} + {:status 500 + :headers {:content-type "text/html; charset=utf-8"} + :body "hi"}])) (def data-visualization {::vega @@ -1099,47 +1107,47 @@ (def spec-data (v/default - '{:clojure.spec.alpha/problems - ({:path [:user/inst], - :pred clojure.core/inst?, - :val 1, - :via [:user/coll :user/map :user/inst], - :in [0 :user/inst]} - {:path [:user/hello], - :pred clojure.core/string?, - :val :user/world, - :via [:user/coll :user/map :user/hello], - :in [0 :user/hello]} - {:path [:user/test], - :pred clojure.core/true?, - :val nil, - :via [:user/coll :user/map :user/test], - :in [0 :user/test]}), - :clojure.spec.alpha/spec :user/coll, - :clojure.spec.alpha/value - [{:user/inst 1, :user/hello :user/world, :user/test nil, :user/set d}]} - :portal.viewer/spec)) + '{:clojure.spec.alpha/problems + ({:path [:user/inst] + :pred clojure.core/inst? + :val 1 + :via [:user/coll :user/map :user/inst] + :in [0 :user/inst]} + {:path [:user/hello] + :pred clojure.core/string? + :val :user/world + :via [:user/coll :user/map :user/hello] + :in [0 :user/hello]} + {:path [:user/test] + :pred clojure.core/true? + :val nil + :via [:user/coll :user/map :user/test] + :in [0 :user/test]}) + :clojure.spec.alpha/spec :user/coll + :clojure.spec.alpha/value + [{:user/inst 1, :user/hello :user/world, :user/test nil, :user/set d}]} + :portal.viewer/spec)) (def data (merge - {::platform-data platform-data - ::hacker-news #?(:org.babashka/nbb nil :default hn/stories) - ::spec-data spec-data - ::table-data table-data - ::diff diff-data - ::diff-text diff-text-data - ::basic-data basic-data - ::themes c/themes - ::clojure-data clojure-data - ::hiccup hiccup - ::data-visualization data-visualization - ::string-data string-data - ::log-data log-data - ::profile-data profile-data - ::test-data test-report - ::prepl-data prepl-data - ::exception-data exception-data - ::http-requests http-requests - ::http-responses http-responses} - (when platform-data - {::platform-collections platform-collections}))) + {::platform-data platform-data + ::hacker-news #?(:org.babashka/nbb nil :default hn/stories) + ::spec-data spec-data + ::table-data table-data + ::diff diff-data + ::diff-text diff-text-data + ::basic-data basic-data + ::themes c/themes + ::clojure-data clojure-data + ::hiccup hiccup + ::data-visualization data-visualization + ::string-data string-data + ::log-data log-data + ::profile-data profile-data + ::test-data test-report + ::prepl-data prepl-data + ::exception-data exception-data + ::http-requests http-requests + ::http-responses http-responses} + (when platform-data + {::platform-collections platform-collections}))) diff --git a/src/examples/default_visualizer.clj b/src/examples/default_visualizer.clj index c270ac8b..9ba8a67b 100644 --- a/src/examples/default_visualizer.clj +++ b/src/examples/default_visualizer.clj @@ -12,9 +12,9 @@ (comment (tap> - (with-meta - {:a 1 - :b 2 - :c 3} - {`nav #'nav-dep-anno-tree - :deps-map {:c #{:b :a}}}))) \ No newline at end of file + (with-meta + {:a 1 + :b 2 + :c 3} + {`nav #'nav-dep-anno-tree + :deps-map {:c #{:b :a}}}))) diff --git a/src/examples/fetch.cljs b/src/examples/fetch.cljs index 83ed8b98..110d541c 100644 --- a/src/examples/fetch.cljs +++ b/src/examples/fetch.cljs @@ -3,16 +3,16 @@ (defn- node-fetch [url] (let [http (js/require "https")] (js/Promise. - (fn [resolve reject] - (.end - (.request - http - url - (fn [res] - (let [body (atom "")] - (.on res "data" #(swap! body str %)) - (.on res "error" reject) - (.on res "end" #(resolve @body)))))))))) + (fn [resolve reject] + (.end + (.request + http + url + (fn [res] + (let [body (atom "")] + (.on res "data" #(swap! body str %)) + (.on res "error" reject) + (.on res "end" #(resolve @body)))))))))) (defn- web-fetch [url] (.then (js/fetch url) #(.text %))) diff --git a/src/examples/hacker_news.cljc b/src/examples/hacker_news.cljc index b8afbb0d..bf0a9589 100644 --- a/src/examples/hacker_news.cljc +++ b/src/examples/hacker_news.cljc @@ -1,11 +1,17 @@ (ns examples.hacker-news - (:require #?(:clj [portal.sync :as a] - :cljs [portal.async :as a] - :cljr [portal.sync :as a]) - #?(:cljs [examples.fetch :refer [fetch]]) - [clojure.core.protocols :refer [nav]] - #?(:clj [portal.runtime.json :as json] - :cljr [portal.runtime.json :as json]))) + (:require + [clojure.core.protocols :refer [nav]] + #?@(:clj + [[portal.runtime.json :as json] + [portal.sync :as a]] + + :cljr + [[portal.runtime.json :as json] + [portal.sync :as a]] + + :cljs + [[examples.fetch :refer [fetch]] + [portal.async :as a]]))) (def root "https://hacker-news.firebaseio.com/v0") @@ -49,8 +55,8 @@ #?(:clj (java.util.Date. timestamp) :cljs (js/Date. timestamp) :cljr (.DateTime - (System.DateTimeOffset/FromUnixTimeMilliseconds - timestamp)))) + (System.DateTimeOffset/FromUnixTimeMilliseconds + timestamp)))) (declare nav-hn) (declare nav-item) diff --git a/src/examples/macros.cljc b/src/examples/macros.cljc index 88909db7..7c69b78b 100644 --- a/src/examples/macros.cljc +++ b/src/examples/macros.cljc @@ -1,5 +1,8 @@ -(ns ^:no-doc examples.macros - #?(:portal (:import) :cljs (:require-macros examples.macros))) +(ns examples.macros + {:no-doc true} + #?(:cljs + (:require-macros + [examples.macros]))) #?(:clj (defmacro read-file [file-name] (slurp file-name)) :cljs (defn read-file [_file-name] ::missing) diff --git a/src/portal/api.cljc b/src/portal/api.cljc index 0a6b1dce..d8be5c04 100644 --- a/src/portal/api.cljc +++ b/src/portal/api.cljc @@ -1,17 +1,22 @@ (ns portal.api - (:require #?(:clj - [portal.runtime.jvm.commands]) - #?(:clj [portal.runtime.jvm.launcher :as l] - :cljs [portal.runtime.node.launcher :as l] - :cljr [portal.runtime.clr.launcher :as l]) - #?(:clj [portal.sync :as a] - :cljs [portal.async :as a] - :cljr [portal.sync :as a]) - #?(:clj [clojure.java.io :as io] - :cljs [portal.resources :as io]) - [clojure.set :as set] - [portal.runtime :as rt] - [portal.runtime.cson :as cson])) + (:require + [clojure.set :as set] + [portal.runtime :as rt] + [portal.runtime.cson :as cson] + #?@(:clj + [[clojure.java.io :as io] + [portal.runtime.jvm.commands] + [portal.runtime.jvm.launcher :as l] + [portal.sync :as a]] + + :cljr + [[portal.runtime.clr.launcher :as l] + [portal.sync :as a]] + + :cljs + [[portal.async :as a] + [portal.resources :as io] + [portal.runtime.node.launcher :as l]]))) (defn submit "Tap target function. @@ -97,8 +102,8 @@ ([portal options] (l/open portal (merge - (dissoc (:options rt/*session*) :value) - (rename options))))) + (dissoc (:options rt/*session*) :value) + (rename options))))) (defn close "Close all current inspector windows. @@ -206,17 +211,17 @@ (if *nrepl-init* (*nrepl-init* portal) (throw - (ex-info - "Please start nREPL with `portal.nrepl/wrap-repl` middleware to enable the portal subrepl." - {:portal-instance portal - :missing-middleware 'portal.nrepl/wrap-repl}))))) + (ex-info + "Please start nREPL with `portal.nrepl/wrap-repl` middleware to enable the portal subrepl." + {:portal-instance portal + :missing-middleware 'portal.nrepl/wrap-repl}))))) #?(:cljs (def ^:private docs-json (io/inline "portal/docs.json"))) (defn- get-docs [] (cson/read - #?(:clj (slurp (io/resource "portal/docs.json")) - :cljs docs-json))) + #?(:clj (slurp (io/resource "portal/docs.json")) + :cljs docs-json))) (defn docs "Open portal docs. diff --git a/src/portal/async.cljc b/src/portal/async.cljc index 0f12aa4d..4bdddbc1 100644 --- a/src/portal/async.cljc +++ b/src/portal/async.cljc @@ -1,14 +1,17 @@ -(ns ^:no-doc portal.async - (:refer-clojure :exclude [let try promise]) - #?(:portal (:import) :cljs (:require-macros portal.async))) +(ns portal.async + {:no-doc true} + (:refer-clojure :exclude [let promise try]) + #?(:cljs + (:require-macros + [portal.async]))) (defmacro do [& body] (reduce - (fn [chain form] - `(.then ~chain - (fn [] (.resolve js/Promise ~form)))) - `(.resolve js/Promise nil) - body)) + (fn [chain form] + `(.then ~chain + (fn [] (.resolve js/Promise ~form)))) + `(.resolve js/Promise nil) + body)) (defmacro let [bindings & body] (->> (partition-all 2 bindings) @@ -20,24 +23,24 @@ (defmacro try [& body] (reduce - (fn [chain form] - (cond - (and (coll? form) (= 'finally (first form))) - `(.finally ~chain - (fn [] - (portal.async/do ~@(rest form)))) + (fn [chain form] + (cond + (and (coll? form) (= 'finally (first form))) + `(.finally ~chain + (fn [] + (portal.async/do ~@(rest form)))) - (and (coll? form) (= 'catch (first form))) - (clojure.core/let [[_ _type ex-binding & body] form] - `(.catch ~chain - (fn [~ex-binding] - (portal.async/do ~@body)))) + (and (coll? form) (= 'catch (first form))) + (clojure.core/let [[_ _type ex-binding & body] form] + `(.catch ~chain + (fn [~ex-binding] + (portal.async/do ~@body)))) - :else - `(.then ~chain - (fn [] - (.resolve js/Promise ~form))))) - `(.resolve js/Promise nil) - body)) + :else + `(.then ~chain + (fn [] + (.resolve js/Promise ~form))))) + `(.resolve js/Promise nil) + body)) -#?(:cljs (defn race [& args] (.race js/Promise args))) \ No newline at end of file +#?(:cljs (defn race [& args] (.race js/Promise args))) diff --git a/src/portal/client/clr.clj b/src/portal/client/clr.clj index 9558dc38..ce35de43 100644 --- a/src/portal/client/clr.clj +++ b/src/portal/client/clr.clj @@ -1,12 +1,11 @@ -(ns ^:no-doc ^:no-check portal.client.clr - (:require [portal.runtime] - [portal.runtime.cson :as cson]) - (:import (System.Net.Http - HttpClient - HttpMethod - HttpRequestMessage - StringContent) - (System.Text Encoding))) +(ns :no-check + {:no-doc true} + (:require + [portal.runtime] + [portal.runtime.cson :as cson]) + (:import + (System.Net.Http HttpClient HttpMethod HttpRequestMessage StringContent) + (System.Text Encoding))) (defn- serialize [encoding value] (try @@ -28,13 +27,13 @@ port 53755}} value] (let [request (HttpRequestMessage. - HttpMethod/Post - (str "http://" host ":" port "/submit"))] + HttpMethod/Post + (str "http://" host ":" port "/submit"))] (set! (.-Content request) (StringContent. - (serialize encoding value) - Encoding/UTF8 - (case encoding - :edn "application/edn" - :cson "application/cson"))) + (serialize encoding value) + Encoding/UTF8 + (case encoding + :edn "application/edn" + :cson "application/cson"))) (.EnsureSuccessStatusCode (.Send ^HttpClient client request))))) diff --git a/src/portal/client/common.cljs b/src/portal/client/common.cljs index 452ea3f9..f8fa9904 100644 --- a/src/portal/client/common.cljs +++ b/src/portal/client/common.cljs @@ -1,18 +1,20 @@ -(ns ^:no-doc portal.client.common - (:require [portal.runtime] - [portal.runtime.cson :as cson] - [portal.runtime.json :as json] - [portal.runtime.transit :as transit])) +(ns portal.client.common + {:no-doc true} + (:require + [portal.runtime] + [portal.runtime.cson :as cson] + [portal.runtime.json :as json] + [portal.runtime.transit :as transit])) (defn- error->data [ex] (merge - (when-let [data (ex-data ex)] - {:data data}) - {:runtime :cljs - :cause (ex-message ex) - :via [{:type (symbol (.-name (type ex))) - :message (ex-message ex)}] - :stack (.-stack ex)})) + (when-let [data (ex-data ex)] + {:data data}) + {:runtime :cljs + :cause (ex-message ex) + :via [{:type (symbol (.-name (type ex))) + :message (ex-message ex)}] + :stack (.-stack ex)})) (defn- serialize [encoding value] (try @@ -34,13 +36,13 @@ port 53755}} value] (fetch - (str "http://" host ":" port "/submit") - {:method "POST" - :headers - {"content-type" - (case encoding - :json "application/json" - :cson "application/cson" - :transit "application/transit+json" - :edn "application/edn")} - :body (serialize encoding value)})))) + (str "http://" host ":" port "/submit") + {:method "POST" + :headers + {"content-type" + (case encoding + :json "application/json" + :cson "application/cson" + :transit "application/transit+json" + :edn "application/edn")} + :body (serialize encoding value)})))) diff --git a/src/portal/client/jvm.clj b/src/portal/client/jvm.clj index 515c7226..54b6014f 100644 --- a/src/portal/client/jvm.clj +++ b/src/portal/client/jvm.clj @@ -1,9 +1,10 @@ (ns portal.client.jvm - (:require [org.httpkit.client :as http] - [portal.runtime] - [portal.runtime.cson :as cson] - [portal.runtime.json :as json] - [portal.runtime.transit :as transit])) + (:require + [org.httpkit.client :as http] + [portal.runtime] + [portal.runtime.cson :as cson] + [portal.runtime.json :as json] + [portal.runtime.transit :as transit])) (defn- serialize [encoding value] (try @@ -41,15 +42,15 @@ port 53755}} value] @(http/post - (str "http://" host ":" port "/submit") - {:headers - {"content-type" - (case encoding - :json "application/json" - :cson "application/cson" - :transit "application/transit+json" - :edn "application/edn")} - :body (serialize encoding value)}))) + (str "http://" host ":" port "/submit") + {:headers + {"content-type" + (case encoding + :json "application/json" + :cson "application/cson" + :transit "application/transit+json" + :edn "application/edn")} + :body (serialize encoding value)}))) (comment (submit {:runtime :jvm :value "hello jvm"}) diff --git a/src/portal/client/node.cljs b/src/portal/client/node.cljs index d6c994c0..bf9e1966 100644 --- a/src/portal/client/node.cljs +++ b/src/portal/client/node.cljs @@ -1,26 +1,26 @@ (ns portal.client.node (:require [clojure.string :as str] - [portal.client.common :refer (->submit)])) + [portal.client.common :refer [->submit]])) (defn fetch [url options] (let [https? (str/starts-with? url "https") http (js/require (str "http" (when https? "s")))] (js/Promise. - (fn [resolve reject] - (let [req (.request - http - url - (clj->js options) - (fn [^js res] - (let [body (atom "")] - (.on res "data" #(swap! body str %)) - (.on res "error" reject) - (.on res "end" #(resolve - {:status (.-statusCode res) - :body @body})))))] - (.write req (:body options)) - (.end req)))))) + (fn [resolve reject] + (let [req (.request + http + url + (clj->js options) + (fn [^js res] + (let [body (atom "")] + (.on res "data" #(swap! body str %)) + (.on res "error" reject) + (.on res "end" #(resolve + {:status (.-statusCode res) + :body @body})))))] + (.write req (:body options)) + (.end req)))))) (def submit (->submit fetch)) diff --git a/src/portal/client/planck.cljs b/src/portal/client/planck.cljs index e0a86b58..2e354c9a 100644 --- a/src/portal/client/planck.cljs +++ b/src/portal/client/planck.cljs @@ -1,6 +1,7 @@ (ns portal.client.planck - (:require [planck.http :as http] - [portal.client.common :refer (->submit)])) + (:require + [planck.http :as http] + [portal.client.common :refer [->submit]])) (def ^:private http-methods {"GET" http/get diff --git a/src/portal/client/web.cljs b/src/portal/client/web.cljs index 96dbbf88..ec7c5d48 100644 --- a/src/portal/client/web.cljs +++ b/src/portal/client/web.cljs @@ -1,6 +1,6 @@ (ns portal.client.web (:require - [portal.client.common :refer (->submit)])) + [portal.client.common :refer [->submit]])) (defn- fetch [url options] (js/fetch url (clj->js options))) diff --git a/src/portal/console.cljc b/src/portal/console.cljc index 9ad6a15c..0cc5f363 100644 --- a/src/portal/console.cljc +++ b/src/portal/console.cljc @@ -1,8 +1,10 @@ (ns portal.console - #?(:joyride (:import) - :clj (:require [clojure.java.io :as io]) - :portal (:import) - :cljs (:require-macros portal.console))) + #?(:cljs + (:require-macros + [portal.console])) + #?(:clj + (:require + [clojure.java.io :as io]))) (defn ^:no-doc now [] #?(:clj (java.util.Date.) :cljs (js/Date.) :cljr (DateTime/Now))) @@ -35,25 +37,25 @@ (let [{:keys [line column file]} (meta form)] `(let [[flow# result#] (run (fn [] ~expr))] (tap> - (with-meta - {:form (quote ~expr) - :level (if (= flow# :throw) :fatal ~level) - :result result# - :ns (quote ~(symbol (str *ns*))) - :file ~#?(:clj (get-file env file) - :portal *file* - :joyride '*file* - :org.babashka/nbb *file* - :cljs file - :cljr *file*) - :line ~line - :column ~column - :time (now) - :runtime (runtime)} - {:portal.viewer/default :portal.viewer/log - :portal.viewer/for - {:form :portal.viewer/pprint - :time :portal.viewer/relative-time}})) + (with-meta + {:form (quote ~expr) + :level (if (= flow# :throw) :fatal ~level) + :result result# + :ns (quote ~(symbol (str *ns*))) + :file ~#?(:clj (get-file env file) + :portal *file* + :joyride '*file* + :org.babashka/nbb *file* + :cljs file + :cljr *file*) + :line ~line + :column ~column + :time (now) + :runtime (runtime)} + {:portal.viewer/default :portal.viewer/log + :portal.viewer/for + {:form :portal.viewer/pprint + :time :portal.viewer/relative-time}})) (if (= flow# :throw) (throw result#) result#)))) (defmacro log [expr] (capture :info &form expr &env)) diff --git a/src/portal/extensions/electron.cljs b/src/portal/extensions/electron.cljs index 5fed5f66..304229b1 100644 --- a/src/portal/extensions/electron.cljs +++ b/src/portal/extensions/electron.cljs @@ -1,25 +1,26 @@ (ns portal.extensions.electron - (:require ["electron" :refer [BrowserWindow app]] - [clojure.edn :as edn] - [portal.api :as p] - [portal.async :as a] - [portal.runtime.fs :as fs] - [portal.runtime.node.server :as server])) + (:require + ["electron" :refer [BrowserWindow app]] + [clojure.edn :as edn] + [portal.api :as p] + [portal.async :as a] + [portal.runtime.fs :as fs] + [portal.runtime.node.server :as server])) (defonce ^:private window (atom nil)) (defn- create-window [] (BrowserWindow. - #js {:title "portal" - :width 1200 - :height 600 - ;; :titleBarStyle "hiddenInset" - :transparent true - :alwaysOnTop true - :frame false - :opacity 0.75 - :webPreferences #js {:zoomFactor 1.5} - :show false})) + #js {:title "portal" + :width 1200 + :height 600 + ;; :titleBarStyle "hiddenInset" + :transparent true + :alwaysOnTop true + :frame false + :opacity 0.75 + :webPreferences #js {:zoomFactor 1.5} + :show false})) (def ^:private close-timeout (* 60 60 1000)) @@ -37,10 +38,10 @@ (.preventDefault e) (.hide window) (let [timeout (js/setTimeout - (fn [] - (js/console.log "destroying") - (.destroy window)) - close-timeout)] + (fn [] + (js/console.log "destroying") + (.destroy window)) + close-timeout)] (.once window "show" (fn [] (js/console.log "prevent destroy") diff --git a/src/portal/extensions/pwa.cljs b/src/portal/extensions/pwa.cljs index 50e65a68..c0ef99fa 100644 --- a/src/portal/extensions/pwa.cljs +++ b/src/portal/extensions/pwa.cljs @@ -1,25 +1,26 @@ (ns portal.extensions.pwa - (:require [clojure.string :as str] - [examples.data :as demo] - [portal.async :as a] - [portal.colors :as c] - [portal.extensions.vs-code-notebook :as notebook] - [portal.resources :as io] - [portal.runtime :as rt] - [portal.runtime.edn :as edn] - [portal.runtime.json :as json] - [portal.runtime.transit :as transit] - [portal.shortcuts :as shortcuts] - [portal.ui.api :as api] - [portal.ui.app :as app] - [portal.ui.commands :as commands] - [portal.ui.drag-and-drop :as dnd] - [portal.ui.inspector :as ins] - [portal.ui.state :as state] - [portal.ui.styled :refer [div]] - [portal.ui.theme :as theme] - [reagent.core :as r] - [reagent.dom :as dom])) + (:require + [clojure.string :as str] + [examples.data :as demo] + [portal.async :as a] + [portal.colors :as c] + [portal.extensions.vs-code-notebook :as notebook] + [portal.resources :as io] + [portal.runtime :as rt] + [portal.runtime.edn :as edn] + [portal.runtime.json :as json] + [portal.runtime.transit :as transit] + [portal.shortcuts :as shortcuts] + [portal.ui.api :as api] + [portal.ui.app :as app] + [portal.ui.commands :as commands] + [portal.ui.drag-and-drop :as dnd] + [portal.ui.inspector :as ins] + [portal.ui.state :as state] + [portal.ui.styled :refer [div]] + [portal.ui.theme :as theme] + [reagent.core :as r] + [reagent.dom :as dom])) (defn open-demo "Load demo data" @@ -39,8 +40,8 @@ (defn send! [msg] (when-let [f (get rt/ops (:op msg))] (js/Promise. - (fn [resolve] - (f msg resolve))))) + (fn [resolve] + (f msg resolve))))) (defn launch-queue-consumer [item] (a/let [files (js/Promise.all (map #(.getFile %) (.-files item))) @@ -61,10 +62,10 @@ (let [theme (theme/use-theme) state (state/use-state) mapping (reduce-kv - (fn [mapping k v] - (assoc mapping v (get theme k))) - {} - (::c/nord c/themes)) + (fn [mapping k v] + (assoc mapping v (get theme k))) + {} + (::c/nord c/themes)) svg (str/replace (io/inline "splash.svg") hex-color mapping)] [:<> [commands/palette] @@ -129,11 +130,11 @@ (defn ->map [entries] (persistent! - (reduce - (fn [m entry] - (assoc! m (keyword (aget entry 0)) (aget entry 1))) - (transient {}) - entries))) + (reduce + (fn [m entry] + (assoc! m (keyword (aget entry 0)) (aget entry 1))) + (transient {}) + entries))) (defn- qs->map [qs] (->map (.entries (js/URLSearchParams. qs)))) @@ -162,14 +163,14 @@ (defn- parse-data [params response] (let [{:keys [status body]} response content-type (some-> - (or (:content-type params) - (get-in response [:headers :content-type])) - (str/split #";") - first) + (or (:content-type params) + (get-in response [:headers :content-type])) + (str/split #";") + first) metadata {:query-params params :http-response response}] (if-not (= status 200) (ins/error->data - (ex-info (str "Error fetching data: " status) metadata)) + (ex-info (str "Error fetching data: " status) metadata)) (try (with-meta* (case content-type @@ -178,11 +179,11 @@ "application/edn" (edn/read-string body) "text/plain" body (ins/error->data - (ex-info (str "Unsupported :content-type " content-type) metadata))) + (ex-info (str "Unsupported :content-type " content-type) metadata))) metadata) (catch :default e (ins/error->data - (ex-info (str "Error parsing :content-type " content-type) metadata e))))))) + (ex-info (str "Error parsing :content-type " content-type) metadata e))))))) (defn ->response [^js response] (a/let [body (.text response)] @@ -203,7 +204,7 @@ (js/navigator.serviceWorker.register "sw.js")) (when js/window.launchQueue (js/window.launchQueue.setConsumer - #(launch-queue-consumer %))) + #(launch-queue-consumer %))) (reset! state/sender send!) (render-app)) @@ -219,4 +220,4 @@ (when (= mode :app) (render-app)))) -(set! (.-embed api/portal-api) notebook/activate) \ No newline at end of file +(set! (.-embed api/portal-api) notebook/activate) diff --git a/src/portal/extensions/vs_code.cljs b/src/portal/extensions/vs_code.cljs index 91d27512..a620053d 100644 --- a/src/portal/extensions/vs_code.cljs +++ b/src/portal/extensions/vs_code.cljs @@ -1,14 +1,15 @@ (ns portal.extensions.vs-code - (:require ["vscode" :as vscode :refer [notebooks]] - [clojure.edn :as edn] - [clojure.string :as str] - [portal.api :as p] - [portal.async :as a] - [portal.resources :as io] - [portal.runtime.browser :as browser] - [portal.runtime.fs :as fs] - [portal.runtime.index :as index] - [portal.runtime.node.server :as server])) + (:require + ["vscode" :as vscode :refer [notebooks]] + [clojure.edn :as edn] + [clojure.string :as str] + [portal.api :as p] + [portal.async :as a] + [portal.resources :as io] + [portal.runtime.browser :as browser] + [portal.runtime.fs :as fs] + [portal.runtime.index :as index] + [portal.runtime.node.server :as server])) (defonce ^:private !app-db (atom {:context nil :disposables []})) @@ -40,20 +41,20 @@ (let [{:keys [host port]} server session-id (:session-id portal) ^js panel (.createWebviewPanel - vscode/window - "portal" - (str/join - " - " - ["portal" - (get options :window-title "vs-code") - "0.58.3"]) - (view-column) - (clj->js - {:enableScripts true - :retainContextWhenHidden true - :portMapping - [{:webviewPort port - :extensionHostPort port}]})) + vscode/window + "portal" + (str/join + " - " + ["portal" + (get options :window-title "vs-code") + "0.58.3"]) + (view-column) + (clj->js + {:enableScripts true + :retainContextWhenHidden true + :portMapping + [{:webviewPort port + :extensionHostPort port}]})) ^js web-view (.-webview panel)] (set! (.-iconPath panel) (.file vscode/Uri (.asAbsolutePath ^js (:context @!app-db) "icon.png"))) @@ -63,19 +64,19 @@ :port port :session-id (str session-id)})) (.onDidReceiveMessage - web-view - (fn handle-message [^js message] - (when-let [^js event (and (string? message) (js/JSON.parse message))] - (case (.-type event) - "close" (.dispose panel) - "set-title" (set! (.-title panel) (.-title event)) - "set-theme" :unsupported))) - js/undefined - (.-subscriptions ^js (:context @!app-db))) + web-view + (fn handle-message [^js message] + (when-let [^js event (and (string? message) (js/JSON.parse message))] + (case (.-type event) + "close" (.dispose panel) + "set-title" (set! (.-title panel) (.-title event)) + "set-theme" :unsupported))) + js/undefined + (.-subscriptions ^js (:context @!app-db))) (.onDidChangeViewState - panel - (fn [_event] - (save-view-column (.-viewColumn panel)))))) + panel + (fn [_event] + (save-view-column (.-viewColumn panel)))))) (defmethod browser/-open :vs-code [args] (-open args)) @@ -92,25 +93,25 @@ (fn [] (let [path (fs/exists (fs/join (get-workspace-folder) "resources/portal-dev/main.js"))] (p/open - {:mode :dev - :window-title "vs-code-dev" - :resource {"main.js" path} - :launcher :vs-code})))}) + {:mode :dev + :window-title "vs-code-dev" + :resource {"main.js" path} + :launcher :vs-code})))}) (defn- setup-notebook-handler [] (let [message-channel (.createRendererMessaging notebooks "portal-edn-renderer")] (.onDidReceiveMessage - message-channel - (fn handle-message [^js event] - (let [message (.-message event)] - (case (.-type message) - "open-editor" - (p/open - {:launcher :vs-code - :window-title "notebook" - :value (edn/read-string - {:default tagged-literal} - (.-data message))}))))))) + message-channel + (fn handle-message [^js event] + (let [message (.-message event)] + (case (.-type message) + "open-editor" + (p/open + {:launcher :vs-code + :window-title "notebook" + :value (edn/read-string + {:default tagged-literal} + (.-data message))}))))))) (defmethod server/route [:post "/open"] [req ^js res] (a/let [body (server/get-body req)] @@ -119,8 +120,8 @@ (defn- open-file* [{:keys [file line column]}] (a/let [document (.openTextDocument - vscode/workspace - (.parse vscode/Uri file)) + vscode/workspace + (.parse vscode/Uri file)) ^js editor (.showTextDocument vscode/window document 1 false) ^js position (vscode/Position. (dec line) (dec column)) ^js range (vscode/Range. position position)] @@ -173,29 +174,29 @@ (defn- get-extension ^js/Promise [extension-name] (js/Promise. - (fn [resolve reject] - (let [n (atom 16) delay 250] - (js/setTimeout - (fn work [] - (try - (resolve (.-exports (.getExtension vscode/extensions extension-name))) - (catch :default e - (if (zero? (swap! n dec)) - (reject (ex-info "Max attempts reached" {} e)) - (js/setTimeout work delay))))) - delay))))) + (fn [resolve reject] + (let [n (atom 16) delay 250] + (js/setTimeout + (fn work [] + (try + (resolve (.-exports (.getExtension vscode/extensions extension-name))) + (catch :default e + (if (zero? (swap! n dec)) + (reject (ex-info "Max attempts reached" {} e)) + (js/setTimeout work delay))))) + delay))))) (defn- setup-joyride! [] (a/try (a/let [^js joyride (get-extension "betterthantomorrow.joyride")] (reduce - (fn [^js/Promise chain source] - (-> chain - (.then - (fn [_] - (.runCode joyride source))))) - (.resolve js/Promise 0) - portal-source)) + (fn [^js/Promise chain source] + (-> chain + (.then + (fn [_] + (.runCode joyride source))))) + (.resolve js/Promise 0) + portal-source)) (catch :default e (.error js/console e))) (clj->js {:resources {:inline io/inline}})) diff --git a/src/portal/extensions/vs_code_notebook.cljs b/src/portal/extensions/vs_code_notebook.cljs index 024efc4b..c691a218 100644 --- a/src/portal/extensions/vs_code_notebook.cljs +++ b/src/portal/extensions/vs_code_notebook.cljs @@ -1,17 +1,18 @@ (ns portal.extensions.vs-code-notebook - (:require [clojure.string :as str] - [portal.async :as a] - [portal.runtime :as rt] - [portal.runtime.edn :as edn] - [portal.ui.cljs :as cljs] - [portal.ui.embed :as embed] - [portal.ui.inspector :as ins] - [portal.ui.load :as load] - [portal.ui.options :as opts] - [portal.ui.rpc :as rpc] - [portal.ui.state :as state] - [reagent.core :as r] - [reagent.dom :as dom])) + (:require + [clojure.string :as str] + [portal.async :as a] + [portal.runtime :as rt] + [portal.runtime.edn :as edn] + [portal.ui.cljs :as cljs] + [portal.ui.embed :as embed] + [portal.ui.inspector :as ins] + [portal.ui.load :as load] + [portal.ui.options :as opts] + [portal.ui.rpc :as rpc] + [portal.ui.state :as state] + [reagent.core :as r] + [reagent.dom :as dom])) (defonce context (atom nil)) (defonce component (r/atom embed/app)) @@ -23,10 +24,10 @@ (inspect value)) ([value _] (.postMessage - ^js @context - #js {:type "open-editor" - :data (binding [*print-meta* true] - (pr-str value))}))) + ^js @context + #js {:type "open-editor" + :data (binding [*print-meta* true] + (pr-str value))}))) (rt/register! #'inspect {:name `portal.api/inspect}) @@ -43,8 +44,8 @@ (defn send! [msg] (when-let [f (get rt/ops (:op msg))] (js/Promise. - (fn [resolve] - (f msg resolve))))) + (fn [resolve] + (f msg resolve))))) (defonce ^:private session (random-uuid)) @@ -55,8 +56,8 @@ (if (str/starts-with? message "\"^{") (edn/read-string message) (throw (ex-info - message - (js->clj data :keywordize-keys true))))) + message + (js->clj data :keywordize-keys true))))) "x-application/edn" (.text data))) diff --git a/src/portal/main.clj b/src/portal/main.clj index e216610b..1737fb70 100644 --- a/src/portal/main.clj +++ b/src/portal/main.clj @@ -1,8 +1,10 @@ (ns portal.main - (:require [clojure.edn :as edn] - [clojure.java.io :as io] - [portal.api :as p]) - (:import [java.io PushbackReader])) + (:require + [clojure.edn :as edn] + [clojure.java.io :as io] + [portal.api :as p]) + (:import + (java.io PushbackReader))) (defn- lazy-fn [symbol] (fn [& args] (apply (requiring-resolve symbol) args))) @@ -27,7 +29,7 @@ "transit" (-> System/in read-transit))] (reset! (p/open) in) (.addShutdownHook - (Runtime/getRuntime) - (Thread. #(p/close))) + (Runtime/getRuntime) + (Thread. #(p/close))) (println "Press CTRL+C to exit") @(promise))) diff --git a/src/portal/main.cljs b/src/portal/main.cljs index 33f45e38..613dcade 100644 --- a/src/portal/main.cljs +++ b/src/portal/main.cljs @@ -1,4 +1,3 @@ (ns portal.main) (defn -main []) - diff --git a/src/portal/nrepl.clj b/src/portal/nrepl.clj index 3cdf6dee..7269bd1c 100644 --- a/src/portal/nrepl.clj +++ b/src/portal/nrepl.clj @@ -1,15 +1,17 @@ (ns portal.nrepl - (:require [clojure.datafy :as d] - [clojure.main :as main] - [clojure.test :as test] - [nrepl.middleware :refer [set-descriptor!]] - [nrepl.middleware.caught :as caught] - [nrepl.middleware.print :as print] - [nrepl.misc :refer (response-for)] - [nrepl.transport :as transport] - [portal.api :as p]) - (:import [java.util Date] - [nrepl.transport Transport])) + (:require + [clojure.datafy :as d] + [clojure.main :as main] + [clojure.test :as test] + [nrepl.middleware :refer [set-descriptor!]] + [nrepl.middleware.caught :as caught] + [nrepl.middleware.print :as print] + [nrepl.misc :refer [response-for]] + [nrepl.transport :as transport] + [portal.api :as p]) + (:import + (java.util Date) + (nrepl.transport Transport))) ; fork of https://github.com/DaveWM/nrepl-rebl/blob/master/src/nrepl_rebl/core.clj @@ -51,10 +53,10 @@ [msg] (try (some? - (get - @(:session msg) - (requiring-resolve - 'shadow.cljs.devtools.server.nrepl-impl/*repl-state*))) + (get + @(:session msg) + (requiring-resolve + 'shadow.cljs.devtools.server.nrepl-impl/*repl-state*))) (catch Exception _ false))) (defrecord ^:no-doc PortalTransport [transport handler-msg] @@ -71,14 +73,14 @@ (when-let [result (get-result msg)] (-> result (merge - (select-keys handler-msg [:ns :file :column :line :code]) - (when (= "load-file" (:op handler-msg)) - {:code (:file handler-msg) - :file (:file-path handler-msg)}) - (when-let [report (-> handler-msg :report deref not-empty)] - {:report report}) - (when-let [stdio (-> handler-msg :stdio deref not-empty)] - {:stdio stdio})) + (select-keys handler-msg [:ns :file :column :line :code]) + (when (= "load-file" (:op handler-msg)) + {:code (:file handler-msg) + :file (:file-path handler-msg)}) + (when-let [report (-> handler-msg :report deref not-empty)] + {:report report}) + (when-let [stdio (-> handler-msg :stdio deref not-empty)] + {:stdio stdio})) (update :ns (fnil symbol 'user)) (assoc :time (:time handler-msg) :ms (quot (- (System/nanoTime) (:start handler-msg)) 1000000) @@ -102,20 +104,20 @@ (swap! report conj value) (test-report value))] (handler - (cond-> msg - (#{"eval" "load-file"} (:op msg)) - (-> (update :transport - ->PortalTransport - (assoc msg - :report report - :stdio (atom []) - :start (System/nanoTime) - :time (Date.))) - (update :session - (fn [session] - (swap! session assoc - #'test/report portal-report) - session))))))) + (cond-> msg + (#{"eval" "load-file"} (:op msg)) + (-> (update :transport + ->PortalTransport + (assoc msg + :report report + :stdio (atom []) + :start (System/nanoTime) + :time (Date.))) + (update :session + (fn [session] + (swap! session assoc + #'test/report portal-report) + session))))))) (defn wrap-portal "nREPL middleware for inspecting `eval` and `load-file` ops for the following to `tap>`: @@ -172,23 +174,23 @@ [(:code msg) (:file msg)]) {:keys [value] :as response} (p/eval-str - portal - code - (-> {:ns (get @session #'*portal-ns*)} - (merge msg) - (select-keys [:ns :line :column]) - (assoc :file file - :verbose true - :context (case op "eval" :expr "load-file" :statement) - :re-render (= op "load-file"))))] + portal + code + (-> {:ns (get @session #'*portal-ns*)} + (merge msg) + (select-keys [:ns :line :column]) + (assoc :file file + :verbose true + :context (case op "eval" :expr "load-file" :statement) + :re-render (= op "load-file"))))] (when-let [namespace (:ns response)] (swap! session assoc #'*portal-ns* namespace)) (when (= value :cljs/quit) (swap! session dissoc #'*portal-session* #'*portal-ns*)) (merge - response - {:status :done - ::print/keys #{:value}})) + response + {:status :done + ::print/keys #{:value}})) (catch Exception e (swap! session assoc #'*e e) {::caught/throwable e @@ -238,10 +240,10 @@ (defn- ->id [value] (let [id (next-id)] (swap! - values - #(cond-> % - (> (count %) 32) (dissoc (ffirst %)) - :always (assoc id value))) + values + #(cond-> % + (> (count %) 32) (dissoc (ffirst %)) + :always (assoc id value))) id)) (defn- link-value [value] @@ -257,8 +259,8 @@ (assoc :ex (binding [*print-meta* true] (pr-str - (link-value - (d/datafy (::caught/throwable message)))))) + (link-value + (d/datafy (::caught/throwable message)))))) (contains? message :value) (update :value link-value))) @@ -273,10 +275,10 @@ (defn- wrap-notebook* [handler {:keys [op] :as message}] (handler - (cond-> message - (and (= op "eval") - (get-in message [:nrepl.middleware.eval/env :calva-notebook])) - (update :transport ->NotebookTransport)))) + (cond-> message + (and (= op "eval") + (get-in message [:nrepl.middleware.eval/env :calva-notebook])) + (update :transport ->NotebookTransport)))) (defn wrap-notebook "nREPL middleware for use with [Calva Notebooks](https://calva.io/notebooks/) @@ -296,4 +298,4 @@ "All of portal's nREPL middleware." [`wrap-notebook `wrap-repl - `wrap-portal]) \ No newline at end of file + `wrap-portal]) diff --git a/src/portal/resources.cljc b/src/portal/resources.cljc index d9ec0a4b..6941792d 100644 --- a/src/portal/resources.cljc +++ b/src/portal/resources.cljc @@ -1,19 +1,28 @@ -(ns ^:no-doc portal.resources - #?(:cljs (:require-macros portal.resources)) - #?(:clj (:require [clojure.java.io :as io])) - #?(:org.babashka/nbb (:require ["fs" :as fs] - ["path" :as path]) - :joyride (:require ["vscode" :as vscode] - ["ext://djblue.portal$resources" :as resources]))) +(ns portal.resources + {:no-doc true} + #?(:cljs + (:require-macros + [portal.resources])) + (:require + #?@(:clj + [[clojure.java.io :as io]] + + :joyride + [["ext://djblue.portal$resources" :as resources] + ["vscode" :as vscode]] + + :org.babashka/nbb + [["fs" :as fs] + ["path" :as path]]))) #?(:org.babashka/nbb (def file *file*)) (defn resource [_resource-name] #?(:org.babashka/nbb (some - (fn [file] - (when (fs/existsSync file) file)) - [(path/join file "../../" _resource-name) - (path/join file "../../../resources" _resource-name)]) + (fn [file] + (when (fs/existsSync file) file)) + [(path/join file "../../" _resource-name) + (path/join file "../../../resources" _resource-name)]) :joyride (let [vscode (js/require "vscode") path (js/require "path") @@ -40,4 +49,4 @@ :joyride (defn inline [resourece-name] (resources/inline resourece-name)) :org.babashka/nbb (defn inline [resource-name] (fs/readFileSync (resource resource-name) "utf8")) - :cljs (defn inline [resourece-name] (get @resources resourece-name))) \ No newline at end of file + :cljs (defn inline [resourece-name] (get @resources resourece-name))) diff --git a/src/portal/runtime.cljc b/src/portal/runtime.cljc index 2562e33c..09cf791b 100644 --- a/src/portal/runtime.cljc +++ b/src/portal/runtime.cljc @@ -1,15 +1,28 @@ -(ns ^:no-doc portal.runtime +(ns portal.runtime + {:no-doc true} (:refer-clojure :exclude [read]) - (:require #?(:clj [portal.sync :as a] - :cljr [portal.sync :as a] - :cljs [portal.async :as a]) - #?(:joyride [portal.runtime.datafy :refer [datafy nav]] - :org.babashka/nbb [portal.runtime.datafy :refer [datafy nav]] - :default [clojure.datafy :refer [datafy nav]]) - #?(:joyride [cljs.pprint :as pprint] - :default [clojure.pprint :as pprint]) - [portal.runtime.cson :as cson] - [portal.viewer :as v])) + (:require + [portal.runtime.cson :as cson] + [portal.viewer :as v] + #?@(:clj + [[portal.sync :as a]] + + :cljr + [[portal.sync :as a]] + + :cljs + [[portal.async :as a]] + + :joyride + [[cljs.pprint :as pprint] + [portal.runtime.datafy :refer [datafy nav]]] + + :org.babashka/nbb + [[portal.runtime.datafy :refer [datafy nav]]] + + :default + [[clojure.datafy :refer [datafy nav]] + [clojure.pprint :as pprint]]))) (def ^:private tagged-type (type (cson/->Tagged "tag" []))) @@ -48,11 +61,11 @@ (defn open-session [{:keys [session-id] :as session}] (merge - (get-session session-id) - {:id (atom 0) - :value-cache (atom {}) - :watch-registry (atom #{})} - session)) + (get-session session-id) + {:id (atom 0) + :value-cache (atom {}) + :watch-registry (atom #{})} + session)) (defn close-session [session-id] (swap! sessions dissoc session-id)) @@ -81,9 +94,9 @@ (defn- can-meta? [value] #?(:clj (and - (not (instance? clojure.lang.Range value)) - (or (instance? clojure.lang.IObj value) - (var? value))) + (not (instance? clojure.lang.Range value)) + (or (instance? clojure.lang.IObj value) + (var? value))) :cljr (or (instance? clojure.lang.IObj value) (var? value)) :joyride @@ -102,22 +115,22 @@ (cond (map? x) (reduce-kv - (fn [out k v] - (+ out (hash+ k) (hash+ v))) - (+ 1 (if (sorted? x) 1 0) (hash+ (meta x))) - x) + (fn [out k v] + (+ out (hash+ k) (hash+ v))) + (+ 1 (if (sorted? x) 1 0) (hash+ (meta x))) + x) (coll? x) (reduce - (fn [out v] - (+ out (hash+ v))) - (+ (cond - (list? x) 3 - (set? x) (if (sorted? x) 4 5) - (vector? x) 6 - :else 7) - (hash+ (meta x))) - x) + (fn [out v] + (+ out (hash+ v))) + (+ (cond + (list? x) 3 + (set? x) (if (sorted? x) 4 5) + (vector? x) 6 + :else 7) + (hash+ (meta x))) + x) :else (cond-> (+ (hash x) (hash (type x))) @@ -147,20 +160,20 @@ (defn- invalidate [session-id a old new] (when-not (= (value->key old) (value->key new)) (set-timeout - #(when (= @a new) (notify session-id a)) - 100))) + #(when (= @a new) (notify session-id a)) + 100))) (defn- watch-atom [a] (let [{:keys [session-id watch-registry]} *session*] (when-not (contains? @watch-registry a) (swap! - watch-registry - (fn [atoms] - (if (contains? atoms a) - atoms - (do - (add-watch a session-id #'invalidate) - (conj atoms a)))))))) + watch-registry + (fn [atoms] + (if (contains? atoms a) + atoms + (do + (add-watch a session-id #'invalidate) + (conj atoms a)))))))) (defn- toggle-watch "Toggle watching an atom for a given Portal session." @@ -168,30 +181,30 @@ [a] (let [{:keys [session-id watch-registry]} *session*] (when - (contains? - (swap! - watch-registry - (fn [atoms] - (if (contains? atoms a) - (do - (remove-watch a session-id) - (disj atoms a)) - (do - (add-watch a session-id #'invalidate) - (conj atoms a))))) a) + (contains? + (swap! + watch-registry + (fn [atoms] + (if (contains? atoms a) + (do + (remove-watch a session-id) + (disj atoms a)) + (do + (add-watch a session-id #'invalidate) + (conj atoms a))))) a) (set-timeout #(notify session-id a) 0)))) (defn- value->id [value] (let [k (value->key value) out (atom nil)] (swap! - (:value-cache *session*) - (fn [cache] - (if-let [id (and k (get cache k))] - (do (reset! out id) cache) - (let [id (next-id *session*)] - (reset! out id) - (cond-> (assoc cache [:id id] value) k (assoc k id)))))) + (:value-cache *session*) + (fn [cache] + (if-let [id (and k (get cache k))] + (do (reset! out id) cache) + (let [id (next-id *session*)] + (reset! out id) + (cond-> (assoc cache [:id id] value) k (assoc k id)))))) @out)) (defn- value->id? [value] @@ -213,23 +226,23 @@ (defn- to-object [buffer value tag rep] (if-not *session* (cson/-to-json - (with-meta - (cson/tagged-value "remote" (pr-str value)) - (meta value)) - buffer) + (with-meta + (cson/tagged-value "remote" (pr-str value)) + (meta value)) + buffer) (let [m (meta value)] (when (atom? value) (watch-atom value)) (cson/tag - buffer - "object" - (cond-> {:tag tag - :id (value->id value) - :type (pr-str (type value)) - :pr-str (pr-str' value) - :protocols (cond-> #{} - (deref? value) (conj :IDeref))} - m (assoc :meta m) - rep (assoc :rep rep)))))) + buffer + "object" + (cond-> {:tag tag + :id (value->id value) + :type (pr-str (type value)) + :pr-str (pr-str' value) + :protocols (cond-> #{} + (deref? value) (conj :IDeref))} + m (assoc :meta m) + rep (assoc :rep rep)))))) #?(:bb nil :clj @@ -239,13 +252,13 @@ (if-let [id (value->id? value)] (cson/-to-json (cson/tagged-value "ref" id) buffer) (cson/tagged-coll - buffer - (cond - (instance? java.util.Set value) "#" - (instance? java.util.RandomAccess value) "[" - :else "(") - {::id (value->id value) ::type (type value)} - value))))) + buffer + (cond + (instance? java.util.Set value) "#" + (instance? java.util.RandomAccess value) "[" + :else "(") + {::id (value->id value) ::type (type value)} + value))))) #?(:bb nil :clj @@ -255,12 +268,12 @@ (if-let [id (value->id? value)] (cson/-to-json (cson/tagged-value "ref" id) buffer) (cson/tagged-map - buffer - "{" - (if (record? value) - (meta value) - {::id (value->id value) ::type (type value)}) - value))))) + buffer + "{" + (if (record? value) + (meta value) + {::id (value->id value) ::type (type value)}) + value))))) (extend-type #?(:clj Object :cljr Object @@ -308,23 +321,23 @@ (defn write [value session] (binding [*session* session] (cson/write - value - (merge - session - {:transform (comp id-var id-coll) - :to-object to-object})))) + value + (merge + session + {:transform (comp id-var id-coll) + :to-object to-object})))) (defn read [string session] (binding [*session* session] (cson/read - string - (merge - session - {:default-handler - (fn [op value] - (case op - "ref" (id->value value) - (cson/tagged-value op value)))})))) + string + (merge + session + {:default-handler + (fn [op value] + (case op + "ref" (id->value value) + (cson/tagged-value op value)))})))) (defonce ^:private tap-list (atom (with-meta (list) @@ -356,7 +369,7 @@ (catch #?(:clj Exception :cljr Exception :cljs :default) e (swap! tap-list conj (error->data - (ex-info "Failed to receive value." {:value-type (type new-value)} e)))))) + (ex-info "Failed to receive value." {:value-type (type new-value)} e)))))) (def ^:private runtime-keymap (atom ^::no-cache {})) @@ -364,26 +377,26 @@ (let [{:keys [options watch-registry]} *session*] (with-meta (merge - {:name (if (= :dev (:mode options)) - "portal-dev" - "portal") - :version "0.58.3" - :runtime (runtime) - :platform - #?(:bb "bb" - :clj "jvm" - :cljr "clr" - :joyride "joyride" - :org.babashka/nbb "nbb" - :cljs (cond - (exists? js/window) "web" - (exists? js/process) "node" - (exists? js/PLANCK_VERSION) "planck" - :else "web")) - :value tap-list - :keymap runtime-keymap - :watch-registry watch-registry} - options) + {:name (if (= :dev (:mode options)) + "portal-dev" + "portal") + :version "0.58.3" + :runtime (runtime) + :platform + #?(:bb "bb" + :clj "jvm" + :cljr "clr" + :joyride "joyride" + :org.babashka/nbb "nbb" + :cljs (cond + (exists? js/window) "web" + (exists? js/process) "node" + (exists? js/PLANCK_VERSION) "planck" + :else "web")) + :value tap-list + :keymap runtime-keymap + :watch-registry watch-registry} + options) {::no-cache true}))) (defn clear-values @@ -420,22 +433,22 @@ (defn- get-functions [v] (-> (reduce-kv - (fn [out name opts] - (let [m (merge (meta (:var opts)) opts) - result (-> (select-keys m [:doc :command]) - (assoc :name name) - (vary-meta assoc ::no-cache true))] - (if (:private m) - out - (if-let [predicate (:predicate m)] - (try - (cond-> out - (predicate v) - (assoc name result)) - (catch #?(:clj Exception :cljr Exception :cljs :default) _ex out)) - (assoc out name result))))) - {} - @registry) + (fn [out name opts] + (let [m (merge (meta (:var opts)) opts) + result (-> (select-keys m [:doc :command]) + (assoc :name name) + (vary-meta assoc ::no-cache true))] + (if (:private m) + out + (if-let [predicate (:predicate m)] + (try + (cond-> out + (predicate v) + (assoc name result)) + (catch #?(:clj Exception :cljr Exception :cljs :default) _ex out)) + (assoc out name result))))) + {} + @registry) (v/table {:columns [:doc :command]}) (vary-meta assoc ::no-cache true))) @@ -456,17 +469,17 @@ (done (assoc (source-info f) :return return))) (catch #?(:clj Exception :cljr Exception :cljs js/Error) e (done (assoc - (source-info f) - :error - (-> (ex-info - (ex-message e) - {::function f - ::args args - ::found? (some? f) - ::data (ex-data e)} - e) - datafy - (assoc :runtime (runtime))))))))) + (source-info f) + :error + (-> (ex-info + (ex-message e) + {::function f + ::args args + ::found? (some? f) + ::data (ex-data e)} + e) + datafy + (assoc :runtime (runtime))))))))) (def ops {:portal.rpc/invoke #'invoke}) diff --git a/src/portal/runtime/browser.cljc b/src/portal/runtime/browser.cljc index a9610842..962b1610 100644 --- a/src/portal/runtime/browser.cljc +++ b/src/portal/runtime/browser.cljc @@ -1,46 +1,56 @@ -(ns ^:no-doc portal.runtime.browser - #?(:clj (:refer-clojure :exclude [random-uuid])) - #?(:clj (:require [clojure.java.browse :refer [browse-url]] - [clojure.string :as str] - [portal.runtime :as rt] - [portal.runtime.fs :as fs] - [portal.runtime.json :as json] - [portal.runtime.jvm.client :as c] - [portal.runtime.shell :as shell]) - :cljs (:require [clojure.string :as str] - [portal.runtime :as rt] - [portal.runtime.fs :as fs] - [portal.runtime.json :as json] - [portal.runtime.node.client :as c] - [portal.runtime.shell :as shell]) - :cljr (:require [clojure.string :as str] - [portal.runtime :as rt] - [portal.runtime.clr.client :as c] - [portal.runtime.fs :as fs] - [portal.runtime.json :as json] - [portal.runtime.shell :as shell])) - #?(:cljr (:import [System.Runtime.InteropServices OSPlatform RuntimeInformation]))) +(ns portal.runtime.browser + {:no-doc true} + #?(:clj + (:refer-clojure :exclude [random-uuid])) + (:require + #?@(:clj + [[clojure.java.browse :refer [browse-url]] + [clojure.string :as str] + [portal.runtime :as rt] + [portal.runtime.fs :as fs] + [portal.runtime.json :as json] + [portal.runtime.jvm.client :as c] + [portal.runtime.shell :as shell]] + + :cljr + [[clojure.string :as str] + [portal.runtime :as rt] + [portal.runtime.clr.client :as c] + [portal.runtime.fs :as fs] + [portal.runtime.json :as json] + [portal.runtime.shell :as shell]] + + :cljs + [[clojure.string :as str] + [portal.runtime :as rt] + [portal.runtime.fs :as fs] + [portal.runtime.json :as json] + [portal.runtime.node.client :as c] + [portal.runtime.shell :as shell]])) + #?(:cljr + (:import + (System.Runtime.InteropServices OSPlatform RuntimeInformation)))) (defmulti -open (comp :launcher :options)) (defn- get-chrome-bin [{::keys [chrome-bin]}] (fs/find-bin - (concat - ["/Applications/Google Chrome.app/Contents/MacOS" - "/Program Files/Google/Chrome/Application" - "/Program Files (x86)/Google/Chrome/Application" - "/mnt/c/Program Files/Google/Chrome/Application" - "/mnt/c/Program Files (x86)/Google/Chrome/Application"] - (fs/paths)) - (concat chrome-bin - ["chrome" "chrome.exe" "google-chrome-stable" "chromium-browser" "Google Chrome"]))) + (concat + ["/Applications/Google Chrome.app/Contents/MacOS" + "/Program Files/Google/Chrome/Application" + "/Program Files (x86)/Google/Chrome/Application" + "/mnt/c/Program Files/Google/Chrome/Application" + "/mnt/c/Program Files (x86)/Google/Chrome/Application"] + (fs/paths)) + (concat chrome-bin + ["chrome" "chrome.exe" "google-chrome-stable" "chromium-browser" "Google Chrome"]))) (defn- get-app-id-profile-osx [app-name] (let [info (fs/join - (fs/home) - "Applications/Chrome Apps.localized/" - (str app-name ".app") - "Contents/Info.plist")] + (fs/home) + "Applications/Chrome Apps.localized/" + (str app-name ".app") + "Contents/Info.plist")] (when-let [app-id (some->> info fs/exists fs/slurp @@ -51,12 +61,12 @@ (defn- get-app-id-from-pref-file [path app-name] (when (fs/exists path) (some - (fn [[id extension]] - (let [name (get-in extension ["manifest" "name"] "")] - (when (= app-name name) id))) - (get-in - (json/read (fs/slurp path)) - ["extensions" "settings"])))) + (fn [[id extension]] + (let [name (get-in extension ["manifest" "name"] "")] + (when (= app-name name) id))) + (get-in + (json/read (fs/slurp path)) + ["extensions" "settings"])))) (defn- chrome-profile [path] (re-find #"Default|Profile\s\d+$" path)) @@ -66,36 +76,36 @@ (fs/join ".config" "google-chrome") fs/exists)] (first - (for [file (fs/list chrome-config-dir) - :let [profile (chrome-profile file) - preferences (fs/join file "Preferences") - app-id (get-app-id-from-pref-file preferences app-name)] - :when (and profile app-id)] - {:app-id app-id :profile profile})))) + (for [file (fs/list chrome-config-dir) + :let [profile (chrome-profile file) + preferences (fs/join file "Preferences") + app-id (get-app-id-from-pref-file preferences app-name)] + :when (and profile app-id)] + {:app-id app-id :profile profile})))) (defn- get-windows-user [] (str/trim (:out (shell/sh "cmd.exe" "/C" "echo %USERNAME%")))) (defn- windows-chrome-web-applications [] (tree-seq - (fn [f] - (and (not (fs/is-file f)) - (or - (str/includes? f "_crx_") - (str/ends-with? f "Web Applications")))) - (fn [d] (fs/list d)) - (fs/join - "/mnt/c/Users" - (get-windows-user) - "AppData/Local/Google/Chrome/User Data/Default/Web Applications"))) + (fn [f] + (and (not (fs/is-file f)) + (or + (str/includes? f "_crx_") + (str/ends-with? f "Web Applications")))) + (fn [d] (fs/list d)) + (fs/join + "/mnt/c/Users" + (get-windows-user) + "AppData/Local/Google/Chrome/User Data/Default/Web Applications"))) (defn- get-app-id-profile-windows [app-name] (try (some - (fn [file] - (when (str/ends-with? file (str app-name ".lnk")) - {:app-id (str/replace (fs/basename (fs/dirname file)) "_crx_" "")})) - (windows-chrome-web-applications)) + (fn [file] + (when (str/ends-with? file (str app-name ".lnk")) + {:app-id (str/replace (fs/basename (fs/dirname file)) "_crx_" "")})) + (windows-chrome-web-applications)) (catch #?(:cljs :default :default Exception) _))) (defn- get-app-id-profile @@ -125,25 +135,25 @@ (defn- browse [url] (or - (some-> (get-browser) (shell/spawn url)) - #?(:clj - (try (browse-url url) - (catch Exception _e - (println "Goto" url "to view portal ui."))) - :cljs - (case (.-platform js/process) - ("android" "linux") (shell/spawn "xdg-open" url) - "darwin" (shell/spawn "open" url) - "win32" (shell/spawn "cmd" "/c" "start" url) - (println "Goto" url "to view portal ui.")) - :cljr - (condp identical? (.Platform Environment/OSVersion) - PlatformID/Win32NT (shell/sh "cmd" "/c" "start" url) - PlatformID/Win32Windows (shell/sh "cmd" "/c" "start" url) - PlatformID/Unix (if (RuntimeInformation/IsOSPlatform OSPlatform/OSX) - (shell/sh "open" url) - (shell/sh "xdg-open" url)) - (println "Goto" url "to view portal ui."))))) + (some-> (get-browser) (shell/spawn url)) + #?(:clj + (try (browse-url url) + (catch Exception _e + (println "Goto" url "to view portal ui."))) + :cljs + (case (.-platform js/process) + ("android" "linux") (shell/spawn "xdg-open" url) + "darwin" (shell/spawn "open" url) + "win32" (shell/spawn "cmd" "/c" "start" url) + (println "Goto" url "to view portal ui.")) + :cljr + (condp identical? (.Platform Environment/OSVersion) + PlatformID/Win32NT (shell/sh "cmd" "/c" "start" url) + PlatformID/Win32Windows (shell/sh "cmd" "/c" "start" url) + PlatformID/Unix (if (RuntimeInformation/IsOSPlatform OSPlatform/OSX) + (shell/sh "open" url) + (shell/sh "xdg-open" url)) + (println "Goto" url "to view portal ui."))))) #?(:clj (defn- random-uuid [] (java.util.UUID/randomUUID))) diff --git a/src/portal/runtime/clr/assembly.clj b/src/portal/runtime/clr/assembly.clj index d6acd704..395636de 100644 --- a/src/portal/runtime/clr/assembly.clj +++ b/src/portal/runtime/clr/assembly.clj @@ -1,21 +1,23 @@ -(ns ^:no-doc ^:no-check portal.runtime.clr.assembly - (:require [portal.runtime.fs :as fs])) +(ns :no-check + {:no-doc true} + (:require + [portal.runtime.fs :as fs])) (defn- find-dll [package version] (fs/exists - (fs/join (fs/home) ".nuget/packages" - package - version - "lib/netstandard2.1" - (str package ".dll")))) + (fs/join (fs/home) ".nuget/packages" + package + version + "lib/netstandard2.1" + (str package ".dll")))) (defn- resolve-dlls [deps] (reduce-kv - (fn [out package info] - (let [dll (find-dll (name package) (:nuget/version info))] - (cond-> out dll (assoc package dll)))) - {} - deps)) + (fn [out package info] + (let [dll (find-dll (name package) (:nuget/version info))] + (cond-> out dll (assoc package dll)))) + {} + deps)) (defn load-deps [deps] (doseq [[_package dll] (resolve-dlls deps)] diff --git a/src/portal/runtime/clr/client.clj b/src/portal/runtime/clr/client.clj index 45af9d2f..d04383d9 100644 --- a/src/portal/runtime/clr/client.clj +++ b/src/portal/runtime/clr/client.clj @@ -1,7 +1,10 @@ -(ns ^:no-doc portal.runtime.clr.client - (:require [clojure.pprint :as pprint] - [portal.runtime :as rt]) - (:import [clojure.lang IAtom IDeref])) +(ns portal.runtime.clr.client + {:no-doc true} + (:require + [clojure.pprint :as pprint] + [portal.runtime :as rt]) + (:import + (clojure.lang IAtom IDeref))) (def ops {:portal.rpc/response @@ -18,11 +21,11 @@ (if-let [send! (get @rt/connections session-id)] (deliver p send!) (add-watch - rt/connections - watch-key - (fn [_ _ _old new] - (when-let [send! (get new session-id)] - (deliver p send!))))) + rt/connections + watch-key + (fn [_ _ _old new] + (when-let [send! (get new session-id)] + (deliver p send!))))) (let [result (deref p timeout nil)] (remove-watch rt/connections watch-key) result))) @@ -62,10 +65,10 @@ response :else (throw (ex-info - "Portal request timeout" - {::timeout true - :session-id :all - :message message}))))))) + "Portal request timeout" + {::timeout true + :session-id :all + :message message}))))))) (defn request ([message] diff --git a/src/portal/runtime/clr/launcher.clj b/src/portal/runtime/clr/launcher.clj index 14668bc2..e2a18315 100644 --- a/src/portal/runtime/clr/launcher.clj +++ b/src/portal/runtime/clr/launcher.clj @@ -1,11 +1,14 @@ -(ns ^:no-doc ^:no-check portal.runtime.clr.launcher - (:require [clojure.string :as str] - [portal.runtime :as rt] - [portal.runtime.browser :as browser] - [portal.runtime.clr.client :as c] - [portal.runtime.clr.server :as server]) - (:import (System.Net HttpListener HttpListenerContext) - (System.Text Encoding))) +(ns :no-check + {:no-doc true} + (:require + [clojure.string :as str] + [portal.runtime :as rt] + [portal.runtime.browser :as browser] + [portal.runtime.clr.client :as c] + [portal.runtime.clr.server :as server]) + (:import + (System.Net HttpListener HttpListenerContext) + (System.Text Encoding))) (defn- read-request [^HttpListenerContext context] (let [request (.Request context) @@ -17,13 +20,13 @@ :uri uri :query-string query-string :headers (reduce - (fn [out ^String header] - (let [values (.GetValues headers header)] - (assoc out - (str/lower-case header) - (str/join ", " values)))) - {} - (.AllKeys headers)) + (fn [out ^String header] + (let [values (.GetValues headers header)] + (assoc out + (str/lower-case header) + (str/join ", " values)))) + {} + (.AllKeys headers)) :websocket? (.IsWebSocketRequest request) :body (.InputStream request) :context context})) @@ -53,22 +56,22 @@ (str "http://" host ":" port "/")) (.Start http-server) (reset! - server - {:http-server http-server - :future - (future - (while (.IsListening http-server) - (let [context (.GetContext http-server)] - (future - (try - (let [request-map (read-request context) - response-map (server/handler request-map)] - (when-not (:websocket? request-map) - (write-response context response-map))) - (catch Exception e - (write-response context {:status 500 :body (pr-str e)}))))))) - :port port - :host host}))))) + server + {:http-server http-server + :future + (future + (while (.IsListening http-server) + (let [context (.GetContext http-server)] + (future + (try + (let [request-map (read-request context) + response-map (server/handler request-map)] + (when-not (:websocket? request-map) + (write-response context response-map))) + (catch Exception e + (write-response context {:status 500 :body (pr-str e)}))))))) + :port port + :host host}))))) (defn stop [] (when-let [server @server] diff --git a/src/portal/runtime/clr/server.clj b/src/portal/runtime/clr/server.clj index 05098d8a..a822fcd8 100644 --- a/src/portal/runtime/clr/server.clj +++ b/src/portal/runtime/clr/server.clj @@ -1,18 +1,21 @@ -(ns ^:no-doc ^:no-check portal.runtime.clr.server - (:require [clojure.edn :as edn] - [clojure.string :as str] - [portal.runtime :as rt] - [portal.runtime.fs :as fs] - [portal.runtime.index :as index] - [portal.runtime.json :as json] - [portal.runtime.rpc :as rpc]) - (:import (clojure.lang RT) - (System Environment Guid) - (System.IO Path) - (System.Net HttpListenerContext) - (System.Net.WebSockets WebSocket WebSocketMessageType WebSocketState) - (System.Text Encoding) - (System.Threading CancellationToken Thread))) +(ns :no-check + {:no-doc true} + (:require + [clojure.edn :as edn] + [clojure.string :as str] + [portal.runtime :as rt] + [portal.runtime.fs :as fs] + [portal.runtime.index :as index] + [portal.runtime.json :as json] + [portal.runtime.rpc :as rpc]) + (:import + (System Environment Guid) + (System.IO Path) + (System.Net HttpListenerContext) + (System.Net.WebSockets WebSocket WebSocketMessageType WebSocketState) + (System.Text Encoding) + (System.Threading CancellationToken Thread) + (clojure.lang RT))) (defmulti route (juxt :request-method :uri)) @@ -22,20 +25,20 @@ (defn- send-message [^WebSocket ws ^String message] (let [bytes (.GetBytes Encoding/UTF8 message)] (.SendAsync - ws - (array-segment bytes) - WebSocketMessageType/Text - true - CancellationToken/None))) + ws + (array-segment bytes) + WebSocketMessageType/Text + true + CancellationToken/None))) (defn- receive-message [^WebSocket ws] (let [max-size (* 50 1024 1024) buffer (byte-array max-size)] (loop [receive-count 0] (let [task (.ReceiveAsync - ws - (array-segment buffer receive-count (- max-size receive-count)) - CancellationToken/None) + ws + (array-segment buffer receive-count (- max-size receive-count)) + CancellationToken/None) _ (.Wait task) result (.Result task)] (if-not (.EndOfMessage result) @@ -84,22 +87,22 @@ (defn- resource [path] (some - (fn [dir] - (fs/exists (fs/join (fs/cwd) dir path))) - (str/split - (Environment/GetEnvironmentVariable "CLOJURE_LOAD_PATH") - (re-pattern (str Path/PathSeparator))))) + (fn [dir] + (fs/exists (fs/join (fs/cwd) dir path))) + (str/split + (Environment/GetEnvironmentVariable "CLOJURE_LOAD_PATH") + (re-pattern (str Path/PathSeparator))))) (defmethod route :default [request] (if-not (str/ends-with? (:uri request) ".map") {:status 404} (let [uri (subs (:uri request) 1)] (some - (fn [file] - (when file - (send-resource "application/json" (fs/slurp file)))) - [(resource (str "portal-dev/" uri)) - (resource uri)])))) + (fn [file] + (when file + (send-resource "application/json" (fs/slurp file)))) + [(resource (str "portal-dev/" uri)) + (resource uri)])))) (defmethod route [:get "/icon.svg"] [_] {:status 200 @@ -111,20 +114,20 @@ :headers {"Content-Type" "text/javascript"} :body (fs/slurp - (resource - (case (-> request :session :options :mode) - :dev "portal-dev/main.js" - "portal/main.js")))}) + (resource + (case (-> request :session :options :mode) + :dev "portal-dev/main.js" + "portal/main.js")))}) (defn- get-session-id [request] ;; There might be a referrer which is not a UUID in standalone mode. (try (some-> - (or (:query-string request) - (when-let [referer (get-in request [:headers "referer"])] - (last (str/split referer #"\?")))) - str - Guid/Parse) + (or (:query-string request) + (when-let [referer (get-in request [:headers "referer"])] + (last (str/split referer #"\?")))) + str + Guid/Parse) (catch Exception _ nil))) (defn- with-session [request] @@ -140,9 +143,9 @@ (defmethod route [:post "/submit"] [request] (let [body (slurp (:body request) :encoding "utf8")] (rt/update-value - (case (content-type request) - "application/json" (json/read body) - "application/edn" (edn/read-string {:default tagged-literal} body))) + (case (content-type request) + "application/json" (json/read body) + "application/edn" (edn/read-string {:default tagged-literal} body))) {:status 204 :headers {"Access-Control-Allow-Origin" "*"}})) diff --git a/src/portal/runtime/cson.cljc b/src/portal/runtime/cson.cljc index 0f0f0a86..9af30515 100644 --- a/src/portal/runtime/cson.cljc +++ b/src/portal/runtime/cson.cljc @@ -1,26 +1,33 @@ -(ns ^:no-doc portal.runtime.cson +(ns portal.runtime.cson "Clojure/Script Object Notation" + {:no-doc true} (:refer-clojure :exclude [read]) - #?(:clj (:require [portal.runtime.json-buffer :as json]) - :cljr (:require [portal.runtime.json-buffer :as json]) - :joyride - (:require - [portal.runtime.json-buffer :as json] - [portal.runtime.macros :as m]) - :org.babashka/nbb - (:require - [portal.runtime.json-buffer :as json] - [portal.runtime.macros :as m]) - :cljs - (:require - [goog.crypt.base64 :as Base64] - [portal.runtime.json-buffer :as json] - [portal.runtime.macros :as m])) - #?(:clj (:import [java.net URL] - [java.util Base64 Date UUID]) - :joyride (:import) - :org.babashka/nbb (:import) - :cljs (:import [goog.math Long]))) + (:require + #?@(:clj + [[portal.runtime.json-buffer :as json]] + + :cljr + [[portal.runtime.json-buffer :as json]] + + :cljs + [[goog.crypt.base64 :as Base64] + [portal.runtime.json-buffer :as json] + [portal.runtime.macros :as m]] + + :joyride + [[portal.runtime.json-buffer :as json] + [portal.runtime.macros :as m]] + + :org.babashka/nbb + [[portal.runtime.json-buffer :as json] + [portal.runtime.macros :as m]])) + (:import + #?@(:clj + [(java.net URL) + (java.util Base64 Date UUID)] + + :cljs + [(goog.math Long)]))) (defprotocol ToJson (-to-json [value buffer])) @@ -286,12 +293,12 @@ #?(:cljs (m/extend-type? - js/BigInt - ToJson - (-to-json [value buffer] - (-> buffer - (json/push-string "N") - (json/push-string (str value)))))) + js/BigInt + ToJson + (-to-json [value buffer] + (-> buffer + (json/push-string "N") + (json/push-string (str value)))))) (defn- ->bigint [buffer] #?(:clj (bigint (json/next-string buffer)) @@ -352,14 +359,14 @@ (-> buffer (json/push-string "inst") (json/push-long - (inst-ms - #?(:cljr (.UtcDateTime (System.DateTimeOffset. value)) :default value)))))) + (inst-ms + #?(:cljr (.UtcDateTime (System.DateTimeOffset. value)) :default value)))))) (defn- ->inst [buffer] #?(:clj (Date. ^long (json/next-long buffer)) :cljr (.DateTime - (System.DateTimeOffset/FromUnixTimeMilliseconds - (json/next-long buffer))) + (System.DateTimeOffset/FromUnixTimeMilliseconds + (json/next-long buffer))) :cljs (js/Date. (json/next-long buffer)))) #?(:joyride (def UUID (type (random-uuid)))) @@ -395,12 +402,12 @@ #?(:cljs (m/extend-type? - js/URL - ToJson - (-to-json [value buffer] - (-> buffer - (json/push-string "url") - (json/push-string (str value)))))) + js/URL + ToJson + (-to-json [value buffer] + (-> buffer + (json/push-string "url") + (json/push-string (str value)))))) (defn- ->url [buffer] #?(:clj (URL. (json/next-string buffer)) @@ -458,12 +465,12 @@ (tagged-coll buffer tag (meta value) value)) ([buffer tag meta-map value] (reduce - to-json - (-> buffer - (push-meta meta-map) - (json/push-string tag) - (json/push-long (count value))) - value))) + to-json + (-> buffer + (push-meta meta-map) + (json/push-string tag) + (json/push-long (count value))) + value))) #?(:bb (def clojure.lang.APersistentMap$KeySeq (type (keys {0 0})))) #?(:bb (def clojure.lang.APersistentMap$ValSeq (type (vals {0 0})))) @@ -583,10 +590,10 @@ #?(:org.babashka/nbb nil :cljs (m/extend-type? - ^:cljs.analyzer/no-resolve - cljs.core/IntegerRange - ToJson - (-to-json [value buffer] (tagged-coll buffer "(" value)))) + ^:cljs.analyzer/no-resolve + cljs.core/IntegerRange + ToJson + (-to-json [value buffer] (tagged-coll buffer "(" value)))) #?(:joyride (def Range (type (range)))) #?(:org.babashka/nbb (def Range (type (range)))) @@ -639,8 +646,8 @@ (if (== i n) (persistent! out) (recur - (unchecked-inc i) - (conj! out (->value buffer))))))) + (unchecked-inc i) + (conj! out (->value buffer))))))) #?(:joyride (def PersistentHashSet (type #{1}))) #?(:org.babashka/nbb (def PersistentHashSet (type #{1}))) @@ -665,10 +672,10 @@ values (for [_ (range n)] (->value buffer)) order (zipmap values (range))] (into - (sorted-set-by - (fn [a b] - (compare (get order a) (get order b)))) - values))) + (sorted-set-by + (fn [a b] + (compare (get order a) (get order b)))) + values))) (defn tagged-map ([buffer value] @@ -677,15 +684,15 @@ (tagged-map buffer tag (meta value) value)) ([buffer tag meta-map value] (reduce-kv - (fn [buffer k v] - (-> buffer - (to-json k) - (to-json v))) - (-> buffer - (push-meta meta-map) - (json/push-string tag) - (json/push-long (count value))) - value))) + (fn [buffer k v] + (-> buffer + (to-json k) + (to-json v))) + (-> buffer + (push-meta meta-map) + (json/push-string tag) + (json/push-long (count value))) + value))) #?(:joyride (def PersistentHashMap (type (hash-map)))) #?(:org.babashka/nbb (def PersistentHashMap (type (hash-map)))) @@ -731,8 +738,8 @@ (if (== i n) (persistent! m) (recur - (unchecked-inc i) - (assoc! m (->value buffer) (->value buffer))))))) + (unchecked-inc i) + (assoc! m (->value buffer) (->value buffer))))))) (defn- ->sorted-map [buffer] (let [n (json/next-long buffer) @@ -740,10 +747,10 @@ [(->value buffer) (->value buffer)]) order (zipmap (map first pairs) (range))] (into - (sorted-map-by - (fn [a b] - (compare (get order a) (get order b)))) - pairs))) + (sorted-map-by + (fn [a b] + (compare (get order a) (get order b)))) + pairs))) #?(:bb (def clojure.lang.TaggedLiteral (type (tagged-literal 'a :a)))) @@ -770,35 +777,35 @@ (if-not (string? op) op (transform - (#?@(:bb [case] :cljr [case] :clj [condp eq] :cljs [case]) - op - "s" (json/next-string buffer) - ":" (->keyword buffer) - "{" (->map buffer) - "$" (->symbol buffer) - "[" (->into [] buffer) - "(" (or (list* (->into [] buffer)) '()) - ";" (->keyword-2 buffer) - "%" (->symbol-2 buffer) - "#" (->into #{} buffer) - "^" (->meta buffer) - "D" (->double buffer) - "N" (->bigint buffer) - "C" (->char buffer) - "R" (->ratio buffer) - "bin" (->bin buffer) - "inst" (->inst buffer) - "smap" (->sorted-map buffer) - "sset" (->sset buffer) - "url" (->url buffer) - "uuid" (->uuid buffer) - "tag" (->tagged-literal buffer) - "long" (->long buffer) - "nan" ##NaN - "inf" ##Inf - "-inf" ##-Inf - (let [handler (:default-handler *options* tagged-value)] - (handler op (->value buffer)))))))) + (#?@(:bb [case] :cljr [case] :clj [condp eq] :cljs [case]) + op + "s" (json/next-string buffer) + ":" (->keyword buffer) + "{" (->map buffer) + "$" (->symbol buffer) + "[" (->into [] buffer) + "(" (or (list* (->into [] buffer)) '()) + ";" (->keyword-2 buffer) + "%" (->symbol-2 buffer) + "#" (->into #{} buffer) + "^" (->meta buffer) + "D" (->double buffer) + "N" (->bigint buffer) + "C" (->char buffer) + "R" (->ratio buffer) + "bin" (->bin buffer) + "inst" (->inst buffer) + "smap" (->sorted-map buffer) + "sset" (->sset buffer) + "url" (->url buffer) + "uuid" (->uuid buffer) + "tag" (->tagged-literal buffer) + "long" (->long buffer) + "nan" ##NaN + "inf" ##Inf + "-inf" ##-Inf + (let [handler (:default-handler *options* tagged-value)] + (handler op (->value buffer)))))))) (defn write ([value] (write value nil)) diff --git a/src/portal/runtime/datafy.cljc b/src/portal/runtime/datafy.cljc index 300f9974..0c02ad98 100644 --- a/src/portal/runtime/datafy.cljc +++ b/src/portal/runtime/datafy.cljc @@ -1,4 +1,5 @@ -(ns ^:no-doc portal.runtime.datafy) +(ns portal.runtime.datafy + {:no-doc true}) (defn datafy "Attempts to return x as data. @@ -10,4 +11,4 @@ [x] x) -(defn nav [_coll _k v] v) \ No newline at end of file +(defn nav [_coll _k v] v) diff --git a/src/portal/runtime/edn.cljc b/src/portal/runtime/edn.cljc index 27c0c3b6..fd3224e1 100644 --- a/src/portal/runtime/edn.cljc +++ b/src/portal/runtime/edn.cljc @@ -1,12 +1,17 @@ -(ns ^:no-doc portal.runtime.edn +(ns portal.runtime.edn + {:no-doc true} (:refer-clojure :exclude [read-string]) - (:require #?(:org.babashka/nbb [clojure.core] - :cljs [cljs.tools.reader.impl.commons :as commons]) - #?(:org.babashka/nbb [clojure.core] - :cljs [cljs.tools.reader.impl.utils :refer [numeric?]]) - [clojure.edn :as edn] - [clojure.string :as str] - [portal.runtime.cson :as cson])) + (:require + [clojure.edn :as edn] + [clojure.string :as str] + [portal.runtime.cson :as cson] + #?@(:cljs + [[cljs.tools.reader.impl.commons :as commons] + [cljs.tools.reader.impl.utils :refer [numeric?]]] + + :org.babashka/nbb + [[clojure.core] + [clojure.core]]))) ;; Discard metadata on tagged-literals to improve success rate of read-string. ;; Consider using a different type in the future. @@ -63,10 +68,10 @@ ([{:keys [readers]} edn-string] (with-redefs #?(:org.babashka/nbb [] :cljs [commons/parse-symbol parse-symbol] :default []) (edn/read-string - {:readers (merge - {'portal/var ->var - 'portal/re ->regex - 'portal/bin cson/base64-decode} - readers) - :default tagged-literal} - (-> edn-string escape-var escape-regex))))) \ No newline at end of file + {:readers (merge + {'portal/var ->var + 'portal/re ->regex + 'portal/bin cson/base64-decode} + readers) + :default tagged-literal} + (-> edn-string escape-var escape-regex))))) diff --git a/src/portal/runtime/fs.cljc b/src/portal/runtime/fs.cljc index 7f581425..25457a73 100644 --- a/src/portal/runtime/fs.cljc +++ b/src/portal/runtime/fs.cljc @@ -1,13 +1,22 @@ -(ns ^:no-doc portal.runtime.fs - (:refer-clojure :exclude [slurp spit list file-seq]) - #?(:clj (:require [clojure.java.io :as io] - [clojure.string :as s]) - :cljs (:require ["fs" :as fs] - ["os" :as os] - ["path" :as path] - [clojure.string :as s]) - :cljr (:require [clojure.string :as s])) - #?(:cljr (:import (System.IO Directory File Path)))) +(ns portal.runtime.fs + {:no-doc true} + (:refer-clojure :exclude [file-seq list slurp spit]) + (:require + #?@(:clj + [[clojure.java.io :as io] + [clojure.string :as s]] + + :cljr + [[clojure.string :as s]] + + :cljs + [["fs" :as fs] + ["os" :as os] + ["path" :as path] + [clojure.string :as s]])) + #?(:cljr + (:import + (System.IO Directory File Path)))) (defn cwd [] #?(:clj (System/getProperty "user.dir") @@ -66,14 +75,14 @@ #?(:clj (.lastModified (io/file f)) :cljs (.getTime ^js/Date (.-mtime (fs/lstatSync f))) :cljr (.ToUnixTimeMilliseconds - (DateTimeOffset. (File/GetLastWriteTime f)))))) + (DateTimeOffset. (File/GetLastWriteTime f)))))) (defn can-execute [f] #?(:clj (let [file (io/file f)] (and (.exists file) (.canExecute file) f)) :cljs (when (not - (try (fs/accessSync f fs/constants.X_OK) - (catch :default _e true))) + (try (fs/accessSync f fs/constants.X_OK) + (catch :default _e true))) f) :cljr (exists f))) @@ -82,11 +91,11 @@ (defn find-bin [paths files] (first - (for [file files - path paths - :let [f (join path file)] - :when (can-execute f)] - f))) + (for [file files + path paths + :let [f (join path file)] + :when (can-execute f)] + f))) (defn home [] #?(:clj (System/getProperty "user.home") @@ -127,6 +136,6 @@ (defn file-seq [dir] (tree-seq - (fn [f] (not (is-file f))) - (fn [d] (seq (list d))) - (join dir))) \ No newline at end of file + (fn [f] (not (is-file f))) + (fn [d] (seq (list d))) + (join dir))) diff --git a/src/portal/runtime/index.cljc b/src/portal/runtime/index.cljc index a8022391..96fef790 100644 --- a/src/portal/runtime/index.cljc +++ b/src/portal/runtime/index.cljc @@ -1,4 +1,5 @@ -(ns ^:no-doc portal.runtime.index) +(ns portal.runtime.index + {:no-doc true}) (defn html [{:keys [name version host port session-id code-url platform mode] :or {name "portal" @@ -6,25 +7,25 @@ code-url "main.js" platform #?(:bb "bb" :clj "jvm" :cljs "node" :cljr "clr")}}] (str - "" - "" - "" - "" (str name " - " platform " - " version) "" - "" - "" - "" - "" - "" - "" - "
" - "" - "" - ;; wait.js will ensure headless chrome doesn't exit early - (when (= mode :test) "") - "" - "")) + "" + "" + "" + "" (str name " - " platform " - " version) "" + "" + "" + "" + "" + "" + "" + "
" + "" + "" + ;; wait.js will ensure headless chrome doesn't exit early + (when (= mode :test) "") + "" + "")) diff --git a/src/portal/runtime/json.cljc b/src/portal/runtime/json.cljc index 77b660a5..529658a0 100644 --- a/src/portal/runtime/json.cljc +++ b/src/portal/runtime/json.cljc @@ -1,9 +1,16 @@ -(ns ^:no-doc portal.runtime.json +(ns portal.runtime.json + {:no-doc true} (:refer-clojure :exclude [read]) - #?(:bb (:require [cheshire.core :as json]) - :clj (:require [clojure.data.json :as json]) - :cljr (:require [portal.runtime.clr.assembly] - [clojure.data.json :as json]))) + (:require + #?@(:bb + [[cheshire.core :as json]] + + :clj + [[clojure.data.json :as json]] + + :cljr + [[clojure.data.json :as json] + [portal.runtime.clr.assembly]]))) (defn write [value] #?(:bb (json/generate-string value) diff --git a/src/portal/runtime/json_buffer.cljc b/src/portal/runtime/json_buffer.cljc index 76fc1b9c..3a753b1b 100644 --- a/src/portal/runtime/json_buffer.cljc +++ b/src/portal/runtime/json_buffer.cljc @@ -1,18 +1,16 @@ -(ns ^:no-doc portal.runtime.json-buffer - #?(:cljr (:require [portal.runtime.clr.assembly])) - #?(:bb (:require [portal.runtime.json :as json]) - :clj (:import (com.google.gson.stream JsonReader JsonToken JsonWriter) - (java.io StringReader StringWriter)) - :cljr (:import (System.Text.Json - JsonElement - JsonValueKind - JsonDocumentOptions - JsonSerializerOptions) - (System.Text.Json.Nodes - JsonNode - JsonArray - JsonValue - JsonNodeOptions)))) +(ns portal.runtime.json-buffer + {:no-doc true} + (:require + #?(:bb [portal.runtime.json :as json] + :cljr [portal.runtime.clr.assembly])) + (:import + #?@(:clj + [(com.google.gson.stream JsonReader JsonToken JsonWriter) + (java.io StringReader StringWriter)] + + :cljr + [(System.Text.Json JsonDocumentOptions JsonElement JsonSerializerOptions JsonValueKind) + (System.Text.Json.Nodes JsonArray JsonNode JsonNodeOptions JsonValue)]))) (defn -shift [this] (this)) @@ -29,10 +27,10 @@ (volatile! (json/read data)) :cljr (volatile! - (seq - (JsonNode/Parse ^String data - (JsonNodeOptions.) - (JsonDocumentOptions.)))) + (seq + (JsonNode/Parse ^String data + (JsonNodeOptions.) + (JsonDocumentOptions.)))) :clj (doto (JsonReader. (StringReader. data)) (.beginArray)) diff --git a/src/portal/runtime/jvm/client.clj b/src/portal/runtime/jvm/client.clj index 9b2a58c5..649d5c9f 100644 --- a/src/portal/runtime/jvm/client.clj +++ b/src/portal/runtime/jvm/client.clj @@ -1,7 +1,10 @@ -(ns ^:no-doc portal.runtime.jvm.client - (:require [clojure.pprint :as pprint] - [portal.runtime :as rt]) - (:import [clojure.lang IAtom IDeref])) +(ns portal.runtime.jvm.client + {:no-doc true} + (:require + [clojure.pprint :as pprint] + [portal.runtime :as rt]) + (:import + (clojure.lang IAtom IDeref))) (def ops {:portal.rpc/response @@ -18,11 +21,11 @@ (if-let [send! (get @rt/connections session-id)] (deliver p send!) (add-watch - rt/connections - watch-key - (fn [_ _ _old new] - (when-let [send! (get new session-id)] - (deliver p send!))))) + rt/connections + watch-key + (fn [_ _ _old new] + (when-let [send! (get new session-id)] + (deliver p send!))))) (let [result (deref p timeout nil)] (remove-watch rt/connections watch-key) result))) @@ -39,10 +42,10 @@ (if-not (= response ::timeout) response (throw (ex-info - "Portal request timeout" - {::timeout true - :session-id session-id - :message message}))))) + "Portal request timeout" + {::timeout true + :session-id session-id + :message message}))))) (throw (ex-info "No such portal session" {:session-id session-id :message message})))) @@ -65,10 +68,10 @@ response :else (throw (ex-info - "Portal request timeout" - {::timeout true - :session-id :all - :message message}))))))) + "Portal request timeout" + {::timeout true + :session-id :all + :message message}))))))) (defn request ([message] diff --git a/src/portal/runtime/jvm/commands.clj b/src/portal/runtime/jvm/commands.clj index 0da875c4..c8337750 100644 --- a/src/portal/runtime/jvm/commands.clj +++ b/src/portal/runtime/jvm/commands.clj @@ -1,8 +1,11 @@ -(ns ^:no-doc portal.runtime.jvm.commands - (:require [portal.runtime :as rt] - [portal.runtime.jvm.editor :as editor]) - (:import [java.io File] - [java.net URI URL])) +(ns portal.runtime.jvm.commands + {:no-doc true} + (:require + [portal.runtime :as rt] + [portal.runtime.jvm.editor :as editor]) + (:import + (java.io File) + (java.net URI URL))) (defn- can-slurp? [value] (or (string? value) diff --git a/src/portal/runtime/jvm/editor.clj b/src/portal/runtime/jvm/editor.clj index 7b605dee..53d0bce0 100644 --- a/src/portal/runtime/jvm/editor.clj +++ b/src/portal/runtime/jvm/editor.clj @@ -1,27 +1,30 @@ -(ns ^:no-doc portal.runtime.jvm.editor +(ns portal.runtime.jvm.editor + {:no-doc true} (:refer-clojure :exclude [resolve]) - (:require [clojure.java.io :as io] - [clojure.set :as set] - [clojure.string :as str] - [org.httpkit.client :as http] - [portal.runtime :as rt] - [portal.runtime.fs :as fs] - [portal.runtime.jvm.launcher :as launcher] - [portal.runtime.shell :refer [spawn]]) - (:import (java.io File) - (java.net URL URI))) + (:require + [clojure.java.io :as io] + [clojure.set :as set] + [clojure.string :as str] + [org.httpkit.client :as http] + [portal.runtime :as rt] + [portal.runtime.fs :as fs] + [portal.runtime.jvm.launcher :as launcher] + [portal.runtime.shell :refer [spawn]]) + (:import + (java.io File) + (java.net URI URL))) (defprotocol IResolve (resolve [this])) (defn- find-file [file-name] (some - (fn [^File file] - (when (and (.isFile file) - (= (.getName file) file-name)) - file)) - (concat - (file-seq (io/file "src")) - (file-seq (io/file "test"))))) + (fn [^File file] + (when (and (.isFile file) + (= (.getName file) file-name)) + file)) + (concat + (file-seq (io/file "src")) + (file-seq (io/file "test"))))) (defn- exists [path] (when-let [file (or (fs/exists path) (find-file path))] @@ -60,8 +63,8 @@ (if (fs/is-file (:file m)) (some->> m :file resolve (merge m)) (or - (some->> m :ns resolve (merge m)) - (some->> m :file resolve (merge m)))))) + (some->> m :ns resolve (merge m)) + (some->> m :file resolve (merge m)))))) (extend-protocol IResolve nil @@ -85,8 +88,8 @@ clojure.lang.Symbol (resolve [^clojure.lang.Symbol s] (or - (when (namespace s) (some-> s find-var* resolve)) - (some->> s ns->paths (some io/resource) resolve))) + (when (namespace s) (some-> s find-var* resolve)) + (some->> s ns->paths (some io/resource) resolve))) URL (resolve [^URL url] (or (exists (.getPath url)) @@ -117,17 +120,17 @@ (let [file-info (select-keys info [:file :line :column]) {:keys [error status] :as response} @(http/request - {:url (str "http://" (:host config) ":" (:port config) "/open-file") - :method :post - :headers {"content-type" "application/edn"} - :body (pr-str file-info)})] + {:url (str "http://" (:host config) ":" (:port config) "/open-file") + :method :post + :headers {"content-type" "application/edn"} + :body (pr-str file-info)})] (when (or error (not= status 200)) (throw - (ex-info "Unable to open file in intellij editor" - {:file-info file-info - :config config - :response (select-keys response [:body :headers :status])} - error))))) + (ex-info "Unable to open file in intellij editor" + {:file-info file-info + :config config + :response (select-keys response [:body :headers :status])} + error))))) (defmethod -open-editor :vs-code [{:keys [file line column] :as info}] (try @@ -140,11 +143,11 @@ (defmethod -open-editor :auto [info] (-open-editor - (assoc info :editor - (cond - (fs/exists ".portal/vs-code.edn") :vs-code - (fs/exists ".portal/intellij.edn") :intellij - :else :emacs)))) + (assoc info :editor + (cond + (fs/exists ".portal/vs-code.edn") :vs-code + (fs/exists ".portal/intellij.edn") :intellij + :else :emacs)))) (defn can-goto [input] (or (and (satisfies? IResolve input) (resolve input)) @@ -159,9 +162,9 @@ (when-let [location (can-goto input)] (let [{:keys [options]} rt/*session*] (-open-editor - (assoc location - :editor - (or (:editor options) - (:launcher options) - :auto))) - true))) \ No newline at end of file + (assoc location + :editor + (or (:editor options) + (:launcher options) + :auto))) + true))) diff --git a/src/portal/runtime/jvm/launcher.clj b/src/portal/runtime/jvm/launcher.clj index df3012a5..5c029518 100644 --- a/src/portal/runtime/jvm/launcher.clj +++ b/src/portal/runtime/jvm/launcher.clj @@ -1,13 +1,15 @@ -(ns ^:no-doc portal.runtime.jvm.launcher - (:require [clojure.edn :as edn] - [org.httpkit.client :as client] - [org.httpkit.server :as http] - [portal.runtime :as rt] - [portal.runtime.browser :as browser] - [portal.runtime.fs :as fs] - [portal.runtime.jvm.client :as c] - [portal.runtime.jvm.server :as server] - [portal.runtime.shell :refer [spawn]])) +(ns portal.runtime.jvm.launcher + {:no-doc true} + (:require + [clojure.edn :as edn] + [org.httpkit.client :as client] + [org.httpkit.server :as http] + [portal.runtime :as rt] + [portal.runtime.browser :as browser] + [portal.runtime.fs :as fs] + [portal.runtime.jvm.client :as c] + [portal.runtime.jvm.server :as server] + [portal.runtime.shell :refer [spawn]])) (defn- get-search-paths [] (->> (fs/cwd) (iterate fs/dirname) (take-while some?))) @@ -15,31 +17,31 @@ (defn get-config [{:keys [options config-file]}] (let [search-paths (get-search-paths)] (or (some - (fn [parent] - (some-> parent - (fs/join ".portal" config-file) - fs/exists - fs/slurp - edn/read-string - (merge (when-let [config (:launcher-config options)] - config)))) - search-paths) + (fn [parent] + (some-> parent + (fs/join ".portal" config-file) + fs/exists + fs/slurp + edn/read-string + (merge (when-let [config (:launcher-config options)] + config)))) + search-paths) (throw - (ex-info - (str "No config file found: " config-file) - {:options options - :config-file config-file - :search-paths search-paths}))))) + (ex-info + (str "No config file found: " config-file) + {:options options + :config-file config-file + :search-paths search-paths}))))) (defn- remote-open [{:keys [portal options server] :as args}] (let [config (get-config args) {:keys [status error] :as response} @(client/request - {:url (str "http://" (:host config) ":" (:port config) "/open") - :method :post - :body (pr-str {:portal (into {} portal) - :options (select-keys options [:window-title]) - :server (select-keys server [:host :port])})})] + {:url (str "http://" (:host config) ":" (:port config) "/open") + :method :post + :body (pr-str {:portal (into {} portal) + :options (select-keys options [:window-title]) + :server (select-keys server [:host :port])})})] (when (or error (not= status 200)) (throw (ex-info "Unable to open extension" {:options options @@ -52,11 +54,11 @@ (remote-open (assoc args :config-file "intellij.edn")) (catch Exception e (throw - (ex-info - (str - (ex-message e) - ": Please ensure extension is installed and Portal tab is open.") - (ex-data e)))))) + (ex-info + (str + (ex-message e) + ": Please ensure extension is installed and Portal tab is open.") + (ex-data e)))))) (defmethod browser/-open :vs-code [args] (remote-open (assoc args :config-file "vs-code.edn"))) @@ -69,10 +71,10 @@ (defmethod browser/-open :auto [args] (browser/-open - (assoc-in args [:options :launcher] - (cond - (fs/exists ".portal/vs-code.edn") :vs-code - (fs/exists ".portal/intellij.edn") :intellij)))) + (assoc-in args [:options :launcher] + (cond + (fs/exists ".portal/vs-code.edn") :vs-code + (fs/exists ".portal/intellij.edn") :intellij)))) (defonce ^:private server (atom nil)) @@ -87,10 +89,10 @@ :max-ws (* 1024 1024 1024) :legacy-return-value? false})] (reset! - server - {:http-server http-server - :port (http/server-port http-server) - :host host}))))) + server + {:http-server http-server + :port (http/server-port http-server) + :host host}))))) (defn stop [] (some-> server deref :http-server http/server-stop!) diff --git a/src/portal/runtime/jvm/server.clj b/src/portal/runtime/jvm/server.clj index 21a9b16f..16ef9167 100644 --- a/src/portal/runtime/jvm/server.clj +++ b/src/portal/runtime/jvm/server.clj @@ -1,18 +1,21 @@ -(ns ^:no-doc portal.runtime.jvm.server - (:require [clojure.edn :as edn] - [clojure.java.io :as io] - [clojure.string :as str] - [cognitect.transit :as transit] - [org.httpkit.server :as server] - [portal.runtime :as rt] - [portal.runtime.cson :as cson] - [portal.runtime.fs :as fs] - [portal.runtime.index :as index] - [portal.runtime.json :as json] - [portal.runtime.npm :as npm] - [portal.runtime.rpc :as rpc]) - (:import [java.io File PushbackReader] - [java.util UUID])) +(ns portal.runtime.jvm.server + {:no-doc true} + (:require + [clojure.edn :as edn] + [clojure.java.io :as io] + [clojure.string :as str] + [cognitect.transit :as transit] + [org.httpkit.server :as server] + [portal.runtime :as rt] + [portal.runtime.cson :as cson] + [portal.runtime.fs :as fs] + [portal.runtime.index :as index] + [portal.runtime.json :as json] + [portal.runtime.npm :as npm] + [portal.runtime.rpc :as rpc]) + (:import + (java.io File PushbackReader) + (java.util UUID))) (def ^:private enable-cors {:status 204 @@ -40,12 +43,12 @@ (let [session (rt/open-session (:session request)) debug (open-debug session)] (server/as-channel - request - {:on-receive (fn [_ch message] (rpc/on-receive session message)) - :on-open (fn [ch] (rpc/on-open session #(server/send! ch %))) - :on-close (fn [_ch _status] - (close-debug debug) - (rpc/on-close session))}))) + request + {:on-receive (fn [_ch message] (rpc/on-receive session message)) + :on-open (fn [ch] (rpc/on-open session #(server/send! ch %))) + :on-close (fn [_ch _status] + (close-debug debug) + (rpc/on-close session))}))) (defn- send-resource [content-type resource] {:status 200 @@ -61,11 +64,11 @@ {:status 404} (let [uri (subs (:uri request) 1)] (some - (fn [^File file] - (when (and file (.exists file)) - (send-resource "application/json" (slurp file)))) - [(io/file (io/resource (str "portal-dev/" uri))) - (io/file (io/resource uri))])))) + (fn [^File file] + (when (and file (.exists file)) + (send-resource "application/json" (slurp file)))) + [(io/file (io/resource (str "portal-dev/" uri))) + (io/file (io/resource uri))])))) (defmethod route [:get "/icon.svg"] [_] {:status 200 @@ -77,19 +80,19 @@ :headers {"Content-Type" "text/javascript"} :body (slurp - (io/resource - (case (-> request :session :options :mode) - :dev "portal-dev/main.js" - "portal/main.js")))}) + (io/resource + (case (-> request :session :options :mode) + :dev "portal-dev/main.js" + "portal/main.js")))}) (defn- get-session-id [request] ;; There might be a referrer which is not a UUID in standalone mode. (try (some-> - (or (:query-string request) - (when-let [referer (get-in request [:headers "referer"])] - (last (str/split referer #"\?")))) - UUID/fromString) + (or (:query-string request) + (when-let [referer (get-in request [:headers "referer"])] + (last (str/split referer #"\?")))) + UUID/fromString) (catch Exception _ nil))) (defn- with-session [request] @@ -108,8 +111,8 @@ "application/json" (json/read-stream (io/reader body)) "application/cson" (cson/read (slurp body)) "application/edn" (edn/read - {:default tagged-literal} - (PushbackReader. (io/reader body))))) + {:default tagged-literal} + (PushbackReader. (io/reader body))))) (defn- ->js [file] (let [source (fs/slurp file)] @@ -127,18 +130,18 @@ "Access-Control-Allow-Origin" "*"} :body (json/write - (let [{:keys [name path macros] :as m} (body request)] - (if (or (= name 'react) (string? name) (:npm name)) - (node-resolve m) - (some - (fn [ext] - (when-let [resource (io/resource (str path ext))] - {:lang (if (= ext ".js") :js :clj) - :file (str resource) - :source (slurp resource)})) - (if macros - [".clj" ".cljc"] - [".cljs" ".cljc" ".js"])))))}) + (let [{:keys [name path macros] :as m} (body request)] + (if (or (= name 'react) (string? name) (:npm name)) + (node-resolve m) + (some + (fn [ext] + (when-let [resource (io/resource (str path ext))] + {:lang (if (= ext ".js") :js :clj) + :file (str resource) + :source (slurp resource)})) + (if macros + [".clj" ".cljc"] + [".cljs" ".cljc" ".js"])))))}) (defmethod route [:options "/submit"] [_] enable-cors) (defmethod route [:post "/submit"] [request] diff --git a/src/portal/runtime/macros.cljc b/src/portal/runtime/macros.cljc index 72a17014..7f322d75 100644 --- a/src/portal/runtime/macros.cljc +++ b/src/portal/runtime/macros.cljc @@ -1,5 +1,8 @@ -(ns ^:no-doc portal.runtime.macros - #?(:cljs (:require-macros portal.runtime.macros))) +(ns portal.runtime.macros + {:no-doc true} + #?(:cljs + (:require-macros + [portal.runtime.macros]))) #?(:clj (defn- resolve-var [& args] diff --git a/src/portal/runtime/node/client.cljs b/src/portal/runtime/node/client.cljs index f3411937..93b7c1ed 100644 --- a/src/portal/runtime/node/client.cljs +++ b/src/portal/runtime/node/client.cljs @@ -1,6 +1,8 @@ -(ns ^:no-doc portal.runtime.node.client - (:require [portal.async :as a] - [portal.runtime :as rt])) +(ns portal.runtime.node.client + {:no-doc true} + (:require + [portal.async :as a] + [portal.runtime :as rt])) (def ops {:portal.rpc/response @@ -14,24 +16,24 @@ (defn- get-connection [session-id] (let [done (atom nil)] (.race - js/Promise - [(js/Promise. - (fn [resolve _reject] - (let [handle (js/setTimeout #(resolve nil) timeout)] - (reset! done #(js/clearTimeout handle))))) - (js/Promise. - (fn [resolve _reject] - (if-let [send! (get @rt/connections session-id)] - (do (@done) (resolve send!)) - (let [watch-key (keyword (gensym))] - (add-watch - rt/connections - watch-key - (fn [_ _ _old new] - (when-let [send! (get new session-id)] - (@done) - (remove-watch rt/connections watch-key) - (resolve send!))))))))]))) + js/Promise + [(js/Promise. + (fn [resolve _reject] + (let [handle (js/setTimeout #(resolve nil) timeout)] + (reset! done #(js/clearTimeout handle))))) + (js/Promise. + (fn [resolve _reject] + (if-let [send! (get @rt/connections session-id)] + (do (@done) (resolve send!)) + (let [watch-key (keyword (gensym))] + (add-watch + rt/connections + watch-key + (fn [_ _ _old new] + (when-let [send! (get new session-id)] + (@done) + (remove-watch rt/connections watch-key) + (resolve send!))))))))]))) (defn request ([message] @@ -46,11 +48,11 @@ (let [id (rt/next-id) message (assoc message :portal.rpc/id id)] (.then - (js/Promise. - (fn [resolve reject] - (swap! rt/pending-requests assoc id [resolve reject]) - (send! message))) - #(do (swap! rt/pending-requests dissoc id) %))) + (js/Promise. + (fn [resolve reject] + (swap! rt/pending-requests assoc id [resolve reject]) + (send! message))) + #(do (swap! rt/pending-requests dissoc id) %))) (throw (ex-info "No such portal session" {:session-id session-id :message message})))))) diff --git a/src/portal/runtime/node/launcher.cljs b/src/portal/runtime/node/launcher.cljs index 6d6241d2..700183f4 100644 --- a/src/portal/runtime/node/launcher.cljs +++ b/src/portal/runtime/node/launcher.cljs @@ -1,13 +1,15 @@ -(ns ^:no-doc portal.runtime.node.launcher - (:require ["http" :as http] - [clojure.edn :as edn] - [portal.async :as a] - [portal.client.node :as client] - [portal.runtime :as rt] - [portal.runtime.browser :as browser] - [portal.runtime.fs :as fs] - [portal.runtime.node.client :as c] - [portal.runtime.node.server :as server])) +(ns portal.runtime.node.launcher + {:no-doc true} + (:require + ["http" :as http] + [clojure.edn :as edn] + [portal.async :as a] + [portal.client.node :as client] + [portal.runtime :as rt] + [portal.runtime.browser :as browser] + [portal.runtime.fs :as fs] + [portal.runtime.node.client :as c] + [portal.runtime.node.server :as server])) (defn- get-workspace-folder [] (try @@ -24,19 +26,19 @@ (let [search-paths (concat (get-search-paths (fs/cwd)) (some-> (get-workspace-folder) get-search-paths))] (or (some - (fn [parent] - (some-> parent - (fs/join ".portal" config-file) - fs/exists - fs/slurp - edn/read-string)) - search-paths) + (fn [parent] + (some-> parent + (fs/join ".portal" config-file) + fs/exists + fs/slurp + edn/read-string)) + search-paths) (throw - (ex-info - (str "No config file found: " config-file) - {:options options - :config-file config-file - :search-paths search-paths}))))) + (ex-info + (str "No config file found: " config-file) + {:options options + :config-file config-file + :search-paths search-paths}))))) (defn- localhost "https://github.com/nodejs/node/issues/40537" @@ -47,12 +49,12 @@ (a/let [config (get-config args) {:keys [status error] :as response} (client/fetch - (str "http://" (localhost (:host config)) ":" (:port config) "/open") - {:method "POST" - :headers {"content-type" "application/edn"} - :body (pr-str {:portal (into {} portal) - :options (select-keys options [:window-title]) - :server (select-keys server [:host :port])})})] + (str "http://" (localhost (:host config)) ":" (:port config) "/open") + {:method "POST" + :headers {"content-type" "application/edn"} + :body (pr-str {:portal (into {} portal) + :options (select-keys options [:window-title]) + :server (select-keys server [:host :port])})})] (when (or error (not= status 200)) (throw (ex-info "Unable to open extension" {:options options @@ -69,23 +71,23 @@ (defn- create-server [handler port host] (js/Promise. - (fn [resolve _reject] - (let [^js server (http/createServer #(handler %1 %2))] - (set! (.-requestTimeout server) 0) - (set! (.-headersTimeout server) 0) - (.on server - "connection" - (fn [^js socket] - (swap! sockets conj socket) - (.on socket - "close" - (fn [] - (.destroy socket) - (swap! sockets disj socket))))) - (.listen server #js {:port port :host (localhost host)} - #(resolve {:http-server server - :port (.-port (.address server)) - :host host})))))) + (fn [resolve _reject] + (let [^js server (http/createServer #(handler %1 %2))] + (set! (.-requestTimeout server) 0) + (set! (.-headersTimeout server) 0) + (.on server + "connection" + (fn [^js socket] + (swap! sockets conj socket) + (.on socket + "close" + (fn [] + (.destroy socket) + (swap! sockets disj socket))))) + (.listen server #js {:port port :host (localhost host)} + #(resolve {:http-server server + :port (.-port (.address server)) + :host host})))))) (defn start [options] (let [options (merge @rt/default-options options)] diff --git a/src/portal/runtime/node/server.cljs b/src/portal/runtime/node/server.cljs index 7b81ca70..dd855380 100644 --- a/src/portal/runtime/node/server.cljs +++ b/src/portal/runtime/node/server.cljs @@ -1,14 +1,16 @@ -(ns ^:no-doc portal.runtime.node.server - (:require [clojure.edn :as edn] - [clojure.string :as str] - [portal.async :as a] - [portal.resources :as io] - [portal.runtime :as rt] - [portal.runtime.fs :as fs] - [portal.runtime.index :as index] - [portal.runtime.json :as json] - [portal.runtime.rpc :as rpc] - [portal.runtime.transit :as transit])) +(ns portal.runtime.node.server + {:no-doc true} + (:require + [clojure.edn :as edn] + [clojure.string :as str] + [portal.async :as a] + [portal.resources :as io] + [portal.runtime :as rt] + [portal.runtime.fs :as fs] + [portal.runtime.index :as index] + [portal.runtime.json :as json] + [portal.runtime.rpc :as rpc] + [portal.runtime.transit :as transit])) (defn- get-header [^js req k] (-> req .-headers (aget k))) @@ -26,10 +28,10 @@ (defn- get-session-id [^js req] (some-> - (or (second (str/split (.-url req) #"\?")) - (when-let [referer (get-header req "referer")] - (last (str/split referer #"\?")))) - uuid)) + (or (second (str/split (.-url req) #"\?")) + (when-let [referer (get-header req "referer")] + (last (str/split referer #"\?")))) + uuid)) (defn- get-session [req] (some-> req get-session-id rt/get-session)) @@ -44,15 +46,15 @@ (let [session (get-session req)] (.on (.-socket req) "error" js/console.error) (.handleUpgrade - (Server. #js {:noServer true}) - req - (.-socket req) - (.-headers req) - (fn [^js ws] - (let [session (rt/open-session session)] - (rpc/on-open session #(.send ws %)) - (.on ws "message" (fn [message] (rpc/on-receive session message))) - (.on ws "close" (fn [] (rpc/on-close session)))))))) + (Server. #js {:noServer true}) + req + (.-socket req) + (.-headers req) + (fn [^js ws] + (let [session (rt/open-session session)] + (rpc/on-open session #(.send ws %)) + (.on ws "message" (fn [message] (rpc/on-receive session message))) + (.on ws "close" (fn [] (rpc/on-close session)))))))) (defn- send-resource [^js res content-type body] (-> res @@ -66,8 +68,8 @@ (swap! rt/sessions assoc session-id {}) (doto res (.writeHead - 307 - #js {"Location" (str "?" session-id)}) + 307 + #js {"Location" (str "?" session-id)}) (.end))))) (def ^:private favicon (io/inline "portal/icon.svg")) @@ -80,42 +82,42 @@ (defmethod route [:get "/main.js"] [req res] (let [options (-> req get-session :options)] (send-resource - res - "text/javascript" - (case (:mode options) - :dev (fs/slurp (or (get-in options [:resource "main.js"]) - (io/resource "portal-dev/main.js"))) - main-js)))) + res + "text/javascript" + (case (:mode options) + :dev (fs/slurp (or (get-in options [:resource "main.js"]) + (io/resource "portal-dev/main.js"))) + main-js)))) (defn get-body [^js req] (js/Promise. - (fn [resolve reject] - (let [body (atom "")] - (.on req "data" #(swap! body str %)) - (.on req "end" #(resolve @body)) - (.on req "error" reject))))) + (fn [resolve reject] + (let [body (atom "")] + (.on req "data" #(swap! body str %)) + (.on req "end" #(resolve @body)) + (.on req "error" reject))))) (defmethod route [:post "/submit"] [^js req ^js res] (a/let [body (get-body req)] (rt/update-value - (case (get-header req "content-type") - "application/transit+json" (transit/read body) - "application/json" (js->clj (json/read body)) - "application/edn" (edn/read-string {:default tagged-literal} body))) + (case (get-header req "content-type") + "application/transit+json" (transit/read body) + "application/json" (js->clj (json/read body)) + "application/edn" (edn/read-string {:default tagged-literal} body))) (doto res (.writeHead - 204 - #js {"Access-Control-Allow-Origin" "*"}) + 204 + #js {"Access-Control-Allow-Origin" "*"}) (.end)))) (defmethod route [:options "/submit"] [_req ^js res] (doto res (.writeHead - 204 - #js {"Access-Control-Allow-Origin" "*" - "Access-Control-Allow-Headers" "origin, content-type" - "Access-Control-Allow-Methods" "POST, GET, OPTIONS, DELETE" - "Access-Control-Max-Age" 86400}) + 204 + #js {"Access-Control-Allow-Origin" "*" + "Access-Control-Allow-Headers" "origin, content-type" + "Access-Control-Allow-Methods" "POST, GET, OPTIONS, DELETE" + "Access-Control-Max-Age" 86400}) (.end))) (defmethod route :default [_req ^js res] (-> res (.writeHead 404) .end)) diff --git a/src/portal/runtime/npm.cljc b/src/portal/runtime/npm.cljc index 7713f0ff..a4c8698a 100644 --- a/src/portal/runtime/npm.cljc +++ b/src/portal/runtime/npm.cljc @@ -1,35 +1,37 @@ -(ns ^:no-doc portal.runtime.npm - (:require #?(:clj [clojure.java.io :as io]) - [clojure.string :as str] - [portal.runtime.fs :as fs] - [portal.runtime.json :as json])) +(ns portal.runtime.npm + {:no-doc true} + (:require + [clojure.string :as str] + [portal.runtime.fs :as fs] + [portal.runtime.json :as json] + #?(:clj [clojure.java.io :as io]))) (defn- package-resolve [module] (when-let [package (fs/exists (fs/join module "package.json"))] (fs/exists - (fs/join - module - (let [json (json/read (fs/slurp package) {}) - umd (get-in json ["exports" "umd"]) - unpkg (get json "unpkg") - browser (get json "browser") - main (get json "main")] - (or umd - (when (string? browser) - browser) - (get browser main) - (get browser (str "./" main)) - main - unpkg - "index.js")))))) + (fs/join + module + (let [json (json/read (fs/slurp package) {}) + umd (get-in json ["exports" "umd"]) + unpkg (get json "unpkg") + browser (get json "browser") + main (get json "main")] + (or umd + (when (string? browser) + browser) + (get browser main) + (get browser (str "./" main)) + main + unpkg + "index.js")))))) #_{:clj-kondo/ignore #?(:clj [] :default [:unused-binding])} (defn- resource-resolve [file] #?(:clj (some-> - (io/file - (or (io/resource file) - (io/resource (str file ".js")))) - str))) + (io/file + (or (io/resource file) + (io/resource (str file ".js")))) + str))) (defn- relative-resolve [module root] (let [path (fs/join root module)] @@ -56,15 +58,15 @@ (relative-resolve module root) (let [search-paths (get-parents root)] (or - (some - (fn [root] - (let [path (fs/join root module)] - (or - (fs/is-file path) - (fs/is-file (str path ".js")) - (package-resolve path) - (fs/is-file (fs/join path "index.js"))))) - search-paths) - (throw - (ex-info (str "Unable to find node module: " (pr-str module)) - {:module module :search-paths search-paths}))))))) + (some + (fn [root] + (let [path (fs/join root module)] + (or + (fs/is-file path) + (fs/is-file (str path ".js")) + (package-resolve path) + (fs/is-file (fs/join path "index.js"))))) + search-paths) + (throw + (ex-info (str "Unable to find node module: " (pr-str module)) + {:module module :search-paths search-paths}))))))) diff --git a/src/portal/runtime/rpc.cljc b/src/portal/runtime/rpc.cljc index 0404d97e..d3c7aa64 100644 --- a/src/portal/runtime/rpc.cljc +++ b/src/portal/runtime/rpc.cljc @@ -1,8 +1,10 @@ -(ns ^:no-doc portal.runtime.rpc - (:require #?(:clj [portal.runtime.jvm.client :as c] - :cljs [portal.runtime.node.client :as c] - :cljr [portal.runtime.clr.client :as c]) - [portal.runtime :as rt])) +(ns portal.runtime.rpc + {:no-doc true} + (:require + [portal.runtime :as rt] + #?(:clj [portal.runtime.jvm.client :as c] + :cljr [portal.runtime.clr.client :as c] + :cljs [portal.runtime.node.client :as c]))) (defn on-open [session send!] (swap! rt/connections @@ -32,12 +34,12 @@ op (get ops (:op body) not-found) done (fn on-done [response] (send! - (assoc response - :portal.rpc/id id - :op :portal.rpc/response)))] + (assoc response + :portal.rpc/id id + :op :portal.rpc/response)))] (binding [rt/*session* session] (op body done)))) (defn on-close [session] (swap! rt/connections dissoc (:session-id session)) - (rt/reset-session session)) \ No newline at end of file + (rt/reset-session session)) diff --git a/src/portal/runtime/shell.cljc b/src/portal/runtime/shell.cljc index 14ac6636..4683d89d 100644 --- a/src/portal/runtime/shell.cljc +++ b/src/portal/runtime/shell.cljc @@ -1,7 +1,9 @@ -(ns ^:no-doc portal.runtime.shell - #?(:clj (:require [clojure.java.shell :as shell]) - :cljs (:require ["child_process" :as cp]) - :cljr (:require [clojure.clr.shell :as shell]))) +(ns portal.runtime.shell + {:no-doc true} + (:require + #?(:clj [clojure.java.shell :as shell] + :cljr [clojure.clr.shell :as shell] + :cljs ["child_process" :as cp]))) (defn spawn [bin & args] #?(:clj @@ -12,10 +14,10 @@ (println err out)))) :cljs (js/Promise. - (fn [resolve reject] - (let [ps (cp/spawn bin (clj->js args))] - (.on ps "error" reject) - (.on ps "close" resolve)))) + (fn [resolve reject] + (let [ps (cp/spawn bin (clj->js args))] + (.on ps "error" reject) + (.on ps "close" resolve)))) :cljr (future (let [{:keys [exit err out]} (apply shell/sh bin args)] @@ -29,4 +31,4 @@ {:exit (.-status result) :out (str (.-stdout result)) :err (str (.-stderr result))}) - :cljr (apply shell/sh bin args))) \ No newline at end of file + :cljr (apply shell/sh bin args))) diff --git a/src/portal/runtime/transit.cljc b/src/portal/runtime/transit.cljc index c1b6e76a..5494858f 100644 --- a/src/portal/runtime/transit.cljc +++ b/src/portal/runtime/transit.cljc @@ -1,10 +1,13 @@ -(ns ^:no-doc portal.runtime.transit +(ns portal.runtime.transit + {:no-doc true} (:refer-clojure :exclude [read]) - #?(:org.babashka/nbb (:require) - :joyride (:require [cljs.core]) - :clj (:require [cognitect.transit :as transit]) - :cljs (:require [cognitect.transit :as transit])) - #?(:clj (:import [java.io ByteArrayOutputStream ByteArrayInputStream]))) + (:require + #?(:clj [cognitect.transit :as transit] + :cljs [cognitect.transit :as transit] + :joyride [cljs.core])) + #?(:clj + (:import + (java.io ByteArrayInputStream ByteArrayOutputStream)))) (defn read [string] #?(:org.babashka/nbb @@ -27,9 +30,9 @@ :clj (let [out (ByteArrayOutputStream. 1024)] (transit/write - (transit/writer out :json {:transform transit/write-meta}) - value) + (transit/writer out :json {:transform transit/write-meta}) + value) (.toString out)) :cljs (transit/write - (transit/writer :json {:transform transit/write-meta}) - value))) + (transit/writer :json {:transform transit/write-meta}) + value))) diff --git a/src/portal/runtime/web/client.cljs b/src/portal/runtime/web/client.cljs index dc016611..3afd8f19 100644 --- a/src/portal/runtime/web/client.cljs +++ b/src/portal/runtime/web/client.cljs @@ -1,5 +1,7 @@ -(ns ^:no-doc portal.runtime.web.client - (:require [portal.runtime :as rt])) +(ns portal.runtime.web.client + {:no-doc true} + (:require + [portal.runtime :as rt])) (defonce connection (atom nil)) @@ -11,8 +13,8 @@ ([_session-id message] (if-let [child-window @connection] (rt/read - (.portal.ui.rpc.handler ^js child-window (rt/write message @session)) - @session) + (.portal.ui.rpc.handler ^js child-window (rt/write message @session)) + @session) (throw (ex-info "Portal not open" message))))) (defn- push-state [session-id new-value] diff --git a/src/portal/runtime/web/launcher.cljs b/src/portal/runtime/web/launcher.cljs index 23467c35..89e74d32 100644 --- a/src/portal/runtime/web/launcher.cljs +++ b/src/portal/runtime/web/launcher.cljs @@ -1,8 +1,10 @@ -(ns ^:no-doc portal.runtime.web.launcher - (:require [portal.resources :as io] - [portal.runtime :as rt] - [portal.runtime.index :as index] - [portal.runtime.web.client :as c])) +(ns portal.runtime.web.launcher + {:no-doc true} + (:require + [portal.resources :as io] + [portal.runtime :as rt] + [portal.runtime.index :as index] + [portal.runtime.web.client :as c])) (defn- str->src [value content-type] (let [blob (js/Blob. #js [value] #js {:type content-type}) @@ -26,15 +28,15 @@ (defn send! [message] (js/Promise. - (fn [resolve _reject] - (let [session (merge (rt/get-session (:session-id @c/session)) @c/session) - body (rt/read message session) - id (:portal.rpc/id body) - f (get rt/ops (:op body) not-found)] - (when (== id 1) - (swap! c/session rt/reset-session)) - (binding [rt/*session* session] - (f body #(resolve (rt/write (assoc % :portal.rpc/id id) session)))))))) + (fn [resolve _reject] + (let [session (merge (rt/get-session (:session-id @c/session)) @c/session) + body (rt/read message session) + id (:portal.rpc/id body) + f (get rt/ops (:op body) not-found)] + (when (== id 1) + (swap! c/session rt/reset-session)) + (binding [rt/*session* session] + (f body #(resolve (rt/write (assoc % :portal.rpc/id id) session)))))))) (defn- get-session [] (if (exists? js/PORTAL_SESSION) diff --git a/src/portal/shadow/preload.cljs b/src/portal/shadow/preload.cljs index 044c1a97..ca422baa 100644 --- a/src/portal/shadow/preload.cljs +++ b/src/portal/shadow/preload.cljs @@ -1,4 +1,5 @@ -(ns portal.shadow.preload - (:require [portal.shadow.remote :as remote])) - -(add-tap remote/submit) +(ns portal.shadow.preload + (:require + [portal.shadow.remote :as remote])) + +(add-tap remote/submit) diff --git a/src/portal/shadow/remote.clj b/src/portal/shadow/remote.clj index 79f1dc5c..863cf7b8 100644 --- a/src/portal/shadow/remote.clj +++ b/src/portal/shadow/remote.clj @@ -1,5 +1,6 @@ (ns portal.shadow.remote - (:require [portal.api :as p])) + (:require + [portal.api :as p])) (defn hook {:shadow.build/stage :compile-prepare} @@ -9,5 +10,5 @@ (cond-> build-state (= (:shadow.build/mode build-state) :dev) (assoc-in - [:compiler-options :closure-defines `port] - (:port (p/start options)))))) + [:compiler-options :closure-defines `port] + (:port (p/start options)))))) diff --git a/src/portal/shadow/remote.cljs b/src/portal/shadow/remote.cljs index 3f998dd0..deb166c8 100644 --- a/src/portal/shadow/remote.cljs +++ b/src/portal/shadow/remote.cljs @@ -1,31 +1,32 @@ -(ns portal.shadow.remote - (:require [portal.client.web :as client])) - -(goog-define port 0) - -(defn get-port - "Get portal server port." - {:added "0.28.0"} - [] - (if-not (zero? port) - port - (let [error (js/Error. - (str "Portal server port is missing. " - "Did you add the portal.shadow.remote/hook to :build-hooks in shadow-cljs.edn? \n" - "See https://shadow-cljs.github.io/docs/UsersGuide.html#build-hooks for more info."))] - (.error js/console error) - (throw error)))) - -(defn submit - "Tap target function. - - Usage: - (add-tap portal.shadow/submit) - (remove-tap portal.shadow/submit)" - {:added "0.28.0" - :see-also ["portal.api/submit" - "portal.client.web/submit"]} - ([value] - (submit {:encoding :edn} value)) - ([option value] - (client/submit (assoc option :port (get-port)) value))) +(ns portal.shadow.remote + (:require + [portal.client.web :as client])) + +(goog-define port 0) + +(defn get-port + "Get portal server port." + {:added "0.28.0"} + [] + (if-not (zero? port) + port + (let [error (js/Error. + (str "Portal server port is missing. " + "Did you add the portal.shadow.remote/hook to :build-hooks in shadow-cljs.edn? \n" + "See https://shadow-cljs.github.io/docs/UsersGuide.html#build-hooks for more info."))] + (.error js/console error) + (throw error)))) + +(defn submit + "Tap target function. + + Usage: + (add-tap portal.shadow/submit) + (remove-tap portal.shadow/submit)" + {:added "0.28.0" + :see-also ["portal.api/submit" + "portal.client.web/submit"]} + ([value] + (submit {:encoding :edn} value)) + ([option value] + (client/submit (assoc option :port (get-port)) value))) diff --git a/src/portal/shortcuts.cljs b/src/portal/shortcuts.cljs index 113fb026..cb20e112 100644 --- a/src/portal/shortcuts.cljs +++ b/src/portal/shortcuts.cljs @@ -1,5 +1,7 @@ -(ns ^:no-doc portal.shortcuts - (:require [clojure.string :as str])) +(ns portal.shortcuts + {:no-doc true} + (:require + [clojure.string :as str])) (defn- get-platform [] (let [platform js/window.navigator.platform] @@ -79,10 +81,9 @@ (defn add! [k f] (init) (add-watch - log k - (fn [_ _ _ log] - (when-not (empty? log) - (f log))))) + log k + (fn [_ _ _ log] + (when-not (empty? log) + (f log))))) (defn remove! [k] (remove-watch log k)) - diff --git a/src/portal/spec.cljc b/src/portal/spec.cljc index c659c4a3..14ae4f3a 100644 --- a/src/portal/spec.cljc +++ b/src/portal/spec.cljc @@ -1,6 +1,8 @@ -(ns ^:no-doc portal.spec - (:require [clojure.spec.alpha :as s] - [portal.colors :as c])) +(ns portal.spec + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [portal.colors :as c])) (s/def ::options (s/keys :opt [::c/theme])) @@ -9,4 +11,3 @@ parsed (s/conform ::options options)] (when (= parsed ::s/invalid) (throw (ex-info "Invalid options" (s/explain-data ::options options)))))) - diff --git a/src/portal/sync.cljc b/src/portal/sync.cljc index 366bb934..953974ba 100644 --- a/src/portal/sync.cljc +++ b/src/portal/sync.cljc @@ -1,4 +1,5 @@ -(ns ^:no-doc portal.sync +(ns portal.sync + {:no-doc true} (:refer-clojure :exclude [let try])) (defmacro let [bindings & body] diff --git a/src/portal/ui/api.cljs b/src/portal/ui/api.cljs index 9339a796..def7a5c5 100644 --- a/src/portal/ui/api.cljs +++ b/src/portal/ui/api.cljs @@ -1,6 +1,7 @@ (ns portal.ui.api - (:require [portal.viewer :as v] - [reagent.core :as r])) + (:require + [portal.viewer :as v] + [reagent.core :as r])) (defonce viewers (r/atom (v/table [] {:columns [:name :doc]}))) @@ -8,17 +9,17 @@ (swap! viewers (fn [viewers] (assoc - viewers - (or - (first - (keep-indexed - (fn [index {:keys [name]}] - (when (= (:name viewer-spec) name) - index)) - viewers)) - (count viewers)) - viewer-spec)))) + viewers + (or + (first + (keep-indexed + (fn [index {:keys [name]}] + (when (= (:name viewer-spec) name) + index)) + viewers)) + (count viewers)) + viewer-spec)))) (def ^:no-doc portal-api "Portal API for JS interop." #js {}) -(set! (.-portal_api js/window) portal-api) \ No newline at end of file +(set! (.-portal_api js/window) portal-api) diff --git a/src/portal/ui/app.cljs b/src/portal/ui/app.cljs index 06ad21ca..86a4a595 100644 --- a/src/portal/ui/app.cljs +++ b/src/portal/ui/app.cljs @@ -1,54 +1,56 @@ -(ns ^:no-doc portal.ui.app - (:require ["react" :as react] - [clojure.string :as str] - [portal.colors :as c] - [portal.ui.api :as api] - [portal.ui.commands :as commands] - [portal.ui.connection-status :as status] - [portal.ui.drag-and-drop :as dnd] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.options :as opts] - [portal.ui.react :refer [use-effect]] - [portal.ui.select :as select] - [portal.ui.state :as state] - [portal.ui.styled :as s] - [portal.ui.theme :as theme] - [portal.ui.viewer.bin :as bin] - [portal.ui.viewer.bytes :as bytes] - [portal.ui.viewer.charts :as charts] - [portal.ui.viewer.cljdoc :as cljdoc] - [portal.ui.viewer.code :as code] - [portal.ui.viewer.color :as color] - [portal.ui.viewer.csv :as csv] - [portal.ui.viewer.date-time :as date-time] - [portal.ui.viewer.deref :as deref] - [portal.ui.viewer.diff :as diff] - [portal.ui.viewer.diff-text :as diff-text] - [portal.ui.viewer.duration :as duration] - [portal.ui.viewer.edn :as edn] - [portal.ui.viewer.exception :as ex] - [portal.ui.viewer.hiccup :as hiccup] - [portal.ui.viewer.html :as html] - [portal.ui.viewer.http :as http] - [portal.ui.viewer.image :as image] - [portal.ui.viewer.json :as json] - [portal.ui.viewer.jwt :as jwt] - [portal.ui.viewer.log :as log] - [portal.ui.viewer.markdown :as md] - [portal.ui.viewer.pprint :as pprint] - [portal.ui.viewer.prepl :as prepl] - [portal.ui.viewer.relative-time :as relative-time] - [portal.ui.viewer.source-location :as source-location] - [portal.ui.viewer.spec :as spec] - [portal.ui.viewer.table :as table] - [portal.ui.viewer.test-report :as test-report] - [portal.ui.viewer.text :as text] - [portal.ui.viewer.transit :as transit] - [portal.ui.viewer.tree :as tree] - [portal.ui.viewer.vega :as vega] - [portal.ui.viewer.vega-lite :as vega-lite] - [reagent.core :as r])) +(ns portal.ui.app + {:no-doc true} + (:require + ["react" :as react] + [clojure.string :as str] + [portal.colors :as c] + [portal.ui.api :as api] + [portal.ui.commands :as commands] + [portal.ui.connection-status :as status] + [portal.ui.drag-and-drop :as dnd] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.options :as opts] + [portal.ui.react :refer [use-effect]] + [portal.ui.select :as select] + [portal.ui.state :as state] + [portal.ui.styled :as s] + [portal.ui.theme :as theme] + [portal.ui.viewer.bin :as bin] + [portal.ui.viewer.bytes :as bytes] + [portal.ui.viewer.charts :as charts] + [portal.ui.viewer.cljdoc :as cljdoc] + [portal.ui.viewer.code :as code] + [portal.ui.viewer.color :as color] + [portal.ui.viewer.csv :as csv] + [portal.ui.viewer.date-time :as date-time] + [portal.ui.viewer.deref :as deref] + [portal.ui.viewer.diff :as diff] + [portal.ui.viewer.diff-text :as diff-text] + [portal.ui.viewer.duration :as duration] + [portal.ui.viewer.edn :as edn] + [portal.ui.viewer.exception :as ex] + [portal.ui.viewer.hiccup :as hiccup] + [portal.ui.viewer.html :as html] + [portal.ui.viewer.http :as http] + [portal.ui.viewer.image :as image] + [portal.ui.viewer.json :as json] + [portal.ui.viewer.jwt :as jwt] + [portal.ui.viewer.log :as log] + [portal.ui.viewer.markdown :as md] + [portal.ui.viewer.pprint :as pprint] + [portal.ui.viewer.prepl :as prepl] + [portal.ui.viewer.relative-time :as relative-time] + [portal.ui.viewer.source-location :as source-location] + [portal.ui.viewer.spec :as spec] + [portal.ui.viewer.table :as table] + [portal.ui.viewer.test-report :as test-report] + [portal.ui.viewer.text :as text] + [portal.ui.viewer.transit :as transit] + [portal.ui.viewer.tree :as tree] + [portal.ui.viewer.vega :as vega] + [portal.ui.viewer.vega-lite :as vega-lite] + [reagent.core :as r])) (defn- select-viewer [] (let [state (state/use-state) @@ -128,10 +130,10 @@ :gap (:padding theme)}} [s/div {:style {:grid-row "1"}} "["] (map-indexed - (fn [idx k] - ^{:key idx} - [s/div {:style {:grid-row "1"}} [ins/preview k]]) - path) + (fn [idx k] + ^{:key idx} + [s/div {:style {:grid-row "1"}} [ins/preview k]]) + path) [s/div {:style {:grid-row "1"}} "]"]] [open-command-palette] [s/div {:style @@ -149,26 +151,26 @@ (::c/diff-add theme) (::c/background2 theme))] (use-effect - #js [header] - (state/set-theme header) - (state/notify-parent {:type :set-theme :color header})) + #js [header] + (state/set-theme header) + (state/notify-parent {:type :set-theme :color header})) (use-effect - #js [opts] - (when-let [{:keys [name platform version]} opts] - (state/set-title! - (str/join - " - " - [(:window-title opts name) platform version])))))) + #js [opts] + (when-let [{:keys [name platform version]} opts] + (state/set-title! + (str/join + " - " + [(:window-title opts name) platform version])))))) (defn display-notification [notification] (let [state (state/use-state) theme (theme/use-theme) timeout (:timeout notification)] (react/useEffect - (fn [] - (when timeout - (js/setTimeout #(state/dispatch! state state/dismiss notification) timeout))) - #js []) + (fn [] + (when timeout + (js/setTimeout #(state/dispatch! state state/dismiss notification) timeout))) + #js []) [s/div {:style {:display :flex @@ -203,14 +205,14 @@ (let [state (state/use-state)] (use-runtime-info) (into - [:<> - [:style - "@keyframes fade-in-out {" - "0%, 100% { opacity: 0 }" - "20%, 80% { opacity: 100 }" - "}"]] - (for [notification (::notifications @state)] - [display-notification notification])))) + [:<> + [:style + "@keyframes fade-in-out {" + "0%, 100% { opacity: 0 }" + "20%, 80% { opacity: 100 }" + "}"]] + (for [notification (::notifications @state)] + [display-notification notification])))) (defn- search-input [] (let [ref (react/useRef nil) @@ -222,9 +224,9 @@ (nth theme/order depth) ::c/border)] (use-effect - :always - (swap! commands/search-refs conj ref) - #(swap! commands/search-refs disj ref)) + :always + (swap! commands/search-refs conj ref) + #(swap! commands/search-refs disj ref)) [s/div {:style @@ -237,13 +239,13 @@ :on-change #(let [value (.-value (.-target %))] (when context (state/dispatch! - state - update - :search-text - (fn [filters] - (if (str/blank? value) - (dissoc filters location) - (assoc filters location value)))))) + state + update + :search-text + (fn [filters] + (if (str/blank? value) + (dissoc filters location) + (assoc filters location value)))))) :on-key-down (fn [e] (when (= (.-key e) "Enter") (.blur (.-current ref)))) @@ -282,19 +284,19 @@ (let [theme (theme/use-theme)] [s/div (merge - {:style {:display :flex - :width "2rem" - :height "2rem" - :border-radius "100%" - :align-items :center - :justify-content :center - :cursor :pointer - :border [1 :solid "rgba(0,0,0,0)"]}} - props - (when-not (:disabled props) - {:style/hover - {:background (::c/background theme) - :border [1 :solid (::c/border theme)]}})) + {:style {:display :flex + :width "2rem" + :height "2rem" + :border-radius "100%" + :align-items :center + :justify-content :center + :cursor :pointer + :border [1 :solid "rgba(0,0,0,0)"]}} + props + (when-not (:disabled props) + {:style/hover + {:background (::c/background theme) + :border [1 :solid (::c/border theme)]}})) child])) (defn- toolbar [] @@ -324,11 +326,11 @@ :title "Go back in portal history." :size "2x" :style (merge - {:transform "scale(0.75)" - :color (::c/text theme)} - (when disabled? - {:opacity 0.45 - :cursor :default}))}]]) + {:transform "scale(0.75)" + :color (::c/text theme)} + (when disabled? + {:opacity 0.45 + :cursor :default}))}]]) (let [disabled? (nil? @(r/cursor state [:portal/next-state]))] [button-hover {:disabled disabled? @@ -338,11 +340,11 @@ :title "Go forward in portal history." :size "2x" :style (merge - {:transform "scale(0.75)" - :color (::c/text theme)} - (when disabled? - {:opacity 0.45 - :cursor :default}))}]]) + {:transform "scale(0.75)" + :color (::c/text theme)} + (when disabled? + {:opacity 0.45 + :cursor :default}))}]]) [search-input] [button-hover {:on-click #(state/dispatch! state state/clear)} @@ -350,17 +352,17 @@ {:title "Clear all values from portal. - CTRL L" :size "2x" :style (merge - {:transform "scale(0.75)" - :color (::c/text theme)})}]]])) + {:transform "scale(0.75)" + :color (::c/text theme)})}]]])) (defn inspect-1 [value] (let [theme (theme/use-theme) state (state/use-state) ref (react/useRef)] (use-effect - #js [(.-current ref)] - (when-let [el (.-current ref)] - (state/dispatch! state assoc :scroll-element el))) + #js [(.-current ref)] + (when-let [el (.-current ref)] + (state/dispatch! state assoc :scroll-element el))) [s/div {:on-mouse-up (fn [e] @@ -435,43 +437,43 @@ (defn- container [children] (let [theme (theme/use-theme)] (into - [s/div - {:on-mouse-over - (fn [_e] - (reset! ins/hover? nil)) - :style - {:-webkit-app-region (when-not (theme/is-vs-code?) :drag) - :display :flex - :flex-direction :column - :background (::c/background theme) - :color (::c/text theme) - :font-family (:font-family theme) - :font-size (:font-size theme) - :height "100vh" - :width "100vw"}} - [styles] - [scrollbars]] - children))) + [s/div + {:on-mouse-over + (fn [_e] + (reset! ins/hover? nil)) + :style + {:-webkit-app-region (when-not (theme/is-vs-code?) :drag) + :display :flex + :flex-direction :column + :background (::c/background theme) + :color (::c/text theme) + :font-family (:font-family theme) + :font-size (:font-size theme) + :height "100vh" + :width "100vw"}} + [styles] + [scrollbars]] + children))) (defn- inspect-1-history [default-value] (let [current-state @(state/use-state)] [:<> [commands/palette] (doall - (map-indexed - (fn [index state] - ^{:key index} - [s/div - {:style - {:flex "1" - :display - (if (= state current-state) - :block - :none)}} - [select/with-position - {:row 0 :column index} - [inspect-1 (state/get-value state default-value)]]]) - (state/get-history current-state)))])) + (map-indexed + (fn [index state] + ^{:key index} + [s/div + {:style + {:flex "1" + :display + (if (= state current-state) + :block + :none)}} + [select/with-position + {:row 0 :column index} + [inspect-1 (state/get-value state default-value)]]]) + (state/get-history current-state)))])) (def viewers ^{:portal.viewer/default :portal.viewer/table diff --git a/src/portal/ui/cljs.cljs b/src/portal/ui/cljs.cljs index eb8e2e66..14c6dc47 100644 --- a/src/portal/ui/cljs.cljs +++ b/src/portal/ui/cljs.cljs @@ -1,4 +1,5 @@ -(ns ^:no-doc portal.ui.cljs) +(ns portal.ui.cljs + {:no-doc true}) (def eval-fn (atom nil)) diff --git a/src/portal/ui/commands.cljs b/src/portal/ui/commands.cljs index b0aa985d..dd0209d2 100644 --- a/src/portal/ui/commands.cljs +++ b/src/portal/ui/commands.cljs @@ -1,22 +1,23 @@ (ns portal.ui.commands - (:require ["react" :as react] - [clojure.pprint :as pp] - [clojure.set :as set] - [clojure.string :as str] - [clojure.walk :as walk] - [portal.async :as a] - [portal.colors :as c] - [portal.shortcuts :as shortcuts] - [portal.ui.drag-and-drop :as dnd] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.options :as options] - [portal.ui.parsers :as p] - [portal.ui.react :refer [use-effect]] - [portal.ui.state :as state] - [portal.ui.styled :as s] - [portal.ui.theme :as theme] - [reagent.core :as r])) + (:require + ["react" :as react] + [clojure.pprint :as pp] + [clojure.set :as set] + [clojure.string :as str] + [clojure.walk :as walk] + [portal.async :as a] + [portal.colors :as c] + [portal.shortcuts :as shortcuts] + [portal.ui.drag-and-drop :as dnd] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.options :as options] + [portal.ui.parsers :as p] + [portal.ui.react :refer [use-effect]] + [portal.ui.state :as state] + [portal.ui.styled :as s] + [portal.ui.theme :as theme] + [reagent.core :as r])) (def ^:dynamic *state* nil) (defonce ^:private input (r/atom nil)) @@ -32,21 +33,21 @@ (defn- palette-container [& children] (let [theme (theme/use-theme)] (into - [s/div - {:on-click #(.stopPropagation %) - :style - {:font-family (:font-family theme) - :max-height "100%" - :height :fit-content - :margin "0 auto" - :overflow :hidden - :display :flex - :flex-direction :column - :background (::c/background2 theme) - :box-shadow "0 0 10px #0007" - :border [1 :solid (::c/border theme)] - :border-radius (:border-radius theme)}}] - children))) + [s/div + {:on-click #(.stopPropagation %) + :style + {:font-family (:font-family theme) + :max-height "100%" + :height :fit-content + :margin "0 auto" + :overflow :hidden + :display :flex + :flex-direction :column + :background (::c/background2 theme) + :box-shadow "0 0 10px #0007" + :border [1 :solid (::c/border theme)] + :border-radius (:border-radius theme)}}] + children))) (defonce ^:private handlers (atom {})) (def ^:private shortcut-context (react/createContext 0)) @@ -58,15 +59,15 @@ (defn- with-shortcuts [f & children] (let [i (react/useContext shortcut-context)] (use-effect - #js [f] - (swap! handlers assoc i f) - (fn [] - (swap! handlers dissoc i))) + #js [f] + (swap! handlers assoc i f) + (fn [] + (swap! handlers dissoc i))) (use-effect - :always - (shortcuts/add! ::with-shortcuts dispatch) - (fn [] - (shortcuts/remove! ::with-shortcuts))) + :always + (shortcuts/add! ::with-shortcuts dispatch) + (fn [] + (shortcuts/remove! ::with-shortcuts))) (into [:r> (.-Provider shortcut-context) #js {:value (inc i)}] children))) (defn- checkbox [checked?] @@ -99,11 +100,11 @@ (let [el (atom nil)] (fn [] (r/create-class - {:component-did-mount - (fn [] - (when-let [el @el] (.scrollIntoView el #js {:block "center"}))) - :reagent-render - (fn [] [:div {:ref #(reset! el %)}])})))) + {:component-did-mount + (fn [] + (when-let [el @el] (.scrollIntoView el #js {:block "center"}))) + :reagent-render + (fn [] [:div {:ref #(reset! el %)}])})))) (defn- try-sort "Attempts to sort the given selection" @@ -136,20 +137,20 @@ [with-shortcuts (fn [log] (when - (condp shortcuts/match? log - "arrowup" (swap! active #(mod (dec %) n)) - "k" (swap! active #(mod (dec %) n)) - #{"shift" "tab"} (swap! active #(mod (dec %) n)) - "arrowdown" (swap! active #(mod (inc %) n)) - "j" (swap! active #(mod (inc %) n)) - "tab" (swap! active #(mod (inc %) n)) - "a" (on-toggle) - "i" (on-invert) - " " (on-select (nth options @active)) - "enter" (on-done @selected) - "escape" (on-close) - - nil) + (condp shortcuts/match? log + "arrowup" (swap! active #(mod (dec %) n)) + "k" (swap! active #(mod (dec %) n)) + #{"shift" "tab"} (swap! active #(mod (dec %) n)) + "arrowdown" (swap! active #(mod (inc %) n)) + "j" (swap! active #(mod (inc %) n)) + "tab" (swap! active #(mod (inc %) n)) + "a" (on-toggle) + "i" (on-invert) + " " (on-select (nth options @active)) + "enter" (on-done @selected) + "escape" (on-close) + + nil) (shortcuts/matched! log))) [palette-container @@ -183,34 +184,34 @@ {:style {:overflow :auto}} (->> options (map-indexed - (fn [index option] - (let [active? (= index @active)] - [s/div - {:key (hash option) - :on-click (fn [e] - (.stopPropagation e) - (on-select option)) - :style - (merge - {:border-left [5 :solid "#0000"] - :box-sizing :border-box - :padding-left (:padding theme) - :padding-top (* 0.5 (:padding theme)) - :padding-bottom (* 0.5 (:padding theme)) - :cursor :pointer - :color (if (selected? option) - (::c/boolean theme) - (::c/text theme)) - :display :flex - :align-items :center - :height :fit-content} - (when active? - {:border-left [5 :solid (::c/boolean theme)] - :background (::c/background theme)}))} - (when active? [scroll-into-view]) - [checkbox (some? (selected? option))] - [s/div {:style {:width (:padding theme)}}] - [ins/inspector option]]))) + (fn [index option] + (let [active? (= index @active)] + [s/div + {:key (hash option) + :on-click (fn [e] + (.stopPropagation e) + (on-select option)) + :style + (merge + {:border-left [5 :solid "#0000"] + :box-sizing :border-box + :padding-left (:padding theme) + :padding-top (* 0.5 (:padding theme)) + :padding-bottom (* 0.5 (:padding theme)) + :cursor :pointer + :color (if (selected? option) + (::c/boolean theme) + (::c/text theme)) + :display :flex + :align-items :center + :height :fit-content} + (when active? + {:border-left [5 :solid (::c/boolean theme)] + :background (::c/background theme)}))} + (when active? [scroll-into-view]) + [checkbox (some? (selected? option))] + [s/div {:style {:width (:padding theme)}}] + [ins/inspector option]]))) doall)]]])))) (def ^:private client-keymap (r/atom {})) @@ -225,11 +226,11 @@ (defn- find-combos [keymap command] (let [command-name (:name command)] (keep - (fn [[combo f]] - (when (and (= f command-name) - (shortcuts/platform-supported? combo)) - combo)) - keymap))) + (fn [[combo f]] + (when (and (= f command-name) + (shortcuts/platform-supported? combo)) + combo)) + keymap))) (def ^:private shortcut->symbol {"arrowright" [icons/arrow-right {:size "xs"}] @@ -247,16 +248,16 @@ (let [theme (theme/use-theme)] [:<> (drop-last - (interleave - coll - (for [i (-> coll count range)] - ^{:key i} - [s/div - {:style {:box-sizing :border-box - :padding-left (:padding theme) - :padding-right (:padding theme)}} - [s/div {:style {:height "100%" - :border-right [1 :solid (::c/border theme)]}}]])))])) + (interleave + coll + (for [i (-> coll count range)] + ^{:key i} + [s/div + {:style {:box-sizing :border-box + :padding-left (:padding theme) + :padding-right (:padding theme)}} + [s/div {:style {:height "100%" + :border-right [1 :solid (::c/border theme)]}}]])))])) (defn shortcut [command] (let [theme (theme/use-theme) @@ -271,54 +272,54 @@ [:<> {:key (hash combo)} (map-indexed - (fn [index k] - [s/div - {:key index - :style - {:display :flex - :align-items :center - :background "#0002" - :border-radius (:border-radius theme) - :box-sizing :border-box - :padding-top (* 0.25 (:padding theme)) - :padding-bottom (* 0.25 (:padding theme)) - :padding-left (:padding theme) - :padding-right (:padding theme) - :margin-right (* 0.5 (:padding theme)) - :margin-left (* 0.5 (:padding theme))}} - (get shortcut->symbol k (.toUpperCase k))]) - (sort-by combo-order combo))])]])) + (fn [index k] + [s/div + {:key index + :style + {:display :flex + :align-items :center + :background "#0002" + :border-radius (:border-radius theme) + :box-sizing :border-box + :padding-top (* 0.25 (:padding theme)) + :padding-bottom (* 0.25 (:padding theme)) + :padding-left (:padding theme) + :padding-right (:padding theme) + :margin-right (* 0.5 (:padding theme)) + :margin-left (* 0.5 (:padding theme))}} + (get shortcut->symbol k (.toUpperCase k))]) + (sort-by combo-order combo))])]])) (defn- palette-component-item [props & children] (let [theme (theme/use-theme) {:keys [active? on-click]} props] (into - [s/div - {:on-click on-click - :style - (merge - {:border-left [5 :solid "#0000"] - :cursor :pointer - :display :flex - :justify-content :space-between - :align-items :center - :height :fit-content - :box-sizing :border-box - :padding-left (:padding theme) - :padding-top (* 0.5 (:padding theme)) - :padding-bottom (* 0.5 (:padding theme))} - (when active? - {:border-left [5 :solid (::c/boolean theme)] - :background (::c/background theme)})) - :style/hover - {:background (::c/background theme)}}] - children))) + [s/div + {:on-click on-click + :style + (merge + {:border-left [5 :solid "#0000"] + :cursor :pointer + :display :flex + :justify-content :space-between + :align-items :center + :height :fit-content + :box-sizing :border-box + :padding-left (:padding theme) + :padding-top (* 0.5 (:padding theme)) + :padding-bottom (* 0.5 (:padding theme))} + (when active? + {:border-left [5 :solid (::c/boolean theme)] + :background (::c/background theme)})) + :style/hover + {:background (::c/background theme)}}] + children))) (defn- stringify [props option] (pr-str - (if-let [filter-by (:filter-by props)] - (filter-by option) - option))) + (if-let [filter-by (:filter-by props)] + (filter-by option) + option))) (defn- filter-options [props text] (if (str/blank? text) @@ -349,14 +350,14 @@ [with-shortcuts (fn [log] (when - (condp shortcuts/match? log - "arrowup" (swap! active #(mod (dec %) n)) - #{"shift" "tab"} (swap! active #(mod (dec %) n)) - "arrowdown" (swap! active #(mod (inc %) n)) - "tab" (swap! active #(mod (inc %) n)) - "enter" (on-select) - "escape" (on-close) - nil) + (condp shortcuts/match? log + "arrowup" (swap! active #(mod (dec %) n)) + #{"shift" "tab"} (swap! active #(mod (dec %) n)) + "arrowdown" (swap! active #(mod (inc %) n)) + "tab" (swap! active #(mod (inc %) n)) + "enter" (on-select) + "escape" (on-close) + nil) (shortcuts/matched! log))) [palette-container [s/div @@ -386,22 +387,22 @@ :overflow :auto}} (->> options (map-indexed - (fn [index option] - (let [active? (= index @active) - on-click (fn [e] - (.stopPropagation e) - (reset! active index) - (on-select))] - ^{:key index} - [:<> - (when active? [scroll-into-view]) - [palette-component-item - {:active? active? - :on-click on-click} - [component + (fn [index option] + (let [active? (= index @active) + on-click (fn [e] + (.stopPropagation e) + (reset! active index) + (on-select))] + ^{:key index} + [:<> + (when active? [scroll-into-view]) + [palette-component-item {:active? active? :on-click on-click} - option]]]))) + [component + {:active? active? + :on-click on-click} + option]]]))) doall)]]])))) (defn- can-meta? [value] (implements? IWithMeta value)) @@ -427,12 +428,12 @@ (catch :default e (ex-data e)))] (when-not command (state/dispatch! - state - state/history-push - {:portal/key name - :portal/f f - :portal/args args - :portal/value result})))))) + state + state/history-push + {:portal/key name + :portal/f f + :portal/args args + :portal/value result})))))) (defn- command-item [{:keys [active?]} command] (let [theme (theme/use-theme)] @@ -476,25 +477,25 @@ #{"meta" "shift" "p"}]} [state] (a/let [commands (sort-by - :name - (remove - (fn [option] - (or - (#{`open-command-palette} - (:name option)) - (when-let [predicate (:predicate option)] - (not (predicate @state))))) - (vals (get-commands))))] + :name + (remove + (fn [option] + (or + (#{`open-command-palette} + (:name option)) + (when-let [predicate (:predicate option)] + (not (predicate @state))))) + (vals (get-commands))))] (open - state - (fn [state] - [palette-component - {:filter-by :name - :options commands - :component command-item - :on-select - (fn [command] - ((:run command) state))}])))) + state + (fn [state] + [palette-component + {:filter-by :name + :options commands + :component command-item + :on-select + (fn [command] + ((:run command) state))}])))) ;; pick args @@ -502,58 +503,58 @@ ([options] (pick-one *state* options)) ([state options] (js/Promise. - (fn [resolve] - (open - state - (fn [_state] - [palette-component - {:on-select #(resolve [%]) - :options options}])))))) + (fn [resolve] + (open + state + (fn [_state] + [palette-component + {:on-select #(resolve [%]) + :options options}])))))) (defn pick-many ([options] (pick-many *state* options)) ([state options] (js/Promise. - (fn [resolve] - (open - state - (fn [] - (let [state (state/use-state)] - [selector-component - {:options options - :run - (fn [options] - (close state) - (resolve [options]))}]))))))) + (fn [resolve] + (open + state + (fn [] + (let [state (state/use-state)] + [selector-component + {:options options + :run + (fn [options] + (close state) + (resolve [options]))}]))))))) (defn pick-in ([v] (pick-in *state* v)) ([state v] (js/Promise. - (fn [resolve] - (let [get-key - (fn get-key [path v] - (open - state - (fn [_state] - [palette-component - {:options (concat [::done] (keys v)) - :on-select - (fn [k] - (let [path (conj path k) - next-value (get v k)] - (cond - (= k ::done) - (resolve [(drop-last path)]) - - (not (map? next-value)) - (resolve [path]) - - :else - (get-key path next-value))))}])))] - (get-key [] v)))))) + (fn [resolve] + (let [get-key + (fn get-key [path v] + (open + state + (fn [_state] + [palette-component + {:options (concat [::done] (keys v)) + :on-select + (fn [k] + (let [path (conj path k) + next-value (get v k)] + (cond + (= k ::done) + (resolve [(drop-last path)]) + + (not (map? next-value)) + (resolve [path]) + + :else + (get-key path next-value))))}])))] + (get-key [] v)))))) ;; portal data commands @@ -581,13 +582,13 @@ [value] (with-meta (reduce - (fn [m path] - (assoc-in m (reverse path) (get-in value path))) - {} - (for [row (keys value) - column (map-keys value) - :when (contains? (get value row) column)] - [row column])) + (fn [m path] + (assoc-in m (reverse path) (get-in value path))) + {} + (for [row (keys value) + column (map-keys value) + :when (contains? (get value row) column)] + [row column])) (meta value))) (defn select-columns @@ -597,10 +598,10 @@ (cond (map? value) (reduce-kv - (fn [v k m] - (assoc v k (select-keys m ks))) - value - value) + (fn [v k m] + (assoc v k (select-keys m ks))) + value + value) :else (map #(select-keys % ks) value)) (meta value))) @@ -619,12 +620,12 @@ (defn- copy-edn! [value] (copy-to-clipboard! - (str/trim - (with-out-str - (binding [*print-meta* true - *print-length* 1000 - *print-level* 100] - (pp/pprint value)))))) + (str/trim + (with-out-str + (binding [*print-meta* true + *print-length* 1000 + *print-level* 100] + (pp/pprint value)))))) (defn- selected-values [state-val] (let [values (state/selected-values state-val)] @@ -681,11 +682,11 @@ current (:name (ins/get-viewer state (first context)))] (when (> (count viewers) 1) (some - (fn [[prev next]] - (case direction - :prev (when (= next current) prev) - :next (when (= prev current) next))) - (partition 2 1 (conj viewers (last viewers))))))) + (fn [[prev next]] + (case direction + :prev (when (= next current) prev) + :next (when (= prev current) next))) + (partition 2 1 (conj viewers (last viewers))))))) (defn ^:command select-prev-viewer {:shortcuts [#{"shift" "k"} #{"shift" "arrowup"}]} @@ -787,36 +788,36 @@ (a/let [commands (::state/previous-commands @state)] (when (seq commands) (open - (fn [_state] - [palette-component - {:options commands - :filter-by :portal/key - :on-select - (fn [command] - (a/let [k (:portal/key command) - f (or (:portal/f command) - (if (keyword? k) - k - (partial state/invoke (:portal/key command)))) - args (:portal/args command) - value (apply f (state/get-selected-value @state) args)] - (state/dispatch! - state - state/history-push - (assoc command :portal/value value)))) - :component - (fn [command] - [s/div - {:style {:display :flex - :justify-content :space-between - :overflow :hidden - :align-items :center - :text-overflow :ellipsis - :white-space :nowrap}} - [ins/inspector (:portal/key command)] + (fn [_state] + [palette-component + {:options commands + :filter-by :portal/key + :on-select + (fn [command] + (a/let [k (:portal/key command) + f (or (:portal/f command) + (if (keyword? k) + k + (partial state/invoke (:portal/key command)))) + args (:portal/args command) + value (apply f (state/get-selected-value @state) args)] + (state/dispatch! + state + state/history-push + (assoc command :portal/value value)))) + :component + (fn [command] [s/div - {:style {:opacity 0.5}} - (for [a (:portal/args command)] (pr-str a))]])}]))))) + {:style {:display :flex + :justify-content :space-between + :overflow :hidden + :align-items :center + :text-overflow :ellipsis + :white-space :nowrap}} + [ins/inspector (:portal/key command)] + [s/div + {:style {:opacity 0.5}} + (for [a (:portal/args command)] (pr-str a))]])}]))))) (defn ^:command set-theme [state] (a/let [[theme] (pick-one state (keys c/themes))] @@ -927,9 +928,9 @@ value of clojure.core.protocols/nav." [state] (state/dispatch! - state - state/nav - (state/get-selected-context @state))) + state + state/nav + (state/get-selected-context @state))) (register! #'nav {:name 'clojure.datafy/nav :predicate (comp :collection state/get-selected-context)}) @@ -938,9 +939,9 @@ "List all available css variable provided by vs-code." [state] (state/dispatch! - state - state/history-push - {:portal/value (theme/get-vs-code-css-vars)})) + state + state/history-push + {:portal/value (theme/get-vs-code-css-vars)})) (register! #'vs-code-vars {:predicate theme/is-vs-code?}) @@ -962,24 +963,24 @@ (defn- prompt-file [] (js/Promise. - (fn [resolve _reject] - (let [id "open-file-dialog" - input (or - (js/document.getElementById id) - (js/document.createElement "input"))] - (set! (.-id input) id) - (set! (.-type input) "file") - (set! (.-multiple input) "true") - (set! (.-style input) "visibility:hidden") - (.addEventListener - input - "change" - (fn [event] - (a/let [value (dnd/handle-files (-> event .-target .-files))] - (resolve value))) - false) - (js/document.body.appendChild input) - (.click input))))) + (fn [resolve _reject] + (let [id "open-file-dialog" + input (or + (js/document.getElementById id) + (js/document.createElement "input"))] + (set! (.-id input) id) + (set! (.-type input) "file") + (set! (.-multiple input) "true") + (set! (.-style input) "visibility:hidden") + (.addEventListener + input + "change" + (fn [event] + (a/let [value (dnd/handle-files (-> event .-target .-files))] + (resolve value))) + false) + (js/document.body.appendChild input) + (.click input))))) (defn open-file "Open a File" @@ -1045,15 +1046,15 @@ value (state/get-selected-value @state) opts (options/use-options)] (use-effect - #js [(hash value)] - (a/let [fns (state/invoke 'portal.runtime/get-functions value)] - (reset! - runtime-registry - (update-vals - fns - (fn [opts] - (make-command - (assoc opts :f (partial state/invoke (:name opts))))))))) + #js [(hash value)] + (a/let [fns (state/invoke 'portal.runtime/get-functions value)] + (reset! + runtime-registry + (update-vals + fns + (fn [opts] + (make-command + (assoc opts :f (partial state/invoke (:name opts))))))))) [with-shortcuts (fn [log] (when-not (shortcuts/input? log) diff --git a/src/portal/ui/connection_status.cljs b/src/portal/ui/connection_status.cljs index ab8d3783..5f49a002 100644 --- a/src/portal/ui/connection_status.cljs +++ b/src/portal/ui/connection_status.cljs @@ -1,13 +1,15 @@ -(ns ^:no-doc portal.ui.connection-status - (:require [portal.async :as a] - [portal.ui.react :refer [use-effect]] - [portal.ui.state :as state])) +(ns portal.ui.connection-status + {:no-doc true} + (:require + [portal.async :as a] + [portal.ui.react :refer [use-effect]] + [portal.ui.state :as state])) (defn- timeout [ms] (js/Promise. - (fn [_resolve reject] - (js/setTimeout - #(reject (ex-info "Timeout reached" {:duration ms})) ms)))) + (fn [_resolve reject] + (js/setTimeout + #(reject (ex-info "Timeout reached" {:duration ms})) ms)))) (def ^:private poll-interval-ms 5000) @@ -19,21 +21,21 @@ (defn- use-conn-poll [] (let [state (state/use-state)] (use-effect - #js [state] - (let [last-poller (atom nil) - poller (fn poller [] - (a/try - (a/race (state/invoke 'portal.runtime/ping) - (timeout poll-interval-ms)) - (state/dispatch! state state/dismiss disconnect-notification) - (catch :default _ - (state/dispatch! state state/notify disconnect-notification)) - (finally - (when @last-poller - (reset! last-poller (js/setTimeout poller poll-interval-ms))))))] - (reset! last-poller (js/setTimeout poller 0)) - (fn [] - (js/clearTimeout @last-poller) - (reset! last-poller nil)))))) + #js [state] + (let [last-poller (atom nil) + poller (fn poller [] + (a/try + (a/race (state/invoke 'portal.runtime/ping) + (timeout poll-interval-ms)) + (state/dispatch! state state/dismiss disconnect-notification) + (catch :default _ + (state/dispatch! state state/notify disconnect-notification)) + (finally + (when @last-poller + (reset! last-poller (js/setTimeout poller poll-interval-ms))))))] + (reset! last-poller (js/setTimeout poller 0)) + (fn [] + (js/clearTimeout @last-poller) + (reset! last-poller nil)))))) -(defn poller [] (use-conn-poll) nil) \ No newline at end of file +(defn poller [] (use-conn-poll) nil) diff --git a/src/portal/ui/core.cljs b/src/portal/ui/core.cljs index 14115b56..49cb803c 100644 --- a/src/portal/ui/core.cljs +++ b/src/portal/ui/core.cljs @@ -1,27 +1,29 @@ -(ns ^:no-doc portal.ui.core - (:require ["react" :as react] - [portal.async :as a] - [portal.extensions.vs-code-notebook :as notebook] - [portal.ui.api :as api] - [portal.ui.app :as app] - [portal.ui.cljs :as cljs] - [portal.ui.inspector :as ins] - [portal.ui.options :as opts] - [portal.ui.react :refer [use-effect]] - [portal.ui.rpc :as rpc] - [portal.ui.state :as state] - [reagent.core :as r] - [reagent.dom :as dom])) +(ns portal.ui.core + {:no-doc true} + (:require + ["react" :as react] + [portal.async :as a] + [portal.extensions.vs-code-notebook :as notebook] + [portal.ui.api :as api] + [portal.ui.app :as app] + [portal.ui.cljs :as cljs] + [portal.ui.inspector :as ins] + [portal.ui.options :as opts] + [portal.ui.react :refer [use-effect]] + [portal.ui.rpc :as rpc] + [portal.ui.state :as state] + [reagent.core :as r] + [reagent.dom :as dom])) (def functional-compiler (r/create-compiler {:function-components true})) (defn- custom-app [opts] (let [[app set-app!] (react/useState nil)] (use-effect - :once - (a/let [_ (cljs/eval-string {:code (str "(require '" (namespace (:main opts)) ")")}) - res (cljs/eval-string {:code (str (:main opts)) :context :expr})] - (set-app! (fn [] (:value res))))) + :once + (a/let [_ (cljs/eval-string {:code (str "(require '" (namespace (:main opts)) ")")}) + res (cljs/eval-string {:code (str (:main opts)) :context :expr})] + (set-app! (fn [] (:value res))))) (when app [app/root [app]]))) @@ -53,4 +55,4 @@ (defn reload! [] (render-app)) -(set! (.-embed api/portal-api) notebook/activate) \ No newline at end of file +(set! (.-embed api/portal-api) notebook/activate) diff --git a/src/portal/ui/drag_and_drop.cljs b/src/portal/ui/drag_and_drop.cljs index fcca65d8..0486c762 100644 --- a/src/portal/ui/drag_and_drop.cljs +++ b/src/portal/ui/drag_and_drop.cljs @@ -1,28 +1,30 @@ -(ns ^:no-doc portal.ui.drag-and-drop - (:require ["react" :as react] - [clojure.string :as string] - [portal.async :as a] - [portal.ui.parsers :as p] - [portal.ui.state :as state] - [portal.ui.styled :as s] - [portal.viewer :as v])) +(ns portal.ui.drag-and-drop + {:no-doc true} + (:require + ["react" :as react] + [clojure.string :as string] + [portal.async :as a] + [portal.ui.parsers :as p] + [portal.ui.state :as state] + [portal.ui.styled :as s] + [portal.viewer :as v])) (defn read-file ([file] (read-file file :text)) ([file type] (js/Promise. - (fn [resolve reject] - (let [reader (js/window.FileReader.)] - (.addEventListener - reader - "load" - (fn [e] - (resolve (.-result (.-target e))))) - (.addEventListener reader "error" reject) - (case type - :text (.readAsText reader file) - :bin (.readAsArrayBuffer reader file))))))) + (fn [resolve reject] + (let [reader (js/window.FileReader.)] + (.addEventListener + reader + "load" + (fn [e] + (resolve (.-result (.-target e))))) + (.addEventListener reader "error" reject) + (case type + :text (.readAsText reader file) + :bin (.readAsArrayBuffer reader file))))))) (defn- read-binary [file] @@ -84,9 +86,9 @@ (fn [e] (.preventDefault e) (a/let [value (handle-files - (for [item (.items (.-dataTransfer e)) - :when (= (.-kind item) "file")] - (.getAsFile item)))] + (for [item (.items (.-dataTransfer e)) + :when (= (.-kind item) "file")] + (.getAsFile item)))] (state/dispatch! state state/history-push {:portal/value value})) (set-active! false)) :style {:position :relative}} @@ -124,4 +126,4 @@ :on-drag-leave (fn [_e] (set-active! false))}]]) - children])) \ No newline at end of file + children])) diff --git a/src/portal/ui/embed.cljs b/src/portal/ui/embed.cljs index 852c3822..7756fe5c 100644 --- a/src/portal/ui/embed.cljs +++ b/src/portal/ui/embed.cljs @@ -1,15 +1,17 @@ -(ns ^:no-doc portal.ui.embed - (:require [portal.colors :as c] - [portal.ui.app :as app] - [portal.ui.commands :as commands] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.options :as opts] - [portal.ui.select :as select] - [portal.ui.state :as state] - [portal.ui.styled :as s] - [portal.ui.theme :as theme] - [reagent.core :as r])) +(ns portal.ui.embed + {:no-doc true} + (:require + [portal.colors :as c] + [portal.ui.app :as app] + [portal.ui.commands :as commands] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.options :as opts] + [portal.ui.select :as select] + [portal.ui.state :as state] + [portal.ui.styled :as s] + [portal.ui.theme :as theme] + [reagent.core :as r])) (defn- open-external [{:keys [value on-click]}] (let [theme (theme/use-theme) @@ -25,11 +27,11 @@ (fn open-editor [e] (.stopPropagation e) (on-click - (let [values (state/selected-values @state)] - (case (count values) - 0 value - 1 (first values) - values))))}]))) + (let [values (state/selected-values @state)] + (case (count values) + 0 value + 1 (first values) + values))))}]))) (defn- history-arrow [{:keys [icon title on-click enabled]}] (let [state (state/use-state) @@ -41,13 +43,13 @@ :size "1x" :on-click #(state/dispatch! state on-click) :style (merge - {:cursor :pointer - :padding (:padding theme) - :color (::c/text theme) - :box-sizing :content-box} - (when disabled? - {:opacity 0.45 - :cursor :default}))}])) + {:cursor :pointer + :padding (:padding theme) + :color (::c/text theme) + :box-sizing :content-box} + (when disabled? + {:opacity 0.45 + :cursor :default}))}])) (defn command-button [] (let [state (state/use-state) @@ -70,14 +72,14 @@ :position :relative :min-height (* 2 (:padding theme))}} (into - [s/div - {:style - {:right (* 2 (:padding theme)) - :width :fit-content - :position :absolute - :border [1 :solid (::c/border theme)] - :background (::c/background theme)}}] - children)])) + [s/div + {:style + {:right (* 2 (:padding theme)) + :width :fit-content + :position :absolute + :border [1 :solid (::c/border theme)] + :background (::c/background theme)}}] + children)])) (defn command-container [child] (let [state (state/use-state)] @@ -116,9 +118,9 @@ :on-change (fn [e] (ins/set-viewer! - state - selected-context - (keyword (subs (.. e -target -value) 1))))} + state + selected-context + (keyword (subs (.. e -target -value) 1))))} (for [{:keys [name]} compatible-viewers] ^{:key name} [s/option {:value (pr-str name)} (pr-str name)])] diff --git a/src/portal/ui/filter.cljc b/src/portal/ui/filter.cljc index a90c0056..282d4f52 100644 --- a/src/portal/ui/filter.cljc +++ b/src/portal/ui/filter.cljc @@ -1,6 +1,8 @@ -(ns ^:no-doc portal.ui.filter - (:require [clojure.string :as str] - #?(:cljs [portal.ui.rpc.runtime :as rt]))) +(ns portal.ui.filter + {:no-doc true} + (:require + [clojure.string :as str] + #?(:cljs [portal.ui.rpc.runtime :as rt]))) #?(:clj (defn regexp? [value] (instance? java.util.regex.Pattern value))) @@ -20,15 +22,15 @@ (map? value) (some - (fn [[k v]] - (or (match* k pattern) (match* v pattern))) - value) + (fn [[k v]] + (or (match* k pattern) (match* v pattern))) + value) (coll? value) (some - (fn [v] - (match* v pattern)) - value) + (fn [v] + (match* v pattern)) + value) :else false)) @@ -57,14 +59,14 @@ (cond (map? value) (persistent! - (reduce-kv - (fn [result k v] - (if-not (or (matcher k) - (matcher v)) - result - (assoc! result k v))) - (transient {}) - value)) + (reduce-kv + (fn [result k v] + (if-not (or (matcher k) + (matcher v)) + result + (assoc! result k v))) + (transient {}) + value)) (or (seq? value) (list? value)) (filter matcher value) @@ -94,20 +96,20 @@ (seq (persistent! out)) (let [search-words (keep - (fn [{:keys [substring] :as search-word}] - (when-let [start (re-index (->pattern substring) s i)] - (let [end (+ start (count substring))] - (assoc search-word :start start :end end)))) - search-words)] + (fn [{:keys [substring] :as search-word}] + (when-let [start (re-index (->pattern substring) s i)] + (let [end (+ start (count substring))] + (assoc search-word :start start :end end)))) + search-words)] (if-let [{:keys [start end] :as entry} (first (sort-by :start search-words))] (recur - (long end) - search-words - (cond-> out - (not= start i) (conj! {:start i :end start}) - :always (conj! entry))) + (long end) + search-words + (cond-> out + (not= start i) (conj! {:start i :end start}) + :always (conj! entry))) (recur - string-length - search-words - (conj! out {:start i :end string-length})))))))) + string-length + search-words + (conj! out {:start i :end string-length})))))))) diff --git a/src/portal/ui/html.cljs b/src/portal/ui/html.cljs index e19f42b1..62afffb1 100644 --- a/src/portal/ui/html.cljs +++ b/src/portal/ui/html.cljs @@ -1,15 +1,17 @@ -(ns ^:no-doc portal.ui.html - (:require [clojure.string :as str] - [portal.ui.inspector :as ins])) +(ns portal.ui.html + {:no-doc true} + (:require + [clojure.string :as str] + [portal.ui.inspector :as ins])) (defn- ->style [string] (persistent! - (reduce - (fn [style rule] - (let [[k v] (str/split rule #":")] - (assoc! style (keyword (str/trim k)) (str/trim v)))) - (transient {}) - (str/split string #";")))) + (reduce + (fn [style rule] + (let [[k v] (str/split rule #":")] + (assoc! style (keyword (str/trim k)) (str/trim v)))) + (transient {}) + (str/split string #";")))) (defn- dom->hiccup [opts ^js el] (let [{:keys [text-handler]} opts] @@ -19,19 +21,19 @@ text-handler) 1 (let [attrs (.-attributes el)] (into - [(keyword (str/lower-case (.-tagName el))) - (persistent! - (reduce - (fn [attrs ^js attr] - (let [k (keyword (.-name attr))] - (assoc! attrs k - (case k - :style (->style (.-value attr)) - (.-value attr))))) - (transient {}) - attrs))] - (map (partial dom->hiccup opts)) - (.-childNodes el)))))) + [(keyword (str/lower-case (.-tagName el))) + (persistent! + (reduce + (fn [attrs ^js attr] + (let [k (keyword (.-name attr))] + (assoc! attrs k + (case k + :style (->style (.-value attr)) + (.-value attr))))) + (transient {}) + attrs))] + (map (partial dom->hiccup opts)) + (.-childNodes el)))))) (defn- parse-dom [string] (-> (js/DOMParser.) @@ -52,4 +54,4 @@ {:text-handler (fn [text] [ins/highlight-words text])}) -(defn html+ [html] (parse-html html opts)) \ No newline at end of file +(defn html+ [html] (parse-html html opts)) diff --git a/src/portal/ui/icons.cljs b/src/portal/ui/icons.cljs index f1593d53..b85b95d5 100644 --- a/src/portal/ui/icons.cljs +++ b/src/portal/ui/icons.cljs @@ -1,37 +1,38 @@ (ns portal.ui.icons - (:require ["@fortawesome/free-solid-svg-icons/faArrowDown" :refer [faArrowDown]] - ["@fortawesome/free-solid-svg-icons/faArrowLeft" :refer [faArrowLeft]] - ["@fortawesome/free-solid-svg-icons/faArrowRight" :refer [faArrowRight]] - ["@fortawesome/free-solid-svg-icons/faArrowUp" :refer [faArrowUp]] - ["@fortawesome/free-solid-svg-icons/faAt" :refer [faAt]] - ["@fortawesome/free-solid-svg-icons/faBan" :refer [faBan]] - ["@fortawesome/free-solid-svg-icons/faCaretDown" :refer [faCaretDown]] - ["@fortawesome/free-solid-svg-icons/faCaretLeft" :refer [faCaretLeft]] - ["@fortawesome/free-solid-svg-icons/faCaretRight" :refer [faCaretRight]] - ["@fortawesome/free-solid-svg-icons/faCaretUp" :refer [faCaretUp]] - ["@fortawesome/free-solid-svg-icons/faCheckCircle" :refer [faCheckCircle]] - ["@fortawesome/free-solid-svg-icons/faChevronDown" :refer [faChevronDown]] - ["@fortawesome/free-solid-svg-icons/faChevronRight" :refer [faChevronRight]] - ["@fortawesome/free-solid-svg-icons/faCircle" :refer [faCircle]] - ["@fortawesome/free-solid-svg-icons/faCopy" :refer [faCopy]] - ["@fortawesome/free-solid-svg-icons/faEllipsisH" :refer [faEllipsisH]] - ["@fortawesome/free-solid-svg-icons/faExchangeAlt" :refer [faExchangeAlt]] - ["@fortawesome/free-solid-svg-icons/faExclamationTriangle" :refer [faExclamationTriangle]] - ["@fortawesome/free-solid-svg-icons/faExternalLinkAlt" :refer [faExternalLinkAlt]] - ["@fortawesome/free-solid-svg-icons/faFileCode" :refer [faFileCode]] - ["@fortawesome/free-solid-svg-icons/faInfoCircle" :refer [faInfoCircle]] - ["@fortawesome/free-solid-svg-icons/faMinusCircle" :refer [faMinusCircle]] - ["@fortawesome/free-solid-svg-icons/faPause" :refer [faPause]] - ["@fortawesome/free-solid-svg-icons/faPlay" :refer [faPlay]] - ["@fortawesome/free-solid-svg-icons/faPlayCircle" :refer [faPlayCircle]] - ["@fortawesome/free-solid-svg-icons/faPlusCircle" :refer [faPlusCircle]] - ["@fortawesome/free-solid-svg-icons/faSignOutAlt" :refer [faSignOutAlt]] - ["@fortawesome/free-solid-svg-icons/faStopCircle" :refer [faStopCircle]] - ["@fortawesome/free-solid-svg-icons/faTerminal" :refer [faTerminal]] - ["@fortawesome/free-solid-svg-icons/faTimes" :refer [faTimes]] - ["@fortawesome/free-solid-svg-icons/faTimesCircle" :refer [faTimesCircle]] - ["@fortawesome/react-fontawesome" :refer [FontAwesomeIcon]] - [portal.ui.styled :as d])) + (:require + ["@fortawesome/free-solid-svg-icons/faArrowDown" :refer [faArrowDown]] + ["@fortawesome/free-solid-svg-icons/faArrowLeft" :refer [faArrowLeft]] + ["@fortawesome/free-solid-svg-icons/faArrowRight" :refer [faArrowRight]] + ["@fortawesome/free-solid-svg-icons/faArrowUp" :refer [faArrowUp]] + ["@fortawesome/free-solid-svg-icons/faAt" :refer [faAt]] + ["@fortawesome/free-solid-svg-icons/faBan" :refer [faBan]] + ["@fortawesome/free-solid-svg-icons/faCaretDown" :refer [faCaretDown]] + ["@fortawesome/free-solid-svg-icons/faCaretLeft" :refer [faCaretLeft]] + ["@fortawesome/free-solid-svg-icons/faCaretRight" :refer [faCaretRight]] + ["@fortawesome/free-solid-svg-icons/faCaretUp" :refer [faCaretUp]] + ["@fortawesome/free-solid-svg-icons/faCheckCircle" :refer [faCheckCircle]] + ["@fortawesome/free-solid-svg-icons/faChevronDown" :refer [faChevronDown]] + ["@fortawesome/free-solid-svg-icons/faChevronRight" :refer [faChevronRight]] + ["@fortawesome/free-solid-svg-icons/faCircle" :refer [faCircle]] + ["@fortawesome/free-solid-svg-icons/faCopy" :refer [faCopy]] + ["@fortawesome/free-solid-svg-icons/faEllipsisH" :refer [faEllipsisH]] + ["@fortawesome/free-solid-svg-icons/faExchangeAlt" :refer [faExchangeAlt]] + ["@fortawesome/free-solid-svg-icons/faExclamationTriangle" :refer [faExclamationTriangle]] + ["@fortawesome/free-solid-svg-icons/faExternalLinkAlt" :refer [faExternalLinkAlt]] + ["@fortawesome/free-solid-svg-icons/faFileCode" :refer [faFileCode]] + ["@fortawesome/free-solid-svg-icons/faInfoCircle" :refer [faInfoCircle]] + ["@fortawesome/free-solid-svg-icons/faMinusCircle" :refer [faMinusCircle]] + ["@fortawesome/free-solid-svg-icons/faPause" :refer [faPause]] + ["@fortawesome/free-solid-svg-icons/faPlay" :refer [faPlay]] + ["@fortawesome/free-solid-svg-icons/faPlayCircle" :refer [faPlayCircle]] + ["@fortawesome/free-solid-svg-icons/faPlusCircle" :refer [faPlusCircle]] + ["@fortawesome/free-solid-svg-icons/faSignOutAlt" :refer [faSignOutAlt]] + ["@fortawesome/free-solid-svg-icons/faStopCircle" :refer [faStopCircle]] + ["@fortawesome/free-solid-svg-icons/faTerminal" :refer [faTerminal]] + ["@fortawesome/free-solid-svg-icons/faTimes" :refer [faTimes]] + ["@fortawesome/free-solid-svg-icons/faTimesCircle" :refer [faTimesCircle]] + ["@fortawesome/react-fontawesome" :refer [FontAwesomeIcon]] + [portal.ui.styled :as d])) (defn icon [icon props] [:> FontAwesomeIcon (d/attrs->css (merge {:icon icon :size "lg"} props))]) @@ -66,4 +67,4 @@ (def stop-circle (partial icon faStopCircle)) (def terminal (partial icon faTerminal)) (def times-circle (partial icon faTimesCircle)) -(def times (partial icon faTimes)) \ No newline at end of file +(def times (partial icon faTimes)) diff --git a/src/portal/ui/inspector.cljs b/src/portal/ui/inspector.cljs index ae96683a..4765249b 100644 --- a/src/portal/ui/inspector.cljs +++ b/src/portal/ui/inspector.cljs @@ -1,25 +1,27 @@ (ns portal.ui.inspector - (:refer-clojure :exclude [coll? map? char?]) - (:require ["anser" :as anser] - ["react" :as react] - [clojure.set :as set] - [clojure.string :as str] - [portal.async :as a] - [portal.colors :as c] - [portal.runtime.cson :as cson] - [portal.runtime.edn :as edn] - [portal.ui.api :as api] - [portal.ui.filter :as f] - [portal.ui.icons :as icons] - [portal.ui.lazy :as l] - [portal.ui.react :refer [use-effect]] - [portal.ui.rpc.runtime :as rt] - [portal.ui.select :as select] - [portal.ui.state :as state] - [portal.ui.styled :as s] - [portal.ui.theme :as theme] - [reagent.core :as r]) - (:import [goog.math Long])) + (:refer-clojure :exclude [char? coll? map?]) + (:require + ["anser" :as anser] + ["react" :as react] + [clojure.set :as set] + [clojure.string :as str] + [portal.async :as a] + [portal.colors :as c] + [portal.runtime.cson :as cson] + [portal.runtime.edn :as edn] + [portal.ui.api :as api] + [portal.ui.filter :as f] + [portal.ui.icons :as icons] + [portal.ui.lazy :as l] + [portal.ui.react :refer [use-effect]] + [portal.ui.rpc.runtime :as rt] + [portal.ui.select :as select] + [portal.ui.state :as state] + [portal.ui.styled :as s] + [portal.ui.theme :as theme] + [reagent.core :as r]) + (:import + (goog.math Long))) (declare inspector*) (declare inspector) @@ -44,13 +46,13 @@ (defn error->data [ex] (merge - (when-let [data (.-data ex)] - {:data data}) - {:runtime :portal - :cause (.-message ex) - :via [{:type (symbol (.-name (type ex))) - :message (.-message ex)}] - :stack (.-stack ex)})) + (when-let [data (.-data ex)] + {:data data}) + {:runtime :portal + :cause (.-message ex) + :via [{:type (symbol (.-name (type ex))) + :message (.-message ex)}] + :stack (.-stack ex)})) (defn- inspect-error [error] (let [theme (theme/use-theme)] @@ -76,19 +78,19 @@ (def error-boundary (r/create-class - {:display-name "ErrorBoundary" - :constructor - (fn [this _props] - (set! (.-state this) #js {:error nil})) - :component-did-catch - (fn [_this _e _info]) - :get-derived-state-from-error - (fn [error] #js {:error error}) - :render - (fn [this] - (if-let [error (.. this -state -error)] - (r/as-element [inspect-error* error]) - (.. this -props -children)))})) + {:display-name "ErrorBoundary" + :constructor + (fn [this _props] + (set! (.-state this) #js {:error nil})) + :component-did-catch + (fn [_this _e _info]) + :get-derived-state-from-error + (fn [error] #js {:error error}) + :render + (fn [this] + (if-let [error (.. this -state -error)] + (r/as-element [inspect-error* error]) + (.. this -props -children)))})) (defonce viewers api/viewers) @@ -186,8 +188,8 @@ (defn with-context [value & children] (let [context (use-context)] (into - [:r> (.-Provider inspector-context) - #js {:value (merge context value)}] children))) + [:r> (.-Provider inspector-context) + #js {:value (merge context value)}] children))) (defn with-default-viewer [viewer & children] (into [with-context {:portal.viewer/default viewer}] children)) @@ -274,20 +276,20 @@ (defn- all-locations [state context] (let [search-text (:search-text @state)] (seq - (reduce-kv - (fn [out location search-text] - (if-not (child? location context) - out - (into - out - (keep - (fn [substring] - (when-not (str/blank? substring) - {:substring substring - :context (-> location meta :context)})) - (str/split search-text #"\s+"))))) - [] - search-text)))) + (reduce-kv + (fn [out location search-text] + (if-not (child? location context) + out + (into + out + (keep + (fn [substring] + (when-not (str/blank? substring) + {:substring substring + :context (-> location meta :context)})) + (str/split search-text #"\s+"))))) + [] + search-text)))) (defn- use-search-words [] (let [state (state/use-state) @@ -430,23 +432,23 @@ (when-not (:readonly? context) [s/div (merge - {:title - (if expanded? - "Click to collapse value. - SPACE | E" - "Click to expand value. - SPACE | E") - :style - (merge - {:cursor :pointer - :display :flex - :align-items :center - :color (::c/border theme)} - style) - :style/hover {:color color} - :on-click (fn [e] - (.stopPropagation e) - (if (.-shiftKey e) - (state/dispatch! state state/expand-inc-1 context) - (state/dispatch! state state/toggle-expand-1 context)))}) + {:title + (if expanded? + "Click to collapse value. - SPACE | E" + "Click to expand value. - SPACE | E") + :style + (merge + {:cursor :pointer + :display :flex + :align-items :center + :color (::c/border theme)} + style) + :style/hover {:color color} + :on-click (fn [e] + (.stopPropagation e) + (if (.-shiftKey e) + (state/dispatch! state state/expand-inc-1 context) + (state/dispatch! state state/toggle-expand-1 context)))}) (if expanded? [icons/caret-down] [icons/caret-right])]))) @@ -487,9 +489,9 @@ (let [[show-meta? set-show-meta!] (react/useState false) theme (theme/use-theme) metadata (dissoc - (meta values) - :portal.runtime/id - :portal.runtime/type)] + (meta values) + :portal.runtime/id + :portal.runtime/type)] [s/div {:style {:border [1 :solid (::c/border theme)] @@ -609,8 +611,8 @@ (let [m (meta value)] (when-let [viewer (get-in m [:portal.viewer/for k])] (merge - (select-keys m [viewer]) - {:portal.viewer/default viewer})))) + (select-keys m [viewer]) + {:portal.viewer/default viewer})))) (defn use-search-text [] (let [state (state/use-state) @@ -625,24 +627,24 @@ [container-map [l/lazy-seq (keep-indexed - (fn [index [k v]] - (when (or (matcher k) (matcher v)) - ^{:key (str (->id k) (->id v))} - [:<> - [select/with-position - {:row index :column 0} - [with-context - {:key? true} - [container-map-k - [inspector - {:map-ns map-ns} - k]]]] - [select/with-position - {:row index :column 1} - [with-key k - [container-map-v - [inspector (get-props values k) v]]]]])) - sorted-values)]])) + (fn [index [k v]] + (when (or (matcher k) (matcher v)) + ^{:key (str (->id k) (->id v))} + [:<> + [select/with-position + {:row index :column 0} + [with-context + {:key? true} + [container-map-k + [inspector + {:map-ns map-ns} + k]]]] + [select/with-position + {:row index :column 1} + [with-key k + [container-map-v + [inspector (get-props values k) v]]]]])) + sorted-values)]])) (defn inspect-map-k-v [values] (let [map-ns (:map-ns (use-options))] @@ -701,17 +703,17 @@ values [l/lazy-seq (keep-indexed - (fn [index value] - (when (matcher value) - (let [key (str (if (vector? values) - index - (- n index 1)) - (->id value))] - ^{:key key} - [select/with-position - {:row index :column 0} - [with-key index [inspector value]]]))) - values)]])) + (fn [index value] + (when (matcher value) + (let [key (str (if (vector? values) + index + (- n index 1)) + (->id value))] + ^{:key key} + [select/with-position + {:row index :column 0} + [with-key index [inspector value]]]))) + values)]])) (defn- inspect-coll [values] (let [search-text (use-search-text)] @@ -723,14 +725,14 @@ (defn- ->map [entries] (persistent! - (reduce - (fn [m entry] - (let [k (aget entry 0)] - (if (str/starts-with? k "closure_uid") - m - (assoc! m (keyword k) (aget entry 1))))) - (transient {}) - entries))) + (reduce + (fn [m entry] + (let [k (aget entry 0)] + (if (str/starts-with? k "closure_uid") + m + (assoc! m (keyword k) (aget entry 1))))) + (transient {}) + entries))) (defn- inspect-js-object [value] (let [v (->map (.entries js/Object value))] @@ -918,7 +920,7 @@ (= inspect-object (get-inspect-component - (get-value-type v))) + (get-value-type v))) [inspect-unreadable string] :else [inspector* context v])) @@ -1015,12 +1017,12 @@ (a/do (set-viewer! state [context] (:name viewer)) (state/dispatch! - state - (if selected - state/deselect-context - state/select-context) - context - (or (.-metaKey e) (.-altKey e))))) + state + (if selected + state/deselect-context + state/select-context) + context + (or (.-metaKey e) (.-altKey e))))) :on-double-click (fn [e] (.stopPropagation e) @@ -1065,49 +1067,49 @@ [s/div {:style (merge - {:position :absolute - :pointer-events :none - :top 0 - :left 0 - :right 0 - :bottom 0 - :z-index 2 - :transition transition} - (when (and selected (not hover)) - {:box-shadow [0 0 3 color]}) - (cond - (and selected hover) - {:border-top-right-radius (:border-radius theme) - :border-bottom-right-radius (:border-radius theme) - :border [1 :solid color]} - selected - {:border-radius (:border-radius theme) - :border [1 :solid color]} - :else - {:border-radius (:border-radius theme) - :border [1 :solid "rgba(0,0,0,0)"]}))}] + {:position :absolute + :pointer-events :none + :top 0 + :left 0 + :right 0 + :bottom 0 + :z-index 2 + :transition transition} + (when (and selected (not hover)) + {:box-shadow [0 0 3 color]}) + (cond + (and selected hover) + {:border-top-right-radius (:border-radius theme) + :border-bottom-right-radius (:border-radius theme) + :border [1 :solid color]} + selected + {:border-radius (:border-radius theme) + :border [1 :solid color]} + :else + {:border-radius (:border-radius theme) + :border [1 :solid "rgba(0,0,0,0)"]}))}] [s/div {:style (merge - {:position :absolute - :pointer-events :none - :z-index 2 - :left (- (dec (:padding theme))) - :top 0 - :bottom 0 - :border-radius (:border-radius theme) - :transition transition} - (when selected - {:right 0 - :top 0 - :bottom 0}) - (when-not selected - {:opacity 0.85}) - (when (and selected hover) - {:box-shadow [0 0 3 (get theme (nth theme/order (:depth context)))]}) - (if-not hover - {:border-left [(- (:padding theme) 1) :solid "rgba(0,0,0,0)"]} - {:border-left [(- (:padding theme) 1) :solid color]}))}]])) + {:position :absolute + :pointer-events :none + :z-index 2 + :left (- (dec (:padding theme))) + :top 0 + :bottom 0 + :border-radius (:border-radius theme) + :transition transition} + (when selected + {:right 0 + :top 0 + :bottom 0}) + (when-not selected + {:opacity 0.85}) + (when (and selected hover) + {:box-shadow [0 0 3 (get theme (nth theme/order (:depth context)))]}) + (if-not hover + {:border-left [(- (:padding theme) 1) :solid "rgba(0,0,0,0)"]} + {:border-left [(- (:padding theme) 1) :solid color]}))}]])) (defn wrapper [context & children] (let [theme (theme/use-theme) @@ -1115,25 +1117,25 @@ wrapper-options (use-wrapper-options context) background (get-background context)] (into - [s/div - (merge - wrapper-options - {:ref ref - :title (-> value meta :doc) - :on-mouse-over - (fn [e] - (.stopPropagation e) - (reset! hover? context)) - :style - {:position :relative - :z-index 0 - :flex "1" - :font-family (:font-family theme) - :border [1 :solid "rgba(0,0,0,0)"] - :background (when selected background)}}) - ^{:key "inspector-border"} [inspector-border context] - ^{:key "multi-select-counter"} [multi-select-counter context]] - children))) + [s/div + (merge + wrapper-options + {:ref ref + :title (-> value meta :doc) + :on-mouse-over + (fn [e] + (.stopPropagation e) + (reset! hover? context)) + :style + {:position :relative + :z-index 0 + :flex "1" + :font-family (:font-family theme) + :border [1 :solid "rgba(0,0,0,0)"] + :background (when selected background)}}) + ^{:key "inspector-border"} [inspector-border context] + ^{:key "multi-select-counter"} [multi-select-counter context]] + children))) (defn- inspector* [context value] (let [ref (react/useRef nil) @@ -1146,26 +1148,26 @@ options (assoc options :ref ref :props props) type (get-value-type value) component (or - (when-not (= (:name viewer) :portal.viewer/inspector) - (:component viewer)) - (if expanded? - (get-inspect-component type) - (get-preview-component type)))] + (when-not (= (:name viewer) :portal.viewer/inspector) + (:component viewer)) + (if expanded? + (get-inspect-component type) + (get-preview-component type)))] (select/use-register-context context viewer) (use-effect - #js [(hash location) (some? expanded?)] - (when (and (nil? expanded?) - (default-expand? state theme context value)) - (state/dispatch! - state assoc-in [:expanded? location] - (get-in (meta value) [:portal.viewer/inspector :expanded] 1)))) + #js [(hash location) (some? expanded?)] + (when (and (nil? expanded?) + (default-expand? state theme context value)) + (state/dispatch! + state assoc-in [:expanded? location] + (get-in (meta value) [:portal.viewer/inspector :expanded] 1)))) (use-effect - #js [selected (.-current ref)] - (when (and selected - (not= (.. js/document -activeElement -tagName) "INPUT")) - (when-let [el (.-current ref)] - (when-not (and (.hasFocus js/document) (l/element-visible? el)) - (.scrollIntoView el #js {:inline "nearest" :block "nearest" :behavior "smooth"}))))) + #js [selected (.-current ref)] + (when (and selected + (not= (.. js/document -activeElement -tagName) "INPUT")) + (when-let [el (.-current ref)] + (when-not (and (.hasFocus js/document) (l/element-visible? el)) + (.scrollIntoView el #js {:inline "nearest" :block "nearest" :behavior "smooth"}))))) [:> error-boundary [with-options options [(get-in props [:portal.viewer/inspector :wrapper] wrapper) @@ -1179,9 +1181,9 @@ state (state/use-state) selected @(r/track is-selected? state context)] (use-effect - #js [selected (.-current ref)] - (when (and selected (.hasFocus js/document)) - (some-> ref .-current (.focus #js {:preventScroll true})))) + #js [selected (.-current ref)] + (when (and selected (.hasFocus js/document)) + (some-> ref .-current (.focus #js {:preventScroll true})))) (when-not (:readonly? context) [s/div {:ref ref @@ -1200,10 +1202,10 @@ ([props value] (let [context (cond-> - (-> (use-context) - (assoc :value value) - (update :depth inc) - (assoc :parent (use-parent))) + (-> (use-context) + (assoc :value value) + (update :depth inc) + (assoc :parent (use-parent))) (get-in props [:portal.viewer/inspector :toggle-bg] true) (update :alt-bg not) props diff --git a/src/portal/ui/lazy.cljc b/src/portal/ui/lazy.cljc index 7e6e06e2..115de3ef 100644 --- a/src/portal/ui/lazy.cljc +++ b/src/portal/ui/lazy.cljc @@ -1,3 +1,4 @@ -(ns ^:no-doc portal.ui.lazy) +(ns portal.ui.lazy + {:no-doc true}) (defmacro use-lazy [k value] `(use-lazy* ~k (fn [] ~value))) diff --git a/src/portal/ui/lazy.cljs b/src/portal/ui/lazy.cljs index 88f55491..ad8fa977 100644 --- a/src/portal/ui/lazy.cljs +++ b/src/portal/ui/lazy.cljs @@ -1,32 +1,35 @@ -(ns ^:no-doc portal.ui.lazy +(ns portal.ui.lazy + {:no-doc true} (:refer-clojure :exclude [lazy-seq]) - (:require ["react" :as react] - [portal.ui.react :refer [use-effect]] - [portal.ui.state :as state] - [reagent.core :as r]) - (:require-macros portal.ui.lazy)) + (:require-macros + [portal.ui.lazy]) + (:require + ["react" :as react] + [portal.ui.react :refer [use-effect]] + [portal.ui.state :as state] + [reagent.core :as r])) (defn- observer-visible? [entries] (< 0.5 (reduce - (fn [sum entry] - (if-not (.-isIntersecting entry) - sum - (+ sum (.-intersectionRatio entry)))) 0 entries))) + (fn [sum entry] + (if-not (.-isIntersecting entry) + sum + (+ sum (.-intersectionRatio entry)))) 0 entries))) (defn- observer-visible-sensor [f] (let [ref (react/useRef nil)] (use-effect - #js [(.-current ref) f] - (when (.-current ref) - (let [observer - (js/IntersectionObserver. - (fn [entries] - (when (observer-visible? entries) (f))) - #js {:root nil :rootMargin "0px" :threshold 0.5})] - (.observe observer (.-current ref)) - (fn [] - (when (.-current ref) - (.unobserve observer (.-current ref))))))) + #js [(.-current ref) f] + (when (.-current ref) + (let [observer + (js/IntersectionObserver. + (fn [entries] + (when (observer-visible? entries) (f))) + #js {:root nil :rootMargin "0px" :threshold 0.5})] + (.observe observer (.-current ref)) + (fn [] + (when (.-current ref) + (.unobserve observer (.-current ref))))))) [:div {:ref ref :style {:height "0.5em" :width "0.5em"}}])) (defn element-visible? [element] @@ -45,16 +48,16 @@ (let [ref (react/useRef nil) container (:scroll-element @(state/use-state))] (use-effect - #js [(.-current ref) f container] - (when (some-> ref .-current element-visible?) - (f)) - (when container - (let [on-scroll - (fn [] - (when (some-> ref .-current element-visible?) - (f)))] - (.addEventListener ^js container "scroll" on-scroll) - #(.removeEventListener ^js container "scroll" on-scroll)))) + #js [(.-current ref) f container] + (when (some-> ref .-current element-visible?) + (f)) + (when container + (let [on-scroll + (fn [] + (when (some-> ref .-current element-visible?) + (f)))] + (.addEventListener ^js container "scroll" on-scroll) + #(.removeEventListener ^js container "scroll" on-scroll)))) [:div {:ref ref :style {:height "0.5em" :width "0.5em"}}])) (defn- visible-sensor [f] diff --git a/src/portal/ui/load.cljs b/src/portal/ui/load.cljs index 6e4500c3..5f9021cb 100644 --- a/src/portal/ui/load.cljs +++ b/src/portal/ui/load.cljs @@ -1,4 +1,5 @@ -(ns ^:no-doc portal.ui.load) +(ns portal.ui.load + {:no-doc true}) (defn- module-wrapper "https://nodejs.org/api/modules.html#the-module-wrapper" @@ -22,10 +23,10 @@ (.send xhr (pr-str m)) #_(.timeEnd js/console _label) (some-> - (.parse js/JSON (.-responseText xhr)) - (js->clj :keywordize-keys true) - (update :lang keyword) - (assoc :name (:name m))))) + (.parse js/JSON (.-responseText xhr)) + (js->clj :keywordize-keys true) + (update :lang keyword) + (assoc :name (:name m))))) (def ^:private require-cache (atom {})) @@ -33,33 +34,33 @@ (defn load-require-cache [modules] (swap! - require-cache - (fn [cache] - (reduce-kv - (fn [cache module-name export] - (assoc cache module-name (Module. export))) - cache - modules)))) + require-cache + (fn [cache] + (reduce-kv + (fn [cache module-name export] + (assoc cache module-name (Module. export))) + cache + modules)))) (defn node-require ([module] (node-require nil module)) ([parent module-name] (or - (some-> ^Module (get @require-cache module-name) .-exports) - (try - (let [{:keys [file] :as value} (load-fn-sync {:npm true :name module-name :parent parent})] - (if-let [^Module module (get @require-cache file)] - (.-exports module) - (let [exports #js {} - module-obj (Module. exports)] - (swap! require-cache assoc file module-obj) - ((js/eval (module-wrapper value)) - exports #(node-require (:dir value) %) module-obj (:file value) (:dir value)) - (.-exports module-obj)))) - (catch :default e - (.error js/console e) - (throw e)))))) + (some-> ^Module (get @require-cache module-name) .-exports) + (try + (let [{:keys [file] :as value} (load-fn-sync {:npm true :name module-name :parent parent})] + (if-let [^Module module (get @require-cache file)] + (.-exports module) + (let [exports #js {} + module-obj (Module. exports)] + (swap! require-cache assoc file module-obj) + ((js/eval (module-wrapper value)) + exports #(node-require (:dir value) %) module-obj (:file value) (:dir value)) + (.-exports module-obj)))) + (catch :default e + (.error js/console e) + (throw e)))))) (set! (.-require js/window) node-require) (set! (.-process js/window) diff --git a/src/portal/ui/options.cljs b/src/portal/ui/options.cljs index 35c25b03..6253fe69 100644 --- a/src/portal/ui/options.cljs +++ b/src/portal/ui/options.cljs @@ -1,9 +1,10 @@ (ns portal.ui.options - (:require ["react" :as react] - [clojure.edn :as edn] - [portal.ui.react :refer [use-effect]] - [portal.ui.state :as state] - [reagent.core :as r])) + (:require + ["react" :as react] + [clojure.edn :as edn] + [portal.ui.react :refer [use-effect]] + [portal.ui.state :as state] + [reagent.core :as r])) (defn- get-extension-options [] (when-let [options (.getItem js/sessionStorage "PORTAL_EXTENSION_OPTIONS")] @@ -28,9 +29,9 @@ (defn with-options [& children] (let [[options set-options!] (react/useState ::loading)] (use-effect - :once - (-> (state/invoke `portal.runtime/get-options) - (.then set-options!))) + :once + (-> (state/invoke `portal.runtime/get-options) + (.then set-options!))) (into [with-options* options] children))) (defn use-options [] (react/useContext options-context)) diff --git a/src/portal/ui/parsers.cljs b/src/portal/ui/parsers.cljs index 465ab3cd..37a54113 100644 --- a/src/portal/ui/parsers.cljs +++ b/src/portal/ui/parsers.cljs @@ -1,7 +1,8 @@ -(ns ^:no-doc portal.ui.parsers) +(ns portal.ui.parsers + {:no-doc true}) (defmulti parse-string (fn [format _] format)) (defmethod parse-string :format/text [_ s] s) -(defn formats [] (keys (methods parse-string))) \ No newline at end of file +(defn formats [] (keys (methods parse-string))) diff --git a/src/portal/ui/react.cljc b/src/portal/ui/react.cljc index daadf661..1efaadae 100644 --- a/src/portal/ui/react.cljc +++ b/src/portal/ui/react.cljc @@ -1,6 +1,11 @@ -(ns ^:no-doc portal.ui.react - #?(:cljs (:require ["react" :as react])) - #?(:cljs (:require-macros portal.ui.react))) +(ns portal.ui.react + {:no-doc true} + #?(:cljs + (:require-macros + [portal.ui.react])) + #?(:cljs + (:require + ["react" :as react]))) #?(:cljs (defn use-effect* [f deps] @@ -11,7 +16,7 @@ (defmacro use-effect [deps & body] `(use-effect* - (fn [] - (let [result# (do ~@body)] - (if (fn? result#) result# js/undefined))) - ~deps)) \ No newline at end of file + (fn [] + (let [result# (do ~@body)] + (if (fn? result#) result# js/undefined))) + ~deps)) diff --git a/src/portal/ui/repl/sci/eval.cljs b/src/portal/ui/repl/sci/eval.cljs index 05ea77ae..71657d0e 100644 --- a/src/portal/ui/repl/sci/eval.cljs +++ b/src/portal/ui/repl/sci/eval.cljs @@ -1,10 +1,12 @@ -(ns ^:no-doc portal.ui.repl.sci.eval +(ns portal.ui.repl.sci.eval + {:no-doc true} (:refer-clojure :exclude [Throwable->map]) - (:require [clojure.string :as str] - [portal.ui.cljs :as cljs] - [portal.ui.load :as load] - [portal.ui.repl.sci.libs :as libs] - [sci.core :as sci])) + (:require + [clojure.string :as str] + [portal.ui.cljs :as cljs] + [portal.ui.load :as load] + [portal.ui.repl.sci.libs :as libs] + [sci.core :as sci])) (sci/alter-var-root sci/print-fn (constantly *print-fn*)) (sci/alter-var-root sci/print-err-fn (constantly *print-err-fn*)) @@ -23,15 +25,15 @@ (defn- ex-trace [ex] (when-let [stacktrace (sci/stacktrace ex)] (into - [] - (for [{:keys [_column file line ns] name* :name} stacktrace - :let [ns (->aliases ns ns)]] - [(symbol (str ns) - (name (or name* (gensym "eval")))) - 'invoke - (or file - (ns->file ns)) - (or line 1)])))) + [] + (for [{:keys [_column file line ns] name* :name} stacktrace + :let [ns (->aliases ns ns)]] + [(symbol (str ns) + (name (or name* (gensym "eval")))) + 'invoke + (or file + (ns->file ns)) + (or line 1)])))) (def ^:private ex-type cljs.core/ExceptionInfo) @@ -49,14 +51,14 @@ :cause (ex-message ex) :data (ex-data ex) :via (mapv - (fn [ex] - (merge - {:type (->class ex) - :data (ex-data ex) - :message (ex-message ex)} - (when-let [at (first (ex-trace ex))] - {:at at}))) - chain) + (fn [ex] + (merge + {:type (->class ex) + :data (ex-data ex) + :message (ex-message ex)} + (when-let [at (first (ex-trace ex))] + {:at at}))) + chain) :trace (vec (mapcat ex-trace chain))})) (defn eval-string [msg] @@ -83,18 +85,18 @@ sci/print-err-fn #(out-fn {:tag :err :val %}) sci/file (:file msg)} (cond-> - {:value (loop [last-val nil] - (let [[form _s] (sci/parse-next+string - ctx reader - {:read-cond :allow})] - (if (= ::sci/eof form) - last-val - (let [value (sci/eval-form ctx form)] - (set! *3 *2) - (set! *2 *1) - (set! *1 value) - (recur value))))) - :ns (str @sci/ns)} + {:value (loop [last-val nil] + (let [[form _s] (sci/parse-next+string + ctx reader + {:read-cond :allow})] + (if (= ::sci/eof form) + last-val + (let [value (sci/eval-form ctx form)] + (set! *3 *2) + (set! *2 *1) + (set! *1 value) + (recur value))))) + :ns (str @sci/ns)} (seq @stdio) (assoc :stdio @stdio)))) (catch :default e diff --git a/src/portal/ui/repl/sci/import.cljc b/src/portal/ui/repl/sci/import.cljc index 607c2faa..1f3ebc8b 100644 --- a/src/portal/ui/repl/sci/import.cljc +++ b/src/portal/ui/repl/sci/import.cljc @@ -1,26 +1,31 @@ -(ns ^:no-doc portal.ui.repl.sci.import +(ns portal.ui.repl.sci.import + {:no-doc true} (:refer-clojure :exclude [import]) - #?(:cljs (:require-macros portal.ui.repl.sci.import)) - #?(:cljs (:require [sci.core :as sci]))) + #?(:cljs + (:require-macros + [portal.ui.repl.sci.import])) + #?(:cljs + (:require + [sci.core :as sci]))) (defn- sci-import [symbols] (let [ns (gensym)] (reduce-kv - (fn [namespaces namespace var-symbols] - (let [namespace (if (= namespace 'cljs.core) 'clojure.core namespace)] - (assoc - namespaces - (list 'quote namespace) - `(let [~ns (sci.core/create-ns '~namespace nil)] - ~(reduce - (fn [mapped var-symbol] - (assoc mapped - (list 'quote (symbol (name var-symbol))) - `(sci.core/copy-var ~var-symbol ~ns))) - {:obj ns} - var-symbols))))) - {} - (group-by (comp symbol namespace) symbols)))) + (fn [namespaces namespace var-symbols] + (let [namespace (if (= namespace 'cljs.core) 'clojure.core namespace)] + (assoc + namespaces + (list 'quote namespace) + `(let [~ns (sci.core/create-ns '~namespace nil)] + ~(reduce + (fn [mapped var-symbol] + (assoc mapped + (list 'quote (symbol (name var-symbol))) + `(sci.core/copy-var ~var-symbol ~ns))) + {:obj ns} + var-symbols))))) + {} + (group-by (comp symbol namespace) symbols)))) (defmacro import [& symbols] (sci-import symbols)) @@ -29,16 +34,16 @@ {namespace (let [ns (sci/create-ns namespace nil)] (reduce - (fn [ns-map [var-name var]] - (let [m (meta var)] - (if (:private m) - ns-map - (assoc ns-map var-name - (sci/new-var (symbol var-name) @var (assoc m :ns ns)))))) - {:obj ns} - publics))})) + (fn [ns-map [var-name var]] + (let [m (meta var)] + (if (:private m) + ns-map + (assoc ns-map var-name + (sci/new-var (symbol var-name) @var (assoc m :ns ns)))))) + {:obj ns} + publics))})) (defmacro import-ns [& namespaces] `(merge - ~@(for [ns namespaces] - `(import-ns* '~ns (ns-publics '~ns))))) + ~@(for [ns namespaces] + `(import-ns* '~ns (ns-publics '~ns))))) diff --git a/src/portal/ui/repl/sci/libs.cljs b/src/portal/ui/repl/sci/libs.cljs index 507a0680..da4688a2 100644 --- a/src/portal/ui/repl/sci/libs.cljs +++ b/src/portal/ui/repl/sci/libs.cljs @@ -1,54 +1,57 @@ -(ns ^:no-doc portal.ui.repl.sci.libs - (:require ["react" :as react] - ["react-dom" :as react-dom] - ["react/jsx-runtime" :as jsx-runtime] - ["vega" :as vega] - ["vega-embed" :as vega-embed] - ["vega-lite" :as vega-lite] - cljs.reader - clojure.zip - goog.crypt.base64 - portal.colors - portal.runtime.cson - portal.ui.api - portal.ui.app - portal.ui.commands - portal.ui.icons - portal.ui.inspector - portal.ui.options - portal.ui.parsers - [portal.ui.repl.sci.import :as sci-import] - portal.ui.rpc - portal.ui.select - portal.ui.state - portal.ui.styled - portal.ui.theme - portal.ui.viewer.bin - portal.ui.viewer.charts - portal.ui.viewer.code - portal.ui.viewer.csv - portal.ui.viewer.date-time - portal.ui.viewer.diff - portal.ui.viewer.edn - portal.ui.viewer.exception - portal.ui.viewer.hiccup - portal.ui.viewer.html - portal.ui.viewer.image - portal.ui.viewer.json - portal.ui.viewer.log - portal.ui.viewer.markdown - portal.ui.viewer.relative-time - portal.ui.viewer.table - portal.ui.viewer.text - portal.ui.viewer.transit - portal.ui.viewer.tree - portal.ui.viewer.vega - portal.ui.viewer.vega-lite - portal.viewer - [reagent.core :as r] - [sci.configs.reagent.reagent :as reagent] - [sci.core :as sci]) - (:import [goog.math Long])) +(ns portal.ui.repl.sci.libs + {:no-doc true} + (:require + ["react" :as react] + ["react-dom" :as react-dom] + ["react/jsx-runtime" :as jsx-runtime] + ["vega" :as vega] + ["vega-embed" :as vega-embed] + ["vega-lite" :as vega-lite] + [cljs.reader] + [clojure.zip] + [goog.crypt.base64] + [portal.colors] + [portal.runtime.cson] + [portal.ui.api] + [portal.ui.app] + [portal.ui.commands] + [portal.ui.icons] + [portal.ui.inspector] + [portal.ui.options] + [portal.ui.parsers] + [portal.ui.repl.sci.import :as sci-import] + [portal.ui.rpc] + [portal.ui.select] + [portal.ui.state] + [portal.ui.styled] + [portal.ui.theme] + [portal.ui.viewer.bin] + [portal.ui.viewer.charts] + [portal.ui.viewer.code] + [portal.ui.viewer.csv] + [portal.ui.viewer.date-time] + [portal.ui.viewer.diff] + [portal.ui.viewer.edn] + [portal.ui.viewer.exception] + [portal.ui.viewer.hiccup] + [portal.ui.viewer.html] + [portal.ui.viewer.image] + [portal.ui.viewer.json] + [portal.ui.viewer.log] + [portal.ui.viewer.markdown] + [portal.ui.viewer.relative-time] + [portal.ui.viewer.table] + [portal.ui.viewer.text] + [portal.ui.viewer.transit] + [portal.ui.viewer.tree] + [portal.ui.viewer.vega] + [portal.ui.viewer.vega-lite] + [portal.viewer] + [reagent.core :as r] + [sci.configs.reagent.reagent :as reagent] + [sci.core :as sci]) + (:import + (goog.math Long))) (def js-libs {"react" react @@ -60,66 +63,66 @@ (def namespaces (merge - (sci-import/import-ns - clojure.zip - goog.crypt.base64 - goog.math - portal.colors - portal.runtime.cson - portal.ui.api - portal.ui.app - portal.ui.commands - portal.ui.icons - portal.ui.inspector - portal.ui.options - portal.ui.parsers - portal.ui.rpc - portal.ui.select - portal.ui.state - portal.ui.styled - portal.ui.theme - portal.ui.viewer.bin - portal.ui.viewer.charts - portal.ui.viewer.code - portal.ui.viewer.csv - portal.ui.viewer.date-time - portal.ui.viewer.diff - portal.ui.viewer.edn - portal.ui.viewer.exception - portal.ui.viewer.hiccup - portal.ui.viewer.html - portal.ui.viewer.image - portal.ui.viewer.json - portal.ui.viewer.log - portal.ui.viewer.markdown - portal.ui.viewer.relative-time - portal.ui.viewer.table - portal.ui.viewer.text - portal.ui.viewer.transit - portal.ui.viewer.tree - portal.ui.viewer.vega - portal.ui.viewer.vega-lite - portal.viewer) - (sci-import/import - cljs.core/random-uuid - cljs.core/tap> - cljs.reader/read-string) - {'reagent.core - (assoc reagent/reagent-namespace - 'adapt-react-class - (sci/copy-var r/adapt-react-class reagent/rns) - 'render - (sci/copy-var r/render reagent/rns)) - 'reagent.ratom reagent/reagent-ratom-namespace - 'reagent.debug reagent/reagent-debug-namespace})) + (sci-import/import-ns + clojure.zip + goog.crypt.base64 + goog.math + portal.colors + portal.runtime.cson + portal.ui.api + portal.ui.app + portal.ui.commands + portal.ui.icons + portal.ui.inspector + portal.ui.options + portal.ui.parsers + portal.ui.rpc + portal.ui.select + portal.ui.state + portal.ui.styled + portal.ui.theme + portal.ui.viewer.bin + portal.ui.viewer.charts + portal.ui.viewer.code + portal.ui.viewer.csv + portal.ui.viewer.date-time + portal.ui.viewer.diff + portal.ui.viewer.edn + portal.ui.viewer.exception + portal.ui.viewer.hiccup + portal.ui.viewer.html + portal.ui.viewer.image + portal.ui.viewer.json + portal.ui.viewer.log + portal.ui.viewer.markdown + portal.ui.viewer.relative-time + portal.ui.viewer.table + portal.ui.viewer.text + portal.ui.viewer.transit + portal.ui.viewer.tree + portal.ui.viewer.vega + portal.ui.viewer.vega-lite + portal.viewer) + (sci-import/import + cljs.core/random-uuid + cljs.core/tap> + cljs.reader/read-string) + {'reagent.core + (assoc reagent/reagent-namespace + 'adapt-react-class + (sci/copy-var r/adapt-react-class reagent/rns) + 'render + (sci/copy-var r/render reagent/rns)) + 'reagent.ratom reagent/reagent-ratom-namespace + 'reagent.debug reagent/reagent-debug-namespace})) (defn init [opts] (sci/init - (merge {:namespaces namespaces - :js-libs js-libs - :classes {'js js/window - 'Math js/Math - 'goog.math.Long Long - :allow :all} - :disable-arity-checks true} - opts))) + (merge {:namespaces namespaces + :js-libs js-libs + :classes {'js js/window + 'Math js/Math + 'goog.math.Long Long + :allow :all} + :disable-arity-checks true} + opts))) diff --git a/src/portal/ui/rpc.cljs b/src/portal/ui/rpc.cljs index 51841b56..58273cbe 100644 --- a/src/portal/ui/rpc.cljs +++ b/src/portal/ui/rpc.cljs @@ -1,25 +1,28 @@ -(ns ^:no-doc portal.ui.rpc +(ns portal.ui.rpc + {:no-doc true} (:refer-clojure :exclude [read type]) - (:require [clojure.string :as str] - [portal.async :as a] - [portal.runtime.cson :as cson] - [portal.runtime.macros :as m] - [portal.ui.cljs :as cljs] - [portal.ui.rpc.runtime :as rt] - [portal.ui.state :as state]) - (:import [goog.math Long])) + (:require + [clojure.string :as str] + [portal.async :as a] + [portal.runtime.cson :as cson] + [portal.runtime.macros :as m] + [portal.ui.cljs :as cljs] + [portal.ui.rpc.runtime :as rt] + [portal.ui.state :as state]) + (:import + (goog.math Long))) (defn call [f & args] (apply state/invoke f args)) (m/extend-type? - js/BigInt - IHash - (-hash [this] - (hash (.toString this))) - IPrintWithWriter - (-pr-writer [this writer _opts] - (-write writer (str this "N")))) + js/BigInt + IHash + (-hash [this] + (hash (.toString this))) + IPrintWithWriter + (-pr-writer [this writer _opts] + (-write writer (str this "N")))) (extend-type array IHash @@ -56,10 +59,10 @@ cson/ToJson (-to-json [value buffer] (cson/-to-json - (with-meta - (cson/tagged-value "remote" (pr-str value)) - (meta value)) - buffer)))) + (with-meta + (cson/tagged-value "remote" (pr-str value)) + (meta value)) + buffer)))) (defmulti ^:no-doc -read (fn [tag _] tag)) @@ -69,18 +72,18 @@ (defn- read [string] (cson/read - string - {:transform rt/transform - :default-handler -read})) + string + {:transform rt/transform + :default-handler -read})) (defn- write [value] (cson/write - value - {:transform - (fn [value] - (if-let [id (rt/->id value)] - (cson/tagged-value "ref" id) - value))})) + value + {:transform + (fn [value] + (if-let [id (rt/->id value)] + (cson/tagged-value "ref" id) + value))})) (defonce ^:private id (atom 0)) (defonce ^:private pending-requests (atom {})) @@ -91,20 +94,20 @@ (defn- ws-request [message] (js/Promise. - (fn [resolve reject] - (let [id (:portal.rpc/id message)] - (swap! pending-requests assoc id [resolve reject]) - (send! (assoc message :portal.rpc/id id)))))) + (fn [resolve reject] + (let [id (:portal.rpc/id message)] + (swap! pending-requests assoc id [resolve reject]) + (send! (assoc message :portal.rpc/id id)))))) (defn- web-request [message] (js/Promise. - (fn [resolve reject] - (try - (-> (write message) - js/window.opener.portal.web.send_BANG_ - (.then read) - resolve) - (catch :default e (reject e)))))) + (fn [resolve reject] + (try + (-> (write message) + js/window.opener.portal.web.send_BANG_ + (.then read) + resolve) + (catch :default e (reject e)))))) (defn request [message] ((if js/window.opener web-request ws-request) @@ -122,9 +125,9 @@ (let [return (fn [msg] (send! - (assoc msg - :op :portal.rpc/response - :portal.rpc/id (:portal.rpc/id message)))) + (assoc msg + :op :portal.rpc/response + :portal.rpc/id (:portal.rpc/id message)))) error (fn [e] (return {:error (ex-data e) :message (.-message e)}))] @@ -161,8 +164,8 @@ (fn [message send!] (state/dispatch! state/state state/history-push {:portal/value (:state message)}) (send! - {:op :portal.rpc/response - :portal.rpc/id (:portal.rpc/id message)}))}) + {:op :portal.rpc/response + :portal.rpc/id (:portal.rpc/id message)}))}) (defn- dispatch [message send!] ;; (tap> (assoc message :type :response)) @@ -205,20 +208,20 @@ (if-let [ws @ws-promise] ws (reset! - ws-promise - (js/Promise. - (fn [resolve reject] - (when-let [chan (js/WebSocket. - (str protocol "//" host (when port (str ":" port)) "/rpc?" session))] - (set! (.-onmessage chan) #(dispatch (read (.-data %)) - (fn [message] - (send! message)))) - (set! (.-onerror chan) (fn [e] - (reject e) - (doseq [[_ [_ reject]] @pending-requests] - (reject e)))) - (set! (.-onclose chan) #(reset! ws-promise nil)) - (set! (.-onopen chan) #(do (rt/reset-cache!) (resolve chan)))))))))) + ws-promise + (js/Promise. + (fn [resolve reject] + (when-let [chan (js/WebSocket. + (str protocol "//" host (when port (str ":" port)) "/rpc?" session))] + (set! (.-onmessage chan) #(dispatch (read (.-data %)) + (fn [message] + (send! message)))) + (set! (.-onerror chan) (fn [e] + (reject e) + (doseq [[_ [_ reject]] @pending-requests] + (reject e)))) + (set! (.-onclose chan) #(reset! ws-promise nil)) + (set! (.-onopen chan) #(do (rt/reset-cache!) (resolve chan)))))))))) (defn- send! [message] (.then (connect) #(.send % (write message)))) diff --git a/src/portal/ui/rpc/runtime.cljs b/src/portal/ui/rpc/runtime.cljs index f8856937..c62a31dc 100644 --- a/src/portal/ui/rpc/runtime.cljs +++ b/src/portal/ui/rpc/runtime.cljs @@ -1,9 +1,11 @@ -(ns ^:no-doc portal.ui.rpc.runtime +(ns portal.ui.rpc.runtime + {:no-doc true} (:refer-clojure :exclude [deref pr-str]) - (:require [clojure.pprint :as pprint] - [portal.runtime.cson :as cson] - [portal.ui.state :as state] - [reagent.core :as r])) + (:require + [clojure.pprint :as pprint] + [portal.runtime.cson :as cson] + [portal.ui.state :as state] + [reagent.core :as r])) (defn call [f & args] (apply state/invoke f args)) @@ -23,8 +25,8 @@ (if-let [id (->id this)] (cson/tag buffer "ref" id) (cson/-to-json - (cson/tagged-value "remote" (:pr-str object)) - buffer))))) + (cson/tagged-value "remote" (:pr-str object)) + buffer))))) (defprotocol Runtime) @@ -40,8 +42,8 @@ IWithMeta (-with-meta [_this m] (RuntimeObject. - runtime - (assoc object :meta m))) + runtime + (assoc object :meta m))) IPrintWithWriter (-pr-writer [_this writer _opts] (-write writer (:pr-str object)))) @@ -71,9 +73,9 @@ IWatchable (-add-watch [this key f] (-add-watch - a key - (fn [key _a old new] - (f key this old new)))) + a key + (fn [key _a old new] + (f key this old new)))) (-remove-watch [_this key] (-remove-watch a key)) (-notify-watches [_this oldval newval] @@ -99,8 +101,8 @@ (defn ->runtime [call object] (if (and - (not= (:tag object) :var) - (contains? (:protocols object) :IDeref)) + (not= (:tag object) :var) + (contains? (:protocols object) :IDeref)) (->RuntimeAtom call object (r/atom ::loading)) (->RuntimeObject call object))) @@ -154,12 +156,12 @@ (defn reset-cache! [] (swap! - state/value-cache - (fn [cache] - (when registry - (doseq [weak-ref (vals cache) - :let [object (weak-ref-value weak-ref)] - :when object] - (.unregister ^js registry object))) - {})) - (state/reset-value-cache!)) \ No newline at end of file + state/value-cache + (fn [cache] + (when registry + (doseq [weak-ref (vals cache) + :let [object (weak-ref-value weak-ref)] + :when object] + (.unregister ^js registry object))) + {})) + (state/reset-value-cache!)) diff --git a/src/portal/ui/select.cljs b/src/portal/ui/select.cljs index 01c6ae68..4d42c966 100644 --- a/src/portal/ui/select.cljs +++ b/src/portal/ui/select.cljs @@ -1,6 +1,8 @@ -(ns ^:no-doc portal.ui.select - (:require ["react" :as react] - [portal.ui.react :refer [use-effect]])) +(ns portal.ui.select + {:no-doc true} + (:require + ["react" :as react] + [portal.ui.react :refer [use-effect]])) (defonce ^:no-doc selection-index (atom {})) (defonce ^:private index-context (react/createContext [])) @@ -77,8 +79,8 @@ (defn use-register-context [context viewer] (let [index (react/useContext index-context)] (use-effect - #js [(hash index) (hash context) (hash viewer)] - (let [updates (compute-relative-index @selection-index index context)] - (swap! selection-index merge updates) - (fn [] - (apply swap! selection-index dissoc (keys updates))))))) + #js [(hash index) (hash context) (hash viewer)] + (let [updates (compute-relative-index @selection-index index context)] + (swap! selection-index merge updates) + (fn [] + (apply swap! selection-index dissoc (keys updates))))))) diff --git a/src/portal/ui/state.cljs b/src/portal/ui/state.cljs index a49d3473..7eb8df23 100644 --- a/src/portal/ui/state.cljs +++ b/src/portal/ui/state.cljs @@ -1,9 +1,11 @@ -(ns ^:no-doc portal.ui.state - (:require ["react" :as react] - [portal.async :as a] - [portal.colors :as c] - [portal.ui.select :as select] - [reagent.core :as r])) +(ns portal.ui.state + {:no-doc true} + (:require + ["react" :as react] + [portal.async :as a] + [portal.colors :as c] + [portal.ui.select :as select] + [reagent.core :as r])) (defonce sender (atom nil)) (defonce render (atom nil)) @@ -26,23 +28,23 @@ (defn- sleep [ms] (js/Promise. - (fn [resolve _reject] - (js/setTimeout resolve ms)))) + (fn [resolve _reject] + (js/setTimeout resolve ms)))) (defn- wait-for [p ms] (.race js/Promise #js - [(sleep ms) - (.catch p (fn [e] (.error js/console e)))])) + [(sleep ms) + (.catch p (fn [e] (.error js/console e)))])) (defn dispatch! [state f & args] (swap! - sync-promise - (fn [last-promise] - (a/do - (wait-for last-promise 1000) - (a/let [next-state (apply f @state args)] - (when next-state (reset! state next-state))))))) + sync-promise + (fn [last-promise] + (a/do + (wait-for last-promise 1000) + (a/let [next-state (apply f @state args)] + (when next-state (reset! state next-state))))))) (def ^:private state-context (react/createContext nil)) @@ -158,19 +160,19 @@ (defn history-push [state {:portal/keys [key value f] :as entry}] (-> (push-command state entry) (assoc - :portal/previous-state state - :portal/key key - :portal/f f - :portal/value value - :selected (mapv - (fn [context] - (-> context - (dissoc :props :collection :key) - (assoc :depth 1 - :path [] - :stable-path [] - :alt-bg true))) - (:selected state))) + :portal/previous-state state + :portal/key key + :portal/f f + :portal/value value + :selected (mapv + (fn [context] + (-> context + (dissoc :props :collection :key) + (assoc :depth 1 + :path [] + :stable-path [] + :alt-bg true))) + (:selected state))) (dissoc :portal/next-state) (push-search-text entry) (push-viewer entry) @@ -257,7 +259,7 @@ (defn set-title! [title] (set-title title) (notify-parent - {:type :set-title :title title})) + {:type :set-title :title title})) (defn- log-message [message] (when-not (= 'portal.runtime/ping (:f message)) @@ -272,19 +274,19 @@ (.then (fn [{:keys [return error] :as response}] (when js/goog.DEBUG (log-message - {:runtime :portal - :level (if error :error :info) - :ns (if-not (symbol? f) - 'unknown - (-> f namespace symbol)) - :f f - :args args - :line (:line response 1) - :column (:column response 1) - :file (:file response) - :result (or return error) - :time time - :ms (- (.now js/Date) start)})) + {:runtime :portal + :level (if error :error :info) + :ns (if-not (symbol? f) + 'unknown + (-> f namespace symbol)) + :f f + :args args + :line (:line response 1) + :column (:column response 1) + :file (:file response) + :result (or return error) + :time time + :ms (- (.now js/Date) start)})) (if-not error return (throw (ex-info (pr-str error) error)))))))) @@ -307,8 +309,8 @@ :selected-viewers :lazy-take) (assoc - :portal/previous-state nil - :portal/next-state nil)))) + :portal/previous-state nil + :portal/next-state nil)))) (defn- send-selected-values [_ _ state state'] (when (not= (selected-values state) @@ -329,9 +331,9 @@ (defn get-history [state] (concat - (reverse - (take-while some? (rest (iterate :portal/previous-state state)))) - (take-while some? (iterate :portal/next-state state)))) + (reverse + (take-while some? (rest (iterate :portal/previous-state state)))) + (take-while some? (iterate :portal/next-state state)))) (defn notify [state notification] (if (some #{notification} (:portal.ui.app/notifications state)) @@ -347,4 +349,4 @@ "Close this inspector windows." [] (notify-parent {:type :close}) - (.close js/window)) \ No newline at end of file + (.close js/window)) diff --git a/src/portal/ui/styled.cljs b/src/portal/ui/styled.cljs index c564942a..58246b2e 100644 --- a/src/portal/ui/styled.cljs +++ b/src/portal/ui/styled.cljs @@ -1,5 +1,6 @@ (ns portal.ui.styled - (:require [clojure.string :as str])) + (:require + [clojure.string :as str])) (def selectors {:style #(str "." %) @@ -24,14 +25,14 @@ (defn style->css [style] (reduce-kv - (fn [css k v] - (str - css - (when (and k v) - (str (value->css k) ":" - (if (exclude? k) - v - (value->css v)) ";")))) "" style)) + (fn [css k v] + (str + css + (when (and k v) + (str (value->css k) ":" + (if (exclude? k) + v + (value->css v)) ";")))) "" style)) (defn- generate-class [selector style] (let [css (style->css style)] @@ -51,16 +52,16 @@ (defn attrs->css [attrs] (reduce - (fn [attrs selector] - (if-not (contains? attrs selector) - attrs - (let [style (get attrs selector) - class (get-class selector style)] - (-> attrs - (dissoc selector) - (update :class str " " class))))) - attrs - (keys selectors))) + (fn [attrs selector] + (if-not (contains? attrs selector) + attrs + (let [style (get attrs selector) + class (get-class selector style)] + (-> attrs + (dissoc selector) + (update :class str " " class))))) + attrs + (keys selectors))) (defn styled [component attrs & children] (into [component @@ -95,9 +96,9 @@ (defn map->css [m] (reduce-kv - (fn [css k v] - (str css - (str/join " " (map name k)) - "{" (style->css v) "}\n")) - "" - m)) + (fn [css k v] + (str css + (str/join " " (map name k)) + "{" (style->css v) "}\n")) + "" + m)) diff --git a/src/portal/ui/theme.cljs b/src/portal/ui/theme.cljs index c7df96dd..2690a81c 100644 --- a/src/portal/ui/theme.cljs +++ b/src/portal/ui/theme.cljs @@ -1,9 +1,10 @@ (ns portal.ui.theme - (:require ["react" :as react] - [clojure.string :as str] - [portal.colors :as c] - [portal.ui.options :as opts] - [portal.ui.react :refer [use-effect]])) + (:require + ["react" :as react] + [clojure.string :as str] + [portal.colors :as c] + [portal.ui.options :as opts] + [portal.ui.react :refer [use-effect]])) (defn ^:no-doc is-vs-code? [] (-> js/document @@ -22,52 +23,52 @@ (defn ^:no-doc get-vs-code-css-vars [] (when-let [style (get-style)] (persistent! - (reduce - (fn [vars rule] - (if-let [[attr value] (str/split rule #"\s*:\s*")] - (assoc! vars (str "var(" attr ")") value) - vars)) - (transient {}) - (str/split style #"\s*;\s*"))))) + (reduce + (fn [vars rule] + (if-let [[attr value] (str/split rule #"\s*:\s*")] + (assoc! vars (str "var(" attr ")") value) + vars)) + (transient {}) + (str/split style #"\s*;\s*"))))) (defn- get-theme [theme-name] (let [opts (opts/use-options) vars (get-vs-code-css-vars)] (merge - {:font-family "monospace" - :font-size "12pt" - :string-length 100 - :max-depth 2 - :padding 6 - :border-radius 2} - (update-vals - (or (get c/themes theme-name) - (get (:themes opts) theme-name)) - #(get vars % %))))) + {:font-family "monospace" + :font-size "12pt" + :string-length 100 + :max-depth 2 + :padding 6 + :border-radius 2} + (update-vals + (or (get c/themes theme-name) + (get (:themes opts) theme-name)) + #(get vars % %))))) (defn- use-theme-detector [] (let [media-query (.matchMedia js/window "(prefers-color-scheme: dark)") [dark-theme set-dark-theme!] (react/useState (.-matches media-query))] (use-effect - :once - (let [listener (fn [e] (set-dark-theme! (.-matches e)))] - (.addListener media-query listener) - (fn [] - (.removeListener media-query listener)))) + :once + (let [listener (fn [e] (set-dark-theme! (.-matches e)))] + (.addListener media-query listener) + (fn [] + (.removeListener media-query listener)))) dark-theme)) (defn- use-vscode-theme-detector [] (let [[change-id set-change-id!] (react/useState 0)] (when (is-vs-code?) (react/useEffect - (fn [] - (let [observer (js/MutationObserver. #(set-change-id! inc))] - (.observe observer - js/document.documentElement - #js {:attributes true - :attributeFilter #js ["style"]}) - #(.disconnect observer))) - #js [])) + (fn [] + (let [observer (js/MutationObserver. #(set-change-id! inc))] + (.observe observer + js/document.documentElement + #js {:attributes true + :attributeFilter #js ["style"]}) + #(.disconnect observer))) + #js [])) change-id)) (defn- default-theme [dark-theme] @@ -87,8 +88,8 @@ (defn ^:no-doc with-background [] (let [background (::c/background (use-theme))] (use-effect - #js [background] - (set! (.. js/document -body -style -backgroundColor) background)) + #js [background] + (set! (.. js/document -body -style -backgroundColor) background)) nil)) (defn with-theme [theme-name & children] diff --git a/src/portal/ui/viewer/bin.cljs b/src/portal/ui/viewer/bin.cljs index 0eda5c8b..d7902c34 100644 --- a/src/portal/ui/viewer/bin.cljs +++ b/src/portal/ui/viewer/bin.cljs @@ -1,9 +1,11 @@ -(ns ^:no-doc portal.ui.viewer.bin - (:require [portal.colors :as c] - [portal.ui.inspector :as ins] - [portal.ui.lazy :as l] - [portal.ui.styled :as s] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.bin + {:no-doc true} + (:require + [portal.colors :as c] + [portal.ui.inspector :as ins] + [portal.ui.lazy :as l] + [portal.ui.styled :as s] + [portal.ui.theme :as theme])) (def ^:private indexed (partial map-indexed vector)) @@ -53,16 +55,16 @@ :grid-template-columns (str "repeat(" (+ 1 1 8 1 16) ", auto)")}} (l/use-lazy - value - (for [[idx [hex ascii]] (indexed (map vector hex ascii))] - [:<> {:key idx} - [s/div - {:style {:color (::c/border theme)}} - (.padStart (.toString idx 16) 8 "0") ":"] - [s/div] - [:<> hex] - [s/div] - [:<> ascii]]))]])) + value + (for [[idx [hex ascii]] (indexed (map vector hex ascii))] + [:<> {:key idx} + [s/div + {:style {:color (::c/border theme)}} + (.padStart (.toString idx 16) 8 "0") ":"] + [s/div] + [:<> hex] + [s/div] + [:<> ascii]]))]])) (def viewer {:predicate ins/bin? diff --git a/src/portal/ui/viewer/bytes.cljs b/src/portal/ui/viewer/bytes.cljs index 0a8a50c7..dddcf8c1 100644 --- a/src/portal/ui/viewer/bytes.cljs +++ b/src/portal/ui/viewer/bytes.cljs @@ -1,4 +1,5 @@ -(ns ^:no-doc portal.ui.viewer.bytes +(ns portal.ui.viewer.bytes + {:no-doc true} (:require [portal.colors :as-alias c] [portal.ui.inspector :as ins] diff --git a/src/portal/ui/viewer/charts.cljs b/src/portal/ui/viewer/charts.cljs index 06af138a..65b19d6c 100644 --- a/src/portal/ui/viewer/charts.cljs +++ b/src/portal/ui/viewer/charts.cljs @@ -1,8 +1,10 @@ -(ns ^:no-doc portal.ui.viewer.charts - (:require [clojure.spec.alpha :as sp] - [portal.colors :as c] - [portal.ui.theme :as theme] - [portal.ui.viewer.vega-lite :as v])) +(ns portal.ui.viewer.charts + {:no-doc true} + (:require + [clojure.spec.alpha :as sp] + [portal.colors :as c] + [portal.ui.theme :as theme] + [portal.ui.viewer.vega-lite :as v])) ;; collection of maps of [{:x 0 :y 0} ...] maps (sp/def :tabular/x number?) diff --git a/src/portal/ui/viewer/cljdoc.cljs b/src/portal/ui/viewer/cljdoc.cljs index 1641e8b5..4da6eded 100644 --- a/src/portal/ui/viewer/cljdoc.cljs +++ b/src/portal/ui/viewer/cljdoc.cljs @@ -1,33 +1,35 @@ -(ns ^:no-doc portal.ui.viewer.cljdoc - (:require ["react" :as react] - [portal.colors :as c] - [portal.ui.inspector :as ins] - [portal.ui.react :refer [use-effect]] - [portal.ui.select :as select] - [portal.ui.styled :as s] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.cljdoc + {:no-doc true} + (:require + ["react" :as react] + [portal.colors :as c] + [portal.ui.inspector :as ins] + [portal.ui.react :refer [use-effect]] + [portal.ui.select :as select] + [portal.ui.styled :as s] + [portal.ui.theme :as theme])) (def ^:private observer-context (react/createContext nil)) (defn- with-observer [f & children] (let [[observer set-observer!] (react/useState nil)] (use-effect - #js [f] - (set-observer! - (js/IntersectionObserver. - (fn [entries] - (f - (reduce - (fn [result entry] - (let [element (.-target entry) - id (.getAttribute element "data-observer")] - (assoc result - id - {:element element - :ratio (.-intersectionRatio entry)}))) - {} - entries))) - #js {:root nil :rootMargin "0px" :threshold 0}))) + #js [f] + (set-observer! + (js/IntersectionObserver. + (fn [entries] + (f + (reduce + (fn [result entry] + (let [element (.-target entry) + id (.getAttribute element "data-observer")] + (assoc result + id + {:element element + :ratio (.-intersectionRatio entry)}))) + {} + entries))) + #js {:root nil :rootMargin "0px" :threshold 0}))) (when observer (into [:r> (.-Provider observer-context) @@ -39,11 +41,11 @@ observer (react/useContext observer-context) id (str id)] (use-effect - #js [id ref observer] - (when-let [el (.-current ref)] - (.setAttribute el "data-observer" id) - (.observe observer el) - #(.unobserve observer el))) + #js [id ref observer] + (when-let [el (.-current ref)] + (.setAttribute el "data-observer" id) + (.observe observer el) + #(.unobserve observer el))) ref)) (def ^:private index-context (react/createContext 0)) @@ -56,21 +58,21 @@ (defn- first-visible [visible index] (->> visible (keep - (fn [[label {:keys [ratio]}]] - (when-not (zero? ratio) label))) + (fn [[label {:keys [ratio]}]] + (when-not (zero? ratio) label))) (select-keys (:order index)) (sort-by second) ffirst)) (defn- selected-path [index selected] (zipmap - (->> selected - (iterate - (fn [label] - (get-in index [:parents label]))) - (take-while some?) - reverse) - (range))) + (->> selected + (iterate + (fn [label] + (get-in index [:parents label]))) + (take-while some?) + reverse) + (range))) (defn- docs-nav [value visible] (let [index (use-index) @@ -132,31 +134,31 @@ [select/with-position {:row (get-in index [:order label]) :column 0} (or - (when-let [markdown (:markdown entry)] - [ins/inspector - {:style {:padding 40} - :portal.viewer/default :portal.viewer/markdown} - markdown]) - (when-let [hiccup (:hiccup entry)] - [ins/inspector - {:portal.viewer/default :portal.viewer/hiccup} - hiccup]) - [s/h1 - {:style - {:margin 0 - :padding 40 - :font-size "2em" - :color (::c/namespace theme)}} - [s/span - {:on-click - (fn [e] - (.stopPropagation e) - (when-let [el (.-current ref)] - (.scrollIntoView ^js el))) - :style - {:cursor :pointer - :color (::c/tag theme)}} "# "] - label])]]]]]])) + (when-let [markdown (:markdown entry)] + [ins/inspector + {:style {:padding 40} + :portal.viewer/default :portal.viewer/markdown} + markdown]) + (when-let [hiccup (:hiccup entry)] + [ins/inspector + {:portal.viewer/default :portal.viewer/hiccup} + hiccup]) + [s/h1 + {:style + {:margin 0 + :padding 40 + :font-size "2em" + :color (::c/namespace theme)}} + [s/span + {:on-click + (fn [e] + (.stopPropagation e) + (when-let [el (.-current ref)] + (.scrollIntoView ^js el))) + :style + {:cursor :pointer + :color (::c/tag theme)}} "# "] + label])]]]]]])) (defn render-docs [value] (let [has-label? (string? (first value)) @@ -166,12 +168,12 @@ (when has-label? [ins/toggle-bg [render-article value]]) (map-indexed - (fn [index value] - ^{:key index} - [render-docs value]) - (cond-> value - has-label? rest - has-article? rest))])) + (fn [index value] + ^{:key index} + [render-docs value]) + (cond-> value + has-label? rest + has-article? rest))])) (defn get-docs-order ([value] diff --git a/src/portal/ui/viewer/code.cljs b/src/portal/ui/viewer/code.cljs index d5b6a360..f7b8b66b 100644 --- a/src/portal/ui/viewer/code.cljs +++ b/src/portal/ui/viewer/code.cljs @@ -1,95 +1,97 @@ -(ns ^:no-doc portal.ui.viewer.code - (:require ["highlight.js" :as hljs] - [clojure.string :as str] - [portal.colors :as c] - [portal.ui.filter :as f] - [portal.ui.html :as h] - [portal.ui.inspector :as ins] - [portal.ui.styled :as s] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.code + {:no-doc true} + (:require + ["highlight.js" :as hljs] + [clojure.string :as str] + [portal.colors :as c] + [portal.ui.filter :as f] + [portal.ui.html :as h] + [portal.ui.inspector :as ins] + [portal.ui.styled :as s] + [portal.ui.theme :as theme])) (def ^:private root-class "portal-viewer-code") (defn- ->styles [theme] (let [{::c/keys [uri keyword text namespace background string package number tag border]} theme] (update-keys - {"pre code.hljs" {:display :block :overflow-x :auto :padding "1em"} - "code.hljs" {:padding "3px 5px"} - ".hljs" {:background background} - ".hljs,.hljs-subst" {:color text} - ".hljs-selector-tag" {:color "#81a1c1"} - ".hljs-selector-id" {:color namespace :font-weight 700} - ".hljs-selector-attr,.hljs-selector-class" {:color namespace} - ".hljs-property,.hljs-selector-pseudo" {:color package} - ".hljs-addition" {:background-color "rgba(163,190,140,.5)"} - ".hljs-deletion" {:background-color "rgba(191,97,106,.5)"} - ".hljs-built_in,.hljs-class,.hljs-type" {:color namespace} - ".hljs-function" {:color package} - ".hljs-function>.hljs-title" {:color package} - ".hljs-title.hljs-function" {:color package} - ".hljs-keyword" {:color keyword} - ".hljs-literal" {:color text} - ".hljs-symbol" {:color keyword} - ".hljs-number" {:color number} - ".hljs-regexp" {:color tag} - ".hljs-string" {:color string} - ".hljs-title" {:color symbol} - ".hljs-params" {:color text} - ".hljs-bullet" {:color border} - ".hljs-code" {:color namespace} - ".hljs-emphasis" {:font-style :italic} - ".hljs-formula" {:color namespace} - ".hljs-strong" {:font-weight 700} - ".hljs-link:hover" {:text-decoration :underline} - ".hljs-comment,.hljs-quote" {:color border} - ".hljs-doctag" {:color namespace} - ".hljs-meta,.hljs-meta .hljs-keyword" {:color keyword} - ".hljs-meta .hljs-string" {:color string} - ".hljs-attr" {:color namespace} - ".hljs-attribute" {:color text} - ".hljs-name" {:color namespace} - ".hljs-section" {:color package} - ".hljs-tag" {:color tag} - ".hljs-template-variable,.hljs-variable" {:color text} - ".hljs-template-tag" {:color keyword} - ".language-abnf .hljs-attribute" {:color package} - ".language-abnf .hljs-symbol" {:color tag} - ".language-apache .hljs-attribute" {:color package} - ".language-apache .hljs-section" {:color border} - ".language-arduino .hljs-built_in" {:color package} - ".language-aspectj .hljs-meta" {:color uri} - ".language-aspectj>.hljs-title" {:color package} - ".language-bnf .hljs-attribute" {:color namespace} - ".language-coq .hljs-built_in" {:color package} - ".language-cpp .hljs-meta .hljs-string" {:color string} - ".language-css .hljs-built_in" {:color package} - ".language-css .hljs-keyword" {:color uri} - ".language-diff .hljs-meta" {:color namespace} - ".language-ebnf .hljs-attribute" {:color namespace} - ".language-glsl .hljs-built_in" {:color package} - ".language-groovy .hljs-meta:not(:first-child)" {:color uri} - ".language-haxe .hljs-meta" {:color uri} - ".language-java .hljs-meta" {:color uri} - ".language-ldif .hljs-attribute" {:color namespace} - ".language-lisp .hljs-name" {:color package} - ".language-lua .hljs-built_in" {:color package} - ".language-moonscript .hljs-built_in" {:color package} - ".language-nginx .hljs-attribute" {:color package} - ".language-nginx .hljs-section" {:color keyword} - ".language-pf .hljs-built_in" {:color package} - ".language-processing .hljs-built_in" {:color package} - ".language-scss .hljs-keyword" {:color keyword} - ".language-stylus .hljs-keyword" {:color keyword} - ".language-swift .hljs-meta" {:color uri} - ".language-vim .hljs-built_in" {:color package :font-style :italic} - ".language-yaml .hljs-meta" {:color uri}} - (fn [selector] - (str "." root-class " " selector))))) + {"pre code.hljs" {:display :block :overflow-x :auto :padding "1em"} + "code.hljs" {:padding "3px 5px"} + ".hljs" {:background background} + ".hljs,.hljs-subst" {:color text} + ".hljs-selector-tag" {:color "#81a1c1"} + ".hljs-selector-id" {:color namespace :font-weight 700} + ".hljs-selector-attr,.hljs-selector-class" {:color namespace} + ".hljs-property,.hljs-selector-pseudo" {:color package} + ".hljs-addition" {:background-color "rgba(163,190,140,.5)"} + ".hljs-deletion" {:background-color "rgba(191,97,106,.5)"} + ".hljs-built_in,.hljs-class,.hljs-type" {:color namespace} + ".hljs-function" {:color package} + ".hljs-function>.hljs-title" {:color package} + ".hljs-title.hljs-function" {:color package} + ".hljs-keyword" {:color keyword} + ".hljs-literal" {:color text} + ".hljs-symbol" {:color keyword} + ".hljs-number" {:color number} + ".hljs-regexp" {:color tag} + ".hljs-string" {:color string} + ".hljs-title" {:color symbol} + ".hljs-params" {:color text} + ".hljs-bullet" {:color border} + ".hljs-code" {:color namespace} + ".hljs-emphasis" {:font-style :italic} + ".hljs-formula" {:color namespace} + ".hljs-strong" {:font-weight 700} + ".hljs-link:hover" {:text-decoration :underline} + ".hljs-comment,.hljs-quote" {:color border} + ".hljs-doctag" {:color namespace} + ".hljs-meta,.hljs-meta .hljs-keyword" {:color keyword} + ".hljs-meta .hljs-string" {:color string} + ".hljs-attr" {:color namespace} + ".hljs-attribute" {:color text} + ".hljs-name" {:color namespace} + ".hljs-section" {:color package} + ".hljs-tag" {:color tag} + ".hljs-template-variable,.hljs-variable" {:color text} + ".hljs-template-tag" {:color keyword} + ".language-abnf .hljs-attribute" {:color package} + ".language-abnf .hljs-symbol" {:color tag} + ".language-apache .hljs-attribute" {:color package} + ".language-apache .hljs-section" {:color border} + ".language-arduino .hljs-built_in" {:color package} + ".language-aspectj .hljs-meta" {:color uri} + ".language-aspectj>.hljs-title" {:color package} + ".language-bnf .hljs-attribute" {:color namespace} + ".language-coq .hljs-built_in" {:color package} + ".language-cpp .hljs-meta .hljs-string" {:color string} + ".language-css .hljs-built_in" {:color package} + ".language-css .hljs-keyword" {:color uri} + ".language-diff .hljs-meta" {:color namespace} + ".language-ebnf .hljs-attribute" {:color namespace} + ".language-glsl .hljs-built_in" {:color package} + ".language-groovy .hljs-meta:not(:first-child)" {:color uri} + ".language-haxe .hljs-meta" {:color uri} + ".language-java .hljs-meta" {:color uri} + ".language-ldif .hljs-attribute" {:color namespace} + ".language-lisp .hljs-name" {:color package} + ".language-lua .hljs-built_in" {:color package} + ".language-moonscript .hljs-built_in" {:color package} + ".language-nginx .hljs-attribute" {:color package} + ".language-nginx .hljs-section" {:color keyword} + ".language-pf .hljs-built_in" {:color package} + ".language-processing .hljs-built_in" {:color package} + ".language-scss .hljs-keyword" {:color keyword} + ".language-stylus .hljs-keyword" {:color keyword} + ".language-swift .hljs-meta" {:color uri} + ".language-vim .hljs-built_in" {:color package :font-style :italic} + ".language-yaml .hljs-meta" {:color uri}} + (fn [selector] + (str "." root-class " " selector))))) (defn- ->css [styles] (str/join - (for [[class style] styles] - (str class "{" (s/style->css style) "}")))) + (for [[class style] styles] + (str class "{" (s/style->css style) "}")))) (def ^:private language-map {"emacs-lisp" "lisp" "elisp" "lisp"}) @@ -128,19 +130,19 @@ code (if-let [search-text (ins/use-search-text)] (->> (str/split-lines code) (filter - (fn [line-content] - (some - #(str/includes? line-content %) - (str/split search-text #"\s+")))) + (fn [line-content] + (some + #(str/includes? line-content %) + (str/split search-text #"\s+")))) (str/join "\n")) code) out (if-let [language (or (:class attrs) (some-> - (get-in opts [:props :portal.viewer/code :language]) - name))] + (get-in opts [:props :portal.viewer/code :language]) + name))] (hljs/highlight - code - #js {:language (get language-map language language)}) + code + #js {:language (get language-map language language)}) (hljs/highlightAuto code)) html (.-value out) language (or (:class attrs) (.-language out))] diff --git a/src/portal/ui/viewer/color.cljs b/src/portal/ui/viewer/color.cljs index 2039005e..16ffd7c8 100644 --- a/src/portal/ui/viewer/color.cljs +++ b/src/portal/ui/viewer/color.cljs @@ -1,9 +1,11 @@ -(ns ^:no-doc portal.ui.viewer.color - (:require [clojure.spec.alpha :as s] - [portal.colors :as c] - [portal.ui.inspector :as ins] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.color + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [portal.colors :as c] + [portal.ui.inspector :as ins] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) ;;; :spec (defn- hex-short? [string] @@ -53,4 +55,4 @@ {:predicate color? :component #'inspect-color :name :portal.viewer/color - :doc "View hex / rgb / rgba colors"}) \ No newline at end of file + :doc "View hex / rgb / rgba colors"}) diff --git a/src/portal/ui/viewer/csv.cljs b/src/portal/ui/viewer/csv.cljs index 1fdb24c4..c444a344 100644 --- a/src/portal/ui/viewer/csv.cljs +++ b/src/portal/ui/viewer/csv.cljs @@ -1,7 +1,9 @@ -(ns ^:no-doc portal.ui.viewer.csv - (:require ["papaparse" :refer [parse]] - [portal.ui.inspector :as ins] - [portal.ui.parsers :as p])) +(ns portal.ui.viewer.csv + {:no-doc true} + (:require + ["papaparse" :refer [parse]] + [portal.ui.inspector :as ins] + [portal.ui.parsers :as p])) (defn parse-csv [csv-string] (try diff --git a/src/portal/ui/viewer/date_time.cljs b/src/portal/ui/viewer/date_time.cljs index 3760d852..92c21fb5 100644 --- a/src/portal/ui/viewer/date_time.cljs +++ b/src/portal/ui/viewer/date_time.cljs @@ -1,9 +1,11 @@ -(ns ^:no-doc portal.ui.viewer.date-time - (:require [clojure.spec.alpha :as s] - [portal.colors :as c] - [portal.ui.inspector :as ins] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.date-time + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [portal.colors :as c] + [portal.ui.inspector :as ins] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) ;;; :spec (s/def ::date-time @@ -67,8 +69,8 @@ {:title "Hour" :style style} [ins/highlight-words (str - (let [hour (mod hour 12)] - (if (= hour 0) 12 hour)))]] + (let [hour (mod hour 12)] + (if (= hour 0) 12 hour)))]] [d/span {:style border} ":"] [d/span {:title "Minute" :style style} diff --git a/src/portal/ui/viewer/deref.cljs b/src/portal/ui/viewer/deref.cljs index 95755b82..319a3ebc 100644 --- a/src/portal/ui/viewer/deref.cljs +++ b/src/portal/ui/viewer/deref.cljs @@ -1,13 +1,15 @@ -(ns ^:no-doc portal.ui.viewer.deref - (:require ["react" :as react] - [portal.colors :as c] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.options :as options] - [portal.ui.rpc :as rpc] - [portal.ui.select :as select] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.deref + {:no-doc true} + (:require + ["react" :as react] + [portal.colors :as c] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.options :as options] + [portal.ui.rpc :as rpc] + [portal.ui.select :as select] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) (defn atom? [value] (and (satisfies? cljs.core/IDeref value) diff --git a/src/portal/ui/viewer/diff.cljs b/src/portal/ui/viewer/diff.cljs index f68ad52c..ec41ee6d 100644 --- a/src/portal/ui/viewer/diff.cljs +++ b/src/portal/ui/viewer/diff.cljs @@ -1,15 +1,17 @@ -(ns ^:no-doc portal.ui.viewer.diff - (:require [clojure.spec.alpha :as s] - [lambdaisland.deep-diff2.diff-impl :as diff] - [portal.colors :as c] - [portal.runtime.cson :as cson] - [portal.ui.commands :as commands] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.rpc :as rpc] - [portal.ui.select :as select] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.diff + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [lambdaisland.deep-diff2.diff-impl :as diff] + [portal.colors :as c] + [portal.runtime.cson :as cson] + [portal.ui.commands :as commands] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.rpc :as rpc] + [portal.ui.select :as select] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) (extend-protocol cson/ToJson diff/Deletion @@ -27,9 +29,9 @@ (defn diff? [value] (or - (instance? diff/Deletion value) - (instance? diff/Insertion value) - (instance? diff/Mismatch value))) + (instance? diff/Deletion value) + (instance? diff/Insertion value) + (instance? diff/Mismatch value))) ;;; :spec (s/def ::diffable (s/coll-of any? :min-count 2)) @@ -154,15 +156,15 @@ (->> (test-actual value) (partition 2 1) (map-indexed - (fn [idx [a b]] - ^{:key idx} - [ins/with-key - idx - [ins/with-collection - [a b] - [select/with-position - {:row idx :column 0} - [ins/inspector (diff/diff a b)]]]])))]]])) + (fn [idx [a b]] + ^{:key idx} + [ins/with-key + idx + [ins/with-collection + [a b] + [select/with-position + {:row idx :column 0} + [ins/inspector (diff/diff a b)]]]])))]]])) (def ^:no-doc deep-diff2 {:predicate diff? @@ -179,7 +181,7 @@ name (#'commands/var->name var)] (swap! commands/registry assoc name (commands/make-command - (merge (meta var) - {:predicate (fn [& args] (= 2 (count args))) - :f var - :name name})))) + (merge (meta var) + {:predicate (fn [& args] (= 2 (count args))) + :f var + :name name})))) diff --git a/src/portal/ui/viewer/diff_text.cljs b/src/portal/ui/viewer/diff_text.cljs index 58f7b1ca..3989eb8f 100644 --- a/src/portal/ui/viewer/diff_text.cljs +++ b/src/portal/ui/viewer/diff_text.cljs @@ -1,13 +1,15 @@ -(ns ^:no-doc portal.ui.viewer.diff-text - (:require ["diff" :as df] - [clojure.spec.alpha :as s] - [clojure.string :as str] - [portal.colors :as c] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.lazy :as l] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.diff-text + {:no-doc true} + (:require + ["diff" :as df] + [clojure.spec.alpha :as s] + [clojure.string :as str] + [portal.colors :as c] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.lazy :as l] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) ;;; :spec (s/def ::diff-text (s/cat :a string? :b string?)) @@ -40,71 +42,71 @@ :border-top-right-radius (:border-radius theme)}}] [l/lazy-seq (map-indexed - (fn [index [before ^js item after]] - (let [added (.-added item) - removed (.-removed item) - text (.-value item) - border-color (cond - added add - removed remove - :else (::c/border theme))] - ^{:key index} - [d/div - {:style - {:position :relative - :border-left [5 :solid border-color] - :border-right [1 :solid border-color] - :background (cond added (str add "22") - removed (str remove "22"))}} - (if-not (or removed added) - (if (:expanded? opts) - [ins/highlight-words text] - (let [lines (str/split-lines text)] - (if (< (count lines) 6) - [ins/highlight-words text] - [:<> - (when before - [:<> - [ins/highlight-words (str/join "\n" (take 3 lines))] - [d/div {:style {:background (::c/border theme) - :text-align :center}} - [icons/ellipsis-h]]]) - (when after - [:<> - [d/div {:style {:background (::c/border theme) - :text-align :center}} - [icons/ellipsis-h]] - [ins/highlight-words (str/join "\n" (take-last 3 lines))]])]))) - (cond - (changed? before) - (keep-indexed - (fn [idx ^js item] - (when (or (.-added item) (not (.-removed item))) - ^{:key idx} - [d/span {:style {:background (when (.-added item) - (if added - (str add "66") - (str remove "66")))}} - [ins/highlight-words (.-value item)]])) - (df/diffChars (.-value before) (str/trimr text))) + (fn [index [before ^js item after]] + (let [added (.-added item) + removed (.-removed item) + text (.-value item) + border-color (cond + added add + removed remove + :else (::c/border theme))] + ^{:key index} + [d/div + {:style + {:position :relative + :border-left [5 :solid border-color] + :border-right [1 :solid border-color] + :background (cond added (str add "22") + removed (str remove "22"))}} + (if-not (or removed added) + (if (:expanded? opts) + [ins/highlight-words text] + (let [lines (str/split-lines text)] + (if (< (count lines) 6) + [ins/highlight-words text] + [:<> + (when before + [:<> + [ins/highlight-words (str/join "\n" (take 3 lines))] + [d/div {:style {:background (::c/border theme) + :text-align :center}} + [icons/ellipsis-h]]]) + (when after + [:<> + [d/div {:style {:background (::c/border theme) + :text-align :center}} + [icons/ellipsis-h]] + [ins/highlight-words (str/join "\n" (take-last 3 lines))]])]))) + (cond + (changed? before) + (keep-indexed + (fn [idx ^js item] + (when (or (.-added item) (not (.-removed item))) + ^{:key idx} + [d/span {:style {:background (when (.-added item) + (if added + (str add "66") + (str remove "66")))}} + [ins/highlight-words (.-value item)]])) + (df/diffChars (.-value before) (str/trimr text))) - (changed? after) - (keep-indexed - (fn [idx ^js item] - (when (or (.-added item) (not (.-removed item))) - ^{:key idx} - [d/span {:style {:background (when (.-added item) - (if added - (str add "66") - (str remove "66")))}} - [ins/highlight-words (.-value item)]])) - (df/diffChars (.-value after) (str/trimr text))) + (changed? after) + (keep-indexed + (fn [idx ^js item] + (when (or (.-added item) (not (.-removed item))) + ^{:key idx} + [d/span {:style {:background (when (.-added item) + (if added + (str add "66") + (str remove "66")))}} + [ins/highlight-words (.-value item)]])) + (df/diffChars (.-value after) (str/trimr text))) - :else - (str/trimr text))) + :else + (str/trimr text))) - (when (or removed added) "\n")])) - (partition 3 1 (concat [nil] diff [nil])))] + (when (or removed added) "\n")])) + (partition 3 1 (concat [nil] diff [nil])))] [d/div {:style {:height (:padding theme) :padding-left (:padding theme) @@ -118,4 +120,4 @@ {:predicate diff-text? :component #'inspect-text-diff :name :portal.viewer/diff-text - :doc "Diff two strings."}) \ No newline at end of file + :doc "Diff two strings."}) diff --git a/src/portal/ui/viewer/duration.cljs b/src/portal/ui/viewer/duration.cljs index 923a9da0..8eabd196 100644 --- a/src/portal/ui/viewer/duration.cljs +++ b/src/portal/ui/viewer/duration.cljs @@ -1,4 +1,5 @@ -(ns ^:no-doc portal.ui.viewer.duration +(ns portal.ui.viewer.duration + {:no-doc true} (:require [portal.colors :as-alias c] [portal.ui.inspector :as ins] diff --git a/src/portal/ui/viewer/edn.cljs b/src/portal/ui/viewer/edn.cljs index 52d38fdc..a29fc83a 100644 --- a/src/portal/ui/viewer/edn.cljs +++ b/src/portal/ui/viewer/edn.cljs @@ -1,7 +1,9 @@ -(ns ^:no-doc portal.ui.viewer.edn - (:require [portal.runtime.edn :as edn] - [portal.ui.inspector :as ins] - [portal.ui.parsers :as p])) +(ns portal.ui.viewer.edn + {:no-doc true} + (:require + [portal.runtime.edn :as edn] + [portal.ui.inspector :as ins] + [portal.ui.parsers :as p])) (defn read-string [edn-string] (try (edn/read-string edn-string) diff --git a/src/portal/ui/viewer/exception.cljs b/src/portal/ui/viewer/exception.cljs index 1e58e97d..d18e424b 100644 --- a/src/portal/ui/viewer/exception.cljs +++ b/src/portal/ui/viewer/exception.cljs @@ -1,15 +1,17 @@ -(ns ^:no-doc portal.ui.viewer.exception - (:require [clojure.spec.alpha :as s] - [clojure.string :as str] - [portal.colors :as c] - [portal.ui.filter :as f] - [portal.ui.icons :as icon] - [portal.ui.inspector :as ins] - [portal.ui.select :as select] - [portal.ui.styled :as d] - [portal.ui.theme :as theme] - [portal.ui.viewer.log :as log] - [portal.viewer :as v])) +(ns portal.ui.viewer.exception + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [clojure.string :as str] + [portal.colors :as c] + [portal.ui.filter :as f] + [portal.ui.icons :as icon] + [portal.ui.inspector :as ins] + [portal.ui.select :as select] + [portal.ui.styled :as d] + [portal.ui.theme :as theme] + [portal.ui.viewer.log :as log] + [portal.viewer :as v])) ;;; :spec (s/def ::cause string?) @@ -28,8 +30,8 @@ (s/def ::via (s/coll-of - (s/keys :req-un [::type] - :opt-un [::message ::at]))) + (s/keys :req-un [::type] + :opt-un [::message ::at]))) (s/def ::exception (s/keys :req-un [::via] @@ -111,22 +113,22 @@ [d/div {:style {:flex "1" :display :flex :flex-direction :column}} (keep-indexed - (fn [idx {:keys [clj? sym method index] :as source}] - (when (matcher method) - ^{:key index} - [ins/with-key - index - [d/div - {:key idx - :style {:display :flex - :flex "1" - :justify-content :space-between}} + (fn [idx {:keys [clj? sym method index] :as source}] + (when (matcher method) + ^{:key index} + [ins/with-key + index [d/div - [select/with-position - {:row idx :column 1} - [ins/inspector {:portal.viewer/default :portal.viewer/source-location} - (assoc source :label (if clj? (symbol nil (name sym)) method))]]]]])) - (if expanded? trace (take 1 trace)))] + {:key idx + :style {:display :flex + :flex "1" + :justify-content :space-between}} + [d/div + [select/with-position + {:row idx :column 1} + [ins/inspector {:portal.viewer/default :portal.viewer/source-location} + (assoc source :label (if clj? (symbol nil (name sym)) method))]]]]])) + (if expanded? trace (take 1 trace)))] [d/div {:style {:min-width "3em" :text-align :right}} @@ -148,15 +150,15 @@ (with-meta trace (merge - {:class class - :method method - :line line - :column 1 - :index index} - (when file - {:file file}) - (when-let [ns (and clj? (some-> clj-name namespace symbol))] - {:clj? true :ns ns :sym clj-name}))))) + {:class class + :method method + :line line + :column 1 + :index index} + (when file + {:file file}) + (when-let [ns (and clj? (some-> clj-name namespace symbol))] + {:clj? true :ns ns :sym clj-name}))))) (defn- wrapper [context & children] (let [opts (ins/use-options) @@ -192,27 +194,27 @@ :border-bottom [1 :solid (::c/border theme)]}} (->> trace (map-indexed - analyze-trace-item) + analyze-trace-item) (filter - (fn [line] - (when (matcher line) - (let [{:keys [clj? ns]} (meta line)] - (if (:expanded? options) true - (and clj? (not (or - (str/starts-with? (str ns) "nrepl.middleware") - (str/starts-with? (str ns) "clojure.lang.Compiler"))))))))) + (fn [line] + (when (matcher line) + (let [{:keys [clj? ns]} (meta line)] + (if (:expanded? options) true + (and clj? (not (or + (str/starts-with? (str ns) "nrepl.middleware") + (str/starts-with? (str ns) "clojure.lang.Compiler"))))))))) (partition-by (comp :file meta)) (map-indexed - (fn [index trace] - ^{:key index} - [select/with-position - {:column 0 :row index} - [ins/with-key - index - [ins/inspector - {:portal.viewer/inspector {:wrapper wrapper} - :portal.viewer/default :portal.viewer/sub-trace} - (with-meta trace (meta (first trace)))]]])))]])) + (fn [index trace] + ^{:key index} + [select/with-position + {:column 0 :row index} + [ins/with-key + index + [ins/inspector + {:portal.viewer/inspector {:wrapper wrapper} + :portal.viewer/default :portal.viewer/sub-trace} + (with-meta trace (meta (first trace)))]]])))]])) (defn- inspect-via [value] (let [theme (theme/use-theme) @@ -298,7 +300,7 @@ value [ins/inspect-map-k-v (v/for - (dissoc value :cause :phase :runtime) + (dissoc value :cause :phase :runtime) {:trace :portal.viewer/stack-trace})]])]])) (def viewer diff --git a/src/portal/ui/viewer/hiccup.cljs b/src/portal/ui/viewer/hiccup.cljs index dc166835..b248e057 100644 --- a/src/portal/ui/viewer/hiccup.cljs +++ b/src/portal/ui/viewer/hiccup.cljs @@ -1,11 +1,13 @@ -(ns ^:no-doc portal.ui.viewer.hiccup - (:require [portal.colors :as c] - [portal.ui.filter :as-alias f] - [portal.ui.inspector :as ins] - [portal.ui.lazy :as l] - [portal.ui.select :as select] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.hiccup + {:no-doc true} + (:require + [portal.colors :as c] + [portal.ui.filter :as-alias f] + [portal.ui.inspector :as ins] + [portal.ui.lazy :as l] + [portal.ui.select :as select] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) (defn- header-styles [theme] {:color (::c/namespace theme) @@ -23,74 +25,74 @@ (str "1px solid " (::c/border theme))}] [:style (d/map->css - {[:h1.hiccup] (merge {:font-size "2em"} h border-bottom) - [:h2.hiccup] (merge {:font-size "1.5em"} h border-bottom) - - [:h3.hiccup] h [:h4.hiccup] h [:h5.hiccup] h [:h6.hiccup] h - - [:a.hiccup] {:color (::c/uri theme) :width :fit-content} - - [:ul.hiccup] {:margin 0} - [:ol.hiccup] {:margin 0} - [:li.hiccup] {:margin-top (:padding theme)} - - [:p.hiccup] - {:font-family "-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji" - :font-size "1.1em" - :line-height "1.5em" - :margin 0} - - [:img.hiccup] {:max-width "100%"} - [:hr.hiccup] {:width "calc(100% - 2px)" - :border [1 :solid (::c/border theme)] - :border-radius (:border-radius theme)} - - [:code.hiccup] - {:background bg2 - :display :inline-block - :border-radius (:border-radius theme) - :border [1 :solid (::c/border theme)] - :box-sizing :border-box - :padding [0 (* 1.5 (:padding theme))]} - - [:blockquote.hiccup] - {:margin 0 - :background bg - :padding-left (* 2 (:padding theme)) - :padding-bottom (:padding theme) - :padding-top (:padding theme) - :font-style :normal - :border-left [(:padding theme) :solid (::c/border theme)]} - - [:table.hiccup] - {:margin 1 - :color (::c/text theme) - :display :block - :font-size (:font-size theme) - :overflow :auto - :max-width "calc(100% - 2px)" - :width :max-content - :border-style :hidden - :border-collapse :collapse - :border-radius (:border-radius theme)} - - [:th.hiccup] - {:font-weight :bold - :text-align :center - :padding (* 1.5 (:padding theme)) - :border [1 :solid (::c/border theme)]} - [:td.hiccup] - {:text-align :left - :padding (:padding theme) - :border [1 :solid (::c/border theme)]} - - ["tr.hiccup:nth-child(odd)"] {:background bg} - ["tr.hiccup:nth-child(even)"] {:background bg2} - - ["div.hiccup-root"] - {:display :flex - :flex-direction :column - :gap (* 1.5 (:padding theme))}})])) + {[:h1.hiccup] (merge {:font-size "2em"} h border-bottom) + [:h2.hiccup] (merge {:font-size "1.5em"} h border-bottom) + + [:h3.hiccup] h [:h4.hiccup] h [:h5.hiccup] h [:h6.hiccup] h + + [:a.hiccup] {:color (::c/uri theme) :width :fit-content} + + [:ul.hiccup] {:margin 0} + [:ol.hiccup] {:margin 0} + [:li.hiccup] {:margin-top (:padding theme)} + + [:p.hiccup] + {:font-family "-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji" + :font-size "1.1em" + :line-height "1.5em" + :margin 0} + + [:img.hiccup] {:max-width "100%"} + [:hr.hiccup] {:width "calc(100% - 2px)" + :border [1 :solid (::c/border theme)] + :border-radius (:border-radius theme)} + + [:code.hiccup] + {:background bg2 + :display :inline-block + :border-radius (:border-radius theme) + :border [1 :solid (::c/border theme)] + :box-sizing :border-box + :padding [0 (* 1.5 (:padding theme))]} + + [:blockquote.hiccup] + {:margin 0 + :background bg + :padding-left (* 2 (:padding theme)) + :padding-bottom (:padding theme) + :padding-top (:padding theme) + :font-style :normal + :border-left [(:padding theme) :solid (::c/border theme)]} + + [:table.hiccup] + {:margin 1 + :color (::c/text theme) + :display :block + :font-size (:font-size theme) + :overflow :auto + :max-width "calc(100% - 2px)" + :width :max-content + :border-style :hidden + :border-collapse :collapse + :border-radius (:border-radius theme)} + + [:th.hiccup] + {:font-weight :bold + :text-align :center + :padding (* 1.5 (:padding theme)) + :border [1 :solid (::c/border theme)]} + [:td.hiccup] + {:text-align :left + :padding (:padding theme) + :border [1 :solid (::c/border theme)]} + + ["tr.hiccup:nth-child(odd)"] {:background bg} + ["tr.hiccup:nth-child(even)"] {:background bg2} + + ["div.hiccup-root"] + {:display :flex + :flex-direction :column + :gap (* 1.5 (:padding theme))}})])) (defn inspect-code [& args] (let [[_ attrs code] (second args) @@ -133,17 +135,17 @@ (into [component (merge (first args) {:portal.viewer/default tag})] (rest args))))]]) (if (map? (first args)) (into - (if (= tag :<>) - [tag (first args)] - [tag (update (first args) :class str " hiccup")]) - (map #(process-hiccup context %)) - (rest args)) + (if (= tag :<>) + [tag (first args)] + [tag (update (first args) :class str " hiccup")]) + (map #(process-hiccup context %)) + (rest args)) (into - (if (= tag :<>) - [tag] - [tag {:class "hiccup"}]) - (map #(process-hiccup context %)) - args)))))) + (if (= tag :<>) + [tag] + [tag {:class "hiccup"}]) + (map #(process-hiccup context %)) + args)))))) (defn- inspect-hiccup* [value] (let [viewers (ins/viewers-by-name @ins/viewers) @@ -155,13 +157,13 @@ {:overflow :auto :max-height (when-not (:expanded? opts) "24rem")}} (process-hiccup - {:count (atom -1) :viewers viewers} - (if-let [[tag attrs] value] - (let [missing-tag? (not= tag (first value)) - missing-attrs? (and (map? attrs) - (not= attrs (second value)))] - (cond-> [] missing-tag? (conj tag) missing-attrs? (conj attrs) :always (into value))) - value))]])) + {:count (atom -1) :viewers viewers} + (if-let [[tag attrs] value] + (let [missing-tag? (not= tag (first value)) + missing-attrs? (and (map? attrs) + (not= attrs (second value)))] + (cond-> [] missing-tag? (conj tag) missing-attrs? (conj attrs) :always (into value))) + value))]])) (defn inspect-hiccup [value] [l/lazy-render [inspect-hiccup* value]]) diff --git a/src/portal/ui/viewer/html.cljs b/src/portal/ui/viewer/html.cljs index 056d4d76..0ad63099 100644 --- a/src/portal/ui/viewer/html.cljs +++ b/src/portal/ui/viewer/html.cljs @@ -1,7 +1,9 @@ -(ns ^:no-doc portal.ui.viewer.html - (:require [portal.colors :as c] - [portal.ui.styled :as s] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.html + {:no-doc true} + (:require + [portal.colors :as c] + [portal.ui.styled :as s] + [portal.ui.theme :as theme])) (defn inspect-html [value] (let [theme (theme/use-theme)] diff --git a/src/portal/ui/viewer/http.cljs b/src/portal/ui/viewer/http.cljs index 4665a090..a13cb465 100644 --- a/src/portal/ui/viewer/http.cljs +++ b/src/portal/ui/viewer/http.cljs @@ -1,12 +1,14 @@ -(ns ^:no-doc portal.ui.viewer.http - (:require [clojure.spec.alpha :as s] - [clojure.string :as str] - [portal.colors :as c] - [portal.ui.filter :as-alias f] - [portal.ui.inspector :as ins] - [portal.ui.select :as select] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.http + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [clojure.string :as str] + [portal.colors :as c] + [portal.ui.filter :as-alias f] + [portal.ui.inspector :as ins] + [portal.ui.select :as select] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) ;;; :spec (s/def ::uri string?) diff --git a/src/portal/ui/viewer/image.cljs b/src/portal/ui/viewer/image.cljs index 8889c5a8..1026ff04 100644 --- a/src/portal/ui/viewer/image.cljs +++ b/src/portal/ui/viewer/image.cljs @@ -1,8 +1,10 @@ -(ns ^:no-doc portal.ui.viewer.image - (:require [portal.colors :as c] - [portal.ui.inspector :as ins] - [portal.ui.styled :as s] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.image + {:no-doc true} + (:require + [portal.colors :as c] + [portal.ui.inspector :as ins] + [portal.ui.styled :as s] + [portal.ui.theme :as theme])) (defn inspect-image [value] (let [theme (theme/use-theme) diff --git a/src/portal/ui/viewer/json.cljs b/src/portal/ui/viewer/json.cljs index 24608eed..e8ac38b4 100644 --- a/src/portal/ui/viewer/json.cljs +++ b/src/portal/ui/viewer/json.cljs @@ -1,6 +1,8 @@ -(ns ^:no-doc portal.ui.viewer.json - (:require [portal.ui.inspector :as ins] - [portal.ui.parsers :as p])) +(ns portal.ui.viewer.json + {:no-doc true} + (:require + [portal.ui.inspector :as ins] + [portal.ui.parsers :as p])) (defn- parse-json [json-string] (try (js->clj (js/JSON.parse json-string) :keywordize-keys true) diff --git a/src/portal/ui/viewer/jwt.cljs b/src/portal/ui/viewer/jwt.cljs index 57cbd72f..148f57ca 100644 --- a/src/portal/ui/viewer/jwt.cljs +++ b/src/portal/ui/viewer/jwt.cljs @@ -1,8 +1,10 @@ -(ns ^:no-doc portal.ui.viewer.jwt - (:require [clojure.string :as str] - [goog.crypt.base64 :as Base64] - [portal.ui.inspector :as ins] - [portal.ui.parsers :as p])) +(ns portal.ui.viewer.jwt + {:no-doc true} + (:require + [clojure.string :as str] + [goog.crypt.base64 :as Base64] + [portal.ui.inspector :as ins] + [portal.ui.parsers :as p])) (defn- parse-json [value] (js->clj (.parse js/JSON (js/atob value)) :keywordize-keys true)) diff --git a/src/portal/ui/viewer/log.cljs b/src/portal/ui/viewer/log.cljs index 99da5227..bdc9284b 100644 --- a/src/portal/ui/viewer/log.cljs +++ b/src/portal/ui/viewer/log.cljs @@ -1,15 +1,17 @@ -(ns ^:no-doc portal.ui.viewer.log - (:require [clojure.spec.alpha :as s] - [portal.colors :as c] - [portal.resources :refer [inline]] - [portal.ui.filter :as-alias f] - #_[shadow.resource :refer [inline]] ;; for hot reloading - [portal.ui.inspector :as ins] - [portal.ui.select :as select] - [portal.ui.styled :as d] - [portal.ui.theme :as theme] - [portal.ui.viewer.date-time :as date-time] - [portal.ui.viewer.source-location :as src])) +(ns portal.ui.viewer.log + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [portal.colors :as c] + [portal.resources :refer [inline]] + [portal.ui.filter :as-alias f] + #_[shadow.resource :refer [inline]] + [portal.ui.inspector :as ins] + [portal.ui.select :as select] + [portal.ui.styled :as d] + [portal.ui.theme :as theme] + [portal.ui.viewer.date-time :as date-time] + [portal.ui.viewer.source-location :as src])) (defn- parse [xml-string] (let [parser (js/DOMParser.) @@ -72,8 +74,8 @@ :style {:height 22 :width 22} :src (str - "data:image/svg+xml;base64," - (-> icon parse (theme-svg color) stringify js/btoa))}])))) + "data:image/svg+xml;base64," + (-> icon parse (theme-svg color) stringify js/btoa))}])))) ;;; :spec (def ^:private levels @@ -119,7 +121,7 @@ border (cond-> {:border-top [1 :solid (::c/border theme)]} (not expanded?) (assoc - :border-bottom [1 :solid (::c/border theme)])) + :border-bottom [1 :solid (::c/border theme)])) flex {:box-sizing :border-box :padding (:padding theme) :display :flex @@ -155,29 +157,29 @@ [d/div {:style (merge - flex - {:border-top [1 :solid (::c/border theme)] - :justify-content :flex-end} - border - (when-not runtime? - {:border-right [1 :solid (::c/border theme)] - :border-top-right-radius (:border-radius theme) - :border-bottom-right-radius (:border-radius theme)}))} + flex + {:border-top [1 :solid (::c/border theme)] + :justify-content :flex-end} + border + (when-not runtime? + {:border-right [1 :solid (::c/border theme)] + :border-top-right-radius (:border-radius theme) + :border-bottom-right-radius (:border-radius theme)}))} [src/inspect-source log]] (when runtime? [d/div {:style (merge - {:padding (* 0.5 (:padding theme)) - :display :flex - :align-items :center - :color (::c/uri theme) - :border-top [1 :solid (::c/border theme)] - :border-left [1 :solid (::c/border theme)] - :border-right [1 :solid (::c/border theme)] - :border-top-right-radius (:border-radius theme) - :border-bottom-right-radius (when-not expanded? (:border-radius theme))} - border)} + {:padding (* 0.5 (:padding theme)) + :display :flex + :align-items :center + :color (::c/uri theme) + :border-top [1 :solid (::c/border theme)] + :border-left [1 :solid (::c/border theme)] + :border-right [1 :solid (::c/border theme)] + :border-top-right-radius (:border-radius theme) + :border-bottom-right-radius (when-not expanded? (:border-radius theme))} + border)} [icon runtime]])] (when (:expanded? options) diff --git a/src/portal/ui/viewer/markdown.cljs b/src/portal/ui/viewer/markdown.cljs index ff770c3b..664ea14d 100644 --- a/src/portal/ui/viewer/markdown.cljs +++ b/src/portal/ui/viewer/markdown.cljs @@ -1,15 +1,17 @@ -(ns ^:no-doc portal.ui.viewer.markdown - (:require ["marked" :refer [marked]] - [clojure.string :as str] - [portal.colors :as c] - [portal.ui.html :as h] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.lazy :as l] - [portal.ui.parsers :as p] - [portal.ui.styled :as d] - [portal.ui.theme :as theme] - [portal.ui.viewer.hiccup :refer [inspect-hiccup]])) +(ns portal.ui.viewer.markdown + {:no-doc true} + (:require + ["marked" :refer [marked]] + [clojure.string :as str] + [portal.colors :as c] + [portal.ui.html :as h] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.lazy :as l] + [portal.ui.parsers :as p] + [portal.ui.styled :as d] + [portal.ui.theme :as theme] + [portal.ui.viewer.hiccup :refer [inspect-hiccup]])) (declare ->inline) (declare ->hiccup) @@ -34,15 +36,15 @@ (defn- ->link [^js token] (let [href (.-href token)] (->inline - (let [title (.-title token)] - [:a (cond-> {:href href - :target "_blank" - :on-click - (fn [e] - (when-not (absolute-link? href) - (.preventDefault e)))} - title (assoc :title title))]) - (.-tokens token)))) + (let [title (.-title token)] + [:a (cond-> {:href href + :target "_blank" + :on-click + (fn [e] + (when-not (absolute-link? href) + (.preventDefault e)))} + title (assoc :title title))]) + (.-tokens token)))) (defn- ->image [^js token] (let [title (.-title token) alt (->text token)] @@ -57,35 +59,35 @@ [:thead {} (persistent! - (reduce - (fn [out ^js cell] - (conj! - out - (->inline - [:th {:align (.-align token)}] - (.-tokens cell)))) - (transient [:tr {}]) - (.-header token)))]) + (reduce + (fn [out ^js cell] + (conj! + out + (->inline + [:th {:align (.-align token)}] + (.-tokens cell)))) + (transient [:tr {}]) + (.-header token)))]) (defn ->row [^js token ^js row] (persistent! - (reduce - (fn [out ^js cell] - (conj! - out - (->inline - [:td {:align (.-align token)}] - (.-tokens cell)))) - (transient [:tr {}]) - row))) + (reduce + (fn [out ^js cell] + (conj! + out + (->inline + [:td {:align (.-align token)}] + (.-tokens cell)))) + (transient [:tr {}]) + row))) (defn- ->rows [^js token] (persistent! - (reduce - (fn [out row] - (conj! out (->row token row))) - (transient [:tbody {}]) - (.-rows token)))) + (reduce + (fn [out row] + (conj! out (->row token row))) + (transient [:tbody {}]) + (.-rows token)))) (defn- ->table [^js token] [:table (->header token) (->rows token)]) @@ -96,13 +98,13 @@ _loose (.-loose token) tag (if ordered :ol :ul)] (persistent! - (reduce - (fn [out ^js item] - (let [_checked (.-checked item) - _task (.-task item)] - (conj! out [:li {} (->hiccup (.-tokens item))]))) - (transient [tag {:start start}]) - (.-items token))))) + (reduce + (fn [out ^js item] + (let [_checked (.-checked item) + _task (.-task item)] + (conj! out [:li {} (->hiccup (.-tokens item))]))) + (transient [tag {:start start}]) + (.-items token))))) (defn- ->code [^js token] (let [lang (.-lang token)] @@ -139,60 +141,60 @@ color (get theme color)] (set! (.-text text-node) remaining-text) (->hiccup - [:blockquote - {:style - {:border-color color}} - [:div + [:blockquote {:style - {:display :flex - :align-items :center - :gap (:padding theme) - :font-size "1.35rem" - :font-weight :bold - :color color - :margin-bottom (:padding theme)}} - [icon {:size "1x"}] " " label]] - tokens)) + {:border-color color}} + [:div + {:style + {:display :flex + :align-items :center + :gap (:padding theme) + :font-size "1.35rem" + :font-weight :bold + :color color + :margin-bottom (:padding theme)}} + [icon {:size "1x"}] " " label]] + tokens)) (->hiccup [:blockquote {}] tokens)))) (defn- ->inline [out tokens] (reduce - (fn [out ^js token] - (case (.-type token) - "escape" (conj out (->text token)) - "html" (conj out (h/parse-html (.-text token))) - "link" (conj out (->link token)) - "image" (conj out (->image token)) - "strong" (conj out (->strong token)) - "em" (conj out (->inline [:em {}] (.-tokens token))) - "codespan" (conj out [:code {} (->text token)]) - "br" (conj out [:br {}]) - "del" (conj out (->inline [:del {}] (.-tokens token))) - "text" (conj out (->text token)))) - out - tokens)) + (fn [out ^js token] + (case (.-type token) + "escape" (conj out (->text token)) + "html" (conj out (h/parse-html (.-text token))) + "link" (conj out (->link token)) + "image" (conj out (->image token)) + "strong" (conj out (->strong token)) + "em" (conj out (->inline [:em {}] (.-tokens token))) + "codespan" (conj out [:code {} (->text token)]) + "br" (conj out [:br {}]) + "del" (conj out (->inline [:del {}] (.-tokens token))) + "text" (conj out (->text token)))) + out + tokens)) (defn ->hiccup ([tokens] (->hiccup [:<>] tokens)) ([out tokens] (reduce - (fn [out ^js token] - (case (.-type token) - "space" out - "hr" (conj out [:hr {}]) - "heading" (conj out (->heading token)) - "code" (conj out (->code token)) - "table" (conj out (->table token)) - "blockquote" (conj out (->blockquote token)) - "list" (conj out (->list token)) - "html" (conj out (h/parse-html (->text token))) - "paragraph" (conj out (->paragraph token)) - "text" (if-let [tokens (.-tokens token)] - (->inline out tokens) - (conj out (->text token))))) - out - tokens))) + (fn [out ^js token] + (case (.-type token) + "space" out + "hr" (conj out [:hr {}]) + "heading" (conj out (->heading token)) + "code" (conj out (->code token)) + "table" (conj out (->table token)) + "blockquote" (conj out (->blockquote token)) + "list" (conj out (->list token)) + "html" (conj out (h/parse-html (->text token))) + "paragraph" (conj out (->paragraph token)) + "text" (if-let [tokens (.-tokens token)] + (->inline out tokens) + (conj out (->text token))))) + out + tokens))) (defn ^:no-doc parse-markdown [value] (->hiccup (.lexer marked value))) @@ -206,13 +208,13 @@ [d/div {:style (merge - {:gap 16 - :width 896 - :max-width "calc(100vw - 36px)" - :display :flex - :box-sizing :border-box - :flex-direction :column} - (get-in opts [:props :style]))} + {:gap 16 + :width 896 + :max-width "calc(100vw - 36px)" + :display :flex + :box-sizing :border-box + :flex-direction :column} + (get-in opts [:props :style]))} (parse-markdown value)]]))) (defn inspect-markdown [value] diff --git a/src/portal/ui/viewer/pprint.cljs b/src/portal/ui/viewer/pprint.cljs index 3578ec7f..0782fda2 100644 --- a/src/portal/ui/viewer/pprint.cljs +++ b/src/portal/ui/viewer/pprint.cljs @@ -1,10 +1,12 @@ -(ns ^:no-doc portal.ui.viewer.pprint - (:require [clojure.pprint :as pp] - [clojure.string :as str] - [portal.runtime.cson :as cson] - [portal.ui.filter :as f] - [portal.ui.inspector :as ins] - [portal.ui.viewer.code :as code])) +(ns portal.ui.viewer.pprint + {:no-doc true} + (:require + [clojure.pprint :as pp] + [clojure.string :as str] + [portal.runtime.cson :as cson] + [portal.ui.filter :as f] + [portal.ui.inspector :as ins] + [portal.ui.viewer.code :as code])) (defn- queue? [obj] (instance? PersistentQueue obj)) @@ -71,9 +73,9 @@ *elide-binary* true] [code/highlight-clj (str/trim - (with-out-str - (pp/with-pprint-dispatch (if (code? value) pp/code-dispatch pprint-dispatch) - (pp/pprint (f/filter-value value search-text)))))]))) + (with-out-str + (pp/with-pprint-dispatch (if (code? value) pp/code-dispatch pprint-dispatch) + (pp/pprint (f/filter-value value search-text)))))]))) (def viewer {:predicate (constantly true) diff --git a/src/portal/ui/viewer/prepl.cljs b/src/portal/ui/viewer/prepl.cljs index 3cdb2996..b1f4e4d8 100644 --- a/src/portal/ui/viewer/prepl.cljs +++ b/src/portal/ui/viewer/prepl.cljs @@ -1,16 +1,18 @@ -(ns ^:no-doc portal.ui.viewer.prepl - (:require ["anser" :as anser] - [clojure.spec.alpha :as s] - [portal.colors :as c] - [portal.runtime.edn :as edn] - [portal.ui.filter :as f] - [portal.ui.html :as h] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.select :as select] - [portal.ui.state :as state] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.prepl + {:no-doc true} + (:require + ["anser" :as anser] + [clojure.spec.alpha :as s] + [portal.colors :as c] + [portal.runtime.edn :as edn] + [portal.ui.filter :as f] + [portal.ui.html :as h] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.select :as select] + [portal.ui.state :as state] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) ;;; :spec (s/def ::tag #{:out :err :tap :ret}) @@ -26,23 +28,23 @@ (let [theme (theme/use-theme)] [:style (d/map->css - {[:.ansi-black-fg] {:color (::c/border theme)} - [:.ansi-black-bg] {:background (::c/border theme)} - [:.ansi-red-fg] {:color (::c/exception theme)} - [:.ansi-red-bg] {:background (::c/exception theme)} - [:.ansi-green-fg] {:color (::c/string theme)} - [:.ansi-green-bg] {:background (::c/string theme)} - [:.ansi-yellow-fg] {:color (::c/tag theme)} - [:.ansi-yellow-bg] {:background (::c/tag theme)} - [:.ansi-blue-fg] {:color (::c/boolean theme)} - [:.ansi-blue-bg] {:background (::c/boolean theme)} - [:.ansi-magenta-fg] {:color (::c/number theme)} - [:.ansi-magenta-bg] {:background (::c/number theme)} - [:.ansi-cyan-fg] {:color (::c/package theme)} - [:.ansi-cyan-bg] {:background (::c/package theme)} - [:.ansi-white-fg] {:color (::c/text theme)} - [:.ansi-white-bg] {:background (::c/text theme)} - [:.ansi-bold] {:font-weight :bold}})])) + {[:.ansi-black-fg] {:color (::c/border theme)} + [:.ansi-black-bg] {:background (::c/border theme)} + [:.ansi-red-fg] {:color (::c/exception theme)} + [:.ansi-red-bg] {:background (::c/exception theme)} + [:.ansi-green-fg] {:color (::c/string theme)} + [:.ansi-green-bg] {:background (::c/string theme)} + [:.ansi-yellow-fg] {:color (::c/tag theme)} + [:.ansi-yellow-bg] {:background (::c/tag theme)} + [:.ansi-blue-fg] {:color (::c/boolean theme)} + [:.ansi-blue-bg] {:background (::c/boolean theme)} + [:.ansi-magenta-fg] {:color (::c/number theme)} + [:.ansi-magenta-bg] {:background (::c/number theme)} + [:.ansi-cyan-fg] {:color (::c/package theme)} + [:.ansi-cyan-bg] {:background (::c/package theme)} + [:.ansi-white-fg] {:color (::c/text theme)} + [:.ansi-white-bg] {:background (::c/text theme)} + [:.ansi-bold] {:font-weight :bold}})])) (defn- inspect-prepl-ret [value index] (let [theme (theme/use-theme) @@ -204,25 +206,25 @@ [ins/with-collection value (reverse - (keep-indexed - (fn [index value] - (when (matcher value) - (with-meta - (if (#{:tap :ret} (:tag value)) - [ins/with-key - index - [inspect-prepl-ret value index]] - [d/span - {:style - {:color - (if (= (:tag value) :err) - (::c/exception theme) - (::c/text theme))}} - [h/html+ (anser/ansiToHtml - (escape-html (:val value)) - #js {:use_classes true})]]) - {:key index}))) - value))]]]])) + (keep-indexed + (fn [index value] + (when (matcher value) + (with-meta + (if (#{:tap :ret} (:tag value)) + [ins/with-key + index + [inspect-prepl-ret value index]] + [d/span + {:style + {:color + (if (= (:tag value) :err) + (::c/exception theme) + (::c/text theme))}} + [h/html+ (anser/ansiToHtml + (escape-html (:val value)) + #js {:use_classes true})]]) + {:key index}))) + value))]]]])) (defn io? [value] (s/valid? ::prepl value)) diff --git a/src/portal/ui/viewer/relative_time.cljs b/src/portal/ui/viewer/relative_time.cljs index 50f6bb12..3a4c98b8 100644 --- a/src/portal/ui/viewer/relative_time.cljs +++ b/src/portal/ui/viewer/relative_time.cljs @@ -1,10 +1,12 @@ -(ns ^:no-doc portal.ui.viewer.relative-time +(ns portal.ui.viewer.relative-time + {:no-doc true} (:refer-clojure :exclude [second]) - (:require ["react" :as react] - [clojure.spec.alpha :as s] - [portal.ui.react :refer [use-effect]] - [portal.ui.styled :as d] - [portal.ui.viewer.date-time :as date-time])) + (:require + ["react" :as react] + [clojure.spec.alpha :as s] + [portal.ui.react :refer [use-effect]] + [portal.ui.styled :as d] + [portal.ui.viewer.date-time :as date-time])) ;;; :spec (s/def ::relative-time @@ -39,16 +41,16 @@ (let [diff (- (.getTime b) (.getTime a)) ms (Math/abs diff)] (some - (fn [[unit scale]] - (when (> ms scale) - {:scale (Math/floor (/ ms scale)) - :unit unit - :direction - (cond - (neg? diff) :past - (pos? diff) :future - :else :now)})) - (partition 2 time-scales))))) + (fn [[unit scale]] + (when (> ms scale) + {:scale (Math/floor (/ ms scale)) + :unit unit + :direction + (cond + (neg? diff) :past + (pos? diff) :future + :else :now)})) + (partition 2 time-scales))))) (defn- format-relative-time [{:keys [scale unit direction]}] (if (= direction :now) @@ -66,13 +68,13 @@ (let [value (date-time/parse value) [now set-now!] (react/useState (js/Date.))] (use-effect - :once - (let [i (js/setInterval - (fn [] - (set-now! (js/Date.))) - 1000)] - (fn [] - (js/clearInterval i)))) + :once + (let [i (js/setInterval + (fn [] + (set-now! (js/Date.))) + 1000)] + (fn [] + (js/clearInterval i)))) [d/div (format-relative-time (relative-time now value))])) (def viewer diff --git a/src/portal/ui/viewer/source_location.cljs b/src/portal/ui/viewer/source_location.cljs index 8a12d537..18d93505 100644 --- a/src/portal/ui/viewer/source_location.cljs +++ b/src/portal/ui/viewer/source_location.cljs @@ -1,10 +1,12 @@ -(ns ^:no-doc portal.ui.viewer.source-location - (:require [clojure.spec.alpha :as s] - [portal.colors :as c] - [portal.ui.inspector :as ins] - [portal.ui.rpc :as rpc] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.source-location + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [portal.colors :as c] + [portal.ui.inspector :as ins] + [portal.ui.rpc :as rpc] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) ;;; :spec (s/def ::ns symbol?) @@ -43,11 +45,11 @@ :color (::c/uri theme)}} [ins/highlight-words (str - (or (:label value) - (:ns value) - (:file value)) - ":" - (:line value))]])) + (or (:label value) + (:ns value) + (:file value)) + ":" + (:line value))]])) (def viewer {:predicate source-location? diff --git a/src/portal/ui/viewer/spec.cljs b/src/portal/ui/viewer/spec.cljs index 7b6069f5..7cfbd351 100644 --- a/src/portal/ui/viewer/spec.cljs +++ b/src/portal/ui/viewer/spec.cljs @@ -1,11 +1,13 @@ -(ns ^:no-doc portal.ui.viewer.spec - (:require [clojure.spec.alpha :as s] - [portal.colors :as c] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.select :as select] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.spec + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [portal.colors :as c] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.select :as select] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) ;;; :spec (s/def ::path vector?) @@ -58,10 +60,10 @@ (defn with-keys [ks & children] (reduce - (fn [out k] - [ins/inc-depth [ins/with-key k out]]) - (into [:<>] children) - (reverse ks))) + (fn [out k] + [ins/inc-depth [ins/with-key k out]]) + (into [:<>] children) + (reverse ks))) (defn inspect-spec [spec] (let [theme (theme/use-theme)] @@ -103,49 +105,49 @@ :border-right [1 :solid (::c/border theme)]}} [ins/inspector :val]] (map-indexed - (fn [idx problem] - ^{:key idx} - [:<> - [d/div - {:style - {:grid-column "1" - :padding (:padding theme) - :border-right [1 :solid (::c/border theme)] - :border-top [1 :solid (::c/border theme)]}} - [select/with-position - {:row idx :column 0} - [ins/with-key - :clojure.spec.alpha/problems - [ins/with-key idx - [ins/with-key - :via + (fn [idx problem] + ^{:key idx} + [:<> + [d/div + {:style + {:grid-column "1" + :padding (:padding theme) + :border-right [1 :solid (::c/border theme)] + :border-top [1 :solid (::c/border theme)]}} + [select/with-position + {:row idx :column 0} + [ins/with-key + :clojure.spec.alpha/problems + [ins/with-key idx [ins/with-key - (dec (count (:via problem))) - [ins/inspector (last (:via problem))]]]]]]] - [d/div - {:style - {:grid-column "2" - :padding (:padding theme) - :border-right [1 :solid (::c/border theme)] - :border-top [1 :solid (::c/border theme)]}} - [select/with-position - {:row idx :column 2} - [ins/with-key - :clojure.spec.alpha/problems - [ins/with-key idx - [inspect-problem problem]]]]] - [select/with-position - {:row idx :column 3} + :via + [ins/with-key + (dec (count (:via problem))) + [ins/inspector (last (:via problem))]]]]]]] [d/div {:style - {:grid-column "3" + {:grid-column "2" :padding (:padding theme) :border-right [1 :solid (::c/border theme)] :border-top [1 :solid (::c/border theme)]}} - [with-keys - (:in problem) - [ins/inspector (:val problem)]]]]]) - (:clojure.spec.alpha/problems spec)) + [select/with-position + {:row idx :column 2} + [ins/with-key + :clojure.spec.alpha/problems + [ins/with-key idx + [inspect-problem problem]]]]] + [select/with-position + {:row idx :column 3} + [d/div + {:style + {:grid-column "3" + :padding (:padding theme) + :border-right [1 :solid (::c/border theme)] + :border-top [1 :solid (::c/border theme)]}} + [with-keys + (:in problem) + [ins/inspector (:val problem)]]]]]) + (:clojure.spec.alpha/problems spec)) [d/div {:style {:grid-column "4" :grid-row (str "1 / span " (inc (count (:clojure.spec.alpha/problems spec)))) @@ -168,4 +170,4 @@ {:predicate can-view? :component #'inspect-spec :name :portal.viewer/spec - :doc "A viewer for data produced via clojure.spec.alpha/explain-data"}) \ No newline at end of file + :doc "A viewer for data produced via clojure.spec.alpha/explain-data"}) diff --git a/src/portal/ui/viewer/table.cljs b/src/portal/ui/viewer/table.cljs index 68524474..a3f7c72e 100644 --- a/src/portal/ui/viewer/table.cljs +++ b/src/portal/ui/viewer/table.cljs @@ -1,14 +1,16 @@ -(ns ^:no-doc portal.ui.viewer.table - (:require ["react" :as react] - [clojure.spec.alpha :as s] - [portal.colors :as c] - [portal.ui.filter :as f] - [portal.ui.inspector :as ins] - [portal.ui.lazy :as l] - [portal.ui.select :as select] - [portal.ui.styled :as d] - [portal.ui.theme :as theme] - [reagent.core :as r])) +(ns portal.ui.viewer.table + {:no-doc true} + (:require + ["react" :as react] + [clojure.spec.alpha :as s] + [portal.colors :as c] + [portal.ui.filter :as f] + [portal.ui.inspector :as ins] + [portal.ui.lazy :as l] + [portal.ui.select :as select] + [portal.ui.styled :as d] + [portal.ui.theme :as theme] + [reagent.core :as r])) (defonce ^:private hover (react/createContext nil)) @@ -24,19 +26,19 @@ (let [theme (theme/use-theme) context (ins/use-context)] (into - [d/div - {:style - (cond-> - {:display :grid - :grid-gap 1 - :font-size (:font-size theme) - :background (::c/border theme) - :border [1 :solid (::c/border theme)] - :border-radius (:border-radius theme) - :grid-template-columns :min-content} - (not= (:depth context) 1) - (assoc :overflow :auto))}] - children))) + [d/div + {:style + (cond-> + {:display :grid + :grid-gap 1 + :font-size (:font-size theme) + :background (::c/border theme) + :border [1 :solid (::c/border theme)] + :border-radius (:border-radius theme) + :grid-template-columns :min-content} + (not= (:depth context) 1) + (assoc :overflow :auto))}] + children))) (defn- cell [row column child] (let [background (ins/get-background) @@ -54,20 +56,20 @@ :grid-column (str (inc column))}} [d/div {:style (cond-> - {:height "100%" - :width "100%" - :box-sizing :border-box - :padding (:padding theme)} + {:height "100%" + :width "100%" + :box-sizing :border-box + :padding (:padding theme)} (nil? child) (assoc - :background - (list - 'repeating-linear-gradient - "45deg" - [border 0] - [border width] - [background width] - [background (* 3 width)]))) + :background + (list + 'repeating-linear-gradient + "45deg" + [border 0] + [border width] + [background width] + [background (* 3 width)]))) :style/hover {:background (when child (str (::c/border theme) "55"))}} [select/with-position {:row row :column column} child]]])) @@ -79,46 +81,46 @@ [d/div {:style (merge - (cond - (= 0 row column) - {:z-index 3 - :top 0 - :left 0 - :border-bottom [3 :solid (::c/border theme)] - :border-right [3 :solid (::c/border theme)]} - (zero? row) - {:z-index 2 - :top 0 - :text-align :center - :border-bottom [3 :solid (::c/border theme)]} - (zero? column) - {:z-index 1 - :left 0 - :text-align :right - :border-right [3 :solid (::c/border theme)]}) - (cond - @(r/track hover? hover first row) - {:border-right [3 :solid (::c/boolean theme)]} - @(r/track hover? hover second column) - {:border-bottom [3 :solid (::c/boolean theme)]}) - {:position :sticky - :background background - :box-sizing :border-box - :padding (:padding theme) - :grid-row (str (inc row) - (when span (str " / span " span))) - :grid-column (str (inc column))})} + (cond + (= 0 row column) + {:z-index 3 + :top 0 + :left 0 + :border-bottom [3 :solid (::c/border theme)] + :border-right [3 :solid (::c/border theme)]} + (zero? row) + {:z-index 2 + :top 0 + :text-align :center + :border-bottom [3 :solid (::c/border theme)]} + (zero? column) + {:z-index 1 + :left 0 + :text-align :right + :border-right [3 :solid (::c/border theme)]}) + (cond + @(r/track hover? hover first row) + {:border-right [3 :solid (::c/boolean theme)]} + @(r/track hover? hover second column) + {:border-bottom [3 :solid (::c/boolean theme)]}) + {:position :sticky + :background background + :box-sizing :border-box + :padding (:padding theme) + :grid-row (str (inc row) + (when span (str " / span " span))) + :grid-column (str (inc column))})} [select/with-position {:row row :column column} child]])) (defn- columns [cols] [:<> [special 0 0] (map-indexed - (fn [col-index column] - ^{:key (hash column)} - [ins/with-key column - [special 0 (inc col-index) [ins/inspector column]]]) - cols)]) + (fn [col-index column] + ^{:key (hash column)} + [ins/with-key column + [special 0 (inc col-index) [ins/inspector column]]]) + cols)]) (defn- inspect-map-table [values] (let [rows (seq (ins/try-sort (keys values))) @@ -130,28 +132,28 @@ [columns cols] [l/lazy-seq (keep-indexed - (fn [row-index row] - (when (or (matcher row) - (matcher (get values row))) - [:<> - {:key (hash row)} - [ins/with-key row - [special (inc row-index) 0 [ins/inspector row]]] - [ins/toggle-bg + (fn [row-index row] + (when (or (matcher row) + (matcher (get values row))) + [:<> + {:key (hash row)} [ins/with-key row - (map-indexed - (fn [col-index column] - (let [coll (get values row)] - ^{:key col-index} - [ins/with-collection coll - [ins/with-key column - [cell - (inc row-index) - (inc col-index) - (when (contains? coll column) - [ins/inspector (ins/get-props coll column) (get coll column)])]]])) - cols)]]])) - rows)]])) + [special (inc row-index) 0 [ins/inspector row]]] + [ins/toggle-bg + [ins/with-key row + (map-indexed + (fn [col-index column] + (let [coll (get values row)] + ^{:key col-index} + [ins/with-collection coll + [ins/with-key column + [cell + (inc row-index) + (inc col-index) + (when (contains? coll column) + [ins/inspector (ins/get-props coll column) (get coll column)])]]])) + cols)]]])) + rows)]])) (defn- inspect-coll-table [values] (let [rows (seq values) @@ -163,26 +165,26 @@ [columns cols] [l/lazy-seq (keep-indexed - (fn [row-index row] - (when (matcher row) - ^{:key row-index} - [:<> - [ins/with-key row-index - [special (inc row-index) 0 [ins/inspector row-index]]] - [ins/toggle-bg + (fn [row-index row] + (when (matcher row) + ^{:key row-index} + [:<> [ins/with-key row-index - (map-indexed - (fn [col-index column] - ^{:key col-index} - [ins/with-collection row - [ins/with-key column - [cell - (inc row-index) - (inc col-index) - (when (contains? row column) - [ins/inspector (ins/get-props row column) (get row column)])]]]) - cols)]]])) - rows)]])) + [special (inc row-index) 0 [ins/inspector row-index]]] + [ins/toggle-bg + [ins/with-key row-index + (map-indexed + (fn [col-index column] + ^{:key col-index} + [ins/with-collection row + [ins/with-key column + [cell + (inc row-index) + (inc col-index) + (when (contains? row column) + [ins/inspector (ins/get-props row column) (get row column)])]]]) + cols)]]])) + rows)]])) (defn- inspect-vector-table [values] (let [search-text (ins/use-search-text) @@ -192,25 +194,25 @@ [columns cols]) [l/lazy-seq (keep-indexed - (fn [row-index row] - (when (matcher row) - ^{:key row-index} - [:<> - [ins/with-key row-index - [special (inc row-index) 0 [ins/inspector row-index]]] - [ins/toggle-bg + (fn [row-index row] + (when (matcher row) + ^{:key row-index} + [:<> [ins/with-key row-index - (map-indexed - (fn [col-index value] - ^{:key col-index} - [ins/with-collection row - [ins/with-key col-index - [cell - (inc row-index) - (inc col-index) - [ins/inspector value]]]]) - row)]]])) - values)]])) + [special (inc row-index) 0 [ins/inspector row-index]]] + [ins/toggle-bg + [ins/with-key row-index + (map-indexed + (fn [col-index value] + ^{:key col-index} + [ins/with-collection row + [ins/with-key col-index + [cell + (inc row-index) + (inc col-index) + [ins/inspector value]]]]) + row)]]])) + values)]])) (defn- inspect-map [values] (let [rows (seq (ins/try-sort (keys values))) @@ -219,23 +221,23 @@ [table [l/lazy-seq (keep-indexed - (fn [row-index row] - (when (or (matcher row) - (matcher (get values row))) - [:<> - {:key row-index} - [ins/with-key row - [special (inc row-index) 0 [ins/inspector row]]] - [ins/toggle-bg + (fn [row-index row] + (when (or (matcher row) + (matcher (get values row))) + [:<> + {:key row-index} [ins/with-key row - [ins/with-collection values - [ins/with-key row-index - [ins/with-key row - [cell - (inc row-index) - 1 - [ins/inspector (ins/get-props values row) (get values row)]]]]]]]])) - rows)]])) + [special (inc row-index) 0 [ins/inspector row]]] + [ins/toggle-bg + [ins/with-key row + [ins/with-collection values + [ins/with-key row-index + [ins/with-key row + [cell + (inc row-index) + 1 + [ins/inspector (ins/get-props values row) (get values row)]]]]]]]])) + rows)]])) (defn- inspect-multi-map-table [values] (let [rows (seq (ins/try-sort (keys values))) @@ -247,34 +249,34 @@ [columns cols] [l/lazy-seq (keep-indexed - (fn [row-index {:keys [row value index]}] - (when (or (matcher row) (matcher value)) - [:<> - {:key row-index} - (when (zero? index) + (fn [row-index {:keys [row value index]}] + (when (or (matcher row) (matcher value)) + [:<> + {:key row-index} + (when (zero? index) + [ins/with-key row + [special (inc row-index) 0 [ins/inspector row] (count (get values row))]]) + [ins/toggle-bg [ins/with-key row - [special (inc row-index) 0 [ins/inspector row] (count (get values row))]]) - [ins/toggle-bg - [ins/with-key row - (map-indexed - (fn [col-index column] - ^{:key col-index} - [ins/with-collection value - [ins/with-key index - [ins/with-key column - [cell - (inc row-index) - (inc col-index) - (when (contains? value column) - [ins/inspector (ins/get-props value column) (get value column)])]]]]) - cols)]]])) - (mapcat - (fn [row] - (map-indexed - (fn [index value] - {:row row :value value :index index}) - (get values row))) - rows))]])) + (map-indexed + (fn [col-index column] + ^{:key col-index} + [ins/with-collection value + [ins/with-key index + [ins/with-key column + [cell + (inc row-index) + (inc col-index) + (when (contains? value column) + [ins/inspector (ins/get-props value column) (get value column)])]]]]) + cols)]]])) + (mapcat + (fn [row] + (map-indexed + (fn [index value] + {:row row :value value :index index}) + (get values row))) + rows))]])) ;;; :spec (s/def ::map map?) diff --git a/src/portal/ui/viewer/test_report.cljs b/src/portal/ui/viewer/test_report.cljs index 745c7528..5f21d407 100644 --- a/src/portal/ui/viewer/test_report.cljs +++ b/src/portal/ui/viewer/test_report.cljs @@ -1,13 +1,15 @@ -(ns ^:no-doc portal.ui.viewer.test-report - (:require [clojure.spec.alpha :as s] - [portal.colors :as c] - [portal.ui.filter :as-alias f] - [portal.ui.icons :as icons] - [portal.ui.inspector :as ins] - [portal.ui.select :as select] - [portal.ui.styled :as d] - [portal.ui.theme :as theme] - [portal.ui.viewer.source-location :as src])) +(ns portal.ui.viewer.test-report + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [portal.colors :as c] + [portal.ui.filter :as-alias f] + [portal.ui.icons :as icons] + [portal.ui.inspector :as ins] + [portal.ui.select :as select] + [portal.ui.styled :as d] + [portal.ui.theme :as theme] + [portal.ui.viewer.source-location :as src])) ;;; :spec (s/def :test-run/type #{:end-run-tests}) @@ -174,10 +176,10 @@ (update :vars (fnil conj empty-vec) (merge - (summary (:asserts state)) - {:ns test-ns - :var test-var - :asserts (:asserts state 0)}))))) + (summary (:asserts state)) + {:ns test-ns + :var test-var + :asserts (:asserts state 0)}))))) (defn- end-test-ns [{:keys [test-ns vars] :as state}] (-> state @@ -185,41 +187,41 @@ (update :results (fnil conj empty-vec) (merge - (summary vars) - {:ns test-ns - :vars vars})))) + (summary vars) + {:ns test-ns + :vars vars})))) (defn- get-results [value] (let [include? (when value (into #{} value))] (:results - (reduce - (fn [{:keys [test-ns test-var] :as state} row] - (case (:type row) - :summary state - :begin-test-ns (assoc state :test-ns (:ns row)) - :end-test-ns (-> state end-test-var end-test-ns) - :begin-test-var (assoc state :test-var (:var row)) - :end-test-var (end-test-var state) - (if (and value (not (include? row))) - state - (update - state - :asserts - (fnil conj empty-vec) - (cond-> row - test-ns (assoc :ns test-ns) - test-var (assoc :var test-var)))))) - {:results empty-vec} - value)))) + (reduce + (fn [{:keys [test-ns test-var] :as state} row] + (case (:type row) + :summary state + :begin-test-ns (assoc state :test-ns (:ns row)) + :end-test-ns (-> state end-test-var end-test-ns) + :begin-test-var (assoc state :test-var (:var row)) + :end-test-var (end-test-var state) + (if (and value (not (include? row))) + state + (update + state + :asserts + (fnil conj empty-vec) + (cond-> row + test-ns (assoc :ns test-ns) + test-var (assoc :var test-var)))))) + {:results empty-vec} + value)))) (defn- group-assertions [value] (let [results (get-results value)] (if (= 1 (count results)) (first results) (merge - (summary results) - {:message :test-report - :results results})))) + (summary results) + {:message :test-report + :results results})))) (defn- inspect-test-report [value] [inspect-assertion (group-assertions value)]) diff --git a/src/portal/ui/viewer/text.cljs b/src/portal/ui/viewer/text.cljs index 36e3a6eb..dc3ea92a 100644 --- a/src/portal/ui/viewer/text.cljs +++ b/src/portal/ui/viewer/text.cljs @@ -1,10 +1,12 @@ -(ns ^:no-doc portal.ui.viewer.text - (:require [clojure.string :as str] - [portal.colors :as c] - [portal.ui.inspector :as ins] - [portal.ui.lazy :as l] - [portal.ui.styled :as s] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.text + {:no-doc true} + (:require + [clojure.string :as str] + [portal.colors :as c] + [portal.ui.inspector :as ins] + [portal.ui.lazy :as l] + [portal.ui.styled :as s] + [portal.ui.theme :as theme])) (defn inspect-text [value] (let [theme (theme/use-theme) @@ -25,39 +27,39 @@ [s/tbody [l/lazy-seq (->> - (str/split value #"\n") - (map-indexed - (fn [line line-content] - [(inc line) line-content])) - (filter - (fn [[_ line-content]] - (if search-text - (some - #(str/includes? line-content %) - (str/split search-text #"\s+")) - true))) - (map - (fn [[line line-content]] - [s/tr - {:key line} - [s/td - {:style - {:color (::c/number theme) - :background background - :font-size (:font-size theme) - :user-select :none - :text-align :right - :vertical-align :top - :padding-right (* 2 (:padding theme))}} - [s/span line]] - [s/td - {:style - {:color (::c/text theme) - :background background - :text-align :left - :font-size (:font-size theme)}} - [:pre {:style {:margin 0 :white-space :pre-wrap}} - [ins/highlight-words line-content]]]]))) + (str/split value #"\n") + (map-indexed + (fn [line line-content] + [(inc line) line-content])) + (filter + (fn [[_ line-content]] + (if search-text + (some + #(str/includes? line-content %) + (str/split search-text #"\s+")) + true))) + (map + (fn [[line line-content]] + [s/tr + {:key line} + [s/td + {:style + {:color (::c/number theme) + :background background + :font-size (:font-size theme) + :user-select :none + :text-align :right + :vertical-align :top + :padding-right (* 2 (:padding theme))}} + [s/span line]] + [s/td + {:style + {:color (::c/text theme) + :background background + :text-align :left + :font-size (:font-size theme)}} + [:pre {:style {:margin 0 :white-space :pre-wrap}} + [ins/highlight-words line-content]]]]))) {:default-take 100 :step 100}]]]])) (def viewer diff --git a/src/portal/ui/viewer/transit.cljs b/src/portal/ui/viewer/transit.cljs index a8466289..e0d1c268 100644 --- a/src/portal/ui/viewer/transit.cljs +++ b/src/portal/ui/viewer/transit.cljs @@ -1,7 +1,9 @@ -(ns ^:no-doc portal.ui.viewer.transit - (:require [cognitect.transit :as t] - [portal.ui.inspector :as ins] - [portal.ui.parsers :as p])) +(ns portal.ui.viewer.transit + {:no-doc true} + (:require + [cognitect.transit :as t] + [portal.ui.inspector :as ins] + [portal.ui.parsers :as p])) (defn- parse-transit [transit-string] (try (t/read (t/reader :json) transit-string) diff --git a/src/portal/ui/viewer/tree.cljs b/src/portal/ui/viewer/tree.cljs index 198ee064..fffc3236 100644 --- a/src/portal/ui/viewer/tree.cljs +++ b/src/portal/ui/viewer/tree.cljs @@ -1,10 +1,12 @@ -(ns ^:no-doc portal.ui.viewer.tree - (:require [portal.ui.filter :as f] - [portal.ui.inspector :as ins] - [portal.ui.lazy :as l] - [portal.ui.select :as select] - [portal.ui.styled :as s] - [portal.ui.theme :as theme])) +(ns portal.ui.viewer.tree + {:no-doc true} + (:require + [portal.ui.filter :as f] + [portal.ui.inspector :as ins] + [portal.ui.lazy :as l] + [portal.ui.select :as select] + [portal.ui.styled :as s] + [portal.ui.theme :as theme])) (defn- delimiter [value] (cond @@ -40,20 +42,20 @@ :text-align :center}} [ins/toggle-expand]] [s/div {:style (merge - {:grid-row "1" - :grid-column "3" - :color color - :position :relative - :border-left border - :border-right border - :border-top border - :border-top-right-radius (:border-radius theme) - :border-top-left-radius (:border-radius theme) - :background selected-background} - (when-not expanded? - {:border-bottom border - :border-bottom-right-radius (:border-radius theme) - :border-bottom-left-radius (:border-radius theme)})) + {:grid-row "1" + :grid-column "3" + :color color + :position :relative + :border-left border + :border-right border + :border-top border + :border-top-right-radius (:border-radius theme) + :border-top-left-radius (:border-radius theme) + :background selected-background} + (when-not expanded? + {:border-bottom border + :border-bottom-right-radius (:border-radius theme) + :border-bottom-left-radius (:border-radius theme)})) :on-click (:on-click wrapper-options)} open (when-not expanded? [:<> close [:sub (count value)]]) @@ -124,47 +126,47 @@ [ins/with-collection value [l/lazy-seq (keep-indexed - (fn [idx [k v]] - (when (or (matcher k) (matcher v)) - (if-not (ins/coll? v) - ^{:key idx} - [s/div - {:style {:display :flex - :gap (:padding theme)}} + (fn [idx [k v]] + (when (or (matcher k) (matcher v)) + (if-not (ins/coll? v) + ^{:key idx} [s/div + {:style {:display :flex + :gap (:padding theme)}} + [s/div + [ins/with-key k + [select/with-position + {:row idx :column 0} + [ins/inspector {:portal.viewer/inspector {:toggle-bg false}} k]]]] [ins/with-key k [select/with-position - {:row idx :column 0} - [ins/inspector {:portal.viewer/inspector {:toggle-bg false}} k]]]] - [ins/with-key k - [select/with-position - {:row idx :column 1} - [ins/inspector {:portal.viewer/inspector {:toggle-bg false}} v]]]] + {:row idx :column 1} + [ins/inspector {:portal.viewer/inspector {:toggle-bg false}} v]]]] - ^{:key idx} - [ins/toggle-bg - [s/div - {:style {:display :grid - :grid-template-columns "auto auto 1fr"}} + ^{:key idx} + [ins/toggle-bg [s/div - {:style {:grid-row "1" :grid-column "2" - :padding [0 (:padding theme)]}} + {:style {:display :grid + :grid-template-columns "auto auto 1fr"}} + [s/div + {:style {:grid-row "1" :grid-column "2" + :padding [0 (:padding theme)]}} + [ins/with-key k + [select/with-position + {:row idx :column 0} + [ins/inspector + {:portal.viewer/default :portal.viewer/tree + :portal.viewer/inspector {:wrapper wrapper :toggle-bg false}} + k]]]] [ins/with-key k [select/with-position - {:row idx :column 0} + {:row idx :column 1} [ins/inspector {:portal.viewer/default :portal.viewer/tree + :portal.viewer/tree {:parent :tree} :portal.viewer/inspector {:wrapper wrapper :toggle-bg false}} - k]]]] - [ins/with-key k - [select/with-position - {:row idx :column 1} - [ins/inspector - {:portal.viewer/default :portal.viewer/tree - :portal.viewer/tree {:parent :tree} - :portal.viewer/inspector {:wrapper wrapper :toggle-bg false}} - v]]]]]))) - (ins/try-sort-map value))]])) + v]]]]]))) + (ins/try-sort-map value))]])) (defn- inspect-tree-coll [value] (let [theme (theme/use-theme) @@ -173,33 +175,33 @@ [ins/with-collection value [l/lazy-seq (keep-indexed - (fn [idx v] - (when (matcher v) - (if-not (ins/coll? v) - ^{:key idx} - [s/div - [ins/with-key idx - [select/with-position - {:row idx :column 0} - [ins/inspector - {:portal.viewer/inspector {:toggle-bg false}} - v]]]] - ^{:key idx} - [s/div - {:style {:display :grid - :grid-template-columns "auto auto 1fr"}} + (fn [idx v] + (when (matcher v) + (if-not (ins/coll? v) + ^{:key idx} + [s/div + [ins/with-key idx + [select/with-position + {:row idx :column 0} + [ins/inspector + {:portal.viewer/inspector {:toggle-bg false}} + v]]]] + ^{:key idx} [s/div - {:style {:grid-row "1" :grid-column "2" - :padding [0 (:padding theme)]}}] - [ins/with-key idx - [select/with-position - {:row idx :column 0} - [ins/inspector - {:portal.viewer/default :portal.viewer/tree - :portal.viewer/tree {:parent :tree} - :portal.viewer/inspector {:wrapper wrapper :toggle-bg false}} - v]]]]))) - value)]])) + {:style {:display :grid + :grid-template-columns "auto auto 1fr"}} + [s/div + {:style {:grid-row "1" :grid-column "2" + :padding [0 (:padding theme)]}}] + [ins/with-key idx + [select/with-position + {:row idx :column 0} + [ins/inspector + {:portal.viewer/default :portal.viewer/tree + :portal.viewer/tree {:parent :tree} + :portal.viewer/inspector {:wrapper wrapper :toggle-bg false}} + v]]]]))) + value)]])) (defn inspect-tree [value] (let [opts (ins/use-options) @@ -216,4 +218,4 @@ {:predicate ins/coll? :component #'inspect-tree :name :portal.viewer/tree - :doc "For viewing highly nested values, such as hiccup."}) \ No newline at end of file + :doc "For viewing highly nested values, such as hiccup."}) diff --git a/src/portal/ui/viewer/vega.cljs b/src/portal/ui/viewer/vega.cljs index de717ad7..c6680725 100644 --- a/src/portal/ui/viewer/vega.cljs +++ b/src/portal/ui/viewer/vega.cljs @@ -1,14 +1,16 @@ -(ns ^:no-doc portal.ui.viewer.vega +(ns portal.ui.viewer.vega "Viewer for the Vega-Lite specification https://vega.github.io/vega/docs/specification/" - (:require ["react" :as react] - ["vega-embed" :as vegaEmbed] - [clojure.spec.alpha :as s] - [portal.colors :as c] - [portal.ui.inspector :as ins] - [portal.ui.react :refer [use-effect]] - [portal.ui.styled :as d] - [portal.ui.theme :as theme])) + {:no-doc true} + (:require + ["react" :as react] + ["vega-embed" :as vegaEmbed] + [clojure.spec.alpha :as s] + [portal.colors :as c] + [portal.ui.inspector :as ins] + [portal.ui.react :refer [use-effect]] + [portal.ui.styled :as d] + [portal.ui.theme :as theme])) ;;; :spec (def vega-url #"https://vega\.github\.io/schema/vega/v\d\.json") @@ -26,19 +28,19 @@ (let [theme (theme/use-theme)] [:style (d/map->css - {[:.vega-embed :.chart-wrapper] - {:width "fit-content" - :height "fit-content"} - [:.vega-embed] - {:width "100%"} - [:.vega-embed :summary] - {:opacity 1 - :cursor :default - :position :absolute - :right (* 0.5 (:padding theme)) - :top (* 0.5 (:padding theme)) - :z-index 0 - :transform "scale(0.6)"}})])) + {[:.vega-embed :.chart-wrapper] + {:width "fit-content" + :height "fit-content"} + [:.vega-embed] + {:width "100%"} + [:.vega-embed :summary] + {:opacity 1 + :cursor :default + :position :absolute + :right (* 0.5 (:padding theme)) + :top (* 0.5 (:padding theme)) + :z-index 0 + :transform "scale(0.6)"}})])) (defn- default-config "Specifies a nicer set of vega-lite specification styles. @@ -85,15 +87,15 @@ (let [ref (react/useRef nil) [rect set-rect!] (react/useState #js {:height 200 :width 200})] (use-effect - #js [(.-current ref)] - (when-let [el (.-current ref)] - (let [resize-observer - (js/ResizeObserver. - (fn [] - (set-rect! (.getBoundingClientRect el))))] - (.observe resize-observer el) - (fn [] - (.disconnect resize-observer))))) + #js [(.-current ref)] + (when-let [el (.-current ref)] + (let [resize-observer + (js/ResizeObserver. + (fn [] + (set-rect! (.getBoundingClientRect el))))] + (.observe resize-observer el) + (fn [] + (.disconnect resize-observer))))) [ref rect])) (defn vega-embed [opts value] @@ -110,24 +112,24 @@ width (.-width relative-rect)] (use-effect - #js [(hash theme)] - (when-let [el (.-current absolute)] - (-> (vegaEmbed el (clj->js (assoc doc :width width)) (clj->js opts)) - (.then (fn [value] - (set! (.-current view) (.-view value)) - (set-init! true))) - (.catch (fn [err] (js/console.error err))))) - #(when-let [view (.-current view)] - (.finalize view) - (set! (.-current view) nil))) + #js [(hash theme)] + (when-let [el (.-current absolute)] + (-> (vegaEmbed el (clj->js (assoc doc :width width)) (clj->js opts)) + (.then (fn [value] + (set! (.-current view) (.-view value)) + (set-init! true))) + (.catch (fn [err] (js/console.error err))))) + #(when-let [view (.-current view)] + (.finalize view) + (set! (.-current view) nil))) (use-effect - #js [init (.-current view) width] - (when-let [view (.-current view)] - (let [width (- width 2 - (* 2 (:padding theme)))] - (.width view width) - (.run view)))) + #js [init (.-current view) width] + (when-let [view (.-current view)] + (let [width (- width 2 + (* 2 (:padding theme)))] + (.width view width) + (.run view)))) [d/div (when-let [title (:title value)] diff --git a/src/portal/ui/viewer/vega_lite.cljs b/src/portal/ui/viewer/vega_lite.cljs index 53846baa..caa64dc2 100644 --- a/src/portal/ui/viewer/vega_lite.cljs +++ b/src/portal/ui/viewer/vega_lite.cljs @@ -1,8 +1,10 @@ -(ns ^:no-doc portal.ui.viewer.vega-lite +(ns portal.ui.viewer.vega-lite "Viewer for the Vega-Lite specification https://vega.github.io/vega-lite/docs/spec.html" - (:require [clojure.spec.alpha :as s] - [portal.ui.viewer.vega :as vega])) + {:no-doc true} + (:require + [clojure.spec.alpha :as s] + [portal.ui.viewer.vega :as vega])) ;;; :spec (def vega-lite-url #"https://vega\.github\.io/schema/vega-lite/v\d\.json") diff --git a/src/portal/viewer.cljc b/src/portal/viewer.cljc index 55cca2ef..b5b7747f 100644 --- a/src/portal/viewer.cljc +++ b/src/portal/viewer.cljc @@ -2,7 +2,7 @@ "Namespace for easily setting default viewers for provided values. Note: Support for input validation may come in the future." - (:refer-clojure :exclude [pr-str for])) + (:refer-clojure :exclude [for pr-str])) (declare hiccup) @@ -182,4 +182,4 @@ (defn size-bytes ([value] (default value ::size-bytes)) - ([value opts] (default value ::size-bytes opts))) \ No newline at end of file + ([value opts] (default value ::size-bytes opts))) diff --git a/src/portal/web.cljs b/src/portal/web.cljs index 44cb4421..03510e60 100644 --- a/src/portal/web.cljs +++ b/src/portal/web.cljs @@ -1,10 +1,11 @@ (ns portal.web - (:require [clojure.set :as set] - [portal.runtime :as rt] - [portal.runtime.web.client :as c] - [portal.runtime.web.launcher :as l] - [portal.shortcuts :as shortcuts] - [portal.spec :as s])) + (:require + [clojure.set :as set] + [portal.runtime :as rt] + [portal.runtime.web.client :as c] + [portal.runtime.web.launcher :as l] + [portal.shortcuts :as shortcuts] + [portal.spec :as s])) (def ^:export send! l/send!) @@ -103,12 +104,12 @@ (reset! init? true) (l/init @rt/default-options) (shortcuts/add! - ::init - (fn [log] - (when (shortcuts/match? - {::shortcuts/osx #{"meta" "shift" "o"} - ::shortcuts/default #{"control" "shift" "o"}} - log) - (open)))))) + ::init + (fn [log] + (when (shortcuts/match? + {::shortcuts/osx #{"meta" "shift" "o"} + ::shortcuts/default #{"control" "shift" "o"}} + log) + (open)))))) (js/setTimeout init 0) diff --git a/test/portal/bench.cljc b/test/portal/bench.cljc index 861e2fdb..81b3b384 100644 --- a/test/portal/bench.cljc +++ b/test/portal/bench.cljc @@ -1,6 +1,9 @@ (ns portal.bench - #?(:cljs (:refer-clojure :exclude [simple-benchmark])) - #?(:cljs (:require-macros portal.bench))) + #?(:cljs + (:refer-clojure :exclude [simple-benchmark])) + #?(:cljs + (:require-macros + [portal.bench]))) (defn- now ([] @@ -43,13 +46,13 @@ (defn run* [f ^long n] (dotimes [_ n] (f)) (simple-stats - (loop [i 0 results (transient [])] - (if (== i n) - (persistent! results) - (let [start (now) - _ (f) - end (now start)] - (recur (unchecked-inc i) - (conj! results (trunc end)))))))) + (loop [i 0 results (transient [])] + (if (== i n) + (persistent! results) + (let [start (now) + _ (f) + end (now start)] + (recur (unchecked-inc i) + (conj! results (trunc end)))))))) (defmacro run [expr n] `(run* #(do ~expr) ~n)) diff --git a/test/portal/client_test.cljc b/test/portal/client_test.cljc index dc244cbd..d0f57d30 100644 --- a/test/portal/client_test.cljc +++ b/test/portal/client_test.cljc @@ -1,22 +1,25 @@ (ns portal.client-test - #?(:clj - (:require [clojure.test :refer [deftest is]] - [portal.api :as p] - [portal.client.jvm :as c] - [portal.runtime :as rt] - [portal.sync :as a]) - :cljr - (:require [clojure.test :refer [deftest is]] - [portal.api :as p] - [portal.client.clr :as c] - [portal.runtime :as rt] - [portal.sync :as a]) - :cljs - (:require [clojure.test :refer [async deftest is]] - [portal.api :as p] - [portal.async :as a] - [portal.client.node :as c] - [portal.runtime :as rt]))) + (:require + #?@(:clj + [[clojure.test :refer [deftest is]] + [portal.api :as p] + [portal.client.jvm :as c] + [portal.runtime :as rt] + [portal.sync :as a]] + + :cljr + [[clojure.test :refer [deftest is]] + [portal.api :as p] + [portal.client.clr :as c] + [portal.runtime :as rt] + [portal.sync :as a]] + + :cljs + [[clojure.test :refer [async deftest is]] + [portal.api :as p] + [portal.async :as a] + [portal.client.node :as c] + [portal.runtime :as rt]]))) (def ^:private bad-seq (map (fn [_] (throw (ex-info "Error" {}))) (range 10))) @@ -34,4 +37,4 @@ (deftest client-test #?(:cljs (async done (client-test* done)) - :default (client-test* (constantly nil)))) \ No newline at end of file + :default (client-test* (constantly nil)))) diff --git a/test/portal/e2e.clj b/test/portal/e2e.clj index 1ae66318..df3bc44c 100644 --- a/test/portal/e2e.clj +++ b/test/portal/e2e.clj @@ -1,5 +1,6 @@ (ns portal.e2e - (:require [portal.colors :as c])) + (:require + [portal.colors :as c])) (defn step [code] (binding [*out* *err*] diff --git a/test/portal/runtime/api_test.clj b/test/portal/runtime/api_test.clj index fe261314..96201835 100644 --- a/test/portal/runtime/api_test.clj +++ b/test/portal/runtime/api_test.clj @@ -1,7 +1,8 @@ (ns portal.runtime.api-test - (:require [clojure.test :refer [deftest is]] - [portal.api :as p] - [portal.runtime.browser :as browser])) + (:require + [clojure.test :refer [deftest is]] + [portal.api :as p] + [portal.runtime.browser :as browser])) (defn- headless-chrome-flags [url] ["--headless=new" "--disable-gpu" url]) @@ -21,8 +22,8 @@ (is (= 6 (p/eval-str portal "*1"))) (is (= :world (:hello (p/eval-str portal "{:hello :world}")))) (is (thrown? - clojure.lang.ExceptionInfo - (p/eval-str portal "(throw (ex-info \"error\" {:hello :world}))"))) + clojure.lang.ExceptionInfo + (p/eval-str portal "(throw (ex-info \"error\" {:hello :world}))"))) (is (= :hi (p/eval-str portal "(.resolve js/Promise :hi)" {:await true}))) (is (some? (some #{portal} (p/sessions)))) (p/close portal))) diff --git a/test/portal/runtime/api_test.cljs b/test/portal/runtime/api_test.cljs index 34b51079..e376d606 100644 --- a/test/portal/runtime/api_test.cljs +++ b/test/portal/runtime/api_test.cljs @@ -1,8 +1,9 @@ (ns portal.runtime.api-test - (:require [clojure.test :refer [async deftest is]] - [portal.api :as p] - [portal.async :as a] - [portal.runtime.browser :as browser])) + (:require + [clojure.test :refer [async deftest is]] + [portal.api :as p] + [portal.async :as a] + [portal.runtime.browser :as browser])) (defn- headless-chrome-flags [url] ["--headless=new" "--disable-gpu" url]) diff --git a/test/portal/runtime/bench_cson.cljc b/test/portal/runtime/bench_cson.cljc index 9a8cdfcd..3ee23f2e 100644 --- a/test/portal/runtime/bench_cson.cljc +++ b/test/portal/runtime/bench_cson.cljc @@ -1,10 +1,11 @@ (ns portal.runtime.bench-cson - (:require [clojure.edn :as edn] - [examples.data :as d] - [portal.bench :as b] - [portal.runtime.cson :as cson] - [portal.runtime.transit :as transit] - [portal.viewer :as v])) + (:require + [clojure.edn :as edn] + [examples.data :as d] + [portal.bench :as b] + [portal.runtime.cson :as cson] + [portal.runtime.transit :as transit] + [portal.viewer :as v])) (def bench-data {:platform-data (select-keys d/platform-data [::d/uuid ::d/date]) @@ -26,64 +27,64 @@ (defn run-benchmark [] (doall - (let [n 10 bench-data (assoc bench-data :all bench-data)] - (concat - (for [[data value] bench-data - encoding formats] - (merge - (case encoding - :transit (let [value (transit/write value)] - (b/run (transit/read value) n)) - :edn (let [value (pr-meta value)] - (b/run (edn/read-string value) n)) - :cson (let [value (cson/write value)] - (b/run (cson/read value) n))) - {:test :read - :encoding encoding - :data data - :benchmark (pr-str (keyword (name encoding) "read"))})) - (for [[data value] bench-data - encoding formats] - (merge - (case encoding - :transit (b/run (transit/write value) n) - :edn (b/run (pr-meta value) n) - :cson (b/run (cson/write value) n)) - {:test :write - :encoding encoding - :data data - :benchmark (pr-str (keyword (name encoding) "write"))})))))) + (let [n 10 bench-data (assoc bench-data :all bench-data)] + (concat + (for [[data value] bench-data + encoding formats] + (merge + (case encoding + :transit (let [value (transit/write value)] + (b/run (transit/read value) n)) + :edn (let [value (pr-meta value)] + (b/run (edn/read-string value) n)) + :cson (let [value (cson/write value)] + (b/run (cson/read value) n))) + {:test :read + :encoding encoding + :data data + :benchmark (pr-str (keyword (name encoding) "read"))})) + (for [[data value] bench-data + encoding formats] + (merge + (case encoding + :transit (b/run (transit/write value) n) + :edn (b/run (pr-meta value) n) + :cson (b/run (cson/write value) n)) + {:test :write + :encoding encoding + :data data + :benchmark (pr-str (keyword (name encoding) "write"))})))))) (defn charts [data] (->> (group-by :data data) (sort-by - (fn [[_ values]] - (reduce - + - (keep - (fn [{:keys [encoding total]}] - (when (= :cson encoding) - total)) - values))) - >) + (fn [[_ values]] + (reduce + + + (keep + (fn [{:keys [encoding total]}] + (when (= :cson encoding) + total)) + values))) + >) (map - (fn [[label values]] - (with-meta - [:div - [:h3 {:style {:text-align :center}} label] - [:portal.viewer/inspector - (-> {:$schema "https://vega.github.io/schema/vega-lite/v5.json" - :data {:values values} - :mark {:type :bar :tooltip true} - :encoding - {:x {:aggregate :sum :field :total} - :y {:field :benchmark - :type :ordinal - :sort {:op :sum :field :total :order :descending}} - :color {:field :encoding}}} - (v/vega-lite) - (vary-meta assoc :value (get bench-data label bench-data)))]] - {:key (str label)}))) + (fn [[label values]] + (with-meta + [:div + [:h3 {:style {:text-align :center}} label] + [:portal.viewer/inspector + (-> {:$schema "https://vega.github.io/schema/vega-lite/v5.json" + :data {:values values} + :mark {:type :bar :tooltip true} + :encoding + {:x {:aggregate :sum :field :total} + :y {:field :benchmark + :type :ordinal + :sort {:op :sum :field :total :order :descending}} + :color {:field :encoding}}} + (v/vega-lite) + (vary-meta assoc :value (get bench-data label bench-data)))]] + {:key (str label)}))) (into [:div {:style {:display :grid :gap 20 @@ -92,46 +93,46 @@ (defn table [data] (v/table - (->> - (for [[label tests] (group-by :data data)] - (with-meta - (into {:label label} - (for [{:keys [encoding test total]} tests] - [(keyword (name encoding) (name test)) total])) - {:portal.viewer/for - (zipmap (for [{:keys [encoding test]} tests] - (keyword (name encoding) (name test))) - (repeat :portal.viewer/duration-ms))})) - (sort-by :cson/read) - (into [])) - {:columns - #?(:cljr - [:label - :edn/write :cson/write - :edn/read :cson/read] - :org.babashka/nbb - [:label - :edn/write :cson/write - :edn/read :cson/read] - :default - [:label - :edn/write :transit/write :cson/write - :edn/read :transit/read :cson/read])})) + (->> + (for [[label tests] (group-by :data data)] + (with-meta + (into {:label label} + (for [{:keys [encoding test total]} tests] + [(keyword (name encoding) (name test)) total])) + {:portal.viewer/for + (zipmap (for [{:keys [encoding test]} tests] + (keyword (name encoding) (name test))) + (repeat :portal.viewer/duration-ms))})) + (sort-by :cson/read) + (into [])) + {:columns + #?(:cljr + [:label + :edn/write :cson/write + :edn/read :cson/read] + :org.babashka/nbb + [:label + :edn/write :cson/write + :edn/read :cson/read] + :default + [:label + :edn/write :transit/write :cson/write + :edn/read :transit/read :cson/read])})) (defn combined-chart [values] (v/vega-lite - {:$schema "https://vega.github.io/schema/vega-lite/v5.json" - :data {:values values} - :mark :bar - :encoding - {:x {:field :data - :sort {:op :sum :field :total :order :descending}} - :y {:field :total - :type :quantitative - :aggregate :sum} - :xOffset {:field :benchmark - :sort {:op :sum :field :total :order :descending}} - :color {:field :benchmark}}})) + {:$schema "https://vega.github.io/schema/vega-lite/v5.json" + :data {:values values} + :mark :bar + :encoding + {:x {:field :data + :sort {:op :sum :field :total :order :descending}} + :y {:field :total + :type :quantitative + :aggregate :sum} + :xOffset {:field :benchmark + :sort {:op :sum :field :total :order :descending}} + :color {:field :benchmark}}})) (comment (def data (run-benchmark)) @@ -140,4 +141,4 @@ (def no-edn (remove (comp #{:edn} :encoding) data)) (tap> [no-edn (table no-edn) (charts no-edn) (combined-chart no-edn)])) -(defn run [] (table (run-benchmark))) \ No newline at end of file +(defn run [] (table (run-benchmark))) diff --git a/test/portal/runtime/cson_test.cljc b/test/portal/runtime/cson_test.cljc index e556f1bd..50363ceb 100644 --- a/test/portal/runtime/cson_test.cljc +++ b/test/portal/runtime/cson_test.cljc @@ -1,10 +1,14 @@ (ns portal.runtime.cson-test - (:require [clojure.test :refer [deftest are is]] - [portal.runtime.cson :as cson]) - #?(:clj (:import [java.util Date] - [java.util UUID]) - :cljr (:import [System DateTime Guid] - [System.Text Encoding]))) + (:require + [clojure.test :refer [are deftest is]] + [portal.runtime.cson :as cson]) + (:import + #?@(:clj + [(java.util Date UUID)] + + :cljr + [(System DateTime Guid) + (System.Text Encoding)]))) (defn pass [v] (cson/read (cson/write v))) @@ -12,44 +16,44 @@ (deftest simple-values (are [value] (= value (pass value)) - nil - 0 - 1.0 - 1.5 - #?(:clj 42N - :cljr 42N - :joyride (js/BigInt "42") - :cljs (when (exists? js/BigInt) - (js/BigInt "42"))) - \newline - true - false - 'hello - 'hello/world - :hello - :hello/world - "" - "hello" - "hello/world")) + nil + 0 + 1.0 + 1.5 + #?(:clj 42N + :cljr 42N + :joyride (js/BigInt "42") + :cljs (when (exists? js/BigInt) + (js/BigInt "42"))) + \newline + true + false + 'hello + 'hello/world + :hello + :hello/world + "" + "hello" + "hello/world")) (deftest escape-strings (are [value] (= value (pass value)) - "\n" - "\"" - " \"hello\" ")) + "\n" + "\"" + " \"hello\" ")) (deftest basic-collections (are [value] (= value (pass value)) - [] - [1 2 3] - {} - {:a :b} - #{} - #{1 2 3} - '() - (list 1 2 3))) + [] + [1 2 3] + {} + {:a :b} + #{} + #{1 2 3} + '() + (list 1 2 3))) (def composite-value ['hello @@ -71,20 +75,20 @@ (deftest composite-collections (are [value] (= value (pass value)) - [[[]]] - #{#{#{}}} - {{} {}} - {[] []} - {#{} #{}} - {(list) (list)} - (list [] #{} {}) - composite-value)) + [[[]]] + #{#{#{}}} + {{} {}} + {[] []} + {#{} #{}} + {(list) (list)} + (list [] #{} {}) + composite-value)) (deftest special-collections (are [value] (= value (pass value)) - (range 10) - (first {:a 1}))) + (range 10) + (first {:a 1}))) (deftest range-with-meta (let [v (with-meta (range 0 5 1.0) {:my :meta})] @@ -99,10 +103,10 @@ (deftest seq-collections (are [value] (= (seq value) (pass (seq value))) - '(0) - [0] - #{0} - {0 0})) + '(0) + [0] + #{0} + {0 0})) (deftest sorted-collections (let [a (sorted-map :a 1 :c 3 :b 2) @@ -146,8 +150,8 @@ (are [v] (= v (pass v)) v1 v2) (are [v] (= (meta* v) (meta* (pass v))) v1 v2)) (is (thrown? - #?(:clj AssertionError :cljr Exception :cljs js/Error) - (cson/tagged-value :my/tag {:hello :world})) + #?(:clj AssertionError :cljr Exception :cljs js/Error) + (cson/tagged-value :my/tag {:hello :world})) "only allow string tags")) (deftest metadata @@ -198,4 +202,4 @@ (let [bin #?(:clj (.getBytes "hi") :cljr (.GetBytes Encoding/UTF8 "hi") :cljs (.encode (js/TextEncoder.) "hi"))] - (is (= "[\"bin\",\"aGk=\"]" (cson/write bin))))) \ No newline at end of file + (is (= "[\"bin\",\"aGk=\"]" (cson/write bin))))) diff --git a/test/portal/runtime/edn_test.cljc b/test/portal/runtime/edn_test.cljc index b418cc38..8bbccf78 100644 --- a/test/portal/runtime/edn_test.cljc +++ b/test/portal/runtime/edn_test.cljc @@ -1,6 +1,7 @@ (ns portal.runtime.edn-test - (:require [clojure.test :refer [deftest is]] - [portal.runtime.edn :as edn])) + (:require + [clojure.test :refer [deftest is]] + [portal.runtime.edn :as edn])) (deftest read-string-test (let [tagged (edn/read-string "^{:my :meta} #'hi")] @@ -16,4 +17,4 @@ #?(:org.babashka/nbb nil :default (let [s "#function [clojure.core/constantly/fn--5740]"] - (is (= s (pr-str (edn/read-string s))))))) \ No newline at end of file + (is (= s (pr-str (edn/read-string s))))))) diff --git a/test/portal/runtime/fs_test.cljc b/test/portal/runtime/fs_test.cljc index 48e1f2ba..1dd2974c 100644 --- a/test/portal/runtime/fs_test.cljc +++ b/test/portal/runtime/fs_test.cljc @@ -1,6 +1,7 @@ (ns portal.runtime.fs-test - (:require [clojure.test :refer [deftest is]] - [portal.runtime.fs :as fs])) + (:require + [clojure.test :refer [deftest is]] + [portal.runtime.fs :as fs])) (deftest fs-test (is (some? (fs/slurp "deps.edn"))) @@ -11,8 +12,8 @@ (is (some? (fs/is-file "deps.edn"))) (is (nil? (fs/is-file "deps.end"))) (is (contains? - (into #{} (fs/list (fs/cwd))) - (fs/join (fs/cwd) "deps.edn"))) + (into #{} (fs/list (fs/cwd))) + (fs/join (fs/cwd) "deps.edn"))) (let [dir (str "target/" (gensym)) file (str dir "/" (gensym))] (fs/mkdir dir) diff --git a/test/portal/runtime/json_buffer_test.cljc b/test/portal/runtime/json_buffer_test.cljc index b5c633df..e048752d 100644 --- a/test/portal/runtime/json_buffer_test.cljc +++ b/test/portal/runtime/json_buffer_test.cljc @@ -1,6 +1,7 @@ (ns portal.runtime.json-buffer-test - (:require [clojure.test :refer [deftest is]] - [portal.runtime.json-buffer :as b])) + (:require + [clojure.test :refer [deftest is]] + [portal.runtime.json-buffer :as b])) (defn- write-json [buffer _] (-> buffer diff --git a/test/portal/runtime/jvm/editor_test.clj b/test/portal/runtime/jvm/editor_test.clj index cebc491a..16f84a98 100644 --- a/test/portal/runtime/jvm/editor_test.clj +++ b/test/portal/runtime/jvm/editor_test.clj @@ -1,57 +1,58 @@ (ns portal.runtime.jvm.editor-test - (:require [clojure.java.io :as io] - [clojure.test :refer [are deftest]] - [portal.runtime] - [portal.runtime.fs :as fs] - [portal.runtime.jvm.editor :as editor])) + (:require + [clojure.java.io :as io] + [clojure.test :refer [are deftest]] + [portal.runtime] + [portal.runtime.fs :as fs] + [portal.runtime.jvm.editor :as editor])) (deftest can-goto-test (are [value] (fs/exists (:file (editor/can-goto value))) - ;; maps - {:file "deps.edn"} - {:ns 'portal.runtime} + ;; maps + {:file "deps.edn"} + {:ns 'portal.runtime} - ;; vars - #'portal.runtime/ops + ;; vars + #'portal.runtime/ops - ;; namespace symbols - 'portal.runtime - 'portal.runtime/ops + ;; namespace symbols + 'portal.runtime + 'portal.runtime/ops - ;; urls - (io/resource "portal/runtime.cljc") + ;; urls + (io/resource "portal/runtime.cljc") - ;; files - (io/file "deps.edn") + ;; files + (io/file "deps.edn") - ;; strings - "deps.edn" - "src/portal/runtime.cljc" + ;; strings + "deps.edn" + "src/portal/runtime.cljc" - ;; string on classpath - "portal/runtime.cljc") + ;; string on classpath + "portal/runtime.cljc") (are [value] (not (fs/exists (:file (editor/can-goto value)))) - ;; maps - {:file "missing.edn"} - {:ns 'ns.missing} - {} + ;; maps + {:file "missing.edn"} + {:ns 'ns.missing} + {} - ;; namespace symbols - 'ns.missing - 'ns.missing/conj + ;; namespace symbols + 'ns.missing + 'ns.missing/conj - ;; urls - (io/resource "portal/missing.cljc") + ;; urls + (io/resource "portal/missing.cljc") - ;; files - (io/file "missing.edn") + ;; files + (io/file "missing.edn") - ;; strings - "missing.edn" - "src/portal/missing.cljc" + ;; strings + "missing.edn" + "src/portal/missing.cljc" - ;; string on classpath - "portal/missing.cljc")) + ;; string on classpath + "portal/missing.cljc")) diff --git a/test/portal/runtime/npm_test.cljc b/test/portal/runtime/npm_test.cljc index 72d6c9a0..925d52d3 100644 --- a/test/portal/runtime/npm_test.cljc +++ b/test/portal/runtime/npm_test.cljc @@ -1,21 +1,22 @@ (ns portal.runtime.npm-test - (:require [clojure.test :refer [are deftest]] - [portal.runtime.fs :as fs] - [portal.runtime.npm :refer [node-resolve]] - [portal.runtime.shell :refer [sh]])) + (:require + [clojure.test :refer [are deftest]] + [portal.runtime.fs :as fs] + [portal.runtime.npm :refer [node-resolve]] + [portal.runtime.shell :refer [sh]])) (deftest valid-modules (when-not (fs/exists "node_modules") (sh "npm" "install" "react@^17.0.2")) (are [module] (some? (node-resolve module)) - "react/jsx-runtime.js" - "react/index" - "react")) + "react/jsx-runtime.js" + "react/index" + "react")) (deftest invalid-modules (are [module] (thrown? - #?(:clj Exception :cljr Exception :cljs js/Error) - (node-resolve module)) - "react/index.j")) + #?(:clj Exception :cljr Exception :cljs js/Error) + (node-resolve module)) + "react/index.j")) diff --git a/test/portal/runtime/shell_test.cljc b/test/portal/runtime/shell_test.cljc index f7509b05..efcf9f5e 100644 --- a/test/portal/runtime/shell_test.cljc +++ b/test/portal/runtime/shell_test.cljc @@ -1,7 +1,8 @@ (ns portal.runtime.shell-test - (:require [clojure.test :refer [deftest is]] - [portal.runtime.shell :as sh])) + (:require + [clojure.test :refer [deftest is]] + [portal.runtime.shell :as sh])) (deftest echo (is (= {:exit 0, :out "hello\n", :err ""} - (sh/sh "echo" "hello")))) \ No newline at end of file + (sh/sh "echo" "hello")))) diff --git a/test/portal/runtime_test.cljc b/test/portal/runtime_test.cljc index 9979bce0..041cd1ef 100644 --- a/test/portal/runtime_test.cljc +++ b/test/portal/runtime_test.cljc @@ -1,6 +1,7 @@ (ns portal.runtime-test - (:require [clojure.test :refer [are deftest is]] - [portal.runtime :as rt])) + (:require + [clojure.test :refer [are deftest is]] + [portal.runtime :as rt])) (deftest un-hashable-values (let [value #?(:bb :skip @@ -22,23 +23,23 @@ (are [a b] (= (#'rt/value->key a) (#'rt/value->key b)) - [] [] + [] [] - [1] [1] + [1] [1] - ^:one [1] ^:one [1] + ^:one [1] ^:one [1] - {:a ^:one [1]} - {:a ^:one [1]}) + {:a ^:one [1]} + {:a ^:one [1]}) (are [a b] (not= (#'rt/value->key a) (#'rt/value->key b)) - [1] '(1) + [1] '(1) - #{1 2 3} (sorted-set 1 2 3) + #{1 2 3} (sorted-set 1 2 3) - ^{:one 1} [] ^{:two 2} [] + ^{:one 1} [] ^{:two 2} [] - {:a ^{:one 2} [1]} - {:a ^{:two 2} [1]})) \ No newline at end of file + {:a ^{:one 2} [1]} + {:a ^{:two 2} [1]})) diff --git a/test/portal/test_clr.clj b/test/portal/test_clr.clj index 78f6a2e1..c6deb5ea 100644 --- a/test/portal/test_clr.clj +++ b/test/portal/test_clr.clj @@ -1,18 +1,20 @@ (ns portal.test-clr - (:require [clojure.pprint :as pp] - [clojure.test :as t] - [portal.client-test] - [portal.client.clr :as p] - [portal.runtime-test] - [portal.runtime.api-test] - [portal.runtime.bench-cson :as bench] - [portal.runtime.cson-test] - [portal.runtime.edn-test] - [portal.runtime.fs-test] - [portal.runtime.json-buffer-test] - [portal.runtime.npm-test] - [portal.runtime.shell-test]) - (:import (System Environment))) + (:require + [clojure.pprint :as pp] + [clojure.test :as t] + [portal.client-test] + [portal.client.clr :as p] + [portal.runtime-test] + [portal.runtime.api-test] + [portal.runtime.bench-cson :as bench] + [portal.runtime.cson-test] + [portal.runtime.edn-test] + [portal.runtime.fs-test] + [portal.runtime.json-buffer-test] + [portal.runtime.npm-test] + [portal.runtime.shell-test]) + (:import + (System Environment))) (def port (Environment/GetEnvironmentVariable "PORTAL_PORT")) @@ -22,8 +24,8 @@ (if port (submit value) (pp/print-table - (get-in (meta value) [:portal.viewer/table :columns]) - value))) + (get-in (meta value) [:portal.viewer/table :columns]) + value))) (defn run-tests [& tests] (if-not port @@ -38,14 +40,14 @@ (defn -main [] (let [{:keys [fail error]} (run-tests - 'portal.client-test - 'portal.runtime-test - 'portal.runtime.api-test - 'portal.runtime.cson-test - 'portal.runtime.edn-test - 'portal.runtime.fs-test - 'portal.runtime.json-buffer-test - 'portal.runtime.npm-test - 'portal.runtime.shell-test)] + 'portal.client-test + 'portal.runtime-test + 'portal.runtime.api-test + 'portal.runtime.cson-test + 'portal.runtime.edn-test + 'portal.runtime.fs-test + 'portal.runtime.json-buffer-test + 'portal.runtime.npm-test + 'portal.runtime.shell-test)] (table (bench/run)) (Environment/Exit (+ fail error)))) diff --git a/test/portal/test_planck.cljs b/test/portal/test_planck.cljs index 94b39c05..49ff80c9 100644 --- a/test/portal/test_planck.cljs +++ b/test/portal/test_planck.cljs @@ -1,11 +1,12 @@ (ns portal.test-planck - (:require [cljs.test :refer [run-tests]] - [clojure.pprint :as pp] - [planck.core :refer [exit]] - [planck.environ :refer [env]] - [portal.client.planck :as p] - [portal.runtime.bench-cson :as bench] - [portal.runtime.cson-test])) + (:require + [cljs.test :refer [run-tests]] + [clojure.pprint :as pp] + [planck.core :refer [exit]] + [planck.environ :refer [env]] + [portal.client.planck :as p] + [portal.runtime.bench-cson :as bench] + [portal.runtime.cson-test])) (defmethod cljs.test/report [:cljs.test/default :end-run-tests] [m] (when-not (cljs.test/successful? m) @@ -19,8 +20,8 @@ (if port (submit value) (pp/print-table - (get-in (meta value) [:portal.viewer/table :columns]) - value))) + (get-in (meta value) [:portal.viewer/table :columns]) + value))) (defn -main [] (run-tests 'portal.runtime.cson-test) diff --git a/test/portal/test_runner.clj b/test/portal/test_runner.clj index f11249b8..5768a4fc 100644 --- a/test/portal/test_runner.clj +++ b/test/portal/test_runner.clj @@ -1,18 +1,19 @@ (ns portal.test-runner - (:require [clojure.pprint :as pp] - [clojure.test :as t] - [portal.client-test] - [portal.client.jvm :as p] - [portal.runtime-test] - [portal.runtime.api-test] - [portal.runtime.bench-cson :as bench] - [portal.runtime.cson-test] - [portal.runtime.edn-test] - [portal.runtime.fs-test] - [portal.runtime.json-buffer-test] - [portal.runtime.jvm.editor-test] - [portal.runtime.npm-test] - [portal.runtime.shell-test])) + (:require + [clojure.pprint :as pp] + [clojure.test :as t] + [portal.client-test] + [portal.client.jvm :as p] + [portal.runtime-test] + [portal.runtime.api-test] + [portal.runtime.bench-cson :as bench] + [portal.runtime.cson-test] + [portal.runtime.edn-test] + [portal.runtime.fs-test] + [portal.runtime.json-buffer-test] + [portal.runtime.jvm.editor-test] + [portal.runtime.npm-test] + [portal.runtime.shell-test])) (def port (System/getenv "PORTAL_PORT")) @@ -22,8 +23,8 @@ (if port (submit value) (pp/print-table - (get-in (meta value) [:portal.viewer/table :columns]) - value))) + (get-in (meta value) [:portal.viewer/table :columns]) + value))) (defn run-tests [& tests] (if-not port diff --git a/test/portal/test_runner.cljs b/test/portal/test_runner.cljs index dbf39222..a973f250 100644 --- a/test/portal/test_runner.cljs +++ b/test/portal/test_runner.cljs @@ -1,8 +1,9 @@ (ns portal.test-runner - (:require [clojure.pprint :as pp] - [clojure.test :as t] - [portal.async :as a] - [portal.client.node :as p])) + (:require + [clojure.pprint :as pp] + [clojure.test :as t] + [portal.async :as a] + [portal.client.node :as p])) (defmethod cljs.test/report [:cljs.test/default :end-run-tests] [m] (when-not (cljs.test/successful? m) @@ -16,8 +17,8 @@ (if port (submit value) (pp/print-table - (get-in (meta value) [:portal.viewer/table :columns]) - value))) + (get-in (meta value) [:portal.viewer/table :columns]) + value))) (defn run-tests [f] (if-not port diff --git a/test/portal/test_runtime_runner.cljs b/test/portal/test_runtime_runner.cljs index a4a7fe3a..3e0d43fd 100644 --- a/test/portal/test_runtime_runner.cljs +++ b/test/portal/test_runtime_runner.cljs @@ -1,30 +1,31 @@ (ns portal.test-runtime-runner - (:require [clojure.string :as str] - [clojure.test :as t] - [portal.client-test] - [portal.runtime-test] - [portal.runtime.api-test] - [portal.runtime.bench-cson :as bench] - [portal.runtime.cson-test] - [portal.runtime.edn-test] - [portal.runtime.fs-test] - [portal.runtime.json-buffer-test] - [portal.runtime.npm-test] - [portal.runtime.shell-test] - [portal.test-runner :as runner])) + (:require + [clojure.string :as str] + [clojure.test :as t] + [portal.client-test] + [portal.runtime-test] + [portal.runtime.api-test] + [portal.runtime.bench-cson :as bench] + [portal.runtime.cson-test] + [portal.runtime.edn-test] + [portal.runtime.fs-test] + [portal.runtime.json-buffer-test] + [portal.runtime.npm-test] + [portal.runtime.shell-test] + [portal.test-runner :as runner])) (defn -main [] (runner/run - #(t/run-tests 'portal.client-test - 'portal.runtime-test - 'portal.runtime.api-test - 'portal.runtime.cson-test - 'portal.runtime.edn-test - 'portal.runtime.fs-test - 'portal.runtime.json-buffer-test - 'portal.runtime.npm-test - 'portal.runtime.shell-test)) + #(t/run-tests 'portal.client-test + 'portal.runtime-test + 'portal.runtime.api-test + 'portal.runtime.cson-test + 'portal.runtime.edn-test + 'portal.runtime.fs-test + 'portal.runtime.json-buffer-test + 'portal.runtime.npm-test + 'portal.runtime.shell-test)) (runner/table (bench/run))) (when-not (str/ends-with? (second js/process.argv) "nbb") - (-main)) \ No newline at end of file + (-main)) diff --git a/test/portal/test_ui_runner.cljs b/test/portal/test_ui_runner.cljs index 90d49cd9..bb4e7e87 100644 --- a/test/portal/test_ui_runner.cljs +++ b/test/portal/test_ui_runner.cljs @@ -1,16 +1,17 @@ (ns portal.test-ui-runner - (:require [clojure.test :as t] - [portal.runtime.cson-test] - [portal.runtime.edn-test] - [portal.runtime.json-buffer-test] - [portal.test-runner :as runner] - [portal.ui.state-test])) + (:require + [clojure.test :as t] + [portal.runtime.cson-test] + [portal.runtime.edn-test] + [portal.runtime.json-buffer-test] + [portal.test-runner :as runner] + [portal.ui.state-test])) (defn -main [] (runner/run - #(t/run-tests 'portal.runtime.cson-test - 'portal.runtime.edn-test - 'portal.runtime.json-buffer-test - 'portal.ui.state-test))) + #(t/run-tests 'portal.runtime.cson-test + 'portal.runtime.edn-test + 'portal.runtime.json-buffer-test + 'portal.ui.state-test))) (-main) diff --git a/test/portal/ui/state_test.cljs b/test/portal/ui/state_test.cljs index 9e1491c7..903c09b7 100644 --- a/test/portal/ui/state_test.cljs +++ b/test/portal/ui/state_test.cljs @@ -1,6 +1,7 @@ (ns portal.ui.state-test - (:require [clojure.test :refer [deftest is]] - [portal.ui.state :as state])) + (:require + [clojure.test :refer [deftest is]] + [portal.ui.state :as state])) (deftest expanded-test (let [state nil