From fb5435c646be7a207dd8c30eed2f67067c458f59 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Fri, 23 Jul 2021 01:18:36 +0200 Subject: [PATCH] Add `editor.addStyle` method --- src/editor/index.js | 12 +++++++++++- src/editor/model/Editor.js | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/editor/index.js b/src/editor/index.js index 614d1abde..ba247eb9d 100644 --- a/src/editor/index.js +++ b/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|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|string} style CSS string or style model + * @returns {Array} 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} diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index ce74206da..79c475d6d 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -484,6 +484,17 @@ export default Backbone.Model.extend({ return this; }, + /** + * Add styles to the editor + * @param {Array|Object|string} style CSS string or style model + * @returns {Array} + * @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}