mirror of https://github.com/logseq/logseq
parent
14a3e5287b
commit
ac31842cec
|
@ -274,6 +274,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]
|
||||
|
|
|
@ -100,7 +100,9 @@
|
|||
: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}
|
||||
|
||||
|
@ -144,6 +146,7 @@
|
|||
:block/properties
|
||||
:block/properties-order
|
||||
:block/properties-text-values
|
||||
:block/macros
|
||||
:block/invalid-properties
|
||||
:block/warning
|
||||
}
|
||||
|
@ -152,6 +155,7 @@
|
|||
;; If only block/content changes
|
||||
(def db-version-retract-attributes
|
||||
#{:block/refs
|
||||
:block/macros
|
||||
:block/warning})
|
||||
|
||||
|
||||
|
|
|
@ -494,6 +494,27 @@
|
|||
(conj acc (assoc block :block/path-refs path-ref-pages))
|
||||
parents)))))
|
||||
|
||||
(defn- macro->block
|
||||
"macro: {:name \"\" arguments [\"\"]}"
|
||||
[macro]
|
||||
{:block/uuid (random-uuid)
|
||||
: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)
|
||||
|
@ -524,6 +545,7 @@
|
|||
: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)]
|
||||
|
@ -669,8 +691,9 @@
|
|||
(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)]
|
||||
(recur (conj headings block') (rest blocks) {} {} []))
|
||||
(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) {} {} []))
|
||||
|
||||
:else
|
||||
(recur headings (rest blocks) timestamps properties (conj body block))))
|
||||
|
|
|
@ -529,6 +529,20 @@
|
|||
(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
|
||||
|
@ -545,6 +559,7 @@
|
|||
(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)
|
||||
|
|
|
@ -114,7 +114,8 @@
|
|||
:card-next-schedule 6, :ls-type 79, :card-last-interval 6, :type 107,
|
||||
:template 5, :title 114, :alias 41, :supports 5, :id 145, :url 5,
|
||||
:card-ease-factor 6, :created-at 46,
|
||||
:card-last-reviewed 6, :platforms 51, :initial-version 8, :heading 226}
|
||||
:card-last-reviewed 6, :platforms 51, :initial-version 8, :heading 226
|
||||
:logseq.macro-arguments 109, :logseq.macro-name 109}
|
||||
(get-top-block-properties db))
|
||||
"Counts for top block properties")
|
||||
|
||||
|
@ -161,7 +162,7 @@
|
|||
;; only increase over time as the docs graph rarely has deletions
|
||||
(testing "Counts"
|
||||
(is (= 303 (count files)) "Correct file count")
|
||||
(is (= 63954 (count (d/datoms db :eavt))) "Correct datoms count")
|
||||
(is (= 64390 (count (d/datoms db :eavt))) "Correct datoms count")
|
||||
|
||||
(is (= 5866
|
||||
(ffirst
|
||||
|
|
|
@ -60,12 +60,19 @@
|
|||
{:tx tx :revert-tx revert-tx})) refs)))
|
||||
(apply concat))
|
||||
retracted-tx' (mapcat :tx retracted-tx)
|
||||
revert-tx (mapcat :revert-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)]
|
||||
(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'))
|
||||
(concat txs retracted-tx' macros-tx))
|
||||
txs))
|
||||
|
||||
(defn transact!
|
||||
|
|
|
@ -66,7 +66,8 @@
|
|||
[promesa.core :as p]
|
||||
[rum.core :as rum]
|
||||
[frontend.fs.capacitor-fs :as capacitor-fs]
|
||||
[logseq.db :as ldb]))
|
||||
[logseq.db :as ldb]
|
||||
[frontend.db.query-dsl :as query-dsl]))
|
||||
|
||||
;; FIXME: should support multiple images concurrently uploading
|
||||
|
||||
|
@ -3407,8 +3408,17 @@
|
|||
(defn- valid-dsl-query-block?
|
||||
"Whether block has a valid dsl query."
|
||||
[block]
|
||||
(some-> (:block/content block)
|
||||
(string/includes? "{{query ")))
|
||||
(->> (: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))))))))))
|
||||
|
||||
(defn- valid-custom-query-block?
|
||||
"Whether block has a valid custom query."
|
||||
|
|
|
@ -516,13 +516,13 @@
|
|||
:export-blocks-as-markdown
|
||||
(try
|
||||
(let [content
|
||||
(if (string? root-block-uuids-or-page-name)
|
||||
(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)))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue