Browse Source

Update getParentRules in StyleManager

up-style-manager
Artur Arseniev 5 years ago
parent
commit
8e4fba774e
  1. 6
      src/css_composer/model/CssRule.js
  2. 22
      src/style_manager/index.js

6
src/css_composer/model/CssRule.js

@ -147,7 +147,7 @@ export default class CssRule extends Model.extend(Styleable) {
const style = this.styleToString(opts); const style = this.styleToString(opts);
const singleAtRule = this.get('singleAtRule'); const singleAtRule = this.get('singleAtRule');
if ((selectors || singleAtRule) && style) { if ((selectors || singleAtRule) && (style || opts.allowEmpty)) {
result = singleAtRule ? style : `${selectors}{${style}}`; result = singleAtRule ? style : `${selectors}{${style}}`;
} }
@ -218,7 +218,9 @@ export default class CssRule extends Model.extend(Styleable) {
let result = ''; let result = '';
const atRule = this.getAtRule(); const atRule = this.getAtRule();
const block = this.getDeclaration(opts); const block = this.getDeclaration(opts);
block && (result = block); if (block || opts.allowEmpty) {
result = block;
}
if (atRule && result) { if (atRule && result) {
result = `${atRule}{${result}}`; result = `${atRule}{${result}}`;

22
src/style_manager/index.js

@ -363,13 +363,27 @@ export default () => {
if (em && target) { if (em && target) {
const cssC = em.get('CssComposer'); const cssC = em.get('CssComposer');
const cssGen = em.get('CodeManager').getGenerator('css'); const cssGen = em.get('CodeManager').getGenerator('css');
const cmp = target.toHTML ? true : target.getComponent(); const cmp = target.toHTML ? target : target.getComponent();
console.log({ cmp }); const sel = em.getSelected();
const all = cssC let cmpRules = [];
.getRules(target.getSelectors().getFullString()) let otherRules = [];
// Componente related rule
if (cmp) {
cmpRules = cssC.getRules(`#${cmp.getId()}`);
otherRules = cssC.getRules(sel.getSelectors().getFullString());
} else {
cmpRules = cssC.getRules(`#${sel.getId()}`);
otherRules = cssC.getRules(target.getSelectors().getFullString());
}
const all = otherRules
.concat(cmpRules)
.filter(rule => (state ? rule.get('state') === state : 1)) .filter(rule => (state ? rule.get('state') === state : 1))
.sort(cssGen.sortRules) .sort(cssGen.sortRules)
.reverse(); .reverse();
// Slice removes rules not related to the current device
result = all.slice(all.indexOf(target) + 1); result = all.slice(all.indexOf(target) + 1);
} }

Loading…
Cancel
Save