@webiny/lexical-editor 0.0.0-unstable.085ff6572f → 0.0.0-unstable.0d717d18dd

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 (433) hide show
  1. package/README.md +6 -12
  2. package/commands/image.d.ts +6 -0
  3. package/commands/image.js +5 -0
  4. package/commands/image.js.map +1 -0
  5. package/commands/index.d.ts +5 -0
  6. package/commands/index.js +5 -0
  7. package/commands/list.d.ts +7 -0
  8. package/commands/list.js +7 -0
  9. package/commands/list.js.map +1 -0
  10. package/commands/quote.d.ts +5 -0
  11. package/commands/quote.js +5 -0
  12. package/commands/quote.js.map +1 -0
  13. package/commands/toolbar.d.ts +1 -0
  14. package/commands/toolbar.js +5 -0
  15. package/commands/toolbar.js.map +1 -0
  16. package/commands/typography.d.ts +8 -0
  17. package/commands/typography.js +5 -0
  18. package/commands/typography.js.map +1 -0
  19. package/components/Editor/EditorPlaceholder.d.ts +15 -0
  20. package/components/Editor/EditorPlaceholder.js +41 -0
  21. package/components/Editor/EditorPlaceholder.js.map +1 -0
  22. package/components/Editor/EnsureHeadingTagPlugin.d.ts +6 -0
  23. package/components/Editor/EnsureHeadingTagPlugin.js +13 -0
  24. package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -0
  25. package/components/Editor/RichTextEditor.d.ts +45 -16
  26. package/components/Editor/RichTextEditor.js +103 -136
  27. package/components/Editor/RichTextEditor.js.map +1 -1
  28. package/components/Editor/normalizeInputValue.d.ts +6 -0
  29. package/components/Editor/normalizeInputValue.js +14 -0
  30. package/components/Editor/normalizeInputValue.js.map +1 -0
  31. package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +20 -10
  32. package/components/LexicalEditorConfig/LexicalEditorConfig.js +33 -18
  33. package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
  34. package/components/LexicalEditorConfig/components/Node.d.ts +14 -0
  35. package/components/LexicalEditorConfig/components/Node.js +25 -0
  36. package/components/LexicalEditorConfig/components/Node.js.map +1 -0
  37. package/components/LexicalEditorConfig/components/Plugin.d.ts +13 -0
  38. package/components/LexicalEditorConfig/components/Plugin.js +25 -0
  39. package/components/LexicalEditorConfig/components/Plugin.js.map +1 -0
  40. package/components/LexicalEditorConfig/components/ToolbarElement.d.ts +13 -0
  41. package/components/LexicalEditorConfig/components/ToolbarElement.js +25 -0
  42. package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -0
  43. package/components/LexicalHtmlRenderer.d.ts +5 -10
  44. package/components/LexicalHtmlRenderer.js +43 -65
  45. package/components/LexicalHtmlRenderer.js.map +1 -1
  46. package/components/Toolbar/StaticToolbar.css +566 -0
  47. package/components/Toolbar/StaticToolbar.d.ts +5 -0
  48. package/components/Toolbar/StaticToolbar.js +17 -0
  49. package/components/Toolbar/StaticToolbar.js.map +1 -0
  50. package/components/ToolbarActions/BoldAction.d.ts +2 -2
  51. package/components/ToolbarActions/BoldAction.js +25 -42
  52. package/components/ToolbarActions/BoldAction.js.map +1 -1
  53. package/components/ToolbarActions/BulletListAction.d.ts +2 -2
  54. package/components/ToolbarActions/BulletListAction.js +34 -55
  55. package/components/ToolbarActions/BulletListAction.js.map +1 -1
  56. package/components/ToolbarActions/CodeHighlightAction.d.ts +2 -2
  57. package/components/ToolbarActions/CodeHighlightAction.js +25 -42
  58. package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
  59. package/components/ToolbarActions/FontColorAction.d.ts +23 -5
  60. package/components/ToolbarActions/FontColorAction.js +40 -79
  61. package/components/ToolbarActions/FontColorAction.js.map +1 -1
  62. package/components/ToolbarActions/FontSizeAction.d.ts +2 -2
  63. package/components/ToolbarActions/FontSizeAction.js +70 -99
  64. package/components/ToolbarActions/FontSizeAction.js.map +1 -1
  65. package/components/ToolbarActions/ImageAction.d.ts +2 -0
  66. package/components/ToolbarActions/ImageAction.js +36 -0
  67. package/components/ToolbarActions/ImageAction.js.map +1 -0
  68. package/components/ToolbarActions/ItalicAction.d.ts +2 -2
  69. package/components/ToolbarActions/ItalicAction.js +25 -42
  70. package/components/ToolbarActions/ItalicAction.js.map +1 -1
  71. package/components/ToolbarActions/LinkAction.d.ts +2 -2
  72. package/components/ToolbarActions/LinkAction.js +34 -62
  73. package/components/ToolbarActions/LinkAction.js.map +1 -1
  74. package/components/ToolbarActions/NumberedListAction.d.ts +2 -2
  75. package/components/ToolbarActions/NumberedListAction.js +38 -57
  76. package/components/ToolbarActions/NumberedListAction.js.map +1 -1
  77. package/components/ToolbarActions/QuoteAction.d.ts +2 -2
  78. package/components/ToolbarActions/QuoteAction.js +31 -51
  79. package/components/ToolbarActions/QuoteAction.js.map +1 -1
  80. package/components/ToolbarActions/TextAlignmentAction.d.ts +23 -5
  81. package/components/ToolbarActions/TextAlignmentAction.js +47 -68
  82. package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
  83. package/components/ToolbarActions/TypographyAction.d.ts +23 -5
  84. package/components/ToolbarActions/TypographyAction.js +76 -140
  85. package/components/ToolbarActions/TypographyAction.js.map +1 -1
  86. package/components/ToolbarActions/UnderlineAction.d.ts +2 -2
  87. package/components/ToolbarActions/UnderlineAction.js +24 -42
  88. package/components/ToolbarActions/UnderlineAction.js.map +1 -1
  89. package/context/FontColorActionContext.js +4 -9
  90. package/context/FontColorActionContext.js.map +1 -1
  91. package/context/RichTextEditorContext.d.ts +10 -18
  92. package/context/RichTextEditorContext.js +38 -67
  93. package/context/RichTextEditorContext.js.map +1 -1
  94. package/context/SharedHistoryContext.d.ts +5 -5
  95. package/context/SharedHistoryContext.js +14 -25
  96. package/context/SharedHistoryContext.js.map +1 -1
  97. package/context/TextAlignmentActionContextProps.d.ts +1 -1
  98. package/context/TextAlignmentActionContextProps.js +4 -9
  99. package/context/TextAlignmentActionContextProps.js.map +1 -1
  100. package/context/TypographyActionContext.d.ts +3 -2
  101. package/context/TypographyActionContext.js +4 -9
  102. package/context/TypographyActionContext.js.map +1 -1
  103. package/exports/admin/ui/lexical.d.ts +15 -0
  104. package/exports/admin/ui/lexical.js +5 -0
  105. package/hooks/index.d.ts +7 -0
  106. package/hooks/index.js +7 -0
  107. package/hooks/useCurrentElement.d.ts +7 -0
  108. package/hooks/useCurrentElement.js +23 -0
  109. package/hooks/useCurrentElement.js.map +1 -0
  110. package/hooks/useCurrentSelection.d.ts +13 -0
  111. package/hooks/useCurrentSelection.js +48 -0
  112. package/hooks/useCurrentSelection.js.map +1 -0
  113. package/hooks/useFontColorPicker.d.ts +1 -1
  114. package/hooks/useFontColorPicker.js +9 -14
  115. package/hooks/useFontColorPicker.js.map +1 -1
  116. package/hooks/useIsMounted.d.ts +1 -0
  117. package/hooks/useIsMounted.js +11 -0
  118. package/hooks/useIsMounted.js.map +1 -0
  119. package/hooks/useRichTextEditor.d.ts +1 -1
  120. package/hooks/useRichTextEditor.js +9 -14
  121. package/hooks/useRichTextEditor.js.map +1 -1
  122. package/hooks/useTextAlignmentAction.d.ts +1 -1
  123. package/hooks/useTextAlignmentAction.js +9 -14
  124. package/hooks/useTextAlignmentAction.js.map +1 -1
  125. package/hooks/useTypographyAction.d.ts +1 -1
  126. package/hooks/useTypographyAction.js +9 -14
  127. package/hooks/useTypographyAction.js.map +1 -1
  128. package/images/icons/pencil-fill.js +17 -0
  129. package/images/icons/pencil-fill.js.map +1 -0
  130. package/images/icons/text-paragraph.js +18 -0
  131. package/images/icons/text-paragraph.js.map +1 -0
  132. package/images/icons/type-h1.js +17 -0
  133. package/images/icons/type-h1.js.map +1 -0
  134. package/images/icons/type-h2.js +17 -0
  135. package/images/icons/type-h2.js.map +1 -0
  136. package/images/icons/type-h3.js +17 -0
  137. package/images/icons/type-h3.js.map +1 -0
  138. package/images/icons/type-h4.js +17 -0
  139. package/images/icons/type-h4.js.map +1 -0
  140. package/images/icons/type-h5.js +17 -0
  141. package/images/icons/type-h5.js.map +1 -0
  142. package/images/icons/type-h6.js +17 -0
  143. package/images/icons/type-h6.js.map +1 -0
  144. package/images/icons/unlink_icon.js +27 -0
  145. package/images/icons/unlink_icon.js.map +1 -0
  146. package/index.d.ts +34 -42
  147. package/index.js +34 -295
  148. package/package.json +29 -27
  149. package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +2 -2
  150. package/plugins/BlurEventPlugin/BlurEventPlugin.js +16 -27
  151. package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
  152. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +12 -19
  153. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
  154. package/plugins/CodeHighlightPlugin/index.d.ts +1 -1
  155. package/plugins/CodeHighlightPlugin/index.js +1 -16
  156. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +10 -0
  157. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +20 -0
  158. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -0
  159. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +7 -0
  160. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +47 -0
  161. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -0
  162. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +5 -81
  163. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +5 -6
  164. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +8 -219
  165. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
  166. package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -1
  167. package/plugins/FloatingLinkEditorPlugin/index.js +1 -16
  168. package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.d.ts +1 -0
  169. package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js +9 -0
  170. package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js.map +1 -0
  171. package/plugins/FloatingLinkEditorPlugin/types.d.ts +10 -0
  172. package/plugins/FloatingLinkEditorPlugin/types.js +0 -0
  173. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +8 -0
  174. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +121 -0
  175. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +1 -0
  176. package/plugins/FontColorPlugin/FontColorPlugin.d.ts +1 -2
  177. package/plugins/FontColorPlugin/FontColorPlugin.js +21 -38
  178. package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
  179. package/plugins/FontColorPlugin/applyColorToNode.d.ts +3 -0
  180. package/plugins/FontColorPlugin/applyColorToNode.js +9 -0
  181. package/plugins/FontColorPlugin/applyColorToNode.js.map +1 -0
  182. package/plugins/FontColorPlugin/applyColorToSelection.d.ts +3 -0
  183. package/plugins/FontColorPlugin/applyColorToSelection.js +48 -0
  184. package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -0
  185. package/plugins/ImagesPlugin/ImagesPlugin.d.ts +11 -0
  186. package/plugins/ImagesPlugin/ImagesPlugin.js +106 -0
  187. package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -0
  188. package/plugins/LinkPlugin/LinkPlugin.d.ts +5 -0
  189. package/plugins/LinkPlugin/LinkPlugin.js +52 -0
  190. package/plugins/LinkPlugin/LinkPlugin.js.map +1 -0
  191. package/plugins/ListPLugin/ListPlugin.d.ts +1 -0
  192. package/plugins/ListPLugin/ListPlugin.js +51 -0
  193. package/plugins/ListPLugin/ListPlugin.js.map +1 -0
  194. package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +25 -0
  195. package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -0
  196. package/plugins/StateHandlingPlugin.d.ts +8 -0
  197. package/plugins/StateHandlingPlugin.js +66 -0
  198. package/plugins/StateHandlingPlugin.js.map +1 -0
  199. package/plugins/TypographyPlugin/TypographyPlugin.d.ts +1 -2
  200. package/plugins/TypographyPlugin/TypographyPlugin.js +19 -34
  201. package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
  202. package/static/svg/pencil-fill.94cb216b.svg +1 -0
  203. package/static/svg/text-paragraph.61674422.svg +1 -0
  204. package/static/svg/type-h1.f292ffe1.svg +1 -0
  205. package/static/svg/type-h2.a9d1aa48.svg +1 -0
  206. package/static/svg/type-h3.4a29ff88.svg +1 -0
  207. package/static/svg/type-h4.7f48750c.svg +1 -0
  208. package/static/svg/type-h5.14b4ac56.svg +1 -0
  209. package/static/svg/type-h6.4e9dfe2d.svg +1 -0
  210. package/static/svg/unlink_icon.074ceed3.svg +1 -0
  211. package/types.d.ts +12 -63
  212. package/types.js +1 -25
  213. package/ui/ContentEditable.css +22 -0
  214. package/ui/ContentEditable.d.ts +12 -0
  215. package/ui/ContentEditable.js +11 -0
  216. package/ui/ContentEditable.js.map +1 -0
  217. package/ui/Divider.d.ts +2 -2
  218. package/ui/Divider.js +8 -12
  219. package/ui/Divider.js.map +1 -1
  220. package/ui/DropDown.d.ts +9 -13
  221. package/ui/DropDown.js +48 -204
  222. package/ui/DropDown.js.map +1 -1
  223. package/ui/ImageResizer.d.ts +24 -0
  224. package/ui/ImageResizer.js +180 -0
  225. package/ui/ImageResizer.js.map +1 -0
  226. package/ui/LinkPreview.css +2 -2
  227. package/ui/LinkPreview.d.ts +2 -2
  228. package/ui/LinkPreview.js +67 -94
  229. package/ui/LinkPreview.js.map +1 -1
  230. package/ui/Placeholder.css +4 -6
  231. package/ui/Placeholder.d.ts +5 -3
  232. package/ui/Placeholder.js +12 -23
  233. package/ui/Placeholder.js.map +1 -1
  234. package/ui/TextInput.d.ts +3 -3
  235. package/ui/TextInput.js +20 -38
  236. package/ui/TextInput.js.map +1 -1
  237. package/ui/ToolbarActionDialog.d.ts +2 -3
  238. package/ui/ToolbarActionDialog.js +66 -103
  239. package/ui/ToolbarActionDialog.js.map +1 -1
  240. package/utils/canUseDOM.d.ts +1 -0
  241. package/utils/canUseDOM.js +4 -0
  242. package/utils/canUseDOM.js.map +1 -0
  243. package/utils/files.d.ts +11 -0
  244. package/utils/files.js +12 -0
  245. package/utils/files.js.map +1 -0
  246. package/utils/getDOMRangeRect.d.ts +0 -2
  247. package/utils/getDOMRangeRect.js +12 -26
  248. package/utils/getDOMRangeRect.js.map +1 -1
  249. package/utils/getSelectedNode.d.ts +1 -1
  250. package/utils/getSelectedNode.js +13 -29
  251. package/utils/getSelectedNode.js.map +1 -1
  252. package/utils/getTransparentImage.d.ts +1 -0
  253. package/utils/getTransparentImage.js +4 -0
  254. package/utils/getTransparentImage.js.map +1 -0
  255. package/utils/insertImage.d.ts +2 -0
  256. package/utils/insertImage.js +14 -0
  257. package/utils/insertImage.js.map +1 -0
  258. package/utils/isAnchorLink.d.ts +1 -0
  259. package/utils/isAnchorLink.js +4 -0
  260. package/utils/isAnchorLink.js.map +1 -0
  261. package/utils/isChildOfFloatingToolbar.d.ts +1 -0
  262. package/utils/isChildOfFloatingToolbar.js +9 -0
  263. package/utils/isChildOfFloatingToolbar.js.map +1 -0
  264. package/{plugins/AutoLinkPlugin/AutoLinkPlugin.d.ts → utils/isHTMLElement.d.ts} +1 -4
  265. package/utils/isHTMLElement.js +6 -0
  266. package/utils/isHTMLElement.js.map +1 -0
  267. package/utils/isValidJSON.js +11 -17
  268. package/utils/isValidJSON.js.map +1 -1
  269. package/utils/isValidLexicalData.d.ts +4 -2
  270. package/utils/isValidLexicalData.js +20 -23
  271. package/utils/isValidLexicalData.js.map +1 -1
  272. package/utils/point.js +27 -68
  273. package/utils/point.js.map +1 -1
  274. package/utils/rect.d.ts +4 -6
  275. package/utils/rect.js +83 -155
  276. package/utils/rect.js.map +1 -1
  277. package/utils/sanitizeUrl.d.ts +0 -7
  278. package/utils/sanitizeUrl.js +11 -26
  279. package/utils/sanitizeUrl.js.map +1 -1
  280. package/utils/setFloatingElemPosition.d.ts +1 -3
  281. package/utils/setFloatingElemPosition.js +32 -39
  282. package/utils/setFloatingElemPosition.js.map +1 -1
  283. package/commands/webiny-list.d.ts +0 -7
  284. package/commands/webiny-list.js +0 -13
  285. package/commands/webiny-list.js.map +0 -1
  286. package/commands/webiny-quote.d.ts +0 -5
  287. package/commands/webiny-quote.js +0 -9
  288. package/commands/webiny-quote.js.map +0 -1
  289. package/components/AddRichTextEditorNodeType.d.ts +0 -6
  290. package/components/AddRichTextEditorNodeType.js +0 -28
  291. package/components/AddRichTextEditorNodeType.js.map +0 -1
  292. package/components/AddRichTextEditorPlugin.d.ts +0 -12
  293. package/components/AddRichTextEditorPlugin.js +0 -33
  294. package/components/AddRichTextEditorPlugin.js.map +0 -1
  295. package/components/AddToolbarAction.d.ts +0 -7
  296. package/components/AddToolbarAction.js +0 -33
  297. package/components/AddToolbarAction.js.map +0 -1
  298. package/components/Editor/HeadingEditor.d.ts +0 -7
  299. package/components/Editor/HeadingEditor.js +0 -29
  300. package/components/Editor/HeadingEditor.js.map +0 -1
  301. package/components/Editor/ParagraphEditor.d.ts +0 -7
  302. package/components/Editor/ParagraphEditor.js +0 -30
  303. package/components/Editor/ParagraphEditor.js.map +0 -1
  304. package/components/Toolbar/HeadingToolbar.d.ts +0 -12
  305. package/components/Toolbar/HeadingToolbar.js +0 -23
  306. package/components/Toolbar/HeadingToolbar.js.map +0 -1
  307. package/components/Toolbar/ParagraphToolbar.d.ts +0 -12
  308. package/components/Toolbar/ParagraphToolbar.js +0 -23
  309. package/components/Toolbar/ParagraphToolbar.js.map +0 -1
  310. package/components/Toolbar/Toolbar.css +0 -435
  311. package/components/Toolbar/Toolbar.d.ts +0 -13
  312. package/components/Toolbar/Toolbar.js +0 -215
  313. package/components/Toolbar/Toolbar.js.map +0 -1
  314. package/components/ToolbarPresets/HeadingToolbarPreset.d.ts +0 -2
  315. package/components/ToolbarPresets/HeadingToolbarPreset.js +0 -56
  316. package/components/ToolbarPresets/HeadingToolbarPreset.js.map +0 -1
  317. package/components/ToolbarPresets/ParagraphToolbarPreset.d.ts +0 -2
  318. package/components/ToolbarPresets/ParagraphToolbarPreset.js +0 -71
  319. package/components/ToolbarPresets/ParagraphToolbarPreset.js.map +0 -1
  320. package/hooks/useList.d.ts +0 -2
  321. package/hooks/useList.js +0 -39
  322. package/hooks/useList.js.map +0 -1
  323. package/hooks/useQuote.d.ts +0 -2
  324. package/hooks/useQuote.js +0 -20
  325. package/hooks/useQuote.js.map +0 -1
  326. package/images/icons/chat-square-quote.svg +0 -1
  327. package/images/icons/chevron-down.svg +0 -1
  328. package/images/icons/code.svg +0 -1
  329. package/images/icons/font-color.svg +0 -1
  330. package/images/icons/indent.svg +0 -3
  331. package/images/icons/justify.svg +0 -3
  332. package/images/icons/link.svg +0 -1
  333. package/images/icons/list-ol.svg +0 -1
  334. package/images/icons/list-ul.svg +0 -1
  335. package/images/icons/outdent.svg +0 -3
  336. package/images/icons/text-center.svg +0 -1
  337. package/images/icons/text-left.svg +0 -1
  338. package/images/icons/text-right.svg +0 -1
  339. package/images/icons/type-bold.svg +0 -1
  340. package/images/icons/type-italic.svg +0 -1
  341. package/images/icons/type-strikethrough.svg +0 -1
  342. package/images/icons/type-underline.svg +0 -1
  343. package/index.js.map +0 -1
  344. package/nodes/FontColorNode.d.ts +0 -43
  345. package/nodes/FontColorNode.js +0 -127
  346. package/nodes/FontColorNode.js.map +0 -1
  347. package/nodes/HeadingNode.d.ts +0 -34
  348. package/nodes/HeadingNode.js +0 -192
  349. package/nodes/HeadingNode.js.map +0 -1
  350. package/nodes/ListItemNode.d.ts +0 -46
  351. package/nodes/ListItemNode.js +0 -441
  352. package/nodes/ListItemNode.js.map +0 -1
  353. package/nodes/ListNode/formatList.d.ts +0 -12
  354. package/nodes/ListNode/formatList.js +0 -424
  355. package/nodes/ListNode/formatList.js.map +0 -1
  356. package/nodes/ListNode.d.ts +0 -42
  357. package/nodes/ListNode.js +0 -294
  358. package/nodes/ListNode.js.map +0 -1
  359. package/nodes/ParagraphNode.d.ts +0 -32
  360. package/nodes/ParagraphNode.js +0 -218
  361. package/nodes/ParagraphNode.js.map +0 -1
  362. package/nodes/QuoteNode.d.ts +0 -34
  363. package/nodes/QuoteNode.js +0 -225
  364. package/nodes/QuoteNode.js.map +0 -1
  365. package/nodes/TypographyElementNode.d.ts +0 -42
  366. package/nodes/TypographyElementNode.js +0 -155
  367. package/nodes/TypographyElementNode.js.map +0 -1
  368. package/nodes/types.d.ts +0 -15
  369. package/nodes/types.js +0 -5
  370. package/nodes/types.js.map +0 -1
  371. package/nodes/webinyNodes.d.ts +0 -7
  372. package/nodes/webinyNodes.js +0 -45
  373. package/nodes/webinyNodes.js.map +0 -1
  374. package/plugins/AutoLinkPlugin/AutoLinkPlugin.js +0 -46
  375. package/plugins/AutoLinkPlugin/AutoLinkPlugin.js.map +0 -1
  376. package/plugins/AutoLinkPlugin/index.d.ts +0 -1
  377. package/plugins/AutoLinkPlugin/index.js +0 -16
  378. package/plugins/AutoLinkPlugin/index.js.map +0 -1
  379. package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.d.ts +0 -17
  380. package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js +0 -88
  381. package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js.map +0 -1
  382. package/plugins/ClickableLinkPlugin/index.d.ts +0 -1
  383. package/plugins/ClickableLinkPlugin/index.js +0 -16
  384. package/plugins/ClickableLinkPlugin/index.js.map +0 -1
  385. package/plugins/CodeHighlightPlugin/index.js.map +0 -1
  386. package/plugins/FloatingLinkEditorPlugin/index.js.map +0 -1
  387. package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.d.ts +0 -8
  388. package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js +0 -34
  389. package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js.map +0 -1
  390. package/plugins/LexicalUpdateStatePlugin/index.d.ts +0 -1
  391. package/plugins/LexicalUpdateStatePlugin/index.js +0 -16
  392. package/plugins/LexicalUpdateStatePlugin/index.js.map +0 -1
  393. package/plugins/WebinyListPLugin/WebinyListPlugin.d.ts +0 -1
  394. package/plugins/WebinyListPLugin/WebinyListPlugin.js +0 -25
  395. package/plugins/WebinyListPLugin/WebinyListPlugin.js.map +0 -1
  396. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js +0 -24
  397. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js.map +0 -1
  398. package/themes/webinyLexicalTheme.css +0 -429
  399. package/themes/webinyLexicalTheme.d.ts +0 -9
  400. package/themes/webinyLexicalTheme.js +0 -87
  401. package/themes/webinyLexicalTheme.js.map +0 -1
  402. package/types.js.map +0 -1
  403. package/utils/findTypographyStyleByHtmlTag.d.ts +0 -8
  404. package/utils/findTypographyStyleByHtmlTag.js +0 -16
  405. package/utils/findTypographyStyleByHtmlTag.js.map +0 -1
  406. package/utils/generateInitialLexicalValue.d.ts +0 -5
  407. package/utils/generateInitialLexicalValue.js +0 -30
  408. package/utils/generateInitialLexicalValue.js.map +0 -1
  409. package/utils/getLexicalTextSelectionState.d.ts +0 -5
  410. package/utils/getLexicalTextSelectionState.js +0 -163
  411. package/utils/getLexicalTextSelectionState.js.map +0 -1
  412. package/utils/nodes/clearNodeFormating.d.ts +0 -2
  413. package/utils/nodes/clearNodeFormating.js +0 -28
  414. package/utils/nodes/clearNodeFormating.js.map +0 -1
  415. package/utils/nodes/formatToHeading.d.ts +0 -3
  416. package/utils/nodes/formatToHeading.js +0 -25
  417. package/utils/nodes/formatToHeading.js.map +0 -1
  418. package/utils/nodes/formatToParagraph.d.ts +0 -2
  419. package/utils/nodes/formatToParagraph.js +0 -20
  420. package/utils/nodes/formatToParagraph.js.map +0 -1
  421. package/utils/nodes/formatToQuote.d.ts +0 -2
  422. package/utils/nodes/formatToQuote.js +0 -25
  423. package/utils/nodes/formatToQuote.js.map +0 -1
  424. package/utils/nodes/listNode.d.ts +0 -11
  425. package/utils/nodes/listNode.js +0 -107
  426. package/utils/nodes/listNode.js.map +0 -1
  427. package/utils/styleObjectToString.d.ts +0 -2
  428. package/utils/styleObjectToString.js +0 -22
  429. package/utils/styleObjectToString.js.map +0 -1
  430. package/utils/toTypographyEmotionMap.d.ts +0 -3
  431. package/utils/toTypographyEmotionMap.js +0 -36
  432. package/utils/toTypographyEmotionMap.js.map +0 -1
  433. /package/plugins/{WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.d.ts → QuoteNodePlugin/QuoteNodePlugin.d.ts} +0 -0
