mirror of
https://github.com/penpot/penpot.git
synced 2026-03-25 21:00:29 +01:00
♻️ Use main-instance? attribute
This commit is contained in:
@@ -564,6 +564,9 @@
|
||||
{:type :set
|
||||
:attr :component-root?
|
||||
:val (:component-root? shape)}
|
||||
{:type :set
|
||||
:attr :main-instance?
|
||||
:val (:main-instance? shape)}
|
||||
{:type :set
|
||||
:attr :shape-ref
|
||||
:val (:shape-ref shape)}
|
||||
|
||||
@@ -455,10 +455,11 @@
|
||||
(let [page (ctpl/get-page data page-id)
|
||||
|
||||
[new-shape new-shapes]
|
||||
(ctn/instantiate-component page
|
||||
component
|
||||
(:id data)
|
||||
position)
|
||||
(ctn/make-component-instance page
|
||||
component
|
||||
(:id data)
|
||||
position
|
||||
true)
|
||||
|
||||
add-shapes
|
||||
(fn [page]
|
||||
|
||||
@@ -94,15 +94,16 @@
|
||||
(nil? (:parent-id new-shape))
|
||||
(assoc :component-id (:id new-shape)
|
||||
:component-file file-id
|
||||
:component-root? true)
|
||||
:component-root? true
|
||||
:main-instance? true)
|
||||
|
||||
(some? (:parent-id new-shape))
|
||||
(dissoc :component-root?)))]
|
||||
|
||||
(ctst/clone-object shape nil objects update-new-shape update-original-shape)))
|
||||
|
||||
(defn instantiate-component
|
||||
[container component component-file-id position]
|
||||
(defn make-component-instance
|
||||
[container component component-file-id position main-instance?]
|
||||
(let [component-shape (get-shape component (:id component))
|
||||
|
||||
orig-pos (gpt/point (:x component-shape) (:y component-shape))
|
||||
@@ -138,6 +139,9 @@
|
||||
:component-root? true
|
||||
:name new-name)
|
||||
|
||||
(and (nil? (:parent-id original-shape)) main-instance?)
|
||||
(assoc :main-instance? true)
|
||||
|
||||
(some? (:parent-id original-shape))
|
||||
(dissoc :component-root?))))
|
||||
|
||||
|
||||
@@ -194,10 +194,11 @@
|
||||
|
||||
; Make a new main instance for the component
|
||||
[main-instance-shape main-instance-shapes]
|
||||
(ctn/instantiate-component page
|
||||
component
|
||||
(:id file-data)
|
||||
position)
|
||||
(ctn/make-component-instance page
|
||||
component
|
||||
(:id file-data)
|
||||
position
|
||||
true)
|
||||
|
||||
; Add all shapes of the main instance to the library page
|
||||
add-main-instance-shapes
|
||||
|
||||
Reference in New Issue
Block a user