mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 16:30:37 -05:00
🐛 Fix error when converting graphics to components
This commit is contained in:
parent
f639c73d03
commit
7d8e43b3d3
4 changed files with 33 additions and 30 deletions
|
@ -55,6 +55,7 @@
|
|||
[app.main.data.workspace.layers :as dwly]
|
||||
[app.main.data.workspace.layout :as layout]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
||||
[app.main.data.workspace.media :as dwm]
|
||||
[app.main.data.workspace.notifications :as dwn]
|
||||
[app.main.data.workspace.path :as dwdp]
|
||||
|
@ -2081,38 +2082,42 @@
|
|||
[it file-data page [index [media-obj pos]]]
|
||||
(let [process-shapes
|
||||
(fn [[shape children]]
|
||||
(let [page' (reduce #(ctst/add-shape (:id %2) %2 %1 uuid/zero (:parent-id %2) nil false)
|
||||
page
|
||||
(cons shape children))
|
||||
(let [changes1 (-> (pcb/empty-changes it)
|
||||
(pcb/set-save-undo? false)
|
||||
(pcb/with-page page)
|
||||
(pcb/with-objects (:objects page))
|
||||
(pcb/with-library-data file-data)
|
||||
(pcb/delete-media (:id media-obj))
|
||||
(pcb/add-objects (cons shape children)))
|
||||
|
||||
shape' (ctn/get-shape page' (:id shape))
|
||||
page' (reduce (fn [page shape]
|
||||
(ctst/add-shape (:id shape)
|
||||
shape
|
||||
page
|
||||
uuid/zero
|
||||
uuid/zero
|
||||
nil
|
||||
true))
|
||||
page
|
||||
(cons shape children))
|
||||
|
||||
path (cph/merge-path-item (tr "workspace.assets.graphics") (:path media-obj))
|
||||
[_ _ changes2] (dwlh/generate-add-component it
|
||||
[shape]
|
||||
(:objects page')
|
||||
(:id page)
|
||||
(:id file-data)
|
||||
true
|
||||
nil
|
||||
dwsh/prepare-create-artboard-from-selection)
|
||||
|
||||
[component-shape component-shapes updated-shapes]
|
||||
(ctn/make-component-shape shape' (:objects page') (:id file-data) true)
|
||||
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/set-save-undo? false)
|
||||
(pcb/with-page page')
|
||||
(pcb/with-objects (:objects page'))
|
||||
(pcb/with-library-data file-data)
|
||||
(pcb/delete-media (:id media-obj))
|
||||
(pcb/add-objects (cons shape children))
|
||||
(pcb/add-component (:id component-shape)
|
||||
path
|
||||
(:name media-obj)
|
||||
component-shapes
|
||||
updated-shapes
|
||||
(:id shape)
|
||||
(:id page)))]
|
||||
changes (pcb/concat-changes changes1 changes2)]
|
||||
|
||||
(dch/commit-changes changes)))
|
||||
|
||||
shapes (if (= (:mtype media-obj) "image/svg+xml")
|
||||
(->> (dwm/load-and-parse-svg media-obj)
|
||||
(rx/mapcat (partial dwm/create-shapes-svg (:id file-data) (:objects page) pos)))
|
||||
(dwm/create-shapes-img pos media-obj))]
|
||||
(dwm/create-shapes-img pos media-obj :wrapper-type :frame))]
|
||||
|
||||
(->> (rx/concat
|
||||
(rx/of (update-remove-graphics index))
|
||||
|
|
|
@ -313,8 +313,6 @@
|
|||
(ptk/data-event :layout/update parents)
|
||||
(dwt/update-thumbnail file-id page-id (:id root))))))))))
|
||||
|
||||
|
||||
|
||||
(defn add-component
|
||||
"Add a new component to current file library, from the currently selected shapes.
|
||||
This operation is made in two steps, first one for calculate the
|
||||
|
@ -330,7 +328,6 @@
|
|||
components-v2 (features/active-feature? state :components-v2)]
|
||||
(rx/of (add-component2 selected components-v2))))))
|
||||
|
||||
|
||||
(defn add-multiple-components
|
||||
"Add several new components to current file library, from the currently selected shapes."
|
||||
[]
|
||||
|
|
|
@ -282,9 +282,9 @@
|
|||
(defn create-shapes-img
|
||||
"Convert a media object that contains a bitmap image into shapes,
|
||||
one shape of type :image and one group that contains it."
|
||||
[pos {:keys [name width height id mtype] :as media-obj}]
|
||||
[pos {:keys [name width height id mtype] :as media-obj} & {:keys [wrapper-type] :or {wrapper-type :group}}]
|
||||
(let [group-shape (cts/setup-shape
|
||||
{:type :group
|
||||
{:type wrapper-type
|
||||
:x (:x pos)
|
||||
:y (:y pos)
|
||||
:width width
|
||||
|
|
|
@ -100,7 +100,7 @@
|
|||
parent-id (get-in objects [frame-id :parent-id])
|
||||
ordered-indexes (->> ordered-indexes (remove #(= % parent-id)))
|
||||
to-move-shapes (map (d/getf objects) ordered-indexes)]
|
||||
(when (d/not-empty? to-move-shapes)
|
||||
(if (d/not-empty? to-move-shapes)
|
||||
(-> changes
|
||||
(cond-> (not (ctl/any-layout? objects frame-id))
|
||||
(pcb/update-shapes ordered-indexes ctl/remove-layout-item-data))
|
||||
|
@ -108,7 +108,8 @@
|
|||
(pcb/change-parent frame-id to-move-shapes 0)
|
||||
(cond-> (ctl/grid-layout? objects frame-id)
|
||||
(pcb/update-shapes [frame-id] ctl/assign-cells))
|
||||
(pcb/reorder-grid-children [frame-id])))))
|
||||
(pcb/reorder-grid-children [frame-id]))
|
||||
changes)))
|
||||
|
||||
(defn move-shapes-into-frame
|
||||
[frame-id shapes]
|
||||
|
|
Loading…
Reference in a new issue