@webiny/lexical-editor 0.0.0-unstable.a4637c5ce6 → 0.0.0-unstable.a4f3e4ea8b

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 (292) hide show
  1. package/README.md +6 -12
  2. package/commands/image.js +2 -1
  3. package/commands/image.js.map +1 -1
  4. package/commands/index.d.ts +5 -5
  5. package/commands/index.js +5 -7
  6. package/commands/list.js +4 -3
  7. package/commands/list.js.map +1 -1
  8. package/commands/quote.js +2 -1
  9. package/commands/quote.js.map +1 -1
  10. package/commands/toolbar.js +2 -1
  11. package/commands/toolbar.js.map +1 -1
  12. package/commands/typography.js +2 -1
  13. package/commands/typography.js.map +1 -1
  14. package/components/Editor/EditorPlaceholder.d.ts +15 -0
  15. package/components/Editor/EditorPlaceholder.js +41 -0
  16. package/components/Editor/EditorPlaceholder.js.map +1 -0
  17. package/components/Editor/EnsureHeadingTagPlugin.js +9 -16
  18. package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -1
  19. package/components/Editor/RichTextEditor.d.ts +12 -6
  20. package/components/Editor/RichTextEditor.js +90 -118
  21. package/components/Editor/RichTextEditor.js.map +1 -1
  22. package/components/Editor/normalizeInputValue.d.ts +1 -1
  23. package/components/Editor/normalizeInputValue.js +11 -13
  24. package/components/Editor/normalizeInputValue.js.map +1 -1
  25. package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +17 -16
  26. package/components/LexicalEditorConfig/LexicalEditorConfig.js +30 -59
  27. package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
  28. package/components/LexicalEditorConfig/components/Node.js +21 -26
  29. package/components/LexicalEditorConfig/components/Node.js.map +1 -1
  30. package/components/LexicalEditorConfig/components/Plugin.js +21 -26
  31. package/components/LexicalEditorConfig/components/Plugin.js.map +1 -1
  32. package/components/LexicalEditorConfig/components/ToolbarElement.js +21 -26
  33. package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -1
  34. package/components/LexicalHtmlRenderer.d.ts +3 -6
  35. package/components/LexicalHtmlRenderer.js +38 -48
  36. package/components/LexicalHtmlRenderer.js.map +1 -1
  37. package/components/Toolbar/StaticToolbar.css +362 -56
  38. package/components/Toolbar/StaticToolbar.d.ts +1 -1
  39. package/components/Toolbar/StaticToolbar.js +13 -18
  40. package/components/Toolbar/StaticToolbar.js.map +1 -1
  41. package/components/ToolbarActions/BoldAction.js +22 -21
  42. package/components/ToolbarActions/BoldAction.js.map +1 -1
  43. package/components/ToolbarActions/BulletListAction.js +31 -36
  44. package/components/ToolbarActions/BulletListAction.js.map +1 -1
  45. package/components/ToolbarActions/CodeHighlightAction.js +22 -21
  46. package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
  47. package/components/ToolbarActions/FontColorAction.d.ts +8 -8
  48. package/components/ToolbarActions/FontColorAction.js +36 -42
  49. package/components/ToolbarActions/FontColorAction.js.map +1 -1
  50. package/components/ToolbarActions/FontSizeAction.d.ts +1 -13
  51. package/components/ToolbarActions/FontSizeAction.js +66 -85
  52. package/components/ToolbarActions/FontSizeAction.js.map +1 -1
  53. package/components/ToolbarActions/ImageAction.js +32 -33
  54. package/components/ToolbarActions/ImageAction.js.map +1 -1
  55. package/components/ToolbarActions/ItalicAction.js +22 -21
  56. package/components/ToolbarActions/ItalicAction.js.map +1 -1
  57. package/components/ToolbarActions/LinkAction.js +32 -33
  58. package/components/ToolbarActions/LinkAction.js.map +1 -1
  59. package/components/ToolbarActions/NumberedListAction.js +35 -44
  60. package/components/ToolbarActions/NumberedListAction.js.map +1 -1
  61. package/components/ToolbarActions/QuoteAction.js +29 -30
  62. package/components/ToolbarActions/QuoteAction.js.map +1 -1
  63. package/components/ToolbarActions/TextAlignmentAction.d.ts +8 -8
  64. package/components/ToolbarActions/TextAlignmentAction.js +42 -54
  65. package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
  66. package/components/ToolbarActions/TypographyAction.d.ts +8 -8
  67. package/components/ToolbarActions/TypographyAction.js +72 -99
  68. package/components/ToolbarActions/TypographyAction.js.map +1 -1
  69. package/components/ToolbarActions/UnderlineAction.js +21 -20
  70. package/components/ToolbarActions/UnderlineAction.js.map +1 -1
  71. package/context/FontColorActionContext.js +3 -2
  72. package/context/FontColorActionContext.js.map +1 -1
  73. package/context/RichTextEditorContext.d.ts +5 -6
  74. package/context/RichTextEditorContext.js +35 -17
  75. package/context/RichTextEditorContext.js.map +1 -1
  76. package/context/SharedHistoryContext.d.ts +2 -1
  77. package/context/SharedHistoryContext.js +11 -15
  78. package/context/SharedHistoryContext.js.map +1 -1
  79. package/context/TextAlignmentActionContextProps.js +3 -2
  80. package/context/TextAlignmentActionContextProps.js.map +1 -1
  81. package/context/TypographyActionContext.d.ts +1 -1
  82. package/context/TypographyActionContext.js +3 -2
  83. package/context/TypographyActionContext.js.map +1 -1
  84. package/exports/admin/ui/lexical.d.ts +15 -0
  85. package/exports/admin/ui/lexical.js +5 -0
  86. package/hooks/index.d.ts +7 -8
  87. package/hooks/index.js +7 -10
  88. package/hooks/useCurrentElement.d.ts +2 -2
  89. package/hooks/useCurrentElement.js +19 -23
  90. package/hooks/useCurrentElement.js.map +1 -1
  91. package/hooks/useCurrentSelection.js +41 -50
  92. package/hooks/useCurrentSelection.js.map +1 -1
  93. package/hooks/useFontColorPicker.d.ts +1 -1
  94. package/hooks/useFontColorPicker.js +6 -7
  95. package/hooks/useFontColorPicker.js.map +1 -1
  96. package/hooks/useIsMounted.js +7 -8
  97. package/hooks/useIsMounted.js.map +1 -1
  98. package/hooks/useRichTextEditor.d.ts +1 -1
  99. package/hooks/useRichTextEditor.js +6 -7
  100. package/hooks/useRichTextEditor.js.map +1 -1
  101. package/hooks/useTextAlignmentAction.d.ts +1 -1
  102. package/hooks/useTextAlignmentAction.js +6 -7
  103. package/hooks/useTextAlignmentAction.js.map +1 -1
  104. package/hooks/useTypographyAction.d.ts +1 -1
  105. package/hooks/useTypographyAction.js +6 -7
  106. package/hooks/useTypographyAction.js.map +1 -1
  107. package/images/icons/pencil-fill.js +17 -0
  108. package/images/icons/pencil-fill.js.map +1 -0
  109. package/images/icons/text-paragraph.js +18 -0
  110. package/images/icons/text-paragraph.js.map +1 -0
  111. package/images/icons/type-h1.js +17 -0
  112. package/images/icons/type-h1.js.map +1 -0
  113. package/images/icons/type-h2.js +17 -0
  114. package/images/icons/type-h2.js.map +1 -0
  115. package/images/icons/type-h3.js +17 -0
  116. package/images/icons/type-h3.js.map +1 -0
  117. package/images/icons/type-h4.js +17 -0
  118. package/images/icons/type-h4.js.map +1 -0
  119. package/images/icons/type-h5.js +17 -0
  120. package/images/icons/type-h5.js.map +1 -0
  121. package/images/icons/type-h6.js +17 -0
  122. package/images/icons/type-h6.js.map +1 -0
  123. package/images/icons/unlink_icon.js +27 -0
  124. package/images/icons/unlink_icon.js.map +1 -0
  125. package/index.d.ts +34 -37
  126. package/index.js +34 -50
  127. package/package.json +29 -26
  128. package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +1 -1
  129. package/plugins/BlurEventPlugin/BlurEventPlugin.js +12 -15
  130. package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
  131. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +8 -9
  132. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
  133. package/plugins/CodeHighlightPlugin/index.d.ts +1 -1
  134. package/plugins/CodeHighlightPlugin/index.js +1 -3
  135. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +4 -10
  136. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +16 -154
  137. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -1
  138. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +2 -3
  139. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +42 -57
  140. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -1
  141. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +4 -138
  142. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +5 -6
  143. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +7 -10
  144. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
  145. package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -1
  146. package/plugins/FloatingLinkEditorPlugin/index.js +1 -3
  147. package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js +6 -9
  148. package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js.map +1 -1
  149. package/plugins/FloatingLinkEditorPlugin/types.d.ts +10 -0
  150. package/plugins/FloatingLinkEditorPlugin/types.js +0 -0
  151. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +8 -0
  152. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +121 -0
  153. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +1 -0
  154. package/plugins/FontColorPlugin/FontColorPlugin.js +16 -21
  155. package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
  156. package/plugins/FontColorPlugin/applyColorToNode.js +5 -4
  157. package/plugins/FontColorPlugin/applyColorToNode.js.map +1 -1
  158. package/plugins/FontColorPlugin/applyColorToSelection.js +43 -61
  159. package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -1
  160. package/plugins/ImagesPlugin/ImagesPlugin.d.ts +2 -3
  161. package/plugins/ImagesPlugin/ImagesPlugin.js +83 -128
  162. package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
  163. package/plugins/LinkPlugin/LinkPlugin.js +47 -54
  164. package/plugins/LinkPlugin/LinkPlugin.js.map +1 -1
  165. package/plugins/ListPLugin/ListPlugin.js +47 -13
  166. package/plugins/ListPLugin/ListPlugin.js.map +1 -1
  167. package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +21 -14
  168. package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -1
  169. package/plugins/StateHandlingPlugin.d.ts +1 -1
  170. package/plugins/StateHandlingPlugin.js +59 -68
  171. package/plugins/StateHandlingPlugin.js.map +1 -1
  172. package/plugins/TypographyPlugin/TypographyPlugin.js +15 -22
  173. package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
  174. package/static/svg/pencil-fill.94cb216b.svg +1 -0
  175. package/static/svg/text-paragraph.61674422.svg +1 -0
  176. package/static/svg/type-h1.f292ffe1.svg +1 -0
  177. package/static/svg/type-h2.a9d1aa48.svg +1 -0
  178. package/static/svg/type-h3.4a29ff88.svg +1 -0
  179. package/static/svg/type-h4.7f48750c.svg +1 -0
  180. package/static/svg/type-h5.14b4ac56.svg +1 -0
  181. package/static/svg/type-h6.4e9dfe2d.svg +1 -0
  182. package/static/svg/unlink_icon.074ceed3.svg +1 -0
  183. package/types.d.ts +3 -3
  184. package/types.js +1 -9
  185. package/ui/ContentEditable.css +10 -10
  186. package/ui/ContentEditable.d.ts +2 -2
  187. package/ui/ContentEditable.js +6 -14
  188. package/ui/ContentEditable.js.map +1 -1
  189. package/ui/Divider.d.ts +2 -2
  190. package/ui/Divider.js +6 -5
  191. package/ui/Divider.js.map +1 -1
  192. package/ui/DropDown.d.ts +7 -10
  193. package/ui/DropDown.js +46 -178
  194. package/ui/DropDown.js.map +1 -1
  195. package/ui/ImageResizer.d.ts +2 -2
  196. package/ui/ImageResizer.js +173 -204
  197. package/ui/ImageResizer.js.map +1 -1
  198. package/ui/LinkPreview.css +2 -2
  199. package/ui/LinkPreview.d.ts +2 -2
  200. package/ui/LinkPreview.js +61 -84
  201. package/ui/LinkPreview.js.map +1 -1
  202. package/ui/Placeholder.css +2 -1
  203. package/ui/Placeholder.d.ts +1 -1
  204. package/ui/Placeholder.js +9 -20
  205. package/ui/Placeholder.js.map +1 -1
  206. package/ui/TextInput.d.ts +2 -2
  207. package/ui/TextInput.js +17 -30
  208. package/ui/TextInput.js.map +1 -1
  209. package/ui/ToolbarActionDialog.d.ts +1 -1
  210. package/ui/ToolbarActionDialog.js +65 -73
  211. package/ui/ToolbarActionDialog.js.map +1 -1
  212. package/utils/canUseDOM.js +2 -1
  213. package/utils/canUseDOM.js.map +1 -1
  214. package/utils/files.d.ts +6 -6
  215. package/utils/files.js +9 -18
  216. package/utils/files.js.map +1 -1
  217. package/utils/getDOMRangeRect.js +10 -20
  218. package/utils/getDOMRangeRect.js.map +1 -1
  219. package/utils/getSelectedNode.js +9 -20
  220. package/utils/getSelectedNode.js.map +1 -1
  221. package/utils/getTransparentImage.js +2 -3
  222. package/utils/getTransparentImage.js.map +1 -1
  223. package/utils/insertImage.d.ts +1 -1
  224. package/utils/insertImage.js +9 -11
  225. package/utils/insertImage.js.map +1 -1
  226. package/utils/isAnchorLink.js +2 -3
  227. package/utils/isAnchorLink.js.map +1 -1
  228. package/utils/isChildOfFloatingToolbar.js +6 -9
  229. package/utils/isChildOfFloatingToolbar.js.map +1 -1
  230. package/utils/isHTMLElement.js +3 -9
  231. package/utils/isHTMLElement.js.map +1 -1
  232. package/utils/isValidJSON.js +9 -10
  233. package/utils/isValidJSON.js.map +1 -1
  234. package/utils/isValidLexicalData.d.ts +2 -2
  235. package/utils/isValidLexicalData.js +17 -20
  236. package/utils/isValidLexicalData.js.map +1 -1
  237. package/utils/point.js +32 -45
  238. package/utils/point.js.map +1 -1
  239. package/utils/rect.d.ts +3 -3
  240. package/utils/rect.js +93 -126
  241. package/utils/rect.js.map +1 -1
  242. package/utils/sanitizeUrl.js +9 -22
  243. package/utils/sanitizeUrl.js.map +1 -1
  244. package/utils/setFloatingElemPosition.d.ts +1 -1
  245. package/utils/setFloatingElemPosition.js +30 -27
  246. package/utils/setFloatingElemPosition.js.map +1 -1
  247. package/commands/index.js.map +0 -1
  248. package/components/Editor/HeadingEditor.d.ts +0 -7
  249. package/components/Editor/HeadingEditor.js +0 -22
  250. package/components/Editor/HeadingEditor.js.map +0 -1
  251. package/components/Editor/ParagraphEditor.d.ts +0 -7
  252. package/components/Editor/ParagraphEditor.js +0 -22
  253. package/components/Editor/ParagraphEditor.js.map +0 -1
  254. package/components/Toolbar/Toolbar.css +0 -643
  255. package/components/Toolbar/Toolbar.d.ts +0 -6
  256. package/components/Toolbar/Toolbar.js +0 -148
  257. package/components/Toolbar/Toolbar.js.map +0 -1
  258. package/hooks/index.js.map +0 -1
  259. package/hooks/useList.d.ts +0 -2
  260. package/hooks/useList.js +0 -50
  261. package/hooks/useList.js.map +0 -1
  262. package/hooks/useQuote.d.ts +0 -2
  263. package/hooks/useQuote.js +0 -17
  264. package/hooks/useQuote.js.map +0 -1
  265. package/images/icons/chat-square-quote.svg +0 -1
  266. package/images/icons/chevron-down.svg +0 -1
  267. package/images/icons/code.svg +0 -1
  268. package/images/icons/font-color.svg +0 -1
  269. package/images/icons/indent.svg +0 -3
  270. package/images/icons/insert-image.svg +0 -4
  271. package/images/icons/justify.svg +0 -3
  272. package/images/icons/link.svg +0 -1
  273. package/images/icons/list-ol.svg +0 -1
  274. package/images/icons/list-ul.svg +0 -1
  275. package/images/icons/outdent.svg +0 -3
  276. package/images/icons/text-center.svg +0 -1
  277. package/images/icons/text-left.svg +0 -1
  278. package/images/icons/text-right.svg +0 -1
  279. package/images/icons/type-bold.svg +0 -1
  280. package/images/icons/type-italic.svg +0 -1
  281. package/images/icons/type-strikethrough.svg +0 -1
  282. package/images/icons/type-underline.svg +0 -1
  283. package/index.js.map +0 -1
  284. package/plugins/CodeHighlightPlugin/index.js.map +0 -1
  285. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +0 -8
  286. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +0 -104
  287. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +0 -1
  288. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +0 -9
  289. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +0 -34
  290. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js.map +0 -1
  291. package/plugins/FloatingLinkEditorPlugin/index.js.map +0 -1
  292. package/types.js.map +0 -1
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._
package/commands/image.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createCommand } from "lexical";
2
- export const INSERT_IMAGE_COMMAND = createCommand("INSERT_IMAGE_COMMAND");
2
+ const INSERT_IMAGE_COMMAND = createCommand("INSERT_IMAGE_COMMAND");
3
+ export { INSERT_IMAGE_COMMAND };
3
4
 
