From 387c5e67f393d6a3306b19461f57890e35e3bd94 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Wed, 2 Apr 2025 19:54:48 +0200 Subject: [PATCH] :bug: Fix flick on create variant (#6217) --- .../src/app/common/files/shapes_helpers.cljc | 9 +++++++-- .../src/app/main/data/workspace/shapes.cljs | 6 +++++- .../src/app/main/data/workspace/variants.cljs | 18 +++++++++--------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/common/src/app/common/files/shapes_helpers.cljc b/common/src/app/common/files/shapes_helpers.cljc index 772b71e63..e4f265c4c 100644 --- a/common/src/app/common/files/shapes_helpers.cljc +++ b/common/src/app/common/files/shapes_helpers.cljc @@ -62,6 +62,10 @@ changes id parent-id objects selected index frame-name without-fill? nil)) ([changes id parent-id objects selected index frame-name without-fill? target-cell-id] + (prepare-create-artboard-from-selection + changes id parent-id objects selected index frame-name without-fill? target-cell-id nil)) + + ([changes id parent-id objects selected index frame-name without-fill? target-cell-id delta] (when-let [selected-objs (->> selected (map (d/getf objects)) (not-empty))] @@ -99,10 +103,11 @@ :id)) target-cell-id) + attrs {:type :frame - :x (:x srect) - :y (:y srect) + :x (cond-> (:x srect) delta (+ (:x delta))) + :y (cond-> (:y srect) delta (+ (:y delta))) :width (:width srect) :height (:height srect)} diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index b65989e26..7b9fd48e0 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -237,6 +237,8 @@ ([id parent-id index] (create-artboard-from-selection id parent-id index nil)) ([id parent-id index name] + (create-artboard-from-selection id parent-id index name nil)) + ([id parent-id index name delta] (ptk/reify ::create-artboard-from-selection ptk/WatchEvent (watch [it state _] @@ -260,7 +262,9 @@ selected index name - false) + false + nil + delta) undo-id (js/Symbol)] diff --git a/frontend/src/app/main/data/workspace/variants.cljs b/frontend/src/app/main/data/workspace/variants.cljs index 08c5fa985..b88f18ff4 100644 --- a/frontend/src/app/main/data/workspace/variants.cljs +++ b/frontend/src/app/main/data/workspace/variants.cljs @@ -11,6 +11,7 @@ [app.common.files.changes-builder :as pcb] [app.common.files.helpers :as cfh] [app.common.files.variant :as cfv] + [app.common.geom.point :as gpt] [app.common.logic.variant-properties :as clvp] [app.common.logic.variants :as clv] [app.common.types.component :as ctc] @@ -248,6 +249,12 @@ :stroke-color "#bb97d8" ;; todo use color var? :stroke-opacity 1 :stroke-width 2} + + ;; Move the position of the variant container so the main shape doesn't + ;; change its position + delta (if (ctsl/any-layout? parent) + (gpt/point 0 0) + (gpt/point -30 -30)) undo-id (js/Symbol)] @@ -261,20 +268,13 @@ (dwl/rename-component component-id name)) ;; Create variant container - (dwsh/create-artboard-from-selection variant-id) + (dwsh/create-artboard-from-selection variant-id nil nil nil delta) (cl/remove-all-fills variant-vec {:color clr/black :opacity 1}) (dwsl/create-layout-from-id variant-id :flex) (dwsh/update-shapes variant-vec #(merge % cont-props)) (dwsh/update-shapes [main-instance-id] #(merge % main-props)) (cl/add-stroke variant-vec stroke-props) - (set-variant-id component-id variant-id) - - ;; Set the position of the variant container so the main shape doesn't - ;; change its position - (when-not (ctsl/any-layout? parent) - (dwt/update-position variant-id - {:x (- (:x main) 30) :y (- (:y main) 30)} - {:absolute? true}))) + (set-variant-id component-id variant-id)) ;; Add the necessary number of new properties, with default values (rx/from