diff --git a/src/uxbox/ui/workspace/canvas.cljs b/src/uxbox/ui/workspace/canvas.cljs index d5e33f297..407b0564e 100644 --- a/src/uxbox/ui/workspace/canvas.cljs +++ b/src/uxbox/ui/workspace/canvas.cljs @@ -24,7 +24,7 @@ [uxbox.ui.mixins :as mx] [uxbox.ui.workspace.base :as uuwb] [uxbox.ui.workspace.drawarea :refer (draw-area)] - [uxbox.ui.workspace.canvas.movement] + [uxbox.ui.workspace.movement :as cmov] [uxbox.ui.workspace.canvas.resize] [uxbox.ui.workspace.canvas.ruler :refer (ruler)] [uxbox.ui.workspace.canvas.selection :refer (shapes-selection)] @@ -155,23 +155,28 @@ (let [key1 (events/listen js/document EventType.MOUSEMOVE on-mousemove) key2 (events/listen js/document EventType.KEYDOWN on-key-down) - key3 (events/listen js/document EventType.KEYUP on-key-up)] - (assoc own ::key1 key1 ::key2 key2 ::key3 key3)))) + key3 (events/listen js/document EventType.KEYUP on-key-up) + sub1 (cmov/watch-move-actions)] + (assoc own + ::sub1 sub1 + ::key1 key1 + ::key2 key2 + ::key3 key3)))) (defn- viewport-will-unmount [own] - (let [key1 (::key1 own) - key2 (::key2 own) - key3 (::key3 own)] - (events/unlistenByKey key1) - (events/unlistenByKey key2) - (events/unlistenByKey key3) - (dissoc own ::key1 ::key2 ::key3))) + (events/unlistenByKey (::key1 own)) + (events/unlistenByKey (::key2 own)) + (events/unlistenByKey (::key3 own)) + (.close (::sub1 own)) + (dissoc own ::key1 ::key2 ::key3 ::sub1)) (defn- viewport-transfer-state [old-own own] - (let [data (select-keys old-own [::key1 ::key2 ::key3])] - (merge own data))) + (->> [::key1 ::key2 ::key3 + ::sub1] + (select-keys old-own) + (merge own))) (def viewport (mx/component diff --git a/src/uxbox/ui/workspace/canvas/movement.cljs b/src/uxbox/ui/workspace/canvas/movement.cljs deleted file mode 100644 index dd5061471..000000000 --- a/src/uxbox/ui/workspace/canvas/movement.cljs +++ /dev/null @@ -1,41 +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 Andrey Antukh -;; Copyright (c) 2015-2016 Juan de la Cruz - -(ns uxbox.ui.workspace.canvas.movement - (:require-macros [uxbox.util.syntax :refer [define-once]]) - (:require [beicon.core :as rx] - [lentes.core :as l] - [uxbox.rstore :as rs] - [uxbox.state :as st] - [uxbox.ui.core :as uuc] - [uxbox.ui.workspace.base :as wb] - [uxbox.data.shapes :as uds] - [uxbox.util.geom.point :as gpt])) - -(define-once :movement-subscription - (letfn [(on-value [delta] - (let [pageid (get-in @st/state [:workspace :page]) - selected (get-in @st/state [:workspace :selected]) - shapes (->> (vals @wb/shapes-by-id-l) - (filter #(= (:page %) pageid)) - (filter (comp selected :id))) - delta (gpt/divide delta @wb/zoom-l)] - (doseq [{:keys [id group]} shapes] - (rs/emit! (uds/move-shape id delta))))) - - (init [] - (let [stoper (->> uuc/actions-s - (rx/map :type) - (rx/filter empty?) - (rx/take 1))] - (as-> wb/mouse-delta-s $ - (rx/take-until stoper $) - (rx/on-value $ on-value))))] - - (as-> uuc/actions-s $ - (rx/filter #(= "ui.shape.move" (:type %)) $) - (rx/on-value $ init)))) diff --git a/src/uxbox/ui/workspace/movement.cljs b/src/uxbox/ui/workspace/movement.cljs new file mode 100644 index 000000000..919ecb5e1 --- /dev/null +++ b/src/uxbox/ui/workspace/movement.cljs @@ -0,0 +1,53 @@ +;; 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 Andrey Antukh +;; Copyright (c) 2015-2016 Juan de la Cruz + +(ns uxbox.ui.workspace.movement + "Shape movement in workspace logic." + (:require-macros [uxbox.util.syntax :refer [define-once]]) + (:require [beicon.core :as rx] + [lentes.core :as l] + [uxbox.rstore :as rs] + [uxbox.state :as st] + [uxbox.ui.core :as uuc] + [uxbox.ui.workspace.base :as wb] + [uxbox.data.shapes :as uds] + [uxbox.util.geom.point :as gpt])) + +(declare initialize) +(declare handle-movement) + +;; --- Public Api + +(defn watch-move-actions + [] + (as-> uuc/actions-s $ + (rx/filter #(= "ui.shape.move" (:type %)) $) + (rx/on-value $ initialize))) + +;; --- Implementation + +(defn- initialize + [] + (let [stoper (->> uuc/actions-s + (rx/map :type) + (rx/filter empty?) + (rx/take 1))] + (as-> wb/mouse-delta-s $ + (rx/take-until stoper $) + (rx/on-value $ handle-movement)))) + +(defn- handle-movement + [delta] + (let [pageid (get-in @st/state [:workspace :page]) + selected (get-in @st/state [:workspace :selected]) + shapes (->> (vals @wb/shapes-by-id-l) + (filter #(= (:page %) pageid)) + (filter (comp selected :id))) + delta (gpt/divide delta @wb/zoom-l)] + (doseq [{:keys [id group]} shapes] + (rs/emit! (uds/move-shape id delta))))) +