Przeglądaj źródła

fix: macros were not being saved

macros were being discarded as unknown blocks when they should've been
saved as a block with a known type.  Introduced a new type number as
macros don't have most of the attributes that blocks or pages do.
Features like collapsible queries now work in db graphs. Also removed
an outdated reference that assumed macro was a page (which it no longer
is)
Gabriel Horner 2 lat temu
rodzic
commit
2acac87094

+ 11 - 0
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -199,6 +199,7 @@
     ;; refs
    [:block/page :int]
    [:block/path-refs {:optional true} [:set :int]]
+   [:block/macros {:optional true} [:set :int]]
    [:block/link {:optional true} :int]
     ;; other
    [:block/marker {:optional true} :string]
@@ -255,6 +256,15 @@
    [:db/ident :keyword]
    [:db/type {:optional true} :string]])
 
+(def macro
+  [:map
+   [:db/ident :string]
+   [:block/uuid :uuid]
+   [:block/type [:= #{"macro"}]]
+   [:block/properties block-properties]
+   ;; Should this be removed?
+   [:block/tx-id {:optional true} :int]])
+
 (def DB
   "Malli schema for entities from schema/schema-for-db-based-graph. In order to
   thoroughly validate properties, the entities and this schema should be
@@ -267,4 +277,5 @@
     file-block
     schema-version
     db-ident
+    macro
     unknown-block]])

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

@@ -38,7 +38,7 @@
    :hl-stamp {:schema {:type :number}}
    :hl-color {:schema {:type :default}}
    :logseq.macro-name {:schema {:type :default}}
-   :logseq.macro-arguments {:schema {:type :default}}
+   :logseq.macro-arguments {:schema {:type :coll}}
    :logseq.order-list-type {:schema {:type :default}}
    :logseq.tldraw.page {:schema {:type :map}}
    :logseq.tldraw.shape {:schema {:type :map}}

+ 1 - 1
deps/db/src/logseq/db/sqlite/db.cljs

@@ -124,7 +124,7 @@
                                (map :uuid))
           latest-journal-blocks (when (seq recent-journals)
                                   (query repo db (str "select * from blocks where type = 1 and page_uuid IN " (clj-list->sql recent-journals))))
-          init-data (query repo db "select * from blocks where type in (3, 4, 5, 6)")]
+          init-data (query repo db "select * from blocks where type in (3, 4, 5, 6, 7)")]
       {:all-pages all-pages
        :all-blocks all-block-ids
        :journal-blocks latest-journal-blocks

+ 1 - 1
deps/db/src/logseq/db/sqlite/restore.cljs

@@ -80,7 +80,7 @@
                     (keep (fn [b]
                             (let [eid (assign-id-to-uuid-fn (:uuid b))]
                               (if (and (uuid-string? (:uuid b))
-                                       (not (contains?  #{3 6} (:type b)))) ; deleted blocks still refed
+                                       (= 5 (:type b)))
                                 [[eid :block/uuid (:uuid b)]
                                  [eid :block/unknown? true]]
                                 (datoms-str->eav-vec (:datoms b) eid))))

+ 2 - 0
deps/db/src/logseq/db/sqlite/util.cljs

@@ -11,6 +11,7 @@
 (defn- type-of-block
   "
   TODO: use :block/type
+  FIXME: 4 isn't used. Delete it?
   | value | meaning                                        |
   |-------+------------------------------------------------|
   |     1 | normal block                                   |
@@ -26,6 +27,7 @@
     (some #{:file/content :schema/version :db/type} (keys block)) 3
     (contains? (:block/type block) "property") 6
     (:block/name block) 2
+    (contains? (set (:block/type block)) "macro") 7
     :else 5))
 
 (defn time-ms

+ 20 - 11
src/main/frontend/format/block.cljs

@@ -14,25 +14,34 @@
             [frontend.handler.property.util :as pu]
             [lambdaisland.glogi :as log]
             [frontend.util :as util]
+            [datascript.core :as d]
             [logseq.db.frontend.property :as db-property]))
 
 (defn- update-extracted-block-properties
   "Updates DB graph blocks to ensure that built-in properties are using uuids
   for property ids"
   [blocks]
-  (let [repo (state/get-current-repo)]
-    (if (config/db-based-graph? repo)
-     (map (fn [b]
-            (if (:block/properties b)
-              (-> b
-                  (dissoc :block/properties-order)
-                  (update :block/properties
-                          (fn [props]
+  (let [repo (state/get-current-repo)
+        update-properties (fn [props]
                             (update-keys props #(if (contains? db-property/built-in-properties-keys %)
                                                   (pu/get-built-in-property-uuid repo %)
-                                                  %)))))
-              b))
-          blocks)
+                                                  %)))]
+    (if (config/db-based-graph? repo)
+     (->> blocks
+          (map (fn [b]
+                 (if (:block/properties b)
+                   (-> b
+                       (dissoc :block/properties-order)
+                       (update :block/properties update-properties))
+                   b)))
+          (map (fn [b]
+                 (if (:block/macros b)
+                   (update b :block/macros
+                           (fn [macros]
+                             (map #(-> %
+                                       (assoc :block/uuid (d/squuid))
+                                       (update :block/properties update-properties)) macros)))
+                   b))))
      blocks)))
 
 (defn extract-blocks

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

@@ -154,8 +154,7 @@
                    (or (util/uuid-string? name)
                        (gp-config/draw? name)
                        (db/built-in-pages-names (string/upper-case name))
-                       (db-property/built-in-properties-keys-str name)
-                       (contains? (:block/type p) "macro")))))
+                       (db-property/built-in-properties-keys-str name)))))
        (common-handler/fix-pages-timestamps)))
 
 (defn get-filters