mirror of
https://github.com/penpot/penpot.git
synced 2025-02-01 11:59:17 -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.data :as d :refer [ordered-map]]
|
||||||
[app.common.types.shape.radius :as ctsr]
|
[app.common.types.shape.radius :as ctsr]
|
||||||
[app.common.types.token :as ctt]
|
[app.common.types.token :as ctt]
|
||||||
|
[app.main.data.tokens :as dt]
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
[app.main.data.workspace.transforms :as dwt]
|
[app.main.data.workspace.transforms :as dwt]
|
||||||
[app.main.store :as st]))
|
[app.main.store :as st]))
|
||||||
|
@ -29,8 +30,27 @@
|
||||||
[token shapes token-attributes]
|
[token shapes token-attributes]
|
||||||
(some #(token-applied? token % token-attributes) shapes))
|
(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 ------------------------------------------------------------
|
;; 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]
|
(defn update-shape-radius [value shape-ids]
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(dch/update-shapes shape-ids
|
(dch/update-shapes shape-ids
|
||||||
|
|
|
@ -7,12 +7,9 @@
|
||||||
(ns app.main.ui.workspace.tokens.sidebar
|
(ns app.main.ui.workspace.tokens.sidebar
|
||||||
(:require-macros [app.main.style :as stl])
|
(:require-macros [app.main.style :as stl])
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
|
||||||
[app.main.data.modal :as modal]
|
[app.main.data.modal :as modal]
|
||||||
[app.main.data.tokens :as dt]
|
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.ui.components.search-bar :refer [search-bar]]
|
|
||||||
[app.main.ui.icons :as i]
|
[app.main.ui.icons :as i]
|
||||||
[app.main.ui.workspace.sidebar.assets.common :as cmm]
|
[app.main.ui.workspace.sidebar.assets.common :as cmm]
|
||||||
[app.main.ui.workspace.tokens.common :refer [workspace-shapes]]
|
[app.main.ui.workspace.tokens.common :refer [workspace-shapes]]
|
||||||
|
@ -20,20 +17,6 @@
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[rumext.v2 :as mf]))
|
[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/defc token-pill
|
||||||
{::mf/wrap-props false}
|
{::mf/wrap-props false}
|
||||||
[{:keys [on-click token highlighted?]}]
|
[{:keys [on-click token highlighted?]}]
|
||||||
|
@ -66,7 +49,7 @@
|
||||||
(mf/deps selected-shapes token-type-props)
|
(mf/deps selected-shapes token-type-props)
|
||||||
(fn [event token]
|
(fn [event token]
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(on-apply-token {:token token
|
(wtc/on-apply-token {:token token
|
||||||
:token-type-props token-type-props
|
:token-type-props token-type-props
|
||||||
:selected-shapes selected-shapes})))
|
:selected-shapes selected-shapes})))
|
||||||
tokens-count (count tokens)]
|
tokens-count (count tokens)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue