🐛 Fix restore component restore layout

This commit is contained in:
alonso.torres 2025-04-30 11:49:08 +02:00 committed by Alonso Torres
parent a2c9d307df
commit 36b78e5e21
2 changed files with 12 additions and 6 deletions

View file

@ -581,11 +581,14 @@
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(cll/generate-restore-component ldata component-id library-id page objects)) (cll/generate-restore-component ldata component-id library-id page objects))
page-id
(->> changes :redo-changes (keep :page-id) first)
frames frames
(->> changes :redo-changes (keep :frame-id))] (->> changes :redo-changes (keep :frame-id))]
(rx/of (dch/commit-changes changes) (rx/of (dch/commit-changes changes)
(ptk/data-event :layout/update {:ids frames})))))) (ptk/data-event :layout/update {:page-id page-id :ids frames}))))))
(defn restore-components (defn restore-components

View file

@ -97,15 +97,17 @@
;; Never call this directly but through the data-event `:layout/update` ;; Never call this directly but through the data-event `:layout/update`
;; Otherwise a lot of cycle dependencies could be generated ;; Otherwise a lot of cycle dependencies could be generated
(defn- update-layout-positions (defn- update-layout-positions
[{:keys [ids undo-group]}] [{:keys [page-id ids undo-group]}]
(ptk/reify ::update-layout-positions (ptk/reify ::update-layout-positions
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [objects (dsh/lookup-page-objects state) (let [page-id (or page-id (:current-page-id state))
objects (dsh/lookup-page-objects state page-id)
ids (->> ids (filter #(contains? objects %)))] ids (->> ids (filter #(contains? objects %)))]
(if (d/not-empty? ids) (if (d/not-empty? ids)
(let [modif-tree (dwm/create-modif-tree ids (ctm/reflow-modifiers))] (let [modif-tree (dwm/create-modif-tree ids (ctm/reflow-modifiers))]
(rx/of (dwm/apply-modifiers {:modifiers modif-tree (rx/of (dwm/apply-modifiers {:page-id page-id
:modifiers modif-tree
:stack-undo? true :stack-undo? true
:undo-group undo-group}))) :undo-group undo-group})))
(rx/empty)))))) (rx/empty))))))
@ -127,8 +129,9 @@
(rx/filter #(d/not-empty? %)) (rx/filter #(d/not-empty? %))
(rx/map (rx/map
(fn [data] (fn [data]
(let [ids (reduce #(into %1 (:ids %2)) #{} data)] (let [page-id (->> data (keep :page-id) first)
(update-layout-positions {:ids ids})))) ids (reduce #(into %1 (:ids %2)) #{} data)]
(update-layout-positions {:page-id page-id :ids ids}))))
(rx/take-until stopper)))))) (rx/take-until stopper))))))
(defn finalize-shape-layout (defn finalize-shape-layout