Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chakra fixes 2 #2133

Merged
merged 4 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 51 additions & 29 deletions src/cljs/athens/parse_renderer.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
[athens.router :as router]
[clojure.string :as str]
[instaparse.core :as insta]
[re-frame.core :as rf]))
[re-frame.core :as rf]
[reagent.core :as r]))


(declare parse-and-render)


(def fm-props
{:as "b"
:class "formatting"
:class "fmt"
:whiteSpace "nowrap"
:fontWeight "normal"
:opacity "0.3"})
Expand All @@ -40,30 +41,54 @@
:textDecoration "none"})


(defn page-link-el
[]
(let [this (r/current-component)]
(into [:> Box {:as "span"
:sx {".link" {:color "link"
:borderRadius "1px"
:cursor "pointer"
:minWidth "0"
:whiteSpace "inherit"
:wordBreak "inherit"
:alignItems "flex-start"
:justifyContent "flex-start"
:lineHeight "unset"
:position "relative"
:textAlign "inherit"
:display "inline"
:fontSize "inherit"
:fontWeight "inherit"
:textDecoration "none"}
".fmt" (merge {:whiteSpace "nowrap"
:display "inline"
:color "foreground.secondary"
:fontWeight "normal"
:opacity "0.3"})}}]
(r/children this))))


(defn parse-title
"Title coll is a sequence of plain strings or hiccup elements. If string, return string, otherwise parse the hiccup
for its plain-text representation."
[title-coll]
(->> (map (fn [el]
(if (string? el)
el
(str "[[" (str/join (get-in el [3 2])) "]]"))) title-coll)
(str "[[" (str/join (get-in el [2 2])) "]]"))) title-coll)
(str/join "")))


(defn render-page-link
"Renders a page link given the title of the page."
[{:keys [from title]} title-coll]
[:<>
[:> Text fm-props "[["]
[page-link-el
[:span {:class "fmt"} "[["]
(cond
(not (str/blank? title))
[:> Button
(merge link-props
{:class "page-link"
:fontWeight "normal"
:title from
:onClick (fn [e]
[:span {:class "link"
:title from
:on-click (fn [e]
(let [parsed-title (parse-title title-coll)
shift? (.-shiftKey e)]
(.. e stopPropagation) ; prevent bubbling up click handler for nested links
Expand All @@ -72,27 +97,24 @@
:pane (if shift?
:right-pane
:main-pane)}])
(router/navigate-page parsed-title e)))})
(router/navigate-page parsed-title e)))}
title]

:else
(into
[:> Button
(merge link-props
{:class "page-link"
:title from
:onClick (fn [e]
(let [parsed-title (parse-title title-coll)
shift? (.-shiftKey e)]
(.. e stopPropagation) ; prevent bubbling up click handler for nested links
(rf/dispatch [:reporting/navigation {:source :pr-page-link
:target :page
:pane (if shift?
:right-pane
:main-pane)}])
(router/navigate-page parsed-title e)))})]
title-coll))
[:> Text fm-props "]]"]])
(into [:span {:class "link"
:title from
:on-click (fn [e]
(let [parsed-title (parse-title title-coll)
shift? (.-shiftKey e)]
(.. e stopPropagation) ; prevent bubbling up click handler for nested links
(rf/dispatch [:reporting/navigation {:source :pr-page-link
:target :page
:pane (if shift?
:right-pane
:main-pane)}])
(router/navigate-page parsed-title e)))}]
title-coll))
[:span {:class "fmt"} "]]"]])


(defn- block-breadcrumb-string
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/Block/components/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const _Content = ({ children, fontSize, ...props }) => {
gridArea: "main",
},
// activate interactive content (links, buttons, etc.)
"a, button, label, video, embed, iframe, img": {
"a, .link, button, label, video, embed, iframe, img": {
pointerEvents: "auto",
zIndex: 2,
},
Expand Down