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";
25 * Load the nodes for lexical.
27 export function getNodesForPageEditor(): (KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement)[] {
29 CalloutNode, // Todo - Create custom
30 HeadingNode, // Todo - Create custom
31 QuoteNode, // Todo - Create custom
32 ListNode, // Todo - Create custom
39 DetailsNode, SummaryNode,
46 replace: ParagraphNode,
47 with: (node: ParagraphNode) => {
48 return new CustomParagraphNode();
53 with(node: TableNode) {
54 return new CustomTableNode();
58 replace: ListItemNode,
59 with: (node: ListItemNode) => {
60 return new CustomListItemNode(node.__value, node.__checked);
66 export function registerCommonNodeMutationListeners(context: EditorUiContext): void {
67 const decorated = [ImageNode, CodeBlockNode, DiagramNode];
69 const decorationDestroyListener = (mutations: Map<string, NodeMutation>): void => {
70 for (let [nodeKey, mutation] of mutations) {
71 if (mutation === "destroyed") {
72 const decorator = context.manager.getDecoratorByNodeKey(nodeKey);
74 decorator.destroy(context);
80 for (let decoratedNode of decorated) {
81 // Have to pass a unique function here since they are stored by lexical keyed on listener function.
82 context.editor.registerMutationListener(decoratedNode, (mutations) => decorationDestroyListener(mutations));
86 export type LexicalNodeMatcher = (node: LexicalNode|null|undefined) => boolean;
87 export type LexicalElementNodeCreator = () => ElementNode;