Przeglądaj źródła

feat: add whiteboard toggle

Peng Xiao 3 lat temu
rodzic
commit
035b96e70a

+ 4 - 6
deps/graph-parser/src/logseq/graph_parser/extract.cljc

@@ -185,10 +185,9 @@
        {:block/uuid (uuid (:pageId shape))})]))
        {:block/uuid (uuid (:pageId shape))})]))
 
 
 (defn- with-whiteboard-block-refs
 (defn- with-whiteboard-block-refs
-  [shape parent-ref]
+  [shape]
   (let [refs (or (get-shape-refs shape) [])]
   (let [refs (or (get-shape-refs shape) [])]
-    (merge {:block/refs refs
-            :block/path-refs (into [] (concat refs [parent-ref]))})))
+    (merge {:block/refs refs})))
 
 
 (defn- with-whiteboard-content
 (defn- with-whiteboard-content
   [shape]
   [shape]
@@ -200,11 +199,10 @@
 
 
 (defn with-whiteboard-block-props
 (defn with-whiteboard-block-props
   [block]
   [block]
-  (let [shape (:block/properties block)
-        parent (select-keys (:block/page block) [:block/name])]
+  (let [shape (:block/properties block)]
     (when (= :whiteboard-shape (:ls-type shape))
     (when (= :whiteboard-shape (:ls-type shape))
       (merge {:block/uuid (uuid (:id shape))}
       (merge {:block/uuid (uuid (:id shape))}
-             (with-whiteboard-block-refs shape parent)
+             (with-whiteboard-block-refs shape)
              (with-whiteboard-content shape)))))
              (with-whiteboard-content shape)))))
 
 
 (defn extract-whiteboard-edn
 (defn extract-whiteboard-edn

+ 16 - 1
src/main/frontend/components/settings.cljs

@@ -501,6 +501,14 @@
                  (config-handler/set-config! :feature/enable-flashcards? value)))
                  (config-handler/set-config! :feature/enable-flashcards? value)))
              true))
              true))
 
 
