@webiny/lexical-editor 6.0.0-alpha.5 → 6.0.0-rc.0

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 (172) hide show
  1. package/README.md +6 -12
  2. package/commands/index.d.ts +5 -5
  3. package/commands/index.js +5 -5
  4. package/commands/index.js.map +1 -1
  5. package/components/Editor/EnsureHeadingTagPlugin.js +1 -1
  6. package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -1
  7. package/components/Editor/RichTextEditor.d.ts +11 -6
  8. package/components/Editor/RichTextEditor.js +22 -16
  9. package/components/Editor/RichTextEditor.js.map +1 -1
  10. package/components/Editor/normalizeInputValue.d.ts +1 -1
  11. package/components/Editor/normalizeInputValue.js.map +1 -1
  12. package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +14 -16
  13. package/components/LexicalEditorConfig/LexicalEditorConfig.js +20 -58
  14. package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
  15. package/components/LexicalHtmlRenderer.d.ts +3 -6
  16. package/components/LexicalHtmlRenderer.js +12 -17
  17. package/components/LexicalHtmlRenderer.js.map +1 -1
  18. package/components/Toolbar/StaticToolbar.css +416 -0
  19. package/components/Toolbar/StaticToolbar.d.ts +1 -1
  20. package/components/Toolbar/StaticToolbar.js +2 -2
  21. package/components/Toolbar/StaticToolbar.js.map +1 -1
  22. package/components/ToolbarActions/BoldAction.js +2 -2
  23. package/components/ToolbarActions/BoldAction.js.map +1 -1
  24. package/components/ToolbarActions/BulletListAction.js +5 -6
  25. package/components/ToolbarActions/BulletListAction.js.map +1 -1
  26. package/components/ToolbarActions/CodeHighlightAction.js +2 -2
  27. package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
  28. package/components/ToolbarActions/FontColorAction.js +4 -4
  29. package/components/ToolbarActions/FontColorAction.js.map +1 -1
  30. package/components/ToolbarActions/ImageAction.js +3 -3
  31. package/components/ToolbarActions/ImageAction.js.map +1 -1
  32. package/components/ToolbarActions/ItalicAction.js +2 -2
  33. package/components/ToolbarActions/ItalicAction.js.map +1 -1
  34. package/components/ToolbarActions/LinkAction.js +3 -3
  35. package/components/ToolbarActions/LinkAction.js.map +1 -1
  36. package/components/ToolbarActions/NumberedListAction.js +7 -11
  37. package/components/ToolbarActions/NumberedListAction.js.map +1 -1
  38. package/components/ToolbarActions/QuoteAction.js +6 -6
  39. package/components/ToolbarActions/QuoteAction.js.map +1 -1
  40. package/components/ToolbarActions/TextAlignmentAction.js +4 -4
  41. package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
  42. package/components/ToolbarActions/TypographyAction.js +14 -11
  43. package/components/ToolbarActions/TypographyAction.js.map +1 -1
  44. package/components/ToolbarActions/UnderlineAction.js +1 -1
  45. package/components/ToolbarActions/UnderlineAction.js.map +1 -1
  46. package/context/RichTextEditorContext.d.ts +5 -6
  47. package/context/RichTextEditorContext.js +17 -4
  48. package/context/RichTextEditorContext.js.map +1 -1
  49. package/context/TypographyActionContext.d.ts +1 -1
  50. package/context/TypographyActionContext.js.map +1 -1
  51. package/exports/admin/lexical.d.ts +15 -0
  52. package/exports/admin/lexical.js +23 -0
  53. package/exports/admin/lexical.js.map +1 -0
  54. package/hooks/index.d.ts +7 -8
  55. package/hooks/index.js +7 -8
  56. package/hooks/index.js.map +1 -1
  57. package/hooks/useCurrentElement.js +2 -3
  58. package/hooks/useCurrentElement.js.map +1 -1
  59. package/hooks/useCurrentSelection.js +4 -4
  60. package/hooks/useCurrentSelection.js.map +1 -1
  61. package/hooks/useFontColorPicker.d.ts +1 -1
  62. package/hooks/useFontColorPicker.js +1 -1
  63. package/hooks/useFontColorPicker.js.map +1 -1
  64. package/hooks/useRichTextEditor.d.ts +1 -1
  65. package/hooks/useRichTextEditor.js +1 -1
  66. package/hooks/useRichTextEditor.js.map +1 -1
  67. package/hooks/useTextAlignmentAction.d.ts +1 -1
  68. package/hooks/useTextAlignmentAction.js +1 -1
  69. package/hooks/useTextAlignmentAction.js.map +1 -1
  70. package/hooks/useTypographyAction.d.ts +1 -1
  71. package/hooks/useTypographyAction.js +1 -1
  72. package/hooks/useTypographyAction.js.map +1 -1
  73. package/index.d.ts +33 -37
  74. package/index.js +33 -37
  75. package/index.js.map +1 -1
  76. package/package.json +18 -22
  77. package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +1 -1
  78. package/plugins/BlurEventPlugin/BlurEventPlugin.js +1 -1
  79. package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
  80. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +1 -1
  81. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
  82. package/plugins/CodeHighlightPlugin/index.d.ts +1 -1
  83. package/plugins/CodeHighlightPlugin/index.js +1 -1
  84. package/plugins/CodeHighlightPlugin/index.js.map +1 -1
  85. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +4 -10
  86. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +15 -145
  87. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -1
  88. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +2 -3
  89. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +10 -11
  90. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -1
  91. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +1 -136
  92. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +5 -6
  93. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +3 -7
  94. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
  95. package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -1
  96. package/plugins/FloatingLinkEditorPlugin/index.js +1 -1
  97. package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
  98. package/plugins/FloatingLinkEditorPlugin/types.d.ts +10 -0
  99. package/plugins/FloatingLinkEditorPlugin/types.js +3 -0
  100. package/plugins/FloatingLinkEditorPlugin/types.js.map +1 -0
  101. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +8 -0
  102. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +128 -0
  103. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +1 -0
  104. package/plugins/FontColorPlugin/FontColorPlugin.js +2 -2
  105. package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
  106. package/plugins/FontColorPlugin/applyColorToSelection.js +1 -1
  107. package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -1
  108. package/plugins/ImagesPlugin/ImagesPlugin.d.ts +1 -2
  109. package/plugins/ImagesPlugin/ImagesPlugin.js +5 -8
  110. package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
  111. package/plugins/LinkPlugin/LinkPlugin.js +2 -3
  112. package/plugins/LinkPlugin/LinkPlugin.js.map +1 -1
  113. package/plugins/ListPLugin/ListPlugin.js +45 -3
  114. package/plugins/ListPLugin/ListPlugin.js.map +1 -1
  115. package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +12 -4
  116. package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -1
  117. package/plugins/StateHandlingPlugin.d.ts +1 -1
  118. package/plugins/StateHandlingPlugin.js +6 -6
  119. package/plugins/StateHandlingPlugin.js.map +1 -1
  120. package/plugins/TypographyPlugin/TypographyPlugin.js +2 -2
  121. package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
  122. package/types.d.ts +3 -3
  123. package/types.js +1 -1
  124. package/types.js.map +1 -1
  125. package/ui/ContentEditable.d.ts +0 -1
  126. package/ui/Divider.d.ts +0 -1
  127. package/ui/DropDown.js +4 -3
  128. package/ui/DropDown.js.map +1 -1
  129. package/ui/ImageResizer.d.ts +0 -1
  130. package/ui/ImageResizer.js.map +1 -1
  131. package/ui/LinkPreview.d.ts +0 -1
  132. package/ui/TextInput.d.ts +0 -1
  133. package/utils/files.d.ts +6 -6
  134. package/utils/files.js +3 -13
  135. package/utils/files.js.map +1 -1
  136. package/utils/insertImage.d.ts +1 -1
  137. package/utils/insertImage.js.map +1 -1
  138. package/utils/isValidLexicalData.d.ts +2 -2
  139. package/utils/isValidLexicalData.js.map +1 -1
  140. package/utils/rect.d.ts +1 -1
  141. package/utils/rect.js +1 -1
  142. package/utils/rect.js.map +1 -1
  143. package/utils/sanitizeUrl.js +1 -1
  144. package/utils/sanitizeUrl.js.map +1 -1
  145. package/utils/setFloatingElemPosition.d.ts +1 -1
  146. package/utils/setFloatingElemPosition.js +23 -21
  147. package/utils/setFloatingElemPosition.js.map +1 -1
  148. package/components/Editor/HeadingEditor.d.ts +0 -7
  149. package/components/Editor/HeadingEditor.js +0 -22
  150. package/components/Editor/HeadingEditor.js.map +0 -1
  151. package/components/Editor/ParagraphEditor.d.ts +0 -7
  152. package/components/Editor/ParagraphEditor.js +0 -22
  153. package/components/Editor/ParagraphEditor.js.map +0 -1
  154. package/components/Toolbar/Toolbar.css +0 -643
  155. package/components/Toolbar/Toolbar.d.ts +0 -6
  156. package/components/Toolbar/Toolbar.js +0 -148
  157. package/components/Toolbar/Toolbar.js.map +0 -1
  158. package/components/ToolbarActions/FontSizeAction.d.ts +0 -14
  159. package/components/ToolbarActions/FontSizeAction.js +0 -91
  160. package/components/ToolbarActions/FontSizeAction.js.map +0 -1
  161. package/hooks/useList.d.ts +0 -2
  162. package/hooks/useList.js +0 -50
  163. package/hooks/useList.js.map +0 -1
  164. package/hooks/useQuote.d.ts +0 -2
  165. package/hooks/useQuote.js +0 -17
  166. package/hooks/useQuote.js.map +0 -1
  167. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +0 -8
  168. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +0 -104
  169. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +0 -1
  170. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +0 -9
  171. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +0 -34
  172. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.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._
