]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/nodes/index.ts
befc2ab2e05442f5f1ef49d2edc8030252443428
[bookstack] / resources / js / wysiwyg / nodes / index.ts
1 import {HeadingNode, QuoteNode} from '@lexical/rich-text';
2 import {CalloutNode} from './callout';
3 import {ElementNode, KlassConstructor, LexicalNode, LexicalNodeReplacement, ParagraphNode} from "lexical";
4 import {CustomParagraphNode} from "./custom-paragraph";
5 import {LinkNode} from "@lexical/link";
6 import {ImageNode} from "./image";
7 import {DetailsNode, SummaryNode} from "./details";
8 import {ListItemNode, ListNode} from "@lexical/list";
9 import {TableCellNode, TableNode, TableRowNode} from "@lexical/table";
10 import {CustomTableNode} from "./custom-table";
11 import {HorizontalRuleNode} from "./horizontal-rule";
12
13 /**
14  * Load the nodes for lexical.
15  */
16 export function getNodesForPageEditor(): (KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement)[] {
17     return [
18         CalloutNode, // Todo - Create custom
19         HeadingNode, // Todo - Create custom
20         QuoteNode, // Todo - Create custom
21         ListNode, // Todo - Create custom
22         ListItemNode,
23         CustomTableNode,
24         TableRowNode,
25         TableCellNode,
26         ImageNode,
27         HorizontalRuleNode,
28         DetailsNode, SummaryNode,
29         CustomParagraphNode,
30         LinkNode,
31         {
32             replace: ParagraphNode,
33             with: (node: ParagraphNode) => {
34                 return new CustomParagraphNode();
35             }
36         },
37         {
38             replace: TableNode,
39             with(node: TableNode) {
40                 return new CustomTableNode();
41             }
42         },
43     ];
44 }
45
46 export type LexicalNodeMatcher = (node: LexicalNode|null|undefined) => boolean;
47 export type LexicalElementNodeCreator = () => ElementNode;