mirror of
https://github.com/penpot/penpot.git
synced 2026-09-06 12:09:24 +00:00
Split some conditions as separated predicate functions.
This commit is contained in:
parent
70282daaf7
commit
ef0e0ab74c
@ -13,7 +13,6 @@
|
|||||||
[uxbox.state :as st]
|
[uxbox.state :as st]
|
||||||
[uxbox.state.shapes :as stsh]
|
[uxbox.state.shapes :as stsh]
|
||||||
[uxbox.schema :as sc]
|
[uxbox.schema :as sc]
|
||||||
[uxbox.xforms :as xf]
|
|
||||||
[uxbox.data.pages :as udp]
|
[uxbox.data.pages :as udp]
|
||||||
[uxbox.util.geom.point :as gpt]
|
[uxbox.util.geom.point :as gpt]
|
||||||
[uxbox.util.data :refer (index-of)]))
|
[uxbox.util.data :refer (index-of)]))
|
||||||
@ -294,23 +293,43 @@
|
|||||||
(update-in state [:workspace :selected] disj id)
|
(update-in state [:workspace :selected] disj id)
|
||||||
(update-in state [:workspace :selected] conj id))))))
|
(update-in state [:workspace :selected] conj id))))))
|
||||||
|
|
||||||
|
;; --- Select Shapes
|
||||||
|
|
||||||
|
(defn- not-blocked-group?
|
||||||
|
"Check if the shape is a blocked group."
|
||||||
|
[shape]
|
||||||
|
(and (not (:blocked shape))
|
||||||
|
(= :builtin/group (:type shape))))
|
||||||
|
|
||||||
|
(defn- has-blocked-parent?
|
||||||
|
"Check if shape has blocked parent."
|
||||||
|
[shape]
|
||||||
|
(sh/parent-satisfies? shape :blocked))
|
||||||
|
|
||||||
|
(defn- has-locked-parent?
|
||||||
|
[shape]
|
||||||
|
(sh/parent-satisfies? shape :locked))
|
||||||
|
|
||||||
|
(defrecord SelectShapes [selrect]
|
||||||
|
rs/UpdateEvent
|
||||||
|
(-apply-update [_ state]
|
||||||
|
(let [pageid (get-in state [:workspace :page])
|
||||||
|
xform (comp (filter #(= (:page %) pageid))
|
||||||
|
(remove :hidden)
|
||||||
|
(remove :blocked)
|
||||||
|
(remove not-blocked-group?)
|
||||||
|
(remove has-locked-parent?)
|
||||||
|
(remove has-blocked-parent?)
|
||||||
|
(map sh/outer-rect')
|
||||||
|
(filter #(sh/contained-in? % selrect))
|
||||||
|
(map :id))]
|
||||||
|
(->> (into #{} xform (vals (:shapes-by-id state)))
|
||||||
|
(assoc-in state [:workspace :selected])))))
|
||||||
|
|
||||||
(defn select-shapes
|
(defn select-shapes
|
||||||
"Select shapes that matches the select rect."
|
"Select shapes that matches the select rect."
|
||||||
[selrect]
|
[selrect]
|
||||||
(reify
|
(SelectShapes. selrect))
|
||||||
rs/UpdateEvent
|
|
||||||
(-apply-update [_ state]
|
|
||||||
(let [pageid (get-in state [:workspace :page])
|
|
||||||
xf (comp
|
|
||||||
(filter #(= (:page %) pageid))
|
|
||||||
(remove :hidden)
|
|
||||||
(remove #(and (not (:blocked %)) (= (:type %) :builtin/group)))
|
|
||||||
(remove #(and (not= % (sh/resolve-parent %)) (:blocked (sh/resolve-parent %))))
|
|
||||||
(map sh/outer-rect')
|
|
||||||
(filter #(sh/contained-in? % selrect))
|
|
||||||
(map :id))]
|
|
||||||
(->> (into #{} xf (vals (:shapes-by-id state)))
|
|
||||||
(assoc-in state [:workspace :selected]))))))
|
|
||||||
|
|
||||||
;; --- Events (implicit) (for selected)
|
;; --- Events (implicit) (for selected)
|
||||||
|
|
||||||
|
|||||||
@ -498,6 +498,18 @@
|
|||||||
(resolve-parent (get-in @st/state [:shapes-by-id group]))
|
(resolve-parent (get-in @st/state [:shapes-by-id group]))
|
||||||
shape))
|
shape))
|
||||||
|
|
||||||
|
(defn parent-satisfies?
|
||||||
|
"Resolve the first parent that satisfies a condition."
|
||||||
|
[{:keys [group] :as shape} pred]
|
||||||
|
(let [shapes-by-id (:shapes-by-id @st/state)]
|
||||||
|
(if group
|
||||||
|
(loop [parent (get shapes-by-id group)]
|
||||||
|
(cond
|
||||||
|
(pred parent) true
|
||||||
|
(:group parent) (recur (get shapes-by-id (:group parent)))
|
||||||
|
:else false))
|
||||||
|
false)))
|
||||||
|
|
||||||
(defn contained-in?
|
(defn contained-in?
|
||||||
"Check if a shape is contained in the
|
"Check if a shape is contained in the
|
||||||
provided selection rect."
|
provided selection rect."
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user