+(rum/defc whiteboards-enabled-switcher
+  [enable-whiteboards?]
+  (ui/toggle enable-whiteboards?
+             (fn []
+               (let [value (not enable-whiteboards?)]
+                 (config-handler/set-config! :feature/enable-whiteboards? value)))
+             true))
+
 (rum/defc user-proxy-settings
 (rum/defc user-proxy-settings
   [{:keys [protocol host port] :as agent-opts}]
   [{:keys [protocol host port] :as agent-opts}]
   (ui/button [:span
   (ui/button [:span
@@ -521,6 +529,11 @@
    {:left-label (t :settings-page/enable-flashcards)
    {:left-label (t :settings-page/enable-flashcards)
     :action (flashcards-enabled-switcher enable-flashcards?)}))
     :action (flashcards-enabled-switcher enable-flashcards?)}))
 
 
+(defn whiteboards-switcher-row [enable-whiteboards?]
+  (row-with-button-action
+   {:left-label (t :settings-page/enable-whiteboards)
+    :action (whiteboards-enabled-switcher enable-whiteboards?)}))
+
 (defn https-user-agent-row [agent-opts]
 (defn https-user-agent-row [agent-opts]
   (row-with-button-action
   (row-with-button-action
    {:left-label (t :settings-page/network-proxy)
    {:left-label (t :settings-page/network-proxy)
@@ -614,13 +627,15 @@
   (let [instrument-disabled? (state/sub :instrument/disabled?)
   (let [instrument-disabled? (state/sub :instrument/disabled?)
         developer-mode? (state/sub [:ui/developer-mode?])
         developer-mode? (state/sub [:ui/developer-mode?])
         https-agent-opts (state/sub [:electron/user-cfgs :settings/agent])
         https-agent-opts (state/sub [:electron/user-cfgs :settings/agent])
-        enable-flashcards? (state/enable-flashcards? current-repo)]
+        enable-flashcards? (state/enable-flashcards? current-repo)
+        enable-whiteboards? (state/enable-whiteboards? current-repo)]
     [:div.panel-wrap.is-advanced
     [:div.panel-wrap.is-advanced
      (when (and util/mac? (util/electron?)) (app-auto-update-row t))
      (when (and util/mac? (util/electron?)) (app-auto-update-row t))
      (usage-diagnostics-row t instrument-disabled?)
      (usage-diagnostics-row t instrument-disabled?)
      (when-not (mobile-util/native-platform?) (developer-mode-row t developer-mode?))
      (when-not (mobile-util/native-platform?) (developer-mode-row t developer-mode?))
      (when (and (util/electron?) config/enable-plugins?) (plugin-system-switcher-row))
      (when (and (util/electron?) config/enable-plugins?) (plugin-system-switcher-row))
      (flashcards-switcher-row enable-flashcards?)
      (flashcards-switcher-row enable-flashcards?)
+     (when (util/electron?) (whiteboards-switcher-row enable-whiteboards?))
      (when (util/electron?) (https-user-agent-row https-agent-opts))
      (when (util/electron?) (https-user-agent-row https-agent-opts))
      (clear-cache-row t)
      (clear-cache-row t)
 
 

+ 46 - 45
src/main/frontend/components/sidebar.cljs

@@ -62,7 +62,7 @@
   [e]
   [e]
   (when-let [target (.. e -target)]
   (when-let [target (.. e -target)]
     (let [rect (.. target getBoundingClientRect)]
     (let [rect (.. target getBoundingClientRect)]
-     (- (.. e -pageY) (.. rect -top)))))
+      (- (.. e -pageY) (.. rect -top)))))
 
 
 (defn- move-up?
 (defn- move-up?
   [e]
   [e]
@@ -235,60 +235,61 @@
        [:div.nav-header.flex.gap-1.flex-col
        [:div.nav-header.flex.gap-1.flex-col
         (if-let [page (:page default-home)]
         (if-let [page (:page default-home)]
           (sidebar-item
           (sidebar-item
-            {:class            "home-nav"
-             :title            page
-             :on-click-handler route-handler/redirect-to-home!
-             :active           (and (not srs-open?)
-                                    (= route-name :page)
-                                    (= page (get-in route-match [:path-params :name])))
-             :icon             "home"})
+           {:class            "home-nav"
+            :title            page
+            :on-click-handler route-handler/redirect-to-home!
+            :active           (and (not srs-open?)
+                                   (= route-name :page)
+                                   (= page (get-in route-match [:path-params :name])))
+            :icon             "home"})
           (sidebar-item
           (sidebar-item
-            {:class            "journals-nav"
-             :active           (and (not srs-open?)
-                                 (or (= route-name :all-journals) (= route-name :home)))
-             :title            (t :left-side-bar/journals)
-             :on-click-handler route-handler/go-to-journals!
-             :icon             "calendar"}))
+           {:class            "journals-nav"
+            :active           (and (not srs-open?)
+                                   (or (= route-name :all-journals) (= route-name :home)))
+            :title            (t :left-side-bar/journals)
+            :on-click-handler route-handler/go-to-journals!
+            :icon             "calendar"}))
 
 
         (when (state/enable-flashcards? (state/get-current-repo))
         (when (state/enable-flashcards? (state/get-current-repo))
           [:div.flashcards-nav
           [:div.flashcards-nav
            (flashcards srs-open?)])
            (flashcards srs-open?)])
 
 
         (sidebar-item
         (sidebar-item
-          {:class  "graph-view-nav"
-           :title  (t :right-side-bar/graph-view)
-           :href   (rfe/href :graph)
-           :active (and (not srs-open?) (= route-name :graph))
-           :icon   "hierarchy"})
+         {:class  "graph-view-nav"
+          :title  (t :right-side-bar/graph-view)
+          :href   (rfe/href :graph)
+          :active (and (not srs-open?) (= route-name :graph))
+          :icon   "hierarchy"})
 
 
         (sidebar-item
         (sidebar-item
-          {:class  "all-pages-nav"
-           :title  (t :right-side-bar/all-pages)
-           :href   (rfe/href :all-pages)
-           :active (and (not srs-open?) (= route-name :all-pages))
-           :icon   "files"})
-           
-        (sidebar-item
-         {:class "whiteboard"
-          :title "Whiteboards"
-          :href  (rfe/href :whiteboards)
-          :icon  "artboard"})]]
+         {:class  "all-pages-nav"
+          :title  (t :right-side-bar/all-pages)
+          :href   (rfe/href :all-pages)
+          :active (and (not srs-open?) (= route-name :all-pages))
+          :icon   "files"})
+
+        (when (state/enable-whiteboards?)
+          (sidebar-item
+           {:class "whiteboard"
+            :title "Whiteboards"
+            :href  (rfe/href :whiteboards)
+            :icon  "artboard"}))]]
 
 
       (favorites t)
       (favorites t)
 
 
       (when (and left-sidebar-open? (not config/publishing?)) (recent-pages t))
       (when (and left-sidebar-open? (not config/publishing?)) (recent-pages t))
 
 
       (when-not (mobile-util/native-platform?)
       (when-not (mobile-util/native-platform?)
-       [:nav.px-2 {:aria-label "Sidebar"
-                   :class      "new-page"}
-        (when-not config/publishing?
-          [:a.item.group.flex.items-center.px-2.py-2.text-sm.font-medium.rounded-md.new-page-link
-           {:on-click (fn []
-                        (and (util/sm-breakpoint?)
-                             (state/toggle-left-sidebar!))
-                        (state/pub-event! [:go/search]))}
-           (ui/icon "circle-plus mr-3" {:style {:font-size 20}})
-           [:span.flex-1 (t :right-side-bar/new-page)]])])]]))
+        [:nav.px-2 {:aria-label "Sidebar"
+                    :class      "new-page"}
+         (when-not config/publishing?
+           [:a.item.group.flex.items-center.px-2.py-2.text-sm.font-medium.rounded-md.new-page-link
+            {:on-click (fn []
+                         (and (util/sm-breakpoint?)
+                              (state/toggle-left-sidebar!))
+                         (state/pub-event! [:go/search]))}
+            (ui/icon "circle-plus mr-3" {:style {:font-size 20}})
+            [:span.flex-1 (t :right-side-bar/new-page)]])])]]))
 
 
 (rum/defc left-sidebar < rum/reactive
 (rum/defc left-sidebar < rum/reactive
   [{:keys [left-sidebar-open? route-match]}]
   [{:keys [left-sidebar-open? route-match]}]
@@ -350,7 +351,7 @@
       [:div.cp__sidebar-main-content
       [:div.cp__sidebar-main-content
        {:data-is-margin-less-pages margin-less-pages?
        {:data-is-margin-less-pages margin-less-pages?
         :data-is-full-width        (or margin-less-pages?
         :data-is-full-width        (or margin-less-pages?
-                                        (contains? #{:all-files :all-pages :my-publishing} route-name))}
+                                       (contains? #{:all-files :all-pages :my-publishing} route-name))}
 
 
        (when show-recording-bar?
        (when show-recording-bar?
          (recording-bar))
          (recording-bar))
@@ -432,7 +433,7 @@
                      (state/sidebar-add-block! current-repo db-id block-type)))
                      (state/sidebar-add-block! current-repo db-id block-type)))
                  (reset! sidebar-inited? true))))
                  (reset! sidebar-inited? true))))
            (when (state/mobile?)
            (when (state/mobile?)
-                  (state/set-state! :mobile/show-tabbar? true))
+             (state/set-state! :mobile/show-tabbar? true))
            state)}
            state)}
   []
   []
   (let [default-home (get-default-home-if-valid)
   (let [default-home (get-default-home-if-valid)
@@ -630,6 +631,6 @@
                                     :db-restoring? db-restoring?})
                                     :db-restoring? db-restoring?})
       [:a#download.hidden]
       [:a#download.hidden]
       (when
       (when
-          (and (not config/mobile?)
-               (not config/publishing?))
-          (help-button))])))
+       (and (not config/mobile?)
+            (not config/publishing?))
+        (help-button))])))

