fix: Writing in new page in sidebar makes new line after each keypress

also, makes tippy lazy
pull/2222/head
Tienson Qin 2021-06-17 22:12:03 +08:00
parent effae4b9d6
commit 55448c8ed1
5 changed files with 40 additions and 30 deletions

View File

@ -342,16 +342,19 @@
:href href
:on-click (fn [e]
(util/stop e)
(editor-handler/insert-first-page-block-if-not-exists! redirect-page-name)
(if (gobj/get e "shiftKey")
(when-let [page-entity (db/entity [:block/name redirect-page-name])]
(state/sidebar-add-block!
(state/get-current-repo)
(:db/id page-entity)
:page
{:page page-entity}))
(route-handler/redirect! {:to :page
:path-params {:name redirect-page-name}}))
(do
(js/setTimeout #(editor-handler/insert-first-page-block-if-not-exists! redirect-page-name) 310)
(when-let [page-entity (db/entity [:block/name redirect-page-name])]
(state/sidebar-add-block!
(state/get-current-repo)
(:db/id page-entity)
:page
{:page page-entity})))
(do
(editor-handler/insert-first-page-block-if-not-exists! redirect-page-name)
(route-handler/redirect! {:to :page
:path-params {:name redirect-page-name}})))
(when (and contents-page?
(state/get-left-sidebar-open?))
(ui-handler/close-left-sidebar!)))}
@ -391,21 +394,22 @@
(rfe/href :page {:name redirect-page-name}))
inner (page-inner config page-name href redirect-page-name page-entity contents-page? children html-export? label)]
(if (and (not (util/mobile?)) (not preview?))
(ui/tippy {:html [:div.tippy-wrapper.overflow-y-auto.p-4
{:style {:width 735
:text-align "left"
:font-weight 500
:max-height 600
:padding-bottom 64}}
[:h2.font-bold.text-lg (if (= page redirect-page-name)
page
[:span
[:span.text-sm.mr-2 "Alias:" ]
redirect-page-name])]
(let [page (db/entity [:block/name (string/lower-case redirect-page-name)])]
(editor-handler/insert-first-page-block-if-not-exists! redirect-page-name)
(when-let [f (state/get-page-blocks-cp)]
(f (state/get-current-repo) page {:sidebar? sidebar? :preview? true})))]
(ui/tippy {:html (fn []
[:div.tippy-wrapper.overflow-y-auto.p-4
{:style {:width 735
:text-align "left"
:font-weight 500
:max-height 600
:padding-bottom 64}}
[:h2.font-bold.text-lg (if (= page redirect-page-name)
page
[:span
[:span.text-sm.mr-2 "Alias:" ]
redirect-page-name])]
(let [page (db/entity [:block/name (string/lower-case redirect-page-name)])]
(editor-handler/insert-first-page-block-if-not-exists! redirect-page-name)
(when-let [f (state/get-page-blocks-cp)]
(f (state/get-current-repo) page {:sidebar? sidebar? :preview? true})))])
:interactive true
:delay [1000, 100]}
inner)

View File

@ -272,7 +272,8 @@
(db/pull [:block/name page-name])))
_ (when (and (not block?) (db/page-empty? (state/get-current-repo) (:db/id page)))
(page-handler/create! page-name {:page-map page
:redirect? false}))
:redirect? false
:create-first-block? false}))
{:keys [title] :as properties} (:block/properties page)
page-name (:block/name page)
page-original-name (:block/original-name page)

View File

@ -689,7 +689,7 @@
(when (string? page-name)
(when-let [page (db/entity [:block/name (string/lower-case page-name)])]
(when (db/page-empty? (state/get-current-repo) (:db/id page))
(api-insert-new-block! "" {:page page-name})))))
(api-insert-new-block! "" {:page page-name})))))
(defn update-timestamps-content!
[{:block/keys [repeated? marker format] :as block} content]

View File

@ -67,8 +67,9 @@
(defn create!
([title]
(create! title {}))
([title {:keys [redirect? page-map]
:or {redirect? true}}]
([title {:keys [redirect? page-map create-first-block?]
:or {redirect? true
create-first-block? true}}]
(let [title (string/trim title)
page (string/lower-case title)
format (state/get-preferred-format)
@ -85,7 +86,8 @@
[tx default-properties]
[tx])]
(db/transact! txs)
(editor-handler/insert-first-page-block-if-not-exists! page)
(when create-first-block?
(editor-handler/insert-first-page-block-if-not-exists! page))
(when redirect?
(route-handler/redirect! {:to :page
:path-params {:name page}})))))

View File

@ -621,6 +621,9 @@
:onHide #(reset! *mounted? false)}
opts)
(assoc :html (if mounted?
(:html opts)
(when-let [html (:html opts)]
(if (fn? html)
(html)
html))
[:div ""])))
child)))