From 06ec1e00ee7b2a2ff8d5a71f9b762701d3cef87c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 19 Mar 2020 18:54:24 +0100 Subject: [PATCH] :sparkles: Add context menu to all shapes. --- frontend/src/uxbox/main/ui/shapes/path.cljs | 23 ++++++------- frontend/src/uxbox/main/ui/shapes/text.cljs | 36 +++++++++++---------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/frontend/src/uxbox/main/ui/shapes/path.cljs b/frontend/src/uxbox/main/ui/shapes/path.cljs index edad7ce68..31b479b3b 100644 --- a/frontend/src/uxbox/main/ui/shapes/path.cljs +++ b/frontend/src/uxbox/main/ui/shapes/path.cljs @@ -24,17 +24,18 @@ (mf/defc path-wrapper [{:keys [shape] :as props}] (let [selected (mf/deref refs/selected-shapes) - selected? (contains? selected (:id shape))] - (letfn [(on-mouse-down [event] - (common/on-mouse-down event shape selected)) - (on-double-click [event] - (when selected? - (st/emit! (dw/start-edition-mode (:id shape)))))] - [:g.shape {:class (when selected? "selected") - :on-double-click on-double-click - :on-mouse-down on-mouse-down} - [:& path-shape {:shape shape - :background? true}]]))) + selected? (contains? selected (:id shape)) + on-mouse-down #(common/on-mouse-down % shape) + on-context-menu #(common/on-context-menu % shape) + on-double-click + (fn [event] + (when selected? + (st/emit! (dw/start-edition-mode (:id shape)))))] + [:g.shape {:on-double-click on-double-click + :on-mouse-down on-mouse-down + :on-context-menu on-context-menu} + [:& path-shape {:shape shape + :background? true}]])) ;; --- Path Shape diff --git a/frontend/src/uxbox/main/ui/shapes/text.cljs b/frontend/src/uxbox/main/ui/shapes/text.cljs index c78c90f1c..f130076f6 100644 --- a/frontend/src/uxbox/main/ui/shapes/text.cljs +++ b/frontend/src/uxbox/main/ui/shapes/text.cljs @@ -12,7 +12,7 @@ [lentes.core :as l] [rumext.core :as mx] [rumext.alpha :as mf] - [uxbox.main.data.workspace :as udw] + [uxbox.main.data.workspace :as dw] [uxbox.main.geom :as geom] [uxbox.main.refs :as refs] [uxbox.main.store :as st] @@ -45,18 +45,20 @@ edition (mf/deref refs/selected-edition) edition? (= edition id) selected? (and (contains? selected id) - (= (count selected) 1))] - (letfn [(on-mouse-down [event] - (handle-mouse-down event shape selected)) - (on-double-click [event] - (dom/stop-propagation event) - (st/emit! (udw/start-edition-mode id)))] - [:g.shape {:class (when selected? "selected") - :on-double-click on-double-click - :on-mouse-down on-mouse-down} - (if edition? - [:& text-shape-edit {:shape shape}] - [:& text-shape {:shape shape}])]))) + (= (count selected) 1)) + + on-mouse-down #(common/on-mouse-down % shape) + on-context-menu #(common/on-context-menu % shape) + on-double-click + (fn [event] + (when selected? + (st/emit! (dw/start-edition-mode (:id shape)))))] + [:g.shape {:on-double-click on-double-click + :on-mouse-down on-mouse-down + :on-context-menu on-context-menu} + (if edition? + [:& text-shape-edit {:shape shape}] + [:& text-shape {:shape shape}])])) ;; --- Text Styles Helpers @@ -118,13 +120,13 @@ (fn [] (let [content (-> (mf/ref-val ref) (dom/get-value))] - (st/emit! (udw/update-shape id {:content content})))) + (st/emit! (dw/update-shape id {:content content})))) on-blur (fn [event] - (st/emit! udw/clear-edition-mode - udw/deselect-all))] + (st/emit! dw/clear-edition-mode + dw/deselect-all))] (mf/use-effect #(let [dom (mf/ref-val ref) val (dom/get-value dom)] @@ -134,7 +136,7 @@ (fn [] (let [content (-> (mf/ref-val ref) (dom/get-value))] - (st/emit! (udw/update-shape id {:content content})))))) + (st/emit! (dw/update-shape id {:content content}))))))