Browse Source

Add `editor.addStyle` method

pull/3670/head
Artur Arseniev 5 years ago
parent
commit
fb5435c646
  1. 12
      src/editor/index.js
  2. 11
      src/editor/model/Editor.js

12
src/editor/index.js

@ -306,7 +306,6 @@ 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}');
@ -321,6 +320,17 @@ export default (config = {}) => {
return this;
},
/**
* Add styles to the editor
* @param {Array<Object>|Object|string} style CSS string or style model
* @returns {Array<CssRule>} Array of created CssRule instances
* @example
* editor.addStyle('.cls{color: red}');
*/
addStyle(style, opts = {}) {
return em.addStyle(style, opts);
},
/**
* Returns the last selected component, if there is one
* @return {Model}

11
src/editor/model/Editor.js

@ -484,6 +484,17 @@ export default Backbone.Model.extend({
return this;
},
/**
* Add styles to the editor
* @param {Array<Object>|Object|string} style CSS string or style model
* @returns {Array<CssRule>}
* @private
*/
addStyle(style, opts = {}) {
const res = this.getStyle().add(style, opts);
return isArray(res) ? res : [res];
},
/**
* Returns rules/style model from the editor's canvas
* @return {Rules}

Loading…
Cancel
Save