mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
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:
@@ -105,47 +105,6 @@
|
||||
|
||||
(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?
|
||||
"Triggering condition: Mobile phones
|
||||
*** Warning!!! ***
|
||||
|
||||
@@ -87,14 +87,6 @@
|
||||
:minute "2-digit"
|
||||
: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?
|
||||
[title]
|
||||
(common-date/valid-journal-title? title (state/get-date-formatter)))
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
(import-vars
|
||||
[frontend.db.conn
|
||||
;; TODO: remove later
|
||||
get-repo-path
|
||||
get-repo-name
|
||||
get-short-repo-name
|
||||
get-db
|
||||
@@ -24,13 +23,12 @@
|
||||
entity pull pull-many]
|
||||
|
||||
[frontend.db.model
|
||||
delete-files get-block-and-children get-block-by-uuid sort-by-order
|
||||
get-block-parent get-block-parents parents-collapsed?
|
||||
get-block-immediate-children get-block-page
|
||||
get-file file-exists? get-files-full
|
||||
get-latest-journals get-page get-case-page get-page-alias-names
|
||||
get-block-and-children get-block-by-uuid sort-by-order
|
||||
get-block-parent get-block-parents
|
||||
get-block-immediate-children get-file
|
||||
get-latest-journals get-page get-case-page
|
||||
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?])
|
||||
|
||||
(defn start-db-conn!
|
||||
|
||||
@@ -26,23 +26,6 @@
|
||||
(when-let [db (conn/get-db repo)]
|
||||
(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
|
||||
([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]
|
||||
(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
|
||||
[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)]
|
||||
(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?
|
||||
[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)]
|
||||
(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?
|
||||
"sanitized page-name only"
|
||||
[page-name]
|
||||
(when (string? 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?
|
||||
"Given a page entity, page object or page name, check if it is a whiteboard page"
|
||||
[page]
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
"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?
|
||||
as they are being removed from graph-parser output"
|
||||
(:require [cljs-time.format :as tf]
|
||||
[cljs.cache :as cache]
|
||||
(:require [cljs.cache :as cache]
|
||||
[clojure.string :as string]
|
||||
[frontend.common.cache :as common.cache]
|
||||
[frontend.config :as config]
|
||||
[frontend.date :as date]
|
||||
[frontend.db :as db]
|
||||
[frontend.format :as format]
|
||||
[frontend.format.mldoc :as mldoc]
|
||||
@@ -45,33 +43,6 @@ and handles unexpected failure."
|
||||
(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
|
||||
[{:block/keys [uuid title format] :as block}]
|
||||
(when-not (string/blank? title)
|
||||
|
||||
@@ -194,10 +194,6 @@
|
||||
(p/do!
|
||||
(.setStyle StatusBar (clj->js {:style (.-Dark Style)})))))
|
||||
|
||||
(defn find-first
|
||||
[pred coll]
|
||||
(first (filter pred coll)))
|
||||
|
||||
(defn find-index
|
||||
"Find first index of an element in list"
|
||||
[pred-or-val coll]
|
||||
@@ -368,22 +364,6 @@
|
||||
last-newline-content (subs s (inc before-last-newline-length) from-newline-index)]
|
||||
(.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
|
||||
(defn stop [e]
|
||||
(when e (doto e (.preventDefault) (.stopPropagation)))))
|
||||
@@ -1011,18 +991,6 @@
|
||||
{:result ret#
|
||||
: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)))
|
||||
|
||||
#?(:cljs
|
||||
|
||||
@@ -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?'))))))
|
||||
Reference in New Issue
Block a user