Răsfoiți Sursa

fix(pdf): save highlights for file graph

charlie 6 luni în urmă
părinte
comite
88ba998607

+ 7 - 15
src/main/frontend/extensions/pdf/assets.cljs

@@ -126,24 +126,16 @@
           (do
             (println "[existed ref block]" ref-block)
             ref-block)
-          (let [text       (:text content)
+          (let [text (:text content)
                 wrap-props #(if-let [stamp (:image content)]
                               (assoc %
-                                     :hl-type :area
-                                     :hl-stamp stamp)
+                                :hl-type :area
+                                :hl-stamp stamp)
                               %)
-                db-base? (config/db-based-graph? (state/get-current-repo))
-                props (cond->
-                       {(pu/get-pid :logseq.property/ls-type)  :annotation
-                        (pu/get-pid :logseq.property.pdf/hl-page)  page
-                        (pu/get-pid :logseq.property.pdf/hl-color) (:color properties)}
-
-                        db-base?
-                        (assoc (pu/get-pid :logseq.property.pdf/hl-value) hl)
-
-                        (not db-base?)
-                         ;; force custom uuid
-                        (assoc :id (if (string? id) (uuid id) id)))
+                props {:id (if (string? id) (uuid id) id)
+                       (pu/get-pid :logseq.property/ls-type) :annotation
+                       (pu/get-pid :logseq.property.pdf/hl-page) page
+                       (pu/get-pid :logseq.property.pdf/hl-color) (:color properties)}
                 properties (wrap-props props)]
             (when (string? text)
               (editor-handler/api-insert-new-block!

+ 11 - 10
src/main/frontend/extensions/pdf/core.cljs

@@ -568,18 +568,19 @@
                           highlights' (conj highlights hl)]
                       (set-highlights! highlights')
 
-                      (if-let [vw-pos (and (pdf-assets/area-highlight? hl)
-                                           (pdf-utils/scaled-to-vw-pos viewer (:position hl)))]
+                      (when-let [vw-pos (and (pdf-assets/area-highlight? hl)
+                                          (pdf-utils/scaled-to-vw-pos viewer (:position hl)))]
                         ;; exceptions
                         (->
-                         (p/let [result (pdf-assets/persist-hl-area-image$ viewer (:pdf/current @state/state)
-                                                                           hl nil (:bounding vw-pos))]
-                           (if (de/entity? result)
-                             (let [hl' (assoc-in hl [:content :image] (:db/id result))]
-                               (set-highlights! (map (fn [hl] (if (= (:id hl) (:id hl')) hl' hl)) highlights'))
-                               hl')
-                             (throw (js/Error. (str "[pdf] unexpected persist asset image return:" result)))))
-                         (p/catch (fn [e] (js/console.error e))))
+                          (p/let [result (pdf-assets/persist-hl-area-image$ viewer (:pdf/current @state/state)
+                                           hl nil (:bounding vw-pos))]
+                            (when (de/entity? result)
+                              (let [hl' (assoc-in hl [:content :image] (:db/id result))]
+                                (set-highlights! (map (fn [hl] (if (= (:id hl) (:id hl')) hl' hl)) highlights'))
+                                hl')
+                              ;(throw (js/Error. (str "[pdf] unexpected persist asset image return:" result)))
+                              ))
+                          (p/catch (fn [e] (js/console.error e))))
                         hl))))
         upd-hl! (fn [hl]
                   (let [highlights (pdf-utils/fix-nested-js highlights)]