From cdaba395c400011f157d138d1e140975b12808e4 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 7 Nov 2022 18:21:36 +0100 Subject: [PATCH] :sparkles: Small fixes for flex layout --- common/src/app/common/geom/shapes/constraints.cljc | 1 - .../common/geom/shapes/flex_layout/drop_area.cljc | 14 ++------------ .../common/geom/shapes/flex_layout/positions.cljc | 1 - common/src/app/common/pages/helpers.cljc | 6 ------ common/test/common_tests/geom_shapes_test.cljc | 9 ++++----- frontend/src/app/main/data/workspace/shapes.cljs | 3 ++- frontend/src/app/main/render.cljs | 11 +++-------- .../src/app/main/ui/viewer/handoff/render.cljs | 2 -- frontend/src/app/main/ui/viewer/shapes.cljs | 1 - .../app/main/ui/workspace/viewport/selection.cljs | 3 --- 10 files changed, 11 insertions(+), 40 deletions(-) diff --git a/common/src/app/common/geom/shapes/constraints.cljc b/common/src/app/common/geom/shapes/constraints.cljc index 0b9fe0b6f..00b1f700a 100644 --- a/common/src/app/common/geom/shapes/constraints.cljc +++ b/common/src/app/common/geom/shapes/constraints.cljc @@ -81,7 +81,6 @@ cp (gsi/line-line-intersect c3 (gpt/add c3 dir-v) p0 p3)] (gpt/to-vec c3 cp))) - (defn top-vector [child-points parent-points] diff --git a/common/src/app/common/geom/shapes/flex_layout/drop_area.cljc b/common/src/app/common/geom/shapes/flex_layout/drop_area.cljc index 228e09b13..3b9ff8a58 100644 --- a/common/src/app/common/geom/shapes/flex_layout/drop_area.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/drop_area.cljc @@ -16,6 +16,7 @@ [app.common.types.shape.layout :as ctl])) (defn layout-drop-areas + "Retrieve the layout drop areas to move shapes inside layouts" [{:keys [margin-x margin-y] :as frame} layout-data children] (let [col? (ctl/col? frame) @@ -84,14 +85,7 @@ (-> (gsr/make-rect x (+ y half-point-height) width (- height half-point-height)) (assoc :index (if reverse? index (inc index))))])) - result (conj result line-area-1 line-area-2) - - ;;line-area - ;;(-> (gsr/make-rect x y width height) - ;; (assoc :index (if reverse? (inc index) index))) - ;;result (conj result line-area) - ;;result (conj result (gsr/make-rect box-x box-y box-width box-height)) - ] + result (conj result line-area-1 line-area-2)] [result parent-rect (+ x width) (+ y height)])) @@ -158,10 +152,6 @@ children (subvec children from-idx (+ from-idx num-children)) - - ;; To debug the lines - ;;result (conj result line-area) - result (first (reduce redfn-child [result line-area] (d/with-next children)))] [result (+ from-idx num-children) (+ x width) (+ y height)]))] diff --git a/common/src/app/common/geom/shapes/flex_layout/positions.cljc b/common/src/app/common/geom/shapes/flex_layout/positions.cljc index d6bc69c21..ae748d060 100644 --- a/common/src/app/common/geom/shapes/flex_layout/positions.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/positions.cljc @@ -249,7 +249,6 @@ (some? margin-y) (gpt/add (vv margin-y))) - ;; Fix position when layout is flipped corner-p (cond-> corner-p diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index 2799639a5..7bbda08e8 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -33,12 +33,6 @@ ([{:keys [type]}] (= type :frame))) -(defn layout-shape? - ([objects id] - (layout-shape? (get objects id))) - ([{:keys [type layout]}] - (and (= type :frame) layout))) - (defn group-shape? [{:keys [type]}] (= type :group)) diff --git a/common/test/common_tests/geom_shapes_test.cljc b/common/test/common_tests/geom_shapes_test.cljc index e974774f8..864bf6b8c 100644 --- a/common/test/common_tests/geom_shapes_test.cljc +++ b/common/test/common_tests/geom_shapes_test.cljc @@ -171,12 +171,11 @@ (t/testing "Transform shape with invalid selrect fails gracefully" (t/are [type selrect] (let [modifiers (ctm/move-modifiers 0 0) - shape-before (-> (create-test-shape type {:modifiers modifiers}) - (assoc :selrect selrect)) - shape-after (gsh/transform-shape shape-before)] + shape-before (-> (create-test-shape type) (assoc :selrect selrect)) + shape-after (gsh/transform-shape shape-before modifiers)] - (t/is (not= (:selrect shape-before) - (:selrect shape-after)))) + (t/is (= (:selrect shape-before) + (:selrect shape-after)))) :rect {:x 0.0 :y 0.0 :x1 0.0 :y1 0.0 :x2 ##Inf :y2 ##Inf :width ##Inf :height ##Inf} :path {:x 0.0 :y 0.0 :x1 0.0 :y1 0.0 :x2 ##Inf :y2 ##Inf :width ##Inf :height ##Inf} diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index 2f15ac226..b36930d58 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -16,6 +16,7 @@ [app.common.types.shape :as cts] [app.common.types.shape-tree :as ctst] [app.common.types.shape.interactions :as ctsi] + [app.common.types.shape.layout :as ctl] [app.common.uuid :as uuid] [app.main.data.comments :as dc] [app.main.data.workspace.changes :as dch] @@ -148,7 +149,7 @@ layout-ids (->> ids (mapcat (partial cph/get-parent-ids objects)) - (filter (partial cph/layout-shape? objects))) + (filter (partial ctl/layout? objects))) components-v2 (features/active-feature? state :components-v2) diff --git a/frontend/src/app/main/render.cljs b/frontend/src/app/main/render.cljs index c12236ad1..41073f6e2 100644 --- a/frontend/src/app/main/render.cljs +++ b/frontend/src/app/main/render.cljs @@ -81,9 +81,7 @@ [{:keys [shape] :as props}] (let [render-thumbnails? (mf/use-ctx muc/render-thumbnails) - childs (mapv #(get objects %) (:shapes shape)) - ;;shape (gsh/transform-shape shape) - ] + childs (mapv #(get objects %) (:shapes shape))] (if (and render-thumbnails? (some? (:thumbnail shape))) [:& frame/frame-thumbnail {:shape shape :bounds (:children-bounds shape)}] [:& frame-shape {:shape shape :childs childs}]))))) @@ -136,8 +134,7 @@ bool-wrapper (mf/use-memo (mf/deps objects) #(bool-wrapper-factory objects)) frame-wrapper (mf/use-memo (mf/deps objects) #(frame-wrapper-factory objects))] (when (and shape (not (:hidden shape))) - (let [;;shape (gsh/transform-shape shape) - opts #js {:shape shape} + (let [opts #js {:shape shape} svg-raw? (= :svg-raw (:type shape))] (if-not svg-raw? [:> shape-container {:shape shape} @@ -167,9 +164,7 @@ [objects object] (let [shapes (cph/get-immediate-children objects) srect (gsh/selection-rect shapes) - object (merge object (select-keys srect [:x :y :width :height])) - ;; object (gsh/transform-shape object) - ] + object (merge object (select-keys srect [:x :y :width :height]))] (assoc object :fill-color "#f0f0f0"))) (defn adapt-objects-for-shape diff --git a/frontend/src/app/main/ui/viewer/handoff/render.cljs b/frontend/src/app/main/ui/viewer/handoff/render.cljs index 0fc20987e..d32844940 100644 --- a/frontend/src/app/main/ui/viewer/handoff/render.cljs +++ b/frontend/src/app/main/ui/viewer/handoff/render.cljs @@ -88,8 +88,6 @@ [props] (let [shape (unchecked-get props "shape") childs (mapv #(get objects %) (:shapes shape)) - ;;shape (gsh/transform-shape shape) - props (-> (obj/create) (obj/merge! props) (obj/merge! #js {:shape shape diff --git a/frontend/src/app/main/ui/viewer/shapes.cljs b/frontend/src/app/main/ui/viewer/shapes.cljs index 2b2522078..e43ff5780 100644 --- a/frontend/src/app/main/ui/viewer/shapes.cljs +++ b/frontend/src/app/main/ui/viewer/shapes.cljs @@ -350,7 +350,6 @@ [props] (let [shape (obj/get props "shape") childs (mapv #(get objects %) (:shapes shape)) - ;;shape (gsh/transform-shape shape) props (obj/merge! #js {} props #js {:shape shape :childs childs diff --git a/frontend/src/app/main/ui/workspace/viewport/selection.cljs b/frontend/src/app/main/ui/workspace/viewport/selection.cljs index b42fbbc36..0a1cb7821 100644 --- a/frontend/src/app/main/ui/workspace/viewport/selection.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/selection.cljs @@ -341,7 +341,6 @@ (let [shape (mf/use-memo (mf/deps shapes) #(->> shapes - #_(map gsh/transform-shape) (gsh/selection-rect) (cts/setup-shape))) on-resize @@ -369,7 +368,6 @@ (let [shape (mf/use-memo (mf/deps shapes) #(->> shapes - #_(map gsh/transform-shape) (gsh/selection-rect) (cts/setup-shape)))] @@ -384,7 +382,6 @@ (mf/defc single-handlers [{:keys [shape zoom color disable-handlers] :as props}] (let [shape-id (:id shape) - ;;shape (gsh/transform-shape shape) on-resize (fn [current-position _initial-position event]