@pega/cosmos-react-rte 2.0.0-dev.9.4 → 2.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js +2 -2
  2. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js.map +1 -1
  3. package/lib/components/RichTextEditor/DecoratorComponents/Image.js +1 -1
  4. package/lib/components/RichTextEditor/DecoratorComponents/Image.js.map +1 -1
  5. package/lib/components/RichTextEditor/DecoratorComponents/Link.js +1 -1
  6. package/lib/components/RichTextEditor/DecoratorComponents/Link.js.map +1 -1
  7. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +2 -0
  8. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +1 -1
  9. package/lib/components/RichTextEditor/DecoratorComponents/Table.js +8 -7
  10. package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +1 -1
  11. package/lib/components/RichTextEditor/RichTextEditor.context.d.ts +3 -3
  12. package/lib/components/RichTextEditor/RichTextEditor.context.d.ts.map +1 -1
  13. package/lib/components/RichTextEditor/RichTextEditor.context.js +1 -1
  14. package/lib/components/RichTextEditor/RichTextEditor.context.js.map +1 -1
  15. package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +1 -1
  16. package/lib/components/RichTextEditor/RichTextEditor.js +91 -65
  17. package/lib/components/RichTextEditor/RichTextEditor.js.map +1 -1
  18. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +3 -0
  19. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +1 -1
  20. package/lib/components/RichTextEditor/RichTextEditor.styles.js +121 -51
  21. package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -1
  22. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +29 -1
  23. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +1 -1
  24. package/lib/components/RichTextEditor/RichTextEditor.types.js.map +1 -1
  25. package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +1 -1
  26. package/lib/components/RichTextEditor/RichTextViewer.js +18 -7
  27. package/lib/components/RichTextEditor/RichTextViewer.js.map +1 -1
  28. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +3 -1
  29. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +1 -1
  30. package/lib/components/RichTextEditor/RichTextViewer.types.js.map +1 -1
  31. package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts.map +1 -1
  32. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js +14 -17
  33. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js.map +1 -1
  34. package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts.map +1 -1
  35. package/lib/components/RichTextEditor/Toolbar/ImageButton.js +10 -15
  36. package/lib/components/RichTextEditor/Toolbar/ImageButton.js.map +1 -1
  37. package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts.map +1 -1
  38. package/lib/components/RichTextEditor/Toolbar/IndentButton.js +5 -2
  39. package/lib/components/RichTextEditor/Toolbar/IndentButton.js.map +1 -1
  40. package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts.map +1 -1
  41. package/lib/components/RichTextEditor/Toolbar/TableButton.js +5 -3
  42. package/lib/components/RichTextEditor/Toolbar/TableButton.js.map +1 -1
  43. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts.map +1 -1
  44. package/lib/components/RichTextEditor/Toolbar/TextSelect.js +35 -18
  45. package/lib/components/RichTextEditor/Toolbar/TextSelect.js.map +1 -1
  46. package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts.map +1 -1
  47. package/lib/components/RichTextEditor/Toolbar/Toolbar.js +11 -20
  48. package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +1 -1
  49. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +3 -4
  50. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +1 -1
  51. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts +9 -1
  52. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +1 -1
  53. package/lib/components/RichTextEditor/utils/EditorCommands.js +130 -17
  54. package/lib/components/RichTextEditor/utils/EditorCommands.js.map +1 -1
  55. package/lib/components/RichTextEditor/utils/ListCommands.js +10 -14
  56. package/lib/components/RichTextEditor/utils/ListCommands.js.map +1 -1
  57. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +1 -1
  58. package/lib/components/RichTextEditor/utils/htmlConverter.js +45 -21
  59. package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -1
  60. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts +9 -2
  61. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +1 -1
  62. package/lib/components/RichTextEditor/utils/interactionRenderer.js +40 -5
  63. package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +1 -1
  64. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts +2 -0
  65. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +1 -1
  66. package/lib/components/RichTextEditor/utils/markdownConverter.js +26 -7
  67. package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -1
  68. package/lib/components/RichTextEditor/utils/renderers.d.ts.map +1 -1
  69. package/lib/components/RichTextEditor/utils/renderers.js +22 -19
  70. package/lib/components/RichTextEditor/utils/renderers.js.map +1 -1
  71. package/lib/components/RichTextEditor/utils/search.d.ts.map +1 -1
  72. package/lib/components/RichTextEditor/utils/search.js +7 -3
  73. package/lib/components/RichTextEditor/utils/search.js.map +1 -1
  74. package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +1 -1
  75. package/lib/components/RichTextEditor/utils/slateConverter.js +1 -0
  76. package/lib/components/RichTextEditor/utils/slateConverter.js.map +1 -1
  77. package/package.json +15 -13
@@ -2,14 +2,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import styled from 'styled-components';
3
3
  import { defaultThemeProp } from '@pega/cosmos-react-core';
4
4
  const StyledCodeBlock = styled.code `
5
- background-color: ${props => props.theme.base.colors.gray.light};
5
+ background-color: ${props => props.theme.base.colors.gray['extra-light']};
6
6
  display: block;
7
7
  font-family: monospace;
8
8
  padding: ${props => props.theme.base.spacing};
9
9
  `;
10
10
  StyledCodeBlock.defaultProps = defaultThemeProp;
11
11
  const CodeBlock = (props) => {
12
- return _jsx(StyledCodeBlock, Object.assign({}, props), void 0);
12
+ return _jsx(StyledCodeBlock, { ...props }, void 0);
13
13
  };
14
14
  export default CodeBlock;
