mirror of https://github.com/logseq/logseq
fix: worker dependencies
parent
ab612a0a1b
commit
77726bda4c
|
@ -347,3 +347,16 @@
|
|||
https://github.com/logseq/logseq/pull/8679"
|
||||
[parts]
|
||||
(string/join "/" parts))
|
||||
|
||||
(def escape-chars "[]{}().+*?|$")
|
||||
|
||||
(defn escape-regex-chars
|
||||
"Escapes characters in string `old-value"
|
||||
[old-value]
|
||||
(reduce (fn [acc escape-char]
|
||||
(string/replace acc escape-char (str "\\" escape-char)))
|
||||
old-value escape-chars))
|
||||
|
||||
(defn replace-ignore-case
|
||||
[s old-value new-value]
|
||||
(string/replace s (re-pattern (str "(?i)" (escape-regex-chars old-value))) new-value))
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
[frontend.state :as state]
|
||||
[frontend.worker.handler.page :as worker-page]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.graph-parser.text :as text]
|
||||
[frontend.handler.ui :as ui-handler]
|
||||
[frontend.config :as config]
|
||||
[frontend.fs :as fs]
|
||||
|
@ -86,29 +85,7 @@
|
|||
|
||||
;; other fns
|
||||
;; =========
|
||||
(defn rename-update-namespace!
|
||||
"update :block/namespace of the renamed block"
|
||||
[page old-original-name new-name]
|
||||
(let [old-namespace? (text/namespace-page? old-original-name)
|
||||
new-namespace? (text/namespace-page? new-name)
|
||||
repo (state/get-current-repo)]
|
||||
(cond
|
||||
new-namespace?
|
||||
;; update namespace
|
||||
(let [namespace (first (common-util/split-last "/" new-name))]
|
||||
(when namespace
|
||||
(create! namespace {:redirect? false}) ;; create parent page if not exist, creation of namespace ref is handled in `create!`
|
||||
(let [namespace-block (db/pull [:block/name (common-util/page-name-sanity-lc namespace)])
|
||||
page-txs [{:db/id (:db/id page)
|
||||
:block/namespace (:db/id namespace-block)}]]
|
||||
(db/transact! repo page-txs))))
|
||||
|
||||
old-namespace?
|
||||
;; retract namespace
|
||||
(db/transact! [[:db/retract (:db/id page) :block/namespace]])
|
||||
|
||||
:else
|
||||
nil)))
|
||||
|
||||
(defn after-page-deleted!
|
||||
[repo page-name file-path]
|
||||
|
@ -116,7 +93,7 @@
|
|||
;; TODO: move favorite && unfavorite to worker too
|
||||
(unfavorite-page! page-name)
|
||||
|
||||
(when (= (common-util/page-name-sanity-lc (state/get-current-page))
|
||||
(when (= (some-> (state/get-current-page) common-util/page-name-sanity-lc)
|
||||
(common-util/page-name-sanity-lc page-name))
|
||||
(route-handler/redirect-to-home!))
|
||||
|
||||
|
@ -147,7 +124,7 @@
|
|||
old-page-name (common-util/page-name-sanity-lc old-name)
|
||||
new-page-name (common-util/page-name-sanity-lc new-name)
|
||||
page (db/entity [:block/name new-page-name])
|
||||
redirect? (= (common-util/page-name-sanity-lc (state/get-current-page))
|
||||
redirect? (= (some-> (state/get-current-page) common-util/page-name-sanity-lc)
|
||||
(common-util/page-name-sanity-lc old-page-name))]
|
||||
;; Redirect to the newly renamed page
|
||||
(when redirect?
|
||||
|
|
|
@ -641,18 +641,11 @@
|
|||
(str prefix new-value)))
|
||||
s)))
|
||||
|
||||
(def escape-chars "[]{}().+*?|$")
|
||||
#?(:cljs
|
||||
(def escape-regex-chars common-util/escape-regex-chars))
|
||||
|
||||
(defn escape-regex-chars
|
||||
"Escapes characters in string `old-value"
|
||||
[old-value]
|
||||
(reduce (fn [acc escape-char]
|
||||
(string/replace acc escape-char (str "\\" escape-char)))
|
||||
old-value escape-chars))
|
||||
|
||||
(defn replace-ignore-case
|
||||
[s old-value new-value]
|
||||
(string/replace s (re-pattern (str "(?i)" (escape-regex-chars old-value))) new-value))
|
||||
#?(:cljs
|
||||
(def replace-ignore-case common-util/replace-ignore-case))
|
||||
|
||||
;; copy from https://stackoverflow.com/questions/18735665/how-can-i-get-the-positions-of-regex-matches-in-clojurescript
|
||||
#?(:cljs
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
(ns frontend.worker.file.page-rename
|
||||
"File based page rename fns"
|
||||
(:require [frontend.util :as util]
|
||||
(:require [logseq.common.util :as common-util]
|
||||
[logseq.graph-parser.property :as gp-property]
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[clojure.walk :as walk]
|
||||
|
@ -22,7 +22,7 @@
|
|||
(:org-mode/insert-file-link? config)
|
||||
(re-find
|
||||
(re-pattern
|
||||
(util/format
|
||||
(common-util/format
|
||||
"\\[\\[file:\\.*/.*%s\\.org\\]\\[(.*?)\\]\\]" old-name))
|
||||
content))]
|
||||
(-> (if old-org-ref
|
||||
|
@ -39,15 +39,15 @@
|
|||
|
||||
(defn- replace-tag-ref!
|
||||
[content old-name new-name]
|
||||
(let [old-tag (util/format "#%s" old-name)
|
||||
(let [old-tag (common-util/format "#%s" old-name)
|
||||
new-tag (if (re-find #"[\s\t]+" new-name)
|
||||
(util/format "#[[%s]]" new-name)
|
||||
(common-util/format "#[[%s]]" new-name)
|
||||
(str "#" new-name))]
|
||||
;; hash tag parsing rules https://github.com/logseq/mldoc/blob/701243eaf9b4157348f235670718f6ad19ebe7f8/test/test_markdown.ml#L631
|
||||
;; Safari doesn't support look behind, don't use
|
||||
;; TODO: parse via mldoc
|
||||
(string/replace content
|
||||
(re-pattern (str "(?i)(^|\\s)(" (util/escape-regex-chars old-tag) ")(?=[,\\.]*($|\\s))"))
|
||||
(re-pattern (str "(?i)(^|\\s)(" (common-util/escape-regex-chars old-tag) ")(?=[,\\.]*($|\\s))"))
|
||||
;; case_insense^ ^lhs ^_grp2 look_ahead^ ^_grp3
|
||||
(fn [[_match lhs _grp2 _grp3]]
|
||||
(str lhs new-tag)))))
|
||||
|
@ -58,7 +58,7 @@
|
|||
org-format? (= :org format)
|
||||
old-property (if org-format? (gp-property/colons-org old-name) (str old-name gp-property/colons))
|
||||
new-property (if org-format? (gp-property/colons-org (name new-name)) (str (name new-name) gp-property/colons))]
|
||||
(util/replace-ignore-case content old-property new-property)))
|
||||
(common-util/replace-ignore-case content old-property new-property)))
|
||||
|
||||
(defn- replace-old-page!
|
||||
"Unsanitized names"
|
||||
|
@ -104,8 +104,8 @@
|
|||
"Unsanitized only"
|
||||
[db config old-original-name new-name]
|
||||
;; update all pages which have references to this page
|
||||
(let [page (d/entity db [:block/name (util/page-name-sanity-lc old-original-name)])
|
||||
to-page (d/entity db [:block/name (util/page-name-sanity-lc new-name)])
|
||||
(let [page (d/entity db [:block/name (common-util/page-name-sanity-lc old-original-name)])
|
||||
to-page (d/entity db [:block/name (common-util/page-name-sanity-lc new-name)])
|
||||
blocks (:block/_refs (d/entity db (:db/id page)))
|
||||
tx (->> (map (fn [{:block/keys [uuid content properties format] :as block}]
|
||||
(let [content (let [content' (replace-old-page! config content old-original-name new-name format)]
|
||||
|
@ -115,7 +115,7 @@
|
|||
(when-not (= properties' properties)
|
||||
properties'))]
|
||||
(when (or content properties)
|
||||
(util/remove-nils-non-nested
|
||||
(common-util/remove-nils-non-nested
|
||||
{:block/uuid uuid
|
||||
:block/content content
|
||||
:block/properties properties
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"Page rename"
|
||||
(:require [logseq.outliner.core :as outliner-core]
|
||||
[logseq.outliner.tree :as otree]
|
||||
[frontend.handler.common.page :as page-common-handler]
|
||||
[frontend.worker.handler.page :as worker-page]
|
||||
[datascript.core :as d]
|
||||
[medley.core :as medley]
|
||||
[clojure.string :as string]
|
||||
|
@ -11,7 +11,31 @@
|
|||
[frontend.worker.file.page-rename :as page-rename]
|
||||
[logseq.db.sqlite.util :as sqlite-util]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.common.util :as common-util]))
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.graph-parser.text :as text]))
|
||||
|
||||
(defn rename-update-namespace!
|
||||
"update :block/namespace of the renamed block"
|
||||
[repo conn config page old-original-name new-name]
|
||||
(let [old-namespace? (text/namespace-page? old-original-name)
|
||||
new-namespace? (text/namespace-page? new-name)]
|
||||
(cond
|
||||
new-namespace?
|
||||
;; update namespace
|
||||
(let [namespace (first (common-util/split-last "/" new-name))]
|
||||
(when namespace
|
||||
(worker-page/create! repo conn config namespace) ;; create parent page if not exist, creation of namespace ref is handled in `create!`
|
||||
(let [namespace-block (d/entity @conn [:block/name (common-util/page-name-sanity-lc namespace)])
|
||||
page-txs [{:db/id (:db/id page)
|
||||
:block/namespace (:db/id namespace-block)}]]
|
||||
(d/transact! conn repo page-txs))))
|
||||
|
||||
old-namespace?
|
||||
;; retract namespace
|
||||
(d/transact! conn [[:db/retract (:db/id page) :block/namespace]])
|
||||
|
||||
:else
|
||||
nil)))
|
||||
|
||||
(defn- replace-page-ref
|
||||
"Replace from-page refs with to-page"
|
||||
|
@ -101,11 +125,11 @@
|
|||
(page-rename/replace-page-ref db config from-page-name to-page-name))
|
||||
tx-data (concat blocks-tx-data replace-ref-tx-data)]
|
||||
(d/transact! conn tx-data {:persist-op? persist-op?})
|
||||
(page-common-handler/rename-update-namespace! from-page
|
||||
(common-util/get-page-original-name from-page)
|
||||
(common-util/get-page-original-name to-page)))
|
||||
(rename-update-namespace! repo conn config from-page
|
||||
(common-util/get-page-original-name from-page)
|
||||
(common-util/get-page-original-name to-page)))
|
||||
|
||||
(page-common-handler/delete! from-page-name nil :redirect-to-home? false :persist-op? persist-op?)))
|
||||
(worker-page/delete! repo conn from-page-name (fn [_]))))
|
||||
|
||||
(defn- compute-new-file-path
|
||||
"Construct the full path given old full path and the file sanitized body.
|
||||
|
@ -162,7 +186,7 @@
|
|||
(merge {:old-path old-path
|
||||
:new-path new-path}))})
|
||||
|
||||
(page-common-handler/rename-update-namespace! page old-original-name new-name)))))
|
||||
(rename-update-namespace! repo conn config page old-original-name new-name)))))
|
||||
|
||||
(defn- rename-namespace-pages!
|
||||
"Original names (unsanitized only)"
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
[logseq.outliner.transaction :as outliner-tx]
|
||||
[frontend.worker.util :as worker-util]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.common.config :as common-config]
|
||||
[malli.core :as m]
|
||||
[malli.util :as mu]
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
|
@ -24,7 +25,6 @@
|
|||
[frontend.worker.rtc.const :as rtc-const]
|
||||
[frontend.worker.rtc.op-mem-layer :as op-mem-layer]
|
||||
[frontend.worker.rtc.ws :as ws]
|
||||
[frontend.state :as state]
|
||||
[promesa.core :as p]
|
||||
[cljs-bean.core :as bean]))
|
||||
|
||||
|
@ -883,9 +883,10 @@
|
|||
(defn <start-rtc
|
||||
[repo conn token]
|
||||
(go
|
||||
(let [state (<init-state token)]
|
||||
(let [state (<init-state token)
|
||||
config (worker-state/get-config repo)]
|
||||
(if-let [graph-uuid (op-mem-layer/get-graph-uuid repo)]
|
||||
(<! (<loop-for-rtc state graph-uuid repo conn (state/get-date-formatter)))
|
||||
(<! (<loop-for-rtc state graph-uuid repo conn (common-config/get-date-formatter config)))
|
||||
(worker-util/post-message :notification [[:div
|
||||
[:p "RTC is not supported for this graph"]]
|
||||
:error])))))
|
||||
|
|
Loading…
Reference in New Issue