mirror of
https://github.com/penpot/penpot.git
synced 2025-06-14 10:01:38 +02:00
🎉 Change main shape name along with component name
This commit is contained in:
parent
1719f24b57
commit
6929347da7
5 changed files with 24 additions and 18 deletions
|
@ -595,8 +595,6 @@
|
||||||
;; function. Better check it and test toroughly when activating
|
;; function. Better check it and test toroughly when activating
|
||||||
;; components-v2 mode.
|
;; components-v2 mode.
|
||||||
in-copy? (ctk/in-component-copy? shape)
|
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
|
;; For geometric attributes, there are cases in that the value changes
|
||||||
;; slightly (e.g. when rounding to pixel, or when recalculating text
|
;; slightly (e.g. when rounding to pixel, or when recalculating text
|
||||||
|
@ -607,7 +605,6 @@
|
||||||
(gsh/close-attrs? attr val shape-val))]
|
(gsh/close-attrs? attr val shape-val))]
|
||||||
|
|
||||||
(when (and group (not ignore) (not equal?)
|
(when (and group (not ignore) (not equal?)
|
||||||
(not root-name?)
|
|
||||||
(not (and ignore-geometry is-geometry?)))
|
(not (and ignore-geometry is-geometry?)))
|
||||||
;; Notify touched even if it's not copy, because it may be a main instance
|
;; Notify touched even if it's not copy, because it may be a main instance
|
||||||
(on-touched shape))
|
(on-touched shape))
|
||||||
|
@ -618,7 +615,6 @@
|
||||||
;; In some cases we need to ignore touched only if the attribute is
|
;; In some cases we need to ignore touched only if the attribute is
|
||||||
;; geometric (position, width or transformation).
|
;; geometric (position, width or transformation).
|
||||||
(and in-copy? group (not ignore) (not equal?)
|
(and in-copy? group (not ignore) (not equal?)
|
||||||
(not root-name?)
|
|
||||||
(not (and ignore-geometry is-geometry?)))
|
(not (and ignore-geometry is-geometry?)))
|
||||||
(-> (update :touched cph/set-touched-group group)
|
(-> (update :touched cph/set-touched-group group)
|
||||||
(dissoc :remote-synced?))
|
(dissoc :remote-synced?))
|
||||||
|
|
|
@ -366,6 +366,11 @@
|
||||||
|
|
||||||
(rx/of (dch/commit-changes changes)))))))
|
(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
|
(defn duplicate-component
|
||||||
"Create a new component copied from the one with the given id."
|
"Create a new component copied from the one with the given id."
|
||||||
[library-id component-id]
|
[library-id component-id]
|
||||||
|
|
|
@ -1196,14 +1196,10 @@
|
||||||
:val (get dest-shape attr)
|
:val (get dest-shape attr)
|
||||||
:ignore-touched true}
|
: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))
|
(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)
|
(recur (next attrs)
|
||||||
roperations
|
roperations
|
||||||
uoperations)
|
uoperations)
|
||||||
|
|
|
@ -639,8 +639,13 @@
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps @state)
|
(mf/deps @state)
|
||||||
(fn [new-name]
|
(fn [new-name]
|
||||||
(st/emit! (dwl/rename-component (:renaming @state) new-name))
|
(let [component-id (:renaming @state)
|
||||||
(swap! state assoc :renaming nil)))
|
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
|
cancel-rename
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
@ -1778,7 +1783,7 @@
|
||||||
(st/emit! (dwl/add-typography typography)
|
(st/emit! (dwl/add-typography typography)
|
||||||
(ptk/event ::ev/event {::ev/name "add-asset-to-library"
|
(ptk/event ::ev/event {::ev/name "add-asset-to-library"
|
||||||
:asset-type "typography"}))))
|
:asset-type "typography"}))))
|
||||||
|
|
||||||
handle-change
|
handle-change
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps file-id)
|
(mf/deps file-id)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
(:require-macros [app.main.style :refer [css]])
|
(:require-macros [app.main.style :refer [css]])
|
||||||
(:require
|
(:require
|
||||||
[app.main.data.workspace :as dw]
|
[app.main.data.workspace :as dw]
|
||||||
|
[app.main.data.workspace.libraries :as dwl]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.ui.context :as ctx]
|
[app.main.ui.context :as ctx]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
|
@ -30,13 +31,16 @@
|
||||||
(swap! local assoc :edition true)))
|
(swap! local assoc :edition true)))
|
||||||
|
|
||||||
accept-edit (fn []
|
accept-edit (fn []
|
||||||
(let [name-input (mf/ref-val name-ref)
|
(let [name-input (mf/ref-val name-ref)
|
||||||
name (dom/get-value name-input)]
|
name (str/trim (dom/get-value name-input))
|
||||||
|
main-instance? (:main-instance? shape)]
|
||||||
(on-stop-edit)
|
(on-stop-edit)
|
||||||
(swap! local assoc :edition false)
|
(swap! local assoc :edition false)
|
||||||
(st/emit! (dw/end-rename-shape)
|
(st/emit! (dw/end-rename-shape))
|
||||||
(when-not (str/empty? (str/trim name))
|
(when-not (str/empty? name)
|
||||||
(dw/update-shape (:id shape) {:name (str/trim 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 []
|
cancel-edit (fn []
|
||||||
(on-stop-edit)
|
(on-stop-edit)
|
||||||
(swap! local assoc :edition false)
|
(swap! local assoc :edition false)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue