diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index afef7e2c1..fcc4253ae 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -1203,6 +1203,19 @@ (->> (impl-match-by-selrect state selrect) (assoc-in state [:workspace-local :selected])))))) +(defn select-inside-group + [group-id position] + (ptk/reify ::select-inside-group + ptk/UpdateEvent + (update [_ state] + (let [page-id (::page-id state) + objects (get-in state [:workspace-data page-id :objects]) + group (get objects group-id) + children (map #(get objects %) (:shapes group)) + selected (->> children (filter #(geom/has-point? % position)) first)] + (cond-> state + selected (assoc-in [:workspace-local :selected] #{(:id selected)})))))) + ;; --- Update Shape Attrs (defn update-shape diff --git a/frontend/src/uxbox/main/geom.cljs b/frontend/src/uxbox/main/geom.cljs index b8023a064..0558e826b 100644 --- a/frontend/src/uxbox/main/geom.cljs +++ b/frontend/src/uxbox/main/geom.cljs @@ -587,6 +587,20 @@ (< ry1 sy2) (> ry2 sy1)))) +(defn has-point? + [shape position] + (let [{:keys [x y]} position + selrect {:x1 (- x 5) + :y1 (- y 5) + :x2 (+ x 5) + :y2 (+ y 5) + :x (- x 5) + :y (- y 5) + :width 10 + :height 10 + :type :rect}] + (overlaps? shape selrect))) + (defn transform-shape ([shape] (transform-shape nil shape)) ([frame shape] diff --git a/frontend/src/uxbox/main/ui/shapes/group.cljs b/frontend/src/uxbox/main/ui/shapes/group.cljs index eaea47d1a..cdf73601e 100644 --- a/frontend/src/uxbox/main/ui/shapes/group.cljs +++ b/frontend/src/uxbox/main/ui/shapes/group.cljs @@ -13,9 +13,12 @@ [uxbox.util.dom :as dom] [uxbox.util.interop :as itr] [uxbox.main.ui.shapes.common :as common] - [uxbox.main.ui.shapes.attrs :as attrs])) + [uxbox.main.ui.shapes.attrs :as attrs] + [uxbox.main.data.workspace :as dw] + [uxbox.main.store :as st] + [uxbox.main.streams :as ms])) -(defonce ^:dynamic *debug* (atom true)) +(defonce ^:dynamic *debug* (atom false)) (declare translate-to-frame) (declare group-shape) @@ -34,7 +37,9 @@ (fn [event] (dom/stop-propagation event) (dom/prevent-default event) - #_(st/emit! (dw/select-inside-group)))] + (st/emit! (dw/select-inside-group + (:id shape) + @ms/mouse-position)))] [:g.shape {:on-mouse-down on-mouse-down :on-context-menu on-context-menu @@ -73,7 +78,7 @@ [:rect {:x x :y y :fill (if (deref *debug*) "red" "transparent") - :opacity 0.8 + :opacity 0.5 :id (str "group-" id) :width width :height height}])])))