From 62eb224ac0fe0ef7f9a3788349afb909eb3f5944 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 24 Aug 2016 16:45:11 +0300 Subject: [PATCH] Fix group shape rerender when a transformation is applied to its children shapes. --- src/uxbox/main/ui/shapes.cljs | 24 +--------- src/uxbox/main/ui/shapes/group.cljs | 72 +++++++++++++---------------- src/uxbox/main/ui/shapes/rect.cljs | 2 +- 3 files changed, 35 insertions(+), 63 deletions(-) diff --git a/src/uxbox/main/ui/shapes.cljs b/src/uxbox/main/ui/shapes.cljs index 2d95c81833..3c72a50c90 100644 --- a/src/uxbox/main/ui/shapes.cljs +++ b/src/uxbox/main/ui/shapes.cljs @@ -5,27 +5,7 @@ ;; Copyright (c) 2016 Andrey Antukh (ns uxbox.main.ui.shapes - (:require [lentes.core :as l] - [rum.core :as rum] - [uxbox.main.state :as st] - [uxbox.util.mixins :as mx] - [uxbox.main.ui.shapes.group :as group])) + (:require [uxbox.main.ui.shapes.group :as group])) (def render-component group/render-component) - -(defn- focus-shape - [id] - (-> (l/in [:shapes-by-id id]) - (l/derive st/state))) - -(defn- shape-render - [own id] - (let [shape (mx/react (focus-shape id))] - (when-not (:hidden shape) - (render-component shape)))) - -(def shape - (mx/component - {:render shape-render - :name "shape" - :mixins [mx/static mx/reactive]})) +(def shape group/component-container) diff --git a/src/uxbox/main/ui/shapes/group.cljs b/src/uxbox/main/ui/shapes/group.cljs index 3ac60c0964..76a90856b9 100644 --- a/src/uxbox/main/ui/shapes/group.cljs +++ b/src/uxbox/main/ui/shapes/group.cljs @@ -5,11 +5,9 @@ ;; Copyright (c) 2016 Andrey Antukh (ns uxbox.main.ui.shapes.group - (:require [sablono.core :refer-macros [html]] - [rum.core :as rum] - [lentes.core :as l] + (:require [lentes.core :as l] [uxbox.main.state :as st] - [uxbox.util.mixins :as mx] + [uxbox.util.mixins :as mx :include-macros true] [uxbox.main.ui.shapes.common :as common] [uxbox.main.ui.shapes.attrs :as attrs] [uxbox.main.ui.shapes.icon :as icon] @@ -23,10 +21,14 @@ (declare group-component) +(defn- focus-shape + [id] + (-> (l/in [:shapes-by-id id]) + (l/derive st/state))) + (defn render-component - [{:keys [type] :as shape}] - ;; (println "render-component" (pr-str shape)) - (case type + [shape] + (case (:type shape) :group (group-component shape) :text (text/text-component shape) :icon (icon/icon-component shape) @@ -34,50 +36,40 @@ :path (path/path-component shape) :circle (circle/circle-component shape))) +(mx/defc component-container + {:mixins [mx/reactive mx/static]} + [id] + (let [shape (mx/react (focus-shape id))] + (when-not (:hidden shape) + (render-component shape)))) + ;; --- Group Component (declare group-shape) -(defn- group-component-render - [own shape] - (let [{:keys [id x y width height group]} shape - selected (mx/react common/selected-ref) +(mx/defc group-component + {:mixins [mx/static mx/reactive]} + [{:keys [id x y width height group] :as shape}] + (let [selected (mx/react common/selected-ref) selected? (contains? selected id) on-mouse-down #(common/on-mouse-down % shape selected)] - (html - [:g.shape.group-shape - {:class (when selected? "selected") - :on-mouse-down on-mouse-down} - (group-shape shape render-component)]))) - -(def group-component - (mx/component - {:render group-component-render - :name "group-component" - :mixins [mx/static mx/reactive]})) + [:g.shape.group-shape + {:class (when selected? "selected") + :on-mouse-down on-mouse-down} + (group-shape shape component-container)])) ;; --- Group Shape -(defn- group-shape-render - [own {:keys [items id dx dy rotation] :as shape} factory] +(mx/defc group-shape + {:mixins [mx/static mx/reactive]} + [{:keys [items id dx dy rotation] :as shape} factory] (let [key (str "shape-" id) rfm (geom/transformation-matrix shape) attrs (merge {:id key :key key :transform (str rfm)} (attrs/extract-style-attrs shape) - (attrs/make-debug-attrs shape)) - shapes-by-id (get @st/state :shapes-by-id) - xf (comp - (map #(get shapes-by-id %)) - (remove :hidden))] - (html - [:g attrs - (for [item (reverse (into [] xf items)) - :let [key (str (:id item))]] - (-> (factory item) - (rum/with-key key)))]))) + (attrs/make-debug-attrs shape))] + [:g attrs + (for [item items :let [key (str item)]] + (-> (factory item) + (mx/with-key key)))])) -(def group-shape - (mx/component - {:render group-shape-render - :name "group-shape" - :mixins [mx/static]})) diff --git a/src/uxbox/main/ui/shapes/rect.cljs b/src/uxbox/main/ui/shapes/rect.cljs index d7ff2044cf..d51803388f 100644 --- a/src/uxbox/main/ui/shapes/rect.cljs +++ b/src/uxbox/main/ui/shapes/rect.cljs @@ -37,7 +37,7 @@ ;; --- Rect Shape (mx/defc rect-shape - [{:keys [id x1 y1 x2 y2] :as shape}] + [{:keys [id x1 y1] :as shape}] (let [key (str "shape-" id) rfm (geom/transformation-matrix shape) size (geom/size shape)