mirror of
https://github.com/penpot/penpot.git
synced 2025-03-14 08:41:48 -05:00
Extract gap as extra function
This commit is contained in:
parent
39822a3b31
commit
4cf8b2c143
1 changed files with 34 additions and 30 deletions
|
@ -257,7 +257,38 @@
|
||||||
:gap {:column-gap "Column Gap"
|
:gap {:column-gap "Column Gap"
|
||||||
:row-gap "Row Gap"}})
|
:row-gap "Row Gap"}})
|
||||||
|
|
||||||
(defn spacing-attribute-actions [{:keys [token-id selected-shapes] :as _props}]
|
(defn gap-attribute-actions [{:keys [token-id selected-shapes] :as _props}]
|
||||||
|
(let [token {:id token-id}
|
||||||
|
gap-attrs (:gap spacing)
|
||||||
|
all-gap-attrs (into #{} (keys gap-attrs))
|
||||||
|
{:keys [all-selected? selected-pred shape-ids]} (attribute-actions token selected-shapes all-gap-attrs)
|
||||||
|
all-gap (let [props {:attributes all-gap-attrs
|
||||||
|
: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))))}])
|
||||||
|
single-gap (->> gap-attrs
|
||||||
|
(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))})))
|
||||||
|
(into))]
|
||||||
|
(concat all-gap single-gap)))
|
||||||
|
|
||||||
|
(defn spacing-attribute-actions [{:keys [token-id selected-shapes] :as props}]
|
||||||
(let [token {:id token-id}
|
(let [token {:id token-id}
|
||||||
on-update-shape (fn [resolved-value shape-ids attrs]
|
on-update-shape (fn [resolved-value shape-ids attrs]
|
||||||
(dwsl/update-layout shape-ids {:layout-padding (zipmap attrs (repeat resolved-value))}))
|
(dwsl/update-layout shape-ids {:layout-padding (zipmap attrs (repeat resolved-value))}))
|
||||||
|
@ -327,38 +358,11 @@
|
||||||
:else (-> (assoc props :on-update-shape on-update-shape)
|
:else (-> (assoc props :on-update-shape on-update-shape)
|
||||||
(wtc/apply-token)))]
|
(wtc/apply-token)))]
|
||||||
(st/emit! event))}))))
|
(st/emit! event))}))))
|
||||||
gap-attrs (:gap spacing)
|
gap-items (gap-attribute-actions props)]
|
||||||
all-gap-attrs (into #{} (keys gap-attrs))
|
|
||||||
{:keys [all-selected? selected-pred shape-ids]} (attribute-actions token selected-shapes all-gap-attrs)
|
|
||||||
single-gap (->> gap-attrs
|
|
||||||
(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))})))
|
|
||||||
(into))
|
|
||||||
all-gap (let [props {:attributes all-gap-attrs
|
|
||||||
: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 padding-items
|
(concat padding-items
|
||||||
single-padding-items
|
single-padding-items
|
||||||
[:separator]
|
[:separator]
|
||||||
[all-gap]
|
gap-items)))
|
||||||
single-gap)))
|
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(comment
|
(comment
|
||||||
|
|
Loading…
Add table
Reference in a new issue