@pega/cosmos-react-rte 8.0.0-build.9.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts +2 -3
  2. package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts.map +1 -1
  3. package/lib/components/DynamicContentEditor/DynamicContentEditor.js +8 -4
  4. package/lib/components/DynamicContentEditor/DynamicContentEditor.js.map +1 -1
  5. package/lib/components/Editor/Editor.d.ts +3 -6
  6. package/lib/components/Editor/Editor.d.ts.map +1 -1
  7. package/lib/components/Editor/Editor.js +120 -55
  8. package/lib/components/Editor/Editor.js.map +1 -1
  9. package/lib/components/Editor/Editor.styles.d.ts +2 -1
  10. package/lib/components/Editor/Editor.styles.d.ts.map +1 -1
  11. package/lib/components/Editor/Editor.styles.js +7 -12
  12. package/lib/components/Editor/Editor.styles.js.map +1 -1
  13. package/lib/components/Editor/Editor.types.d.ts +2 -0
  14. package/lib/components/Editor/Editor.types.d.ts.map +1 -1
  15. package/lib/components/Editor/Editor.types.js.map +1 -1
  16. package/lib/components/Editor/ImageEditor.d.ts.map +1 -1
  17. package/lib/components/Editor/ImageEditor.js +56 -40
  18. package/lib/components/Editor/ImageEditor.js.map +1 -1
  19. package/lib/components/Editor/Toolbar/AnchorButton.d.ts.map +1 -1
  20. package/lib/components/Editor/Toolbar/AnchorButton.js +5 -4
  21. package/lib/components/Editor/Toolbar/AnchorButton.js.map +1 -1
  22. package/lib/components/Editor/Toolbar/TextSelect.d.ts +18 -3
  23. package/lib/components/Editor/Toolbar/TextSelect.d.ts.map +1 -1
  24. package/lib/components/Editor/Toolbar/TextSelect.js +63 -23
  25. package/lib/components/Editor/Toolbar/TextSelect.js.map +1 -1
  26. package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +1 -1
  27. package/lib/components/Editor/Toolbar/Toolbar.js +4 -2
  28. package/lib/components/Editor/Toolbar/Toolbar.js.map +1 -1
  29. package/lib/components/RichTextEditor/DecoratorComponents/BlockQuote.d.ts +1 -1
  30. package/lib/components/RichTextEditor/DecoratorComponents/BlockQuote.d.ts.map +1 -1
  31. package/lib/components/RichTextEditor/DecoratorComponents/Code.d.ts +1 -1
  32. package/lib/components/RichTextEditor/DecoratorComponents/Code.d.ts.map +1 -1
  33. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts +1 -1
  34. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts.map +1 -1
  35. package/lib/components/RichTextEditor/DecoratorComponents/HorizontalRule.d.ts +1 -1
  36. package/lib/components/RichTextEditor/DecoratorComponents/HorizontalRule.d.ts.map +1 -1
  37. package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts +5 -2
  38. package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts.map +1 -1
  39. package/lib/components/RichTextEditor/DecoratorComponents/Image.js.map +1 -1
  40. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +4 -5
  41. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +1 -1
  42. package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +1 -1
  43. package/lib/components/RichTextEditor/RichTextEditor.d.ts +2 -3
  44. package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +1 -1
  45. package/lib/components/RichTextEditor/RichTextEditor.js +12 -3
  46. package/lib/components/RichTextEditor/RichTextEditor.js.map +1 -1
  47. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +1 -1
  48. package/lib/components/RichTextEditor/RichTextEditor.styles.js +4 -0
  49. package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -1
  50. package/lib/components/RichTextEditor/RichTextTreeRenderer.d.ts +2 -2
  51. package/lib/components/RichTextEditor/RichTextTreeRenderer.d.ts.map +1 -1
  52. package/lib/components/RichTextEditor/RichTextTreeRenderer.js.map +1 -1
  53. package/lib/components/RichTextEditor/RichTextViewer.d.ts +2 -3
  54. package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +1 -1
  55. package/lib/components/RichTextEditor/RichTextViewer.js +34 -3
  56. package/lib/components/RichTextEditor/RichTextViewer.js.map +1 -1
  57. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +13 -7
  58. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +1 -1
  59. package/lib/components/RichTextEditor/RichTextViewer.types.js.map +1 -1
  60. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts.map +1 -1
  61. package/lib/components/RichTextEditor/Toolbar/TextSelect.js +10 -2
  62. package/lib/components/RichTextEditor/Toolbar/TextSelect.js.map +1 -1
  63. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +1 -1
  64. package/lib/components/RichTextEditor/utils/EditorCommands.js.map +1 -1
  65. package/lib/components/RichTextEditor/utils/ListCommands.js.map +1 -1
  66. package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -1
  67. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts +2 -2
  68. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +1 -1
  69. package/lib/components/RichTextEditor/utils/markdownConverter.js +1 -3
  70. package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -1
  71. package/lib/components/RichTextEditor/utils/renderers.d.ts +7 -5
  72. package/lib/components/RichTextEditor/utils/renderers.d.ts.map +1 -1
  73. package/lib/components/RichTextEditor/utils/renderers.js.map +1 -1
  74. package/lib/components/RichTextEditor/utils/slateConverter.js.map +1 -1
  75. package/package.json +10 -11
  76. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts +0 -4
  77. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts.map +0 -1
  78. package/lib/components/RichTextEditor/DecoratorComponents/Link.js +0 -8
  79. package/lib/components/RichTextEditor/DecoratorComponents/Link.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextTreeRenderer.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextTreeRenderer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIjC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAI/D,MAAM,OAAO,GAAG,CAAC,IAAgB,EAAE,KAAa,EAAE,EAAE;IAClD,IAAI,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAkB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3F,OAAO,KAAC,QAAQ,cAAc,YAAY,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,IAA3C,KAAK,CAAkD,CAAC;IAChF,CAAC;IACD,OAAO,KAAC,QAAQ,cAAc,YAAY,CAAC,IAAI,CAAC,IAA1B,KAAK,CAAiC,CAAC;AAC/D,CAAC,CAAC;AAMF,MAAM,CAAC,MAAM,oBAAoB,GAAkC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC/E,OAAO,4BAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAI,CAAC;AACzD,CAAC,CAAC","sourcesContent":["import { Fragment } from 'react';\nimport type { FC } from 'react';\nimport type { CosmosCustom } from 'slate';\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { nodeRenderer, leafRenderer } from './utils/renderers';\n\ntype CosmosNode = CosmosCustom.Element | CosmosCustom.Text;\n\nconst getNode = (node: CosmosNode, index: number) => {\n if (hasProp(node, 'children')) {\n const children: JSX.Element[] = node.children.map((childNode, i) => getNode(childNode, i));\n return <Fragment key={index}>{nodeRenderer({ ...node, children })}</Fragment>;\n }\n return <Fragment key={index}>{leafRenderer(node)}</Fragment>;\n};\n\nexport interface RichTextTreeRendererProps {\n nodes: CosmosNode[];\n}\n\nexport const RichTextTreeRenderer: FC<RichTextTreeRendererProps> = ({ nodes }) => {\n return <>{nodes.map((node, i) => getNode(node, i))}</>;\n};\n"]}
1
+ {"version":3,"file":"RichTextTreeRenderer.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextTreeRenderer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIjC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAI/D,MAAM,OAAO,GAAG,CAAC,IAAgB,EAAE,KAAa,EAAE,EAAE;IAClD,IAAI,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAkB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3F,OAAO,KAAC,QAAQ,cAAc,YAAY,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,IAA3C,KAAK,CAAkD,CAAC;IAChF,CAAC;IACD,OAAO,KAAC,QAAQ,cAAc,YAAY,CAAC,IAAI,CAAC,IAA1B,KAAK,CAAiC,CAAC;AAC/D,CAAC,CAAC;AAMF,MAAM,CAAC,MAAM,oBAAoB,GAAkC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC/E,OAAO,4BAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAI,CAAC;AACzD,CAAC,CAAC","sourcesContent":["import { Fragment } from 'react';\nimport type { FC } from 'react';\nimport type { PegaCustom } from 'slate';\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { nodeRenderer, leafRenderer } from './utils/renderers';\n\ntype CosmosNode = PegaCustom.Element | PegaCustom.Text;\n\nconst getNode = (node: CosmosNode, index: number) => {\n if (hasProp(node, 'children')) {\n const children: JSX.Element[] = node.children.map((childNode, i) => getNode(childNode, i));\n return <Fragment key={index}>{nodeRenderer({ ...node, children })}</Fragment>;\n }\n return <Fragment key={index}>{leafRenderer(node)}</Fragment>;\n};\n\nexport interface RichTextTreeRendererProps {\n nodes: CosmosNode[];\n}\n\nexport const RichTextTreeRenderer: FC<RichTextTreeRendererProps> = ({ nodes }) => {\n return <>{nodes.map((node, i) => getNode(node, i))}</>;\n};\n"]}
@@ -1,8 +1,7 @@
1
- import type { FC } from 'react';
2
- import type { ForwardProps } from '@pega/cosmos-react-core';
1
+ import type { ForwardRefForwardPropsComponent } from '@pega/cosmos-react-core';
3
2
  import type { RichTextViewerProps } from './RichTextViewer.types';
