@pega/cosmos-react-rte 9.0.0-build.9.9 → 9.0.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 (191) hide show
  1. package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts +4 -2
  2. package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts.map +1 -1
  3. package/lib/components/DynamicContentEditor/DynamicContentEditor.js +64 -59
  4. package/lib/components/DynamicContentEditor/DynamicContentEditor.js.map +1 -1
  5. package/lib/components/Editor/Editor.context.d.ts +6 -6
  6. package/lib/components/Editor/Editor.context.d.ts.map +1 -1
  7. package/lib/components/Editor/Editor.context.js +1 -1
  8. package/lib/components/Editor/Editor.context.js.map +1 -1
  9. package/lib/components/Editor/Editor.d.ts +1 -10
  10. package/lib/components/Editor/Editor.d.ts.map +1 -1
  11. package/lib/components/Editor/Editor.js +301 -490
  12. package/lib/components/Editor/Editor.js.map +1 -1
  13. package/lib/components/Editor/Editor.styles.d.ts +37 -7
  14. package/lib/components/Editor/Editor.styles.d.ts.map +1 -1
  15. package/lib/components/Editor/Editor.styles.js +60 -30
  16. package/lib/components/Editor/Editor.styles.js.map +1 -1
  17. package/lib/components/Editor/Editor.test-ids.d.ts +2 -1
  18. package/lib/components/Editor/Editor.test-ids.d.ts.map +1 -1
  19. package/lib/components/Editor/Editor.test-ids.js +2 -0
  20. package/lib/components/Editor/Editor.test-ids.js.map +1 -1
  21. package/lib/components/Editor/Editor.types.d.ts +34 -14
  22. package/lib/components/Editor/Editor.types.d.ts.map +1 -1
  23. package/lib/components/Editor/Editor.types.js.map +1 -1
  24. package/lib/components/Editor/IframeTiptapEditor.d.ts +30 -0
  25. package/lib/components/Editor/IframeTiptapEditor.d.ts.map +1 -0
  26. package/lib/components/Editor/IframeTiptapEditor.js +695 -0
  27. package/lib/components/Editor/IframeTiptapEditor.js.map +1 -0
  28. package/lib/components/Editor/ImageActionButtons.d.ts +20 -0
  29. package/lib/components/Editor/ImageActionButtons.d.ts.map +1 -0
  30. package/lib/components/Editor/ImageActionButtons.js +84 -0
  31. package/lib/components/Editor/ImageActionButtons.js.map +1 -0
  32. package/lib/components/Editor/ImageEditDialog.d.ts +17 -0
  33. package/lib/components/Editor/ImageEditDialog.d.ts.map +1 -0
  34. package/lib/components/Editor/ImageEditDialog.js +90 -0
  35. package/lib/components/Editor/ImageEditDialog.js.map +1 -0
  36. package/lib/components/Editor/TableCellMenu.d.ts +35 -0
  37. package/lib/components/Editor/TableCellMenu.d.ts.map +1 -0
  38. package/lib/components/Editor/TableCellMenu.js +120 -0
  39. package/lib/components/Editor/TableCellMenu.js.map +1 -0
  40. package/lib/components/Editor/Toolbar/AIRewriteButton.d.ts +17 -0
  41. package/lib/components/Editor/Toolbar/AIRewriteButton.d.ts.map +1 -0
  42. package/lib/components/Editor/Toolbar/AIRewriteButton.js +79 -0
  43. package/lib/components/Editor/Toolbar/AIRewriteButton.js.map +1 -0
  44. package/lib/components/Editor/Toolbar/AlignmentSelect.d.ts +8 -0
  45. package/lib/components/Editor/Toolbar/AlignmentSelect.d.ts.map +1 -0
  46. package/lib/components/Editor/Toolbar/AlignmentSelect.js +137 -0
  47. package/lib/components/Editor/Toolbar/AlignmentSelect.js.map +1 -0
  48. package/lib/components/Editor/Toolbar/AnchorButton.d.ts +3 -4
  49. package/lib/components/Editor/Toolbar/AnchorButton.d.ts.map +1 -1
  50. package/lib/components/Editor/Toolbar/AnchorButton.js +156 -82
  51. package/lib/components/Editor/Toolbar/AnchorButton.js.map +1 -1
  52. package/lib/components/Editor/Toolbar/ColorPickerButton.d.ts +9 -0
  53. package/lib/components/Editor/Toolbar/ColorPickerButton.d.ts.map +1 -0
  54. package/lib/components/Editor/Toolbar/ColorPickerButton.js +190 -0
  55. package/lib/components/Editor/Toolbar/ColorPickerButton.js.map +1 -0
  56. package/lib/components/Editor/Toolbar/FontFamilySelect.d.ts +8 -0
  57. package/lib/components/Editor/Toolbar/FontFamilySelect.d.ts.map +1 -0
  58. package/lib/components/Editor/Toolbar/FontFamilySelect.js +150 -0
  59. package/lib/components/Editor/Toolbar/FontFamilySelect.js.map +1 -0
  60. package/lib/components/Editor/Toolbar/FontSizeSelect.d.ts +8 -0
  61. package/lib/components/Editor/Toolbar/FontSizeSelect.d.ts.map +1 -0
  62. package/lib/components/Editor/Toolbar/FontSizeSelect.js +145 -0
  63. package/lib/components/Editor/Toolbar/FontSizeSelect.js.map +1 -0
  64. package/lib/components/Editor/Toolbar/ImageButton.d.ts +5 -5
  65. package/lib/components/Editor/Toolbar/ImageButton.d.ts.map +1 -1
  66. package/lib/components/Editor/Toolbar/ImageButton.js +131 -18
  67. package/lib/components/Editor/Toolbar/ImageButton.js.map +1 -1
  68. package/lib/components/Editor/Toolbar/SourceCodeButton.d.ts +8 -0
  69. package/lib/components/Editor/Toolbar/SourceCodeButton.d.ts.map +1 -0
  70. package/lib/components/Editor/Toolbar/SourceCodeButton.js +49 -0
  71. package/lib/components/Editor/Toolbar/SourceCodeButton.js.map +1 -0
  72. package/lib/components/Editor/Toolbar/TableButton.d.ts +8 -0
  73. package/lib/components/Editor/Toolbar/TableButton.d.ts.map +1 -0
  74. package/lib/components/Editor/Toolbar/TableButton.js +291 -0
  75. package/lib/components/Editor/Toolbar/TableButton.js.map +1 -0
  76. package/lib/components/Editor/Toolbar/TextSelect.d.ts +4 -5
  77. package/lib/components/Editor/Toolbar/TextSelect.d.ts.map +1 -1
  78. package/lib/components/Editor/Toolbar/TextSelect.js +61 -30
  79. package/lib/components/Editor/Toolbar/TextSelect.js.map +1 -1
  80. package/lib/components/Editor/Toolbar/Toolbar.d.ts +17 -6
  81. package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +1 -1
  82. package/lib/components/Editor/Toolbar/Toolbar.js +169 -47
  83. package/lib/components/Editor/Toolbar/Toolbar.js.map +1 -1
  84. package/lib/components/Editor/Toolbar/Toolbar.test-ids.d.ts +2 -2
  85. package/lib/components/Editor/Toolbar/Toolbar.test-ids.d.ts.map +1 -1
  86. package/lib/components/Editor/Toolbar/Toolbar.test-ids.js +17 -1
  87. package/lib/components/Editor/Toolbar/Toolbar.test-ids.js.map +1 -1
  88. package/lib/components/Editor/Toolbar/WordCount.d.ts +8 -0
  89. package/lib/components/Editor/Toolbar/WordCount.d.ts.map +1 -0
  90. package/lib/components/Editor/Toolbar/WordCount.js +31 -0
  91. package/lib/components/Editor/Toolbar/WordCount.js.map +1 -0
  92. package/lib/components/Editor/extensions/FontSize.d.ts +21 -0
  93. package/lib/components/Editor/extensions/FontSize.d.ts.map +1 -0
  94. package/lib/components/Editor/extensions/FontSize.js +42 -0
  95. package/lib/components/Editor/extensions/FontSize.js.map +1 -0
  96. package/lib/components/Editor/extensions/PreserveDiv.d.ts +13 -0
  97. package/lib/components/Editor/extensions/PreserveDiv.d.ts.map +1 -0
  98. package/lib/components/Editor/extensions/PreserveDiv.js +73 -0
  99. package/lib/components/Editor/extensions/PreserveDiv.js.map +1 -0
  100. package/lib/components/Editor/extensions/TableCellSelection.d.ts +4 -0
  101. package/lib/components/Editor/extensions/TableCellSelection.d.ts.map +1 -0
  102. package/lib/components/Editor/extensions/TableCellSelection.js +53 -0
  103. package/lib/components/Editor/extensions/TableCellSelection.js.map +1 -0
  104. package/lib/components/Editor/extensions/TextIndent.d.ts +22 -0
  105. package/lib/components/Editor/extensions/TextIndent.d.ts.map +1 -0
  106. package/lib/components/Editor/extensions/TextIndent.js +137 -0
  107. package/lib/components/Editor/extensions/TextIndent.js.map +1 -0
  108. package/lib/components/Editor/hooks/useCloseOnEditorClick.d.ts +5 -0
  109. package/lib/components/Editor/hooks/useCloseOnEditorClick.d.ts.map +1 -0
  110. package/lib/components/Editor/hooks/useCloseOnEditorClick.js +18 -0
  111. package/lib/components/Editor/hooks/useCloseOnEditorClick.js.map +1 -0
  112. package/lib/components/Editor/hooks/useEscapeKey.d.ts +4 -0
  113. package/lib/components/Editor/hooks/useEscapeKey.d.ts.map +1 -0
  114. package/lib/components/Editor/hooks/useEscapeKey.js +24 -0
  115. package/lib/components/Editor/hooks/useEscapeKey.js.map +1 -0
  116. package/lib/components/Editor/hooks/useIframeSetup.d.ts +54 -0
  117. package/lib/components/Editor/hooks/useIframeSetup.d.ts.map +1 -0
  118. package/lib/components/Editor/hooks/useIframeSetup.js +284 -0
  119. package/lib/components/Editor/hooks/useIframeSetup.js.map +1 -0
  120. package/lib/components/Editor/hooks/useImageActions.d.ts +19 -0
  121. package/lib/components/Editor/hooks/useImageActions.d.ts.map +1 -0
  122. package/lib/components/Editor/hooks/useImageActions.js +198 -0
  123. package/lib/components/Editor/hooks/useImageActions.js.map +1 -0
  124. package/lib/components/Editor/hooks/useTableCellMenu.d.ts +22 -0
  125. package/lib/components/Editor/hooks/useTableCellMenu.d.ts.map +1 -0
  126. package/lib/components/Editor/hooks/useTableCellMenu.js +120 -0
  127. package/lib/components/Editor/hooks/useTableCellMenu.js.map +1 -0
  128. package/lib/components/Editor/iframeContentStyles.d.ts +10 -0
  129. package/lib/components/Editor/iframeContentStyles.d.ts.map +1 -0
  130. package/lib/components/Editor/iframeContentStyles.js +162 -0
  131. package/lib/components/Editor/iframeContentStyles.js.map +1 -0
  132. package/lib/components/Editor/index.d.ts +2 -0
  133. package/lib/components/Editor/index.d.ts.map +1 -1
  134. package/lib/components/Editor/index.js +1 -0
  135. package/lib/components/Editor/index.js.map +1 -1
  136. package/lib/components/Editor/sanitize.d.ts +3 -0
  137. package/lib/components/Editor/sanitize.d.ts.map +1 -0
  138. package/lib/components/Editor/sanitize.js +11 -0
  139. package/lib/components/Editor/sanitize.js.map +1 -0
  140. package/lib/components/Editor/utils/htmlPlaceholder.d.ts +69 -0
  141. package/lib/components/Editor/utils/htmlPlaceholder.d.ts.map +1 -0
  142. package/lib/components/Editor/utils/htmlPlaceholder.js +154 -0
  143. package/lib/components/Editor/utils/htmlPlaceholder.js.map +1 -0
  144. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +6 -4
  145. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +1 -1
  146. package/lib/components/RichTextEditor/DecoratorComponents/Table.js +10 -8
  147. package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +1 -1
  148. package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +1 -1
  149. package/lib/components/RichTextEditor/RichTextEditor.js +15 -2
  150. package/lib/components/RichTextEditor/RichTextEditor.js.map +1 -1
  151. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +5 -5
  152. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +1 -1
  153. package/lib/components/RichTextEditor/RichTextEditor.styles.js +3 -5
  154. package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -1
  155. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +5 -0
  156. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +1 -1
  157. package/lib/components/RichTextEditor/RichTextEditor.types.js.map +1 -1
  158. package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +1 -1
  159. package/lib/components/RichTextEditor/RichTextViewer.js +9 -2
  160. package/lib/components/RichTextEditor/RichTextViewer.js.map +1 -1
  161. package/lib/components/RichTextEditor/Toolbar/Toolbar.js +1 -1
  162. package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +1 -1
  163. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts +4 -4
  164. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts.map +1 -1
  165. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js.map +1 -1
  166. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts.map +1 -1
  167. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +41 -26
  168. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +1 -1
  169. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts +2 -0
  170. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +1 -1
  171. package/lib/components/RichTextEditor/utils/htmlConverter.js +12 -0
  172. package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -1
  173. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +1 -1
  174. package/lib/components/RichTextEditor/utils/interactionRenderer.js +20 -19
  175. package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +1 -1
  176. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +1 -1
  177. package/lib/components/RichTextEditor/utils/markdownConverter.js +131 -30
  178. package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -1
  179. package/lib/components/RichTextEditor/utils/renderers.d.ts +5 -3
  180. package/lib/components/RichTextEditor/utils/renderers.d.ts.map +1 -1
  181. package/lib/components/RichTextEditor/utils/renderers.js +62 -34
  182. package/lib/components/RichTextEditor/utils/renderers.js.map +1 -1
  183. package/lib/components/RichTextEditor/utils/slateConverter.d.ts +4 -3
  184. package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +1 -1
  185. package/lib/components/RichTextEditor/utils/slateConverter.js +86 -38
  186. package/lib/components/RichTextEditor/utils/slateConverter.js.map +1 -1
  187. package/package.json +30 -8
  188. package/lib/components/Editor/ImageEditor.d.ts +0 -10
  189. package/lib/components/Editor/ImageEditor.d.ts.map +0 -1
  190. package/lib/components/Editor/ImageEditor.js +0 -292
  191. package/lib/components/Editor/ImageEditor.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"AnchorButton.js","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/AnchorButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAIrE,OAAO,EACL,MAAM,EACN,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,aAAa,EACb,IAAI,EACJ,OAAO,EACR,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,SAAS,MAAM,8DAA8D,CAAC;AAE1F,OAAO,aAAa,MAAM,4CAA4C,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AAI,CAAC,CAAC;4CACpB,CAAC;4CAAC,MAAM,CAAC;gDACP,WAAW,CAAC,KAAK,CAAC,CAAC;4CACrB,CAAC;wCACH,CAAC;oCACH,CAAC,EACD,MAAM,EAAE,GAAG,EAAE;wCACX,IAAI,CAAC;4CACH,kCAAkC;4CAClC,IAAI,GAAG,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC;4CACjE,WAAW,CAAC,IAAI,CAAC,CAAC;wCACpB,CAAC;wCAAC,MAAM,CAAC;4CACP,WAAW,CAAC,KAAK,CAAC,CAAC;wCACrB,CAAC;oCACH,CAAC,EACD,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,EAC3C,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EACvC,GAAG,EAAE,WAAW,GAChB,IACG,GACF,GACK,GACI,IACnB,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { useRef, useState, useEffect, useLayoutEffect } from 'react';\nimport type { FC, ChangeEvent, MouseEvent, KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport type { Editor, EditorSelection } from 'tinymce';\n\nimport {\n Button,\n CardContent,\n Grid,\n Icon,\n registerIcon,\n Input,\n useOuterEvent,\n Form,\n useI18n\n} from '@pega/cosmos-react-core';\nimport type { ForwardProps } from '@pega/cosmos-react-core';\nimport * as chainIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/chain.icon';\n\nimport ToolbarButton from '../../RichTextEditor/Toolbar/ToolbarButton';\nimport { getKeyCommand } from '../../RichTextEditor/Toolbar/utils';\nimport { StyledEditPopover } from '../Editor.styles';\n\nregisterIcon(chainIcon);\n\ninterface AnchorButtonProps {\n osx: boolean;\n editor: Editor;\n}\n\nconst AnchorButton: FC<AnchorButtonProps & ForwardProps> = ({ osx, editor, ...restProps }) => {\n const t = useI18n();\n const buttonRef = useRef<HTMLButtonElement>(null);\n const textInputRef = useRef<HTMLInputElement>(null);\n const urlInputRef = useRef<HTMLInputElement>(null);\n const popoverRef = useRef(null);\n const [selectedText, setSelectedText] = useState('');\n const [selection, setSelection] = useState<EditorSelection | undefined>();\n const [url, setUrl] = useState('');\n const [urlMatch, setUrlMatch] = useState(false);\n const [anchorMenu, setAnchorMenu] = useState(false);\n const [shouldFocusInput, setShouldFocusInput] = useState(false);\n const tooltip = getKeyCommand(osx, ({ ctrl }) => `${t('rte_link')} (${ctrl}K)`);\n\n const openMenu = (opts: { focusInput?: boolean } = {}) => {\n setAnchorMenu(true);\n if (opts.focusInput) {\n setShouldFocusInput(true);\n }\n };\n\n const resetMenu = () => {\n setSelection(undefined);\n setSelectedText('');\n setUrl('');\n setUrlMatch(true);\n setAnchorMenu(false);\n };\n\n useOuterEvent('mousedown', [popoverRef, buttonRef], () => {\n if (anchorMenu) {\n resetMenu();\n }\n });\n\n const createLink = () => {\n if (url && selection) {\n editor.focus();\n editor.selection = selection;\n if (selection.getNode().tagName === 'A') {\n const anchorEl = editor.selection.getNode();\n anchorEl.setAttribute('href', url);\n anchorEl.setAttribute('data-mce-href', url);\n anchorEl.textContent = selectedText;\n editor.execCommand('mceAddUndoLevel');\n } else {\n editor.insertContent(\n `<a href='${\n new URL(/^[a-z][a-z0-9.+-]*:/i.test(url) ? url : `https:${url}`).href\n }'>${selectedText}</a>`\n );\n }\n resetMenu();\n }\n };\n\n useEffect(() => {\n if (anchorMenu) {\n if (editor.selection) {\n const selectedEl = editor.selection.getNode();\n if (selectedEl?.tagName === 'A') {\n setSelectedText(selectedEl.textContent || '');\n setUrl(selectedEl.getAttribute('href') || '');\n } else {\n setSelectedText(editor.selection.getContent({ format: 'text' }));\n }\n setSelection({ ...editor.selection });\n }\n } else {\n resetMenu();\n }\n }, [anchorMenu]);\n\n const preventDef = (e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n };\n\n const isLinkActive = () => {\n return editor.selection.getNode().tagName === 'A' && editor.hasFocus();\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 anchorMenu\n ) {\n event?.preventDefault();\n resetMenu();\n buttonRef.current?.focus();\n }\n };\n\n useEffect(() => {\n const keyCommandListener = (e: KeyboardEvent) => {\n if (e.key === 'k' && (e.metaKey || e.ctrlKey) && editor.hasFocus()) {\n e.preventDefault();\n openMenu({ focusInput: true });\n }\n if (e.key === 'Escape') {\n cancelAnchorCreation();\n }\n };\n\n editor.getDoc().addEventListener('keydown', keyCommandListener);\n\n return () => {\n editor.getDoc().removeEventListener('keydown', keyCommandListener);\n };\n }, []);\n\n useLayoutEffect(() => {\n if (anchorMenu && shouldFocusInput) {\n textInputRef.current?.focus();\n setShouldFocusInput(false);\n }\n }, [textInputRef.current]);\n\n useEffect(() => {\n // These events must be added here so they run before the native event in useArrows (used in the toolbar).\n const onKeyDown = (e: KeyboardEvent) => {\n e.stopPropagation();\n };\n textInputRef.current?.addEventListener('keydown', onKeyDown);\n urlInputRef.current?.addEventListener('keydown', onKeyDown);\n return () => {\n textInputRef.current?.removeEventListener('keydown', onKeyDown);\n urlInputRef.current?.removeEventListener('keydown', onKeyDown);\n };\n }, [textInputRef.current, urlInputRef.current]);\n\n return (\n <>\n <ToolbarButton\n ref={buttonRef}\n onMouseDown={e => {\n e.preventDefault();\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 {...restProps}\n >\n <Icon name='chain' />\n </ToolbarButton>\n <StyledEditPopover\n show={anchorMenu}\n target={buttonRef.current}\n ref={popoverRef}\n placement='bottom'\n >\n <CardContent>\n <Form\n as='div'\n actions={\n <>\n <Button\n variant='secondary'\n onKeyDown={cancelAnchorCreation}\n onMouseDown={cancelAnchorCreation}\n type='button'\n >\n {t('cancel')}\n </Button>\n <Button\n disabled={!url || !urlMatch}\n name='apply'\n variant='primary'\n onClick={(e: MouseEvent) => {\n e.preventDefault();\n createLink();\n }}\n >\n {t('apply')}\n </Button>\n </>\n }\n >\n <Grid container={{ rowGap: 2 }}>\n <Input\n label={t('rte_link_text')}\n value={selectedText}\n onClick={preventDef}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n setSelectedText(e.target.value);\n }}\n ref={textInputRef}\n />\n <Input\n label={t('rte_link_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 : `https:${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 : `https:${url}`);\n setUrlMatch(true);\n } catch {\n setUrlMatch(false);\n }\n }}\n info={!urlMatch ? t('rte_invalid_url') : ''}\n status={!urlMatch ? 'error' : undefined}\n ref={urlInputRef}\n />\n </Grid>\n </Form>\n </CardContent>\n </StyledEditPopover>\n </>\n );\n};\n\nexport default AnchorButton;\n"]}
