diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index 58124284d0..96dd03c8fd 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -29,6 +29,12 @@ (defn is-direct-child-of-root? ([objects id] (is-direct-child-of-root? (get objects id))) + ([shape] + (and (some? shape) (= (dm/get-prop shape :frame-id) uuid/zero)))) + +(defn root-frame? + ([objects id] + (root-frame? (get objects id))) ([shape] (and (some? shape) (= (dm/get-prop shape :type) :frame) @@ -229,7 +235,7 @@ (or (root? frame) (nil? frame)) nil - (is-direct-child-of-root? frame) + (root-frame? frame) frame :else @@ -614,7 +620,7 @@ (->> (get-parent-ids objects shape-id) (cons shape-id) (map (d/getf objects)) - (d/seek is-direct-child-of-root?) + (d/seek root-frame?) :id)) (defn comparator-layout-z-index diff --git a/frontend/src/app/main/ui/viewer/inspect/render.cljs b/frontend/src/app/main/ui/viewer/inspect/render.cljs index a2d944bfa9..136f593b8b 100644 --- a/frontend/src/app/main/ui/viewer/inspect/render.cljs +++ b/frontend/src/app/main/ui/viewer/inspect/render.cljs @@ -34,7 +34,7 @@ [shape hover?] (fn [event] (when-not (or (cph/group-shape? shape) - (cph/is-direct-child-of-root? shape)) + (cph/root-frame? shape)) (dom/prevent-default event) (dom/stop-propagation event) (st/emit! (dv/hover-shape (:id shape) hover?))))) @@ -42,7 +42,7 @@ (defn select-shape [shape] (fn [event] (when-not (or (cph/group-shape? shape) - (cph/is-direct-child-of-root? shape)) + (cph/root-frame? shape)) (dom/stop-propagation event) (dom/prevent-default event) (cond diff --git a/frontend/src/app/main/ui/workspace/shapes.cljs b/frontend/src/app/main/ui/workspace/shapes.cljs index 4618c37bc8..ce440a8900 100644 --- a/frontend/src/app/main/ui/workspace/shapes.cljs +++ b/frontend/src/app/main/ui/workspace/shapes.cljs @@ -90,7 +90,7 @@ ;; FIXME: WARN: this breaks react rule of hooks (hooks can't be under conditional) active-frames - (when (cph/is-direct-child-of-root? shape) + (when (cph/root-frame? shape) (mf/use-ctx ctx/active-frames)) thumbnail? @@ -125,4 +125,3 @@ (def bool-wrapper (bool/bool-wrapper-factory shape-wrapper)) (def root-frame-wrapper (frame/root-frame-wrapper-factory shape-wrapper)) (def nested-frame-wrapper (frame/nested-frame-wrapper-factory shape-wrapper)) - diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 4fc1a0d766..275d9f4a0c 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -141,7 +141,7 @@ (fn [] (let [parent-id (->> @hover-ids - (d/seek (partial cph/is-direct-child-of-root? base-objects)))] + (d/seek (partial cph/root-frame? base-objects)))] (when (some? parent-id) (get base-objects parent-id))))) @@ -244,7 +244,7 @@ first-selected-shape (first selected-shapes) selecting-first-level-frame? (and one-selected-shape? - (cph/is-direct-child-of-root? first-selected-shape)) + (cph/root-frame? first-selected-shape)) offset-x (if selecting-first-level-frame? (:x first-selected-shape) diff --git a/frontend/src/app/main/ui/workspace/viewport/guides.cljs b/frontend/src/app/main/ui/workspace/viewport/guides.cljs index 5d8a254e74..1182ca4ea4 100644 --- a/frontend/src/app/main/ui/workspace/viewport/guides.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/guides.cljs @@ -293,7 +293,7 @@ (not (is-guide-inside-frame? (assoc guide :position pos) frame)))] (when (or (nil? frame) - (and (cph/is-direct-child-of-root? frame) + (and (cph/root-frame? frame) (not (ctst/rotated-frame? frame)))) [:g.guide-area {:opacity (when frame-guide-outside? 0)} (when-not disabled-guides? diff --git a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs index d2652212f1..3423a5da7c 100644 --- a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs @@ -217,7 +217,7 @@ root-frame-with-data? #(as-> (get objects %) obj - (and (cph/is-direct-child-of-root? obj) + (and (cph/root-frame? obj) (d/not-empty? (:shapes obj)) (not (ctk/instance-head? obj)) (not (ctk/main-instance? obj)))) @@ -240,9 +240,10 @@ no-fill-nested-frames? (fn [id] - (and (cph/frame-shape? objects id) - (not (cph/is-direct-child-of-root? objects id)) - (empty? (dm/get-in objects [id :fills])))) + (let [shape (get objects id)] + (and (cph/frame-shape? shape) + (not (cph/is-direct-child-of-root? shape)) + (empty? (get shape :fills))))) hover-shape (->> ids @@ -276,7 +277,7 @@ (let [all-frames (mf/use-memo (mf/deps objects) #(ctt/get-root-frames-ids objects)) selected-frames (mf/use-memo (mf/deps selected) #(->> all-frames (filter selected))) - xf-selected-frame (comp (remove cph/is-direct-child-of-root?) + xf-selected-frame (comp (remove cph/root-frame?) (map #(cph/get-shape-id-root-frame objects %))) selected-shapes-frames (mf/use-memo (mf/deps selected) #(into #{} xf-selected-frame selected)) diff --git a/frontend/src/app/util/code_gen/style_css_values.cljs b/frontend/src/app/util/code_gen/style_css_values.cljs index c45e2679d3..53805f28f2 100644 --- a/frontend/src/app/util/code_gen/style_css_values.cljs +++ b/frontend/src/app/util/code_gen/style_css_values.cljs @@ -30,7 +30,7 @@ (not (ctl/layout-absolute? shape)) (or (cph/group-shape? shape) (cph/frame-shape? shape))) - (cph/is-direct-child-of-root? shape)) + (cph/root-frame? shape)) :relative (and (ctl/any-layout-immediate-child? objects shape) @@ -54,14 +54,14 @@ ;;shape (gsh/transform-shape) shape-value (get selrect coord) ] - (when (and (not (cph/is-direct-child-of-root? shape)) + (when (and (not (cph/root-frame? shape)) (or (not (ctl/any-layout-immediate-child? objects shape)) (ctl/layout-absolute? shape))) (- shape-value parent-value)))) #_(defn get-shape-position [shape objects coord] - (when-not (or (cph/is-direct-child-of-root? shape) + (when-not (or (cph/root-frame? shape) (and (ctl/any-layout-immediate-child? objects shape) (not (ctl/layout-absolute? shape)))) (let [parent (get objects (:parent-id shape))