UNPKG

@mkljczk/lexical-remark

Version:

This package contains Markdown helpers and functionality for Lexical using remark-parse.

76 lines (75 loc) 2.1 kB
/* eslint-disable @typescript-eslint/no-use-before-define */ import { ElementNode, } from 'lexical'; export function convertCollapsibleContentElement(domNode) { const node = $createCollapsibleContentNode(); return { node, }; } /** * A Lexical node to represent the content of an HTML details container which exists outside of the summary */ export class CollapsibleContentNode extends ElementNode { static getType() { return 'collapsible-content'; } static clone(node) { return new CollapsibleContentNode(node.__key); } createDOM(config) { const dom = document.createElement('div'); dom.classList.add('Collapsible__content'); return dom; } updateDOM(prevNode, dom) { return false; } static importDOM() { return { div: (domNode) => { if (!domNode.hasAttribute('data-lexical-collapsible-content')) { return null; } return { conversion: convertCollapsibleContentElement, priority: 2, }; }, }; } exportDOM() { const element = document.createElement('div'); element.setAttribute('data-lexical-collapsible-content', 'true'); return { element }; } static importJSON(serializedNode) { return $createCollapsibleContentNode(); } isShadowRoot() { return true; } exportJSON() { return { ...super.exportJSON(), type: 'collapsible-content', version: 1, }; } } /** * Creates a Collapsible Content node * * @returns A Collapsible Content node */ export function $createCollapsibleContentNode() { return new CollapsibleContentNode(); } /** * A typeguard to assert on a Collapsible Content node * * @param node A Lexical node * @returns true if the node is a Collapsible Content node, otherwise false */ export function $isCollapsibleContentNode(node) { return node instanceof CollapsibleContentNode; }