15
15
  //# sourceMappingURL=CodeBlock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlock.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/DecoratorComponents/CodeBlock.tsx"],"names":[],"mappings":";AACA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAA;sBACb,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK;;;aAGpD,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO;CAC7C,CAAC;AAEF,eAAe,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEhD,MAAM,SAAS,GAAY,CAAC,KAAU,EAAE,EAAE;IACxC,OAAO,KAAC,eAAe,oBAAK,KAAK,UAAI,CAAC;AACxC,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import { FC } from 'react';\nimport styled from 'styled-components';\n\nimport { defaultThemeProp } from '@pega/cosmos-react-core';\n\nconst StyledCodeBlock = styled.code`\n background-color: ${props => props.theme.base.colors.gray.light};\n display: block;\n font-family: monospace;\n padding: ${props => props.theme.base.spacing};\n`;\n\nStyledCodeBlock.defaultProps = defaultThemeProp;\n\nconst CodeBlock: FC<any> = (props: any) => {\n return <StyledCodeBlock {...props} />;\n};\n\nexport default CodeBlock;\n"]}
1
+ {"version":3,"file":"CodeBlock.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/DecoratorComponents/CodeBlock.tsx"],"names":[],"mappings":";AACA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAA;sBACb,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC;;;aAG7D,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO;CAC7C,CAAC;AAEF,eAAe,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEhD,MAAM,SAAS,GAAY,CAAC,KAAU,EAAE,EAAE;IACxC,OAAO,KAAC,eAAe,OAAK,KAAK,WAAI,CAAC;AACxC,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import { FC } from 'react';\nimport styled from 'styled-components';\n\nimport { defaultThemeProp } from '@pega/cosmos-react-core';\n\nconst StyledCodeBlock = styled.code`\n background-color: ${props => props.theme.base.colors.gray['extra-light']};\n display: block;\n font-family: monospace;\n padding: ${props => props.theme.base.spacing};\n`;\n\nStyledCodeBlock.defaultProps = defaultThemeProp;\n\nconst CodeBlock: FC<any> = (props: any) => {\n return <StyledCodeBlock {...props} />;\n};\n\nexport default CodeBlock;\n"]}
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Flex, Image } from '@pega/cosmos-react-core';
3
3
  const ImageBlock = (props) => {
4
- return (_jsx(Flex, Object.assign({ container: { alignItems: 'end' } }, { children: _jsx(Image, { src: props.src, alt: props.alt }, void 0) }), void 0));
4
+ return (_jsx(Flex, { container: { alignItems: 'end' }, children: _jsx(Image, { src: props.src, alt: props.alt }, void 0) }, void 0));
5
5
  };
6
6
  export default ImageBlock;
7
7
  //# sourceMappingURL=Image.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Image.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/DecoratorComponents/Image.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAOtD,MAAM,UAAU,GAAY,CAAC,KAAsB,EAAE,EAAE;IACrD,OAAO,CACL,KAAC,IAAI,kBAAC,SAAS,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,gBACpC,KAAC,KAAK,IAAC,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,WAAI,YACpC,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { FC } from 'react';\n\nimport { Flex, Image } from '@pega/cosmos-react-core';\n\ninterface ImageBlockProps {\n src: string;\n alt: string;\n}\n\nconst ImageBlock: FC<any> = (props: ImageBlockProps) => {\n return (\n <Flex container={{ alignItems: 'end' }}>\n <Image src={props.src} alt={props.alt} />\n </Flex>\n );\n};\n\nexport default ImageBlock;\n"]}
1
+ {"version":3,"file":"Image.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/DecoratorComponents/Image.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAOtD,MAAM,UAAU,GAAY,CAAC,KAAsB,EAAE,EAAE;IACrD,OAAO,CACL,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,YACpC,KAAC,KAAK,IAAC,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,WAAI,WACpC,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { FC } from 'react';\n\nimport { Flex, Image } from '@pega/cosmos-react-core';\n\ninterface ImageBlockProps {\n src: string;\n alt: string;\n}\n\nconst ImageBlock: FC<any> = (props: ImageBlockProps) => {\n return (\n <Flex container={{ alignItems: 'end' }}>\n <Image src={props.src} alt={props.alt} />\n </Flex>\n );\n};\n\nexport default ImageBlock;\n"]}
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Link } from '@pega/cosmos-react-core';
3
3
  const LinkEntity = (props) => {
4
4
  const { url } = props.contentState.getEntity(props.entityKey).getData();
5
- return (_jsx(Link, Object.assign({ href: url, target: '_blank' }, { children: props.children }), void 0));
5
+ return (_jsx(Link, { href: url, target: '_blank', children: props.children }, void 0));
6
6
  };
7
7
  export default LinkEntity;
8
8
  //# sourceMappingURL=Link.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Link.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/DecoratorComponents/Link.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,MAAM,UAAU,GAAY,CAAC,KAAU,EAAE,EAAE;IACzC,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;IACxE,OAAO,CACL,KAAC,IAAI,kBAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAC,QAAQ,gBAC7B,KAAK,CAAC,QAAQ,YACV,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { FC } from 'react';\n\nimport { Link } from '@pega/cosmos-react-core';\n\nconst LinkEntity: FC<any> = (props: any) => {\n const { url } = props.contentState.getEntity(props.entityKey).getData();\n return (\n <Link href={url} target='_blank'>\n {props.children}\n </Link>\n );\n};\n\nexport default LinkEntity;\n"]}
1
+ {"version":3,"file":"Link.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/DecoratorComponents/Link.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,MAAM,UAAU,GAAY,CAAC,KAAU,EAAE,EAAE;IACzC,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;IACxE,OAAO,CACL,KAAC,IAAI,IAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAC,QAAQ,YAC7B,KAAK,CAAC,QAAQ,WACV,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { FC } from 'react';\n\nimport { Link } from '@pega/cosmos-react-core';\n\nconst LinkEntity: FC<any> = (props: any) => {\n const { url } = props.contentState.getEntity(props.entityKey).getData();\n return (\n <Link href={url} target='_blank'>\n {props.children}\n </Link>\n );\n};\n\nexport default LinkEntity;\n"]}
@@ -1,4 +1,6 @@
1
1
  import { FC } from 'react';
