@payloadcms/richtext-lexical 3.29.0-internal.d74b919 → 3.29.0-internal.e4e913b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -110,10 +110,6 @@ unclosedTags, unclosableTags) {
110
110
  // bring the whitespace back. So our returned string looks like this: " **foo** "
111
111
  const frozenString = textContent.trim();
112
112
  let output = frozenString;
113
- if (!node.hasFormat('code')) {
114
- // Escape any markdown characters in the text content
115
- output = output.replace(/([*_`~\\])/g, '\\$1');
116
- }
117
113
  // the opening tags to be added to the result
118
114
  let openingTags = '';
119
115
  // the closing tags to be added to the result
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownExport.js","names":["$getRoot","$isDecoratorNode","$isElementNode","$isLineBreakNode","$isTextNode","isEmptyParagraph","transformersByType","createMarkdownExport","transformers","shouldPreserveNewLines","byType","elementTransformers","multilineElement","element","isNewlineDelimited","textFormatTransformers","textFormat","filter","transformer","format","length","sort","a","b","includes","node","output","children","getChildren","forEach","child","i","result","exportTopLevelElements","textMatch","push","concat","join","textTransformersIndex","textMatchTransformers","export","_node","exportChildren","getTextContent","unclosedTags","unclosableTags","mainLoop","parentNode","textNode","textContent","exportTextFormat","textTransformers","frozenString","trim","hasFormat","replace","openingTags","closingTagsBefore","closingTagsAfter","prevNode","getTextSibling","nextNode","applied","Set","tag","has","add","find","unclosedTag","nodeHasFormat","nextNodeHasFormat","unhandledUnclosedTags","pop","backward","sibling","getPreviousSibling","getNextSibling","parent","getParentOrThrow","isInline","descendant","getLastDescendant","getFirstDescendant"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownExport.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { ElementNode, LexicalNode, TextFormatType, TextNode } from 'lexical'\n\nimport { $getRoot, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isTextNode } from 'lexical'\n\nimport type {\n ElementTransformer,\n MultilineElementTransformer,\n TextFormatTransformer,\n TextMatchTransformer,\n Transformer,\n} from './MarkdownTransformers.js'\n\nimport { isEmptyParagraph, transformersByType } from './utils.js'\n\n/**\n * Renders string from markdown. The selection is moved to the start after the operation.\n */\nexport function createMarkdownExport(\n transformers: Array<Transformer>,\n shouldPreserveNewLines: boolean = false,\n): (node?: ElementNode) => string {\n const byType = transformersByType(transformers)\n const elementTransformers = [...byType.multilineElement, ...byType.element]\n const isNewlineDelimited = !shouldPreserveNewLines\n\n // Export only uses text formats that are responsible for single format\n // e.g. it will filter out *** (bold, italic) and instead use separate ** and *\n const textFormatTransformers = byType.textFormat\n .filter((transformer) => transformer.format.length === 1)\n // Make sure all text transformers that contain 'code' in their format are at the end of the array. Otherwise, formatted code like\n // <strong><code>code</code></strong> will be exported as `**Bold Code**`, as the code format will be applied first, and the bold format\n // will be applied second and thus skipped entirely, as the code format will prevent any further formatting.\n .sort((a, b) => {\n if (a.format.includes('code') && !b.format.includes('code')) {\n return 1\n } else if (!a.format.includes('code') && b.format.includes('code')) {\n return -1\n } else {\n return 0\n }\n })\n\n return (node) => {\n const output: string[] = []\n const children = (node || $getRoot()).getChildren()\n\n children.forEach((child, i) => {\n const result = exportTopLevelElements(\n child,\n elementTransformers,\n textFormatTransformers,\n byType.textMatch,\n )\n\n if (result != null) {\n output.push(\n // separate consecutive group of texts with a line break: eg. [\"hello\", \"world\"] -> [\"hello\", \"/nworld\"]\n isNewlineDelimited &&\n i > 0 &&\n !isEmptyParagraph(child) &&\n !isEmptyParagraph(children[i - 1]!)\n ? '\\n'.concat(result)\n : result,\n )\n }\n })\n // Ensure consecutive groups of texts are at least \\n\\n apart while each empty paragraph render as a newline.\n // Eg. [\"hello\", \"\", \"\", \"hi\", \"\\nworld\"] -> \"hello\\n\\n\\nhi\\n\\nworld\"\n return output.join('\\n')\n }\n}\n\nfunction exportTopLevelElements(\n node: LexicalNode,\n elementTransformers: Array<ElementTransformer | MultilineElementTransformer>,\n textTransformersIndex: Array<TextFormatTransformer>,\n textMatchTransformers: Array<TextMatchTransformer>,\n): null | string {\n for (const transformer of elementTransformers) {\n if (!transformer.export) {\n continue\n }\n const result = transformer.export(node, (_node) =>\n exportChildren(_node, textTransformersIndex, textMatchTransformers),\n )\n\n if (result != null) {\n return result\n }\n }\n\n if ($isElementNode(node)) {\n return exportChildren(node, textTransformersIndex, textMatchTransformers)\n } else if ($isDecoratorNode(node)) {\n return node.getTextContent()\n } else {\n return null\n }\n}\n\nfunction exportChildren(\n node: ElementNode,\n textTransformersIndex: Array<TextFormatTransformer>,\n textMatchTransformers: Array<TextMatchTransformer>,\n unclosedTags?: Array<{ format: TextFormatType; tag: string }>,\n unclosableTags?: Array<{ format: TextFormatType; tag: string }>,\n): string {\n const output = []\n const children = node.getChildren()\n // keep track of unclosed tags from the very beginning\n if (!unclosedTags) {\n unclosedTags = []\n }\n if (!unclosableTags) {\n unclosableTags = []\n }\n\n mainLoop: for (const child of children) {\n for (const transformer of textMatchTransformers) {\n if (!transformer.export) {\n continue\n }\n\n const result = transformer.export(\n child,\n (parentNode) =>\n exportChildren(\n parentNode,\n textTransformersIndex,\n textMatchTransformers,\n unclosedTags,\n // Add current unclosed tags to the list of unclosable tags - we don't want nested tags from\n // textmatch transformers to close the outer ones, as that may result in invalid markdown.\n // E.g. **text [text**](https://lexical.io)\n // is invalid markdown, as the closing ** is inside the link.\n //\n [...unclosableTags, ...unclosedTags],\n ),\n (textNode, textContent) =>\n exportTextFormat(\n textNode,\n textContent,\n textTransformersIndex,\n unclosedTags,\n unclosableTags,\n ),\n )\n\n if (result != null) {\n output.push(result)\n continue mainLoop\n }\n }\n\n if ($isLineBreakNode(child)) {\n output.push('\\n')\n } else if ($isTextNode(child)) {\n output.push(\n exportTextFormat(\n child,\n child.getTextContent(),\n textTransformersIndex,\n unclosedTags,\n unclosableTags,\n ),\n )\n } else if ($isElementNode(child)) {\n // empty paragraph returns \"\"\n output.push(\n exportChildren(\n child,\n textTransformersIndex,\n textMatchTransformers,\n unclosedTags,\n unclosableTags,\n ),\n )\n } else if ($isDecoratorNode(child)) {\n output.push(child.getTextContent())\n }\n }\n\n return output.join('')\n}\n\nfunction exportTextFormat(\n node: TextNode,\n textContent: string,\n textTransformers: Array<TextFormatTransformer>,\n // unclosed tags include the markdown tags that haven't been closed yet, and their associated formats\n unclosedTags: Array<{ format: TextFormatType; tag: string }>,\n unclosableTags?: Array<{ format: TextFormatType; tag: string }>,\n): string {\n // This function handles the case of a string looking like this: \" foo \"\n // Where it would be invalid markdown to generate: \"** foo **\"\n // We instead want to trim the whitespace out, apply formatting, and then\n // bring the whitespace back. So our returned string looks like this: \" **foo** \"\n const frozenString = textContent.trim()\n let output = frozenString\n\n if (!node.hasFormat('code')) {\n // Escape any markdown characters in the text content\n output = output.replace(/([*_`~\\\\])/g, '\\\\$1')\n }\n\n // the opening tags to be added to the result\n let openingTags = ''\n // the closing tags to be added to the result\n let closingTagsBefore = ''\n let closingTagsAfter = ''\n\n const prevNode = getTextSibling(node, true)\n const nextNode = getTextSibling(node, false)\n\n const applied = new Set()\n\n for (const transformer of textTransformers) {\n const format = transformer.format[0]!\n const tag = transformer.tag\n\n // dedup applied formats\n if (hasFormat(node, format) && !applied.has(format)) {\n // Multiple tags might be used for the same format (*, _)\n applied.add(format)\n\n // append the tag to openningTags, if it's not applied to the previous nodes,\n // or the nodes before that (which would result in an unclosed tag)\n if (!hasFormat(prevNode, format) || !unclosedTags.find((element) => element.tag === tag)) {\n unclosedTags.push({ format, tag })\n openingTags += tag\n }\n }\n }\n\n // close any tags in the same order they were applied, if necessary\n for (let i = 0; i < unclosedTags.length; i++) {\n const unclosedTag = unclosedTags[i]!\n const nodeHasFormat = hasFormat(node, unclosedTag.format)\n const nextNodeHasFormat = hasFormat(nextNode, unclosedTag.format)\n\n // prevent adding closing tag if next sibling will do it\n if (nodeHasFormat && nextNodeHasFormat) {\n continue\n }\n\n const unhandledUnclosedTags = [...unclosedTags] // Shallow copy to avoid modifying the original array\n\n while (unhandledUnclosedTags.length > i) {\n const unclosedTag = unhandledUnclosedTags.pop()\n\n // If tag is unclosable, don't close it and leave it in the original array,\n // So that it can be closed when it's no longer unclosable\n if (\n unclosableTags &&\n unclosedTag &&\n unclosableTags.find((element) => element.tag === unclosedTag.tag)\n ) {\n continue\n }\n\n if (unclosedTag && typeof unclosedTag.tag === 'string') {\n if (!nodeHasFormat) {\n // Handles cases where the tag has not been closed before, e.g. if the previous node\n // was a text match transformer that did not account for closing tags of the next node (e.g. a link)\n closingTagsBefore += unclosedTag.tag\n } else if (!nextNodeHasFormat) {\n closingTagsAfter += unclosedTag.tag\n }\n }\n // Mutate the original array to remove the closed tag\n unclosedTags.pop()\n }\n break\n }\n\n output = openingTags + output + closingTagsAfter\n // Replace trimmed version of textContent ensuring surrounding whitespace is not modified\n return closingTagsBefore + textContent.replace(frozenString, () => output)\n}\n\n// Get next or previous text sibling a text node, including cases\n// when it's a child of inline element (e.g. link)\nfunction getTextSibling(node: TextNode, backward: boolean): null | TextNode {\n let sibling = backward ? node.getPreviousSibling() : node.getNextSibling()\n\n if (!sibling) {\n const parent = node.getParentOrThrow()\n\n if (parent.isInline()) {\n sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling()\n }\n }\n\n while (sibling) {\n if ($isElementNode(sibling)) {\n if (!sibling.isInline()) {\n break\n }\n\n const descendant = backward ? sibling.getLastDescendant() : sibling.getFirstDescendant()\n\n if ($isTextNode(descendant)) {\n return descendant\n } else {\n sibling = backward ? sibling.getPreviousSibling() : sibling.getNextSibling()\n }\n }\n\n if ($isTextNode(sibling)) {\n return sibling\n }\n\n if (!$isElementNode(sibling)) {\n return null\n }\n }\n\n return null\n}\n\nfunction hasFormat(node: LexicalNode | null | undefined, format: TextFormatType): boolean {\n return $isTextNode(node) && node.hasFormat(format)\n}\n"],"mappings":"AAAA;;;;;;GAUA,SAASA,QAAQ,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAA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AAA,GAAaP,QAAA,GAAWC,OAAA,CAAQO,iBAAiB,KAAKP,OAAA,CAAQQ,kBAAkB;MAEtF,IAAI9E,WAAA,CAAY4E,UAAA,GAAa;QAC3B,OAAOA,UAAA;MACT,OAAO;QACLN,OAAA,GAAUD,QAAA,GAAWC,OAAA,CAAQC,kBAAkB,KAAKD,OAAA,CAAQE,cAAc;MAC5E;IACF;IAEA,IAAIxE,WAAA,CAAYsE,OAAA,GAAU;MACxB,OAAOA,OAAA;IACT;IAEA,IAAI,CAACxE,cAAA,CAAewE,OAAA,GAAU;MAC5B,OAAO;IACT;EACF;EAEA,OAAO;AACT;AAEA,SAASpB,UAAU7B,IAAoC,EAAEN,MAAsB;EAC7E,OAAOf,WAAA,CAAYqB,IAAA,KAASA,IAAA,CAAK6B,SAAS,CAACnC,MAAA;AAC7C","ignoreList":[]}
1
+ {"version":3,"file":"MarkdownExport.js","names":["$getRoot","$isDecoratorNode","$isElementNode","$isLineBreakNode","$isTextNode","isEmptyParagraph","transformersByType","createMarkdownExport","transformers","shouldPreserveNewLines","byType","elementTransformers","multilineElement","element","isNewlineDelimited","textFormatTransformers","textFormat","filter","transformer","format","length","sort","a","b","includes","node","output","children","getChildren","forEach","child","i","result","exportTopLevelElements","textMatch","push","concat","join","textTransformersIndex","textMatchTransformers","export","_node","exportChildren","getTextContent","unclosedTags","unclosableTags","mainLoop","parentNode","textNode","textContent","exportTextFormat","textTransformers","frozenString","trim","openingTags","closingTagsBefore","closingTagsAfter","prevNode","getTextSibling","nextNode","applied","Set","tag","hasFormat","has","add","find","unclosedTag","nodeHasFormat","nextNodeHasFormat","unhandledUnclosedTags","pop","replace","backward","sibling","getPreviousSibling","getNextSibling","parent","getParentOrThrow","isInline","descendant","getLastDescendant","getFirstDescendant"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownExport.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { ElementNode, LexicalNode, TextFormatType, TextNode } from 'lexical'\n\nimport { $getRoot, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isTextNode } from 'lexical'\n\nimport type {\n ElementTransformer,\n MultilineElementTransformer,\n TextFormatTransformer,\n TextMatchTransformer,\n Transformer,\n} from './MarkdownTransformers.js'\n\nimport { isEmptyParagraph, transformersByType } from './utils.js'\n\n/**\n * Renders string from markdown. The selection is moved to the start after the operation.\n */\nexport function createMarkdownExport(\n transformers: Array<Transformer>,\n shouldPreserveNewLines: boolean = false,\n): (node?: ElementNode) => string {\n const byType = transformersByType(transformers)\n const elementTransformers = [...byType.multilineElement, ...byType.element]\n const isNewlineDelimited = !shouldPreserveNewLines\n\n // Export only uses text formats that are responsible for single format\n // e.g. it will filter out *** (bold, italic) and instead use separate ** and *\n const textFormatTransformers = byType.textFormat\n .filter((transformer) => transformer.format.length === 1)\n // Make sure all text transformers that contain 'code' in their format are at the end of the array. Otherwise, formatted code like\n // <strong><code>code</code></strong> will be exported as `**Bold Code**`, as the code format will be applied first, and the bold format\n // will be applied second and thus skipped entirely, as the code format will prevent any further formatting.\n .sort((a, b) => {\n if (a.format.includes('code') && !b.format.includes('code')) {\n return 1\n } else if (!a.format.includes('code') && b.format.includes('code')) {\n return -1\n } else {\n return 0\n }\n })\n\n return (node) => {\n const output: string[] = []\n const children = (node || $getRoot()).getChildren()\n\n children.forEach((child, i) => {\n const result = exportTopLevelElements(\n child,\n elementTransformers,\n textFormatTransformers,\n byType.textMatch,\n )\n\n if (result != null) {\n output.push(\n // separate consecutive group of texts with a line break: eg. [\"hello\", \"world\"] -> [\"hello\", \"/nworld\"]\n isNewlineDelimited &&\n i > 0 &&\n !isEmptyParagraph(child) &&\n !isEmptyParagraph(children[i - 1]!)\n ? '\\n'.concat(result)\n : result,\n )\n }\n })\n // Ensure consecutive groups of texts are at least \\n\\n apart while each empty paragraph render as a newline.\n // Eg. [\"hello\", \"\", \"\", \"hi\", \"\\nworld\"] -> \"hello\\n\\n\\nhi\\n\\nworld\"\n return output.join('\\n')\n }\n}\n\nfunction exportTopLevelElements(\n node: LexicalNode,\n elementTransformers: Array<ElementTransformer | MultilineElementTransformer>,\n textTransformersIndex: Array<TextFormatTransformer>,\n textMatchTransformers: Array<TextMatchTransformer>,\n): null | string {\n for (const transformer of elementTransformers) {\n if (!transformer.export) {\n continue\n }\n const result = transformer.export(node, (_node) =>\n exportChildren(_node, textTransformersIndex, textMatchTransformers),\n )\n\n if (result != null) {\n return result\n }\n }\n\n if ($isElementNode(node)) {\n return exportChildren(node, textTransformersIndex, textMatchTransformers)\n } else if ($isDecoratorNode(node)) {\n return node.getTextContent()\n } else {\n return null\n }\n}\n\nfunction exportChildren(\n node: ElementNode,\n textTransformersIndex: Array<TextFormatTransformer>,\n textMatchTransformers: Array<TextMatchTransformer>,\n unclosedTags?: Array<{ format: TextFormatType; tag: string }>,\n unclosableTags?: Array<{ format: TextFormatType; tag: string }>,\n): string {\n const output = []\n const children = node.getChildren()\n // keep track of unclosed tags from the very beginning\n if (!unclosedTags) {\n unclosedTags = []\n }\n if (!unclosableTags) {\n unclosableTags = []\n }\n\n mainLoop: for (const child of children) {\n for (const transformer of textMatchTransformers) {\n if (!transformer.export) {\n continue\n }\n\n const result = transformer.export(\n child,\n (parentNode) =>\n exportChildren(\n parentNode,\n textTransformersIndex,\n textMatchTransformers,\n unclosedTags,\n // Add current unclosed tags to the list of unclosable tags - we don't want nested tags from\n // textmatch transformers to close the outer ones, as that may result in invalid markdown.\n // E.g. **text [text**](https://lexical.io)\n // is invalid markdown, as the closing ** is inside the link.\n //\n [...unclosableTags, ...unclosedTags],\n ),\n (textNode, textContent) =>\n exportTextFormat(\n textNode,\n textContent,\n textTransformersIndex,\n unclosedTags,\n unclosableTags,\n ),\n )\n\n if (result != null) {\n output.push(result)\n continue mainLoop\n }\n }\n\n if ($isLineBreakNode(child)) {\n output.push('\\n')\n } else if ($isTextNode(child)) {\n output.push(\n exportTextFormat(\n child,\n child.getTextContent(),\n textTransformersIndex,\n unclosedTags,\n unclosableTags,\n ),\n )\n } else if ($isElementNode(child)) {\n // empty paragraph returns \"\"\n output.push(\n exportChildren(\n child,\n textTransformersIndex,\n textMatchTransformers,\n unclosedTags,\n unclosableTags,\n ),\n )\n } else if ($isDecoratorNode(child)) {\n output.push(child.getTextContent())\n }\n }\n\n return output.join('')\n}\n\nfunction exportTextFormat(\n node: TextNode,\n textContent: string,\n textTransformers: Array<TextFormatTransformer>,\n // unclosed tags include the markdown tags that haven't been closed yet, and their associated formats\n unclosedTags: Array<{ format: TextFormatType; tag: string }>,\n unclosableTags?: Array<{ format: TextFormatType; tag: string }>,\n): string {\n // This function handles the case of a string looking like this: \" foo \"\n // Where it would be invalid markdown to generate: \"** foo **\"\n // We instead want to trim the whitespace out, apply formatting, and then\n // bring the whitespace back. So our returned string looks like this: \" **foo** \"\n const frozenString = textContent.trim()\n let output = frozenString\n // the opening tags to be added to the result\n let openingTags = ''\n // the closing tags to be added to the result\n let closingTagsBefore = ''\n let closingTagsAfter = ''\n\n const prevNode = getTextSibling(node, true)\n const nextNode = getTextSibling(node, false)\n\n const applied = new Set()\n\n for (const transformer of textTransformers) {\n const format = transformer.format[0]!\n const tag = transformer.tag\n\n // dedup applied formats\n if (hasFormat(node, format) && !applied.has(format)) {\n // Multiple tags might be used for the same format (*, _)\n applied.add(format)\n\n // append the tag to openningTags, if it's not applied to the previous nodes,\n // or the nodes before that (which would result in an unclosed tag)\n if (!hasFormat(prevNode, format) || !unclosedTags.find((element) => element.tag === tag)) {\n unclosedTags.push({ format, tag })\n openingTags += tag\n }\n }\n }\n\n // close any tags in the same order they were applied, if necessary\n for (let i = 0; i < unclosedTags.length; i++) {\n const unclosedTag = unclosedTags[i]!\n const nodeHasFormat = hasFormat(node, unclosedTag.format)\n const nextNodeHasFormat = hasFormat(nextNode, unclosedTag.format)\n\n // prevent adding closing tag if next sibling will do it\n if (nodeHasFormat && nextNodeHasFormat) {\n continue\n }\n\n const unhandledUnclosedTags = [...unclosedTags] // Shallow copy to avoid modifying the original array\n\n while (unhandledUnclosedTags.length > i) {\n const unclosedTag = unhandledUnclosedTags.pop()\n\n // If tag is unclosable, don't close it and leave it in the original array,\n // So that it can be closed when it's no longer unclosable\n if (\n unclosableTags &&\n unclosedTag &&\n unclosableTags.find((element) => element.tag === unclosedTag.tag)\n ) {\n continue\n }\n\n if (unclosedTag && typeof unclosedTag.tag === 'string') {\n if (!nodeHasFormat) {\n // Handles cases where the tag has not been closed before, e.g. if the previous node\n // was a text match transformer that did not account for closing tags of the next node (e.g. a link)\n closingTagsBefore += unclosedTag.tag\n } else if (!nextNodeHasFormat) {\n closingTagsAfter += unclosedTag.tag\n }\n }\n // Mutate the original array to remove the closed tag\n unclosedTags.pop()\n }\n break\n }\n\n output = openingTags + output + closingTagsAfter\n // Replace trimmed version of textContent ensuring surrounding whitespace is not modified\n return closingTagsBefore + textContent.replace(frozenString, () => output)\n}\n\n// Get next or previous text sibling a text node, including cases\n// when it's a child of inline element (e.g. link)\nfunction getTextSibling(node: TextNode, backward: boolean): null | TextNode {\n let sibling = backward ? node.getPreviousSibling() : node.getNextSibling()\n\n if (!sibling) {\n const parent = node.getParentOrThrow()\n\n if (parent.isInline()) {\n sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling()\n }\n }\n\n while (sibling) {\n if ($isElementNode(sibling)) {\n if (!sibling.isInline()) {\n break\n }\n\n const descendant = backward ? sibling.getLastDescendant() : sibling.getFirstDescendant()\n\n if ($isTextNode(descendant)) {\n return descendant\n } else {\n sibling = backward ? sibling.getPreviousSibling() : sibling.getNextSibling()\n }\n }\n\n if ($isTextNode(sibling)) {\n return sibling\n }\n\n if (!$isElementNode(sibling)) {\n return null\n }\n }\n\n return null\n}\n\nfunction hasFormat(node: LexicalNode | null | undefined, format: TextFormatType): boolean {\n return $isTextNode(node) && node.hasFormat(format)\n}\n"],"mappings":"AAAA;;;;;;GAUA,SAASA,QAAQ,EAAEC,gBA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9E,WAAA,CAAY4E,UAAA,GAAa;QAC3B,OAAOA,UAAA;MACT,OAAO;QACLN,OAAA,GAAUD,QAAA,GAAWC,OAAA,CAAQC,kBAAkB,KAAKD,OAAA,CAAQE,cAAc;MAC5E;IACF;IAEA,IAAIxE,WAAA,CAAYsE,OAAA,GAAU;MACxB,OAAOA,OAAA;IACT;IAEA,IAAI,CAACxE,cAAA,CAAewE,OAAA,GAAU;MAC5B,OAAO;IACT;EACF;EAEA,OAAO;AACT;AAEA,SAASX,UAAUtC,IAAoC,EAAEN,MAAsB;EAC7E,OAAOf,WAAA,CAAYqB,IAAA,KAASA,IAAA,CAAKsC,SAAS,CAAC5C,MAAA;AAC7C","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownImport.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/MarkdownImport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAe1C,OAAO,KAAK,EAGV,qBAAqB,EAErB,WAAW,EACZ,MAAM,2BAA2B,CAAA;AAKlC,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IACjD,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACtD,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAA;CACnE,CAAC,CAAA;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,EAChC,sBAAsB,UAAQ,GAC7B,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,IAAI,CAyCtD"}
1
+ {"version":3,"file":"MarkdownImport.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/MarkdownImport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAc1C,OAAO,KAAK,EAGV,qBAAqB,EAErB,WAAW,EACZ,MAAM,2BAA2B,CAAA;AAMlC,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IACjD,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACtD,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAA;CACnE,CAAC,CAAA;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,EAChC,sBAAsB,UAAQ,GAC7B,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,IAAI,CAyCtD"}
@@ -7,7 +7,8 @@
7
7
  */import { $isListItemNode, $isListNode } from '@lexical/list';
8
8
  import { $isQuoteNode } from '@lexical/rich-text';
9
9
  import { $findMatchingParent } from '@lexical/utils';
10
- import { $createLineBreakNode, $createParagraphNode, $createTextNode, $getRoot, $getSelection, $isParagraphNode, $isTextNode } from 'lexical';
10
+ import { $createLineBreakNode, $createParagraphNode, $createTextNode, $getRoot, $getSelection, $isParagraphNode } from 'lexical';
11
+ import { IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI } from '../../../lexical/utils/environment.js';
11
12
  import { importTextTransformers } from './importTextTransformers.js';
12
13
  import { isEmptyParagraph, transformersByType } from './utils.js';
13
14
  /**
@@ -148,14 +149,6 @@ function $importBlocks(lineText, rootNode, elementTransformers, textFormatTransf
148
149
  }
149
150
  }
150
151
  importTextTransformers(textNode, textFormatTransformersIndex, textMatchTransformers);
151
- // Go through every text node in the element node and handle escape characters
152
- for (const child of elementNode.getChildren()) {
153
- if ($isTextNode(child)) {
154
- const textContent = child.getTextContent();
155
- const escapedText = textContent.replace(/\\([*_`~])/g, '$1');
156
- child.setTextContent(escapedText);
157
- }
158
- }
159
152
  // If no transformer found and we left with original paragraph node
160
153
  // can check if its content can be appended to the previous node
161
154
  // if it's a paragraph, quote or list
@@ -190,20 +183,17 @@ function createTextFormatTransformersIndex(textTransformers) {
190
183
  transformersByTag[tag] = transformer;
191
184
  const tagRegExp = tag.replace(/([*^+])/g, '\\$1');
192
185
  openTagsRegExp.push(tagRegExp);
193
- // Single-char tag (e.g. "*"),
194
- if (tag.length === 1) {
195
- fullMatchRegExpByTag[tag] = new RegExp(`(?<![\\\\${tagRegExp}])(${tagRegExp})((\\\\${tagRegExp})?.*?[^${tagRegExp}\\s](\\\\${tagRegExp})?)((?<!\\\\)|(?<=\\\\\\\\))(${tagRegExp})(?![\\\\${tagRegExp}])`);
186
+ if (IS_SAFARI || IS_IOS || IS_APPLE_WEBKIT) {
187
+ fullMatchRegExpByTag[tag] = new RegExp(`(${tagRegExp})(?![${tagRegExp}\\s])(.*?[^${tagRegExp}\\s])${tagRegExp}(?!${tagRegExp})`);
196
188
  } else {
197
- // Multi‐char tags (e.g. "**")
198
- fullMatchRegExpByTag[tag] = new RegExp(`(?<!\\\\)(${tagRegExp})((\\\\${tagRegExp})?.*?[^\\s](\\\\${tagRegExp})?)((?<!\\\\)|(?<=\\\\\\\\))(${tagRegExp})(?!\\\\)`);
189
+ fullMatchRegExpByTag[tag] = new RegExp(`(?<![\\\\${tagRegExp}])(${tagRegExp})((\\\\${tagRegExp})?.*?[^${tagRegExp}\\s](\\\\${tagRegExp})?)((?<!\\\\)|(?<=\\\\\\\\))(${tagRegExp})(?![\\\\${tagRegExp}])`);
199
190
  }
200
191
  }
201
192
  return {
202
193
  // Reg exp to find open tag + content + close tag
203
194
  fullMatchRegExpByTag,
204
- // Regexp to locate *any* potential opening tag (longest first).
205
- // eslint-disable-next-line regexp/no-useless-character-class, regexp/no-empty-capturing-group, regexp/no-empty-group
206
- openTagsRegExp: new RegExp(`${escapeRegExp}(${openTagsRegExp.join('|')})`, 'g'),
195
+ // Reg exp to find opening tags
196
+ openTagsRegExp: new RegExp((IS_SAFARI || IS_IOS || IS_APPLE_WEBKIT ? '' : `${escapeRegExp}`) + '(' + openTagsRegExp.join('|') + ')', 'g'),
207
197
  transformersByTag
208
198
  };
209
199
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownImport.js","names":["$isListItemNode","$isListNode","$isQuoteNode","$findMatchingParent","$createLineBreakNode","$createParagraphNode","$createTextNode","$getRoot","$getSelection","$isParagraphNode","$isTextNode","importTextTransformers","isEmptyParagraph","transformersByType","createMarkdownImport","transformers","shouldPreserveNewLines","byType","textFormatTransformersIndex","createTextFormatTransformersIndex","textFormat","markdownString","node","lines","split","linesLength","length","root","clear","i","lineText","imported","shiftedIndex","$importMultiline","multilineElement","$importBlocks","element","textMatch","children","getChildren","child","getChildrenSize","remove","selectStart","startLineIndex","multilineElementTransformers","rootNode","transformer","handleImportAfterStartMatch","regExpEnd","regExpStart","replace","startMatch","match","result","regexpEndRegex","regExp","isEndOptional","optional","endLineIndex","endMatch","index","linesInBetween","push","slice","line","text","elementTransformers","textMatchTransformers","textNode","elementNode","append","setTextContent","textContent","getTextContent","escapedText","isAttached","previousNode","getPreviousSibling","targetNode","lastDescendant","getLastDescendant","getTextContentSize","splice","textTransformers","transformersByTag","fullMatchRegExpByTag","openTagsRegExp","escapeRegExp","tag","tagRegExp","RegExp","join"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownImport.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { ListItemNode } from '@lexical/list'\nimport type { ElementNode } from 'lexical'\n\nimport { $isListItemNode, $isListNode } from '@lexical/list'\nimport { $isQuoteNode } from '@lexical/rich-text'\nimport { $findMatchingParent } from '@lexical/utils'\nimport {\n $createLineBreakNode,\n $createParagraphNode,\n $createTextNode,\n $getRoot,\n $getSelection,\n $isParagraphNode,\n $isTextNode,\n} from 'lexical'\n\nimport type {\n ElementTransformer,\n MultilineElementTransformer,\n TextFormatTransformer,\n TextMatchTransformer,\n Transformer,\n} from './MarkdownTransformers.js'\n\nimport { importTextTransformers } from './importTextTransformers.js'\nimport { isEmptyParagraph, transformersByType } from './utils.js'\n\nexport type TextFormatTransformersIndex = Readonly<{\n fullMatchRegExpByTag: Readonly<Record<string, RegExp>>\n openTagsRegExp: RegExp\n transformersByTag: Readonly<Record<string, TextFormatTransformer>>\n}>\n\n/**\n * Renders markdown from a string. The selection is moved to the start after the operation.\n */\nexport function createMarkdownImport(\n transformers: Array<Transformer>,\n shouldPreserveNewLines = false,\n): (markdownString: string, node?: ElementNode) => void {\n const byType = transformersByType(transformers)\n const textFormatTransformersIndex = createTextFormatTransformersIndex(byType.textFormat)\n\n return (markdownString, node) => {\n const lines = markdownString.split('\\n')\n const linesLength = lines.length\n const root = node || $getRoot()\n root.clear()\n\n for (let i = 0; i < linesLength; i++) {\n const lineText = lines[i]!\n\n const [imported, shiftedIndex] = $importMultiline(lines, i, byType.multilineElement, root)\n\n if (imported) {\n // If a multiline markdown element was imported, we don't want to process the lines that were part of it anymore.\n // There could be other sub-markdown elements (both multiline and normal ones) matching within this matched multiline element's children.\n // However, it would be the responsibility of the matched multiline transformer to decide how it wants to handle them.\n // We cannot handle those, as there is no way for us to know how to maintain the correct order of generated lexical nodes for possible children.\n i = shiftedIndex // Next loop will start from the line after the last line of the multiline element\n continue\n }\n\n $importBlocks(lineText, root, byType.element, textFormatTransformersIndex, byType.textMatch)\n }\n\n // By default, removing empty paragraphs as md does not really\n // allow empty lines and uses them as delimiter.\n // If you need empty lines set shouldPreserveNewLines = true.\n const children = root.getChildren()\n for (const child of children) {\n if (!shouldPreserveNewLines && isEmptyParagraph(child) && root.getChildrenSize() > 1) {\n child.remove()\n }\n }\n\n if ($getSelection() !== null) {\n root.selectStart()\n }\n }\n}\n\n/**\n *\n * @returns first element of the returned tuple is a boolean indicating if a multiline element was imported. The second element is the index of the last line that was processed.\n */\nfunction $importMultiline(\n lines: Array<string>,\n startLineIndex: number,\n multilineElementTransformers: Array<MultilineElementTransformer>,\n rootNode: ElementNode,\n): [boolean, number] {\n for (const transformer of multilineElementTransformers) {\n const { handleImportAfterStartMatch, regExpEnd, regExpStart, replace } = transformer\n\n const startMatch = lines[startLineIndex]?.match(regExpStart)\n if (!startMatch) {\n continue // Try next transformer\n }\n\n if (handleImportAfterStartMatch) {\n const result = handleImportAfterStartMatch({\n lines,\n rootNode,\n startLineIndex,\n startMatch,\n transformer,\n })\n if (result === null) {\n continue\n } else if (result) {\n return result\n }\n }\n\n const regexpEndRegex: RegExp | undefined =\n typeof regExpEnd === 'object' && 'regExp' in regExpEnd ? regExpEnd.regExp : regExpEnd\n\n const isEndOptional =\n regExpEnd && typeof regExpEnd === 'object' && 'optional' in regExpEnd\n ? regExpEnd.optional\n : !regExpEnd\n\n let endLineIndex = startLineIndex\n const linesLength = lines.length\n\n // check every single line for the closing match. It could also be on the same line as the opening match.\n while (endLineIndex < linesLength) {\n const endMatch = regexpEndRegex ? lines[endLineIndex]?.match(regexpEndRegex) : null\n if (!endMatch) {\n if (\n !isEndOptional ||\n (isEndOptional && endLineIndex < linesLength - 1) // Optional end, but didn't reach the end of the document yet => continue searching for potential closing match\n ) {\n endLineIndex++\n continue // Search next line for closing match\n }\n }\n\n // Now, check if the closing match matched is the same as the opening match.\n // If it is, we need to continue searching for the actual closing match.\n if (endMatch && startLineIndex === endLineIndex && endMatch.index === startMatch.index) {\n endLineIndex++\n continue // Search next line for closing match\n }\n\n // At this point, we have found the closing match. Next: calculate the lines in between open and closing match\n // This should not include the matches themselves, and be split up by lines\n const linesInBetween: string[] = []\n\n if (endMatch && startLineIndex === endLineIndex) {\n linesInBetween.push(lines[startLineIndex]!.slice(startMatch[0].length, -endMatch[0].length))\n } else {\n for (let i = startLineIndex; i <= endLineIndex; i++) {\n const line = lines[i]!\n if (i === startLineIndex) {\n const text = line.slice(startMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else if (i === endLineIndex && endMatch) {\n const text = line.slice(0, -endMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else {\n linesInBetween.push(line)\n }\n }\n }\n\n if (replace(rootNode, null, startMatch, endMatch!, linesInBetween, true) !== false) {\n // Return here. This $importMultiline function is run line by line and should only process a single multiline element at a time.\n return [true, endLineIndex]\n }\n\n // The replace function returned false, despite finding the matching open and close tags => this transformer does not want to handle it.\n // Thus, we continue letting the remaining transformers handle the passed lines of text from the beginning\n break\n }\n }\n\n // No multiline transformer handled this line successfully\n return [false, startLineIndex]\n}\n\nfunction $importBlocks(\n lineText: string,\n rootNode: ElementNode,\n elementTransformers: Array<ElementTransformer>,\n textFormatTransformersIndex: TextFormatTransformersIndex,\n textMatchTransformers: Array<TextMatchTransformer>,\n) {\n const textNode = $createTextNode(lineText)\n const elementNode = $createParagraphNode()\n elementNode.append(textNode)\n rootNode.append(elementNode)\n\n for (const { regExp, replace } of elementTransformers) {\n const match = lineText.match(regExp)\n\n if (match) {\n textNode.setTextContent(lineText.slice(match[0].length))\n if (replace(elementNode, [textNode], match, true) !== false) {\n break\n }\n }\n }\n\n importTextTransformers(textNode, textFormatTransformersIndex, textMatchTransformers)\n\n // Go through every text node in the element node and handle escape characters\n for (const child of elementNode.getChildren()) {\n if ($isTextNode(child)) {\n const textContent = child.getTextContent()\n const escapedText = textContent.replace(/\\\\([*_`~])/g, '$1')\n child.setTextContent(escapedText)\n }\n }\n\n // If no transformer found and we left with original paragraph node\n // can check if its content can be appended to the previous node\n // if it's a paragraph, quote or list\n if (elementNode.isAttached() && lineText.length > 0) {\n const previousNode = elementNode.getPreviousSibling()\n if ($isParagraphNode(previousNode) || $isQuoteNode(previousNode) || $isListNode(previousNode)) {\n let targetNode: ListItemNode | null | typeof previousNode = previousNode\n\n if ($isListNode(previousNode)) {\n const lastDescendant = previousNode.getLastDescendant()\n if (lastDescendant == null) {\n targetNode = null\n } else {\n targetNode = $findMatchingParent(lastDescendant, $isListItemNode)\n }\n }\n\n if (targetNode != null && targetNode.getTextContentSize() > 0) {\n targetNode.splice(targetNode.getChildrenSize(), 0, [\n $createLineBreakNode(),\n ...elementNode.getChildren(),\n ])\n elementNode.remove()\n }\n }\n }\n}\n\nfunction createTextFormatTransformersIndex(\n textTransformers: Array<TextFormatTransformer>,\n): TextFormatTransformersIndex {\n const transformersByTag: Record<string, TextFormatTransformer> = {}\n const fullMatchRegExpByTag: Record<string, RegExp> = {}\n const openTagsRegExp: string[] = []\n const escapeRegExp = `(?<![\\\\\\\\])`\n\n for (const transformer of textTransformers) {\n const { tag } = transformer\n transformersByTag[tag] = transformer\n const tagRegExp = tag.replace(/([*^+])/g, '\\\\$1')\n openTagsRegExp.push(tagRegExp)\n\n // Single-char tag (e.g. \"*\"),\n if (tag.length === 1) {\n fullMatchRegExpByTag[tag] = new RegExp(\n `(?<![\\\\\\\\${tagRegExp}])(${tagRegExp})((\\\\\\\\${tagRegExp})?.*?[^${tagRegExp}\\\\s](\\\\\\\\${tagRegExp})?)((?<!\\\\\\\\)|(?<=\\\\\\\\\\\\\\\\))(${tagRegExp})(?![\\\\\\\\${tagRegExp}])`,\n )\n } else {\n // Multi‐char tags (e.g. \"**\")\n fullMatchRegExpByTag[tag] = new RegExp(\n `(?<!\\\\\\\\)(${tagRegExp})((\\\\\\\\${tagRegExp})?.*?[^\\\\s](\\\\\\\\${tagRegExp})?)((?<!\\\\\\\\)|(?<=\\\\\\\\\\\\\\\\))(${tagRegExp})(?!\\\\\\\\)`,\n )\n }\n }\n\n return {\n // Reg exp to find open tag + content + close tag\n fullMatchRegExpByTag,\n\n // Regexp to locate *any* potential opening tag (longest first).\n // eslint-disable-next-line regexp/no-useless-character-class, regexp/no-empty-capturing-group, regexp/no-empty-group\n openTagsRegExp: new RegExp(`${escapeRegExp}(${openTagsRegExp.join('|')})`, 'g'),\n transformersByTag,\n }\n}\n"],"mappings":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AA,YAAqBA,SAAA,IAAa;IAErK,OAAO;MACL;MACAJ,oBAAoB,CAACG,GAAA,CAAI,GAAG,IAAIE,MAAA,CAC9B,aAAaD,SAAA,UAAmBA,SAAA,mBAA4BA,SAAA,gCAAyCA,SAAA,WAAoB;IAE7H;EACF;EAEA,OAAO;IACL;IACAJ,oBAAA;IAEA;IACA;IACAC,cAAA,EAAgB,IAAII,MAAA,CAAO,GAAGH,YAAA,IAAgBD,cAAA,CAAeK,IAAI,CAAC,OAAO,EAAE;IAC3EP;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"MarkdownImport.js","names":["$isListItemNode","$isListNode","$isQuoteNode","$findMatchingParent","$createLineBreakNode","$createParagraphNode","$createTextNode","$getRoot","$getSelection","$isParagraphNode","IS_APPLE_WEBKIT","IS_IOS","IS_SAFARI","importTextTransformers","isEmptyParagraph","transformersByType","createMarkdownImport","transformers","shouldPreserveNewLines","byType","textFormatTransformersIndex","createTextFormatTransformersIndex","textFormat","markdownString","node","lines","split","linesLength","length","root","clear","i","lineText","imported","shiftedIndex","$importMultiline","multilineElement","$importBlocks","element","textMatch","children","getChildren","child","getChildrenSize","remove","selectStart","startLineIndex","multilineElementTransformers","rootNode","transformer","handleImportAfterStartMatch","regExpEnd","regExpStart","replace","startMatch","match","result","regexpEndRegex","regExp","isEndOptional","optional","endLineIndex","endMatch","index","linesInBetween","push","slice","line","text","elementTransformers","textMatchTransformers","textNode","elementNode","append","setTextContent","isAttached","previousNode","getPreviousSibling","targetNode","lastDescendant","getLastDescendant","getTextContentSize","splice","textTransformers","transformersByTag","fullMatchRegExpByTag","openTagsRegExp","escapeRegExp","tag","tagRegExp","RegExp","join"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownImport.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { ListItemNode } from '@lexical/list'\nimport type { ElementNode } from 'lexical'\n\nimport { $isListItemNode, $isListNode } from '@lexical/list'\nimport { $isQuoteNode } from '@lexical/rich-text'\nimport { $findMatchingParent } from '@lexical/utils'\nimport {\n $createLineBreakNode,\n $createParagraphNode,\n $createTextNode,\n $getRoot,\n $getSelection,\n $isParagraphNode,\n} from 'lexical'\n\nimport type {\n ElementTransformer,\n MultilineElementTransformer,\n TextFormatTransformer,\n TextMatchTransformer,\n Transformer,\n} from './MarkdownTransformers.js'\n\nimport { IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI } from '../../../lexical/utils/environment.js'\nimport { importTextTransformers } from './importTextTransformers.js'\nimport { isEmptyParagraph, transformersByType } from './utils.js'\n\nexport type TextFormatTransformersIndex = Readonly<{\n fullMatchRegExpByTag: Readonly<Record<string, RegExp>>\n openTagsRegExp: RegExp\n transformersByTag: Readonly<Record<string, TextFormatTransformer>>\n}>\n\n/**\n * Renders markdown from a string. The selection is moved to the start after the operation.\n */\nexport function createMarkdownImport(\n transformers: Array<Transformer>,\n shouldPreserveNewLines = false,\n): (markdownString: string, node?: ElementNode) => void {\n const byType = transformersByType(transformers)\n const textFormatTransformersIndex = createTextFormatTransformersIndex(byType.textFormat)\n\n return (markdownString, node) => {\n const lines = markdownString.split('\\n')\n const linesLength = lines.length\n const root = node || $getRoot()\n root.clear()\n\n for (let i = 0; i < linesLength; i++) {\n const lineText = lines[i]!\n\n const [imported, shiftedIndex] = $importMultiline(lines, i, byType.multilineElement, root)\n\n if (imported) {\n // If a multiline markdown element was imported, we don't want to process the lines that were part of it anymore.\n // There could be other sub-markdown elements (both multiline and normal ones) matching within this matched multiline element's children.\n // However, it would be the responsibility of the matched multiline transformer to decide how it wants to handle them.\n // We cannot handle those, as there is no way for us to know how to maintain the correct order of generated lexical nodes for possible children.\n i = shiftedIndex // Next loop will start from the line after the last line of the multiline element\n continue\n }\n\n $importBlocks(lineText, root, byType.element, textFormatTransformersIndex, byType.textMatch)\n }\n\n // By default, removing empty paragraphs as md does not really\n // allow empty lines and uses them as delimiter.\n // If you need empty lines set shouldPreserveNewLines = true.\n const children = root.getChildren()\n for (const child of children) {\n if (!shouldPreserveNewLines && isEmptyParagraph(child) && root.getChildrenSize() > 1) {\n child.remove()\n }\n }\n\n if ($getSelection() !== null) {\n root.selectStart()\n }\n }\n}\n\n/**\n *\n * @returns first element of the returned tuple is a boolean indicating if a multiline element was imported. The second element is the index of the last line that was processed.\n */\nfunction $importMultiline(\n lines: Array<string>,\n startLineIndex: number,\n multilineElementTransformers: Array<MultilineElementTransformer>,\n rootNode: ElementNode,\n): [boolean, number] {\n for (const transformer of multilineElementTransformers) {\n const { handleImportAfterStartMatch, regExpEnd, regExpStart, replace } = transformer\n\n const startMatch = lines[startLineIndex]?.match(regExpStart)\n if (!startMatch) {\n continue // Try next transformer\n }\n\n if (handleImportAfterStartMatch) {\n const result = handleImportAfterStartMatch({\n lines,\n rootNode,\n startLineIndex,\n startMatch,\n transformer,\n })\n if (result === null) {\n continue\n } else if (result) {\n return result\n }\n }\n\n const regexpEndRegex: RegExp | undefined =\n typeof regExpEnd === 'object' && 'regExp' in regExpEnd ? regExpEnd.regExp : regExpEnd\n\n const isEndOptional =\n regExpEnd && typeof regExpEnd === 'object' && 'optional' in regExpEnd\n ? regExpEnd.optional\n : !regExpEnd\n\n let endLineIndex = startLineIndex\n const linesLength = lines.length\n\n // check every single line for the closing match. It could also be on the same line as the opening match.\n while (endLineIndex < linesLength) {\n const endMatch = regexpEndRegex ? lines[endLineIndex]?.match(regexpEndRegex) : null\n if (!endMatch) {\n if (\n !isEndOptional ||\n (isEndOptional && endLineIndex < linesLength - 1) // Optional end, but didn't reach the end of the document yet => continue searching for potential closing match\n ) {\n endLineIndex++\n continue // Search next line for closing match\n }\n }\n\n // Now, check if the closing match matched is the same as the opening match.\n // If it is, we need to continue searching for the actual closing match.\n if (endMatch && startLineIndex === endLineIndex && endMatch.index === startMatch.index) {\n endLineIndex++\n continue // Search next line for closing match\n }\n\n // At this point, we have found the closing match. Next: calculate the lines in between open and closing match\n // This should not include the matches themselves, and be split up by lines\n const linesInBetween: string[] = []\n\n if (endMatch && startLineIndex === endLineIndex) {\n linesInBetween.push(lines[startLineIndex]!.slice(startMatch[0].length, -endMatch[0].length))\n } else {\n for (let i = startLineIndex; i <= endLineIndex; i++) {\n const line = lines[i]!\n if (i === startLineIndex) {\n const text = line.slice(startMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else if (i === endLineIndex && endMatch) {\n const text = line.slice(0, -endMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else {\n linesInBetween.push(line)\n }\n }\n }\n\n if (replace(rootNode, null, startMatch, endMatch!, linesInBetween, true) !== false) {\n // Return here. This $importMultiline function is run line by line and should only process a single multiline element at a time.\n return [true, endLineIndex]\n }\n\n // The replace function returned false, despite finding the matching open and close tags => this transformer does not want to handle it.\n // Thus, we continue letting the remaining transformers handle the passed lines of text from the beginning\n break\n }\n }\n\n // No multiline transformer handled this line successfully\n return [false, startLineIndex]\n}\n\nfunction $importBlocks(\n lineText: string,\n rootNode: ElementNode,\n elementTransformers: Array<ElementTransformer>,\n textFormatTransformersIndex: TextFormatTransformersIndex,\n textMatchTransformers: Array<TextMatchTransformer>,\n) {\n const textNode = $createTextNode(lineText)\n const elementNode = $createParagraphNode()\n elementNode.append(textNode)\n rootNode.append(elementNode)\n\n for (const { regExp, replace } of elementTransformers) {\n const match = lineText.match(regExp)\n\n if (match) {\n textNode.setTextContent(lineText.slice(match[0].length))\n if (replace(elementNode, [textNode], match, true) !== false) {\n break\n }\n }\n }\n\n importTextTransformers(textNode, textFormatTransformersIndex, textMatchTransformers)\n\n // If no transformer found and we left with original paragraph node\n // can check if its content can be appended to the previous node\n // if it's a paragraph, quote or list\n if (elementNode.isAttached() && lineText.length > 0) {\n const previousNode = elementNode.getPreviousSibling()\n if ($isParagraphNode(previousNode) || $isQuoteNode(previousNode) || $isListNode(previousNode)) {\n let targetNode: ListItemNode | null | typeof previousNode = previousNode\n\n if ($isListNode(previousNode)) {\n const lastDescendant = previousNode.getLastDescendant()\n if (lastDescendant == null) {\n targetNode = null\n } else {\n targetNode = $findMatchingParent(lastDescendant, $isListItemNode)\n }\n }\n\n if (targetNode != null && targetNode.getTextContentSize() > 0) {\n targetNode.splice(targetNode.getChildrenSize(), 0, [\n $createLineBreakNode(),\n ...elementNode.getChildren(),\n ])\n elementNode.remove()\n }\n }\n }\n}\n\nfunction createTextFormatTransformersIndex(\n textTransformers: Array<TextFormatTransformer>,\n): TextFormatTransformersIndex {\n const transformersByTag: Record<string, TextFormatTransformer> = {}\n const fullMatchRegExpByTag: Record<string, RegExp> = {}\n const openTagsRegExp: string[] = []\n const escapeRegExp = `(?<![\\\\\\\\])`\n\n for (const transformer of textTransformers) {\n const { tag } = transformer\n transformersByTag[tag] = transformer\n const tagRegExp = tag.replace(/([*^+])/g, '\\\\$1')\n openTagsRegExp.push(tagRegExp)\n\n if (IS_SAFARI || IS_IOS || IS_APPLE_WEBKIT) {\n fullMatchRegExpByTag[tag] = new RegExp(\n `(${tagRegExp})(?![${tagRegExp}\\\\s])(.*?[^${tagRegExp}\\\\s])${tagRegExp}(?!${tagRegExp})`,\n )\n } else {\n fullMatchRegExpByTag[tag] = new RegExp(\n `(?<![\\\\\\\\${tagRegExp}])(${tagRegExp})((\\\\\\\\${tagRegExp})?.*?[^${tagRegExp}\\\\s](\\\\\\\\${tagRegExp})?)((?<!\\\\\\\\)|(?<=\\\\\\\\\\\\\\\\))(${tagRegExp})(?![\\\\\\\\${tagRegExp}])`,\n )\n }\n }\n\n return {\n // Reg exp to find open tag + content + close tag\n fullMatchRegExpByTag,\n // Reg exp to find opening tags\n openTagsRegExp: new RegExp(\n (IS_SAFARI || IS_IOS || IS_APPLE_WEBKIT ? '' : `${escapeRegExp}`) +\n '(' +\n openTagsRegExp.join('|') +\n ')',\n 'g',\n ),\n transformersByTag,\n }\n}\n"],"mappings":"AAAA;;;;;;GAWA,SAASA,eAAe,EAAEC,WAAW,QAAQ;AAC7C,SAAS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UD,eAAA,GAAkB,KAAK,GAAG6E,YAAA,EAAc,IAC9D,MACAD,cAAA,CAAeK,IAAI,CAAC,OACpB,KACF;IAEFP;EACF;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/richtext-lexical",
3
- "version": "3.29.0-internal.d74b919",
3
+ "version": "3.29.0-internal.e4e913b",
4
4
  "description": "The officially supported Lexical richtext adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -364,8 +364,8 @@
364
364
  "react-error-boundary": "4.1.2",
365
365
  "ts-essentials": "10.0.3",
366
366
  "uuid": "10.0.0",
367
- "@payloadcms/translations": "3.29.0-internal.d74b919",
368
- "@payloadcms/ui": "3.29.0-internal.d74b919"
367
+ "@payloadcms/translations": "3.29.0-internal.e4e913b",
368
+ "@payloadcms/ui": "3.29.0-internal.e4e913b"
369
369
  },
370
370
  "devDependencies": {
371
371
  "@babel/cli": "7.26.4",
@@ -386,15 +386,15 @@
386
386
  "eslint-plugin-react-compiler": "19.0.0-beta-714736e-20250131",
387
387
  "swc-plugin-transform-remove-imports": "3.1.0",
388
388
  "@payloadcms/eslint-config": "3.28.0",
389
- "payload": "3.29.0-internal.d74b919"
389
+ "payload": "3.29.0-internal.e4e913b"
390
390
  },
391
391
  "peerDependencies": {
392
392
  "@faceless-ui/modal": "3.0.0-beta.2",
393
393
  "@faceless-ui/scroll-info": "2.0.0",
394
394
  "react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
395
395
  "react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
396
- "@payloadcms/next": "3.29.0-internal.d74b919",
397
- "payload": "3.29.0-internal.d74b919"
396
+ "@payloadcms/next": "3.29.0-internal.e4e913b",
397
+ "payload": "3.29.0-internal.e4e913b"
398
398
  },
399
399
  "engines": {
400
400
  "node": "^18.20.2 || >=20.9.0"
@@ -1,12 +0,0 @@
1
- var st=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";var Q=class{_x;_y;constructor(t,e){this._x=t,this._y=e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}equals({x:t,y:e}){return this.x===t&&this.y===e}get x(){return this._x}get y(){return this._y}};function ct(r){return r instanceof Q}import{c as Ne}from"react/compiler-runtime";import{jsx as Ie}from"react/jsx-runtime";import{useLexicalComposerContext as ye}from"@lexical/react/LexicalComposerContext.js";import{mergeRegister as Oe}from"@lexical/utils";import{$getSelection as V,$isRangeSelection as Z,$isTextNode as Ae,COMMAND_PRIORITY_LOW as be,createCommand as ke,getDOMSelection as Me}from"lexical";import{useEffect as xt,useState as $e}from"react";import*as q from"react";import{c as dt}from"react/compiler-runtime";import{useLexicalComposerContext as mt}from"@lexical/react/LexicalComposerContext.js";import{mergeRegister as at}from"@lexical/utils";import{$getSelection as gt,$isRangeSelection as ae,$setSelection as le,COMMAND_PRIORITY_LOW as k,createCommand as fe,KEY_ARROW_DOWN_COMMAND as ue,KEY_ARROW_UP_COMMAND as de,KEY_ENTER_COMMAND as me,KEY_ESCAPE_COMMAND as ge,KEY_TAB_COMMAND as pe}from"lexical";import{useCallback as j,useEffect as M,useLayoutEffect as he,useMemo as xe,useRef as Ee,useState as _e}from"react";var Te="slash-menu-popup",lt=r=>{let t=document.getElementById("slash-menu");if(!t)return;let e=t.getBoundingClientRect();e.top+e.height>window.innerHeight&&t.scrollIntoView({block:"center"}),e.top<0&&t.scrollIntoView({block:"center"}),r.scrollIntoView({block:"nearest"})};function Se(r,t,e){let o=e;for(let n=o;n<=t.length;n++)r.substring(r.length-n)===t.substring(0,n)&&(o=n);return o}function we(r){let t=gt();if(!ae(t)||!t.isCollapsed())return;let e=t.anchor;if(e.type!=="text")return;let o=e.getNode();if(!o.isSimpleText())return;let n=e.offset,i=o.getTextContent().slice(0,n),c=r.replaceableString.length,s=Se(i,r.matchingString,c),a=n-s;if(a<0)return;let f;return a===0?[f]=o.splitText(n):[,f]=o.splitText(a,n),f}function Ce(r,t){let e=getComputedStyle(r),o=e.position==="absolute",n=t?/(auto|scroll|hidden)/:/(auto|scroll)/;if(e.position==="fixed")return document.body;for(let i=r;i=i.parentElement;)if(e=getComputedStyle(i),!(o&&e.position==="static")&&n.test(e.overflow+e.overflowY+e.overflowX))return i;return document.body}function ft(r,t){let e=r.getBoundingClientRect(),o=t.getBoundingClientRect();return e.top>o.top&&e.top<o.bottom}function Re(r,t,e,o){let n=dt(12),[i]=mt(),c;n[0]!==i||n[1]!==e||n[2]!==o||n[3]!==r||n[4]!==t.current?(c=()=>{let a=t.current;if(a!=null&&r!=null){let f=i.getRootElement(),l=f!=null?Ce(f,!1):document.body,m;m=!1;let g;g=ft(a,l);let p=function(){m||(window.requestAnimationFrame(function(){e(),m=!1}),m=!0);let u=ft(a,l);u!==g&&(g=u,o?.(u))},d=new ResizeObserver(e);return window.addEventListener("resize",e),document.addEventListener("scroll",p,{capture:!0,passive:!0}),d.observe(a),()=>{d.disconnect(),window.removeEventListener("resize",e),document.removeEventListener("scroll",p,!0)}}},n[0]=i,n[1]=e,n[2]=o,n[3]=r,n[4]=t.current,n[5]=c):c=n[5];let s;n[6]!==i||n[7]!==e||n[8]!==o||n[9]!==r||n[10]!==t?(s=[i,o,e,r,t],n[6]=i,n[7]=e,n[8]=o,n[9]=r,n[10]=t,n[11]=s):s=n[11],M(c,s)}var ut=fe("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function pt({anchorElementRef:r,close:t,editor:e,groups:o,menuRenderFn:n,resolution:i,shouldSplitNodeWithQuery:c=!1}){let[s,a]=_e(null),f=i.match&&i.match.matchingString||"",l=j(d=>{let u=e.getRootElement();u!==null&&(u.setAttribute("aria-activedescendant",`${Te}__item-${d.key}`),a(d.key))},[e]),m=j(()=>{if(o!==null&&f!=null){let d=o.flatMap(u=>u.items);if(d.length){let u=d[0];l(u)}}},[o,l,f]);M(()=>{m()},[f,m]);let g=j(d=>{t(),e.update(()=>{let u=i.match!=null&&c?we(i.match):null;u&&u.remove()}),setTimeout(()=>{let u;e.read(()=>{u=gt()?.clone()}),e.update(()=>{u&&le(u)}),d.onSelect({editor:e,queryString:i.match?i.match.matchingString:""})},0)},[e,c,i.match,t]);M(()=>()=>{let d=e.getRootElement();d!==null&&d.removeAttribute("aria-activedescendant")},[e]),he(()=>{o===null?a(null):s===null&&m()},[o,s,l,m]),M(()=>at(e.registerCommand(ut,({item:d})=>d.ref&&d.ref.current!=null?(lt(d.ref.current),!0):!1,k)),[e,l]),M(()=>at(e.registerCommand(ue,d=>{let u=d;if(o!==null&&o.length&&s!==null){let x=o.flatMap(T=>T.items),h=x.findIndex(T=>T.key===s),E=h!==x.length-1?h+1:0,_=x[E];if(!_)return!1;l(_),_.ref!=null&&_.ref.current&&e.dispatchCommand(ut,{index:E,item:_}),u.preventDefault(),u.stopImmediatePropagation()}return!0},k),e.registerCommand(de,d=>{let u=d;if(o!==null&&o.length&&s!==null){let x=o.flatMap(T=>T.items),h=x.findIndex(T=>T.key===s),E=h!==0?h-1:x.length-1,_=x[E];if(!_)return!1;l(_),_.ref!=null&&_.ref.current&&lt(_.ref.current),u.preventDefault(),u.stopImmediatePropagation()}return!0},k),e.registerCommand(ge,d=>{let u=d;return u.preventDefault(),u.stopImmediatePropagation(),t(),!0},k),e.registerCommand(pe,d=>{let u=d;if(o===null||s===null)return!1;let h=o.flatMap(E=>E.items).find(E=>E.key===s);return h?(u.preventDefault(),u.stopImmediatePropagation(),g(h),!0):!1},k),e.registerCommand(me,d=>{if(o===null||s===null)return!1;let x=o.flatMap(h=>h.items).find(h=>h.key===s);return x?(d!==null&&(d.preventDefault(),d.stopImmediatePropagation()),g(x),!0):!1},k)),[g,t,e,o,s,l]);let p=xe(()=>({groups:o,selectedItemKey:s,selectItemAndCleanUp:g,setSelectedItemKey:a}),[g,s,o]);return n(r,p,i.match?i.match.matchingString:"")}function Fe(r,t){t!=null&&(r.className=t),r.setAttribute("aria-label","Slash menu"),r.setAttribute("role","listbox"),r.style.display="block",r.style.position="absolute"}function ht(r,t,e,o){let n=dt(14),[i]=mt(),c;n[0]===Symbol.for("react.memo_cache_sentinel")?(c=st?document.createElement("div"):null,n[0]=c):c=n[0];let s=Ee(c),a;n[1]!==r||n[2]!==o||n[3]!==i||n[4]!==t?(a=()=>{if(s.current===null||parent===void 0)return;let d=i.getRootElement(),u=s.current,x=u.firstChild;if(d!==null&&t!==null){let{height:h,width:E}=t.getRect(),{left:_,top:T}=t.getRect(),N=T;if(T=T-(r.getBoundingClientRect().top+window.scrollY),_=_-(r.getBoundingClientRect().left+window.scrollX),u.style.left=`${_+window.scrollX}px`,u.style.height=`${h}px`,u.style.width=`${E}px`,x!==null){let S=x.getBoundingClientRect(),F=S.height,w=S.width,I=d.getBoundingClientRect();_+w>I.right&&(u.style.left=`${I.right-w+window.scrollX}px`);let y=N+F+32>window.innerHeight,A=N<0;y&&!A?u.style.top=`${T+32-F+window.scrollY-(h+24)}px`:u.style.top=`${T+window.scrollY+32}px`}u.isConnected||(Fe(u,o),r.append(u)),u.setAttribute("id","slash-menu"),s.current=u,d.setAttribute("aria-controls","slash-menu")}},n[1]=r,n[2]=o,n[3]=i,n[4]=t,n[5]=a):a=n[5];let f=a,l,m;n[6]!==i||n[7]!==f||n[8]!==t?(l=()=>{let d=i.getRootElement();if(t!==null)return f(),()=>{d!==null&&d.removeAttribute("aria-controls");let u=s.current;u!==null&&u.isConnected&&(u.remove(),u.removeAttribute("id"))}},m=[i,f,t],n[6]=i,n[7]=f,n[8]=t,n[9]=l,n[10]=m):(l=n[9],m=n[10]),M(l,m);let g;return n[11]!==t||n[12]!==e?(g=d=>{t!==null&&(d||e(null))},n[11]=t,n[12]=e,n[13]=g):g=n[13],Re(t,s,f,g),s}var no=`\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'"~=<>_:;`;function Le(r){let t=r.anchor;if(t.type!=="text")return null;let e=t.getNode();if(!e.isSimpleText())return null;let o=t.offset;return e.getTextContent().slice(0,o)}function Et(r,t,e){let o=Me(e);if(o===null||!o.isCollapsed)return!1;let n=o.anchorNode,i=r,c=o.anchorOffset;if(n==null||c==null)return!1;try{t.setStart(n,i),t.setEnd(n,c>1?c:1)}catch{return!1}return!0}function De(r){let t;return r.getEditorState().read(()=>{let e=V();Z(e)&&(t=Le(e))}),t}function _t(r,t){return t!==0?!1:r.getEditorState().read(()=>{let e=V();if(Z(e)){let i=e.anchor.getNode().getPreviousSibling();return Ae(i)&&i.isTextEntity()}return!1})}function Tt(r){q.startTransition?q.startTransition(r):r()}var Be=ke("ENABLE_SLASH_MENU_COMMAND");function oo(r){let t=Ne(30),{anchorClassName:e,anchorElem:o,groups:n,menuRenderFn:i,onClose:c,onOpen:s,onQueryChange:a,triggerFn:f}=r,[l]=ye(),[m,g]=$e(null),p=ht(o,m,g,e),d;t[0]!==c||t[1]!==m?(d=()=>{g(null),c!=null&&m!==null&&c()},t[0]=c,t[1]=m,t[2]=d):d=t[2];let u=d,x;t[3]!==s||t[4]!==m?(x=F=>{g(F),s!=null&&m===null&&s(F)},t[3]=s,t[4]=m,t[5]=x):x=t[5];let h=x,E,_;t[6]!==l||t[7]!==h?(E=()=>Oe(l.registerCommand(Be,F=>{let{node:w}=F;return l.getEditorState().read(()=>{let I={leadOffset:0,matchingString:"",replaceableString:""};if(!_t(l,I.leadOffset)&&w!==null){let y=l._window??window,A=y.document.createRange();Et(I.leadOffset,A,y)!==null&&Tt(()=>h({getRect:()=>A.getBoundingClientRect(),match:I}));return}}),!0},be)),_=[l,h],t[6]=l,t[7]=h,t[8]=E,t[9]=_):(E=t[8],_=t[9]),xt(E,_);let T;t[10]!==u||t[11]!==l||t[12]!==a||t[13]!==h||t[14]!==f?(T=()=>{let F=()=>{l.getEditorState().read(()=>{let I=l._window??window,y=I.document.createRange(),A=V(),W=De(l);if(!Z(A)||!A.isCollapsed()||W===void 0||y===null){u();return}let b=f({editor:l,query:W});if(a(b?b.matchingString:null),b!==null&&!_t(l,b.leadOffset)&&Et(b.leadOffset,y,I)!==null){Tt(()=>h({getRect:()=>y.getBoundingClientRect(),match:b}));return}u()})},w=l.registerUpdateListener(F);return()=>{w()}},t[10]=u,t[11]=l,t[12]=a,t[13]=h,t[14]=f,t[15]=T):T=t[15];let N;t[16]!==u||t[17]!==l||t[18]!==a||t[19]!==h||t[20]!==m||t[21]!==f?(N=[l,f,a,m,u,h],t[16]=u,t[17]=l,t[18]=a,t[19]=h,t[20]=m,t[21]=f,t[22]=N):N=t[22],xt(T,N);let S;return t[23]!==p||t[24]!==u||t[25]!==l||t[26]!==n||t[27]!==i||t[28]!==m?(S=p.current===null||m===null||l===null?null:Ie(pt,{anchorElementRef:p,close:u,editor:l,groups:n,menuRenderFn:i,resolution:m,shouldSplitNodeWithQuery:!0}),t[23]=p,t[24]=u,t[25]=l,t[26]=n,t[27]=i,t[28]=m,t[29]=S):S=t[29],S}var St=class r{_bottom;_left;_right;_top;constructor(t,e,o,n){let[i,c]=e<=n?[e,n]:[n,e],[s,a]=t<=o?[t,o]:[o,t];this._top=i,this._right=a,this._left=s,this._bottom=c}static fromDOM(t){let{height:e,left:o,top:n,width:i}=t.getBoundingClientRect();return r.fromLWTH(o,i,n,e)}static fromDOMRect(t){let{height:e,left:o,top:n,width:i}=t;return r.fromLWTH(o,i,n,e)}static fromLTRB(t,e,o,n){return new r(t,e,o,n)}static fromLWTH(t,e,o,n){return new r(t,o,t+e,o+n)}static fromPoints(t,e){let{x:o,y:n}=t,{x:i,y:c}=e;return r.fromLTRB(o,n,i,c)}contains(t){if(ct(t)){let{x:c,y:s}=t,a=s<this._top,f=s>this._bottom,l=c<this._left,m=c>this._right;return{reason:{isOnBottomSide:f,isOnLeftSide:l,isOnRightSide:m,isOnTopSide:a},result:!a&&!f&&!l&&!m}}let{bottom:e,left:o,right:n,top:i}=t;return i>=this._top&&i<=this._bottom&&e>=this._top&&e<=this._bottom&&o>=this._left&&o<=this._right&&n>=this._left&&n<=this._right}distanceFromPoint(t){let e=this.contains(t);if(e.result)return{distance:0,isOnBottomSide:e.reason.isOnBottomSide,isOnLeftSide:e.reason.isOnLeftSide,isOnRightSide:e.reason.isOnRightSide,isOnTopSide:e.reason.isOnTopSide};let o=0,n=0;return t.x<this._left?o=this._left-t.x:t.x>this._right&&(o=t.x-this._right),t.y<this._top?n=this._top-t.y:t.y>this._bottom&&(n=t.y-this._bottom),{distance:Math.sqrt(o*o+n*n),isOnBottomSide:t.y>this._bottom,isOnLeftSide:t.x<this._left,isOnRightSide:t.x>this._right,isOnTopSide:t.y<this._top}}equals({bottom:t,left:e,right:o,top:n}){return n===this._top&&t===this._bottom&&e===this._left&&o===this._right}generateNewRect({bottom:t=this.bottom,left:e=this.left,right:o=this.right,top:n=this.top}){return new r(e,n,o,t)}intersectsWith(t){let{height:e,left:o,top:n,width:i}=t,{height:c,left:s,top:a,width:f}=this,l=o+i>=s+f?o+i:s+f,m=n+e>=a+c?n+e:a+c,g=o<=s?o:s,p=n<=a?n:a;return l-g<=i+f&&m-p<=e+c}get bottom(){return this._bottom}get height(){return Math.abs(this._bottom-this._top)}get left(){return this._left}get right(){return this._right}get top(){return this._top}get width(){return Math.abs(this._left-this._right)}};function co({editorConfig:r}){return Pe({nodes:r.features.nodes})}function Pe({nodes:r}){return r.map(t=>"node"in t?t.node:t)}import{$getRoot as We,$isDecoratorNode as Nt,$isElementNode as U,$isLineBreakNode as Qe,$isTextNode as G}from"lexical";import{$isListItemNode as ve,$isListNode as wt}from"@lexical/list";import{$isHeadingNode as He,$isQuoteNode as Ke}from"@lexical/rich-text";import{$isParagraphNode as Ue,$isTextNode as Ge}from"lexical";var C={markdownFormatKind:null,regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:!1},R={...C,requiresParagraphStart:!0},mo={...R,export:$(1),markdownFormatKind:"paragraphH1",regEx:/^# /,regExForAutoFormatting:/^# /},go={...R,export:$(2),markdownFormatKind:"paragraphH2",regEx:/^## /,regExForAutoFormatting:/^## /},po={...R,export:$(3),markdownFormatKind:"paragraphH3",regEx:/^### /,regExForAutoFormatting:/^### /},ho={...R,export:$(4),markdownFormatKind:"paragraphH4",regEx:/^#### /,regExForAutoFormatting:/^#### /},xo={...R,export:$(5),markdownFormatKind:"paragraphH5",regEx:/^##### /,regExForAutoFormatting:/^##### /},Eo={...R,export:$(6),markdownFormatKind:"paragraphH6",regEx:/^###### /,regExForAutoFormatting:/^###### /},_o={...R,export:ze,markdownFormatKind:"paragraphBlockQuote",regEx:/^> /,regExForAutoFormatting:/^> /},To={...R,export:J,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})- /,regExForAutoFormatting:/^(\s{0,10})- /},So={...R,export:J,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})\* /,regExForAutoFormatting:/^(\s{0,10})\* /},wo={...R,export:J,markdownFormatKind:"paragraphOrderedList",regEx:/^(\s{0,10})(\d+)\.\s/,regExForAutoFormatting:/^(\s{0,10})(\d+)\.\s/},Co={...R,markdownFormatKind:"horizontalRule",regEx:/^\*\*\*$/,regExForAutoFormatting:/^\*\*\* /},Ro={...R,markdownFormatKind:"horizontalRule",regEx:/^---$/,regExForAutoFormatting:/^--- /},Fo={...C,exportFormat:"code",exportTag:"`",markdownFormatKind:"code",regEx:/(`)(\s*)([^`]*)(\s*)(`)()/,regExForAutoFormatting:/(`)(\s*\b)([^`]*)(\b\s*)(`)(\s)$/},No={...C,exportFormat:"bold",exportTag:"**",markdownFormatKind:"bold",regEx:/(\*\*)(\s*)([^*]*)(\s*)(\*\*)()/,regExForAutoFormatting:/(\*\*)(\s*\b)([^*]*)(\b\s*)(\*\*)(\s)$/},Io={...C,exportFormat:"italic",exportTag:"*",markdownFormatKind:"italic",regEx:/(\*)(\s*)([^*]*)(\s*)(\*)()/,regExForAutoFormatting:/(\*)(\s*\b)([^*]*)(\b\s*)(\*)(\s)$/},yo={...C,exportFormat:"bold",exportTag:"_",markdownFormatKind:"bold",regEx:/(__)(\s*)([^_]*)(\s*)(__)()/,regExForAutoFormatting:/(__)(\s*)([^_]*)(\s*)(__)(\s)$/},Oo={...C,exportFormat:"italic",exportTag:"_",markdownFormatKind:"italic",regEx:/(_)()([^_]*)()(_)()/,regExForAutoFormatting:/(_)()([^_]*)()(_)(\s)$/},Ao={...C,exportFormat:"underline",exportTag:"<u>",exportTagClose:"</u>",markdownFormatKind:"underline",regEx:/(<u>)(\s*)([^<]*)(\s*)(<\/u>)()/,regExForAutoFormatting:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},bo={...C,exportFormat:"strikethrough",exportTag:"~~",markdownFormatKind:"strikethrough",regEx:/(~~)(\s*)([^~]*)(\s*)(~~)()/,regExForAutoFormatting:/(~~)(\s*\b)([^~]*)(\b\s*)(~~)(\s)$/},ko={...C,markdownFormatKind:"strikethrough_italic_bold",regEx:/(~~_\*\*)(\s*\b)([^*_~]+)(\b\s*)(\*\*_~~)()/,regExForAutoFormatting:/(~~_\*\*)(\s*\b)([^*_~]+)(\b\s*)(\*\*_~~)(\s)$/},Mo={...C,markdownFormatKind:"italic_bold",regEx:/(_\*\*)(\s*\b)([^*_]+)(\b\s*)(\*\*_)/,regExForAutoFormatting:/(_\*\*)(\s*\b)([^*_]+)(\b\s*)(\*\*_)(\s)$/},$o={...C,markdownFormatKind:"strikethrough_italic",regEx:/(~~_)(\s*)([^_~]+)(\s*)(_~~)/,regExForAutoFormatting:/(~~_)(\s*)([^_~]+)(\s*)(_~~)(\s)$/},Lo={...C,markdownFormatKind:"strikethrough_bold",regEx:/(~~\*\*)(\s*\b)([^*~]+)(\b\s*)(\*\*~~)/,regExForAutoFormatting:/(~~\*\*)(\s*\b)([^*~]+)(\b\s*)(\*\*~~)(\s)$/},Do={...C,markdownFormatKind:"link",regEx:/(\[)([^\]]*)(\]\()([^)]*)(\)*)()/,regExForAutoFormatting:/(\[)([^\]]*)(\]\()([^)]*)(\)*)(\s)$/};function $(r){return(t,e)=>He(t)&&t.getTag()==="h"+r?"#".repeat(r)+" "+e(t):null}function J(r,t){return wt(r)?Ct(r,t,0):null}var Xe=4;function Ct(r,t,e){let o=[],n=r.getChildren(),i=0;for(let c of n)if(ve(c)){if(c.getChildrenSize()===1){let f=c.getFirstChild();if(wt(f)){o.push(Ct(f,t,e+1));continue}}let s=" ".repeat(e*Xe),a=r.getListType()==="bullet"?"- ":`${r.getStart()+i}. `;o.push(s+a+t(c)),i++}return o.join(`
2
- `)}function ze(r,t){return Ke(r)?"> "+t(r):null}function H(r,t){let e={};for(let o of r){let n=t(o);n&&(e[n]?e[n].push(o):e[n]=[o])}return e}function L(r){let t=H(r,e=>e.type);return{element:t.element||[],multilineElement:t["multiline-element"]||[],textFormat:t["text-format"]||[],textMatch:t["text-match"]||[]}}var D=/[!-/:-@[-`{-~\s]/,Ye=/^\s{0,3}$/;function v(r){if(!Ue(r))return!1;let t=r.getFirstChild();return t==null||r.getChildrenSize()===1&&Ge(t)&&Ye.test(t.getTextContent())}function It(r,t=!1){let e=L(r),o=[...e.multilineElement,...e.element],n=!t,i=e.textFormat.filter(c=>c.format.length===1).sort((c,s)=>c.format.includes("code")&&!s.format.includes("code")?1:!c.format.includes("code")&&s.format.includes("code")?-1:0);return c=>{let s=[],a=(c||We()).getChildren();return a.forEach((f,l)=>{let m=je(f,o,i,e.textMatch);m!=null&&s.push(n&&l>0&&!v(f)&&!v(a[l-1])?`
3
- `.concat(m):m)}),s.join(`
4
- `)}}function je(r,t,e,o){for(let n of t){if(!n.export)continue;let i=n.export(r,c=>X(c,e,o));if(i!=null)return i}return U(r)?X(r,e,o):Nt(r)?r.getTextContent():null}function X(r,t,e,o,n){let i=[],c=r.getChildren();o||(o=[]),n||(n=[]);t:for(let s of c){for(let a of e){if(!a.export)continue;let f=a.export(s,l=>X(l,t,e,o,[...n,...o]),(l,m)=>Rt(l,m,t,o,n));if(f!=null){i.push(f);continue t}}Qe(s)?i.push(`
5
- `):G(s)?i.push(Rt(s,s.getTextContent(),t,o,n)):U(s)?i.push(X(s,t,e,o,n)):Nt(s)&&i.push(s.getTextContent())}return i.join("")}function Rt(r,t,e,o,n){let i=t.trim(),c=i;r.hasFormat("code")||(c=c.replace(/([*_`~\\])/g,"\\$1"));let s="",a="",f="",l=Ft(r,!0),m=Ft(r,!1),g=new Set;for(let p of e){let d=p.format[0],u=p.tag;K(r,d)&&!g.has(d)&&(g.add(d),(!K(l,d)||!o.find(x=>x.tag===u))&&(o.push({format:d,tag:u}),s+=u))}for(let p=0;p<o.length;p++){let d=o[p],u=K(r,d.format),x=K(m,d.format);if(u&&x)continue;let h=[...o];for(;h.length>p;){let E=h.pop();n&&E&&n.find(_=>_.tag===E.tag)||(E&&typeof E.tag=="string"&&(u?x||(f+=E.tag):a+=E.tag),o.pop())}break}return c=s+c+f,a+t.replace(i,()=>c)}function Ft(r,t){let e=t?r.getPreviousSibling():r.getNextSibling();if(!e){let o=r.getParentOrThrow();o.isInline()&&(e=t?o.getPreviousSibling():o.getNextSibling())}for(;e;){if(U(e)){if(!e.isInline())break;let o=t?e.getLastDescendant():e.getFirstDescendant();if(G(o))return o;e=t?e.getPreviousSibling():e.getNextSibling()}if(G(e))return e;if(!U(e))return null}return null}function K(r,t){return G(r)&&r.hasFormat(t)}import{$isListItemNode as Ve,$isListNode as kt}from"@lexical/list";import{$isQuoteNode as Ze}from"@lexical/rich-text";import{$findMatchingParent as Je}from"@lexical/utils";import{$createLineBreakNode as tn,$createParagraphNode as en,$createTextNode as nn,$getRoot as on,$getSelection as rn,$isParagraphNode as sn,$isTextNode as cn}from"lexical";import{$isTextNode as B}from"lexical";function yt(r,t){let e=r.getTextContent(),o=qe(e,t);if(!o)return null;let n=o.index||0,i=n+o[0].length,c=t.transformersByTag[o[1]];return{endIndex:i,match:o,startIndex:n,transformer:c}}function qe(r,t){let e=r.match(t.openTagsRegExp);if(e==null)return null;for(let o of e){let n=o.replace(/^\s/,""),i=t.fullMatchRegExpByTag[n];if(i==null)continue;let c=r.match(i),s=t.transformersByTag[n];if(c!=null&&s!=null){if(s.intraword!==!1)return c;let{index:a=0}=c,f=r[a-1],l=r[a+c[0].length];if((!f||D.test(f))&&(!l||D.test(l)))return c}}return null}function Ot(r,t,e,o,n){let i=r.getTextContent(),c,s,a;if(n[0]===i?a=r:t===0?[a,c]=r.splitText(e):[s,a,c]=r.splitText(t,e),a.setTextContent(n[2]),o)for(let f of o.format)a.hasFormat(f)||a.toggleFormat(f);return{nodeAfter:c,nodeBefore:s,transformedNode:a}}function At(r,t){let e=r,o,n,i,c;for(let s of t){if(!s.replace||!s.importRegExp)continue;let a=e.getTextContent().match(s.importRegExp);if(!a)continue;let f=a.index||0,l=s.getEndIndex?s.getEndIndex(e,a):f+a[0].length;l!==!1&&(o===void 0||n===void 0||f<o&&l>n)&&(o=f,n=l,i=s,c=a)}return o===void 0||n===void 0||i===void 0||c===void 0?null:{endIndex:n,match:c,startIndex:o,transformer:i}}function bt(r,t,e,o,n){let i,c,s;if(t===0?[s,i]=r.splitText(e):[c,s,i]=r.splitText(t,e),!o.replace)return null;let a=s?o.replace(s,n):void 0;return{nodeAfter:i,nodeBefore:c,transformedNode:a||void 0}}function O(r,t,e){let o=yt(r,t),n=At(r,e);if(o&&n&&(o.startIndex<=n.startIndex&&o.endIndex>=n.endIndex?n=null:o=null),o){let i=Ot(r,o.startIndex,o.endIndex,o.transformer,o.match);i.nodeAfter&&B(i.nodeAfter)&&!i.nodeAfter.hasFormat("code")&&O(i.nodeAfter,t,e),i.nodeBefore&&B(i.nodeBefore)&&!i.nodeBefore.hasFormat("code")&&O(i.nodeBefore,t,e),i.transformedNode&&B(i.transformedNode)&&!i.transformedNode.hasFormat("code")&&O(i.transformedNode,t,e);return}else if(n){let i=bt(r,n.startIndex,n.endIndex,n.transformer,n.match);if(!i)return;i.nodeAfter&&B(i.nodeAfter)&&!i.nodeAfter.hasFormat("code")&&O(i.nodeAfter,t,e),i.nodeBefore&&B(i.nodeBefore)&&!i.nodeBefore.hasFormat("code")&&O(i.nodeBefore,t,e),i.transformedNode&&B(i.transformedNode)&&!i.transformedNode.hasFormat("code")&&O(i.transformedNode,t,e);return}else return}function Mt(r,t=!1){let e=L(r),o=fn(e.textFormat);return(n,i)=>{let c=n.split(`
6
- `),s=c.length,a=i||on();a.clear();for(let l=0;l<s;l++){let m=c[l],[g,p]=an(c,l,e.multilineElement,a);if(g){l=p;continue}ln(m,a,e.element,o,e.textMatch)}let f=a.getChildren();for(let l of f)!t&&v(l)&&a.getChildrenSize()>1&&l.remove();rn()!==null&&a.selectStart()}}function an(r,t,e,o){for(let n of e){let{handleImportAfterStartMatch:i,regExpEnd:c,regExpStart:s,replace:a}=n,f=r[t]?.match(s);if(!f)continue;if(i){let d=i({lines:r,rootNode:o,startLineIndex:t,startMatch:f,transformer:n});if(d===null)continue;if(d)return d}let l=typeof c=="object"&&"regExp"in c?c.regExp:c,m=c&&typeof c=="object"&&"optional"in c?c.optional:!c,g=t,p=r.length;for(;g<p;){let d=l?r[g]?.match(l):null;if(!d&&(!m||m&&g<p-1)){g++;continue}if(d&&t===g&&d.index===f.index){g++;continue}let u=[];if(d&&t===g)u.push(r[t].slice(f[0].length,-d[0].length));else for(let x=t;x<=g;x++){let h=r[x];if(x===t){let E=h.slice(f[0].length);u.push(E)}else if(x===g&&d){let E=h.slice(0,-d[0].length);u.push(E)}else u.push(h)}if(a(o,null,f,d,u,!0)!==!1)return[!0,g];break}}return[!1,t]}function ln(r,t,e,o,n){let i=nn(r),c=en();c.append(i),t.append(c);for(let{regExp:s,replace:a}of e){let f=r.match(s);if(f&&(i.setTextContent(r.slice(f[0].length)),a(c,[i],f,!0)!==!1))break}O(i,o,n);for(let s of c.getChildren())if(cn(s)){let f=s.getTextContent().replace(/\\([*_`~])/g,"$1");s.setTextContent(f)}if(c.isAttached()&&r.length>0){let s=c.getPreviousSibling();if(sn(s)||Ze(s)||kt(s)){let a=s;if(kt(s)){let f=s.getLastDescendant();f==null?a=null:a=Je(f,Ve)}a!=null&&a.getTextContentSize()>0&&(a.splice(a.getChildrenSize(),0,[tn(),...c.getChildren()]),c.remove())}}}function fn(r){let t={},e={},o=[],n="(?<![\\\\])";for(let i of r){let{tag:c}=i;t[c]=i;let s=c.replace(/([*^+])/g,"\\$1");o.push(s),c.length===1?e[c]=new RegExp(`(?<![\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)((?<!\\\\)|(?<=\\\\\\\\))(${s})(?![\\\\${s}])`):e[c]=new RegExp(`(?<!\\\\)(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)((?<!\\\\)|(?<=\\\\\\\\))(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:e,openTagsRegExp:new RegExp(`${n}(${o.join("|")})`,"g"),transformersByTag:t}}import{$createRangeSelection as un,$getSelection as tt,$isLineBreakNode as dn,$isRangeSelection as et,$isRootOrShadowRoot as Lt,$isTextNode as Dt,$setSelection as mn}from"lexical";function gn(r,t,e,o){let n=r.getParent();if(!Lt(n)||r.getFirstChild()!==t)return!1;let i=t.getTextContent();if(i[e-1]!==" ")return!1;for(let{regExp:c,replace:s}of o){let a=i.match(c);if(a&&a[0].length===(a[0].endsWith(" ")?e:e-1)){let f=t.getNextSiblings(),[l,m]=t.splitText(e);l?.remove();let g=m?[m,...f]:f;if(s(r,g,a,!1)!==!1)return!0}}return!1}function pn(r,t,e,o){let n=r.getParent();if(!Lt(n)||r.getFirstChild()!==t)return!1;let i=t.getTextContent();if(i[e-1]!==" ")return!1;for(let{regExpEnd:c,regExpStart:s,replace:a}of o){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;let f=i.match(s);if(f&&f[0].length===(f[0].endsWith(" ")?e:e-1)){let l=t.getNextSiblings(),[m,g]=t.splitText(e);m?.remove();let p=g?[g,...l]:l;if(a(r,p,f,null,null,!1)!==!1)return!0}}return!1}function hn(r,t,e){let o=r.getTextContent(),n=o[t-1],i=e[n];if(i==null)return!1;t<o.length&&(o=o.slice(0,t));for(let c of i){if(!c.replace||!c.regExp)continue;let s=o.match(c.regExp);if(s===null)continue;let a=s.index||0,f=a+s[0].length,l;return a===0?[l]=r.splitText(f):[,l]=r.splitText(a,f),l&&(l.selectNext(0,0),c.replace(l,s)),!0}return!1}function xn(r,t,e){let o=r.getTextContent(),n=t-1,i=o[n],c=e[i];if(!c)return!1;for(let s of c){let{tag:a}=s,f=a.length,l=n-f+1;if(f>1&&!Bt(o,l,a,0,f)||o[l-1]===" ")continue;let m=o[n+1];if(s.intraword===!1&&m&&!D.test(m))continue;let g=r,p=g,d=$t(o,l,a),u=p;for(;d<0&&(u=u.getPreviousSibling())&&!dn(u);)if(Dt(u)){let w=u.getTextContent();p=u,d=$t(w,w.length,a)}if(d<0||p===g&&d+f===l)continue;let x=p.getTextContent();if(d>0&&x[d-1]===i)continue;let h=x[d-1];if(s.intraword===!1&&h&&!D.test(h))continue;let E=g.getTextContent(),_=E.slice(0,l)+E.slice(n+1);g.setTextContent(_);let T=p===g?_:x;p.setTextContent(T.slice(0,d)+T.slice(d+f));let N=tt(),S=un();mn(S);let F=n-f*(p===g?2:1)+1;S.anchor.set(p.__key,d,"text"),S.focus.set(g.__key,F,"text");for(let w of s.format)S.hasFormat(w)||S.formatText(w);S.anchor.set(S.focus.key,S.focus.offset,S.focus.type);for(let w of s.format)S.hasFormat(w)&&S.toggleFormat(w);return et(N)&&(S.format=N.format),!0}return!1}function $t(r,t,e){let o=e.length;for(let n=t;n>=o;n--){let i=n-o;if(Bt(r,i,e,0,o)&&r[i+o]!==" ")return i}return-1}function Bt(r,t,e,o,n){for(let i=0;i<n;i++)if(r[t+i]!==e[o+i])return!1;return!0}function rr(r,t=z){let e=L(t),o=H(e.textFormat,({tag:c})=>c[c.length-1]),n=H(e.textMatch,({trigger:c})=>c);for(let c of t){let s=c.type;if(s==="element"||s==="text-match"||s==="multiline-element"){let a=c.dependencies;for(let f of a)if(!r.hasNode(f))throw new Error("MarkdownShortcuts: missing dependency %s for transformer. Ensure node dependency is included in editor initial config."+f.getType())}}let i=(c,s,a)=>{gn(c,s,a,e.element)||pn(c,s,a,e.multilineElement)||hn(s,a,n)||xn(s,a,o)};return r.registerUpdateListener(({dirtyLeaves:c,editorState:s,prevEditorState:a,tags:f})=>{if(f.has("collaboration")||f.has("historic")||r.isComposing())return;let l=s.read(tt),m=a.read(tt);if(!et(m)||!et(l)||!l.isCollapsed()||l.is(m))return;let g=l.anchor.key,p=l.anchor.offset,d=s._nodeMap.get(g);!Dt(d)||!c.has(g)||p!==1&&p>m.anchor.offset+1||r.update(()=>{if(d.hasFormat("code"))return;let u=d.getParent();u!==null&&i(u,d,l.anchor.offset)})})}import{$createListItemNode as En,$createListNode as _n,$isListItemNode as Tn,$isListNode as P,ListItemNode as ot,ListNode as rt}from"@lexical/list";import{$createHeadingNode as Sn,$createQuoteNode as wn,$isHeadingNode as Cn,$isQuoteNode as Pt,HeadingNode as Rn,QuoteNode as Fn}from"@lexical/rich-text";import{$createLineBreakNode as Nn}from"lexical";var vt=/^[\t ]*$/,Gt=/^(\s*)(\d+)\.\s/,Xt=/^(\s*)[-*+]\s/,zt=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,nt=/^(#{1,6})\s/,Yt=/^>\s/,In=/^[ \t]*(\\`\\`\\`|```)(\w+)?/,Ht=/[ \t]*(\\`\\`\\`|```)$/,yn=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,On=/^\|(.+)\|\s?$/,An=/^(\| ?:?-*:? ?)+\|\s?$/,Kt=/^[ \t]*<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,Ut=/^[ \t]*<\/[a-z_][\w-]*\s*>/i,bn=r=>(t,e,o)=>{let n=r(o);n.append(...e),t.replace(n),n.select(0,0)},Wt=4;function kn(r){let t=r.match(/\t/g),e=r.match(/ /g),o=0;return t&&(o+=t.length),e&&(o+=Math.floor(e.length/Wt)),o}var it=r=>(t,e,o)=>{let n=t.getPreviousSibling(),i=t.getNextSibling(),c=En(r==="check"?o[3]==="x":void 0);if(P(i)&&i.getListType()===r){let a=i.getFirstChild();a!==null?a.insertBefore(c):i.append(c),t.remove()}else if(P(n)&&n.getListType()===r)n.append(c),t.remove();else{let a=_n(r,r==="number"?Number(o[2]):void 0);a.append(c),t.replace(a)}c.append(...e),c.select(0,0);let s=kn(o[1]);s&&c.setIndent(s)},Y=(r,t,e)=>{let o=[],n=r.getChildren(),i=0;for(let c of n)if(Tn(c)){if(c.getChildrenSize()===1){let l=c.getFirstChild();if(P(l)){o.push(Y(l,t,e+1));continue}}let s=" ".repeat(e*Wt),a=r.getListType(),f=a==="number"?`${r.getStart()+i}. `:a==="check"?`- [${c.getChecked()?"x":" "}] `:"- ";o.push(s+f+t(c)),i++}return o.join(`
7
- `)},Qt={type:"element",dependencies:[Rn],export:(r,t)=>{if(!Cn(r))return null;let e=Number(r.getTag().slice(1));return"#".repeat(e)+" "+t(r)},regExp:nt,replace:bn(r=>{let t="h"+r[1].length;return Sn(t)})},jt={type:"element",dependencies:[Fn],export:(r,t)=>{if(!Pt(r))return null;let e=t(r).split(`
8
- `),o=[];for(let n of e)o.push("> "+n);return o.join(`
9
- `)},regExp:Yt,replace:(r,t,e,o)=>{if(o){let i=r.getPreviousSibling();if(Pt(i)){i.splice(i.getChildrenSize(),0,[Nn(),...t]),i.select(0,0),r.remove();return}}let n=wn();n.append(...t),r.replace(n),n.select(0,0)}},qt={type:"element",dependencies:[rt,ot],export:(r,t)=>P(r)?Y(r,t,0):null,regExp:Xt,replace:it("bullet")},Mn={type:"element",dependencies:[rt,ot],export:(r,t)=>P(r)?Y(r,t,0):null,regExp:zt,replace:it("check")},Vt={type:"element",dependencies:[rt,ot],export:(r,t)=>P(r)?Y(r,t,0):null,regExp:Gt,replace:it("number")},Zt={type:"text-format",format:["code"],tag:"`"},Jt={type:"text-format",format:["highlight"],tag:"=="},te={type:"text-format",format:["bold","italic"],tag:"***"},ee={type:"text-format",format:["bold","italic"],intraword:!1,tag:"___"},ne={type:"text-format",format:["bold"],tag:"**"},oe={type:"text-format",format:["bold"],intraword:!1,tag:"__"},re={type:"text-format",format:["strikethrough"],tag:"~~"},ie={type:"text-format",format:["italic"],tag:"*"},se={type:"text-format",format:["italic"],intraword:!1,tag:"_"};function ce(r,t){let e=r.split(`
10
- `),o=!1,n=[],i=0;for(let c=0;c<e.length;c++){let s=e[c],a=n[n.length-1];if(yn.test(s)){n.push(s);continue}if(Ht.test(s)){i===0&&(o=!0),i===1&&(o=!1),i>0&&i--,n.push(s);continue}if(In.test(s)){o=!0,i++,n.push(s);continue}if(o){n.push(s);continue}vt.test(s)||vt.test(a)||!a||nt.test(a)||nt.test(s)||Yt.test(s)||Gt.test(s)||Xt.test(s)||zt.test(s)||On.test(s)||An.test(s)||!t||Kt.test(s)||Ut.test(s)||Kt.test(a)||Ut.test(a)||Ht.test(a)?n.push(s):n[n.length-1]=a+" "+s.trim()}return n.join(`
11
- `)}var $n=[Qt,jt,qt,Vt],Ln=[],Dn=[Zt,te,ee,ne,oe,Jt,ie,se,re],Bn=[],z=[...$n,...Ln,...Dn,...Bn];function mr(r,t=z,e,o=!1,n=!0){let i=o?r:ce(r,n);return Mt(t,o)(i,e)}function gr(r=z,t,e=!1){return It(r,e)(t)}export{st as a,rr as b,mr as c,gr as d,Q as e,ct as f,no as g,Be as h,oo as i,St as j,co as k};
12
- //# sourceMappingURL=chunk-FV3BVQ6U.js.map