mirror of
https://github.com/penpot/penpot.git
synced 2026-06-01 13:10:21 +00:00
💄 Change function names
This commit is contained in:
parent
4e1b940e04
commit
8e2a52af50
@ -51,7 +51,7 @@
|
|||||||
|
|
||||||
(defn update-shape-radius
|
(defn update-shape-radius
|
||||||
([value shape-ids attributes] (update-shape-radius value shape-ids attributes nil))
|
([value shape-ids attributes] (update-shape-radius value shape-ids attributes nil))
|
||||||
([value shape-ids attributes page-id] ; The attributes param is needed to have the same arity that other update functions
|
([value shape-ids attributes page-id]
|
||||||
(when (number? value)
|
(when (number? value)
|
||||||
(let [value (max 0 value)]
|
(let [value (max 0 value)]
|
||||||
(dwsh/update-shapes shape-ids
|
(dwsh/update-shapes shape-ids
|
||||||
|
|||||||
@ -54,7 +54,7 @@
|
|||||||
[app.plugins.register :as r]
|
[app.plugins.register :as r]
|
||||||
[app.plugins.ruler-guides :as rg]
|
[app.plugins.ruler-guides :as rg]
|
||||||
[app.plugins.text :as text]
|
[app.plugins.text :as text]
|
||||||
[app.plugins.tokens :refer [resolve-tokens translate-prop token-attr?]]
|
[app.plugins.tokens :refer [applied-tokens-plugin->applied-tokens token-attr-plugin->token-attr token-attr?]]
|
||||||
[app.plugins.utils :as u]
|
[app.plugins.utils :as u]
|
||||||
[app.util.http :as http]
|
[app.util.http :as http]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
@ -1298,15 +1298,15 @@
|
|||||||
{:this true
|
{:this true
|
||||||
:get
|
:get
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(let [tokens
|
(let [applied-tokens
|
||||||
(-> (u/locate-shape file-id page-id id)
|
(-> (u/locate-shape file-id page-id id)
|
||||||
(get :applied-tokens)
|
(get :applied-tokens)
|
||||||
(resolve-tokens))]
|
(applied-tokens-plugin->applied-tokens))]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [acc [prop name]]
|
(fn [acc [prop name]]
|
||||||
(obj/set! acc (json/write-camel-key prop) name))
|
(obj/set! acc (json/write-camel-key prop) name))
|
||||||
#js {}
|
#js {}
|
||||||
tokens)))}
|
applied-tokens)))}
|
||||||
|
|
||||||
:applyToken
|
:applyToken
|
||||||
{:enumerable false
|
{:enumerable false
|
||||||
@ -1315,7 +1315,7 @@
|
|||||||
[:maybe [:set [:and ::sm/keyword [:fn token-attr?]]]]]
|
[:maybe [:set [:and ::sm/keyword [:fn token-attr?]]]]]
|
||||||
:fn (fn [token attrs]
|
:fn (fn [token attrs]
|
||||||
(let [token (u/locate-token file-id (obj/get token "$set-id") (obj/get token "$id"))
|
(let [token (u/locate-token file-id (obj/get token "$set-id") (obj/get token "$id"))
|
||||||
kw-attrs (into #{} (map (comp translate-prop keyword) attrs))]
|
kw-attrs (into #{} (map token-attr-plugin->token-attr attrs))]
|
||||||
(if (some #(not (token-attr? %)) kw-attrs)
|
(if (some #(not (token-attr? %)) kw-attrs)
|
||||||
(u/display-not-valid :applyToken attrs)
|
(u/display-not-valid :applyToken attrs)
|
||||||
(st/emit!
|
(st/emit!
|
||||||
|
|||||||
@ -20,42 +20,47 @@
|
|||||||
[app.plugins.utils :as u]
|
[app.plugins.utils :as u]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[clojure.datafy :refer [datafy]]
|
[clojure.datafy :refer [datafy]]
|
||||||
[clojure.set :refer [map-invert]]
|
[clojure.set :refer [map-invert]]))
|
||||||
[cuerdas.core :as str]))
|
|
||||||
|
|
||||||
;; === Token
|
;; === Token
|
||||||
|
|
||||||
(def token-name-mapping
|
;; Give more semantic names to the shape attributes that tokens can be applied to
|
||||||
{:r1 :borderRadiusTopLeft
|
(def ^:private map:token-attr->token-attr-plugin
|
||||||
:r2 :borderRadiusTopRight
|
{:r1 :border-radius-top-left
|
||||||
:r3 :borderRadiusBottomRight
|
:r2 :border-radius-top-right
|
||||||
:r4 :borderRadiusBottomLeft
|
:r3 :border-radius-bottom-right
|
||||||
|
:r4 :border-radius-bottom-left
|
||||||
|
|
||||||
:p1 :paddingTopLeft
|
:p1 :padding-top-left
|
||||||
:p2 :paddingTopRight
|
:p2 :padding-top-right
|
||||||
:p3 :paddingBottomRight
|
:p3 :padding-bottom-right
|
||||||
:p4 :paddingBottomLeft
|
:p4 :padding-bottom-left
|
||||||
|
|
||||||
:m1 :marginTopLeft
|
:m1 :margin-top-left
|
||||||
:m2 :marginTopRight
|
:m2 :margin-top-right
|
||||||
:m3 :marginBottomRight
|
:m3 :margin-bottom-right
|
||||||
:m4 :marginBottomLeft})
|
:m4 :margin-bottom-left})
|
||||||
|
|
||||||
(def name-token-mapping
|
(def ^:private map:token-attr-plugin->token-attr
|
||||||
(map-invert token-name-mapping))
|
(map-invert map:token-attr->token-attr-plugin))
|
||||||
|
|
||||||
(defn resolve-prop
|
(defn token-attr->token-attr-plugin
|
||||||
[k]
|
[k]
|
||||||
(get token-name-mapping k k))
|
(get map:token-attr->token-attr-plugin k k))
|
||||||
|
|
||||||
(defn translate-prop
|
(defn token-attr-plugin->token-attr
|
||||||
[k]
|
[k]
|
||||||
(let [k (-> (str/camel k) keyword)]
|
(get map:token-attr-plugin->token-attr k k))
|
||||||
(get name-token-mapping k k)))
|
|
||||||
|
(defn applied-tokens-plugin->applied-tokens
|
||||||
|
[value]
|
||||||
|
(into {}
|
||||||
|
(map (fn [[k v]] [(token-attr->token-attr-plugin k) v]))
|
||||||
|
value))
|
||||||
|
|
||||||
(defn token-attr?
|
(defn token-attr?
|
||||||
[attr]
|
[attr]
|
||||||
(cto/token-attr? (translate-prop attr)))
|
(cto/token-attr? (token-attr-plugin->token-attr attr)))
|
||||||
|
|
||||||
(defn- apply-token-to-shapes
|
(defn- apply-token-to-shapes
|
||||||
[file-id set-id id shape-ids attrs]
|
[file-id set-id id shape-ids attrs]
|
||||||
@ -65,7 +70,7 @@
|
|||||||
(u/display-not-valid :applyToSelected attrs)
|
(u/display-not-valid :applyToSelected attrs)
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(dwta/toggle-token {:token token
|
(dwta/toggle-token {:token token
|
||||||
:attrs (into #{} (map translate-prop) attrs)
|
:attrs (into #{} (map token-attr-plugin->token-attr) attrs)
|
||||||
:shape-ids shape-ids
|
:shape-ids shape-ids
|
||||||
:expand-with-children false})))))
|
:expand-with-children false})))))
|
||||||
|
|
||||||
@ -77,13 +82,6 @@
|
|||||||
(ts/tokenscript-symbols->penpot-unit))]
|
(ts/tokenscript-symbols->penpot-unit))]
|
||||||
resolved-value))
|
resolved-value))
|
||||||
|
|
||||||
|
|
||||||
(defn resolve-tokens
|
|
||||||
[value]
|
|
||||||
(into {}
|
|
||||||
(map (fn [[k v]] [(resolve-prop k) v]))
|
|
||||||
value))
|
|
||||||
|
|
||||||
(defn token-proxy? [p]
|
(defn token-proxy? [p]
|
||||||
(obj/type-of? p "TokenProxy"))
|
(obj/type-of? p "TokenProxy"))
|
||||||
|
|
||||||
|
|||||||
@ -264,7 +264,7 @@ export class AppComponent {
|
|||||||
type: 'apply-token',
|
type: 'apply-token',
|
||||||
setId: this.currentSetId,
|
setId: this.currentSetId,
|
||||||
tokenId,
|
tokenId,
|
||||||
// properties: ['strokeColor'] // Uncomment to choose attribute to apply
|
// properties: ['borderRadiusTopRight'] // Uncomment to choose attribute to apply
|
||||||
}); // (incompatible attributes will have no effect)
|
}); // (incompatible attributes will have no effect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user