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 {CustomListItemNode} from "./custom-list-item";
21 import {CustomTableCellNode} from "./custom-table-cell";
22 import {CustomTableRowNode} from "./custom-table-row";
23 import {CustomListNode} from "./custom-list";
24 import {HeadingNode} from "@lexical/rich-text/LexicalHeadingNode";
25 import {QuoteNode} from "@lexical/rich-text/LexicalQuoteNode";
28 * Load the nodes for lexical.
30 export function getNodesForPageEditor(): (KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement)[] {
36 CustomListItemNode, // TODO - Alignment?
40 ImageNode, // TODO - Alignment
42 DetailsNode, SummaryNode,
45 MediaNode, // TODO - Alignment
50 with: (node: ListNode) => {
51 return new CustomListNode(node.getListType(), node.getStart());
55 replace: ListItemNode,
56 with: (node: ListItemNode) => {
57 return new CustomListItemNode(node.__value, node.__checked);
62 with(node: TableNode) {
63 return new CustomTableNode();
67 replace: TableRowNode,
68 with(node: TableRowNode) {
69 return new CustomTableRowNode();
73 replace: TableCellNode,
74 with: (node: TableCellNode) => {
75 const cell = new CustomTableCellNode(
80 cell.__rowSpan = node.__rowSpan;
87 export function registerCommonNodeMutationListeners(context: EditorUiContext): void {
88 const decorated = [ImageNode, CodeBlockNode, DiagramNode];
90 const decorationDestroyListener = (mutations: Map<string, NodeMutation>): void => {
91 for (let [nodeKey, mutation] of mutations) {
92 if (mutation === "destroyed") {
93 const decorator = context.manager.getDecoratorByNodeKey(nodeKey);
95 decorator.destroy(context);
101 for (let decoratedNode of decorated) {
102 // Have to pass a unique function here since they are stored by lexical keyed on listener function.
103 context.editor.registerMutationListener(decoratedNode, (mutations) => decorationDestroyListener(mutations));
107 export type LexicalNodeMatcher = (node: LexicalNode|null|undefined) => boolean;
108 export type LexicalElementNodeCreator = () => ElementNode;