mirror of https://github.com/logseq/logseq
fix: copy block ref for db graphs
Copy block embed has been disabled for now, it needs to be fixed first.pull/11433/head
parent
d84639a655
commit
e3723141fa
|
@ -28,6 +28,7 @@
|
|||
[goog.object :as gobj]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.common.util.block-ref :as block-ref]
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[promesa.core :as p]
|
||||
[rum.core :as rum]
|
||||
[logseq.db :as ldb]))
|
||||
|
@ -36,7 +37,8 @@
|
|||
|
||||
(rum/defc custom-context-menu-content
|
||||
[]
|
||||
(let [repo (state/get-current-repo)]
|
||||
(let [repo (state/get-current-repo)
|
||||
db-based? (config/db-based-graph? repo)]
|
||||
[:<>
|
||||
(ui/menu-background-color #(property-handler/batch-set-block-property! repo
|
||||
(state/get-selection-block-ids)
|
||||
|
@ -74,11 +76,11 @@
|
|||
(shui/dropdown-menu-item
|
||||
{:key "copy as"
|
||||
:on-pointer-down (fn [e]
|
||||
(util/stop-propagation e)
|
||||
(let [block-uuids (state/get-selection-block-ids)]
|
||||
(shui/popup-hide!)
|
||||
(shui/dialog-open!
|
||||
#(export/export-blocks block-uuids {:whiteboard? false}))))}
|
||||
(util/stop-propagation e)
|
||||
(let [block-uuids (state/get-selection-block-ids)]
|
||||
(shui/popup-hide!)
|
||||
(shui/dialog-open!
|
||||
#(export/export-blocks block-uuids {:whiteboard? false}))))}
|
||||
(t :content/copy-export-as))
|
||||
|
||||
(shui/dropdown-menu-item
|
||||
|
@ -86,10 +88,11 @@
|
|||
:on-click editor-handler/copy-block-refs}
|
||||
(t :content/copy-block-ref))
|
||||
|
||||
(shui/dropdown-menu-item
|
||||
{:key "copy block embeds"
|
||||
:on-click editor-handler/copy-block-embeds}
|
||||
(t :content/copy-block-emebed))
|
||||
(when-not db-based?
|
||||
(shui/dropdown-menu-item
|
||||
{:key "copy block embeds"
|
||||
:on-click editor-handler/copy-block-embeds}
|
||||
(t :content/copy-block-emebed)))
|
||||
|
||||
(shui/dropdown-menu-separator)
|
||||
|
||||
|
@ -226,14 +229,19 @@
|
|||
(shui/dropdown-menu-item
|
||||
{:key "Copy block ref"
|
||||
:on-click (fn [_e]
|
||||
(editor-handler/copy-block-ref! block-id block-ref/->block-ref))}
|
||||
(editor-handler/copy-block-ref! block-id
|
||||
(if db? page-ref/->page-ref block-ref/->block-ref)))}
|
||||
(t :content/copy-block-ref))
|
||||
|
||||
(shui/dropdown-menu-item
|
||||
{:key "Copy block embed"
|
||||
:on-click (fn [_e]
|
||||
(editor-handler/copy-block-ref! block-id #(util/format "{{embed ((%s))}}" %)))}
|
||||
(t :content/copy-block-emebed))
|
||||
(when-not db?
|
||||
(shui/dropdown-menu-item
|
||||
{:key "Copy block embed"
|
||||
:on-click (fn [_e]
|
||||
(editor-handler/copy-block-ref! block-id
|
||||
(if db?
|
||||
block-ref/->block-ref
|
||||
#(util/format "{{embed ((%s))}}" %))))}
|
||||
(t :content/copy-block-emebed)))
|
||||
|
||||
;; TODO Logseq protocol mobile support
|
||||
(when (util/electron?)
|
||||
|
@ -250,7 +258,7 @@
|
|||
{:key "Copy as"
|
||||
:on-click (fn [_]
|
||||
(shui/dialog-open!
|
||||
#(export/export-blocks [block-id] {:whiteboard? false})))}
|
||||
#(export/export-blocks [block-id] {:whiteboard? false})))}
|
||||
(t :content/copy-export-as))
|
||||
|
||||
(shui/dropdown-menu-item
|
||||
|
|
|
@ -1034,11 +1034,13 @@
|
|||
block (db/entity [:block/uuid (:id first-block)])
|
||||
copy-str (some->> adjusted-blocks
|
||||
(map (fn [{:keys [id level]}]
|
||||
(condp = (:block/format block)
|
||||
:org
|
||||
(str (string/join (repeat level "*")) " " (block-ref/->block-ref id))
|
||||
:markdown
|
||||
(str (string/join (repeat (dec level) "\t")) "- " (block-ref/->block-ref id)))))
|
||||
(if (config/db-based-graph? (state/get-current-repo))
|
||||
(str (string/join (repeat (dec level) "\t")) "- " (page-ref/->page-ref id))
|
||||
(condp = (:block/format block)
|
||||
:org
|
||||
(str (string/join (repeat level "*")) " " (block-ref/->block-ref id))
|
||||
:markdown
|
||||
(str (string/join (repeat (dec level) "\t")) "- " (block-ref/->block-ref id))))))
|
||||
(string/join "\n\n"))]
|
||||
(set-blocks-id! (map :id blocks))
|
||||
(util/copy-to-clipboard! copy-str))))
|
||||
|
@ -1049,9 +1051,13 @@
|
|||
(let [ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
|
||||
(uuid id)) blocks))
|
||||
(remove nil?))
|
||||
ids-str (some->> ids
|
||||
(map (fn [id] (util/format "{{embed ((%s))}}" id)))
|
||||
(string/join "\n\n"))]
|
||||
ids-str (if (config/db-based-graph? (state/get-current-repo))
|
||||
(some->> ids
|
||||
(map (fn [id] (block-ref/->block-ref id)))
|
||||
(string/join "\n\n"))
|
||||
(some->> ids
|
||||
(map (fn [id] (util/format "{{embed ((%s))}}" id)))
|
||||
(string/join "\n\n")))]
|
||||
(set-blocks-id! ids)
|
||||
(util/copy-to-clipboard! ids-str))))
|
||||
|
||||
|
@ -3145,9 +3151,16 @@
|
|||
[format]
|
||||
(when-let [current-block (state/get-edit-block)]
|
||||
(when-let [block-id (:block/uuid current-block)]
|
||||
(if (= format "embed")
|
||||
(copy-block-ref! block-id #(str "{{embed ((" % "))}}"))
|
||||
(copy-block-ref! block-id block-ref/->block-ref)))))
|
||||
(let [db? (config/db-based-graph? (state/get-current-repo))]
|
||||
(if (= format "embed")
|
||||
(copy-block-ref! block-id
|
||||
(if db?
|
||||
block-ref/->block-ref
|
||||
#(str "{{embed ((" % "))}}")))
|
||||
(copy-block-ref! block-id
|
||||
(if db?
|
||||
page-ref/->page-ref
|
||||
block-ref/->block-ref)))))))
|
||||
|
||||
(defn copy-current-block-embed []
|
||||
(copy-current-block-ref "embed"))
|
||||
|
|
Loading…
Reference in New Issue