diff --git a/common/src/app/common/types/token.cljc b/common/src/app/common/types/token.cljc index fae1ec84eb..e961ddc282 100644 --- a/common/src/app/common/types/token.cljc +++ b/common/src/app/common/types/token.cljc @@ -129,6 +129,8 @@ (def font-size-keys (schema-keys schema:font-size)) +(def typography-keys (set/union font-size-keys)) + (def ^:private schema:number [:map [:rotation {:optional true} token-name-ref] @@ -144,7 +146,7 @@ spacing-keys dimensions-keys rotation-keys - font-size-keys + typography-keys number-keys)) (def ^:private schema:tokens diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index e6ca9e89b5..fe67cc1cd2 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -1498,26 +1498,29 @@ Will return a value that matches this schema: (defn get-tokens-of-unknown-type "Search for all tokens in the decoded json file that have a type that is not currently supported by Penpot. Returns a map token-path -> token type." - ([decoded-json] - (get-tokens-of-unknown-type decoded-json "" (get-json-format decoded-json))) - ([decoded-json parent-path json-format] - (let [type-key (if (= json-format :json-format/dtcg) "$type" "type")] - (reduce-kv - (fn [unknown-tokens k v] - (let [child-path (if (empty? parent-path) - (name k) - (str parent-path "." k))] - (if (and (map? v) - (not (contains? v type-key))) - (let [nested-unknown-tokens (get-tokens-of-unknown-type v child-path json-format)] - (merge unknown-tokens nested-unknown-tokens)) - (let [token-type-str (get v type-key) - token-type (cto/dtcg-token-type->token-type token-type-str)] - (if (and (not (some? token-type)) (some? token-type-str)) - (assoc unknown-tokens child-path token-type-str) - unknown-tokens))))) - nil - decoded-json)))) + [decoded-json {:keys [json-format parent-path process-token-type] + :or {json-format (get-json-format decoded-json) + parent-path "" + process-token-type identity} + :as opts}] + (let [type-key (if (= json-format :json-format/dtcg) "$type" "type")] + (reduce-kv + (fn [unknown-tokens k v] + (let [child-path (if (empty? parent-path) + (name k) + (str parent-path "." k))] + (if (and (map? v) + (not (contains? v type-key))) + (let [nested-unknown-tokens (get-tokens-of-unknown-type v (assoc opts :parent-path child-path))] + (merge unknown-tokens nested-unknown-tokens)) + (let [token-type-str (get v type-key) + token-type (-> (cto/dtcg-token-type->token-type token-type-str) + (process-token-type))] + (if (and (not (some? token-type)) (some? token-type-str)) + (assoc unknown-tokens child-path token-type-str) + unknown-tokens))))) + nil + decoded-json))) ;; === Serialization handlers for RPC API (transit) and database (fressian) diff --git a/frontend/src/app/main/data/workspace/tokens/import_export.cljs b/frontend/src/app/main/data/workspace/tokens/import_export.cljs index 52af367e36..2e321bd926 100644 --- a/frontend/src/app/main/data/workspace/tokens/import_export.cljs +++ b/frontend/src/app/main/data/workspace/tokens/import_export.cljs @@ -8,7 +8,9 @@ (:require [app.common.files.helpers :as cfh] [app.common.json :as json] + [app.common.types.token :as ctt] [app.common.types.tokens-lib :as ctob] + [app.config :as cf] [app.main.data.notifications :as ntf] [app.main.data.style-dictionary :as sd] [app.main.data.workspace.tokens.errors :as wte] @@ -60,7 +62,17 @@ [decoded-json file-name] (try {:tokens-lib (ctob/parse-decoded-json decoded-json file-name) - :unknown-tokens (ctob/get-tokens-of-unknown-type decoded-json)} + :unknown-tokens (ctob/get-tokens-of-unknown-type decoded-json + ;; Filter out FF token-types + {:process-token-type + (fn [dtcg-token-type] + (if (or + (and (not (contains? cf/flags :token-units)) + (= dtcg-token-type "number")) + (and (not (contains? cf/flags :token-typography-types)) + (contains? ctt/typography-keys dtcg-token-type))) + nil + dtcg-token-type))})} (catch js/Error e (let [err (or (extract-name-error e) (wte/error-ex-info :error.import/invalid-json-data decoded-json e))]