Explorar o código

fix: context menu of whiteboard pages

Peng Xiao %!s(int64=3) %!d(string=hai) anos
pai
achega
a5e01895c7

+ 2 - 0
src/main/frontend/components/content.cljs

@@ -375,6 +375,8 @@
 (rum/defc hiccup-content < rum/static
   (mixins/event-mixin
    (fn [state]
+     ;; fixme: this mixin will register global event listeners on window
+     ;; which might cause unexpected issues
      (mixins/listen state js/window "contextmenu"
                     (fn [e]
                       (let [target (gobj/get e "target")

+ 13 - 13
src/main/frontend/components/page.cljs

@@ -287,19 +287,19 @@
           old-name (or title page-name)]
       [:h1.page-title.flex.cursor-pointer.gap-1.w-full
        {:on-mouse-down (fn [e]
-                           (when (util/right-click? e)
-                             (state/set-state! :page-title/context {:page page-name})))
-          :on-click (fn [e]
-                      (.preventDefault e)
-                      (if (gobj/get e "shiftKey")
-                        (when-let [page (db/pull repo '[*] [:block/name page-name])]
-                          (state/sidebar-add-block!
-                           repo
-                           (:db/id page)
-                           :page))
-                        (when (and (not hls-page?) (not fmt-journal?))
-                          (reset! *input-value (if untitled? "" old-name))
-                          (reset! *edit? true))))}
+                         (when (util/right-click? e)
+                           (state/set-state! :page-title/context {:page page-name})))
+        :on-click (fn [e]
+                    (.preventDefault e)
+                    (if (gobj/get e "shiftKey")
+                      (when-let [page (db/pull repo '[*] [:block/name page-name])]
+                        (state/sidebar-add-block!
+                         repo
+                         (:db/id page)
+                         :page))
+                      (when (and (not hls-page?) (not fmt-journal?))
+                        (reset! *input-value (if untitled? "" old-name))
+                        (reset! *edit? true))))}
        (when (not= icon "") [:span.page-icon icon])
        [:div.page-title-sizer-wrapper.relative
         (when (rum/react *edit?)

+ 11 - 2
src/main/frontend/components/whiteboard.cljs

@@ -1,14 +1,17 @@
 (ns frontend.components.whiteboard
   "Whiteboard related components"
   (:require [cljs.math :as math]
+            [frontend.components.content :as content]
             [frontend.components.page :as page]
             [frontend.components.reference :as reference]
             [frontend.context.i18n :refer [t]]
             [frontend.db.model :as model]
+            [frontend.handler.common :as common-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.user :as user-handler]
             [frontend.handler.whiteboard :as whiteboard-handler]
-            [frontend.rum :refer [use-bounding-client-rect use-click-outside use-breakpoint]]
+            [frontend.rum :refer [use-bounding-client-rect use-breakpoint
+                                  use-click-outside]]
             [frontend.state :as state]
             [frontend.ui :as ui]
             [frontend.util :as util]
@@ -230,7 +233,13 @@
      [:div.whiteboard-page-title-root
       [:div.whiteboard-page-title
        {:style {:color "var(--ls-primary-text-color)"
-                :user-select "none"}}
+                :user-select "none"}
+        :on-context-menu (fn [e]
+                           (util/stop e)
+                           (common-handler/show-custom-context-menu!
+                            e
+                            (content/page-title-custom-context-menu-content page-name))
+                           (state/set-state! :page-title/context nil))}
        (page/page-title page-name
                         [:span.text-lg
                          (ui/icon "whiteboard" {:extension? true})]

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

@@ -697,7 +697,7 @@ Similar to re-frame subscriptions"
 
 (defn get-current-page
   []
-  (when (= :page (get-current-route))
+  (when (#{:page :whiteboard} (get-current-route))
     (get-in (get-route-match)
             [:path-params :name])))