From 65942ef63b3ee3694823eb7b8ca0c24a7be3dbd1 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 3 Jun 2024 13:39:26 +0200 Subject: [PATCH] Use set of attributes for action generation --- .../ui/workspace/tokens/context_menu.cljs | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) 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 389a93dcd..d011f9c8b 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -19,6 +19,7 @@ [app.main.ui.workspace.context-menu :refer [menu-entry prevent-default]] [app.main.ui.workspace.tokens.core :as wtc] [app.util.dom :as dom] + [clojure.set :as set] [okulary.core :as l] [rumext.v2 :as mf])) @@ -34,12 +35,12 @@ {:reg-objects? true :attrs [:rx :ry :r1 :r2 :r3 :r4]}))) -(defn apply-border-radius-token [{:keys [token-id token-type-props selected-shapes]} attribute] +(defn apply-border-radius-token [{:keys [token-id token-type-props selected-shapes]} attributes] (let [token (dt/get-token-data-from-token-id token-id) - updated-token-type-props (if (#{:r1 :r2 :r3 :r4} attribute) + updated-token-type-props (if (set/superset? #{:r1 :r2 :r3 :r4} attributes) (assoc token-type-props :on-update-shape update-shape-radius-single-corner - :attributes #{attribute}) + :attributes attributes) token-type-props)] (wtc/on-apply-token {:token token :token-type-props updated-token-type-props @@ -65,24 +66,29 @@ (defn additional-actions [{:keys [token-type] :as context-data}] - (case token-type - :border-radius (let [action #(apply-border-radius-token context-data %)] - [{:title "All" :action #(action :all)} - {:title "Top Left" :action #(action :r1)} - {:title "Top Right" :action #(action :r2)} - {:title "Bottom Right" :action #(action :r3)} - {:title "Bottom Left" :action #(action :r4)}]) - :spacing (let [action #(apply-spacing-token context-data %)] - [{:title "All" :action #(action #{:p1 :p2 :p3 :p4})} - {:title "Column Gap" :action #(action #{:column-gap})} - {:title "Vertical padding" :action #(action #{:p1 :p3})} - {:title "Horizontal padding" :action #(action #{:p2 :p4})} - {:title "Row Gap" :action #(action #{:row-gap})} - {:title "Top" :action #(action #{:p1})} - {:title "Right" :action #(action #{:p2})} - {:title "Bottom" :action #(action #{:p3})} - {:title "Left" :action #(action #{:p4})}]) - [])) + (let [attributes->actions (fn [update-fn coll] + (for [{:keys [attributes] :as item} coll] + (assoc item :action #(update-fn context-data attributes))))] + (case token-type + :border-radius (attributes->actions + apply-border-radius-token + [{:title "All" :attributes #{:all}} + {:title "Top Left" :attributes #{:r1}} + {:title "Top Right" :attributes #{:r2}} + {:title "Bottom Right" :attributes #{:r3}} + {:title "Bottom Left" :attributes #{:r4}}]) + :spacing (attributes->actions + apply-spacing-token + [{:title "All" :attributes #{:p1 :p2 :p3 :p4}} + {:title "Column Gap" :attributes #{:column-gap}} + {:title "Vertical padding" :attributes #{:p1 :p3}} + {:title "Horizontal padding" :attributes #{:p2 :p4}} + {:title "Row Gap" :attributes #{:row-gap}} + {:title "Top" :attributes #{:p1}} + {:title "Right" :attributes #{:p2}} + {:title "Bottom" :attributes #{:p3}} + {:title "Left" :attributes #{:p4}}]) + []))) (defn generate-menu-entries [{:keys [token-id token-type-props token-type selected-shapes] :as context-data}] (let [{:keys [modal]} token-type-props