Decouple graph-parser util from app util usage

For tiny util heavily used fns like safe-re-find and uuid-string?,
decouple graph-parser from so much of the app
This commit is contained in:
Gabriel Horner
2022-05-13 16:17:43 -04:00
parent b9bbd0c605
commit 5b0d5fb8b5
27 changed files with 88 additions and 83 deletions

View File

@@ -257,7 +257,7 @@
(defn- another-block-with-same-id-exists?
[current-id block-id]
(and (string? block-id)
(gp-util/uuid-string? block-id)
(util/uuid-string? block-id)
(not= current-id (cljs.core/uuid block-id))
(db/entity [:block/uuid (cljs.core/uuid block-id)])))
@@ -338,7 +338,7 @@
(if (and (state/enable-timetracking?)
(not= (:block/content block) value))
(let [format (:block/format block)
new-marker (last (gp-util/safe-re-find (marker/marker-pattern format) (or value "")))
new-marker (last (util/safe-re-find (marker/marker-pattern format) (or value "")))
new-value (with-marker-time value block format
new-marker
(:block/marker block))]
@@ -483,10 +483,10 @@
(let [current-page (state/get-current-page)
block-id (or
(and (:id config)
(gp-util/uuid-string? (:id config))
(util/uuid-string? (:id config))
(:id config))
(and current-page
(gp-util/uuid-string? current-page)
(util/uuid-string? current-page)
current-page))]
(= uuid (and block-id (medley/uuid block-id)))))
@@ -1147,7 +1147,7 @@
[]
(when-let [page (get-nearest-page)]
(let [page-name (string/lower-case page)
block? (gp-util/uuid-string? page-name)]
block? (util/uuid-string? page-name)]
(when-let [page (db/get-page page-name)]
(if block?
(state/sidebar-add-block!
@@ -1177,7 +1177,7 @@
(let [page (state/get-current-page)
block-id (and
(string? page)
(gp-util/uuid-string? page)
(util/uuid-string? page)
(medley/uuid page))]
(when block-id
(let [block-parent (db/get-block-parent block-id)]
@@ -2040,7 +2040,7 @@
(defn- last-top-level-child?
[{:keys [id]} current-node]
(when id
(when-let [entity (if (gp-util/uuid-string? (str id))
(when-let [entity (if (util/uuid-string? (str id))
(db/entity [:block/uuid (uuid id)])
(db/entity [:block/name (util/page-name-sanity-lc id)]))]
(= (:block/uuid entity) (tree/-get-parent-id current-node)))))
@@ -2867,7 +2867,7 @@
(string/join "\n"
(mapv (fn [p] (->> (string/trim p)
((fn [p]
(if (gp-util/safe-re-find (if (= format :org)
(if (util/safe-re-find (if (= format :org)
#"\s*\*+\s+"
#"\s*-\s+") p)
p
@@ -2932,9 +2932,9 @@
;; from external
(let [format (or (db/get-page-format (state/get-current-page)) :markdown)]
(match [format
(nil? (gp-util/safe-re-find #"(?m)^\s*(?:[-+*]|#+)\s+" text))
(nil? (gp-util/safe-re-find #"(?m)^\s*\*+\s+" text))
(nil? (gp-util/safe-re-find #"(?:\r?\n){2,}" text))]
(nil? (util/safe-re-find #"(?m)^\s*(?:[-+*]|#+)\s+" text))
(nil? (util/safe-re-find #"(?m)^\s*\*+\s+" text))
(nil? (util/safe-re-find #"(?:\r?\n){2,}" text))]
[:markdown false _ _]
(paste-text-parseable format text)
@@ -3219,7 +3219,7 @@
:or {collapse? false expanded? false incremental? true root-block nil}}]
(when-let [page (or (state/get-current-page)
(date/today))]
(let [block? (gp-util/uuid-string? page)
(let [block? (util/uuid-string? page)
block-id (or root-block (and block? (uuid page)))
blocks (if block-id
(db/get-block-and-children (state/get-current-repo) block-id)