mirror of
https://github.com/penpot/penpot.git
synced 2025-02-11 01:28:30 -05:00
🐛 Fix problems on sync with components chain with deleted components
This commit is contained in:
parent
697a542754
commit
74d2273d24
4 changed files with 28 additions and 22 deletions
|
@ -6,11 +6,11 @@
|
|||
|
||||
(ns user
|
||||
(:require
|
||||
[app.common.pprint :as pp]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.schema.desc-js-like :as smdj]
|
||||
[app.common.schema.desc-native :as smdn]
|
||||
[app.common.schema.generators :as sg]
|
||||
[app.common.pprint :as pp]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.pprint :refer [pprint print-table]]
|
||||
[clojure.repl :refer :all]
|
||||
|
|
|
@ -749,21 +749,23 @@
|
|||
(defmulti components-changed (fn [_ change] (:type change)))
|
||||
|
||||
(defmethod components-changed :mod-obj
|
||||
[file-data {:keys [id page-id _component-id operations]}]
|
||||
(when page-id
|
||||
(let [page (ctpl/get-page file-data page-id)
|
||||
shape-and-parents (map #(ctn/get-shape page %)
|
||||
(cons id (cfh/get-parent-ids (:objects page) id)))
|
||||
need-sync? (fn [operation]
|
||||
; We need to trigger a sync if the shape has changed any
|
||||
; attribute that participates in components synchronization.
|
||||
(and (= (:type operation) :set)
|
||||
(get ctk/sync-attrs (:attr operation))))
|
||||
any-sync? (some need-sync? operations)]
|
||||
(when any-sync?
|
||||
(let [xform (comp (filter :main-instance) ; Select shapes that are main component instances
|
||||
[file-data {:keys [id page-id component-id operations]}]
|
||||
(let [need-sync? (fn [operation]
|
||||
; We need to trigger a sync if the shape has changed any
|
||||
; attribute that participates in components synchronization.
|
||||
(and (= (:type operation) :set)
|
||||
(get ctk/sync-attrs (:attr operation))))
|
||||
any-sync? (some need-sync? operations)]
|
||||
(when any-sync?
|
||||
(if page-id
|
||||
(let [page (ctpl/get-page file-data page-id)
|
||||
shape-and-parents (map #(ctn/get-shape page %)
|
||||
(cons id (cfh/get-parent-ids (:objects page) id)))
|
||||
xform (comp (filter :main-instance) ; Select shapes that are main component instances
|
||||
(map :component-id))]
|
||||
(into #{} xform shape-and-parents))))))
|
||||
(into #{} xform shape-and-parents))
|
||||
(when component-id
|
||||
#{component-id})))))
|
||||
|
||||
(defmethod components-changed :mov-objects
|
||||
[file-data {:keys [page-id _component-id parent-id shapes] :as change}]
|
||||
|
|
|
@ -103,6 +103,12 @@
|
|||
(concat (map #(ctn/make-container % :page) (ctpl/pages-seq file-data))
|
||||
(map #(ctn/make-container % :component) (ctkl/components-seq file-data))))
|
||||
|
||||
(defn object-containers-seq
|
||||
"Generate a sequence of all pages and all deleted components (all those components that have :objects), wrapped as containers"
|
||||
[file-data]
|
||||
(concat (map #(ctn/make-container % :page) (ctpl/pages-seq file-data))
|
||||
(map #(ctn/make-container % :component) (ctkl/deleted-components-seq file-data))))
|
||||
|
||||
(defn update-container
|
||||
"Update a container inside the file, it can be a page or a component"
|
||||
[file-data container f]
|
||||
|
|
|
@ -317,10 +317,10 @@
|
|||
|
||||
(let [file (wsh/get-file state file-id)
|
||||
components-v2 (get-in file [:options :components-v2])]
|
||||
(loop [pages (vals (get file :pages-index))
|
||||
(loop [containers (ctf/object-containers-seq file)
|
||||
changes (pcb/empty-changes it)]
|
||||
(if-let [page (first pages)]
|
||||
(recur (next pages)
|
||||
(if-let [container (first containers)]
|
||||
(recur (next containers)
|
||||
(pcb/concat-changes
|
||||
changes
|
||||
(generate-sync-container it
|
||||
|
@ -328,7 +328,7 @@
|
|||
asset-id
|
||||
library-id
|
||||
state
|
||||
(cfh/make-container page :page)
|
||||
container
|
||||
components-v2)))
|
||||
changes))))
|
||||
|
||||
|
@ -597,9 +597,7 @@
|
|||
(log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?)
|
||||
(let [shape-inst (ctn/get-shape container shape-id)
|
||||
library (dm/get-in libraries [(:component-file shape-inst) :data])
|
||||
component (or (ctkl/get-component library (:component-id shape-inst))
|
||||
(and reset?
|
||||
(ctkl/get-deleted-component library (:component-id shape-inst))))]
|
||||
component (ctkl/get-component library (:component-id shape-inst) true)]
|
||||
(if (and (ctk/in-component-copy? shape-inst)
|
||||
(or (ctf/direct-copy? shape-inst component container nil libraries) reset?)) ; In a normal sync, we don't want to sync remote mains, only direct/near
|
||||
(let [redirect-shaperef (partial redirect-shaperef container libraries)
|
||||
|
|
Loading…
Add table
Reference in a new issue