mirror of
https://github.com/penpot/penpot.git
synced 2025-01-20 05:34:23 -05:00
🎉 Set touched groups when changing tokens in copies
This commit is contained in:
parent
6077ba6690
commit
d378937a37
2 changed files with 43 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue