From 0cf5c4ab9be8ec623ae6523b01daac4b7e3dd991 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sun, 28 Feb 2016 11:43:07 +0200 Subject: [PATCH] Split data.workspace shape related events to separated ns. --- src/uxbox/data/shapes.cljs | 272 ++++++++++++++++++++ src/uxbox/data/workspace.cljs | 269 +------------------ src/uxbox/ui/workspace/canvas/draw.cljs | 11 +- src/uxbox/ui/workspace/canvas/movement.cljs | 4 +- src/uxbox/ui/workspace/sidebar/layers.cljs | 47 ++-- src/uxbox/ui/workspace/sidebar/options.cljs | 33 +-- 6 files changed, 330 insertions(+), 306 deletions(-) create mode 100644 src/uxbox/data/shapes.cljs diff --git a/src/uxbox/data/shapes.cljs b/src/uxbox/data/shapes.cljs new file mode 100644 index 0000000000..42c86ca7c0 --- /dev/null +++ b/src/uxbox/data/shapes.cljs @@ -0,0 +1,272 @@ +(ns uxbox.data.shapes + (:require [bouncer.validators :as v] + [beicon.core :as rx] + [uxbox.shapes :as sh] + [uxbox.rstore :as rs] + [uxbox.router :as r] + [uxbox.state :as st] + [uxbox.state.shapes :as stsh] + [uxbox.schema :as sc] + [uxbox.util.time :as time] + [uxbox.xforms :as xf] + [uxbox.shapes :as sh] + [uxbox.util.geom.point :as gpt] + [uxbox.util.data :refer (index-of)])) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Schemas +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def ^:static +shape-schema+ + {:x [sc/integer] + :y [sc/integer] + :width [sc/integer] + :height [sc/integer] + :type [sc/required sc/shape-type]}) + +(def ^:static +shape-size-schema+ + {:width [sc/integer] + :height [sc/integer] + :lock [sc/boolean]}) + +(def ^:static +shape-fill-attrs-schema+ + {:color [sc/color] + :opacity [sc/number]}) + +(def ^:static +shape-stroke-attrs-schema+ + {:color [sc/color] + :width [sc/integer] + :type [sc/keyword] + :opacity [sc/number]}) + +(def ^:static +shape-line-attrs-schema+ + {:x1 [sc/integer] + :y1 [sc/integer] + :x2 [sc/integer] + :y2 [sc/integer]}) + +(def ^:static +shape-radius-attrs-schema+ + {:rx [sc/integer] + :ry [sc/integer]}) + +(def ^:static +shape-position-schema+ + {:x [sc/integer] + :y [sc/integer]}) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Events (explicit) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defn add-shape + "Create and add shape to the current selected page." + [shape] + (sc/validate! +shape-schema+ shape) + (reify + rs/UpdateEvent + (-apply-update [_ state] + (let [page (get-in state [:workspace :page])] + (stsh/assoc-shape-to-page state shape page))))) + +(defn delete-shape + "Remove the shape using its id." + [id] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (let [shape (get-in state [:shapes-by-id id])] + (stsh/dissoc-shape state shape))))) + +(defn move-shape + "Mark a shape selected for drawing in the canvas." + [sid delta] + {:pre [(gpt/point? delta)]} + (reify + rs/UpdateEvent + (-apply-update [_ state] + (let [shape (get-in state [:shapes-by-id sid])] + (update-in state [:shapes-by-id sid] sh/move delta))))) + +(defn update-line-attrs + [sid {:keys [x1 y1 x2 y2] :as opts}] + (sc/validate! +shape-line-attrs-schema+ opts) + (reify + rs/UpdateEvent + (-apply-update [_ state] + (let [shape (get-in state [:shapes-by-id sid]) + props (select-keys opts [: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) + (>= 360 rotation)]} + (reify + rs/UpdateEvent + (-apply-update [_ state] + (update-in state [:shapes-by-id sid] + sh/rotate rotation)))) + +(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. + + WARN: only works with shapes that works + with height and width such are ::rect" + [sid {:keys [width height] :as opts}] + (sc/validate! +shape-size-schema+ opts) + (reify + rs/UpdateEvent + (-apply-update [_ state] + (let [shape (get-in state [:shapes-by-id sid]) + size (merge (sh/size shape) opts)] + (update-in state [:shapes-by-id sid] sh/resize' size))))) + +(defn update-position + "Update the start position coordenate of the shape." + [sid {:keys [x y] :as opts}] + (sc/validate! +shape-position-schema+ opts) + (reify + rs/UpdateEvent + (-apply-update [_ state] + (update-in state [:shapes-by-id sid] sh/move' opts)))) + +(defn update-fill-attrs + [sid {:keys [color opacity] :as opts}] + (sc/validate! +shape-fill-attrs-schema+ opts) + (reify + rs/UpdateEvent + (-apply-update [_ state] + (update-in state [:shapes-by-id sid] + merge + (when color {:fill color}) + (when opacity {:opacity opacity}))))) + +(defn update-stroke-attrs + [sid {:keys [color opacity type width] :as opts}] + (sc/validate! +shape-stroke-attrs-schema+ opts) + (reify + rs/UpdateEvent + (-apply-update [_ state] + (update-in state [:shapes-by-id sid] + merge + (when type {:stroke-type type}) + (when width {:stroke-width width}) + (when color {:stroke color}) + (when opacity {:stroke-opacity opacity}))))) + +(defn update-radius-attrs + [sid {:keys [rx ry] :as opts}] + (sc/validate! +shape-radius-attrs-schema+ opts) + (reify + rs/UpdateEvent + (-apply-update [_ state] + (update-in state [:shapes-by-id sid] + merge + (when rx {:rx rx}) + (when ry {:ry ry}))))) + +(defn hide-shape + [sid] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (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] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (assoc-in state [:shapes-by-id sid :blocked] 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 block-shape (:items shape)))))))) + +(defn unblock-shape + [sid] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (assoc-in state [:shapes-by-id sid :blocked] 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 unblock-shape (:items shape)))))))) + +(defn lock-shape + [sid] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (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)))))))) + +(defn drop-shape + "Event used in drag and drop for transfer shape + from one position to an other." + [sid tid loc] + {:pre [(not (nil? tid)) + (not (nil? sid))]} + (reify + rs/UpdateEvent + (-apply-update [_ state] + (stsh/drop-shape state sid tid loc)))) + diff --git a/src/uxbox/data/workspace.cljs b/src/uxbox/data/workspace.cljs index 982f695f59..f55e4593e9 100644 --- a/src/uxbox/data/workspace.cljs +++ b/src/uxbox/data/workspace.cljs @@ -7,52 +7,13 @@ [uxbox.state :as st] [uxbox.state.shapes :as stsh] [uxbox.schema :as sc] - [uxbox.time :as time] + [uxbox.util.time :as time] [uxbox.xforms :as xf] [uxbox.shapes :as sh] + [uxbox.data.shapes :as uds] [uxbox.util.geom.point :as gpt] [uxbox.util.data :refer (index-of)])) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Schemas -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(def ^:static +shape-schema+ - {:x [sc/integer] - :y [sc/integer] - :width [sc/integer] - :height [sc/integer] - :type [sc/required sc/shape-type]}) - -(def ^:static +shape-size-schema+ - {:width [sc/integer] - :height [sc/integer] - :lock [sc/boolean]}) - -(def ^:static +shape-fill-attrs-schema+ - {:color [sc/color] - :opacity [sc/number]}) - -(def ^:static +shape-stroke-attrs-schema+ - {:color [sc/color] - :width [sc/integer] - :type [sc/keyword] - :opacity [sc/number]}) - -(def ^:static +shape-line-attrs-schema+ - {:x1 [sc/integer] - :y1 [sc/integer] - :x2 [sc/integer] - :y2 [sc/integer]}) - -(def ^:static +shape-radius-attrs-schema+ - {:rx [sc/integer] - :ry [sc/integer]}) - -(def ^:static +shape-position-schema+ - {:x [sc/integer] - :y [sc/integer]}) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Events (explicit) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -125,219 +86,6 @@ (->> (into #{} xf (vals (:shapes-by-id state))) (assoc-in state [:workspace :selected])))))) -(defn add-shape - "Create and add shape to the current selected page." - [shape] - (sc/validate! +shape-schema+ shape) - (reify - rs/UpdateEvent - (-apply-update [_ state] - (let [page (get-in state [:workspace :page])] - (stsh/assoc-shape-to-page state shape page))))) - -(defn delete-shape - "Remove the shape using its id." - [id] - (reify - rs/UpdateEvent - (-apply-update [_ state] - (let [shape (get-in state [:shapes-by-id id])] - (stsh/dissoc-shape state shape))))) - -(defn move-shape - "Mark a shape selected for drawing in the canvas." - [sid delta] - {:pre [(gpt/point? delta)]} - (reify - rs/UpdateEvent - (-apply-update [_ state] - (let [shape (get-in state [:shapes-by-id sid])] - (update-in state [:shapes-by-id sid] sh/move delta))))) - -(defn update-line-attrs - [sid {:keys [x1 y1 x2 y2] :as opts}] - (sc/validate! +shape-line-attrs-schema+ opts) - (reify - rs/UpdateEvent - (-apply-update [_ state] - (let [shape (get-in state [:shapes-by-id sid]) - props (select-keys opts [: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) - (>= 360 rotation)]} - (reify - rs/UpdateEvent - (-apply-update [_ state] - (update-in state [:shapes-by-id sid] - sh/rotate rotation)))) - -(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. - - WARN: only works with shapes that works - with height and width such are ::rect" - [sid {:keys [width height] :as opts}] - (sc/validate! +shape-size-schema+ opts) - (reify - rs/UpdateEvent - (-apply-update [_ state] - (let [shape (get-in state [:shapes-by-id sid]) - size (merge (sh/size shape) opts)] - (update-in state [:shapes-by-id sid] sh/resize' size))))) - -(defn update-position - "Update the start position coordenate of the shape." - [sid {:keys [x y] :as opts}] - (sc/validate! +shape-position-schema+ opts) - (reify - rs/UpdateEvent - (-apply-update [_ state] - (update-in state [:shapes-by-id sid] sh/move' opts)))) - -(defn update-fill-attrs - [sid {:keys [color opacity] :as opts}] - (sc/validate! +shape-fill-attrs-schema+ opts) - (reify - rs/UpdateEvent - (-apply-update [_ state] - (update-in state [:shapes-by-id sid] - merge - (when color {:fill color}) - (when opacity {:opacity opacity}))))) - -(defn update-stroke-attrs - [sid {:keys [color opacity type width] :as opts}] - (sc/validate! +shape-stroke-attrs-schema+ opts) - (reify - rs/UpdateEvent - (-apply-update [_ state] - (update-in state [:shapes-by-id sid] - merge - (when type {:stroke-type type}) - (when width {:stroke-width width}) - (when color {:stroke color}) - (when opacity {:stroke-opacity opacity}))))) - -(defn update-radius-attrs - [sid {:keys [rx ry] :as opts}] - (sc/validate! +shape-radius-attrs-schema+ opts) - (reify - rs/UpdateEvent - (-apply-update [_ state] - (update-in state [:shapes-by-id sid] - merge - (when rx {:rx rx}) - (when ry {:ry ry}))))) - -(defn hide-shape - [sid] - (reify - rs/UpdateEvent - (-apply-update [_ state] - (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] - (reify - rs/UpdateEvent - (-apply-update [_ state] - (assoc-in state [:shapes-by-id sid :blocked] 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 block-shape (:items shape)))))))) - -(defn unblock-shape - [sid] - (reify - rs/UpdateEvent - (-apply-update [_ state] - (assoc-in state [:shapes-by-id sid :blocked] 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 unblock-shape (:items shape)))))))) - -(defn lock-shape - [sid] - (reify - rs/UpdateEvent - (-apply-update [_ state] - (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)))))))) - -(defn drop-shape - "Event used in drag and drop for transfer shape - from one position to an other." - [sid tid loc] - {:pre [(not (nil? tid)) - (not (nil? sid))]} - (reify - rs/UpdateEvent - (-apply-update [_ state] - (stsh/drop-shape state sid tid loc)))) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Events (for selected) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -389,6 +137,7 @@ (update $ :workspace assoc :selected #{})) state)))))) +;; TODO: maybe split in two separate events (defn duplicate-selected [] (reify @@ -405,7 +154,7 @@ (-apply-watch [_ state] (let [selected (get-in state [:workspace :selected])] (rx/from-coll - (into [(deselect-all)] (map #(delete-shape %) selected))))))) + (into [(deselect-all)] (map #(uds/delete-shape %) selected))))))) (defn move-selected "Move a minimal position unit the selected shapes." @@ -422,30 +171,30 @@ :right (gpt/point n 0) :left (gpt/point (- n) 0))] (rx/from-coll - (map #(move-shape % delta) selected))))))) + (map #(uds/move-shape % delta) selected))))))) (defn update-selected-shapes-fill "Update the fill related attributed on selected shapes." [opts] - (sc/validate! +shape-fill-attrs-schema+ opts) + (sc/validate! uds/+shape-fill-attrs-schema+ opts) (reify rs/WatchEvent (-apply-watch [_ state] (rx/from-coll (->> (get-in state [:workspace :selected]) - (map #(update-fill-attrs % opts))))))) + (map #(uds/update-fill-attrs % opts))))))) (defn update-selected-shapes-stroke "Update the fill related attributed on selected shapes." [opts] - (sc/validate! +shape-stroke-attrs-schema+ opts) + (sc/validate! uds/+shape-stroke-attrs-schema+ opts) (reify rs/WatchEvent (-apply-watch [_ state] (rx/from-coll (->> (get-in state [:workspace :selected]) - (map #(update-stroke-attrs % opts))))))) + (map #(uds/update-stroke-attrs % opts))))))) diff --git a/src/uxbox/ui/workspace/canvas/draw.cljs b/src/uxbox/ui/workspace/canvas/draw.cljs index bf88e7c88e..dd84053e6b 100644 --- a/src/uxbox/ui/workspace/canvas/draw.cljs +++ b/src/uxbox/ui/workspace/canvas/draw.cljs @@ -6,7 +6,8 @@ [lentes.core :as l] [uxbox.rstore :as rs] [uxbox.shapes :as ush] - [uxbox.data.workspace :as dw] + [uxbox.data.workspace :as udw] + [uxbox.data.shapes :as uds] [uxbox.ui.core :as uuc] [uxbox.ui.shapes.core :as uusc] [uxbox.ui.workspace.base :as wb] @@ -65,8 +66,8 @@ (let [shape @+drawing-shape+ shpos @+drawing-position+ shape (ush/resize shape shpos)] - (rs/emit! (dw/add-shape shape) - (dw/select-for-drawing nil)) + (rs/emit! (uds/add-shape shape) + (udw/select-for-drawing nil)) (reset! +drawing-position+ nil) (reset! +drawing-shape+ nil))) @@ -74,8 +75,8 @@ (let [{:keys [x y]} @wb/mouse-canvas-a props {:x1 x :y1 y :x2 (+ x 100) :y2 (+ y 100)} shape (ush/initialize shape props)] - (rs/emit! (dw/add-shape shape) - (dw/select-for-drawing nil)))) + (rs/emit! (uds/add-shape shape) + (udw/select-for-drawing nil)))) (init [] (when-let [shape (:drawing @wb/workspace-l)] (case (:type shape) diff --git a/src/uxbox/ui/workspace/canvas/movement.cljs b/src/uxbox/ui/workspace/canvas/movement.cljs index f220f593d1..88a7c397c6 100644 --- a/src/uxbox/ui/workspace/canvas/movement.cljs +++ b/src/uxbox/ui/workspace/canvas/movement.cljs @@ -6,7 +6,7 @@ [uxbox.state :as ust] [uxbox.ui.core :as uuc] [uxbox.ui.workspace.base :as uuwb] - [uxbox.data.workspace :as dw])) + [uxbox.data.shapes :as uds])) (define-once :movement-subscription (letfn [(on-value [delta] @@ -16,7 +16,7 @@ (filter #(= (:page %) pageid)) (filter (comp selected :id)))] (doseq [{:keys [id group]} shapes] - (rs/emit! (dw/move-shape id delta))))) + (rs/emit! (uds/move-shape id delta))))) (init [] (as-> uuc/actions-s $ diff --git a/src/uxbox/ui/workspace/sidebar/layers.cljs b/src/uxbox/ui/workspace/sidebar/layers.cljs index ece39ca3e4..f6afaed366 100644 --- a/src/uxbox/ui/workspace/sidebar/layers.cljs +++ b/src/uxbox/ui/workspace/sidebar/layers.cljs @@ -9,7 +9,8 @@ [uxbox.state :as st] [uxbox.library :as library] [uxbox.util.data :refer (read-string classnames)] - [uxbox.data.workspace :as dw] + [uxbox.data.workspace :as udw] + [uxbox.data.shapes :as uds] [uxbox.ui.shapes.core :as uusc] [uxbox.ui.workspace.base :as wb] [uxbox.ui.icons :as i] @@ -41,18 +42,18 @@ nil (.-ctrlKey event) - (rs/emit! (dw/select-shape id)) + (rs/emit! (udw/select-shape id)) (> (count selected) 1) - (rs/emit! (dw/deselect-all) - (dw/select-shape id)) + (rs/emit! (udw/deselect-all) + (udw/select-shape id)) (contains? selected id) - (rs/emit! (dw/select-shape id)) + (rs/emit! (udw/select-shape id)) :else - (rs/emit! (dw/deselect-all) - (dw/select-shape id))))) + (rs/emit! (udw/deselect-all) + (udw/select-shape id))))) (defn- toggle-visibility [selected item event] @@ -60,10 +61,10 @@ (let [id (:id item) hidden? (:hidden item)] (if hidden? - (rs/emit! (dw/show-shape id)) - (rs/emit! (dw/hide-shape id))) + (rs/emit! (uds/show-shape id)) + (rs/emit! (uds/hide-shape id))) (when (contains? selected id) - (rs/emit! (dw/select-shape id))))) + (rs/emit! (udw/select-shape id))))) (defn- toggle-blocking [item event] @@ -71,8 +72,8 @@ (let [id (:id item) blocked? (:blocked item)] (if blocked? - (rs/emit! (dw/unblock-shape id)) - (rs/emit! (dw/block-shape id))))) + (rs/emit! (uds/unblock-shape id)) + (rs/emit! (uds/block-shape id))))) (defn- toggle-locking [item event] @@ -80,8 +81,8 @@ (let [id (:id item) locked? (:locked item)] (if locked? - (rs/emit! (dw/unlock-shape id)) - (rs/emit! (dw/lock-shape id))))) + (rs/emit! (uds/unlock-shape id)) + (rs/emit! (uds/lock-shape id))))) (defn- element-icon [item] @@ -136,8 +137,8 @@ (let [id (dnd/get-data event) over (:over @local)] (case (:over @local) - :top (rs/emit! (dw/drop-shape id (:id item) :before)) - :bottom (rs/emit! (dw/drop-shape id (:id item) :after))) + :top (rs/emit! (uds/drop-shape id (:id item) :before)) + :bottom (rs/emit! (uds/drop-shape id (:id item) :after))) (swap! local assoc :dragging false :over nil))) (on-drag-over [event] (dom/prevent-default event) @@ -215,9 +216,9 @@ (let [id (dnd/get-data event) over (:over @local)] (case (:over @local) - :top (rs/emit! (dw/drop-shape id (:id item) :before)) - :bottom (rs/emit! (dw/drop-shape id (:id item) :after)) - :middle (rs/emit! (dw/drop-shape id (:id item) :inside))) + :top (rs/emit! (uds/drop-shape id (:id item) :before)) + :bottom (rs/emit! (uds/drop-shape id (:id item) :after)) + :middle (rs/emit! (uds/drop-shape id (:id item) :inside))) (swap! local assoc :dragging false :over nil))) (on-drag-over [event] (dom/prevent-default event) @@ -281,10 +282,10 @@ selected (:selected workspace) shapes-by-id (rum/react wb/shapes-by-id-l) page (rum/react (focus-page (:page workspace))) - close #(rs/emit! (dw/toggle-flag :layers)) - duplicate #(rs/emit! (dw/duplicate-selected)) - group #(rs/emit! (dw/group-selected)) - delete #(rs/emit! (dw/delete-selected)) + close #(rs/emit! (udw/toggle-flag :layers)) + duplicate #(rs/emit! (udw/duplicate-selected)) + group #(rs/emit! (udw/group-selected)) + delete #(rs/emit! (udw/delete-selected)) dragel (volatile! nil)] (html [:div#layers.tool-window diff --git a/src/uxbox/ui/workspace/sidebar/options.cljs b/src/uxbox/ui/workspace/sidebar/options.cljs index 28d32ba3e5..91a373d2b0 100644 --- a/src/uxbox/ui/workspace/sidebar/options.cljs +++ b/src/uxbox/ui/workspace/sidebar/options.cljs @@ -8,7 +8,8 @@ [uxbox.state :as st] [uxbox.shapes :as sh] [uxbox.library :as library] - [uxbox.data.workspace :as dw] + [uxbox.data.workspace :as udw] + [uxbox.data.shapes :as uds] [uxbox.ui.workspace.base :as wb] [uxbox.ui.icons :as i] [uxbox.ui.mixins :as mx] @@ -71,7 +72,7 @@ [menu own shape] (letfn [(change-stroke [value] (let [sid (:id shape)] - (rs/emit! (dw/update-stroke-attrs sid value)))) + (rs/emit! (uds/update-stroke-attrs sid value)))) (on-width-change [event] (let [value (dom/event->value event) value (parse-float value 1)] @@ -136,7 +137,7 @@ [menu own shape] (letfn [(change-fill [value] (let [sid (:id shape)] - (rs/emit! (dw/update-fill-attrs sid value)))) + (rs/emit! (uds/update-fill-attrs sid value)))) (on-color-change [event] (let [value (dom/event->value event)] (change-fill {:color value}))) @@ -180,24 +181,24 @@ value (parse-int value 0) sid (:id shape) props {attr value}] - (rs/emit! (dw/update-size sid props)))) + (rs/emit! (uds/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-rotation sid value)))) + (rs/emit! (uds/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-position sid props)))) + (rs/emit! (uds/update-position sid props)))) (on-border-change [attr event] (let [value (dom/event->value event) value (parse-int value nil) sid (:id shape) props {attr value}] - (rs/emit! (dw/update-radius-attrs sid props))))] + (rs/emit! (uds/update-radius-attrs sid props))))] (let [size (sh/size shape)] (html [:div.element-set {:key (str (:id menu))} @@ -278,18 +279,18 @@ value (parse-int value 0) sid (:id shape) props {attr value}] - (rs/emit! (dw/update-size sid props)))) + (rs/emit! (uds/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-rotation sid value)))) + (rs/emit! (uds/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-position sid props))))] + (rs/emit! (uds/update-position sid props))))] (let [size (sh/size shape)] (html [:div.element-set {:key (str (:id menu))} @@ -355,18 +356,18 @@ value (parse-int value 0) sid (:id shape) props {attr value}] - (rs/emit! (dw/update-radius-attrs sid props)))) + (rs/emit! (uds/update-radius-attrs sid props)))) (on-rotation-change [event] (let [value (dom/event->value event) value (parse-int value 0) sid (:id shape)] - (rs/emit! (dw/update-rotation sid value)))) + (rs/emit! (uds/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-position sid props))))] + (rs/emit! (uds/update-position sid props))))] (html [:div.element-set {:key (str (:id menu))} [:div.element-set-title (:name menu)] @@ -430,13 +431,13 @@ (let [value (dom/event->value event) value (parse-int value 0) sid (:id shape)] - (rs/emit! (dw/update-rotation sid value)))) + (rs/emit! (uds/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-line-attrs sid props))))] + (rs/emit! (uds/update-line-attrs sid props))))] (html [:div.element-set {:key (str (:id menu))} [:div.element-set-title (:name menu)] @@ -578,7 +579,7 @@ (defn options-toolbox-render [own] (let [shape (rum/react selected-shape-l) - close #(rs/emit! (dw/toggle-flag :element-options))] + close #(rs/emit! (udw/toggle-flag :element-options))] (html [:div.elementa-options.tool-window [:div.tool-window-bar