forked from SparkDevNetwork/Rock
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathnested-list.ts
More file actions
44 lines (39 loc) · 1.52 KB
/
nested-list.ts
File metadata and controls
44 lines (39 loc) · 1.52 KB
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
import { BlockToolConstructorOptions } from "@editorjs/editorjs";
import EditorNestedList, { NestedListData, NestedListItem } from "@editorjs/nested-list";
interface LegacyListData {
style: "ordered" | "unordered";
items: Array<string>;
}
/**
* Custom subclass of the nested list block tool.
*/
export class NestedList extends EditorNestedList {
/**
* Create a new instance of the NestedList tool.
*
* @param config The configuration to initialize with.
*/
public constructor(config: BlockToolConstructorOptions<NestedListData | LegacyListData>) {
/* Handle legacy non-nested list data, if found convert it to the new format. */
if (config.data.items !== undefined && config.data.items.length > 0 && typeof (config.data.items[0]) === 'string') {
config.data.items = config.data.items.map(value => {
const item: NestedListItem = {
content: <string>value,
items: []
};
return item;
});
}
super(<BlockToolConstructorOptions<NestedListData>>config);
}
/**
* Checks if there is any contents and if not indicate the block should
* not be included in the saved data.
*
* @param savedData The data generated by the save method.
* @returns true if the block data should be included; false otherwise.
*/
public validate(savedData: NestedListData) {
return savedData.items.length > 0 && savedData.items[0].content !== "";
}
}