From 9e8038a96509797281e1c5f624dc69dc8670b85a Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 27 Feb 2023 11:06:28 +0400 Subject: [PATCH] Add new `noCustom` option to `Component.getName()` --- src/dom_components/model/Component.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/dom_components/model/Component.ts b/src/dom_components/model/Component.ts index 0349c1831..c4964fa19 100644 --- a/src/dom_components/model/Component.ts +++ b/src/dom_components/model/Component.ts @@ -1443,7 +1443,14 @@ export default class Component extends StyleableModel { * Get the name of the component * @return {String} * */ - getName() { + getName( + opts: { + /** + * Avoid custom name assigned to the component. + */ + noCustom?: boolean; + } = {} + ) { const { em } = this; const { type, tagName, name } = this.attributes; const defName = type || tagName; @@ -1452,8 +1459,10 @@ export default class Component extends StyleableModel { const i18nName = name && em?.t(`${i18nPfx}${name}`); const i18nNameTag = nameTag && em?.t(`${i18nPfx}${nameTag}`); const i18nDefName = em && (em.t(`${i18nPfx}${type}`) || em.t(`${i18nPfx}${tagName}`)); + const customName = this.get('custom-name'); + return ( - this.get('custom-name') || // Used in Layers (when the user changes the name) + (!opts.noCustom ? customName : '') || // Used in Layers (when the user changes the name) i18nName || // Use local component `name` key (eg. `domComponents.names.myComponentName`) name || // Use component `name` key i18nNameTag || // Use local component `tagName` key (eg. `domComponents.names.div`)