|
|
@@ -19,7 +19,11 @@
|
|
|
[medley.core :as medley]
|
|
|
[promesa.core :as p]
|
|
|
[rum.core :as rum]
|
|
|
- [frontend.ui :as ui]))
|
|
|
+ [frontend.ui :as ui]
|
|
|
+ [frontend.db.async :as db-async]
|
|
|
+ [goog.functions :refer [debounce]]
|
|
|
+ [frontend.handler.property :as property-handler]
|
|
|
+ [datascript.impl.entity :as de]))
|
|
|
|
|
|
(declare pdf-container system-embed-playground)
|
|
|
|
|
|
@@ -34,7 +38,7 @@
|
|
|
|
|
|
(rum/defcs pdf-highlight-finder
|
|
|
< rum/static rum/reactive
|
|
|
- (rum/local false ::mounted?)
|
|
|
+ (rum/local false ::mounted?)
|
|
|
[state ^js viewer]
|
|
|
(let [*mounted? (::mounted? state)]
|
|
|
(when viewer
|
|
|
@@ -71,11 +75,11 @@
|
|
|
[^js viewer]
|
|
|
(let [el-ref (rum/use-ref nil)
|
|
|
adjust-main-size!
|
|
|
- (util/debounce
|
|
|
- 200 (fn [width]
|
|
|
- (let [root-el js/document.documentElement]
|
|
|
- (.setProperty (.-style root-el) "--ph-view-container-width" width)
|
|
|
- (pdf-utils/adjust-viewer-size! viewer))))
|
|
|
+ (util/debounce
|
|
|
+ 200 (fn [width]
|
|
|
+ (let [root-el js/document.documentElement]
|
|
|
+ (.setProperty (.-style root-el) "--ph-view-container-width" width)
|
|
|
+ (pdf-utils/adjust-viewer-size! viewer))))
|
|
|
group-id (.-$groupIdentity viewer)]
|
|
|
|
|
|
;; draggable handler
|
|
|
@@ -148,8 +152,8 @@
|
|
|
"copy"
|
|
|
(do
|
|
|
(util/copy-to-clipboard!
|
|
|
- (or (:text content) (pdf-utils/fix-selection-text-breakline (.toString selection)))
|
|
|
- :owner-window (pdf-windows/resolve-own-window viewer))
|
|
|
+ (or (:text content) (pdf-utils/fix-selection-text-breakline (.toString selection)))
|
|
|
+ :owner-window (pdf-windows/resolve-own-window viewer))
|
|
|
(pdf-utils/clear-all-selection))
|
|
|
|
|
|
"link"
|
|
|
@@ -171,11 +175,11 @@
|
|
|
(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 viewer))
|
|
|
+ (p/let [highlight' (add-hl! highlight)]
|
|
|
+ (pdf-utils/clear-all-selection)
|
|
|
+ (pdf-assets/copy-hl-ref! highlight' viewer)))
|
|
|
|
|
|
- ;; update highlight
|
|
|
+;; update highlight
|
|
|
(upd-hl! (assoc highlight :properties properties)))
|
|
|
|
|
|
(reset! *highlight-last-color (keyword action)))))
|
|
|
@@ -208,7 +212,6 @@
|
|
|
(for [it ["yellow", "red", "green", "blue", "purple"]]
|
|
|
[:a {:key it :data-color it :data-action it} it])]
|
|
|
|
|
|
-
|
|
|
(and id [:li.item {:data-action "ref"} (t :pdf/copy-ref)])
|
|
|
|
|
|
(and (not area?) [:li.item {:data-action "copy"} (t :pdf/copy-text)])
|
|
|
@@ -228,8 +231,7 @@
|
|
|
|
|
|
(when (true? (:clearSelection extras))
|
|
|
(pdf-utils/clear-all-selection)))}
|
|
|
- label]))
|
|
|
- ]))
|
|
|
+ label]))]))
|
|
|
|
|
|
(rum/defc pdf-highlights-text-region
|
|
|
[^js viewer vw-hl hl {:keys [show-ctx-menu!]}]
|
|
|
@@ -250,7 +252,7 @@
|
|
|
(fn [^js e]
|
|
|
(when-let [^js dt (and id (.-dataTransfer e))]
|
|
|
(reset! block/*dragging? true)
|
|
|
- (pdf-assets/ensure-ref-block! (state/get-current-pdf) hl)
|
|
|
+ (pdf-assets/ensure-ref-block! (state/get-current-pdf) hl nil)
|
|
|
(.setData dt "text/plain" (str "((" id "))"))))]
|
|
|
|
|
|
[:div.extensions__pdf-hls-text-region
|
|
|
@@ -289,9 +291,9 @@
|
|
|
update-hl! (fn [hl] (some-> (rum/deref *ops-ref) (:upd-hl!) (apply [hl])))]
|
|
|
|
|
|
(rum/use-effect!
|
|
|
- (fn []
|
|
|
- (rum/set-ref! *ops-ref ops))
|
|
|
- [ops])
|
|
|
+ (fn []
|
|
|
+ (rum/set-ref! *ops-ref ops))
|
|
|
+ [ops])
|
|
|
|
|
|
;; resizable
|
|
|
(rum/use-effect!
|
|
|
@@ -326,19 +328,21 @@
|
|
|
(let [hl' (assoc hl :position to-sc-pos)
|
|
|
hl' (assoc-in hl' [:content :image] (js/Date.now))]
|
|
|
|
|
|
- (p/then
|
|
|
- (pdf-assets/persist-hl-area-image$ viewer
|
|
|
- (:pdf/current @state/state)
|
|
|
- hl' hl (:bounding to-vw-pos))
|
|
|
- (fn [] (js/setTimeout
|
|
|
- #(do
|
|
|
- ;; reset dom effects
|
|
|
- (set! (.. target -style -transform) (str "translate(0, 0)"))
|
|
|
- (.removeAttribute target "data-x")
|
|
|
- (.removeAttribute target "data-y")
|
|
|
-
|
|
|
- (update-hl! hl')) 200))))
|
|
|
-
|
|
|
+ (p/let [result (pdf-assets/persist-hl-area-image$ viewer
|
|
|
+ (:pdf/current @state/state)
|
|
|
+ hl' hl (:bounding to-vw-pos))]
|
|
|
+
|
|
|
+ (js/setTimeout
|
|
|
+ #(do
|
|
|
+ ;; reset dom effects
|
|
|
+ (set! (.. target -style -transform) (str "translate(0, 0)"))
|
|
|
+ (.removeAttribute target "data-x")
|
|
|
+ (.removeAttribute target "data-y")
|
|
|
+ (let [hl' (if (de/entity? result)
|
|
|
+ (assoc-in hl' [:content :image] (:db/id result))
|
|
|
+ hl')]
|
|
|
+ (update-hl! hl')))
|
|
|
+ 200)))
|
|
|
|
|
|
(js/setTimeout #(rum/set-ref! *dirty false))))
|
|
|
|
|
|
@@ -361,12 +365,10 @@
|
|
|
|
|
|
;; cache pos
|
|
|
(.setAttribute target "data-x" ax)
|
|
|
- (.setAttribute target "data-y" ay))
|
|
|
- ))}
|
|
|
+ (.setAttribute target "data-y" ay))))}
|
|
|
:modifiers [(js/interact.modifiers.restrict
|
|
|
- (bean/->js {:restriction (.closest el ".page")}))]
|
|
|
- :inertia true})
|
|
|
- ))]
|
|
|
+ (bean/->js {:restriction (.closest el ".page")}))]
|
|
|
+ :inertia true})))]
|
|
|
;; destroy
|
|
|
#(.unset it)))
|
|
|
[hl])
|
|
|
@@ -394,8 +396,7 @@
|
|
|
(if (get-in hl [:content :image])
|
|
|
(pdf-highlight-area-region viewer vw-hl hl ops)
|
|
|
(pdf-highlights-text-region viewer vw-hl hl ops))
|
|
|
- (:id hl))
|
|
|
- ))])
|
|
|
+ (:id hl))))])
|
|
|
|
|
|
(rum/defc ^:large-vars/cleanup-todo pdf-highlight-area-selection
|
|
|
[^js viewer {:keys [show-ctx-menu!]}]
|
|
|
@@ -464,73 +465,73 @@
|
|
|
disable-text-selection! #(js-invoke viewer-clt (if % "add" "remove") "disabled-text-selection")
|
|
|
|
|
|
fn-move (rum/use-callback
|
|
|
- (fn [^js/MouseEvent e]
|
|
|
- (set-end! (calc-coords! (.-pageX e) (.-pageY e))))
|
|
|
- [])]
|
|
|
+ (fn [^js/MouseEvent e]
|
|
|
+ (set-end! (calc-coords! (.-pageX e) (.-pageY e))))
|
|
|
+ [])]
|
|
|
|
|
|
(rum/use-effect!
|
|
|
- (fn []
|
|
|
- (when-let [^js/HTMLElement root cnt-el]
|
|
|
- (let [fn-start (fn [^js/MouseEvent e]
|
|
|
- (if (should-start e)
|
|
|
- (let [target (.-target e)
|
|
|
- page-el (.closest target ".page")
|
|
|
- [x y] [(.-pageX e) (.-pageY e)]]
|
|
|
- (rum/set-ref! *start-el target)
|
|
|
- (rum/set-ref! *start-xy [x y])
|
|
|
- (rum/set-ref! *page-el page-el)
|
|
|
- (rum/set-ref! *page-rect (some-> page-el (.getBoundingClientRect) (.toJSON) (bean/->clj)))
|
|
|
- (set-start! (calc-coords! x y))
|
|
|
- (disable-text-selection! true)
|
|
|
-
|
|
|
- (.addEventListener root "mousemove" fn-move))
|
|
|
+ (fn []
|
|
|
+ (when-let [^js/HTMLElement root cnt-el]
|
|
|
+ (let [fn-start (fn [^js/MouseEvent e]
|
|
|
+ (if (should-start e)
|
|
|
+ (let [target (.-target e)
|
|
|
+ page-el (.closest target ".page")
|
|
|
+ [x y] [(.-pageX e) (.-pageY e)]]
|
|
|
+ (rum/set-ref! *start-el target)
|
|
|
+ (rum/set-ref! *start-xy [x y])
|
|
|
+ (rum/set-ref! *page-el page-el)
|
|
|
+ (rum/set-ref! *page-rect (some-> page-el (.getBoundingClientRect) (.toJSON) (bean/->clj)))
|
|
|
+ (set-start! (calc-coords! x y))
|
|
|
+ (disable-text-selection! true)
|
|
|
+
|
|
|
+ (.addEventListener root "mousemove" fn-move))
|
|
|
|
|
|
;; reset
|
|
|
- (do (reset-coords!)
|
|
|
- (disable-text-selection! false))))
|
|
|
-
|
|
|
- fn-end (fn [^js/MouseEvent e]
|
|
|
- (when-let [start-el (rum/deref *start-el)]
|
|
|
- (let [end (calc-coords! (.-pageX e) (.-pageY e))
|
|
|
- rect (calc-rect start end)]
|
|
|
-
|
|
|
- (if (and (> (:width rect) 10)
|
|
|
- (> (:height rect) 10))
|
|
|
-
|
|
|
- (when-let [^js page-el (.closest start-el ".page")]
|
|
|
- (let [page-number (int (.-pageNumber (.-dataset page-el)))
|
|
|
- page-pos (merge rect {:top (- (:top rect) (.-offsetTop page-el))
|
|
|
- :left (- (:left rect) (.-offsetLeft page-el))})
|
|
|
- vw-pos {:bounding page-pos :rects [] :page page-number}
|
|
|
- sc-pos (pdf-utils/vw-to-scaled-pos viewer vw-pos)
|
|
|
-
|
|
|
- point {:x (.-clientX e) :y (.-clientY e)}
|
|
|
- hl {:id nil
|
|
|
- :page page-number
|
|
|
- :position sc-pos
|
|
|
- :content {:text "[:span]" :image (js/Date.now)}
|
|
|
- :properties {}}]
|
|
|
+ (do (reset-coords!)
|
|
|
+ (disable-text-selection! false))))
|
|
|
+
|
|
|
+ fn-end (fn [^js/MouseEvent e]
|
|
|
+ (when-let [start-el (rum/deref *start-el)]
|
|
|
+ (let [end (calc-coords! (.-pageX e) (.-pageY e))
|
|
|
+ rect (calc-rect start end)]
|
|
|
+
|
|
|
+ (if (and (> (:width rect) 10)
|
|
|
+ (> (:height rect) 10))
|
|
|
+
|
|
|
+ (when-let [^js page-el (.closest start-el ".page")]
|
|
|
+ (let [page-number (int (.-pageNumber (.-dataset page-el)))
|
|
|
+ page-pos (merge rect {:top (- (:top rect) (.-offsetTop page-el))
|
|
|
+ :left (- (:left rect) (.-offsetLeft page-el))})
|
|
|
+ vw-pos {:bounding page-pos :rects [] :page page-number}
|
|
|
+ sc-pos (pdf-utils/vw-to-scaled-pos viewer vw-pos)
|
|
|
+
|
|
|
+ point {:x (.-clientX e) :y (.-clientY e)}
|
|
|
+ hl {:id nil
|
|
|
+ :page page-number
|
|
|
+ :position sc-pos
|
|
|
+ :content {:text "" :image (js/Date.now)}
|
|
|
+ :properties {}}]
|
|
|
|
|
|
;; ctx tips for area
|
|
|
- (show-ctx-menu! viewer hl point {:reset-fn #(reset-coords!)}))
|
|
|
+ (show-ctx-menu! viewer hl point {:reset-fn #(reset-coords!)}))
|
|
|
|
|
|
- (set-area-mode! false))
|
|
|
+ (set-area-mode! false))
|
|
|
|
|
|
;; reset
|
|
|
- (reset-coords!)))
|
|
|
+ (reset-coords!)))
|
|
|
|
|
|
- (disable-text-selection! false)
|
|
|
- (.removeEventListener root "mousemove" fn-move)))]
|
|
|
+ (disable-text-selection! false)
|
|
|
+ (.removeEventListener root "mousemove" fn-move)))]
|
|
|
|
|
|
- (doto root
|
|
|
- (.addEventListener "mousedown" fn-start)
|
|
|
- (.addEventListener "mouseup" fn-end #js {:once true}))
|
|
|
+ (doto root
|
|
|
+ (.addEventListener "mousedown" fn-start)
|
|
|
+ (.addEventListener "mouseup" fn-end #js {:once true}))
|
|
|
|
|
|
;; destroy
|
|
|
- #(doto root
|
|
|
- (.removeEventListener "mousedown" fn-start)
|
|
|
- (.removeEventListener "mouseup" fn-end)))))
|
|
|
- [start])
|
|
|
+ #(doto root
|
|
|
+ (.removeEventListener "mousedown" fn-start)
|
|
|
+ (.removeEventListener "mouseup" fn-end)))))
|
|
|
+ [start])
|
|
|
|
|
|
[:div.extensions__pdf-area-selection
|
|
|
{:ref *el}
|
|
|
@@ -548,10 +549,10 @@
|
|
|
[ctx-menu-state, set-ctx-menu-state!] (rum/use-state {:highlight nil :vw-pos nil :selection nil :point nil :reset-fn nil})
|
|
|
|
|
|
clear-ctx-menu! (rum/use-callback
|
|
|
- #(let [reset-fn (:reset-fn ctx-menu-state)]
|
|
|
- (set-ctx-menu-state! {})
|
|
|
- (and (fn? reset-fn) (reset-fn)))
|
|
|
- [ctx-menu-state])
|
|
|
+ #(let [reset-fn (:reset-fn ctx-menu-state)]
|
|
|
+ (set-ctx-menu-state! {})
|
|
|
+ (and (fn? reset-fn) (reset-fn)))
|
|
|
+ [ctx-menu-state])
|
|
|
|
|
|
show-ctx-menu! (fn [^js viewer hl point & ops]
|
|
|
(let [vw-pos (pdf-utils/scaled-to-vw-pos viewer (:position hl))]
|
|
|
@@ -560,20 +561,28 @@
|
|
|
add-hl! (fn [hl]
|
|
|
(when (:id hl)
|
|
|
;; fix js object
|
|
|
- (let [highlights (pdf-utils/fix-nested-js highlights)]
|
|
|
- (set-highlights! (conj highlights hl)))
|
|
|
-
|
|
|
- (when-let [vw-pos (and (pdf-assets/area-highlight? hl)
|
|
|
- (pdf-utils/scaled-to-vw-pos viewer (:position hl)))]
|
|
|
- ;; exceptions
|
|
|
- (pdf-assets/persist-hl-area-image$ viewer (:pdf/current @state/state)
|
|
|
- hl nil (:bounding vw-pos)))))
|
|
|
-
|
|
|
+ (let [highlights (pdf-utils/fix-nested-js highlights)
|
|
|
+ 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)))]
|
|
|
+ ;; exceptions
|
|
|
+ (->
|
|
|
+ (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')))
|
|
|
+ (p/catch (fn [e]
|
|
|
+ (js/console.error e))))
|
|
|
+ hl))))
|
|
|
upd-hl! (fn [hl]
|
|
|
(let [highlights (pdf-utils/fix-nested-js highlights)]
|
|
|
(when-let [[target-idx] (medley/find-first
|
|
|
- #(= (:id (second %)) (:id hl))
|
|
|
- (medley/indexed highlights))]
|
|
|
+ #(= (:id (second %)) (:id hl))
|
|
|
+ (medley/indexed highlights))]
|
|
|
(set-highlights! (assoc-in highlights [target-idx] hl))
|
|
|
(pdf-assets/update-hl-block! hl))))
|
|
|
|
|
|
@@ -694,13 +703,13 @@
|
|
|
;; hl context tip menu
|
|
|
(when-let [_hl (:highlight ctx-menu-state)]
|
|
|
(js/ReactDOM.createPortal
|
|
|
- (pdf-highlights-ctx-menu viewer ctx-menu-state
|
|
|
- {:clear-ctx-menu! clear-ctx-menu!
|
|
|
- :add-hl! add-hl!
|
|
|
- :del-hl! del-hl!
|
|
|
- :upd-hl! upd-hl!})
|
|
|
+ (pdf-highlights-ctx-menu viewer ctx-menu-state
|
|
|
+ {:clear-ctx-menu! clear-ctx-menu!
|
|
|
+ :add-hl! add-hl!
|
|
|
+ :del-hl! del-hl!
|
|
|
+ :upd-hl! upd-hl!})
|
|
|
|
|
|
- (.querySelector el ".pp-holder")))
|
|
|
+ (.querySelector el ".pp-holder")))
|
|
|
|
|
|
;; debug highlights anchor
|
|
|
;;(if (seq highlights)
|
|
|
@@ -716,13 +725,11 @@
|
|
|
(pdf-page-finder viewer)
|
|
|
|
|
|
;; area selection container
|
|
|
- (when (pdf-utils/support-area?)
|
|
|
- (pdf-highlight-area-selection
|
|
|
- viewer
|
|
|
- {:clear-ctx-menu! clear-ctx-menu!
|
|
|
- :show-ctx-menu! show-ctx-menu!
|
|
|
- :add-hl! add-hl!
|
|
|
- }))]))
|
|
|
+ (pdf-highlight-area-selection
|
|
|
+ viewer
|
|
|
+ {:clear-ctx-menu! clear-ctx-menu!
|
|
|
+ :show-ctx-menu! show-ctx-menu!
|
|
|
+ :add-hl! add-hl!})]))
|
|
|
|
|
|
(rum/defc ^:large-vars/data-var pdf-viewer
|
|
|
[_url ^js pdf-document {:keys [identity filename initial-hls initial-page initial-error]} ops]
|
|
|
@@ -824,10 +831,10 @@
|
|
|
|
|
|
(when (and page-ready? viewer (not initial-error))
|
|
|
[(rum/with-key
|
|
|
- (pdf-highlights
|
|
|
- (:el state) viewer
|
|
|
- initial-hls (:loaded-pages ano-state)
|
|
|
- ops) "pdf-highlights")])]
|
|
|
+ (pdf-highlights
|
|
|
+ (:el state) viewer
|
|
|
+ initial-hls (:loaded-pages ano-state)
|
|
|
+ ops) "pdf-highlights")])]
|
|
|
|
|
|
(when (and page-ready? viewer)
|
|
|
[(when-not in-system-window?
|
|
|
@@ -852,14 +859,28 @@
|
|
|
|
|
|
[:div.mt-5.sm:mt-4.flex
|
|
|
(ui/button
|
|
|
- "Submit"
|
|
|
- {:on-click (fn []
|
|
|
- (let [password @password]
|
|
|
- (confirm-fn password)))})]]))
|
|
|
+ "Submit"
|
|
|
+ {:on-click (fn []
|
|
|
+ (let [password @password]
|
|
|
+ (confirm-fn password)))})]]))
|
|
|
+
|
|
|
+(defonce debounced-set-property!
|
|
|
+ (debounce property-handler/set-block-property! 300))
|
|
|
+
|
|
|
+(defn- debounce-set-last-visit-page!
|
|
|
+ [asset last-visit-page]
|
|
|
+ (when (and (number? last-visit-page)
|
|
|
+ (> last-visit-page 0))
|
|
|
+ (debounced-set-property! (state/get-current-repo)
|
|
|
+ (:db/id asset)
|
|
|
+ :logseq.property.asset/last-visit-page
|
|
|
+ last-visit-page)))
|
|
|
|
|
|
(rum/defc ^:large-vars/data-var pdf-loader
|
|
|
[{:keys [url hls-file identity filename] :as pdf-current}]
|
|
|
- (let [*doc-ref (rum/use-ref nil)
|
|
|
+ (let [repo (state/get-current-repo)
|
|
|
+ db-based? (config/db-based-graph?)
|
|
|
+ *doc-ref (rum/use-ref nil)
|
|
|
[loader-state, set-loader-state!] (rum/use-state {:error nil :pdf-document nil :status nil})
|
|
|
[hls-state, set-hls-state!] (rum/use-state {:initial-hls nil :latest-hls nil :extra nil :loaded false :error nil})
|
|
|
[doc-password, set-doc-password!] (rum/use-state nil) ;; use nil to handle empty string
|
|
|
@@ -867,59 +888,75 @@
|
|
|
set-dirty-hls! (fn [latest-hls] ;; TODO: incremental
|
|
|
(set-hls-state! #(merge % {:initial-hls [] :latest-hls latest-hls})))
|
|
|
set-hls-extra! (fn [extra]
|
|
|
- (set-hls-state! #(merge % {:extra extra})))]
|
|
|
+ (if db-based?
|
|
|
+ (debounce-set-last-visit-page! (:block pdf-current) (:page extra))
|
|
|
+ (set-hls-state! #(merge % {:extra extra}))))]
|
|
|
|
|
|
;; current pdf effects
|
|
|
- (rum/use-effect!
|
|
|
- (fn []
|
|
|
- (when pdf-current
|
|
|
- (pdf-assets/ensure-ref-page! pdf-current)))
|
|
|
- [pdf-current])
|
|
|
+ (when-not db-based?
|
|
|
+ (rum/use-effect!
|
|
|
+ (fn []
|
|
|
+ (when pdf-current
|
|
|
+ (pdf-assets/file-based-ensure-ref-page! pdf-current)))
|
|
|
+ [pdf-current]))
|
|
|
|
|
|
;; load highlights
|
|
|
- (rum/use-effect!
|
|
|
- (fn []
|
|
|
- (p/catch
|
|
|
- (p/let [data (pdf-assets/load-hls-data$ pdf-current)
|
|
|
- {:keys [highlights extra]} data]
|
|
|
- (set-initial-page! (or (when-let [page (:page extra)]
|
|
|
- (util/safe-parse-int page)) 1))
|
|
|
- (set-hls-state! {:initial-hls highlights :latest-hls highlights :extra extra :loaded true}))
|
|
|
-
|
|
|
- ;; error
|
|
|
- (fn [^js e]
|
|
|
- (js/console.error "[load hls error]" e)
|
|
|
-
|
|
|
- (let [msg (str (util/format "Error: failed to load the highlights file: \"%s\". \n"
|
|
|
- (:hls-file pdf-current))
|
|
|
- e)]
|
|
|
- (notification/show! msg :error)
|
|
|
- (set-hls-state! {:loaded true :error e}))))
|
|
|
-
|
|
|
- ;; cancel
|
|
|
- #())
|
|
|
- [hls-file])
|
|
|
-
|
|
|
- ;; cache highlights
|
|
|
- (let [persist-hls-data!
|
|
|
- (rum/use-callback
|
|
|
- (util/debounce
|
|
|
- 4000 (fn [latest-hls extra]
|
|
|
- (pdf-assets/persist-hls-data$
|
|
|
- pdf-current latest-hls extra))) [pdf-current])]
|
|
|
-
|
|
|
+ (if db-based?
|
|
|
+ (rum/use-effect!
|
|
|
+ (fn []
|
|
|
+ (when pdf-current
|
|
|
+ (let [pdf-block (:block pdf-current)]
|
|
|
+ (p/let [data (db-async/<get-pdf-annotations repo (:db/id pdf-block))
|
|
|
+ highlights (map :logseq.property.pdf/hl-value data)]
|
|
|
+ (set-initial-page! (or
|
|
|
+ (:logseq.property.asset/last-visit-page pdf-block)
|
|
|
+ 1))
|
|
|
+ (set-hls-state! {:initial-hls highlights :latest-hls highlights :loaded true})))))
|
|
|
+ [pdf-current])
|
|
|
(rum/use-effect!
|
|
|
(fn []
|
|
|
- (when (= :completed (:status loader-state))
|
|
|
- (p/catch
|
|
|
- (when-not (:error hls-state)
|
|
|
- (p/do! (persist-hls-data! (:latest-hls hls-state) (:extra hls-state))))
|
|
|
+ (p/catch
|
|
|
+ (p/let [data (pdf-assets/file-based-load-hls-data$ pdf-current)
|
|
|
+ {:keys [highlights extra]} data]
|
|
|
+ (set-initial-page! (or (when-let [page (:page extra)]
|
|
|
+ (util/safe-parse-int page)) 1))
|
|
|
+ (set-hls-state! {:initial-hls highlights :latest-hls highlights :extra extra :loaded true}))
|
|
|
+
|
|
|
+ ;; error
|
|
|
+ (fn [^js e]
|
|
|
+ (js/console.error "[load hls error]" e)
|
|
|
+
|
|
|
+ (let [msg (str (util/format "Error: failed to load the highlights file: \"%s\". \n"
|
|
|
+ (:hls-file pdf-current))
|
|
|
+ e)]
|
|
|
+ (notification/show! msg :error)
|
|
|
+ (set-hls-state! {:loaded true :error e}))))
|
|
|
+
|
|
|
+ ;; cancel
|
|
|
+ #())
|
|
|
+ [hls-file]))
|
|
|
+
|
|
|
+ ;; cache highlights
|
|
|
+ (when-not db-based?
|
|
|
+ (let [persist-hls-data!
|
|
|
+ (rum/use-callback
|
|
|
+ (util/debounce
|
|
|
+ 4000 (fn [latest-hls extra]
|
|
|
+ (pdf-assets/file-based-persist-hls-data$
|
|
|
+ pdf-current latest-hls extra))) [pdf-current])]
|
|
|
+
|
|
|
+ (rum/use-effect!
|
|
|
+ (fn []
|
|
|
+ (when (= :completed (:status loader-state))
|
|
|
+ (p/catch
|
|
|
+ (when-not (:error hls-state)
|
|
|
+ (p/do! (persist-hls-data! (:latest-hls hls-state) (:extra hls-state))))
|
|
|
|
|
|
;; write hls file error
|
|
|
- (fn [e]
|
|
|
- (js/console.error "[write hls error]" e)))))
|
|
|
+ (fn [e]
|
|
|
+ (js/console.error "[write hls error]" e)))))
|
|
|
|
|
|
- [(:latest-hls hls-state) (:extra hls-state)]))
|
|
|
+ [(:latest-hls hls-state) (:extra hls-state)])))
|
|
|
|
|
|
;; load document
|
|
|
(rum/use-effect!
|
|
|
@@ -969,12 +1006,12 @@
|
|
|
(do
|
|
|
(set-loader-state! {:error nil})
|
|
|
(shui/dialog-open!
|
|
|
- (fn [{:keys [close]}]
|
|
|
- (let [on-password-fn
|
|
|
- (fn [password]
|
|
|
- (close)
|
|
|
- (set-doc-password! password))]
|
|
|
- (pdf-password-input on-password-fn)))))
|
|
|
+ (fn [{:keys [close]}]
|
|
|
+ (let [on-password-fn
|
|
|
+ (fn [password]
|
|
|
+ (close)
|
|
|
+ (set-doc-password! password))]
|
|
|
+ (pdf-password-input on-password-fn)))))
|
|
|
|
|
|
(do
|
|
|
(notification/show!
|
|
|
@@ -1064,9 +1101,9 @@
|
|
|
|
|
|
(when (and (not system-win?) pdf-current)
|
|
|
(js/ReactDOM.createPortal
|
|
|
- (pdf-container-outer
|
|
|
- (pdf-container pdf-current))
|
|
|
- (js/document.querySelector "#app-single-container")))]))
|
|
|
+ (pdf-container-outer
|
|
|
+ (pdf-container pdf-current))
|
|
|
+ (js/document.querySelector "#app-single-container")))]))
|
|
|
|
|
|
(rum/defcs system-embed-playground
|
|
|
< rum/reactive
|