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

Fix actions

This commit is contained in:
Florian Schroedl 2024-07-22 17:07:42 +02:00
parent f731a30f81
commit 2836ff2693

View file

@ -215,38 +215,34 @@
all-attributes #{:r1 :r2 :r3 :r4} all-attributes #{:r1 :r2 :r3 :r4}
ids-by-attributes (wtt/shapes-ids-by-applied-attributes token selected-shapes all-attributes) ids-by-attributes (wtt/shapes-ids-by-applied-attributes token selected-shapes all-attributes)
shape-ids (into #{} (map :id selected-shapes)) shape-ids (into #{} (map :id selected-shapes))
all? (wtt/shapes-applied-all? ids-by-attributes shape-ids all-attributes) all-selected? (wtt/shapes-applied-all? ids-by-attributes shape-ids all-attributes)
selected-pred #(and
(not all?)
(seq (% ids-by-attributes)))
single-attributes (->> {:r1 "Top Left" single-attributes (->> {:r1 "Top Left"
:r2 "Top Right" :r2 "Top Right"
:r3 "Bottom Left" :r3 "Bottom Left"
:r4 "Bottom Right"} :r4 "Bottom Right"}
(map (fn [[attr title]] (map (fn [[attr title]]
(let [selected? (selected-pred attr)] (let [selected? (seq (attr ids-by-attributes))]
{:title title {:title title
:selected? selected? :selected? (and (not all-selected?) selected?)
:action (if selected? :action #(let [props {:attributes #{attr}
(st/emit! (wtc/unapply-token {:token token :token token
:attributes #{attr} :shape-ids shape-ids}
:shape-ids shape-ids})) event (cond
(st/emit! (wtc/apply-token {:token token all-selected? (-> (assoc props :attributes-to-remove #{:r1 :r2 :r3 :r4 :rx :ry})
:attributes #{attr} (wtc/apply-token))
:on-update-shape wtc/update-shape-radius-single-corner selected? (wtc/unapply-token props)
:shape-ids shape-ids})))}))))] :else (-> (assoc props :on-update-shape wtc/update-shape-radius-single-corner)
(concat (wtc/apply-token)))]
[{:title "All" (st/emit! event))}))))
:selected? all? all-attribute (let [props {:attributes all-attributes
:action #(if all? :token token
(st/emit! (wtc/unapply-token {:token token :shape-ids shape-ids}]
:attributes all-attributes {:title "All"
:shape-ids shape-ids})) :selected? all-selected?
(st/emit! (wtc/apply-token {:token token :action #(if all-selected?
:attributes all-attributes (st/emit! (wtc/unapply-token props))
:on-update-shape wtc/update-shape-radius-all (st/emit! (wtc/apply-token (assoc props :on-update-shape wtc/update-shape-radius-all))))})]
:shape-ids shape-ids})))}] (concat [all-attribute] single-attributes)))
single-attributes)))
(defn shape-attribute-actions [{:keys [token-id token-type selected-shapes] :as context-data}] (defn shape-attribute-actions [{:keys [token-id token-type selected-shapes] :as context-data}]
(let [attributes->actions (fn [update-fn coll] (let [attributes->actions (fn [update-fn coll]