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

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.
Files changed (474) hide show
  1. package/dist/exports/client/Field-Q2MD4LTV.js +2 -0
  2. package/dist/exports/client/Field-Q2MD4LTV.js.map +7 -0
  3. package/dist/exports/client/{RelationshipComponent-JPESGV4Q.js → RelationshipComponent-APF3CN47.js} +2 -2
  4. package/dist/exports/client/bundled.css +1 -1
  5. package/dist/exports/client/chunk-46KMRCKV.js +2 -0
  6. package/dist/exports/client/chunk-46KMRCKV.js.map +7 -0
  7. package/dist/exports/client/chunk-BZZVLW4U.js +2 -0
  8. package/dist/exports/client/chunk-BZZVLW4U.js.map +7 -0
  9. package/dist/exports/client/chunk-FV3BVQ6U.js +12 -0
  10. package/dist/exports/client/chunk-FV3BVQ6U.js.map +7 -0
  11. package/dist/exports/client/{chunk-PUXDVIHC.js → chunk-Y2GOLUGU.js} +2 -2
  12. package/dist/exports/client/{component-P5K7Z5NW.js → component-Y3OSWJM5.js} +2 -2
  13. package/dist/exports/client/componentInline-ZB4EY7EQ.js +2 -0
  14. package/dist/exports/client/index.js +10 -10
  15. package/dist/exports/client/index.js.map +4 -4
  16. package/dist/exports/html/index.d.ts +15 -15
  17. package/dist/exports/html/index.d.ts.map +1 -1
  18. package/dist/exports/html/index.js +13 -13
  19. package/dist/exports/html/index.js.map +1 -1
  20. package/dist/exports/html-async/index.d.ts +15 -15
  21. package/dist/exports/html-async/index.d.ts.map +1 -1
  22. package/dist/exports/html-async/index.js +13 -13
  23. package/dist/exports/html-async/index.js.map +1 -1
  24. package/dist/exports/plaintext/index.d.ts +3 -0
  25. package/dist/exports/plaintext/index.d.ts.map +1 -0
  26. package/dist/exports/plaintext/index.js +2 -0
  27. package/dist/exports/plaintext/index.js.map +1 -0
  28. package/dist/exports/react/index.d.ts +15 -15
  29. package/dist/exports/react/index.d.ts.map +1 -1
  30. package/dist/exports/react/index.js +14 -14
  31. package/dist/exports/react/index.js.map +1 -1
  32. package/dist/features/blockquote/server/index.js +1 -1
  33. package/dist/features/blockquote/server/index.js.map +1 -1
  34. package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
  35. package/dist/features/blocks/client/component/BlockContent.js +2 -4
  36. package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
  37. package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
  38. package/dist/features/blocks/client/componentInline/index.js +2 -4
  39. package/dist/features/blocks/client/componentInline/index.js.map +1 -1
  40. package/dist/features/blocks/server/linesFromMatchToContentAndPropsString.d.ts.map +1 -1
  41. package/dist/features/blocks/server/linesFromMatchToContentAndPropsString.js +1 -1
  42. package/dist/features/blocks/server/linesFromMatchToContentAndPropsString.js.map +1 -1
  43. package/dist/features/converters/htmlToLexical/index.d.ts.map +1 -1
  44. package/dist/features/converters/htmlToLexical/index.js +0 -1
  45. package/dist/features/converters/htmlToLexical/index.js.map +1 -1
  46. package/dist/features/converters/lexicalToHtml/async/converters/blockquote.d.ts.map +1 -0
  47. package/dist/features/converters/lexicalToHtml/async/converters/blockquote.js.map +1 -0
  48. package/dist/features/converters/lexicalToHtml/async/converters/heading.d.ts.map +1 -0
  49. package/dist/features/converters/lexicalToHtml/async/converters/heading.js.map +1 -0
  50. package/dist/features/converters/lexicalToHtml/async/converters/horizontalRule.d.ts.map +1 -0
  51. package/dist/features/converters/lexicalToHtml/async/converters/horizontalRule.js.map +1 -0
  52. package/dist/features/converters/lexicalToHtml/async/converters/linebreak.d.ts.map +1 -0
  53. package/dist/features/converters/lexicalToHtml/async/converters/linebreak.js.map +1 -0
  54. package/dist/features/converters/lexicalToHtml/async/converters/link.d.ts.map +1 -0
  55. package/dist/features/converters/{html → lexicalToHtml}/async/converters/link.js +4 -12
  56. package/dist/features/converters/lexicalToHtml/async/converters/link.js.map +1 -0
  57. package/dist/features/converters/lexicalToHtml/async/converters/list.d.ts.map +1 -0
  58. package/dist/features/converters/{html → lexicalToHtml}/async/converters/list.js +1 -1
  59. package/dist/features/converters/lexicalToHtml/async/converters/list.js.map +1 -0
  60. package/dist/features/converters/lexicalToHtml/async/converters/paragraph.d.ts.map +1 -0
  61. package/dist/features/converters/lexicalToHtml/async/converters/paragraph.js.map +1 -0
  62. package/dist/features/converters/lexicalToHtml/async/converters/tab.d.ts.map +1 -0
  63. package/dist/features/converters/lexicalToHtml/async/converters/tab.js.map +1 -0
  64. package/dist/features/converters/lexicalToHtml/async/converters/table.d.ts.map +1 -0
  65. package/dist/features/converters/lexicalToHtml/async/converters/table.js.map +1 -0
  66. package/dist/features/converters/lexicalToHtml/async/converters/text.d.ts.map +1 -0
  67. package/dist/features/converters/lexicalToHtml/async/converters/text.js.map +1 -0
  68. package/dist/features/converters/lexicalToHtml/async/converters/upload.d.ts.map +1 -0
  69. package/dist/features/converters/lexicalToHtml/async/converters/upload.js.map +1 -0
  70. package/dist/features/converters/lexicalToHtml/async/defaultConverters.d.ts.map +1 -0
  71. package/dist/features/converters/lexicalToHtml/async/defaultConverters.js.map +1 -0
  72. package/dist/features/converters/lexicalToHtml/async/field/index.d.ts.map +1 -0
  73. package/dist/features/converters/{html → lexicalToHtml}/async/field/index.js +11 -11
  74. package/dist/features/converters/lexicalToHtml/async/field/index.js.map +1 -0
  75. package/dist/features/converters/lexicalToHtml/async/index.d.ts.map +1 -0
  76. package/dist/features/converters/lexicalToHtml/async/index.js.map +1 -0
  77. package/dist/features/converters/lexicalToHtml/async/types.d.ts.map +1 -0
  78. package/dist/features/converters/lexicalToHtml/async/types.js.map +1 -0
  79. package/dist/features/converters/lexicalToHtml/shared/findConverterForNode.d.ts.map +1 -0
  80. package/dist/features/converters/lexicalToHtml/shared/findConverterForNode.js.map +1 -0
  81. package/dist/features/converters/lexicalToHtml/shared/types.d.ts.map +1 -0
  82. package/dist/features/converters/lexicalToHtml/shared/types.js.map +1 -0
  83. package/dist/features/converters/lexicalToHtml/sync/converters/blockquote.d.ts.map +1 -0
  84. package/dist/features/converters/lexicalToHtml/sync/converters/blockquote.js.map +1 -0
  85. package/dist/features/converters/lexicalToHtml/sync/converters/heading.d.ts.map +1 -0
  86. package/dist/features/converters/lexicalToHtml/sync/converters/heading.js.map +1 -0
  87. package/dist/features/converters/lexicalToHtml/sync/converters/horizontalRule.d.ts.map +1 -0
  88. package/dist/features/converters/lexicalToHtml/sync/converters/horizontalRule.js.map +1 -0
  89. package/dist/features/converters/lexicalToHtml/sync/converters/linebreak.d.ts.map +1 -0
  90. package/dist/features/converters/lexicalToHtml/sync/converters/linebreak.js.map +1 -0
  91. package/dist/features/converters/lexicalToHtml/sync/converters/link.d.ts.map +1 -0
  92. package/dist/features/converters/{html → lexicalToHtml}/sync/converters/link.js +4 -12
  93. package/dist/features/converters/lexicalToHtml/sync/converters/link.js.map +1 -0
  94. package/dist/features/converters/lexicalToHtml/sync/converters/list.d.ts.map +1 -0
  95. package/dist/features/converters/{html → lexicalToHtml}/sync/converters/list.js +1 -1
  96. package/dist/features/converters/lexicalToHtml/sync/converters/list.js.map +1 -0
  97. package/dist/features/converters/lexicalToHtml/sync/converters/paragraph.d.ts.map +1 -0
  98. package/dist/features/converters/lexicalToHtml/sync/converters/paragraph.js.map +1 -0
  99. package/dist/features/converters/lexicalToHtml/sync/converters/tab.d.ts.map +1 -0
  100. package/dist/features/converters/lexicalToHtml/sync/converters/tab.js.map +1 -0
  101. package/dist/features/converters/lexicalToHtml/sync/converters/table.d.ts.map +1 -0
  102. package/dist/features/converters/lexicalToHtml/sync/converters/table.js.map +1 -0
  103. package/dist/features/converters/lexicalToHtml/sync/converters/text.d.ts.map +1 -0
  104. package/dist/features/converters/lexicalToHtml/sync/converters/text.js.map +1 -0
  105. package/dist/features/converters/lexicalToHtml/sync/converters/upload.d.ts.map +1 -0
  106. package/dist/features/converters/lexicalToHtml/sync/converters/upload.js.map +1 -0
  107. package/dist/features/converters/lexicalToHtml/sync/defaultConverters.d.ts.map +1 -0
  108. package/dist/features/converters/lexicalToHtml/sync/defaultConverters.js.map +1 -0
  109. package/dist/features/converters/lexicalToHtml/sync/index.d.ts.map +1 -0
  110. package/dist/features/converters/lexicalToHtml/sync/index.js.map +1 -0
  111. package/dist/features/converters/lexicalToHtml/sync/types.d.ts.map +1 -0
  112. package/dist/features/converters/lexicalToHtml/sync/types.js.map +1 -0
  113. package/dist/features/converters/lexicalToHtml_deprecated/converter/converters/linebreak.d.ts.map +1 -0
  114. package/dist/features/converters/lexicalToHtml_deprecated/converter/converters/linebreak.js.map +1 -0
  115. package/dist/features/converters/lexicalToHtml_deprecated/converter/converters/paragraph.d.ts.map +1 -0
  116. package/dist/features/converters/lexicalToHtml_deprecated/converter/converters/paragraph.js.map +1 -0
  117. package/dist/features/converters/lexicalToHtml_deprecated/converter/converters/tab.d.ts.map +1 -0
  118. package/dist/features/converters/lexicalToHtml_deprecated/converter/converters/tab.js.map +1 -0
  119. package/dist/features/converters/lexicalToHtml_deprecated/converter/converters/text.d.ts.map +1 -0
  120. package/dist/features/converters/lexicalToHtml_deprecated/converter/converters/text.js.map +1 -0
  121. package/dist/features/converters/lexicalToHtml_deprecated/converter/defaultConverters.d.ts.map +1 -0
  122. package/dist/features/converters/lexicalToHtml_deprecated/converter/defaultConverters.js.map +1 -0
  123. package/dist/features/converters/lexicalToHtml_deprecated/converter/index.d.ts.map +1 -0
  124. package/dist/features/converters/lexicalToHtml_deprecated/converter/index.js.map +1 -0
  125. package/dist/features/converters/lexicalToHtml_deprecated/converter/types.d.ts.map +1 -0
  126. package/dist/features/converters/lexicalToHtml_deprecated/converter/types.js.map +1 -0
  127. package/dist/features/converters/lexicalToHtml_deprecated/field/index.d.ts.map +1 -0
  128. package/dist/features/converters/lexicalToHtml_deprecated/field/index.js.map +1 -0
  129. package/dist/features/converters/lexicalToHtml_deprecated/index.d.ts.map +1 -0
  130. package/dist/features/converters/lexicalToHtml_deprecated/index.js.map +1 -0
  131. package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -0
  132. package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -0
  133. package/dist/features/converters/lexicalToJSX/converter/converters/blockquote.d.ts.map +1 -0
  134. package/dist/features/converters/lexicalToJSX/converter/converters/blockquote.js.map +1 -0
  135. package/dist/features/converters/lexicalToJSX/converter/converters/heading.d.ts.map +1 -0
  136. package/dist/features/converters/lexicalToJSX/converter/converters/heading.js.map +1 -0
  137. package/dist/features/converters/lexicalToJSX/converter/converters/horizontalRule.d.ts.map +1 -0
  138. package/dist/features/converters/lexicalToJSX/converter/converters/horizontalRule.js.map +1 -0
  139. package/dist/features/converters/lexicalToJSX/converter/converters/linebreak.d.ts.map +1 -0
  140. package/dist/features/converters/lexicalToJSX/converter/converters/linebreak.js.map +1 -0
  141. package/dist/features/converters/lexicalToJSX/converter/converters/link.d.ts.map +1 -0
  142. package/dist/features/converters/lexicalToJSX/converter/converters/link.js.map +1 -0
  143. package/dist/features/converters/lexicalToJSX/converter/converters/list.d.ts.map +1 -0
  144. package/dist/features/converters/lexicalToJSX/converter/converters/list.js.map +1 -0
  145. package/dist/features/converters/lexicalToJSX/converter/converters/paragraph.d.ts.map +1 -0
  146. package/dist/features/converters/lexicalToJSX/converter/converters/paragraph.js.map +1 -0
  147. package/dist/features/converters/lexicalToJSX/converter/converters/tab.d.ts.map +1 -0
  148. package/dist/features/converters/lexicalToJSX/converter/converters/tab.js.map +1 -0
  149. package/dist/features/converters/lexicalToJSX/converter/converters/table.d.ts.map +1 -0
  150. package/dist/features/converters/lexicalToJSX/converter/converters/table.js.map +1 -0
  151. package/dist/features/converters/lexicalToJSX/converter/converters/text.d.ts.map +1 -0
  152. package/dist/features/converters/lexicalToJSX/converter/converters/text.js.map +1 -0
  153. package/dist/features/converters/lexicalToJSX/converter/converters/upload.d.ts.map +1 -0
  154. package/dist/features/converters/lexicalToJSX/converter/converters/upload.js.map +1 -0
  155. package/dist/features/converters/lexicalToJSX/converter/defaultConverters.d.ts.map +1 -0
  156. package/dist/features/converters/lexicalToJSX/converter/defaultConverters.js.map +1 -0
  157. package/dist/features/converters/lexicalToJSX/converter/index.d.ts.map +1 -0
  158. package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -0
  159. package/dist/features/converters/lexicalToJSX/converter/types.d.ts.map +1 -0
  160. package/dist/features/converters/lexicalToJSX/converter/types.js.map +1 -0
  161. package/dist/features/converters/lexicalToMarkdown/index.d.ts +7 -0
  162. package/dist/features/converters/lexicalToMarkdown/index.d.ts.map +1 -0
  163. package/dist/features/converters/lexicalToMarkdown/index.js +24 -0
  164. package/dist/features/converters/lexicalToMarkdown/index.js.map +1 -0
  165. package/dist/features/converters/lexicalToPlaintext/convertLexicalToPlaintext.spec.js +84 -0
  166. package/dist/features/converters/lexicalToPlaintext/convertLexicalToPlaintext.spec.js.map +1 -0
  167. package/dist/features/converters/lexicalToPlaintext/shared/findConverterForNode.d.ts +7 -0
  168. package/dist/features/converters/lexicalToPlaintext/shared/findConverterForNode.d.ts.map +1 -0
  169. package/dist/features/converters/lexicalToPlaintext/shared/findConverterForNode.js +15 -0
  170. package/dist/features/converters/lexicalToPlaintext/shared/findConverterForNode.js.map +1 -0
  171. package/dist/features/converters/lexicalToPlaintext/shared/types.d.ts +5 -0
  172. package/dist/features/converters/lexicalToPlaintext/shared/types.d.ts.map +1 -0
  173. package/dist/features/converters/lexicalToPlaintext/shared/types.js +2 -0
  174. package/dist/features/converters/lexicalToPlaintext/shared/types.js.map +1 -0
  175. package/dist/features/converters/lexicalToPlaintext/sync/index.d.ts +22 -0
  176. package/dist/features/converters/lexicalToPlaintext/sync/index.d.ts.map +1 -0
  177. package/dist/features/converters/lexicalToPlaintext/sync/index.js +79 -0
  178. package/dist/features/converters/lexicalToPlaintext/sync/index.js.map +1 -0
  179. package/dist/features/converters/lexicalToPlaintext/sync/types.d.ts +60 -0
  180. package/dist/features/converters/lexicalToPlaintext/sync/types.d.ts.map +1 -0
  181. package/dist/features/converters/lexicalToPlaintext/sync/types.js +2 -0
  182. package/dist/features/converters/lexicalToPlaintext/sync/types.js.map +1 -0
  183. package/dist/features/converters/markdownToLexical/index.d.ts +8 -0
  184. package/dist/features/converters/markdownToLexical/index.d.ts.map +1 -0
  185. package/dist/features/converters/markdownToLexical/index.js +21 -0
  186. package/dist/features/converters/markdownToLexical/index.js.map +1 -0
  187. package/dist/features/converters/utilities/payloadPopulateFn.d.ts +1 -1
  188. package/dist/features/converters/utilities/payloadPopulateFn.d.ts.map +1 -1
  189. package/dist/features/converters/utilities/payloadPopulateFn.js.map +1 -1
  190. package/dist/features/converters/utilities/restPopulateFn.d.ts +1 -1
  191. package/dist/features/converters/utilities/restPopulateFn.d.ts.map +1 -1
  192. package/dist/features/converters/utilities/restPopulateFn.js.map +1 -1
  193. package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.d.ts.map +1 -1
  194. package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js +5 -6
  195. package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
  196. package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.d.ts +1 -0
  197. package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.d.ts.map +1 -1
  198. package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js +5 -1
  199. package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
  200. package/dist/features/experimental_table/client/plugins/TablePlugin/index.js +3 -3
  201. package/dist/features/experimental_table/client/plugins/TablePlugin/index.js.map +1 -1
  202. package/dist/features/experimental_table/server/index.js +1 -1
  203. package/dist/features/experimental_table/server/index.js.map +1 -1
  204. package/dist/features/heading/server/index.js +1 -1
  205. package/dist/features/heading/server/index.js.map +1 -1
  206. package/dist/features/indent/client/IndentPlugin.d.ts.map +1 -1
  207. package/dist/features/indent/client/IndentPlugin.js +26 -6
  208. package/dist/features/indent/client/IndentPlugin.js.map +1 -1
  209. package/dist/features/indent/client/index.d.ts +2 -1
  210. package/dist/features/indent/client/index.d.ts.map +1 -1
  211. package/dist/features/indent/client/index.js +41 -19
  212. package/dist/features/indent/client/index.js.map +1 -1
  213. package/dist/features/indent/server/index.d.ts +7 -0
  214. package/dist/features/indent/server/index.d.ts.map +1 -1
  215. package/dist/features/indent/server/index.js.map +1 -1
  216. package/dist/features/link/server/index.d.ts.map +1 -1
  217. package/dist/features/link/server/index.js +3 -7
  218. package/dist/features/link/server/index.js.map +1 -1
  219. package/dist/features/lists/htmlConverter.d.ts +1 -1
  220. package/dist/features/lists/htmlConverter.d.ts.map +1 -1
  221. package/dist/features/lists/htmlConverter.js +1 -1
  222. package/dist/features/lists/htmlConverter.js.map +1 -1
  223. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +2 -2
  224. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
  225. package/dist/features/typesServer.d.ts +1 -1
  226. package/dist/features/typesServer.d.ts.map +1 -1
  227. package/dist/features/typesServer.js.map +1 -1
  228. package/dist/field/Field.d.ts.map +1 -1
  229. package/dist/field/Field.js +2 -3
  230. package/dist/field/Field.js.map +1 -1
  231. package/dist/field/bundled.css +1 -1
  232. package/dist/index.d.ts +13 -11
  233. package/dist/index.d.ts.map +1 -1
  234. package/dist/index.js +12 -10
  235. package/dist/index.js.map +1 -1
  236. package/dist/lexical/config/client/EditorConfigProvider.js +4 -4
  237. package/dist/lexical/config/client/EditorConfigProvider.js.map +1 -1
  238. package/dist/nodeTypes.d.ts +1 -1
  239. package/dist/nodeTypes.d.ts.map +1 -1
  240. package/dist/nodeTypes.js.map +1 -1
  241. package/dist/packages/@lexical/markdown/MarkdownExport.js +4 -0
  242. package/dist/packages/@lexical/markdown/MarkdownExport.js.map +1 -1
  243. package/dist/packages/@lexical/markdown/MarkdownImport.d.ts.map +1 -1
  244. package/dist/packages/@lexical/markdown/MarkdownImport.js +17 -7
  245. package/dist/packages/@lexical/markdown/MarkdownImport.js.map +1 -1
  246. package/package.json +23 -18
  247. package/dist/exports/client/Field-FLAQN6LU.js +0 -2
  248. package/dist/exports/client/Field-FLAQN6LU.js.map +0 -7
  249. package/dist/exports/client/chunk-3LGFOM34.js +0 -2
  250. package/dist/exports/client/chunk-3LGFOM34.js.map +0 -7
  251. package/dist/exports/client/chunk-QBDC3MVG.js +0 -2
  252. package/dist/exports/client/chunk-QBDC3MVG.js.map +0 -7
  253. package/dist/exports/client/chunk-XO6X2M3F.js +0 -12
  254. package/dist/exports/client/chunk-XO6X2M3F.js.map +0 -7
  255. package/dist/exports/client/componentInline-IBB73SHH.js +0 -2
  256. package/dist/features/converters/html/async/converters/blockquote.d.ts.map +0 -1
  257. package/dist/features/converters/html/async/converters/blockquote.js.map +0 -1
  258. package/dist/features/converters/html/async/converters/heading.d.ts.map +0 -1
  259. package/dist/features/converters/html/async/converters/heading.js.map +0 -1
  260. package/dist/features/converters/html/async/converters/horizontalRule.d.ts.map +0 -1
  261. package/dist/features/converters/html/async/converters/horizontalRule.js.map +0 -1
  262. package/dist/features/converters/html/async/converters/linebreak.d.ts.map +0 -1
  263. package/dist/features/converters/html/async/converters/linebreak.js.map +0 -1
  264. package/dist/features/converters/html/async/converters/link.d.ts.map +0 -1
  265. package/dist/features/converters/html/async/converters/link.js.map +0 -1
  266. package/dist/features/converters/html/async/converters/list.d.ts.map +0 -1
  267. package/dist/features/converters/html/async/converters/list.js.map +0 -1
  268. package/dist/features/converters/html/async/converters/paragraph.d.ts.map +0 -1
  269. package/dist/features/converters/html/async/converters/paragraph.js.map +0 -1
  270. package/dist/features/converters/html/async/converters/tab.d.ts.map +0 -1
  271. package/dist/features/converters/html/async/converters/tab.js.map +0 -1
  272. package/dist/features/converters/html/async/converters/table.d.ts.map +0 -1
  273. package/dist/features/converters/html/async/converters/table.js.map +0 -1
  274. package/dist/features/converters/html/async/converters/text.d.ts.map +0 -1
  275. package/dist/features/converters/html/async/converters/text.js.map +0 -1
  276. package/dist/features/converters/html/async/converters/upload.d.ts.map +0 -1
  277. package/dist/features/converters/html/async/converters/upload.js.map +0 -1
  278. package/dist/features/converters/html/async/defaultConverters.d.ts.map +0 -1
  279. package/dist/features/converters/html/async/defaultConverters.js.map +0 -1
  280. package/dist/features/converters/html/async/field/index.d.ts.map +0 -1
  281. package/dist/features/converters/html/async/field/index.js.map +0 -1
  282. package/dist/features/converters/html/async/index.d.ts.map +0 -1
  283. package/dist/features/converters/html/async/index.js.map +0 -1
  284. package/dist/features/converters/html/async/types.d.ts.map +0 -1
  285. package/dist/features/converters/html/async/types.js.map +0 -1
  286. package/dist/features/converters/html/shared/findConverterForNode.d.ts.map +0 -1
  287. package/dist/features/converters/html/shared/findConverterForNode.js.map +0 -1
  288. package/dist/features/converters/html/shared/types.d.ts.map +0 -1
  289. package/dist/features/converters/html/shared/types.js.map +0 -1
  290. package/dist/features/converters/html/sync/converters/blockquote.d.ts.map +0 -1
  291. package/dist/features/converters/html/sync/converters/blockquote.js.map +0 -1
  292. package/dist/features/converters/html/sync/converters/heading.d.ts.map +0 -1
  293. package/dist/features/converters/html/sync/converters/heading.js.map +0 -1
  294. package/dist/features/converters/html/sync/converters/horizontalRule.d.ts.map +0 -1
  295. package/dist/features/converters/html/sync/converters/horizontalRule.js.map +0 -1
  296. package/dist/features/converters/html/sync/converters/linebreak.d.ts.map +0 -1
  297. package/dist/features/converters/html/sync/converters/linebreak.js.map +0 -1
  298. package/dist/features/converters/html/sync/converters/link.d.ts.map +0 -1
  299. package/dist/features/converters/html/sync/converters/link.js.map +0 -1
  300. package/dist/features/converters/html/sync/converters/list.d.ts.map +0 -1
  301. package/dist/features/converters/html/sync/converters/list.js.map +0 -1
  302. package/dist/features/converters/html/sync/converters/paragraph.d.ts.map +0 -1
  303. package/dist/features/converters/html/sync/converters/paragraph.js.map +0 -1
  304. package/dist/features/converters/html/sync/converters/tab.d.ts.map +0 -1
  305. package/dist/features/converters/html/sync/converters/tab.js.map +0 -1
  306. package/dist/features/converters/html/sync/converters/table.d.ts.map +0 -1
  307. package/dist/features/converters/html/sync/converters/table.js.map +0 -1
  308. package/dist/features/converters/html/sync/converters/text.d.ts.map +0 -1
  309. package/dist/features/converters/html/sync/converters/text.js.map +0 -1
  310. package/dist/features/converters/html/sync/converters/upload.d.ts.map +0 -1
  311. package/dist/features/converters/html/sync/converters/upload.js.map +0 -1
  312. package/dist/features/converters/html/sync/defaultConverters.d.ts.map +0 -1
  313. package/dist/features/converters/html/sync/defaultConverters.js.map +0 -1
  314. package/dist/features/converters/html/sync/index.d.ts.map +0 -1
  315. package/dist/features/converters/html/sync/index.js.map +0 -1
  316. package/dist/features/converters/html/sync/types.d.ts.map +0 -1
  317. package/dist/features/converters/html/sync/types.js.map +0 -1
  318. package/dist/features/converters/html_deprecated/converter/converters/linebreak.d.ts.map +0 -1
  319. package/dist/features/converters/html_deprecated/converter/converters/linebreak.js.map +0 -1
  320. package/dist/features/converters/html_deprecated/converter/converters/paragraph.d.ts.map +0 -1
  321. package/dist/features/converters/html_deprecated/converter/converters/paragraph.js.map +0 -1
  322. package/dist/features/converters/html_deprecated/converter/converters/tab.d.ts.map +0 -1
  323. package/dist/features/converters/html_deprecated/converter/converters/tab.js.map +0 -1
  324. package/dist/features/converters/html_deprecated/converter/converters/text.d.ts.map +0 -1
  325. package/dist/features/converters/html_deprecated/converter/converters/text.js.map +0 -1
  326. package/dist/features/converters/html_deprecated/converter/defaultConverters.d.ts.map +0 -1
  327. package/dist/features/converters/html_deprecated/converter/defaultConverters.js.map +0 -1
  328. package/dist/features/converters/html_deprecated/converter/index.d.ts.map +0 -1
  329. package/dist/features/converters/html_deprecated/converter/index.js.map +0 -1
  330. package/dist/features/converters/html_deprecated/converter/types.d.ts.map +0 -1
  331. package/dist/features/converters/html_deprecated/converter/types.js.map +0 -1
  332. package/dist/features/converters/html_deprecated/field/index.d.ts.map +0 -1
  333. package/dist/features/converters/html_deprecated/field/index.js.map +0 -1
  334. package/dist/features/converters/html_deprecated/index.d.ts.map +0 -1
  335. package/dist/features/converters/html_deprecated/index.js.map +0 -1
  336. package/dist/features/converters/jsx/Component/index.d.ts.map +0 -1
  337. package/dist/features/converters/jsx/Component/index.js.map +0 -1
  338. package/dist/features/converters/jsx/converter/converters/blockquote.d.ts.map +0 -1
  339. package/dist/features/converters/jsx/converter/converters/blockquote.js.map +0 -1
  340. package/dist/features/converters/jsx/converter/converters/heading.d.ts.map +0 -1
  341. package/dist/features/converters/jsx/converter/converters/heading.js.map +0 -1
  342. package/dist/features/converters/jsx/converter/converters/horizontalRule.d.ts.map +0 -1
  343. package/dist/features/converters/jsx/converter/converters/horizontalRule.js.map +0 -1
  344. package/dist/features/converters/jsx/converter/converters/linebreak.d.ts.map +0 -1
  345. package/dist/features/converters/jsx/converter/converters/linebreak.js.map +0 -1
  346. package/dist/features/converters/jsx/converter/converters/link.d.ts.map +0 -1
  347. package/dist/features/converters/jsx/converter/converters/link.js.map +0 -1
  348. package/dist/features/converters/jsx/converter/converters/list.d.ts.map +0 -1
  349. package/dist/features/converters/jsx/converter/converters/list.js.map +0 -1
  350. package/dist/features/converters/jsx/converter/converters/paragraph.d.ts.map +0 -1
  351. package/dist/features/converters/jsx/converter/converters/paragraph.js.map +0 -1
  352. package/dist/features/converters/jsx/converter/converters/tab.d.ts.map +0 -1
  353. package/dist/features/converters/jsx/converter/converters/tab.js.map +0 -1
  354. package/dist/features/converters/jsx/converter/converters/table.d.ts.map +0 -1
  355. package/dist/features/converters/jsx/converter/converters/table.js.map +0 -1
  356. package/dist/features/converters/jsx/converter/converters/text.d.ts.map +0 -1
  357. package/dist/features/converters/jsx/converter/converters/text.js.map +0 -1
  358. package/dist/features/converters/jsx/converter/converters/upload.d.ts.map +0 -1
  359. package/dist/features/converters/jsx/converter/converters/upload.js.map +0 -1
  360. package/dist/features/converters/jsx/converter/defaultConverters.d.ts.map +0 -1
  361. package/dist/features/converters/jsx/converter/defaultConverters.js.map +0 -1
  362. package/dist/features/converters/jsx/converter/index.d.ts.map +0 -1
  363. package/dist/features/converters/jsx/converter/index.js.map +0 -1
  364. package/dist/features/converters/jsx/converter/types.d.ts.map +0 -1
  365. package/dist/features/converters/jsx/converter/types.js.map +0 -1
  366. /package/dist/exports/client/{RelationshipComponent-JPESGV4Q.js.map → RelationshipComponent-APF3CN47.js.map} +0 -0
  367. /package/dist/exports/client/{chunk-PUXDVIHC.js.map → chunk-Y2GOLUGU.js.map} +0 -0
  368. /package/dist/exports/client/{component-P5K7Z5NW.js.map → component-Y3OSWJM5.js.map} +0 -0
  369. /package/dist/exports/client/{componentInline-IBB73SHH.js.map → componentInline-ZB4EY7EQ.js.map} +0 -0
  370. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/blockquote.d.ts +0 -0
  371. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/blockquote.js +0 -0
  372. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/heading.d.ts +0 -0
  373. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/heading.js +0 -0
  374. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/horizontalRule.d.ts +0 -0
  375. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/horizontalRule.js +0 -0
  376. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/linebreak.d.ts +0 -0
  377. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/linebreak.js +0 -0
  378. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/link.d.ts +0 -0
  379. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/list.d.ts +0 -0
  380. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/paragraph.d.ts +0 -0
  381. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/paragraph.js +0 -0
  382. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/tab.d.ts +0 -0
  383. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/tab.js +0 -0
  384. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/table.d.ts +0 -0
  385. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/table.js +0 -0
  386. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/text.d.ts +0 -0
  387. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/text.js +0 -0
  388. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/upload.d.ts +0 -0
  389. /package/dist/features/converters/{html → lexicalToHtml}/async/converters/upload.js +0 -0
  390. /package/dist/features/converters/{html → lexicalToHtml}/async/defaultConverters.d.ts +0 -0
  391. /package/dist/features/converters/{html → lexicalToHtml}/async/defaultConverters.js +0 -0
  392. /package/dist/features/converters/{html → lexicalToHtml}/async/field/index.d.ts +0 -0
  393. /package/dist/features/converters/{html → lexicalToHtml}/async/index.d.ts +0 -0
  394. /package/dist/features/converters/{html → lexicalToHtml}/async/index.js +0 -0
  395. /package/dist/features/converters/{html → lexicalToHtml}/async/types.d.ts +0 -0
  396. /package/dist/features/converters/{html → lexicalToHtml}/async/types.js +0 -0
  397. /package/dist/features/converters/{html → lexicalToHtml}/shared/findConverterForNode.d.ts +0 -0
  398. /package/dist/features/converters/{html → lexicalToHtml}/shared/findConverterForNode.js +0 -0
  399. /package/dist/features/converters/{html → lexicalToHtml}/shared/types.d.ts +0 -0
  400. /package/dist/features/converters/{html → lexicalToHtml}/shared/types.js +0 -0
  401. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/blockquote.d.ts +0 -0
  402. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/blockquote.js +0 -0
  403. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/heading.d.ts +0 -0
  404. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/heading.js +0 -0
  405. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/horizontalRule.d.ts +0 -0
  406. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/horizontalRule.js +0 -0
  407. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/linebreak.d.ts +0 -0
  408. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/linebreak.js +0 -0
  409. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/link.d.ts +0 -0
  410. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/list.d.ts +0 -0
  411. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/paragraph.d.ts +0 -0
  412. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/paragraph.js +0 -0
  413. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/tab.d.ts +0 -0
  414. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/tab.js +0 -0
  415. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/table.d.ts +0 -0
  416. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/table.js +0 -0
  417. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/text.d.ts +0 -0
  418. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/text.js +0 -0
  419. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/upload.d.ts +0 -0
  420. /package/dist/features/converters/{html → lexicalToHtml}/sync/converters/upload.js +0 -0
  421. /package/dist/features/converters/{html → lexicalToHtml}/sync/defaultConverters.d.ts +0 -0
  422. /package/dist/features/converters/{html → lexicalToHtml}/sync/defaultConverters.js +0 -0
  423. /package/dist/features/converters/{html → lexicalToHtml}/sync/index.d.ts +0 -0
  424. /package/dist/features/converters/{html → lexicalToHtml}/sync/index.js +0 -0
  425. /package/dist/features/converters/{html → lexicalToHtml}/sync/types.d.ts +0 -0
  426. /package/dist/features/converters/{html → lexicalToHtml}/sync/types.js +0 -0
  427. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/converters/linebreak.d.ts +0 -0
  428. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/converters/linebreak.js +0 -0
  429. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/converters/paragraph.d.ts +0 -0
  430. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/converters/paragraph.js +0 -0
  431. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/converters/tab.d.ts +0 -0
  432. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/converters/tab.js +0 -0
  433. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/converters/text.d.ts +0 -0
  434. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/converters/text.js +0 -0
  435. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/defaultConverters.d.ts +0 -0
  436. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/defaultConverters.js +0 -0
  437. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/index.d.ts +0 -0
  438. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/index.js +0 -0
  439. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/types.d.ts +0 -0
  440. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/converter/types.js +0 -0
  441. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/field/index.d.ts +0 -0
  442. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/field/index.js +0 -0
  443. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/index.d.ts +0 -0
  444. /package/dist/features/converters/{html_deprecated → lexicalToHtml_deprecated}/index.js +0 -0
  445. /package/dist/features/converters/{jsx → lexicalToJSX}/Component/index.d.ts +0 -0
  446. /package/dist/features/converters/{jsx → lexicalToJSX}/Component/index.js +0 -0
  447. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/blockquote.d.ts +0 -0
  448. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/blockquote.js +0 -0
  449. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/heading.d.ts +0 -0
  450. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/heading.js +0 -0
  451. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/horizontalRule.d.ts +0 -0
  452. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/horizontalRule.js +0 -0
  453. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/linebreak.d.ts +0 -0
  454. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/linebreak.js +0 -0
  455. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/link.d.ts +0 -0
  456. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/link.js +0 -0
  457. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/list.d.ts +0 -0
  458. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/list.js +0 -0
  459. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/paragraph.d.ts +0 -0
  460. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/paragraph.js +0 -0
  461. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/tab.d.ts +0 -0
  462. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/tab.js +0 -0
  463. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/table.d.ts +0 -0
  464. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/table.js +0 -0
  465. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/text.d.ts +0 -0
  466. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/text.js +0 -0
  467. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/upload.d.ts +0 -0
  468. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/converters/upload.js +0 -0
  469. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/defaultConverters.d.ts +0 -0
  470. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/defaultConverters.js +0 -0
  471. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/index.d.ts +0 -0
  472. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/index.js +0 -0
  473. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/types.d.ts +0 -0
  474. /package/dist/features/converters/{jsx → lexicalToJSX}/converter/types.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownExport.js","names":["$getRoot","$isDecoratorNode","$isElementNode","$isLineBreakNode","$isTextNode","isEmptyParagraph","transformersByType","createMarkdownExport","transformers","shouldPreserveNewLines","byType","elementTransformers","multilineElement","element","isNewlineDelimited","textFormatTransformers","textFormat","filter","transformer","format","length","sort","a","b","includes","node","output","children","getChildren","forEach","child","i","result","exportTopLevelElements","textMatch","push","concat","join","textTransformersIndex","textMatchTransformers","export","_node","exportChildren","getTextContent","unclosedTags","unclosableTags","mainLoop","parentNode","textNode","textContent","exportTextFormat","textTransformers","frozenString","trim","openingTags","closingTagsBefore","closingTagsAfter","prevNode","getTextSibling","nextNode","applied","Set","tag","hasFormat","has","add","find","unclosedTag","nodeHasFormat","nextNodeHasFormat","unhandledUnclosedTags","pop","replace","backward","sibling","getPreviousSibling","getNextSibling","parent","getParentOrThrow","isInline","descendant","getLastDescendant","getFirstDescendant"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownExport.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { ElementNode, LexicalNode, TextFormatType, TextNode } from 'lexical'\n\nimport { $getRoot, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isTextNode } from 'lexical'\n\nimport type {\n ElementTransformer,\n MultilineElementTransformer,\n TextFormatTransformer,\n TextMatchTransformer,\n Transformer,\n} from './MarkdownTransformers.js'\n\nimport { isEmptyParagraph, transformersByType } from './utils.js'\n\n/**\n * Renders string from markdown. The selection is moved to the start after the operation.\n */\nexport function createMarkdownExport(\n transformers: Array<Transformer>,\n shouldPreserveNewLines: boolean = false,\n): (node?: ElementNode) => string {\n const byType = transformersByType(transformers)\n const elementTransformers = [...byType.multilineElement, ...byType.element]\n const isNewlineDelimited = !shouldPreserveNewLines\n\n // Export only uses text formats that are responsible for single format\n // e.g. it will filter out *** (bold, italic) and instead use separate ** and *\n const textFormatTransformers = byType.textFormat\n .filter((transformer) => transformer.format.length === 1)\n // Make sure all text transformers that contain 'code' in their format are at the end of the array. Otherwise, formatted code like\n // <strong><code>code</code></strong> will be exported as `**Bold Code**`, as the code format will be applied first, and the bold format\n // will be applied second and thus skipped entirely, as the code format will prevent any further formatting.\n .sort((a, b) => {\n if (a.format.includes('code') && !b.format.includes('code')) {\n return 1\n } else if (!a.format.includes('code') && b.format.includes('code')) {\n return -1\n } else {\n return 0\n }\n })\n\n return (node) => {\n const output: string[] = []\n const children = (node || $getRoot()).getChildren()\n\n children.forEach((child, i) => {\n const result = exportTopLevelElements(\n child,\n elementTransformers,\n textFormatTransformers,\n byType.textMatch,\n )\n\n if (result != null) {\n output.push(\n // separate consecutive group of texts with a line break: eg. [\"hello\", \"world\"] -> [\"hello\", \"/nworld\"]\n isNewlineDelimited &&\n i > 0 &&\n !isEmptyParagraph(child) &&\n !isEmptyParagraph(children[i - 1]!)\n ? '\\n'.concat(result)\n : result,\n )\n }\n })\n // Ensure consecutive groups of texts are at least \\n\\n apart while each empty paragraph render as a newline.\n // Eg. [\"hello\", \"\", \"\", \"hi\", \"\\nworld\"] -> \"hello\\n\\n\\nhi\\n\\nworld\"\n return output.join('\\n')\n }\n}\n\nfunction exportTopLevelElements(\n node: LexicalNode,\n elementTransformers: Array<ElementTransformer | MultilineElementTransformer>,\n textTransformersIndex: Array<TextFormatTransformer>,\n textMatchTransformers: Array<TextMatchTransformer>,\n): null | string {\n for (const transformer of elementTransformers) {\n if (!transformer.export) {\n continue\n }\n const result = transformer.export(node, (_node) =>\n exportChildren(_node, textTransformersIndex, textMatchTransformers),\n )\n\n if (result != null) {\n return result\n }\n }\n\n if ($isElementNode(node)) {\n return exportChildren(node, textTransformersIndex, textMatchTransformers)\n } else if ($isDecoratorNode(node)) {\n return node.getTextContent()\n } else {\n return null\n }\n}\n\nfunction exportChildren(\n node: ElementNode,\n textTransformersIndex: Array<TextFormatTransformer>,\n textMatchTransformers: Array<TextMatchTransformer>,\n unclosedTags?: Array<{ format: TextFormatType; tag: string }>,\n unclosableTags?: Array<{ format: TextFormatType; tag: string }>,\n): string {\n const output = []\n const children = node.getChildren()\n // keep track of unclosed tags from the very beginning\n if (!unclosedTags) {\n unclosedTags = []\n }\n if (!unclosableTags) {\n unclosableTags = []\n }\n\n mainLoop: for (const child of children) {\n for (const transformer of textMatchTransformers) {\n if (!transformer.export) {\n continue\n }\n\n const result = transformer.export(\n child,\n (parentNode) =>\n exportChildren(\n parentNode,\n textTransformersIndex,\n textMatchTransformers,\n unclosedTags,\n // Add current unclosed tags to the list of unclosable tags - we don't want nested tags from\n // textmatch transformers to close the outer ones, as that may result in invalid markdown.\n // E.g. **text [text**](https://lexical.io)\n // is invalid markdown, as the closing ** is inside the link.\n //\n [...unclosableTags, ...unclosedTags],\n ),\n (textNode, textContent) =>\n exportTextFormat(\n textNode,\n textContent,\n textTransformersIndex,\n unclosedTags,\n unclosableTags,\n ),\n )\n\n if (result != null) {\n output.push(result)\n continue mainLoop\n }\n }\n\n if ($isLineBreakNode(child)) {\n output.push('\\n')\n } else if ($isTextNode(child)) {\n output.push(\n exportTextFormat(\n child,\n child.getTextContent(),\n textTransformersIndex,\n unclosedTags,\n unclosableTags,\n ),\n )\n } else if ($isElementNode(child)) {\n // empty paragraph returns \"\"\n output.push(\n exportChildren(\n child,\n textTransformersIndex,\n textMatchTransformers,\n unclosedTags,\n unclosableTags,\n ),\n )\n } else if ($isDecoratorNode(child)) {\n output.push(child.getTextContent())\n }\n }\n\n return output.join('')\n}\n\nfunction exportTextFormat(\n node: TextNode,\n textContent: string,\n textTransformers: Array<TextFormatTransformer>,\n // unclosed tags include the markdown tags that haven't been closed yet, and their associated formats\n unclosedTags: Array<{ format: TextFormatType; tag: string }>,\n unclosableTags?: Array<{ format: TextFormatType; tag: string }>,\n): string {\n // This function handles the case of a string looking like this: \" foo \"\n // Where it would be invalid markdown to generate: \"** foo **\"\n // We instead want to trim the whitespace out, apply formatting, and then\n // bring the whitespace back. So our returned string looks like this: \" **foo** \"\n const frozenString = textContent.trim()\n let output = frozenString\n // the opening tags to be added to the result\n let openingTags = ''\n // the closing tags to be added to the result\n let closingTagsBefore = ''\n let closingTagsAfter = ''\n\n const prevNode = getTextSibling(node, true)\n const nextNode = getTextSibling(node, false)\n\n const applied = new Set()\n\n for (const transformer of textTransformers) {\n const format = transformer.format[0]!\n const tag = transformer.tag\n\n // dedup applied formats\n if (hasFormat(node, format) && !applied.has(format)) {\n // Multiple tags might be used for the same format (*, _)\n applied.add(format)\n\n // append the tag to openningTags, if it's not applied to the previous nodes,\n // or the nodes before that (which would result in an unclosed tag)\n if (!hasFormat(prevNode, format) || !unclosedTags.find((element) => element.tag === tag)) {\n unclosedTags.push({ format, tag })\n openingTags += tag\n }\n }\n }\n\n // close any tags in the same order they were applied, if necessary\n for (let i = 0; i < unclosedTags.length; i++) {\n const unclosedTag = unclosedTags[i]!\n const nodeHasFormat = hasFormat(node, unclosedTag.format)\n const nextNodeHasFormat = hasFormat(nextNode, unclosedTag.format)\n\n // prevent adding closing tag if next sibling will do it\n if (nodeHasFormat && nextNodeHasFormat) {\n continue\n }\n\n const unhandledUnclosedTags = [...unclosedTags] // Shallow copy to avoid modifying the original array\n\n while (unhandledUnclosedTags.length > i) {\n const unclosedTag = unhandledUnclosedTags.pop()\n\n // If tag is unclosable, don't close it and leave it in the original array,\n // So that it can be closed when it's no longer unclosable\n if (\n unclosableTags &&\n unclosedTag &&\n unclosableTags.find((element) => element.tag === unclosedTag.tag)\n ) {\n continue\n }\n\n if (unclosedTag && typeof unclosedTag.tag === 'string') {\n if (!nodeHasFormat) {\n // Handles cases where the tag has not been closed before, e.g. if the previous node\n // was a text match transformer that did not account for closing tags of the next node (e.g. a link)\n closingTagsBefore += unclosedTag.tag\n } else if (!nextNodeHasFormat) {\n closingTagsAfter += unclosedTag.tag\n }\n }\n // Mutate the original array to remove the closed tag\n unclosedTags.pop()\n }\n break\n }\n\n output = openingTags + output + closingTagsAfter\n // Replace trimmed version of textContent ensuring surrounding whitespace is not modified\n return closingTagsBefore + textContent.replace(frozenString, () => output)\n}\n\n// Get next or previous text sibling a text node, including cases\n// when it's a child of inline element (e.g. link)\nfunction getTextSibling(node: TextNode, backward: boolean): null | TextNode {\n let sibling = backward ? node.getPreviousSibling() : node.getNextSibling()\n\n if (!sibling) {\n const parent = node.getParentOrThrow()\n\n if (parent.isInline()) {\n sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling()\n }\n }\n\n while (sibling) {\n if ($isElementNode(sibling)) {\n if (!sibling.isInline()) {\n break\n }\n\n const descendant = backward ? sibling.getLastDescendant() : sibling.getFirstDescendant()\n\n if ($isTextNode(descendant)) {\n return descendant\n } else {\n sibling = backward ? sibling.getPreviousSibling() : sibling.getNextSibling()\n }\n }\n\n if ($isTextNode(sibling)) {\n return sibling\n }\n\n if (!$isElementNode(sibling)) {\n return null\n }\n }\n\n return null\n}\n\nfunction hasFormat(node: LexicalNode | null | undefined, format: TextFormatType): boolean {\n return $isTextNode(node) && node.hasFormat(format)\n}\n"],"mappings":"AAAA;;;;;;GAUA,SAASA,QAAQ,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,EAAEC,WAAW,QAAQ;AAU1F,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ;AAErD;;;AAGA,OAAO,SAASC,qBACdC,YAAgC,EAChCC,sBAAA,GAAkC,KAAK;EAEvC,MAAMC,MAAA,GAASJ,kBAAA,CAAmBE,YAAA;EAClC,MAAMG,mBAAA,GAAsB,C,GAAID,MAAA,CAAOE,gBAAgB,E,GAAKF,MAAA,CAAOG,OAAO,CAAC;EAC3E,MAAMC,kBAAA,GAAqB,CAACL,sBAAA;EAE5B;EACA;EACA,MAAMM,sBAAA,GAAyBL,MAAA,CAAOM,UAAU,CAC7CC,MAAM,CAAEC,WAAA,IAAgBA,WAAA,CAAYC,MAAM,CAACC,MAAM,KAAK,EACvD;EACA;EACA;EAAA,CACCC,IAAI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extNode","isEmptyParagraph","transformersByType","createMarkdownExport","transformers","shouldPreserveNewLines","byType","elementTransformers","multilineElement","element","isNewlineDelimited","textFormatTransformers","textFormat","filter","transformer","format","length","sort","a","b","includes","node","output","children","getChildren","forEach","child","i","result","exportTopLevelElements","textMatch","push","concat","join","textTransformersIndex","textMatchTransformers","export","_node","exportChildren","getTextContent","unclosedTags","unclosableTags","mainLoop","parentNode","textNode","textContent","exportTextFormat","textTransformers","frozenString","trim","hasFormat","replace","openingTags","closingTagsBefore","closingTagsAfter","prevNode","getTextSibling","nextNode","applied","Set","tag","has","add","find","unclosedTag","nodeHasFormat","nextNodeHasFormat","unhandledUnclosedTags","pop","backward","sibling","getPreviousSibling","getNextSibling","parent","getParentOrThrow","isInline","descendant","getLastDescendant","getFirstDescendant"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownExport.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { ElementNode, LexicalNode, TextFormatType, TextNode } from 'lexical'\n\nimport { $getRoot, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isTextNode } from 'lexical'\n\nimport type {\n ElementTransformer,\n MultilineElementTransformer,\n TextFormatTransformer,\n TextMatchTransformer,\n Transformer,\n} from './MarkdownTransformers.js'\n\nimport { isEmptyParagraph, transformersByType } from './utils.js'\n\n/**\n * Renders string from markdown. The selection is moved to the start after the operation.\n */\nexport function createMarkdownExport(\n transformers: Array<Transformer>,\n shouldPreserveNewLines: boolean = false,\n): (node?: ElementNode) => string {\n const byType = transformersByType(transformers)\n const elementTransformers = [...byType.multilineElement, ...byType.element]\n const isNewlineDelimited = !shouldPreserveNewLines\n\n // Export only uses text formats that are responsible for single format\n // e.g. it will filter out *** (bold, italic) and instead use separate ** and *\n const textFormatTransformers = byType.textFormat\n .filter((transformer) => transformer.format.length === 1)\n // Make sure all text transformers that contain 'code' in their format are at the end of the array. Otherwise, formatted code like\n // <strong><code>code</code></strong> will be exported as `**Bold Code**`, as the code format will be applied first, and the bold format\n // will be applied second and thus skipped entirely, as the code format will prevent any further formatting.\n .sort((a, b) => {\n if (a.format.includes('code') && !b.format.includes('code')) {\n return 1\n } else if (!a.format.includes('code') && b.format.includes('code')) {\n return -1\n } else {\n return 0\n }\n })\n\n return (node) => {\n const output: string[] = []\n const children = (node || $getRoot()).getChildren()\n\n children.forEach((child, i) => {\n const result = exportTopLevelElements(\n child,\n elementTransformers,\n textFormatTransformers,\n byType.textMatch,\n )\n\n if (result != null) {\n output.push(\n // separate consecutive group of texts with a line break: eg. [\"hello\", \"world\"] -> [\"hello\", \"/nworld\"]\n isNewlineDelimited &&\n i > 0 &&\n !isEmptyParagraph(child) &&\n !isEmptyParagraph(children[i - 1]!)\n ? '\\n'.concat(result)\n : result,\n )\n }\n })\n // Ensure consecutive groups of texts are at least \\n\\n apart while each empty paragraph render as a newline.\n // Eg. [\"hello\", \"\", \"\", \"hi\", \"\\nworld\"] -> \"hello\\n\\n\\nhi\\n\\nworld\"\n return output.join('\\n')\n }\n}\n\nfunction exportTopLevelElements(\n node: LexicalNode,\n elementTransformers: Array<ElementTransformer | MultilineElementTransformer>,\n textTransformersIndex: Array<TextFormatTransformer>,\n textMatchTransformers: Array<TextMatchTransformer>,\n): null | string {\n for (const transformer of elementTransformers) {\n if (!transformer.export) {\n continue\n }\n const result = transformer.export(node, (_node) =>\n exportChildren(_node, textTransformersIndex, textMatchTransformers),\n )\n\n if (result != null) {\n return result\n }\n }\n\n if ($isElementNode(node)) {\n return exportChildren(node, textTransformersIndex, textMatchTransformers)\n } else if ($isDecoratorNode(node)) {\n return node.getTextContent()\n } else {\n return null\n }\n}\n\nfunction exportChildren(\n node: ElementNode,\n textTransformersIndex: Array<TextFormatTransformer>,\n textMatchTransformers: Array<TextMatchTransformer>,\n unclosedTags?: Array<{ format: TextFormatType; tag: string }>,\n unclosableTags?: Array<{ format: TextFormatType; tag: string }>,\n): string {\n const output = []\n const children = node.getChildren()\n // keep track of unclosed tags from the very beginning\n if (!unclosedTags) {\n unclosedTags = []\n }\n if (!unclosableTags) {\n unclosableTags = []\n }\n\n mainLoop: for (const child of children) {\n for (const transformer of textMatchTransformers) {\n if (!transformer.export) {\n continue\n }\n\n const result = transformer.export(\n child,\n (parentNode) =>\n exportChildren(\n parentNode,\n textTransformersIndex,\n textMatchTransformers,\n unclosedTags,\n // Add current unclosed tags to the list of unclosable tags - we don't want nested tags from\n // textmatch transformers to close the outer ones, as that may result in invalid markdown.\n // E.g. **text [text**](https://lexical.io)\n // is invalid markdown, as the closing ** is inside the link.\n //\n [...unclosableTags, ...unclosedTags],\n ),\n (textNode, textContent) =>\n exportTextFormat(\n textNode,\n textContent,\n textTransformersIndex,\n unclosedTags,\n unclosableTags,\n ),\n )\n\n if (result != null) {\n output.push(result)\n continue mainLoop\n }\n }\n\n if ($isLineBreakNode(child)) {\n output.push('\\n')\n } else if ($isTextNode(child)) {\n output.push(\n exportTextFormat(\n child,\n child.getTextContent(),\n textTransformersIndex,\n unclosedTags,\n unclosableTags,\n ),\n )\n } else if ($isElementNode(child)) {\n // empty paragraph returns \"\"\n output.push(\n exportChildren(\n child,\n textTransformersIndex,\n textMatchTransformers,\n unclosedTags,\n unclosableTags,\n ),\n )\n } else if ($isDecoratorNode(child)) {\n output.push(child.getTextContent())\n }\n }\n\n return output.join('')\n}\n\nfunction exportTextFormat(\n node: TextNode,\n textContent: string,\n textTransformers: Array<TextFormatTransformer>,\n // unclosed tags include the markdown tags that haven't been closed yet, and their associated formats\n unclosedTags: Array<{ format: TextFormatType; tag: string }>,\n unclosableTags?: Array<{ format: TextFormatType; tag: string }>,\n): string {\n // This function handles the case of a string looking like this: \" foo \"\n // Where it would be invalid markdown to generate: \"** foo **\"\n // We instead want to trim the whitespace out, apply formatting, and then\n // bring the whitespace back. So our returned string looks like this: \" **foo** \"\n const frozenString = textContent.trim()\n let output = frozenString\n\n if (!node.hasFormat('code')) {\n // Escape any markdown characters in the text content\n output = output.replace(/([*_`~\\\\])/g, '\\\\$1')\n }\n\n // the opening tags to be added to the result\n let openingTags = ''\n // the closing tags to be added to the result\n let closingTagsBefore = ''\n let closingTagsAfter = ''\n\n const prevNode = getTextSibling(node, true)\n const nextNode = getTextSibling(node, false)\n\n const applied = new Set()\n\n for (const transformer of textTransformers) {\n const format = transformer.format[0]!\n const tag = transformer.tag\n\n // dedup applied formats\n if (hasFormat(node, format) && !applied.has(format)) {\n // Multiple tags might be used for the same format (*, _)\n applied.add(format)\n\n // append the tag to openningTags, if it's not applied to the previous nodes,\n // or the nodes before that (which would result in an unclosed tag)\n if (!hasFormat(prevNode, format) || !unclosedTags.find((element) => element.tag === tag)) {\n unclosedTags.push({ format, tag })\n openingTags += tag\n }\n }\n }\n\n // close any tags in the same order they were applied, if necessary\n for (let i = 0; i < unclosedTags.length; i++) {\n const unclosedTag = unclosedTags[i]!\n const nodeHasFormat = hasFormat(node, unclosedTag.format)\n const nextNodeHasFormat = hasFormat(nextNode, unclosedTag.format)\n\n // prevent adding closing tag if next sibling will do it\n if (nodeHasFormat && nextNodeHasFormat) {\n continue\n }\n\n const unhandledUnclosedTags = [...unclosedTags] // Shallow copy to avoid modifying the original array\n\n while (unhandledUnclosedTags.length > i) {\n const unclosedTag = unhandledUnclosedTags.pop()\n\n // If tag is unclosable, don't close it and leave it in the original array,\n // So that it can be closed when it's no longer unclosable\n if (\n unclosableTags &&\n unclosedTag &&\n unclosableTags.find((element) => element.tag === unclosedTag.tag)\n ) {\n continue\n }\n\n if (unclosedTag && typeof unclosedTag.tag === 'string') {\n if (!nodeHasFormat) {\n // Handles cases where the tag has not been closed before, e.g. if the previous node\n // was a text match transformer that did not account for closing tags of the next node (e.g. a link)\n closingTagsBefore += unclosedTag.tag\n } else if (!nextNodeHasFormat) {\n closingTagsAfter += unclosedTag.tag\n }\n }\n // Mutate the original array to remove the closed tag\n unclosedTags.pop()\n }\n break\n }\n\n output = openingTags + output + closingTagsAfter\n // Replace trimmed version of textContent ensuring surrounding whitespace is not modified\n return closingTagsBefore + textContent.replace(frozenString, () => output)\n}\n\n// Get next or previous text sibling a text node, including cases\n// when it's a child of inline element (e.g. link)\nfunction getTextSibling(node: TextNode, backward: boolean): null | TextNode {\n let sibling = backward ? node.getPreviousSibling() : node.getNextSibling()\n\n if (!sibling) {\n const parent = node.getParentOrThrow()\n\n if (parent.isInline()) {\n sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling()\n }\n }\n\n while (sibling) {\n if ($isElementNode(sibling)) {\n if (!sibling.isInline()) {\n break\n }\n\n const descendant = backward ? sibling.getLastDescendant() : sibling.getFirstDescendant()\n\n if ($isTextNode(descendant)) {\n return descendant\n } else {\n sibling = backward ? sibling.getPreviousSibling() : sibling.getNextSibling()\n }\n }\n\n if ($isTextNode(sibling)) {\n return sibling\n }\n\n if (!$isElementNode(sibling)) {\n return null\n }\n }\n\n return null\n}\n\nfunction hasFormat(node: LexicalNode | null | undefined, format: TextFormatType): boolean {\n return $isTextNode(node) && node.hasFormat(format)\n}\n"],"mappings":"AAAA;;;;;;GAUA,SAASA,QAAQ,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,EAAEC,WAAW,QAAQ;AAU1F,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ;AAErD;;;AAGA,OAAO,SAASC,qBACdC,YAAgC,EAChCC,sBAAA,GAAkC,KAAK;EAEvC,MAAMC,MAAA,GAASJ,kBAAA,CAAmBE,YAAA;EAClC,MAAMG,mBAAA,GAAsB,C,GAAID,MAAA,CAAOE,gBAAgB,E,GAAKF,MAAA,CAAOG,OAAO,CAAC;EAC3E,MAAMC,kBAAA,GAAqB,CAACL,sBAAA;EAE5B;EACA;EACA,MAAMM,sBAAA,GAAyBL,MAAA,CAAOM,UAAU,CAC7CC,MAAM,CAAEC,WAAA,IAAgBA,WAAA,CAAYC,MAAM,CAACC,MAAM,KAAK,EACvD;EACA;EACA;EAAA,CACCC,IAAI,CA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,SAAS,CAACnC,MAAA;AAC7C","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownImport.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/MarkdownImport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAc1C,OAAO,KAAK,EAGV,qBAAqB,EAErB,WAAW,EACZ,MAAM,2BAA2B,CAAA;AAMlC,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IACjD,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACtD,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAA;CACnE,CAAC,CAAA;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,EAChC,sBAAsB,UAAQ,GAC7B,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,IAAI,CAyCtD"}
1
+ {"version":3,"file":"MarkdownImport.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/MarkdownImport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAe1C,OAAO,KAAK,EAGV,qBAAqB,EAErB,WAAW,EACZ,MAAM,2BAA2B,CAAA;AAKlC,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IACjD,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACtD,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAA;CACnE,CAAC,CAAA;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,EAChC,sBAAsB,UAAQ,GAC7B,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,IAAI,CAyCtD"}
@@ -7,8 +7,7 @@
7
7
  */import { $isListItemNode, $isListNode } from '@lexical/list';
8
8
  import { $isQuoteNode } from '@lexical/rich-text';
9
9
  import { $findMatchingParent } from '@lexical/utils';
10
- import { $createLineBreakNode, $createParagraphNode, $createTextNode, $getRoot, $getSelection, $isParagraphNode } from 'lexical';
11
- import { IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI } from '../../../lexical/utils/environment.js';
10
+ import { $createLineBreakNode, $createParagraphNode, $createTextNode, $getRoot, $getSelection, $isParagraphNode, $isTextNode } from 'lexical';
12
11
  import { importTextTransformers } from './importTextTransformers.js';
13
12
  import { isEmptyParagraph, transformersByType } from './utils.js';
14
13
  /**
@@ -149,6 +148,14 @@ function $importBlocks(lineText, rootNode, elementTransformers, textFormatTransf
149
148
  }
150
149
  }
151
150
  importTextTransformers(textNode, textFormatTransformersIndex, textMatchTransformers);
151
+ // Go through every text node in the element node and handle escape characters
152
+ for (const child of elementNode.getChildren()) {
153
+ if ($isTextNode(child)) {
154
+ const textContent = child.getTextContent();
155
+ const escapedText = textContent.replace(/\\([*_`~])/g, '$1');
156
+ child.setTextContent(escapedText);
157
+ }
158
+ }
152
159
  // If no transformer found and we left with original paragraph node
153
160
  // can check if its content can be appended to the previous node
154
161
  // if it's a paragraph, quote or list
@@ -183,17 +190,20 @@ function createTextFormatTransformersIndex(textTransformers) {
183
190
  transformersByTag[tag] = transformer;
184
191
  const tagRegExp = tag.replace(/([*^+])/g, '\\$1');
185
192
  openTagsRegExp.push(tagRegExp);
186
- if (IS_SAFARI || IS_IOS || IS_APPLE_WEBKIT) {
187
- fullMatchRegExpByTag[tag] = new RegExp(`(${tagRegExp})(?![${tagRegExp}\\s])(.*?[^${tagRegExp}\\s])${tagRegExp}(?!${tagRegExp})`);
188
- } else {
193
+ // Single-char tag (e.g. "*"),
194
+ if (tag.length === 1) {
189
195
  fullMatchRegExpByTag[tag] = new RegExp(`(?<![\\\\${tagRegExp}])(${tagRegExp})((\\\\${tagRegExp})?.*?[^${tagRegExp}\\s](\\\\${tagRegExp})?)((?<!\\\\)|(?<=\\\\\\\\))(${tagRegExp})(?![\\\\${tagRegExp}])`);
196
+ } else {
197
+ // Multi‐char tags (e.g. "**")
198
+ fullMatchRegExpByTag[tag] = new RegExp(`(?<!\\\\)(${tagRegExp})((\\\\${tagRegExp})?.*?[^\\s](\\\\${tagRegExp})?)((?<!\\\\)|(?<=\\\\\\\\))(${tagRegExp})(?!\\\\)`);
190
199
  }
191
200
  }
192
201
  return {
193
202
  // Reg exp to find open tag + content + close tag
194
203
  fullMatchRegExpByTag,
195
- // Reg exp to find opening tags
196
- openTagsRegExp: new RegExp((IS_SAFARI || IS_IOS || IS_APPLE_WEBKIT ? '' : `${escapeRegExp}`) + '(' + openTagsRegExp.join('|') + ')', 'g'),
204
+ // Regexp to locate *any* potential opening tag (longest first).
205
+ // eslint-disable-next-line regexp/no-useless-character-class, regexp/no-empty-capturing-group, regexp/no-empty-group
206
+ openTagsRegExp: new RegExp(`${escapeRegExp}(${openTagsRegExp.join('|')})`, 'g'),
197
207
  transformersByTag
198
208
  };
199
209
  }
@@ -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","importTextTransformers","isEmptyParagraph","transformersByType","createMarkdownImport","transformers","shouldPreserveNewLines","byType","textFormatTransformersIndex","createTextFormatTransformersIndex","textFormat","markdownString","node","lines","split","linesLength","length","root","clear","i","lineText","imported","shiftedIndex","$importMultiline","multilineElement","$importBlocks","element","textMatch","children","getChildren","child","getChildrenSize","remove","selectStart","startLineIndex","multilineElementTransformers","rootNode","transformer","handleImportAfterStartMatch","regExpEnd","regExpStart","replace","startMatch","match","result","regexpEndRegex","regExp","isEndOptional","optional","endLineIndex","endMatch","index","linesInBetween","push","slice","line","text","elementTransformers","textMatchTransformers","textNode","elementNode","append","setTextContent","isAttached","previousNode","getPreviousSibling","targetNode","lastDescendant","getLastDescendant","getTextContentSize","splice","textTransformers","transformersByTag","fullMatchRegExpByTag","openTagsRegExp","escapeRegExp","tag","tagRegExp","RegExp","join"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownImport.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { ListItemNode } from '@lexical/list'\nimport type { ElementNode } from 'lexical'\n\nimport { $isListItemNode, $isListNode } from '@lexical/list'\nimport { $isQuoteNode } from '@lexical/rich-text'\nimport { $findMatchingParent } from '@lexical/utils'\nimport {\n $createLineBreakNode,\n $createParagraphNode,\n $createTextNode,\n $getRoot,\n $getSelection,\n $isParagraphNode,\n} from 'lexical'\n\nimport type {\n ElementTransformer,\n MultilineElementTransformer,\n TextFormatTransformer,\n TextMatchTransformer,\n Transformer,\n} from './MarkdownTransformers.js'\n\nimport { IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI } from '../../../lexical/utils/environment.js'\nimport { importTextTransformers } from './importTextTransformers.js'\nimport { isEmptyParagraph, transformersByType } from './utils.js'\n\nexport type TextFormatTransformersIndex = Readonly<{\n fullMatchRegExpByTag: Readonly<Record<string, RegExp>>\n openTagsRegExp: RegExp\n transformersByTag: Readonly<Record<string, TextFormatTransformer>>\n}>\n\n/**\n * Renders markdown from a string. The selection is moved to the start after the operation.\n */\nexport function createMarkdownImport(\n transformers: Array<Transformer>,\n shouldPreserveNewLines = false,\n): (markdownString: string, node?: ElementNode) => void {\n const byType = transformersByType(transformers)\n const textFormatTransformersIndex = createTextFormatTransformersIndex(byType.textFormat)\n\n return (markdownString, node) => {\n const lines = markdownString.split('\\n')\n const linesLength = lines.length\n const root = node || $getRoot()\n root.clear()\n\n for (let i = 0; i < linesLength; i++) {\n const lineText = lines[i]!\n\n const [imported, shiftedIndex] = $importMultiline(lines, i, byType.multilineElement, root)\n\n if (imported) {\n // If a multiline markdown element was imported, we don't want to process the lines that were part of it anymore.\n // There could be other sub-markdown elements (both multiline and normal ones) matching within this matched multiline element's children.\n // However, it would be the responsibility of the matched multiline transformer to decide how it wants to handle them.\n // We cannot handle those, as there is no way for us to know how to maintain the correct order of generated lexical nodes for possible children.\n i = shiftedIndex // Next loop will start from the line after the last line of the multiline element\n continue\n }\n\n $importBlocks(lineText, root, byType.element, textFormatTransformersIndex, byType.textMatch)\n }\n\n // By default, removing empty paragraphs as md does not really\n // allow empty lines and uses them as delimiter.\n // If you need empty lines set shouldPreserveNewLines = true.\n const children = root.getChildren()\n for (const child of children) {\n if (!shouldPreserveNewLines && isEmptyParagraph(child) && root.getChildrenSize() > 1) {\n child.remove()\n }\n }\n\n if ($getSelection() !== null) {\n root.selectStart()\n }\n }\n}\n\n/**\n *\n * @returns first element of the returned tuple is a boolean indicating if a multiline element was imported. The second element is the index of the last line that was processed.\n */\nfunction $importMultiline(\n lines: Array<string>,\n startLineIndex: number,\n multilineElementTransformers: Array<MultilineElementTransformer>,\n rootNode: ElementNode,\n): [boolean, number] {\n for (const transformer of multilineElementTransformers) {\n const { handleImportAfterStartMatch, regExpEnd, regExpStart, replace } = transformer\n\n const startMatch = lines[startLineIndex]?.match(regExpStart)\n if (!startMatch) {\n continue // Try next transformer\n }\n\n if (handleImportAfterStartMatch) {\n const result = handleImportAfterStartMatch({\n lines,\n rootNode,\n startLineIndex,\n startMatch,\n transformer,\n })\n if (result === null) {\n continue\n } else if (result) {\n return result\n }\n }\n\n const regexpEndRegex: RegExp | undefined =\n typeof regExpEnd === 'object' && 'regExp' in regExpEnd ? regExpEnd.regExp : regExpEnd\n\n const isEndOptional =\n regExpEnd && typeof regExpEnd === 'object' && 'optional' in regExpEnd\n ? regExpEnd.optional\n : !regExpEnd\n\n let endLineIndex = startLineIndex\n const linesLength = lines.length\n\n // check every single line for the closing match. It could also be on the same line as the opening match.\n while (endLineIndex < linesLength) {\n const endMatch = regexpEndRegex ? lines[endLineIndex]?.match(regexpEndRegex) : null\n if (!endMatch) {\n if (\n !isEndOptional ||\n (isEndOptional && endLineIndex < linesLength - 1) // Optional end, but didn't reach the end of the document yet => continue searching for potential closing match\n ) {\n endLineIndex++\n continue // Search next line for closing match\n }\n }\n\n // Now, check if the closing match matched is the same as the opening match.\n // If it is, we need to continue searching for the actual closing match.\n if (endMatch && startLineIndex === endLineIndex && endMatch.index === startMatch.index) {\n endLineIndex++\n continue // Search next line for closing match\n }\n\n // At this point, we have found the closing match. Next: calculate the lines in between open and closing match\n // This should not include the matches themselves, and be split up by lines\n const linesInBetween: string[] = []\n\n if (endMatch && startLineIndex === endLineIndex) {\n linesInBetween.push(lines[startLineIndex]!.slice(startMatch[0].length, -endMatch[0].length))\n } else {\n for (let i = startLineIndex; i <= endLineIndex; i++) {\n const line = lines[i]!\n if (i === startLineIndex) {\n const text = line.slice(startMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else if (i === endLineIndex && endMatch) {\n const text = line.slice(0, -endMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else {\n linesInBetween.push(line)\n }\n }\n }\n\n if (replace(rootNode, null, startMatch, endMatch!, linesInBetween, true) !== false) {\n // Return here. This $importMultiline function is run line by line and should only process a single multiline element at a time.\n return [true, endLineIndex]\n }\n\n // The replace function returned false, despite finding the matching open and close tags => this transformer does not want to handle it.\n // Thus, we continue letting the remaining transformers handle the passed lines of text from the beginning\n break\n }\n }\n\n // No multiline transformer handled this line successfully\n return [false, startLineIndex]\n}\n\nfunction $importBlocks(\n lineText: string,\n rootNode: ElementNode,\n elementTransformers: Array<ElementTransformer>,\n textFormatTransformersIndex: TextFormatTransformersIndex,\n textMatchTransformers: Array<TextMatchTransformer>,\n) {\n const textNode = $createTextNode(lineText)\n const elementNode = $createParagraphNode()\n elementNode.append(textNode)\n rootNode.append(elementNode)\n\n for (const { regExp, replace } of elementTransformers) {\n const match = lineText.match(regExp)\n\n if (match) {\n textNode.setTextContent(lineText.slice(match[0].length))\n if (replace(elementNode, [textNode], match, true) !== false) {\n break\n }\n }\n }\n\n importTextTransformers(textNode, textFormatTransformersIndex, textMatchTransformers)\n\n // If no transformer found and we left with original paragraph node\n // can check if its content can be appended to the previous node\n // if it's a paragraph, quote or list\n if (elementNode.isAttached() && lineText.length > 0) {\n const previousNode = elementNode.getPreviousSibling()\n if ($isParagraphNode(previousNode) || $isQuoteNode(previousNode) || $isListNode(previousNode)) {\n let targetNode: ListItemNode | null | typeof previousNode = previousNode\n\n if ($isListNode(previousNode)) {\n const lastDescendant = previousNode.getLastDescendant()\n if (lastDescendant == null) {\n targetNode = null\n } else {\n targetNode = $findMatchingParent(lastDescendant, $isListItemNode)\n }\n }\n\n if (targetNode != null && targetNode.getTextContentSize() > 0) {\n targetNode.splice(targetNode.getChildrenSize(), 0, [\n $createLineBreakNode(),\n ...elementNode.getChildren(),\n ])\n elementNode.remove()\n }\n }\n }\n}\n\nfunction createTextFormatTransformersIndex(\n textTransformers: Array<TextFormatTransformer>,\n): TextFormatTransformersIndex {\n const transformersByTag: Record<string, TextFormatTransformer> = {}\n const fullMatchRegExpByTag: Record<string, RegExp> = {}\n const openTagsRegExp: string[] = []\n const escapeRegExp = `(?<![\\\\\\\\])`\n\n for (const transformer of textTransformers) {\n const { tag } = transformer\n transformersByTag[tag] = transformer\n const tagRegExp = tag.replace(/([*^+])/g, '\\\\$1')\n openTagsRegExp.push(tagRegExp)\n\n if (IS_SAFARI || IS_IOS || IS_APPLE_WEBKIT) {\n fullMatchRegExpByTag[tag] = new RegExp(\n `(${tagRegExp})(?![${tagRegExp}\\\\s])(.*?[^${tagRegExp}\\\\s])${tagRegExp}(?!${tagRegExp})`,\n )\n } else {\n fullMatchRegExpByTag[tag] = new RegExp(\n `(?<![\\\\\\\\${tagRegExp}])(${tagRegExp})((\\\\\\\\${tagRegExp})?.*?[^${tagRegExp}\\\\s](\\\\\\\\${tagRegExp})?)((?<!\\\\\\\\)|(?<=\\\\\\\\\\\\\\\\))(${tagRegExp})(?![\\\\\\\\${tagRegExp}])`,\n )\n }\n }\n\n return {\n // Reg exp to find open tag + content + close tag\n fullMatchRegExpByTag,\n // Reg exp to find opening tags\n openTagsRegExp: new RegExp(\n (IS_SAFARI || IS_IOS || IS_APPLE_WEBKIT ? '' : `${escapeRegExp}`) +\n '(' +\n openTagsRegExp.join('|') +\n ')',\n 'g',\n ),\n transformersByTag,\n }\n}\n"],"mappings":"AAAA;;;;;;GAWA,SAASA,eAAe,EAAEC,WAAW,QAAQ;AAC7C,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;;;AAGA,OAAO,SAASC,qBACdC,YAAgC,EAChCC,sBAAA,GAAyB,KAAK;EAE9B,MAAMC,MAAA,GAASJ,kBAAA,CAAmBE,YAAA;EAClC,MAAMG,2BAAA,GAA8BC,iCAAA,CAAkCF,MAAA,CAAOG,UAAU;EAEvF,OAAO,CAACC,cAAA,EAAgBC,IAAA;IACtB,MAAMC,KAAA,GAAQF,cAAA,CAAeG,KAAK,CAAC;IACnC,MAAMC,WAAA,GAAcF,KAAA,CAAMG,MAAM;IAChC,MAAMC,IAAA,GAAOL,IAAA,IAAQjB,QAAA;IACrBsB,IAAA,CAAKC,KAAK;IAEV,KAAK,IAAIC,CAAA,GAAI,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AO,CAAC,YAAY;IAC1CiC,cAAA,CAAerB,IAAI,CAACwB,SAAA;IAEpB,IAAI7E,SAAA,IAAaD,MAAA,IAAUD,eAAA,EAAiB;MAC1C2E,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,CAAC9E,SAAA,IAAaD,MAAA,IAAUD,eAAA,GAAkB,KAAK,GAAG6E,YAAA,EAAc,IAC9D,MACAD,cAAA,CAAeK,IAAI,CAAC,OACpB,KACF;IAEFP;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"MarkdownImport.js","names":["$isListItemNode","$isListNode","$isQuoteNode","$findMatchingParent","$createLineBreakNode","$createParagraphNode","$createTextNode","$getRoot","$getSelection","$isParagraphNode","$isTextNode","importTextTransformers","isEmptyParagraph","transformersByType","createMarkdownImport","transformers","shouldPreserveNewLines","byType","textFormatTransformersIndex","createTextFormatTransformersIndex","textFormat","markdownString","node","lines","split","linesLength","length","root","clear","i","lineText","imported","shiftedIndex","$importMultiline","multilineElement","$importBlocks","element","textMatch","children","getChildren","child","getChildrenSize","remove","selectStart","startLineIndex","multilineElementTransformers","rootNode","transformer","handleImportAfterStartMatch","regExpEnd","regExpStart","replace","startMatch","match","result","regexpEndRegex","regExp","isEndOptional","optional","endLineIndex","endMatch","index","linesInBetween","push","slice","line","text","elementTransformers","textMatchTransformers","textNode","elementNode","append","setTextContent","textContent","getTextContent","escapedText","isAttached","previousNode","getPreviousSibling","targetNode","lastDescendant","getLastDescendant","getTextContentSize","splice","textTransformers","transformersByTag","fullMatchRegExpByTag","openTagsRegExp","escapeRegExp","tag","tagRegExp","RegExp","join"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownImport.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { ListItemNode } from '@lexical/list'\nimport type { ElementNode } from 'lexical'\n\nimport { $isListItemNode, $isListNode } from '@lexical/list'\nimport { $isQuoteNode } from '@lexical/rich-text'\nimport { $findMatchingParent } from '@lexical/utils'\nimport {\n $createLineBreakNode,\n $createParagraphNode,\n $createTextNode,\n $getRoot,\n $getSelection,\n $isParagraphNode,\n $isTextNode,\n} from 'lexical'\n\nimport type {\n ElementTransformer,\n MultilineElementTransformer,\n TextFormatTransformer,\n TextMatchTransformer,\n Transformer,\n} from './MarkdownTransformers.js'\n\nimport { importTextTransformers } from './importTextTransformers.js'\nimport { isEmptyParagraph, transformersByType } from './utils.js'\n\nexport type TextFormatTransformersIndex = Readonly<{\n fullMatchRegExpByTag: Readonly<Record<string, RegExp>>\n openTagsRegExp: RegExp\n transformersByTag: Readonly<Record<string, TextFormatTransformer>>\n}>\n\n/**\n * Renders markdown from a string. The selection is moved to the start after the operation.\n */\nexport function createMarkdownImport(\n transformers: Array<Transformer>,\n shouldPreserveNewLines = false,\n): (markdownString: string, node?: ElementNode) => void {\n const byType = transformersByType(transformers)\n const textFormatTransformersIndex = createTextFormatTransformersIndex(byType.textFormat)\n\n return (markdownString, node) => {\n const lines = markdownString.split('\\n')\n const linesLength = lines.length\n const root = node || $getRoot()\n root.clear()\n\n for (let i = 0; i < linesLength; i++) {\n const lineText = lines[i]!\n\n const [imported, shiftedIndex] = $importMultiline(lines, i, byType.multilineElement, root)\n\n if (imported) {\n // If a multiline markdown element was imported, we don't want to process the lines that were part of it anymore.\n // There could be other sub-markdown elements (both multiline and normal ones) matching within this matched multiline element's children.\n // However, it would be the responsibility of the matched multiline transformer to decide how it wants to handle them.\n // We cannot handle those, as there is no way for us to know how to maintain the correct order of generated lexical nodes for possible children.\n i = shiftedIndex // Next loop will start from the line after the last line of the multiline element\n continue\n }\n\n $importBlocks(lineText, root, byType.element, textFormatTransformersIndex, byType.textMatch)\n }\n\n // By default, removing empty paragraphs as md does not really\n // allow empty lines and uses them as delimiter.\n // If you need empty lines set shouldPreserveNewLines = true.\n const children = root.getChildren()\n for (const child of children) {\n if (!shouldPreserveNewLines && isEmptyParagraph(child) && root.getChildrenSize() > 1) {\n child.remove()\n }\n }\n\n if ($getSelection() !== null) {\n root.selectStart()\n }\n }\n}\n\n/**\n *\n * @returns first element of the returned tuple is a boolean indicating if a multiline element was imported. The second element is the index of the last line that was processed.\n */\nfunction $importMultiline(\n lines: Array<string>,\n startLineIndex: number,\n multilineElementTransformers: Array<MultilineElementTransformer>,\n rootNode: ElementNode,\n): [boolean, number] {\n for (const transformer of multilineElementTransformers) {\n const { handleImportAfterStartMatch, regExpEnd, regExpStart, replace } = transformer\n\n const startMatch = lines[startLineIndex]?.match(regExpStart)\n if (!startMatch) {\n continue // Try next transformer\n }\n\n if (handleImportAfterStartMatch) {\n const result = handleImportAfterStartMatch({\n lines,\n rootNode,\n startLineIndex,\n startMatch,\n transformer,\n })\n if (result === null) {\n continue\n } else if (result) {\n return result\n }\n }\n\n const regexpEndRegex: RegExp | undefined =\n typeof regExpEnd === 'object' && 'regExp' in regExpEnd ? regExpEnd.regExp : regExpEnd\n\n const isEndOptional =\n regExpEnd && typeof regExpEnd === 'object' && 'optional' in regExpEnd\n ? regExpEnd.optional\n : !regExpEnd\n\n let endLineIndex = startLineIndex\n const linesLength = lines.length\n\n // check every single line for the closing match. It could also be on the same line as the opening match.\n while (endLineIndex < linesLength) {\n const endMatch = regexpEndRegex ? lines[endLineIndex]?.match(regexpEndRegex) : null\n if (!endMatch) {\n if (\n !isEndOptional ||\n (isEndOptional && endLineIndex < linesLength - 1) // Optional end, but didn't reach the end of the document yet => continue searching for potential closing match\n ) {\n endLineIndex++\n continue // Search next line for closing match\n }\n }\n\n // Now, check if the closing match matched is the same as the opening match.\n // If it is, we need to continue searching for the actual closing match.\n if (endMatch && startLineIndex === endLineIndex && endMatch.index === startMatch.index) {\n endLineIndex++\n continue // Search next line for closing match\n }\n\n // At this point, we have found the closing match. Next: calculate the lines in between open and closing match\n // This should not include the matches themselves, and be split up by lines\n const linesInBetween: string[] = []\n\n if (endMatch && startLineIndex === endLineIndex) {\n linesInBetween.push(lines[startLineIndex]!.slice(startMatch[0].length, -endMatch[0].length))\n } else {\n for (let i = startLineIndex; i <= endLineIndex; i++) {\n const line = lines[i]!\n if (i === startLineIndex) {\n const text = line.slice(startMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else if (i === endLineIndex && endMatch) {\n const text = line.slice(0, -endMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else {\n linesInBetween.push(line)\n }\n }\n }\n\n if (replace(rootNode, null, startMatch, endMatch!, linesInBetween, true) !== false) {\n // Return here. This $importMultiline function is run line by line and should only process a single multiline element at a time.\n return [true, endLineIndex]\n }\n\n // The replace function returned false, despite finding the matching open and close tags => this transformer does not want to handle it.\n // Thus, we continue letting the remaining transformers handle the passed lines of text from the beginning\n break\n }\n }\n\n // No multiline transformer handled this line successfully\n return [false, startLineIndex]\n}\n\nfunction $importBlocks(\n lineText: string,\n rootNode: ElementNode,\n elementTransformers: Array<ElementTransformer>,\n textFormatTransformersIndex: TextFormatTransformersIndex,\n textMatchTransformers: Array<TextMatchTransformer>,\n) {\n const textNode = $createTextNode(lineText)\n const elementNode = $createParagraphNode()\n elementNode.append(textNode)\n rootNode.append(elementNode)\n\n for (const { regExp, replace } of elementTransformers) {\n const match = lineText.match(regExp)\n\n if (match) {\n textNode.setTextContent(lineText.slice(match[0].length))\n if (replace(elementNode, [textNode], match, true) !== false) {\n break\n }\n }\n }\n\n importTextTransformers(textNode, textFormatTransformersIndex, textMatchTransformers)\n\n // Go through every text node in the element node and handle escape characters\n for (const child of elementNode.getChildren()) {\n if ($isTextNode(child)) {\n const textContent = child.getTextContent()\n const escapedText = textContent.replace(/\\\\([*_`~])/g, '$1')\n child.setTextContent(escapedText)\n }\n }\n\n // If no transformer found and we left with original paragraph node\n // can check if its content can be appended to the previous node\n // if it's a paragraph, quote or list\n if (elementNode.isAttached() && lineText.length > 0) {\n const previousNode = elementNode.getPreviousSibling()\n if ($isParagraphNode(previousNode) || $isQuoteNode(previousNode) || $isListNode(previousNode)) {\n let targetNode: ListItemNode | null | typeof previousNode = previousNode\n\n if ($isListNode(previousNode)) {\n const lastDescendant = previousNode.getLastDescendant()\n if (lastDescendant == null) {\n targetNode = null\n } else {\n targetNode = $findMatchingParent(lastDescendant, $isListItemNode)\n }\n }\n\n if (targetNode != null && targetNode.getTextContentSize() > 0) {\n targetNode.splice(targetNode.getChildrenSize(), 0, [\n $createLineBreakNode(),\n ...elementNode.getChildren(),\n ])\n elementNode.remove()\n }\n }\n }\n}\n\nfunction createTextFormatTransformersIndex(\n textTransformers: Array<TextFormatTransformer>,\n): TextFormatTransformersIndex {\n const transformersByTag: Record<string, TextFormatTransformer> = {}\n const fullMatchRegExpByTag: Record<string, RegExp> = {}\n const openTagsRegExp: string[] = []\n const escapeRegExp = `(?<![\\\\\\\\])`\n\n for (const transformer of textTransformers) {\n const { tag } = transformer\n transformersByTag[tag] = transformer\n const tagRegExp = tag.replace(/([*^+])/g, '\\\\$1')\n openTagsRegExp.push(tagRegExp)\n\n // Single-char tag (e.g. \"*\"),\n if (tag.length === 1) {\n fullMatchRegExpByTag[tag] = new RegExp(\n `(?<![\\\\\\\\${tagRegExp}])(${tagRegExp})((\\\\\\\\${tagRegExp})?.*?[^${tagRegExp}\\\\s](\\\\\\\\${tagRegExp})?)((?<!\\\\\\\\)|(?<=\\\\\\\\\\\\\\\\))(${tagRegExp})(?![\\\\\\\\${tagRegExp}])`,\n )\n } else {\n // Multi‐char tags (e.g. \"**\")\n fullMatchRegExpByTag[tag] = new RegExp(\n `(?<!\\\\\\\\)(${tagRegExp})((\\\\\\\\${tagRegExp})?.*?[^\\\\s](\\\\\\\\${tagRegExp})?)((?<!\\\\\\\\)|(?<=\\\\\\\\\\\\\\\\))(${tagRegExp})(?!\\\\\\\\)`,\n )\n }\n }\n\n return {\n // Reg exp to find open tag + content + close tag\n fullMatchRegExpByTag,\n\n // Regexp to locate *any* potential opening tag (longest first).\n // eslint-disable-next-line regexp/no-useless-character-class, regexp/no-empty-capturing-group, regexp/no-empty-group\n openTagsRegExp: new RegExp(`${escapeRegExp}(${openTagsRegExp.join('|')})`, 'g'),\n transformersByTag,\n }\n}\n"],"mappings":"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,EAChBC,WAAW,QACN;AAUP,SAASC,sBAAsB,QAAQ;AACvC,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ;AAQrD;;;AAGA,OAAO,SAASC,qBACdC,YAAgC,EAChCC,sBAAA,GAAyB,KAAK;EAE9B,MAAMC,MAAA,GAASJ,kBAAA,CAAmBE,YAAA;EAClC,MAAMG,2BAAA,GAA8BC,iCAAA,CAAkCF,MAAA,CAAOG,UAAU;EAEvF,OAAO,CAACC,cAAA,EAAgBC,IAAA;IACtB,MAAMC,KAAA,GAAQF,cAAA,CAAeG,KAAK,CAAC;IACnC,MAAMC,WAAA,GAAcF,KAAA,CAAMG,MAAM;IAChC,MAAMC,IAAA,GAAOL,IAAA,IAAQf,QAAA;IACrBoB,IAAA,CAAKC,KAAK;IAEV,KAAK,IAAIC,CAAA,GAAI,GAAGA,CAAA,GAAIJ,WAAA,EAAaI,CAAA,IAAK;MACpC,MAAMC,QAAA,GAAWP,KA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AAa;EAElC,KAAK,MAAMzC,WAAA,IAAeqC,gBAAA,EAAkB;IAC1C,MAAM;MAAEK;IAAG,CAAE,GAAG1C,WAAA;IAChBsC,iBAAiB,CAACI,GAAA,CAAI,GAAG1C,WAAA;IACzB,MAAM2C,SAAA,GAAYD,GAAA,CAAItC,OAAO,CAAC,YAAY;IAC1CoC,cAAA,CAAexB,IAAI,CAAC2B,SAAA;IAEpB;IACA,IAAID,GAAA,CAAI/D,MAAM,KAAK,GAAG;MACpB4D,oBAAoB,CAACG,GAAA,CAAI,GAAG,IAAIE,MAAA,CAC9B,YAAYD,SAAA,MAAeA,SAAA,UAAmBA,SAAA,UAAmBA,SAAA,YAAqBA,SAAA,gCAAyCA,SAAA,YAAqBA,SAAA,IAAa;IAErK,OAAO;MACL;MACAJ,oBAAoB,CAACG,GAAA,CAAI,GAAG,IAAIE,MAAA,CAC9B,aAAaD,SAAA,UAAmBA,SAAA,mBAA4BA,SAAA,gCAAyCA,SAAA,WAAoB;IAE7H;EACF;EAEA,OAAO;IACL;IACAJ,oBAAA;IAEA;IACA;IACAC,cAAA,EAAgB,IAAII,MAAA,CAAO,GAAGH,YAAA,IAAgBD,cAAA,CAAeK,IAAI,CAAC,OAAO,EAAE;IAC3EP;EACF;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/richtext-lexical",
3
- "version": "3.29.0-internal.d2c9ba5",
3
+ "version": "3.29.0-internal.d74b919",
4
4
  "description": "The officially supported Lexical richtext adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -45,6 +45,11 @@
45
45
  "types": "./dist/exports/html-async/index.d.ts",
46
46
  "default": "./dist/exports/html-async/index.js"
47
47
  },
48
+ "./plaintext": {
49
+ "import": "./dist/exports/plaintext/index.js",
50
+ "types": "./dist/exports/plaintext/index.d.ts",
51
+ "default": "./dist/exports/plaintext/index.js"
52
+ },
48
53
  "./rsc": {
49
54
  "import": "./dist/exports/server/rsc.js",
50
55
  "types": "./dist/exports/server/rsc.d.ts",
@@ -335,23 +340,23 @@
335
340
  ]
336
341
  },
337
342
  "dependencies": {
338
- "@lexical/headless": "0.27.1",
339
- "@lexical/html": "0.27.1",
340
- "@lexical/link": "0.27.1",
341
- "@lexical/list": "0.27.1",
342
- "@lexical/mark": "0.27.1",
343
- "@lexical/react": "0.27.1",
344
- "@lexical/rich-text": "0.27.1",
345
- "@lexical/selection": "0.27.1",
346
- "@lexical/table": "0.27.1",
347
- "@lexical/utils": "0.27.1",
343
+ "@lexical/headless": "0.28.0",
344
+ "@lexical/html": "0.28.0",
345
+ "@lexical/link": "0.28.0",
346
+ "@lexical/list": "0.28.0",
347
+ "@lexical/mark": "0.28.0",
348
+ "@lexical/react": "0.28.0",
349
+ "@lexical/rich-text": "0.28.0",
350
+ "@lexical/selection": "0.28.0",
351
+ "@lexical/table": "0.28.0",
352
+ "@lexical/utils": "0.28.0",
348
353
  "@types/uuid": "10.0.0",
349
354
  "acorn": "8.12.1",
350
355
  "bson-objectid": "2.0.4",
351
356
  "dequal": "2.0.3",
352
357
  "escape-html": "1.0.3",
353
358
  "jsox": "1.2.121",
354
- "lexical": "0.27.1",
359
+ "lexical": "0.28.0",
355
360
  "mdast-util-from-markdown": "2.0.2",
356
361
  "mdast-util-mdx-jsx": "3.1.3",
357
362
  "micromark-extension-mdx-jsx": "3.0.1",
@@ -359,8 +364,8 @@
359
364
  "react-error-boundary": "4.1.2",
360
365
  "ts-essentials": "10.0.3",
361
366
  "uuid": "10.0.0",
362
- "@payloadcms/translations": "3.29.0-internal.d2c9ba5",
363
- "@payloadcms/ui": "3.29.0-internal.d2c9ba5"
367
+ "@payloadcms/translations": "3.29.0-internal.d74b919",
368
+ "@payloadcms/ui": "3.29.0-internal.d74b919"
364
369
  },
365
370
  "devDependencies": {
366
371
  "@babel/cli": "7.26.4",
@@ -368,7 +373,7 @@
368
373
  "@babel/preset-env": "7.26.7",
369
374
  "@babel/preset-react": "7.26.3",
370
375
  "@babel/preset-typescript": "7.26.0",
371
- "@lexical/eslint-plugin": "0.27.1",
376
+ "@lexical/eslint-plugin": "0.28.0",
372
377
  "@types/escape-html": "1.0.4",
373
378
  "@types/json-schema": "7.0.15",
374
379
  "@types/node": "22.5.4",
@@ -381,15 +386,15 @@
381
386
  "eslint-plugin-react-compiler": "19.0.0-beta-714736e-20250131",
382
387
  "swc-plugin-transform-remove-imports": "3.1.0",
383
388
  "@payloadcms/eslint-config": "3.28.0",
384
- "payload": "3.29.0-internal.d2c9ba5"
389
+ "payload": "3.29.0-internal.d74b919"
385
390
  },
386
391
  "peerDependencies": {
387
392
  "@faceless-ui/modal": "3.0.0-beta.2",
388
393
  "@faceless-ui/scroll-info": "2.0.0",
389
394
  "react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
390
395
  "react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
391
- "@payloadcms/next": "3.29.0-internal.d2c9ba5",
392
- "payload": "3.29.0-internal.d2c9ba5"
396
+ "@payloadcms/next": "3.29.0-internal.d74b919",
397
+ "payload": "3.29.0-internal.d74b919"
393
398
  },
394
399
  "engines": {
395
400
  "node": "^18.20.2 || >=20.9.0"
@@ -1,2 +0,0 @@
1
- "use client";import{c as Re,f as _,h as ke,i as we,j as Te,k as ve,l as De}from"./chunk-XO6X2M3F.js";import{a as Se,b as P}from"./chunk-3LGFOM34.js";import{jsx as F,jsxs as pe}from"react/jsx-runtime";import{FieldDescription as rn,FieldError as sn,FieldLabel as ln,RenderCustomComponent as gt,useEditDepth as an,useEffectEvent as cn,useField as un}from"@payloadcms/ui";import{mergeFieldStyles as dn}from"@payloadcms/ui/shared";import ht,{useCallback as yt,useEffect as xt,useMemo as mn,useState as Et}from"react";import{ErrorBoundary as fn}from"react-error-boundary";import"./bundled.css";import{jsx as O}from"react/jsx-runtime";import{LexicalComposer as tn}from"@lexical/react/LexicalComposer.js";import{useEditDepth as on}from"@payloadcms/ui";import*as mt from"react";import{useMemo as nn}from"react";import{c as Ko}from"react/compiler-runtime";import{jsx as b,jsxs as te}from"react/jsx-runtime";import{useLexicalComposerContext as Ho}from"@lexical/react/LexicalComposerContext.js";import{LexicalErrorBoundary as jo}from"@lexical/react/LexicalErrorBoundary.js";import{HistoryPlugin as zo}from"@lexical/react/LexicalHistoryPlugin.js";import{OnChangePlugin as Wo}from"@lexical/react/LexicalOnChangePlugin.js";import{RichTextPlugin as Yo}from"@lexical/react/LexicalRichTextPlugin.js";import{BLUR_COMMAND as Go,COMMAND_PRIORITY_LOW as ut,FOCUS_COMMAND as Vo}from"lexical";import*as Q from"react";import{useEffect as Uo,useState as qo}from"react";import{jsx as Me}from"react/jsx-runtime";import"react";var K=({anchorElem:t,clientProps:e,plugin:o})=>o.position==="floatingAnchorElem"&&t?o.Component&&Me(o.Component,{anchorElem:t,clientProps:e}):o.Component&&Me(o.Component,{clientProps:e});import{c as Pt}from"react/compiler-runtime";import{useLexicalComposerContext as St}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as oe,mergeRegister as Rt}from"@lexical/utils";import{$createNodeSelection as kt,$getEditor as X,$getNearestNodeFromDOMNode as wt,$getSelection as ne,$isDecoratorNode as H,$isElementNode as xe,$isLineBreakNode as Tt,$isNodeSelection as re,$isRangeSelection as Be,$isRootOrShadowRoot as vt,$isTextNode as Dt,$setSelection as Le,CLICK_COMMAND as Mt,COMMAND_PRIORITY_LOW as G,KEY_ARROW_DOWN_COMMAND as Bt,KEY_ARROW_UP_COMMAND as Lt,KEY_BACKSPACE_COMMAND as It,KEY_DELETE_COMMAND as At,SELECTION_CHANGE_COMMAND as _t}from"lexical";import{useEffect as Ot}from"react";function Ie(){let t=Pt(3),[e]=St(),o=Wt,r,n;return t[0]!==e?(r=()=>Rt(e.registerCommand(Mt,zt,G),e.registerCommand(At,o,G),e.registerCommand(It,o,G),e.registerCommand(_t,jt,G),e.registerCommand(Lt,Kt,G),e.registerCommand(Bt,Ft,G)),n=[e],t[0]=e,t[1]=r,t[2]=n):(r=t[1],n=t[2]),Ot(r,n),null}function Ft(t){let e=ne();if(re(e)){t.preventDefault();let i=e.getNodes()[0]?.getNextSibling();if(H(i)){let p=X().getElementByKey(i.getKey());return p&&Z({element:p,node:i}),!0}if(!xe(i))return!0;let l=i.getFirstDescendant()??i;return l&&(oe(l,ie)?.selectEnd(),t.preventDefault()),!0}if(!Be(e))return!1;let r=(e.isBackward()?e.anchor:e.focus).getNode(),n=oe(r,$t),c=n?.getNextSibling();if(!n||c!==Ae(n))return!1;if(H(c)){let i=X().getElementByKey(c.getKey());if(i)return Z({element:i,node:c}),t.preventDefault(),!0}return!1}function $t(t){return Ae(t)!==null}function Kt(t){let e=ne();if(re(e)){let i=e.getNodes()[0]?.getPreviousSibling();if(H(i)){let p=X().getElementByKey(i.getKey());return p?(Z({element:p,node:i}),t.preventDefault(),!0):!1}if(!xe(i))return!1;let l=i.getLastDescendant()??i;return l?(oe(l,ie)?.selectStart(),t.preventDefault(),!0):!1}if(!Be(e))return!1;let r=(e.isBackward()?e.anchor:e.focus).getNode(),n=oe(r,Ht),c=n?.getPreviousSibling();if(!n||c!==_e(n))return!1;if(H(c)){let i=X().getElementByKey(c.getKey());if(i)return Z({element:i,node:c}),t.preventDefault(),!0}return!1}function Ht(t){return _e(t)!==null}function jt(){let t=Vt();return document.querySelector(".decorator-selected")?.classList.remove("decorator-selected"),t?(t.element?.classList.add("decorator-selected"),!0):!1}function zt(t){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let e=Gt(t);if(!e)return!0;let{target:o}=t;return!(o instanceof HTMLElement)||o.isContentEditable||o.closest('button, textarea, input, .react-select, .code-editor, .no-select-decorator, [role="button"]')?Le(null):Z(e),!0}function Wt(t){let e=ne();return re(e)?(t.preventDefault(),e.getNodes().forEach(Yt),!0):!1}function Yt(t){t.remove()}function Gt(t){if(!(t.target instanceof HTMLElement))return;let e=t.target.closest('[data-lexical-decorator="true"]');if(!(e instanceof HTMLElement))return;let o=wt(e);return H(o)?{element:e,node:o}:void 0}function Vt(){let t=ne();if(!re(t))return;let e=t.getNodes();if(e.length!==1)return;let o=e[0];return H(o)?{decorator:o,element:X().getElementByKey(o.getKey())}:void 0}function Z({element:t,node:e}){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let o=kt();o.add(e.getKey()),Le(o),t.scrollIntoView({behavior:"smooth",block:"nearest"}),t.classList.add("decorator-selected")}function ie(t){if(H(t)&&!t.isInline())return!0;if(!xe(t)||vt(t))return!1;let e=t.getFirstChild(),o=e===null||Tt(e)||Dt(e)||e.isInline();return!t.isInline()&&t.canBeEmpty()!==!1&&o}function Ae(t){let e=t.getNextSibling();for(;e!==null;){if(ie(e))return e;e=e.getNextSibling()}return null}function _e(t){let e=t.getPreviousSibling();for(;e!==null;){if(ie(e))return e;e=e.getPreviousSibling()}return null}import{jsx as Ee}from"react/jsx-runtime";import{useLexicalComposerContext as Zt}from"@lexical/react/LexicalComposerContext.js";import{$createParagraphNode as eo,isHTMLElement as to}from"lexical";import*as Ke from"react";import{useCallback as oo,useEffect as $e,useRef as no,useState as ro}from"react";import{createPortal as io}from"react-dom";var V=(t,e,o,r,n=50,c=25)=>{let i=0;if(t&&!t.contains(r)){let{bottom:l,left:u,right:p,top:h}=t.getBoundingClientRect(),a=h+window.scrollY,s=l+window.scrollY;if(o<a-c||o>s+c||e<u-n||e>p+n)return-1;(e<u||e>p)&&(i=e<u?e-u:e-p)}return i};import{$getNodeByKey as le}from"lexical";function U(t){let e=t.getBoundingClientRect(),o=getComputedStyle(t).getPropertyValue("transform");if(!o||o==="none")return e;let r=o.split(",").pop();return e.y=e.y-Number(r?.replace(")","")),e}function se(t){let e=(u,p)=>u?parseFloat(window.getComputedStyle(u)[p]):0,{marginBottom:o,marginTop:r}=window.getComputedStyle(t),n=e(t.previousElementSibling,"marginBottom"),c=e(t.nextElementSibling,"marginTop"),i=Math.max(parseFloat(r),n);return{marginBottom:Math.max(parseFloat(o),c),marginTop:i}}import{$getRoot as Ut}from"lexical";function j(t){return t.getEditorState().read(()=>Ut().getChildrenKeys())}var qt=1,Jt=-1,Oe=0,B={props:null,result:null};function Qt(t,e,o=20){let r=t.x-e.x,n=t.y-e.y;return r*r+n*n<=o*o}function q(t){let{anchorElem:e,cache_threshold:o=20,editor:r,fuzzy:n=!1,horizontalOffset:c=0,point:{x:i,y:l},startIndex:u=0,useEdgeAsDefault:p=!1}=t;if(o>0&&B.props&&B.result&&B.props.fuzzy===t.fuzzy&&B.props.horizontalOffset===t.horizontalOffset&&B.props.useEdgeAsDefault===t.useEdgeAsDefault&&Qt(B.props.point,t.point,o))return B.result;let h=e.getBoundingClientRect(),a=j(r),s={blockElem:null,blockNode:null,distance:1/0,foundAtIndex:-1,isFoundNodeEmptyParagraph:!1};return r.getEditorState().read(()=>{if(p){let m=r.getElementByKey(a[0]),y=r.getElementByKey(a[a.length-1]);if(m&&y){let[d,f]=[U(m),U(y)];if(l<d.top?(s.blockElem=m,s.distance=d.top-l,s.blockNode=le(a[0]),s.foundAtIndex=0):l>f.bottom&&(s.distance=l-f.bottom,s.blockNode=le(a[a.length-1]),s.blockElem=y,s.foundAtIndex=a.length-1),s?.blockElem)return{blockElem:null,isFoundNodeEmptyParagraph:!1}}}let g=u,x=Oe;for(;g>=0&&g<a.length;){let m=a[g],y=r.getElementByKey(m);if(y===null)break;let d=new _(i+c,l),f=ve.fromDOMRect(U(y)),{marginBottom:E,marginTop:k}=se(y),R=f.generateNewRect({bottom:f.bottom+E,left:h.left,right:h.right,top:f.top-k}),{distance:S,isOnBottomSide:w,isOnTopSide:C}=R.distanceFromPoint(d);if(S===0){s.blockElem=y,s.blockNode=le(m),s.foundAtIndex=g,s.distance=S,s.blockNode&&s.blockNode.getType()==="paragraph"&&s.blockNode.getTextContent()===""&&(!n&&!t.returnEmptyParagraphs&&(s.blockElem=null,s.blockNode=null),s.isFoundNodeEmptyParagraph=!0);break}else n&&S<s.distance&&(s.blockElem=y,s.blockNode=le(m),s.distance=S,s.foundAtIndex=g);x===Oe&&(C?x=Jt:w?x=qt:x=1/0),g+=x}}),B.props=t,B.result={blockElem:s.blockElem,blockNode:s.blockNode,foundAtIndex:s.foundAtIndex,isFoundNodeEmptyParagraph:s.isFoundNodeEmptyParagraph},{blockElem:s.blockElem,blockNode:s.blockNode,foundAtIndex:s.foundAtIndex,isFoundNodeEmptyParagraph:s.isFoundNodeEmptyParagraph}}function ae(t,e){return!!t.closest(`.${e}`)}var Xt=["IMG","INPUT","TEXTAREA","SELECT","BUTTON","VIDEO","OBJECT","EMBED","IFRAME","HR"];function Fe(t){if(!t||Xt.includes(t.tagName)||t.offsetHeight===0||t.offsetWidth===0)return!1;let e=window.getComputedStyle(t);return!(e.display==="table-cell"||e.position==="absolute"||e.visibility==="hidden"||e.opacity==="0")}function ce(t,e,o,r=0){if(!t){e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)";return}let n=t.getBoundingClientRect(),c=window.getComputedStyle(t),i=e.getBoundingClientRect(),l=o.getBoundingClientRect(),u;if(["lexical-block","lexical-upload","lexical-relationship"].some(a=>t.firstElementChild?.classList.contains(a)))u=n.top+8-l.top;else{let a=Fe(t)?parseInt(c.lineHeight,10):0;u=n.top+(a-i.height)/2-l.top}let h=r;e.style.opacity="1",e.style.transform=`translate(${h}px, ${u}px)`}var so="add-block-menu",ue=1/0;function lo(t){return t===0?1/0:ue>=0&&ue<t?ue:Math.floor(t/2)}function ao(t,e,o){let r=e.parentElement,{editorConfig:n}=P(),c=n?.admin?.hideGutter?-24:12,i=no(null),[l,u]=ro(null);$e(()=>{function h(a){let s=a.target;if(!to(s))return;let g=V(r,a.pageX,a.pageY,s);if(g===-1){u(null);return}if(ae(s,so))return;let x=j(t),{blockElem:m,blockNode:y,foundAtIndex:d}=q({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-g,point:new _(a.x,a.y),returnEmptyParagraphs:!0,startIndex:lo(x.length),useEdgeAsDefault:!1});ue=d,m&&y&&(l?.node!==y||l?.elem!==m)&&u({elem:m,node:y})}return document?.addEventListener("mousemove",h),()=>{document?.removeEventListener("mousemove",h)}},[r,e,t,l]),$e(()=>{i.current&&l?.node&&ce(l?.elem,i.current,e,c)},[e,l,c]);let p=oo(h=>{let a=l;a?.node&&(t.update(()=>{let s=!0;if((a?.node.getType()!=="paragraph"||a.node.getTextContent()!=="")&&(s=!1),!s){let g=eo();a?.node.insertAfter(g),setTimeout(()=>{a={elem:t.getElementByKey(g.getKey()),node:g},u(a)},0)}}),setTimeout(()=>{t.update(()=>{t.focus(),a?.node&&"select"in a.node&&typeof a.node.select=="function"&&a.node.select()})},1),setTimeout(()=>{t.dispatchCommand(we,{node:a?.node})},2),h.stopPropagation(),h.preventDefault())},[t,l]);return io(Ee(Ke.Fragment,{children:Ee("button",{"aria-label":"Add block",className:"icon add-block-menu",onClick:h=>{p(h)},ref:i,type:"button",children:Ee("div",{className:o?"icon":""})})}),e)}function He(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=Zt();return ao(r,o,r._editable)}import{jsx as de,jsxs as uo}from"react/jsx-runtime";import{useLexicalComposerContext as mo}from"@lexical/react/LexicalComposerContext.js";import{eventFiles as We}from"@lexical/rich-text";import{$getNearestNodeFromDOMNode as Ye,$getNodeByKey as fo,isHTMLElement as Ce}from"lexical";import*as Je from"react";import{useEffect as be,useRef as me,useState as Ge}from"react";import{createPortal as po}from"react-dom";var je=0,co=-24;var z=0;function ze(t,e,o,r,n,c,i,l,u,p=!1){let{height:h,top:a}=r.getBoundingClientRect(),{top:s,width:g}=i.getBoundingClientRect(),{marginBottom:x,marginTop:m}=se(r),y=a,d=c>=a+h/2+window.scrollY,f=!1;if(n?.elem)if(r!==n?.elem)(d&&n?.elem&&n?.elem===r.nextElementSibling||!d&&n?.elem&&n?.elem===r.previousElementSibling)&&(z++,z<200&&(f=!0));else{z++;let S=n?.boundingBox?.y,w=r.getBoundingClientRect().y;(d===n?.isBelow&&S===w||z<200)&&(f=!1)}if(f)return{isBelow:d,willStayInSamePosition:f};p?y+=h/2:d?y+=h+x/2:y-=m/2;let E=0;p||(d?E=-je:E=je);let k=y-s+E,R=co-e;return o.style.width=`calc(${g}px - ${t})`,o.style.opacity=".8",o.style.transform=`translate(${R}px, calc(${k}px - 2px))`,n?.elem&&(n.elem.style.opacity="",n?.elem===r?d?n.elem.style.marginTop="":n.elem.style.marginBottom="":(n.elem.style.marginBottom="",n.elem.style.marginTop="")),z=0,{isBelow:d,willStayInSamePosition:f}}var go="draggable-block-menu",Ve="application/x-lexical-drag-block",ee=1/0;function Ue(t){return t===0?1/0:ee>=0&&ee<t?ee:Math.floor(t/2)}function ho(t,e){let{transform:o}=e.style;t.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=o})}function qe(t,e){t&&(t.style.opacity="0"),e&&(e.style.opacity="",e.style.marginBottom="",e.style.marginTop="")}function yo(t,e,o){let r=e.parentElement,n=me(null),c=me(null),i=me(null),l=me(!1),[u,p]=Ge(null),[h,a]=Ge(null),{editorConfig:s}=P(),g=s?.admin?.hideGutter?-44:-8;be(()=>{function y(d){let f=d.target;if(!Ce(f))return;let E=V(r,d.pageX,d.pageY,f);if(E===-1){p(null);return}if(ae(f,go))return;let k=j(t),{blockElem:R,foundAtIndex:S,isFoundNodeEmptyParagraph:w}=q({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-E,point:new _(d.x,d.y),startIndex:Ue(k.length),useEdgeAsDefault:!1,verbose:!1});ee=S,!(!R&&!w)&&u!==R&&p(R)}return document?.addEventListener("mousemove",y),()=>{document?.removeEventListener("mousemove",y)}},[r,e,t,u]),be(()=>{n.current&&ce(u,n.current,e,g)},[e,u,g]),be(()=>{function y(f){if(!l.current)return!1;let[E]=We(f);if(E)return!1;let{pageY:k,target:R}=f;if(!Ce(R))return!1;let S=V(r,f.pageX,f.pageY,R,100,50),w=j(t),{blockElem:C,foundAtIndex:W,isFoundNodeEmptyParagraph:I}=q({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-S,point:new _(f.x,f.y),startIndex:Ue(w.length),useEdgeAsDefault:!0,verbose:!0});ee=W;let T=c.current;if(C===null||T===null)return!1;if(u!==C){let{isBelow:v,willStayInSamePosition:A}=ze(s?.admin?.hideGutter?"0px":"3rem",g+(s?.admin?.hideGutter?n?.current?.getBoundingClientRect()?.width??0:-(n?.current?.getBoundingClientRect()?.width??0)),T,C,h,k,e,f,i,I);f.preventDefault(),A||a({boundingBox:C.getBoundingClientRect(),elem:C,isBelow:v})}else h?.elem&&(qe(T,h.elem),a({boundingBox:C.getBoundingClientRect(),elem:C,isBelow:!1}));return!0}function d(f){if(!l.current)return!1;let[E]=We(f);if(E)return!1;let{dataTransfer:k,pageY:R,target:S}=f,w=k?.getData(Ve)||"";return t.update(()=>{let C=fo(w);if(!C||!Ce(S))return!1;let W=V(r,f.pageX,f.pageY,S,100,50),{blockElem:I,isFoundNodeEmptyParagraph:T}=q({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-W,point:new _(f.x,f.y),useEdgeAsDefault:!0});if(!I)return!1;let v=Ye(I);if(!v)return!1;if(v===C)return!0;let{height:A,top:ge}=U(I),he=R>=ge+A/2+window.scrollY;T?(v.insertBefore(C),v.remove()):he?v.insertAfter(C):v.insertBefore(C),u!==null&&p(null),document.querySelectorAll(".lexical-block-highlighter").forEach(D=>{D.remove()});let Y=t.getElementByKey(C.getKey());setTimeout(()=>{let D=Y?.getBoundingClientRect();if(!D)return;let N=document.createElement("div");N.className="lexical-block-highlighter",N.style.backgroundColor="var(--theme-elevation-1000",N.style.transition="opacity 0.5s ease-in-out",N.style.zIndex="1",N.style.pointerEvents="none",N.style.boxSizing="border-box",N.style.borderRadius="4px",N.style.position="absolute",document.body.appendChild(N),N.style.opacity="0.1",N.style.height=`${D.height+8}px`,N.style.width=`${D.width+8}px`,N.style.top=`${D.top+window.scrollY-4}px`,N.style.left=`${D.left-4}px`,setTimeout(()=>{N.style.opacity="0",setTimeout(()=>{N.remove()},500)},1e3)},120)}),!0}return document.addEventListener("dragover",y),document.addEventListener("drop",d),()=>{document.removeEventListener("dragover",y),document.removeEventListener("drop",d)}},[r,g,e,t,h,u,s?.admin?.hideGutter]);function x(y){let d=y.dataTransfer;if(!d||!u)return;ho(d,u);let f="";t.update(()=>{let E=Ye(u);E&&(f=E.getKey())}),l.current=!0,d.setData(Ve,f)}function m(){l.current=!1,h?.elem&&qe(c.current,h?.elem)}return po(uo(Je.Fragment,{children:[de("div",{className:"icon draggable-block-menu",draggable:!0,onDragEnd:m,onDragStart:x,ref:n,children:de("div",{className:o?"icon":""})}),de("div",{className:"draggable-block-target-line",ref:c}),de("div",{className:"debug-highlight",ref:i})]}),e)}function Qe(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=mo();return yo(r,o,r._editable)}import{c as xo}from"react/compiler-runtime";import{jsx as Ne}from"react/jsx-runtime";import{useLexicalComposerContext as Eo}from"@lexical/react/LexicalComposerContext";import{$createParagraphNode as Co,$getRoot as bo}from"lexical";import"react";var Xe="insert-paragraph-at-end",Ze=()=>{let t=xo(4),[e]=Eo(),{editorConfig:o}=P();if(o?.admin?.hideInsertParagraphAtEnd)return null;let r;t[0]!==e?(r=()=>{e.update(No)},t[0]=e,t[1]=r):r=t[1];let n=r,c;return t[2]!==n?(c=Ne("div",{"aria-label":"Insert Paragraph",className:Xe,onClick:n,role:"button",tabIndex:0,children:Ne("div",{className:`${Xe}-inside`,children:Ne("span",{children:"+"})})}),t[2]=n,t[3]=c):c=t[3],c};function No(){let t=Co();bo().append(t),t.select()}import{c as Po}from"react/compiler-runtime";import{useLexicalComposerContext as So}from"@lexical/react/LexicalComposerContext";import*as et from"react";var tt=()=>{let t=Po(4),{editorConfig:e}=P(),[o]=So(),r,n;return t[0]!==o||t[1]!==e.features.markdownTransformers?(r=()=>Re(o,e.features.markdownTransformers??[]),n=[o,e.features.markdownTransformers],t[0]=o,t[1]=e.features.markdownTransformers,t[2]=r,t[3]=n):(r=t[2],n=t[3]),et.useEffect(r,n),null};import{jsx as J,jsxs as nt}from"react/jsx-runtime";import{useLexicalComposerContext as ko}from"@lexical/react/LexicalComposerContext.js";import{useTranslation as rt}from"@payloadcms/ui";import{useCallback as wo,useMemo as To,useState as vo}from"react";import"react";import*as it from"react-dom";import{c as Ro}from"react/compiler-runtime";import"react";function ot(t,e){let o=Ro(4),{maxLength:r,minLength:n}=e,c=r===void 0?75:r,i=n===void 0?1:n,l;return o[0]!==c||o[1]!==i||o[2]!==t?(l=u=>{let{query:p}=u,h="[^"+t+ke+"\\s]",s=new RegExp("(^|\\s|\\()(["+t+"]((?:"+h+"){0,"+c+"}))$").exec(p);if(s!==null){let g=s[1],x=s[3];if(x.length>=i)return{leadOffset:s.index+g.length,matchingString:x,replaceableString:s[2]}}return null},o[0]=c,o[1]=i,o[2]=t,o[3]=l):l=o[3],l}var L="slash-menu-popup";function Do({isSelected:t,item:e,onClick:o,onMouseEnter:r,ref:n}){let{fieldProps:{featureClientSchemaMap:c,schemaPath:i}}=P(),{i18n:l}=rt(),u=`${L}__item ${L}__item-${e.key}`;t&&(u+=` ${L}__item--selected`);let p=e.key;return e.label&&(p=typeof e.label=="function"?e.label({featureClientSchemaMap:c,i18n:l,schemaPath:i}):e.label),p.length>25&&(p=p.substring(0,25)+"..."),nt("button",{"aria-selected":t,className:u,id:L+"__item-"+e.key,onClick:o,onMouseEnter:r,ref:n,role:"option",tabIndex:-1,type:"button",children:[e?.Icon&&J(e.Icon,{}),J("span",{className:`${L}__item-text`,children:p})]},e.key)}function st({anchorElem:t=document.body}){let[e]=ko(),[o,r]=vo(null),{editorConfig:n}=P(),{i18n:c}=rt(),{fieldProps:{featureClientSchemaMap:i,schemaPath:l}}=P(),u=ot("/",{minLength:0}),p=wo(()=>{let a=[];for(let s of n.features.slashMenu.dynamicGroups)if(o){let g=s({editor:e,queryString:o});a=a.concat(g)}return a},[e,o,n?.features]),h=To(()=>{let a=[];for(let s of n?.features.slashMenu.groups??[])a.push(s);if(o){a=a.map(g=>{let x=g.items.filter(m=>{let y=m.key;return m.label&&(y=typeof m.label=="function"?m.label({featureClientSchemaMap:i,i18n:c,schemaPath:l}):m.label),new RegExp(o,"gi").exec(y)?!0:m.keywords!=null?m.keywords.some(d=>new RegExp(o,"gi").exec(d)):!1});return x.length?{...g,items:x}:null}),a=a.filter(g=>g!=null);let s=p();for(let g of s){let x=a.find(m=>m.key===g.key);x?a=a.filter(m=>m.key!==g.key):x={...g,items:[]},x?.items?.length&&(x.items=x.items.concat(x.items)),a.push(x)}}return a},[o,n?.features.slashMenu.groups,p,i,c,l]);return J(Te,{anchorElem:t,groups:h,menuRenderFn:(a,{selectedItemKey:s,selectItemAndCleanUp:g,setSelectedItemKey:x})=>a.current&&h.length?it.createPortal(J("div",{className:L,children:h.map(m=>{let y=m.key;return m.label&&i&&(y=typeof m.label=="function"?m.label({featureClientSchemaMap:i,i18n:c,schemaPath:l}):m.label),nt("div",{className:`${L}__group ${L}__group-${m.key}`,children:[J("div",{className:`${L}__group-title`,children:y}),m.items.map((d,f)=>J(Do,{index:f,isSelected:s===d.key,item:d,onClick:()=>{x(d.key),g(d)},onMouseEnter:()=>{x(d.key)},ref:E=>{d.ref={current:E}}},d.key))]},m.key)})}),a.current):null,onQueryChange:r,triggerFn:u})}import{c as Mo}from"react/compiler-runtime";import{useLexicalComposerContext as Bo}from"@lexical/react/LexicalComposerContext";import{TEXT_TYPE_TO_FORMAT as Lo,TextNode as Io}from"lexical";import{useEffect as Ao}from"react";function lt(t){let e=Mo(6),{features:o}=t,[r]=Bo(),n;e[0]!==r||e[1]!==o.enabledFormats?(n=()=>{let i=_o(o.enabledFormats);if(i.length!==0)return r.registerNodeTransform(Io,l=>{i.forEach(u=>{l.hasFormat(u)&&l.toggleFormat(u)})})},e[0]=r,e[1]=o.enabledFormats,e[2]=n):n=e[2];let c;return e[3]!==r||e[4]!==o?(c=[r,o],e[3]=r,e[4]=o,e[5]=c):c=e[5],Ao(n,c),null}function _o(t){let e=Object.keys(Lo),o=new Set(t);return e.filter(r=>!o.has(r))}import{c as Oo}from"react/compiler-runtime";import{jsx as at}from"react/jsx-runtime";import{ContentEditable as Fo}from"@lexical/react/LexicalContentEditable.js";import{useTranslation as $o}from"@payloadcms/ui";import"react";function ct(t){let e=Oo(7),{className:o,editorConfig:r}=t,{t:n}=$o(),c;if(e[0]!==o||e[1]!==r?.admin?.placeholder||e[2]!==n){let i;e[4]!==r?.admin?.placeholder||e[5]!==n?(i=r?.admin?.placeholder??n("lexical:general:placeholder"),e[4]=r?.admin?.placeholder,e[5]=n,e[6]=i):i=e[6],c=at(Fo,{"aria-placeholder":n("lexical:general:placeholder"),className:o??"ContentEditable__root",placeholder:at("p",{className:"editor-placeholder",children:i})}),e[0]=o,e[1]=r?.admin?.placeholder,e[2]=n,e[3]=c}else c=e[3];return c}var dt=t=>{let e=Ko(19),{editorConfig:o,editorContainerRef:r,isSmallWidthViewport:n,onChange:c}=t,i=P(),[l]=Ho(),[u,p]=qo(null),h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=m=>{m!==null&&p(m)},e[0]=h):h=e[0];let a=h,s,g;e[1]!==l||e[2]!==i?(s=()=>{if(!i?.uuid){console.error("Lexical Editor must be used within an EditorConfigProvider");return}i?.parentEditor?.uuid&&i.parentEditor?.registerChild(i.uuid,i);let m=()=>{i.focusEditor(i)},y=()=>{i.blurEditor(i)},d=l.registerCommand(Vo,()=>(m(),!0),ut),f=l.registerCommand(Go,()=>(y(),!0),ut);return()=>{d(),f(),i.parentEditor?.unregisterChild?.(i.uuid)}},g=[l,i],e[1]=l,e[2]=i,e[3]=s,e[4]=g):(s=e[3],g=e[4]),Uo(s,g);let x;if(e[5]!==l||e[6]!==o||e[7]!==r||e[8]!==u||e[9]!==n||e[10]!==c){let m;e[12]!==c?(m=(d,f,E)=>{(!E.has("focus")||E.size>1)&&c?.(d,f,E)},e[12]=c,e[13]=m):m=e[13];let y;e[14]!==l||e[15]!==o.features.plugins||e[16]!==u||e[17]!==n?(y=u&&te(Q.Fragment,{children:[!n&&l.isEditable()&&te(Q.Fragment,{children:[b(Qe,{anchorElem:u}),b(He,{anchorElem:u})]}),o.features.plugins?.map(d=>{if(d.position==="floatingAnchorElem"&&!(d.desktopOnly===!0&&n))return b(K,{anchorElem:u,clientProps:d.clientProps,plugin:d},d.key)}),l.isEditable()&&b(Q.Fragment,{children:b(st,{anchorElem:u})})]}),e[14]=l,e[15]=o.features.plugins,e[16]=u,e[17]=n,e[18]=y):y=e[18],x=te(Q.Fragment,{children:[o.features.plugins?.map(Jo),te("div",{className:"editor-container",ref:r,children:[o.features.plugins?.map(Qo),b(Yo,{contentEditable:b("div",{className:"editor-scroller",children:b("div",{className:"editor",ref:a,children:b(ct,{editorConfig:o})})}),ErrorBoundary:jo}),b(Ze,{}),b(Ie,{}),b(lt,{features:o.features}),b(Wo,{ignoreSelectionChange:!0,onChange:m}),y,l.isEditable()&&te(Q.Fragment,{children:[b(zo,{}),o?.features?.markdownTransformers?.length>0&&b(tt,{})]}),o.features.plugins?.map(Xo),o.features.plugins?.map(Zo)]}),o.features.plugins?.map(en)]}),e[5]=l,e[6]=o,e[7]=r,e[8]=u,e[9]=n,e[10]=c,e[11]=x}else x=e[11];return x};function Jo(t){if(t.position==="aboveContainer")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function Qo(t){if(t.position==="top")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function Xo(t){if(t.position==="normal")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function Zo(t){if(t.position==="bottom")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function en(t){if(t.position==="belowContainer")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}var ft=({children:t,providers:e})=>{if(!e?.length)return t;let o=e[0];return e.length>1?O(o,{children:O(ft,{providers:e.slice(1),children:t})}):O(o,{children:t})},pt=t=>{let{composerKey:e,editorConfig:o,fieldProps:r,isSmallWidthViewport:n,onChange:c,readOnly:i,value:l}=t,u=P(),p=on(),h=mt.useRef(null),a=nn(()=>{if(l&&typeof l!="object")throw new Error("The value passed to the Lexical editor is not an object. This is not supported. Please remove the data from the field and start again. This is the value that was passed in: "+JSON.stringify(l));if(l&&Array.isArray(l)&&!("root"in l))throw new Error("You have tried to pass in data from the old Slate editor to the new Lexical editor. The data structure is different, thus you will have to migrate your data. We offer a one-line migration script which migrates all your rich text fields: https://payloadcms.com/docs/lexical/migration#migration-via-migration-script-recommended");if(l&&"jsonContent"in l)throw new Error("You have tried to pass in data from payload-plugin-lexical. The data structure is different, thus you will have to migrate your data. Migration guide: https://payloadcms.com/docs/lexical/migration#migrating-from-payload-plugin-lexical");return{editable:i!==!0,editorState:l!=null?JSON.stringify(l):void 0,namespace:o.lexical.namespace,nodes:De({editorConfig:o}),onError:s=>{throw s},theme:o.lexical.theme}},[o]);return a?O(tn,{initialConfig:a,children:O(Se,{editorConfig:o,editorContainerRef:h,fieldProps:r,parentContext:u?.editDepth===p?u:void 0,children:O(ft,{providers:o.features.providers,children:O(dt,{editorConfig:o,editorContainerRef:h,isSmallWidthViewport:n,onChange:c})})})},e+a.editable):O("p",{children:"Loading..."})};var fe="rich-text-lexical",pn=t=>{let{editorConfig:e,field:o,field:{name:r,admin:{className:n,description:c,readOnly:i}={},label:l,localized:u,required:p},path:h,readOnly:a,validate:s}=t,g=a||i,x=h??r,m=an(),y=yt((M,$)=>typeof s=="function"?s(M,{...$,required:p}):!0,[s,p]),{customComponents:{AfterInput:d,BeforeInput:f,Description:E,Error:k,Label:R}={},formInitializing:S,formProcessing:w,initialValue:C,setValue:W,showError:I,value:T}=un({path:x,validate:y}),v=g||w||S,[A,ge]=Et(!1),[Pe,he]=Et(),ye=ht.useRef(C),Y=ht.useRef(T);xt(()=>{let M=()=>{let $=window.matchMedia("(max-width: 768px)").matches;$!==A&&ge($)};return M(),window.addEventListener("resize",M),()=>{window.removeEventListener("resize",M)}},[A]);let D=[fe,"field-type",n,I&&"error",v&&`${fe}--read-only`,e?.admin?.hideGutter!==!0&&!A?`${fe}--show-gutter`:null].filter(Boolean).join(" "),N=`${x}.${m}`,Ct=yt(M=>{let $=M.toJSON();Y.current=$,W($)},[W]),bt=mn(()=>dn(o),[o]),Nt=cn(M=>{Y.current!==T&&JSON.stringify(Y.current)!==JSON.stringify(T)&&(ye.current=M,Y.current=T,he(new Date))});return xt(()=>{Object.is(C,ye.current)||Nt(C)},[C]),pe("div",{className:D,style:bt,children:[F(gt,{CustomComponent:k,Fallback:F(sn,{path:x,showError:I})}),R||F(ln,{label:l,localized:u,path:x,required:p}),pe("div",{className:`${fe}__wrap`,children:[pe(fn,{fallbackRender:gn,onReset:()=>{},children:[f,F(pt,{composerKey:N,editorConfig:e,fieldProps:t,isSmallWidthViewport:A,onChange:Ct,readOnly:v,value:T},JSON.stringify({path:x,rerenderProviderKey:Pe})),d]}),E,F(gt,{CustomComponent:E,Fallback:F(rn,{description:c,path:x})})]})]},N)};function gn({error:t}){return pe("div",{className:"errorBoundary",role:"alert",children:[F("p",{children:"Something went wrong:"}),F("pre",{style:{color:"red"},children:t.message})]})}var $i=pn;export{$i as RichText};
2
- //# sourceMappingURL=Field-FLAQN6LU.js.map