diff --git a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs index 0b90a0e50..6d4c0e073 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -22,6 +22,7 @@ [app.main.ui.components.dropdown :refer [dropdown]] [app.main.ui.icons :as i] [app.main.ui.workspace.tokens.core :as wtc] + [app.main.ui.workspace.tokens.token :as wtt] [app.util.dom :as dom] [app.util.timers :as timers] [clojure.set :as set] @@ -212,7 +213,7 @@ (defn additional-actions [{:keys [token-id token-type selected-shapes] :as context-data}] (let [attributes->actions (fn [update-fn coll] (for [{:keys [attributes] :as item} coll] - (let [selected? (wtc/tokens-applied? {:id token-id} selected-shapes attributes)] + (let [selected? (wtt/tokens-applied? {:id token-id} selected-shapes attributes)] (assoc item :action #(update-fn context-data attributes) :selected? selected?))))] diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index 682cefde4..b88adac6d 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -9,7 +9,6 @@ [app.common.data :as d :refer [ordered-map]] [app.common.types.shape.radius :as ctsr] [app.common.types.token :as ctt] - [app.libs.file-builder :as fb] [app.main.data.tokens :as dt] [app.main.data.workspace :as udw] [app.main.data.workspace.changes :as dch] @@ -18,6 +17,7 @@ [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.workspace.tokens.style-dictionary :as sd] + [app.main.ui.workspace.tokens.token :as wtt] [app.util.dom :as dom] [app.util.webapi :as wapi] [cuerdas.core :as str] @@ -25,20 +25,6 @@ ;; Helpers --------------------------------------------------------------------- -(defn token-applied? - "Test if `token` is applied to a `shape` with the given `token-attributes`." - [token shape token-attributes] - (let [{:keys [id]} token - applied-tokens (get shape :applied-tokens {})] - (some (fn [attr] - (= (get applied-tokens attr) id)) - token-attributes))) - -(defn tokens-applied? - "Test if `token` is applied to to any of `shapes` with the given `token-attributes`." - [token shapes token-attributes] - (some #(token-applied? token % token-attributes) shapes)) - (defn resolve-token-value [{:keys [value resolved-value] :as token}] (or resolved-value @@ -74,7 +60,7 @@ (->> (tokens-name-map tokens) (map (fn [[_k {:keys [name] :as item}]] (cond-> (assoc item :label name) - (token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true)))))) + (wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true)))))) ;; Update functions ------------------------------------------------------------ @@ -83,7 +69,7 @@ :or {on-apply dt/update-token-from-attributes}} token-type-props shape-ids (->> selected-shapes (eduction - (remove #(tokens-applied? token % attributes)) + (remove #(wtt/tokens-applied? token % attributes)) (map :id)))] (p/let [sd-tokens (sd/resolve-workspace-tokens+ {:debug? true})] (let [resolved-token (get sd-tokens (:id token)) diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 3ab3519e0..3b25a7d78 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -16,6 +16,7 @@ [app.main.ui.workspace.sidebar.assets.common :as cmm] [app.main.ui.workspace.tokens.core :as wtc] [app.main.ui.workspace.tokens.style-dictionary :as sd] + [app.main.ui.workspace.tokens.token :as wtt] [app.util.dom :as dom] [cuerdas.core :as str] [okulary.core :as l] @@ -121,7 +122,7 @@ [:& token-pill {:key (:id token) :token token - :highlighted? (wtc/tokens-applied? token selected-shapes attributes) + :highlighted? (wtt/tokens-applied? token selected-shapes attributes) :on-click #(on-token-pill-click % token) :on-context-menu #(on-context-menu % token)}])]])]])) diff --git a/frontend/src/app/main/ui/workspace/tokens/token.cljs b/frontend/src/app/main/ui/workspace/tokens/token.cljs index ce288113d..8a742b4d5 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token.cljs @@ -2,6 +2,20 @@ (:require [cuerdas.core :as str])) +(defn token-applied? + "Test if `token` is applied to a `shape` with the given `token-attributes`." + [token shape token-attributes] + (let [{:keys [id]} token + applied-tokens (get shape :applied-tokens {})] + (some (fn [attr] + (= (get applied-tokens attr) id)) + token-attributes))) + +(defn tokens-applied? + "Test if `token` is applied to to any of `shapes` with the given `token-attributes`." + [token shapes token-attributes] + (some #(token-applied? token % token-attributes) shapes)) + (defn token-name->path "Splits token-name into a path vector split by `.` characters.