Browse Source

Add `avoidDefaults` option

pull/1045/head
Artur Arseniev 8 years ago
parent
commit
16e026c492
  1. 27
      src/dom_components/model/Component.js
  2. 7
      src/editor/config/config.js

27
src/dom_components/model/Component.js

@ -6,6 +6,7 @@ import {
has,
clone,
isString,
forEach,
keys
} from 'underscore';
import { shallowDiff, hasDnd } from 'utils/mixins';
@ -722,6 +723,32 @@ const Component = Backbone.Model.extend(Styleable).extend(
delete obj.attributes.class;
delete obj.toolbar;
if (this.em.getConfig('avoidDefaults')) {
const defaults = this.defaults;
forEach(defaults, (value, key) => {
if (key !== 'type' && obj[key] === value) {
delete obj[key];
}
});
if (isEmpty(obj.type)) {
delete obj.type;
}
forEach(['attributes', 'style'], prop => {
if (isEmpty(defaults[prop]) && isEmpty(obj[prop])) {
delete obj[prop];
}
});
forEach(['classes', 'components'], prop => {
if (isEmpty(defaults[prop]) && !obj[prop].length) {
delete obj[prop];
}
});
}
return obj;
},

7
src/editor/config/config.js

@ -50,7 +50,7 @@ module.exports = {
overflow: auto;
overflow-x: hidden;
}
* ::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.1)
}
@ -114,6 +114,11 @@ module.exports = {
// When `avoidInlineStyle` is true all styles are inserted inside the css rule
avoidInlineStyle: 0,
// Avoid default properties from storable JSON data, like `components` and `styles`.
// With this option enabled your data will be smaller (usefull if need to
// save some storage space)
avoidDefaults: 0,
// (experimental)
// The structure of components is always on the screen but it's not the same
// for style rules. When you delete a component you might leave a lot of styles

Loading…
Cancel
Save