From 20e7afeee5a965d88211d36f6c7d4dfc12cae428 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 4 Jan 2017 22:10:12 +0100 Subject: [PATCH] Add specific selection handler for text edition. --- frontend/src/uxbox/main/ui/shapes/common.cljs | 4 +-- .../src/uxbox/main/ui/shapes/selection.cljs | 31 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/frontend/src/uxbox/main/ui/shapes/common.cljs b/frontend/src/uxbox/main/ui/shapes/common.cljs index b807c89b9..467e4d7d1 100644 --- a/frontend/src/uxbox/main/ui/shapes/common.cljs +++ b/frontend/src/uxbox/main/ui/shapes/common.cljs @@ -5,8 +5,7 @@ ;; Copyright (c) 2016 Andrey Antukh (ns uxbox.main.ui.shapes.common - (:require [sablono.core :refer-macros [html]] - [lentes.core :as l] + (:require [lentes.core :as l] [beicon.core :as rx] [potok.core :as ptk] [uxbox.store :as st] @@ -20,7 +19,6 @@ ;; --- Refs -;; (defonce edition-ref (atom nil)) (def edition-ref (-> (l/in [:workspace :edition]) (l/derive st/state))) diff --git a/frontend/src/uxbox/main/ui/shapes/selection.cljs b/frontend/src/uxbox/main/ui/shapes/selection.cljs index cd721a6b5..68190003b 100644 --- a/frontend/src/uxbox/main/ui/shapes/selection.cljs +++ b/frontend/src/uxbox/main/ui/shapes/selection.cljs @@ -41,7 +41,7 @@ (-> (l/lens focus-selected-shapes) (l/derive st/state))) -(def edition-ref scommon/edition-ref) +(def ^:private edition-ref scommon/edition-ref) ;; --- Resize Implementation @@ -362,22 +362,39 @@ shape (geom/selection-rect shape)] (controls shape zoom on-click))) +(mx/defc text-edition-selection-handlers + {:mixins [mx/static]} + [{:keys [id] :as shape} zoom] + (let [{:keys [x1 y1 width height] :as shape} (geom/selection-rect shape)] + [:g.controls + [:rect.main {:x x1 :y y1 + :width width + :height height + ;; :stroke-dasharray (str (/ 5.0 zoom) "," (/ 5 zoom)) + :style {:stroke "#333" + :stroke-width "0.5" + :stroke-opacity "0.5" + :fill "transparent"}}]])) + (mx/defc selection-handlers {:mixins [mx/reactive mx/static]} [] (let [shapes (mx/react selected-shapes-ref) - edition (mx/react scommon/edition-ref) + edition? (mx/react edition-ref) zoom (mx/react wb/zoom-ref) - shapes-num (count shapes) - shape (first shapes)] + num (count shapes) + {:keys [type] :as shape} (first shapes)] (cond - (zero? shapes-num) + (zero? num) nil - (> shapes-num 1) + (> num 1) (multiple-selection-handlers shapes zoom) - (= :path (:type shape)) + (and (= type :text) edition?) + (text-edition-selection-handlers shape zoom) + + (= type :path) (if (= @edition-ref (:id shape)) (path-edition-selection-handlers shape zoom) (single-selection-handlers shape zoom))