0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-11 15:21:18 -05:00

🐛 Better handling of components v2 in file builder

This commit is contained in:
Andrés Moya 2024-05-20 18:03:30 +02:00
parent 4b05ee35b8
commit 3bf76e8d0f
3 changed files with 24 additions and 12 deletions

View file

@ -48,6 +48,7 @@
(and add-container? (nil? component-id))
(assoc :page-id (:current-page-id file)
:frame-id (:current-frame-id file)))
valid? (ch/check-change! change)]
(when-not valid?
@ -135,13 +136,8 @@
(create-file (uuid/next) name))
([id name]
{:id id
:name name
:data (-> ctf/empty-file-data
(assoc :id id))
;; We keep the changes so we can send them to the backend
:changes []}))
(-> (ctf/make-file {:id id :name name :create-page false})
(assoc :changes [])))) ;; We keep the changes so we can send them to the backend
(defn add-page
[file data]
@ -511,9 +507,12 @@
{:type :del-media
:id id}))))
(defn start-component
([file data] (start-component file data :group))
([file data]
(let [components-v2 (dm/get-in file [:data :options :components-v2])
root-type (if components-v2 :frame :group)]
(start-component file data root-type)))
([file data root-type]
;; 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))
@ -566,9 +565,11 @@
file
(cond
;; Components-v2 component we skip this step
;; In components-v2 components haven't any shape inside them.
(and component-data (:main-instance-id component-data))
file
(update file :data
(fn [data]
(ctkl/update-component data component-id dissoc :objects)))
(empty? children)
(commit-change

View file

@ -240,6 +240,7 @@
(when-not ^boolean (-validate s value)
(let [hint (d/nilv dm/*assert-context* "check error")
explain (-explain s value)]
(println (humanize-explain explain))
(throw (ex-info hint {:type :assertion
:code :data-validation
:hint hint

View file

@ -249,9 +249,18 @@
(deleteObject [_ id]
(set! file (fb/delete-object file (uuid/uuid id))))
(getId [_]
(:id file))
(getCurrentPageId [_]
(:current-page-id file))
(asMap [_]
(clj->js file))
(newId [_]
(uuid/next))
(export [_]
(->> (export-file file)
(rx/subs!
@ -261,7 +270,8 @@
(dom/trigger-download (:name file) export-blob))))))))
(defn create-file-export [^string name]
(File. (fb/create-file name)))
(binding [cfeat/*current* cfeat/default-features]
(File. (fb/create-file name))))
(defn exports []
#js {:createFile create-file-export})