mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Fix crash for applying spacing layout token
This commit is contained in:
parent
cf9ef2ae60
commit
1ba2acea7c
3 changed files with 25 additions and 14 deletions
|
@ -29,6 +29,8 @@
|
|||
[app.main.ui.icons :as i]
|
||||
[app.main.ui.workspace.tokens.core :as wtc]
|
||||
[app.main.ui.workspace.tokens.editable-select :refer [editable-select]]
|
||||
[app.main.ui.workspace.tokens.token :as wtt]
|
||||
[app.main.ui.workspace.tokens.changes :as wtch]
|
||||
[app.main.ui.workspace.tokens.token-types :as wtty]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.i18n :as i18n :refer [tr]]
|
||||
|
@ -985,18 +987,25 @@
|
|||
(mf/use-fn
|
||||
(mf/deps ids)
|
||||
(fn [type prop value]
|
||||
(let [token-value (wtc/maybe-resolve-token-value value)
|
||||
val (or token-value (mth/finite value 0))]
|
||||
(let [token-identifier (wtt/token-identifier value)
|
||||
val (or token-identifier (mth/finite value 0))
|
||||
on-update-shape wtch/update-layout-padding]
|
||||
(cond
|
||||
(and (= type :simple) (= prop :p1))
|
||||
(st/emit! (dwsl/update-layout ids {:layout-padding {:p1 val :p3 val}
|
||||
:applied-tokens {:padding-p1 (if token-value (:id value) nil)
|
||||
:padding-p3 (if token-value (:id value) nil)}}))
|
||||
(if token-identifier
|
||||
(st/emit! (wtch/apply-token {:shape-ids ids
|
||||
:attributes #{:p1 :p3}
|
||||
:token value
|
||||
:on-update-shape on-update-shape}))
|
||||
(st/emit! (on-update-shape value ids #{:p1 :p3})))
|
||||
|
||||
(and (= type :simple) (= prop :p2))
|
||||
(st/emit! (dwsl/update-layout ids {:layout-padding {:p2 val :p4 val}
|
||||
:applied-tokens {:padding-p2 (if token-value (:id value) nil)
|
||||
:padding-p4 (if token-value (:id value) nil)}}))
|
||||
(if token-identifier
|
||||
(st/emit! (wtch/apply-token {:shape-ids ids
|
||||
:attributes #{:p2 :p4}
|
||||
:token value
|
||||
:on-update-shape on-update-shape}))
|
||||
(st/emit! (on-update-shape value ids #{:p2 :p4})))
|
||||
|
||||
(some? prop)
|
||||
(st/emit! (dwsl/update-layout ids {:layout-padding {prop val}}))))))
|
||||
|
|
|
@ -136,6 +136,9 @@
|
|||
(zipmap (repeat value)))]
|
||||
{:layout-gap layout-gap}))
|
||||
|
||||
(defn update-layout-padding [value shape-ids attrs]
|
||||
(dwsl/update-layout shape-ids {:layout-padding (zipmap attrs (repeat value))}))
|
||||
|
||||
(defn update-layout-spacing [value shape-ids attributes]
|
||||
(ptk/reify ::update-layout-spacing
|
||||
ptk/WatchEvent
|
||||
|
|
|
@ -81,8 +81,7 @@
|
|||
(concat [all-action] single-actions)))
|
||||
|
||||
(defn spacing-attribute-actions [{:keys [token selected-shapes] :as context-data}]
|
||||
(let [on-update-shape (fn [resolved-value shape-ids attrs]
|
||||
(dwsl/update-layout shape-ids {:layout-padding (zipmap attrs (repeat resolved-value))}))
|
||||
(let [on-update-shape-padding wtch/update-layout-padding
|
||||
padding-attrs {:p1 "Top"
|
||||
:p2 "Right"
|
||||
:p3 "Bottom"
|
||||
|
@ -105,7 +104,7 @@
|
|||
:shape-ids shape-ids}]
|
||||
(if all-selected?
|
||||
(st/emit! (wtch/unapply-token props))
|
||||
(st/emit! (wtch/apply-token (assoc props :on-update-shape on-update-shape))))))}
|
||||
(st/emit! (wtch/apply-token (assoc props :on-update-shape on-update-shape-padding))))))}
|
||||
{:title "Horizontal"
|
||||
:selected? horizontal-padding-selected?
|
||||
:action (fn []
|
||||
|
@ -116,7 +115,7 @@
|
|||
horizontal-padding-selected? (wtch/apply-token (assoc props :attributes-to-remove horizontal-attributes))
|
||||
:else (wtch/apply-token (assoc props
|
||||
:attributes horizontal-attributes
|
||||
:on-update-shape on-update-shape)))]
|
||||
:on-update-shape on-update-shape-padding)))]
|
||||
(st/emit! event)))}
|
||||
{:title "Vertical"
|
||||
:selected? vertical-padding-selected?
|
||||
|
@ -128,7 +127,7 @@
|
|||
vertical-padding-selected? (wtch/apply-token (assoc props :attributes-to-remove vertical-attributes))
|
||||
:else (wtch/apply-token (assoc props
|
||||
:attributes vertical-attributes
|
||||
:on-update-shape on-update-shape)))]
|
||||
:on-update-shape on-update-shape-padding)))]
|
||||
(st/emit! event)))}]
|
||||
single-padding-items (->> padding-attrs
|
||||
(map (fn [[attr title]]
|
||||
|
@ -149,7 +148,7 @@
|
|||
all-selected? (-> (assoc props :attributes-to-remove all-padding-attrs)
|
||||
(wtch/apply-token))
|
||||
selected? (wtch/unapply-token props)
|
||||
:else (-> (assoc props :on-update-shape on-update-shape)
|
||||
:else (-> (assoc props :on-update-shape on-update-shape-padding)
|
||||
(wtch/apply-token)))]
|
||||
(st/emit! event))}))))
|
||||
gap-items (all-or-sepearate-actions {:attribute-labels {:column-gap "Column Gap"
|
||||
|
|
Loading…
Add table
Reference in a new issue