mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🔥 Remove obsolete code on :move-objects related to old components
This commit is contained in:
committed by
Alejandro Alonso
parent
bd65f3932e
commit
53d8a2d6d7
@@ -692,8 +692,6 @@
|
|||||||
(d/update-in-when data [:pages-index page-id] fix-container)
|
(d/update-in-when data [:pages-index page-id] fix-container)
|
||||||
(d/update-in-when data [:components component-id] fix-container))))
|
(d/update-in-when data [:components component-id] fix-container))))
|
||||||
|
|
||||||
;; FIXME: remove, seems like this method is already unused
|
|
||||||
;; reg-objects operation "regenerates" the geometry and selrect of the parent groups
|
|
||||||
(defmethod process-change :reg-objects
|
(defmethod process-change :reg-objects
|
||||||
[data {:keys [page-id component-id shapes]}]
|
[data {:keys [page-id component-id shapes]}]
|
||||||
;; FIXME: Improve performance
|
;; FIXME: Improve performance
|
||||||
@@ -744,26 +742,36 @@
|
|||||||
(d/update-in-when data [:components component-id :objects] reg-objects))))
|
(d/update-in-when data [:components component-id :objects] reg-objects))))
|
||||||
|
|
||||||
(defmethod process-change :mov-objects
|
(defmethod process-change :mov-objects
|
||||||
[data {:keys [parent-id shapes index page-id component-id ignore-touched after-shape allow-altering-copies syncing]}]
|
;; FIXME: ignore-touched is no longer used, so we can consider it deprecated
|
||||||
|
[data {:keys [parent-id shapes index page-id component-id #_ignore-touched after-shape allow-altering-copies syncing]}]
|
||||||
(letfn [(calculate-invalid-targets [objects shape-id]
|
(letfn [(calculate-invalid-targets [objects shape-id]
|
||||||
(let [reduce-fn #(into %1 (calculate-invalid-targets objects %2))]
|
(let [reduce-fn #(into %1 (calculate-invalid-targets objects %2))]
|
||||||
(->> (get-in objects [shape-id :shapes])
|
(->> (get-in objects [shape-id :shapes])
|
||||||
(reduce reduce-fn #{shape-id}))))
|
(reduce reduce-fn #{shape-id}))))
|
||||||
|
|
||||||
;; Avoid placing a shape as a direct or indirect child of itself,
|
;; Avoid placing a shape as a direct or indirect child of itself, or
|
||||||
;; or inside its main component if it's in a copy,
|
;; inside its main component if it's in a copy, or inside a copy, or
|
||||||
;; or inside a copy, or from a copy
|
;; from a copy
|
||||||
(is-valid-move? [objects shape-id]
|
(is-valid-move? [objects shape-id]
|
||||||
(let [invalid-targets (calculate-invalid-targets objects shape-id)
|
(let [invalid-targets (calculate-invalid-targets objects shape-id)
|
||||||
shape (get objects shape-id)]
|
shape (get objects shape-id)]
|
||||||
(and shape
|
(and shape
|
||||||
(not (invalid-targets parent-id))
|
(not (invalid-targets parent-id))
|
||||||
(not (cfh/components-nesting-loop? objects shape-id parent-id))
|
(not (cfh/components-nesting-loop? objects shape-id parent-id))
|
||||||
(or allow-altering-copies ;; In some cases (like a component swap) it's allowed to change the structure of a copy
|
(or
|
||||||
syncing ;; If we are syncing the changes of a main component, it's allowed to change the structure of a copy
|
;; In some cases (like a component
|
||||||
(and
|
;; swap) it's allowed to change the
|
||||||
(not (ctk/in-component-copy? (get objects (:parent-id shape)))) ;; We don't want to change the structure of component copies
|
;; structure of a copy
|
||||||
(not (ctk/in-component-copy? (get objects parent-id)))))))) ;; We need to check the origin and target frames
|
allow-altering-copies
|
||||||
|
|
||||||
|
;; DEPRECATED, remove once v2.12 released
|
||||||
|
syncing
|
||||||
|
|
||||||
|
(and
|
||||||
|
;; We don't want to change the structure of component copies
|
||||||
|
(not (ctk/in-component-copy? (get objects (:parent-id shape))))
|
||||||
|
;; We need to check the origin and target frames
|
||||||
|
(not (ctk/in-component-copy? (get objects parent-id))))))))
|
||||||
|
|
||||||
(insert-items [prev-shapes index shapes]
|
(insert-items [prev-shapes index shapes]
|
||||||
(let [prev-shapes (or prev-shapes [])]
|
(let [prev-shapes (or prev-shapes [])]
|
||||||
@@ -772,17 +780,13 @@
|
|||||||
(cfh/append-at-the-end prev-shapes shapes))))
|
(cfh/append-at-the-end prev-shapes shapes))))
|
||||||
|
|
||||||
(add-to-parent [parent index shapes]
|
(add-to-parent [parent index shapes]
|
||||||
(let [parent (-> parent
|
(update parent :shapes
|
||||||
(update :shapes insert-items index shapes)
|
(fn [parent-shapes]
|
||||||
;; We need to ensure that no `nil` in the
|
(-> parent-shapes
|
||||||
;; shapes list after adding all the
|
(insert-items index shapes)
|
||||||
;; incoming shapes to the parent.
|
;; We need to ensure that no `nil` in the shapes list
|
||||||
(update :shapes d/vec-without-nils))]
|
;; after adding all the incoming shapes to the parent.
|
||||||
(cond-> parent
|
(d/vec-without-nils)))))
|
||||||
(and (:shape-ref parent)
|
|
||||||
(#{:group :frame} (:type parent))
|
|
||||||
(not ignore-touched))
|
|
||||||
(dissoc :remote-synced))))
|
|
||||||
|
|
||||||
(remove-from-old-parent [old-objects objects shape-id]
|
(remove-from-old-parent [old-objects objects shape-id]
|
||||||
(let [prev-parent-id (dm/get-in old-objects [shape-id :parent-id])]
|
(let [prev-parent-id (dm/get-in old-objects [shape-id :parent-id])]
|
||||||
@@ -790,32 +794,28 @@
|
|||||||
;; the new destination target parent id.
|
;; the new destination target parent id.
|
||||||
(if (= prev-parent-id parent-id)
|
(if (= prev-parent-id parent-id)
|
||||||
objects
|
objects
|
||||||
(let [sid shape-id
|
(d/update-in-when objects [prev-parent-id :shapes]
|
||||||
pid prev-parent-id
|
(fn [shapes]
|
||||||
obj (get objects pid)
|
(-> shapes
|
||||||
component? (and (:shape-ref obj)
|
(d/without-obj shape-id)
|
||||||
(= (:type obj) :group)
|
(d/vec-without-nils)))))))
|
||||||
(not ignore-touched))]
|
|
||||||
(-> objects
|
|
||||||
(d/update-in-when [pid :shapes] d/without-obj sid)
|
|
||||||
(d/update-in-when [pid :shapes] d/vec-without-nils)
|
|
||||||
(cond-> component? (d/update-when pid #(dissoc % :remote-synced))))))))
|
|
||||||
|
|
||||||
(update-parent-id [objects id]
|
(update-parent-id [objects id]
|
||||||
(-> objects
|
(d/update-when objects id assoc :parent-id parent-id))
|
||||||
(d/update-when id assoc :parent-id parent-id)))
|
|
||||||
|
|
||||||
;; Updates the frame-id references that might be outdated
|
;; Updates the frame-id references that might be outdated
|
||||||
(assign-frame-id [frame-id objects id]
|
(update-frame-id [frame-id objects id]
|
||||||
(let [objects (d/update-when objects id assoc :frame-id frame-id)
|
(let [obj (some-> (get objects id)
|
||||||
obj (get objects id)]
|
(assoc :frame-id frame-id))]
|
||||||
(cond-> objects
|
(cond-> objects
|
||||||
;; If we moving frame, the parent frame is the root
|
(some? obj)
|
||||||
;; and we DO NOT NEED update children because the
|
(assoc id obj)
|
||||||
;; children will point correctly to the frame what we
|
|
||||||
;; are currently moving
|
;; If we moving a frame, we DO NOT NEED update
|
||||||
(not= :frame (:type obj))
|
;; children because the children will point correctly
|
||||||
(as-> $$ (reduce (partial assign-frame-id frame-id) $$ (:shapes obj))))))
|
;; to the frame what we are currently moving
|
||||||
|
(not (cfh/frame-shape? obj))
|
||||||
|
(as-> $$ (reduce (partial update-frame-id frame-id) $$ (:shapes obj))))))
|
||||||
|
|
||||||
(move-objects [objects]
|
(move-objects [objects]
|
||||||
(let [parent (get objects parent-id)]
|
(let [parent (get objects parent-id)]
|
||||||
|
|||||||
@@ -1512,7 +1512,7 @@
|
|||||||
:shapes [(:id shape)]
|
:shapes [(:id shape)]
|
||||||
:index index-after
|
:index index-after
|
||||||
:ignore-touched true
|
:ignore-touched true
|
||||||
:syncing true}))
|
:allow-altering-copies true}))
|
||||||
(update :undo-changes conj (make-change
|
(update :undo-changes conj (make-change
|
||||||
container
|
container
|
||||||
{:type :mov-objects
|
{:type :mov-objects
|
||||||
@@ -1520,7 +1520,7 @@
|
|||||||
:shapes [(:id shape)]
|
:shapes [(:id shape)]
|
||||||
:index index-before
|
:index index-before
|
||||||
:ignore-touched true
|
:ignore-touched true
|
||||||
:syncing true})))]
|
:allow-altering-copies true})))]
|
||||||
|
|
||||||
(if (and (ctk/touched-group? parent :shapes-group) omit-touched?)
|
(if (and (ctk/touched-group? parent :shapes-group) omit-touched?)
|
||||||
changes
|
changes
|
||||||
|
|||||||
Reference in New Issue
Block a user