4
5
  //# sourceMappingURL=image.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createCommand","INSERT_IMAGE_COMMAND"],"sources":["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"],"mappings":"AACA,SAASA,aAAa,QAAQ,SAAS;AAOvC,OAAO,MAAMC,oBAAkD,GAC3DD,aAAa,CAAC,sBAAsB,CAAC","ignoreList":[]}
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"}
@@ -1,5 +1,5 @@
1
- export * from "./typography";
2
- export * from "./image";
3
- export * from "./list";
4
- export * from "./quote";
5
- export * from "./toolbar";
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";
package/commands/index.js CHANGED
@@ -1,7 +1,5 @@
1
- export * from "./typography";
2
- export * from "./image";
3
- export * from "./list";
4
- export * from "./quote";
5
- export * from "./toolbar";
6
-
7
- //# sourceMappingURL=index.js.map
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";
package/commands/list.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createCommand } from "lexical";
2
- export const INSERT_UNORDERED_LIST_COMMAND = createCommand("INSERT_UNORDERED_LIST_COMMAND");
3
- export const INSERT_ORDERED_LIST_COMMAND = createCommand("INSERT_ORDERED_LIST_COMMAND");
4
- export const REMOVE_LIST_COMMAND = createCommand("REMOVE_LIST_COMMAND");
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 };
5
6
 
