From a4ab62c0a2a9cc14a1b099919fefec8f78dc4c63 Mon Sep 17 00:00:00 2001 From: Matthew Huebert Date: Wed, 2 Aug 2023 15:19:38 -0600 Subject: [PATCH] more emmy viewers --- .../main/maria/editor/extensions/emmy.cljs | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/editor2/src/main/maria/editor/extensions/emmy.cljs b/editor2/src/main/maria/editor/extensions/emmy.cljs index 1fb818f3..16b29252 100644 --- a/editor2/src/main/maria/editor/extensions/emmy.cljs +++ b/editor2/src/main/maria/editor/extensions/emmy.cljs @@ -4,6 +4,7 @@ [emmy.value] [emmy.expression] [emmy.operator] + [emmy.series] [emmy.portal.css :refer [inject!] :rename {inject! inject-css!}] [emmy.viewer.css :refer [css-map]] [emmy.mafs] @@ -11,17 +12,33 @@ [maria.editor.code.show-values :as show :refer [show]] [sci.ctx-store :refer [get-ctx]])) +(defn show-frozen [opts x] + (show opts (emmy.value/freeze x))) + +(defn show-expression-of [opts x] + (show opts (emmy.expression/expression-of x))) + +(defn show-string [opts x] + (str x)) + +(def viewers-by-type + {emmy.expression/Literal show-expression-of + emmy.operator/Operator show-frozen + emmy.series/PowerSeries show-frozen + emmy.series/Series show-frozen + js/BigInt show-string}) + (defn show-emmy [opts x] - (cond (emmy.operator/operator? x) (show opts (emmy.value/freeze x)) - (instance? emmy.expression/Literal x) (show opts (emmy.expression/expression-of x)) - (instance? Fraction x) (str x) - :else - (when-let [m (meta x)] - (cond (= emmy.mafs/default-viewer (:nextjournal.clerk/viewer m)) - (show/reagent-eval opts (emmy.viewer/expand x)) - - (:portal.viewer/reagent? m) - (show/reagent-eval opts x))))) + (if (instance? Fraction x) + (str x) + (if-let [viewer (viewers-by-type (type x))] + (viewer opts x) + (when-let [m (meta x)] + (cond (= emmy.mafs/default-viewer (:nextjournal.clerk/viewer m)) + (show/reagent-eval opts (emmy.viewer/expand x)) + + (:portal.viewer/reagent? m) + (show/reagent-eval opts x)))))) (defn inject-css-source! [source] (let [style (.createElement js/document "style")]