From c1c637749b9c116cceed88e2c65f1c3c24cacef4 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 31 Dec 2020 13:59:08 +0100 Subject: [PATCH] Add move method to Component --- src/dom_components/model/Component.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index f175cb0d1..21cd953c1 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -1359,6 +1359,22 @@ const Component = Backbone.Model.extend(Styleable).extend( return coll && coll.remove(this, opts); }, + /** + * Move the component to another destination component + * @param {Component} component Destination component (so the current one will be appended as a child) + * @param {Object} opts Options for the append action + * @returns {this} + * @example + * // Move the selected component on top of the wrapper + * const dest = editor.getWrapper(); + * editor.getSelected().move(dest, { at: 0 }); + */ + move(component, opts = {}) { + this.remove({ temporary: 1 }); + component && component.append(this, opts); + return this; + }, + /** * Reset id of the component and any of its style rule * @param {Object} [opts={}] Options