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

enhance: hide hidden properties by default

Show hidden properties only when zoom-in or opened in the sidebar.
Tienson Qin 1 год назад
Родитель
Сommit
b1dd6ca703

+ 3 - 3
deps/db/src/logseq/db/frontend/property.cljs

@@ -24,15 +24,15 @@
           :schema {:type :page
                    :cardinality :many
                    :classes #{:logseq.class}}}
+   ;; TODO: why need :pagetags?
    :pagetags {:original-name "pageTags"
               :visible true
               :schema {:type :page
                        :cardinality :many}}
-   :background-color {:schema {:type :default :hide? true}
-                      :visible true}
+   :background-color {:schema {:type :default :hide? true}}
    :background-image {:schema {:type :default :hide? true}
                       :visible true}
-   :heading {:schema {:type :any}}      ; number (1-6) or boolean for auto heading
+   :heading {:schema {:type :any :hide? true}}      ; number (1-6) or boolean for auto heading
    :query-table {:schema {:type :checkbox}}
    ;; query-properties is a coll of property uuids and keywords where keywords are special frontend keywords
    :query-properties {:schema {:type :coll}}

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

@@ -2130,7 +2130,8 @@
                                         :page-cp page-cp
                                         :block-cp blocks-container
                                         :properties-cp db-properties-cp
-                                        :editor-box (get config :editor-box)}
+                                        :editor-box (get config :editor-box)
+                                        :id (:id config)}
                                        opts)))
 
 (rum/defc invalid-properties-cp

+ 10 - 20
src/main/frontend/components/property.cljs

@@ -622,18 +622,6 @@
         (for [[k v] properties]
           (property-cp block k v opts))))))
 
-(rum/defcs hidden-properties < (rum/local true ::hide?)
-  [state block hidden-properties opts]
-  (let [*hide? (::hide? state)]
-    [:div.hidden-properties.flex.flex-col.gap-1
-     [:a.text-sm.flex.flex-row.items-center.fade-link.select-none
-      {:on-click #(swap! *hide? not)}
-      [:span {:style {:margin-left -1}}
-       (ui/rotating-arrow @*hide?)]
-      [:div {:style {:margin-left 3}} "Hidden properties"]]
-     (when-not @*hide?
-       (properties-section block hidden-properties opts))]))
-
 ;; TODO: Remove :page-configure? as it only ever seems to be set to true
 (rum/defcs ^:large-vars/cleanup-todo properties-area < rum/reactive
   {:init (fn [state]
@@ -661,10 +649,13 @@
                                           (seq properties))
                                   remove-built-in-properties
                                   (remove (fn [[id _]] ((set classes-properties) id))))
+        root-block? (= (:id opts) (str (:block/uuid block)))
         ;; This section produces own-properties and full-hidden-properties
         hide-with-property-id (fn [property-id]
-                                (let [eid (if (uuid? property-id) [:block/uuid property-id] property-id)]
-                                  (boolean (:hide? (:block/schema (db/entity eid))))))
+                                (if root-block?
+                                  false
+                                  (let [eid (if (uuid? property-id) [:block/uuid property-id] property-id)]
+                                    (boolean (:hide? (:block/schema (db/entity eid)))))))
         property-hide-f (cond
                           config/publishing?
                           ;; Publishing is read only so hide all blank properties as they
@@ -680,16 +671,15 @@
                               (nil? property-value)))
                           :else
                           (comp hide-with-property-id first))
-        {block-hidden-properties true
+        {_block-hidden-properties true
          block-own-properties' false} (group-by property-hide-f block-own-properties)
-        {class-hidden-properties true
+        {_class-hidden-properties true
          class-own-properties false} (group-by property-hide-f
                                                (map (fn [id] [id (get block-properties id)]) classes-properties))
         own-properties (->>
                         (if one-class?
                           (concat block-own-properties' class-own-properties)
                           block-own-properties'))
-        full-hidden-properties (concat block-hidden-properties class-hidden-properties)
         class->properties (loop [classes all-classes
                                  properties #{}
                                  result []]
@@ -702,7 +692,7 @@
                                        (conj result [class cur-properties])))
                               result))
         keyboard-triggered? (= (state/sub :editor/new-property-input-id) edit-input-id)]
-    (when-not (and (empty? block-own-properties)
+    (when-not (and (empty? block-own-properties')
                    (empty? class->properties)
                    (not (:page-configure? opts))
                    (not keyboard-triggered?))
@@ -714,8 +704,8 @@
                                  (update :class conj "select-none"))
        (properties-section block (if class-schema? properties own-properties) opts)
 
-       (when (and (seq full-hidden-properties) (not class-schema?) (not config/publishing?))
-         (hidden-properties block full-hidden-properties opts))
+       ;; (when (and (seq full-hidden-properties) (not class-schema?) (not config/publishing?))
+       ;;   (hidden-properties block full-hidden-properties opts))
 
        (rum/with-key (new-property block id keyboard-triggered? opts) (str id "-add-property"))
 

+ 11 - 10
src/main/frontend/handler/db_based/property/util.cljs

@@ -4,7 +4,8 @@
             [frontend.state :as state]
             [logseq.db.frontend.property :as db-property]
             [logseq.common.util :as common-util]
-            [clojure.set :as set]))
+            [clojure.set :as set]
+            [frontend.db :as db]))
 
 (defn get-property-name
   "Get a property's name given its uuid"
@@ -23,17 +24,17 @@
   ([repo property-name]
    (:block/uuid (db-utils/entity repo [:block/name (common-util/page-name-sanity-lc (name property-name))]))))
 
-(defonce *hidden-built-in-properties (atom #{}))
+(defn all-hidden-properties?
+  "Checks if the given properties are all hidden properties"
+  [properties]
+  (every? (fn [id]
+            (:hide? (:block/schema (db/entity [:block/uuid id])))) properties))
 
-(defn all-hidden-built-in-properties?
-  "Checks if the given properties are all hidden built-in properties"
+(defn has-hidden-properties?
+  "Checks if the given properties has any hidden properties"
   [properties]
-  (let [repo (state/get-current-repo)]
-    (when (empty? @*hidden-built-in-properties)
-      (let [built-in-properties (set (map #(get-built-in-property-uuid repo (name %))
-                                          db-property/hidden-built-in-properties))]
-        (reset! *hidden-built-in-properties built-in-properties)))
-    (set/subset? (set properties) @*hidden-built-in-properties)))
+  (some (fn [id]
+          (:hide? (:block/schema (db/entity [:block/uuid id])))) properties))
 
 (defn readable-properties
   "Given a DB graph's properties, returns a readable properties map with keys as

+ 1 - 1
src/main/frontend/handler/editor.cljs

@@ -3444,7 +3444,7 @@
                (valid-custom-query-block? block)
                (and db-based?
                     (seq (:block/properties block))
-                    (not (db-pu/all-hidden-built-in-properties? (keys (:block/properties block)))))
+                    (not (db-pu/all-hidden-properties? (keys (:block/properties block)))))
                (and db-based? (seq tags)
                     (some (fn [t] (seq (:properties (:block/schema t)))) tags))
                (and