7 import {EditorConfig} from "lexical/LexicalEditor";
8 import {QuoteNode, SerializedQuoteNode} from "@lexical/rich-text";
10 CommonBlockAlignment, commonPropertiesDifferent, deserializeCommonBlockNode,
11 SerializedCommonBlockNode,
12 setCommonBlockPropsFromElement,
13 updateElementWithCommonBlockProps
17 export type SerializedCustomQuoteNode = Spread<SerializedCommonBlockNode, SerializedQuoteNode>
19 export class CustomQuoteNode extends QuoteNode {
21 __alignment: CommonBlockAlignment = '';
25 return 'custom-quote';
29 const self = this.getWritable();
34 const self = this.getLatest();
38 setAlignment(alignment: CommonBlockAlignment) {
39 const self = this.getWritable();
40 self.__alignment = alignment;
43 getAlignment(): CommonBlockAlignment {
44 const self = this.getLatest();
45 return self.__alignment;
48 setInset(size: number) {
49 const self = this.getWritable();
54 const self = this.getLatest();
58 static clone(node: CustomQuoteNode) {
59 const newNode = new CustomQuoteNode(node.__key);
60 newNode.__id = node.__id;
61 newNode.__alignment = node.__alignment;
62 newNode.__inset = node.__inset;
66 createDOM(config: EditorConfig): HTMLElement {
67 const dom = super.createDOM(config);
68 updateElementWithCommonBlockProps(dom, this);
72 updateDOM(prevNode: CustomQuoteNode): boolean {
73 return commonPropertiesDifferent(prevNode, this);
76 exportJSON(): SerializedCustomQuoteNode {
78 ...super.exportJSON(),
82 alignment: this.__alignment,
87 static importJSON(serializedNode: SerializedCustomQuoteNode): CustomQuoteNode {
88 const node = $createCustomQuoteNode();
89 deserializeCommonBlockNode(serializedNode, node);
93 static importDOM(): DOMConversionMap | null {
95 blockquote: (node: Node) => ({
96 conversion: $convertBlockquoteElement,
103 function $convertBlockquoteElement(element: HTMLElement): DOMConversionOutput {
104 const node = $createCustomQuoteNode();
105 setCommonBlockPropsFromElement(element, node);
109 export function $createCustomQuoteNode() {
110 return new CustomQuoteNode();
113 export function $isCustomQuoteNode(node: LexicalNode | null | undefined): node is CustomQuoteNode {
114 return node instanceof CustomQuoteNode;