11 import {TableNode} from "@lexical/table/LexicalTableNode";
14 export class CaptionNode extends ElementNode {
15 static getType(): string {
19 static clone(node: CaptionNode): CaptionNode {
20 return new CaptionNode(node.__key);
23 createDOM(_config: EditorConfig, _editor: LexicalEditor): HTMLElement {
24 return document.createElement('caption');
27 updateDOM(_prevNode: unknown, _dom: HTMLElement, _config: EditorConfig): boolean {
31 isParentRequired(): true {
35 canBeEmpty(): boolean {
39 exportJSON(): SerializedElementNode {
41 ...super.exportJSON(),
47 insertDOMIntoParent(nodeDOM: HTMLElement, parentDOM: HTMLElement): boolean {
48 parentDOM.insertBefore(nodeDOM, parentDOM.firstChild);
52 static importJSON(serializedNode: SerializedElementNode): CaptionNode {
53 return $createCaptionNode();
56 static importDOM(): DOMConversionMap | null {
58 caption: (node: Node) => ({
59 conversion(domNode: Node) {
61 node: $createCaptionNode(),
70 export function $createCaptionNode(): CaptionNode {
71 return new CaptionNode();
74 export function $isCaptionNode(node: LexicalNode | null | undefined): node is CaptionNode {
75 return node instanceof CaptionNode;
78 export function $tableHasCaption(table: TableNode): boolean {
79 for (const child of table.getChildren()) {
80 if ($isCaptionNode(child)) {
87 export function $addCaptionToTable(table: TableNode, text: string = ''): void {
88 const caption = $createCaptionNode();
89 const textNode = $createTextNode(text || ' ');
90 caption.append(textNode);
91 table.append(caption);