pull/645/head
Tienson Qin 2020-05-04 16:40:06 +08:00
parent 3e1aef7236
commit 84df65c638
3 changed files with 38 additions and 25 deletions

View File

@ -90,13 +90,14 @@
{
;; enter
13 (fn [state e]
(when-let [input-value (get state ::input-value)]
(let [input-value (get state ::input-value)]
(when @input-value
(util/stop e)
(let [[id on-submit] (:rum/args state)
{:keys [pos]} @*slash-caret-pos]
(on-submit @input-value pos)
(.focus (gdom/getElement id)))
(reset! input-value nil)))}
(reset! input-value nil))))}
nil)))
{:did-remount
(fn [old state]
@ -276,6 +277,7 @@
:or {dummy? false}} id]
(let [value (state/sub :edit-content)
show-commands? (rum/react *show-commands)]
(prn "re-render editor")
[:div.editor {:style {:position "relative"
:display "flex"
:flex "1 1 0%"}}

View File

@ -281,18 +281,19 @@
(> child-level level)))))
(rum/defcs heading-cp < rum/reactive
(rum/local false ::edit?)
(rum/local false ::control-show?)
(rum/local false ::collapsed?)
[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?)
edit? (get state ::edit?)
heading-id (str "ls-heading-parent-" uuid)
collapsed-atom? (get state ::collapsed?)
toggle-collapsed? (state/sub [:ui/collapsed-headings heading-id])
collapsed? (or toggle-collapsed? @collapsed-atom?)
agenda? (= (:id config) "agenda")
state-edit-input-id (state/sub :edit-input-id)]
(let [edit-input-id (str "edit-heading-" uuid)
edit? (= state-edit-input-id edit-input-id)]
agenda? (= (:id config) "agenda")]
(prn "Re-rendered heading")
(let [edit-input-id (str "edit-heading-" uuid)]
(when-not lock?
[:div.ls-heading-parent.flex-1 {:key (str uuid)
:id heading-id
@ -352,9 +353,12 @@
:cy 5
:r 2}]]]])
(if edit?
(if @edit?
(editor/box content {:on-hide (fn [value]
(prn "on-hide")
(reset! edit? false)
(when (= (:edit-input-id @state/state) edit-input-id)
(prn "same")
(swap! state/state assoc
:edit-input-id nil))
(handler/save-heading-if-changed! heading value nil))
@ -365,9 +369,11 @@
(when-not (or (util/link? (gobj/get e "target"))
(util/input? (gobj/get e "target")))
(util/stop e)
(reset! edit? true)
(handler/reset-cursor-range! (gdom/getElement heading-id))
(swap! state/state assoc
:edit-input-id edit-input-id)))}
:edit-input-id edit-input-id)
(prn "on-click")))}
heading-part
;; non-heading children
@ -607,10 +613,14 @@
;; TODO: handle case of no headings
(defn ->hiccup
[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
:div.content
(blocks config headings))))
blocks)))
(comment
;; timestamps

View File

@ -54,6 +54,7 @@
(listen state js/window "click"
(fn [e]
;; If the click target is outside of current node
(prn "clicked")
(when-not (dom/contains node (.. e -target))
(on-hide state e))))