@webiny/lexical-editor 0.0.0-unstable.06b2ede40f
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/LICENSE +21 -0
- package/README.md +17 -0
- package/commands/image.d.ts +6 -0
- package/commands/image.js +4 -0
- package/commands/image.js.map +1 -0
- package/commands/index.d.ts +5 -0
- package/commands/index.js +7 -0
- package/commands/index.js.map +1 -0
- package/commands/list.d.ts +7 -0
- package/commands/list.js +6 -0
- package/commands/list.js.map +1 -0
- package/commands/quote.d.ts +5 -0
- package/commands/quote.js +4 -0
- package/commands/quote.js.map +1 -0
- package/commands/toolbar.d.ts +1 -0
- package/commands/toolbar.js +4 -0
- package/commands/toolbar.js.map +1 -0
- package/commands/typography.d.ts +8 -0
- package/commands/typography.js +4 -0
- package/commands/typography.js.map +1 -0
- package/components/Editor/EnsureHeadingTagPlugin.d.ts +6 -0
- package/components/Editor/EnsureHeadingTagPlugin.js +20 -0
- package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -0
- package/components/Editor/HeadingEditor.d.ts +7 -0
- package/components/Editor/HeadingEditor.js +22 -0
- package/components/Editor/HeadingEditor.js.map +1 -0
- package/components/Editor/ParagraphEditor.d.ts +7 -0
- package/components/Editor/ParagraphEditor.js +22 -0
- package/components/Editor/ParagraphEditor.js.map +1 -0
- package/components/Editor/RichTextEditor.d.ts +49 -0
- package/components/Editor/RichTextEditor.js +133 -0
- package/components/Editor/RichTextEditor.js.map +1 -0
- package/components/Editor/normalizeInputValue.d.ts +6 -0
- package/components/Editor/normalizeInputValue.js +16 -0
- package/components/Editor/normalizeInputValue.js.map +1 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +20 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +63 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -0
- package/components/LexicalEditorConfig/components/Node.d.ts +14 -0
- package/components/LexicalEditorConfig/components/Node.js +30 -0
- package/components/LexicalEditorConfig/components/Node.js.map +1 -0
- package/components/LexicalEditorConfig/components/Plugin.d.ts +13 -0
- package/components/LexicalEditorConfig/components/Plugin.js +30 -0
- package/components/LexicalEditorConfig/components/Plugin.js.map +1 -0
- package/components/LexicalEditorConfig/components/ToolbarElement.d.ts +13 -0
- package/components/LexicalEditorConfig/components/ToolbarElement.js +30 -0
- package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -0
- package/components/LexicalHtmlRenderer.d.ts +14 -0
- package/components/LexicalHtmlRenderer.js +55 -0
- package/components/LexicalHtmlRenderer.js.map +1 -0
- package/components/Toolbar/StaticToolbar.css +260 -0
- package/components/Toolbar/StaticToolbar.d.ts +5 -0
- package/components/Toolbar/StaticToolbar.js +22 -0
- package/components/Toolbar/StaticToolbar.js.map +1 -0
- package/components/Toolbar/Toolbar.css +643 -0
- package/components/Toolbar/Toolbar.d.ts +6 -0
- package/components/Toolbar/Toolbar.js +148 -0
- package/components/Toolbar/Toolbar.js.map +1 -0
- package/components/ToolbarActions/BoldAction.d.ts +2 -0
- package/components/ToolbarActions/BoldAction.js +25 -0
- package/components/ToolbarActions/BoldAction.js.map +1 -0
- package/components/ToolbarActions/BulletListAction.d.ts +2 -0
- package/components/ToolbarActions/BulletListAction.js +40 -0
- package/components/ToolbarActions/BulletListAction.js.map +1 -0
- package/components/ToolbarActions/CodeHighlightAction.d.ts +2 -0
- package/components/ToolbarActions/CodeHighlightAction.js +25 -0
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -0
- package/components/ToolbarActions/FontColorAction.d.ts +29 -0
- package/components/ToolbarActions/FontColorAction.js +50 -0
- package/components/ToolbarActions/FontColorAction.js.map +1 -0
- package/components/ToolbarActions/FontSizeAction.d.ts +14 -0
- package/components/ToolbarActions/FontSizeAction.js +91 -0
- package/components/ToolbarActions/FontSizeAction.js.map +1 -0
- package/components/ToolbarActions/ImageAction.d.ts +2 -0
- package/components/ToolbarActions/ImageAction.js +37 -0
- package/components/ToolbarActions/ImageAction.js.map +1 -0
- package/components/ToolbarActions/ItalicAction.d.ts +2 -0
- package/components/ToolbarActions/ItalicAction.js +25 -0
- package/components/ToolbarActions/ItalicAction.js.map +1 -0
- package/components/ToolbarActions/LinkAction.d.ts +2 -0
- package/components/ToolbarActions/LinkAction.js +37 -0
- package/components/ToolbarActions/LinkAction.js.map +1 -0
- package/components/ToolbarActions/NumberedListAction.d.ts +2 -0
- package/components/ToolbarActions/NumberedListAction.js +48 -0
- package/components/ToolbarActions/NumberedListAction.js.map +1 -0
- package/components/ToolbarActions/QuoteAction.d.ts +2 -0
- package/components/ToolbarActions/QuoteAction.js +33 -0
- package/components/ToolbarActions/QuoteAction.js.map +1 -0
- package/components/ToolbarActions/TextAlignmentAction.d.ts +29 -0
- package/components/ToolbarActions/TextAlignmentAction.js +61 -0
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -0
- package/components/ToolbarActions/TypographyAction.d.ts +29 -0
- package/components/ToolbarActions/TypographyAction.js +108 -0
- package/components/ToolbarActions/TypographyAction.js.map +1 -0
- package/components/ToolbarActions/UnderlineAction.d.ts +2 -0
- package/components/ToolbarActions/UnderlineAction.js +24 -0
- package/components/ToolbarActions/UnderlineAction.js.map +1 -0
- package/context/FontColorActionContext.d.ts +6 -0
- package/context/FontColorActionContext.js +4 -0
- package/context/FontColorActionContext.js.map +1 -0
- package/context/RichTextEditorContext.d.ts +19 -0
- package/context/RichTextEditorContext.js +21 -0
- package/context/RichTextEditorContext.js.map +1 -0
- package/context/SharedHistoryContext.d.ts +10 -0
- package/context/SharedHistoryContext.js +19 -0
- package/context/SharedHistoryContext.js.map +1 -0
- package/context/TextAlignmentActionContextProps.d.ts +9 -0
- package/context/TextAlignmentActionContextProps.js +4 -0
- package/context/TextAlignmentActionContextProps.js.map +1 -0
- package/context/TypographyActionContext.d.ts +8 -0
- package/context/TypographyActionContext.js +4 -0
- package/context/TypographyActionContext.js.map +1 -0
- package/hooks/index.d.ts +8 -0
- package/hooks/index.js +10 -0
- package/hooks/index.js.map +1 -0
- package/hooks/useCurrentElement.d.ts +7 -0
- package/hooks/useCurrentElement.js +27 -0
- package/hooks/useCurrentElement.js.map +1 -0
- package/hooks/useCurrentSelection.d.ts +13 -0
- package/hooks/useCurrentSelection.js +57 -0
- package/hooks/useCurrentSelection.js.map +1 -0
- package/hooks/useFontColorPicker.d.ts +2 -0
- package/hooks/useFontColorPicker.js +11 -0
- package/hooks/useFontColorPicker.js.map +1 -0
- package/hooks/useIsMounted.d.ts +1 -0
- package/hooks/useIsMounted.js +12 -0
- package/hooks/useIsMounted.js.map +1 -0
- package/hooks/useList.d.ts +2 -0
- package/hooks/useList.js +50 -0
- package/hooks/useList.js.map +1 -0
- package/hooks/useQuote.d.ts +2 -0
- package/hooks/useQuote.js +17 -0
- package/hooks/useQuote.js.map +1 -0
- package/hooks/useRichTextEditor.d.ts +2 -0
- package/hooks/useRichTextEditor.js +11 -0
- package/hooks/useRichTextEditor.js.map +1 -0
- package/hooks/useTextAlignmentAction.d.ts +1 -0
- package/hooks/useTextAlignmentAction.js +11 -0
- package/hooks/useTextAlignmentAction.js.map +1 -0
- package/hooks/useTypographyAction.d.ts +1 -0
- package/hooks/useTypographyAction.js +11 -0
- package/hooks/useTypographyAction.js.map +1 -0
- package/images/icons/LICENSE.md +5 -0
- package/images/icons/chat-square-quote.svg +1 -0
- package/images/icons/chevron-down.svg +1 -0
- package/images/icons/code.svg +1 -0
- package/images/icons/font-color.svg +1 -0
- package/images/icons/indent.svg +3 -0
- package/images/icons/insert-image.svg +4 -0
- package/images/icons/justify.svg +3 -0
- package/images/icons/link.svg +1 -0
- package/images/icons/list-ol.svg +1 -0
- package/images/icons/list-ul.svg +1 -0
- package/images/icons/outdent.svg +3 -0
- package/images/icons/pencil-fill.svg +1 -0
- package/images/icons/text-center.svg +1 -0
- package/images/icons/text-left.svg +1 -0
- package/images/icons/text-paragraph.svg +1 -0
- package/images/icons/text-right.svg +1 -0
- package/images/icons/type-bold.svg +1 -0
- package/images/icons/type-h1.svg +1 -0
- package/images/icons/type-h2.svg +1 -0
- package/images/icons/type-h3.svg +1 -0
- package/images/icons/type-h4.svg +1 -0
- package/images/icons/type-h5.svg +1 -0
- package/images/icons/type-h6.svg +1 -0
- package/images/icons/type-italic.svg +1 -0
- package/images/icons/type-strikethrough.svg +1 -0
- package/images/icons/type-underline.svg +1 -0
- package/images/icons/unlink_icon.svg +1 -0
- package/index.d.ts +37 -0
- package/index.js +50 -0
- package/index.js.map +1 -0
- package/package.json +40 -0
- package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +7 -0
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +20 -0
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -0
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.d.ts +1 -0
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +14 -0
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -0
- package/plugins/CodeHighlightPlugin/index.d.ts +1 -0
- package/plugins/CodeHighlightPlugin/index.js +3 -0
- package/plugins/CodeHighlightPlugin/index.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +16 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +158 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +8 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +62 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +176 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +7 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +14 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +8 -0
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +104 -0
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +9 -0
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +34 -0
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -0
- package/plugins/FloatingLinkEditorPlugin/index.js +3 -0
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.d.ts +1 -0
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js +12 -0
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js.map +1 -0
- package/plugins/FontColorPlugin/FontColorPlugin.d.ts +1 -0
- package/plugins/FontColorPlugin/FontColorPlugin.js +27 -0
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -0
- package/plugins/FontColorPlugin/applyColorToNode.d.ts +3 -0
- package/plugins/FontColorPlugin/applyColorToNode.js +8 -0
- package/plugins/FontColorPlugin/applyColorToNode.js.map +1 -0
- package/plugins/FontColorPlugin/applyColorToSelection.d.ts +3 -0
- package/plugins/FontColorPlugin/applyColorToSelection.js +66 -0
- package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -0
- package/plugins/ImagesPlugin/ImagesPlugin.d.ts +12 -0
- package/plugins/ImagesPlugin/ImagesPlugin.js +151 -0
- package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -0
- package/plugins/LinkPlugin/LinkPlugin.d.ts +5 -0
- package/plugins/LinkPlugin/LinkPlugin.js +59 -0
- package/plugins/LinkPlugin/LinkPlugin.js.map +1 -0
- package/plugins/ListPLugin/ListPlugin.d.ts +1 -0
- package/plugins/ListPLugin/ListPlugin.js +17 -0
- package/plugins/ListPLugin/ListPlugin.js.map +1 -0
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.d.ts +1 -0
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +18 -0
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -0
- package/plugins/StateHandlingPlugin.d.ts +8 -0
- package/plugins/StateHandlingPlugin.js +75 -0
- package/plugins/StateHandlingPlugin.js.map +1 -0
- package/plugins/TypographyPlugin/TypographyPlugin.d.ts +1 -0
- package/plugins/TypographyPlugin/TypographyPlugin.js +27 -0
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -0
- package/types.d.ts +12 -0
- package/types.js +9 -0
- package/types.js.map +1 -0
- package/ui/ContentEditable.css +22 -0
- package/ui/ContentEditable.d.ts +12 -0
- package/ui/ContentEditable.js +19 -0
- package/ui/ContentEditable.js.map +1 -0
- package/ui/Divider.d.ts +2 -0
- package/ui/Divider.js +8 -0
- package/ui/Divider.js.map +1 -0
- package/ui/DropDown.d.ts +25 -0
- package/ui/DropDown.js +182 -0
- package/ui/DropDown.js.map +1 -0
- package/ui/ImageResizer.d.ts +24 -0
- package/ui/ImageResizer.js +211 -0
- package/ui/ImageResizer.js.map +1 -0
- package/ui/Input.css +32 -0
- package/ui/LinkPreview.css +69 -0
- package/ui/LinkPreview.d.ts +12 -0
- package/ui/LinkPreview.js +97 -0
- package/ui/LinkPreview.js.map +1 -0
- package/ui/Placeholder.css +20 -0
- package/ui/Placeholder.d.ts +15 -0
- package/ui/Placeholder.js +24 -0
- package/ui/Placeholder.js.map +1 -0
- package/ui/TextInput.d.ts +18 -0
- package/ui/TextInput.js +34 -0
- package/ui/TextInput.js.map +1 -0
- package/ui/ToolbarActionDialog.d.ts +11 -0
- package/ui/ToolbarActionDialog.js +77 -0
- package/ui/ToolbarActionDialog.js.map +1 -0
- package/utils/canUseDOM.d.ts +1 -0
- package/utils/canUseDOM.js +3 -0
- package/utils/canUseDOM.js.map +1 -0
- package/utils/files.d.ts +11 -0
- package/utils/files.js +21 -0
- package/utils/files.js.map +1 -0
- package/utils/getDOMRangeRect.d.ts +8 -0
- package/utils/getDOMRangeRect.js +23 -0
- package/utils/getDOMRangeRect.js.map +1 -0
- package/utils/getSelectedNode.d.ts +2 -0
- package/utils/getSelectedNode.js +25 -0
- package/utils/getSelectedNode.js.map +1 -0
- package/utils/getTransparentImage.d.ts +1 -0
- package/utils/getTransparentImage.js +5 -0
- package/utils/getTransparentImage.js.map +1 -0
- package/utils/insertImage.d.ts +2 -0
- package/utils/insertImage.js +16 -0
- package/utils/insertImage.js.map +1 -0
- package/utils/isAnchorLink.d.ts +1 -0
- package/utils/isAnchorLink.js +5 -0
- package/utils/isAnchorLink.js.map +1 -0
- package/utils/isChildOfFloatingToolbar.d.ts +1 -0
- package/utils/isChildOfFloatingToolbar.js +12 -0
- package/utils/isChildOfFloatingToolbar.js.map +1 -0
- package/utils/isHTMLElement.d.ts +8 -0
- package/utils/isHTMLElement.js +12 -0
- package/utils/isHTMLElement.js.map +1 -0
- package/utils/isValidJSON.d.ts +1 -0
- package/utils/isValidJSON.js +13 -0
- package/utils/isValidJSON.js.map +1 -0
- package/utils/isValidLexicalData.d.ts +4 -0
- package/utils/isValidLexicalData.js +24 -0
- package/utils/isValidLexicalData.js.map +1 -0
- package/utils/point.d.ts +21 -0
- package/utils/point.js +49 -0
- package/utils/point.js.map +1 -0
- package/utils/rect.d.ts +45 -0
- package/utils/rect.js +130 -0
- package/utils/rect.js.map +1 -0
- package/utils/sanitizeUrl.d.ts +1 -0
- package/utils/sanitizeUrl.js +25 -0
- package/utils/sanitizeUrl.js.map +1 -0
- package/utils/setFloatingElemPosition.d.ts +1 -0
- package/utils/setFloatingElemPosition.js +30 -0
- package/utils/setFloatingElemPosition.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
|
|
7
|
+
|
|
8
|
+
## About
|
|
9
|
+
|
|
10
|
+
This package provides a web text editor with rich text editing features. It's built on top of the Lexical framework.
|
|
11
|
+
|
|
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).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LexicalCommand, NodeKey } from "lexical";
|
|
2
|
+
import type { ImageNodeProps } from "@webiny/lexical-nodes";
|
|
3
|
+
export interface ImagePayload extends ImageNodeProps {
|
|
4
|
+
key?: NodeKey;
|
|
5
|
+
}
|
|
6
|
+
export declare const INSERT_IMAGE_COMMAND: LexicalCommand<ImagePayload>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createCommand","INSERT_IMAGE_COMMAND"],"sources":["image.ts"],"sourcesContent":["import type { LexicalCommand, NodeKey } from \"lexical\";\nimport { createCommand } from \"lexical\";\nimport type { ImageNodeProps } from \"@webiny/lexical-nodes\";\n\nexport interface ImagePayload extends ImageNodeProps {\n key?: NodeKey;\n}\n\nexport const INSERT_IMAGE_COMMAND: LexicalCommand<ImagePayload> =\n createCommand(\"INSERT_IMAGE_COMMAND\");\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,SAAS;AAOvC,OAAO,MAAMC,oBAAkD,GAC3DD,aAAa,CAAC,sBAAsB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LexicalCommand } from "lexical";
|
|
2
|
+
export type ListCommandPayload = {
|
|
3
|
+
themeStyleId?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<ListCommandPayload>;
|
|
6
|
+
export declare const INSERT_ORDERED_LIST_COMMAND: LexicalCommand<ListCommandPayload>;
|
|
7
|
+
export declare const REMOVE_LIST_COMMAND: LexicalCommand<void>;
|
package/commands/list.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createCommand } from "lexical";
|
|
2
|
+
export const INSERT_UNORDERED_LIST_COMMAND = createCommand("INSERT_UNORDERED_LIST_COMMAND");
|
|
3
|
+
export const INSERT_ORDERED_LIST_COMMAND = createCommand("INSERT_ORDERED_LIST_COMMAND");
|
|
4
|
+
export const REMOVE_LIST_COMMAND = createCommand("REMOVE_LIST_COMMAND");
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createCommand","INSERT_UNORDERED_LIST_COMMAND","INSERT_ORDERED_LIST_COMMAND","REMOVE_LIST_COMMAND"],"sources":["list.ts"],"sourcesContent":["import type { LexicalCommand } from \"lexical\";\nimport { createCommand } from \"lexical\";\n\nexport type ListCommandPayload = {\n themeStyleId?: string;\n};\n\nexport const INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<ListCommandPayload> = createCommand(\n \"INSERT_UNORDERED_LIST_COMMAND\"\n);\n\nexport const INSERT_ORDERED_LIST_COMMAND: LexicalCommand<ListCommandPayload> = createCommand(\n \"INSERT_ORDERED_LIST_COMMAND\"\n);\n\nexport const REMOVE_LIST_COMMAND: LexicalCommand<void> = createCommand(\"REMOVE_LIST_COMMAND\");\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,SAAS;AAMvC,OAAO,MAAMC,6BAAiE,GAAGD,aAAa,CAC1F,+BACJ,CAAC;AAED,OAAO,MAAME,2BAA+D,GAAGF,aAAa,CACxF,6BACJ,CAAC;AAED,OAAO,MAAMG,mBAAyC,GAAGH,aAAa,CAAC,qBAAqB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createCommand","INSERT_QUOTE_COMMAND"],"sources":["quote.ts"],"sourcesContent":["import type { LexicalCommand } from \"lexical\";\nimport { createCommand } from \"lexical\";\n\nexport type QuoteCommandPayload = {\n themeStyleId: string;\n};\n\nexport const INSERT_QUOTE_COMMAND: LexicalCommand<QuoteCommandPayload> =\n createCommand(\"INSERT_QUOTE_COMMAND\");\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,SAAS;AAMvC,OAAO,MAAMC,oBAAyD,GAClED,aAAa,CAAC,sBAAsB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const HIDE_FLOATING_TOOLBAR: import("lexical").LexicalCommand<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createCommand","HIDE_FLOATING_TOOLBAR"],"sources":["toolbar.ts"],"sourcesContent":["import { createCommand } from \"lexical\";\n\nexport const HIDE_FLOATING_TOOLBAR = createCommand(\"HIDE_FLOATING_TOOLBAR_COMMAND\");\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,SAAS;AAEvC,OAAO,MAAMC,qBAAqB,GAAGD,aAAa,CAAC,+BAA+B,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LexicalCommand, LexicalEditor, NodeKey } from "lexical";
|
|
2
|
+
import type { TypographyValue } from "@webiny/lexical-theme";
|
|
3
|
+
export declare const ADD_TYPOGRAPHY_COMMAND: LexicalCommand<TypographyPayload>;
|
|
4
|
+
export interface TypographyPayload {
|
|
5
|
+
value: TypographyValue;
|
|
6
|
+
caption?: LexicalEditor;
|
|
7
|
+
key?: NodeKey;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createCommand","ADD_TYPOGRAPHY_COMMAND"],"sources":["typography.ts"],"sourcesContent":["import type { LexicalCommand, LexicalEditor, NodeKey } from \"lexical\";\nimport { createCommand } from \"lexical\";\nimport type { TypographyValue } from \"@webiny/lexical-theme\";\n\nexport const ADD_TYPOGRAPHY_COMMAND: LexicalCommand<TypographyPayload> =\n createCommand(\"ADD_TYPOGRAPHY_COMMAND\");\n\nexport interface TypographyPayload {\n value: TypographyValue;\n caption?: LexicalEditor;\n key?: NodeKey;\n}\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,SAAS;AAGvC,OAAO,MAAMC,sBAAyD,GAClED,aAAa,CAAC,wBAAwB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In the "Heading" editor, we only want to support heading tags.
|
|
3
|
+
* However, when the editor is empty, and you start typing, Lexical automatically creates an empty "paragraph" node.
|
|
4
|
+
* This ensures that any paragraph node is automatically converted to a heading node.
|
|
5
|
+
*/
|
|
6
|
+
export declare const EnsureHeadingTagPlugin: () => null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { ParagraphNode, $createHeadingNode } from "@webiny/lexical-nodes";
|
|
3
|
+
import { useRichTextEditor } from "../../hooks";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In the "Heading" editor, we only want to support heading tags.
|
|
7
|
+
* However, when the editor is empty, and you start typing, Lexical automatically creates an empty "paragraph" node.
|
|
8
|
+
* This ensures that any paragraph node is automatically converted to a heading node.
|
|
9
|
+
*/
|
|
10
|
+
export const EnsureHeadingTagPlugin = () => {
|
|
11
|
+
const {
|
|
12
|
+
editor
|
|
13
|
+
} = useRichTextEditor();
|
|
14
|
+
useEffect(() => editor.registerNodeTransform(ParagraphNode, node => {
|
|
15
|
+
node.replace($createHeadingNode("h1"), true);
|
|
16
|
+
}), []);
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=EnsureHeadingTagPlugin.js.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { RichTextEditorProps } from "./RichTextEditor";
|
|
3
|
+
interface HeadingEditorProps extends RichTextEditorProps {
|
|
4
|
+
tag?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
5
|
+
}
|
|
6
|
+
export declare const HeadingEditor: ({ tag, placeholder, ...rest }: HeadingEditorProps) => React.JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { RichTextEditor } from "./RichTextEditor";
|
|
3
|
+
import { Toolbar } from "../Toolbar/Toolbar";
|
|
4
|
+
import { EnsureHeadingTagPlugin } from "./EnsureHeadingTagPlugin";
|
|
5
|
+
const styles = {
|
|
6
|
+
padding: 5
|
|
7
|
+
};
|
|
8
|
+
export const HeadingEditor = ({
|
|
9
|
+
tag,
|
|
10
|
+
placeholder,
|
|
11
|
+
...rest
|
|
12
|
+
}) => {
|
|
13
|
+
return /*#__PURE__*/React.createElement(RichTextEditor, Object.assign({
|
|
14
|
+
toolbar: /*#__PURE__*/React.createElement(Toolbar, null),
|
|
15
|
+
tag: tag ?? "h1",
|
|
16
|
+
placeholder: placeholder ?? "Enter your heading text here..."
|
|
17
|
+
}, rest, {
|
|
18
|
+
styles: styles
|
|
19
|
+
}), /*#__PURE__*/React.createElement(EnsureHeadingTagPlugin, null), rest?.children);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=HeadingEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","RichTextEditor","Toolbar","EnsureHeadingTagPlugin","styles","padding","HeadingEditor","tag","placeholder","rest","createElement","Object","assign","toolbar","children"],"sources":["HeadingEditor.tsx"],"sourcesContent":["import React from \"react\";\nimport type { RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\nimport { RichTextEditor } from \"~/components/Editor/RichTextEditor\";\nimport { Toolbar } from \"~/components/Toolbar/Toolbar\";\nimport { EnsureHeadingTagPlugin } from \"~/components/Editor/EnsureHeadingTagPlugin\";\n\ninterface HeadingEditorProps extends RichTextEditorProps {\n tag?: \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n}\n\nconst styles = { padding: 5 };\n\nexport const HeadingEditor = ({ tag, placeholder, ...rest }: HeadingEditorProps) => {\n return (\n <RichTextEditor\n toolbar={<Toolbar />}\n tag={tag ?? \"h1\"}\n placeholder={placeholder ?? \"Enter your heading text here...\"}\n {...rest}\n styles={styles}\n >\n <EnsureHeadingTagPlugin />\n {rest?.children}\n </RichTextEditor>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,cAAc;AACvB,SAASC,OAAO;AAChB,SAASC,sBAAsB;AAM/B,MAAMC,MAAM,GAAG;EAAEC,OAAO,EAAE;AAAE,CAAC;AAE7B,OAAO,MAAMC,aAAa,GAAGA,CAAC;EAAEC,GAAG;EAAEC,WAAW;EAAE,GAAGC;AAAyB,CAAC,KAAK;EAChF,oBACIT,KAAA,CAAAU,aAAA,CAACT,cAAc,EAAAU,MAAA,CAAAC,MAAA;IACXC,OAAO,eAAEb,KAAA,CAAAU,aAAA,CAACR,OAAO,MAAE,CAAE;IACrBK,GAAG,EAAEA,GAAG,IAAI,IAAK;IACjBC,WAAW,EAAEA,WAAW,IAAI;EAAkC,GAC1DC,IAAI;IACRL,MAAM,EAAEA;EAAO,iBAEfJ,KAAA,CAAAU,aAAA,CAACP,sBAAsB,MAAE,CAAC,EACzBM,IAAI,EAAEK,QACK,CAAC;AAEzB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { RichTextEditorProps } from "./RichTextEditor";
|
|
3
|
+
interface ParagraphLexicalEditorProps extends RichTextEditorProps {
|
|
4
|
+
tag?: "p";
|
|
5
|
+
}
|
|
6
|
+
declare const ParagraphEditor: ({ placeholder, tag, ...rest }: ParagraphLexicalEditorProps) => React.JSX.Element;
|
|
7
|
+
export { ParagraphEditor };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { RichTextEditor } from "./RichTextEditor";
|
|
3
|
+
import { Toolbar } from "../Toolbar/Toolbar";
|
|
4
|
+
const styles = {
|
|
5
|
+
padding: 5
|
|
6
|
+
};
|
|
7
|
+
const ParagraphEditor = ({
|
|
8
|
+
placeholder,
|
|
9
|
+
tag,
|
|
10
|
+
...rest
|
|
11
|
+
}) => {
|
|
12
|
+
return /*#__PURE__*/React.createElement(RichTextEditor, Object.assign({
|
|
13
|
+
toolbar: /*#__PURE__*/React.createElement(Toolbar, null),
|
|
14
|
+
tag: tag ?? "p",
|
|
15
|
+
placeholder: placeholder ?? "Enter your text here..."
|
|
16
|
+
}, rest, {
|
|
17
|
+
styles: styles
|
|
18
|
+
}), rest?.children);
|
|
19
|
+
};
|
|
20
|
+
export { ParagraphEditor };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=ParagraphEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","RichTextEditor","Toolbar","styles","padding","ParagraphEditor","placeholder","tag","rest","createElement","Object","assign","toolbar","children"],"sources":["ParagraphEditor.tsx"],"sourcesContent":["import React from \"react\";\nimport type { RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\nimport { RichTextEditor } from \"~/components/Editor/RichTextEditor\";\nimport { Toolbar } from \"~/components/Toolbar/Toolbar\";\n\ninterface ParagraphLexicalEditorProps extends RichTextEditorProps {\n tag?: \"p\";\n}\n\nconst styles = { padding: 5 };\n\nconst ParagraphEditor = ({ placeholder, tag, ...rest }: ParagraphLexicalEditorProps) => {\n return (\n <RichTextEditor\n toolbar={<Toolbar />}\n tag={tag ?? \"p\"}\n placeholder={placeholder ?? \"Enter your text here...\"}\n {...rest}\n styles={styles}\n >\n {rest?.children}\n </RichTextEditor>\n );\n};\n\nexport { ParagraphEditor };\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,cAAc;AACvB,SAASC,OAAO;AAMhB,MAAMC,MAAM,GAAG;EAAEC,OAAO,EAAE;AAAE,CAAC;AAE7B,MAAMC,eAAe,GAAGA,CAAC;EAAEC,WAAW;EAAEC,GAAG;EAAE,GAAGC;AAAkC,CAAC,KAAK;EACpF,oBACIR,KAAA,CAAAS,aAAA,CAACR,cAAc,EAAAS,MAAA,CAAAC,MAAA;IACXC,OAAO,eAAEZ,KAAA,CAAAS,aAAA,CAACP,OAAO,MAAE,CAAE;IACrBK,GAAG,EAAEA,GAAG,IAAI,GAAI;IAChBD,WAAW,EAAEA,WAAW,IAAI;EAA0B,GAClDE,IAAI;IACRL,MAAM,EAAEA;EAAO,IAEdK,IAAI,EAAEK,QACK,CAAC;AAEzB,CAAC;AAED,SAASR,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { CSSObject } from "@emotion/react";
|
|
3
|
+
import type { Klass, LexicalNode } from "lexical";
|
|
4
|
+
import type { EditorTheme, ThemeEmotionMap } from "@webiny/lexical-theme";
|
|
5
|
+
import type { LexicalValue, ToolbarActionPlugin } from "../../types";
|
|
6
|
+
export interface RichTextEditorProps {
|
|
7
|
+
children?: React.ReactNode | React.ReactNode[];
|
|
8
|
+
classes?: string;
|
|
9
|
+
contentEditableStyles?: React.CSSProperties;
|
|
10
|
+
focus?: boolean;
|
|
11
|
+
height?: number | string;
|
|
12
|
+
nodes?: Klass<LexicalNode>[];
|
|
13
|
+
onBlur?: (editorState: LexicalValue) => void;
|
|
14
|
+
onChange?: (json: LexicalValue) => void;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
placeholderStyles?: React.CSSProperties;
|
|
17
|
+
staticToolbar?: React.ReactNode;
|
|
18
|
+
styles?: React.CSSProperties;
|
|
19
|
+
tag?: string;
|
|
20
|
+
theme: EditorTheme;
|
|
21
|
+
themeEmotionMap?: ThemeEmotionMap;
|
|
22
|
+
toolbarActionPlugins?: ToolbarActionPlugin[];
|
|
23
|
+
themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;
|
|
24
|
+
toolbar?: React.ReactNode;
|
|
25
|
+
value: LexicalValue | null | undefined;
|
|
26
|
+
width?: number | string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @description Main editor container
|
|
30
|
+
*/
|
|
31
|
+
export declare const RichTextEditor: ((props: RichTextEditorProps) => React.JSX.Element) & {
|
|
32
|
+
original: (props: RichTextEditorProps) => React.JSX.Element;
|
|
33
|
+
originalName: string;
|
|
34
|
+
displayName: string;
|
|
35
|
+
} & {
|
|
36
|
+
original: ((props: RichTextEditorProps) => React.JSX.Element) & {
|
|
37
|
+
original: (props: RichTextEditorProps) => React.JSX.Element;
|
|
38
|
+
originalName: string;
|
|
39
|
+
displayName: string;
|
|
40
|
+
};
|
|
41
|
+
originalName: string;
|
|
42
|
+
displayName: string;
|
|
43
|
+
} & {
|
|
44
|
+
createDecorator: (decorator: import("@webiny/react-composition").ComponentDecorator<((props: RichTextEditorProps) => React.JSX.Element) & {
|
|
45
|
+
original: (props: RichTextEditorProps) => React.JSX.Element;
|
|
46
|
+
originalName: string;
|
|
47
|
+
displayName: string;
|
|
48
|
+
}>) => (props: unknown) => React.JSX.Element;
|
|
49
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import React, { Fragment, useRef, useState } from "react";
|
|
2
|
+
import { css } from "emotion";
|
|
3
|
+
import { LexicalComposer } from "@lexical/react/LexicalComposer";
|
|
4
|
+
import { AutoFocusPlugin } from "@lexical/react/LexicalAutoFocusPlugin";
|
|
5
|
+
import { ClearEditorPlugin } from "@lexical/react/LexicalClearEditorPlugin";
|
|
6
|
+
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
7
|
+
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
|
|
8
|
+
import { makeDecoratable } from "@webiny/react-composition";
|
|
9
|
+
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
|
|
10
|
+
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
11
|
+
import { createTheme, toTypographyEmotionMap } from "@webiny/lexical-theme";
|
|
12
|
+
import { allNodes } from "@webiny/lexical-nodes";
|
|
13
|
+
import { RichTextEditorProvider } from "../../context/RichTextEditorContext";
|
|
14
|
+
import { BlurEventPlugin } from "../../plugins/BlurEventPlugin/BlurEventPlugin";
|
|
15
|
+
import { Placeholder } from "../../ui/Placeholder";
|
|
16
|
+
import { SharedHistoryContext, useSharedHistoryContext } from "../../context/SharedHistoryContext";
|
|
17
|
+
import { LexicalEditorWithConfig, useLexicalEditorConfig } from "../LexicalEditorConfig/LexicalEditorConfig";
|
|
18
|
+
import { StateHandlingPlugin } from "../../plugins/StateHandlingPlugin";
|
|
19
|
+
const BaseRichTextEditor = ({
|
|
20
|
+
toolbar,
|
|
21
|
+
staticToolbar,
|
|
22
|
+
onChange,
|
|
23
|
+
nodes,
|
|
24
|
+
placeholder,
|
|
25
|
+
children,
|
|
26
|
+
onBlur,
|
|
27
|
+
focus,
|
|
28
|
+
styles,
|
|
29
|
+
width,
|
|
30
|
+
height,
|
|
31
|
+
contentEditableStyles,
|
|
32
|
+
placeholderStyles,
|
|
33
|
+
...props
|
|
34
|
+
}) => {
|
|
35
|
+
const themeEmotionMap = props.themeEmotionMap ?? toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);
|
|
36
|
+
const editorTheme = useRef(createTheme(props.theme));
|
|
37
|
+
const config = useLexicalEditorConfig();
|
|
38
|
+
const {
|
|
39
|
+
historyState
|
|
40
|
+
} = useSharedHistoryContext();
|
|
41
|
+
const placeholderElem = /*#__PURE__*/React.createElement(Placeholder, {
|
|
42
|
+
styles: placeholderStyles
|
|
43
|
+
}, placeholder || "Enter text...");
|
|
44
|
+
const scrollRef = useRef(null);
|
|
45
|
+
const [floatingAnchorElem, setFloatingAnchorElem] = useState(undefined);
|
|
46
|
+
const onRef = _floatingAnchorElem => {
|
|
47
|
+
if (_floatingAnchorElem !== null) {
|
|
48
|
+
setFloatingAnchorElem(_floatingAnchorElem);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const sizeStyle = {
|
|
52
|
+
height: height || "",
|
|
53
|
+
width: width || ""
|
|
54
|
+
};
|
|
55
|
+
const configNodes = config.nodes.map(node => node.node);
|
|
56
|
+
const configPlugins = config.plugins.map(plugin => /*#__PURE__*/React.createElement(Fragment, {
|
|
57
|
+
key: plugin.name
|
|
58
|
+
}, plugin.element));
|
|
59
|
+
const initialConfig = {
|
|
60
|
+
editorState: null,
|
|
61
|
+
namespace: "webiny",
|
|
62
|
+
onError: () => {
|
|
63
|
+
// Ignore errors. We don't want to break the app because of errors caused by config/value updates.
|
|
64
|
+
// These are usually resolved in the next component render cycle.
|
|
65
|
+
},
|
|
66
|
+
nodes: [...allNodes, ...configNodes, ...(nodes || [])],
|
|
67
|
+
theme: {
|
|
68
|
+
...editorTheme.current,
|
|
69
|
+
emotionMap: themeEmotionMap
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return (
|
|
73
|
+
/*#__PURE__*/
|
|
74
|
+
/**
|
|
75
|
+
* Once the LexicalComposer is mounted, it caches the `initialConfig` internally, and all future
|
|
76
|
+
* updates to the config will be ignored. This is a problem because we pull in Nodes from our config,
|
|
77
|
+
* and initially, there can be multiple re-renders, while the config object is settled.
|
|
78
|
+
*
|
|
79
|
+
* To bypass this issue, we generate a naive `key` based on the number of Nodes.
|
|
80
|
+
*/
|
|
81
|
+
React.createElement(SharedHistoryContext, null, /*#__PURE__*/React.createElement(LexicalComposer, {
|
|
82
|
+
initialConfig: initialConfig,
|
|
83
|
+
key: initialConfig.nodes.length
|
|
84
|
+
}, /*#__PURE__*/React.createElement(RichTextEditorProvider, {
|
|
85
|
+
theme: props.theme,
|
|
86
|
+
themeEmotionMap: themeEmotionMap,
|
|
87
|
+
toolbarActionPlugins: props.toolbarActionPlugins
|
|
88
|
+
}, staticToolbar ? staticToolbar : null, /*#__PURE__*/React.createElement("div", {
|
|
89
|
+
/* This className is necessary for targeting of editor container from CSS files. */
|
|
90
|
+
className: "editor-shell",
|
|
91
|
+
ref: scrollRef,
|
|
92
|
+
style: {
|
|
93
|
+
...styles,
|
|
94
|
+
...sizeStyle,
|
|
95
|
+
overflow: "auto",
|
|
96
|
+
position: "relative"
|
|
97
|
+
}
|
|
98
|
+
}, /*#__PURE__*/React.createElement(StateHandlingPlugin, {
|
|
99
|
+
value: props.value,
|
|
100
|
+
onChange: onChange
|
|
101
|
+
}), /*#__PURE__*/React.createElement(ClearEditorPlugin, null), /*#__PURE__*/React.createElement(HistoryPlugin, {
|
|
102
|
+
externalHistoryState: historyState
|
|
103
|
+
}), onBlur && /*#__PURE__*/React.createElement(BlurEventPlugin, {
|
|
104
|
+
onBlur: onBlur
|
|
105
|
+
}), focus && /*#__PURE__*/React.createElement(AutoFocusPlugin, null), configPlugins, children, /*#__PURE__*/React.createElement(RichTextPlugin, {
|
|
106
|
+
contentEditable: /*#__PURE__*/React.createElement("div", {
|
|
107
|
+
className: "editor-scroller",
|
|
108
|
+
style: {
|
|
109
|
+
...sizeStyle
|
|
110
|
+
}
|
|
111
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
112
|
+
className: "editor",
|
|
113
|
+
ref: onRef
|
|
114
|
+
}, /*#__PURE__*/React.createElement(ContentEditable, {
|
|
115
|
+
style: {
|
|
116
|
+
outline: 0,
|
|
117
|
+
...contentEditableStyles
|
|
118
|
+
}
|
|
119
|
+
}))),
|
|
120
|
+
placeholder: placeholderElem,
|
|
121
|
+
ErrorBoundary: LexicalErrorBoundary
|
|
122
|
+
}), floatingAnchorElem && toolbar))))
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @description Main editor container
|
|
128
|
+
*/
|
|
129
|
+
export const RichTextEditor = makeDecoratable("RichTextEditor", props => {
|
|
130
|
+
return /*#__PURE__*/React.createElement(LexicalEditorWithConfig, null, /*#__PURE__*/React.createElement(BaseRichTextEditor, props));
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=RichTextEditor.js.map
|
|
@@ -0,0 +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 </LexicalEditor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AAe;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":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LexicalValue, NormalizedInputValue } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes
|
|
4
|
+
* of input into a value that is either a `null` or a `LexicalValue`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function normalizeInputValue(value: LexicalValue | null | undefined): NormalizedInputValue;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const isValueEmpty = value => {
|
|
2
|
+
return [undefined, null, "", '""', "null"].includes(value);
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes
|
|
7
|
+
* of input into a value that is either a `null` or a `LexicalValue`.
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeInputValue(value) {
|
|
10
|
+
if (isValueEmpty(value)) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=normalizeInputValue.js.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
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;
|
|
12
|
+
};
|
|
13
|
+
export declare const LexicalEditorWithConfig: ({ children }: {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}) => React.JSX.Element;
|
|
16
|
+
export declare function useLexicalEditorConfig(): {
|
|
17
|
+
toolbarElements: ToolbarElementConfig[];
|
|
18
|
+
plugins: PluginConfig[];
|
|
19
|
+
nodes: NodeConfig[];
|
|
20
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
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);
|
|
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
|
+
};
|
|
49
|
+
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
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=LexicalEditorConfig.js.map
|
|
@@ -0,0 +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,c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B,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":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Klass, LexicalNode } from "lexical";
|
|
3
|
+
export interface NodeConfig {
|
|
4
|
+
name: string;
|
|
5
|
+
node: Klass<LexicalNode>;
|
|
6
|
+
}
|
|
7
|
+
export interface NodeProps {
|
|
8
|
+
name: string;
|
|
9
|
+
node?: Klass<LexicalNode>;
|
|
10
|
+
remove?: boolean;
|
|
11
|
+
before?: string;
|
|
12
|
+
after?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const Node: ({ name, node, after, before, remove }: NodeProps) => React.JSX.Element;
|