diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index 77304b691..8e99a8c92 100644 --- a/src/dom_components/model/Component.js +++ b/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; }, diff --git a/src/editor/config/config.js b/src/editor/config/config.js index bd0786b70..da6a1eb55 100644 --- a/src/editor/config/config.js +++ b/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