mirror of
https://github.com/penpot/penpot.git
synced 2025-08-04 03:18:21 +02:00
✨ Add workspace initialization fix for broken shape references
Is the code that executes at workspace initialization that checks all the shape children for broken references and proceed to emit a special event that fixes the shape children references.
This commit is contained in:
parent
2ec5a3ba6a
commit
7efeeec9b1
4 changed files with 71 additions and 8 deletions
|
@ -93,6 +93,13 @@
|
|||
[:component-id {:optional true} ::sm/uuid]
|
||||
[:ignore-touched {:optional true} :boolean]]]
|
||||
|
||||
[:fix-obj
|
||||
[:map {:title "FixObjChange"}
|
||||
[:type [:= :fix-obj]]
|
||||
[:id ::sm/uuid]
|
||||
[:page-id {:optional true} ::sm/uuid]
|
||||
[:component-id {:optional true} ::sm/uuid]]]
|
||||
|
||||
[:mov-objects
|
||||
[:map {:title "MovObjectsChange"}
|
||||
[:type [:= :mov-objects]]
|
||||
|
@ -218,7 +225,7 @@
|
|||
|
||||
(sm/def! ::changes
|
||||
[:sequential {:gen/max 2} ::change])
|
||||
|
||||
|
||||
(def change?
|
||||
(sm/pred-fn ::change))
|
||||
|
||||
|
@ -337,6 +344,12 @@
|
|||
(d/update-in-when data [:pages-index page-id] ctst/delete-shape id ignore-touched)
|
||||
(d/update-in-when data [:components component-id] ctst/delete-shape id ignore-touched)))
|
||||
|
||||
(defmethod process-change :fix-obj
|
||||
[data {:keys [page-id component-id] :as params}]
|
||||
(if page-id
|
||||
(d/update-in-when data [:pages-index page-id] ctst/fix-shape-children params)
|
||||
(d/update-in-when data [:components component-id] ctst/fix-shape-children params)))
|
||||
|
||||
;; 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
|
||||
|
|
|
@ -90,16 +90,24 @@
|
|||
|
||||
(delete-from-objects [objects]
|
||||
(if-let [target (get objects shape-id)]
|
||||
(let [parent-id (or (:parent-id target)
|
||||
(:frame-id target))
|
||||
children-ids (cph/get-children-ids objects shape-id)]
|
||||
(-> (reduce dissoc objects children-ids)
|
||||
(dissoc shape-id)
|
||||
(let [parent-id (or (:parent-id target)
|
||||
(:frame-id target))
|
||||
children-ids (cph/get-children-ids objects shape-id)]
|
||||
(-> (reduce dissoc objects (cons shape-id children-ids))
|
||||
(d/update-when parent-id delete-from-parent)))
|
||||
objects))]
|
||||
|
||||
(update container :objects delete-from-objects))))
|
||||
|
||||
(defn fix-shape-children
|
||||
"Checks and fix the children relations of the shape. If a children does not
|
||||
exists on the objects tree, it will be removed from shape."
|
||||
[{:keys [objects] :as container} {:keys [id] :as params}]
|
||||
(let [contains? (partial contains? objects)]
|
||||
(d/update-in-when container [:objects id :shapes]
|
||||
(fn [shapes]
|
||||
(into [] (filter contains?) shapes)))))
|
||||
|
||||
(defn get-frames
|
||||
"Retrieves all frame objects as vector"
|
||||
([objects] (get-frames objects nil))
|
||||
|
@ -350,6 +358,7 @@
|
|||
(some? force-id) force-id
|
||||
keep-ids? (:id object)
|
||||
:else (uuid/next))]
|
||||
|
||||
(loop [child-ids (seq (:shapes object))
|
||||
new-direct-children []
|
||||
new-children []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue