Add child button

pull/645/head
Tienson Qin 2020-10-09 00:09:29 +08:00
parent e1cbe4c2ba
commit af7a08e544
3 changed files with 56 additions and 3 deletions

View File

@ -1644,11 +1644,23 @@
blocks)]
sections))))
(rum/defc add-button < rum/reactive
[config ref? custom-query? blocks]
(let [editing (state/sub [:editor/editing?])]
(when-not (or ref? custom-query?
(:block/dummy? (last blocks))
(second (first editing)))
(when-let [last-block (last blocks)]
[:a.add-button-link {:on-click (fn []
(editor-handler/insert-new-block-without-save-previous! config last-block))}
svg/plus-circle]))))
(rum/defc blocks-container < rum/static
[blocks config]
(let [blocks (map #(dissoc % :block/children) blocks)
sidebar? (:sidebar? config)
ref? (:ref? config)]
ref? (:ref? config)
custom-query? (:custom-query? config)]
(when (seq blocks)
[:div.blocks-container.flex-1
{:style {:margin-left (cond
@ -1656,7 +1668,8 @@
0
:else
-18)}}
(build-blocks blocks config)])))
(build-blocks blocks config)
(add-button config ref? custom-query? blocks)])))
;; headers to hiccup
(rum/defc ->hiccup < rum/reactive

View File

@ -101,6 +101,26 @@
(def close (hero-icon "M6 18L18 6M6 6L18 18"))
(def plus (hero-icon "M12 4v16m8-8H4"))
(def plus-circle
[:svg.addButton
{:viewbox "0 0 20 20"}
[:circle.circle {:fill "#dce0e2", :r "9", :cy "10.5", :cx "10.5"}]
[:line
{:stroke-width "1",
:stroke "#868c90",
:y2 "10.5",
:x2 "15",
:y1 "10.5",
:x1 "6"}]
[:line
{:stroke-width "1",
:stroke "#868c90",
:y2 "15",
:x2 "10.5",
:y1 "6",
:x1 "10.5"}]])
(def graph-sm [:div {:style {:transform "rotate(90deg)"}} (hero-icon "M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z" {:height "16" :width "16"})])
(def folder (hero-icon "M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"))
(def folder-sm (hero-icon "M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" {:height "16" :width "16"}))

View File

@ -691,7 +691,7 @@
:value value
:pos pos}))
(defn- insert-new-block!
(defn insert-new-block!
[state]
(when-not config/publishing?
(let [{:keys [block value format id config]} (get-state state)
@ -721,6 +721,26 @@
:blocks-container-id (:id config)
:current-page (state/get-current-page)}))))
(defn insert-new-block-without-save-previous!
[config last-block]
(let [format (:block/format last-block)
id (:id config)
new-level (if (util/uuid-string? id)
(inc (:block/level (db/entity [:block/uuid (medley/uuid id)])))
2)]
(insert-new-block-aux!
last-block
(:block/content last-block)
{:create-new-block? true
:ok-handler
(fn [[_first-block last-block _new-block-content]]
(js/setTimeout #(edit-last-block-for-new-page! last-block :max) 50))
:with-level? true
:new-level new-level
:blocks-container-id (:id config)
:current-page (state/get-current-page)})))
;; TODO: utf8 encode performance
(defn check
[{:block/keys [uuid marker content meta file dummy?] :as block}]