Skip to content

Commit 15b1fa5

Browse files
committed
Parse important declarations in style properties. Fixes GrapesJS#1179
1 parent 051b38d commit 15b1fa5

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/style_manager/model/Properties.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ module.exports = require('backbone')
119119
const values = value.split(' ');
120120
values.forEach((value, i) => {
121121
const property = this.at(i);
122+
if (!property) return;
122123
properties.push({ ...property.attributes, ...{ value } });
123124
});
124125
return properties;

src/style_manager/model/Property.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isUndefined } from 'underscore';
1+
import { isUndefined, isString } from 'underscore';
22

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

17+
// If true to the value will be added '!important'
18+
important: 0,
19+
1720
// If true, will be hidden by default and will show up only for targets
1821
// which require this property (via `stylable-require`)
1922
// Use case:
@@ -89,13 +92,19 @@ module.exports = require('backbone').Model.extend({
8992
*/
9093
parseValue(value) {
9194
const result = { value };
95+
const imp = '!important';
96+
97+
if (isString(value) && value.indexOf(imp) !== -1) {
98+
result.value = value.replace(imp, '').trim();
99+
result.important = 1;
100+
}
92101

93102
if (!this.get('functionName')) {
94103
return result;
95104
}
96105

97106
const args = [];
98-
let valueStr = `${value}`;
107+
let valueStr = `${result.value}`;
99108
let start = valueStr.indexOf('(') + 1;
100109
let end = valueStr.lastIndexOf(')');
101110
args.push(start);
@@ -134,6 +143,10 @@ module.exports = require('backbone').Model.extend({
134143
value = `${fn}(${value})`;
135144
}
136145

146+
if (this.get('important')) {
147+
value = `${value} !important`;
148+
}
149+
137150
return value || '';
138151
}
139152
});

test/specs/grapesjs/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ describe('GrapesJS', () => {
415415
expect(css).toEqual(`${protCss}.test2{color:red;}.test3{color:blue;}`);
416416
});
417417

418-
describe.only('Component selection', () => {
418+
describe('Component selection', () => {
419419
let editor, wrapper, el1, el2, el3;
420420

421421
beforeEach(() => {
@@ -481,7 +481,6 @@ describe('GrapesJS', () => {
481481
});
482482

483483
test('Selection events', () => {
484-
//selectAdd selectRemove selectToggle
485484
const toSpy = {
486485
selected() {},
487486
deselected() {},

0 commit comments

Comments
 (0)