6
7
  //# sourceMappingURL=list.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createCommand","INSERT_UNORDERED_LIST_COMMAND","INSERT_ORDERED_LIST_COMMAND","REMOVE_LIST_COMMAND"],"sources":["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"],"mappings":"AACA,SAASA,aAAa,QAAQ,SAAS;AAMvC,OAAO,MAAMC,6BAAiE,GAAGD,aAAa,CAC1F,+BACJ,CAAC;AAED,OAAO,MAAME,2BAA+D,GAAGF,aAAa,CACxF,6BACJ,CAAC;AAED,OAAO,MAAMG,mBAAyC,GAAGH,aAAa,CAAC,qBAAqB,CAAC","ignoreList":[]}
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"}
package/commands/quote.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createCommand } from "lexical";
2
- export const INSERT_QUOTE_COMMAND = createCommand("INSERT_QUOTE_COMMAND");
2
+ const INSERT_QUOTE_COMMAND = createCommand("INSERT_QUOTE_COMMAND");
3
+ export { INSERT_QUOTE_COMMAND };
3
4
 
4
5
  //# sourceMappingURL=quote.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createCommand","INSERT_QUOTE_COMMAND"],"sources":["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"],"mappings":"AACA,SAASA,aAAa,QAAQ,SAAS;AAMvC,OAAO,MAAMC,oBAAyD,GAClED,aAAa,CAAC,sBAAsB,CAAC","ignoreList":[]}
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"}
@@ -1,4 +1,5 @@
1
1
  import { createCommand } from "lexical";
2
- export const HIDE_FLOATING_TOOLBAR = createCommand("HIDE_FLOATING_TOOLBAR_COMMAND");
2
+ const HIDE_FLOATING_TOOLBAR = createCommand("HIDE_FLOATING_TOOLBAR_COMMAND");
3
+ export { HIDE_FLOATING_TOOLBAR };
3
4
 
4
5
  //# sourceMappingURL=toolbar.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createCommand","HIDE_FLOATING_TOOLBAR"],"sources":["toolbar.ts"],"sourcesContent":["import { createCommand } from \"lexical\";\n\nexport const HIDE_FLOATING_TOOLBAR = createCommand(\"HIDE_FLOATING_TOOLBAR_COMMAND\");\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,SAAS;AAEvC,OAAO,MAAMC,qBAAqB,GAAGD,aAAa,CAAC,+BAA+B,CAAC","ignoreList":[]}
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"}
@@ -1,4 +1,5 @@
1
1
  import { createCommand } from "lexical";
2
- export const ADD_TYPOGRAPHY_COMMAND = createCommand("ADD_TYPOGRAPHY_COMMAND");
2
+ const ADD_TYPOGRAPHY_COMMAND = createCommand("ADD_TYPOGRAPHY_COMMAND");
3
+ export { ADD_TYPOGRAPHY_COMMAND };
3
4
 
4
5
  //# sourceMappingURL=typography.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createCommand","ADD_TYPOGRAPHY_COMMAND"],"sources":["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"],"mappings":"AACA,SAASA,aAAa,QAAQ,SAAS;AAGvC,OAAO,MAAMC,sBAAyD,GAClED,aAAa,CAAC,wBAAwB,CAAC","ignoreList":[]}
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"}
@@ -1,20 +1,13 @@
1
1
  import { useEffect } from "react";
2
- import { ParagraphNode, $createHeadingNode } from "@webiny/lexical-nodes";
3
- import { useRichTextEditor } from "../../hooks";
4
-
5
- /**
6
- * In the "Heading" editor, we only want to support heading tags.
7
- * However, when the editor is empty, and you start typing, Lexical automatically creates an empty "paragraph" node.
8
- * This ensures that any paragraph node is automatically converted to a heading node.
9
- */
10
- export const EnsureHeadingTagPlugin = () => {
11
- const {
12
- editor
13
- } = useRichTextEditor();
14
- useEffect(() => editor.registerNodeTransform(ParagraphNode, node => {
15
- node.replace($createHeadingNode("h1"), true);
16
- }), []);
17
- return null;
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;
18
10
  };
11
+ export { EnsureHeadingTagPlugin };
19
12
 
20
13
  //# sourceMappingURL=EnsureHeadingTagPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","ParagraphNode","$createHeadingNode","useRichTextEditor","EnsureHeadingTagPlugin","editor","registerNodeTransform","node","replace"],"sources":["EnsureHeadingTagPlugin.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { ParagraphNode, $createHeadingNode } from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks\";\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"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AACjC,SAASC,aAAa,EAAEC,kBAAkB,QAAQ,uBAAuB;AACzE,SAASC,iBAAiB;;AAE1B;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,GAAGA,CAAA,KAAM;EACxC,MAAM;IAAEC;EAAO,CAAC,GAAGF,iBAAiB,CAAC,CAAC;EAEtCH,SAAS,CACL,MACIK,MAAM,CAACC,qBAAqB,CAACL,aAAa,EAAEM,IAAI,IAAI;IAChDA,IAAI,CAACC,OAAO,CAACN,kBAAkB,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;EAChD,CAAC,CAAC,EACN,EACJ,CAAC;EACD,OAAO,IAAI;AACf,CAAC","ignoreList":[]}
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,28 +1,31 @@
1
1
  import React from "react";
