@pega/cosmos-react-rte 5.0.0-dev.4.8 → 5.0.0-dev.5.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 (193) hide show
  1. package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts +12 -0
  2. package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts.map +1 -0
  3. package/lib/components/DynamicContentEditor/DynamicContentEditor.js +252 -0
  4. package/lib/components/DynamicContentEditor/DynamicContentEditor.js.map +1 -0
  5. package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.d.ts +2 -0
  6. package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.d.ts.map +1 -0
  7. package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.js +8 -0
  8. package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.js.map +1 -0
  9. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts +35 -0
  10. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts.map +1 -0
  11. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js +3 -0
  12. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js.map +1 -0
  13. package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts +329 -0
  14. package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts.map +1 -0
  15. package/lib/components/DynamicContentEditor/PegaCustomElement.js +27 -0
  16. package/lib/components/DynamicContentEditor/PegaCustomElement.js.map +1 -0
  17. package/lib/components/DynamicContentEditor/index.d.ts +3 -0
  18. package/lib/components/DynamicContentEditor/index.d.ts.map +1 -0
  19. package/lib/components/DynamicContentEditor/index.js +2 -0
  20. package/lib/components/DynamicContentEditor/index.js.map +1 -0
  21. package/lib/components/Editor/Editor.context.d.ts +10 -0
  22. package/lib/components/Editor/Editor.context.d.ts.map +1 -0
  23. package/lib/components/Editor/Editor.context.js +10 -0
  24. package/lib/components/Editor/Editor.context.js.map +1 -0
  25. package/lib/components/Editor/Editor.d.ts +19 -0
  26. package/lib/components/Editor/Editor.d.ts.map +1 -0
  27. package/lib/components/Editor/Editor.js +369 -0
  28. package/lib/components/Editor/Editor.js.map +1 -0
  29. package/lib/components/Editor/Editor.styles.d.ts +5 -0
  30. package/lib/components/Editor/Editor.styles.d.ts.map +1 -0
  31. package/lib/components/Editor/Editor.styles.js +50 -0
  32. package/lib/components/Editor/Editor.styles.js.map +1 -0
  33. package/lib/components/Editor/Editor.test-ids.d.ts +2 -0
  34. package/lib/components/Editor/Editor.test-ids.d.ts.map +1 -0
  35. package/lib/components/Editor/Editor.test-ids.js +8 -0
  36. package/lib/components/Editor/Editor.test-ids.js.map +1 -0
  37. package/lib/components/Editor/Editor.types.d.ts +69 -0
  38. package/lib/components/Editor/Editor.types.d.ts.map +1 -0
  39. package/lib/components/Editor/Editor.types.js +2 -0
  40. package/lib/components/Editor/Editor.types.js.map +1 -0
  41. package/lib/components/Editor/ImageEditor.d.ts +10 -0
  42. package/lib/components/Editor/ImageEditor.d.ts.map +1 -0
  43. package/lib/components/Editor/ImageEditor.js +276 -0
  44. package/lib/components/Editor/ImageEditor.js.map +1 -0
  45. package/lib/components/Editor/Toolbar/AnchorButton.d.ts +10 -0
  46. package/lib/components/Editor/Toolbar/AnchorButton.d.ts.map +1 -0
  47. package/lib/components/Editor/Toolbar/AnchorButton.js +161 -0
  48. package/lib/components/Editor/Toolbar/AnchorButton.js.map +1 -0
  49. package/lib/components/Editor/Toolbar/ImageButton.d.ts +8 -0
  50. package/lib/components/Editor/Toolbar/ImageButton.d.ts.map +1 -0
  51. package/lib/components/Editor/Toolbar/ImageButton.js +30 -0
  52. package/lib/components/Editor/Toolbar/ImageButton.js.map +1 -0
  53. package/lib/components/Editor/Toolbar/TextSelect.d.ts +14 -0
  54. package/lib/components/Editor/Toolbar/TextSelect.d.ts.map +1 -0
  55. package/lib/components/Editor/Toolbar/TextSelect.js +131 -0
  56. package/lib/components/Editor/Toolbar/TextSelect.js.map +1 -0
  57. package/lib/components/Editor/Toolbar/Toolbar.d.ts +17 -0
  58. package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +1 -0
  59. package/lib/components/Editor/Toolbar/Toolbar.js +164 -0
  60. package/lib/components/Editor/Toolbar/Toolbar.js.map +1 -0
  61. package/lib/components/Editor/Toolbar/Toolbar.test-ids.d.ts +3 -0
  62. package/lib/components/Editor/Toolbar/Toolbar.test-ids.d.ts.map +1 -0
  63. package/lib/components/Editor/Toolbar/Toolbar.test-ids.js +16 -0
  64. package/lib/components/Editor/Toolbar/Toolbar.test-ids.js.map +1 -0
  65. package/lib/components/Editor/index.d.ts +4 -0
  66. package/lib/components/Editor/index.d.ts.map +1 -0
  67. package/lib/components/Editor/index.js +3 -0
  68. package/lib/components/Editor/index.js.map +1 -0
  69. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts +4 -0
  70. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts.map +1 -0
  71. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js +15 -0
  72. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js.map +1 -0
  73. package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts +4 -0
  74. package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts.map +1 -0
  75. package/lib/components/RichTextEditor/DecoratorComponents/Image.js +7 -0
  76. package/lib/components/RichTextEditor/DecoratorComponents/Image.js.map +1 -0
  77. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts +4 -0
  78. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts.map +1 -0
  79. package/lib/components/RichTextEditor/DecoratorComponents/Link.js +8 -0
  80. package/lib/components/RichTextEditor/DecoratorComponents/Link.js.map +1 -0
  81. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +6 -0
  82. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +1 -0
  83. package/lib/components/RichTextEditor/DecoratorComponents/Table.js +24 -0
  84. package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +1 -0
  85. package/lib/components/RichTextEditor/RichTextEditor.context.d.ts +15 -0
  86. package/lib/components/RichTextEditor/RichTextEditor.context.d.ts.map +1 -0
  87. package/lib/components/RichTextEditor/RichTextEditor.context.js +11 -0
  88. package/lib/components/RichTextEditor/RichTextEditor.context.js.map +1 -0
  89. package/lib/components/RichTextEditor/RichTextEditor.d.ts +6 -0
  90. package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +1 -0
  91. package/lib/components/RichTextEditor/RichTextEditor.js +346 -0
  92. package/lib/components/RichTextEditor/RichTextEditor.js.map +1 -0
  93. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +10 -0
  94. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +1 -0
  95. package/lib/components/RichTextEditor/RichTextEditor.styles.js +73 -0
  96. package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -0
  97. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +72 -0
  98. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +1 -0
  99. package/lib/components/RichTextEditor/RichTextEditor.types.js +2 -0
  100. package/lib/components/RichTextEditor/RichTextEditor.types.js.map +1 -0
  101. package/lib/components/RichTextEditor/RichTextTreeRenderer.d.ts +9 -0
  102. package/lib/components/RichTextEditor/RichTextTreeRenderer.d.ts.map +1 -0
  103. package/lib/components/RichTextEditor/RichTextTreeRenderer.js +15 -0
  104. package/lib/components/RichTextEditor/RichTextTreeRenderer.js.map +1 -0
  105. package/lib/components/RichTextEditor/RichTextViewer.d.ts +7 -0
  106. package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +1 -0
  107. package/lib/components/RichTextEditor/RichTextViewer.js +38 -0
  108. package/lib/components/RichTextEditor/RichTextViewer.js.map +1 -0
  109. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +33 -0
  110. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +1 -0
  111. package/lib/components/RichTextEditor/RichTextViewer.types.js +2 -0
  112. package/lib/components/RichTextEditor/RichTextViewer.types.js.map +1 -0
  113. package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts +8 -0
  114. package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts.map +1 -0
  115. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js +156 -0
  116. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js.map +1 -0
  117. package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts +5 -0
  118. package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts.map +1 -0
  119. package/lib/components/RichTextEditor/Toolbar/ImageButton.js +30 -0
  120. package/lib/components/RichTextEditor/Toolbar/ImageButton.js.map +1 -0
  121. package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts +8 -0
  122. package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts.map +1 -0
  123. package/lib/components/RichTextEditor/Toolbar/IndentButton.js +31 -0
  124. package/lib/components/RichTextEditor/Toolbar/IndentButton.js.map +1 -0
  125. package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts +5 -0
  126. package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts.map +1 -0
  127. package/lib/components/RichTextEditor/Toolbar/TableButton.js +20 -0
  128. package/lib/components/RichTextEditor/Toolbar/TableButton.js.map +1 -0
  129. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts +6 -0
  130. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts.map +1 -0
  131. package/lib/components/RichTextEditor/Toolbar/TextSelect.js +119 -0
  132. package/lib/components/RichTextEditor/Toolbar/TextSelect.js.map +1 -0
  133. package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts +10 -0
  134. package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts.map +1 -0
  135. package/lib/components/RichTextEditor/Toolbar/Toolbar.js +155 -0
  136. package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +1 -0
  137. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts +9 -0
  138. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts.map +1 -0
  139. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js +2 -0
  140. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js.map +1 -0
  141. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts +14 -0
  142. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts.map +1 -0
  143. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +67 -0
  144. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +1 -0
  145. package/lib/components/RichTextEditor/Toolbar/utils.d.ts +7 -0
  146. package/lib/components/RichTextEditor/Toolbar/utils.d.ts.map +1 -0
  147. package/lib/components/RichTextEditor/Toolbar/utils.js +13 -0
  148. package/lib/components/RichTextEditor/Toolbar/utils.js.map +1 -0
  149. package/lib/components/RichTextEditor/index.d.ts +9 -0
  150. package/lib/components/RichTextEditor/index.d.ts.map +1 -0
  151. package/lib/components/RichTextEditor/index.js +6 -0
  152. package/lib/components/RichTextEditor/index.js.map +1 -0
  153. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts +34 -0
  154. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +1 -0
  155. package/lib/components/RichTextEditor/utils/EditorCommands.js +447 -0
  156. package/lib/components/RichTextEditor/utils/EditorCommands.js.map +1 -0
  157. package/lib/components/RichTextEditor/utils/ListCommands.d.ts +10 -0
  158. package/lib/components/RichTextEditor/utils/ListCommands.d.ts.map +1 -0
  159. package/lib/components/RichTextEditor/utils/ListCommands.js +346 -0
  160. package/lib/components/RichTextEditor/utils/ListCommands.js.map +1 -0
  161. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts +29 -0
  162. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +1 -0
  163. package/lib/components/RichTextEditor/utils/htmlConverter.js +156 -0
  164. package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -0
  165. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts +6 -0
  166. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +1 -0
  167. package/lib/components/RichTextEditor/utils/interactionRenderer.js +132 -0
  168. package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +1 -0
  169. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts +6 -0
  170. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +1 -0
  171. package/lib/components/RichTextEditor/utils/markdownConverter.js +130 -0
  172. package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -0
  173. package/lib/components/RichTextEditor/utils/renderers.d.ts +22 -0
  174. package/lib/components/RichTextEditor/utils/renderers.d.ts.map +1 -0
  175. package/lib/components/RichTextEditor/utils/renderers.js +163 -0
  176. package/lib/components/RichTextEditor/utils/renderers.js.map +1 -0
  177. package/lib/components/RichTextEditor/utils/search.d.ts +11 -0
  178. package/lib/components/RichTextEditor/utils/search.d.ts.map +1 -0
  179. package/lib/components/RichTextEditor/utils/search.js +37 -0
  180. package/lib/components/RichTextEditor/utils/search.js.map +1 -0
  181. package/lib/components/RichTextEditor/utils/slateConverter.d.ts +25 -0
  182. package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +1 -0
  183. package/lib/components/RichTextEditor/utils/slateConverter.js +88 -0
  184. package/lib/components/RichTextEditor/utils/slateConverter.js.map +1 -0
  185. package/lib/components/RichTextEditor/utils/utils.types.d.ts +3 -0
  186. package/lib/components/RichTextEditor/utils/utils.types.d.ts.map +1 -0
  187. package/lib/components/RichTextEditor/utils/utils.types.js +3 -0
  188. package/lib/components/RichTextEditor/utils/utils.types.js.map +1 -0
  189. package/lib/index.d.ts +5 -0
  190. package/lib/index.d.ts.map +1 -0
  191. package/lib/index.js +6 -0
  192. package/lib/index.js.map +1 -0
  193. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextTreeRenderer.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextTreeRenderer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGrC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAI/D,MAAM,OAAO,GAAG,CAAC,IAAgB,EAAE,KAAa,EAAE,EAAE;IAClD,IAAI,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE;QAC7B,MAAM,QAAQ,GAAkB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3F,OAAO,KAAC,QAAQ,cAAc,YAAY,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,IAA3C,KAAK,CAAkD,CAAC;KAC/E;IACD,OAAO,KAAC,QAAQ,cAAc,YAAY,CAAC,IAAI,CAAC,IAA1B,KAAK,CAAiC,CAAC;AAC/D,CAAC,CAAC;AAMF,MAAM,CAAC,MAAM,oBAAoB,GAAkC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC/E,OAAO,4BAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAI,CAAC;AACzD,CAAC,CAAC","sourcesContent":["import { FC, Fragment } from 'react';\nimport { CosmosCustom } from 'slate';\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { nodeRenderer, leafRenderer } from './utils/renderers';\n\ntype CosmosNode = CosmosCustom.Element | CosmosCustom.Text;\n\nconst getNode = (node: CosmosNode, index: number) => {\n if (hasProp(node, 'children')) {\n const children: JSX.Element[] = node.children.map((childNode, i) => getNode(childNode, i));\n return <Fragment key={index}>{nodeRenderer({ ...node, children })}</Fragment>;\n }\n return <Fragment key={index}>{leafRenderer(node)}</Fragment>;\n};\n\nexport interface RichTextTreeRendererProps {\n nodes: CosmosNode[];\n}\n\nexport const RichTextTreeRenderer: FC<RichTextTreeRendererProps> = ({ nodes }) => {\n return <>{nodes.map((node, i) => getNode(node, i))}</>;\n};\n"]}
