Browse Source

enhance: move tags and icon to properties area too

Tienson Qin 1 năm trước cách đây
mục cha
commit
81da3a9960

+ 2 - 1
deps/db/src/logseq/db/frontend/property.cljs

@@ -51,7 +51,8 @@
    :logseq.property/created-from-property {:schema {:type :entity}}
    :logseq.property/created-from-template {:schema {:type :entity}}
    :logseq.property/source-page           {:schema {:type :entity}}
-   :logseq.property/built-in?             {:schema {:type :checkbox}}
+   :logseq.property/built-in?             {:schema {:type :checkbox}
+                                           :hide? true}
    :logseq.property/hide-properties?      {:schema {:type :checkbox}}
    :logseq.property/query-table {:schema {:type :checkbox}}
    ;; query-properties is a coll of property uuids and keywords where keywords are special frontend keywords

+ 9 - 41
src/main/frontend/components/db_based/page.cljs

@@ -57,30 +57,6 @@
                                            (str edit-input-id-prefix "-page")
                                            (assoc configure-opts :class-schema? false :page? true)))])))
 
-(rum/defc icon-row < rum/reactive
-  [page]
-  [:div.grid.grid-cols-5.gap-1.items-center
-   [:label.col-span-2 "Icon:"]
-   (let [icon-value (:logseq.property/icon page)]
-     [:div.col-span-3.flex.flex-row.items-center.gap-2
-      (icon-component/icon-picker icon-value
-                                  {:disabled? config/publishing?
-                                   :on-chosen (fn [_e icon]
-                                                (db-property-handler/set-block-property!
-                                                 (state/get-current-repo)
-                                                 (:db/id page)
-                                                 :logseq.property/icon
-                                                 icon
-                                                 {}))})
-      (when (and icon-value (not config/publishing?))
-        [:a.fade-link.flex {:on-click (fn [_e]
-                                        (db-property-handler/remove-block-property!
-                                         (state/get-current-repo)
-                                         (:db/id page)
-                                         :logseq.property/icon))
-                            :title "Delete this icon"}
-         (ui/icon "X")])])])
-
 (rum/defc tags
   [page]
   (let [tags-property (db/entity :block/tags)]
@@ -90,13 +66,6 @@
                                    (component-block/page-cp (assoc config :tag? true) page))
                         :inline-text component-block/inline-text})))
 
-(rum/defc tags-row < rum/reactive
-  [page]
-  [:div.grid.grid-cols-5.gap-1.items-center
-   [:label.col-span-2 "Tags:"]
-   [:div.col-span-3.flex.flex-row.items-center.gap-2
-    (tags page)]])
-
 (rum/defcs page-configure < rum/reactive
   [state page *mode]
   (let [*mode *mode
@@ -110,16 +79,15 @@
                       class? :class
                       property? :property
                       :else :page)))
