mirror of
https://github.com/penpot/penpot.git
synced 2026-09-18 18:06:14 +00:00
🐛 Improve the smartness of the ref-shape-not-found repair script
This commit is contained in:
parent
206f9acfd9
commit
80feaaeed3
@ -275,10 +275,28 @@
|
|||||||
file-data
|
file-data
|
||||||
(-> (get libraries (:component-file root-shape)) :data))
|
(-> (get libraries (:component-file root-shape)) :data))
|
||||||
component (when component-file
|
component (when component-file
|
||||||
(ctkl/get-component (:data component-file) (:component-id root-shape) true))
|
(ctkl/get-component component-file (:component-id root-shape) true))
|
||||||
shapes (ctf/get-component-shapes file-data component)]
|
component-shapes (ctf/get-component-shapes file-data component)]
|
||||||
(d/seek #(= (:shape-ref %) (:shape-ref shape)) shapes))
|
|
||||||
|
|
||||||
|
;; Check if the shape points to the remote main. If so, reassign to the near main.
|
||||||
|
(if-let [near-shape-1 (d/seek #(= (:shape-ref %) (:shape-ref shape)) component-shapes)]
|
||||||
|
near-shape-1
|
||||||
|
;; Check if it points to any random shape in the page. If so, try to find a matchng
|
||||||
|
;; shape in the near main component.
|
||||||
|
(when-let [random-shape (ctn/get-shape page (:shape-ref shape))]
|
||||||
|
(if-let [near-shape-2 (d/seek #(= (:id %) (:shape-ref random-shape)) component-shapes)]
|
||||||
|
near-shape-2
|
||||||
|
;; If not, check if it's a fostered copy and find a direct main.
|
||||||
|
(let [head-shape (ctn/get-head-shape (:objects page) shape)
|
||||||
|
component-file (if (= (:component-file head-shape) (:id file-data))
|
||||||
|
file-data
|
||||||
|
(-> (get libraries (:component-file head-shape)) :data))
|
||||||
|
component (when component-file
|
||||||
|
(ctkl/get-component component-file (:component-id head-shape) true))
|
||||||
|
component-shapes (ctf/get-component-shapes file-data component)]
|
||||||
|
(if-let [near-shape-3 (d/seek #(= (:id %) (:shape-ref random-shape)) component-shapes)]
|
||||||
|
near-shape-3
|
||||||
|
nil))))))
|
||||||
reassign-shape
|
reassign-shape
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(log/debug :hint " -> reassign shape-ref to" :shape-ref (:id matching-shape))
|
(log/debug :hint " -> reassign shape-ref to" :shape-ref (:id matching-shape))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user