mirror of
https://github.com/penpot/penpot.git
synced 2025-02-01 11:59:17 -05:00
Reuse attribute keys from token schema
This commit is contained in:
parent
6bb4eec805
commit
28e6db9bb4
2 changed files with 22 additions and 5 deletions
|
@ -7,12 +7,27 @@
|
||||||
(ns app.common.types.token
|
(ns app.common.types.token
|
||||||
(:require
|
(:require
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.schema.registry :as sr]))
|
[app.common.schema.registry :as sr]
|
||||||
|
[malli.util :as mu]))
|
||||||
|
|
||||||
(defn merge-schemas [& schema-keys]
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; HELPERS
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defn merge-schemas
|
||||||
|
"Merge registered schemas."
|
||||||
|
[& schema-keys]
|
||||||
(let [schemas (map #(get @sr/registry %) schema-keys)]
|
(let [schemas (map #(get @sr/registry %) schema-keys)]
|
||||||
(reduce sm/merge schemas)))
|
(reduce sm/merge schemas)))
|
||||||
|
|
||||||
|
(defn schema-keys
|
||||||
|
"Converts registed map schema into set of keys."
|
||||||
|
[registered-schema]
|
||||||
|
(->> (get @sr/registry registered-schema)
|
||||||
|
(sm/schema)
|
||||||
|
(mu/keys)
|
||||||
|
(into #{})))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; SCHEMA
|
;; SCHEMA
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -49,6 +64,8 @@
|
||||||
[:r3 {:optional true} ::sm/uuid]
|
[:r3 {:optional true} ::sm/uuid]
|
||||||
[:r4 {:optional true} ::sm/uuid]])
|
[:r4 {:optional true} ::sm/uuid]])
|
||||||
|
|
||||||
|
(def border-radius-keys (schema-keys ::border-radius))
|
||||||
|
|
||||||
(sm/def! ::dimensions
|
(sm/def! ::dimensions
|
||||||
[:map
|
[:map
|
||||||
[:width {:optional true} ::sm/uuid]
|
[:width {:optional true} ::sm/uuid]
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
(:require
|
(:require
|
||||||
[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.main.data.tokens :as dt]
|
[app.common.types.token :as ctt]
|
||||||
[app.main.data.workspace.changes :as dch]))
|
[app.main.data.workspace.changes :as dch]))
|
||||||
|
|
||||||
;; Helpers ---------------------------------------------------------------------
|
;; Helpers ---------------------------------------------------------------------
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
(when (ctsr/has-radius? shape)
|
(when (ctsr/has-radius? shape)
|
||||||
(ctsr/set-radius-1 shape parsed-value)))
|
(ctsr/set-radius-1 shape parsed-value)))
|
||||||
{:reg-objects? true
|
{:reg-objects? true
|
||||||
:attrs [:rx :ry :r1 :r2 :r3 :r4]})))
|
:attrs ctt/border-radius-keys})))
|
||||||
|
|
||||||
;; Token types -----------------------------------------------------------------
|
;; Token types -----------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@
|
||||||
:modal {:key :tokens/boolean
|
:modal {:key :tokens/boolean
|
||||||
:fields [{:label "Boolean"}]}}]
|
:fields [{:label "Boolean"}]}}]
|
||||||
[:border-radius {:title "Border Radius"
|
[:border-radius {:title "Border Radius"
|
||||||
:attributes #{:rx :ry :r1 :r2 :r3 :r4}
|
:attributes ctt/border-radius-keys
|
||||||
:modal {:key :tokens/border-radius
|
:modal {:key :tokens/border-radius
|
||||||
:fields [{:label "Border Radius"
|
:fields [{:label "Border Radius"
|
||||||
:key :border-radius}]}
|
:key :border-radius}]}
|
||||||
|
|
Loading…
Add table
Reference in a new issue