@pega/cosmos-react-rte 4.0.0-dev.2.0 → 4.0.0-dev.20.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 (87) hide show
  1. package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts +9 -0
  2. package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts.map +1 -0
  3. package/lib/components/DynamicContentEditor/DynamicContentEditor.js +239 -0
  4. package/lib/components/DynamicContentEditor/DynamicContentEditor.js.map +1 -0
  5. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts +23 -0
  6. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts.map +1 -0
  7. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js +2 -0
  8. package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js.map +1 -0
  9. package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts +322 -0
  10. package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts.map +1 -0
  11. package/lib/components/DynamicContentEditor/PegaCustomElement.js +27 -0
  12. package/lib/components/DynamicContentEditor/PegaCustomElement.js.map +1 -0
  13. package/lib/components/DynamicContentEditor/index.d.ts +3 -0
  14. package/lib/components/DynamicContentEditor/index.d.ts.map +1 -0
  15. package/lib/components/DynamicContentEditor/index.js +2 -0
  16. package/lib/components/DynamicContentEditor/index.js.map +1 -0
  17. package/lib/components/Editor/Editor.d.ts.map +1 -1
  18. package/lib/components/Editor/Editor.js +10 -8
  19. package/lib/components/Editor/Editor.js.map +1 -1
  20. package/lib/components/Editor/Editor.styles.d.ts +1 -0
  21. package/lib/components/Editor/Editor.styles.d.ts.map +1 -1
  22. package/lib/components/Editor/Editor.styles.js +9 -1
  23. package/lib/components/Editor/Editor.styles.js.map +1 -1
  24. package/lib/components/Editor/Editor.types.d.ts +3 -3
  25. package/lib/components/Editor/Editor.types.d.ts.map +1 -1
  26. package/lib/components/Editor/ImageEditor.d.ts.map +1 -1
  27. package/lib/components/Editor/ImageEditor.js +22 -17
  28. package/lib/components/Editor/ImageEditor.js.map +1 -1
  29. package/lib/components/Editor/Toolbar/TextSelect.d.ts +1 -1
  30. package/lib/components/Editor/Toolbar/TextSelect.d.ts.map +1 -1
  31. package/lib/components/Editor/Toolbar/TextSelect.js +1 -1
  32. package/lib/components/Editor/Toolbar/TextSelect.js.map +1 -1
  33. package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +1 -1
  34. package/lib/components/Editor/Toolbar/Toolbar.js +15 -9
  35. package/lib/components/Editor/Toolbar/Toolbar.js.map +1 -1
  36. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts.map +1 -1
  37. package/lib/components/RichTextEditor/DecoratorComponents/Link.js +1 -1
  38. package/lib/components/RichTextEditor/DecoratorComponents/Link.js.map +1 -1
  39. package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +1 -1
  40. package/lib/components/RichTextEditor/RichTextEditor.js +8 -7
  41. package/lib/components/RichTextEditor/RichTextEditor.js.map +1 -1
  42. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +1 -1
  43. package/lib/components/RichTextEditor/RichTextEditor.styles.js +8 -10
  44. package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -1
  45. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +2 -2
  46. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +1 -1
  47. package/lib/components/RichTextEditor/RichTextEditor.types.js.map +1 -1
  48. package/lib/components/RichTextEditor/RichTextTreeRenderer.d.ts +1 -1
  49. package/lib/components/RichTextEditor/RichTextTreeRenderer.d.ts.map +1 -1
  50. package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +1 -1
  51. package/lib/components/RichTextEditor/RichTextViewer.js +1 -1
  52. package/lib/components/RichTextEditor/RichTextViewer.js.map +1 -1
  53. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +5 -5
  54. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +1 -1
  55. package/lib/components/RichTextEditor/RichTextViewer.types.js.map +1 -1
  56. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts.map +1 -1
  57. package/lib/components/RichTextEditor/Toolbar/TextSelect.js +1 -1
  58. package/lib/components/RichTextEditor/Toolbar/TextSelect.js.map +1 -1
  59. package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts.map +1 -1
  60. package/lib/components/RichTextEditor/Toolbar/Toolbar.js +14 -8
  61. package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +1 -1
  62. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts +4 -4
  63. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts.map +1 -1
  64. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts +3 -2
  65. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +1 -1
  66. package/lib/components/RichTextEditor/utils/EditorCommands.js +6 -1
  67. package/lib/components/RichTextEditor/utils/EditorCommands.js.map +1 -1
  68. package/lib/components/RichTextEditor/utils/ListCommands.js +10 -10
  69. package/lib/components/RichTextEditor/utils/ListCommands.js.map +1 -1
  70. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +1 -1
  71. package/lib/components/RichTextEditor/utils/htmlConverter.js +2 -4
  72. package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -1
  73. package/lib/components/RichTextEditor/utils/interactionRenderer.js +6 -6
  74. package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +1 -1
  75. package/lib/components/RichTextEditor/utils/markdownConverter.js +3 -3
  76. package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -1
  77. package/lib/components/RichTextEditor/utils/renderers.d.ts +1 -1
  78. package/lib/components/RichTextEditor/utils/renderers.d.ts.map +1 -1
  79. package/lib/components/RichTextEditor/utils/renderers.js +4 -4
  80. package/lib/components/RichTextEditor/utils/renderers.js.map +1 -1
  81. package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +1 -1
  82. package/lib/components/RichTextEditor/utils/slateConverter.js.map +1 -1
  83. package/lib/index.d.ts +2 -0
  84. package/lib/index.d.ts.map +1 -1
  85. package/lib/index.js +2 -0
  86. package/lib/index.js.map +1 -1
  87. package/package.json +7 -7
