Skip to content

Commit

Permalink
Parse important declarations in style properties. Fixes GrapesJS#1179
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jun 7, 2018
1 parent 051b38d commit 15b1fa5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/style_manager/model/Properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ module.exports = require('backbone')
const values = value.split(' ');
values.forEach((value, i) => {
const property = this.at(i);
if (!property) return;
properties.push({ ...property.attributes, ...{ value } });
});
return properties;
Expand Down
17 changes: 15 additions & 2 deletions src/style_manager/model/Property.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isUndefined } from 'underscore';
import { isUndefined, isString } from 'underscore';

module.exports = require('backbone').Model.extend({
defaults: {
Expand All @@ -14,6 +14,9 @@ module.exports = require('backbone').Model.extend({
visible: true,
fixedValues: ['initial', 'inherit'],

// If true to the value will be added '!important'
important: 0,

// If true, will be hidden by default and will show up only for targets
// which require this property (via `stylable-require`)
// Use case:
Expand Down Expand Up @@ -89,13 +92,19 @@ module.exports = require('backbone').Model.extend({
*/
parseValue(value) {
const result = { value };
const imp = '!important';

if (isString(value) && value.indexOf(imp) !== -1) {
result.value = value.replace(imp, '').trim();
result.important = 1;
}

if (!this.get('functionName')) {
return result;
}

const args = [];
let valueStr = `${value}`;
let valueStr = `${result.value}`;
let start = valueStr.indexOf('(') + 1;
let end = valueStr.lastIndexOf(')');
args.push(start);
Expand Down Expand Up @@ -134,6 +143,10 @@ module.exports = require('backbone').Model.extend({
value = `${fn}(${value})`;
}

if (this.get('important')) {
value = `${value} !important`;
}

return value || '';
}
});
3 changes: 1 addition & 2 deletions test/specs/grapesjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ describe('GrapesJS', () => {
expect(css).toEqual(`${protCss}.test2{color:red;}.test3{color:blue;}`);
});

describe.only('Component selection', () => {
describe('Component selection', () => {
let editor, wrapper, el1, el2, el3;

beforeEach(() => {
Expand Down Expand Up @@ -481,7 +481,6 @@ describe('GrapesJS', () => {
});

test('Selection events', () => {
//selectAdd selectRemove selectToggle
const toSpy = {
selected() {},
deselected() {},
Expand Down

0 comments on commit 15b1fa5

Please sign in to comment.