Browse Source

Fix attributes/styles collide in data sources

improve-ts-datasources
Artur Arseniev 3 months ago
parent
commit
6b6f52e49d
  1. 6
      packages/core/src/domain_abstract/model/StyleableModel.ts
  2. 57
      packages/core/test/specs/data_sources/dynamic_values/attributes.ts

6
packages/core/src/domain_abstract/model/StyleableModel.ts

@ -182,9 +182,9 @@ export default class StyleableModel<T extends StyleableModelProperties = any> ex
return;
}
});
const resolvedProps = this.dataResolverWatchers.addProps({ style: newStyle }, opts) as Partial<T>;
this.set(resolvedProps, opts as any);
newStyle = resolvedProps['style']! as StyleProps;
this.set({ style: newStyle }, opts);
newStyle = this.attributes['style'] as StyleProps;
const changedKeys = Object.keys(shallowDiff(propOrig, propNew));
const diff: ObjectAny = changedKeys.reduce((acc, key) => {

57
packages/core/test/specs/data_sources/dynamic_values/attributes.ts

@ -240,6 +240,63 @@ describe('Dynamic Attributes', () => {
const input = cmp.getEl();
expect(input?.getAttribute('dynamicAttribute')).toBe(null);
});
test('attributes should not collide with styles', () => {
({ em, dsm, cmpRoot } = setupTestEditor({ config: { avoidInlineStyle: false } }));
dsm.add({
id: 'ds_id',
records: [
{ id: 'id1', value: 'test-value' },
{ id: 'id2', value: 'second-test-value' },
],
});
const cmp = cmpRoot.append({
tagName: 'input',
})[0];
cmp.addAttributes({
static: 'static-value-attr',
dynamic: {
type: DataVariableType,
defaultValue: 'default',
path: 'ds_id.id1.value',
},
});
cmp.addStyle({
static: 'static-value-style',
dynamic: {
type: DataVariableType,
defaultValue: 'default',
path: 'ds_id.id2.value',
},
});
testAttribute(cmp, 'style', 'static:static-value-style;dynamic:second-test-value;');
testAttribute(cmp, 'dynamic', 'test-value');
testAttribute(cmp, 'static', 'static-value-attr');
cmp.addAttributes({
static: 'static-value-attr-2',
dynamic: {
type: DataVariableType,
defaultValue: 'default',
path: 'ds_id.id2.value',
},
});
cmp.addStyle({
static: 'static-value-style-2',
dynamic: {
type: DataVariableType,
defaultValue: 'default',
path: 'ds_id.id1.value',
},
});
testAttribute(cmp, 'style', 'static:static-value-style-2;dynamic:test-value;');
testAttribute(cmp, 'dynamic', 'second-test-value');
testAttribute(cmp, 'static', 'static-value-attr-2');
});
});
function changeDataSourceValue(dsm: DataSourceManager, id: string) {

Loading…
Cancel
Save