From c86b6b7b8f9ea2e66febfea0c96f25d5c88a788a Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 24 Jan 2020 12:33:49 +0100 Subject: [PATCH] :bug: Fix element option position update on all shape types. --- frontend/src/uxbox/main/data/workspace.cljs | 12 +- frontend/src/uxbox/main/geom.cljs | 10 +- .../ui/workspace/sidebar/options/canvas.cljs | 5 +- .../ui/workspace/sidebar/options/circle.cljs | 5 +- .../workspace/sidebar/options/measures.cljs | 119 ------------------ .../ui/workspace/sidebar/options/rect.cljs | 5 +- .../ui/workspace/sidebar/options/text.cljs | 5 +- 7 files changed, 22 insertions(+), 139 deletions(-) delete mode 100644 frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index 8a46f1985..b908720a4 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -1083,14 +1083,20 @@ ;; --- Update Shape Position +(s/def ::x number?) +(s/def ::y number?) +(s/def ::position + (s/keys :opt-un [::x ::y])) + (defn update-position - [id point] + [id position] (us/assert ::us/uuid id) - (us/assert gpt/point? point) + (us/assert ::position position) (ptk/reify ::update-position ptk/UpdateEvent (update [_ state] - (update-in state [:workspace-data :shapes-by-id id] geom/absolute-move point)))) + (update-in state [:workspace-data :shapes-by-id id] + geom/absolute-move position)))) ;; --- Path Modifications diff --git a/frontend/src/uxbox/main/geom.cljs b/frontend/src/uxbox/main/geom.cljs index ce2a6ca69..99f213c1d 100644 --- a/frontend/src/uxbox/main/geom.cljs +++ b/frontend/src/uxbox/main/geom.cljs @@ -62,12 +62,12 @@ (defn absolute-move "Move the shape to the exactly specified position." - [shape point] + [shape position] (case (:type shape) - :icon (absolute-move-rect shape point) - :image (absolute-move-rect shape point) - :rect (absolute-move-rect shape point) - :circle (absolute-move-circle shape point))) + :icon (absolute-move-rect shape position) + :image (absolute-move-rect shape position) + :rect (absolute-move-rect shape position) + :circle (absolute-move-circle shape position))) (defn- absolute-move-rect "A specialized function for absolute moviment diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/canvas.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/canvas.cljs index cc3629e2a..15d6d5cb6 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/canvas.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/canvas.cljs @@ -38,9 +38,8 @@ (fn [event attr] (let [value (-> (dom/get-target event) (dom/get-value) - (d/parse-integer)) - point (gpt/point {attr value})] - (st/emit! (udw/update-position (:id shape) point)))) + (d/parse-integer))] + (st/emit! (udw/update-position (:id shape) {attr value})))) on-width-change #(on-size-change % :width) on-height-change #(on-size-change % :height) diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/circle.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/circle.cljs index 782eef4f2..ecebc54e3 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/circle.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/circle.cljs @@ -40,9 +40,8 @@ (fn [event attr] (let [value (-> (dom/get-target event) (dom/get-value) - (d/parse-integer)) - point (gpt/point {attr value})] - (st/emit! (udw/update-position (:id shape) point)))) + (d/parse-integer))] + (st/emit! (udw/update-position (:id shape) {attr value})))) on-pos-cx-change #(on-position-change % :x) on-pos-cy-change #(on-position-change % :y) diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs deleted file mode 100644 index 1bc01b38f..000000000 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs +++ /dev/null @@ -1,119 +0,0 @@ -;; 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) 2015-2016 Juan de la Cruz -;; Copyright (c) 2015-2019 Andrey Antukh - -(ns uxbox.main.ui.workspace.sidebar.options.measures - (:require - [rumext.alpha :as mf] - [uxbox.common.data :as d] - [uxbox.builtins.icons :as i] - [uxbox.main.data.workspace :as udw] - [uxbox.main.geom :as geom] - [uxbox.main.store :as st] - [uxbox.util.dom :as dom] - [uxbox.util.geom.point :as gpt] - [uxbox.util.i18n :refer [tr]] - [uxbox.util.math :as math])) - -(mf/defc size-options - [{:keys [shape] :as props}] - (let [on-size-change - (fn [event attr] - (let [value (-> (dom/get-target event) - (dom/get-value) - (d/parse-integer 0))] - (st/emit! (udw/update-dimensions (:id shape) {attr value})))) - - on-proportion-lock-change - (fn [event] - (st/emit! (udw/toggle-shape-proportion-lock (:id shape)))) - - on-size-rx-change #(on-size-change % :rx) - on-size-ry-change #(on-size-change % :ry) - ] - [:* - [:span (tr "workspace.options.size")] - [:div.row-flex - [:div.input-element.pixels - [:input.input-text {:type "number" - :min "0" - :on-change on-size-rx-change - :value (-> (:rx shape) - (math/precision 2) - (d/coalesce-str "0"))}]] - [:div.lock-size {:class (when (:proportion-lock shape) "selected") - :on-click on-proportion-lock-change} - (if (:proportion-lock shape) - i/lock - i/unlock)] - - [:div.input-element.pixels - [:input.input-text {:type "number" - :min "0" - :on-change on-size-ry-change - :value (-> (:ry shape) - (math/precision 2) - (d/coalesce-str "0"))}]]]])) - -(mf/defc position-options - [{:keys [shape] :as props}] - (let [on-position-change - (fn [event attr] - (let [value (-> (dom/get-target event) - (dom/get-value) - (d/parse-integer)) - point (gpt/point {attr value})] - (st/emit! (udw/update-position (:id shape) point)))) - - on-pos-cx-change #(on-position-change % :x) - on-pos-cy-change #(on-position-change % :y)] - [:* - [:span (tr "workspace.options.position")] - [:div.row-flex - [:div.input-element.pixels - [:input.input-text {:type "number" - :on-change on-pos-cx-change - :value (-> (:cx shape) - (math/precision 2) - (d/coalesce-str "0"))}]] - [:div.input-element.pixels - [:input.input-text {:type "number" - :on-change on-pos-cy-change - :value (-> (:cy shape) - (math/precision 2) - (d/coalesce-str "0"))}]]]])) - -(mf/defc rotation-and-radius-options - [{:keys [shape] :as props}] - [:* - [:span (tr "workspace.options.rotation-radius")] - [:div.row-flex - [:div.input-element.degrees - [:input.input-text {:placeholder "" - :type "number" - :min 0 - :max 360 - ;; :on-change on-rotation-change - :value (-> (:rotation shape 0) - (math/precision 2) - (d/coalesce-str "0"))}]] - - [:div.input-element.pixels - [:input.input-text - {:type "number" - ;; :on-change on-radius-change - :value (-> (:rx shape) - (math/precision 2) - (d/coalesce-str "0"))}]]]]) - -(mf/defc measures-menu - [{:keys [shape] :as props}] - [:div.element-set - [:div.element-set-title (tr "workspace.options.measures")] - [:div.element-set-content - [:& size-options {:shape shape}] - [:& position-options {:shape shape}] - [:& rotation-and-radius-options {:shape shape}]]]) diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/rect.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/rect.cljs index 81f87c5dc..135d9d20e 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/rect.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/rect.cljs @@ -40,9 +40,8 @@ (fn [event attr] (let [value (-> (dom/get-target event) (dom/get-value) - (d/parse-integer)) - point (gpt/point {attr value})] - (st/emit! (udw/update-position (:id shape) point)))) + (d/parse-integer))] + (st/emit! (udw/update-position (:id shape) {attr value})))) on-rotation-change (fn [event] diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/text.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/text.cljs index 8f4c657c2..0853a6e44 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/text.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/text.cljs @@ -43,9 +43,8 @@ (fn [event attr] (let [value (-> (dom/get-target event) (dom/get-value) - (d/parse-integer)) - point (gpt/point {attr value})] - (st/emit! (udw/update-position (:id shape) point)))) + (d/parse-integer))] + (st/emit! (udw/update-position (:id shape) {attr value})))) on-rotation-change (fn [event]