@webiny/lexical-editor 0.0.0-unstable.496cf268ac → 0.0.0-unstable.606fc9c866

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/commands/webiny-list.d.ts +7 -0
  2. package/commands/webiny-list.js +13 -0
  3. package/commands/webiny-list.js.map +1 -0
  4. package/commands/webiny-quote.d.ts +5 -0
  5. package/commands/webiny-quote.js +9 -0
  6. package/commands/webiny-quote.js.map +1 -0
  7. package/components/Editor/HeadingEditor.js +2 -1
  8. package/components/Editor/HeadingEditor.js.map +1 -1
  9. package/components/Editor/ParagraphEditor.js +3 -3
  10. package/components/Editor/ParagraphEditor.js.map +1 -1
  11. package/components/Editor/RichTextEditor.d.ts +2 -1
  12. package/components/Editor/RichTextEditor.js +30 -4
  13. package/components/Editor/RichTextEditor.js.map +1 -1
  14. package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +2 -0
  15. package/components/LexicalEditorConfig/LexicalEditorConfig.js +3 -1
  16. package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
  17. package/components/LexicalHtmlRenderer.d.ts +6 -1
  18. package/components/LexicalHtmlRenderer.js +22 -3
  19. package/components/LexicalHtmlRenderer.js.map +1 -1
  20. package/components/Toolbar/Toolbar.js +25 -5
  21. package/components/Toolbar/Toolbar.js.map +1 -1
  22. package/components/ToolbarActions/BoldAction.d.ts +0 -3
  23. package/components/ToolbarActions/BoldAction.js +8 -3
  24. package/components/ToolbarActions/BoldAction.js.map +1 -1
  25. package/components/ToolbarActions/BulletListAction.d.ts +0 -3
  26. package/components/ToolbarActions/BulletListAction.js +17 -55
  27. package/components/ToolbarActions/BulletListAction.js.map +1 -1
  28. package/components/ToolbarActions/CodeHighlightAction.d.ts +0 -4
  29. package/components/ToolbarActions/CodeHighlightAction.js +8 -4
  30. package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
  31. package/components/ToolbarActions/FontColorAction.js +0 -5
  32. package/components/ToolbarActions/FontColorAction.js.map +1 -1
  33. package/components/ToolbarActions/FontSizeAction.js +0 -3
  34. package/components/ToolbarActions/FontSizeAction.js.map +1 -1
  35. package/components/ToolbarActions/ItalicAction.d.ts +0 -3
  36. package/components/ToolbarActions/ItalicAction.js +8 -3
  37. package/components/ToolbarActions/ItalicAction.js.map +1 -1
  38. package/components/ToolbarActions/LinkAction.d.ts +0 -5
  39. package/components/ToolbarActions/LinkAction.js +0 -5
  40. package/components/ToolbarActions/LinkAction.js.map +1 -1
  41. package/components/ToolbarActions/NumberedListAction.d.ts +0 -3
  42. package/components/ToolbarActions/NumberedListAction.js +17 -53
  43. package/components/ToolbarActions/NumberedListAction.js.map +1 -1
  44. package/components/ToolbarActions/QuoteAction.d.ts +0 -2
  45. package/components/ToolbarActions/QuoteAction.js +16 -29
  46. package/components/ToolbarActions/QuoteAction.js.map +1 -1
  47. package/components/ToolbarActions/TypographyAction.d.ts +11 -0
  48. package/components/ToolbarActions/TypographyAction.js +118 -0
  49. package/components/ToolbarActions/TypographyAction.js.map +1 -0
  50. package/components/ToolbarActions/UnderlineAction.d.ts +0 -3
  51. package/components/ToolbarActions/UnderlineAction.js +8 -3
  52. package/components/ToolbarActions/UnderlineAction.js.map +1 -1
  53. package/components/ToolbarPresets/HeadingToolbarPreset.js +4 -0
  54. package/components/ToolbarPresets/HeadingToolbarPreset.js.map +1 -1
  55. package/components/ToolbarPresets/ParagraphToolbarPreset.js +4 -0
  56. package/components/ToolbarPresets/ParagraphToolbarPreset.js.map +1 -1
  57. package/context/RichTextEditorContext.d.ts +10 -0
  58. package/context/RichTextEditorContext.js +28 -1
  59. package/context/RichTextEditorContext.js.map +1 -1
  60. package/context/SharedHistoryContext.d.ts +11 -0
  61. package/context/SharedHistoryContext.js +26 -0
  62. package/context/SharedHistoryContext.js.map +1 -0
  63. package/context/TypographyActionContext.d.ts +7 -0
  64. package/context/TypographyActionContext.js +10 -0
  65. package/context/TypographyActionContext.js.map +1 -0
  66. package/hooks/useTypographyAction.d.ts +1 -0
  67. package/hooks/useTypographyAction.js +15 -0
  68. package/hooks/useTypographyAction.js.map +1 -0
  69. package/hooks/useWebinyList.d.ts +2 -0
  70. package/hooks/useWebinyList.js +39 -0
  71. package/hooks/useWebinyList.js.map +1 -0
  72. package/hooks/useWebinyQuote.d.ts +2 -0
  73. package/hooks/useWebinyQuote.js +20 -0
  74. package/hooks/useWebinyQuote.js.map +1 -0
  75. package/index.d.ts +3 -0
  76. package/index.js +21 -0
  77. package/index.js.map +1 -1
  78. package/nodes/FontColorNode.js +1 -1
  79. package/nodes/FontColorNode.js.map +1 -1
  80. package/nodes/TypographyElementNode.d.ts +42 -0
  81. package/nodes/TypographyElementNode.js +154 -0
  82. package/nodes/TypographyElementNode.js.map +1 -0
  83. package/nodes/WebinyQuoteNode.d.ts +29 -0
  84. package/nodes/WebinyQuoteNode.js +148 -0
  85. package/nodes/WebinyQuoteNode.js.map +1 -0
  86. package/nodes/list-node/WebinyListItemNode.d.ts +46 -0
  87. package/nodes/list-node/WebinyListItemNode.js +441 -0
  88. package/nodes/list-node/WebinyListItemNode.js.map +1 -0
  89. package/nodes/list-node/WebinyListNode.d.ts +38 -0
  90. package/nodes/list-node/WebinyListNode.js +253 -0
  91. package/nodes/list-node/WebinyListNode.js.map +1 -0
  92. package/nodes/list-node/formatList.d.ts +12 -0
  93. package/nodes/list-node/formatList.js +423 -0
  94. package/nodes/list-node/formatList.js.map +1 -0
  95. package/nodes/webinyNodes.d.ts +6 -1
  96. package/nodes/webinyNodes.js +7 -2
  97. package/nodes/webinyNodes.js.map +1 -1
  98. package/package.json +9 -6
  99. package/plugins/TypographyPlugin/TypographyPlugin.d.ts +2 -0
  100. package/plugins/TypographyPlugin/TypographyPlugin.js +31 -0
  101. package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -0
  102. package/plugins/WebinyListPLugin/WebinyListPlugin.d.ts +1 -0
  103. package/plugins/WebinyListPLugin/WebinyListPlugin.js +25 -0
  104. package/plugins/WebinyListPLugin/WebinyListPlugin.js.map +1 -0
  105. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.d.ts +1 -0
  106. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js +24 -0
  107. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js.map +1 -0
  108. package/themes/webinyLexicalTheme.css +0 -2
  109. package/themes/webinyLexicalTheme.d.ts +2 -0
  110. package/themes/webinyLexicalTheme.js +1 -0
  111. package/themes/webinyLexicalTheme.js.map +1 -1
  112. package/types.d.ts +58 -0
  113. package/types.js.map +1 -1
  114. package/ui/ToolbarActionDialog.js +0 -1
  115. package/ui/ToolbarActionDialog.js.map +1 -1
  116. package/utils/getLexicalTextSelectionState.d.ts +5 -0
  117. package/utils/getLexicalTextSelectionState.js +141 -0
  118. package/utils/getLexicalTextSelectionState.js.map +1 -0
  119. package/utils/nodes/clearNodeFormating.d.ts +2 -0
  120. package/utils/nodes/clearNodeFormating.js +28 -0
  121. package/utils/nodes/clearNodeFormating.js.map +1 -0
  122. package/utils/nodes/formatToParagraph.d.ts +2 -0
  123. package/utils/nodes/formatToParagraph.js +19 -0
  124. package/utils/nodes/formatToParagraph.js.map +1 -0
  125. package/utils/nodes/formatToQuote.d.ts +2 -0
  126. package/utils/nodes/formatToQuote.js +20 -0
  127. package/utils/nodes/formatToQuote.js.map +1 -0
  128. package/utils/nodes/list-node.d.ts +11 -0
  129. package/utils/nodes/list-node.js +107 -0
  130. package/utils/nodes/list-node.js.map +1 -0
  131. package/utils/styleObjectToString.d.ts +2 -0
  132. package/utils/styleObjectToString.js +22 -0
  133. package/utils/styleObjectToString.js.map +1 -0
  134. package/utils/toTypographyEmotionMap.d.ts +3 -0
  135. package/utils/toTypographyEmotionMap.js +36 -0
  136. package/utils/toTypographyEmotionMap.js.map +1 -0
