2024-12-04 18:53:59 +00:00
|
|
|
import {CalloutNode} from '@lexical/rich-text/LexicalCalloutNode';
|
2024-07-16 16:36:08 +01:00
|
|
|
import {
|
|
|
|
ElementNode,
|
|
|
|
KlassConstructor,
|
|
|
|
LexicalNode,
|
|
|
|
LexicalNodeReplacement, NodeMutation,
|
|
|
|
ParagraphNode
|
|
|
|
} from "lexical";
|
2024-05-29 20:38:31 +01:00
|
|
|
import {LinkNode} from "@lexical/link";
|
2024-12-04 18:53:59 +00:00
|
|
|
import {ImageNode} from "@lexical/rich-text/LexicalImageNode";
|
|
|
|
import {DetailsNode, SummaryNode} from "@lexical/rich-text/LexicalDetailsNode";
|
2024-06-19 16:14:20 +01:00
|
|
|
import {ListItemNode, ListNode} from "@lexical/list";
|
2024-06-21 13:47:47 +01:00
|
|
|
import {TableCellNode, TableNode, TableRowNode} from "@lexical/table";
|
2024-12-04 18:53:59 +00:00
|
|
|
import {HorizontalRuleNode} from "@lexical/rich-text/LexicalHorizontalRuleNode";
|
|
|
|
import {CodeBlockNode} from "@lexical/rich-text/LexicalCodeBlockNode";
|
|
|
|
import {DiagramNode} from "@lexical/rich-text/LexicalDiagramNode";
|
|
|
|
import {EditorUiContext} from "./ui/framework/core";
|
|
|
|
import {MediaNode} from "@lexical/rich-text/LexicalMediaNode";
|
2024-12-03 17:04:50 +00:00
|
|
|
import {HeadingNode} from "@lexical/rich-text/LexicalHeadingNode";
|
|
|
|
import {QuoteNode} from "@lexical/rich-text/LexicalQuoteNode";
|
2024-05-27 20:23:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the nodes for lexical.
|
|
|
|
*/
|
2024-05-28 15:09:50 +01:00
|
|
|
export function getNodesForPageEditor(): (KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement)[] {
|
2024-05-27 20:23:45 +01:00
|
|
|
return [
|
2024-08-11 16:08:51 +01:00
|
|
|
CalloutNode,
|
2024-12-03 17:04:50 +00:00
|
|
|
HeadingNode,
|
|
|
|
QuoteNode,
|
2024-12-03 19:03:52 +00:00
|
|
|
ListNode,
|
|
|
|
ListItemNode,
|
2024-12-03 20:08:33 +00:00
|
|
|
TableNode,
|
|
|
|
TableRowNode,
|
|
|
|
TableCellNode,
|
2024-08-18 16:51:08 +01:00
|
|
|
ImageNode, // TODO - Alignment
|
2024-06-27 15:48:06 +01:00
|
|
|
HorizontalRuleNode,
|
2024-06-06 14:43:50 +01:00
|
|
|
DetailsNode, SummaryNode,
|
2024-07-02 14:46:30 +01:00
|
|
|
CodeBlockNode,
|
2024-07-03 10:28:04 +01:00
|
|
|
DiagramNode,
|
2024-08-18 16:51:08 +01:00
|
|
|
MediaNode, // TODO - Alignment
|
2024-12-03 16:24:49 +00:00
|
|
|
ParagraphNode,
|
2024-06-24 20:50:17 +01:00
|
|
|
LinkNode,
|
2024-05-27 20:23:45 +01:00
|
|
|
];
|
|
|
|
}
|
2024-05-28 18:04:48 +01:00
|
|
|
|
2024-07-16 16:36:08 +01:00
|
|
|
export function registerCommonNodeMutationListeners(context: EditorUiContext): void {
|
|
|
|
const decorated = [ImageNode, CodeBlockNode, DiagramNode];
|
|
|
|
|
|
|
|
const decorationDestroyListener = (mutations: Map<string, NodeMutation>): void => {
|
|
|
|
for (let [nodeKey, mutation] of mutations) {
|
|
|
|
if (mutation === "destroyed") {
|
|
|
|
const decorator = context.manager.getDecoratorByNodeKey(nodeKey);
|
|
|
|
if (decorator) {
|
|
|
|
decorator.destroy(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (let decoratedNode of decorated) {
|
|
|
|
// Have to pass a unique function here since they are stored by lexical keyed on listener function.
|
|
|
|
context.editor.registerMutationListener(decoratedNode, (mutations) => decorationDestroyListener(mutations));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-28 18:04:48 +01:00
|
|
|
export type LexicalNodeMatcher = (node: LexicalNode|null|undefined) => boolean;
|
|
|
|
export type LexicalElementNodeCreator = () => ElementNode;
|