0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 06:58:58 -05:00

🐛 Detect correctly swapped subinstances with nested components

This commit is contained in:
Andrés Moya 2024-02-20 17:38:38 +01:00
parent 6fdefe69ec
commit c64464b1b5
2 changed files with 15 additions and 21 deletions

View file

@ -185,29 +185,24 @@
(d/seek #(= (:shape-ref %) (:id main-shape))))) (d/seek #(= (:shape-ref %) (:id main-shape)))))
(defn find-ref-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." referenced by the instance shape."
[file page libraries shape & {:keys [include-deleted?] :or {include-deleted? false}}] [file page libraries shape & {:keys [include-deleted?] :or {include-deleted? false}}]
(let [root-shape (ctn/get-component-shape (:objects page) shape) (let [parent-heads (->> (cfh/get-parents-with-self (:objects page) (:id shape))
component-file (when root-shape (filter ctk/instance-head?)
(if (and (some? file) (= (:component-file root-shape) (:id file))) (reverse))
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))]
(if (some? ref-shape) ; There is a case when we have a nested orphan copy. In this case there is no near find-ref-shape-in-head
ref-shape ; component for this copy, so shape-ref points to the remote main. (fn [head-shape]
(let [head-shape (ctn/get-head-shape (:objects page) shape) (let [head-file (if (and (some? file) (= (:component-file head-shape) (:id file)))
head-file (if (and (some? file) (= (:component-file head-shape) (:id file))) file
file (get libraries (:component-file head-shape)))
(get libraries (:component-file head-shape))) head-component (when (some? head-file)
head-component (when (some? head-file) (ctkl/get-component (:data head-file) (:component-id head-shape) include-deleted?))]
(ctkl/get-component (:data head-file) (:component-id head-shape) include-deleted?))] (when (some? head-component)
(when (some? head-component) (get-ref-shape (:data head-file) head-component shape))))]
(get-ref-shape (:data head-file) head-component shape))))))
(d/seek find-ref-shape-in-head parent-heads)))
(defn find-remote-shape (defn find-remote-shape
"Recursively go back by the :shape-ref of the shape until find the correct shape of the original component" "Recursively go back by the :shape-ref of the shape until find the correct shape of the original component"

View file

@ -674,7 +674,6 @@
(let [omit-touched? (not reset?) (let [omit-touched? (not reset?)
clear-remote-synced? (and initial-root? reset?) clear-remote-synced? (and initial-root? reset?)
set-remote-synced? (and (not initial-root?) reset?) set-remote-synced? (and (not initial-root?) reset?)
changes (cond-> changes changes (cond-> changes
:always :always
(update-attrs shape-inst (update-attrs shape-inst