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";
27 * Load the nodes for lexical.
29 export function getNodesForPageEditor(): (KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement)[] {
31 CalloutNode, // Todo - Create custom
32 HeadingNode, // Todo - Create custom
33 QuoteNode, // Todo - Create custom
34 ListNode, // Todo - Create custom
41 DetailsNode, SummaryNode,
48 replace: ParagraphNode,
49 with: (node: ParagraphNode) => {
50 return new CustomParagraphNode();
54 replace: ListItemNode,
55 with: (node: ListItemNode) => {
56 return new CustomListItemNode(node.__value, node.__checked);
61 with(node: TableNode) {
62 return new CustomTableNode();
66 replace: TableRowNode,
67 with(node: TableRowNode) {
68 return new CustomTableRowNode();
72 replace: TableCellNode,
73 with: (node: TableCellNode) => {
74 const cell = new CustomTableCellNode(
79 cell.__rowSpan = node.__rowSpan;
86 export function registerCommonNodeMutationListeners(context: EditorUiContext): void {
87 const decorated = [ImageNode, CodeBlockNode, DiagramNode];
89 const decorationDestroyListener = (mutations: Map<string, NodeMutation>): void => {
90 for (let [nodeKey, mutation] of mutations) {
91 if (mutation === "destroyed") {
92 const decorator = context.manager.getDecoratorByNodeKey(nodeKey);
94 decorator.destroy(context);
100 for (let decoratedNode of decorated) {
101 // Have to pass a unique function here since they are stored by lexical keyed on listener function.
102 context.editor.registerMutationListener(decoratedNode, (mutations) => decorationDestroyListener(mutations));
106 export type LexicalNodeMatcher = (node: LexicalNode|null|undefined) => boolean;
107 export type LexicalElementNodeCreator = () => ElementNode;