4
3
  export declare const URL_REGEX: RegExp;
5
- declare const _default: FC<RichTextViewerProps & ForwardProps> & {
4
+ declare const _default: ForwardRefForwardPropsComponent<RichTextViewerProps> & {
6
5
  getTestIds: (testIdProp?: import("@pega/cosmos-react-core").TestIdProp["testId"]) => import("@pega/cosmos-react-core").TestIdsRecord<readonly []>;
7
6
  };
8
7
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextViewer.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAO,MAAM,OAAO,CAAC;AAGrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAQlE,eAAO,MAAM,SAAS,QACoK,CAAC;;;;AA0D3L,wBAAqE"}
1
+ {"version":3,"file":"RichTextViewer.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAG/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAQlE,eAAO,MAAM,SAAS,QACoK,CAAC;;;;AA4F3L,wBAAqE"}
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef, useState, useEffect } from 'react';
3
- import { HTML, ErrorState, useI18n, useTestIds, withTestIds } from '@pega/cosmos-react-core';
3
+ import { HTML, ErrorState, useI18n, useTestIds, withTestIds, hasProp } from '@pega/cosmos-react-core';
4
4
  import convertMarkdown from './utils/markdownConverter';
5
5
  import { StyledEditorContainer, StyledRichTextViewer } from './RichTextEditor.styles';
6
6
  import { convertHtml } from './utils/htmlConverter';
@@ -8,14 +8,45 @@ import { RichTextTreeRenderer } from './RichTextTreeRenderer';
8
8
  import { getRichTextViewerTestIds } from './RichTextViewer.test-ids';
9
9
  // Regex to match valid URLs