@@ -0,0 +1,7 @@
1
+ import { LexicalCommand } from "lexical";
2
+ export declare type WebinyListCommandPayload = {
3
+ themeStyleId: string;
4
+ };
5
+ export declare const INSERT_UNORDERED_WEBINY_LIST_COMMAND: LexicalCommand<WebinyListCommandPayload>;
6
+ export declare const INSERT_ORDERED_WEBINY_LIST_COMMAND: LexicalCommand<WebinyListCommandPayload>;
7
+ export declare const REMOVE_WEBINY_LIST_COMMAND: LexicalCommand<void>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.REMOVE_WEBINY_LIST_COMMAND = exports.INSERT_UNORDERED_WEBINY_LIST_COMMAND = exports.INSERT_ORDERED_WEBINY_LIST_COMMAND = void 0;
7
+ var _lexical = require("lexical");
8
+ var INSERT_UNORDERED_WEBINY_LIST_COMMAND = (0, _lexical.createCommand)("INSERT_UNORDERED_WEBINY_LIST_COMMAND");
9
+ exports.INSERT_UNORDERED_WEBINY_LIST_COMMAND = INSERT_UNORDERED_WEBINY_LIST_COMMAND;
10
+ var INSERT_ORDERED_WEBINY_LIST_COMMAND = (0, _lexical.createCommand)("INSERT_ORDERED_WEBINY_LIST_COMMAND");
11
+ exports.INSERT_ORDERED_WEBINY_LIST_COMMAND = INSERT_ORDERED_WEBINY_LIST_COMMAND;
12
+ var REMOVE_WEBINY_LIST_COMMAND = (0, _lexical.createCommand)("REMOVE_WEBINY_LIST_COMMAND");
13
+ exports.REMOVE_WEBINY_LIST_COMMAND = REMOVE_WEBINY_LIST_COMMAND;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["INSERT_UNORDERED_WEBINY_LIST_COMMAND","createCommand","INSERT_ORDERED_WEBINY_LIST_COMMAND","REMOVE_WEBINY_LIST_COMMAND"],"sources":["webiny-list.ts"],"sourcesContent":["import { createCommand, LexicalCommand } from \"lexical\";\n\nexport type WebinyListCommandPayload = {\n themeStyleId: string;\n};\n\nexport const INSERT_UNORDERED_WEBINY_LIST_COMMAND: LexicalCommand<WebinyListCommandPayload> =\n createCommand(\"INSERT_UNORDERED_WEBINY_LIST_COMMAND\");\nexport const INSERT_ORDERED_WEBINY_LIST_COMMAND: LexicalCommand<WebinyListCommandPayload> =\n createCommand(\"INSERT_ORDERED_WEBINY_LIST_COMMAND\");\n\nexport const REMOVE_WEBINY_LIST_COMMAND: LexicalCommand<void> = createCommand(\n \"REMOVE_WEBINY_LIST_COMMAND\"\n);\n"],"mappings":";;;;;;AAAA;AAMO,IAAMA,oCAA8E,GACvF,IAAAC,sBAAa,EAAC,sCAAsC,CAAC;AAAC;AACnD,IAAMC,kCAA4E,GACrF,IAAAD,sBAAa,EAAC,oCAAoC,CAAC;AAAC;AAEjD,IAAME,0BAAgD,GAAG,IAAAF,sBAAa,EACzE,4BAA4B,CAC/B;AAAC"}
@@ -0,0 +1,5 @@
1
+ import { LexicalCommand } from "lexical";
2
+ export declare type WebinyQuoteCommandPayload = {
3
+ themeStyleId: string;
4
+ };
5
+ export declare const INSERT_WEBINY_QUOTE_COMMAND: LexicalCommand<WebinyQuoteCommandPayload>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.INSERT_WEBINY_QUOTE_COMMAND = void 0;
7
+ var _lexical = require("lexical");
8
+ var INSERT_WEBINY_QUOTE_COMMAND = (0, _lexical.createCommand)("INSERT_WEBINY_QUOTE_COMMAND");
9
+ exports.INSERT_WEBINY_QUOTE_COMMAND = INSERT_WEBINY_QUOTE_COMMAND;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["INSERT_WEBINY_QUOTE_COMMAND","createCommand"],"sources":["webiny-quote.ts"],"sourcesContent":["import { createCommand, LexicalCommand } from \"lexical\";\n\nexport type WebinyQuoteCommandPayload = {\n themeStyleId: string;\n};\n\nexport const INSERT_WEBINY_QUOTE_COMMAND: LexicalCommand<WebinyQuoteCommandPayload> = createCommand(\n \"INSERT_WEBINY_QUOTE_COMMAND\"\n);\n"],"mappings":";;;;;;AAAA;AAMO,IAAMA,2BAAsE,GAAG,IAAAC,sBAAa,EAC/F,6BAA6B,CAChC;AAAC"}
@@ -12,6 +12,7 @@ var _ClickableLinkPlugin = require("../../plugins/ClickableLinkPlugin/ClickableL
12
12
  var _FloatingLinkEditorPlugin = require("../../plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin");
13
13
  var _HeadingToolbar = require("../Toolbar/HeadingToolbar");
14
14
  var _RichTextEditor = require("./RichTextEditor");
15
+ var _WebinyQuoteNodePlugin = require("../../plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin");
15
16
  var _excluded = ["tag", "placeholder"];
16
17
  var HeadingEditor = function HeadingEditor(_ref) {
17
18
  var tag = _ref.tag,
@@ -21,7 +22,7 @@ var HeadingEditor = function HeadingEditor(_ref) {
21
22
  toolbar: /*#__PURE__*/_react.default.createElement(_HeadingToolbar.HeadingToolbar, null),
22
23
  tag: tag !== null && tag !== void 0 ? tag : "h1",
23
24
  placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : "Enter your heading text here..."
24
- }, rest), /*#__PURE__*/_react.default.createElement(_LexicalLinkPlugin.LinkPlugin, null), /*#__PURE__*/_react.default.createElement(_ClickableLinkPlugin.ClickableLinkPlugin, null), /*#__PURE__*/_react.default.createElement(_FloatingLinkEditorPlugin.FloatingLinkEditorPlugin, {
25
+ }, rest), /*#__PURE__*/_react.default.createElement(_LexicalLinkPlugin.LinkPlugin, null), /*#__PURE__*/_react.default.createElement(_WebinyQuoteNodePlugin.WebinyQuotePlugin, null), /*#__PURE__*/_react.default.createElement(_ClickableLinkPlugin.ClickableLinkPlugin, null), /*#__PURE__*/_react.default.createElement(_FloatingLinkEditorPlugin.FloatingLinkEditorPlugin, {
25
26
  anchorElem: document.body
26
27
  }));
27
28
  };
@@ -1 +1 @@
1
- {"version":3,"names":["HeadingEditor","tag","placeholder","rest","document","body"],"sources":["HeadingEditor.tsx"],"sourcesContent":["import React from \"react\";\nimport { LinkPlugin } from \"@lexical/react/LexicalLinkPlugin\";\nimport { ClickableLinkPlugin } from \"~/plugins/ClickableLinkPlugin/ClickableLinkPlugin\";\nimport { FloatingLinkEditorPlugin } from \"~/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin\";\nimport { HeadingToolbar } from \"~/components/Toolbar/HeadingToolbar\";\nimport { RichTextEditor, RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\n\ninterface HeadingEditorProps extends RichTextEditorProps {\n tag?: \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n}\n\nexport const HeadingEditor: React.FC<HeadingEditorProps> = ({ tag, placeholder, ...rest }) => {\n return (\n <RichTextEditor\n toolbar={<HeadingToolbar />}\n tag={tag ?? \"h1\"}\n placeholder={placeholder ?? \"Enter your heading text here...\"}\n {...rest}\n >\n <LinkPlugin />\n <ClickableLinkPlugin />\n <FloatingLinkEditorPlugin anchorElem={document.body} />\n </RichTextEditor>\n );\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAAyF;AAMlF,IAAMA,aAA2C,GAAG,SAA9CA,aAA2C,OAAsC;EAAA,IAAhCC,GAAG,QAAHA,GAAG;IAAEC,WAAW,QAAXA,WAAW;IAAKC,IAAI;EACnF,oBACI,6BAAC,8BAAc;IACX,OAAO,eAAE,6BAAC,8BAAc,OAAI;IAC5B,GAAG,EAAEF,GAAG,aAAHA,GAAG,cAAHA,GAAG,GAAI,IAAK;IACjB,WAAW,EAAEC,WAAW,aAAXA,WAAW,cAAXA,WAAW,GAAI;EAAkC,GAC1DC,IAAI,gBAER,6BAAC,6BAAU,OAAG,eACd,6BAAC,wCAAmB,OAAG,eACvB,6BAAC,kDAAwB;IAAC,UAAU,EAAEC,QAAQ,CAACC;EAAK,EAAG,CAC1C;AAEzB,CAAC;AAAC"}
1
+ {"version":3,"names":["HeadingEditor","tag","placeholder","rest","document","body"],"sources":["HeadingEditor.tsx"],"sourcesContent":["import React from \"react\";\nimport { LinkPlugin } from \"@lexical/react/LexicalLinkPlugin\";\nimport { ClickableLinkPlugin } from \"~/plugins/ClickableLinkPlugin/ClickableLinkPlugin\";\nimport { FloatingLinkEditorPlugin } from \"~/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin\";\nimport { HeadingToolbar } from \"~/components/Toolbar/HeadingToolbar\";\nimport { RichTextEditor, RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\nimport { WebinyQuotePlugin } from \"~/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin\";\n\ninterface HeadingEditorProps extends RichTextEditorProps {\n tag?: \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n}\n\nexport const HeadingEditor: React.FC<HeadingEditorProps> = ({ tag, placeholder, ...rest }) => {\n return (\n <RichTextEditor\n toolbar={<HeadingToolbar />}\n tag={tag ?? \"h1\"}\n placeholder={placeholder ?? \"Enter your heading text here...\"}\n {...rest}\n >\n <LinkPlugin />\n <WebinyQuotePlugin />\n <ClickableLinkPlugin />\n <FloatingLinkEditorPlugin anchorElem={document.body} />\n </RichTextEditor>\n );\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAA0F;AAMnF,IAAMA,aAA2C,GAAG,SAA9CA,aAA2C,OAAsC;EAAA,IAAhCC,GAAG,QAAHA,GAAG;IAAEC,WAAW,QAAXA,WAAW;IAAKC,IAAI;EACnF,oBACI,6BAAC,8BAAc;IACX,OAAO,eAAE,6BAAC,8BAAc,OAAI;IAC5B,GAAG,EAAEF,GAAG,aAAHA,GAAG,cAAHA,GAAG,GAAI,IAAK;IACjB,WAAW,EAAEC,WAAW,aAAXA,WAAW,cAAXA,WAAW,GAAI;EAAkC,GAC1DC,IAAI,gBAER,6BAAC,6BAAU,OAAG,eACd,6BAAC,wCAAiB,OAAG,eACrB,6BAAC,wCAAmB,OAAG,eACvB,6BAAC,kDAAwB;IAAC,UAAU,EAAEC,QAAQ,CAACC;EAAK,EAAG,CAC1C;AAEzB,CAAC;AAAC"}
@@ -7,13 +7,13 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.ParagraphEditor = void 0;
8
8
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
9
  var _react = _interopRequireDefault(require("react"));
10
- var _LexicalListPlugin = require("@lexical/react/LexicalListPlugin");
11
10
  var _CodeHighlightPlugin = require("../../plugins/CodeHighlightPlugin/CodeHighlightPlugin");
12
11
  var _LexicalLinkPlugin = require("@lexical/react/LexicalLinkPlugin");
13
12
  var _FloatingLinkEditorPlugin = require("../../plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin");
14
13
  var _ClickableLinkPlugin = require("../../plugins/ClickableLinkPlugin/ClickableLinkPlugin");
15
14
  var _ParagraphToolbar = require("../Toolbar/ParagraphToolbar");
16
15
  var _RichTextEditor = require("./RichTextEditor");
16
+ var _WebinyListPlugin = require("../../plugins/WebinyListPLugin/WebinyListPlugin");
17
17
  var _excluded = ["placeholder", "tag"];
18
18
  var ParagraphEditor = function ParagraphEditor(_ref) {
19
19
  var placeholder = _ref.placeholder,
@@ -23,8 +23,8 @@ var ParagraphEditor = function ParagraphEditor(_ref) {
23
23
  toolbar: /*#__PURE__*/_react.default.createElement(_ParagraphToolbar.ParagraphToolbar, null),
24
24
  tag: tag !== null && tag !== void 0 ? tag : "p",
25
25
  placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : "Enter your text here..."
26
- }, rest), /*#__PURE__*/_react.default.createElement(_LexicalLinkPlugin.LinkPlugin, null), /*#__PURE__*/_react.default.createElement(_CodeHighlightPlugin.CodeHighlightPlugin, null), /*#__PURE__*/_react.default.createElement(_ClickableLinkPlugin.ClickableLinkPlugin, null), /*#__PURE__*/_react.default.createElement(_FloatingLinkEditorPlugin.FloatingLinkEditorPlugin, {
26
+ }, rest), /*#__PURE__*/_react.default.createElement(_LexicalLinkPlugin.LinkPlugin, null), /*#__PURE__*/_react.default.createElement(_WebinyListPlugin.WebinyListPlugin, null), /*#__PURE__*/_react.default.createElement(_CodeHighlightPlugin.CodeHighlightPlugin, null), /*#__PURE__*/_react.default.createElement(_ClickableLinkPlugin.ClickableLinkPlugin, null), /*#__PURE__*/_react.default.createElement(_FloatingLinkEditorPlugin.FloatingLinkEditorPlugin, {
27
27
  anchorElem: document.body
28
- }), /*#__PURE__*/_react.default.createElement(_LexicalListPlugin.ListPlugin, null));
28
+ }));
29
29
  };
