Browse Source

wip: handle built-in properties

Tienson Qin 2 years ago
parent
commit
dbcd082f08

+ 9 - 2
deps/graph-parser/src/logseq/graph_parser/property.cljs

@@ -47,6 +47,7 @@
   "Properties used by logseq that user can edit and that can have linkable property values"
   #{:alias :aliases :tags})
 
+;; file based graphs only
 (def editable-view-and-table-properties
   "Properties used by view and table component"
   #{;; view props
@@ -69,8 +70,9 @@
   "Properties used by logseq that user can't edit or see"
   []
   (set/union
-   #{:id :custom-id :background-color :background_color :heading :collapsed
-     :created-at :updated-at :last-modified-at :created_at :last_modified_at
+   #{:custom-id :background_color :created_at :last_modified_at ; backward compatibility only
+     :id :background-color :heading :collapsed
+     :created-at :updated-at :last-modified-at
      :query-table :query-properties :query-sort-by :query-sort-desc :ls-type
      :hl-type :hl-page :hl-stamp :hl-color :logseq.macro-name :logseq.macro-arguments
      :logseq.order-list-type :logseq.tldraw.page :logseq.tldraw.shape
@@ -78,6 +80,11 @@
      :todo :doing :now :later :done}
    @built-in-extended-properties))
 
+(defn full-built-in-properties
+  "All the built-in properties used by logseq"
+  []
+  (set/union (editable-built-in-properties) (hidden-built-in-properties)))
+
 (def built-in-property-types
   "Types for built-in properties. Built-in properties whose values are to be
   parsed by gp-text/parse-non-string-property-value should be added here"

+ 6 - 6
deps/graph-parser/src/logseq/graph_parser/whiteboard.cljs

@@ -1,17 +1,17 @@
 (ns logseq.graph-parser.whiteboard
-  "Whiteboard related parser utilities" 
+  "Whiteboard related parser utilities"
   (:require [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.util.block-ref :as block-ref]
             [logseq.graph-parser.util.page-ref :as page-ref]))
 
 (defn block->shape [block]
-  (get-in block [:block/properties :logseq.tldraw.shape] nil))
+  (get-in block [:block/properties :logseq.tldraw.shape]))
 
 (defn page-block->tldr-page [block]
-  (get-in block [:block/properties :logseq.tldraw.page] nil))
+  (get-in block [:block/properties :logseq.tldraw.page]))
 
 (defn shape-block? [block]
-  (= :whiteboard-shape (get-in block [:block/properties :ls-type] nil)))
+  (= :whiteboard-shape (get-in block [:block/properties :ls-type])))
 
 ;; tldraw shape props is now saved into [:block/properties :logseq.tldraw.shape]
 ;; migrate