@@ -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,7 @@
1
- export * from "./typography";
2
- export * from "./image";
3
- export * from "./list";
4
- export * from "./quote";
5
- export * from "./toolbar";
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";
6
6
 
7
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"~/commands/typography\";\nexport * from \"~/commands/image\";\nexport * from \"~/commands/list\";\nexport * from \"~/commands/quote\";\nexport * from \"~/commands/toolbar\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"~/commands/typography.js\";\nexport * from \"~/commands/image.js\";\nexport * from \"~/commands/list.js\";\nexport * from \"~/commands/quote.js\";\nexport * from \"~/commands/toolbar.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  import { useEffect } from "react";
2
2
  import { ParagraphNode, $createHeadingNode } from "@webiny/lexical-nodes";
3
- import { useRichTextEditor } from "../../hooks";
3
+ import { useRichTextEditor } from "../../hooks/index.js";
4
4
 
5
5
  /**
6
6
  * In the "Heading" editor, we only want to support heading tags.
@@ -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,"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/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"],"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,8 +1,11 @@
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;
@@ -11,18 +14,17 @@ export interface RichTextEditorProps {
11
14
  height?: number | string;
12
15
  nodes?: Klass<LexicalNode>[];
13
16
  onBlur?: (editorState: LexicalValue) => void;
14
- onChange?: (json: LexicalValue) => void;
17
+ onChange?: (value: LexicalValue) => void;
15
18
  placeholder?: string;
16
19
  placeholderStyles?: React.CSSProperties;
17
20
  staticToolbar?: React.ReactNode;
18
21
  styles?: React.CSSProperties;
19
22
  tag?: string;
20
23
  theme: EditorTheme;
21
- themeEmotionMap?: ThemeEmotionMap;
22
24
  toolbarActionPlugins?: ToolbarActionPlugin[];
23
- themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;
24
25
  toolbar?: React.ReactNode;
25
26
  value: LexicalValue | null | undefined;
27
+ configRef?: React.MutableRefObject<InitialEditorConfig | undefined>;
26
28
  width?: number | string;
27
29
  }
28
30
  /**
@@ -47,3 +49,6 @@ export declare const RichTextEditor: ((props: RichTextEditorProps) => React.JSX.
47
49
  displayName: string;
48
50
  }>) => (props: unknown) => React.JSX.Element;
49
51
  };
52
+ export declare namespace RichTextEditor {
53
+ type InitialConfig = InitialEditorConfig;
54
+ }
@@ -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,18 +7,17 @@ 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";
11
+ import { RichTextEditorProvider } from "../../context/RichTextEditorContext.js";
12
+ import { BlurEventPlugin } from "../../plugins/BlurEventPlugin/BlurEventPlugin.js";
13
+ import { Placeholder } from "../../ui/Placeholder.js";
14
+ import { SharedHistoryContext, useSharedHistoryContext } from "../../context/SharedHistoryContext.js";
15
+ import { LexicalEditorWithConfig, useLexicalEditorConfig } from "../LexicalEditorConfig/LexicalEditorConfig.js";
16
+ import { StateHandlingPlugin } from "../../plugins/StateHandlingPlugin.js";
19
17
  const BaseRichTextEditor = ({
18
+ onChange,
20
19
  toolbar,
21
20
  staticToolbar,
22
- onChange,
23
21
  nodes,
24
22
  placeholder,
25
23
  children,
@@ -32,8 +30,7 @@ const BaseRichTextEditor = ({
32
30
  placeholderStyles,
33
31
  ...props
34
32
  }) => {
35
- const themeEmotionMap = props.themeEmotionMap ?? toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);
36
- const editorTheme = useRef(createTheme(props.theme));
33
+ const editorTheme = useRef(props.theme);
37
34
  const config = useLexicalEditorConfig();
38
35
  const {
39
36
  historyState
@@ -57,7 +54,7 @@ const BaseRichTextEditor = ({
57
54
  key: plugin.name
58
55
  }, plugin.element));
59
56
  const initialConfig = {
60
- editorState: null,
57
+ editorId: useId(),
61
58
  namespace: "webiny",
62
59
  onError: () => {
63
60
  // Ignore errors. We don't want to break the app because of errors caused by config/value updates.
@@ -65,10 +62,17 @@ const BaseRichTextEditor = ({
65
62
  },
66
63
  nodes: [...allNodes, ...configNodes, ...(nodes || [])],
67
64
  theme: {
68
- ...editorTheme.current,
69
- emotionMap: themeEmotionMap
65
+ ...editorTheme.current.tokens,
66
+ // I'm not aware of a better way to pass custom data to nodes.
67
+ // For now, we're using Lexical's theme to pass colors and typography.
68
+ $colors: editorTheme.current.colors,
69
+ $typography: editorTheme.current.typography,
70
+ $cacheKey: JSON.stringify(editorTheme.current)
70
71
  }
71
72
  };
73
+ if (props.configRef) {
74
+ props.configRef.current = initialConfig;
75
+ }
72
76
  return (
73
77
  /*#__PURE__*/
