0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-26 08:29:42 -05:00

🐛 Make restore component work in external libraries

This commit is contained in:
Andrés Moya 2022-10-04 15:26:14 +02:00
parent fc01acffc7
commit eb7f93d2e6
3 changed files with 16 additions and 15 deletions

View file

@ -416,28 +416,29 @@
(rx/of (dch/commit-changes changes))))))))
(defn restore-component
"Restore a deleted component, with the given id, on the current file library."
[id]
(us/assert ::us/uuid id)
"Restore a deleted component, with the given id, in the given file library."
[library-id component-id]
(us/assert ::us/uuid library-id)
(us/assert ::us/uuid component-id)
(ptk/reify ::restore-component
ptk/WatchEvent
(watch [it state _]
(let [data (get state :workspace-data)
component (ctf/get-deleted-component data id)
page (ctpl/get-page data (:main-instance-page component))
(let [file-data (wsh/get-file state library-id)
component (ctf/get-deleted-component file-data component-id)
page (ctpl/get-page file-data (:main-instance-page component))
; Make a new main instance, with the same id of the original
[_main-instance shapes]
(ctn/make-component-instance page
component
(:id data)
(:id file-data)
(gpt/point (:main-instance-x component)
(:main-instance-y component))
{:main-instance? true
:force-id (:main-instance-id component)})
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/with-library-data file-data)
(pcb/with-page page))
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
@ -446,9 +447,9 @@
; restore-component change needs to be done after add main instance
; because when undo changes, the orden is inverse
changes (pcb/restore-component changes id)]
changes (pcb/restore-component changes component-id)]
(rx/of (dch/commit-changes changes))))))
(rx/of (dch/commit-changes (assoc changes :file-id library-id)))))))
(defn instantiate-component

View file

@ -372,10 +372,10 @@
has-component? (some true? (map #(contains? % :component-id) shapes))
is-component? (and single? (-> shapes first :component-id some?))
shape-id (->> shapes first :id)
component-id (->> shapes first :component-id)
shape-id (-> shapes first :id)
component-id (-> shapes first :component-id)
component-file (-> shapes first :component-file)
main-component? (->> shapes first :main-instance?)
main-component? (-> shapes first :main-instance?)
component-shapes (filter #(contains? % :component-id) shapes)
components-v2 (features/use-feature :components-v2)
@ -397,7 +397,7 @@
do-navigate-component-file #(st/emit! (dwl/nav-to-component-file component-file))
do-update-component #(st/emit! (dwl/update-component-sync shape-id component-file))
do-update-component-in-bulk #(st/emit! (dwl/update-component-in-bulk component-shapes component-file))
do-restore-component #(st/emit! (dwl/restore-component component-id))
do-restore-component #(st/emit! (dwl/restore-component component-file component-id))
_do-update-remote-component
#(st/emit! (modal/show

View file

@ -64,7 +64,7 @@
#(st/emit! (dwl/update-component-sync id library-id))
do-restore-component
#(st/emit! (dwl/restore-component component-id))
#(st/emit! (dwl/restore-component library-id component-id))
_do-update-remote-component
#(st/emit! (modal/show