BookStack/resources/js/wysiwyg/nodes/index.ts

51 lines
1.7 KiB
TypeScript
Raw Normal View History

import {HeadingNode, QuoteNode} from '@lexical/rich-text';
import {CalloutNode} from './callout';
import {ElementNode, KlassConstructor, LexicalNode, LexicalNodeReplacement, ParagraphNode} from "lexical";
import {CustomParagraphNode} from "./custom-paragraph";
import {LinkNode} from "@lexical/link";
import {ImageNode} from "./image";
import {DetailsNode, SummaryNode} from "./details";
import {ListItemNode, ListNode} from "@lexical/list";
import {TableCellNode, TableNode, TableRowNode} from "@lexical/table";
import {CustomTableNode} from "./custom-table";
2024-06-27 22:48:06 +08:00
import {HorizontalRuleNode} from "./horizontal-rule";
import {CodeBlockNode} from "./code-block";
2024-07-03 17:28:04 +08:00
import {DiagramNode} from "./diagram";
/**
* Load the nodes for lexical.
*/
export function getNodesForPageEditor(): (KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement)[] {
return [
CalloutNode, // Todo - Create custom
HeadingNode, // Todo - Create custom
QuoteNode, // Todo - Create custom
ListNode, // Todo - Create custom
ListItemNode,
CustomTableNode,
TableRowNode,
TableCellNode,
ImageNode,
2024-06-27 22:48:06 +08:00
HorizontalRuleNode,
DetailsNode, SummaryNode,
CodeBlockNode,
2024-07-03 17:28:04 +08:00
DiagramNode,
CustomParagraphNode,
LinkNode,
{
replace: ParagraphNode,
with: (node: ParagraphNode) => {
return new CustomParagraphNode();
}
},
{
replace: TableNode,
with(node: TableNode) {
return new CustomTableNode();
}
},
];
}
export type LexicalNodeMatcher = (node: LexicalNode|null|undefined) => boolean;
export type LexicalElementNodeCreator = () => ElementNode;