diff --git a/src/exportMarkdownFromLexical.ts b/src/exportMarkdownFromLexical.ts index 7b5b5031..72748688 100644 --- a/src/exportMarkdownFromLexical.ts +++ b/src/exportMarkdownFromLexical.ts @@ -13,7 +13,7 @@ export type { Options as ToMarkdownOptions } from 'mdast-util-to-markdown' * This is part of the process that converts the editor contents to markdown. * @group Markdown Processing */ -export interface LexicalExportVisitor { +export interface LexicalExportVisitor { /** * Return true if the given node is of the type that this visitor can process. * You can safely use the node type guard functions (as in $isParagraphNode, $isLinkNode, etc.) here. @@ -66,13 +66,13 @@ export interface LexicalExportVisitor(prevNode: T, currentNode: T): T + join?(prevNode: T, currentNode: T): T /** * Default 0, optional, sets the priority of the visitor. The higher the number, the earlier it will be called. @@ -84,7 +84,7 @@ export interface LexicalExportVisitor +export type LexicalVisitor = LexicalExportVisitor /** * @internal @@ -122,7 +122,7 @@ export function exportLexicalTreeToMdast({ referredComponents.add(componentName) } - function appendToParent(parentNode: T, node: C): C | Mdast.Root { + function appendToParent(parentNode: T, node: C): C | Mdast.Root { if (unistRoot === null) { unistRoot = node as unknown as Mdast.Root return unistRoot @@ -172,7 +172,7 @@ export function exportLexicalTreeToMdast({ ...props, ...(hasChildren ? { children: [] } : {}) } - appendToParent(mdastParent!, newNode as unknown as Mdast.Content) + appendToParent(mdastParent!, newNode as unknown as Mdast.RootContent) if ($isElementNode(lexicalNode) && hasChildren) { visitChildren(lexicalNode, newNode as Mdast.Parent) } @@ -251,7 +251,7 @@ export function exportLexicalTreeToMdast({ return typedRoot } -function collapseNestedHtmlTags(node: Mdast.Parent | Mdast.Content) { +function collapseNestedHtmlTags(node: Mdast.Nodes) { if ('children' in node && node.children) { if (isMdastHTMLNode(node) && node.children.length === 1) { const onlyChild = node.children[0] @@ -282,10 +282,10 @@ function collapseNestedHtmlTags(node: Mdast.Parent | Mdast.Content) { } } -function convertUnderlineJsxToHtml(node: Mdast.Parent | Mdast.Content) { +function convertUnderlineJsxToHtml(node: Mdast.Parent | Mdast.RootContent) { if (Object.hasOwn(node, 'children')) { const nodeAsParent = node as Mdast.Parent - const newChildren = [] as Mdast.Content[] + const newChildren = [] as Mdast.RootContent[] nodeAsParent.children.forEach((child) => { if (child.type === 'mdxJsxTextElement' && child.name === 'u') { newChildren.push(...[{ type: 'html', value: '' } as const, ...child.children, { type: 'html', value: '' } as const]) @@ -300,7 +300,7 @@ function convertUnderlineJsxToHtml(node: Mdast.Parent | Mdast.Content) { const TRAILING_WHITESPACE_REGEXP = /\s+$/ const LEADING_WHITESPACE_REGEXP = /^\s+/ -function fixWrappingWhitespace(node: Mdast.Parent | Mdast.Content, parentChain: Mdast.Parent[]) { +function fixWrappingWhitespace(node: Mdast.Parent | Mdast.RootContent, parentChain: Mdast.Parent[]) { if (node.type === 'strong' || node.type === 'emphasis') { const lastChild = node.children.at(-1) if (lastChild?.type === 'text') { @@ -309,7 +309,7 @@ function fixWrappingWhitespace(node: Mdast.Parent | Mdast.Content, parentChain: lastChild.value = lastChild.value.replace(TRAILING_WHITESPACE_REGEXP, '') const parent = parentChain.at(-1) if (parent) { - parent.children.splice(parent.children.indexOf(node as unknown as Mdast.Content) + 1, 0, { + parent.children.splice(parent.children.indexOf(node as unknown as Mdast.RootContent) + 1, 0, { type: 'text', value: trailingWhitespace[0] }) @@ -325,7 +325,7 @@ function fixWrappingWhitespace(node: Mdast.Parent | Mdast.Content, parentChain: const parent = parentChain.at(-1) if (parent) { - parent.children.splice(parent.children.indexOf(node as unknown as Mdast.Content), 0, { + parent.children.splice(parent.children.indexOf(node as unknown as Mdast.RootContent), 0, { type: 'text', value: leadingWhitespace[0] }) diff --git a/src/plugins/core/index.ts b/src/plugins/core/index.ts index 9244fe0a..fde70c4b 100644 --- a/src/plugins/core/index.ts +++ b/src/plugins/core/index.ts @@ -730,7 +730,7 @@ export const viewMode$ = Cell('rich-text', (r) => { filter((mode) => mode.current === 'rich-text'), withLatestFrom(activeEditor$) ), - ([mode, editor]) => { + ([, editor]) => { editor?.dispatchCommand(NESTED_EDITOR_UPDATED_COMMAND, undefined) } ) diff --git a/src/plugins/jsx/LexicalJsxVisitor.ts b/src/plugins/jsx/LexicalJsxVisitor.ts index 05b0b169..cdc32fd1 100644 --- a/src/plugins/jsx/LexicalJsxVisitor.ts +++ b/src/plugins/jsx/LexicalJsxVisitor.ts @@ -9,7 +9,7 @@ export const LexicalJsxVisitor: LexicalExportVisitor { + node.children.forEach((child: Mdast.Nodes) => { if (isMdastJsxNode(child)) { actions.registerReferredComponent(child.name!) }