@webiny/lexical-editor 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.a9593f74dd
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/commands/image.d.ts +6 -0
- package/commands/{insertFiles.js → image.js} +3 -1
- package/commands/image.js.map +1 -0
- package/commands/index.d.ts +3 -0
- package/commands/index.js +40 -0
- package/commands/index.js.map +1 -0
- package/commands/list.d.ts +7 -0
- package/commands/list.js +15 -0
- package/commands/list.js.map +1 -0
- package/commands/quote.d.ts +5 -0
- package/commands/quote.js +11 -0
- package/commands/quote.js.map +1 -0
- package/components/Editor/HeadingEditor.d.ts +2 -2
- package/components/Editor/HeadingEditor.js +10 -7
- package/components/Editor/HeadingEditor.js.map +1 -1
- package/components/Editor/ParagraphEditor.d.ts +2 -2
- package/components/Editor/ParagraphEditor.js +10 -7
- package/components/Editor/ParagraphEditor.js.map +1 -1
- package/components/Editor/RichTextEditor.d.ts +22 -20
- package/components/Editor/RichTextEditor.js +63 -46
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +3 -3
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +3 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
- package/components/LexicalEditorConfig/components/Node.d.ts +2 -2
- package/components/LexicalEditorConfig/components/Node.js +3 -1
- package/components/LexicalEditorConfig/components/Node.js.map +1 -1
- package/components/LexicalEditorConfig/components/Plugin.d.ts +1 -1
- package/components/LexicalEditorConfig/components/Plugin.js +3 -1
- package/components/LexicalEditorConfig/components/Plugin.js.map +1 -1
- package/components/LexicalEditorConfig/components/ToolbarElement.d.ts +1 -1
- package/components/LexicalEditorConfig/components/ToolbarElement.js +3 -1
- package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -1
- package/components/LexicalHtmlRenderer.d.ts +7 -5
- package/components/LexicalHtmlRenderer.js +24 -18
- package/components/LexicalHtmlRenderer.js.map +1 -1
- package/components/Toolbar/StaticToolbar.d.ts +2 -2
- package/components/Toolbar/StaticToolbar.js +7 -78
- package/components/Toolbar/StaticToolbar.js.map +1 -1
- package/components/Toolbar/Toolbar.d.ts +1 -2
- package/components/Toolbar/Toolbar.js +30 -83
- package/components/Toolbar/Toolbar.js.map +1 -1
- package/components/ToolbarActions/BoldAction.js +10 -20
- package/components/ToolbarActions/BoldAction.js.map +1 -1
- package/components/ToolbarActions/BulletListAction.js +17 -24
- package/components/ToolbarActions/BulletListAction.js.map +1 -1
- package/components/ToolbarActions/CodeHighlightAction.js +10 -20
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
- package/components/ToolbarActions/FontColorAction.d.ts +7 -4
- package/components/ToolbarActions/FontColorAction.js +20 -37
- package/components/ToolbarActions/FontColorAction.js.map +1 -1
- package/components/ToolbarActions/FontSizeAction.js +11 -27
- package/components/ToolbarActions/FontSizeAction.js.map +1 -1
- package/components/ToolbarActions/ImageAction.js +11 -8
- package/components/ToolbarActions/ImageAction.js.map +1 -1
- package/components/ToolbarActions/ItalicAction.js +10 -20
- package/components/ToolbarActions/ItalicAction.js.map +1 -1
- package/components/ToolbarActions/LinkAction.js +18 -36
- package/components/ToolbarActions/LinkAction.js.map +1 -1
- package/components/ToolbarActions/NumberedListAction.js +18 -28
- package/components/ToolbarActions/NumberedListAction.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +15 -24
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TextAlignmentAction.d.ts +7 -4
- package/components/ToolbarActions/TextAlignmentAction.js +26 -21
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.d.ts +7 -4
- package/components/ToolbarActions/TypographyAction.js +53 -60
- package/components/ToolbarActions/TypographyAction.js.map +1 -1
- package/components/ToolbarActions/UnderlineAction.js +11 -21
- package/components/ToolbarActions/UnderlineAction.js.map +1 -1
- package/context/FontColorActionContext.js +3 -1
- package/context/FontColorActionContext.js.map +1 -1
- package/context/RichTextEditorContext.d.ts +3 -7
- package/context/RichTextEditorContext.js +20 -36
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/SharedHistoryContext.d.ts +0 -1
- package/context/SharedHistoryContext.js +3 -1
- package/context/SharedHistoryContext.js.map +1 -1
- package/context/TextAlignmentActionContextProps.js +3 -1
- package/context/TextAlignmentActionContextProps.js.map +1 -1
- package/context/TypographyActionContext.d.ts +1 -1
- package/context/TypographyActionContext.js +3 -1
- package/context/TypographyActionContext.js.map +1 -1
- package/hooks/index.d.ts +7 -0
- package/hooks/index.js +84 -0
- package/hooks/index.js.map +1 -0
- package/hooks/useCurrentElement.d.ts +7 -0
- package/hooks/useCurrentElement.js +33 -0
- package/hooks/useCurrentElement.js.map +1 -0
- package/hooks/useCurrentSelection.d.ts +12 -0
- package/hooks/useCurrentSelection.js +72 -0
- package/hooks/useCurrentSelection.js.map +1 -0
- package/hooks/useFontColorPicker.js +3 -1
- package/hooks/useFontColorPicker.js.map +1 -1
- package/hooks/useIsMounted.d.ts +1 -0
- package/hooks/useIsMounted.js +20 -0
- package/hooks/useIsMounted.js.map +1 -0
- package/hooks/useList.js +31 -16
- package/hooks/useList.js.map +1 -1
- package/hooks/useQuote.d.ts +1 -1
- package/hooks/useQuote.js +9 -7
- package/hooks/useQuote.js.map +1 -1
- package/hooks/useRichTextEditor.js +3 -1
- package/hooks/useRichTextEditor.js.map +1 -1
- package/hooks/useTextAlignmentAction.js +3 -1
- package/hooks/useTextAlignmentAction.js.map +1 -1
- package/hooks/useTypographyAction.js +3 -1
- package/hooks/useTypographyAction.js.map +1 -1
- package/index.d.ts +4 -8
- package/index.js +71 -48
- package/index.js.map +1 -1
- package/package.json +16 -20
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +3 -1
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +3 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/index.js +3 -1
- package/plugins/CodeHighlightPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +0 -2
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +15 -11
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js +3 -1
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
- package/plugins/FontColorPlugin/FontColorPlugin.d.ts +1 -2
- package/plugins/FontColorPlugin/FontColorPlugin.js +8 -7
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/ImagesPlugin/ImagesPlugin.d.ts +1 -2
- package/plugins/ImagesPlugin/ImagesPlugin.js +12 -11
- package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.d.ts +9 -0
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js +49 -0
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js.map +1 -0
- package/plugins/LexicalUpdateStatePlugin/index.d.ts +1 -1
- package/plugins/LexicalUpdateStatePlugin/index.js +7 -5
- package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -1
- package/plugins/LinkPlugin/LinkPlugin.d.ts +5 -0
- package/plugins/LinkPlugin/LinkPlugin.js +68 -0
- package/plugins/LinkPlugin/LinkPlugin.js.map +1 -0
- package/plugins/ListPLugin/ListPlugin.js +6 -5
- package/plugins/ListPLugin/ListPlugin.js.map +1 -1
- package/plugins/TypographyPlugin/TypographyPlugin.d.ts +1 -2
- package/plugins/TypographyPlugin/TypographyPlugin.js +7 -7
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js +6 -4
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js.map +1 -1
- package/types.d.ts +2 -61
- package/types.js +5 -3
- package/types.js.map +1 -1
- package/ui/ContentEditable.js +3 -1
- package/ui/ContentEditable.js.map +1 -1
- package/ui/Divider.js +3 -1
- package/ui/Divider.js.map +1 -1
- package/ui/DropDown.d.ts +0 -1
- package/ui/DropDown.js +3 -1
- package/ui/DropDown.js.map +1 -1
- package/ui/ImageResizer.d.ts +0 -2
- package/ui/ImageResizer.js +3 -1
- package/ui/ImageResizer.js.map +1 -1
- package/ui/LinkPreview.js +3 -1
- package/ui/LinkPreview.js.map +1 -1
- package/ui/Placeholder.js +3 -1
- package/ui/Placeholder.js.map +1 -1
- package/ui/TextInput.js +3 -1
- package/ui/TextInput.js.map +1 -1
- package/ui/ToolbarActionDialog.d.ts +1 -1
- package/ui/ToolbarActionDialog.js +4 -2
- package/ui/ToolbarActionDialog.js.map +1 -1
- package/utils/canUseDOM.js +3 -1
- package/utils/canUseDOM.js.map +1 -1
- package/utils/files.d.ts +1 -1
- package/utils/files.js +5 -3
- package/utils/files.js.map +1 -1
- package/utils/generateInitialLexicalValue.js +23 -19
- package/utils/generateInitialLexicalValue.js.map +1 -1
- package/utils/getDOMRangeRect.d.ts +0 -2
- package/utils/getDOMRangeRect.js +3 -1
- package/utils/getDOMRangeRect.js.map +1 -1
- package/utils/getSelectedNode.js +3 -1
- package/utils/getSelectedNode.js.map +1 -1
- package/utils/getTransparentImage.js +3 -1
- package/utils/getTransparentImage.js.map +1 -1
- package/utils/insertImage.d.ts +2 -0
- package/utils/{nodes/insertImage.js → insertImage.js} +6 -5
- package/utils/insertImage.js.map +1 -0
- package/utils/isHTMLElement.d.ts +0 -2
- package/utils/isHTMLElement.js +3 -1
- package/utils/isHTMLElement.js.map +1 -1
- package/utils/isUrlLinkReference.d.ts +1 -0
- package/utils/isUrlLinkReference.js +12 -0
- package/utils/isUrlLinkReference.js.map +1 -0
- package/utils/isValidJSON.js +3 -1
- package/utils/isValidJSON.js.map +1 -1
- package/utils/isValidLexicalData.d.ts +2 -0
- package/utils/isValidLexicalData.js +20 -12
- package/utils/isValidLexicalData.js.map +1 -1
- package/utils/point.js +3 -4
- package/utils/point.js.map +1 -1
- package/utils/rect.d.ts +0 -2
- package/utils/rect.js +3 -6
- package/utils/rect.js.map +1 -1
- package/utils/sanitizeUrl.d.ts +0 -7
- package/utils/sanitizeUrl.js +7 -1
- package/utils/sanitizeUrl.js.map +1 -1
- package/utils/setFloatingElemPosition.d.ts +0 -2
- package/utils/setFloatingElemPosition.js +3 -1
- package/utils/setFloatingElemPosition.js.map +1 -1
- package/commands/insertFiles.d.ts +0 -14
- package/commands/insertFiles.js.map +0 -1
- package/commands/webiny-list.d.ts +0 -7
- package/commands/webiny-list.js +0 -13
- package/commands/webiny-list.js.map +0 -1
- package/commands/webiny-quote.d.ts +0 -5
- package/commands/webiny-quote.js +0 -9
- package/commands/webiny-quote.js.map +0 -1
- package/components/ImageComponent.d.ts +0 -23
- package/components/ImageComponent.js +0 -252
- package/components/ImageComponent.js.map +0 -1
- package/nodes/FontColorNode.d.ts +0 -43
- package/nodes/FontColorNode.js +0 -127
- package/nodes/FontColorNode.js.map +0 -1
- package/nodes/HeadingNode.d.ts +0 -34
- package/nodes/HeadingNode.js +0 -192
- package/nodes/HeadingNode.js.map +0 -1
- package/nodes/ImageNode.d.ts +0 -50
- package/nodes/ImageNode.js +0 -217
- package/nodes/ImageNode.js.map +0 -1
- package/nodes/ListItemNode.d.ts +0 -46
- package/nodes/ListItemNode.js +0 -441
- package/nodes/ListItemNode.js.map +0 -1
- package/nodes/ListNode/formatList.d.ts +0 -12
- package/nodes/ListNode/formatList.js +0 -424
- package/nodes/ListNode/formatList.js.map +0 -1
- package/nodes/ListNode.d.ts +0 -42
- package/nodes/ListNode.js +0 -294
- package/nodes/ListNode.js.map +0 -1
- package/nodes/ParagraphNode.d.ts +0 -32
- package/nodes/ParagraphNode.js +0 -218
- package/nodes/ParagraphNode.js.map +0 -1
- package/nodes/QuoteNode.d.ts +0 -34
- package/nodes/QuoteNode.js +0 -225
- package/nodes/QuoteNode.js.map +0 -1
- package/nodes/TypographyElementNode.d.ts +0 -42
- package/nodes/TypographyElementNode.js +0 -155
- package/nodes/TypographyElementNode.js.map +0 -1
- package/nodes/imageNode.css +0 -43
- package/nodes/types.d.ts +0 -15
- package/nodes/types.js +0 -5
- package/nodes/types.js.map +0 -1
- package/nodes/webinyNodes.d.ts +0 -7
- package/nodes/webinyNodes.js +0 -46
- package/nodes/webinyNodes.js.map +0 -1
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.d.ts +0 -8
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js +0 -34
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js.map +0 -1
- package/themes/webinyLexicalTheme.css +0 -423
- package/themes/webinyLexicalTheme.d.ts +0 -9
- package/themes/webinyLexicalTheme.js +0 -90
- package/themes/webinyLexicalTheme.js.map +0 -1
- package/utils/findTypographyStyleByHtmlTag.d.ts +0 -8
- package/utils/findTypographyStyleByHtmlTag.js +0 -16
- package/utils/findTypographyStyleByHtmlTag.js.map +0 -1
- package/utils/getLexicalTextSelectionState.d.ts +0 -5
- package/utils/getLexicalTextSelectionState.js +0 -163
- package/utils/getLexicalTextSelectionState.js.map +0 -1
- package/utils/nodes/clearNodeFormating.d.ts +0 -2
- package/utils/nodes/clearNodeFormating.js +0 -28
- package/utils/nodes/clearNodeFormating.js.map +0 -1
- package/utils/nodes/formatToHeading.d.ts +0 -3
- package/utils/nodes/formatToHeading.js +0 -25
- package/utils/nodes/formatToHeading.js.map +0 -1
- package/utils/nodes/formatToParagraph.d.ts +0 -2
- package/utils/nodes/formatToParagraph.js +0 -20
- package/utils/nodes/formatToParagraph.js.map +0 -1
- package/utils/nodes/formatToQuote.d.ts +0 -2
- package/utils/nodes/formatToQuote.js +0 -25
- package/utils/nodes/formatToQuote.js.map +0 -1
- package/utils/nodes/insertImage.d.ts +0 -2
- package/utils/nodes/insertImage.js.map +0 -1
- package/utils/nodes/listNode.d.ts +0 -11
- package/utils/nodes/listNode.js +0 -107
- package/utils/nodes/listNode.js.map +0 -1
- package/utils/styleObjectToString.d.ts +0 -2
- package/utils/styleObjectToString.js +0 -22
- package/utils/styleObjectToString.js.map +0 -1
- package/utils/toTypographyEmotionMap.d.ts +0 -3
- package/utils/toTypographyEmotionMap.js +0 -36
- package/utils/toTypographyEmotionMap.js.map +0 -1
|
@@ -6,4 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.INSERT_IMAGE_COMMAND = void 0;
|
|
7
7
|
var _lexical = require("lexical");
|
|
8
8
|
var INSERT_IMAGE_COMMAND = (0, _lexical.createCommand)("INSERT_IMAGE_COMMAND");
|
|
9
|
-
exports.INSERT_IMAGE_COMMAND = INSERT_IMAGE_COMMAND;
|
|
9
|
+
exports.INSERT_IMAGE_COMMAND = INSERT_IMAGE_COMMAND;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_lexical","require","INSERT_IMAGE_COMMAND","createCommand","exports"],"sources":["image.ts"],"sourcesContent":["import { createCommand, LexicalCommand, NodeKey } from \"lexical\";\nimport { 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":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAOO,IAAMC,oBAAkD,GAC3D,IAAAC,sBAAa,EAAC,sBAAsB,CAAC;AAACC,OAAA,CAAAF,oBAAA,GAAAA,oBAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _image = require("./image");
|
|
7
|
+
Object.keys(_image).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _image[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _image[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _list = require("./list");
|
|
18
|
+
Object.keys(_list).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _list[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _list[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _quote = require("./quote");
|
|
29
|
+
Object.keys(_quote).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _quote[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _quote[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_image","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_list","_quote"],"sources":["index.ts"],"sourcesContent":["export * from \"~/commands/image\";\nexport * from \"~/commands/list\";\nexport * from \"~/commands/quote\";\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,KAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,KAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,KAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,KAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,MAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,MAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,MAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAE,MAAA,CAAAN,GAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LexicalCommand } from "lexical";
|
|
2
|
+
export declare 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,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.REMOVE_LIST_COMMAND = exports.INSERT_UNORDERED_LIST_COMMAND = exports.INSERT_ORDERED_LIST_COMMAND = void 0;
|
|
7
|
+
var _lexical = require("lexical");
|
|
8
|
+
var INSERT_UNORDERED_LIST_COMMAND = (0, _lexical.createCommand)("INSERT_UNORDERED_LIST_COMMAND");
|
|
9
|
+
exports.INSERT_UNORDERED_LIST_COMMAND = INSERT_UNORDERED_LIST_COMMAND;
|
|
10
|
+
var INSERT_ORDERED_LIST_COMMAND = (0, _lexical.createCommand)("INSERT_ORDERED_LIST_COMMAND");
|
|
11
|
+
exports.INSERT_ORDERED_LIST_COMMAND = INSERT_ORDERED_LIST_COMMAND;
|
|
12
|
+
var REMOVE_LIST_COMMAND = (0, _lexical.createCommand)("REMOVE_LIST_COMMAND");
|
|
13
|
+
exports.REMOVE_LIST_COMMAND = REMOVE_LIST_COMMAND;
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_lexical","require","INSERT_UNORDERED_LIST_COMMAND","createCommand","exports","INSERT_ORDERED_LIST_COMMAND","REMOVE_LIST_COMMAND"],"sources":["list.ts"],"sourcesContent":["import { createCommand, LexicalCommand } 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":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAMO,IAAMC,6BAAiE,GAAG,IAAAC,sBAAa,EAC1F,+BACJ,CAAC;AAACC,OAAA,CAAAF,6BAAA,GAAAA,6BAAA;AAEK,IAAMG,2BAA+D,GAAG,IAAAF,sBAAa,EACxF,6BACJ,CAAC;AAACC,OAAA,CAAAC,2BAAA,GAAAA,2BAAA;AAEK,IAAMC,mBAAyC,GAAG,IAAAH,sBAAa,EAAC,qBAAqB,CAAC;AAACC,OAAA,CAAAE,mBAAA,GAAAA,mBAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.INSERT_QUOTE_COMMAND = void 0;
|
|
7
|
+
var _lexical = require("lexical");
|
|
8
|
+
var INSERT_QUOTE_COMMAND = (0, _lexical.createCommand)("INSERT_QUOTE_COMMAND");
|
|
9
|
+
exports.INSERT_QUOTE_COMMAND = INSERT_QUOTE_COMMAND;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=quote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_lexical","require","INSERT_QUOTE_COMMAND","createCommand","exports"],"sources":["quote.ts"],"sourcesContent":["import { createCommand, LexicalCommand } 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":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAMO,IAAMC,oBAAyD,GAClE,IAAAC,sBAAa,EAAC,sBAAsB,CAAC;AAACC,OAAA,CAAAF,oBAAA,GAAAA,oBAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { RichTextEditorProps } from "./RichTextEditor";
|
|
3
3
|
interface HeadingEditorProps extends RichTextEditorProps {
|
|
4
4
|
tag?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
5
5
|
}
|
|
6
|
-
export declare const HeadingEditor:
|
|
6
|
+
export declare const HeadingEditor: ({ tag, placeholder, ...rest }: HeadingEditorProps) => JSX.Element;
|
|
7
7
|
export {};
|
|
@@ -10,18 +10,21 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
10
10
|
var _RichTextEditor = require("./RichTextEditor");
|
|
11
11
|
var _Toolbar = require("../Toolbar/Toolbar");
|
|
12
12
|
var _excluded = ["tag", "placeholder"];
|
|
13
|
+
var styles = {
|
|
14
|
+
padding: 5
|
|
15
|
+
};
|
|
13
16
|
var HeadingEditor = function HeadingEditor(_ref) {
|
|
14
17
|
var tag = _ref.tag,
|
|
15
18
|
placeholder = _ref.placeholder,
|
|
16
19
|
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
17
20
|
return /*#__PURE__*/_react.default.createElement(_RichTextEditor.RichTextEditor, Object.assign({
|
|
18
21
|
toolbar: /*#__PURE__*/_react.default.createElement(_Toolbar.Toolbar, null),
|
|
19
|
-
tag: tag
|
|
20
|
-
placeholder: placeholder
|
|
22
|
+
tag: tag ?? "h1",
|
|
23
|
+
placeholder: placeholder ?? "Enter your heading text here..."
|
|
21
24
|
}, rest, {
|
|
22
|
-
styles:
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}), rest === null || rest === void 0 ? void 0 : rest.children);
|
|
25
|
+
styles: styles
|
|
26
|
+
}), rest?.children);
|
|
26
27
|
};
|
|
27
|
-
exports.HeadingEditor = HeadingEditor;
|
|
28
|
+
exports.HeadingEditor = HeadingEditor;
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=HeadingEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HeadingEditor","tag","placeholder","rest","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_RichTextEditor","_Toolbar","_excluded","styles","padding","HeadingEditor","_ref","tag","placeholder","rest","_objectWithoutProperties2","default","createElement","RichTextEditor","Object","assign","toolbar","Toolbar","children","exports"],"sources":["HeadingEditor.tsx"],"sourcesContent":["import React from \"react\";\nimport { RichTextEditor, RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\nimport { Toolbar } from \"~/components/Toolbar/Toolbar\";\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 {rest?.children}\n </RichTextEditor>\n );\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAAuD,IAAAG,SAAA;AAMvD,IAAMC,MAAM,GAAG;EAAEC,OAAO,EAAE;AAAE,CAAC;AAEtB,IAAMC,aAAa,GAAG,SAAhBA,aAAaA,CAAAC,IAAA,EAA0D;EAAA,IAApDC,GAAG,GAAAD,IAAA,CAAHC,GAAG;IAAEC,WAAW,GAAAF,IAAA,CAAXE,WAAW;IAAKC,IAAI,OAAAC,yBAAA,CAAAC,OAAA,EAAAL,IAAA,EAAAJ,SAAA;EACrD,oBACIL,MAAA,CAAAc,OAAA,CAAAC,aAAA,CAACZ,eAAA,CAAAa,cAAc,EAAAC,MAAA,CAAAC,MAAA;IACXC,OAAO,eAAEnB,MAAA,CAAAc,OAAA,CAAAC,aAAA,CAACX,QAAA,CAAAgB,OAAO,MAAE,CAAE;IACrBV,GAAG,EAAEA,GAAG,IAAI,IAAK;IACjBC,WAAW,EAAEA,WAAW,IAAI;EAAkC,GAC1DC,IAAI;IACRN,MAAM,EAAEA;EAAO,IAEdM,IAAI,EAAES,QACK,CAAC;AAEzB,CAAC;AAACC,OAAA,CAAAd,aAAA,GAAAA,aAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { RichTextEditorProps } from "./RichTextEditor";
|
|
3
3
|
interface ParagraphLexicalEditorProps extends RichTextEditorProps {
|
|
4
4
|
tag?: "p";
|
|
5
5
|
}
|
|
6
|
-
declare const ParagraphEditor:
|
|
6
|
+
declare const ParagraphEditor: ({ placeholder, tag, ...rest }: ParagraphLexicalEditorProps) => JSX.Element;
|
|
7
7
|
export { ParagraphEditor };
|
|
@@ -10,18 +10,21 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
10
10
|
var _RichTextEditor = require("./RichTextEditor");
|
|
11
11
|
var _Toolbar = require("../Toolbar/Toolbar");
|
|
12
12
|
var _excluded = ["placeholder", "tag"];
|
|
13
|
+
var styles = {
|
|
14
|
+
padding: 5
|
|
15
|
+
};
|
|
13
16
|
var ParagraphEditor = function ParagraphEditor(_ref) {
|
|
14
17
|
var placeholder = _ref.placeholder,
|
|
15
18
|
tag = _ref.tag,
|
|
16
19
|
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
17
20
|
return /*#__PURE__*/_react.default.createElement(_RichTextEditor.RichTextEditor, Object.assign({
|
|
18
21
|
toolbar: /*#__PURE__*/_react.default.createElement(_Toolbar.Toolbar, null),
|
|
19
|
-
tag: tag
|
|
20
|
-
placeholder: placeholder
|
|
22
|
+
tag: tag ?? "p",
|
|
23
|
+
placeholder: placeholder ?? "Enter your text here..."
|
|
21
24
|
}, rest, {
|
|
22
|
-
styles:
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}), rest === null || rest === void 0 ? void 0 : rest.children);
|
|
25
|
+
styles: styles
|
|
26
|
+
}), rest?.children);
|
|
26
27
|
};
|
|
27
|
-
exports.ParagraphEditor = ParagraphEditor;
|
|
28
|
+
exports.ParagraphEditor = ParagraphEditor;
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=ParagraphEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ParagraphEditor","placeholder","tag","rest","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_RichTextEditor","_Toolbar","_excluded","styles","padding","ParagraphEditor","_ref","placeholder","tag","rest","_objectWithoutProperties2","default","createElement","RichTextEditor","Object","assign","toolbar","Toolbar","children","exports"],"sources":["ParagraphEditor.tsx"],"sourcesContent":["import React from \"react\";\nimport { RichTextEditor, RichTextEditorProps } 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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAAuD,IAAAG,SAAA;AAMvD,IAAMC,MAAM,GAAG;EAAEC,OAAO,EAAE;AAAE,CAAC;AAE7B,IAAMC,eAAe,GAAG,SAAlBA,eAAeA,CAAAC,IAAA,EAAmE;EAAA,IAA7DC,WAAW,GAAAD,IAAA,CAAXC,WAAW;IAAEC,GAAG,GAAAF,IAAA,CAAHE,GAAG;IAAKC,IAAI,OAAAC,yBAAA,CAAAC,OAAA,EAAAL,IAAA,EAAAJ,SAAA;EAChD,oBACIL,MAAA,CAAAc,OAAA,CAAAC,aAAA,CAACZ,eAAA,CAAAa,cAAc,EAAAC,MAAA,CAAAC,MAAA;IACXC,OAAO,eAAEnB,MAAA,CAAAc,OAAA,CAAAC,aAAA,CAACX,QAAA,CAAAgB,OAAO,MAAE,CAAE;IACrBT,GAAG,EAAEA,GAAG,IAAI,GAAI;IAChBD,WAAW,EAAEA,WAAW,IAAI;EAA0B,GAClDE,IAAI;IACRN,MAAM,EAAEA;EAAO,IAEdM,IAAI,EAAES,QACK,CAAC;AAEzB,CAAC;AAACC,OAAA,CAAAd,eAAA,GAAAA,eAAA"}
|
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { CSSObject } from "@emotion/react";
|
|
3
3
|
import { Klass, LexicalNode } from "lexical";
|
|
4
|
-
import {
|
|
4
|
+
import { LexicalValue, ToolbarActionPlugin } from "../../types";
|
|
5
|
+
import { WebinyTheme, ThemeEmotionMap } from "@webiny/lexical-theme";
|
|
5
6
|
export interface RichTextEditorProps {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
tag?: string;
|
|
10
|
-
onChange?: (json: LexicalValue) => void;
|
|
11
|
-
value: LexicalValue | null;
|
|
7
|
+
children?: React.ReactNode | React.ReactNode[];
|
|
8
|
+
classes?: string;
|
|
9
|
+
contentEditableStyles?: React.CSSProperties;
|
|
12
10
|
focus?: boolean;
|
|
13
|
-
|
|
11
|
+
height?: number | string;
|
|
14
12
|
nodes?: Klass<LexicalNode>[];
|
|
15
|
-
/**
|
|
16
|
-
* @description Lexical plugins
|
|
17
|
-
*/
|
|
18
|
-
children?: React.ReactNode | React.ReactNode[];
|
|
19
13
|
onBlur?: (editorState: LexicalValue) => void;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
theme: WebinyTheme;
|
|
23
|
-
themeEmotionMap?: ThemeEmotionMap;
|
|
14
|
+
onChange?: (json: LexicalValue) => void;
|
|
15
|
+
placeholder?: string;
|
|
24
16
|
placeholderStyles?: React.CSSProperties;
|
|
17
|
+
staticToolbar?: React.ReactNode;
|
|
25
18
|
styles?: React.CSSProperties;
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
tag?: string;
|
|
20
|
+
theme: WebinyTheme;
|
|
21
|
+
themeEmotionMap?: ThemeEmotionMap;
|
|
22
|
+
themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;
|
|
23
|
+
toolbar?: React.ReactNode;
|
|
24
|
+
toolbarActionPlugins?: ToolbarActionPlugin[];
|
|
25
|
+
value: LexicalValue | null;
|
|
26
|
+
width?: number | string;
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
30
29
|
* @description Main editor container
|
|
31
30
|
*/
|
|
32
|
-
export declare const RichTextEditor:
|
|
31
|
+
export declare const RichTextEditor: React.FunctionComponent<RichTextEditorProps> & {
|
|
32
|
+
original: React.ComponentType<RichTextEditorProps>;
|
|
33
|
+
originalName: string;
|
|
34
|
+
};
|
|
@@ -10,8 +10,7 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
|
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
-
var
|
|
14
|
-
var _generateInitialLexicalValue = require("../../utils/generateInitialLexicalValue");
|
|
13
|
+
var _react2 = require("@emotion/react");
|
|
15
14
|
var _LexicalComposer = require("@lexical/react/LexicalComposer");
|
|
16
15
|
var _LexicalOnChangePlugin = require("@lexical/react/LexicalOnChangePlugin");
|
|
17
16
|
var _LexicalAutoFocusPlugin = require("@lexical/react/LexicalAutoFocusPlugin");
|
|
@@ -19,18 +18,18 @@ var _LexicalClearEditorPlugin = require("@lexical/react/LexicalClearEditorPlugin
|
|
|
19
18
|
var _LexicalRichTextPlugin = require("@lexical/react/LexicalRichTextPlugin");
|
|
20
19
|
var _LexicalErrorBoundary = _interopRequireDefault(require("@lexical/react/LexicalErrorBoundary"));
|
|
21
20
|
var _reactComposition = require("@webiny/react-composition");
|
|
21
|
+
var _LexicalHistoryPlugin = require("@lexical/react/LexicalHistoryPlugin");
|
|
22
22
|
var _LexicalContentEditable = require("@lexical/react/LexicalContentEditable");
|
|
23
23
|
var _RichTextEditorContext = require("../../context/RichTextEditorContext");
|
|
24
24
|
var _isValidLexicalData = require("../../utils/isValidLexicalData");
|
|
25
25
|
var _LexicalUpdateStatePlugin = require("../../plugins/LexicalUpdateStatePlugin");
|
|
26
26
|
var _BlurEventPlugin = require("../../plugins/BlurEventPlugin/BlurEventPlugin");
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
27
|
+
var _Placeholder = require("../../ui/Placeholder");
|
|
28
|
+
var _generateInitialLexicalValue = require("../../utils/generateInitialLexicalValue");
|
|
29
|
+
var _lexicalTheme = require("@webiny/lexical-theme");
|
|
30
|
+
var _lexicalNodes = require("@webiny/lexical-nodes");
|
|
30
31
|
var _SharedHistoryContext = require("../../context/SharedHistoryContext");
|
|
31
32
|
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
32
|
-
var _react2 = require("@emotion/react");
|
|
33
|
-
var _toTypographyEmotionMap = require("../../utils/toTypographyEmotionMap");
|
|
34
33
|
var _LexicalEditorConfig = require("../LexicalEditorConfig/LexicalEditorConfig");
|
|
35
34
|
var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
|
|
36
35
|
var toolbar = _ref.toolbar,
|
|
@@ -50,6 +49,7 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
|
|
|
50
49
|
toolbarActionPlugins = _ref.toolbarActionPlugins,
|
|
51
50
|
contentEditableStyles = _ref.contentEditableStyles,
|
|
52
51
|
placeholderStyles = _ref.placeholderStyles;
|
|
52
|
+
var editorTheme = (0, _react.useRef)((0, _lexicalTheme.createTheme)());
|
|
53
53
|
var config = (0, _LexicalEditorConfig.useLexicalEditorConfig)();
|
|
54
54
|
var _useSharedHistoryCont = (0, _SharedHistoryContext.useSharedHistoryContext)(),
|
|
55
55
|
historyState = _useSharedHistoryCont.historyState;
|
|
@@ -91,14 +91,17 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
|
|
|
91
91
|
key: plugin.name
|
|
92
92
|
}, plugin.element);
|
|
93
93
|
});
|
|
94
|
+
var editorValue = (0, _isValidLexicalData.isValidLexicalData)(value) ? value : (0, _generateInitialLexicalValue.generateInitialLexicalValue)();
|
|
94
95
|
var initialConfig = {
|
|
95
|
-
|
|
96
|
+
// We update the state via the `<LexicalUpdateStatePlugin/>`.
|
|
97
|
+
editorState: null,
|
|
96
98
|
namespace: "webiny",
|
|
97
|
-
onError: function onError(
|
|
98
|
-
|
|
99
|
+
onError: function onError() {
|
|
100
|
+
// Ignore errors. We don't want to break the app because of errors caused by config/value updates.
|
|
101
|
+
// These are usually resolved in the next component render cycle.
|
|
99
102
|
},
|
|
100
|
-
nodes: [].concat((0, _toConsumableArray2.default)(
|
|
101
|
-
theme: (0, _objectSpread2.default)((0, _objectSpread2.default)({},
|
|
103
|
+
nodes: [].concat((0, _toConsumableArray2.default)(_lexicalNodes.allNodes), (0, _toConsumableArray2.default)(configNodes), (0, _toConsumableArray2.default)(nodes || [])),
|
|
104
|
+
theme: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, editorTheme.current), {}, {
|
|
102
105
|
emotionMap: themeEmotionMap
|
|
103
106
|
})
|
|
104
107
|
};
|
|
@@ -110,37 +113,50 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
|
|
|
110
113
|
}
|
|
111
114
|
});
|
|
112
115
|
}
|
|
113
|
-
return
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
116
|
+
return (
|
|
117
|
+
/*#__PURE__*/
|
|
118
|
+
/**
|
|
119
|
+
* Once the LexicalComposer is mounted, it caches the `initialConfig` internally, and all future
|
|
120
|
+
* updates to the config will be ignored. This is a problem because we pull in Nodes from our config,
|
|
121
|
+
* and initially, there can be multiple re-renders, while the config object is settled.
|
|
122
|
+
*
|
|
123
|
+
* To bypass this issue, we generate a naive `key` based on the number of Nodes.
|
|
124
|
+
*/
|
|
125
|
+
_react.default.createElement(_LexicalComposer.LexicalComposer, {
|
|
126
|
+
initialConfig: initialConfig,
|
|
127
|
+
key: initialConfig.nodes.length
|
|
128
|
+
}, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, staticToolbar && staticToolbar, /*#__PURE__*/_react.default.createElement("div", {
|
|
129
|
+
/* This className is necessary for targeting of editor container from CSS files. */
|
|
130
|
+
className: "editor-shell",
|
|
131
|
+
ref: scrollRef,
|
|
132
|
+
style: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, styles), sizeStyle), {}, {
|
|
133
|
+
overflow: "auto",
|
|
134
|
+
position: "relative"
|
|
135
|
+
})
|
|
136
|
+
}, /*#__PURE__*/_react.default.createElement(_LexicalOnChangePlugin.OnChangePlugin, {
|
|
137
|
+
onChange: handleOnChange
|
|
138
|
+
}), /*#__PURE__*/_react.default.createElement(_LexicalUpdateStatePlugin.UpdateStatePlugin, {
|
|
139
|
+
value: editorValue
|
|
140
|
+
}), /*#__PURE__*/_react.default.createElement(_LexicalClearEditorPlugin.ClearEditorPlugin, null), /*#__PURE__*/_react.default.createElement(_LexicalHistoryPlugin.HistoryPlugin, {
|
|
141
|
+
externalHistoryState: historyState
|
|
142
|
+
}), onBlur && /*#__PURE__*/_react.default.createElement(_BlurEventPlugin.BlurEventPlugin, {
|
|
143
|
+
onBlur: onBlur
|
|
144
|
+
}), focus && /*#__PURE__*/_react.default.createElement(_LexicalAutoFocusPlugin.AutoFocusPlugin, null), configPlugins, children, /*#__PURE__*/_react.default.createElement(_LexicalRichTextPlugin.RichTextPlugin, {
|
|
145
|
+
contentEditable: /*#__PURE__*/_react.default.createElement("div", {
|
|
146
|
+
className: "editor-scroller",
|
|
147
|
+
style: (0, _objectSpread2.default)({}, sizeStyle)
|
|
148
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
149
|
+
className: "editor",
|
|
150
|
+
ref: onRef
|
|
151
|
+
}, /*#__PURE__*/_react.default.createElement(_LexicalContentEditable.ContentEditable, {
|
|
152
|
+
style: (0, _objectSpread2.default)({
|
|
153
|
+
outline: 0
|
|
154
|
+
}, contentEditableStyles)
|
|
155
|
+
}))),
|
|
156
|
+
placeholder: placeholderElem,
|
|
157
|
+
ErrorBoundary: _LexicalErrorBoundary.default
|
|
158
|
+
}), floatingAnchorElem && toolbar)))
|
|
159
|
+
);
|
|
144
160
|
};
|
|
145
161
|
|
|
146
162
|
/**
|
|
@@ -148,12 +164,13 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
|
|
|
148
164
|
*/
|
|
149
165
|
var RichTextEditor = (0, _reactComposition.makeComposable)("RichTextEditor", function (props) {
|
|
150
166
|
return /*#__PURE__*/_react.default.createElement(_LexicalEditorConfig.LexicalEditorWithConfig, null, /*#__PURE__*/_react.default.createElement(_RichTextEditorContext.RichTextEditorProvider, null, /*#__PURE__*/_react.default.createElement(_react2.ClassNames, null, function (_ref2) {
|
|
151
|
-
var _props$themeEmotionMa;
|
|
152
167
|
var css = _ref2.css;
|
|
153
|
-
var themeEmotionMap =
|
|
168
|
+
var themeEmotionMap = props?.themeEmotionMap ?? (0, _lexicalTheme.toTypographyEmotionMap)(css, props.theme, props.themeStylesTransformer);
|
|
154
169
|
return /*#__PURE__*/_react.default.createElement(_SharedHistoryContext.SharedHistoryContext, null, /*#__PURE__*/_react.default.createElement(BaseRichTextEditor, Object.assign({}, props, {
|
|
155
170
|
themeEmotionMap: themeEmotionMap
|
|
156
171
|
})));
|
|
157
172
|
})));
|
|
158
173
|
});
|
|
159
|
-
exports.RichTextEditor = RichTextEditor;
|
|
174
|
+
exports.RichTextEditor = RichTextEditor;
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=RichTextEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BaseRichTextEditor","toolbar","staticToolbar","onChange","value","nodes","placeholder","children","onBlur","focus","styles","width","height","theme","themeEmotionMap","toolbarActionPlugins","contentEditableStyles","placeholderStyles","config","useLexicalEditorConfig","useSharedHistoryContext","historyState","placeholderElem","scrollRef","useRef","useState","undefined","floatingAnchorElem","setFloatingAnchorElem","useRichTextEditor","setTheme","setThemeEmotionMap","setToolbarActionPlugins","useEffect","onRef","_floatingAnchorElem","sizeStyle","configNodes","map","node","configPlugins","plugins","plugin","name","element","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","WebinyNodes","webinyEditorTheme","emotionMap","handleOnChange","editor","read","getEditorState","JSON","stringify","toJSON","overflow","outline","LexicalErrorBoundary","RichTextEditor","makeComposable","props","css","toTypographyEmotionMap"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { Fragment, useEffect, useRef, useState } from \"react\";\nimport { LexicalValue, ThemeEmotionMap, ToolbarActionPlugin } from \"~/types\";\nimport { Placeholder } from \"~/ui/Placeholder\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { EditorState } from \"lexical/LexicalEditorState\";\nimport { Klass, LexicalEditor, LexicalNode } from \"lexical\";\nimport { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { OnChangePlugin } from \"@lexical/react/LexicalOnChangePlugin\";\nimport { AutoFocusPlugin } from \"@lexical/react/LexicalAutoFocusPlugin\";\nimport { ClearEditorPlugin } from \"@lexical/react/LexicalClearEditorPlugin\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport LexicalErrorBoundary from \"@lexical/react/LexicalErrorBoundary\";\nimport { makeComposable } from \"@webiny/react-composition\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport { RichTextEditorProvider } from \"~/context/RichTextEditorContext\";\nimport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nimport { LexicalUpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\nimport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\nimport { HistoryPlugin } from \"@lexical/react/LexicalHistoryPlugin\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { ClassNames } from \"@emotion/react\";\nimport { toTypographyEmotionMap } from \"~/utils/toTypographyEmotionMap\";\nimport {\n LexicalEditorWithConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\n\nexport interface RichTextEditorProps {\n toolbar?: React.ReactNode;\n staticToolbar?: React.ReactNode;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n tag?: string;\n onChange?: (json: LexicalValue) => void;\n value: LexicalValue | null;\n focus?: boolean;\n placeholder?: string;\n nodes?: Klass<LexicalNode>[];\n /**\n * @description Lexical plugins\n */\n children?: React.ReactNode | React.ReactNode[];\n onBlur?: (editorState: LexicalValue) => void;\n height?: number | string;\n width?: number | string;\n /*\n * @description Theme to be injected into lexical editor\n */\n theme: WebinyTheme;\n themeEmotionMap?: ThemeEmotionMap;\n\n placeholderStyles?: React.CSSProperties;\n /*\n * Set inline styles to lexical editor container\n * */\n styles?: React.CSSProperties;\n\n /*\n * Set inline styles to lexical editor editable content\n * */\n contentEditableStyles?: React.CSSProperties;\n\n /*\n * Set classes to lexical input container\n * */\n classes?: string;\n}\n\nconst BaseRichTextEditor: React.FC<RichTextEditorProps> = ({\n toolbar,\n staticToolbar,\n onChange,\n value,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n styles,\n width,\n height,\n theme,\n themeEmotionMap,\n toolbarActionPlugins,\n contentEditableStyles,\n placeholderStyles\n}: RichTextEditorProps) => {\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 { setTheme, setThemeEmotionMap, setToolbarActionPlugins } = useRichTextEditor();\n\n useEffect(() => {\n setTheme(theme);\n setThemeEmotionMap(themeEmotionMap);\n }, [themeEmotionMap, theme]);\n\n useEffect(() => {\n if (toolbarActionPlugins) {\n setToolbarActionPlugins(toolbarActionPlugins || []);\n }\n }, [toolbarActionPlugins]);\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: isValidLexicalData(value) ? value : generateInitialLexicalValue(),\n namespace: \"webiny\",\n onError: (error: Error) => {\n throw error;\n },\n nodes: [...WebinyNodes, ...configNodes, ...(nodes || [])],\n theme: { ...webinyEditorTheme, emotionMap: themeEmotionMap }\n };\n\n function handleOnChange(editorState: EditorState, editor: LexicalEditor) {\n editorState.read(() => {\n if (typeof onChange === \"function\") {\n const editorState = editor.getEditorState();\n onChange(JSON.stringify(editorState.toJSON()));\n }\n });\n }\n\n return (\n <LexicalComposer initialConfig={initialConfig}>\n <>\n {staticToolbar && staticToolbar}\n <div\n className={\"editor-shell\"}\n ref={scrollRef}\n style={{ ...styles, ...sizeStyle, overflow: \"auto\" }}\n >\n {/* data */}\n <OnChangePlugin onChange={handleOnChange} />\n {value && <LexicalUpdateStatePlugin value={value} />}\n <ClearEditorPlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Events */}\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 </>\n </LexicalComposer>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeComposable<RichTextEditorProps>(\"RichTextEditor\", props => {\n return (\n <LexicalEditorWithConfig>\n <RichTextEditorProvider>\n <ClassNames>\n {({ css }) => {\n const themeEmotionMap =\n props?.themeEmotionMap ?? toTypographyEmotionMap(css, props.theme);\n return (\n <SharedHistoryContext>\n <BaseRichTextEditor {...props} themeEmotionMap={themeEmotionMap} />\n </SharedHistoryContext>\n );\n }}\n </ClassNames>\n </RichTextEditorProvider>\n </LexicalEditorWithConfig>\n );\n});\n"],"mappings":";;;;;;;;;;;AAAA;AAEA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA6CA,IAAMA,kBAAiD,GAAG,SAApDA,kBAAiD,OAkB5B;EAAA,IA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K,aAALA,KAAK,uBAALA,KAAK,CAAErD,eAAe,yEAAI,IAAAuD,8CAAsB,EAACD,GAAG,EAAED,KAAK,CAACtD,KAAK,CAAC;IACtE,oBACI,6BAAC,0CAAoB,qBACjB,6BAAC,kBAAkB,oBAAKsD,KAAK;MAAE,eAAe,EAAErD;IAAgB,GAAG,CAChD;EAE/B,CAAC,CACQ,CACQ,CACH;AAElC,CAAC,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_react2","_LexicalComposer","_LexicalOnChangePlugin","_LexicalAutoFocusPlugin","_LexicalClearEditorPlugin","_LexicalRichTextPlugin","_LexicalErrorBoundary","_interopRequireDefault","_reactComposition","_LexicalHistoryPlugin","_LexicalContentEditable","_RichTextEditorContext","_isValidLexicalData","_LexicalUpdateStatePlugin","_BlurEventPlugin","_Placeholder","_generateInitialLexicalValue","_lexicalTheme","_lexicalNodes","_SharedHistoryContext","_useRichTextEditor2","_LexicalEditorConfig","BaseRichTextEditor","_ref","toolbar","staticToolbar","onChange","value","nodes","placeholder","children","onBlur","focus","styles","width","height","theme","themeEmotionMap","toolbarActionPlugins","contentEditableStyles","placeholderStyles","editorTheme","useRef","createTheme","config","useLexicalEditorConfig","_useSharedHistoryCont","useSharedHistoryContext","historyState","placeholderElem","default","createElement","Placeholder","scrollRef","_useState","useState","undefined","_useState2","_slicedToArray2","floatingAnchorElem","setFloatingAnchorElem","_useRichTextEditor","useRichTextEditor","setTheme","setThemeEmotionMap","setToolbarActionPlugins","useEffect","onRef","_floatingAnchorElem","sizeStyle","configNodes","map","node","configPlugins","plugins","plugin","Fragment","key","name","element","editorValue","isValidLexicalData","generateInitialLexicalValue","initialConfig","editorState","namespace","onError","concat","_toConsumableArray2","allNodes","_objectSpread2","current","emotionMap","handleOnChange","editor","read","getEditorState","JSON","stringify","toJSON","LexicalComposer","length","className","ref","style","overflow","position","OnChangePlugin","UpdateStatePlugin","ClearEditorPlugin","HistoryPlugin","externalHistoryState","BlurEventPlugin","AutoFocusPlugin","RichTextPlugin","contentEditable","ContentEditable","outline","ErrorBoundary","LexicalErrorBoundary","RichTextEditor","makeComposable","props","LexicalEditorWithConfig","RichTextEditorProvider","ClassNames","_ref2","css","toTypographyEmotionMap","themeStylesTransformer","SharedHistoryContext","Object","assign","exports"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { Fragment, useEffect, useRef, useState } from \"react\";\nimport { ClassNames, CSSObject } from \"@emotion/react\";\nimport { Klass, LexicalEditor, LexicalNode } from \"lexical\";\nimport { EditorState } from \"lexical/LexicalEditorState\";\nimport { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { OnChangePlugin } from \"@lexical/react/LexicalOnChangePlugin\";\nimport { AutoFocusPlugin } from \"@lexical/react/LexicalAutoFocusPlugin\";\nimport { ClearEditorPlugin } from \"@lexical/react/LexicalClearEditorPlugin\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport LexicalErrorBoundary from \"@lexical/react/LexicalErrorBoundary\";\nimport { makeComposable } from \"@webiny/react-composition\";\nimport { HistoryPlugin } from \"@lexical/react/LexicalHistoryPlugin\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport { RichTextEditorProvider } from \"~/context/RichTextEditorContext\";\nimport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nimport { UpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\nimport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nimport { LexicalValue, ToolbarActionPlugin } from \"~/types\";\nimport { Placeholder } from \"~/ui/Placeholder\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport {\n createTheme,\n WebinyTheme,\n ThemeEmotionMap,\n toTypographyEmotionMap\n} from \"@webiny/lexical-theme\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport {\n LexicalEditorWithConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig\";\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: WebinyTheme;\n themeEmotionMap?: ThemeEmotionMap;\n themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;\n toolbar?: React.ReactNode;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n value: LexicalValue | null;\n width?: number | string;\n}\n\nconst BaseRichTextEditor = ({\n toolbar,\n staticToolbar,\n onChange,\n value,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n styles,\n width,\n height,\n theme,\n themeEmotionMap,\n toolbarActionPlugins,\n contentEditableStyles,\n placeholderStyles\n}: RichTextEditorProps) => {\n const editorTheme = useRef(createTheme());\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 { setTheme, setThemeEmotionMap, setToolbarActionPlugins } = useRichTextEditor();\n\n useEffect(() => {\n setTheme(theme);\n setThemeEmotionMap(themeEmotionMap);\n }, [themeEmotionMap, theme]);\n\n useEffect(() => {\n if (toolbarActionPlugins) {\n setToolbarActionPlugins(toolbarActionPlugins || []);\n }\n }, [toolbarActionPlugins]);\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 editorValue = isValidLexicalData(value) ? value : generateInitialLexicalValue();\n\n const initialConfig = {\n // We update the state via the `<LexicalUpdateStatePlugin/>`.\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 function handleOnChange(editorState: EditorState, editor: LexicalEditor) {\n editorState.read(() => {\n if (typeof onChange === \"function\") {\n const editorState = editor.getEditorState();\n onChange(JSON.stringify(editorState.toJSON()));\n }\n });\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 <LexicalComposer initialConfig={initialConfig} key={initialConfig.nodes.length}>\n <>\n {staticToolbar && staticToolbar}\n <div\n /* This className is necessary for targeting of editor container from CSS files. */\n className={\"editor-shell\"}\n ref={scrollRef}\n style={{ ...styles, ...sizeStyle, overflow: \"auto\", position: \"relative\" }}\n >\n {/* data */}\n <OnChangePlugin onChange={handleOnChange} />\n <UpdateStatePlugin value={editorValue} />\n <ClearEditorPlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Events */}\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 </>\n </LexicalComposer>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeComposable<RichTextEditorProps>(\"RichTextEditor\", props => {\n return (\n <LexicalEditorWithConfig>\n <RichTextEditorProvider>\n <ClassNames>\n {({ css }) => {\n const themeEmotionMap =\n props?.themeEmotionMap ??\n toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);\n return (\n <SharedHistoryContext>\n <BaseRichTextEditor {...props} themeEmotionMap={themeEmotionMap} />\n </SharedHistoryContext>\n );\n }}\n </ClassNames>\n </RichTextEditorProvider>\n </LexicalEditorWithConfig>\n );\n});\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAGA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,uBAAA,GAAAJ,OAAA;AACA,IAAAK,yBAAA,GAAAL,OAAA;AACA,IAAAM,sBAAA,GAAAN,OAAA;AACA,IAAAO,qBAAA,GAAAC,sBAAA,CAAAR,OAAA;AACA,IAAAS,iBAAA,GAAAT,OAAA;AACA,IAAAU,qBAAA,GAAAV,OAAA;AACA,IAAAW,uBAAA,GAAAX,OAAA;AACA,IAAAY,sBAAA,GAAAZ,OAAA;AACA,IAAAa,mBAAA,GAAAb,OAAA;AACA,IAAAc,yBAAA,GAAAd,OAAA;AACA,IAAAe,gBAAA,GAAAf,OAAA;AAEA,IAAAgB,YAAA,GAAAhB,OAAA;AACA,IAAAiB,4BAAA,GAAAjB,OAAA;AACA,IAAAkB,aAAA,GAAAlB,OAAA;AAMA,IAAAmB,aAAA,GAAAnB,OAAA;AACA,IAAAoB,qBAAA,GAAApB,OAAA;AACA,IAAAqB,mBAA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ACgG,OAAA,CAAAb,cAAA,GAAAA,cAAA"}
|
|
@@ -6,9 +6,9 @@ export declare const LexicalEditorConfig: {
|
|
|
6
6
|
({ children }: {
|
|
7
7
|
children: React.ReactNode;
|
|
8
8
|
}): JSX.Element;
|
|
9
|
-
ToolbarElement:
|
|
10
|
-
Plugin:
|
|
11
|
-
Node:
|
|
9
|
+
ToolbarElement: ({ name, element, after, before, remove }: import("./components/ToolbarElement").ToolbarElementProps) => JSX.Element;
|
|
10
|
+
Plugin: ({ name, element, after, before, remove }: import("./components/Plugin").PluginProps) => JSX.Element;
|
|
11
|
+
Node: ({ name, node, after, before, remove }: import("./components/Node").NodeProps) => JSX.Element;
|
|
12
12
|
};
|
|
13
13
|
export declare const LexicalEditorWithConfig: ({ children }: {
|
|
14
14
|
children: React.ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LexicalEditorConfigApply","makeComposable","children","createHOC","newChildren","BaseComponent","ConfigHOC","LexicalEditorConfig","ToolbarElement","Plugin","Node","ViewContext","React","createContext","properties","LexicalEditorWithConfig","useState","setProperties","context","stateUpdater","useLexicalEditorConfig","useContext","config","useMemo","toObject","toolbarElements","plugins","nodes"],"sources":["LexicalEditorConfig.tsx"],"sourcesContent":["import React, { useContext, useMemo, useState } from \"react\";\nimport { makeComposable, Compose, HigherOrderComponent } from \"@webiny/react-composition\";\nimport { Property, Properties, toObject } from \"@webiny/react-properties\";\nimport { ToolbarElement, ToolbarElementConfig } from \"./components/ToolbarElement\";\nimport { Plugin, PluginConfig } from \"./components/Plugin\";\nimport { Node, NodeConfig } from \"./components/Node\";\n\nconst LexicalEditorConfigApply = makeComposable(\"LexicalEditorConfigApply\", ({ children }) => {\n return <>{children}</>;\n});\n\nconst createHOC =\n (newChildren: React.ReactNode): HigherOrderComponent =>\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;AACA;AACA;AACA;AACA;AACA;AAEA,
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactComposition","_reactProperties","_ToolbarElement","_Plugin","_Node","LexicalEditorConfigApply","makeComposable","_ref","children","default","createElement","Fragment","createHOC","newChildren","BaseComponent","ConfigHOC","_ref2","LexicalEditorConfig","_ref3","Compose","component","with","exports","ToolbarElement","Plugin","Node","ViewContext","React","createContext","properties","LexicalEditorWithConfig","_ref4","_useState","useState","_useState2","_slicedToArray2","setProperties","context","stateUpdater","Provider","value","Properties","onChange","useLexicalEditorConfig","_useContext","useContext","config","useMemo","toObject","toolbarElements","plugins","nodes"],"sources":["LexicalEditorConfig.tsx"],"sourcesContent":["import React, { useContext, useMemo, useState } from \"react\";\nimport { makeComposable, Compose, HigherOrderComponent } from \"@webiny/react-composition\";\nimport { Property, Properties, toObject } from \"@webiny/react-properties\";\nimport { ToolbarElement, ToolbarElementConfig } from \"./components/ToolbarElement\";\nimport { Plugin, PluginConfig } from \"./components/Plugin\";\nimport { Node, NodeConfig } from \"./components/Node\";\n\nconst LexicalEditorConfigApply = makeComposable(\"LexicalEditorConfigApply\", ({ children }) => {\n return <>{children}</>;\n});\n\nconst createHOC =\n (newChildren: React.ReactNode): HigherOrderComponent =>\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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAC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ACL"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { Klass, LexicalNode } from "lexical";
|
|
3
3
|
export interface NodeConfig {
|
|
4
4
|
name: string;
|
|
@@ -11,4 +11,4 @@ export interface NodeProps {
|
|
|
11
11
|
before?: string;
|
|
12
12
|
after?: string;
|
|
13
13
|
}
|
|
14
|
-
export declare const Node:
|
|
14
|
+
export declare const Node: ({ name, node, after, before, remove }: NodeProps) => JSX.Element;
|