mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
improve(pdf): support block ref with highlight
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -719,7 +719,7 @@
|
|||||||
[page-name]
|
[page-name]
|
||||||
(if (util/uuid-string? page-name)
|
(if (util/uuid-string? page-name)
|
||||||
(db-utils/entity [:block/uuid (uuid page-name)])
|
(db-utils/entity [:block/uuid (uuid page-name)])
|
||||||
(db-utils/entity [:block/name page-name])))
|
(db-utils/entity [:block/name (string/lower-case page-name)])))
|
||||||
|
|
||||||
(defn- heading-block?
|
(defn- heading-block?
|
||||||
[block]
|
[block]
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
[frontend.util :as utils]
|
[frontend.util :as utils]
|
||||||
[frontend.db.model :as db-model]
|
[frontend.db.model :as db-model]
|
||||||
[frontend.db.utils :as db-utils]
|
[frontend.db.utils :as db-utils]
|
||||||
|
[frontend.handler.page :as page-handler]
|
||||||
[frontend.handler.editor :as editor-handler]
|
[frontend.handler.editor :as editor-handler]
|
||||||
[frontend.state :as state]
|
[frontend.state :as state]
|
||||||
[frontend.config :as config]
|
[frontend.config :as config]
|
||||||
@@ -48,6 +49,45 @@
|
|||||||
data (pr-str {:highlights highlights})]
|
data (pr-str {:highlights highlights})]
|
||||||
(fs/write-file! repo-cur repo-dir hls-file data {:skip-mtime? true}))))
|
(fs/write-file! repo-cur repo-dir hls-file data {:skip-mtime? true}))))
|
||||||
|
|
||||||
|
(defn resolve-ref-page
|
||||||
|
[page-name]
|
||||||
|
(let [page-name (str "hls__" page-name)
|
||||||
|
page (db-model/get-page page-name)]
|
||||||
|
(if-not page
|
||||||
|
(do
|
||||||
|
(page-handler/create! page-name {:redirect? false :create-first-block? false})
|
||||||
|
;; refresh to file
|
||||||
|
(editor-handler/api-insert-new-block! page-name {:page page-name})
|
||||||
|
(db-model/get-page page-name))
|
||||||
|
page)))
|
||||||
|
|
||||||
|
(defn create-ref-block!
|
||||||
|
[{:keys [id content]}]
|
||||||
|
(when-let [pdf-current (:pdf/current @state/state)]
|
||||||
|
(when-let [ref-page (resolve-ref-page (:key pdf-current))]
|
||||||
|
(if-let [ref-block (db-model/get-block-by-uuid id)]
|
||||||
|
(do
|
||||||
|
(js/console.debug "[existed ref block]" ref-block)
|
||||||
|
ref-block)
|
||||||
|
(let [text (:text content)] ;; TODO: image
|
||||||
|
(editor-handler/api-insert-new-block!
|
||||||
|
text {:page (:block/name ref-page)
|
||||||
|
:custom-uuid id
|
||||||
|
:properties {:type "annotation"
|
||||||
|
:id (str id) ;; force custom uuid
|
||||||
|
}}))))))
|
||||||
|
|
||||||
|
(defn del-ref-block!
|
||||||
|
[{:keys [id]}]
|
||||||
|
(when-let [repo (state/get-current-repo)]
|
||||||
|
(when-let [block (db-model/get-block-by-uuid id)]
|
||||||
|
(editor-handler/delete-block-aux! block true))))
|
||||||
|
|
||||||
|
(defn copy-hl-ref!
|
||||||
|
[highlight]
|
||||||
|
(when-let [ref-block (create-ref-block! highlight)]
|
||||||
|
(utils/copy-to-clipboard! (str "((" (:block/uuid ref-block) "))"))))
|
||||||
|
|
||||||
(defn upload-asset!
|
(defn upload-asset!
|
||||||
[page-block files refresh-file!]
|
[page-block files refresh-file!]
|
||||||
(let [repo (state/get-current-repo)
|
(let [repo (state/get-current-repo)
|
||||||
|
|||||||
@@ -87,23 +87,29 @@
|
|||||||
:on-click (fn [^js/MouseEvent e]
|
:on-click (fn [^js/MouseEvent e]
|
||||||
(when-let [action (.. e -target -dataset -action)]
|
(when-let [action (.. e -target -dataset -action)]
|
||||||
(case action
|
(case action
|
||||||
|
"ref"
|
||||||
|
(pdf-assets/copy-hl-ref! highlight)
|
||||||
|
|
||||||
"copy"
|
"copy"
|
||||||
(do
|
(do
|
||||||
(front-utils/copy-to-clipboard! (:text content))
|
(front-utils/copy-to-clipboard! (:text content))
|
||||||
(pdf-utils/clear-all-selection))
|
(pdf-utils/clear-all-selection))
|
||||||
|
|
||||||
"del"
|
"del"
|
||||||
(del-hl! highlight)
|
(do
|
||||||
|
(del-hl! highlight)
|
||||||
|
(pdf-assets/del-ref-block! highlight))
|
||||||
|
|
||||||
;; colors
|
;; colors
|
||||||
(let [properties {:color action}]
|
(let [properties {:color action}]
|
||||||
(if-not id
|
(if-not id
|
||||||
;; add highlight
|
;; add highlight
|
||||||
(do
|
(let [highlight (merge highlight
|
||||||
(add-hl! (merge highlight
|
{:id (pdf-utils/gen-uuid)
|
||||||
{:id (pdf-utils/gen-uuid)
|
:properties properties})]
|
||||||
:properties properties}))
|
(add-hl! highlight)
|
||||||
(pdf-utils/clear-all-selection))
|
(pdf-utils/clear-all-selection)
|
||||||
|
(pdf-assets/copy-hl-ref! highlight))
|
||||||
|
|
||||||
;; update highlight
|
;; update highlight
|
||||||
(do
|
(do
|
||||||
@@ -115,6 +121,9 @@
|
|||||||
(for [it ["yellow", "blue", "green", "red", "purple"]]
|
(for [it ["yellow", "blue", "green", "red", "purple"]]
|
||||||
[:a {:key it :data-color it :data-action it} it])]
|
[:a {:key it :data-color it :data-action it} it])]
|
||||||
|
|
||||||
|
|
||||||
|
(and id [:li.item {:data-action "ref"} "Copy ref"])
|
||||||
|
|
||||||
[:li.item {:data-action "copy"} "Copy text"]
|
[:li.item {:data-action "copy"} "Copy text"]
|
||||||
|
|
||||||
(and id [:li.item {:data-action "del"} "Delete"])
|
(and id [:li.item {:data-action "del"} "Delete"])
|
||||||
|
|||||||
@@ -619,7 +619,7 @@
|
|||||||
(state/set-editor-op! nil)))
|
(state/set-editor-op! nil)))
|
||||||
|
|
||||||
(defn api-insert-new-block!
|
(defn api-insert-new-block!
|
||||||
[content {:keys [page block-uuid sibling? before? properties]
|
[content {:keys [page block-uuid sibling? before? properties custom-uuid]
|
||||||
:or {sibling? false
|
:or {sibling? false
|
||||||
before? false}}]
|
before? false}}]
|
||||||
(when (or page block-uuid)
|
(when (or page block-uuid)
|
||||||
@@ -648,7 +648,7 @@
|
|||||||
(assoc :block/content content
|
(assoc :block/content content
|
||||||
:block/format format)
|
:block/format format)
|
||||||
(wrap-parse-block)
|
(wrap-parse-block)
|
||||||
(assoc :block/uuid (db/new-block-id)))
|
(assoc :block/uuid (or custom-uuid (db/new-block-id))))
|
||||||
new-block (if (:block/page new-block)
|
new-block (if (:block/page new-block)
|
||||||
(assoc new-block :block/page (:db/id (:block/page new-block)))
|
(assoc new-block :block/page (:db/id (:block/page new-block)))
|
||||||
(assoc new-block :block/page (:db/id block)))
|
(assoc new-block :block/page (:db/id block)))
|
||||||
|
|||||||
Reference in New Issue
Block a user