Browse Source

Remove :block/macros

Tienson Qin 1 year ago
parent
commit
21d550de12

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

@@ -219,7 +219,6 @@
    ;; 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]

+ 1 - 5
deps/db/src/logseq/db/frontend/schema.cljs

@@ -100,9 +100,7 @@
    :block/journal-day {}
    ;; page's namespace
    :block/namespace {:db/valueType :db.type/ref}
-   ;; macros in block
-   :block/macros {:db/valueType :db.type/ref
-                  :db/cardinality :db.cardinality/many}
+
    ;; block's file
    :block/file {:db/valueType :db.type/ref}
 
@@ -146,7 +144,6 @@
     :block/properties
     :block/properties-order
     :block/properties-text-values
-    :block/macros
     :block/invalid-properties
     :block/warning
     }
@@ -155,7 +152,6 @@
 ;; If only block/content changes
 (def db-version-retract-attributes
   #{:block/refs
-    :block/macros
     :block/warning})
 
 

+ 2 - 25
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -494,27 +494,6 @@
                (conj acc (assoc block :block/path-refs path-ref-pages))
                parents)))))
 
-(defn- macro->block
-  "macro: {:name \"\" arguments [\"\"]}"
-  [macro]
-  {:db/ident (str (:name macro) " " (string/join " " (:arguments macro)))
-   :block/type "macro"
-   :block/properties {:logseq.macro-name (:name macro)
-                      :logseq.macro-arguments (:arguments macro)}})
-
-(defn extract-macros-from-ast
-  [ast]
-  (let [*result (atom #{})]
-    (walk/postwalk
-     (fn [f]
-       (if (and (vector? f) (= (first f) "Macro"))
-         (do
-           (swap! *result conj (second f))
-           nil)
-         f))
-     ast)
-    (mapv macro->block @*result)))
-
 (defn with-pre-block-if-exists
   [blocks body pre-block-properties encoded-content {:keys [db date-formatter user-config]}]
   (let [first-block (first blocks)
@@ -545,7 +524,6 @@
                                 :block/properties-text-values properties-text-values
                                 :block/invalid-properties invalid-properties
                                 :block/pre-block? pre-block?
-                                :block/macros (extract-macros-from-ast body)
                                 :block/body body}
                          {:keys [tags refs]}
                          (with-page-block-refs {:body body :refs property-refs} false db date-formatter)]
@@ -691,9 +669,8 @@
                   (recur headings (rest blocks) timestamps properties body))
 
                 (heading-block? block)
-                (let [block' (construct-block block properties timestamps body encoded-content format pos-meta with-id? options)
-                      block'' (assoc block' :macros (extract-macros-from-ast (cons block body)))]
-                  (recur (conj headings block'') (rest blocks) {} {} []))
+                (let [block' (construct-block block properties timestamps body encoded-content format pos-meta with-id? options)]
+                  (recur (conj headings block') (rest blocks) {} {} []))
 
                 :else
                 (recur headings (rest blocks) timestamps properties (conj body block))))

+ 0 - 15
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -406,20 +406,6 @@
                      (map #(add-uuid-to-page-map % page-names-to-uuids)))))
       block)))
 
-(defn- update-block-macros
-  [block db page-names-to-uuids]
-  (if (seq (:block/macros block))
-    (update block :block/macros
-            (fn [macros]
-              (mapv (fn [m]
-                      (-> m
-                          (update :block/properties
-                                  (fn [props]
-                                    (update-keys props #(cached-prop-name->uuid db page-names-to-uuids %))))
-                          (assoc :block/uuid (d/squuid))))
-                    macros)))
-    block))
-
 (defn- fix-pre-block-references
   [{:block/keys [left parent page] :as block} pre-blocks]
   (cond-> block
@@ -436,7 +422,6 @@
   (let [old-property-schemas @(:property-schemas import-state)]
     (-> block
         (fix-pre-block-references pre-blocks)
-        (update-block-macros db page-names-to-uuids)
         ;; needs to come before update-block-refs to detect new property schemas
         (handle-block-properties db page-names-to-uuids (:block/refs block) options)
         (update-block-refs page-names-to-uuids old-property-schemas options)

+ 2 - 9
deps/outliner/src/logseq/outliner/datascript.cljs

@@ -60,19 +60,12 @@
                                          {:tx tx :revert-tx revert-tx})) refs)))
                             (apply concat))
           retracted-tx' (mapcat :tx retracted-tx)
-          revert-tx (mapcat :revert-tx retracted-tx)
-          macros-tx (mapcat (fn [b]
-                              ;; Only delete if last reference
-                              (keep #(when (<= (count (:block/_macros (d/entity db (:db/id %))))
-                                               1)
-                                       (when (:db/id %) (vector :db.fn/retractEntity (:db/id %))))
-                                    (:block/macros b)))
-                            retracted-blocks)]
+          revert-tx (mapcat :revert-tx retracted-tx)]
       (when (and (seq retracted-tx') (fn? set-state-fn))
         (set-state-fn [:editor/last-replace-ref-content-tx repo]
                       {:retracted-block-ids retracted-block-ids
                        :revert-tx revert-tx}))
-      (concat txs retracted-tx' macros-tx))
+      (concat txs retracted-tx'))
     txs))
 
 (defn transact!

+ 4 - 5
src/main/frontend/components/block/macros.cljs

@@ -4,11 +4,8 @@
             [frontend.extensions.sci :as sci]
             [frontend.handler.common :as common-handler]
             [frontend.handler.property.util :as pu]
-            [frontend.handler.db-based.property.util :as db-pu]
-            [frontend.state :as state]
             [goog.string :as gstring]
-            [goog.string.format]
-            [frontend.config :as config]))
+            [goog.string.format]))
 
 (defn- normalize-query-function
   [ast result]
@@ -45,7 +42,9 @@
            :updated-at
            :block/updated-at
 
-           (let [prop-key f]
+           (let [vals (map #(pu/lookup-by-name (:block/properties %) f) result)
+                 int? (some integer? vals)
+                 prop-key f]
              `(~'fn [~'b]
                     (~'let [~'result-str (~'get-in ~'b [:block/properties ~prop-key])
                             ~'result-num (~'parseFloat ~'result-str)

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

@@ -3409,17 +3409,7 @@
 (defn- valid-dsl-query-block?
   "Whether block has a valid dsl query."
   [block]
-  (->> (:block/macros (db/entity (:db/id block)))
-       (some (fn [macro]
-               (let [properties (:block/properties macro)
-                     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
-                           (query-dsl/parse-query query-body)
-                           (catch :default _e
-                             nil))))))))))
+  (string/includes? block "{{query "))
 
 (defn- valid-custom-query-block?
   "Whether block has a valid custom query."

+ 11 - 8
src/main/frontend/handler/export/text.cljs

@@ -513,15 +513,18 @@
   {:pre [(or (coll? root-block-uuids-or-page-name)
              (string? root-block-uuids-or-page-name))]}
   (util/profile
-      :export-blocks-as-markdown
-      (let [content
-            (if (string? root-block-uuids-or-page-name)
+   :export-blocks-as-markdown
+   (try
+     (let [content
+          (if (string? root-block-uuids-or-page-name)
               ;; page
-              (common/get-page-content root-block-uuids-or-page-name)
-              (common/root-block-uuids->content repo root-block-uuids-or-page-name))
-            first-block (db/entity [:block/uuid (first root-block-uuids-or-page-name)])
-            format (or (:block/format first-block) (state/get-preferred-format))]
-        (export-helper content format options))))
+            (common/get-page-content root-block-uuids-or-page-name)
+            (common/root-block-uuids->content repo root-block-uuids-or-page-name))
+          first-block (db/entity [:block/uuid (first root-block-uuids-or-page-name)])
+          format (or (:block/format first-block) (state/get-preferred-format))]
+      (export-helper content format options))
+     (catch :default e
+       (js/console.error e)))))
 
 (defn export-files-as-markdown
   "options see also `export-blocks-as-markdown`"