30
30
  exports.ParagraphEditor = ParagraphEditor;
@@ -1 +1 @@
1
- {"version":3,"names":["ParagraphEditor","placeholder","tag","rest","document","body"],"sources":["ParagraphEditor.tsx"],"sourcesContent":["import React from \"react\";\nimport { ListPlugin } from \"@lexical/react/LexicalListPlugin\";\nimport { CodeHighlightPlugin } from \"~/plugins/CodeHighlightPlugin/CodeHighlightPlugin\";\nimport { LinkPlugin } from \"@lexical/react/LexicalLinkPlugin\";\nimport { FloatingLinkEditorPlugin } from \"~/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin\";\nimport { ClickableLinkPlugin } from \"~/plugins/ClickableLinkPlugin/ClickableLinkPlugin\";\nimport { ParagraphToolbar } from \"~/components/Toolbar/ParagraphToolbar\";\nimport { RichTextEditor, RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\n\ninterface ParagraphLexicalEditorProps extends RichTextEditorProps {\n tag?: \"p\";\n}\n\nconst ParagraphEditor: React.FC<ParagraphLexicalEditorProps> = ({ placeholder, tag, ...rest }) => {\n return (\n <RichTextEditor\n toolbar={<ParagraphToolbar />}\n tag={tag ?? \"p\"}\n placeholder={placeholder ?? \"Enter your text here...\"}\n {...rest}\n >\n <LinkPlugin />\n <CodeHighlightPlugin />\n <ClickableLinkPlugin />\n <FloatingLinkEditorPlugin anchorElem={document.body} />\n <ListPlugin />\n </RichTextEditor>\n );\n};\n\nexport { ParagraphEditor };\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAyF;AAMzF,IAAMA,eAAsD,GAAG,SAAzDA,eAAsD,OAAsC;EAAA,IAAhCC,WAAW,QAAXA,WAAW;IAAEC,GAAG,QAAHA,GAAG;IAAKC,IAAI;EACvF,oBACI,6BAAC,8BAAc;IACX,OAAO,eAAE,6BAAC,kCAAgB,OAAI;IAC9B,GAAG,EAAED,GAAG,aAAHA,GAAG,cAAHA,GAAG,GAAI,GAAI;IAChB,WAAW,EAAED,WAAW,aAAXA,WAAW,cAAXA,WAAW,GAAI;EAA0B,GAClDE,IAAI,gBAER,6BAAC,6BAAU,OAAG,eACd,6BAAC,wCAAmB,OAAG,eACvB,6BAAC,wCAAmB,OAAG,eACvB,6BAAC,kDAAwB;IAAC,UAAU,EAAEC,QAAQ,CAACC;EAAK,EAAG,eACvD,6BAAC,6BAAU,OAAG,CACD;AAEzB,CAAC;AAAC"}
1
+ {"version":3,"names":["ParagraphEditor","placeholder","tag","rest","document","body"],"sources":["ParagraphEditor.tsx"],"sourcesContent":["import React from \"react\";\nimport { CodeHighlightPlugin } from \"~/plugins/CodeHighlightPlugin/CodeHighlightPlugin\";\nimport { LinkPlugin } from \"@lexical/react/LexicalLinkPlugin\";\nimport { FloatingLinkEditorPlugin } from \"~/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin\";\nimport { ClickableLinkPlugin } from \"~/plugins/ClickableLinkPlugin/ClickableLinkPlugin\";\nimport { ParagraphToolbar } from \"~/components/Toolbar/ParagraphToolbar\";\nimport { RichTextEditor, RichTextEditorProps } from \"~/components/Editor/RichTextEditor\";\nimport { WebinyListPlugin } from \"~/plugins/WebinyListPLugin/WebinyListPlugin\";\n\ninterface ParagraphLexicalEditorProps extends RichTextEditorProps {\n tag?: \"p\";\n}\n\nconst ParagraphEditor: React.FC<ParagraphLexicalEditorProps> = ({ placeholder, tag, ...rest }) => {\n return (\n <RichTextEditor\n toolbar={<ParagraphToolbar />}\n tag={tag ?? \"p\"}\n placeholder={placeholder ?? \"Enter your text here...\"}\n {...rest}\n >\n <LinkPlugin />\n <WebinyListPlugin />\n <CodeHighlightPlugin />\n <ClickableLinkPlugin />\n <FloatingLinkEditorPlugin anchorElem={document.body} />\n </RichTextEditor>\n );\n};\n\nexport { ParagraphEditor };\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAA+E;AAM/E,IAAMA,eAAsD,GAAG,SAAzDA,eAAsD,OAAsC;EAAA,IAAhCC,WAAW,QAAXA,WAAW;IAAEC,GAAG,QAAHA,GAAG;IAAKC,IAAI;EACvF,oBACI,6BAAC,8BAAc;IACX,OAAO,eAAE,6BAAC,kCAAgB,OAAI;IAC9B,GAAG,EAAED,GAAG,aAAHA,GAAG,cAAHA,GAAG,GAAI,GAAI;IAChB,WAAW,EAAED,WAAW,aAAXA,WAAW,cAAXA,WAAW,GAAI;EAA0B,GAClDE,IAAI,gBAER,6BAAC,6BAAU,OAAG,eACd,6BAAC,kCAAgB,OAAG,eACpB,6BAAC,wCAAmB,OAAG,eACvB,6BAAC,wCAAmB,OAAG,eACvB,6BAAC,kDAAwB;IAAC,UAAU,EAAEC,QAAQ,CAACC;EAAK,EAAG,CAC1C;AAEzB,CAAC;AAAC"}
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { LexicalValue } from "../../types";
2
+ import { LexicalValue, ThemeEmotionMap } from "../../types";
3
3
  import { Klass, LexicalNode } from "lexical";
4
4
  import { WebinyTheme } from "../../themes/webinyLexicalTheme";
5
5
  export interface RichTextEditorProps {
@@ -18,6 +18,7 @@ export interface RichTextEditorProps {
18
18
  height?: number | string;
19
19
  width?: number | string;
20
20
  theme: WebinyTheme;
21
+ themeEmotionMap?: ThemeEmotionMap;
21
22
  }
22
23
  /**
23
24
  * @description Main editor container
@@ -27,6 +27,13 @@ var _BlurEventPlugin = require("../../plugins/BlurEventPlugin/BlurEventPlugin");
27
27
  var _FontColorPlugin = require("../../plugins/FontColorPlugin/FontColorPlugin");
28
28
  var _webinyLexicalTheme = require("../../themes/webinyLexicalTheme");
29
29
  var _webinyNodes = require("../../nodes/webinyNodes");
30
+ var _TypographyPlugin = require("../../plugins/TypographyPlugin/TypographyPlugin");
31
+ var _WebinyQuoteNodePlugin = require("../../plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin");
32
+ var _LexicalHistoryPlugin = require("@lexical/react/LexicalHistoryPlugin");
33
+ var _SharedHistoryContext = require("../../context/SharedHistoryContext");
34
+ var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
35
+ var _react2 = require("@emotion/react");
36
+ var _toTypographyEmotionMap = require("../../utils/toTypographyEmotionMap");
30
37
  var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
31
38
  var toolbar = _ref.toolbar,
32
39
  onChange = _ref.onChange,
@@ -38,13 +45,23 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
38
45
  focus = _ref.focus,
39
46
  width = _ref.width,
40
47
  height = _ref.height,
41
- theme = _ref.theme;
48
+ theme = _ref.theme,
49
+ themeEmotionMap = _ref.themeEmotionMap;
50
+ var _useSharedHistoryCont = (0, _SharedHistoryContext.useSharedHistoryContext)(),
51
+ historyState = _useSharedHistoryCont.historyState;
42
52
  var placeholderElem = /*#__PURE__*/_react.default.createElement(_Placeholder.Placeholder, null, placeholder || "Enter text...");
43
53
  var scrollRef = (0, _react.useRef)(null);
44
54
  var _useState = (0, _react.useState)(undefined),
45
55
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
46
56
  floatingAnchorElem = _useState2[0],
47
57
  setFloatingAnchorElem = _useState2[1];
58
+ var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
59
+ setTheme = _useRichTextEditor.setTheme,
60
+ setThemeEmotionMap = _useRichTextEditor.setThemeEmotionMap;
61
+ (0, _react.useEffect)(function () {
62
+ setTheme(theme);
63
+ setThemeEmotionMap(themeEmotionMap);
64
+ }, [themeEmotionMap]);
48
65
  var onRef = function onRef(_floatingAnchorElem) {
49
66
  if (_floatingAnchorElem !== null) {
50
67
  setFloatingAnchorElem(_floatingAnchorElem);
@@ -62,7 +79,7 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
62
79
  },
63
80
  nodes: [].concat((0, _toConsumableArray2.default)(_webinyNodes.WebinyNodes), (0, _toConsumableArray2.default)(nodes || [])),
64
81
  theme: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _webinyLexicalTheme.webinyEditorTheme), {}, {
65
- styles: theme === null || theme === void 0 ? void 0 : theme.styles
82
+ emotionMap: themeEmotionMap
66
83
  })
67
84
  };
68
85
  function handleOnChange(editorState, editor) {
@@ -83,7 +100,9 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
83
100
  onChange: handleOnChange
84
101
  }), value && /*#__PURE__*/_react.default.createElement(_LexicalUpdateStatePlugin.LexicalUpdateStatePlugin, {
85
102
  value: value
86
- }), /*#__PURE__*/_react.default.createElement(_LexicalClearEditorPlugin.ClearEditorPlugin, null), /*#__PURE__*/_react.default.createElement(_FontColorPlugin.FontColorPlugin, null), onBlur && /*#__PURE__*/_react.default.createElement(_BlurEventPlugin.BlurEventPlugin, {
103
+ }), /*#__PURE__*/_react.default.createElement(_LexicalClearEditorPlugin.ClearEditorPlugin, null), /*#__PURE__*/_react.default.createElement(_FontColorPlugin.FontColorPlugin, null), /*#__PURE__*/_react.default.createElement(_TypographyPlugin.TypographyPlugin, null), /*#__PURE__*/_react.default.createElement(_WebinyQuoteNodePlugin.WebinyQuotePlugin, null), /*#__PURE__*/_react.default.createElement(_LexicalHistoryPlugin.HistoryPlugin, {
104
+ externalHistoryState: historyState
105
+ }), onBlur && /*#__PURE__*/_react.default.createElement(_BlurEventPlugin.BlurEventPlugin, {
87
106
  onBlur: onBlur
88
107
  }), focus && /*#__PURE__*/_react.default.createElement(_LexicalAutoFocusPlugin.AutoFocusPlugin, null), children, /*#__PURE__*/_react.default.createElement(_LexicalRichTextPlugin.RichTextPlugin, {
89
108
  contentEditable: /*#__PURE__*/_react.default.createElement("div", {
@@ -107,6 +126,13 @@ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
107
126
  * @description Main editor container
108
127
  */
109
128
  var RichTextEditor = (0, _reactComposition.makeComposable)("RichTextEditor", function (props) {
110
- return /*#__PURE__*/_react.default.createElement(_RichTextEditorContext.RichTextEditorProvider, null, /*#__PURE__*/_react.default.createElement(BaseRichTextEditor, props));
129
+ return /*#__PURE__*/_react.default.createElement(_RichTextEditorContext.RichTextEditorProvider, null, /*#__PURE__*/_react.default.createElement(_react2.ClassNames, null, function (_ref2) {
130
+ var _props$themeEmotionMa;
131
+ var css = _ref2.css;
132
+ var themeEmotionMap = (_props$themeEmotionMa = props === null || props === void 0 ? void 0 : props.themeEmotionMap) !== null && _props$themeEmotionMa !== void 0 ? _props$themeEmotionMa : (0, _toTypographyEmotionMap.toTypographyEmotionMap)(css, props.theme);
133
+ return /*#__PURE__*/_react.default.createElement(_SharedHistoryContext.SharedHistoryContext, null, /*#__PURE__*/_react.default.createElement(BaseRichTextEditor, Object.assign({}, props, {
134
+ themeEmotionMap: themeEmotionMap
135
+ })));
136
+ }));
111
137
  });
112
138
  exports.RichTextEditor = RichTextEditor;
@@ -1 +1 @@
1
- {"version":3,"names":["BaseRichTextEditor","toolbar","onChange","value","nodes","placeholder","children","onBlur","focus","width","height","theme","placeholderElem","scrollRef","useRef","useState","undefined","floatingAnchorElem","setFloatingAnchorElem","onRef","_floatingAnchorElem","sizeStyle","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","WebinyNodes","webinyEditorTheme","styles","handleOnChange","editor","read","getEditorState","JSON","stringify","toJSON","outline","LexicalErrorBoundary","RichTextEditor","makeComposable","props"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { useRef, useState } from \"react\";\nimport { LexicalValue } 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 { FontColorPlugin } from \"~/plugins/FontColorPlugin/FontColorPlugin\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\n\nexport interface RichTextEditorProps {\n toolbar?: React.ReactNode;\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}\n\nconst BaseRichTextEditor: React.FC<RichTextEditorProps> = ({\n toolbar,\n onChange,\n value,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n width,\n height,\n theme\n}: RichTextEditorProps) => {\n const placeholderElem = <Placeholder>{placeholder || \"Enter text...\"}</Placeholder>;\n const scrollRef = useRef(null);\n const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLElement | undefined>(\n undefined\n );\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 initialConfig = {\n editorState: isValidLexicalData(value) ? value : generateInitialLexicalValue(),\n namespace: \"webiny\",\n onError: (error: Error) => {\n throw error;\n },\n nodes: [...WebinyNodes, ...(nodes || [])],\n theme: { ...webinyEditorTheme, styles: theme?.styles }\n };\n\n function handleOnChange(editorState: EditorState, editor: LexicalEditor) {\n editorState.read(() => {\n if (typeof onChange === \"function\") {\n const editorState = editor.getEditorState();\n //TODO: send plain JSON object\n onChange(JSON.stringify(editorState.toJSON()));\n }\n });\n }\n\n return (\n <LexicalComposer initialConfig={initialConfig}>\n <div ref={scrollRef} style={{ ...sizeStyle }}>\n {/* data */}\n <OnChangePlugin onChange={handleOnChange} />\n {value && <LexicalUpdateStatePlugin value={value} />}\n <ClearEditorPlugin />\n <FontColorPlugin />\n {/* Events */}\n {onBlur && <BlurEventPlugin onBlur={onBlur} />}\n {focus && <AutoFocusPlugin />}\n {/* External plugins and components */}\n {children}\n <RichTextPlugin\n contentEditable={\n <div className=\"editor-scroller\" style={{ ...sizeStyle }}>\n <div className=\"editor\" ref={onRef} style={{ ...sizeStyle }}>\n <ContentEditable style={{ outline: 0, ...sizeStyle }} />\n </div>\n </div>\n }\n placeholder={placeholderElem}\n ErrorBoundary={LexicalErrorBoundary}\n />\n {/* Toolbar */}\n {floatingAnchorElem && toolbar}\n </div>\n </LexicalComposer>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeComposable<RichTextEditorProps>(\"RichTextEditor\", props => {\n return (\n <RichTextEditorProvider>\n <BaseRichTextEditor {...props} />\n </RichTextEditorProvider>\n );\n});\n"],"mappings":";;;;;;;;;;;AAAA;AAEA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuBA,IAAMA,kBAAiD,GAAG,SAAp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;AAEjC,CAAC,CAAC;AAAC"}
1
+ {"version":3,"names":["BaseRichTextEditor","toolbar","onChange","value","nodes","placeholder","children","onBlur","focus","width","height","theme","themeEmotionMap","useSharedHistoryContext","historyState","placeholderElem","scrollRef","useRef","useState","undefined","floatingAnchorElem","setFloatingAnchorElem","useRichTextEditor","setTheme","setThemeEmotionMap","useEffect","onRef","_floatingAnchorElem","sizeStyle","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","WebinyNodes","webinyEditorTheme","emotionMap","handleOnChange","editor","read","getEditorState","JSON","stringify","toJSON","outline","LexicalErrorBoundary","RichTextEditor","makeComposable","props","css","toTypographyEmotionMap"],"sources":["RichTextEditor.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { LexicalValue, ThemeEmotionMap } 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 { FontColorPlugin } from \"~/plugins/FontColorPlugin/FontColorPlugin\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\nimport { TypographyPlugin } from \"~/plugins/TypographyPlugin/TypographyPlugin\";\nimport { WebinyQuotePlugin } from \"~/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin\";\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\";\n\nexport interface RichTextEditorProps {\n toolbar?: React.ReactNode;\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\nconst BaseRichTextEditor: React.FC<RichTextEditorProps> = ({\n toolbar,\n onChange,\n value,\n nodes,\n placeholder,\n children,\n onBlur,\n focus,\n width,\n height,\n theme,\n themeEmotionMap\n}: RichTextEditorProps) => {\n const { historyState } = useSharedHistoryContext();\n const placeholderElem = <Placeholder>{placeholder || \"Enter text...\"}</Placeholder>;\n const scrollRef = useRef(null);\n const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLElement | undefined>(\n undefined\n );\n const { setTheme, setThemeEmotionMap } = useRichTextEditor();\n\n useEffect(() => {\n setTheme(theme);\n setThemeEmotionMap(themeEmotionMap);\n }, [themeEmotionMap]);\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 initialConfig = {\n editorState: isValidLexicalData(value) ? value : generateInitialLexicalValue(),\n namespace: \"webiny\",\n onError: (error: Error) => {\n throw error;\n },\n nodes: [...WebinyNodes, ...(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 //TODO: send plain JSON object\n onChange(JSON.stringify(editorState.toJSON()));\n }\n });\n }\n\n return (\n <LexicalComposer initialConfig={initialConfig}>\n <div ref={scrollRef} style={{ ...sizeStyle }}>\n {/* data */}\n <OnChangePlugin onChange={handleOnChange} />\n {value && <LexicalUpdateStatePlugin value={value} />}\n <ClearEditorPlugin />\n <FontColorPlugin />\n <TypographyPlugin />\n <WebinyQuotePlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n {/* Events */}\n {onBlur && <BlurEventPlugin onBlur={onBlur} />}\n {focus && <AutoFocusPlugin />}\n {/* External plugins and components */}\n {children}\n <RichTextPlugin\n contentEditable={\n <div className=\"editor-scroller\" style={{ ...sizeStyle }}>\n <div className=\"editor\" ref={onRef} style={{ ...sizeStyle }}>\n <ContentEditable style={{ outline: 0, ...sizeStyle }} />\n </div>\n </div>\n }\n placeholder={placeholderElem}\n ErrorBoundary={LexicalErrorBoundary}\n />\n {/* Toolbar */}\n {floatingAnchorElem && toolbar}\n </div>\n </LexicalComposer>\n );\n};\n\n/**\n * @description Main editor container\n */\nexport const RichTextEditor = makeComposable<RichTextEditorProps>(\"RichTextEditor\", props => {\n return (\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 }}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7CC,KAAK,iBAAI,6BAAC,uCAAe,OAAG,EAE5BF,QAAQ,eACT,6BAAC,qCAAc;IACX,eAAe,eACX;MAAK,SAAS,EAAC,iBAAiB;MAAC,KAAK,kCAAOsB,SAAS;IAAG,gBACrD;MAAK,SAAS,EAAC,QAAQ;MAAC,GAAG,EAAEF,KAAM;MAAC,KAAK,kCAAOE,SAAS;IAAG,gBACxD,6BAAC,uCAAe;MAAC,KAAK;QAAIkB,OAAO,EAAE;MAAC,GAAKlB,SAAS;IAAG,EAAG,CACtD,CAEb;IACD,WAAW,EAAEb,eAAgB;IAC7B,aAAa,EAAEgC;EAAqB,EACtC,EAED3B,kBAAkB,IAAInB,OAAO,CAC5B,CACQ;AAE1B,CAAC;;AAED;AACA;AACA;AACO,IAAM+C,cAAc,GAAG,IAAAC,gCAAc,EAAsB,gBAAgB,EAAE,UAAAC,KAAK,EAAI;EACzF,oBACI,6BAAC,6CAAsB,qBACnB,6BAAC,kBAAU,QACN,iBAAa;IAAA;IAAA,IAAVC,GAAG,SAAHA,GAAG;IACH,IAAMvC,eAAe,4BACjBsC,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEtC,eAAe,yEAAI,IAAAwC,8CAAsB,EAACD,GAAG,EAAED,KAAK,CAACvC,KAAK,CAAC;IACtE,oBACI,6BAAC,0CAAoB,qBACjB,6BAAC,kBAAkB,oBAAKuC,KAAK;MAAE,eAAe,EAAEtC;IAAgB,GAAG,CAChD;EAE/B,CAAC,CACQ,CACQ;AAEjC,CAAC,CAAC;AAAC"}
@@ -1,7 +1,9 @@
1
1
  import React from "react";
2
2
  import { FontColorAction } from "../ToolbarActions/FontColorAction";
3
+ import { TypographyAction } from "../ToolbarActions/TypographyAction";
3
4
  interface LexicalEditorConfig extends React.FC<unknown> {
4
5
  FontColorAction: typeof FontColorAction;
6
+ TypographyAction: typeof TypographyAction;
5
7
  }
6
8
  export declare const LexicalEditorConfig: LexicalEditorConfig;
7
9
  export {};
@@ -7,9 +7,11 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.LexicalEditorConfig = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _FontColorAction = require("../ToolbarActions/FontColorAction");
10
+ var _TypographyAction = require("../ToolbarActions/TypographyAction");
10
11
  var LexicalEditorConfig = function LexicalEditorConfig(_ref) {
11
12
  var children = _ref.children;
12
13
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
13
14
  };
14
15
  exports.LexicalEditorConfig = LexicalEditorConfig;
15
- LexicalEditorConfig.FontColorAction = _FontColorAction.FontColorAction;
16
+ LexicalEditorConfig.FontColorAction = _FontColorAction.FontColorAction;
17
+ LexicalEditorConfig.TypographyAction = _TypographyAction.TypographyAction;
@@ -1 +1 @@
1
- {"version":3,"names":["LexicalEditorConfig","children","FontColorAction"],"sources":["LexicalEditorConfig.tsx"],"sourcesContent":["import React from \"react\";\nimport { FontColorAction } from \"~/components/ToolbarActions/FontColorAction\";\n\ninterface LexicalEditorConfig extends React.FC<unknown> {\n FontColorAction: typeof FontColorAction;\n}\n\nexport const LexicalEditorConfig: LexicalEditorConfig = ({ children }) => {\n return <>{children}</>;\n};\n\nLexicalEditorConfig.FontColorAction = FontColorAction;\n"],"mappings":";;;;;;;AAAA;AACA;AAMO,IAAMA,mBAAwC,GAAG,SAA3CA,mBAAwC,OAAqB;EAAA,IAAfC,QAAQ,QAARA,QAAQ;EAC/D,oBAAO,4DAAGA,QAAQ,CAAI;AAC1B,CAAC;AAAC;AAEFD,mBAAmB,CAACE,eAAe,GAAGA,gCAAe"}
1
+ {"version":3,"names":["LexicalEditorConfig","children","FontColorAction","TypographyAction"],"sources":["LexicalEditorConfig.tsx"],"sourcesContent":["import React from \"react\";\nimport { FontColorAction } from \"~/components/ToolbarActions/FontColorAction\";\nimport { TypographyAction } from \"~/components/ToolbarActions/TypographyAction\";\n\ninterface LexicalEditorConfig extends React.FC<unknown> {\n FontColorAction: typeof FontColorAction;\n TypographyAction: typeof TypographyAction;\n}\n\nexport const LexicalEditorConfig: LexicalEditorConfig = ({ children }) => {\n return <>{children}</>;\n};\n\nLexicalEditorConfig.FontColorAction = FontColorAction;\nLexicalEditorConfig.TypographyAction = TypographyAction;\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAOO,IAAMA,mBAAwC,GAAG,SAA3CA,mBAAwC,OAAqB;EAAA,IAAfC,QAAQ,QAARA,QAAQ;EAC/D,oBAAO,4DAAGA,QAAQ,CAAI;AAC1B,CAAC;AAAC;AAEFD,mBAAmB,CAACE,eAAe,GAAGA,gCAAe;AACrDF,mBAAmB,CAACG,gBAAgB,GAAGA,kCAAgB"}
@@ -1,11 +1,16 @@
1
1
  import React from "react";
2
- import { LexicalValue } from "../types";
2
+ import { LexicalValue, ThemeEmotionMap } from "../types";
3
3
  import { Klass, LexicalNode } from "lexical";
4
4
  import { WebinyTheme } from "../themes/webinyLexicalTheme";
5
5
  interface LexicalHtmlRendererProps {
6
6
  nodes?: Klass<LexicalNode>[];
7
7
  value: LexicalValue | null;
8
8
  theme: WebinyTheme;
9
+ themeEmotionMap?: ThemeEmotionMap;
9
10
  }
11
+ export declare const BaseLexicalHtmlRenderer: React.FC<LexicalHtmlRendererProps>;
12
+ /**
13
+ * @description Main editor container
14
+ */
10
15
  export declare const LexicalHtmlRenderer: React.FC<LexicalHtmlRendererProps>;
11
16
  export {};
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.LexicalHtmlRenderer = void 0;
7
+ exports.LexicalHtmlRenderer = exports.BaseLexicalHtmlRenderer = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
10
  var _react = _interopRequireDefault(require("react"));
@@ -17,10 +17,13 @@ var _LexicalErrorBoundary = _interopRequireDefault(require("@lexical/react/Lexic
17
17
  var _LexicalUpdateStatePlugin = require("../plugins/LexicalUpdateStatePlugin");
18
18
  var _webinyNodes = require("../nodes/webinyNodes");
19
19
  var _webinyLexicalTheme = require("../themes/webinyLexicalTheme");
20
- var LexicalHtmlRenderer = function LexicalHtmlRenderer(_ref) {
20
+ var _react2 = require("@emotion/react");
21
+ var _toTypographyEmotionMap = require("../utils/toTypographyEmotionMap");
22
+ var BaseLexicalHtmlRenderer = function BaseLexicalHtmlRenderer(_ref) {
21
23
  var nodes = _ref.nodes,
22
24
  value = _ref.value,
23
- theme = _ref.theme;
25
+ theme = _ref.theme,
26
+ themeEmotionMap = _ref.themeEmotionMap;
24
27
  var initialConfig = {
25
28
  editorState: (0, _isValidLexicalData.isValidLexicalData)(value) ? value : (0, _generateInitialLexicalValue.generateInitialLexicalValue)(),
26
29
  namespace: "webiny",
@@ -30,6 +33,7 @@ var LexicalHtmlRenderer = function LexicalHtmlRenderer(_ref) {
30
33
  editable: false,
31
34
  nodes: [].concat((0, _toConsumableArray2.default)(_webinyNodes.WebinyNodes), (0, _toConsumableArray2.default)(nodes || [])),
32
35
  theme: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _webinyLexicalTheme.webinyEditorTheme), {}, {
36
+ emotionMap: themeEmotionMap,
33
37
  styles: theme.styles
34
38
  })
35
39
  };
@@ -45,4 +49,19 @@ var LexicalHtmlRenderer = function LexicalHtmlRenderer(_ref) {
45
49
  value: value
46
50
  }));
47
51
  };
52
+
53
+ /**
54
+ * @description Main editor container
55
+ */
56
+ exports.BaseLexicalHtmlRenderer = BaseLexicalHtmlRenderer;
57
+ var LexicalHtmlRenderer = function LexicalHtmlRenderer(props) {
58
+ return /*#__PURE__*/_react.default.createElement(_react2.ClassNames, null, function (_ref2) {
59
+ var _props$themeEmotionMa;
60
+ 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, _toTypographyEmotionMap.toTypographyEmotionMap)(css, props.theme);
62
+ return /*#__PURE__*/_react.default.createElement(BaseLexicalHtmlRenderer, Object.assign({}, props, {
63
+ themeEmotionMap: themeEmotionMap
64
+ }));
65
+ });
66
+ };
48
67
  exports.LexicalHtmlRenderer = LexicalHtmlRenderer;
@@ -1 +1 @@
1
- {"version":3,"names":["LexicalHtmlRenderer","nodes","value","theme","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","editable","WebinyNodes","webinyEditorTheme","styles","LexicalErrorBoundary"],"sources":["LexicalHtmlRenderer.tsx"],"sourcesContent":["import React from \"react\";\nimport { LexicalValue } from \"~/types\";\nimport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\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 { LexicalUpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\nimport { Klass, LexicalNode } from \"lexical\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\n\ninterface LexicalHtmlRendererProps {\n nodes?: Klass<LexicalNode>[];\n value: LexicalValue | null;\n /*\n * @description Theme to be injected into lexical editor\n */\n theme: WebinyTheme;\n}\n\nexport const LexicalHtmlRenderer: React.FC<LexicalHtmlRendererProps> = ({\n nodes,\n value,\n theme\n}) => {\n const initialConfig = {\n editorState: isValidLexicalData(value) ? value : generateInitialLexicalValue(),\n namespace: \"webiny\",\n onError: (error: Error) => {\n throw error;\n },\n editable: false,\n nodes: [...WebinyNodes, ...(nodes || [])],\n theme: { ...webinyEditorTheme, styles: theme.styles }\n };\n\n return (\n <LexicalComposer initialConfig={initialConfig}>\n <RichTextPlugin\n contentEditable={\n <div className=\"editor\">\n <ContentEditable />\n </div>\n }\n ErrorBoundary={LexicalErrorBoundary}\n placeholder={null}\n />\n <LexicalUpdateStatePlugin value={value} />\n </LexicalComposer>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAWO,IAAMA,mBAAuD,GAAG,SAA1DA,mBAAuD,OAI9D;EAAA,IAHFC,KAAK,QAALA,KAAK;IACLC,KAAK,QAALA,KAAK;IACLC,KAAK,QAALA,KAAK;EAEL,IAAMC,aAAa,GAAG;IAClBC,WAAW,EAAE,IAAAC,sCAAkB,EAACJ,KAAK,CAAC,GAAGA,KAAK,GAAG,IAAAK,wDAA2B,GAAE;IAC9EC,SAAS,EAAE,QAAQ;IACnBC,OAAO,EAAE,iBAACC,KAAY,EAAK;MACvB,MAAMA,KAAK;IACf,CAAC;IACDC,QAAQ,EAAE,KAAK;IACfV,KAAK,6CAAMW,wBAAW,oCAAMX,KAAK,IAAI,EAAE,EAAE;IACzCE,KAAK,8DAAOU,qCAAiB;MAAEC,MAAM,EAAEX,KAAK,CAACW;IAAM;EACvD,CAAC;EAED,oBACI,6BAAC,gCAAe;IAAC,aAAa,EAAEV;EAAc,gBAC1C,6BAAC,qCAAc;IACX,eAAe,eACX;MAAK,SAAS,EAAC;IAAQ,gBACnB,6BAAC,uCAAe,OAAG,CAE1B;IACD,aAAa,EAAEW,6BAAqB;IACpC,WAAW,EAAE;EAAK,EACpB,eACF,6BAAC,kDAAwB;IAAC,KAAK,EAAEb;EAAM,EAAG,CAC5B;AAE1B,CAAC;AAAC"}
1
+ {"version":3,"names":["BaseLexicalHtmlRenderer","nodes","value","theme","themeEmotionMap","initialConfig","editorState","isValidLexicalData","generateInitialLexicalValue","namespace","onError","error","editable","WebinyNodes","webinyEditorTheme","emotionMap","styles","LexicalErrorBoundary","LexicalHtmlRenderer","props","css","toTypographyEmotionMap"],"sources":["LexicalHtmlRenderer.tsx"],"sourcesContent":["import React from \"react\";\nimport { LexicalValue, ThemeEmotionMap } from \"~/types\";\nimport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\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 { LexicalUpdateStatePlugin } from \"~/plugins/LexicalUpdateStatePlugin\";\nimport { Klass, LexicalNode } from \"lexical\";\nimport { WebinyNodes } from \"~/nodes/webinyNodes\";\nimport { webinyEditorTheme, WebinyTheme } from \"~/themes/webinyLexicalTheme\";\nimport { ClassNames } from \"@emotion/react\";\nimport { toTypographyEmotionMap } from \"~/utils/toTypographyEmotionMap\";\n\ninterface LexicalHtmlRendererProps {\n nodes?: Klass<LexicalNode>[];\n value: LexicalValue | null;\n /*\n * @description Theme to be injected into lexical editor\n */\n theme: WebinyTheme;\n themeEmotionMap?: ThemeEmotionMap;\n}\n\nexport const BaseLexicalHtmlRenderer: React.FC<LexicalHtmlRendererProps> = ({\n nodes,\n value,\n theme,\n themeEmotionMap\n}) => {\n const initialConfig = {\n editorState: isValidLexicalData(value) ? value : generateInitialLexicalValue(),\n namespace: \"webiny\",\n onError: (error: Error) => {\n throw error;\n },\n editable: false,\n nodes: [...WebinyNodes, ...(nodes || [])],\n theme: { ...webinyEditorTheme, emotionMap: themeEmotionMap, styles: theme.styles }\n };\n\n return (\n <LexicalComposer initialConfig={initialConfig}>\n <RichTextPlugin\n contentEditable={\n <div className=\"editor\">\n <ContentEditable />\n </div>\n }\n ErrorBoundary={LexicalErrorBoundary}\n placeholder={null}\n />\n <LexicalUpdateStatePlugin value={value} />\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 ?? toTypographyEmotionMap(css, props.theme);\n return <BaseLexicalHtmlRenderer {...props} themeEmotionMap={themeEmotionMap} />;\n }}\n </ClassNames>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAYO,IAAMA,uBAA2D,GAAG,SAA9DA,uBAA2D,OAKlE;EAAA,IAJFC,KAAK,QAALA,KAAK;IACLC,KAAK,QAALA,KAAK;IACLC,KAAK,QAALA,KAAK;IACLC,eAAe,QAAfA,eAAe;EAEf,IAAMC,aAAa,GAAG;IAClBC,WAAW,EAAE,IAAAC,sCAAkB,EAACL,KAAK,CAAC,GAAGA,KAAK,GAAG,IAAAM,wDAA2B,GAAE;IAC9EC,SAAS,EAAE,QAAQ;IACnBC,OAAO,EAAE,iBAACC,KAAY,EAAK;MACvB,MAAMA,KAAK;IACf,CAAC;IACDC,QAAQ,EAAE,KAAK;IACfX,KAAK,6CAAMY,wBAAW,oCAAMZ,KAAK,IAAI,EAAE,EAAE;IACzCE,KAAK,8DAAOW,qCAAiB;MAAEC,UAAU,EAAEX,eAAe;MAAEY,MAAM,EAAEb,KAAK,CAACa;IAAM;EACpF,CAAC;EAED,oBACI,6BAAC,gCAAe;IAAC,aAAa,EAAEX;EAAc,gBAC1C,6BAAC,qCAAc;IACX,eAAe,eACX;MAAK,SAAS,EAAC;IAAQ,gBACnB,6BAAC,uCAAe,OAAG,CAE1B;IACD,aAAa,EAAEY,6BAAqB;IACpC,WAAW,EAAE;EAAK,EACpB,eACF,6BAAC,kDAAwB;IAAC,KAAK,EAAEf;EAAM,EAAG,CAC5B;AAE1B,CAAC;;AAED;AACA;AACA;AAFA;AAGO,IAAMgB,mBAAuD,GAAG,SAA1DA,mBAAuD,CAAGC,KAAK,EAAI;EAC5E,oBACI,6BAAC,kBAAU,QACN,iBAAa;IAAA;IAAA,IAAVC,GAAG,SAAHA,GAAG;IACH,IAAMhB,eAAe,4BACjBe,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEf,eAAe,yEAAI,IAAAiB,8CAAsB,EAACD,GAAG,EAAED,KAAK,CAAChB,KAAK,CAAC;IACtE,oBAAO,6BAAC,uBAAuB,oBAAKgB,KAAK;MAAE,eAAe,EAAEf;IAAgB,GAAG;EACnF,CAAC,CACQ;AAErB,CAAC;AAAC"}
@@ -19,12 +19,27 @@ require("./Toolbar.css");
19
19
  var _getDOMRangeRect = require("../../utils/getDOMRangeRect");
20
20
  var _setFloatingElemPosition = require("../../utils/setFloatingElemPosition");
21
21
  var _getSelectedNode = require("../../utils/getSelectedNode");
22
- var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
22
+ var _useRichTextEditor3 = require("../../hooks/useRichTextEditor");
23
+ var _getLexicalTextSelectionState = require("../../utils/getLexicalTextSelectionState");
23
24
  var FloatingToolbar = function FloatingToolbar(_ref) {
24
25
  var children = _ref.children,
26
+ type = _ref.type,
25
27
  anchorElem = _ref.anchorElem,
26
28
  editor = _ref.editor;
27
29
  var popupCharStylesEditorRef = (0, _react.useRef)(null);
30
+ var _useRichTextEditor = (0, _useRichTextEditor3.useRichTextEditor)(),
31
+ toolbarType = _useRichTextEditor.toolbarType,
32
+ setToolbarType = _useRichTextEditor.setToolbarType,
33
+ setTextBlockSelection = _useRichTextEditor.setTextBlockSelection;
34
+ var _useState = (0, _react.useState)(editor),
35
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
36
+ activeEditor = _useState2[0],
37
+ setActiveEditor = _useState2[1];
38
+ (0, _react.useEffect)(function () {
39
+ if (toolbarType !== type) {
40
+ setToolbarType(type);
41
+ }
42
+ }, [type]);
28
43
  var updateTextFormatFloatingToolbar = (0, _react.useCallback)(function () {
29
44
  var selection = (0, _lexical.$getSelection)();
30
45
  var popupCharStylesEditorElem = popupCharStylesEditorRef.current;
@@ -34,6 +49,10 @@ var FloatingToolbar = function FloatingToolbar(_ref) {
34
49
  }
35
50
  var isLink = false;
36
51
  if ((0, _lexical.$isRangeSelection)(selection)) {
52
+ var selectionState = (0, _getLexicalTextSelectionState.getLexicalTextSelectionState)(activeEditor, selection);
53
+ if (selectionState) {
54
+ setTextBlockSelection(selectionState);
55
+ }
37
56
  var node = (0, _getSelectedNode.getSelectedNode)(selection);
38
57
  // Update links
39
58
  var parent = node.getParent();
@@ -74,8 +93,9 @@ var FloatingToolbar = function FloatingToolbar(_ref) {
74
93
  editorState.read(function () {
75
94
  updateTextFormatFloatingToolbar();
76
95
  });
77
- }), editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function () {
96
+ }), editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
78
97
  updateTextFormatFloatingToolbar();
98
+ setActiveEditor(newEditor);
79
99
  return false;
80
100
  }, _lexical.COMMAND_PRIORITY_LOW));
81
101
  }, [editor, updateTextFormatFloatingToolbar]);
@@ -90,9 +110,9 @@ var useToolbar = function useToolbar(_ref3) {
90
110
  anchorElem = _ref3$anchorElem === void 0 ? document.body : _ref3$anchorElem,
91
111
  type = _ref3.type,
92
112
  children = _ref3.children;
93
- var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
94
- nodeIsText = _useRichTextEditor.nodeIsText,
95
- setNodeIsText = _useRichTextEditor.setNodeIsText;
113
+ var _useRichTextEditor2 = (0, _useRichTextEditor3.useRichTextEditor)(),
114
+ nodeIsText = _useRichTextEditor2.nodeIsText,
115
+ setNodeIsText = _useRichTextEditor2.setNodeIsText;
96
116
  var updatePopup = (0, _react.useCallback)(function () {
97
117
  editor.getEditorState().read(function () {
98
118
  // Should not to pop up the floating toolbar when using IME input
@@ -1 +1 @@
1
- {"version":3,"names":["FloatingToolbar","children","anchorElem","editor","popupCharStylesEditorRef","useRef","updateTextFormatFloatingToolbar","useCallback","selection","$getSelection","popupCharStylesEditorElem","current","nativeSelection","window","getSelection","isLink","$isRangeSelection","node","getSelectedNode","parent","getParent","$isLinkNode","rootElement","getRootElement","isCollapsed","contains","anchorNode","rangeRect","getDOMRangeRect","setFloatingElemPosition","useEffect","scrollerElem","parentElement","update","getEditorState","read","addEventListener","removeEventListener","mergeRegister","registerUpdateListener","editorState","registerCommand","SELECTION_CHANGE_COMMAND","COMMAND_PRIORITY_LOW","isEditable","useToolbar","document","body","type","useRichTextEditor","nodeIsText","setNodeIsText","updatePopup","isComposing","$isCodeHighlightNode","anchor","getNode","getTextContent","$isTextNode","registerRootListener","createPortal","Toolbar","makeComposable","useLexicalComposerContext"],"sources":["Toolbar.tsx"],"sourcesContent":["import React, { FC, useCallback, useEffect, useRef } from \"react\";\nimport {\n $getSelection,\n $isRangeSelection,\n $isTextNode,\n COMMAND_PRIORITY_LOW,\n LexicalEditor,\n SELECTION_CHANGE_COMMAND\n} from \"lexical\";\nimport { makeComposable } from \"@webiny/react-composition\";\nimport { $isLinkNode } from \"@lexical/link\";\nimport { createPortal } from \"react-dom\";\nimport { mergeRegister } from \"@lexical/utils\";\nimport { $isCodeHighlightNode } from \"@lexical/code\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport \"./Toolbar.css\";\nimport { ToolbarType } from \"~/types\";\nimport { getDOMRangeRect } from \"~/utils/getDOMRangeRect\";\nimport { setFloatingElemPosition } from \"~/utils/setFloatingElemPosition\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\n\ninterface FloatingToolbarProps {\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n editor: LexicalEditor;\n}\n\nconst FloatingToolbar: FC<FloatingToolbarProps> = ({ children, anchorElem, editor }) => {\n const popupCharStylesEditorRef = useRef<HTMLDivElement | null>(null);\n\n const updateTextFormatFloatingToolbar = useCallback(() => {\n const selection = $getSelection();\n\n const popupCharStylesEditorElem = popupCharStylesEditorRef.current;\n const nativeSelection = window.getSelection();\n\n if (popupCharStylesEditorElem === null) {\n return;\n }\n\n let isLink = false;\n if ($isRangeSelection(selection)) {\n const node = getSelectedNode(selection);\n // Update links\n const parent = node.getParent();\n\n if ($isLinkNode(parent) || $isLinkNode(node)) {\n isLink = true;\n }\n }\n\n const rootElement = editor.getRootElement();\n if (\n selection !== null &&\n nativeSelection !== null &&\n !nativeSelection.isCollapsed &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode) &&\n !isLink\n ) {\n const rangeRect = getDOMRangeRect(nativeSelection, rootElement);\n setFloatingElemPosition(rangeRect, popupCharStylesEditorElem, anchorElem);\n }\n }, [editor, anchorElem]);\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement;\n\n const update = () => {\n editor.getEditorState().read(() => {\n updateTextFormatFloatingToolbar();\n });\n };\n\n window.addEventListener(\"resize\", update);\n if (scrollerElem) {\n scrollerElem.addEventListener(\"scroll\", update);\n }\n\n return () => {\n window.removeEventListener(\"resize\", update);\n if (scrollerElem) {\n scrollerElem.removeEventListener(\"scroll\", update);\n }\n };\n }, [editor, updateTextFormatFloatingToolbar, anchorElem]);\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n updateTextFormatFloatingToolbar();\n });\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateTextFormatFloatingToolbar();\n });\n }),\n\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n updateTextFormatFloatingToolbar();\n return false;\n },\n COMMAND_PRIORITY_LOW\n )\n );\n }, [editor, updateTextFormatFloatingToolbar]);\n\n return (\n <div ref={popupCharStylesEditorRef} className=\"floating-text-format-popup\">\n {editor.isEditable() && children}\n </div>\n );\n};\n\ninterface useToolbarProps {\n editor: LexicalEditor;\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n}\n\nconst useToolbar: FC<useToolbarProps> = ({\n editor,\n anchorElem = document.body,\n type,\n children\n}): JSX.Element | null => {\n const { nodeIsText, setNodeIsText } = useRichTextEditor();\n\n const updatePopup = useCallback(() => {\n editor.getEditorState().read(() => {\n // Should not to pop up the floating toolbar when using IME input\n if (editor.isComposing()) {\n return;\n }\n const selection = $getSelection();\n const nativeSelection = window.getSelection();\n const rootElement = editor.getRootElement();\n\n if (\n nativeSelection !== null &&\n (!$isRangeSelection(selection) ||\n rootElement === null ||\n !rootElement.contains(nativeSelection.anchorNode))\n ) {\n setNodeIsText(false);\n return;\n }\n\n if (!$isRangeSelection(selection)) {\n return;\n }\n\n const node = getSelectedNode(selection);\n\n if (\n !$isCodeHighlightNode(selection.anchor.getNode()) &&\n selection.getTextContent() !== \"\"\n ) {\n setNodeIsText($isTextNode(node));\n } else {\n setNodeIsText(false);\n }\n });\n }, [editor]);\n\n useEffect(() => {\n document.addEventListener(\"selectionchange\", updatePopup);\n return () => {\n document.removeEventListener(\"selectionchange\", updatePopup);\n };\n }, [updatePopup]);\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(() => {\n updatePopup();\n }),\n editor.registerRootListener(() => {\n if (editor.getRootElement() === null) {\n setNodeIsText(false);\n }\n })\n );\n }, [editor, updatePopup]);\n\n if (!nodeIsText) {\n return null;\n }\n\n return createPortal(\n <FloatingToolbar type={type} anchorElem={anchorElem} editor={editor}>\n {children}\n </FloatingToolbar>,\n anchorElem\n );\n};\n\nexport interface ToolbarProps {\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n}\n\n/**\n * @description Main toolbar container\n */\nexport const Toolbar = makeComposable<ToolbarProps>(\n \"Toolbar\",\n ({ anchorElem, type, children }): JSX.Element | null => {\n const [editor] = useLexicalComposerContext();\n return useToolbar({ editor, anchorElem, type, children });\n }\n);\n"],"mappings":";;;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AASA,IAAMA,eAAyC,GAAG,SAA5CA,eAAyC,OAAyC;EAAA,IAAnCC,QAAQ,QAARA,QAAQ;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AC7D,CAAC,CACJ;AAAC"}
1
+ {"version":3,"names":["FloatingToolbar","children","type","anchorElem","editor","popupCharStylesEditorRef","useRef","useRichTextEditor","toolbarType","setToolbarType","setTextBlockSelection","useState","activeEditor","setActiveEditor","useEffect","updateTextFormatFloatingToolbar","useCallback","selection","$getSelection","popupCharStylesEditorElem","current","nativeSelection","window","getSelection","isLink","$isRangeSelection","selectionState","getLexicalTextSelectionState","node","getSelectedNode","parent","getParent","$isLinkNode","rootElement","getRootElement","isCollapsed","contains","anchorNode","rangeRect","getDOMRangeRect","setFloatingElemPosition","scrollerElem","parentElement","update","getEditorState","read","addEventListener","removeEventListener","mergeRegister","registerUpdateListener","editorState","registerCommand","SELECTION_CHANGE_COMMAND","_payload","newEditor","COMMAND_PRIORITY_LOW","isEditable","useToolbar","document","body","nodeIsText","setNodeIsText","updatePopup","isComposing","$isCodeHighlightNode","anchor","getNode","getTextContent","$isTextNode","registerRootListener","createPortal","Toolbar","makeComposable","useLexicalComposerContext"],"sources":["Toolbar.tsx"],"sourcesContent":["import React, { FC, useCallback, useEffect, useRef, useState } from \"react\";\nimport {\n $getSelection,\n $isRangeSelection,\n $isTextNode,\n COMMAND_PRIORITY_LOW,\n LexicalEditor,\n SELECTION_CHANGE_COMMAND\n} from \"lexical\";\nimport { makeComposable } from \"@webiny/react-composition\";\nimport { $isLinkNode } from \"@lexical/link\";\nimport { createPortal } from \"react-dom\";\nimport { mergeRegister } from \"@lexical/utils\";\nimport { $isCodeHighlightNode } from \"@lexical/code\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport \"./Toolbar.css\";\nimport { ToolbarType } from \"~/types\";\nimport { getDOMRangeRect } from \"~/utils/getDOMRangeRect\";\nimport { setFloatingElemPosition } from \"~/utils/setFloatingElemPosition\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { getLexicalTextSelectionState } from \"~/utils/getLexicalTextSelectionState\";\n\ninterface FloatingToolbarProps {\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n editor: LexicalEditor;\n}\n\nconst FloatingToolbar: FC<FloatingToolbarProps> = ({ children, type, anchorElem, editor }) => {\n const popupCharStylesEditorRef = useRef<HTMLDivElement | null>(null);\n const { toolbarType, setToolbarType, setTextBlockSelection } = useRichTextEditor();\n const [activeEditor, setActiveEditor] = useState(editor);\n\n useEffect(() => {\n if (toolbarType !== type) {\n setToolbarType(type);\n }\n }, [type]);\n\n const updateTextFormatFloatingToolbar = useCallback(() => {\n const selection = $getSelection();\n\n const popupCharStylesEditorElem = popupCharStylesEditorRef.current;\n const nativeSelection = window.getSelection();\n\n if (popupCharStylesEditorElem === null) {\n return;\n }\n\n let isLink = false;\n if ($isRangeSelection(selection)) {\n const selectionState = getLexicalTextSelectionState(activeEditor, selection);\n if (selectionState) {\n setTextBlockSelection(selectionState);\n }\n const node = getSelectedNode(selection);\n // Update links\n const parent = node.getParent();\n\n if ($isLinkNode(parent) || $isLinkNode(node)) {\n isLink = true;\n }\n }\n\n const rootElement = editor.getRootElement();\n if (\n selection !== null &&\n nativeSelection !== null &&\n !nativeSelection.isCollapsed &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode) &&\n !isLink\n ) {\n const rangeRect = getDOMRangeRect(nativeSelection, rootElement);\n setFloatingElemPosition(rangeRect, popupCharStylesEditorElem, anchorElem);\n }\n }, [editor, anchorElem]);\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement;\n\n const update = () => {\n editor.getEditorState().read(() => {\n updateTextFormatFloatingToolbar();\n });\n };\n\n window.addEventListener(\"resize\", update);\n if (scrollerElem) {\n scrollerElem.addEventListener(\"scroll\", update);\n }\n\n return () => {\n window.removeEventListener(\"resize\", update);\n if (scrollerElem) {\n scrollerElem.removeEventListener(\"scroll\", update);\n }\n };\n }, [editor, updateTextFormatFloatingToolbar, anchorElem]);\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n updateTextFormatFloatingToolbar();\n });\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateTextFormatFloatingToolbar();\n });\n }),\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n (_payload, newEditor) => {\n updateTextFormatFloatingToolbar();\n setActiveEditor(newEditor);\n return false;\n },\n COMMAND_PRIORITY_LOW\n )\n );\n }, [editor, updateTextFormatFloatingToolbar]);\n\n return (\n <div ref={popupCharStylesEditorRef} className=\"floating-text-format-popup\">\n {editor.isEditable() && children}\n </div>\n );\n};\n\ninterface useToolbarProps {\n editor: LexicalEditor;\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n}\n\nconst useToolbar: FC<useToolbarProps> = ({\n editor,\n anchorElem = document.body,\n type,\n children\n}): JSX.Element | null => {\n const { nodeIsText, setNodeIsText } = useRichTextEditor();\n\n const updatePopup = useCallback(() => {\n editor.getEditorState().read(() => {\n // Should not to pop up the floating toolbar when using IME input\n if (editor.isComposing()) {\n return;\n }\n const selection = $getSelection();\n const nativeSelection = window.getSelection();\n const rootElement = editor.getRootElement();\n\n if (\n nativeSelection !== null &&\n (!$isRangeSelection(selection) ||\n rootElement === null ||\n !rootElement.contains(nativeSelection.anchorNode))\n ) {\n setNodeIsText(false);\n return;\n }\n\n if (!$isRangeSelection(selection)) {\n return;\n }\n\n const node = getSelectedNode(selection);\n if (\n !$isCodeHighlightNode(selection.anchor.getNode()) &&\n selection.getTextContent() !== \"\"\n ) {\n setNodeIsText($isTextNode(node));\n } else {\n setNodeIsText(false);\n }\n });\n }, [editor]);\n\n useEffect(() => {\n document.addEventListener(\"selectionchange\", updatePopup);\n return () => {\n document.removeEventListener(\"selectionchange\", updatePopup);\n };\n }, [updatePopup]);\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(() => {\n updatePopup();\n }),\n editor.registerRootListener(() => {\n if (editor.getRootElement() === null) {\n setNodeIsText(false);\n }\n })\n );\n }, [editor, updatePopup]);\n\n if (!nodeIsText) {\n return null;\n }\n\n return createPortal(\n <FloatingToolbar type={type} anchorElem={anchorElem} editor={editor}>\n {children}\n </FloatingToolbar>,\n anchorElem\n );\n};\n\nexport interface ToolbarProps {\n type: ToolbarType;\n anchorElem: HTMLElement;\n children?: React.ReactNode;\n}\n\n/**\n * @description Main toolbar container\n */\nexport const Toolbar = makeComposable<ToolbarProps>(\n \"Toolbar\",\n ({ anchorElem, type, children }): JSX.Element | null => {\n const [editor] = useLexicalComposerContext();\n return useToolbar({ editor, anchorElem, type, children });\n }\n);\n"],"mappings":";;;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AASA,IAAMA,eAAyC,GAAG,SAA5CA,eAAyC,OAA+C;EAAA,IAAzCC,QAAQ,QAARA,QAAQ;IAAEC,IAAI,QAAJA,IAAI;IAAEC,UAAU,QAAVA,UAAU;IAAEC,MAAM,QAANA,MAAM;EACnF,IAAMC,wBAAwB,GAAG,IAAAC,aAAM,EAAwB,IAAI,CAAC;EACpE,yBAA+D,IAAAC,qCAAiB,GAAE;IAA1EC,WAAW,sBAAXA,WAAW;IAAEC,cAAc,sBAAdA,cAAc;IAAEC,qBAAqB,sBAArBA,qBAAqB;EAC1D,gBAAwC,IAAAC,eAAQ,EAACP,MAAM,CAAC;IAAA;IAAjDQ,YAAY;IAAEC,eAAe;EAEpC,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAIN,WAAW,KAAKN,IAAI,EAAE;MACtBO,cAAc,CAACP,IAAI,CAAC;IACxB;EACJ,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;EAEV,IAAMa,+BAA+B,GAAG,IAAAC,kBAAW,EAAC,YAAM;IACtD,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;IAEjC,IAAMC,yBAAyB,GAAGd,wBAAwB,CAACe,OAAO;IAClE,IAAMC,eAAe,GAAGC,MAAM,CAACC,YAAY,EAAE;IAE7C,I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,WAAW,CAAC;IACzD,OAAO,YAAM;MACTJ,QAAQ,CAACX,mBAAmB,CAAC,iBAAiB,EAAEe,WAAW,CAAC;IAChE,CAAC;EACL,CAAC,EAAE,CAACA,WAAW,CAAC,CAAC;EAEjB,IAAAhD,gBAAS,EAAC,YAAM;IACZ,OAAO,IAAAkC,oBAAa,EAChB5C,MAAM,CAAC6C,sBAAsB,CAAC,YAAM;MAChCa,WAAW,EAAE;IACjB,CAAC,CAAC,EACF1D,MAAM,CAACiE,oBAAoB,CAAC,YAAM;MAC9B,IAAIjE,MAAM,CAAC8B,cAAc,EAAE,KAAK,IAAI,EAAE;QAClC2B,aAAa,CAAC,KAAK,CAAC;MACxB;IACJ,CAAC,CAAC,CACL;EACL,CAAC,EAAE,CAACzD,MAAM,EAAE0D,WAAW,CAAC,CAAC;EAEzB,IAAI,CAACF,UAAU,EAAE;IACb,OAAO,IAAI;EACf;EAEA,oBAAO,IAAAU,sBAAY,gBACf,6BAAC,eAAe;IAAC,IAAI,EAAEpE,IAAK;IAAC,UAAU,EAAEC,UAAW;IAAC,MAAM,EAAEC;EAAO,GAC/DH,QAAQ,CACK,EAClBE,UAAU,CACb;AACL,CAAC;AAQD;AACA;AACA;AACO,IAAMoE,OAAO,GAAG,IAAAC,gCAAc,EACjC,SAAS,EACT,iBAAwD;EAAA,IAArDrE,UAAU,SAAVA,UAAU;IAAED,IAAI,SAAJA,IAAI;IAAED,QAAQ,SAARA,QAAQ;EACzB,4BAAiB,IAAAwE,iDAAyB,GAAE;IAAA;IAArCrE,MAAM;EACb,OAAOqD,UAAU,CAAC;IAAErD,MAAM,EAANA,MAAM;IAAED,UAAU,EAAVA,UAAU;IAAED,IAAI,EAAJA,IAAI;IAAED,QAAQ,EAARA;EAAS,CAAC,CAAC;AAC7D,CAAC,CACJ;AAAC"}
@@ -1,5 +1,2 @@
1
1
  /// <reference types="react" />
2
- /**
3
- * Toolbar action. On toolbar, you can see as button that is bold.
4
- */
5
2
  export declare const BoldAction: () => JSX.Element;
@@ -10,10 +10,9 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
10
10
  var _react = _interopRequireWildcard(require("react"));
11
11
  var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
12
12
  var _lexical = require("lexical");
13
- /**
14
- * Toolbar action. On toolbar, you can see as button that is bold.
15
- */
13
+ var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
16
14
  var BoldAction = function BoldAction() {
15
+ var _textBlockSelection$s;
17
16
  var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
18
17
  _useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
19
18
  editor = _useLexicalComposerCo2[0];
@@ -21,10 +20,16 @@ var BoldAction = function BoldAction() {
21
20
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
22
21
  isBold = _useState2[0],
23
22
  setIsBold = _useState2[1];
23
+ var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
24
+ textBlockSelection = _useRichTextEditor.textBlockSelection;
25
+ var isBoldSelected = !!(textBlockSelection !== null && textBlockSelection !== void 0 && (_textBlockSelection$s = textBlockSelection.state) !== null && _textBlockSelection$s !== void 0 && _textBlockSelection$s.bold);
24
26
  var handleClick = function handleClick() {
25
27
  editor.dispatchCommand(_lexical.FORMAT_TEXT_COMMAND, "bold");
26
28
  setIsBold(!isBold);
27
29
  };
30
+ (0, _react.useEffect)(function () {
31
+ setIsBold(isBoldSelected);
32
+ }, [isBoldSelected]);
28
33
  return /*#__PURE__*/_react.default.createElement("button", {
29
34
  onClick: function onClick() {
30
35
  return handleClick();
@@ -1 +1 @@
1
- {"version":3,"names":["BoldAction","useLexicalComposerContext","editor","useState","isBold","setIsBold","handleClick","dispatchCommand","FORMAT_TEXT_COMMAND"],"sources":["BoldAction.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { FORMAT_TEXT_COMMAND } from \"lexical\";\n\n/**\n * Toolbar action. On toolbar, you can see as button that is bold.\n */\nexport const BoldAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isBold, setIsBold] = useState(false);\n const handleClick = () => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, \"bold\");\n setIsBold(!isBold);\n };\n\n return (\n <button\n onClick={() => handleClick()}\n className={\"popup-item spaced \" + (isBold ? \"active\" : \"\")}\n aria-label=\"Format text as bold\"\n >\n <i className=\"format bold\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AAEA;AACA;AACA;AACO,IAAMA,UAAU,GAAG,SAAbA,UAAU,GAAS;EAC5B,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAA4B,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAApCC,MAAM;IAAEC,SAAS;EACxB,IAAMC,WAAW,GAAG,SAAdA,WAAW,GAAS;IACtBJ,MAAM,CAACK,eAAe,CAACC,4BAAmB,EAAE,MAAM,CAAC;IACnDH,SAAS,CAAC,CAACD,MAAM,CAAC;EACtB,CAAC;EAED,oBACI;IACI,OAAO,EAAE;MAAA,OAAME,WAAW,EAAE;IAAA,CAAC;IAC7B,SAAS,EAAE,oBAAoB,IAAIF,MAAM,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC3D,cAAW;EAAqB,gBAEhC;IAAG,SAAS,EAAC;EAAa,EAAG,CACxB;AAEjB,CAAC;AAAC"}
1
+ {"version":3,"names":["BoldAction","useLexicalComposerContext","editor","useState","isBold","setIsBold","useRichTextEditor","textBlockSelection","isBoldSelected","state","bold","handleClick","dispatchCommand","FORMAT_TEXT_COMMAND","useEffect"],"sources":["BoldAction.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { FORMAT_TEXT_COMMAND } from \"lexical\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\n\nexport const BoldAction = () => {\n const [editor] = useLexicalComposerContext();\n const [isBold, setIsBold] = useState(false);\n const { textBlockSelection } = useRichTextEditor();\n const isBoldSelected = !!textBlockSelection?.state?.bold;\n\n const handleClick = () => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, \"bold\");\n setIsBold(!isBold);\n };\n\n useEffect(() => {\n setIsBold(isBoldSelected);\n }, [isBoldSelected]);\n\n return (\n <button\n onClick={() => handleClick()}\n className={\"popup-item spaced \" + (isBold ? \"active\" : \"\")}\n aria-label=\"Format text as bold\"\n >\n <i className=\"format bold\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AAEO,IAAMA,UAAU,GAAG,SAAbA,UAAU,GAAS;EAAA;EAC5B,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,gBAA4B,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAApCC,MAAM;IAAEC,SAAS;EACxB,yBAA+B,IAAAC,qCAAiB,GAAE;IAA1CC,kBAAkB,sBAAlBA,kBAAkB;EAC1B,IAAMC,cAAc,GAAG,CAAC,EAACD,kBAAkB,aAAlBA,kBAAkB,wCAAlBA,kBAAkB,CAAEE,KAAK,kDAAzB,sBAA2BC,IAAI;EAExD,IAAMC,WAAW,GAAG,SAAdA,WAAW,GAAS;IACtBT,MAAM,CAACU,eAAe,CAACC,4BAAmB,EAAE,MAAM,CAAC;IACnDR,SAAS,CAAC,CAACD,MAAM,CAAC;EACtB,CAAC;EAED,IAAAU,gBAAS,EAAC,YAAM;IACZT,SAAS,CAACG,cAAc,CAAC;EAC7B,CAAC,EAAE,CAACA,cAAc,CAAC,CAAC;EAEpB,oBACI;IACI,OAAO,EAAE;MAAA,OAAMG,WAAW,EAAE;IAAA,CAAC;IAC7B,SAAS,EAAE,oBAAoB,IAAIP,MAAM,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC3D,cAAW;EAAqB,gBAEhC;IAAG,SAAS,EAAC;EAAa,EAAG,CACxB;AAEjB,CAAC;AAAC"}
@@ -1,5 +1,2 @@
1
1
  /// <reference types="react" />
2
- /**
3
- * Toolbar button action. On click will wrap the content in bullet list style.
4
- */
5
2
  export declare const BulletListAction: () => JSX.Element;