@webiny/lexical-editor 5.37.8 → 5.38.0-beta.1
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.js +3 -1
- package/components/Editor/ParagraphEditor.js +3 -1
- package/components/Editor/RichTextEditor.d.ts +2 -2
- package/components/Editor/RichTextEditor.js +19 -12
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +3 -1
- package/components/LexicalEditorConfig/components/Node.js +3 -1
- package/components/LexicalEditorConfig/components/Plugin.js +3 -1
- package/components/LexicalEditorConfig/components/ToolbarElement.js +3 -1
- package/components/LexicalHtmlRenderer.d.ts +2 -2
- package/components/LexicalHtmlRenderer.js +24 -17
- 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 -1
- package/components/Toolbar/Toolbar.js +27 -80
- 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 -23
- 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.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 +6 -4
- 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 -27
- 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.js +27 -21
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
- 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/RichTextEditorContext.d.ts +2 -6
- package/context/RichTextEditorContext.js +20 -36
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/SharedHistoryContext.js +3 -1
- package/context/TextAlignmentActionContextProps.js +3 -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/useIsMounted.d.ts +1 -0
- package/hooks/useIsMounted.js +20 -0
- package/hooks/useIsMounted.js.map +1 -0
- package/hooks/useList.js +22 -21
- 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/useTextAlignmentAction.js +3 -1
- package/hooks/useTypographyAction.js +3 -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/CodeHighlightPlugin/CodeHighlightPlugin.js +3 -1
- package/plugins/CodeHighlightPlugin/index.js +3 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +11 -9
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js +3 -1
- package/plugins/FontColorPlugin/FontColorPlugin.js +8 -7
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/ImagesPlugin/ImagesPlugin.d.ts +1 -1
- package/plugins/ImagesPlugin/ImagesPlugin.js +11 -9
- package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.d.ts +9 -0
- package/plugins/LexicalUpdateStatePlugin/{LexicalUpdateStatePlugin.js → UpdateStatePlugin.js} +22 -14
- 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.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 +1 -60
- package/types.js +5 -3
- package/types.js.map +1 -1
- package/ui/ContentEditable.js +3 -1
- package/ui/Divider.js +3 -1
- package/ui/DropDown.js +3 -1
- package/ui/ImageResizer.js +3 -1
- package/ui/LinkPreview.js +3 -1
- package/ui/Placeholder.js +3 -1
- package/ui/TextInput.js +3 -1
- package/ui/ToolbarActionDialog.js +3 -1
- package/utils/canUseDOM.js +3 -1
- package/utils/files.d.ts +1 -1
- package/utils/files.js +3 -1
- package/utils/files.js.map +1 -1
- package/utils/generateInitialLexicalValue.js +3 -1
- package/utils/getDOMRangeRect.js +3 -1
- package/utils/getSelectedNode.js +3 -1
- package/utils/getTransparentImage.js +3 -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.js +3 -1
- package/utils/isUrlLinkReference.js +3 -1
- package/utils/isValidJSON.js +3 -1
- package/utils/isValidLexicalData.js +3 -1
- package/utils/point.js +3 -1
- package/utils/rect.js +3 -1
- package/utils/sanitizeUrl.js +3 -1
- package/utils/setFloatingElemPosition.js +3 -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 -123
- package/nodes/FontColorNode.js.map +0 -1
- package/nodes/HeadingNode.d.ts +0 -34
- package/nodes/HeadingNode.js +0 -191
- package/nodes/HeadingNode.js.map +0 -1
- package/nodes/ImageNode.d.ts +0 -50
- package/nodes/ImageNode.js +0 -206
- package/nodes/ImageNode.js.map +0 -1
- package/nodes/ListItemNode.d.ts +0 -46
- package/nodes/ListItemNode.js +0 -447
- package/nodes/ListItemNode.js.map +0 -1
- package/nodes/ListNode/formatList.d.ts +0 -19
- package/nodes/ListNode/formatList.js +0 -447
- package/nodes/ListNode/formatList.js.map +0 -1
- package/nodes/ListNode.d.ts +0 -42
- package/nodes/ListNode.js +0 -288
- 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 -151
- package/nodes/TypographyElementNode.js.map +0 -1
- package/nodes/imageNode.css +0 -43
- package/nodes/link-node.d.ts +0 -19
- package/nodes/link-node.js +0 -120
- package/nodes/link-node.js.map +0 -1
- 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 -60
- package/nodes/webinyNodes.js.map +0 -1
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.d.ts +0 -8
- 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 -167
- 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 -41
- 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"}
|
|
@@ -24,4 +24,6 @@ var ParagraphEditor = function ParagraphEditor(_ref) {
|
|
|
24
24
|
}
|
|
25
25
|
}), rest === null || rest === void 0 ? void 0 : rest.children);
|
|
26
26
|
};
|
|
27
|
-
exports.ParagraphEditor = ParagraphEditor;
|
|
27
|
+
exports.ParagraphEditor = ParagraphEditor;
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=ParagraphEditor.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { CSSObject } from "@emotion/react";
|
|
3
3
|
import { Klass, LexicalNode } from "lexical";
|
|
4
|
-
import { LexicalValue,
|
|
5
|
-
import { WebinyTheme } from "
|
|
4
|
+
import { LexicalValue, ToolbarActionPlugin } from "../../types";
|
|
5
|
+
import { WebinyTheme, ThemeEmotionMap } from "@webiny/lexical-theme";
|
|
6
6
|
export interface RichTextEditorProps {
|
|
7
7
|
children?: React.ReactNode | React.ReactNode[];
|
|
8
8
|
classes?: string;
|
|
@@ -26,11 +26,10 @@ var _LexicalUpdateStatePlugin = require("../../plugins/LexicalUpdateStatePlugin"
|
|
|
26
26
|
var _BlurEventPlugin = require("../../plugins/BlurEventPlugin/BlurEventPlugin");
|
|
27
27
|
var _Placeholder = require("../../ui/Placeholder");
|
|
28
28
|
var _generateInitialLexicalValue = require("../../utils/generateInitialLexicalValue");
|
|
29
|
-
var
|
|
30
|
-
var
|
|
29
|
+
var _lexicalTheme = require("@webiny/lexical-theme");
|
|
30
|
+
var _lexicalNodes = require("@webiny/lexical-nodes");
|
|
31
31
|
var _SharedHistoryContext = require("../../context/SharedHistoryContext");
|
|
32
32
|
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
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
|
};
|
|
@@ -123,6 +126,8 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
|
|
|
123
126
|
initialConfig: initialConfig,
|
|
124
127
|
key: initialConfig.nodes.length
|
|
125
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",
|
|
126
131
|
ref: scrollRef,
|
|
127
132
|
style: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, styles), sizeStyle), {}, {
|
|
128
133
|
overflow: "auto",
|
|
@@ -130,8 +135,8 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
|
|
|
130
135
|
})
|
|
131
136
|
}, /*#__PURE__*/_react.default.createElement(_LexicalOnChangePlugin.OnChangePlugin, {
|
|
132
137
|
onChange: handleOnChange
|
|
133
|
-
}),
|
|
134
|
-
value:
|
|
138
|
+
}), /*#__PURE__*/_react.default.createElement(_LexicalUpdateStatePlugin.UpdateStatePlugin, {
|
|
139
|
+
value: editorValue
|
|
135
140
|
}), /*#__PURE__*/_react.default.createElement(_LexicalClearEditorPlugin.ClearEditorPlugin, null), /*#__PURE__*/_react.default.createElement(_LexicalHistoryPlugin.HistoryPlugin, {
|
|
136
141
|
externalHistoryState: historyState
|
|
137
142
|
}), onBlur && /*#__PURE__*/_react.default.createElement(_BlurEventPlugin.BlurEventPlugin, {
|
|
@@ -161,10 +166,12 @@ var RichTextEditor = (0, _reactComposition.makeComposable)("RichTextEditor", fun
|
|
|
161
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) {
|
|
162
167
|
var _props$themeEmotionMa;
|
|
163
168
|
var css = _ref2.css;
|
|
164
|
-
var themeEmotionMap = (_props$themeEmotionMa = props === null || props === void 0 ? void 0 : props.themeEmotionMap) !== null && _props$themeEmotionMa !== void 0 ? _props$themeEmotionMa : (0,
|
|
169
|
+
var themeEmotionMap = (_props$themeEmotionMa = props === null || props === void 0 ? void 0 : props.themeEmotionMap) !== null && _props$themeEmotionMa !== void 0 ? _props$themeEmotionMa : (0, _lexicalTheme.toTypographyEmotionMap)(css, props.theme, props.themeStylesTransformer);
|
|
165
170
|
return /*#__PURE__*/_react.default.createElement(_SharedHistoryContext.SharedHistoryContext, null, /*#__PURE__*/_react.default.createElement(BaseRichTextEditor, Object.assign({}, props, {
|
|
166
171
|
themeEmotionMap: themeEmotionMap
|
|
167
172
|
})));
|
|
168
173
|
})));
|
|
169
174
|
});
|
|
170
|
-
exports.RichTextEditor = RichTextEditor;
|
|
175
|
+
exports.RichTextEditor = RichTextEditor;
|
|
176
|
+
|
|
177
|
+
//# sourceMappingURL=RichTextEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_react2","_LexicalComposer","_LexicalOnChangePlugin","_LexicalAutoFocusPlugin","_LexicalClearEditorPlugin","_LexicalRichTextPlugin","_LexicalErrorBoundary","_interopRequireDefault","_reactComposition","_LexicalHistoryPlugin","_LexicalContentEditable","_RichTextEditorContext","_isValidLexicalData","_LexicalUpdateStatePlugin","_BlurEventPlugin","_Placeholder","_generateInitialLexicalValue","_webinyLexicalTheme","_webinyNodes","_SharedHistoryContext","_useRichTextEditor2","_toTypographyEmotionMap","_LexicalEditorConfig","BaseRichTextEditor","_ref","toolbar","staticToolbar","onChange","value","nodes","placeholder","children","onBlur","focus","styles","width","height","theme","themeEmotionMap","toolbarActionPlugins","contentEditableStyles","placeholderStyles","config","useLexicalEditorConfig","_useSharedHistoryCont","useSharedHistoryContext","historyState","placeholderElem","default","createElement","Placeholder","scrollRef","useRef","_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","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","concat","_toConsumableArray2","WebinyNodes","_objectSpread2","webinyEditorTheme","emotionMap","handleOnChange","editor","read","getEditorState","JSON","stringify","toJSON","LexicalComposer","length","ref","style","overflow","position","OnChangePlugin","LexicalUpdateStatePlugin","ClearEditorPlugin","HistoryPlugin","externalHistoryState","BlurEventPlugin","AutoFocusPlugin","RichTextPlugin","contentEditable","className","ContentEditable","outline","ErrorBoundary","LexicalErrorBoundary","RichTextEditor","makeComposable","props","LexicalEditorWithConfig","RichTextEditorProvider","ClassNames","_ref2","_props$themeEmotionMa","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 { LexicalUpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\nimport { BlurEventPlugin } from \"~/plugins/BlurEventPlugin/BlurEventPlugin\";\nimport { LexicalValue, ThemeEmotionMap, ToolbarActionPlugin } from \"~/types\";\nimport { Placeholder } from \"~/ui/Placeholder\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\nimport { SharedHistoryContext, useSharedHistoryContext } from \"~/context/SharedHistoryContext\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { toTypographyEmotionMap } from \"~/utils/toTypographyEmotionMap\";\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: 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 /**\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 ref={scrollRef}\n style={{ ...styles, ...sizeStyle, overflow: \"auto\", position: \"relative\" }}\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 ??\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":";;;;;;;;;;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,CAAAmD,OAAA,CAAAC,aAAA,CAACtC,sBAAA,CAAAgH,sBAAsB,qBACnB9H,MAAA,CAAAmD,OAAA,CAAAC,aAAA,CAACjD,OAAA,CAAA4H,UAAU,QACN,UAAAC,KAAA,EAAa;IAAA,IAAAC,qBAAA;IAAA,IAAVC,GAAG,GAAAF,KAAA,CAAHE,GAAG;IACH,IAAMzF,eAAe,IAAAwF,qBAAA,GACjBL,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEnF,eAAe,cAAAwF,qBAAA,cAAAA,qBAAA,GACtB,IAAAE,8CAAsB,EAACD,GAAG,EAAEN,KAAK,CAACpF,KAAK,EAAEoF,KAAK,CAACQ,sBAAsB,CAAC;IAC1E,oBACIpI,MAAA,CAAAmD,OAAA,CAAAC,aAAA,CAAC9B,qBAAA,CAAA+G,oBAAoB,qBACjBrI,MAAA,CAAAmD,OAAA,CAAAC,aAAA,CAAC1B,kBAAkB,EAAA4G,MAAA,CAAAC,MAAA,KAAKX,KAAK;MAAEnF,eAAe,EAAEA;IAAgB,EAAE,CAChD,CAAC;EAE/B,CACQ,CACQ,CACH,CAAC;AAElC,CAAC,CAAC;AAAC+F,OAAA,CAAAd,cAAA,GAAAA,cAAA"}
|
|
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","_props$themeEmotionMa","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: 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 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,IAAA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AA,CAACnD,OAAA,CAAA6H,UAAU,QACN,UAAAC,KAAA,EAAa;IAAA,IAAAC,qBAAA;IAAA,IAAVC,GAAG,GAAAF,KAAA,CAAHE,GAAG;IACH,IAAM3F,eAAe,IAAA0F,qBAAA,GACjBL,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAErF,eAAe,cAAA0F,qBAAA,cAAAA,qBAAA,GACtB,IAAAE,oCAAsB,EAACD,GAAG,EAAEN,KAAK,CAACtF,KAAK,EAAEsF,KAAK,CAACQ,sBAAsB,CAAC;IAC1E,oBACIrI,MAAA,CAAAqD,OAAA,CAAAC,aAAA,CAAChC,qBAAA,CAAAgH,oBAAoB,qBACjBtI,MAAA,CAAAqD,OAAA,CAAAC,aAAA,CAAC7B,kBAAkB,EAAA8G,MAAA,CAAAC,MAAA,KAAKX,KAAK;MAAErF,eAAe,EAAEA;IAAgB,EAAE,CAChD,CAAC;EAE/B,CACQ,CACQ,CACH,CAAC;AAElC,CAAC,CAAC;AAACiG,OAAA,CAAAd,cAAA,GAAAA,cAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { LexicalValue, ThemeEmotionMap } from "../types";
|
|
3
2
|
import { Klass, LexicalNode } from "lexical";
|
|
4
|
-
import { WebinyTheme } from "../themes/webinyLexicalTheme";
|
|
5
3
|
import { CSSObject } from "@emotion/react";
|
|
4
|
+
import { WebinyTheme, ThemeEmotionMap } from "@webiny/lexical-theme";
|
|
5
|
+
import { LexicalValue } from "../types";
|
|
6
6
|
interface LexicalHtmlRendererProps {
|
|
7
7
|
nodes?: Klass<LexicalNode>[];
|
|
8
8
|
value: LexicalValue | null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
3
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
@@ -7,46 +8,50 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
8
|
exports.LexicalHtmlRenderer = exports.BaseLexicalHtmlRenderer = void 0;
|
|
8
9
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
-
var _react =
|
|
11
|
-
var
|
|
12
|
-
var _generateInitialLexicalValue = require("../utils/generateInitialLexicalValue");
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _react2 = require("@emotion/react");
|
|
13
13
|
var _LexicalComposer = require("@lexical/react/LexicalComposer");
|
|
14
14
|
var _LexicalRichTextPlugin = require("@lexical/react/LexicalRichTextPlugin");
|
|
15
15
|
var _LexicalContentEditable = require("@lexical/react/LexicalContentEditable");
|
|
16
16
|
var _LexicalErrorBoundary = _interopRequireDefault(require("@lexical/react/LexicalErrorBoundary"));
|
|
17
|
+
var _lexicalNodes = require("@webiny/lexical-nodes");
|
|
18
|
+
var _lexicalTheme = require("@webiny/lexical-theme");
|
|
19
|
+
var _isValidLexicalData = require("../utils/isValidLexicalData");
|
|
20
|
+
var _generateInitialLexicalValue = require("../utils/generateInitialLexicalValue");
|
|
17
21
|
var _LexicalUpdateStatePlugin = require("../plugins/LexicalUpdateStatePlugin");
|
|
18
|
-
var _webinyNodes = require("../nodes/webinyNodes");
|
|
19
|
-
var _webinyLexicalTheme = require("../themes/webinyLexicalTheme");
|
|
20
|
-
var _react2 = require("@emotion/react");
|
|
21
|
-
var _toTypographyEmotionMap = require("../utils/toTypographyEmotionMap");
|
|
22
22
|
var BaseLexicalHtmlRenderer = function BaseLexicalHtmlRenderer(_ref) {
|
|
23
23
|
var nodes = _ref.nodes,
|
|
24
24
|
value = _ref.value,
|
|
25
25
|
theme = _ref.theme,
|
|
26
26
|
themeEmotionMap = _ref.themeEmotionMap;
|
|
27
|
+
var editorTheme = (0, _react.useRef)((0, _lexicalTheme.createTheme)());
|
|
28
|
+
var editorValue = (0, _isValidLexicalData.isValidLexicalData)(value) ? value : (0, _generateInitialLexicalValue.generateInitialLexicalValue)();
|
|
27
29
|
var initialConfig = {
|
|
28
|
-
|
|
30
|
+
// We update the state via the `<LexicalUpdateStatePlugin/>`.
|
|
31
|
+
editorState: null,
|
|
29
32
|
namespace: "webiny",
|
|
30
|
-
onError: function onError(
|
|
31
|
-
|
|
33
|
+
onError: function onError() {
|
|
34
|
+
// Ignore errors. We don't want to break the app because of errors caused by config/value updates.
|
|
35
|
+
// These are usually resolved in the next component render cycle.
|
|
32
36
|
},
|
|
33
37
|
editable: false,
|
|
34
|
-
nodes: [].concat((0, _toConsumableArray2.default)(
|
|
35
|
-
theme: (0, _objectSpread2.default)((0, _objectSpread2.default)({},
|
|
38
|
+
nodes: [].concat((0, _toConsumableArray2.default)(_lexicalNodes.allNodes), (0, _toConsumableArray2.default)(nodes || [])),
|
|
39
|
+
theme: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, editorTheme.current), {}, {
|
|
36
40
|
emotionMap: themeEmotionMap,
|
|
37
41
|
styles: theme.styles
|
|
38
42
|
})
|
|
39
43
|
};
|
|
40
44
|
return /*#__PURE__*/_react.default.createElement(_LexicalComposer.LexicalComposer, {
|
|
41
|
-
initialConfig: initialConfig
|
|
45
|
+
initialConfig: initialConfig,
|
|
46
|
+
key: initialConfig.nodes.length
|
|
42
47
|
}, /*#__PURE__*/_react.default.createElement(_LexicalRichTextPlugin.RichTextPlugin, {
|
|
43
48
|
contentEditable: /*#__PURE__*/_react.default.createElement("div", {
|
|
44
49
|
className: "editor"
|
|
45
50
|
}, /*#__PURE__*/_react.default.createElement(_LexicalContentEditable.ContentEditable, null)),
|
|
46
51
|
ErrorBoundary: _LexicalErrorBoundary.default,
|
|
47
52
|
placeholder: null
|
|
48
|
-
}), /*#__PURE__*/_react.default.createElement(_LexicalUpdateStatePlugin.
|
|
49
|
-
value:
|
|
53
|
+
}), /*#__PURE__*/_react.default.createElement(_LexicalUpdateStatePlugin.UpdateStatePlugin, {
|
|
54
|
+
value: editorValue
|
|
50
55
|
}));
|
|
51
56
|
};
|
|
52
57
|
|
|
@@ -58,10 +63,12 @@ var LexicalHtmlRenderer = function LexicalHtmlRenderer(props) {
|
|
|
58
63
|
return /*#__PURE__*/_react.default.createElement(_react2.ClassNames, null, function (_ref2) {
|
|
59
64
|
var _props$themeEmotionMa;
|
|
60
65
|
var css = _ref2.css;
|
|
61
|
-
var themeEmotionMap = (_props$themeEmotionMa = props === null || props === void 0 ? void 0 : props.themeEmotionMap) !== null && _props$themeEmotionMa !== void 0 ? _props$themeEmotionMa : (0,
|
|
66
|
+
var themeEmotionMap = (_props$themeEmotionMa = props === null || props === void 0 ? void 0 : props.themeEmotionMap) !== null && _props$themeEmotionMa !== void 0 ? _props$themeEmotionMa : (0, _lexicalTheme.toTypographyEmotionMap)(css, props.theme, props.themeStylesTransformer);
|
|
62
67
|
return /*#__PURE__*/_react.default.createElement(BaseLexicalHtmlRenderer, Object.assign({}, props, {
|
|
63
68
|
themeEmotionMap: themeEmotionMap
|
|
64
69
|
}));
|
|
65
70
|
});
|
|
66
71
|
};
|
|
67
|
-
exports.LexicalHtmlRenderer = LexicalHtmlRenderer;
|
|
72
|
+
exports.LexicalHtmlRenderer = LexicalHtmlRenderer;
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=LexicalHtmlRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_react2","_LexicalComposer","_LexicalRichTextPlugin","_LexicalContentEditable","_LexicalErrorBoundary","_interopRequireDefault","_lexicalNodes","_lexicalTheme","_isValidLexicalData","_generateInitialLexicalValue","_LexicalUpdateStatePlugin","BaseLexicalHtmlRenderer","_ref","nodes","value","theme","themeEmotionMap","editorTheme","useRef","createTheme","editorValue","isValidLexicalData","generateInitialLexicalValue","initialConfig","editorState","namespace","onError","editable","concat","_toConsumableArray2","default","allNodes","_objectSpread2","current","emotionMap","styles","createElement","LexicalComposer","key","length","RichTextPlugin","contentEditable","className","ContentEditable","ErrorBoundary","LexicalErrorBoundary","placeholder","UpdateStatePlugin","exports","LexicalHtmlRenderer","props","ClassNames","_ref2","_props$themeEmotionMa","css","toTypographyEmotionMap","themeStylesTransformer","Object","assign"],"sources":["LexicalHtmlRenderer.tsx"],"sourcesContent":["import React, { useRef } from \"react\";\nimport { Klass, LexicalNode } from \"lexical\";\nimport { ClassNames, CSSObject } from \"@emotion/react\";\nimport { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport LexicalErrorBoundary from \"@lexical/react/LexicalErrorBoundary\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport {\n createTheme,\n WebinyTheme,\n ThemeEmotionMap,\n toTypographyEmotionMap\n} from \"@webiny/lexical-theme\";\nimport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { LexicalValue } from \"~/types\";\nimport { UpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\n\ninterface LexicalHtmlRendererProps {\n nodes?: Klass<LexicalNode>[];\n value: LexicalValue | null;\n theme: WebinyTheme;\n themeEmotionMap?: ThemeEmotionMap;\n themeStylesTransformer?: (cssObject: Record<string, any>) => CSSObject;\n}\n\nexport const BaseLexicalHtmlRenderer: React.FC<LexicalHtmlRendererProps> = ({\n nodes,\n value,\n theme,\n themeEmotionMap\n}) => {\n const editorTheme = useRef(createTheme());\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 editable: false,\n nodes: [...allNodes, ...(nodes || [])],\n theme: { ...editorTheme.current, emotionMap: themeEmotionMap, styles: theme.styles }\n };\n\n return (\n <LexicalComposer initialConfig={initialConfig} key={initialConfig.nodes.length}>\n <RichTextPlugin\n contentEditable={\n <div className=\"editor\">\n <ContentEditable />\n </div>\n }\n ErrorBoundary={LexicalErrorBoundary}\n placeholder={null}\n />\n <UpdateStatePlugin value={editorValue} />\n </LexicalComposer>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const LexicalHtmlRenderer: React.FC<LexicalHtmlRendererProps> = props => {\n return (\n <ClassNames>\n {({ css }) => {\n const themeEmotionMap =\n props?.themeEmotionMap ??\n toTypographyEmotionMap(css, props.theme, props.themeStylesTransformer);\n return <BaseLexicalHtmlRenderer {...props} themeEmotionMap={themeEmotionMap} />;\n }}\n </ClassNames>\n );\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,uBAAA,GAAAJ,OAAA;AACA,IAAAK,qBAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AAMA,IAAAS,mBAAA,GAAAT,OAAA;AACA,IAAAU,4BAAA,GAAAV,OAAA;AAEA,IAAAW,yBAAA,GAAAX,OAAA;AAUO,IAAMY,uBAA2D,GAAG,SAA9DA,uBAA2DA,CAAAC,IAAA,EAKlE;EAAA,IAJFC,KAAK,GAAAD,IAAA,CAALC,KAAK;IACLC,KAAK,GAAAF,IAAA,CAALE,KAAK;IACLC,KAAK,GAAAH,IAAA,CAALG,KAAK;IACLC,eAAe,GAAAJ,IAAA,CAAfI,eAAe;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AE1B,CAAC;;AAED;AACA;AACA;AAFA4B,OAAA,CAAArC,uBAAA,GAAAA,uBAAA;AAGO,IAAMsC,mBAAuD,GAAG,SAA1DA,mBAAuDA,CAAGC,KAAK,EAAI;EAC5E,oBACIrD,MAAA,CAAAiC,OAAA,CAAAM,aAAA,CAACpC,OAAA,CAAAmD,UAAU,QACN,UAAAC,KAAA,EAAa;IAAA,IAAAC,qBAAA;IAAA,IAAVC,GAAG,GAAAF,KAAA,CAAHE,GAAG;IACH,IAAMtC,eAAe,IAAAqC,qBAAA,GACjBH,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAElC,eAAe,cAAAqC,qBAAA,cAAAA,qBAAA,GACtB,IAAAE,oCAAsB,EAACD,GAAG,EAAEJ,KAAK,CAACnC,KAAK,EAAEmC,KAAK,CAACM,sBAAsB,CAAC;IAC1E,oBAAO3D,MAAA,CAAAiC,OAAA,CAAAM,aAAA,CAACzB,uBAAuB,EAAA8C,MAAA,CAAAC,MAAA,KAAKR,KAAK;MAAElC,eAAe,EAAEA;IAAgB,EAAE,CAAC;EACnF,CACQ,CAAC;AAErB,CAAC;AAACgC,OAAA,CAAAC,mBAAA,GAAAA,mBAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import "./StaticToolbar.css";
|
|
3
|
-
export declare const StaticToolbar: () =>
|
|
3
|
+
export declare const StaticToolbar: () => JSX.Element;
|
|
@@ -8,80 +8,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.StaticToolbar = void 0;
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
var _lexical = require("lexical");
|
|
12
|
-
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
13
|
-
var _utils = require("@lexical/utils");
|
|
14
11
|
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
15
12
|
require("./StaticToolbar.css");
|
|
16
|
-
var _getLexicalTextSelectionState = require("../../utils/getLexicalTextSelectionState");
|
|
17
13
|
var _LexicalEditorConfig = require("../LexicalEditorConfig/LexicalEditorConfig");
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
setTextBlockSelection = _useRichTextEditor.setTextBlockSelection,
|
|
23
|
-
setActiveEditor = _useRichTextEditor.setActiveEditor;
|
|
24
|
-
var _useState = (0, _react.useState)(editor),
|
|
25
|
-
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
26
|
-
toolbarActiveEditor = _useState2[0],
|
|
27
|
-
setToolbarActiveEditor = _useState2[1];
|
|
14
|
+
var StaticToolbar = function StaticToolbar() {
|
|
15
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
16
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
17
|
+
editor = _useLexicalComposerCo2[0];
|
|
28
18
|
var _useLexicalEditorConf = (0, _LexicalEditorConfig.useLexicalEditorConfig)(),
|
|
29
19
|
toolbarElements = _useLexicalEditorConf.toolbarElements;
|
|
30
|
-
var updateToolbar = (0, _react.useCallback)(function () {
|
|
31
|
-
editor.getEditorState().read(function () {
|
|
32
|
-
// Should not to pop up the floating toolbar when using IME input
|
|
33
|
-
if (editor.isComposing()) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
var selection = (0, _lexical.$getSelection)();
|
|
37
|
-
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
38
|
-
var selectionState = (0, _getLexicalTextSelectionState.getLexicalTextSelectionState)(toolbarActiveEditor, selection);
|
|
39
|
-
if (selectionState) {
|
|
40
|
-
var _selectionState$state;
|
|
41
|
-
setTextBlockSelection(selectionState);
|
|
42
|
-
if (selectionState.selectedText !== "" && !((_selectionState$state = selectionState.state) !== null && _selectionState$state !== void 0 && _selectionState$state.link.isSelected)) {
|
|
43
|
-
setNodeIsText(true);
|
|
44
|
-
} else {
|
|
45
|
-
setNodeIsText(false);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (!(0, _lexical.$isRangeSelection)(selection)) {
|
|
50
|
-
setNodeIsText(false);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}, [toolbarActiveEditor]);
|
|
55
|
-
(0, _react.useEffect)(function () {
|
|
56
|
-
document.addEventListener("selectionchange", updateToolbar);
|
|
57
|
-
return function () {
|
|
58
|
-
document.removeEventListener("selectionchange", updateToolbar);
|
|
59
|
-
};
|
|
60
|
-
}, [updateToolbar]);
|
|
61
|
-
(0, _react.useEffect)(function () {
|
|
62
|
-
return editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
|
|
63
|
-
updateToolbar();
|
|
64
|
-
setToolbarActiveEditor(newEditor);
|
|
65
|
-
setActiveEditor(newEditor);
|
|
66
|
-
return false;
|
|
67
|
-
}, _lexical.COMMAND_PRIORITY_CRITICAL);
|
|
68
|
-
}, [editor, updateToolbar]);
|
|
69
|
-
(0, _react.useEffect)(function () {
|
|
70
|
-
return (0, _utils.mergeRegister)(toolbarActiveEditor.registerUpdateListener(function (_ref2) {
|
|
71
|
-
var editorState = _ref2.editorState;
|
|
72
|
-
editorState.read(function () {
|
|
73
|
-
updateToolbar();
|
|
74
|
-
});
|
|
75
|
-
}), editor.registerRootListener(function () {
|
|
76
|
-
if (editor.getRootElement() === null) {
|
|
77
|
-
setNodeIsText(false);
|
|
78
|
-
}
|
|
79
|
-
}), editor.registerRootListener(function () {
|
|
80
|
-
if (editor.getRootElement() === null) {
|
|
81
|
-
setNodeIsText(false);
|
|
82
|
-
}
|
|
83
|
-
}));
|
|
84
|
-
}, [updateToolbar, editor, toolbarActiveEditor]);
|
|
85
20
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
86
21
|
className: "static-toolbar"
|
|
87
22
|
}, editor.isEditable() && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toolbarElements.map(function (action) {
|
|
@@ -90,12 +25,6 @@ var useStaticToolbar = function useStaticToolbar(_ref) {
|
|
|
90
25
|
}, action.element);
|
|
91
26
|
})));
|
|
92
27
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
editor = _useLexicalComposerCo2[0];
|
|
97
|
-
return useStaticToolbar({
|
|
98
|
-
editor: editor
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
exports.StaticToolbar = StaticToolbar;
|
|
28
|
+
exports.StaticToolbar = StaticToolbar;
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=StaticToolbar.js.map
|