mirror of
https://github.com/penpot/penpot.git
synced 2025-02-14 19:19:09 -05:00
Use token identifier
This commit is contained in:
parent
9ff4567955
commit
51a27c07ec
1 changed files with 8 additions and 7 deletions
|
@ -16,6 +16,7 @@
|
||||||
[app.main.data.workspace.shapes :as dwsh]
|
[app.main.data.workspace.shapes :as dwsh]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.ui.workspace.tokens.common :refer [workspace-shapes]]
|
[app.main.ui.workspace.tokens.common :refer [workspace-shapes]]
|
||||||
|
[app.main.ui.workspace.tokens.token :as wtt]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[clojure.data :as data]
|
[clojure.data :as data]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
|
@ -55,22 +56,22 @@
|
||||||
(first))]
|
(first))]
|
||||||
shape))
|
shape))
|
||||||
|
|
||||||
(defn token-from-attributes [token-id attributes]
|
(defn token-from-attributes [token attributes]
|
||||||
(->> (map (fn [attr] [attr token-id]) attributes)
|
(->> (map (fn [attr] [attr (wtt/token-identifier token)]) attributes)
|
||||||
(into {})))
|
(into {})))
|
||||||
|
|
||||||
(defn unapply-token-id [shape attributes]
|
(defn unapply-token-id [shape attributes]
|
||||||
(update shape :applied-tokens d/without-keys attributes))
|
(update shape :applied-tokens d/without-keys attributes))
|
||||||
|
|
||||||
(defn apply-token-id-to-attributes [{:keys [shape token-id attributes]}]
|
(defn apply-token-to-attributes [{:keys [shape token attributes]}]
|
||||||
(let [token (token-from-attributes token-id attributes)]
|
(let [token (token-from-attributes token attributes)]
|
||||||
(toggle-or-apply-token shape token)))
|
(toggle-or-apply-token shape token)))
|
||||||
|
|
||||||
(defn apply-token-to-shape
|
(defn apply-token-to-shape
|
||||||
[{:keys [shape token attributes] :as _props}]
|
[{:keys [shape token attributes] :as _props}]
|
||||||
(let [applied-tokens (apply-token-id-to-attributes {:shape shape
|
(let [applied-tokens (apply-token-to-attributes {:shape shape
|
||||||
:token-id (:id token)
|
:token token
|
||||||
:attributes attributes})]
|
:attributes attributes})]
|
||||||
(update shape :applied-tokens #(merge % applied-tokens))))
|
(update shape :applied-tokens #(merge % applied-tokens))))
|
||||||
|
|
||||||
(defn maybe-apply-token-to-shape
|
(defn maybe-apply-token-to-shape
|
||||||
|
|
Loading…
Add table
Reference in a new issue