mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 07:58:49 -05:00
✨ Improve handling of shape transform modifiers
This commit is contained in:
parent
384b464f0f
commit
ae1e9a861b
6 changed files with 38 additions and 24 deletions
|
@ -424,8 +424,8 @@
|
|||
ids-with-children (concat ids (mapcat #(cp/get-children % objects)
|
||||
(filter not-frame-id? ids)))]
|
||||
|
||||
(d/update-in-when state [:workspace-data :pages-index page-id :objects]
|
||||
#(reduce update-shape % ids-with-children)))))))
|
||||
(update state :workspace-modifiers
|
||||
#(reduce update-shape % ids-with-children)))))))
|
||||
|
||||
|
||||
;; Set-rotation is custom because applies different modifiers to each
|
||||
|
@ -476,9 +476,13 @@
|
|||
(watch [it state stream]
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
children-ids (->> ids (mapcat #(cp/get-children % objects)))
|
||||
ids-with-children (d/concat [] children-ids ids)]
|
||||
ids-with-children (d/concat [] children-ids ids)
|
||||
object-modifiers (get state :workspace-modifiers)]
|
||||
(rx/of (dwu/start-undo-transaction)
|
||||
(dch/update-shapes ids-with-children gsh/transform-shape {:reg-objects? true})
|
||||
(dch/update-shapes ids-with-children (fn [shape]
|
||||
(-> shape
|
||||
(merge (get object-modifiers (:id shape)))
|
||||
(gsh/transform-shape))) {:reg-objects? true})
|
||||
(clear-local-transform)
|
||||
(dwu/commit-undo-transaction))))))
|
||||
|
||||
|
@ -572,4 +576,5 @@
|
|||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(-> state
|
||||
(dissoc :workspace-modifiers)
|
||||
(update :workspace-local dissoc :modifiers :current-move-selected)))))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
@ -209,7 +210,10 @@
|
|||
st/state))
|
||||
|
||||
(def workspace-page-objects
|
||||
(l/derived :objects workspace-page))
|
||||
(l/derived wsh/lookup-page-objects st/state =))
|
||||
|
||||
(def workspace-modifiers
|
||||
(l/derived :workspace-modifiers st/state))
|
||||
|
||||
(def workspace-page-options
|
||||
(l/derived :options workspace-page))
|
||||
|
@ -228,12 +232,21 @@
|
|||
(l/derived #(get % id) workspace-page-objects))
|
||||
|
||||
(defn objects-by-id
|
||||
[ids]
|
||||
(l/derived (fn [objects]
|
||||
(into [] (comp (map #(get objects %))
|
||||
(remove nil?))
|
||||
ids))
|
||||
workspace-page-objects =))
|
||||
([ids]
|
||||
(objects-by-id ids nil))
|
||||
|
||||
([ids {:keys [with-modifiers?]
|
||||
:or { with-modifiers? false }}]
|
||||
(l/derived (fn [state]
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
modifiers (:workspace-modifiers state)
|
||||
objects (cond-> objects
|
||||
with-modifiers?
|
||||
(d/deep-merge modifiers))
|
||||
xform (comp (map #(get objects %))
|
||||
(remove nil?))]
|
||||
(into [] xform ids)))
|
||||
st/state =)))
|
||||
|
||||
(def selected-data
|
||||
(l/derived #(let [selected (wsh/lookup-selected %)
|
||||
|
|
|
@ -235,7 +235,7 @@
|
|||
[{:keys [bounds frame selected-shapes hover-shape zoom]}]
|
||||
(let [selected-ids (into #{} (map :id) selected-shapes)
|
||||
selected-selrect (gsh/selection-rect selected-shapes)
|
||||
hover-selrect (:selrect hover-shape)
|
||||
hover-selrect (-> hover-shape :points gsh/points->selrect)
|
||||
bounds-selrect (bound->selrect bounds)
|
||||
hover-selected-shape? (not (contains? selected-ids (:id hover-shape)))]
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
{:keys [id x y width height]} shape
|
||||
|
||||
childs-ref (mf/use-memo (mf/deps shape) #(refs/objects-by-id (:shapes shape)))
|
||||
childs-ref (mf/use-memo (mf/deps shape) #(refs/objects-by-id (:shapes shape) {:with-modifiers? true}))
|
||||
childs (mf/deref childs-ref)]
|
||||
|
||||
[:> shape-container {:shape shape}
|
||||
|
|
|
@ -59,6 +59,8 @@
|
|||
drawing (mf/deref refs/workspace-drawing)
|
||||
options (mf/deref refs/workspace-page-options)
|
||||
objects (mf/deref refs/workspace-page-objects)
|
||||
object-modifiers (mf/deref refs/workspace-modifiers)
|
||||
objects (d/deep-merge objects object-modifiers)
|
||||
|
||||
;; STATE
|
||||
alt? (mf/use-state false)
|
||||
|
@ -133,8 +135,7 @@
|
|||
show-snap-distance? (and (contains? layout :dynamic-alignment) (= transform :move) (not (empty? selected)))
|
||||
show-snap-points? (and (contains? layout :dynamic-alignment) (or drawing-obj transform))
|
||||
show-selrect? (and selrect (empty? drawing))
|
||||
show-measures? (and (not transform) (not path-editing?) show-distances?)
|
||||
]
|
||||
show-measures? (and (not transform) (not path-editing?) show-distances?)]
|
||||
|
||||
(hooks/setup-dom-events viewport-ref zoom disable-paste in-viewport?)
|
||||
(hooks/setup-viewport-size viewport-ref)
|
||||
|
@ -205,8 +206,7 @@
|
|||
:on-pointer-enter on-pointer-enter
|
||||
:on-pointer-leave on-pointer-leave
|
||||
:on-pointer-move on-pointer-move
|
||||
:on-pointer-up on-pointer-up
|
||||
}
|
||||
:on-pointer-up on-pointer-up}
|
||||
|
||||
[:g {:style {:pointer-events (if disable-events? "none" "auto")}}
|
||||
|
||||
|
@ -222,6 +222,7 @@
|
|||
(when show-selection-handlers?
|
||||
[:& selection/selection-handlers
|
||||
{:selected selected
|
||||
:shapes selected-shapes
|
||||
:zoom zoom
|
||||
:edition edition
|
||||
:disable-handlers (or drawing-tool edition)
|
||||
|
|
|
@ -355,13 +355,8 @@
|
|||
|
||||
(mf/defc selection-handlers
|
||||
{::mf/wrap [mf/memo]}
|
||||
[{:keys [selected edition zoom disable-handlers on-move-selected] :as props}]
|
||||
(let [;; We need remove posible nil values because on shape
|
||||
;; deletion many shape will reamin selected and deleted
|
||||
;; in the same time for small instant of time
|
||||
shapes (->> (mf/deref (refs/objects-by-id selected))
|
||||
(remove nil?))
|
||||
num (count shapes)
|
||||
[{:keys [shapes selected edition zoom disable-handlers on-move-selected] :as props}]
|
||||
(let [num (count shapes)
|
||||
{:keys [id type] :as shape} (first shapes)
|
||||
|
||||
color (if (or (> num 1) (nil? (:shape-ref shape)))
|
||||
|
|
Loading…
Add table
Reference in a new issue