chore: remove fns made unused by OG removal

Found unused ones in deps/common, from unused frontend.db aliases
and from fns that only existed for their corresponding tests
This commit is contained in:
Gabriel Horner
2026-01-13 15:56:32 -05:00
parent 173898240e
commit 05ffa3eeb6
23 changed files with 11 additions and 603 deletions

View File

@@ -13,8 +13,6 @@ frontend.debug/print
frontend.extensions.code/editor frontend.extensions.code/editor
;; Referenced in commented TODO ;; Referenced in commented TODO
frontend.extensions.pdf.utils/get-page-bounding frontend.extensions.pdf.utils/get-page-bounding
;; For repl
logseq.graph-parser.mldoc/ast-export-markdown
;; Protocol fn wrapper that could be used ;; Protocol fn wrapper that could be used
frontend.fs/readdir frontend.fs/readdir
;; Referenced in TODO ;; Referenced in TODO
@@ -49,8 +47,6 @@ frontend.util.pool/terminate-pool!
;; Test runners used by shadow ;; Test runners used by shadow
frontend.test.node-test-runner/main frontend.test.node-test-runner/main
frontend.test.frontend-node-test-runner/main frontend.test.frontend-node-test-runner/main
;; Test runner for nbb
logseq.graph-parser.nbb-test-runner/run-tests
;; For debugging ;; For debugging
frontend.fs.sync/debug-print-sync-events-loop frontend.fs.sync/debug-print-sync-events-loop
frontend.fs.sync/stop-debug-print-sync-events-loop frontend.fs.sync/stop-debug-print-sync-events-loop

View File

