mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 23:31:39 +02:00
🎉 Allow to duplicate a component
This commit is contained in:
parent
03c8b42296
commit
8165fec50e
4 changed files with 52 additions and 1 deletions
|
@ -2118,6 +2118,14 @@
|
||||||
"es" : "Borrar"
|
"es" : "Borrar"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"workspace.assets.duplicate" : {
|
||||||
|
"translations" : {
|
||||||
|
"en" : "Duplicate",
|
||||||
|
"fr" : "",
|
||||||
|
"ru" : "",
|
||||||
|
"es" : "Duplicar"
|
||||||
|
}
|
||||||
|
},
|
||||||
"workspace.assets.edit" : {
|
"workspace.assets.edit" : {
|
||||||
"used-in" : [ "src/app/main/ui/workspace/sidebar/assets.cljs:305", "src/app/main/ui/workspace/sidebar/assets.cljs:433" ],
|
"used-in" : [ "src/app/main/ui/workspace/sidebar/assets.cljs:305", "src/app/main/ui/workspace/sidebar/assets.cljs:433" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
|
|
|
@ -253,6 +253,33 @@
|
||||||
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
||||||
(dws/select-shapes (d/ordered-set (:id group))))))))))
|
(dws/select-shapes (d/ordered-set (:id group))))))))))
|
||||||
|
|
||||||
|
(defn duplicate-component
|
||||||
|
"Create a new component copied from the one with the given id."
|
||||||
|
[{:keys [id] :as params}]
|
||||||
|
(ptk/reify ::duplicate-component
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(let [component (cph/get-component id
|
||||||
|
nil
|
||||||
|
(get state :workspace-data)
|
||||||
|
nil)
|
||||||
|
all-components (vals (get-in state [:workspace-data :components]))
|
||||||
|
unames (set (map :name all-components))
|
||||||
|
new-name (dwc/generate-unique-name unames (:name component))
|
||||||
|
|
||||||
|
[new-shape new-shapes updated-shapes]
|
||||||
|
(dwlh/duplicate-component component)
|
||||||
|
|
||||||
|
rchanges [{:type :add-component
|
||||||
|
:id (:id new-shape)
|
||||||
|
:name new-name
|
||||||
|
:shapes new-shapes}]
|
||||||
|
|
||||||
|
uchanges [{:type :del-component
|
||||||
|
:id (:id new-shape)}]]
|
||||||
|
|
||||||
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true}))))))
|
||||||
|
|
||||||
(defn delete-component
|
(defn delete-component
|
||||||
"Delete the component with the given id, from the current file library."
|
"Delete the component with the given id, from the current file library."
|
||||||
[{:keys [id] :as params}]
|
[{:keys [id] :as params}]
|
||||||
|
|
|
@ -93,6 +93,16 @@
|
||||||
|
|
||||||
(cph/clone-object shape nil objects update-new-shape update-original-shape)))
|
(cph/clone-object shape nil objects update-new-shape update-original-shape)))
|
||||||
|
|
||||||
|
(defn duplicate-component
|
||||||
|
"Clone the root shape of the component and all children. Generate new
|
||||||
|
ids from all of them."
|
||||||
|
[component]
|
||||||
|
(let [component-root (cph/get-component-root component)]
|
||||||
|
(cph/clone-object component-root
|
||||||
|
nil
|
||||||
|
(get component :objects)
|
||||||
|
identity)))
|
||||||
|
|
||||||
|
|
||||||
;; ---- General library synchronization functions ----
|
;; ---- General library synchronization functions ----
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,11 @@
|
||||||
:top nil
|
:top nil
|
||||||
:left nil
|
:left nil
|
||||||
:component-id nil})
|
:component-id nil})
|
||||||
|
on-duplicate
|
||||||
|
(mf/use-callback
|
||||||
|
(mf/deps state)
|
||||||
|
(st/emitf (dwl/duplicate-component {:id (:component-id @state)})))
|
||||||
|
|
||||||
on-delete
|
on-delete
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps state)
|
(mf/deps state)
|
||||||
|
@ -101,7 +106,8 @@
|
||||||
:on-close #(swap! state assoc :menu-open false)
|
:on-close #(swap! state assoc :menu-open false)
|
||||||
:top (:top @state)
|
:top (:top @state)
|
||||||
:left (:left @state)
|
:left (:left @state)
|
||||||
:options [[(tr "workspace.assets.delete") on-delete]]}])]))
|
:options [[(tr "workspace.assets.duplicate") on-duplicate]
|
||||||
|
[(tr "workspace.assets.delete") on-delete]]}])]))
|
||||||
|
|
||||||
(mf/defc graphics-box
|
(mf/defc graphics-box
|
||||||
[{:keys [file-id local? objects open? on-open on-close] :as props}]
|
[{:keys [file-id local? objects open? on-open on-close] :as props}]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue