5 type DOMConversionOutput,
15 import {addClassNamesToElement} from "@lexical/utils";
16 import {CommonBlockNode, copyCommonBlockProperties, SerializedCommonBlockNode} from "lexical/nodes/CommonBlockNode";
18 commonPropertiesDifferent, deserializeCommonBlockNode,
19 setCommonBlockPropsFromElement,
20 updateElementWithCommonBlockProps
21 } from "lexical/nodes/common";
23 export type SerializedQuoteNode = SerializedCommonBlockNode;
26 export class QuoteNode extends CommonBlockNode {
27 static getType(): string {
31 static clone(node: QuoteNode): QuoteNode {
32 const clone = new QuoteNode(node.__key);
33 copyCommonBlockProperties(node, clone);
37 constructor(key?: NodeKey) {
43 createDOM(config: EditorConfig): HTMLElement {
44 const element = document.createElement('blockquote');
45 addClassNamesToElement(element, config.theme.quote);
46 updateElementWithCommonBlockProps(element, this);
50 updateDOM(prevNode: QuoteNode, dom: HTMLElement): boolean {
51 return commonPropertiesDifferent(prevNode, this);
54 static importDOM(): DOMConversionMap | null {
56 blockquote: (node: Node) => ({
57 conversion: $convertBlockquoteElement,
63 exportDOM(editor: LexicalEditor): DOMExportOutput {
64 const {element} = super.exportDOM(editor);
66 if (element && isHTMLElement(element)) {
68 element.append(document.createElement('br'));
77 static importJSON(serializedNode: SerializedQuoteNode): QuoteNode {
78 const node = $createQuoteNode();
79 deserializeCommonBlockNode(serializedNode, node);
83 exportJSON(): SerializedQuoteNode {
85 ...super.exportJSON(),
92 insertNewAfter(_: RangeSelection, restoreSelection?: boolean): ParagraphNode {
93 const newBlock = $createParagraphNode();
94 const direction = this.getDirection();
95 newBlock.setDirection(direction);
96 this.insertAfter(newBlock, restoreSelection);
100 collapseAtStart(): true {
101 const paragraph = $createParagraphNode();
102 const children = this.getChildren();
103 children.forEach((child) => paragraph.append(child));
104 this.replace(paragraph);
108 canMergeWhenEmpty(): true {
113 export function $createQuoteNode(): QuoteNode {
114 return $applyNodeReplacement(new QuoteNode());
117 export function $isQuoteNode(
118 node: LexicalNode | null | undefined,
119 ): node is QuoteNode {
120 return node instanceof QuoteNode;
123 function $convertBlockquoteElement(element: HTMLElement): DOMConversionOutput {
124 const node = $createQuoteNode();
125 setCommonBlockPropsFromElement(element, node);