mirror of
https://github.com/penpot/penpot.git
synced 2025-05-12 11:06:38 +02:00
🐛 Fix issue when group creation leaves an empty group
This commit is contained in:
parent
5730769a19
commit
ed95b59003
4 changed files with 100 additions and 29 deletions
|
@ -33,6 +33,7 @@
|
||||||
- Fix problem with imported SVG on editing paths [#971](https://github.com/penpot/penpot/issues/971)
|
- Fix problem with imported SVG on editing paths [#971](https://github.com/penpot/penpot/issues/971)
|
||||||
- Fix problem with color picker positioning
|
- Fix problem with color picker positioning
|
||||||
- Fix order on color palette [#961](https://github.com/penpot/penpot/issues/961)
|
- Fix order on color palette [#961](https://github.com/penpot/penpot/issues/961)
|
||||||
|
- Fix issue when group creation leaves an empty group [#1724](https://tree.taiga.io/project/penpot/issue/1724)
|
||||||
|
|
||||||
### :arrow_up: Deps updates
|
### :arrow_up: Deps updates
|
||||||
|
|
||||||
|
|
|
@ -991,19 +991,22 @@
|
||||||
[[] [] []]
|
[[] [] []]
|
||||||
ids)
|
ids)
|
||||||
|
|
||||||
[rchanges uchanges] (relocate-shapes-changes objects
|
[rchanges uchanges]
|
||||||
parents
|
(relocate-shapes-changes objects
|
||||||
parent-id
|
parents
|
||||||
page-id
|
parent-id
|
||||||
to-index
|
page-id
|
||||||
ids
|
to-index
|
||||||
groups-to-delete
|
ids
|
||||||
groups-to-unmask
|
groups-to-delete
|
||||||
shapes-to-detach
|
groups-to-unmask
|
||||||
shapes-to-reroot
|
shapes-to-detach
|
||||||
shapes-to-deroot)]
|
shapes-to-reroot
|
||||||
|
shapes-to-deroot)
|
||||||
|
|
||||||
|
]
|
||||||
(rx/of (dch/commit-changes {:redo-changes rchanges
|
(rx/of (dch/commit-changes {:redo-changes rchanges
|
||||||
:undo-chanes uchanges
|
:undo-changes uchanges
|
||||||
:origin it})
|
:origin it})
|
||||||
(dwc/expand-collapse parent-id))))))
|
(dwc/expand-collapse parent-id))))))
|
||||||
|
|
||||||
|
@ -1058,7 +1061,7 @@
|
||||||
:id id
|
:id id
|
||||||
:index cidx}]
|
:index cidx}]
|
||||||
(rx/of (dch/commit-changes {:redo-changes [rchg]
|
(rx/of (dch/commit-changes {:redo-changes [rchg]
|
||||||
:undo-chanes [uchg]
|
:undo-changes [uchg]
|
||||||
:origin it}))))))
|
:origin it}))))))
|
||||||
|
|
||||||
;; --- Shape / Selection Alignment and Distribution
|
;; --- Shape / Selection Alignment and Distribution
|
||||||
|
|
|
@ -32,31 +32,97 @@
|
||||||
(gsh/setup selrect)
|
(gsh/setup selrect)
|
||||||
(assoc :shapes (mapv :id shapes)))))
|
(assoc :shapes (mapv :id shapes)))))
|
||||||
|
|
||||||
|
(defn get-empty-groups
|
||||||
|
"Retrieve emtpy groups after group creation"
|
||||||
|
[objects parent-id shapes]
|
||||||
|
(let [ids (cp/clean-loops objects (into #{} (map :id) shapes))
|
||||||
|
parents (->> ids
|
||||||
|
(reduce #(conj %1 (cp/get-parent %2 objects))
|
||||||
|
#{}))]
|
||||||
|
(loop [current-id (first parents)
|
||||||
|
to-check (rest parents)
|
||||||
|
removed-id? ids
|
||||||
|
result #{}]
|
||||||
|
|
||||||
|
(if-not current-id
|
||||||
|
;; Base case, no next element
|
||||||
|
result
|
||||||
|
|
||||||
|
(let [group (get objects current-id)]
|
||||||
|
(if (and (not= :frame (:type group))
|
||||||
|
(not= current-id parent-id)
|
||||||
|
(empty? (remove removed-id? (:shapes group))))
|
||||||
|
|
||||||
|
;; Adds group to the remove and check its parent
|
||||||
|
(let [to-check (d/concat [] to-check [(cp/get-parent current-id objects)]) ]
|
||||||
|
(recur (first to-check)
|
||||||
|
(rest to-check)
|
||||||
|
(conj removed-id? current-id)
|
||||||
|
(conj result current-id)))
|
||||||
|
|
||||||
|
;; otherwise recur
|
||||||
|
(recur (first to-check)
|
||||||
|
(rest to-check)
|
||||||
|
removed-id?
|
||||||
|
result)))))))
|
||||||
|
|
||||||
(defn prepare-create-group
|
(defn prepare-create-group
|
||||||
[page-id shapes prefix keep-name]
|
[objects page-id shapes prefix keep-name]
|
||||||
(let [group (make-group shapes prefix keep-name)
|
(let [group (make-group shapes prefix keep-name)
|
||||||
|
frame-id (:frame-id (first shapes))
|
||||||
|
parent-id (:parent-id (first shapes))
|
||||||
rchanges [{:type :add-obj
|
rchanges [{:type :add-obj
|
||||||
:id (:id group)
|
:id (:id group)
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:frame-id (:frame-id (first shapes))
|
:frame-id frame-id
|
||||||
:parent-id (:parent-id (first shapes))
|
:parent-id parent-id
|
||||||
:obj group
|
:obj group
|
||||||
:index (::index (first shapes))}
|
:index (::index (first shapes))}
|
||||||
|
|
||||||
{:type :mov-objects
|
{:type :mov-objects
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:parent-id (:id group)
|
:parent-id (:id group)
|
||||||
:shapes (mapv :id shapes)}]
|
:shapes (mapv :id shapes)}]
|
||||||
|
|
||||||
uchanges (conj
|
uchanges (-> (mapv
|
||||||
(mapv (fn [obj] {:type :mov-objects
|
(fn [obj]
|
||||||
:page-id page-id
|
{:type :mov-objects
|
||||||
:parent-id (:parent-id obj)
|
:page-id page-id
|
||||||
:index (::index obj)
|
:parent-id (:parent-id obj)
|
||||||
:shapes [(:id obj)]})
|
:index (::index obj)
|
||||||
shapes)
|
:shapes [(:id obj)]}) shapes)
|
||||||
{:type :del-obj
|
(conj
|
||||||
:id (:id group)
|
{:type :del-obj
|
||||||
:page-id page-id})]
|
:id (:id group)
|
||||||
|
:page-id page-id}))
|
||||||
|
|
||||||
|
ids-to-delete (get-empty-groups objects parent-id shapes)
|
||||||
|
|
||||||
|
delete-group
|
||||||
|
(fn [changes id]
|
||||||
|
(-> changes
|
||||||
|
(conj {:type :del-obj
|
||||||
|
:id id
|
||||||
|
:page-id page-id})))
|
||||||
|
|
||||||
|
add-deleted-group
|
||||||
|
(fn [changes id]
|
||||||
|
(let [obj (-> (get objects id)
|
||||||
|
(d/without-keys [:shapes]))]
|
||||||
|
|
||||||
|
(d/concat [{:type :add-obj
|
||||||
|
:id id
|
||||||
|
:page-id page-id
|
||||||
|
:frame-id (:frame-id obj)
|
||||||
|
:parent-id (:parent-id obj)
|
||||||
|
:obj obj
|
||||||
|
:index (::index obj)}] changes)))
|
||||||
|
|
||||||
|
rchanges (->> ids-to-delete
|
||||||
|
(reduce delete-group rchanges))
|
||||||
|
|
||||||
|
uchanges (->> ids-to-delete
|
||||||
|
(reduce add-deleted-group uchanges))]
|
||||||
[group rchanges uchanges]))
|
[group rchanges uchanges]))
|
||||||
|
|
||||||
(defn prepare-remove-group
|
(defn prepare-remove-group
|
||||||
|
@ -107,7 +173,8 @@
|
||||||
selected (cp/clean-loops objects selected)
|
selected (cp/clean-loops objects selected)
|
||||||
shapes (shapes-for-grouping objects selected)]
|
shapes (shapes-for-grouping objects selected)]
|
||||||
(when-not (empty? shapes)
|
(when-not (empty? shapes)
|
||||||
(let [[group rchanges uchanges] (prepare-create-group page-id shapes "Group-" false)]
|
(let [[group rchanges uchanges]
|
||||||
|
(prepare-create-group objects page-id shapes "Group-" false)]
|
||||||
(rx/of (dch/commit-changes {:redo-changes rchanges
|
(rx/of (dch/commit-changes {:redo-changes rchanges
|
||||||
:undo-changes uchanges
|
:undo-changes uchanges
|
||||||
:origin it})
|
:origin it})
|
||||||
|
@ -146,7 +213,7 @@
|
||||||
(if (and (= (count shapes) 1)
|
(if (and (= (count shapes) 1)
|
||||||
(= (:type (first shapes)) :group))
|
(= (:type (first shapes)) :group))
|
||||||
[(first shapes) [] []]
|
[(first shapes) [] []]
|
||||||
(prepare-create-group page-id shapes "Group-" true))
|
(prepare-create-group objects page-id shapes "Group-" true))
|
||||||
|
|
||||||
rchanges (d/concat rchanges
|
rchanges (d/concat rchanges
|
||||||
[{:type :mod-obj
|
[{:type :mod-obj
|
||||||
|
|
|
@ -131,7 +131,7 @@
|
||||||
(if (and (= (count shapes) 1)
|
(if (and (= (count shapes) 1)
|
||||||
(= (:type (first shapes)) :group))
|
(= (:type (first shapes)) :group))
|
||||||
[(first shapes) [] []]
|
[(first shapes) [] []]
|
||||||
(dwg/prepare-create-group page-id shapes "Component-" true))
|
(dwg/prepare-create-group objects page-id shapes "Component-" true))
|
||||||
|
|
||||||
[new-shape new-shapes updated-shapes]
|
[new-shape new-shapes updated-shapes]
|
||||||
(make-component-shape group objects file-id)
|
(make-component-shape group objects file-id)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue