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

enhance: frontend consistently uses :db/ident

for fetching built-in properties instead of :block/name
Gabriel Horner 1 год назад
Родитель
Сommit
9c5309da47
29 измененных файлов с 101 добавлено и 96 удалено
  1. 16 28
      deps/db/src/logseq/db/frontend/property.cljs
  2. 1 1
      deps/outliner/src/logseq/outliner/core.cljs
  3. 15 15
      src/main/frontend/components/block.cljs
  4. 1 1
      src/main/frontend/components/block/macros.cljs
  5. 1 1
      src/main/frontend/components/content.cljs
  6. 2 2
      src/main/frontend/components/db_based/page.cljs
  7. 1 1
      src/main/frontend/components/editor.cljs
  8. 1 1
      src/main/frontend/components/icon.cljs
  9. 2 2
      src/main/frontend/components/page.cljs
  10. 1 1
      src/main/frontend/components/page_menu.cljs
  11. 2 2
      src/main/frontend/components/property.cljs
  12. 2 2
      src/main/frontend/components/property/closed_value.cljs
  13. 2 2
      src/main/frontend/components/property/value.cljs
  14. 1 1
      src/main/frontend/components/query.cljs
  15. 4 4
      src/main/frontend/components/query_table.cljs
  16. 1 1
      src/main/frontend/extensions/pdf/assets.cljs
  17. 1 1
      src/main/frontend/extensions/pdf/utils.cljs
  18. 2 2
      src/main/frontend/handler/block.cljs
  19. 1 1
      src/main/frontend/handler/db_based/editor.cljs
  20. 4 4
      src/main/frontend/handler/editor.cljs
  21. 1 1
      src/main/frontend/handler/events.cljs
  22. 1 1
      src/main/frontend/handler/graph.cljs
  23. 1 1
      src/main/frontend/handler/page.cljs
  24. 24 7
      src/main/frontend/handler/property/util.cljs
  25. 1 1
      src/main/frontend/handler/route.cljs
  26. 6 6
      src/main/frontend/handler/whiteboard.cljs
  27. 3 2
      src/main/frontend/shui.cljs
  28. 1 1
      src/main/logseq/api.cljs
  29. 2 3
      src/test/frontend/handler/db_based/property_test.cljs

+ 16 - 28
deps/db/src/logseq/db/frontend/property.cljs

