From a4190df073879924a8885dfb114f0122964128e2 Mon Sep 17 00:00:00 2001 From: Alonso Torres Date: Thu, 26 Feb 2026 10:47:44 +0100 Subject: [PATCH] :bug: Fix problem with flex.appendChild with naturalOrdering on plugins API (#8470) --- frontend/src/app/plugins/flex.cljs | 16 ++++++++++------ frontend/src/app/plugins/shape.cljs | 9 +++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/plugins/flex.cljs b/frontend/src/app/plugins/flex.cljs index 8e41288576..9ae4525a5f 100644 --- a/frontend/src/app/plugins/flex.cljs +++ b/frontend/src/app/plugins/flex.cljs @@ -10,12 +10,12 @@ [app.common.schema :as sm] [app.common.types.shape.layout :as ctl] [app.main.data.workspace.shape-layout :as dwsl] - [app.main.data.workspace.transforms :as dwt] + [app.main.data.workspace.shapes :as dwsh] [app.main.store :as st] + [app.plugins.flags :refer [natural-child-ordering?]] [app.plugins.register :as r] [app.plugins.utils :as u] - [app.util.object :as obj] - [potok.v2.core :as ptk])) + [app.util.object :as obj])) ;; Define in `app.plugins.shape` we do this way to prevent circular dependency (def shape-proxy? nil) @@ -259,9 +259,13 @@ (u/display-not-valid :appendChild child) :else - (let [child-id (obj/get child "$id")] - (st/emit! (dwt/move-shapes-to-frame #{child-id} id nil nil) - (ptk/data-event :layout/update {:ids [id]}))))))) + (let [child-id (obj/get child "$id") + shape (u/locate-shape file-id page-id id) + index + (if (and (natural-child-ordering? plugin-id) (not (ctl/reverse? shape))) + 0 + (count (:shapes shape)))] + (st/emit! (dwsh/relocate-shapes #{child-id} id index))))))) (defn layout-child-proxy? [p] (obj/type-of? p "LayoutChildProxy")) diff --git a/frontend/src/app/plugins/shape.cljs b/frontend/src/app/plugins/shape.cljs index 5b434e9ceb..5a0c8f6634 100644 --- a/frontend/src/app/plugins/shape.cljs +++ b/frontend/src/app/plugins/shape.cljs @@ -962,9 +962,10 @@ :else (let [child-id (obj/get child "$id") is-reversed? (ctl/flex-layout? shape) - index (if (and (natural-child-ordering? plugin-id) is-reversed?) - 0 - (count (:shapes shape)))] + index + (if (or (not (natural-child-ordering? plugin-id)) is-reversed?) + 0 + (count (:shapes shape)))] (st/emit! (dwsh/relocate-shapes #{child-id} id index)))))) :insertChild @@ -987,7 +988,7 @@ (let [child-id (obj/get child "$id") is-reversed? (ctl/flex-layout? shape) index - (if (and (natural-child-ordering? plugin-id) is-reversed?) + (if (or (not (natural-child-ordering? plugin-id)) is-reversed?) (- (count (:shapes shape)) index) index)] (st/emit! (dwsh/relocate-shapes #{child-id} id index))))))