@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.
Files changed (153) hide show
  1. package/package.json +4 -4
  2. package/lib/components/Editor/Editor.context.d.ts +0 -10
  3. package/lib/components/Editor/Editor.context.d.ts.map +0 -1
  4. package/lib/components/Editor/Editor.context.js +0 -10
  5. package/lib/components/Editor/Editor.context.js.map +0 -1
  6. package/lib/components/Editor/Editor.d.ts +0 -10
  7. package/lib/components/Editor/Editor.d.ts.map +0 -1
  8. package/lib/components/Editor/Editor.js +0 -187
  9. package/lib/components/Editor/Editor.js.map +0 -1
  10. package/lib/components/Editor/Editor.types.d.ts +0 -48
  11. package/lib/components/Editor/Editor.types.d.ts.map +0 -1
  12. package/lib/components/Editor/Editor.types.js +0 -2
  13. package/lib/components/Editor/Editor.types.js.map +0 -1
  14. package/lib/components/Editor/Toolbar/AnchorButton.d.ts +0 -10
  15. package/lib/components/Editor/Toolbar/AnchorButton.d.ts.map +0 -1
  16. package/lib/components/Editor/Toolbar/AnchorButton.js +0 -141
  17. package/lib/components/Editor/Toolbar/AnchorButton.js.map +0 -1
  18. package/lib/components/Editor/Toolbar/ImageButton.d.ts +0 -8
  19. package/lib/components/Editor/Toolbar/ImageButton.d.ts.map +0 -1
  20. package/lib/components/Editor/Toolbar/ImageButton.js +0 -30
  21. package/lib/components/Editor/Toolbar/ImageButton.js.map +0 -1
  22. package/lib/components/Editor/Toolbar/TextSelect.d.ts +0 -14
  23. package/lib/components/Editor/Toolbar/TextSelect.d.ts.map +0 -1
  24. package/lib/components/Editor/Toolbar/TextSelect.js +0 -117
  25. package/lib/components/Editor/Toolbar/TextSelect.js.map +0 -1
  26. package/lib/components/Editor/Toolbar/Toolbar.d.ts +0 -13
  27. package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +0 -1
  28. package/lib/components/Editor/Toolbar/Toolbar.js +0 -142
  29. package/lib/components/Editor/Toolbar/Toolbar.js.map +0 -1
  30. package/lib/components/Editor/index.d.ts +0 -4
  31. package/lib/components/Editor/index.d.ts.map +0 -1
  32. package/lib/components/Editor/index.js +0 -3
  33. package/lib/components/Editor/index.js.map +0 -1
  34. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts +0 -4
  35. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.d.ts.map +0 -1
  36. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js +0 -15
  37. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js.map +0 -1
  38. package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts +0 -4
  39. package/lib/components/RichTextEditor/DecoratorComponents/Image.d.ts.map +0 -1
  40. package/lib/components/RichTextEditor/DecoratorComponents/Image.js +0 -7
  41. package/lib/components/RichTextEditor/DecoratorComponents/Image.js.map +0 -1
  42. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts +0 -4
  43. package/lib/components/RichTextEditor/DecoratorComponents/Link.d.ts.map +0 -1
  44. package/lib/components/RichTextEditor/DecoratorComponents/Link.js +0 -8
  45. package/lib/components/RichTextEditor/DecoratorComponents/Link.js.map +0 -1
  46. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +0 -8
  47. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +0 -1
  48. package/lib/components/RichTextEditor/DecoratorComponents/Table.js +0 -51
  49. package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +0 -1
  50. package/lib/components/RichTextEditor/RichTextEditor.context.d.ts +0 -15
  51. package/lib/components/RichTextEditor/RichTextEditor.context.d.ts.map +0 -1
  52. package/lib/components/RichTextEditor/RichTextEditor.context.js +0 -11
  53. package/lib/components/RichTextEditor/RichTextEditor.context.js.map +0 -1
  54. package/lib/components/RichTextEditor/RichTextEditor.d.ts +0 -6
  55. package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +0 -1
  56. package/lib/components/RichTextEditor/RichTextEditor.js +0 -292
  57. package/lib/components/RichTextEditor/RichTextEditor.js.map +0 -1
  58. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +0 -15
  59. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +0 -1
  60. package/lib/components/RichTextEditor/RichTextEditor.styles.js +0 -189
  61. package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +0 -1
  62. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +0 -80
  63. package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +0 -1
  64. package/lib/components/RichTextEditor/RichTextEditor.types.js +0 -2
  65. package/lib/components/RichTextEditor/RichTextEditor.types.js.map +0 -1
  66. package/lib/components/RichTextEditor/RichTextViewer.d.ts +0 -6
  67. package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +0 -1
  68. package/lib/components/RichTextEditor/RichTextViewer.js +0 -52
  69. package/lib/components/RichTextEditor/RichTextViewer.js.map +0 -1
  70. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +0 -26
  71. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +0 -1
  72. package/lib/components/RichTextEditor/RichTextViewer.types.js +0 -2
  73. package/lib/components/RichTextEditor/RichTextViewer.types.js.map +0 -1
  74. package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts +0 -8
  75. package/lib/components/RichTextEditor/Toolbar/AnchorButton.d.ts.map +0 -1
  76. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js +0 -156
  77. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js.map +0 -1
  78. package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts +0 -5
  79. package/lib/components/RichTextEditor/Toolbar/ImageButton.d.ts.map +0 -1
  80. package/lib/components/RichTextEditor/Toolbar/ImageButton.js +0 -30
  81. package/lib/components/RichTextEditor/Toolbar/ImageButton.js.map +0 -1
  82. package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts +0 -8
  83. package/lib/components/RichTextEditor/Toolbar/IndentButton.d.ts.map +0 -1
  84. package/lib/components/RichTextEditor/Toolbar/IndentButton.js +0 -28
  85. package/lib/components/RichTextEditor/Toolbar/IndentButton.js.map +0 -1
  86. package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts +0 -5
  87. package/lib/components/RichTextEditor/Toolbar/TableButton.d.ts.map +0 -1
  88. package/lib/components/RichTextEditor/Toolbar/TableButton.js +0 -20
  89. package/lib/components/RichTextEditor/Toolbar/TableButton.js.map +0 -1
  90. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts +0 -6
  91. package/lib/components/RichTextEditor/Toolbar/TextSelect.d.ts.map +0 -1
  92. package/lib/components/RichTextEditor/Toolbar/TextSelect.js +0 -119
  93. package/lib/components/RichTextEditor/Toolbar/TextSelect.js.map +0 -1
  94. package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts +0 -10
  95. package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts.map +0 -1
  96. package/lib/components/RichTextEditor/Toolbar/Toolbar.js +0 -140
  97. package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +0 -1
  98. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts +0 -9
  99. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts.map +0 -1
  100. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js +0 -2
  101. package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js.map +0 -1
  102. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts +0 -14
  103. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts.map +0 -1
  104. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +0 -66
  105. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +0 -1
  106. package/lib/components/RichTextEditor/Toolbar/utils.d.ts +0 -7
  107. package/lib/components/RichTextEditor/Toolbar/utils.d.ts.map +0 -1
  108. package/lib/components/RichTextEditor/Toolbar/utils.js +0 -13
  109. package/lib/components/RichTextEditor/Toolbar/utils.js.map +0 -1
  110. package/lib/components/RichTextEditor/index.d.ts +0 -8
  111. package/lib/components/RichTextEditor/index.d.ts.map +0 -1
  112. package/lib/components/RichTextEditor/index.js +0 -5
  113. package/lib/components/RichTextEditor/index.js.map +0 -1
  114. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts +0 -33
  115. package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +0 -1
  116. package/lib/components/RichTextEditor/utils/EditorCommands.js +0 -423
  117. package/lib/components/RichTextEditor/utils/EditorCommands.js.map +0 -1
  118. package/lib/components/RichTextEditor/utils/ListCommands.d.ts +0 -10
  119. package/lib/components/RichTextEditor/utils/ListCommands.d.ts.map +0 -1
  120. package/lib/components/RichTextEditor/utils/ListCommands.js +0 -346
  121. package/lib/components/RichTextEditor/utils/ListCommands.js.map +0 -1
  122. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts +0 -29
  123. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +0 -1
  124. package/lib/components/RichTextEditor/utils/htmlConverter.js +0 -155
  125. package/lib/components/RichTextEditor/utils/htmlConverter.js.map +0 -1
  126. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts +0 -12
  127. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +0 -1
  128. package/lib/components/RichTextEditor/utils/interactionRenderer.js +0 -105
  129. package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +0 -1
  130. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts +0 -7
  131. package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +0 -1
  132. package/lib/components/RichTextEditor/utils/markdownConverter.js +0 -130
  133. package/lib/components/RichTextEditor/utils/markdownConverter.js.map +0 -1
  134. package/lib/components/RichTextEditor/utils/renderers.d.ts +0 -5
  135. package/lib/components/RichTextEditor/utils/renderers.d.ts.map +0 -1
  136. package/lib/components/RichTextEditor/utils/renderers.js +0 -68
  137. package/lib/components/RichTextEditor/utils/renderers.js.map +0 -1
  138. package/lib/components/RichTextEditor/utils/search.d.ts +0 -11
  139. package/lib/components/RichTextEditor/utils/search.d.ts.map +0 -1
  140. package/lib/components/RichTextEditor/utils/search.js +0 -29
  141. package/lib/components/RichTextEditor/utils/search.js.map +0 -1
  142. package/lib/components/RichTextEditor/utils/slateConverter.d.ts +0 -24
  143. package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +0 -1
  144. package/lib/components/RichTextEditor/utils/slateConverter.js +0 -87
  145. package/lib/components/RichTextEditor/utils/slateConverter.js.map +0 -1
  146. package/lib/components/RichTextEditor/utils/utils.types.d.ts +0 -3
  147. package/lib/components/RichTextEditor/utils/utils.types.d.ts.map +0 -1
  148. package/lib/components/RichTextEditor/utils/utils.types.js +0 -3
  149. package/lib/components/RichTextEditor/utils/utils.types.js.map +0 -1
  150. package/lib/index.d.ts +0 -3
  151. package/lib/index.d.ts.map +0 -1
  152. package/lib/index.js +0 -4
  153. package/lib/index.js.map +0 -1
