mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 04:49:03 -05:00
💄 Update code style and add more coments to :mov-objects change impl.
This commit is contained in:
parent
718a187c1e
commit
6b9d91e2be
2 changed files with 35 additions and 19 deletions
|
@ -945,36 +945,52 @@
|
||||||
(update objects id assoc :parent-id parent-id))
|
(update objects id assoc :parent-id parent-id))
|
||||||
|
|
||||||
;; Updates the frame-id references that might be outdated
|
;; Updates the frame-id references that might be outdated
|
||||||
(update-frame-ids [frame-id objects id]
|
(assign-frame-id [frame-id objects id]
|
||||||
(let [objects (assoc-in objects [id :frame-id] frame-id)
|
(let [objects (update objects id assoc :frame-id frame-id)
|
||||||
obj (get objects id)]
|
obj (get objects id)]
|
||||||
(cond-> objects
|
(cond-> objects
|
||||||
|
;; If we moving frame, the parent frame is the root
|
||||||
|
;; and we DO NOT NEED update children because the
|
||||||
|
;; children will point correctly to the frame what we
|
||||||
|
;; are currently moving
|
||||||
(not= :frame (:type obj))
|
(not= :frame (:type obj))
|
||||||
(as-> $$ (reduce (partial update-frame-ids frame-id) $$ (:shapes obj))))))
|
(as-> $$ (reduce (partial assign-frame-id frame-id) $$ (:shapes obj))))))
|
||||||
|
|
||||||
(move-objects [objects]
|
(move-objects [objects]
|
||||||
(let [valid? (every? (partial is-valid-move? objects) shapes)
|
(let [valid? (every? (partial is-valid-move? objects) shapes)
|
||||||
cpindex (reduce (fn [index id]
|
|
||||||
(let [obj (get objects id)]
|
|
||||||
(assoc! index id (:parent-id obj))))
|
|
||||||
(transient {})
|
|
||||||
(keys objects))
|
|
||||||
cpindex (persistent! cpindex)
|
|
||||||
|
|
||||||
parent (get objects parent-id)
|
;; Create a index of shape ids pointing to the
|
||||||
frame (if (= :frame (:type parent))
|
;; corresponding parents; used mainly for update old
|
||||||
parent
|
;; parents after move operation.
|
||||||
(get objects (:frame-id parent)))
|
cpindex (reduce (fn [index id]
|
||||||
|
(let [obj (get objects id)]
|
||||||
|
(assoc! index id (:parent-id obj))))
|
||||||
|
(transient {})
|
||||||
|
(keys objects))
|
||||||
|
cpindex (persistent! cpindex)
|
||||||
|
|
||||||
frm-id (:id frame)]
|
parent (get objects parent-id)
|
||||||
|
frame-id (if (= :frame (:type parent))
|
||||||
|
(:id parent)
|
||||||
|
(:frame-id parent))]
|
||||||
|
|
||||||
(if valid?
|
(if (and valid? (seq shapes))
|
||||||
(as-> objects $
|
(as-> objects $
|
||||||
|
;; Add the new shapes to the parent object.
|
||||||
(update $ parent-id #(add-to-parent % index shapes))
|
(update $ parent-id #(add-to-parent % index shapes))
|
||||||
|
|
||||||
|
;; Update each individual shapre link to the new parent
|
||||||
(reduce update-parent-id $ shapes)
|
(reduce update-parent-id $ shapes)
|
||||||
|
|
||||||
|
;; Analyze the old parents and clear the old links
|
||||||
|
;; only if the new parrent is different form old
|
||||||
|
;; parent.
|
||||||
(reduce (partial remove-from-old-parent cpindex) $ shapes)
|
(reduce (partial remove-from-old-parent cpindex) $ shapes)
|
||||||
(reduce (partial update-frame-ids frm-id) $ (get-in $ [parent-id :shapes])))
|
|
||||||
objects)))]
|
;; Ensure that all shapes of the new parent has a
|
||||||
|
;; correct link to the topside frame.
|
||||||
|
(reduce (partial assign-frame-id frame-id) $ shapes))
|
||||||
|
objects)))]
|
||||||
|
|
||||||
(if page-id
|
(if page-id
|
||||||
(d/update-in-when data [:pages-index page-id :objects] move-objects)
|
(d/update-in-when data [:pages-index page-id :objects] move-objects)
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
(if-not (contains? shape :content)
|
(if-not (contains? shape :content)
|
||||||
(let [content (gsp/segments->content (:segments shape) (:close? shape))
|
(let [content (gsp/segments->content (:segments shape) (:close? shape))
|
||||||
selrect (gsh/content->selrect content)
|
selrect (gsh/content->selrect content)
|
||||||
points (gsh/rect->points selrect)]
|
points (gsh/rect->points selrect)]
|
||||||
(-> shape
|
(-> shape
|
||||||
(dissoc :segments)
|
(dissoc :segments)
|
||||||
(dissoc :close?)
|
(dissoc :close?)
|
||||||
|
|
Loading…
Add table
Reference in a new issue