Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit a0ef041

Browse files
committed
[IMP] DomHelpers: add append and prepend in domHelpers
1 parent a218fbe commit a0ef041

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/plugin-dom-helpers/src/DomHelpers.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,32 @@ export class DomHelpers<T extends JWPluginConfig = JWPluginConfig> extends JWPlu
175175
}
176176
await this.editor.dispatcher.dispatchHooks('@redraw');
177177
}
178+
/**
179+
* Prepend a DOM Node to another DOM Node's children.
180+
*
181+
* @param params
182+
*/
183+
async prepend(fromDomNode: Node, toDomNode: Node): Promise<void> {
184+
const toNodes = this.getNodes(toDomNode);
185+
const toNode = toNodes[toNodes.length - 1];
186+
for (const fromNode of this.getNodes(fromDomNode).reverse()) {
187+
fromNode.prepend(toNode);
188+
}
189+
await this.editor.dispatcher.dispatchHooks('@redraw');
190+
}
191+
/**
192+
* Append a DOM Node to another DOM Node's children.
193+
*
194+
* @param params
195+
*/
196+
async append(fromDomNode: Node, toDomNode: Node): Promise<void> {
197+
const toNodes = this.getNodes(toDomNode);
198+
const toNode = toNodes[toNodes.length - 1];
199+
for (const fromNode of this.getNodes(fromDomNode).reverse()) {
200+
fromNode.append(toNode);
201+
}
202+
await this.editor.dispatcher.dispatchHooks('@redraw');
203+
}
178204
/**
179205
* Insert html content before, after or inside a DOM Node. If no DOM Node
180206
* was provided, empty the range and insert the html content before the it.

0 commit comments

Comments
 (0)