@pega/cosmos-react-rte 2.1.3 → 2.1.6
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 +4 -4
- 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 -10
- package/lib/components/Editor/Editor.d.ts.map +0 -1
- package/lib/components/Editor/Editor.js +0 -187
- package/lib/components/Editor/Editor.js.map +0 -1
- package/lib/components/Editor/Editor.types.d.ts +0 -48
- 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/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 -141
- 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 -117
- package/lib/components/Editor/Toolbar/TextSelect.js.map +0 -1
- package/lib/components/Editor/Toolbar/Toolbar.d.ts +0 -13
- package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +0 -1
- package/lib/components/Editor/Toolbar/Toolbar.js +0 -142
- package/lib/components/Editor/Toolbar/Toolbar.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 -8
- package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +0 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Table.js +0 -51
- 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 -292
- package/lib/components/RichTextEditor/RichTextEditor.js.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +0 -15
- package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.js +0 -189
- package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +0 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +0 -80
- 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/RichTextViewer.d.ts +0 -6
- package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +0 -1
- package/lib/components/RichTextEditor/RichTextViewer.js +0 -52
- package/lib/components/RichTextEditor/RichTextViewer.js.map +0 -1
- package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +0 -26
- 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 -28
- 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 -140
- 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 -66
- 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 -8
- package/lib/components/RichTextEditor/index.d.ts.map +0 -1
- package/lib/components/RichTextEditor/index.js +0 -5
- package/lib/components/RichTextEditor/index.js.map +0 -1
- package/lib/components/RichTextEditor/utils/EditorCommands.d.ts +0 -33
- package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/EditorCommands.js +0 -423
- 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 -155
- package/lib/components/RichTextEditor/utils/htmlConverter.js.map +0 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts +0 -12
- package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.js +0 -105
- package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +0 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.d.ts +0 -7
- 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 -5
- package/lib/components/RichTextEditor/utils/renderers.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/renderers.js +0 -68
- 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 -29
- package/lib/components/RichTextEditor/utils/search.js.map +0 -1
- package/lib/components/RichTextEditor/utils/slateConverter.d.ts +0 -24
- package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +0 -1
- package/lib/components/RichTextEditor/utils/slateConverter.js +0 -87
- 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 -3
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -4
- package/lib/index.js.map +0 -1
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// Checks a string for regex matches and returns an array of matches
|
|
2
|
-
const checkRegex = (params) => {
|
|
3
|
-
const regexMatches = [];
|
|
4
|
-
let res;
|
|
5
|
-
// eslint-disable-next-line no-cond-assign
|
|
6
|
-
while ((res = params.regexPattern.exec(params.text))) {
|
|
7
|
-
const start = res.index;
|
|
8
|
-
regexMatches.push({
|
|
9
|
-
start,
|
|
10
|
-
end: start + res[0].length,
|
|
11
|
-
match: res,
|
|
12
|
-
...params
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return regexMatches;
|
|
16
|
-
};
|
|
17
|
-
// Parses text node to custom slate node
|
|
18
|
-
const parseTextToCustomSlateNodes = (text, renderers) => {
|
|
19
|
-
// Runs through an array of custom renderers and gets the matches
|
|
20
|
-
const positions = renderers?.flatMap(renderer => checkRegex({ text, ...renderer })) || [];
|
|
21
|
-
// Early exit when no matched positions
|
|
22
|
-
if (positions.length === 0) {
|
|
23
|
-
return [{ text }];
|
|
24
|
-
}
|
|
25
|
-
// Sorts the matches based on the start positions of the matches
|
|
26
|
-
positions.sort((a, b) => a.start - b.start);
|
|
27
|
-
const nodes = [];
|
|
28
|
-
// Use the regex match positions to slice the text into the correct text nodes and other custom nodes
|
|
29
|
-
let lastPos;
|
|
30
|
-
positions.forEach((pos, i) => {
|
|
31
|
-
/* If the first regex match isn't at the start of the text node,
|
|
32
|
-
slice the text node up to the first match and insert it into the nodes array */
|
|
33
|
-
if (i === 0 && pos.start !== 0) {
|
|
34
|
-
nodes.push({
|
|
35
|
-
text: text.slice(i, pos.start)
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
/* If there was a last position, slice the text between the last position
|
|
39
|
-
and the new position to insert it as a new text node */
|
|
40
|
-
if (lastPos && lastPos.end < pos.start) {
|
|
41
|
-
nodes.push({
|
|
42
|
-
text: text.slice(lastPos.end, pos.start)
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
else if (i !== 0) {
|
|
46
|
-
nodes.push({
|
|
47
|
-
text: ' '
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
if (pos.type === 'builtin-url' && pos.match.groups) {
|
|
51
|
-
const { leadingChar, url, trailingChar } = pos.match.groups;
|
|
52
|
-
try {
|
|
53
|
-
// Check for valid URL since the regex isn't exhaustive.
|
|
54
|
-
const { href } = new URL(pos.match.groups.protocol ? url : `https://${url}`);
|
|
55
|
-
if (leadingChar) {
|
|
56
|
-
nodes.push({ text: leadingChar });
|
|
57
|
-
}
|
|
58
|
-
nodes.push({
|
|
59
|
-
text: url,
|
|
60
|
-
href
|
|
61
|
-
});
|
|
62
|
-
if (trailingChar) {
|
|
63
|
-
nodes.push({ text: trailingChar });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
// Invalid URL, just render as text.
|
|
68
|
-
nodes.push({ text: pos.match[0] });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else if (pos.component) {
|
|
72
|
-
nodes.push({
|
|
73
|
-
type: 'custom',
|
|
74
|
-
component: pos.component,
|
|
75
|
-
content: pos.match,
|
|
76
|
-
children: [{ text: '' }]
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
else if (pos.getSearchAttributes) {
|
|
80
|
-
const searchResult = pos.getSearchAttributes(pos.match);
|
|
81
|
-
if (searchResult) {
|
|
82
|
-
nodes.push({
|
|
83
|
-
text: searchResult.text,
|
|
84
|
-
searchResult: {
|
|
85
|
-
markdown: searchResult.markdown,
|
|
86
|
-
component: searchResult.component,
|
|
87
|
-
props: searchResult.props,
|
|
88
|
-
toJSON: () => undefined
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/* If we are at the end of the positions array, and there's still text left
|
|
94
|
-
slice the text and add it as a new text node */
|
|
95
|
-
if (i === positions.length - 1 && pos.end < text.length - 1) {
|
|
96
|
-
nodes.push({
|
|
97
|
-
text: text.slice(pos.end, text.length)
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
lastPos = pos;
|
|
101
|
-
});
|
|
102
|
-
return nodes.length > 0 ? nodes : [{ text: '' }];
|
|
103
|
-
};
|
|
104
|
-
export default parseTextToCustomSlateNodes;
|
|
105
|
-
//# sourceMappingURL=interactionRenderer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interactionRenderer.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/interactionRenderer.ts"],"names":[],"mappings":"AAqBA,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,wCAAwC;AACxC,MAAM,2BAA2B,GAAG,CAAC,IAAY,EAAE,SAAuB,EAAE,EAAE;IAC5E,iEAAiE;IACjE,MAAM,SAAS,GACb,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,IAAI,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,EAAE,CAAC,SAAS;qBACxB;iBACF,CAAC,CAAC;aACJ;SACF;QAED;yDACiD;QACjD,IAAI,CAAC,KAAK,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3D,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';\n\nimport { SearchRenderers } from '../RichTextEditor.types';\nimport { InteractionRenderers } from '../RichTextViewer.types';\n\ninterface Renderers {\n regexPattern: InteractionRenderers['regexPattern'];\n type?: InteractionRenderers['type'];\n component?: InteractionRenderers['component'];\n getSearchAttributes?: SearchRenderers['getSearchAttributes'];\n}\ninterface RegexMatch extends Renderers {\n start: number;\n end: number;\n match: RegExpExecArray;\n}\n\ninterface CheckRegexParams extends Renderers {\n text: string;\n}\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// Parses text node to custom slate node\nconst parseTextToCustomSlateNodes = (text: string, renderers?: Renderers[]) => {\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, trailingChar } = 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\n if (leadingChar) {\n nodes.push({ text: leadingChar });\n }\n\n nodes.push({\n text: url,\n href\n });\n\n if (trailingChar) {\n nodes.push({ text: trailingChar });\n }\n } catch {\n // Invalid URL, just render as text.\n nodes.push({ text: pos.match[0] });\n }\n } else if (pos.component) {\n nodes.push({\n type: 'custom',\n component: pos.component,\n content: pos.match,\n children: [{ text: '' }]\n });\n } else if (pos.getSearchAttributes) {\n const searchResult = pos.getSearchAttributes(pos.match);\n if (searchResult) {\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 }\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 - 1) {\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,7 +0,0 @@
|
|
|
1
|
-
import { Element, Text } from 'slate';
|
|
2
|
-
import { RichTextViewerProps } from '../RichTextViewer.types';
|
|
3
|
-
import { RichTextEditorProps } from '../RichTextEditor.types';
|
|
4
|
-
export declare const convertMarkdownForEditor: (md?: string, searchRenderers?: RichTextEditorProps['searchRenderers']) => (Element | Text)[];
|
|
5
|
-
declare const convertMarkdown: (md: string, interactionRenderers?: RichTextViewerProps['interactionRenderers'], markdownMap?: RichTextViewerProps['markdownMap']) => (Element | Text)[];
|
|
6
|
-
export default convertMarkdown;
|
|
7
|
-
//# 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,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAoI9D,eAAO,MAAM,wBAAwB,kCAEjB,mBAAmB,CAAC,iBAAiB,CAAC,KACvD,CAAC,OAAO,GAAG,IAAI,CAAC,EAOlB,CAAC;AAIF,QAAA,MAAM,eAAe,OACf,MAAM,yBACa,mBAAmB,CAAC,sBAAsB,CAAC,gBACpD,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 === 'link' || 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 }, void 0),
|
|
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,MAAyB,MAAM,QAAQ,CAAC;AAE/C,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,KAAY,EACZ,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,MAAgC,IAAI,EAAE,EAC7C,oBAAoB,EACpB,WAAW,CACZ,CAAC;KACH;SAAM,IAA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IAAI;gBAChB,QAAQ;aACE,CAAC;SACd;KACF;AACH,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CACtB,MAAe,EACf,oBAAkE,EAClE,WAAgD,EAC5B,EAAE;IACtB,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,OAAO,CAAC,KAAK,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,EAAE,GAAG,EAAE,EACP,eAAwD,EACpC,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,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, { Token, Tokens } 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: 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 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: 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"]}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { RenderElementProps, RenderLeafProps } from 'slate-react';
|
|
3
|
-
export declare const nodeRenderer: (props: RenderElementProps) => JSX.Element;
|
|
4
|
-
export declare const leafRenderer: (props: RenderLeafProps) => JSX.Element;
|
|
5
|
-
//# 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;AAOlE,eAAO,MAAM,YAAY,UAAW,kBAAkB,gBA4ErD,CAAC;AAGF,eAAO,MAAM,YAAY,UAAW,eAAe,gBAiClD,CAAC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Text, Link, Image } from '@pega/cosmos-react-core';
|
|
3
|
-
import { Table, TableRow, TableCell, TableBody } from '../DecoratorComponents/Table';
|
|
4
|
-
// Renderer for block level elements
|
|
5
|
-
export const nodeRenderer = (props) => {
|
|
6
|
-
switch (props.element.type) {
|
|
7
|
-
case 'heading-1':
|
|
8
|
-
return (_jsx(Text, { variant: 'h1', ...props.attributes, children: props.children }, void 0));
|
|
9
|
-
case 'heading-2':
|
|
10
|
-
return (_jsx(Text, { variant: 'h2', ...props.attributes, children: props.children }, void 0));
|
|
11
|
-
case 'heading-3':
|
|
12
|
-
return (_jsx(Text, { variant: 'h3', ...props.attributes, children: props.children }, void 0));
|
|
13
|
-
case 'heading-4':
|
|
14
|
-
return (_jsx(Text, { variant: 'h4', ...props.attributes, children: props.children }, void 0));
|
|
15
|
-
case 'ordered-list':
|
|
16
|
-
return _jsx("ol", { ...props.attributes, children: props.children }, void 0);
|
|
17
|
-
case 'unordered-list':
|
|
18
|
-
return _jsx("ul", { ...props.attributes, children: props.children }, void 0);
|
|
19
|
-
case 'list-item':
|
|
20
|
-
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 }, void 0));
|
|
21
|
-
case 'custom': {
|
|
22
|
-
const CustomComponent = props.element.component;
|
|
23
|
-
return _jsx(CustomComponent, { ...props.attributes, children: props.element.content }, void 0);
|
|
24
|
-
}
|
|
25
|
-
case 'override': {
|
|
26
|
-
return props.element.component;
|
|
27
|
-
}
|
|
28
|
-
case 'table':
|
|
29
|
-
return _jsx(Table, { ...props.attributes, children: props.children }, void 0);
|
|
30
|
-
case 'table-body':
|
|
31
|
-
return _jsx(TableBody, { ...props.attributes, children: props.children }, void 0);
|
|
32
|
-
case 'table-row':
|
|
33
|
-
return _jsx(TableRow, { ...props.attributes, children: props.children }, void 0);
|
|
34
|
-
case 'table-cell':
|
|
35
|
-
return _jsx(TableCell, { ...props.attributes, children: props.children }, void 0);
|
|
36
|
-
case 'paragraph':
|
|
37
|
-
return (_jsx("div", { children: _jsx(Text, { ...props.attributes, children: props.children }, void 0) }, void 0));
|
|
38
|
-
case 'image':
|
|
39
|
-
return (_jsxs("div", { ...props.attributes, children: [_jsx(Image, { src: props.element.src, alt: props.element.alt }, void 0), props.children] }, void 0));
|
|
40
|
-
case 'image-placeholder':
|
|
41
|
-
return _jsx("div", { ...props.attributes, children: props.children }, void 0);
|
|
42
|
-
default: {
|
|
43
|
-
return _jsx("span", { ...props.attributes, children: props.children }, void 0);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
// Renderer for inline elements
|
|
48
|
-
export const leafRenderer = (props) => {
|
|
49
|
-
let child = props.children;
|
|
50
|
-
if (props.leaf.searchResult) {
|
|
51
|
-
const CustomComponent = props.leaf.searchResult.component;
|
|
52
|
-
return (_jsx("span", { ...props.attributes, children: _jsx(CustomComponent, { ...props.leaf.searchResult.props, children: child }, void 0) }, void 0));
|
|
53
|
-
}
|
|
54
|
-
if (props.leaf['line-through']) {
|
|
55
|
-
child = _jsx("del", { children: child }, void 0);
|
|
56
|
-
}
|
|
57
|
-
if (props.leaf.italic) {
|
|
58
|
-
child = _jsx("em", { children: child }, void 0);
|
|
59
|
-
}
|
|
60
|
-
if (props.leaf.bold) {
|
|
61
|
-
child = _jsx("strong", { children: child }, void 0);
|
|
62
|
-
}
|
|
63
|
-
if (props.leaf.href) {
|
|
64
|
-
child = (_jsx(Link, { href: props.leaf.href, target: '_blank', children: child }, void 0));
|
|
65
|
-
}
|
|
66
|
-
return _jsx("span", { ...props.attributes, children: child }, void 0);
|
|
67
|
-
};
|
|
68
|
-
//# sourceMappingURL=renderers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderers.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/renderers.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EA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,EAAE;IACrD,IAAI,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC;IAE3B,IAAI,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE;QAC3B,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC;QAC1D,OAAO,CACL,kBAAU,KAAK,CAAC,UAAU,YACxB,KAAC,eAAe,OAAK,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,YAAG,KAAK,WAAmB,WACxE,CACR,CAAC;KACH;IAED,IAAI,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QAC9B,KAAK,GAAG,wBAAM,KAAK,WAAO,CAAC;KAC5B;IAED,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE;QACrB,KAAK,GAAG,uBAAK,KAAK,WAAM,CAAC;KAC1B;IAED,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;QACnB,KAAK,GAAG,2BAAS,KAAK,WAAU,CAAC;KAClC;IAED,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;QACnB,KAAK,GAAG,CACN,KAAC,IAAI,IAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAC,QAAQ,YACzC,KAAK,WACD,CACR,CAAC;KACH;IAED,OAAO,kBAAU,KAAK,CAAC,UAAU,YAAG,KAAK,WAAQ,CAAC;AACpD,CAAC,CAAC","sourcesContent":["import { RenderElementProps, RenderLeafProps } from 'slate-react';\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 nodeRenderer = (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 return <CustomComponent {...props.attributes}>{props.element.content}</CustomComponent>;\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\n// Renderer for inline elements\nexport const leafRenderer = (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"]}
|
|
@@ -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;;;;;aAiC/E,CAAC"}
|
|
@@ -1,29 +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
|
-
if (selection && Range.isCollapsed(selection)) {
|
|
6
|
-
// Gets the cursor position in the RTE
|
|
7
|
-
const [cursorPos] = Range.edges(selection);
|
|
8
|
-
// Gets the Slate node at the search trigger
|
|
9
|
-
const [searchNode] = Editor.node(editor, cursorPos);
|
|
10
|
-
// If the search is triggered from within a searchResult node, ignore the search
|
|
11
|
-
if (searchNode?.searchResult)
|
|
12
|
-
return;
|
|
13
|
-
// Gets the point before the line that is currently being typed in the RTE
|
|
14
|
-
const posBeforeWord = Editor.before(editor, cursorPos, { unit: 'line' });
|
|
15
|
-
// Gets the range before the line up to the cursor position
|
|
16
|
-
const lineRange = posBeforeWord && Editor.range(editor, posBeforeWord, cursorPos);
|
|
17
|
-
// Gets all of the text on the current line
|
|
18
|
-
const lineText = lineRange && Editor.string(editor, lineRange);
|
|
19
|
-
// Matches the text on the current line with the regex provided
|
|
20
|
-
const beforeMatch = lineText && lineText.match(regex);
|
|
21
|
-
if (beforeMatch && typeof beforeMatch.groups?.[groupId] === 'string') {
|
|
22
|
-
const matchLength = beforeMatch.groups.match.length;
|
|
23
|
-
// Gets the range of the matching text to place the popover correctly
|
|
24
|
-
const targetRange = Editor.range(editor, { ...cursorPos, offset: cursorPos.offset - matchLength }, cursorPos);
|
|
25
|
-
return { search: beforeMatch.groups[groupId], target: targetRange, trigger };
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
//# 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,EAChF,EAAE;IACF,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAE7B,IAAI,SAAS,IAAI,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE;QAC7C,sCAAsC;QACtC,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC3C,4CAA4C;QAC5C,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QACpD,gFAAgF;QAChF,IAAK,UAAmB,EAAE,YAAY;YAAE,OAAO;QAE/C,0EAA0E;QAC1E,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QACzE,2DAA2D;QAC3D,MAAM,SAAS,GAAG,aAAa,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QAClF,2CAA2C;QAC3C,MAAM,QAAQ,GAAG,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAE/D,+DAA+D;QAC/D,MAAM,WAAW,GAAG,QAAQ,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEtD,IAAI,WAAW,IAAI,OAAO,WAAW,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,EAAE;YACpE,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;YACpD,qEAAqE;YACrE,MAAM,WAAW,GAAG,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\n if (selection && Range.isCollapsed(selection)) {\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,24 +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
|
-
paragraph: string;
|
|
16
|
-
bold: string;
|
|
17
|
-
'line-through': string;
|
|
18
|
-
italic: string;
|
|
19
|
-
href: string;
|
|
20
|
-
image: string;
|
|
21
|
-
};
|
|
22
|
-
export declare const constructHtml: (nodes: (Element | Text)[]) => string;
|
|
23
|
-
export declare const convertSlateToHtml: (nodes: (Element | Text)[]) => string;
|
|
24
|
-
//# 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;AAEpD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;CAmB1B,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,87 +0,0 @@
|
|
|
1
|
-
import { Element, Text } from 'slate';
|
|
2
|
-
export const slateToHtmlMap = {
|
|
3
|
-
link: 'a',
|
|
4
|
-
'heading-1': 'h1',
|
|
5
|
-
'heading-2': 'h2',
|
|
6
|
-
'heading-3': 'h3',
|
|
7
|
-
'heading-4': 'h4',
|
|
8
|
-
'unordered-list': 'ul',
|
|
9
|
-
'ordered-list': 'ol',
|
|
10
|
-
'list-item': 'li',
|
|
11
|
-
table: 'table',
|
|
12
|
-
'table-body': 'tbody',
|
|
13
|
-
'table-row': 'tr',
|
|
14
|
-
'table-cell': 'td',
|
|
15
|
-
paragraph: 'p',
|
|
16
|
-
bold: 'b',
|
|
17
|
-
'line-through': 'del',
|
|
18
|
-
italic: 'i',
|
|
19
|
-
href: 'a',
|
|
20
|
-
image: 'img'
|
|
21
|
-
};
|
|
22
|
-
// Reduces the properties in a slate node into the correct html attributes, mostly used for list-items at the moment
|
|
23
|
-
const getAttrs = (el) => {
|
|
24
|
-
// eslint-disable-next-line sonarjs/no-small-switch
|
|
25
|
-
switch (el.type) {
|
|
26
|
-
case 'list-item':
|
|
27
|
-
return [
|
|
28
|
-
{ name: 'data-id', value: el.id },
|
|
29
|
-
{ name: 'data-parent-id', value: el.parentId },
|
|
30
|
-
{ name: 'data-order', value: el.order },
|
|
31
|
-
{ name: 'data-level', value: el.level }
|
|
32
|
-
].reduce((acc, attr) => {
|
|
33
|
-
if (attr.value) {
|
|
34
|
-
return `${acc} ${attr.name}='${attr.value}'`;
|
|
35
|
-
}
|
|
36
|
-
return acc;
|
|
37
|
-
}, '');
|
|
38
|
-
default:
|
|
39
|
-
return Object.keys(el).reduce((innerAcc, key) => {
|
|
40
|
-
return key !== 'type' && key !== 'children'
|
|
41
|
-
? `${innerAcc} ${key}='${el[key]}'`
|
|
42
|
-
: innerAcc;
|
|
43
|
-
}, '');
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
// Recursive function to reduce Slate Nodes into an HTML string
|
|
47
|
-
export const constructHtml = (nodes) => {
|
|
48
|
-
return nodes.reduce((acc, node) => {
|
|
49
|
-
if (Element.isElement(node) &&
|
|
50
|
-
(node.type === 'image-placeholder' || node.type === 'custom' || node.type === 'override'))
|
|
51
|
-
return acc;
|
|
52
|
-
const htmlTag = Element.isElement(node) ? slateToHtmlMap[node.type] : undefined;
|
|
53
|
-
let html;
|
|
54
|
-
if (Text.isText(node)) {
|
|
55
|
-
const { text, ...restNode } = node;
|
|
56
|
-
// Reducing inline style properties from a single Slate Node into the correct HTML tags
|
|
57
|
-
html = Object.keys(restNode).reduce((innerAcc, key, i) => {
|
|
58
|
-
const tag = slateToHtmlMap[key];
|
|
59
|
-
// Add the href attribute if needed
|
|
60
|
-
const firstInnerTag = tag === 'a' ? `${tag} href='${restNode[key]}'` : tag;
|
|
61
|
-
if (i === 0) {
|
|
62
|
-
return `<${firstInnerTag}>${text}</${tag}>`;
|
|
63
|
-
}
|
|
64
|
-
return `<${firstInnerTag}>${innerAcc}</${tag}>`;
|
|
65
|
-
}, '');
|
|
66
|
-
if (!html) {
|
|
67
|
-
html = text;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
const attrs = getAttrs(node);
|
|
72
|
-
html = `<${htmlTag}${attrs}>${constructHtml(node.children || [])}</${htmlTag}>`;
|
|
73
|
-
}
|
|
74
|
-
return `${acc}${html}`;
|
|
75
|
-
}, '');
|
|
76
|
-
};
|
|
77
|
-
export const convertSlateToHtml = (nodes) => {
|
|
78
|
-
if (nodes.length === 1 &&
|
|
79
|
-
Element.isElement(nodes[0]) &&
|
|
80
|
-
Text.isText(nodes[0].children[0]) &&
|
|
81
|
-
nodes[0].children[0].text === '') {
|
|
82
|
-
return '';
|
|
83
|
-
}
|
|
84
|
-
const htmlNodes = constructHtml(nodes);
|
|
85
|
-
return `<body>${htmlNodes}</body>`;
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=slateConverter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;gBACjC,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,EAAE;gBAC9C,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE;gBACvC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE;a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K,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 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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.types.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/utils.types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,UAAqC,CAAC;AAC7D,eAAO,MAAM,UAAU,UAAgE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.types.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/utils.types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;AAC7D,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC","sourcesContent":["export const LIST_TYPES = ['unordered-list', 'ordered-list'];\nexport const TEXT_TYPES = ['paragraph', 'header-1', 'header-2', 'header-3', 'header-4'];\n"]}
|
package/lib/index.d.ts
DELETED
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC"}
|
package/lib/index.js
DELETED
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"]}
|