10
10
  export const URL_REGEX = /(?<leadingChar>^|\s)(?<url>(?<protocol>https?:\/\/)?(?<host>[a-z0-9]+(?:[-.][a-z0-9]+)*\.(?<tld>[a-z]{2,5})(?<port>:[0-9]{1,5})?)(?<pathQueryHash>[/a-zA-Z0-9?=&+%@.|#_~:[\]'()-]*)?)/g;
11
- const RichTextViewer = forwardRef(function RichTextViewer({ testId, content, type, interactionRenderers, markdownMap, onRetry, ...restProps }, ref) {
11
+ const isValidHTTPURL = (href) => {
12
+ if (!href)
13
+ return false;
14
+ try {
15
+ const url = new URL(href, window.location.href);
16
+ return url.protocol.startsWith('http');
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ };
22
+ const findFirstHref = (nodes) => {
23
+ for (const node of nodes) {
24
+ if (hasProp(node, 'children')) {
25
+ const href = findFirstHref(node.children);
26
+ if (isValidHTTPURL(href)) {
27
+ return href;
28
+ }
29
+ }
30
+ else if (isValidHTTPURL(node.href)) {
31
+ return node.href;
32
+ }
33
+ }
34
+ };
35
+ const RichTextViewer = forwardRef(function RichTextViewer({ testId, content, type, interactionRenderers, markdownMap, onRetry, onMarkdownLinkRender, ...restProps }, ref) {
12
36
  const testIds = useTestIds(testId, getRichTextViewerTestIds);
13
37
  const t = useI18n();
14
38
  const [nodes, setNodes] = useState([]);
15
39
  const [error, setError] = useState(false);
16
40
  useEffect(() => {
17
41
  if (type === 'markdown') {
18
- setNodes(convertMarkdown(content, [...(interactionRenderers || []), { regexPattern: URL_REGEX, type: 'builtin-url' }], markdownMap));
42
+ const newNodes = convertMarkdown(content, [...(interactionRenderers ?? []), { regexPattern: URL_REGEX, type: 'builtin-url' }], markdownMap);
43
+ if (onMarkdownLinkRender) {
44
+ const href = findFirstHref(newNodes);
45
+ if (href) {
46
+ onMarkdownLinkRender(href);
47
+ }
48
+ }
49
+ setNodes(newNodes);
19
50
  }
20
51
  if (type === 'richtext') {
21
52
  setNodes(JSON.parse(content));
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextViewer.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGxD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG7F,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAErE,4BAA4B;AAC5B,MAAM,C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OAAO,EAAE,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAE1C,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,oBAAoB,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC;QACpF,OAAO,KAAC,IAAI,IAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAI,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,UAAU,IAAC,OAAO,EAAE,CAAC,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,OAAO,GAAI,CACjE,CAAC,CAAC,CAAC,CACF,KAAC,oBAAoB,mBAAc,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,KAAM,SAAS,YACtE,KAAC,qBAAqB,cACpB,KAAC,oBAAoB,IAAC,KAAK,EAAE,KAAK,GAAI,GAChB,GACH,CACxB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,cAAc,EAAE,wBAAwB,CAAC,CAAC","sourcesContent":["import { forwardRef, useState, useEffect } from 'react';\nimport type { FC, Ref } from 'react';\n\nimport { HTML, ErrorState, useI18n, useTestIds, withTestIds } from '@pega/cosmos-react-core';\nimport type { ForwardProps } from '@pega/cosmos-react-core';\n\nimport convertMarkdown from './utils/markdownConverter';\nimport type { RichTextViewerProps } from './RichTextViewer.types';\nimport { StyledEditorContainer, StyledRichTextViewer } from './RichTextEditor.styles';\nimport { convertHtml } from './utils/htmlConverter';\nimport { RichTextTreeRenderer } from './RichTextTreeRenderer';\nimport type { RichTextTreeRendererProps } from './RichTextTreeRenderer';\nimport { getRichTextViewerTestIds } from './RichTextViewer.test-ids';\n\n// Regex to match valid URLs\nexport const URL_REGEX =\n /(?<leadingChar>^|\\s)(?<url>(?<protocol>https?:\\/\\/)?(?<host>[a-z0-9]+(?:[-.][a-z0-9]+)*\\.(?<tld>[a-z]{2,5})(?<port>:[0-9]{1,5})?)(?<pathQueryHash>[/a-zA-Z0-9?=&+%@.|#_~:[\\]'()-]*)?)/g;\n\nconst RichTextViewer: FC<RichTextViewerProps & ForwardProps> = forwardRef(function RichTextViewer(\n {\n testId,\n content,\n type,\n interactionRenderers,\n markdownMap,\n onRetry,\n ...restProps\n }: RichTextViewerProps,\n ref: Ref<HTMLDivElement>\n) {\n const testIds = useTestIds(testId, getRichTextViewerTestIds);\n const t = useI18n();\n const [nodes, setNodes] = useState<RichTextTreeRendererProps['nodes']>([]);\n const [error, setError] = useState(false);\n\n useEffect(() => {\n if (type === 'markdown') {\n setNodes(\n convertMarkdown(\n content,\n [...(interactionRenderers || []), { regexPattern: URL_REGEX, type: 'builtin-url' }],\n markdownMap\n )\n );\n }\n if (type === 'richtext') {\n setNodes(JSON.parse(content));\n }\n if (type === 'html' && interactionRenderers && interactionRenderers.length > 0) {\n try {\n setNodes(convertHtml(content, interactionRenderers));\n setError(false);\n } catch {\n setNodes([]);\n setError(true);\n }\n }\n }, [content, type, interactionRenderers]);\n\n if (type === 'html' && (!interactionRenderers || interactionRenderers.length === 0)) {\n return <HTML ref={ref} content={content} />;\n }\n\n return error ? (\n <ErrorState message={t('rte_invalid_html')} onRetry={onRetry} />\n ) : (\n <StyledRichTextViewer data-testid={testIds.root} ref={ref} {...restProps}>\n <StyledEditorContainer>\n <RichTextTreeRenderer nodes={nodes} />\n </StyledEditorContainer>\n </StyledRichTextViewer>\n );\n});\n\nexport default withTestIds(RichTextViewer, getRichTextViewerTestIds);\n"]}
1
+ {"version":3,"file":"RichTextViewer.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIxD,OAAO,EACL,IAAI,EACJ,UAAU,EACV,OAAO,EACP,UAAU,EACV,WAAW,EACX,OAAO,EACR,MAAM,yBAAyB,CAAC;AAGjC,OAAO,eAAe,M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EAAE,CAAC,CAAC;gBACb,QAAQ,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAE1C,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,oBAAoB,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC;QACpF,OAAO,KAAC,IAAI,IAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAI,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,UAAU,IAAC,OAAO,EAAE,CAAC,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,OAAO,GAAI,CACjE,CAAC,CAAC,CAAC,CACF,KAAC,oBAAoB,mBAAc,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,KAAM,SAAS,YACtE,KAAC,qBAAqB,cACpB,KAAC,oBAAoB,IAAC,KAAK,EAAE,KAAK,GAAI,GAChB,GACH,CACxB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,cAAc,EAAE,wBAAwB,CAAC,CAAC","sourcesContent":["import { forwardRef, useState, useEffect } from 'react';\nimport type { PropsWithoutRef } from 'react';\nimport type { PegaCustom } from 'slate';\n\nimport {\n HTML,\n ErrorState,\n useI18n,\n useTestIds,\n withTestIds,\n hasProp\n} from '@pega/cosmos-react-core';\nimport type { ForwardRefForwardPropsComponent } from '@pega/cosmos-react-core';\n\nimport convertMarkdown from './utils/markdownConverter';\nimport type { RichTextViewerProps } from './RichTextViewer.types';\nimport { StyledEditorContainer, StyledRichTextViewer } from './RichTextEditor.styles';\nimport { convertHtml } from './utils/htmlConverter';\nimport { RichTextTreeRenderer } from './RichTextTreeRenderer';\nimport type { RichTextTreeRendererProps } from './RichTextTreeRenderer';\nimport { getRichTextViewerTestIds } from './RichTextViewer.test-ids';\n\n// Regex to match valid URLs\nexport const URL_REGEX =\n /(?<leadingChar>^|\\s)(?<url>(?<protocol>https?:\\/\\/)?(?<host>[a-z0-9]+(?:[-.][a-z0-9]+)*\\.(?<tld>[a-z]{2,5})(?<port>:[0-9]{1,5})?)(?<pathQueryHash>[/a-zA-Z0-9?=&+%@.|#_~:[\\]'()-]*)?)/g;\n\nconst isValidHTTPURL = (href?: string): boolean => {\n if (!href) return false;\n\n try {\n const url = new URL(href, window.location.href);\n return url.protocol.startsWith('http');\n } catch {\n return false;\n }\n};\n\nconst findFirstHref = (nodes: (PegaCustom.Element | PegaCustom.Text)[]): string | undefined => {\n for (const node of nodes) {\n if (hasProp(node, 'children')) {\n const href = findFirstHref(node.children);\n if (isValidHTTPURL(href)) {\n return href;\n }\n } else if (isValidHTTPURL(node.href)) {\n return node.href;\n }\n }\n};\n\nconst RichTextViewer: ForwardRefForwardPropsComponent<RichTextViewerProps> = forwardRef(\n function RichTextViewer(\n {\n testId,\n content,\n type,\n interactionRenderers,\n markdownMap,\n onRetry,\n onMarkdownLinkRender,\n ...restProps\n }: PropsWithoutRef<RichTextViewerProps>,\n ref: RichTextViewerProps['ref']\n ) {\n const testIds = useTestIds(testId, getRichTextViewerTestIds);\n const t = useI18n();\n const [nodes, setNodes] = useState<RichTextTreeRendererProps['nodes']>([]);\n const [error, setError] = useState(false);\n\n useEffect(() => {\n if (type === 'markdown') {\n const newNodes = convertMarkdown(\n content,\n [...(interactionRenderers ?? []), { regexPattern: URL_REGEX, type: 'builtin-url' }],\n markdownMap\n );\n\n if (onMarkdownLinkRender) {\n const href = findFirstHref(newNodes);\n if (href) {\n onMarkdownLinkRender(href);\n }\n }\n\n setNodes(newNodes);\n }\n if (type === 'richtext') {\n setNodes(JSON.parse(content));\n }\n if (type === 'html' && interactionRenderers && interactionRenderers.length > 0) {\n try {\n setNodes(convertHtml(content, interactionRenderers));\n setError(false);\n } catch {\n setNodes([]);\n setError(true);\n }\n }\n }, [content, type, interactionRenderers]);\n\n if (type === 'html' && (!interactionRenderers || interactionRenderers.length === 0)) {\n return <HTML ref={ref} content={content} />;\n }\n\n return error ? (\n <ErrorState message={t('rte_invalid_html')} onRetry={onRetry} />\n ) : (\n <StyledRichTextViewer data-testid={testIds.root} ref={ref} {...restProps}>\n <StyledEditorContainer>\n <RichTextTreeRenderer nodes={nodes} />\n </StyledEditorContainer>\n </StyledRichTextViewer>\n );\n }\n);\n\nexport default withTestIds(RichTextViewer, getRichTextViewerTestIds);\n"]}
@@ -1,5 +1,5 @@
1
- import type { marked } from 'marked';
2
- import type { ComponentType, FC } from 'react';
1
+ import type { MarkedToken, Tokens } from 'marked';
2
+ import type { ComponentType, Ref } from 'react';
3
3
  import type { ErrorStateProps, ExcludeStrict, TestIdProp } from '@pega/cosmos-react-core';
4
4
  export interface InteractionRenderers {
5
5
  type: string;
@@ -14,20 +14,26 @@ export interface InteractionRenderers {
14
14
  } | undefined;
15
15
  }
16
16
  export type TokenMap = {
17
- [K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]: Extract<marked.Token, {
17
+ [K in ExcludeStrict<MarkedToken, Tokens.Def>['type']]: Extract<MarkedToken, {
18
18
  type: K;
19
19
  }>;
20
20
  };
21
21
  export type MDMap = {
22
- [K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]?: (token: TokenMap[K]) => FC<{
22
+ [K in ExcludeStrict<MarkedToken, Tokens.Def>['type']]?: (token: TokenMap[K]) => ComponentType<{
23
23
  token: TokenMap[K];
24
24
  }> | undefined;
25
25
  };
26
- export interface RichTextViewerProps extends TestIdProp {
26
+ export type RichTextViewerProps = TestIdProp & {
27
27
  content: string;
28
- type: 'markdown' | 'html' | 'richtext';
29
28
  interactionRenderers?: InteractionRenderers[];
30
29
  markdownMap?: MDMap;
31
30
  onRetry?: ErrorStateProps['onRetry'];
32
- }
31
+ ref?: Ref<HTMLDivElement>;
32
+ } & ({
33
+ type: 'markdown';
34
+ onMarkdownLinkRender?: (href: string) => void;
35
+ } | {
36
+ type: 'html' | 'richtext';
37
+ onMarkdownLinkRender?: never;
38
+ });
33
39
  //# sourceMappingURL=RichTextViewer.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextViewer.types.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1F,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,CACpB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,KAElB;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC7F,SAAS,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,GAAG;KACpB,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC;CAClG,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;KACjB,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAA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M,QAAQ,GAAG;KACpB,CAAC,IAAI,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC;CACzF,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;KACjB,CAAC,IAAI,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CACtD,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KACf,aAAa,CAAC;QAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC,GAAG,SAAS;CACvD,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAC9C,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACrC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B,GAAG,CACE;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,oBAAoB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAAC,oBAAoB,CAAC,EAAE,KAAK,CAAA;CAAE,CAC9D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextViewer.types.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { marked } from 'marked';\nimport type { ComponentType, FC } from 'react';\n\nimport type { ErrorStateProps, ExcludeStrict, TestIdProp } from '@pega/cosmos-react-core';\n\nexport interface InteractionRenderers {\n type: string;\n regexPattern: RegExp;\n xmlElement?: string;\n component?: ComponentType<any>;\n getSearchAttributes?: (\n xmlElement: string,\n searchResult: string\n ) =>\n | { markdown: string; component: ComponentType<any>; props: Record<string, any>; text: string }\n | undefined;\n}\n\nexport type TokenMap = {\n [K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]: Extract<marked.Token, { type: K }>;\n};\n\nexport type MDMap = {\n [K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]?: (\n token: TokenMap[K]\n ) => FC<{ token: TokenMap[K] }> | undefined;\n};\n\nexport interface RichTextViewerProps extends TestIdProp {\n content: string;\n type: 'markdown' | 'html' | 'richtext';\n interactionRenderers?: InteractionRenderers[];\n markdownMap?: MDMap;\n onRetry?: ErrorStateProps['onRetry'];\n}\n"]}
1
+ {"version":3,"file":"RichTextViewer.types.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MarkedToken, Tokens } from 'marked';\nimport type { ComponentType, Ref } from 'react';\n\nimport type { ErrorStateProps, ExcludeStrict, TestIdProp } from '@pega/cosmos-react-core';\n\nexport interface InteractionRenderers {\n type: string;\n regexPattern: RegExp;\n xmlElement?: string;\n component?: ComponentType<any>;\n getSearchAttributes?: (\n xmlElement: string,\n searchResult: string\n ) =>\n | { markdown: string; component: ComponentType<any>; props: Record<string, any>; text: string }\n | undefined;\n}\n\nexport type TokenMap = {\n [K in ExcludeStrict<MarkedToken, Tokens.Def>['type']]: Extract<MarkedToken, { type: K }>;\n};\n\nexport type MDMap = {\n [K in ExcludeStrict<MarkedToken, Tokens.Def>['type']]?: (\n token: TokenMap[K]\n ) => ComponentType<{ token: TokenMap[K] }> | undefined;\n};\n\nexport type RichTextViewerProps = TestIdProp & {\n content: string;\n interactionRenderers?: InteractionRenderers[];\n markdownMap?: MDMap;\n onRetry?: ErrorStateProps['onRetry'];\n ref?: Ref<HTMLDivElement>;\n} & (\n | { type: 'markdown'; onMarkdownLinkRender?: (href: string) => void }\n | { type: 'html' | 'richtext'; onMarkdownLinkRender?: never }\n );\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"TextSelect.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/TextSelect.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAyC,MAAM,OAAO,CAAC;AA0DvE,QAAA,MAAM,UAAU,EAAE,EAAE,CAAC;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,CAmIpC,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"TextSelect.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/TextSelect.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAyC,MAAM,OAAO,CAAC;AA0DvE,QAAA,MAAM,UAAU,EAAE,EAAE,CAAC;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,CA2IpC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -48,7 +48,11 @@ const TextSelect = ({ osx }) => {
48
48
  const editor = useSlate();
49
49
  const textFormats = useCallback(() => {
50
50
  return [
51
- { text: t('rte_heading_style_normal'), subText: getTextCommand(0, osx), type: 'paragraph' },
51
+ {
52
+ text: t('rte_heading_style_normal'),
53
+ subText: getTextCommand(0, osx),
54
+ type: 'paragraph'
55
+ },
52
56
  {
53
57
  text: t('rte_heading_style_heading_1'),
54
58
  subText: getTextCommand(1, osx),
@@ -64,7 +68,11 @@ const TextSelect = ({ osx }) => {
64
68
  subText: getTextCommand(3, osx),
65
69
  type: 'heading-3'
66
70
  },
67
- { text: t('rte_heading_style_heading_4'), subText: getTextCommand(4, osx), type: 'heading-4' }
71
+ {
72
+ text: t('rte_heading_style_heading_4'),
73
+ subText: getTextCommand(4, osx),
74
+ type: 'heading-4'
75
+ }
68
76
  ];
69
77
  }, [osx])();
70
78
  const textMapping = {
@@ -1 +1 @@
1
- {"version":3,"file":"TextSelect.js","sourceRoot":"","sources":["../../../../src/components/RichText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E,SAAS,CAAC,OAAO,IAAI,SAAS,EAC9C,IAAI,EAAC,eAAe,EACpB,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,YAAmD,GAChE,GACM,IACT,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { useRef, useState, useCallback } from 'react';\nimport type { FC, MouseEvent, KeyboardEvent, FocusEvent } from 'react';\nimport { Transforms } from 'slate';\nimport type { Element } from 'slate';\nimport { ReactEditor, useSlate } from 'slate-react';\nimport styled, { css } from 'styled-components';\n\nimport {\n Popover,\n Icon,\n registerIcon,\n useOuterEvent,\n Menu,\n Button,\n defaultThemeProp,\n useI18n,\n Tooltip,\n calculateFontSize\n} from '@pega/cosmos-react-core';\nimport * as arrowMicroDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/arrow-micro-down.icon';\n\nimport EditorCommands from '../utils/EditorCommands';\nimport { useRTEContext } from '../RichTextEditor.context';\n\nimport { getKeyCommand } from './utils';\n\nregisterIcon(arrowMicroDownIcon);\n\nconst StyledTextSelect = styled(Button)(({ theme }) => {\n const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n return css`\n color: ${theme.base.palette['foreground-color']};\n display: inline-flex;\n align-items: center;\n border-radius: calc(0.25 * ${theme.base['border-radius']});\n height: calc(4 * ${theme.base.spacing});\n padding: calc(0.5 * ${theme.base.spacing});\n font-size: ${fontSizes.xxs};\n\n span {\n white-space: nowrap;\n }\n\n :focus {\n box-shadow: ${theme.base.shadow.focus};\n }\n `;\n});\n\nStyledTextSelect.defaultProps = defaultThemeProp;\n\nconst StyledSelectMenu = styled.div`\n min-width: 10rem;\n`;\n\nconst getTextCommand = (num: number, osx: boolean) => {\n return getKeyCommand(osx, ({ ctrl, alt }) => `${ctrl}${alt}${num}`);\n};\n\nconst TextSelect: FC<{ osx: boolean }> = ({ osx }) => {\n const t = useI18n();\n const { disabled } = useRTEContext();\n const [open, setOpen] = useState(false);\n const selecting = useRef(false);\n const openedByClick = useRef(false);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const popoverRef = useRef(null);\n const menuRef = useRef(null);\n const editor = useSlate();\n\n const textFormats = useCallback(() => {\n return [\n { text: t('rte_heading_style_normal'), subText: getTextCommand(0, osx), type: 'paragraph' },\n {\n text: t('rte_heading_style_heading_1'),\n subText: getTextCommand(1, osx),\n type: 'heading-1'\n },\n {\n text: t('rte_heading_style_heading_2'),\n subText: getTextCommand(2, osx),\n type: 'heading-2'\n },\n {\n text: t('rte_heading_style_heading_3'),\n subText: getTextCommand(3, osx),\n type: 'heading-3'\n },\n { text: t('rte_heading_style_heading_4'), subText: getTextCommand(4, osx), type: 'heading-4' }\n ];\n }, [osx])();\n\n const textMapping: { [key: string]: string } = {\n paragraph: t('rte_heading_style_normal'),\n 'heading-1': t('rte_heading_style_heading_1'),\n 'heading-2': t('rte_heading_style_heading_2'),\n 'heading-3': t('rte_heading_style_heading_3'),\n 'heading-4': t('rte_heading_style_heading_4'),\n '': t('rte_heading_style_normal')\n };\n\n useOuterEvent('click', [buttonRef, popoverRef, menuRef], () => {\n setOpen(false);\n });\n\n const onTextSelect = (type: Element['type'], e: MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n EditorCommands.setBlock(type, editor);\n if (!openedByClick.current) {\n buttonRef.current?.focus();\n }\n setOpen(false);\n selecting.current = true;\n setTimeout(() => {\n if (!ReactEditor.isFocused(editor) && openedByClick.current) {\n const selection = editor.selection;\n ReactEditor.focus(editor);\n if (selection) Transforms.select(editor, selection);\n }\n }, 0);\n };\n\n return (\n <>\n <StyledTextSelect\n variant='simple'\n type='button'\n disabled={disabled}\n icon={false}\n ref={buttonRef}\n onMouseDown={(e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n setOpen(true);\n openedByClick.current = true;\n }}\n onKeyDown={(e: KeyboardEvent) => {\n if (e.key === 'Enter' && !selecting.current) {\n e.preventDefault();\n setOpen(true);\n openedByClick.current = false;\n } else if (e.key === 'Enter') {\n e.preventDefault();\n selecting.current = false;\n } else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {\n setOpen(false);\n }\n }}\n onFocus={(e: FocusEvent) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onClick={(e: MouseEvent) => e.stopPropagation()}\n aria-expanded={open}\n aria-label={`Text formatting toolbar. ${t('rte_heading_style')}. ${\n textMapping[EditorCommands.getActiveBlockType(editor)]\n } selected`}\n aria-haspopup\n >\n <span>{textMapping[EditorCommands.getActiveBlockType(editor)]}</span>\n <Icon name='arrow-micro-down' />\n </StyledTextSelect>\n {buttonRef.current && (\n <Tooltip target={buttonRef.current} showDelay='none' hideDelay='none'>\n {t('rte_heading_style')}\n </Tooltip>\n )}\n <Popover\n show={open}\n as={StyledSelectMenu}\n target={buttonRef.current}\n placement='bottom-start'\n ref={popoverRef}\n >\n <Menu\n items={textFormats.map(({ text, type, subText }) => ({\n id: type,\n primary: text,\n secondary: [subText],\n selected: type === EditorCommands.getActiveBlockType(editor)\n }))}\n focusControlEl={buttonRef.current || undefined}\n mode='single-select'\n ref={menuRef}\n onItemClick={onTextSelect as (id: string, e: MouseEvent) => void}\n />\n </Popover>\n </>\n );\n};\n\nexport default TextSelect;\n"]}
1
+ {"version":3,"file":"TextSelect.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/TextSelect.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,MAAM,EACN,gBAAgB,EAChB,OAAO,EACP,OAAO,EACP,iBAAiB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kBAAkB,CAAC,MAAM,CAAC,CACvD,WAAW,oCAGX,yBAAO,WAAW,CAAC,cAAc,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,GAAQ,EACrE,KAAC,IAAI,IAAC,IAAI,EAAC,kBAAkB,GAAG,IACf,EAClB,SAAS,CAAC,OAAO,IAAI,CACpB,KAAC,OAAO,IAAC,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,EAAC,MAAM,EAAC,SAAS,EAAC,MAAM,YAClE,CAAC,CAAC,mBAAmB,CAAC,GACf,CACX,EACD,KAAC,OAAO,IACN,IAAI,EAAE,IAAI,EACV,EAAE,EAAE,gBAAgB,EACpB,MAAM,EAAE,SAAS,CAAC,OAAO,EACzB,SAAS,EAAC,cAAc,EACxB,GAAG,EAAE,UAAU,YAEf,KAAC,IAAI,IACH,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;wBACnD,EAAE,EAAE,IAAI;wBACR,OAAO,EAAE,IAAI;wBACb,SAAS,EAAE,CAAC,OAAO,CAAC;wBACpB,QAAQ,EAAE,IAAI,KAAK,cAAc,CAAC,kBAAkB,CAAC,MAAM,CAAC;qBAC7D,CAAC,CAAC,EACH,cAAc,EAAE,SAAS,CAAC,OAAO,IAAI,SAAS,EAC9C,IAAI,EAAC,eAAe,EACpB,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,YAAmD,GAChE,GACM,IACT,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { useRef, useState, useCallback } from 'react';\nimport type { FC, MouseEvent, KeyboardEvent, FocusEvent } from 'react';\nimport { Transforms } from 'slate';\nimport type { Element } from 'slate';\nimport { ReactEditor, useSlate } from 'slate-react';\nimport styled, { css } from 'styled-components';\n\nimport {\n Popover,\n Icon,\n registerIcon,\n useOuterEvent,\n Menu,\n Button,\n defaultThemeProp,\n useI18n,\n Tooltip,\n calculateFontSize\n} from '@pega/cosmos-react-core';\nimport * as arrowMicroDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/arrow-micro-down.icon';\n\nimport EditorCommands from '../utils/EditorCommands';\nimport { useRTEContext } from '../RichTextEditor.context';\n\nimport { getKeyCommand } from './utils';\n\nregisterIcon(arrowMicroDownIcon);\n\nconst StyledTextSelect = styled(Button)(({ theme }) => {\n const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n return css`\n color: ${theme.base.palette['foreground-color']};\n display: inline-flex;\n align-items: center;\n border-radius: calc(0.25 * ${theme.base['border-radius']});\n height: calc(4 * ${theme.base.spacing});\n padding: calc(0.5 * ${theme.base.spacing});\n font-size: ${fontSizes.xxs};\n\n span {\n white-space: nowrap;\n }\n\n :focus {\n box-shadow: ${theme.base.shadow.focus};\n }\n `;\n});\n\nStyledTextSelect.defaultProps = defaultThemeProp;\n\nconst StyledSelectMenu = styled.div`\n min-width: 10rem;\n`;\n\nconst getTextCommand = (num: number, osx: boolean) => {\n return getKeyCommand(osx, ({ ctrl, alt }) => `${ctrl}${alt}${num}`);\n};\n\nconst TextSelect: FC<{ osx: boolean }> = ({ osx }) => {\n const t = useI18n();\n const { disabled } = useRTEContext();\n const [open, setOpen] = useState(false);\n const selecting = useRef(false);\n const openedByClick = useRef(false);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const popoverRef = useRef(null);\n const menuRef = useRef(null);\n const editor = useSlate();\n\n const textFormats = useCallback(() => {\n return [\n {\n text: t('rte_heading_style_normal'),\n subText: getTextCommand(0, osx),\n type: 'paragraph'\n },\n {\n text: t('rte_heading_style_heading_1'),\n subText: getTextCommand(1, osx),\n type: 'heading-1'\n },\n {\n text: t('rte_heading_style_heading_2'),\n subText: getTextCommand(2, osx),\n type: 'heading-2'\n },\n {\n text: t('rte_heading_style_heading_3'),\n subText: getTextCommand(3, osx),\n type: 'heading-3'\n },\n {\n text: t('rte_heading_style_heading_4'),\n subText: getTextCommand(4, osx),\n type: 'heading-4'\n }\n ];\n }, [osx])();\n\n const textMapping: { [key: string]: string } = {\n paragraph: t('rte_heading_style_normal'),\n 'heading-1': t('rte_heading_style_heading_1'),\n 'heading-2': t('rte_heading_style_heading_2'),\n 'heading-3': t('rte_heading_style_heading_3'),\n 'heading-4': t('rte_heading_style_heading_4'),\n '': t('rte_heading_style_normal')\n };\n\n useOuterEvent('click', [buttonRef, popoverRef, menuRef], () => {\n setOpen(false);\n });\n\n const onTextSelect = (type: Element['type'], e: MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n EditorCommands.setBlock(type, editor);\n if (!openedByClick.current) {\n buttonRef.current?.focus();\n }\n setOpen(false);\n selecting.current = true;\n setTimeout(() => {\n if (!ReactEditor.isFocused(editor) && openedByClick.current) {\n const selection = editor.selection;\n ReactEditor.focus(editor);\n if (selection) Transforms.select(editor, selection);\n }\n }, 0);\n };\n\n return (\n <>\n <StyledTextSelect\n variant='simple'\n type='button'\n disabled={disabled}\n icon={false}\n ref={buttonRef}\n onMouseDown={(e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n setOpen(true);\n openedByClick.current = true;\n }}\n onKeyDown={(e: KeyboardEvent) => {\n if (e.key === 'Enter' && !selecting.current) {\n e.preventDefault();\n setOpen(true);\n openedByClick.current = false;\n } else if (e.key === 'Enter') {\n e.preventDefault();\n selecting.current = false;\n } else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {\n setOpen(false);\n }\n }}\n onFocus={(e: FocusEvent) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onClick={(e: MouseEvent) => e.stopPropagation()}\n aria-expanded={open}\n aria-label={`Text formatting toolbar. ${t('rte_heading_style')}. ${\n textMapping[EditorCommands.getActiveBlockType(editor)]\n } selected`}\n aria-haspopup\n >\n <span>{textMapping[EditorCommands.getActiveBlockType(editor)]}</span>\n <Icon name='arrow-micro-down' />\n </StyledTextSelect>\n {buttonRef.current && (\n <Tooltip target={buttonRef.current} showDelay='none' hideDelay='none'>\n {t('rte_heading_style')}\n </Tooltip>\n )}\n <Popover\n show={open}\n as={StyledSelectMenu}\n target={buttonRef.current}\n placement='bottom-start'\n ref={popoverRef}\n >\n <Menu\n items={textFormats.map(({ text, type, subText }) => ({\n id: type,\n primary: text,\n secondary: [subText],\n selected: type === EditorCommands.getActiveBlockType(editor)\n }))}\n focusControlEl={buttonRef.current || undefined}\n mode='single-select'\n ref={menuRef}\n onItemClick={onTextSelect as (id: string, e: MouseEvent) => void}\n />\n </Popover>\n </>\n );\n};\n\nexport default TextSelect;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"EditorCommands.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAc,KAAK,EAAQ,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,KAAK,EAAgB,IAAI,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAY7D,QAAA,MAAM,QAAQ;6BAEa,aAAa,CAAC,MAAM,IAAI,EAAE,MAAM,CAAC,UAAU,MAAM;2BAKnD,aAAa,CAAC,MAAM,IAAI,EAAE,MAAM,CAAC,UAAU,MAAM;4BAShD,OAAO,CAAC,MAAM,CAAC,UAAU,MAAM;iCAQ1B,MAAM,KAAG,MAAM;uBAazB,OAAO,CAAC,MAAM,CAAC,UAAU,MAAM;8BAIxB,MAAM,UAAU,KAAK,GAAG,IAAI,QAAQ,MAAM;+BAQzC,MAAM,UAAU,KAAK,GAAG,IAAI,QAAQ,IAAI;8BAOzC,MAAM,KAAG,SAAS,CAAC,IAAI,CAAC;0BAS5B,MAAM;0BA0CN,MAAM,aAAa;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EA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port { Editor, Transforms, Range, Path, Element, Text } from 'slate';\nimport type { CosmosCustom, Node, NodeEntry } from 'slate';\n\nimport type { ExcludeStrict } from '@pega/cosmos-react-core';\n\nimport ListCommands from './ListCommands';\n\nconst textKeyCodeMapping: { [key: number]: Element['type'] } = {\n 48: 'paragraph',\n 49: 'heading-1',\n 50: 'heading-2',\n 51: 'heading-3',\n 52: 'heading-4'\n};\n\nconst commands = {\n // Checks if an inline format is active\n isFormatActive: (format: ExcludeStrict<keyof Text, 'text'>, editor: Editor) => {\n const marks = Editor.marks(editor);\n return marks ? marks[format] === true : false;\n },\n // Toggles an inline format on or off\n toggleFormat: (format: ExcludeStrict<keyof Text, 'text'>, editor: Editor) => {\n const formatActive = commands.isFormatActive(format, editor);\n if (formatActive) {\n Editor.removeMark(editor, format);\n } else {\n Editor.addMark(editor, format, true);\n }\n },\n // Checks if a block level format is active\n isBlockActive: (format: Element['type'], editor: Editor) => {\n const [match] = Editor.nodes<Element>(editor, {\n match: n => Element.isElement(n) && n.type === format\n });\n\n return !!match;\n },\n // Gets the active block level type\n getActiveBlockType: (editor: Editor): string => {\n const [match] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: Element.isElement,\n mode: 'lowest'\n });\n\n if (match) {\n return match[0].type;\n }\n return '';\n },\n // Sets the block type of the currently selected block\n setBlock: (format: Element['type'], editor: Editor) => {\n Transforms.setNodes(editor, { type: format }, { mode: 'lowest' });\n },\n // Replaces a target in the editor with the given text\n replaceWithText: (editor: Editor, target: Range | null, text: string) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertText(editor, text);\n Transforms.move(editor);\n },\n // Replaces a target in the editor with the given node\n replaceWithNodes: (editor: Editor, target: Range | null, node: Node) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertNodes(editor, node);\n },\n // Gets the highest selected block level node\n getSelectedNode: (editor: Editor): NodeEntry<Node> => {\n const [node] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: n => Element.isElement(n),\n mode: 'highest'\n });\n return node;\n },\n // Appends a 3x3 table into the editor and adds a blank line to the bottom\n appendTable: (editor: Editor) => {\n const baseArr: unknown[][] = new Array(3).fill(new Array(3).fill(0));\n const table: [CosmosCustom.TableElement, CosmosCustom.ParagraphElement] = [\n {\n type: 'table',\n children: [\n {\n type: 'table-body',\n children: baseArr.map(row => {\n return {\n type: 'table-row',\n children: row.map(() => {\n return {\n type: 'table-cell',\n children: [{ type: 'paragraph', children: [{ text: '' }] }]\n };\n })\n };\n })\n }\n ]\n },\n {\n type: 'paragraph',\n children: [{ text: '' }]\n }\n ];\n\n Transforms.insertNodes(editor, table, { mode: 'highest' });\n const [firstTableCell] = Editor.nodes<CosmosCustom.ParagraphElement>(editor, {\n at: editor.selection?.anchor.path.slice(0, 1),\n match: n => Element.isElement(n) && n.type === 'paragraph',\n mode: 'highest'\n });\n if (firstTableCell) {\n const [, path] = firstTableCell;\n path.push(0);\n const nextPosition = { path, offset: 0 };\n Transforms.setSelection(editor, { anchor: nextPosition, focus: nextPosition });\n }\n },\n // Finds the image placeholder and replaces it with an image node\n appendImage: (editor: Editor, imageData: { src: string; alt: string }, id: string) => {\n const [node] = Editor.nodes<CosmosCustom.ImagePlaceholderElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image-placeholder',\n at: [Number(id)]\n });\n\n if (node) {\n const [, path] = node;\n Transforms.setNodes(\n editor,\n { type: 'image', src: imageData.src, alt: imageData.alt },\n { at: path }\n );\n Transforms.unsetNodes(editor, 'id', { at: path });\n return Editor.end(editor, path);\n }\n return null;\n },\n appendImagePlaceholder: (editor: Editor): string => {\n const node = commands.getSelectedNode(editor);\n\n if (node) {\n const [, path] = node;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'image-placeholder', children: [{ text: '' }] },\n { at: next }\n );\n return next[0].toString();\n }\n return '';\n },\n // Creates a link at the given selection\n createLink: (editor: Editor, text: string, url: string, selection: Range | null) => {\n const linkNode = { text: text || url, href: url };\n if (selection) {\n if (Range.isCollapsed(selection)) {\n const [node] = Editor.node(editor, selection);\n if (Text.isText(node) && node.href) {\n const before = Editor.before(editor, selection, { unit: 'word' });\n const after = Editor.after(editor, selection, { unit: 'word' });\n if (before && after) {\n Transforms.insertNodes(editor, [linkNode], { at: { anchor: before, focus: after } });\n } else if (before) {\n const calculatedAfter = Editor.after(editor, before, { unit: 'word' });\n if (calculatedAfter) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: before, focus: calculatedAfter }\n });\n }\n } else if (after) {\n const calculatedBefore = Editor.before(editor, after, { unit: 'word' });\n if (calculatedBefore) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: calculatedBefore, focus: after }\n });\n }\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n } else {\n Transforms.insertNodes(editor, [linkNode], {\n at: selection\n });\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n },\n // Used to handle the enter key when the cursor is next to an image, inserts a new paragraph\n checkImageEnter: (editor: Editor, e: KeyboardEvent) => {\n const [image] = Editor.nodes<CosmosCustom.ImageElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image'\n });\n if (image) {\n if (e.keyCode < 37 && e.keyCode > 40) {\n e.preventDefault();\n }\n if (e.key === 'Enter') {\n e.preventDefault();\n const [, path] = image;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'paragraph', children: [{ text: '' }] },\n { at: next }\n );\n Transforms.select(editor, next);\n }\n }\n },\n // Turns the href and/or searchResult property off on the text node when space is pressed while on a link or mention\n checkLinkBreak: (editor: Editor, e: KeyboardEvent) => {\n const [link] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.href\n });\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if ((link || searchResult) && (e.key === ' ' || e.key === 'Enter')) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : ' ' });\n Editor.removeMark(editor, link ? 'href' : 'searchResult');\n }\n },\n /**\n * Turns the searchResult property off on the text node when any key is pressed while on a searchResult.\n * Will delete the searchResult node if backspace key is hit.\n * Will re-position cursor to the start/end of the searchResult if arrow navigation is used.\n */\n checkSearchDownKeys: (editor: Editor, e: KeyboardEvent) => {\n const [text] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n)\n });\n\n if (text) {\n const [node, path] = text;\n const nextNode = Editor.next(editor)?.[0] as Text;\n const nextPath = Editor.next(editor)?.[1];\n const previousNode = Editor.previous(editor)?.[0] as Text;\n const previousPath = Editor.previous(editor)?.[1];\n\n const next = nextNode && nextNode.searchResult;\n const nextInline = next && path[0] === nextPath?.[0];\n const previous = previousNode && previousNode.searchResult;\n const previousInline = previous && path[0] === previousPath?.[0];\n\n // Checks if the current selection is a single cursor point rather than spanning multiple characters\n const singlePointSelection =\n editor.selection?.anchor.offset === editor.selection?.focus.offset &&\n editor.selection?.anchor.path[0] === editor.selection?.focus.path[0] &&\n editor.selection?.anchor.path[1] === editor.selection?.focus.path[1];\n\n // Checks if the current selected node is a search result, or directly adjacent inline with a search result\n if (node.searchResult || (next && nextInline) || (previous && previousInline)) {\n const atStart = node.searchResult && editor.selection?.anchor.offset === 0;\n const atEnd = node.searchResult && editor.selection?.anchor.offset === node.text.length;\n\n // Deletes the entire search result only if the cursor is at the end of the search result\n if (e.key === 'Backspace' && (atEnd || (previous && previousInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.delete(editor, { at: previous ? previousPath : path });\n // Deletes the entire search result only if the cursor is at the start of the search result\n } else if (e.key === 'Delete' && (atStart || (next && nextInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.delete(editor, { at: next ? nextPath : path });\n // Moves cursor to start of search result only if the cursor is at the end of the search result\n } else if (e.key === 'ArrowLeft' && (atEnd || (previous && previousInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.move(editor, {\n distance: previous ? previousNode.text.length : node.text.length,\n unit: 'character',\n reverse: true\n });\n // Moves cursor to end of search result only if the cursor is at the start of the search result\n } else if (e.key === 'ArrowRight' && (atStart || (next && nextInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.move(editor, {\n distance: next ? nextNode.text.length : node.text.length,\n unit: 'character'\n });\n // Ensures all other character (besides special key bindings) are inserted as plain text\n } else if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : e.key });\n }\n\n // Prevents partial search result selections from disabling the searchResult flag\n if (singlePointSelection) {\n Editor.removeMark(editor, 'searchResult');\n }\n }\n }\n },\n // Checks arrow navigation key up events around search results\n checkSearchUpKeys: (editor: Editor, e: KeyboardEvent) => {\n const [text] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n)\n });\n\n if (text) {\n const [node, path] = text;\n\n const cursorInSearchResult =\n node.searchResult &&\n editor.selection?.anchor.path[0] === path[0] &&\n editor.selection?.anchor.path[1] === path[1];\n\n if (cursorInSearchResult && editor.selection) {\n const distanceToStart = editor.selection.anchor.offset;\n const distanceToEnd = node.text.length - editor.selection.anchor.offset;\n // Moves cursor to the start of the search result\n if (e.key === 'ArrowLeft') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToStart,\n unit: 'character',\n reverse: true\n });\n // Moves cursor to end of search result\n } else if (e.key === 'ArrowRight') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToEnd,\n unit: 'character'\n });\n // Moves cursor to start or end of search result, whichever is closer\n } else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToStart <= distanceToEnd ? distanceToStart : distanceToEnd,\n unit: 'character',\n reverse: distanceToStart <= distanceToEnd\n });\n }\n }\n }\n },\n // Either adds a tab character or indents a list depending on the selection\n indent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<CosmosCustom.ListElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.nestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n Transforms.insertText(editor, '\\t', { at: start });\n }\n },\n // Either removes a tab character or un indents a list depending on the selection\n unindent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<CosmosCustom.ListItemElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.unNestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n let end = Editor.after(editor, editor.selection, { unit: 'block' });\n end = end || Editor.end(editor, editor.selection);\n if (start && end) {\n const text = Editor.string(editor, { anchor: start, focus: end });\n const newText = text.replace(/\\t/, '');\n Transforms.insertText(editor, newText, { at: { anchor: start, focus: end } });\n }\n }\n },\n checkKeyCommands: (editor: Editor, e: KeyboardEvent, markdownOnly?: boolean) => {\n const cmdOrCtrl = e.metaKey || e.ctrlKey;\n let commandExecuted = false;\n if (cmdOrCtrl && !markdownOnly) {\n // Command or Ctrl + Shift\n if (e.shiftKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n case 'x':\n commands.toggleFormat('line-through', editor);\n commandExecuted = true;\n break;\n case 'l':\n ListCommands.toggleList('unordered-list', editor);\n commandExecuted = true;\n break;\n default:\n }\n // Command or Ctrl but not alt\n } else if (!e.shiftKey && !e.altKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n default:\n }\n }\n } else if (cmdOrCtrl && markdownOnly && !e.shiftKey && !e.altKey && e.key === 'x') {\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if (searchResult) {\n Editor.removeMark(editor, 'searchResult');\n }\n }\n\n if (e.altKey && !markdownOnly) {\n if (cmdOrCtrl) {\n if (textKeyCodeMapping[e.keyCode]) {\n commands.setBlock(textKeyCodeMapping[e.keyCode], editor);\n commandExecuted = true;\n }\n } else if (e.keyCode === 77) {\n if (e.shiftKey) {\n commands.unindent(editor);\n commandExecuted = true;\n } else {\n commands.indent(editor);\n commandExecuted = true;\n }\n }\n }\n\n if (markdownOnly && e.key === 'Backspace') {\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if (searchResult) {\n Editor.removeMark(editor, 'searchResult');\n }\n if (!editor.selection) {\n Transforms.select(editor, {\n anchor: { offset: 0, path: [0, 0] },\n focus: { offset: 0, path: [0, 0] }\n });\n }\n }\n\n if (commandExecuted) e.preventDefault();\n }\n};\n\nexport default commands;\n"]}
1
+ {"version":3,"file":"EditorCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAKvE,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,MAAM,kBAAkB,GAAuC;IAC7D,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;CAChB,CAAC;AAEF,MAAM,QAAQ,GAAG;IACf,uCAAuC;IACvC,cAAc,EAAE,CAAC,MAAyC,EAAE,MAAc,EAAE,EAAE;QAC5E,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK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AC,CAAC,EAAE,CAAC,CAAC,EAAE;iBACnC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,IAAI,eAAe;YAAE,CAAC,CAAC,cAAc,EAAE,CAAC;IAC1C,CAAC;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import type { KeyboardEvent } from 'react';\nimport { Editor, Transforms, Range, Path, Element, Text } from 'slate';\nimport type { PegaCustom, Node, NodeEntry } from 'slate';\n\nimport type { ExcludeStrict } from '@pega/cosmos-react-core';\n\nimport ListCommands from './ListCommands';\n\nconst textKeyCodeMapping: { [key: number]: Element['type'] } = {\n 48: 'paragraph',\n 49: 'heading-1',\n 50: 'heading-2',\n 51: 'heading-3',\n 52: 'heading-4'\n};\n\nconst commands = {\n // Checks if an inline format is active\n isFormatActive: (format: ExcludeStrict<keyof Text, 'text'>, editor: Editor) => {\n const marks = Editor.marks(editor);\n return marks ? marks[format] === true : false;\n },\n // Toggles an inline format on or off\n toggleFormat: (format: ExcludeStrict<keyof Text, 'text'>, editor: Editor) => {\n const formatActive = commands.isFormatActive(format, editor);\n if (formatActive) {\n Editor.removeMark(editor, format);\n } else {\n Editor.addMark(editor, format, true);\n }\n },\n // Checks if a block level format is active\n isBlockActive: (format: Element['type'], editor: Editor) => {\n const [match] = Editor.nodes<Element>(editor, {\n match: n => Element.isElement(n) && n.type === format\n });\n\n return !!match;\n },\n // Gets the active block level type\n getActiveBlockType: (editor: Editor): string => {\n const [match] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: Element.isElement,\n mode: 'lowest'\n });\n\n if (match) {\n return match[0].type;\n }\n return '';\n },\n // Sets the block type of the currently selected block\n setBlock: (format: Element['type'], editor: Editor) => {\n Transforms.setNodes(editor, { type: format }, { mode: 'lowest' });\n },\n // Replaces a target in the editor with the given text\n replaceWithText: (editor: Editor, target: Range | null, text: string) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertText(editor, text);\n Transforms.move(editor);\n },\n // Replaces a target in the editor with the given node\n replaceWithNodes: (editor: Editor, target: Range | null, node: Node) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertNodes(editor, node);\n },\n // Gets the highest selected block level node\n getSelectedNode: (editor: Editor): NodeEntry<Node> => {\n const [node] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: n => Element.isElement(n),\n mode: 'highest'\n });\n return node;\n },\n // Appends a 3x3 table into the editor and adds a blank line to the bottom\n appendTable: (editor: Editor) => {\n const baseArr: unknown[][] = new Array(3).fill(new Array(3).fill(0));\n const table: [PegaCustom.TableElement, PegaCustom.ParagraphElement] = [\n {\n type: 'table',\n children: [\n {\n type: 'table-body',\n children: baseArr.map(row => {\n return {\n type: 'table-row',\n children: row.map(() => {\n return {\n type: 'table-cell',\n children: [{ type: 'paragraph', children: [{ text: '' }] }]\n };\n })\n };\n })\n }\n ]\n },\n {\n type: 'paragraph',\n children: [{ text: '' }]\n }\n ];\n\n Transforms.insertNodes(editor, table, { mode: 'highest' });\n const [firstTableCell] = Editor.nodes<PegaCustom.ParagraphElement>(editor, {\n at: editor.selection?.anchor.path.slice(0, 1),\n match: n => Element.isElement(n) && n.type === 'paragraph',\n mode: 'highest'\n });\n if (firstTableCell) {\n const [, path] = firstTableCell;\n path.push(0);\n const nextPosition = { path, offset: 0 };\n Transforms.setSelection(editor, { anchor: nextPosition, focus: nextPosition });\n }\n },\n // Finds the image placeholder and replaces it with an image node\n appendImage: (editor: Editor, imageData: { src: string; alt: string }, id: string) => {\n const [node] = Editor.nodes<PegaCustom.ImagePlaceholderElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image-placeholder',\n at: [Number(id)]\n });\n\n if (node) {\n const [, path] = node;\n Transforms.setNodes(\n editor,\n { type: 'image', src: imageData.src, alt: imageData.alt },\n { at: path }\n );\n Transforms.unsetNodes(editor, 'id', { at: path });\n return Editor.end(editor, path);\n }\n return null;\n },\n appendImagePlaceholder: (editor: Editor): string => {\n const node = commands.getSelectedNode(editor);\n\n if (node) {\n const [, path] = node;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'image-placeholder', children: [{ text: '' }] },\n { at: next }\n );\n return next[0].toString();\n }\n return '';\n },\n // Creates a link at the given selection\n createLink: (editor: Editor, text: string, url: string, selection: Range | null) => {\n const linkNode = { text: text || url, href: url };\n if (selection) {\n if (Range.isCollapsed(selection)) {\n const [node] = Editor.node(editor, selection);\n if (Text.isText(node) && node.href) {\n const before = Editor.before(editor, selection, { unit: 'word' });\n const after = Editor.after(editor, selection, { unit: 'word' });\n if (before && after) {\n Transforms.insertNodes(editor, [linkNode], { at: { anchor: before, focus: after } });\n } else if (before) {\n const calculatedAfter = Editor.after(editor, before, { unit: 'word' });\n if (calculatedAfter) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: before, focus: calculatedAfter }\n });\n }\n } else if (after) {\n const calculatedBefore = Editor.before(editor, after, { unit: 'word' });\n if (calculatedBefore) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: calculatedBefore, focus: after }\n });\n }\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n } else {\n Transforms.insertNodes(editor, [linkNode], {\n at: selection\n });\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n },\n // Used to handle the enter key when the cursor is next to an image, inserts a new paragraph\n checkImageEnter: (editor: Editor, e: KeyboardEvent) => {\n const [image] = Editor.nodes<PegaCustom.ImageElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image'\n });\n if (image) {\n if (e.keyCode < 37 && e.keyCode > 40) {\n e.preventDefault();\n }\n if (e.key === 'Enter') {\n e.preventDefault();\n const [, path] = image;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'paragraph', children: [{ text: '' }] },\n { at: next }\n );\n Transforms.select(editor, next);\n }\n }\n },\n // Turns the href and/or searchResult property off on the text node when space is pressed while on a link or mention\n checkLinkBreak: (editor: Editor, e: KeyboardEvent) => {\n const [link] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.href\n });\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if ((link || searchResult) && (e.key === ' ' || e.key === 'Enter')) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : ' ' });\n Editor.removeMark(editor, link ? 'href' : 'searchResult');\n }\n },\n /**\n * Turns the searchResult property off on the text node when any key is pressed while on a searchResult.\n * Will delete the searchResult node if backspace key is hit.\n * Will re-position cursor to the start/end of the searchResult if arrow navigation is used.\n */\n checkSearchDownKeys: (editor: Editor, e: KeyboardEvent) => {\n const [text] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n)\n });\n\n if (text) {\n const [node, path] = text;\n const nextNode = Editor.next(editor)?.[0] as Text;\n const nextPath = Editor.next(editor)?.[1];\n const previousNode = Editor.previous(editor)?.[0] as Text;\n const previousPath = Editor.previous(editor)?.[1];\n\n const next = nextNode && nextNode.searchResult;\n const nextInline = next && path[0] === nextPath?.[0];\n const previous = previousNode && previousNode.searchResult;\n const previousInline = previous && path[0] === previousPath?.[0];\n\n // Checks if the current selection is a single cursor point rather than spanning multiple characters\n const singlePointSelection =\n editor.selection?.anchor.offset === editor.selection?.focus.offset &&\n editor.selection?.anchor.path[0] === editor.selection?.focus.path[0] &&\n editor.selection?.anchor.path[1] === editor.selection?.focus.path[1];\n\n // Checks if the current selected node is a search result, or directly adjacent inline with a search result\n if (node.searchResult || (next && nextInline) || (previous && previousInline)) {\n const atStart = node.searchResult && editor.selection?.anchor.offset === 0;\n const atEnd = node.searchResult && editor.selection?.anchor.offset === node.text.length;\n\n // Deletes the entire search result only if the cursor is at the end of the search result\n if (e.key === 'Backspace' && (atEnd || (previous && previousInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.delete(editor, { at: previous ? previousPath : path });\n // Deletes the entire search result only if the cursor is at the start of the search result\n } else if (e.key === 'Delete' && (atStart || (next && nextInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.delete(editor, { at: next ? nextPath : path });\n // Moves cursor to start of search result only if the cursor is at the end of the search result\n } else if (e.key === 'ArrowLeft' && (atEnd || (previous && previousInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.move(editor, {\n distance: previous ? previousNode.text.length : node.text.length,\n unit: 'character',\n reverse: true\n });\n // Moves cursor to end of search result only if the cursor is at the start of the search result\n } else if (e.key === 'ArrowRight' && (atStart || (next && nextInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.move(editor, {\n distance: next ? nextNode.text.length : node.text.length,\n unit: 'character'\n });\n // Ensures all other character (besides special key bindings) are inserted as plain text\n } else if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : e.key });\n }\n\n // Prevents partial search result selections from disabling the searchResult flag\n if (singlePointSelection) {\n Editor.removeMark(editor, 'searchResult');\n }\n }\n }\n },\n // Checks arrow navigation key up events around search results\n checkSearchUpKeys: (editor: Editor, e: KeyboardEvent) => {\n const [text] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n)\n });\n\n if (text) {\n const [node, path] = text;\n\n const cursorInSearchResult =\n node.searchResult &&\n editor.selection?.anchor.path[0] === path[0] &&\n editor.selection?.anchor.path[1] === path[1];\n\n if (cursorInSearchResult && editor.selection) {\n const distanceToStart = editor.selection.anchor.offset;\n const distanceToEnd = node.text.length - editor.selection.anchor.offset;\n // Moves cursor to the start of the search result\n if (e.key === 'ArrowLeft') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToStart,\n unit: 'character',\n reverse: true\n });\n // Moves cursor to end of search result\n } else if (e.key === 'ArrowRight') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToEnd,\n unit: 'character'\n });\n // Moves cursor to start or end of search result, whichever is closer\n } else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToStart <= distanceToEnd ? distanceToStart : distanceToEnd,\n unit: 'character',\n reverse: distanceToStart <= distanceToEnd\n });\n }\n }\n }\n },\n // Either adds a tab character or indents a list depending on the selection\n indent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<PegaCustom.ListElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.nestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n Transforms.insertText(editor, '\\t', { at: start });\n }\n },\n // Either removes a tab character or un indents a list depending on the selection\n unindent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<PegaCustom.ListItemElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.unNestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n let end = Editor.after(editor, editor.selection, { unit: 'block' });\n end = end || Editor.end(editor, editor.selection);\n if (start && end) {\n const text = Editor.string(editor, { anchor: start, focus: end });\n const newText = text.replace(/\\t/, '');\n Transforms.insertText(editor, newText, { at: { anchor: start, focus: end } });\n }\n }\n },\n checkKeyCommands: (editor: Editor, e: KeyboardEvent, markdownOnly?: boolean) => {\n const cmdOrCtrl = e.metaKey || e.ctrlKey;\n let commandExecuted = false;\n if (cmdOrCtrl && !markdownOnly) {\n // Command or Ctrl + Shift\n if (e.shiftKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n case 'x':\n commands.toggleFormat('line-through', editor);\n commandExecuted = true;\n break;\n case 'l':\n ListCommands.toggleList('unordered-list', editor);\n commandExecuted = true;\n break;\n default:\n }\n // Command or Ctrl but not alt\n } else if (!e.shiftKey && !e.altKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n default:\n }\n }\n } else if (cmdOrCtrl && markdownOnly && !e.shiftKey && !e.altKey && e.key === 'x') {\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if (searchResult) {\n Editor.removeMark(editor, 'searchResult');\n }\n }\n\n if (e.altKey && !markdownOnly) {\n if (cmdOrCtrl) {\n if (textKeyCodeMapping[e.keyCode]) {\n commands.setBlock(textKeyCodeMapping[e.keyCode], editor);\n commandExecuted = true;\n }\n } else if (e.keyCode === 77) {\n if (e.shiftKey) {\n commands.unindent(editor);\n commandExecuted = true;\n } else {\n commands.indent(editor);\n commandExecuted = true;\n }\n }\n }\n\n if (markdownOnly && e.key === 'Backspace') {\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if (searchResult) {\n Editor.removeMark(editor, 'searchResult');\n }\n if (!editor.selection) {\n Transforms.select(editor, {\n anchor: { offset: 0, path: [0, 0] },\n focus: { offset: 0, path: [0, 0] }\n });\n }\n }\n\n if (commandExecuted) e.preventDefault();\n }\n};\n\nexport default commands;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ListCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/ListCommands.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAGhE,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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AAC;oBAChC,CAAC;iBACF,CACF,CAAC;gBAEF,iEAAiE;gBACjE,KAAK,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxE,MAAM,SAAS,GAAG,CAAC,GAAG,iBAAiB,EAAE,CAAC,CAAC,CAAC;oBAC5C,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;gBAC1E,CAAC;YACH,CAAC;YAED,6EAA6E;YAC7E,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;YACvD,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import type { KeyboardEvent } from 'react';\nimport { Editor, Element, Path, Transforms, Text } from 'slate';\nimport type { CosmosCustom, Node, 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,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,OAA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iBACN,EACD;oBACE,KAAK,EAAE,CAAC,CAAC,EAAE;wBACT,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;4BAAE,OAAO,KAAK,CAAC;wBAEpC,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,EAAE;4BAAE,KAAK,IAAI,CAAC,CAAC;wBACvC,OAAO,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,EAAE,CAAC;oBAChC,CAAC;iBACF,CACF,CAAC;gBAEF,iEAAiE;gBACjE,KAAK,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxE,MAAM,SAAS,GAAG,CAAC,GAAG,iBAAiB,EAAE,CAAC,CAAC,CAAC;oBAC5C,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;gBAC1E,CAAC;YACH,CAAC;YAED,6EAA6E;YAC7E,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;YACvD,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import type { KeyboardEvent } from 'react';\nimport { Editor, Element, Path, Transforms, Text } from 'slate';\nimport type { PegaCustom, Node, NodeEntry } from 'slate';\n\nimport { createUID } from '@pega/cosmos-react-core';\n\nimport { LIST_TYPES, TEXT_TYPES } from './utils.types';\n\ntype FullListItemElement = PegaCustom.ListItemElement & {\n id: string;\n parentId: string;\n order: number;\n level: number;\n};\n\nconst matchList = (n: Node): n is PegaCustom.ListElement =>\n Element.isElement(n) && LIST_TYPES.includes(n.type);\n\nconst matchListItem = (n: Node): n is PegaCustom.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 PegaCustom.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<PegaCustom.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<PegaCustom.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<PegaCustom.TextElement>(editor, {\n at: abovePath,\n match: n => Element.isElement(n) && TEXT_TYPES.includes(n.type)\n });\n\n let copiedSubListNodes: PegaCustom.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 PegaCustom.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 PegaCustom.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<PegaCustom.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<PegaCustom.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<PegaCustom.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<PegaCustom.ListItemElement>(\n editor,\n { parentId: newParentId },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n } else {\n Transforms.unsetNodes<PegaCustom.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<PegaCustom.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"]}