portal

Sam Ritchie 2023-06-04T15:35:16.480039Z

@djblue what pattern would you recommend for passing configuration options to a viewer? I can guess here that the answer is “rpc!” but I wanted to check. katex supports a bunch of configuration options, like custom macros: https://katex.org/docs/options.html I can pass them in here, in this options map:

Sam Ritchie 2023-06-05T13:06:11.328659Z

I accidentally passed :zenburn vs :portal.colors/zenburn and I kind of like the old macOS vibes!!

😂 1
Sam Ritchie 2023-06-05T13:20:45.542289Z

@djblue works great!!

(def portal
  (p/start!
   {:emmy.portal/tex {:macros {"\\f" "#1f(#2)"}}
    :theme :portal.colors/zenburn}))
do you have opinions on a convention for passing options here? nested under :viewers, or without the key prefix, etc?

Sam Ritchie 2023-06-05T13:29:45.999579Z

it might be nice to have a load-viewer or something that takes a namespace symbol and does this automatically:

(-> (io/resource "emmy/portal/tex.cljs")
    (slurp)
    (p/eval-str))

djblue 2023-06-05T19:22:24.829359Z

I could see adding something like the following to portal.api:

(defn load-ns [ns]
  (p/eval-str (pr-str (list 'require ns))))

Sam Ritchie 2023-06-05T19:24:37.209479Z

Oh nice is that enough, instead of my explicit slurp and eval-str?

Sam Ritchie 2023-06-05T19:24:40.020009Z

So good

djblue 2023-06-05T19:25:38.206889Z

I think it would work, however, now you might need to specify :reload to re-require the ns 🤔

djblue 2023-06-05T19:26:50.208229Z

Maybe this instead:

(defn load-ns [& args]
  (p/eval-str (pr-str (conj args 'require))))

djblue 2023-06-05T19:27:21.028819Z

Then you could (load-ns 'emmy.portal.tex :reload)

Sam Ritchie 2023-06-04T15:36:15.570289Z

(defn get-opts []
  #js {:throwOnError false
       :displayMode true})

(defn tex [_]
  (let [opts (get-opts)]
    (fn [text]
      [:span
       {:dangerouslySetInnerHTML
        {:__html
         (k/renderToString text opts)}}])))

Sam Ritchie 2023-06-04T15:37:30.834129Z

actually I’m not sure RPC call is the right way; I can figure that out, but I think I want to be able to take these options as arguments to my start! wrapper and supply them to the viewer

Sam Ritchie 2023-06-04T15:39:18.959579Z

I love btw that with this {:on-load install!} flag you have, I can make changes to the viewers and reload the Chrome page and all changes are picked up

💯 1
djblue 2023-06-04T15:41:04.209519Z

I think https://github.com/djblue/portal/blob/master/src/portal/ui/options.cljs#L33 is probably what you want but it isn't available to sci just yet 🤔

Sam Ritchie 2023-06-04T15:46:03.967899Z

yeah that sounds like it!

Sam Ritchie 2023-06-04T15:46:51.157979Z

I would use it for mafs, for example, to let the user select the default theme vs the mafs theme

Sam Ritchie 2023-06-04T15:47:11.113189Z

and for tex of course there are a bunch of options w/ the link above

djblue 2023-06-04T15:48:53.017409Z

If you still have a copy of portal locally, you can quickly add it here https://github.com/djblue/portal/blob/master/src/portal/ui/sci/libs.cljs#L10

Sam Ritchie 2023-06-04T15:49:21.948799Z

nice I’ll give it a try

Sam Ritchie 2023-06-04T15:49:50.529919Z

I’m going to push today/tomorrow toward getting this all tested, documented and merged… I am taking the “get an enormous PR that does everything and then cut off tidy sections” approach

😂 1
djblue 2023-06-04T15:56:54.209089Z

I would pull latest as well, you can pass in {:theme :portal.colors/zenburn} to open with a different theme:ok_hand:

🎉 1
Sam Ritchie 2023-06-04T19:02:42.945459Z

@djblue so then I get access to all options that I’ve passed to p/open;

Sam Ritchie 2023-06-04T19:03:02.830579Z

Do I have to wrap my component in with-options , or does portal do that for me?

djblue 2023-06-04T19:38:53.765249Z

To get options, you just need to call the use-options hook

Sam Ritchie 2023-06-04T20:02:05.047839Z

Yes for sure I was just wondering if I also have to call with-options to populate the context

djblue 2023-06-04T20:03:36.295439Z

Gotcha, yeah context gets populated on app init here https://github.com/djblue/portal/blob/master/src/portal/ui/core.cljs#L44

❤️ 1
Sam Ritchie 2023-06-04T15:42:56.004299Z

sorry to overshare here but this is nuts… I: • send out a Mafs chart using (of-x sin) • it renders and wraps itself in the appropriate (mafs/mafs (mafs/cartesian) …) shell • I then SELECT THE GRAPH in Portal, which makes the original fragment available via @portal • I can then build a new scene that includes @portal

(tap> (mafs/mafs
         (mafs/cartesian)
         @portal
         (mafs/of-y exp {:color :green})))

🙌 2