diff --git a/src/nextjournal/clerk.clj b/src/nextjournal/clerk.clj index 4e601b6ec..9d113b294 100644 --- a/src/nextjournal/clerk.clj +++ b/src/nextjournal/clerk.clj @@ -12,7 +12,8 @@ [nextjournal.clerk.eval :as eval] [nextjournal.clerk.parser :as parser] [nextjournal.clerk.viewer :as v] - [nextjournal.clerk.webserver :as webserver])) + [nextjournal.clerk.webserver :as webserver] + [nextjournal.clerk.window :as window])) (defonce ^:private !show-filter-fn (atom nil)) (defonce ^:private !last-file (atom nil)) @@ -78,9 +79,9 @@ #_(show! "https://raw.githubusercontent.com/nextjournal/clerk-demo/main/notebooks/rule_30.clj") #_(show! (java.io.StringReader. ";; # In Memory Notebook 👋\n(+ 41 1)")) -(defn window! "todo" [& args] (apply (requiring-resolve 'nextjournal.clerk.window/open!) args)) -(defn close-window! "todo" [id] ((requiring-resolve 'nextjournal.clerk.window/close!) id)) -(defn close-all-windows! "todo" [] ((requiring-resolve 'nextjournal.clerk.window/close-all!))) +(defn window! [& args] (apply window/open! args)) +(defn close-window! [id] (window/close! id)) +(defn close-all-windows! [] (window/close-all!)) (defn recompute! "Recomputes the currently visible doc, without parsing it." diff --git a/src/nextjournal/clerk/tap.clj b/src/nextjournal/clerk/tap.clj index 3eaf9ec68..6b7cb02fa 100644 --- a/src/nextjournal/clerk/tap.clj +++ b/src/nextjournal/clerk/tap.clj @@ -1,8 +1,7 @@ ;; # 🚰 Tap Inspector (ns nextjournal.clerk.tap {:nextjournal.clerk/visibility {:code :hide :result :hide}} - (:require [nextjournal.clerk :as clerk] - [nextjournal.clerk.viewer :as v]) + (:require [nextjournal.clerk.viewer :as v]) (:import (java.time Instant LocalTime ZoneId))) (defn inst->local-time-str [inst] (str (LocalTime/ofInstant inst (ZoneId/systemDefault)))) @@ -24,18 +23,18 @@ [:button.text-xs.rounded-full.px-3.py-1.border-2.font-sans.hover:bg-slate-100.cursor-pointer {:on-click #(nextjournal.clerk.render/clerk-eval `(reset-taps!))} "Clear"]])))) -^{::clerk/sync true ::clerk/viewer switch-view ::clerk/visibility {:result :show}} +^{:nextjournal.clerk/sync true :nextjournal.clerk/viewer switch-view :nextjournal.clerk/visibility {:result :show}} (defonce !view (atom :stream)) (defonce !taps (atom ())) (defn reset-taps! [] (reset! !taps ()) - (clerk/recompute!)) + ((resolve 'nextjournal.clerk/recompute!))) (defn tapped [x] (swap! !taps conj (record-tap x)) - (clerk/recompute!)) + ((resolve 'nextjournal.clerk/recompute!))) (defonce tap-setup (add-tap (fn [x] ((resolve `tapped) x)))) @@ -57,10 +56,10 @@ (update-in [:nextjournal/value ::tapped-at] inst->local-time-str)))}) -^{::clerk/visibility {:result :show} - ::clerk/viewers (v/add-viewers [tap-viewer])} -(clerk/fragment (cond->> @!taps - (= :latest @!view) (take 1))) +^{:nextjournal.clerk/visibility {:result :show} + :nextjournal.clerk/viewers (v/add-viewers [tap-viewer])} +(v/fragment (cond->> @!taps + (= :latest @!view) (take 1))) (comment (last @!taps) @@ -69,9 +68,9 @@ (tap> (shuffle (range (+ 20 (rand-int 200))))) (tap> (clerk/md "> The purpose of visualization is **insight**, not pictures.")) (tap> (v/plotly {:data [{:z [[1 2 3] [3 2 1]] :type "surface"}]})) - (tap> (clerk/html {::clerk/width :full} [:h1.w-full.border-2.border-amber-500.bg-amber-500.h-10])) - (tap> (clerk/table {::clerk/width :full} [[1 2] [3 4]])) - (tap> (clerk/plotly {::clerk/width :full} {:data [{:y [3 1 2]}]})) + (tap> (clerk/html {:nextjournal.clerk/width :full} [:h1.w-full.border-2.border-amber-500.bg-amber-500.h-10])) + (tap> (clerk/table {:nextjournal.clerk/width :full} [[1 2] [3 4]])) + (tap> (clerk/plotly {:nextjournal.clerk/width :full} {:data [{:y [3 1 2]}]})) (tap> (clerk/image "trees.png")) (do (require 'rule-30) (tap> (clerk/with-viewers (clerk/add-viewers rule-30/viewers) rule-30/rule-30)))