Browse Source

Update Composite props

up-style-manager
Artur Arseniev 5 years ago
parent
commit
6997fd0c47
  1. 64
      src/style_manager/model/PropertyComposite.js
  2. 18
      test/specs/style_manager/model/Properties.js

64
src/style_manager/model/PropertyComposite.js

@ -43,38 +43,44 @@ export default Property.extend({
__upProperties(prop, opts = {}) { __upProperties(prop, opts = {}) {
if (!this.__hasCustom() || opts.__up || opts.__clearIn) return; if (!this.__hasCustom() || opts.__up || opts.__clearIn) return;
if (this.isDetached()) { // if (this.isDetached()) {
const style = this.getProperties().reduce((acc, prop) => { // const style = this.getProperties().reduce((acc, prop) => {
acc[prop.getName()] = prop.hasValue({ noParent: true }) ? prop.__getFullValue() : ''; // acc[prop.getName()] = prop.hasValue({ noParent: true }) ? prop.__getFullValue() : '';
return acc; // return acc;
}, {}); // }, {});
this.__upTargetsStyle({ ...style, [prop.getName()]: prop.__getFullValue() }, opts); // this.__upTargetsStyle({ ...style, [prop.getName()]: prop.__getFullValue() }, opts);
} else { // } else {
const { __clear, ...rest } = opts; // const { __clear, ...rest } = opts;
this.upValue(this.__getFullValue(), rest); // this.upValue(this.__getFullValue(), rest);
} // }
this.__upTargetsStyleProps(opts);
}, },
__upTargetsStyle(style, opts = {}) { __upTargetsStyleProps(opts = {}) {
const toStyle = this.get('toStyle'); this.__upTargetsStyle(this.getStyleFromProps(), opts);
const { __clear } = opts; },
let newStyle = style;
if (toStyle && !__clear) { // __upTargetsStyle(style, opts = {}) {
const values = this.getValues(); // const toStyle = this.get('toStyle');
newStyle = toStyle(values, { ...opts, style }); // const { __clear } = opts;
} // let newStyle = style;
if (this.isDetached()) { // if (toStyle && !__clear) {
newStyle[this.getName()] = ''; // const values = this.getValues();
} else { // newStyle = toStyle(values, { ...opts, style });
this.getProperties().map(prop => { // }
newStyle[prop.getName()] = '';
});
}
return Property.prototype.__upTargetsStyle.call(this, newStyle, opts); // if (this.isDetached()) {
}, // newStyle[this.getName()] = '';
// } else {
// this.getProperties().map(prop => {
// newStyle[prop.getName()] = '';
// });
// }
// return Property.prototype.__upTargetsStyle.call(this, newStyle, opts);
// },
/** /**
* Get style object from current properties * Get style object from current properties
@ -165,7 +171,7 @@ export default Property.extend({
const values = this.__splitStyleName(style, this.getName(), sep); const values = this.__splitStyleName(style, this.getName(), sep);
props.forEach((prop, i) => { props.forEach((prop, i) => {
const value = values[i]; const value = values[i];
let res = !isUndefined(value) ? value : prop.getDefaultValue(); let res = !isUndefined(value) ? value : ''; // : prop.getDefaultValue();
if (props4Nums) { if (props4Nums) {
// Try to get value from a shorthand: // Try to get value from a shorthand:
@ -213,7 +219,7 @@ export default Property.extend({
getValues({ byName } = {}) { getValues({ byName } = {}) {
return this.getProperties().reduce((res, prop) => { return this.getProperties().reduce((res, prop) => {
const key = byName ? prop.getName() : prop.getId(); const key = byName ? prop.getName() : prop.getId();
res[key] = `${prop.__getFullValue({ withDefault: 1 })}`; res[key] = `${prop.__getFullValue()}`;
return res; return res;
}, {}); }, {});
}, },

18
test/specs/style_manager/model/Properties.js

@ -124,10 +124,10 @@ describe('StyleManager properties logic', () => {
[propCTest]: '33px', [propCTest]: '33px',
}) })
).toEqual({ ).toEqual({
[propATest]: '0', [propATest]: '',
[propBTest]: '0', [propBTest]: '',
[propCTest]: '33px', [propCTest]: '33px',
[propDTest]: '0', [propDTest]: '',
}); });
// null if no properties are found // null if no properties are found
@ -162,6 +162,7 @@ describe('StyleManager properties logic', () => {
[propCTest]: '3px', [propCTest]: '3px',
[propDTest]: '4px', [propDTest]: '4px',
}); });
compTypeProp.set('detached', false); compTypeProp.set('detached', false);
expect(compTypeProp.getStyleFromProps()).toEqual({ expect(compTypeProp.getStyleFromProps()).toEqual({
[propTest]: '1px 2px 3px 4px', [propTest]: '1px 2px 3px 4px',
@ -170,6 +171,17 @@ describe('StyleManager properties logic', () => {
[propCTest]: '', [propCTest]: '',
[propDTest]: '', [propDTest]: '',
}); });
compTypeProp.set('detached', true);
rule1.setStyle({ [propATest]: '10px', [propBTest]: '20px' });
obj.__upSel();
expect(compTypeProp.getStyleFromProps()).toEqual({
[propTest]: '',
[propATest]: '10px',
[propBTest]: '20px',
[propCTest]: '',
[propDTest]: '',
});
}); });
test('getStyleFromProps with custom toStyle', () => { test('getStyleFromProps with custom toStyle', () => {

Loading…
Cancel
Save