-
Notifications
You must be signed in to change notification settings - Fork 143
/
container.ts
48 lines (40 loc) · 1.21 KB
/
container.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Scope from '../../scope';
import BlockBlot from '../block';
import ParentBlot from './parent';
class ContainerBlot extends ParentBlot {
public static blotName = 'container';
public static scope = Scope.BLOCK_BLOT;
public static tagName: string;
public prev!: BlockBlot | ContainerBlot | null;
public next!: BlockBlot | ContainerBlot | null;
public checkMerge(): boolean {
return (
this.next !== null && this.next.statics.blotName === this.statics.blotName
);
}
public deleteAt(index: number, length: number): void {
super.deleteAt(index, length);
this.enforceAllowedChildren();
}
public formatAt(
index: number,
length: number,
name: string,
value: any,
): void {
super.formatAt(index, length, name, value);
this.enforceAllowedChildren();
}
public insertAt(index: number, value: string, def?: any): void {
super.insertAt(index, value, def);
this.enforceAllowedChildren();
}
public optimize(context: { [key: string]: any }): void {
super.optimize(context);
if (this.children.length > 0 && this.next != null && this.checkMerge()) {
this.next.moveChildren(this);
this.next.remove();
}
}
}
export default ContainerBlot;