mirror of
https://github.com/penpot/penpot.git
synced 2025-06-04 03:21:38 +02:00
🐛 Fix stroke width validation (#6124)
This commit is contained in:
parent
f98009ec54
commit
b3a3cca9fe
5 changed files with 49 additions and 5 deletions
|
@ -44,6 +44,10 @@
|
||||||
{:error/code :error.style-dictionary/invalid-token-value-opacity
|
{:error/code :error.style-dictionary/invalid-token-value-opacity
|
||||||
:error/fn #(str/join "\n" [(str (tr "workspace.token.invalid-value" %) ".") (tr "workspace.token.opacity-range")])}
|
:error/fn #(str/join "\n" [(str (tr "workspace.token.invalid-value" %) ".") (tr "workspace.token.opacity-range")])}
|
||||||
|
|
||||||
|
:error.style-dictionary/invalid-token-value-stroke-width
|
||||||
|
{:error/code :error.style-dictionary/invalid-token-value-stroke-width
|
||||||
|
:error/fn #(str/join "\n" [(str (tr "workspace.token.invalid-value" %) ".") (tr "workspace.token.stroke-width-range")])}
|
||||||
|
|
||||||
:error/unknown
|
:error/unknown
|
||||||
{:error/code :error/unknown
|
{:error/code :error/unknown
|
||||||
:error/fn #(tr "labels.unknown-error")}})
|
:error/fn #(tr "labels.unknown-error")}})
|
||||||
|
|
|
@ -87,8 +87,34 @@
|
||||||
(and (not has-references?) out-of-scope)
|
(and (not has-references?) out-of-scope)
|
||||||
{:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value-opacity value)]}
|
{:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value-opacity value)]}
|
||||||
|
|
||||||
(and has-references? out-of-scope)
|
(and has-references? out-of-scope parsed-value)
|
||||||
(assoc parsed-value :warnings [(wtw/warning-with-value :warning.style-dictionary/invalid-referenced-token-value value)])
|
(assoc parsed-value :warnings [(wtw/warning-with-value :warning.style-dictionary/invalid-referenced-token-value-opacity value)])
|
||||||
|
|
||||||
|
:else {:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value value)]})))
|
||||||
|
|
||||||
|
|
||||||
|
(defn- parse-sd-token-stroke-width-value
|
||||||
|
"Parses `value` of a dimensions `sd-token` into a map like `{:value 1 :unit \"px\"}`.
|
||||||
|
If the `value` is not parseable and/or has missing references returns a map with `:errors`.
|
||||||
|
If the `value` is parseable but is out of range returns a map with `warnings`."
|
||||||
|
[value has-references?]
|
||||||
|
|
||||||
|
(let [parsed-value (wtt/parse-token-value value)
|
||||||
|
out-of-scope (< (:value parsed-value) 0)
|
||||||
|
references (seq (ctob/find-token-value-references value))]
|
||||||
|
(cond
|
||||||
|
(and parsed-value (not out-of-scope))
|
||||||
|
parsed-value
|
||||||
|
|
||||||
|
references
|
||||||
|
{:errors [(wte/error-with-value :error.style-dictionary/missing-reference references)]
|
||||||
|
:references references}
|
||||||
|
|
||||||
|
(and (not has-references?) out-of-scope)
|
||||||
|
{:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value-stroke-width value)]}
|
||||||
|
|
||||||
|
(and has-references? out-of-scope parsed-value)
|
||||||
|
(assoc parsed-value :warnings [(wtw/warning-with-value :warning.style-dictionary/invalid-referenced-token-value-stroke-width value)])
|
||||||
|
|
||||||
:else {:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value value)]})))
|
:else {:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value value)]})))
|
||||||
|
|
||||||
|
@ -132,6 +158,7 @@
|
||||||
parsed-token-value (case (:type origin-token)
|
parsed-token-value (case (:type origin-token)
|
||||||
:color (parse-sd-token-color-value value)
|
:color (parse-sd-token-color-value value)
|
||||||
:opacity (parse-sd-token-opacity-value value has-references?)
|
:opacity (parse-sd-token-opacity-value value has-references?)
|
||||||
|
:stroke-width (parse-sd-token-stroke-width-value value has-references?)
|
||||||
(parse-sd-token-numeric-value value))
|
(parse-sd-token-numeric-value value))
|
||||||
output-token (cond (:errors parsed-token-value)
|
output-token (cond (:errors parsed-token-value)
|
||||||
(merge origin-token parsed-token-value)
|
(merge origin-token parsed-token-value)
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
(ns app.main.ui.workspace.tokens.warnings
|
(ns app.main.ui.workspace.tokens.warnings
|
||||||
(:require
|
(:require
|
||||||
|
[app.util.i18n :refer [tr]]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
(def warning-codes
|
(def warning-codes
|
||||||
{:warning.style-dictionary/invalid-referenced-token-value
|
{:warning.style-dictionary/invalid-referenced-token-value-opacity
|
||||||
{:warning/code :warning.style-dictionary/invalid-referenced-token-value
|
{:warning/code :warning.style-dictionary/invalid-referenced-token-value-opacity
|
||||||
:warning/fn (fn [value] (str/join "\n" [(str "Resolved value " value ".") "Opacity must be between 0 and 100% or 0 and 1 (e.g. 50% or 0.5)"]))}
|
:warning/fn (fn [value] (str/join "\n" [(str (tr "workspace.token.resolved-value" value) ".") (tr "workspace.token.opacity-range")]))}
|
||||||
|
|
||||||
|
:warning.style-dictionary/invalid-referenced-token-value-stroke-width
|
||||||
|
{:warning/code :warning.style-dictionary/invalid-referenced-token-value-stroke-width
|
||||||
|
:warning/fn (fn [value] (str/join "\n" [(str (tr "workspace.token.resolved-value" value) ".") (tr "workspace.token.stroke-width-range")]))}
|
||||||
|
|
||||||
:warning/unknown
|
:warning/unknown
|
||||||
{:warning/code :warning/unknown
|
{:warning/code :warning/unknown
|
||||||
|
|
|
@ -6675,6 +6675,10 @@ msgstr "Invalid token value: %s"
|
||||||
msgid "workspace.token.opacity-range"
|
msgid "workspace.token.opacity-range"
|
||||||
msgstr "Opacity must be between 0 and 100% or 0 and 1 (e.g. 50% or 0.5)."
|
msgstr "Opacity must be between 0 and 100% or 0 and 1 (e.g. 50% or 0.5)."
|
||||||
|
|
||||||
|
#: src/app/main/ui/workspace/tokens/errors.cljs
|
||||||
|
msgid "workspace.token.stroke-width-range"
|
||||||
|
msgstr "Stroke width must be between equal or bigger than 0."
|
||||||
|
|
||||||
#: src/app/main/ui/workspace/tokens/modals/themes.cljs:179
|
#: src/app/main/ui/workspace/tokens/modals/themes.cljs:179
|
||||||
msgid "workspace.token.label.group"
|
msgid "workspace.token.label.group"
|
||||||
msgstr "Group"
|
msgstr "Group"
|
||||||
|
|
|
@ -6677,6 +6677,10 @@ msgstr "Valor de token no válido: %s"
|
||||||
msgid "workspace.token.opacity-range"
|
msgid "workspace.token.opacity-range"
|
||||||
msgstr "La opacidad debe estar entre 0 y 100% o 0 y 1 (p.e. 50% o 0.5)."
|
msgstr "La opacidad debe estar entre 0 y 100% o 0 y 1 (p.e. 50% o 0.5)."
|
||||||
|
|
||||||
|
#: src/app/main/ui/workspace/tokens/errors.cljs
|
||||||
|
msgid "workspace.token.stroke-width-range"
|
||||||
|
msgstr "Stroke width debe ser mayor o igual a 0."
|
||||||
|
|
||||||
#: src/app/main/ui/workspace/tokens/modals/themes.cljs:179
|
#: src/app/main/ui/workspace/tokens/modals/themes.cljs:179
|
||||||
msgid "workspace.token.label.group"
|
msgid "workspace.token.label.group"
|
||||||
msgstr "Grupo"
|
msgstr "Grupo"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue