1 import {HeadingNode, QuoteNode} from '@lexical/rich-text';
2 import {CalloutNode} from './callout';
7 LexicalNodeReplacement, NodeMutation,
10 import {LinkNode} from "@lexical/link";
11 import {ImageNode} from "./image";
12 import {DetailsNode, SummaryNode} from "./details";
13 import {ListItemNode, ListNode} from "@lexical/list";
14 import {TableCellNode, TableNode, TableRowNode} from "@lexical/table";
15 import {CustomTableNode} from "./custom-table";
16 import {HorizontalRuleNode} from "./horizontal-rule";
17 import {CodeBlockNode} from "./code-block";
18 import {DiagramNode} from "./diagram";
19 import {EditorUiContext} from "../ui/framework/core";
20 import {MediaNode} from "./media";
21 import {CustomListItemNode} from "./custom-list-item";
22 import {CustomTableCellNode} from "./custom-table-cell";
23 import {CustomTableRowNode} from "./custom-table-row";
24 import {CustomHeadingNode} from "./custom-heading";
25 import {CustomQuoteNode} from "./custom-quote";
26 import {CustomListNode} from "./custom-list";
29 * Load the nodes for lexical.
31 export function getNodesForPageEditor(): (KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement)[] {
37 CustomListItemNode, // TODO - Alignment?
41 ImageNode, // TODO - Alignment
43 DetailsNode, SummaryNode,
46 MediaNode, // TODO - Alignment
51 with: (node: HeadingNode) => {
52 return new CustomHeadingNode(node.__tag);
57 with: (node: QuoteNode) => {
58 return new CustomQuoteNode();
63 with: (node: ListNode) => {
64 return new CustomListNode(node.getListType(), node.getStart());
68 replace: ListItemNode,
69 with: (node: ListItemNode) => {
70 return new CustomListItemNode(node.__value, node.__checked);
75 with(node: TableNode) {
76 return new CustomTableNode();
80 replace: TableRowNode,
81 with(node: TableRowNode) {
82 return new CustomTableRowNode();
86 replace: TableCellNode,
87 with: (node: TableCellNode) => {
88 const cell = new CustomTableCellNode(
93 cell.__rowSpan = node.__rowSpan;
100 export function registerCommonNodeMutationListeners(context: EditorUiContext): void {
101 const decorated = [ImageNode, CodeBlockNode, DiagramNode];
103 const decorationDestroyListener = (mutations: Map<string, NodeMutation>): void => {
104 for (let [nodeKey, mutation] of mutations) {
105 if (mutation === "destroyed") {
106 const decorator = context.manager.getDecoratorByNodeKey(nodeKey);
108 decorator.destroy(context);
114 for (let decoratedNode of decorated) {
115 // Have to pass a unique function here since they are stored by lexical keyed on listener function.
116 context.editor.registerMutationListener(decoratedNode, (mutations) => decorationDestroyListener(mutations));
120 export type LexicalNodeMatcher = (node: LexicalNode|null|undefined) => boolean;
121 export type LexicalElementNodeCreator = () => ElementNode;