0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-08 08:09:14 -05:00

Use all-or-sepearate-actions for gap

This commit is contained in:
Florian Schroedl 2024-07-24 13:41:08 +02:00
parent 335808bf03
commit c11c1e0c03

View file

@ -137,21 +137,18 @@
:gap {:column-gap "Column Gap" :gap {:column-gap "Column Gap"
:row-gap "Row Gap"}}) :row-gap "Row Gap"}})
(defn gap-attribute-actions [{:keys [token selected-shapes]}] (defn all-or-sepearate-actions [attribute-labels on-update-shape {:keys [token selected-shapes]}]
(let [on-update-shape update-layout-spacing (let [attributes (set (keys attribute-labels))
gap-attrs (:gap spacing) {:keys [all-selected? selected-pred shape-ids]} (attribute-actions token selected-shapes attributes)
all-gap-attrs (into #{} (keys gap-attrs)) all-action (let [props {:attributes attributes
{: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 :token token
:shape-ids shape-ids}] :shape-ids shape-ids}]
[{:title "All" {:title "All"
:selected? all-selected? :selected? all-selected?
:action #(if all-selected? :action #(if all-selected?
(st/emit! (wtc/unapply-token props)) (st/emit! (wtc/unapply-token props))
(st/emit! (wtc/apply-token (assoc props :on-update-shape on-update-shape))))}]) (st/emit! (wtc/apply-token (assoc props :on-update-shape on-update-shape))))})
single-gap (->> gap-attrs single-actions (map (fn [[attr title]]
(map (fn [[attr title]]
(let [selected? (selected-pred attr)] (let [selected? (selected-pred attr)]
{:title title {:title title
:selected? (and (not all-selected?) selected?) :selected? (and (not all-selected?) selected?)
@ -159,14 +156,14 @@
:token token :token token
:shape-ids shape-ids} :shape-ids shape-ids}
event (cond event (cond
all-selected? (-> (assoc props :attributes-to-remove #{:row-gap :column-gap}) all-selected? (-> (assoc props :attributes-to-remove attributes)
(wtc/apply-token)) (wtc/apply-token))
selected? (wtc/unapply-token props) selected? (wtc/unapply-token props)
: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))}))
(into))] attribute-labels)]
(concat all-gap single-gap))) (concat [all-action] single-actions)))
(defn spacing-attribute-actions [{:keys [token selected-shapes] :as context-data}] (defn spacing-attribute-actions [{:keys [token selected-shapes] :as context-data}]
(let [on-update-shape (fn [resolved-value shape-ids attrs] (let [on-update-shape (fn [resolved-value shape-ids attrs]
@ -237,40 +234,14 @@
: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-items (gap-attribute-actions context-data)] gap-items (all-or-sepearate-actions {:column-gap "Column Gap"
:row-gap "Row Gap"}
update-layout-spacing context-data)]
(concat padding-items (concat padding-items
single-padding-items single-padding-items
[:separator] [:separator]
gap-items))) gap-items)))
(defn all-or-sepearate-actions [attribute-labels on-update-shape {:keys [token selected-shapes]}]
(let [attributes (set (keys attribute-labels))
{:keys [all-selected? selected-pred shape-ids]} (attribute-actions token selected-shapes attributes)
all-action (let [props {:attributes 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 on-update-shape))))})
single-actions (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 attributes)
(wtc/apply-token))
selected? (wtc/unapply-token props)
:else (-> (assoc props :on-update-shape on-update-shape)
(wtc/apply-token)))]
(st/emit! event))}))
attribute-labels)]
(concat [all-action] single-actions)))
(defn sizing-attribute-actions [context-data] (defn sizing-attribute-actions [context-data]
(concat (concat
(all-or-sepearate-actions {:width "Width" (all-or-sepearate-actions {:width "Width"