0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00

Merge pull request #223 from tokens-studio/fic-spacing-crash-on-non-layout

Fix app crashing when spacing padding is applied to a shape without a…
This commit is contained in:
Akshay Gupta 2024-07-23 13:02:21 +05:30 committed by GitHub
commit dde8ab0680
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -138,19 +138,23 @@
:token-type-props updated-token-type-props
:selected-shapes selected-shapes})))
(defn update-layout-spacing [value shape-ids attributes]
(if-let [layout-gap (cond
(:row-gap attributes) {:row-gap value}
(:column-gap attributes) {:column-gap value})]
(st/emit! (dwsl/update-layout shape-ids {:layout-gap layout-gap}))
(st/emit! (dwsl/update-layout shape-ids {:layout-padding (zipmap attributes (repeat value))}))))
(defn update-layout-spacing [value selected-shapes attributes]
(doseq [shape selected-shapes]
(let [shape-id (:id shape)]
(if-let [layout-gap (cond
(:row-gap attributes) {:row-gap value}
(:column-gap attributes) {:column-gap value})]
(st/emit! (dwsl/update-layout [shape-id] {:layout-gap layout-gap}))
(when (:layout shape)
(st/emit! (dwsl/update-layout [shape-id] {:layout-padding (zipmap attributes (repeat value))})))))))
(defn apply-spacing-token [{:keys [token-id token-type-props selected-shapes]} attributes]
(let [token (dt/get-token-data-from-token-id token-id)
attributes (set attributes)
updated-token-type-props (assoc token-type-props
:on-update-shape update-layout-spacing
:on-update-shape (fn [value shape-ids]
(update-layout-spacing value selected-shapes attributes))
:attributes attributes)]
(wtc/on-apply-token {:token token
:token-type-props updated-token-type-props