mirror of
https://github.com/penpot/penpot.git
synced 2025-01-07 15:39:42 -05:00
🐛 Detect correctly swapped subinstances with nested components
This commit is contained in:
parent
6fdefe69ec
commit
c64464b1b5
2 changed files with 15 additions and 21 deletions
|
@ -185,29 +185,24 @@
|
|||
(d/seek #(= (:shape-ref %) (:id main-shape)))))
|
||||
|
||||
(defn find-ref-shape
|
||||
"Locate the near component in the local file or libraries, and retrieve the shape
|
||||
"Locate the nearest 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-component-shape (:objects page) shape)
|
||||
component-file (when root-shape
|
||||
(if (and (some? file) (= (:component-file root-shape) (:id file)))
|
||||
file
|
||||
(get libraries (:component-file root-shape))))
|
||||
component (when component-file
|
||||
(ctkl/get-component (:data component-file) (:component-id root-shape) include-deleted?))
|
||||
ref-shape (when component
|
||||
(get-ref-shape (:data component-file) component shape))]
|
||||
(let [parent-heads (->> (cfh/get-parents-with-self (:objects page) (:id shape))
|
||||
(filter ctk/instance-head?)
|
||||
(reverse))
|
||||
|
||||
(if (some? ref-shape) ; There is a case when we have a nested orphan copy. In this case there is no near
|
||||
ref-shape ; component for this copy, so shape-ref points to the remote main.
|
||||
(let [head-shape (ctn/get-head-shape (:objects page) shape)
|
||||
head-file (if (and (some? file) (= (:component-file head-shape) (:id file)))
|
||||
file
|
||||
(get libraries (:component-file head-shape)))
|
||||
head-component (when (some? head-file)
|
||||
(ctkl/get-component (:data head-file) (:component-id head-shape) include-deleted?))]
|
||||
(when (some? head-component)
|
||||
(get-ref-shape (:data head-file) head-component shape))))))
|
||||
find-ref-shape-in-head
|
||||
(fn [head-shape]
|
||||
(let [head-file (if (and (some? file) (= (:component-file head-shape) (:id file)))
|
||||
file
|
||||
(get libraries (:component-file head-shape)))
|
||||
head-component (when (some? head-file)
|
||||
(ctkl/get-component (:data head-file) (:component-id head-shape) include-deleted?))]
|
||||
(when (some? head-component)
|
||||
(get-ref-shape (:data head-file) head-component shape))))]
|
||||
|
||||
(d/seek find-ref-shape-in-head parent-heads)))
|
||||
|
||||
(defn find-remote-shape
|
||||
"Recursively go back by the :shape-ref of the shape until find the correct shape of the original component"
|
||||
|
|
|
@ -674,7 +674,6 @@
|
|||
(let [omit-touched? (not reset?)
|
||||
clear-remote-synced? (and initial-root? reset?)
|
||||
set-remote-synced? (and (not initial-root?) reset?)
|
||||
|
||||
changes (cond-> changes
|
||||
:always
|
||||
(update-attrs shape-inst
|
||||
|
|
Loading…
Reference in a new issue