0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 00:10:11 -05:00

🎉 Change main shape name along with component name

This commit is contained in:
Pablo Alba 2023-05-23 13:46:42 +02:00 committed by Andrés Moya
parent 1719f24b57
commit 6929347da7
5 changed files with 24 additions and 18 deletions

View file

@ -595,8 +595,6 @@
;; function. Better check it and test toroughly when activating
;; components-v2 mode.
in-copy? (ctk/in-component-copy? shape)
root-name? (and (= group :name-group)
(:component-root? shape))
;; For geometric attributes, there are cases in that the value changes
;; slightly (e.g. when rounding to pixel, or when recalculating text
@ -607,7 +605,6 @@
(gsh/close-attrs? attr val shape-val))]
(when (and group (not ignore) (not equal?)
(not root-name?)
(not (and ignore-geometry is-geometry?)))
;; Notify touched even if it's not copy, because it may be a main instance
(on-touched shape))
@ -618,7 +615,6 @@
;; In some cases we need to ignore touched only if the attribute is
;; geometric (position, width or transformation).
(and in-copy? group (not ignore) (not equal?)
(not root-name?)
(not (and ignore-geometry is-geometry?)))
(-> (update :touched cph/set-touched-group group)
(dissoc :remote-synced?))

View file

@ -366,6 +366,11 @@
(rx/of (dch/commit-changes changes)))))))
(defn rename-component-and-main-instance
[component-id shape-id name page-id]
(st/emit! (rename-component component-id name)
(dch/update-shapes [shape-id] #(merge % {:name name}) {:page-id page-id :stack-undo? true})))
(defn duplicate-component
"Create a new component copied from the one with the given id."
[library-id component-id]

View file

@ -1196,14 +1196,10 @@
:val (get dest-shape attr)
:ignore-touched true}
attr-group (get cp/component-sync-attrs attr)
root-name? (and (= attr-group :name-group)
(:component-root? dest-shape))]
attr-group (get cp/component-sync-attrs attr)]
(if (or (= (get origin-shape attr) (get dest-shape attr))
(and (touched attr-group) omit-touched?)
root-name?)
(and (touched attr-group) omit-touched?))
(recur (next attrs)
roperations
uoperations)

View file

@ -639,8 +639,13 @@
(mf/use-fn
(mf/deps @state)
(fn [new-name]
(st/emit! (dwl/rename-component (:renaming @state) new-name))
(swap! state assoc :renaming nil)))
(let [component-id (:renaming @state)
component (dm/get-in file [:components component-id])
main-instance-id (:main-instance-id component)
main-instance-page (:main-instance-page component)]
(dwl/rename-component-and-main-instance component-id main-instance-id new-name main-instance-page)
(swap! state assoc :renaming nil))))
cancel-rename
(mf/use-fn
@ -1778,7 +1783,7 @@
(st/emit! (dwl/add-typography typography)
(ptk/event ::ev/event {::ev/name "add-asset-to-library"
:asset-type "typography"}))))
handle-change
(mf/use-fn
(mf/deps file-id)

View file

@ -8,6 +8,7 @@
(:require-macros [app.main.style :refer [css]])
(:require
[app.main.data.workspace :as dw]
[app.main.data.workspace.libraries :as dwl]
[app.main.store :as st]
[app.main.ui.context :as ctx]
[app.util.dom :as dom]
@ -30,13 +31,16 @@
(swap! local assoc :edition true)))
accept-edit (fn []
(let [name-input (mf/ref-val name-ref)
name (dom/get-value name-input)]
(let [name-input (mf/ref-val name-ref)
name (str/trim (dom/get-value name-input))
main-instance? (:main-instance? shape)]
(on-stop-edit)
(swap! local assoc :edition false)
(st/emit! (dw/end-rename-shape)
(when-not (str/empty? (str/trim name))
(dw/update-shape (:id shape) {:name (str/trim name)})))))
(st/emit! (dw/end-rename-shape))
(when-not (str/empty? name)
(if main-instance?
(dwl/rename-component-and-main-instance (:component-id shape) (:id shape) name nil)
(st/emit! (dw/update-shape (:id shape) {:name name}))))))
cancel-edit (fn []
(on-stop-edit)
(swap! local assoc :edition false)