mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Add resolving function and move to core ns
This commit is contained in:
parent
68a201374c
commit
df48295903
2 changed files with 23 additions and 20 deletions
|
@ -9,6 +9,7 @@
|
|||
[app.common.data :as d :refer [ordered-map]]
|
||||
[app.common.types.shape.radius :as ctsr]
|
||||
[app.common.types.token :as ctt]
|
||||
[app.main.data.tokens :as dt]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.transforms :as dwt]
|
||||
[app.main.store :as st]))
|
||||
|
@ -29,8 +30,27 @@
|
|||
[token shapes token-attributes]
|
||||
(some #(token-applied? token % token-attributes) shapes))
|
||||
|
||||
(defn resolve-token-value [value]
|
||||
(if-let [int-or-double (d/parse-double value)]
|
||||
int-or-double
|
||||
(throw (ex-info (str "Implement token value resolve for " value) value))))
|
||||
|
||||
;; Update functions ------------------------------------------------------------
|
||||
|
||||
(defn on-apply-token [{:keys [token token-type-props selected-shapes] :as _props}]
|
||||
(let [{:keys [attributes on-apply on-update-shape]
|
||||
:or {on-apply dt/update-token-from-attributes}} token-type-props
|
||||
shape-ids (->> selected-shapes
|
||||
(eduction
|
||||
(remove #(tokens-applied? token % attributes))
|
||||
(map :id)))
|
||||
token-value (resolve-token-value (:value token))]
|
||||
(doseq [shape selected-shapes]
|
||||
(st/emit! (on-apply {:token-id (:id token)
|
||||
:shape-id (:id shape)
|
||||
:attributes attributes}))
|
||||
(on-update-shape token-value shape-ids))))
|
||||
|
||||
(defn update-shape-radius [value shape-ids]
|
||||
(st/emit!
|
||||
(dch/update-shapes shape-ids
|
||||
|
|
|
@ -7,12 +7,9 @@
|
|||
(ns app.main.ui.workspace.tokens.sidebar
|
||||
(:require-macros [app.main.style :as stl])
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.main.data.modal :as modal]
|
||||
[app.main.data.tokens :as dt]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.components.search-bar :refer [search-bar]]
|
||||
[app.main.ui.icons :as i]
|
||||
[app.main.ui.workspace.sidebar.assets.common :as cmm]
|
||||
[app.main.ui.workspace.tokens.common :refer [workspace-shapes]]
|
||||
|
@ -20,20 +17,6 @@
|
|||
[app.util.dom :as dom]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(defn on-apply-token [{:keys [token token-type-props selected-shapes] :as _props}]
|
||||
(let [{:keys [attributes on-apply on-update-shape]
|
||||
:or {on-apply dt/update-token-from-attributes}} token-type-props
|
||||
shape-ids (->> selected-shapes
|
||||
(eduction
|
||||
(remove #(tokens-applied? token % attributes))
|
||||
(map :id)))
|
||||
token-value (d/parse-integer (:value token))]
|
||||
(doseq [shape selected-shapes]
|
||||
(st/emit! (on-apply {:token-id (:id token)
|
||||
:shape-id (:id shape)
|
||||
:attributes attributes}))
|
||||
(on-update-shape token-value shape-ids))))
|
||||
|
||||
(mf/defc token-pill
|
||||
{::mf/wrap-props false}
|
||||
[{:keys [on-click token highlighted?]}]
|
||||
|
@ -66,9 +49,9 @@
|
|||
(mf/deps selected-shapes token-type-props)
|
||||
(fn [event token]
|
||||
(dom/stop-propagation event)
|
||||
(on-apply-token {:token token
|
||||
:token-type-props token-type-props
|
||||
:selected-shapes selected-shapes})))
|
||||
(wtc/on-apply-token {:token token
|
||||
:token-type-props token-type-props
|
||||
:selected-shapes selected-shapes})))
|
||||
tokens-count (count tokens)]
|
||||
[:div {:on-click on-toggle-open-click}
|
||||
[:& cmm/asset-section {:file-id (:id file)
|
||||
|
|
Loading…
Add table
Reference in a new issue