Просмотр исходного кода

enhance: add a link button for embedded block and page icon for page

Tienson Qin 2 лет назад
Родитель
Сommit
eb09da9730

+ 13 - 4
src/main/frontend/components/block.cljs

@@ -19,6 +19,7 @@
             [frontend.components.query.builder :as query-builder-component]
             [frontend.components.svg :as svg]
             [frontend.components.query :as query]
+            [frontend.components.icon :as icon]
             [frontend.components.property :as property-component]
             [frontend.components.property.value :as pv]
             [frontend.config :as config]
@@ -2363,7 +2364,9 @@
             [:div.flex.flex-1.w-full.flex-row.flex-wrap.justify-between.items-center
              (cond
                (:block/name block)
-               (page-cp config block)
+               [:div.flex.flex-row.items-center.gap-1
+                (icon/get-page-icon block {})
+                (page-cp config block)]
 
                (or (seq title) (:block/marker block))
                (build-block-title config block)
@@ -2371,8 +2374,13 @@
                :else
                nil)
 
-             (when (seq block-tags)
-               (tags config block))]]))
+             [:div.flex.flex-row.items-center.gap-1
+              (when (seq block-tags)
+                (tags config block))
+              (when (and (:original-block config) (not (:block/name block)))
+                [:a.fade-link {:title "Embed block"
+                               :href (rfe/href :page {:name (str (:block/uuid block))})}
+                 (ui/icon "link")])]]]))
 
        (clock-summary-cp block body)]
 
@@ -2896,7 +2904,8 @@
                    (when (and card? (not review-cards?)) " shadow-md")
                    (when selected? " selected")
                    (when order-list? " is-order-list")
-                   (when (string/blank? content) " is-blank"))
+                   (when (string/blank? content) " is-blank")
+                   (when original-block " embed-block"))
        :blockid (str uuid)
        :haschild (str (boolean has-child?))}
 

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

@@ -27,7 +27,6 @@
             [frontend.handler.user :as user-handler]
             [frontend.handler.whiteboard :as whiteboard-handler]
             [frontend.handler.recent :as recent-handler]
-            [frontend.handler.property.util :as pu]
             [frontend.mixins :as mixins]
             [frontend.mobile.action-bar :as action-bar]
             [frontend.mobile.footer :as footer]
@@ -89,13 +88,7 @@
       (if untitiled? (t :untitled)
           (pdf-utils/fix-local-asset-pagename original-name))]]))
 
-(defn get-page-icon [page-entity]
-  (let [default-icon (ui/icon "page" {:extension? true})
-        page-icon (pu/get-property page-entity :icon)]
-    (or
-     (when-not (string/blank? page-icon)
-       (icon/icon page-icon))
-     default-icon))) ;; Fall back to default if icon is undefined or empty
+ ;; Fall back to default if icon is undefined or empty
 
 (rum/defc favorites < rum/reactive
   [t]
@@ -122,7 +115,7 @@
        (let [favorites (map
                         (fn [e]
                           (let [name (:block/name e)
-                                icon (get-page-icon e)]
+                                icon (icon/get-page-icon e {})]
                             {:id (str (:db/id e))
                              :value name
                              :content [:li.favorite-item (page-name name icon false)]}))
@@ -153,7 +146,7 @@
             :draggable true
             :on-drag-start (fn [event] (editor-handler/block->data-transfer! name event))
             :data-ref name}
-           (page-name name (get-page-icon entity) true)]))])))
+           (page-name name (icon/get-page-icon entity {}) true)]))])))
 
 (rum/defcs flashcards < db-mixins/query rum/reactive
   {:did-mount (fn [state]

+ 15 - 4
src/main/frontend/components/icon.cljs

@@ -10,16 +10,27 @@
             [frontend.ui :as ui]
             [frontend.util :as util]
             [goog.object :as gobj]
-            [goog.functions :refer [debounce]]))
+            [goog.functions :refer [debounce]]
+            [frontend.handler.property.util :as pu]))
 
 (defn icon
-  [icon]
+  [icon & opts]
   (cond
     (and (= :emoji (:type icon)) (:id icon))
-    [:em-emoji {:id (:id icon)}]
+    [:em-emoji (merge {:id (:id icon)}
+                      opts)]
 
     (and (= :tabler-icon (:type icon)) (:id icon))
-    (ui/icon (:id icon))))
+    (ui/icon (:id icon) opts)))
+
+(defn get-page-icon
+  [page-entity opts]
+  (let [default-icon (ui/icon "page" (merge opts {:extension? true}))
+        page-icon (pu/get-property page-entity :icon)]
+    (or
+     (when-not (string/blank? page-icon)
+       (icon page-icon opts))
+     default-icon)))
 
 (defn- search-emojis
   [q]

+ 15 - 7
src/main/frontend/ui.cljs

@@ -1035,13 +1035,21 @@
    (when-not (string/blank? name)
      (let [^js jsTablerIcons (gobj/get js/window "tablerIcons")]
        (if (or extension? font? (not jsTablerIcons))
-         [:span.ui__icon (merge {:class
-                                 (util/format
-                                  (str "%s-" name
-                                       (when (:class opts)
-                                         (str " " (string/trim (:class opts)))))
-                                  (if extension? "tie tie" "ti ti"))}
-                                (dissoc opts :class :extension? :font?))]
+         (let [opts (merge {:class
+                            (util/format
+                             (str "%s-" name
+                                  (when (:class opts)
+                                    (str " " (string/trim (:class opts)))))
+                             (if extension? "tie tie" "ti ti"))}
+                           (dissoc opts :class :extension? :font?))
+               opts' (cond
+                      (and size (:style opts))
+                      (assoc opts :style (assoc (:style opts) :font-size size))
+                      size
+                      (assoc opts :style {:font-size size})
+                      :else
+                      opts)]
+           [:span.ui__icon opts'])
 
          ;; tabler svg react
          (when-let [klass (tabler-icon name)]