Browse Source

Update component getName

pull/4141/head
Artur Arseniev 5 years ago
parent
commit
e1b9e5ba6f
  1. 25
      src/dom_components/model/Component.js

25
src/dom_components/model/Component.js

@ -1336,24 +1336,21 @@ export default class Component extends Model.extend(Styleable) {
* */ * */
getName() { getName() {
const { em } = this; const { em } = this;
const { type, tagName } = this.attributes; const { type, tagName, name } = this.attributes;
const cName = this.get('name'); const defName = type || tagName;
const isDiv = tagName == 'div'; const nameTag = !type && tagName;
const tag = isDiv ? 'box' : tagName;
const defName = type || tag;
const nameTag = !type && tagName && !isDiv && tagName;
const i18nPfx = 'domComponents.names.'; const i18nPfx = 'domComponents.names.';
const i18nName = cName && em && em.t(`${i18nPfx}${cName}`); const i18nName = name && em?.t(`${i18nPfx}${name}`);
const i18nNameTag = nameTag && em && em.t(`${i18nPfx}${nameTag}`); const i18nNameTag = nameTag && em?.t(`${i18nPfx}${nameTag}`);
const i18nDefName = em && (em.t(`${i18nPfx}${type}`) || em.t(`${i18nPfx}${tagName}`)); const i18nDefName = em && (em.t(`${i18nPfx}${type}`) || em.t(`${i18nPfx}${tagName}`));
return ( return (
this.get('custom-name') || // Used in Layers (when the user changes the name) this.get('custom-name') || // Used in Layers (when the user changes the name)
i18nName || i18nName || // Use local component `name` key (eg. `domComponents.names.myComponentName`)
cName || // Component name (check if there is a i18n string for it) name || // Use component `name` key
i18nNameTag || i18nNameTag || // Use local component `tagName` key (eg. `domComponents.names.div`)
capitalize(nameTag) || // Try name by tag if there is no valid type capitalize(nameTag) || // Use component `tagName` key
i18nDefName || i18nDefName || // Use local component `type` key (eg. `domComponents.names.image`)
capitalize(defName) // Use the default name capitalize(defName) // Use component `type` key
); );
} }

Loading…
Cancel
Save