more cleanup

This commit is contained in:
Tienson Qin
2025-12-26 11:39:23 +08:00
parent f1de1ea163
commit ec7a325bcb
45 changed files with 119 additions and 1164 deletions

View File

@@ -94,32 +94,6 @@
(some-> (resolve-asset-real-path-url (state/get-current-repo) path)
(common-util/safe-decode-uri-component)))))
(defn get-matched-alias-by-ext
[ext]
(when-let [ext (and (alias-enabled?)
(string? ext)
(not (string/blank? ext))
(util/safe-lower-case ext))]
(let [alias (medley/find-first
(fn [{:keys [exts]}]
(some #(string/ends-with? ext %) exts))
(get-alias-dirs))]
alias)))
(defn get-asset-file-link
"Link text for inserting to markdown/org"
[format url file-name image?]
(let [pdf? (and url (string/ends-with? (string/lower-case url) ".pdf"))
media? (and url (or (config/ext-of-audio? url)
(config/ext-of-video? url)))]
(case (keyword format)
:markdown (util/format (str (when (or image? media? pdf?) "!") "[%s](%s)") file-name url)
:org (if image?
(util/format "[[%s]]" url)
(util/format "[[%s][%s]]" url file-name))
nil)))
(defn <make-data-url
[path]
(let [repo-dir (config/get-repo-dir (state/get-current-repo))]

View File

@@ -1,6 +1,5 @@
(ns ^:no-doc frontend.handler.block
(:require [clojure.string :as string]
[clojure.walk :as walk]
[datascript.impl.entity :as de]
[dommy.core :as dom]
[frontend.config :as config]
@@ -15,41 +14,12 @@
[frontend.util :as util]
[goog.object :as gobj]
[logseq.db :as ldb]
[logseq.graph-parser.block :as gp-block]
[logseq.outliner.core :as outliner-core]
[logseq.outliner.op]
[promesa.core :as p]))
;; Fns
;; TODO: reduced version
(defn- walk-block
[block check? transform]
(let [result (atom nil)]
(walk/postwalk
(fn [x]
(if (check? x)
(reset! result (transform x))
x))
(:block.temp/ast-body block))
@result))
(defn get-timestamp
[block typ]
(walk-block block
(fn [x]
(and (gp-block/timestamp-block? x)
(= typ (first (second x)))))
#(second (second %))))
(defn get-scheduled-ast
[block]
(get-timestamp block "Scheduled"))
(defn get-deadline-ast
[block]
(get-timestamp block "Deadline"))
(defn select-block!
[block-uuid]
(let [blocks (util/get-blocks-by-id block-uuid)]

View File

@@ -2,7 +2,6 @@
"Handles DB graph exports and imports across graphs"
(:require [cljs.pprint :as pprint]
[clojure.string :as string]
[frontend.config :as config]
[frontend.handler.notification :as notification]
[frontend.state :as state]
[frontend.util :as util]

View File

@@ -145,7 +145,7 @@
(defn <get-remote-graphs
[]
(->
(p/let [_ (state/set-state! [:file-sync/remote-graphs :loading] true)
(p/let [_ (state/set-state! :rtc/loading-graphs? true)
_ (js/Promise. user-handler/task--ensure-id&access-token)
token (state/get-auth-id-token)
graphs (state/<invoke-db-worker :thread-api/rtc-get-graphs token)
@@ -164,7 +164,7 @@
(repo-handler/refresh-repos!))
(p/finally
(fn []
(state/set-state! [:file-sync/remote-graphs :loading] false)))))
(state/set-state! :rtc/loading-graphs? false)))))
(defn <rtc-invite-email
[graph-uuid email]

View File

@@ -58,7 +58,6 @@
[logseq.db.frontend.property :as db-property]
[logseq.graph-parser.block :as gp-block]
[logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.property :as gp-property]
[logseq.graph-parser.utf8 :as utf8]
[logseq.outliner.core :as outliner-core]
[logseq.outliner.property :as outliner-property]
@@ -848,37 +847,6 @@
(doseq [journal journals]
(outliner-op/delete-page! (:block/uuid journal)))))))))))
(defn set-block-timestamp!
[block-id key value]
(let [key (string/lower-case (str key))
block-id (if (string? block-id) (uuid block-id) block-id)
value (str value)]
(when-let [block (db/entity [:block/uuid block-id])]
(let [{:block/keys [title]} block
content (or title (state/get-edit-content))
new-content (-> (text-util/remove-timestamp content key)
(text-util/add-timestamp key value))]
(when (not= content new-content)
(let [input-id (state/get-edit-input-id)]
(if (and input-id
(string/ends-with? input-id (str block-id)))
(state/set-edit-content! input-id new-content)
(save-block-if-changed! block new-content))))))))
(defn set-editing-block-timestamp!
"Almost the same as set-block-timestamp! except for:
- it doesn't save the block
- it extracts current content from current input"
[key value]
(let [key (string/lower-case (str key))
value (str value)
content (state/get-edit-content)
new-content (-> (text-util/remove-timestamp content key)
(text-util/add-timestamp key value))]
(when (not= content new-content)
(let [input-id (state/get-edit-input-id)]
(state/set-edit-content! input-id new-content)))))
(defn copy-block-ref!
([block-id]
(copy-block-ref! block-id #(str %)))
@@ -1582,10 +1550,6 @@
[q]
(search/template-search q))
(defn <get-matched-properties
[q]
(search/property-search q))
(defn get-last-command
[input]
(try
@@ -2039,44 +2003,6 @@
(insert-template! element-id db-id
{:replace-empty-target? true}))))
(defn get-searching-property
[input]
(let [value (.-value input)
pos (util/get-selection-start input)
postfix (subs value pos)
end-index (when-let [idx (string/index-of postfix gp-property/colons)]
(+ (max 0 (count (subs value 0 pos))) idx))
start-index (or (when-let [p (string/last-index-of (subs value 0 pos) "\n")]
(inc p))
0)]
{:end-index end-index
:searching-property (when (and start-index end-index (>= end-index start-index))
(subs value start-index end-index))}))
(defn property-on-chosen-handler
[element-id q]
(fn [property]
(when-let [input (gdom/getElement element-id)]
(let [{:keys [end-index searching-property]} (get-searching-property input)]
(cursor/move-cursor-to input (+ end-index 2))
(commands/insert! element-id (str (or property q) gp-property/colons " ")
{:last-pattern (str searching-property gp-property/colons)})
(state/clear-editor-action!)
(js/setTimeout (fn []
(let [pos (let [input (gdom/getElement element-id)]
(cursor/get-caret-pos input))]
(state/set-editor-action-data! {:property (or property q)
:pos pos})
(state/set-editor-action! :property-value-search)))
50)))))
(defn property-value-on-chosen-handler
[element-id q]
(fn [property-value]
(commands/insert! element-id (str gp-property/colons " " (or property-value q))
{:last-pattern (str gp-property/colons " " q)})
(state/clear-editor-action!)))
(declare indent-outdent)
(defn- last-top-level-child?

View File

@@ -31,9 +31,10 @@
(cli-export-common/get-page-content page-uuid)))
;; Utils
(defn <get-all-pages
[repo]
(state/<invoke-db-worker :thread-api/export-get-all-pages repo))
(comment
(defn <get-all-pages
[repo]
(state/<invoke-db-worker :thread-api/export-get-all-pages repo)))
(defn <get-debug-datoms
[repo]
@@ -69,4 +70,4 @@
(def remove-page-ref-brackets cli-export-common/remove-page-ref-brackets)
(def remove-tags cli-export-common/remove-tags)
(def remove-prefix-spaces-in-Plain cli-export-common/remove-prefix-spaces-in-Plain)
(def walk-block-ast cli-export-common/walk-block-ast)
(def walk-block-ast cli-export-common/walk-block-ast)

View File

@@ -31,11 +31,6 @@
[]
(path/path-join @root-dir "config" "config.edn"))
(defn safe-global-config-path
"Fetch config path in a general context, not just for global config"
[]
(when @root-dir (global-config-path)))
(defn set-global-config-state!
[content]
(let [config (edn/read-string content)]

View File

@@ -7,50 +7,15 @@
[clojure.walk :as walk]
[frontend.db :as db]
[frontend.db.async :as db-async]
[frontend.format.block :as block]
[frontend.format.mldoc :as mldoc]
[frontend.handler.editor :as editor]
[frontend.handler.notification :as notification]
[frontend.handler.page :as page-handler]
[frontend.state :as state]
[frontend.util :as util]
[logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.whiteboard :as gp-whiteboard]
[medley.core :as medley]
[promesa.core :as p]))
;;; import OPML files
(defn import-from-opml!
[data finished-ok-handler]
#_:clj-kondo/ignore
(when-let [repo (state/get-current-repo)]
(let [config (gp-mldoc/default-config :markdown)
[headers parsed-blocks] (mldoc/opml->edn config data)
;; add empty pos metadata
parsed-blocks (map (fn [b] [b {}]) parsed-blocks)
page-name (:title headers)
parsed-blocks (->>
(block/extract-blocks parsed-blocks "" :markdown {:page-name page-name})
(mapv editor/wrap-parse-block))]
(p/do!
(when (not (db/page-exists? page-name))
(page-handler/<create! page-name {:redirect? false}))
(let [page-block (db/get-page page-name)
children (:block/_parent page-block)
blocks (db/sort-by-order children)
last-block (last blocks)
snd-last-block (last (butlast blocks))
[target-block sibling?] (if (and last-block (seq (:block/title last-block)))
[last-block true]
(if snd-last-block
[snd-last-block true]
[page-block false]))]
(editor/paste-blocks
parsed-blocks
{:target-block target-block
:sibling? sibling?})
(finished-ok-handler [page-name]))))))
(defn create-page-with-exported-tree!
"Create page from the per page object generated in `export-repo-as-edn-v2!`
Return page-name (title)

View File

@@ -276,7 +276,6 @@
;; We should implement an app-wide check rather than list them all here
(not (:graph/loading? @state/state))
(not (:graph/importing @state/state))
(not (state/loading-files? repo))
(not config/publishing?))
(when-let [title (date/today)]
(state/set-today! title)

View File

@@ -1,28 +1,15 @@
(ns frontend.handler.query.builder
"DSL query builder handler"
(:require [clojure.walk :as walk]
[logseq.common.util.page-ref :as page-ref]
[frontend.db.query-dsl :as query-dsl]
[lambdaisland.glogi :as log]
[frontend.db.query-dsl :as query-dsl]))
[logseq.common.util.page-ref :as page-ref]))
;; TODO: make it extensible for Datalog/SPARQL etc.
(def operators [:and :or :not])
(def operators-set (set operators))
(def page-filters ["all page tags"
"namespace"
"tags"
"property"
"sample"])
(def block-filters ["page reference"
"property"
"task"
"priority"
"page"
"full text search"
"between"
"sample"])
(def db-based-block-filters
["tags"
"page reference"

View File

@@ -1,8 +1,7 @@
(ns frontend.handler.repo
"System-component-like ns that manages user's repos/graphs"
(:refer-clojure :exclude [clone])
(:require [cljs-bean.core :as bean]
[clojure.string :as string]
(:require [clojure.string :as string]
[electron.ipc :as ipc]
[frontend.config :as config]
[frontend.date :as date]
@@ -22,7 +21,6 @@
[frontend.util :as util]
[frontend.util.text :as text-util]
[logseq.common.config :as common-config]
[logseq.db :as ldb]
[logseq.db.frontend.schema :as db-schema]
[promesa.core :as p]))
@@ -78,26 +76,14 @@
(defn get-repos
[]
(p/let [nfs-dbs (db-persist/get-all-graphs)
nfs-dbs (map (fn [db]
(let [graph-name (:name db)]
{:url graph-name
:metadata (:metadata db)
:root (config/get-local-dir graph-name)
:nfs? true}))
nfs-dbs)
nfs-dbs (and (seq nfs-dbs)
(cond (util/electron?)
(p/chain
(ipc/ipc :inflateGraphsInfo (ldb/write-transit-str nfs-dbs))
ldb/read-transit-str)
;(mobile-util/native-platform?)
;(util-fs/inflate-graphs-info nfs-dbs)
:else
nfs-dbs))]
(seq (bean/->clj nfs-dbs))))
(p/let [dbs (db-persist/get-all-graphs)]
(map (fn [db]
(let [graph-name (:name db)]
{:url graph-name
:metadata (:metadata db)
:root (config/get-local-dir graph-name)
:nfs? true}))
dbs)))
(defn combine-local-&-remote-graphs
[local-repos remote-repos]
@@ -126,23 +112,12 @@
(last (string/split (:root repo) #"/")))]
[(:remote? repo) (string/lower-case graph-name)])) repos''))))
(defn get-detail-graph-info
[url]
(when-let [graphs (seq (and url (combine-local-&-remote-graphs
(state/get-repos)
(state/get-remote-file-graphs))))]
(first (filter #(when-let [url' (:url %)]
(= url url')) graphs))))
(defn refresh-repos!
[]
(p/let [repos (get-repos)
repos' (combine-local-&-remote-graphs
repos
(concat
(state/get-rtc-graphs)
(when-not (or (util/mobile?) util/web-platform?)
(state/get-remote-file-graphs))))]
(state/get-rtc-graphs))]
(state/set-repos! repos')
repos'))

View File

@@ -50,10 +50,6 @@
[]
(redirect! {:to :graphs}))
(defn redirect-to-whiteboard-dashboard!
[]
(redirect! {:to :whiteboards}))
;; Named block links only works on web (and publishing)
(if util/web-platform?
(defn- default-page-route [page-name-or-block-uuid]

View File

@@ -11,7 +11,6 @@
[frontend.config :as config]
[frontend.debug :as debug]
[frontend.flows :as flows]
[frontend.handler.config :as config-handler]
[frontend.handler.notification :as notification]
[frontend.state :as state]
[goog.crypt :as crypt]
@@ -19,18 +18,6 @@
[goog.crypt.Sha256]
[missionary.core :as m]))
(defn set-preferred-format!
[format]
(when format
(config-handler/set-config! :preferred-format format)
(state/set-preferred-format! format)))
(defn set-preferred-workflow!
[workflow]
(when workflow
(config-handler/set-config! :preferred-workflow workflow)
(state/set-preferred-workflow! workflow)))
;;; userinfo, token, login/logout, ...
(defn- decode-username
@@ -210,11 +197,6 @@
;; refresh remote graph list by pub login event
(when (user-uuid) (state/pub-event! [:user/fetch-info-and-graphs]))))))
(defn has-refresh-token?
"Has refresh-token"
[]
(boolean (js/localStorage.getItem "refresh-token")))
(defn login-callback
[session]
(set-tokens!
@@ -289,13 +271,6 @@
(-> (state/get-auth-id-token) parse-jwt expired?))
(throw (ex-info "empty or expired token and refresh failed" {:type :expired-token})))))))
(defn <user-uuid
[]
(go
(if-some [exp (<! (<ensure-id&access-token))]
exp
(user-uuid))))
;;; user groups
(defn rtc-group?