mirror of
https://github.com/penpot/penpot.git
synced 2025-05-30 10:46:10 +02:00
Move token-applied? to token ns
This commit is contained in:
parent
224b656d57
commit
e38a943ce0
4 changed files with 21 additions and 19 deletions
|
@ -22,6 +22,7 @@
|
||||||
[app.main.ui.components.dropdown :refer [dropdown]]
|
[app.main.ui.components.dropdown :refer [dropdown]]
|
||||||
[app.main.ui.icons :as i]
|
[app.main.ui.icons :as i]
|
||||||
[app.main.ui.workspace.tokens.core :as wtc]
|
[app.main.ui.workspace.tokens.core :as wtc]
|
||||||
|
[app.main.ui.workspace.tokens.token :as wtt]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.timers :as timers]
|
[app.util.timers :as timers]
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
|
@ -212,7 +213,7 @@
|
||||||
(defn additional-actions [{:keys [token-id token-type selected-shapes] :as context-data}]
|
(defn additional-actions [{:keys [token-id token-type selected-shapes] :as context-data}]
|
||||||
(let [attributes->actions (fn [update-fn coll]
|
(let [attributes->actions (fn [update-fn coll]
|
||||||
(for [{:keys [attributes] :as item} 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
|
(assoc item
|
||||||
:action #(update-fn context-data attributes)
|
:action #(update-fn context-data attributes)
|
||||||
:selected? selected?))))]
|
:selected? selected?))))]
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
[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.libs.file-builder :as fb]
|
|
||||||
[app.main.data.tokens :as dt]
|
[app.main.data.tokens :as dt]
|
||||||
[app.main.data.workspace :as udw]
|
[app.main.data.workspace :as udw]
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
@ -18,6 +17,7 @@
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.ui.workspace.tokens.style-dictionary :as sd]
|
[app.main.ui.workspace.tokens.style-dictionary :as sd]
|
||||||
|
[app.main.ui.workspace.tokens.token :as wtt]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.webapi :as wapi]
|
[app.util.webapi :as wapi]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
|
@ -25,20 +25,6 @@
|
||||||
|
|
||||||
;; Helpers ---------------------------------------------------------------------
|
;; 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}]
|
(defn resolve-token-value [{:keys [value resolved-value] :as token}]
|
||||||
(or
|
(or
|
||||||
resolved-value
|
resolved-value
|
||||||
|
@ -74,7 +60,7 @@
|
||||||
(->> (tokens-name-map tokens)
|
(->> (tokens-name-map tokens)
|
||||||
(map (fn [[_k {:keys [name] :as item}]]
|
(map (fn [[_k {:keys [name] :as item}]]
|
||||||
(cond-> (assoc item :label name)
|
(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 ------------------------------------------------------------
|
;; Update functions ------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -83,7 +69,7 @@
|
||||||
:or {on-apply dt/update-token-from-attributes}} token-type-props
|
:or {on-apply dt/update-token-from-attributes}} token-type-props
|
||||||
shape-ids (->> selected-shapes
|
shape-ids (->> selected-shapes
|
||||||
(eduction
|
(eduction
|
||||||
(remove #(tokens-applied? token % attributes))
|
(remove #(wtt/tokens-applied? token % attributes))
|
||||||
(map :id)))]
|
(map :id)))]
|
||||||
(p/let [sd-tokens (sd/resolve-workspace-tokens+ {:debug? true})]
|
(p/let [sd-tokens (sd/resolve-workspace-tokens+ {:debug? true})]
|
||||||
(let [resolved-token (get sd-tokens (:id token))
|
(let [resolved-token (get sd-tokens (:id token))
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
[app.main.ui.workspace.sidebar.assets.common :as cmm]
|
[app.main.ui.workspace.sidebar.assets.common :as cmm]
|
||||||
[app.main.ui.workspace.tokens.core :as wtc]
|
[app.main.ui.workspace.tokens.core :as wtc]
|
||||||
[app.main.ui.workspace.tokens.style-dictionary :as sd]
|
[app.main.ui.workspace.tokens.style-dictionary :as sd]
|
||||||
|
[app.main.ui.workspace.tokens.token :as wtt]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
|
@ -121,7 +122,7 @@
|
||||||
[:& token-pill
|
[:& token-pill
|
||||||
{:key (:id token)
|
{:key (:id token)
|
||||||
:token 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-click #(on-token-pill-click % token)
|
||||||
:on-context-menu #(on-context-menu % token)}])]])]]))
|
:on-context-menu #(on-context-menu % token)}])]])]]))
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,20 @@
|
||||||
(:require
|
(:require
|
||||||
[cuerdas.core :as str]))
|
[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
|
(defn token-name->path
|
||||||
"Splits token-name into a path vector split by `.` characters.
|
"Splits token-name into a path vector split by `.` characters.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue