mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Extract common logic
This commit is contained in:
parent
2836ff2693
commit
fd2f5537cf
1 changed files with 39 additions and 0 deletions
|
@ -210,9 +210,48 @@
|
|||
:token-type-props token-type-props
|
||||
:selected-shapes selected-shapes})))
|
||||
|
||||
(defn attribute-actions [token selected-shapes attributes]
|
||||
(let [ids-by-attributes (wtt/shapes-ids-by-applied-attributes token selected-shapes attributes)
|
||||
shape-ids (into #{} (map :id selected-shapes))]
|
||||
{:all-selected? (wtt/shapes-applied-all? ids-by-attributes shape-ids attributes)
|
||||
:shape-ids shape-ids
|
||||
:selected-pred #(seq (% ids-by-attributes))}))
|
||||
|
||||
(defn border-radius-attribute-actions [{:keys [token-id selected-shapes] :as _props}]
|
||||
(let [token {:id token-id}
|
||||
all-attributes #{:r1 :r2 :r3 :r4}
|
||||
{:keys [all-selected? selected-pred shape-ids]} (attribute-actions token selected-shapes #{:r1 :r2 :r3 :r4})
|
||||
single-attributes (->> {:r1 "Top Left"
|
||||
:r2 "Top Right"
|
||||
:r3 "Bottom Left"
|
||||
:r4 "Bottom Right"}
|
||||
(map (fn [[attr title]]
|
||||
(let [selected? (selected-pred attr)]
|
||||
{:title title
|
||||
:selected? (and (not all-selected?) selected?)
|
||||
:action #(let [props {:attributes #{attr}
|
||||
:token token
|
||||
:shape-ids shape-ids}
|
||||
event (cond
|
||||
all-selected? (-> (assoc props :attributes-to-remove #{:r1 :r2 :r3 :r4 :rx :ry})
|
||||
(wtc/apply-token))
|
||||
selected? (wtc/unapply-token props)
|
||||
:else (-> (assoc props :on-update-shape wtc/update-shape-radius-single-corner)
|
||||
(wtc/apply-token)))]
|
||||
(st/emit! event))}))))
|
||||
all-attribute (let [props {:attributes all-attributes
|
||||
:token token
|
||||
:shape-ids shape-ids}]
|
||||
{:title "All"
|
||||
:selected? all-selected?
|
||||
:action #(if all-selected?
|
||||
(st/emit! (wtc/unapply-token props))
|
||||
(st/emit! (wtc/apply-token (assoc props :on-update-shape wtc/update-shape-radius-all))))})]
|
||||
(concat [all-attribute] single-attributes)))
|
||||
|
||||
(defn spacing-attribute-actions [{:keys [token-id selected-shapes] :as _props}]
|
||||
(let [token {:id token-id}
|
||||
all-attributes #{:p1 :p2 :p3 :p4}
|
||||
ids-by-attributes (wtt/shapes-ids-by-applied-attributes token selected-shapes all-attributes)
|
||||
shape-ids (into #{} (map :id selected-shapes))
|
||||
all-selected? (wtt/shapes-applied-all? ids-by-attributes shape-ids all-attributes)
|
||||
|
|
Loading…
Add table
Reference in a new issue