0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-01 11:59:17 -05:00

Use set of attributes for action generation

This commit is contained in:
Florian Schroedl 2024-06-03 13:39:26 +02:00
parent c1096e15da
commit 65942ef63b

View file

@ -19,6 +19,7 @@
[app.main.ui.workspace.context-menu :refer [menu-entry prevent-default]] [app.main.ui.workspace.context-menu :refer [menu-entry prevent-default]]
[app.main.ui.workspace.tokens.core :as wtc] [app.main.ui.workspace.tokens.core :as wtc]
[app.util.dom :as dom] [app.util.dom :as dom]
[clojure.set :as set]
[okulary.core :as l] [okulary.core :as l]
[rumext.v2 :as mf])) [rumext.v2 :as mf]))
@ -34,12 +35,12 @@
{:reg-objects? true {:reg-objects? true
:attrs [:rx :ry :r1 :r2 :r3 :r4]}))) :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) (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 (assoc token-type-props
:on-update-shape update-shape-radius-single-corner :on-update-shape update-shape-radius-single-corner
:attributes #{attribute}) :attributes attributes)
token-type-props)] token-type-props)]
(wtc/on-apply-token {:token token (wtc/on-apply-token {:token token
:token-type-props updated-token-type-props :token-type-props updated-token-type-props
@ -65,24 +66,29 @@
(defn additional-actions [{:keys [token-type] :as context-data}] (defn additional-actions [{:keys [token-type] :as context-data}]
(case token-type (let [attributes->actions (fn [update-fn coll]
:border-radius (let [action #(apply-border-radius-token context-data %)] (for [{:keys [attributes] :as item} coll]
[{:title "All" :action #(action :all)} (assoc item :action #(update-fn context-data attributes))))]
{:title "Top Left" :action #(action :r1)} (case token-type
{:title "Top Right" :action #(action :r2)} :border-radius (attributes->actions
{:title "Bottom Right" :action #(action :r3)} apply-border-radius-token
{:title "Bottom Left" :action #(action :r4)}]) [{:title "All" :attributes #{:all}}
:spacing (let [action #(apply-spacing-token context-data %)] {:title "Top Left" :attributes #{:r1}}
[{:title "All" :action #(action #{:p1 :p2 :p3 :p4})} {:title "Top Right" :attributes #{:r2}}
{:title "Column Gap" :action #(action #{:column-gap})} {:title "Bottom Right" :attributes #{:r3}}
{:title "Vertical padding" :action #(action #{:p1 :p3})} {:title "Bottom Left" :attributes #{:r4}}])
{:title "Horizontal padding" :action #(action #{:p2 :p4})} :spacing (attributes->actions
{:title "Row Gap" :action #(action #{:row-gap})} apply-spacing-token
{:title "Top" :action #(action #{:p1})} [{:title "All" :attributes #{:p1 :p2 :p3 :p4}}
{:title "Right" :action #(action #{:p2})} {:title "Column Gap" :attributes #{:column-gap}}
{:title "Bottom" :action #(action #{:p3})} {:title "Vertical padding" :attributes #{:p1 :p3}}
{:title "Left" :action #(action #{:p4})}]) {: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}] (defn generate-menu-entries [{:keys [token-id token-type-props token-type selected-shapes] :as context-data}]
(let [{:keys [modal]} token-type-props (let [{:keys [modal]} token-type-props