diff --git a/src/uxbox/ui/shapes/icon.cljs b/src/uxbox/ui/shapes/icon.cljs index e71975ab3..ba6f21f4f 100644 --- a/src/uxbox/ui/shapes/icon.cljs +++ b/src/uxbox/ui/shapes/icon.cljs @@ -79,7 +79,7 @@ :on-mouse-down on-mouse-down :on-mouse-up on-mouse-up} (uusc/render-shape shape #(uusc/shape %)) - (when selected? + (when (and selected? (= (count selected) 1)) (handlers shape))]))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/uxbox/ui/workspace/canvas.cljs b/src/uxbox/ui/workspace/canvas.cljs index 25f318849..c020298a5 100644 --- a/src/uxbox/ui/workspace/canvas.cljs +++ b/src/uxbox/ui/workspace/canvas.cljs @@ -56,7 +56,7 @@ (background) (grid 1) [:svg.page-layout {} - #_(shapes-selection shapes-selected) + (shapes-selection) [:g.main {} (for [item (:shapes page)] (-> (uus/shape item) diff --git a/src/uxbox/ui/workspace/canvas/selection.cljs b/src/uxbox/ui/workspace/canvas/selection.cljs index 7ee8c1d7b..6e046bc00 100644 --- a/src/uxbox/ui/workspace/canvas/selection.cljs +++ b/src/uxbox/ui/workspace/canvas/selection.cljs @@ -1,45 +1,34 @@ (ns uxbox.ui.workspace.canvas.selection (:require [sablono.core :as html :refer-macros [html]] [rum.core :as rum] - [beicon.core :as rx] [cats.labs.lens :as l] - [uxbox.rstore :as rs] - [uxbox.state :as st] - [uxbox.shapes :as sh] + [uxbox.state :as ust] + [uxbox.shapes :as ush] + [uxbox.util.lens :as ul] [uxbox.ui.workspace.base :as wb] - [uxbox.ui.mixins :as mx] - [uxbox.util.dom :as dom])) + [uxbox.ui.mixins :as mx])) -(def ^:private selection-circle-style - {:fillOpacity "0.5" - :strokeWidth "1px" - :vectorEffect "non-scaling-stroke"}) - -(def ^:private default-selection-props - {:r 5 :style selection-circle-style - :fill "#333" - :stroke "#333"}) +(def ^:const selected-shapes-l + (letfn [(getter [state] + (let [selected (get-in state [:workspace :selected])] + (mapv #(get-in state [:shapes-by-id %]) selected)))] + (as-> (ul/getter getter) $ + (l/focus-atom $ ust/state)))) (defn shapes-selection-render - [own shapes] - (when (seq shapes) - (let [{:keys [width height x y]} (sh/outer-rect shapes)] - (html - [:g.controls - [:rect {:x x :y y :width width :height height :stroke-dasharray "5,5" - :style {:stroke "#333" :fill "transparent" - :stroke-opacity "1"}}] - [:circle.top-left (merge default-selection-props - {:cx x :cy y})] - [:circle.top-right (merge default-selection-props - {:cx (+ x width) :cy y})] - [:circle.bottom-left (merge default-selection-props - {:cx x :cy (+ y height)})] - [:circle.bottom-right (merge default-selection-props - {:cx (+ x width) :cy (+ y height)})]])))) + [own] + (let [shapes (rum/react selected-shapes-l)] + (when (> (count shapes) 1) + (let [{:keys [width height x y]} (ush/outer-rect shapes)] + (html + [:g.controls + [:rect {:x x :y y :width width :height height + :stroke-dasharray "5,5" + :style {:stroke "#333" :fill "transparent" + :stroke-opacity "1"}}]]))))) -(def ^:static shapes-selection +(def ^:const shapes-selection (mx/component {:render shapes-selection-render :name "shapes-selection" - :mixins [mx/static]})) + :mixins [rum/reactive mx/static]}))