@webiny/lexical-editor 5.44.1-beta.0 → 5.45.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/README.md +6 -12
  2. package/commands/image.d.ts +2 -2
  3. package/commands/image.js +2 -8
  4. package/commands/image.js.map +1 -1
  5. package/commands/index.d.ts +5 -4
  6. package/commands/index.js +5 -49
  7. package/commands/index.js.map +1 -1
  8. package/commands/list.d.ts +1 -1
  9. package/commands/list.js +4 -10
  10. package/commands/list.js.map +1 -1
  11. package/commands/quote.d.ts +1 -1
  12. package/commands/quote.js +2 -8
  13. package/commands/quote.js.map +1 -1
  14. package/commands/toolbar.js +2 -8
  15. package/commands/toolbar.js.map +1 -1
  16. package/commands/typography.d.ts +8 -0
  17. package/commands/typography.js +4 -0
  18. package/commands/typography.js.map +1 -0
  19. package/components/Editor/EnsureHeadingTagPlugin.js +10 -16
  20. package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -1
  21. package/components/Editor/RichTextEditor.d.ts +12 -8
  22. package/components/Editor/RichTextEditor.js +89 -102
  23. package/components/Editor/RichTextEditor.js.map +1 -1
  24. package/components/Editor/normalizeInputValue.d.ts +1 -1
  25. package/components/Editor/normalizeInputValue.js +2 -8
  26. package/components/Editor/normalizeInputValue.js.map +1 -1
  27. package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +14 -16
  28. package/components/LexicalEditorConfig/LexicalEditorConfig.js +21 -69
  29. package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
  30. package/components/LexicalEditorConfig/components/Node.d.ts +1 -1
  31. package/components/LexicalEditorConfig/components/Node.js +17 -26
  32. package/components/LexicalEditorConfig/components/Node.js.map +1 -1
  33. package/components/LexicalEditorConfig/components/Plugin.js +17 -26
  34. package/components/LexicalEditorConfig/components/Plugin.js.map +1 -1
  35. package/components/LexicalEditorConfig/components/ToolbarElement.js +17 -26
  36. package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -1
  37. package/components/LexicalHtmlRenderer.d.ts +4 -7
  38. package/components/LexicalHtmlRenderer.js +35 -53
  39. package/components/LexicalHtmlRenderer.js.map +1 -1
  40. package/components/Toolbar/StaticToolbar.css +416 -0
  41. package/components/Toolbar/StaticToolbar.d.ts +3 -1
  42. package/components/Toolbar/StaticToolbar.js +19 -23
  43. package/components/Toolbar/StaticToolbar.js.map +1 -1
  44. package/components/ToolbarActions/BoldAction.js +16 -21
  45. package/components/ToolbarActions/BoldAction.js.map +1 -1
  46. package/components/ToolbarActions/BulletListAction.js +25 -31
  47. package/components/ToolbarActions/BulletListAction.js.map +1 -1
  48. package/components/ToolbarActions/CodeHighlightAction.js +16 -21
  49. package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
  50. package/components/ToolbarActions/FontColorAction.js +32 -42
  51. package/components/ToolbarActions/FontColorAction.js.map +1 -1
  52. package/components/ToolbarActions/ImageAction.js +19 -34
  53. package/components/ToolbarActions/ImageAction.js.map +1 -1
  54. package/components/ToolbarActions/ItalicAction.js +16 -21
  55. package/components/ToolbarActions/ItalicAction.js.map +1 -1
  56. package/components/ToolbarActions/LinkAction.js +19 -24
  57. package/components/ToolbarActions/LinkAction.js.map +1 -1
  58. package/components/ToolbarActions/NumberedListAction.js +25 -36
  59. package/components/ToolbarActions/NumberedListAction.js.map +1 -1
  60. package/components/ToolbarActions/QuoteAction.js +20 -25
  61. package/components/ToolbarActions/QuoteAction.js.map +1 -1
  62. package/components/ToolbarActions/TextAlignmentAction.js +36 -45
  63. package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
  64. package/components/ToolbarActions/TypographyAction.js +57 -79
  65. package/components/ToolbarActions/TypographyAction.js.map +1 -1
  66. package/components/ToolbarActions/UnderlineAction.js +16 -21
  67. package/components/ToolbarActions/UnderlineAction.js.map +1 -1
  68. package/context/FontColorActionContext.js +2 -9
  69. package/context/FontColorActionContext.js.map +1 -1
  70. package/context/RichTextEditorContext.d.ts +6 -7
  71. package/context/RichTextEditorContext.js +28 -26
  72. package/context/RichTextEditorContext.js.map +1 -1
  73. package/context/SharedHistoryContext.d.ts +2 -2
  74. package/context/SharedHistoryContext.js +12 -20
  75. package/context/SharedHistoryContext.js.map +1 -1
  76. package/context/TextAlignmentActionContextProps.d.ts +1 -1
  77. package/context/TextAlignmentActionContextProps.js +2 -9
  78. package/context/TextAlignmentActionContextProps.js.map +1 -1
  79. package/context/TypographyActionContext.d.ts +3 -2
  80. package/context/TypographyActionContext.js +2 -9
  81. package/context/TypographyActionContext.js.map +1 -1
  82. package/exports/admin/lexical.d.ts +15 -0
  83. package/exports/admin/lexical.js +23 -0
  84. package/exports/admin/lexical.js.map +1 -0
  85. package/hooks/index.d.ts +7 -8
  86. package/hooks/index.js +7 -93
  87. package/hooks/index.js.map +1 -1
  88. package/hooks/useCurrentElement.d.ts +3 -3
  89. package/hooks/useCurrentElement.js +11 -18
  90. package/hooks/useCurrentElement.js.map +1 -1
  91. package/hooks/useCurrentSelection.d.ts +2 -1
  92. package/hooks/useCurrentSelection.js +27 -40
  93. package/hooks/useCurrentSelection.js.map +1 -1
  94. package/hooks/useFontColorPicker.d.ts +1 -1
  95. package/hooks/useFontColorPicker.js +5 -11
  96. package/hooks/useFontColorPicker.js.map +1 -1
  97. package/hooks/useIsMounted.js +6 -14
  98. package/hooks/useIsMounted.js.map +1 -1
  99. package/hooks/useRichTextEditor.d.ts +1 -1
  100. package/hooks/useRichTextEditor.js +5 -11
  101. package/hooks/useRichTextEditor.js.map +1 -1
  102. package/hooks/useTextAlignmentAction.d.ts +1 -1
  103. package/hooks/useTextAlignmentAction.js +5 -11
  104. package/hooks/useTextAlignmentAction.js.map +1 -1
  105. package/hooks/useTypographyAction.d.ts +1 -1
  106. package/hooks/useTypographyAction.js +5 -11
  107. package/hooks/useTypographyAction.js.map +1 -1
  108. package/index.d.ts +33 -38
  109. package/index.js +44 -322
  110. package/index.js.map +1 -1
  111. package/package.json +18 -22
  112. package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +2 -2
  113. package/plugins/BlurEventPlugin/BlurEventPlugin.js +16 -22
  114. package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
  115. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +9 -14
  116. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
  117. package/plugins/CodeHighlightPlugin/index.d.ts +1 -1
  118. package/plugins/CodeHighlightPlugin/index.js +1 -16
  119. package/plugins/CodeHighlightPlugin/index.js.map +1 -1
  120. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +10 -0
  121. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +28 -0
  122. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -0
  123. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +7 -0
  124. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +61 -0
  125. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -0
  126. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +2 -136
  127. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +4 -16
  128. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +7 -180
  129. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
  130. package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -1
  131. package/plugins/FloatingLinkEditorPlugin/index.js +1 -16
  132. package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
  133. package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js +3 -9
  134. package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js.map +1 -1
  135. package/plugins/FloatingLinkEditorPlugin/types.d.ts +10 -0
  136. package/plugins/FloatingLinkEditorPlugin/types.js +3 -0
  137. package/plugins/FloatingLinkEditorPlugin/types.js.map +1 -0
  138. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +8 -2
  139. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +120 -88
  140. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +1 -1
  141. package/plugins/FontColorPlugin/FontColorPlugin.js +19 -22
  142. package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
  143. package/plugins/FontColorPlugin/applyColorToNode.d.ts +2 -2
  144. package/plugins/FontColorPlugin/applyColorToNode.js +4 -10
  145. package/plugins/FontColorPlugin/applyColorToNode.js.map +1 -1
  146. package/plugins/FontColorPlugin/applyColorToSelection.d.ts +2 -2
  147. package/plugins/FontColorPlugin/applyColorToSelection.js +28 -44
  148. package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -1
  149. package/plugins/ImagesPlugin/ImagesPlugin.d.ts +1 -2
  150. package/plugins/ImagesPlugin/ImagesPlugin.js +58 -60
  151. package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
  152. package/plugins/LinkPlugin/LinkPlugin.js +29 -37
  153. package/plugins/LinkPlugin/LinkPlugin.js.map +1 -1
  154. package/plugins/ListPLugin/ListPlugin.js +52 -15
  155. package/plugins/ListPLugin/ListPlugin.js.map +1 -1
  156. package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +19 -16
  157. package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -1
  158. package/plugins/StateHandlingPlugin.d.ts +1 -1
  159. package/plugins/StateHandlingPlugin.js +32 -39
  160. package/plugins/StateHandlingPlugin.js.map +1 -1
  161. package/plugins/TypographyPlugin/TypographyPlugin.js +17 -21
  162. package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
  163. package/types.d.ts +4 -4
  164. package/types.js +6 -38
  165. package/types.js.map +1 -1
  166. package/ui/ContentEditable.d.ts +0 -1
  167. package/ui/ContentEditable.js +7 -14
  168. package/ui/ContentEditable.js.map +1 -1
  169. package/ui/Divider.d.ts +0 -1
  170. package/ui/Divider.js +3 -10
  171. package/ui/Divider.js.map +1 -1
  172. package/ui/DropDown.d.ts +1 -1
  173. package/ui/DropDown.js +64 -90
  174. package/ui/DropDown.js.map +1 -1
  175. package/ui/ImageResizer.d.ts +0 -1
  176. package/ui/ImageResizer.js +78 -83
  177. package/ui/ImageResizer.js.map +1 -1
  178. package/ui/LinkPreview.d.ts +0 -1
  179. package/ui/LinkPreview.js +22 -29
  180. package/ui/LinkPreview.js.map +1 -1
  181. package/ui/Placeholder.d.ts +1 -1
  182. package/ui/Placeholder.js +10 -16
  183. package/ui/Placeholder.js.map +1 -1
  184. package/ui/TextInput.d.ts +0 -1
  185. package/ui/TextInput.js +11 -18
  186. package/ui/TextInput.js.map +1 -1
  187. package/ui/ToolbarActionDialog.js +30 -42
  188. package/ui/ToolbarActionDialog.js.map +1 -1
  189. package/utils/canUseDOM.js +1 -7
  190. package/utils/canUseDOM.js.map +1 -1
  191. package/utils/files.d.ts +6 -6
  192. package/utils/files.js +5 -32
  193. package/utils/files.js.map +1 -1
  194. package/utils/getDOMRangeRect.js +4 -10
  195. package/utils/getDOMRangeRect.js.map +1 -1
  196. package/utils/getSelectedNode.d.ts +1 -1
  197. package/utils/getSelectedNode.js +9 -16
  198. package/utils/getSelectedNode.js.map +1 -1
  199. package/utils/getTransparentImage.js +1 -7
  200. package/utils/getTransparentImage.js.map +1 -1
  201. package/utils/insertImage.d.ts +1 -1
  202. package/utils/insertImage.js +8 -14
  203. package/utils/insertImage.js.map +1 -1
  204. package/utils/isAnchorLink.js +1 -7
  205. package/utils/isAnchorLink.js.map +1 -1
  206. package/utils/isChildOfFloatingToolbar.js +3 -12
  207. package/utils/isChildOfFloatingToolbar.js.map +1 -1
  208. package/utils/isHTMLElement.js +1 -7
  209. package/utils/isHTMLElement.js.map +1 -1
  210. package/utils/isValidJSON.js +3 -9
  211. package/utils/isValidJSON.js.map +1 -1
  212. package/utils/isValidLexicalData.d.ts +3 -3
  213. package/utils/isValidLexicalData.js +6 -12
  214. package/utils/isValidLexicalData.js.map +1 -1
  215. package/utils/point.js +35 -60
  216. package/utils/point.js.map +1 -1
  217. package/utils/rect.d.ts +1 -1
  218. package/utils/rect.js +115 -149
  219. package/utils/rect.js.map +1 -1
  220. package/utils/sanitizeUrl.js +6 -13
  221. package/utils/sanitizeUrl.js.map +1 -1
  222. package/utils/setFloatingElemPosition.d.ts +1 -1
  223. package/utils/setFloatingElemPosition.js +24 -30
  224. package/utils/setFloatingElemPosition.js.map +1 -1
  225. package/components/Editor/HeadingEditor.d.ts +0 -7
  226. package/components/Editor/HeadingEditor.js +0 -30
  227. package/components/Editor/HeadingEditor.js.map +0 -1
  228. package/components/Editor/ParagraphEditor.d.ts +0 -7
  229. package/components/Editor/ParagraphEditor.js +0 -29
  230. package/components/Editor/ParagraphEditor.js.map +0 -1
  231. package/components/Toolbar/Toolbar.css +0 -643
  232. package/components/Toolbar/Toolbar.d.ts +0 -11
  233. package/components/Toolbar/Toolbar.js +0 -165
  234. package/components/Toolbar/Toolbar.js.map +0 -1
  235. package/components/ToolbarActions/FontSizeAction.d.ts +0 -14
  236. package/components/ToolbarActions/FontSizeAction.js +0 -109
  237. package/components/ToolbarActions/FontSizeAction.js.map +0 -1
  238. package/hooks/useList.d.ts +0 -2
  239. package/hooks/useList.js +0 -54
  240. package/hooks/useList.js.map +0 -1
  241. package/hooks/useQuote.d.ts +0 -2
  242. package/hooks/useQuote.js +0 -22
  243. package/hooks/useQuote.js.map +0 -1
  244. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +0 -9
  245. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +0 -118
  246. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +0 -1
  247. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +0 -9
  248. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +0 -44
  249. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js.map +0 -1
  250. package/utils/generateInitialLexicalValue.d.ts +0 -4
  251. package/utils/generateInitialLexicalValue.js +0 -33
  252. package/utils/generateInitialLexicalValue.js.map +0 -1
