mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -05:00
🐛 Fix interactions in viewer
This commit is contained in:
parent
de8220245c
commit
fe6623b342
5 changed files with 31 additions and 25 deletions
|
@ -305,7 +305,11 @@
|
|||
(ptk/reify ::go-to-frame
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [frames (get-in state [:viewer-data :frames])
|
||||
(let [route (:route state)
|
||||
qparams (:query-params route)
|
||||
page-id (:page-id qparams)
|
||||
|
||||
frames (get-in state [:viewer :pages page-id :frames])
|
||||
index (d/index-of-pred frames #(= (:id %) frame-id))]
|
||||
(when index
|
||||
(rx/of (go-to-frame-by-index index)))))))
|
||||
|
@ -320,12 +324,6 @@
|
|||
qparams (:query-params route)]
|
||||
(rx/of (rt/nav :viewer pparams (assoc qparams :section section)))))))
|
||||
|
||||
(defn set-current-frame [frame-id]
|
||||
(ptk/reify ::set-current-frame
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(assoc-in state [:viewer-data :current-frame-id] frame-id))))
|
||||
|
||||
(defn deselect-all []
|
||||
(ptk/reify ::deselect-all
|
||||
ptk/UpdateEvent
|
||||
|
@ -355,7 +353,10 @@
|
|||
(ptk/reify ::shift-select-to
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [objects (get-in state [:viewer-data :objects])
|
||||
(let [route (:route state)
|
||||
qparams (:query-params route)
|
||||
page-id (:page-id qparams)
|
||||
objects (get-in state [:viewer :pages page-id :objects])
|
||||
selection (-> state
|
||||
(get-in [:viewer-local :selected] #{})
|
||||
(conj id))]
|
||||
|
@ -368,8 +369,13 @@
|
|||
(ptk/reify ::select-all
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [objects (get-in state [:viewer-data :objects])
|
||||
frame-id (get-in state [:viewer-data :current-frame-id])
|
||||
(let [route (:route state)
|
||||
qparams (:query-params route)
|
||||
page-id (:page-id qparams)
|
||||
index (:index qparams)
|
||||
objects (get-in state [:viewer :pages page-id :objects])
|
||||
frame-id (get-in state [:viewer :pages page-id :frames index :id])
|
||||
|
||||
selection (->> objects
|
||||
(filter #(= (:frame-id (second %)) frame-id))
|
||||
(map first)
|
||||
|
|
|
@ -51,8 +51,7 @@
|
|||
(mf/use-effect
|
||||
(mf/deps (:id frame))
|
||||
(fn []
|
||||
(st/emit! (dv/set-current-frame (:id frame))
|
||||
(dv/select-shape (:id frame)))))
|
||||
(st/emit! (dv/select-shape (:id frame)))))
|
||||
|
||||
[:*
|
||||
[:& left-sidebar {:frame frame
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
|
||||
(def file-colors-ref
|
||||
(l/derived (l/in [:viewer-data :file :colors]) st/state))
|
||||
(l/derived (l/in [:viewer :file :data :colors]) st/state))
|
||||
|
||||
(defn make-colors-library-ref [file-id]
|
||||
(let [get-library
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
(:content shape))
|
||||
|
||||
(def file-typographies-ref
|
||||
(l/derived (l/in [:viewer-data :file :typographies]) st/state))
|
||||
(l/derived (l/in [:viewer :file :data :typographies]) st/state))
|
||||
|
||||
(defn make-typographies-library-ref [file-id]
|
||||
(let [get-library
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
(prepare-objects page frame))
|
||||
|
||||
wrapper (mf/use-memo
|
||||
(mf/deps objects)
|
||||
(mf/deps objects interactions?)
|
||||
#(shapes/frame-container-factory objects interactions?))
|
||||
|
||||
;; Retrieve frame again with correct modifier
|
||||
|
@ -77,16 +77,17 @@
|
|||
(st/emit! (dcm/close-thread))))]
|
||||
|
||||
(mf/use-effect
|
||||
(fn []
|
||||
;; bind with passive=false to allow the event to be cancelled
|
||||
;; https://stackoverflow.com/a/57582286/3219895
|
||||
(let [key1 (events/listen goog/global "wheel" on-mouse-wheel #js {"passive" false})
|
||||
key2 (events/listen js/window "keydown" on-key-down)
|
||||
key3 (events/listen js/window "click" on-click)]
|
||||
(fn []
|
||||
(events/unlistenByKey key1)
|
||||
(events/unlistenByKey key2)
|
||||
(events/unlistenByKey key3)))))
|
||||
(mf/deps local) ;; on-click event depends on local
|
||||
(fn []
|
||||
;; bind with passive=false to allow the event to be cancelled
|
||||
;; https://stackoverflow.com/a/57582286/3219895
|
||||
(let [key1 (events/listen goog/global "wheel" on-mouse-wheel #js {"passive" false})
|
||||
key2 (events/listen js/window "keydown" on-key-down)
|
||||
key3 (events/listen js/window "click" on-click)]
|
||||
(fn []
|
||||
(events/unlistenByKey key1)
|
||||
(events/unlistenByKey key2)
|
||||
(events/unlistenByKey key3)))))
|
||||
|
||||
[:svg {:view-box (:vbox size)
|
||||
:width (:width size)
|
||||
|
|
Loading…
Reference in a new issue