@webiny/lexical-editor 6.0.0-alpha.5 → 6.0.0-rc.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 (172) hide show
  1. package/README.md +6 -12
  2. package/commands/index.d.ts +5 -5
  3. package/commands/index.js +5 -5
  4. package/commands/index.js.map +1 -1
  5. package/components/Editor/EnsureHeadingTagPlugin.js +1 -1
  6. package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -1
  7. package/components/Editor/RichTextEditor.d.ts +11 -6
  8. package/components/Editor/RichTextEditor.js +22 -16
  9. package/components/Editor/RichTextEditor.js.map +1 -1
  10. package/components/Editor/normalizeInputValue.d.ts +1 -1
  11. package/components/Editor/normalizeInputValue.js.map +1 -1
  12. package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +14 -16
  13. package/components/LexicalEditorConfig/LexicalEditorConfig.js +20 -58
  14. package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
  15. package/components/LexicalHtmlRenderer.d.ts +3 -6
  16. package/components/LexicalHtmlRenderer.js +12 -17
  17. package/components/LexicalHtmlRenderer.js.map +1 -1
  18. package/components/Toolbar/StaticToolbar.css +416 -0
  19. package/components/Toolbar/StaticToolbar.d.ts +1 -1
  20. package/components/Toolbar/StaticToolbar.js +2 -2
  21. package/components/Toolbar/StaticToolbar.js.map +1 -1
  22. package/components/ToolbarActions/BoldAction.js +2 -2
  23. package/components/ToolbarActions/BoldAction.js.map +1 -1
  24. package/components/ToolbarActions/BulletListAction.js +5 -6
  25. package/components/ToolbarActions/BulletListAction.js.map +1 -1
  26. package/components/ToolbarActions/CodeHighlightAction.js +2 -2
  27. package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
  28. package/components/ToolbarActions/FontColorAction.js +4 -4
  29. package/components/ToolbarActions/FontColorAction.js.map +1 -1
  30. package/components/ToolbarActions/ImageAction.js +3 -3
  31. package/components/ToolbarActions/ImageAction.js.map +1 -1
  32. package/components/ToolbarActions/ItalicAction.js +2 -2
  33. package/components/ToolbarActions/ItalicAction.js.map +1 -1
  34. package/components/ToolbarActions/LinkAction.js +3 -3
  35. package/components/ToolbarActions/LinkAction.js.map +1 -1
  36. package/components/ToolbarActions/NumberedListAction.js +7 -11
  37. package/components/ToolbarActions/NumberedListAction.js.map +1 -1
  38. package/components/ToolbarActions/QuoteAction.js +6 -6
  39. package/components/ToolbarActions/QuoteAction.js.map +1 -1
  40. package/components/ToolbarActions/TextAlignmentAction.js +4 -4
  41. package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
  42. package/components/ToolbarActions/TypographyAction.js +14 -11
  43. package/components/ToolbarActions/TypographyAction.js.map +1 -1
  44. package/components/ToolbarActions/UnderlineAction.js +1 -1
  45. package/components/ToolbarActions/UnderlineAction.js.map +1 -1
  46. package/context/RichTextEditorContext.d.ts +5 -6
  47. package/context/RichTextEditorContext.js +17 -4
  48. package/context/RichTextEditorContext.js.map +1 -1
  49. package/context/TypographyActionContext.d.ts +1 -1
  50. package/context/TypographyActionContext.js.map +1 -1
  51. package/exports/admin/lexical.d.ts +15 -0
  52. package/exports/admin/lexical.js +23 -0
  53. package/exports/admin/lexical.js.map +1 -0
  54. package/hooks/index.d.ts +7 -8
  55. package/hooks/index.js +7 -8
  56. package/hooks/index.js.map +1 -1
  57. package/hooks/useCurrentElement.js +2 -3
  58. package/hooks/useCurrentElement.js.map +1 -1
  59. package/hooks/useCurrentSelection.js +4 -4
  60. package/hooks/useCurrentSelection.js.map +1 -1
  61. package/hooks/useFontColorPicker.d.ts +1 -1
  62. package/hooks/useFontColorPicker.js +1 -1
  63. package/hooks/useFontColorPicker.js.map +1 -1
  64. package/hooks/useRichTextEditor.d.ts +1 -1
  65. package/hooks/useRichTextEditor.js +1 -1
  66. package/hooks/useRichTextEditor.js.map +1 -1
  67. package/hooks/useTextAlignmentAction.d.ts +1 -1
  68. package/hooks/useTextAlignmentAction.js +1 -1
  69. package/hooks/useTextAlignmentAction.js.map +1 -1
  70. package/hooks/useTypographyAction.d.ts +1 -1
  71. package/hooks/useTypographyAction.js +1 -1
  72. package/hooks/useTypographyAction.js.map +1 -1
  73. package/index.d.ts +33 -37
  74. package/index.js +33 -37
  75. package/index.js.map +1 -1
  76. package/package.json +18 -22
  77. package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +1 -1
  78. package/plugins/BlurEventPlugin/BlurEventPlugin.js +1 -1
  79. package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
  80. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +1 -1
  81. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
  82. package/plugins/CodeHighlightPlugin/index.d.ts +1 -1
  83. package/plugins/CodeHighlightPlugin/index.js +1 -1
  84. package/plugins/CodeHighlightPlugin/index.js.map +1 -1
  85. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +4 -10
  86. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +15 -145
  87. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -1
  88. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +2 -3
  89. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +10 -11
  90. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -1
  91. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +1 -136
  92. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +5 -6
  93. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +3 -7
  94. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
  95. package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -1
  96. package/plugins/FloatingLinkEditorPlugin/index.js +1 -1
  97. package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
  98. package/plugins/FloatingLinkEditorPlugin/types.d.ts +10 -0
  99. package/plugins/FloatingLinkEditorPlugin/types.js +3 -0
  100. package/plugins/FloatingLinkEditorPlugin/types.js.map +1 -0
  101. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +8 -0
  102. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +128 -0
  103. package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +1 -0
  104. package/plugins/FontColorPlugin/FontColorPlugin.js +2 -2
  105. package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
  106. package/plugins/FontColorPlugin/applyColorToSelection.js +1 -1
  107. package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -1
  108. package/plugins/ImagesPlugin/ImagesPlugin.d.ts +1 -2
  109. package/plugins/ImagesPlugin/ImagesPlugin.js +5 -8
  110. package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
  111. package/plugins/LinkPlugin/LinkPlugin.js +2 -3
  112. package/plugins/LinkPlugin/LinkPlugin.js.map +1 -1
  113. package/plugins/ListPLugin/ListPlugin.js +45 -3
  114. package/plugins/ListPLugin/ListPlugin.js.map +1 -1
  115. package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +12 -4
  116. package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -1
  117. package/plugins/StateHandlingPlugin.d.ts +1 -1
  118. package/plugins/StateHandlingPlugin.js +6 -6
  119. package/plugins/StateHandlingPlugin.js.map +1 -1
  120. package/plugins/TypographyPlugin/TypographyPlugin.js +2 -2
  121. package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
  122. package/types.d.ts +3 -3
  123. package/types.js +1 -1
  124. package/types.js.map +1 -1
  125. package/ui/ContentEditable.d.ts +0 -1
  126. package/ui/Divider.d.ts +0 -1
  127. package/ui/DropDown.js +4 -3
  128. package/ui/DropDown.js.map +1 -1
  129. package/ui/ImageResizer.d.ts +0 -1
  130. package/ui/ImageResizer.js.map +1 -1
  131. package/ui/LinkPreview.d.ts +0 -1
  132. package/ui/TextInput.d.ts +0 -1
  133. package/utils/files.d.ts +6 -6
  134. package/utils/files.js +3 -13
  135. package/utils/files.js.map +1 -1
  136. package/utils/insertImage.d.ts +1 -1
  137. package/utils/insertImage.js.map +1 -1
  138. package/utils/isValidLexicalData.d.ts +2 -2
  139. package/utils/isValidLexicalData.js.map +1 -1
  140. package/utils/rect.d.ts +1 -1
  141. package/utils/rect.js +1 -1
  142. package/utils/rect.js.map +1 -1
  143. package/utils/sanitizeUrl.js +1 -1
  144. package/utils/sanitizeUrl.js.map +1 -1
  145. package/utils/setFloatingElemPosition.d.ts +1 -1
  146. package/utils/setFloatingElemPosition.js +23 -21
  147. package/utils/setFloatingElemPosition.js.map +1 -1
  148. package/components/Editor/HeadingEditor.d.ts +0 -7
  149. package/components/Editor/HeadingEditor.js +0 -22
  150. package/components/Editor/HeadingEditor.js.map +0 -1
  151. package/components/Editor/ParagraphEditor.d.ts +0 -7
  152. package/components/Editor/ParagraphEditor.js +0 -22
  153. package/components/Editor/ParagraphEditor.js.map +0 -1
  154. package/components/Toolbar/Toolbar.css +0 -643
  155. package/components/Toolbar/Toolbar.d.ts +0 -6
  156. package/components/Toolbar/Toolbar.js +0 -148
  157. package/components/Toolbar/Toolbar.js.map +0 -1
  158. package/components/ToolbarActions/FontSizeAction.d.ts +0 -14
  159. package/components/ToolbarActions/FontSizeAction.js +0 -91
  160. package/components/ToolbarActions/FontSizeAction.js.map +0 -1
  161. package/hooks/useList.d.ts +0 -2
  162. package/hooks/useList.js +0 -50
  163. package/hooks/useList.js.map +0 -1
  164. package/hooks/useQuote.d.ts +0 -2
  165. package/hooks/useQuote.js +0 -17
  166. package/hooks/useQuote.js.map +0 -1
  167. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +0 -8
  168. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +0 -104
  169. package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +0 -1
  170. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +0 -9
  171. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +0 -34
  172. package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["React","useCallback","$isLinkNode","TOGGLE_LINK_COMMAND","getNodeFromSelection","useDeriveValueFromSelection","useRichTextEditor","LinkAction","editor","isLink","rangeSelection","node","getParent","insertLink","dispatchCommand","url","createElement","onClick","className"],"sources":["LinkAction.tsx"],"sourcesContent":["import React, { useCallback } from \"react\";\nimport { $isLinkNode, TOGGLE_LINK_COMMAND } from \"@webiny/lexical-nodes\";\nimport { getNodeFromSelection } from \"~/hooks/useCurrentElement\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection\";\nimport { useRichTextEditor } from \"~/hooks\";\n\nexport const LinkAction = () => {\n const { editor } = useRichTextEditor();\n const isLink = useDeriveValueFromSelection(({ rangeSelection }) => {\n if (!rangeSelection) {\n return false;\n }\n const node = getNodeFromSelection(rangeSelection);\n return node ? $isLinkNode(node) || $isLinkNode(node.getParent()) : false;\n });\n\n const insertLink = useCallback(() => {\n if (!isLink) {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url: \"https://\" });\n } else {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);\n }\n }, [editor, isLink]);\n\n return (\n <button\n onClick={insertLink}\n className={\"popup-item spaced \" + (isLink ? \"active\" : \"\")}\n aria-label=\"Insert link\"\n >\n <i className=\"format link\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,QAAQ,OAAO;AAC1C,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,uBAAuB;AACxE,SAASC,oBAAoB;AAC7B,SAASC,2BAA2B;AACpC,SAASC,iBAAiB;AAE1B,OAAO,MAAMC,UAAU,GAAGA,CAAA,KAAM;EAC5B,MAAM;IAAEC;EAAO,CAAC,GAAGF,iBAAiB,CAAC,CAAC;EACtC,MAAMG,MAAM,GAAGJ,2BAA2B,CAAC,CAAC;IAAEK;EAAe,CAAC,KAAK;IAC/D,IAAI,CAACA,cAAc,EAAE;MACjB,OAAO,KAAK;IAChB;IACA,MAAMC,IAAI,GAAGP,oBAAoB,CAACM,cAAc,CAAC;IACjD,OAAOC,IAAI,GAAGT,WAAW,CAACS,IAAI,CAAC,IAAIT,WAAW,CAACS,IAAI,CAACC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK;EAC5E,CAAC,CAAC;EAEF,MAAMC,UAAU,GAAGZ,WAAW,CAAC,MAAM;IACjC,IAAI,CAACQ,MAAM,EAAE;MACTD,MAAM,CAACM,eAAe,CAACX,mBAAmB,EAAE;QAAEY,GAAG,EAAE;MAAW,CAAC,CAAC;IACpE,CAAC,MAAM;MACHP,MAAM,CAACM,eAAe,CAACX,mBAAmB,EAAE,IAAI,CAAC;IACrD;EACJ,CAAC,EAAE,CAACK,MAAM,EAAEC,MAAM,CAAC,CAAC;EAEpB,oBACIT,KAAA,CAAAgB,aAAA;IACIC,OAAO,EAAEJ,UAAW;IACpBK,SAAS,EAAE,oBAAoB,IAAIT,MAAM,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC3D,cAAW;EAAa,gBAExBT,KAAA,CAAAgB,aAAA;IAAGE,SAAS,EAAC;EAAa,CAAE,CACxB,CAAC;AAEjB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useCallback","$isLinkNode","TOGGLE_LINK_COMMAND","getNodeFromSelection","useDeriveValueFromSelection","useRichTextEditor","LinkAction","editor","isLink","rangeSelection","node","getParent","insertLink","dispatchCommand","url","createElement","onClick","className"],"sources":["LinkAction.tsx"],"sourcesContent":["import React, { useCallback } from \"react\";\nimport { $isLinkNode, TOGGLE_LINK_COMMAND } from \"@webiny/lexical-nodes\";\nimport { getNodeFromSelection } from \"~/hooks/useCurrentElement.js\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection.js\";\nimport { useRichTextEditor } from \"~/hooks/index.js\";\n\nexport const LinkAction = () => {\n const { editor } = useRichTextEditor();\n const isLink = useDeriveValueFromSelection(({ rangeSelection }) => {\n if (!rangeSelection) {\n return false;\n }\n const node = getNodeFromSelection(rangeSelection);\n return node ? $isLinkNode(node) || $isLinkNode(node.getParent()) : false;\n });\n\n const insertLink = useCallback(() => {\n if (!isLink) {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url: \"https://\" });\n } else {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);\n }\n }, [editor, isLink]);\n\n return (\n <button\n onClick={insertLink}\n className={\"popup-item spaced \" + (isLink ? \"active\" : \"\")}\n aria-label=\"Insert link\"\n >\n <i className=\"format link\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,QAAQ,OAAO;AAC1C,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,uBAAuB;AACxE,SAASC,oBAAoB;AAC7B,SAASC,2BAA2B;AACpC,SAASC,iBAAiB;AAE1B,OAAO,MAAMC,UAAU,GAAGA,CAAA,KAAM;EAC5B,MAAM;IAAEC;EAAO,CAAC,GAAGF,iBAAiB,CAAC,CAAC;EACtC,MAAMG,MAAM,GAAGJ,2BAA2B,CAAC,CAAC;IAAEK;EAAe,CAAC,KAAK;IAC/D,IAAI,CAACA,cAAc,EAAE;MACjB,OAAO,KAAK;IAChB;IACA,MAAMC,IAAI,GAAGP,oBAAoB,CAACM,cAAc,CAAC;IACjD,OAAOC,IAAI,GAAGT,WAAW,CAACS,IAAI,CAAC,IAAIT,WAAW,CAACS,IAAI,CAACC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK;EAC5E,CAAC,CAAC;EAEF,MAAMC,UAAU,GAAGZ,WAAW,CAAC,MAAM;IACjC,IAAI,CAACQ,MAAM,EAAE;MACTD,MAAM,CAACM,eAAe,CAACX,mBAAmB,EAAE;QAAEY,GAAG,EAAE;MAAW,CAAC,CAAC;IACpE,CAAC,MAAM;MACHP,MAAM,CAACM,eAAe,CAACX,mBAAmB,EAAE,IAAI,CAAC;IACrD;EACJ,CAAC,EAAE,CAACK,MAAM,EAAEC,MAAM,CAAC,CAAC;EAEpB,oBACIT,KAAA,CAAAgB,aAAA;IACIC,OAAO,EAAEJ,UAAW;IACpBK,SAAS,EAAE,oBAAoB,IAAIT,MAAM,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC3D,cAAW;EAAa,gBAExBT,KAAA,CAAAgB,aAAA;IAAGE,SAAS,EAAC;EAAa,CAAE,CACxB,CAAC;AAEjB,CAAC","ignoreList":[]}
