0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

🐛 Fix interactions in viewer

This commit is contained in:
Andrés Moya 2021-09-10 11:13:48 +02:00 committed by Andrey Antukh
parent de8220245c
commit fe6623b342
5 changed files with 31 additions and 25 deletions

View file

@ -305,7 +305,11 @@
(ptk/reify ::go-to-frame (ptk/reify ::go-to-frame
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (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))] index (d/index-of-pred frames #(= (:id %) frame-id))]
(when index (when index
(rx/of (go-to-frame-by-index index))))))) (rx/of (go-to-frame-by-index index)))))))
@ -320,12 +324,6 @@
qparams (:query-params route)] qparams (:query-params route)]
(rx/of (rt/nav :viewer pparams (assoc qparams :section section))))))) (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 [] (defn deselect-all []
(ptk/reify ::deselect-all (ptk/reify ::deselect-all
ptk/UpdateEvent ptk/UpdateEvent
@ -355,7 +353,10 @@
(ptk/reify ::shift-select-to (ptk/reify ::shift-select-to
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (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 selection (-> state
(get-in [:viewer-local :selected] #{}) (get-in [:viewer-local :selected] #{})
(conj id))] (conj id))]
@ -368,8 +369,13 @@
(ptk/reify ::select-all (ptk/reify ::select-all
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [objects (get-in state [:viewer-data :objects]) (let [route (:route state)
frame-id (get-in state [:viewer-data :current-frame-id]) 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 selection (->> objects
(filter #(= (:frame-id (second %)) frame-id)) (filter #(= (:frame-id (second %)) frame-id))
(map first) (map first)

View file

@ -51,8 +51,7 @@
(mf/use-effect (mf/use-effect
(mf/deps (:id frame)) (mf/deps (:id frame))
(fn [] (fn []
(st/emit! (dv/set-current-frame (:id frame)) (st/emit! (dv/select-shape (:id frame)))))
(dv/select-shape (:id frame)))))
[:* [:*
[:& left-sidebar {:frame frame [:& left-sidebar {:frame frame

View file

@ -19,7 +19,7 @@
(def file-colors-ref (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] (defn make-colors-library-ref [file-id]
(let [get-library (let [get-library

View file

@ -22,7 +22,7 @@
(:content shape)) (:content shape))
(def file-typographies-ref (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] (defn make-typographies-library-ref [file-id]
(let [get-library (let [get-library

View file

@ -49,7 +49,7 @@
(prepare-objects page frame)) (prepare-objects page frame))
wrapper (mf/use-memo wrapper (mf/use-memo
(mf/deps objects) (mf/deps objects interactions?)
#(shapes/frame-container-factory objects interactions?)) #(shapes/frame-container-factory objects interactions?))
;; Retrieve frame again with correct modifier ;; Retrieve frame again with correct modifier
@ -77,6 +77,7 @@
(st/emit! (dcm/close-thread))))] (st/emit! (dcm/close-thread))))]
(mf/use-effect (mf/use-effect
(mf/deps local) ;; on-click event depends on local
(fn [] (fn []
;; bind with passive=false to allow the event to be cancelled ;; bind with passive=false to allow the event to be cancelled
;; https://stackoverflow.com/a/57582286/3219895 ;; https://stackoverflow.com/a/57582286/3219895