@pega/cosmos-react-rte 5.0.0-dev.4.7 → 5.0.0-dev.4.9
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/package.json +2 -2
- package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts +0 -12
- package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts.map +0 -1
- package/lib/components/DynamicContentEditor/DynamicContentEditor.js +0 -252
- package/lib/components/DynamicContentEditor/DynamicContentEditor.js.map +0 -1
- package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.d.ts +0 -2
- package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.d.ts.map +0 -1
- package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.js +0 -8
- package/lib/components/DynamicContentEditor/DynamicContentEditor.test-ids.js.map +0 -1
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts +0 -35
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts.map +0 -1
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js +0 -3
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js.map +0 -1
- package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts +0 -329
- package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts.map +0 -1
- package/lib/components/DynamicContentEditor/PegaCustomElement.js +0 -27
- package/lib/components/DynamicContentEditor/PegaCustomElement.js.map +0 -1
- package/lib/components/DynamicContentEditor/index.d.ts +0 -3
- package/lib/components/DynamicContentEditor/index.d.ts.map +0 -1
- package/lib/components/DynamicContentEditor/index.js +0 -2
- package/lib/components/DynamicContentEditor/index.js.map +0 -1
- package/lib/components/Editor/Editor.context.d.ts +0 -10
- package/lib/components/Editor/Editor.context.d.ts.map +0 -1
- package/lib/components/Editor/Editor.context.js +0 -10
- package/lib/components/Editor/Editor.context.js.map +0 -1
- package/lib/components/Editor/Editor.d.ts +0 -19
- package/lib/components/Editor/Editor.d.ts.map +0 -1
- package/lib/components/Editor/Editor.js +0 -369
- package/lib/components/Editor/Editor.js.map +0 -1
- package/lib/components/Editor/Editor.styles.d.ts +0 -5
- package/lib/components/Editor/Editor.styles.d.ts.map +0 -1
- package/lib/components/Editor/Editor.styles.js +0 -50
- package/lib/components/Editor/Editor.styles.js.map +0 -1
- package/lib/components/Editor/Editor.test-ids.d.ts +0 -2
- package/lib/components/Editor/Editor.test-ids.d.ts.map +0 -1
- package/lib/components/Editor/Editor.test-ids.js +0 -8
- package/lib/components/Editor/Editor.test-ids.js.map +0 -1
- package/lib/components/Editor/Editor.types.d.ts +0 -69
- package/lib/components/Editor/Editor.types.d.ts.map +0 -1
- package/lib/components/Editor/Editor.types.js +0 -2
- package/lib/components/Editor/Editor.types.js.map +0 -1
- package/lib/components/Editor/ImageEditor.d.ts +0 -10
- package/lib/components/Editor/ImageEditor.d.ts.map +0 -1
- package/lib/components/Editor/ImageEditor.js +0 -276
- package/lib/components/Editor/ImageEditor.js.map +0 -1
- package/lib/components/Editor/Toolbar/AnchorButton.d.ts +0 -10
- package/lib/components/Editor/Toolbar/AnchorButton.d.ts.map +0 -1
- package/lib/components/Editor/Toolbar/AnchorButton.js +0 -161
- package/lib/components/Editor/Toolbar/AnchorButton.js.map +0 -1
- package/lib/components/Editor/Toolbar/ImageButton.d.ts +0 -8
- package/lib/components/Editor/Toolbar/ImageButton.d.ts.map +0 -1
- package/lib/components/Editor/Toolbar/ImageButton.js +0 -30
- package/lib/components/Editor/Toolbar/ImageButton.js.map +0 -1
- package/lib/components/Editor/Toolbar/TextSelect.d.ts +0 -14
- package/lib/components/Editor/Toolbar/TextSelect.d.ts.map +0 -1
- package/lib/components/Editor/Toolbar/TextSelect.js +0 -131
- package/lib/components/Editor/Toolbar/TextSelect.js.map +0 -1
- package/lib/components/Editor/Toolbar/Toolbar.d.ts +0 -17
- package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +0 -1
- package/lib/components/Editor/Toolbar/Toolbar.js +0 -164
- package/lib/components/Editor/Toolbar/Toolbar.js.map +0 -1
- package/lib/components/Editor/Toolbar/Toolbar.test-ids.d.ts +0 -3
- package/lib/components/Editor/Toolbar/Toolbar.test-ids.d.ts.map +0 -1
- package/lib/components/Editor/Toolbar/Toolbar.test-ids.js +0 -16
- package/lib/components/Editor/Toolbar/Toolbar.test-ids.js.map +0 -1
- package/lib/components/Editor/index.d.ts +0 -4
- package/lib/components/Editor/index.d.ts.map +0 -1
- package/lib/components/Editor/index.js +0 -3
- package/lib/components/Editor/index.js.map +0 -1
- package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts +0 -4
- package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts.map +0 -1
- package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js +0 -15
- package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js.map +0 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts +0 -4
- package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts.map +0 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Image.js +0 -7
- package/lib/components/RichTextEditor/DecoratorComponents/Image.js.map +0 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts +0 -4
- package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts.map +0 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Link.js +0 -8
- package/lib/components/RichTextEditor/DecoratorComponents/Link.js.map +0 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +0 -6
- package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +0 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Table.js +0 -24
- package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.context.d.ts +0 -15
- package/lib/components/RichTextEditor/RichTextEditor.context.d.ts.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.context.js +0 -11
- package/lib/components/RichTextEditor/RichTextEditor.context.js.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.d.ts +0 -6
- package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.js +0 -346
- package/lib/components/RichTextEditor/RichTextEditor.js.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +0 -10
- package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.js +0 -73
- package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +0 -72
- package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.js +0 -2
- package/lib/components/RichTextEditor/RichTextEditor.types.js.map +0 -1
- package/lib/components/RichTextEditor/RichTextTreeRenderer.d.ts +0 -9
- package/lib/components/RichTextEditor/RichTextTreeRenderer.d.ts.map +0 -1
- package/lib/components/RichTextEditor/RichTextTreeRenderer.js +0 -15
- package/lib/components/RichTextEditor/RichTextTreeRenderer.js.map +0 -1
- package/lib/components/RichTextEditor/RichTextViewer.d.ts +0 -7
- package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +0 -1
- package/lib/components/RichTextEditor/RichTextViewer.js +0 -38
- package/lib/components/RichTextEditor/RichTextViewer.js.map +0 -1
- package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +0 -33
- package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +0 -1
- package/lib/components/RichTextEditor/RichTextViewer.types.js +0 -2
- package/lib/components/RichTextEditor/RichTextViewer.types.js.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts +0 -8
- package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/AnchorButton.js +0 -156
- package/lib/components/RichTextEditor/Toolbar/AnchorButton.js.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts +0 -5
- package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/ImageButton.js +0 -30
- package/lib/components/RichTextEditor/Toolbar/ImageButton.js.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts +0 -8
- package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/IndentButton.js +0 -31
- package/lib/components/RichTextEditor/Toolbar/IndentButton.js.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts +0 -5
- package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/TableButton.js +0 -20
- package/lib/components/RichTextEditor/Toolbar/TableButton.js.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts +0 -6
- package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/TextSelect.js +0 -119
- package/lib/components/RichTextEditor/Toolbar/TextSelect.js.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts +0 -10
- package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.js +0 -155
- package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts +0 -9
- package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js +0 -2
- package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts +0 -14
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +0 -67
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/utils.d.ts +0 -7
- package/lib/components/RichTextEditor/Toolbar/utils.d.ts.map +0 -1
- package/lib/components/RichTextEditor/Toolbar/utils.js +0 -13
- package/lib/components/RichTextEditor/Toolbar/utils.js.map +0 -1
- package/lib/components/RichTextEditor/index.d.ts +0 -9
- package/lib/components/RichTextEditor/index.d.ts.map +0 -1
- package/lib/components/RichTextEditor/index.js +0 -6
- package/lib/components/RichTextEditor/index.js.map +0 -1
- package/lib/components/RichTextEditor/utils/EditorCommands.d.ts +0 -34
- package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/EditorCommands.js +0 -447
- package/lib/components/RichTextEditor/utils/EditorCommands.js.map +0 -1
- package/lib/components/RichTextEditor/utils/ListCommands.d.ts +0 -10
- package/lib/components/RichTextEditor/utils/ListCommands.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/ListCommands.js +0 -346
- package/lib/components/RichTextEditor/utils/ListCommands.js.map +0 -1
- package/lib/components/RichTextEditor/utils/htmlConverter.d.ts +0 -29
- package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/htmlConverter.js +0 -156
- package/lib/components/RichTextEditor/utils/htmlConverter.js.map +0 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts +0 -6
- package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.js +0 -132
- package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +0 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.d.ts +0 -6
- package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.js +0 -130
- package/lib/components/RichTextEditor/utils/markdownConverter.js.map +0 -1
- package/lib/components/RichTextEditor/utils/renderers.d.ts +0 -22
- package/lib/components/RichTextEditor/utils/renderers.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/renderers.js +0 -163
- package/lib/components/RichTextEditor/utils/renderers.js.map +0 -1
- package/lib/components/RichTextEditor/utils/search.d.ts +0 -11
- package/lib/components/RichTextEditor/utils/search.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/search.js +0 -37
- package/lib/components/RichTextEditor/utils/search.js.map +0 -1
- package/lib/components/RichTextEditor/utils/slateConverter.d.ts +0 -25
- package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/slateConverter.js +0 -88
- package/lib/components/RichTextEditor/utils/slateConverter.js.map +0 -1
- package/lib/components/RichTextEditor/utils/utils.types.d.ts +0 -3
- package/lib/components/RichTextEditor/utils/utils.types.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/utils.types.js +0 -3
- package/lib/components/RichTextEditor/utils/utils.types.js.map +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -6
- package/lib/index.js.map +0 -1
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { TLDs } from 'global-tld-list';
|
|
2
|
-
const parser = new DOMParser();
|
|
3
|
-
// Checks a string for regex matches and returns an array of matches
|
|
4
|
-
const checkRegex = (params) => {
|
|
5
|
-
const regexMatches = [];
|
|
6
|
-
let res;
|
|
7
|
-
// eslint-disable-next-line no-cond-assign
|
|
8
|
-
while ((res = params.regexPattern.exec(params.text))) {
|
|
9
|
-
const start = res.index;
|
|
10
|
-
regexMatches.push({
|
|
11
|
-
start,
|
|
12
|
-
end: start + res[0].length,
|
|
13
|
-
match: res,
|
|
14
|
-
...params
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return regexMatches;
|
|
18
|
-
};
|
|
19
|
-
// Extracts all properties from an xml element represented as a string
|
|
20
|
-
export const getXMLAttributes = (element) => {
|
|
21
|
-
const document = parser.parseFromString(element, 'application/xml');
|
|
22
|
-
if (document.querySelector('parsererror'))
|
|
23
|
-
return undefined;
|
|
24
|
-
const attributes = {};
|
|
25
|
-
for (let i = 0; i < document.documentElement.attributes.length; i += 1) {
|
|
26
|
-
const attr = document.documentElement.attributes.item(i);
|
|
27
|
-
if (attr) {
|
|
28
|
-
attributes[attr.name] = attr.value;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
attributes.rawText = element;
|
|
32
|
-
return attributes;
|
|
33
|
-
};
|
|
34
|
-
// Parses text node to custom slate node
|
|
35
|
-
const parseTextToCustomSlateNodes = (text, renderers) => {
|
|
36
|
-
// Runs through an array of custom renderers and gets the matches
|
|
37
|
-
const positions = renderers?.flatMap(renderer => checkRegex({ text, ...renderer })) || [];
|
|
38
|
-
// Early exit when no matched positions
|
|
39
|
-
if (positions.length === 0) {
|
|
40
|
-
return [{ text }];
|
|
41
|
-
}
|
|
42
|
-
// Sorts the matches based on the start positions of the matches
|
|
43
|
-
positions.sort((a, b) => a.start - b.start);
|
|
44
|
-
const nodes = [];
|
|
45
|
-
// Use the regex match positions to slice the text into the correct text nodes and other custom nodes
|
|
46
|
-
let lastPos;
|
|
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
|
|
50
|
-
if (i === 0 && pos.start !== 0) {
|
|
51
|
-
nodes.push({
|
|
52
|
-
text: text.slice(i, pos.start)
|
|
53
|
-
});
|
|
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
|
|
57
|
-
if (lastPos && lastPos.end < pos.start) {
|
|
58
|
-
nodes.push({
|
|
59
|
-
text: text.slice(lastPos.end, pos.start)
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
else if (i !== 0) {
|
|
63
|
-
nodes.push({
|
|
64
|
-
text: ' '
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (pos.type === 'builtin-url' && pos.match.groups) {
|
|
68
|
-
const { leadingChar, url } = pos.match.groups;
|
|
69
|
-
try {
|
|
70
|
-
// Check for valid URL since the regex isn't exhaustive.
|
|
71
|
-
const { href } = new URL(pos.match.groups.protocol ? url : `https://${url}`);
|
|
72
|
-
if (!TLDs.includes(pos.match.groups.tld)) {
|
|
73
|
-
throw new Error('Invalid URL. Skipping formatting.');
|
|
74
|
-
}
|
|
75
|
-
if (leadingChar) {
|
|
76
|
-
nodes.push({ text: leadingChar });
|
|
77
|
-
}
|
|
78
|
-
nodes.push({
|
|
79
|
-
text: url,
|
|
80
|
-
href
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
// Invalid URL, just render as text.
|
|
85
|
-
nodes.push({ text: pos.match[0] });
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else if (pos.xmlElement) {
|
|
89
|
-
const xmlAttributes = getXMLAttributes(pos.match[0]);
|
|
90
|
-
if (!xmlAttributes) {
|
|
91
|
-
// Invalid XML, just render as text.
|
|
92
|
-
nodes.push({ text: pos.match[0] });
|
|
93
|
-
}
|
|
94
|
-
else if (pos.component) {
|
|
95
|
-
nodes.push({
|
|
96
|
-
type: 'custom',
|
|
97
|
-
component: pos.component,
|
|
98
|
-
content: xmlAttributes,
|
|
99
|
-
children: [{ text: '' }]
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
else if (pos.getSearchAttributes) {
|
|
103
|
-
const searchResult = pos.getSearchAttributes(pos.xmlElement, pos.match[0]);
|
|
104
|
-
if (searchResult && searchResult.text) {
|
|
105
|
-
nodes.push({
|
|
106
|
-
text: searchResult.text,
|
|
107
|
-
searchResult: {
|
|
108
|
-
markdown: searchResult.markdown,
|
|
109
|
-
component: searchResult.component,
|
|
110
|
-
props: searchResult.props,
|
|
111
|
-
toJSON: () => undefined
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
nodes.push({ text: pos.match[0] });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
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
|
|
122
|
-
if (i === positions.length - 1 && pos.end < text.length) {
|
|
123
|
-
nodes.push({
|
|
124
|
-
text: text.slice(pos.end, text.length)
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
lastPos = pos;
|
|
128
|
-
});
|
|
129
|
-
return nodes.length > 0 ? nodes : [{ text: '' }];
|
|
130
|
-
};
|
|
131
|
-
export default parseTextToCustomSlateNodes;
|
|
132
|
-
//# sourceMappingURL=interactionRenderer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interactionRenderer.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/interactionRenderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAcvC,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;AAE/B,oEAAoE;AACpE,MAAM,UAAU,GAAG,CAAC,MAAwB,EAAE,EAAE;IAC9C,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,IAAI,GAAG,CAAC;IACR,0CAA0C;IAC1C,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE;QACpD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACxB,YAAY,CAAC,IAAI,CAAC;YAChB,KAAK;YACL,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM;YAC1B,KAAK,EAAE,GAAG;YACV,GAAG,MAAM;SACV,CAAC,CAAC;KACJ;IACD,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAsC,EAAE;IACtF,MAAM,QAAQ,GAAG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BAAM;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"]}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Element, Text } from 'slate';
|
|
2
|
-
import { InteractionRenderers, RichTextViewerProps } from '../RichTextViewer.types';
|
|
3
|
-
export declare const convertMarkdownForEditor: (md?: string, searchRenderers?: InteractionRenderers[]) => (Element | Text)[];
|
|
4
|
-
declare const convertMarkdown: (md: string, interactionRenderers?: InteractionRenderers[], markdownMap?: RichTextViewerProps['markdownMap']) => (Element | Text)[];
|
|
5
|
-
export default convertMarkdown;
|
|
6
|
-
//# sourceMappingURL=markdownConverter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"markdownConverter.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/markdownConverter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAKpD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAoIpF,eAAO,MAAM,wBAAwB,kCAEjB,oBAAoB,EAAE,KACvC,CAAC,OAAO,GAAG,IAAI,CAAC,EAOlB,CAAC;AAIF,QAAA,MAAM,eAAe,OACf,MAAM,yBACa,oBAAoB,EAAE,gBAC/B,mBAAmB,CAAC,aAAa,CAAC,KAC/C,CAAC,OAAO,GAAG,IAAI,CAAC,EAIlB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { marked } from 'marked';
|
|
3
|
-
import { hasProp } from '@pega/cosmos-react-core';
|
|
4
|
-
import parseTextToCustomSlateNodes from './interactionRenderer';
|
|
5
|
-
marked.setOptions({ mangle: false });
|
|
6
|
-
const getNode = (token, interactionRenderers, markdownMap) => {
|
|
7
|
-
if (!hasProp(token, 'type') || token.type === 'def')
|
|
8
|
-
return { type: 'paragraph', children: [{ text: '' }] };
|
|
9
|
-
let children;
|
|
10
|
-
if (hasProp(token, 'tokens')) {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
12
|
-
children = markDownToSlate(token.tokens || [], interactionRenderers, markdownMap);
|
|
13
|
-
}
|
|
14
|
-
else if (hasProp(token, 'items')) {
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
16
|
-
children = markDownToSlate(token.items, interactionRenderers, markdownMap);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
let mdText = '';
|
|
20
|
-
if (token.type === 'text')
|
|
21
|
-
mdText = token.raw;
|
|
22
|
-
else if (hasProp(token, 'text'))
|
|
23
|
-
mdText = token.text;
|
|
24
|
-
children = parseTextToCustomSlateNodes(mdText, interactionRenderers);
|
|
25
|
-
}
|
|
26
|
-
if (markdownMap?.[token.type]) {
|
|
27
|
-
// Typed as any since typescript is unaware that token type matches argument
|
|
28
|
-
const CustomComponent = markdownMap[token.type]?.(token);
|
|
29
|
-
if (CustomComponent)
|
|
30
|
-
return {
|
|
31
|
-
type: 'override',
|
|
32
|
-
component: _jsx(CustomComponent, { token: token }),
|
|
33
|
-
children: [{ text: '' }]
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (!children.length) {
|
|
37
|
-
return {
|
|
38
|
-
type: 'paragraph',
|
|
39
|
-
children: [{ text: token.raw }]
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
switch (token.type) {
|
|
43
|
-
case 'paragraph': {
|
|
44
|
-
return {
|
|
45
|
-
type: token.type,
|
|
46
|
-
children
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
case 'heading': {
|
|
50
|
-
return {
|
|
51
|
-
type: token.depth && token.depth <= 4
|
|
52
|
-
? `heading-${token.depth}`
|
|
53
|
-
: 'heading-4',
|
|
54
|
-
children
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
case 'link': {
|
|
58
|
-
return {
|
|
59
|
-
href: token.href,
|
|
60
|
-
text: token.text || ''
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
case 'em': {
|
|
64
|
-
return {
|
|
65
|
-
italic: true,
|
|
66
|
-
text: token.text || ''
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
case 'strong': {
|
|
70
|
-
return {
|
|
71
|
-
bold: true,
|
|
72
|
-
text: token.text || ''
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
case 'del': {
|
|
76
|
-
return {
|
|
77
|
-
'line-through': true,
|
|
78
|
-
text: token.text || ''
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
case 'list': {
|
|
82
|
-
return {
|
|
83
|
-
type: token.ordered ? 'ordered-list' : 'unordered-list',
|
|
84
|
-
children: children
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
case 'list_item': {
|
|
88
|
-
return {
|
|
89
|
-
type: 'list-item',
|
|
90
|
-
children: children
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
case 'image': {
|
|
94
|
-
return {
|
|
95
|
-
type: 'image',
|
|
96
|
-
alt: token.text,
|
|
97
|
-
src: token.href,
|
|
98
|
-
children: [{ text: '' }]
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
default: {
|
|
102
|
-
return {
|
|
103
|
-
type: token.type,
|
|
104
|
-
children
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const markDownToSlate = (tokens, interactionRenderers, markdownMap) => {
|
|
110
|
-
return tokens.map(token => {
|
|
111
|
-
return getNode(token, interactionRenderers, markdownMap);
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
export const convertMarkdownForEditor = (md = '', searchRenderers) => {
|
|
115
|
-
return [
|
|
116
|
-
{
|
|
117
|
-
type: 'paragraph',
|
|
118
|
-
children: parseTextToCustomSlateNodes(md, searchRenderers)
|
|
119
|
-
}
|
|
120
|
-
];
|
|
121
|
-
};
|
|
122
|
-
// Converts markdown into Slate compatible nodes, also takes regex used
|
|
123
|
-
// in Feed Component to pass them down to custom elements
|
|
124
|
-
const convertMarkdown = (md, interactionRenderers, markdownMap) => {
|
|
125
|
-
const lexer = new marked.Lexer({ gfm: false });
|
|
126
|
-
const output = lexer.lex(md);
|
|
127
|
-
return markDownToSlate(output, interactionRenderers, markdownMap);
|
|
128
|
-
};
|
|
129
|
-
export default convertMarkdown;
|
|
130
|
-
//# sourceMappingURL=markdownConverter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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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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"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { RenderElementProps, RenderLeafProps } from 'slate-react';
|
|
2
|
-
import { CosmosCustom } from 'slate';
|
|
3
|
-
import { ComponentType } from 'react';
|
|
4
|
-
import { Text } from '@pega/cosmos-react-core';
|
|
5
|
-
export declare const slateNodeRenderer: (props: RenderElementProps) => JSX.Element;
|
|
6
|
-
type Node = {
|
|
7
|
-
children: JSX.Element[];
|
|
8
|
-
type: string;
|
|
9
|
-
href?: string;
|
|
10
|
-
italic?: boolean;
|
|
11
|
-
bold?: boolean;
|
|
12
|
-
'line-through'?: boolean;
|
|
13
|
-
component?: JSX.Element | ComponentType<any>;
|
|
14
|
-
src?: string;
|
|
15
|
-
alt?: string;
|
|
16
|
-
content?: Record<string, string>;
|
|
17
|
-
};
|
|
18
|
-
export declare const nodeRenderer: (node: Node) => JSX.Element;
|
|
19
|
-
export declare const slateLeafRenderer: (props: RenderLeafProps) => JSX.Element;
|
|
20
|
-
export declare const leafRenderer: (leaf: CosmosCustom.Text) => JSX.Element;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=renderers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
import { Text, Link, Image } from '@pega/cosmos-react-core';
|
|
4
|
-
import { Table, TableRow, TableCell, TableBody } from '../DecoratorComponents/Table';
|
|
5
|
-
// Renderer for block level elements
|
|
6
|
-
export const slateNodeRenderer = (props) => {
|
|
7
|
-
switch (props.element.type) {
|
|
8
|
-
case 'heading-1':
|
|
9
|
-
return (_jsx(Text, { variant: 'h1', ...props.attributes, children: props.children }));
|
|
10
|
-
case 'heading-2':
|
|
11
|
-
return (_jsx(Text, { variant: 'h2', ...props.attributes, children: props.children }));
|
|
12
|
-
case 'heading-3':
|
|
13
|
-
return (_jsx(Text, { variant: 'h3', ...props.attributes, children: props.children }));
|
|
14
|
-
case 'heading-4':
|
|
15
|
-
return (_jsx(Text, { variant: 'h4', ...props.attributes, children: props.children }));
|
|
16
|
-
case 'ordered-list':
|
|
17
|
-
return _jsx("ol", { ...props.attributes, children: props.children });
|
|
18
|
-
case 'unordered-list':
|
|
19
|
-
return _jsx("ul", { ...props.attributes, children: props.children });
|
|
20
|
-
case 'list-item':
|
|
21
|
-
return (_jsx("li", { ...props.attributes, "data-order": props.element.order, "data-level": props.element.level, "data-id": props.element.id, "data-parent-id": props.element.parentId, children: props.children }));
|
|
22
|
-
case 'custom': {
|
|
23
|
-
const CustomComponent = props.element.component;
|
|
24
|
-
let child = _jsx(CustomComponent, { ...props.attributes, children: props.element.content });
|
|
25
|
-
if (props.element.href) {
|
|
26
|
-
child = _jsx(Link, { href: props.element.href, children: child });
|
|
27
|
-
}
|
|
28
|
-
if (props.element.italic) {
|
|
29
|
-
child = _jsx("em", { children: child });
|
|
30
|
-
}
|
|
31
|
-
if (props.element.bold) {
|
|
32
|
-
child = _jsx("strong", { children: child });
|
|
33
|
-
}
|
|
34
|
-
if (props.element['line-through']) {
|
|
35
|
-
child = _jsx("del", { children: child });
|
|
36
|
-
}
|
|
37
|
-
return child;
|
|
38
|
-
}
|
|
39
|
-
case 'override': {
|
|
40
|
-
return props.element.component;
|
|
41
|
-
}
|
|
42
|
-
case 'table':
|
|
43
|
-
return _jsx(Table, { ...props.attributes, children: props.children });
|
|
44
|
-
case 'table-body':
|
|
45
|
-
return _jsx(TableBody, { ...props.attributes, children: props.children });
|
|
46
|
-
case 'table-row':
|
|
47
|
-
return _jsx(TableRow, { ...props.attributes, children: props.children });
|
|
48
|
-
case 'table-cell':
|
|
49
|
-
return _jsx(TableCell, { ...props.attributes, children: props.children });
|
|
50
|
-
case 'paragraph':
|
|
51
|
-
return (_jsx("div", { children: _jsx(Text, { ...props.attributes, children: props.children }) }));
|
|
52
|
-
case 'image':
|
|
53
|
-
return (_jsxs("div", { ...props.attributes, children: [_jsx(Image, { src: props.element.src, alt: props.element.alt }), props.children] }));
|
|
54
|
-
case 'image-placeholder':
|
|
55
|
-
return _jsx("div", { ...props.attributes, children: props.children });
|
|
56
|
-
default: {
|
|
57
|
-
return _jsx("span", { ...props.attributes, children: props.children });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
// Renderer for block level elements
|
|
62
|
-
export const nodeRenderer = (node) => {
|
|
63
|
-
switch (node.type) {
|
|
64
|
-
case 'heading-1':
|
|
65
|
-
return _jsx(Text, { variant: 'h1', children: node.children });
|
|
66
|
-
case 'heading-2':
|
|
67
|
-
return _jsx(Text, { variant: 'h2', children: node.children });
|
|
68
|
-
case 'heading-3':
|
|
69
|
-
return _jsx(Text, { variant: 'h3', children: node.children });
|
|
70
|
-
case 'heading-4':
|
|
71
|
-
return _jsx(Text, { variant: 'h4', children: node.children });
|
|
72
|
-
case 'ordered-list':
|
|
73
|
-
return _jsx("ol", { children: node.children });
|
|
74
|
-
case 'unordered-list':
|
|
75
|
-
return _jsx("ul", { children: node.children });
|
|
76
|
-
case 'list-item':
|
|
77
|
-
return _jsx("li", { children: node.children });
|
|
78
|
-
case 'custom': {
|
|
79
|
-
const CustomComponent = node.component;
|
|
80
|
-
let child = _jsx(CustomComponent, { children: node.content });
|
|
81
|
-
if (node.href) {
|
|
82
|
-
child = _jsx(Link, { href: node.href, children: child });
|
|
83
|
-
}
|
|
84
|
-
if (node.italic) {
|
|
85
|
-
child = _jsx("em", { children: child });
|
|
86
|
-
}
|
|
87
|
-
if (node.bold) {
|
|
88
|
-
child = _jsx("strong", { children: child });
|
|
89
|
-
}
|
|
90
|
-
if (node['line-through']) {
|
|
91
|
-
child = _jsx("del", { children: child });
|
|
92
|
-
}
|
|
93
|
-
return child;
|
|
94
|
-
}
|
|
95
|
-
case 'override': {
|
|
96
|
-
return node.component;
|
|
97
|
-
}
|
|
98
|
-
case 'table':
|
|
99
|
-
return _jsx(Table, { children: node.children });
|
|
100
|
-
case 'table-body':
|
|
101
|
-
return _jsx(TableBody, { children: node.children });
|
|
102
|
-
case 'table-row':
|
|
103
|
-
return _jsx(TableRow, { children: node.children });
|
|
104
|
-
case 'table-cell':
|
|
105
|
-
return _jsx(TableCell, { children: node.children });
|
|
106
|
-
case 'paragraph':
|
|
107
|
-
return (_jsx("div", { children: _jsx(Text, { children: node.children }) }));
|
|
108
|
-
case 'image':
|
|
109
|
-
return (_jsxs("div", { children: [_jsx(Image, { src: node.src, alt: node.alt }), node.children] }));
|
|
110
|
-
case 'image-placeholder':
|
|
111
|
-
return _jsx("div", { children: node.children });
|
|
112
|
-
case 'space':
|
|
113
|
-
return _jsx("br", {});
|
|
114
|
-
default: {
|
|
115
|
-
return _jsx(_Fragment, { children: node.children });
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
// Renderer for inline elements
|
|
120
|
-
export const slateLeafRenderer = (props) => {
|
|
121
|
-
let child = props.children;
|
|
122
|
-
if (props.leaf.searchResult) {
|
|
123
|
-
const CustomComponent = props.leaf.searchResult.component;
|
|
124
|
-
return (_jsx("span", { ...props.attributes, children: _jsx(CustomComponent, { ...props.leaf.searchResult.props, children: child }) }));
|
|
125
|
-
}
|
|
126
|
-
if (props.leaf['line-through']) {
|
|
127
|
-
child = _jsx("del", { children: child });
|
|
128
|
-
}
|
|
129
|
-
if (props.leaf.italic) {
|
|
130
|
-
child = _jsx("em", { children: child });
|
|
131
|
-
}
|
|
132
|
-
if (props.leaf.bold) {
|
|
133
|
-
child = _jsx("strong", { children: child });
|
|
134
|
-
}
|
|
135
|
-
if (props.leaf.href) {
|
|
136
|
-
child = _jsx(Link, { href: props.leaf.href, children: child });
|
|
137
|
-
}
|
|
138
|
-
return _jsx("span", { ...props.attributes, children: child });
|
|
139
|
-
};
|
|
140
|
-
const StyledSpan = styled.span `
|
|
141
|
-
white-space: pre-line;
|
|
142
|
-
`;
|
|
143
|
-
export const leafRenderer = (leaf) => {
|
|
144
|
-
let child = leaf.text;
|
|
145
|
-
if (leaf.searchResult) {
|
|
146
|
-
const CustomComponent = leaf.searchResult.component;
|
|
147
|
-
return (_jsx("span", { children: _jsx(CustomComponent, { ...leaf.searchResult.props, children: child }) }));
|
|
148
|
-
}
|
|
149
|
-
if (leaf['line-through']) {
|
|
150
|
-
child = _jsx("del", { children: child });
|
|
151
|
-
}
|
|
152
|
-
if (leaf.italic) {
|
|
153
|
-
child = _jsx("em", { children: child });
|
|
154
|
-
}
|
|
155
|
-
if (leaf.bold) {
|
|
156
|
-
child = _jsx("strong", { children: child });
|
|
157
|
-
}
|
|
158
|
-
if (leaf.href) {
|
|
159
|
-
child = _jsx(Link, { href: leaf.href, children: child });
|
|
160
|
-
}
|
|
161
|
-
return _jsx(StyledSpan, { children: child });
|
|
162
|
-
};
|
|
163
|
-
//# sourceMappingURL=renderers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderers.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/renderers.tsx"],"names":[],"mappings":";AAGA,OAAO,MAAM,MA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AAEF,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAA;;CAE7B,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAuB,EAAE,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,KAAC,IAAI,IAAC,IAAI,EAAE,IAAI,CAAC,IAAI,YAAG,KAAK,GAAQ,CAAC;KAC/C;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,11 +0,0 @@
|
|
|
1
|
-
import { Editor } from 'slate';
|
|
2
|
-
export declare const onSearchChange: (editor: Editor, { groupId, regex, trigger }: {
|
|
3
|
-
groupId: string;
|
|
4
|
-
regex: RegExp;
|
|
5
|
-
trigger: string;
|
|
6
|
-
}) => {
|
|
7
|
-
search: string;
|
|
8
|
-
target: import("slate").BaseRange;
|
|
9
|
-
trigger: string;
|
|
10
|
-
} | undefined;
|
|
11
|
-
//# sourceMappingURL=search.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,OAAO,CAAC;AAG5C,eAAO,MAAM,cAAc,WACjB,MAAM;aAC0B,MAAM;WAAS,MAAM;aAAW,MAAM;;;;;aAyC/E,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Editor, Range } from 'slate';
|
|
2
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
3
|
-
export const onSearchChange = (editor, { groupId, regex, trigger }) => {
|
|
4
|
-
const { selection } = editor;
|
|
5
|
-
let collapsed;
|
|
6
|
-
// Prevents error on triple clicks
|
|
7
|
-
try {
|
|
8
|
-
collapsed = selection ? Range.isCollapsed(selection) : false;
|
|
9
|
-
}
|
|
10
|
-
catch (e) {
|
|
11
|
-
collapsed = false;
|
|
12
|
-
}
|
|
13
|
-
if (selection && collapsed) {
|
|
14
|
-
// Gets the cursor position in the RTE
|
|
15
|
-
const [cursorPos] = Range.edges(selection);
|
|
16
|
-
// Gets the Slate node at the search trigger
|
|
17
|
-
const [searchNode] = Editor.node(editor, cursorPos);
|
|
18
|
-
// If the search is triggered from within a searchResult node, ignore the search
|
|
19
|
-
if (searchNode?.searchResult)
|
|
20
|
-
return;
|
|
21
|
-
// Gets the point before the line that is currently being typed in the RTE
|
|
22
|
-
const posBeforeWord = Editor.before(editor, cursorPos, { unit: 'line' });
|
|
23
|
-
// Gets the range before the line up to the cursor position
|
|
24
|
-
const lineRange = posBeforeWord && Editor.range(editor, posBeforeWord, cursorPos);
|
|
25
|
-
// Gets all of the text on the current line
|
|
26
|
-
const lineText = lineRange && Editor.string(editor, lineRange);
|
|
27
|
-
// Matches the text on the current line with the regex provided
|
|
28
|
-
const beforeMatch = lineText && lineText.match(regex);
|
|
29
|
-
if (beforeMatch && typeof beforeMatch.groups?.[groupId] === 'string') {
|
|
30
|
-
const matchLength = beforeMatch.groups.match.length;
|
|
31
|
-
// Gets the range of the matching text to place the popover correctly
|
|
32
|
-
const targetRange = Editor.range(editor, { ...cursorPos, offset: cursorPos.offset - matchLength }, cursorPos);
|
|
33
|
-
return { search: beforeMatch.groups[groupId], target: targetRange, trigger };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=search.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAQ,MAAM,OAAO,CAAC;AAE5C,wDAAwD;AACxD,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,MAAc,EACd,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAuD,E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,MAAM,CAAC,KAAK,CAC9B,MAAM,EACN,EAAE,GAAG,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,WAAW,EAAE,EACxD,SAAS,CACV,CAAC;YACF,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;SAC9E;KACF;AACH,CAAC,CAAC","sourcesContent":["import { Editor, Range, Text } from 'slate';\n\n// eslint-disable-next-line import/prefer-default-export\nexport const onSearchChange = (\n editor: Editor,\n { groupId, regex, trigger }: { groupId: string; regex: RegExp; trigger: string }\n) => {\n const { selection } = editor;\n let collapsed;\n\n // Prevents error on triple clicks\n try {\n collapsed = selection ? Range.isCollapsed(selection) : false;\n } catch (e) {\n collapsed = false;\n }\n\n if (selection && collapsed) {\n // Gets the cursor position in the RTE\n const [cursorPos] = Range.edges(selection);\n // Gets the Slate node at the search trigger\n const [searchNode] = Editor.node(editor, cursorPos);\n // If the search is triggered from within a searchResult node, ignore the search\n if ((searchNode as Text)?.searchResult) return;\n\n // Gets the point before the line that is currently being typed in the RTE\n const posBeforeWord = Editor.before(editor, cursorPos, { unit: 'line' });\n // Gets the range before the line up to the cursor position\n const lineRange = posBeforeWord && Editor.range(editor, posBeforeWord, cursorPos);\n // Gets all of the text on the current line\n const lineText = lineRange && Editor.string(editor, lineRange);\n\n // Matches the text on the current line with the regex provided\n const beforeMatch = lineText && lineText.match(regex);\n\n if (beforeMatch && typeof beforeMatch.groups?.[groupId] === 'string') {\n const matchLength = beforeMatch.groups.match.length;\n // Gets the range of the matching text to place the popover correctly\n const targetRange = Editor.range(\n editor,\n { ...cursorPos, offset: cursorPos.offset - matchLength },\n cursorPos\n );\n return { search: beforeMatch.groups[groupId], target: targetRange, trigger };\n }\n }\n};\n"]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Element, Text } from 'slate';
|
|
2
|
-
export declare const slateToHtmlMap: {
|
|
3
|
-
link: string;
|
|
4
|
-
'heading-1': string;
|
|
5
|
-
'heading-2': string;
|
|
6
|
-
'heading-3': string;
|
|
7
|
-
'heading-4': string;
|
|
8
|
-
'unordered-list': string;
|
|
9
|
-
'ordered-list': string;
|
|
10
|
-
'list-item': string;
|
|
11
|
-
table: string;
|
|
12
|
-
'table-body': string;
|
|
13
|
-
'table-row': string;
|
|
14
|
-
'table-cell': string;
|
|
15
|
-
text: string;
|
|
16
|
-
paragraph: string;
|
|
17
|
-
bold: string;
|
|
18
|
-
'line-through': string;
|
|
19
|
-
italic: string;
|
|
20
|
-
href: string;
|
|
21
|
-
image: string;
|
|
22
|
-
};
|
|
23
|
-
export declare const constructHtml: (nodes: (Element | Text)[]) => string;
|
|
24
|
-
export declare const convertSlateToHtml: (nodes: (Element | Text)[]) => string;
|
|
25
|
-
//# sourceMappingURL=slateConverter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|