2
- import type { CSSObject } from "@emotion/react";
3
2
  import type { Klass, LexicalNode } from "lexical";
4
- import type { EditorTheme, ThemeEmotionMap } from "@webiny/lexical-theme";
5
- import type { LexicalValue, ToolbarActionPlugin } from "../../types";
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
+ };
6
9
  export interface RichTextEditorProps {
7
10
  children?: React.ReactNode | React.ReactNode[];
8
11
  classes?: string;
12
+ disabled?: boolean;
9
13
  contentEditableStyles?: React.CSSProperties;
10
14
  focus?: boolean;
11
15
  height?: number | string;
12
16
  nodes?: Klass<LexicalNode>[];
13
17
  onBlur?: (editorState: LexicalValue) => void;
14
- onChange?: (json: LexicalValue) => void;
18
+ onChange?: (value: LexicalValue) => void;
15
19
  placeholder?: string;
16
20
  placeholderStyles?: React.CSSProperties;
17
21
  staticToolbar?: React.ReactNode;
18
22
  styles?: React.CSSProperties;
19
23
  tag?: string;
20
24
  theme: EditorTheme;
21
- themeEmotionMap?: ThemeEmotionMap;
22
25
  toolbarActionPlugins?: ToolbarActionPlugin[];
23
- themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;
24
26
  toolbar?: React.ReactNode;
25
27
  value: LexicalValue | null | undefined;
28
+ configRef?: React.MutableRefObject<InitialEditorConfig | undefined>;
26
29
  width?: number | string;
27
30
  }
