From 9a8b00a84995a3fb4d570cefdd01fa7c93802263 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 2 May 2021 11:14:01 +0800 Subject: [PATCH] enhance: align center bullets and headings --- src/main/frontend/components/block.cljs | 25 ++++++++++++++----------- src/main/frontend/components/editor.css | 1 + src/main/frontend/format/block.cljs | 5 ++++- src/main/frontend/handler/editor.cljs | 2 +- src/main/frontend/handler/repo.cljs | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 7f4912acd..101b612db 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -1026,7 +1026,7 @@ collapsed? (get (:block/properties block) :collapsed) control-show? (util/react *control-show?) dark? (= "dark" (state/sub :ui/theme))] - [:div.mr-2.flex.flex-row.items-center + [:div.bullet.mr-2.flex.flex-row.items-center {:style {:height 24 :margin-top 0 :float "left"}} @@ -1418,7 +1418,7 @@ :on-drag-over (fn [event] (block-content-on-drag-over event uuid)) :on-drag-leave (fn [_event] (block-content-on-drag-leave uuid)) :on-drop (fn [event] (block-content-on-drop event block uuid))}] - [:div.flex.relative + [:div.flex.relative {:style {:width "100%"}} [:div.flex-1.flex-col.relative.block-content (cond-> {:id (str "block-content-" uuid)} (not slide?) @@ -1492,8 +1492,8 @@ (rum/defc block-content-or-editor < rum/reactive [config {:block/keys [uuid title body meta content dummy? page format repo children pre-block? idx] :as block} edit-input-id block-id slide?] - (let [edit? (state/sub [:editor/editing? edit-input-id]) - editor-box (get config :editor-box)] + (let [editor-box (get config :editor-box) + edit? (state/sub [:editor/editing? edit-input-id])] (if (and edit? editor-box) [:div.editor-wrapper {:id (str "editor-" edit-input-id)} (editor-box {:block block @@ -1655,8 +1655,9 @@ :should-update (fn [old-state new-state] (not= (:block/content (second (:rum/args old-state))) (:block/content (second (:rum/args new-state)))))} - [state config {:block/keys [uuid title body meta content dummy? page format repo children pre-block? top? properties refs-with-children] :as block}] - (let [*control-show? (get state ::control-show?) + [state config {:block/keys [uuid title body meta content dummy? page format repo children pre-block? top? properties refs-with-children heading-level level type] :as block}] + (let [heading? (and (= type :heading) (<= level 6)) + *control-show? (get state ::control-show?) collapsed? (get properties :collapsed) ref? (boolean (:ref? config)) breadcrumb-show? (:breadcrumb-show? config) @@ -1672,7 +1673,8 @@ (or (seq children) (seq body)))) attrs (on-drag-and-mouse-attrs block uuid top? block-id *move-to-top? has-child? *control-show? doc-mode?) - [data-refs data-refs-self] (get-data-refs-and-self block refs-with-children)] + [data-refs data-refs-self] (get-data-refs-and-self block refs-with-children) + edit-input-id (str "edit-block-" unique-dom-id uuid)] [:div.ls-block.flex.flex-col.rounded-sm (cond-> {:id block-id @@ -1687,7 +1689,9 @@ :repo repo :haschild (str has-child?)} (not slide?) - (merge attrs)) + (merge attrs) + (and heading? heading-level) + (assoc :data-heading-level heading-level)) (when (and ref? breadcrumb-show?) (when-let [comp (block-parents config repo uuid format false)] @@ -1695,12 +1699,11 @@ (dnd-separator-wrapper block slide? top?) - [:div.flex-1.flex-row + [:div.flex.flex-row {:class (if heading? "items-center" "")} (when (not slide?) (block-control config block uuid block-id body children dummy? *control-show?)) - (let [edit-input-id (str "edit-block-" unique-dom-id uuid)] - (block-content-or-editor config block edit-input-id block-id slide?))] + (block-content-or-editor config block edit-input-id block-id slide?)] (when (seq children) [:div.block-children {:style {:margin-left (if doc-mode? 12 21) diff --git a/src/main/frontend/components/editor.css b/src/main/frontend/components/editor.css index be40bcc84..1f21d2ff6 100644 --- a/src/main/frontend/components/editor.css +++ b/src/main/frontend/components/editor.css @@ -17,6 +17,7 @@ } .editor-wrapper { + width: 100%; margin: 0 auto; } diff --git a/src/main/frontend/format/block.cljs b/src/main/frontend/format/block.cljs index 5cb7dca76..63677dc56 100644 --- a/src/main/frontend/format/block.cljs +++ b/src/main/frontend/format/block.cljs @@ -446,7 +446,10 @@ (remove string/blank?)) block (second block) block (if markdown-heading? - (assoc block :level 1 :heading-level (:level block)) + (assoc block + :type :heading + :level 1 + :heading-level (:level block)) block) level (:level block) [children current-block-children] diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 292d05b01..914d4516d 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -2051,7 +2051,7 @@ (util/cursor-move-back input 1) (util/cursor-move-forward input 1)))))) -(defn- delete-and-update [input start end] +(defn- delete-and-update [^js input start end] (.setRangeText input "" start end) (state/set-edit-content! (state/get-edit-input-id) (.-value input))) diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index a60c91330..9484d6241 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -57,7 +57,7 @@ "org" "* What's **Contents**?\n** It's a normal page called [[Contents]], you can use it for:\n*** 1. table of content/index/MOC\n*** 2. pinning/bookmarking favorites pages/blocks (e.g. [[Logseq]])\n*** 3. You can also put many different things, depending on your personal workflow." "markdown" - "## What's **Contents**?\n### It's a normal page called [[Contents]], you can use it for:\n#### 1. table of content/index/MOC\n#### 2. pinning/bookmarking favorites pages/blocks (e.g. [[Logseq]])\n#### 3. You can also put many different things, depending on your personal workflow." + "- What's **Contents**?\n - It's a normal page called [[Contents]], you can use it for:\n - 1. table of content/index/MOC\n - 2. pinning/bookmarking favorites pages/blocks (e.g. [[Logseq]])\n - 3. You can also put many different things, depending on your personal workflow." "")] (p/let [_ (fs/mkdir-if-not-exists (str repo-dir "/" (state/get-pages-directory))) file-exists? (fs/create-if-not-exists repo-url repo-dir file-path default-content)]