Browse Source

Add canClear method to Property

up-style-manager
Artur Arseniev 4 years ago
parent
commit
c962b92f89
  1. 2
      src/style_manager/config/config.js
  2. 25
      src/style_manager/model/Property.js
  3. 5
      src/style_manager/model/PropertyComposite.js

2
src/style_manager/config/config.js

@ -4,7 +4,7 @@ export default {
{ {
name: 'General', name: 'General',
open: false, open: false,
properties: ['float', 'display', 'position', 'top', 'right', 'left', 'bottom'], properties: ['display', 'float', 'position', 'top', 'right', 'left', 'bottom'],
}, },
{ {
name: 'Flex', name: 'Flex',

25
src/style_manager/model/Property.js

@ -126,6 +126,14 @@ export default class Property extends Model {
return !isUndefined(val) && val !== '' && !parentValue; return !isUndefined(val) && val !== '' && !parentValue;
} }
/**
* Indicates if the current value is coming from a parent target (eg. another CSSRule).
* @returns {Boolean}
*/
hasValueParent() {
return this.hasValue() && !this.hasValue({ noParent: true });
}
/** /**
* Get the CSS style object of the property. * Get the CSS style object of the property.
* @param {Object} [opts={}] Options * @param {Object} [opts={}] Options
@ -182,6 +190,23 @@ export default class Property extends Model {
this._up(this.__getClearProps(), { ...opts, __clear: true }); this._up(this.__getClearProps(), { ...opts, __clear: true });
} }
/**
* Indicates if the current value comes directly from the selected target and so can be cleared.
* @returns {Boolean}
*/
canClear() {
const parent = this.getParent();
return parent ? parent.__canClearProp(this) : this.hasValue({ noParent: true });
}
/**
* If the current property is a sub-property, this will return the parent Property.
* @returns {[Property]|null}
*/
getParent() {
return this.__getParentProp() || null;
}
__parseValue(value, opts) { __parseValue(value, opts) {
return this.parseValue(value, opts); return this.parseValue(value, opts);
} }

5
src/style_manager/model/PropertyComposite.js

@ -43,6 +43,7 @@ export default class PropertyComposite extends Property {
join: null, join: null,
fromStyle: null, fromStyle: null,
toStyle: null, toStyle: null,
full: true,
}; };
} }
@ -354,6 +355,10 @@ export default class PropertyComposite extends Property {
return this.get('properties').getFullValue(); return this.get('properties').getFullValue();
} }
__canClearProp(prop) {
return this.isDetached() && prop.hasValue({ noParent: true });
}
} }
/** /**
* [Property]: property.html * [Property]: property.html

Loading…
Cancel
Save