mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 23:31:21 -05:00
🐛 Fix importing a component from a zip file in v2
This commit is contained in:
parent
2aa1b97769
commit
41024728ae
1 changed files with 27 additions and 23 deletions
|
@ -38,16 +38,17 @@
|
||||||
fail-on-spec?]
|
fail-on-spec?]
|
||||||
:or {add-container? false
|
:or {add-container? false
|
||||||
fail-on-spec? false}}]
|
fail-on-spec? false}}]
|
||||||
(let [component-id (:current-component-id file)
|
(let [components-v2 (dm/get-in file [:data :options :components-v2])
|
||||||
change (cond-> change
|
component-id (:current-component-id file)
|
||||||
(and add-container? (some? component-id))
|
change (cond-> change
|
||||||
(-> (assoc :component-id component-id)
|
(and add-container? (some? component-id))
|
||||||
(cond-> (some? (:current-frame-id file))
|
(-> (assoc :component-id component-id)
|
||||||
(assoc :frame-id (:current-frame-id file))))
|
(cond-> (some? (:current-frame-id file))
|
||||||
|
(assoc :frame-id (:current-frame-id file))))
|
||||||
|
|
||||||
(and add-container? (nil? component-id))
|
(and add-container? (nil? component-id))
|
||||||
(assoc :page-id (:current-page-id file)
|
(assoc :page-id (:current-page-id file)
|
||||||
:frame-id (:current-frame-id file)))
|
:frame-id (:current-frame-id file)))
|
||||||
|
|
||||||
valid? (ch/check-change! change)]
|
valid? (ch/check-change! change)]
|
||||||
|
|
||||||
|
@ -61,12 +62,12 @@
|
||||||
::sm/explain explain))))
|
::sm/explain explain))))
|
||||||
|
|
||||||
(cond-> file
|
(cond-> file
|
||||||
valid?
|
(and valid? (not (and components-v2 add-container? (some? component-id))))
|
||||||
(-> (update :changes conjv change)
|
(-> (update :changes conjv change) ;; In components-v2 we do not add shapes
|
||||||
(update :data ch/process-changes [change] false))
|
(update :data ch/process-changes [change] false)) ;; inside a component
|
||||||
|
|
||||||
(not valid?)
|
(not valid?)
|
||||||
(update :errors conjv change)))))
|
(update :errors conjv change)))));)
|
||||||
|
|
||||||
(defn- lookup-objects
|
(defn- lookup-objects
|
||||||
([file]
|
([file]
|
||||||
|
@ -181,10 +182,11 @@
|
||||||
(update :parent-stack conjv (:id obj)))))
|
(update :parent-stack conjv (:id obj)))))
|
||||||
|
|
||||||
(defn close-artboard [file]
|
(defn close-artboard [file]
|
||||||
(let [parent-id (-> file :parent-stack peek)
|
(let [components-v2 (dm/get-in file [:data :options :components-v2])
|
||||||
|
parent-id (-> file :parent-stack peek)
|
||||||
parent (lookup-shape file parent-id)
|
parent (lookup-shape file parent-id)
|
||||||
current-frame-id (or (:frame-id parent)
|
current-frame-id (or (:frame-id parent)
|
||||||
(when (nil? (:current-component-id file))
|
(when (or (nil? (:current-component-id file)) components-v2)
|
||||||
root-id))]
|
root-id))]
|
||||||
(-> file
|
(-> file
|
||||||
(assoc :current-frame-id current-frame-id)
|
(assoc :current-frame-id current-frame-id)
|
||||||
|
@ -515,7 +517,8 @@
|
||||||
|
|
||||||
([file data root-type]
|
([file data root-type]
|
||||||
;; FIXME: data probably can be a shape instance, then we can use gsh/shape->rect
|
;; FIXME: data probably can be a shape instance, then we can use gsh/shape->rect
|
||||||
(let [selrect (or (grc/make-rect (:x data) (:y data) (:width data) (:height data))
|
(let [components-v2 (dm/get-in file [:data :options :components-v2])
|
||||||
|
selrect (or (grc/make-rect (:x data) (:y data) (:width data) (:height data))
|
||||||
grc/empty-rect)
|
grc/empty-rect)
|
||||||
name (:name data)
|
name (:name data)
|
||||||
path (:path data)
|
path (:path data)
|
||||||
|
@ -542,13 +545,14 @@
|
||||||
|
|
||||||
(-> file
|
(-> file
|
||||||
(commit-change
|
(commit-change
|
||||||
{:type :add-component
|
(cond-> {:type :add-component
|
||||||
:id (:id obj)
|
:id (:id obj)
|
||||||
:name name
|
:name name
|
||||||
:path path
|
:path path
|
||||||
:main-instance-id main-instance-id
|
:main-instance-id main-instance-id
|
||||||
:main-instance-page main-instance-page
|
:main-instance-page main-instance-page}
|
||||||
:shapes [obj]})
|
(not components-v2)
|
||||||
|
(assoc :shapes [obj])))
|
||||||
|
|
||||||
(assoc :last-id (:id obj))
|
(assoc :last-id (:id obj))
|
||||||
(assoc :parent-stack [(:id obj)])
|
(assoc :parent-stack [(:id obj)])
|
||||||
|
|
Loading…
Add table
Reference in a new issue