mirror of
https://github.com/penpot/penpot.git
synced 2025-02-01 11:59:17 -05:00
Add generic context menu actions
This commit is contained in:
parent
cabc3d3f36
commit
da3f2f820c
1 changed files with 19 additions and 13 deletions
|
@ -361,10 +361,28 @@
|
||||||
[:separator]
|
[:separator]
|
||||||
gap-items)))
|
gap-items)))
|
||||||
|
|
||||||
|
(defn generic-attribute-actions [attributes title {:keys [token selected-shapes]}]
|
||||||
|
(let [{:keys [on-update-shape] :as p} (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
|
(def shape-attribute-actions-map
|
||||||
{:border-radius border-radius-attribute-actions
|
{:border-radius border-radius-attribute-actions
|
||||||
:spacing spacing-attribute-actions
|
:spacing spacing-attribute-actions
|
||||||
:sizing nil})
|
:rotation (partial generic-attribute-actions #{:rotation} "Rotation")
|
||||||
|
:opacity (partial generic-attribute-actions #{:opacity} "Opacity")
|
||||||
|
:stroke-width (partial generic-attribute-actions #{:stroke-width} "Stroke Width")})
|
||||||
|
|
||||||
(defn shape-attribute-actions [{:keys [token] :as context-data}]
|
(defn shape-attribute-actions [{:keys [token] :as context-data}]
|
||||||
(when-let [with-actions (get shape-attribute-actions-map (:type token))]
|
(when-let [with-actions (get shape-attribute-actions-map (:type token))]
|
||||||
|
@ -381,8 +399,6 @@
|
||||||
:action #(update-fn context-data attributes)
|
:action #(update-fn context-data attributes)
|
||||||
:selected? selected?)))))]
|
:selected? selected?)))))]
|
||||||
(case (:type token)
|
(case (:type token)
|
||||||
:border-radius (border-radius-attribute-actions context-data)
|
|
||||||
:spacing (spacing-attribute-actions context-data)
|
|
||||||
:sizing (attributes->actions
|
:sizing (attributes->actions
|
||||||
apply-sizing-token
|
apply-sizing-token
|
||||||
[{:title "All" :attributes #{:width :height :layout-item-min-w :layout-item-max-w :layout-item-min-h :layout-item-max-h}}
|
[{:title "All" :attributes #{:width :height :layout-item-min-w :layout-item-max-w :layout-item-min-h :layout-item-max-h}}
|
||||||
|
@ -403,17 +419,7 @@
|
||||||
{:title "y" :attributes #{:y}}])
|
{:title "y" :attributes #{:y}}])
|
||||||
;;TODO: Background blur {:title "Background blur" :attributes #{:width}}])
|
;;TODO: Background blur {:title "Background blur" :attributes #{:width}}])
|
||||||
|
|
||||||
:opacity (attributes->actions
|
|
||||||
apply-rotation-opacity-stroke-token
|
|
||||||
[{:title "opacity" :attributes #{:opacity}}])
|
|
||||||
|
|
||||||
:rotation (attributes->actions
|
|
||||||
apply-rotation-opacity-stroke-token
|
|
||||||
[{:title "rotation" :attributes #{:rotation}}])
|
|
||||||
|
|
||||||
:stroke-width (attributes->actions
|
|
||||||
apply-rotation-opacity-stroke-token
|
|
||||||
[{:title "stroke width" :attributes #{:stroke-width}}])
|
|
||||||
|
|
||||||
[])))
|
[])))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue