diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 678cd5ff06..8245f6b83c 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -20,7 +20,6 @@ [frontend.components.query :as query] [frontend.components.query.builder :as query-builder-component] [frontend.components.svg :as svg] - [frontend.components.title :as title] [frontend.components.select :as select] [frontend.config :as config] [frontend.context.i18n :refer [t]] @@ -722,7 +721,7 @@ (->elem :span (map-inline config label)) show-unique-title? - (title/block-unique-title page-entity) + (block-handler/block-unique-title page-entity) :else (let [title (:block/title page-entity) diff --git a/src/main/frontend/components/cmdk/core.cljs b/src/main/frontend/components/cmdk/core.cljs index 1955fc6ff0..89005c2c0d 100644 --- a/src/main/frontend/components/cmdk/core.cljs +++ b/src/main/frontend/components/cmdk/core.cljs @@ -4,7 +4,6 @@ [electron.ipc :as ipc] [frontend.components.block :as block] [frontend.components.cmdk.list-item :as list-item] - [frontend.components.title :as title] [frontend.config :as config] [frontend.context.i18n :refer [t]] [frontend.db :as db] @@ -18,6 +17,7 @@ [frontend.handler.page :as page-handler] [frontend.handler.route :as route-handler] [frontend.handler.whiteboard :as whiteboard-handler] + [frontend.handler.block :as block-handler] [frontend.mixins :as mixins] [frontend.modules.shortcut.core :as shortcut] [frontend.modules.shortcut.utils :as shortcut-utils] @@ -235,7 +235,7 @@ "whiteboard" :else "page") - title (title/block-unique-title page) + title (block-handler/block-unique-title page) title' (if source-page (str title " -> alias: " (:block/title source-page)) title)] (hash-map :icon icon :icon-theme :gray @@ -245,7 +245,7 @@ (defn- block-item [repo block current-page !input] (let [id (:block/uuid block) - text (title/block-unique-title block) + text (block-handler/block-unique-title block) icon "letter-n"] {:icon icon :icon-theme :gray diff --git a/src/main/frontend/components/container.cljs b/src/main/frontend/components/container.cljs index b4a8cecd6d..9380b90387 100644 --- a/src/main/frontend/components/container.cljs +++ b/src/main/frontend/components/container.cljs @@ -15,7 +15,6 @@ [frontend.components.block :as block] [dommy.core :as d] [frontend.components.content :as cp-content] - [frontend.components.title :as title] [frontend.config :as config] [frontend.context.i18n :refer [t]] [frontend.db :as db] @@ -32,6 +31,7 @@ [frontend.handler.user :as user-handler] [frontend.handler.whiteboard :as whiteboard-handler] [frontend.handler.recent :as recent-handler] + [frontend.handler.block :as block-handler] [frontend.mixins :as mixins] [frontend.mobile.action-bar :as action-bar] [frontend.mobile.footer :as footer] @@ -133,7 +133,7 @@ :class "w-60"}}) (util/stop e))} (ldb/object? page) - (assoc :title (title/block-unique-title page))) + (assoc :title (block-handler/block-unique-title page))) [:span.page-icon.ml-3.justify-center icon] [:span.page-title {:class (when untitled? "opacity-50") :style {:display "ruby"}} @@ -206,7 +206,7 @@ (for [page pages] [:li.recent-item.select-none {:key (str "recent-" (:db/id page)) - :title (title/block-unique-title page) + :title (block-handler/block-unique-title page) :draggable true :on-drag-start (fn [event] (editor-handler/block->data-transfer! (:block/name page) event true)) :data-ref name} diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index 8fe43764cd..7bbd6453b1 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -6,7 +6,6 @@ [frontend.components.file-based.datetime :as datetime-comp] [frontend.components.search :as search] [frontend.components.svg :as svg] - [frontend.components.title :as title] [frontend.config :as config] [frontend.context.i18n :refer [t]] [frontend.date :as date] @@ -19,6 +18,7 @@ [frontend.handler.paste :as paste-handler] [frontend.handler.property.util :as pu] [frontend.handler.search :as search-handler] + [frontend.handler.block :as block-handler] [frontend.mixins :as mixins] [frontend.search :refer [fuzzy-search]] [frontend.state :as state] @@ -215,7 +215,7 @@ (if (ldb/class? target) (str (:block/title block) " -> alias: " (:block/title target)) (:block/title block))) - (title/block-unique-title block))] + (block-handler/block-unique-title block))] (search-handler/highlight-exact-query title q))]])) :empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 (if db-tag? "Search for a tag" diff --git a/src/main/frontend/components/property/value.cljs b/src/main/frontend/components/property/value.cljs index 0ff669a148..8b6c35c0c9 100644 --- a/src/main/frontend/components/property/value.cljs +++ b/src/main/frontend/components/property/value.cljs @@ -5,7 +5,6 @@ [dommy.core :as d] [frontend.components.icon :as icon-component] [frontend.components.select :as select] - [frontend.components.title :as title] [frontend.config :as config] [frontend.date :as date] [frontend.db :as db] @@ -515,7 +514,7 @@ [header label] (if (integer? id) (let [node-title (if (seq (:property/schema.classes property)) (:block/title node) - (title/block-unique-title node)) + (block-handler/block-unique-title node)) title (subs node-title 0 256) node (or (db/entity id) node) icon (get-node-icon node) diff --git a/src/main/frontend/components/title.cljs b/src/main/frontend/components/title.cljs deleted file mode 100644 index b3c16591c6..0000000000 --- a/src/main/frontend/components/title.cljs +++ /dev/null @@ -1,30 +0,0 @@ -(ns frontend.components.title - (:require [clojure.string :as string] - [frontend.db :as db] - [logseq.db :as ldb] - [datascript.impl.entity :as de])) - -(defn block-unique-title - "Multiple pages/objects may have the same `:block/title`. - Notice: this doesn't prevent for pages/objects that have the same tag or created by different clients." - [block] - (let [block-e (cond - (de/entity? block) - block - (uuid? (:block/uuid block)) - (db/entity [:block/uuid (:block/uuid block)]) - :else - block) - tags (remove (fn [t] (some-> (:block/raw-title block-e) (ldb/inline-tag? t))) - (map (fn [tag] (if (number? tag) (db/entity tag) tag)) (:block/tags block)))] - (if (and (seq tags) - (not (ldb/journal? block))) - (str (:block/title block) - " " - (string/join - ", " - (keep (fn [tag] - (when-let [title (:block/title tag)] - (str "#" title))) - tags))) - (:block/title block)))) diff --git a/src/main/frontend/handler/block.cljs b/src/main/frontend/handler/block.cljs index 7e8a88f87b..0e914f1204 100644 --- a/src/main/frontend/handler/block.cljs +++ b/src/main/frontend/handler/block.cljs @@ -22,7 +22,8 @@ [frontend.handler.property.util :as pu] [dommy.core :as dom] [goog.object :as gobj] - [promesa.core :as p])) + [promesa.core :as p] + [datascript.impl.entity :as de])) ;; Fns @@ -188,6 +189,31 @@ (-> (property-util/remove-built-in-properties format content) (drawer/remove-logbook)))) +(defn block-unique-title + "Multiple pages/objects may have the same `:block/title`. + Notice: this doesn't prevent for pages/objects that have the same tag or created by different clients." + [block] + (let [block-e (cond + (de/entity? block) + block + (uuid? (:block/uuid block)) + (db/entity [:block/uuid (:block/uuid block)]) + :else + block) + tags (remove (fn [t] (some-> (:block/raw-title block-e) (ldb/inline-tag? t))) + (map (fn [tag] (if (number? tag) (db/entity tag) tag)) (:block/tags block)))] + (if (and (seq tags) + (not (ldb/journal? block))) + (str (:block/title block) + " " + (string/join + ", " + (keep (fn [tag] + (when-let [title (:block/title tag)] + (str "#" title))) + tags))) + (:block/title block)))) + (defn edit-block! [block pos & {:keys [_container-id custom-content tail-len save-code-editor?] :or {tail-len 0