@@ -1,346 +0,0 @@
1
- import { Editor, Element, Path, Transforms, Text } from 'slate';
2
- import { createUID } from '@pega/cosmos-react-core';
3
- import { LIST_TYPES, TEXT_TYPES } from './utils.types';
4
- const matchList = (n) => Element.isElement(n) && LIST_TYPES.includes(n.type);
5
- const matchListItem = (n) => Element.isElement(n) && n.type === 'list-item';
6
- const getNextPathBelow = (path) => {
7
- path[path.length - 1] = path[path.length - 1] + 1;
8
- return path;
9
- };
10
- const commands = {
11
- toggleList: (type, editor) => {
12
- const [listItemInSelection] = Editor.nodes(editor, {
13
- at: editor.selection?.anchor.path || undefined,
14
- match: matchListItem
15
- });
16
- if (!listItemInSelection) {
17
- Transforms.wrapNodes(editor, { type, children: [] });
18
- Transforms.wrapNodes(editor, {
19
- type: 'list-item',
20
- order: 1,
21
- level: 1,
22
- id: createUID(),
23
- children: []
24
- });
25
- }
26
- else {
27
- Transforms.setNodes(editor, { type }, { match: matchList });
28
- }
29
- },
30
- checkListEnter: (editor, event) => {
31
- /* Gets the list item node at your selection in the lowest part of the tree.
32
- Your selection could technically be in multiple list items in the tree because
33
- the lists can be nested. That is what the mode: 'lowest' arg is for. */
34
- const [listItemNodeEntry] = Editor.nodes(editor, {
35
- at: editor.selection?.anchor.path || undefined,
36
- match: matchListItem,
37
- mode: 'lowest'
38
- });
39
- if (['Backspace', 'Enter'].includes(event.key) && listItemNodeEntry) {
40
- const [listItemNode, listItemPath] = listItemNodeEntry;
41
- // Getting the text node
42
- const [[textNode]] = Editor.nodes(editor, {
43
- at: editor.selection?.anchor.path || undefined,
44
- match: Text.isText
45
- });
46
- // Getting the parent list-item node
47
- const [[parentNode]] = Editor.nodes(editor, {
48
- at: editor.selection || undefined,
49
- match: matchListItem,
50
- mode: 'highest'
51
- });
52
- let belowListItemPath;
53
- try {
54
- belowListItemPath = Path.next(listItemPath);
55
- }
56
- catch {
57
- belowListItemPath = undefined;
58
- }
59
- if (textNode.text !== '') {
60
- // If the text node the selection is in is not empty, and the key that was pressed is Enter
61
- if (event.key === 'Enter') {
62
- event.preventDefault();
63
- const newId = createUID();
64
- const copiedChildren = [];
65
- // If this list-item has another list nested inside of it
66
- if (listItemNode.children.length === 2) {
67
- // Copy the list nested inside
68
- const copiedList = { ...listItemNode.children[1] };
69
- // Add a new parentId to all the children in the list
70
- copiedList.children = copiedList.children.map(node => {
71
- return { ...node, parentId: newId };
72
- });
73
- copiedChildren.push(copiedList);
74
- // Remove the list
75
- Transforms.removeNodes(editor, { at: [...listItemPath, 1] });
76
- }
77
- /* Create a new list item with the copied children as it's children,
78
- and insert it into the editor */
79
- Transforms.insertNodes(editor, {
80
- type: 'list-item',
81
- order: listItemNode.order ? listItemNode.order + 1 : 0,
82
- level: listItemNode.level ? listItemNode.level : 1,
83
- id: newId,
84
- parentId: parentNode.id,
85
- children: [{ type: 'paragraph', children: [{ text: '' }] }, ...copiedChildren]
86
- });
87
- /* Nodes needs to be lifted one level higher because it will be inserted
88
- into the list item itself rather than it's parent list */
89
- Transforms.liftNodes(editor, {
90
- match: n => matchListItem(n) && n.id === newId
91
- });
92
- const selectionPoint = { path: [...Path.next(listItemPath), 0, 0], offset: 0 };
93
- // Set the selection to the new list item created
94
- Transforms.setSelection(editor, { focus: selectionPoint, anchor: selectionPoint });
95
- }
96
- else if (editor.selection?.anchor.offset === 0) {
97
- commands.unNestList(editor);
98
- }
99
- }
100
- else if (parentNode && parentNode.children.length > 1) {
101
- // Un nest this list item from it's parent
102
- event.preventDefault();
103
- commands.unNestList(editor);
104
- }
105
- else if (belowListItemPath) {
106
- // Break out of the list
107
- event.preventDefault();
108
- Transforms.unwrapNodes(editor, {
109
- at: editor.selection?.anchor.path || undefined,
110
- match: matchListItem
111
- });
112
- Transforms.liftNodes(editor);
113
- }
114
- }
115
- },
116
- nestList: (editor) => {
117
- const [listItemNodeEntry] = Editor.nodes(editor, {
118
- at: editor.selection?.anchor.path || undefined,
119
- match: matchListItem,
120
- mode: 'lowest'
121
- });
122
- let listType = 'unordered-list';
123
- const [highestList] = Editor.nodes(editor, {
124
- at: editor.selection?.anchor.path || undefined,
125
- match: matchList,
126
- mode: 'highest'
127
- });
128
- if (highestList) {
129
- listType = highestList[0].type;
130
- }
131
- const [listItemNode, listItemPath] = listItemNodeEntry || [
132
- undefined,
133
- undefined
134
- ];
135
- // Try to find the path to the node above the selected list item
136
- let abovePath;
137
- try {
138
- abovePath = Path.previous(listItemPath);
139
- }
140
- catch {
141
- abovePath = undefined;
142
- }
143
- // Only nest the list if there is a list item above the list item trying to be nested
144
- if (listItemNode && abovePath && listItemNode.level < 3) {
145
- // Get the list item and it's path from above the current list item
146
- const [[aboveListItemNode, aboveListItemPath]] = Editor.nodes(editor, {
147
- at: abovePath,
148
- match: n => matchListItem(n) && n.level === listItemNode.level
149
- });
150
- // Gets the path for the text node above list-item
151
- const [[, innerTextNodePath]] = Editor.nodes(editor, {
152
- at: abovePath,
153
- match: n => Element.isElement(n) && TEXT_TYPES.includes(n.type)
154
- });
155
- let copiedSubListNodes = [];
156
- const newListItemChildren = [listItemNode.children[0]];
157
- if (listItemNode.children.length && listItemNode.children.length > 1) {
158
- // Copy the item to be nested's sub list if it has one
159
- const subList = listItemNode.children[1];
160
- if (subList) {
161
- copiedSubListNodes = [...subList.children];
162
- }
163
- }
164
- // If the above list item has a sub list
165
- if (aboveListItemNode.children.length > 1) {
166
- // Get the list items in the sub list of the above list item
167
- const { children } = aboveListItemNode.children[1];
168
- // Gets the last list item in the above sub list
169
- const [[parentSubListItem, parentSubListItemPath]] = Editor.nodes(editor, {
170
- at: aboveListItemPath,
171
- match: n => matchListItem(n) &&
172
- n.order === children.length &&
173
- n.level - 1 === listItemNode.level
174
- });
175
- // Gets the path after the last list item in the above sub list
176
- const nextParentSubListItemPath = Path.next(parentSubListItemPath);
177
- /* Inserts a copy of the list-item you are nesting below the lowest list item
178
- in the above sub list, as well as copies of any children the list-item you are
179
- nesting had. */
180
- let subOrderCount = parentSubListItem.order + 1;
181
- Transforms.insertNodes(editor, [
182
- {
183
- ...listItemNode,
184
- level: listItemNode.level + 1,
185
- order: parentSubListItem.order + 1,
186
- parentId: aboveListItemNode.id,
187
- children: newListItemChildren
188
- },
189
- ...copiedSubListNodes.map(n => {
190
- subOrderCount += 1;
191
- return {
192
- ...n,
193
- level: listItemNode.level + 1,
194
- order: subOrderCount,
195
- parentId: aboveListItemNode.id
196
- };
197
- })
198
- ], { at: nextParentSubListItemPath });
199
- }
200
- else {
201
- const nextInnerTextNodePath = getNextPathBelow(innerTextNodePath);
202
- // Nest the selected list item into a new list and then into the above list item
203
- let subOrderCount = 1;
204
- Transforms.insertNodes(editor, {
205
- type: listType,
206
- children: [
207
- {
208
- ...listItemNode,
209
- order: 1,
210
- level: listItemNode.level + 1,
211
- parentId: aboveListItemNode.id,
212
- children: newListItemChildren
213
- },
214
- ...copiedSubListNodes.map(n => {
215
- subOrderCount += 1;
216
- return {
217
- ...n,
218
- level: listItemNode.level + 1,
219
- order: subOrderCount,
220
- parentId: aboveListItemNode.id
221
- };
222
- })
223
- ]
224
- }, { at: nextInnerTextNodePath, mode: 'lowest' });
225
- }
226
- // Remove the old list item as we just copied it into the correct place
227
- Transforms.removeNodes(editor, { at: listItemPath });
228
- }
229
- },
230
- unNestList: (editor) => {
231
- // Get the current node to be un nested
232
- const [[node, nodePath]] = Editor.nodes(editor, {
233
- at: editor.selection?.anchor.path || undefined,
234
- match: matchListItem,
235
- mode: 'lowest'
236
- });
237
- const [singleItemList] = Editor.nodes(editor, {
238
- match: n => matchList(n) && n.children.length === 1,
239
- mode: 'highest'
240
- });
241
- if (singleItemList) {
242
- Transforms.unwrapNodes(editor, { match: matchListItem });
243
- Transforms.unwrapNodes(editor, { match: matchList });
244
- return;
245
- }
246
- // Attempt to get the highest parent in the nested list if it exists
247
- const [highestParent] = Editor.nodes(editor, {
248
- at: editor.selection || undefined,
249
- match: n => matchListItem(n) && node.level - n.level === 2,
250
- mode: 'lowest'
251
- });
252
- // Get the parent list node if it exists (list item)
253
- const [[parentNode]] = Editor.nodes(editor, {
254
- at: editor.selection || undefined,
255
- match: n => matchListItem(n) && node.level - n.level === 1,
256
- mode: 'lowest'
257
- });
258
- // Get the parent list
259
- const [[parentList]] = Editor.nodes(editor, {
260
- at: editor.selection || undefined,
261
- match: matchList,
262
- mode: 'lowest'
263
- });
264
- if (parentNode && parentNode.children.length > 1) {
265
- let newParentId;
266
- if (highestParent) {
267
- const [highestParentNode] = highestParent;
268
- newParentId = highestParentNode.id;
269
- }
270
- // Setting the node to un nests new order and level
271
- Transforms.setNodes(editor, {
272
- level: node.level - 1,
273
- order: parentNode.order + 1
274
- }, { at: nodePath, match: n => matchListItem(n) && n.id === node.id });
275
- // Set the level of any children under the node we are un nesting
276
- Transforms.setNodes(editor, { level: node.level }, {
277
- at: nodePath,
278
- match: n => matchListItem(n) && n.level > node.level
279
- });
280
- // If there's a new parent id set it, otherwise unset the parent id entirely
281
- if (newParentId) {
282
- Transforms.setNodes(editor, { parentId: newParentId }, { at: nodePath, match: n => matchListItem(n) && n.id === node.id });
283
- }
284
- else {
285
- Transforms.unsetNodes(editor, 'parentId', {
286
- at: nodePath,
287
- match: n => matchListItem(n) && n.id === node.id
288
- });
289
- }
290
- const listItemsExistBelow = node.order < parentList.children.length;
291
- if (listItemsExistBelow) {
292
- // Getting the inner text node inside of the list item in order to get the next path
293
- const [[, innerTextNodePath]] = Editor.nodes(editor, {
294
- at: nodePath,
295
- match: matchList
296
- });
297
- const nextPath = Path.next(innerTextNodePath);
298
- const copiedChildren = [];
299
- let count = 1;
300
- // Copy the children from the parent list that are below the list item we are un nesting
301
- for (let i = node.order; i < parentList.children.length; i += 1) {
302
- copiedChildren.push({
303
- ...parentList.children[i],
304
- parentId: node.id,
305
- order: count
306
- });
307
- count += 1;
308
- }
309
- // Insert a new list with the copied children into the un nested list item
310
- Transforms.insertNodes(editor, {
311
- type: parentList.type,
312
- children: [...copiedChildren]
313
- }, { at: nextPath });
314
- const [[newParentList, newParentListPath]] = Editor.nodes(editor, {
315
- at: editor.selection?.anchor.path || undefined,
316
- match: matchList,
317
- mode: 'lowest'
318
- });
319
- let order = 0;
320
- // Set the nodes below the list item being un nested
321
- Transforms.setNodes(editor, {
322
- parentId: node.id,
323
- order
324
- }, {
325
- match: n => {
326
- if (!matchListItem(n))
327
- return false;
328
- if (n.parentId === node.id)
329
- order += 1;
330
- return n.parentId === node.id;
331
- }
332
- });
333
- // Removing all old nodes from that were under the un nested item
334
- for (let i = newParentList.children.length - 1; i >= node.order; i -= 1) {
335
- const childPath = [...newParentListPath, i];
336
- Transforms.removeNodes(editor, { at: childPath, match: matchListItem });
337
- }
338
- }
339
- // Lift the current node at the users selection out of it's parent node twice
340
- Transforms.liftNodes(editor, { match: matchListItem });
341
- Transforms.liftNodes(editor, { match: matchListItem });
342
- }
343
- }
344
- };
345
- export default commands;
346
- //# sourceMappingURL=ListCommands.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ListCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/ListCommands.ts"],"names":[],"mappings":"AACA,OAAO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,KAAK,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE;oBACvE,MAAM,SAAS,GAAG,CAAC,GAAG,iBAAiB,EAAE,CAAC,CAAC,CAAC;oBAC5C,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;iBACzE;aACF;YAED,6EAA6E;YAC7E,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;YACvD,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;SACxD;IACH,CAAC;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { KeyboardEvent } from 'react';\nimport { Editor, Node, Element, Path, Transforms, CosmosCustom, Text, NodeEntry } from 'slate';\n\nimport { createUID } from '@pega/cosmos-react-core';\n\nimport { LIST_TYPES, TEXT_TYPES } from './utils.types';\n\ntype FullListItemElement = CosmosCustom.ListItemElement & {\n id: string;\n parentId: string;\n order: number;\n level: number;\n};\n\nconst matchList = (n: Node): n is CosmosCustom.ListElement =>\n Element.isElement(n) && LIST_TYPES.includes(n.type);\n\nconst matchListItem = (n: Node): n is CosmosCustom.ListItemElement =>\n Element.isElement(n) && n.type === 'list-item';\n\nconst getNextPathBelow = (path: Path) => {\n path[path.length - 1] = path[path.length - 1] + 1;\n return path;\n};\n\nconst commands = {\n toggleList: (type: 'unordered-list' | 'ordered-list', editor: Editor) => {\n const [listItemInSelection] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem\n });\n\n if (!listItemInSelection) {\n Transforms.wrapNodes(editor, { type, children: [] });\n Transforms.wrapNodes(editor, {\n type: 'list-item',\n order: 1,\n level: 1,\n id: createUID(),\n children: []\n });\n } else {\n Transforms.setNodes(editor, { type }, { match: matchList });\n }\n },\n checkListEnter: (editor: Editor, event: KeyboardEvent<any>) => {\n /* Gets the list item node at your selection in the lowest part of the tree.\n Your selection could technically be in multiple list items in the tree because\n the lists can be nested. That is what the mode: 'lowest' arg is for. */\n const [listItemNodeEntry] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n\n if (['Backspace', 'Enter'].includes(event.key) && listItemNodeEntry) {\n const [listItemNode, listItemPath] = listItemNodeEntry;\n // Getting the text node\n const [[textNode]] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: Text.isText\n });\n // Getting the parent list-item node\n const [[parentNode]] = Editor.nodes(editor, {\n at: editor.selection || undefined,\n match: matchListItem,\n mode: 'highest'\n });\n\n let belowListItemPath;\n try {\n belowListItemPath = Path.next(listItemPath);\n } catch {\n belowListItemPath = undefined;\n }\n\n if (textNode.text !== '') {\n // If the text node the selection is in is not empty, and the key that was pressed is Enter\n if (event.key === 'Enter') {\n event.preventDefault();\n const newId = createUID();\n const copiedChildren: Element[] = [];\n // If this list-item has another list nested inside of it\n if (listItemNode.children.length === 2) {\n // Copy the list nested inside\n const copiedList = { ...listItemNode.children[1] } as CosmosCustom.ListElement;\n // Add a new parentId to all the children in the list\n copiedList.children = copiedList.children.map(node => {\n return { ...node, parentId: newId };\n });\n copiedChildren.push(copiedList);\n // Remove the list\n Transforms.removeNodes(editor, { at: [...listItemPath, 1] });\n }\n /* Create a new list item with the copied children as it's children,\n and insert it into the editor */\n Transforms.insertNodes(editor, {\n type: 'list-item',\n order: listItemNode.order ? listItemNode.order + 1 : 0,\n level: listItemNode.level ? listItemNode.level : 1,\n id: newId,\n parentId: parentNode.id,\n children: [{ type: 'paragraph', children: [{ text: '' }] }, ...copiedChildren]\n });\n /* Nodes needs to be lifted one level higher because it will be inserted\n into the list item itself rather than it's parent list */\n Transforms.liftNodes<CosmosCustom.ListItemElement>(editor, {\n match: n => matchListItem(n) && n.id === newId\n });\n const selectionPoint = { path: [...Path.next(listItemPath), 0, 0], offset: 0 };\n // Set the selection to the new list item created\n Transforms.setSelection(editor, { focus: selectionPoint, anchor: selectionPoint });\n } else if (editor.selection?.anchor.offset === 0) {\n commands.unNestList(editor);\n }\n } else if (parentNode && parentNode.children.length > 1) {\n // Un nest this list item from it's parent\n event.preventDefault();\n commands.unNestList(editor);\n } else if (belowListItemPath) {\n // Break out of the list\n event.preventDefault();\n Transforms.unwrapNodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem\n });\n Transforms.liftNodes(editor);\n }\n }\n },\n nestList: (editor: Editor) => {\n const [listItemNodeEntry] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n\n let listType: `${'un' | ''}ordered-list` = 'unordered-list';\n const [highestList] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchList,\n mode: 'highest'\n });\n\n if (highestList) {\n listType = highestList[0].type;\n }\n\n const [listItemNode, listItemPath] = (listItemNodeEntry as NodeEntry<FullListItemElement>) || [\n undefined,\n undefined\n ];\n\n // Try to find the path to the node above the selected list item\n let abovePath;\n try {\n abovePath = Path.previous(listItemPath);\n } catch {\n abovePath = undefined;\n }\n\n // Only nest the list if there is a list item above the list item trying to be nested\n if (listItemNode && abovePath && listItemNode.level < 3) {\n // Get the list item and it's path from above the current list item\n const [[aboveListItemNode, aboveListItemPath]] = Editor.nodes<CosmosCustom.ListItemElement>(\n editor,\n {\n at: abovePath,\n match: n => matchListItem(n) && n.level === listItemNode.level\n }\n );\n // Gets the path for the text node above list-item\n const [[, innerTextNodePath]] = Editor.nodes<CosmosCustom.TextElement>(editor, {\n at: abovePath,\n match: n => Element.isElement(n) && TEXT_TYPES.includes(n.type)\n });\n\n let copiedSubListNodes: CosmosCustom.ListItemElement[] = [];\n const newListItemChildren = [listItemNode.children[0]];\n if (listItemNode.children.length && listItemNode.children.length > 1) {\n // Copy the item to be nested's sub list if it has one\n const subList = listItemNode.children[1] as CosmosCustom.ListElement;\n if (subList) {\n copiedSubListNodes = [...subList.children];\n }\n }\n\n // If the above list item has a sub list\n if (aboveListItemNode.children.length > 1) {\n // Get the list items in the sub list of the above list item\n const { children } = aboveListItemNode.children[1] as CosmosCustom.ListElement;\n // Gets the last list item in the above sub list\n const [[parentSubListItem, parentSubListItemPath]] = Editor.nodes<FullListItemElement>(\n editor,\n {\n at: aboveListItemPath,\n match: n =>\n matchListItem(n) &&\n n.order === children.length &&\n (n.level as number) - 1 === listItemNode.level\n }\n );\n\n // Gets the path after the last list item in the above sub list\n const nextParentSubListItemPath = Path.next(parentSubListItemPath);\n\n /* Inserts a copy of the list-item you are nesting below the lowest list item\n in the above sub list, as well as copies of any children the list-item you are\n nesting had. */\n let subOrderCount = parentSubListItem.order + 1;\n Transforms.insertNodes(\n editor,\n [\n {\n ...listItemNode,\n level: listItemNode.level + 1,\n order: parentSubListItem.order + 1,\n parentId: aboveListItemNode.id,\n children: newListItemChildren\n },\n ...copiedSubListNodes.map(n => {\n subOrderCount += 1;\n return {\n ...n,\n level: listItemNode.level + 1,\n order: subOrderCount,\n parentId: aboveListItemNode.id\n };\n })\n ],\n { at: nextParentSubListItemPath }\n );\n } else {\n const nextInnerTextNodePath = getNextPathBelow(innerTextNodePath);\n // Nest the selected list item into a new list and then into the above list item\n let subOrderCount = 1;\n Transforms.insertNodes(\n editor,\n {\n type: listType,\n children: [\n {\n ...listItemNode,\n order: 1,\n level: listItemNode.level + 1,\n parentId: aboveListItemNode.id,\n children: newListItemChildren\n },\n ...copiedSubListNodes.map(n => {\n subOrderCount += 1;\n return {\n ...n,\n level: listItemNode.level + 1,\n order: subOrderCount,\n parentId: aboveListItemNode.id\n };\n })\n ]\n },\n { at: nextInnerTextNodePath, mode: 'lowest' }\n );\n }\n\n // Remove the old list item as we just copied it into the correct place\n Transforms.removeNodes(editor, { at: listItemPath });\n }\n },\n unNestList: (editor: Editor) => {\n // Get the current node to be un nested\n const [[node, nodePath]] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchListItem,\n mode: 'lowest'\n });\n const [singleItemList] = Editor.nodes<CosmosCustom.ListElement>(editor, {\n match: n => matchList(n) && n.children.length === 1,\n mode: 'highest'\n });\n\n if (singleItemList) {\n Transforms.unwrapNodes(editor, { match: matchListItem });\n Transforms.unwrapNodes(editor, { match: matchList });\n return;\n }\n // Attempt to get the highest parent in the nested list if it exists\n const [highestParent] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection || undefined,\n match: n => matchListItem(n) && node.level - (n.level as number) === 2,\n mode: 'lowest'\n });\n // Get the parent list node if it exists (list item)\n const [[parentNode]] = Editor.nodes<FullListItemElement>(editor, {\n at: editor.selection || undefined,\n match: n => matchListItem(n) && node.level - (n.level as number) === 1,\n mode: 'lowest'\n });\n // Get the parent list\n const [[parentList]] = Editor.nodes(editor, {\n at: editor.selection || undefined,\n match: matchList,\n mode: 'lowest'\n });\n if (parentNode && parentNode.children.length > 1) {\n let newParentId;\n if (highestParent) {\n const [highestParentNode] = highestParent;\n newParentId = highestParentNode.id;\n }\n\n // Setting the node to un nests new order and level\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n {\n level: node.level - 1,\n order: parentNode.order + 1\n },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n\n // Set the level of any children under the node we are un nesting\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n { level: node.level },\n {\n at: nodePath,\n match: n => matchListItem(n) && (n.level as number) > node.level\n }\n );\n\n // If there's a new parent id set it, otherwise unset the parent id entirely\n if (newParentId) {\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n { parentId: newParentId },\n { at: nodePath, match: n => matchListItem(n) && n.id === node.id }\n );\n } else {\n Transforms.unsetNodes<CosmosCustom.ListItemElement>(editor, 'parentId', {\n at: nodePath,\n match: n => matchListItem(n) && n.id === node.id\n });\n }\n\n const listItemsExistBelow = node.order < parentList.children.length;\n\n if (listItemsExistBelow) {\n // Getting the inner text node inside of the list item in order to get the next path\n const [[, innerTextNodePath]] = Editor.nodes(editor, {\n at: nodePath,\n match: matchList\n });\n const nextPath = Path.next(innerTextNodePath);\n const copiedChildren = [];\n\n let count = 1;\n // Copy the children from the parent list that are below the list item we are un nesting\n for (let i = node.order; i < parentList.children.length; i += 1) {\n copiedChildren.push({\n ...parentList.children[i],\n parentId: node.id,\n order: count\n });\n count += 1;\n }\n\n // Insert a new list with the copied children into the un nested list item\n Transforms.insertNodes(\n editor,\n {\n type: parentList.type,\n children: [...copiedChildren]\n },\n { at: nextPath }\n );\n\n const [[newParentList, newParentListPath]] = Editor.nodes(editor, {\n at: editor.selection?.anchor.path || undefined,\n match: matchList,\n mode: 'lowest'\n });\n\n let order = 0;\n // Set the nodes below the list item being un nested\n Transforms.setNodes<CosmosCustom.ListItemElement>(\n editor,\n {\n parentId: node.id,\n order\n },\n {\n match: n => {\n if (!matchListItem(n)) return false;\n\n if (n.parentId === node.id) order += 1;\n return n.parentId === node.id;\n }\n }\n );\n\n // Removing all old nodes from that were under the un nested item\n for (let i = newParentList.children.length - 1; i >= node.order; i -= 1) {\n const childPath = [...newParentListPath, i];\n Transforms.removeNodes(editor, { at: childPath, match: matchListItem });\n }\n }\n\n // Lift the current node at the users selection out of it's parent node twice\n Transforms.liftNodes(editor, { match: matchListItem });\n Transforms.liftNodes(editor, { match: matchListItem });\n }\n }\n};\n\nexport default commands;\n"]}
@@ -1,29 +0,0 @@
1
- import type * as slate from 'slate';
2
- import { RichTextViewerProps } from '../RichTextViewer.types';
3
- export declare const htmlToSlateMap: {
4
- readonly h1: "heading-1";
5
- readonly h2: "heading-2";
6
- readonly h3: "heading-3";
7
- readonly h4: "heading-4";
8
- readonly ul: "unordered-list";
9
- readonly ol: "ordered-list";
10
- readonly li: "list-item";
11
- readonly table: "table";
12
- readonly tr: "table-row";
13
- readonly td: "table-cell";
14
- readonly tbody: "table-body";
15
- readonly p: "paragraph";
16
- readonly img: "image";
17
- readonly b: "skip";
18
- readonly del: "skip";
19
- readonly i: "skip";
20
- readonly a: "skip";
21
- };
22
- export declare const inlineHtmlToStyleMap: {
23
- readonly b: "bold";
24
- readonly del: "line-through";
25
- readonly i: "italic";
26
- readonly a: "href";
27
- };
28
- export declare const convertHtml: (html: string, interactionRenderers?: RichTextViewerProps['interactionRenderers']) => (slate.Element | slate.Text)[];
29
- //# sourceMappingURL=htmlConverter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"htmlConverter.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/htmlConverter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAY9D,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;CAkBjB,CAAC;AAGX,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAgIX,eAAO,MAAM,WAAW,SAChB,MAAM,yBACW,mBAAmB,CAAC,sBAAsB,CAAC,KACjE,CAAC,aAAa,GAAG,UAAU,CAAC,EAe9B,CAAC"}
@@ -1,155 +0,0 @@
1
- import { parse } from 'parse5';
2
- import parseTextToCustomSlateNodes from './interactionRenderer';
3
- const checkElement = (node) => !!node && node.nodeName !== '#text' && node.nodeName !== '#comment';
4
- const checkTextNode = (node) => !!node && node.nodeName === '#text';
5
- const checkComment = (node) => !!node && node.nodeName === '#comment';
6
- // Mapping of HTML tags to slate types. b, del, i, and a tags are labeled as skip because they need special logic
7
- export const htmlToSlateMap = {
8
- h1: 'heading-1',
9
- h2: 'heading-2',
10
- h3: 'heading-3',
11
- h4: 'heading-4',
12
- ul: 'unordered-list',
13
- ol: 'ordered-list',
14
- li: 'list-item',
15
- table: 'table',
16
- tr: 'table-row',
17
- td: 'table-cell',
18
- tbody: 'table-body',
19
- p: 'paragraph',
20
- img: 'image',
21
- b: 'skip',
22
- del: 'skip',
23
- i: 'skip',
24
- a: 'skip'
25
- };
26
- // Inline HTML tags to slate types
27
- export const inlineHtmlToStyleMap = {
28
- b: 'bold',
29
- del: 'line-through',
30
- i: 'italic',
31
- a: 'href'
32
- };
33
- // Maps HTML Attributes to an object. Right now this is specifically used for list items.
34
- const getAttributes = (node) => {
35
- if (checkElement(node) && node.attrs.length) {
36
- switch (node.nodeName) {
37
- case 'li':
38
- return Object.fromEntries(node.attrs.flatMap(attr => {
39
- // eslint-disable-next-line sonarjs/no-nested-switch
40
- switch (attr.name) {
41
- case 'data-id':
42
- return [['id', attr.value]];
43
- case 'data-parent-id':
44
- return [['parentId', attr.value]];
45
- case 'data-level':
46
- return [['level', attr.value]];
47
- case 'data-order':
48
- return [['order', attr.value]];
49
- default:
50
- return [];
51
- }
52
- }));
53
- case 'img': {
54
- const imgAttrs = ['src', 'alt'];
55
- const attrsObj = {};
56
- for (let i = 0; i < node.attrs.length; i += 1) {
57
- const { name, value } = node.attrs[i];
58
- if (imgAttrs.includes(name)) {
59
- attrsObj[name] = value;
60
- }
61
- }
62
- return attrsObj;
63
- }
64
- default:
65
- return {};
66
- }
67
- }
68
- return {};
69
- };
70
- const getSlateNode = (node, parentNode, interactionRenderers) => {
71
- if (checkTextNode(node)) {
72
- if (node.parentNode.nodeName === 'body') {
73
- return {
74
- node: {
75
- type: 'paragraph',
76
- children: [{ text: node.value }]
77
- }
78
- };
79
- }
80
- // Make sure to spread any parent style attributes for slates text nodes
81
- const children = parseTextToCustomSlateNodes(node.value, interactionRenderers);
82
- if (children.length === 1) {
83
- return { node: { ...parentNode, ...children[0] } };
84
- }
85
- return {
86
- node: {
87
- ...parentNode,
88
- children
89
- }
90
- };
91
- }
92
- const type = htmlToSlateMap[node.nodeName];
93
- /*
94
- If the type of the HTML tag is an inline (b, i, del, a) we want to let the recursive function know
95
- that it needs to collapse the next node, also we are setting the correct style mark to true
96
- */
97
- if (type === 'skip') {
98
- const style = inlineHtmlToStyleMap[node.nodeName];
99
- let value = true;
100
- if (node.nodeName === 'a') {
101
- const hrefObj = node.attrs?.find(attr => attr.name === 'href');
102
- value = hrefObj ? hrefObj.value : value;
103
- }
104
- return {
105
- node: { ...parentNode, [style]: value, text: '' },
106
- collapseNext: true
107
- };
108
- }
109
- const attributes = getAttributes(node);
110
- const nodeObj = {
111
- type: type || 'paragraph',
112
- ...attributes,
113
- children: [{ text: '' }]
114
- };
115
- return { node: nodeObj };
116
- };
117
- // Recursive function that will convert Parse5Nodes into Slate compatible nodes
118
- const convertNodes = (nodes, parentNode, interactionRenderers) => {
119
- const returnNodes = [];
120
- nodes.forEach(node => {
121
- const { node: slateNode, collapseNext } = getSlateNode(node, parentNode, interactionRenderers);
122
- if (!checkComment(node)) {
123
- let returnNode = slateNode;
124
- if (checkElement(node) && node.childNodes && node.childNodes.length) {
125
- if (collapseNext) {
126
- returnNode = convertNodes(node.childNodes, slateNode, interactionRenderers)[0];
127
- }
128
- else {
129
- slateNode.children = convertNodes(node.childNodes, undefined, interactionRenderers);
130
- returnNode = slateNode;
131
- }
132
- }
133
- returnNodes.push(returnNode);
134
- }
135
- });
136
- return returnNodes;
137
- };
138
- const defaultValue = [{ type: 'paragraph', children: [{ text: '' }] }];
139
- export const convertHtml = (html, interactionRenderers) => {
140
- // Wrap the html in another body in case the value given has no body
141
- const doc = parse(`<body>${html.replace('\n', '')}</body>`);
142
- let nodesToConvert = doc.childNodes;
143
- // If we have a root tag
144
- if (doc.childNodes.length === 1) {
145
- const root = doc.childNodes[0];
146
- if (!checkElement(root))
147
- return defaultValue;
148
- const body = root.childNodes[1];
149
- if (!checkElement(body))
150
- return defaultValue;
151
- nodesToConvert = body.childNodes;
152
- }
153
- return convertNodes(nodesToConvert, undefined, interactionRenderers);
154
- };
155
- //# sourceMappingURL=htmlConverter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"htmlConverter.js","sourceRoot":"","sources":["../../../../src/components/RichText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,CAAC,CAAC;IACH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAmB,CAAC,CAAC;AAExF,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,IAAY,EACZ,oBAAkE,EAClC,EAAE;IAClC,oEAAoE;IACpE,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;IAC5D,IAAI,cAAc,GAAG,GAAG,CAAC,UAAU,CAAC;IACpC,wBAAwB;IACxB,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/B,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YAAE,OAAO,YAAY,CAAC;QAE7C,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YAAE,OAAO,YAAY,CAAC;QAE7C,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC;KAClC;IACD,OAAO,YAAY,CAAC,cAAc,EAAE,SAAS,EAAE,oBAAoB,CAAC,CAAC;AACvE,CAAC,CAAC","sourcesContent":["import { parse } from 'parse5';\n// Use namespaced types to more easily differentiate between similar types (ie, ChildNode from parse5 and Node from slate).\nimport type * as parse5 from 'parse5';\nimport type * as slate from 'slate';\n\nimport { RichTextViewerProps } from '../RichTextViewer.types';\n\nimport parseTextToCustomSlateNodes from './interactionRenderer';\n\nconst checkElement = (node: parse5.ChildNode | undefined): node is parse5.Element =>\n !!node && node.nodeName !== '#text' && node.nodeName !== '#comment';\nconst checkTextNode = (node: parse5.ChildNode | undefined): node is parse5.TextNode =>\n !!node && node.nodeName === '#text';\nconst checkComment = (node: parse5.ChildNode | undefined): node is parse5.TextNode =>\n !!node && node.nodeName === '#comment';\n\n// Mapping of HTML tags to slate types. b, del, i, and a tags are labeled as skip because they need special logic\nexport const htmlToSlateMap = {\n h1: 'heading-1',\n h2: 'heading-2',\n h3: 'heading-3',\n h4: 'heading-4',\n ul: 'unordered-list',\n ol: 'ordered-list',\n li: 'list-item',\n table: 'table',\n tr: 'table-row',\n td: 'table-cell',\n tbody: 'table-body',\n p: 'paragraph',\n img: 'image',\n b: 'skip',\n del: 'skip',\n i: 'skip',\n a: 'skip'\n} as const;\n\n// Inline HTML tags to slate types\nexport const inlineHtmlToStyleMap = {\n b: 'bold',\n del: 'line-through',\n i: 'italic',\n a: 'href'\n} as const;\n\n// Maps HTML Attributes to an object. Right now this is specifically used for list items.\nconst getAttributes = (node: parse5.ChildNode) => {\n if (checkElement(node) && node.attrs.length) {\n switch (node.nodeName) {\n case 'li':\n return Object.fromEntries(\n node.attrs.flatMap(attr => {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (attr.name) {\n case 'data-id':\n return [['id', attr.value]];\n case 'data-parent-id':\n return [['parentId', attr.value]];\n case 'data-level':\n return [['level', attr.value]];\n case 'data-order':\n return [['order', attr.value]];\n default:\n return [];\n }\n })\n );\n case 'img': {\n const imgAttrs = ['src', 'alt'];\n const attrsObj: { [key: string]: string } = {};\n for (let i = 0; i < node.attrs.length; i += 1) {\n const { name, value } = node.attrs[i];\n if (imgAttrs.includes(name)) {\n attrsObj[name] = value;\n }\n }\n return attrsObj;\n }\n default:\n return {};\n }\n }\n return {};\n};\n\nconst getSlateNode = (\n node: parse5.ChildNode,\n parentNode?: slate.Element | slate.Text,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): { node: slate.Element | slate.Text; collapseNext?: boolean } => {\n if (checkTextNode(node)) {\n if (node.parentNode.nodeName === 'body') {\n return {\n node: {\n type: 'paragraph',\n children: [{ text: node.value }]\n }\n };\n }\n // Make sure to spread any parent style attributes for slates text nodes\n const children = parseTextToCustomSlateNodes(node.value, interactionRenderers);\n if (children.length === 1) {\n return { node: { ...parentNode, ...children[0] } as slate.Text };\n }\n return {\n node: {\n ...parentNode,\n children\n } as slate.Element\n };\n }\n\n const type = htmlToSlateMap[node.nodeName as keyof typeof htmlToSlateMap];\n /*\n If the type of the HTML tag is an inline (b, i, del, a) we want to let the recursive function know\n that it needs to collapse the next node, also we are setting the correct style mark to true\n */\n if (type === 'skip') {\n const style = inlineHtmlToStyleMap[node.nodeName as 'b' | 'i' | 'del' | 'a'];\n let value: string | boolean = true;\n if (node.nodeName === 'a') {\n const hrefObj = node.attrs?.find(attr => attr.name === 'href');\n value = hrefObj ? hrefObj.value : value;\n }\n return {\n node: { ...parentNode, [style]: value, text: '' } as slate.Text,\n collapseNext: true\n };\n }\n\n const attributes = getAttributes(node);\n const nodeObj = {\n type: type || 'paragraph',\n ...attributes,\n children: [{ text: '' }]\n } as slate.Element;\n return { node: nodeObj };\n};\n\n// Recursive function that will convert Parse5Nodes into Slate compatible nodes\nconst convertNodes = (\n nodes: parse5.ChildNode[],\n parentNode?: slate.Element | slate.Text,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): (slate.Element | slate.Text)[] => {\n const returnNodes: (slate.Element | slate.Text)[] = [];\n nodes.forEach(node => {\n const { node: slateNode, collapseNext } = getSlateNode(node, parentNode, interactionRenderers);\n if (!checkComment(node)) {\n let returnNode = slateNode;\n if (checkElement(node) && node.childNodes && node.childNodes.length) {\n if (collapseNext) {\n returnNode = convertNodes(node.childNodes, slateNode, interactionRenderers)[0];\n } else {\n (slateNode as slate.Element).children = convertNodes(\n node.childNodes,\n undefined,\n interactionRenderers\n );\n returnNode = slateNode;\n }\n }\n\n returnNodes.push(returnNode);\n }\n });\n return returnNodes;\n};\n\nconst defaultValue = [{ type: 'paragraph', children: [{ text: '' }] } as slate.Element];\n\nexport const convertHtml = (\n html: string,\n interactionRenderers?: RichTextViewerProps['interactionRenderers']\n): (slate.Element | slate.Text)[] => {\n // Wrap the html in another body in case the value given has no body\n const doc = parse(`<body>${html.replace('\\n', '')}</body>`);\n let nodesToConvert = doc.childNodes;\n // If we have a root tag\n if (doc.childNodes.length === 1) {\n const root = doc.childNodes[0];\n if (!checkElement(root)) return defaultValue;\n\n const body = root.childNodes[1];\n if (!checkElement(body)) return defaultValue;\n\n nodesToConvert = body.childNodes;\n }\n return convertNodes(nodesToConvert, undefined, interactionRenderers);\n};\n"]}
@@ -1,12 +0,0 @@
1
- import type * as slate from 'slate';
2
- import { SearchRenderers } from '../RichTextEditor.types';
3
- import { InteractionRenderers } from '../RichTextViewer.types';
4
- interface Renderers {
5
- regexPattern: InteractionRenderers['regexPattern'];
6
- type?: InteractionRenderers['type'];
7
- component?: InteractionRenderers['component'];
8
- getSearchAttributes?: SearchRenderers['getSearchAttributes'];
9
- }
10
- declare const parseTextToCustomSlateNodes: (text: string, renderers?: Renderers[] | undefined) => (slate.CosmosCustom.Element | slate.CosmosCustom.Text)[];
11
- export default parseTextToCustomSlateNodes;
12
- //# sourceMappingURL=interactionRenderer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interactionRenderer.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/interactionRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,UAAU,SAAS;IACjB,YAAY,EAAE,oBAAoB,CAAC,cAAc,CAAC,CAAC;IACnD,IAAI,CAAC,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACpC,SAAS,CAAC,EAAE,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAC9C,mBAAmB,CAAC,EAAE,eAAe,CAAC,qBAAqB,CAAC,CAAC;CAC9D;AA6BD,QAAA,MAAM,2BAA2B,SAAU,MAAM,kGA+FhD,CAAC;AAEF,eAAe,2BAA2B,CAAC"}