From 9805f8b9f2210e0a28777bd817715532133f56ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 19 Jan 2021 10:14:23 +0100 Subject: [PATCH] :tada: Rename shapes inside components --- common/app/common/pages/changes.cljc | 13 ++++++++----- common/app/common/pages/common.cljc | 3 ++- frontend/src/app/main/data/workspace/libraries.cljs | 12 ++++++------ .../app/main/data/workspace/libraries_helpers.cljs | 9 +++++++-- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/common/app/common/pages/changes.cljc b/common/app/common/pages/changes.cljc index 8d3fad6fb..61d64015a 100644 --- a/common/app/common/pages/changes.cljc +++ b/common/app/common/pages/changes.cljc @@ -403,14 +403,17 @@ (defmethod process-operation :set [shape op] - (let [attr (:attr op) - val (:val op) - ignore (:ignore-touched op) - shape-ref (:shape-ref shape) - group (get component-sync-attrs attr)] + (let [attr (:attr op) + val (:val op) + ignore (:ignore-touched op) + shape-ref (:shape-ref shape) + group (get component-sync-attrs attr) + root-name? (and (= group :name-group) + (:component-root? shape))] (cond-> shape (and shape-ref group (not ignore) (not= val (get shape attr)) + (not root-name?) ;; FIXME: it's difficult to tell if the geometry changes affect ;; an individual shape inside the component, or are for ;; the whole component (in which case we shouldn't set diff --git a/common/app/common/pages/common.cljc b/common/app/common/pages/common.cljc index bfd1de496..74ef4b924 100644 --- a/common/app/common/pages/common.cljc +++ b/common/app/common/pages/common.cljc @@ -16,7 +16,8 @@ (def root uuid/zero) (def component-sync-attrs - {:fill-color :fill-group + {:name :name-group + :fill-color :fill-group :fill-opacity :fill-group :fill-color-gradient :fill-group :fill-color-ref-file :fill-group diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 1689b6366..e4db49129 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -401,15 +401,14 @@ update-new-shape (fn [new-shape original-shape] - (let [new-name - (dwc/generate-unique-name @unames (:name new-shape))] + (let [new-name (dwc/generate-unique-name @unames (:name new-shape))] - (swap! unames conj new-name) + (when (nil? (:parent-id original-shape)) + (swap! unames conj new-name)) (cond-> new-shape true (as-> $ - (assoc $ :name new-name) (geom/move $ delta) (assoc $ :frame-id frame-id) (assoc $ :parent-id @@ -417,12 +416,13 @@ (dissoc $ :touched)) (nil? (:shape-ref original-shape)) - (assoc :shape-ref (:id original-shape)) + (assoc :shape-ref (:id original-shape)) (nil? (:parent-id original-shape)) (assoc :component-id (:id original-shape) :component-file file-id - :component-root? true) + :component-root? true + :name new-name) (some? (:parent-id original-shape)) (dissoc :component-root?)))) diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index 3a4f43f0a..895521856 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -1115,9 +1115,14 @@ :val (get dest-shape attr) :ignore-touched true} - attr-group (get cp/component-sync-attrs attr)] + attr-group (get cp/component-sync-attrs attr) + + root-name? (and (= attr-group :name-group) + (:component-root? dest-shape))] + (if (or (= (get origin-shape attr) (get dest-shape attr)) - (and (touched attr-group) omit-touched?)) + (and (touched attr-group) omit-touched?) + root-name?) (recur (next attrs) roperations uoperations)