Browse Source

Don't remove styles with avoidInlineStyle #4503

pull/5201/head
Artur Arseniev 3 years ago
parent
commit
88339f66cf
  1. 28
      src/dom_components/model/Component.ts

28
src/dom_components/model/Component.ts

@ -43,7 +43,7 @@ const escapeRegExp = (str: string) => {
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
}; };
const avoidInline = (em: EditorModel) => em && em.getConfig().avoidInlineStyle; const avoidInline = (em: EditorModel) => !!em?.getConfig().avoidInlineStyle;
export const eventDrag = 'component:drag'; export const eventDrag = 'component:drag';
export const keySymbols = '__symbols'; export const keySymbols = '__symbols';
@ -564,11 +564,11 @@ export default class Component extends StyleableModel<ComponentProperties> {
* @return {Object} * @return {Object}
*/ */
getStyle(options: any = {}, optsAdd: any = {}) { getStyle(options: any = {}, optsAdd: any = {}) {
const em = this.em; const { em } = this;
const prop = isString(options) ? options : ''; const prop = isString(options) ? options : '';
const opts = prop ? optsAdd : options; const opts = prop ? optsAdd : options;
if (em && em.getConfig().avoidInlineStyle && !opts.inline) { if (avoidInline(em) && !opts.inline) {
const state = em.get('state'); const state = em.get('state');
const cc = em.Css; const cc = em.Css;
const rule = cc.getIdRule(this.getId(), { state, ...opts }); const rule = cc.getIdRule(this.getId(), { state, ...opts });
@ -592,7 +592,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
setStyle(prop: ObjectStrings = {}, opts: any = {}) { setStyle(prop: ObjectStrings = {}, opts: any = {}) {
const { opt, em } = this; const { opt, em } = this;
if (em && em.getConfig().avoidInlineStyle && !opt.temporary && !opts.inline) { if (avoidInline(em) && !opt.temporary && !opts.inline) {
const style = this.get('style') || {}; const style = this.get('style') || {};
prop = isString(prop) ? this.parseStyle(prop) : prop; prop = isString(prop) ? this.parseStyle(prop) : prop;
prop = { ...prop, ...style }; prop = { ...prop, ...style };
@ -640,19 +640,17 @@ export default class Component extends StyleableModel<ComponentProperties> {
// Check if we need an ID on the component // Check if we need an ID on the component
if (!has(attributes, 'id')) { if (!has(attributes, 'id')) {
let addId; let addId = false;
// If we don't rely on inline styling we have to check // If we don't rely on inline styling we have to check
// for the ID selector // for the ID selector
if (avoidInline(em)) { if (avoidInline(em) || !isEmpty(this.getStyle())) {
addId = sm && sm.get(id, sm.Selector.TYPE_ID); addId = !!sm?.get(id, sm.Selector.TYPE_ID);
} else if (!isEmpty(this.getStyle())) {
addId = 1;
} }
// Symbols should always have an id // Symbols should always have an id
if (this.__getSymbol() || this.__getSymbols()) { if (this.__getSymbol() || this.__getSymbols()) {
addId = 1; addId = true;
} }
if (addId) { if (addId) {
@ -1598,9 +1596,13 @@ export default class Component extends StyleableModel<ComponentProperties> {
* @private * @private
*/ */
getAttrToHTML() { getAttrToHTML() {
var attr = this.getAttributes(); const attrs = this.getAttributes();
delete attr.style;
return attr; if (avoidInline(this.em)) {
delete attrs.style;
}
return attrs;
} }
/** /**

Loading…
Cancel
Save