mirror of
https://github.com/penpot/penpot.git
synced 2025-12-23 22:48:40 -05:00
Compare commits
2 Commits
main
...
hiru-sync-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f98e9c50c | ||
|
|
d213bc96d4 |
@@ -4,13 +4,20 @@
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.common.types.component)
|
||||
(ns app.common.types.component
|
||||
(:require
|
||||
[app.common.types.container :as ctn]))
|
||||
|
||||
(defn instance-root?
|
||||
"An intance root is the shape, inside an instance, that has
|
||||
the link to the component. Other shapes have :shape-ref but
|
||||
not :component-id."
|
||||
[shape]
|
||||
(some? (:component-id shape)))
|
||||
|
||||
(defn instance-of?
|
||||
"Check if the shape is the root of an instance of the
|
||||
given component at the given file library."
|
||||
[shape file-id component-id]
|
||||
(and (some? (:component-id shape))
|
||||
(some? (:component-file shape))
|
||||
@@ -18,6 +25,7 @@
|
||||
(= (:component-file shape) file-id)))
|
||||
|
||||
(defn is-main-of?
|
||||
"Check if the first shape is a near or remote main of the second one."
|
||||
[shape-main shape-inst]
|
||||
(and (:shape-ref shape-inst)
|
||||
(or (= (:shape-ref shape-inst) (:id shape-main))
|
||||
@@ -29,12 +37,13 @@
|
||||
(some? (:main-instance? shape)))
|
||||
|
||||
(defn is-main-instance?
|
||||
"Check if this shape is the root of the main instance of the given component."
|
||||
"Check if the shape in the page is the main instance of the component."
|
||||
[shape-id page-id component]
|
||||
(and (= shape-id (:main-instance-id component))
|
||||
(= page-id (:main-instance-page component))))
|
||||
|
||||
(defn get-component-root
|
||||
"Get the root shape of the component."
|
||||
[component]
|
||||
(get-in component [:objects (:id component)]))
|
||||
|
||||
@@ -67,4 +76,11 @@
|
||||
:shape-ref
|
||||
:touched))
|
||||
|
||||
|
||||
(defn standalone-instance?
|
||||
"Check if the shape inside the container is not a subinstance
|
||||
(an instance inside another one)."
|
||||
[shape container]
|
||||
(when (:component-id shape)
|
||||
(if (ctn/page? container)
|
||||
(:component-root? shape)
|
||||
(nil? (:parent-id shape)))))
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
[potok.core :as ptk]))
|
||||
|
||||
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
||||
(log/set-level! :warn)
|
||||
(log/set-level! :info)
|
||||
|
||||
(s/def ::file ::dd/file)
|
||||
|
||||
@@ -754,8 +754,8 @@
|
||||
:library-id library-id})))
|
||||
(when (and (seq (:redo-changes library-changes))
|
||||
sync-components?)
|
||||
(rx/of (sync-file-2nd-stage file-id library-id asset-id))))))))))
|
||||
|
||||
(rx/of (sync-file-2nd-stage file-id library-id nil)))))))))) ; In 2nd stage the original asset is not used
|
||||
; because other components may have changed
|
||||
(defn- sync-file-2nd-stage
|
||||
"If some components have been modified, we need to launch another synchronization
|
||||
to update the instances of the changed components."
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
[clojure.set :as set]))
|
||||
|
||||
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
||||
(log/set-level! :warn)
|
||||
(log/set-level! :info)
|
||||
|
||||
(declare generate-sync-container)
|
||||
(declare generate-sync-shape)
|
||||
@@ -242,7 +242,11 @@
|
||||
(log/debug :msg "Sync component in local library" :component-id (:id container)))
|
||||
|
||||
(let [linked-shapes (->> (vals (:objects container))
|
||||
(filter #(uses-assets? asset-type asset-id % library-id)))]
|
||||
(filter #(uses-assets? asset-type
|
||||
asset-id
|
||||
%
|
||||
library-id
|
||||
(ctk/standalone-instance? % container))))]
|
||||
(loop [shapes (seq linked-shapes)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-container container)
|
||||
@@ -260,22 +264,31 @@
|
||||
|
||||
(defmulti uses-assets?
|
||||
"Checks if a shape uses some asset of the given type in the given library."
|
||||
(fn [asset-type _ _ _] asset-type))
|
||||
(fn [asset-type _ _ _ _] asset-type))
|
||||
|
||||
(defmethod uses-assets? :components
|
||||
[_ component-id shape library-id]
|
||||
(if (nil? component-id)
|
||||
(ctk/uses-library-components? shape library-id)
|
||||
(ctk/instance-of? shape library-id component-id)))
|
||||
[_ component-id shape library-id standalone-instance?]
|
||||
(when (and (if (nil? component-id)
|
||||
(ctk/uses-library-components? shape library-id)
|
||||
(ctk/instance-of? shape library-id component-id))
|
||||
(not standalone-instance?))
|
||||
(js/console.log "ignored shape" (clj->js shape)))
|
||||
(and (if (nil? component-id)
|
||||
(ctk/uses-library-components? shape library-id)
|
||||
(ctk/instance-of? shape library-id component-id))
|
||||
;; Subinstances are synced with the near component, not the remote.
|
||||
;; So an instance that is not root, cannot be considered "using"
|
||||
;; the component.
|
||||
standalone-instance?))
|
||||
|
||||
(defmethod uses-assets? :colors
|
||||
[_ color-id shape library-id]
|
||||
[_ color-id shape library-id _]
|
||||
(if (nil? color-id)
|
||||
(ctc/uses-library-colors? shape library-id)
|
||||
(ctc/uses-library-color? shape library-id color-id)))
|
||||
|
||||
(defmethod uses-assets? :typographies
|
||||
[_ typography-id shape library-id]
|
||||
[_ typography-id shape library-id _]
|
||||
(if (nil? typography-id)
|
||||
(cty/uses-library-typographies? shape library-id)
|
||||
(cty/uses-library-typography? shape library-id typography-id)))
|
||||
|
||||
Reference in New Issue
Block a user