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

Commit 5c7f85f

Browse files
committed
redraw after dom helper call
1 parent e9a4fd1 commit 5c7f85f

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,75 +24,87 @@ export class DomHelpers<T extends JWPluginConfig = JWPluginConfig> extends JWPlu
2424
*
2525
* @param params
2626
*/
27-
addClass(domNode: Node | Node[], className: string | string[]): void {
27+
async addClass(domNode: Node | Node[], className: string | string[]): Promise<void> {
2828
const classes = Array.isArray(className) ? className : [className];
2929
for (const node of this.getNodes(domNode)) {
3030
node.modifiers.get(Attributes).classList.add(...classes);
3131
}
32+
await this.editor.dispatcher.dispatchHooks('@redraw');
3233
}
3334
/**
3435
* Remove a class or a list of classes from a DOM node or a list of DOM nodes.
3536
*
3637
* @param params
3738
*/
38-
removeClass(domNode: Node | Node[], className: string | string[]): void {
39+
async removeClass(domNode: Node | Node[], className: string | string[]): Promise<void> {
3940
const classes = Array.isArray(className) ? className : [className];
4041
for (const node of this.getNodes(domNode)) {
4142
node.modifiers.get(Attributes).classList.remove(...classes);
4243
}
44+
await this.editor.dispatcher.dispatchHooks('@redraw');
4345
}
4446
/**
4547
* Add or remove a class or a list of classes from a DOM node or a list of
4648
* DOM nodes.
4749
*
4850
* @param params
4951
*/
50-
toggleClass(domNode: Node | Node[], className: string): void {
52+
async toggleClass(domNode: Node | Node[], className: string): Promise<void> {
5153
const classes = Array.isArray(className) ? className : [className];
5254
for (const node of this.getNodes(domNode)) {
5355
node.modifiers.get(Attributes).classList.toggle(...classes);
5456
}
57+
await this.editor.dispatcher.dispatchHooks('@redraw');
5558
}
5659
/**
5760
* Set an attribute on a DOM node or a list of DOM nodes.
5861
*
5962
* @param params
6063
*/
61-
setAttribute(domNode: Node | Node[], name: string, value: string): void {
64+
async setAttribute(domNode: Node | Node[], name: string, value: string): Promise<void> {
6265
for (const node of this.getNodes(domNode)) {
6366
node.modifiers.get(Attributes).set(name, value);
6467
}
68+
await this.editor.dispatcher.dispatchHooks('@redraw');
6569
}
6670
/**
6771
* Set a style key/value pair on a DOM node or a list of DOM nodes.
6872
*
6973
* @param params
7074
*/
71-
setStyle(domNode: Node | Node[], name: string, value: string, important?: boolean): void {
75+
async setStyle(
76+
domNode: Node | Node[],
77+
name: string,
78+
value: string,
79+
important?: boolean,
80+
): Promise<void> {
7281
for (const node of this.getNodes(domNode)) {
7382
value = important ? value + ' !important' : value;
7483
node.modifiers.get(Attributes).style.set(name, value);
7584
}
85+
await this.editor.dispatcher.dispatchHooks('@redraw');
7686
}
7787
/**
7888
* Remove a DOM node or a list of DOM nodes.
7989
*
8090
* @param params
8191
*/
82-
remove(domNode: Node | Node[]): void {
92+
async remove(domNode: Node | Node[]): Promise<void> {
8393
for (const node of this.getNodes(domNode)) {
8494
node.remove();
8595
}
96+
await this.editor.dispatcher.dispatchHooks('@redraw');
8697
}
8798
/**
8899
* Remove the contents of a DOM node or of a list of DOM nodes.
89100
*
90101
* @param params
91102
*/
92-
empty(domNode: Node | Node[]): void {
103+
async empty(domNode: Node | Node[]): Promise<void> {
93104
for (const node of this.getNodes(domNode)) {
94105
node.empty();
95106
}
107+
await this.editor.dispatcher.dispatchHooks('@redraw');
96108
}
97109
/**
98110
* Replace a DOM node or a list of DOM nodes with the given HTML content.
@@ -109,6 +121,7 @@ export class DomHelpers<T extends JWPluginConfig = JWPluginConfig> extends JWPlu
109121
for (const node of nodes) {
110122
node.remove();
111123
}
124+
await this.editor.dispatcher.dispatchHooks('@redraw');
112125
}
113126
/**
114127
* Wrap the given HTML content within a DOM container.
@@ -126,29 +139,32 @@ export class DomHelpers<T extends JWPluginConfig = JWPluginConfig> extends JWPlu
126139
for (const parsedNode of parsedNodes) {
127140
container.wrap(parsedNode);
128141
}
142+
await this.editor.dispatcher.dispatchHooks('@redraw');
129143
}
130144
/**
131145
* Move a DOM Node before another.
132146
*
133147
* @param params
134148
*/
135-
moveBefore(fromDomNode: Node, toDomNode: Node): void {
149+
async moveBefore(fromDomNode: Node, toDomNode: Node): Promise<void> {
136150
const toNode = this.getNodes(toDomNode)[0];
137151
for (const fromNode of this.getNodes(fromDomNode)) {
138152
fromNode.before(toNode);
139153
}
154+
await this.editor.dispatcher.dispatchHooks('@redraw');
140155
}
141156
/**
142157
* Move a DOM Node after another.
143158
*
144159
* @param params
145160
*/
146-
moveAfter(fromDomNode: Node, toDomNode: Node): void {
161+
async moveAfter(fromDomNode: Node, toDomNode: Node): Promise<void> {
147162
const toNodes = this.getNodes(toDomNode);
148163
const toNode = toNodes[toNodes.length - 1];
149164
for (const fromNode of this.getNodes(fromDomNode).reverse()) {
150165
fromNode.after(toNode);
151166
}
167+
await this.editor.dispatcher.dispatchHooks('@redraw');
152168
}
153169
/**
154170
* Insert html content before, after or inside a DOM Node. If no DOM Node
@@ -184,6 +200,7 @@ export class DomHelpers<T extends JWPluginConfig = JWPluginConfig> extends JWPlu
184200
}
185201
break;
186202
}
203+
await this.editor.dispatcher.dispatchHooks('@redraw');
187204
return parsedNodes;
188205
}
189206
/**

0 commit comments

Comments
 (0)