mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 05:06:10 +02:00
♻️ Use main-instance? attribute
This commit is contained in:
parent
dcf18b3aee
commit
eebd596fca
6 changed files with 33 additions and 22 deletions
|
@ -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
|
||||
(ctn/make-component-instance page
|
||||
component
|
||||
(:id data)
|
||||
position)
|
||||
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
|
||||
(ctn/make-component-instance page
|
||||
component
|
||||
(:id file-data)
|
||||
position)
|
||||
position
|
||||
true)
|
||||
|
||||
; Add all shapes of the main instance to the library page
|
||||
add-main-instance-shapes
|
||||
|
|
|
@ -91,10 +91,11 @@
|
|||
file
|
||||
(fn [file-data]
|
||||
(let [[instance-shape instance-shapes]
|
||||
(ctn/instantiate-component (ctpl/get-page file-data page-id)
|
||||
(ctn/make-component-instance (ctpl/get-page file-data page-id)
|
||||
(ctkl/get-component (:data library) component-id)
|
||||
(:id library)
|
||||
(gpt/point 0 0))]
|
||||
(gpt/point 0 0)
|
||||
false)]
|
||||
|
||||
(swap! idmap assoc label (:id instance-shape))
|
||||
(-> file-data
|
||||
|
|
|
@ -106,12 +106,13 @@
|
|||
|
||||
|
||||
[new-instance-shape new-instance-shapes]
|
||||
(ctn/instantiate-component main-instance-page
|
||||
(ctn/make-component-instance main-instance-page
|
||||
{:id (:id new-component-shape)
|
||||
:name (:name new-component-shape)
|
||||
:objects (d/index-by :id new-component-shapes)}
|
||||
(:component-file main-instance-shape)
|
||||
position)]
|
||||
position
|
||||
false)]
|
||||
|
||||
[new-component-shape new-component-shapes
|
||||
new-instance-shape new-instance-shapes]))
|
||||
|
@ -122,7 +123,7 @@
|
|||
(let [component (cph/get-component libraries file-id component-id)
|
||||
|
||||
[new-shape new-shapes]
|
||||
(ctn/instantiate-component page component file-id position)
|
||||
(ctn/make-component-instance page component file-id position false)
|
||||
|
||||
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
|
||||
(pcb/empty-changes it (:id page))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue