diff --git a/common/src/app/common/types/shape/layout.cljc b/common/src/app/common/types/shape/layout.cljc index 5a9ffcf97..534174444 100644 --- a/common/src/app/common/types/shape/layout.cljc +++ b/common/src/app/common/types/shape/layout.cljc @@ -100,15 +100,13 @@ (and (= :frame (:type shape)) (= :flex (:layout shape))))) (defn layout-child? [objects shape] - (let [parent-id (:parent-id shape) - parent (get objects parent-id)] - (layout? parent))) + (let [frame-id (:frame-id shape) + frame (get objects frame-id)] + (layout? frame))) (defn layout-child-id? [objects id] - (let [shape (get objects id) - parent-id (:parent-id shape) - parent (get objects parent-id)] - (layout? parent))) + (let [shape (get objects id)] + (layout-child? objects shape))) (defn inside-layout? "Check if the shape is inside a layout" diff --git a/frontend/src/app/main/data/workspace/drawing/box.cljs b/frontend/src/app/main/data/workspace/drawing/box.cljs index 4c4c3346e..39971af7c 100644 --- a/frontend/src/app/main/data/workspace/drawing/box.cljs +++ b/frontend/src/app/main/data/workspace/drawing/box.cljs @@ -37,19 +37,21 @@ (assoc :x (- (:x point) (* sx (- dy dx))))))) (defn resize-shape [{:keys [x y width height] :as shape} initial point lock?] - (let [draw-rect (gsh/make-rect initial (cond-> point lock? (adjust-ratio initial))) - shape-rect (gsh/make-rect x y width height) + (if (and (some? x) (some? y) (some? width) (some? height)) + (let [draw-rect (gsh/make-rect initial (cond-> point lock? (adjust-ratio initial))) + shape-rect (gsh/make-rect x y width height) - scalev (gpt/point (/ (:width draw-rect) (:width shape-rect)) - (/ (:height draw-rect) (:height shape-rect))) + scalev (gpt/point (/ (:width draw-rect) (:width shape-rect)) + (/ (:height draw-rect) (:height shape-rect))) - movev (gpt/to-vec (gpt/point shape-rect) (gpt/point draw-rect))] + movev (gpt/to-vec (gpt/point shape-rect) (gpt/point draw-rect))] - (-> shape - (assoc :click-draw? false) - (gsh/transform-shape (-> (ctm/empty) - (ctm/resize scalev (gpt/point x y)) - (ctm/move movev)))))) + (-> shape + (assoc :click-draw? false) + (gsh/transform-shape (-> (ctm/empty) + (ctm/resize scalev (gpt/point x y)) + (ctm/move movev))))) + shape)) (defn update-drawing [state initial point lock?] (update-in state [:workspace-drawing :object] resize-shape initial point lock?)) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 848379901..2512826dc 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -219,6 +219,7 @@ (rx/concat (->> ms/mouse-position + (rx/filter some?) (rx/with-latest-from ms/mouse-position-shift ms/mouse-position-alt) (rx/map normalize-proportion-lock) (rx/switch-map (fn [[point _ _ :as current]] diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 858f8fb57..51a0becaa 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -324,11 +324,7 @@ (l/derived :workspace-editor-state st/state)) (def workspace-modifiers - (l/derived :workspace-modifiers st/state)) - -(defn workspace-modifiers-by-id - [ids] - (l/derived #(select-keys % ids) workspace-modifiers)) + (l/derived :workspace-modifiers st/state =)) (def workspace-modifiers-with-objects (l/derived @@ -340,20 +336,29 @@ (and (= (:modifiers a) (:modifiers b)) (identical? (:objects a) (:objects b)))))) -(defn workspace-modifiers-by-frame-id - [frame-id] +(def workspace-frame-modifiers (l/derived (fn [{:keys [modifiers objects]}] - (let [keys (->> modifiers - (keys) - (filter (fn [id] - (let [shape (get objects id)] - (or (= frame-id id) - (and (= frame-id (:frame-id shape)) - (not (= :frame (:type shape)))))))))] - (select-keys modifiers keys))) - workspace-modifiers-with-objects - =)) + (->> modifiers + (reduce + (fn [result [id modifiers]] + (let [shape (get objects id) + frame-id (:frame-id shape)] + (cond + (cph/frame-shape? shape) + (assoc-in result [id id] modifiers) + + (some? frame-id) + (assoc-in result [frame-id id] modifiers) + + :else + result))) + {}))) + workspace-modifiers-with-objects)) + +(defn workspace-modifiers-by-frame-id + [frame-id] + (l/derived #(get % frame-id) workspace-frame-modifiers =)) (defn select-bool-children [id] (l/derived (partial wsh/select-bool-children id) st/state =)) diff --git a/frontend/src/app/main/ui/workspace/shapes.cljs b/frontend/src/app/main/ui/workspace/shapes.cljs index 0b92d475e..35148dc16 100644 --- a/frontend/src/app/main/ui/workspace/shapes.cljs +++ b/frontend/src/app/main/ui/workspace/shapes.cljs @@ -110,9 +110,7 @@ :circle [:> circle-wrapper opts] :svg-raw [:> svg-raw-wrapper opts] :bool [:> bool-wrapper opts] - - ;; Only used when drawing a new frame. - :frame [:> nested-frame-wrapper opts] + :frame [:> nested-frame-wrapper opts] nil)])))