@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.
- package/README.md +6 -12
- package/commands/index.d.ts +5 -5
- package/commands/index.js +5 -5
- package/commands/index.js.map +1 -1
- package/components/Editor/EnsureHeadingTagPlugin.js +1 -1
- package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -1
- package/components/Editor/RichTextEditor.d.ts +11 -6
- package/components/Editor/RichTextEditor.js +22 -16
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/Editor/normalizeInputValue.d.ts +1 -1
- package/components/Editor/normalizeInputValue.js.map +1 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +14 -16
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +20 -58
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
- package/components/LexicalHtmlRenderer.d.ts +3 -6
- package/components/LexicalHtmlRenderer.js +12 -17
- package/components/LexicalHtmlRenderer.js.map +1 -1
- package/components/Toolbar/StaticToolbar.css +416 -0
- package/components/Toolbar/StaticToolbar.d.ts +1 -1
- package/components/Toolbar/StaticToolbar.js +2 -2
- package/components/Toolbar/StaticToolbar.js.map +1 -1
- package/components/ToolbarActions/BoldAction.js +2 -2
- package/components/ToolbarActions/BoldAction.js.map +1 -1
- package/components/ToolbarActions/BulletListAction.js +5 -6
- package/components/ToolbarActions/BulletListAction.js.map +1 -1
- package/components/ToolbarActions/CodeHighlightAction.js +2 -2
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
- package/components/ToolbarActions/FontColorAction.js +4 -4
- package/components/ToolbarActions/FontColorAction.js.map +1 -1
- package/components/ToolbarActions/ImageAction.js +3 -3
- package/components/ToolbarActions/ImageAction.js.map +1 -1
- package/components/ToolbarActions/ItalicAction.js +2 -2
- package/components/ToolbarActions/ItalicAction.js.map +1 -1
- package/components/ToolbarActions/LinkAction.js +3 -3
- package/components/ToolbarActions/LinkAction.js.map +1 -1
- package/components/ToolbarActions/NumberedListAction.js +7 -11
- package/components/ToolbarActions/NumberedListAction.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +6 -6
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TextAlignmentAction.js +4 -4
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.js +14 -11
- package/components/ToolbarActions/TypographyAction.js.map +1 -1
- package/components/ToolbarActions/UnderlineAction.js +1 -1
- package/components/ToolbarActions/UnderlineAction.js.map +1 -1
- package/context/RichTextEditorContext.d.ts +5 -6
- package/context/RichTextEditorContext.js +17 -4
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/TypographyActionContext.d.ts +1 -1
- package/context/TypographyActionContext.js.map +1 -1
- package/exports/admin/lexical.d.ts +15 -0
- package/exports/admin/lexical.js +23 -0
- package/exports/admin/lexical.js.map +1 -0
- package/hooks/index.d.ts +7 -8
- package/hooks/index.js +7 -8
- package/hooks/index.js.map +1 -1
- package/hooks/useCurrentElement.js +2 -3
- package/hooks/useCurrentElement.js.map +1 -1
- package/hooks/useCurrentSelection.js +4 -4
- package/hooks/useCurrentSelection.js.map +1 -1
- package/hooks/useFontColorPicker.d.ts +1 -1
- package/hooks/useFontColorPicker.js +1 -1
- package/hooks/useFontColorPicker.js.map +1 -1
- package/hooks/useRichTextEditor.d.ts +1 -1
- package/hooks/useRichTextEditor.js +1 -1
- package/hooks/useRichTextEditor.js.map +1 -1
- package/hooks/useTextAlignmentAction.d.ts +1 -1
- package/hooks/useTextAlignmentAction.js +1 -1
- package/hooks/useTextAlignmentAction.js.map +1 -1
- package/hooks/useTypographyAction.d.ts +1 -1
- package/hooks/useTypographyAction.js +1 -1
- package/hooks/useTypographyAction.js.map +1 -1
- package/index.d.ts +33 -37
- package/index.js +33 -37
- package/index.js.map +1 -1
- package/package.json +18 -22
- package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +1 -1
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +1 -1
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +1 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/index.d.ts +1 -1
- package/plugins/CodeHighlightPlugin/index.js +1 -1
- package/plugins/CodeHighlightPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +4 -10
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +15 -145
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +2 -3
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +10 -11
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +1 -136
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +5 -6
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +3 -7
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/types.d.ts +10 -0
- package/plugins/FloatingLinkEditorPlugin/types.js +3 -0
- package/plugins/FloatingLinkEditorPlugin/types.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +8 -0
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +128 -0
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +1 -0
- package/plugins/FontColorPlugin/FontColorPlugin.js +2 -2
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/FontColorPlugin/applyColorToSelection.js +1 -1
- package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -1
- package/plugins/ImagesPlugin/ImagesPlugin.d.ts +1 -2
- package/plugins/ImagesPlugin/ImagesPlugin.js +5 -8
- package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
- package/plugins/LinkPlugin/LinkPlugin.js +2 -3
- package/plugins/LinkPlugin/LinkPlugin.js.map +1 -1
- package/plugins/ListPLugin/ListPlugin.js +45 -3
- package/plugins/ListPLugin/ListPlugin.js.map +1 -1
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +12 -4
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -1
- package/plugins/StateHandlingPlugin.d.ts +1 -1
- package/plugins/StateHandlingPlugin.js +6 -6
- package/plugins/StateHandlingPlugin.js.map +1 -1
- package/plugins/TypographyPlugin/TypographyPlugin.js +2 -2
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
- package/types.d.ts +3 -3
- package/types.js +1 -1
- package/types.js.map +1 -1
- package/ui/ContentEditable.d.ts +0 -1
- package/ui/Divider.d.ts +0 -1
- package/ui/DropDown.js +4 -3
- package/ui/DropDown.js.map +1 -1
- package/ui/ImageResizer.d.ts +0 -1
- package/ui/ImageResizer.js.map +1 -1
- package/ui/LinkPreview.d.ts +0 -1
- package/ui/TextInput.d.ts +0 -1
- package/utils/files.d.ts +6 -6
- package/utils/files.js +3 -13
- package/utils/files.js.map +1 -1
- package/utils/insertImage.d.ts +1 -1
- package/utils/insertImage.js.map +1 -1
- package/utils/isValidLexicalData.d.ts +2 -2
- package/utils/isValidLexicalData.js.map +1 -1
- package/utils/rect.d.ts +1 -1
- package/utils/rect.js +1 -1
- package/utils/rect.js.map +1 -1
- package/utils/sanitizeUrl.js +1 -1
- package/utils/sanitizeUrl.js.map +1 -1
- package/utils/setFloatingElemPosition.d.ts +1 -1
- package/utils/setFloatingElemPosition.js +23 -21
- package/utils/setFloatingElemPosition.js.map +1 -1
- package/components/Editor/HeadingEditor.d.ts +0 -7
- package/components/Editor/HeadingEditor.js +0 -22
- package/components/Editor/HeadingEditor.js.map +0 -1
- package/components/Editor/ParagraphEditor.d.ts +0 -7
- package/components/Editor/ParagraphEditor.js +0 -22
- package/components/Editor/ParagraphEditor.js.map +0 -1
- package/components/Toolbar/Toolbar.css +0 -643
- package/components/Toolbar/Toolbar.d.ts +0 -6
- package/components/Toolbar/Toolbar.js +0 -148
- package/components/Toolbar/Toolbar.js.map +0 -1
- package/components/ToolbarActions/FontSizeAction.d.ts +0 -14
- package/components/ToolbarActions/FontSizeAction.js +0 -91
- package/components/ToolbarActions/FontSizeAction.js.map +0 -1
- package/hooks/useList.d.ts +0 -2
- package/hooks/useList.js +0 -50
- package/hooks/useList.js.map +0 -1
- package/hooks/useQuote.d.ts +0 -2
- package/hooks/useQuote.js +0 -17
- package/hooks/useQuote.js.map +0 -1
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +0 -8
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +0 -104
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +0 -1
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +0 -9
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +0 -34
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
# @webiny/lexical-editor
|
|
2
|
-
[](https://www.npmjs.com/package/@webiny/lexical-editor)
|
|
3
|
-
[](https://www.npmjs.com/package/@webiny/lexical-editor)
|
|
4
|
-
[](https://github.com/prettier/prettier)
|
|
5
|
-
[](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
|
-
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
9
8
|
|
|
10
|
-
|
|
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/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "
|
|
3
|
-
export * from "
|
|
4
|
-
export * from "
|
|
5
|
-
export * from "
|
|
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
|
package/commands/index.js.map
CHANGED
|
@@ -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
|
|
5
|
-
import type {
|
|
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?: (
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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,E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AAQ,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,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,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;AA4B5B,MAAMC,kBAAkB,GAAGA,CAAC;EACxBC,QAAQ;EACRC,OAAO;EACPC,aAAa;EACbC,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,MA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,aAAA,CAAC/B,aAAa;MAACsE,oBAAoB,EAAEzC;IAAa,CAAE,CAAC,EAEpDX,MAAM,iBAAI7B,KAAA,CAAA0C,aAAA,CAAC3B,eAAe;MAACc,MAAM,EAAEA;IAAO,CAAE,CAAC,EAC7CC,KAAK,iBAAI9B,KAAA,CAAA0C,aAAA,CAACpC,eAAe,MAAE,CAAC,EAE5B+C,aAAa,EACbzB,QAAQ,eACT5B,KAAA,CAAA0C,aAAA,CAAClC,cAAc;MACX0E,eAAe,eACXlF,KAAA,CAAA0C,aAAA;QAAKiC,SAAS,EAAC,iBAAiB;QAACE,KAAK,EAAE;UAAE,GAAG5B;QAAU;MAAE,gBACrDjD,KAAA,CAAA0C,aAAA;QAAKiC,SAAS,EAAC,QAAQ;QAACC,GAAG,EAAE7B;MAAM,gBAC/B/C,KAAA,CAAA0C,aAAA,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
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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":["
|
|
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 {
|
|
4
|
-
import type {
|
|
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:
|
|
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 {
|
|
9
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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","
|
|
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,eAAe,QAAQ,uCAAuC;AACvE,SAASC,oBAAoB,QAAQ,wCAAwC;AAC7E,SAASC,QAAQ,QAAQ,uBAAuB;AAGhD,SAASC,sBAAsB;AAC/B,SAASC,mBAAmB;AAQ5B,OAAO,MAAMC,mBAAmB,GAAGA,CAAC;EAAEC,KAAK;EAAEC,KAAK;EAAE,GAAGC;AAAgC,CAAC,KAAK;EACzF,MAAMC,KAAkB,GAAGD,KAAK,CAACC,KAAK;EACtC,MAAMC,WAAW,GAAGb,MAAM,CAACY,KAAK,CAAC;EAEjC,MAAME,aAAa,GAAG;IAClBC,WAAW,EAAE,IAAI;IACjBC,SAAS,EAAE,QAAQ;IACnBC,OAAO,EAAEA,CAAA,KAAM;MACX;MACA;IAAA,CACH;IACDC,QAAQ,EAAE,KAAK;IACfT,KAAK,EAAE,CAAC,GAAGJ,QAAQ,EAAE,IAAII,KAAK,IAAI,EAAE,CAAC,CAAC;IACtCG,KAAK,EAAE;MACH,GAAGC,WAAW,CAACM,OAAO,CAACC,MAAM;MAC7B;MACA;M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