diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 8467b6974b..bf29c06e31 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -1289,6 +1289,19 @@ (into #{} xform shape-and-parents)) (when component-id #{component-id}))) +(defmethod components-changed :reorder-children + [file-data {:keys [parent-id page-id component-id shapes]}] + (if page-id + (let [page (ctpl/get-page file-data page-id) + parents (map (partial ctn/get-shape page) + (cons parent-id (cfh/get-parent-ids (:objects page) parent-id))) + xform (comp (filter :main-instance) + (map :component-id))] + ;; a reorder that keeps the order changes nothing + (when (not= (vec shapes) (vec (:shapes (ctn/get-shape page parent-id)))) + (into #{} xform parents))) + (when component-id #{component-id}))) + (defmethod components-changed :restore-component [_ {:keys [id]}] #{id}) diff --git a/common/test/common_tests/logic/comp_sync_test.cljc b/common/test/common_tests/logic/comp_sync_test.cljc index 98b8b06f26..f46d5584b4 100644 --- a/common/test/common_tests/logic/comp_sync_test.cljc +++ b/common/test/common_tests/logic/comp_sync_test.cljc @@ -1166,6 +1166,19 @@ (ch/components-changed (:data file) (change {:type :assign :value {:opacity 0.5}})))) (t/is (nil? (ch/components-changed (:data file) (change {:type :assign :value {:interactions []}})))))) +(t/deftest reordering-the-children-of-a-main-changes-its-component + (let [file (-> (thf/sample-file :file1) + (tho/add-component-with-many-children-and-copy :component1 :main-root + [:main-child1 :main-child2] :copy-root)) + page (thf/current-page file) + root (ths/get-shape file :main-root) + change (fn [shapes] + {:type :reorder-children :parent-id (:id root) :page-id (:id page) :shapes shapes})] + (t/is (= #{(thi/id :component1)} + (ch/components-changed (:data file) (change (vec (reverse (:shapes root))))))) + (t/testing "a reorder that keeps the order changes nothing" + (t/is (empty? (ch/components-changed (:data file) (change (:shapes root)))))))) + (t/deftest a-copy-grid-with-its-own-cells-orders-its-children-by-their-flow (let [page-id (thi/new-id! :page) grid {:id (thi/new-id! :grid) :type :frame :layout :grid :layout-grid-dir :row diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 5bf8d32722..4180ea2b12 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2182,6 +2182,13 @@ (t/is (seq turned)) (t/is (every? geom/decomposes? turned)))) +(t/deftest pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false + :layout-item-margins false :grid-square true :rich-variants false + :layout-children true :grid-empty false :layout-copies false :text true}] + :ops [[:make-variant] [:make-variant 6] [:combine] [:make-variant 11] [:combine] + [:remove-child 9] [:grid-direction 0 0 13] [:update-main]]})))) + (t/deftest moving-a-flex-copy-child-after-a-switch-resized-its-sibling-authors-no-geometry (t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false :layout-item-margins false :grid-square false :rich-variants true