Browse Source

fix: disable page/block preview when editing

Tienson Qin 3 years ago
parent
commit
f3ed5e60c8
2 changed files with 11 additions and 5 deletions
  1. 5 1
      src/main/frontend/components/block.cljs
  2. 6 4
      src/main/frontend/ui.cljs

+ 5 - 1
src/main/frontend/components/block.cljs

@@ -509,6 +509,7 @@
 
     (if (or (not manual?) open?)
       (ui/tippy {:ref             *tippy-ref
+                 :in-editor?      true
                  :html            html-template
                  :interactive     true
                  :delay           [1000, 100]
@@ -761,6 +762,7 @@
                                           (db/get-block-and-children repo block-id)
                                           (assoc config :id (str id) :preview? true))]])
                         :interactive true
+                        :in-editor?  true
                         :delay       [1000, 100]} inner)
              inner)])
         [:span.warning.mr-1 {:title "Block ref invalid"}
@@ -1056,7 +1058,8 @@
      (when-not (string/blank? query)
        (custom-query (assoc config :dsl-query? true)
                      {:title (ui/tippy {:html commands/query-doc
-                                        :interactive true}
+                                        :interactive true
+                                        :in-editor?  true}
                                        [:span.font-medium.px-2.py-1.query-title.text-sm.rounded-md.shadow-xs
                                         (str "Query: " query)])
                       :query query})))])
@@ -1981,6 +1984,7 @@
                                          (for [clock (take 10 (reverse clocks))]
                                            [:li clock])]])))
                     :interactive true
+                    :in-editor?  true
                     :delay       [1000, 100]}
                    [:div.text-sm.time-spent.ml-1 {:style {:padding-top 3}}
                     [:a.fade-link

+ 6 - 4
src/main/frontend/ui.cljs

@@ -787,12 +787,13 @@
           :checked selected}]
         label])]))
 
-(rum/defcs tippy < rum/static
+(rum/defcs tippy < rum/reactive
   (rum/local false ::mounted?)
-  [state {:keys [fixed-position? open?] :as opts} child]
+  [state {:keys [fixed-position? open? in-editor?] :as opts} child]
   (let [*mounted? (::mounted? state)
         mounted? @*mounted?
-        manual (not= open? nil)]
+        manual (not= open? nil)
+        editing? (state/sub :editor/editing?)]
     (Tippy (->
             (merge {:arrow true
                     :sticky true
@@ -800,7 +801,8 @@
                     :theme "customized"
                     :disabled (not (state/enable-tooltip?))
                     :unmountHTMLWhenHide true
-                    :open (if manual open? @*mounted?)
+                    :open (when-not (and in-editor? editing?)
+                            (if manual open? @*mounted?))
                     :trigger (if manual "manual" "mouseenter focus")
                     ;; See https://github.com/tvkhoa/react-tippy/issues/13
                     :popperOptions {:modifiers {:flip {:enabled (not fixed-position?)}