diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 07a78f4a4f..05e61ef8a4 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -1889,7 +1889,7 @@ [:a.fade-link summary]])))) - (let [block-refs-count (count (:block/_refs (db/entity (:db/id block))))] + (let [block-refs-count (count (:block/_refs block))] (when (and block-refs-count (> block-refs-count 0)) [:div [:a.open-block-ref-link.bg-base-2.text-sm.ml-2 @@ -2084,7 +2084,8 @@ :should-update (fn [old-state new-state] (let [compare-keys [:block/uuid :block/properties :block/parent :block/left - :block/children :block/content] + :block/children :block/content + :block/_refs] config-compare-keys [:show-cloze?]] (or (not= (select-keys (second (:rum/args old-state)) compare-keys) diff --git a/src/main/frontend/components/content.cljs b/src/main/frontend/components/content.cljs index 79503a17fe..2dd1d0a200 100644 --- a/src/main/frontend/components/content.cljs +++ b/src/main/frontend/components/content.cljs @@ -65,7 +65,11 @@ (let [block-uuids (editor-handler/get-selected-toplevel-block-uuids)] (state/set-modal! #(export/export-blocks block-uuids))))} - "Copy as")]]) + "Copy as") + (ui/menu-link + {:key "copy block refs" + :on-click editor-handler/copy-block-refs} + "Copy block refs")]]) ;; FIXME: Make it configurable (def block-background-colors diff --git a/src/main/frontend/db/model.cljs b/src/main/frontend/db/model.cljs index 88e9b862e8..d1b10a5025 100644 --- a/src/main/frontend/db/model.cljs +++ b/src/main/frontend/db/model.cljs @@ -20,7 +20,7 @@ ;; correponding handlers. ;; Use it as an input argument for datalog queries -(defonce block-attrs +(def block-attrs '[:db/id :block/uuid :block/type @@ -28,6 +28,7 @@ :block/format :block/title :block/refs + :block/_refs :block/path-refs :block/tags :block/content @@ -473,7 +474,7 @@ (get-page-blocks repo-url page nil)) ([repo-url page {:keys [use-cache? pull-keys] :or {use-cache? true - pull-keys '[*]}}] + pull-keys block-attrs}}] (let [page (string/lower-case (string/trim page)) page-entity (or (db-utils/entity repo-url [:block/name page]) (db-utils/entity repo-url [:block/original-name page])) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 3eccd5412e..cac6be628c 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1033,12 +1033,16 @@ (state/set-edit-content! input-id new-content) (save-block-if-changed! block new-content))))))) +(defn- set-block-id! + [block-id] + (let [block (db/entity [:block/uuid block-id])] + (when-not (:block/pre-block? block) + (set-block-property! block-id "id" (str block-id))))) + (defn copy-block-ref! ([block-id] (copy-block-ref! block-id #(str %))) ([block-id tap-clipboard] - (let [block (db/entity [:block/uuid block-id])] - (when-not (:block/pre-block? block) - (set-block-property! block-id "id" (str block-id)))) + (set-block-id! block-id) (util/copy-to-clipboard! (tap-clipboard block-id)))) (defn select-block! @@ -1131,6 +1135,20 @@ (state/set-copied-blocks content tree) (notification/show! "Copied!" :success)))) +(defn copy-block-refs + [] + (when-let [blocks (seq (get-selected-blocks-with-children))] + (let [repo (state/get-current-repo) + ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")] + (uuid id)) blocks)) + (remove nil?)) + ids-str (some->> ids + (map (fn [id] (util/format "((%s))" id))) + (string/join "\n\n"))] + (doseq [id ids] + (set-block-id! id)) + (util/copy-to-clipboard! ids-str)))) + (defn get-selected-toplevel-block-uuids [] (when-let [blocks (seq (get-selected-blocks-with-children))]