mirror of
https://github.com/penpot/penpot.git
synced 2025-07-12 00:37:16 +02:00
🎉 Allow to create a nested component in one step
This commit is contained in:
parent
4ad27c3fca
commit
9725dd5fff
6 changed files with 143 additions and 59 deletions
|
@ -59,35 +59,41 @@
|
|||
;; ---- Components and instances creation ----
|
||||
|
||||
(defn generate-add-component
|
||||
"If there is exactly one id, and it's a group, use it as root. Otherwise,
|
||||
create a group that contains all ids. Then, make a component with it,
|
||||
and link all shapes to their corresponding one in the component."
|
||||
"If there is exactly one id, and it's a group, and not already a component, use
|
||||
it as root. Otherwise, create a group that contains all ids. Then, make a
|
||||
component with it, and link all shapes to their corresponding one in the component."
|
||||
[it shapes objects page-id file-id components-v2]
|
||||
(if (and (= (count shapes) 1)
|
||||
(:component-id (first shapes)))
|
||||
[(first shapes) (pcb/empty-changes it)]
|
||||
(let [name (if (= 1 (count shapes)) (:name (first shapes)) "Component-1")
|
||||
[path name] (cph/parse-path-name name)
|
||||
(let [[group changes]
|
||||
(if (and (= (count shapes) 1)
|
||||
(= (:type (first shapes)) :group)
|
||||
(not (ctk/instance-root? (first shapes))))
|
||||
[(first shapes) (-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-objects objects))]
|
||||
(let [group-name (if (= 1 (count shapes))
|
||||
(:name (first shapes))
|
||||
"Component-1")]
|
||||
(dwg/prepare-create-group it
|
||||
objects
|
||||
page-id
|
||||
shapes
|
||||
group-name
|
||||
(not (ctk/instance-root? (first shapes))))))
|
||||
|
||||
[group changes]
|
||||
(if (and (= (count shapes) 1)
|
||||
(= (:type (first shapes)) :group))
|
||||
[(first shapes) (-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-objects objects))]
|
||||
(dwg/prepare-create-group it objects page-id shapes name true))
|
||||
name (:name group)
|
||||
[path name] (cph/parse-path-name name)
|
||||
|
||||
[new-shape new-shapes updated-shapes]
|
||||
(ctn/make-component-shape group objects file-id components-v2)
|
||||
[new-shape new-shapes updated-shapes]
|
||||
(ctn/make-component-shape group objects file-id components-v2)
|
||||
|
||||
changes (-> changes
|
||||
(pcb/add-component (:id new-shape)
|
||||
path
|
||||
name
|
||||
new-shapes
|
||||
updated-shapes
|
||||
(:id group)
|
||||
page-id))]
|
||||
[group new-shape changes])))
|
||||
changes (-> changes
|
||||
(pcb/add-component (:id new-shape)
|
||||
path
|
||||
name
|
||||
new-shapes
|
||||
updated-shapes
|
||||
(:id group)
|
||||
page-id))]
|
||||
[group new-shape changes]))
|
||||
|
||||
(defn duplicate-component
|
||||
"Clone the root shape of the component and all children. Generate new
|
||||
|
|
|
@ -407,20 +407,19 @@
|
|||
:accept-style :primary
|
||||
:on-accept do-update-component-in-bulk}))]
|
||||
[:*
|
||||
(when (and (not has-frame?) (not is-component?))
|
||||
(when (not has-frame?)
|
||||
[:*
|
||||
[:& menu-separator]
|
||||
[:& menu-entry {:title (tr "workspace.shape.menu.create-component")
|
||||
:shortcut (sc/get-tooltip :create-component)
|
||||
:on-click do-add-component}]
|
||||
(when has-component?
|
||||
(when (and has-component? (not single?))
|
||||
[:*
|
||||
[:& menu-entry {:title (tr "workspace.shape.menu.detach-instances-in-bulk")
|
||||
:shortcut (sc/get-tooltip :detach-component)
|
||||
:on-click do-detach-component-in-bulk}]
|
||||
(when (not single?)
|
||||
[:& menu-entry {:title (tr "workspace.shape.menu.update-components-in-bulk")
|
||||
:on-click do-update-in-bulk}])])])
|
||||
[:& menu-entry {:title (tr "workspace.shape.menu.update-components-in-bulk")
|
||||
:on-click do-update-in-bulk}]])])
|
||||
|
||||
(when is-component?
|
||||
;; WARNING: this menu is the same as the context menu at the sidebar.
|
||||
|
|
|
@ -207,7 +207,7 @@
|
|||
(dump-selected' @st/state))
|
||||
|
||||
(defn dump-tree'
|
||||
([state ] (dump-tree' state false false))
|
||||
([state] (dump-tree' state false false))
|
||||
([state show-ids] (dump-tree' state show-ids false))
|
||||
([state show-ids show-touched]
|
||||
(let [page-id (get state :current-page-id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue