mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 16:09:17 -05:00
🐛 Fixes problem when moving child
This commit is contained in:
parent
185b1f9ee1
commit
20c6ae867b
3 changed files with 29 additions and 6 deletions
|
@ -37,6 +37,23 @@
|
|||
(:id shape)))]
|
||||
(some check-parenthood (vals objects))))
|
||||
|
||||
(defn calculate-child-parent-map
|
||||
[objects]
|
||||
(let [red-fn
|
||||
(fn [acc {:keys [id shapes]}]
|
||||
;; Insert every pair shape -> parent into accumulated value
|
||||
(into acc (map #(vector % id) (or shapes []))))]
|
||||
(reduce red-fn {} (vals objects))))
|
||||
|
||||
(defn get-all-parents
|
||||
[shape-id objects]
|
||||
(let [child->parent (calculate-child-parent-map objects)
|
||||
rec-fn (fn [cur result]
|
||||
(if-let [parent (child->parent cur)]
|
||||
(recur parent (conj result parent))
|
||||
(vec (reverse result))))]
|
||||
(rec-fn shape-id [])))
|
||||
|
||||
(defn replace-shapes
|
||||
"Replace inside shapes the value `to-replace-id` for the value in items keeping the same order.
|
||||
`to-replace-id` can be a set, a sequable or a single value. Any of these will be changed into a
|
||||
|
|
|
@ -1502,20 +1502,21 @@
|
|||
(let [page-id (::page-id state)
|
||||
objects (get-in state [:workspace-data page-id :objects])
|
||||
groups-to-adjust (->> ids
|
||||
(map #(helpers/get-parent % objects))
|
||||
(mapcat #(reverse (helpers/get-all-parents % objects)))
|
||||
(map #(get objects %))
|
||||
(filter #(= (:type %) :group))
|
||||
(map #(:id %))
|
||||
distinct)
|
||||
|
||||
update-group
|
||||
(fn [group]
|
||||
(let [group-objects (map #(get objects %) (:shapes group))
|
||||
(fn [state group]
|
||||
(let [objects (get-in state [:workspace-data page-id :objects])
|
||||
group-objects (map #(get objects %) (:shapes group))
|
||||
selrect (geom/selection-rect group-objects)]
|
||||
(merge group (select-keys selrect [:x :y :width :height]))))
|
||||
|
||||
reduce-fn
|
||||
#(update-in %1 [:workspace-data page-id :objects %2] update-group)]
|
||||
#(update-in %1 [:workspace-data page-id :objects %2] (partial update-group %1))]
|
||||
|
||||
(reduce reduce-fn state groups-to-adjust)))
|
||||
|
||||
|
|
|
@ -250,10 +250,15 @@
|
|||
[{:keys [shapes selected zoom] :as props}]
|
||||
(let [shape (geom/selection-rect shapes)
|
||||
on-resize #(do (dom/stop-propagation %2)
|
||||
(st/emit! (start-resize %1 selected shape)))]
|
||||
(st/emit! (start-resize %1 selected shape)))
|
||||
|
||||
on-rotate #(do (dom/stop-propagation %)
|
||||
(println "ROTATE!"))]
|
||||
|
||||
[:& controls {:shape shape
|
||||
:zoom zoom
|
||||
:on-resize on-resize}]))
|
||||
:on-resize on-resize
|
||||
:on-rotate on-rotate}]))
|
||||
|
||||
(mf/defc single-selection-handlers
|
||||
[{:keys [shape zoom objects] :as props}]
|
||||
|
|
Loading…
Add table
Reference in a new issue