mirror of
https://github.com/penpot/penpot.git
synced 2025-05-20 19:26:11 +02:00
Merge pull request #3892 from penpot/superalex-fix-ungroup-a-copy
🐛 Fix ungroup a component
This commit is contained in:
commit
87df30eefe
2 changed files with 6 additions and 51 deletions
|
@ -13,14 +13,10 @@
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
[app.common.types.container :as ctn]
|
[app.common.types.container :as ctn]
|
||||||
[app.common.types.pages-list :as ctpl]
|
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
[app.common.types.shape-tree :as ctst]
|
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
[app.common.uuid :as uuid]
|
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
[app.main.data.workspace.selection :as dws]
|
[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.state-helpers :as wsh]
|
||||||
[app.main.data.workspace.undo :as dwu]
|
[app.main.data.workspace.undo :as dwu]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
|
@ -178,45 +174,6 @@
|
||||||
(pcb/remove-objects [(:id frame)]))))
|
(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
|
;; GROUPS
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -245,17 +202,12 @@
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
file-data (get state :workspace-data)
|
|
||||||
file (wsh/get-local-file state)
|
|
||||||
|
|
||||||
prepare
|
prepare
|
||||||
(fn [shape-id]
|
(fn [shape-id]
|
||||||
(let [shape (get objects shape-id)
|
(let [shape (get objects shape-id)
|
||||||
changes
|
changes
|
||||||
(cond
|
(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))
|
(or (cfh/group-shape? shape) (cfh/bool-shape? shape))
|
||||||
(remove-group-changes it page-id shape objects)
|
(remove-group-changes it page-id shape objects)
|
||||||
|
|
||||||
|
@ -267,7 +219,9 @@
|
||||||
(pcb/update-shapes [(:parent-id shape)] ctl/assign-cells))))
|
(pcb/update-shapes [(:parent-id shape)] ctl/assign-cells))))
|
||||||
|
|
||||||
selected (->> (wsh/lookup-selected state)
|
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
|
changes-list (sequence
|
||||||
(keep prepare)
|
(keep prepare)
|
||||||
selected)
|
selected)
|
||||||
|
|
|
@ -253,8 +253,9 @@
|
||||||
single? (= (count shapes) 1)
|
single? (= (count shapes) 1)
|
||||||
do-create-artboard-from-selection #(st/emit! (dwsh/create-artboard-from-selection))
|
do-create-artboard-from-selection #(st/emit! (dwsh/create-artboard-from-selection))
|
||||||
|
|
||||||
has-frame? (->> shapes (d/seek cfh/frame-shape?))
|
;; components can't be ungrouped
|
||||||
has-group? (->> shapes (d/seek cfh/group-shape?))
|
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-bool? (->> shapes (d/seek cfh/bool-shape?))
|
||||||
has-mask? (->> shapes (d/seek :masked-group))
|
has-mask? (->> shapes (d/seek :masked-group))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue