Browse Source
Merge pull request #2872 from mcottret/feature/set-style-set-components-options Closes #2856
Expose options parameter to `setStyle` & `setComponents`. Closes #2856
pull/2881/head
Artur Arseniev
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
18 additions and
12 deletions
-
src/dom_components/index.js
-
src/editor/index.js
-
src/editor/model/Editor.js
|
|
|
@ -509,6 +509,7 @@ export default () => { |
|
|
|
* @param {string} [component.content=''] String inside component |
|
|
|
* @param {Object} [component.style={}] Style object |
|
|
|
* @param {Object} [component.attributes={}] Attribute object |
|
|
|
* @param {Object} opt the options object to be used by the [Components.add]{@link getComponents} method |
|
|
|
* @return {Component|Array<Component>} Component/s added |
|
|
|
* @example |
|
|
|
* // Example of a new component with some extra property
|
|
|
|
@ -522,8 +523,8 @@ export default () => { |
|
|
|
* attributes: { title: 'here' } |
|
|
|
* }); |
|
|
|
*/ |
|
|
|
addComponent(component) { |
|
|
|
return this.getComponents().add(component); |
|
|
|
addComponent(component, opt = {}) { |
|
|
|
return this.getComponents().add(component, opt); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
@ -551,11 +552,12 @@ export default () => { |
|
|
|
/** |
|
|
|
* Set components |
|
|
|
* @param {Object|string} components HTML string or components model |
|
|
|
* @param {Object} opt the options object to be used by the {@link addComponent} method |
|
|
|
* @return {this} |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
setComponents(components) { |
|
|
|
this.clear().addComponent(components); |
|
|
|
setComponents(components, opt = {}) { |
|
|
|
this.clear().addComponent(components, opt); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
@ -247,6 +247,7 @@ export default (config = {}) => { |
|
|
|
/** |
|
|
|
* Set components inside editor's canvas. This method overrides actual components |
|
|
|
* @param {Array<Object>|Object|string} components HTML string or components model |
|
|
|
* @param {Object} opt the options object to be used by the [setComponents]{@link em#setComponents} method |
|
|
|
* @return {this} |
|
|
|
* @example |
|
|
|
* editor.setComponents('<div class="cls">New component</div>'); |
|
|
|
@ -257,8 +258,8 @@ export default (config = {}) => { |
|
|
|
* content: 'New component' |
|
|
|
* }); |
|
|
|
*/ |
|
|
|
setComponents(components) { |
|
|
|
em.setComponents(components); |
|
|
|
setComponents(components, opt = {}) { |
|
|
|
em.setComponents(components, opt); |
|
|
|
return this; |
|
|
|
}, |
|
|
|
|
|
|
|
@ -294,6 +295,7 @@ export default (config = {}) => { |
|
|
|
/** |
|
|
|
* Set style inside editor's canvas. This method overrides actual style |
|
|
|
* @param {Array<Object>|Object|string} style CSS string or style model |
|
|
|
* @param {Object} opt the options object to be used by the [setStyle]{@link em#setStyle} method |
|
|
|
* @return {this} |
|
|
|
* @example |
|
|
|
* editor.setStyle('.cls{color: red}'); |
|
|
|
@ -303,8 +305,8 @@ export default (config = {}) => { |
|
|
|
* style: { color: 'red' } |
|
|
|
* }); |
|
|
|
*/ |
|
|
|
setStyle(style) { |
|
|
|
em.setStyle(style); |
|
|
|
setStyle(style, opt = {}) { |
|
|
|
em.setStyle(style, opt); |
|
|
|
return this; |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
@ -382,11 +382,12 @@ export default Backbone.Model.extend({ |
|
|
|
/** |
|
|
|
* Set components inside editor's canvas. This method overrides actual components |
|
|
|
* @param {Object|string} components HTML string or components model |
|
|
|
* @param {Object} opt the options object to be used by the [setComponents]{@link setComponents} method |
|
|
|
* @return {this} |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
setComponents(components) { |
|
|
|
return this.get('DomComponents').setComponents(components); |
|
|
|
setComponents(components, opt = {}) { |
|
|
|
return this.get('DomComponents').setComponents(components, opt); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
@ -407,13 +408,14 @@ export default Backbone.Model.extend({ |
|
|
|
/** |
|
|
|
* Set style inside editor's canvas. This method overrides actual style |
|
|
|
* @param {Object|string} style CSS string or style model |
|
|
|
* @param {Object} opt the options object to be used by the [CssRules.add]{@link rules#add} method |
|
|
|
* @return {this} |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
setStyle(style) { |
|
|
|
setStyle(style, opt = {}) { |
|
|
|
var rules = this.get('CssComposer').getAll(); |
|
|
|
for (var i = 0, len = rules.length; i < len; i++) rules.pop(); |
|
|
|
rules.add(style); |
|
|
|
rules.add(style, opt); |
|
|
|
return this; |
|
|
|
}, |
|
|
|
|
|
|
|
|