-    [:div.flex.flex-col.gap-1
-     [:<>
-      (when (= mode :property)
-        (property-component/property-config page {:inline-text component-block/inline-text}))
-      (when (= mode :class)
-        (class-component/configure page {:show-title? false}))
-      (when-not config/publishing? (tags-row page))
-      (when-not config/publishing? (icon-row page))
-      [:h2 "Properties: "]
-      (page-properties page (assoc page-opts :mode mode))]]))
+    [:div.flex.flex-col.gap-1.pt-2.pb-4
+     (case mode
+       :property
+       (property-component/property-config page {:inline-text component-block/inline-text})
+
+       :class
+       (class-component/configure page {:show-title? false})
+
+       (page-properties page (assoc page-opts :mode mode)))]))
 
 (rum/defc page-properties-react < rum/reactive
   [page* page-opts]

+ 8 - 2
src/main/frontend/components/property.cljs

@@ -716,6 +716,7 @@
   [state target-block edit-input-id {:keys [in-block-container? page? page-configure? class-schema?] :as opts}]
   (let [id (::id state)
         block (resolve-linked-block-if-exists target-block)
+        page? (db/page? block)
         block-properties (:block/properties block)
         properties (if (and class-schema? page-configure?)
                      (->> (db-property/get-class-ordered-properties block)
@@ -725,7 +726,7 @@
                                      (remove (fn [property]
                                                (let [id (if (vector? property) (first property) property)]
                                                  (or
-                                                  (= id :block/tags)
+                                                  (when-not page? (= id :block/tags))
                                                   (when-let [ent (db/entity id)]
                                                     (and (not (get-in ent [:block/schema :public?]))
                                                          (ldb/built-in? ent))))))
@@ -792,7 +793,12 @@
                                                        (.closest (.-target %) "[blockid]"))]
                                    (state/set-selection-blocks! [block])
                                    (some-> js/document.activeElement (.blur)))))
-       (properties-section block (if class-schema? properties own-properties) opts)
+       (let [own-properties' (if (and page? (not class-schema?))
+                               (concat [[:block/tags (:block/tags block)]
+                                        [:logseq.property/icon (:logseq.property/icon block)]]
+                                       (remove (fn [[k _v]] (contains? #{:block/tags :logseq.property/icon} k)) own-properties))
+                               own-properties)]
+         (properties-section block (if class-schema? properties own-properties') opts))
 
        (rum/with-key (new-property block id keyboard-triggered? opts) (str id "-add-property"))
 

+ 49 - 25
src/main/frontend/components/property/value.cljs

@@ -27,6 +27,28 @@
             [datascript.impl.entity :as de]
             [frontend.handler.property.util :as pu]))
 
+(rum/defc icon-row < rum/reactive
+  [block]
+  (let [icon-value (:logseq.property/icon block)]
+    [:div.col-span-3.flex.flex-row.items-center.gap-2
+     (icon-component/icon-picker icon-value
+                                 {:disabled? config/publishing?
+                                  :on-chosen (fn [_e icon]
+                                               (db-property-handler/set-block-property!
+                                                (state/get-current-repo)
+                                                (:db/id block)
+                                                :logseq.property/icon
+                                                icon
+                                                {}))})
+     (when (and icon-value (not config/publishing?))
+       [:a.fade-link.flex {:on-click (fn [_e]
+                                       (db-property-handler/remove-block-property!
+                                        (state/get-current-repo)
+                                        (:db/id block)
+                                        :logseq.property/icon))
+                           :title "Delete this icon"}
+        (ui/icon "X")])]))
+
 (defn- select-type?
   [property type]
   (or (contains? #{:page :number :url :date} type)
@@ -714,32 +736,34 @@
         value (if (and (de/entity? value) (= (:db/ident value) :logseq.property/empty-placeholder))
                 nil
                 value)]
-    (if (and select-type?
-             (not (and (not closed-values?) (= type :date))))
-      (single-value-select block property value
-                           (fn []
-                             (select-item property type value opts))
-                           select-opts
-                           (assoc opts :editing? editing?))
-      (case type
-        :date
-        (property-value-date-picker block property value {:editing? editing?})
-
-        :checkbox
-        (let [add-property! (fn []
-                              (<add-property! block (:db/ident property) (boolean (not value))))]
-          (shui/checkbox {:class "jtrigger flex flex-row items-center"
-                          :checked value
-                          :auto-focus editing?
-                          :on-checked-change add-property!
-                          :on-key-down (fn [e]
-                                         (when (= (util/ekey e) "Enter")
-                                           (add-property!)))}))
+    (if (= :logseq.property/icon (:db/ident property))
+      (icon-row block)
+      (if (and select-type?
+              (not (and (not closed-values?) (= type :date))))
+       (single-value-select block property value
+                            (fn []
+                              (select-item property type value opts))
+                            select-opts
+                            (assoc opts :editing? editing?))
+       (case type
+         :date
+         (property-value-date-picker block property value {:editing? editing?})
+
+         :checkbox
+         (let [add-property! (fn []
+                               (<add-property! block (:db/ident property) (boolean (not value))))]
+           (shui/checkbox {:class "jtrigger flex flex-row items-center"
+                           :checked value
+                           :auto-focus editing?
+                           :on-checked-change add-property!
+                           :on-key-down (fn [e]
+                                          (when (= (util/ekey e) "Enter")
+                                            (add-property!)))}))
         ;; :others
-        [:div.flex.flex-1
-         (if editing?
-           (property-editing block property value schema editor-box editor-args editor-id)
-           (property-value-inner block property value opts))]))))
+         [:div.flex.flex-1
+          (if editing?
+            (property-editing block property value schema editor-box editor-args editor-id)
+            (property-value-inner block property value opts))])))))
 
 (rum/defc multiple-values
   [block property v {:keys [on-chosen dropdown? editing?]

+ 33 - 36
src/main/frontend/handler/db_based/property.cljs

@@ -201,17 +201,13 @@
                       (catch :default e
                         (notification/show! (str e) :error false)
                         nil))
-            tags-or-alias? (contains? db-property/db-attribute-properties property-id)
-            old-values (if tags-or-alias?
-                         (->> (get block property-id)
-                              (map (fn [e] (:db/id e))))
-                         (get block (:db/ident property)))]
+            old-values (get block (:db/ident property))]
         (when (not= old-values values')
           (if-let [msg (some #(validate-property-value schema %) values')]
             (let [msg' (str "\"" property-name "\"" " " (if (coll? msg) (first msg) msg))]
               (notification/show! msg' :warning))
             (do
-              (when-not tags-or-alias? (upsert-property! repo property-id (assoc property-schema :type property-type) {}))
+              (upsert-property! repo property-id (assoc property-schema :type property-type) {})
               (let [pair-id (:db/id (db-property/get-pair-e block property-id))
                     tx-data (concat
                              [(when pair-id [:db/retract pair-id property-id])]
@@ -257,9 +253,16 @@
         property-schema (:block/schema property)
         {:keys [type cardinality]} property-schema
         multiple-values? (= cardinality :many)
-        v (or (resolve-tag v) v)]
-    (if (and multiple-values? (coll? v))
+        v (or (resolve-tag v) v)
+        db-attribute? (contains? db-property/db-attribute-properties property-id)]
+    (cond
+      db-attribute?
+      (db/transact! repo [{:db/id (:db/id block) property-id v}]
+        {:outliner-op :save-block})
+      (and multiple-values? (coll? v))
       (reset-block-property-multiple-values! repo block-eid property-id v opts)
+
+      :else
       (let [v (if property v (or v ""))]
         (when (some? v)
           (let [infer-schema (when-not type (infer-schema-from-input-string v))
@@ -274,35 +277,29 @@
                        (catch :default e
                          (js/console.error e)
                          (notification/show! (str e) :error false)
-                         nil)))
-                tags-or-alias? (and (contains? db-property/db-attribute-properties property-id) (uuid? v*))]
-            (if tags-or-alias?
-              (let [property-value-id v*]
-                (db/transact! repo
-                              [[:db/add (:db/id block) property-id property-value-id]]
-                              {:outliner-op :save-block}))
-              (when-not (contains? (if (set? value) value #{value}) v*)
-                (if-let [msg (when-not (= v* :logseq.property/empty-placeholder) (validate-property-value schema v*))]
-                  (let [msg' (str "\"" k-name "\"" " " (if (coll? msg) (first msg) msg))]
-                    (notification/show! msg' :warning))
-                  (let [_ (upsert-property! repo property-id (assoc property-schema :type property-type) {:property-name property-name})
-                        status? (= :logseq.task/status (:db/ident property))
-                        value (if (= value :logseq.property/empty-placeholder) [] value)
-                        new-value (cond
-                                    multiple-values?
-                                    (let [f (if (coll? v*) concat conj)]
-                                      (f value v*))
-
-                                    :else
-                                    v*)
+                         nil)))]
+            (when-not (contains? (if (set? value) value #{value}) v*)
+              (if-let [msg (when-not (= v* :logseq.property/empty-placeholder) (validate-property-value schema v*))]
+                (let [msg' (str "\"" k-name "\"" " " (if (coll? msg) (first msg) msg))]
+                  (notification/show! msg' :warning))
+                (let [_ (upsert-property! repo property-id (assoc property-schema :type property-type) {:property-name property-name})
+                      status? (= :logseq.task/status (:db/ident property))
+                      value (if (= value :logseq.property/empty-placeholder) [] value)
+                      new-value (cond
+                                  multiple-values?
+                                  (let [f (if (coll? v*) concat conj)]
+                                    (f value v*))
+
+                                  :else
+                                  v*)
                         ;; don't modify maps
-                        new-value (if (or (sequential? new-value) (set? new-value))
-                                    (if (= :coll property-type)
-                                      (vec (remove string/blank? new-value))
-                                      (set (remove string/blank? new-value)))
-                                    new-value)
-                        tx-data (build-property-value-tx-data block property-id new-value status?)]
-                    (db/transact! repo tx-data {:outliner-op :save-block})))))))))))
+                      new-value (if (or (sequential? new-value) (set? new-value))
+                                  (if (= :coll property-type)
+                                    (vec (remove string/blank? new-value))
+                                    (set (remove string/blank? new-value)))
+                                  new-value)
+                      tx-data (build-property-value-tx-data block property-id new-value status?)]
+                  (db/transact! repo tx-data {:outliner-op :save-block}))))))))))
 
 (defn class-add-property!
   [repo class-uuid property-id]