mirror of https://github.com/logseq/logseq
WIP
parent
3e1aef7236
commit
84df65c638
|
@ -90,13 +90,14 @@
|
||||||
{
|
{
|
||||||
;; enter
|
;; enter
|
||||||
13 (fn [state e]
|
13 (fn [state e]
|
||||||
(when-let [input-value (get state ::input-value)]
|
(let [input-value (get state ::input-value)]
|
||||||
(util/stop e)
|
(when @input-value
|
||||||
(let [[id on-submit] (:rum/args state)
|
(util/stop e)
|
||||||
{:keys [pos]} @*slash-caret-pos]
|
(let [[id on-submit] (:rum/args state)
|
||||||
(on-submit @input-value pos)
|
{:keys [pos]} @*slash-caret-pos]
|
||||||
(.focus (gdom/getElement id)))
|
(on-submit @input-value pos)
|
||||||
(reset! input-value nil)))}
|
(.focus (gdom/getElement id)))
|
||||||
|
(reset! input-value nil))))}
|
||||||
nil)))
|
nil)))
|
||||||
{:did-remount
|
{:did-remount
|
||||||
(fn [old state]
|
(fn [old state]
|
||||||
|
@ -276,6 +277,7 @@
|
||||||
:or {dummy? false}} id]
|
:or {dummy? false}} id]
|
||||||
(let [value (state/sub :edit-content)
|
(let [value (state/sub :edit-content)
|
||||||
show-commands? (rum/react *show-commands)]
|
show-commands? (rum/react *show-commands)]
|
||||||
|
(prn "re-render editor")
|
||||||
[:div.editor {:style {:position "relative"
|
[:div.editor {:style {:position "relative"
|
||||||
:display "flex"
|
:display "flex"
|
||||||
:flex "1 1 0%"}}
|
:flex "1 1 0%"}}
|
||||||
|
|
|
@ -281,18 +281,19 @@
|
||||||
(> child-level level)))))
|
(> child-level level)))))
|
||||||
|
|
||||||
(rum/defcs heading-cp < rum/reactive
|
(rum/defcs heading-cp < rum/reactive
|
||||||
|
(rum/local false ::edit?)
|
||||||
(rum/local false ::control-show?)
|
(rum/local false ::control-show?)
|
||||||
(rum/local false ::collapsed?)
|
(rum/local false ::collapsed?)
|
||||||
[state {:heading/keys [uuid idx level children meta content dummy? lock? show-page? page] :as heading} heading-part config]
|
[state {:heading/keys [uuid idx level children meta content dummy? lock? show-page? page] :as heading} heading-part config]
|
||||||
(let [control-show? (get state ::control-show?)
|
(let [control-show? (get state ::control-show?)
|
||||||
|
edit? (get state ::edit?)
|
||||||
heading-id (str "ls-heading-parent-" uuid)
|
heading-id (str "ls-heading-parent-" uuid)
|
||||||
collapsed-atom? (get state ::collapsed?)
|
collapsed-atom? (get state ::collapsed?)
|
||||||
toggle-collapsed? (state/sub [:ui/collapsed-headings heading-id])
|
toggle-collapsed? (state/sub [:ui/collapsed-headings heading-id])
|
||||||
collapsed? (or toggle-collapsed? @collapsed-atom?)
|
collapsed? (or toggle-collapsed? @collapsed-atom?)
|
||||||
agenda? (= (:id config) "agenda")
|
agenda? (= (:id config) "agenda")]
|
||||||
state-edit-input-id (state/sub :edit-input-id)]
|
(prn "Re-rendered heading")
|
||||||
(let [edit-input-id (str "edit-heading-" uuid)
|
(let [edit-input-id (str "edit-heading-" uuid)]
|
||||||
edit? (= state-edit-input-id edit-input-id)]
|
|
||||||
(when-not lock?
|
(when-not lock?
|
||||||
[:div.ls-heading-parent.flex-1 {:key (str uuid)
|
[:div.ls-heading-parent.flex-1 {:key (str uuid)
|
||||||
:id heading-id
|
:id heading-id
|
||||||
|
@ -352,9 +353,12 @@
|
||||||
:cy 5
|
:cy 5
|
||||||
:r 2}]]]])
|
:r 2}]]]])
|
||||||
|
|
||||||
(if edit?
|
(if @edit?
|
||||||
(editor/box content {:on-hide (fn [value]
|
(editor/box content {:on-hide (fn [value]
|
||||||
|
(prn "on-hide")
|
||||||
|
(reset! edit? false)
|
||||||
(when (= (:edit-input-id @state/state) edit-input-id)
|
(when (= (:edit-input-id @state/state) edit-input-id)
|
||||||
|
(prn "same")
|
||||||
(swap! state/state assoc
|
(swap! state/state assoc
|
||||||
:edit-input-id nil))
|
:edit-input-id nil))
|
||||||
(handler/save-heading-if-changed! heading value nil))
|
(handler/save-heading-if-changed! heading value nil))
|
||||||
|
@ -365,9 +369,11 @@
|
||||||
(when-not (or (util/link? (gobj/get e "target"))
|
(when-not (or (util/link? (gobj/get e "target"))
|
||||||
(util/input? (gobj/get e "target")))
|
(util/input? (gobj/get e "target")))
|
||||||
(util/stop e)
|
(util/stop e)
|
||||||
|
(reset! edit? true)
|
||||||
(handler/reset-cursor-range! (gdom/getElement heading-id))
|
(handler/reset-cursor-range! (gdom/getElement heading-id))
|
||||||
(swap! state/state assoc
|
(swap! state/state assoc
|
||||||
:edit-input-id edit-input-id)))}
|
:edit-input-id edit-input-id)
|
||||||
|
(prn "on-click")))}
|
||||||
heading-part
|
heading-part
|
||||||
|
|
||||||
;; non-heading children
|
;; non-heading children
|
||||||
|
@ -426,16 +432,16 @@
|
||||||
level-str [:a.initial-color {:href (str "/page/" uuid)}
|
level-str [:a.initial-color {:href (str "/page/" uuid)}
|
||||||
(str (apply str (repeat level "*")) " ")]]
|
(str (apply str (repeat level "*")) " ")]]
|
||||||
(->elem element
|
(->elem element
|
||||||
{:id anchor}
|
{:id anchor}
|
||||||
(remove-nils
|
(remove-nils
|
||||||
(concat
|
(concat
|
||||||
[
|
[
|
||||||
;; (when-not agenda? level-str)
|
;; (when-not agenda? level-str)
|
||||||
checkbox
|
checkbox
|
||||||
marker
|
marker
|
||||||
priority]
|
priority]
|
||||||
(map-inline title)
|
(map-inline title)
|
||||||
[tags])))))]
|
[tags])))))]
|
||||||
(heading-cp t heading-part config)))
|
(heading-cp t heading-part config)))
|
||||||
|
|
||||||
(defn list-element
|
(defn list-element
|
||||||
|
@ -607,10 +613,14 @@
|
||||||
;; TODO: handle case of no headings
|
;; TODO: handle case of no headings
|
||||||
(defn ->hiccup
|
(defn ->hiccup
|
||||||
[headings config]
|
[headings config]
|
||||||
(let [headings (map-indexed (fn [idx heading] ["Heading" (assoc heading :heading/idx idx)]) headings)]
|
(let [headings (map-indexed (fn [idx heading] ["Heading" (assoc heading :heading/idx idx)]) headings)
|
||||||
|
blocks (blocks config headings)
|
||||||
|
blocks (if (seq blocks)
|
||||||
|
blocks
|
||||||
|
[[:div.text-gray-500.cursor "Click to edit"]])]
|
||||||
(->elem
|
(->elem
|
||||||
:div.content
|
:div.content
|
||||||
(blocks config headings))))
|
blocks)))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
;; timestamps
|
;; timestamps
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
(listen state js/window "click"
|
(listen state js/window "click"
|
||||||
(fn [e]
|
(fn [e]
|
||||||
;; If the click target is outside of current node
|
;; If the click target is outside of current node
|
||||||
|
(prn "clicked")
|
||||||
(when-not (dom/contains node (.. e -target))
|
(when-not (dom/contains node (.. e -target))
|
||||||
(on-hide state e))))
|
(on-hide state e))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue