1 import {CalloutNode} from './callout';
6 LexicalNodeReplacement, NodeMutation,
9 import {LinkNode} from "@lexical/link";
10 import {ImageNode} from "./image";
11 import {DetailsNode, SummaryNode} from "./details";
12 import {ListItemNode, ListNode} from "@lexical/list";
13 import {TableCellNode, TableNode, TableRowNode} from "@lexical/table";
14 import {CustomTableNode} from "./custom-table";
15 import {HorizontalRuleNode} from "./horizontal-rule";
16 import {CodeBlockNode} from "./code-block";
17 import {DiagramNode} from "./diagram";
18 import {EditorUiContext} from "../ui/framework/core";
19 import {MediaNode} from "./media";
20 import {CustomTableCellNode} from "./custom-table-cell";
21 import {CustomTableRowNode} from "./custom-table-row";
22 import {HeadingNode} from "@lexical/rich-text/LexicalHeadingNode";
23 import {QuoteNode} from "@lexical/rich-text/LexicalQuoteNode";
26 * Load the nodes for lexical.
28 export function getNodesForPageEditor(): (KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement)[] {
38 ImageNode, // TODO - Alignment
40 DetailsNode, SummaryNode,
43 MediaNode, // TODO - Alignment
48 with(node: TableNode) {
49 return new CustomTableNode();
53 replace: TableRowNode,
54 with(node: TableRowNode) {
55 return new CustomTableRowNode();
59 replace: TableCellNode,
60 with: (node: TableCellNode) => {
61 const cell = new CustomTableCellNode(
66 cell.__rowSpan = node.__rowSpan;
73 export function registerCommonNodeMutationListeners(context: EditorUiContext): void {
74 const decorated = [ImageNode, CodeBlockNode, DiagramNode];
76 const decorationDestroyListener = (mutations: Map<string, NodeMutation>): void => {
77 for (let [nodeKey, mutation] of mutations) {
78 if (mutation === "destroyed") {
79 const decorator = context.manager.getDecoratorByNodeKey(nodeKey);
81 decorator.destroy(context);
87 for (let decoratedNode of decorated) {
88 // Have to pass a unique function here since they are stored by lexical keyed on listener function.
89 context.editor.registerMutationListener(decoratedNode, (mutations) => decorationDestroyListener(mutations));
93 export type LexicalNodeMatcher = (node: LexicalNode|null|undefined) => boolean;
94 export type LexicalElementNodeCreator = () => ElementNode;