From d378937a370f452f6edde4c88d5c87eefe6411bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 21 Nov 2024 16:39:43 +0100 Subject: [PATCH] :tada: Set touched groups when changing tokens in copies --- common/src/app/common/types/container.cljc | 31 ++++++++++++++++++---- common/src/app/common/types/token.cljc | 17 ++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index ca0181604b..5c5673459e 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -18,6 +18,7 @@ [app.common.types.plugins :as ctpg] [app.common.types.shape-tree :as ctst] [app.common.types.shape.layout :as ctl] + [app.common.types.token :as ctt] [app.common.uuid :as uuid])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -540,14 +541,28 @@ ;; --- SHAPE UPDATE +(defn- get-token-groups + [shape new-applied-tokens] + (let [old-applied-tokens (d/nilv (:applied-tokens shape) #{}) + changed-token-attrs (filter #(not= (get old-applied-tokens %) (get new-applied-tokens %)) + ctt/all-keys) + changed-groups (into #{} + (comp (map ctt/token-attr->shape-attr) + (map #(get ctk/sync-attrs %)) + (filter some?)) + changed-token-attrs)] + changed-groups)) + (defn set-shape-attr "Assign attribute to shape with touched logic. The returned shape will contain a metadata associated with it indicating if shape is touched or not." [shape attr val & {:keys [ignore-touched ignore-geometry]}] - (let [group (get ctk/sync-attrs attr) - shape-val (get shape attr) + (let [group (get ctk/sync-attrs attr) + token-groups (when (= attr :applied-tokens) + (get-token-groups shape val)) + shape-val (get shape attr) ignore? (or ignore-touched @@ -585,9 +600,15 @@ ;; set the "touched" flag for the group the attribute belongs to. ;; In some cases we need to ignore touched only if the attribute is ;; geometric (position, width or transformation). - (and in-copy? group (not ignore?) (not equal?) - (not (and ignore-geometry is-geometry?))) - (-> (update :touched ctk/set-touched-group group) + (and in-copy? + (or (and group (not equal?)) (seq token-groups)) + (not ignore?) (not (and ignore-geometry is-geometry?))) + (-> (update :touched (fn [touched] + (reduce #(ctk/set-touched-group %1 %2) + touched + (if group + (cons group token-groups) + token-groups)))) (dissoc :remote-synced)) (nil? val) diff --git a/common/src/app/common/types/token.cljc b/common/src/app/common/types/token.cljc index d97279fb66..b1e58dfed8 100644 --- a/common/src/app/common/types/token.cljc +++ b/common/src/app/common/types/token.cljc @@ -150,6 +150,15 @@ (def rotation-keys (schema-keys ::rotation)) +(def all-keys (set/union color-keys + border-radius-keys + stroke-width-keys + sizing-keys + opacity-keys + spacing-keys + dimensions-keys + rotation-keys)) + (sm/register! ^{::sm/type ::tokens} [:map {:title "Applied Tokens"}]) @@ -174,3 +183,11 @@ (opacity-keys shape-attr) #{shape-attr} (spacing-keys shape-attr) #{shape-attr} (rotation-keys shape-attr) #{shape-attr})) + +(defn token-attr->shape-attr + [token-attr] + (case token-attr + :fill :fills + :stroke-color :strokes + :stroke-width :strokes + token-attr))