mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 05:28:33 +02:00
🐛 Rework svg import of deleted components
This commit is contained in:
parent
6aeb87a122
commit
798970a923
3 changed files with 88 additions and 65 deletions
|
@ -41,16 +41,19 @@
|
|||
(let [components-v2 (dm/get-in file [:data :options :components-v2])
|
||||
component-id (:current-component-id file)
|
||||
change (cond-> change
|
||||
(and add-container? (some? component-id))
|
||||
(and add-container? (some? component-id) (not components-v2))
|
||||
(-> (assoc :component-id component-id)
|
||||
(cond-> (some? (:current-frame-id file))
|
||||
(assoc :frame-id (:current-frame-id file))))
|
||||
|
||||
(and add-container? (nil? component-id))
|
||||
(and add-container? (or (nil? component-id) components-v2))
|
||||
(assoc :page-id (:current-page-id file)
|
||||
:frame-id (:current-frame-id file)))
|
||||
|
||||
valid? (ch/check-change! change)]
|
||||
valid? (or (and components-v2
|
||||
(nil? (:component-id change))
|
||||
(nil? (:page-id change)))
|
||||
(ch/check-change! change))]
|
||||
|
||||
(when-not valid?
|
||||
(let [explain (sm/explain ::ch/change change)]
|
||||
|
@ -62,7 +65,7 @@
|
|||
::sm/explain explain))))
|
||||
|
||||
(cond-> file
|
||||
(and valid? (not (and components-v2 add-container? (some? component-id))))
|
||||
(and valid? (or (not add-container?) (some? (:component-id change)) (some? (:page-id change))))
|
||||
(-> (update :changes conjv change) ;; In components-v2 we do not add shapes
|
||||
(update :data ch/process-changes [change] false)) ;; inside a component
|
||||
|
||||
|
@ -524,6 +527,11 @@
|
|||
path (:path data)
|
||||
main-instance-id (:main-instance-id data)
|
||||
main-instance-page (:main-instance-page data)
|
||||
|
||||
;; In components v1 we must create the root shape and set it inside
|
||||
;; the :objects attribute of the component. When in components-v2,
|
||||
;; this will be ignored as the root shape has already been created
|
||||
;; in its page, by the normal page import.
|
||||
attrs (-> data
|
||||
(assoc :type root-type)
|
||||
(assoc :x (:x selrect))
|
||||
|
@ -559,6 +567,29 @@
|
|||
(assoc :current-component-id (:id obj))
|
||||
(assoc :current-frame-id (if (= (:type obj) :frame) (:id obj) uuid/zero))))))
|
||||
|
||||
(defn start-deleted-component
|
||||
[file data]
|
||||
(let [attrs (-> data
|
||||
(assoc :id (:main-instance-id data))
|
||||
(assoc :component-file (:id file))
|
||||
(assoc :component-id (:id data))
|
||||
(assoc :x (:main-instance-x data))
|
||||
(assoc :y (:main-instance-y data))
|
||||
(dissoc :path)
|
||||
(dissoc :main-instance-id)
|
||||
(dissoc :main-instance-page)
|
||||
(dissoc :main-instance-x)
|
||||
(dissoc :main-instance-y)
|
||||
(dissoc :main-instance-parent)
|
||||
(dissoc :main-instance-frame))]
|
||||
;; To create a deleted component, first we add all shapes of the main instance
|
||||
;; in the main instance page, and in the finish event we delete it.
|
||||
(-> file
|
||||
(update :parent-stack conjv (:main-instance-parent data))
|
||||
(assoc :current-page-id (:main-instance-page data))
|
||||
(assoc :current-frame-id (:main-instance-frame data))
|
||||
(add-artboard attrs))))
|
||||
|
||||
(defn finish-component
|
||||
[file]
|
||||
(let [component-id (:current-component-id file)
|
||||
|
@ -623,43 +654,18 @@
|
|||
(update :parent-stack pop))))
|
||||
|
||||
(defn finish-deleted-component
|
||||
[component-id page-id main-instance-x main-instance-y file]
|
||||
[component-id file]
|
||||
(let [file (assoc file :current-component-id component-id)
|
||||
page (ctpl/get-page (:data file) page-id)
|
||||
component (ctkl/get-component (:data file) component-id)
|
||||
main-instance-id (:main-instance-id component)
|
||||
|
||||
; To obtain a deleted component, we first create the component
|
||||
; and the main instance in the workspace, and then delete them.
|
||||
[_ shapes]
|
||||
(ctn/make-component-instance page
|
||||
component
|
||||
(:data file)
|
||||
(gpt/point main-instance-x
|
||||
main-instance-y)
|
||||
true
|
||||
{:main-instance true
|
||||
:force-id main-instance-id})]
|
||||
(as-> file $
|
||||
(reduce #(commit-change %1
|
||||
{:type :add-obj
|
||||
:id (:id %2)
|
||||
:page-id (:id page)
|
||||
:parent-id (:parent-id %2)
|
||||
:frame-id (:frame-id %2)
|
||||
:ignore-touched true
|
||||
:obj %2})
|
||||
$
|
||||
shapes)
|
||||
(commit-change $ {:type :del-component
|
||||
component (ctkl/get-component (:data file) component-id)]
|
||||
(-> file
|
||||
(close-artboard)
|
||||
(commit-change {:type :del-component
|
||||
:id component-id})
|
||||
(reduce #(commit-change %1 {:type :del-obj
|
||||
:page-id page-id
|
||||
:ignore-touched true
|
||||
:id (:id %2)})
|
||||
$
|
||||
shapes)
|
||||
(dissoc $ :current-component-id))))
|
||||
(commit-change {:type :del-obj
|
||||
:page-id (:main-instance-page component)
|
||||
:id (:main-instance-id component)
|
||||
:ignore-touched true})
|
||||
(dissoc :current-page-id))))
|
||||
|
||||
(defn create-component-instance
|
||||
[file data]
|
||||
|
@ -670,7 +676,6 @@
|
|||
page-id (:current-page-id file)
|
||||
page (ctpl/get-page (:data file) page-id)
|
||||
component (ctkl/get-component (:data file) component-id)
|
||||
;; main-instance-id (:main-instance-id component)
|
||||
|
||||
components-v2 (dm/get-in file [:options :components-v2])
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue