3 DOMConversionMap, DOMConversionOutput,
7 SerializedElementNode, Spread,
9 import type {EditorConfig} from "lexical/LexicalEditor";
11 export type SerializedHorizontalRuleNode = Spread<{
13 }, SerializedElementNode>
15 export class HorizontalRuleNode extends ElementNode {
19 return 'horizontal-rule';
23 const self = this.getWritable();
28 const self = this.getLatest();
32 static clone(node: HorizontalRuleNode): HorizontalRuleNode {
33 const newNode = new HorizontalRuleNode(node.__key);
34 newNode.__id = node.__id;
38 createDOM(_config: EditorConfig, _editor: LexicalEditor): HTMLElement {
39 const el = document.createElement('hr');
41 el.setAttribute('id', this.__id);
47 updateDOM(prevNode: HorizontalRuleNode, dom: HTMLElement) {
48 return prevNode.__id !== this.__id;
51 static importDOM(): DOMConversionMap|null {
53 hr(node: HTMLElement): DOMConversion|null {
55 conversion: (element: HTMLElement): DOMConversionOutput|null => {
56 const node = new HorizontalRuleNode();
58 node.setId(element.id);
69 exportJSON(): SerializedHorizontalRuleNode {
71 ...super.exportJSON(),
72 type: 'horizontal-rule',
78 static importJSON(serializedNode: SerializedHorizontalRuleNode): HorizontalRuleNode {
79 const node = $createHorizontalRuleNode();
80 node.setId(serializedNode.id);
86 export function $createHorizontalRuleNode(): HorizontalRuleNode {
87 return new HorizontalRuleNode();
90 export function $isHorizontalRuleNode(node: LexicalNode | null | undefined): node is HorizontalRuleNode {
91 return node instanceof HorizontalRuleNode;