+ 2 - 0
src/main/frontend/dicts.cljc

@@ -188,6 +188,7 @@
         :settings-page/plugin-system "Plug-in system"
         :settings-page/plugin-system "Plug-in system"
         :settings-page/enable-flashcards "Flashcards"
         :settings-page/enable-flashcards "Flashcards"
         :settings-page/network-proxy "Network proxy"
         :settings-page/network-proxy "Network proxy"
+        :settings-page/enable-whiteboards "Whiteboards"
         :logseq "Logseq"
         :logseq "Logseq"
         :on "ON"
         :on "ON"
         :more-options "More options"
         :more-options "More options"
@@ -908,6 +909,7 @@
            :settings-page/enable-journals "开启日记"
            :settings-page/enable-journals "开启日记"
            :settings-page/enable-all-pages-public "发布所有页面"
            :settings-page/enable-all-pages-public "发布所有页面"
            :settings-page/enable-encryption "激活加密功能"
            :settings-page/enable-encryption "激活加密功能"
+           :settings-page/enable-whiteboards "激活白板功能"
            :settings-page/customize-shortcuts "自定义快捷键"
            :settings-page/customize-shortcuts "自定义快捷键"
            :settings-page/shortcut-settings "快捷键设置"
            :settings-page/shortcut-settings "快捷键设置"
            :settings-page/home-default-page "设置首页默认页面"
            :settings-page/home-default-page "设置首页默认页面"

+ 9 - 0
src/main/frontend/state.cljs

@@ -387,6 +387,15 @@
   (true? (:feature/enable-block-timestamps?
   (true? (:feature/enable-block-timestamps?
            (get (sub-config) (get-current-repo)))))
            (get (sub-config) (get-current-repo)))))
 
 
+(defn enable-whiteboards?
+  ([]
+   (enable-whiteboards? (get-current-repo)))
+  ([repo]
+   (and
+    (util/electron?)
+    (true? (:feature/enable-whiteboards?
+            (get (sub-config) repo))))))
+
 (defn sub-graph-config
 (defn sub-graph-config
   []
   []
   (get (sub-config) (get-current-repo)))
   (get (sub-config) (get-current-repo)))