74
78
  /**
@@ -83,9 +87,11 @@ const BaseRichTextEditor = ({
83
87
  key: initialConfig.nodes.length
84
88
  }, /*#__PURE__*/React.createElement(RichTextEditorProvider, {
85
89
  theme: props.theme,
86
- themeEmotionMap: themeEmotionMap,
87
90
  toolbarActionPlugins: props.toolbarActionPlugins
88
91
  }, staticToolbar ? staticToolbar : null, /*#__PURE__*/React.createElement("div", {
92
+ "data-role": "overlays",
93
+ className: "relative"
94
+ }), /*#__PURE__*/React.createElement("div", {
89
95
  /* This className is necessary for targeting of editor container from CSS files. */
90
96
  className: "editor-shell",
91
97
  ref: scrollRef,
@@ -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":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACzD,SAASC,GAAG,QAAQ,SAAS;AAG7B,SAASC,eAAe,QAAQ,gCAAgC;AAChE,SAASC,eAAe,QAAQ,uCAAuC;AACvE,SAASC,iBAAiB,QAAQ,yCAAyC;AAC3E,SAASC,cAAc,QAAQ,sCAAsC;AACrE,SAASC,oBAAoB,QAAQ,qCAAqC;AAC1E,SAASC,eAAe,QAAQ,2BAA2B;AAC3D,SAASC,aAAa,QAAQ,qCAAqC;AACnE,SAASC,eAAe,QAAQ,uCAAuC;AAEvE,SAASC,WAAW,EAAEC,sBAAsB,QAAQ,uBAAuB;AAC3E,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,sBAAsB;AAC/B,SAASC,eAAe;AAExB,SAASC,WAAW;AACpB,SAASC,oBAAoB,EAAEC,uBAAuB;AACtD,SACIC,uBAAuB,EACvBC,sBAAsB;AAE1B,SAASC,mBAAmB;AAyB5B,MAAMC,kBAAkB,GAAGA,CAAC;EACxBC,OAAO;EACPC,aAAa;EACbC,QAAQ;EACRC,KAAK;EACLC,WAAW;EACXC,QAAQ;EACRC,MAAM;EACNC,KAAK;EACLC,MAAM;EACNC,KAAK;EACLC,MAAM;EACNC,qBAAqB;EACrBC,iBAAiB;EACjB,GAAGC;AACc,CAAC,KAAK;EACvB,MAAMC,eAAe,GACjBD,KAAK,CAACC,eAAe,IACrBzB,sBAAsB,CAACV,GAAG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ACT9B,KAAA,CAAA8C,aAAA,CAACtC,cAAc;MACXsE,eAAe,eACX9E,KAAA,CAAA8C,aAAA;QAAKyB,SAAS,EAAC,iBAAiB;QAACE,KAAK,EAAE;UAAE,GAAGpB;QAAU;MAAE,gBACrDrD,KAAA,CAAA8C,aAAA;QAAKyB,SAAS,EAAC,QAAQ;QAACC,GAAG,EAAErB;MAAM,gBAC/BnD,KAAA,CAAA8C,aAAA,CAAClC,eAAe;QACZ6D,KAAK,EAAE;UAAEM,OAAO,EAAE,CAAC;UAAE,GAAG3C;QAAsB;MAAE,CACnD,CACA,CACJ,CACR;MACDP,WAAW,EAAEgB,eAAgB;MAC7BmC,aAAa,EAAEvE;IAAqB,CACvC,CAAC,EAEDuC,kBAAkB,IAAIvB,OACtB,CACe,CACX,CACC;EAAC;AAE/B,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMwD,cAAc,GAAGvE,eAAe,CAAC,gBAAgB,EAAG4B,KAA0B,IAAK;EAC5F,oBACItC,KAAA,CAAA8C,aAAA,CAACzB,uBAAuB,qBACpBrB,KAAA,CAAA8C,aAAA,CAACtB,kBAAkB,EAAKc,KAAQ,CACX,CAAC;AAElC,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","Fragment","useId","useRef","useState","LexicalComposer","AutoFocusPlugin","ClearEditorPlugin","RichTextPlugin","LexicalErrorBoundary","makeDecoratable","HistoryPlugin","ContentEditable","allNodes","RichTextEditorProvider","BlurEventPlugin","Placeholder","SharedHistoryContext","useSharedHistoryContext","LexicalEditorWithConfig","useLexicalEditorConfig","StateHandlingPlugin","BaseRichTextEditor","onChange","toolbar","staticToolbar","nodes","placeholder","children","onBlur","focus","styles","width","height","contentEditableStyles","placeholderStyles","props","editorTheme","theme","config","historyState","placeholderElem","createElement","scrollRef","floatingAnchorElem","setFloatingAnchorElem","undefined","onRef","_floatingAnchorElem","sizeStyle","configNodes","map","node","configPlugins","plugins","plugin","key","name","element","initialConfig","editorId","namespace","onError","current","tokens","$colors","colors","$typography","typography","$cacheKey","JSON","stringify","configRef","length","toolbarActionPlugins","className","ref","style","overflow","position","value","externalHistoryState","contentEditable","outline","ErrorBoundary","RichTextEditor"],"sources":["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 { Placeholder } from \"~/ui/Placeholder.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 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 height,\n contentEditableStyles,\n placeholderStyles,\n ...props\n}: RichTextEditorProps) => {\n const editorTheme = useRef(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\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 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 ? 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 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\nexport namespace RichTextEditor {\n export type InitialConfig = InitialEditorConfig;\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEhE,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CAAC9B,eAAe;QACZiE,KAAK,EAAE;UAAEM,OAAO,EAAE,CAAC;UAAE,GAAGjD;QAAsB;MAAE,CACnD,CACA,CACJ,CACR;MACDP,WAAW,EAAEc,eAAgB;MAC7B2C,aAAa,EAAE3E;IAAqB,CACvC,CAAC,EAEDmC,kBAAkB,IAAIpB,OACtB,CACe,CACX,CACC;EAAC;AAE/B,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAM6D,cAAc,GAAG3E,eAAe,CAAC,gBAAgB,EAAG0B,KAA0B,IAAK;EAC5F,oBACIpC,KAAA,CAAA0C,aAAA,CAACvB,uBAAuB,qBACpBnB,KAAA,CAAA0C,aAAA,CAACpB,kBAAkB,EAAKc,KAAQ,CACX,CAAC;AAElC,CAAC,CAAC","ignoreList":[]}
@@ -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 +1 @@
1
- {"version":3,"names":["isValueEmpty","value","undefined","includes","normalizeInputValue"],"sources":["normalizeInputValue.ts"],"sourcesContent":["import type { LexicalValue, NormalizedInputValue } from \"~/types\";\n\nconst isValueEmpty = (value: any) => {\n return [undefined, null, \"\", '\"\"', \"null\"].includes(value);\n};\n\n/**\n * Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes\n * of input into a value that is either a `null` or a `LexicalValue`.\n */\nexport function normalizeInputValue(value: LexicalValue | null | undefined) {\n if (isValueEmpty(value)) {\n return null;\n }\n\n return value as NormalizedInputValue;\n}\n"],"mappings":"AAEA,MAAMA,YAAY,GAAIC,KAAU,IAAK;EACjC,OAAO,CAACC,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAACC,QAAQ,CAACF,KAAK,CAAC;AAC9D,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASG,mBAAmBA,CAACH,KAAsC,EAAE;EACxE,IAAID,YAAY,CAACC,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EAEA,OAAOA,KAAK;AAChB","ignoreList":[]}
1
+ {"version":3,"names":["isValueEmpty","value","undefined","includes","normalizeInputValue"],"sources":["normalizeInputValue.ts"],"sourcesContent":["import type { LexicalValue, NormalizedInputValue } from \"~/types.js\";\n\nconst isValueEmpty = (value: any) => {\n return [undefined, null, \"\", '\"\"', \"null\"].includes(value);\n};\n\n/**\n * Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes\n * of input into a value that is either a `null` or a `LexicalValue`.\n */\nexport function normalizeInputValue(value: LexicalValue | null | undefined) {\n if (isValueEmpty(value)) {\n return null;\n }\n\n return value as NormalizedInputValue;\n}\n"],"mappings":"AAEA,MAAMA,YAAY,GAAIC,KAAU,IAAK;EACjC,OAAO,CAACC,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAACC,QAAQ,CAACF,KAAK,CAAC;AAC9D,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASG,mBAAmBA,CAACH,KAAsC,EAAE;EACxE,IAAID,YAAY,CAACC,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EAEA,OAAOA,KAAK;AAChB","ignoreList":[]}
@@ -1,20 +1,18 @@
1
- import React from "react";
2
- import type { ToolbarElementConfig } from "./components/ToolbarElement";
3
- import type { PluginConfig } from "./components/Plugin";
4
- import type { NodeConfig } from "./components/Node";
5
- export declare const LexicalEditorConfig: {
6
- ({ children }: {
7
- children: React.ReactNode;
8
- }): React.JSX.Element;
9
- ToolbarElement: ({ name, element, after, before, remove }: import("./components/ToolbarElement").ToolbarElementProps) => React.JSX.Element;
10
- Plugin: ({ name, element, after, before, remove }: import("./components/Plugin").PluginProps) => React.JSX.Element;
11
- Node: ({ name, node, after, before, remove }: import("./components/Node").NodeProps) => React.JSX.Element;
1
+ import type { ToolbarElementConfig } from "./components/ToolbarElement.js";
2
+ import type { PluginConfig } from "./components/Plugin.js";
3
+ import type { NodeConfig } from "./components/Node.js";
4
+ export type { ToolbarElementConfig } from "./components/ToolbarElement.js";
5
+ export type { PluginConfig } from "./components/Plugin.js";
6
+ export type { NodeConfig } from "./components/Node.js";
7
+ export declare const LexicalEditorConfig: (({ priority, children }: import("@webiny/react-properties").ConfigProps) => React.JSX.Element) & {
8
+ ToolbarElement: ({ name, element, after, before, remove }: import("./components/ToolbarElement.js").ToolbarElementProps) => import("react").JSX.Element;
9
+ Plugin: ({ name, element, after, before, remove }: import("./components/Plugin.js").PluginProps) => import("react").JSX.Element;
10
+ Node: ({ name, node, after, before, remove }: import("./components/Node.js").NodeProps) => import("react").JSX.Element;
12
11
  };
13
- export declare const LexicalEditorWithConfig: ({ children }: {
14
- children: React.ReactNode;
15
- }) => React.JSX.Element;
16
- export declare function useLexicalEditorConfig(): {
12
+ export declare const LexicalEditorWithConfig: ({ onProperties, children }: import("@webiny/react-properties").WithConfigProps) => React.JSX.Element;
13
+ interface LexicalEditorConfigData {
17
14
  toolbarElements: ToolbarElementConfig[];
18
15
  plugins: PluginConfig[];
19
16
  nodes: NodeConfig[];
20
- };
17
+ }
18
+ export declare function useLexicalEditorConfig(): LexicalEditorConfigData;
@@ -1,63 +1,25 @@
1
- import React, { useContext, useMemo, useState } from "react";
2
- import { makeDecoratable, Compose } from "@webiny/react-composition";
3
- import { Properties, toObject } from "@webiny/react-properties";
4
- import { ToolbarElement } from "./components/ToolbarElement";
5
- import { Plugin } from "./components/Plugin";
6
- import { Node } from "./components/Node";
7
- const LexicalEditorConfigApply = makeDecoratable("LexicalEditorConfigApply", ({
8
- children
9
- }) => {
10
- return /*#__PURE__*/React.createElement(React.Fragment, null, children);
1
+ import { useMemo } from "react";
2
+ import { createConfigurableComponent } from "@webiny/react-properties";
3
+ import { ToolbarElement } from "./components/ToolbarElement.js";
4
+ import { Plugin } from "./components/Plugin.js";
5
+ import { Node } from "./components/Node.js";
6
+ const base = createConfigurableComponent("LexicalEditor");
7
+ export const LexicalEditorConfig = Object.assign(base.Config, {
8
+ ToolbarElement,
9
+ Plugin,
10
+ Node
11
11
  });
12
- const createHOC = newChildren => BaseComponent => {
13
- return function ConfigHOC({
14
- children
15
- }) {
16
- return /*#__PURE__*/React.createElement(BaseComponent, null, newChildren, children);
17
- };
18
- };
19
- export const LexicalEditorConfig = ({
20
- children
21
- }) => {
22
- return /*#__PURE__*/React.createElement(Compose, {
23
- component: LexicalEditorConfigApply,
24
- with: createHOC(children)
25
- });
26
- };
27
- LexicalEditorConfig.ToolbarElement = ToolbarElement;
28
- LexicalEditorConfig.Plugin = Plugin;
29
- LexicalEditorConfig.Node = Node;
30
- const ViewContext = /*#__PURE__*/React.createContext({
31
- properties: []
32
- });
33
- export const LexicalEditorWithConfig = ({
34
- children
35
- }) => {
36
- const [properties, setProperties] = useState([]);
37
- const context = {
38
- properties
39
- };
40
- const stateUpdater = properties => {
41
- setProperties(properties);
42
- };
43
- return /*#__PURE__*/React.createElement(ViewContext.Provider, {
44
- value: context
45
- }, /*#__PURE__*/React.createElement(Properties, {
46
- onChange: stateUpdater
47
- }, /*#__PURE__*/React.createElement(LexicalEditorConfigApply, null), children));
48
- };
12
+ export const LexicalEditorWithConfig = base.WithConfig;
49
13
  export function useLexicalEditorConfig() {
50
- const {
51
- properties
52
- } = useContext(ViewContext);
53
- const config = useMemo(() => {
54
- return toObject(properties);
55
- }, [properties]);
56
- return {
57
- toolbarElements: config.toolbarElements || [],
58
- plugins: config.plugins || [],
59
- nodes: config.nodes || []
60
- };
14
+ const config = base.useConfig();
15
+ const toolbarElements = config.toolbarElements || [];
16
+ const plugins = config.plugins || [];
17
+ const nodes = config.nodes || [];
18
+ return useMemo(() => ({
19
+ toolbarElements: [...toolbarElements],
20
+ plugins: [...plugins],
21
+ nodes: [...nodes]
22
+ }), [config]);
61
23
  }
62
24
 
63
25
  //# sourceMappingURL=LexicalEditorConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","useContext","useMemo","useState","makeDecoratable","Compose","Properties","toObject","ToolbarElement","Plugin","Node","LexicalEditorConfigApply","children","createElement","Fragment","createHOC","newChildren","BaseComponent","ConfigHOC","LexicalEditorConfig","component","with","ViewContext","createContext","properties","LexicalEditorWithConfig","setProperties","context","stateUpdater","Provider","value","onChange","useLexicalEditorConfig","config","toolbarElements","plugins","nodes"],"sources":["LexicalEditorConfig.tsx"],"sourcesContent":["import React, { useContext, useMemo, useState } from \"react\";\nimport type { Decorator, GenericComponent } from \"@webiny/react-composition\";\nimport { makeDecoratable, Compose } from \"@webiny/react-composition\";\nimport type { Property } from \"@webiny/react-properties\";\nimport { Properties, toObject } from \"@webiny/react-properties\";\nimport type { ToolbarElementConfig } from \"./components/ToolbarElement\";\nimport { ToolbarElement } from \"./components/ToolbarElement\";\nimport type { PluginConfig } from \"./components/Plugin\";\nimport { Plugin } from \"./components/Plugin\";\nimport type { NodeConfig } from \"./components/Node\";\nimport { Node } from \"./components/Node\";\n\nconst LexicalEditorConfigApply = makeDecoratable(\"LexicalEditorConfigApply\", ({ children }) => {\n return <>{children}</>;\n});\n\nconst createHOC =\n (newChildren: React.ReactNode): Decorator<GenericComponent> =>\n BaseComponent => {\n return function ConfigHOC({ children }) {\n return (\n <BaseComponent>\n {newChildren}\n {children}\n </BaseComponent>\n );\n };\n };\n\nexport const LexicalEditorConfig = ({ children }: { children: React.ReactNode }) => {\n return <Compose component={LexicalEditorConfigApply} with={createHOC(children)} />;\n};\n\nLexicalEditorConfig.ToolbarElement = ToolbarElement;\nLexicalEditorConfig.Plugin = Plugin;\nLexicalEditorConfig.Node = Node;\n\ninterface ViewContext {\n properties: Property[];\n}\n\nconst ViewContext = React.createContext<ViewContext>({ properties: [] });\n\nexport const LexicalEditorWithConfig = ({ children }: { children: React.ReactNode }) => {\n const [properties, setProperties] = useState<Property[]>([]);\n const context = { properties };\n\n const stateUpdater = (properties: Property[]) => {\n setProperties(properties);\n };\n\n return (\n <ViewContext.Provider value={context}>\n <Properties onChange={stateUpdater}>\n <LexicalEditorConfigApply />\n {children}\n </Properties>\n </ViewContext.Provider>\n );\n};\n\ninterface LexicalEditorConfigData {\n toolbarElements: ToolbarElementConfig[];\n plugins: PluginConfig[];\n nodes: NodeConfig[];\n}\n\nexport function useLexicalEditorConfig() {\n const { properties } = useContext(ViewContext);\n\n const config = useMemo(() => {\n return toObject<LexicalEditorConfigData>(properties);\n }, [properties]);\n\n return {\n toolbarElements: config.toolbarElements || [],\n plugins: config.plugins || [],\n nodes: config.nodes || []\n };\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAE5D,SAASC,eAAe,EAAEC,OAAO,QAAQ,2BAA2B;AAEpE,SAASC,UAAU,EAAEC,QAAQ,QAAQ,0BAA0B;AAE/D,SAASC,cAAc;AAEvB,SAASC,MAAM;AAEf,SAASC,IAAI;AAEb,MAAMC,wBAAwB,GAAGP,eAAe,CAAC,0BAA0B,EAAE,CAAC;EAAEQ;AAAS,CAAC,KAAK;EAC3F,oBAAOZ,KAAA,CAAAa,aAAA,CAAAb,KAAA,CAAAc,QAAA,QAAGF,QAAW,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAMG,SAAS,GACVC,WAA4B,IAC7BC,aAAa,IAAI;EACb,OAAO,SAASC,SAASA,CAAC;IAAEN;EAAS,CAAC,EAAE;IACpC,oBACIZ,KAAA,CAAAa,aAAA,CAACI,aAAa,QACTD,WAAW,EACXJ,QACU,CAAC;EAExB,CAAC;AACL,CAAC;AAEL,OAAO,MAAMO,mBAAmB,GAAGA,CAAC;EAAEP;AAAwC,CAAC,KAAK;EAChF,oBAAOZ,KAAA,CAAAa,aAAA,CAACR,OAAO;IAACe,SAAS,EAAET,wBAAyB;IAACU,IAAI,EAAEN,SAAS,CAACH,QAAQ;EAAE,CAAE,CAAC;AACtF,CAAC;AAEDO,mBAAmB,CAACX,cAAc,GAAGA,cAAc;AACnDW,mBAAmB,CAACV,MAAM,GAAGA,MAAM;AACnCU,mBAAmB,CAACT,IAAI,GAAGA,IAAI;AAM/B,MAAMY,WAAW,gBAAGtB,KAAK,CAACuB,aAAa,CAAc;EAAEC,UAAU,EAAE;AAAG,CAAC,CAAC;AAExE,OAAO,MAAMC,uBAAuB,GAAGA,CAAC;EAAEb;AAAwC,CAAC,KAAK;EACpF,MAAM,CAACY,UAAU,EAAEE,aAAa,CAAC,GAAGvB,QAAQ,CAAa,EAAE,CAAC;EAC5D,MAAMwB,OAAO,GAAG;IAAEH;EAAW,CAAC;EAE9B,MAAMI,YAAY,GAAIJ,UAAsB,IAAK;IAC7CE,aAAa,CAACF,UAAU,CAAC;EAC7B,CAAC;EAED,oBACIxB,KAAA,CAAAa,aAAA,CAACS,WAAW,CAACO,QAAQ;IAACC,KAAK,EAAEH;EAAQ,gBACjC3B,KAAA,CAAAa,aAAA,CAACP,UAAU;IAACyB,QAAQ,EAAEH;EAAa,gBAC/B5B,KAAA,CAAAa,aAAA,CAACF,wBAAwB,MAAE,CAAC,EAC3BC,QACO,CACM,CAAC;AAE/B,CAAC;AAQD,OAAO,SAASoB,sBAAsBA,CAAA,EAAG;EACrC,MAAM;IAAER;EAAW,CAAC,GAAGvB,UAAU,CAACqB,WAAW,CAAC;EAE9C,MAAMW,MAAM,GAAG/B,OAAO,CAAC,MAAM;IACzB,OAAOK,QAAQ,CAA0BiB,UAAU,CAAC;EACxD,CAAC,EAAE,CAACA,UAAU,CAAC,CAAC;EAEhB,OAAO;IACHU,eAAe,EAAED,MAAM,CAACC,eAAe,IAAI,EAAE;IAC7CC,OAAO,EAAEF,MAAM,CAACE,OAAO,IAAI,EAAE;IAC7BC,KAAK,EAAEH,MAAM,CAACG,KAAK,IAAI;EAC3B,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"names":["useMemo","createConfigurableComponent","ToolbarElement","Plugin","Node","base","LexicalEditorConfig","Object","assign","Config","LexicalEditorWithConfig","WithConfig","useLexicalEditorConfig","config","useConfig","toolbarElements","plugins","nodes"],"sources":["LexicalEditorConfig.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport { createConfigurableComponent } from \"@webiny/react-properties\";\nimport type { ToolbarElementConfig } from \"./components/ToolbarElement.js\";\nimport { ToolbarElement } from \"./components/ToolbarElement.js\";\nimport type { PluginConfig } from \"./components/Plugin.js\";\nimport { Plugin } from \"./components/Plugin.js\";\nimport type { NodeConfig } from \"./components/Node.js\";\nimport { Node } from \"./components/Node.js\";\n\nexport type { ToolbarElementConfig } from \"./components/ToolbarElement.js\";\nexport type { PluginConfig } from \"./components/Plugin.js\";\nexport type { NodeConfig } from \"./components/Node.js\";\n\nconst base = createConfigurableComponent<LexicalEditorConfigData>(\"LexicalEditor\");\n\nexport const LexicalEditorConfig = Object.assign(base.Config, {\n ToolbarElement,\n Plugin,\n Node\n});\n\nexport const LexicalEditorWithConfig = base.WithConfig;\n\ninterface LexicalEditorConfigData {\n toolbarElements: ToolbarElementConfig[];\n plugins: PluginConfig[];\n nodes: NodeConfig[];\n}\n\nexport function useLexicalEditorConfig(): LexicalEditorConfigData {\n const config = base.useConfig();\n const toolbarElements = config.toolbarElements || [];\n const plugins = config.plugins || [];\n const nodes = config.nodes || [];\n\n return useMemo(\n () => ({\n toolbarElements: [...toolbarElements],\n plugins: [...plugins],\n nodes: [...nodes]\n }),\n [config]\n );\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,2BAA2B,QAAQ,0BAA0B;AAEtE,SAASC,cAAc;AAEvB,SAASC,MAAM;AAEf,SAASC,IAAI;AAMb,MAAMC,IAAI,GAAGJ,2BAA2B,CAA0B,eAAe,CAAC;AAElF,OAAO,MAAMK,mBAAmB,GAAGC,MAAM,CAACC,MAAM,CAACH,IAAI,CAACI,MAAM,EAAE;EAC1DP,cAAc;EACdC,MAAM;EACNC;AACJ,CAAC,CAAC;AAEF,OAAO,MAAMM,uBAAuB,GAAGL,IAAI,CAACM,UAAU;AAQtD,OAAO,SAASC,sBAAsBA,CAAA,EAA4B;EAC9D,MAAMC,MAAM,GAAGR,IAAI,CAACS,SAAS,CAAC,CAAC;EAC/B,MAAMC,eAAe,GAAGF,MAAM,CAACE,eAAe,IAAI,EAAE;EACpD,MAAMC,OAAO,GAAGH,MAAM,CAACG,OAAO,IAAI,EAAE;EACpC,MAAMC,KAAK,GAAGJ,MAAM,CAACI,KAAK,IAAI,EAAE;EAEhC,OAAOjB,OAAO,CACV,OAAO;IACHe,eAAe,EAAE,CAAC,GAAGA,eAAe,CAAC;IACrCC,OAAO,EAAE,CAAC,GAAGA,OAAO,CAAC;IACrBC,KAAK,EAAE,CAAC,GAAGA,KAAK;EACpB,CAAC,CAAC,EACF,CAACJ,MAAM,CACX,CAAC;AACL","ignoreList":[]}
@@ -1,14 +1,11 @@
1
1
  import React from "react";
2
2
  import type { Klass, LexicalNode } from "lexical";
3
- import type { CSSObject } from "@emotion/react";
4
- import type { EditorTheme, ThemeEmotionMap } from "@webiny/lexical-theme";
5
- import type { LexicalValue } from "../types";
3
+ import type { EditorTheme } from "@webiny/lexical-theme";
4
+ import type { LexicalValue } from "../types.js";
6
5
  interface LexicalHtmlRendererProps {
7
6
  nodes?: Klass<LexicalNode>[];
8
7
  value: LexicalValue | null;
9
- theme: Partial<EditorTheme>;
10
- themeEmotionMap?: ThemeEmotionMap;
11
- themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;
8
+ theme: EditorTheme;
12
9
  }
13
10
  export declare const LexicalHtmlRenderer: ({ nodes, value, ...props }: LexicalHtmlRendererProps) => React.JSX.Element;
14
11
  export {};
@@ -1,25 +1,18 @@
1
1
  import React, { useRef } from "react";
2
- import { css } from "emotion";
3
2
  import { LexicalComposer } from "@lexical/react/LexicalComposer";
4
3
  import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
5
4
  import { ContentEditable } from "@lexical/react/LexicalContentEditable";
6
- import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
5
+ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary.js";
7
6
  import { allNodes } from "@webiny/lexical-nodes";
8
- import { createTheme, toTypographyEmotionMap } from "@webiny/lexical-theme";
9
- import { RichTextEditorProvider } from "../context/RichTextEditorContext";
10
- import { StateHandlingPlugin } from "../plugins/StateHandlingPlugin";
7
+ import { RichTextEditorProvider } from "../context/RichTextEditorContext.js";
8
+ import { StateHandlingPlugin } from "../plugins/StateHandlingPlugin.js";
11
9
  export const LexicalHtmlRenderer = ({
12
10
  nodes,
13
11
  value,
14
12
  ...props
15
13
  }) => {
16
- const theme = {
17
- styles: {},
18
- emotionMap: {},
19
- ...props.theme
20
- };
21
- const themeEmotionMap = props?.themeEmotionMap ?? toTypographyEmotionMap(css, theme, props.themeStylesTransformer);
22
- const editorTheme = useRef(createTheme(theme));
14
+ const theme = props.theme;
15
+ const editorTheme = useRef(theme);
23
16
  const initialConfig = {
24
17
  editorState: null,
25
18
  namespace: "webiny",
@@ -30,17 +23,19 @@ export const LexicalHtmlRenderer = ({
30
23
  editable: false,
31
24
  nodes: [...allNodes, ...(nodes || [])],
32
25
  theme: {
33
- ...editorTheme.current,
34
- emotionMap: themeEmotionMap,
35
- styles: theme.styles
26
+ ...editorTheme.current.tokens,
27
+ // I'm not aware of a better way to pass custom data to nodes.
28
+ // For now, we're using Lexical's theme to pass colors and typography.
29
+ $colors: editorTheme.current.colors,
30
+ $typography: editorTheme.current.typography,
31
+ $cacheKey: JSON.stringify(editorTheme.current)
36
32
  }
37
33
  };
38
34
  return /*#__PURE__*/React.createElement(LexicalComposer, {
39
35
  initialConfig: initialConfig,
40
36
  key: initialConfig.nodes.length
41
37
  }, /*#__PURE__*/React.createElement(RichTextEditorProvider, {
42
- theme: theme,
43
- themeEmotionMap: themeEmotionMap
38
+ theme: theme
44
39
  }, /*#__PURE__*/React.createElement(RichTextPlugin, {
45
40
  contentEditable: /*#__PURE__*/React.createElement("div", {
46
41
  className: "editor"
@@ -1 +1 @@
1
- {"version":3,"names":["React","useRef","css","LexicalComposer","RichTextPlugin","ContentEditable","LexicalErrorBoundary","allNodes","createTheme","toTypographyEmotionMap","RichTextEditorProvider","StateHandlingPlugin","LexicalHtmlRenderer","nodes","value","props","theme","styles","emotionMap","themeEmotionMap","themeStylesTransformer","editorTheme","initialConfig","editorState","namespace","onError","editable","current","createElement","key","length","contentEditable","className","ErrorBoundary","placeholder"],"sources":["LexicalHtmlRenderer.tsx"],"sourcesContent":["import React, { useRef } from \"react\";\nimport type { Klass, LexicalNode } from \"lexical\";\nimport { css } from \"emotion\";\nimport type { CSSObject } from \"@emotion/react\";\nimport { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport LexicalErrorBoundary from \"@lexical/react/LexicalErrorBoundary\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport type { EditorTheme, ThemeEmotionMap } from \"@webiny/lexical-theme\";\nimport { createTheme, toTypographyEmotionMap } from \"@webiny/lexical-theme\";\nimport type { LexicalValue } from \"~/types\";\nimport { RichTextEditorProvider } from \"~/context/RichTextEditorContext\";\nimport { StateHandlingPlugin } from \"~/plugins/StateHandlingPlugin\";\n\ninterface LexicalHtmlRendererProps {\n nodes?: Klass<LexicalNode>[];\n value: LexicalValue | null;\n theme: Partial<EditorTheme>;\n themeEmotionMap?: ThemeEmotionMap;\n themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;\n}\n\nexport const LexicalHtmlRenderer = ({ nodes, value, ...props }: LexicalHtmlRendererProps) => {\n const theme: EditorTheme = { styles: {}, emotionMap: {}, ...props.theme };\n const themeEmotionMap =\n props?.themeEmotionMap ?? toTypographyEmotionMap(css, theme, props.themeStylesTransformer);\n const editorTheme = useRef(createTheme(theme));\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 editable: false,\n nodes: [...allNodes, ...(nodes || [])],\n theme: { ...editorTheme.current, emotionMap: themeEmotionMap, styles: theme.styles }\n };\n\n return (\n <LexicalComposer initialConfig={initialConfig} key={initialConfig.nodes.length}>\n <RichTextEditorProvider theme={theme} themeEmotionMap={themeEmotionMap}>\n <RichTextPlugin\n contentEditable={\n <div className=\"editor\">\n <ContentEditable />\n </div>\n }\n ErrorBoundary={LexicalErrorBoundary}\n placeholder={null}\n />\n <StateHandlingPlugin value={value} />\n </RichTextEditorProvider>\n </LexicalComposer>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,MAAM,QAAQ,OAAO;AAErC,SAASC,GAAG,QAAQ,SAAS;AAE7B,SAASC,eAAe,QAAQ,gCAAgC;AAChE,SAASC,cAAc,QAAQ,sCAAsC;AACrE,SAASC,eAAe,QAAQ,uCAAuC;AACvE,OAAOC,oBAAoB,MAAM,qCAAqC;AACtE,SAASC,QAAQ,QAAQ,uBAAuB;AAEhD,SAASC,WAAW,EAAEC,sBAAsB,QAAQ,uBAAuB;AAE3E,SAASC,sBAAsB;AAC/B,SAASC,mBAAmB;AAU5B,OAAO,MAAMC,mBAAmB,GAAGA,CAAC;EAAEC,KAAK;EAAEC,KAAK;EAAE,GAAGC;AAAgC,CAAC,KAAK;EACzF,MAAMC,KAAkB,GAAG;IAAEC,MAAM,EAAE,CAAC,CAAC;IAAEC,UAAU,EAAE,CAAC,CAAC;IAAE,GAAGH,KAAK,CAACC;EAAM,CAAC;EACzE,MAAMG,eAAe,GACjBJ,KAAK,EAAEI,eAAe,IAAIV,sBAAsB,CAACP,GAAG,EAAEc,KAAK,EAAED,KAAK,CAACK,sBAAsB,CAAC;EAC9F,MAAMC,WAAW,GAAGpB,MAAM,CAACO,WAAW,CAACQ,KAAK,CAAC,CAAC;EAE9C,MAAMM,aAAa,GAAG;IAClBC,WAAW,EAAE,IAAI;IACjBC,SAAS,EAAE,QAAQ;IACnBC,OAAO,EAAEA,CAAA,KAAM;MACX;MACA;IAAA,CACH;IACDC,QAAQ,EAAE,KAAK;IACfb,KAAK,EAAE,CAAC,GAAGN,QAAQ,EAAE,IAAIM,KAAK,IAAI,EAAE,CAAC,CAAC;IACtCG,KAAK,EAAE;MAAE,GAAGK,WAAW,CAACM,OAAO;MAAET,UAAU,EAAEC,eAAe;MAAEF,MAAM,EAAED,KAAK,CAACC;IAAO;EACvF,CAAC;EAED,oBACIjB,KAAA,CAAA4B,aAAA,CAACzB,eAAe;IAACmB,aAAa,EAAEA,aAAc;IAACO,GAAG,EAAEP,aAAa,CAACT,KAAK,CAACiB;EAAO,gBAC3E9B,KAAA,CAAA4B,aAAA,CAAClB,sBAAsB;IAACM,KAAK,EAAEA,KAAM;IAACG,eAAe,EAAEA;EAAgB,gBACnEnB,KAAA,CAAA4B,aAAA,CAACxB,cAAc;IACX2B,eAAe,eACX/B,KAAA,CAAA4B,aAAA;MAAKI,SAAS,EAAC;IAAQ,gBACnBhC,KAAA,CAAA4B,aAAA,CAACvB,eAAe,MAAE,CACjB,CACR;IACD4B,aAAa,EAAE3B,oBAAqB;IACpC4B,WAAW,EAAE;EAAK,CACrB,CAAC,eACFlC,KAAA,CAAA4B,aAAA,CAACjB,mBAAmB;IAACG,KAAK,EAAEA;EAAM,CAAE,CAChB,CACX,CAAC;AAE1B,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useRef","LexicalComposer","RichTextPlugin","ContentEditable","LexicalErrorBoundary","allNodes","RichTextEditorProvider","StateHandlingPlugin","LexicalHtmlRenderer","nodes","value","props","theme","editorTheme","initialConfig","editorState","namespace","onError","editable","current","tokens","$colors","colors","$typography","typography","$cacheKey","JSON","stringify","createElement","key","length","contentEditable","className","ErrorBoundary","placeholder"],"sources":["LexicalHtmlRenderer.tsx"],"sourcesContent":["import React, { useRef } from \"react\";\nimport type { Klass, LexicalNode } from \"lexical\";\nimport { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport { LexicalErrorBoundary } from \"@lexical/react/LexicalErrorBoundary.js\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport type { EditorTheme } from \"@webiny/lexical-theme\";\nimport type { LexicalValue } from \"~/types.js\";\nimport { RichTextEditorProvider } from \"~/context/RichTextEditorContext.js\";\nimport { StateHandlingPlugin } from \"~/plugins/StateHandlingPlugin.js\";\n\ninterface LexicalHtmlRendererProps {\n nodes?: Klass<LexicalNode>[];\n value: LexicalValue | null;\n theme: EditorTheme;\n}\n\nexport const LexicalHtmlRenderer = ({ nodes, value, ...props }: LexicalHtmlRendererProps) => {\n const theme: EditorTheme = props.theme;\n const editorTheme = useRef(theme);\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 editable: false,\n nodes: [...allNodes, ...(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 return (\n <LexicalComposer initialConfig={initialConfig} key={initialConfig.nodes.length}>\n <RichTextEditorProvider theme={theme}>\n <RichTextPlugin\n contentEditable={\n <div className=\"editor\">\n <ContentEditable />\n </div>\n }\n ErrorBoundary={LexicalErrorBoundary}\n placeholder={null}\n />\n <StateHandlingPlugin value={value} />\n </RichTextEditorProvider>\n </LexicalComposer>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,MAAM,QAAQ,OAAO;AAErC,SAASC,eAAe,QAAQ,gCAAgC;AAChE,SAASC,cAAc,QAAQ,sCAAsC;AACrE,SAASC,eAA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