7 import {EditorConfig} from "lexical/LexicalEditor";
8 import {QuoteNode, SerializedQuoteNode} from "@lexical/rich-text";
10 CommonBlockAlignment, commonPropertiesDifferent,
11 SerializedCommonBlockNode,
12 setCommonBlockPropsFromElement,
13 updateElementWithCommonBlockProps
17 export type SerializedCustomQuoteNode = Spread<SerializedCommonBlockNode, SerializedQuoteNode>
19 export class CustomQuoteNode extends QuoteNode {
21 __alignment: CommonBlockAlignment = '';
24 return 'custom-quote';
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 static clone(node: CustomQuoteNode) {
48 const newNode = new CustomQuoteNode(node.__key);
49 newNode.__id = node.__id;
50 newNode.__alignment = node.__alignment;
54 createDOM(config: EditorConfig): HTMLElement {
55 const dom = super.createDOM(config);
56 updateElementWithCommonBlockProps(dom, this);
60 updateDOM(prevNode: CustomQuoteNode): boolean {
61 return commonPropertiesDifferent(prevNode, this);
64 exportJSON(): SerializedCustomQuoteNode {
66 ...super.exportJSON(),
70 alignment: this.__alignment,
74 static importJSON(serializedNode: SerializedCustomQuoteNode): CustomQuoteNode {
75 const node = $createCustomQuoteNode();
76 node.setId(serializedNode.id);
77 node.setAlignment(serializedNode.alignment);
81 static importDOM(): DOMConversionMap | null {
83 blockquote: (node: Node) => ({
84 conversion: $convertBlockquoteElement,
91 function $convertBlockquoteElement(element: HTMLElement): DOMConversionOutput {
92 const node = $createCustomQuoteNode();
93 setCommonBlockPropsFromElement(element, node);
97 export function $createCustomQuoteNode() {
98 return new CustomQuoteNode();
101 export function $isCustomQuoteNode(node: LexicalNode | null | undefined): node is CustomQuoteNode {
102 return node instanceof CustomQuoteNode;