4 DOMConversionOutput, ElementFormatType,
7 SerializedParagraphNode,
10 import {EditorConfig} from "lexical/LexicalEditor";
13 export type SerializedCustomParagraphNode = Spread<{
15 }, SerializedParagraphNode>
17 export class CustomParagraphNode extends ParagraphNode {
21 return 'custom-paragraph';
25 const self = this.getWritable();
30 const self = this.getLatest();
34 static clone(node: CustomParagraphNode): CustomParagraphNode {
35 const newNode = new CustomParagraphNode(node.__key);
36 newNode.__id = node.__id;
40 createDOM(config: EditorConfig): HTMLElement {
41 const dom = super.createDOM(config);
43 dom.setAttribute('id', this.__id);
49 exportJSON(): SerializedCustomParagraphNode {
51 ...super.exportJSON(),
52 type: 'custom-paragraph',
58 static importJSON(serializedNode: SerializedCustomParagraphNode): CustomParagraphNode {
59 const node = $createCustomParagraphNode();
60 node.setId(serializedNode.id);
64 static importDOM(): DOMConversionMap|null {
66 p(node: HTMLElement): DOMConversion|null {
68 conversion: (element: HTMLElement): DOMConversionOutput|null => {
69 const node = $createCustomParagraphNode();
71 node.setFormat(element.style.textAlign as ElementFormatType);
72 const indent = parseInt(element.style.textIndent, 10) / 20;
74 node.setIndent(indent);
79 node.setId(element.id);
91 export function $createCustomParagraphNode(): CustomParagraphNode {
92 return new CustomParagraphNode();
95 export function $isCustomParagraphNode(node: LexicalNode | null | undefined): node is CustomParagraphNode {
96 return node instanceof CustomParagraphNode;