From 193ad115a29aaa3a9ce077108b51c4db409ee283 Mon Sep 17 00:00:00 2001 From: Akshay Gupta Date: Mon, 3 Jun 2024 23:25:59 +0530 Subject: [PATCH 1/2] Add context menu functionalities on sizing tokens --- common/src/app/common/types/token.cljc | 8 ++--- .../ui/workspace/tokens/context_menu.cljs | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/types/token.cljc b/common/src/app/common/types/token.cljc index 336e92eb1..29b478930 100644 --- a/common/src/app/common/types/token.cljc +++ b/common/src/app/common/types/token.cljc @@ -77,10 +77,10 @@ [:map [:width {:optional true} ::sm/uuid] [:height {:optional true} ::sm/uuid] - [:min-height {:optional true} ::sm/uuid] - [:max-height {:optional true} ::sm/uuid] - [:min-width {:optional true} ::sm/uuid] - [:max-width {:optional true} ::sm/uuid]]) + [:layout-item-min-w {:optional true} ::sm/uuid] + [:layout-item-max-w {:optional true} ::sm/uuid] + [:layout-item-min-h {:optional true} ::sm/uuid] + [:layout-item-max-h {:optional true} ::sm/uuid]]) (def sizing-keys (schema-keys ::sizing)) diff --git a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs index 034bf5eda..e0a7eea7a 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -13,6 +13,7 @@ [app.main.data.tokens :as dt] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.shape-layout :as dwsl] + [app.main.data.workspace.transforms :as dwt] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.components.dropdown :refer [dropdown]] @@ -63,6 +64,30 @@ :token-type-props updated-token-type-props :selected-shapes selected-shapes}))) +(defn update-shape-dimensions [value shape-ids attributes] + (println "attributes is " attributes) + (st/emit! (dwt/update-dimensions shape-ids (first attributes) value))) + +(defn update-layout-sizing-limits [value shape-ids attributes] + (st/emit! (dwsl/update-layout-child shape-ids {(first attributes) value}))) + +(defn apply-sizing-token [{:keys [token-id token-type-props selected-shapes]} attribute] + (let [token (dt/get-token-data-from-token-id token-id) + updated-token-type-props (cond + (#{:width :height} attribute) + (assoc token-type-props + :on-update-shape update-shape-dimensions + :attributes #{attribute}) + + (#{:layout-item-min-w :layout-item-max-w + :layout-item-min-h :layout-item-max-h} attribute) + (assoc token-type-props + :on-update-shape update-layout-sizing-limits + :attributes #{attribute}))] + (wtc/on-apply-token {:token token + :token-type-props updated-token-type-props + :selected-shapes selected-shapes}))) + (defn additional-actions [{:keys [token-type] :as context-data}] (case token-type @@ -82,6 +107,16 @@ {:title "Right" :action #(action #{:p2})} {:title "Bottom" :action #(action #{:p3})} {:title "Left" :action #(action #{:p4})}]) + + :sizing (let [action #(apply-sizing-token context-data %)] + [{:title "All" :action #(action :all)} + {:title "Width" :action #(action :width)} + {:title "Height" :action #(action :height)} + {:title "Min width" :action #(action :layout-item-min-w)} + {:title "Max width" :action #(action :layout-item-max-w)} + {:title "Min height" :action #(action :layout-item-min-h)} + {:title "Max height" :action #(action :layout-item-max-h)}]) + [])) (defn generate-menu-entries [{:keys [token-id token-type-props token-type selected-shapes] :as context-data}] From a553253d28d887d6a36e6e4a342719d904d1b858 Mon Sep 17 00:00:00 2001 From: Akshay Gupta Date: Mon, 3 Jun 2024 23:34:51 +0530 Subject: [PATCH 2/2] remove println statement --- frontend/src/app/main/ui/workspace/tokens/context_menu.cljs | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs index e0a7eea7a..65d4fe000 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -65,7 +65,6 @@ :selected-shapes selected-shapes}))) (defn update-shape-dimensions [value shape-ids attributes] - (println "attributes is " attributes) (st/emit! (dwt/update-dimensions shape-ids (first attributes) value))) (defn update-layout-sizing-limits [value shape-ids attributes]