From 0468b6acca3cd4ddfe8194dd57434bd6ac998971 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 6 Oct 2023 12:18:06 +0200 Subject: [PATCH] :bug: Improve immediate-children helper --- .../src/app/common/geom/shapes/min_size_layout.cljc | 10 ++++------ common/src/app/common/pages/helpers.cljc | 13 ++++++++++--- .../src/app/main/ui/workspace/viewport/debug.cljs | 4 +++- .../ui/workspace/viewport/grid_layout_editor.cljs | 8 ++++---- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/common/src/app/common/geom/shapes/min_size_layout.cljc b/common/src/app/common/geom/shapes/min_size_layout.cljc index 7bd3b088a..9b2d5bcdf 100644 --- a/common/src/app/common/geom/shapes/min_size_layout.cljc +++ b/common/src/app/common/geom/shapes/min_size_layout.cljc @@ -7,7 +7,6 @@ (ns app.common.geom.shapes.min-size-layout (:require [app.common.data :as d] - [app.common.geom.shapes.common :as gco] [app.common.geom.shapes.flex-layout.bounds :as fb] [app.common.geom.shapes.flex-layout.layout-data :as fd] [app.common.geom.shapes.grid-layout.bounds :as gb] @@ -22,15 +21,14 @@ (cond (and (ctl/fill-width? child) (ctl/flex-layout? child)) - (gpo/width-points (fb/layout-content-bounds bounds child (->> child :shapes (map (d/getf objects))) objects)) + (let [children (->> child :shapes (map (d/getf objects)))] + (gpo/width-points (fb/layout-content-bounds bounds child children objects))) (and (ctl/fill-width? child) (ctl/grid-layout? child)) (let [children - (->> (cph/get-immediate-children objects (:id child)) - (remove :hidden) - (remove gco/invalid-geometry?) - (map (fn [child] [@(get bounds (:id child)) child]))) + (->> (cph/get-immediate-children objects (:id child) {:remove-hidden true}) + (map #(vector @(get bounds (:id %)) %))) layout-data (gd/calc-layout-data child @(get bounds (:id child)) children bounds objects true)] (gpo/width-points (gb/layout-content-bounds bounds child layout-data))) diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index c0885d892..4d79957b0 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -8,6 +8,7 @@ (:require [app.common.data :as d] [app.common.data.macros :as dm] + [app.common.geom.shapes.common :as gco] [app.common.types.components-list :as ctkl] [app.common.types.pages-list :as ctpl] [app.common.types.shape.layout :as ctl] @@ -266,12 +267,18 @@ (defn get-immediate-children "Retrieve resolved shape objects that are immediate children of the specified shape-id" - ([objects] (get-immediate-children objects uuid/zero)) - ([objects shape-id] + ([objects] (get-immediate-children objects uuid/zero nil)) + ([objects shape-id] (get-immediate-children objects shape-id nil)) + ([objects shape-id {:keys [remove-hidden remove-blocked] :or {remove-hidden false remove-blocked false}}] (let [lookup (d/getf objects)] (->> (lookup shape-id) (:shapes) - (keep lookup))))) + (keep (fn [cid] + (when-let [child (lookup cid)] + (when (and (or (not remove-hidden) (not (:hidden child))) + (or (not remove-blocked) (not (:blocked child)))) + child)))) + (remove gco/invalid-geometry?))))) (declare indexed-shapes) diff --git a/frontend/src/app/main/ui/workspace/viewport/debug.cljs b/frontend/src/app/main/ui/workspace/viewport/debug.cljs index 0e870a275..8079d6121 100644 --- a/frontend/src/app/main/ui/workspace/viewport/debug.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/debug.cljs @@ -41,9 +41,11 @@ (remove :hidden)) bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points])) + children+bounds (->> children (map (fn [shape] [@(get bounds (:id shape)) shape]))) + grid-layout-data (when (ctl/grid-layout? shape) - (gsg/calc-layout-data shape (:points shape) children bounds objects)) + (gsg/calc-layout-data shape (:points shape) children+bounds bounds objects)) layout-bounds (cond (ctl/flex-layout? shape) diff --git a/frontend/src/app/main/ui/workspace/viewport/grid_layout_editor.cljs b/frontend/src/app/main/ui/workspace/viewport/grid_layout_editor.cljs index 7f96444da..8d7f64886 100644 --- a/frontend/src/app/main/ui/workspace/viewport/grid_layout_editor.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/grid_layout_editor.cljs @@ -748,10 +748,10 @@ objects (-> objects (gsh/apply-objects-modifiers (select-keys modifiers ids)) (gsh/update-shapes-geometry (reverse ids)))] - (->> (:shapes shape) - (map (d/getf objects)) - (remove :hidden) - (map #(vector (gpo/parent-coords-bounds (:points %) (:points shape)) %)))))) + (->> (cph/get-immediate-children objects (:id shape)) + (keep (fn [child] + (when-not (:hidden child) + [(gpo/parent-coords-bounds (:points child) (:points shape)) child]))))))) children (hooks/use-equal-memo children)