Skip to content

Commit

Permalink
more emmy viewers
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuebert committed Aug 2, 2023
1 parent b202acf commit a4ab62c
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions editor2/src/main/maria/editor/extensions/emmy.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,41 @@
[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]
[maria.editor.extensions.reagent :as ext.reagent]
[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")]
Expand Down

0 comments on commit a4ab62c

Please sign in to comment.