Compare commits

...

3 Commits

Author SHA1 Message Date
Andrés Moya
a23ca6a1cb 🐛 Fix applied tokens reading in shape proxy 2026-02-12 17:14:16 +01:00
Andrés Moya
c626634610 🐛 Detect empty font-family 2026-02-12 16:04:23 +01:00
Andrés Moya
11eedd0368 🐛 Patch alternative ways of applying tokens to shapes 2026-02-12 16:01:55 +01:00
5 changed files with 21 additions and 9 deletions

View File

@@ -35,7 +35,7 @@
[::sm/text {:error/fn token-value-empty-fn}])
(def schema:token-value-font-family
[:vector :string])
[:vector ::sm/text])
(def schema:token-value-typography-map
[:map

View File

@@ -11,6 +11,7 @@
[app.common.files.helpers :as cfh]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.json :as json]
[app.common.path-names :as cpn]
[app.common.record :as crc]
[app.common.schema :as sm]
@@ -1295,7 +1296,7 @@
(get :applied-tokens))]
(reduce
(fn [acc [prop name]]
(obj/set! acc (d/name prop) name))
(obj/set! acc (json/write-camel-key prop) name))
#js {}
tokens)))}

View File

@@ -16,7 +16,7 @@
[app.main.data.workspace.tokens.application :as dwta]
[app.main.data.workspace.tokens.library-edit :as dwtl]
[app.main.store :as st]
[app.plugins.shape :as shape]
;; [app.plugins.shape :as shape]
[app.plugins.utils :as u]
[app.util.object :as obj]
[beicon.v2.core :as rx]
@@ -113,13 +113,17 @@
:applyToShapes
{:schema [:tuple
[:vector [:fn shape/shape-proxy?]]
[:maybe [:set ::sm/keyword]]]
;; FIXME: the schema decoder is interpreting the array of shape-proxys and converting
;; them to plain maps. For now we adapt the schema to accept it, but the decoder
;; should be fixed to keep the original proxy objects coming from the plugin.
;; [:vector [:fn shape/shape-proxy?]]
[:vector [:map [:id ::sm/uuid]]]
[:maybe [:set [:set [:and ::sm/keyword [:fn cto/token-attr?]]]]]]
:fn (fn [shapes attrs]
(apply-token-to-shapes file-id set-id id (map :id shapes) attrs))}
:applyToSelected
{:schema [:tuple [:maybe [:set ::sm/keyword]]]
{:schema [:tuple [:maybe [:set [:and ::sm/keyword [:fn cto/token-attr?]]]]]
:fn (fn [attrs]
(let [selected (get-in @st/state [:workspace-local :selected])]
(apply-token-to-shapes file-id set-id id selected attrs)))}))

View File

@@ -251,7 +251,14 @@ function applyToken(
token.applyToSelected(properties);
}
// Alternatve way
// Alternative way
//
// const selection = penpot.selection;
// if (token && selection) {
// token.applyToShapes(selection, properties);
// }
// Other alternative way
//
// const selection = penpot.selection;
// if (token && selection) {

View File

@@ -3744,7 +3744,7 @@ export interface ShapeBase extends PluginData {
* and the value set to the attributes will depend on which sets are active
* (and will change if different sets or themes are activated later).
*/
readonly tokens: { [property: string]: string };
readonly tokens: { [property in TokenProperty]: string };
/**
* @return Returns true if the current shape is inside a component instance
@@ -5221,7 +5221,7 @@ type TokenDimensionProps =
| 'y'
// Stroke width
| 'stroke-width';
| 'strokeWidth';
/**
* The properties that a FontFamilies token can be applied to.