From 2ab803cebcaa641946670481f7bc0935a42ecea0 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 10 Apr 2020 09:31:17 +0200 Subject: [PATCH] :bug: Fixes problem with dashboard preview --- frontend/src/uxbox/main/exports.cljs | 71 ++++++++++--------- frontend/src/uxbox/main/ui/shapes/frame.cljs | 5 +- .../src/uxbox/main/ui/viewer/thumbnails.cljs | 8 +-- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/frontend/src/uxbox/main/exports.cljs b/frontend/src/uxbox/main/exports.cljs index fa6432ba5..278aaed98 100644 --- a/frontend/src/uxbox/main/exports.cljs +++ b/frontend/src/uxbox/main/exports.cljs @@ -39,36 +39,43 @@ {:width (if (mth/nan? width) 100 width) :height (if (mth/nan? height) 100 height)})) -(declare frame-shape) -(declare group-shape) +(declare shape-wrapper) -(mf/defc frame-wrapper - [{:keys [shape objects] :as props}] - (let [childs (mapv #(get objects %) (:shapes shape))] - [:& frame-shape {:shape shape :childs childs}])) +(defn frame-wrapper [objects] + (mf/fnc frame-wrapper + [{:keys [shape] :as props}] + (let [childs (mapv #(get objects %) (:shapes shape)) + shape-wrapper (shape-wrapper objects) + frame-shape (frame/frame-shape shape-wrapper) + shape (geom/transform-shape shape)] + [:& frame-shape {:shape shape :childs childs}]))) -(mf/defc group-wrapper - [{:keys [shape-wrapper shape objects] :as props}] - (let [children (mapv #(get objects %) (:shapes shape))] - [:& group-shape {:shape shape :children children}])) +(defn group-wrapper [objects] + (mf/fnc group-wrapper + [{:keys [shape frame] :as props}] + (let [children (mapv #(get objects %) (:shapes shape)) + shape-wrapper (shape-wrapper objects) + group-shape (group/group-shape shape-wrapper)] + [:& group-shape {:frame frame + :shape shape + :children children}]))) -(mf/defc shape-wrapper - [{:keys [frame shape objects] :as props}] - (when (and shape (not (:hidden shape))) - (let [shape (geom/transform-shape frame shape)] - (case (:type shape) - :curve [:& path/path-shape {:shape shape}] - :text [:& text/text-shape {:shape shape}] - :icon [:& icon/icon-shape {:shape shape}] - :rect [:& rect/rect-shape {:shape shape}] - :path [:& path/path-shape {:shape shape}] - :image [:& image/image-shape {:shape shape}] - :circle [:& circle/circle-shape {:shape shape}] - :group [:& group-wrapper {:shape shape :objects objects}] - nil)))) - -(def group-shape (group/group-shape shape-wrapper)) -(def frame-shape (frame/frame-shape shape-wrapper)) +(defn shape-wrapper [objects] + (mf/fnc shape-wrapper + [{:keys [frame shape] :as props}] + (when (and shape (not (:hidden shape))) + (let [shape (geom/transform-shape frame shape) + opts #js {:shape shape :frame frame}] + (case (:type shape) + :curve [:> path/path-shape opts] + :text [:> text/text-shape opts] + :icon [:> icon/icon-shape opts] + :rect [:> rect/rect-shape opts] + :path [:> path/path-shape opts] + :image [:> image/image-shape opts] + :circle [:> circle/circle-shape opts] + :group [:> (group-wrapper objects) opts] + nil))))) (mf/defc page-svg [{:keys [data] :as props}] @@ -76,7 +83,9 @@ root (get objects uuid/zero) shapes (->> (:shapes root) (map #(get objects %))) - dim (calculate-dimensions data)] + dim (calculate-dimensions data) + frame-wrapper (frame-wrapper objects) + shape-wrapper (shape-wrapper objects)] [:svg {:view-box (str "0 0 " (:width dim 0) " " (:height dim 0)) :version "1.1" :xmlnsXlink "http://www.w3.org/1999/xlink" @@ -85,9 +94,7 @@ (for [item shapes] (if (= (:type item) :frame) [:& frame-wrapper {:shape item - :key (:id item) - :objects objects}] + :key (:id item)}] [:& shape-wrapper {:shape item - :key (:id item) - :objects objects}]))])) + :key (:id item)}]))])) diff --git a/frontend/src/uxbox/main/ui/shapes/frame.cljs b/frontend/src/uxbox/main/ui/shapes/frame.cljs index 87a4f4336..948ab15ab 100644 --- a/frontend/src/uxbox/main/ui/shapes/frame.cljs +++ b/frontend/src/uxbox/main/ui/shapes/frame.cljs @@ -99,15 +99,14 @@ ;; User may also select the frame with single click in the label :on-click on-double-click} (:name shape)] - [:& frame-shape {:shape shape + [:& frame-shape {:shape (geom/transform-shape shape) :childs childs}]]))))) (defn frame-shape [shape-wrapper] (mf/fnc frame-shape [{:keys [shape childs] :as props}] - (let [shape (geom/transform-shape shape) - {:keys [id x y width height]} shape + (let [{:keys [id x y width height]} shape props (-> (attrs/extract-style-attrs shape) (itr/obj-assign! diff --git a/frontend/src/uxbox/main/ui/viewer/thumbnails.cljs b/frontend/src/uxbox/main/ui/viewer/thumbnails.cljs index 84443cae1..e41401c29 100644 --- a/frontend/src/uxbox/main/ui/viewer/thumbnails.cljs +++ b/frontend/src/uxbox/main/ui/viewer/thumbnails.cljs @@ -87,7 +87,8 @@ width (* (:width frame) zoom) height (* (:height frame) zoom) - vbox (str "0 0 " (:width frame 0) " " (:height frame 0))] + vbox (str "0 0 " (:width frame 0) " " (:height frame 0)) + frame-wrapper (exports/frame-wrapper objects)] [:svg {:view-box vbox :width width @@ -95,9 +96,8 @@ :version "1.1" :xmlnsXlink "http://www.w3.org/1999/xlink" :xmlns "http://www.w3.org/2000/svg"} - [:& exports/frame-wrapper {:shape frame - :objects objects - :view-box vbox}]])) + [:& frame-wrapper {:shape frame + :view-box vbox}]])) (mf/defc thumbnails-summary [{:keys [on-toggle-expand on-close total] :as props}]