mirror of
https://github.com/penpot/penpot.git
synced 2025-05-31 11:16:11 +02:00
🐛 Fix stroke token errors (#5661)
* 🐛 Fix change on any stroke attribute remove tokens * 🐛 Fix add new stroke, reorder stroke or remove stroke should remove applied tokens * 📎 Review fixes
This commit is contained in:
parent
25b89ec59f
commit
231d875f79
4 changed files with 71 additions and 55 deletions
|
@ -20,13 +20,13 @@
|
|||
(defn- generate-unapply-tokens
|
||||
"When updating attributes that have a token applied, we must unapply it, because the value
|
||||
of the attribute now has been given directly, and does not come from the token."
|
||||
[changes objects]
|
||||
[changes objects changed-sub-attr]
|
||||
(let [mod-obj-changes (->> (:redo-changes changes)
|
||||
(filter #(= (:type %) :mod-obj)))
|
||||
|
||||
check-attr (fn [shape changes attr]
|
||||
(let [tokens (get shape :applied-tokens {})
|
||||
token-attrs (cto/shape-attr->token-attrs attr)]
|
||||
token-attrs (cto/shape-attr->token-attrs attr changed-sub-attr)]
|
||||
(if (some #(contains? tokens %) token-attrs)
|
||||
(pcb/update-shapes changes [(:id shape)] #(cto/unapply-token-id % token-attrs))
|
||||
changes)))
|
||||
|
@ -44,7 +44,7 @@
|
|||
mod-obj-changes)))
|
||||
|
||||
(defn generate-update-shapes
|
||||
[changes ids update-fn objects {:keys [attrs ignore-tree ignore-touched with-objects?]}]
|
||||
[changes ids update-fn objects {:keys [attrs changed-sub-attr ignore-tree ignore-touched with-objects?]}]
|
||||
(let [changes (reduce
|
||||
(fn [changes id]
|
||||
(let [opts {:attrs attrs
|
||||
|
@ -61,7 +61,7 @@
|
|||
(pcb/reorder-grid-children ids)
|
||||
(cond->
|
||||
(not ignore-touched)
|
||||
(generate-unapply-tokens objects)))]
|
||||
(generate-unapply-tokens objects changed-sub-attr)))]
|
||||
changes))
|
||||
|
||||
(defn- generate-update-shape-flags
|
||||
|
|
|
@ -175,15 +175,20 @@
|
|||
::dimensions])
|
||||
|
||||
(defn shape-attr->token-attrs
|
||||
[shape-attr]
|
||||
(cond
|
||||
(= :fills shape-attr) #{:fill}
|
||||
(= :strokes shape-attr) #{:stroke-color :stroke-width}
|
||||
(border-radius-keys shape-attr) #{shape-attr}
|
||||
(sizing-keys shape-attr) #{shape-attr}
|
||||
(opacity-keys shape-attr) #{shape-attr}
|
||||
(spacing-keys shape-attr) #{shape-attr}
|
||||
(rotation-keys shape-attr) #{shape-attr}))
|
||||
([shape-attr] (shape-attr->token-attrs shape-attr nil))
|
||||
([shape-attr changed-sub-attr]
|
||||
(cond
|
||||
(= :fills shape-attr) #{:fill}
|
||||
(and (= :strokes shape-attr) (nil? changed-sub-attr)) #{:stroke-width :stroke-color}
|
||||
(= :strokes shape-attr)
|
||||
(cond
|
||||
(some #{:stroke-color} changed-sub-attr) #{:stroke-color}
|
||||
(some #{:stroke-width} changed-sub-attr) #{:stroke-width})
|
||||
(border-radius-keys shape-attr) #{shape-attr}
|
||||
(sizing-keys shape-attr) #{shape-attr}
|
||||
(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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue