From 8e81d796f050ceb6351081afdaee0da25431a510 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 26 Nov 2019 18:32:00 +0100 Subject: [PATCH] :lipstick: Minor cosmetic improvements on shapes related namespaces. --- frontend/src/uxbox/main/ui/shapes.cljs | 34 +++++++------------ frontend/src/uxbox/main/ui/shapes/canvas.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/circle.cljs | 4 +-- frontend/src/uxbox/main/ui/shapes/icon.cljs | 4 +-- frontend/src/uxbox/main/ui/shapes/image.cljs | 4 +-- frontend/src/uxbox/main/ui/shapes/path.cljs | 4 +-- frontend/src/uxbox/main/ui/shapes/rect.cljs | 4 +-- frontend/src/uxbox/main/ui/shapes/text.cljs | 6 ++-- .../src/uxbox/main/ui/workspace/drawarea.cljs | 4 +-- 9 files changed, 29 insertions(+), 37 deletions(-) diff --git a/frontend/src/uxbox/main/ui/shapes.cljs b/frontend/src/uxbox/main/ui/shapes.cljs index 579569f477..b39457bdb0 100644 --- a/frontend/src/uxbox/main/ui/shapes.cljs +++ b/frontend/src/uxbox/main/ui/shapes.cljs @@ -18,29 +18,19 @@ [uxbox.main.ui.shapes.canvas :as canvas] [uxbox.main.ui.shapes.text :as text])) -(defn render-shape - [shape] - (mf/html - (case (:type shape) - :canvas [:& canvas/canvas-component {:shape shape}] - :curve [:& path/path-component {:shape shape}] - :text [:& text/text-component {:shape shape}] - :icon [:& icon/icon-component {:shape shape}] - :rect [:& rect/rect-component {:shape shape}] - :path [:& path/path-component {:shape shape}] - :image [:& image/image-component {:shape shape}] - :circle [:& circle/circle-component {:shape shape}]))) - -(mf/defc render-shape' - {:wrap [mf/wrap-memo]} - [{:keys [shape] :as props}] - (render-shape shape)) - -(mf/defc shape-component +(mf/defc shape-wrapper {:wrap [mf/wrap-memo]} [{:keys [shape] :as props}] (when (and shape (not (:hidden shape))) - [:& render-shape' {:shape shape}])) + (case (:type shape) + :canvas [:& canvas/canvas-wrapper {:shape shape}] + :curve [:& path/path-wrapper {:shape shape}] + :text [:& text/text-wrapper {:shape shape}] + :icon [:& icon/icon-wrapper {:shape shape}] + :rect [:& rect/rect-wrapper {:shape shape}] + :path [:& path/path-wrapper {:shape shape}] + :image [:& image/image-wrapper {:shape shape}] + :circle [:& circle/circle-wrapper {:shape shape}]))) (mf/defc canvas-and-shapes {:wrap [mf/wrap-memo]} @@ -50,8 +40,8 @@ canvas (map #(get shapes-by-id %) (:canvas page []))] [:* (for [item canvas] - [:& shape-component {:shape item :key (:id item)}]) + [:& shape-wrapper {:shape item :key (:id item)}]) (for [item shapes] - [:& shape-component {:shape item :key (:id item)}])])) + [:& shape-wrapper {:shape item :key (:id item)}])])) diff --git a/frontend/src/uxbox/main/ui/shapes/canvas.cljs b/frontend/src/uxbox/main/ui/shapes/canvas.cljs index 9f20c76e24..1f2a37de6d 100644 --- a/frontend/src/uxbox/main/ui/shapes/canvas.cljs +++ b/frontend/src/uxbox/main/ui/shapes/canvas.cljs @@ -24,7 +24,7 @@ (def canvas-default-props {:fill-color "#ffffff"}) -(mf/defc canvas-component +(mf/defc canvas-wrapper [{:keys [shape] :as props}] (let [selected (mf/deref refs/selected-shapes) selected? (contains? selected (:id shape)) diff --git a/frontend/src/uxbox/main/ui/shapes/circle.cljs b/frontend/src/uxbox/main/ui/shapes/circle.cljs index 8d05facc07..947b0b1e81 100644 --- a/frontend/src/uxbox/main/ui/shapes/circle.cljs +++ b/frontend/src/uxbox/main/ui/shapes/circle.cljs @@ -15,11 +15,11 @@ [uxbox.util.geom.matrix :as gmt] [uxbox.util.geom.point :as gpt])) -;; --- Circle Component +;; --- Circle Wrapper (declare circle-shape) -(mf/defc circle-component +(mf/defc circle-wrapper [{:keys [shape] :as props}] (let [selected (mf/deref refs/selected-shapes) selected? (contains? selected (:id shape)) diff --git a/frontend/src/uxbox/main/ui/shapes/icon.cljs b/frontend/src/uxbox/main/ui/shapes/icon.cljs index 0eb8498dc0..e87cd59b79 100644 --- a/frontend/src/uxbox/main/ui/shapes/icon.cljs +++ b/frontend/src/uxbox/main/ui/shapes/icon.cljs @@ -17,11 +17,11 @@ [uxbox.util.geom.point :as gpt])) -;; --- Icon Component +;; --- Icon Wrapper (declare icon-shape) -(mf/defc icon-component +(mf/defc icon-wrapper [{:keys [shape] :as props}] (let [selected (mf/deref refs/selected-shapes) selected? (contains? selected (:id shape)) diff --git a/frontend/src/uxbox/main/ui/shapes/image.cljs b/frontend/src/uxbox/main/ui/shapes/image.cljs index c4d308b00a..04136cd9a4 100644 --- a/frontend/src/uxbox/main/ui/shapes/image.cljs +++ b/frontend/src/uxbox/main/ui/shapes/image.cljs @@ -24,11 +24,11 @@ (-> (l/in [:images id]) (l/derive st/state))) -;; --- Image Component +;; --- Image Wrapper (declare image-shape) -(mf/defc image-component +(mf/defc image-wrapper [{:keys [shape] :as props}] (let [selected (mf/deref refs/selected-shapes) image (mf/deref (image-ref (:image shape))) diff --git a/frontend/src/uxbox/main/ui/shapes/path.cljs b/frontend/src/uxbox/main/ui/shapes/path.cljs index 2889a17424..aa2dac2666 100644 --- a/frontend/src/uxbox/main/ui/shapes/path.cljs +++ b/frontend/src/uxbox/main/ui/shapes/path.cljs @@ -17,11 +17,11 @@ [uxbox.util.data :refer [classnames normalize-props]] [uxbox.util.geom.matrix :as gmt])) -;; --- Path Component +;; --- Path Wrapper (declare path-shape) -(mf/defc path-component +(mf/defc path-wrapper [{:keys [shape] :as props}] (let [selected (mf/deref refs/selected-shapes) selected? (contains? selected (:id shape))] diff --git a/frontend/src/uxbox/main/ui/shapes/rect.cljs b/frontend/src/uxbox/main/ui/shapes/rect.cljs index 8df875ae83..f1f38928ce 100644 --- a/frontend/src/uxbox/main/ui/shapes/rect.cljs +++ b/frontend/src/uxbox/main/ui/shapes/rect.cljs @@ -16,11 +16,11 @@ [uxbox.util.geom.matrix :as gmt] [uxbox.util.geom.point :as gpt])) -;; --- Rect Component +;; --- Rect Wrapper (declare rect-shape) -(mf/defc rect-component +(mf/defc rect-wrapper [{:keys [shape] :as props}] (let [selected (mf/deref refs/selected-shapes) selected? (contains? selected (:id shape)) diff --git a/frontend/src/uxbox/main/ui/shapes/text.cljs b/frontend/src/uxbox/main/ui/shapes/text.cljs index 0e4d7a0866..38de6261b4 100644 --- a/frontend/src/uxbox/main/ui/shapes/text.cljs +++ b/frontend/src/uxbox/main/ui/shapes/text.cljs @@ -23,6 +23,8 @@ [uxbox.util.dom :as dom] [uxbox.util.geom.matrix :as gmt])) +;; TODO: this code need a good refactor + ;; --- Events (defn handle-mouse-down @@ -33,13 +35,13 @@ (dom/stop-propagation event) (common/on-mouse-down event shape selected))) -;; --- Text Component +;; --- Text Wrapper (declare text-shape-html) (declare text-shape-wrapper) (declare text-shape-edit) -(mf/defc text-component +(mf/defc text-wrapper [{:keys [shape] :as props}] (let [{:keys [id x1 y1 content group]} shape selected (mf/deref refs/selected-shapes) diff --git a/frontend/src/uxbox/main/ui/workspace/drawarea.cljs b/frontend/src/uxbox/main/ui/workspace/drawarea.cljs index 5f7cfe62b2..c76d87ae4d 100644 --- a/frontend/src/uxbox/main/ui/workspace/drawarea.cljs +++ b/frontend/src/uxbox/main/ui/workspace/drawarea.cljs @@ -325,7 +325,7 @@ [{:keys [shape zoom]}] (let [{:keys [x1 y1 width height]} (geom/selection-rect shape)] [:g - (shapes/render-shape shape) + [:& shapes/shape-wrapper {:shape shape}] [:rect.main {:x x1 :y y1 :width width :height height @@ -347,7 +347,7 @@ (st/emit! (dw/set-tooltip nil)))] (when-let [{:keys [x y] :as segment} (first (:segments shape))] [:g - (shapes/render-shape shape) + [:& shapes/shape-wrapper {:shape shape}] (when (not= :curve (:type shape)) [:circle.close-bezier {:cx x