@@ -0,0 +1,7 @@
1
+ import { FC } from 'react';
2
+ import { ForwardProps } from '@pega/cosmos-react-core';
3
+ import { RichTextViewerProps } from './RichTextViewer.types';
4
+ export declare const URL_REGEX: RegExp;
5
+ declare const RichTextViewer: FC<RichTextViewerProps & ForwardProps>;
6
+ export default RichTextViewer;
7
+ //# sourceMappingURL=RichTextViewer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextViewer.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAwC,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAQ,YAAY,EAAuB,MAAM,yBAAyB,CAAC;AAGlF,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAM7D,eAAO,MAAM,SAAS,QACoK,CAAC;AAE3L,QAAA,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,GAAG,YAAY,CA6CzD,CAAC;AAEH,eAAe,cAAc,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useState, useEffect } from 'react';
3
+ import { HTML, ErrorState, useI18n } from '@pega/cosmos-react-core';
4
+ import convertMarkdown from './utils/markdownConverter';
5
+ import { StyledEditorContainer, StyledRichTextViewer } from './RichTextEditor.styles';
6
+ import { convertHtml } from './utils/htmlConverter';
7
+ import { RichTextTreeRenderer } from './RichTextTreeRenderer';
8
+ // Regex to match valid URLs
9
+ export const URL_REGEX = /(?<leadingChar>^|\s)(?<url>(?<protocol>https?:\/\/)?(?<host>[a-z0-9]+(?:[-.][a-z0-9]+)*\.(?<tld>[a-z]{2,5})(?<port>:[0-9]{1,5})?)(?<pathQueryHash>[/a-zA-Z0-9?=&+%@.|#_~:[\]'()-]*)?)/g;
10
+ const RichTextViewer = forwardRef(function RichTextViewer({ content, type, interactionRenderers, markdownMap, onRetry, ...restProps }, ref) {
11
+ const t = useI18n();
12
+ const [nodes, setNodes] = useState([]);
13
+ const [error, setError] = useState(false);
14
+ useEffect(() => {
15
+ if (type === 'markdown') {
16
+ setNodes(convertMarkdown(content, [...(interactionRenderers || []), { regexPattern: URL_REGEX, type: 'builtin-url' }], markdownMap));
17
+ }
18
+ if (type === 'richtext') {
19
+ setNodes(JSON.parse(content));
20
+ }
21
+ if (type === 'html' && interactionRenderers && interactionRenderers.length > 0) {
22
+ try {
23
+ setNodes(convertHtml(content, interactionRenderers));
24
+ setError(false);
25
+ }
26
+ catch {
27
+ setNodes([]);
28
+ setError(true);
29
+ }
30
+ }
31
+ }, [content, type, interactionRenderers]);
32
+ if (type === 'html' && (!interactionRenderers || interactionRenderers.length === 0)) {
33
+ return _jsx(HTML, { ref: ref, content: content });
34
+ }
35
+ return error ? (_jsx(ErrorState, { message: t('rte_invalid_html'), onRetry: onRetry })) : (_jsx(StyledRichTextViewer, { ref: ref, ...restProps, children: _jsx(StyledEditorContainer, { children: _jsx(RichTextTreeRenderer, { nodes: nodes }) }) }));
36
+ });
37
+ export default RichTextViewer;
38
+ //# sourceMappingURL=RichTextViewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextViewer.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAW,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,IAAI,EAAgB,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM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AC,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAE1C,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,oBAAoB,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE;QACnF,OAAO,KAAC,IAAI,IAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAI,CAAC;KAC7C;IAED,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,UAAU,IAAC,OAAO,EAAE,CAAC,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,OAAO,GAAI,CACjE,CAAC,CAAC,CAAC,CACF,KAAC,oBAAoB,IAAC,GAAG,EAAE,GAAG,KAAM,SAAS,YAC3C,KAAC,qBAAqB,cACpB,KAAC,oBAAoB,IAAC,KAAK,EAAE,KAAK,GAAI,GAChB,GACH,CACxB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,cAAc,CAAC","sourcesContent":["import { FC, Ref, forwardRef, useState, useEffect } from 'react';\n\nimport { HTML, ForwardProps, ErrorState, useI18n } from '@pega/cosmos-react-core';\n\nimport convertMarkdown from './utils/markdownConverter';\nimport { RichTextViewerProps } from './RichTextViewer.types';\nimport { StyledEditorContainer, StyledRichTextViewer } from './RichTextEditor.styles';\nimport { convertHtml } from './utils/htmlConverter';\nimport { RichTextTreeRenderer, RichTextTreeRendererProps } from './RichTextTreeRenderer';\n\n// Regex to match valid URLs\nexport const URL_REGEX =\n /(?<leadingChar>^|\\s)(?<url>(?<protocol>https?:\\/\\/)?(?<host>[a-z0-9]+(?:[-.][a-z0-9]+)*\\.(?<tld>[a-z]{2,5})(?<port>:[0-9]{1,5})?)(?<pathQueryHash>[/a-zA-Z0-9?=&+%@.|#_~:[\\]'()-]*)?)/g;\n\nconst RichTextViewer: FC<RichTextViewerProps & ForwardProps> = forwardRef(function RichTextViewer(\n { content, type, interactionRenderers, markdownMap, onRetry, ...restProps }: RichTextViewerProps,\n ref: Ref<HTMLDivElement>\n) {\n const t = useI18n();\n const [nodes, setNodes] = useState<RichTextTreeRendererProps['nodes']>([]);\n const [error, setError] = useState(false);\n\n useEffect(() => {\n if (type === 'markdown') {\n setNodes(\n convertMarkdown(\n content,\n [...(interactionRenderers || []), { regexPattern: URL_REGEX, type: 'builtin-url' }],\n markdownMap\n )\n );\n }\n if (type === 'richtext') {\n setNodes(JSON.parse(content));\n }\n if (type === 'html' && interactionRenderers && interactionRenderers.length > 0) {\n try {\n setNodes(convertHtml(content, interactionRenderers));\n setError(false);\n } catch {\n setNodes([]);\n setError(true);\n }\n }\n }, [content, type, interactionRenderers]);\n\n if (type === 'html' && (!interactionRenderers || interactionRenderers.length === 0)) {\n return <HTML ref={ref} content={content} />;\n }\n\n return error ? (\n <ErrorState message={t('rte_invalid_html')} onRetry={onRetry} />\n ) : (\n <StyledRichTextViewer ref={ref} {...restProps}>\n <StyledEditorContainer>\n <RichTextTreeRenderer nodes={nodes} />\n </StyledEditorContainer>\n </StyledRichTextViewer>\n );\n});\n\nexport default RichTextViewer;\n"]}
@@ -0,0 +1,33 @@
1
+ import { marked } from 'marked';
2
+ import { ComponentType, FC } from 'react';
3
+ import { ErrorStateProps, ExcludeStrict } from '@pega/cosmos-react-core';
4
+ export interface InteractionRenderers {
5
+ type: string;
6
+ regexPattern: RegExp;
7
+ xmlElement?: string;
8
+ component?: ComponentType<any>;
9
+ getSearchAttributes?: (xmlElement: string, searchResult: string) => {
10
+ markdown: string;
11
+ component: ComponentType<any>;
12
+ props: Record<string, any>;
13
+ text: string;
14
+ } | undefined;
15
+ }
16
+ export type TokenMap = {
17
+ [K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]: Extract<marked.Token, {
18
+ type: K;
19
+ }>;
20
+ };
21
+ export type MDMap = {
22
+ [K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]?: (token: TokenMap[K]) => FC<{
23
+ token: TokenMap[K];
24
+ }> | undefined;
25
+ };
26
+ export interface RichTextViewerProps {
27
+ content: string;
28
+ type: 'markdown' | 'html' | 'richtext';
29
+ interactionRenderers?: InteractionRenderers[];
30
+ markdownMap?: MDMap;
31
+ onRetry?: ErrorStateProps['onRetry'];
32
+ }
33
+ //# sourceMappingURL=RichTextViewer.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextViewer.types.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEzE,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,CACpB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,KAElB;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC7F,SAAS,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,GAAG;KACpB,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC;CAClG,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;KACjB,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAC9D,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KACf,EAAE,CAAC;QAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC,GAAG,SAAS;CAC5C,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;IACvC,oBAAoB,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAC9C,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;CACtC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RichTextViewer.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextViewer.types.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"","sourcesContent":["import { marked } from 'marked';\nimport { ComponentType, FC } from 'react';\n\nimport { ErrorStateProps, ExcludeStrict } from '@pega/cosmos-react-core';\n\nexport interface InteractionRenderers {\n type: string;\n regexPattern: RegExp;\n xmlElement?: string;\n component?: ComponentType<any>;\n getSearchAttributes?: (\n xmlElement: string,\n searchResult: string\n ) =>\n | { markdown: string; component: ComponentType<any>; props: Record<string, any>; text: string }\n | undefined;\n}\n\nexport type TokenMap = {\n [K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]: Extract<marked.Token, { type: K }>;\n};\n\nexport type MDMap = {\n [K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]?: (\n token: TokenMap[K]\n ) => FC<{ token: TokenMap[K] }> | undefined;\n};\n\nexport interface RichTextViewerProps {\n content: string;\n type: 'markdown' | 'html' | 'richtext';\n interactionRenderers?: InteractionRenderers[];\n markdownMap?: MDMap;\n onRetry?: ErrorStateProps['onRetry'];\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ import { ForwardProps } from '@pega/cosmos-react-core';
3
+ interface AnchorButtonProps {
4
+ osx: boolean;
5
+ }
6
+ declare const AnchorButton: FC<AnchorButtonProps & ForwardProps>;
7
+ export default AnchorButton;
8
+ //# sourceMappingURL=AnchorButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnchorButton.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/AnchorButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EAQH,MAAM,OAAO,CAAC;AAIf,OAAO,EAUL,YAAY,EAGb,MAAM,yBAAyB,CAAC;AAWjC,UAAU,iBAAiB;IACzB,GAAG,EAAE,OAAO,CAAC;CACd;AAED,QAAA,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,GAAG,YAAY,CAyNtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,156 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useRef, useState, useEffect } from 'react';
3
+ import { Text, Editor, Transforms } from 'slate';
4
+ import { ReactEditor, useSlate } from 'slate-react';
5
+ import { Button, CardContent, Grid, Icon, registerIcon, Input, Popover, useOuterEvent, useElement, Form, useI18n } from '@pega/cosmos-react-core';
6
+ import * as chainIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/chain.icon';
7
+ import { useRTEContext } from '../RichTextEditor.context';
8
+ import EditorCommands from '../utils/EditorCommands';
9
+ import ToolbarButton from './ToolbarButton';
10
+ import { getKeyCommand } from './utils';
11
+ registerIcon(chainIcon);
12
+ const AnchorButton = ({ osx, ...props }) => {
13
+ const t = useI18n();
14
+ const { setPopoverOpen, onEditorFocus } = useRTEContext();
15
+ const buttonRef = useRef(null);
16
+ const textInputRef = useRef(null);
17
+ const urlInputRef = useRef(null);
18
+ const editor = useSlate();
19
+ const [popoverEl, setPopoverEl] = useElement();
20
+ const [selectedText, setSelectedText] = useState('');
21
+ const [selection, setSelection] = useState(null);
22
+ const [url, setUrl] = useState('');
23
+ const [urlMatch, setUrlMatch] = useState(true);
24
+ const [anchorMenu, setAnchorMenu] = useState(false);
25
+ const tooltip = getKeyCommand(osx, ({ ctrl }) => `${t('rte_link')} (${ctrl}K)`);
26
+ const openMenu = (opts = {}) => {
27
+ setAnchorMenu(true);
28
+ setPopoverOpen(true);
29
+ if (opts.focusInput) {
30
+ setTimeout(() => {
31
+ textInputRef.current?.focus();
32
+ }, 0);
33
+ }
34
+ };
35
+ const resetMenu = (opts = { focusEditor: true }) => {
36
+ setSelection(null);
37
+ setSelectedText('');
38
+ setUrl('');
39
+ setUrlMatch(true);
40
+ setAnchorMenu(false);
41
+ setPopoverOpen(false);
42
+ if (opts.focusEditor) {
43
+ setTimeout(() => {
44
+ onEditorFocus({
45
+ runAfterFocus: () => {
46
+ if (selection)
47
+ Transforms.setSelection(editor, selection);
48
+ }
49
+ });
50
+ }, 0);
51
+ }
52
+ };
53
+ useOuterEvent('mousedown', [popoverEl], () => {
54
+ if (anchorMenu) {
55
+ resetMenu();
56
+ }
57
+ });
58
+ const createLink = () => {
59
+ if (url) {
60
+ EditorCommands.createLink(editor, selectedText, new URL(/^[a-z][a-z0-9.+-]*:/i.test(url) ? url : `http:${url}`).href, selection);
61
+ resetMenu();
62
+ }
63
+ };
64
+ useEffect(() => {
65
+ if (editor.selection) {
66
+ setSelectedText(Editor.string(editor, editor.selection));
67
+ setSelection(editor.selection);
68
+ const [match] = Editor.nodes(editor, {
69
+ match: n => Text.isText(n) && !!n.href,
70
+ at: editor.selection
71
+ });
72
+ if (match) {
73
+ setUrl(match[0].href || '');
74
+ setSelectedText(match[0].text);
75
+ }
76
+ else {
77
+ setUrl('');
78
+ }
79
+ }
80
+ }, [anchorMenu]);
81
+ const preventDef = (e) => {
82
+ e.preventDefault();
83
+ e.stopPropagation();
84
+ };
85
+ const isLinkActive = () => {
86
+ const [link] = Editor.nodes(editor, { match: n => Text.isText(n) && !!n.href });
87
+ return !!link;
88
+ };
89
+ const cancelAnchorCreation = (event) => {
90
+ if ((event?.type === 'keydown' && event?.key === 'Enter') ||
91
+ event?.type === 'mousedown' ||
92
+ !event) {
93
+ event?.preventDefault();
94
+ resetMenu({ focusEditor: false });
95
+ buttonRef.current?.focus();
96
+ }
97
+ };
98
+ useEffect(() => {
99
+ const keyCommandListener = (e) => {
100
+ if (e.key === 'k' && (e.metaKey || e.ctrlKey) && ReactEditor.isFocused(editor)) {
101
+ e.preventDefault();
102
+ openMenu({ focusInput: true });
103
+ }
104
+ if (e.key === 'Escape') {
105
+ cancelAnchorCreation();
106
+ }
107
+ };
108
+ document.addEventListener('keydown', keyCommandListener);
109
+ return () => {
110
+ document.removeEventListener('keydown', keyCommandListener);
111
+ };
112
+ }, []);
113
+ return (_jsxs(_Fragment, { children: [_jsx(ToolbarButton, { ref: buttonRef, onMouseDown: () => {
114
+ openMenu();
115
+ }, onKeyDown: (e) => {
116
+ if (e.key === 'Enter') {
117
+ e.preventDefault();
118
+ openMenu({ focusInput: true });
119
+ }
120
+ }, active: isLinkActive(), tooltip: tooltip, label: t('rte_link'), ...props, children: _jsx(Icon, { name: 'chain' }) }), _jsx(Popover, { show: anchorMenu, target: buttonRef.current, ref: setPopoverEl, placement: 'bottom', children: _jsx(CardContent, { children: _jsx(Form, { actions: _jsxs(_Fragment, { children: [_jsx(Button, { variant: 'secondary', onKeyDown: cancelAnchorCreation, onMouseDown: cancelAnchorCreation, type: 'button', children: "Cancel" }), _jsx(Button, { disabled: !url || !urlMatch, name: 'apply', type: 'submit', variant: 'primary', children: "Apply" })] }), onSubmit: (e) => {
121
+ e.preventDefault();
122
+ createLink();
123
+ }, children: _jsxs(Grid, { container: { rowGap: 2 }, children: [_jsx(Input, { label: 'Text', value: selectedText, onClick: preventDef, onChange: (e) => {
124
+ setSelectedText(e.target.value);
125
+ }, onBlur: () => {
126
+ setTimeout(() => {
127
+ if (document.activeElement !== urlInputRef.current) {
128
+ resetMenu({ focusEditor: false });
129
+ }
130
+ }, 0);
131
+ }, ref: textInputRef }), _jsx(Input, { label: 'URL', value: url, onClick: preventDef, onChange: (e) => {
132
+ const urlInput = e.target.value;
133
+ setUrl(urlInput);
134
+ if (!urlMatch) {
135
+ try {
136
+ // eslint-disable-next-line no-new
137
+ new URL(/^[a-z][a-z0-9+.-]*:/i.test(urlInput) ? urlInput : `http:${urlInput}`);
138
+ setUrlMatch(true);
139
+ }
140
+ catch {
141
+ setUrlMatch(false);
142
+ }
143
+ }
144
+ }, onBlur: () => {
145
+ try {
146
+ // eslint-disable-next-line no-new
147
+ new URL(/^[a-z][a-z0-9+.-]*:/i.test(url) ? url : `http:${url}`);
148
+ setUrlMatch(true);
149
+ }
150
+ catch {
151
+ setUrlMatch(false);
152
+ }
153
+ }, info: !urlMatch ? 'Not a valid URL' : '', status: !urlMatch ? 'error' : undefined, ref: urlInputRef })] }) }) }) })] }));
154
+ };
155
+ export default AnchorButton;
156
+ //# sourceMappingURL=AnchorButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnchorButton.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/AnchorButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,MAAM,EACN,QAAQ,EAER,SAAS,EAIV,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,IAAI,EAAE,MAAM,EAAS,UAAU,EAAE,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,EACL,MAAM,EACN,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,OAAO,EACP,aAAa,EACb,UAAU,EAEV,IAAI,EACJ,OAAO,EACR,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,SAAS,MAAM,8DAA8D,CAAC;AAE1F,OAAO,EAAE,a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B,IACG,GACF,GACK,GACN,IACT,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import {\n FC,\n useRef,\n useState,\n ChangeEvent,\n useEffect,\n MouseEvent,\n KeyboardEvent as ReactKeyboardEvent,\n FormEvent\n} from 'react';\nimport { Text, Editor, Range, Transforms } from 'slate';\nimport { ReactEditor, useSlate } from 'slate-react';\n\nimport {\n Button,\n CardContent,\n Grid,\n Icon,\n registerIcon,\n Input,\n Popover,\n useOuterEvent,\n useElement,\n ForwardProps,\n Form,\n useI18n\n} from '@pega/cosmos-react-core';\nimport * as chainIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/chain.icon';\n\nimport { useRTEContext } from '../RichTextEditor.context';\nimport EditorCommands from '../utils/EditorCommands';\n\nimport ToolbarButton from './ToolbarButton';\nimport { getKeyCommand } from './utils';\n\nregisterIcon(chainIcon);\n\ninterface AnchorButtonProps {\n osx: boolean;\n}\n\nconst AnchorButton: FC<AnchorButtonProps & ForwardProps> = ({ osx, ...props }) => {\n const t = useI18n();\n const { setPopoverOpen, onEditorFocus } = useRTEContext();\n const buttonRef = useRef<HTMLButtonElement>(null);\n const textInputRef = useRef<HTMLInputElement>(null);\n const urlInputRef = useRef<HTMLInputElement>(null);\n const editor = useSlate();\n const [popoverEl, setPopoverEl] = useElement();\n const [selectedText, setSelectedText] = useState('');\n const [selection, setSelection] = useState<Range | null>(null);\n const [url, setUrl] = useState('');\n const [urlMatch, setUrlMatch] = useState(true);\n const [anchorMenu, setAnchorMenu] = useState(false);\n const tooltip = getKeyCommand(osx, ({ ctrl }) => `${t('rte_link')} (${ctrl}K)`);\n\n const openMenu = (opts: { focusInput?: boolean } = {}) => {\n setAnchorMenu(true);\n setPopoverOpen(true);\n if (opts.focusInput) {\n setTimeout(() => {\n textInputRef.current?.focus();\n }, 0);\n }\n };\n\n const resetMenu = (opts: { focusEditor?: boolean } = { focusEditor: true }) => {\n setSelection(null);\n setSelectedText('');\n setUrl('');\n setUrlMatch(true);\n setAnchorMenu(false);\n setPopoverOpen(false);\n if (opts.focusEditor) {\n setTimeout(() => {\n onEditorFocus({\n runAfterFocus: () => {\n if (selection) Transforms.setSelection(editor, selection);\n }\n });\n }, 0);\n }\n };\n\n useOuterEvent('mousedown', [popoverEl], () => {\n if (anchorMenu) {\n resetMenu();\n }\n });\n\n const createLink = () => {\n if (url) {\n EditorCommands.createLink(\n editor,\n selectedText,\n new URL(/^[a-z][a-z0-9.+-]*:/i.test(url) ? url : `http:${url}`).href,\n selection\n );\n resetMenu();\n }\n };\n\n useEffect(() => {\n if (editor.selection) {\n setSelectedText(Editor.string(editor, editor.selection));\n setSelection(editor.selection);\n const [match] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.href,\n at: editor.selection\n });\n if (match) {\n setUrl(match[0].href || '');\n setSelectedText(match[0].text);\n } else {\n setUrl('');\n }\n }\n }, [anchorMenu]);\n\n const preventDef = (e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n };\n\n const isLinkActive = () => {\n const [link] = Editor.nodes<Text>(editor, { match: n => Text.isText(n) && !!n.href });\n return !!link;\n };\n\n const cancelAnchorCreation = (event?: KeyboardEvent | MouseEvent) => {\n if (\n (event?.type === 'keydown' && (event as KeyboardEvent)?.key === 'Enter') ||\n event?.type === 'mousedown' ||\n !event\n ) {\n event?.preventDefault();\n resetMenu({ focusEditor: false });\n buttonRef.current?.focus();\n }\n };\n\n useEffect(() => {\n const keyCommandListener = (e: KeyboardEvent) => {\n if (e.key === 'k' && (e.metaKey || e.ctrlKey) && ReactEditor.isFocused(editor)) {\n e.preventDefault();\n openMenu({ focusInput: true });\n }\n if (e.key === 'Escape') {\n cancelAnchorCreation();\n }\n };\n\n document.addEventListener('keydown', keyCommandListener);\n\n return () => {\n document.removeEventListener('keydown', keyCommandListener);\n };\n }, []);\n\n return (\n <>\n <ToolbarButton\n ref={buttonRef}\n onMouseDown={() => {\n openMenu();\n }}\n onKeyDown={(e: ReactKeyboardEvent) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n openMenu({ focusInput: true });\n }\n }}\n active={isLinkActive()}\n tooltip={tooltip}\n label={t('rte_link')}\n {...props}\n >\n <Icon name='chain' />\n </ToolbarButton>\n <Popover show={anchorMenu} target={buttonRef.current} ref={setPopoverEl} placement='bottom'>\n <CardContent>\n <Form\n actions={\n <>\n <Button\n variant='secondary'\n onKeyDown={cancelAnchorCreation}\n onMouseDown={cancelAnchorCreation}\n type='button'\n >\n Cancel\n </Button>\n <Button disabled={!url || !urlMatch} name='apply' type='submit' variant='primary'>\n Apply\n </Button>\n </>\n }\n onSubmit={(e: FormEvent) => {\n e.preventDefault();\n createLink();\n }}\n >\n <Grid container={{ rowGap: 2 }}>\n <Input\n label='Text'\n value={selectedText}\n onClick={preventDef}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n setSelectedText(e.target.value);\n }}\n onBlur={() => {\n setTimeout(() => {\n if (document.activeElement !== urlInputRef.current) {\n resetMenu({ focusEditor: false });\n }\n }, 0);\n }}\n ref={textInputRef}\n />\n <Input\n label='URL'\n value={url}\n onClick={preventDef}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n const urlInput = e.target.value;\n setUrl(urlInput);\n\n if (!urlMatch) {\n try {\n // eslint-disable-next-line no-new\n new URL(\n /^[a-z][a-z0-9+.-]*:/i.test(urlInput) ? urlInput : `http:${urlInput}`\n );\n setUrlMatch(true);\n } catch {\n setUrlMatch(false);\n }\n }\n }}\n onBlur={() => {\n try {\n // eslint-disable-next-line no-new\n new URL(/^[a-z][a-z0-9+.-]*:/i.test(url) ? url : `http:${url}`);\n setUrlMatch(true);\n } catch {\n setUrlMatch(false);\n }\n }}\n info={!urlMatch ? 'Not a valid URL' : ''}\n status={!urlMatch ? 'error' : undefined}\n ref={urlInputRef}\n />\n </Grid>\n </Form>\n </CardContent>\n </Popover>\n </>\n );\n};\n\nexport default AnchorButton;\n"]}
@@ -0,0 +1,5 @@
1
+ import { FC } from 'react';
2
+ import { ForwardProps } from '@pega/cosmos-react-core';
3
+ declare const ImageButton: FC<ForwardProps>;
4
+ export default ImageButton;
5
+ //# sourceMappingURL=ImageButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageButton.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/ImageButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAU,MAAM,OAAO,CAAC;AAIhD,OAAO,EAAsB,YAAY,EAAW,MAAM,yBAAyB,CAAC;AAapF,QAAA,MAAM,WAAW,EAAE,EAAE,CAAC,YAAY,CAmCjC,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef } from 'react';
3
+ import styled from 'styled-components';
4
+ import { hideVisually } from 'polished';
5
+ import { Icon, registerIcon, useI18n } from '@pega/cosmos-react-core';
6
+ import * as pictureIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/picture.icon';
7
+ import { useRTEContext } from '../RichTextEditor.context';
8
+ import ToolbarButton from './ToolbarButton';
9
+ registerIcon(pictureIcon);
10
+ const StyledImageInput = styled.input `
11
+ ${hideVisually}
12
+ `;
13
+ const ImageButton = ({ ...props }) => {
14
+ const t = useI18n();
15
+ const { addImage } = useRTEContext();
16
+ const fileInputRef = useRef(null);
17
+ const onImageInputChange = (e) => {
18
+ if (e.target.files) {
19
+ addImage(e.target.files[0]);
20
+ if (fileInputRef.current) {
21
+ fileInputRef.current.value = '';
22
+ }
23
+ }
24
+ };
25
+ return (_jsxs(_Fragment, { children: [_jsx(StyledImageInput, { type: 'file', accept: 'image/*', ref: fileInputRef, onChange: onImageInputChange }), _jsx(ToolbarButton, { onClick: () => {
26
+ fileInputRef?.current?.click();
27
+ }, tooltip: t('rte_image'), label: t('rte_image'), ...props, children: _jsx(Icon, { name: 'picture' }) })] }));
28
+ };
29
+ export default ImageButton;
30
+ //# sourceMappingURL=ImageButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageButton.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/ImageButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAgB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,KAAK,WAAW,MAAM,gEAAgE,CAAC;AAE9F,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,YAAY,CAAC,WAAW,CAAC,CAAC;AAE1B,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAA;IACjC,YAAY;CACf,CAAC;AAEF,MAAM,WAAW,GAAqB,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IACrD,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,CAAC;IACrC,MAAM,YAAY,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IAEpD,MAAM,kBAAkB,GAAG,CAAC,CAAgC,EAAE,EAAE;QAC9D,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE;YAClB,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAE5B,IAAI,YAAY,CAAC,OAAO,EAAE;gBACxB,YAAY,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC;aACjC;SACF;IACH,CAAC,CAAC;IAEF,OAAO,CACL,8BACE,KAAC,gBAAgB,IACf,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,SAAS,EAChB,GAAG,EAAE,YAAY,EACjB,QAAQ,EAAE,kBAAkB,GAC5B,EACF,KAAC,aAAa,IACZ,OAAO,EAAE,GAAG,EAAE;oBACZ,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;gBACjC,CAAC,EACD,OAAO,EAAE,CAAC,CAAC,WAAW,CAAC,EACvB,KAAK,EAAE,CAAC,CAAC,WAAW,CAAC,KACjB,KAAK,YAET,KAAC,IAAI,IAAC,IAAI,EAAC,SAAS,GAAG,GACT,IACf,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import { ChangeEvent, FC, useRef } from 'react';\nimport styled from 'styled-components';\nimport { hideVisually } from 'polished';\n\nimport { Icon, registerIcon, ForwardProps, useI18n } from '@pega/cosmos-react-core';\nimport * as pictureIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/picture.icon';\n\nimport { useRTEContext } from '../RichTextEditor.context';\n\nimport ToolbarButton from './ToolbarButton';\n\nregisterIcon(pictureIcon);\n\nconst StyledImageInput = styled.input`\n ${hideVisually}\n`;\n\nconst ImageButton: FC<ForwardProps> = ({ ...props }) => {\n const t = useI18n();\n const { addImage } = useRTEContext();\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n const onImageInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files) {\n addImage(e.target.files[0]);\n\n if (fileInputRef.current) {\n fileInputRef.current.value = '';\n }\n }\n };\n\n return (\n <>\n <StyledImageInput\n type='file'\n accept='image/*'\n ref={fileInputRef}\n onChange={onImageInputChange}\n />\n <ToolbarButton\n onClick={() => {\n fileInputRef?.current?.click();\n }}\n tooltip={t('rte_image')}\n label={t('rte_image')}\n {...props}\n >\n <Icon name='picture' />\n </ToolbarButton>\n </>\n );\n};\n\nexport default ImageButton;\n"]}
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ interface IndentButtonProps {
3
+ type: 'indent' | 'unindent';
4
+ osx: boolean;
5
+ }
6
+ declare const IndentButton: FC<IndentButtonProps>;
7
+ export default IndentButton;
8
+ //# sourceMappingURL=IndentButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndentButton.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/IndentButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAc3B,UAAU,iBAAiB;IACzB,IAAI,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC5B,GAAG,EAAE,OAAO,CAAC;CACd;AAID,QAAA,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAwBvC,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ReactEditor, useSlate } from 'slate-react';
3
+ import { Icon, navigatorIsAvailable, registerIcon, useI18n } from '@pega/cosmos-react-core';
4
+ import * as indentIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/indent.icon';
5
+ import * as unindentIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/unindent.icon';
6
+ import EditorCommands from '../utils/EditorCommands';
7
+ import ToolbarButton from './ToolbarButton';
8
+ import { getKeyCommand } from './utils';
9
+ registerIcon(indentIcon, unindentIcon);
10
+ const isMobile = navigatorIsAvailable && navigator.userAgent.includes('Mobile');
11
+ const IndentButton = ({ type, osx }) => {
12
+ const editor = useSlate();
13
+ const t = useI18n();
14
+ const tooltipMobile = type === 'indent' ? `${t('rte_indent')}` : `${t('rte_unindent')}`;
15
+ const tooltipDesktop = getKeyCommand(osx, ({ shift, alt }) => type === 'indent' ? `${t('rte_indent')} (${alt}M)` : `${t('rte_unindent')} (${alt}${shift}M)`);
16
+ const tooltip = isMobile ? tooltipMobile : tooltipDesktop;
17
+ const onMouseDown = e => {
18
+ e.preventDefault();
19
+ if (type === 'indent') {
20
+ EditorCommands.indent(editor);
21
+ }
22
+ else {
23
+ EditorCommands.unindent(editor);
24
+ }
25
+ if (!ReactEditor.isFocused(editor))
26
+ ReactEditor.focus(editor);
27
+ };
28
+ return (_jsx(ToolbarButton, { onMouseDown: onMouseDown, tooltip: tooltip, label: type, children: _jsx(Icon, { name: type }) }));
29
+ };
30
+ export default IndentButton;
31
+ //# sourceMappingURL=IndentButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndentButton.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/IndentButton.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,KAAK,UAAU,MAAM,+DAA+D,CAAC;AAC5F,OAAO,KAAK,YAAY,MAAM,iEAAiE,CAAC;AAEhG,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,OAAO,aAAqC,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,YAAY,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AAOvC,MAAM,QAAQ,GAAG,oBAAoB,IAAI,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAEhF,MAAM,YAAY,GAA0B,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE;IAC5D,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC;IAC1B,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,aAAa,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,EAAE,CAAC;IACxF,MAAM,cAAc,GAAG,aAAa,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAC3D,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,KAAK,GAAG,GAAG,KAAK,IAAI,CAC9F,CAAC;IACF,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,cAAc,CAAC;IAE1D,MAAM,WAAW,GAAsC,CAAC,CAAC,EAAE;QACzD,CAAC,CAAC,cAAc,EAAE,CAAC;QACnB,IAAI,IAAI,KAAK,QAAQ,EAAE;YACrB,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SAC/B;aAAM;YACL,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SACjC;QACD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC;YAAE,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChE,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,aAAa,IAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,YACpE,KAAC,IAAI,IAAC,IAAI,EAAE,IAAI,GAAI,GACN,CACjB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { FC } from 'react';\nimport { ReactEditor, useSlate } from 'slate-react';\n\nimport { Icon, navigatorIsAvailable, registerIcon, useI18n } from '@pega/cosmos-react-core';\nimport * as indentIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/indent.icon';\nimport * as unindentIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/unindent.icon';\n\nimport EditorCommands from '../utils/EditorCommands';\n\nimport ToolbarButton, { ToolBarButtonProps } from './ToolbarButton';\nimport { getKeyCommand } from './utils';\n\nregisterIcon(indentIcon, unindentIcon);\n\ninterface IndentButtonProps {\n type: 'indent' | 'unindent';\n osx: boolean;\n}\n\nconst isMobile = navigatorIsAvailable && navigator.userAgent.includes('Mobile');\n\nconst IndentButton: FC<IndentButtonProps> = ({ type, osx }) => {\n const editor = useSlate();\n const t = useI18n();\n const tooltipMobile = type === 'indent' ? `${t('rte_indent')}` : `${t('rte_unindent')}`;\n const tooltipDesktop = getKeyCommand(osx, ({ shift, alt }) =>\n type === 'indent' ? `${t('rte_indent')} (${alt}M)` : `${t('rte_unindent')} (${alt}${shift}M)`\n );\n const tooltip = isMobile ? tooltipMobile : tooltipDesktop;\n\n const onMouseDown: ToolBarButtonProps['onMouseDown'] = e => {\n e.preventDefault();\n if (type === 'indent') {\n EditorCommands.indent(editor);\n } else {\n EditorCommands.unindent(editor);\n }\n if (!ReactEditor.isFocused(editor)) ReactEditor.focus(editor);\n };\n\n return (\n <ToolbarButton onMouseDown={onMouseDown} tooltip={tooltip} label={type}>\n <Icon name={type} />\n </ToolbarButton>\n );\n};\n\nexport default IndentButton;\n"]}
@@ -0,0 +1,5 @@
1
+ import { FC } from 'react';
2
+ import { ForwardProps } from '@pega/cosmos-react-core';
3
+ declare const TableButton: FC<ForwardProps>;
4
+ export default TableButton;
5
+ //# sourceMappingURL=TableButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableButton.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/TableButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAG3B,OAAO,EAAsB,YAAY,EAAW,MAAM,yBAAyB,CAAC;AASpF,QAAA,MAAM,WAAW,EAAE,EAAE,CAAC,YAAY,CAsBjC,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useSlate } from 'slate-react';
3
+ import { Icon, registerIcon, useI18n } from '@pega/cosmos-react-core';
4
+ import * as tableIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/table.icon';
5
+ import EditorCommands from '../utils/EditorCommands';
6
+ import ToolbarButton from './ToolbarButton';
7
+ registerIcon(tableIcon);
8
+ const TableButton = props => {
9
+ const t = useI18n();
10
+ const editor = useSlate();
11
+ const createNewTable = () => {
12
+ EditorCommands.appendTable(editor);
13
+ };
14
+ return (_jsx(ToolbarButton, { type: 'button', onMouseDown: e => {
15
+ e.preventDefault();
16
+ createNewTable();
17
+ }, tooltip: t('rte_table'), label: t('rte_table'), ...props, children: _jsx(Icon, { name: 'table' }) }));
18
+ };
19
+ export default TableButton;
20
+ //# sourceMappingURL=TableButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableButton.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/TableButton.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAgB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,KAAK,SAAS,MAAM,8DAA8D,CAAC;AAE1F,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,YAAY,CAAC,SAAS,CAAC,CAAC;AAExB,MAAM,WAAW,GAAqB,KAAK,CAAC,EAAE;IAC5C,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC;IAE1B,MAAM,cAAc,GAAG,GAAG,EAAE;QAC1B,cAAc,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,aAAa,IACZ,IAAI,EAAC,QAAQ,EACb,WAAW,EAAE,CAAC,CAAC,EAAE;YACf,CAAC,CAAC,cAAc,EAAE,CAAC;YACnB,cAAc,EAAE,CAAC;QACnB,CAAC,EACD,OAAO,EAAE,CAAC,CAAC,WAAW,CAAC,EACvB,KAAK,EAAE,CAAC,CAAC,WAAW,CAAC,KACjB,KAAK,YAET,KAAC,IAAI,IAAC,IAAI,EAAC,OAAO,GAAG,GACP,CACjB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import { FC } from 'react';\nimport { useSlate } from 'slate-react';\n\nimport { Icon, registerIcon, ForwardProps, useI18n } from '@pega/cosmos-react-core';\nimport * as tableIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/table.icon';\n\nimport EditorCommands from '../utils/EditorCommands';\n\nimport ToolbarButton from './ToolbarButton';\n\nregisterIcon(tableIcon);\n\nconst TableButton: FC<ForwardProps> = props => {\n const t = useI18n();\n const editor = useSlate();\n\n const createNewTable = () => {\n EditorCommands.appendTable(editor);\n };\n\n return (\n <ToolbarButton\n type='button'\n onMouseDown={e => {\n e.preventDefault();\n createNewTable();\n }}\n tooltip={t('rte_table')}\n label={t('rte_table')}\n {...props}\n >\n <Icon name='table' />\n </ToolbarButton>\n );\n};\n\nexport default TableButton;\n"]}
@@ -0,0 +1,6 @@
1
+ import { FC } from 'react';
2
+ declare const TextSelect: FC<{
3
+ osx: boolean;
4
+ }>;
5
+ export default TextSelect;
6
+ //# sourceMappingURL=TextSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextSelect.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/TextSelect.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAwE,MAAM,OAAO,CAAC;AA8EjG,QAAA,MAAM,UAAU,EAAE,EAAE,CAAC;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,CAwGpC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,119 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useRef, useState, useCallback } from 'react';
3
+ import { Transforms } from 'slate';
4
+ import { ReactEditor, useSlate } from 'slate-react';
5
+ import styled, { css } from 'styled-components';
6
+ import { Popover, Icon, registerIcon, useOuterEvent, Menu, Button, defaultThemeProp, useI18n, Tooltip, calculateFontSize } from '@pega/cosmos-react-core';
7
+ import * as arrowMicroDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/arrow-micro-down.icon';
8
+ import EditorCommands from '../utils/EditorCommands';
9
+ import { useRTEContext } from '../RichTextEditor.context';
10
+ import { getKeyCommand } from './utils';
11
+ registerIcon(arrowMicroDownIcon);
12
+ const StyledTextSelect = styled(Button)(({ theme }) => {
13
+ const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);
14
+ return css `
15
+ color: ${theme.base.palette['foreground-color']};
16
+ display: inline-flex;
17
+ align-items: center;
18
+ border-radius: calc(0.25 * ${theme.base['border-radius']});
19
+ height: calc(4 * ${theme.base.spacing});
20
+ padding: calc(0.5 * ${theme.base.spacing});
21
+ font-size: ${fontSizes.xxs};
22
+
23
+ span {
24
+ white-space: nowrap;
25
+ }
26
+
27
+ :focus {
28
+ box-shadow: ${theme.base.shadow.focus};
29
+ }
30
+ `;
31
+ });
32
+ StyledTextSelect.defaultProps = defaultThemeProp;
33
+ const StyledSelectMenu = styled.div `
34
+ min-width: 10rem;
35
+ `;
36
+ const textMapping = {
37
+ paragraph: 'Normal',
38
+ 'heading-1': 'Heading 1',
39
+ 'heading-2': 'Heading 2',
40
+ 'heading-3': 'Heading 3',
41
+ 'heading-4': 'Heading 4',
42
+ '': 'Normal'
43
+ };
44
+ const getTextCommand = (num, osx) => {
45
+ return getKeyCommand(osx, ({ ctrl, alt }) => `${ctrl}${alt}${num}`);
46
+ };
47
+ const getTextFormats = (osx) => {
48
+ return [
49
+ { text: 'Normal', subText: getTextCommand(0, osx), type: 'paragraph' },
50
+ { text: 'Heading 1', subText: getTextCommand(1, osx), type: 'heading-1' },
51
+ { text: 'Heading 2', subText: getTextCommand(2, osx), type: 'heading-2' },
52
+ { text: 'Heading 3', subText: getTextCommand(3, osx), type: 'heading-3' },
53
+ { text: 'Heading 4', subText: getTextCommand(4, osx), type: 'heading-4' }
54
+ ];
55
+ };
56
+ const TextSelect = ({ osx }) => {
57
+ const t = useI18n();
58
+ const { disabled } = useRTEContext();
59
+ const [open, setOpen] = useState(false);
60
+ const selecting = useRef(false);
61
+ const openedByClick = useRef(false);
62
+ const buttonRef = useRef(null);
63
+ const popoverRef = useRef(null);
64
+ const menuRef = useRef(null);
65
+ const editor = useSlate();
66
+ const textFormats = useCallback(() => {
67
+ return getTextFormats(osx);
68
+ }, [osx])();
69
+ useOuterEvent('click', [buttonRef, popoverRef, menuRef], () => {
70
+ setOpen(false);
71
+ });
72
+ const onTextSelect = (type, e) => {
73
+ e.stopPropagation();
74
+ e.preventDefault();
75
+ EditorCommands.setBlock(type, editor);
76
+ if (!openedByClick.current) {
77
+ buttonRef.current?.focus();
78
+ }
79
+ setOpen(false);
80
+ selecting.current = true;
81
+ setTimeout(() => {
82
+ if (!ReactEditor.isFocused(editor) && openedByClick.current) {
83
+ const selection = editor.selection;
84
+ ReactEditor.focus(editor);
85
+ if (selection)
86
+ Transforms.select(editor, selection);
87
+ }
88
+ }, 0);
89
+ };
90
+ return (_jsxs(_Fragment, { children: [_jsxs(StyledTextSelect, { variant: 'simple', type: 'button', disabled: disabled, icon: false, ref: buttonRef, onMouseDown: (e) => {
91
+ e.preventDefault();
92
+ e.stopPropagation();
93
+ setOpen(true);
94
+ openedByClick.current = true;
95
+ }, onKeyDown: (e) => {
96
+ if (e.key === 'Enter' && !selecting.current) {
97
+ e.preventDefault();
98
+ setOpen(true);
99
+ openedByClick.current = false;
100
+ }
101
+ else if (e.key === 'Enter') {
102
+ e.preventDefault();
103
+ selecting.current = false;
104
+ }
105
+ else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
106
+ setOpen(false);
107
+ }
108
+ }, onFocus: (e) => {
109
+ e.preventDefault();
110
+ e.stopPropagation();
111
+ }, onClick: (e) => e.stopPropagation(), "aria-expanded": open, "aria-label": `Text formatting toolbar. ${t('rte_heading_style')}. ${textMapping[EditorCommands.getActiveBlockType(editor)]} selected`, "aria-haspopup": true, children: [_jsx("span", { children: textMapping[EditorCommands.getActiveBlockType(editor)] }), _jsx(Icon, { name: 'arrow-micro-down' })] }), buttonRef.current && (_jsx(Tooltip, { target: buttonRef.current, showDelay: 'none', hideDelay: 'none', children: t('rte_heading_style') })), _jsx(Popover, { show: open, as: StyledSelectMenu, target: buttonRef.current, placement: 'bottom-start', ref: popoverRef, children: _jsx(Menu, { items: textFormats.map(({ text, type, subText }) => ({
112
+ id: type,
113
+ primary: text,
114
+ secondary: [subText],
115
+ selected: type === EditorCommands.getActiveBlockType(editor)
116
+ })), focusControlEl: buttonRef.current || undefined, mode: 'single-select', ref: menuRef, onItemClick: onTextSelect }) })] }));
117
+ };
118
+ export default TextSelect;
119
+ //# sourceMappingURL=TextSelect.js.map