🐛 Restore component fix order inside flex (#6432)

This commit is contained in:
Alonso Torres 2025-05-08 13:37:59 +02:00 committed by GitHub
parent 66b47f9444
commit 7e6a621484
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 6 deletions

View file

@ -1049,6 +1049,33 @@
:id id :id id
:delta delta}))) :delta delta})))
(defn reorder-children
[changes id children]
(assert-page-id! changes)
(assert-objects! changes)
(let [page-id (::page-id (meta changes))
objects (lookup-objects changes)
shape (get objects id)
old-children (:shapes shape)
redo-change
{:type :reorder-children
:parent-id (:id shape)
:page-id page-id
:shapes children}
undo-change
{:type :reorder-children
:parent-id (:id shape)
:page-id page-id
:shapes old-children}]
(-> changes
(update :redo-changes conj redo-change)
(update :undo-changes conj undo-change)
(apply-changes-local))))
(defn reorder-grid-children (defn reorder-grid-children
[changes ids] [changes ids]
(assert-page-id! changes) (assert-page-id! changes)

View file

@ -1976,17 +1976,26 @@
[changes library-data component-id library-id current-page objects] [changes library-data component-id library-id current-page objects]
(let [{:keys [changes shape]} (prepare-restore-component changes library-data component-id current-page) (let [{:keys [changes shape]} (prepare-restore-component changes library-data component-id current-page)
parent-id (:parent-id shape) parent-id (:parent-id shape)
objects (cond-> (assoc objects (:id shape) shape)
(not (nil? parent-id)) insert-before?
(update-in [parent-id :shapes] (and (ctl/flex-layout? objects parent-id)
#(conj % (:id shape)))) (not (ctl/reverse? objects parent-id)))
objects
(-> objects
(assoc (:id shape) shape)
(cond-> (and (some? parent-id) insert-before?)
(update-in [parent-id :shapes] #(d/concat-vec [(:id shape)] %)))
(cond-> (and (some? parent-id) (not insert-before?))
(update-in [parent-id :shapes] conj (:id shape))))
;; Adds a resize-parents operation so the groups are updated. We add all the new objects ;; Adds a resize-parents operation so the groups are updated. We add all the new objects
new-objects-ids (->> changes :redo-changes (filter #(= (:type %) :add-obj)) (mapv :id)) new-objects-ids (->> changes :redo-changes (filter #(= (:type %) :add-obj)) (mapv :id))
changes (-> changes changes (-> changes
(pcb/with-objects objects) (pcb/with-objects objects)
(pcb/resize-parents new-objects-ids))] (pcb/resize-parents new-objects-ids)
;; Fix the order of the children inside the parent
(pcb/reorder-children parent-id (get-in objects [parent-id :shapes])))]
(assoc changes :file-id library-id))) (assoc changes :file-id library-id)))
(defn generate-detach-component (defn generate-detach-component