mirror of
https://github.com/penpot/penpot.git
synced 2026-05-26 10:23:45 +00:00
Improved delete-shape event.
This commit is contained in:
parent
d74d2d7295
commit
16a4d4c8b4
@ -138,26 +138,42 @@
|
|||||||
(assoc-in $ [:shapes-by-id sid] shape))))))
|
(assoc-in $ [:shapes-by-id sid] shape))))))
|
||||||
|
|
||||||
|
|
||||||
;; FIXME: delete shape that is part of group.
|
|
||||||
(defn delete-shape
|
(defn delete-shape
|
||||||
"Remove the shape using its id."
|
"Remove the shape using its id."
|
||||||
[id]
|
[id]
|
||||||
(letfn [(dissoc-shape [state {:keys [id] :as shape}]
|
(letfn [(dissoc-group [state {:keys [id] :as shape}]
|
||||||
(if (= (:type shape) :builtin/group)
|
(let [state (update-in state [:shapes-by-id] dissoc id)]
|
||||||
(let [state (update-in state [:shapes-by-id] dissoc id)]
|
(->> (:items shape)
|
||||||
(->> (map #(get-in state [:shapes-by-id %]) (:items shape))
|
(map #(get-in state [:shapes-by-id %]))
|
||||||
(reduce dissoc-shape state)))
|
(reduce dissoc-from-index state))))
|
||||||
(update-in state [:shapes-by-id] dissoc id)))]
|
|
||||||
|
(dissoc-icon [state {:keys [id] :as shape}]
|
||||||
|
(update-in state [:shapes-by-id] dissoc id))
|
||||||
|
|
||||||
|
(dissoc-from-group [state {:keys [id group] :as shape}]
|
||||||
|
(if-let [group' (get-in state [:shapes-by-id group])]
|
||||||
|
(as-> (:items group') $
|
||||||
|
(into [] (remove #(= % id) $))
|
||||||
|
(assoc-in state [:shapes-by-id group :items] $))
|
||||||
|
state))
|
||||||
|
|
||||||
|
(dissoc-from-page [state {:keys [page id] :as shape}]
|
||||||
|
(as-> (get-in state [:pages-by-id page :shapes]) $
|
||||||
|
(into [] (remove #(= % id) $))
|
||||||
|
(assoc-in state [:pages-by-id page :shapes] $)))
|
||||||
|
|
||||||
|
(dissoc-from-index [state shape]
|
||||||
|
(case (:type shape)
|
||||||
|
:builtin/icon (dissoc-icon state shape)
|
||||||
|
:builtin/group (dissoc-group state shape)))]
|
||||||
(reify
|
(reify
|
||||||
rs/UpdateEvent
|
rs/UpdateEvent
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(let [shape (get-in state [:shapes-by-id id])
|
(let [shape (get-in state [:shapes-by-id id])]
|
||||||
pageid (:page shape)
|
(as-> state $
|
||||||
shapes (get-in state [:pages-by-id pageid :shapes])
|
(dissoc-from-page $ shape)
|
||||||
shapes (into [] (remove #(= % id) shapes))]
|
(dissoc-from-group $ shape)
|
||||||
(as-> state $
|
(dissoc-from-index $ shape)))))))
|
||||||
(assoc-in $ [:pages-by-id pageid :shapes] shapes)
|
|
||||||
(dissoc-shape $ shape)))))))
|
|
||||||
|
|
||||||
(defn move-shape
|
(defn move-shape
|
||||||
"Mark a shape selected for drawing in the canvas."
|
"Mark a shape selected for drawing in the canvas."
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user