@payloadcms/richtext-lexical 3.85.1 → 3.85.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownTransformers.js","names":["$createListItemNode","$createListNode","$isListItemNode","$isListNode","ListItemNode","ListNode","$createHeadingNode","$createQuoteNode","$isHeadingNode","$isQuoteNode","HeadingNode","QuoteNode","$createLineBreakNode","EMPTY_OR_WHITESPACE_ONLY","ORDERED_LIST_REGEX","UNORDERED_LIST_REGEX","CHECK_LIST_REGEX","HEADING_REGEX","QUOTE_REGEX","CODE_START_REGEX","CODE_END_REGEX","CODE_SINGLE_LINE_REGEX","TABLE_ROW_REG_EXP","TABLE_ROW_DIVIDER_REG_EXP","TAG_START_REGEX","TAG_END_REGEX","createBlockNode","createNode","parentNode","children","match","node","append","replace","select","LIST_INDENT_SIZE","getIndent","whitespaces","tabs","spaces","indent","length","Math","floor","listReplace","listType","previousNode","getPreviousSibling","nextNode","getNextSibling","listItem","undefined","getListType","firstChild","getFirstChild","insertBefore","remove","list","Number","setIndent","listExport","listNode","exportChildren","depth","output","getChildren","index","listItemNode","getChildrenSize","push","repeat","prefix","getStart","getChecked","join","HEADING","type","dependencies","export","level","getTag","slice","regExp","tag","QUOTE","lines","split","line","_match","isImport","splice","UNORDERED_LIST","CHECK_LIST","ORDERED_LIST","INLINE_CODE","format","HIGHLIGHT","BOLD_ITALIC_STAR","BOLD_ITALIC_UNDERSCORE","intraword","BOLD_STAR","BOLD_UNDERSCORE","STRIKETHROUGH","ITALIC_STAR","ITALIC_UNDERSCORE","normalizeMarkdown","input","shouldMergeAdjacentLines","inCodeBlock","sanitizedLines","nestedDeepCodeBlock","i","lastLine","test","trim"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownTransformers.ts"],"sourcesContent":["/* eslint-disable regexp/no-unused-capturing-group */\n/**\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 { ListType } from '@lexical/list'\nimport type { HeadingTagType } from '@lexical/rich-text'\nimport type { ElementNode, Klass, LexicalNode, TextFormatType, TextNode } from 'lexical'\n\nimport {\n $createListItemNode,\n $createListNode,\n $isListItemNode,\n $isListNode,\n ListItemNode,\n ListNode,\n} from '@lexical/list'\nimport {\n $createHeadingNode,\n $createQuoteNode,\n $isHeadingNode,\n $isQuoteNode,\n HeadingNode,\n QuoteNode,\n} from '@lexical/rich-text'\nimport { $createLineBreakNode } from 'lexical'\n\nexport type Transformer =\n | ElementTransformer\n | MultilineElementTransformer\n | TextFormatTransformer\n | TextMatchTransformer\n\nexport type ElementTransformer = {\n dependencies: Array<Klass<LexicalNode>>\n /**\n * `export` is called when the `$convertToMarkdownString` is called to convert the editor state into markdown.\n *\n * @return return null to cancel the export, even though the regex matched. Lexical will then search for the next transformer.\n */\n export: (\n node: LexicalNode,\n\n traverseChildren: (node: ElementNode) => string,\n ) => null | string\n regExp: RegExp\n /**\n * `replace` is called when markdown is imported or typed in the editor\n *\n * @return return false to cancel the transform, even though the regex matched. Lexical will then search for the next transformer.\n */\n replace: (\n parentNode: ElementNode,\n children: Array<LexicalNode>,\n match: Array<string>,\n /**\n * Whether the match is from an import operation (e.g. through `$convertFromMarkdownString`) or not (e.g. through typing in the editor).\n */\n isImport: boolean,\n ) => boolean | void\n type: 'element'\n}\n\nexport type MultilineElementTransformer = {\n dependencies: Array<Klass<LexicalNode>>\n /**\n * `export` is called when the `$convertToMarkdownString` is called to convert the editor state into markdown.\n *\n * @return return null to cancel the export, even though the regex matched. Lexical will then search for the next transformer.\n */\n export?: (\n node: LexicalNode,\n\n traverseChildren: (node: ElementNode) => string,\n ) => null | string\n /**\n * Use this function to manually handle the import process, once the `regExpStart` has matched successfully.\n * Without providing this function, the default behavior is to match until `regExpEnd` is found, or until the end of the document if `regExpEnd.optional` is true.\n *\n * @returns a tuple or null. The 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. If null is returned, the next multilineElementTransformer will be tried. If undefined is returned, the default behavior will be used.\n */\n handleImportAfterStartMatch?: (args: {\n lines: Array<string>\n rootNode: ElementNode\n startLineIndex: number\n startMatch: RegExpMatchArray\n transformer: MultilineElementTransformer\n }) => [boolean, number] | null | undefined\n /**\n * This regex determines when to stop matching. Anything in between regExpStart and regExpEnd will be matched\n */\n regExpEnd?:\n | {\n /**\n * Whether the end match is optional. If true, the end match is not required to match for the transformer to be triggered.\n * The entire text from regexpStart to the end of the document will then be matched.\n */\n optional?: true\n regExp: RegExp\n }\n | RegExp\n /**\n * This regex determines when to start matching\n */\n regExpStart: RegExp\n /**\n * `replace` is called only when markdown is imported in the editor, not when it's typed\n *\n * @return return false to cancel the transform, even though the regex matched. Lexical will then search for the next transformer.\n */\n replace: (\n rootNode: ElementNode,\n /**\n * During markdown shortcut transforms, children nodes may be provided to the transformer. If this is the case, no `linesInBetween` will be provided and\n * the children nodes should be used instead of the `linesInBetween` to create the new node.\n */\n children: Array<LexicalNode> | null,\n startMatch: Array<string>,\n endMatch: Array<string> | null,\n /**\n * linesInBetween includes the text between the start & end matches, split up by lines, not including the matches themselves.\n * This is null when the transformer is triggered through markdown shortcuts (by typing in the editor)\n */\n linesInBetween: Array<string> | null,\n /**\n * Whether the match is from an import operation (e.g. through `$convertFromMarkdownString`) or not (e.g. through typing in the editor).\n */\n isImport: boolean,\n ) => boolean | void\n type: 'multiline-element'\n}\n\nexport type TextFormatTransformer = Readonly<{\n format: ReadonlyArray<TextFormatType>\n intraword?: boolean\n tag: string\n type: 'text-format'\n}>\n\nexport type TextMatchTransformer = Readonly<{\n dependencies: Array<Klass<LexicalNode>>\n /**\n * Determines how a node should be exported to markdown\n */\n export?: (\n node: LexicalNode,\n\n exportChildren: (node: ElementNode) => string,\n\n exportFormat: (node: TextNode, textContent: string) => string,\n ) => null | string\n /**\n * For import operations, this function can be used to determine the end index of the match, after `importRegExp` has matched.\n * Without this function, the end index will be determined by the length of the match from `importRegExp`. Manually determining the end index can be useful if\n * the match from `importRegExp` is not the entire text content of the node. That way, `importRegExp` can be used to match only the start of the node, and `getEndIndex`\n * can be used to match the end of the node.\n *\n * @returns The end index of the match, or false if the match was unsuccessful and a different transformer should be tried.\n */\n getEndIndex?: (node: TextNode, match: RegExpMatchArray) => false | number\n /**\n * This regex determines what text is matched during markdown imports\n */\n importRegExp?: RegExp\n /**\n * This regex determines what text is matched for markdown shortcuts while typing in the editor\n */\n regExp: RegExp\n /**\n * Determines how the matched markdown text should be transformed into a node during the markdown import process\n *\n * @returns nothing, or a TextNode that may be a child of the new node that is created.\n * If a TextNode is returned, text format matching will be applied to it (e.g. bold, italic, etc.)\n */\n replace?: (node: TextNode, match: RegExpMatchArray) => TextNode | void\n /**\n * Single character that allows the transformer to trigger when typed in the editor. This does not affect markdown imports outside of the markdown shortcut plugin.\n * If the trigger is matched, the `regExp` will be used to match the text in the second step.\n */\n trigger?: string\n type: 'text-match'\n}>\n\nconst EMPTY_OR_WHITESPACE_ONLY = /^[\\t ]*$/\nconst ORDERED_LIST_REGEX = /^(\\s*)(\\d+)\\.\\s/\nconst UNORDERED_LIST_REGEX = /^(\\s*)[-*+]\\s/\nconst CHECK_LIST_REGEX = /^(\\s*)(?:-\\s)?\\s?(\\[(\\s|x)?\\])\\s/i\nconst HEADING_REGEX = /^(#{1,6})\\s/\nconst QUOTE_REGEX = /^>\\s/\nconst CODE_START_REGEX = /^[ \\t]*(\\\\`\\\\`\\\\`|```)(\\w+)?/\nconst CODE_END_REGEX = /[ \\t]*(\\\\`\\\\`\\\\`|```)$/\nconst CODE_SINGLE_LINE_REGEX = /^[ \\t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/\nconst TABLE_ROW_REG_EXP = /^\\|(.+)\\|\\s?$/\nconst TABLE_ROW_DIVIDER_REG_EXP = /^(\\| ?:?-*:? ?)+\\|\\s?$/\nconst TAG_START_REGEX = /^[ \\t]*<[a-z_][\\w-]*(?:\\s[^<>]*)?\\/?>/i\nconst TAG_END_REGEX = /^[ \\t]*<\\/[a-z_][\\w-]*\\s*>/i\n\nconst createBlockNode = (\n createNode: (match: Array<string>) => ElementNode,\n): ElementTransformer['replace'] => {\n return (parentNode, children, match) => {\n const node = createNode(match)\n node.append(...children)\n parentNode.replace(node)\n node.select(0, 0)\n }\n}\n\n// Amount of spaces that define indentation level\n// TODO: should be an option\nconst LIST_INDENT_SIZE = 4\n\nfunction getIndent(whitespaces: string): number {\n const tabs = whitespaces.match(/\\t/g)\n const spaces = whitespaces.match(/ /g)\n\n let indent = 0\n\n if (tabs) {\n indent += tabs.length\n }\n\n if (spaces) {\n indent += Math.floor(spaces.length / LIST_INDENT_SIZE)\n }\n\n return indent\n}\n\nconst listReplace = (listType: ListType): ElementTransformer['replace'] => {\n return (parentNode, children, match) => {\n const previousNode = parentNode.getPreviousSibling()\n const nextNode = parentNode.getNextSibling()\n const listItem = $createListItemNode(listType === 'check' ? match[3] === 'x' : undefined)\n if ($isListNode(nextNode) && nextNode.getListType() === listType) {\n const firstChild = nextNode.getFirstChild()\n if (firstChild !== null) {\n firstChild.insertBefore(listItem)\n } else {\n // should never happen, but let's handle gracefully, just in case.\n nextNode.append(listItem)\n }\n parentNode.remove()\n } else if ($isListNode(previousNode) && previousNode.getListType() === listType) {\n previousNode.append(listItem)\n parentNode.remove()\n } else {\n const list = $createListNode(listType, listType === 'number' ? Number(match[2]) : undefined)\n list.append(listItem)\n parentNode.replace(list)\n }\n listItem.append(...children)\n listItem.select(0, 0)\n const indent = getIndent(match[1]!)\n if (indent) {\n listItem.setIndent(indent)\n }\n }\n}\n\nconst listExport = (\n listNode: ListNode,\n exportChildren: (node: ElementNode) => string,\n depth: number,\n): string => {\n const output: string[] = []\n const children = listNode.getChildren()\n let index = 0\n for (const listItemNode of children) {\n if ($isListItemNode(listItemNode)) {\n if (listItemNode.getChildrenSize() === 1) {\n const firstChild = listItemNode.getFirstChild()\n if ($isListNode(firstChild)) {\n output.push(listExport(firstChild, exportChildren, depth + 1))\n continue\n }\n }\n const indent = ' '.repeat(depth * LIST_INDENT_SIZE)\n const listType = listNode.getListType()\n const prefix =\n listType === 'number'\n ? `${listNode.getStart() + index}. `\n : listType === 'check'\n ? `- [${listItemNode.getChecked() ? 'x' : ' '}] `\n : '- '\n output.push(indent + prefix + exportChildren(listItemNode))\n index++\n }\n }\n\n return output.join('\\n')\n}\n\nexport const HEADING: ElementTransformer = {\n type: 'element',\n dependencies: [HeadingNode],\n export: (node, exportChildren) => {\n if (!$isHeadingNode(node)) {\n return null\n }\n const level = Number(node.getTag().slice(1))\n return '#'.repeat(level) + ' ' + exportChildren(node)\n },\n regExp: HEADING_REGEX,\n replace: createBlockNode((match) => {\n const tag = ('h' + match[1]!.length) as HeadingTagType\n return $createHeadingNode(tag)\n }),\n}\n\nexport const QUOTE: ElementTransformer = {\n type: 'element',\n dependencies: [QuoteNode],\n export: (node, exportChildren) => {\n if (!$isQuoteNode(node)) {\n return null\n }\n\n const lines = exportChildren(node).split('\\n')\n const output: string[] = []\n for (const line of lines) {\n output.push('> ' + line)\n }\n return output.join('\\n')\n },\n regExp: QUOTE_REGEX,\n replace: (parentNode, children, _match, isImport) => {\n if (isImport) {\n const previousNode = parentNode.getPreviousSibling()\n if ($isQuoteNode(previousNode)) {\n previousNode.splice(previousNode.getChildrenSize(), 0, [\n $createLineBreakNode(),\n ...children,\n ])\n previousNode.select(0, 0)\n parentNode.remove()\n return\n }\n }\n\n const node = $createQuoteNode()\n node.append(...children)\n parentNode.replace(node)\n node.select(0, 0)\n },\n}\n\nexport const UNORDERED_LIST: ElementTransformer = {\n type: 'element',\n dependencies: [ListNode, ListItemNode],\n export: (node, exportChildren) => {\n return $isListNode(node) ? listExport(node, exportChildren, 0) : null\n },\n regExp: UNORDERED_LIST_REGEX,\n replace: listReplace('bullet'),\n}\n\nexport const CHECK_LIST: ElementTransformer = {\n type: 'element',\n dependencies: [ListNode, ListItemNode],\n export: (node, exportChildren) => {\n return $isListNode(node) ? listExport(node, exportChildren, 0) : null\n },\n regExp: CHECK_LIST_REGEX,\n replace: listReplace('check'),\n}\n\nexport const ORDERED_LIST: ElementTransformer = {\n type: 'element',\n dependencies: [ListNode, ListItemNode],\n export: (node, exportChildren) => {\n return $isListNode(node) ? listExport(node, exportChildren, 0) : null\n },\n regExp: ORDERED_LIST_REGEX,\n replace: listReplace('number'),\n}\n\nexport const INLINE_CODE: TextFormatTransformer = {\n type: 'text-format',\n format: ['code'],\n tag: '`',\n}\n\nexport const HIGHLIGHT: TextFormatTransformer = {\n type: 'text-format',\n format: ['highlight'],\n tag: '==',\n}\n\nexport const BOLD_ITALIC_STAR: TextFormatTransformer = {\n type: 'text-format',\n format: ['bold', 'italic'],\n tag: '***',\n}\n\nexport const BOLD_ITALIC_UNDERSCORE: TextFormatTransformer = {\n type: 'text-format',\n format: ['bold', 'italic'],\n intraword: false,\n tag: '___',\n}\n\nexport const BOLD_STAR: TextFormatTransformer = {\n type: 'text-format',\n format: ['bold'],\n tag: '**',\n}\n\nexport const BOLD_UNDERSCORE: TextFormatTransformer = {\n type: 'text-format',\n format: ['bold'],\n intraword: false,\n tag: '__',\n}\n\nexport const STRIKETHROUGH: TextFormatTransformer = {\n type: 'text-format',\n format: ['strikethrough'],\n tag: '~~',\n}\n\nexport const ITALIC_STAR: TextFormatTransformer = {\n type: 'text-format',\n format: ['italic'],\n tag: '*',\n}\n\nexport const ITALIC_UNDERSCORE: TextFormatTransformer = {\n type: 'text-format',\n format: ['italic'],\n intraword: false,\n tag: '_',\n}\n\nexport function normalizeMarkdown(input: string, shouldMergeAdjacentLines: boolean): string {\n const lines = input.split('\\n')\n let inCodeBlock = false\n const sanitizedLines: string[] = []\n let nestedDeepCodeBlock = 0\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!\n const lastLine = sanitizedLines[sanitizedLines.length - 1]\n\n // Code blocks of ```single line``` don't toggle the inCodeBlock flag\n if (CODE_SINGLE_LINE_REGEX.test(line)) {\n sanitizedLines.push(line)\n continue\n }\n\n if (CODE_END_REGEX.test(line)) {\n if (nestedDeepCodeBlock === 0) {\n inCodeBlock = true\n }\n if (nestedDeepCodeBlock === 1) {\n inCodeBlock = false\n }\n if (nestedDeepCodeBlock > 0) {\n nestedDeepCodeBlock--\n }\n sanitizedLines.push(line)\n continue\n }\n\n // Toggle inCodeBlock state when encountering start or end of a code block\n if (CODE_START_REGEX.test(line)) {\n inCodeBlock = true\n nestedDeepCodeBlock++\n sanitizedLines.push(line)\n continue\n }\n\n // If we are inside a code block, keep the line unchanged\n if (inCodeBlock) {\n sanitizedLines.push(line)\n continue\n }\n\n // In markdown the concept of \"empty paragraphs\" does not exist.\n // Blocks must be separated by an empty line. Non-empty adjacent lines must be merged.\n if (\n EMPTY_OR_WHITESPACE_ONLY.test(line) ||\n EMPTY_OR_WHITESPACE_ONLY.test(lastLine!) ||\n !lastLine ||\n HEADING_REGEX.test(lastLine) ||\n HEADING_REGEX.test(line) ||\n QUOTE_REGEX.test(line) ||\n ORDERED_LIST_REGEX.test(line) ||\n UNORDERED_LIST_REGEX.test(line) ||\n CHECK_LIST_REGEX.test(line) ||\n TABLE_ROW_REG_EXP.test(line) ||\n TABLE_ROW_DIVIDER_REG_EXP.test(line) ||\n !shouldMergeAdjacentLines ||\n TAG_START_REGEX.test(line) ||\n TAG_END_REGEX.test(line) ||\n TAG_START_REGEX.test(lastLine) ||\n TAG_END_REGEX.test(lastLine) ||\n CODE_END_REGEX.test(lastLine)\n ) {\n sanitizedLines.push(line)\n } else {\n sanitizedLines[sanitizedLines.length - 1] = lastLine + ' ' + line.trim()\n }\n }\n\n return sanitizedLines.join('\\n')\n}\n"],"mappings":"AAAA,sDACA;;;;;;wDAYA,SACEA,mBAAmB,EACnBC,eAAe,EACfC,eAAe,EACfC,WAAW,EACXC,YAAY,EACZC,QAAQ,QACH;AACP,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,cAAc,EACdC,YAAY,E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,QAAA,GAAW,MAAMzB,IAAA,CAAK2B,IAAI;IACxE;EACF;EAEA,OAAOL,cAAA,CAAenC,IAAI,CAAC;AAC7B","ignoreList":[]}
1
+ {"version":3,"file":"MarkdownTransformers.js","names":["$createListItemNode","$createListNode","$isListItemNode","$isListNode","ListItemNode","ListNode","$createHeadingNode","$createQuoteNode","$isHeadingNode","$isQuoteNode","HeadingNode","QuoteNode","$createLineBreakNode","$isLineBreakNode","$isTextNode","$setState","createState","EMPTY_OR_WHITESPACE_ONLY","ORDERED_LIST_REGEX","UNORDERED_LIST_REGEX","CHECK_LIST_REGEX","HEADING_REGEX","QUOTE_REGEX","CODE_START_REGEX","CODE_END_REGEX","CODE_SINGLE_LINE_REGEX","TABLE_ROW_REG_EXP","TABLE_ROW_DIVIDER_REG_EXP","TAG_START_REGEX","TAG_END_REGEX","hardLineBreakState","parse","val","test","parseMarkdownHardLineBreak","line","endsWith","slice","spaces","match","hasNonWhitespaceContentOnLine","children","endIndex","i","getTextContent","$extractMarkdownHardLineBreakMarker","previousNode","getChildren","lastChildIndex","length","lastChild","lastText","hardLineBreak","text","marker","setTextContent","$createMarkdownLineBreakNode","lineBreakNode","createBlockNode","createNode","parentNode","node","append","replace","select","LIST_INDENT_SIZE","getIndent","whitespaces","tabs","indent","Math","floor","listReplace","listType","getPreviousSibling","nextNode","getNextSibling","listItem","undefined","getListType","firstChild","getFirstChild","insertBefore","remove","list","Number","setIndent","listExport","listNode","exportChildren","depth","output","index","listItemNode","getChildrenSize","push","repeat","prefix","getStart","getChecked","join","HEADING","type","dependencies","export","level","getTag","regExp","tag","QUOTE","lines","split","_match","isImport","splice","UNORDERED_LIST","CHECK_LIST","ORDERED_LIST","INLINE_CODE","format","HIGHLIGHT","BOLD_ITALIC_STAR","BOLD_ITALIC_UNDERSCORE","intraword","BOLD_STAR","BOLD_UNDERSCORE","STRIKETHROUGH","ITALIC_STAR","ITALIC_UNDERSCORE","normalizeMarkdown","input","shouldMergeAdjacentLines","inCodeBlock","sanitizedLines","nestedDeepCodeBlock","lastLine","lastLineHasHardLineBreak","trim","trimStart"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownTransformers.ts"],"sourcesContent":["/* eslint-disable regexp/no-unused-capturing-group */\n/**\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 { ListType } from '@lexical/list'\nimport type { HeadingTagType } from '@lexical/rich-text'\nimport type {\n ElementNode,\n Klass,\n LexicalNode,\n LineBreakNode,\n TextFormatType,\n TextNode,\n} from 'lexical'\n\nimport {\n $createListItemNode,\n $createListNode,\n $isListItemNode,\n $isListNode,\n ListItemNode,\n ListNode,\n} from '@lexical/list'\nimport {\n $createHeadingNode,\n $createQuoteNode,\n $isHeadingNode,\n $isQuoteNode,\n HeadingNode,\n QuoteNode,\n} from '@lexical/rich-text'\nimport {\n $createLineBreakNode,\n $isLineBreakNode,\n $isTextNode,\n $setState,\n createState,\n} from 'lexical'\n\nexport type Transformer =\n | ElementTransformer\n | MultilineElementTransformer\n | TextFormatTransformer\n | TextMatchTransformer\n\nexport type ElementTransformer = {\n dependencies: Array<Klass<LexicalNode>>\n /**\n * `export` is called when the `$convertToMarkdownString` is called to convert the editor state into markdown.\n *\n * @return return null to cancel the export, even though the regex matched. Lexical will then search for the next transformer.\n */\n export: (\n node: LexicalNode,\n\n traverseChildren: (node: ElementNode) => string,\n ) => null | string\n regExp: RegExp\n /**\n * `replace` is called when markdown is imported or typed in the editor\n *\n * @return return false to cancel the transform, even though the regex matched. Lexical will then search for the next transformer.\n */\n replace: (\n parentNode: ElementNode,\n children: Array<LexicalNode>,\n match: Array<string>,\n /**\n * Whether the match is from an import operation (e.g. through `$convertFromMarkdownString`) or not (e.g. through typing in the editor).\n */\n isImport: boolean,\n ) => boolean | void\n type: 'element'\n}\n\nexport type MultilineElementTransformer = {\n dependencies: Array<Klass<LexicalNode>>\n /**\n * `export` is called when the `$convertToMarkdownString` is called to convert the editor state into markdown.\n *\n * @return return null to cancel the export, even though the regex matched. Lexical will then search for the next transformer.\n */\n export?: (\n node: LexicalNode,\n\n traverseChildren: (node: ElementNode) => string,\n ) => null | string\n /**\n * Use this function to manually handle the import process, once the `regExpStart` has matched successfully.\n * Without providing this function, the default behavior is to match until `regExpEnd` is found, or until the end of the document if `regExpEnd.optional` is true.\n *\n * @returns a tuple or null. The 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. If null is returned, the next multilineElementTransformer will be tried. If undefined is returned, the default behavior will be used.\n */\n handleImportAfterStartMatch?: (args: {\n lines: Array<string>\n rootNode: ElementNode\n startLineIndex: number\n startMatch: RegExpMatchArray\n transformer: MultilineElementTransformer\n }) => [boolean, number] | null | undefined\n /**\n * This regex determines when to stop matching. Anything in between regExpStart and regExpEnd will be matched\n */\n regExpEnd?:\n | {\n /**\n * Whether the end match is optional. If true, the end match is not required to match for the transformer to be triggered.\n * The entire text from regexpStart to the end of the document will then be matched.\n */\n optional?: true\n regExp: RegExp\n }\n | RegExp\n /**\n * This regex determines when to start matching\n */\n regExpStart: RegExp\n /**\n * `replace` is called only when markdown is imported in the editor, not when it's typed\n *\n * @return return false to cancel the transform, even though the regex matched. Lexical will then search for the next transformer.\n */\n replace: (\n rootNode: ElementNode,\n /**\n * During markdown shortcut transforms, children nodes may be provided to the transformer. If this is the case, no `linesInBetween` will be provided and\n * the children nodes should be used instead of the `linesInBetween` to create the new node.\n */\n children: Array<LexicalNode> | null,\n startMatch: Array<string>,\n endMatch: Array<string> | null,\n /**\n * linesInBetween includes the text between the start & end matches, split up by lines, not including the matches themselves.\n * This is null when the transformer is triggered through markdown shortcuts (by typing in the editor)\n */\n linesInBetween: Array<string> | null,\n /**\n * Whether the match is from an import operation (e.g. through `$convertFromMarkdownString`) or not (e.g. through typing in the editor).\n */\n isImport: boolean,\n ) => boolean | void\n type: 'multiline-element'\n}\n\nexport type TextFormatTransformer = Readonly<{\n format: ReadonlyArray<TextFormatType>\n intraword?: boolean\n tag: string\n type: 'text-format'\n}>\n\nexport type TextMatchTransformer = Readonly<{\n dependencies: Array<Klass<LexicalNode>>\n /**\n * Determines how a node should be exported to markdown\n */\n export?: (\n node: LexicalNode,\n\n exportChildren: (node: ElementNode) => string,\n\n exportFormat: (node: TextNode, textContent: string) => string,\n ) => null | string\n /**\n * For import operations, this function can be used to determine the end index of the match, after `importRegExp` has matched.\n * Without this function, the end index will be determined by the length of the match from `importRegExp`. Manually determining the end index can be useful if\n * the match from `importRegExp` is not the entire text content of the node. That way, `importRegExp` can be used to match only the start of the node, and `getEndIndex`\n * can be used to match the end of the node.\n *\n * @returns The end index of the match, or false if the match was unsuccessful and a different transformer should be tried.\n */\n getEndIndex?: (node: TextNode, match: RegExpMatchArray) => false | number\n /**\n * This regex determines what text is matched during markdown imports\n */\n importRegExp?: RegExp\n /**\n * This regex determines what text is matched for markdown shortcuts while typing in the editor\n */\n regExp: RegExp\n /**\n * Determines how the matched markdown text should be transformed into a node during the markdown import process\n *\n * @returns nothing, or a TextNode that may be a child of the new node that is created.\n * If a TextNode is returned, text format matching will be applied to it (e.g. bold, italic, etc.)\n */\n replace?: (node: TextNode, match: RegExpMatchArray) => TextNode | void\n /**\n * Single character that allows the transformer to trigger when typed in the editor. This does not affect markdown imports outside of the markdown shortcut plugin.\n * If the trigger is matched, the `regExp` will be used to match the text in the second step.\n */\n trigger?: string\n type: 'text-match'\n}>\n\nconst EMPTY_OR_WHITESPACE_ONLY = /^[\\t ]*$/\nconst ORDERED_LIST_REGEX = /^(\\s*)(\\d+)\\.\\s/\nconst UNORDERED_LIST_REGEX = /^(\\s*)[-*+]\\s/\nconst CHECK_LIST_REGEX = /^(\\s*)(?:-\\s)?\\s?(\\[(\\s|x)?\\])\\s/i\nconst HEADING_REGEX = /^(#{1,6})\\s/\nconst QUOTE_REGEX = /^>\\s/\nconst CODE_START_REGEX = /^[ \\t]*(\\\\`\\\\`\\\\`|```)(\\w+)?/\nconst CODE_END_REGEX = /[ \\t]*(\\\\`\\\\`\\\\`|```)$/\nconst CODE_SINGLE_LINE_REGEX = /^[ \\t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/\nconst TABLE_ROW_REG_EXP = /^\\|(.+)\\|\\s?$/\nconst TABLE_ROW_DIVIDER_REG_EXP = /^(\\| ?:?-*:? ?)+\\|\\s?$/\nconst TAG_START_REGEX = /^[ \\t]*<[a-z_][\\w-]*(?:\\s[^<>]*)?\\/?>/i\nconst TAG_END_REGEX = /^[ \\t]*<\\/[a-z_][\\w-]*\\s*>/i\n\n/**\n * A CommonMark hard line break marker: either a single backslash (`\\`) or two or\n * more trailing spaces, both placed at the end of a line before the newline.\n * See https://spec.commonmark.org/0.31.2/#hard-line-breaks\n */\nexport type MarkdownHardLineBreak = string\n\n/**\n * Stores the original hard line break marker on a `LineBreakNode` so it can be\n * preserved across a markdown import/export round trip instead of being\n * collapsed into a soft line break.\n *\n * Note: unlike upstream Lexical (which sets `resetOnCopyNode: true`), that option\n * does not exist in the `lexical` version pinned here (0.41.0), so it is omitted.\n */\nexport const hardLineBreakState = createState('mdHardLineBreak', {\n parse: (val): MarkdownHardLineBreak => {\n if (typeof val === 'string' && /^(\\\\| {2,})$/.test(val)) {\n return val\n }\n return ''\n },\n})\n\n/**\n * Detects a CommonMark hard line break marker at the end of a raw line.\n *\n * @returns a tuple of `[textWithoutMarker, marker]` when a marker is found, otherwise null.\n */\nexport function parseMarkdownHardLineBreak(line: string): [string, MarkdownHardLineBreak] | null {\n if (line.endsWith('\\\\')) {\n return [line.slice(0, -1), '\\\\']\n }\n\n const spaces = line.match(/^(.*?\\S)( {2,})$/)\n return spaces ? [spaces[1]!, spaces[2]!] : null\n}\n\nfunction hasNonWhitespaceContentOnLine(children: Array<LexicalNode>, endIndex: number): boolean {\n for (let i = endIndex - 1; i >= 0; i--) {\n if ($isLineBreakNode(children[i])) {\n return false\n }\n if (/\\S/.test(children[i]!.getTextContent())) {\n return true\n }\n }\n return false\n}\n\n/**\n * Removes a trailing hard line break marker from the last text node of `previousNode`\n * (if present) and returns the marker, so it can be carried onto a `LineBreakNode`.\n */\nfunction $extractMarkdownHardLineBreakMarker(\n previousNode: ElementNode,\n): MarkdownHardLineBreak | null {\n const children = previousNode.getChildren()\n const lastChildIndex = children.length - 1\n const lastChild = children[lastChildIndex]\n\n if (!$isTextNode(lastChild)) {\n return null\n }\n\n const lastText = lastChild.getTextContent()\n const hardLineBreak = parseMarkdownHardLineBreak(lastText)\n\n if (hardLineBreak !== null) {\n const [text, marker] = hardLineBreak\n lastChild.setTextContent(text)\n return marker\n }\n\n // Trailing whitespace may have been split into its own text node by inline\n // transformers (e.g. after formatted or linked content). Only treat it as a\n // hard break when there is preceding non-whitespace content on the same line.\n if (/^ {2,}$/.test(lastText) && hasNonWhitespaceContentOnLine(children, lastChildIndex)) {\n lastChild.setTextContent('')\n return lastText\n }\n\n return null\n}\n\n/**\n * Creates a `LineBreakNode` for a markdown line join, preserving any CommonMark\n * hard line break marker found at the end of `previousNode` via node state.\n */\nexport function $createMarkdownLineBreakNode(previousNode: ElementNode): LineBreakNode {\n const lineBreakNode = $createLineBreakNode()\n const hardLineBreak = $extractMarkdownHardLineBreakMarker(previousNode)\n\n if (hardLineBreak !== null) {\n $setState(lineBreakNode, hardLineBreakState, hardLineBreak)\n }\n\n return lineBreakNode\n}\n\nconst createBlockNode = (\n createNode: (match: Array<string>) => ElementNode,\n): ElementTransformer['replace'] => {\n return (parentNode, children, match) => {\n const node = createNode(match)\n node.append(...children)\n parentNode.replace(node)\n node.select(0, 0)\n }\n}\n\n// Amount of spaces that define indentation level\n// TODO: should be an option\nconst LIST_INDENT_SIZE = 4\n\nfunction getIndent(whitespaces: string): number {\n const tabs = whitespaces.match(/\\t/g)\n const spaces = whitespaces.match(/ /g)\n\n let indent = 0\n\n if (tabs) {\n indent += tabs.length\n }\n\n if (spaces) {\n indent += Math.floor(spaces.length / LIST_INDENT_SIZE)\n }\n\n return indent\n}\n\nconst listReplace = (listType: ListType): ElementTransformer['replace'] => {\n return (parentNode, children, match) => {\n const previousNode = parentNode.getPreviousSibling()\n const nextNode = parentNode.getNextSibling()\n const listItem = $createListItemNode(listType === 'check' ? match[3] === 'x' : undefined)\n if ($isListNode(nextNode) && nextNode.getListType() === listType) {\n const firstChild = nextNode.getFirstChild()\n if (firstChild !== null) {\n firstChild.insertBefore(listItem)\n } else {\n // should never happen, but let's handle gracefully, just in case.\n nextNode.append(listItem)\n }\n parentNode.remove()\n } else if ($isListNode(previousNode) && previousNode.getListType() === listType) {\n previousNode.append(listItem)\n parentNode.remove()\n } else {\n const list = $createListNode(listType, listType === 'number' ? Number(match[2]) : undefined)\n list.append(listItem)\n parentNode.replace(list)\n }\n listItem.append(...children)\n listItem.select(0, 0)\n const indent = getIndent(match[1]!)\n if (indent) {\n listItem.setIndent(indent)\n }\n }\n}\n\nconst listExport = (\n listNode: ListNode,\n exportChildren: (node: ElementNode) => string,\n depth: number,\n): string => {\n const output: string[] = []\n const children = listNode.getChildren()\n let index = 0\n for (const listItemNode of children) {\n if ($isListItemNode(listItemNode)) {\n if (listItemNode.getChildrenSize() === 1) {\n const firstChild = listItemNode.getFirstChild()\n if ($isListNode(firstChild)) {\n output.push(listExport(firstChild, exportChildren, depth + 1))\n continue\n }\n }\n const indent = ' '.repeat(depth * LIST_INDENT_SIZE)\n const listType = listNode.getListType()\n const prefix =\n listType === 'number'\n ? `${listNode.getStart() + index}. `\n : listType === 'check'\n ? `- [${listItemNode.getChecked() ? 'x' : ' '}] `\n : '- '\n output.push(indent + prefix + exportChildren(listItemNode))\n index++\n }\n }\n\n return output.join('\\n')\n}\n\nexport const HEADING: ElementTransformer = {\n type: 'element',\n dependencies: [HeadingNode],\n export: (node, exportChildren) => {\n if (!$isHeadingNode(node)) {\n return null\n }\n const level = Number(node.getTag().slice(1))\n return '#'.repeat(level) + ' ' + exportChildren(node)\n },\n regExp: HEADING_REGEX,\n replace: createBlockNode((match) => {\n const tag = ('h' + match[1]!.length) as HeadingTagType\n return $createHeadingNode(tag)\n }),\n}\n\nexport const QUOTE: ElementTransformer = {\n type: 'element',\n dependencies: [QuoteNode],\n export: (node, exportChildren) => {\n if (!$isQuoteNode(node)) {\n return null\n }\n\n const lines = exportChildren(node).split('\\n')\n const output: string[] = []\n for (const line of lines) {\n output.push('> ' + line)\n }\n return output.join('\\n')\n },\n regExp: QUOTE_REGEX,\n replace: (parentNode, children, _match, isImport) => {\n if (isImport) {\n const previousNode = parentNode.getPreviousSibling()\n if ($isQuoteNode(previousNode)) {\n previousNode.splice(previousNode.getChildrenSize(), 0, [\n $createMarkdownLineBreakNode(previousNode),\n ...children,\n ])\n previousNode.select(0, 0)\n parentNode.remove()\n return\n }\n }\n\n const node = $createQuoteNode()\n node.append(...children)\n parentNode.replace(node)\n node.select(0, 0)\n },\n}\n\nexport const UNORDERED_LIST: ElementTransformer = {\n type: 'element',\n dependencies: [ListNode, ListItemNode],\n export: (node, exportChildren) => {\n return $isListNode(node) ? listExport(node, exportChildren, 0) : null\n },\n regExp: UNORDERED_LIST_REGEX,\n replace: listReplace('bullet'),\n}\n\nexport const CHECK_LIST: ElementTransformer = {\n type: 'element',\n dependencies: [ListNode, ListItemNode],\n export: (node, exportChildren) => {\n return $isListNode(node) ? listExport(node, exportChildren, 0) : null\n },\n regExp: CHECK_LIST_REGEX,\n replace: listReplace('check'),\n}\n\nexport const ORDERED_LIST: ElementTransformer = {\n type: 'element',\n dependencies: [ListNode, ListItemNode],\n export: (node, exportChildren) => {\n return $isListNode(node) ? listExport(node, exportChildren, 0) : null\n },\n regExp: ORDERED_LIST_REGEX,\n replace: listReplace('number'),\n}\n\nexport const INLINE_CODE: TextFormatTransformer = {\n type: 'text-format',\n format: ['code'],\n tag: '`',\n}\n\nexport const HIGHLIGHT: TextFormatTransformer = {\n type: 'text-format',\n format: ['highlight'],\n tag: '==',\n}\n\nexport const BOLD_ITALIC_STAR: TextFormatTransformer = {\n type: 'text-format',\n format: ['bold', 'italic'],\n tag: '***',\n}\n\nexport const BOLD_ITALIC_UNDERSCORE: TextFormatTransformer = {\n type: 'text-format',\n format: ['bold', 'italic'],\n intraword: false,\n tag: '___',\n}\n\nexport const BOLD_STAR: TextFormatTransformer = {\n type: 'text-format',\n format: ['bold'],\n tag: '**',\n}\n\nexport const BOLD_UNDERSCORE: TextFormatTransformer = {\n type: 'text-format',\n format: ['bold'],\n intraword: false,\n tag: '__',\n}\n\nexport const STRIKETHROUGH: TextFormatTransformer = {\n type: 'text-format',\n format: ['strikethrough'],\n tag: '~~',\n}\n\nexport const ITALIC_STAR: TextFormatTransformer = {\n type: 'text-format',\n format: ['italic'],\n tag: '*',\n}\n\nexport const ITALIC_UNDERSCORE: TextFormatTransformer = {\n type: 'text-format',\n format: ['italic'],\n intraword: false,\n tag: '_',\n}\n\nexport function normalizeMarkdown(input: string, shouldMergeAdjacentLines: boolean): string {\n const lines = input.split('\\n')\n let inCodeBlock = false\n const sanitizedLines: string[] = []\n let nestedDeepCodeBlock = 0\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!\n const lastLine = sanitizedLines[sanitizedLines.length - 1]\n // A hard line break marker on the current line only matters if another line follows it.\n const hardLineBreak = i < lines.length - 1 ? parseMarkdownHardLineBreak(line) : null\n const lastLineHasHardLineBreak =\n lastLine !== undefined && parseMarkdownHardLineBreak(lastLine) !== null\n\n // Code blocks of ```single line``` don't toggle the inCodeBlock flag\n if (CODE_SINGLE_LINE_REGEX.test(line)) {\n sanitizedLines.push(line)\n continue\n }\n\n if (CODE_END_REGEX.test(line)) {\n if (nestedDeepCodeBlock === 0) {\n inCodeBlock = true\n }\n if (nestedDeepCodeBlock === 1) {\n inCodeBlock = false\n }\n if (nestedDeepCodeBlock > 0) {\n nestedDeepCodeBlock--\n }\n sanitizedLines.push(line)\n continue\n }\n\n // Toggle inCodeBlock state when encountering start or end of a code block\n if (CODE_START_REGEX.test(line)) {\n inCodeBlock = true\n nestedDeepCodeBlock++\n sanitizedLines.push(line)\n continue\n }\n\n // If we are inside a code block, keep the line unchanged\n if (inCodeBlock) {\n sanitizedLines.push(line)\n continue\n }\n\n // In markdown the concept of \"empty paragraphs\" does not exist.\n // Blocks must be separated by an empty line. Non-empty adjacent lines must be merged.\n if (\n EMPTY_OR_WHITESPACE_ONLY.test(line) ||\n EMPTY_OR_WHITESPACE_ONLY.test(lastLine!) ||\n !lastLine ||\n HEADING_REGEX.test(lastLine) ||\n HEADING_REGEX.test(line) ||\n QUOTE_REGEX.test(line) ||\n ORDERED_LIST_REGEX.test(line) ||\n UNORDERED_LIST_REGEX.test(line) ||\n CHECK_LIST_REGEX.test(line) ||\n TABLE_ROW_REG_EXP.test(line) ||\n TABLE_ROW_DIVIDER_REG_EXP.test(line) ||\n // Don't merge the next line into a line that ends with a hard line break marker.\n lastLineHasHardLineBreak ||\n !shouldMergeAdjacentLines ||\n TAG_START_REGEX.test(line) ||\n TAG_END_REGEX.test(line) ||\n TAG_START_REGEX.test(lastLine) ||\n TAG_END_REGEX.test(lastLine) ||\n CODE_END_REGEX.test(lastLine)\n ) {\n sanitizedLines.push(line)\n } else {\n // Preserve a trailing hard line break marker on the merged line so it survives import.\n sanitizedLines[sanitizedLines.length - 1] =\n lastLine + ' ' + (hardLineBreak === null ? line.trim() : line.trimStart())\n }\n }\n\n return sanitizedLines.join('\\n')\n}\n"],"mappings":"AAAA,sDACA;;;;;;wDAmBA,SACEA,mBAAmB,EACnBC,eAAe,EACfC,eAAe,EACfC,WAAW,EACXC,YAAY,EACZC,QAAQ,QACH;AACP,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,cAAc,EACdC,YAAY,EACZC,WAAW,EACXC,SAAS,QACJ;AACP,SACEC,oBAAoB,EACpBC,gBAAgB,EAChBC,WAAW,EACXC,SAAS,EACTC,WAAW,QACN;AA8JP,MAAMC,wBAAA,GAA2B;AACjC,MAAMC,kBAAA,GAAqB;AAC3B,MAAMC,oBAAA,GAAuB;AAC7B,MAAMC,gBAA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,IAAA,KACjBjB,kBAAA,CAAmBe,IAAI,CAACE,IAAA,KACxBhB,oBAAA,CAAqBc,IAAI,CAACE,IAAA,KAC1Bf,gBAAA,CAAiBa,IAAI,CAACE,IAAA,KACtBT,iBAAA,CAAkBO,IAAI,CAACE,IAAA,KACvBR,yBAAA,CAA0BM,IAAI,CAACE,IAAA;IAC/B;IACAqG,wBAAA,IACA,CAACL,wBAAA,IACDvG,eAAA,CAAgBK,IAAI,CAACE,IAAA,KACrBN,aAAA,CAAcI,IAAI,CAACE,IAAA,KACnBP,eAAA,CAAgBK,IAAI,CAACsG,QAAA,KACrB1G,aAAA,CAAcI,IAAI,CAACsG,QAAA,KACnB/G,cAAA,CAAeS,IAAI,CAACsG,QAAA,GACpB;MACAF,cAAA,CAAetC,IAAI,CAAC5D,IAAA;IACtB,OAAO;MACL;MACAkG,cAAc,CAACA,cAAA,CAAepF,MAAM,GAAG,EAAE,GACvCsF,QAAA,GAAW,OAAOnF,aAAA,KAAkB,OAAOjB,IAAA,CAAKsG,IAAI,KAAKtG,IAAA,CAAKuG,SAAS,EAAC;IAC5E;EACF;EAEA,OAAOL,cAAA,CAAejC,IAAI,CAAC;AAC7B","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/richtext-lexical",
3
- "version": "3.85.1",
3
+ "version": "3.85.2",
4
4
  "description": "The officially supported Lexical richtext adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -378,8 +378,8 @@
378
378
  "react-error-boundary": "4.1.2",
379
379
  "ts-essentials": "10.0.3",
380
380
  "uuid": "13.0.2",
381
- "@payloadcms/translations": "3.85.1",
382
- "@payloadcms/ui": "3.85.1"
381
+ "@payloadcms/translations": "3.85.2",
382
+ "@payloadcms/ui": "3.85.2"
383
383
  },
384
384
  "devDependencies": {
385
385
  "@babel/cli": "7.27.2",
@@ -398,7 +398,7 @@
398
398
  "esbuild": "0.27.1",
399
399
  "esbuild-sass-plugin": "3.3.1",
400
400
  "swc-plugin-transform-remove-imports": "8.3.0",
401
- "payload": "3.85.1",
401
+ "payload": "3.85.2",
402
402
  "@payloadcms/eslint-config": "3.28.0"
403
403
  },
404
404
  "peerDependencies": {
@@ -406,8 +406,8 @@
406
406
  "@faceless-ui/scroll-info": "2.0.0",
407
407
  "react": "^19.0.1 || ^19.1.2 || ^19.2.1",
408
408
  "react-dom": "^19.0.1 || ^19.1.2 || ^19.2.1",
409
- "payload": "3.85.1",
410
- "@payloadcms/next": "3.85.1"
409
+ "@payloadcms/next": "3.85.2",
410
+ "payload": "3.85.2"
411
411
  },
412
412
  "engines": {
413
413
  "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";import{c as he}from"react/compiler-runtime";import{useRef as xe}from"react";function ro(r){let t=he(2),e=r===void 0?500:r,o=xe(void 0),n;return t[0]!==e?(n=s=>new Promise(i=>{let l=()=>{s(),i()};"requestIdleCallback"in window?("cancelIdleCallback"in window&&o.current!==void 0&&cancelIdleCallback(o.current),o.current=requestIdleCallback(l,{timeout:e})):Ee().then(l)}),t[0]=e,t[1]=n):n=t[1],n}function Ee(){return new Promise(r=>{setTimeout(r,100),requestAnimationFrame(()=>{setTimeout(r,0)})})}import{jsx as _e}from"react/jsx-runtime";import{useControllableState as Te}from"@payloadcms/ui";import{createContext as we,use as Ce,useMemo as Se}from"react";var ct=we({currentView:"default",inheritable:!1,setCurrentView:()=>{}}),fo=r=>{let t=Re(),e=r.currentView!==void 0,o=t.inheritable&&(!!t.views||!!t.hasExplicitCurrentView),n=e||t.inheritable&&!!t.hasExplicitCurrentView,{children:c,currentView:s,inheritable:i,views:l}={children:r.children,currentView:o?t.currentView:r.currentView,inheritable:t.inheritable||r.inheritable,views:o&&t.views?t.views:r.views},[a,u]=Te(s,"default"),p=l&&a!=="default"&&!l[a]?"default":a,m=Se(()=>{let g=l?l[p]:void 0;return{currentView:p,currentViewMap:g,hasExplicitCurrentView:n,inheritable:i,isControlledByParent:o,setCurrentView:u,views:l}},[p,i,n,o,u,l]);return _e(ct,{value:m,children:c})};function Re(){return Ce(ct)}var G=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 lt(r){return r instanceof G}import{jsx as Ve}from"react/jsx-runtime";import{useLexicalComposerContext as Xe}from"@lexical/react/LexicalComposerContext.js";import{mergeRegister as Ge}from"@lexical/utils";import{$getSelection as j,$isRangeSelection as W,$isTextNode as ze,COMMAND_PRIORITY_LOW as Ye,createCommand as je,getDOMSelection as We}from"lexical";import{useCallback as _t,useEffect as Tt,useState as qe}from"react";import*as Y from"react";import{c as pt}from"react/compiler-runtime";import{useLexicalComposerContext as gt}from"@lexical/react/LexicalComposerContext.js";import{mergeRegister as at}from"@lexical/utils";import{$getSelection as ht,$isRangeSelection as ye,$setSelection as be,COMMAND_PRIORITY_LOW as ft,COMMAND_PRIORITY_NORMAL as $,createCommand as ke,KEY_ARROW_DOWN_COMMAND as Oe,KEY_ARROW_UP_COMMAND as Ne,KEY_ENTER_COMMAND as Fe,KEY_ESCAPE_COMMAND as Ie,KEY_TAB_COMMAND as Me}from"lexical";import{useCallback as z,useEffect as k,useLayoutEffect as Ae,useMemo as De,useRef as Le,useState as $e}from"react";var Be="slash-menu-popup",ut=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 ve(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 Pe(r){let t=ht();if(!ye(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,c=o.getTextContent().slice(0,n),s=r.replaceableString.length,i=ve(c,r.matchingString,s),l=n-i;if(l<0)return;let a;return l===0?[a]=o.splitText(n):[,a]=o.splitText(l,n),a}function He(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 c=r;c=c.parentElement;)if(e=getComputedStyle(c),!(o&&e.position==="static")&&n.test(e.overflow+e.overflowY+e.overflowX))return c;return document.body}function dt(r,t){let e=r.getBoundingClientRect(),o=t.getBoundingClientRect();return e.top>o.top&&e.top<o.bottom}function Ke(r,t,e,o){let n=pt(7),[c]=gt(),s,i;n[0]!==c||n[1]!==e||n[2]!==o||n[3]!==r||n[4]!==t?(s=()=>{let l=t.current;if(l!=null&&r!=null){let a=c.getRootElement(),u=a!=null?He(a,!1):document.body,p=!1,m=dt(l,u),g=function(){p||(window.requestAnimationFrame(function(){e(),p=!1}),p=!0);let d=dt(l,u);d!==m&&(m=d,o?.(d))},f=new ResizeObserver(e);return window.addEventListener("resize",e),document.addEventListener("scroll",g,{capture:!0,passive:!0}),f.observe(l),()=>{f.disconnect(),window.removeEventListener("resize",e),document.removeEventListener("scroll",g,!0)}}},i=[c,o,e,r,t],n[0]=c,n[1]=e,n[2]=o,n[3]=r,n[4]=t,n[5]=s,n[6]=i):(s=n[5],i=n[6]),k(s,i)}var mt=ke("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function xt({anchorElementRef:r,close:t,editor:e,groups:o,menuRenderFn:n,resolution:c,shouldSplitNodeWithQuery:s=!1}){let[i,l]=$e(null),a=c.match&&c.match.matchingString||"",u=z(f=>{let d=e.getRootElement();d!==null&&(d.setAttribute("aria-activedescendant",`${Be}__item-${f.key}`),l(f.key))},[e]),p=z(()=>{if(o!==null&&a!=null){let f=o.flatMap(d=>d.items);if(f.length){let d=f[0];u(d)}}},[o,u,a]);k(()=>{p()},[a,p]);let m=z(f=>{t(),e.update(()=>{let d=c.match!=null&&s?Pe(c.match):null;d&&d.remove()}),setTimeout(()=>{let d;e.read(()=>{d=ht()?.clone()}),e.update(()=>{d&&be(d)}),f.onSelect({editor:e,queryString:c.match?c.match.matchingString:""})},0)},[e,s,c.match,t]);k(()=>()=>{let f=e.getRootElement();f!==null&&f.removeAttribute("aria-activedescendant")},[e]),Ae(()=>{o===null?l(null):i===null&&p()},[o,i,u,p]),k(()=>at(e.registerCommand(mt,({item:f})=>f.ref&&f.ref.current!=null?(ut(f.ref.current),!0):!1,ft)),[e,u]),k(()=>at(e.registerCommand(Oe,f=>{let d=f;if(o!==null&&o.length&&i!==null){let h=o.flatMap(T=>T.items),x=h.findIndex(T=>T.key===i),E=x!==h.length-1?x+1:0,_=h[E];if(!_)return!1;u(_),_.ref!=null&&_.ref.current&&e.dispatchCommand(mt,{index:E,item:_}),d.preventDefault(),d.stopImmediatePropagation()}return!0},$),e.registerCommand(Ne,f=>{let d=f;if(o!==null&&o.length&&i!==null){let h=o.flatMap(T=>T.items),x=h.findIndex(T=>T.key===i),E=x!==0?x-1:h.length-1,_=h[E];if(!_)return!1;u(_),_.ref!=null&&_.ref.current&&ut(_.ref.current),d.preventDefault(),d.stopImmediatePropagation()}return!0},$),e.registerCommand(Ie,f=>{let d=f;return d.preventDefault(),d.stopImmediatePropagation(),t(),!0},ft),e.registerCommand(Me,f=>{let d=f;if(o===null||i===null)return!1;let x=o.flatMap(E=>E.items).find(E=>E.key===i);return x?(d.preventDefault(),d.stopImmediatePropagation(),m(x),!0):!1},$),e.registerCommand(Fe,f=>{if(o===null||i===null)return!1;let h=o.flatMap(x=>x.items).find(x=>x.key===i);return h?(f!==null&&(f.preventDefault(),f.stopImmediatePropagation()),m(h),!0):!1},$)),[m,t,e,o,i,u]);let g=De(()=>({groups:o,selectedItemKey:i,selectItemAndCleanUp:m,setSelectedItemKey:l}),[m,i,o]);return n(r,g,c.match?c.match.matchingString:"")}function Ue(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 Et(r,t,e,o){let n=pt(14),[c]=gt(),s;n[0]===Symbol.for("react.memo_cache_sentinel")?(s=st?document.createElement("div"):null,n[0]=s):s=n[0];let i=Le(s),l;n[1]!==r||n[2]!==o||n[3]!==c||n[4]!==t?(l=()=>{if(i.current===null||parent===void 0)return;let f=c.getRootElement(),d=i.current,h=d.firstChild;if(f!==null&&t!==null){let{height:x,width:E}=t.getRect(),{left:_,top:T}=t.getRect(),b=T;if(T=T-(r.getBoundingClientRect().top+window.scrollY),_=_-(r.getBoundingClientRect().left+window.scrollX),d.style.left=`${_+window.scrollX}px`,d.style.height=`${x}px`,d.style.width=`${E}px`,h!==null){let w=h.getBoundingClientRect(),L=w.height,S=w.width,X=f.getBoundingClientRect(),rt=document.dir==="rtl"||document.documentElement.dir==="rtl",de=r.getBoundingClientRect(),it=Math.max(0,X.left);if(!rt&&_+S>X.right)d.style.left=`${X.right-S+window.scrollX}px`;else if(rt&&w.left<it){let ge=it+S-de.left;d.style.left=`${ge+window.scrollX}px`}let me=b+L+32>window.innerHeight,pe=b<0;me&&!pe?d.style.top=`${T+32-L+window.scrollY-(x+24)}px`:d.style.top=`${T+window.scrollY+32}px`}d.isConnected||(Ue(d,o),r.append(d)),d.setAttribute("id","slash-menu"),i.current=d,f.setAttribute("aria-controls","slash-menu")}},n[1]=r,n[2]=o,n[3]=c,n[4]=t,n[5]=l):l=n[5];let a=l,u,p;n[6]!==c||n[7]!==a||n[8]!==t?(u=()=>{let f=c.getRootElement();if(t!==null)return a(),()=>{f!==null&&f.removeAttribute("aria-controls");let d=i.current;d!==null&&d.isConnected&&(d.remove(),d.removeAttribute("id"))}},p=[c,a,t],n[6]=c,n[7]=a,n[8]=t,n[9]=u,n[10]=p):(u=n[9],p=n[10]),k(u,p);let m;return n[11]!==t||n[12]!==e?(m=f=>{t!==null&&(f||e(null))},n[11]=t,n[12]=e,n[13]=m):m=n[13],Ke(t,i,a,m),i}var ko=`\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'"~=<>_:;`;function Qe(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 wt(r,t,e){let o=We(e);if(o===null||!o.isCollapsed)return!1;let n=o.anchorNode,c=r,s=o.anchorOffset;if(n==null||s==null)return!1;try{t.setStart(n,c),t.setEnd(n,s>1?s:1)}catch{return!1}return!0}function Je(r){let t;return r.getEditorState().read(()=>{let e=j();W(e)&&(t=Qe(e))}),t}function Ct(r,t){return t!==0?!1:r.getEditorState().read(()=>{let e=j();if(W(e)){let c=e.anchor.getNode().getPreviousSibling();return ze(c)&&c.isTextEntity()}return!1})}function St(r){Y.startTransition?Y.startTransition(r):r()}var Ze=je("ENABLE_SLASH_MENU_COMMAND");function Oo({anchorClassName:r,anchorElem:t,groups:e,menuRenderFn:o,onClose:n,onOpen:c,onQueryChange:s,triggerFn:i}){let[l]=Xe(),[a,u]=qe(null),p=Et(t,a,u,r),m=_t(()=>{u(null),n!=null&&a!==null&&n()},[n,a]),g=_t(f=>{u(f),c!=null&&a===null&&c(f)},[c,a]);return Tt(()=>Ge(l.registerCommand(Ze,({node:f})=>(l.getEditorState().read(()=>{let d={leadOffset:0,matchingString:"",replaceableString:""};if(!Ct(l,d.leadOffset)&&f!==null){let h=l._window??window,x=h.document.createRange();wt(d.leadOffset,x,h)!==null&&St(()=>g({getRect:()=>x.getBoundingClientRect(),match:d}));return}}),!0),Ye)),[l,g]),Tt(()=>{let f=()=>{l.getEditorState().read(()=>{let h=l._window??window,x=h.document.createRange(),E=j(),_=Je(l);if(!W(E)||!E.isCollapsed()||_===void 0||x===null){m();return}let T=i({editor:l,query:_});if(s(T?T.matchingString:null),T!==null&&!Ct(l,T.leadOffset)&&wt(T.leadOffset,x,h)!==null){St(()=>g({getRect:()=>x.getBoundingClientRect(),match:T}));return}m()})},d=l.registerUpdateListener(f);return()=>{d()}},[l,i,s,a,m,g]),p.current===null||a===null||l===null?null:Ve(xt,{anchorElementRef:p,close:m,editor:l,groups:e,menuRenderFn:o,resolution:a,shouldSplitNodeWithQuery:!0})}var Rt=class r{_bottom;_left;_right;_top;constructor(t,e,o,n){let[c,s]=e<=n?[e,n]:[n,e],[i,l]=t<=o?[t,o]:[o,t];this._top=c,this._right=l,this._left=i,this._bottom=s}static fromDOM(t){let{height:e,left:o,top:n,width:c}=t.getBoundingClientRect();return r.fromLWTH(o,c,n,e)}static fromDOMRect(t){let{height:e,left:o,top:n,width:c}=t;return r.fromLWTH(o,c,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:c,y:s}=e;return r.fromLTRB(o,n,c,s)}contains(t){if(lt(t)){let{x:s,y:i}=t,l=i<this._top,a=i>this._bottom,u=s<this._left,p=s>this._right;return{reason:{isOnBottomSide:a,isOnLeftSide:u,isOnRightSide:p,isOnTopSide:l},result:!l&&!a&&!u&&!p}}let{bottom:e,left:o,right:n,top:c}=t;return c>=this._top&&c<=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:c}=t,{height:s,left:i,top:l,width:a}=this,u=o+c>=i+a?o+c:i+a,p=n+e>=l+s?n+e:l+s,m=o<=i?o:i,g=n<=l?n:l;return u-m<=c+a&&p-g<=e+s}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)}};import q from"react";var A=new WeakMap;function Ao(r,t){A.has(r)||A.set(r,new Map);let e=A.get(r);for(let[o,n]of Object.entries(t))if(!(!n||typeof n!="object")){if(o==="blocks"){for(let[c,s]of Object.entries(n))e.set(`block:${c}`,s);continue}if(o==="inlineBlocks"){for(let[c,s]of Object.entries(n))e.set(`inlineBlock:${c}`,s);continue}e.set(o,n)}}function Do(r){A.delete(r)}function yt(r,t,e){let o=A.get(r);if(t==="block"&&e?.__fields?.blockType){let n=e.__fields.blockType;return o?.get(`block:${n}`)}if(t==="inlineBlock"&&e?.__fields?.blockType){let n=e.__fields.blockType;return o?.get(`inlineBlock:${n}`)}return o?.get(t)}function tn({node:r,nodeType:t}){if(!("getType"in r)||r.getType()!==t)return;let e=r;if(e.prototype._originalDecorate||(e.prototype._originalDecorate=e.prototype.decorate),e.prototype._originalCreateDOM||(e.prototype._originalCreateDOM=e.prototype.createDOM),e.prototype.decorate&&!e.prototype._decorateOverridden){e.prototype._decorateOverridden=!0;let o=!!e.prototype.createDOM;e.prototype.decorate=function(n,c){let s=yt(n,t,this);if(s){if(s.Component)return s.Component({config:c,editor:n,isEditor:!0,isJSXConverter:!1,node:this});if(s.createDOM&&s.html){let l=typeof s.html=="function"?s.html({config:c,editor:n,isEditor:!0,isJSXConverter:!1,node:this}):s.html;return q.createElement("span",{dangerouslySetInnerHTML:{__html:l}})}if(s.html&&o&&!s.createDOM)return q.createElement(q.Fragment);if(t==="block"){let l=s;if(l.Block||l.Label)return e.prototype._originalDecorate.call(this,n,c,l.Block,l.Label)}else if(t==="inlineBlock"){let l=s;if(l.Block||l.Label)return e.prototype._originalDecorate.call(this,n,c,l.Block,l.Label)}}return e.prototype._originalDecorate.call(this,n,c)}}e.prototype.createDOM&&!e.prototype._createDOMOverridden&&(e.prototype._createDOMOverridden=!0,e.prototype.createDOM=function(o,n){let c=yt(n,t,this);if(c){if(c.createDOM)return c.createDOM({config:o,editor:n,node:this});if(c.html){let s=typeof c.html=="function"?c.html({config:o,editor:n,isEditor:!0,isJSXConverter:!1,node:this}):c.html,i=document.createElement("div");return i.innerHTML=s,i.firstElementChild||i}}return e.prototype._originalCreateDOM.call(this,o,n)})}function Lo({editorConfig:r,nodeViews:t}){let e=en({nodes:r.features.nodes});if(t){let o=new Set;for(let[n,c]of Object.entries(t))!c||typeof c!="object"||(n==="blocks"&&Object.keys(c).length>0?o.add("block"):n==="inlineBlocks"&&Object.keys(c).length>0?o.add("inlineBlock"):o.add(n));for(let n of e)if("getType"in n){let c=n.getType();o.has(c)&&tn({node:n,nodeType:c})}}return e}function en({nodes:r}){return r.map(t=>"node"in t?t.node:t)}import{$getRoot as un,$isDecoratorNode as Ft,$isElementNode as P,$isLineBreakNode as dn,$isTextNode as H}from"lexical";import{$isListItemNode as nn,$isListNode as bt}from"@lexical/list";import{$isHeadingNode as on,$isQuoteNode as rn}from"@lexical/rich-text";import{$isParagraphNode as sn,$isTextNode as cn}from"lexical";var C={markdownFormatKind:null,regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:!1},R={...C,requiresParagraphStart:!0},Ho={...R,export:O(1),markdownFormatKind:"paragraphH1",regEx:/^# /,regExForAutoFormatting:/^# /},Ko={...R,export:O(2),markdownFormatKind:"paragraphH2",regEx:/^## /,regExForAutoFormatting:/^## /},Uo={...R,export:O(3),markdownFormatKind:"paragraphH3",regEx:/^### /,regExForAutoFormatting:/^### /},Vo={...R,export:O(4),markdownFormatKind:"paragraphH4",regEx:/^#### /,regExForAutoFormatting:/^#### /},Xo={...R,export:O(5),markdownFormatKind:"paragraphH5",regEx:/^##### /,regExForAutoFormatting:/^##### /},Go={...R,export:O(6),markdownFormatKind:"paragraphH6",regEx:/^###### /,regExForAutoFormatting:/^###### /},zo={...R,export:an,markdownFormatKind:"paragraphBlockQuote",regEx:/^> /,regExForAutoFormatting:/^> /},Yo={...R,export:Q,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})- /,regExForAutoFormatting:/^(\s{0,10})- /},jo={...R,export:Q,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})\* /,regExForAutoFormatting:/^(\s{0,10})\* /},Wo={...R,export:Q,markdownFormatKind:"paragraphOrderedList",regEx:/^(\s{0,10})(\d+)\.\s/,regExForAutoFormatting:/^(\s{0,10})(\d+)\.\s/},qo={...R,markdownFormatKind:"horizontalRule",regEx:/^\*\*\*$/,regExForAutoFormatting:/^\*\*\* /},Qo={...R,markdownFormatKind:"horizontalRule",regEx:/^---$/,regExForAutoFormatting:/^--- /},Jo={...C,exportFormat:"code",exportTag:"`",markdownFormatKind:"code",regEx:/(`)(\s*)([^`]*)(\s*)(`)()/,regExForAutoFormatting:/(`)(\s*\b)([^`]*)(\b\s*)(`)(\s)$/},Zo={...C,exportFormat:"bold",exportTag:"**",markdownFormatKind:"bold",regEx:/(\*\*)(\s*)([^*]*)(\s*)(\*\*)()/,regExForAutoFormatting:/(\*\*)(\s*\b)([^*]*)(\b\s*)(\*\*)(\s)$/},tr={...C,exportFormat:"italic",exportTag:"*",markdownFormatKind:"italic",regEx:/(\*)(\s*)([^*]*)(\s*)(\*)()/,regExForAutoFormatting:/(\*)(\s*\b)([^*]*)(\b\s*)(\*)(\s)$/},er={...C,exportFormat:"bold",exportTag:"_",markdownFormatKind:"bold",regEx:/(__)(\s*)([^_]*)(\s*)(__)()/,regExForAutoFormatting:/(__)(\s*)([^_]*)(\s*)(__)(\s)$/},nr={...C,exportFormat:"italic",exportTag:"_",markdownFormatKind:"italic",regEx:/(_)()([^_]*)()(_)()/,regExForAutoFormatting:/(_)()([^_]*)()(_)(\s)$/},or={...C,exportFormat:"underline",exportTag:"<u>",exportTagClose:"</u>",markdownFormatKind:"underline",regEx:/(<u>)(\s*)([^<]*)(\s*)(<\/u>)()/,regExForAutoFormatting:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},rr={...C,exportFormat:"strikethrough",exportTag:"~~",markdownFormatKind:"strikethrough",regEx:/(~~)(\s*)([^~]*)(\s*)(~~)()/,regExForAutoFormatting:/(~~)(\s*\b)([^~]*)(\b\s*)(~~)(\s)$/},ir={...C,markdownFormatKind:"strikethrough_italic_bold",regEx:/(~~_\*\*)(\s*\b)([^*_~]+)(\b\s*)(\*\*_~~)()/,regExForAutoFormatting:/(~~_\*\*)(\s*\b)([^*_~]+)(\b\s*)(\*\*_~~)(\s)$/},sr={...C,markdownFormatKind:"italic_bold",regEx:/(_\*\*)(\s*\b)([^*_]+)(\b\s*)(\*\*_)/,regExForAutoFormatting:/(_\*\*)(\s*\b)([^*_]+)(\b\s*)(\*\*_)(\s)$/},cr={...C,markdownFormatKind:"strikethrough_italic",regEx:/(~~_)(\s*)([^_~]+)(\s*)(_~~)/,regExForAutoFormatting:/(~~_)(\s*)([^_~]+)(\s*)(_~~)(\s)$/},lr={...C,markdownFormatKind:"strikethrough_bold",regEx:/(~~\*\*)(\s*\b)([^*~]+)(\b\s*)(\*\*~~)/,regExForAutoFormatting:/(~~\*\*)(\s*\b)([^*~]+)(\b\s*)(\*\*~~)(\s)$/},ar={...C,markdownFormatKind:"link",regEx:/(\[)([^\]]*)(\]\()([^)]*)(\)*)()/,regExForAutoFormatting:/(\[)([^\]]*)(\]\()([^)]*)(\)*)(\s)$/};function O(r){return(t,e)=>on(t)&&t.getTag()==="h"+r?"#".repeat(r)+" "+e(t):null}function Q(r,t){return bt(r)?kt(r,t,0):null}var ln=4;function kt(r,t,e){let o=[],n=r.getChildren(),c=0;for(let s of n)if(nn(s)){if(s.getChildrenSize()===1){let a=s.getFirstChild();if(bt(a)){o.push(kt(a,t,e+1));continue}}let i=" ".repeat(e*ln),l=r.getListType()==="bullet"?"- ":`${r.getStart()+c}. `;o.push(i+l+t(s)),c++}return o.join(`
2
- `)}function an(r,t){return rn(r)?"> "+t(r):null}function B(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 N(r){let t=B(r,e=>e.type);return{element:t.element||[],multilineElement:t["multiline-element"]||[],textFormat:t["text-format"]||[],textMatch:t["text-match"]||[]}}var F=/[!-/:-@[-`{-~\s]/,fn=/^\s{0,3}$/;function D(r){if(!sn(r))return!1;let t=r.getFirstChild();return t==null||r.getChildrenSize()===1&&cn(t)&&fn.test(t.getTextContent())}function It(r,t=!1){let e=N(r),o=[...e.multilineElement,...e.element],n=!t,c=e.textFormat.filter(s=>s.format.length===1).sort((s,i)=>s.format.includes("code")&&!i.format.includes("code")?1:!s.format.includes("code")&&i.format.includes("code")?-1:0);return s=>{let i=[],l=(s||un()).getChildren();return l.forEach((a,u)=>{let p=mn(a,o,c,e.textMatch);p!=null&&i.push(n&&u>0&&!D(a)&&!D(l[u-1])?`
3
- `.concat(p):p)}),i.join(`
4
- `)}}function mn(r,t,e,o){for(let n of t){if(!n.export)continue;let c=n.export(r,s=>K(s,e,o));if(c!=null)return c}return P(r)?K(r,e,o):Ft(r)?r.getTextContent():null}function K(r,t,e,o,n){let c=[],s=r.getChildren();o||(o=[]),n||(n=[]);t:for(let i of s){for(let l of e){if(!l.export)continue;let a=l.export(i,u=>K(u,t,e,o,[...n,...o]),(u,p)=>Ot(u,p,t,o,n));if(a!=null){c.push(a);continue t}}dn(i)?c.push(`
5
- `):H(i)?c.push(Ot(i,i.getTextContent(),t,o,n)):P(i)?c.push(K(i,t,e,o,n)):Ft(i)&&c.push(i.getTextContent())}return c.join("")}function Ot(r,t,e,o,n){let c=t.trim(),s=c;r.hasFormat("code")||(s=s.replace(/([*_`~\\])/g,"\\$1"));let i="",l="",a="",u=Nt(r,!0),p=Nt(r,!1),m=new Set;for(let g of e){let f=g.format[0],d=g.tag;v(r,f)&&!m.has(f)&&(m.add(f),(!v(u,f)||!o.find(h=>h.tag===d))&&(o.push({format:f,tag:d}),i+=d))}for(let g=0;g<o.length;g++){let f=o[g],d=v(r,f.format),h=v(p,f.format);if(d&&h)continue;let x=[...o];for(;x.length>g;){let E=x.pop();n&&E&&n.find(_=>_.tag===E.tag)||(E&&typeof E.tag=="string"&&(d?h||(a+=E.tag):l+=E.tag),o.pop())}break}return s=i+s+a,l+t.replace(c,()=>s)}function Nt(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(P(e)){if(!e.isInline())break;let o=t?e.getLastDescendant():e.getFirstDescendant();if(H(o))return o;e=t?e.getPreviousSibling():e.getNextSibling()}if(H(e))return e;if(!P(e))return null}return null}function v(r,t){return H(r)&&r.hasFormat(t)}import{$isListItemNode as gn,$isListNode as $t}from"@lexical/list";import{$isQuoteNode as hn}from"@lexical/rich-text";import{$findMatchingParent as xn}from"@lexical/utils";import{$createLineBreakNode as En,$createParagraphNode as _n,$createTextNode as Tn,$getRoot as wn,$getSelection as Cn,$isParagraphNode as Sn}from"lexical";import{$isTextNode as I}from"lexical";function Mt(r,t){let e=r.getTextContent(),o=pn(e,t);if(!o)return null;let n=o.index||0,c=n+o[0].length,s=t.transformersByTag[o[1]];return{endIndex:c,match:o,startIndex:n,transformer:s}}function pn(r,t){let e=r.match(t.openTagsRegExp);if(e==null)return null;for(let o of e){let n=o.replace(/^\s/,""),c=t.fullMatchRegExpByTag[n];if(c==null)continue;let s=r.match(c),i=t.transformersByTag[n];if(s!=null&&i!=null){if(i.intraword!==!1)return s;let{index:l=0}=s,a=r[l-1],u=r[l+s[0].length];if((!a||F.test(a))&&(!u||F.test(u)))return s}}return null}function At(r,t,e,o,n){let c=r.getTextContent(),s,i,l;if(n[0]===c?l=r:t===0?[l,s]=r.splitText(e):[i,l,s]=r.splitText(t,e),l.setTextContent(n[2]),o)for(let a of o.format)l.hasFormat(a)||l.toggleFormat(a);return{nodeAfter:s,nodeBefore:i,transformedNode:l}}function Dt(r,t){let e=r,o,n,c,s;for(let i of t){if(!i.replace||!i.importRegExp)continue;let l=e.getTextContent().match(i.importRegExp);if(!l)continue;let a=l.index||0,u=i.getEndIndex?i.getEndIndex(e,l):a+l[0].length;u!==!1&&(o===void 0||n===void 0||a<o&&u>n)&&(o=a,n=u,c=i,s=l)}return o===void 0||n===void 0||c===void 0||s===void 0?null:{endIndex:n,match:s,startIndex:o,transformer:c}}function Lt(r,t,e,o,n){let c,s,i;if(t===0?[i,c]=r.splitText(e):[s,i,c]=r.splitText(t,e),!o.replace)return null;let l=i?o.replace(i,n):void 0;return{nodeAfter:c,nodeBefore:s,transformedNode:l||void 0}}function y(r,t,e){let o=Mt(r,t),n=Dt(r,e);if(o&&n&&(o.startIndex<=n.startIndex&&o.endIndex>=n.endIndex?n=null:o=null),o){let i=At(r,o.startIndex,o.endIndex,o.transformer,o.match);i.nodeAfter&&I(i.nodeAfter)&&!i.nodeAfter.hasFormat("code")&&y(i.nodeAfter,t,e),i.nodeBefore&&I(i.nodeBefore)&&!i.nodeBefore.hasFormat("code")&&y(i.nodeBefore,t,e),i.transformedNode&&I(i.transformedNode)&&!i.transformedNode.hasFormat("code")&&y(i.transformedNode,t,e)}else if(n){let i=Lt(r,n.startIndex,n.endIndex,n.transformer,n.match);if(!i)return;i.nodeAfter&&I(i.nodeAfter)&&!i.nodeAfter.hasFormat("code")&&y(i.nodeAfter,t,e),i.nodeBefore&&I(i.nodeBefore)&&!i.nodeBefore.hasFormat("code")&&y(i.nodeBefore,t,e),i.transformedNode&&I(i.transformedNode)&&!i.transformedNode.hasFormat("code")&&y(i.transformedNode,t,e)}let s=r.getTextContent().replace(/\\([*_`~])/g,"$1");r.setTextContent(s)}function Bt(r,t=!1){let e=N(r),o=bn(e.textFormat);return(n,c)=>{let s=n.split(`
6
- `),i=s.length,l=c||wn();l.clear();for(let u=0;u<i;u++){let p=s[u],[m,g]=Rn(s,u,e.multilineElement,l);if(m){u=g;continue}yn(p,l,e.element,o,e.textMatch)}let a=l.getChildren();for(let u of a)!t&&D(u)&&l.getChildrenSize()>1&&u.remove();Cn()!==null&&l.selectStart()}}function Rn(r,t,e,o){for(let n of e){let{handleImportAfterStartMatch:c,regExpEnd:s,regExpStart:i,replace:l}=n,a=r[t]?.match(i);if(!a)continue;if(c){let f=c({lines:r,rootNode:o,startLineIndex:t,startMatch:a,transformer:n});if(f===null)continue;if(f)return f}let u=typeof s=="object"&&"regExp"in s?s.regExp:s,p=s&&typeof s=="object"&&"optional"in s?s.optional:!s,m=t,g=r.length;for(;m<g;){let f=u?r[m]?.match(u):null;if(!f&&(!p||p&&m<g-1)){m++;continue}if(f&&t===m&&f.index===a.index){m++;continue}let d=[];if(f&&t===m)d.push(r[t].slice(a[0].length,-f[0].length));else for(let h=t;h<=m;h++){let x=r[h];if(h===t){let E=x.slice(a[0].length);d.push(E)}else if(h===m&&f){let E=x.slice(0,-f[0].length);d.push(E)}else d.push(x)}if(l(o,null,a,f,d,!0)!==!1)return[!0,m];break}}return[!1,t]}function yn(r,t,e,o,n){let c=Tn(r),s=_n();s.append(c),t.append(s);for(let{regExp:i,replace:l}of e){let a=r.match(i);if(a&&(c.setTextContent(r.slice(a[0].length)),l(s,[c],a,!0)!==!1))break}if(y(c,o,n),s.isAttached()&&r.length>0){let i=s.getPreviousSibling();if(Sn(i)||hn(i)||$t(i)){let l=i;if($t(i)){let a=i.getLastDescendant();a==null?l=null:l=xn(a,gn)}l!=null&&l.getTextContentSize()>0&&(l.splice(l.getChildrenSize(),0,[En(),...s.getChildren()]),s.remove())}}}function bn(r){let t={},e={},o=[],n="(?<![\\\\])";for(let c of r){let{tag:s}=c;t[s]=c;let i=s.replace(/([*^+])/g,"\\$1");o.push(i),s.length===1?e[s]=new RegExp(`(?<![\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?![\\\\${i}])`):e[s]=new RegExp(`(?<!\\\\)(${i})((\\\\${i})?.*?[^\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?!\\\\)`)}return{fullMatchRegExpByTag:e,openTagsRegExp:new RegExp(`${n}(${o.join("|")})`,"g"),transformersByTag:t}}import{$createRangeSelection as kn,$getSelection as J,$isLineBreakNode as On,$isRangeSelection as Z,$isRootOrShadowRoot as Pt,$isTextNode as Ht,$setSelection as Nn}from"lexical";function Fn(r,t,e,o){let n=r.getParent();if(!Pt(n)||r.getFirstChild()!==t)return!1;let c=t.getTextContent();if(c[e-1]!==" ")return!1;for(let{regExp:s,replace:i}of o){let l=c.match(s);if(l&&l[0].length===(l[0].endsWith(" ")?e:e-1)){let a=t.getNextSiblings(),[u,p]=t.splitText(e);u?.remove();let m=p?[p,...a]:a;if(i(r,m,l,!1)!==!1)return!0}}return!1}function In(r,t,e,o){let n=r.getParent();if(!Pt(n)||r.getFirstChild()!==t)return!1;let c=t.getTextContent();if(c[e-1]!==" ")return!1;for(let{regExpEnd:s,regExpStart:i,replace:l}of o){if(s&&!("optional"in s)||s&&"optional"in s&&!s.optional)continue;let a=c.match(i);if(a&&a[0].length===(a[0].endsWith(" ")?e:e-1)){let u=t.getNextSiblings(),[p,m]=t.splitText(e);p?.remove();let g=m?[m,...u]:u;if(l(r,g,a,null,null,!1)!==!1)return!0}}return!1}function Mn(r,t,e){let o=r.getTextContent(),n=o[t-1],c=e[n];if(c==null)return!1;t<o.length&&(o=o.slice(0,t));for(let s of c){if(!s.replace||!s.regExp)continue;let i=o.match(s.regExp);if(i===null)continue;let l=i.index||0,a=l+i[0].length,u;return l===0?[u]=r.splitText(a):[,u]=r.splitText(l,a),u&&(u.selectNext(0,0),s.replace(u,i)),!0}return!1}function An(r,t,e){let o=r.getTextContent(),n=t-1,c=o[n],s=e[c];if(!s)return!1;for(let i of s){let{tag:l}=i,a=l.length,u=n-a+1;if(a>1&&!Kt(o,u,l,0,a)||o[u-1]===" ")continue;let p=o[n+1];if(i.intraword===!1&&p&&!F.test(p))continue;let m=r,g=m,f=vt(o,u,l),d=g;for(;f<0&&(d=d.getPreviousSibling())&&!On(d);)if(Ht(d)){let S=d.getTextContent();g=d,f=vt(S,S.length,l)}if(f<0||g===m&&f+a===u)continue;let h=g.getTextContent();if(f>0&&h[f-1]===c)continue;let x=h[f-1];if(i.intraword===!1&&x&&!F.test(x))continue;let E=m.getTextContent(),_=E.slice(0,u)+E.slice(n+1);m.setTextContent(_);let T=g===m?_:h;g.setTextContent(T.slice(0,f)+T.slice(f+a));let b=J(),w=kn();Nn(w);let L=n-a*(g===m?2:1)+1;w.anchor.set(g.__key,f,"text"),w.focus.set(m.__key,L,"text");for(let S of i.format)w.hasFormat(S)||w.formatText(S);w.anchor.set(w.focus.key,w.focus.offset,w.focus.type);for(let S of i.format)w.hasFormat(S)&&w.toggleFormat(S);return Z(b)&&(w.format=b.format),!0}return!1}function vt(r,t,e){let o=e.length;for(let n=t;n>=o;n--){let c=n-o;if(Kt(r,c,e,0,o)&&r[c+o]!==" ")return c}return-1}function Kt(r,t,e,o,n){for(let c=0;c<n;c++)if(r[t+c]!==e[o+c])return!1;return!0}function Ir(r,t=U){let e=N(t),o=B(e.textFormat,({tag:s})=>s[s.length-1]),n=B(e.textMatch,({trigger:s})=>s);for(let s of t){let i=s.type;if(i==="element"||i==="text-match"||i==="multiline-element"){let l=s.dependencies;for(let a of l)if(!r.hasNode(a))throw new Error("MarkdownShortcuts: missing dependency %s for transformer. Ensure node dependency is included in editor initial config."+a.getType())}}let c=(s,i,l)=>{Fn(s,i,l,e.element)||In(s,i,l,e.multilineElement)||Mn(i,l,n)||An(i,l,o)};return r.registerUpdateListener(({dirtyLeaves:s,editorState:i,prevEditorState:l,tags:a})=>{if(a.has("collaboration")||a.has("historic")||r.isComposing())return;let u=i.read(J),p=l.read(J);if(!Z(p)||!Z(u)||!u.isCollapsed()||u.is(p))return;let m=u.anchor.key,g=u.anchor.offset,f=i._nodeMap.get(m);!Ht(f)||!s.has(m)||g!==1&&g>p.anchor.offset+1||r.update(()=>{if(f.hasFormat("code"))return;let d=f.getParent();d!==null&&c(d,f,u.anchor.offset)})})}import{$createListItemNode as Dn,$createListNode as Ln,$isListItemNode as $n,$isListNode as M,ListItemNode as et,ListNode as nt}from"@lexical/list";import{$createHeadingNode as Bn,$createQuoteNode as vn,$isHeadingNode as Pn,$isQuoteNode as Ut,HeadingNode as Hn,QuoteNode as Kn}from"@lexical/rich-text";import{$createLineBreakNode as Un}from"lexical";var Vt=/^[\t ]*$/,Yt=/^(\s*)(\d+)\.\s/,jt=/^(\s*)[-*+]\s/,Wt=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,tt=/^(#{1,6})\s/,qt=/^>\s/,Vn=/^[ \t]*(\\`\\`\\`|```)(\w+)?/,Xt=/[ \t]*(\\`\\`\\`|```)$/,Xn=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,Gn=/^\|(.+)\|\s?$/,zn=/^(\| ?:?-*:? ?)+\|\s?$/,Gt=/^[ \t]*<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,zt=/^[ \t]*<\/[a-z_][\w-]*\s*>/i,Yn=r=>(t,e,o)=>{let n=r(o);n.append(...e),t.replace(n),n.select(0,0)},Qt=4;function jn(r){let t=r.match(/\t/g),e=r.match(/ /g),o=0;return t&&(o+=t.length),e&&(o+=Math.floor(e.length/Qt)),o}var ot=r=>(t,e,o)=>{let n=t.getPreviousSibling(),c=t.getNextSibling(),s=Dn(r==="check"?o[3]==="x":void 0);if(M(c)&&c.getListType()===r){let l=c.getFirstChild();l!==null?l.insertBefore(s):c.append(s),t.remove()}else if(M(n)&&n.getListType()===r)n.append(s),t.remove();else{let l=Ln(r,r==="number"?Number(o[2]):void 0);l.append(s),t.replace(l)}s.append(...e),s.select(0,0);let i=jn(o[1]);i&&s.setIndent(i)},V=(r,t,e)=>{let o=[],n=r.getChildren(),c=0;for(let s of n)if($n(s)){if(s.getChildrenSize()===1){let u=s.getFirstChild();if(M(u)){o.push(V(u,t,e+1));continue}}let i=" ".repeat(e*Qt),l=r.getListType(),a=l==="number"?`${r.getStart()+c}. `:l==="check"?`- [${s.getChecked()?"x":" "}] `:"- ";o.push(i+a+t(s)),c++}return o.join(`
7
- `)},Jt={type:"element",dependencies:[Hn],export:(r,t)=>{if(!Pn(r))return null;let e=Number(r.getTag().slice(1));return"#".repeat(e)+" "+t(r)},regExp:tt,replace:Yn(r=>{let t="h"+r[1].length;return Bn(t)})},Zt={type:"element",dependencies:[Kn],export:(r,t)=>{if(!Ut(r))return null;let e=t(r).split(`
8
- `),o=[];for(let n of e)o.push("> "+n);return o.join(`
9
- `)},regExp:qt,replace:(r,t,e,o)=>{if(o){let c=r.getPreviousSibling();if(Ut(c)){c.splice(c.getChildrenSize(),0,[Un(),...t]),c.select(0,0),r.remove();return}}let n=vn();n.append(...t),r.replace(n),n.select(0,0)}},te={type:"element",dependencies:[nt,et],export:(r,t)=>M(r)?V(r,t,0):null,regExp:jt,replace:ot("bullet")},Wn={type:"element",dependencies:[nt,et],export:(r,t)=>M(r)?V(r,t,0):null,regExp:Wt,replace:ot("check")},ee={type:"element",dependencies:[nt,et],export:(r,t)=>M(r)?V(r,t,0):null,regExp:Yt,replace:ot("number")},ne={type:"text-format",format:["code"],tag:"`"},oe={type:"text-format",format:["highlight"],tag:"=="},re={type:"text-format",format:["bold","italic"],tag:"***"},ie={type:"text-format",format:["bold","italic"],intraword:!1,tag:"___"},se={type:"text-format",format:["bold"],tag:"**"},ce={type:"text-format",format:["bold"],intraword:!1,tag:"__"},le={type:"text-format",format:["strikethrough"],tag:"~~"},ae={type:"text-format",format:["italic"],tag:"*"},fe={type:"text-format",format:["italic"],intraword:!1,tag:"_"};function ue(r,t){let e=r.split(`
10
- `),o=!1,n=[],c=0;for(let s=0;s<e.length;s++){let i=e[s],l=n[n.length-1];if(Xn.test(i)){n.push(i);continue}if(Xt.test(i)){c===0&&(o=!0),c===1&&(o=!1),c>0&&c--,n.push(i);continue}if(Vn.test(i)){o=!0,c++,n.push(i);continue}if(o){n.push(i);continue}Vt.test(i)||Vt.test(l)||!l||tt.test(l)||tt.test(i)||qt.test(i)||Yt.test(i)||jt.test(i)||Wt.test(i)||Gn.test(i)||zn.test(i)||!t||Gt.test(i)||zt.test(i)||Gt.test(l)||zt.test(l)||Xt.test(l)?n.push(i):n[n.length-1]=l+" "+i.trim()}return n.join(`
11
- `)}var qn=[Jt,Zt,te,ee],Qn=[],Jn=[ne,re,ie,se,ce,oe,ae,fe,le],Zn=[],U=[...qn,...Qn,...Jn,...Zn];function Hr(r,t=U,e,o=!1,n=!0){let c=o?r:ue(r,n);return Bt(t,o)(c,e)}function Kr(r=U,t,e=!1){return It(r,e)(t)}export{Ir as a,Hr as b,Kr as c,st as d,ro as e,fo as f,Re as g,G as h,lt as i,ko as j,Ze as k,Oo as l,Rt as m,Ao as n,Do as o,Lo as p};
12
- //# sourceMappingURL=chunk-FTT5KJ6W.js.map