2
+ import { DefaultTheme } from 'styled-components';
3
+ export declare const getTableStyles: (theme: DefaultTheme) => import("styled-components").FlattenSimpleInterpolation;
2
4
  export declare const TableBody: FC<any>;
3
5
  export declare const Table: FC<any>;
4
6
  export declare const TableRow: FC<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/DecoratorComponents/Table.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAmB,MAAM,OAAO,CAAC;AAoC5C,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,GAAG,CAO5B,CAAC;AAEH,eAAO,MAAM,KAAK,EAAE,EAAE,CAAC,GAAG,CAOxB,CAAC;AAEH,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,GAAG,CAO3B,CAAC;AAEH,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,GAAG,CAO5B,CAAC"}
1
+ {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/DecoratorComponents/Table.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAmB,MAAM,OAAO,CAAC;AAC5C,OAAe,EAAE,YAAY,EAAO,MAAM,mBAAmB,CAAC;AAI9D,eAAO,MAAM,cAAc,UAAW,YAAY,2DA2BjD,CAAC;AAMF,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,GAAG,CAO5B,CAAC;AAEH,eAAO,MAAM,KAAK,EAAE,EAAE,CAAC,GAAG,CAOxB,CAAC;AAEH,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,GAAG,CAO3B,CAAC;AAEH,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,GAAG,CAO5B,CAAC"}
@@ -1,12 +1,12 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef } from 'react';
3
- import styled from 'styled-components';
3
+ import styled, { css } from 'styled-components';
4
4
  import { defaultThemeProp } from '@pega/cosmos-react-core';
5
- const StyledTable = styled.table `
5
+ export const getTableStyles = (theme) => css `
6
6
  border-collapse: collapse;
7
7
 
8
8
  td {
9
- border: 0.0625rem solid ${props => props.theme.base.palette['border-line']};
9
+ border: 0.0625rem solid ${theme.base.palette['border-line']};
10
10
  min-width: 6.25rem;
11
11
  }
12
12
 
@@ -30,21 +30,22 @@ const StyledTable = styled.table `
30
30
  }
31
31
  }
32
32
  `;
33
+ const StyledTable = styled.table(props => getTableStyles(props.theme));
33
34
  StyledTable.defaultProps = defaultThemeProp;
34
35
  export const TableBody = forwardRef((props, ref) => {
35
36
  const { children, ...restProps } = props;
36
- return (_jsx("tbody", Object.assign({}, restProps, { ref: ref }, { children: children }), void 0));
37
+ return (_jsx("tbody", { ...restProps, ref: ref, children: children }, void 0));
37
38
  });
38
39
  export const Table = forwardRef((props, ref) => {
39
40
  const { children, ...restProps } = props;
40
- return (_jsx(StyledTable, Object.assign({}, restProps, { ref: ref }, { children: children }), void 0));
41
+ return (_jsx(StyledTable, { ...restProps, ref: ref, children: children }, void 0));
41
42
  });
42
43
  export const TableRow = forwardRef((props, ref) => {
43
44
  const { children, ...restProps } = props;
44
- return (_jsx("tr", Object.assign({}, restProps, { ref: ref }, { children: children }), void 0));
45
+ return (_jsx("tr", { ...restProps, ref: ref, children: children }, void 0));
45
46
  });
46
47
  export const TableCell = forwardRef((props, ref) => {
47
48
  const { children, ...restProps } = props;
48
- return (_jsx("td", Object.assign({}, restProps, { ref: ref }, { children: children }), void 0));
49
+ return (_jsx("td", { ...restProps, ref: ref, children: children }, void 0));
49
50
  });
50
51
  //# sourceMappingURL=Table.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/DecoratorComponents/Table.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,UAAU,EAAO,MAAM,OAAO,CAAC;AAC5C,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAA;;;;8BAIF,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;CAuB7E,CAAC;AAEF,WAAW,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE5C,MAAM,CAAC,MAAM,SAAS,GAAY,UAAU,CAAC,CAAC,KAAU,EAAE,GAAa,EAAE,EAAE;IACzE,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACzC,OAAO,CACL,gCAAW,SAAS,IAAE,GAAG,EAAE,GAAG,gBAC3B,QAAQ,YACH,CACT,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,KAAK,GAAY,UAAU,CAAC,CAAC,KAAU,EAAE,GAAa,EAAE,EAAE;IACrE,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACzC,OAAO,CACL,KAAC,WAAW,oBAAK,SAAS,IAAE,GAAG,EAAE,GAAG,gBACjC,QAAQ,YACG,CACf,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAY,UAAU,CAAC,CAAC,KAAU,EAAE,GAAa,EAAE,EAAE;IACxE,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACzC,OAAO,CACL,6BAAQ,SAAS,IAAE,GAAG,EAAE,GAAG,gBACxB,QAAQ,YACN,CACN,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAY,UAAU,CAAC,CAAC,KAAU,EAAE,GAAa,EAAE,EAAE;IACzE,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACzC,OAAO,CACL,6BAAQ,SAAS,IAAE,GAAG,EAAE,GAAG,gBACxB,QAAQ,YACN,CACN,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { FC, forwardRef, Ref } from 'react';\nimport styled from 'styled-components';\n\nimport { defaultThemeProp } from '@pega/cosmos-react-core';\n\nconst StyledTable = styled.table`\n border-collapse: collapse;\n\n td {\n border: 0.0625rem solid ${props => props.theme.base.palette['border-line']};\n min-width: 6.25rem;\n }\n\n tr:first-child {\n td:first-child {\n border-top-left-radius: 0.125rem;\n }\n\n td:last-child {\n border-top-right-radius: 0.125rem;\n }\n }\n\n tr:last-child {\n td:first-child {\n border-bottom-left-radius: 0.125rem;\n }\n\n td:last-child {\n border-bottom-right-radius: 0.125rem;\n }\n }\n`;\n\nStyledTable.defaultProps = defaultThemeProp;\n\nexport const TableBody: FC<any> = forwardRef((props: any, ref: Ref<any>) => {\n const { children, ...restProps } = props;\n return (\n <tbody {...restProps} ref={ref}>\n {children}\n </tbody>\n );\n});\n\nexport const Table: FC<any> = forwardRef((props: any, ref: Ref<any>) => {\n const { children, ...restProps } = props;\n return (\n <StyledTable {...restProps} ref={ref}>\n {children}\n </StyledTable>\n );\n});\n\nexport const TableRow: FC<any> = forwardRef((props: any, ref: Ref<any>) => {\n const { children, ...restProps } = props;\n return (\n <tr {...restProps} ref={ref}>\n {children}\n </tr>\n );\n});\n\nexport const TableCell: FC<any> = forwardRef((props: any, ref: Ref<any>) => {\n const { children, ...restProps } = props;\n return (\n <td {...restProps} ref={ref}>\n {children}\n </td>\n );\n});\n"]}
1
+ {"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/DecoratorComponents/Table.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,UAAU,EAAO,MAAM,OAAO,CAAC;AAC5C,OAAO,MAAM,EAAE,EAAgB,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAmB,EAAE,EAAE,CAAC,GAAG,CAAA;;;;8BAI5B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;CAuB9D,CAAC;AAEF,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAEvE,WAAW,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE5C,MAAM,CAAC,MAAM,SAAS,GAAY,UAAU,CAAC,CAAC,KAAU,EAAE,GAAa,EAAE,EAAE;IACzE,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACzC,OAAO,CACL,mBAAW,SAAS,EAAE,GAAG,EAAE,GAAG,YAC3B,QAAQ,WACH,CACT,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,KAAK,GAAY,UAAU,CAAC,CAAC,KAAU,EAAE,GAAa,EAAE,EAAE;IACrE,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACzC,OAAO,CACL,KAAC,WAAW,OAAK,SAAS,EAAE,GAAG,EAAE,GAAG,YACjC,QAAQ,WACG,CACf,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAY,UAAU,CAAC,CAAC,KAAU,EAAE,GAAa,EAAE,EAAE;IACxE,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACzC,OAAO,CACL,gBAAQ,SAAS,EAAE,GAAG,EAAE,GAAG,YACxB,QAAQ,WACN,CACN,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAY,UAAU,CAAC,CAAC,KAAU,EAAE,GAAa,EAAE,EAAE;IACzE,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACzC,OAAO,CACL,gBAAQ,SAAS,EAAE,GAAG,EAAE,GAAG,YACxB,QAAQ,WACN,CACN,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { FC, forwardRef, Ref } from 'react';\nimport styled, { DefaultTheme, css } from 'styled-components';\n\nimport { defaultThemeProp } from '@pega/cosmos-react-core';\n\nexport const getTableStyles = (theme: DefaultTheme) => css`\n border-collapse: collapse;\n\n td {\n border: 0.0625rem solid ${theme.base.palette['border-line']};\n min-width: 6.25rem;\n }\n\n tr:first-child {\n td:first-child {\n border-top-left-radius: 0.125rem;\n }\n\n td:last-child {\n border-top-right-radius: 0.125rem;\n }\n }\n\n tr:last-child {\n td:first-child {\n border-bottom-left-radius: 0.125rem;\n }\n\n td:last-child {\n border-bottom-right-radius: 0.125rem;\n }\n }\n`;\n\nconst StyledTable = styled.table(props => getTableStyles(props.theme));\n\nStyledTable.defaultProps = defaultThemeProp;\n\nexport const TableBody: FC<any> = forwardRef((props: any, ref: Ref<any>) => {\n const { children, ...restProps } = props;\n return (\n <tbody {...restProps} ref={ref}>\n {children}\n </tbody>\n );\n});\n\nexport const Table: FC<any> = forwardRef((props: any, ref: Ref<any>) => {\n const { children, ...restProps } = props;\n return (\n <StyledTable {...restProps} ref={ref}>\n {children}\n </StyledTable>\n );\n});\n\nexport const TableRow: FC<any> = forwardRef((props: any, ref: Ref<any>) => {\n const { children, ...restProps } = props;\n return (\n <tr {...restProps} ref={ref}>\n {children}\n </tr>\n );\n});\n\nexport const TableCell: FC<any> = forwardRef((props: any, ref: Ref<any>) => {\n const { children, ...restProps } = props;\n return (\n <td {...restProps} ref={ref}>\n {children}\n </td>\n );\n});\n"]}
@@ -1,9 +1,9 @@
1
- import { MouseEvent } from 'react';
1
+ import { MouseEvent, FocusEvent } from 'react';
2
2
  export interface RichTextEditorContextValue {
3
- onImageAdded?: (image: File, id: string) => void;
3
+ addImage: (image: File) => void;
4
4
  setPopoverOpen: (open: boolean) => void;
5
5
  onEditorFocus: (args: {
6
- event?: MouseEvent | FocusEvent;
6
+ event?: MouseEvent | FocusEvent<any>;
7
7
  force?: boolean;
8
8
  runAfterFocus?: () => void;
9
9
  focusEditor?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextEditor.context.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,UAAU,EAAc,MAAM,OAAO,CAAC;AAE9D,MAAM,WAAW,0BAA0B;IACzC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,cAAc,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACxC,aAAa,EAAE,CAAC,IAAI,EAAE;QACpB,KAAK,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;QAChC,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;QAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,KAAK,IAAI,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,qBAAqB,qDAKhC,CAAC;AAEH,eAAO,MAAM,aAAa,kCAEzB,CAAC"}
1
+ {"version":3,"file":"RichTextEditor.context.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,UAAU,EAAc,UAAU,EAAE,MAAM,OAAO,CAAC;AAE1E,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC;IAChC,cAAc,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACxC,aAAa,EAAE,CAAC,IAAI,EAAE;QACpB,KAAK,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QACrC,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;QAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,KAAK,IAAI,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,qBAAqB,qDAKhC,CAAC;AAEH,eAAO,MAAM,aAAa,kCAEzB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { createContext, useContext } from 'react';
2
2
  export const RichTextEditorContext = createContext({
3
- onImageAdded: () => { },
3
+ addImage: () => { },
4
4
  setPopoverOpen: () => { },
5
5
  onEditorFocus: () => { },
6
6
  disabled: false
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextEditor.context.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAc,UAAU,EAAE,MAAM,OAAO,CAAC;AAc9D,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAA6B;IAC7E,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;IACxB,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;IACvB,QAAQ,EAAE,KAAK;CAChB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,OAAO,UAAU,CAAC,qBAAqB,CAAC,CAAC;AAC3C,CAAC,CAAC","sourcesContent":["import { createContext, MouseEvent, useContext } from 'react';\n\nexport interface RichTextEditorContextValue {\n onImageAdded?: (image: File, id: string) => void;\n setPopoverOpen: (open: boolean) => void;\n onEditorFocus: (args: {\n event?: MouseEvent | FocusEvent;\n force?: boolean;\n runAfterFocus?: () => void;\n focusEditor?: boolean;\n }) => void;\n disabled: boolean;\n}\n\nexport const RichTextEditorContext = createContext<RichTextEditorContextValue>({\n onImageAdded: () => {},\n setPopoverOpen: () => {},\n onEditorFocus: () => {},\n disabled: false\n});\n\nexport const useRTEContext = () => {\n return useContext(RichTextEditorContext);\n};\n"]}
1
+ {"version":3,"file":"RichTextEditor.context.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAc,UAAU,EAAc,MAAM,OAAO,CAAC;AAc1E,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAA6B;IAC7E,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;IAClB,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;IACxB,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;IACvB,QAAQ,EAAE,KAAK;CAChB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,OAAO,UAAU,CAAC,qBAAqB,CAAC,CAAC;AAC3C,CAAC,CAAC","sourcesContent":["import { createContext, MouseEvent, useContext, FocusEvent } from 'react';\n\nexport interface RichTextEditorContextValue {\n addImage: (image: File) => void;\n setPopoverOpen: (open: boolean) => void;\n onEditorFocus: (args: {\n event?: MouseEvent | FocusEvent<any>;\n force?: boolean;\n runAfterFocus?: () => void;\n focusEditor?: boolean;\n }) => void;\n disabled: boolean;\n}\n\nexport const RichTextEditorContext = createContext<RichTextEditorContextValue>({\n addImage: () => {},\n setPopoverOpen: () => {},\n onEditorFocus: () => {},\n disabled: false\n});\n\nexport const useRTEContext = () => {\n return useContext(RichTextEditorContext);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,EAAE,EASH,MAAM,OAAO,CAAC;AAQf,OAAO,EAQL,YAAY,EAMb,MAAM,yBAAyB,CAAC;AAUjC,OAAO,EAAuB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AA0DlF,QAAA,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,GAAG,YAAY,CAiZ1D,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,EAAE,EASH,MAAM,OAAO,CAAC;AASf,OAAO,EAQL,YAAY,EAMb,MAAM,yBAAyB,CAAC;AAUjC,OAAO,EAAuB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AA2DlF,QAAA,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,GAAG,YAAY,CAwb1D,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,12 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useState, useRef, useMemo, useEffect, useCallback, useImperativeHandle, useReducer } from 'react';
3
3
  // Import the Slate editor factory.
4
- import { createEditor, Node } from 'slate';
4
+ import { createEditor, Node, Transforms } from 'slate';
5
5
  // Import the Slate components and React plugin.
6
6
  import { Slate, Editable, withReact, ReactEditor } from 'slate-react';
7
+ import { withHistory } from 'slate-history';
7
8
  import styled from 'styled-components';
8
- import { FormField, FormControl, StyledPopover, useTheme, useUID, createUID, debounce, Popover, Menu, menuHelpers, useAfterInitialEffect } from '@pega/cosmos-react-core';
9
- import StyledRichTextEditor, { EditorContainer } from './RichTextEditor.styles';
9
+ import { FormField, FormControl, StyledPopover, useTheme, useUID, createUID, debounce, Popover, Menu, menuHelpers } from '@pega/cosmos-react-core';
10
+ import StyledRichTextEditor, { EditorContainer, StyledFormField } from './RichTextEditor.styles';
10
11
  import Toolbar from './Toolbar/Toolbar';
11
12
  import { nodeRenderer, leafRenderer } from './utils/renderers';
12
13
  import { onSearchChange } from './utils/search';
@@ -15,6 +16,7 @@ import ListCommands from './utils/ListCommands';
15
16
  import { convertHtml } from './utils/htmlConverter';
16
17
  import { convertSlateToHtml } from './utils/slateConverter';
17
18
  import { RichTextEditorContext } from './RichTextEditor.context';
19
+ import { convertMarkdownForEditor } from './utils/markdownConverter';
18
20
  const withVoids = (editor) => {
19
21
  editor.isVoid = element => {
20
22
  if (element.type === 'image' || element.type === 'image-placeholder') {
@@ -25,7 +27,6 @@ const withVoids = (editor) => {
25
27
  return editor;
26
28
  };
27
29
  const syntheticFocusReducer = (currentId, action) => {
28
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
29
30
  const { type, menuItems, selectedItemId } = action;
30
31
  switch (type) {
31
32
  case 'child':
@@ -33,24 +34,24 @@ const syntheticFocusReducer = (currentId, action) => {
33
34
  if (!currentId)
34
35
  return menuItems[0].id;
35
36
  // if currently highlighted item has children, select first of them
36
- return (_b = (_a = menuHelpers.getItem(menuItems, currentId)) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b[0].id;
37
+ return menuHelpers.getItem(menuItems, currentId)?.items?.[0].id;
37
38
  case 'parent':
38
39
  // find and return parent of currently selected item
39
- return (_c = menuHelpers.getParentItem(menuItems, currentId)) === null || _c === void 0 ? void 0 : _c.id;
40
+ return menuHelpers.getParentItem(menuItems, currentId)?.id;
40
41
  case 'next':
41
42
  // return next sibling of currently selected item
42
- return (_e = (_d = menuHelpers.getNextItem(menuItems, currentId)) === null || _d === void 0 ? void 0 : _d.id) !== null && _e !== void 0 ? _e : currentId;
43
+ return menuHelpers.getNextItem(menuItems, currentId)?.id ?? currentId;
43
44
  case 'prev':
44
45
  // return prev sibling of currently selected item
45
- return (_g = (_f = menuHelpers.getPrevItem(menuItems, currentId)) === null || _f === void 0 ? void 0 : _f.id) !== null && _g !== void 0 ? _g : currentId;
46
+ return menuHelpers.getPrevItem(menuItems, currentId)?.id ?? currentId;
46
47
  case 'list_change':
47
48
  // if currently selected item does not exist in new list, select first one
48
49
  if (currentId && menuHelpers.getItem(menuItems, currentId))
49
50
  return currentId;
50
- return (_h = menuItems[0]) === null || _h === void 0 ? void 0 : _h.id;
51
+ return menuItems[0]?.id;
51
52
  case 'set':
52
53
  // return arbitrary selected item id if it is in the tree; undefined otherwise
53
- return selectedItemId ? (_j = menuHelpers.getItem(menuItems, selectedItemId)) === null || _j === void 0 ? void 0 : _j.id : undefined;
54
+ return selectedItemId ? menuHelpers.getItem(menuItems, selectedItemId)?.id : undefined;
54
55
  case 'clear':
55
56
  return undefined;
56
57
  default:
@@ -63,17 +64,12 @@ const StyledSearchPopover = styled(StyledPopover) `
63
64
  const RichTextEditor = forwardRef((props, ref) => {
64
65
  const { components: { 'text-area': { 'min-height': minHeight } } } = useTheme();
65
66
  const uid = useUID();
66
- const { id = uid, label, labelHidden, info, status, required, disabled, readOnly, onChange, onFocus, onBlur, placeholder, toolbar, onImageAdded, markdownOnly, searchTriggers, onSearch, getSearchItemReplacement, menu, height = { min: minHeight }, defaultValue, autoFocus, ...restProps } = props;
67
+ const { id = uid, label, labelHidden, info, status, required, disabled, readOnly, onChange, onFocus, onBlur, placeholder, toolbar, onImageAdded, markdownOnly, searchTriggers, onSearch, getSearchItemReplacement, searchRenderers, menu, height = { min: minHeight }, defaultValue, autoFocus, ...restProps } = props;
67
68
  const formFieldRef = useRef(null);
68
- const editor = useMemo(() => withVoids(withReact(createEditor())), []);
69
- const [value, setValue] = useState(defaultValue && !markdownOnly
69
+ const editor = useMemo(() => withVoids(withReact(withHistory(createEditor()))), []);
70
+ const [value, setValue] = useState(() => defaultValue && !markdownOnly
70
71
  ? convertHtml(defaultValue)
71
- : [
72
- {
73
- type: 'paragraph',
74
- children: [{ text: defaultValue || '' }]
75
- }
76
- ]);
72
+ : convertMarkdownForEditor(defaultValue, searchRenderers));
77
73
  const [toolbarPopover, setToolbarPopover] = useState(false);
78
74
  const [toolbarSticky, setToolbarSticky] = useState(false);
79
75
  const [focusableToolbarBtn, setFocusableToolbarBtn] = useState(null);
@@ -81,8 +77,7 @@ const RichTextEditor = forwardRef((props, ref) => {
81
77
  const [popoverTarget, setPopoverTarget] = useState(null);
82
78
  const [searchEl, setSearchEl] = useState(null);
83
79
  const updateToolbarStyle = () => {
84
- var _a;
85
- if ((((_a = formFieldRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0) > window.innerHeight) {
80
+ if ((formFieldRef.current?.offsetHeight || 0) > window.innerHeight) {
86
81
  setToolbarSticky(true);
87
82
  }
88
83
  else {
@@ -93,24 +88,37 @@ const RichTextEditor = forwardRef((props, ref) => {
93
88
  const getPlainText = () => {
94
89
  return value
95
90
  .map(node => {
91
+ if (markdownOnly && node.children) {
92
+ return node.children
93
+ .map(textNode => textNode.searchResult?.markdown || textNode.text)
94
+ .join('');
95
+ }
96
96
  return Node.string(node);
97
97
  })
98
98
  .join('\n');
99
99
  };
100
100
  const onEditorFocus = ({ event, force, focusEditor, runAfterFocus }) => {
101
101
  if (focusEditor) {
102
- ReactEditor.focus(editor);
102
+ setTimeout(() => {
103
+ if (!ReactEditor.isFocused(editor)) {
104
+ ReactEditor.focus(editor);
105
+ onFocus?.();
106
+ }
107
+ }, 0);
103
108
  }
104
109
  if (runAfterFocus && (force || (!disabled && !toolbarPopover))) {
105
110
  setTimeout(runAfterFocus, 0);
106
111
  }
107
112
  else {
108
- event === null || event === void 0 ? void 0 : event.stopPropagation();
113
+ event?.stopPropagation();
109
114
  }
110
115
  };
111
- const blurEditor = () => {
112
- ReactEditor.blur(editor);
113
- onBlur === null || onBlur === void 0 ? void 0 : onBlur();
116
+ const blurEditor = (force) => {
117
+ if (force)
118
+ ReactEditor.blur(editor);
119
+ if (ReactEditor.isFocused(editor)) {
120
+ onBlur?.();
121
+ }
114
122
  };
115
123
  useImperativeHandle(ref, () => ({
116
124
  focus: () => {
@@ -136,19 +144,48 @@ const RichTextEditor = forwardRef((props, ref) => {
136
144
  ]);
137
145
  },
138
146
  appendImage: ({ src, alt }, imageId) => {
139
- EditorCommands.appendImage(editor, { src, alt }, imageId);
147
+ const path = EditorCommands.appendImage(editor, { src, alt }, imageId);
148
+ if (path) {
149
+ Transforms.select(editor, { anchor: path, focus: path });
150
+ ReactEditor.focus(editor);
151
+ }
140
152
  },
141
153
  insertText: (text) => {
142
154
  editor.insertText(text);
155
+ },
156
+ insertHtml: (html, overwrite = false) => {
157
+ setValue(prevValue => {
158
+ if (overwrite) {
159
+ const point = { path: [0, 0], offset: 0 };
160
+ editor.selection = { anchor: point, focus: point };
161
+ return convertHtml(html !== '' ? html : '<p></p>');
162
+ }
163
+ return [...prevValue, ...convertHtml(html)];
164
+ });
143
165
  }
144
166
  }), [value, setValue]);
145
167
  const onMenuItemClick = (itemId, e) => {
146
- var _a;
147
168
  // MenuItem expects actual click events, but we don't have reference to actual menu item element to trigger a click.
148
- (_a = menu === null || menu === void 0 ? void 0 : menu.onItemClick) === null || _a === void 0 ? void 0 : _a.call(menu, itemId, e);
149
- const replacementText = getSearchItemReplacement === null || getSearchItemReplacement === void 0 ? void 0 : getSearchItemReplacement(itemId);
150
- if (replacementText) {
151
- EditorCommands.replaceWithText(editor, popoverTarget, replacementText);
169
+ menu?.onItemClick?.(itemId, e);
170
+ const replacement = getSearchItemReplacement?.(itemId);
171
+ if (replacement) {
172
+ let node;
173
+ if (replacement.markdown && replacement.component && replacement.props) {
174
+ node = {
175
+ text: replacement.text,
176
+ searchResult: {
177
+ markdown: replacement.markdown,
178
+ component: replacement.component,
179
+ props: replacement.props,
180
+ // Prevents copying searchResult attribute onPaste
181
+ toJSON: () => undefined
182
+ }
183
+ };
184
+ }
185
+ else {
186
+ node = { text: replacement.text };
187
+ }
188
+ EditorCommands.replaceWithNodes(editor, popoverTarget, node);
152
189
  }
153
190
  };
154
191
  const onKeyDown = useCallback((event) => {
@@ -166,7 +203,6 @@ const RichTextEditor = forwardRef((props, ref) => {
166
203
  event.preventDefault();
167
204
  if (focusedId) {
168
205
  onMenuItemClick(focusedId, event);
169
- setPopoverTarget(null);
170
206
  dispatchFocus({ type: 'clear', menuItems: menu.items });
171
207
  }
172
208
  break;
@@ -187,15 +223,19 @@ const RichTextEditor = forwardRef((props, ref) => {
187
223
  else {
188
224
  ListCommands.checkListEnter(editor, event);
189
225
  EditorCommands.checkLinkBreak(editor, event);
226
+ EditorCommands.checkSearchDownKeys(editor, event);
190
227
  EditorCommands.checkImageEnter(editor, event);
191
228
  EditorCommands.checkKeyCommands(editor, event);
192
229
  }
193
230
  }, [menu, focusedId, popoverTarget, focusableToolbarBtn]);
231
+ const onKeyUp = (event) => {
232
+ EditorCommands.checkSearchUpKeys(editor, event);
233
+ };
194
234
  // Adds an image placeholder to be replaced later in time by an image
195
235
  const addImage = (file) => {
196
236
  const placeholderId = EditorCommands.appendImagePlaceholder(editor);
197
237
  if (placeholderId)
198
- onImageAdded === null || onImageAdded === void 0 ? void 0 : onImageAdded(file, placeholderId);
238
+ onImageAdded?.(file, placeholderId);
199
239
  };
200
240
  const onPaste = (e) => {
201
241
  let image;
@@ -226,15 +266,14 @@ const RichTextEditor = forwardRef((props, ref) => {
226
266
  }
227
267
  }, [popoverTarget]);
228
268
  useEffect(() => {
229
- onChange === null || onChange === void 0 ? void 0 : onChange();
269
+ onChange?.();
230
270
  }, [value]);
231
271
  useEffect(() => {
232
- var _a;
233
272
  if (menu && popoverTarget) {
234
273
  dispatchFocus({
235
274
  type: 'set',
236
275
  menuItems: menu.items,
237
- selectedItemId: (_a = menu.items[0]) === null || _a === void 0 ? void 0 : _a.id
276
+ selectedItemId: menu.items[0]?.id
238
277
  });
239
278
  }
240
279
  }, [menu, popoverTarget]);
@@ -245,22 +284,18 @@ const RichTextEditor = forwardRef((props, ref) => {
245
284
  }, 0);
246
285
  }
247
286
  }, []);
248
- useAfterInitialEffect(() => {
249
- if (!menu) {
250
- ReactEditor.focus(editor);
251
- }
252
- }, [menu]);
253
- return (_jsx(RichTextEditorContext.Provider, Object.assign({ value: {
254
- onImageAdded,
287
+ return (_jsx(RichTextEditorContext.Provider, { value: {
288
+ addImage,
255
289
  setPopoverOpen: setToolbarPopover,
256
290
  onEditorFocus,
257
291
  disabled: disabled || false
258
- } }, { children: _jsx(FormField, Object.assign({ label:
292
+ }, children: _jsx(FormField, { as: StyledFormField, toolbar: !!(!markdownOnly && toolbar?.length), label:
259
293
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
260
- _jsx("span", Object.assign({ onClick: () => onEditorFocus({ focusEditor: true }) }, { children: label }), void 0), labelHidden: labelHidden, id: id, labelOrder: -1, info: info, status: status, required: required, disabled: disabled, readOnly: readOnly, onDrop: onDrop, onFocus: (e) => {
261
- if (e.target === formFieldRef.current)
262
- onEditorFocus({});
263
- }, ref: formFieldRef, "aria-label": `${label} ${!markdownOnly && !readOnly && (toolbar === null || toolbar === void 0 ? void 0 : toolbar.length) ? 'Hit tab to edit toolbar below' : ''}` }, { children: _jsxs(Slate, Object.assign({ editor: editor, value: value, onChange: newValue => {
294
+ _jsx("span", { onClick: () => onEditorFocus({ focusEditor: true }), children: label }, void 0), labelHidden: labelHidden, id: id, info: info, status: status, required: required, disabled: disabled, readOnly: readOnly, onDrop: onDrop, onFocus: (e) => {
295
+ if (e.target === formFieldRef.current && !disabled) {
296
+ onEditorFocus({ focusEditor: true });
297
+ }
298
+ }, ref: formFieldRef, "aria-label": `${label} ${!markdownOnly && !readOnly && toolbar?.length ? 'Hit tab to edit toolbar below' : ''}`, tabIndex: disabled ? -1 : undefined, children: _jsxs(Slate, { editor: editor, value: value, onChange: newValue => {
264
299
  if (!disabled) {
265
300
  setValue(newValue);
266
301
  debouncedUpdateToolbarStyle();
@@ -273,7 +308,7 @@ const RichTextEditor = forwardRef((props, ref) => {
273
308
  {
274
309
  trigger,
275
310
  groupId: `g${groupId}`,
276
- regex: new RegExp(String.raw `${trigger}(?<g${groupId}>${regex || String.raw `\w*`})$`)
311
+ regex: new RegExp(String.raw `(?:^|\s)(?<match>${trigger}(?<g${groupId}>${regex || String.raw `\w*`}))$`)
277
312
  }
278
313
  ];
279
314
  }
@@ -300,26 +335,17 @@ const RichTextEditor = forwardRef((props, ref) => {
300
335
  }
301
336
  }
302
337
  }
303
- } }, { children: [_jsxs(FormControl, Object.assign({}, restProps, { ref: ref, ariaLabel: label, id: id, required: required, disabled: disabled, readOnly: readOnly, status: status, as: StyledRichTextEditor, toolbar: !!(!markdownOnly && (toolbar === null || toolbar === void 0 ? void 0 : toolbar.length)), onClick: () => {
338
+ }, children: [_jsxs(FormControl, { ...restProps, ref: ref, ariaLabel: label, required: required, disabled: disabled, readOnly: readOnly, status: status, as: StyledRichTextEditor, toolbar: !!(!markdownOnly && toolbar?.length), onClick: () => {
304
339
  onEditorFocus({ focusEditor: true });
305
- }, focused: ReactEditor.isFocused(editor) }, { children: [_jsx(EditorContainer, Object.assign({ toolbar: !!(!markdownOnly && (toolbar === null || toolbar === void 0 ? void 0 : toolbar.length)), containerHeight: height, onClick: () => {
340
+ }, focused: ReactEditor.isFocused(editor), children: [_jsx(EditorContainer, { toolbar: !!(!markdownOnly && toolbar?.length), containerHeight: height, onClick: () => {
306
341
  if (!disabled) {
307
342
  onEditorFocus({ focusEditor: true });
308
- onFocus === null || onFocus === void 0 ? void 0 : onFocus();
309
343
  }
310
- } }, { children: _jsx(Editable, { renderElement: nodeRenderer, renderLeaf: leafRenderer, onKeyDown: onKeyDown, placeholder: placeholder, onFocus: () => {
311
- if (!disabled) {
312
- onEditorFocus({});
313
- onFocus === null || onFocus === void 0 ? void 0 : onFocus();
314
- }
315
- else {
316
- blurEditor();
317
- }
318
- }, onBlur: blurEditor, disabled: disabled, readOnly: readOnly, onPaste: onPaste }, void 0) }), void 0),
319
- !markdownOnly && !readOnly && (toolbar === null || toolbar === void 0 ? void 0 : toolbar.length) ? (_jsx(Toolbar, { features: toolbar, sticky: toolbarSticky, setFocusableBtn: el => {
344
+ }, children: _jsx(Editable, { id: id, renderElement: nodeRenderer, renderLeaf: leafRenderer, onKeyDown: onKeyDown, onKeyUp: onKeyUp, placeholder: placeholder, onFocus: event => {
345
+ onEditorFocus({ focusEditor: true, event });
346
+ }, onBlur: () => blurEditor(), disabled: disabled, readOnly: readOnly, onPaste: onPaste, tabIndex: disabled ? -1 : undefined }, void 0) }, void 0), !markdownOnly && !readOnly && toolbar?.length ? (_jsx(Toolbar, { features: toolbar, sticky: toolbarSticky, setFocusableBtn: el => {
320
347
  setFocusableToolbarBtn(el);
321
- } }, void 0)) : null] }), void 0),
322
- _jsx(Popover, Object.assign({ show: !!popoverTarget && !!menu, strategy: 'fixed', target: searchEl, placement: 'bottom-start' }, { children: menu && (_jsx(Menu, Object.assign({}, menu, { as: StyledSearchPopover, currentItemId: focusedId, mode: 'action', onItemClick: onMenuItemClick }), void 0)) }), void 0)] }), void 0) }), void 0) }), void 0));
348
+ } }, void 0)) : null] }, void 0), _jsx(Popover, { show: !!popoverTarget && !!menu, strategy: 'fixed', target: searchEl, placement: 'bottom-start', children: menu && (_jsx(Menu, { ...menu, as: StyledSearchPopover, currentItemId: focusedId, mode: 'action', onItemClick: onMenuItemClick }, void 0)) }, void 0)] }, void 0) }, void 0) }, void 0));
323
349
  });
324
350
  export default RichTextEditor;
325
351
  //# sourceMappingURL=RichTextEditor.js.map