0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 06:32:38 -05:00

🐛 Fix ungroup a component copy

This commit is contained in:
Alejandro Alonso 2023-12-05 13:53:27 +01:00 committed by Andrey Antukh
parent eea55706a4
commit a9ba35c0d2
2 changed files with 6 additions and 51 deletions

View file

@ -13,14 +13,10 @@
[app.common.geom.shapes :as gsh]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.pages-list :as ctpl]
[app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.shapes :as dwsh]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.undo :as dwu]
[beicon.core :as rx]
@ -178,45 +174,6 @@
(pcb/remove-objects [(:id frame)]))))
(defn- clone-component-shapes-changes
[changes shape objects]
(let [shape-parent-id (:parent-id shape)
new-shape-id (uuid/next)
[_ new-shapes _]
(ctst/clone-object shape
shape-parent-id
objects
(fn [object _]
(cond-> object
(= new-shape-id (:parent-id object))
(assoc :parent-id shape-parent-id)))
(fn [object _] object)
new-shape-id
false)
new-shapes (->> new-shapes
(filter #(not= (:id %) new-shape-id)))]
(reduce
(fn [changes shape]
(pcb/add-object changes shape))
changes
new-shapes)))
(defn remove-component-changes
[it page-id shape objects file-data file]
(let [page (ctpl/get-page file-data page-id)
components-v2 (dm/get-in file-data [:options :components-v2])
;; In order to ungroup a component, we first make a clone of its shapes,
;; and then we delete it
changes (-> (pcb/empty-changes it page-id)
(pcb/with-objects objects)
(pcb/with-library-data file-data)
(pcb/with-page page)
(clone-component-shapes-changes shape objects)
(dwsh/delete-shapes-changes file page objects [(:id shape)] it components-v2))]
;; TODO: Should we call detach-comment-thread ?
changes))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUPS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -245,17 +202,12 @@
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
file-data (get state :workspace-data)
file (wsh/get-local-file state)
prepare
(fn [shape-id]
(let [shape (get objects shape-id)
changes
(cond
(ctk/main-instance? shape)
(remove-component-changes it page-id shape objects file-data file)
(or (cfh/group-shape? shape) (cfh/bool-shape? shape))
(remove-group-changes it page-id shape objects)
@ -267,7 +219,9 @@
(pcb/update-shapes [(:parent-id shape)] ctl/assign-cells))))
selected (->> (wsh/lookup-selected state)
(remove #(ctn/has-any-copy-parent? objects (get objects %))))
(remove #(ctn/has-any-copy-parent? objects (get objects %)))
;; components can't be ungrouped
(remove #(ctk/instance-head? (get objects %))))
changes-list (sequence
(keep prepare)
selected)

View file

@ -253,8 +253,9 @@
single? (= (count shapes) 1)
do-create-artboard-from-selection #(st/emit! (dwsh/create-artboard-from-selection))
has-frame? (->> shapes (d/seek cfh/frame-shape?))
has-group? (->> shapes (d/seek cfh/group-shape?))
;; components can't be ungrouped
has-frame? (->> shapes (d/seek #(and (cfh/frame-shape? %) (not (ctk/instance-head? %)))))
has-group? (->> shapes (d/seek #(and (cfh/group-shape? %) (not (ctk/instance-head? %)))))
has-bool? (->> shapes (d/seek cfh/bool-shape?))
has-mask? (->> shapes (d/seek :masked-group))