mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 07:58:49 -05:00
Merge pull request #4131 from penpot/hiru-bugfixes-4
🐛 Fix update main when there are swapped copies
This commit is contained in:
commit
9fbdc10971
4 changed files with 68 additions and 40 deletions
|
@ -166,13 +166,6 @@
|
|||
:else
|
||||
(get-instance-root objects (get objects (:parent-id shape)))))
|
||||
|
||||
(defn get-copy-root
|
||||
"Get the top shape of the copy."
|
||||
[objects shape]
|
||||
(when (:shape-ref shape)
|
||||
(let [parent (cfh/get-parent objects (:id shape))]
|
||||
(or (get-copy-root objects parent) shape))))
|
||||
|
||||
(defn inside-component-main?
|
||||
"Check if the shape is a component main instance or is inside one."
|
||||
[objects shape]
|
||||
|
|
|
@ -190,7 +190,7 @@
|
|||
"Locate the near component in the local file or libraries, and retrieve the shape
|
||||
referenced by the instance shape."
|
||||
[file page libraries shape & {:keys [include-deleted?] :or {include-deleted? false}}]
|
||||
(let [root-shape (ctn/get-copy-root (:objects page) shape)
|
||||
(let [root-shape (ctn/get-component-shape (:objects page) shape)
|
||||
component-file (when root-shape
|
||||
(if (and (some? file) (= (:component-file root-shape) (:id file)))
|
||||
file
|
||||
|
@ -218,10 +218,23 @@
|
|||
component-file (get-in libraries [(:component-file top-instance) :data])
|
||||
component (ctkl/get-component component-file (:component-id top-instance) true)
|
||||
remote-shape (get-ref-shape component-file component shape)
|
||||
component-container (get-component-container component-file component)]
|
||||
component-container (get-component-container component-file component)
|
||||
[remote-shape component-container]
|
||||
(if (some? remote-shape)
|
||||
[remote-shape component-container]
|
||||
;; If not found, try the case of this being a fostered or swapped children
|
||||
(let [head-instance (ctn/get-head-shape (:objects container) shape)
|
||||
component-file (get-in libraries [(:component-file head-instance) :data])
|
||||
head-component (ctkl/get-component component-file (:component-id head-instance) true)
|
||||
remote-shape' (get-ref-shape component-file head-component shape)
|
||||
component-container (get-component-container component-file component)]
|
||||
[remote-shape' component-container]))]
|
||||
|
||||
(if (nil? remote-shape)
|
||||
shape
|
||||
(find-remote-shape component-container libraries remote-shape))))
|
||||
nil
|
||||
(if (nil? (:shape-ref remote-shape))
|
||||
remote-shape
|
||||
(find-remote-shape component-container libraries remote-shape)))))
|
||||
|
||||
(defn get-component-shapes
|
||||
"Retrieve all shapes of the component"
|
||||
|
|
|
@ -77,7 +77,11 @@
|
|||
extract (cond-> {:type (:type change)
|
||||
:raw-change change}
|
||||
shape
|
||||
(assoc :shape (str prefix (:name shape)))
|
||||
(assoc :shape (str prefix (:name shape))
|
||||
:shape-id (str (:id shape)))
|
||||
(:obj change)
|
||||
(assoc :obj (:name (:obj change))
|
||||
:obj-id (:id (:obj change)))
|
||||
(:operations change)
|
||||
(assoc :operations (:operations change)))]
|
||||
extract))]
|
||||
|
|
|
@ -886,7 +886,6 @@
|
|||
(map #(redirect-shaperef %) children-inst)
|
||||
children-inst)
|
||||
|
||||
|
||||
only-inst (fn [changes child-inst]
|
||||
(add-shape-to-main changes
|
||||
child-inst
|
||||
|
@ -1088,10 +1087,8 @@
|
|||
root-main))
|
||||
|
||||
update-original-shape (fn [original-shape new-shape]
|
||||
(if-not (:shape-ref original-shape)
|
||||
(assoc original-shape
|
||||
:shape-ref (:id new-shape))
|
||||
original-shape))
|
||||
(assoc original-shape
|
||||
:shape-ref (:id new-shape)))
|
||||
|
||||
[_new-shape new-shapes updated-shapes]
|
||||
(ctst/clone-shape shape
|
||||
|
@ -1116,25 +1113,46 @@
|
|||
:obj shape'}))))
|
||||
|
||||
mod-obj-change (fn [changes shape']
|
||||
(update changes :redo-changes conj
|
||||
{:type :mod-obj
|
||||
:page-id (:id page)
|
||||
:id (:id shape')
|
||||
:operations [{:type :set
|
||||
:attr :component-id
|
||||
:val (:component-id shape')}
|
||||
{:type :set
|
||||
:attr :component-file
|
||||
:val (:component-file shape')}
|
||||
{:type :set
|
||||
:attr :component-root
|
||||
:val (:component-root shape')}
|
||||
{:type :set
|
||||
:attr :shape-ref
|
||||
:val (:shape-ref shape')}
|
||||
{:type :set
|
||||
:attr :touched
|
||||
:val (:touched shape')}]}))
|
||||
(let [shape-original (ctn/get-shape page (:id shape'))]
|
||||
(-> changes
|
||||
(update :redo-changes conj
|
||||
{:type :mod-obj
|
||||
:page-id (:id page)
|
||||
:id (:id shape')
|
||||
:operations [{:type :set
|
||||
:attr :component-id
|
||||
:val (:component-id shape')}
|
||||
{:type :set
|
||||
:attr :component-file
|
||||
:val (:component-file shape')}
|
||||
{:type :set
|
||||
:attr :component-root
|
||||
:val (:component-root shape')}
|
||||
{:type :set
|
||||
:attr :shape-ref
|
||||
:val (:shape-ref shape')}
|
||||
{:type :set
|
||||
:attr :touched
|
||||
:val (:touched shape')}]})
|
||||
(update :undo-changes conj
|
||||
{:type :mod-obj
|
||||
:page-id (:id page)
|
||||
:id (:id shape-original)
|
||||
:operations [{:type :set
|
||||
:attr :component-id
|
||||
:val (:component-id shape-original)}
|
||||
{:type :set
|
||||
:attr :component-file
|
||||
:val (:component-file shape-original)}
|
||||
{:type :set
|
||||
:attr :component-root
|
||||
:val (:component-root shape-original)}
|
||||
{:type :set
|
||||
:attr :shape-ref
|
||||
:val (:shape-ref shape-original)}
|
||||
{:type :set
|
||||
:attr :touched
|
||||
:val (:touched shape-original)}]}))))
|
||||
|
||||
del-obj-change (fn [changes shape']
|
||||
(update changes :undo-changes conj
|
||||
|
@ -1161,7 +1179,8 @@
|
|||
parents (cfh/get-parent-ids objects (:id shape))
|
||||
parent (first parents)
|
||||
children (cfh/get-children-ids objects (:id shape))
|
||||
ids (into [(:id shape)] children)
|
||||
ids (-> (into [(:id shape)] children)
|
||||
(reverse)) ;; Remove from bottom to top
|
||||
|
||||
add-redo-change (fn [changes id]
|
||||
(update changes :redo-changes conj
|
||||
|
@ -1190,12 +1209,11 @@
|
|||
(update :redo-changes conj (make-change
|
||||
container
|
||||
{:type :reg-objects
|
||||
:shapes (vec parents)}))
|
||||
(add-undo-change (:id shape)))
|
||||
:shapes (vec parents)})))
|
||||
|
||||
changes' (reduce add-undo-change
|
||||
changes'
|
||||
children)]
|
||||
ids)]
|
||||
|
||||
(if (and (cfh/touched-group? parent :shapes-group) omit-touched?)
|
||||
changes
|
||||
|
|
Loading…
Add table
Reference in a new issue