mirror of
https://github.com/penpot/penpot.git
synced 2025-03-12 07:41:43 -05:00
parent
13e02283d8
commit
b313aa47ce
2 changed files with 53 additions and 6 deletions
|
@ -419,6 +419,16 @@
|
||||||
(assert (not (nil? parent-id)) "parent-id should never be nil here")
|
(assert (not (nil? parent-id)) "parent-id should never be nil here")
|
||||||
(update-in state [:shapes parent-id :items] #(into [] (remove #{id}) %)))
|
(update-in state [:shapes parent-id :items] #(into [] (remove #{id}) %)))
|
||||||
|
|
||||||
|
(strip-empty-groups [state parent-id]
|
||||||
|
(if (nil? parent-id)
|
||||||
|
state
|
||||||
|
(let [group (get-in state [:shapes parent-id])]
|
||||||
|
(if (empty? (:items group))
|
||||||
|
(-> state
|
||||||
|
(remove-group group)
|
||||||
|
(strip-empty-groups (:group group)))
|
||||||
|
state))))
|
||||||
|
|
||||||
(selective-degroup [state [shape & rest :as shapes]]
|
(selective-degroup [state [shape & rest :as shapes]]
|
||||||
(let [group (get-in state [:shapes (:group shape)])
|
(let [group (get-in state [:shapes (:group shape)])
|
||||||
position (get-relocation-position state group)
|
position (get-relocation-position state group)
|
||||||
|
@ -429,7 +439,8 @@
|
||||||
(-> state
|
(-> state
|
||||||
(relocate-shape shape-id parent-id position)
|
(relocate-shape shape-id parent-id position)
|
||||||
(remove-from-parent shape-id (:id group))))
|
(remove-from-parent shape-id (:id group))))
|
||||||
$ shapes))))]
|
$ (reverse shapes))
|
||||||
|
(strip-empty-groups $ (:id group)))))]
|
||||||
(let [shapes (into #{} (map #(get-in state [:shapes %])) shapes)
|
(let [shapes (into #{} (map #(get-in state [:shapes %])) shapes)
|
||||||
groups (into #{} (filter #(= (:type %) :group)) shapes)
|
groups (into #{} (filter #(= (:type %) :group)) shapes)
|
||||||
parents (into #{} (map :group) shapes)]
|
parents (into #{} (map :group) shapes)]
|
||||||
|
|
|
@ -455,11 +455,47 @@
|
||||||
:pages {1 {:id 1 :shapes [1 3]}}
|
:pages {1 {:id 1 :shapes [1 3]}}
|
||||||
:shapes {1 {:id 1 :page 1}
|
:shapes {1 {:id 1 :page 1}
|
||||||
2 {:id 2 :page 1 :group 3}
|
2 {:id 2 :page 1 :group 3}
|
||||||
3 {:id 3 :page 1 :type :group :items [2]}}}]
|
3 {:id 3 :page 1 :type :group :items [2]}}}
|
||||||
(let [result (impl/degroup-shapes initial [1] 1)]
|
result (impl/degroup-shapes initial [1] 1)]
|
||||||
;; (pprint expected)
|
;; (pprint expected)
|
||||||
;; (pprint result)
|
;; (pprint result)
|
||||||
(t/is (= result expected)))))
|
(t/is (= result expected))))
|
||||||
|
|
||||||
|
|
||||||
|
;; degroup all shapes from group
|
||||||
|
|
||||||
|
(t/deftest degroup-shapes-1-2
|
||||||
|
(let [initial {:pages {1 {:id 1 :shapes [3]}}
|
||||||
|
:shapes {1 {:id 1 :page 1 :group 3}
|
||||||
|
2 {:id 2 :page 1 :group 3}
|
||||||
|
3 {:id 3 :page 1 :type :group :items [1 2]}}}
|
||||||
|
expected {:workspace {:selected #{1 2}}
|
||||||
|
:pages {1 {:id 1 :shapes [1 2]}}
|
||||||
|
:shapes {1 {:id 1 :page 1}
|
||||||
|
2 {:id 2 :page 1}}}
|
||||||
|
result (impl/degroup-shapes initial [1 2] 1)]
|
||||||
|
;; (pprint expected)
|
||||||
|
;; (pprint result)
|
||||||
|
(t/is (= result expected))))
|
||||||
|
|
||||||
|
|
||||||
|
;; degroup all shapes from neested group
|
||||||
|
|
||||||
|
(t/deftest degroup-shapes-1-3
|
||||||
|
(let [initial {:pages {1 {:id 1 :shapes [4]}}
|
||||||
|
:shapes {1 {:id 1 :page 1 :group 3}
|
||||||
|
2 {:id 2 :page 1 :group 3}
|
||||||
|
3 {:id 3 :page 1 :group 4 :type :group :items [1 2]}
|
||||||
|
4 {:id 4 :page 1 :type :group :items [3]}}}
|
||||||
|
expected {:workspace {:selected #{1 2}}
|
||||||
|
:pages {1 {:id 1 :shapes [4]}}
|
||||||
|
:shapes {1 {:id 1 :page 1 :group 4}
|
||||||
|
2 {:id 2 :page 1 :group 4}
|
||||||
|
4 {:id 4 :page 1 :type :group :items [1 2]}}}
|
||||||
|
result (impl/degroup-shapes initial [1 2] 1)]
|
||||||
|
;; (pprint expected)
|
||||||
|
;; (pprint result)
|
||||||
|
(t/is (= result expected))))
|
||||||
|
|
||||||
;; degroup group inside a group
|
;; degroup group inside a group
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue