🐛 Fix problem with absolutes inside grid

This commit is contained in:
alonso.torres 2023-12-15 10:22:54 +01:00
parent f8dd86da34
commit 52c849ce4b
10 changed files with 57 additions and 46 deletions

View file

@ -872,10 +872,10 @@
(pcb/update-shapes [parent-id] #(ctl/add-children-to-index % ids objects to-index)))
(pcb/update-shapes parents
(fn [parent]
(fn [parent objects]
(cond-> parent
(ctl/grid-layout? parent)
(ctl/assign-cells))))
(ctl/assign-cells objects))))
(pcb/reorder-grid-children parents)

View file

@ -70,7 +70,7 @@
update-layout-ids
(->> ids
(map (d/getf objects))
(filter #(some update-layout-attr? (pcb/changed-attrs % update-fn {:attrs attrs})))
(filter #(some update-layout-attr? (pcb/changed-attrs % objects update-fn {:attrs attrs})))
(map :id))
changes (reduce

View file

@ -182,10 +182,10 @@
(-> changes
(pcb/update-shapes
[(:parent-id first-shape)]
(fn [shape]
(fn [shape objects]
(-> shape
(ctl/push-into-cell [(:id first-shape)] row column)
(ctl/assign-cells))))
(ctl/assign-cells objects))))
(pcb/reorder-grid-children [(:parent-id first-shape)])))
changes)

View file

@ -191,14 +191,14 @@
;; Temporary remove the children when moving them
frame (-> frame
(update :shapes #(d/removev ids %))
(ctl/assign-cells))
(ctl/assign-cells objects))
ids (->> ids (remove #(ctl/position-absolute? objects %)))
frame (-> frame
(update :shapes d/concat-vec ids)
(cond-> (some? cell)
(ctl/push-into-cell ids row column))
(ctl/assign-cells))]
(ctl/assign-cells objects))]
(-> modifiers
(ctm/change-property :layout-grid-rows (:layout-grid-rows frame))

View file

@ -498,7 +498,8 @@
changes (-> (pcb/add-object changes new-obj {:ignore-touched (and duplicating-component? child?)})
(pcb/amend-last-change #(assoc % :old-id (:id obj)))
(cond-> (ctl/grid-layout? objects (:parent-id obj))
(-> (pcb/update-shapes [(:parent-id obj)] (fn [shape] (-> shape ctl/assign-cells ctl/check-deassigned-cells)))
(-> (pcb/update-shapes [(:parent-id obj)] ctl/assign-cells)
(pcb/update-shapes [(:parent-id obj)] ctl/check-deassigned-cells)
(pcb/reorder-grid-children [(:parent-id obj)]))))
changes (cond-> changes

View file

@ -79,16 +79,13 @@
(-> shape
(merge initial-layout-data)
;; (cond-> (= type :grid) (-> ctl/assign-cells ctl/reorder-grid-children))
;; If the original shape is not a frame we set clip content and show-viewer to false
(cond-> (not from-frame?)
(assoc :show-content true :hide-in-viewer true)))
params (calculate-params objects (cfh/get-immediate-children objects (:id shape)) shape)]
(cond-> (merge shape params)
(= type :grid) (-> ctl/assign-cells ctl/reorder-grid-children)))
)))
(= type :grid) (-> (ctl/assign-cells objects) ctl/reorder-grid-children))))))
;; Never call this directly but through the data-event `:layout/update`
;; Otherwise a lot of cycle dependencies could be generated
@ -277,10 +274,10 @@
(rx/of (dwu/start-undo-transaction undo-id)
(dwc/update-shapes
ids
(fn [shape]
(fn [shape objects]
(case type
:row (ctl/remove-grid-row shape index)
:column (ctl/remove-grid-column shape index))))
:row (ctl/remove-grid-row shape index objects)
:column (ctl/remove-grid-column shape index objects))))
(ptk/data-event :layout/update ids)
(dwu/commit-undo-transaction undo-id))))))
@ -435,11 +432,11 @@
(dwc/update-shapes children-ids (partial fix-child-sizing objects changes))
(dwc/update-shapes
parent-ids
(fn [parent]
(fn [parent objects]
(-> parent
(fix-parent-sizing objects (set ids) changes)
(cond-> (ctl/grid-layout? parent)
(ctl/assign-cells)))))
(ctl/assign-cells objects)))))
(ptk/data-event :layout/update ids)
(dwu/commit-undo-transaction undo-id))))))
@ -475,10 +472,9 @@
(let [undo-id (js/Symbol)]
(rx/of
(dwu/start-undo-transaction undo-id)
(dwc/update-shapes
[layout-id]
(fn [shape]
(fn [shape objects]
(case mode
:auto
;; change the manual cells and move to auto
@ -492,7 +488,7 @@
(> (:column-span cell) 1))
(-> (d/update-in-when [:layout-grid-cells cell-id] assoc :shapes [] :position :auto)
(ctl/resize-cell-area (:row cell) (:column cell) (:row cell) (:column cell) 1 1)
(ctl/assign-cells)))))
(ctl/assign-cells objects)))))
shape))
:manual
@ -503,7 +499,7 @@
(cond-> shape
(contains? #{:area :auto} (:position cell))
(-> (d/assoc-in-when [:layout-grid-cells cell-id :position] :manual)
(ctl/assign-cells)))))
(ctl/assign-cells objects)))))
shape))
:area
@ -522,7 +518,7 @@
first-column
(inc (- last-row first-row))
(inc (- last-column first-column)))
(ctl/assign-cells))]
(ctl/assign-cells objects))]
(-> shape
(d/update-in-when [:layout-grid-cells (:id target-cell)] assoc :position :area))))))
@ -535,8 +531,9 @@
(ptk/reify ::update-grid-cell-position
ptk/WatchEvent
(watch [_ _ _]
(let [undo-id (js/Symbol)]
(watch [_ state _]
(let [objects (wsh/lookup-page-objects state)
undo-id (js/Symbol)]
(rx/of
(dwu/start-undo-transaction undo-id)
(dwc/update-shapes
@ -550,6 +547,6 @@
(ctl/resize-cell-area (:row prev-data) (:column prev-data)
(:row new-data) (:column new-data)
(:row-span new-data) (:column-span new-data))
(ctl/assign-cells)))))
(ctl/assign-cells objects)))))
(ptk/data-event :layout/update [layout-id])
(dwu/commit-undo-transaction undo-id))))))

View file

@ -629,7 +629,7 @@
(-> changes
(pcb/update-shapes [(:id parent)] (fn [shape] (-> shape
(assoc :layout-grid-cells layout-grid-cells)
(ctl/assign-cells))))
(ctl/assign-cells objects))))
(pcb/reorder-grid-children [(:id parent)]))))
changes

View file

@ -196,13 +196,13 @@
{::mf/wrap-props false}
[props]
(let [shape (unchecked-get props "shape")
x (unchecked-get props "x")
y (unchecked-get props "y")
width (unchecked-get props "width")
height (unchecked-get props "height")
handler (unchecked-get props "handler")
objects (mf/deref refs/workspace-page-objects)
{cell-id :id} (unchecked-get props "cell")
{:keys [row column row-span column-span]} (get-in shape [:layout-grid-cells cell-id])
@ -237,7 +237,7 @@
shape
(-> (ctl/resize-cell-area shape row column new-row new-column new-row-span new-column-span)
(ctl/assign-cells))
(ctl/assign-cells objects))
modifiers
(-> (ctm/empty)