mirror of
https://github.com/penpot/penpot.git
synced 2025-03-12 07:41:43 -05:00
Merge pull request #2407 from penpot/hiru-restore-remote-comp
🐛 Make restore component work in external libraries
This commit is contained in:
commit
0618aa32a0
3 changed files with 16 additions and 15 deletions
|
@ -416,28 +416,29 @@
|
||||||
(rx/of (dch/commit-changes changes))))))))
|
(rx/of (dch/commit-changes changes))))))))
|
||||||
|
|
||||||
(defn restore-component
|
(defn restore-component
|
||||||
"Restore a deleted component, with the given id, on the current file library."
|
"Restore a deleted component, with the given id, in the given file library."
|
||||||
[id]
|
[library-id component-id]
|
||||||
(us/assert ::us/uuid id)
|
(us/assert ::us/uuid library-id)
|
||||||
|
(us/assert ::us/uuid component-id)
|
||||||
(ptk/reify ::restore-component
|
(ptk/reify ::restore-component
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [data (get state :workspace-data)
|
(let [file-data (wsh/get-file state library-id)
|
||||||
component (ctf/get-deleted-component data id)
|
component (ctf/get-deleted-component file-data component-id)
|
||||||
page (ctpl/get-page data (:main-instance-page component))
|
page (ctpl/get-page file-data (:main-instance-page component))
|
||||||
|
|
||||||
; Make a new main instance, with the same id of the original
|
; Make a new main instance, with the same id of the original
|
||||||
[_main-instance shapes]
|
[_main-instance shapes]
|
||||||
(ctn/make-component-instance page
|
(ctn/make-component-instance page
|
||||||
component
|
component
|
||||||
(:id data)
|
(:id file-data)
|
||||||
(gpt/point (:main-instance-x component)
|
(gpt/point (:main-instance-x component)
|
||||||
(:main-instance-y component))
|
(:main-instance-y component))
|
||||||
{:main-instance? true
|
{:main-instance? true
|
||||||
:force-id (:main-instance-id component)})
|
:force-id (:main-instance-id component)})
|
||||||
|
|
||||||
changes (-> (pcb/empty-changes it)
|
changes (-> (pcb/empty-changes it)
|
||||||
(pcb/with-library-data data)
|
(pcb/with-library-data file-data)
|
||||||
(pcb/with-page page))
|
(pcb/with-page page))
|
||||||
|
|
||||||
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
|
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
|
; restore-component change needs to be done after add main instance
|
||||||
; because when undo changes, the orden is inverse
|
; 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
|
(defn instantiate-component
|
||||||
|
|
|
@ -372,10 +372,10 @@
|
||||||
has-component? (some true? (map #(contains? % :component-id) shapes))
|
has-component? (some true? (map #(contains? % :component-id) shapes))
|
||||||
is-component? (and single? (-> shapes first :component-id some?))
|
is-component? (and single? (-> shapes first :component-id some?))
|
||||||
|
|
||||||
shape-id (->> shapes first :id)
|
shape-id (-> shapes first :id)
|
||||||
component-id (->> shapes first :component-id)
|
component-id (-> shapes first :component-id)
|
||||||
component-file (-> shapes first :component-file)
|
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)
|
component-shapes (filter #(contains? % :component-id) shapes)
|
||||||
|
|
||||||
components-v2 (features/use-feature :components-v2)
|
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-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 #(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-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
|
_do-update-remote-component
|
||||||
#(st/emit! (modal/show
|
#(st/emit! (modal/show
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
#(st/emit! (dwl/update-component-sync id library-id))
|
#(st/emit! (dwl/update-component-sync id library-id))
|
||||||
|
|
||||||
do-restore-component
|
do-restore-component
|
||||||
#(st/emit! (dwl/restore-component component-id))
|
#(st/emit! (dwl/restore-component library-id component-id))
|
||||||
|
|
||||||
_do-update-remote-component
|
_do-update-remote-component
|
||||||
#(st/emit! (modal/show
|
#(st/emit! (modal/show
|
||||||
|
|
Loading…
Add table
Reference in a new issue