diff --git a/src/uxbox/data/shapes.cljs b/src/uxbox/data/shapes.cljs index ff0b10f8d..088ff2e5f 100644 --- a/src/uxbox/data/shapes.cljs +++ b/src/uxbox/data/shapes.cljs @@ -311,36 +311,12 @@ ;; --- Select Shapes -(defn- not-blocked-group? - "Check if the shape is a blocked group." - [shape] - (and (not (:blocked shape)) - (= :group (:type shape)))) - -(defn- has-blocked-parent? - "Check if shape has blocked parent." - [shape] - (geom/parent-satisfies? shape :blocked)) - -(defn- has-locked-parent? - [shape] - (geom/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 geom/outer-rect) - (filter #(geom/contained-in? % selrect)) - (map :id))] - (->> (into #{} xform (vals (:shapes-by-id state))) - (assoc-in state [:workspace :selected]))))) + (let [page (get-in state [:workspace :page]) + shapes (stsh/match-by-selrect state page selrect)] + (assoc-in state [:workspace :selected] shapes)))) (defn select-shapes "Select shapes that matches the select rect." diff --git a/src/uxbox/state/shapes.cljs b/src/uxbox/state/shapes.cljs index 664bcd33c..8a1cc94ab 100644 --- a/src/uxbox/state/shapes.cljs +++ b/src/uxbox/state/shapes.cljs @@ -1,6 +1,7 @@ (ns uxbox.state.shapes "A collection of functions for manage shapes insinde the state." - (:require [uxbox.util.data :refer (index-of)])) + (:require [uxbox.util.data :refer (index-of)] + [uxbox.util.geom :as geom])) ;; --- Shape Creation @@ -235,24 +236,30 @@ :bottom (drop-relative state :last shape) (throw (ex-info "Invalid data" {})))) -;; --- Shape Packing +;; --- Shape Selection -;; (defn- deep-scan-shape-ids -;; [state acc id] -;; (let [shape (get-in state [:shapes-by-id id])] -;; (if (= (:type shape) :group) -;; (reduce (partial deep-scan-shape-ids state) -;; (conj acc id) -;; (:items shape)) -;; (conj acc id)))) +(defn- try-match-shape + [xf selrect acc {:keys [type id items] :as shape}] + (cond + (geom/contained-in? shape selrect) + (conj acc id) -;; (defn pack-shape -;; [state id] -;; (let [ids (deep-scan-shape-ids state #{} id) -;; index (reduce (fn [acc id] -;; (let [shape (get-in state [:shapes-by-id id])] -;; (assoc acc id shape))) -;; {} ids)] -;; {:type :packed-shape -;; :index index -;; :id id})) + (:locked shape) + acc + + (= type :group) + (reduce (partial try-match-shape xf selrect) + acc (sequence xf items)) + + :else + acc)) + +(defn match-by-selrect + [state page selrect] + (let [xf (comp (map #(get-in state [:shapes-by-id %])) + (remove :hidden) + (remove :blocked) + (map geom/outer-rect)) + match (partial try-match-shape xf selrect) + shapes (get-in state [:pages-by-id page :shapes])] + (reduce match #{} (sequence xf shapes))))