From 3cdbc27de9cdd440042b5efad2528e3773161a7c Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 28 Aug 2025 13:43:17 +0200 Subject: [PATCH] :sparkles: Unapply font-weight token when changing font-family --- common/src/app/common/logic/shapes.cljc | 15 ++++++++++----- common/src/app/common/types/shape/token.cljc | 7 +++++++ 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 common/src/app/common/types/shape/token.cljc diff --git a/common/src/app/common/logic/shapes.cljc b/common/src/app/common/logic/shapes.cljc index a1b981a5b4..60913d56f5 100644 --- a/common/src/app/common/logic/shapes.cljc +++ b/common/src/app/common/logic/shapes.cljc @@ -17,12 +17,13 @@ [app.common.types.pages-list :as ctpl] [app.common.types.shape.interactions :as ctsi] [app.common.types.shape.layout :as ctl] + [app.common.types.shape.token :as ctst] [app.common.types.text :as ctt] [app.common.types.token :as cto] [app.common.uuid :as uuid] [clojure.set :as set])) -(def text-typography-attrs (set ctt/text-typography-attrs)) +(def text-typography-style-attrs (set ctt/text-typography-attrs)) (defn- generate-unapply-tokens "When updating attributes that have a token applied, we must unapply it, because the value @@ -38,10 +39,14 @@ (let [new-shape (get new-objects (:id shape)) attrs (ctt/get-diff-attrs (:content shape) (:content new-shape)) - ;; Unapply token when applying typography asset style - attrs (if (seq (set/intersection text-typography-attrs attrs)) - (into attrs cto/typography-keys) - attrs)] + attrs (cond-> attrs + ;; Unapply token when applying typography asset style + (seq (set/intersection text-typography-style-attrs attrs)) + (into cto/typography-keys) + + ;; Unapply font-weight when changing the font-family attribute + (and (:font-id attrs) (ctst/font-weight-applied? shape)) + (conj :font-weight))] (apply set/union (map cto/shape-attr->token-attrs attrs)))) check-attr diff --git a/common/src/app/common/types/shape/token.cljc b/common/src/app/common/types/shape/token.cljc new file mode 100644 index 0000000000..7ad0adff4a --- /dev/null +++ b/common/src/app/common/types/shape/token.cljc @@ -0,0 +1,7 @@ +(ns app.common.types.shape.token) + +(defn font-weight-applied? + [shape] + (or + (get-in shape [:applied-tokens :font-weight]) + (get-in shape [:applied-tokens :typography :font-weight])))