5 type DOMConversionOutput,
17 import {addClassNamesToElement} from "@lexical/utils";
18 import {CommonBlockNode, copyCommonBlockProperties} from "lexical/nodes/CommonBlockNode";
20 commonPropertiesDifferent, deserializeCommonBlockNode,
21 SerializedCommonBlockNode, setCommonBlockPropsFromElement,
22 updateElementWithCommonBlockProps
23 } from "../../nodes/_common";
25 export type SerializedQuoteNode = SerializedCommonBlockNode;
28 export class QuoteNode extends CommonBlockNode {
29 static getType(): string {
33 static clone(node: QuoteNode): QuoteNode {
34 const clone = new QuoteNode(node.__key);
35 copyCommonBlockProperties(node, clone);
39 constructor(key?: NodeKey) {
45 createDOM(config: EditorConfig): HTMLElement {
46 const element = document.createElement('blockquote');
47 addClassNamesToElement(element, config.theme.quote);
48 updateElementWithCommonBlockProps(element, this);
52 updateDOM(prevNode: QuoteNode, dom: HTMLElement): boolean {
53 return commonPropertiesDifferent(prevNode, this);
56 static importDOM(): DOMConversionMap | null {
58 blockquote: (node: Node) => ({
59 conversion: $convertBlockquoteElement,
65 exportDOM(editor: LexicalEditor): DOMExportOutput {
66 const {element} = super.exportDOM(editor);
68 if (element && isHTMLElement(element)) {
70 element.append(document.createElement('br'));
79 static importJSON(serializedNode: SerializedQuoteNode): QuoteNode {
80 const node = $createQuoteNode();
81 deserializeCommonBlockNode(serializedNode, node);
85 exportJSON(): SerializedQuoteNode {
87 ...super.exportJSON(),
94 insertNewAfter(_: RangeSelection, restoreSelection?: boolean): ParagraphNode {
95 const newBlock = $createParagraphNode();
96 const direction = this.getDirection();
97 newBlock.setDirection(direction);
98 this.insertAfter(newBlock, restoreSelection);
102 collapseAtStart(): true {
103 const paragraph = $createParagraphNode();
104 const children = this.getChildren();
105 children.forEach((child) => paragraph.append(child));
106 this.replace(paragraph);
110 canMergeWhenEmpty(): true {
115 export function $createQuoteNode(): QuoteNode {
116 return $applyNodeReplacement(new QuoteNode());
119 export function $isQuoteNode(
120 node: LexicalNode | null | undefined,
121 ): node is QuoteNode {
122 return node instanceof QuoteNode;
125 function $convertBlockquoteElement(element: HTMLElement): DOMConversionOutput {
126 const node = $createQuoteNode();
127 setCommonBlockPropsFromElement(element, node);