0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-10 14:51:37 -05:00

Extract singular token applied predicate

This commit is contained in:
Florian Schroedl 2024-07-05 14:13:14 +02:00
parent bc1f27eac9
commit 5a358e3d0c

View file

@ -18,17 +18,24 @@
applied-tokens) applied-tokens)
(into {})))) (into {}))))
(defn token-attribute-applied?
"Test if `token` is applied to a `shape` on single `token-attribute`."
[token shape token-attribute]
(when-let [id (get-in shape [:applied-tokens token-attribute])]
(= (:id token) id)))
(defn token-applied? (defn token-applied?
"Test if `token` is applied to a `shape` with the given `token-attributes`." "Test if `token` is applied to a `shape` with at least one of the one of the given `token-attributes`."
[token shape token-attributes] [token shape token-attributes]
(let [{:keys [id]} token (some #(token-attribute-applied? token shape %) token-attributes))
applied-tokens (get shape :applied-tokens {})]
(some (fn [attr]
(= (get applied-tokens attr) id))
token-attributes)))
(defn shapes-token-applied? (defn shapes-token-applied?
"Test if `token` is applied to to any of `shapes` with the given `token-attributes`." "Test if `token` is applied to to any of `shapes` with at least one of the one of the given `token-attributes`."
[token shapes token-attributes]
(some #(token-applied? token % token-attributes) shapes))
(defn shapes-token-applied-all?
"Test if `token` is applied to to any of `shapes` with at least one of the one of the given `token-attributes`."
[token shapes token-attributes] [token shapes token-attributes]
(some #(token-applied? token % token-attributes) shapes)) (some #(token-applied? token % token-attributes) shapes))