From 9f98e9c50c30e1a49b428b90754a0334f27f7893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 26 Aug 2022 14:08:20 +0200 Subject: [PATCH] wip --- common/src/app/common/types/component.cljc | 22 ++++++++++++++++--- .../app/main/data/workspace/libraries.cljs | 2 +- .../data/workspace/libraries_helpers.cljs | 17 ++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/common/src/app/common/types/component.cljc b/common/src/app/common/types/component.cljc index 7177a52f9..42c34abfe 100644 --- a/common/src/app/common/types/component.cljc +++ b/common/src/app/common/types/component.cljc @@ -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))))) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 151273abe..6fabf804c 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -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) diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index a8bc5d3db..72976278d 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -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 (cph/component? container))))] + (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) @@ -263,14 +267,19 @@ (fn [asset-type _ _ _ _] asset-type)) (defmethod uses-assets? :components - [_ component-id shape library-id component?] + [_ 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. - (or (:component-root? shape) component?))) + standalone-instance?)) (defmethod uses-assets? :colors [_ color-id shape library-id _]