@pega/cosmos-react-rte 2.1.4 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +3 -3
- package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextViewer.types.js.map +1 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.js +2 -2
- package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { marked } from 'marked';
|
|
2
2
|
import { ComponentType, FC } from 'react';
|
|
3
3
|
import { ErrorStateProps } from '@pega/cosmos-react-core';
|
|
4
4
|
export interface InteractionRenderers {
|
|
@@ -7,12 +7,12 @@ export interface InteractionRenderers {
|
|
|
7
7
|
component?: ComponentType<any>;
|
|
8
8
|
}
|
|
9
9
|
export declare type TokenMap = {
|
|
10
|
-
[K in Exclude<Token, Tokens.Def>['type']]: Extract<Token, {
|
|
10
|
+
[K in Exclude<marked.Token, marked.Tokens.Def>['type']]: Extract<marked.Token, {
|
|
11
11
|
type: K;
|
|
12
12
|
}>;
|
|
13
13
|
};
|
|
14
14
|
export declare type MDMap = {
|
|
15
|
-
[K in Exclude<Token, Tokens.Def>['type']]?: (token: TokenMap[K]) => FC<{
|
|
15
|
+
[K in Exclude<marked.Token, marked.Tokens.Def>['type']]?: (token: TokenMap[K]) => FC<{
|
|
16
16
|
token: TokenMap[K];
|
|
17
17
|
}> | undefined;
|
|
18
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextViewer.types.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"RichTextViewer.types.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;CAChC;AAED,oBAAY,QAAQ,GAAG;KACpB,CAAC,IAAI,OAAO,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;CAC5F,CAAC;AAEF,oBAAY,KAAK,GAAG;KACjB,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CACxD,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KACf,EAAE,CAAC;QAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC,GAAG,SAAS;CAC5C,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;IACvC,oBAAoB,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAC9C,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;CACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextViewer.types.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"RichTextViewer.types.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"","sourcesContent":["import { marked } from 'marked';\nimport { ComponentType, FC } from 'react';\n\nimport { ErrorStateProps } from '@pega/cosmos-react-core';\n\nexport interface InteractionRenderers {\n type: string;\n regexPattern: RegExp;\n component?: ComponentType<any>;\n}\n\nexport type TokenMap = {\n [K in Exclude<marked.Token, marked.Tokens.Def>['type']]: Extract<marked.Token, { type: K }>;\n};\n\nexport type MDMap = {\n [K in Exclude<marked.Token, marked.Tokens.Def>['type']]?: (\n token: TokenMap[K]\n ) => FC<{ token: TokenMap[K] }> | undefined;\n};\n\nexport interface RichTextViewerProps {\n content: string;\n type: 'markdown' | 'html' | 'richtext';\n interactionRenderers?: InteractionRenderers[];\n markdownMap?: MDMap;\n onRetry?: ErrorStateProps['onRetry'];\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import marked from 'marked';
|
|
2
|
+
import { marked } from 'marked';
|
|
3
3
|
import { hasProp } from '@pega/cosmos-react-core';
|
|
4
4
|
import parseTextToCustomSlateNodes from './interactionRenderer';
|
|
5
5
|
marked.setOptions({ mangle: false });
|
|
@@ -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 === 'link' || */token.type === 'text')
|
|
21
21
|
mdText = token.raw;
|
|
22
22
|
else if (hasProp(token, 'text'))
|
|
23
23
|
mdText = token.text;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/markdownConverter.tsx"],"names":[],"mappings":";AACA,OAAO,
|
|
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;AAKlD,OAAO,2BAA2B,MAAM,uBAAuB,CAAC;AAEhE,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAErC,MAAM,OAAO,GAAG,CACd,KAAmB,EACnB,oBAAkE,EAClE,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,KAAK,MAAM;YAAE,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC;aACxE,IAAI,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;YAAE,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC;QAErD,QAAQ,GAAG,2BAA2B,CAAC,MAAM,EAAE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2B,CAAC,EAAE,EAAE,eAAe,CAAC;SAC3D;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;yDACyD;AACzD,MAAM,eAAe,GAAG,CACtB,EAAU,EACV,oBAAkE,EAClE,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 { RichTextViewerProps } from '../RichTextViewer.types';\nimport { RichTextEditorProps } from '../RichTextEditor.types';\n\nimport parseTextToCustomSlateNodes from './interactionRenderer';\n\nmarked.setOptions({ mangle: false });\n\nconst getNode = (\n token: marked.Token,\n interactionRenderers?: RichTextViewerProps['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?: RichTextViewerProps['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?: RichTextEditorProps['searchRenderers']\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?: RichTextViewerProps['interactionRenderers'],\n markdownMap?: RichTextViewerProps['markdownMap']\n): (Element | Text)[] => {\n const lexer = new marked.Lexer({ gfm: false });\n const output = lexer.lex(md);\n return markDownToSlate(output, interactionRenderers, markdownMap);\n};\n\nexport default convertMarkdown;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-rte",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
4
4
|
"author": "Pegasystems",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"repository": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"build": "tsc -b"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@pega/cosmos-react-core": "2.1.
|
|
23
|
+
"@pega/cosmos-react-core": "2.1.7",
|
|
24
24
|
"@popperjs/core": "^2.11.0",
|
|
25
25
|
"dompurify": "^2.3.1",
|
|
26
|
-
"marked": "^
|
|
26
|
+
"marked": "^4.0.12",
|
|
27
27
|
"parse5": "^6.0.1",
|
|
28
28
|
"polished": "^4.1.0",
|
|
29
29
|
"react": "^16.14.0 || ^17.0.0",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@storybook/react": "^6.4.8",
|
|
45
45
|
"@storybook/theming": "^6.4.8",
|
|
46
46
|
"@types/dompurify": "^2.2.3",
|
|
47
|
-
"@types/marked": "
|
|
47
|
+
"@types/marked": "^4.0.2",
|
|
48
48
|
"@types/parse5": "^6.0.0",
|
|
49
49
|
"@types/tinymce": "^4.6.4",
|
|
50
50
|
"enzyme": "^3.11.0",
|