@payloadcms/richtext-lexical 3.12.0 → 3.12.1-canary.33ecab2
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.
- package/dist/exports/client/Field-DTQOXLGX.js +2 -0
- package/dist/exports/client/Field-DTQOXLGX.js.map +7 -0
- package/dist/exports/client/chunk-JSFV2MHZ.js +2 -0
- package/dist/exports/client/chunk-JSFV2MHZ.js.map +7 -0
- package/dist/exports/client/chunk-WCORQHZQ.js +12 -0
- package/dist/exports/client/chunk-WCORQHZQ.js.map +7 -0
- package/dist/exports/client/{component-NSAU5Y76.js → component-OQJ5KXCS.js} +2 -2
- package/dist/exports/client/index.js +11 -11
- package/dist/exports/client/index.js.map +3 -3
- package/dist/features/blocks/server/markdownTransformer.d.ts.map +1 -1
- package/dist/features/blocks/server/markdownTransformer.js +1 -2
- package/dist/features/blocks/server/markdownTransformer.js.map +1 -1
- package/dist/features/link/markdownTransformer.d.ts.map +1 -1
- package/dist/features/link/markdownTransformer.js +6 -11
- package/dist/features/link/markdownTransformer.js.map +1 -1
- package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.d.ts +5 -1
- package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.d.ts.map +1 -1
- package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.js +42 -26
- package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.js.map +1 -1
- package/dist/features/upload/client/drawer/index.d.ts.map +1 -1
- package/dist/features/upload/client/drawer/index.js +24 -0
- package/dist/features/upload/client/drawer/index.js.map +1 -1
- package/dist/field/rscEntry.d.ts.map +1 -1
- package/dist/field/rscEntry.js +3 -0
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/lexical/LexicalEditor.js +5 -3
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/ui/ContentEditable.d.ts +3 -1
- package/dist/lexical/ui/ContentEditable.d.ts.map +1 -1
- package/dist/lexical/ui/ContentEditable.js +18 -7
- package/dist/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/packages/@lexical/markdown/MarkdownExport.js +68 -14
- package/dist/packages/@lexical/markdown/MarkdownExport.js.map +1 -1
- package/dist/packages/@lexical/markdown/MarkdownImport.d.ts +6 -1
- package/dist/packages/@lexical/markdown/MarkdownImport.d.ts.map +1 -1
- package/dist/packages/@lexical/markdown/MarkdownImport.js +3 -119
- package/dist/packages/@lexical/markdown/MarkdownImport.js.map +1 -1
- package/dist/packages/@lexical/markdown/MarkdownTransformers.d.ts +4 -1
- package/dist/packages/@lexical/markdown/MarkdownTransformers.d.ts.map +1 -1
- package/dist/packages/@lexical/markdown/MarkdownTransformers.js.map +1 -1
- package/dist/packages/@lexical/markdown/importTextFormatTransformer.d.ts +22 -0
- package/dist/packages/@lexical/markdown/importTextFormatTransformer.d.ts.map +1 -0
- package/dist/packages/@lexical/markdown/importTextFormatTransformer.js +88 -0
- package/dist/packages/@lexical/markdown/importTextFormatTransformer.js.map +1 -0
- package/dist/packages/@lexical/markdown/importTextMatchTransformer.d.ts +21 -0
- package/dist/packages/@lexical/markdown/importTextMatchTransformer.d.ts.map +1 -0
- package/dist/packages/@lexical/markdown/importTextMatchTransformer.js +54 -0
- package/dist/packages/@lexical/markdown/importTextMatchTransformer.js.map +1 -0
- package/dist/packages/@lexical/markdown/importTextTransformers.d.ts +18 -0
- package/dist/packages/@lexical/markdown/importTextTransformers.d.ts.map +1 -0
- package/dist/packages/@lexical/markdown/importTextTransformers.js +55 -0
- package/dist/packages/@lexical/markdown/importTextTransformers.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/jsx/lexicalMarkdownCopy.d.ts.map +1 -1
- package/dist/utilities/jsx/lexicalMarkdownCopy.js +11 -6
- package/dist/utilities/jsx/lexicalMarkdownCopy.js.map +1 -1
- package/package.json +7 -7
- package/dist/exports/client/Field-7XFZE2MU.js +0 -2
- package/dist/exports/client/Field-7XFZE2MU.js.map +0 -7
- package/dist/exports/client/chunk-H3D3IU3G.js +0 -2
- package/dist/exports/client/chunk-H3D3IU3G.js.map +0 -7
- package/dist/exports/client/chunk-XOABLBHB.js +0 -12
- package/dist/exports/client/chunk-XOABLBHB.js.map +0 -7
- /package/dist/exports/client/{component-NSAU5Y76.js.map → component-OQJ5KXCS.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownImport.js","names":["$isListItemNode","$isListNode","$isQuoteNode","$findMatchingParent","$createLineBreakNode","$createParagraphNode","$createTextNode","$getRoot","$getSelection","$isParagraphNode","IS_APPLE_WEBKIT","IS_IOS","IS_SAFARI","isEmptyParagraph","PUNCTUATION_OR_SPACE","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","text","elementTransformers","textMatchTransformers","textNode","elementNode","append","setTextContent","importTextFormatTransformers","isAttached","previousNode","getPreviousSibling","targetNode","lastDescendant","getLastDescendant","getTextContentSize","splice","textContent","getTextContent","findOutermostMatch","importTextMatchTransformers","currentNode","leadingNode","remainderNode","startIndex","endIndex","splitText","transformersByTag","format","hasFormat","toggleFormat","textNode_","mainLoop","importRegExp","getEndIndex","newTextNode","replaceNode","textTransformersIndex","openTagsMatch","openTagsRegExp","tag","fullMatchRegExp","fullMatchRegExpByTag","fullMatch","intraword","beforeChar","afterChar","test","textTransformers","escapeRegExp","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, TextNode } 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 { isEmptyParagraph, PUNCTUATION_OR_SPACE, transformersByType } from './utils.js'\n\ntype 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 if (i === startLineIndex) {\n const text = lines[i].slice(startMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else if (i === endLineIndex && endMatch) {\n const text = lines[i].slice(0, -endMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else {\n linesInBetween.push(lines[i])\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 importTextFormatTransformers(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\n// Processing text content and replaces text format tags.\n// It takes outermost tag match and its content, creates text node with\n// format based on tag and then recursively executed over node's content\n//\n// E.g. for \"*Hello **world**!*\" string it will create text node with\n// \"Hello **world**!\" content and italic format and run recursively over\n// its content to transform \"**world**\" part\nfunction importTextFormatTransformers(\n textNode: TextNode,\n textFormatTransformersIndex: TextFormatTransformersIndex,\n textMatchTransformers: Array<TextMatchTransformer>,\n) {\n const textContent = textNode.getTextContent()\n const match = findOutermostMatch(textContent, textFormatTransformersIndex)\n\n if (!match) {\n // Once text format processing is done run text match transformers, as it\n // only can span within single text node (unline formats that can cover multiple nodes)\n importTextMatchTransformers(textNode, textMatchTransformers)\n return\n }\n\n let currentNode, leadingNode, remainderNode\n\n // If matching full content there's no need to run splitText and can reuse existing textNode\n // to update its content and apply format. E.g. for **_Hello_** string after applying bold\n // format (**) it will reuse the same text node to apply italic (_)\n if (match[0] === textContent) {\n currentNode = textNode\n } else {\n const startIndex = match.index || 0\n const endIndex = startIndex + match[0].length\n\n if (startIndex === 0) {\n ;[currentNode, remainderNode] = textNode.splitText(endIndex)\n } else {\n ;[leadingNode, currentNode, remainderNode] = textNode.splitText(startIndex, endIndex)\n }\n }\n\n currentNode.setTextContent(match[2])\n const transformer = textFormatTransformersIndex.transformersByTag[match[1]]\n\n if (transformer) {\n for (const format of transformer.format) {\n if (!currentNode.hasFormat(format)) {\n currentNode.toggleFormat(format)\n }\n }\n }\n\n // Recursively run over inner text if it's not inline code\n if (!currentNode.hasFormat('code')) {\n importTextFormatTransformers(currentNode, textFormatTransformersIndex, textMatchTransformers)\n }\n\n // Run over leading/remaining text if any\n if (leadingNode) {\n importTextFormatTransformers(leadingNode, textFormatTransformersIndex, textMatchTransformers)\n }\n\n if (remainderNode) {\n importTextFormatTransformers(remainderNode, textFormatTransformersIndex, textMatchTransformers)\n }\n}\n\nfunction importTextMatchTransformers(\n textNode_: TextNode,\n textMatchTransformers: Array<TextMatchTransformer>,\n) {\n let textNode = textNode_\n\n mainLoop: while (textNode) {\n for (const transformer of textMatchTransformers) {\n if (!transformer.replace || !transformer.importRegExp) {\n continue\n }\n const match = textNode.getTextContent().match(transformer.importRegExp)\n\n if (!match) {\n continue\n }\n\n const startIndex = match.index || 0\n const endIndex = transformer.getEndIndex\n ? transformer.getEndIndex(textNode, match)\n : startIndex + match[0].length\n\n if (endIndex === false) {\n continue\n }\n\n let newTextNode, replaceNode\n\n if (startIndex === 0) {\n ;[replaceNode, textNode] = textNode.splitText(endIndex)\n } else {\n ;[, replaceNode, newTextNode] = textNode.splitText(startIndex, endIndex)\n }\n\n if (newTextNode) {\n importTextMatchTransformers(newTextNode, textMatchTransformers)\n }\n transformer.replace(replaceNode, match)\n continue mainLoop\n }\n\n break\n }\n}\n\n// Finds first \"<tag>content<tag>\" match that is not nested into another tag\nfunction findOutermostMatch(\n textContent: string,\n textTransformersIndex: TextFormatTransformersIndex,\n): null | RegExpMatchArray {\n const openTagsMatch = textContent.match(textTransformersIndex.openTagsRegExp)\n\n if (openTagsMatch == null) {\n return null\n }\n\n for (const match of openTagsMatch) {\n // Open tags reg exp might capture leading space so removing it\n // before using match to find transformer\n const tag = match.replace(/^\\s/, '')\n const fullMatchRegExp = textTransformersIndex.fullMatchRegExpByTag[tag]\n if (fullMatchRegExp == null) {\n continue\n }\n\n const fullMatch = textContent.match(fullMatchRegExp)\n const transformer = textTransformersIndex.transformersByTag[tag]\n if (fullMatch != null && transformer != null) {\n if (transformer.intraword !== false) {\n return fullMatch\n }\n\n // For non-intraword transformers checking if it's within a word\n // or surrounded with space/punctuation/newline\n const { index = 0 } = fullMatch\n const beforeChar = textContent[index - 1]\n const afterChar = textContent[index + fullMatch[0].length]\n\n if (\n (!beforeChar || PUNCTUATION_OR_SPACE.test(beforeChar)) &&\n (!afterChar || PUNCTUATION_OR_SPACE.test(afterChar))\n ) {\n return fullMatch\n }\n }\n }\n\n return null\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,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,EAAc,IAC9D,MACAV,cAAA,CAAea,IAAI,CAAC,OACpB,KACF;IAEFzB;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","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 if (i === startLineIndex) {\n const text = lines[i].slice(startMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else if (i === endLineIndex && endMatch) {\n const text = lines[i].slice(0, -endMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else {\n linesInBetween.push(lines[i])\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,SAASC,YAAY,QAAQ;AAC7B,SAASC,mBAAmB,QAAQ;AACpC,SACEC,oBAAoB,EACpBC,oBAAoB,EACpBC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,gBAAgB,QACX;AAUP,SAASC,eAAe,EAAEC,MAAM,EAAEC,SAAS,QAAQ;AACnD,SAASC,sBAAsB,QAAQ;AACvC,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ;AAQrD;;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AAW,GAC3B;QACD8B,WAAA,CAAY3B,MAAM;MACpB;IACF;EACF;AACF;AAEA,SAASvB,kCACP6D,gBAA8C;EAE9C,MAAMC,iBAAA,GAA2D,CAAC;EAClE,MAAMC,oBAAA,GAA+C,CAAC;EACtD,MAAMC,cAAA,GAA2B,EAAE;EACnC,MAAMC,YAAA,GAAe,aAAa;EAElC,KAAK,MAAMrC,WAAA,IAAeiC,gBAAA,EAAkB;IAC1C,MAAM;MAAEK;IAAG,CAAE,GAAGtC,WAAA;IAChBkC,iBAAiB,CAACI,GAAA,CAAI,GAAGtC,WAAA;IACzB,MAAMuC,SAAA,GAAYD,GAAA,CAAIlC,OAAO,CAAC,YAAY;IAC1CgC,cAAA,CAAepB,IAAI,CAACuB,SAAA;IAEpB,IAAI5E,SAAA,IAAaD,MAAA,IAAUD,eAAA,EAAiB;MAC1C0E,oBAAoB,CAACG,GAAA,CAAI,GAAG,IAAIE,MAAA,CAC9B,IAAID,SAAA,QAAiBA,SAAA,cAAuBA,SAAA,QAAiBA,SAAA,MAAeA,SAAA,GAAY;IAE5F,OAAO;MACLJ,oBAAoB,CAACG,GAAA,CAAI,GAAG,IAAIE,MAAA,CAC9B,YAAYD,SAAA,MAAeA,SAAA,UAAmBA,SAAA,UAAmBA,SAAA,YAAqBA,SAAA,gCAAyCA,SAAA,YAAqBA,SAAA,IAAa;IAErK;EACF;EAEA,OAAO;IACL;IACAJ,oBAAA;IACA;IACAC,cAAA,EAAgB,IAAII,MAAA,CAClB,CAAC7E,SAAA,IAAaD,MAAA,IAAUD,eAAA,GAAkB,KAAK,GAAG4E,YAAA,EAAc,IAC9D,MACAD,cAAA,CAAeK,IAAI,CAAC,OACpB,KACF;IAEFP;EACF;AACF","ignoreList":[]}
|
|
@@ -117,8 +117,11 @@ export type TextMatchTransformer = Readonly<{
|
|
|
117
117
|
regExp: RegExp;
|
|
118
118
|
/**
|
|
119
119
|
* Determines how the matched markdown text should be transformed into a node during the markdown import process
|
|
120
|
+
*
|
|
121
|
+
* @returns nothing, or a TextNode that may be a child of the new node that is created.
|
|
122
|
+
* If a TextNode is returned, text format matching will be applied to it (e.g. bold, italic, etc.)
|
|
120
123
|
*/
|
|
121
|
-
replace?: (node: TextNode, match: RegExpMatchArray) => void;
|
|
124
|
+
replace?: (node: TextNode, match: RegExpMatchArray) => TextNode | void;
|
|
122
125
|
/**
|
|
123
126
|
* 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.
|
|
124
127
|
* If the trigger is matched, the `regExp` will be used to match the text in the second step.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownTransformers.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/MarkdownTransformers.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAoBxF,MAAM,MAAM,WAAW,GACnB,kBAAkB,GAClB,2BAA2B,GAC3B,qBAAqB,GACrB,oBAAoB,CAAA;AAExB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;IACvC;;;;OAIG;IACH,MAAM,EAAE,CACN,IAAI,EAAE,WAAW,EAEjB,gBAAgB,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,MAAM,KAC5C,IAAI,GAAG,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,OAAO,EAAE,CACP,UAAU,EAAE,WAAW,EACvB,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,EAC5B,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,EAAE,OAAO,KACd,OAAO,GAAG,IAAI,CAAA;IACnB,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,2BA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,OAAO,CAAA;IACnB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,aAAa,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;IACvC;;OAEG;IACH,MAAM,CAAC,EAAE,CACP,IAAI,EAAE,WAAW,EAEjB,cAAc,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,MAAM,EAE7C,YAAY,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,KAAK,MAAM,KAC1D,IAAI,GAAG,MAAM,CAAA;IAClB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,KAAK,KAAK,GAAG,MAAM,CAAA;IACzE;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd
|
|
1
|
+
{"version":3,"file":"MarkdownTransformers.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/MarkdownTransformers.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAoBxF,MAAM,MAAM,WAAW,GACnB,kBAAkB,GAClB,2BAA2B,GAC3B,qBAAqB,GACrB,oBAAoB,CAAA;AAExB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;IACvC;;;;OAIG;IACH,MAAM,EAAE,CACN,IAAI,EAAE,WAAW,EAEjB,gBAAgB,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,MAAM,KAC5C,IAAI,GAAG,MAAM,CAAA;IAClB,MAAM,EAAE,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;AAED,eAAO,MAAM,cAAc,EAAE,kBAQ5B,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,kBAQxB,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,kBAQ1B,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,qBAIzB,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,qBAIvB,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,qBAI9B,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,qBAKpC,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,qBAIvB,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,qBAK7B,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,qBAI3B,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,qBAIzB,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,qBAK/B,CAAA;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,wBAAwB,UAAQ,GAAG,MAAM,CAmDzF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownTransformers.js","names":["$createListItemNode","$createListNode","$isListItemNode","$isListNode","ListItemNode","ListNode","$createHeadingNode","$createQuoteNode","$isHeadingNode","$isQuoteNode","HeadingNode","QuoteNode","$createLineBreakNode","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","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","i","lastLine","test"],"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 replace?: (node: TextNode, match: RegExpMatchArray) => 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 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?$/\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 = false): string {\n const lines = input.split('\\n')\n let inCodeBlock = false\n const sanitizedLines: string[] = []\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 // Detect the start or end of a code block\n if (CODE_START_REGEX.test(line) || CODE_END_REGEX.test(line)) {\n inCodeBlock = !inCodeBlock\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 line === '' ||\n 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 ) {\n sanitizedLines.push(line)\n } else {\n sanitizedLines[sanitizedLines.length - 1] = lastLine + line\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,EACZC,WAAW,EACXC,SAAS,QACJ;AACP,SAASC,oBAAoB,QAAQ;AA2JrC,MAAMC,kBAAA,GAAqB;AAC3B,MAAMC,oBAAA,GAAuB;AAC7B,MAAMC,gBAAA,GAAmB;AACzB,MAAMC,aAAA,GAAgB;AACtB,MAAMC,WAAA,GAAc;AACpB,MAAMC,gBAAA,GAAmB;AACzB,MAAMC,cAAA,GAAiB;AACvB,MAAMC,sBAA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,kBAAA,CAAmBgG,IAAI,CAACzB,IAAA,KACxBtE,oBAAA,CAAqB+F,IAAI,CAACzB,IAAA,KAC1BrE,gBAAA,CAAiB8F,IAAI,CAACzB,IAAA,KACtB/D,iBAAA,CAAkBwF,IAAI,CAACzB,IAAA,KACvB9D,yBAAA,CAA0BuF,IAAI,CAACzB,IAAA,KAC/B,CAACoB,wBAAA,EACD;MACAE,cAAA,CAAexC,IAAI,CAACkB,IAAA;IACtB,OAAO;MACLsB,cAAc,CAACA,cAAA,CAAepE,MAAM,GAAG,EAAE,GAAGsE,QAAA,GAAWxB,IAAA;IACzD;EACF;EAEA,OAAOsB,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","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","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","i","lastLine","test"],"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 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?$/\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 = false): string {\n const lines = input.split('\\n')\n let inCodeBlock = false\n const sanitizedLines: string[] = []\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 // Detect the start or end of a code block\n if (CODE_START_REGEX.test(line) || CODE_END_REGEX.test(line)) {\n inCodeBlock = !inCodeBlock\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 line === '' ||\n 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 ) {\n sanitizedLines.push(line)\n } else {\n sanitizedLines[sanitizedLines.length - 1] = lastLine + line\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,EACZC,WAAW,EACXC,SAAS,QACJ;AACP,SAASC,oBAAoB,QAAQ;AA8JrC,MAAMC,kBAAA,GAAqB;AAC3B,MAAMC,oBAAA,GAAuB;AAC7B,MAAMC,gBAAA,GAAmB;AACzB,MAAMC,aAAA,GAAgB;AACtB,MAAMC,WAAA,GAAc;AACpB,MAAMC,gBAAA,GAAmB;AACzB,MAAMC,cAAA,GAAiB;AACvB,MAAMC,sBAAA,GAAyB;AAC/B,MAAMC,iBAAA,GAAoB;AAC1B,MAAMC,yBAAA,GAA4B;AAElC,MAAMC,eAAA,GACJC,UAAA;EAEA,OAAO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AAI,CAACzB,IAAA,KACtB/D,iBAAA,CAAkBwF,IAAI,CAACzB,IAAA,KACvB9D,yBAAA,CAA0BuF,IAAI,CAACzB,IAAA,KAC/B,CAACoB,wBAAA,EACD;MACAE,cAAA,CAAexC,IAAI,CAACkB,IAAA;IACtB,OAAO;MACLsB,cAAc,CAACA,cAAA,CAAepE,MAAM,GAAG,EAAE,GAAGsE,QAAA,GAAWxB,IAAA;IACzD;EACF;EAEA,OAAOsB,cAAA,CAAenC,IAAI,CAAC;AAC7B","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { TextNode } from 'lexical';
|
|
9
|
+
import type { TextFormatTransformersIndex } from './MarkdownImport.js';
|
|
10
|
+
import type { TextFormatTransformer } from './MarkdownTransformers.js';
|
|
11
|
+
export declare function findOutermostTextFormatTransformer(textNode: TextNode, textFormatTransformersIndex: TextFormatTransformersIndex): {
|
|
12
|
+
endIndex: number;
|
|
13
|
+
match: RegExpMatchArray;
|
|
14
|
+
startIndex: number;
|
|
15
|
+
transformer: TextFormatTransformer;
|
|
16
|
+
} | null;
|
|
17
|
+
export declare function importTextFormatTransformer(textNode: TextNode, startIndex: number, endIndex: number, transformer: TextFormatTransformer, match: RegExpMatchArray): {
|
|
18
|
+
nodeAfter: TextNode | undefined;
|
|
19
|
+
nodeBefore: TextNode | undefined;
|
|
20
|
+
transformedNode: TextNode;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=importTextFormatTransformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importTextFormatTransformer.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/importTextFormatTransformer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAItE,wBAAgB,kCAAkC,CAChD,QAAQ,EAAE,QAAQ,EAClB,2BAA2B,EAAE,2BAA2B,GACvD;IACD,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,gBAAgB,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,qBAAqB,CAAA;CACnC,GAAG,IAAI,CAmBP;AA+CD,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,qBAAqB,EAClC,KAAK,EAAE,gBAAgB,GACtB;IACD,SAAS,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC/B,UAAU,EAAE,QAAQ,GAAG,SAAS,CAAA;IAChC,eAAe,EAAE,QAAQ,CAAA;CAC1B,CAkCA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/import { PUNCTUATION_OR_SPACE } from './utils.js';
|
|
8
|
+
export function findOutermostTextFormatTransformer(textNode, textFormatTransformersIndex) {
|
|
9
|
+
const textContent = textNode.getTextContent();
|
|
10
|
+
const match = findOutermostMatch(textContent, textFormatTransformersIndex);
|
|
11
|
+
if (!match) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const textFormatMatchStart = match.index || 0;
|
|
15
|
+
const textFormatMatchEnd = textFormatMatchStart + match[0].length;
|
|
16
|
+
const transformer = textFormatTransformersIndex.transformersByTag[match[1]];
|
|
17
|
+
return {
|
|
18
|
+
endIndex: textFormatMatchEnd,
|
|
19
|
+
match,
|
|
20
|
+
startIndex: textFormatMatchStart,
|
|
21
|
+
transformer
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// Finds first "<tag>content<tag>" match that is not nested into another tag
|
|
25
|
+
function findOutermostMatch(textContent, textTransformersIndex) {
|
|
26
|
+
const openTagsMatch = textContent.match(textTransformersIndex.openTagsRegExp);
|
|
27
|
+
if (openTagsMatch == null) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
for (const match of openTagsMatch) {
|
|
31
|
+
// Open tags reg exp might capture leading space so removing it
|
|
32
|
+
// before using match to find transformer
|
|
33
|
+
const tag = match.replace(/^\s/, '');
|
|
34
|
+
const fullMatchRegExp = textTransformersIndex.fullMatchRegExpByTag[tag];
|
|
35
|
+
if (fullMatchRegExp == null) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const fullMatch = textContent.match(fullMatchRegExp);
|
|
39
|
+
const transformer = textTransformersIndex.transformersByTag[tag];
|
|
40
|
+
if (fullMatch != null && transformer != null) {
|
|
41
|
+
if (transformer.intraword !== false) {
|
|
42
|
+
return fullMatch;
|
|
43
|
+
}
|
|
44
|
+
// For non-intraword transformers checking if it's within a word
|
|
45
|
+
// or surrounded with space/punctuation/newline
|
|
46
|
+
const {
|
|
47
|
+
index = 0
|
|
48
|
+
} = fullMatch;
|
|
49
|
+
const beforeChar = textContent[index - 1];
|
|
50
|
+
const afterChar = textContent[index + fullMatch[0].length];
|
|
51
|
+
if ((!beforeChar || PUNCTUATION_OR_SPACE.test(beforeChar)) && (!afterChar || PUNCTUATION_OR_SPACE.test(afterChar))) {
|
|
52
|
+
return fullMatch;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
export function importTextFormatTransformer(textNode, startIndex, endIndex, transformer, match) {
|
|
59
|
+
const textContent = textNode.getTextContent();
|
|
60
|
+
// No text matches - we can safely process the text format match
|
|
61
|
+
let nodeAfter, nodeBefore, transformedNode;
|
|
62
|
+
// If matching full content there's no need to run splitText and can reuse existing textNode
|
|
63
|
+
// to update its content and apply format. E.g. for **_Hello_** string after applying bold
|
|
64
|
+
// format (**) it will reuse the same text node to apply italic (_)
|
|
65
|
+
if (match[0] === textContent) {
|
|
66
|
+
transformedNode = textNode;
|
|
67
|
+
} else {
|
|
68
|
+
if (startIndex === 0) {
|
|
69
|
+
[transformedNode, nodeAfter] = textNode.splitText(endIndex);
|
|
70
|
+
} else {
|
|
71
|
+
[nodeBefore, transformedNode, nodeAfter] = textNode.splitText(startIndex, endIndex);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
transformedNode.setTextContent(match[2]);
|
|
75
|
+
if (transformer) {
|
|
76
|
+
for (const format of transformer.format) {
|
|
77
|
+
if (!transformedNode.hasFormat(format)) {
|
|
78
|
+
transformedNode.toggleFormat(format);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
nodeAfter,
|
|
84
|
+
nodeBefore,
|
|
85
|
+
transformedNode
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=importTextFormatTransformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importTextFormatTransformer.js","names":["PUNCTUATION_OR_SPACE","findOutermostTextFormatTransformer","textNode","textFormatTransformersIndex","textContent","getTextContent","match","findOutermostMatch","textFormatMatchStart","index","textFormatMatchEnd","length","transformer","transformersByTag","endIndex","startIndex","textTransformersIndex","openTagsMatch","openTagsRegExp","tag","replace","fullMatchRegExp","fullMatchRegExpByTag","fullMatch","intraword","beforeChar","afterChar","test","importTextFormatTransformer","nodeAfter","nodeBefore","transformedNode","splitText","setTextContent","format","hasFormat","toggleFormat"],"sources":["../../../../src/packages/@lexical/markdown/importTextFormatTransformer.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 { TextNode } from 'lexical'\n\nimport type { TextFormatTransformersIndex } from './MarkdownImport.js'\nimport type { TextFormatTransformer } from './MarkdownTransformers.js'\n\nimport { PUNCTUATION_OR_SPACE } from './utils.js'\n\nexport function findOutermostTextFormatTransformer(\n textNode: TextNode,\n textFormatTransformersIndex: TextFormatTransformersIndex,\n): {\n endIndex: number\n match: RegExpMatchArray\n startIndex: number\n transformer: TextFormatTransformer\n} | null {\n const textContent = textNode.getTextContent()\n const match = findOutermostMatch(textContent, textFormatTransformersIndex)\n\n if (!match) {\n return null\n }\n\n const textFormatMatchStart: number = match.index || 0\n const textFormatMatchEnd = textFormatMatchStart + match[0].length\n\n const transformer: TextFormatTransformer = textFormatTransformersIndex.transformersByTag[match[1]]\n\n return {\n endIndex: textFormatMatchEnd,\n match,\n startIndex: textFormatMatchStart,\n transformer,\n }\n}\n\n// Finds first \"<tag>content<tag>\" match that is not nested into another tag\nfunction findOutermostMatch(\n textContent: string,\n textTransformersIndex: TextFormatTransformersIndex,\n): null | RegExpMatchArray {\n const openTagsMatch = textContent.match(textTransformersIndex.openTagsRegExp)\n\n if (openTagsMatch == null) {\n return null\n }\n\n for (const match of openTagsMatch) {\n // Open tags reg exp might capture leading space so removing it\n // before using match to find transformer\n const tag = match.replace(/^\\s/, '')\n const fullMatchRegExp = textTransformersIndex.fullMatchRegExpByTag[tag]\n if (fullMatchRegExp == null) {\n continue\n }\n\n const fullMatch = textContent.match(fullMatchRegExp)\n const transformer = textTransformersIndex.transformersByTag[tag]\n if (fullMatch != null && transformer != null) {\n if (transformer.intraword !== false) {\n return fullMatch\n }\n\n // For non-intraword transformers checking if it's within a word\n // or surrounded with space/punctuation/newline\n const { index = 0 } = fullMatch\n const beforeChar = textContent[index - 1]\n const afterChar = textContent[index + fullMatch[0].length]\n\n if (\n (!beforeChar || PUNCTUATION_OR_SPACE.test(beforeChar)) &&\n (!afterChar || PUNCTUATION_OR_SPACE.test(afterChar))\n ) {\n return fullMatch\n }\n }\n }\n\n return null\n}\n\nexport function importTextFormatTransformer(\n textNode: TextNode,\n startIndex: number,\n endIndex: number,\n transformer: TextFormatTransformer,\n match: RegExpMatchArray,\n): {\n nodeAfter: TextNode | undefined // If split\n nodeBefore: TextNode | undefined // If split\n transformedNode: TextNode\n} {\n const textContent = textNode.getTextContent()\n\n // No text matches - we can safely process the text format match\n let nodeAfter, nodeBefore, transformedNode\n\n // If matching full content there's no need to run splitText and can reuse existing textNode\n // to update its content and apply format. E.g. for **_Hello_** string after applying bold\n // format (**) it will reuse the same text node to apply italic (_)\n if (match[0] === textContent) {\n transformedNode = textNode\n } else {\n if (startIndex === 0) {\n ;[transformedNode, nodeAfter] = textNode.splitText(endIndex)\n } else {\n ;[nodeBefore, transformedNode, nodeAfter] = textNode.splitText(startIndex, endIndex)\n }\n }\n\n transformedNode.setTextContent(match[2])\n\n if (transformer) {\n for (const format of transformer.format) {\n if (!transformedNode.hasFormat(format)) {\n transformedNode.toggleFormat(format)\n }\n }\n }\n\n return {\n nodeAfter,\n nodeBefore,\n transformedNode,\n }\n}\n"],"mappings":"AAAA;;;;;;GAaA,SAASA,oBAAoB,QAAQ;AAErC,OAAO,SAASC,mCACdC,QAAkB,EAClBC,2BAAwD;EAOxD,MAAMC,WAAA,GAAcF,QAAA,CAASG,cAAc;EAC3C,MAAMC,KAAA,GAAQC,kBAAA,CAAmBH,WAAA,EAAaD,2BAAA;EAE9C,IAAI,CAACG,KAAA,EAAO;IACV,OAAO;EACT;EAEA,MAAME,oBAAA,GAA+BF,KAAA,CAAMG,KAAK,IAAI;EACpD,MAAMC,kBAAA,GAAqBF,oBAAA,GAAuBF,KAAK,CAAC,EAAE,CAACK,MAAM;EAEjE,MAAMC,WAAA,GAAqCT,2BAAA,CAA4BU,iBAAiB,CAACP,KAAK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B,EAChBF,WAAkC,EAClCN,KAAuB;EAMvB,MAAMF,WAAA,GAAcF,QAAA,CAASG,cAAc;EAE3C;EACA,IAAIwB,SAAA,EAAWC,UAAA,EAAYC,eAAA;EAE3B;EACA;EACA;EACA,IAAIzB,KAAK,CAAC,EAAE,KAAKF,WAAA,EAAa;IAC5B2B,eAAA,GAAkB7B,QAAA;EACpB,OAAO;IACL,IAAIa,UAAA,KAAe,GAAG;MACnB,CAACgB,eAAA,EAAiBF,SAAA,CAAU,GAAG3B,QAAA,CAAS8B,SAAS,CAAClB,QAAA;IACrD,OAAO;MACJ,CAACgB,UAAA,EAAYC,eAAA,EAAiBF,SAAA,CAAU,GAAG3B,QAAA,CAAS8B,SAAS,CAACjB,UAAA,EAAYD,QAAA;IAC7E;EACF;EAEAiB,eAAA,CAAgBE,cAAc,CAAC3B,KAAK,CAAC,EAAE;EAEvC,IAAIM,WAAA,EAAa;IACf,KAAK,MAAMsB,MAAA,IAAUtB,WAAA,CAAYsB,MAAM,EAAE;MACvC,IAAI,CAACH,eAAA,CAAgBI,SAAS,CAACD,MAAA,GAAS;QACtCH,eAAA,CAAgBK,YAAY,CAACF,MAAA;MAC/B;IACF;EACF;EAEA,OAAO;IACLL,SAAA;IACAC,UAAA;IACAC;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type TextNode } from 'lexical';
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import type { TextMatchTransformer } from './MarkdownTransformers.js';
|
|
10
|
+
export declare function findOutermostTextMatchTransformer(textNode_: TextNode, textMatchTransformers: Array<TextMatchTransformer>): {
|
|
11
|
+
endIndex: number;
|
|
12
|
+
match: RegExpMatchArray;
|
|
13
|
+
startIndex: number;
|
|
14
|
+
transformer: TextMatchTransformer;
|
|
15
|
+
} | null;
|
|
16
|
+
export declare function importFoundTextMatchTransformer(textNode: TextNode, startIndex: number, endIndex: number, transformer: TextMatchTransformer, match: RegExpMatchArray): {
|
|
17
|
+
nodeAfter: TextNode | undefined;
|
|
18
|
+
nodeBefore: TextNode | undefined;
|
|
19
|
+
transformedNode?: TextNode;
|
|
20
|
+
} | null;
|
|
21
|
+
//# sourceMappingURL=importTextMatchTransformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importTextMatchTransformer.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/importTextMatchTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAErE,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,QAAQ,EACnB,qBAAqB,EAAE,KAAK,CAAC,oBAAoB,CAAC,GACjD;IACD,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,gBAAgB,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,oBAAoB,CAAA;CAClC,GAAG,IAAI,CAsDP;AAED,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,oBAAoB,EACjC,KAAK,EAAE,gBAAgB,GACtB;IACD,SAAS,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC/B,UAAU,EAAE,QAAQ,GAAG,SAAS,CAAA;IAChC,eAAe,CAAC,EAAE,QAAQ,CAAA;CAC3B,GAAG,IAAI,CAmBP"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export function findOutermostTextMatchTransformer(textNode_, textMatchTransformers) {
|
|
2
|
+
const textNode = textNode_;
|
|
3
|
+
let foundMatchStartIndex = undefined;
|
|
4
|
+
let foundMatchEndIndex = undefined;
|
|
5
|
+
let foundMatchTransformer = undefined;
|
|
6
|
+
let foundMatch = undefined;
|
|
7
|
+
for (const transformer of textMatchTransformers) {
|
|
8
|
+
if (!transformer.replace || !transformer.importRegExp) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
const match = textNode.getTextContent().match(transformer.importRegExp);
|
|
12
|
+
if (!match) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const startIndex = match.index || 0;
|
|
16
|
+
const endIndex = transformer.getEndIndex ? transformer.getEndIndex(textNode, match) : startIndex + match[0].length;
|
|
17
|
+
if (endIndex === false) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (foundMatchStartIndex === undefined || foundMatchEndIndex === undefined || startIndex < foundMatchStartIndex && endIndex > foundMatchEndIndex) {
|
|
21
|
+
foundMatchStartIndex = startIndex;
|
|
22
|
+
foundMatchEndIndex = endIndex;
|
|
23
|
+
foundMatchTransformer = transformer;
|
|
24
|
+
foundMatch = match;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (foundMatchStartIndex === undefined || foundMatchEndIndex === undefined || foundMatchTransformer === undefined || foundMatch === undefined) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
endIndex: foundMatchEndIndex,
|
|
32
|
+
match: foundMatch,
|
|
33
|
+
startIndex: foundMatchStartIndex,
|
|
34
|
+
transformer: foundMatchTransformer
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function importFoundTextMatchTransformer(textNode, startIndex, endIndex, transformer, match) {
|
|
38
|
+
let nodeAfter, nodeBefore, transformedNode;
|
|
39
|
+
if (startIndex === 0) {
|
|
40
|
+
[transformedNode, nodeAfter] = textNode.splitText(endIndex);
|
|
41
|
+
} else {
|
|
42
|
+
[nodeBefore, transformedNode, nodeAfter] = textNode.splitText(startIndex, endIndex);
|
|
43
|
+
}
|
|
44
|
+
if (!transformer.replace) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const potentialTransformedNode = transformer.replace(transformedNode, match);
|
|
48
|
+
return {
|
|
49
|
+
nodeAfter,
|
|
50
|
+
nodeBefore,
|
|
51
|
+
transformedNode: potentialTransformedNode || undefined
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=importTextMatchTransformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importTextMatchTransformer.js","names":["findOutermostTextMatchTransformer","textNode_","textMatchTransformers","textNode","foundMatchStartIndex","undefined","foundMatchEndIndex","foundMatchTransformer","foundMatch","transformer","replace","importRegExp","match","getTextContent","startIndex","index","endIndex","getEndIndex","length","importFoundTextMatchTransformer","nodeAfter","nodeBefore","transformedNode","splitText","potentialTransformedNode"],"sources":["../../../../src/packages/@lexical/markdown/importTextMatchTransformer.ts"],"sourcesContent":["import { type TextNode } from 'lexical'\n\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 */\nimport type { TextMatchTransformer } from './MarkdownTransformers.js'\n\nexport function findOutermostTextMatchTransformer(\n textNode_: TextNode,\n textMatchTransformers: Array<TextMatchTransformer>,\n): {\n endIndex: number\n match: RegExpMatchArray\n startIndex: number\n transformer: TextMatchTransformer\n} | null {\n const textNode = textNode_\n\n let foundMatchStartIndex: number | undefined = undefined\n let foundMatchEndIndex: number | undefined = undefined\n let foundMatchTransformer: TextMatchTransformer | undefined = undefined\n let foundMatch: RegExpMatchArray | undefined = undefined\n\n for (const transformer of textMatchTransformers) {\n if (!transformer.replace || !transformer.importRegExp) {\n continue\n }\n const match = textNode.getTextContent().match(transformer.importRegExp)\n\n if (!match) {\n continue\n }\n\n const startIndex = match.index || 0\n const endIndex = transformer.getEndIndex\n ? transformer.getEndIndex(textNode, match)\n : startIndex + match[0].length\n\n if (endIndex === false) {\n continue\n }\n\n if (\n foundMatchStartIndex === undefined ||\n foundMatchEndIndex === undefined ||\n (startIndex < foundMatchStartIndex && endIndex > foundMatchEndIndex)\n ) {\n foundMatchStartIndex = startIndex\n foundMatchEndIndex = endIndex\n foundMatchTransformer = transformer\n foundMatch = match\n }\n }\n\n if (\n foundMatchStartIndex === undefined ||\n foundMatchEndIndex === undefined ||\n foundMatchTransformer === undefined ||\n foundMatch === undefined\n ) {\n return null\n }\n\n return {\n endIndex: foundMatchEndIndex,\n match: foundMatch,\n startIndex: foundMatchStartIndex,\n transformer: foundMatchTransformer,\n }\n}\n\nexport function importFoundTextMatchTransformer(\n textNode: TextNode,\n startIndex: number,\n endIndex: number,\n transformer: TextMatchTransformer,\n match: RegExpMatchArray,\n): {\n nodeAfter: TextNode | undefined // If split\n nodeBefore: TextNode | undefined // If split\n transformedNode?: TextNode\n} | null {\n let nodeAfter, nodeBefore, transformedNode\n\n if (startIndex === 0) {\n ;[transformedNode, nodeAfter] = textNode.splitText(endIndex)\n } else {\n ;[nodeBefore, transformedNode, nodeAfter] = textNode.splitText(startIndex, endIndex)\n }\n\n if (!transformer.replace) {\n return null\n }\n const potentialTransformedNode = transformer.replace(transformedNode, match)\n\n return {\n nodeAfter,\n nodeBefore,\n transformedNode: potentialTransformedNode || undefined,\n }\n}\n"],"mappings":"AAWA,OAAO,SAASA,kCACdC,SAAmB,EACnBC,qBAAkD;EAOlD,MAAMC,QAAA,GAAWF,SAAA;EAEjB,IAAIG,oBAAA,GAA2CC,SAAA;EAC/C,IAAIC,kBAAA,GAAyCD,SAAA;EAC7C,IAAIE,qBAAA,GAA0DF,SAAA;EAC9D,IAAIG,UAAA,GAA2CH,SAAA;EAE/C,KAAK,MAAMI,WAAA,IAAeP,qBAAA,EAAuB;IAC/C,IAAI,CAACO,WAAA,CAAYC,OAAO,IAAI,CAACD,WAAA,CAAYE,YAAY,EAAE;MACrD;IACF;IACA,MAAMC,KAAA,GAAQT,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AI,CAACP,WAAA,CAAYC,OAAO,EAAE;IACxB,OAAO;EACT;EACA,MAAMc,wBAAA,GAA2Bf,WAAA,CAAYC,OAAO,CAACY,eAAA,EAAiBV,KAAA;EAEtE,OAAO;IACLQ,SAAA;IACAC,UAAA;IACAC,eAAA,EAAiBE,wBAAA,IAA4BnB;EAC/C;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type TextNode } from 'lexical';
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import type { TextFormatTransformersIndex } from './MarkdownImport.js';
|
|
10
|
+
import type { TextMatchTransformer } from './MarkdownTransformers.js';
|
|
11
|
+
/**
|
|
12
|
+
* Handles applying both text format and text match transformers.
|
|
13
|
+
* It finds the outermost text format or text match and applies it,
|
|
14
|
+
* then recursively calls itself to apply the next outermost transformer,
|
|
15
|
+
* until there are no more transformers to apply.
|
|
16
|
+
*/
|
|
17
|
+
export declare function importTextTransformers(textNode: TextNode, textFormatTransformersIndex: TextFormatTransformersIndex, textMatchTransformers: Array<TextMatchTransformer>): void;
|
|
18
|
+
//# sourceMappingURL=importTextTransformers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importTextTransformers.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/importTextTransformers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEpD;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAWrE;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,QAAQ,EAClB,2BAA2B,EAAE,2BAA2B,EACxD,qBAAqB,EAAE,KAAK,CAAC,oBAAoB,CAAC,QAyFnD"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { $isTextNode } from 'lexical';
|
|
2
|
+
import { findOutermostTextFormatTransformer, importTextFormatTransformer } from './importTextFormatTransformer.js';
|
|
3
|
+
import { findOutermostTextMatchTransformer, importFoundTextMatchTransformer } from './importTextMatchTransformer.js';
|
|
4
|
+
/**
|
|
5
|
+
* Handles applying both text format and text match transformers.
|
|
6
|
+
* It finds the outermost text format or text match and applies it,
|
|
7
|
+
* then recursively calls itself to apply the next outermost transformer,
|
|
8
|
+
* until there are no more transformers to apply.
|
|
9
|
+
*/
|
|
10
|
+
export function importTextTransformers(textNode, textFormatTransformersIndex, textMatchTransformers) {
|
|
11
|
+
let foundTextFormat = findOutermostTextFormatTransformer(textNode, textFormatTransformersIndex);
|
|
12
|
+
let foundTextMatch = findOutermostTextMatchTransformer(textNode, textMatchTransformers);
|
|
13
|
+
if (foundTextFormat && foundTextMatch) {
|
|
14
|
+
// Find the outermost transformer
|
|
15
|
+
if (foundTextFormat.startIndex <= foundTextMatch.startIndex && foundTextFormat.endIndex >= foundTextMatch.endIndex) {
|
|
16
|
+
// foundTextFormat wraps foundTextMatch - apply foundTextFormat by setting foundTextMatch to null
|
|
17
|
+
foundTextMatch = null;
|
|
18
|
+
} else {
|
|
19
|
+
// foundTextMatch wraps foundTextFormat - apply foundTextMatch by setting foundTextFormat to null
|
|
20
|
+
foundTextFormat = null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (foundTextFormat) {
|
|
24
|
+
const result = importTextFormatTransformer(textNode, foundTextFormat.startIndex, foundTextFormat.endIndex, foundTextFormat.transformer, foundTextFormat.match);
|
|
25
|
+
if (result.nodeAfter && $isTextNode(result.nodeAfter) && !result.nodeAfter.hasFormat('code')) {
|
|
26
|
+
importTextTransformers(result.nodeAfter, textFormatTransformersIndex, textMatchTransformers);
|
|
27
|
+
}
|
|
28
|
+
if (result.nodeBefore && $isTextNode(result.nodeBefore) && !result.nodeBefore.hasFormat('code')) {
|
|
29
|
+
importTextTransformers(result.nodeBefore, textFormatTransformersIndex, textMatchTransformers);
|
|
30
|
+
}
|
|
31
|
+
if (result.transformedNode && $isTextNode(result.transformedNode) && !result.transformedNode.hasFormat('code')) {
|
|
32
|
+
importTextTransformers(result.transformedNode, textFormatTransformersIndex, textMatchTransformers);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
} else if (foundTextMatch) {
|
|
36
|
+
const result = importFoundTextMatchTransformer(textNode, foundTextMatch.startIndex, foundTextMatch.endIndex, foundTextMatch.transformer, foundTextMatch.match);
|
|
37
|
+
if (!result) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (result.nodeAfter && $isTextNode(result.nodeAfter) && !result.nodeAfter.hasFormat('code')) {
|
|
41
|
+
importTextTransformers(result.nodeAfter, textFormatTransformersIndex, textMatchTransformers);
|
|
42
|
+
}
|
|
43
|
+
if (result.nodeBefore && $isTextNode(result.nodeBefore) && !result.nodeBefore.hasFormat('code')) {
|
|
44
|
+
importTextTransformers(result.nodeBefore, textFormatTransformersIndex, textMatchTransformers);
|
|
45
|
+
}
|
|
46
|
+
if (result.transformedNode && $isTextNode(result.transformedNode) && !result.transformedNode.hasFormat('code')) {
|
|
47
|
+
importTextTransformers(result.transformedNode, textFormatTransformersIndex, textMatchTransformers);
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
} else {
|
|
51
|
+
// Done!
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=importTextTransformers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importTextTransformers.js","names":["$isTextNode","findOutermostTextFormatTransformer","importTextFormatTransformer","findOutermostTextMatchTransformer","importFoundTextMatchTransformer","importTextTransformers","textNode","textFormatTransformersIndex","textMatchTransformers","foundTextFormat","foundTextMatch","startIndex","endIndex","result","transformer","match","nodeAfter","hasFormat","nodeBefore","transformedNode"],"sources":["../../../../src/packages/@lexical/markdown/importTextTransformers.ts"],"sourcesContent":["import { $isTextNode, type TextNode } from 'lexical'\n\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 */\nimport type { TextFormatTransformersIndex } from './MarkdownImport.js'\nimport type { TextMatchTransformer } from './MarkdownTransformers.js'\n\nimport {\n findOutermostTextFormatTransformer,\n importTextFormatTransformer,\n} from './importTextFormatTransformer.js'\nimport {\n findOutermostTextMatchTransformer,\n importFoundTextMatchTransformer,\n} from './importTextMatchTransformer.js'\n\n/**\n * Handles applying both text format and text match transformers.\n * It finds the outermost text format or text match and applies it,\n * then recursively calls itself to apply the next outermost transformer,\n * until there are no more transformers to apply.\n */\nexport function importTextTransformers(\n textNode: TextNode,\n textFormatTransformersIndex: TextFormatTransformersIndex,\n textMatchTransformers: Array<TextMatchTransformer>,\n) {\n let foundTextFormat = findOutermostTextFormatTransformer(textNode, textFormatTransformersIndex)\n\n let foundTextMatch = findOutermostTextMatchTransformer(textNode, textMatchTransformers)\n\n if (foundTextFormat && foundTextMatch) {\n // Find the outermost transformer\n if (\n foundTextFormat.startIndex <= foundTextMatch.startIndex &&\n foundTextFormat.endIndex >= foundTextMatch.endIndex\n ) {\n // foundTextFormat wraps foundTextMatch - apply foundTextFormat by setting foundTextMatch to null\n foundTextMatch = null\n } else {\n // foundTextMatch wraps foundTextFormat - apply foundTextMatch by setting foundTextFormat to null\n foundTextFormat = null\n }\n }\n\n if (foundTextFormat) {\n const result = importTextFormatTransformer(\n textNode,\n foundTextFormat.startIndex,\n foundTextFormat.endIndex,\n foundTextFormat.transformer,\n foundTextFormat.match,\n )\n\n if (result.nodeAfter && $isTextNode(result.nodeAfter) && !result.nodeAfter.hasFormat('code')) {\n importTextTransformers(result.nodeAfter, textFormatTransformersIndex, textMatchTransformers)\n }\n if (\n result.nodeBefore &&\n $isTextNode(result.nodeBefore) &&\n !result.nodeBefore.hasFormat('code')\n ) {\n importTextTransformers(result.nodeBefore, textFormatTransformersIndex, textMatchTransformers)\n }\n if (\n result.transformedNode &&\n $isTextNode(result.transformedNode) &&\n !result.transformedNode.hasFormat('code')\n ) {\n importTextTransformers(\n result.transformedNode,\n textFormatTransformersIndex,\n textMatchTransformers,\n )\n }\n return\n } else if (foundTextMatch) {\n const result = importFoundTextMatchTransformer(\n textNode,\n foundTextMatch.startIndex,\n foundTextMatch.endIndex,\n foundTextMatch.transformer,\n foundTextMatch.match,\n )\n if (!result) {\n return\n }\n\n if (result.nodeAfter && $isTextNode(result.nodeAfter) && !result.nodeAfter.hasFormat('code')) {\n importTextTransformers(result.nodeAfter, textFormatTransformersIndex, textMatchTransformers)\n }\n if (\n result.nodeBefore &&\n $isTextNode(result.nodeBefore) &&\n !result.nodeBefore.hasFormat('code')\n ) {\n importTextTransformers(result.nodeBefore, textFormatTransformersIndex, textMatchTransformers)\n }\n if (\n result.transformedNode &&\n $isTextNode(result.transformedNode) &&\n !result.transformedNode.hasFormat('code')\n ) {\n importTextTransformers(\n result.transformedNode,\n textFormatTransformersIndex,\n textMatchTransformers,\n )\n }\n return\n } else {\n // Done!\n return\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAuB;AAY3C,SACEC,kCAAkC,EAClCC,2BAA2B,QACtB;AACP,SACEC,iCAAiC,EACjCC,+BAA+B,QAC1B;AAEP;;;;;;AAMA,OAAO,SAASC,uBACdC,QAAkB,EAClBC,2BAAwD,EACxDC,qBAAkD;EAElD,IAAIC,eAAA,GAAkBR,kCAAA,CAAmCK,QAAA,EAAUC,2BAAA;EAEnE,IAAIG,cAAA,GAAiBP,iCAAA,CAAkCG,QAAA,EAAUE,qBAAA;EAEjE,IAAIC,eAAA,IAAmBC,cAAA,EAAgB;IACrC;IACA,IACED,eAAA,CAAgBE,UAAU,IAA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,WAAA,CAAYa,MAAA,CAAOG,SAAS,KAAK,CAACH,MAAA,CAAOG,SAAS,CAACC,SAAS,CAAC,SAAS;MAC5FZ,sBAAA,CAAuBQ,MAAA,CAAOG,SAAS,EAAET,2BAAA,EAA6BC,qBAAA;IACxE;IACA,IACEK,MAAA,CAAOK,UAAU,IACjBlB,WAAA,CAAYa,MAAA,CAAOK,UAAU,KAC7B,CAACL,MAAA,CAAOK,UAAU,CAACD,SAAS,CAAC,SAC7B;MACAZ,sBAAA,CAAuBQ,MAAA,CAAOK,UAAU,EAAEX,2BAAA,EAA6BC,qBAAA;IACzE;IACA,IACEK,MAAA,CAAOM,eAAe,IACtBnB,WAAA,CAAYa,MAAA,CAAOM,eAAe,KAClC,CAACN,MAAA,CAAOM,eAAe,CAACF,SAAS,CAAC,SAClC;MACAZ,sBAAA,CACEQ,MAAA,CAAOM,eAAe,EACtBZ,2BAAA,EACAC,qBAAA;IAEJ;IACA;EACF,OAAO;IACL;IACA;EACF;AACF","ignoreList":[]}
|
package/dist/types.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ export type LexicalFieldAdminProps = {
|
|
|
9
9
|
* Controls if the gutter (padding to the left & gray vertical line) should be hidden. @default false
|
|
10
10
|
*/
|
|
11
11
|
hideGutter?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Changes the placeholder text in the editor if no content is present.
|
|
14
|
+
*/
|
|
15
|
+
placeholder?: string;
|
|
12
16
|
};
|
|
13
17
|
export type LexicalEditorProps = {
|
|
14
18
|
admin?: LexicalFieldAdminProps;
|