From b154bb8ff4b4b8742016df8e660389b5bf3a08f6 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sun, 10 Jul 2016 12:42:49 +0300 Subject: [PATCH] Move viewer app shapes from canvas to dedicated namespace. --- src/uxbox/view/ui/viewer/canvas.cljs | 25 ++------------- src/uxbox/view/ui/viewer/shapes.cljs | 46 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 src/uxbox/view/ui/viewer/shapes.cljs diff --git a/src/uxbox/view/ui/viewer/canvas.cljs b/src/uxbox/view/ui/viewer/canvas.cljs index 21e625db6..6b493eb4e 100644 --- a/src/uxbox/view/ui/viewer/canvas.cljs +++ b/src/uxbox/view/ui/viewer/canvas.cljs @@ -14,12 +14,7 @@ [uxbox.main.state :as st] [uxbox.main.ui.shapes :as uus] [uxbox.main.ui.icons :as i] - [uxbox.main.ui.shapes.rect :refer (rect-shape)] - [uxbox.main.ui.shapes.icon :refer (icon-shape)] - [uxbox.main.ui.shapes.text :refer (text-shape)] - [uxbox.main.ui.shapes.group :refer (group-shape)] - [uxbox.main.ui.shapes.line :refer (line-shape)] - [uxbox.main.ui.shapes.circle :refer (circle-shape)])) + [uxbox.view.ui.viewer.shapes :as shapes])) ;; --- Refs @@ -57,22 +52,6 @@ [:svg.page-layout {:width width :height height} (background) (for [id (reverse (:shapes page))] - (-> (shape id) + (-> (shapes/shape id) (rum/with-key (str id))))]])) -;; --- Shapes - -(mx/defc shape-component - [{:keys [type] :as shape}] - (case type - :group (group-shape shape shape-component) - :text (text-shape shape) - :line (line-shape shape) - :icon (icon-shape shape) - :rect (rect-shape shape) - :circle (circle-shape shape))) - -(mx/defc shape - [sid] - (let [item (get-in @st/state [:shapes-by-id sid])] - (shape-component item))) diff --git a/src/uxbox/view/ui/viewer/shapes.cljs b/src/uxbox/view/ui/viewer/shapes.cljs new file mode 100644 index 000000000..c0781abc7 --- /dev/null +++ b/src/uxbox/view/ui/viewer/shapes.cljs @@ -0,0 +1,46 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) 2016 Andrey Antukh + +(ns uxbox.view.ui.viewer.shapes + (:require [sablono.core :refer-macros [html]] + [lentes.core :as l] + [rum.core :as rum] + [uxbox.util.mixins :as mx :include-macros true] + [uxbox.util.data :refer (parse-int)] + [uxbox.main.state :as st] + [uxbox.main.ui.shapes :as uus] + [uxbox.main.ui.icons :as i] + [uxbox.main.ui.shapes.rect :refer (rect-shape)] + [uxbox.main.ui.shapes.icon :refer (icon-shape)] + [uxbox.main.ui.shapes.text :refer (text-shape)] + [uxbox.main.ui.shapes.group :refer (group-shape)] + [uxbox.main.ui.shapes.line :refer (line-shape)] + [uxbox.main.ui.shapes.circle :refer (circle-shape)])) + +;; --- Interactions Wrapper + +(mx/defc interactions-wrapper + [shape factory] + (let [interactions (:interactions shape)] + [:g (factory shape)])) + +;; --- Shapes + +(mx/defc shape* + [{:keys [type] :as shape}] + (case type + :group (group-shape shape #(interactions-wrapper % shape*)) + :text (text-shape shape) + :line (line-shape shape) + :icon (icon-shape shape) + :rect (rect-shape shape) + :circle (circle-shape shape))) + +(mx/defc shape + [sid] + (let [item (get-in @st/state [:shapes-by-id sid])] + (interactions-wrapper item shape*))) +