package/README.md CHANGED
@@ -1,17 +1,11 @@
1
1
  # @webiny/lexical-editor
2
- [![](https://img.shields.io/npm/dw/@webiny/app-page-builder.svg)](https://www.npmjs.com/package/@webiny/lexical-editor)
3
- [![](https://img.shields.io/npm/v/@webiny/app-page-builder.svg)](https://www.npmjs.com/package/@webiny/lexical-editor)
4
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
2
 
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
7
6
 
8
- ## About
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
9
8
 
10
- This package provides a web text editor with rich text editing features. It's built on top of the Lexical framework.
9
+ ---
11
10
 
12
-
13
- To find more about the Lexical framework go to their website [lexical.dev](https://lexical.dev/)
14
-
15
- ## Where is it used?
16
-
17
- Currently, this packaged is used in [@webiny/app-pagebuilder](../app-page-builder).
11
+ _This README file is automatically generated during the publish process._
@@ -0,0 +1,6 @@
1
+ import type { LexicalCommand, NodeKey } from "lexical";
2
+ import type { ImageNodeProps } from "@webiny/lexical-nodes";
3
+ export interface ImagePayload extends ImageNodeProps {
4
+ key?: NodeKey;
5
+ }
6
+ export declare const INSERT_IMAGE_COMMAND: LexicalCommand<ImagePayload>;
@@ -0,0 +1,5 @@
1
+ import { createCommand } from "lexical";
2
+ const INSERT_IMAGE_COMMAND = createCommand("INSERT_IMAGE_COMMAND");
3
+ export { INSERT_IMAGE_COMMAND };
4
+
5
+ //# sourceMappingURL=image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands/image.js","sources":["../../src/commands/image.ts"],"sourcesContent":["import type { LexicalCommand, NodeKey } from \"lexical\";\nimport { createCommand } from \"lexical\";\nimport type { ImageNodeProps } from \"@webiny/lexical-nodes\";\n\nexport interface ImagePayload extends ImageNodeProps {\n key?: NodeKey;\n}\n\nexport const INSERT_IMAGE_COMMAND: LexicalCommand<ImagePayload> =\n createCommand(\"INSERT_IMAGE_COMMAND\");\n"],"names":["INSERT_IMAGE_COMMAND","createCommand"],"mappings":";AAQO,MAAMA,uBACTC,cAAc"}
@@ -0,0 +1,5 @@
1
+ export * from "../commands/typography.js";
2
+ export * from "../commands/image.js";
3
+ export * from "../commands/list.js";
4
+ export * from "../commands/quote.js";
5
+ export * from "../commands/toolbar.js";
@@ -0,0 +1,5 @@
1
+ export * from "./typography.js";
2
+ export * from "./image.js";
3
+ export * from "./list.js";
4
+ export * from "./quote.js";
5
+ export * from "./toolbar.js";
@@ -0,0 +1,7 @@
1
+ import type { LexicalCommand } from "lexical";
2
+ export type ListCommandPayload = {
3
+ themeStyleId?: string;
4
+ };
5
+ export declare const INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<ListCommandPayload>;
6
+ export declare const INSERT_ORDERED_LIST_COMMAND: LexicalCommand<ListCommandPayload>;
7
+ export declare const REMOVE_LIST_COMMAND: LexicalCommand<void>;
@@ -0,0 +1,7 @@
1
+ import { createCommand } from "lexical";
2
+ const INSERT_UNORDERED_LIST_COMMAND = createCommand("INSERT_UNORDERED_LIST_COMMAND");
3
+ const INSERT_ORDERED_LIST_COMMAND = createCommand("INSERT_ORDERED_LIST_COMMAND");
4
+ const REMOVE_LIST_COMMAND = createCommand("REMOVE_LIST_COMMAND");
5
+ export { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND };
6
+
7
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands/list.js","sources":["../../src/commands/list.ts"],"sourcesContent":["import type { LexicalCommand } from \"lexical\";\nimport { createCommand } from \"lexical\";\n\nexport type ListCommandPayload = {\n themeStyleId?: string;\n};\n\nexport const INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<ListCommandPayload> = createCommand(\n \"INSERT_UNORDERED_LIST_COMMAND\"\n);\n\nexport const INSERT_ORDERED_LIST_COMMAND: LexicalCommand<ListCommandPayload> = createCommand(\n \"INSERT_ORDERED_LIST_COMMAND\"\n);\n\nexport const REMOVE_LIST_COMMAND: LexicalCommand<void> = createCommand(\"REMOVE_LIST_COMMAND\");\n"],"names":["INSERT_UNORDERED_LIST_COMMAND","createCommand","INSERT_ORDERED_LIST_COMMAND","REMOVE_LIST_COMMAND"],"mappings":";AAOO,MAAMA,gCAAoEC,cAC7E;AAGG,MAAMC,8BAAkED,cAC3E;AAGG,MAAME,sBAA4CF,cAAc"}
@@ -0,0 +1,5 @@
1
+ import type { LexicalCommand } from "lexical";
2
+ export type QuoteCommandPayload = {
3
+ themeStyleId: string;
4
+ };
5
+ export declare const INSERT_QUOTE_COMMAND: LexicalCommand<QuoteCommandPayload>;
@@ -0,0 +1,5 @@
1
+ import { createCommand } from "lexical";
2
+ const INSERT_QUOTE_COMMAND = createCommand("INSERT_QUOTE_COMMAND");
3
+ export { INSERT_QUOTE_COMMAND };
4
+
5
+ //# sourceMappingURL=quote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands/quote.js","sources":["../../src/commands/quote.ts"],"sourcesContent":["import type { LexicalCommand } from \"lexical\";\nimport { createCommand } from \"lexical\";\n\nexport type QuoteCommandPayload = {\n themeStyleId: string;\n};\n\nexport const INSERT_QUOTE_COMMAND: LexicalCommand<QuoteCommandPayload> =\n createCommand(\"INSERT_QUOTE_COMMAND\");\n"],"names":["INSERT_QUOTE_COMMAND","createCommand"],"mappings":";AAOO,MAAMA,uBACTC,cAAc"}
@@ -0,0 +1 @@
1
+ export declare const HIDE_FLOATING_TOOLBAR: import("lexical").LexicalCommand<unknown>;
@@ -0,0 +1,5 @@
1
+ import { createCommand } from "lexical";
2
+ const HIDE_FLOATING_TOOLBAR = createCommand("HIDE_FLOATING_TOOLBAR_COMMAND");
3
+ export { HIDE_FLOATING_TOOLBAR };
4
+
5
+ //# sourceMappingURL=toolbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands/toolbar.js","sources":["../../src/commands/toolbar.ts"],"sourcesContent":["import { createCommand } from \"lexical\";\n\nexport const HIDE_FLOATING_TOOLBAR = createCommand(\"HIDE_FLOATING_TOOLBAR_COMMAND\");\n"],"names":["HIDE_FLOATING_TOOLBAR","createCommand"],"mappings":";AAEO,MAAMA,wBAAwBC,cAAc"}
@@ -0,0 +1,8 @@
1
+ import type { LexicalCommand, LexicalEditor, NodeKey } from "lexical";
2
+ import type { TypographyValue } from "@webiny/lexical-theme";
3
+ export declare const ADD_TYPOGRAPHY_COMMAND: LexicalCommand<TypographyPayload>;
4
+ export interface TypographyPayload {
5
+ value: TypographyValue;
6
+ caption?: LexicalEditor;
7
+ key?: NodeKey;
8
+ }
@@ -0,0 +1,5 @@
1
+ import { createCommand } from "lexical";
2
+ const ADD_TYPOGRAPHY_COMMAND = createCommand("ADD_TYPOGRAPHY_COMMAND");
3
+ export { ADD_TYPOGRAPHY_COMMAND };
4
+
5
+ //# sourceMappingURL=typography.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands/typography.js","sources":["../../src/commands/typography.ts"],"sourcesContent":["import type { LexicalCommand, LexicalEditor, NodeKey } from \"lexical\";\nimport { createCommand } from \"lexical\";\nimport type { TypographyValue } from \"@webiny/lexical-theme\";\n\nexport const ADD_TYPOGRAPHY_COMMAND: LexicalCommand<TypographyPayload> =\n createCommand(\"ADD_TYPOGRAPHY_COMMAND\");\n\nexport interface TypographyPayload {\n value: TypographyValue;\n caption?: LexicalEditor;\n key?: NodeKey;\n}\n"],"names":["ADD_TYPOGRAPHY_COMMAND","createCommand"],"mappings":";AAIO,MAAMA,yBACTC,cAAc"}
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ interface EditorPlaceholderProps {
3
+ text: React.ReactNode;
4
+ styles?: React.CSSProperties;
5
+ fallbackClassName?: string;
6
+ }
7
+ /**
8
+ * Renders our own placeholder, shown whenever the editor's text content is empty —
9
+ * regardless of the current block type. Lexical's built-in placeholder only shows for an
10
+ * empty paragraph, so it disappears when the block is a heading, quote, etc. The placeholder
11
+ * also picks up the current block's typography (via its style id), falling back to the
12
+ * default paragraph style, so its size/font matches whatever the user is about to type.
13
+ */
14
+ export declare const EditorPlaceholder: ({ text, styles, fallbackClassName }: EditorPlaceholderProps) => React.JSX.Element | null;
15
+ export {};
@@ -0,0 +1,41 @@
1
+ import react, { useEffect, useState } from "react";
2
+ import { $getRoot } from "lexical";
3
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
4
+ import { $isRootTextContentEmpty } from "@lexical/text";
5
+ import { Placeholder } from "../../ui/Placeholder.js";
6
+ import { useRichTextEditor } from "../../hooks/index.js";
7
+ const hasStyleId = (node)=>!!node && "function" == typeof node.getStyleId;
8
+ const EditorPlaceholder = ({ text, styles, fallbackClassName })=>{
9
+ const [editor] = useLexicalComposerContext();
10
+ const { theme } = useRichTextEditor();
11
+ const [state, setState] = useState({
12
+ isEmpty: true
13
+ });
14
+ useEffect(()=>{
15
+ const update = ()=>{
16
+ editor.getEditorState().read(()=>{
17
+ const isEmpty = $isRootTextContentEmpty(editor.isComposing());
18
+ const firstBlock = $getRoot().getFirstChild();
19
+ const styleId = hasStyleId(firstBlock) ? firstBlock.getStyleId() : void 0;
20
+ const className = styleId ? theme.getTypographyById(styleId)?.className : void 0;
21
+ setState({
22
+ isEmpty,
23
+ className
24
+ });
25
+ });
26
+ };
27
+ update();
28
+ return editor.registerUpdateListener(update);
29
+ }, [
30
+ editor,
31
+ theme
32
+ ]);
33
+ if (!state.isEmpty) return null;
34
+ return /*#__PURE__*/ react.createElement(Placeholder, {
35
+ styles: styles,
36
+ className: state.className ?? fallbackClassName
37
+ }, text);
38
+ };
39
+ export { EditorPlaceholder };
40
+
41
+ //# sourceMappingURL=EditorPlaceholder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components/Editor/EditorPlaceholder.js","sources":["../../../src/components/Editor/EditorPlaceholder.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport type { LexicalNode } from \"lexical\";\nimport { $getRoot } from \"lexical\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { $isRootTextContentEmpty } from \"@lexical/text\";\nimport { Placeholder } from \"~/ui/Placeholder.js\";\nimport { useRichTextEditor } from \"~/hooks/index.js\";\n\ninterface EditorPlaceholderProps {\n text: React.ReactNode;\n styles?: React.CSSProperties;\n fallbackClassName?: string;\n}\n\ninterface WithStyleId {\n getStyleId(): string | undefined;\n}\n\nconst hasStyleId = (node: LexicalNode | null): node is LexicalNode & WithStyleId => {\n return !!node && typeof (node as Partial<WithStyleId>).getStyleId === \"function\";\n};\n\n/**\n * Renders our own placeholder, shown whenever the editor's text content is empty —\n * regardless of the current block type. Lexical's built-in placeholder only shows for an\n * empty paragraph, so it disappears when the block is a heading, quote, etc. The placeholder\n * also picks up the current block's typography (via its style id), falling back to the\n * default paragraph style, so its size/font matches whatever the user is about to type.\n */\nexport const EditorPlaceholder = ({ text, styles, fallbackClassName }: EditorPlaceholderProps) => {\n const [editor] = useLexicalComposerContext();\n const { theme } = useRichTextEditor();\n const [state, setState] = useState<{ isEmpty: boolean; className?: string }>({\n isEmpty: true\n });\n\n useEffect(() => {\n const update = () => {\n editor.getEditorState().read(() => {\n const isEmpty = $isRootTextContentEmpty(editor.isComposing());\n const firstBlock = $getRoot().getFirstChild();\n const styleId = hasStyleId(firstBlock) ? firstBlock.getStyleId() : undefined;\n const className = styleId ? theme.getTypographyById(styleId)?.className : undefined;\n setState({ isEmpty, className });\n });\n };\n update();\n return editor.registerUpdateListener(update);\n }, [editor, theme]);\n\n if (!state.isEmpty) {\n return null;\n }\n\n return (\n <Placeholder styles={styles} className={state.className ?? fallbackClassName}>\n {text}\n </Placeholder>\n );\n};\n"],"names":["hasStyleId","node","EditorPlaceholder","text","styles","fallbackClassName","editor","useLexicalComposerContext","theme","useRichTextEditor","state","setState","useState","useEffect","update","isEmpty","$isRootTextContentEmpty","firstBlock","$getRoot","styleId","undefined","className","Placeholder"],"mappings":";;;;;;AAkBA,MAAMA,aAAa,CAACC,OACT,CAAC,CAACA,QAAQ,AAAqD,cAArD,OAAQA,KAA8B,UAAU;AAU9D,MAAMC,oBAAoB,CAAC,EAAEC,IAAI,EAAEC,MAAM,EAAEC,iBAAiB,EAA0B;IACzF,MAAM,CAACC,OAAO,GAAGC;IACjB,MAAM,EAAEC,KAAK,EAAE,GAAGC;IAClB,MAAM,CAACC,OAAOC,SAAS,GAAGC,SAAmD;QACzE,SAAS;IACb;IAEAC,UAAU;QACN,MAAMC,SAAS;YACXR,OAAO,cAAc,GAAG,IAAI,CAAC;gBACzB,MAAMS,UAAUC,wBAAwBV,OAAO,WAAW;gBAC1D,MAAMW,aAAaC,WAAW,aAAa;gBAC3C,MAAMC,UAAUnB,WAAWiB,cAAcA,WAAW,UAAU,KAAKG;gBACnE,MAAMC,YAAYF,UAAUX,MAAM,iBAAiB,CAACW,UAAU,YAAYC;gBAC1ET,SAAS;oBAAEI;oBAASM;gBAAU;YAClC;QACJ;QACAP;QACA,OAAOR,OAAO,sBAAsB,CAACQ;IACzC,GAAG;QAACR;QAAQE;KAAM;IAElB,IAAI,CAACE,MAAM,OAAO,EACd,OAAO;IAGX,OAAO,WAAP,GACI,oBAACY,aAAWA;QAAC,QAAQlB;QAAQ,WAAWM,MAAM,SAAS,IAAIL;OACtDF;AAGb"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * In the "Heading" editor, we only want to support heading tags.
3
+ * However, when the editor is empty, and you start typing, Lexical automatically creates an empty "paragraph" node.
4
+ * This ensures that any paragraph node is automatically converted to a heading node.
5
+ */
6
+ export declare const EnsureHeadingTagPlugin: () => null;
@@ -0,0 +1,13 @@
1
+ import { useEffect } from "react";
2
+ import { $createHeadingNode, ParagraphNode } from "@webiny/lexical-nodes";
3
+ import { useRichTextEditor } from "../../hooks/index.js";
4
+ const EnsureHeadingTagPlugin = ()=>{
5
+ const { editor } = useRichTextEditor();
6
+ useEffect(()=>editor.registerNodeTransform(ParagraphNode, (node)=>{
7
+ node.replace($createHeadingNode("h1"), true);
8
+ }), []);
9
+ return null;
10
+ };
11
+ export { EnsureHeadingTagPlugin };
12
+
13
+ //# sourceMappingURL=EnsureHeadingTagPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components/Editor/EnsureHeadingTagPlugin.js","sources":["../../../src/components/Editor/EnsureHeadingTagPlugin.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { ParagraphNode, $createHeadingNode } from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks/index.js\";\n\n/**\n * In the \"Heading\" editor, we only want to support heading tags.\n * However, when the editor is empty, and you start typing, Lexical automatically creates an empty \"paragraph\" node.\n * This ensures that any paragraph node is automatically converted to a heading node.\n */\nexport const EnsureHeadingTagPlugin = () => {\n const { editor } = useRichTextEditor();\n\n useEffect(\n () =>\n editor.registerNodeTransform(ParagraphNode, node => {\n node.replace($createHeadingNode(\"h1\"), true);\n }),\n []\n );\n return null;\n};\n"],"names":["EnsureHeadingTagPlugin","editor","useRichTextEditor","useEffect","ParagraphNode","node","$createHeadingNode"],"mappings":";;;AASO,MAAMA,yBAAyB;IAClC,MAAM,EAAEC,MAAM,EAAE,GAAGC;IAEnBC,UACI,IACIF,OAAO,qBAAqB,CAACG,eAAeC,CAAAA;YACxCA,KAAK,OAAO,CAACC,mBAAmB,OAAO;QAC3C,IACJ,EAAE;IAEN,OAAO;AACX"}
@@ -1,26 +1,55 @@
1
1
  import React from "react";
2
- import { LexicalValue, ThemeEmotionMap } from "../../types";
3
- import { Klass, LexicalNode } from "lexical";
4
- import { WebinyTheme } from "../../themes/webinyLexicalTheme";
2
+ import type { Klass, LexicalNode } from "lexical";
3
+ import { LexicalComposer } from "@lexical/react/LexicalComposer";
4
+ import type { EditorTheme } from "@webiny/lexical-theme";
5
+ import type { LexicalValue, ToolbarActionPlugin } from "../../types.js";
6
+ export type InitialEditorConfig = React.ComponentProps<typeof LexicalComposer>["initialConfig"] & {
7
+ editorId: string;
8
+ };
5
9
  export interface RichTextEditorProps {
6
- toolbar?: React.ReactNode;
7
- tag?: string;
8
- onChange?: (json: LexicalValue) => void;
9
- value: LexicalValue | null;
10
+ children?: React.ReactNode | React.ReactNode[];
11
+ classes?: string;
12
+ disabled?: boolean;
13
+ contentEditableStyles?: React.CSSProperties;
10
14
  focus?: boolean;
11
- placeholder?: string;
15
+ height?: number | string;
12
16
  nodes?: Klass<LexicalNode>[];
13
- /**
14
- * @description Lexical plugins
15
- */
16
- children?: React.ReactNode | React.ReactNode[];
17
17
  onBlur?: (editorState: LexicalValue) => void;
18
- height?: number | string;
18
+ onChange?: (value: LexicalValue) => void;
19
+ placeholder?: string;
20
+ placeholderStyles?: React.CSSProperties;
21
+ staticToolbar?: React.ReactNode;
22
+ styles?: React.CSSProperties;
23
+ tag?: string;
24
+ theme: EditorTheme;
25
+ toolbarActionPlugins?: ToolbarActionPlugin[];
26
+ toolbar?: React.ReactNode;
27
+ value: LexicalValue | null | undefined;
28
+ configRef?: React.MutableRefObject<InitialEditorConfig | undefined>;
19
29
  width?: number | string;
20
- theme: WebinyTheme;
21
- themeEmotionMap?: ThemeEmotionMap;
22
30
  }
23
31
  /**
24
32
  * @description Main editor container
25
33
  */
26
- export declare const RichTextEditor: import("@webiny/react-composition").ComposableFC<RichTextEditorProps>;
34
+ export declare const RichTextEditor: ((props: RichTextEditorProps) => React.JSX.Element) & {
35
+ original: (props: RichTextEditorProps) => React.JSX.Element;
36
+ originalName: string;
37
+ displayName: string;
38
+ } & {
39
+ original: ((props: RichTextEditorProps) => React.JSX.Element) & {
40
+ original: (props: RichTextEditorProps) => React.JSX.Element;
41
+ originalName: string;
42
+ displayName: string;
43
+ };
44
+ originalName: string;
45
+ displayName: string;
46
+ } & {
47
+ createDecorator: (decorator: import("@webiny/react-composition").ComponentDecorator<((props: RichTextEditorProps) => React.JSX.Element) & {
48
+ original: (props: RichTextEditorProps) => React.JSX.Element;
49
+ originalName: string;
50
+ displayName: string;
51
+ }>) => (props: unknown) => React.JSX.Element;
52
+ };
53
+ export declare namespace RichTextEditor {
54
+ type InitialConfig = InitialEditorConfig;
55
+ }
@@ -1,138 +1,105 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.RichTextEditor = void 0;
9
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
- var _react = _interopRequireWildcard(require("react"));
13
- var _Placeholder = require("../../ui/Placeholder");
14
- var _generateInitialLexicalValue = require("../../utils/generateInitialLexicalValue");
15
- var _LexicalComposer = require("@lexical/react/LexicalComposer");
16
- var _LexicalOnChangePlugin = require("@lexical/react/LexicalOnChangePlugin");
17
- var _LexicalAutoFocusPlugin = require("@lexical/react/LexicalAutoFocusPlugin");
18
- var _LexicalClearEditorPlugin = require("@lexical/react/LexicalClearEditorPlugin");
19
- var _LexicalRichTextPlugin = require("@lexical/react/LexicalRichTextPlugin");
20
- var _LexicalErrorBoundary = _interopRequireDefault(require("@lexical/react/LexicalErrorBoundary"));
21
- var _reactComposition = require("@webiny/react-composition");
22
- var _LexicalContentEditable = require("@lexical/react/LexicalContentEditable");
23
- var _RichTextEditorContext = require("../../context/RichTextEditorContext");
24
- var _isValidLexicalData = require("../../utils/isValidLexicalData");
25
- var _LexicalUpdateStatePlugin = require("../../plugins/LexicalUpdateStatePlugin");
26
- var _BlurEventPlugin = require("../../plugins/BlurEventPlugin/BlurEventPlugin");
27
- var _FontColorPlugin = require("../../plugins/FontColorPlugin/FontColorPlugin");
28
- var _webinyLexicalTheme = require("../../themes/webinyLexicalTheme");
29
- var _webinyNodes = require("../../nodes/webinyNodes");
30
- var _TypographyPlugin = require("../../plugins/TypographyPlugin/TypographyPlugin");
31
- var _WebinyQuoteNodePlugin = require("../../plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin");
32
- var _LexicalHistoryPlugin = require("@lexical/react/LexicalHistoryPlugin");
33
- var _SharedHistoryContext = require("../../context/SharedHistoryContext");
34
- var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
35
- var _react2 = require("@emotion/react");
36
- var _toTypographyEmotionMap = require("../../utils/toTypographyEmotionMap");
37
- var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
38
- var toolbar = _ref.toolbar,
39
- onChange = _ref.onChange,
40
- value = _ref.value,
41
- nodes = _ref.nodes,
42
- placeholder = _ref.placeholder,
43
- children = _ref.children,
44
- onBlur = _ref.onBlur,
45
- focus = _ref.focus,
46
- width = _ref.width,
47
- height = _ref.height,
48
- theme = _ref.theme,
49
- themeEmotionMap = _ref.themeEmotionMap;
50
- var _useSharedHistoryCont = (0, _SharedHistoryContext.useSharedHistoryContext)(),
51
- historyState = _useSharedHistoryCont.historyState;
52
- var placeholderElem = /*#__PURE__*/_react.default.createElement(_Placeholder.Placeholder, null, placeholder || "Enter text...");
53
- var scrollRef = (0, _react.useRef)(null);
54
- var _useState = (0, _react.useState)(undefined),
55
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
56
- floatingAnchorElem = _useState2[0],
57
- setFloatingAnchorElem = _useState2[1];
58
- var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
59
- setTheme = _useRichTextEditor.setTheme,
60
- setThemeEmotionMap = _useRichTextEditor.setThemeEmotionMap;
61
- (0, _react.useEffect)(function () {
62
- setTheme(theme);
63
- setThemeEmotionMap(themeEmotionMap);
64
- }, [themeEmotionMap]);
65
- var onRef = function onRef(_floatingAnchorElem) {
66
- if (_floatingAnchorElem !== null) {
67
- setFloatingAnchorElem(_floatingAnchorElem);
68
- }
69
- };
70
- var sizeStyle = {
71
- height: height || "",
72
- width: width || ""
73
- };
74
- var initialConfig = {
75
- editorState: (0, _isValidLexicalData.isValidLexicalData)(value) ? value : (0, _generateInitialLexicalValue.generateInitialLexicalValue)(),
76
- namespace: "webiny",
77
- onError: function onError(error) {
78
- throw error;
79
- },
80
- nodes: [].concat((0, _toConsumableArray2.default)(_webinyNodes.WebinyNodes), (0, _toConsumableArray2.default)(nodes || [])),
81
- theme: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _webinyLexicalTheme.webinyEditorTheme), {}, {
82
- emotionMap: themeEmotionMap
83
- })
84
- };
85
- function handleOnChange(editorState, editor) {
86
- editorState.read(function () {
87
- if (typeof onChange === "function") {
88
- var _editorState = editor.getEditorState();
89
- //TODO: send plain JSON object
90
- onChange(JSON.stringify(_editorState.toJSON()));
91
- }
92
- });
93
- }
94
- return /*#__PURE__*/_react.default.createElement(_LexicalComposer.LexicalComposer, {
95
- initialConfig: initialConfig
96
- }, /*#__PURE__*/_react.default.createElement("div", {
97
- ref: scrollRef,
98
- style: (0, _objectSpread2.default)({}, sizeStyle)
99
- }, /*#__PURE__*/_react.default.createElement(_LexicalOnChangePlugin.OnChangePlugin, {
100
- onChange: handleOnChange
101
- }), value && /*#__PURE__*/_react.default.createElement(_LexicalUpdateStatePlugin.LexicalUpdateStatePlugin, {
102
- value: value
103
- }), /*#__PURE__*/_react.default.createElement(_LexicalClearEditorPlugin.ClearEditorPlugin, null), /*#__PURE__*/_react.default.createElement(_FontColorPlugin.FontColorPlugin, null), /*#__PURE__*/_react.default.createElement(_TypographyPlugin.TypographyPlugin, null), /*#__PURE__*/_react.default.createElement(_WebinyQuoteNodePlugin.QuotePlugin, null), /*#__PURE__*/_react.default.createElement(_LexicalHistoryPlugin.HistoryPlugin, {
104
- externalHistoryState: historyState
105
- }), onBlur && /*#__PURE__*/_react.default.createElement(_BlurEventPlugin.BlurEventPlugin, {
106
- onBlur: onBlur
107
- }), focus && /*#__PURE__*/_react.default.createElement(_LexicalAutoFocusPlugin.AutoFocusPlugin, null), children, /*#__PURE__*/_react.default.createElement(_LexicalRichTextPlugin.RichTextPlugin, {
108
- contentEditable: /*#__PURE__*/_react.default.createElement("div", {
109
- className: "editor-scroller",
110
- style: (0, _objectSpread2.default)({}, sizeStyle)
111
- }, /*#__PURE__*/_react.default.createElement("div", {
112
- className: "editor",
113
- ref: onRef,
114
- style: (0, _objectSpread2.default)({}, sizeStyle)
115
- }, /*#__PURE__*/_react.default.createElement(_LexicalContentEditable.ContentEditable, {
116
- style: (0, _objectSpread2.default)({
117
- outline: 0
118
- }, sizeStyle)
119
- }))),
120
- placeholder: placeholderElem,
121
- ErrorBoundary: _LexicalErrorBoundary.default
122
- }), floatingAnchorElem && toolbar));
1
+ import react, { Fragment, useId, useRef, useState } from "react";
2
+ import { LexicalComposer } from "@lexical/react/LexicalComposer";
3
+ import { AutoFocusPlugin } from "@lexical/react/LexicalAutoFocusPlugin";
4
+ import { ClearEditorPlugin } from "@lexical/react/LexicalClearEditorPlugin";
5
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
6
+ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
7
+ import { makeDecoratable } from "@webiny/react-composition";
8
+ import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
9
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
10
+ import { allNodes } from "@webiny/lexical-nodes";
11
+ import { RichTextEditorProvider } from "../../context/RichTextEditorContext.js";
12
+ import { BlurEventPlugin } from "../../plugins/BlurEventPlugin/BlurEventPlugin.js";
13
+ import { EditorPlaceholder } from "./EditorPlaceholder.js";
14
+ import { SharedHistoryContext, useSharedHistoryContext } from "../../context/SharedHistoryContext.js";
15
+ import { LexicalEditorWithConfig, useLexicalEditorConfig } from "../LexicalEditorConfig/LexicalEditorConfig.js";
16
+ import { StateHandlingPlugin } from "../../plugins/StateHandlingPlugin.js";
17
+ const BaseRichTextEditor = ({ onChange, toolbar, staticToolbar, nodes, placeholder, children, onBlur, focus, styles, width, disabled = false, height, contentEditableStyles, placeholderStyles, ...props })=>{
18
+ const editorTheme = useRef(props.theme);
19
+ const config = useLexicalEditorConfig();
20
+ const { historyState } = useSharedHistoryContext();
21
+ const defaultParagraphClassName = props.theme?.typography?.paragraphs?.[0]?.className;
22
+ const scrollRef = useRef(null);
23
+ const [floatingAnchorElem, setFloatingAnchorElem] = useState(void 0);
24
+ const onRef = (_floatingAnchorElem)=>{
25
+ if (null !== _floatingAnchorElem) setFloatingAnchorElem(_floatingAnchorElem);
26
+ };
27
+ const sizeStyle = {
28
+ height: height || "",
29
+ width: width || ""
30
+ };
31
+ const configNodes = config.nodes.map((node)=>node.node);
32
+ const configPlugins = config.plugins.map((plugin)=>/*#__PURE__*/ react.createElement(Fragment, {
33
+ key: plugin.name
34
+ }, plugin.element));
35
+ const initialConfig = {
36
+ editorId: useId(),
37
+ editable: !disabled,
38
+ namespace: "webiny",
39
+ onError: ()=>{},
40
+ nodes: [
41
+ ...allNodes,
42
+ ...configNodes,
43
+ ...nodes || []
44
+ ],
45
+ theme: {
46
+ ...editorTheme.current.tokens,
47
+ $colors: editorTheme.current.colors,
48
+ $typography: editorTheme.current.typography,
49
+ $cacheKey: JSON.stringify(editorTheme.current)
50
+ }
51
+ };
52
+ if (props.configRef) props.configRef.current = initialConfig;
53
+ return /*#__PURE__*/ react.createElement(SharedHistoryContext, null, /*#__PURE__*/ react.createElement(LexicalComposer, {
54
+ initialConfig: initialConfig,
55
+ key: initialConfig.nodes.length
56
+ }, /*#__PURE__*/ react.createElement(RichTextEditorProvider, {
57
+ theme: props.theme,
58
+ toolbarActionPlugins: props.toolbarActionPlugins
59
+ }, staticToolbar && !disabled ? staticToolbar : null, /*#__PURE__*/ react.createElement("div", {
60
+ "data-role": "overlays",
61
+ className: "relative"
62
+ }), /*#__PURE__*/ react.createElement("div", {
63
+ className: "editor-shell",
64
+ ref: scrollRef,
65
+ style: {
66
+ ...styles,
67
+ ...sizeStyle,
68
+ overflow: "auto",
69
+ position: "relative"
70
+ }
71
+ }, /*#__PURE__*/ react.createElement(StateHandlingPlugin, {
72
+ value: props.value,
73
+ onChange: disabled ? void 0 : onChange
74
+ }), /*#__PURE__*/ react.createElement(ClearEditorPlugin, null), /*#__PURE__*/ react.createElement(HistoryPlugin, {
75
+ externalHistoryState: historyState
76
+ }), onBlur && /*#__PURE__*/ react.createElement(BlurEventPlugin, {
77
+ onBlur: onBlur
78
+ }), focus && /*#__PURE__*/ react.createElement(AutoFocusPlugin, null), configPlugins, children, /*#__PURE__*/ react.createElement(RichTextPlugin, {
79
+ contentEditable: /*#__PURE__*/ react.createElement("div", {
80
+ className: "editor-scroller",
81
+ style: {
82
+ ...sizeStyle
83
+ }
84
+ }, /*#__PURE__*/ react.createElement("div", {
85
+ className: "editor",
86
+ ref: onRef
87
+ }, /*#__PURE__*/ react.createElement(ContentEditable, {
88
+ disabled: disabled,
89
+ style: {
90
+ outline: 0,
91
+ ...contentEditableStyles
92
+ }
93
+ }))),
94
+ placeholder: null,
95
+ ErrorBoundary: LexicalErrorBoundary
96
+ }), /*#__PURE__*/ react.createElement(EditorPlaceholder, {
97
+ text: placeholder || "Enter text...",
98
+ styles: placeholderStyles,
99
+ fallbackClassName: defaultParagraphClassName
100
+ }), disabled ? null : floatingAnchorElem && toolbar))));
123
101
  };
102
+ const RichTextEditor = makeDecoratable("RichTextEditor", (props)=>/*#__PURE__*/ react.createElement(LexicalEditorWithConfig, null, /*#__PURE__*/ react.createElement(BaseRichTextEditor, props)));
103
+ export { RichTextEditor };
124
104
 
125
- /**
126
- * @description Main editor container
127
- */
128
- var RichTextEditor = (0, _reactComposition.makeComposable)("RichTextEditor", function (props) {
129
- return /*#__PURE__*/_react.default.createElement(_RichTextEditorContext.RichTextEditorProvider, null, /*#__PURE__*/_react.default.createElement(_react2.ClassNames, null, function (_ref2) {
130
- var _props$themeEmotionMa;
131
- var css = _ref2.css;
132
- var themeEmotionMap = (_props$themeEmotionMa = props === null || props === void 0 ? void 0 : props.themeEmotionMap) !== null && _props$themeEmotionMa !== void 0 ? _props$themeEmotionMa : (0, _toTypographyEmotionMap.toTypographyEmotionMap)(css, props.theme);
133
- return /*#__PURE__*/_react.default.createElement(_SharedHistoryContext.SharedHistoryContext, null, /*#__PURE__*/_react.default.createElement(BaseRichTextEditor, Object.assign({}, props, {
134
- themeEmotionMap: themeEmotionMap
135
- })));
136
- }));
137
- });
138
- exports.RichTextEditor = RichTextEditor;
105
+ //# sourceMappingURL=RichTextEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["BaseRichTextEditor","toolbar","onChange","value","nodes","placeholder","children","onBlur","focus","width","height","theme","themeEmotionMap","useSharedHistoryContext","historyState","placeholderElem","scrollRef","useRef","useState","undefined","floatingAnchorElem","setFloatingAnchorElem","useRichTextEditor","setTheme","setThemeEmotionMap","useEffect","onRef","_floatingAnchorElem","sizeStyle","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","WebinyNodes","webinyEditorTheme","emotionMap","handleOnChange","editor","read","getEditorState","JSON","stringify","toJSON","outline","LexicalErrorBoundary","RichTextEditor","makeComposable","props","css","toTypographyEmotionMap"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { LexicalValue, ThemeEmotionMap } from \"~/types\";\nimport { Placeholder } from \"~/ui/Placeholder\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { EditorState } from \"lexical/LexicalEditorState\";\nimport { Klass, LexicalEditor, LexicalNode } from \"lexical\";\nimport { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { OnChangePlugin } from \"@lexical/react/LexicalOnChangePlugin\";\nimport { AutoFocusPlugin } from \"@lexical/react/LexicalAutoFocusPlugin\";\nimport { ClearEditorPlugin } from \"@lexical/react/LexicalClearEditorPlugin\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport LexicalErrorBoundary from \"@lexical/react/LexicalErrorBoundary\";\nimport { makeComposable } from \"@webiny/react-composition\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport { RichTextEditorProvider } from \"~/context/RichTextEditorContext\";\nimport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nimport { LexicalUpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\nimport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nimport { FontColorPlugin } from \"~/plugins/FontColorPlugin/FontColorPlugin\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\nimport { TypographyPlugin } from \"~/plugins/TypographyPlugin/TypographyPlugin\";\nimport { QuotePlugin } from \"~/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin\";\nimport { HistoryPlugin } from \"@lexical/react/LexicalHistoryPlugin\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { ClassNames } from \"@emotion/react\";\nimport { toTypographyEmotionMap } from \"~/utils/toTypographyEmotionMap\";\n\nexport interface RichTextEditorProps {\n toolbar?: React.ReactNode;\n tag?: string;\n onChange?: (json: LexicalValue) => void;\n value: LexicalValue | null;\n focus?: boolean;\n placeholder?: string;\n nodes?: Klass<LexicalNode>[];\n /**\n * @description Lexical plugins\n */\n children?: React.ReactNode | React.ReactNode[];\n onBlur?: (editorState: LexicalValue) => void;\n height?: number | string;\n width?: number | string;\n /*\n * @description Theme to be injected into lexical editor\n */\n theme: WebinyTheme;\n themeEmotionMap?: ThemeEmotionMap;\n}\n\nconst BaseRichTextEditor: React.FC<RichTextEditorProps> = ({\n toolbar,\n onChange,\n value,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n width,\n height,\n theme,\n themeEmotionMap\n}: RichTextEditorProps) => {\n const { historyState } = useSharedHistoryContext();\n const placeholderElem = <Placeholder>{placeholder || \"Enter text...\"}</Placeholder>;\n const scrollRef = useRef(null);\n const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLElement | undefined>(\n undefined\n );\n const { setTheme, setThemeEmotionMap } = useRichTextEditor();\n\n useEffect(() => {\n setTheme(theme);\n setThemeEmotionMap(themeEmotionMap);\n }, [themeEmotionMap]);\n\n const onRef = (_floatingAnchorElem: HTMLDivElement) => {\n if (_floatingAnchorElem !== null) {\n setFloatingAnchorElem(_floatingAnchorElem);\n }\n };\n\n const sizeStyle = {\n height: height || \"\",\n width: width || \"\"\n };\n\n const initialConfig = {\n editorState: isValidLexicalData(value) ? value : generateInitialLexicalValue(),\n namespace: \"webiny\",\n onError: (error: Error) => {\n throw error;\n },\n nodes: [...WebinyNodes, ...(nodes || [])],\n theme: { ...webinyEditorTheme, emotionMap: themeEmotionMap }\n };\n\n function handleOnChange(editorState: EditorState, editor: LexicalEditor) {\n editorState.read(() => {\n if (typeof onChange === \"function\") {\n const editorState = editor.getEditorState();\n //TODO: send plain JSON object\n onChange(JSON.stringify(editorState.toJSON()));\n }\n });\n }\n\n return (\n <LexicalComposer initialConfig={initialConfig}>\n <div ref={scrollRef} style={{ ...sizeStyle }}>\n {/* data */}\n <OnChangePlugin onChange={handleOnChange} />\n {value && <LexicalUpdateStatePlugin value={value} />}\n <ClearEditorPlugin />\n <FontColorPlugin />\n <TypographyPlugin />\n <QuotePlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Events */}\n {onBlur && <BlurEventPlugin onBlur={onBlur} />}\n {focus && <AutoFocusPlugin />}\n {/* External plugins and components */}\n {children}\n <RichTextPlugin\n contentEditable={\n <div className=\"editor-scroller\" style={{ ...sizeStyle }}>\n <div className=\"editor\" ref={onRef} style={{ ...sizeStyle }}>\n <ContentEditable style={{ outline: 0, ...sizeStyle }} />\n </div>\n </div>\n }\n placeholder={placeholderElem}\n ErrorBoundary={LexicalErrorBoundary}\n />\n {/* Toolbar */}\n {floatingAnchorElem && toolbar}\n </div>\n </LexicalComposer>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeComposable<RichTextEditorProps>(\"RichTextEditor\", props => {\n return (\n <RichTextEditorProvider>\n <ClassNames>\n {({ css }) => {\n const themeEmotionMap =\n props?.themeEmotionMap ?? toTypographyEmotionMap(css, props.theme);\n return (\n <SharedHistoryContext>\n <BaseRichTextEditor {...props} themeEmotionMap={themeEmotionMap} />\n </SharedHistoryContext>\n );\n }}\n </ClassNames>\n </RichTextEditorProvider>\n );\n});\n"],"mappings":"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"}
1
+ {"version":3,"file":"components/Editor/RichTextEditor.js","sources":["../../../src/components/Editor/RichTextEditor.tsx"],"sourcesContent":["import React, { Fragment, useId, useRef, useState } from \"react\";\nimport type { Klass, LexicalNode } from \"lexical\";\nimport { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { AutoFocusPlugin } from \"@lexical/react/LexicalAutoFocusPlugin\";\nimport { ClearEditorPlugin } from \"@lexical/react/LexicalClearEditorPlugin\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport { LexicalErrorBoundary } from \"@lexical/react/LexicalErrorBoundary\";\nimport { makeDecoratable } from \"@webiny/react-composition\";\nimport { HistoryPlugin } from \"@lexical/react/LexicalHistoryPlugin\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport type { EditorTheme } from \"@webiny/lexical-theme\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport { RichTextEditorProvider } from \"~/context/RichTextEditorContext.js\";\nimport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin.js\";\nimport type { LexicalValue, ToolbarActionPlugin } from \"~/types.js\";\nimport { EditorPlaceholder } from \"~/components/Editor/EditorPlaceholder.js\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext.js\";\nimport {\n LexicalEditorWithConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig.js\";\nimport { StateHandlingPlugin } from \"~/plugins/StateHandlingPlugin.js\";\n\nexport type InitialEditorConfig = React.ComponentProps<typeof LexicalComposer>[\"initialConfig\"] & {\n editorId: string;\n};\n\nexport interface RichTextEditorProps {\n children?: React.ReactNode | React.ReactNode[];\n classes?: string;\n disabled?: boolean;\n contentEditableStyles?: React.CSSProperties;\n focus?: boolean;\n height?: number | string;\n nodes?: Klass<LexicalNode>[];\n onBlur?: (editorState: LexicalValue) => void;\n onChange?: (value: LexicalValue) => void;\n placeholder?: string;\n placeholderStyles?: React.CSSProperties;\n staticToolbar?: React.ReactNode;\n styles?: React.CSSProperties;\n tag?: string;\n theme: EditorTheme;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n toolbar?: React.ReactNode;\n value: LexicalValue | null | undefined;\n configRef?: React.MutableRefObject<InitialEditorConfig | undefined>;\n width?: number | string;\n}\n\nconst BaseRichTextEditor = ({\n onChange,\n toolbar,\n staticToolbar,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n styles,\n width,\n disabled = false,\n height,\n contentEditableStyles,\n placeholderStyles,\n ...props\n}: RichTextEditorProps) => {\n const editorTheme = useRef(props.theme);\n const config = useLexicalEditorConfig();\n const { historyState } = useSharedHistoryContext();\n // Apply the default paragraph's typography class so the placeholder matches the real\n // text's size/line-height/font (the muted color is kept via placeholderStyles).\n const defaultParagraphClassName = props.theme?.typography?.paragraphs?.[0]?.className;\n const scrollRef = useRef(null);\n\n const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLElement | undefined>(\n undefined\n );\n const onRef = (_floatingAnchorElem: HTMLDivElement) => {\n if (_floatingAnchorElem !== null) {\n setFloatingAnchorElem(_floatingAnchorElem);\n }\n };\n\n const sizeStyle = {\n height: height || \"\",\n width: width || \"\"\n };\n\n const configNodes = config.nodes.map(node => node.node);\n const configPlugins = config.plugins.map(plugin => (\n <Fragment key={plugin.name}>{plugin.element}</Fragment>\n ));\n\n const initialConfig = {\n editorId: useId(),\n editable: !disabled,\n namespace: \"webiny\",\n onError: () => {\n // Ignore errors. We don't want to break the app because of errors caused by config/value updates.\n // These are usually resolved in the next component render cycle.\n },\n nodes: [...allNodes, ...configNodes, ...(nodes || [])],\n theme: {\n ...editorTheme.current.tokens,\n // I'm not aware of a better way to pass custom data to nodes.\n // For now, we're using Lexical's theme to pass colors and typography.\n $colors: editorTheme.current.colors,\n $typography: editorTheme.current.typography,\n $cacheKey: JSON.stringify(editorTheme.current)\n }\n };\n\n if (props.configRef) {\n props.configRef.current = initialConfig;\n }\n\n return (\n /**\n * Once the LexicalComposer is mounted, it caches the `initialConfig` internally, and all future\n * updates to the config will be ignored. This is a problem because we pull in Nodes from our config,\n * and initially, there can be multiple re-renders, while the config object is settled.\n *\n * To bypass this issue, we generate a naive `key` based on the number of Nodes.\n */\n <SharedHistoryContext>\n <LexicalComposer initialConfig={initialConfig} key={initialConfig.nodes.length}>\n <RichTextEditorProvider\n theme={props.theme}\n toolbarActionPlugins={props.toolbarActionPlugins}\n >\n {staticToolbar && !disabled ? staticToolbar : null}\n <div data-role={\"overlays\"} className={\"relative\"}></div>\n <div\n /* This className is necessary for targeting of editor container from CSS files. */\n className={\"editor-shell\"}\n ref={scrollRef}\n style={{\n ...styles,\n ...sizeStyle,\n overflow: \"auto\",\n position: \"relative\"\n }}\n >\n {/* State plugins. */}\n <StateHandlingPlugin\n value={props.value}\n onChange={disabled ? undefined : onChange}\n />\n <ClearEditorPlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Event plugins. */}\n {onBlur && <BlurEventPlugin onBlur={onBlur} />}\n {focus && <AutoFocusPlugin />}\n {/* External plugins and components. */}\n {configPlugins}\n {children}\n <RichTextPlugin\n contentEditable={\n <div className=\"editor-scroller\" style={{ ...sizeStyle }}>\n <div className=\"editor\" ref={onRef}>\n <ContentEditable\n disabled={disabled}\n style={{ outline: 0, ...contentEditableStyles }}\n />\n </div>\n </div>\n }\n placeholder={null}\n ErrorBoundary={LexicalErrorBoundary}\n />\n <EditorPlaceholder\n text={placeholder || \"Enter text...\"}\n styles={placeholderStyles}\n fallbackClassName={defaultParagraphClassName}\n />\n {/* Toolbar. */}\n {disabled ? null : floatingAnchorElem && toolbar}\n </div>\n </RichTextEditorProvider>\n </LexicalComposer>\n </SharedHistoryContext>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeDecoratable(\"RichTextEditor\", (props: RichTextEditorProps) => {\n return (\n <LexicalEditorWithConfig>\n <BaseRichTextEditor {...props} />\n </LexicalEditorWithConfig>\n );\n});\n\nexport namespace RichTextEditor {\n export type InitialConfig = InitialEditorConfig;\n}\n"],"names":["BaseRichTextEditor","onChange","toolbar","staticToolbar","nodes","placeholder","children","onBlur","focus","styles","width","disabled","height","contentEditableStyles","placeholderStyles","props","editorTheme","useRef","config","useLexicalEditorConfig","historyState","useSharedHistoryContext","defaultParagraphClassName","scrollRef","floatingAnchorElem","setFloatingAnchorElem","useState","undefined","onRef","_floatingAnchorElem","sizeStyle","configNodes","node","configPlugins","plugin","Fragment","initialConfig","useId","allNodes","JSON","SharedHistoryContext","LexicalComposer","RichTextEditorProvider","StateHandlingPlugin","ClearEditorPlugin","HistoryPlugin","BlurEventPlugin","AutoFocusPlugin","RichTextPlugin","ContentEditable","LexicalErrorBoundary","EditorPlaceholder","RichTextEditor","makeDecoratable","LexicalEditorWithConfig"],"mappings":"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"}