1
+ {"version":3,"file":"AnchorButton.js","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/AnchorButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAIlF,OAAO,EACL,MAAM,EACN,WAAW,EACX,IAAI,EACJ,IAAI,EACJ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sourcesContent":["import { useRef, useState, useEffect, useLayoutEffect, useCallback } from 'react';\nimport type { ChangeEvent, MouseEvent, KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport type { Editor as TiptapEditor } from '@tiptap/core';\n\nimport {\n Button,\n CardContent,\n Grid,\n Icon,\n registerIcon,\n Input,\n useOuterEvent,\n Form,\n useI18n,\n Text,\n useElement,\n useEscape,\n isInstance\n} from '@pega/cosmos-react-core';\nimport type { ForwardProps } from '@pega/cosmos-react-core';\nimport * as chainIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/chain.icon';\n\nimport ToolbarButton from '../../RichTextEditor/Toolbar/ToolbarButton';\nimport { getKeyCommand } from '../../RichTextEditor/Toolbar/utils';\nimport { StyledEditPopover } from '../Editor.styles';\nimport useCloseOnEditorClick from '../hooks/useCloseOnEditorClick';\n\nregisterIcon(chainIcon);\n\ninterface AnchorButtonProps {\n osx: boolean;\n editor: TiptapEditor;\n}\n\nconst AnchorButton = ({ osx, editor, ...restProps }: AnchorButtonProps & ForwardProps) => {\n const t = useI18n();\n const buttonRef = useRef<HTMLButtonElement>(null);\n const [textInputEl, setTextInputEl] = useElement<HTMLInputElement>();\n const [urlInputEl, setUrlInputEl] = useElement<HTMLInputElement>();\n const [popoverEl, setPopoverEl] = useElement<HTMLDivElement>();\n const [linkText, setLinkText] = useState('');\n const [url, setUrl] = useState('');\n const [urlMatch, setUrlMatch] = useState(true);\n const [anchorMenu, setAnchorMenu] = useState(false);\n const [shouldFocusInput, setShouldFocusInput] = useState(false);\n // Store the original selection range when menu opens so we can restore it when creating the link\n const originalSelectionRef = useRef<{ from: number; to: number } | null>(null);\n const tooltip = getKeyCommand(osx, ({ ctrl }) => `${t('rte_link')} (${ctrl}K)`);\n\n const openMenu = (opts: { focusInput?: boolean } = {}) => {\n // Save the original selection before opening the menu\n const { from, to } = editor.state.selection;\n originalSelectionRef.current = { from, to };\n setAnchorMenu(true);\n if (opts.focusInput) {\n setShouldFocusInput(true);\n }\n };\n\n const resetMenu = useCallback(() => {\n setLinkText('');\n setUrl('');\n setUrlMatch(true);\n setAnchorMenu(false);\n originalSelectionRef.current = null;\n }, []);\n\n useOuterEvent('mousedown', [popoverEl, buttonRef], () => {\n if (anchorMenu) {\n resetMenu();\n }\n });\n\n // Close menu when clicking inside the editor iframe\n const handleEditorClick = useCallback(() => {\n if (anchorMenu) {\n resetMenu();\n }\n }, [anchorMenu, resetMenu]);\n useCloseOnEditorClick(anchorMenu, handleEditorClick);\n\n const isValidUrl = (urlString: string): boolean => {\n if (!urlString.trim()) return false;\n const allowedProtocols = /^(https?|mailto|tel):/i;\n const hasProtocol = /^[a-z][a-z0-9.+-]*:/i.test(urlString);\n\n try {\n const testUrl = hasProtocol ? urlString : `https://${urlString}`;\n if (hasProtocol && !allowedProtocols.test(urlString)) {\n return false;\n }\n const urlObj = new URL(testUrl);\n return URL.canParse?.(testUrl) ?? Boolean(urlObj.href);\n } catch {\n return false;\n }\n };\n\n const createLink = useCallback(() => {\n if (!url || !isValidUrl(url)) {\n return;\n }\n\n // Only allow safe protocols to prevent XSS (e.g., javascript: URLs)\n const allowedProtocols = /^(https?|mailto|tel):/i;\n const hasProtocol = /^[a-z][a-z0-9.+-]*:/i.test(url);\n\n let normalizedUrl: string;\n if (hasProtocol) {\n // Reject URLs with disallowed protocols\n if (!allowedProtocols.test(url)) {\n return;\n }\n normalizedUrl = url;\n } else {\n normalizedUrl = `https://${url}`;\n }\n\n // Use the original selection to determine if text was selected in the editor\n const originalSelection = originalSelectionRef.current;\n\n if (originalSelection && originalSelection.from !== originalSelection.to) {\n // Text was originally selected - restore selection and apply link\n // Then collapse selection to end and clear stored mark so subsequent typing isn't linked\n editor\n .chain()\n .focus()\n .setTextSelection({ from: originalSelection.from, to: originalSelection.to })\n .setLink({ href: normalizedUrl })\n .setTextSelection(originalSelection.to)\n .unsetMark('link')\n .run();\n } else if (linkText) {\n // No text was originally selected, insert new link with the text entered in modal\n editor\n .chain()\n .focus()\n .insertContent({\n type: 'text',\n text: linkText,\n marks: [{ type: 'link', attrs: { href: normalizedUrl } }]\n })\n .unsetMark('link')\n .insertContent(' ')\n .run();\n }\n resetMenu();\n }, [url, linkText, editor, resetMenu]);\n\n useEffect(() => {\n if (anchorMenu && originalSelectionRef.current) {\n // Use the stored original selection to populate the modal\n // This avoids issues where focus shift may collapse the editor selection\n const { from, to } = originalSelectionRef.current;\n const text = editor.state.doc.textBetween(from, to);\n const linkMark = editor.getAttributes('link');\n\n if (linkMark.href) {\n setUrl(linkMark.href);\n setLinkText(text || '');\n } else {\n setLinkText(text || '');\n }\n } else if (!anchorMenu) {\n resetMenu();\n }\n }, [anchorMenu, editor, resetMenu]);\n\n const preventDef = (e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n };\n\n const isLinkActive = () => {\n return editor.isActive('link') && editor.isFocused;\n };\n\n const cancelAnchorCreation = useCallback(\n (event?: KeyboardEvent | MouseEvent) => {\n if (\n ((event && 'key' in event && event.key === 'Escape') ||\n event?.type === 'click' ||\n !event) &&\n anchorMenu\n ) {\n if (event && 'key' in event && event.key === 'Escape') {\n event.stopPropagation();\n }\n\n resetMenu();\n buttonRef.current?.focus();\n }\n },\n [anchorMenu, resetMenu]\n );\n\n // Ctrl+K shortcut to open link dialog from within the editor iframe\n useEffect(() => {\n const handleCtrlK = (e: KeyboardEvent) => {\n if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {\n e.preventDefault();\n openMenu({ focusInput: true });\n }\n };\n\n const iframeWindow = editor.view.dom.ownerDocument.defaultView;\n iframeWindow?.addEventListener('keydown', handleCtrlK);\n return () => iframeWindow?.removeEventListener('keydown', handleCtrlK);\n }, [editor]);\n\n // Escape to close popover - listen on both iframe and parent document\n // since focus may be in either location depending on how the popover was opened\n useEffect(() => {\n const handleEscape = (e: KeyboardEvent) => {\n if (e.key === 'Escape' && anchorMenu) {\n e.preventDefault();\n cancelAnchorCreation();\n }\n };\n const iframeWindow = editor.view.dom.ownerDocument.defaultView;\n iframeWindow?.addEventListener('keydown', handleEscape);\n document.addEventListener('keydown', handleEscape);\n return () => {\n iframeWindow?.removeEventListener('keydown', handleEscape);\n document.removeEventListener('keydown', handleEscape);\n };\n }, [editor, anchorMenu, cancelAnchorCreation]);\n\n useEscape(cancelAnchorCreation, popoverEl);\n\n useLayoutEffect(() => {\n if (textInputEl && shouldFocusInput) {\n textInputEl.focus();\n setShouldFocusInput(false);\n }\n }, [textInputEl, shouldFocusInput]);\n\n useEffect(() => {\n // These events must be added here so they run before the native event in useArrows (used in the toolbar).\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key !== 'Escape') {\n e.stopPropagation();\n }\n };\n textInputEl?.addEventListener('keydown', onKeyDown);\n urlInputEl?.addEventListener('keydown', onKeyDown);\n return () => {\n textInputEl?.removeEventListener('keydown', onKeyDown);\n urlInputEl?.removeEventListener('keydown', onKeyDown);\n };\n }, [textInputEl, urlInputEl]);\n\n return (\n <>\n <ToolbarButton\n ref={buttonRef}\n onMouseDown={e => {\n e.preventDefault();\n openMenu();\n }}\n onKeyDown={(e: ReactKeyboardEvent) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n openMenu({ focusInput: true });\n }\n }}\n onBlur={(e: React.FocusEvent) => {\n const { relatedTarget } = e;\n if (\n isInstance(relatedTarget, Node) &&\n !buttonRef.current?.contains(relatedTarget) &&\n !popoverEl?.contains(relatedTarget)\n ) {\n resetMenu();\n }\n }}\n active={isLinkActive()}\n tooltip={tooltip}\n label={t('rte_link')}\n {...restProps}\n >\n <Icon name='chain' />\n </ToolbarButton>\n <StyledEditPopover\n show={anchorMenu}\n target={buttonRef.current}\n ref={setPopoverEl}\n placement='bottom'\n >\n <CardContent>\n <Form\n as='div'\n actions={\n <>\n <Button variant='secondary' onClick={cancelAnchorCreation} type='button'>\n {t('cancel')}\n </Button>\n <Button\n variant='primary'\n disabled={!url || !urlMatch}\n onClick={(e: MouseEvent) => {\n e.preventDefault();\n createLink();\n }}\n >\n {t('apply')}\n </Button>\n </>\n }\n >\n <Grid container={{ rowGap: 2 }}>\n <Text variant='h2'>{t('rte_add_link')}</Text>\n <Input\n label={t('rte_link_text')}\n value={linkText}\n onClick={preventDef}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n setLinkText(e.target.value);\n }}\n ref={setTextInputEl}\n />\n <Input\n label={t('rte_link_url')}\n value={url}\n onClick={preventDef}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n const urlInput = e.target.value;\n setUrl(urlInput);\n // Clear error while typing, validate on blur\n if (!urlMatch) {\n setUrlMatch(true);\n }\n }}\n onBlur={() => {\n setUrlMatch(!url || isValidUrl(url));\n }}\n info={url && !urlMatch ? t('rte_invalid_url') : ''}\n status={url && !urlMatch ? 'error' : undefined}\n ref={setUrlInputEl}\n />\n </Grid>\n </Form>\n </CardContent>\n </StyledEditPopover>\n </>\n );\n};\n\nexport default AnchorButton;\n"]}
@@ -0,0 +1,9 @@
1
+ import type { Editor as TiptapEditor } from '@tiptap/core';
2
+ interface ColorPickerButtonProps {
3
+ editor: TiptapEditor;
4
+ type: 'text' | 'highlight';
5
+ 'data-testid'?: string;
6
+ }
7
+ declare const ColorPickerButton: ({ editor, type, ...restProps }: ColorPickerButtonProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default ColorPickerButton;
9
+ //# sourceMappingURL=ColorPickerButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorPickerButton.d.ts","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/ColorPickerButton.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAuG3D,UAAU,sBAAsB;IAC9B,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAID,QAAA,MAAM,iBAAiB,GAAI,gCAAgC,sBAAsB,4CAuMhF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,190 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useRef, useState, useEffect, useCallback } from 'react';
3
+ import styled, { css } from 'styled-components';
4
+ import { Button, RadioButtonGroup, RadioButton, ColorPicker, defaultThemeProp, useI18n, useUID, Tooltip, Popover, useOuterEvent, Text, Flex, calculateFontSize, isInstance, readableColor } from '@pega/cosmos-react-core';
5
+ import useEscapeKey from '../hooks/useEscapeKey';
6
+ import useCloseOnEditorClick from '../hooks/useCloseOnEditorClick';
7
+ const StyledColorButton = styled(Button)(({ theme }) => {
8
+ return css `
9
+ color: ${theme.base.palette['foreground-color']};
10
+ display: inline-flex;
11
+ align-items: center;
12
+ justify-content: center;
13
+ height: calc(3.5 * ${theme.base.spacing});
14
+ min-width: calc(3.5 * ${theme.base.spacing});
15
+ padding: 0;
16
+ `;
17
+ });
18
+ const StyledTextColorIcon = styled.span(({ theme, $color }) => {
19
+ const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);
20
+ return css `
21
+ display: flex;
22
+ flex-direction: column;
23
+ align-items: center;
24
+ font-weight: bold;
25
+ font-size: ${fontSizes.s};
26
+ line-height: 1;
27
+
28
+ &::after {
29
+ content: '';
30
+ display: block;
31
+ width: 100%;
32
+ height: calc(0.375 * ${theme.base.spacing});
33
+ background-color: ${$color || theme.base.palette['foreground-color']};
34
+ border-radius: calc(0.125 * ${theme.base.spacing});
35
+ margin-top: calc(0.125 * ${theme.base.spacing});
36
+ }
37
+ `;
38
+ });
39
+ StyledTextColorIcon.defaultProps = defaultThemeProp;
40
+ const StyledHighlightColorIcon = styled.span(({ theme, $color }) => {
41
+ const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);
42
+ const textColor = $color ? readableColor($color) : 'inherit';
43
+ return css `
44
+ display: flex;
45
+ align-items: center;
46
+ justify-content: center;
47
+ font-weight: bold;
48
+ font-size: ${fontSizes.s};
49
+ min-width: 1.25em;
50
+ min-height: 1.25em;
51
+ padding: 0.125em 0.25em;
52
+ border: calc(0.125 * ${theme.base.spacing}) solid
53
+ ${theme.components['form-control']['border-color']};
54
+ border-radius: calc(0.25 * ${theme.base['border-radius']});
55
+ background-color: ${$color || 'transparent'};
56
+ color: ${textColor};
57
+ `;
58
+ });
59
+ StyledHighlightColorIcon.defaultProps = defaultThemeProp;
60
+ StyledColorButton.defaultProps = defaultThemeProp;
61
+ const StyledPopoverContent = styled.div(({ theme }) => {
62
+ return css `
63
+ padding: ${theme.base.spacing};
64
+ min-width: calc(14 * ${theme.base.spacing});
65
+ `;
66
+ });
67
+ StyledPopoverContent.defaultProps = defaultThemeProp;
68
+ const StyledButtonGroup = styled.div(({ theme }) => {
69
+ return css `
70
+ display: flex;
71
+ gap: calc(0.5 * ${theme.base.spacing});
72
+ justify-content: flex-end;
73
+ `;
74
+ });
75
+ StyledButtonGroup.defaultProps = defaultThemeProp;
76
+ const ColorPickerButton = ({ editor, type, ...restProps }) => {
77
+ const t = useI18n();
78
+ const titleId = useUID();
79
+ const buttonRef = useRef(null);
80
+ const popoverRef = useRef(null);
81
+ const [open, setOpen] = useState(false);
82
+ const [colorType, setColorType] = useState('custom');
83
+ const [customColor, setCustomColor] = useState('#000000');
84
+ // Focus first radio button when popover opens
85
+ useEffect(() => {
86
+ if (open) {
87
+ // Use setTimeout to wait for popover to render
88
+ const timer = setTimeout(() => {
89
+ if (popoverRef.current) {
90
+ const firstRadio = popoverRef.current.querySelector('input[type="radio"]');
91
+ firstRadio?.focus();
92
+ }
93
+ }, 0);
94
+ return () => clearTimeout(timer);
95
+ }
96
+ }, [open]);
97
+ const getCurrentColor = () => {
98
+ const attrs = type === 'text' ? editor.getAttributes('textStyle') : editor.getAttributes('highlight');
99
+ const { color } = attrs;
100
+ return typeof color === 'string' ? color : undefined;
101
+ };
102
+ const currentColor = getCurrentColor();
103
+ const openMenu = () => {
104
+ // Initialize state based on current color, default to custom
105
+ if (currentColor) {
106
+ setCustomColor(currentColor);
107
+ }
108
+ else {
109
+ setCustomColor('#000000');
110
+ }
111
+ setColorType('custom');
112
+ setOpen(true);
113
+ };
114
+ const resetMenu = () => {
115
+ setOpen(false);
116
+ };
117
+ useOuterEvent('mousedown', [popoverRef, buttonRef], (event) => {
118
+ // Don't close if clicking inside a nested popover (like ColorPicker's palette)
119
+ const { target } = event;
120
+ if (isInstance(target, HTMLElement) && target.closest('[data-popper-placement]')) {
121
+ return;
122
+ }
123
+ if (open) {
124
+ resetMenu();
125
+ }
126
+ });
127
+ const handleSubmit = () => {
128
+ if (colorType === 'auto') {
129
+ if (type === 'text') {
130
+ editor.chain().focus().unsetColor().run();
131
+ }
132
+ else {
133
+ editor.chain().focus().unsetHighlight().run();
134
+ }
135
+ }
136
+ else if (type === 'text') {
137
+ editor.chain().focus().setColor(customColor).run();
138
+ }
139
+ else {
140
+ editor.chain().focus().setHighlight({ color: customColor }).run();
141
+ }
142
+ resetMenu();
143
+ };
144
+ const handleCancelKeyDown = (event) => {
145
+ if (event.key === 'Enter' && open) {
146
+ event.preventDefault();
147
+ resetMenu();
148
+ buttonRef.current?.focus();
149
+ }
150
+ };
151
+ const handleCancelMouseDown = (event) => {
152
+ if (open) {
153
+ event.preventDefault();
154
+ resetMenu();
155
+ buttonRef.current?.focus();
156
+ }
157
+ };
158
+ const handleEscapeClose = useCallback(() => {
159
+ resetMenu();
160
+ buttonRef.current?.focus();
161
+ }, []);
162
+ useEscapeKey(open, handleEscapeClose, editor);
163
+ useCloseOnEditorClick(open, handleEscapeClose);
164
+ const label = type === 'text' ? t('rte_text_color') : t('rte_background_color');
165
+ const modalTitle = type === 'text' ? t('rte_font_color') : t('rte_background_color');
166
+ const isHighlight = type === 'highlight';
167
+ return (_jsxs(_Fragment, { children: [_jsx(StyledColorButton, { ...restProps, variant: 'simple', type: 'button', ref: buttonRef, "data-toolbar-item": 'true', onMouseDown: (e) => {
168
+ e.preventDefault();
169
+ openMenu();
170
+ }, onKeyDown: (e) => {
171
+ if (e.key === 'Enter') {
172
+ e.preventDefault();
173
+ openMenu();
174
+ }
175
+ }, onBlur: (e) => {
176
+ const { relatedTarget } = e;
177
+ if (isInstance(relatedTarget, Node) &&
178
+ !buttonRef.current?.contains(relatedTarget) &&
179
+ !popoverRef.current?.contains(relatedTarget)) {
180
+ resetMenu();
181
+ }
182
+ }, "aria-label": label, "aria-haspopup": 'dialog', "aria-expanded": open, children: isHighlight ? (_jsx(StyledHighlightColorIcon, { "$color": currentColor, children: "A" })) : (_jsx(StyledTextColorIcon, { "$color": currentColor, children: "A" })) }), buttonRef.current && !open && (_jsx(Tooltip, { target: buttonRef.current, showDelay: 'none', hideDelay: 'none', children: label })), _jsx(Popover, { show: open, target: buttonRef.current, ref: popoverRef, placement: 'bottom', children: _jsx(StyledPopoverContent, { role: 'dialog', "aria-labelledby": titleId, children: _jsxs(Flex, { container: { direction: 'column', gap: 1 }, children: [_jsx(Text, { variant: 'h4', id: titleId, children: modalTitle }), _jsxs(RadioButtonGroup, { name: 'colorType', label: t('rte_color_type'), labelHidden: true, onChange: (e) => {
183
+ const { value } = e.target;
184
+ if (value === 'auto' || value === 'custom') {
185
+ setColorType(value);
186
+ }
187
+ }, inline: true, children: [_jsx(RadioButton, { label: t('rte_color_auto'), value: 'auto', checked: colorType === 'auto' }), _jsx(RadioButton, { label: t('rte_color_custom'), value: 'custom', checked: colorType === 'custom' })] }), _jsx(ColorPicker, { label: t('rte_color'), labelHidden: true, value: customColor, onChange: color => setCustomColor(color.hex), disabled: colorType === 'auto' }), _jsxs(StyledButtonGroup, { children: [_jsx(Button, { variant: 'secondary', onKeyDown: handleCancelKeyDown, onMouseDown: handleCancelMouseDown, type: 'button', children: t('cancel') }), _jsx(Button, { variant: 'primary', onClick: handleSubmit, children: t('submit') })] })] }) }) })] }));
188
+ };
189
+ export default ColorPickerButton;
190
+ //# sourceMappingURL=ColorPickerButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorPickerButton.js","sourceRo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AC,EACrB,WAAW,QACX,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,EAC5C,QAAQ,EAAE,SAAS,KAAK,MAAM,GAC9B,EACF,MAAC,iBAAiB,eAChB,KAAC,MAAM,IACL,OAAO,EAAC,WAAW,EACnB,SAAS,EAAE,mBAAmB,EAC9B,WAAW,EAAE,qBAAqB,EAClC,IAAI,EAAC,QAAQ,YAEZ,CAAC,CAAC,QAAQ,CAAC,GACL,EACT,KAAC,MAAM,IAAC,OAAO,EAAC,SAAS,EAAC,OAAO,EAAE,YAAY,YAC5C,CAAC,CAAC,QAAQ,CAAC,GACL,IACS,IACf,GACc,GACf,IACT,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC","sourcesContent":["import { useRef, useState, useEffect, useCallback } from 'react';\nimport type { MouseEvent, KeyboardEvent as ReactKeyboardEvent, ChangeEvent } from 'react';\nimport type { Editor as TiptapEditor } from '@tiptap/core';\nimport styled, { css } from 'styled-components';\n\nimport {\n Button,\n RadioButtonGroup,\n RadioButton,\n ColorPicker,\n defaultThemeProp,\n useI18n,\n useUID,\n Tooltip,\n Popover,\n useOuterEvent,\n Text,\n Flex,\n calculateFontSize,\n isInstance,\n readableColor\n} from '@pega/cosmos-react-core';\n\nimport useEscapeKey from '../hooks/useEscapeKey';\nimport useCloseOnEditorClick from '../hooks/useCloseOnEditorClick';\n\nconst StyledColorButton = styled(Button)(({ theme }) => {\n return css`\n color: ${theme.base.palette['foreground-color']};\n display: inline-flex;\n align-items: center;\n justify-content: center;\n height: calc(3.5 * ${theme.base.spacing});\n min-width: calc(3.5 * ${theme.base.spacing});\n padding: 0;\n `;\n});\n\nconst StyledTextColorIcon = styled.span<{ $color?: string }>(({ theme, $color }) => {\n const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n return css`\n display: flex;\n flex-direction: column;\n align-items: center;\n font-weight: bold;\n font-size: ${fontSizes.s};\n line-height: 1;\n\n &::after {\n content: '';\n display: block;\n width: 100%;\n height: calc(0.375 * ${theme.base.spacing});\n background-color: ${$color || theme.base.palette['foreground-color']};\n border-radius: calc(0.125 * ${theme.base.spacing});\n margin-top: calc(0.125 * ${theme.base.spacing});\n }\n `;\n});\n\nStyledTextColorIcon.defaultProps = defaultThemeProp;\n\nconst StyledHighlightColorIcon = styled.span<{ $color?: string }>(({ theme, $color }) => {\n const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n const textColor = $color ? readableColor($color) : 'inherit';\n return css`\n display: flex;\n align-items: center;\n justify-content: center;\n font-weight: bold;\n font-size: ${fontSizes.s};\n min-width: 1.25em;\n min-height: 1.25em;\n padding: 0.125em 0.25em;\n border: calc(0.125 * ${theme.base.spacing}) solid\n ${theme.components['form-control']['border-color']};\n border-radius: calc(0.25 * ${theme.base['border-radius']});\n background-color: ${$color || 'transparent'};\n color: ${textColor};\n `;\n});\n\nStyledHighlightColorIcon.defaultProps = defaultThemeProp;\n\nStyledColorButton.defaultProps = defaultThemeProp;\n\nconst StyledPopoverContent = styled.div(({ theme }) => {\n return css`\n padding: ${theme.base.spacing};\n min-width: calc(14 * ${theme.base.spacing});\n `;\n});\n\nStyledPopoverContent.defaultProps = defaultThemeProp;\n\nconst StyledButtonGroup = styled.div(({ theme }) => {\n return css`\n display: flex;\n gap: calc(0.5 * ${theme.base.spacing});\n justify-content: flex-end;\n `;\n});\n\nStyledButtonGroup.defaultProps = defaultThemeProp;\n\ninterface ColorPickerButtonProps {\n editor: TiptapEditor;\n type: 'text' | 'highlight';\n 'data-testid'?: string;\n}\n\ntype ColorType = 'auto' | 'custom';\n\nconst ColorPickerButton = ({ editor, type, ...restProps }: ColorPickerButtonProps) => {\n const t = useI18n();\n const titleId = useUID();\n const buttonRef = useRef<HTMLButtonElement>(null);\n const popoverRef = useRef<HTMLDivElement>(null);\n const [open, setOpen] = useState(false);\n const [colorType, setColorType] = useState<ColorType>('custom');\n const [customColor, setCustomColor] = useState('#000000');\n\n // Focus first radio button when popover opens\n useEffect(() => {\n if (open) {\n // Use setTimeout to wait for popover to render\n const timer = setTimeout(() => {\n if (popoverRef.current) {\n const firstRadio =\n popoverRef.current.querySelector<HTMLInputElement>('input[type=\"radio\"]');\n firstRadio?.focus();\n }\n }, 0);\n return () => clearTimeout(timer);\n }\n }, [open]);\n\n const getCurrentColor = (): string | undefined => {\n const attrs =\n type === 'text' ? editor.getAttributes('textStyle') : editor.getAttributes('highlight');\n const { color } = attrs;\n return typeof color === 'string' ? color : undefined;\n };\n\n const currentColor = getCurrentColor();\n\n const openMenu = () => {\n // Initialize state based on current color, default to custom\n if (currentColor) {\n setCustomColor(currentColor);\n } else {\n setCustomColor('#000000');\n }\n setColorType('custom');\n setOpen(true);\n };\n\n const resetMenu = () => {\n setOpen(false);\n };\n\n useOuterEvent('mousedown', [popoverRef, buttonRef], (event: Event) => {\n // Don't close if clicking inside a nested popover (like ColorPicker's palette)\n const { target } = event;\n if (isInstance(target, HTMLElement) && target.closest('[data-popper-placement]')) {\n return;\n }\n if (open) {\n resetMenu();\n }\n });\n\n const handleSubmit = () => {\n if (colorType === 'auto') {\n if (type === 'text') {\n editor.chain().focus().unsetColor().run();\n } else {\n editor.chain().focus().unsetHighlight().run();\n }\n } else if (type === 'text') {\n editor.chain().focus().setColor(customColor).run();\n } else {\n editor.chain().focus().setHighlight({ color: customColor }).run();\n }\n resetMenu();\n };\n\n const handleCancelKeyDown = (event: ReactKeyboardEvent<HTMLButtonElement>) => {\n if (event.key === 'Enter' && open) {\n event.preventDefault();\n resetMenu();\n buttonRef.current?.focus();\n }\n };\n\n const handleCancelMouseDown = (event: MouseEvent<HTMLButtonElement>) => {\n if (open) {\n event.preventDefault();\n resetMenu();\n buttonRef.current?.focus();\n }\n };\n\n const handleEscapeClose = useCallback(() => {\n resetMenu();\n buttonRef.current?.focus();\n }, []);\n\n useEscapeKey(open, handleEscapeClose, editor);\n useCloseOnEditorClick(open, handleEscapeClose);\n\n const label = type === 'text' ? t('rte_text_color') : t('rte_background_color');\n const modalTitle = type === 'text' ? t('rte_font_color') : t('rte_background_color');\n const isHighlight = type === 'highlight';\n\n return (\n <>\n <StyledColorButton\n {...restProps}\n variant='simple'\n type='button'\n ref={buttonRef}\n data-toolbar-item='true'\n onMouseDown={(e: MouseEvent) => {\n e.preventDefault();\n openMenu();\n }}\n onKeyDown={(e: ReactKeyboardEvent) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n openMenu();\n }\n }}\n onBlur={(e: React.FocusEvent) => {\n const { relatedTarget } = e;\n if (\n isInstance(relatedTarget, Node) &&\n !buttonRef.current?.contains(relatedTarget) &&\n !popoverRef.current?.contains(relatedTarget)\n ) {\n resetMenu();\n }\n }}\n aria-label={label}\n aria-haspopup='dialog'\n aria-expanded={open}\n >\n {isHighlight ? (\n <StyledHighlightColorIcon $color={currentColor}>A</StyledHighlightColorIcon>\n ) : (\n <StyledTextColorIcon $color={currentColor}>A</StyledTextColorIcon>\n )}\n </StyledColorButton>\n {buttonRef.current && !open && (\n <Tooltip target={buttonRef.current} showDelay='none' hideDelay='none'>\n {label}\n </Tooltip>\n )}\n <Popover show={open} target={buttonRef.current} ref={popoverRef} placement='bottom'>\n <StyledPopoverContent role='dialog' aria-labelledby={titleId}>\n <Flex container={{ direction: 'column', gap: 1 }}>\n <Text variant='h4' id={titleId}>\n {modalTitle}\n </Text>\n <RadioButtonGroup\n name='colorType'\n label={t('rte_color_type')}\n labelHidden\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n const { value } = e.target;\n if (value === 'auto' || value === 'custom') {\n setColorType(value);\n }\n }}\n inline\n >\n <RadioButton\n label={t('rte_color_auto')}\n value='auto'\n checked={colorType === 'auto'}\n />\n <RadioButton\n label={t('rte_color_custom')}\n value='custom'\n checked={colorType === 'custom'}\n />\n </RadioButtonGroup>\n <ColorPicker\n label={t('rte_color')}\n labelHidden\n value={customColor}\n onChange={color => setCustomColor(color.hex)}\n disabled={colorType === 'auto'}\n />\n <StyledButtonGroup>\n <Button\n variant='secondary'\n onKeyDown={handleCancelKeyDown}\n onMouseDown={handleCancelMouseDown}\n type='button'\n >\n {t('cancel')}\n </Button>\n <Button variant='primary' onClick={handleSubmit}>\n {t('submit')}\n </Button>\n </StyledButtonGroup>\n </Flex>\n </StyledPopoverContent>\n </Popover>\n </>\n );\n};\n\nexport default ColorPickerButton;\n"]}
@@ -0,0 +1,8 @@
1
+ import type { Editor as TiptapEditor } from '@tiptap/core';
2
+ interface FontFamilySelectProps {
3
+ editor: TiptapEditor;
4
+ 'data-testid'?: string;
5
+ }
6
+ declare const FontFamilySelect: ({ editor, ...restProps }: FontFamilySelectProps) => import("react/jsx-runtime").JSX.Element;
7
+ export default FontFamilySelect;
8
+ //# sourceMappingURL=FontFamilySelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FontFamilySelect.d.ts","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/FontFamilySelect.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAoE3D,UAAU,qBAAqB;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,QAAA,MAAM,gBAAgB,GAAI,0BAA0B,qBAAqB,4CAwJxE,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,150 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useRef, useState, useCallback } from 'react';
3
+ import styled, { css } from 'styled-components';
4
+ import { Popover, Icon, registerIcon, useOuterEvent, Menu, Button, defaultThemeProp, useI18n, Tooltip, calculateFontSize, isInstance } from '@pega/cosmos-react-core';
5
+ import * as arrowMicroDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/arrow-micro-down.icon';
6
+ import useEscapeKey from '../hooks/useEscapeKey';
7
+ import useCloseOnEditorClick from '../hooks/useCloseOnEditorClick';
8
+ registerIcon(arrowMicroDownIcon);
9
+ const StyledFontSelect = styled(Button)(({ theme }) => {
10
+ const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);
11
+ return css `
12
+ color: ${theme.base.palette['foreground-color']};
13
+ display: inline-flex;
14
+ align-items: center;
15
+ height: calc(3.5 * ${theme.base.spacing});
16
+ padding: 0 calc(0.5 * ${theme.base.spacing});
17
+ font-size: ${fontSizes.xxs};
18
+ min-width: 12ch;
19
+
20
+ span {
21
+ white-space: nowrap;
22
+ overflow: hidden;
23
+ text-overflow: ellipsis;
24
+ }
25
+ `;
26
+ });
27
+ StyledFontSelect.defaultProps = defaultThemeProp;
28
+ const StyledSelectMenu = styled.div(({ theme }) => {
29
+ return css `
30
+ min-width: 16ch;
31
+ max-height: calc(30 * ${theme.base.spacing});
32
+ `;
33
+ });
34
+ StyledSelectMenu.defaultProps = defaultThemeProp;
35
+ const FONT_FAMILIES = [
36
+ { id: 'default', labelKey: 'rte_default_font', value: '' },
37
+ { id: 'arial', label: 'Arial', value: 'Arial, Helvetica, sans-serif' },
38
+ { id: 'courier', label: 'Courier New', value: '"Courier New", Courier, monospace' },
39
+ { id: 'georgia', label: 'Georgia', value: 'Georgia, serif' },
40
+ { id: 'times', label: 'Times New Roman', value: '"Times New Roman", Times, serif' },
41
+ { id: 'trebuchet', label: 'Trebuchet MS', value: '"Trebuchet MS", sans-serif' },
42
+ { id: 'verdana', label: 'Verdana', value: 'Verdana, Geneva, sans-serif' }
43
+ ];
44
+ const FontFamilySelect = ({ editor, ...restProps }) => {
45
+ const t = useI18n();
46
+ const [open, setOpen] = useState(false);
47
+ const selecting = useRef(false);
48
+ const openedByClick = useRef(false);
49
+ const buttonRef = useRef(null);
50
+ const popoverRef = useRef(null);
51
+ const menuRef = useRef(null);
52
+ useOuterEvent('mousedown', [buttonRef, popoverRef, menuRef], () => {
53
+ if (open) {
54
+ setOpen(false);
55
+ }
56
+ });
57
+ const handleEscapeClose = useCallback(() => {
58
+ setOpen(false);
59
+ buttonRef.current?.focus();
60
+ }, []);
61
+ useEscapeKey(open, handleEscapeClose, editor);
62
+ useCloseOnEditorClick(open, handleEscapeClose);
63
+ const onFontSelect = (fontId, e) => {
64
+ e.stopPropagation();
65
+ e.preventDefault();
66
+ const font = FONT_FAMILIES.find(f => f.id === fontId);
67
+ if (font) {
68
+ if (font.value) {
69
+ editor.chain().focus().setFontFamily(font.value).run();
70
+ }
71
+ else {
72
+ editor.chain().focus().unsetFontFamily().run();
73
+ }
74
+ }
75
+ if (!openedByClick.current) {
76
+ buttonRef.current?.focus();
77
+ }
78
+ setOpen(false);
79
+ selecting.current = true;
80
+ setTimeout(() => {
81
+ selecting.current = false;
82
+ if (!editor.isFocused && openedByClick.current) {
83
+ editor.commands.focus();
84
+ }
85
+ }, 0);
86
+ };
87
+ const getFontLabel = (font) => {
88
+ if (font.labelKey) {
89
+ return t(font.labelKey);
90
+ }
91
+ return font.label;
92
+ };
93
+ const getActiveFont = () => {
94
+ const attrs = editor.getAttributes('textStyle');
95
+ const { fontFamily } = attrs;
96
+ if (typeof fontFamily !== 'string' || !fontFamily)
97
+ return t('rte_default_font');
98
+ const match = FONT_FAMILIES.find(f => f.value === fontFamily);
99
+ return match ? getFontLabel(match) : fontFamily;
100
+ };
101
+ const getActiveFontId = () => {
102
+ const attrs = editor.getAttributes('textStyle');
103
+ const { fontFamily } = attrs;
104
+ if (typeof fontFamily !== 'string' || !fontFamily)
105
+ return 'default';
106
+ const match = FONT_FAMILIES.find(f => f.value === fontFamily);
107
+ return match?.id ?? 'default';
108
+ };
109
+ return (_jsxs(_Fragment, { children: [_jsxs(StyledFontSelect, { ...restProps, variant: 'simple', type: 'button', icon: false, ref: buttonRef, "data-toolbar-item": 'true', onMouseDown: (e) => {
110
+ e.preventDefault();
111
+ if (!open) {
112
+ openedByClick.current = true;
113
+ }
114
+ setOpen(!open);
115
+ }, onKeyDown: (e) => {
116
+ if (e.key === 'Enter' && !selecting.current) {
117
+ e.preventDefault();
118
+ setOpen(true);
119
+ openedByClick.current = false;
120
+ }
121
+ else if (e.key === 'Enter') {
122
+ e.preventDefault();
123
+ selecting.current = false;
124
+ }
125
+ else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
126
+ setOpen(false);
127
+ }
128
+ else if (e.key === 'Escape' && open) {
129
+ e.preventDefault();
130
+ setOpen(false);
131
+ }
132
+ }, onFocus: (e) => {
133
+ e.preventDefault();
134
+ e.stopPropagation();
135
+ }, onBlur: (e) => {
136
+ const { relatedTarget } = e;
137
+ if (isInstance(relatedTarget, Node) &&
138
+ !buttonRef.current?.contains(relatedTarget) &&
139
+ !popoverRef.current?.contains(relatedTarget) &&
140
+ !menuRef.current?.contains(relatedTarget)) {
141
+ setOpen(false);
142
+ }
143
+ }, onClick: (e) => e.stopPropagation(), "aria-expanded": open, "aria-label": `${t('rte_font_family')}. ${getActiveFont()} ${t('selected').toLocaleLowerCase()}`, "aria-haspopup": true, children: [_jsx("span", { children: getActiveFont() }), _jsx(Icon, { name: 'arrow-micro-down' })] }), buttonRef.current && (_jsx(Tooltip, { target: buttonRef.current, showDelay: 'none', hideDelay: 'none', children: t('rte_font_family') })), _jsx(Popover, { show: open, as: StyledSelectMenu, target: buttonRef.current, placement: 'bottom-start', ref: popoverRef, children: _jsx(Menu, { items: FONT_FAMILIES.map(font => ({
144
+ id: font.id,
145
+ primary: getFontLabel(font),
146
+ selected: font.id === getActiveFontId()
147
+ })), focusControlEl: buttonRef.current ?? undefined, mode: 'single-select', ref: menuRef, onItemClick: onFontSelect }) })] }));
148
+ };
149
+ export default FontFamilySelect;
150
+ //# sourceMappingURL=FontFamilySelect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FontFamilySelect.js","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/FontFamilySelect.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,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ACH,cAAc,EAAE,SAAS,CAAC,OAAO,IAAI,SAAS,EAC9C,IAAI,EAAC,eAAe,EACpB,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,YAAY,GACzB,GACM,IACT,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import { useRef, useState, useCallback } from 'react';\nimport type { MouseEvent, KeyboardEvent, FocusEvent } from 'react';\nimport type { Editor as TiptapEditor } from '@tiptap/core';\nimport styled, { css } from 'styled-components';\n\nimport {\n Popover,\n Icon,\n registerIcon,\n useOuterEvent,\n Menu,\n Button,\n defaultThemeProp,\n useI18n,\n Tooltip,\n calculateFontSize,\n isInstance\n} from '@pega/cosmos-react-core';\nimport type { TranslationPack } from '@pega/cosmos-react-core';\nimport * as arrowMicroDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/arrow-micro-down.icon';\n\nimport useEscapeKey from '../hooks/useEscapeKey';\nimport useCloseOnEditorClick from '../hooks/useCloseOnEditorClick';\n\nregisterIcon(arrowMicroDownIcon);\n\nconst StyledFontSelect = styled(Button)(({ theme }) => {\n const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n return css`\n color: ${theme.base.palette['foreground-color']};\n display: inline-flex;\n align-items: center;\n height: calc(3.5 * ${theme.base.spacing});\n padding: 0 calc(0.5 * ${theme.base.spacing});\n font-size: ${fontSizes.xxs};\n min-width: 12ch;\n\n span {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n `;\n});\n\nStyledFontSelect.defaultProps = defaultThemeProp;\n\nconst StyledSelectMenu = styled.div(({ theme }) => {\n return css`\n min-width: 16ch;\n max-height: calc(30 * ${theme.base.spacing});\n `;\n});\n\nStyledSelectMenu.defaultProps = defaultThemeProp;\n\ntype FontFamilyItem =\n | { id: string; labelKey: keyof TranslationPack; value: string; label?: never }\n | { id: string; label: string; value: string; labelKey?: never };\n\nconst FONT_FAMILIES: FontFamilyItem[] = [\n { id: 'default', labelKey: 'rte_default_font', value: '' },\n { id: 'arial', label: 'Arial', value: 'Arial, Helvetica, sans-serif' },\n { id: 'courier', label: 'Courier New', value: '\"Courier New\", Courier, monospace' },\n { id: 'georgia', label: 'Georgia', value: 'Georgia, serif' },\n { id: 'times', label: 'Times New Roman', value: '\"Times New Roman\", Times, serif' },\n { id: 'trebuchet', label: 'Trebuchet MS', value: '\"Trebuchet MS\", sans-serif' },\n { id: 'verdana', label: 'Verdana', value: 'Verdana, Geneva, sans-serif' }\n];\n\ninterface FontFamilySelectProps {\n editor: TiptapEditor;\n 'data-testid'?: string;\n}\n\nconst FontFamilySelect = ({ editor, ...restProps }: FontFamilySelectProps) => {\n const t = useI18n();\n const [open, setOpen] = useState(false);\n const selecting = useRef(false);\n const openedByClick = useRef(false);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const popoverRef = useRef<HTMLDivElement>(null);\n const menuRef = useRef<HTMLDivElement>(null);\n\n useOuterEvent('mousedown', [buttonRef, popoverRef, menuRef], () => {\n if (open) {\n setOpen(false);\n }\n });\n\n const handleEscapeClose = useCallback(() => {\n setOpen(false);\n buttonRef.current?.focus();\n }, []);\n\n useEscapeKey(open, handleEscapeClose, editor);\n useCloseOnEditorClick(open, handleEscapeClose);\n\n const onFontSelect = (fontId: string, e: MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n\n const font = FONT_FAMILIES.find(f => f.id === fontId);\n if (font) {\n if (font.value) {\n editor.chain().focus().setFontFamily(font.value).run();\n } else {\n editor.chain().focus().unsetFontFamily().run();\n }\n }\n\n if (!openedByClick.current) {\n buttonRef.current?.focus();\n }\n setOpen(false);\n selecting.current = true;\n setTimeout(() => {\n selecting.current = false;\n if (!editor.isFocused && openedByClick.current) {\n editor.commands.focus();\n }\n }, 0);\n };\n\n const getFontLabel = (font: FontFamilyItem): string => {\n if (font.labelKey) {\n return t(font.labelKey);\n }\n return font.label;\n };\n\n const getActiveFont = (): string => {\n const attrs = editor.getAttributes('textStyle');\n const { fontFamily } = attrs;\n if (typeof fontFamily !== 'string' || !fontFamily) return t('rte_default_font');\n const match = FONT_FAMILIES.find(f => f.value === fontFamily);\n return match ? getFontLabel(match) : fontFamily;\n };\n\n const getActiveFontId = (): string => {\n const attrs = editor.getAttributes('textStyle');\n const { fontFamily } = attrs;\n if (typeof fontFamily !== 'string' || !fontFamily) return 'default';\n const match = FONT_FAMILIES.find(f => f.value === fontFamily);\n return match?.id ?? 'default';\n };\n\n return (\n <>\n <StyledFontSelect\n {...restProps}\n variant='simple'\n type='button'\n icon={false}\n ref={buttonRef}\n data-toolbar-item='true'\n onMouseDown={(e: MouseEvent) => {\n e.preventDefault();\n if (!open) {\n openedByClick.current = true;\n }\n setOpen(!open);\n }}\n onKeyDown={(e: KeyboardEvent) => {\n if (e.key === 'Enter' && !selecting.current) {\n e.preventDefault();\n setOpen(true);\n openedByClick.current = false;\n } else if (e.key === 'Enter') {\n e.preventDefault();\n selecting.current = false;\n } else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {\n setOpen(false);\n } else if (e.key === 'Escape' && open) {\n e.preventDefault();\n setOpen(false);\n }\n }}\n onFocus={(e: FocusEvent) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onBlur={(e: FocusEvent) => {\n const { relatedTarget } = e;\n if (\n isInstance(relatedTarget, Node) &&\n !buttonRef.current?.contains(relatedTarget) &&\n !popoverRef.current?.contains(relatedTarget) &&\n !menuRef.current?.contains(relatedTarget)\n ) {\n setOpen(false);\n }\n }}\n onClick={(e: MouseEvent) => e.stopPropagation()}\n aria-expanded={open}\n aria-label={`${t('rte_font_family')}. ${getActiveFont()} ${t('selected').toLocaleLowerCase()}`}\n aria-haspopup\n >\n <span>{getActiveFont()}</span>\n <Icon name='arrow-micro-down' />\n </StyledFontSelect>\n {buttonRef.current && (\n <Tooltip target={buttonRef.current} showDelay='none' hideDelay='none'>\n {t('rte_font_family')}\n </Tooltip>\n )}\n <Popover\n show={open}\n as={StyledSelectMenu}\n target={buttonRef.current}\n placement='bottom-start'\n ref={popoverRef}\n >\n <Menu\n items={FONT_FAMILIES.map(font => ({\n id: font.id,\n primary: getFontLabel(font),\n selected: font.id === getActiveFontId()\n }))}\n focusControlEl={buttonRef.current ?? undefined}\n mode='single-select'\n ref={menuRef}\n onItemClick={onFontSelect}\n />\n </Popover>\n </>\n );\n};\n\nexport default FontFamilySelect;\n"]}
@@ -0,0 +1,8 @@
1
+ import type { Editor as TiptapEditor } from '@tiptap/core';
2
+ interface FontSizeSelectProps {
3
+ editor: TiptapEditor;
4
+ 'data-testid'?: string;
5
+ }
6
+ declare const FontSizeSelect: ({ editor, ...restProps }: FontSizeSelectProps) => import("react/jsx-runtime").JSX.Element;
7
+ export default FontSizeSelect;
8
+ //# sourceMappingURL=FontSizeSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FontSizeSelect.d.ts","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/FontSizeSelect.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAqE3D,UAAU,mBAAmB;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,QAAA,MAAM,cAAc,GAAI,0BAA0B,mBAAmB,4CA6IpE,CAAC;AAEF,eAAe,cAAc,CAAC"}