mirror of https://github.com/logseq/logseq
improve(pdf): support context menu for pdf highlight region
parent
b7b0822152
commit
1bfd1203a4
|
@ -94,12 +94,10 @@
|
||||||
(let [mounted (rum/use-ref false)]
|
(let [mounted (rum/use-ref false)]
|
||||||
(rum/use-effect!
|
(rum/use-effect!
|
||||||
(fn []
|
(fn []
|
||||||
(let [cb #(if-not (rum/deref mounted)
|
(let [cb #(clear-ctx-tip!)]
|
||||||
(rum/set-ref! mounted true)
|
(js/setTimeout #(js/document.addEventListener "click" cb))
|
||||||
(clear-ctx-tip!))]
|
|
||||||
(js/document.addEventListener "click" cb)
|
|
||||||
#(js/document.removeEventListener "click" cb)))
|
#(js/document.removeEventListener "click" cb)))
|
||||||
[clear-ctx-tip!]))
|
[]))
|
||||||
|
|
||||||
;; TODO: precise position
|
;; TODO: precise position
|
||||||
;;(when-let [
|
;;(when-let [
|
||||||
|
@ -169,14 +167,17 @@
|
||||||
|
|
||||||
(let [id (:id hl)
|
(let [id (:id hl)
|
||||||
{:keys [rects]} (:position vw-hl)
|
{:keys [rects]} (:position vw-hl)
|
||||||
{:keys [color]} (:properties hl)]
|
{:keys [color]} (:properties hl)
|
||||||
[:div.extensions__pdf-hls-text-region
|
open-tip! (fn [^js/MouseEvent e]
|
||||||
{:on-click
|
(.preventDefault e)
|
||||||
(fn [^js/MouseEvent e]
|
(let [x (.-clientX e)
|
||||||
(let [x (.-clientX e)
|
y (.-clientY e)]
|
||||||
y (.-clientY e)]
|
|
||||||
|
|
||||||
(show-ctx-tip! viewer hl {:x x :y y})))}
|
(show-ctx-tip! viewer hl {:x x :y y})))]
|
||||||
|
|
||||||
|
[:div.extensions__pdf-hls-text-region
|
||||||
|
{:on-click open-tip!
|
||||||
|
:on-context-menu open-tip!}
|
||||||
|
|
||||||
(map-indexed
|
(map-indexed
|
||||||
(fn [idx rect]
|
(fn [idx rect]
|
||||||
|
@ -191,7 +192,14 @@
|
||||||
{:keys [show-ctx-tip! upd-hl!]}]
|
{:keys [show-ctx-tip! upd-hl!]}]
|
||||||
|
|
||||||
(let [*el (rum/use-ref nil)
|
(let [*el (rum/use-ref nil)
|
||||||
*dirty (rum/use-ref nil)]
|
*dirty (rum/use-ref nil)
|
||||||
|
open-tip! (fn [^js/MouseEvent e]
|
||||||
|
(.preventDefault e)
|
||||||
|
(when-not (rum/deref *dirty)
|
||||||
|
(let [x (.-clientX e)
|
||||||
|
y (.-clientY e)]
|
||||||
|
|
||||||
|
(show-ctx-tip! viewer hl {:x x :y y}))))]
|
||||||
|
|
||||||
;; resizable
|
;; resizable
|
||||||
(rum/use-effect!
|
(rum/use-effect!
|
||||||
|
@ -275,15 +283,11 @@
|
||||||
(when-let [vw-bounding (get-in vw-hl [:position :bounding])]
|
(when-let [vw-bounding (get-in vw-hl [:position :bounding])]
|
||||||
(let [{:keys [color]} (:properties hl)]
|
(let [{:keys [color]} (:properties hl)]
|
||||||
[:div.extensions__pdf-hls-area-region
|
[:div.extensions__pdf-hls-area-region
|
||||||
{:ref *el
|
{:ref *el
|
||||||
:style vw-bounding
|
:style vw-bounding
|
||||||
:data-color color
|
:data-color color
|
||||||
:on-click (fn [^js/MouseEvent e]
|
:on-click open-tip!
|
||||||
(when-not (rum/deref *dirty)
|
:on-context-menu open-tip!}]))))
|
||||||
(let [x (.-clientX e)
|
|
||||||
y (.-clientY e)]
|
|
||||||
|
|
||||||
(show-ctx-tip! viewer hl {:x x :y y}))))}]))))
|
|
||||||
|
|
||||||
(rum/defc pdf-highlights-region-container
|
(rum/defc pdf-highlights-region-container
|
||||||
[^js viewer page-hls ops]
|
[^js viewer page-hls ops]
|
||||||
|
|
Loading…
Reference in New Issue