@@ -51,17 +51,6 @@
[path] [path]
(second (split-ext path))) (second (split-ext path)))
(defn safe-filename?
"Safe filename on all platforms"
[fname]
(and (not (string/blank? fname))
(< (count fname) 255)
(not (or (re-find #"[\/?<>\\:*|\"]" fname)
(re-find #"^\.+$" fname)
(re-find #"[\. ]$" fname)
(re-find #"(?i)^(COM[0-9]|CON|LPT[0-9]|NUL|PRN|AUX|com[0-9]|con|lpt[0-9]|nul|prn|aux)\..+" fname)
(re-find #"[\u0000-\u001f\u0080-\u009f]" fname)))))
(defn- path-join-internal (defn- path-join-internal
"Joins the given path segments into a single path, handling relative paths, "Joins the given path segments into a single path, handling relative paths,
'..' and '.' normalization." '..' and '.' normalization."
@@ -253,31 +242,6 @@
(js/console.error "unhandled trim-base" base-path sub-path) (js/console.error "unhandled trim-base" base-path sub-path)
nil)))) nil))))
(defn relative-path
"Get relative path from base path.
Works for both path and URL."
[base-path sub-path]
(let [base-path (path-normalize base-path)
sub-path (path-normalize sub-path)
is-url? (is-file-url? base-path)]
(if (string/starts-with? sub-path base-path)
(if is-url?
(safe-decode-uri-component (string/replace (subs sub-path (count base-path)) #"^/+", ""))
(string/replace (subs sub-path (count base-path)) #"^/+", ""))
;; append as many ..
;; NOTE: This is a buggy impl, relative-path is different when base-path is a file or a dir
(let [base-segs (string/split base-path #"/" -1)
path-segs (string/split sub-path #"/" -1)
common-segs (take-while #(= (first %) (second %)) (map vector base-segs path-segs))
base-segs (drop (count common-segs) base-segs)
remain-segs (drop (count common-segs) path-segs)
base-prefix (apply str (repeat (max 0 (dec (count base-segs))) "../"))]
(js/console.error (js/Error. "buggy relative-path") base-path sub-path)
#_{:clj-kondo/ignore [:path-invalid-construct/string-join]}
(if is-url?
(safe-decode-uri-component (str base-prefix (string/join "/" remain-segs)))
(str base-prefix (string/join "/" remain-segs)))))))
(defn parent (defn parent
"Parent, containing directory" "Parent, containing directory"
[path] [path]
@@ -286,45 +250,12 @@
(path-normalize (str path "/..")) (path-normalize (str path "/.."))
nil)) nil))
(defn resolve-relative-path
"Assume current-path is a file"
[current-path rel-path]
(if-let [base-dir (parent current-path)]
(path-join base-dir rel-path)
rel-path))
(defn get-relative-path
"Assume current-path is a file, and target-path is a file or directory.
Return relative path from current-path to target-path.
Works for both path and URL. Also works for relative path.
The opposite operation is `resolve-relative-path`"
[current-path target-path]
(let [base-path (parent current-path)
sub-path (path-normalize target-path)
is-url? (is-file-url? base-path)
base-segs (if base-path
(string/split base-path #"/" -1)
[])
path-segs (string/split sub-path #"/" -1)
common-segs (take-while #(= (first %) (second %)) (map vector base-segs path-segs))
base-segs (drop (count common-segs) base-segs)
remain-segs (drop (count common-segs) path-segs)
base-prefix (apply str (repeat (max 0 (count base-segs)) "../"))]
#_{:clj-kondo/ignore [:path-invalid-construct/string-join]}
(if is-url?
(safe-decode-uri-component (str base-prefix (string/join "/" remain-segs)))
(str base-prefix (string/join "/" remain-segs)))))
;; compat ;; compat
(defn basename (defn basename
[path] [path]
(let [path (string/replace path #"/+$" "")] (let [path (string/replace path #"/+$" "")]
(filename path))) (filename path)))
(defn dirname
[path]
(parent path))
(defn absolute? (defn absolute?
"Whether path `p` is absolute." "Whether path `p` is absolute."
[p] [p]

View File

@@ -48,16 +48,6 @@
(when (string? tag-name) (when (string? tag-name)
(not (re-find #"[#\t\r\n]+" tag-name)))) (not (re-find #"[#\t\r\n]+" tag-name))))
(defn tag?
"Whether `s` is a tag."
[s]
(and (string? s)
(string/starts-with? s "#")
(or
(not (string/includes? s " "))
(string/starts-with? s "#[[")
(string/ends-with? s "]]"))))
(defn safe-subs (defn safe-subs
([s start] ([s start]
(let [c (count s)] (let [c (count s)]
@@ -66,10 +56,6 @@
(let [c (count s)] (let [c (count s)]
(subs s (min c start) (min c end))))) (subs s (min c start) (min c end)))))
(defn unquote-string
[v]
(string/trim (subs v 1 (dec (count v)))))
(defn wrapped-by (defn wrapped-by
[v start end] [v start end]
(and (string? v) (>= (count v) 2) (and (string? v) (>= (count v) 2)
@@ -254,15 +240,6 @@
[fmt & args] [fmt & args]
(apply gstring/format fmt args)) (apply gstring/format fmt args))
(defn remove-first [pred coll]
((fn inner [coll]
(lazy-seq
(when-let [[x & xs] (seq coll)]
(if (pred x)
xs
(cons x (inner xs))))))
coll))
(defn concat-without-nil (defn concat-without-nil
[& cols] [& cols]
(->> (apply concat cols) (->> (apply concat cols)
@@ -298,10 +275,6 @@
[s old-value new-value] [s old-value new-value]
(string/replace s (re-pattern (str "(?i)" (escape-regex-chars old-value))) new-value)) (string/replace s (re-pattern (str "(?i)" (escape-regex-chars old-value))) new-value))
(defn replace-first-ignore-case
[s old-value new-value]
(string/replace-first s (re-pattern (str "(?i)" (escape-regex-chars old-value))) new-value))
(defn sort-coll-by-dependency (defn sort-coll-by-dependency
"Sort the elements in the collection based on dependencies. "Sort the elements in the collection based on dependencies.
coll: [{:id 1 :depend-on 2} {:id 2 :depend-on 3} {:id 3}] coll: [{:id 1 :depend-on 2} {:id 2 :depend-on 3} {:id 3}]

View File

@@ -8,10 +8,6 @@
(str left-parens right-parens)) (str left-parens right-parens))
(def block-ref-re #"\(\(([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})\)\)") (def block-ref-re #"\(\(([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})\)\)")
(defn get-all-block-ref-ids
[content]
(map second (re-seq block-ref-re content)))
(defn get-block-ref-id (defn get-block-ref-id
"Extracts block id from block-ref using regex" "Extracts block id from block-ref using regex"
[s] [s]

View File

@@ -4,19 +4,12 @@
(def left-braces "Opening characters for macro" "{{") (def left-braces "Opening characters for macro" "{{")
(def right-braces "Closing characters for macro" "}}") (def right-braces "Closing characters for macro" "}}")
(def query-macro (str left-braces "query"))
(defn macro? (defn macro?
[*s] [*s]
(when-let [s (and (string? *s) (string/trim *s))] (when-let [s (and (string? *s) (string/trim *s))]
(and (string/starts-with? s left-braces) (string/ends-with? s right-braces)))) (and (string/starts-with? s left-braces) (string/ends-with? s right-braces))))
(defn query-macro?
[s]
(and (string? s)
(string/includes? s (str query-macro " "))
(not (string/includes? s (str "`" query-macro)))))
(defn macro-subs (defn macro-subs
[macro-content arguments] [macro-content arguments]
(loop [s macro-content (loop [s macro-content

View File

@@ -12,21 +12,6 @@
(is (= ["some-song" ""] (path/split-ext "some-song"))) (is (= ["some-song" ""] (path/split-ext "some-song")))
(is (= ["some-file.edn" "txt"] (path/split-ext "some-file.edn.txt")))) (is (= ["some-file.edn" "txt"] (path/split-ext "some-file.edn.txt"))))
(deftest safe-file-name?
(testing "safe-file-name"
(is (path/safe-filename? "foo"))
(is (path/safe-filename? "foo bar"))
(is (path/safe-filename? "foo-bar"))
(is (path/safe-filename? "foo_bar"))
(is (path/safe-filename? "foo.bar"))
(is (path/safe-filename? "foo..bar"))
(is (path/safe-filename? "foo...bar"))
(is (not (path/safe-filename? "foo/bar")))
(is (not (path/safe-filename? "foo?bar")))
(is (not (path/safe-filename? "foo<bar")))
(is (not (path/safe-filename? "foo>bar")))))
(deftest path-join (deftest path-join
(testing "path-join" (testing "path-join"
(is (= "foo/bar" (path/path-join "foo" "bar"))) (is (= "foo/bar" (path/path-join "foo" "bar")))

View File

@@ -3,15 +3,11 @@ logseq.graph-parser.mldoc/ast-export-markdown
;; API ;; API
logseq.graph-parser.mldoc/block-with-title? logseq.graph-parser.mldoc/block-with-title?
;; API ;; API
logseq.graph-parser.mldoc/link?
;; API
logseq.graph-parser.mldoc/->db-edn logseq.graph-parser.mldoc/->db-edn
;; API ;; API
logseq.graph-parser.text/get-file-basename logseq.graph-parser.text/get-file-basename
;; API ;; API
logseq.graph-parser.mldoc/mldoc-link? logseq.graph-parser.mldoc/mldoc-link?
;; public var
logseq.graph-parser.schema.mldoc/block-ast-coll-schema
;; API ;; API
logseq.graph-parser.text/get-page-name logseq.graph-parser.text/get-page-name
logseq.graph-parser.text/get-namespace-last-part logseq.graph-parser.text/get-namespace-last-part

View File

@@ -201,12 +201,6 @@
;; 3. local asset link ;; 3. local asset link
(boolean (common-config/local-relative-asset? ref-value)))))))) (boolean (common-config/local-relative-asset? ref-value))))))))
(defn link?
[format link]
(when (string? link)
(some-> (first (inline->edn link (default-config format)))
ast-link?)))
(defn mldoc-link? (defn mldoc-link?
"Check whether s is a link (including page/block refs)." "Check whether s is a link (including page/block refs)."
[format s] [format s]

View File

@@ -215,6 +215,3 @@
(def block-ast-with-pos-coll-schema (def block-ast-with-pos-coll-schema
[:sequential [:cat block-ast-schema [:maybe pos-schema]]]) [:sequential [:cat block-ast-schema [:maybe pos-schema]]])
(def block-ast-coll-schema
[:sequential block-ast-schema])

View File

@@ -3,42 +3,6 @@
[logseq.graph-parser.mldoc :as gp-mldoc] [logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.text :as text])) [logseq.graph-parser.text :as text]))
(deftest test-link
(testing "non-link"
(are [x y] (= (gp-mldoc/link? :markdown x) y)
"google.com" false))
(testing "plain links"
(are [x y] (= (gp-mldoc/link? :markdown x) y)
"http://www.google.com" true
"http://google.com" true))
(testing "org links with labels"
(are [x y] (= (gp-mldoc/link? :org x) y)
"[[http://www.google.com][google]]" true
"[[http://google.com][google]]" true
"[[https://www.google.com][google]]" true
"[[https://google.com][google]]" true))
(testing "org links without labels"
(are [x y] (= (gp-mldoc/link? :org x) y)
"[[http://www.google.com]]" true
"[[https://www.google.com]]" true
"[[draws/2022-03-06-15-00-28.excalidraw]]" true
"[[assets/2022-03-06-15-00-28.pdf]]" true))
(testing "markdown links"
(are [x y] (= (gp-mldoc/link? :markdown x) y)
"[google](http://www.google.com)" true
"[google](https://www.google.com)" true
"[[draws/2022-03-06-15-00-28.excalidraw]]" true
"![a pdf](assets/2022-03-06-15-00-28.pdf)" true))
;; https://github.com/logseq/logseq/issues/4308
(testing "parsing links should be finished"
(are [x y] (= (gp-mldoc/link? :markdown x) y)
"[YouTube](https://www.youtube.com/watch?v=-8ym7pyUs9gL) - [Vimeo](https://vimeo.com/677920303) {{youtube https://www.youtube.com/watch?v=-8ym7pyUs9g}}" true)))
(def md-config (gp-mldoc/default-config :markdown)) (def md-config (gp-mldoc/default-config :markdown))
(deftest src-test (deftest src-test

View File

@@ -2,7 +2,6 @@
"Used to generate kondo config from malli-schema" "Used to generate kondo config from malli-schema"
(:require-macros [gen-malli-kondo-config.collect :refer [collect-schema]]) (:require-macros [gen-malli-kondo-config.collect :refer [collect-schema]])
(:require [frontend.util] (:require [frontend.util]
[frontend.util.list]
[malli.clj-kondo :as mc] [malli.clj-kondo :as mc]
[malli.instrument])) [malli.instrument]))

View File

@@ -105,47 +105,6 @@
(def media-formats (set/union (common-config/img-formats) audio-formats video-formats)) (def media-formats (set/union (common-config/img-formats) audio-formats video-formats))
(defn extname-of-supported?
([input] (extname-of-supported?
input
[image-formats doc-formats audio-formats
video-formats markup-formats
(common-config/text-formats)]))
([input formats]
(when-let [input (some->
(cond-> input
(and (string? input)
(not (string/blank? input)))
(string/replace-first "." ""))
(util/safe-lower-case)
(keyword))]
(boolean
(some
(fn [s]
(contains? s input))
formats)))))
(defn ext-of-video?
([s] (ext-of-video? s true))
([s html5?]
(when-let [s (and (string? s) (util/get-file-ext s))]
(let [video-formats' (cond-> video-formats
html5? (disj :mkv))]
(extname-of-supported? s [video-formats'])))))
(defn ext-of-audio?
([s] (ext-of-audio? s true))
([s html5?]
(when-let [s (and (string? s) (util/get-file-ext s))]
(let [audio-formats' (cond-> audio-formats
html5? (disj :wma :ogg))]
(extname-of-supported? s [audio-formats'])))))
(defn ext-of-image?
[s]
(when-let [s (and (string? s) (util/get-file-ext s))]
(extname-of-supported? s [image-formats])))
(def mobile? (def mobile?
"Triggering condition: Mobile phones "Triggering condition: Mobile phones
*** Warning!!! *** *** Warning!!! ***

View File

@@ -87,14 +87,6 @@
:minute "2-digit" :minute "2-digit"
:hourCycle "h23"})))) :hourCycle "h23"}))))
(defn normalize-date
[s]
(common-date/normalize-date s (state/get-date-formatter)))
(defn normalize-journal-title
[title]
(common-date/normalize-journal-title title (state/get-date-formatter)))
(defn valid-journal-title? (defn valid-journal-title?
[title] [title]
(common-date/valid-journal-title? title (state/get-date-formatter))) (common-date/valid-journal-title? title (state/get-date-formatter)))

View File

@@ -14,7 +14,6 @@
(import-vars (import-vars
[frontend.db.conn [frontend.db.conn
;; TODO: remove later ;; TODO: remove later
get-repo-path
get-repo-name get-repo-name
get-short-repo-name get-short-repo-name
get-db get-db
@@ -24,13 +23,12 @@
entity pull pull-many] entity pull pull-many]
[frontend.db.model [frontend.db.model
delete-files get-block-and-children get-block-by-uuid sort-by-order get-block-and-children get-block-by-uuid sort-by-order
get-block-parent get-block-parents parents-collapsed? get-block-parent get-block-parents
get-block-immediate-children get-block-page get-block-immediate-children get-file
get-file file-exists? get-files-full get-latest-journals get-page get-case-page
get-latest-journals get-page get-case-page get-page-alias-names
get-page-format journal-page? page? sub-block get-page-format journal-page? page? sub-block
page-empty? page-exists? get-alias-source-page page-exists? get-alias-source-page
has-children? whiteboard-page?]) has-children? whiteboard-page?])
(defn start-db-conn! (defn start-db-conn!

View File

@@ -26,23 +26,6 @@
(when-let [db (conn/get-db repo)] (when-let [db (conn/get-db repo)]
(ldb/get-alias-source-page db alias-id))) (ldb/get-alias-source-page db alias-id)))
(defn file-exists?
[repo path]
(when (and repo path)
(when-let [db (conn/get-db repo)]
(db-utils/entity db [:file/path path]))))
(defn get-files-full
[repo]
(when-let [db (conn/get-db repo)]
(->>
(d/q
'[:find (pull ?file [*])
:where
[?file :file/path]]
db)
(flatten))))
(defn get-file (defn get-file
([path] ([path]
(get-file (state/get-current-repo) path)) (get-file (state/get-current-repo) path))
@@ -109,13 +92,6 @@ independent of format as format specific heading characters are stripped"
[repo-url page-id] [repo-url page-id]
(ldb/page-alias-set (conn/get-db repo-url) page-id)) (ldb/page-alias-set (conn/get-db repo-url) page-id))
(defn get-page-alias-names
[repo page-id]
(let [alias-ids (->> (page-alias-set repo page-id)
(remove #{page-id}))]
(when (seq alias-ids)
(map (fn [id] (:block/title (db-utils/entity id))) alias-ids))))
(defn with-pages (defn with-pages
[blocks] [blocks]
(let [pages-ids (->> (map (comp :db/id :block/page) blocks) (let [pages-ids (->> (map (comp :db/id :block/page) blocks)
@@ -255,13 +231,6 @@ independent of format as format specific heading characters are stripped"
(when-let [db (conn/get-db repo)] (when-let [db (conn/get-db repo)]
(ldb/page-exists? db page-name tags)))) (ldb/page-exists? db page-name tags))))
(defn page-empty?
"Whether a page is empty. Does it has a non-page block?
`page-id` could be either a string or a db/id."
[repo page-id]
(when-let [db (conn/get-db repo)]
(ldb/page-empty? db page-id)))
(defn parents-collapsed? (defn parents-collapsed?
[repo block-uuid] [repo block-uuid]
(when-let [block (:block/parent (get-block-parents-v2 repo block-uuid))] (when-let [block (:block/parent (get-block-parents-v2 repo block-uuid))]
@@ -313,36 +282,12 @@ independent of format as format specific heading characters are stripped"
(when-let [db (conn/get-db repo)] (when-let [db (conn/get-db repo)]
(graph-view/get-pages-that-mentioned-page db page-id include-journals?))) (graph-view/get-pages-that-mentioned-page db page-id include-journals?)))
(defn get-referenced-blocks
([eid]
(get-referenced-blocks (state/get-current-repo) eid))
([repo eid]
(when repo
(when (conn/get-db repo)
(let [entity (db-utils/entity eid)
ids (page-alias-set repo eid)
entities (mapcat (fn [id]
(:block/_refs (db-utils/entity id))) ids)]
(->> entities
(remove (fn [block]
(or
(= (:db/id block) eid)
(= eid (:db/id (:block/page block)))
(ldb/hidden? (:block/page block))
(contains? (set (map :db/id (:block/tags block))) (:db/id entity))
(some? (get block (:db/ident entity))))))
(util/distinct-by :db/id)))))))
(defn journal-page? (defn journal-page?
"sanitized page-name only" "sanitized page-name only"
[page-name] [page-name]
(when (string? page-name) (when (string? page-name)
(ldb/journal? (ldb/get-page (conn/get-db) page-name)))) (ldb/journal? (ldb/get-page (conn/get-db) page-name))))
(defn delete-files
[files]
(mapv (fn [path] [:db.fn/retractEntity [:file/path path]]) files))
(defn whiteboard-page? (defn whiteboard-page?
"Given a page entity, page object or page name, check if it is a whiteboard page" "Given a page entity, page object or page name, check if it is a whiteboard page"
[page] [page]

View File

@@ -2,12 +2,10 @@
"Block code needed by app but not graph-parser. This should be the only frontend "Block code needed by app but not graph-parser. This should be the only frontend
namespace that has references to legacy file attributes like :block/pre-block? namespace that has references to legacy file attributes like :block/pre-block?
as they are being removed from graph-parser output" as they are being removed from graph-parser output"
(:require [cljs-time.format :as tf] (:require [cljs.cache :as cache]
[cljs.cache :as cache]
[clojure.string :as string] [clojure.string :as string]
[frontend.common.cache :as common.cache] [frontend.common.cache :as common.cache]
[frontend.config :as config] [frontend.config :as config]
[frontend.date :as date]
[frontend.db :as db] [frontend.db :as db]
[frontend.format :as format] [frontend.format :as format]
[frontend.format.mldoc :as mldoc] [frontend.format.mldoc :as mldoc]
@@ -45,33 +43,6 @@ and handles unexpected failure."
(notification/show! "An unexpected error occurred during block extraction." :error) (notification/show! "An unexpected error occurred during block extraction." :error)
[])))) []))))
(defn- normalize-as-percentage
[block]
(some->> block
str
(re-matches #"(-?\d+\.?\d*)%")
second
(#(/ % 100))))
(defn- normalize-as-date
[block]
(some->> block
str
date/normalize-date
(tf/unparse date/custom-formatter)))
(defn normalize-block
"Normalizes supported formats such as dates and percentages.
Be careful, this function may harm query sort performance!
- nlp-date? - Enable NLP parsing on date items.
Requires heavy computation (see `normalize-as-date` for details)"
[block nlp-date?]
(->> [normalize-as-percentage (when nlp-date? normalize-as-date) identity]
(remove nil?)
(map #(% (if (set? block) (first block) block)))
(remove nil?)
(first)))
(defn parse-block (defn parse-block
[{:block/keys [uuid title format] :as block}] [{:block/keys [uuid title format] :as block}]
(when-not (string/blank? title) (when-not (string/blank? title)

View File

@@ -194,10 +194,6 @@
(p/do! (p/do!
(.setStyle StatusBar (clj->js {:style (.-Dark Style)}))))) (.setStyle StatusBar (clj->js {:style (.-Dark Style)})))))
(defn find-first
[pred coll]
(first (filter pred coll)))
(defn find-index (defn find-index
"Find first index of an element in list" "Find first index of an element in list"
[pred-or-val coll] [pred-or-val coll]
@@ -368,22 +364,6 @@
last-newline-content (subs s (inc before-last-newline-length) from-newline-index)] last-newline-content (subs s (inc before-last-newline-length) from-newline-index)]
(.countGraphemes splitter last-newline-content)))) (.countGraphemes splitter last-newline-content))))
#?(:cljs
(defn get-text-range
"Return the substring of the first grapheme-num characters of s if first-line? is true,
otherwise return the substring of s before the last \n and the first grapheme-num characters.
grapheme-num treats multi-char as 1, like emoji characters"
[s grapheme-num first-line?]
(let [newline-pos (if first-line?
0
(inc (or (string/last-index-of s \newline) -1)))
^js splitter (GraphemeSplitter.)
^js newline-graphemes (.splitGraphemes splitter (subs s newline-pos))
^js newline-graphemes (.slice newline-graphemes 0 grapheme-num)
content (.join newline-graphemes "")]
(subs s 0 (+ newline-pos (count content))))))
#?(:cljs #?(:cljs
(defn stop [e] (defn stop [e]
(when e (doto e (.preventDefault) (.stopPropagation))))) (when e (doto e (.preventDefault) (.stopPropagation)))))
@@ -1011,18 +991,6 @@
{:result ret# {:result ret#
:time (- (cljs.core/system-time) start#)}))) :time (- (cljs.core/system-time) start#)})))
;; TODO: profile and profileEnd
(comment
(= (get-relative-path "journals/2020_11_18.org" "pages/grant_ideas.org")
"../pages/grant_ideas.org")
(= (get-relative-path "journals/2020_11_18.org" "journals/2020_11_19.org")
"./2020_11_19.org")
(= (get-relative-path "a/b/c/d/g.org" "a/b/c/e/f.org")
"../e/f.org"))
(defn keyname [key] (str (namespace key) "/" (name key))) (defn keyname [key] (str (namespace key) "/" (name key)))
#?(:cljs #?(:cljs

View File

@@ -1,29 +0,0 @@
(ns frontend.util.list
"High level list operations for use in editor"
(:require [clojure.string :as string]))
(defn- newline?
[line]
(or (= line "\n") (= line "\r\n")))
(defn re-order-items
[lines start-idx]
(loop [lines lines
idx start-idx
result []
double-newlines? false]
(let [[line & others] lines]
(if (empty? lines)
(->> result
(map (fn [line] (if (newline? line) "" line)))
(string/join "\n"))
(let [[_ num-str] (re-find #"^(\d+){1}\." line)
num (if num-str (parse-long num-str) nil)
double-newlines?' (or double-newlines?
(and (newline? line) (seq others) (newline? (first others))))
[idx' result'] (if (and (not double-newlines?') num)
(let [idx' (inc idx)
line' (string/replace-first line (str num ".") (str idx' "."))]
[idx' (conj result line')])
[idx (conj result line)])]
(recur others idx' result' double-newlines?'))))))

View File

@@ -1,5 +1,5 @@
(ns frontend.db.model-test (ns frontend.db.model-test
(:require [cljs.test :refer [use-fixtures deftest is are]] (:require [cljs.test :refer [use-fixtures deftest is]]
[datascript.core :as d] [datascript.core :as d]
[frontend.db :as db] [frontend.db :as db]
[frontend.db.conn :as conn] [frontend.db.conn :as conn]
@@ -11,38 +11,6 @@
(def test-db test-helper/test-db) (def test-db test-helper/test-db)
(deftest test-page-alias-with-multiple-alias
(let [ab-uuid (random-uuid)
aa-uuid (random-uuid)]
(load-test-files
[{:page {:block/title "ab"
:build/keep-uuid? true
:block/uuid ab-uuid
:build/properties {:block/alias #{[:block/uuid aa-uuid]
[:build/page {:block/title "ad"}]}}}}
{:page {:block/title "aa"
:build/keep-uuid? true
:block/uuid aa-uuid
:build/properties {:block/alias #{[:block/uuid ab-uuid]
[:build/page {:block/title "ac"}]}}}}
{:page {:block/title "ae"}
:blocks [{:block/title (str "## ref to [[" ab-uuid "]]")}]}]))
(let [aid (:db/id (test-helper/find-page-by-title "aa"))
bid (:db/id (test-helper/find-page-by-title "ab"))
a-aliases (model/page-alias-set test-db aid)
b-aliases (model/page-alias-set test-db bid)
alias-names (model/get-page-alias-names test-db aid)
b-ref-blocks (model/get-referenced-blocks bid)
a-ref-blocks (model/get-referenced-blocks aid)]
(are [x y] (= x y)
4 (count a-aliases)
4 (count b-aliases)
1 (count b-ref-blocks)
1 (count a-ref-blocks)
#{"ab" "ac" "ad"} (set alias-names))))
(deftest test-page-alias-set (deftest test-page-alias-set
(let [ab-uuid (random-uuid)] (let [ab-uuid (random-uuid)]
(load-test-files (load-test-files
@@ -56,13 +24,8 @@
:blocks [{:block/title (str "## ref to [[" ab-uuid "]]")}]}])) :blocks [{:block/title (str "## ref to [[" ab-uuid "]]")}]}]))
(let [page-id (:db/id (test-helper/find-page-by-title "aa")) (let [page-id (:db/id (test-helper/find-page-by-title "aa"))
a-aliases (model/page-alias-set test-db page-id) a-aliases (model/page-alias-set test-db page-id)]
alias-names (model/get-page-alias-names test-db page-id) (is (= 3 (count a-aliases)))))
a-ref-blocks (model/get-referenced-blocks page-id)]
(are [x y] (= x y)
3 (count a-aliases)
1 (count a-ref-blocks)
#{"ab" "ac"} (set alias-names))))
(defn- page-mention-check? (defn- page-mention-check?
[page-name include-journals?] [page-name include-journals?]

View File

@@ -1,117 +0,0 @@
(ns frontend.format.block-test
(:require [cljs.test :refer [deftest testing are]]
[frontend.format.block :as block]
[frontend.date :as date]
[frontend.util :as util]))
(deftest test-normalize-date
(testing "normalize date values"
(are [x y] (= (block/normalize-block x true) y)
"Aug 12th, 2022"
"2022-08-12T00:00:00Z"
"2022-08-12T00:00:00Z"
"2022-08-12T00:00:00Z"
#{"Aug 12th, 2022"}
"2022-08-12T00:00:00Z"
#{"2022-08-12T00:00:00Z"}
"2022-08-12T00:00:00Z")))
(deftest monitor-normalize-date-time
(testing "monitor time consumption of normalize date values"
(are [x _y timeout] (>= timeout (:time (util/with-time (block/normalize-block x true))))
"Aug 12th, 2022"
"2022-08-12T00:00:00Z"
50.0 ;; actual 2.2
"2022-08-12T00:00:00Z"
"2022-08-12T00:00:00Z"
1000.0 ;; actual 125
#{"Aug 12th, 2022"}
"2022-08-12T00:00:00Z"
50.0 ;; actual 1.7
#{"2022-08-12T00:00:00Z"}
"2022-08-12T00:00:00Z"
250.0 ;; actual 17.0
)))
(deftest test-normalize-percentage
(testing "normalize percentages"
(are [x y] (= (block/normalize-block x false) y)
"50%"
0.5
"0%"
0
"-5%"
-0.05
#{"50%"}
0.5)))
(deftest test-normalize-random-values
(testing "random values should not be processed"
(are [x y] (= (block/normalize-block x false) y)
"anreanre"
"anreanre"
""
""
"a.0%"
"a.0%"
"%"
"%"
"-%"
"-%")))
(deftest monitor-normalize-randome-values-time
(testing "monitor time consumption of random values should not be processed"
(are [x _y timeout] (>= timeout (:time (util/with-time (block/normalize-block x false))))
"anreanre"
"anreanre"
2.0 ;; actual 0.07
""
""
2.0 ;; actual 0.07
"a.0%"
"a.0%"
0.5 ;; actual 0.02
"%"
"%"
1.0 ;; actual 0.03
"-%"
"-%"
0.5 ;; actual 0.02
)))
(deftest test-normalize-journal-title
(testing "normalize journal titles"
(are [x y] (let [f #(-> % date/normalize-journal-title str)]
(= (f x) y))
"Aug 12th, 2022"
"20220812T000000"
"2022-08-12"
"20220812T000000"
"2022-10"
""
"2022Q4"
""
"2022-08"
"")))

View File

@@ -1,30 +0,0 @@
(ns frontend.util.list-test
(:require [cljs.test :refer [deftest is testing]]
[frontend.util.list :as list-util]))
(deftest test-re-order-items
(testing "Single list"
(is (= (list-util/re-order-items
["2. x"
"3. x"]
2)
"3. x\n4. x"))
(is (= (list-util/re-order-items
["7. x"
"foo"
"bar 3."
"5. x"
"baz"]
2)
"3. x\nfoo\nbar 3.\n4. x\nbaz")))
(testing "Only reorder the first list"
(is (= (list-util/re-order-items
["7. x"
"foo"
"\n"
"\n"
"bar 3."
"5. x"
"baz"]
2)
"3. x\nfoo\n\n\nbar 3.\n5. x\nbaz"))))

View File

@@ -1,11 +1,6 @@
(ns frontend.util-test (ns frontend.util-test
(:require [cljs.test :refer [deftest is testing]] (:require [cljs.test :refer [deftest is testing]]
[frontend.util :as util] [frontend.util :as util]))
[frontend.config :as config]))
(deftest test-find-first
(testing "find-first"
(is (= 1 (util/find-first identity [1])))))
(deftest test-delete-emoji-current-pos (deftest test-delete-emoji-current-pos
(testing "safe current position from end for emoji" (testing "safe current position from end for emoji"
@@ -39,24 +34,6 @@
(is (= 1 (util/get-line-pos "abc\n😀d\ne" 6))) (is (= 1 (util/get-line-pos "abc\n😀d\ne" 6)))
(is (= 2 (util/get-line-pos "ab\nc😀d\ne" 6))))) (is (= 2 (util/get-line-pos "ab\nc😀d\ne" 6)))))
(deftest test-get-text-range
(testing "get-text-range"
(is (= "" (util/get-text-range "abcdefg" 0 true)))
(is (= "" (util/get-text-range "abcdefg" 0 false)))
(is (= "abcdefg" (util/get-text-range "abcdefg" 10 true)))
(is (= "abcdefg" (util/get-text-range "abcdefg" 10 false)))
(is (= "abc" (util/get-text-range "abcdefg" 3 true)))
(is (= "abc" (util/get-text-range "abcdefg" 3 false)))
(is (= "abc" (util/get-text-range "abcdefg\nhijklmn" 3 true)))
(is (= "abcdefg\nhij" (util/get-text-range "abcdefg\nhijklmn" 3 false)))
(is (= "abcdefg\nhijklmn" (util/get-text-range "abcdefg\nhijklmn" 10 false)))
(is (= "abcdefg\nhijklmn\nopq" (util/get-text-range "abcdefg\nhijklmn\nopqrst" 3 false)))
(is (= "a😀b" (util/get-text-range "a😀bcdefg" 3 true)))
(is (= "a😀b" (util/get-text-range "a😀bcdefg" 3 false)))
(is (= "a😀b" (util/get-text-range "a😀bcdefg\nhijklmn" 3 true)))
(is (= "a😀bcdefg\nhij" (util/get-text-range "a😀bcdefg\nhijklmn" 3 false)))
(is (= "a😀bcdefg\nh😀i" (util/get-text-range "a😀bcdefg\nh😀ijklmn" 3 false)))))
(deftest test-memoize-last (deftest test-memoize-last
(testing "memoize-last add test" (testing "memoize-last add test"
(let [actual-ops (atom 0) (let [actual-ops (atom 0)
@@ -75,17 +52,4 @@
(is (= (m+ 3 5) 8)) (is (= (m+ 3 5) 8))
(is (= @actual-ops 4)) (is (= @actual-ops 4))
(is (= (m+ 3 5) 8)) (is (= (m+ 3 5) 8))
(is (= @actual-ops 4))))) (is (= @actual-ops 4)))))
(deftest test-media-format-from-input
(testing "predicate file type from ext (html5 supported)"
(is (= (config/ext-of-audio? "file.mp3") true))
(is (= (config/ext-of-audio? "fIle.mP3") true))
(is (= (config/ext-of-audio? "https://x.com/file.mp3") true))
(is (= (config/ext-of-audio? "file.wma") false))
(is (= (config/ext-of-audio? "file.wma" false) true))
(is (= (config/ext-of-video? "file.mp4") true))
(is (= (config/ext-of-video? "file.mp3") false))
(is (= (config/ext-of-image? "file.svg") true))
(is (= (config/ext-of-image? "a.file.png") true))
(is (= (config/ext-of-image? "file.tiff") false))))