28
31
  /**
@@ -47,3 +50,6 @@ export declare const RichTextEditor: ((props: RichTextEditorProps) => React.JSX.
47
50
  displayName: string;
48
51
  }>) => (props: unknown) => React.JSX.Element;
49
52
  };
53
+ export declare namespace RichTextEditor {
54
+ type InitialConfig = InitialEditorConfig;
55
+ }
@@ -1,5 +1,4 @@
1
- import React, { Fragment, useRef, useState } from "react";
2
- import { css } from "emotion";
1
+ import react, { Fragment, useId, useRef, useState } from "react";
3
2
  import { LexicalComposer } from "@lexical/react/LexicalComposer";
4
3
  import { AutoFocusPlugin } from "@lexical/react/LexicalAutoFocusPlugin";
5
4
  import { ClearEditorPlugin } from "@lexical/react/LexicalClearEditorPlugin";
@@ -8,126 +7,99 @@ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
8
7
  import { makeDecoratable } from "@webiny/react-composition";
9
8
  import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
10
9
  import { ContentEditable } from "@lexical/react/LexicalContentEditable";
11
- import { createTheme, toTypographyEmotionMap } from "@webiny/lexical-theme";
12
10
  import { allNodes } from "@webiny/lexical-nodes";
13
- import { RichTextEditorProvider } from "../../context/RichTextEditorContext";
14
- import { BlurEventPlugin } from "../../plugins/BlurEventPlugin/BlurEventPlugin";
15
- import { Placeholder } from "../../ui/Placeholder";
16
- import { SharedHistoryContext, useSharedHistoryContext } from "../../context/SharedHistoryContext";
17
- import { LexicalEditorWithConfig, useLexicalEditorConfig } from "../LexicalEditorConfig/LexicalEditorConfig";
18
- import { StateHandlingPlugin } from "../../plugins/StateHandlingPlugin";
19
- const BaseRichTextEditor = ({
20
- toolbar,
21
- staticToolbar,
22
- onChange,
23
- nodes,
24
- placeholder,
25
- children,
26
- onBlur,
27
- focus,
28
- styles,
29
- width,
30
- height,
31
- contentEditableStyles,
32
- placeholderStyles,
33
- ...props
34
- }) => {
35
- const themeEmotionMap = props.themeEmotionMap ?? toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);
36
- const editorTheme = useRef(createTheme(props.theme));
37
- const config = useLexicalEditorConfig();
38
- const {
39
- historyState
40
- } = useSharedHistoryContext();
41
- const placeholderElem = /*#__PURE__*/React.createElement(Placeholder, {
42
- styles: placeholderStyles
43
- }, placeholder || "Enter text...");
44
- const scrollRef = useRef(null);
45
- const [floatingAnchorElem, setFloatingAnchorElem] = useState(undefined);
46
- const onRef = _floatingAnchorElem => {
47
- if (_floatingAnchorElem !== null) {
48
- setFloatingAnchorElem(_floatingAnchorElem);
49
- }
50
- };
51
- const sizeStyle = {
52
- height: height || "",
53
- width: width || ""
54
- };
55
- const configNodes = config.nodes.map(node => node.node);
56
- const configPlugins = config.plugins.map(plugin => /*#__PURE__*/React.createElement(Fragment, {
57
- key: plugin.name
58
- }, plugin.element));
59
- const initialConfig = {
60
- editorState: null,
61
- namespace: "webiny",
62
- onError: () => {
63
- // Ignore errors. We don't want to break the app because of errors caused by config/value updates.
64
- // These are usually resolved in the next component render cycle.
65
- },
66
- nodes: [...allNodes, ...configNodes, ...(nodes || [])],
67
- theme: {
68
- ...editorTheme.current,
69
- emotionMap: themeEmotionMap
70
- }
71
- };
72
- return (
73
- /*#__PURE__*/
74
- /**
75
- * Once the LexicalComposer is mounted, it caches the `initialConfig` internally, and all future
76
- * updates to the config will be ignored. This is a problem because we pull in Nodes from our config,
77
- * and initially, there can be multiple re-renders, while the config object is settled.
78
- *
79
- * To bypass this issue, we generate a naive `key` based on the number of Nodes.
80
- */
81
- React.createElement(SharedHistoryContext, null, /*#__PURE__*/React.createElement(LexicalComposer, {
82
- initialConfig: initialConfig,
83
- key: initialConfig.nodes.length
84
- }, /*#__PURE__*/React.createElement(RichTextEditorProvider, {
85
- theme: props.theme,
86
- themeEmotionMap: themeEmotionMap,
87
- toolbarActionPlugins: props.toolbarActionPlugins
88
- }, staticToolbar ? staticToolbar : null, /*#__PURE__*/React.createElement("div", {
89
- /* This className is necessary for targeting of editor container from CSS files. */
90
- className: "editor-shell",
91
- ref: scrollRef,
92
- style: {
93
- ...styles,
94
- ...sizeStyle,
95
- overflow: "auto",
96
- position: "relative"
97
- }
98
- }, /*#__PURE__*/React.createElement(StateHandlingPlugin, {
99
- value: props.value,
100
- onChange: onChange
101
- }), /*#__PURE__*/React.createElement(ClearEditorPlugin, null), /*#__PURE__*/React.createElement(HistoryPlugin, {
102
- externalHistoryState: historyState
103
- }), onBlur && /*#__PURE__*/React.createElement(BlurEventPlugin, {
104
- onBlur: onBlur
105
- }), focus && /*#__PURE__*/React.createElement(AutoFocusPlugin, null), configPlugins, children, /*#__PURE__*/React.createElement(RichTextPlugin, {
106
- contentEditable: /*#__PURE__*/React.createElement("div", {
107
- className: "editor-scroller",
108
- style: {
109
- ...sizeStyle
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)
110
50
  }
111
- }, /*#__PURE__*/React.createElement("div", {
112
- className: "editor",
113
- ref: onRef
114
- }, /*#__PURE__*/React.createElement(ContentEditable, {
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,
115
65
  style: {
116
- outline: 0,
117
- ...contentEditableStyles
66
+ ...styles,
67
+ ...sizeStyle,
68
+ overflow: "auto",
69
+ position: "relative"
118
70
  }
119
- }))),
120
- placeholder: placeholderElem,
121
- ErrorBoundary: LexicalErrorBoundary
122
- }), floatingAnchorElem && toolbar))))
123
- );
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))));
124
101
  };
125
-
126
- /**
127
- * @description Main editor container
128
- */
129
- export const RichTextEditor = makeDecoratable("RichTextEditor", props => {
130
- return /*#__PURE__*/React.createElement(LexicalEditorWithConfig, null, /*#__PURE__*/React.createElement(BaseRichTextEditor, props));
131
- });
102
+ const RichTextEditor = makeDecoratable("RichTextEditor", (props)=>/*#__PURE__*/ react.createElement(LexicalEditorWithConfig, null, /*#__PURE__*/ react.createElement(BaseRichTextEditor, props)));
103
+ export { RichTextEditor };
132
104
 
