mirror of
https://github.com/penpot/penpot.git
synced 2025-02-01 03:49:22 -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.plugins :as ctpg]
|
||||||
[app.common.types.shape-tree :as ctst]
|
[app.common.types.shape-tree :as ctst]
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
|
[app.common.types.token :as ctt]
|
||||||
[app.common.uuid :as uuid]))
|
[app.common.uuid :as uuid]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -540,14 +541,28 @@
|
||||||
|
|
||||||
;; --- SHAPE UPDATE
|
;; --- 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
|
(defn set-shape-attr
|
||||||
"Assign attribute to shape with touched logic.
|
"Assign attribute to shape with touched logic.
|
||||||
|
|
||||||
The returned shape will contain a metadata associated with it
|
The returned shape will contain a metadata associated with it
|
||||||
indicating if shape is touched or not."
|
indicating if shape is touched or not."
|
||||||
[shape attr val & {:keys [ignore-touched ignore-geometry]}]
|
[shape attr val & {:keys [ignore-touched ignore-geometry]}]
|
||||||
(let [group (get ctk/sync-attrs attr)
|
(let [group (get ctk/sync-attrs attr)
|
||||||
shape-val (get shape attr)
|
token-groups (when (= attr :applied-tokens)
|
||||||
|
(get-token-groups shape val))
|
||||||
|
shape-val (get shape attr)
|
||||||
|
|
||||||
ignore?
|
ignore?
|
||||||
(or ignore-touched
|
(or ignore-touched
|
||||||
|
@ -585,9 +600,15 @@
|
||||||
;; set the "touched" flag for the group the attribute belongs to.
|
;; set the "touched" flag for the group the attribute belongs to.
|
||||||
;; In some cases we need to ignore touched only if the attribute is
|
;; In some cases we need to ignore touched only if the attribute is
|
||||||
;; geometric (position, width or transformation).
|
;; geometric (position, width or transformation).
|
||||||
(and in-copy? group (not ignore?) (not equal?)
|
(and in-copy?
|
||||||
(not (and ignore-geometry is-geometry?)))
|
(or (and group (not equal?)) (seq token-groups))
|
||||||
(-> (update :touched ctk/set-touched-group group)
|
(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))
|
(dissoc :remote-synced))
|
||||||
|
|
||||||
(nil? val)
|
(nil? val)
|
||||||
|
|
|
@ -150,6 +150,15 @@
|
||||||
|
|
||||||
(def rotation-keys (schema-keys ::rotation))
|
(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/register!
|
||||||
^{::sm/type ::tokens}
|
^{::sm/type ::tokens}
|
||||||
[:map {:title "Applied Tokens"}])
|
[:map {:title "Applied Tokens"}])
|
||||||
|
@ -174,3 +183,11 @@
|
||||||
(opacity-keys shape-attr) #{shape-attr}
|
(opacity-keys shape-attr) #{shape-attr}
|
||||||
(spacing-keys shape-attr) #{shape-attr}
|
(spacing-keys shape-attr) #{shape-attr}
|
||||||
(rotation-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