mirror of
https://github.com/penpot/penpot.git
synced 2025-06-24 12:26:59 +02:00
🐛 Fix when a component annotation is changed on a library, update dialog appears
This commit is contained in:
parent
463d81745b
commit
b98f693959
2 changed files with 44 additions and 19 deletions
|
@ -177,3 +177,23 @@
|
||||||
:remote-synced
|
:remote-synced
|
||||||
:shape-ref
|
:shape-ref
|
||||||
:touched))
|
:touched))
|
||||||
|
|
||||||
|
|
||||||
|
(defn- extract-ids [shape]
|
||||||
|
(if (map? shape)
|
||||||
|
(let [current-id (:id shape)
|
||||||
|
child-ids (mapcat extract-ids (:children shape))]
|
||||||
|
(cons current-id child-ids))
|
||||||
|
[]))
|
||||||
|
|
||||||
|
(defn diff-components
|
||||||
|
"Compare two components, and return a set of the keys with different values"
|
||||||
|
[comp1 comp2]
|
||||||
|
(let [eq (fn [key val1 val2]
|
||||||
|
(if (= key :objects)
|
||||||
|
(= (extract-ids val1) (extract-ids val2))
|
||||||
|
(= val1 val2)))]
|
||||||
|
(->> (concat (keys comp1) (keys comp2))
|
||||||
|
(distinct)
|
||||||
|
(filter #(not (eq % (get comp1 %) (get comp2 %))))
|
||||||
|
set)))
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.features :as cfeat]
|
[app.common.features :as cfeat]
|
||||||
[app.common.time :as dt]
|
[app.common.time :as dt]
|
||||||
[app.common.types.component :as ctk]))
|
[app.common.types.component :as ctk]
|
||||||
|
[clojure.set :as set]))
|
||||||
|
|
||||||
(defn components
|
(defn components
|
||||||
([file-data] (components file-data nil))
|
([file-data] (components file-data nil))
|
||||||
|
@ -51,31 +52,35 @@
|
||||||
(let [wrap-objects-fn cfeat/*wrap-with-objects-map-fn*]
|
(let [wrap-objects-fn cfeat/*wrap-with-objects-map-fn*]
|
||||||
(d/update-in-when file-data [:components id]
|
(d/update-in-when file-data [:components id]
|
||||||
(fn [component]
|
(fn [component]
|
||||||
(let [objects (some-> objects wrap-objects-fn)]
|
(let [objects (some-> objects wrap-objects-fn)
|
||||||
(cond-> component
|
new-comp (cond-> component
|
||||||
(some? name)
|
(some? name)
|
||||||
(assoc :name name)
|
(assoc :name name)
|
||||||
|
|
||||||
(some? path)
|
(some? path)
|
||||||
(assoc :path path)
|
(assoc :path path)
|
||||||
|
|
||||||
(some? main-instance-id)
|
(some? main-instance-id)
|
||||||
(assoc :main-instance-id main-instance-id)
|
(assoc :main-instance-id main-instance-id)
|
||||||
|
|
||||||
(some? main-instance-page)
|
(some? main-instance-page)
|
||||||
(assoc :main-instance-page main-instance-page)
|
(assoc :main-instance-page main-instance-page)
|
||||||
|
|
||||||
(some? objects)
|
(some? objects)
|
||||||
(assoc :objects objects)
|
(assoc :objects objects)
|
||||||
|
|
||||||
(some? annotation)
|
(some? annotation)
|
||||||
(assoc :annotation annotation)
|
(assoc :annotation annotation)
|
||||||
|
|
||||||
(nil? annotation)
|
(nil? annotation)
|
||||||
(dissoc :annotation)
|
(dissoc :annotation))
|
||||||
|
diff (set/difference
|
||||||
|
(ctk/diff-components component new-comp)
|
||||||
|
#{:annotation})] ;; The set of properties that doesn't mark a component as touched
|
||||||
|
|
||||||
:always
|
(if (empty? diff)
|
||||||
(touch)))))))
|
new-comp
|
||||||
|
(touch new-comp)))))))
|
||||||
|
|
||||||
(defn get-component
|
(defn get-component
|
||||||
([file-data component-id]
|
([file-data component-id]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue