@pega/cosmos-react-rte 4.0.0-dev.14.0 → 4.0.0-dev.14.2
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.
- package/lib/components/Editor/ImageEditor.js +3 -3
- package/lib/components/Editor/ImageEditor.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.js +5 -5
- package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.js.map +1 -1
- package/lib/components/RichTextEditor/utils/ListCommands.js +10 -10
- package/lib/components/RichTextEditor/utils/ListCommands.js.map +1 -1
- package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/htmlConverter.js +2 -4
- package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.js +6 -6
- package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +1 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.js +3 -3
- package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -1
- package/package.json +2 -2
|
@@ -94,9 +94,9 @@ const ImageEditor = ({ editorEl, editor, onChange }) => {
|
|
|
94
94
|
const onAltTextChange = (e) => {
|
|
95
95
|
setAltText(e.target.value);
|
|
96
96
|
};
|
|
97
|
-
|
|
98
|
-
If the value entered is too small, the value will be defaulted.
|
|
99
|
-
When the height is input, a new width will be calculated and vice versa.
|
|
97
|
+
// The next two functions handle changing the height and width of the selected image element.
|
|
98
|
+
// If the value entered is too small, the value will be defaulted.
|
|
99
|
+
// When the height is input, a new width will be calculated and vice versa.
|
|
100
100
|
const onHeightChange = (incomingValue) => {
|
|
101
101
|
const inputHeight = parseInt(incomingValue, 10);
|
|
102
102
|
setHeight(inputHeight);
|
|
@@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AC,EAC/B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAChD,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,aAAa,GACvB,GACG,EACP,KAAC,IAAI,IAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,YAC5B,KAAC,WAAW,IACV,KAAK,EAAE,CAAC,CAAC,sBAAsB,CAAC,EAChC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EACjD,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,cAAc,GACxB,GACG,IACN,CACJ,IACI,GACF,GACK,IACN,CACX,IACA,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import {\n FC,\n MouseEvent as ReactMouseEvent,\n useEffect,\n useRef,\n useState,\n ChangeEvent,\n CSSProperties,\n useLayoutEffect\n} from 'react';\nimport { Editor } from 'tinymce';\nimport styled from 'styled-components';\n\nimport {\n Button,\n CardContent,\n CardHeader,\n Checkbox,\n createUID,\n Flex,\n Form,\n Grid,\n Icon,\n Input,\n NumberInput,\n Popover,\n Text,\n useAfterInitialEffect,\n useElement,\n useI18n,\n useOuterEvent,\n useUID,\n VisuallyHiddenText\n} from '@pega/cosmos-react-core';\n\nconst IgnoreMouseEventsIcon = styled.svg`\n pointer-events: none;\n`;\n\nexport const imgHoverClass = createUID();\n\nconst ImageEditor: FC<{ editorEl: HTMLElement; editor: Editor; onChange: () => void }> = ({\n editorEl,\n editor,\n onChange\n}) => {\n const t = useI18n();\n const id = useUID();\n const [showImagePopover, setShowImagePopover] = useState(false);\n const [showEditButton, setShowEditButton] = useState(false);\n const [canShowEditButton, setCanShowEditButton] = useState(false);\n const [imgEl, setImageEl] = useState<HTMLImageElement | null>(null);\n const [imgElements, setImageElements] = useState<HTMLImageElement[]>([]);\n const [buttonEl, setButtonEl] = useElement<HTMLButtonElement>(null);\n const [width, setWidth] = useState(0);\n const [height, setHeight] = useState(0);\n const [aspectRatio, setAspectRatio] = useState(0);\n const [altText, setAltText] = useState('');\n const [customSize, setCustomSize] = useState(false);\n const [keyCommandText, setKeyCommandText] = useState('');\n const imagePopoverRef = useRef<HTMLDivElement>(null);\n const altTextInputRef = useRef<HTMLInputElement>(null);\n const editorOpenedWithEnter = useRef(false);\n const [btnStyle, setBtnStyle] = useState<CSSProperties>({});\n\n const onImageClick = (e: MouseEvent | ReactMouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n setShowImagePopover(true);\n };\n\n const calculateBtnStyles = (el: HTMLElement): CSSProperties => {\n const elementRect = el.getBoundingClientRect();\n return {\n position: 'absolute',\n top: elementRect.top + (elementRect.height / 2 - (buttonEl?.scrollHeight || 0) / 2),\n left: elementRect.left + (elementRect.width / 2 - (buttonEl?.scrollWidth || 0) / 2)\n };\n };\n\n const onImageMouseEnter = (e: MouseEvent) => {\n if (!showImagePopover) {\n const el = e.target as HTMLElement;\n setShowEditButton(true);\n setImageEl(el as HTMLImageElement);\n }\n };\n\n const onImageMouseLeave = (e: MouseEvent) => {\n if (e.relatedTarget && (e.relatedTarget as HTMLButtonElement).id !== id && !showImagePopover) {\n setImageEl(null);\n setShowEditButton(false);\n }\n };\n\n const setImageState = () => {\n if (imgEl) {\n let imgHeight;\n let imgWidth;\n let hasHeightOrWidthAttribute = false;\n if (imgEl.getAttribute('height')) {\n imgHeight = parseInt(imgEl.getAttribute('height') as string, 10);\n hasHeightOrWidthAttribute = true;\n } else {\n imgHeight = imgEl.naturalHeight;\n }\n if (imgEl.getAttribute('width')) {\n imgWidth = parseInt(imgEl.getAttribute('width') as string, 10);\n hasHeightOrWidthAttribute = true;\n } else {\n imgWidth = imgEl.naturalWidth;\n }\n setAltText(imgEl.getAttribute('alt') || '');\n setHeight(imgHeight);\n setWidth(imgWidth);\n setAspectRatio(imgWidth / imgHeight);\n setCustomSize(hasHeightOrWidthAttribute);\n }\n };\n\n useOuterEvent('mousedown', [imagePopoverRef], () => {\n setImageState();\n setShowImagePopover(false);\n });\n\n const onCheckBoxClick = (e: ReactMouseEvent) => {\n e.stopPropagation();\n };\n\n const onInputClick = (e: ReactMouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n };\n\n const onInputFocus = (e: FocusEvent) => {\n e.stopPropagation();\n };\n\n const onAltTextChange = (e: ChangeEvent<HTMLInputElement>) => {\n setAltText(e.target.value);\n };\n\n /* The next two functions handle changing the height and width of the selected image element.\n If the value entered is too small, the value will be defaulted.\n When the height is input, a new width will be calculated and vice versa. */\n const onHeightChange = (incomingValue: string) => {\n const inputHeight = parseInt(incomingValue, 10);\n\n setHeight(inputHeight);\n setWidth(inputHeight * aspectRatio);\n };\n\n const onWidthChange = (incomingValue: string) => {\n const inputWidth = parseInt(incomingValue, 10);\n\n setWidth(inputWidth);\n setHeight(inputWidth / aspectRatio);\n };\n\n const onImageChangeSubmit = (e: MouseEvent) => {\n e.preventDefault();\n if (imgEl) {\n if (customSize) {\n if (Number.isNaN(height) || Number.isNaN(width)) {\n imgEl.removeAttribute('height');\n imgEl.removeAttribute('width');\n setHeight(imgEl.naturalHeight);\n setWidth(imgEl.naturalWidth);\n } else {\n imgEl.setAttribute('height', height.toString());\n imgEl.setAttribute('width', width.toString());\n }\n } else {\n imgEl.removeAttribute('height');\n imgEl.removeAttribute('width');\n }\n imgEl.setAttribute('alt', altText);\n }\n\n editor.selection.select(editor.dom.select(`img[src=\"${imgEl?.src}\"]`)[0]);\n setImageEl(null);\n setShowImagePopover(false);\n onChange();\n };\n\n const onImageChangeCancel = () => {\n setImageEl(null);\n setShowImagePopover(false);\n };\n\n const onImageDelete = () => {\n if (imgEl) {\n imgEl.remove();\n }\n setImageEl(null);\n setShowImagePopover(false);\n onChange();\n };\n\n // Keeps the imageElements state up to date with existing and newly added img tags inside of TinyMCE\n useEffect(() => {\n const iframeDoc = editor.getDoc();\n const imageElements = iframeDoc?.querySelectorAll('img') ?? ([] as HTMLImageElement[]);\n setImageElements(() => {\n return [...imageElements];\n });\n const observer = new MutationObserver(mutations => {\n mutations.forEach(mutation => {\n if (\n mutation.type === 'childList' &&\n (mutation.addedNodes.length || mutation.removedNodes.length)\n ) {\n const newImageElements = iframeDoc?.querySelectorAll('img') ?? ([] as HTMLImageElement[]);\n setImageElements(() => [...newImageElements]);\n }\n });\n });\n if (iframeDoc) {\n observer.observe(iframeDoc.body, { childList: true, subtree: true });\n }\n return () => {\n observer.disconnect();\n };\n }, [editorEl, editor, setImageElements]);\n\n // Adds event listeners to HTML img elements inside of TinyMCE\n // This has to be done because there are no react components for these images\n useEffect(() => {\n imgElements.forEach(imgElement => {\n imgElement.addEventListener('mouseenter', onImageMouseEnter);\n imgElement.addEventListener('mouseout', onImageMouseLeave);\n imgElement.addEventListener('click', onImageClick);\n });\n return () => {\n imgElements.forEach(imgElement => {\n imgElement.removeEventListener('mouseenter', onImageMouseEnter);\n imgElement.removeEventListener('mouseout', onImageMouseLeave);\n imgElement.removeEventListener('click', onImageClick);\n });\n };\n }, [imgElements, onImageMouseEnter, onImageMouseLeave, onImageClick]);\n\n useEffect(() => {\n setImageState();\n imgEl?.setAttribute('class', imgHoverClass);\n if (imgEl && imgEl.clientHeight > 36 && imgEl.clientWidth > 36) {\n setCanShowEditButton(true);\n } else {\n setCanShowEditButton(false);\n }\n return () => {\n imgEl?.removeAttribute('class');\n };\n }, [imgEl]);\n\n useEffect(() => {\n const onKeyUp = () => {\n const selection = editor.selection.getSel();\n let nextToImg = false;\n // If your selection is next to an image on it's own line (not breaking text)\n if (\n selection &&\n selection.anchorNode?.childNodes.length === 1 &&\n selection.anchorNode?.firstChild?.nodeName === 'IMG' &&\n selection.anchorOffset === 0\n ) {\n setImageEl(selection.anchorNode.firstChild as HTMLImageElement);\n setShowEditButton(true);\n nextToImg = true;\n // If your selection is next to an image that breaks text up inside of a paragraph\n } else if (selection && selection.anchorNode?.nextSibling?.nodeName === 'IMG') {\n setImageEl(selection.anchorNode.nextSibling as HTMLImageElement);\n setShowEditButton(true);\n nextToImg = true;\n } else if (selection && imgEl && showEditButton) {\n setImageEl(null);\n setShowEditButton(false);\n setKeyCommandText('');\n }\n\n if (nextToImg) {\n setKeyCommandText(t('rte_image_key_command'));\n }\n };\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Enter' && showEditButton) {\n e.stopPropagation();\n e.preventDefault();\n editorOpenedWithEnter.current = true;\n setShowImagePopover(true);\n } else if (e.key === 'Del' && showEditButton) {\n onImageDelete();\n }\n };\n editor.on('keyup', onKeyUp);\n editor.on('keydown', onKeyDown, true);\n return () => {\n editor.off('keyup', onKeyUp);\n editor.off('keydown', onKeyDown);\n };\n }, [editor, imgEl, showEditButton]);\n\n useAfterInitialEffect(() => {\n if (showImagePopover) {\n editor.selection.getSel()?.collapseToEnd();\n\n if (editorOpenedWithEnter.current) {\n altTextInputRef.current?.focus();\n editorOpenedWithEnter.current = false;\n }\n } else {\n editor.focus();\n }\n }, [showImagePopover]);\n\n useLayoutEffect(() => {\n if (imgEl && buttonEl) {\n setBtnStyle(calculateBtnStyles(imgEl));\n }\n }, [imgEl, buttonEl]);\n\n return (\n <>\n {showEditButton && imgEl && canShowEditButton && (\n <Button\n id={id}\n icon\n variant='primary'\n ref={setButtonEl}\n onClick={() => setShowImagePopover(true)}\n style={{ ...btnStyle }}\n >\n <Icon name='pencil-solid' as={IgnoreMouseEventsIcon} />\n </Button>\n )}\n <VisuallyHiddenText aria-live='polite'>{keyCommandText}</VisuallyHiddenText>\n {showImagePopover && (buttonEl || !canShowEditButton) && imgEl && (\n <Popover\n target={canShowEditButton ? buttonEl : imgEl}\n strategy='fixed'\n arrow\n ref={imagePopoverRef}\n onClick={(e: MouseEvent) => e.stopPropagation()}\n >\n <CardHeader\n actions={\n <Button variant='simple' icon onClick={onImageChangeCancel} label={t('close')}>\n <Icon name='times' />\n </Button>\n }\n >\n <Text variant='h3'>{t('rte_image_settings')}</Text>\n </CardHeader>\n <CardContent>\n <Form\n as='div'\n actions={\n <Flex container={{ justify: 'between' }} item={{ grow: 1 }}>\n <Flex item={{ grow: 1 }}>\n <Button onClick={onImageChangeCancel}>{t('cancel')}</Button>\n <Button onClick={onImageDelete}>{t('delete')}</Button>\n </Flex>\n <Button variant='primary' onClick={onImageChangeSubmit}>\n {t('submit')}\n </Button>\n </Flex>\n }\n >\n <Grid\n container={{\n gap: 2,\n areas: customSize\n ? '\"desc desc\" \"radio radio\" \"width height\"'\n : '\"desc desc\" \"radio radio\"'\n }}\n >\n <Grid item={{ area: 'desc' }}>\n <Input\n label={t('description')}\n value={altText}\n onClick={onInputClick}\n onChange={onAltTextChange}\n onFocus={onInputFocus}\n info={t('rte_image_description_info')}\n ref={altTextInputRef}\n />\n </Grid>\n <Grid item={{ area: 'radio' }}>\n <Checkbox\n checked={customSize}\n label={t('rte_image_custom_size')}\n onClick={onCheckBoxClick}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n setCustomSize(e.target.checked);\n }}\n />\n </Grid>\n {customSize && (\n <>\n <Grid item={{ area: 'width' }}>\n <NumberInput\n label={t('rte_width_in_pixels')}\n value={Math.floor(Math.max(width, 1)).toString()}\n onClick={onInputClick}\n onChange={onWidthChange}\n />\n </Grid>\n <Grid item={{ area: 'height' }}>\n <NumberInput\n label={t('rte_height_in_pixels')}\n value={Math.floor(Math.max(height, 1)).toString()}\n onClick={onInputClick}\n onChange={onHeightChange}\n />\n </Grid>\n </>\n )}\n </Grid>\n </Form>\n </CardContent>\n </Popover>\n )}\n </>\n );\n};\n\nexport default ImageEditor;\n"]}
|
|
1
|
+
{"version":3,"file":"ImageEditor.js","sourceRoot":"","sources":["../../../src/components/Editor/ImageEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,SAAS,EACT,MAAM,EACN,QAAQ,EAGR,eAAe,EAChB,MAAM,OAAO,CAAC;AAEf,OAA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GACvB,GACG,EACP,KAAC,IAAI,IAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,YAC5B,KAAC,WAAW,IACV,KAAK,EAAE,CAAC,CAAC,sBAAsB,CAAC,EAChC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EACjD,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,cAAc,GACxB,GACG,IACN,CACJ,IACI,GACF,GACK,IACN,CACX,IACA,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import {\n FC,\n MouseEvent as ReactMouseEvent,\n useEffect,\n useRef,\n useState,\n ChangeEvent,\n CSSProperties,\n useLayoutEffect\n} from 'react';\nimport { Editor } from 'tinymce';\nimport styled from 'styled-components';\n\nimport {\n Button,\n CardContent,\n CardHeader,\n Checkbox,\n createUID,\n Flex,\n Form,\n Grid,\n Icon,\n Input,\n NumberInput,\n Popover,\n Text,\n useAfterInitialEffect,\n useElement,\n useI18n,\n useOuterEvent,\n useUID,\n VisuallyHiddenText\n} from '@pega/cosmos-react-core';\n\nconst IgnoreMouseEventsIcon = styled.svg`\n pointer-events: none;\n`;\n\nexport const imgHoverClass = createUID();\n\nconst ImageEditor: FC<{ editorEl: HTMLElement; editor: Editor; onChange: () => void }> = ({\n editorEl,\n editor,\n onChange\n}) => {\n const t = useI18n();\n const id = useUID();\n const [showImagePopover, setShowImagePopover] = useState(false);\n const [showEditButton, setShowEditButton] = useState(false);\n const [canShowEditButton, setCanShowEditButton] = useState(false);\n const [imgEl, setImageEl] = useState<HTMLImageElement | null>(null);\n const [imgElements, setImageElements] = useState<HTMLImageElement[]>([]);\n const [buttonEl, setButtonEl] = useElement<HTMLButtonElement>(null);\n const [width, setWidth] = useState(0);\n const [height, setHeight] = useState(0);\n const [aspectRatio, setAspectRatio] = useState(0);\n const [altText, setAltText] = useState('');\n const [customSize, setCustomSize] = useState(false);\n const [keyCommandText, setKeyCommandText] = useState('');\n const imagePopoverRef = useRef<HTMLDivElement>(null);\n const altTextInputRef = useRef<HTMLInputElement>(null);\n const editorOpenedWithEnter = useRef(false);\n const [btnStyle, setBtnStyle] = useState<CSSProperties>({});\n\n const onImageClick = (e: MouseEvent | ReactMouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n setShowImagePopover(true);\n };\n\n const calculateBtnStyles = (el: HTMLElement): CSSProperties => {\n const elementRect = el.getBoundingClientRect();\n return {\n position: 'absolute',\n top: elementRect.top + (elementRect.height / 2 - (buttonEl?.scrollHeight || 0) / 2),\n left: elementRect.left + (elementRect.width / 2 - (buttonEl?.scrollWidth || 0) / 2)\n };\n };\n\n const onImageMouseEnter = (e: MouseEvent) => {\n if (!showImagePopover) {\n const el = e.target as HTMLElement;\n setShowEditButton(true);\n setImageEl(el as HTMLImageElement);\n }\n };\n\n const onImageMouseLeave = (e: MouseEvent) => {\n if (e.relatedTarget && (e.relatedTarget as HTMLButtonElement).id !== id && !showImagePopover) {\n setImageEl(null);\n setShowEditButton(false);\n }\n };\n\n const setImageState = () => {\n if (imgEl) {\n let imgHeight;\n let imgWidth;\n let hasHeightOrWidthAttribute = false;\n if (imgEl.getAttribute('height')) {\n imgHeight = parseInt(imgEl.getAttribute('height') as string, 10);\n hasHeightOrWidthAttribute = true;\n } else {\n imgHeight = imgEl.naturalHeight;\n }\n if (imgEl.getAttribute('width')) {\n imgWidth = parseInt(imgEl.getAttribute('width') as string, 10);\n hasHeightOrWidthAttribute = true;\n } else {\n imgWidth = imgEl.naturalWidth;\n }\n setAltText(imgEl.getAttribute('alt') || '');\n setHeight(imgHeight);\n setWidth(imgWidth);\n setAspectRatio(imgWidth / imgHeight);\n setCustomSize(hasHeightOrWidthAttribute);\n }\n };\n\n useOuterEvent('mousedown', [imagePopoverRef], () => {\n setImageState();\n setShowImagePopover(false);\n });\n\n const onCheckBoxClick = (e: ReactMouseEvent) => {\n e.stopPropagation();\n };\n\n const onInputClick = (e: ReactMouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n };\n\n const onInputFocus = (e: FocusEvent) => {\n e.stopPropagation();\n };\n\n const onAltTextChange = (e: ChangeEvent<HTMLInputElement>) => {\n setAltText(e.target.value);\n };\n\n // The next two functions handle changing the height and width of the selected image element.\n // If the value entered is too small, the value will be defaulted.\n // When the height is input, a new width will be calculated and vice versa.\n const onHeightChange = (incomingValue: string) => {\n const inputHeight = parseInt(incomingValue, 10);\n\n setHeight(inputHeight);\n setWidth(inputHeight * aspectRatio);\n };\n\n const onWidthChange = (incomingValue: string) => {\n const inputWidth = parseInt(incomingValue, 10);\n\n setWidth(inputWidth);\n setHeight(inputWidth / aspectRatio);\n };\n\n const onImageChangeSubmit = (e: MouseEvent) => {\n e.preventDefault();\n if (imgEl) {\n if (customSize) {\n if (Number.isNaN(height) || Number.isNaN(width)) {\n imgEl.removeAttribute('height');\n imgEl.removeAttribute('width');\n setHeight(imgEl.naturalHeight);\n setWidth(imgEl.naturalWidth);\n } else {\n imgEl.setAttribute('height', height.toString());\n imgEl.setAttribute('width', width.toString());\n }\n } else {\n imgEl.removeAttribute('height');\n imgEl.removeAttribute('width');\n }\n imgEl.setAttribute('alt', altText);\n }\n\n editor.selection.select(editor.dom.select(`img[src=\"${imgEl?.src}\"]`)[0]);\n setImageEl(null);\n setShowImagePopover(false);\n onChange();\n };\n\n const onImageChangeCancel = () => {\n setImageEl(null);\n setShowImagePopover(false);\n };\n\n const onImageDelete = () => {\n if (imgEl) {\n imgEl.remove();\n }\n setImageEl(null);\n setShowImagePopover(false);\n onChange();\n };\n\n // Keeps the imageElements state up to date with existing and newly added img tags inside of TinyMCE\n useEffect(() => {\n const iframeDoc = editor.getDoc();\n const imageElements = iframeDoc?.querySelectorAll('img') ?? ([] as HTMLImageElement[]);\n setImageElements(() => {\n return [...imageElements];\n });\n const observer = new MutationObserver(mutations => {\n mutations.forEach(mutation => {\n if (\n mutation.type === 'childList' &&\n (mutation.addedNodes.length || mutation.removedNodes.length)\n ) {\n const newImageElements = iframeDoc?.querySelectorAll('img') ?? ([] as HTMLImageElement[]);\n setImageElements(() => [...newImageElements]);\n }\n });\n });\n if (iframeDoc) {\n observer.observe(iframeDoc.body, { childList: true, subtree: true });\n }\n return () => {\n observer.disconnect();\n };\n }, [editorEl, editor, setImageElements]);\n\n // Adds event listeners to HTML img elements inside of TinyMCE\n // This has to be done because there are no react components for these images\n useEffect(() => {\n imgElements.forEach(imgElement => {\n imgElement.addEventListener('mouseenter', onImageMouseEnter);\n imgElement.addEventListener('mouseout', onImageMouseLeave);\n imgElement.addEventListener('click', onImageClick);\n });\n return () => {\n imgElements.forEach(imgElement => {\n imgElement.removeEventListener('mouseenter', onImageMouseEnter);\n imgElement.removeEventListener('mouseout', onImageMouseLeave);\n imgElement.removeEventListener('click', onImageClick);\n });\n };\n }, [imgElements, onImageMouseEnter, onImageMouseLeave, onImageClick]);\n\n useEffect(() => {\n setImageState();\n imgEl?.setAttribute('class', imgHoverClass);\n if (imgEl && imgEl.clientHeight > 36 && imgEl.clientWidth > 36) {\n setCanShowEditButton(true);\n } else {\n setCanShowEditButton(false);\n }\n return () => {\n imgEl?.removeAttribute('class');\n };\n }, [imgEl]);\n\n useEffect(() => {\n const onKeyUp = () => {\n const selection = editor.selection.getSel();\n let nextToImg = false;\n // If your selection is next to an image on it's own line (not breaking text)\n if (\n selection &&\n selection.anchorNode?.childNodes.length === 1 &&\n selection.anchorNode?.firstChild?.nodeName === 'IMG' &&\n selection.anchorOffset === 0\n ) {\n setImageEl(selection.anchorNode.firstChild as HTMLImageElement);\n setShowEditButton(true);\n nextToImg = true;\n // If your selection is next to an image that breaks text up inside of a paragraph\n } else if (selection && selection.anchorNode?.nextSibling?.nodeName === 'IMG') {\n setImageEl(selection.anchorNode.nextSibling as HTMLImageElement);\n setShowEditButton(true);\n nextToImg = true;\n } else if (selection && imgEl && showEditButton) {\n setImageEl(null);\n setShowEditButton(false);\n setKeyCommandText('');\n }\n\n if (nextToImg) {\n setKeyCommandText(t('rte_image_key_command'));\n }\n };\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Enter' && showEditButton) {\n e.stopPropagation();\n e.preventDefault();\n editorOpenedWithEnter.current = true;\n setShowImagePopover(true);\n } else if (e.key === 'Del' && showEditButton) {\n onImageDelete();\n }\n };\n editor.on('keyup', onKeyUp);\n editor.on('keydown', onKeyDown, true);\n return () => {\n editor.off('keyup', onKeyUp);\n editor.off('keydown', onKeyDown);\n };\n }, [editor, imgEl, showEditButton]);\n\n useAfterInitialEffect(() => {\n if (showImagePopover) {\n editor.selection.getSel()?.collapseToEnd();\n\n if (editorOpenedWithEnter.current) {\n altTextInputRef.current?.focus();\n editorOpenedWithEnter.current = false;\n }\n } else {\n editor.focus();\n }\n }, [showImagePopover]);\n\n useLayoutEffect(() => {\n if (imgEl && buttonEl) {\n setBtnStyle(calculateBtnStyles(imgEl));\n }\n }, [imgEl, buttonEl]);\n\n return (\n <>\n {showEditButton && imgEl && canShowEditButton && (\n <Button\n id={id}\n icon\n variant='primary'\n ref={setButtonEl}\n onClick={() => setShowImagePopover(true)}\n style={{ ...btnStyle }}\n >\n <Icon name='pencil-solid' as={IgnoreMouseEventsIcon} />\n </Button>\n )}\n <VisuallyHiddenText aria-live='polite'>{keyCommandText}</VisuallyHiddenText>\n {showImagePopover && (buttonEl || !canShowEditButton) && imgEl && (\n <Popover\n target={canShowEditButton ? buttonEl : imgEl}\n strategy='fixed'\n arrow\n ref={imagePopoverRef}\n onClick={(e: MouseEvent) => e.stopPropagation()}\n >\n <CardHeader\n actions={\n <Button variant='simple' icon onClick={onImageChangeCancel} label={t('close')}>\n <Icon name='times' />\n </Button>\n }\n >\n <Text variant='h3'>{t('rte_image_settings')}</Text>\n </CardHeader>\n <CardContent>\n <Form\n as='div'\n actions={\n <Flex container={{ justify: 'between' }} item={{ grow: 1 }}>\n <Flex item={{ grow: 1 }}>\n <Button onClick={onImageChangeCancel}>{t('cancel')}</Button>\n <Button onClick={onImageDelete}>{t('delete')}</Button>\n </Flex>\n <Button variant='primary' onClick={onImageChangeSubmit}>\n {t('submit')}\n </Button>\n </Flex>\n }\n >\n <Grid\n container={{\n gap: 2,\n areas: customSize\n ? '\"desc desc\" \"radio radio\" \"width height\"'\n : '\"desc desc\" \"radio radio\"'\n }}\n >\n <Grid item={{ area: 'desc' }}>\n <Input\n label={t('description')}\n value={altText}\n onClick={onInputClick}\n onChange={onAltTextChange}\n onFocus={onInputFocus}\n info={t('rte_image_description_info')}\n ref={altTextInputRef}\n />\n </Grid>\n <Grid item={{ area: 'radio' }}>\n <Checkbox\n checked={customSize}\n label={t('rte_image_custom_size')}\n onClick={onCheckBoxClick}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n setCustomSize(e.target.checked);\n }}\n />\n </Grid>\n {customSize && (\n <>\n <Grid item={{ area: 'width' }}>\n <NumberInput\n label={t('rte_width_in_pixels')}\n value={Math.floor(Math.max(width, 1)).toString()}\n onClick={onInputClick}\n onChange={onWidthChange}\n />\n </Grid>\n <Grid item={{ area: 'height' }}>\n <NumberInput\n label={t('rte_height_in_pixels')}\n value={Math.floor(Math.max(height, 1)).toString()}\n onClick={onInputClick}\n onChange={onHeightChange}\n />\n </Grid>\n </>\n )}\n </Grid>\n </Form>\n </CardContent>\n </Popover>\n )}\n </>\n );\n};\n\nexport default ImageEditor;\n"]}
|
|
@@ -45,6 +45,11 @@ const StyledRichTextEditor = styled.div(({ toolbar, theme, focused }) => {
|
|
|
45
45
|
width: 100%;
|
|
46
46
|
position: relative;
|
|
47
47
|
|
|
48
|
+
/* Override default styling of slate placeholder. */
|
|
49
|
+
span[contenteditable='false'] {
|
|
50
|
+
opacity: ${theme.base.transparency['transparent-3']} !important;
|
|
51
|
+
}
|
|
52
|
+
|
|
48
53
|
${focused &&
|
|
49
54
|
css `
|
|
50
55
|
&:not([disabled]) {
|
|
@@ -52,11 +57,6 @@ const StyledRichTextEditor = styled.div(({ toolbar, theme, focused }) => {
|
|
|
52
57
|
box-shadow: ${theme.components['form-control'][':focus']['box-shadow']};
|
|
53
58
|
}
|
|
54
59
|
`}
|
|
55
|
-
|
|
56
|
-
/* Override default styling of slate placeholder. */
|
|
57
|
-
span[contenteditable='false'] {
|
|
58
|
-
opacity: ${theme.base.transparency['transparent-3']} !important;
|
|
59
|
-
}
|
|
60
60
|
`;
|
|
61
61
|
});
|
|
62
62
|
StyledRichTextEditor.defaultProps = defaultThemeProp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.styles.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,kDAAkD,CAAC;AAW9E,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAC7C,CAAC,EAAE,eAAe,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE;IAChD,OAAO,GAAG,CAAA;QACN,OAAO,eAAe,KAAK,QAAQ;QACrC,GAAG,CAAA;kBACS,eAAe;OAC1B;;QAEC,OAAO,eAAe,KAAK,QAAQ;QACrC,GAAG,CAAA;UACC,eAAe,CAAC,GAAG;YACrB,GAAG,CAAA;wBACa,eAAe,CAAC,GAAG;SAClC;;UAEC,eAAe,CAAC,GAAG;YACrB,GAAG,CAAA;wBACa,eAAe,CAAC,GAAG;SAClC;OACF;;QAEC,CAAC,QAAQ,IAAI,OAAO,CAAC;QACvB,GAAG,CAAA;mBACU,KAAK,CAAC,IAAI,CAAC,OAAO;OAC9B;;QAEC,eAAe;QACjB,GAAG,CAAA;;OAEF;;;;;;QAMC,UAAU;KACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,qBAAqB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEtD,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CACrC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;IAC9B,OAAO,GAAG,CAAA;0BACY,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,aAAa
|
|
1
|
+
{"version":3,"file":"RichTextEditor.styles.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,kDAAkD,CAAC;AAW9E,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAC7C,CAAC,EAAE,eAAe,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE;IAChD,OAAO,GAAG,CAAA;QACN,OAAO,eAAe,KAAK,QAAQ;QACrC,GAAG,CAAA;kBACS,eAAe;OAC1B;;QAEC,OAAO,eAAe,KAAK,QAAQ;QACrC,GAAG,CAAA;UACC,eAAe,CAAC,GAAG;YACrB,GAAG,CAAA;wBACa,eAAe,CAAC,GAAG;SAClC;;UAEC,eAAe,CAAC,GAAG;YACrB,GAAG,CAAA;wBACa,eAAe,CAAC,GAAG;SAClC;OACF;;QAEC,CAAC,QAAQ,IAAI,OAAO,CAAC;QACvB,GAAG,CAAA;mBACU,KAAK,CAAC,IAAI,CAAC,OAAO;OAC9B;;QAEC,eAAe;QACjB,GAAG,CAAA;;OAEF;;;;;;QAMC,UAAU;KACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,qBAAqB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEtD,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CACrC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;IAC9B,OAAO,GAAG,CAAA;0BACY,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,aAAa;;;;;;mBAMzE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC;;;QAGnD,OAAO;QACT,GAAG,CAAA;;0BAEiB,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC;wBAC5D,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC;;OAEzE;KACF,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAA4B,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;IAC3F,OAAO,GAAG,CAAA;MACN,oBAAoB;QAClB,CAAC,OAAO;QACV,GAAG,CAAA;;;OAGF;;GAEJ,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;IAK1C,UAAU;;;;;;;CAOb,CAAC;AAEF,eAAe,oBAAoB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport { defaultThemeProp, StyledLink } from '@pega/cosmos-react-core';\nimport { listStyles } from '@pega/cosmos-react-core/lib/components/HTML/HTML';\n\nimport { RichTextEditorProps } from './RichTextEditor.types';\n\ninterface StyledRichTextEditorProps {\n toolbar?: boolean;\n focused?: boolean;\n readOnly?: boolean;\n containerHeight?: RichTextEditorProps['height'];\n}\n\nexport const StyledEditorContainer = styled.div<StyledRichTextEditorProps>(\n ({ containerHeight, readOnly, toolbar, theme }) => {\n return css`\n ${typeof containerHeight === 'string' &&\n css`\n height: ${containerHeight};\n `}\n\n ${typeof containerHeight === 'object' &&\n css`\n ${containerHeight.min &&\n css`\n min-height: ${containerHeight.min};\n `}\n\n ${containerHeight.max &&\n css`\n max-height: ${containerHeight.max};\n `}\n `}\n\n ${(readOnly || toolbar) &&\n css`\n padding: ${theme.base.spacing};\n `}\n\n ${containerHeight &&\n css`\n overflow: auto;\n `}\n\n &:hover {\n cursor: text;\n }\n\n ${listStyles}\n `;\n }\n);\n\nStyledEditorContainer.defaultProps = defaultThemeProp;\n\nconst StyledRichTextEditor = styled.div<StyledRichTextEditorProps>(\n ({ toolbar, theme, focused }) => {\n return css`\n background-color: ${toolbar ? theme.base.palette['primary-background'] : 'transparent'};\n width: 100%;\n position: relative;\n\n /* Override default styling of slate placeholder. */\n span[contenteditable='false'] {\n opacity: ${theme.base.transparency['transparent-3']} !important;\n }\n\n ${focused &&\n css`\n &:not([disabled]) {\n border-color: ${theme.components['form-control'][':focus']['border-color']};\n box-shadow: ${theme.components['form-control'][':focus']['box-shadow']};\n }\n `}\n `;\n }\n);\n\nStyledRichTextEditor.defaultProps = defaultThemeProp;\n\nexport const StyledRichTextFormField = styled.div<StyledRichTextEditorProps>(({ toolbar }) => {\n return css`\n ${StyledRichTextEditor} {\n ${!toolbar &&\n css`\n border: none;\n box-shadow: none;\n `}\n }\n `;\n});\n\nexport const StyledRichTextViewer = styled.div`\n width: 100%;\n position: relative;\n overflow-wrap: break-word;\n\n ${StyledLink} {\n &:enabled:focus,\n &:not([disabled]):focus {\n box-shadow: none;\n text-decoration: underline;\n }\n }\n`;\n\nexport default StyledRichTextEditor;\n"]}
|
|
@@ -42,7 +42,7 @@ export interface RichTextEditorProps extends FormControlProps, BaseProps {
|
|
|
42
42
|
/**
|
|
43
43
|
* A set of custom renderer configurations to convert markdown for search results.
|
|
44
44
|
* @internal
|
|
45
|
-
|
|
45
|
+
*/
|
|
46
46
|
searchRenderers?: InteractionRenderers[];
|
|
47
47
|
/** The menu that will render as a response to a search query. */
|
|
48
48
|
menu?: MenuProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.types.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,WAAW,EAAE,CAAC,SAAS,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3E,oEAAoE;IACpE,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CACxD,CAAC;AACF,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB,EAAE,SAAS;IACtE,gEAAgE;IAChE,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;IACrB,iGAAiG;IACjG,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sEAAsE;IACtE,cAAc,CAAC,EAA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,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kIAAkI;IAClI,MAAM,CAAC,EACH,MAAM,GACN;QACE,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACN,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAC3B,2BAA2B;IAC3B,GAAG,CAAC,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC;CAChC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.types.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref, ComponentType } from 'react';\n\nimport { FormControlProps, MenuProps } from '@pega/cosmos-react-core';\nimport { BaseProps } from '@pega/cosmos-react-core/lib/types';\n\nimport { Features } from './Toolbar/Toolbar.types';\nimport { InteractionRenderers } from './RichTextViewer.types';\n\nexport type RichTextEditorState = {\n focus: () => void;\n getPlainText: () => string;\n getRichText: () => string;\n getHtml: () => string;\n clear: () => void;\n appendImage: (imageData: { src: string; alt: string }, id: string) => void;\n /** This functionality will only work when the editor is focused. */\n insertText: (text: string) => void;\n insertHtml: (html: string, overwrite: boolean) => void;\n};\nexport interface RichTextEditorProps extends FormControlProps, BaseProps {\n /** An array of strings that activate features on the toolbar */\n toolbar?: Features[];\n /** Turning on markdown only turns off the tool bar, any rich text features, and input styling */\n markdownOnly?: boolean;\n /** A set of characters that designate special search capabilities. */\n searchTriggers?: {\n trigger: string;\n regex?: string;\n }[];\n /** Callback triggered on text change following a valid search trigger. */\n onSearch?: (event: { search: string; trigger: string }) => void;\n /** Callback triggered on selection of a search result that returns an object representing the node to replace the search with. */\n getSearchItemReplacement?: (id: string) =>\n | {\n markdown?: string;\n component?: ComponentType<any>;\n props?: Record<string, any>;\n text: string;\n }\n | undefined;\n /**\n * A set of custom renderer configurations to convert markdown for search results.\n * @internal\n
|
|
1
|
+
{"version":3,"file":"RichTextEditor.types.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref, ComponentType } from 'react';\n\nimport { FormControlProps, MenuProps } from '@pega/cosmos-react-core';\nimport { BaseProps } from '@pega/cosmos-react-core/lib/types';\n\nimport { Features } from './Toolbar/Toolbar.types';\nimport { InteractionRenderers } from './RichTextViewer.types';\n\nexport type RichTextEditorState = {\n focus: () => void;\n getPlainText: () => string;\n getRichText: () => string;\n getHtml: () => string;\n clear: () => void;\n appendImage: (imageData: { src: string; alt: string }, id: string) => void;\n /** This functionality will only work when the editor is focused. */\n insertText: (text: string) => void;\n insertHtml: (html: string, overwrite: boolean) => void;\n};\nexport interface RichTextEditorProps extends FormControlProps, BaseProps {\n /** An array of strings that activate features on the toolbar */\n toolbar?: Features[];\n /** Turning on markdown only turns off the tool bar, any rich text features, and input styling */\n markdownOnly?: boolean;\n /** A set of characters that designate special search capabilities. */\n searchTriggers?: {\n trigger: string;\n regex?: string;\n }[];\n /** Callback triggered on text change following a valid search trigger. */\n onSearch?: (event: { search: string; trigger: string }) => void;\n /** Callback triggered on selection of a search result that returns an object representing the node to replace the search with. */\n getSearchItemReplacement?: (id: string) =>\n | {\n markdown?: string;\n component?: ComponentType<any>;\n props?: Record<string, any>;\n text: string;\n }\n | undefined;\n /**\n * A set of custom renderer configurations to convert markdown for search results.\n * @internal\n */\n searchRenderers?: InteractionRenderers[];\n /** The menu that will render as a response to a search query. */\n menu?: MenuProps;\n /** A callback that supplies an object with functions that can manipulate the editor and retrieve it's content/state */\n onChange?: () => void;\n /** A callback that runs if the editor is focused */\n onFocus?: () => void;\n /** A callback that runs if the editor loses focus */\n onBlur?: () => void;\n /** A callback when an image is added through the toolbar image feature */\n onImageAdded?: (image: File, id: string) => void;\n /** Standard placeholder for an input */\n placeholder?: string;\n /** Default value for the RTE - HTML String */\n defaultValue?: string;\n /** Will automatically focus the RTE on render if true */\n autoFocus?: boolean;\n /** Sets the height for the RTE. If no max height is set the RTE will continue to expand, otherwise an overflow will be applied */\n height?:\n | string\n | {\n min?: string;\n max?: string;\n };\n type?: 'html' | 'markdown';\n /** Handle to the state. */\n ref?: Ref<RichTextEditorState>;\n}\n"]}
|
|
@@ -28,9 +28,9 @@ const commands = {
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
checkListEnter: (editor, event) => {
|
|
31
|
-
|
|
32
|
-
Your selection could technically be in multiple list items in the tree because
|
|
33
|
-
the lists can be nested. That is what the mode: 'lowest' arg is for.
|
|
31
|
+
// Gets the list item node at your selection in the lowest part of the tree.
|
|
32
|
+
// Your selection could technically be in multiple list items in the tree because
|
|
33
|
+
// the lists can be nested. That is what the mode: 'lowest' arg is for.
|
|
34
34
|
const [listItemNodeEntry] = Editor.nodes(editor, {
|
|
35
35
|
at: editor.selection?.anchor.path || undefined,
|
|
36
36
|
match: matchListItem,
|
|
@@ -74,8 +74,8 @@ const commands = {
|
|
|
74
74
|
// Remove the list
|
|
75
75
|
Transforms.removeNodes(editor, { at: [...listItemPath, 1] });
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
and insert it into the editor
|
|
77
|
+
// Create a new list item with the copied children as it's children,
|
|
78
|
+
// and insert it into the editor
|
|
79
79
|
Transforms.insertNodes(editor, {
|
|
80
80
|
type: 'list-item',
|
|
81
81
|
order: listItemNode.order ? listItemNode.order + 1 : 0,
|
|
@@ -84,8 +84,8 @@ const commands = {
|
|
|
84
84
|
parentId: parentNode.id,
|
|
85
85
|
children: [{ type: 'paragraph', children: [{ text: '' }] }, ...copiedChildren]
|
|
86
86
|
});
|
|
87
|
-
|
|
88
|
-
into the list item itself rather than it's parent list
|
|
87
|
+
// Nodes needs to be lifted one level higher because it will be inserted
|
|
88
|
+
// into the list item itself rather than it's parent list
|
|
89
89
|
Transforms.liftNodes(editor, {
|
|
90
90
|
match: n => matchListItem(n) && n.id === newId
|
|
91
91
|
});
|
|
@@ -174,9 +174,9 @@ const commands = {
|
|
|
174
174
|
});
|
|
175
175
|
// Gets the path after the last list item in the above sub list
|
|
176
176
|
const nextParentSubListItemPath = Path.next(parentSubListItemPath);
|
|
177
|
-
|
|
178
|
-
in the above sub list, as well as copies of any children the list-item you are
|
|
179
|
-
nesting had.
|
|
177
|
+
// Inserts a copy of the list-item you are nesting below the lowest list item
|
|
178
|
+
// in the above sub list, as well as copies of any children the list-item you are
|
|
179
|
+
// nesting had.
|
|
180
180
|
let subOrderCount = parentSubListItem.order + 1;
|
|
181
181
|
Transforms.insertNodes(editor, [
|
|
182
182
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/ListCommands.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAQ,OAAO,EAAE,IAAI,EAAE,UAAU,EAAgB,IAAI,EAAa,MAAM,OAAO,CAAC;AAE/F,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AASvD,MAAM,SAAS,GAAG,CAAC,CAAO,EAAiC,EAAE,CAC3D,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEtD,MAAM,aAAa,GAAG,CAAC,CAAO,EAAqC,EAAE,CACnE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAEjD,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAE,EAAE;IACtC,IAAI,CAAC,I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C","sourcesContent":["import { KeyboardEvent } from 'react';\nimport { Editor, Node, Element, Path, Transforms, CosmosCustom, Text, NodeEntry } from 'slate';\n\nimport { createUID } from '@pega/cosmos-react-core';\n\nimport { LIST_TYPES, TEXT_TYPES } from './utils.types';\n\ntype FullListItemElement = CosmosCustom.ListItemElement & {\n id: string;\n parentId: string;\n order: number;\n level: number;\n};\n\nconst matchList = (n: Node): n is CosmosCustom.ListElement =>\n Element.isElement(n) && LIST_TYPES.includes(n.type);\n\nconst matchListItem = (n: Node): n is CosmosCustom.ListItemElement =>\n Element.isElement(n) && n.type === 'list-item';\n\nconst getNextPathBelow = (path: Path) => {\n path[path.length - 1] = path[path.length - 1] + 1;\n return path;\n};\n\nconst commands = {\n toggleList: (type: 'unordered-list' | 'ordered-list', editor: Editor) => {\n const [listItemInSelection] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem\n });\n\n if (!listItemInSelection) {\n Transforms.wrapNodes(editor, { type, children: [] });\n Transforms.wrapNodes(editor, {\n type: 'list-item',\n order: 1,\n level: 1,\n id: createUID(),\n children: []\n });\n } else {\n Transforms.setNodes(editor, { type }, { match: matchList });\n }\n },\n checkListEnter: (editor: Editor, event: KeyboardEvent<any>) => {\n /* Gets the list item node at your selection in the lowest part of the tree.\n Your selection could technically be in multiple list items in the tree because\n the lists can be nested. That is what the mode: 'lowest' arg is for. */\n const [listItemNodeEntry] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n\n if (['Backspace', 'Enter'].includes(event.key) && listItemNodeEntry) {\n const [listItemNode, listItemPath] = listItemNodeEntry;\n // Getting the text node\n const [[textNode]] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: Text.isText\n });\n // Getting the parent list-item node\n const [[parentNode]] = Editor.nodes(editor, {\n at: editor.selection || undefined,\n match: matchListItem,\n mode: 'highest'\n });\n\n let belowListItemPath;\n try {\n belowListItemPath = Path.next(listItemPath);\n } catch {\n belowListItemPath = undefined;\n }\n\n if (textNode.text !== '') {\n // If the text node the selection is in is not empty, and the key that was pressed is Enter\n if (event.key === 'Enter') {\n event.preventDefault();\n const newId = createUID();\n const copiedChildren: Element[] = [];\n // If this list-item has another list nested inside of it\n if (listItemNode.children.length === 2) {\n // Copy the list nested inside\n const copiedList = { ...listItemNode.children[1] } as CosmosCustom.ListElement;\n // Add a new parentId to all the children in the list\n copiedList.children = copiedList.children.map(node => {\n return { ...node, parentId: newId };\n });\n copiedChildren.push(copiedList);\n // Remove the list\n Transforms.removeNodes(editor, { at: [...listItemPath, 1] });\n }\n /* Create a new list item with the copied children as it's children,\n and insert it into the editor */\n Transforms.insertNodes(editor, {\n type: 'list-item',\n order: listItemNode.order ? listItemNode.order + 1 : 0,\n level: listItemNode.level ? listItemNode.level : 1,\n id: newId,\n parentId: parentNode.id,\n children: [{ type: 'paragraph', children: [{ text: '' }] }, ...copiedChildren]\n });\n /* Nodes needs to be lifted one level higher because it will be inserted\n into the list item itself rather than it's parent list */\n Transforms.liftNodes<CosmosCustom.ListItemElement>(editor, {\n match: n => matchListItem(n) && n.id === newId\n });\n const selectionPoint = { path: [...Path.next(listItemPath), 0, 0], offset: 0 };\n // Set the selection to the new list item created\n Transforms.setSelection(editor, { focus: selectionPoint, anchor: selectionPoint });\n } else if (editor.selection?.anchor.offset === 0) {\n commands.unNestList(editor);\n }\n } else if (parentNode && parentNode.children.length > 1) {\n // Un nest this list item from it's parent\n event.preventDefault();\n commands.unNestList(editor);\n } else if (belowListItemPath) {\n // Break out of the list\n event.preventDefault();\n Transforms.unwrapNodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem\n });\n Transforms.liftNodes(editor);\n }\n }\n },\n nestList: (editor: Editor) => {\n const [listItemNodeEntry] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n\n let listType: `${'un' | ''}ordered-list` = 'unordered-list';\n const [highestList] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchList,\n mode: 'highest'\n });\n\n if (highestList) {\n listType = highestList[0].type;\n }\n\n const [listItemNode, listItemPath] = (listItemNodeEntry as NodeEntry<FullListItemElement>) || [\n undefined,\n undefined\n ];\n\n // Try to find the path to the node above the selected list item\n let abovePath;\n try {\n abovePath = Path.previous(listItemPath);\n } catch {\n abovePath = undefined;\n }\n\n // Only nest the list if there is a list item above the list item trying to be nested\n if (listItemNode && abovePath && listItemNode.level < 3) {\n // Get the list item and it's path from above the current list item\n const [[aboveListItemNode, aboveListItemPath]] = Editor.nodes<CosmosCustom.ListItemElement>(\n editor,\n {\n at: abovePath,\n match: n => matchListItem(n) && n.level === listItemNode.level\n }\n );\n // Gets the path for the text node above list-item\n const [[, innerTextNodePath]] = Editor.nodes<CosmosCustom.TextElement>(editor, {\n at: abovePath,\n match: n => Element.isElement(n) && TEXT_TYPES.includes(n.type)\n });\n\n let copiedSubListNodes: CosmosCustom.ListItemElement[] = [];\n const newListItemChildren = [listItemNode.children[0]];\n if (listItemNode.children.length && listItemNode.children.length > 1) {\n // Copy the item to be nested's sub list if it has one\n const subList = listItemNode.children[1] as CosmosCustom.ListElement;\n if (subList) {\n copiedSubListNodes = [...subList.children];\n }\n }\n\n // If the above list item has a sub list\n if (aboveListItemNode.children.length > 1) {\n // Get the list items in the sub list of the above list item\n const { children } = aboveListItemNode.children[1] as CosmosCustom.ListElement;\n // Gets the last list item in the above sub list\n const [[parentSubListItem, parentSubListItemPath]] = Editor.nodes<FullListItemElement>(\n editor,\n {\n at: aboveListItemPath,\n match: n =>\n matchListItem(n) &&\n n.order === children.length &&\n (n.level as number) - 1 === listItemNode.level\n }\n );\n\n // Gets the path after the last list item in the above sub list\n const nextParentSubListItemPath = Path.next(parentSubListItemPath);\n\n /* Inserts a copy of the list-item you are nesting below the lowest list item\n in the above sub list, as well as copies of any children the list-item you are\n nesting had. */\n let subOrderCount = parentSubListItem.order + 1;\n Transforms.insertNodes(\n editor,\n [\n {\n ...listItemNode,\n level: listItemNode.level + 1,\n order: parentSubListItem.order + 1,\n parentId: aboveListItemNode.id,\n children: newListItemChildren\n },\n ...copiedSubListNodes.map(n => {\n subOrderCount += 1;\n return {\n ...n,\n level: listItemNode.level + 1,\n order: subOrderCount,\n parentId: aboveListItemNode.id\n };\n })\n ],\n { at: nextParentSubListItemPath }\n );\n } else {\n const nextInnerTextNodePath = getNextPathBelow(innerTextNodePath);\n // Nest the selected list item into a new list and then into the above list item\n let subOrderCount = 1;\n Transforms.insertNodes(\n editor,\n {\n type: listType,\n children: [\n {\n ...listItemNode,\n order: 1,\n level: listItemNode.level + 1,\n parentId: aboveListItemNode.id,\n children: newListItemChildren\n },\n ...copiedSubListNodes.map(n => {\n subOrderCount += 1;\n return {\n ...n,\n level: listItemNode.level + 1,\n order: subOrderCount,\n parentId: aboveListItemNode.id\n };\n })\n ]\n },\n { at: nextInnerTextNodePath, mode: 'lowest' }\n );\n }\n\n // Remove the old list item as we just copied it into the correct place\n Transforms.removeNodes(editor, { at: listItemPath });\n }\n },\n unNestList: (editor: Editor) => {\n // Get the current node to be un nested\n const [[node, nodePath]] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n const [singleItemList] = Editor.nodes<CosmosCustom.ListElement>(editor, {\n match: n => matchList(n) && n.children.length === 1,\n mode: 'highest'\n });\n\n if (singleItemList) {\n Transforms.unwrapNodes(editor, { match: matchListItem });\n Transforms.unwrapNodes(editor, { match: matchList });\n return;\n }\n // Attempt to get the highest parent in the nested list if it exists\n const [highestParent] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection || undefined,\n match: n => matchListItem(n) && node.level - (n.level as number) === 2,\n mode: 'lowest'\n });\n // Get the parent list node if it exists (list item)\n const [[parentNode]] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection || undefined,\n match: n => matchListItem(n) && node.level - (n.level as number) === 1,\n mode: 'lowest'\n });\n // Get the parent list\n const [[parentList]] = Editor.nodes(editor, {\n at: editor.selection || undefined,\n match: matchList,\n mode: 'lowest'\n });\n if (parentNode && parentNode.children.length > 1) {\n let newParentId;\n if (highestParent) {\n const [highestParentNode] = highestParent;\n newParentId = highestParentNode.id;\n }\n\n // Setting the node to un nests new order and level\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n {\n level: node.level - 1,\n order: parentNode.order + 1\n },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n\n // Set the level of any children under the node we are un nesting\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n { level: node.level },\n {\n at: nodePath,\n match: n => matchListItem(n) && (n.level as number) > node.level\n }\n );\n\n // If there's a new parent id set it, otherwise unset the parent id entirely\n if (newParentId) {\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n { parentId: newParentId },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n } else {\n Transforms.unsetNodes<CosmosCustom.ListItemElement>(editor, 'parentId', {\n at: nodePath,\n match: n => matchListItem(n) && n.id === node.id\n });\n }\n\n const listItemsExistBelow = node.order < parentList.children.length;\n\n if (listItemsExistBelow) {\n // Getting the inner text node inside of the list item in order to get the next path\n const [[, innerTextNodePath]] = Editor.nodes(editor, {\n at: nodePath,\n match: matchList\n });\n const nextPath = Path.next(innerTextNodePath);\n const copiedChildren = [];\n\n let count = 1;\n // Copy the children from the parent list that are below the list item we are un nesting\n for (let i = node.order; i < parentList.children.length; i += 1) {\n copiedChildren.push({\n ...parentList.children[i],\n parentId: node.id,\n order: count\n });\n count += 1;\n }\n\n // Insert a new list with the copied children into the un nested list item\n Transforms.insertNodes(\n editor,\n {\n type: parentList.type,\n children: [...copiedChildren]\n },\n { at: nextPath }\n );\n\n const [[newParentList, newParentListPath]] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchList,\n mode: 'lowest'\n });\n\n let order = 0;\n // Set the nodes below the list item being un nested\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n {\n parentId: node.id,\n order\n },\n {\n match: n => {\n if (!matchListItem(n)) return false;\n\n if (n.parentId === node.id) order += 1;\n return n.parentId === node.id;\n }\n }\n );\n\n // Removing all old nodes from that were under the un nested item\n for (let i = newParentList.children.length - 1; i >= node.order; i -= 1) {\n const childPath = [...newParentListPath, i];\n Transforms.removeNodes(editor, { at: childPath, match: matchListItem });\n }\n }\n\n // Lift the current node at the users selection out of it's parent node twice\n Transforms.liftNodes(editor, { match: matchListItem });\n Transforms.liftNodes(editor, { match: matchListItem });\n }\n }\n};\n\nexport default commands;\n"]}
|
|
1
|
+
{"version":3,"file":"ListCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/ListCommands.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAQ,OAAO,EAAE,IAAI,EAAE,UAAU,EAAgB,IAAI,EAAa,MAAM,OAAO,CAAC;AAE/F,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AASvD,MAAM,SAAS,GAAG,CAAC,CAAO,EAAiC,EAAE,CAC3D,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEtD,MAAM,aAAa,GAAG,CAAC,CAAO,EAAqC,EAAE,CACnE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAEjD,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAE,EAAE;IACtC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAClD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,QAAQ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NodeEntry } from 'slate';\n\nimport { createUID } from '@pega/cosmos-react-core';\n\nimport { LIST_TYPES, TEXT_TYPES } from './utils.types';\n\ntype FullListItemElement = CosmosCustom.ListItemElement & {\n id: string;\n parentId: string;\n order: number;\n level: number;\n};\n\nconst matchList = (n: Node): n is CosmosCustom.ListElement =>\n Element.isElement(n) && LIST_TYPES.includes(n.type);\n\nconst matchListItem = (n: Node): n is CosmosCustom.ListItemElement =>\n Element.isElement(n) && n.type === 'list-item';\n\nconst getNextPathBelow = (path: Path) => {\n path[path.length - 1] = path[path.length - 1] + 1;\n return path;\n};\n\nconst commands = {\n toggleList: (type: 'unordered-list' | 'ordered-list', editor: Editor) => {\n const [listItemInSelection] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem\n });\n\n if (!listItemInSelection) {\n Transforms.wrapNodes(editor, { type, children: [] });\n Transforms.wrapNodes(editor, {\n type: 'list-item',\n order: 1,\n level: 1,\n id: createUID(),\n children: []\n });\n } else {\n Transforms.setNodes(editor, { type }, { match: matchList });\n }\n },\n checkListEnter: (editor: Editor, event: KeyboardEvent<any>) => {\n // Gets the list item node at your selection in the lowest part of the tree.\n // Your selection could technically be in multiple list items in the tree because\n // the lists can be nested. That is what the mode: 'lowest' arg is for.\n const [listItemNodeEntry] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n\n if (['Backspace', 'Enter'].includes(event.key) && listItemNodeEntry) {\n const [listItemNode, listItemPath] = listItemNodeEntry;\n // Getting the text node\n const [[textNode]] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: Text.isText\n });\n // Getting the parent list-item node\n const [[parentNode]] = Editor.nodes(editor, {\n at: editor.selection || undefined,\n match: matchListItem,\n mode: 'highest'\n });\n\n let belowListItemPath;\n try {\n belowListItemPath = Path.next(listItemPath);\n } catch {\n belowListItemPath = undefined;\n }\n\n if (textNode.text !== '') {\n // If the text node the selection is in is not empty, and the key that was pressed is Enter\n if (event.key === 'Enter') {\n event.preventDefault();\n const newId = createUID();\n const copiedChildren: Element[] = [];\n // If this list-item has another list nested inside of it\n if (listItemNode.children.length === 2) {\n // Copy the list nested inside\n const copiedList = { ...listItemNode.children[1] } as CosmosCustom.ListElement;\n // Add a new parentId to all the children in the list\n copiedList.children = copiedList.children.map(node => {\n return { ...node, parentId: newId };\n });\n copiedChildren.push(copiedList);\n // Remove the list\n Transforms.removeNodes(editor, { at: [...listItemPath, 1] });\n }\n // Create a new list item with the copied children as it's children,\n // and insert it into the editor\n Transforms.insertNodes(editor, {\n type: 'list-item',\n order: listItemNode.order ? listItemNode.order + 1 : 0,\n level: listItemNode.level ? listItemNode.level : 1,\n id: newId,\n parentId: parentNode.id,\n children: [{ type: 'paragraph', children: [{ text: '' }] }, ...copiedChildren]\n });\n // Nodes needs to be lifted one level higher because it will be inserted\n // into the list item itself rather than it's parent list\n Transforms.liftNodes<CosmosCustom.ListItemElement>(editor, {\n match: n => matchListItem(n) && n.id === newId\n });\n const selectionPoint = { path: [...Path.next(listItemPath), 0, 0], offset: 0 };\n // Set the selection to the new list item created\n Transforms.setSelection(editor, { focus: selectionPoint, anchor: selectionPoint });\n } else if (editor.selection?.anchor.offset === 0) {\n commands.unNestList(editor);\n }\n } else if (parentNode && parentNode.children.length > 1) {\n // Un nest this list item from it's parent\n event.preventDefault();\n commands.unNestList(editor);\n } else if (belowListItemPath) {\n // Break out of the list\n event.preventDefault();\n Transforms.unwrapNodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem\n });\n Transforms.liftNodes(editor);\n }\n }\n },\n nestList: (editor: Editor) => {\n const [listItemNodeEntry] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n\n let listType: `${'un' | ''}ordered-list` = 'unordered-list';\n const [highestList] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchList,\n mode: 'highest'\n });\n\n if (highestList) {\n listType = highestList[0].type;\n }\n\n const [listItemNode, listItemPath] = (listItemNodeEntry as NodeEntry<FullListItemElement>) || [\n undefined,\n undefined\n ];\n\n // Try to find the path to the node above the selected list item\n let abovePath;\n try {\n abovePath = Path.previous(listItemPath);\n } catch {\n abovePath = undefined;\n }\n\n // Only nest the list if there is a list item above the list item trying to be nested\n if (listItemNode && abovePath && listItemNode.level < 3) {\n // Get the list item and it's path from above the current list item\n const [[aboveListItemNode, aboveListItemPath]] = Editor.nodes<CosmosCustom.ListItemElement>(\n editor,\n {\n at: abovePath,\n match: n => matchListItem(n) && n.level === listItemNode.level\n }\n );\n // Gets the path for the text node above list-item\n const [[, innerTextNodePath]] = Editor.nodes<CosmosCustom.TextElement>(editor, {\n at: abovePath,\n match: n => Element.isElement(n) && TEXT_TYPES.includes(n.type)\n });\n\n let copiedSubListNodes: CosmosCustom.ListItemElement[] = [];\n const newListItemChildren = [listItemNode.children[0]];\n if (listItemNode.children.length && listItemNode.children.length > 1) {\n // Copy the item to be nested's sub list if it has one\n const subList = listItemNode.children[1] as CosmosCustom.ListElement;\n if (subList) {\n copiedSubListNodes = [...subList.children];\n }\n }\n\n // If the above list item has a sub list\n if (aboveListItemNode.children.length > 1) {\n // Get the list items in the sub list of the above list item\n const { children } = aboveListItemNode.children[1] as CosmosCustom.ListElement;\n // Gets the last list item in the above sub list\n const [[parentSubListItem, parentSubListItemPath]] = Editor.nodes<FullListItemElement>(\n editor,\n {\n at: aboveListItemPath,\n match: n =>\n matchListItem(n) &&\n n.order === children.length &&\n (n.level as number) - 1 === listItemNode.level\n }\n );\n\n // Gets the path after the last list item in the above sub list\n const nextParentSubListItemPath = Path.next(parentSubListItemPath);\n\n // Inserts a copy of the list-item you are nesting below the lowest list item\n // in the above sub list, as well as copies of any children the list-item you are\n // nesting had.\n let subOrderCount = parentSubListItem.order + 1;\n Transforms.insertNodes(\n editor,\n [\n {\n ...listItemNode,\n level: listItemNode.level + 1,\n order: parentSubListItem.order + 1,\n parentId: aboveListItemNode.id,\n children: newListItemChildren\n },\n ...copiedSubListNodes.map(n => {\n subOrderCount += 1;\n return {\n ...n,\n level: listItemNode.level + 1,\n order: subOrderCount,\n parentId: aboveListItemNode.id\n };\n })\n ],\n { at: nextParentSubListItemPath }\n );\n } else {\n const nextInnerTextNodePath = getNextPathBelow(innerTextNodePath);\n // Nest the selected list item into a new list and then into the above list item\n let subOrderCount = 1;\n Transforms.insertNodes(\n editor,\n {\n type: listType,\n children: [\n {\n ...listItemNode,\n order: 1,\n level: listItemNode.level + 1,\n parentId: aboveListItemNode.id,\n children: newListItemChildren\n },\n ...copiedSubListNodes.map(n => {\n subOrderCount += 1;\n return {\n ...n,\n level: listItemNode.level + 1,\n order: subOrderCount,\n parentId: aboveListItemNode.id\n };\n })\n ]\n },\n { at: nextInnerTextNodePath, mode: 'lowest' }\n );\n }\n\n // Remove the old list item as we just copied it into the correct place\n Transforms.removeNodes(editor, { at: listItemPath });\n }\n },\n unNestList: (editor: Editor) => {\n // Get the current node to be un nested\n const [[node, nodePath]] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n const [singleItemList] = Editor.nodes<CosmosCustom.ListElement>(editor, {\n match: n => matchList(n) && n.children.length === 1,\n mode: 'highest'\n });\n\n if (singleItemList) {\n Transforms.unwrapNodes(editor, { match: matchListItem });\n Transforms.unwrapNodes(editor, { match: matchList });\n return;\n }\n // Attempt to get the highest parent in the nested list if it exists\n const [highestParent] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection || undefined,\n match: n => matchListItem(n) && node.level - (n.level as number) === 2,\n mode: 'lowest'\n });\n // Get the parent list node if it exists (list item)\n const [[parentNode]] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection || undefined,\n match: n => matchListItem(n) && node.level - (n.level as number) === 1,\n mode: 'lowest'\n });\n // Get the parent list\n const [[parentList]] = Editor.nodes(editor, {\n at: editor.selection || undefined,\n match: matchList,\n mode: 'lowest'\n });\n if (parentNode && parentNode.children.length > 1) {\n let newParentId;\n if (highestParent) {\n const [highestParentNode] = highestParent;\n newParentId = highestParentNode.id;\n }\n\n // Setting the node to un nests new order and level\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n {\n level: node.level - 1,\n order: parentNode.order + 1\n },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n\n // Set the level of any children under the node we are un nesting\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n { level: node.level },\n {\n at: nodePath,\n match: n => matchListItem(n) && (n.level as number) > node.level\n }\n );\n\n // If there's a new parent id set it, otherwise unset the parent id entirely\n if (newParentId) {\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n { parentId: newParentId },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n } else {\n Transforms.unsetNodes<CosmosCustom.ListItemElement>(editor, 'parentId', {\n at: nodePath,\n match: n => matchListItem(n) && n.id === node.id\n });\n }\n\n const listItemsExistBelow = node.order < parentList.children.length;\n\n if (listItemsExistBelow) {\n // Getting the inner text node inside of the list item in order to get the next path\n const [[, innerTextNodePath]] = Editor.nodes(editor, {\n at: nodePath,\n match: matchList\n });\n const nextPath = Path.next(innerTextNodePath);\n const copiedChildren = [];\n\n let count = 1;\n // Copy the children from the parent list that are below the list item we are un nesting\n for (let i = node.order; i < parentList.children.length; i += 1) {\n copiedChildren.push({\n ...parentList.children[i],\n parentId: node.id,\n order: count\n });\n count += 1;\n }\n\n // Insert a new list with the copied children into the un nested list item\n Transforms.insertNodes(\n editor,\n {\n type: parentList.type,\n children: [...copiedChildren]\n },\n { at: nextPath }\n );\n\n const [[newParentList, newParentListPath]] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchList,\n mode: 'lowest'\n });\n\n let order = 0;\n // Set the nodes below the list item being un nested\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n {\n parentId: node.id,\n order\n },\n {\n match: n => {\n if (!matchListItem(n)) return false;\n\n if (n.parentId === node.id) order += 1;\n return n.parentId === node.id;\n }\n }\n );\n\n // Removing all old nodes from that were under the un nested item\n for (let i = newParentList.children.length - 1; i >= node.order; i -= 1) {\n const childPath = [...newParentListPath, i];\n Transforms.removeNodes(editor, { at: childPath, match: matchListItem });\n }\n }\n\n // Lift the current node at the users selection out of it's parent node twice\n Transforms.liftNodes(editor, { match: matchListItem });\n Transforms.liftNodes(editor, { match: matchListItem });\n }\n }\n};\n\nexport default commands;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlConverter.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/htmlConverter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAY9D,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;CAkBjB,CAAC;AAGX,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;
|
|
1
|
+
{"version":3,"file":"htmlConverter.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/htmlConverter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAY9D,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;CAkBjB,CAAC;AAGX,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AA8IX,eAAO,MAAM,WAAW,SAChB,MAAM,yBACW,mBAAmB,CAAC,sBAAsB,CAAC,KACjE,CAAC,aAAa,GAAG,UAAU,CAAC,EAe9B,CAAC"}
|
|
@@ -93,10 +93,8 @@ const getSlateNode = (node, parentNode, interactionRenderers) => {
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
const type = htmlToSlateMap[node.nodeName];
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
that it needs to collapse the next node, also we are setting the correct style mark to true
|
|
99
|
-
*/
|
|
96
|
+
// If the type of the HTML tag is an inline (b, i, del, a) we want to let the recursive function know
|
|
97
|
+
// that it needs to collapse the next node, also we are setting the correct style mark to true
|
|
100
98
|
if (type === 'skip') {
|
|
101
99
|
const style = inlineHtmlToStyleMap[node.nodeName];
|
|
102
100
|
let value = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/htmlConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAO/B,OAAO,2BAA2B,MAAM,uBAAuB,CAAC;AAEhE,MAAM,YAAY,GAAG,CAAC,IAAkC,EAA0B,EAAE,CAClF,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,IAAI,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC;AACtE,MAAM,aAAa,GAAG,CAAC,IAAkC,EAA2B,EAAE,CACpF,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,CAAC;AACtC,MAAM,YAAY,GAAG,CAAC,IAAkC,EAA2B,EAAE,CACnF,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC;AAEzC,iHAAiH;AACjH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,gBAAgB;IACpB,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,WAAW;IACf,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,YAAY;IAChB,KAAK,EAAE,YAAY;IACnB,CAAC,EAAE,WAAW;IACd,GAAG,EAAE,OAAO;IACZ,CAAC,EA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E,OAAO,YAAY,CAAC;QAE7C,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC;KAClC;IACD,OAAO,YAAY,CAAC,cAAc,EAAE,SAAS,EAAE,oBAAoB,CAAC,CAAC;AACvE,CAAC,CAAC","sourcesContent":["import { parse } from 'parse5';\n// Use namespaced types to more easily differentiate between similar types (ie, ChildNode from parse5 and Node from slate).\nimport type * as parse5 from 'parse5';\nimport type * as slate from 'slate';\n\nimport { RichTextViewerProps } from '../RichTextViewer.types';\n\nimport parseTextToCustomSlateNodes from './interactionRenderer';\n\nconst checkElement = (node: parse5.ChildNode | undefined): node is parse5.Element =>\n !!node && node.nodeName !== '#text' && node.nodeName !== '#comment';\nconst checkTextNode = (node: parse5.ChildNode | undefined): node is parse5.TextNode =>\n !!node && node.nodeName === '#text';\nconst checkComment = (node: parse5.ChildNode | undefined): node is parse5.TextNode =>\n !!node && node.nodeName === '#comment';\n\n// Mapping of HTML tags to slate types. b, del, i, and a tags are labeled as skip because they need special logic\nexport const htmlToSlateMap = {\n h1: 'heading-1',\n h2: 'heading-2',\n h3: 'heading-3',\n h4: 'heading-4',\n ul: 'unordered-list',\n ol: 'ordered-list',\n li: 'list-item',\n table: 'table',\n tr: 'table-row',\n td: 'table-cell',\n tbody: 'table-body',\n p: 'paragraph',\n img: 'image',\n b: 'skip',\n del: 'skip',\n i: 'skip',\n a: 'skip'\n} as const;\n\n// Inline HTML tags to slate types\nexport const inlineHtmlToStyleMap = {\n b: 'bold',\n del: 'line-through',\n i: 'italic',\n a: 'href'\n} as const;\n\n// Maps HTML Attributes to an object. Right now this is specifically used for list items.\n\ninterface InlineParentNodes extends slate.CosmosCustom.CustomElement {\n href?: string;\n italic?: boolean;\n bold?: boolean;\n text?: string;\n}\n\nconst getAttributes = (node: parse5.ChildNode) => {\n if (checkElement(node) && node.attrs.length) {\n switch (node.nodeName) {\n case 'li':\n return Object.fromEntries(\n node.attrs.flatMap(attr => {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (attr.name) {\n case 'data-id':\n return [['id', attr.value]];\n case 'data-parent-id':\n return [['parentId', attr.value]];\n case 'data-level':\n return [['level', attr.value]];\n case 'data-order':\n return [['order', attr.value]];\n default:\n return [];\n }\n })\n );\n case 'img': {\n const imgAttrs = ['src', 'alt'];\n const attrsObj: { [key: string]: string } = {};\n for (let i = 0; i < node.attrs.length; i += 1) {\n const { name, value } = node.attrs[i];\n if (imgAttrs.includes(name)) {\n attrsObj[name] = value;\n }\n }\n return attrsObj;\n }\n default:\n return {};\n }\n }\n return {};\n};\n\nconst getSlateNode = (\n node: parse5.ChildNode,\n parentNode?: slate.Element | slate.Text,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): { node: slate.Element | slate.Text; collapseNext?: boolean } => {\n if (checkTextNode(node)) {\n if (node.parentNode.nodeName === 'body') {\n return {\n node: {\n type: 'paragraph',\n children: [{ text: node.value }]\n }\n };\n }\n // Make sure to spread any parent style attributes for slates text nodes\n const children = parseTextToCustomSlateNodes(\n node.value,\n interactionRenderers\n ) as slate.CosmosCustom.CustomElement[];\n if (children.length === 1) {\n const tempParentNode = parentNode as InlineParentNodes;\n if (children[0]?.type === 'custom') {\n delete tempParentNode?.text;\n }\n\n return { node: { ...tempParentNode, ...children[0] } as slate.Text };\n }\n return {\n node: {\n ...parentNode,\n children\n } as slate.Element\n };\n }\n\n const type = htmlToSlateMap[node.nodeName as keyof typeof htmlToSlateMap];\n /*\n If the type of the HTML tag is an inline (b, i, del, a) we want to let the recursive function know\n that it needs to collapse the next node, also we are setting the correct style mark to true\n */\n if (type === 'skip') {\n const style = inlineHtmlToStyleMap[node.nodeName as 'b' | 'i' | 'del' | 'a'];\n let value: string | boolean = true;\n if (node.nodeName === 'a') {\n const hrefObj = node.attrs?.find(attr => attr.name === 'href');\n value = hrefObj ? hrefObj.value : value;\n }\n return {\n node: { ...parentNode, [style]: value, text: '' } as slate.Text,\n collapseNext: true\n };\n }\n\n const attributes = getAttributes(node);\n const nodeObj = {\n type: type || 'paragraph',\n ...attributes,\n children: [{ text: '' }]\n } as slate.Element;\n return { node: nodeObj };\n};\n\n// Recursive function that will convert Parse5Nodes into Slate compatible nodes\nconst convertNodes = (\n nodes: parse5.ChildNode[],\n parentNode?: slate.Element | slate.Text,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): (slate.Element | slate.Text)[] => {\n const returnNodes: (slate.Element | slate.Text)[] = [];\n nodes.forEach(node => {\n const { node: slateNode, collapseNext } = getSlateNode(node, parentNode, interactionRenderers);\n if (!checkComment(node)) {\n let returnNode = slateNode;\n if (checkElement(node) && node.childNodes && node.childNodes.length) {\n if (collapseNext) {\n returnNode = convertNodes(node.childNodes, slateNode, interactionRenderers)[0];\n } else {\n (slateNode as slate.Element).children = convertNodes(\n node.childNodes,\n undefined,\n interactionRenderers\n );\n returnNode = slateNode;\n }\n }\n\n returnNodes.push(returnNode);\n }\n });\n return returnNodes;\n};\n\nconst defaultValue = [{ type: 'paragraph', children: [{ text: '' }] } as slate.Element];\n\nexport const convertHtml = (\n html: string,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): (slate.Element | slate.Text)[] => {\n // Wrap the html in another body in case the value given has no body\n const doc = parse(`<body>${html.replace('\\n', '')}</body>`);\n let nodesToConvert = doc.childNodes;\n // If we have a root tag\n if (doc.childNodes.length === 1) {\n const root = doc.childNodes[0];\n if (!checkElement(root)) return defaultValue;\n\n const body = root.childNodes[1];\n if (!checkElement(body)) return defaultValue;\n\n nodesToConvert = body.childNodes;\n }\n return convertNodes(nodesToConvert, undefined, interactionRenderers);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"htmlConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/htmlConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAO/B,OAAO,2BAA2B,MAAM,uBAAuB,CAAC;AAEhE,MAAM,YAAY,GAAG,CAAC,IAAkC,EAA0B,EAAE,CAClF,CAAC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rB,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAmB,CAAC,CAAC;AAExF,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,IAAY,EACZ,oBAAkE,EAClC,EAAE;IAClC,oEAAoE;IACpE,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;IAC5D,IAAI,cAAc,GAAG,GAAG,CAAC,UAAU,CAAC;IACpC,wBAAwB;IACxB,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/B,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YAAE,OAAO,YAAY,CAAC;QAE7C,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YAAE,OAAO,YAAY,CAAC;QAE7C,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC;KAClC;IACD,OAAO,YAAY,CAAC,cAAc,EAAE,SAAS,EAAE,oBAAoB,CAAC,CAAC;AACvE,CAAC,CAAC","sourcesContent":["import { parse } from 'parse5';\n// Use namespaced types to more easily differentiate between similar types (ie, ChildNode from parse5 and Node from slate).\nimport type * as parse5 from 'parse5';\nimport type * as slate from 'slate';\n\nimport { RichTextViewerProps } from '../RichTextViewer.types';\n\nimport parseTextToCustomSlateNodes from './interactionRenderer';\n\nconst checkElement = (node: parse5.ChildNode | undefined): node is parse5.Element =>\n !!node && node.nodeName !== '#text' && node.nodeName !== '#comment';\nconst checkTextNode = (node: parse5.ChildNode | undefined): node is parse5.TextNode =>\n !!node && node.nodeName === '#text';\nconst checkComment = (node: parse5.ChildNode | undefined): node is parse5.TextNode =>\n !!node && node.nodeName === '#comment';\n\n// Mapping of HTML tags to slate types. b, del, i, and a tags are labeled as skip because they need special logic\nexport const htmlToSlateMap = {\n h1: 'heading-1',\n h2: 'heading-2',\n h3: 'heading-3',\n h4: 'heading-4',\n ul: 'unordered-list',\n ol: 'ordered-list',\n li: 'list-item',\n table: 'table',\n tr: 'table-row',\n td: 'table-cell',\n tbody: 'table-body',\n p: 'paragraph',\n img: 'image',\n b: 'skip',\n del: 'skip',\n i: 'skip',\n a: 'skip'\n} as const;\n\n// Inline HTML tags to slate types\nexport const inlineHtmlToStyleMap = {\n b: 'bold',\n del: 'line-through',\n i: 'italic',\n a: 'href'\n} as const;\n\n// Maps HTML Attributes to an object. Right now this is specifically used for list items.\n\ninterface InlineParentNodes extends slate.CosmosCustom.CustomElement {\n href?: string;\n italic?: boolean;\n bold?: boolean;\n text?: string;\n}\n\nconst getAttributes = (node: parse5.ChildNode) => {\n if (checkElement(node) && node.attrs.length) {\n switch (node.nodeName) {\n case 'li':\n return Object.fromEntries(\n node.attrs.flatMap(attr => {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (attr.name) {\n case 'data-id':\n return [['id', attr.value]];\n case 'data-parent-id':\n return [['parentId', attr.value]];\n case 'data-level':\n return [['level', attr.value]];\n case 'data-order':\n return [['order', attr.value]];\n default:\n return [];\n }\n })\n );\n case 'img': {\n const imgAttrs = ['src', 'alt'];\n const attrsObj: { [key: string]: string } = {};\n for (let i = 0; i < node.attrs.length; i += 1) {\n const { name, value } = node.attrs[i];\n if (imgAttrs.includes(name)) {\n attrsObj[name] = value;\n }\n }\n return attrsObj;\n }\n default:\n return {};\n }\n }\n return {};\n};\n\nconst getSlateNode = (\n node: parse5.ChildNode,\n parentNode?: slate.Element | slate.Text,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): { node: slate.Element | slate.Text; collapseNext?: boolean } => {\n if (checkTextNode(node)) {\n if (node.parentNode.nodeName === 'body') {\n return {\n node: {\n type: 'paragraph',\n children: [{ text: node.value }]\n }\n };\n }\n // Make sure to spread any parent style attributes for slates text nodes\n const children = parseTextToCustomSlateNodes(\n node.value,\n interactionRenderers\n ) as slate.CosmosCustom.CustomElement[];\n if (children.length === 1) {\n const tempParentNode = parentNode as InlineParentNodes;\n if (children[0]?.type === 'custom') {\n delete tempParentNode?.text;\n }\n\n return { node: { ...tempParentNode, ...children[0] } as slate.Text };\n }\n return {\n node: {\n ...parentNode,\n children\n } as slate.Element\n };\n }\n\n const type = htmlToSlateMap[node.nodeName as keyof typeof htmlToSlateMap];\n // If the type of the HTML tag is an inline (b, i, del, a) we want to let the recursive function know\n // that it needs to collapse the next node, also we are setting the correct style mark to true\n if (type === 'skip') {\n const style = inlineHtmlToStyleMap[node.nodeName as 'b' | 'i' | 'del' | 'a'];\n let value: string | boolean = true;\n if (node.nodeName === 'a') {\n const hrefObj = node.attrs?.find(attr => attr.name === 'href');\n value = hrefObj ? hrefObj.value : value;\n }\n return {\n node: { ...parentNode, [style]: value, text: '' } as slate.Text,\n collapseNext: true\n };\n }\n\n const attributes = getAttributes(node);\n const nodeObj = {\n type: type || 'paragraph',\n ...attributes,\n children: [{ text: '' }]\n } as slate.Element;\n return { node: nodeObj };\n};\n\n// Recursive function that will convert Parse5Nodes into Slate compatible nodes\nconst convertNodes = (\n nodes: parse5.ChildNode[],\n parentNode?: slate.Element | slate.Text,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): (slate.Element | slate.Text)[] => {\n const returnNodes: (slate.Element | slate.Text)[] = [];\n nodes.forEach(node => {\n const { node: slateNode, collapseNext } = getSlateNode(node, parentNode, interactionRenderers);\n if (!checkComment(node)) {\n let returnNode = slateNode;\n if (checkElement(node) && node.childNodes && node.childNodes.length) {\n if (collapseNext) {\n returnNode = convertNodes(node.childNodes, slateNode, interactionRenderers)[0];\n } else {\n (slateNode as slate.Element).children = convertNodes(\n node.childNodes,\n undefined,\n interactionRenderers\n );\n returnNode = slateNode;\n }\n }\n\n returnNodes.push(returnNode);\n }\n });\n return returnNodes;\n};\n\nconst defaultValue = [{ type: 'paragraph', children: [{ text: '' }] } as slate.Element];\n\nexport const convertHtml = (\n html: string,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): (slate.Element | slate.Text)[] => {\n // Wrap the html in another body in case the value given has no body\n const doc = parse(`<body>${html.replace('\\n', '')}</body>`);\n let nodesToConvert = doc.childNodes;\n // If we have a root tag\n if (doc.childNodes.length === 1) {\n const root = doc.childNodes[0];\n if (!checkElement(root)) return defaultValue;\n\n const body = root.childNodes[1];\n if (!checkElement(body)) return defaultValue;\n\n nodesToConvert = body.childNodes;\n }\n return convertNodes(nodesToConvert, undefined, interactionRenderers);\n};\n"]}
|
|
@@ -45,15 +45,15 @@ const parseTextToCustomSlateNodes = (text, renderers) => {
|
|
|
45
45
|
// Use the regex match positions to slice the text into the correct text nodes and other custom nodes
|
|
46
46
|
let lastPos;
|
|
47
47
|
positions.forEach((pos, i) => {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// If the first regex match isn't at the start of the text node,
|
|
49
|
+
// slice the text node up to the first match and insert it into the nodes array
|
|
50
50
|
if (i === 0 && pos.start !== 0) {
|
|
51
51
|
nodes.push({
|
|
52
52
|
text: text.slice(i, pos.start)
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
// If there was a last position, slice the text between the last position
|
|
56
|
+
// and the new position to insert it as a new text node
|
|
57
57
|
if (lastPos && lastPos.end < pos.start) {
|
|
58
58
|
nodes.push({
|
|
59
59
|
text: text.slice(lastPos.end, pos.start)
|
|
@@ -117,8 +117,8 @@ const parseTextToCustomSlateNodes = (text, renderers) => {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
// If we are at the end of the positions array, and there's still text left
|
|
121
|
+
// slice the text and add it as a new text node
|
|
122
122
|
if (i === positions.length - 1 && pos.end < text.length) {
|
|
123
123
|
nodes.push({
|
|
124
124
|
text: text.slice(pos.end, text.length)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactionRenderer.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/interactionRenderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAcvC,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;AAE/B,oEAAoE;AACpE,MAAM,UAAU,GAAG,CAAC,MAAwB,EAAE,EAAE;IAC9C,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,IAAI,GAAG,CAAC;IACR,0CAA0C;IAC1C,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE;QACpD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACxB,YAAY,CAAC,IAAI,CAAC;YAChB,KAAK;YACL,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM;YAC1B,KAAK,EAAE,GAAG;YACV,GAAG,MAAM;SACV,CAAC,CAAC;KACJ;IACD,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAsC,EAAE;IACtF,MAAM,QAAQ,GAAG,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IACpE,IAAI,QAAQ,CAAC,aAAa,CAAC,aAAa,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5D,MAAM,UAAU,GAA2B,EAAE,CAAC;IAE9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QACtE,MAAM,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACzD,IAAI,IAAI,EAAE;YACR,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;SACpC;KACF;IACD,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,wCAAwC;AACxC,MAAM,2BAA2B,GAAG,CAClC,IAAY,EACZ,SAAkC,EACF,EAAE;IAClC,iEAAiE;IACjE,MAAM,SAAS,GACb,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAE1E,uCAAuC;IACvC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QAC1B,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;KACnB;IAED,gEAAgE;IAChE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAE5C,MAAM,KAAK,GAAmC,EAAE,CAAC;IAEjD,qGAAqG;IACrG,IAAI,OAAmB,CAAC;IACxB,SAAS,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QAC3B;
|
|
1
|
+
{"version":3,"file":"interactionRenderer.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/interactionRenderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAcvC,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;AAE/B,oEAAoE;AACpE,MAAM,UAAU,GAAG,CAAC,MAAwB,EAAE,EAAE;IAC9C,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,IAAI,GAAG,CAAC;IACR,0CAA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C,mBAAmB,EAAE;gBAClC,MAAM,YAAY,GAAG,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC3E,IAAI,YAAY,IAAI,YAAY,CAAC,IAAI,EAAE;oBACrC,KAAK,CAAC,IAAI,CAAC;wBACT,IAAI,EAAE,YAAY,CAAC,IAAI;wBACvB,YAAY,EAAE;4BACZ,QAAQ,EAAE,YAAY,CAAC,QAAQ;4BAC/B,SAAS,EAAE,YAAY,CAAC,SAAS;4BACjC,KAAK,EAAE,YAAY,CAAC,KAAK;4BACzB,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;yBACxB;qBACF,CAAC,CAAC;iBACJ;qBAAM;oBACL,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;iBACpC;aACF;SACF;QAED,2EAA2E;QAC3E,+CAA+C;QAC/C,IAAI,CAAC,KAAK,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE;YACvD,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC;aACvC,CAAC,CAAC;SACJ;QACD,OAAO,GAAG,GAAG,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF,eAAe,2BAA2B,CAAC","sourcesContent":["import type * as slate from 'slate';\nimport { TLDs } from 'global-tld-list';\n\nimport { InteractionRenderers } from '../RichTextViewer.types';\n\ninterface RegexMatch extends InteractionRenderers {\n start: number;\n end: number;\n match: RegExpExecArray;\n}\n\ninterface CheckRegexParams extends InteractionRenderers {\n text: string;\n}\n\nconst parser = new DOMParser();\n\n// Checks a string for regex matches and returns an array of matches\nconst checkRegex = (params: CheckRegexParams) => {\n const regexMatches: RegexMatch[] = [];\n let res;\n // eslint-disable-next-line no-cond-assign\n while ((res = params.regexPattern.exec(params.text))) {\n const start = res.index;\n regexMatches.push({\n start,\n end: start + res[0].length,\n match: res,\n ...params\n });\n }\n return regexMatches;\n};\n\n// Extracts all properties from an xml element represented as a string\nexport const getXMLAttributes = (element: string): Record<string, string> | undefined => {\n const document = parser.parseFromString(element, 'application/xml');\n if (document.querySelector('parsererror')) return undefined;\n const attributes: Record<string, string> = {};\n\n for (let i = 0; i < document.documentElement.attributes.length; i += 1) {\n const attr = document.documentElement.attributes.item(i);\n if (attr) {\n attributes[attr.name] = attr.value;\n }\n }\n attributes.rawText = element;\n\n return attributes;\n};\n\n// Parses text node to custom slate node\nconst parseTextToCustomSlateNodes = (\n text: string,\n renderers?: InteractionRenderers[]\n): (slate.Element | slate.Text)[] => {\n // Runs through an array of custom renderers and gets the matches\n const positions: RegexMatch[] =\n renderers?.flatMap(renderer => checkRegex({ text, ...renderer })) || [];\n\n // Early exit when no matched positions\n if (positions.length === 0) {\n return [{ text }];\n }\n\n // Sorts the matches based on the start positions of the matches\n positions.sort((a, b) => a.start - b.start);\n\n const nodes: (slate.Element | slate.Text)[] = [];\n\n // Use the regex match positions to slice the text into the correct text nodes and other custom nodes\n let lastPos: RegexMatch;\n positions.forEach((pos, i) => {\n // If the first regex match isn't at the start of the text node,\n // slice the text node up to the first match and insert it into the nodes array\n\n if (i === 0 && pos.start !== 0) {\n nodes.push({\n text: text.slice(i, pos.start)\n });\n }\n\n // If there was a last position, slice the text between the last position\n // and the new position to insert it as a new text node\n if (lastPos && lastPos.end < pos.start) {\n nodes.push({\n text: text.slice(lastPos.end, pos.start)\n });\n } else if (i !== 0) {\n nodes.push({\n text: ' '\n });\n }\n\n if (pos.type === 'builtin-url' && pos.match.groups) {\n const { leadingChar, url } = pos.match.groups;\n\n try {\n // Check for valid URL since the regex isn't exhaustive.\n const { href } = new URL(pos.match.groups.protocol ? url : `https://${url}`);\n if (!TLDs.includes(pos.match.groups.tld)) {\n throw new Error('Invalid URL. Skipping formatting.');\n }\n\n if (leadingChar) {\n nodes.push({ text: leadingChar });\n }\n\n nodes.push({\n text: url,\n href\n });\n } catch {\n // Invalid URL, just render as text.\n nodes.push({ text: pos.match[0] });\n }\n } else if (pos.xmlElement) {\n const xmlAttributes = getXMLAttributes(pos.match[0]);\n\n if (!xmlAttributes) {\n // Invalid XML, just render as text.\n nodes.push({ text: pos.match[0] });\n } else if (pos.component) {\n nodes.push({\n type: 'custom',\n component: pos.component,\n content: xmlAttributes,\n children: [{ text: '' }]\n });\n } else if (pos.getSearchAttributes) {\n const searchResult = pos.getSearchAttributes(pos.xmlElement, pos.match[0]);\n if (searchResult && searchResult.text) {\n nodes.push({\n text: searchResult.text,\n searchResult: {\n markdown: searchResult.markdown,\n component: searchResult.component,\n props: searchResult.props,\n toJSON: () => undefined\n }\n });\n } else {\n nodes.push({ text: pos.match[0] });\n }\n }\n }\n\n // If we are at the end of the positions array, and there's still text left\n // slice the text and add it as a new text node\n if (i === positions.length - 1 && pos.end < text.length) {\n nodes.push({\n text: text.slice(pos.end, text.length)\n });\n }\n lastPos = pos;\n });\n\n return nodes.length > 0 ? nodes : [{ text: '' }];\n};\n\nexport default parseTextToCustomSlateNodes;\n"]}
|
|
@@ -17,7 +17,7 @@ const getNode = (token, interactionRenderers, markdownMap) => {
|
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
19
19
|
let mdText = '';
|
|
20
|
-
if (
|
|
20
|
+
if (token.type === 'text')
|
|
21
21
|
mdText = token.raw;
|
|
22
22
|
else if (hasProp(token, 'text'))
|
|
23
23
|
mdText = token.text;
|
|
@@ -119,8 +119,8 @@ export const convertMarkdownForEditor = (md = '', searchRenderers) => {
|
|
|
119
119
|
}
|
|
120
120
|
];
|
|
121
121
|
};
|
|
122
|
-
|
|
123
|
-
in Feed Component to pass them down to custom elements
|
|
122
|
+
// Converts markdown into Slate compatible nodes, also takes regex used
|
|
123
|
+
// in Feed Component to pass them down to custom elements
|
|
124
124
|
const convertMarkdown = (md, interactionRenderers, markdownMap) => {
|
|
125
125
|
const lexer = new marked.Lexer({ gfm: false });
|
|
126
126
|
const output = lexer.lex(md);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/markdownConverter.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIlD,OAAO,2BAA2B,MAAM,uBAAuB,CAAC;AAEhE,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAErC,MAAM,OAAO,GAAG,CACd,KAAmB,EACnB,oBAA6C,EAC7C,WAAgD,EAChC,EAAE;IAClB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK;QACjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAEzD,IAAI,QAAQ,CAAC;IAEb,IAAI,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;QAC5B,mEAAmE;QACnE,QAAQ,GAAG,eAAe,CACvB,KAAK,CAAC,MAAuC,IAAI,EAAE,EACpD,oBAAoB,EACpB,WAAW,CACZ,CAAC;KACH;SAAM,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE;QAClC,mEAAmE;QACnE,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,KAAK,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;KAC5E;SAAM;QACL,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,
|
|
1
|
+
{"version":3,"file":"markdownConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/markdownConverter.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIlD,OAAO,2BAA2B,MAAM,uBAAuB,CAAC;AAEhE,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAErC,MAAM,OAAO,GAAG,CACd,KAAmB,EACnB,oBAA6C,EAC7C,WAAgD,EAChC,EAAE;IAClB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK;QACjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAEzD,IAAI,QAAQ,CAAC;IAEb,IAAI,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;QAC5B,mEAAmE;QACnE,QAAQ,GAAG,eAAe,CACvB,KAAK,CAAC,MAAuC,IAAI,EAAE,EACpD,oBAAoB,EACpB,WAAW,CACZ,CAAC;KACH;SAAM,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE;QAClC,mEAAmE;QACnE,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,KAAK,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;KAC5E;SAAM;QACL,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;YAAE,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC;aACzC,IAAI,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;YAAE,MAAM,GAAG,KAAK,CAAC,IAAI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;QACL;YACE,IAAI,EAAE,WAAW;YACjB,QAAQ,EAAE,2BAA2B,CAAC,EAAE,EAAE,eAAe,CAAC;SAC3D;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,uEAAuE;AACvE,yDAAyD;AACzD,MAAM,eAAe,GAAG,CACtB,EAAU,EACV,oBAA6C,EAC7C,WAAgD,EAC5B,EAAE;IACtB,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7B,OAAO,eAAe,CAAC,MAAM,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;AACpE,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { CosmosCustom, Element, Text } from 'slate';\nimport { marked } from 'marked';\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { InteractionRenderers, RichTextViewerProps } from '../RichTextViewer.types';\n\nimport parseTextToCustomSlateNodes from './interactionRenderer';\n\nmarked.setOptions({ mangle: false });\n\nconst getNode = (\n token: marked.Token,\n interactionRenderers?: InteractionRenderers[],\n markdownMap?: RichTextViewerProps['markdownMap']\n): Element | Text => {\n if (!hasProp(token, 'type') || token.type === 'def')\n return { type: 'paragraph', children: [{ text: '' }] };\n\n let children;\n\n if (hasProp(token, 'tokens')) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children = markDownToSlate(\n (token.tokens as marked.Tokens.Link['tokens']) || [],\n interactionRenderers,\n markdownMap\n );\n } else if (hasProp(token, 'items')) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children = markDownToSlate(token.items, interactionRenderers, markdownMap);\n } else {\n let mdText = '';\n\n if (token.type === 'text') mdText = token.raw;\n else if (hasProp(token, 'text')) mdText = token.text;\n\n children = parseTextToCustomSlateNodes(mdText, interactionRenderers);\n }\n\n if (markdownMap?.[token.type]) {\n // Typed as any since typescript is unaware that token type matches argument\n const CustomComponent: any = markdownMap[token.type]?.(token as any);\n if (CustomComponent)\n return {\n type: 'override',\n component: <CustomComponent token={token} />,\n children: [{ text: '' }]\n };\n }\n\n if (!children.length) {\n return {\n type: 'paragraph',\n children: [{ text: token.raw }]\n };\n }\n\n switch (token.type) {\n case 'paragraph': {\n return {\n type: token.type,\n children\n };\n }\n case 'heading': {\n return {\n type:\n token.depth && token.depth <= 4\n ? (`heading-${token.depth}` as `heading-${1 | 2 | 3 | 4}`)\n : 'heading-4',\n children\n };\n }\n case 'link': {\n return {\n href: token.href,\n text: token.text || ''\n };\n }\n case 'em': {\n return {\n italic: true,\n text: token.text || ''\n };\n }\n case 'strong': {\n return {\n bold: true,\n text: token.text || ''\n };\n }\n case 'del': {\n return {\n 'line-through': true,\n text: token.text || ''\n };\n }\n case 'list': {\n return {\n type: token.ordered ? 'ordered-list' : 'unordered-list',\n children: children as CosmosCustom.ListItemElement[]\n };\n }\n case 'list_item': {\n return {\n type: 'list-item',\n children: children as Element[]\n };\n }\n case 'image': {\n return {\n type: 'image',\n alt: token.text,\n src: token.href,\n children: [{ text: '' }]\n };\n }\n default: {\n return {\n type: token.type,\n children\n } as Element;\n }\n }\n};\n\nconst markDownToSlate = (\n tokens: marked.Token[],\n interactionRenderers?: InteractionRenderers[],\n markdownMap?: RichTextViewerProps['markdownMap']\n): (Element | Text)[] => {\n return tokens.map(token => {\n return getNode(token, interactionRenderers, markdownMap);\n });\n};\n\nexport const convertMarkdownForEditor = (\n md = '',\n searchRenderers?: InteractionRenderers[]\n): (Element | Text)[] => {\n return [\n {\n type: 'paragraph',\n children: parseTextToCustomSlateNodes(md, searchRenderers)\n }\n ];\n};\n\n// Converts markdown into Slate compatible nodes, also takes regex used\n// in Feed Component to pass them down to custom elements\nconst convertMarkdown = (\n md: string,\n interactionRenderers?: InteractionRenderers[],\n markdownMap?: RichTextViewerProps['markdownMap']\n): (Element | Text)[] => {\n const lexer = new marked.Lexer({ gfm: false });\n const output = lexer.lex(md);\n return markDownToSlate(output, interactionRenderers, markdownMap);\n};\n\nexport default convertMarkdown;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-rte",
|
|
3
|
-
"version": "4.0.0-dev.14.
|
|
3
|
+
"version": "4.0.0-dev.14.2",
|
|
4
4
|
"author": "Pegasystems",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"build": "tsc -b"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@pega/cosmos-react-core": "4.0.0-dev.14.
|
|
23
|
+
"@pega/cosmos-react-core": "4.0.0-dev.14.2",
|
|
24
24
|
"@popperjs/core": "^2.11.6",
|
|
25
25
|
"@types/marked": "^4.0.2",
|
|
26
26
|
"@types/parse5": "^6.0.0",
|