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-node";
26 * Load the nodes for lexical.
28 export function getNodesForPageEditor(): (KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement)[] {
30 CalloutNode, // Todo - Create custom
31 HeadingNode, // Todo - Create custom
32 QuoteNode, // Todo - Create custom
33 ListNode, // Todo - Create custom
40 DetailsNode, SummaryNode,
47 replace: ParagraphNode,
48 with: (node: ParagraphNode) => {
49 return new CustomParagraphNode();
54 with(node: TableNode) {
55 return new CustomTableNode();
59 replace: ListItemNode,
60 with: (node: ListItemNode) => {
61 return new CustomListItemNode(node.__value, node.__checked);
65 replace: TableCellNode,
66 with: (node: TableCellNode) => {
67 const cell = new CustomTableCellNode(
72 cell.__rowSpan = node.__rowSpan;
79 export function registerCommonNodeMutationListeners(context: EditorUiContext): void {
80 const decorated = [ImageNode, CodeBlockNode, DiagramNode];
82 const decorationDestroyListener = (mutations: Map<string, NodeMutation>): void => {
83 for (let [nodeKey, mutation] of mutations) {
84 if (mutation === "destroyed") {
85 const decorator = context.manager.getDecoratorByNodeKey(nodeKey);
87 decorator.destroy(context);
93 for (let decoratedNode of decorated) {
94 // Have to pass a unique function here since they are stored by lexical keyed on listener function.
95 context.editor.registerMutationListener(decoratedNode, (mutations) => decorationDestroyListener(mutations));
99 export type LexicalNodeMatcher = (node: LexicalNode|null|undefined) => boolean;
100 export type LexicalElementNodeCreator = () => ElementNode;