mirror of
https://github.com/penpot/penpot.git
synced 2025-05-24 17:56:10 +02:00
🐛 Disallow to create a redundant component
This commit is contained in:
parent
7c3d71e572
commit
50d756b189
3 changed files with 59 additions and 54 deletions
11
CHANGES.md
11
CHANGES.md
|
@ -11,11 +11,12 @@
|
||||||
|
|
||||||
### :bug: Bugs fixed
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
- Fix problem with exporting before the document is saved [Taiga #2189](https://tree.taiga.io/project/penpot/issue/2189)
|
- Fix problem with exporting before the document is saved [Taiga #2189](https://tree.taiga.io/project/penpot/issue/2189).
|
||||||
- Fix undo stacking when changing color from color-picker [Taiga #2191](https://tree.taiga.io/project/penpot/issue/2191)
|
- Fix undo stacking when changing color from color-picker [Taiga #2191](https://tree.taiga.io/project/penpot/issue/2191).
|
||||||
- Fix pages dropdown in viewer [Taiga #2087](https://tree.taiga.io/project/penpot/issue/2087)
|
- Fix pages dropdown in viewer [Taiga #2087](https://tree.taiga.io/project/penpot/issue/2087).
|
||||||
- Fix problem when exporting texts with gradients or opacity [Taiga #2200](https://tree.taiga.io/project/penpot/issue/2200)
|
- Fix problem when exporting texts with gradients or opacity [Taiga #2200](https://tree.taiga.io/project/penpot/issue/2200).
|
||||||
- Fix problem with view mode comments [Taiga #](https://tree.taiga.io/project/penpot/issue/2226)
|
- Fix problem with view mode comments [Taiga #226](https://tree.taiga.io/project/penpot/issue/2226).
|
||||||
|
- Disallow to create a component when already has one [Taiga #2237](https://tree.taiga.io/project/penpot/issue/2237).
|
||||||
|
|
||||||
### :arrow_up: Deps updates
|
### :arrow_up: Deps updates
|
||||||
### :heart: Community contributions by (Thank you!)
|
### :heart: Community contributions by (Thank you!)
|
||||||
|
|
|
@ -125,70 +125,73 @@
|
||||||
create a group that contains all ids. Then, make a component with it,
|
create a group that contains all ids. Then, make a component with it,
|
||||||
and link all shapes to their corresponding one in the component."
|
and link all shapes to their corresponding one in the component."
|
||||||
[shapes objects page-id file-id]
|
[shapes objects page-id file-id]
|
||||||
(let [[group rchanges uchanges]
|
(if (and (= (count shapes) 1)
|
||||||
(if (and (= (count shapes) 1)
|
(:component-id (first shapes)))
|
||||||
(= (:type (first shapes)) :group))
|
empty-changes
|
||||||
[(first shapes) [] []]
|
(let [[group rchanges uchanges]
|
||||||
(dwg/prepare-create-group objects page-id shapes "Component-1" true))
|
(if (and (= (count shapes) 1)
|
||||||
|
(= (:type (first shapes)) :group))
|
||||||
|
[(first shapes) [] []]
|
||||||
|
(dwg/prepare-create-group objects page-id shapes "Component-1" true))
|
||||||
|
|
||||||
[new-shape new-shapes updated-shapes]
|
[new-shape new-shapes updated-shapes]
|
||||||
(make-component-shape group objects file-id)
|
(make-component-shape group objects file-id)
|
||||||
|
|
||||||
rchanges (conj rchanges
|
rchanges (conj rchanges
|
||||||
{:type :add-component
|
{:type :add-component
|
||||||
:id (:id new-shape)
|
:id (:id new-shape)
|
||||||
:name (:name new-shape)
|
:name (:name new-shape)
|
||||||
:shapes new-shapes})
|
:shapes new-shapes})
|
||||||
|
|
||||||
rchanges (into rchanges
|
rchanges (into rchanges
|
||||||
(map (fn [updated-shape]
|
(map (fn [updated-shape]
|
||||||
{:type :mod-obj
|
|
||||||
:page-id page-id
|
|
||||||
:id (:id updated-shape)
|
|
||||||
:operations [{:type :set
|
|
||||||
:attr :component-id
|
|
||||||
:val (:component-id updated-shape)}
|
|
||||||
{:type :set
|
|
||||||
:attr :component-file
|
|
||||||
:val (:component-file updated-shape)}
|
|
||||||
{:type :set
|
|
||||||
:attr :component-root?
|
|
||||||
:val (:component-root? updated-shape)}
|
|
||||||
{:type :set
|
|
||||||
:attr :shape-ref
|
|
||||||
:val (:shape-ref updated-shape)}
|
|
||||||
{:type :set
|
|
||||||
:attr :touched
|
|
||||||
:val (:touched updated-shape)}]})
|
|
||||||
updated-shapes))
|
|
||||||
|
|
||||||
uchanges (conj uchanges
|
|
||||||
{:type :del-component
|
|
||||||
:id (:id new-shape)})
|
|
||||||
|
|
||||||
uchanges (into uchanges
|
|
||||||
(map (fn [updated-shape]
|
|
||||||
(let [original-shape (get objects (:id updated-shape))]
|
|
||||||
{:type :mod-obj
|
{:type :mod-obj
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:id (:id updated-shape)
|
:id (:id updated-shape)
|
||||||
:operations [{:type :set
|
:operations [{:type :set
|
||||||
:attr :component-id
|
:attr :component-id
|
||||||
:val (:component-id original-shape)}
|
:val (:component-id updated-shape)}
|
||||||
{:type :set
|
{:type :set
|
||||||
:attr :component-file
|
:attr :component-file
|
||||||
:val (:component-file original-shape)}
|
:val (:component-file updated-shape)}
|
||||||
{:type :set
|
{:type :set
|
||||||
:attr :component-root?
|
:attr :component-root?
|
||||||
:val (:component-root? original-shape)}
|
:val (:component-root? updated-shape)}
|
||||||
{:type :set
|
{:type :set
|
||||||
:attr :shape-ref
|
:attr :shape-ref
|
||||||
:val (:shape-ref original-shape)}
|
:val (:shape-ref updated-shape)}
|
||||||
{:type :set
|
{:type :set
|
||||||
:attr :touched
|
:attr :touched
|
||||||
:val (:touched original-shape)}]}))
|
:val (:touched updated-shape)}]})
|
||||||
updated-shapes))]
|
updated-shapes))
|
||||||
[group rchanges uchanges]))
|
|
||||||
|
uchanges (conj uchanges
|
||||||
|
{:type :del-component
|
||||||
|
:id (:id new-shape)})
|
||||||
|
|
||||||
|
uchanges (into uchanges
|
||||||
|
(map (fn [updated-shape]
|
||||||
|
(let [original-shape (get objects (:id updated-shape))]
|
||||||
|
{:type :mod-obj
|
||||||
|
:page-id page-id
|
||||||
|
:id (:id updated-shape)
|
||||||
|
:operations [{:type :set
|
||||||
|
:attr :component-id
|
||||||
|
:val (:component-id original-shape)}
|
||||||
|
{:type :set
|
||||||
|
:attr :component-file
|
||||||
|
:val (:component-file original-shape)}
|
||||||
|
{:type :set
|
||||||
|
:attr :component-root?
|
||||||
|
:val (:component-root? original-shape)}
|
||||||
|
{:type :set
|
||||||
|
:attr :shape-ref
|
||||||
|
:val (:shape-ref original-shape)}
|
||||||
|
{:type :set
|
||||||
|
:attr :touched
|
||||||
|
:val (:touched original-shape)}]}))
|
||||||
|
updated-shapes))]
|
||||||
|
[group rchanges uchanges])))
|
||||||
|
|
||||||
(defn duplicate-component
|
(defn duplicate-component
|
||||||
"Clone the root shape of the component and all children. Generate new
|
"Clone the root shape of the component and all children. Generate new
|
||||||
|
|
|
@ -281,7 +281,8 @@
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.delete-flow-start")
|
[:& menu-entry {:title (tr "workspace.shape.menu.delete-flow-start")
|
||||||
:on-click (do-remove-flow flow)}])))
|
:on-click (do-remove-flow flow)}])))
|
||||||
|
|
||||||
(when (not= (:type shape) :frame)
|
(when (and (not= (:type shape) :frame)
|
||||||
|
(or multiple? (nil? (:component-id shape))))
|
||||||
[:*
|
[:*
|
||||||
[:& menu-separator]
|
[:& menu-separator]
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.create-component")
|
[:& menu-entry {:title (tr "workspace.shape.menu.create-component")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue