mirror of
https://github.com/penpot/penpot.git
synced 2025-04-12 15:01:28 -05:00
🐛 Fix create a main component inside another and move one main inside another
This commit is contained in:
parent
cee827a97b
commit
23527b1d19
4 changed files with 22 additions and 17 deletions
|
@ -187,7 +187,7 @@
|
|||
exists and its main-instance does not point to this
|
||||
shape."
|
||||
[shape file page libraries]
|
||||
(when (some? (:main-instance shape))
|
||||
(when (true? (:main-instance shape))
|
||||
(report-error! :component-not-main
|
||||
"Shape not expected to be main instance"
|
||||
shape file page))
|
||||
|
@ -210,7 +210,7 @@
|
|||
(defn validate-component-not-main-not-head!
|
||||
"Validate that this shape is not main instance and not head."
|
||||
[shape file page]
|
||||
(when (some? (:main-instance shape))
|
||||
(when (true? (:main-instance shape))
|
||||
(report-error! :component-main
|
||||
"Shape not expected to be main instance"
|
||||
shape file page))
|
||||
|
@ -231,7 +231,7 @@
|
|||
(defn validate-component-not-root!
|
||||
"Validate that this shape is not an instance root."
|
||||
[shape file page]
|
||||
(when (some? (:component-root shape))
|
||||
(when (true? (:component-root shape))
|
||||
(report-error! :should-not-be-component-root
|
||||
"Shape should not be component root"
|
||||
shape file page)))
|
||||
|
|
|
@ -97,7 +97,7 @@
|
|||
(defn instance-root?
|
||||
"Check if this shape is the head of a top instance."
|
||||
[shape]
|
||||
(some? (:component-root shape)))
|
||||
(true? (:component-root shape)))
|
||||
|
||||
(defn instance-head?
|
||||
"Check if this shape is the head of a top instance or a subinstance."
|
||||
|
@ -127,7 +127,7 @@
|
|||
"Check if this shape is the root of the main instance of some
|
||||
component."
|
||||
[shape]
|
||||
(some? (:main-instance shape)))
|
||||
(true? (:main-instance shape)))
|
||||
|
||||
(defn in-component-copy?
|
||||
"Check if the shape is inside a component non-main instance."
|
||||
|
@ -156,7 +156,7 @@
|
|||
|
||||
(defn get-component-root
|
||||
[component]
|
||||
(if (some? (:main-instance-id component))
|
||||
(if (true? (:main-instance-id component))
|
||||
(get-in component [:objects (:main-instance-id component)])
|
||||
(get-in component [:objects (:id component)])))
|
||||
|
||||
|
|
|
@ -196,19 +196,21 @@
|
|||
Also remove component-root of all children. Return the same structure
|
||||
as make-component-shape."
|
||||
[root objects file-id]
|
||||
(let [new-id (uuid/next)
|
||||
new-root (assoc root
|
||||
:component-id new-id
|
||||
:component-file file-id
|
||||
:component-root true
|
||||
:main-instance true)
|
||||
new-children (->> (cfh/get-children objects (:id root))
|
||||
(map #(dissoc % :component-root)))]
|
||||
(let [new-id (uuid/next)
|
||||
inside-component? (some? (get-instance-root objects root))
|
||||
new-root (cond-> (assoc root
|
||||
:component-id new-id
|
||||
:component-file file-id
|
||||
:main-instance true)
|
||||
(not inside-component?)
|
||||
(assoc :component-root true))
|
||||
new-children (->> (cfh/get-children objects (:id root))
|
||||
(map #(dissoc % :component-root)))]
|
||||
[(assoc new-root :id new-id)
|
||||
nil
|
||||
(into [new-root] new-children)]))
|
||||
|
||||
(defn make-component-shape
|
||||
(defn make-component-shape ;; Only used for components v1
|
||||
"Clone the shape and all children. Generate new ids and detach
|
||||
from parent and frame. Update the original shapes to have links
|
||||
to the new ones."
|
||||
|
@ -280,7 +282,7 @@
|
|||
|
||||
component-shape (if components-v2
|
||||
(-> (get-shape component-page (:main-instance-id component))
|
||||
(assoc :parent-id nil)
|
||||
(assoc :parent-id nil) ;; On v2 we force parent-id to nil in order to behave like v1
|
||||
(assoc :frame-id uuid/zero))
|
||||
(get-shape component (:id component)))
|
||||
|
||||
|
@ -333,7 +335,7 @@
|
|||
:component-root true
|
||||
:name new-name)
|
||||
|
||||
(some? (:parent-id original-shape))
|
||||
(some? (:parent-id original-shape)) ;; On v2 we have removed the parent-id for component roots (see above)
|
||||
(dissoc :component-root))))
|
||||
|
||||
[new-shape new-shapes _]
|
||||
|
|
|
@ -840,6 +840,9 @@
|
|||
;; Remove layout-item properties when moving a shape outside a layout
|
||||
(cond-> (not (ctl/any-layout? objects frame-id))
|
||||
(pcb/update-shapes moving-shapes-ids ctl/remove-layout-item-data))
|
||||
;; Remove componnet-root property when moving a shape inside a component
|
||||
(cond-> (ctn/get-instance-root objects frame)
|
||||
(pcb/update-shapes moving-shapes-ids #(dissoc % :component-root)))
|
||||
(pcb/update-shapes moving-shapes-ids #(cond-> % (cfh/frame-shape? %) (assoc :hide-in-viewer true)))
|
||||
(pcb/update-shapes shape-ids-to-detach ctk/detach-shape)
|
||||
(pcb/change-parent frame-id moving-shapes drop-index)
|
||||
|
|
Loading…
Add table
Reference in a new issue