mirror of
https://github.com/penpot/penpot.git
synced 2025-02-26 08:45:34 -05:00
💄 Cosmetic changes to the group and ungroup events.
This commit is contained in:
parent
cd72860ea0
commit
3eb7cb0bb1
2 changed files with 63 additions and 61 deletions
|
@ -2286,73 +2286,75 @@
|
||||||
:width (:width selection-rect)
|
:width (:width selection-rect)
|
||||||
:height (:height selection-rect)})
|
:height (:height selection-rect)})
|
||||||
|
|
||||||
(defn create-group []
|
(def create-group
|
||||||
(let [id (uuid/next)]
|
(ptk/reify ::create-group
|
||||||
(ptk/reify ::create-group
|
ptk/WatchEvent
|
||||||
ptk/WatchEvent
|
(watch [_ state stream]
|
||||||
(watch [_ state stream]
|
(let [id (uuid/next)
|
||||||
(let [selected (get-in state [:workspace-local :selected])]
|
selected (get-in state [:workspace-local :selected])]
|
||||||
(if (not-empty selected)
|
(when (not-empty selected)
|
||||||
(let [page-id (get-in state [:workspace-page :id])
|
(let [page-id (get-in state [:workspace-page :id])
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
selected-objects (map (partial get objects) selected)
|
selected-objects (map (partial get objects) selected)
|
||||||
selection-rect (geom/selection-rect selected-objects)
|
selection-rect (geom/selection-rect selected-objects)
|
||||||
frame-id (-> selected-objects first :frame-id)
|
frame-id (-> selected-objects first :frame-id)
|
||||||
group-shape (group-shape id frame-id selected selection-rect)
|
group-shape (group-shape id frame-id selected selection-rect)
|
||||||
frame-children (get-in objects [frame-id :shapes])
|
frame-children (get-in objects [frame-id :shapes])
|
||||||
index-frame (->> frame-children (map-indexed vector) (filter #(selected (second %))) first first)]
|
index-frame (->> frame-children
|
||||||
|
(map-indexed vector)
|
||||||
|
(filter #(selected (second %)))
|
||||||
|
(ffirst))
|
||||||
|
|
||||||
(let [rchanges [{:type :add-obj
|
rchanges [{:type :add-obj
|
||||||
:id id
|
:id id
|
||||||
:frame-id frame-id
|
:frame-id frame-id
|
||||||
:obj group-shape
|
:obj group-shape
|
||||||
:index index-frame}
|
:index index-frame}
|
||||||
{:type :mov-objects
|
{:type :mov-objects
|
||||||
:parent-id id
|
:parent-id id
|
||||||
:shapes (into [] selected)}]
|
:shapes (vec selected)}]
|
||||||
uchanges [{:type :mov-objects
|
uchanges [{:type :mov-objects
|
||||||
:parent-id frame-id
|
:parent-id frame-id
|
||||||
:shapes (into [] selected)}
|
:shapes (vec selected)}
|
||||||
{:type :del-obj
|
{:type :del-obj
|
||||||
:id id}]]
|
:id id}]]
|
||||||
(rx/of (commit-changes rchanges uchanges {:commit-local? true})
|
(rx/of (commit-changes rchanges uchanges {:commit-local? true})
|
||||||
(fn [state] (assoc-in state [:workspace-local :selected] #{id})))))
|
(select-shapes #{id}))))))))
|
||||||
rx/empty))))))
|
|
||||||
|
|
||||||
(defn remove-group
|
(def remove-group
|
||||||
[]
|
|
||||||
(ptk/reify ::remove-group
|
(ptk/reify ::remove-group
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [selected (get-in state [:workspace-local :selected])
|
(let [page-id (::page-id state)
|
||||||
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
|
selected (get-in state [:workspace-local :selected])
|
||||||
group-id (first selected)
|
group-id (first selected)
|
||||||
group (get-in state [:workspace-data (::page-id state) :objects group-id])]
|
group (get objects group-id)]
|
||||||
(if (and (= (count selected) 1) (= (:type group) :group))
|
(when (and (= 1 (count selected))
|
||||||
(let [objects (get-in state [:workspace-data (::page-id state) :objects])
|
(= (:type group) :group))
|
||||||
shapes (get-in objects [group-id :shapes])
|
(let [shapes (:shapes group)
|
||||||
parent-id (helpers/get-parent group-id objects)
|
parent-id (helpers/get-parent group-id objects)
|
||||||
parent (get objects parent-id)
|
parent (get objects parent-id)
|
||||||
index-in-parent (->> (:shapes parent)
|
index-in-parent (->> (:shapes parent)
|
||||||
(map-indexed vector)
|
(map-indexed vector)
|
||||||
(filter #(#{group-id} (second %)))
|
(filter #(#{group-id} (second %)))
|
||||||
first first)]
|
(ffirst))
|
||||||
(let [rchanges [{:type :mov-objects
|
rchanges [{:type :mov-objects
|
||||||
:parent-id parent-id
|
:parent-id parent-id
|
||||||
:shapes shapes
|
:shapes shapes
|
||||||
:index index-in-parent}]
|
:index index-in-parent}]
|
||||||
uchanges [{:type :add-obj
|
uchanges [{:type :add-obj
|
||||||
:id group-id
|
:id group-id
|
||||||
:frame-id (:frame-id group)
|
:frame-id (:frame-id group)
|
||||||
:obj (assoc group :shapes [])}
|
:obj (assoc group :shapes [])}
|
||||||
{:type :mov-objects
|
{:type :mov-objects
|
||||||
:parent-id group-id
|
:parent-id group-id
|
||||||
:shapes shapes}
|
:shapes shapes}
|
||||||
{:type :mov-objects
|
{:type :mov-objects
|
||||||
:parent-id parent-id
|
:parent-id parent-id
|
||||||
:shapes [group-id]
|
:shapes [group-id]
|
||||||
:index index-in-parent}]]
|
:index index-in-parent}]]
|
||||||
(rx/of (commit-changes rchanges uchanges {:commit-local? true}))))
|
(rx/of (commit-changes rchanges uchanges {:commit-local? true}))))))))
|
||||||
rx/empty)))))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Shortcuts
|
;; Shortcuts
|
||||||
|
@ -2366,8 +2368,8 @@
|
||||||
"ctrl+shift+l" #(st/emit! (toggle-layout-flag :layers))
|
"ctrl+shift+l" #(st/emit! (toggle-layout-flag :layers))
|
||||||
"+" #(st/emit! increase-zoom)
|
"+" #(st/emit! increase-zoom)
|
||||||
"-" #(st/emit! decrease-zoom)
|
"-" #(st/emit! decrease-zoom)
|
||||||
"ctrl+g" #(st/emit! (create-group))
|
"ctrl+g" #(st/emit! create-group)
|
||||||
"ctrl+shift+g" #(st/emit! (remove-group))
|
"ctrl+shift+g" #(st/emit! remove-group)
|
||||||
"shift+0" #(st/emit! zoom-to-50)
|
"shift+0" #(st/emit! zoom-to-50)
|
||||||
"shift+1" #(st/emit! reset-zoom)
|
"shift+1" #(st/emit! reset-zoom)
|
||||||
"shift+2" #(st/emit! zoom-to-200)
|
"shift+2" #(st/emit! zoom-to-200)
|
||||||
|
|
|
@ -58,8 +58,8 @@
|
||||||
do-hide-shape #(st/emit! (dw/hide-shape (:id shape)))
|
do-hide-shape #(st/emit! (dw/hide-shape (:id shape)))
|
||||||
do-lock-shape #(st/emit! (dw/block-shape (:id shape)))
|
do-lock-shape #(st/emit! (dw/block-shape (:id shape)))
|
||||||
do-unlock-shape #(st/emit! (dw/unblock-shape (:id shape)))
|
do-unlock-shape #(st/emit! (dw/unblock-shape (:id shape)))
|
||||||
do-create-group #(st/emit! (dw/create-group))
|
do-create-group #(st/emit! dw/create-group)
|
||||||
do-remove-group #(st/emit! (dw/remove-group))]
|
do-remove-group #(st/emit! dw/remove-group)]
|
||||||
[:*
|
[:*
|
||||||
[:& menu-entry {:title "Copy"
|
[:& menu-entry {:title "Copy"
|
||||||
:shortcut "Ctrl + c"
|
:shortcut "Ctrl + c"
|
||||||
|
|
Loading…
Add table
Reference in a new issue