Skip to content

Commit

Permalink
Drop render-map, use different key for assigned parens
Browse files Browse the repository at this point in the history
  • Loading branch information
mk committed May 25, 2023
1 parent eda1dfb commit bc34e40
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
34 changes: 10 additions & 24 deletions src/nextjournal/clerk/render.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -428,21 +428,21 @@
[triangle expanded?]]
[:span.group-hover:text-indigo-700 opening-paren]]))

(defn render-coll [xs {:as opts :keys [closing-paren path viewer !expanded-at] :or {path []}}]
(defn render-coll [xs {:as opts :keys [closing-parens path viewer !expanded-at] :or {path []}}]
(let [expanded? (get @!expanded-at path)
{:keys [opening-paren]} viewer]
{:keys [opening-paren closing-paren]} viewer]
(prn :clos closing-paren closing-parens )
[:span.inspected-value.whitespace-nowrap
{:class (when expanded? "inline-flex")}
[:span
(if (< 1 (count xs))
(if (expandable? xs)
[expand-button !expanded-at opening-paren path]
[:span opening-paren])
(into [:<>]
(comp (inspect-children opts)
(interpose (if expanded? [:<> [:br] triangle-spacer nbsp (when (= 2 (count opening-paren)) nbsp)] " ")))
xs)
[:span
(cond->> closing-paren (list? closing-paren) (into [:<>]))]]]))
(into [:span] (or closing-parens [closing-paren]))]]))

(defn render-elision [{:as fetch-opts :keys [total offset unbounded?]} _]
[view-context/consume :fetch-fn
Expand All @@ -455,20 +455,6 @@
:on-click #(when (fn? fetch-fn)
(fetch-fn fetch-opts))} (- total offset) (when unbounded? "+") (if (fn? fetch-fn) " more…" " more elided")])])

(defn render-map [xs {:as opts :keys [closing-paren path viewer !expanded-at] :or {path []}}]
(let [expanded? (get @!expanded-at path)]
[:span.inspected-value.whitespace-nowrap
{:class (when expanded? "inline-flex")}
[:span
(if (expandable? xs)
[expand-button !expanded-at "{" path]
[:span "{"])
(into [:<>]
(comp (inspect-children opts)
(interpose (if expanded? [:<> [:br] triangle-spacer nbsp #_(repeat (inc (count path)) nbsp)] " ")))
xs)
(cond->> closing-paren (list? closing-paren) (into [:<>]))]]))


(defn render-string [s {:as opts :keys [path !expanded-at] :or {path []}}]
(let [expanded? (get @!expanded-at path)]
Expand All @@ -480,16 +466,16 @@
(inspect-presented opts %)))
(if (string? s) [s] s))))

(defn render-quoted-string [s {:as opts :keys [closing-paren path viewer !expanded-at] :or {path []}}]
(let [{:keys [opening-paren]} viewer]
(defn render-quoted-string [s {:as opts :keys [closing-parens path viewer !expanded-at] :or {path []}}]
(let [{:keys [opening-paren closing-paren]} viewer]
[:span.inspected-value.inline-flex
[:span.cmt-string
(if (some #(and (string? %) (str/includes? % "\n")) (if (string? s) [s] s))
[expand-button !expanded-at opening-paren path]
[:span opening-paren])]
[:div
[:span.cmt-string (viewer/->value (render-string s opts)) (first closing-paren)]
(when (list? closing-paren) (into [:<>] (rest closing-paren)))]]))
(into [:div
[:span.cmt-string (viewer/->value (render-string s opts)) (first closing-paren)]
(rest closing-parens)])]))

(defn render-number [num]
[:span.cmt-number.inspected-value
Expand Down
8 changes: 4 additions & 4 deletions src/nextjournal/clerk/viewer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@
{:pred sequential? :name `sequential-viewer :render-fn 'nextjournal.clerk.render/render-coll :opening-paren "(" :closing-paren ")" :page-size 20})

(def map-viewer
{:pred map? :name `map-viewer :render-fn 'nextjournal.clerk.render/render-map :opening-paren "{" :closing-paren "}" :page-size 10})
{:pred map? :name `map-viewer :render-fn 'nextjournal.clerk.render/render-coll :opening-paren "{" :closing-paren "}" :page-size 10})

#?(:cljs (defn var->symbol [v] (if (instance? sci.lang.Var v) (sci.impl.vars/toSymbol v) (symbol v))))

Expand Down Expand Up @@ -1640,9 +1640,9 @@
(or (-> value last :nextjournal/viewer :closing-paren) ;; the last element can carry parens
(and (= `map-entry-viewer (-> value last :nextjournal/viewer :name)) ;; the last element is a map entry whose value can carry parens
(-> value last :nextjournal/value last :nextjournal/viewer :closing-paren))))]
(cond-> (if (or (not closing) defer-closing?)
node
(assoc-in node [:nextjournal/opts :closing-paren] (cons closing closing-parens)))
(cond-> (assoc-in node [:nextjournal/opts :closing-parens] (if (or (not closing) defer-closing?)
'()
(cons closing closing-parens)))
non-leaf? (update :nextjournal/value
(fn [xs]
(into []
Expand Down

0 comments on commit bc34e40

Please sign in to comment.