@@ -1,34 +1,30 @@
1
1
  import React from "react";
2
2
  import { $isListNode } from "@webiny/lexical-nodes";
3
- import { findTypographyStyleByHtmlTag } from "@webiny/lexical-theme";
4
- import { INSERT_ORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND } from "../../commands";
5
- import { useRichTextEditor } from "../../hooks/useRichTextEditor";
6
- import { useCurrentElement } from "../../hooks/useCurrentElement";
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";
7
6
  export const NumberedListAction = () => {
8
7
  const {
9
8
  element
10
9
  } = useCurrentElement();
11
10
  const {
12
11
  editor,
13
- themeEmotionMap
12
+ theme
14
13
  } = useRichTextEditor();
15
14
  const isList = $isListNode(element);
16
15
  const isNumbered = isList && element.getListType() === "number";
17
16
  const getStyleId = () => {
18
- if (!themeEmotionMap) {
19
- return undefined;
20
- }
21
17
  // check default style for numbered list
22
- const id = findTypographyStyleByHtmlTag("ol", themeEmotionMap)?.id;
18
+ const id = theme.getTypographyByTag("ol")?.id;
23
19
  if (id) {
24
20
  return id;
25
21
  }
26
22
  // fallback to ul list styles
27
- return findTypographyStyleByHtmlTag("ul", themeEmotionMap)?.id;
23
+ return theme.getTypographyByTag("ul")?.id;
28
24
  };
29
25
  const formatNumberedList = () => {
30
26
  if (!isNumbered) {
31
- const styleId = themeEmotionMap ? getStyleId() : undefined;
27
+ const styleId = getStyleId();
32
28
  editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, {
33
29
  themeStyleId: styleId
34
30
  });
@@ -1 +1 @@
1
- {"version":3,"names":["React","$isListNode","findTypographyStyleByHtmlTag","INSERT_ORDERED_LIST_COMMAND","REMOVE_LIST_COMMAND","useRichTextEditor","useCurrentElement","NumberedListAction","element","editor","themeEmotionMap","isList","isNumbered","getListType","getStyleId","undefined","id","formatNumberedList","styleId","dispatchCommand","themeStyleId","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 { 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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,aAAA;IACIC,OAAO,EAAEA,CAAA,KAAML,kBAAkB,CAAC,CAAE;IACpCM,SAAS,EAAE,oBAAoB,IAAIX,UAAU,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC/D,cAAW;EAA8B,gBAEzCZ,KAAA,CAAAqB,aAAA;IAAGE,SAAS,EAAC;EAAoB,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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AEzCX,KAAA,CAAAqB,aAAA;IAAGE,SAAS,EAAC;EAAoB,CAAE,CAC/B,CAAC;AAEjB,CAAC","ignoreList":[]}
@@ -1,11 +1,12 @@
1
1
  import React from "react";
2
2
  import { $isQuoteNode, formatToQuote, formatToParagraph } from "@webiny/lexical-nodes";
3
- import { useRichTextEditor } from "../../hooks/useRichTextEditor";
4
- import { useCurrentElement } from "../../hooks/useCurrentElement";
3
+ import { useRichTextEditor } from "../../hooks/useRichTextEditor.js";
4
+ import { useCurrentElement } from "../../hooks/useCurrentElement.js";
5
+ const QUOTE_TAG = "quote";
5
6
  export const QuoteAction = () => {
6
7
  const {
7
8
  editor,
8
- themeEmotionMap
9
+ theme
9
10
  } = useRichTextEditor();
10
11
  const {
11
12
  element
@@ -14,9 +15,8 @@ export const QuoteAction = () => {
14
15
  const formatText = () => {
15
16
  if (!isQuote) {
16
17
  // Try to set default quote style, when the action button is clicked for first time
17
- const DEFAULT_QUOTE_ID = "quote";
18
- const hasQuoteStyles = themeEmotionMap && themeEmotionMap[DEFAULT_QUOTE_ID];
19
- formatToQuote(editor, hasQuoteStyles ? DEFAULT_QUOTE_ID : undefined);
18
+ const hasQuoteStyles = theme.getTypographyByTag(QUOTE_TAG);
19
+ formatToQuote(editor, hasQuoteStyles ? QUOTE_TAG : undefined);
20
20
  return;
21
21
  }
22
22
  formatToParagraph(editor);
@@ -1 +1 @@
1
- {"version":3,"names":["React","$isQuoteNode","formatToQuote","formatToParagraph","useRichTextEditor","useCurrentElement","QuoteAction","editor","themeEmotionMap","element","isQuote","formatText","DEFAULT_QUOTE_ID","hasQuoteStyles","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\";\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,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,YAAY,EAAEC,aAAa,EAAEC,iBAAiB,QAAQ,uBAAuB;AACtF,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAE1B,OAAO,MAAMC,WAAW,GAAGA,CAAA,KAAM;EAC7B,MAAM;IAAEC,MAAM;IAAEC;EAAgB,CAAC,GAAGJ,iBAAiB,CAAC,CAAC;EACvD,MAAM;IAAEK;EAAQ,CAAC,GAAGJ,iBAAiB,CAAC,CAAC;EACvC,MAAMK,OAAO,GAAGT,YAAY,CAACQ,OAAO,CAAC;EAErC,MAAME,UAAU,GAAGA,CAAA,KAAM;IACrB,IAAI,CAACD,OAAO,EAAE;MACV;MACA,MAAME,gBAAgB,GAAG,OAAO;MAChC,MAAMC,cAAc,GAAGL,eAAe,IAAIA,eAAe,CAACI,gBAAgB,CAAC;MAC3EV,aAAa,CAACK,MAAM,EAAEM,cAAc,GAAGD,gBAAgB,GAAGE,SAAS,CAAC;MACpE;IACJ;IACAX,iBAAiB,CAACI,MAAM,CAAC;EAC7B,CAAC;EAED,oBACIP,KAAA,CAAAe,aAAA;IACIC,OAAO,EAAEL,UAAW;IACpBM,SAAS,EAAE,aAAa,IAAIP,OAAO,GAAG,QAAQ,GAAG,EAAE,CAAE;IACrD,cAAW;EAAsB,gBAEjCV,KAAA,CAAAe,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,10 +1,10 @@
1
1
  import React, { useEffect, useMemo } from "react";
2
2
  import { FORMAT_ELEMENT_COMMAND, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND } from "lexical";
3
3
  import { Compose, makeDecoratable } from "@webiny/react-composition";
4
- import { TextAlignmentActionContext } from "../../context/TextAlignmentActionContextProps";
5
- import { useDeriveValueFromSelection } from "../../hooks/useCurrentSelection";
6
- import { getSelectedNode } from "../../utils/getSelectedNode";
7
- import { useRichTextEditor } from "../../hooks";
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";
8
8
 
9
9
  /*
10
10
  * Base text alignment dropdown composable component.
@@ -1 +1 @@
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\";\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,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
+ {"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,10 +1,10 @@
1
1
  import React, { useCallback, useEffect, useState } from "react";
2
2
  import { Compose, makeDecoratable } from "@webiny/react-composition";
3
- import { TypographyActionContext } from "../../context/TypographyActionContext";
3
+ import { TypographyActionContext } from "../../context/TypographyActionContext.js";
4
4
  import { $isHeadingNode, $isListNode, $isParagraphNode, $isQuoteNode } from "@webiny/lexical-nodes";
5
- import { useRichTextEditor } from "../../hooks/useRichTextEditor";
6
- import { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, INSERT_QUOTE_COMMAND, ADD_TYPOGRAPHY_COMMAND } from "../../commands";
7
- import { useCurrentElement } from "../../hooks/useCurrentElement";
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
8
 
9
9
  // Unfortunately, for some time in v5 we had `quoteblock` in our theme, so let's not break it.
10
10
  const quoteTagNames = ["blockquote", "quoteblock"];
@@ -31,7 +31,7 @@ export const TypographyAction = () => {
31
31
  const [typography, setTypography] = useState();
32
32
  const {
33
33
  editor,
34
- themeEmotionMap
34
+ theme
35
35
  } = useRichTextEditor();
36
36
  const {
37
37
  element
@@ -45,16 +45,19 @@ export const TypographyAction = () => {
45
45
  editor.dispatchCommand(ADD_TYPOGRAPHY_COMMAND, {
46
46
  value
47
47
  });
48
+ return;
48
49
  }
49
50
  if (value.tag === "ol") {
50
51
  editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, {
51
52
  themeStyleId: value.id
52
53
  });
54
+ return;
53
55
  }
54
56
  if (value.tag === "ul") {
55
57
  editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, {
56
58
  themeStyleId: value.id
57
59
  });
60
+ return;
58
61
  }
59
62
  if (quoteTagNames.includes(value.tag)) {
60
63
  editor.dispatchCommand(INSERT_QUOTE_COMMAND, {
@@ -63,7 +66,7 @@ export const TypographyAction = () => {
63
66
  }
64
67
  }, []);
65
68
  useEffect(() => {
66
- if (!element || !themeEmotionMap) {
69
+ if (!element) {
67
70
  return;
68
71
  }
69
72
  if (isParagraphSelected || isHeadingSelected || isQuoteSelected) {
@@ -71,27 +74,27 @@ export const TypographyAction = () => {
71
74
  if (!styleId) {
72
75
  return;
73
76
  }
74
- const style = themeEmotionMap[styleId];
77
+ const style = theme.getTypographyById(styleId);
75
78
  if (style) {
76
79
  setTypography({
77
80
  id: style.id,
78
- name: style.name
81
+ label: style.label
79
82
  });
80
83
  }
81
84
  return;
82
85
  }
83
86
 
84
87
  // list and quote element
85
- if (themeEmotionMap && $isListNode(element)) {
88
+ if ($isListNode(element)) {
86
89
  const styleId = element.getStyleId();
87
90
  if (!styleId) {
88
91
  return;
89
92
  }
90
- const style = themeEmotionMap[styleId];
93
+ const style = theme.getTypographyById(styleId);
91
94
  if (style) {
92
95
  setTypography({
93
96
  id: style.id,
94
- name: style.name
97
+ label: style.label
95
98
  });
96
99
  }
97
100
  }
@@ -1 +1 @@
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","themeEmotionMap","isParagraphSelected","isHeadingSelected","isQuoteSelected","onTypographySelect","value","tag","includes","dispatchCommand","themeStyleId","id","styleId","getStyleId","style","name","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\";\nimport { TypographyActionContext } from \"~/context/TypographyActionContext\";\nimport { $isHeadingNode, $isListNode, $isParagraphNode, $isQuoteNode } from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport type { ListCommandPayload, QuoteCommandPayload, TypographyPayload } from \"~/commands\";\nimport {\n INSERT_ORDERED_LIST_COMMAND,\n INSERT_UNORDERED_LIST_COMMAND,\n INSERT_QUOTE_COMMAND,\n ADD_TYPOGRAPHY_COMMAND\n} from \"~/commands\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement\";\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, themeEmotionMap } = 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 }\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 (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 || !themeEmotionMap) {\n return;\n }\n\n if (isParagraphSelected || isHeadingSelected || isQuoteSelected) {\n const styleId = element.getStyleId();\n if (!styleId) {\n return;\n }\n\n const style = themeEmotionMap[styleId];\n if (style) {\n setTypography({\n id: style.id,\n name: style.name\n });\n }\n return;\n }\n\n // list and quote element\n if (themeEmotionMap && $isListNode(element)) {\n const styleId = element.getStyleId();\n if (!styleId) {\n return;\n }\n\n const style = themeEmotionMap[styleId];\n if (style) {\n setTypography({\n id: style.id,\n name: style.name\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;AAE1B,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,CAA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4B,MAAE,CACD,CAAC;AAE3C,CAAC;AAEDQ,gBAAgB,CAACqB,kBAAkB,GAAG1B,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,KAAA,CAAAuB,aAAA,CAACnB,OAAO;IAACoB,SAAS,EAAEN,4BAA6B;IAACO,IAAI,EAAEA,CAAA,KAAM,MAAMH;EAAQ,CAAE,CAAC;AAC1F,CA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ORMAT_TEXT_COMMAND } from "lexical";
3
- import { useCurrentSelection, useRichTextEditor } from "../../hooks";
3
+ import { useCurrentSelection, useRichTextEditor } from "../../hooks/index.js";
4
4
  export const UnderlineAction = () => {
5
5
  const {
6
6
  editor
@@ -1 +1 @@
1
- {"version":3,"names":["React","FORMAT_TEXT_COMMAND","useCurrentSelection","useRichTextEditor","UnderlineAction","editor","rangeSelection","isUnderlineSelected","hasFormat","handleClick","dispatchCommand","createElement","onClick","className"],"sources":["UnderlineAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { FORMAT_TEXT_COMMAND } from \"lexical\";\nimport { useCurrentSelection, useRichTextEditor } from \"~/hooks\";\n\nexport const UnderlineAction = () => {\n const { editor } = useRichTextEditor();\n const { rangeSelection } = useCurrentSelection();\n const isUnderlineSelected = rangeSelection ? rangeSelection.hasFormat(\"underline\") : false;\n\n const handleClick = () => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, \"underline\");\n };\n\n return (\n <button\n onClick={handleClick}\n className={\"popup-item spaced \" + (isUnderlineSelected ? \"active\" : \"\")}\n aria-label=\"Underline text\"\n >\n <i className=\"format underline\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,mBAAmB,EAAEC,iBAAiB;AAE/C,OAAO,MAAMC,eAAe,GAAGA,CAAA,KAAM;EACjC,MAAM;IAAEC;EAAO,CAAC,GAAGF,iBAAiB,CAAC,CAAC;EACtC,MAAM;IAAEG;EAAe,CAAC,GAAGJ,mBAAmB,CAAC,CAAC;EAChD,MAAMK,mBAAmB,GAAGD,cAAc,GAAGA,cAAc,CAACE,SAAS,CAAC,WAAW,CAAC,GAAG,KAAK;EAE1F,MAAMC,WAAW,GAAGA,CAAA,KAAM;IACtBJ,MAAM,CAACK,eAAe,CAACT,mBAAmB,EAAE,WAAW,CAAC;EAC5D,CAAC;EAED,oBACID,KAAA,CAAAW,aAAA;IACIC,OAAO,EAAEH,WAAY;IACrBI,SAAS,EAAE,oBAAoB,IAAIN,mBAAmB,GAAG,QAAQ,GAAG,EAAE,CAAE;IACxE,cAAW;EAAgB,gBAE3BP,KAAA,CAAAW,aAAA;IAAGE,SAAS,EAAC;EAAkB,CAAE,CAC7B,CAAC;AAEjB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","FORMAT_TEXT_COMMAND","useCurrentSelection","useRichTextEditor","UnderlineAction","editor","rangeSelection","isUnderlineSelected","hasFormat","handleClick","dispatchCommand","createElement","onClick","className"],"sources":["UnderlineAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { FORMAT_TEXT_COMMAND } from \"lexical\";\nimport { useCurrentSelection, useRichTextEditor } from \"~/hooks/index.js\";\n\nexport const UnderlineAction = () => {\n const { editor } = useRichTextEditor();\n const { rangeSelection } = useCurrentSelection();\n const isUnderlineSelected = rangeSelection ? rangeSelection.hasFormat(\"underline\") : false;\n\n const handleClick = () => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, \"underline\");\n };\n\n return (\n <button\n onClick={handleClick}\n className={\"popup-item spaced \" + (isUnderlineSelected ? \"active\" : \"\")}\n aria-label=\"Underline text\"\n >\n <i className=\"format underline\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,mBAAmB,EAAEC,iBAAiB;AAE/C,OAAO,MAAMC,eAAe,GAAGA,CAAA,KAAM;EACjC,MAAM;IAAEC;EAAO,CAAC,GAAGF,iBAAiB,CAAC,CAAC;EACtC,MAAM;IAAEG;EAAe,CAAC,GAAGJ,mBAAmB,CAAC,CAAC;EAChD,MAAMK,mBAAmB,GAAGD,cAAc,GAAGA,cAAc,CAACE,SAAS,CAAC,WAAW,CAAC,GAAG,KAAK;EAE1F,MAAMC,WAAW,GAAGA,CAAA,KAAM;IACtBJ,MAAM,CAACK,eAAe,CAACT,mBAAmB,EAAE,WAAW,CAAC;EAC5D,CAAC;EAED,oBACID,KAAA,CAAAW,aAAA;IACIC,OAAO,EAAEH,WAAY;IACrBI,SAAS,EAAE,oBAAoB,IAAIN,mBAAmB,GAAG,QAAQ,GAAG,EAAE,CAAE;IACxE,cAAW;EAAgB,gBAE3BP,KAAA,CAAAW,aAAA;IAAGE,SAAS,EAAC;EAAkB,CAAE,CAC7B,CAAC;AAEjB,CAAC","ignoreList":[]}
@@ -1,19 +1,18 @@
1
1
  import React from "react";
2
2
  import type { LexicalEditor } from "lexical";
3
- import type { ThemeEmotionMap, EditorTheme } from "@webiny/lexical-theme";
4
- import type { ToolbarActionPlugin } from "../types";
3
+ import { type EditorTheme, Theme } from "@webiny/lexical-theme";
4
+ import type { ToolbarActionPlugin } from "../types.js";
5
5
  export interface RichTextEditorContext {
6
6
  editor: LexicalEditor;
7
- theme?: EditorTheme;
8
- themeEmotionMap?: ThemeEmotionMap;
7
+ getOverlaysElement: () => HTMLElement;
9
8
  toolbarActionPlugins: ToolbarActionPlugin[];
9
+ theme: Theme;
10
10
  }
11
11
  export declare const RichTextEditorContext: React.Context<RichTextEditorContext | undefined>;
12
12
  interface RichTextEditorProviderProps {
13
13
  theme: EditorTheme;
14
- themeEmotionMap?: ThemeEmotionMap;
15
14
  toolbarActionPlugins?: ToolbarActionPlugin[];
16
15
  children?: React.ReactNode | React.ReactNode[];
17
16
  }
18
- export declare const RichTextEditorProvider: ({ themeEmotionMap, theme, toolbarActionPlugins, children }: RichTextEditorProviderProps) => React.JSX.Element;
17
+ export declare const RichTextEditorProvider: ({ theme, toolbarActionPlugins, children }: RichTextEditorProviderProps) => React.JSX.Element;
19
18
  export {};
@@ -1,18 +1,31 @@
1
- import React, { createContext } from "react";
1
+ import React, { createContext, useCallback, useMemo } from "react";
2
2
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
+ import { Theme } from "@webiny/lexical-theme";
3
4
  export const RichTextEditorContext = /*#__PURE__*/createContext(undefined);
4
5
  export const RichTextEditorProvider = ({
5
- themeEmotionMap,
6
6
  theme,
7
7
  toolbarActionPlugins = [],
8
8
  children
9
9
  }) => {
10
10
  const [editor] = useLexicalComposerContext();
11
+ const getOverlaysElement = useCallback(() => {
12
+ const rootElement = editor.getRootElement();
13
+ if (!rootElement) {
14
+ return document.body;
15
+ }
16
+ const shell = rootElement.closest(".editor-shell");
17
+ if (!shell) {
18
+ return document.body;
19
+ }
20
+ const overlays = shell.previousElementSibling;
21
+ return overlays ?? document.body;
22
+ }, [editor]);
23
+ const internalTheme = useMemo(() => new Theme(theme.colors, theme.typography, theme.tokens), [theme]);
11
24
  return /*#__PURE__*/React.createElement(RichTextEditorContext.Provider, {
12
25
  value: {
13
26
  editor,
14
- theme,
15
- themeEmotionMap,
27
+ getOverlaysElement,
28
+ theme: internalTheme,
16
29
  toolbarActionPlugins
17
30
  }
18
31
  }, children);
@@ -1 +1 @@
1
- {"version":3,"names":["React","createContext","useLexicalComposerContext","RichTextEditorContext","undefined","RichTextEditorProvider","themeEmotionMap","theme","toolbarActionPlugins","children","editor","createElement","Provider","value"],"sources":["RichTextEditorContext.tsx"],"sourcesContent":["import React, { createContext } from \"react\";\nimport type { LexicalEditor } from \"lexical\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport type { ThemeEmotionMap, EditorTheme } from \"@webiny/lexical-theme\";\nimport type { ToolbarActionPlugin } from \"~/types\";\n\nexport interface RichTextEditorContext {\n editor: LexicalEditor;\n theme?: EditorTheme;\n themeEmotionMap?: ThemeEmotionMap;\n toolbarActionPlugins: ToolbarActionPlugin[];\n}\n\nexport const RichTextEditorContext = createContext<RichTextEditorContext | undefined>(undefined);\n\ninterface RichTextEditorProviderProps {\n theme: EditorTheme;\n themeEmotionMap?: ThemeEmotionMap;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n children?: React.ReactNode | React.ReactNode[];\n}\n\nexport const RichTextEditorProvider = ({\n themeEmotionMap,\n theme,\n toolbarActionPlugins = [],\n children\n}: RichTextEditorProviderProps) => {\n const [editor] = useLexicalComposerContext();\n\n return (\n <RichTextEditorContext.Provider\n value={{\n editor,\n theme,\n themeEmotionMap,\n toolbarActionPlugins\n }}\n >\n {children}\n </RichTextEditorContext.Provider>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,QAAQ,OAAO;AAE5C,SAASC,yBAAyB,QAAQ,uCAAuC;AAWjF,OAAO,MAAMC,qBAAqB,gBAAGF,aAAa,CAAoCG,SAAS,CAAC;AAShG,OAAO,MAAMC,sBAAsB,GAAGA,CAAC;EACnCC,eAAe;EACfC,KAAK;EACLC,oBAAoB,GAAG,EAAE;EACzBC;AACyB,CAAC,KAAK;EAC/B,MAAM,CAACC,MAAM,CAAC,GAAGR,yBAAyB,CAAC,CAAC;EAE5C,oBACIF,KAAA,CAAAW,aAAA,CAACR,qBAAqB,CAACS,QAAQ;IAC3BC,KAAK,EAAE;MACHH,MAAM;MACNH,KAAK;MACLD,eAAe;MACfE;IACJ;EAAE,GAEDC,QAC2B,CAAC;AAEzC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","createContext","useCallback","useMemo","useLexicalComposerContext","Theme","RichTextEditorContext","undefined","RichTextEditorProvider","theme","toolbarActionPlugins","children","editor","getOverlaysElement","rootElement","getRootElement","document","body","shell","closest","overlays","previousElementSibling","internalTheme","colors","typography","tokens","createElement","Provider","value"],"sources":["RichTextEditorContext.tsx"],"sourcesContent":["import React, { createContext, useCallback, useMemo } from \"react\";\nimport type { LexicalEditor } from \"lexical\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { type EditorTheme, Theme } from \"@webiny/lexical-theme\";\nimport type { ToolbarActionPlugin } from \"~/types.js\";\n\nexport interface RichTextEditorContext {\n editor: LexicalEditor;\n getOverlaysElement: () => HTMLElement;\n toolbarActionPlugins: ToolbarActionPlugin[];\n theme: Theme;\n}\n\nexport const RichTextEditorContext = createContext<RichTextEditorContext | undefined>(undefined);\n\ninterface RichTextEditorProviderProps {\n theme: EditorTheme;\n toolbarActionPlugins?: ToolbarActionPlugin[];\n children?: React.ReactNode | React.ReactNode[];\n}\n\nexport const RichTextEditorProvider = ({\n theme,\n toolbarActionPlugins = [],\n children\n}: RichTextEditorProviderProps) => {\n const [editor] = useLexicalComposerContext();\n\n const getOverlaysElement = useCallback(() => {\n const rootElement = editor.getRootElement();\n if (!rootElement) {\n return document.body;\n }\n\n const shell = rootElement.closest(\".editor-shell\");\n if (!shell) {\n return document.body;\n }\n const overlays = shell.previousElementSibling;\n\n return (overlays ?? document.body) as HTMLElement;\n }, [editor]);\n\n const internalTheme = useMemo(\n () => new Theme(theme.colors, theme.typography, theme.tokens),\n [theme]\n );\n\n return (\n <RichTextEditorContext.Provider\n value={{\n editor,\n getOverlaysElement,\n theme: internalTheme,\n toolbarActionPlugins\n }}\n >\n {children}\n </RichTextEditorContext.Provider>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAElE,SAASC,yBAAyB,QAAQ,uCAAuC;AACjF,SAA2BC,KAAK,QAAQ,uBAAuB;AAU/D,OAAO,MAAMC,qBAAqB,gBAAGL,aAAa,CAAoCM,SAAS,CAAC;AAQhG,OAAO,MAAMC,sBAAsB,GAAGA,CAAC;EACnCC,KAAK;EACLC,oBAAoB,GAAG,EAAE;EACzBC;AACyB,CAAC,KAAK;EAC/B,MAAM,CAACC,MAAM,CAAC,GAAGR,yBAAyB,CAAC,CAAC;EAE5C,MAAMS,kBAAkB,GAAGX,WAAW,CAAC,MAAM;IACzC,MAAMY,WAAW,GAAGF,MAAM,CAACG,cAAc,CAAC,CAAC;IAC3C,IAAI,CAACD,WAAW,EAAE;MACd,OAAOE,QAAQ,CAACC,IAAI;IACxB;IAEA,MAAMC,KAAK,GAAGJ,WAAW,CAACK,OAAO,CAAC,eAAe,CAAC;IAClD,IAAI,CAACD,KAAK,EAAE;MACR,OAAOF,QAAQ,CAACC,IAAI;IACxB;IACA,MAAMG,QAAQ,GAAGF,KAAK,CAACG,sBAAsB;IAE7C,OAAQD,QAAQ,IAAIJ,QAAQ,CAACC,IAAI;EACrC,CAAC,EAAE,CAACL,MAAM,CAAC,CAAC;EAEZ,MAAMU,aAAa,GAAGnB,OAAO,CACzB,MAAM,IAAIE,KAAK,CAACI,KAAK,CAACc,MAAM,EAAEd,KAAK,CAACe,UAAU,EAAEf,KAAK,CAACgB,MAAM,CAAC,EAC7D,CAAChB,KAAK,CACV,CAAC;EAED,oBACIT,KAAA,CAAA0B,aAAA,CAACpB,qBAAqB,CAACqB,QAAQ;IAC3BC,KAAK,EAAE;MACHhB,MAAM;MACNC,kBAAkB;MAClBJ,KAAK,EAAEa,aAAa;MACpBZ;IACJ;EAAE,GAEDC,QAC2B,CAAC;AAEzC,CAAC","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import type { TypographyValue } from "@webiny/lexical-theme";
3
- export type ActiveTypography = Pick<TypographyValue, "id" | "name">;
3
+ export type ActiveTypography = Pick<TypographyValue, "id" | "label">;
4
4
  export interface TypographyActionContextProps {
5
5
  value: ActiveTypography | undefined;
6
6
  applyTypography: (value: TypographyValue) => void;
@@ -1 +1 @@
1
- {"version":3,"names":["React","TypographyActionContext","createContext","undefined"],"sources":["TypographyActionContext.tsx"],"sourcesContent":["import React from \"react\";\nimport type { TypographyValue } from \"@webiny/lexical-theme\";\n\nexport type ActiveTypography = Pick<TypographyValue, \"id\" | \"name\">;\n\nexport interface TypographyActionContextProps {\n /*\n * @desc Current selected typography\n * */\n value: ActiveTypography | undefined;\n\n /*\n * @desc Apply font family to selected text.\n * @params: value\n */\n applyTypography: (value: TypographyValue) => void;\n}\n\nexport const TypographyActionContext = React.createContext<\n TypographyActionContextProps | undefined\n>(undefined);\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAkBzB,OAAO,MAAMC,uBAAuB,gBAAGD,KAAK,CAACE,aAAa,CAExDC,SAAS,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","TypographyActionContext","createContext","undefined"],"sources":["TypographyActionContext.tsx"],"sourcesContent":["import React from \"react\";\nimport type { TypographyValue } from \"@webiny/lexical-theme\";\n\nexport type ActiveTypography = Pick<TypographyValue, \"id\" | \"label\">;\n\nexport interface TypographyActionContextProps {\n /*\n * @desc Current selected typography\n * */\n value: ActiveTypography | undefined;\n\n /*\n * @desc Apply font family to selected text.\n * @params: value\n */\n applyTypography: (value: TypographyValue) => void;\n}\n\nexport const TypographyActionContext = React.createContext<\n TypographyActionContextProps | undefined\n>(undefined);\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAkBzB,OAAO,MAAMC,uBAAuB,gBAAGD,KAAK,CAACE,aAAa,CAExDC,SAAS,CAAC","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ export { LexicalHtmlRenderer } from "../../components/LexicalHtmlRenderer.js";
2
+ export { getNodeFromSelection } from "../../hooks/index.js";
3
+ export { useCurrentElement } from "../../hooks/index.js";
4
+ export { useCurrentSelection } from "../../hooks/index.js";
5
+ export { useDeriveValueFromSelection } from "../../hooks/index.js";
6
+ export { useRichTextEditor } from "../../hooks/index.js";
7
+ export { useFontColorPicker } from "../../hooks/index.js";
8
+ export { useTextAlignmentAction } from "../../hooks/index.js";
9
+ export { useTypographyAction } from "../../hooks/index.js";
10
+ export { useIsMounted } from "../../hooks/index.js";
11
+ export { Divider } from "../../ui/Divider.js";
12
+ export { DropDownItem } from "../../ui/DropDown.js";
13
+ export { DropDown } from "../../ui/DropDown.js";
14
+ export type { Klass, LexicalNode } from "../../types.js";
15
+ export { LexicalEditorConfig, useLexicalEditorConfig } from "../../components/LexicalEditorConfig/LexicalEditorConfig.js";
@@ -0,0 +1,23 @@
1
+ // render
2
+ export { LexicalHtmlRenderer } from "../../components/LexicalHtmlRenderer.js";
3
+ // hooks
4
+ export { getNodeFromSelection } from "../../hooks/index.js";
5
+ export { useCurrentElement } from "../../hooks/index.js";
6
+ export { useCurrentSelection } from "../../hooks/index.js";
7
+ export { useDeriveValueFromSelection } from "../../hooks/index.js";
8
+ export { useRichTextEditor } from "../../hooks/index.js";
9
+ export { useFontColorPicker } from "../../hooks/index.js";
10
+ export { useTextAlignmentAction } from "../../hooks/index.js";
11
+ export { useTypographyAction } from "../../hooks/index.js";
12
+ export { useIsMounted } from "../../hooks/index.js";
13
+ // UI elements
14
+ export { Divider } from "../../ui/Divider.js";
15
+ export { DropDownItem } from "../../ui/DropDown.js";
16
+ export { DropDown } from "../../ui/DropDown.js";
17
+
18
+ // types
19
+
20
+ // config
21
+ export { LexicalEditorConfig, useLexicalEditorConfig } from "../../components/LexicalEditorConfig/LexicalEditorConfig.js";
22
+
23
+ //# sourceMappingURL=lexical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["LexicalHtmlRenderer","getNodeFromSelection","useCurrentElement","useCurrentSelection","useDeriveValueFromSelection","useRichTextEditor","useFontColorPicker","useTextAlignmentAction","useTypographyAction","useIsMounted","Divider","DropDownItem","DropDown","LexicalEditorConfig","useLexicalEditorConfig"],"sources":["lexical.ts"],"sourcesContent":["// render\nexport { LexicalHtmlRenderer } from \"~/components/LexicalHtmlRenderer.js\";\n// hooks\nexport { getNodeFromSelection } from \"~/hooks/index.js\";\nexport { useCurrentElement } from \"~/hooks/index.js\";\nexport { useCurrentSelection } from \"~/hooks/index.js\";\nexport { useDeriveValueFromSelection } from \"~/hooks/index.js\";\nexport { useRichTextEditor } from \"~/hooks/index.js\";\nexport { useFontColorPicker } from \"~/hooks/index.js\";\nexport { useTextAlignmentAction } from \"~/hooks/index.js\";\nexport { useTypographyAction } from \"~/hooks/index.js\";\nexport { useIsMounted } from \"~/hooks/index.js\";\n// UI elements\nexport { Divider } from \"~/ui/Divider.js\";\nexport { DropDownItem } from \"~/ui/DropDown.js\";\nexport { DropDown } from \"~/ui/DropDown.js\";\n\n// types\nexport type { Klass, LexicalNode } from \"~/types.js\";\n// config\nexport {\n LexicalEditorConfig,\n useLexicalEditorConfig\n} from \"~/components/LexicalEditorConfig/LexicalEditorConfig.js\";\n"],"mappings":"AAAA;AACA,SAASA,mBAAmB;AAC5B;AACA,SAASC,oBAAoB;AAC7B,SAASC,iBAAiB;AAC1B,SAASC,mBAAmB;AAC5B,SAASC,2BAA2B;AACpC,SAASC,iBAAiB;AAC1B,SAASC,kBAAkB;AAC3B,SAASC,sBAAsB;AAC/B,SAASC,mBAAmB;AAC5B,SAASC,YAAY;AACrB;AACA,SAASC,OAAO;AAChB,SAASC,YAAY;AACrB,SAASC,QAAQ;;AAEjB;;AAEA;AACA,SACIC,mBAAmB,EACnBC,sBAAsB","ignoreList":[]}
package/hooks/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- export * from "./useRichTextEditor";
2
- export * from "./useFontColorPicker";
3
- export * from "./useTypographyAction";
4
- export * from "./useTextAlignmentAction";
5
- export * from "./useCurrentSelection";
6
- export * from "./useCurrentElement";
7
- export * from "./useList";
8
- export * from "./useIsMounted";
1
+ export * from "./useRichTextEditor.js";
2
+ export * from "./useFontColorPicker.js";
3
+ export * from "./useTypographyAction.js";
4
+ export * from "./useTextAlignmentAction.js";
5
+ export * from "./useCurrentSelection.js";
6
+ export * from "./useCurrentElement.js";
7
+ export * from "./useIsMounted.js";
package/hooks/index.js CHANGED
@@ -1,10 +1,9 @@
1
- export * from "./useRichTextEditor";
2
- export * from "./useFontColorPicker";
3
- export * from "./useTypographyAction";
4
- export * from "./useTextAlignmentAction";
5
- export * from "./useCurrentSelection";
6
- export * from "./useCurrentElement";
7
- export * from "./useList";
8
- export * from "./useIsMounted";
1
+ export * from "./useRichTextEditor.js";
2
+ export * from "./useFontColorPicker.js";
3
+ export * from "./useTypographyAction.js";
4
+ export * from "./useTextAlignmentAction.js";
5
+ export * from "./useCurrentSelection.js";
6
+ export * from "./useCurrentElement.js";
7
+ export * from "./useIsMounted.js";
9
8
 
10
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./useRichTextEditor\";\nexport * from \"./useFontColorPicker\";\nexport * from \"./useTypographyAction\";\nexport * from \"./useTextAlignmentAction\";\nexport * from \"./useCurrentSelection\";\nexport * from \"./useCurrentElement\";\nexport * from \"./useList\";\nexport * from \"./useIsMounted\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./useRichTextEditor.js\";\nexport * from \"./useFontColorPicker.js\";\nexport * from \"./useTypographyAction.js\";\nexport * from \"./useTextAlignmentAction.js\";\nexport * from \"./useCurrentSelection.js\";\nexport * from \"./useCurrentElement.js\";\nexport * from \"./useIsMounted.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1,6 +1,5 @@
1
- import { $findMatchingParent } from "@lexical/utils";
2
- import { $isRootOrShadowRoot } from "lexical";
3
- import { useDeriveValueFromSelection } from "./useCurrentSelection";
1
+ import { $isRootOrShadowRoot, $findMatchingParent } from "lexical";
2
+ import { useDeriveValueFromSelection } from "./useCurrentSelection.js";
4
3
  export function useCurrentElement() {
5
4
  return useDeriveValueFromSelection(({
6
5
  rangeSelection
@@ -1 +1 @@
1
- {"version":3,"names":["$findMatchingParent","$isRootOrShadowRoot","useDeriveValueFromSelection","useCurrentElement","rangeSelection","element","getNodeFromSelection","selection","anchorNode","anchor","getNode","getKey","e","parent","getParent","getTopLevelElementOrThrow"],"sources":["useCurrentElement.ts"],"sourcesContent":["import { $findMatchingParent } from \"@lexical/utils\";\nimport type { RangeSelection } from \"lexical\";\nimport { $isRootOrShadowRoot } from \"lexical\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection\";\n\nexport function useCurrentElement() {\n return useDeriveValueFromSelection(({ rangeSelection }) => {\n if (!rangeSelection) {\n return { element: null };\n }\n\n return { element: getNodeFromSelection(rangeSelection) };\n });\n}\n\nexport function getNodeFromSelection(selection: RangeSelection) {\n const anchorNode = selection.anchor.getNode();\n\n const element =\n anchorNode.getKey() === \"root\"\n ? anchorNode\n : $findMatchingParent(anchorNode, e => {\n const parent = e.getParent();\n return parent !== null && $isRootOrShadowRoot(parent);\n });\n\n return element || anchorNode.getTopLevelElementOrThrow();\n}\n"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,gBAAgB;AAEpD,SAASC,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,2BAA2B;AAEpC,OAAO,SAASC,iBAAiBA,CAAA,EAAG;EAChC,OAAOD,2BAA2B,CAAC,CAAC;IAAEE;EAAe,CAAC,KAAK;IACvD,IAAI,CAACA,cAAc,EAAE;MACjB,OAAO;QAAEC,OAAO,EAAE;MAAK,CAAC;IAC5B;IAEA,OAAO;MAAEA,OAAO,EAAEC,oBAAoB,CAACF,cAAc;IAAE,CAAC;EAC5D,CAAC,CAAC;AACN;AAEA,OAAO,SAASE,oBAAoBA,CAACC,SAAyB,EAAE;EAC5D,MAAMC,UAAU,GAAGD,SAAS,CAACE,MAAM,CAACC,OAAO,CAAC,CAAC;EAE7C,MAAML,OAAO,GACTG,UAAU,CAACG,MAAM,CAAC,CAAC,KAAK,MAAM,GACxBH,UAAU,GACVR,mBAAmB,CAACQ,UAAU,EAAEI,CAAC,IAAI;IACjC,MAAMC,MAAM,GAAGD,CAAC,CAACE,SAAS,CAAC,CAAC;IAC5B,OAAOD,MAAM,KAAK,IAAI,IAAIZ,mBAAmB,CAACY,MAAM,CAAC;EACzD,CAAC,CAAC;EAEZ,OAAOR,OAAO,IAAIG,UAAU,CAACO,yBAAyB,CAAC,CAAC;AAC5D","ignoreList":[]}
1
+ {"version":3,"names":["$isRootOrShadowRoot","$findMatchingParent","useDeriveValueFromSelection","useCurrentElement","rangeSelection","element","getNodeFromSelection","selection","anchorNode","anchor","getNode","getKey","e","parent","getParent","getTopLevelElementOrThrow"],"sources":["useCurrentElement.ts"],"sourcesContent":["import type { RangeSelection } from \"lexical\";\nimport { $isRootOrShadowRoot, $findMatchingParent } from \"lexical\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection.js\";\n\nexport function useCurrentElement() {\n return useDeriveValueFromSelection(({ rangeSelection }) => {\n if (!rangeSelection) {\n return { element: null };\n }\n\n return { element: getNodeFromSelection(rangeSelection) };\n });\n}\n\nexport function getNodeFromSelection(selection: RangeSelection) {\n const anchorNode = selection.anchor.getNode();\n\n const element =\n anchorNode.getKey() === \"root\"\n ? anchorNode\n : $findMatchingParent(anchorNode, e => {\n const parent = e.getParent();\n return parent !== null && $isRootOrShadowRoot(parent);\n });\n\n return element || anchorNode.getTopLevelElementOrThrow();\n}\n"],"mappings":"AACA,SAASA,mBAAmB,EAAEC,mBAAmB,QAAQ,SAAS;AAClE,SAASC,2BAA2B;AAEpC,OAAO,SAASC,iBAAiBA,CAAA,EAAG;EAChC,OAAOD,2BAA2B,CAAC,CAAC;IAAEE;EAAe,CAAC,KAAK;IACvD,IAAI,CAACA,cAAc,EAAE;MACjB,OAAO;QAAEC,OAAO,EAAE;MAAK,CAAC;IAC5B;IAEA,OAAO;MAAEA,OAAO,EAAEC,oBAAoB,CAACF,cAAc;IAAE,CAAC;EAC5D,CAAC,CAAC;AACN;AAEA,OAAO,SAASE,oBAAoBA,CAACC,SAAyB,EAAE;EAC5D,MAAMC,UAAU,GAAGD,SAAS,CAACE,MAAM,CAACC,OAAO,CAAC,CAAC;EAE7C,MAAML,OAAO,GACTG,UAAU,CAACG,MAAM,CAAC,CAAC,KAAK,MAAM,GACxBH,UAAU,GACVP,mBAAmB,CAACO,UAAU,EAAEI,CAAC,IAAI;IACjC,MAAMC,MAAM,GAAGD,CAAC,CAACE,SAAS,CAAC,CAAC;IAC5B,OAAOD,MAAM,KAAK,IAAI,IAAIb,mBAAmB,CAACa,MAAM,CAAC;EACzD,CAAC,CAAC;EAEZ,OAAOR,OAAO,IAAIG,UAAU,CAACO,yBAAyB,CAAC,CAAC;AAC5D","ignoreList":[]}
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useEffect, useState } from "react";
2
2
  import { $getSelection, $isRangeSelection, $isNodeSelection } from "lexical";
3
- import { useIsMounted } from "./useIsMounted";
4
- import { useRichTextEditor } from "./useRichTextEditor";
3
+ import { useIsMounted } from "./useIsMounted.js";
4
+ import { useRichTextEditor } from "./useRichTextEditor.js";
5
5
  function getOutput(selection) {
6
6
  return {
7
7
  selection,
@@ -16,7 +16,7 @@ export function useCurrentSelection() {
16
16
  const [selection, setSelection] = useState(getOutput(null));
17
17
  const isMounted = useIsMounted();
18
18
  const storeSelection = useCallback(() => {
19
- editor.getEditorState().read(() => {
19
+ editor.read(() => {
20
20
  if (isMounted()) {
21
21
  setSelection(getOutput($getSelection()));
22
22
  }
@@ -38,7 +38,7 @@ export function useDeriveValueFromSelection(generator) {
38
38
  const [value, setValue] = useState(generator(getOutput(null)));
39
39
  const isMounted = useIsMounted();
40
40
  const generateValue = useCallback(() => {
41
- editor.getEditorState().read(() => {
41
+ editor.read(() => {
42
42
  if (isMounted()) {
43
43
  setValue(generator(getOutput($getSelection())));
44
44
  }
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useEffect","useState","$getSelection","$isRangeSelection","$isNodeSelection","useIsMounted","useRichTextEditor","getOutput","selection","rangeSelection","nodeSelection","useCurrentSelection","editor","setSelection","isMounted","storeSelection","getEditorState","read","registerUpdateListener","useDeriveValueFromSelection","generator","value","setValue","generateValue"],"sources":["useCurrentSelection.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport type { RangeSelection, NodeSelection } from \"lexical\";\nimport { $getSelection, $isRangeSelection, $isNodeSelection } from \"lexical\";\nimport { useIsMounted } from \"./useIsMounted\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\n\nexport interface CurrentSelection {\n selection: ReturnType<typeof $getSelection>;\n rangeSelection: RangeSelection | null;\n nodeSelection: NodeSelection | null;\n}\n\ninterface Generator<T> {\n (params: CurrentSelection): T;\n}\n\nfunction getOutput(selection: ReturnType<typeof $getSelection>) {\n return {\n selection,\n rangeSelection: $isRangeSelection(selection) ? selection : null,\n nodeSelection: $isNodeSelection(selection) ? selection : null\n };\n}\n\nexport function useCurrentSelection() {\n const { editor } = useRichTextEditor();\n const [selection, setSelection] = useState<CurrentSelection>(getOutput(null));\n const isMounted = useIsMounted();\n\n const storeSelection = useCallback(() => {\n editor.getEditorState().read(() => {\n if (isMounted()) {\n setSelection(getOutput($getSelection()));\n }\n });\n }, [editor]);\n\n useEffect(() => {\n // On first mount, store current selection.\n storeSelection();\n\n // Subscribe to editor updates and keep track of the selection.\n return editor.registerUpdateListener(storeSelection);\n }, []);\n\n return selection;\n}\n\nexport function useDeriveValueFromSelection<T>(generator: Generator<T>) {\n const { editor } = useRichTextEditor();\n const [value, setValue] = useState<T>(generator(getOutput(null)));\n const isMounted = useIsMounted();\n\n const generateValue = useCallback(() => {\n editor.getEditorState().read(() => {\n if (isMounted()) {\n setValue(generator(getOutput($getSelection())));\n }\n });\n }, [editor]);\n\n useEffect(() => {\n // On first mount, generate current value.\n generateValue();\n\n // Subscribe to editor updates and regenerate the value.\n return editor.registerUpdateListener(generateValue);\n }, []);\n\n return value;\n}\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAExD,SAASC,aAAa,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,SAAS;AAC5E,SAASC,YAAY;AACrB,SAASC,iBAAiB;AAY1B,SAASC,SAASA,CAACC,SAA2C,EAAE;EAC5D,OAAO;IACHA,SAAS;IACTC,cAAc,EAAEN,iBAAiB,CAACK,SAAS,CAAC,GAAGA,SAAS,GAAG,IAAI;IAC/DE,aAAa,EAAEN,gBAAgB,CAACI,SAAS,CAAC,GAAGA,SAAS,GAAG;EAC7D,CAAC;AACL;AAEA,OAAO,SAASG,mBAAmBA,CAAA,EAAG;EAClC,MAAM;IAA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Aa,CAAC,CAAC;;IAEf;IACA,OAAOX,MAAM,CAACM,sBAAsB,CAACK,aAAa,CAAC;EACvD,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOF,KAAK;AAChB","ignoreList":[]}
1
+ {"version":3,"names":["useCallback","useEffect","useState","$getSelection","$isRangeSelection","$isNodeSelection","useIsMounted","useRichTextEditor","getOutput","selection","rangeSelection","nodeSelection","useCurrentSelection","editor","setSelection","isMounted","storeSelection","read","registerUpdateListener","useDeriveValueFromSelection","generator","value","setValue","generateValue"],"sources":["useCurrentSelection.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport type { RangeSelection, NodeSelection } from \"lexical\";\nimport { $getSelection, $isRangeSelection, $isNodeSelection } from \"lexical\";\nimport { useIsMounted } from \"./useIsMounted.js\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor.js\";\n\nexport interface CurrentSelection {\n selection: ReturnType<typeof $getSelection>;\n rangeSelection: RangeSelection | null;\n nodeSelection: NodeSelection | null;\n}\n\ninterface Generator<T> {\n (params: CurrentSelection): T;\n}\n\nfunction getOutput(selection: ReturnType<typeof $getSelection>) {\n return {\n selection,\n rangeSelection: $isRangeSelection(selection) ? selection : null,\n nodeSelection: $isNodeSelection(selection) ? selection : null\n };\n}\n\nexport function useCurrentSelection() {\n const { editor } = useRichTextEditor();\n const [selection, setSelection] = useState<CurrentSelection>(getOutput(null));\n const isMounted = useIsMounted();\n\n const storeSelection = useCallback(() => {\n editor.read(() => {\n if (isMounted()) {\n setSelection(getOutput($getSelection()));\n }\n });\n }, [editor]);\n\n useEffect(() => {\n // On first mount, store current selection.\n storeSelection();\n\n // Subscribe to editor updates and keep track of the selection.\n return editor.registerUpdateListener(storeSelection);\n }, []);\n\n return selection;\n}\n\nexport function useDeriveValueFromSelection<T>(generator: Generator<T>) {\n const { editor } = useRichTextEditor();\n const [value, setValue] = useState<T>(generator(getOutput(null)));\n const isMounted = useIsMounted();\n\n const generateValue = useCallback(() => {\n editor.read(() => {\n if (isMounted()) {\n setValue(generator(getOutput($getSelection())));\n }\n });\n }, [editor]);\n\n useEffect(() => {\n // On first mount, generate current value.\n generateValue();\n\n // Subscribe to editor updates and regenerate the value.\n return editor.registerUpdateListener(generateValue);\n }, []);\n\n return value;\n}\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAExD,SAASC,aAAa,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,SAAS;AAC5E,SAASC,YAAY;AACrB,SAASC,iBAAiB;AAY1B,SAASC,SAASA,CAACC,SAA2C,EAAE;EAC5D,OAAO;IACHA,SAAS;IACTC,cAAc,EAAEN,iBAAiB,CAACK,SAAS,CAAC,GAAGA,SAAS,GAAG,IAAI;IAC/DE,aAAa,EAAEN,gBAAgB,CAACI,SAAS,CAAC,GAAGA,SAAS,GAAG;EAC7D,CAAC;AACL;AAEA,OAAO,SAASG,mBAAmBA,CAAA,EAAG;EAClC,MAAM;IAAEC;EAAO,CAAC,GAAGN,iBAAiB,CAAC,CAAC;EACtC,MAAM,CAACE,SAAS,EAAEK,YAAY,CAAC,GAAGZ,QAAQ,CAAmBM,SAAS,CAAC,IAAI,CAAC,CAAC;EAC7E,MAAMO,SAAS,GAAGT,YAAY,CAAC,CAAC;EAEhC,MAAMU,cAAc,GAAGhB,WAAW,CAAC,MAAM;IACrCa,MAAM,CAACI,IAAI,CAAC,MAAM;MACd,IAAIF,SAAS,CAAC,CAAC,EAAE;QACbD,YAAY,CAACN,SAAS,CAACL,aAAa,CAAC,CAAC,CAAC,CAAC;MAC5C;IACJ,CAAC,CAAC;EACN,CAAC,EAAE,CAACU,MAAM,CAAC,CAAC;EAEZZ,SAAS,CAAC,MAAM;IACZ;IACAe,cAAc,CAAC,CAAC;;IAEhB;IACA,OAAOH,MAAM,CAACK,sBAAsB,CAACF,cAAc,CAAC;EACxD,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOP,SAAS;AACpB;AAEA,OAAO,SAASU,2BAA2BA,CAAIC,SAAuB,EAAE;EACpE,MAAM;IAAEP;EAAO,CAAC,GAAGN,iBAAiB,CAAC,CAAC;EACtC,MAAM,CAACc,KAAK,EAAEC,QAAQ,CAAC,GAAGpB,QAAQ,CAAIkB,SAAS,CAACZ,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;EACjE,MAAMO,SAAS,GAAGT,YAAY,CAAC,CAAC;EAEhC,MAAMiB,aAAa,GAAGvB,WAAW,CAAC,MAAM;IACpCa,MAAM,CAACI,IAAI,CAAC,MAAM;MACd,IAAIF,SAAS,CAAC,CAAC,EAAE;QACbO,QAAQ,CAACF,SAAS,CAACZ,SAAS,CAACL,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;MACnD;IACJ,CAAC,CAAC;EACN,CAAC,EAAE,CAACU,MAAM,CAAC,CAAC;EAEZZ,SAAS,CAAC,MAAM;IACZ;IACAsB,aAAa,CAAC,CAAC;;IAEf;IACA,OAAOV,MAAM,CAACK,sBAAsB,CAACK,aAAa,CAAC;EACvD,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOF,KAAK;AAChB","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import { FontColorActionContext } from "../context/FontColorActionContext";
1
+ import { FontColorActionContext } from "../context/FontColorActionContext.js";
2
2
  export declare function useFontColorPicker(): FontColorActionContext;