133
105
  //# sourceMappingURL=RichTextEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","Fragment","useRef","useState","css","LexicalComposer","AutoFocusPlugin","ClearEditorPlugin","RichTextPlugin","LexicalErrorBoundary","makeDecoratable","HistoryPlugin","ContentEditable","createTheme","toTypographyEmotionMap","allNodes","RichTextEditorProvider","BlurEventPlugin","Placeholder","SharedHistoryContext","useSharedHistoryContext","LexicalEditorWithConfig","useLexicalEditorConfig","StateHandlingPlugin","BaseRichTextEditor","toolbar","staticToolbar","onChange","nodes","placeholder","children","onBlur","focus","styles","width","height","contentEditableStyles","placeholderStyles","props","themeEmotionMap","theme","themeStylesTransformer","editorTheme","config","historyState","placeholderElem","createElement","scrollRef","floatingAnchorElem","setFloatingAnchorElem","undefined","onRef","_floatingAnchorElem","sizeStyle","configNodes","map","node","configPlugins","plugins","plugin","key","name","element","initialConfig","editorState","namespace","onError","current","emotionMap","length","toolbarActionPlugins","className","ref","style","overflow","position","value","externalHistoryState","contentEditable","outline","ErrorBoundary","RichTextEditor"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { Fragment, useRef, useState } from \"react\";\nimport { css } from \"emotion\";\nimport type { CSSObject } from \"@emotion/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, ThemeEmotionMap } from \"@webiny/lexical-theme\";\nimport { createTheme, toTypographyEmotionMap } from \"@webiny/lexical-theme\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport { RichTextEditorProvider } from \"~/context/RichTextEditorContext\";\nimport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nimport type { LexicalValue, ToolbarActionPlugin } from \"~/types\";\nimport { Placeholder } from \"~/ui/Placeholder\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport {\n LexicalEditorWithConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\nimport { StateHandlingPlugin } from \"~/plugins/StateHandlingPlugin\";\n\nexport interface RichTextEditorProps {\n children?: React.ReactNode | React.ReactNode[];\n classes?: string;\n contentEditableStyles?: React.CSSProperties;\n focus?: boolean;\n height?: number | string;\n nodes?: Klass<LexicalNode>[];\n onBlur?: (editorState: LexicalValue) => void;\n onChange?: (json: LexicalValue) => void;\n placeholder?: string;\n placeholderStyles?: React.CSSProperties;\n staticToolbar?: React.ReactNode;\n styles?: React.CSSProperties;\n tag?: string;\n theme: EditorTheme;\n themeEmotionMap?: ThemeEmotionMap;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;\n toolbar?: React.ReactNode;\n value: LexicalValue | null | undefined;\n width?: number | string;\n}\n\nconst BaseRichTextEditor = ({\n toolbar,\n staticToolbar,\n onChange,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n styles,\n width,\n height,\n contentEditableStyles,\n placeholderStyles,\n ...props\n}: RichTextEditorProps) => {\n const themeEmotionMap =\n props.themeEmotionMap ??\n toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);\n\n const editorTheme = useRef(createTheme(props.theme));\n const config = useLexicalEditorConfig();\n const { historyState } = useSharedHistoryContext();\n const placeholderElem = (\n <Placeholder styles={placeholderStyles}>{placeholder || \"Enter text...\"}</Placeholder>\n );\n const scrollRef = useRef(null);\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 editorState: null,\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: { ...editorTheme.current, emotionMap: themeEmotionMap }\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 themeEmotionMap={themeEmotionMap}\n toolbarActionPlugins={props.toolbarActionPlugins}\n >\n {staticToolbar ? staticToolbar : null}\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 value={props.value} onChange={onChange} />\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 style={{ outline: 0, ...contentEditableStyles }}\n />\n </div>\n </div>\n }\n placeholder={placeholderElem}\n ErrorBoundary={LexicalErrorBoundary}\n />\n {/* Toolbar. */}\n {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"],"mappings":"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","ignoreList":[]}
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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"}
@@ -1,4 +1,4 @@
1
- import type { LexicalValue, NormalizedInputValue } from "../../types";
1
+ import type { LexicalValue, NormalizedInputValue } from "../../types.js";
2
2
  /**
3
3
  * Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes
4
4
  * of input into a value that is either a `null` or a `LexicalValue`.
@@ -1,16 +1,14 @@
1
- const isValueEmpty = value => {
2
- return [undefined, null, "", '""', "null"].includes(value);
3
- };
4
-
5
- /**
6
- * Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes
7
- * of input into a value that is either a `null` or a `LexicalValue`.
8
- */
9
- export function normalizeInputValue(value) {
10
- if (isValueEmpty(value)) {
11
- return null;
12
- }
13
- return value;
1
+ const isValueEmpty = (value)=>[
2
+ void 0,
3
+ null,
4
+ "",
5
+ '""',
6
+ "null"
7
+ ].includes(value);
8
+ function normalizeInputValue(value) {
9
+ if (isValueEmpty(value)) return null;
10
+ return value;
14
11
  }
12
+ export { normalizeInputValue };
15
13
 
16
14
  //# sourceMappingURL=normalizeInputValue.js.map