0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 00:01:51 -05:00

♻️ Small refactor set modifiers

This commit is contained in:
Andrés Moya 2021-07-08 13:09:12 +02:00 committed by Alonso Torres
parent 0ff0fd7ced
commit 741d3050ad

View file

@ -227,7 +227,7 @@
(declare start-move) (declare start-move)
(declare start-move-duplicate) (declare start-move-duplicate)
(declare start-local-displacement) (declare set-local-displacement)
(declare clear-local-transform) (declare clear-local-transform)
(defn start-move-selected (defn start-move-selected
@ -342,9 +342,10 @@
(->> position (->> position
(rx/with-latest vector snap-delta) (rx/with-latest vector snap-delta)
(rx/map snap/correct-snap-point) (rx/map snap/correct-snap-point)
(rx/map start-local-displacement)) (rx/map set-local-displacement))
(rx/of (apply-modifiers ids {:set-modifiers? true}) (rx/of (set-modifiers ids)
(apply-modifiers ids)
(calculate-frame-for-move ids) (calculate-frame-for-move ids)
(finish-transform))))))))) (finish-transform)))))))))
@ -396,10 +397,11 @@
(->> move-events (->> move-events
(rx/take-until stopper) (rx/take-until stopper)
(rx/scan #(gpt/add %1 mov-vec) (gpt/point 0 0)) (rx/scan #(gpt/add %1 mov-vec) (gpt/point 0 0))
(rx/map start-local-displacement)) (rx/map set-local-displacement))
(rx/of (move-selected direction shift?))) (rx/of (move-selected direction shift?)))
(rx/of (apply-modifiers selected {:set-modifiers? true}) (rx/of (set-modifiers selected)
(apply-modifiers selected)
(finish-transform)))) (finish-transform))))
(rx/empty)))))) (rx/empty))))))
@ -537,49 +539,39 @@
(rx/of (apply-modifiers ids))))))) (rx/of (apply-modifiers ids)))))))
(defn apply-modifiers (defn apply-modifiers
([ids] [ids]
(apply-modifiers ids nil)) (us/verify (s/coll-of uuid?) ids)
(ptk/reify ::apply-modifiers
ptk/WatchEvent
(watch [_ state _]
(let [objects (wsh/lookup-page-objects state)
children-ids (->> ids (mapcat #(cp/get-children % objects)))
ids-with-children (d/concat [] children-ids ids)
object-modifiers (get state :workspace-modifiers)
ignore-tree (d/mapm #(get-in %2 [:modifiers :ignore-geometry?]) object-modifiers)]
([ids {:keys [set-modifiers?] (rx/of (dwu/start-undo-transaction)
:or {set-modifiers? false}}] (dch/update-shapes
(us/verify (s/coll-of uuid?) ids) ids-with-children
(ptk/reify ::apply-modifiers (fn [shape]
ptk/WatchEvent (-> shape
(watch [_ state _] (merge (get object-modifiers (:id shape)))
(let [objects (wsh/lookup-page-objects state) (gsh/transform-shape)))
children-ids (->> ids (mapcat #(cp/get-children % objects))) {:reg-objects? true
ids-with-children (d/concat [] children-ids ids) :ignore-tree ignore-tree
;; Attributes that can change in the transform. This way we don't have to check
state (if set-modifiers? ;; all the attributes
(ptk/update (set-modifiers ids) state) :attrs [:selrect :points
state) :x :y
object-modifiers (get state :workspace-modifiers) :width :height
:content
ignore-tree (d/mapm #(get-in %2 [:modifiers :ignore-geometry?]) object-modifiers)] :transform
:transform-inverse
(rx/of (dwu/start-undo-transaction) :rotation
(dch/update-shapes :flip-x
ids-with-children :flip-y]})
(fn [shape] (clear-local-transform)
(-> shape (dwu/commit-undo-transaction))))))
(merge (get object-modifiers (:id shape)))
(gsh/transform-shape)))
{:reg-objects? true
:ignore-tree ignore-tree
;; Attributes that can change in the transform. This way we don't have to check
;; all the attributes
:attrs [:selrect :points
:x :y
:width :height
:content
:transform
:transform-inverse
:rotation
:flip-x
:flip-y]
})
(clear-local-transform)
(dwu/commit-undo-transaction)))))))
;; --- Update Dimensions ;; --- Update Dimensions
@ -649,7 +641,7 @@
:displacement (gmt/translate-matrix (gpt/point 0 (- (:height selrect))))}) :displacement (gmt/translate-matrix (gpt/point 0 (- (:height selrect))))})
(apply-modifiers selected)))))) (apply-modifiers selected))))))
(defn start-local-displacement [point] (defn set-local-displacement [point]
(ptk/reify ::start-local-displacement (ptk/reify ::start-local-displacement
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]