@@ -19,13 +19,13 @@
   (let [properties (:block/properties block)]
     (and (seq properties)
          (and (= :whiteboard-shape (:ls-type properties))
-              (not (seq (get properties :logseq.tldraw.shape nil)))))))
+              (not (seq (get properties :logseq.tldraw.shape)))))))
 
 (defn page-block-needs-migrate? [block]
   (let [properties (:block/properties block)]
     (and (seq properties)
          (and (= :whiteboard-page (:ls-type properties))
-              (not (seq (get properties :logseq.tldraw.page nil)))))))
+              (not (seq (get properties :logseq.tldraw.page)))))))
 
 (defn migrate-shape-block [block]
   (if (shape-block-needs-migrate? block)

+ 32 - 20
src/main/frontend/components/block.cljs

@@ -48,6 +48,8 @@
             [frontend.handler.ui :as ui-handler]
             [frontend.handler.whiteboard :as whiteboard-handler]
             [frontend.handler.export.common :as export-common-handler]
+            [frontend.handler.property :as property-handler]
+            [frontend.handler.property.util :as pu]
             [frontend.mobile.util :as mobile-util]
             [frontend.modules.outliner.tree :as tree]
             [frontend.security :as security]
@@ -869,8 +871,9 @@
         [:span "Loading..."]
         (let [db-id (:db/id block)
               block (when db-id (db/sub-block db-id))
-              block-type (keyword (get-in block [:block/properties :ls-type]))
-              hl-type (get-in block [:block/properties :hl-type])
+              properties (:block/properties block)
+              block-type (keyword (pu/lookup properties :ls-type))
+              hl-type (pu/lookup properties :hl-type)
               repo (state/get-current-repo)
               stop-inner-events? (= block-type :whiteboard-shape)]
           (if (and block (:block/content block))
@@ -1371,14 +1374,14 @@
   [name config arguments]
   (if-let [block-uuid (:block/uuid config)]
     (let [format (get-in config [:block :block/format] :markdown)
+          properties (-> (db/entity [:block/uuid block-uuid])
+                         (:block/page)
+                         (:db/id)
+                         (db/entity)
+                         :block/properties)
+          macros (pu/lookup properties :macros)
           macro-content (or
-                         (-> (db/entity [:block/uuid block-uuid])
-                             (:block/page)
-                             (:db/id)
-                             (db/entity)
-                             :block/properties
-                             :macros
-                             (get name))
+                         (get macros name)
                          (get (state/get-macros) name)
                          (get (state/get-macros) (keyword name)))
           macro-content (cond
@@ -1907,7 +1910,9 @@
   (let [config (assoc config :block t)
         slide? (boolean (:slide? config))
         block-ref? (:block-ref? config)
-        block-type (or (keyword (:ls-type properties)) :default)
+        block-type (or (keyword
+                        (pu/lookup properties :ls-type))
+                       :default)
         html-export? (:html-export? config)
         checkbox (when (and (not pre-block?)
                             (not html-export?))
@@ -1917,14 +1922,14 @@
                         (marker-switch t))
         marker-cp (marker-cp t)
         priority (priority-cp t)
-        bg-color (:background-color properties)
+        bg-color (pu/lookup properties :background-color)
         ;; `heading-level` is for backward compatibility, will remove it in later releases
         heading-level (:block/heading-level t)
         heading (or
                  (and heading-level
                       (<= heading-level 6)
                       heading-level)
-                 (:heading properties))
+                 (pu/lookup properties :heading))
         heading (if (true? heading) (min (inc level) 6) heading)
         elem (if heading
                (keyword (str "h" heading
@@ -1933,7 +1938,7 @@
     (->elem
      elem
      (merge
-      {:data-hl-type (:hl-type properties)}
+      {:data-hl-type (pu/lookup properties :hl-type)}
       (when (and marker
                  (not (string/blank? marker))
                  (not= "nil" marker))
@@ -1947,7 +1952,7 @@
            :class "px-1 with-bg-color"})))
 
      ;; children
-     (let [area?  (= :area (keyword (:hl-type properties)))
+     (let [area?  (= :area (keyword (pu/lookup properties :hl-type)))
            hl-ref #(when (and (or config/publishing? (util/electron?))
                               (not (#{:default :whiteboard-shape} block-type)))
                      [:div.prefix-link
@@ -1966,10 +1971,13 @@
                              :dune)))}
 
                       [:span.hl-page
-                       [:strong.forbid-edit (str "P" (or (:hl-page properties) "?"))]
+                       [:strong.forbid-edit (str "P" (or
+                                                      (pu/lookup properties :hl-page)
+                                                      "?"))]
                        [:label.blank " "]]
 
-                      (when (and area? (:hl-stamp properties))
+                      (when (and area?
+                                 (pu/lookup properties :hl-stamp))
                         (pdf-assets/area-display t))])]
        (remove-nils
         (concat
@@ -2277,7 +2285,9 @@
         block-ref? (:block-ref? config)
         stop-events? (:stop-events? config)
         block-ref-with-title? (and block-ref? (not (state/show-full-blocks?)) (seq title))
-        block-type (or (:ls-type properties) :default)
+        block-type (or
+                    (pu/lookup properties :ls-type)
+                    :default)
         content (if (string? content) (string/trim content) "")
         mouse-down-key (if (util/ios?)
                          :on-click
@@ -2288,8 +2298,10 @@
                 :data-type (name block-type)
                 :style {:width "100%" :pointer-events (when stop-events? "none")}}
 
-                (not (string/blank? (:hl-color properties)))
-                (assoc :data-hl-color (:hl-color properties))
+                (not (string/blank?
+                      (pu/lookup properties :hl-color)))
+                (assoc :data-hl-color
+                       (pu/lookup properties :hl-color))
 
                 (not block-ref?)
                 (assoc mouse-down-key (fn [e]
@@ -2755,7 +2767,7 @@
         {:block.temp/keys [top?]} block
         config (build-config config* block {:navigated? navigated? :navigating-block navigating-block})
         blocks-container-id (:blocks-container-id config)
-        heading? (:heading properties)
+        heading? (pu/lookup properties :heading)
         *control-show? (get state ::control-show?)
         db-collapsed? (util/collapsed? block)
         collapsed? (cond

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

@@ -16,6 +16,7 @@
             [frontend.handler.page :as page-handler]
             [frontend.handler.common.developer :as dev-common-handler]
             [frontend.handler.property :as property-handler]
+            [frontend.handler.property.util :as pu]
             [frontend.mixins :as mixins]
             [frontend.state :as state]
             [frontend.ui :as ui]
@@ -26,7 +27,8 @@
             [frontend.util.url :as url-util]
             [goog.dom :as gdom]
             [goog.object :as gobj]
-            [rum.core :as rum]))
+            [rum.core :as rum]
+            ))
 
 ;; TODO i18n support
 
@@ -178,7 +180,9 @@
   shortcut/disable-all-shortcuts
   [_target block-id]
     (when-let [block (db/entity [:block/uuid block-id])]
-      (let [heading (-> block :block/properties :heading (or false))
+      (let [properties (:block/properties block)
+            heading (or (pu/lookup properties :heading)
+                        false)
             repo (state/get-current-repo)]
         [:.menu-links-wrapper
          (ui/menu-background-color #(property-handler/set-block-property! repo block-id :background-color %)

+ 3 - 1
src/main/frontend/components/editor.cljs

@@ -15,6 +15,7 @@
             [frontend.handler.editor.lifecycle :as lifecycle]
             [frontend.handler.page :as page-handler]
             [frontend.handler.paste :as paste-handler]
+            [frontend.handler.property.util :as pu]
             [frontend.search :refer [fuzzy-search]]
             [frontend.mixins :as mixins]
             [frontend.modules.shortcut.core :as shortcut]
@@ -506,7 +507,8 @@
   "Get textarea css class according to it's content"
   [block content format]
   (let [content (if content (str content) "")
-        heading (-> block :block/properties :heading)
+        properties (:block/properties block)
+        heading (pu/lookup properties :heading)
         heading (if (true? heading)
                   (min (inc (:block/level block)) 6)
                   heading)]

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

@@ -18,6 +18,7 @@
             [frontend.components.svg :as svg]
             [frontend.modules.shortcut.core :as shortcut]
             [frontend.components.select :as select]
+            [logseq.graph-parser.property :as gp-property]
             [medley.core :as medley]
             [cljs-time.coerce :as tc]))
 
@@ -547,8 +548,12 @@
                                             (:properties (:block/schema e))))))
                               (map (fn [id]
                                      [id nil])))
+        built-in-properties (set (map name (gp-property/full-built-in-properties)))
         properties (->> (concat (seq properties) class-properties)
-                        (util/distinct-by first))]
+                        (util/distinct-by first)
+                        (remove (fn [[k _v]]
+                                  (when (uuid? k)
+                                    (contains? built-in-properties (:block/name (db/entity [:block/uuid k])))))))]
     (when-not (and (empty? properties)
                    (not new-property?)
                    (not (:page-configure? opts)))
@@ -556,9 +561,9 @@
        (when (:selected? opts)
          {:class "select-none"})
        (when (seq properties)
-         (for [[prop-uuid-or-built-in-prop v] properties]
-           (if (uuid? prop-uuid-or-built-in-prop)
-             (when-let [property (db/sub-block (:db/id (db/entity [:block/uuid prop-uuid-or-built-in-prop])))]
+         (for [[k v] properties]
+           (when (uuid? k)
+             (when-let [property (db/sub-block (:db/id (db/entity [:block/uuid k])))]
                [:div.property-pair
                 [:div.property-key.col-span-1
                  (property-key block property (select-keys opts [:class-schema?]))]
@@ -566,10 +571,5 @@
                   [:div.property-description.col-span-3.font-light
                    (get-in property [:block/schema :description])]
                   [:div.property-value.col-span-3
-                   (property-value block property v (assoc opts :parsed-value v))])])
-             ;; TODO: built in properties should have UUID and corresponding schema
-             ;; builtin
-             [:div
-              [:a.mr-2 (str prop-uuid-or-built-in-prop)]
-              [:span v]])))
+                   (property-value block property v (assoc opts :parsed-value v))])]))))
        (new-property block edit-input-id properties new-property? opts)])))

+ 4 - 1
src/main/frontend/components/query.cljs

@@ -14,6 +14,7 @@
             [frontend.extensions.sci :as sci]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.property :as property-handler]
+            [frontend.handler.property.util :as pu]
             [logseq.graph-parser.util :as gp-util]))
 
 (defn built-in-custom-query?
@@ -157,8 +158,10 @@
                        collapsed?
                        (:block/collapsed? current-block)))
         built-in-collapsed? (and collapsed? built-in?)
