From ff5ec11bacfcc5f628cde22f9caaa9bb28a98cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 11 Jun 2020 14:54:52 +0200 Subject: [PATCH] :bug: Fix two runtime errors when creating shapes from library --- common/uxbox/common/geom/shapes.cljc | 7 ++++--- common/uxbox/common/pages.cljc | 4 ++-- frontend/src/uxbox/main/data/workspace.cljs | 3 --- .../main/ui/workspace/sidebar/libraries.cljs | 19 ++++++++++++------- .../workspace/sidebar/options/measures.cljs | 2 ++ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/common/uxbox/common/geom/shapes.cljc b/common/uxbox/common/geom/shapes.cljc index 8f63639af..fb783daca 100644 --- a/common/uxbox/common/geom/shapes.cljc +++ b/common/uxbox/common/geom/shapes.cljc @@ -194,9 +194,10 @@ (us/assert number? height) (-> shape (assoc :width width :height height) - (update :selrect (fn [shape] - (assoc :x2 (+ (:x1 shape) width) - :y2 (+ (:y1 shape) height)))))) + (update :selrect (fn [selrect] + (assoc selrect + :x2 (+ (:x1 selrect) width) + :y2 (+ (:y1 selrect) height)))))) ;; --- Setup (Initialize) diff --git a/common/uxbox/common/pages.cljc b/common/uxbox/common/pages.cljc index 593a0ca67..5d3b99802 100644 --- a/common/uxbox/common/pages.cljc +++ b/common/uxbox/common/pages.cljc @@ -377,10 +377,10 @@ :height 1 :selrect {:x 0 :x1 0 - :x2 0 + :x2 1 :y 0 :y1 0 - :y2 0 + :y2 1 :width 1 :height 1} :points [] diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index c90cbf317..0e12717ce 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -542,9 +542,6 @@ (rx/of (add-shape shape)))))) - - - ;; --- Update Shape Attrs (defn update-shape diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/libraries.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/libraries.cljs index fd46171f3..8a410d504 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/libraries.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/libraries.cljs @@ -13,6 +13,9 @@ [cuerdas.core :as str] [rumext.alpha :as mf] [uxbox.common.data :as d] + [uxbox.common.pages :as cp] + [uxbox.common.geom.shapes :as geom] + [uxbox.common.geom.point :as gpt] [uxbox.main.ui.icons :as i] [uxbox.main.data.workspace :as dw] [uxbox.main.refs :as refs] @@ -50,17 +53,19 @@ (defmulti shape-from-item (fn [type _] type)) (defmethod shape-from-item :icons [_ item] - (-> item - (assoc :type :icon) - (assoc :width (-> item :metadata :width)) - (assoc :height (-> item :metadata :height)))) + (-> (cp/make-minimal-shape :icon) + (merge item) + (geom/resize (-> item :metadata :width) (-> item :metadata :height)) + (geom/absolute-move (gpt/point 0 0)))) (defmethod shape-from-item :images [_ item] (let [metadata (select-keys item [:width :height :thumb-width :thumb-height :thumb-uri :uri])] - (-> item - (assoc :type :image) - (assoc :metadata metadata)))) + (-> (cp/make-minimal-shape :image) + (merge item) + (assoc :metadata metadata) + (geom/resize (-> item :width) (-> item :height)) + (geom/absolute-move (gpt/point 0 0))))) ;; --- Components diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs index d28b3c302..10605ec25 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs @@ -126,6 +126,7 @@ :on-change on-pos-y-change :value (-> shape :selrect :y (math/precision 2))}]]]) + ;; ROTATION (when (options :rotation) [:div.row-flex [:span.element-set-subtitle (t locale "workspace.options.rotation")] @@ -152,6 +153,7 @@ (d/coalesce 0) (math/precision 2)))}]]) + ;; RADIUS (when (options :radius) [:div.row-flex [:span.element-set-subtitle (t locale "workspace.options.radius")]