@@ -45,15 +45,15 @@ const parseTextToCustomSlateNodes = (text, renderers) => {
45
45
  // Use the regex match positions to slice the text into the correct text nodes and other custom nodes
46
46
  let lastPos;
47
47
  positions.forEach((pos, i) => {
48
- /* If the first regex match isn't at the start of the text node,
49
- slice the text node up to the first match and insert it into the nodes array */
48
+ // If the first regex match isn't at the start of the text node,
49
+ // slice the text node up to the first match and insert it into the nodes array
50
50
  if (i === 0 && pos.start !== 0) {
51
51
  nodes.push({
52
52
  text: text.slice(i, pos.start)
53
53
  });
54
54
  }
55
- /* If there was a last position, slice the text between the last position
56
- and the new position to insert it as a new text node */
55
+ // If there was a last position, slice the text between the last position
56
+ // and the new position to insert it as a new text node
57
57
  if (lastPos && lastPos.end < pos.start) {
58
58
  nodes.push({
59
59
  text: text.slice(lastPos.end, pos.start)
@@ -117,8 +117,8 @@ const parseTextToCustomSlateNodes = (text, renderers) => {
117
117
  }
118
118
  }
119
119
  }
120
- /* If we are at the end of the positions array, and there's still text left
121
- slice the text and add it as a new text node */
120
+ // If we are at the end of the positions array, and there's still text left
121
+ // slice the text and add it as a new text node
122
122
  if (i === positions.length - 1 && pos.end < text.length) {
123
123
  nodes.push({
124
124
  text: text.slice(pos.end, text.length)
@@ -1 +1 @@
1
- {"version":3,"file":"interactionRenderer.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/interactionRenderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAcvC,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;AAE/B,oEAAoE;AACpE,MAAM,UAAU,GAAG,CAAC,MAAwB,EAAE,EAAE;IAC9C,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,IAAI,GAAG,CAA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AClC,MAAM,YAAY,GAAG,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC3E,IAAI,YAAY,IAAI,YAAY,CAAC,IAAI,EAAE;oBACrC,KAAK,CAAC,IAAI,CAAC;wBACT,IAAI,EAAE,YAAY,CAAC,IAAI;wBACvB,YAAY,EAAE;4BACZ,QAAQ,EAAE,YAAY,CAAC,QAAQ;4BAC/B,SAAS,EAAE,YAAY,CAAC,SAAS;4BACjC,KAAK,EAAE,YAAY,CAAC,KAAK;4BACzB,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;yBACxB;qBACF,CAAC,CAAC;iBACJ;qBAAM;oBACL,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;iBACpC;aACF;SACF;QAED;yDACiD;QACjD,IAAI,CAAC,KAAK,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE;YACvD,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC;aACvC,CAAC,CAAC;SACJ;QACD,OAAO,GAAG,GAAG,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF,eAAe,2BAA2B,CAAC","sourcesContent":["import type * as slate from 'slate';\nimport { TLDs } from 'global-tld-list';\n\nimport { InteractionRenderers } from '../RichTextViewer.types';\n\ninterface RegexMatch extends InteractionRenderers {\n start: number;\n end: number;\n match: RegExpExecArray;\n}\n\ninterface CheckRegexParams extends InteractionRenderers {\n text: string;\n}\n\nconst parser = new DOMParser();\n\n// Checks a string for regex matches and returns an array of matches\nconst checkRegex = (params: CheckRegexParams) => {\n const regexMatches: RegexMatch[] = [];\n let res;\n // eslint-disable-next-line no-cond-assign\n while ((res = params.regexPattern.exec(params.text))) {\n const start = res.index;\n regexMatches.push({\n start,\n end: start + res[0].length,\n match: res,\n ...params\n });\n }\n return regexMatches;\n};\n\n// Extracts all properties from an xml element represented as a string\nexport const getXMLAttributes = (element: string): Record<string, string> | undefined => {\n const document = parser.parseFromString(element, 'application/xml');\n if (document.querySelector('parsererror')) return undefined;\n const attributes: Record<string, string> = {};\n\n for (let i = 0; i < document.documentElement.attributes.length; i += 1) {\n const attr = document.documentElement.attributes.item(i);\n if (attr) {\n attributes[attr.name] = attr.value;\n }\n }\n attributes.rawText = element;\n\n return attributes;\n};\n\n// Parses text node to custom slate node\nconst parseTextToCustomSlateNodes = (\n text: string,\n renderers?: InteractionRenderers[]\n): (slate.Element | slate.Text)[] => {\n // Runs through an array of custom renderers and gets the matches\n const positions: RegexMatch[] =\n renderers?.flatMap(renderer => checkRegex({ text, ...renderer })) || [];\n\n // Early exit when no matched positions\n if (positions.length === 0) {\n return [{ text }];\n }\n\n // Sorts the matches based on the start positions of the matches\n positions.sort((a, b) => a.start - b.start);\n\n const nodes: (slate.Element | slate.Text)[] = [];\n\n // Use the regex match positions to slice the text into the correct text nodes and other custom nodes\n let lastPos: RegexMatch;\n positions.forEach((pos, i) => {\n /* If the first regex match isn't at the start of the text node,\n slice the text node up to the first match and insert it into the nodes array */\n\n if (i === 0 && pos.start !== 0) {\n nodes.push({\n text: text.slice(i, pos.start)\n });\n }\n\n /* If there was a last position, slice the text between the last position\n and the new position to insert it as a new text node */\n if (lastPos && lastPos.end < pos.start) {\n nodes.push({\n text: text.slice(lastPos.end, pos.start)\n });\n } else if (i !== 0) {\n nodes.push({\n text: ' '\n });\n }\n\n if (pos.type === 'builtin-url' && pos.match.groups) {\n const { leadingChar, url } = pos.match.groups;\n\n try {\n // Check for valid URL since the regex isn't exhaustive.\n const { href } = new URL(pos.match.groups.protocol ? url : `https://${url}`);\n if (!TLDs.includes(pos.match.groups.tld)) {\n throw new Error('Invalid URL. Skipping formatting.');\n }\n\n if (leadingChar) {\n nodes.push({ text: leadingChar });\n }\n\n nodes.push({\n text: url,\n href\n });\n } catch {\n // Invalid URL, just render as text.\n nodes.push({ text: pos.match[0] });\n }\n } else if (pos.xmlElement) {\n const xmlAttributes = getXMLAttributes(pos.match[0]);\n\n if (!xmlAttributes) {\n // Invalid XML, just render as text.\n nodes.push({ text: pos.match[0] });\n } else if (pos.component) {\n nodes.push({\n type: 'custom',\n component: pos.component,\n content: xmlAttributes,\n children: [{ text: '' }]\n });\n } else if (pos.getSearchAttributes) {\n const searchResult = pos.getSearchAttributes(pos.xmlElement, pos.match[0]);\n if (searchResult && searchResult.text) {\n nodes.push({\n text: searchResult.text,\n searchResult: {\n markdown: searchResult.markdown,\n component: searchResult.component,\n props: searchResult.props,\n toJSON: () => undefined\n }\n });\n } else {\n nodes.push({ text: pos.match[0] });\n }\n }\n }\n\n /* If we are at the end of the positions array, and there's still text left\n slice the text and add it as a new text node */\n if (i === positions.length - 1 && pos.end < text.length) {\n nodes.push({\n text: text.slice(pos.end, text.length)\n });\n }\n lastPos = pos;\n });\n\n return nodes.length > 0 ? nodes : [{ text: '' }];\n};\n\nexport default parseTextToCustomSlateNodes;\n"]}
1
+ {"version":3,"file":"interactionRenderer.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/interactionRenderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAcvC,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;AAE/B,oEAAoE;AACpE,MAAM,UAAU,GAAG,CAAC,MAAwB,EAAE,EAAE;IAC9C,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,IAAI,GAAG,CAAC;IACR,0CAA0C;I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AAmB,EAAE;gBAClC,MAAM,YAAY,GAAG,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC3E,IAAI,YAAY,IAAI,YAAY,CAAC,IAAI,EAAE;oBACrC,KAAK,CAAC,IAAI,CAAC;wBACT,IAAI,EAAE,YAAY,CAAC,IAAI;wBACvB,YAAY,EAAE;4BACZ,QAAQ,EAAE,YAAY,CAAC,QAAQ;4BAC/B,SAAS,EAAE,YAAY,CAAC,SAAS;4BACjC,KAAK,EAAE,YAAY,CAAC,KAAK;4BACzB,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;yBACxB;qBACF,CAAC,CAAC;iBACJ;qBAAM;oBACL,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;iBACpC;aACF;SACF;QAED,2EAA2E;QAC3E,+CAA+C;QAC/C,IAAI,CAAC,KAAK,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE;YACvD,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC;aACvC,CAAC,CAAC;SACJ;QACD,OAAO,GAAG,GAAG,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF,eAAe,2BAA2B,CAAC","sourcesContent":["import type * as slate from 'slate';\nimport { TLDs } from 'global-tld-list';\n\nimport { InteractionRenderers } from '../RichTextViewer.types';\n\ninterface RegexMatch extends InteractionRenderers {\n start: number;\n end: number;\n match: RegExpExecArray;\n}\n\ninterface CheckRegexParams extends InteractionRenderers {\n text: string;\n}\n\nconst parser = new DOMParser();\n\n// Checks a string for regex matches and returns an array of matches\nconst checkRegex = (params: CheckRegexParams) => {\n const regexMatches: RegexMatch[] = [];\n let res;\n // eslint-disable-next-line no-cond-assign\n while ((res = params.regexPattern.exec(params.text))) {\n const start = res.index;\n regexMatches.push({\n start,\n end: start + res[0].length,\n match: res,\n ...params\n });\n }\n return regexMatches;\n};\n\n// Extracts all properties from an xml element represented as a string\nexport const getXMLAttributes = (element: string): Record<string, string> | undefined => {\n const document = parser.parseFromString(element, 'application/xml');\n if (document.querySelector('parsererror')) return undefined;\n const attributes: Record<string, string> = {};\n\n for (let i = 0; i < document.documentElement.attributes.length; i += 1) {\n const attr = document.documentElement.attributes.item(i);\n if (attr) {\n attributes[attr.name] = attr.value;\n }\n }\n attributes.rawText = element;\n\n return attributes;\n};\n\n// Parses text node to custom slate node\nconst parseTextToCustomSlateNodes = (\n text: string,\n renderers?: InteractionRenderers[]\n): (slate.Element | slate.Text)[] => {\n // Runs through an array of custom renderers and gets the matches\n const positions: RegexMatch[] =\n renderers?.flatMap(renderer => checkRegex({ text, ...renderer })) || [];\n\n // Early exit when no matched positions\n if (positions.length === 0) {\n return [{ text }];\n }\n\n // Sorts the matches based on the start positions of the matches\n positions.sort((a, b) => a.start - b.start);\n\n const nodes: (slate.Element | slate.Text)[] = [];\n\n // Use the regex match positions to slice the text into the correct text nodes and other custom nodes\n let lastPos: RegexMatch;\n positions.forEach((pos, i) => {\n // If the first regex match isn't at the start of the text node,\n // slice the text node up to the first match and insert it into the nodes array\n\n if (i === 0 && pos.start !== 0) {\n nodes.push({\n text: text.slice(i, pos.start)\n });\n }\n\n // If there was a last position, slice the text between the last position\n // and the new position to insert it as a new text node\n if (lastPos && lastPos.end < pos.start) {\n nodes.push({\n text: text.slice(lastPos.end, pos.start)\n });\n } else if (i !== 0) {\n nodes.push({\n text: ' '\n });\n }\n\n if (pos.type === 'builtin-url' && pos.match.groups) {\n const { leadingChar, url } = pos.match.groups;\n\n try {\n // Check for valid URL since the regex isn't exhaustive.\n const { href } = new URL(pos.match.groups.protocol ? url : `https://${url}`);\n if (!TLDs.includes(pos.match.groups.tld)) {\n throw new Error('Invalid URL. Skipping formatting.');\n }\n\n if (leadingChar) {\n nodes.push({ text: leadingChar });\n }\n\n nodes.push({\n text: url,\n href\n });\n } catch {\n // Invalid URL, just render as text.\n nodes.push({ text: pos.match[0] });\n }\n } else if (pos.xmlElement) {\n const xmlAttributes = getXMLAttributes(pos.match[0]);\n\n if (!xmlAttributes) {\n // Invalid XML, just render as text.\n nodes.push({ text: pos.match[0] });\n } else if (pos.component) {\n nodes.push({\n type: 'custom',\n component: pos.component,\n content: xmlAttributes,\n children: [{ text: '' }]\n });\n } else if (pos.getSearchAttributes) {\n const searchResult = pos.getSearchAttributes(pos.xmlElement, pos.match[0]);\n if (searchResult && searchResult.text) {\n nodes.push({\n text: searchResult.text,\n searchResult: {\n markdown: searchResult.markdown,\n component: searchResult.component,\n props: searchResult.props,\n toJSON: () => undefined\n }\n });\n } else {\n nodes.push({ text: pos.match[0] });\n }\n }\n }\n\n // If we are at the end of the positions array, and there's still text left\n // slice the text and add it as a new text node\n if (i === positions.length - 1 && pos.end < text.length) {\n nodes.push({\n text: text.slice(pos.end, text.length)\n });\n }\n lastPos = pos;\n });\n\n return nodes.length > 0 ? nodes : [{ text: '' }];\n};\n\nexport default parseTextToCustomSlateNodes;\n"]}
@@ -17,7 +17,7 @@ const getNode = (token, interactionRenderers, markdownMap) => {
17
17
  }
18
18
  else {
19
19
  let mdText = '';
20
- if ( /* token.type === 'link' || */token.type === 'text')
20
+ if (token.type === 'text')
21
21
  mdText = token.raw;
22
22
  else if (hasProp(token, 'text'))
23
23
  mdText = token.text;
@@ -119,8 +119,8 @@ export const convertMarkdownForEditor = (md = '', searchRenderers) => {
119
119
  }
120
120
  ];
121
121
  };
122
- /* Converts markdown into Slate compatible nodes, also takes regex used
123
- in Feed Component to pass them down to custom elements */
122
+ // Converts markdown into Slate compatible nodes, also takes regex used
123
+ // in Feed Component to pass them down to custom elements
124
124
  const convertMarkdown = (md, interactionRenderers, markdownMap) => {
125
125
  const lexer = new marked.Lexer({ gfm: false });
126
126
  const output = lexer.lex(md);
@@ -1 +1 @@
1
- {"version":3,"file":"markdownConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/markdownConverter.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIlD,OAAO,2BAA2B,MAAM,uBAAuB,CAAC;AAEhE,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAErC,MAAM,OAAO,GAAG,CACd,KAAmB,EACnB,oBAA6C,EAC7C,WAAgD,EAChC,EAAE;IAClB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK;QACjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAEzD,IAAI,QAAQ,CAAC;IAEb,IAAI,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;QAC5B,mEAAmE;QACnE,QAAQ,GAAG,eAAe,CACvB,KAAK,CAAC,MAAuC,IAAI,EAAE,EACpD,oBAAoB,EACpB,WAAW,CACZ,CAAC;KACH;SAAM,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE;QAClC,mEAAmE;QACnE,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,KAAK,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;KAC5E;SAAM;QACL,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,KAAI,8BAA+B,KAAK,CAAC,IAAI,K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3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,EAAE,GAAG,EAAE,EACP,eAAwC,EACpB,EAAE;IACtB,OAAO;QACL;YACE,IAAI,EAAE,WAAW;YACjB,QAAQ,EAAE,2BAA2B,CAAC,EAAE,EAAE,eAAe,CAAC;SAC3D;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;yDACyD;AACzD,MAAM,eAAe,GAAG,CACtB,EAAU,EACV,oBAA6C,EAC7C,WAAgD,EAC5B,EAAE;IACtB,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7B,OAAO,eAAe,CAAC,MAAM,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;AACpE,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { CosmosCustom, Element, Text } from 'slate';\nimport { marked } from 'marked';\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { InteractionRenderers, RichTextViewerProps } from '../RichTextViewer.types';\n\nimport parseTextToCustomSlateNodes from './interactionRenderer';\n\nmarked.setOptions({ mangle: false });\n\nconst getNode = (\n token: marked.Token,\n interactionRenderers?: InteractionRenderers[],\n markdownMap?: RichTextViewerProps['markdownMap']\n): Element | Text => {\n if (!hasProp(token, 'type') || token.type === 'def')\n return { type: 'paragraph', children: [{ text: '' }] };\n\n let children;\n\n if (hasProp(token, 'tokens')) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children = markDownToSlate(\n (token.tokens as marked.Tokens.Link['tokens']) || [],\n interactionRenderers,\n markdownMap\n );\n } else if (hasProp(token, 'items')) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children = markDownToSlate(token.items, interactionRenderers, markdownMap);\n } else {\n let mdText = '';\n\n if (/* token.type === 'link' || */ token.type === 'text') mdText = token.raw;\n else if (hasProp(token, 'text')) mdText = token.text;\n\n children = parseTextToCustomSlateNodes(mdText, interactionRenderers);\n }\n\n if (markdownMap?.[token.type]) {\n // Typed as any since typescript is unaware that token type matches argument\n const CustomComponent: any = markdownMap[token.type]?.(token as any);\n if (CustomComponent)\n return {\n type: 'override',\n component: <CustomComponent token={token} />,\n children: [{ text: '' }]\n };\n }\n\n if (!children.length) {\n return {\n type: 'paragraph',\n children: [{ text: token.raw }]\n };\n }\n\n switch (token.type) {\n case 'paragraph': {\n return {\n type: token.type,\n children\n };\n }\n case 'heading': {\n return {\n type:\n token.depth && token.depth <= 4\n ? (`heading-${token.depth}` as `heading-${1 | 2 | 3 | 4}`)\n : 'heading-4',\n children\n };\n }\n case 'link': {\n return {\n href: token.href,\n text: token.text || ''\n };\n }\n case 'em': {\n return {\n italic: true,\n text: token.text || ''\n };\n }\n case 'strong': {\n return {\n bold: true,\n text: token.text || ''\n };\n }\n case 'del': {\n return {\n 'line-through': true,\n text: token.text || ''\n };\n }\n case 'list': {\n return {\n type: token.ordered ? 'ordered-list' : 'unordered-list',\n children: children as CosmosCustom.ListItemElement[]\n };\n }\n case 'list_item': {\n return {\n type: 'list-item',\n children: children as Element[]\n };\n }\n case 'image': {\n return {\n type: 'image',\n alt: token.text,\n src: token.href,\n children: [{ text: '' }]\n };\n }\n default: {\n return {\n type: token.type,\n children\n } as Element;\n }\n }\n};\n\nconst markDownToSlate = (\n tokens: marked.Token[],\n interactionRenderers?: InteractionRenderers[],\n markdownMap?: RichTextViewerProps['markdownMap']\n): (Element | Text)[] => {\n return tokens.map(token => {\n return getNode(token, interactionRenderers, markdownMap);\n });\n};\n\nexport const convertMarkdownForEditor = (\n md = '',\n searchRenderers?: InteractionRenderers[]\n): (Element | Text)[] => {\n return [\n {\n type: 'paragraph',\n children: parseTextToCustomSlateNodes(md, searchRenderers)\n }\n ];\n};\n\n/* Converts markdown into Slate compatible nodes, also takes regex used\nin Feed Component to pass them down to custom elements */\nconst convertMarkdown = (\n md: string,\n interactionRenderers?: InteractionRenderers[],\n markdownMap?: RichTextViewerProps['markdownMap']\n): (Element | Text)[] => {\n const lexer = new marked.Lexer({ gfm: false });\n const output = lexer.lex(md);\n return markDownToSlate(output, interactionRenderers, markdownMap);\n};\n\nexport default convertMarkdown;\n"]}
1
+ {"version":3,"file":"markdownConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/markdownConverter.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIlD,OAAO,2BAA2B,MAAM,uBAAuB,CAAC;AAEhE,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAErC,MAAM,OAAO,GAAG,CACd,KAAmB,EACnB,oBAA6C,EAC7C,WAAgD,EAChC,EAAE;IAClB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK;QACjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAEzD,IAAI,QAAQ,CAAC;IAEb,IAAI,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;QAC5B,mEAAmE;QACnE,QAAQ,GAAG,eAAe,CACvB,KAAK,CAAC,MAAuC,IAAI,EAAE,EACpD,oBAAoB,EACpB,WAAW,CACZ,CAAC;KACH;SAAM,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE;QAClC,mEAAmE;QACnE,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,KAAK,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;KAC5E;SAAM;QACL,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,IAAI,KAAK,C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C,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,EAAE,GAAG,EAAE,EACP,eAAwC,EACpB,EAAE;IACtB,OAAO;QACL;YACE,IAAI,EAAE,WAAW;YACjB,QAAQ,EAAE,2BAA2B,CAAC,EAAE,EAAE,eAAe,CAAC;SAC3D;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,uEAAuE;AACvE,yDAAyD;AACzD,MAAM,eAAe,GAAG,CACtB,EAAU,EACV,oBAA6C,EAC7C,WAAgD,EAC5B,EAAE;IACtB,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7B,OAAO,eAAe,CAAC,MAAM,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;AACpE,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { CosmosCustom, Element, Text } from 'slate';\nimport { marked } from 'marked';\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { InteractionRenderers, RichTextViewerProps } from '../RichTextViewer.types';\n\nimport parseTextToCustomSlateNodes from './interactionRenderer';\n\nmarked.setOptions({ mangle: false });\n\nconst getNode = (\n token: marked.Token,\n interactionRenderers?: InteractionRenderers[],\n markdownMap?: RichTextViewerProps['markdownMap']\n): Element | Text => {\n if (!hasProp(token, 'type') || token.type === 'def')\n return { type: 'paragraph', children: [{ text: '' }] };\n\n let children;\n\n if (hasProp(token, 'tokens')) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children = markDownToSlate(\n (token.tokens as marked.Tokens.Link['tokens']) || [],\n interactionRenderers,\n markdownMap\n );\n } else if (hasProp(token, 'items')) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children = markDownToSlate(token.items, interactionRenderers, markdownMap);\n } else {\n let mdText = '';\n\n if (token.type === 'text') mdText = token.raw;\n else if (hasProp(token, 'text')) mdText = token.text;\n\n children = parseTextToCustomSlateNodes(mdText, interactionRenderers);\n }\n\n if (markdownMap?.[token.type]) {\n // Typed as any since typescript is unaware that token type matches argument\n const CustomComponent: any = markdownMap[token.type]?.(token as any);\n if (CustomComponent)\n return {\n type: 'override',\n component: <CustomComponent token={token} />,\n children: [{ text: '' }]\n };\n }\n\n if (!children.length) {\n return {\n type: 'paragraph',\n children: [{ text: token.raw }]\n };\n }\n\n switch (token.type) {\n case 'paragraph': {\n return {\n type: token.type,\n children\n };\n }\n case 'heading': {\n return {\n type:\n token.depth && token.depth <= 4\n ? (`heading-${token.depth}` as `heading-${1 | 2 | 3 | 4}`)\n : 'heading-4',\n children\n };\n }\n case 'link': {\n return {\n href: token.href,\n text: token.text || ''\n };\n }\n case 'em': {\n return {\n italic: true,\n text: token.text || ''\n };\n }\n case 'strong': {\n return {\n bold: true,\n text: token.text || ''\n };\n }\n case 'del': {\n return {\n 'line-through': true,\n text: token.text || ''\n };\n }\n case 'list': {\n return {\n type: token.ordered ? 'ordered-list' : 'unordered-list',\n children: children as CosmosCustom.ListItemElement[]\n };\n }\n case 'list_item': {\n return {\n type: 'list-item',\n children: children as Element[]\n };\n }\n case 'image': {\n return {\n type: 'image',\n alt: token.text,\n src: token.href,\n children: [{ text: '' }]\n };\n }\n default: {\n return {\n type: token.type,\n children\n } as Element;\n }\n }\n};\n\nconst markDownToSlate = (\n tokens: marked.Token[],\n interactionRenderers?: InteractionRenderers[],\n markdownMap?: RichTextViewerProps['markdownMap']\n): (Element | Text)[] => {\n return tokens.map(token => {\n return getNode(token, interactionRenderers, markdownMap);\n });\n};\n\nexport const convertMarkdownForEditor = (\n md = '',\n searchRenderers?: InteractionRenderers[]\n): (Element | Text)[] => {\n return [\n {\n type: 'paragraph',\n children: parseTextToCustomSlateNodes(md, searchRenderers)\n }\n ];\n};\n\n// Converts markdown into Slate compatible nodes, also takes regex used\n// in Feed Component to pass them down to custom elements\nconst convertMarkdown = (\n md: string,\n interactionRenderers?: InteractionRenderers[],\n markdownMap?: RichTextViewerProps['markdownMap']\n): (Element | Text)[] => {\n const lexer = new marked.Lexer({ gfm: false });\n const output = lexer.lex(md);\n return markDownToSlate(output, interactionRenderers, markdownMap);\n};\n\nexport default convertMarkdown;\n"]}
@@ -3,7 +3,7 @@ import { CosmosCustom } from 'slate';
3
3
  import { ComponentType } from 'react';
4
4
  import { Text } from '@pega/cosmos-react-core';
5
5
  export declare const slateNodeRenderer: (props: RenderElementProps) => JSX.Element;
6
- declare type Node = {
6
+ type Node = {
7
7
  children: JSX.Element[];
8
8
  type: string;
9
9
  href?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/renderers.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,aAAa,EAAa,MAAM,OAAO,CAAC;AAGjD,OAAO,EAAE,IAAI,EAAe,MAAM,yBAAyB,CAAC;AAK5D,eAAO,MAAM,iBAAiB,UAAW,kBAAkB,gBA6F1D,CAAC;AAEF,aAAK,IAAI,GAAG;IACV,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAGF,eAAO,MAAM,YAAY,SAAU,IAAI,gBAqEtC,CAAC;AAGF,eAAO,MAAM,iBAAiB,UAAW,eAAe,gBAiCvD,CAAC;AAMF,eAAO,MAAM,YAAY,SAAU,iBAAiB,gBAgCnD,CAAC"}
1
+ {"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/renderers.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,aAAa,EAAa,MAAM,OAAO,CAAC;AAGjD,OAAO,EAAE,IAAI,EAAe,MAAM,yBAAyB,CAAC;AAK5D,eAAO,MAAM,iBAAiB,UAAW,kBAAkB,gBAyF1D,CAAC;AAEF,KAAK,IAAI,GAAG;IACV,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAGF,eAAO,MAAM,YAAY,SAAU,IAAI,gBAiEtC,CAAC;AAGF,eAAO,MAAM,iBAAiB,UAAW,eAAe,gBA6BvD,CAAC;AAMF,eAAO,MAAM,YAAY,SAAU,iBAAiB,gBA4BnD,CAAC"}
@@ -23,7 +23,7 @@ export const slateNodeRenderer = (props) => {
23
23
  const CustomComponent = props.element.component;
24
24
  let child = _jsx(CustomComponent, { ...props.attributes, children: props.element.content });
25
25
  if (props.element.href) {
26
- child = (_jsx(Link, { href: props.element.href, target: '_blank', children: child }));
26
+ child = _jsx(Link, { href: props.element.href, children: child });
27
27
  }
28
28
  if (props.element.italic) {
29
29
  child = _jsx("em", { children: child });
@@ -79,7 +79,7 @@ export const nodeRenderer = (node) => {
79
79
  const CustomComponent = node.component;
80
80
  let child = _jsx(CustomComponent, { children: node.content });
81
81
  if (node.href) {
82
- child = (_jsx(Link, { href: node.href, target: '_blank', children: child }));
82
+ child = _jsx(Link, { href: node.href, children: child });
83
83
  }
84
84
  if (node.italic) {
85
85
  child = _jsx("em", { children: child });
@@ -133,7 +133,7 @@ export const slateLeafRenderer = (props) => {
133
133
  child = _jsx("strong", { children: child });
134
134
  }
135
135
  if (props.leaf.href) {
136
- child = (_jsx(Link, { href: props.leaf.href, target: '_blank', children: child }));
136
+ child = _jsx(Link, { href: props.leaf.href, children: child });
137
137
  }
138
138
  return _jsx("span", { ...props.attributes, children: child });
139
139
  };
@@ -156,7 +156,7 @@ export const leafRenderer = (leaf) => {
156
156
  child = _jsx("strong", { children: child });
157
157
  }
158
158
  if (leaf.href) {
159
- child = (_jsx(Link, { href: leaf.href, target: '_blank', children: child }));
159
+ child = _jsx(Link, { href: leaf.href, children: child });
160
160
  }
161
161
  return _jsx(StyledSpan, { children: child });
162
162
  };
@@ -1 +1 @@
1
- {"version":3,"file":"renderers.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/renderers.tsx"],"names":[],"mappings":";AAGA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAErF,oCAAoC;AACpC,MAAM,CA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EAAE;IACtD,IAAI,KAAK,GAAuB,IAAI,CAAC,IAAI,CAAC;IAC1C,IAAI,IAAI,CAAC,YAAY,EAAE;QACrB,MAAM,eAAe,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC;QACpD,OAAO,CACL,yBACE,KAAC,eAAe,OAAK,IAAI,CAAC,YAAY,CAAC,KAAK,YAAG,KAAK,GAAmB,GAClE,CACR,CAAC;KACH;IAED,IAAI,IAAI,CAAC,cAAc,CAAC,EAAE;QACxB,KAAK,GAAG,wBAAM,KAAK,GAAO,CAAC;KAC5B;IAED,IAAI,IAAI,CAAC,MAAM,EAAE;QACf,KAAK,GAAG,uBAAK,KAAK,GAAM,CAAC;KAC1B;IAED,IAAI,IAAI,CAAC,IAAI,EAAE;QACb,KAAK,GAAG,2BAAS,KAAK,GAAU,CAAC;KAClC;IAED,IAAI,IAAI,CAAC,IAAI,EAAE;QACb,KAAK,GAAG,CACN,KAAC,IAAI,IAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAC,QAAQ,YACnC,KAAK,GACD,CACR,CAAC;KACH;IAED,OAAO,KAAC,UAAU,cAAE,KAAK,GAAc,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import { RenderElementProps, RenderLeafProps } from 'slate-react';\nimport { CosmosCustom } from 'slate';\nimport { ComponentType, ReactNode } from 'react';\nimport styled from 'styled-components';\n\nimport { Text, Link, Image } from '@pega/cosmos-react-core';\n\nimport { Table, TableRow, TableCell, TableBody } from '../DecoratorComponents/Table';\n\n// Renderer for block level elements\nexport const slateNodeRenderer = (props: RenderElementProps) => {\n switch (props.element.type) {\n case 'heading-1':\n return (\n <Text variant='h1' {...props.attributes}>\n {props.children}\n </Text>\n );\n case 'heading-2':\n return (\n <Text variant='h2' {...props.attributes}>\n {props.children}\n </Text>\n );\n case 'heading-3':\n return (\n <Text variant='h3' {...props.attributes}>\n {props.children}\n </Text>\n );\n case 'heading-4':\n return (\n <Text variant='h4' {...props.attributes}>\n {props.children}\n </Text>\n );\n case 'ordered-list':\n return <ol {...props.attributes}>{props.children}</ol>;\n case 'unordered-list':\n return <ul {...props.attributes}>{props.children}</ul>;\n case 'list-item':\n return (\n <li\n {...props.attributes}\n data-order={props.element.order}\n data-level={props.element.level}\n data-id={props.element.id}\n data-parent-id={props.element.parentId}\n >\n {props.children}\n </li>\n );\n case 'custom': {\n const CustomComponent = props.element.component;\n let child = <CustomComponent {...props.attributes}>{props.element.content}</CustomComponent>;\n if (props.element.href) {\n child = (\n <Link href={props.element.href} target='_blank'>\n {child}\n </Link>\n );\n }\n if (props.element.italic) {\n child = <em>{child}</em>;\n }\n if (props.element.bold) {\n child = <strong>{child}</strong>;\n }\n if (props.element['line-through']) {\n child = <del>{child}</del>;\n }\n return child;\n }\n case 'override': {\n return props.element.component;\n }\n case 'table':\n return <Table {...props.attributes}>{props.children}</Table>;\n case 'table-body':\n return <TableBody {...props.attributes}>{props.children}</TableBody>;\n case 'table-row':\n return <TableRow {...props.attributes}>{props.children}</TableRow>;\n case 'table-cell':\n return <TableCell {...props.attributes}>{props.children}</TableCell>;\n case 'paragraph':\n return (\n <div>\n <Text {...props.attributes}>{props.children}</Text>\n </div>\n );\n case 'image':\n return (\n <div {...props.attributes}>\n <Image src={props.element.src} alt={props.element.alt as string} />\n {props.children}\n </div>\n );\n case 'image-placeholder':\n return <div {...props.attributes}>{props.children}</div>;\n default: {\n return <span {...props.attributes}>{props.children}</span>;\n }\n }\n};\n\ntype Node = {\n children: JSX.Element[];\n type: string;\n href?: string;\n italic?: boolean;\n bold?: boolean;\n 'line-through'?: boolean;\n component?: JSX.Element | ComponentType<any>;\n src?: string;\n alt?: string;\n content?: Record<string, string>;\n};\n\n// Renderer for block level elements\nexport const nodeRenderer = (node: Node) => {\n switch (node.type) {\n case 'heading-1':\n return <Text variant='h1'>{node.children}</Text>;\n case 'heading-2':\n return <Text variant='h2'>{node.children}</Text>;\n case 'heading-3':\n return <Text variant='h3'>{node.children}</Text>;\n case 'heading-4':\n return <Text variant='h4'>{node.children}</Text>;\n case 'ordered-list':\n return <ol>{node.children}</ol>;\n case 'unordered-list':\n return <ul>{node.children}</ul>;\n case 'list-item':\n return <li>{node.children}</li>;\n case 'custom': {\n const CustomComponent = node.component as ComponentType<any>;\n let child = <CustomComponent>{node.content}</CustomComponent>;\n if (node.href) {\n child = (\n <Link href={node.href} target='_blank'>\n {child}\n </Link>\n );\n }\n if (node.italic) {\n child = <em>{child}</em>;\n }\n if (node.bold) {\n child = <strong>{child}</strong>;\n }\n if (node['line-through']) {\n child = <del>{child}</del>;\n }\n return child;\n }\n case 'override': {\n return node.component as JSX.Element;\n }\n case 'table':\n return <Table>{node.children}</Table>;\n case 'table-body':\n return <TableBody>{node.children}</TableBody>;\n case 'table-row':\n return <TableRow>{node.children}</TableRow>;\n case 'table-cell':\n return <TableCell>{node.children}</TableCell>;\n case 'paragraph':\n return (\n <div>\n <Text>{node.children}</Text>\n </div>\n );\n case 'image':\n return (\n <div>\n <Image src={node.src} alt={node.alt as string} />\n {node.children}\n </div>\n );\n case 'image-placeholder':\n return <div>{node.children}</div>;\n case 'space':\n return <br />;\n default: {\n return <>{node.children}</>;\n }\n }\n};\n\n// Renderer for inline elements\nexport const slateLeafRenderer = (props: RenderLeafProps) => {\n let child = props.children;\n\n if (props.leaf.searchResult) {\n const CustomComponent = props.leaf.searchResult.component;\n return (\n <span {...props.attributes}>\n <CustomComponent {...props.leaf.searchResult.props}>{child}</CustomComponent>\n </span>\n );\n }\n\n if (props.leaf['line-through']) {\n child = <del>{child}</del>;\n }\n\n if (props.leaf.italic) {\n child = <em>{child}</em>;\n }\n\n if (props.leaf.bold) {\n child = <strong>{child}</strong>;\n }\n\n if (props.leaf.href) {\n child = (\n <Link href={props.leaf.href} target='_blank'>\n {child}\n </Link>\n );\n }\n\n return <span {...props.attributes}>{child}</span>;\n};\n\nconst StyledSpan = styled.span`\n white-space: pre-line;\n`;\n\nexport const leafRenderer = (leaf: CosmosCustom.Text) => {\n let child: string | ReactNode = leaf.text;\n if (leaf.searchResult) {\n const CustomComponent = leaf.searchResult.component;\n return (\n <span>\n <CustomComponent {...leaf.searchResult.props}>{child}</CustomComponent>\n </span>\n );\n }\n\n if (leaf['line-through']) {\n child = <del>{child}</del>;\n }\n\n if (leaf.italic) {\n child = <em>{child}</em>;\n }\n\n if (leaf.bold) {\n child = <strong>{child}</strong>;\n }\n\n if (leaf.href) {\n child = (\n <Link href={leaf.href} target='_blank'>\n {child}\n </Link>\n );\n }\n\n return <StyledSpan>{child}</StyledSpan>;\n};\n"]}
1
+ {"version":3,"file":"renderers.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/renderers.tsx"],"names":[],"mappings":";AAGA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAErF,oCAAoC;AACpC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAyB,EAAE,EAAE;IAC7D,QAAQ,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE;QAC1B,KAAK,WAAW;YACd,OAAO,CACL,KAAC,IAAI,IAAC,OAAO,EAAC,IAAI,KAAK,KAAK,CAAC,UAAU,YACpC,KAAK,CAAC,QAAQ,GACV,CACR,CAAC;QACJ,KAAK,WAAW;YACd,OAAO,CACL,KAAC,IAAI,IAAC,OAAO,EAAC,IAAI,KAAK,KAAK,CAAC,UAAU,YACpC,KAAK,CAAC,QAAQ,GACV,CACR,CAAC;QACJ,KAAK,WAAW;YACd,OAAO,CACL,KAAC,IAAI,IAAC,OAAO,EAAC,IAAI,KAAK,KAAK,CAAC,UAAU,YACpC,KAAK,CAAC,QAAQ,GACV,CACR,CAAC;QACJ,KAAK,WAAW;YACd,OAAO,CACL,KAAC,IAAI,IAAC,OAAO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IAED,OAAO,KAAC,UAAU,cAAE,KAAK,GAAc,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import { RenderElementProps, RenderLeafProps } from 'slate-react';\nimport { CosmosCustom } from 'slate';\nimport { ComponentType, ReactNode } from 'react';\nimport styled from 'styled-components';\n\nimport { Text, Link, Image } from '@pega/cosmos-react-core';\n\nimport { Table, TableRow, TableCell, TableBody } from '../DecoratorComponents/Table';\n\n// Renderer for block level elements\nexport const slateNodeRenderer = (props: RenderElementProps) => {\n switch (props.element.type) {\n case 'heading-1':\n return (\n <Text variant='h1' {...props.attributes}>\n {props.children}\n </Text>\n );\n case 'heading-2':\n return (\n <Text variant='h2' {...props.attributes}>\n {props.children}\n </Text>\n );\n case 'heading-3':\n return (\n <Text variant='h3' {...props.attributes}>\n {props.children}\n </Text>\n );\n case 'heading-4':\n return (\n <Text variant='h4' {...props.attributes}>\n {props.children}\n </Text>\n );\n case 'ordered-list':\n return <ol {...props.attributes}>{props.children}</ol>;\n case 'unordered-list':\n return <ul {...props.attributes}>{props.children}</ul>;\n case 'list-item':\n return (\n <li\n {...props.attributes}\n data-order={props.element.order}\n data-level={props.element.level}\n data-id={props.element.id}\n data-parent-id={props.element.parentId}\n >\n {props.children}\n </li>\n );\n case 'custom': {\n const CustomComponent = props.element.component;\n let child = <CustomComponent {...props.attributes}>{props.element.content}</CustomComponent>;\n if (props.element.href) {\n child = <Link href={props.element.href}>{child}</Link>;\n }\n if (props.element.italic) {\n child = <em>{child}</em>;\n }\n if (props.element.bold) {\n child = <strong>{child}</strong>;\n }\n if (props.element['line-through']) {\n child = <del>{child}</del>;\n }\n return child;\n }\n case 'override': {\n return props.element.component;\n }\n case 'table':\n return <Table {...props.attributes}>{props.children}</Table>;\n case 'table-body':\n return <TableBody {...props.attributes}>{props.children}</TableBody>;\n case 'table-row':\n return <TableRow {...props.attributes}>{props.children}</TableRow>;\n case 'table-cell':\n return <TableCell {...props.attributes}>{props.children}</TableCell>;\n case 'paragraph':\n return (\n <div>\n <Text {...props.attributes}>{props.children}</Text>\n </div>\n );\n case 'image':\n return (\n <div {...props.attributes}>\n <Image src={props.element.src} alt={props.element.alt as string} />\n {props.children}\n </div>\n );\n case 'image-placeholder':\n return <div {...props.attributes}>{props.children}</div>;\n default: {\n return <span {...props.attributes}>{props.children}</span>;\n }\n }\n};\n\ntype Node = {\n children: JSX.Element[];\n type: string;\n href?: string;\n italic?: boolean;\n bold?: boolean;\n 'line-through'?: boolean;\n component?: JSX.Element | ComponentType<any>;\n src?: string;\n alt?: string;\n content?: Record<string, string>;\n};\n\n// Renderer for block level elements\nexport const nodeRenderer = (node: Node) => {\n switch (node.type) {\n case 'heading-1':\n return <Text variant='h1'>{node.children}</Text>;\n case 'heading-2':\n return <Text variant='h2'>{node.children}</Text>;\n case 'heading-3':\n return <Text variant='h3'>{node.children}</Text>;\n case 'heading-4':\n return <Text variant='h4'>{node.children}</Text>;\n case 'ordered-list':\n return <ol>{node.children}</ol>;\n case 'unordered-list':\n return <ul>{node.children}</ul>;\n case 'list-item':\n return <li>{node.children}</li>;\n case 'custom': {\n const CustomComponent = node.component as ComponentType<any>;\n let child = <CustomComponent>{node.content}</CustomComponent>;\n if (node.href) {\n child = <Link href={node.href}>{child}</Link>;\n }\n if (node.italic) {\n child = <em>{child}</em>;\n }\n if (node.bold) {\n child = <strong>{child}</strong>;\n }\n if (node['line-through']) {\n child = <del>{child}</del>;\n }\n return child;\n }\n case 'override': {\n return node.component as JSX.Element;\n }\n case 'table':\n return <Table>{node.children}</Table>;\n case 'table-body':\n return <TableBody>{node.children}</TableBody>;\n case 'table-row':\n return <TableRow>{node.children}</TableRow>;\n case 'table-cell':\n return <TableCell>{node.children}</TableCell>;\n case 'paragraph':\n return (\n <div>\n <Text>{node.children}</Text>\n </div>\n );\n case 'image':\n return (\n <div>\n <Image src={node.src} alt={node.alt as string} />\n {node.children}\n </div>\n );\n case 'image-placeholder':\n return <div>{node.children}</div>;\n case 'space':\n return <br />;\n default: {\n return <>{node.children}</>;\n }\n }\n};\n\n// Renderer for inline elements\nexport const slateLeafRenderer = (props: RenderLeafProps) => {\n let child = props.children;\n\n if (props.leaf.searchResult) {\n const CustomComponent = props.leaf.searchResult.component;\n return (\n <span {...props.attributes}>\n <CustomComponent {...props.leaf.searchResult.props}>{child}</CustomComponent>\n </span>\n );\n }\n\n if (props.leaf['line-through']) {\n child = <del>{child}</del>;\n }\n\n if (props.leaf.italic) {\n child = <em>{child}</em>;\n }\n\n if (props.leaf.bold) {\n child = <strong>{child}</strong>;\n }\n\n if (props.leaf.href) {\n child = <Link href={props.leaf.href}>{child}</Link>;\n }\n\n return <span {...props.attributes}>{child}</span>;\n};\n\nconst StyledSpan = styled.span`\n white-space: pre-line;\n`;\n\nexport const leafRenderer = (leaf: CosmosCustom.Text) => {\n let child: string | ReactNode = leaf.text;\n if (leaf.searchResult) {\n const CustomComponent = leaf.searchResult.component;\n return (\n <span>\n <CustomComponent {...leaf.searchResult.props}>{child}</CustomComponent>\n </span>\n );\n }\n\n if (leaf['line-through']) {\n child = <del>{child}</del>;\n }\n\n if (leaf.italic) {\n child = <em>{child}</em>;\n }\n\n if (leaf.bold) {\n child = <strong>{child}</strong>;\n }\n\n if (leaf.href) {\n child = <Link href={leaf.href}>{child}</Link>;\n }\n\n return <StyledSpan>{child}</StyledSpan>;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"slateConverter.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/slateConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAEpD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;CAoB1B,CAAC;AA8BF,eAAO,MAAM,aAAa,UAAW,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,KAAG,MAkCzD,CAAC;AAEF,eAAO,MAAM,kBAAkB,UAAW,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,KAAG,MAW9D,CAAC"}
1
+ {"version":3,"file":"slateConverter.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/slateConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAIpD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;CAoB1B,CAAC;AA8BF,eAAO,MAAM,aAAa,UAAW,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,KAAG,MAkCzD,CAAC;AAEF,eAAO,MAAM,kBAAkB,UAAW,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,KAAG,MAW9D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"slateConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/slateConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAEpD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,GAAG;IACT,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,cAAc,EAAE,IAAI;IACpB,WAAW,EAAE,IAAI;IACjB,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,OAAO;IACrB,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,GAAG;IACd,IAAI,EAAE,GAAG;IACT,cAAc,EAAE,KAAK;IACrB,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,GAAG;IACT,KAAK,EAAE,KAAK;CACb,CAAC;AAEF,oHAAoH;AACpH,MAAM,QAAQ,GAAG,CACf,EAAuF,EACvF,EAAE;IACF,mDAAmD;IACnD,QAAQ,EAAE,CAAC,IAAI,EAAE;QACf,KAAK,WAAW;YACd,OAAO;gBACL,EAAE,IAAI,EAAE,S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E;IACtE,IACE,KAAK,CAAC,MAAM,KAAK,CAAC;QAClB,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACjC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,EAChC;QACA,OAAO,EAAE,CAAC;KACX;IACD,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACvC,OAAO,SAAS,SAAS,SAAS,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import { CosmosCustom, Element, Text } from 'slate';\n\nexport const slateToHtmlMap = {\n link: 'a',\n 'heading-1': 'h1',\n 'heading-2': 'h2',\n 'heading-3': 'h3',\n 'heading-4': 'h4',\n 'unordered-list': 'ul',\n 'ordered-list': 'ol',\n 'list-item': 'li',\n table: 'table',\n 'table-body': 'tbody',\n 'table-row': 'tr',\n 'table-cell': 'td',\n text: 'span',\n paragraph: 'p',\n bold: 'b',\n 'line-through': 'del',\n italic: 'i',\n href: 'a',\n image: 'img'\n};\n\n// Reduces the properties in a slate node into the correct html attributes, mostly used for list-items at the moment\nconst getAttrs = (\n el: Exclude<Element, CosmosCustom.ImagePlaceholderElement | CosmosCustom.CustomElement>\n) => {\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (el.type) {\n case 'list-item':\n return [\n { name: 'data-id', value: el.id },\n { name: 'data-parent-id', value: el.parentId },\n { name: 'data-order', value: el.order },\n { name: 'data-level', value: el.level }\n ].reduce((acc, attr) => {\n if (attr.value) {\n return `${acc} ${attr.name}='${attr.value}'`;\n }\n return acc;\n }, '');\n default:\n return Object.keys(el).reduce((innerAcc, key) => {\n return key !== 'type' && key !== 'children'\n ? `${innerAcc} ${key}='${el[key as keyof Element]}'`\n : innerAcc;\n }, '');\n }\n};\n\n// Recursive function to reduce Slate Nodes into an HTML string\nexport const constructHtml = (nodes: (Element | Text)[]): string => {\n return nodes.reduce((acc, node) => {\n if (\n Element.isElement(node) &&\n (node.type === 'image-placeholder' || node.type === 'custom' || node.type === 'override')\n )\n return acc;\n\n const htmlTag = Element.isElement(node) ? slateToHtmlMap[node.type] : undefined;\n let html;\n if (Text.isText(node)) {\n const { text, ...restNode } = node;\n // Reducing inline style properties from a single Slate Node into the correct HTML tags\n html = Object.keys(restNode).reduce((innerAcc, key, i) => {\n const tag = slateToHtmlMap[key as 'bold' | 'line-through' | 'italic' | 'href'];\n // Add the href attribute if needed\n const firstInnerTag = tag === 'a' ? `${tag} href='${restNode[key as 'href']}'` : tag;\n\n if (i === 0) {\n return `<${firstInnerTag}>${text}</${tag}>`;\n }\n return `<${firstInnerTag}>${innerAcc}</${tag}>`;\n }, '');\n if (!html) {\n html = text;\n }\n } else {\n const attrs = getAttrs(node);\n html = `<${htmlTag}${attrs}>${constructHtml(\n (node.children as (Element | Text)[]) || []\n )}</${htmlTag}>`;\n }\n return `${acc}${html}`;\n }, '');\n};\n\nexport const convertSlateToHtml = (nodes: (Element | Text)[]): string => {\n if (\n nodes.length === 1 &&\n Element.isElement(nodes[0]) &&\n Text.isText(nodes[0].children[0]) &&\n nodes[0].children[0].text === ''\n ) {\n return '';\n }\n const htmlNodes = constructHtml(nodes);\n return `<body>${htmlNodes}</body>`;\n};\n"]}
1
+ {"version":3,"file":"slateConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/slateConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAIpD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,GAAG;IACT,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,cAAc,EAAE,IAAI;IACpB,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YAClD,CAAC,EAAE,EAAE,CAAC,CAAC;YACP,IAAI,CAAC,IAAI,EAAE;gBACT,IAAI,GAAG,IAAI,CAAC;aACb;SACF;aAAM;YACL,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,IAAI,aAAa,CACxC,IAAI,CAAC,QAA+B,IAAI,EAAE,CAC5C,KAAK,OAAO,GAAG,CAAC;SAClB;QACD,OAAO,GAAG,GAAG,GAAG,IAAI,EAAE,CAAC;IACzB,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAyB,EAAU,EAAE;IACtE,IACE,KAAK,CAAC,MAAM,KAAK,CAAC;QAClB,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACjC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,EAChC;QACA,OAAO,EAAE,CAAC;KACX;IACD,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACvC,OAAO,SAAS,SAAS,SAAS,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import { CosmosCustom, Element, Text } from 'slate';\n\nimport { ExcludeStrict } from '@pega/cosmos-react-core';\n\nexport const slateToHtmlMap = {\n link: 'a',\n 'heading-1': 'h1',\n 'heading-2': 'h2',\n 'heading-3': 'h3',\n 'heading-4': 'h4',\n 'unordered-list': 'ul',\n 'ordered-list': 'ol',\n 'list-item': 'li',\n table: 'table',\n 'table-body': 'tbody',\n 'table-row': 'tr',\n 'table-cell': 'td',\n text: 'span',\n paragraph: 'p',\n bold: 'b',\n 'line-through': 'del',\n italic: 'i',\n href: 'a',\n image: 'img'\n};\n\n// Reduces the properties in a slate node into the correct html attributes, mostly used for list-items at the moment\nconst getAttrs = (\n el: ExcludeStrict<Element, CosmosCustom.ImagePlaceholderElement | CosmosCustom.CustomElement>\n) => {\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (el.type) {\n case 'list-item':\n return [\n { name: 'data-id', value: el.id },\n { name: 'data-parent-id', value: el.parentId },\n { name: 'data-order', value: el.order },\n { name: 'data-level', value: el.level }\n ].reduce((acc, attr) => {\n if (attr.value) {\n return `${acc} ${attr.name}='${attr.value}'`;\n }\n return acc;\n }, '');\n default:\n return Object.keys(el).reduce((innerAcc, key) => {\n return key !== 'type' && key !== 'children'\n ? `${innerAcc} ${key}='${el[key as keyof Element]}'`\n : innerAcc;\n }, '');\n }\n};\n\n// Recursive function to reduce Slate Nodes into an HTML string\nexport const constructHtml = (nodes: (Element | Text)[]): string => {\n return nodes.reduce((acc, node) => {\n if (\n Element.isElement(node) &&\n (node.type === 'image-placeholder' || node.type === 'custom' || node.type === 'override')\n )\n return acc;\n\n const htmlTag = Element.isElement(node) ? slateToHtmlMap[node.type] : undefined;\n let html;\n if (Text.isText(node)) {\n const { text, ...restNode } = node;\n // Reducing inline style properties from a single Slate Node into the correct HTML tags\n html = Object.keys(restNode).reduce((innerAcc, key, i) => {\n const tag = slateToHtmlMap[key as 'bold' | 'line-through' | 'italic' | 'href'];\n // Add the href attribute if needed\n const firstInnerTag = tag === 'a' ? `${tag} href='${restNode[key as 'href']}'` : tag;\n\n if (i === 0) {\n return `<${firstInnerTag}>${text}</${tag}>`;\n }\n return `<${firstInnerTag}>${innerAcc}</${tag}>`;\n }, '');\n if (!html) {\n html = text;\n }\n } else {\n const attrs = getAttrs(node);\n html = `<${htmlTag}${attrs}>${constructHtml(\n (node.children as (Element | Text)[]) || []\n )}</${htmlTag}>`;\n }\n return `${acc}${html}`;\n }, '');\n};\n\nexport const convertSlateToHtml = (nodes: (Element | Text)[]): string => {\n if (\n nodes.length === 1 &&\n Element.isElement(nodes[0]) &&\n Text.isText(nodes[0].children[0]) &&\n nodes[0].children[0].text === ''\n ) {\n return '';\n }\n const htmlNodes = constructHtml(nodes);\n return `<body>${htmlNodes}</body>`;\n};\n"]}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { default as DynamicContentEditor } from './components/DynamicContentEditor';
2
+ export * from './components/DynamicContentEditor';
1
3
  export * from './components/Editor';
2
4
  export * from './components/RichTextEditor';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACpF,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC"}
package/lib/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // This file is autogenerated. Any changes will be overwritten.
2
+ export { default as DynamicContentEditor } from './components/DynamicContentEditor';
3
+ export * from './components/DynamicContentEditor';
2
4
  export * from './components/Editor';
3
5
  export * from './components/RichTextEditor';
4
6
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC","sourcesContent":["// This file is autogenerated. Any changes will be overwritten.\nexport * from './components/Editor';\nexport * from './components/RichTextEditor';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACpF,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC","sourcesContent":["// This file is autogenerated. Any changes will be overwritten.\nexport { default as DynamicContentEditor } from './components/DynamicContentEditor';\nexport * from './components/DynamicContentEditor';\nexport * from './components/Editor';\nexport * from './components/RichTextEditor';\n"]}
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@pega/cosmos-react-rte",
3
- "version": "4.0.0-dev.2.0",
4
- "author": "Pegasystems",
5
- "license": "SEE LICENSE IN LICENSE",
3
+ "version": "4.0.0-dev.20.0",
6
4
  "repository": {
7
5
  "type": "git",
8
6
  "url": "https://github.com/pegasystems/cosmos-react.git",
9
7
  "directory": "packages/cosmos-rte"
10
8
  },
9
+ "license": "SEE LICENSE IN LICENSE",
10
+ "author": "Pegasystems",
11
+ "sideEffects": false,
11
12
  "main": "lib/index.js",
12
13
  "types": "lib/index.d.ts",
13
14
  "files": [
@@ -15,12 +16,11 @@
15
16
  "README.md",
16
17
  "lib"
17
18
  ],
18
- "sideEffects": false,
19
19
  "scripts": {
20
20
  "build": "tsc -b"
21
21
  },
22
22
  "dependencies": {
23
- "@pega/cosmos-react-core": "4.0.0-dev.2.0",
23
+ "@pega/cosmos-react-core": "4.0.0-dev.20.0",
24
24
  "@popperjs/core": "^2.11.6",
25
25
  "@types/marked": "^4.0.2",
26
26
  "@types/parse5": "^6.0.0",
@@ -40,7 +40,7 @@
40
40
  "slate-react": "^0.76.1",
41
41
  "styled-components": "^5.2.0",
42
42
  "stylis": "^4.0.13",
43
- "tinymce": "^6.0.3"
43
+ "tinymce": "^6.3.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@storybook/addon-a11y": "^6.4.19",
@@ -50,6 +50,6 @@
50
50
  "@storybook/addons": "^6.4.19",
51
51
  "@storybook/react": "^6.4.19",
52
52
  "@storybook/theming": "^6.4.19",
53
- "typescript": "~4.7.2"
53
+ "typescript": "~5.0.2"
54
54
  }
55
55
  }