-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ExampleDefaultBlockTool.ts
70 lines (59 loc) · 1.72 KB
/
ExampleDefaultBlockTool.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type {
BlockTool,
BlockToolConstructorOptions,
} from "@editorjs/editorjs";
interface DefaultBlockToolData {
text: string;
}
// DefaultBlockToolData must extends DefaultBlockToolData
// See also: https://github.com/codex-team/editor.js/issues/1520
interface ExampleDefaultBlockToolData extends DefaultBlockToolData {
style: string;
}
interface ValidatedExampleDefaultBlockToolData
extends ExampleDefaultBlockToolData {}
class ExampleDefaultBlockTool implements BlockTool {
#style: string;
#text: string;
constructor({
data,
}: BlockToolConstructorOptions<
// Specify also DefaultBlockToolData to accept splitted default block data.
// See also: https://github.com/codex-team/editor.js/issues/1520
DefaultBlockToolData | ExampleDefaultBlockToolData
>) {
// Filter undefined and empty object.
// See also: https://github.com/codex-team/editor.js/issues/1432
if (data && "text" in data) {
this.#text = data.text;
} else {
this.#text = "";
}
// Filter undefined and empty object.
// See also: https://github.com/codex-team/editor.js/issues/1432
if (data && "style" in data) {
this.#style = data.style;
} else {
this.#style = "";
}
}
render() {
return document.createElement("div");
}
save(): ExampleDefaultBlockToolData {
return {
style: this.#style,
text: this.#text,
};
}
validate(data: ExampleDefaultBlockToolData) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const compatibilityCheck: ValidatedExampleDefaultBlockToolData = data;
return true;
}
}
export { ExampleDefaultBlockTool };
export type {
ExampleDefaultBlockToolData,
ValidatedExampleDefaultBlockToolData,
};