diff --git a/public/index.html b/public/index.html index 25dda2f300..4af885a044 100644 --- a/public/index.html +++ b/public/index.html @@ -1,16 +1,55 @@ -Logseq: A local-first knowledge base
+ + + + + const git = await portal.get('git') + window.git = git + const fs = await portal.get('fs') + window.fs = fs + const pfs = await portal.get('pfs') + window.pfs = pfs + const gitHttp = await portal.get('gitHttp') + window.gitHttp = gitHttp + const workerThread = await portal.get('workerThread') + window.workerThread = workerThread +})() + + + + + + diff --git a/src/main/frontend/db/model.cljs b/src/main/frontend/db/model.cljs index aa5c60b415..ab8665cbec 100644 --- a/src/main/frontend/db/model.cljs +++ b/src/main/frontend/db/model.cljs @@ -719,7 +719,7 @@ [page-name] (if (util/uuid-string? 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? [block] diff --git a/src/main/frontend/extensions/pdf/assets.cljs b/src/main/frontend/extensions/pdf/assets.cljs index fa47edc3a1..78ca70c83c 100644 --- a/src/main/frontend/extensions/pdf/assets.cljs +++ b/src/main/frontend/extensions/pdf/assets.cljs @@ -3,6 +3,7 @@ [frontend.util :as utils] [frontend.db.model :as db-model] [frontend.db.utils :as db-utils] + [frontend.handler.page :as page-handler] [frontend.handler.editor :as editor-handler] [frontend.state :as state] [frontend.config :as config] @@ -48,6 +49,45 @@ data (pr-str {:highlights highlights})] (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! [page-block files refresh-file!] (let [repo (state/get-current-repo) diff --git a/src/main/frontend/extensions/pdf/highlights.cljs b/src/main/frontend/extensions/pdf/highlights.cljs index 15e9073f13..4ed7a8cf40 100644 --- a/src/main/frontend/extensions/pdf/highlights.cljs +++ b/src/main/frontend/extensions/pdf/highlights.cljs @@ -87,23 +87,29 @@ :on-click (fn [^js/MouseEvent e] (when-let [action (.. e -target -dataset -action)] (case action + "ref" + (pdf-assets/copy-hl-ref! highlight) + "copy" (do (front-utils/copy-to-clipboard! (:text content)) (pdf-utils/clear-all-selection)) "del" - (del-hl! highlight) + (do + (del-hl! highlight) + (pdf-assets/del-ref-block! highlight)) ;; colors (let [properties {:color action}] (if-not id ;; add highlight - (do - (add-hl! (merge highlight - {:id (pdf-utils/gen-uuid) - :properties properties})) - (pdf-utils/clear-all-selection)) + (let [highlight (merge highlight + {:id (pdf-utils/gen-uuid) + :properties properties})] + (add-hl! highlight) + (pdf-utils/clear-all-selection) + (pdf-assets/copy-hl-ref! highlight)) ;; update highlight (do @@ -115,6 +121,9 @@ (for [it ["yellow", "blue", "green", "red", "purple"]] [: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"] (and id [:li.item {:data-action "del"} "Delete"]) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index d23577d6a7..728c6975a4 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -619,7 +619,7 @@ (state/set-editor-op! nil))) (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 before? false}}] (when (or page block-uuid) @@ -648,7 +648,7 @@ (assoc :block/content content :block/format format) (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) (assoc new-block :block/page (:db/id (:block/page new-block))) (assoc new-block :block/page (:db/id block)))