From 03370c267d1e77c9631a9cce4a1b6411e4e391ce Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 24 Jul 2024 15:02:10 +0200 Subject: [PATCH] Cleanup --- .../ui/workspace/tokens/context_menu.cljs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 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 424fd0329..b34615dad 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -93,6 +93,22 @@ :shape-ids shape-ids :selected-pred #(seq (% ids-by-attributes))})) +(defn generic-attribute-actions [attributes title {:keys [token selected-shapes]}] + (let [{:keys [on-update-shape]} (get wtc/token-types (:type token)) + {:keys [selected-pred shape-ids]} (attribute-actions token selected-shapes attributes)] + (map (fn [attribute] + (let [selected? (selected-pred attribute) + props {:attributes #{attribute} + :token token + :shape-ids shape-ids}] + + {:title title + :selected? selected? + :action #(if selected? + (st/emit! (wtc/unapply-token props)) + (st/emit! (wtc/apply-token (assoc props :on-update-shape on-update-shape))))})) + attributes))) + (defn all-or-sepearate-actions [{:keys [attribute-labels on-update-shape-all on-update-shape]} {:keys [token selected-shapes]}] (let [attributes (set (keys attribute-labels)) @@ -220,22 +236,6 @@ :on-update-shape update-layout-sizing-limits} context-data))) -(defn generic-attribute-actions [attributes title {:keys [token selected-shapes]}] - (let [{:keys [on-update-shape]} (get wtc/token-types (:type token)) - {:keys [selected-pred shape-ids]} (attribute-actions token selected-shapes attributes)] - (map (fn [attribute] - (let [selected? (selected-pred attribute) - props {:attributes #{attribute} - :token token - :shape-ids shape-ids}] - - {:title title - :selected? selected? - :action #(if selected? - (st/emit! (wtc/unapply-token props)) - (st/emit! (wtc/apply-token (assoc props :on-update-shape on-update-shape))))})) - attributes))) - (def shape-attribute-actions-map (let [stroke-width (partial generic-attribute-actions #{:stroke-width} "Stroke Width")] {:border-radius (partial all-or-sepearate-actions {:attribute-labels {:r1 "Top Left"