1 import {HeadingNode, QuoteNode} from '@lexical/rich-text';
2 import {CalloutNode} from './callout';
7 LexicalNodeReplacement, NodeMutation,
10 import {CustomParagraphNode} from "./custom-paragraph";
11 import {LinkNode} from "@lexical/link";
12 import {ImageNode} from "./image";
13 import {DetailsNode, SummaryNode} from "./details";
14 import {ListItemNode, ListNode} from "@lexical/list";
15 import {TableCellNode, TableNode, TableRowNode} from "@lexical/table";
16 import {CustomTableNode} from "./custom-table";
17 import {HorizontalRuleNode} from "./horizontal-rule";
18 import {CodeBlockNode} from "./code-block";
19 import {DiagramNode} from "./diagram";
20 import {EditorUiContext} from "../ui/framework/core";
21 import {MediaNode} from "./media";
22 import {CustomListItemNode} from "./custom-list-item";
23 import {CustomTableCellNode} from "./custom-table-cell";
24 import {CustomTableRowNode} from "./custom-table-row";
25 import {CustomHeadingNode} from "./custom-heading";
26 import {CustomQuoteNode} from "./custom-quote";
27 import {CustomListNode} from "./custom-list";
30 * Load the nodes for lexical.
32 export function getNodesForPageEditor(): (KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement)[] {
38 CustomListItemNode, // TODO - Alignment?
42 ImageNode, // TODO - Alignment
44 DetailsNode, SummaryNode,
47 MediaNode, // TODO - Alignment
51 replace: ParagraphNode,
52 with: (node: ParagraphNode) => {
53 return new CustomParagraphNode();
58 with: (node: HeadingNode) => {
59 return new CustomHeadingNode(node.__tag);
64 with: (node: QuoteNode) => {
65 return new CustomQuoteNode();
70 with: (node: ListNode) => {
71 return new CustomListNode(node.getListType(), node.getStart());
75 replace: ListItemNode,
76 with: (node: ListItemNode) => {
77 return new CustomListItemNode(node.__value, node.__checked);
82 with(node: TableNode) {
83 return new CustomTableNode();
87 replace: TableRowNode,
88 with(node: TableRowNode) {
89 return new CustomTableRowNode();
93 replace: TableCellNode,
94 with: (node: TableCellNode) => {
95 const cell = new CustomTableCellNode(
100 cell.__rowSpan = node.__rowSpan;
107 export function registerCommonNodeMutationListeners(context: EditorUiContext): void {
108 const decorated = [ImageNode, CodeBlockNode, DiagramNode];
110 const decorationDestroyListener = (mutations: Map<string, NodeMutation>): void => {
111 for (let [nodeKey, mutation] of mutations) {
112 if (mutation === "destroyed") {
113 const decorator = context.manager.getDecoratorByNodeKey(nodeKey);
115 decorator.destroy(context);
121 for (let decoratedNode of decorated) {
122 // Have to pass a unique function here since they are stored by lexical keyed on listener function.
123 context.editor.registerMutationListener(decoratedNode, (mutations) => decorationDestroyListener(mutations));
127 export type LexicalNodeMatcher = (node: LexicalNode|null|undefined) => boolean;
128 export type LexicalElementNodeCreator = () => ElementNode;