Browse Source

Fix regressions in style manager

pull/856/head
Artur Arseniev 9 years ago
parent
commit
ba1e6414e9
  1. 133
      dist/grapes.js
  2. 6
      dist/grapes.min.js
  3. 2
      package-lock.json
  4. 2
      package.json
  5. 8
      test/specs/style_manager/view/PropertyCompositeView.js

133
dist/grapes.js

@ -4977,6 +4977,7 @@ module.exports = Backbone.View.extend({
} }
em && em.on('update:component:style:' + this.property, this.targetUpdated); em && em.on('update:component:style:' + this.property, this.targetUpdated);
//em && em.on(`styleable:change:${this.property}`, this.targetUpdated);
this.listenTo(this.propTarget, 'update', this.targetUpdated); this.listenTo(this.propTarget, 'update', this.targetUpdated);
this.listenTo(model, 'destroy remove', this.remove); this.listenTo(model, 'destroy remove', this.remove);
this.listenTo(model, 'change:value', this.modelValueChanged); this.listenTo(model, 'change:value', this.modelValueChanged);
@ -5024,9 +5025,9 @@ module.exports = Backbone.View.extend({
/** /**
* Clear the property from the target * Clear the property from the target
*/ */
clear: function clear() { clear: function clear(e) {
var target = this.getTargetModel(); e && e.stopPropagation();
target.removeStyle(this.model.get('property')); this.model.clearValue();
this.targetUpdated(); this.targetUpdated();
}, },
@ -5365,7 +5366,7 @@ module.exports = Backbone.View.extend({
* */ * */
setValue: function setValue(value) { setValue: function setValue(value) {
var model = this.model; var model = this.model;
var val = value || model.getDefaultValue(); var val = (0, _underscore.isUndefined)(value) ? model.getDefaultValue() : value;
var input = this.getInputEl(); var input = this.getInputEl();
input && (input.value = val); input && (input.value = val);
}, },
@ -16475,6 +16476,8 @@ module.exports = __webpack_require__(0).Collection.extend(_TypeableCollection2.d
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _underscore = __webpack_require__(1);
module.exports = __webpack_require__(0).Model.extend({ module.exports = __webpack_require__(0).Model.extend({
defaults: { defaults: {
name: '', name: '',
@ -16511,6 +16514,18 @@ module.exports = __webpack_require__(0).Model.extend({
}, },
/**
* Clear the value
* @return {this}
*/
clearValue: function clearValue() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
this.set({ value: undefined }, opts);
return this;
},
/** /**
* Update value * Update value
* @param {any} value * @param {any} value
@ -16601,13 +16616,13 @@ module.exports = __webpack_require__(0).Model.extend({
*/ */
getFullValue: function getFullValue(val) { getFullValue: function getFullValue(val) {
var fn = this.get('functionName'); var fn = this.get('functionName');
var value = val || this.get('value'); var value = (0, _underscore.isUndefined)(val) ? this.get('value') : val;
if (fn) { if (fn && !(0, _underscore.isUndefined)(value)) {
value = fn + '(' + value + ')'; value = fn + '(' + value + ')';
} }
return value; return value || '';
} }
}); });
@ -16636,6 +16651,7 @@ module.exports = Backbone.View.extend({
this.onChange = o.onChange; this.onChange = o.onChange;
this.onInputRender = o.onInputRender || {}; this.onInputRender = o.onInputRender || {};
this.customValue = o.customValue || {}; this.customValue = o.customValue || {};
this.properties = [];
var coll = this.collection; var coll = this.collection;
this.listenTo(coll, 'add', this.addTo); this.listenTo(coll, 'add', this.addTo);
this.listenTo(coll, 'reset', this.render); this.listenTo(coll, 'reset', this.render);
@ -16661,6 +16677,7 @@ module.exports = Backbone.View.extend({
view.render(); view.render();
var el = view.el; var el = view.el;
this.properties.push(view);
if (frag) { if (frag) {
frag.appendChild(el); frag.appendChild(el);
@ -16671,6 +16688,7 @@ module.exports = Backbone.View.extend({
render: function render() { render: function render() {
var _this = this; var _this = this;
this.properties = [];
var fragment = document.createDocumentFragment(); var fragment = document.createDocumentFragment();
this.collection.each(function (model) { this.collection.each(function (model) {
return _this.add(model, fragment); return _this.add(model, fragment);
@ -16690,9 +16708,11 @@ module.exports = Backbone.View.extend({
/* WEBPACK VAR INJECTION */(function(Backbone) { /* WEBPACK VAR INJECTION */(function(Backbone) {
var InputNumber = __webpack_require__(18); var InputNumber = __webpack_require__(18);
var PropertyView = __webpack_require__(5);
var $ = Backbone.$; var $ = Backbone.$;
var timeout = void 0;
module.exports = __webpack_require__(5).extend({ module.exports = PropertyView.extend({
templateInput: function templateInput() { templateInput: function templateInput() {
return ''; return '';
}, },
@ -16702,6 +16722,8 @@ module.exports = __webpack_require__(5).extend({
this.listenTo(model, 'el:change', this.elementUpdated); this.listenTo(model, 'el:change', this.elementUpdated);
}, },
setValue: function setValue(value) { setValue: function setValue(value) {
var parsed = this.model.parseValue(value);
value = '' + parsed.value + parsed.unit;
this.inputInst.setValue(value, { silent: 1 }); this.inputInst.setValue(value, { silent: 1 });
}, },
onRender: function onRender() { onRender: function onRender() {
@ -16872,6 +16894,13 @@ module.exports = PropertyView.extend({
PropertyView.prototype.inputValueChanged.apply(this, args); PropertyView.prototype.inputValueChanged.apply(this, args);
} }
}, },
clear: function clear(e) {
var props = this.properties;
props && props.forEach(function (propView) {
return propView.clear();
});
PropertyView.prototype.clear.apply(this, arguments);
},
/** /**
@ -16881,6 +16910,7 @@ module.exports = PropertyView.extend({
var model = this.model; var model = this.model;
var props = model.get('properties') || []; var props = model.get('properties') || [];
var self = this; var self = this;
this.properties = [];
if (props.length) { if (props.length) {
if (!this.$input) { if (!this.$input) {
@ -16905,6 +16935,7 @@ module.exports = PropertyView.extend({
var PropertiesView = __webpack_require__(13); var PropertiesView = __webpack_require__(13);
var propsView = new PropertiesView(this.getPropsConfig()); var propsView = new PropertiesView(this.getPropsConfig());
this.$props = propsView.render().$el; this.$props = propsView.render().$el;
this.properties = propsView.properties;
this.$el.find('#' + this.pfx + 'input-holder').append(this.$props); this.$el.find('#' + this.pfx + 'input-holder').append(this.$props);
} }
} }
@ -17218,7 +17249,8 @@ module.exports = Input.extend({
var force = 0; var force = 0;
var opt = opts || {}; var opt = opts || {};
var model = this.model; var model = this.model;
var val = value !== '' ? value : model.get('defaults'); var defValue = ''; //model.get('defaults');
var val = !(0, _underscore.isUndefined)(value) ? value : defValue;
var units = model.get('units') || []; var units = model.get('units') || [];
var unit = model.get('unit') || units.length && units[0] || ''; var unit = model.get('unit') || units.length && units[0] || '';
var max = model.get('max'); var max = model.get('max');
@ -17238,7 +17270,7 @@ module.exports = Input.extend({
var valCopy = val + ''; var valCopy = val + '';
val += ''; // Make it suitable for replace val += ''; // Make it suitable for replace
val = parseFloat(val.replace(',', '.')); val = parseFloat(val.replace(',', '.'));
val = !isNaN(val) ? val : model.get('defaults'); val = !isNaN(val) ? val : defValue;
var uN = valCopy.replace(val, ''); var uN = valCopy.replace(val, '');
// Check if exists as unit // Check if exists as unit
if (_.indexOf(units, uN) >= 0) unit = uN; if (_.indexOf(units, uN) >= 0) unit = uN;
@ -17246,9 +17278,8 @@ module.exports = Input.extend({
} }
} }
if (typeof max !== 'undefined' && max !== '') val = val > max ? max : val; if (!(0, _underscore.isUndefined)(max) && max !== '') val = val > max ? max : val;
if (!(0, _underscore.isUndefined)(min) && min !== '') val = val < min ? min : val;
if (typeof min !== 'undefined' && min !== '') val = val < min ? min : val;
return { return {
force: force, force: force,
@ -17516,7 +17547,7 @@ module.exports = {
methods[method](body, 'mouseover', this.onHover); methods[method](body, 'mouseover', this.onHover);
methods[method](body, 'mouseout', this.onOut); methods[method](body, 'mouseout', this.onOut);
methods[method](body, 'click', this.onClick); methods[method](body, 'click', this.onClick);
methods[method](win, 'scroll', this.onFrameScroll); methods[method](win, 'scroll resize', this.onFrameScroll);
methods[method](win, 'keydown', this.onKeyPress); methods[method](win, 'keydown', this.onKeyPress);
em[method]('change:selectedComponent', this.onSelect, this); em[method]('change:selectedComponent', this.onSelect, this);
}, },
@ -20612,11 +20643,25 @@ module.exports = Property.extend({
}, },
/**
* Clear the value
* @return {this}
*/
clearValue: function clearValue() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
this.get('properties').each(function (property) {
return property.clearValue();
});
return Property.prototype.clearValue.apply(this, arguments);
},
/** /**
* Update property values * Update property values
*/ */
updateValues: function updateValues() { updateValues: function updateValues() {
var values = this.get('value').split(this.get('separator')); var values = this.getFullValue().split(this.get('separator'));
this.get('properties').each(function (property, i) { this.get('properties').each(function (property, i) {
var len = values.length; var len = values.length;
// Try to get value from a shorthand: // Try to get value from a shorthand:
@ -20682,6 +20727,12 @@ module.exports = PropertyCompositeView.extend({
this.listenTo(model, 'updateValue', this.inputValueChanged); this.listenTo(model, 'updateValue', this.inputValueChanged);
this.delegateEvents(); this.delegateEvents();
}, },
clear: function clear(e) {
e && e.stopPropagation();
this.model.get('layers').reset();
this.model.clearValue();
this.targetUpdated();
},
/** /**
@ -21361,6 +21412,8 @@ module.exports = Property.extend({
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _underscore = __webpack_require__(1);
var Property = __webpack_require__(12); var Property = __webpack_require__(12);
var InputNumber = __webpack_require__(18); var InputNumber = __webpack_require__(18);
@ -21391,6 +21444,12 @@ module.exports = Property.extend({
this.set('unit', units[0]); this.set('unit', units[0]);
} }
}, },
clearValue: function clearValue() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
this.set({ value: undefined, unit: undefined }, opts);
return this;
},
parseValue: function parseValue(val) { parseValue: function parseValue(val) {
var parsed = Property.prototype.parseValue.apply(this, arguments); var parsed = Property.prototype.parseValue.apply(this, arguments);
@ -21405,7 +21464,11 @@ module.exports = Property.extend({
return parsed; return parsed;
}, },
getFullValue: function getFullValue() { getFullValue: function getFullValue() {
var value = this.get('value') + this.get('unit'); var value = this.get('value');
var unit = this.get('unit');
value = !(0, _underscore.isUndefined)(value) ? value : '';
unit = !(0, _underscore.isUndefined)(unit) && value ? unit : '';
value = '' + value + unit;
return Property.prototype.getFullValue.apply(this, [value]); return Property.prototype.getFullValue.apply(this, [value]);
} }
}); });
@ -22207,7 +22270,12 @@ exports.default = {
this.set('style', propNew, opts); this.set('style', propNew, opts);
var diff = (0, _mixins.shallowDiff)(propOrig, propNew); var diff = (0, _mixins.shallowDiff)(propOrig, propNew);
(0, _underscore.keys)(diff).forEach(function (pr) { (0, _underscore.keys)(diff).forEach(function (pr) {
return _this.trigger('change:style:' + pr); var em = _this.em;
_this.trigger('change:style:' + pr);
if (em) {
em.trigger('styleable:change');
em.trigger('styleable:change:' + pr);
}
}); });
return propNew; return propNew;
@ -23457,7 +23525,7 @@ module.exports = function () {
plugins: plugins, plugins: plugins,
// Will be replaced on build // Will be replaced on build
version: '0.13.8', version: '0.13.9',
/** /**
* Initializes an editor based on passed options * Initializes an editor based on passed options
@ -39371,14 +39439,18 @@ module.exports = Property.extend({
"use strict"; "use strict";
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var Property = __webpack_require__(14); var Property = __webpack_require__(14);
module.exports = Property.extend({ module.exports = Property.extend({
events: { events: function events() {
'change [type=range]': 'inputValueChanged', return _extends({}, Property.prototype.events, {
'input [type=range]': 'inputValueChangedSoft' 'change [type=range]': 'inputValueChanged',
'input [type=range]': 'inputValueChangedSoft',
change: ''
});
}, },
templateInput: function templateInput(model) { templateInput: function templateInput(model) {
var ppfx = this.ppfx; var ppfx = this.ppfx;
return '\n <div class="' + ppfx + 'field ' + ppfx + 'field-range">\n <input type="range"\n min="' + model.get('min') + '"\n max="' + model.get('max') + '"\n step="' + model.get('step') + '"/>\n </div>\n '; return '\n <div class="' + ppfx + 'field ' + ppfx + 'field-range">\n <input type="range"\n min="' + model.get('min') + '"\n max="' + model.get('max') + '"\n step="' + model.get('step') + '"/>\n </div>\n ';
@ -45832,6 +45904,8 @@ module.exports = {
"use strict"; "use strict";
/* WEBPACK VAR INJECTION */(function(Backbone) { /* WEBPACK VAR INJECTION */(function(Backbone) {
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var Layers = __webpack_require__(197); var Layers = __webpack_require__(197);
var $ = Backbone.$; var $ = Backbone.$;
@ -45842,20 +45916,21 @@ module.exports = {
var config = em.getConfig(); var config = em.getConfig();
var pfx = config.stylePrefix; var pfx = config.stylePrefix;
var panels = em.Panels; var panels = em.Panels;
var lyStylePfx = config.layers.stylePrefix || 'nv-'; var cLayers = _extends({}, config.layers);
var lyStylePfx = cLayers.stylePrefix || 'nv-';
config.layers.stylePrefix = config.stylePrefix + lyStylePfx; cLayers.stylePrefix = config.stylePrefix + lyStylePfx;
config.layers.pStylePrefix = config.stylePrefix; cLayers.pStylePrefix = config.stylePrefix;
config.layers.em = em.editor; cLayers.em = em.editor;
config.layers.opened = em.editor.get('opened'); cLayers.opened = em.editor.get('opened');
// Check if panel exists otherwise crate it // Check if panel exists otherwise crate it
if (!panels.getPanel('views-container')) this.panel = panels.addPanel({ id: 'views-container' });else this.panel = panels.getPanel('views-container'); if (!panels.getPanel('views-container')) this.panel = panels.addPanel({ id: 'views-container' });else this.panel = panels.getPanel('views-container');
var toAppend = $('<div class="' + pfx + 'layers"></div>'); var toAppend = $('<div class="' + pfx + 'layers"></div>');
this.panel.set('appendContent', toAppend).trigger('change:appendContent'); this.panel.set('appendContent', toAppend).trigger('change:appendContent');
config.layers.sortContainer = toAppend.get(0); cLayers.sortContainer = toAppend.get(0);
var layers = new Layers().init(collection, config.layers); var layers = new Layers().init(collection, cLayers);
this.$layers = layers.render(); this.$layers = layers.render();
toAppend.append(this.$layers); toAppend.append(this.$layers);
this.toAppend = toAppend; this.toAppend = toAppend;

6
dist/grapes.min.js

File diff suppressed because one or more lines are too long

2
package-lock.json

@ -1,6 +1,6 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"version": "0.13.8", "version": "0.13.9",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

2
package.json

@ -1,7 +1,7 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"description": "Free and Open Source Web Builder Framework", "description": "Free and Open Source Web Builder Framework",
"version": "0.13.8", "version": "0.13.9",
"author": "Artur Arseniev", "author": "Artur Arseniev",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"homepage": "http://grapesjs.com", "homepage": "http://grapesjs.com",

8
test/specs/style_manager/view/PropertyCompositeView.js

@ -89,13 +89,13 @@ module.exports = {
}); });
it('Input value is empty', () => { it('Input value is empty', () => {
expect(model.getFullValue()).toEqual('0% val2'); expect(model.getFullValue()).toEqual('0 val2');
}); });
it('Update input on value change', () => { it('Update input on value change', () => {
view.model.set('value', propValue); view.model.set('value', propValue);
// Fetch always values from properties // Fetch always values from properties
expect(view.getInputValue()).toEqual('0% val2'); expect(view.getInputValue()).toEqual('0 val2');
}); });
describe('With target setted', () => { describe('With target setted', () => {
@ -123,7 +123,7 @@ module.exports = {
prop2Val = properties[1].defaults; prop2Val = properties[1].defaults;
prop2Unit = properties[1].units[0]; prop2Unit = properties[1].units[0];
prop3Val = properties[2].list[2].value; prop3Val = properties[2].list[2].value;
finalResult = propValue + ' ' + prop2Val + prop2Unit + ' ' + prop3Val; finalResult = propValue + ' ' + prop2Val + ' ' + prop3Val;
$prop1 = view.$props.find('#' + properties[0].property + ' input'); $prop1 = view.$props.find('#' + properties[0].property + ' input');
$prop2 = view.$props.find('#' + properties[1].property + ' input'); $prop2 = view.$props.find('#' + properties[1].property + ' input');
$prop3 = view.$props.find('#' + properties[2].property + ' select'); $prop3 = view.$props.find('#' + properties[2].property + ' select');
@ -151,7 +151,7 @@ module.exports = {
$prop1.val(propValue).trigger('change'); $prop1.val(propValue).trigger('change');
var compStyle = view.getTarget().get('style'); var compStyle = view.getTarget().get('style');
var assertStyle = {}; var assertStyle = {};
assertStyle[propName] = propValue + ' 0% val2'; assertStyle[propName] = propValue + ' 0 val2';
expect(compStyle).toEqual(assertStyle); expect(compStyle).toEqual(assertStyle);
}); });

Loading…
Cancel
Save