0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 00:40:30 -05:00

Improved blocking/unblocking shapes on layers toolbox.

This commit is contained in:
Andrey Antukh 2016-01-29 21:44:53 +02:00
parent 18b07d509c
commit 07359752ff
2 changed files with 31 additions and 8 deletions

View file

@ -254,16 +254,36 @@
(assoc-in state [:shapes-by-id sid] (assoc shape :hidden false)) (assoc-in state [:shapes-by-id sid] (assoc shape :hidden false))
(assoc-in state [:shapes-by-id sid] (assoc shape :hidden true))))))) (assoc-in state [:shapes-by-id sid] (assoc shape :hidden true)))))))
(defn toggle-shape-blocking
(defn block-shape
[sid] [sid]
(reify (reify
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(let [shape (get-in state [:shapes-by-id sid]) (assoc-in state [:shapes-by-id sid :blocked] true))
blocked? (:blocked shape false)]
(if blocked? rs/WatchEvent
(assoc-in state [:shapes-by-id sid] (assoc shape :blocked false)) (-apply-watch [_ state]
(assoc-in state [:shapes-by-id sid] (assoc shape :blocked true))))))) (let [shape (get-in state [:shapes-by-id sid])]
(if-not (= (:type shape) :builtin/group)
(rx/empty)
(rx/from-coll
(map block-shape (:items shape))))))))
(defn unblock-shape
[sid]
(reify
rs/UpdateEvent
(-apply-update [_ state]
(assoc-in state [:shapes-by-id sid :blocked] false))
rs/WatchEvent
(-apply-watch [_ state]
(let [shape (get-in state [:shapes-by-id sid])]
(if-not (= (:type shape) :builtin/group)
(rx/empty)
(rx/from-coll
(map unblock-shape (:items shape))))))))
(defn toggle-shape-locking (defn toggle-shape-locking
[sid] [sid]

View file

@ -61,8 +61,11 @@
(defn- toggle-blocking (defn- toggle-blocking
[item event] [item event]
(dom/stop-propagation event) (dom/stop-propagation event)
(let [id (:id item)] (let [id (:id item)
(rs/emit! (dw/toggle-shape-blocking id)))) blocked? (:blocked item)]
(if blocked?
(rs/emit! (dw/unblock-shape id))
(rs/emit! (dw/block-shape id)))))
(defn- toggle-locking (defn- toggle-locking
[item event] [item event]