@@ -1,53 +1,42 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.NumberedListAction = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _lexicalNodes = require("@webiny/lexical-nodes");
10
- var _lexicalTheme = require("@webiny/lexical-theme");
11
- var _commands = require("../../commands");
12
- var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
13
- var _useCurrentElement2 = require("../../hooks/useCurrentElement");
14
- var NumberedListAction = exports.NumberedListAction = function NumberedListAction() {
15
- var _useCurrentElement = (0, _useCurrentElement2.useCurrentElement)(),
16
- element = _useCurrentElement.element;
17
- var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
18
- editor = _useRichTextEditor.editor,
19
- themeEmotionMap = _useRichTextEditor.themeEmotionMap;
20
- var isList = (0, _lexicalNodes.$isListNode)(element);
21
- var isNumbered = isList && element.getListType() === "number";
22
- var getStyleId = function getStyleId() {
23
- if (!themeEmotionMap) {
24
- return undefined;
25
- }
1
+ import React from "react";
2
+ import { $isListNode } from "@webiny/lexical-nodes";
3
+ import { INSERT_ORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND } from "../../commands/index.js";
4
+ import { useRichTextEditor } from "../../hooks/useRichTextEditor.js";
5
+ import { useCurrentElement } from "../../hooks/useCurrentElement.js";
6
+ export const NumberedListAction = () => {
7
+ const {
8
+ element
9
+ } = useCurrentElement();
10
+ const {
11
+ editor,
12
+ theme
13
+ } = useRichTextEditor();
14
+ const isList = $isListNode(element);
15
+ const isNumbered = isList && element.getListType() === "number";
16
+ const getStyleId = () => {
26
17
  // check default style for numbered list
27
- var id = (0, _lexicalTheme.findTypographyStyleByHtmlTag)("ol", themeEmotionMap)?.id;
18
+ const id = theme.getTypographyByTag("ol")?.id;
28
19
  if (id) {
29
20
  return id;
30
21
  }
31
22
  // fallback to ul list styles
32
- return (0, _lexicalTheme.findTypographyStyleByHtmlTag)("ul", themeEmotionMap)?.id;
23
+ return theme.getTypographyByTag("ul")?.id;
33
24
  };
34
- var formatNumberedList = function formatNumberedList() {
25
+ const formatNumberedList = () => {
35
26
  if (!isNumbered) {
36
- var styleId = themeEmotionMap ? getStyleId() : undefined;
37
- editor.dispatchCommand(_commands.INSERT_ORDERED_LIST_COMMAND, {
27
+ const styleId = getStyleId();
28
+ editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, {
38
29
  themeStyleId: styleId
39
30
  });
40
31
  } else {
41
- editor.dispatchCommand(_commands.REMOVE_LIST_COMMAND, undefined);
32
+ editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
42
33
  }
43
34
  };
44
- return /*#__PURE__*/_react.default.createElement("button", {
45
- onClick: function onClick() {
46
- return formatNumberedList();
47
- },
35
+ return /*#__PURE__*/React.createElement("button", {
36
+ onClick: () => formatNumberedList(),
48
37
  className: "popup-item spaced " + (isNumbered ? "active" : ""),
49
38
  "aria-label": "Format text as numbered list"
50
- }, /*#__PURE__*/_react.default.createElement("i", {
39
+ }, /*#__PURE__*/React.createElement("i", {
51
40
  className: "icon numbered-list"
52
41
  }));
53
42
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_lexicalNodes","_lexicalTheme","_commands","_useRichTextEditor2","_useCurrentElement2","NumberedListAction","exports","_useCurrentElement","useCurrentElement","element","_useRichTextEditor","useRichTextEditor","editor","themeEmotionMap","isList","$isListNode","isNumbered","getListType","getStyleId","undefined","id","findTypographyStyleByHtmlTag","formatNumberedList","styleId","dispatchCommand","INSERT_ORDERED_LIST_COMMAND","themeStyleId","REMOVE_LIST_COMMAND","default","createElement","onClick","className"],"sources":["NumberedListAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { $isListNode, ListNode } from \"@webiny/lexical-nodes\";\nimport { findTypographyStyleByHtmlTag } from \"@webiny/lexical-theme\";\nimport { INSERT_ORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND } from \"~/commands\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement\";\n\nexport const NumberedListAction = () => {\n const { element } = useCurrentElement();\n const { editor, themeEmotionMap } = useRichTextEditor();\n const isList = $isListNode(element);\n const isNumbered = isList && (element as ListNode).getListType() === \"number\";\n\n const getStyleId = (): string | undefined => {\n if (!themeEmotionMap) {\n return undefined;\n }\n // check default style for numbered list\n const id = findTypographyStyleByHtmlTag(\"ol\", themeEmotionMap)?.id;\n if (id) {\n return id;\n }\n // fallback to ul list styles\n return findTypographyStyleByHtmlTag(\"ul\", themeEmotionMap)?.id;\n };\n\n const formatNumberedList = () => {\n if (!isNumbered) {\n const styleId = themeEmotionMap ? getStyleId() : undefined;\n editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, { themeStyleId: styleId });\n } else {\n editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);\n }\n };\n\n return (\n <button\n onClick={() => formatNumberedList()}\n className={\"popup-item spaced \" + (isNumbered ? \"active\" : \"\")}\n aria-label=\"Format text as numbered list\"\n >\n <i className=\"icon numbered-list\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,mBAAA,GAAAL,OAAA;AAEO,IAAMM,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAAG,SAArBA,kBAAkBA,CAAA,EAAS;EACpC,IAAAE,kBAAA,GAAoB,IAAAC,qCAAiB,EAAC,CAAC;IAA/BC,OAAO,GAAAF,kBAAA,CAAPE,OAAO;EACf,IAA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,CAAE,CAC/B,CAAC;AAEjB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","$isListNode","INSERT_ORDERED_LIST_COMMAND","REMOVE_LIST_COMMAND","useRichTextEditor","useCurrentElement","NumberedListAction","element","editor","theme","isList","isNumbered","getListType","getStyleId","id","getTypographyByTag","formatNumberedList","styleId","dispatchCommand","themeStyleId","undefined","createElement","onClick","className"],"sources":["NumberedListAction.tsx"],"sourcesContent":["import React from \"react\";\nimport type { ListNode } from \"@webiny/lexical-nodes\";\nimport { $isListNode } from \"@webiny/lexical-nodes\";\nimport { INSERT_ORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND } from \"~/commands/index.js\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor.js\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement.js\";\n\nexport const NumberedListAction = () => {\n const { element } = useCurrentElement();\n const { editor, theme } = useRichTextEditor();\n const isList = $isListNode(element);\n const isNumbered = isList && (element as ListNode).getListType() === \"number\";\n\n const getStyleId = (): string | undefined => {\n // check default style for numbered list\n const id = theme.getTypographyByTag(\"ol\")?.id;\n if (id) {\n return id;\n }\n // fallback to ul list styles\n return theme.getTypographyByTag(\"ul\")?.id;\n };\n\n const formatNumberedList = () => {\n if (!isNumbered) {\n const styleId = getStyleId();\n editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, { themeStyleId: styleId });\n } else {\n editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);\n }\n };\n\n return (\n <button\n onClick={() => formatNumberedList()}\n className={\"popup-item spaced \" + (isNumbered ? \"active\" : \"\")}\n aria-label=\"Format text as numbered list\"\n >\n <i className=\"icon numbered-list\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,2BAA2B,EAAEC,mBAAmB;AACzD,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAE1B,OAAO,MAAMC,kBAAkB,GAAGA,CAAA,KAAM;EACpC,MAAM;IAAEC;EAAQ,CAAC,GAAGF,iBAAiB,CAAC,CAAC;EACvC,MAAM;IAAEG,MAAM;IAAEC;EAAM,CAAC,GAAGL,iBAAiB,CAAC,CAAC;EAC7C,MAAMM,MAAM,GAAGT,WAAW,CAACM,OAAO,CAAC;EACnC,MAAMI,UAAU,GAAGD,MAAM,IAAKH,OAAO,CAAcK,WAAW,CAAC,CAAC,KAAK,QAAQ;EAE7E,MAAMC,UAAU,GAAGA,CAAA,KAA0B;IACzC;IACA,MAAMC,EAAE,GAAGL,KAAK,CAACM,kBAAkB,CAAC,IAAI,CAAC,EAAED,EAAE;IAC7C,IAAIA,EAAE,EAAE;MACJ,OAAOA,EAAE;IACb;IACA;IACA,OAAOL,KAAK,CAACM,kBAAkB,CAAC,IAAI,CAAC,EAAED,EAAE;EAC7C,CAAC;EAED,MAAME,kBAAkB,GAAGA,CAAA,KAAM;IAC7B,IAAI,CAACL,UAAU,EAAE;MACb,MAAMM,OAAO,GAAGJ,UAAU,CAAC,CAAC;MAC5BL,MAAM,CAACU,eAAe,CAAChB,2BAA2B,EAAE;QAAEiB,YAAY,EAAEF;MAAQ,CAAC,CAAC;IAClF,CAAC,MAAM;MACHT,MAAM,CAACU,eAAe,CAACf,mBAAmB,EAAEiB,SAAS,CAAC;IAC1D;EACJ,CAAC;EAED,oBACIpB,KAAA,CAAAqB,aAAA;IACIC,OAAO,EAAEA,CAAA,KAAMN,kBAAkB,CAAC,CAAE;IACpCO,SAAS,EAAE,oBAAoB,IAAIZ,UAAU,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC/D,cAAW;EAA8B,gBAEzCX,KAAA,CAAAqB,aAAA;IAAGE,SAAS,EAAC;EAAoB,CAAE,CAC/B,CAAC;AAEjB,CAAC","ignoreList":[]}
@@ -1,36 +1,31 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.QuoteAction = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _lexicalNodes = require("@webiny/lexical-nodes");
10
- var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
11
- var _useCurrentElement2 = require("../../hooks/useCurrentElement");
12
- var QuoteAction = exports.QuoteAction = function QuoteAction() {
13
- var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
14
- editor = _useRichTextEditor.editor,
15
- themeEmotionMap = _useRichTextEditor.themeEmotionMap;
16
- var _useCurrentElement = (0, _useCurrentElement2.useCurrentElement)(),
17
- element = _useCurrentElement.element;
18
- var isQuote = (0, _lexicalNodes.$isQuoteNode)(element);
19
- var formatText = function formatText() {
1
+ import React from "react";
2
+ import { $isQuoteNode, formatToQuote, formatToParagraph } from "@webiny/lexical-nodes";
3
+ import { useRichTextEditor } from "../../hooks/useRichTextEditor.js";
4
+ import { useCurrentElement } from "../../hooks/useCurrentElement.js";
5
+ const QUOTE_TAG = "quote";
6
+ export const QuoteAction = () => {
7
+ const {
8
+ editor,
9
+ theme
10
+ } = useRichTextEditor();
11
+ const {
12
+ element
13
+ } = useCurrentElement();
14
+ const isQuote = $isQuoteNode(element);
15
+ const formatText = () => {
20
16
  if (!isQuote) {
21
17
  // Try to set default quote style, when the action button is clicked for first time
22
- var DEFAULT_QUOTE_ID = "quote";
23
- var hasQuoteStyles = themeEmotionMap && themeEmotionMap[DEFAULT_QUOTE_ID];
24
- (0, _lexicalNodes.formatToQuote)(editor, hasQuoteStyles ? DEFAULT_QUOTE_ID : undefined);
18
+ const hasQuoteStyles = theme.getTypographyByTag(QUOTE_TAG);
19
+ formatToQuote(editor, hasQuoteStyles ? QUOTE_TAG : undefined);
25
20
  return;
26
21
  }
27
- (0, _lexicalNodes.formatToParagraph)(editor);
22
+ formatToParagraph(editor);
28
23
  };
29
- return /*#__PURE__*/_react.default.createElement("button", {
24
+ return /*#__PURE__*/React.createElement("button", {
30
25
  onClick: formatText,
31
26
  className: "popup-item " + (isQuote ? "active" : ""),
32
27
  "aria-label": "Format text as quote"
33
- }, /*#__PURE__*/_react.default.createElement("i", {
28
+ }, /*#__PURE__*/React.createElement("i", {
34
29
  className: "icon quote"
35
30
  }));
36
31
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_lexicalNodes","_useRichTextEditor2","_useCurrentElement2","QuoteAction","exports","_useRichTextEditor","useRichTextEditor","editor","themeEmotionMap","_useCurrentElement","useCurrentElement","element","isQuote","$isQuoteNode","formatText","DEFAULT_QUOTE_ID","hasQuoteStyles","formatToQuote","undefined","formatToParagraph","default","createElement","onClick","className"],"sources":["QuoteAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { $isQuoteNode, formatToQuote, formatToParagraph } from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement\";\n\nexport const QuoteAction = () => {\n const { editor, themeEmotionMap } = useRichTextEditor();\n const { element } = useCurrentElement();\n const isQuote = $isQuoteNode(element);\n\n const formatText = () => {\n if (!isQuote) {\n // Try to set default quote style, when the action button is clicked for first time\n const DEFAULT_QUOTE_ID = \"quote\";\n const hasQuoteStyles = themeEmotionMap && themeEmotionMap[DEFAULT_QUOTE_ID];\n formatToQuote(editor, hasQuoteStyles ? DEFAULT_QUOTE_ID : undefined);\n return;\n }\n formatToParagraph(editor);\n };\n\n return (\n <button\n onClick={formatText}\n className={\"popup-item \" + (isQuote ? \"active\" : \"\")}\n aria-label=\"Format text as quote\"\n >\n <i className=\"icon quote\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AAEO,IAAMI,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAG,SAAdA,WAAWA,CAAA,EAAS;EAC7B,IAAAE,kBAAA,GAAoC,IAAAC,qCAAiB,EAAC,CAAC;IAA/CC,MAAM,GAAAF,kBAAA,CAANE,MAAM;IAAEC,eAAe,GAAAH,kBAAA,CAAfG,eAAe;EAC/B,IAAAC,kBAAA,GAAoB,IAAAC,qCAAiB,EAAC,CAAC;IAA/BC,OAAO,GAAAF,kBAAA,CAAPE,OAAO;EACf,IAAMC,OAAO,GAAG,IAAAC,0BAAY,EAACF,OAAO,CAAC;EAErC,IAAMG,UAAU,GAAG,SAAbA,UAAUA,CAAA,EAAS;IACrB,IAAI,CAACF,OAAO,EAAE;MACV;MACA,IAAMG,gBAAgB,GAAG,OAAO;MAChC,IAAMC,cAAc,GAAGR,eAAe,IAAIA,eAAe,CAACO,gBAAgB,CAAC;MAC3E,IAAAE,2BAAa,EAACV,MAAM,EAAES,cAAc,GAAGD,gBAAgB,GAAGG,SAAS,CAAC;MACpE;IACJ;IACA,IAAAC,+BAAiB,EAACZ,MAAM,CAAC;EAC7B,CAAC;EAED,oBACIV,MAAA,CAAAuB,OAAA,CAAAC,aAAA;IACIC,OAAO,EAAER,UAAW;IACpBS,SAAS,EAAE,aAAa,IAAIX,OAAO,GAAG,QAAQ,GAAG,EAAE,CAAE;IACrD,cAAW;EAAsB,gBAEjCf,MAAA,CAAAuB,OAAA,CAAAC,aAAA;IAAGE,SAAS,EAAC;EAAY,CAAE,CACvB,CAAC;AAEjB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","$isQuoteNode","formatToQuote","formatToParagraph","useRichTextEditor","useCurrentElement","QUOTE_TAG","QuoteAction","editor","theme","element","isQuote","formatText","hasQuoteStyles","getTypographyByTag","undefined","createElement","onClick","className"],"sources":["QuoteAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { $isQuoteNode, formatToQuote, formatToParagraph } from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor.js\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement.js\";\n\nconst QUOTE_TAG = \"quote\";\n\nexport const QuoteAction = () => {\n const { editor, theme } = useRichTextEditor();\n const { element } = useCurrentElement();\n const isQuote = $isQuoteNode(element);\n\n const formatText = () => {\n if (!isQuote) {\n // Try to set default quote style, when the action button is clicked for first time\n const hasQuoteStyles = theme.getTypographyByTag(QUOTE_TAG);\n formatToQuote(editor, hasQuoteStyles ? QUOTE_TAG : undefined);\n return;\n }\n formatToParagraph(editor);\n };\n\n return (\n <button\n onClick={formatText}\n className={\"popup-item \" + (isQuote ? \"active\" : \"\")}\n aria-label=\"Format text as quote\"\n >\n <i className=\"icon quote\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,YAAY,EAAEC,aAAa,EAAEC,iBAAiB,QAAQ,uBAAuB;AACtF,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAE1B,MAAMC,SAAS,GAAG,OAAO;AAEzB,OAAO,MAAMC,WAAW,GAAGA,CAAA,KAAM;EAC7B,MAAM;IAAEC,MAAM;IAAEC;EAAM,CAAC,GAAGL,iBAAiB,CAAC,CAAC;EAC7C,MAAM;IAAEM;EAAQ,CAAC,GAAGL,iBAAiB,CAAC,CAAC;EACvC,MAAMM,OAAO,GAAGV,YAAY,CAACS,OAAO,CAAC;EAErC,MAAME,UAAU,GAAGA,CAAA,KAAM;IACrB,IAAI,CAACD,OAAO,EAAE;MACV;MACA,MAAME,cAAc,GAAGJ,KAAK,CAACK,kBAAkB,CAACR,SAAS,CAAC;MAC1DJ,aAAa,CAACM,MAAM,EAAEK,cAAc,GAAGP,SAAS,GAAGS,SAAS,CAAC;MAC7D;IACJ;IACAZ,iBAAiB,CAACK,MAAM,CAAC;EAC7B,CAAC;EAED,oBACIR,KAAA,CAAAgB,aAAA;IACIC,OAAO,EAAEL,UAAW;IACpBM,SAAS,EAAE,aAAa,IAAIP,OAAO,GAAG,QAAQ,GAAG,EAAE,CAAE;IACrD,cAAW;EAAsB,gBAEjCX,KAAA,CAAAgB,aAAA;IAAGE,SAAS,EAAC;EAAY,CAAE,CACvB,CAAC;AAEjB,CAAC","ignoreList":[]}
@@ -1,69 +1,60 @@
1
- "use strict";
1
+ import React, { useEffect, useMemo } from "react";
2
+ import { FORMAT_ELEMENT_COMMAND, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND } from "lexical";
3
+ import { Compose, makeDecoratable } from "@webiny/react-composition";
4
+ import { TextAlignmentActionContext } from "../../context/TextAlignmentActionContextProps.js";
5
+ import { useDeriveValueFromSelection } from "../../hooks/useCurrentSelection.js";
6
+ import { getSelectedNode } from "../../utils/getSelectedNode.js";
7
+ import { useRichTextEditor } from "../../hooks/index.js";
2
8
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.TextAlignmentAction = exports.BaseTextAlignmentDropDown = void 0;
8
- var _react = _interopRequireWildcard(require("react"));
9
- var _lexical = require("lexical");
10
- var _reactComposition = require("@webiny/react-composition");
11
- var _TextAlignmentActionContextProps = require("../../context/TextAlignmentActionContextProps");
12
- var _useCurrentSelection = require("../../hooks/useCurrentSelection");
13
- var _getSelectedNode = require("../../utils/getSelectedNode");
14
- var _hooks = require("../../hooks");
15
9
  /*
16
10
  * Base text alignment dropdown composable component.
17
11
  * Note: To add a custom dropdown component use @see LexicalEditorConfig API.
18
12
  */
19
- var BaseTextAlignmentDropDown = exports.BaseTextAlignmentDropDown = (0, _reactComposition.makeDecoratable)("BaseTextAlignmentDropDown", function () {
20
- (0, _react.useEffect)(function () {
13
+ export const BaseTextAlignmentDropDown = makeDecoratable("BaseTextAlignmentDropDown", () => {
14
+ useEffect(() => {
21
15
  console.log("Default BaseTextAlignmentDropDown, please add your own component");
22
16
  }, []);
23
17
  return null;
24
18
  });
25
- var TextAlignmentActionDropDown = function TextAlignmentActionDropDown(_ref) {
26
- var element = _ref.element;
27
- return /*#__PURE__*/_react.default.createElement(_reactComposition.Compose, {
19
+ const TextAlignmentActionDropDown = ({
20
+ element
21
+ }) => {
22
+ return /*#__PURE__*/React.createElement(Compose, {
28
23
  component: BaseTextAlignmentDropDown,
29
- with: function _with() {
30
- return function () {
31
- return element;
32
- };
33
- }
24
+ with: () => () => element
34
25
  });
35
26
  };
36
- var TextAlignmentAction = exports.TextAlignmentAction = function TextAlignmentAction() {
37
- var _useRichTextEditor = (0, _hooks.useRichTextEditor)(),
38
- editor = _useRichTextEditor.editor;
39
- var alignmentValue = (0, _useCurrentSelection.useDeriveValueFromSelection)(function (_ref2) {
40
- var rangeSelection = _ref2.rangeSelection;
41
- var node = rangeSelection ? (0, _getSelectedNode.getSelectedNode)(rangeSelection) : null;
27
+ export const TextAlignmentAction = () => {
28
+ const {
29
+ editor
30
+ } = useRichTextEditor();
31
+ const alignmentValue = useDeriveValueFromSelection(({
32
+ rangeSelection
33
+ }) => {
34
+ const node = rangeSelection ? getSelectedNode(rangeSelection) : null;
42
35
  if (node) {
43
36
  return node.getParent()?.getFormatType() || "";
44
37
  }
45
38
  return "";
46
39
  });
47
- var applyTextAlignment = function applyTextAlignment(value) {
48
- editor.dispatchCommand(_lexical.FORMAT_ELEMENT_COMMAND, value);
40
+ const applyTextAlignment = value => {
41
+ editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, value);
49
42
  };
50
- var outdentText = function outdentText() {
51
- editor.dispatchCommand(_lexical.OUTDENT_CONTENT_COMMAND, undefined);
43
+ const outdentText = () => {
44
+ editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);
52
45
  };
53
- var indentText = function indentText() {
54
- editor.dispatchCommand(_lexical.INDENT_CONTENT_COMMAND, undefined);
46
+ const indentText = () => {
47
+ editor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);
55
48
  };
56
- var context = (0, _react.useMemo)(function () {
57
- return {
58
- value: alignmentValue,
59
- applyTextAlignment: applyTextAlignment,
60
- outdentText: outdentText,
61
- indentText: indentText
62
- };
63
- }, [alignmentValue]);
64
- return /*#__PURE__*/_react.default.createElement(_TextAlignmentActionContextProps.TextAlignmentActionContext.Provider, {
49
+ const context = useMemo(() => ({
50
+ value: alignmentValue,
51
+ applyTextAlignment,
52
+ outdentText,
53
+ indentText
54
+ }), [alignmentValue]);
55
+ return /*#__PURE__*/React.createElement(TextAlignmentActionContext.Provider, {
65
56
  value: context
66
- }, /*#__PURE__*/_react.default.createElement(BaseTextAlignmentDropDown, null));
57
+ }, /*#__PURE__*/React.createElement(BaseTextAlignmentDropDown, null));
67
58
  };
68
59
  TextAlignmentAction.TextAlignmentDropDown = TextAlignmentActionDropDown;
69
60
 
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_lexical","_reactComposition","_TextAlignmentActionContextProps","_useCurrentSelection","_getSelectedNode","_hooks","BaseTextAlignmentDropDown","exports","makeDecoratable","useEffect","console","log","TextAlignmentActionDropDown","_ref","element","default","createElement","Compose","component","with","_with","TextAlignmentAction","_useRichTextEditor","useRichTextEditor","editor","alignmentValue","useDeriveValueFromSelection","_ref2","rangeSelection","node","getSelectedNode","getParent","getFormatType","applyTextAlignment","value","dispatchCommand","FORMAT_ELEMENT_COMMAND","outdentText","OUTDENT_CONTENT_COMMAND","undefined","indentText","INDENT_CONTENT_COMMAND","context","useMemo","TextAlignmentActionContext","Provider","TextAlignmentDropDown"],"sources":["TextAlignmentAction.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from \"react\";\nimport {\n ElementFormatType,\n FORMAT_ELEMENT_COMMAND,\n INDENT_CONTENT_COMMAND,\n OUTDENT_CONTENT_COMMAND\n} from \"lexical\";\nimport { Compose, makeDecoratable } from \"@webiny/react-composition\";\nimport { TextAlignmentActionContext } from \"~/context/TextAlignmentActionContextProps\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { useRichTextEditor } from \"~/hooks\";\n\n/*\n * Base text alignment dropdown composable component.\n * Note: To add a custom dropdown component use @see LexicalEditorConfig API.\n */\nexport const BaseTextAlignmentDropDown = makeDecoratable(\n \"BaseTextAlignmentDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTextAlignmentDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TextAlignmentActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TextAlignmentActionDropDown = ({\n element\n}: TextAlignmentActionDropdownProps): JSX.Element => {\n return <Compose component={BaseTextAlignmentDropDown} with={() => () => element} />;\n};\n\nexport type TextAlignmentAction = React.ComponentType<unknown> & {\n TextAlignmentDropDown: typeof TextAlignmentActionDropDown;\n};\n\nexport const TextAlignmentAction: TextAlignmentAction = () => {\n const { editor } = useRichTextEditor();\n const alignmentValue: ElementFormatType = useDeriveValueFromSelection(({ rangeSelection }) => {\n const node = rangeSelection ? getSelectedNode(rangeSelection) : null;\n if (node) {\n return node.getParent()?.getFormatType() || \"\";\n }\n return \"\";\n });\n\n const applyTextAlignment = (value: ElementFormatType) => {\n editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, value);\n };\n\n const outdentText = () => {\n editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);\n };\n\n const indentText = () => {\n editor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);\n };\n\n const context = useMemo(\n () => ({\n value: alignmentValue,\n applyTextAlignment,\n outdentText,\n indentText\n }),\n [alignmentValue]\n );\n\n return (\n <TextAlignmentActionContext.Provider value={context}>\n <BaseTextAlignmentDropDown />\n </TextAlignmentActionContext.Provider>\n );\n};\n\nTextAlignmentAction.TextAlignmentDropDown = TextAlignmentActionDropDown;\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAMA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,gCAAA,GAAAH,OAAA;AACA,IAAAI,oBAAA,GAAAJ,OA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AAwB,EAAK;IACrDV,MAAM,CAACW,eAAe,CAACC,+BAAsB,EAAEF,KAAK,CAAC;EACzD,CAAC;EAED,IAAMG,WAAW,GAAG,SAAdA,WAAWA,CAAA,EAAS;IACtBb,MAAM,CAACW,eAAe,CAACG,gCAAuB,EAAEC,SAAS,CAAC;EAC9D,CAAC;EAED,IAAMC,UAAU,GAAG,SAAbA,UAAUA,CAAA,EAAS;IACrBhB,MAAM,CAACW,eAAe,CAACM,+BAAsB,EAAEF,SAAS,CAAC;EAC7D,CAAC;EAED,IAAMG,OAAO,GAAG,IAAAC,cAAO,EACnB;IAAA,OAAO;MACHT,KAAK,EAAET,cAAc;MACrBQ,kBAAkB,EAAlBA,kBAAkB;MAClBI,WAAW,EAAXA,WAAW;MACXG,UAAU,EAAVA;IACJ,CAAC;EAAA,CAAC,EACF,CAACf,cAAc,CACnB,CAAC;EAED,oBACI5B,MAAA,CAAAkB,OAAA,CAAAC,aAAA,CAACd,gCAAA,CAAA0C,0BAA0B,CAACC,QAAQ;IAACX,KAAK,EAAEQ;EAAQ,gBAChD7C,MAAA,CAAAkB,OAAA,CAAAC,aAAA,CAACV,yBAAyB,MAAE,CACK,CAAC;AAE9C,CAAC;AAEDe,mBAAmB,CAACyB,qBAAqB,GAAGlC,2BAA2B","ignoreList":[]}
1
+ {"version":3,"names":["React","useEffect","useMemo","FORMAT_ELEMENT_COMMAND","INDENT_CONTENT_COMMAND","OUTDENT_CONTENT_COMMAND","Compose","makeDecoratable","TextAlignmentActionContext","useDeriveValueFromSelection","getSelectedNode","useRichTextEditor","BaseTextAlignmentDropDown","console","log","TextAlignmentActionDropDown","element","createElement","component","with","TextAlignmentAction","editor","alignmentValue","rangeSelection","node","getParent","getFormatType","applyTextAlignment","value","dispatchCommand","outdentText","undefined","indentText","context","Provider","TextAlignmentDropDown"],"sources":["TextAlignmentAction.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from \"react\";\nimport type { ElementFormatType } from \"lexical\";\nimport { FORMAT_ELEMENT_COMMAND, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND } from \"lexical\";\nimport { Compose, makeDecoratable } from \"@webiny/react-composition\";\nimport { TextAlignmentActionContext } from \"~/context/TextAlignmentActionContextProps.js\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection.js\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode.js\";\nimport { useRichTextEditor } from \"~/hooks/index.js\";\n\n/*\n * Base text alignment dropdown composable component.\n * Note: To add a custom dropdown component use @see LexicalEditorConfig API.\n */\nexport const BaseTextAlignmentDropDown = makeDecoratable(\n \"BaseTextAlignmentDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTextAlignmentDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TextAlignmentActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TextAlignmentActionDropDown = ({\n element\n}: TextAlignmentActionDropdownProps): JSX.Element => {\n return <Compose component={BaseTextAlignmentDropDown} with={() => () => element} />;\n};\n\nexport type TextAlignmentAction = React.ComponentType<unknown> & {\n TextAlignmentDropDown: typeof TextAlignmentActionDropDown;\n};\n\nexport const TextAlignmentAction: TextAlignmentAction = () => {\n const { editor } = useRichTextEditor();\n const alignmentValue: ElementFormatType = useDeriveValueFromSelection(({ rangeSelection }) => {\n const node = rangeSelection ? getSelectedNode(rangeSelection) : null;\n if (node) {\n return node.getParent()?.getFormatType() || \"\";\n }\n return \"\";\n });\n\n const applyTextAlignment = (value: ElementFormatType) => {\n editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, value);\n };\n\n const outdentText = () => {\n editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);\n };\n\n const indentText = () => {\n editor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);\n };\n\n const context = useMemo(\n () => ({\n value: alignmentValue,\n applyTextAlignment,\n outdentText,\n indentText\n }),\n [alignmentValue]\n );\n\n return (\n <TextAlignmentActionContext.Provider value={context}>\n <BaseTextAlignmentDropDown />\n </TextAlignmentActionContext.Provider>\n );\n};\n\nTextAlignmentAction.TextAlignmentDropDown = TextAlignmentActionDropDown;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAEjD,SAASC,sBAAsB,EAAEC,sBAAsB,EAAEC,uBAAuB,QAAQ,SAAS;AACjG,SAASC,OAAO,EAAEC,eAAe,QAAQ,2BAA2B;AACpE,SAASC,0BAA0B;AACnC,SAASC,2BAA2B;AACpC,SAASC,eAAe;AACxB,SAASC,iBAAiB;;AAE1B;AACA;AACA;AACA;AACA,OAAO,MAAMC,yBAAyB,GAAGL,eAAe,CACpD,2BAA2B,EAC3B,MAA0B;EACtBN,SAAS,CAAC,MAAM;IACZY,OAAO,CAACC,GAAG,CAAC,kEAAkE,CAAC;EACnF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CACJ,CAAC;AAMD,MAAMC,2BAA2B,GAAGA,CAAC;EACjCC;AAC8B,CAAC,KAAkB;EACjD,oBAAOhB,KAAA,CAAAiB,aAAA,CAACX,OAAO;IAACY,SAAS,EAAEN,yBAA0B;IAACO,IAAI,EAAEA,CAAA,KAAM,MAAMH;EAAQ,CAAE,CAAC;AACvF,CAAC;AAMD,OAAO,MAAMI,mBAAwC,GAAGA,CAAA,KAAM;EAC1D,MAAM;IAAEC;EAAO,CAAC,GAAGV,iBAAiB,CAAC,CAAC;EACtC,MAAMW,cAAiC,GAAGb,2BAA2B,CAAC,CAAC;IAAEc;EAAe,CAAC,KAAK;IAC1F,MAAMC,IAAI,GAAGD,cAAc,GAAGb,eAAe,CAACa,cAAc,CAAC,GAAG,IAAI;IACpE,IAAIC,IAAI,EAAE;MACN,OAAOA,IAAI,CAACC,SAAS,CAAC,CAAC,EAAEC,aAAa,CAAC,CAAC,IAAI,EAAE;IAClD;IACA,OAAO,EAAE;EACb,CAAC,CAAC;EAEF,MAAMC,kBAAkB,GAAIC,KAAwB,IAAK;IACrDP,MAAM,CAACQ,eAAe,CAAC1B,sBAAsB,EAAEyB,KAAK,CAAC;EACzD,CAAC;EAED,MAAME,WAAW,GAAGA,CAAA,KAAM;IACtBT,MAAM,CAACQ,eAAe,CAACxB,uBAAuB,EAAE0B,SAAS,CAAC;EAC9D,CAAC;EAED,MAAMC,UAAU,GAAGA,CAAA,KAAM;IACrBX,MAAM,CAACQ,eAAe,CAACzB,sBAAsB,EAAE2B,SAAS,CAAC;EAC7D,CAAC;EAED,MAAME,OAAO,GAAG/B,OAAO,CACnB,OAAO;IACH0B,KAAK,EAAEN,cAAc;IACrBK,kBAAkB;IAClBG,WAAW;IACXE;EACJ,CAAC,CAAC,EACF,CAACV,cAAc,CACnB,CAAC;EAED,oBACItB,KAAA,CAAAiB,aAAA,CAACT,0BAA0B,CAAC0B,QAAQ;IAACN,KAAK,EAAEK;EAAQ,gBAChDjC,KAAA,CAAAiB,aAAA,CAACL,yBAAyB,MAAE,CACK,CAAC;AAE9C,CAAC;AAEDQ,mBAAmB,CAACe,qBAAqB,GAAGpB,2BAA2B","ignoreList":[]}
@@ -1,132 +1,110 @@
1
- "use strict";
1
+ import React, { useCallback, useEffect, useState } from "react";
2
+ import { Compose, makeDecoratable } from "@webiny/react-composition";
3
+ import { TypographyActionContext } from "../../context/TypographyActionContext.js";
4
+ import { $isHeadingNode, $isListNode, $isParagraphNode, $isQuoteNode } from "@webiny/lexical-nodes";
5
+ import { useRichTextEditor } from "../../hooks/useRichTextEditor.js";
6
+ import { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, INSERT_QUOTE_COMMAND, ADD_TYPOGRAPHY_COMMAND } from "../../commands/index.js";
7
+ import { useCurrentElement } from "../../hooks/useCurrentElement.js";
8
+
9
+ // Unfortunately, for some time in v5 we had `quoteblock` in our theme, so let's not break it.
10
+ const quoteTagNames = ["blockquote", "quoteblock"];
2
11
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.TypographyAction = exports.BaseTypographyActionDropDown = void 0;
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
- var _react = _interopRequireWildcard(require("react"));
11
- var _reactComposition = require("@webiny/react-composition");
12
- var _TypographyActionContext = require("../../context/TypographyActionContext");
13
- var _lexicalNodes = require("@webiny/lexical-nodes");
14
- var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
15
- var _commands = require("../../commands");
16
- var _useCurrentElement2 = require("../../hooks/useCurrentElement");
17
12
  /*
18
13
  * Base composable action component that is mounted on toolbar action as a placeholder for the custom toolbar action.
19
14
  * Note: Toa add custom component access trough @see LexicalEditorConfig API
20
15
  * */
21
- var BaseTypographyActionDropDown = exports.BaseTypographyActionDropDown = (0, _reactComposition.makeDecoratable)("BaseTypographyActionDropDown", function () {
22
- (0, _react.useEffect)(function () {
16
+ export const BaseTypographyActionDropDown = makeDecoratable("BaseTypographyActionDropDown", () => {
17
+ useEffect(() => {
23
18
  console.log("Default BaseTypographyActionDropDown, please add your own component");
24
19
  }, []);
25
20
  return null;
26
21
  });
27
- var TypographyActionDropDown = function TypographyActionDropDown(_ref) {
28
- var element = _ref.element;
29
- return /*#__PURE__*/_react.default.createElement(_reactComposition.Compose, {
22
+ const TypographyActionDropDown = ({
23
+ element
24
+ }) => {
25
+ return /*#__PURE__*/React.createElement(Compose, {
30
26
  component: BaseTypographyActionDropDown,
31
- with: function _with() {
32
- return function () {
33
- return element;
34
- };
35
- }
27
+ with: () => () => element
36
28
  });
37
29
  };
38
- var TypographyAction = exports.TypographyAction = function TypographyAction() {
39
- var _useState = (0, _react.useState)(),
40
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
41
- typography = _useState2[0],
42
- setTypography = _useState2[1];
43
- var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
44
- editor = _useRichTextEditor.editor,
45
- themeEmotionMap = _useRichTextEditor.themeEmotionMap;
46
- var _useCurrentElement = (0, _useCurrentElement2.useCurrentElement)(),
47
- element = _useCurrentElement.element;
48
- var isTypographySelected = (0, _lexicalNodes.$isTypographyNode)(element);
49
- var isParagraphSelected = (0, _lexicalNodes.$isParagraphNode)(element);
50
- var isHeadingSelected = (0, _lexicalNodes.$isHeadingNode)(element);
51
- var isQuoteSelected = (0, _lexicalNodes.$isQuoteNode)(element);
52
- var setTypographySelect = (0, _react.useCallback)(function (value) {
30
+ export const TypographyAction = () => {
31
+ const [typography, setTypography] = useState();
32
+ const {
33
+ editor,
34
+ theme
35
+ } = useRichTextEditor();
36
+ const {
37
+ element
38
+ } = useCurrentElement();
39
+ const isParagraphSelected = $isParagraphNode(element);
40
+ const isHeadingSelected = $isHeadingNode(element);
41
+ const isQuoteSelected = $isQuoteNode(element);
42
+ const onTypographySelect = useCallback(value => {
53
43
  setTypography(value);
54
- }, [typography]);
55
- var onTypographySelect = (0, _react.useCallback)(function (value) {
56
- setTypographySelect(value);
57
44
  if (value.tag.includes("h") || value.tag.includes("p")) {
58
- editor.dispatchCommand(_lexicalNodes.ADD_TYPOGRAPHY_COMMAND, {
59
- value: value
45
+ editor.dispatchCommand(ADD_TYPOGRAPHY_COMMAND, {
46
+ value
60
47
  });
48
+ return;
61
49
  }
62
50
  if (value.tag === "ol") {
63
- editor.dispatchCommand(_commands.INSERT_ORDERED_LIST_COMMAND, {
51
+ editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, {
64
52
  themeStyleId: value.id
65
53
  });
54
+ return;
66
55
  }
67
56
  if (value.tag === "ul") {
68
- editor.dispatchCommand(_commands.INSERT_UNORDERED_LIST_COMMAND, {
57
+ editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, {
69
58
  themeStyleId: value.id
70
59
  });
60
+ return;
71
61
  }
72
- if (value.tag === "quoteblock") {
73
- editor.dispatchCommand(_commands.INSERT_QUOTE_COMMAND, {
62
+ if (quoteTagNames.includes(value.tag)) {
63
+ editor.dispatchCommand(INSERT_QUOTE_COMMAND, {
74
64
  themeStyleId: value.id
75
65
  });
76
66
  }
77
67
  }, []);
78
- (0, _react.useEffect)(function () {
68
+ useEffect(() => {
79
69
  if (!element) {
80
70
  return;
81
71
  }
82
- // header and paragraph elements inserted with typography node
83
- if (isTypographySelected) {
84
- var el = element;
85
- setTypography(el.getTypographyValue());
86
- return;
87
- }
88
72
  if (isParagraphSelected || isHeadingSelected || isQuoteSelected) {
89
- var styleId = element.getTypographyStyleId();
73
+ const styleId = element.getStyleId();
90
74
  if (!styleId) {
91
75
  return;
92
76
  }
93
- if (!themeEmotionMap) {
94
- return;
95
- }
96
- var style = themeEmotionMap[styleId];
77
+ const style = theme.getTypographyById(styleId);
97
78
  if (style) {
98
79
  setTypography({
99
- name: style?.name,
100
80
  id: style.id,
101
- css: style.styles,
102
- tag: style.tag
81
+ label: style.label
103
82
  });
104
83
  }
105
84
  return;
106
85
  }
107
86
 
108
87
  // list and quote element
109
- if (themeEmotionMap && ((0, _lexicalNodes.$isListNode)(element) || (0, _lexicalNodes.$isQuoteNode)(element))) {
110
- var themeStyleId = element?.getStyleId() || undefined;
111
- if (themeStyleId) {
112
- var elementStyle = themeEmotionMap[themeStyleId];
113
- if (elementStyle) {
114
- setTypography({
115
- id: elementStyle.id,
116
- css: elementStyle.styles,
117
- name: elementStyle.name,
118
- tag: elementStyle.tag
119
- });
120
- }
88
+ if ($isListNode(element)) {
89
+ const styleId = element.getStyleId();
90
+ if (!styleId) {
91
+ return;
92
+ }
93
+ const style = theme.getTypographyById(styleId);
94
+ if (style) {
95
+ setTypography({
96
+ id: style.id,
97
+ label: style.label
98
+ });
121
99
  }
122
100
  }
123
- }, [element, isTypographySelected, isQuoteSelected, isParagraphSelected, isHeadingSelected]);
124
- return /*#__PURE__*/_react.default.createElement(_TypographyActionContext.TypographyActionContext.Provider, {
101
+ }, [element, isQuoteSelected, isParagraphSelected, isHeadingSelected]);
102
+ return /*#__PURE__*/React.createElement(TypographyActionContext.Provider, {
125
103
  value: {
126
104
  value: typography,
127
105
  applyTypography: onTypographySelect
128
106
  }
129
- }, /*#__PURE__*/_react.default.createElement(BaseTypographyActionDropDown, null));
107
+ }, /*#__PURE__*/React.createElement(BaseTypographyActionDropDown, null));
130
108
  };
131
109
  TypographyAction.TypographyDropDown = TypographyActionDropDown;
132
110
 
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactComposition","_TypographyActionContext","_lexicalNodes","_useRichTextEditor2","_commands","_useCurrentElement2","BaseTypographyActionDropDown","exports","makeDecoratable","useEffect","console","log","TypographyActionDropDown","_ref","element","default","createElement","Compose","component","with","_with","TypographyAction","_useState","useState","_useState2","_slicedToArray2","typography","setTypography","_useRichTextEditor","useRichTextEditor","editor","themeEmotionMap","_useCurrentElement","useCurrentElement","isTypographySelected","$isTypographyNode","isParagraphSelected","$isParagraphNode","isHeadingSelected","$isHeadingNode","isQuoteSelected","$isQuoteNode","setTypographySelect","useCallback","value","onTypographySelect","tag","includes","dispatchCommand","ADD_TYPOGRAPHY_COMMAND","INSERT_ORDERED_LIST_COMMAND","themeStyleId","id","INSERT_UNORDERED_LIST_COMMAND","INSERT_QUOTE_COMMAND","el","getTypographyValue","styleId","getTypographyStyleId","style","name","css","styles","$isListNode","getStyleId","undefined","elementStyle","TypographyActionContext","Provider","applyTypography","TypographyDropDown"],"sources":["TypographyAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { LexicalCommand } from \"lexical\";\nimport { Compose, makeDecoratable } from \"@webiny/react-composition\";\nimport { TypographyValue } from \"@webiny/lexical-theme\";\nimport { TypographyActionContext } from \"~/context/TypographyActionContext\";\nimport {\n $isHeadingNode,\n $isListNode,\n $isParagraphNode,\n $isQuoteNode,\n $isTypographyNode,\n ADD_TYPOGRAPHY_COMMAND,\n TypographyNode,\n TypographyPayload\n} from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport {\n INSERT_ORDERED_LIST_COMMAND,\n INSERT_UNORDERED_LIST_COMMAND,\n INSERT_QUOTE_COMMAND,\n ListCommandPayload,\n QuoteCommandPayload\n} from \"~/commands\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement\";\n\n/*\n * Base composable action component that is mounted on toolbar action as a placeholder for the custom toolbar action.\n * Note: Toa add custom component access trough @see LexicalEditorConfig API\n * */\nexport const BaseTypographyActionDropDown = makeDecoratable(\n \"BaseTypographyActionDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTypographyActionDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TypographyActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TypographyActionDropDown = ({ element }: TypographyActionDropdownProps): JSX.Element => {\n return <Compose component={BaseTypographyActionDropDown} with={() => () => element} />;\n};\n\nexport type TypographyAction = React.ComponentType<unknown> & {\n TypographyDropDown: typeof TypographyActionDropDown;\n};\n\nexport const TypographyAction: TypographyAction = () => {\n const [typography, setTypography] = useState<TypographyValue>();\n const { editor, themeEmotionMap } = useRichTextEditor();\n const { element } = useCurrentElement();\n const isTypographySelected = $isTypographyNode(element);\n const isParagraphSelected = $isParagraphNode(element);\n const isHeadingSelected = $isHeadingNode(element);\n const isQuoteSelected = $isQuoteNode(element);\n\n const setTypographySelect = useCallback(\n (value: TypographyValue) => {\n setTypography(value);\n },\n [typography]\n );\n\n const onTypographySelect = useCallback((value: TypographyValue) => {\n setTypographySelect(value);\n if (value.tag.includes(\"h\") || value.tag.includes(\"p\")) {\n editor.dispatchCommand<LexicalCommand<TypographyPayload>>(ADD_TYPOGRAPHY_COMMAND, {\n value\n });\n }\n\n if (value.tag === \"ol\") {\n editor.dispatchCommand<LexicalCommand<ListCommandPayload>>(\n INSERT_ORDERED_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"ul\") {\n editor.dispatchCommand<LexicalCommand<ListCommandPayload>>(\n INSERT_UNORDERED_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"quoteblock\") {\n editor.dispatchCommand<LexicalCommand<QuoteCommandPayload>>(INSERT_QUOTE_COMMAND, {\n themeStyleId: value.id\n });\n }\n }, []);\n\n useEffect(() => {\n if (!element) {\n return;\n }\n // header and paragraph elements inserted with typography node\n if (isTypographySelected) {\n const el = element as TypographyNode;\n setTypography(el.getTypographyValue());\n return;\n }\n\n if (isParagraphSelected || isHeadingSelected || isQuoteSelected) {\n const styleId = element.getTypographyStyleId();\n if (!styleId) {\n return;\n }\n\n if (!themeEmotionMap) {\n return;\n }\n\n const style = themeEmotionMap[styleId];\n if (style) {\n setTypography({\n name: style?.name,\n id: style.id,\n css: style.styles,\n tag: style.tag\n });\n }\n return;\n }\n\n // list and quote element\n if (themeEmotionMap && ($isListNode(element) || $isQuoteNode(element))) {\n const themeStyleId = element?.getStyleId() || undefined;\n if (themeStyleId) {\n const elementStyle = themeEmotionMap[themeStyleId];\n if (elementStyle) {\n setTypography({\n id: elementStyle.id,\n css: elementStyle.styles,\n name: elementStyle.name,\n tag: elementStyle.tag\n });\n }\n }\n }\n }, [element, isTypographySelected, isQuoteSelected, isParagraphSelected, isHeadingSelected]);\n\n return (\n <TypographyActionContext.Provider\n value={{\n value: typography,\n applyTypography: onTypographySelect\n }}\n >\n <BaseTypographyActionDropDown />\n </TypographyActionContext.Provider>\n );\n};\n\nTypographyAction.TypographyDropDown = TypographyActionDropDown;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAD,OAAA;AAEA,IAAAE,wBAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAUA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAOA,IAAAM,mBAAA,GAAAN,OAAA;AAEA;AAC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B,KAAK,EAAE;MACHA,KAAK,EAAElB,UAAU;MACjB2C,eAAe,EAAExB;IACrB;EAAE,gBAEFhD,MAAA,CAAAkB,OAAA,CAAAC,aAAA,CAACV,4BAA4B,MAAE,CACD,CAAC;AAE3C,CAAC;AAEDe,gBAAgB,CAACiD,kBAAkB,GAAG1D,wBAAwB","ignoreList":[]}
1
+ {"version":3,"names":["React","useCallback","useEffect","useState","Compose","makeDecoratable","TypographyActionContext","$isHeadingNode","$isListNode","$isParagraphNode","$isQuoteNode","useRichTextEditor","INSERT_ORDERED_LIST_COMMAND","INSERT_UNORDERED_LIST_COMMAND","INSERT_QUOTE_COMMAND","ADD_TYPOGRAPHY_COMMAND","useCurrentElement","quoteTagNames","BaseTypographyActionDropDown","console","log","TypographyActionDropDown","element","createElement","component","with","TypographyAction","typography","setTypography","editor","theme","isParagraphSelected","isHeadingSelected","isQuoteSelected","onTypographySelect","value","tag","includes","dispatchCommand","themeStyleId","id","styleId","getStyleId","style","getTypographyById","label","Provider","applyTypography","TypographyDropDown"],"sources":["TypographyAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport type { LexicalCommand } from \"lexical\";\nimport { Compose, makeDecoratable } from \"@webiny/react-composition\";\nimport type { TypographyValue } from \"@webiny/lexical-theme\";\nimport type { ActiveTypography } from \"~/context/TypographyActionContext.js\";\nimport { TypographyActionContext } from \"~/context/TypographyActionContext.js\";\nimport { $isHeadingNode, $isListNode, $isParagraphNode, $isQuoteNode } from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor.js\";\nimport type {\n ListCommandPayload,\n QuoteCommandPayload,\n TypographyPayload\n} from \"~/commands/index.js\";\nimport {\n INSERT_ORDERED_LIST_COMMAND,\n INSERT_UNORDERED_LIST_COMMAND,\n INSERT_QUOTE_COMMAND,\n ADD_TYPOGRAPHY_COMMAND\n} from \"~/commands/index.js\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement.js\";\n\n// Unfortunately, for some time in v5 we had `quoteblock` in our theme, so let's not break it.\nconst quoteTagNames = [\"blockquote\", \"quoteblock\"];\n\n/*\n * Base composable action component that is mounted on toolbar action as a placeholder for the custom toolbar action.\n * Note: Toa add custom component access trough @see LexicalEditorConfig API\n * */\nexport const BaseTypographyActionDropDown = makeDecoratable(\n \"BaseTypographyActionDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTypographyActionDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TypographyActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TypographyActionDropDown = ({ element }: TypographyActionDropdownProps): JSX.Element => {\n return <Compose component={BaseTypographyActionDropDown} with={() => () => element} />;\n};\n\nexport type TypographyAction = React.ComponentType<unknown> & {\n TypographyDropDown: typeof TypographyActionDropDown;\n};\n\nexport const TypographyAction: TypographyAction = () => {\n const [typography, setTypography] = useState<ActiveTypography>();\n const { editor, theme } = useRichTextEditor();\n const { element } = useCurrentElement();\n const isParagraphSelected = $isParagraphNode(element);\n const isHeadingSelected = $isHeadingNode(element);\n const isQuoteSelected = $isQuoteNode(element);\n\n const onTypographySelect = useCallback((value: TypographyValue) => {\n setTypography(value);\n\n if (value.tag.includes(\"h\") || value.tag.includes(\"p\")) {\n editor.dispatchCommand<LexicalCommand<TypographyPayload>>(ADD_TYPOGRAPHY_COMMAND, {\n value\n });\n return;\n }\n\n if (value.tag === \"ol\") {\n editor.dispatchCommand<LexicalCommand<ListCommandPayload>>(\n INSERT_ORDERED_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n return;\n }\n\n if (value.tag === \"ul\") {\n editor.dispatchCommand<LexicalCommand<ListCommandPayload>>(\n INSERT_UNORDERED_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n return;\n }\n\n if (quoteTagNames.includes(value.tag)) {\n editor.dispatchCommand<LexicalCommand<QuoteCommandPayload>>(INSERT_QUOTE_COMMAND, {\n themeStyleId: value.id\n });\n }\n }, []);\n\n useEffect(() => {\n if (!element) {\n return;\n }\n\n if (isParagraphSelected || isHeadingSelected || isQuoteSelected) {\n const styleId = element.getStyleId();\n if (!styleId) {\n return;\n }\n\n const style = theme.getTypographyById(styleId);\n if (style) {\n setTypography({\n id: style.id,\n label: style.label\n });\n }\n return;\n }\n\n // list and quote element\n if ($isListNode(element)) {\n const styleId = element.getStyleId();\n if (!styleId) {\n return;\n }\n\n const style = theme.getTypographyById(styleId);\n if (style) {\n setTypography({\n id: style.id,\n label: style.label\n });\n }\n }\n }, [element, isQuoteSelected, isParagraphSelected, isHeadingSelected]);\n\n return (\n <TypographyActionContext.Provider\n value={{\n value: typography,\n applyTypography: onTypographySelect\n }}\n >\n <BaseTypographyActionDropDown />\n </TypographyActionContext.Provider>\n );\n};\n\nTypographyAction.TypographyDropDown = TypographyActionDropDown;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAE/D,SAASC,OAAO,EAAEC,eAAe,QAAQ,2BAA2B;AAGpE,SAASC,uBAAuB;AAChC,SAASC,cAAc,EAAEC,WAAW,EAAEC,gBAAgB,EAAEC,YAAY,QAAQ,uBAAuB;AACnG,SAASC,iBAAiB;AAM1B,SACIC,2BAA2B,EAC3BC,6BAA6B,EAC7BC,oBAAoB,EACpBC,sBAAsB;AAE1B,SAASC,iBAAiB;;AAE1B;AACA,MAAMC,aAAa,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC;;AAElD;AACA;AACA;AACA;AACA,OAAO,MAAMC,4BAA4B,GAAGb,eAAe,CACvD,8BAA8B,EAC9B,MAA0B;EACtBH,SAAS,CAAC,MAAM;IACZiB,OAAO,CAACC,GAAG,CAAC,qEAAqE,CAAC;EACtF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CACJ,CAAC;AAMD,MAAMC,wBAAwB,GAAGA,CAAC;EAAEC;AAAuC,CAAC,KAAkB;EAC1F,oBAAOtB,KAA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D,CAAC;AAE3C,CAAC;AAEDQ,gBAAgB,CAACsB,kBAAkB,GAAG3B,wBAAwB","ignoreList":[]}
@@ -1,27 +1,22 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.UnderlineAction = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _lexical = require("lexical");
10
- var _hooks = require("../../hooks");
11
- var UnderlineAction = exports.UnderlineAction = function UnderlineAction() {
12
- var _useRichTextEditor = (0, _hooks.useRichTextEditor)(),
13
- editor = _useRichTextEditor.editor;
14
- var _useCurrentSelection = (0, _hooks.useCurrentSelection)(),
15
- rangeSelection = _useCurrentSelection.rangeSelection;
16
- var isUnderlineSelected = rangeSelection ? rangeSelection.hasFormat("underline") : false;
17
- var handleClick = function handleClick() {
18
- editor.dispatchCommand(_lexical.FORMAT_TEXT_COMMAND, "underline");
1
+ import React from "react";
2
+ import { FORMAT_TEXT_COMMAND } from "lexical";
3
+ import { useCurrentSelection, useRichTextEditor } from "../../hooks/index.js";
4
+ export const UnderlineAction = () => {
5
+ const {
6
+ editor
7
+ } = useRichTextEditor();
8
+ const {
9
+ rangeSelection
10
+ } = useCurrentSelection();
11
+ const isUnderlineSelected = rangeSelection ? rangeSelection.hasFormat("underline") : false;
12
+ const handleClick = () => {
13
+ editor.dispatchCommand(FORMAT_TEXT_COMMAND, "underline");
19
14
  };
20
- return /*#__PURE__*/_react.default.createElement("button", {
15
+ return /*#__PURE__*/React.createElement("button", {
21
16
  onClick: handleClick,
22
17
  className: "popup-item spaced " + (isUnderlineSelected ? "active" : ""),
23
- "aria-label": "Format text as italic"
24
- }, /*#__PURE__*/_react.default.createElement("i", {
18
+ "aria-label": "Underline text"
19
+ }, /*#__PURE__*/React.createElement("i", {
25
20
  className: "format underline"
26
21
  }));
27
22
  };