Browse Source

Merge remote-tracking branch 'origin/master' into improve/plugin-register-ui-actions

# Conflicts:
#	src/main/frontend/state.cljs
charlie 4 years ago
parent
commit
cf84f2ae7d

+ 1 - 1
package.json

@@ -80,7 +80,7 @@
         "ignore": "^5.1.8",
         "is-svg": "4.2.2",
         "jszip": "^3.5.0",
-        "mldoc": "0.7.9",
+        "mldoc": "0.8.2",
         "path": "^0.12.7",
         "posthog-js": "^1.10.2",
         "react": "^17.0.2",

+ 4 - 4
resources/css/common.css

@@ -881,23 +881,23 @@ button.menu {
   color: var(--ls-link-text-color, #24292e);
 }
 
-a.menu-link:hover,
+.menu-link:hover,
 button.pull:hover,
 button.menu:focus {
   background-color: var(--ls-menu-hover-color, #f4f5f7);
 }
 
-a.menu-link {
+.menu-link {
   background-color: var(--ls-primary-background-color, #fff);
   color: var(--ls-primary-text-color);
 }
 
-a.menu-link:first-of-type {
+.menu-link:first-of-type {
   border-top-left-radius: var(--ls-border-radius-low);
   border-top-right-radius: var(--ls-border-radius-low);
 }
 
-a.menu-link:last-of-type {
+.menu-link:last-of-type {
   border-bottom-left-radius: var(--ls-border-radius-low);
   border-bottom-right-radius: var(--ls-border-radius-low);
 }

+ 43 - 51
src/main/frontend/components/block.cljs

@@ -672,7 +672,7 @@
     ["Subscript" l]
     (->elem :sub (map-inline config l))
     ["Tag" s]
-    (when s
+    (when-let [s (block/get-tag item)]
       (let [s (text/page-ref-un-brackets! s)]
         [:a.tag {:data-ref s
                  :href (rfe/href :page {:name s})
@@ -722,9 +722,9 @@
       [:a {:href (str "mainto:" address)}
        address])
 
-    ["Block_reference" id]
-    ;; FIXME: alert when self block reference
-    (block-reference (assoc config :reference? true) id nil)
+    ;; ["Block_reference" id]
+    ;; ;; FIXME: alert when self block reference
+    ;; (block-reference (assoc config :reference? true) id nil)
 
     ["Nested_link" link]
     (nested-link config html-export? link)
@@ -732,19 +732,21 @@
     ["Link" link]
     (let [{:keys [url label title metadata full_text]} link]
       (match url
+        ["Block_ref" id]
+        (let [label* (if (seq (mldoc/plain->text label)) label nil)]
+          (block-reference (assoc config :reference? true) id label*))
+
+        ["Page_ref" page]
+        (let [label* (if (seq (mldoc/plain->text label)) label nil)]
+          (if (and (string? page) (string/blank? page))
+            [:span (util/format "[[%s]]" page)]
+            (page-reference (:html-export? config) page config label*)))
+
         ["Search" s]
         (cond
           (string/blank? s)
           [:span.warning {:title "Invalid link"} full_text]
 
-          (text/block-ref? s)
-          (let [block-id (text/block-ref-un-brackets! s)]
-            (block-reference config block-id label))
-
-          (text/page-ref? s)
-          (let [page (text/page-ref-un-brackets! s)]
-            (page-reference (:html-export? config) page config label))
-
           (= \# (first s))
           (->elem :a {:on-click #(route-handler/jump-to-anchor! (mldoc/anchorLink (subs s 1)))} (subs s 1))
 
@@ -1157,9 +1159,7 @@
                          (editor-handler/expand-block! uuid)
                          (editor-handler/collapse-block! uuid)))))}
       [:span {:class (if control-show? "control-show" "control-hide")}
-         (cond
-           collapsed? (svg/caret-right)
-           has-child? (svg/caret-down))]]
+       (ui/rotating-arrow collapsed?)]]
      [:a {:on-click (fn [e]
                       (bullet-on-click e block config uuid))}
       [:span.bullet-container.cursor
@@ -1524,10 +1524,7 @@
     [:div.block-content.inline
      (cond-> {:id (str "block-content-" uuid)}
        (not slide?)
-       (merge attrs)
-
-       block-ref?
-       (assoc :class "cursor-pointer"))
+       (merge attrs))
 
      [:span
       ;; .flex.relative {:style {:width "100%"}}
@@ -1634,6 +1631,12 @@
        (not (d/has-class? (gobj/get e "target") "bullet"))
        (not @*dragging?)))
 
+(rum/defc breadcrumb-fragment
+  [href label]
+  [:a {:href href} label])
+
+(rum/defc breadcrumb-separator [] [:span.mx-2.opacity-50 "➤"])
+
 (defn block-parents
   ([config repo block-id format]
    (block-parents config repo block-id format true))
@@ -1641,36 +1644,23 @@
    (let [parents (db/get-block-parents repo block-id 3)
          page (db/get-block-page repo block-id)
          page-name (:block/name page)
-         page-original-name (:block/original-name page)]
-     (when (or (seq parents)
-               show-page?
-               page-name)
-       (let [parents-atom (atom parents)
-             component [:div.block-parents.flex-row.flex-1
-                        (when show-page?
-                          [:a {:href (rfe/href :page {:name page-name})}
-                           (or page-original-name page-name)])
-
-                        (when (and show-page? (seq parents) (> (count parents) 1))
-                          [:span.mx-2.opacity-50 "➤"])
-
-                        (when (seq parents)
-                          (let [parents (doall
-                                         (for [{:block/keys [uuid title name]} parents]
-                                           (when-not name ; not page
-                                             [:a {:on-mouse-down (fn [e]
-                                                                   (util/stop e)
-                                                                   (route-handler/redirect! {:to :page
-                                                                                             :path-params {:name uuid}}))}
-                                              (map-inline config title)])))
-                                parents (remove nil? parents)]
-                            (reset! parents-atom parents)
-                            (when (seq parents)
-                              (interpose [:span.mx-2.opacity-50 "➤"]
-                                         parents))))]
-             component (filterv identity component)]
-         (when (or (seq @parents-atom) show-page?)
-           component))))))
+         page-original-name (:block/original-name page)
+         show? (or (seq parents) show-page? page-name)]
+     (when show?
+       (let [page-name-props (when show-page?
+                                  [(rfe/href :page {:name page-name})
+                                   (or page-original-name page-name)])
+             parents-props (doall
+                                (for [{:block/keys [uuid title name]} parents]
+                                  (when-not name ; not page
+                                    [(rfe/href :page {:name uuid})
+                                     (->elem :span (map-inline config title))])))
+             breadcrumb (->> (into [] parents-props)
+                             (concat [page-name-props])
+                             (filterv identity)
+                             (map (fn [[href label]] (breadcrumb-fragment href label)))
+                             (interpose (breadcrumb-separator)))]
+         [:div.block-parents.flex-row.flex-1 breadcrumb])))))
 
 (defn- block-drag-over
   [event uuid top? block-id *move-to]
@@ -2358,10 +2348,12 @@
         blocks->vec-tree #(if (or custom-query? ref?) % (tree/blocks->vec-tree % (:id config)))
         blocks' (blocks->vec-tree blocks)
         blocks (if (seq blocks') blocks' blocks)
-        config (assoc config :blocks-container-id blocks-container-id)]
+        config (assoc config :blocks-container-id blocks-container-id)
+        doc-mode? (:document/mode? config)]
     (when (seq blocks)
       [:div.blocks-container.flex-1
-       {:style {:margin-left (cond
+       {:class (when doc-mode? "document-mode")
+        :style {:margin-left (cond
                                sidebar?
                                0
                                :else

+ 40 - 22
src/main/frontend/components/block.css

@@ -9,7 +9,6 @@
   min-height: 24px;
   max-width: 100%;
   overflow: initial;
-  cursor: text;
   white-space: pre-wrap;
   overflow-wrap: break-word;
   word-break: break-word;
@@ -233,44 +232,63 @@
   margin-left: auto;
 }
 
-.ls-block h1 {
-  font-size: 2em;
-  margin: 0.67em 0
+.ls-block h1, .editor-inner .h1 {
+    font-size: 2em;
 }
 
-.ls-block h2 {
-  font-size: 1.5em;
-  margin: 0.75em 0
+.ls-block h2, .editor-inner .h2 {
+    font-size: 1.5em;
 }
 
-.ls-block h3 {
-  font-size: 1.17em;
-  margin: 0.83em 0
+.ls-block h3, .editor-inner .h3 {
+    font-size: 1.17em;
 }
 
-.ls-block h4 {
-  margin: 1.12em 0
+.ls-block h4, .editor-inner .h4 {
+    font-size: 1.12em;
 }
 
-.ls-block h5 {
+.ls-block h5, .editor-inner .h5 {
   font-size: 0.83em;
-  margin: 1.5em 0
 }
 
-.ls-block h6 {
+.ls-block h6, .editor-inner .h6 {
   font-size: 0.75em;
-  margin: 1.67em 0
 }
 
-.ls-block h1,
-.ls-block h2,
-.ls-block h3,
-.ls-block h4,
-.ls-block h5,
-.ls-block h6 {
+.ls-block :is(h1,h2,h3,h4,h5,h6), .editor-inner .h1, .editor-inner .h2, .editor-inner .h3,
+.editor-inner .h4, .editor-inner .h5, .editor-inner .h6 {
   font-weight: 600
 }
 
+.ls-block :is(h1, h2), .editor-inner .h1, .editor-inner .h2 {
+    border-bottom: 1px solid var(--ls-quaternary-background-color);
+    margin: 0.4em 0 0;
+}
+
+.document-mode .ls-block h1, .document-mode .editor-inner .h1 {
+    margin: 0.67em 0;
+}
+.document-mode .ls-block h2, .document-mode .editor-inner .h2 {
+    margin: 0.75em 0;
+}
+.document-mode .ls-block h3, .document-mode .editor-inner .h3 {
+    margin: 0.83em 0;
+}
+.document-mode .ls-block h4, .document-mode .editor-inner .h4 {
+    margin: 1.12em 0;
+}
+.document-mode .ls-block h5, .document-mode .editor-inner .h5 {
+    margin: 1.5em 0;
+}
+.document-mode .ls-block h6, .document-mode .editor-inner .h6 {
+    margin: 1.67em 0;
+}
+
+.document-mode .ls-block {
+    margin-bottom: 2rem;
+}
+
 .color-level {
   background-color: var(--color-level-1);
 }

+ 3 - 10
src/main/frontend/components/editor.cljs

@@ -369,18 +369,11 @@
     (set-up-key-down! repo state format)
     (set-up-key-up! state input input-id search-timeout)))
 
-(defn- get-editor-style
+(defn- get-editor-heading-class
   [content heading-level]
   (if (string/includes? content "\n")
     nil
-    (case heading-level
-      1 {:font-size "2em" :font-weight "bold" :margin "0.67em 0"}
-      2 {:font-size "1.5em" :font-weight "bold" :margin "0.75em 0"}
-      3 {:font-size "1.17em" :font-weight "bold" :margin "0.83em 0"}
-      4 {:font-weight "bold" :margin "1.12em 0"}
-      5 {:font-size "0.83em" :font-weight "bold" :margin "1.5em 0"}
-      6 {:font-size "0.75em" :font-weight "bold" :margin "1.67em 0"}
-      nil)))
+    (if heading-level (str "h" heading-level))))
 
 
 (rum/defc mock-textarea
@@ -436,7 +429,7 @@
        :on-change         (editor-handler/editor-on-change! block id search-timeout)
        :on-paste          (editor-handler/editor-on-paste! id)
        :auto-focus        false
-       :style             (get-editor-style content heading-level)})
+       :class             (get-editor-heading-class content heading-level)})
 
      (mock-textarea)
 

+ 3 - 3
src/main/frontend/components/repo.cljs

@@ -232,13 +232,13 @@
                             "origin-top-right.absolute.left-0.mt-2.w-48.rounded-md.shadow-lg")
               :links-footer [:div
                              (when (seq switch-repos) [:hr.my-4])
-                             [:a {:class "block px-4 py-2 text-sm text-gray-700 transition ease-in-out duration-150 cursor menu-link"
+                             [:a {:class "block px-4 py-2 text-sm transition ease-in-out duration-150 cursor menu-link"
                                   :href (rfe/href :repo-add)}
                               (t :new-graph)]
-                             [:a {:class "block px-4 py-2 text-sm text-gray-700 transition ease-in-out duration-150 cursor menu-link"
+                             [:a {:class "block px-4 py-2 text-sm transition ease-in-out duration-150 cursor menu-link"
                                   :href (rfe/href :repos)}
                               (t :all-graphs)]
-                             [:a {:class "block px-4 py-2 text-sm text-gray-700 transition ease-in-out duration-150 cursor menu-link"
+                             [:a {:class "block px-4 py-2 text-sm transition ease-in-out duration-150 cursor menu-link"
                                   :on-click (fn []
                                               (repo-handler/re-index! nfs-handler/rebuild-index!))}
                               (t :re-index)]]}

+ 1 - 3
src/main/frontend/components/right_sidebar.cljs

@@ -188,9 +188,7 @@
              [:div.flex.flex-row.justify-center
               [:a.opacity-50.hover:opacity-100.flex.items-center.pr-1
                {:on-click #(state/sidebar-block-toggle-collapse! db-id)}
-               (if collapse?
-                 (svg/caret-right)
-                 (svg/caret-down))]
+               (ui/rotating-arrow collapse?)]
               [:div.ml-1.font-medium
                title]]
              (close #(state/sidebar-remove-block! idx))]

+ 3 - 3
src/main/frontend/components/search.cljs

@@ -32,7 +32,7 @@
     (let [q-words (string/split q #" ")
           lc-content (string/lower-case content)
           lc-q (string/lower-case q)]
-      (if (or (string/includes? lc-content lc-q)
+      (if (and (string/includes? lc-content lc-q)
               (not (util/safe-re-find #" " q)))
         (let [i (string/index-of lc-content lc-q)
               [before after] [(subs content 0 i) (subs content (+ i (count q)))]]
@@ -74,8 +74,8 @@
   [repo uuid format content q search-mode]
   [:div [
          (when (not= search-mode :page)
-           [:div {:class "mb-1"} (block/block-parents {:id "block-search-block-parent" :block? true} repo (clojure.core/uuid uuid) format)])
-         [:div {:class "font-medium"} (highlight-exact-query content q)]]])
+           [:div {:class "mb-1" :key "parents"} (block/block-parents {:id "block-search-block-parent" :block? true} repo (clojure.core/uuid uuid) format)])
+         [:div {:class "font-medium" :key "content"} (highlight-exact-query content q)]]])
 
 (rum/defc highlight-fuzzy
   [content indexes]

+ 16 - 9
src/main/frontend/components/sidebar.cljs

@@ -167,9 +167,11 @@
 (defn get-default-home-if-valid
   []
   (when-let [default-home (state/get-default-home)]
-    (when-let [page (:page default-home)]
-      (when (db/entity [:block/name (string/lower-case page)])
-        default-home))))
+    (let [page (:page default-home)
+          page (when page (db/entity [:block/name (string/lower-case page)]))]
+      (if page
+        default-home
+        (dissoc default-home :page)))))
 
 (defonce sidebar-inited? (atom false))
 ;; TODO: simplify logic
@@ -209,7 +211,8 @@
        (cond
          (and default-home
               (= :home (state/get-current-route))
-              (not (state/route-has-p?)))
+              (not (state/route-has-p?))
+              (:page default-home))
          (route-handler/redirect! {:to :page
                                    :path-params {:name (:page default-home)}})
 
@@ -261,11 +264,15 @@
 
 (rum/defc new-block-mode < rum/reactive
   []
-  (when (state/sub [:editor/new-block-toggle?])
-    [:a.px-1.text-sm.font-medium.bg-base-2.mr-4.rounded-md
-     {:title "Click to switch to \"Enter\" for creating new block"
-      :on-click state/toggle-new-block-shortcut!}
-     "A"]))
+  (when (state/sub [:document/mode?])
+    (ui/tippy {:html [:div.p-2
+                      [:p.mb-2 [:b "Document mode"]]
+                      [:ul
+                       [:li "Shift + Enter to create new block"]
+                       [:li "Click `D` or type `t d` to toggle document mode"]]]}
+     [:a.px-1.text-sm.font-medium.bg-base-2.mr-4.rounded-md
+      {:on-click state/toggle-document-mode!}
+      "D"])))
 
 (rum/defc help-button < rum/reactive
   []

+ 32 - 4
src/main/frontend/format/block.cljs

@@ -1,6 +1,7 @@
 (ns frontend.format.block
   (:require [clojure.string :as string]
             [clojure.walk :as walk]
+            [cljs.core.match :refer [match]]
             [frontend.config :as config]
             [frontend.date :as date]
             [frontend.db :as db]
@@ -21,9 +22,24 @@
 
 (defn get-tag
   [block]
-  (and (vector? block)
-       (= "Tag" (first block))
-       (second block)))
+  (when-let [tag-value (and (vector? block)
+                            (= "Tag" (first block))
+                            (second block))]
+    (->
+     (mapv (fn [e]
+             (match e
+                    ["Plain" s]
+                    s
+                    ["Link" t]
+                    (let [{full_text :full_text} t]
+                      full_text)
+                    ["Nested_link" t]
+                    (let [ {content :content} t]
+                      content)
+                    :else
+                    ""
+                    )) tag-value)
+     (string/join))))
 
 (defn get-page-reference
   [block]
@@ -32,6 +48,11 @@
                (let [typ (first (:url (second block)))]
                  ;; {:url ["File" "file:../pages/hello_world.org"], :label [["Plain" "hello world"]], :title nil}
                  (or
+                  (and
+                   (= typ "Page_ref")
+                   (string? (second (:url (second block))))
+                   (second (:url (second block))))
+
                   (and
                    (= typ "Search")
                    (string? (second (:url (second block))))
@@ -74,7 +95,7 @@
 
                (and (vector? block)
                     (= "Tag" (first block)))
-               (let [text (second block)]
+               (let [text (get-tag block)]
                  (when (and
                         (string? text)
                         (text/page-ref? text))
@@ -85,6 +106,7 @@
     (cond
       (and
        (string? page)
+       (not (string/blank? page))
        (text/block-ref? page))
       (text/block-ref-un-brackets! page)
 
@@ -103,6 +125,12 @@
                              (= "Block_reference" (first block)))
                         (last block)
 
+                        (and (vector? block)
+                             (= "Link" (first block))
+                             (map? (second block))
+                             (= "Block_ref" (first (:url (second block)))))
+                        (second (:url (second block)))
+
                         (and (vector? block)
                              (= "Macro" (first block)))
                         (let [{:keys [name arguments]} (second block)]

+ 0 - 4
src/main/frontend/modules/shortcut/config.cljs

@@ -297,10 +297,6 @@
     {:desc    "Toggle between dark/light theme"
      :binding "t t"
      :fn      state/toggle-theme!}
-    :ui/toggle-new-block
-    {:desc    "Toggle newblock/newline command for inserting newline/newblock"
-     :binding "t e"
-     :fn      state/toggle-new-block-shortcut!}
     :ui/toggle-contents
     {:desc    "Toggle Contents in sidebar"
      :binding "t c"

+ 134 - 139
src/main/frontend/state.cljs

@@ -16,129 +16,129 @@
 
 (defonce ^:private state
   (atom
-   {:route-match nil
-    :today nil
-    :system/events (async/chan 100)
-    :db/batch-txs (async/chan 100)
-    :file/writes (async/chan 100)
-    :notification/show? false
-    :notification/content nil
-    :repo/cloning? false
-    :repo/loading-files? nil
-    :repo/importing-to-db? nil
-    :repo/sync-status {}
-    :repo/changed-files nil
-    :nfs/user-granted? {}
-    :nfs/refreshing? nil
-    :instrument/disabled? (storage/get "instrument-disabled")
-    ;; TODO: how to detect the network reliably?
-    :network/online? true
-    :indexeddb/support? true
-    :me nil
-    :git/current-repo (storage/get :git/current-repo)
-    :git/status {}
-    :format/loading {}
-    :draw? false
-    :db/restoring? nil
-
-    :journals-length 2
-
-    :search/q ""
-    :search/mode :global
-    :search/result nil
-
-    ;; modals
-    :modal/show? false
-
-    ;; right sidebar
-    :ui/settings-open? false
-    :ui/sidebar-open? false
-    :ui/left-sidebar-open? false
-    :ui/theme (or (storage/get :ui/theme) "dark")
-    :ui/system-theme? ((fnil identity (or util/mac? util/win32? false)) (storage/get :ui/system-theme?))
-    :ui/wide-mode? false
-    ;; :show-all, :hide-block-body, :hide-block-children
-    :ui/cycle-collapse :show-all
-    :ui/sidebar-collapsed-blocks {}
-    :ui/root-component nil
-    :ui/file-component nil
-    :ui/custom-query-components {}
-    :ui/show-recent? false
-    :ui/developer-mode? (or (= (storage/get "developer-mode") "true")
-                            false)
-    ;; remember scroll positions of visited paths
-    :ui/paths-scroll-positions {}
-
-    :document/mode? (or (storage/get :document/mode?) false)
-
-    :github/contents {}
-    :config {}
-    :block/component-editing-mode? false
-    :editor/draw-mode? false
-    :editor/show-page-search? false
-    :editor/show-page-search-hashtag? false
-    :editor/show-date-picker? false
-    ;; With label or other data
-    :editor/show-input nil
-    :editor/last-saved-cursor nil
-    :editor/editing? nil
-    :editor/last-edit-block-input-id nil
-    :editor/last-edit-block-id nil
-    :editor/in-composition? false
-    :editor/content {}
-    :editor/block nil
-    :editor/block-dom-id nil
-    :editor/set-timestamp-block nil
-    :editor/last-input-time nil
-    :editor/new-block-toggle? false
-    :editor/args nil
-    :db/last-transact-time {}
-    :db/last-persist-transact-ids {}
-    ;; whether database is persisted
-    :db/persisted? {}
-    :db/latest-txs (or (storage/get-transit :db/latest-txs) {})
-    :cursor-range nil
-
-    :selection/mode false
-    :selection/blocks []
-    :selection/start-block nil
-    ;; either :up or :down, defaults to down
-    ;; used to determine selection direction when two or more blocks are selected
-    :selection/direction :down
-    :custom-context-menu/show? false
-    :custom-context-menu/links nil
-
-    ;; pages or blocks in the right sidebar
-    ;; It is a list of `[repo db-id block-type block-data]` 4-tuple
-    :sidebar/blocks '()
-
-    :preferred-language (storage/get :preferred-language)
-
-    ;; electron
-    :electron/updater-pending? false
-    :electron/updater {}
-
-    ;; plugin
-    :plugin/indicator-text        nil
-    :plugin/installed-plugins     {}
-    :plugin/installed-themes      []
-    :plugin/installed-commands    {}
-    :plugin/installed-ui-items    {}
-    :plugin/simple-commands       {}
-    :plugin/selected-theme        nil
-    :plugin/selected-unpacked-pkg nil
-    :plugin/active-readme         nil
-
-    ;; all notification contents as k-v pairs
-    :notification/contents {}
-    :graph/syncing? false
-
-    ;; copied blocks
-    :copy/blocks {:copy/content nil :copy/block-tree nil}
-
-    :date-picker/date nil
-
-    :view/components {}}))
+   (let [document-mode? (or (storage/get :document/mode?) false)]
+     {:route-match nil
+      :today nil
+      :system/events (async/chan 100)
+      :db/batch-txs (async/chan 100)
+      :file/writes (async/chan 100)
+      :notification/show? false
+      :notification/content nil
+      :repo/cloning? false
+      :repo/loading-files? nil
+      :repo/importing-to-db? nil
+      :repo/sync-status {}
+      :repo/changed-files nil
+      :nfs/user-granted? {}
+      :nfs/refreshing? nil
+      :instrument/disabled? (storage/get "instrument-disabled")
+      ;; TODO: how to detect the network reliably?
+      :network/online? true
+      :indexeddb/support? true
+      :me nil
+      :git/current-repo (storage/get :git/current-repo)
+      :git/status {}
+      :format/loading {}
+      :draw? false
+      :db/restoring? nil
+
+      :journals-length 2
+
+      :search/q ""
+      :search/mode :global
+      :search/result nil
+
+      ;; modals
+      :modal/show? false
+
+      ;; right sidebar
+      :ui/settings-open? false
+      :ui/sidebar-open? false
+      :ui/left-sidebar-open? false
+      :ui/theme (or (storage/get :ui/theme) "dark")
+      :ui/system-theme? ((fnil identity (or util/mac? util/win32? false)) (storage/get :ui/system-theme?))
+      :ui/wide-mode? false
+      ;; :show-all, :hide-block-body, :hide-block-children
+      :ui/cycle-collapse :show-all
+      :ui/sidebar-collapsed-blocks {}
+      :ui/root-component nil
+      :ui/file-component nil
+      :ui/custom-query-components {}
+      :ui/show-recent? false
+      :ui/developer-mode? (or (= (storage/get "developer-mode") "true")
+                              false)
+      ;; remember scroll positions of visited paths
+      :ui/paths-scroll-positions {}
+
+      :document/mode? document-mode?
+
+      :github/contents {}
+      :config {}
+      :block/component-editing-mode? false
+      :editor/draw-mode? false
+      :editor/show-page-search? false
+      :editor/show-page-search-hashtag? false
+      :editor/show-date-picker? false
+      ;; With label or other data
+      :editor/show-input nil
+      :editor/last-saved-cursor nil
+      :editor/editing? nil
+      :editor/last-edit-block-input-id nil
+      :editor/last-edit-block-id nil
+      :editor/in-composition? false
+      :editor/content {}
+      :editor/block nil
+      :editor/block-dom-id nil
+      :editor/set-timestamp-block nil
+      :editor/last-input-time nil
+      :editor/new-block-toggle? document-mode?
+      :editor/args nil
+      :db/last-transact-time {}
+      :db/last-persist-transact-ids {}
+      ;; whether database is persisted
+      :db/persisted? {}
+      :db/latest-txs (or (storage/get-transit :db/latest-txs) {})
+      :cursor-range nil
+
+      :selection/mode false
+      :selection/blocks []
+      :selection/start-block nil
+      ;; either :up or :down, defaults to down
+      ;; used to determine selection direction when two or more blocks are selected
+      :selection/direction :down
+      :custom-context-menu/show? false
+      :custom-context-menu/links nil
+
+      ;; pages or blocks in the right sidebar
+      ;; It is a list of `[repo db-id block-type block-data]` 4-tuple
+      :sidebar/blocks '()
+
+      :preferred-language (storage/get :preferred-language)
+
+      ;; electron
+      :electron/updater-pending? false
+      :electron/updater {}
+
+      ;; plugin
+      :plugin/indicator-text        nil
+      :plugin/installed-plugins     {}
+      :plugin/installed-themes      []
+      :plugin/installed-commands    {}
+      :plugin/simple-commands       {}
+      :plugin/selected-theme        nil
+      :plugin/selected-unpacked-pkg nil
+      :plugin/active-readme         nil
+
+      ;; all notification contents as k-v pairs
+      :notification/contents {}
+      :graph/syncing? false
+
+      ;; copied blocks
+      :copy/blocks {:copy/content nil :copy/block-tree nil}
+
+      :date-picker/date nil
+
+      :view/components {}})))
 
 (defn get-route-match
   []
@@ -155,8 +155,8 @@
 (defn get-current-page
   []
   (when (= :page (get-current-route))
-   (get-in (get-route-match)
-           [:path-params :name])))
+    (get-in (get-route-match)
+            [:path-params :name])))
 
 (defn route-has-p?
   []
@@ -899,18 +899,12 @@
   [value]
   (set-state! :today value))
 
-(defn toggle-document-mode!
-  []
-  (let [mode (get @state :document/mode?)]
-    (set-state! :document/mode? (not mode))
-    (storage/set :document/mode? (not mode))))
-
 (defn get-date-formatter
   []
   (or
    (when-let [repo (get-current-repo)]
      (get-in @state [:config repo :date-formatter]))
-    ;; TODO:
+   ;; TODO:
    (get-in @state [:me :settings :date-formatter])
    "MMM do, yyyy"))
 
@@ -1055,6 +1049,13 @@
   []
   (update-state! :editor/new-block-toggle? not))
 
+(defn toggle-document-mode!
+  []
+  (let [mode (get @state :document/mode?)]
+    (set-state! :document/mode? (not mode))
+    (storage/set :document/mode? (not mode)))
+  (toggle-new-block-shortcut!))
+
 (defn enable-tooltip?
   []
   (get (get (sub-config) (get-current-repo))
@@ -1114,12 +1115,6 @@
   (filterv #(= (keyword (first %)) (keyword type))
            (apply concat (vals (:plugin/simple-commands @state)))))
 
-(defn get-plugins-ui-items-with-type
-  [type]
-  (filterv #(= (keyword (first %)) (keyword type))
-           (apply concat (vals (:plugin/installed-ui-items @state)))))
-
-
 (defn get-scheduled-future-days
   []
   (let [days (:scheduled/future-days (get-config))]
@@ -1183,7 +1178,7 @@
      (when-let [last-time (get-in @state [:editor/last-input-time repo])]
        (let [now (util/time-ms)]
          (>= (- now last-time) 500)))
-      ;; not in editing mode
+     ;; not in editing mode
      (not (get-edit-input-id)))))
 
 (defn set-last-persist-transact-id!

+ 24 - 21
src/main/frontend/ui.cljs

@@ -79,7 +79,7 @@
 
 (rum/defc menu-link
   [options child]
-  [:a.block.px-4.py-2.text-sm.text-gray-700.transition.ease-in-out.duration-150.cursor.menu-link
+  [:a.block.px-4.py-2.text-sm.transition.ease-in-out.duration-150.cursor.menu-link
    options
    child])
 
@@ -524,6 +524,12 @@
    [:span.icon.flex.items-center svg/loading]
    [:span.text.pl-2 content]])
 
+(rum/defc rotating-arrow
+  [collapsed?]
+  [:span
+   {:class (if collapsed? "rotating-arrow collapsed" "rotating-arrow not-collapsed")}
+   (svg/caret-right)])
+
 (rum/defcs foldable <
   (rum/local false ::control?)
   (rum/local false ::collapsed?)
@@ -547,10 +553,7 @@
           :on-click (fn [e]
                       (util/stop e)
                       (swap! collapsed? not))}
-         [:span {:class (if @control? "control-show" "control-hide")}
-          (if @collapsed?
-            (svg/caret-right)
-            (svg/caret-down))]]
+         [:span {:class (if @control? "control-show" "control-hide")} (rotating-arrow @collapsed?)]]
         (if (fn? header)
           (header @collapsed?)
           header)]]]
@@ -610,19 +613,19 @@
   (let [*mounted? (::mounted? state)
         mounted? @*mounted?]
     (Tippy (->
-           (merge {:arrow true
-                   :sticky true
-                   :theme "customized"
-                   :disabled (not (state/enable-tooltip?))
-                   :unmountHTMLWhenHide true
-                   :open @*mounted?
-                   :onShow #(reset! *mounted? true)
-                   :onHide #(reset! *mounted? false)}
-                  opts)
-           (assoc :html (if mounted?
-                          (when-let [html (:html opts)]
-                            (if (fn? html)
-                              (html)
-                              html))
-                          [:div {:key "tippy"} ""])))
-          child)))
+            (merge {:arrow true
+                    :sticky true
+                    :theme "customized"
+                    :disabled (not (state/enable-tooltip?))
+                    :unmountHTMLWhenHide true
+                    :open @*mounted?
+                    :onShow #(reset! *mounted? true)
+                    :onHide #(reset! *mounted? false)}
+                   opts)
+            (assoc :html (if mounted?
+                           (when-let [html (:html opts)]
+                             (if (fn? html)
+                               (html)
+                               html))
+                           [:div {:key "tippy"} ""])))
+           child)))

+ 8 - 0
src/main/frontend/ui.css

@@ -187,3 +187,11 @@
     @apply py-1.5 sm:leading-4 sm:text-xs;
   }
 }
+
+.rotating-arrow.not-collapsed svg {
+  transform: rotate(90deg);
+}
+
+.rotating-arrow svg {
+  transition: all 100ms ease-in 0ms;
+}

+ 1 - 1
src/main/frontend/version.cljs

@@ -1,3 +1,3 @@
 (ns frontend.version)
 
-(defonce version "0.2.2")
+(defonce version "0.2.2-1")

+ 9 - 4
yarn.lock

@@ -5734,10 +5734,10 @@ mkdirp@^0.5.0, mkdirp@^0.5.4, mkdirp@~0.5.1:
   dependencies:
     minimist "^1.2.5"
 
-mldoc@0.7.9:
-  version "0.7.9"
-  resolved "https://registry.yarnpkg.com/mldoc/-/mldoc-0.7.9.tgz#78d077940f22338d92d2f240fcb1d052edd1d967"
-  integrity sha512-GjCZPU17G9qH0b4xyVADRfaW0wTvZ82f1bnMABz78sI7/yM9WESjNVnC8TERx5VAYI9F/EeW+SQZ2aNROQEWxQ==
+mldoc@0.8.2:
+  version "0.8.2"
+  resolved "https://registry.yarnpkg.com/mldoc/-/mldoc-0.8.2.tgz#4b536d9c99528e4f6c6df56b2f642c43db08b55f"
+  integrity sha512-Kl7wi3BvruwkWHchNOaC9N32ItpFC8GkRfpk3WpabuGkJi0TyFKIQfStLP3lZK7cYzSG4THEf8nzofoandoGDg==
   dependencies:
     yargs "^12.0.2"
 
@@ -7121,6 +7121,11 @@ react-grid-layout@^0.16.6:
     react-draggable "3.x"
     react-resizable "1.x"
 
[email protected]:
+  version "2.1.0"
+  resolved "https://registry.yarnpkg.com/react-icon-base/-/react-icon-base-2.1.0.tgz#a196e33fdf1e7aaa1fda3aefbb68bdad9e82a79d"
+  integrity sha1-oZbjP98eeqof2jrvu2i9rZ6Cp50=
+
 react-icons@^2.2.7:
   version "2.2.7"
   resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-2.2.7.tgz#d7860826b258557510dac10680abea5ca23cf650"