mirror of
https://github.com/penpot/penpot.git
synced 2025-05-08 02:55:54 +02: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
|
(ns user
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.pprint :as pp]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.schema.desc-js-like :as smdj]
|
[app.common.schema.desc-js-like :as smdj]
|
||||||
[app.common.schema.desc-native :as smdn]
|
[app.common.schema.desc-native :as smdn]
|
||||||
[app.common.schema.generators :as sg]
|
[app.common.schema.generators :as sg]
|
||||||
[app.common.pprint :as pp]
|
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.pprint :refer [pprint print-table]]
|
[clojure.pprint :refer [pprint print-table]]
|
||||||
[clojure.repl :refer :all]
|
[clojure.repl :refer :all]
|
||||||
|
|
|
@ -749,21 +749,23 @@
|
||||||
(defmulti components-changed (fn [_ change] (:type change)))
|
(defmulti components-changed (fn [_ change] (:type change)))
|
||||||
|
|
||||||
(defmethod components-changed :mod-obj
|
(defmethod components-changed :mod-obj
|
||||||
[file-data {:keys [id page-id _component-id operations]}]
|
[file-data {:keys [id page-id component-id operations]}]
|
||||||
(when page-id
|
(let [need-sync? (fn [operation]
|
||||||
(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
|
; We need to trigger a sync if the shape has changed any
|
||||||
; attribute that participates in components synchronization.
|
; attribute that participates in components synchronization.
|
||||||
(and (= (:type operation) :set)
|
(and (= (:type operation) :set)
|
||||||
(get ctk/sync-attrs (:attr operation))))
|
(get ctk/sync-attrs (:attr operation))))
|
||||||
any-sync? (some need-sync? operations)]
|
any-sync? (some need-sync? operations)]
|
||||||
(when any-sync?
|
(when any-sync?
|
||||||
(let [xform (comp (filter :main-instance) ; Select shapes that are main component instances
|
(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))]
|
(map :component-id))]
|
||||||
(into #{} xform shape-and-parents))))))
|
(into #{} xform shape-and-parents))
|
||||||
|
(when component-id
|
||||||
|
#{component-id})))))
|
||||||
|
|
||||||
(defmethod components-changed :mov-objects
|
(defmethod components-changed :mov-objects
|
||||||
[file-data {:keys [page-id _component-id parent-id shapes] :as change}]
|
[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))
|
(concat (map #(ctn/make-container % :page) (ctpl/pages-seq file-data))
|
||||||
(map #(ctn/make-container % :component) (ctkl/components-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
|
(defn update-container
|
||||||
"Update a container inside the file, it can be a page or a component"
|
"Update a container inside the file, it can be a page or a component"
|
||||||
[file-data container f]
|
[file-data container f]
|
||||||
|
|
|
@ -317,10 +317,10 @@
|
||||||
|
|
||||||
(let [file (wsh/get-file state file-id)
|
(let [file (wsh/get-file state file-id)
|
||||||
components-v2 (get-in file [:options :components-v2])]
|
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)]
|
changes (pcb/empty-changes it)]
|
||||||
(if-let [page (first pages)]
|
(if-let [container (first containers)]
|
||||||
(recur (next pages)
|
(recur (next containers)
|
||||||
(pcb/concat-changes
|
(pcb/concat-changes
|
||||||
changes
|
changes
|
||||||
(generate-sync-container it
|
(generate-sync-container it
|
||||||
|
@ -328,7 +328,7 @@
|
||||||
asset-id
|
asset-id
|
||||||
library-id
|
library-id
|
||||||
state
|
state
|
||||||
(cfh/make-container page :page)
|
container
|
||||||
components-v2)))
|
components-v2)))
|
||||||
changes))))
|
changes))))
|
||||||
|
|
||||||
|
@ -597,9 +597,7 @@
|
||||||
(log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?)
|
(log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?)
|
||||||
(let [shape-inst (ctn/get-shape container shape-id)
|
(let [shape-inst (ctn/get-shape container shape-id)
|
||||||
library (dm/get-in libraries [(:component-file shape-inst) :data])
|
library (dm/get-in libraries [(:component-file shape-inst) :data])
|
||||||
component (or (ctkl/get-component library (:component-id shape-inst))
|
component (ctkl/get-component library (:component-id shape-inst) true)]
|
||||||
(and reset?
|
|
||||||
(ctkl/get-deleted-component library (:component-id shape-inst))))]
|
|
||||||
(if (and (ctk/in-component-copy? shape-inst)
|
(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
|
(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)
|
(let [redirect-shaperef (partial redirect-shaperef container libraries)
|
||||||
|
|
Loading…
Add table
Reference in a new issue