diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 8b98382859..9ebac327a0 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -113,22 +113,26 @@ :else (get-component-shape objects (get objects (:parent-id shape)) options)))) -(defn in-component-main? - "Check if the shape is inside a component non-main instance. - Note that we must iterate on the parents because non-root shapes in - a main component have not any discriminating attribute." + +(defn component-main? + "Check if the shape is a component main instance or is inside one." [objects shape] - (let [component-shape (get-component-shape objects shape {:allow-main? true})] - (:main-instance component-shape))) + (cond + (or (nil? shape) (cph/root? shape)) + false + (ctk/main-instance? shape) + true + :else + (component-main? objects (get objects (:parent-id shape))))) (defn in-any-component? "Check if the shape is part of any component (main or copy), wether it's head or not." [objects shape] (or (ctk/in-component-copy? shape) - (ctk/main-instance? shape) - (in-component-main? objects shape))) + (ctk/instance-head? shape) + (component-main? objects shape))) (defn make-component-shape "Clone the shape and all children. Generate new ids and detach