mirror of
https://github.com/penpot/penpot.git
synced 2025-02-26 08:45:34 -05:00
✨ Fix interaction targets
This commit is contained in:
parent
a774f4d4fa
commit
2799c09294
2 changed files with 28 additions and 31 deletions
|
@ -384,7 +384,9 @@
|
||||||
(rx/of (rt/nav screen pparams (assoc qparams :index index)))))))
|
(rx/of (rt/nav screen pparams (assoc qparams :index index)))))))
|
||||||
|
|
||||||
(defn go-to-frame
|
(defn go-to-frame
|
||||||
([frame-id] (go-to-frame frame-id nil))
|
([frame-id]
|
||||||
|
(go-to-frame frame-id nil))
|
||||||
|
|
||||||
([frame-id animation]
|
([frame-id animation]
|
||||||
(us/verify ::us/uuid frame-id)
|
(us/verify ::us/uuid frame-id)
|
||||||
(us/verify (s/nilable ::cti/animation) animation)
|
(us/verify (s/nilable ::cti/animation) animation)
|
||||||
|
@ -414,8 +416,7 @@
|
||||||
page-id (:page-id qparams)
|
page-id (:page-id qparams)
|
||||||
frames (get-in state [:viewer :pages page-id :frames])
|
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
|
(rx/of (go-to-frame-by-index (or index 0))))))))
|
||||||
(rx/of (go-to-frame-by-index index))))))))
|
|
||||||
|
|
||||||
(defn go-to-frame-auto
|
(defn go-to-frame-auto
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -171,25 +171,30 @@
|
||||||
(rx/map #(move-edit-interaction initial-pos %)))
|
(rx/map #(move-edit-interaction initial-pos %)))
|
||||||
(rx/of (finish-edit-interaction index initial-pos))))))))
|
(rx/of (finish-edit-interaction index initial-pos))))))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn get-target-frame
|
||||||
|
[state position]
|
||||||
|
|
||||||
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
|
from-id (-> state wsh/lookup-selected first)
|
||||||
|
from-shape (wsh/lookup-shape state from-id)
|
||||||
|
|
||||||
|
from-frame-id (if (cph/frame-shape? from-shape)
|
||||||
|
from-id (:frame-id from-shape))
|
||||||
|
|
||||||
|
target-frame (cph/frame-by-position objects position)]
|
||||||
|
|
||||||
|
(when (and (not= (:id target-frame) uuid/zero)
|
||||||
|
(not= (:id target-frame) from-frame-id)
|
||||||
|
(not (:hide-in-viewer target-frame)))
|
||||||
|
target-frame)))
|
||||||
|
|
||||||
(defn move-edit-interaction
|
(defn move-edit-interaction
|
||||||
[initial-pos position]
|
[_initial-pos position]
|
||||||
(ptk/reify ::move-edit-interaction
|
(ptk/reify ::move-edit-interaction
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [page-id (:current-page-id state)
|
(let [end-frame (get-target-frame state position)]
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
|
||||||
selected-shape-id (-> state wsh/lookup-selected first)
|
|
||||||
selected-shape (get objects selected-shape-id)
|
|
||||||
selected-shape-frame-id (:frame-id selected-shape)
|
|
||||||
start-frame (get objects selected-shape-frame-id)
|
|
||||||
end-frame (cph/frame-by-position objects position)
|
|
||||||
|
|
||||||
position (when (not= position initial-pos) position)
|
|
||||||
end-frame (when (and (not= (:id end-frame) uuid/zero )
|
|
||||||
(not= (:id end-frame) (:id start-frame))
|
|
||||||
(not= (:id end-frame) selected-shape-id)
|
|
||||||
(not (:hide-in-viewer end-frame)))
|
|
||||||
end-frame)]
|
|
||||||
(-> state
|
(-> state
|
||||||
(assoc-in [:workspace-local :draw-interaction-to] position)
|
(assoc-in [:workspace-local :draw-interaction-to] position)
|
||||||
(assoc-in [:workspace-local :draw-interaction-to-frame] end-frame))))))
|
(assoc-in [:workspace-local :draw-interaction-to-frame] end-frame))))))
|
||||||
|
@ -207,18 +212,9 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [position @ms/mouse-position
|
(let [position @ms/mouse-position
|
||||||
page-id (:current-page-id state)
|
target-frame (get-target-frame state position)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
|
||||||
target-frame (cph/frame-by-position objects position)
|
|
||||||
|
|
||||||
shape-id (-> state wsh/lookup-selected first)
|
shape-id (-> state wsh/lookup-selected first)
|
||||||
shape (get objects shape-id)
|
shape (wsh/lookup-shape state shape-id)
|
||||||
|
|
||||||
invalid-target? (or (nil? target-frame)
|
|
||||||
(= (:id target-frame) uuid/zero)
|
|
||||||
(= (:id target-frame) (:id shape))
|
|
||||||
(= (:id target-frame) (:frame-id shape))
|
|
||||||
(:hide-in-viewer target-frame))
|
|
||||||
|
|
||||||
change-interaction
|
change-interaction
|
||||||
(fn [interaction]
|
(fn [interaction]
|
||||||
|
@ -236,11 +232,11 @@
|
||||||
(= position initial-pos)
|
(= position initial-pos)
|
||||||
|
|
||||||
;; New interaction but invalid target
|
;; New interaction but invalid target
|
||||||
(and (nil? index) invalid-target?))
|
(and (nil? index) (nil? target-frame)))
|
||||||
nil
|
nil
|
||||||
|
|
||||||
;; Dropped interaction in an invalid target. We remove it
|
;; Dropped interaction in an invalid target. We remove it
|
||||||
(and (some? index) invalid-target?)
|
(and (some? index) (nil? target-frame))
|
||||||
(rx/of (remove-interaction shape index))
|
(rx/of (remove-interaction shape index))
|
||||||
|
|
||||||
(nil? index)
|
(nil? index)
|
||||||
|
|
Loading…
Add table
Reference in a new issue