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

Merge pull request #3699 from penpot/hiru-bugfixes

Hiru bugfixes
This commit is contained in:
Pablo Alba 2023-10-09 12:02:54 +02:00 committed by GitHub
commit f88ce0e404
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 45 deletions

View file

@ -271,9 +271,10 @@
update-new-shape update-new-shape
(fn [new-shape original-shape] (fn [new-shape original-shape]
(let [new-name (:name new-shape) (let [new-name (:name new-shape)
main-instance? (and main-instance? (ctk/instance-root? new-shape))] ; Only the instance root can be a main instance root? (or (ctk/instance-root? original-shape) ; If shape is inside a component (not components-v2)
(nil? (:parent-id original-shape)))] ; we detect it by having no parent)
(when (nil? (:parent-id original-shape)) (when root?
(vswap! unames conj new-name)) (vswap! unames conj new-name))
(vswap! ids-map assoc (:id original-shape) (:id new-shape)) (vswap! ids-map assoc (:id original-shape) (:id new-shape))
@ -283,12 +284,15 @@
(-> (gsh/move delta) (-> (gsh/move delta)
(dissoc :touched)) (dissoc :touched))
main-instance? (and main-instance? root?)
(assoc :main-instance true) (assoc :main-instance true)
(not main-instance?) (not main-instance?)
(dissoc :main-instance) (dissoc :main-instance)
main-instance?
(dissoc :shape-ref)
(and (not main-instance?) (and (not main-instance?)
(or components-v2 ; In v1, shape-ref points to the remote instance (or components-v2 ; In v1, shape-ref points to the remote instance
(nil? (:shape-ref original-shape)))) ; in v2, shape-ref points to the near instance (nil? (:shape-ref original-shape)))) ; in v2, shape-ref points to the near instance
@ -300,21 +304,17 @@
:component-root true :component-root true
:name new-name) :name new-name)
(and (nil? (:parent-id original-shape)) main-instance? components-v2)
(assoc :main-instance true)
(some? (:parent-id original-shape)) (some? (:parent-id original-shape))
(dissoc :component-root)))) (dissoc :component-root))))
[new-shape new-shapes _] [new-shape new-shapes _]
(ctst/clone-object (ctst/clone-object component-shape
component-shape nil
nil (if components-v2 (:objects component-page) (:objects component))
(if components-v2 (:objects component-page) (:objects component)) update-new-shape
update-new-shape (fn [object _] object)
(fn [object _] object) force-id
force-id keep-ids?)
keep-ids?)
;; If frame-id points to a shape inside the component, remap it to the ;; If frame-id points to a shape inside the component, remap it to the
;; corresponding new frame shape. If not, set it to the destination frame. ;; corresponding new frame shape. If not, set it to the destination frame.

View file

@ -394,7 +394,7 @@
file-data file-data
position position
false false
{:main-instance true {:main-instance? true
:force-frame-id uuid/zero :force-frame-id uuid/zero
:keep-ids? true}) :keep-ids? true})
add-shapes add-shapes

View file

@ -55,6 +55,7 @@
[app.main.data.workspace.layers :as dwly] [app.main.data.workspace.layers :as dwly]
[app.main.data.workspace.layout :as layout] [app.main.data.workspace.layout :as layout]
[app.main.data.workspace.libraries :as dwl] [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.media :as dwm]
[app.main.data.workspace.notifications :as dwn] [app.main.data.workspace.notifications :as dwn]
[app.main.data.workspace.path :as dwdp] [app.main.data.workspace.path :as dwdp]
@ -2081,38 +2082,42 @@
[it file-data page [index [media-obj pos]]] [it file-data page [index [media-obj pos]]]
(let [process-shapes (let [process-shapes
(fn [[shape children]] (fn [[shape children]]
(let [page' (reduce #(ctst/add-shape (:id %2) %2 %1 uuid/zero (:parent-id %2) nil false) (let [changes1 (-> (pcb/empty-changes it)
page (pcb/set-save-undo? false)
(cons shape children)) (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] changes (pcb/concat-changes changes1 changes2)]
(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)))]
(dch/commit-changes changes))) (dch/commit-changes changes)))
shapes (if (= (:mtype media-obj) "image/svg+xml") shapes (if (= (:mtype media-obj) "image/svg+xml")
(->> (dwm/load-and-parse-svg media-obj) (->> (dwm/load-and-parse-svg media-obj)
(rx/mapcat (partial dwm/create-shapes-svg (:id file-data) (:objects page) pos))) (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/concat
(rx/of (update-remove-graphics index)) (rx/of (update-remove-graphics index))

View file

@ -313,8 +313,6 @@
(ptk/data-event :layout/update parents) (ptk/data-event :layout/update parents)
(dwt/update-thumbnail file-id page-id (:id root)))))))))) (dwt/update-thumbnail file-id page-id (:id root))))))))))
(defn add-component (defn add-component
"Add a new component to current file library, from the currently selected shapes. "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 This operation is made in two steps, first one for calculate the
@ -330,7 +328,6 @@
components-v2 (features/active-feature? state :components-v2)] components-v2 (features/active-feature? state :components-v2)]
(rx/of (add-component2 selected components-v2)))))) (rx/of (add-component2 selected components-v2))))))
(defn add-multiple-components (defn add-multiple-components
"Add several new components to current file library, from the currently selected shapes." "Add several new components to current file library, from the currently selected shapes."
[] []

View file

@ -282,9 +282,9 @@
(defn create-shapes-img (defn create-shapes-img
"Convert a media object that contains a bitmap image into shapes, "Convert a media object that contains a bitmap image into shapes,
one shape of type :image and one group that contains it." 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 (let [group-shape (cts/setup-shape
{:type :group {:type wrapper-type
:x (:x pos) :x (:x pos)
:y (:y pos) :y (:y pos)
:width width :width width

View file

@ -100,7 +100,7 @@
parent-id (get-in objects [frame-id :parent-id]) parent-id (get-in objects [frame-id :parent-id])
ordered-indexes (->> ordered-indexes (remove #(= % parent-id))) ordered-indexes (->> ordered-indexes (remove #(= % parent-id)))
to-move-shapes (map (d/getf objects) ordered-indexes)] to-move-shapes (map (d/getf objects) ordered-indexes)]
(when (d/not-empty? to-move-shapes) (if (d/not-empty? to-move-shapes)
(-> changes (-> changes
(cond-> (not (ctl/any-layout? objects frame-id)) (cond-> (not (ctl/any-layout? objects frame-id))
(pcb/update-shapes ordered-indexes ctl/remove-layout-item-data)) (pcb/update-shapes ordered-indexes ctl/remove-layout-item-data))
@ -108,7 +108,8 @@
(pcb/change-parent frame-id to-move-shapes 0) (pcb/change-parent frame-id to-move-shapes 0)
(cond-> (ctl/grid-layout? objects frame-id) (cond-> (ctl/grid-layout? objects frame-id)
(pcb/update-shapes [frame-id] ctl/assign-cells)) (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 (defn move-shapes-into-frame
[frame-id shapes] [frame-id shapes]