refactor: allow a block to have multiple types

For example, a whiteboard page can be used both as a property and a class.
This commit is contained in:
Tienson Qin
2023-09-25 10:46:00 +08:00
parent e7423f93ac
commit 0e8653985d
20 changed files with 92 additions and 112 deletions

View File

@@ -145,9 +145,9 @@
;; TODO: performance improvement
(defn- extract-pages-and-blocks
"uri-encoded? - if is true, apply URL decode on the file path
options -
options -
:extracted-block-ids - An atom that contains all block ids that have been extracted in the current page (not yet saved to db)
:resolve-uuid-fn - Optional fn which is called to resolve uuids of each block. Enables diff-merge
:resolve-uuid-fn - Optional fn which is called to resolve uuids of each block. Enables diff-merge
(2 ways diff) based uuid resolution upon external editing.
returns a list of the uuids, given the receiving ast, or nil if not able to resolve.
Implemented in file-common-handler/diff-merge-uuids for IoC
@@ -169,7 +169,7 @@
(vec))
ref-pages (atom #{})
blocks (map (fn [block]
(if (contains? #{"macro"} (:block/type block))
(if (contains? (:block/type block) "macro")
block
(let [block-ref-pages (seq (:block/refs block))
page-lookup-ref [:block/name page-name]

View File

@@ -103,6 +103,6 @@
page (first pages)]
(is (= (get-in page [:block/file :file/path]) "/whiteboards/foo.edn"))
(is (= (:block/name page) "foo"))
(is (= (:block/type page) "whiteboard"))
(is (true? (contains? (:block/type page) "whiteboard")))
(is (= (:block/original-name page) "Foo"))
(is (every? #(= (:block/parent %) {:block/name "foo"}) blocks))))

View File

@@ -95,7 +95,7 @@
parent (:block/page (ffirst blocks))]
(is (= {:block/name "foo"
:block/original-name "Foo"
:block/type "whiteboard"
:block/type #{"whiteboard"}
:block/file {:file/path "/whiteboards/foo.edn"}}
parent)
"parsed block in the whiteboard page has correct parent page"))))