mirror of
https://github.com/penpot/penpot.git
synced 2025-05-09 21:06:37 +02:00
✨ Updating a library color updates texts that uses it
This commit is contained in:
parent
e01e689f69
commit
96fbc83a0a
1 changed files with 74 additions and 59 deletions
|
@ -101,13 +101,20 @@
|
||||||
(= (:component-file shape) library-id)))
|
(= (:component-file shape) library-id)))
|
||||||
|
|
||||||
:colors
|
:colors
|
||||||
(fn [shape] (some
|
(fn [shape] (if (= (:type shape) :text)
|
||||||
#(let [attr (name %)
|
(->> shape
|
||||||
attr-ref-id (keyword (str attr "-ref-id"))
|
:content
|
||||||
attr-ref-file (keyword (str attr "-ref-file"))]
|
;; Check if any node in the content has a reference for the library
|
||||||
(and (get shape attr-ref-id)
|
(ut/some-node
|
||||||
(= library-id (get shape attr-ref-file))))
|
#(and (some? (:fill-color-ref-id %))
|
||||||
cp/color-sync-attrs))
|
(= library-id (:fill-color-ref-file %)))))
|
||||||
|
(some
|
||||||
|
#(let [attr (name %)
|
||||||
|
attr-ref-id (keyword (str attr "-ref-id"))
|
||||||
|
attr-ref-file (keyword (str attr "-ref-file"))]
|
||||||
|
(and (get shape attr-ref-id)
|
||||||
|
(= library-id (get shape attr-ref-file))))
|
||||||
|
cp/color-sync-attrs)))
|
||||||
|
|
||||||
:typographies
|
:typographies
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
|
@ -162,58 +169,8 @@
|
||||||
component-id
|
component-id
|
||||||
reset-touched?)))
|
reset-touched?)))
|
||||||
|
|
||||||
(defmethod generate-sync-shape :colors
|
(defn generate-sync-text-shape [shape page-id component-id update-node]
|
||||||
[_ library-id library-items _ page-id component-id shape]
|
(let [old-content (:content shape)
|
||||||
|
|
||||||
;; Synchronize a shape that uses some colors of the library. The value of the
|
|
||||||
;; color in the library is copied to the shape.
|
|
||||||
(loop [attrs (seq cp/color-sync-attrs)
|
|
||||||
roperations []
|
|
||||||
uoperations []]
|
|
||||||
(let [attr (first attrs)]
|
|
||||||
(if (nil? attr)
|
|
||||||
(if (empty? roperations)
|
|
||||||
empty-changes
|
|
||||||
(let [rchanges [(d/without-nils {:type :mod-obj
|
|
||||||
:page-id page-id
|
|
||||||
:component-id component-id
|
|
||||||
:id (:id shape)
|
|
||||||
:operations roperations})]
|
|
||||||
uchanges [(d/without-nils {:type :mod-obj
|
|
||||||
:page-id page-id
|
|
||||||
:component-id component-id
|
|
||||||
:id (:id shape)
|
|
||||||
:operations uoperations})]]
|
|
||||||
[rchanges uchanges]))
|
|
||||||
(let [attr-ref-id (keyword (str (name attr) "-ref-id"))]
|
|
||||||
(if (or (not (contains? shape attr-ref-id))
|
|
||||||
(nil? (get library-items (get shape attr-ref-id))))
|
|
||||||
(recur (next attrs)
|
|
||||||
roperations
|
|
||||||
uoperations)
|
|
||||||
(let [color (get library-items (get shape attr-ref-id))
|
|
||||||
roperation {:type :set
|
|
||||||
:attr attr
|
|
||||||
:val (:value color)
|
|
||||||
:ignore-touched true}
|
|
||||||
uoperation {:type :set
|
|
||||||
:attr attr
|
|
||||||
:val (get shape attr)
|
|
||||||
:ignore-touched true}]
|
|
||||||
(recur (next attrs)
|
|
||||||
(conj roperations roperation)
|
|
||||||
(conj uoperations uoperation)))))))))
|
|
||||||
|
|
||||||
(defmethod generate-sync-shape :typographies
|
|
||||||
[_ library-id library-items _ page-id component-id shape]
|
|
||||||
|
|
||||||
;; Synchronize a shape that uses some typographies of the library. The attributes
|
|
||||||
;; of the typography are copied to the shape."
|
|
||||||
(let [update-node (fn [node]
|
|
||||||
(if-let [typography (get library-items (:typography-ref-id node))]
|
|
||||||
(merge node (d/without-keys typography [:name :id]))
|
|
||||||
node))
|
|
||||||
old-content (:content shape)
|
|
||||||
new-content (ut/map-node update-node old-content)
|
new-content (ut/map-node update-node old-content)
|
||||||
rchanges [(d/without-nils {:type :mod-obj
|
rchanges [(d/without-nils {:type :mod-obj
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
|
@ -233,6 +190,64 @@
|
||||||
empty-changes
|
empty-changes
|
||||||
[rchanges lchanges])))
|
[rchanges lchanges])))
|
||||||
|
|
||||||
|
(defmethod generate-sync-shape :colors
|
||||||
|
[_ library-id library-items _ page-id component-id shape]
|
||||||
|
|
||||||
|
;; Synchronize a shape that uses some colors of the library. The value of the
|
||||||
|
;; color in the library is copied to the shape.
|
||||||
|
(if (= :text (:type shape))
|
||||||
|
(let [update-node (fn [node]
|
||||||
|
(if-let [color (get library-items (:fill-color-ref-id node))]
|
||||||
|
(assoc node :fill-color (:value color))
|
||||||
|
node))]
|
||||||
|
(generate-sync-text-shape shape page-id component-id update-node))
|
||||||
|
(loop [attrs (seq cp/color-sync-attrs)
|
||||||
|
roperations []
|
||||||
|
uoperations []]
|
||||||
|
(let [attr (first attrs)]
|
||||||
|
(if (nil? attr)
|
||||||
|
(if (empty? roperations)
|
||||||
|
empty-changes
|
||||||
|
(let [rchanges [(d/without-nils {:type :mod-obj
|
||||||
|
:page-id page-id
|
||||||
|
:component-id component-id
|
||||||
|
:id (:id shape)
|
||||||
|
:operations roperations})]
|
||||||
|
uchanges [(d/without-nils {:type :mod-obj
|
||||||
|
:page-id page-id
|
||||||
|
:component-id component-id
|
||||||
|
:id (:id shape)
|
||||||
|
:operations uoperations})]]
|
||||||
|
[rchanges uchanges]))
|
||||||
|
(let [attr-ref-id (keyword (str (name attr) "-ref-id"))]
|
||||||
|
(if-not (contains? shape attr-ref-id)
|
||||||
|
(recur (next attrs)
|
||||||
|
roperations
|
||||||
|
uoperations)
|
||||||
|
(let [color (get library-items (get shape attr-ref-id))
|
||||||
|
roperation {:type :set
|
||||||
|
:attr attr
|
||||||
|
:val (:value color)
|
||||||
|
:ignore-touched true}
|
||||||
|
uoperation {:type :set
|
||||||
|
:attr attr
|
||||||
|
:val (get shape attr)
|
||||||
|
:ignore-touched true}]
|
||||||
|
(recur (next attrs)
|
||||||
|
(conj roperations roperation)
|
||||||
|
(conj uoperations uoperation))))))))))
|
||||||
|
|
||||||
|
(defmethod generate-sync-shape :typographies
|
||||||
|
[_ library-id library-items _ page-id component-id shape]
|
||||||
|
|
||||||
|
;; Synchronize a shape that uses some typographies of the library. The attributes
|
||||||
|
;; of the typography are copied to the shape."
|
||||||
|
(let [update-node (fn [node]
|
||||||
|
(if-let [typography (get library-items (:typography-ref-id node))]
|
||||||
|
(merge node (d/without-keys typography [:name :id]))
|
||||||
|
node))]
|
||||||
|
(generate-sync-text-shape shape page-id component-id update-node)))
|
||||||
|
|
||||||
|
|
||||||
;; ---- Create a new component ----
|
;; ---- Create a new component ----
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue