From a13fb1f94f87418570cb305d65bdd6c8baea497d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 4 Mar 2022 13:08:29 +0100 Subject: [PATCH] :bug: Fix multiple edition --- common/src/app/common/pages/common.cljc | 2 - common/src/app/common/spec/radius.cljc | 9 +++- .../app/main/data/workspace/transforms.cljs | 4 +- .../sidebar/options/menus/measures.cljs | 27 ++++++++---- .../sidebar/options/shapes/multiple.cljs | 41 ++++++++++++------- 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/common/src/app/common/pages/common.cljc b/common/src/app/common/pages/common.cljc index 1339a9b6c..1988f2137 100644 --- a/common/src/app/common/pages/common.cljc +++ b/common/src/app/common/pages/common.cljc @@ -247,8 +247,6 @@ :width :height :x :y :rotation - :rx :ry - :r1 :r2 :r3 :r4 :selrect :constraints-h diff --git a/common/src/app/common/spec/radius.cljc b/common/src/app/common/spec/radius.cljc index 8d13019e8..87472899c 100644 --- a/common/src/app/common/spec/radius.cljc +++ b/common/src/app/common/spec/radius.cljc @@ -6,8 +6,9 @@ (ns app.common.spec.radius (:require - [app.common.spec :as us] - [clojure.spec.alpha :as s])) + [app.common.pages.common :refer [editable-attrs]] + [app.common.spec :as us] + [clojure.spec.alpha :as s])) (s/def ::rx ::us/safe-number) (s/def ::ry ::us/safe-number) @@ -30,6 +31,10 @@ ;; shapes that has border radius, and so it hasn't :rx nor :r1. ;; In this case operations must leave shape untouched. +(defn has-radius? + [shape] + ((get editable-attrs (:type shape)) :rx)) + (defn radius-mode [shape] (if (:r1 shape) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 330c32513..45608c7f5 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -12,6 +12,7 @@ [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] [app.common.math :as mth] + [app.common.pages.common :as cpc] [app.common.pages.helpers :as cph] [app.common.spec :as us] [app.main.data.workspace.changes :as dch] @@ -145,7 +146,8 @@ shapes (->> shapes (remove #(get % :blocked false)) (mapcat #(cph/get-children objects (:id %))) - (concat shapes)) + (concat shapes) + (filter #((cpc/editable-attrs (:type %)) :rotation))) update-shape (fn [modifiers shape] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs index a7f40f5fb..5b7a59747 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs @@ -34,7 +34,7 @@ (def ^:private type->options {:bool #{:size :position :rotation} :circle #{:size :position :rotation} - :frame #{:size :position :rotation :radius :presets} + :frame #{:presets :size :position :radius} :group #{:size :position :rotation} :image #{:size :position :rotation :radius} :path #{:size :position :rotation} @@ -141,26 +141,36 @@ (fn [value] (st/emit! (udw/increase-rotation ids value)))) + change-radius + (mf/use-callback + (mf/deps ids-with-children) + (fn [update-fn] + (dch/update-shapes ids-with-children + (fn [shape] + (if (ctr/has-radius? shape) + (update-fn shape) + shape))))) + on-switch-to-radius-1 (mf/use-callback (mf/deps ids) (fn [_value] (if all-equal? - (st/emit! (dch/update-shapes ids-with-children ctr/switch-to-radius-1)) + (st/emit! (change-radius ctr/switch-to-radius-1)) (reset! radius-multi? true)))) on-switch-to-radius-4 (mf/use-callback (mf/deps ids) (fn [_value] - (st/emit! (dch/update-shapes ids-with-children ctr/switch-to-radius-4)) + (st/emit! (change-radius ctr/switch-to-radius-4)) (reset! radius-multi? false))) on-radius-1-change (mf/use-callback (mf/deps ids) (fn [value] - (st/emit! (dch/update-shapes ids-with-children #(ctr/set-radius-1 % value))))) + (st/emit! (change-radius #(ctr/set-radius-1 % value))))) on-radius-multi-change (mf/use-callback @@ -168,16 +178,15 @@ (fn [event] (let [value (-> event dom/get-target dom/get-value d/parse-integer)] (when (some? value) - (st/emit! (dch/update-shapes ids-with-children ctr/switch-to-radius-1) - (dch/update-shapes ids-with-children #(ctr/set-radius-1 % value))) + (st/emit! (change-radius ctr/switch-to-radius-1) + (change-radius #(ctr/set-radius-1 % value))) (reset! radius-multi? false))))) on-radius-4-change (mf/use-callback (mf/deps ids) (fn [value attr] - (st/emit! (dch/update-shapes ids-with-children #(ctr/set-radius-4 % attr value))))) - + (st/emit! (change-radius #(ctr/set-radius-4 % attr value))))) on-width-change #(on-size-change % :width) on-height-change #(on-size-change % :height) @@ -273,7 +282,7 @@ :precision 2}]]]) ;; ROTATION - (when (and (not= type :frame) (options :rotation)) + (when (options :rotation) [:div.row-flex [:span.element-set-subtitle (tr "workspace.options.rotation")] [:div.input-element.degrees {:title (tr "workspace.options.rotation")} diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs index 69fa38320..a7a913a8b 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs @@ -27,7 +27,7 @@ ;; - children: read it from all the children, and then merging it. ;; - ignore: do not read this attribute from this shape. ;; - text: read it from all the content nodes, and then merging it. -(def type->props +(def type->read-mode {:frame {:measure :shape :layer :shape @@ -118,7 +118,7 @@ :stroke :shape :text :ignore}}) -(def props->attrs +(def group->attrs {:measure measure-attrs :layer layer-attrs :constraint constraint-attrs @@ -157,36 +157,47 @@ (when v (select-keys v blur-keys))) (defn get-attrs* - "Given a `type` of options that we want to extract and the shapes to extract them from + "Given a group of attributes that we want to extract and the shapes to extract them from returns a list of tuples [id, values] with the extracted properties for the shapes that applies (some of them ignore some attributes)" - [shapes objects attr-type] - (let [attrs (props->attrs attr-type) + [shapes objects attr-group] + (let [attrs (group->attrs attr-group) + merge-attrs (fn [v1 v2] (cond - (= attr-type :shadow) (attrs/get-attrs-multi [v1 v2] attrs shadow-eq shadow-sel) - (= attr-type :blur) (attrs/get-attrs-multi [v1 v2] attrs blur-eq blur-sel) - :else (attrs/get-attrs-multi [v1 v2] attrs))) + (= attr-group :shadow) (attrs/get-attrs-multi [v1 v2] attrs shadow-eq shadow-sel) + (= attr-group :blur) (attrs/get-attrs-multi [v1 v2] attrs blur-eq blur-sel) + :else (attrs/get-attrs-multi [v1 v2] attrs))) extract-attrs (fn [[ids values] {:keys [id type content] :as shape}] - (let [props (get-in type->props [type attr-type])] - (case props + (let [read-mode (get-in type->read-mode [type attr-group]) + editable-attrs (filter (get cpc/editable-attrs (:type shape)) attrs)] + (case read-mode :ignore [ids values] - :shape (let [editable-attrs (filter (get cpc/editable-attrs (:type shape)) attrs)] + + :shape (let [;; Get the editable attrs from the shape, ensuring that all attributes + ;; are present, with value nil if they are not present in the shape. + shape-values (merge + (into {} (map #(hash-map % nil) editable-attrs)) + (select-keys shape editable-attrs))] [(conj ids id) - (merge-attrs values (select-keys shape editable-attrs))]) + (merge-attrs values shape-values)]) + :text [(conj ids id) (-> values (merge-attrs (select-keys shape attrs)) (merge-attrs (merge - (select-keys txt/default-text-attrs attrs) - (attrs/get-attrs-multi (txt/node-seq content) attrs))))] + (select-keys txt/default-text-attrs attrs) + (attrs/get-attrs-multi (txt/node-seq content) attrs))))] + :children (let [children (->> (:shapes shape []) (map #(get objects %))) - [new-ids new-values] (get-attrs* children objects attr-type)] + [new-ids new-values] (get-attrs* children objects attr-group)] [(d/concat-vec ids new-ids) (merge-attrs values new-values)]) + [])))] + (reduce extract-attrs [[] []] shapes))) (def get-attrs (memoize get-attrs*))