0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 08:20:45 -05:00

🐛 Improve immediate-children helper

This commit is contained in:
alonso.torres 2023-10-06 12:18:06 +02:00
parent caee3160f2
commit 0468b6acca
4 changed files with 21 additions and 14 deletions

View file

@ -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)))

View file

@ -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)

View file

@ -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)

View file

@ -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)