From 43b6056c1e84f6f0e325d4f0d6522cf6fb58e419 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 30 Jan 2016 11:34:27 +0200 Subject: [PATCH] Improved naming. --- src/uxbox/data/workspace.cljs | 101 +++++++++++++------ src/uxbox/ui/workspace/options.cljs | 21 ++-- src/uxbox/ui/workspace/toolboxes/layers.cljs | 14 ++- 3 files changed, 89 insertions(+), 47 deletions(-) diff --git a/src/uxbox/data/workspace.cljs b/src/uxbox/data/workspace.cljs index 3a82393f9d..bc4064e713 100644 --- a/src/uxbox/data/workspace.cljs +++ b/src/uxbox/data/workspace.cljs @@ -27,7 +27,7 @@ :lock [v/boolean]}) (def ^:static +shape-update-fill-schema+ - {:fill [sc/color] + {:color [sc/color] :opacity [v/number]}) (def ^:static +shape-update-stroke-schema+ @@ -194,7 +194,18 @@ (let [shape (get-in state [:shapes-by-id sid])] (update-in state [:shapes-by-id sid] sh/-move delta))))) -(defn update-shape-rotation +(defn update-line + [sid props] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (let [shape (get-in state [:shapes-by-id sid]) + props (select-keys props [:x1 :y1 :x2 :y2]) + props' (select-keys shape [:x1 :y1 :x2 :y2])] + (update-in state [:shapes-by-id sid] sh/-initialize + (merge props' props)))))) + +(defn update-rotation [sid rotation] {:pre [(number? rotation) (>= rotation 0) @@ -205,7 +216,7 @@ (update-in state [:shapes-by-id sid] sh/-rotate rotation)))) -(defn update-shape-size +(defn update-size "A helper event just for update the position of the shape using the width and heigt attrs instread final point of coordinates. @@ -220,7 +231,7 @@ (let [size [width height]] (update-in state [:shapes-by-id sid] sh/-resize' size))))) -(defn update-shape-position +(defn update-position "Update the start position coordenate of the shape." [sid {:keys [x y] :as opts}] (sc/validate! +shape-update-position-schema+ opts) @@ -229,31 +240,20 @@ (-apply-update [_ state] (update-in state [:shapes-by-id sid] sh/-move' [x y])))) -(defn update-line - [sid props] - (reify - rs/UpdateEvent - (-apply-update [_ state] - (let [shape (get-in state [:shapes-by-id sid]) - props (select-keys props [:x1 :y1 :x2 :y2]) - props' (select-keys shape [:x1 :y1 :x2 :y2])] - (update-in state [:shapes-by-id sid] sh/-initialize - (merge props' props)))))) - ;; TODO: rename fill to "color" for consistency. -(defn update-shape-fill - [sid {:keys [fill opacity] :as opts}] +(defn update-fill-attrs + [sid {:keys [color opacity] :as opts}] (sc/validate! +shape-update-fill-schema+ opts) (reify rs/UpdateEvent (-apply-update [_ state] (update-in state [:shapes-by-id sid] merge - (when fill {:fill fill}) + (when color {:fill color}) (when opacity {:opacity opacity}))))) -(defn update-shape-stroke +(defn update-stroke-attrs [sid {:keys [color opacity width type] :as opts}] (sc/validate! +shape-update-stroke-schema+ opts) (reify @@ -266,17 +266,35 @@ (when color {:stroke color}) (when opacity {:stroke-opacity opacity}))))) -(defn toggle-shape-visibility +(defn hide-shape [sid] (reify rs/UpdateEvent (-apply-update [_ state] - (let [shape (get-in state [:shapes-by-id sid]) - hidden? (:hidden shape false)] - (if hidden? - (assoc-in state [:shapes-by-id sid] (assoc shape :hidden false)) - (assoc-in state [:shapes-by-id sid] (assoc shape :hidden true))))))) + (assoc-in state [:shapes-by-id sid :hidden] true)) + rs/WatchEvent + (-apply-watch [_ state] + (let [shape (get-in state [:shapes-by-id sid])] + (if-not (= (:type shape) :builtin/group) + (rx/empty) + (rx/from-coll + (map hide-shape (:items shape)))))))) + +(defn show-shape + [sid] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (assoc-in state [:shapes-by-id sid :hidden] false)) + + rs/WatchEvent + (-apply-watch [_ state] + (let [shape (get-in state [:shapes-by-id sid])] + (if-not (= (:type shape) :builtin/group) + (rx/empty) + (rx/from-coll + (map show-shape (:items shape)))))))) (defn block-shape [sid] @@ -308,16 +326,35 @@ (rx/from-coll (map unblock-shape (:items shape)))))))) -(defn toggle-shape-locking +(defn lock-shape [sid] (reify rs/UpdateEvent (-apply-update [_ state] - (let [shape (get-in state [:shapes-by-id sid]) - locked? (:locked shape false)] - (if locked? - (assoc-in state [:shapes-by-id sid] (assoc shape :locked false)) - (assoc-in state [:shapes-by-id sid] (assoc shape :locked true))))))) + (assoc-in state [:shapes-by-id sid :locked] true)) + + rs/WatchEvent + (-apply-watch [_ state] + (let [shape (get-in state [:shapes-by-id sid])] + (if-not (= (:type shape) :builtin/group) + (rx/empty) + (rx/from-coll + (map lock-shape (:items shape)))))))) + +(defn unlock-shape + [sid] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (assoc-in state [:shapes-by-id sid :locked] false)) + + rs/WatchEvent + (-apply-watch [_ state] + (let [shape (get-in state [:shapes-by-id sid])] + (if-not (= (:type shape) :builtin/group) + (rx/empty) + (rx/from-coll + (map unlock-shape (:items shape)))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Events (for selected) @@ -424,5 +461,5 @@ (-apply-watch [_ state] (rx/from-coll (->> (get-in state [:workspace :selected]) - (map #(update-shape-fill % opts))))))) + (map #(update-fill-attrs % opts))))))) diff --git a/src/uxbox/ui/workspace/options.cljs b/src/uxbox/ui/workspace/options.cljs index a4749aae02..1eca7f866e 100644 --- a/src/uxbox/ui/workspace/options.cljs +++ b/src/uxbox/ui/workspace/options.cljs @@ -74,7 +74,7 @@ [menu own shape] (letfn [(change-stroke [value] (let [sid (:id shape)] - (rs/emit! (dw/update-shape-stroke sid value)))) + (rs/emit! (dw/update-stroke-attrs sid value)))) (on-width-change [event] (let [value (dom/event->value event) value (parse-float value 1)] @@ -136,8 +136,7 @@ [menu own shape] (letfn [(change-fill [value] (let [sid (:id shape)] - (-> (dw/update-shape-fill sid value) - (rs/emit!)))) + (rs/emit! (dw/update-fill-attrs sid value)))) (on-color-change [event] (let [value (dom/event->value event)] (change-fill {:fill value}))) @@ -146,7 +145,7 @@ value (parse-float value 1)] (change-fill {:opacity value}))) (on-color-picker-event [{:keys [hex]}] - (change-fill {:fill hex}))] + (change-fill {:color hex}))] (html [:div.element-set {:key (str (:id menu))} [:div.element-set-title (:name menu)] @@ -181,18 +180,18 @@ value (parse-int value 0) sid (:id shape) props {attr value}] - (rs/emit! (dw/update-shape-size sid props)))) + (rs/emit! (dw/update-size sid props)))) (on-rotation-change [event] (let [value (dom/event->value event) value (parse-int value 0) sid (:id shape)] - (rs/emit! (dw/update-shape-rotation sid value)))) + (rs/emit! (dw/update-rotation sid value)))) (on-pos-change [attr event] (let [value (dom/event->value event) value (parse-int value nil) sid (:id shape) props {attr value}] - (rs/emit! (dw/update-shape-position sid props)))) + (rs/emit! (dw/update-position sid props)))) (on-border-change [attr event])] (html [:div.element-set {:key (str (:id menu))} @@ -271,18 +270,18 @@ value (parse-int value 0) sid (:id shape) props {attr value}] - #_(rs/emit! (dw/update-shape-size sid props)))) + #_(rs/emit! (dw/update-size sid props)))) (on-rotation-change [event] (let [value (dom/event->value event) value (parse-int value 0) sid (:id shape)] - #_(rs/emit! (dw/update-shape-rotation sid value)))) + #_(rs/emit! (dw/update-rotation sid value)))) (on-pos-change [attr event] (let [value (dom/event->value event) value (parse-int value nil) sid (:id shape) props {attr value}] - #_(rs/emit! (dw/update-shape-position sid props))))] + #_(rs/emit! (dw/update-position sid props))))] (html [:div.element-set {:key (str (:id menu))} [:div.element-set-title (:name menu)] @@ -346,7 +345,7 @@ (let [value (dom/event->value event) value (parse-int value 0) sid (:id shape)] - (rs/emit! (dw/update-shape-rotation sid value)))) + (rs/emit! (dw/update-rotation sid value)))) (on-pos-change [attr event] (let [value (dom/event->value event) value (parse-int value nil) diff --git a/src/uxbox/ui/workspace/toolboxes/layers.cljs b/src/uxbox/ui/workspace/toolboxes/layers.cljs index 80222b3a35..c50d4dff91 100644 --- a/src/uxbox/ui/workspace/toolboxes/layers.cljs +++ b/src/uxbox/ui/workspace/toolboxes/layers.cljs @@ -53,8 +53,11 @@ (defn- toggle-visibility [selected item event] (dom/stop-propagation event) - (let [id (:id item)] - (rs/emit! (dw/toggle-shape-visibility id)) + (let [id (:id item) + hidden? (:hidden item)] + (if hidden? + (rs/emit! (dw/show-shape id)) + (rs/emit! (dw/hide-shape id))) (when (contains? selected id) (rs/emit! (dw/select-shape id))))) @@ -70,8 +73,11 @@ (defn- toggle-locking [item event] (dom/stop-propagation event) - (let [id (:id item)] - (rs/emit! (dw/toggle-shape-locking id)))) + (let [id (:id item) + locked? (:locked item)] + (if locked? + (rs/emit! (dw/unlock-shape id)) + (rs/emit! (dw/lock-shape id))))) (defn- element-icon [item]