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