Browse Source

Preserve custom styles on text component change. Fixes #5442

pull/5504/head
Artur Arseniev 2 years ago
parent
commit
0e6e1dbd34
  1. 16
      src/dom_components/model/Components.ts

16
src/dom_components/model/Components.ts

@ -18,13 +18,17 @@ export const getComponentIds = (cmp?: Component | Component[] | Components, res:
return res; return res;
}; };
const getComponentsFromDefs = (items: any, all: ObjectAny = {}, opts: any = {}) => { const getComponentsFromDefs = (
items: ReturnType<Components['parseString']>,
all: ReturnType<ComponentManager['allById']> = {},
opts: any = {}
) => {
opts.visitedCmps = opts.visitedCmps || {}; opts.visitedCmps = opts.visitedCmps || {};
const { visitedCmps } = opts; const { visitedCmps } = opts;
const itms = isArray(items) ? items : [items]; const itms = isArray(items) ? items : [items];
return itms.map(item => { return itms.map(item => {
const { attributes = {}, components, tagName } = item; const { attributes = {}, components, tagName, style } = item;
let { id, draggable, ...restAttr } = attributes; let { id, draggable, ...restAttr } = attributes;
let result = item; let result = item;
@ -35,9 +39,11 @@ const getComponentsFromDefs = (items: any, all: ObjectAny = {}, opts: any = {})
// Update the component if exists already // Update the component if exists already
if (all[id]) { if (all[id]) {
result = all[id]; result = all[id] as any;
tagName && result.set({ tagName }, { ...opts, silent: true }); const cmp = result as unknown as Component;
keys(restAttr).length && result.addAttributes(restAttr, { ...opts }); tagName && cmp.set({ tagName }, { ...opts, silent: true });
keys(restAttr).length && cmp.addAttributes(restAttr, { ...opts });
keys(style).length && cmp.addStyle(style, opts);
} }
} else { } else {
// Found another component with the same ID, treat it as a new component // Found another component with the same ID, treat it as a new component

Loading…
Cancel
Save