+        properties (:block/properties current-block)
+        query-table-property (pu/lookup properties :query-table)
         table? (or table-view?
-                   (get-in current-block [:block/properties :query-table])
+                   query-table-property
                    (and (string? query) (string/ends-with? (string/trim query) "table")))
         view-fn (if (keyword? view) (get-in (state/sub-config) [:query/views view]) view)
         view-f (and view-fn (sci/eval-string (pr-str view-fn)))

+ 12 - 5
src/main/frontend/components/query_table.cljs

@@ -16,7 +16,9 @@
             [logseq.shui.core :as shui]
             [medley.core :as medley]
             [rum.core :as rum]
-            [logseq.graph-parser.text :as text]))
+            [logseq.graph-parser.text :as text]
+            [frontend.handler.property.util :as pu]
+            [frontend.handler.property :as property-handler]))
 
 ;; Util fns
 ;; ========
@@ -65,11 +67,14 @@
   :sort-desc? and :sort-by-column. :sort-by-column is nil if no sorting is to be
   done"
   [current-block]
-  (let [p-desc? (get-in current-block [:block/properties :query-sort-desc])
+  (let [properties (:block/properties current-block)
+        p-desc? (pu/lookup properties :query-sort-desc)
         desc? (if (some? p-desc?) p-desc? true)
-        p-sort-by (keyword (get-in current-block [:block/properties :query-sort-by]))
+        properties (:block/properties current-block)
+        query-sort-by (pu/lookup properties :query-sort-by)
+        p-sort-by (keyword query-sort-by)
         ;; Starting with #6105, we started putting properties under namespaces.
-        nlp-date? (get-in current-block [:block/properties :logseq.query/nlp-date])
+        nlp-date? (pu/lookup properties :logseq.query/nlp-date)
         sort-by-column (or (some-> p-sort-by keyword)
                          (if (query-dsl/query-contains-filter? (:block/content current-block) "sort-by")
                            nil
@@ -104,7 +109,9 @@
     keys))
 
 (defn get-columns [current-block result {:keys [page?]}]
-  (let [query-properties (some-> (get-in current-block [:block/properties :query-properties] "")
+  (let [properties (:block/properties current-block)
+        query-properties (or (pu/lookup properties :query-properties) "")
+        query-properties (some-> query-properties
                                  (common-handler/safe-read-string "Parsing query properties failed"))
         query-properties (if page? (remove #{:block} query-properties) query-properties)
         columns (if (seq query-properties)

+ 11 - 5
src/main/frontend/db/model.cljs

@@ -276,6 +276,7 @@ independent of format as format specific heading characters are stripped"
            second
            string/lower-case))
 
+;; FIXME: replace :heading with id
 (defn get-block-by-page-name-and-block-route-name
   "Returns first block for given page name and block's route name. Block's route
   name must match the content of a page's block header"
@@ -1146,6 +1147,7 @@ independent of format as format specific heading characters are stripped"
   [page-name]
   (:block/journal? (db-utils/entity [:block/name page-name])))
 
+;; FIXME: replace :template with id
 (defn get-all-templates
   []
   (let [pred (fn [_db properties]
@@ -1445,6 +1447,7 @@ independent of format as format specific heading characters are stripped"
                         (remove nil?))]
     orphaned-pages))
 
+;; FIXME: replace :logseq.macro-name with id
 (defn get-macro-blocks
   [repo macro-name]
   (d/q
@@ -1485,11 +1488,14 @@ independent of format as format specific heading characters are stripped"
 
 (defn get-whiteboard-id-nonces
   [repo page-name]
-  (->> (get-page-blocks-no-cache repo page-name {:keys [:block/uuid :block/properties]})
-       (filter #(:logseq.tldraw.shape (:block/properties %)))
-       (map (fn [{:block/keys [uuid properties]}]
-              {:id (str uuid)
-               :nonce (get-in properties [:logseq.tldraw.shape :nonce])}))))
+  (let [key (if (react/db-graph?)
+              (:block/uuid (db-utils/entity [:block/name "logseq.tldraw.shape"]))
+              :logseq.tldraw.shape)]
+    (->> (get-page-blocks-no-cache repo page-name {:keys [:block/uuid :block/properties]})
+         (keep (fn [{:block/keys [uuid properties]}]
+                 (when-let [shape (get properties key)]
+                   {:id (str uuid)
+                    :nonce (:nonce shape)}))))))
 
 (defn get-all-classes
   [repo]

+ 9 - 3
src/main/frontend/handler/block.cljs

@@ -16,7 +16,8 @@
    [frontend.config :as config]
    [frontend.db.listener :as db-listener]
    [frontend.util.drawer :as drawer]
-   [frontend.handler.file-based.property.util :as property-util]))
+   [frontend.handler.file-based.property.util :as property-util]
+   [frontend.handler.property.util :as pu]))
 
 ;;  Fns
 
@@ -268,7 +269,10 @@
 
 (defn get-idx-of-order-list-block
   [block order-list-type]
-  (let [order-block-fn? #(some-> % :block/properties :logseq.order-list-type (= order-list-type))
+  (let [order-block-fn? (fn [block]
+                          (let [properties (:block/properties block)
+                                type (pu/lookup properties :logseq.order-list-type)]
+                            (= type order-list-type)))
         prev-block-fn   #(some->> (:db/id %) (db-model/get-prev-sibling (state/get-current-repo)))
         prev-block      (prev-block-fn block)]
     (letfn [(page-fn? [b] (some-> b :block/name some?))
@@ -295,7 +299,9 @@
 
 (defn attach-order-list-state
   [config block]
-  (let [own-order-list-type  (some-> block :block/properties :logseq.order-list-type str string/lower-case)
+  (let [properties (:block/properties block)
+        type (pu/lookup properties :logseq.order-list-type)
+        own-order-list-type  (some-> type str string/lower-case)
         own-order-list-index (some->> own-order-list-type (get-idx-of-order-list-block block))]
     (assoc config :own-order-list-type own-order-list-type
                   :own-order-list-index own-order-list-index

+ 28 - 27
src/main/frontend/handler/db_based/property.cljs

@@ -112,11 +112,11 @@
   [repo property k-name property-uuid property-type]
   (let [k-name (name k-name)]
     (when (and property (nil? (:block/type property)))
-     (db/transact! repo [(outliner-core/block-with-updated-at
-                          {:block/schema {:type property-type}
-                           :block/uuid property-uuid
-                           :block/type "property"})]
-       {:outliner-op :update-property}))
+      (db/transact! repo [(outliner-core/block-with-updated-at
+                           {:block/schema {:type property-type}
+                            :block/uuid property-uuid
+                            :block/type "property"})]
+        {:outliner-op :update-property}))
     (when (nil? property) ;if property not exists yet
       (db/transact! repo [(outliner-core/block-with-timestamps
                            {:block/schema {:type property-type}
@@ -158,9 +158,9 @@
                                 (if (coll? v*)
                                   (vec (distinct (concat value v*)))
                                   (let [v (mapv (fn [x] (if (= x old-value) v* x)) value)]
-                                   (if (contains? (set v) v*)
-                                     v
-                                     (conj v v*))))
+                                    (if (contains? (set v) v*)
+                                      v
+                                      (conj v v*))))
 
                                 multiple-values?
                                 (let [f (if (coll? v*) concat conj)]
@@ -295,24 +295,25 @@
       (db/transact! repo txs {:outliner-op :batch-add-property}))))
 
 (defn batch-remove-property!
-  [repo block-ids property-uuid]
-  {:pre (string? property-uuid)}
-  (let [txs (mapcat
-             (fn [id]
-               (when-let [block (db/entity [:block/uuid id])]
-                 (let [origin-properties (:block/properties block)]
-                   (when (contains? (set (keys origin-properties)) property-uuid)
-                     (let [properties' (dissoc origin-properties property-uuid)
-                           refs (outliner-core/rebuild-block-refs block properties')]
-                       [[:db/retract (:db/id block) :block/refs]
-                        {:block/uuid (:block/uuid block)
-                         :block/properties properties'
-                         :block/refs refs}])))))
-             block-ids)]
-    (when (seq txs)
-      (db/transact! repo txs {:outliner-op :remove-property}))))
+  [repo block-ids key]
+  (when-let [property-uuid (if (uuid? key)
+                             uuid
+                             (:block/uuid (db/entity [:block/name (util/page-name-sanity-lc (name key))])))]
+    (let [txs (mapcat
+               (fn [id]
+                 (when-let [block (db/entity [:block/uuid id])]
+                   (let [origin-properties (:block/properties block)]
+                     (when (contains? (set (keys origin-properties)) property-uuid)
+                       (let [properties' (dissoc origin-properties property-uuid)
+                             refs (outliner-core/rebuild-block-refs block properties')]
+                         [[:db/retract (:db/id block) :block/refs]
+                          {:block/uuid (:block/uuid block)
+                           :block/properties properties'
+                           :block/refs refs}])))))
+               block-ids)]
+      (when (seq txs)
+        (db/transact! repo txs {:outliner-op :remove-property})))))
 
 (defn remove-block-property!
-  [repo block-id property-uuid]
-  {:pre (string? property-uuid)}
-  (batch-remove-property! repo [block-id] property-uuid))
+  [repo block-id key]
+  (batch-remove-property! repo [block-id] key))

+ 15 - 10
src/main/frontend/handler/editor.cljs

@@ -20,6 +20,7 @@
             [frontend.handler.block :as block-handler]
             [frontend.handler.common :as common-handler]
             [frontend.handler.property :as property-handler]
+            [frontend.handler.property.util :as pu]
             [frontend.handler.export.html :as export-html]
             [frontend.handler.export.text :as export-text]
             [frontend.handler.notification :as notification]
@@ -70,7 +71,8 @@
 
 (defn get-block-own-order-list-type
   [block]
-  (some-> block :block/properties :logseq.order-list-type))
+  (let [properties (:block/properties block)]
+    (pu/lookup properties :logseq.order-list-type)))
 
 (defn set-block-own-order-list-type!
   [block type]
@@ -797,7 +799,9 @@
 (defn set-block-query-properties!
   [block-id all-properties key add?]
   (when-let [block (db/entity [:block/uuid block-id])]
-    (let [query-properties (-> (get-in block [:block/properties :query-properties] "")
+    (let [properties (:block/properties block)
+          query-properties (or (pu/lookup properties :query-properties) "")
+          query-properties (-> query-properties
                                (common-handler/safe-read-string "Failed to parse query properties"))
           query-properties (if (seq query-properties)
                              query-properties
@@ -3249,14 +3253,15 @@
   [block]
   (->> (:block/macros (db/entity (:db/id block)))
        (some (fn [macro]
-               (when-let [query-body (and
-                                      (= "query" (get-in macro [:block/properties :logseq.macro-name]))
-                                      (first (:logseq.macro-arguments (:block/properties macro))))]
-                 (seq (:query
-                       (try
-                         (query-dsl/parse-query query-body)
-                         (catch :default _e
-                           nil)))))))))
+               (let [properties (:block/properties macro)
+                     macro-name (pu/lookup properties :logseq.macro-name)
+                     macro-arguments (pu/lookup properties :logseq.macro-arguments)]
+                 (when-let [query-body (and (= "query" macro-name) (first macro-arguments))]
+                  (seq (:query
+                        (try
+                          (query-dsl/parse-query query-body)
+                          (catch :default _e
+                            nil))))))))))
 
 (defn- valid-custom-query-block?
   "Whether block has a valid customl query."

+ 4 - 1
src/main/frontend/handler/events.cljs

@@ -53,6 +53,7 @@
             [frontend.handler.shell :as shell-handler]
             [frontend.handler.ui :as ui-handler]
             [frontend.handler.user :as user-handler]
+            [frontend.handler.property.util :as pu]
             [frontend.handler.whiteboard :as whiteboard-handler]
             [frontend.handler.web.nfs :as nfs-handler]
             [frontend.mobile.core :as mobile]
@@ -325,7 +326,9 @@
     (query-properties-settings-inner block shown-properties all-properties close-fn)))
 
 (defmethod handle :modal/set-query-properties [[_ block all-properties]]
-  (let [block-properties (some-> (get-in block [:block/properties :query-properties])
+  (let [properties (:block/properties block)
+        query-properties (pu/lookup properties :query-properties)
+        block-properties (some-> query-properties
                                  (common-handler/safe-read-string "Parsing query properties failed"))
         shown-properties (if (seq block-properties)
                            (set block-properties)

+ 10 - 7
src/main/frontend/handler/property.cljs

@@ -3,22 +3,25 @@
   (:require [frontend.handler.db-based.property :as db-property]
             [frontend.handler.file-based.property :as file-property]
             [frontend.config :as config]
-            [frontend.state :as state]))
+            [frontend.state :as state]
+            [logseq.graph-parser.util :as gp-util]))
 
 (def builtin-schema-types db-property/builtin-schema-types)
 
-(defn set-block-property!
-  [repo block-id key v & opts]
-  (if (config/db-based-graph? repo)
-    (db-property/set-block-property! repo block-id key v opts)
-    (file-property/set-block-property! block-id key v)))
-
 (defn remove-block-property!
   [repo block-id key]
   (if (config/db-based-graph? repo)
     (db-property/remove-block-property! repo block-id key)
     (file-property/remove-block-property! block-id key)))
 
+(defn set-block-property!
+  [repo block-id key v & opts]
+  (if (config/db-based-graph? repo)
+    (if (nil? v)
+      (db-property/remove-block-property! repo block-id key)
+      (db-property/set-block-property! repo block-id key v opts))
+    (file-property/set-block-property! block-id key v)))
+
 (defn update-property!
   [repo property-uuid opts]
   {:pre [(uuid? property-uuid)]}

+ 24 - 0
src/main/frontend/handler/property/util.cljs

@@ -0,0 +1,24 @@
+(ns frontend.handler.property.util
+  (:require [frontend.config :as config]
+            [frontend.state :as state]
+            [frontend.config :as config]
+            [logseq.graph-parser.property :as gp-property]
+            [logseq.graph-parser.util :as gp-util]
+            [frontend.db :as db]))
+
+(defn lookup
+  "Get the value of coll's (a map) `key`"
+  [coll key]
+  (let [repo (state/get-current-repo)]
+    (if (and (config/db-based-graph? repo)
+             (keyword? key)
+             (contains? (gp-property/full-built-in-properties) key))
+      (when-let [property (db/entity repo [:block/name (gp-util/page-name-sanity-lc (name key))])]
+        (get coll (:block/uuid property)))
+      (get coll key))))
+
+(defn get-property
+  "Get the value of block's property `key`"
+  [block key]
+  (when-let [properties (:block/properties block)]
+    (lookup properties key)))

+ 4 - 2
src/main/frontend/handler/route.cljs

@@ -8,6 +8,7 @@
             [frontend.handler.recent :as recent-handler]
             [frontend.handler.search :as search-handler]
             [frontend.handler.ui :as ui-handler]
+            [frontend.handler.property.util :as pu]
             [frontend.state :as state]
             [frontend.util :as util]
             [frontend.extensions.pdf.utils :as pdf-utils]
@@ -52,8 +53,9 @@
   (defn- default-page-route [page-name-or-block-uuid]
     ;; Only query if in a block context
     (let [block (when (uuid? page-name-or-block-uuid)
-                  (model/get-block-by-uuid page-name-or-block-uuid))]
-      (if (get-in block [:block/properties :heading])
+                  (model/get-block-by-uuid page-name-or-block-uuid))
+          properties (:block/properties block)]
+      (if (pu/lookup properties :heading)
         {:to :page-block
          :path-params {:name (get-in block [:block/page :block/name])
                        :block-route-name (model/heading-content->route-name (:block/content block))}}

+ 11 - 7
src/main/frontend/handler/whiteboard.cljs

@@ -7,6 +7,7 @@
             [frontend.db.utils :as db-utils]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.route :as route-handler]
+            [frontend.handler.property.util :as pu]
             [frontend.modules.editor.undo-redo :as history]
             [frontend.modules.outliner.core :as outliner]
             [frontend.modules.outliner.file :as outliner-file]
@@ -44,7 +45,8 @@
 
 (defn- build-shapes
   [page-block blocks]
-  (let [shapes-index (get-in page-block [:block/properties :logseq.tldraw.page :shapes-index])
+  (let [page-metadata (pu/get-property page-block :logseq.tldraw.page)
+        shapes-index (:shapes-index page-metadata)
         shape-id->index (zipmap shapes-index (range 0 (count shapes-index)))]
     (->> blocks
          (map (fn [block]
@@ -107,8 +109,7 @@
         repo (state/get-current-repo)
         deleted-shapes (when (seq deleted-ids)
                          (->> (db/pull-many repo '[*] (mapv (fn [id] [:block/uuid (uuid id)]) deleted-ids))
-                              (map (fn [b]
-                                     (get-in b [:block/properties :logseq.tldraw.shape])))))
+                              (map (fn [b] (pu/get-property b :logseq.tldraw.shape)))))
         deleted-shapes-tx (mapv (fn [id] [:db/retractEntity [:block/uuid (uuid id)]]) deleted-ids)
         with-timestamps (fn [block]
                           (if (contains? created-ids (str (:block/uuid block)))
@@ -136,7 +137,8 @@
   (let [tl-page ^js (second (first (.-pages app)))
         shapes (.-shapes ^js tl-page)
         page-block (model/get-page page-name)
-        prev-shapes-index (get-in page-block [:block/properties :logseq.tldraw.page :shapes-index])
+        prev-page-metadata (pu/get-property page-block :logseq.tldraw.page)
+        prev-shapes-index (:shapes-index prev-page-metadata)
         shape-id->prev-index (zipmap prev-shapes-index (range (count prev-shapes-index)))
         new-id-nonces (set (map-indexed (fn [idx shape]
                                   (let [id (.-id shape)]
@@ -370,14 +372,16 @@
 (defn update-bindings!
   [^js tl-page page-name]
   (when-let [page (db/entity [:block/name page-name])]
-    (let [bindings (get-in page [:block/properties :logseq.tldraw.page :bindings])]
+    (let [page-metadata (pu/get-property page :logseq.tldraw.page)
+          bindings (:bindings page-metadata)]
       (when (seq bindings)
         (.updateBindings tl-page (bean/->js bindings))))))
 
 (defn update-shapes-index!
   [^js tl-page page-name]
   (when-let [page (db/entity [:block/name page-name])]
-    (let [shapes-index (get-in page [:block/properties :logseq.tldraw.page :shapes-index])]
+    (let [page-metadata (pu/get-property page :logseq.tldraw.page)
+          shapes-index (:shapes-index page-metadata)]
       (when (seq shapes-index)
         (.updateShapesIndex tl-page (bean/->js shapes-index))))))
 
@@ -408,7 +412,7 @@
               (when (seq new-shapes)
                 (delete-shapes! api new-shapes))
               (when (seq changed-shapes)
-                (let [prev-shapes (map (fn [b] (get-in b [:block/properties :logseq.tldraw.shape]))
+                (let [prev-shapes (map (fn [b] (pu/get-property b :logseq.tldraw.shape))
                                        prev-changed-blocks)]
                   (update-shapes! api prev-shapes))))))))
     (catch :default e

+ 8 - 4
src/main/frontend/modules/outliner/core.cljs

@@ -16,7 +16,8 @@
             [logseq.graph-parser.util :as gp-util]
             [cljs.spec.alpha :as s]
             [frontend.format.block :as block]
-            [frontend.handler.file-based.property.util :as property-util]))
+            [frontend.handler.file-based.property.util :as property-util]
+            [frontend.handler.property.util :as pu]))
 
 (s/def ::block-map (s/keys :opt [:db/id :block/uuid :block/page :block/left :block/parent]))
 
@@ -508,17 +509,20 @@
            last
            rest))))
 
-(defn blocks-with-ordered-list-props
+(defn- blocks-with-ordered-list-props
   [blocks target-block sibling?]
   (let [target-block (if sibling? target-block (some-> target-block :db/id db/pull block tree/-get-down :data))]
-    (letfn [(list-type-fn [b] (some-> b :block/properties :logseq.order-list-type))]
+    (let [list-type-fn (fn [block] (pu/get-property block :logseq.order-list-type))
+          k (if (config/db-based-graph? (state/get-current-repo))
+              (:block/uuid (db/entity [:block/name "logseq.order-list-type"]))
+              :logseq.order-list-type)]
       (if-let [list-type (and target-block (list-type-fn target-block))]
         (mapv
           (fn [{:block/keys [content format] :as block}]
             (cond-> block
               (and (some? (:block/uuid block))
                    (nil? (list-type-fn block)))
-              (update :block/properties #(assoc % :logseq.order-list-type list-type))
+              (update :block/properties assoc k list-type)
 
               (not (config/db-based-graph? (state/get-current-repo)))
               (assoc :block/content (property-util/insert-property format content :logseq.order-list-type list-type))))