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,36 +137,33 @@
: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) :token token
all-gap (let [props {:attributes all-gap-attrs :shape-ids shape-ids}]
:token token {:title "All"
:shape-ids shape-ids}] :selected? all-selected?
[{:title "All" :action #(if all-selected?
:selected? all-selected? (st/emit! (wtc/unapply-token props))
:action #(if all-selected? (st/emit! (wtc/apply-token (assoc props :on-update-shape on-update-shape))))})
(st/emit! (wtc/unapply-token props)) single-actions (map (fn [[attr title]]
(st/emit! (wtc/apply-token (assoc props :on-update-shape on-update-shape))))}]) (let [selected? (selected-pred attr)]
single-gap (->> gap-attrs {:title title
(map (fn [[attr title]] :selected? (and (not all-selected?) selected?)
(let [selected? (selected-pred attr)] :action #(let [props {:attributes #{attr}
{:title title :token token
:selected? (and (not all-selected?) selected?) :shape-ids shape-ids}
:action #(let [props {:attributes #{attr} event (cond
:token token all-selected? (-> (assoc props :attributes-to-remove attributes)
:shape-ids shape-ids} (wtc/apply-token))
event (cond selected? (wtc/unapply-token props)
all-selected? (-> (assoc props :attributes-to-remove #{:row-gap :column-gap}) :else (-> (assoc props :on-update-shape on-update-shape)
(wtc/apply-token)) (wtc/apply-token)))]
selected? (wtc/unapply-token props) (st/emit! event))}))
:else (-> (assoc props :on-update-shape on-update-shape) attribute-labels)]
(wtc/apply-token)))] (concat [all-action] single-actions)))
(st/emit! event))})))
(into))]
(concat all-gap single-gap)))
(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"