6 ParagraphNode, SerializedParagraphNode, Spread,
8 import {EditorConfig} from "lexical/LexicalEditor";
10 CommonBlockAlignment, commonPropertiesDifferent, deserializeCommonBlockNode,
11 SerializedCommonBlockNode,
12 setCommonBlockPropsFromElement,
13 updateElementWithCommonBlockProps
16 export type SerializedCustomParagraphNode = Spread<SerializedCommonBlockNode, SerializedParagraphNode>
18 export class CustomParagraphNode extends ParagraphNode {
20 __alignment: CommonBlockAlignment = '';
24 return 'custom-paragraph';
28 const self = this.getWritable();
33 const self = this.getLatest();
37 setAlignment(alignment: CommonBlockAlignment) {
38 const self = this.getWritable();
39 self.__alignment = alignment;
42 getAlignment(): CommonBlockAlignment {
43 const self = this.getLatest();
44 return self.__alignment;
47 setInset(size: number) {
48 const self = this.getWritable();
53 const self = this.getLatest();
57 static clone(node: CustomParagraphNode): CustomParagraphNode {
58 const newNode = new CustomParagraphNode(node.__key);
59 newNode.__id = node.__id;
60 newNode.__alignment = node.__alignment;
61 newNode.__inset = node.__inset;
65 createDOM(config: EditorConfig): HTMLElement {
66 const dom = super.createDOM(config);
67 updateElementWithCommonBlockProps(dom, this);
71 updateDOM(prevNode: CustomParagraphNode, dom: HTMLElement, config: EditorConfig): boolean {
72 return super.updateDOM(prevNode, dom, config)
73 || commonPropertiesDifferent(prevNode, this);
76 exportJSON(): SerializedCustomParagraphNode {
78 ...super.exportJSON(),
79 type: 'custom-paragraph',
82 alignment: this.__alignment,
87 static importJSON(serializedNode: SerializedCustomParagraphNode): CustomParagraphNode {
88 const node = $createCustomParagraphNode();
89 deserializeCommonBlockNode(serializedNode, node);
93 static importDOM(): DOMConversionMap|null {
95 p(node: HTMLElement): DOMConversion|null {
97 conversion: (element: HTMLElement): DOMConversionOutput|null => {
98 const node = $createCustomParagraphNode();
99 if (element.style.textIndent) {
100 const indent = parseInt(element.style.textIndent, 10) / 20;
102 node.setIndent(indent);
106 setCommonBlockPropsFromElement(element, node);
117 export function $createCustomParagraphNode(): CustomParagraphNode {
118 return new CustomParagraphNode();
121 export function $isCustomParagraphNode(node: LexicalNode | null | undefined): node is CustomParagraphNode {
122 return node instanceof CustomParagraphNode;