@@ -176,42 +176,30 @@
   ;; Disallow tags or page refs as they would create unreferenceable page names
   (not (re-find #"^(#|\[\[)" s)))
 
-(defn lookup
-  "Get the value of coll's (a map) `key`. For file and db graphs"
-  [repo db coll key]
-  (when db
-    (let [property-name (if (keyword? key)
-                          (name key)
-                          key)]
-      (if (sqlite-util/db-based-graph? repo)
-        (when-let [property (d/entity db [:block/name (common-util/page-name-sanity-lc property-name)])]
-          (get coll (:block/uuid property)))
-        (get coll key)))))
-
-(defn get-block-property-value
-  "Get the value of block's property `key`"
-  [repo db block key]
-  (when db
-    (let [block (or (d/entity db (:db/id block)) block)]
-      (when-let [properties (:block/properties block)]
-        (lookup repo db properties key)))))
-
 (defn get-pid
-  "Get a built-in property's id (name or uuid) given its db-ident. Use when it can be a file or db graph.
-   Use db-pu/get-built-in-property-uuid if just a db graph"
+  "Get a built-in property's id (keyword name for file graph and uuid for db graph)
+  given its db-ident. Use this fn on a file or db graph. Use
+  db-pu/get-built-in-property-uuid if only in a db graph context"
   [repo db db-ident]
   (if (sqlite-util/db-based-graph? repo)
     (:block/uuid (d/entity db db-ident))
     (get-in built-in-properties [db-ident :name])))
 
-(defn get-property
-  "Get a property given its unsanitized name"
-  [db property-name]
-  (d/entity db [:block/name (common-util/page-name-sanity-lc (name property-name))]))
+(defn lookup
+  "Get the value of coll by db-ident. For file and db graphs"
+  [repo db coll db-ident]
+  (get coll (get-pid repo db db-ident)))
+
+(defn get-block-property-value
+  "Get the value of built-in block's property by its db-ident"
+  [repo db block db-ident]
+  (when db
+    (let [block' (or (d/entity db (:db/id block)) block)]
+      (get (:block/properties block') (get-pid repo db db-ident)))))
 
 (defn shape-block?
   [repo db block]
-  (= :whiteboard-shape (get-block-property-value repo db block :ls-type)))
+  (= :whiteboard-shape (get-block-property-value repo db block :logseq.property/ls-type)))
 
 (defn get-built-in
   "Gets a built-in page/class/property/X by its :db/ident"
@@ -219,7 +207,7 @@
   (d/entity db db-ident))
 
 (defn get-by-ident-or-name
-  "Gets a property by ident or name"
+  "Gets a property by db-ident or name if it's a user property"
   [db ident-or-name]
   (if (and (keyword? ident-or-name) (namespace ident-or-name))
     (get-built-in db ident-or-name)

+ 1 - 1
deps/outliner/src/logseq/outliner/core.cljs

@@ -638,7 +638,7 @@
   (let [db @conn
         tb (when target-block (block db target-block))
         target-block (if sibling? target-block (when tb (:block (otree/-get-down tb conn))))
-        list-type-fn (fn [block] (db-property/get-block-property-value repo db block :logseq.order-list-type))
+        list-type-fn (fn [block] (db-property/get-block-property-value repo db block :logseq.property/order-list-type))
         k (db-property/get-pid repo db :logseq.property/order-list-type)]
     (if-let [list-type (and target-block (list-type-fn target-block))]
       (mapv

+ 15 - 15
src/main/frontend/components/block.cljs

@@ -591,7 +591,7 @@
       :on-key-up (fn [e] (when (and e (= (.-key e) "Enter"))
                            (open-page-ref e config page-name page-name-in-block contents-page? whiteboard-page?)))}
      (when-not hide-icon?
-       (when-let [icon (pu/get-block-property-value page-entity :icon)]
+       (when-let [icon (pu/get-block-property-value page-entity :logseq.property/icon)]
          [:span.mr-1.inline-flex.items-center (icon/icon icon)]))
      [:span
       (if (and (coll? children) (seq children))
@@ -911,8 +911,8 @@
             db-id (:db/id block)
             block (when db-id (db/sub-block db-id))
             properties (:block/properties block)
-            block-type (keyword (pu/lookup properties :ls-type))
-            hl-type (pu/lookup properties :hl-type)
+            block-type (keyword (pu/lookup properties :logseq.property/ls-type))
+            hl-type (pu/lookup properties :logseq.property/hl-type)
             repo (state/get-current-repo)
             stop-inner-events? (= block-type :whiteboard-shape)]
         (if (and block (:block/content block))
@@ -1429,7 +1429,7 @@
                          (:db/id)
                          (db/entity)
                          :block/properties)
-          macros (pu/lookup properties :macros)
+          macros (pu/lookup-by-name properties :macros)
           macro-content (or
                          (get macros name)
                          (get (state/get-macros) name)
@@ -1969,7 +1969,7 @@
         slide? (boolean (:slide? config))
         block-ref? (:block-ref? config)
         block-type (or (keyword
-                        (pu/lookup properties :ls-type))
+                        (pu/lookup properties :logseq.property/ls-type))
                        :default)
         html-export? (:html-export? config)
         checkbox (when (and (not pre-block?)
@@ -1980,14 +1980,14 @@
                         (marker-switch t))
         marker-cp (marker-cp t)
         priority (priority-cp t)
-        bg-color (pu/lookup properties :background-color)
+        bg-color (pu/lookup properties :logseq.property/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)
-                 (pu/lookup properties :heading))
+                 (pu/lookup properties :logseq.property/heading))
         heading (if (true? heading) (min (inc level) 6) heading)
         elem (if heading
                (keyword (str "h" heading
@@ -1996,7 +1996,7 @@
     (->elem
      elem
      (merge
-      {:data-hl-type (pu/lookup properties :hl-type)}
+      {:data-hl-type (pu/lookup properties :logseq.property/hl-type)}
       (when (and marker
                  (not (string/blank? marker))
                  (not= "nil" marker))
@@ -2010,7 +2010,7 @@
            :class "px-1 with-bg-color"})))
 
      ;; children
-     (let [area?  (= :area (keyword (pu/lookup properties :hl-type)))
+     (let [area?  (= :area (keyword (pu/lookup properties :logseq.property/hl-type)))
            hl-ref #(when (and (or config/publishing? (util/electron?))
                               (not (#{:default :whiteboard-shape} block-type)))
                      [:div.prefix-link
@@ -2030,12 +2030,12 @@
 
                       [:span.hl-page
                        [:strong.forbid-edit (str "P" (or
-                                                      (pu/lookup properties :hl-page)
+                                                      (pu/lookup properties :logseq.property/hl-page)
                                                       "?"))]
                        [:label.blank " "]]
 
                       (when (and area?
-                                 (pu/lookup properties :hl-stamp))
+                                 (pu/lookup properties :logseq.property/hl-stamp))
                         (pdf-assets/area-display t))])]
        (remove-nils
         (concat
@@ -2374,7 +2374,7 @@
         stop-events? (:stop-events? config)
         block-ref-with-title? (and block-ref? (not (state/show-full-blocks?)) (seq title))
         block-type (or
-                    (pu/lookup properties :ls-type)
+                    (pu/lookup properties :logseq.property/ls-type)
                     :default)
         content (if (string? content) (string/trim content) "")
         mouse-down-key (if (util/ios?)
@@ -2387,9 +2387,9 @@
                 :style {:width "100%" :pointer-events (when stop-events? "none")}}
 
                 (not (string/blank?
-                      (pu/lookup properties :hl-color)))
+                      (pu/lookup properties :logseq.property/hl-color)))
                 (assoc :data-hl-color
-                       (pu/lookup properties :hl-color))
+                       (pu/lookup properties :logseq.property/hl-color))
 
                 (not block-ref?)
                 (assoc mouse-down-key (fn [e]
@@ -3014,7 +3014,7 @@
         {:block/keys [uuid pre-block? content properties]} block
         config (build-config config* block {:navigated? navigated? :navigating-block navigating-block})
         level (:level config)
-        heading? (pu/lookup properties :heading)
+        heading? (pu/lookup properties :logseq.property/heading)
         *control-show? (get container-state ::control-show?)
         db-collapsed? (util/collapsed? block)
         collapsed? (cond

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

@@ -45,7 +45,7 @@
            :updated-at
            :block/updated-at
 
-           (let [vals (map #(pu/lookup (:block/properties %) f) result)
+           (let [vals (map #(pu/lookup-by-name (:block/properties %) f) result)
                  int? (some integer? vals)
                  repo (state/get-current-repo)
                  prop-key (if (config/db-based-graph? repo)

+ 1 - 1
src/main/frontend/components/content.cljs

@@ -182,7 +182,7 @@
         db? (config/db-based-graph? repo)]
     (when-let [block (db/entity [:block/uuid block-id])]
       (let [properties (:block/properties block)
-            heading (or (pu/lookup properties :heading)
+            heading (or (pu/lookup properties :logseq.property/heading)
                         false)]
         [:.menu-links-wrapper
          (ui/menu-background-color #(property-handler/set-block-property! repo block-id :background-color %)

+ 2 - 2
src/main/frontend/components/db_based/page.cljs

@@ -65,7 +65,7 @@
   [page]
   [:div.grid.grid-cols-5.gap-1.items-center
    [:label.col-span-2 "Icon:"]
-   (let [icon-value (pu/get-block-property-value page :icon)]
+   (let [icon-value (pu/get-block-property-value page :logseq.property/icon)]
      [:div.col-span-3.flex.flex-row.items-center.gap-2
       (icon-component/icon-picker icon-value
                                   {:disabled? config/publishing?
@@ -82,7 +82,7 @@
                                          (:block/uuid page)
                                          (db-pu/get-built-in-property-uuid :logseq.property/icon)))
                             :title "Delete this icon"}
-        (ui/icon "X")])])])
+         (ui/icon "X")])])])
 
 (rum/defc tags
   [page]

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

@@ -584,7 +584,7 @@
   [block content format]
   (let [content (if content (str content) "")
         properties (:block/properties block)
-        heading (pu/lookup properties :heading)
+        heading (pu/lookup properties :logseq.property/heading)
         heading (if (true? heading)
                   (min (inc (:block/level block)) 6)
                   heading)]

+ 1 - 1
src/main/frontend/components/icon.cljs

@@ -29,7 +29,7 @@
 (defn get-page-icon
   [page-entity opts]
   (let [default-icon (ui/icon "page" (merge opts {:extension? true}))
-        page-icon (pu/get-block-property-value page-entity :icon)]
+        page-icon (pu/get-block-property-value page-entity :logseq.property/icon)]
     (or
      (when-not (string/blank? page-icon)
        (icon page-icon opts))

+ 2 - 2
src/main/frontend/components/page.cljs

@@ -314,7 +314,7 @@
           page (db/sub-block (:db/id page))
           title (:block/original-name page)]
       (when title
-        (let [icon (pu/lookup (:block/properties page) :icon)
+        (let [icon (pu/lookup (:block/properties page) :logseq.property/icon)
               *title-value (get state ::title-value)
               *edit? (get state ::edit?)
               *input-value (get state ::input-value)
@@ -1322,7 +1322,7 @@
                   {:on-change (fn []
                                 (swap! *checks update idx not))})]
                [:td.icon.w-4.p-0.overflow-hidden
-                (when-let [icon (pu/get-block-property-value page :icon)]
+                (when-let [icon (pu/get-block-property-value page :logseq.property/icon)]
                   icon)]
                [:td.name [:a {:on-click (fn [e]
                                           (.preventDefault e)

+ 1 - 1
src/main/frontend/components/page_menu.cljs

@@ -59,7 +59,7 @@
           block? (and page (util/uuid-string? page-name) (not whiteboard?))
           contents? (= page-name "contents")
           properties (:block/properties page)
-          public? (true? (pu/lookup properties :public))
+          public? (true? (pu/lookup properties :logseq.property/public))
           _favorites-updated? (state/sub :favorites/updated?)
           favorited? (page-handler/favorited? page-name)
           developer-mode? (state/sub [:ui/developer-mode?])

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

@@ -246,7 +246,7 @@
 
           [:div.grid.grid-cols-4.gap-1.items-center.leading-8
            [:label.col-span-1 "Icon:"]
-           (let [icon-value (pu/get-block-property-value property :icon)]
+           (let [icon-value (pu/get-block-property-value property :logseq.property/icon)]
              [:div.col-span-3.flex.flex-row.items-center.gap-2
               (icon-component/icon-picker icon-value
                                           {:on-chosen (fn [_e icon]
@@ -538,7 +538,7 @@
   [state block property {:keys [class-schema? block? collapsed? page-cp inline-text]}]
   (let [*hover? (::hover? state)
         repo (state/get-current-repo)
-        icon (pu/get-block-property-value property :icon)
+        icon (pu/get-block-property-value property :logseq.property/icon)
         property-name (:block/original-name property)]
     [:div.flex.flex-row.items-center
      {:on-mouse-over   #(reset! *hover? true)

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

@@ -57,7 +57,7 @@
   {:init (fn [state]
            (let [block (second (:rum/args state))
                  value (or (str (get-in block [:block/schema :value])) "")
-                 icon (when block (pu/get-block-property-value block :icon))
+                 icon (when block (pu/get-block-property-value block :logseq.property/icon))
                  description (or (get-in block [:block/schema :description]) "")]
              (assoc state
                     ::value (atom value)
@@ -118,7 +118,7 @@
      {:on-mouse-over #(reset! *hover? true)
       :on-mouse-out #(reset! *hover? false)}
      [:div.flex.flex-row.items-center.gap-2
-      (icon-component/icon-picker (pu/get-block-property-value item :icon)
+      (icon-component/icon-picker (pu/get-block-property-value item :logseq.property/icon)
                                   {:on-chosen (fn [_e icon]
                                                 (update-icon icon))})
       (cond

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

@@ -415,7 +415,7 @@
             items (if closed-values?
                     (keep (fn [id]
                             (when-let [block (when id (db/entity [:block/uuid id]))]
-                              (let [icon (pu/get-block-property-value block :icon)
+                              (let [icon (pu/get-block-property-value block :logseq.property/icon)
                                     value (db-property/closed-value-name block)]
                                 {:label (if icon
                                           [:div.flex.flex-row.gap-2
@@ -553,7 +553,7 @@
       [:div.text-sm.opacity-70 "loading"]
       (when-let [block (db/sub-block (:db/id (db/entity [:block/uuid value])))]
         (let [value' (get-in block [:block/schema :value])
-              icon (pu/get-block-property-value block :icon)]
+              icon (pu/get-block-property-value block :logseq.property/icon)]
           (cond
             (:block/name block)
             (page-cp {:disable-preview? true

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

@@ -158,7 +158,7 @@
                        (:block/collapsed? current-block)))
         built-in-collapsed? (and collapsed? built-in?)
         properties (:block/properties current-block)
-        query-table-property (pu/lookup properties :query-table)
+        query-table-property (pu/lookup properties :logseq.property/query-table)
         table? (or table-view?
                    query-table-property
                    (and (string? query) (string/ends-with? (string/trim query) "table")))

+ 4 - 4
src/main/frontend/components/query_table.cljs

@@ -72,12 +72,12 @@
   done"
   [current-block {:keys [db-graph?]}]
   (let [properties (:block/properties current-block)
-        p-desc? (pu/lookup properties :query-sort-desc)
+        p-desc? (pu/lookup properties :logseq.property/query-sort-desc)
         desc? (if (some? p-desc?) p-desc? true)
         properties (:block/properties current-block)
-        query-sort-by (pu/lookup properties :query-sort-by)
+        query-sort-by (pu/lookup properties :logseq.property/query-sort-by)
         ;; Starting with #6105, we started putting properties under namespaces.
-        nlp-date? (and (not db-graph?) (pu/lookup properties :logseq.query/nlp-date))
+        nlp-date? (and (not db-graph?) (pu/lookup-by-name properties :logseq.query/nlp-date))
         sort-by-column (or (if (uuid? query-sort-by) query-sort-by (keyword query-sort-by))
                            (if (query-dsl/query-contains-filter? (:block/content current-block) "sort-by")
                              nil
@@ -124,7 +124,7 @@
 
 (defn get-columns [current-block result {:keys [page?]}]
   (let [properties (:block/properties current-block)
-        query-properties (pu/lookup properties :query-properties)
+        query-properties (pu/lookup properties :logseq.property/query-properties)
         query-properties (if (config/db-based-graph? (state/get-current-repo))
                            query-properties
                            (some-> query-properties

+ 1 - 1
src/main/frontend/extensions/pdf/assets.cljs

@@ -237,7 +237,7 @@
         page-name (:block/original-name page)
         ;; FIXME: file-path property for db version
         file-path (:file-path (:block/properties page))
-        hl-page   (pu/get-block-property-value block :hl-page)]
+        hl-page   (pu/get-block-property-value block :logseq.property/hl-page)]
     (when-let [target-key (and page-name (subs page-name 5))]
       (p/let [hls (resolve-hls-data-by-key$ target-key)
               hls (and hls (:highlights hls))]

+ 1 - 1
src/main/frontend/extensions/pdf/utils.cljs

@@ -17,7 +17,7 @@
   (and filename (string? filename) (string/starts-with? filename "hls__")))
 
 (def get-area-block-asset-url
-  #(publish-db/get-area-block-asset-url %1 %2 {:prop-lookup-fn pu/lookup}))
+  #(publish-db/get-area-block-asset-url %1 %2 {:prop-lookup-fn pu/lookup-by-name}))
 
 (defn get-bounding-rect
   [rects]

+ 2 - 2
src/main/frontend/handler/block.cljs

@@ -116,7 +116,7 @@
   [block order-list-type]
   (let [order-block-fn? (fn [block]
                           (let [properties (:block/properties block)
-                                type (pu/lookup properties :logseq.order-list-type)]
+                                type (pu/lookup properties :logseq.property/order-list-type)]
                             (= type order-list-type)))
         prev-block-fn   #(some->> (:db/id %) (db-model/get-prev-sibling (db/get-db)))
         prev-block      (prev-block-fn block)]
@@ -145,7 +145,7 @@
 (defn attach-order-list-state
   [config block]
   (let [properties (:block/properties block)
-        type (pu/lookup properties :logseq.order-list-type)
+        type (pu/lookup properties :logseq.property/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

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

@@ -124,7 +124,7 @@
 (defn- set-heading-aux!
   [block-id heading]
   (let [block (db/pull [:block/uuid block-id])
-        old-heading (pu/lookup (:block/properties block) :heading)]
+        old-heading (pu/lookup (:block/properties block) :logseq.property/heading)]
     (cond
       ;; nothing changed for first two cases
       (or (and (nil? old-heading) (nil? heading))

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

@@ -85,7 +85,7 @@
 (defn get-block-own-order-list-type
   [block]
   (let [properties (:block/properties block)]
-    (pu/lookup properties :logseq.order-list-type)))
+    (pu/lookup properties :logseq.property/order-list-type)))
 
 (defn set-block-own-order-list-type!
   [block type]
@@ -894,7 +894,7 @@
   [block-id all-properties key add?]
   (when-let [block (db/entity [:block/uuid block-id])]
     (let [properties (:block/properties block)
-          query-properties (pu/lookup properties :query-properties)
+          query-properties (pu/lookup properties :logseq.property/query-properties)
           repo (state/get-current-repo)
           db-based? (config/db-based-graph? repo)
           query-properties (if db-based?
@@ -3417,8 +3417,8 @@
   (->> (:block/macros (db/entity (:db/id block)))
        (some (fn [macro]
                (let [properties (:block/properties macro)
-                     macro-name (pu/lookup properties :logseq.macro-name)
-                     macro-arguments (pu/lookup properties :logseq.macro-arguments)]
+                     macro-name (pu/lookup properties :logseq.property/macro-name)
+                     macro-arguments (pu/lookup properties :logseq.property/macro-arguments)]
                  (when-let [query-body (and (= "query" macro-name) (not-empty (string/join " " macro-arguments)))]
                    (seq (:query
                          (try

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

@@ -329,7 +329,7 @@
 
 (defmethod handle :modal/set-query-properties [[_ block all-properties]]
   (let [properties (:block/properties block)
-        query-properties (pu/lookup properties :query-properties)
+        query-properties (pu/lookup properties :logseq.property/query-properties)
         block-properties (if (config/db-based-graph? (state/get-current-repo))
                            query-properties
                            (some-> query-properties

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

@@ -107,7 +107,7 @@
               (not journal?)
               (remove :block/journal?)
               (not excluded-pages?)
-              (remove (fn [p] (true? (pu/get-block-property-value p :exclude-from-graph-view)))))
+              (remove (fn [p] (true? (pu/get-block-property-value p :logseq.property/exclude-from-graph-view)))))
             links (concat (seq relation)
                           (seq tagged-pages)
                           (seq namespaces))

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

@@ -241,7 +241,7 @@
   [page-name]
   (let [properties (db/get-page-properties page-name)]
     (if (config/db-based-graph? (state/get-current-repo))
-      (pu/lookup properties :filters)
+      (pu/lookup properties :logseq.property/filters)
       (let [properties-str (or (:filters properties) "{}")]
         (try (reader/read-string properties-str)
              (catch :default e

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

@@ -4,28 +4,45 @@
   compatible with file graphs"
   (:require [frontend.state :as state]
             [frontend.db :as db]
+            [datascript.core :as d]
+            [logseq.common.util :as common-util]
+            [logseq.db.sqlite.util :as sqlite-util]
             [logseq.db.frontend.property :as db-property]))
 
 (defn lookup
-  "Get the value of coll's (a map) `key`. For file and db graphs"
+  "Get the value of coll's (a map) by db-ident. For file and db graphs"
   [coll key]
   (let [repo (state/get-current-repo)
         db (db/get-db repo)]
     (db-property/lookup repo db coll key)))
 
+(defn lookup-by-name
+  "Get the value of coll's (a map) by name. Only use this
+   for file graphs or for db graphs when user properties are involved"
+  [coll key]
+  (let [repo (state/get-current-repo)
+        db (db/get-db repo)
+        property-name (if (keyword? key)
+                        (name key)
+                        key)]
+    (if (sqlite-util/db-based-graph? repo)
+      (when-let [property (d/entity db [:block/name (common-util/page-name-sanity-lc property-name)])]
+        (get coll (:block/uuid property)))
+      (get coll key))))
+
 (defn get-block-property-value
-  "Get the value of block's property `key`"
-  [block key]
+  "Get the value of a built-in block's property by its db-ident"
+  [block db-ident]
   (let [repo (state/get-current-repo)
         db (db/get-db repo)]
-    (db-property/get-block-property-value repo db block key)))
+    (db-property/get-block-property-value repo db block db-ident)))
 
 (defn get-property
   "Get a property given its unsanitized name"
   [property-name]
   (let [repo (state/get-current-repo)
         db (db/get-db repo)]
-    (db-property/get-property db property-name)))
+    (d/entity db [:block/name (common-util/page-name-sanity-lc (name property-name))])))
 
 ;; TODO: move this to another ns
 (defn get-page-uuid
@@ -42,10 +59,10 @@
     (db-property/get-pid repo db db-ident)))
 
 (defn block->shape [block]
-  (get-block-property-value block :logseq.tldraw.shape))
+  (get-block-property-value block :logseq.property.tldraw/shape))
 
 (defn page-block->tldr-page [block]
-  (get-block-property-value block :logseq.tldraw.page))
+  (get-block-property-value block :logseq.property.tldraw/page))
 
 (defn shape-block?
   [block]

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

@@ -55,7 +55,7 @@
     (let [block (when (uuid? page-name-or-block-uuid)
                   (model/get-block-by-uuid page-name-or-block-uuid))
           properties (:block/properties block)]
-      (if (pu/lookup properties :heading)
+      (if (pu/lookup properties :logseq.property/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))}}

+ 6 - 6
src/main/frontend/handler/whiteboard.cljs

@@ -31,7 +31,7 @@
 
 (defn- build-shapes
   [page-block blocks]
-  (let [page-metadata (pu/get-block-property-value page-block :logseq.tldraw.page)
+  (let [page-metadata (pu/get-block-property-value page-block :logseq.property.tldraw/page)
         shapes-index (:shapes-index page-metadata)
         shape-id->index (zipmap shapes-index (range 0 (count shapes-index)))]
     (->> blocks
@@ -98,7 +98,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))
-                              (mapv (fn [b] (pu/get-block-property-value b :logseq.tldraw.shape)))
+                              (mapv (fn [b] (pu/get-block-property-value b :logseq.property.tldraw/shape)))
                               (remove nil?)))
         deleted-shapes-tx (mapv (fn [id] [:db/retractEntity [:block/uuid (uuid id)]]) deleted-ids)
         upserted-blocks (->> (map #(shape->block % page-name) upsert-shapes)
@@ -106,11 +106,11 @@
                                        (= (:nonce
                                            (pu/get-block-property-value
                                             (db/entity [:block/uuid (:block/uuid b)])
-                                            :logseq.tldraw.shape))
+                                            :logseq.property.tldraw/shape))
                                           (:nonce
                                            (pu/get-block-property-value
                                             b
-                                            :logseq.tldraw.shape))))))
+                                            :logseq.property.tldraw/shape))))))
         page-entity (model/get-page page-name)
         page-block (build-page-block page-entity page-name tl-page assets shapes-index)]
     (when (or (seq upserted-blocks)
@@ -133,7 +133,7 @@
   (let [tl-page ^js (second (first (.-pages app)))
         shapes (.-shapes ^js tl-page)
         page-block (model/get-page page-name)
-        prev-page-metadata (pu/get-block-property-value page-block :logseq.tldraw.page)
+        prev-page-metadata (pu/get-block-property-value page-block :logseq.property.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]
@@ -318,7 +318,7 @@
     (let [tl-page ^js (second (first (.-pages app)))]
       (when tl-page
         (when-let [page (db/entity [:block/name page-name])]
-         (let [page-metadata (pu/get-block-property-value page :logseq.tldraw.page)
+         (let [page-metadata (pu/get-block-property-value page :logseq.property.tldraw/page)
                shapes-index (:shapes-index page-metadata)]
            (when (seq shapes-index)
              (.updateShapesIndex tl-page (bean/->js shapes-index)))))))))

+ 3 - 2
src/main/frontend/shui.cljs

@@ -11,13 +11,14 @@
     [logseq.shui.context :refer [make-context]]))
 
 
-(def default-versions {:logseq.table.version 1})
+(def default-versions {:logseq.property.table/version 1})
 
 (defn get-shui-component-version
   "Returns the version of the shui component, checking first
   the block properties, then the global config, then the defaults."
   [component-name block-config]
-  (let [version-key (keyword (str "logseq." (name component-name) ".version"))]
+  (let [version-key (keyword (str "logseq.property." (name component-name))
+                             "version")]
     (js/parseFloat
       (or (pu/lookup (get-in block-config [:block :block/properties]) version-key)
           (get-in (state/get-config) [version-key])

+ 1 - 1
src/main/logseq/api.cljs

@@ -801,7 +801,7 @@
     (p/let [block-uuid (sdk-utils/uuid-or-throw-error block-uuid)
             _ (db-async/<get-block (state/get-current-repo) block-uuid :children? false)]
       (when-let [block (db-model/query-block-by-uuid block-uuid)]
-        (pu/lookup (:block/properties block) key)))))
+        (pu/lookup-by-name (:block/properties block) key)))))
 
 (def ^:export get_block_properties
   (fn [block-uuid]

+ 2 - 3
src/test/frontend/handler/db_based/property_test.cljs

@@ -4,7 +4,6 @@
             [clojure.test :refer [deftest is testing are use-fixtures]]
             [frontend.test.helper :as test-helper]
             [datascript.core :as d]
-            [frontend.handler.property.util :as pu]
             [frontend.state :as state]
             [frontend.handler.page :as page-handler]
             [frontend.handler.editor :as editor-handler]))
@@ -153,9 +152,9 @@
       (let [fb (db/entity [:block/uuid fbid])
             sb (db/entity [:block/uuid sbid])]
         (are [x y] (= x y)
-          (pu/get-block-property-value fb k)
+          (get (:block/properties fb) (:block/uuid (db/entity [:block/name k])))
           v
-          (pu/get-block-property-value sb k)
+          (get (:block/properties sb) (:block/uuid (db/entity [:block/name k])))
           v))))
 
   (testing "Batch remove properties"